rtl8225se.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /* Radio tuning for RTL8225 on RTL8187SE
  2. *
  3. * Copyright 2009 Larry Finger <Larry.Finger@lwfinger.net>
  4. * Copyright 2014 Andrea Merello <andrea.merello@gmail.com>
  5. *
  6. * Based on the r8180 and Realtek r8187se drivers, which are:
  7. * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al.
  8. *
  9. * Also based on the rtl8187 driver, which is:
  10. * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
  11. * Copyright 2007 Andrea Merello <andrea.merello@gmail.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #include <net/mac80211.h>
  18. #include "rtl8180.h"
  19. #include "rtl8225se.h"
  20. #define PFX "rtl8225 (se) "
  21. static const u32 RF_GAIN_TABLE[] = {
  22. 0x0096, 0x0076, 0x0056, 0x0036, 0x0016, 0x01f6, 0x01d6, 0x01b6,
  23. 0x0196, 0x0176, 0x00F7, 0x00D7, 0x00B7, 0x0097, 0x0077, 0x0057,
  24. 0x0037, 0x00FB, 0x00DB, 0x00BB, 0x00FF, 0x00E3, 0x00C3, 0x00A3,
  25. 0x0083, 0x0063, 0x0043, 0x0023, 0x0003, 0x01E3, 0x01C3, 0x01A3,
  26. 0x0183, 0x0163, 0x0143, 0x0123, 0x0103
  27. };
  28. static const u8 cck_ofdm_gain_settings[] = {
  29. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
  30. 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  31. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
  32. 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  33. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
  34. 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  35. };
  36. static const u8 rtl8225se_tx_gain_cck_ofdm[] = {
  37. 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e
  38. };
  39. static const u8 rtl8225se_tx_power_cck[] = {
  40. 0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02,
  41. 0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02,
  42. 0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02,
  43. 0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02,
  44. 0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03,
  45. 0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03
  46. };
  47. static const u8 rtl8225se_tx_power_cck_ch14[] = {
  48. 0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00,
  49. 0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00,
  50. 0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00,
  51. 0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00,
  52. 0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00,
  53. 0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00
  54. };
  55. static const u8 rtl8225se_tx_power_ofdm[] = {
  56. 0x80, 0x90, 0xa2, 0xb5, 0xcb, 0xe4
  57. };
  58. static const u32 rtl8225se_chan[] = {
  59. 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380,
  60. 0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x074A,
  61. };
  62. static const u8 rtl8225sez2_tx_power_cck_ch14[] = {
  63. 0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00
  64. };
  65. static const u8 rtl8225sez2_tx_power_cck_B[] = {
  66. 0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x04
  67. };
  68. static const u8 rtl8225sez2_tx_power_cck_A[] = {
  69. 0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04
  70. };
  71. static const u8 rtl8225sez2_tx_power_cck[] = {
  72. 0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04
  73. };
  74. static const u8 ZEBRA_AGC[] = {
  75. 0x7E, 0x7E, 0x7E, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A,
  76. 0x79, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72,
  77. 0x71, 0x70, 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A,
  78. 0x69, 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62,
  79. 0x48, 0x47, 0x46, 0x45, 0x44, 0x29, 0x28, 0x27,
  80. 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x08, 0x07,
  81. 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00,
  82. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  83. 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
  84. 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x15, 0x16,
  85. 0x17, 0x17, 0x18, 0x18, 0x19, 0x1a, 0x1a, 0x1b,
  86. 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, 0x1d, 0x1e, 0x1e,
  87. 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x20, 0x21,
  88. 0x21, 0x21, 0x22, 0x22, 0x22, 0x23, 0x23, 0x24,
  89. 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27,
  90. 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F
  91. };
  92. static const u8 OFDM_CONFIG[] = {
  93. 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50,
  94. 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00,
  95. 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26,
  96. 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB,
  97. 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00,
  98. 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00,
  99. 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e,
  100. 0xD8, 0x3C, 0x7B, 0x10, 0x10
  101. };
  102. static void rtl8187se_three_wire_io(struct ieee80211_hw *dev, u8 *data,
  103. u8 len, bool write)
  104. {
  105. struct rtl8180_priv *priv = dev->priv;
  106. int i;
  107. u8 tmp;
  108. do {
  109. for (i = 0; i < 5; i++) {
  110. tmp = rtl818x_ioread8(priv, SW_3W_CMD1);
  111. if (!(tmp & 0x3))
  112. break;
  113. udelay(10);
  114. }
  115. if (i == 5)
  116. wiphy_err(dev->wiphy, PFX
  117. "CmdReg: 0x%x RE/WE bits aren't clear\n", tmp);
  118. tmp = rtl818x_ioread8(priv, &priv->map->rf_sw_config) | 0x02;
  119. rtl818x_iowrite8(priv, &priv->map->rf_sw_config, tmp);
  120. tmp = rtl818x_ioread8(priv, REG_ADDR1(0x84)) & 0xF7;
  121. rtl818x_iowrite8(priv, REG_ADDR1(0x84), tmp);
  122. if (write) {
  123. if (len == 16) {
  124. rtl818x_iowrite16(priv, SW_3W_DB0,
  125. *(u16 *)data);
  126. } else if (len == 64) {
  127. rtl818x_iowrite32(priv, SW_3W_DB0_4,
  128. *((u32 *)data));
  129. rtl818x_iowrite32(priv, SW_3W_DB1_4,
  130. *((u32 *)(data + 4)));
  131. } else
  132. wiphy_err(dev->wiphy, PFX
  133. "Unimplemented length\n");
  134. } else {
  135. rtl818x_iowrite16(priv, SW_3W_DB0, *(u16 *)data);
  136. }
  137. if (write)
  138. tmp = 2;
  139. else
  140. tmp = 1;
  141. rtl818x_iowrite8(priv, SW_3W_CMD1, tmp);
  142. for (i = 0; i < 5; i++) {
  143. tmp = rtl818x_ioread8(priv, SW_3W_CMD1);
  144. if (!(tmp & 0x3))
  145. break;
  146. udelay(10);
  147. }
  148. rtl818x_iowrite8(priv, SW_3W_CMD1, 0);
  149. if (!write) {
  150. *((u16 *)data) = rtl818x_ioread16(priv, SI_DATA_REG);
  151. *((u16 *)data) &= 0x0FFF;
  152. }
  153. } while (0);
  154. }
  155. static u32 rtl8187se_rf_readreg(struct ieee80211_hw *dev, u8 addr)
  156. {
  157. u32 dataread = addr & 0x0F;
  158. rtl8187se_three_wire_io(dev, (u8 *)&dataread, 16, 0);
  159. return dataread;
  160. }
  161. static void rtl8187se_rf_writereg(struct ieee80211_hw *dev, u8 addr, u32 data)
  162. {
  163. u32 outdata = (data << 4) | (u32)(addr & 0x0F);
  164. rtl8187se_three_wire_io(dev, (u8 *)&outdata, 16, 1);
  165. }
  166. static void rtl8225se_write_zebra_agc(struct ieee80211_hw *dev)
  167. {
  168. int i;
  169. for (i = 0; i < 128; i++) {
  170. rtl8225se_write_phy_ofdm(dev, 0xF, ZEBRA_AGC[i]);
  171. rtl8225se_write_phy_ofdm(dev, 0xE, i+0x80);
  172. rtl8225se_write_phy_ofdm(dev, 0xE, 0);
  173. }
  174. }
  175. static void rtl8187se_write_ofdm_config(struct ieee80211_hw *dev)
  176. {
  177. /* write OFDM_CONFIG table */
  178. int i;
  179. for (i = 0; i < 60; i++)
  180. rtl8225se_write_phy_ofdm(dev, i, OFDM_CONFIG[i]);
  181. }
  182. static void rtl8225sez2_rf_set_tx_power(struct ieee80211_hw *dev, int channel)
  183. {
  184. struct rtl8180_priv *priv = dev->priv;
  185. u8 cck_power, ofdm_power;
  186. cck_power = priv->channels[channel - 1].hw_value & 0xFF;
  187. if (cck_power > 35)
  188. cck_power = 35;
  189. rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK,
  190. cck_ofdm_gain_settings[cck_power]);
  191. usleep_range(1000, 5000);
  192. ofdm_power = priv->channels[channel - 1].hw_value >> 8;
  193. if (ofdm_power > 35)
  194. ofdm_power = 35;
  195. rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM,
  196. cck_ofdm_gain_settings[ofdm_power]);
  197. if (ofdm_power < 12) {
  198. rtl8225se_write_phy_ofdm(dev, 7, 0x5C);
  199. rtl8225se_write_phy_ofdm(dev, 9, 0x5C);
  200. }
  201. if (ofdm_power < 18) {
  202. rtl8225se_write_phy_ofdm(dev, 7, 0x54);
  203. rtl8225se_write_phy_ofdm(dev, 9, 0x54);
  204. } else {
  205. rtl8225se_write_phy_ofdm(dev, 7, 0x50);
  206. rtl8225se_write_phy_ofdm(dev, 9, 0x50);
  207. }
  208. usleep_range(1000, 5000);
  209. }
  210. static void rtl8187se_write_rf_gain(struct ieee80211_hw *dev)
  211. {
  212. int i;
  213. for (i = 0; i <= 36; i++) {
  214. rtl8187se_rf_writereg(dev, 0x01, i); mdelay(1);
  215. rtl8187se_rf_writereg(dev, 0x02, RF_GAIN_TABLE[i]); mdelay(1);
  216. }
  217. }
  218. static void rtl8187se_write_initial_gain(struct ieee80211_hw *dev,
  219. int init_gain)
  220. {
  221. switch (init_gain) {
  222. default:
  223. rtl8225se_write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
  224. rtl8225se_write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
  225. rtl8225se_write_phy_ofdm(dev, 0x05, 0xFA); mdelay(1);
  226. break;
  227. case 2:
  228. rtl8225se_write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
  229. rtl8225se_write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
  230. rtl8225se_write_phy_ofdm(dev, 0x05, 0xFA); mdelay(1);
  231. break;
  232. case 3:
  233. rtl8225se_write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
  234. rtl8225se_write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
  235. rtl8225se_write_phy_ofdm(dev, 0x05, 0xFB); mdelay(1);
  236. break;
  237. case 4:
  238. rtl8225se_write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
  239. rtl8225se_write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
  240. rtl8225se_write_phy_ofdm(dev, 0x05, 0xFB); mdelay(1);
  241. break;
  242. case 5:
  243. rtl8225se_write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
  244. rtl8225se_write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
  245. rtl8225se_write_phy_ofdm(dev, 0x05, 0xFB); mdelay(1);
  246. break;
  247. case 6:
  248. rtl8225se_write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
  249. rtl8225se_write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
  250. rtl8225se_write_phy_ofdm(dev, 0x05, 0xFC); mdelay(1);
  251. break;
  252. case 7:
  253. rtl8225se_write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
  254. rtl8225se_write_phy_ofdm(dev, 0x24, 0xA6); mdelay(1);
  255. rtl8225se_write_phy_ofdm(dev, 0x05, 0xFC); mdelay(1);
  256. break;
  257. case 8:
  258. rtl8225se_write_phy_ofdm(dev, 0x17, 0x66); mdelay(1);
  259. rtl8225se_write_phy_ofdm(dev, 0x24, 0xB6); mdelay(1);
  260. rtl8225se_write_phy_ofdm(dev, 0x05, 0xFC); mdelay(1);
  261. break;
  262. }
  263. }
  264. void rtl8225se_rf_init(struct ieee80211_hw *dev)
  265. {
  266. struct rtl8180_priv *priv = dev->priv;
  267. u32 rf23, rf24;
  268. u8 d_cut = 0;
  269. u8 tmp;
  270. /* Page 1 */
  271. rtl8187se_rf_writereg(dev, 0x00, 0x013F); mdelay(1);
  272. rf23 = rtl8187se_rf_readreg(dev, 0x08); mdelay(1);
  273. rf24 = rtl8187se_rf_readreg(dev, 0x09); mdelay(1);
  274. if (rf23 == 0x0818 && rf24 == 0x070C)
  275. d_cut = 1;
  276. wiphy_info(dev->wiphy, "RTL8225-SE version %s\n",
  277. d_cut ? "D" : "not-D");
  278. /* Page 0: reg 0 - 15 */
  279. rtl8187se_rf_writereg(dev, 0x00, 0x009F); mdelay(1);
  280. rtl8187se_rf_writereg(dev, 0x01, 0x06E0); mdelay(1);
  281. rtl8187se_rf_writereg(dev, 0x02, 0x004D); mdelay(1);
  282. rtl8187se_rf_writereg(dev, 0x03, 0x07F1); mdelay(1);
  283. rtl8187se_rf_writereg(dev, 0x04, 0x0975); mdelay(1);
  284. rtl8187se_rf_writereg(dev, 0x05, 0x0C72); mdelay(1);
  285. rtl8187se_rf_writereg(dev, 0x06, 0x0AE6); mdelay(1);
  286. rtl8187se_rf_writereg(dev, 0x07, 0x00CA); mdelay(1);
  287. rtl8187se_rf_writereg(dev, 0x08, 0x0E1C); mdelay(1);
  288. rtl8187se_rf_writereg(dev, 0x09, 0x02F0); mdelay(1);
  289. rtl8187se_rf_writereg(dev, 0x0A, 0x09D0); mdelay(1);
  290. rtl8187se_rf_writereg(dev, 0x0B, 0x01BA); mdelay(1);
  291. rtl8187se_rf_writereg(dev, 0x0C, 0x0640); mdelay(1);
  292. rtl8187se_rf_writereg(dev, 0x0D, 0x08DF); mdelay(1);
  293. rtl8187se_rf_writereg(dev, 0x0E, 0x0020); mdelay(1);
  294. rtl8187se_rf_writereg(dev, 0x0F, 0x0990); mdelay(1);
  295. /* page 1: reg 16-30 */
  296. rtl8187se_rf_writereg(dev, 0x00, 0x013F); mdelay(1);
  297. rtl8187se_rf_writereg(dev, 0x03, 0x0806); mdelay(1);
  298. rtl8187se_rf_writereg(dev, 0x04, 0x03A7); mdelay(1);
  299. rtl8187se_rf_writereg(dev, 0x05, 0x059B); mdelay(1);
  300. rtl8187se_rf_writereg(dev, 0x06, 0x0081); mdelay(1);
  301. rtl8187se_rf_writereg(dev, 0x07, 0x01A0); mdelay(1);
  302. rtl8187se_rf_writereg(dev, 0x0A, 0x0001); mdelay(1);
  303. rtl8187se_rf_writereg(dev, 0x0B, 0x0418); mdelay(1);
  304. rtl8187se_rf_writereg(dev, 0x0C, 0x0FBE); mdelay(1);
  305. rtl8187se_rf_writereg(dev, 0x0D, 0x0008); mdelay(1);
  306. if (d_cut)
  307. rtl8187se_rf_writereg(dev, 0x0E, 0x0807);
  308. else
  309. rtl8187se_rf_writereg(dev, 0x0E, 0x0806);
  310. mdelay(1);
  311. rtl8187se_rf_writereg(dev, 0x0F, 0x0ACC); mdelay(1);
  312. rtl8187se_rf_writereg(dev, 0x00, 0x01D7); mdelay(1);
  313. rtl8187se_rf_writereg(dev, 0x03, 0x0E00); mdelay(1);
  314. rtl8187se_rf_writereg(dev, 0x04, 0x0E50); mdelay(1);
  315. rtl8187se_write_rf_gain(dev);
  316. rtl8187se_rf_writereg(dev, 0x05, 0x0203); mdelay(1);
  317. rtl8187se_rf_writereg(dev, 0x06, 0x0200); mdelay(1);
  318. rtl8187se_rf_writereg(dev, 0x00, 0x0137); mdelay(11);
  319. rtl8187se_rf_writereg(dev, 0x0D, 0x0008); mdelay(11);
  320. rtl8187se_rf_writereg(dev, 0x00, 0x0037); mdelay(11);
  321. rtl8187se_rf_writereg(dev, 0x04, 0x0160); mdelay(11);
  322. rtl8187se_rf_writereg(dev, 0x07, 0x0080); mdelay(11);
  323. rtl8187se_rf_writereg(dev, 0x02, 0x088D); msleep(221);
  324. rtl8187se_rf_writereg(dev, 0x00, 0x0137); mdelay(11);
  325. rtl8187se_rf_writereg(dev, 0x07, 0x0000); mdelay(1);
  326. rtl8187se_rf_writereg(dev, 0x07, 0x0180); mdelay(1);
  327. rtl8187se_rf_writereg(dev, 0x07, 0x0220); mdelay(1);
  328. rtl8187se_rf_writereg(dev, 0x07, 0x03E0); mdelay(1);
  329. rtl8187se_rf_writereg(dev, 0x06, 0x00C1); mdelay(1);
  330. rtl8187se_rf_writereg(dev, 0x0A, 0x0001); mdelay(1);
  331. if (priv->xtal_cal) {
  332. tmp = (priv->xtal_in << 4) | (priv->xtal_out << 1) |
  333. (1 << 11) | (1 << 9);
  334. rtl8187se_rf_writereg(dev, 0x0F, tmp);
  335. wiphy_info(dev->wiphy, "Xtal cal\n");
  336. mdelay(1);
  337. } else {
  338. wiphy_info(dev->wiphy, "NO Xtal cal\n");
  339. rtl8187se_rf_writereg(dev, 0x0F, 0x0ACC);
  340. mdelay(1);
  341. }
  342. /* page 0 */
  343. rtl8187se_rf_writereg(dev, 0x00, 0x00BF); mdelay(1);
  344. rtl8187se_rf_writereg(dev, 0x0D, 0x08DF); mdelay(1);
  345. rtl8187se_rf_writereg(dev, 0x02, 0x004D); mdelay(1);
  346. rtl8187se_rf_writereg(dev, 0x04, 0x0975); msleep(31);
  347. rtl8187se_rf_writereg(dev, 0x00, 0x0197); mdelay(1);
  348. rtl8187se_rf_writereg(dev, 0x05, 0x05AB); mdelay(1);
  349. rtl8187se_rf_writereg(dev, 0x00, 0x009F); mdelay(1);
  350. rtl8187se_rf_writereg(dev, 0x01, 0x0000); mdelay(1);
  351. rtl8187se_rf_writereg(dev, 0x02, 0x0000); mdelay(1);
  352. /* power save parameters */
  353. /* TODO: move to dev.c */
  354. rtl818x_iowrite8(priv, REG_ADDR1(0x024E),
  355. rtl818x_ioread8(priv, REG_ADDR1(0x24E)) & 0x9F);
  356. rtl8225se_write_phy_cck(dev, 0x00, 0xC8);
  357. rtl8225se_write_phy_cck(dev, 0x06, 0x1C);
  358. rtl8225se_write_phy_cck(dev, 0x10, 0x78);
  359. rtl8225se_write_phy_cck(dev, 0x2E, 0xD0);
  360. rtl8225se_write_phy_cck(dev, 0x2F, 0x06);
  361. rtl8225se_write_phy_cck(dev, 0x01, 0x46);
  362. /* power control */
  363. rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK, 0x10);
  364. rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM, 0x1B);
  365. rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03);
  366. rtl8225se_write_phy_ofdm(dev, 0x00, 0x12);
  367. rtl8225se_write_zebra_agc(dev);
  368. rtl8225se_write_phy_ofdm(dev, 0x10, 0x00);
  369. rtl8187se_write_ofdm_config(dev);
  370. /* turn on RF */
  371. rtl8187se_rf_writereg(dev, 0x00, 0x009F); udelay(500);
  372. rtl8187se_rf_writereg(dev, 0x04, 0x0972); udelay(500);
  373. /* turn on RF again */
  374. rtl8187se_rf_writereg(dev, 0x00, 0x009F); udelay(500);
  375. rtl8187se_rf_writereg(dev, 0x04, 0x0972); udelay(500);
  376. /* turn on BB */
  377. rtl8225se_write_phy_ofdm(dev, 0x10, 0x40);
  378. rtl8225se_write_phy_ofdm(dev, 0x12, 0x40);
  379. rtl8187se_write_initial_gain(dev, 4);
  380. }
  381. void rtl8225se_rf_stop(struct ieee80211_hw *dev)
  382. {
  383. /* checked for 8187se */
  384. struct rtl8180_priv *priv = dev->priv;
  385. /* turn off BB RXIQ matrix to cut off rx signal */
  386. rtl8225se_write_phy_ofdm(dev, 0x10, 0x00);
  387. rtl8225se_write_phy_ofdm(dev, 0x12, 0x00);
  388. /* turn off RF */
  389. rtl8187se_rf_writereg(dev, 0x04, 0x0000);
  390. rtl8187se_rf_writereg(dev, 0x00, 0x0000);
  391. usleep_range(1000, 5000);
  392. /* turn off A/D and D/A */
  393. rtl8180_set_anaparam(priv, RTL8225SE_ANAPARAM_OFF);
  394. rtl8180_set_anaparam2(priv, RTL8225SE_ANAPARAM2_OFF);
  395. }
  396. void rtl8225se_rf_set_channel(struct ieee80211_hw *dev,
  397. struct ieee80211_conf *conf)
  398. {
  399. int chan =
  400. ieee80211_frequency_to_channel(conf->chandef.chan->center_freq);
  401. rtl8225sez2_rf_set_tx_power(dev, chan);
  402. rtl8187se_rf_writereg(dev, 0x7, rtl8225se_chan[chan - 1]);
  403. if ((rtl8187se_rf_readreg(dev, 0x7) & 0x0F80) !=
  404. rtl8225se_chan[chan - 1])
  405. rtl8187se_rf_writereg(dev, 0x7, rtl8225se_chan[chan - 1]);
  406. usleep_range(10000, 20000);
  407. }
  408. static const struct rtl818x_rf_ops rtl8225se_ops = {
  409. .name = "rtl8225-se",
  410. .init = rtl8225se_rf_init,
  411. .stop = rtl8225se_rf_stop,
  412. .set_chan = rtl8225se_rf_set_channel,
  413. };
  414. const struct rtl818x_rf_ops *rtl8187se_detect_rf(struct ieee80211_hw *dev)
  415. {
  416. return &rtl8225se_ops;
  417. }