phy_ht.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /*
  2. Broadcom B43 wireless driver
  3. IEEE 802.11n HT-PHY support
  4. Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; see the file COPYING. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include <linux/slab.h>
  19. #include "b43.h"
  20. #include "phy_ht.h"
  21. #include "tables_phy_ht.h"
  22. #include "radio_2059.h"
  23. #include "main.h"
  24. /* Force values to keep compatibility with wl */
  25. enum ht_rssi_type {
  26. HT_RSSI_W1 = 0,
  27. HT_RSSI_W2 = 1,
  28. HT_RSSI_NB = 2,
  29. HT_RSSI_IQ = 3,
  30. HT_RSSI_TSSI_2G = 4,
  31. HT_RSSI_TSSI_5G = 5,
  32. HT_RSSI_TBD = 6,
  33. };
  34. /**************************************************
  35. * Radio 2059.
  36. **************************************************/
  37. static void b43_radio_2059_channel_setup(struct b43_wldev *dev,
  38. const struct b43_phy_ht_channeltab_e_radio2059 *e)
  39. {
  40. static const u16 routing[] = { R2059_C1, R2059_C2, R2059_C3, };
  41. u16 r;
  42. int core;
  43. b43_radio_write(dev, 0x16, e->radio_syn16);
  44. b43_radio_write(dev, 0x17, e->radio_syn17);
  45. b43_radio_write(dev, 0x22, e->radio_syn22);
  46. b43_radio_write(dev, 0x25, e->radio_syn25);
  47. b43_radio_write(dev, 0x27, e->radio_syn27);
  48. b43_radio_write(dev, 0x28, e->radio_syn28);
  49. b43_radio_write(dev, 0x29, e->radio_syn29);
  50. b43_radio_write(dev, 0x2c, e->radio_syn2c);
  51. b43_radio_write(dev, 0x2d, e->radio_syn2d);
  52. b43_radio_write(dev, 0x37, e->radio_syn37);
  53. b43_radio_write(dev, 0x41, e->radio_syn41);
  54. b43_radio_write(dev, 0x43, e->radio_syn43);
  55. b43_radio_write(dev, 0x47, e->radio_syn47);
  56. for (core = 0; core < 3; core++) {
  57. r = routing[core];
  58. b43_radio_write(dev, r | 0x4a, e->radio_rxtx4a);
  59. b43_radio_write(dev, r | 0x58, e->radio_rxtx58);
  60. b43_radio_write(dev, r | 0x5a, e->radio_rxtx5a);
  61. b43_radio_write(dev, r | 0x6a, e->radio_rxtx6a);
  62. b43_radio_write(dev, r | 0x6d, e->radio_rxtx6d);
  63. b43_radio_write(dev, r | 0x6e, e->radio_rxtx6e);
  64. b43_radio_write(dev, r | 0x92, e->radio_rxtx92);
  65. b43_radio_write(dev, r | 0x98, e->radio_rxtx98);
  66. }
  67. udelay(50);
  68. /* Calibration */
  69. b43_radio_mask(dev, R2059_RFPLL_MISC_EN, ~0x1);
  70. b43_radio_mask(dev, R2059_RFPLL_MISC_CAL_RESETN, ~0x4);
  71. b43_radio_set(dev, R2059_RFPLL_MISC_CAL_RESETN, 0x4);
  72. b43_radio_set(dev, R2059_RFPLL_MISC_EN, 0x1);
  73. udelay(300);
  74. }
  75. /* Calibrate resistors in LPF of PLL? */
  76. static void b43_radio_2059_rcal(struct b43_wldev *dev)
  77. {
  78. /* Enable */
  79. b43_radio_set(dev, R2059_C3 | R2059_RCAL_CONFIG, 0x1);
  80. usleep_range(10, 20);
  81. b43_radio_set(dev, R2059_C3 | 0x0BF, 0x1);
  82. b43_radio_maskset(dev, R2059_C3 | 0x19B, 0x3, 0x2);
  83. /* Start */
  84. b43_radio_set(dev, R2059_C3 | R2059_RCAL_CONFIG, 0x2);
  85. usleep_range(100, 200);
  86. /* Stop */
  87. b43_radio_mask(dev, R2059_C3 | R2059_RCAL_CONFIG, ~0x2);
  88. if (!b43_radio_wait_value(dev, R2059_C3 | R2059_RCAL_STATUS, 1, 1, 100,
  89. 1000000))
  90. b43err(dev->wl, "Radio 0x2059 rcal timeout\n");
  91. /* Disable */
  92. b43_radio_mask(dev, R2059_C3 | R2059_RCAL_CONFIG, ~0x1);
  93. b43_radio_set(dev, 0xa, 0x60);
  94. }
  95. /* Calibrate the internal RC oscillator? */
  96. static void b43_radio_2057_rccal(struct b43_wldev *dev)
  97. {
  98. const u16 radio_values[3][2] = {
  99. { 0x61, 0xE9 }, { 0x69, 0xD5 }, { 0x73, 0x99 },
  100. };
  101. int i;
  102. for (i = 0; i < 3; i++) {
  103. b43_radio_write(dev, R2059_RCCAL_MASTER, radio_values[i][0]);
  104. b43_radio_write(dev, R2059_RCCAL_X1, 0x6E);
  105. b43_radio_write(dev, R2059_RCCAL_TRC0, radio_values[i][1]);
  106. /* Start */
  107. b43_radio_write(dev, R2059_RCCAL_START_R1_Q1_P1, 0x55);
  108. /* Wait */
  109. if (!b43_radio_wait_value(dev, R2059_RCCAL_DONE_OSCCAP, 2, 2,
  110. 500, 5000000))
  111. b43err(dev->wl, "Radio 0x2059 rccal timeout\n");
  112. /* Stop */
  113. b43_radio_write(dev, R2059_RCCAL_START_R1_Q1_P1, 0x15);
  114. }
  115. b43_radio_mask(dev, R2059_RCCAL_MASTER, ~0x1);
  116. }
  117. static void b43_radio_2059_init_pre(struct b43_wldev *dev)
  118. {
  119. b43_phy_mask(dev, B43_PHY_HT_RF_CTL_CMD, ~B43_PHY_HT_RF_CTL_CMD_CHIP0_PU);
  120. b43_phy_set(dev, B43_PHY_HT_RF_CTL_CMD, B43_PHY_HT_RF_CTL_CMD_FORCE);
  121. b43_phy_mask(dev, B43_PHY_HT_RF_CTL_CMD, ~B43_PHY_HT_RF_CTL_CMD_FORCE);
  122. b43_phy_set(dev, B43_PHY_HT_RF_CTL_CMD, B43_PHY_HT_RF_CTL_CMD_CHIP0_PU);
  123. }
  124. static void b43_radio_2059_init(struct b43_wldev *dev)
  125. {
  126. const u16 routing[] = { R2059_C1, R2059_C2, R2059_C3 };
  127. int i;
  128. /* Prepare (reset?) radio */
  129. b43_radio_2059_init_pre(dev);
  130. r2059_upload_inittabs(dev);
  131. for (i = 0; i < ARRAY_SIZE(routing); i++)
  132. b43_radio_set(dev, routing[i] | 0x146, 0x3);
  133. /* Post init starts below */
  134. b43_radio_set(dev, R2059_RFPLL_MISC_CAL_RESETN, 0x0078);
  135. b43_radio_set(dev, R2059_XTAL_CONFIG2, 0x0080);
  136. msleep(2);
  137. b43_radio_mask(dev, R2059_RFPLL_MISC_CAL_RESETN, ~0x0078);
  138. b43_radio_mask(dev, R2059_XTAL_CONFIG2, ~0x0080);
  139. if (1) { /* FIXME */
  140. b43_radio_2059_rcal(dev);
  141. b43_radio_2057_rccal(dev);
  142. }
  143. b43_radio_mask(dev, R2059_RFPLL_MASTER, ~0x0008);
  144. }
  145. /**************************************************
  146. * RF
  147. **************************************************/
  148. static void b43_phy_ht_force_rf_sequence(struct b43_wldev *dev, u16 rf_seq)
  149. {
  150. u8 i;
  151. u16 save_seq_mode = b43_phy_read(dev, B43_PHY_HT_RF_SEQ_MODE);
  152. b43_phy_set(dev, B43_PHY_HT_RF_SEQ_MODE, 0x3);
  153. b43_phy_set(dev, B43_PHY_HT_RF_SEQ_TRIG, rf_seq);
  154. for (i = 0; i < 200; i++) {
  155. if (!(b43_phy_read(dev, B43_PHY_HT_RF_SEQ_STATUS) & rf_seq)) {
  156. i = 0;
  157. break;
  158. }
  159. msleep(1);
  160. }
  161. if (i)
  162. b43err(dev->wl, "Forcing RF sequence timeout\n");
  163. b43_phy_write(dev, B43_PHY_HT_RF_SEQ_MODE, save_seq_mode);
  164. }
  165. static void b43_phy_ht_pa_override(struct b43_wldev *dev, bool enable)
  166. {
  167. struct b43_phy_ht *htphy = dev->phy.ht;
  168. static const u16 regs[3] = { B43_PHY_HT_RF_CTL_INT_C1,
  169. B43_PHY_HT_RF_CTL_INT_C2,
  170. B43_PHY_HT_RF_CTL_INT_C3 };
  171. int i;
  172. if (enable) {
  173. for (i = 0; i < 3; i++)
  174. b43_phy_write(dev, regs[i], htphy->rf_ctl_int_save[i]);
  175. } else {
  176. for (i = 0; i < 3; i++)
  177. htphy->rf_ctl_int_save[i] = b43_phy_read(dev, regs[i]);
  178. /* TODO: Does 5GHz band use different value (not 0x0400)? */
  179. for (i = 0; i < 3; i++)
  180. b43_phy_write(dev, regs[i], 0x0400);
  181. }
  182. }
  183. /**************************************************
  184. * Various PHY ops
  185. **************************************************/
  186. static u16 b43_phy_ht_classifier(struct b43_wldev *dev, u16 mask, u16 val)
  187. {
  188. u16 tmp;
  189. u16 allowed = B43_PHY_HT_CLASS_CTL_CCK_EN |
  190. B43_PHY_HT_CLASS_CTL_OFDM_EN |
  191. B43_PHY_HT_CLASS_CTL_WAITED_EN;
  192. tmp = b43_phy_read(dev, B43_PHY_HT_CLASS_CTL);
  193. tmp &= allowed;
  194. tmp &= ~mask;
  195. tmp |= (val & mask);
  196. b43_phy_maskset(dev, B43_PHY_HT_CLASS_CTL, ~allowed, tmp);
  197. return tmp;
  198. }
  199. static void b43_phy_ht_reset_cca(struct b43_wldev *dev)
  200. {
  201. u16 bbcfg;
  202. b43_phy_force_clock(dev, true);
  203. bbcfg = b43_phy_read(dev, B43_PHY_HT_BBCFG);
  204. b43_phy_write(dev, B43_PHY_HT_BBCFG, bbcfg | B43_PHY_HT_BBCFG_RSTCCA);
  205. udelay(1);
  206. b43_phy_write(dev, B43_PHY_HT_BBCFG, bbcfg & ~B43_PHY_HT_BBCFG_RSTCCA);
  207. b43_phy_force_clock(dev, false);
  208. b43_phy_ht_force_rf_sequence(dev, B43_PHY_HT_RF_SEQ_TRIG_RST2RX);
  209. }
  210. static void b43_phy_ht_zero_extg(struct b43_wldev *dev)
  211. {
  212. u8 i, j;
  213. u16 base[] = { 0x40, 0x60, 0x80 };
  214. for (i = 0; i < ARRAY_SIZE(base); i++) {
  215. for (j = 0; j < 4; j++)
  216. b43_phy_write(dev, B43_PHY_EXTG(base[i] + j), 0);
  217. }
  218. for (i = 0; i < ARRAY_SIZE(base); i++)
  219. b43_phy_write(dev, B43_PHY_EXTG(base[i] + 0xc), 0);
  220. }
  221. /* Some unknown AFE (Analog Frondned) op */
  222. static void b43_phy_ht_afe_unk1(struct b43_wldev *dev)
  223. {
  224. u8 i;
  225. static const u16 ctl_regs[3][2] = {
  226. { B43_PHY_HT_AFE_C1_OVER, B43_PHY_HT_AFE_C1 },
  227. { B43_PHY_HT_AFE_C2_OVER, B43_PHY_HT_AFE_C2 },
  228. { B43_PHY_HT_AFE_C3_OVER, B43_PHY_HT_AFE_C3},
  229. };
  230. for (i = 0; i < 3; i++) {
  231. /* TODO: verify masks&sets */
  232. b43_phy_set(dev, ctl_regs[i][1], 0x4);
  233. b43_phy_set(dev, ctl_regs[i][0], 0x4);
  234. b43_phy_mask(dev, ctl_regs[i][1], ~0x1);
  235. b43_phy_set(dev, ctl_regs[i][0], 0x1);
  236. b43_httab_write(dev, B43_HTTAB16(8, 5 + (i * 0x10)), 0);
  237. b43_phy_mask(dev, ctl_regs[i][0], ~0x4);
  238. }
  239. }
  240. static void b43_phy_ht_read_clip_detection(struct b43_wldev *dev, u16 *clip_st)
  241. {
  242. clip_st[0] = b43_phy_read(dev, B43_PHY_HT_C1_CLIP1THRES);
  243. clip_st[1] = b43_phy_read(dev, B43_PHY_HT_C2_CLIP1THRES);
  244. clip_st[2] = b43_phy_read(dev, B43_PHY_HT_C3_CLIP1THRES);
  245. }
  246. static void b43_phy_ht_bphy_init(struct b43_wldev *dev)
  247. {
  248. unsigned int i;
  249. u16 val;
  250. val = 0x1E1F;
  251. for (i = 0; i < 16; i++) {
  252. b43_phy_write(dev, B43_PHY_N_BMODE(0x88 + i), val);
  253. val -= 0x202;
  254. }
  255. val = 0x3E3F;
  256. for (i = 0; i < 16; i++) {
  257. b43_phy_write(dev, B43_PHY_N_BMODE(0x98 + i), val);
  258. val -= 0x202;
  259. }
  260. b43_phy_write(dev, B43_PHY_N_BMODE(0x38), 0x668);
  261. }
  262. static void b43_phy_ht_bphy_reset(struct b43_wldev *dev, bool reset)
  263. {
  264. u16 tmp;
  265. tmp = b43_read16(dev, B43_MMIO_PSM_PHY_HDR);
  266. b43_write16(dev, B43_MMIO_PSM_PHY_HDR,
  267. tmp | B43_PSM_HDR_MAC_PHY_FORCE_CLK);
  268. /* Put BPHY in or take it out of the reset */
  269. if (reset)
  270. b43_phy_set(dev, B43_PHY_B_BBCFG,
  271. B43_PHY_B_BBCFG_RSTCCA | B43_PHY_B_BBCFG_RSTRX);
  272. else
  273. b43_phy_mask(dev, B43_PHY_B_BBCFG,
  274. (u16)~(B43_PHY_B_BBCFG_RSTCCA |
  275. B43_PHY_B_BBCFG_RSTRX));
  276. b43_write16(dev, B43_MMIO_PSM_PHY_HDR, tmp);
  277. }
  278. /**************************************************
  279. * Samples
  280. **************************************************/
  281. static void b43_phy_ht_stop_playback(struct b43_wldev *dev)
  282. {
  283. struct b43_phy_ht *phy_ht = dev->phy.ht;
  284. u16 tmp;
  285. int i;
  286. tmp = b43_phy_read(dev, B43_PHY_HT_SAMP_STAT);
  287. if (tmp & 0x1)
  288. b43_phy_set(dev, B43_PHY_HT_SAMP_CMD, B43_PHY_HT_SAMP_CMD_STOP);
  289. else if (tmp & 0x2)
  290. b43_phy_mask(dev, B43_PHY_HT_IQLOCAL_CMDGCTL, 0x7FFF);
  291. b43_phy_mask(dev, B43_PHY_HT_SAMP_CMD, ~0x0004);
  292. for (i = 0; i < 3; i++) {
  293. if (phy_ht->bb_mult_save[i] >= 0) {
  294. b43_httab_write(dev, B43_HTTAB16(13, 0x63 + i * 4),
  295. phy_ht->bb_mult_save[i]);
  296. b43_httab_write(dev, B43_HTTAB16(13, 0x67 + i * 4),
  297. phy_ht->bb_mult_save[i]);
  298. }
  299. }
  300. }
  301. static u16 b43_phy_ht_load_samples(struct b43_wldev *dev)
  302. {
  303. int i;
  304. u16 len = 20 << 3;
  305. b43_phy_write(dev, B43_PHY_HT_TABLE_ADDR, 0x4400);
  306. for (i = 0; i < len; i++) {
  307. b43_phy_write(dev, B43_PHY_HT_TABLE_DATAHI, 0);
  308. b43_phy_write(dev, B43_PHY_HT_TABLE_DATALO, 0);
  309. }
  310. return len;
  311. }
  312. static void b43_phy_ht_run_samples(struct b43_wldev *dev, u16 samps, u16 loops,
  313. u16 wait)
  314. {
  315. struct b43_phy_ht *phy_ht = dev->phy.ht;
  316. u16 save_seq_mode;
  317. int i;
  318. for (i = 0; i < 3; i++) {
  319. if (phy_ht->bb_mult_save[i] < 0)
  320. phy_ht->bb_mult_save[i] = b43_httab_read(dev, B43_HTTAB16(13, 0x63 + i * 4));
  321. }
  322. b43_phy_write(dev, B43_PHY_HT_SAMP_DEP_CNT, samps - 1);
  323. if (loops != 0xFFFF)
  324. loops--;
  325. b43_phy_write(dev, B43_PHY_HT_SAMP_LOOP_CNT, loops);
  326. b43_phy_write(dev, B43_PHY_HT_SAMP_WAIT_CNT, wait);
  327. save_seq_mode = b43_phy_read(dev, B43_PHY_HT_RF_SEQ_MODE);
  328. b43_phy_set(dev, B43_PHY_HT_RF_SEQ_MODE,
  329. B43_PHY_HT_RF_SEQ_MODE_CA_OVER);
  330. /* TODO: find out mask bits! Do we need more function arguments? */
  331. b43_phy_mask(dev, B43_PHY_HT_SAMP_CMD, ~0);
  332. b43_phy_mask(dev, B43_PHY_HT_SAMP_CMD, ~0);
  333. b43_phy_mask(dev, B43_PHY_HT_IQLOCAL_CMDGCTL, ~0);
  334. b43_phy_set(dev, B43_PHY_HT_SAMP_CMD, 0x1);
  335. for (i = 0; i < 100; i++) {
  336. if (!(b43_phy_read(dev, B43_PHY_HT_RF_SEQ_STATUS) & 1)) {
  337. i = 0;
  338. break;
  339. }
  340. udelay(10);
  341. }
  342. if (i)
  343. b43err(dev->wl, "run samples timeout\n");
  344. b43_phy_write(dev, B43_PHY_HT_RF_SEQ_MODE, save_seq_mode);
  345. }
  346. static void b43_phy_ht_tx_tone(struct b43_wldev *dev)
  347. {
  348. u16 samp;
  349. samp = b43_phy_ht_load_samples(dev);
  350. b43_phy_ht_run_samples(dev, samp, 0xFFFF, 0);
  351. }
  352. /**************************************************
  353. * RSSI
  354. **************************************************/
  355. static void b43_phy_ht_rssi_select(struct b43_wldev *dev, u8 core_sel,
  356. enum ht_rssi_type rssi_type)
  357. {
  358. static const u16 ctl_regs[3][2] = {
  359. { B43_PHY_HT_AFE_C1, B43_PHY_HT_AFE_C1_OVER, },
  360. { B43_PHY_HT_AFE_C2, B43_PHY_HT_AFE_C2_OVER, },
  361. { B43_PHY_HT_AFE_C3, B43_PHY_HT_AFE_C3_OVER, },
  362. };
  363. static const u16 radio_r[] = { R2059_C1, R2059_C2, R2059_C3, };
  364. int core;
  365. if (core_sel == 0) {
  366. b43err(dev->wl, "RSSI selection for core off not implemented yet\n");
  367. } else {
  368. for (core = 0; core < 3; core++) {
  369. /* Check if caller requested a one specific core */
  370. if ((core_sel == 1 && core != 0) ||
  371. (core_sel == 2 && core != 1) ||
  372. (core_sel == 3 && core != 2))
  373. continue;
  374. switch (rssi_type) {
  375. case HT_RSSI_TSSI_2G:
  376. b43_phy_set(dev, ctl_regs[core][0], 0x3 << 8);
  377. b43_phy_set(dev, ctl_regs[core][0], 0x3 << 10);
  378. b43_phy_set(dev, ctl_regs[core][1], 0x1 << 9);
  379. b43_phy_set(dev, ctl_regs[core][1], 0x1 << 10);
  380. b43_radio_set(dev, R2059_C3 | 0xbf, 0x1);
  381. b43_radio_write(dev, radio_r[core] | 0x159,
  382. 0x11);
  383. break;
  384. default:
  385. b43err(dev->wl, "RSSI selection for type %d not implemented yet\n",
  386. rssi_type);
  387. }
  388. }
  389. }
  390. }
  391. static void b43_phy_ht_poll_rssi(struct b43_wldev *dev, enum ht_rssi_type type,
  392. s32 *buf, u8 nsamp)
  393. {
  394. u16 phy_regs_values[12];
  395. static const u16 phy_regs_to_save[] = {
  396. B43_PHY_HT_AFE_C1, B43_PHY_HT_AFE_C1_OVER,
  397. 0x848, 0x841,
  398. B43_PHY_HT_AFE_C2, B43_PHY_HT_AFE_C2_OVER,
  399. 0x868, 0x861,
  400. B43_PHY_HT_AFE_C3, B43_PHY_HT_AFE_C3_OVER,
  401. 0x888, 0x881,
  402. };
  403. u16 tmp[3];
  404. int i;
  405. for (i = 0; i < 12; i++)
  406. phy_regs_values[i] = b43_phy_read(dev, phy_regs_to_save[i]);
  407. b43_phy_ht_rssi_select(dev, 5, type);
  408. for (i = 0; i < 6; i++)
  409. buf[i] = 0;
  410. for (i = 0; i < nsamp; i++) {
  411. tmp[0] = b43_phy_read(dev, B43_PHY_HT_RSSI_C1);
  412. tmp[1] = b43_phy_read(dev, B43_PHY_HT_RSSI_C2);
  413. tmp[2] = b43_phy_read(dev, B43_PHY_HT_RSSI_C3);
  414. buf[0] += ((s8)((tmp[0] & 0x3F) << 2)) >> 2;
  415. buf[1] += ((s8)(((tmp[0] >> 8) & 0x3F) << 2)) >> 2;
  416. buf[2] += ((s8)((tmp[1] & 0x3F) << 2)) >> 2;
  417. buf[3] += ((s8)(((tmp[1] >> 8) & 0x3F) << 2)) >> 2;
  418. buf[4] += ((s8)((tmp[2] & 0x3F) << 2)) >> 2;
  419. buf[5] += ((s8)(((tmp[2] >> 8) & 0x3F) << 2)) >> 2;
  420. }
  421. for (i = 0; i < 12; i++)
  422. b43_phy_write(dev, phy_regs_to_save[i], phy_regs_values[i]);
  423. }
  424. /**************************************************
  425. * Tx/Rx
  426. **************************************************/
  427. static void b43_phy_ht_tx_power_fix(struct b43_wldev *dev)
  428. {
  429. int i;
  430. for (i = 0; i < 3; i++) {
  431. u16 mask;
  432. u32 tmp = b43_httab_read(dev, B43_HTTAB32(26, 0xE8));
  433. if (0) /* FIXME */
  434. mask = 0x2 << (i * 4);
  435. else
  436. mask = 0;
  437. b43_phy_mask(dev, B43_PHY_EXTG(0x108), mask);
  438. b43_httab_write(dev, B43_HTTAB16(7, 0x110 + i), tmp >> 16);
  439. b43_httab_write(dev, B43_HTTAB8(13, 0x63 + (i * 4)),
  440. tmp & 0xFF);
  441. b43_httab_write(dev, B43_HTTAB8(13, 0x73 + (i * 4)),
  442. tmp & 0xFF);
  443. }
  444. }
  445. static void b43_phy_ht_tx_power_ctl(struct b43_wldev *dev, bool enable)
  446. {
  447. struct b43_phy_ht *phy_ht = dev->phy.ht;
  448. u16 en_bits = B43_PHY_HT_TXPCTL_CMD_C1_COEFF |
  449. B43_PHY_HT_TXPCTL_CMD_C1_HWPCTLEN |
  450. B43_PHY_HT_TXPCTL_CMD_C1_PCTLEN;
  451. static const u16 cmd_regs[3] = { B43_PHY_HT_TXPCTL_CMD_C1,
  452. B43_PHY_HT_TXPCTL_CMD_C2,
  453. B43_PHY_HT_TXPCTL_CMD_C3 };
  454. static const u16 status_regs[3] = { B43_PHY_HT_TX_PCTL_STATUS_C1,
  455. B43_PHY_HT_TX_PCTL_STATUS_C2,
  456. B43_PHY_HT_TX_PCTL_STATUS_C3 };
  457. int i;
  458. if (!enable) {
  459. if (b43_phy_read(dev, B43_PHY_HT_TXPCTL_CMD_C1) & en_bits) {
  460. /* We disable enabled TX pwr ctl, save it's state */
  461. for (i = 0; i < 3; i++)
  462. phy_ht->tx_pwr_idx[i] =
  463. b43_phy_read(dev, status_regs[i]);
  464. }
  465. b43_phy_mask(dev, B43_PHY_HT_TXPCTL_CMD_C1, ~en_bits);
  466. } else {
  467. b43_phy_set(dev, B43_PHY_HT_TXPCTL_CMD_C1, en_bits);
  468. if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ) {
  469. for (i = 0; i < 3; i++)
  470. b43_phy_write(dev, cmd_regs[i], 0x32);
  471. }
  472. for (i = 0; i < 3; i++)
  473. if (phy_ht->tx_pwr_idx[i] <=
  474. B43_PHY_HT_TXPCTL_CMD_C1_INIT)
  475. b43_phy_write(dev, cmd_regs[i],
  476. phy_ht->tx_pwr_idx[i]);
  477. }
  478. phy_ht->tx_pwr_ctl = enable;
  479. }
  480. static void b43_phy_ht_tx_power_ctl_idle_tssi(struct b43_wldev *dev)
  481. {
  482. struct b43_phy_ht *phy_ht = dev->phy.ht;
  483. static const u16 base[] = { 0x840, 0x860, 0x880 };
  484. u16 save_regs[3][3];
  485. s32 rssi_buf[6];
  486. int core;
  487. for (core = 0; core < 3; core++) {
  488. save_regs[core][1] = b43_phy_read(dev, base[core] + 6);
  489. save_regs[core][2] = b43_phy_read(dev, base[core] + 7);
  490. save_regs[core][0] = b43_phy_read(dev, base[core] + 0);
  491. b43_phy_write(dev, base[core] + 6, 0);
  492. b43_phy_mask(dev, base[core] + 7, ~0xF); /* 0xF? Or just 0x6? */
  493. b43_phy_set(dev, base[core] + 0, 0x0400);
  494. b43_phy_set(dev, base[core] + 0, 0x1000);
  495. }
  496. b43_phy_ht_tx_tone(dev);
  497. udelay(20);
  498. b43_phy_ht_poll_rssi(dev, HT_RSSI_TSSI_2G, rssi_buf, 1);
  499. b43_phy_ht_stop_playback(dev);
  500. b43_phy_ht_reset_cca(dev);
  501. phy_ht->idle_tssi[0] = rssi_buf[0] & 0xff;
  502. phy_ht->idle_tssi[1] = rssi_buf[2] & 0xff;
  503. phy_ht->idle_tssi[2] = rssi_buf[4] & 0xff;
  504. for (core = 0; core < 3; core++) {
  505. b43_phy_write(dev, base[core] + 0, save_regs[core][0]);
  506. b43_phy_write(dev, base[core] + 6, save_regs[core][1]);
  507. b43_phy_write(dev, base[core] + 7, save_regs[core][2]);
  508. }
  509. }
  510. static void b43_phy_ht_tssi_setup(struct b43_wldev *dev)
  511. {
  512. static const u16 routing[] = { R2059_C1, R2059_C2, R2059_C3, };
  513. int core;
  514. /* 0x159 is probably TX_SSI_MUX or TSSIG (by comparing to N-PHY) */
  515. for (core = 0; core < 3; core++) {
  516. b43_radio_set(dev, 0x8bf, 0x1);
  517. b43_radio_write(dev, routing[core] | 0x0159, 0x0011);
  518. }
  519. }
  520. static void b43_phy_ht_tx_power_ctl_setup(struct b43_wldev *dev)
  521. {
  522. struct b43_phy_ht *phy_ht = dev->phy.ht;
  523. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  524. u8 *idle = phy_ht->idle_tssi;
  525. u8 target[3];
  526. s16 a1[3], b0[3], b1[3];
  527. u16 freq = dev->phy.chandef->chan->center_freq;
  528. int i, c;
  529. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
  530. for (c = 0; c < 3; c++) {
  531. target[c] = sprom->core_pwr_info[c].maxpwr_2g;
  532. a1[c] = sprom->core_pwr_info[c].pa_2g[0];
  533. b0[c] = sprom->core_pwr_info[c].pa_2g[1];
  534. b1[c] = sprom->core_pwr_info[c].pa_2g[2];
  535. }
  536. } else if (freq >= 4900 && freq < 5100) {
  537. for (c = 0; c < 3; c++) {
  538. target[c] = sprom->core_pwr_info[c].maxpwr_5gl;
  539. a1[c] = sprom->core_pwr_info[c].pa_5gl[0];
  540. b0[c] = sprom->core_pwr_info[c].pa_5gl[1];
  541. b1[c] = sprom->core_pwr_info[c].pa_5gl[2];
  542. }
  543. } else if (freq >= 5100 && freq < 5500) {
  544. for (c = 0; c < 3; c++) {
  545. target[c] = sprom->core_pwr_info[c].maxpwr_5g;
  546. a1[c] = sprom->core_pwr_info[c].pa_5g[0];
  547. b0[c] = sprom->core_pwr_info[c].pa_5g[1];
  548. b1[c] = sprom->core_pwr_info[c].pa_5g[2];
  549. }
  550. } else if (freq >= 5500) {
  551. for (c = 0; c < 3; c++) {
  552. target[c] = sprom->core_pwr_info[c].maxpwr_5gh;
  553. a1[c] = sprom->core_pwr_info[c].pa_5gh[0];
  554. b0[c] = sprom->core_pwr_info[c].pa_5gh[1];
  555. b1[c] = sprom->core_pwr_info[c].pa_5gh[2];
  556. }
  557. } else {
  558. target[0] = target[1] = target[2] = 52;
  559. a1[0] = a1[1] = a1[2] = -424;
  560. b0[0] = b0[1] = b0[2] = 5612;
  561. b1[0] = b1[1] = b1[2] = -1393;
  562. }
  563. b43_phy_set(dev, B43_PHY_HT_TSSIMODE, B43_PHY_HT_TSSIMODE_EN);
  564. b43_phy_mask(dev, B43_PHY_HT_TXPCTL_CMD_C1,
  565. ~B43_PHY_HT_TXPCTL_CMD_C1_PCTLEN & 0xFFFF);
  566. /* TODO: Does it depend on sprom->fem.ghz2.tssipos? */
  567. b43_phy_set(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI, 0x4000);
  568. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C1,
  569. ~B43_PHY_HT_TXPCTL_CMD_C1_INIT, 0x19);
  570. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C2,
  571. ~B43_PHY_HT_TXPCTL_CMD_C2_INIT, 0x19);
  572. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C3,
  573. ~B43_PHY_HT_TXPCTL_CMD_C3_INIT, 0x19);
  574. b43_phy_set(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI,
  575. B43_PHY_HT_TXPCTL_IDLE_TSSI_BINF);
  576. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI,
  577. ~B43_PHY_HT_TXPCTL_IDLE_TSSI_C1,
  578. idle[0] << B43_PHY_HT_TXPCTL_IDLE_TSSI_C1_SHIFT);
  579. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI,
  580. ~B43_PHY_HT_TXPCTL_IDLE_TSSI_C2,
  581. idle[1] << B43_PHY_HT_TXPCTL_IDLE_TSSI_C2_SHIFT);
  582. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI2,
  583. ~B43_PHY_HT_TXPCTL_IDLE_TSSI2_C3,
  584. idle[2] << B43_PHY_HT_TXPCTL_IDLE_TSSI2_C3_SHIFT);
  585. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_N, ~B43_PHY_HT_TXPCTL_N_TSSID,
  586. 0xf0);
  587. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_N, ~B43_PHY_HT_TXPCTL_N_NPTIL2,
  588. 0x3 << B43_PHY_HT_TXPCTL_N_NPTIL2_SHIFT);
  589. #if 0
  590. /* TODO: what to mask/set? */
  591. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C1, 0x800, 0)
  592. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C1, 0x400, 0)
  593. #endif
  594. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_TARG_PWR,
  595. ~B43_PHY_HT_TXPCTL_TARG_PWR_C1,
  596. target[0] << B43_PHY_HT_TXPCTL_TARG_PWR_C1_SHIFT);
  597. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_TARG_PWR,
  598. ~B43_PHY_HT_TXPCTL_TARG_PWR_C2 & 0xFFFF,
  599. target[1] << B43_PHY_HT_TXPCTL_TARG_PWR_C2_SHIFT);
  600. b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_TARG_PWR2,
  601. ~B43_PHY_HT_TXPCTL_TARG_PWR2_C3,
  602. target[2] << B43_PHY_HT_TXPCTL_TARG_PWR2_C3_SHIFT);
  603. for (c = 0; c < 3; c++) {
  604. s32 num, den, pwr;
  605. u32 regval[64];
  606. for (i = 0; i < 64; i++) {
  607. num = 8 * (16 * b0[c] + b1[c] * i);
  608. den = 32768 + a1[c] * i;
  609. pwr = max((4 * num + den / 2) / den, -8);
  610. regval[i] = pwr;
  611. }
  612. b43_httab_write_bulk(dev, B43_HTTAB16(26 + c, 0), 64, regval);
  613. }
  614. }
  615. /**************************************************
  616. * Channel switching ops.
  617. **************************************************/
  618. static void b43_phy_ht_spur_avoid(struct b43_wldev *dev,
  619. struct ieee80211_channel *new_channel)
  620. {
  621. struct bcma_device *core = dev->dev->bdev;
  622. int spuravoid = 0;
  623. /* Check for 13 and 14 is just a guess, we don't have enough logs. */
  624. if (new_channel->hw_value == 13 || new_channel->hw_value == 14)
  625. spuravoid = 1;
  626. bcma_core_pll_ctl(core, B43_BCMA_CLKCTLST_PHY_PLL_REQ, 0, false);
  627. bcma_pmu_spuravoid_pllupdate(&core->bus->drv_cc, spuravoid);
  628. bcma_core_pll_ctl(core,
  629. B43_BCMA_CLKCTLST_80211_PLL_REQ |
  630. B43_BCMA_CLKCTLST_PHY_PLL_REQ,
  631. B43_BCMA_CLKCTLST_80211_PLL_ST |
  632. B43_BCMA_CLKCTLST_PHY_PLL_ST, false);
  633. b43_mac_switch_freq(dev, spuravoid);
  634. b43_wireless_core_phy_pll_reset(dev);
  635. if (spuravoid)
  636. b43_phy_set(dev, B43_PHY_HT_BBCFG, B43_PHY_HT_BBCFG_RSTRX);
  637. else
  638. b43_phy_mask(dev, B43_PHY_HT_BBCFG,
  639. ~B43_PHY_HT_BBCFG_RSTRX & 0xFFFF);
  640. b43_phy_ht_reset_cca(dev);
  641. }
  642. static void b43_phy_ht_channel_setup(struct b43_wldev *dev,
  643. const struct b43_phy_ht_channeltab_e_phy *e,
  644. struct ieee80211_channel *new_channel)
  645. {
  646. if (new_channel->band == IEEE80211_BAND_5GHZ) {
  647. /* Switch to 2 GHz for a moment to access B-PHY regs */
  648. b43_phy_mask(dev, B43_PHY_HT_BANDCTL, ~B43_PHY_HT_BANDCTL_5GHZ);
  649. b43_phy_ht_bphy_reset(dev, true);
  650. /* Switch to 5 GHz */
  651. b43_phy_set(dev, B43_PHY_HT_BANDCTL, B43_PHY_HT_BANDCTL_5GHZ);
  652. } else {
  653. /* Switch to 2 GHz */
  654. b43_phy_mask(dev, B43_PHY_HT_BANDCTL, ~B43_PHY_HT_BANDCTL_5GHZ);
  655. b43_phy_ht_bphy_reset(dev, false);
  656. }
  657. b43_phy_write(dev, B43_PHY_HT_BW1, e->bw1);
  658. b43_phy_write(dev, B43_PHY_HT_BW2, e->bw2);
  659. b43_phy_write(dev, B43_PHY_HT_BW3, e->bw3);
  660. b43_phy_write(dev, B43_PHY_HT_BW4, e->bw4);
  661. b43_phy_write(dev, B43_PHY_HT_BW5, e->bw5);
  662. b43_phy_write(dev, B43_PHY_HT_BW6, e->bw6);
  663. if (new_channel->hw_value == 14) {
  664. b43_phy_ht_classifier(dev, B43_PHY_HT_CLASS_CTL_OFDM_EN, 0);
  665. b43_phy_set(dev, B43_PHY_HT_TEST, 0x0800);
  666. } else {
  667. b43_phy_ht_classifier(dev, B43_PHY_HT_CLASS_CTL_OFDM_EN,
  668. B43_PHY_HT_CLASS_CTL_OFDM_EN);
  669. if (new_channel->band == IEEE80211_BAND_2GHZ)
  670. b43_phy_mask(dev, B43_PHY_HT_TEST, ~0x840);
  671. }
  672. if (1) /* TODO: On N it's for early devices only, what about HT? */
  673. b43_phy_ht_tx_power_fix(dev);
  674. b43_phy_ht_spur_avoid(dev, new_channel);
  675. b43_phy_write(dev, 0x017e, 0x3830);
  676. }
  677. static int b43_phy_ht_set_channel(struct b43_wldev *dev,
  678. struct ieee80211_channel *channel,
  679. enum nl80211_channel_type channel_type)
  680. {
  681. struct b43_phy *phy = &dev->phy;
  682. const struct b43_phy_ht_channeltab_e_radio2059 *chent_r2059 = NULL;
  683. if (phy->radio_ver == 0x2059) {
  684. chent_r2059 = b43_phy_ht_get_channeltab_e_r2059(dev,
  685. channel->center_freq);
  686. if (!chent_r2059)
  687. return -ESRCH;
  688. } else {
  689. return -ESRCH;
  690. }
  691. /* TODO: In case of N-PHY some bandwidth switching goes here */
  692. if (phy->radio_ver == 0x2059) {
  693. b43_radio_2059_channel_setup(dev, chent_r2059);
  694. b43_phy_ht_channel_setup(dev, &(chent_r2059->phy_regs),
  695. channel);
  696. } else {
  697. return -ESRCH;
  698. }
  699. return 0;
  700. }
  701. /**************************************************
  702. * Basic PHY ops.
  703. **************************************************/
  704. static int b43_phy_ht_op_allocate(struct b43_wldev *dev)
  705. {
  706. struct b43_phy_ht *phy_ht;
  707. phy_ht = kzalloc(sizeof(*phy_ht), GFP_KERNEL);
  708. if (!phy_ht)
  709. return -ENOMEM;
  710. dev->phy.ht = phy_ht;
  711. return 0;
  712. }
  713. static void b43_phy_ht_op_prepare_structs(struct b43_wldev *dev)
  714. {
  715. struct b43_phy *phy = &dev->phy;
  716. struct b43_phy_ht *phy_ht = phy->ht;
  717. int i;
  718. memset(phy_ht, 0, sizeof(*phy_ht));
  719. phy_ht->tx_pwr_ctl = true;
  720. for (i = 0; i < 3; i++)
  721. phy_ht->tx_pwr_idx[i] = B43_PHY_HT_TXPCTL_CMD_C1_INIT + 1;
  722. for (i = 0; i < 3; i++)
  723. phy_ht->bb_mult_save[i] = -1;
  724. }
  725. static int b43_phy_ht_op_init(struct b43_wldev *dev)
  726. {
  727. struct b43_phy_ht *phy_ht = dev->phy.ht;
  728. u16 tmp;
  729. u16 clip_state[3];
  730. bool saved_tx_pwr_ctl;
  731. if (dev->dev->bus_type != B43_BUS_BCMA) {
  732. b43err(dev->wl, "HT-PHY is supported only on BCMA bus!\n");
  733. return -EOPNOTSUPP;
  734. }
  735. b43_phy_ht_tables_init(dev);
  736. b43_phy_mask(dev, 0x0be, ~0x2);
  737. b43_phy_set(dev, 0x23f, 0x7ff);
  738. b43_phy_set(dev, 0x240, 0x7ff);
  739. b43_phy_set(dev, 0x241, 0x7ff);
  740. b43_phy_ht_zero_extg(dev);
  741. b43_phy_mask(dev, B43_PHY_EXTG(0), ~0x3);
  742. b43_phy_write(dev, B43_PHY_HT_AFE_C1_OVER, 0);
  743. b43_phy_write(dev, B43_PHY_HT_AFE_C2_OVER, 0);
  744. b43_phy_write(dev, B43_PHY_HT_AFE_C3_OVER, 0);
  745. b43_phy_write(dev, B43_PHY_EXTG(0x103), 0x20);
  746. b43_phy_write(dev, B43_PHY_EXTG(0x101), 0x20);
  747. b43_phy_write(dev, 0x20d, 0xb8);
  748. b43_phy_write(dev, B43_PHY_EXTG(0x14f), 0xc8);
  749. b43_phy_write(dev, 0x70, 0x50);
  750. b43_phy_write(dev, 0x1ff, 0x30);
  751. if (0) /* TODO: condition */
  752. ; /* TODO: PHY op on reg 0x217 */
  753. if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ)
  754. b43_phy_ht_classifier(dev, B43_PHY_HT_CLASS_CTL_CCK_EN, 0);
  755. else
  756. b43_phy_ht_classifier(dev, B43_PHY_HT_CLASS_CTL_CCK_EN,
  757. B43_PHY_HT_CLASS_CTL_CCK_EN);
  758. b43_phy_set(dev, 0xb1, 0x91);
  759. b43_phy_write(dev, 0x32f, 0x0003);
  760. b43_phy_write(dev, 0x077, 0x0010);
  761. b43_phy_write(dev, 0x0b4, 0x0258);
  762. b43_phy_mask(dev, 0x17e, ~0x4000);
  763. b43_phy_write(dev, 0x0b9, 0x0072);
  764. b43_httab_write_few(dev, B43_HTTAB16(7, 0x14e), 2, 0x010f, 0x010f);
  765. b43_httab_write_few(dev, B43_HTTAB16(7, 0x15e), 2, 0x010f, 0x010f);
  766. b43_httab_write_few(dev, B43_HTTAB16(7, 0x16e), 2, 0x010f, 0x010f);
  767. b43_phy_ht_afe_unk1(dev);
  768. b43_httab_write_few(dev, B43_HTTAB16(7, 0x130), 9, 0x777, 0x111, 0x111,
  769. 0x777, 0x111, 0x111, 0x777, 0x111, 0x111);
  770. b43_httab_write(dev, B43_HTTAB16(7, 0x120), 0x0777);
  771. b43_httab_write(dev, B43_HTTAB16(7, 0x124), 0x0777);
  772. b43_httab_write(dev, B43_HTTAB16(8, 0x00), 0x02);
  773. b43_httab_write(dev, B43_HTTAB16(8, 0x10), 0x02);
  774. b43_httab_write(dev, B43_HTTAB16(8, 0x20), 0x02);
  775. b43_httab_write_few(dev, B43_HTTAB16(8, 0x08), 4,
  776. 0x8e, 0x96, 0x96, 0x96);
  777. b43_httab_write_few(dev, B43_HTTAB16(8, 0x18), 4,
  778. 0x8f, 0x9f, 0x9f, 0x9f);
  779. b43_httab_write_few(dev, B43_HTTAB16(8, 0x28), 4,
  780. 0x8f, 0x9f, 0x9f, 0x9f);
  781. b43_httab_write_few(dev, B43_HTTAB16(8, 0x0c), 4, 0x2, 0x2, 0x2, 0x2);
  782. b43_httab_write_few(dev, B43_HTTAB16(8, 0x1c), 4, 0x2, 0x2, 0x2, 0x2);
  783. b43_httab_write_few(dev, B43_HTTAB16(8, 0x2c), 4, 0x2, 0x2, 0x2, 0x2);
  784. b43_phy_maskset(dev, 0x0280, 0xff00, 0x3e);
  785. b43_phy_maskset(dev, 0x0283, 0xff00, 0x3e);
  786. b43_phy_maskset(dev, B43_PHY_OFDM(0x0141), 0xff00, 0x46);
  787. b43_phy_maskset(dev, 0x0283, 0xff00, 0x40);
  788. b43_httab_write_few(dev, B43_HTTAB16(00, 0x8), 4,
  789. 0x09, 0x0e, 0x13, 0x18);
  790. b43_httab_write_few(dev, B43_HTTAB16(01, 0x8), 4,
  791. 0x09, 0x0e, 0x13, 0x18);
  792. /* TODO: Did wl mean 2 instead of 40? */
  793. b43_httab_write_few(dev, B43_HTTAB16(40, 0x8), 4,
  794. 0x09, 0x0e, 0x13, 0x18);
  795. b43_phy_maskset(dev, B43_PHY_OFDM(0x24), 0x3f, 0xd);
  796. b43_phy_maskset(dev, B43_PHY_OFDM(0x64), 0x3f, 0xd);
  797. b43_phy_maskset(dev, B43_PHY_OFDM(0xa4), 0x3f, 0xd);
  798. b43_phy_set(dev, B43_PHY_EXTG(0x060), 0x1);
  799. b43_phy_set(dev, B43_PHY_EXTG(0x064), 0x1);
  800. b43_phy_set(dev, B43_PHY_EXTG(0x080), 0x1);
  801. b43_phy_set(dev, B43_PHY_EXTG(0x084), 0x1);
  802. /* Copy some tables entries */
  803. tmp = b43_httab_read(dev, B43_HTTAB16(7, 0x144));
  804. b43_httab_write(dev, B43_HTTAB16(7, 0x14a), tmp);
  805. tmp = b43_httab_read(dev, B43_HTTAB16(7, 0x154));
  806. b43_httab_write(dev, B43_HTTAB16(7, 0x15a), tmp);
  807. tmp = b43_httab_read(dev, B43_HTTAB16(7, 0x164));
  808. b43_httab_write(dev, B43_HTTAB16(7, 0x16a), tmp);
  809. /* Reset CCA */
  810. b43_phy_force_clock(dev, true);
  811. tmp = b43_phy_read(dev, B43_PHY_HT_BBCFG);
  812. b43_phy_write(dev, B43_PHY_HT_BBCFG, tmp | B43_PHY_HT_BBCFG_RSTCCA);
  813. b43_phy_write(dev, B43_PHY_HT_BBCFG, tmp & ~B43_PHY_HT_BBCFG_RSTCCA);
  814. b43_phy_force_clock(dev, false);
  815. b43_mac_phy_clock_set(dev, true);
  816. b43_phy_ht_pa_override(dev, false);
  817. b43_phy_ht_force_rf_sequence(dev, B43_PHY_HT_RF_SEQ_TRIG_RX2TX);
  818. b43_phy_ht_force_rf_sequence(dev, B43_PHY_HT_RF_SEQ_TRIG_RST2RX);
  819. b43_phy_ht_pa_override(dev, true);
  820. /* TODO: Should we restore it? Or store it in global PHY info? */
  821. b43_phy_ht_classifier(dev, 0, 0);
  822. b43_phy_ht_read_clip_detection(dev, clip_state);
  823. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
  824. b43_phy_ht_bphy_init(dev);
  825. b43_httab_write_bulk(dev, B43_HTTAB32(0x1a, 0xc0),
  826. B43_HTTAB_1A_C0_LATE_SIZE, b43_httab_0x1a_0xc0_late);
  827. saved_tx_pwr_ctl = phy_ht->tx_pwr_ctl;
  828. b43_phy_ht_tx_power_fix(dev);
  829. b43_phy_ht_tx_power_ctl(dev, false);
  830. b43_phy_ht_tx_power_ctl_idle_tssi(dev);
  831. b43_phy_ht_tx_power_ctl_setup(dev);
  832. b43_phy_ht_tssi_setup(dev);
  833. b43_phy_ht_tx_power_ctl(dev, saved_tx_pwr_ctl);
  834. return 0;
  835. }
  836. static void b43_phy_ht_op_free(struct b43_wldev *dev)
  837. {
  838. struct b43_phy *phy = &dev->phy;
  839. struct b43_phy_ht *phy_ht = phy->ht;
  840. kfree(phy_ht);
  841. phy->ht = NULL;
  842. }
  843. /* http://bcm-v4.sipsolutions.net/802.11/Radio/Switch%20Radio */
  844. static void b43_phy_ht_op_software_rfkill(struct b43_wldev *dev,
  845. bool blocked)
  846. {
  847. if (b43_read32(dev, B43_MMIO_MACCTL) & B43_MACCTL_ENABLED)
  848. b43err(dev->wl, "MAC not suspended\n");
  849. if (blocked) {
  850. b43_phy_mask(dev, B43_PHY_HT_RF_CTL_CMD,
  851. ~B43_PHY_HT_RF_CTL_CMD_CHIP0_PU);
  852. } else {
  853. if (dev->phy.radio_ver == 0x2059)
  854. b43_radio_2059_init(dev);
  855. else
  856. B43_WARN_ON(1);
  857. b43_switch_channel(dev, dev->phy.channel);
  858. }
  859. }
  860. static void b43_phy_ht_op_switch_analog(struct b43_wldev *dev, bool on)
  861. {
  862. if (on) {
  863. b43_phy_write(dev, B43_PHY_HT_AFE_C1, 0x00cd);
  864. b43_phy_write(dev, B43_PHY_HT_AFE_C1_OVER, 0x0000);
  865. b43_phy_write(dev, B43_PHY_HT_AFE_C2, 0x00cd);
  866. b43_phy_write(dev, B43_PHY_HT_AFE_C2_OVER, 0x0000);
  867. b43_phy_write(dev, B43_PHY_HT_AFE_C3, 0x00cd);
  868. b43_phy_write(dev, B43_PHY_HT_AFE_C3_OVER, 0x0000);
  869. } else {
  870. b43_phy_write(dev, B43_PHY_HT_AFE_C1_OVER, 0x07ff);
  871. b43_phy_write(dev, B43_PHY_HT_AFE_C1, 0x00fd);
  872. b43_phy_write(dev, B43_PHY_HT_AFE_C2_OVER, 0x07ff);
  873. b43_phy_write(dev, B43_PHY_HT_AFE_C2, 0x00fd);
  874. b43_phy_write(dev, B43_PHY_HT_AFE_C3_OVER, 0x07ff);
  875. b43_phy_write(dev, B43_PHY_HT_AFE_C3, 0x00fd);
  876. }
  877. }
  878. static int b43_phy_ht_op_switch_channel(struct b43_wldev *dev,
  879. unsigned int new_channel)
  880. {
  881. struct ieee80211_channel *channel = dev->wl->hw->conf.chandef.chan;
  882. enum nl80211_channel_type channel_type =
  883. cfg80211_get_chandef_type(&dev->wl->hw->conf.chandef);
  884. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
  885. if ((new_channel < 1) || (new_channel > 14))
  886. return -EINVAL;
  887. } else {
  888. return -EINVAL;
  889. }
  890. return b43_phy_ht_set_channel(dev, channel, channel_type);
  891. }
  892. static unsigned int b43_phy_ht_op_get_default_chan(struct b43_wldev *dev)
  893. {
  894. if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
  895. return 11;
  896. return 36;
  897. }
  898. /**************************************************
  899. * R/W ops.
  900. **************************************************/
  901. static void b43_phy_ht_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
  902. u16 set)
  903. {
  904. b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg);
  905. b43_write16(dev, B43_MMIO_PHY_DATA,
  906. (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
  907. }
  908. static u16 b43_phy_ht_op_radio_read(struct b43_wldev *dev, u16 reg)
  909. {
  910. /* HT-PHY needs 0x200 for read access */
  911. reg |= 0x200;
  912. b43_write16f(dev, B43_MMIO_RADIO24_CONTROL, reg);
  913. return b43_read16(dev, B43_MMIO_RADIO24_DATA);
  914. }
  915. static void b43_phy_ht_op_radio_write(struct b43_wldev *dev, u16 reg,
  916. u16 value)
  917. {
  918. b43_write16f(dev, B43_MMIO_RADIO24_CONTROL, reg);
  919. b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
  920. }
  921. static enum b43_txpwr_result
  922. b43_phy_ht_op_recalc_txpower(struct b43_wldev *dev, bool ignore_tssi)
  923. {
  924. return B43_TXPWR_RES_DONE;
  925. }
  926. static void b43_phy_ht_op_adjust_txpower(struct b43_wldev *dev)
  927. {
  928. }
  929. /**************************************************
  930. * PHY ops struct.
  931. **************************************************/
  932. const struct b43_phy_operations b43_phyops_ht = {
  933. .allocate = b43_phy_ht_op_allocate,
  934. .free = b43_phy_ht_op_free,
  935. .prepare_structs = b43_phy_ht_op_prepare_structs,
  936. .init = b43_phy_ht_op_init,
  937. .phy_maskset = b43_phy_ht_op_maskset,
  938. .radio_read = b43_phy_ht_op_radio_read,
  939. .radio_write = b43_phy_ht_op_radio_write,
  940. .software_rfkill = b43_phy_ht_op_software_rfkill,
  941. .switch_analog = b43_phy_ht_op_switch_analog,
  942. .switch_channel = b43_phy_ht_op_switch_channel,
  943. .get_default_chan = b43_phy_ht_op_get_default_chan,
  944. .recalc_txpower = b43_phy_ht_op_recalc_txpower,
  945. .adjust_txpower = b43_phy_ht_op_adjust_txpower,
  946. };