phy_common.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. b43_phy_write(dev, destreg, b43_phy_read(dev, srcreg));
  254. }
  255. void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask)
  256. {
  257. if (dev->phy.ops->phy_maskset) {
  258. assert_mac_suspended(dev);
  259. dev->phy.ops->phy_maskset(dev, offset, mask, 0);
  260. } else {
  261. b43_phy_write(dev, offset,
  262. b43_phy_read(dev, offset) & mask);
  263. }
  264. }
  265. void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set)
  266. {
  267. if (dev->phy.ops->phy_maskset) {
  268. assert_mac_suspended(dev);
  269. dev->phy.ops->phy_maskset(dev, offset, 0xFFFF, set);
  270. } else {
  271. b43_phy_write(dev, offset,
  272. b43_phy_read(dev, offset) | set);
  273. }
  274. }
  275. void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
  276. {
  277. if (dev->phy.ops->phy_maskset) {
  278. assert_mac_suspended(dev);
  279. dev->phy.ops->phy_maskset(dev, offset, mask, set);
  280. } else {
  281. b43_phy_write(dev, offset,
  282. (b43_phy_read(dev, offset) & mask) | set);
  283. }
  284. }
  285. void b43_phy_put_into_reset(struct b43_wldev *dev)
  286. {
  287. u32 tmp;
  288. switch (dev->dev->bus_type) {
  289. #ifdef CONFIG_B43_BCMA
  290. case B43_BUS_BCMA:
  291. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  292. tmp &= ~B43_BCMA_IOCTL_GMODE;
  293. tmp |= B43_BCMA_IOCTL_PHY_RESET;
  294. tmp |= BCMA_IOCTL_FGC;
  295. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  296. udelay(1);
  297. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  298. tmp &= ~BCMA_IOCTL_FGC;
  299. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  300. udelay(1);
  301. break;
  302. #endif
  303. #ifdef CONFIG_B43_SSB
  304. case B43_BUS_SSB:
  305. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  306. tmp &= ~B43_TMSLOW_GMODE;
  307. tmp |= B43_TMSLOW_PHYRESET;
  308. tmp |= SSB_TMSLOW_FGC;
  309. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  310. usleep_range(1000, 2000);
  311. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  312. tmp &= ~SSB_TMSLOW_FGC;
  313. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  314. usleep_range(1000, 2000);
  315. break;
  316. #endif
  317. }
  318. }
  319. void b43_phy_take_out_of_reset(struct b43_wldev *dev)
  320. {
  321. u32 tmp;
  322. switch (dev->dev->bus_type) {
  323. #ifdef CONFIG_B43_BCMA
  324. case B43_BUS_BCMA:
  325. /* Unset reset bit (with forcing clock) */
  326. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  327. tmp &= ~B43_BCMA_IOCTL_PHY_RESET;
  328. tmp &= ~B43_BCMA_IOCTL_PHY_CLKEN;
  329. tmp |= BCMA_IOCTL_FGC;
  330. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  331. udelay(1);
  332. /* Do not force clock anymore */
  333. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  334. tmp &= ~BCMA_IOCTL_FGC;
  335. tmp |= B43_BCMA_IOCTL_PHY_CLKEN;
  336. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  337. udelay(1);
  338. break;
  339. #endif
  340. #ifdef CONFIG_B43_SSB
  341. case B43_BUS_SSB:
  342. /* Unset reset bit (with forcing clock) */
  343. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  344. tmp &= ~B43_TMSLOW_PHYRESET;
  345. tmp &= ~B43_TMSLOW_PHYCLKEN;
  346. tmp |= SSB_TMSLOW_FGC;
  347. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  348. ssb_read32(dev->dev->sdev, SSB_TMSLOW); /* flush */
  349. usleep_range(1000, 2000);
  350. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  351. tmp &= ~SSB_TMSLOW_FGC;
  352. tmp |= B43_TMSLOW_PHYCLKEN;
  353. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  354. ssb_read32(dev->dev->sdev, SSB_TMSLOW); /* flush */
  355. usleep_range(1000, 2000);
  356. break;
  357. #endif
  358. }
  359. }
  360. int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel)
  361. {
  362. struct b43_phy *phy = &(dev->phy);
  363. u16 channelcookie, savedcookie;
  364. int err;
  365. /* First we set the channel radio code to prevent the
  366. * firmware from sending ghost packets.
  367. */
  368. channelcookie = new_channel;
  369. if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ)
  370. channelcookie |= B43_SHM_SH_CHAN_5GHZ;
  371. /* FIXME: set 40Mhz flag if required */
  372. if (0)
  373. channelcookie |= B43_SHM_SH_CHAN_40MHZ;
  374. savedcookie = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN);
  375. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie);
  376. /* Now try to switch the PHY hardware channel. */
  377. err = phy->ops->switch_channel(dev, new_channel);
  378. if (err)
  379. goto err_restore_cookie;
  380. /* Wait for the radio to tune to the channel and stabilize. */
  381. msleep(8);
  382. return 0;
  383. err_restore_cookie:
  384. b43_shm_write16(dev, B43_SHM_SHARED,
  385. B43_SHM_SH_CHAN, savedcookie);
  386. return err;
  387. }
  388. void b43_software_rfkill(struct b43_wldev *dev, bool blocked)
  389. {
  390. struct b43_phy *phy = &dev->phy;
  391. b43_mac_suspend(dev);
  392. phy->ops->software_rfkill(dev, blocked);
  393. phy->radio_on = !blocked;
  394. b43_mac_enable(dev);
  395. }
  396. /**
  397. * b43_phy_txpower_adjust_work - TX power workqueue.
  398. *
  399. * Workqueue for updating the TX power parameters in hardware.
  400. */
  401. void b43_phy_txpower_adjust_work(struct work_struct *work)
  402. {
  403. struct b43_wl *wl = container_of(work, struct b43_wl,
  404. txpower_adjust_work);
  405. struct b43_wldev *dev;
  406. mutex_lock(&wl->mutex);
  407. dev = wl->current_dev;
  408. if (likely(dev && (b43_status(dev) >= B43_STAT_STARTED)))
  409. dev->phy.ops->adjust_txpower(dev);
  410. mutex_unlock(&wl->mutex);
  411. }
  412. void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags)
  413. {
  414. struct b43_phy *phy = &dev->phy;
  415. unsigned long now = jiffies;
  416. enum b43_txpwr_result result;
  417. if (!(flags & B43_TXPWR_IGNORE_TIME)) {
  418. /* Check if it's time for a TXpower check. */
  419. if (time_before(now, phy->next_txpwr_check_time))
  420. return; /* Not yet */
  421. }
  422. /* The next check will be needed in two seconds, or later. */
  423. phy->next_txpwr_check_time = round_jiffies(now + (HZ * 2));
  424. if ((dev->dev->board_vendor == SSB_BOARDVENDOR_BCM) &&
  425. (dev->dev->board_type == SSB_BOARD_BU4306))
  426. return; /* No software txpower adjustment needed */
  427. result = phy->ops->recalc_txpower(dev, !!(flags & B43_TXPWR_IGNORE_TSSI));
  428. if (result == B43_TXPWR_RES_DONE)
  429. return; /* We are done. */
  430. B43_WARN_ON(result != B43_TXPWR_RES_NEED_ADJUST);
  431. B43_WARN_ON(phy->ops->adjust_txpower == NULL);
  432. /* We must adjust the transmission power in hardware.
  433. * Schedule b43_phy_txpower_adjust_work(). */
  434. ieee80211_queue_work(dev->wl->hw, &dev->wl->txpower_adjust_work);
  435. }
  436. int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset)
  437. {
  438. const bool is_ofdm = (shm_offset != B43_SHM_SH_TSSI_CCK);
  439. unsigned int a, b, c, d;
  440. unsigned int average;
  441. u32 tmp;
  442. tmp = b43_shm_read32(dev, B43_SHM_SHARED, shm_offset);
  443. a = tmp & 0xFF;
  444. b = (tmp >> 8) & 0xFF;
  445. c = (tmp >> 16) & 0xFF;
  446. d = (tmp >> 24) & 0xFF;
  447. if (a == 0 || a == B43_TSSI_MAX ||
  448. b == 0 || b == B43_TSSI_MAX ||
  449. c == 0 || c == B43_TSSI_MAX ||
  450. d == 0 || d == B43_TSSI_MAX)
  451. return -ENOENT;
  452. /* The values are OK. Clear them. */
  453. tmp = B43_TSSI_MAX | (B43_TSSI_MAX << 8) |
  454. (B43_TSSI_MAX << 16) | (B43_TSSI_MAX << 24);
  455. b43_shm_write32(dev, B43_SHM_SHARED, shm_offset, tmp);
  456. if (is_ofdm) {
  457. a = (a + 32) & 0x3F;
  458. b = (b + 32) & 0x3F;
  459. c = (c + 32) & 0x3F;
  460. d = (d + 32) & 0x3F;
  461. }
  462. /* Get the average of the values with 0.5 added to each value. */
  463. average = (a + b + c + d + 2) / 4;
  464. if (is_ofdm) {
  465. /* Adjust for CCK-boost */
  466. if (b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF1)
  467. & B43_HF_CCKBOOST)
  468. average = (average >= 13) ? (average - 13) : 0;
  469. }
  470. return average;
  471. }
  472. void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on)
  473. {
  474. b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4);
  475. }
  476. bool b43_is_40mhz(struct b43_wldev *dev)
  477. {
  478. return dev->phy.chandef->width == NL80211_CHAN_WIDTH_40;
  479. }
  480. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BmacPhyClkFgc */
  481. void b43_phy_force_clock(struct b43_wldev *dev, bool force)
  482. {
  483. u32 tmp;
  484. WARN_ON(dev->phy.type != B43_PHYTYPE_N &&
  485. dev->phy.type != B43_PHYTYPE_HT);
  486. switch (dev->dev->bus_type) {
  487. #ifdef CONFIG_B43_BCMA
  488. case B43_BUS_BCMA:
  489. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  490. if (force)
  491. tmp |= BCMA_IOCTL_FGC;
  492. else
  493. tmp &= ~BCMA_IOCTL_FGC;
  494. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  495. break;
  496. #endif
  497. #ifdef CONFIG_B43_SSB
  498. case B43_BUS_SSB:
  499. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  500. if (force)
  501. tmp |= SSB_TMSLOW_FGC;
  502. else
  503. tmp &= ~SSB_TMSLOW_FGC;
  504. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  505. break;
  506. #endif
  507. }
  508. }
  509. /* http://bcm-v4.sipsolutions.net/802.11/PHY/Cordic */
  510. struct b43_c32 b43_cordic(int theta)
  511. {
  512. static const u32 arctg[] = {
  513. 2949120, 1740967, 919879, 466945, 234379, 117304,
  514. 58666, 29335, 14668, 7334, 3667, 1833,
  515. 917, 458, 229, 115, 57, 29,
  516. };
  517. u8 i;
  518. s32 tmp;
  519. s8 signx = 1;
  520. u32 angle = 0;
  521. struct b43_c32 ret = { .i = 39797, .q = 0, };
  522. while (theta > (180 << 16))
  523. theta -= (360 << 16);
  524. while (theta < -(180 << 16))
  525. theta += (360 << 16);
  526. if (theta > (90 << 16)) {
  527. theta -= (180 << 16);
  528. signx = -1;
  529. } else if (theta < -(90 << 16)) {
  530. theta += (180 << 16);
  531. signx = -1;
  532. }
  533. for (i = 0; i <= 17; i++) {
  534. if (theta > angle) {
  535. tmp = ret.i - (ret.q >> i);
  536. ret.q += ret.i >> i;
  537. ret.i = tmp;
  538. angle += arctg[i];
  539. } else {
  540. tmp = ret.i + (ret.q >> i);
  541. ret.q -= ret.i >> i;
  542. ret.i = tmp;
  543. angle -= arctg[i];
  544. }
  545. }
  546. ret.i *= signx;
  547. ret.q *= signx;
  548. return ret;
  549. }