phy_common.c 15 KB

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