phy_common.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. Broadcom B43 wireless driver
  3. Common PHY routines
  4. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
  5. Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
  6. Copyright (c) 2005-2008 Michael Buesch <m@bues.ch>
  7. Copyright (c) 2005, 2006 Danny van Dyk <kugelfang@gentoo.org>
  8. Copyright (c) 2005, 2006 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; see the file COPYING. If not, write to
  19. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  20. Boston, MA 02110-1301, USA.
  21. */
  22. #include "phy_common.h"
  23. #include "phy_g.h"
  24. #include "phy_a.h"
  25. #include "phy_n.h"
  26. #include "phy_lp.h"
  27. #include "phy_ht.h"
  28. #include "phy_lcn.h"
  29. #include "b43.h"
  30. #include "main.h"
  31. int b43_phy_allocate(struct b43_wldev *dev)
  32. {
  33. struct b43_phy *phy = &(dev->phy);
  34. int err;
  35. phy->ops = NULL;
  36. switch (phy->type) {
  37. case B43_PHYTYPE_G:
  38. #ifdef CONFIG_B43_PHY_G
  39. phy->ops = &b43_phyops_g;
  40. #endif
  41. break;
  42. case B43_PHYTYPE_N:
  43. #ifdef CONFIG_B43_PHY_N
  44. phy->ops = &b43_phyops_n;
  45. #endif
  46. break;
  47. case B43_PHYTYPE_LP:
  48. #ifdef CONFIG_B43_PHY_LP
  49. phy->ops = &b43_phyops_lp;
  50. #endif
  51. break;
  52. case B43_PHYTYPE_HT:
  53. #ifdef CONFIG_B43_PHY_HT
  54. phy->ops = &b43_phyops_ht;
  55. #endif
  56. break;
  57. case B43_PHYTYPE_LCN:
  58. #ifdef CONFIG_B43_PHY_LCN
  59. phy->ops = &b43_phyops_lcn;
  60. #endif
  61. break;
  62. }
  63. if (B43_WARN_ON(!phy->ops))
  64. return -ENODEV;
  65. err = phy->ops->allocate(dev);
  66. if (err)
  67. phy->ops = NULL;
  68. return err;
  69. }
  70. void b43_phy_free(struct b43_wldev *dev)
  71. {
  72. dev->phy.ops->free(dev);
  73. dev->phy.ops = NULL;
  74. }
  75. int b43_phy_init(struct b43_wldev *dev)
  76. {
  77. struct b43_phy *phy = &dev->phy;
  78. const struct b43_phy_operations *ops = phy->ops;
  79. int err;
  80. /* During PHY init we need to use some channel. On the first init this
  81. * function is called *before* b43_op_config, so our pointer is NULL.
  82. */
  83. if (!phy->chandef) {
  84. phy->chandef = &dev->wl->hw->conf.chandef;
  85. phy->channel = phy->chandef->chan->hw_value;
  86. }
  87. phy->ops->switch_analog(dev, true);
  88. b43_software_rfkill(dev, false);
  89. err = ops->init(dev);
  90. if (err) {
  91. b43err(dev->wl, "PHY init failed\n");
  92. goto err_block_rf;
  93. }
  94. phy->do_full_init = false;
  95. err = b43_switch_channel(dev, phy->channel);
  96. if (err) {
  97. b43err(dev->wl, "PHY init: Channel switch to default failed\n");
  98. goto err_phy_exit;
  99. }
  100. return 0;
  101. err_phy_exit:
  102. phy->do_full_init = true;
  103. if (ops->exit)
  104. ops->exit(dev);
  105. err_block_rf:
  106. b43_software_rfkill(dev, true);
  107. return err;
  108. }
  109. void b43_phy_exit(struct b43_wldev *dev)
  110. {
  111. const struct b43_phy_operations *ops = dev->phy.ops;
  112. b43_software_rfkill(dev, true);
  113. dev->phy.do_full_init = true;
  114. if (ops->exit)
  115. ops->exit(dev);
  116. }
  117. bool b43_has_hardware_pctl(struct b43_wldev *dev)
  118. {
  119. if (!dev->phy.hardware_power_control)
  120. return false;
  121. if (!dev->phy.ops->supports_hwpctl)
  122. return false;
  123. return dev->phy.ops->supports_hwpctl(dev);
  124. }
  125. void b43_radio_lock(struct b43_wldev *dev)
  126. {
  127. u32 macctl;
  128. #if B43_DEBUG
  129. B43_WARN_ON(dev->phy.radio_locked);
  130. dev->phy.radio_locked = true;
  131. #endif
  132. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  133. macctl |= B43_MACCTL_RADIOLOCK;
  134. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  135. /* Commit the write and wait for the firmware
  136. * to finish any radio register access. */
  137. b43_read32(dev, B43_MMIO_MACCTL);
  138. udelay(10);
  139. }
  140. void b43_radio_unlock(struct b43_wldev *dev)
  141. {
  142. u32 macctl;
  143. #if B43_DEBUG
  144. B43_WARN_ON(!dev->phy.radio_locked);
  145. dev->phy.radio_locked = false;
  146. #endif
  147. /* Commit any write */
  148. b43_read16(dev, B43_MMIO_PHY_VER);
  149. /* unlock */
  150. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  151. macctl &= ~B43_MACCTL_RADIOLOCK;
  152. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  153. }
  154. void b43_phy_lock(struct b43_wldev *dev)
  155. {
  156. #if B43_DEBUG
  157. B43_WARN_ON(dev->phy.phy_locked);
  158. dev->phy.phy_locked = true;
  159. #endif
  160. B43_WARN_ON(dev->dev->core_rev < 3);
  161. if (!b43_is_mode(dev->wl, NL80211_IFTYPE_AP))
  162. b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
  163. }
  164. void b43_phy_unlock(struct b43_wldev *dev)
  165. {
  166. #if B43_DEBUG
  167. B43_WARN_ON(!dev->phy.phy_locked);
  168. dev->phy.phy_locked = false;
  169. #endif
  170. B43_WARN_ON(dev->dev->core_rev < 3);
  171. if (!b43_is_mode(dev->wl, NL80211_IFTYPE_AP))
  172. b43_power_saving_ctl_bits(dev, 0);
  173. }
  174. static inline void assert_mac_suspended(struct b43_wldev *dev)
  175. {
  176. if (!B43_DEBUG)
  177. return;
  178. if ((b43_status(dev) >= B43_STAT_INITIALIZED) &&
  179. (dev->mac_suspended <= 0)) {
  180. b43dbg(dev->wl, "PHY/RADIO register access with "
  181. "enabled MAC.\n");
  182. dump_stack();
  183. }
  184. }
  185. u16 b43_radio_read(struct b43_wldev *dev, u16 reg)
  186. {
  187. assert_mac_suspended(dev);
  188. dev->phy.writes_counter = 0;
  189. return dev->phy.ops->radio_read(dev, reg);
  190. }
  191. void b43_radio_write(struct b43_wldev *dev, u16 reg, u16 value)
  192. {
  193. assert_mac_suspended(dev);
  194. if (b43_bus_host_is_pci(dev->dev) &&
  195. ++dev->phy.writes_counter > B43_MAX_WRITES_IN_ROW) {
  196. b43_read32(dev, B43_MMIO_MACCTL);
  197. dev->phy.writes_counter = 1;
  198. }
  199. dev->phy.ops->radio_write(dev, reg, value);
  200. }
  201. void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask)
  202. {
  203. b43_radio_write16(dev, offset,
  204. b43_radio_read16(dev, offset) & mask);
  205. }
  206. void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set)
  207. {
  208. b43_radio_write16(dev, offset,
  209. b43_radio_read16(dev, offset) | set);
  210. }
  211. void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
  212. {
  213. b43_radio_write16(dev, offset,
  214. (b43_radio_read16(dev, offset) & mask) | set);
  215. }
  216. bool b43_radio_wait_value(struct b43_wldev *dev, u16 offset, u16 mask,
  217. u16 value, int delay, int timeout)
  218. {
  219. u16 val;
  220. int i;
  221. for (i = 0; i < timeout; i += delay) {
  222. val = b43_radio_read(dev, offset);
  223. if ((val & mask) == value)
  224. return true;
  225. udelay(delay);
  226. }
  227. return false;
  228. }
  229. u16 b43_phy_read(struct b43_wldev *dev, u16 reg)
  230. {
  231. assert_mac_suspended(dev);
  232. dev->phy.writes_counter = 0;
  233. if (dev->phy.ops->phy_read)
  234. return dev->phy.ops->phy_read(dev, reg);
  235. b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg);
  236. return b43_read16(dev, B43_MMIO_PHY_DATA);
  237. }
  238. void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value)
  239. {
  240. assert_mac_suspended(dev);
  241. if (b43_bus_host_is_pci(dev->dev) &&
  242. ++dev->phy.writes_counter > B43_MAX_WRITES_IN_ROW) {
  243. b43_read16(dev, B43_MMIO_PHY_VER);
  244. dev->phy.writes_counter = 1;
  245. }
  246. if (dev->phy.ops->phy_write)
  247. return dev->phy.ops->phy_write(dev, reg, value);
  248. b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg);
  249. b43_write16(dev, B43_MMIO_PHY_DATA, value);
  250. }
  251. void b43_phy_copy(struct b43_wldev *dev, u16 destreg, u16 srcreg)
  252. {
  253. assert_mac_suspended(dev);
  254. dev->phy.ops->phy_write(dev, destreg,
  255. dev->phy.ops->phy_read(dev, srcreg));
  256. }
  257. void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask)
  258. {
  259. if (dev->phy.ops->phy_maskset) {
  260. assert_mac_suspended(dev);
  261. dev->phy.ops->phy_maskset(dev, offset, mask, 0);
  262. } else {
  263. b43_phy_write(dev, offset,
  264. b43_phy_read(dev, offset) & mask);
  265. }
  266. }
  267. void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set)
  268. {
  269. if (dev->phy.ops->phy_maskset) {
  270. assert_mac_suspended(dev);
  271. dev->phy.ops->phy_maskset(dev, offset, 0xFFFF, set);
  272. } else {
  273. b43_phy_write(dev, offset,
  274. b43_phy_read(dev, offset) | set);
  275. }
  276. }
  277. void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
  278. {
  279. if (dev->phy.ops->phy_maskset) {
  280. assert_mac_suspended(dev);
  281. dev->phy.ops->phy_maskset(dev, offset, mask, set);
  282. } else {
  283. b43_phy_write(dev, offset,
  284. (b43_phy_read(dev, offset) & mask) | set);
  285. }
  286. }
  287. void b43_phy_put_into_reset(struct b43_wldev *dev)
  288. {
  289. u32 tmp;
  290. switch (dev->dev->bus_type) {
  291. #ifdef CONFIG_B43_BCMA
  292. case B43_BUS_BCMA:
  293. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  294. tmp &= ~B43_BCMA_IOCTL_GMODE;
  295. tmp |= B43_BCMA_IOCTL_PHY_RESET;
  296. tmp |= BCMA_IOCTL_FGC;
  297. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  298. udelay(1);
  299. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  300. tmp &= ~BCMA_IOCTL_FGC;
  301. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  302. udelay(1);
  303. break;
  304. #endif
  305. #ifdef CONFIG_B43_SSB
  306. case B43_BUS_SSB:
  307. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  308. tmp &= ~B43_TMSLOW_GMODE;
  309. tmp |= B43_TMSLOW_PHYRESET;
  310. tmp |= SSB_TMSLOW_FGC;
  311. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  312. usleep_range(1000, 2000);
  313. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  314. tmp &= ~SSB_TMSLOW_FGC;
  315. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  316. usleep_range(1000, 2000);
  317. break;
  318. #endif
  319. }
  320. }
  321. void b43_phy_take_out_of_reset(struct b43_wldev *dev)
  322. {
  323. u32 tmp;
  324. switch (dev->dev->bus_type) {
  325. #ifdef CONFIG_B43_BCMA
  326. case B43_BUS_BCMA:
  327. /* Unset reset bit (with forcing clock) */
  328. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  329. tmp &= ~B43_BCMA_IOCTL_PHY_RESET;
  330. tmp &= ~B43_BCMA_IOCTL_PHY_CLKEN;
  331. tmp |= BCMA_IOCTL_FGC;
  332. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  333. udelay(1);
  334. /* Do not force clock anymore */
  335. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  336. tmp &= ~BCMA_IOCTL_FGC;
  337. tmp |= B43_BCMA_IOCTL_PHY_CLKEN;
  338. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  339. udelay(1);
  340. break;
  341. #endif
  342. #ifdef CONFIG_B43_SSB
  343. case B43_BUS_SSB:
  344. /* Unset reset bit (with forcing clock) */
  345. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  346. tmp &= ~B43_TMSLOW_PHYRESET;
  347. tmp &= ~B43_TMSLOW_PHYCLKEN;
  348. tmp |= SSB_TMSLOW_FGC;
  349. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  350. ssb_read32(dev->dev->sdev, SSB_TMSLOW); /* flush */
  351. usleep_range(1000, 2000);
  352. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  353. tmp &= ~SSB_TMSLOW_FGC;
  354. tmp |= B43_TMSLOW_PHYCLKEN;
  355. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  356. ssb_read32(dev->dev->sdev, SSB_TMSLOW); /* flush */
  357. usleep_range(1000, 2000);
  358. break;
  359. #endif
  360. }
  361. }
  362. int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel)
  363. {
  364. struct b43_phy *phy = &(dev->phy);
  365. u16 channelcookie, savedcookie;
  366. int err;
  367. /* First we set the channel radio code to prevent the
  368. * firmware from sending ghost packets.
  369. */
  370. channelcookie = new_channel;
  371. if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ)
  372. channelcookie |= B43_SHM_SH_CHAN_5GHZ;
  373. /* FIXME: set 40Mhz flag if required */
  374. if (0)
  375. channelcookie |= B43_SHM_SH_CHAN_40MHZ;
  376. savedcookie = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN);
  377. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie);
  378. /* Now try to switch the PHY hardware channel. */
  379. err = phy->ops->switch_channel(dev, new_channel);
  380. if (err)
  381. goto err_restore_cookie;
  382. /* Wait for the radio to tune to the channel and stabilize. */
  383. msleep(8);
  384. return 0;
  385. err_restore_cookie:
  386. b43_shm_write16(dev, B43_SHM_SHARED,
  387. B43_SHM_SH_CHAN, savedcookie);
  388. return err;
  389. }
  390. void b43_software_rfkill(struct b43_wldev *dev, bool blocked)
  391. {
  392. struct b43_phy *phy = &dev->phy;
  393. b43_mac_suspend(dev);
  394. phy->ops->software_rfkill(dev, blocked);
  395. phy->radio_on = !blocked;
  396. b43_mac_enable(dev);
  397. }
  398. /**
  399. * b43_phy_txpower_adjust_work - TX power workqueue.
  400. *
  401. * Workqueue for updating the TX power parameters in hardware.
  402. */
  403. void b43_phy_txpower_adjust_work(struct work_struct *work)
  404. {
  405. struct b43_wl *wl = container_of(work, struct b43_wl,
  406. txpower_adjust_work);
  407. struct b43_wldev *dev;
  408. mutex_lock(&wl->mutex);
  409. dev = wl->current_dev;
  410. if (likely(dev && (b43_status(dev) >= B43_STAT_STARTED)))
  411. dev->phy.ops->adjust_txpower(dev);
  412. mutex_unlock(&wl->mutex);
  413. }
  414. void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags)
  415. {
  416. struct b43_phy *phy = &dev->phy;
  417. unsigned long now = jiffies;
  418. enum b43_txpwr_result result;
  419. if (!(flags & B43_TXPWR_IGNORE_TIME)) {
  420. /* Check if it's time for a TXpower check. */
  421. if (time_before(now, phy->next_txpwr_check_time))
  422. return; /* Not yet */
  423. }
  424. /* The next check will be needed in two seconds, or later. */
  425. phy->next_txpwr_check_time = round_jiffies(now + (HZ * 2));
  426. if ((dev->dev->board_vendor == SSB_BOARDVENDOR_BCM) &&
  427. (dev->dev->board_type == SSB_BOARD_BU4306))
  428. return; /* No software txpower adjustment needed */
  429. result = phy->ops->recalc_txpower(dev, !!(flags & B43_TXPWR_IGNORE_TSSI));
  430. if (result == B43_TXPWR_RES_DONE)
  431. return; /* We are done. */
  432. B43_WARN_ON(result != B43_TXPWR_RES_NEED_ADJUST);
  433. B43_WARN_ON(phy->ops->adjust_txpower == NULL);
  434. /* We must adjust the transmission power in hardware.
  435. * Schedule b43_phy_txpower_adjust_work(). */
  436. ieee80211_queue_work(dev->wl->hw, &dev->wl->txpower_adjust_work);
  437. }
  438. int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset)
  439. {
  440. const bool is_ofdm = (shm_offset != B43_SHM_SH_TSSI_CCK);
  441. unsigned int a, b, c, d;
  442. unsigned int average;
  443. u32 tmp;
  444. tmp = b43_shm_read32(dev, B43_SHM_SHARED, shm_offset);
  445. a = tmp & 0xFF;
  446. b = (tmp >> 8) & 0xFF;
  447. c = (tmp >> 16) & 0xFF;
  448. d = (tmp >> 24) & 0xFF;
  449. if (a == 0 || a == B43_TSSI_MAX ||
  450. b == 0 || b == B43_TSSI_MAX ||
  451. c == 0 || c == B43_TSSI_MAX ||
  452. d == 0 || d == B43_TSSI_MAX)
  453. return -ENOENT;
  454. /* The values are OK. Clear them. */
  455. tmp = B43_TSSI_MAX | (B43_TSSI_MAX << 8) |
  456. (B43_TSSI_MAX << 16) | (B43_TSSI_MAX << 24);
  457. b43_shm_write32(dev, B43_SHM_SHARED, shm_offset, tmp);
  458. if (is_ofdm) {
  459. a = (a + 32) & 0x3F;
  460. b = (b + 32) & 0x3F;
  461. c = (c + 32) & 0x3F;
  462. d = (d + 32) & 0x3F;
  463. }
  464. /* Get the average of the values with 0.5 added to each value. */
  465. average = (a + b + c + d + 2) / 4;
  466. if (is_ofdm) {
  467. /* Adjust for CCK-boost */
  468. if (b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF1)
  469. & B43_HF_CCKBOOST)
  470. average = (average >= 13) ? (average - 13) : 0;
  471. }
  472. return average;
  473. }
  474. void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on)
  475. {
  476. b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4);
  477. }
  478. bool b43_is_40mhz(struct b43_wldev *dev)
  479. {
  480. return dev->phy.chandef->width == NL80211_CHAN_WIDTH_40;
  481. }
  482. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BmacPhyClkFgc */
  483. void b43_phy_force_clock(struct b43_wldev *dev, bool force)
  484. {
  485. u32 tmp;
  486. WARN_ON(dev->phy.type != B43_PHYTYPE_N &&
  487. dev->phy.type != B43_PHYTYPE_HT);
  488. switch (dev->dev->bus_type) {
  489. #ifdef CONFIG_B43_BCMA
  490. case B43_BUS_BCMA:
  491. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  492. if (force)
  493. tmp |= BCMA_IOCTL_FGC;
  494. else
  495. tmp &= ~BCMA_IOCTL_FGC;
  496. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  497. break;
  498. #endif
  499. #ifdef CONFIG_B43_SSB
  500. case B43_BUS_SSB:
  501. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  502. if (force)
  503. tmp |= SSB_TMSLOW_FGC;
  504. else
  505. tmp &= ~SSB_TMSLOW_FGC;
  506. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  507. break;
  508. #endif
  509. }
  510. }
  511. /* http://bcm-v4.sipsolutions.net/802.11/PHY/Cordic */
  512. struct b43_c32 b43_cordic(int theta)
  513. {
  514. static const u32 arctg[] = {
  515. 2949120, 1740967, 919879, 466945, 234379, 117304,
  516. 58666, 29335, 14668, 7334, 3667, 1833,
  517. 917, 458, 229, 115, 57, 29,
  518. };
  519. u8 i;
  520. s32 tmp;
  521. s8 signx = 1;
  522. u32 angle = 0;
  523. struct b43_c32 ret = { .i = 39797, .q = 0, };
  524. while (theta > (180 << 16))
  525. theta -= (360 << 16);
  526. while (theta < -(180 << 16))
  527. theta += (360 << 16);
  528. if (theta > (90 << 16)) {
  529. theta -= (180 << 16);
  530. signx = -1;
  531. } else if (theta < -(90 << 16)) {
  532. theta += (180 << 16);
  533. signx = -1;
  534. }
  535. for (i = 0; i <= 17; i++) {
  536. if (theta > angle) {
  537. tmp = ret.i - (ret.q >> i);
  538. ret.q += ret.i >> i;
  539. ret.i = tmp;
  540. angle += arctg[i];
  541. } else {
  542. tmp = ret.i + (ret.q >> i);
  543. ret.q -= ret.i >> i;
  544. ret.i = tmp;
  545. angle -= arctg[i];
  546. }
  547. }
  548. ret.i *= signx;
  549. ret.q *= signx;
  550. return ret;
  551. }