phy_ht.c 31 KB

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