phy_lcn.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*
  2. Broadcom B43 wireless driver
  3. IEEE 802.11n LCN-PHY support
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <linux/slab.h>
  18. #include "b43.h"
  19. #include "phy_lcn.h"
  20. #include "tables_phy_lcn.h"
  21. #include "main.h"
  22. /**************************************************
  23. * Radio 2064.
  24. **************************************************/
  25. /* wlc_lcnphy_radio_2064_channel_tune_4313 */
  26. static void b43_radio_2064_channel_setup(struct b43_wldev *dev)
  27. {
  28. u16 save[2];
  29. b43_radio_set(dev, 0x09d, 0x4);
  30. b43_radio_write(dev, 0x09e, 0xf);
  31. /* Channel specific values in theory, in practice always the same */
  32. b43_radio_write(dev, 0x02a, 0xb);
  33. b43_radio_maskset(dev, 0x030, ~0x3, 0xa);
  34. b43_radio_maskset(dev, 0x091, ~0x3, 0);
  35. b43_radio_maskset(dev, 0x038, ~0xf, 0x7);
  36. b43_radio_maskset(dev, 0x030, ~0xc, 0x8);
  37. b43_radio_maskset(dev, 0x05e, ~0xf, 0x8);
  38. b43_radio_maskset(dev, 0x05e, ~0xf0, 0x80);
  39. b43_radio_write(dev, 0x06c, 0x80);
  40. save[0] = b43_radio_read(dev, 0x044);
  41. save[1] = b43_radio_read(dev, 0x12b);
  42. b43_radio_set(dev, 0x044, 0x7);
  43. b43_radio_set(dev, 0x12b, 0xe);
  44. /* TODO */
  45. b43_radio_write(dev, 0x040, 0xfb);
  46. b43_radio_write(dev, 0x041, 0x9a);
  47. b43_radio_write(dev, 0x042, 0xa3);
  48. b43_radio_write(dev, 0x043, 0x0c);
  49. /* TODO */
  50. b43_radio_set(dev, 0x044, 0x0c);
  51. udelay(1);
  52. b43_radio_write(dev, 0x044, save[0]);
  53. b43_radio_write(dev, 0x12b, save[1]);
  54. if (dev->phy.rev == 1) {
  55. /* brcmsmac uses outdated 0x3 for 0x038 */
  56. b43_radio_write(dev, 0x038, 0x0);
  57. b43_radio_write(dev, 0x091, 0x7);
  58. }
  59. }
  60. /* wlc_radio_2064_init */
  61. static void b43_radio_2064_init(struct b43_wldev *dev)
  62. {
  63. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
  64. b43_radio_write(dev, 0x09c, 0x0020);
  65. b43_radio_write(dev, 0x105, 0x0008);
  66. } else {
  67. /* TODO */
  68. }
  69. b43_radio_write(dev, 0x032, 0x0062);
  70. b43_radio_write(dev, 0x033, 0x0019);
  71. b43_radio_write(dev, 0x090, 0x0010);
  72. b43_radio_write(dev, 0x010, 0x0000);
  73. if (dev->phy.rev == 1) {
  74. b43_radio_write(dev, 0x060, 0x007f);
  75. b43_radio_write(dev, 0x061, 0x0072);
  76. b43_radio_write(dev, 0x062, 0x007f);
  77. }
  78. b43_radio_write(dev, 0x01d, 0x0002);
  79. b43_radio_write(dev, 0x01e, 0x0006);
  80. b43_phy_write(dev, 0x4ea, 0x4688);
  81. b43_phy_maskset(dev, 0x4eb, ~0x7, 0x2);
  82. b43_phy_mask(dev, 0x4eb, ~0x01c0);
  83. b43_phy_maskset(dev, 0x46a, 0xff00, 0x19);
  84. b43_lcntab_write(dev, B43_LCNTAB16(0x00, 0x55), 0);
  85. b43_radio_mask(dev, 0x05b, (u16) ~0xff02);
  86. b43_radio_set(dev, 0x004, 0x40);
  87. b43_radio_set(dev, 0x120, 0x10);
  88. b43_radio_set(dev, 0x078, 0x80);
  89. b43_radio_set(dev, 0x129, 0x2);
  90. b43_radio_set(dev, 0x057, 0x1);
  91. b43_radio_set(dev, 0x05b, 0x2);
  92. /* TODO: wait for some bit to be set */
  93. b43_radio_read(dev, 0x05c);
  94. b43_radio_mask(dev, 0x05b, (u16) ~0xff02);
  95. b43_radio_mask(dev, 0x057, (u16) ~0xff01);
  96. b43_phy_write(dev, 0x933, 0x2d6b);
  97. b43_phy_write(dev, 0x934, 0x2d6b);
  98. b43_phy_write(dev, 0x935, 0x2d6b);
  99. b43_phy_write(dev, 0x936, 0x2d6b);
  100. b43_phy_write(dev, 0x937, 0x016b);
  101. b43_radio_mask(dev, 0x057, (u16) ~0xff02);
  102. b43_radio_write(dev, 0x0c2, 0x006f);
  103. }
  104. /**************************************************
  105. * Various PHY ops
  106. **************************************************/
  107. /* wlc_lcnphy_toggle_afe_pwdn */
  108. static void b43_phy_lcn_afe_set_unset(struct b43_wldev *dev)
  109. {
  110. u16 afe_ctl2 = b43_phy_read(dev, B43_PHY_LCN_AFE_CTL2);
  111. u16 afe_ctl1 = b43_phy_read(dev, B43_PHY_LCN_AFE_CTL1);
  112. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2 | 0x1);
  113. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1 | 0x1);
  114. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2 & ~0x1);
  115. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1 & ~0x1);
  116. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2);
  117. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1);
  118. }
  119. /* wlc_lcnphy_clear_tx_power_offsets */
  120. static void b43_phy_lcn_clear_tx_power_offsets(struct b43_wldev *dev)
  121. {
  122. u8 i;
  123. if (1) { /* FIXME */
  124. b43_phy_write(dev, B43_PHY_LCN_TABLE_ADDR, (0x7 << 10) | 0x340);
  125. for (i = 0; i < 30; i++) {
  126. b43_phy_write(dev, B43_PHY_LCN_TABLE_DATAHI, 0);
  127. b43_phy_write(dev, B43_PHY_LCN_TABLE_DATALO, 0);
  128. }
  129. }
  130. b43_phy_write(dev, B43_PHY_LCN_TABLE_ADDR, (0x7 << 10) | 0x80);
  131. for (i = 0; i < 64; i++) {
  132. b43_phy_write(dev, B43_PHY_LCN_TABLE_DATAHI, 0);
  133. b43_phy_write(dev, B43_PHY_LCN_TABLE_DATALO, 0);
  134. }
  135. }
  136. /* wlc_lcnphy_rev0_baseband_init */
  137. static void b43_phy_lcn_rev0_baseband_init(struct b43_wldev *dev)
  138. {
  139. b43_radio_write(dev, 0x11c, 0);
  140. b43_phy_write(dev, 0x43b, 0);
  141. b43_phy_write(dev, 0x43c, 0);
  142. b43_phy_write(dev, 0x44c, 0);
  143. b43_phy_write(dev, 0x4e6, 0);
  144. b43_phy_write(dev, 0x4f9, 0);
  145. b43_phy_write(dev, 0x4b0, 0);
  146. b43_phy_write(dev, 0x938, 0);
  147. b43_phy_write(dev, 0x4b0, 0);
  148. b43_phy_write(dev, 0x44e, 0);
  149. b43_phy_set(dev, 0x567, 0x03);
  150. b43_phy_set(dev, 0x44a, 0x44);
  151. b43_phy_write(dev, 0x44a, 0x80);
  152. if (!(dev->dev->bus_sprom->boardflags_lo & B43_BFL_FEM))
  153. ; /* TODO */
  154. b43_phy_maskset(dev, 0x634, ~0xff, 0xc);
  155. if (dev->dev->bus_sprom->boardflags_lo & B43_BFL_FEM) {
  156. b43_phy_maskset(dev, 0x634, ~0xff, 0xa);
  157. b43_phy_write(dev, 0x910, 0x1);
  158. }
  159. b43_phy_write(dev, 0x910, 0x1);
  160. b43_phy_maskset(dev, 0x448, ~0x300, 0x100);
  161. b43_phy_maskset(dev, 0x608, ~0xff, 0x17);
  162. b43_phy_maskset(dev, 0x604, ~0x7ff, 0x3ea);
  163. }
  164. /* wlc_lcnphy_bu_tweaks */
  165. static void b43_phy_lcn_bu_tweaks(struct b43_wldev *dev)
  166. {
  167. b43_phy_set(dev, 0x805, 0x1);
  168. b43_phy_maskset(dev, 0x42f, ~0x7, 0x3);
  169. b43_phy_maskset(dev, 0x030, ~0x7, 0x3);
  170. b43_phy_write(dev, 0x414, 0x1e10);
  171. b43_phy_write(dev, 0x415, 0x0640);
  172. b43_phy_maskset(dev, 0x4df, (u16) ~0xff00, 0xf700);
  173. b43_phy_set(dev, 0x44a, 0x44);
  174. b43_phy_write(dev, 0x44a, 0x80);
  175. b43_phy_maskset(dev, 0x434, ~0xff, 0xfd);
  176. b43_phy_maskset(dev, 0x420, ~0xff, 0x10);
  177. if (dev->dev->bus_sprom->board_rev >= 0x1204)
  178. b43_radio_set(dev, 0x09b, 0xf0);
  179. b43_phy_write(dev, 0x7d6, 0x0902);
  180. /* TODO: more ops */
  181. if (dev->phy.rev == 1) {
  182. /* TODO: more ops */
  183. b43_phy_lcn_clear_tx_power_offsets(dev);
  184. }
  185. }
  186. /* wlc_lcnphy_vbat_temp_sense_setup */
  187. static void b43_phy_lcn_sense_setup(struct b43_wldev *dev)
  188. {
  189. u8 i;
  190. u16 save_radio_regs[6][2] = {
  191. { 0x007, 0 }, { 0x0ff, 0 }, { 0x11f, 0 }, { 0x005, 0 },
  192. { 0x025, 0 }, { 0x112, 0 },
  193. };
  194. u16 save_phy_regs[14][2] = {
  195. { 0x503, 0 }, { 0x4a4, 0 }, { 0x4d0, 0 }, { 0x4d9, 0 },
  196. { 0x4da, 0 }, { 0x4a6, 0 }, { 0x938, 0 }, { 0x939, 0 },
  197. { 0x4d8, 0 }, { 0x4d0, 0 }, { 0x4d7, 0 }, { 0x4a5, 0 },
  198. { 0x40d, 0 }, { 0x4a2, 0 },
  199. };
  200. u16 save_radio_4a4;
  201. for (i = 0; i < 6; i++)
  202. save_radio_regs[i][1] = b43_radio_read(dev,
  203. save_radio_regs[i][0]);
  204. for (i = 0; i < 14; i++)
  205. save_phy_regs[i][1] = b43_phy_read(dev, save_phy_regs[i][0]);
  206. save_radio_4a4 = b43_radio_read(dev, 0x4a4);
  207. /* TODO: config sth */
  208. for (i = 0; i < 6; i++)
  209. b43_radio_write(dev, save_radio_regs[i][0],
  210. save_radio_regs[i][1]);
  211. for (i = 0; i < 14; i++)
  212. b43_phy_write(dev, save_phy_regs[i][0], save_phy_regs[i][1]);
  213. b43_radio_write(dev, 0x4a4, save_radio_4a4);
  214. }
  215. /**************************************************
  216. * Channel switching ops.
  217. **************************************************/
  218. static int b43_phy_lcn_set_channel(struct b43_wldev *dev,
  219. struct ieee80211_channel *channel,
  220. enum nl80211_channel_type channel_type)
  221. {
  222. /* TODO: PLL and PHY ops */
  223. b43_phy_set(dev, 0x44a, 0x44);
  224. b43_phy_write(dev, 0x44a, 0x80);
  225. b43_phy_set(dev, 0x44a, 0x44);
  226. b43_phy_write(dev, 0x44a, 0x80);
  227. b43_radio_2064_channel_setup(dev);
  228. mdelay(1);
  229. b43_phy_lcn_afe_set_unset(dev);
  230. /* TODO */
  231. return 0;
  232. }
  233. /**************************************************
  234. * Basic PHY ops.
  235. **************************************************/
  236. static int b43_phy_lcn_op_allocate(struct b43_wldev *dev)
  237. {
  238. struct b43_phy_lcn *phy_lcn;
  239. phy_lcn = kzalloc(sizeof(*phy_lcn), GFP_KERNEL);
  240. if (!phy_lcn)
  241. return -ENOMEM;
  242. dev->phy.lcn = phy_lcn;
  243. return 0;
  244. }
  245. static void b43_phy_lcn_op_free(struct b43_wldev *dev)
  246. {
  247. struct b43_phy *phy = &dev->phy;
  248. struct b43_phy_lcn *phy_lcn = phy->lcn;
  249. kfree(phy_lcn);
  250. phy->lcn = NULL;
  251. }
  252. static void b43_phy_lcn_op_prepare_structs(struct b43_wldev *dev)
  253. {
  254. struct b43_phy *phy = &dev->phy;
  255. struct b43_phy_lcn *phy_lcn = phy->lcn;
  256. memset(phy_lcn, 0, sizeof(*phy_lcn));
  257. }
  258. /* wlc_phy_init_lcnphy */
  259. static int b43_phy_lcn_op_init(struct b43_wldev *dev)
  260. {
  261. b43_phy_set(dev, 0x44a, 0x80);
  262. b43_phy_mask(dev, 0x44a, 0x7f);
  263. b43_phy_set(dev, 0x6d1, 0x80);
  264. b43_phy_write(dev, 0x6d0, 0x7);
  265. b43_phy_lcn_afe_set_unset(dev);
  266. b43_phy_write(dev, 0x60a, 0xa0);
  267. b43_phy_write(dev, 0x46a, 0x19);
  268. b43_phy_maskset(dev, 0x663, 0xFF00, 0x64);
  269. b43_phy_lcn_tables_init(dev);
  270. b43_phy_lcn_rev0_baseband_init(dev);
  271. b43_phy_lcn_bu_tweaks(dev);
  272. if (dev->phy.radio_ver == 0x2064)
  273. b43_radio_2064_init(dev);
  274. else
  275. B43_WARN_ON(1);
  276. b43_phy_lcn_sense_setup(dev);
  277. return 0;
  278. }
  279. static void b43_phy_lcn_op_software_rfkill(struct b43_wldev *dev,
  280. bool blocked)
  281. {
  282. if (b43_read32(dev, B43_MMIO_MACCTL) & B43_MACCTL_ENABLED)
  283. b43err(dev->wl, "MAC not suspended\n");
  284. if (blocked) {
  285. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL2, ~0x7c00);
  286. b43_phy_set(dev, B43_PHY_LCN_RF_CTL1, 0x1f00);
  287. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL5, ~0x7f00);
  288. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL4, ~0x2);
  289. b43_phy_set(dev, B43_PHY_LCN_RF_CTL3, 0x808);
  290. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL7, ~0x8);
  291. b43_phy_set(dev, B43_PHY_LCN_RF_CTL6, 0x8);
  292. } else {
  293. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL1, ~0x1f00);
  294. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL3, ~0x808);
  295. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL6, ~0x8);
  296. }
  297. }
  298. static void b43_phy_lcn_op_switch_analog(struct b43_wldev *dev, bool on)
  299. {
  300. if (on) {
  301. b43_phy_mask(dev, B43_PHY_LCN_AFE_CTL1, ~0x7);
  302. } else {
  303. b43_phy_set(dev, B43_PHY_LCN_AFE_CTL2, 0x7);
  304. b43_phy_set(dev, B43_PHY_LCN_AFE_CTL1, 0x7);
  305. }
  306. }
  307. static int b43_phy_lcn_op_switch_channel(struct b43_wldev *dev,
  308. unsigned int new_channel)
  309. {
  310. struct ieee80211_channel *channel = dev->wl->hw->conf.channel;
  311. enum nl80211_channel_type channel_type = dev->wl->hw->conf.channel_type;
  312. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
  313. if ((new_channel < 1) || (new_channel > 14))
  314. return -EINVAL;
  315. } else {
  316. return -EINVAL;
  317. }
  318. return b43_phy_lcn_set_channel(dev, channel, channel_type);
  319. }
  320. static unsigned int b43_phy_lcn_op_get_default_chan(struct b43_wldev *dev)
  321. {
  322. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
  323. return 1;
  324. return 36;
  325. }
  326. static enum b43_txpwr_result
  327. b43_phy_lcn_op_recalc_txpower(struct b43_wldev *dev, bool ignore_tssi)
  328. {
  329. return B43_TXPWR_RES_DONE;
  330. }
  331. static void b43_phy_lcn_op_adjust_txpower(struct b43_wldev *dev)
  332. {
  333. }
  334. /**************************************************
  335. * R/W ops.
  336. **************************************************/
  337. static u16 b43_phy_lcn_op_read(struct b43_wldev *dev, u16 reg)
  338. {
  339. b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
  340. return b43_read16(dev, B43_MMIO_PHY_DATA);
  341. }
  342. static void b43_phy_lcn_op_write(struct b43_wldev *dev, u16 reg, u16 value)
  343. {
  344. b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
  345. b43_write16(dev, B43_MMIO_PHY_DATA, value);
  346. }
  347. static void b43_phy_lcn_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
  348. u16 set)
  349. {
  350. b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
  351. b43_write16(dev, B43_MMIO_PHY_DATA,
  352. (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
  353. }
  354. static u16 b43_phy_lcn_op_radio_read(struct b43_wldev *dev, u16 reg)
  355. {
  356. /* LCN-PHY needs 0x200 for read access */
  357. reg |= 0x200;
  358. b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
  359. return b43_read16(dev, B43_MMIO_RADIO24_DATA);
  360. }
  361. static void b43_phy_lcn_op_radio_write(struct b43_wldev *dev, u16 reg,
  362. u16 value)
  363. {
  364. b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
  365. b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
  366. }
  367. /**************************************************
  368. * PHY ops struct.
  369. **************************************************/
  370. const struct b43_phy_operations b43_phyops_lcn = {
  371. .allocate = b43_phy_lcn_op_allocate,
  372. .free = b43_phy_lcn_op_free,
  373. .prepare_structs = b43_phy_lcn_op_prepare_structs,
  374. .init = b43_phy_lcn_op_init,
  375. .phy_read = b43_phy_lcn_op_read,
  376. .phy_write = b43_phy_lcn_op_write,
  377. .phy_maskset = b43_phy_lcn_op_maskset,
  378. .radio_read = b43_phy_lcn_op_radio_read,
  379. .radio_write = b43_phy_lcn_op_radio_write,
  380. .software_rfkill = b43_phy_lcn_op_software_rfkill,
  381. .switch_analog = b43_phy_lcn_op_switch_analog,
  382. .switch_channel = b43_phy_lcn_op_switch_channel,
  383. .get_default_chan = b43_phy_lcn_op_get_default_chan,
  384. .recalc_txpower = b43_phy_lcn_op_recalc_txpower,
  385. .adjust_txpower = b43_phy_lcn_op_adjust_txpower,
  386. };