phy_ht.c 31 KB

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