phy_lcn.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. static void b43_radio_2064_channel_setup(struct b43_wldev *dev)
  26. {
  27. u16 save[2];
  28. b43_radio_set(dev, 0x09d, 0x4);
  29. b43_radio_write(dev, 0x09e, 0xf);
  30. b43_radio_write(dev, 0x02a, 0xb);
  31. b43_radio_maskset(dev, 0x030, ~0x3, 0xa);
  32. b43_radio_maskset(dev, 0x091, ~0x3, 0);
  33. b43_radio_maskset(dev, 0x038, ~0xf, 0x7);
  34. b43_radio_maskset(dev, 0x030, ~0xc, 0x8);
  35. b43_radio_maskset(dev, 0x05e, ~0xf, 0x8);
  36. b43_radio_maskset(dev, 0x05e, ~0xf0, 0x80);
  37. b43_radio_write(dev, 0x06c, 0x80);
  38. save[0] = b43_radio_read(dev, 0x044);
  39. save[1] = b43_radio_read(dev, 0x12b);
  40. b43_radio_set(dev, 0x044, 0x7);
  41. b43_radio_set(dev, 0x12b, 0xe);
  42. /* TODO */
  43. b43_radio_write(dev, 0x040, 0xfb);
  44. b43_radio_write(dev, 0x041, 0x9a);
  45. b43_radio_write(dev, 0x042, 0xa3);
  46. b43_radio_write(dev, 0x043, 0x0c);
  47. /* TODO */
  48. b43_radio_set(dev, 0x044, 0x0c);
  49. udelay(1);
  50. b43_radio_write(dev, 0x044, save[0]);
  51. b43_radio_write(dev, 0x12b, save[1]);
  52. b43_radio_write(dev, 0x038, 0x0);
  53. b43_radio_write(dev, 0x091, 0x7);
  54. }
  55. static void b43_radio_2064_init(struct b43_wldev *dev)
  56. {
  57. b43_radio_write(dev, 0x09c, 0x0020);
  58. b43_radio_write(dev, 0x105, 0x0008);
  59. b43_radio_write(dev, 0x032, 0x0062);
  60. b43_radio_write(dev, 0x033, 0x0019);
  61. b43_radio_write(dev, 0x090, 0x0010);
  62. b43_radio_write(dev, 0x010, 0x0000);
  63. b43_radio_write(dev, 0x060, 0x007f);
  64. b43_radio_write(dev, 0x061, 0x0072);
  65. b43_radio_write(dev, 0x062, 0x007f);
  66. b43_radio_write(dev, 0x01d, 0x0002);
  67. b43_radio_write(dev, 0x01e, 0x0006);
  68. b43_phy_write(dev, 0x4ea, 0x4688);
  69. b43_phy_maskset(dev, 0x4eb, ~0x7, 0x2);
  70. b43_phy_mask(dev, 0x4eb, ~0x01c0);
  71. b43_phy_maskset(dev, 0x46a, 0xff00, 0x19);
  72. b43_lcntab_write(dev, B43_LCNTAB16(0x00, 0x55), 0);
  73. b43_radio_mask(dev, 0x05b, (u16) ~0xff02);
  74. b43_radio_set(dev, 0x004, 0x40);
  75. b43_radio_set(dev, 0x120, 0x10);
  76. b43_radio_set(dev, 0x078, 0x80);
  77. b43_radio_set(dev, 0x129, 0x2);
  78. b43_radio_set(dev, 0x057, 0x1);
  79. b43_radio_set(dev, 0x05b, 0x2);
  80. /* TODO: wait for some bit to be set */
  81. b43_radio_read(dev, 0x05c);
  82. b43_radio_mask(dev, 0x05b, (u16) ~0xff02);
  83. b43_radio_mask(dev, 0x057, (u16) ~0xff01);
  84. b43_phy_write(dev, 0x933, 0x2d6b);
  85. b43_phy_write(dev, 0x934, 0x2d6b);
  86. b43_phy_write(dev, 0x935, 0x2d6b);
  87. b43_phy_write(dev, 0x936, 0x2d6b);
  88. b43_phy_write(dev, 0x937, 0x016b);
  89. b43_radio_mask(dev, 0x057, (u16) ~0xff02);
  90. b43_radio_write(dev, 0x0c2, 0x006f);
  91. }
  92. /**************************************************
  93. * Various PHY ops
  94. **************************************************/
  95. static void b43_phy_lcn_afe_set_unset(struct b43_wldev *dev)
  96. {
  97. u16 afe_ctl2 = b43_phy_read(dev, B43_PHY_LCN_AFE_CTL2);
  98. u16 afe_ctl1 = b43_phy_read(dev, B43_PHY_LCN_AFE_CTL1);
  99. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2 | 0x1);
  100. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1 | 0x1);
  101. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2 & ~0x1);
  102. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1 & ~0x1);
  103. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL2, afe_ctl2);
  104. b43_phy_write(dev, B43_PHY_LCN_AFE_CTL1, afe_ctl1);
  105. }
  106. static void b43_phy_lcn_clean_0x18_table(struct b43_wldev *dev)
  107. {
  108. u8 i;
  109. for (i = 0; i < 0x80; i++)
  110. b43_lcntab_write(dev, B43_LCNTAB32(0x18, i), 0x80000);
  111. }
  112. static void b43_phy_lcn_clear_0x07_table(struct b43_wldev *dev)
  113. {
  114. u8 i;
  115. b43_phy_write(dev, B43_PHY_LCN_TABLE_ADDR, (0x7 << 10) | 0x340);
  116. for (i = 0; i < 30; i++) {
  117. b43_phy_write(dev, B43_PHY_LCN_TABLE_DATAHI, 0);
  118. b43_phy_write(dev, B43_PHY_LCN_TABLE_DATALO, 0);
  119. }
  120. b43_phy_write(dev, B43_PHY_LCN_TABLE_ADDR, (0x7 << 10) | 0x80);
  121. for (i = 0; i < 64; i++) {
  122. b43_phy_write(dev, B43_PHY_LCN_TABLE_DATAHI, 0);
  123. b43_phy_write(dev, B43_PHY_LCN_TABLE_DATALO, 0);
  124. }
  125. }
  126. static void b43_phy_lcn_pre_radio_init(struct b43_wldev *dev)
  127. {
  128. b43_radio_write(dev, 0x11c, 0);
  129. b43_phy_write(dev, 0x43b, 0);
  130. b43_phy_write(dev, 0x43c, 0);
  131. b43_phy_write(dev, 0x44c, 0);
  132. b43_phy_write(dev, 0x4e6, 0);
  133. b43_phy_write(dev, 0x4f9, 0);
  134. b43_phy_write(dev, 0x4b0, 0);
  135. b43_phy_write(dev, 0x938, 0);
  136. b43_phy_write(dev, 0x4b0, 0);
  137. b43_phy_write(dev, 0x44e, 0);
  138. b43_phy_set(dev, 0x567, 0x03);
  139. b43_phy_set(dev, 0x44a, 0x44);
  140. b43_phy_write(dev, 0x44a, 0x80);
  141. b43_phy_maskset(dev, 0x634, ~0xff, 0xc);
  142. b43_phy_maskset(dev, 0x634, ~0xff, 0xa);
  143. b43_phy_write(dev, 0x910, 0x1);
  144. b43_phy_maskset(dev, 0x448, ~0x300, 0x100);
  145. b43_phy_maskset(dev, 0x608, ~0xff, 0x17);
  146. b43_phy_maskset(dev, 0x604, ~0x7ff, 0x3ea);
  147. b43_phy_set(dev, 0x805, 0x1);
  148. b43_phy_maskset(dev, 0x42f, ~0x7, 0x3);
  149. b43_phy_maskset(dev, 0x030, ~0x7, 0x3);
  150. b43_phy_write(dev, 0x414, 0x1e10);
  151. b43_phy_write(dev, 0x415, 0x0640);
  152. b43_phy_maskset(dev, 0x4df, (u16) ~0xff00, 0xf700);
  153. b43_phy_set(dev, 0x44a, 0x44);
  154. b43_phy_write(dev, 0x44a, 0x80);
  155. b43_phy_maskset(dev, 0x434, ~0xff, 0xfd);
  156. b43_phy_maskset(dev, 0x420, ~0xff, 0x10);
  157. b43_radio_set(dev, 0x09b, 0xf0);
  158. b43_phy_write(dev, 0x7d6, 0x0902);
  159. /* TODO: more ops */
  160. }
  161. /**************************************************
  162. * Channel switching ops.
  163. **************************************************/
  164. static int b43_phy_lcn_set_channel(struct b43_wldev *dev,
  165. struct ieee80211_channel *channel,
  166. enum nl80211_channel_type channel_type)
  167. {
  168. /* TODO: PLL and PHY ops */
  169. b43_phy_set(dev, 0x44a, 0x44);
  170. b43_phy_write(dev, 0x44a, 0x80);
  171. b43_phy_set(dev, 0x44a, 0x44);
  172. b43_phy_write(dev, 0x44a, 0x80);
  173. b43_radio_2064_channel_setup(dev);
  174. mdelay(1);
  175. b43_phy_lcn_afe_set_unset(dev);
  176. /* TODO */
  177. return 0;
  178. }
  179. /**************************************************
  180. * Basic PHY ops.
  181. **************************************************/
  182. static int b43_phy_lcn_op_allocate(struct b43_wldev *dev)
  183. {
  184. struct b43_phy_lcn *phy_lcn;
  185. phy_lcn = kzalloc(sizeof(*phy_lcn), GFP_KERNEL);
  186. if (!phy_lcn)
  187. return -ENOMEM;
  188. dev->phy.lcn = phy_lcn;
  189. return 0;
  190. }
  191. static void b43_phy_lcn_op_free(struct b43_wldev *dev)
  192. {
  193. struct b43_phy *phy = &dev->phy;
  194. struct b43_phy_lcn *phy_lcn = phy->lcn;
  195. kfree(phy_lcn);
  196. phy->lcn = NULL;
  197. }
  198. static void b43_phy_lcn_op_prepare_structs(struct b43_wldev *dev)
  199. {
  200. struct b43_phy *phy = &dev->phy;
  201. struct b43_phy_lcn *phy_lcn = phy->lcn;
  202. memset(phy_lcn, 0, sizeof(*phy_lcn));
  203. }
  204. static int b43_phy_lcn_op_init(struct b43_wldev *dev)
  205. {
  206. b43_phy_set(dev, 0x44a, 0x80);
  207. b43_phy_mask(dev, 0x44a, 0x7f);
  208. b43_phy_set(dev, 0x6d1, 0x80);
  209. b43_phy_write(dev, 0x6d0, 0x7);
  210. b43_phy_lcn_afe_set_unset(dev);
  211. b43_phy_write(dev, 0x60a, 0xa0);
  212. b43_phy_write(dev, 0x46a, 0x19);
  213. b43_phy_maskset(dev, 0x663, 0xFF00, 0x64);
  214. b43_phy_lcn_tables_init(dev);
  215. /* TODO: various tables ops here */
  216. b43_phy_lcn_clean_0x18_table(dev);
  217. b43_phy_lcn_pre_radio_init(dev);
  218. b43_phy_lcn_clear_0x07_table(dev);
  219. if (dev->phy.radio_ver == 0x2064)
  220. b43_radio_2064_init(dev);
  221. else
  222. B43_WARN_ON(1);
  223. return 0;
  224. }
  225. static void b43_phy_lcn_op_software_rfkill(struct b43_wldev *dev,
  226. bool blocked)
  227. {
  228. if (b43_read32(dev, B43_MMIO_MACCTL) & B43_MACCTL_ENABLED)
  229. b43err(dev->wl, "MAC not suspended\n");
  230. if (blocked) {
  231. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL2, ~0x7c00);
  232. b43_phy_set(dev, B43_PHY_LCN_RF_CTL1, 0x1f00);
  233. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL5, ~0x7f00);
  234. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL4, ~0x2);
  235. b43_phy_set(dev, B43_PHY_LCN_RF_CTL3, 0x808);
  236. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL7, ~0x8);
  237. b43_phy_set(dev, B43_PHY_LCN_RF_CTL6, 0x8);
  238. } else {
  239. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL1, ~0x1f00);
  240. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL3, ~0x808);
  241. b43_phy_mask(dev, B43_PHY_LCN_RF_CTL6, ~0x8);
  242. }
  243. }
  244. static void b43_phy_lcn_op_switch_analog(struct b43_wldev *dev, bool on)
  245. {
  246. if (on) {
  247. b43_phy_mask(dev, B43_PHY_LCN_AFE_CTL1, ~0x7);
  248. } else {
  249. b43_phy_set(dev, B43_PHY_LCN_AFE_CTL2, 0x7);
  250. b43_phy_set(dev, B43_PHY_LCN_AFE_CTL1, 0x7);
  251. }
  252. }
  253. static int b43_phy_lcn_op_switch_channel(struct b43_wldev *dev,
  254. unsigned int new_channel)
  255. {
  256. struct ieee80211_channel *channel = dev->wl->hw->conf.channel;
  257. enum nl80211_channel_type channel_type = dev->wl->hw->conf.channel_type;
  258. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
  259. if ((new_channel < 1) || (new_channel > 14))
  260. return -EINVAL;
  261. } else {
  262. return -EINVAL;
  263. }
  264. return b43_phy_lcn_set_channel(dev, channel, channel_type);
  265. }
  266. static unsigned int b43_phy_lcn_op_get_default_chan(struct b43_wldev *dev)
  267. {
  268. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
  269. return 1;
  270. return 36;
  271. }
  272. static enum b43_txpwr_result
  273. b43_phy_lcn_op_recalc_txpower(struct b43_wldev *dev, bool ignore_tssi)
  274. {
  275. return B43_TXPWR_RES_DONE;
  276. }
  277. static void b43_phy_lcn_op_adjust_txpower(struct b43_wldev *dev)
  278. {
  279. }
  280. /**************************************************
  281. * R/W ops.
  282. **************************************************/
  283. static u16 b43_phy_lcn_op_read(struct b43_wldev *dev, u16 reg)
  284. {
  285. b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
  286. return b43_read16(dev, B43_MMIO_PHY_DATA);
  287. }
  288. static void b43_phy_lcn_op_write(struct b43_wldev *dev, u16 reg, u16 value)
  289. {
  290. b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
  291. b43_write16(dev, B43_MMIO_PHY_DATA, value);
  292. }
  293. static void b43_phy_lcn_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
  294. u16 set)
  295. {
  296. b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
  297. b43_write16(dev, B43_MMIO_PHY_DATA,
  298. (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
  299. }
  300. static u16 b43_phy_lcn_op_radio_read(struct b43_wldev *dev, u16 reg)
  301. {
  302. /* LCN-PHY needs 0x200 for read access */
  303. reg |= 0x200;
  304. b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
  305. return b43_read16(dev, B43_MMIO_RADIO24_DATA);
  306. }
  307. static void b43_phy_lcn_op_radio_write(struct b43_wldev *dev, u16 reg,
  308. u16 value)
  309. {
  310. b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
  311. b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
  312. }
  313. /**************************************************
  314. * PHY ops struct.
  315. **************************************************/
  316. const struct b43_phy_operations b43_phyops_lcn = {
  317. .allocate = b43_phy_lcn_op_allocate,
  318. .free = b43_phy_lcn_op_free,
  319. .prepare_structs = b43_phy_lcn_op_prepare_structs,
  320. .init = b43_phy_lcn_op_init,
  321. .phy_read = b43_phy_lcn_op_read,
  322. .phy_write = b43_phy_lcn_op_write,
  323. .phy_maskset = b43_phy_lcn_op_maskset,
  324. .radio_read = b43_phy_lcn_op_radio_read,
  325. .radio_write = b43_phy_lcn_op_radio_write,
  326. .software_rfkill = b43_phy_lcn_op_software_rfkill,
  327. .switch_analog = b43_phy_lcn_op_switch_analog,
  328. .switch_channel = b43_phy_lcn_op_switch_channel,
  329. .get_default_chan = b43_phy_lcn_op_get_default_chan,
  330. .recalc_txpower = b43_phy_lcn_op_recalc_txpower,
  331. .adjust_txpower = b43_phy_lcn_op_adjust_txpower,
  332. };