reset.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. /*
  2. * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
  4. * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
  5. * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
  6. * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
  7. *
  8. * Permission to use, copy, modify, and distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. *
  20. */
  21. #define _ATH5K_RESET
  22. /*****************************\
  23. Reset functions and helpers
  24. \*****************************/
  25. #include <linux/pci.h> /* To determine if a card is pci-e */
  26. #include <linux/log2.h>
  27. #include "ath5k.h"
  28. #include "reg.h"
  29. #include "base.h"
  30. #include "debug.h"
  31. /**
  32. * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
  33. *
  34. * @ah: the &struct ath5k_hw
  35. * @channel: the currently set channel upon reset
  36. *
  37. * Write the delta slope coefficient (used on pilot tracking ?) for OFDM
  38. * operation on the AR5212 upon reset. This is a helper for ath5k_hw_reset().
  39. *
  40. * Since delta slope is floating point we split it on its exponent and
  41. * mantissa and provide these values on hw.
  42. *
  43. * For more infos i think this patent is related
  44. * http://www.freepatentsonline.com/7184495.html
  45. */
  46. static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
  47. struct ieee80211_channel *channel)
  48. {
  49. /* Get exponent and mantissa and set it */
  50. u32 coef_scaled, coef_exp, coef_man,
  51. ds_coef_exp, ds_coef_man, clock;
  52. BUG_ON(!(ah->ah_version == AR5K_AR5212) ||
  53. !(channel->hw_value & CHANNEL_OFDM));
  54. /* Get coefficient
  55. * ALGO: coef = (5 * clock * carrier_freq) / 2)
  56. * we scale coef by shifting clock value by 24 for
  57. * better precision since we use integers */
  58. /* TODO: Half/quarter rate */
  59. clock = ath5k_hw_htoclock(1, channel->hw_value & CHANNEL_TURBO);
  60. coef_scaled = ((5 * (clock << 24)) / 2) / channel->center_freq;
  61. /* Get exponent
  62. * ALGO: coef_exp = 14 - highest set bit position */
  63. coef_exp = ilog2(coef_scaled);
  64. /* Doesn't make sense if it's zero*/
  65. if (!coef_scaled || !coef_exp)
  66. return -EINVAL;
  67. /* Note: we've shifted coef_scaled by 24 */
  68. coef_exp = 14 - (coef_exp - 24);
  69. /* Get mantissa (significant digits)
  70. * ALGO: coef_mant = floor(coef_scaled* 2^coef_exp+0.5) */
  71. coef_man = coef_scaled +
  72. (1 << (24 - coef_exp - 1));
  73. /* Calculate delta slope coefficient exponent
  74. * and mantissa (remove scaling) and set them on hw */
  75. ds_coef_man = coef_man >> (24 - coef_exp);
  76. ds_coef_exp = coef_exp - 16;
  77. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
  78. AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
  79. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
  80. AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
  81. return 0;
  82. }
  83. /*
  84. * index into rates for control rates, we can set it up like this because
  85. * this is only used for AR5212 and we know it supports G mode
  86. */
  87. static const unsigned int control_rates[] =
  88. { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };
  89. /**
  90. * ath5k_hw_write_rate_duration - fill rate code to duration table
  91. *
  92. * @ah: the &struct ath5k_hw
  93. * @mode: one of enum ath5k_driver_mode
  94. *
  95. * Write the rate code to duration table upon hw reset. This is a helper for
  96. * ath5k_hw_reset(). It seems all this is doing is setting an ACK timeout on
  97. * the hardware, based on current mode, for each rate. The rates which are
  98. * capable of short preamble (802.11b rates 2Mbps, 5.5Mbps, and 11Mbps) have
  99. * different rate code so we write their value twice (one for long preample
  100. * and one for short).
  101. *
  102. * Note: Band doesn't matter here, if we set the values for OFDM it works
  103. * on both a and g modes. So all we have to do is set values for all g rates
  104. * that include all OFDM and CCK rates. If we operate in turbo or xr/half/
  105. * quarter rate mode, we need to use another set of bitrates (that's why we
  106. * need the mode parameter) but we don't handle these proprietary modes yet.
  107. */
  108. static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
  109. unsigned int mode)
  110. {
  111. struct ath5k_softc *sc = ah->ah_sc;
  112. struct ieee80211_rate *rate;
  113. unsigned int i;
  114. /* Write rate duration table */
  115. for (i = 0; i < sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates; i++) {
  116. u32 reg;
  117. u16 tx_time;
  118. rate = &sc->sbands[IEEE80211_BAND_2GHZ].bitrates[control_rates[i]];
  119. /* Set ACK timeout */
  120. reg = AR5K_RATE_DUR(rate->hw_value);
  121. /* An ACK frame consists of 10 bytes. If you add the FCS,
  122. * which ieee80211_generic_frame_duration() adds,
  123. * its 14 bytes. Note we use the control rate and not the
  124. * actual rate for this rate. See mac80211 tx.c
  125. * ieee80211_duration() for a brief description of
  126. * what rate we should choose to TX ACKs. */
  127. tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
  128. sc->vif, 10, rate));
  129. ath5k_hw_reg_write(ah, tx_time, reg);
  130. if (!(rate->flags & IEEE80211_RATE_SHORT_PREAMBLE))
  131. continue;
  132. /*
  133. * We're not distinguishing short preamble here,
  134. * This is true, all we'll get is a longer value here
  135. * which is not necessarilly bad. We could use
  136. * export ieee80211_frame_duration() but that needs to be
  137. * fixed first to be properly used by mac802111 drivers:
  138. *
  139. * - remove erp stuff and let the routine figure ofdm
  140. * erp rates
  141. * - remove passing argument ieee80211_local as
  142. * drivers don't have access to it
  143. * - move drivers using ieee80211_generic_frame_duration()
  144. * to this
  145. */
  146. ath5k_hw_reg_write(ah, tx_time,
  147. reg + (AR5K_SET_SHORT_PREAMBLE << 2));
  148. }
  149. }
  150. /*
  151. * Reset chipset
  152. */
  153. static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
  154. {
  155. int ret;
  156. u32 mask = val ? val : ~0U;
  157. ATH5K_TRACE(ah->ah_sc);
  158. /* Read-and-clear RX Descriptor Pointer*/
  159. ath5k_hw_reg_read(ah, AR5K_RXDP);
  160. /*
  161. * Reset the device and wait until success
  162. */
  163. ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
  164. /* Wait at least 128 PCI clocks */
  165. udelay(15);
  166. if (ah->ah_version == AR5K_AR5210) {
  167. val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
  168. | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
  169. mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
  170. | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
  171. } else {
  172. val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  173. mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  174. }
  175. ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
  176. /*
  177. * Reset configuration register (for hw byte-swap). Note that this
  178. * is only set for big endian. We do the necessary magic in
  179. * AR5K_INIT_CFG.
  180. */
  181. if ((val & AR5K_RESET_CTL_PCU) == 0)
  182. ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
  183. return ret;
  184. }
  185. /*
  186. * Sleep control
  187. */
  188. int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
  189. bool set_chip, u16 sleep_duration)
  190. {
  191. unsigned int i;
  192. u32 staid, data;
  193. ATH5K_TRACE(ah->ah_sc);
  194. staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
  195. switch (mode) {
  196. case AR5K_PM_AUTO:
  197. staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
  198. /* fallthrough */
  199. case AR5K_PM_NETWORK_SLEEP:
  200. if (set_chip)
  201. ath5k_hw_reg_write(ah,
  202. AR5K_SLEEP_CTL_SLE_ALLOW |
  203. sleep_duration,
  204. AR5K_SLEEP_CTL);
  205. staid |= AR5K_STA_ID1_PWR_SV;
  206. break;
  207. case AR5K_PM_FULL_SLEEP:
  208. if (set_chip)
  209. ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
  210. AR5K_SLEEP_CTL);
  211. staid |= AR5K_STA_ID1_PWR_SV;
  212. break;
  213. case AR5K_PM_AWAKE:
  214. staid &= ~AR5K_STA_ID1_PWR_SV;
  215. if (!set_chip)
  216. goto commit;
  217. /* Preserve sleep duration */
  218. data = ath5k_hw_reg_read(ah, AR5K_SLEEP_CTL);
  219. if (data & 0xffc00000)
  220. data = 0;
  221. else
  222. data = data & 0xfffcffff;
  223. ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
  224. udelay(15);
  225. for (i = 50; i > 0; i--) {
  226. /* Check if the chip did wake up */
  227. if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  228. AR5K_PCICFG_SPWR_DN) == 0)
  229. break;
  230. /* Wait a bit and retry */
  231. udelay(200);
  232. ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
  233. }
  234. /* Fail if the chip didn't wake up */
  235. if (i <= 0)
  236. return -EIO;
  237. break;
  238. default:
  239. return -EINVAL;
  240. }
  241. commit:
  242. ah->ah_power_mode = mode;
  243. ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
  244. return 0;
  245. }
  246. /*
  247. * Bring up MAC + PHY Chips and program PLL
  248. * TODO: Half/Quarter rate support
  249. */
  250. int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
  251. {
  252. struct pci_dev *pdev = ah->ah_sc->pdev;
  253. u32 turbo, mode, clock, bus_flags;
  254. int ret;
  255. turbo = 0;
  256. mode = 0;
  257. clock = 0;
  258. ATH5K_TRACE(ah->ah_sc);
  259. /* Wakeup the device */
  260. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  261. if (ret) {
  262. ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
  263. return ret;
  264. }
  265. if (ah->ah_version != AR5K_AR5210) {
  266. /*
  267. * Get channel mode flags
  268. */
  269. if (ah->ah_radio >= AR5K_RF5112) {
  270. mode = AR5K_PHY_MODE_RAD_RF5112;
  271. clock = AR5K_PHY_PLL_RF5112;
  272. } else {
  273. mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
  274. clock = AR5K_PHY_PLL_RF5111; /*Zero*/
  275. }
  276. if (flags & CHANNEL_2GHZ) {
  277. mode |= AR5K_PHY_MODE_FREQ_2GHZ;
  278. clock |= AR5K_PHY_PLL_44MHZ;
  279. if (flags & CHANNEL_CCK) {
  280. mode |= AR5K_PHY_MODE_MOD_CCK;
  281. } else if (flags & CHANNEL_OFDM) {
  282. /* XXX Dynamic OFDM/CCK is not supported by the
  283. * AR5211 so we set MOD_OFDM for plain g (no
  284. * CCK headers) operation. We need to test
  285. * this, 5211 might support ofdm-only g after
  286. * all, there are also initial register values
  287. * in the code for g mode (see initvals.c). */
  288. if (ah->ah_version == AR5K_AR5211)
  289. mode |= AR5K_PHY_MODE_MOD_OFDM;
  290. else
  291. mode |= AR5K_PHY_MODE_MOD_DYN;
  292. } else {
  293. ATH5K_ERR(ah->ah_sc,
  294. "invalid radio modulation mode\n");
  295. return -EINVAL;
  296. }
  297. } else if (flags & CHANNEL_5GHZ) {
  298. mode |= AR5K_PHY_MODE_FREQ_5GHZ;
  299. if (ah->ah_radio == AR5K_RF5413)
  300. clock = AR5K_PHY_PLL_40MHZ_5413;
  301. else
  302. clock |= AR5K_PHY_PLL_40MHZ;
  303. if (flags & CHANNEL_OFDM)
  304. mode |= AR5K_PHY_MODE_MOD_OFDM;
  305. else {
  306. ATH5K_ERR(ah->ah_sc,
  307. "invalid radio modulation mode\n");
  308. return -EINVAL;
  309. }
  310. } else {
  311. ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
  312. return -EINVAL;
  313. }
  314. if (flags & CHANNEL_TURBO)
  315. turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
  316. } else { /* Reset the device */
  317. /* ...enable Atheros turbo mode if requested */
  318. if (flags & CHANNEL_TURBO)
  319. ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
  320. AR5K_PHY_TURBO);
  321. }
  322. /* reseting PCI on PCI-E cards results card to hang
  323. * and always return 0xffff... so we ingore that flag
  324. * for PCI-E cards */
  325. bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
  326. /* Reset chipset */
  327. if (ah->ah_version == AR5K_AR5210) {
  328. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  329. AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
  330. AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
  331. mdelay(2);
  332. } else {
  333. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  334. AR5K_RESET_CTL_BASEBAND | bus_flags);
  335. }
  336. if (ret) {
  337. ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
  338. return -EIO;
  339. }
  340. /* ...wakeup again!*/
  341. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  342. if (ret) {
  343. ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
  344. return ret;
  345. }
  346. /* ...final warm reset */
  347. if (ath5k_hw_nic_reset(ah, 0)) {
  348. ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
  349. return -EIO;
  350. }
  351. if (ah->ah_version != AR5K_AR5210) {
  352. /* ...update PLL if needed */
  353. if (ath5k_hw_reg_read(ah, AR5K_PHY_PLL) != clock) {
  354. ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
  355. udelay(300);
  356. }
  357. /* ...set the PHY operating mode */
  358. ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
  359. ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
  360. }
  361. return 0;
  362. }
  363. /*
  364. * If there is an external 32KHz crystal available, use it
  365. * as ref. clock instead of 32/40MHz clock and baseband clocks
  366. * to save power during sleep or restore normal 32/40MHz
  367. * operation.
  368. *
  369. * XXX: When operating on 32KHz certain PHY registers (27 - 31,
  370. * 123 - 127) require delay on access.
  371. */
  372. static void ath5k_hw_set_sleep_clock(struct ath5k_hw *ah, bool enable)
  373. {
  374. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  375. u32 scal, spending, usec32;
  376. /* Only set 32KHz settings if we have an external
  377. * 32KHz crystal present */
  378. if ((AR5K_EEPROM_HAS32KHZCRYSTAL(ee->ee_misc1) ||
  379. AR5K_EEPROM_HAS32KHZCRYSTAL_OLD(ee->ee_misc1)) &&
  380. enable) {
  381. /* 1 usec/cycle */
  382. AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, 1);
  383. /* Set up tsf increment on each cycle */
  384. AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 61);
  385. /* Set baseband sleep control registers
  386. * and sleep control rate */
  387. ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
  388. if ((ah->ah_radio == AR5K_RF5112) ||
  389. (ah->ah_radio == AR5K_RF5413) ||
  390. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
  391. spending = 0x14;
  392. else
  393. spending = 0x18;
  394. ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
  395. if ((ah->ah_radio == AR5K_RF5112) ||
  396. (ah->ah_radio == AR5K_RF5413) ||
  397. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
  398. ath5k_hw_reg_write(ah, 0x26, AR5K_PHY_SLMT);
  399. ath5k_hw_reg_write(ah, 0x0d, AR5K_PHY_SCAL);
  400. ath5k_hw_reg_write(ah, 0x07, AR5K_PHY_SCLOCK);
  401. ath5k_hw_reg_write(ah, 0x3f, AR5K_PHY_SDELAY);
  402. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  403. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x02);
  404. } else {
  405. ath5k_hw_reg_write(ah, 0x0a, AR5K_PHY_SLMT);
  406. ath5k_hw_reg_write(ah, 0x0c, AR5K_PHY_SCAL);
  407. ath5k_hw_reg_write(ah, 0x03, AR5K_PHY_SCLOCK);
  408. ath5k_hw_reg_write(ah, 0x20, AR5K_PHY_SDELAY);
  409. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  410. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x03);
  411. }
  412. /* Enable sleep clock operation */
  413. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG,
  414. AR5K_PCICFG_SLEEP_CLOCK_EN);
  415. } else {
  416. /* Disable sleep clock operation and
  417. * restore default parameters */
  418. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
  419. AR5K_PCICFG_SLEEP_CLOCK_EN);
  420. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  421. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0);
  422. ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
  423. ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
  424. if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
  425. scal = AR5K_PHY_SCAL_32MHZ_2417;
  426. else if (ee->ee_is_hb63)
  427. scal = AR5K_PHY_SCAL_32MHZ_HB63;
  428. else
  429. scal = AR5K_PHY_SCAL_32MHZ;
  430. ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
  431. ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
  432. ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
  433. if ((ah->ah_radio == AR5K_RF5112) ||
  434. (ah->ah_radio == AR5K_RF5413) ||
  435. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
  436. spending = 0x14;
  437. else
  438. spending = 0x18;
  439. ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
  440. if ((ah->ah_radio == AR5K_RF5112) ||
  441. (ah->ah_radio == AR5K_RF5413))
  442. usec32 = 39;
  443. else
  444. usec32 = 31;
  445. AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, usec32);
  446. AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 1);
  447. }
  448. return;
  449. }
  450. /* TODO: Half/Quarter rate */
  451. static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
  452. struct ieee80211_channel *channel)
  453. {
  454. if (ah->ah_version == AR5K_AR5212 &&
  455. ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
  456. /* Setup ADC control */
  457. ath5k_hw_reg_write(ah,
  458. (AR5K_REG_SM(2,
  459. AR5K_PHY_ADC_CTL_INBUFGAIN_OFF) |
  460. AR5K_REG_SM(2,
  461. AR5K_PHY_ADC_CTL_INBUFGAIN_ON) |
  462. AR5K_PHY_ADC_CTL_PWD_DAC_OFF |
  463. AR5K_PHY_ADC_CTL_PWD_ADC_OFF),
  464. AR5K_PHY_ADC_CTL);
  465. /* Disable barker RSSI threshold */
  466. AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
  467. AR5K_PHY_DAG_CCK_CTL_EN_RSSI_THR);
  468. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
  469. AR5K_PHY_DAG_CCK_CTL_RSSI_THR, 2);
  470. /* Set the mute mask */
  471. ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
  472. }
  473. /* Clear PHY_BLUETOOTH to allow RX_CLEAR line debug */
  474. if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212B)
  475. ath5k_hw_reg_write(ah, 0, AR5K_PHY_BLUETOOTH);
  476. /* Enable DCU double buffering */
  477. if (ah->ah_phy_revision > AR5K_SREV_PHY_5212B)
  478. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  479. AR5K_TXCFG_DCU_DBL_BUF_DIS);
  480. /* Set DAC/ADC delays */
  481. if (ah->ah_version == AR5K_AR5212) {
  482. u32 scal;
  483. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  484. if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
  485. scal = AR5K_PHY_SCAL_32MHZ_2417;
  486. else if (ee->ee_is_hb63)
  487. scal = AR5K_PHY_SCAL_32MHZ_HB63;
  488. else
  489. scal = AR5K_PHY_SCAL_32MHZ;
  490. ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
  491. }
  492. /* Set fast ADC */
  493. if ((ah->ah_radio == AR5K_RF5413) ||
  494. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
  495. u32 fast_adc = true;
  496. if (channel->center_freq == 2462 ||
  497. channel->center_freq == 2467)
  498. fast_adc = 0;
  499. /* Only update if needed */
  500. if (ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ADC) != fast_adc)
  501. ath5k_hw_reg_write(ah, fast_adc,
  502. AR5K_PHY_FAST_ADC);
  503. }
  504. /* Fix for first revision of the RF5112 RF chipset */
  505. if (ah->ah_radio == AR5K_RF5112 &&
  506. ah->ah_radio_5ghz_revision <
  507. AR5K_SREV_RAD_5112A) {
  508. u32 data;
  509. ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
  510. AR5K_PHY_CCKTXCTL);
  511. if (channel->hw_value & CHANNEL_5GHZ)
  512. data = 0xffb81020;
  513. else
  514. data = 0xffb80d20;
  515. ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
  516. }
  517. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  518. u32 usec_reg;
  519. /* 5311 has different tx/rx latency masks
  520. * from 5211, since we deal 5311 the same
  521. * as 5211 when setting initvals, shift
  522. * values here to their proper locations */
  523. usec_reg = ath5k_hw_reg_read(ah, AR5K_USEC_5211);
  524. ath5k_hw_reg_write(ah, usec_reg & (AR5K_USEC_1 |
  525. AR5K_USEC_32 |
  526. AR5K_USEC_TX_LATENCY_5211 |
  527. AR5K_REG_SM(29,
  528. AR5K_USEC_RX_LATENCY_5210)),
  529. AR5K_USEC_5211);
  530. /* Clear QCU/DCU clock gating register */
  531. ath5k_hw_reg_write(ah, 0, AR5K_QCUDCU_CLKGT);
  532. /* Set DAC/ADC delays */
  533. ath5k_hw_reg_write(ah, 0x08, AR5K_PHY_SCAL);
  534. /* Enable PCU FIFO corruption ECO */
  535. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
  536. AR5K_DIAG_SW_ECO_ENABLE);
  537. }
  538. }
  539. static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
  540. struct ieee80211_channel *channel, u8 *ant, u8 ee_mode)
  541. {
  542. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  543. s16 cck_ofdm_pwr_delta;
  544. /* Adjust power delta for channel 14 */
  545. if (channel->center_freq == 2484)
  546. cck_ofdm_pwr_delta =
  547. ((ee->ee_cck_ofdm_power_delta -
  548. ee->ee_scaled_cck_delta) * 2) / 10;
  549. else
  550. cck_ofdm_pwr_delta =
  551. (ee->ee_cck_ofdm_power_delta * 2) / 10;
  552. /* Set CCK to OFDM power delta on tx power
  553. * adjustment register */
  554. if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
  555. if (channel->hw_value == CHANNEL_G)
  556. ath5k_hw_reg_write(ah,
  557. AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1),
  558. AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) |
  559. AR5K_REG_SM((cck_ofdm_pwr_delta * -1),
  560. AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX),
  561. AR5K_PHY_TX_PWR_ADJ);
  562. else
  563. ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ);
  564. } else {
  565. /* For older revs we scale power on sw during tx power
  566. * setup */
  567. ah->ah_txpower.txp_cck_ofdm_pwr_delta = cck_ofdm_pwr_delta;
  568. ah->ah_txpower.txp_cck_ofdm_gainf_delta =
  569. ee->ee_cck_ofdm_gain_delta;
  570. }
  571. /* Set antenna idle switch table */
  572. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_ANT_CTL,
  573. AR5K_PHY_ANT_CTL_SWTABLE_IDLE,
  574. (ah->ah_ant_ctl[ee_mode][0] |
  575. AR5K_PHY_ANT_CTL_TXRX_EN));
  576. /* Set antenna switch tables */
  577. ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[0]],
  578. AR5K_PHY_ANT_SWITCH_TABLE_0);
  579. ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[1]],
  580. AR5K_PHY_ANT_SWITCH_TABLE_1);
  581. /* Noise floor threshold */
  582. ath5k_hw_reg_write(ah,
  583. AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
  584. AR5K_PHY_NFTHRES);
  585. if ((channel->hw_value & CHANNEL_TURBO) &&
  586. (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0)) {
  587. /* Switch settling time (Turbo) */
  588. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  589. AR5K_PHY_SETTLING_SWITCH,
  590. ee->ee_switch_settling_turbo[ee_mode]);
  591. /* Tx/Rx attenuation (Turbo) */
  592. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
  593. AR5K_PHY_GAIN_TXRX_ATTEN,
  594. ee->ee_atn_tx_rx_turbo[ee_mode]);
  595. /* ADC/PGA desired size (Turbo) */
  596. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  597. AR5K_PHY_DESIRED_SIZE_ADC,
  598. ee->ee_adc_desired_size_turbo[ee_mode]);
  599. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  600. AR5K_PHY_DESIRED_SIZE_PGA,
  601. ee->ee_pga_desired_size_turbo[ee_mode]);
  602. /* Tx/Rx margin (Turbo) */
  603. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  604. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  605. ee->ee_margin_tx_rx_turbo[ee_mode]);
  606. } else {
  607. /* Switch settling time */
  608. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  609. AR5K_PHY_SETTLING_SWITCH,
  610. ee->ee_switch_settling[ee_mode]);
  611. /* Tx/Rx attenuation */
  612. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
  613. AR5K_PHY_GAIN_TXRX_ATTEN,
  614. ee->ee_atn_tx_rx[ee_mode]);
  615. /* ADC/PGA desired size */
  616. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  617. AR5K_PHY_DESIRED_SIZE_ADC,
  618. ee->ee_adc_desired_size[ee_mode]);
  619. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  620. AR5K_PHY_DESIRED_SIZE_PGA,
  621. ee->ee_pga_desired_size[ee_mode]);
  622. /* Tx/Rx margin */
  623. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  624. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  625. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  626. ee->ee_margin_tx_rx[ee_mode]);
  627. }
  628. /* XPA delays */
  629. ath5k_hw_reg_write(ah,
  630. (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
  631. (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
  632. (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
  633. (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
  634. /* XLNA delay */
  635. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RF_CTL3,
  636. AR5K_PHY_RF_CTL3_TXE2XLNA_ON,
  637. ee->ee_tx_end2xlna_enable[ee_mode]);
  638. /* Thresh64 (ANI) */
  639. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_NF,
  640. AR5K_PHY_NF_THRESH62,
  641. ee->ee_thr_62[ee_mode]);
  642. /* False detect backoff for channels
  643. * that have spur noise. Write the new
  644. * cyclic power RSSI threshold. */
  645. if (ath5k_hw_chan_has_spur_noise(ah, channel))
  646. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
  647. AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
  648. AR5K_INIT_CYCRSSI_THR1 +
  649. ee->ee_false_detect[ee_mode]);
  650. else
  651. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
  652. AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
  653. AR5K_INIT_CYCRSSI_THR1);
  654. /* I/Q correction
  655. * TODO: Per channel i/q infos ? */
  656. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  657. AR5K_PHY_IQ_CORR_ENABLE |
  658. (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
  659. ee->ee_q_cal[ee_mode]);
  660. /* Heavy clipping -disable for now */
  661. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_1)
  662. ath5k_hw_reg_write(ah, 0, AR5K_PHY_HEAVY_CLIP_ENABLE);
  663. return;
  664. }
  665. /*
  666. * Main reset function
  667. */
  668. int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
  669. struct ieee80211_channel *channel, bool change_channel)
  670. {
  671. u32 s_seq[10], s_ant, s_led[3], staid1_flags, tsf_up, tsf_lo;
  672. u32 phy_tst1;
  673. u8 mode, freq, ee_mode, ant[2];
  674. int i, ret;
  675. ATH5K_TRACE(ah->ah_sc);
  676. s_ant = 0;
  677. ee_mode = 0;
  678. staid1_flags = 0;
  679. tsf_up = 0;
  680. tsf_lo = 0;
  681. freq = 0;
  682. mode = 0;
  683. /*
  684. * Save some registers before a reset
  685. */
  686. /*DCU/Antenna selection not available on 5210*/
  687. if (ah->ah_version != AR5K_AR5210) {
  688. switch (channel->hw_value & CHANNEL_MODES) {
  689. case CHANNEL_A:
  690. mode = AR5K_MODE_11A;
  691. freq = AR5K_INI_RFGAIN_5GHZ;
  692. ee_mode = AR5K_EEPROM_MODE_11A;
  693. break;
  694. case CHANNEL_G:
  695. mode = AR5K_MODE_11G;
  696. freq = AR5K_INI_RFGAIN_2GHZ;
  697. ee_mode = AR5K_EEPROM_MODE_11G;
  698. break;
  699. case CHANNEL_B:
  700. mode = AR5K_MODE_11B;
  701. freq = AR5K_INI_RFGAIN_2GHZ;
  702. ee_mode = AR5K_EEPROM_MODE_11B;
  703. break;
  704. case CHANNEL_T:
  705. mode = AR5K_MODE_11A_TURBO;
  706. freq = AR5K_INI_RFGAIN_5GHZ;
  707. ee_mode = AR5K_EEPROM_MODE_11A;
  708. break;
  709. case CHANNEL_TG:
  710. if (ah->ah_version == AR5K_AR5211) {
  711. ATH5K_ERR(ah->ah_sc,
  712. "TurboG mode not available on 5211");
  713. return -EINVAL;
  714. }
  715. mode = AR5K_MODE_11G_TURBO;
  716. freq = AR5K_INI_RFGAIN_2GHZ;
  717. ee_mode = AR5K_EEPROM_MODE_11G;
  718. break;
  719. case CHANNEL_XR:
  720. if (ah->ah_version == AR5K_AR5211) {
  721. ATH5K_ERR(ah->ah_sc,
  722. "XR mode not available on 5211");
  723. return -EINVAL;
  724. }
  725. mode = AR5K_MODE_XR;
  726. freq = AR5K_INI_RFGAIN_5GHZ;
  727. ee_mode = AR5K_EEPROM_MODE_11A;
  728. break;
  729. default:
  730. ATH5K_ERR(ah->ah_sc,
  731. "invalid channel: %d\n", channel->center_freq);
  732. return -EINVAL;
  733. }
  734. if (change_channel) {
  735. /*
  736. * Save frame sequence count
  737. * For revs. after Oahu, only save
  738. * seq num for DCU 0 (Global seq num)
  739. */
  740. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  741. for (i = 0; i < 10; i++)
  742. s_seq[i] = ath5k_hw_reg_read(ah,
  743. AR5K_QUEUE_DCU_SEQNUM(i));
  744. } else {
  745. s_seq[0] = ath5k_hw_reg_read(ah,
  746. AR5K_QUEUE_DCU_SEQNUM(0));
  747. }
  748. /* TSF accelerates on AR5211 durring reset
  749. * As a workaround save it here and restore
  750. * it later so that it's back in time after
  751. * reset. This way it'll get re-synced on the
  752. * next beacon without breaking ad-hoc.
  753. *
  754. * On AR5212 TSF is almost preserved across a
  755. * reset so it stays back in time anyway and
  756. * we don't have to save/restore it.
  757. *
  758. * XXX: Since this breaks power saving we have
  759. * to disable power saving until we receive the
  760. * next beacon, so we can resync beacon timers */
  761. if (ah->ah_version == AR5K_AR5211) {
  762. tsf_up = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
  763. tsf_lo = ath5k_hw_reg_read(ah, AR5K_TSF_L32);
  764. }
  765. }
  766. /* Save default antenna */
  767. s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
  768. if (ah->ah_version == AR5K_AR5212) {
  769. /* Restore normal 32/40MHz clock operation
  770. * to avoid register access delay on certain
  771. * PHY registers */
  772. ath5k_hw_set_sleep_clock(ah, false);
  773. /* Since we are going to write rf buffer
  774. * check if we have any pending gain_F
  775. * optimization settings */
  776. if (change_channel && ah->ah_rf_banks != NULL)
  777. ath5k_hw_gainf_calibrate(ah);
  778. }
  779. }
  780. /*GPIOs*/
  781. s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  782. AR5K_PCICFG_LEDSTATE;
  783. s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
  784. s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  785. /* AR5K_STA_ID1 flags, only preserve antenna
  786. * settings and ack/cts rate mode */
  787. staid1_flags = ath5k_hw_reg_read(ah, AR5K_STA_ID1) &
  788. (AR5K_STA_ID1_DEFAULT_ANTENNA |
  789. AR5K_STA_ID1_DESC_ANTENNA |
  790. AR5K_STA_ID1_RTS_DEF_ANTENNA |
  791. AR5K_STA_ID1_ACKCTS_6MB |
  792. AR5K_STA_ID1_BASE_RATE_11B |
  793. AR5K_STA_ID1_SELFGEN_DEF_ANT);
  794. /* Wakeup the device */
  795. ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
  796. if (ret)
  797. return ret;
  798. /*
  799. * Initialize operating mode
  800. */
  801. ah->ah_op_mode = op_mode;
  802. /* PHY access enable */
  803. if (ah->ah_mac_srev >= AR5K_SREV_AR5211)
  804. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
  805. else
  806. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ | 0x40,
  807. AR5K_PHY(0));
  808. /* Write initial settings */
  809. ret = ath5k_hw_write_initvals(ah, mode, change_channel);
  810. if (ret)
  811. return ret;
  812. /*
  813. * 5211/5212 Specific
  814. */
  815. if (ah->ah_version != AR5K_AR5210) {
  816. /*
  817. * Write initial RF gain settings
  818. * This should work for both 5111/5112
  819. */
  820. ret = ath5k_hw_rfgain_init(ah, freq);
  821. if (ret)
  822. return ret;
  823. mdelay(1);
  824. /*
  825. * Tweak initval settings for revised
  826. * chipsets and add some more config
  827. * bits
  828. */
  829. ath5k_hw_tweak_initval_settings(ah, channel);
  830. /*
  831. * Set TX power
  832. */
  833. ret = ath5k_hw_txpower(ah, channel, ee_mode,
  834. ah->ah_txpower.txp_max_pwr / 2);
  835. if (ret)
  836. return ret;
  837. /* Write rate duration table only on AR5212 and if
  838. * virtual interface has already been brought up
  839. * XXX: rethink this after new mode changes to
  840. * mac80211 are integrated */
  841. if (ah->ah_version == AR5K_AR5212 &&
  842. ah->ah_sc->vif != NULL)
  843. ath5k_hw_write_rate_duration(ah, mode);
  844. /*
  845. * Write RF buffer
  846. */
  847. ret = ath5k_hw_rfregs_init(ah, channel, mode);
  848. if (ret)
  849. return ret;
  850. /* Write OFDM timings on 5212*/
  851. if (ah->ah_version == AR5K_AR5212 &&
  852. channel->hw_value & CHANNEL_OFDM) {
  853. struct ath5k_eeprom_info *ee =
  854. &ah->ah_capabilities.cap_eeprom;
  855. ret = ath5k_hw_write_ofdm_timings(ah, channel);
  856. if (ret)
  857. return ret;
  858. /* Note: According to docs we can have a newer
  859. * EEPROM on old hardware, so we need to verify
  860. * that our hardware is new enough to have spur
  861. * mitigation registers (delta phase etc) */
  862. if (ah->ah_mac_srev >= AR5K_SREV_AR5424 ||
  863. (ah->ah_mac_srev >= AR5K_SREV_AR5424 &&
  864. ee->ee_version >= AR5K_EEPROM_VERSION_5_3))
  865. ath5k_hw_set_spur_mitigation_filter(ah,
  866. channel);
  867. }
  868. /*Enable/disable 802.11b mode on 5111
  869. (enable 2111 frequency converter + CCK)*/
  870. if (ah->ah_radio == AR5K_RF5111) {
  871. if (mode == AR5K_MODE_11B)
  872. AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
  873. AR5K_TXCFG_B_MODE);
  874. else
  875. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  876. AR5K_TXCFG_B_MODE);
  877. }
  878. /*
  879. * In case a fixed antenna was set as default
  880. * use the same switch table twice.
  881. */
  882. if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_A)
  883. ant[0] = ant[1] = AR5K_ANT_SWTABLE_A;
  884. else if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_B)
  885. ant[0] = ant[1] = AR5K_ANT_SWTABLE_B;
  886. else {
  887. ant[0] = AR5K_ANT_SWTABLE_A;
  888. ant[1] = AR5K_ANT_SWTABLE_B;
  889. }
  890. /* Commit values from EEPROM */
  891. ath5k_hw_commit_eeprom_settings(ah, channel, ant, ee_mode);
  892. } else {
  893. /*
  894. * For 5210 we do all initialization using
  895. * initvals, so we don't have to modify
  896. * any settings (5210 also only supports
  897. * a/aturbo modes)
  898. */
  899. mdelay(1);
  900. /* Disable phy and wait */
  901. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
  902. mdelay(1);
  903. }
  904. /*
  905. * Restore saved values
  906. */
  907. /*DCU/Antenna selection not available on 5210*/
  908. if (ah->ah_version != AR5K_AR5210) {
  909. if (change_channel) {
  910. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  911. for (i = 0; i < 10; i++)
  912. ath5k_hw_reg_write(ah, s_seq[i],
  913. AR5K_QUEUE_DCU_SEQNUM(i));
  914. } else {
  915. ath5k_hw_reg_write(ah, s_seq[0],
  916. AR5K_QUEUE_DCU_SEQNUM(0));
  917. }
  918. if (ah->ah_version == AR5K_AR5211) {
  919. ath5k_hw_reg_write(ah, tsf_up, AR5K_TSF_U32);
  920. ath5k_hw_reg_write(ah, tsf_lo, AR5K_TSF_L32);
  921. }
  922. }
  923. ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
  924. }
  925. /* Ledstate */
  926. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
  927. /* Gpio settings */
  928. ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
  929. ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
  930. /* Restore sta_id flags and preserve our mac address*/
  931. ath5k_hw_reg_write(ah, AR5K_LOW_ID(ah->ah_sta_id),
  932. AR5K_STA_ID0);
  933. ath5k_hw_reg_write(ah, staid1_flags | AR5K_HIGH_ID(ah->ah_sta_id),
  934. AR5K_STA_ID1);
  935. /*
  936. * Configure PCU
  937. */
  938. /* Restore bssid and bssid mask */
  939. /* XXX: add ah->aid once mac80211 gives this to us */
  940. ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
  941. /* Set PCU config */
  942. ath5k_hw_set_opmode(ah);
  943. /* Clear any pending interrupts
  944. * PISR/SISR Not available on 5210 */
  945. if (ah->ah_version != AR5K_AR5210)
  946. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
  947. /* Set RSSI/BRSSI thresholds
  948. *
  949. * Note: If we decide to set this value
  950. * dynamicaly, have in mind that when AR5K_RSSI_THR
  951. * register is read it might return 0x40 if we haven't
  952. * wrote anything to it plus BMISS RSSI threshold is zeroed.
  953. * So doing a save/restore procedure here isn't the right
  954. * choice. Instead store it on ath5k_hw */
  955. ath5k_hw_reg_write(ah, (AR5K_TUNE_RSSI_THRES |
  956. AR5K_TUNE_BMISS_THRES <<
  957. AR5K_RSSI_THR_BMISS_S),
  958. AR5K_RSSI_THR);
  959. /* MIC QoS support */
  960. if (ah->ah_mac_srev >= AR5K_SREV_AR2413) {
  961. ath5k_hw_reg_write(ah, 0x000100aa, AR5K_MIC_QOS_CTL);
  962. ath5k_hw_reg_write(ah, 0x00003210, AR5K_MIC_QOS_SEL);
  963. }
  964. /* QoS NOACK Policy */
  965. if (ah->ah_version == AR5K_AR5212) {
  966. ath5k_hw_reg_write(ah,
  967. AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES) |
  968. AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET) |
  969. AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET),
  970. AR5K_QOS_NOACK);
  971. }
  972. /*
  973. * Configure PHY
  974. */
  975. /* Set channel on PHY */
  976. ret = ath5k_hw_channel(ah, channel);
  977. if (ret)
  978. return ret;
  979. /*
  980. * Enable the PHY and wait until completion
  981. * This includes BaseBand and Synthesizer
  982. * activation.
  983. */
  984. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
  985. /*
  986. * On 5211+ read activation -> rx delay
  987. * and use it.
  988. *
  989. * TODO: Half/quarter rate support
  990. */
  991. if (ah->ah_version != AR5K_AR5210) {
  992. u32 delay;
  993. delay = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
  994. AR5K_PHY_RX_DELAY_M;
  995. delay = (channel->hw_value & CHANNEL_CCK) ?
  996. ((delay << 2) / 22) : (delay / 10);
  997. udelay(100 + (2 * delay));
  998. } else {
  999. mdelay(1);
  1000. }
  1001. /*
  1002. * Perform ADC test to see if baseband is ready
  1003. * Set tx hold and check adc test register
  1004. */
  1005. phy_tst1 = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
  1006. ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
  1007. for (i = 0; i <= 20; i++) {
  1008. if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
  1009. break;
  1010. udelay(200);
  1011. }
  1012. ath5k_hw_reg_write(ah, phy_tst1, AR5K_PHY_TST1);
  1013. /*
  1014. * Start automatic gain control calibration
  1015. *
  1016. * During AGC calibration RX path is re-routed to
  1017. * a power detector so we don't receive anything.
  1018. *
  1019. * This method is used to calibrate some static offsets
  1020. * used together with on-the fly I/Q calibration (the
  1021. * one performed via ath5k_hw_phy_calibrate), that doesn't
  1022. * interrupt rx path.
  1023. *
  1024. * While rx path is re-routed to the power detector we also
  1025. * start a noise floor calibration, to measure the
  1026. * card's noise floor (the noise we measure when we are not
  1027. * transmiting or receiving anything).
  1028. *
  1029. * If we are in a noisy environment AGC calibration may time
  1030. * out and/or noise floor calibration might timeout.
  1031. */
  1032. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
  1033. AR5K_PHY_AGCCTL_CAL);
  1034. /* At the same time start I/Q calibration for QAM constellation
  1035. * -no need for CCK- */
  1036. ah->ah_calibration = false;
  1037. if (!(mode == AR5K_MODE_11B)) {
  1038. ah->ah_calibration = true;
  1039. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
  1040. AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
  1041. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  1042. AR5K_PHY_IQ_RUN);
  1043. }
  1044. /* Wait for gain calibration to finish (we check for I/Q calibration
  1045. * during ath5k_phy_calibrate) */
  1046. if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
  1047. AR5K_PHY_AGCCTL_CAL, 0, false)) {
  1048. ATH5K_ERR(ah->ah_sc, "gain calibration timeout (%uMHz)\n",
  1049. channel->center_freq);
  1050. }
  1051. /*
  1052. * If we run NF calibration before AGC, it always times out.
  1053. * Binary HAL starts NF and AGC calibration at the same time
  1054. * and only waits for AGC to finish. Also if AGC or NF cal.
  1055. * times out, reset doesn't fail on binary HAL. I believe
  1056. * that's wrong because since rx path is routed to a detector,
  1057. * if cal. doesn't finish we won't have RX. Sam's HAL for AR5210/5211
  1058. * enables noise floor calibration after offset calibration and if noise
  1059. * floor calibration fails, reset fails. I believe that's
  1060. * a better approach, we just need to find a polling interval
  1061. * that suits best, even if reset continues we need to make
  1062. * sure that rx path is ready.
  1063. */
  1064. ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
  1065. /* Restore antenna mode */
  1066. ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
  1067. /*
  1068. * Configure QCUs/DCUs
  1069. */
  1070. /* TODO: HW Compression support for data queues */
  1071. /* TODO: Burst prefetch for data queues */
  1072. /*
  1073. * Reset queues and start beacon timers at the end of the reset routine
  1074. * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
  1075. * Note: If we want we can assign multiple qcus on one dcu.
  1076. */
  1077. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
  1078. ret = ath5k_hw_reset_tx_queue(ah, i);
  1079. if (ret) {
  1080. ATH5K_ERR(ah->ah_sc,
  1081. "failed to reset TX queue #%d\n", i);
  1082. return ret;
  1083. }
  1084. }
  1085. /*
  1086. * Configure DMA/Interrupts
  1087. */
  1088. /*
  1089. * Set Rx/Tx DMA Configuration
  1090. *
  1091. * Set standard DMA size (128). Note that
  1092. * a DMA size of 512 causes rx overruns and tx errors
  1093. * on pci-e cards (tested on 5424 but since rx overruns
  1094. * also occur on 5416/5418 with madwifi we set 128
  1095. * for all PCI-E cards to be safe).
  1096. *
  1097. * XXX: need to check 5210 for this
  1098. * TODO: Check out tx triger level, it's always 64 on dumps but I
  1099. * guess we can tweak it and see how it goes ;-)
  1100. */
  1101. if (ah->ah_version != AR5K_AR5210) {
  1102. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  1103. AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
  1104. AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
  1105. AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
  1106. }
  1107. /* Pre-enable interrupts on 5211/5212*/
  1108. if (ah->ah_version != AR5K_AR5210)
  1109. ath5k_hw_set_imr(ah, ah->ah_imr);
  1110. /* Enable 32KHz clock function for AR5212+ chips
  1111. * Set clocks to 32KHz operation and use an
  1112. * external 32KHz crystal when sleeping if one
  1113. * exists */
  1114. if (ah->ah_version == AR5K_AR5212)
  1115. ath5k_hw_set_sleep_clock(ah, true);
  1116. /*
  1117. * Disable beacons and reset the register
  1118. */
  1119. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
  1120. AR5K_BEACON_RESET_TSF);
  1121. return 0;
  1122. }
  1123. #undef _ATH5K_RESET