reset.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  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. ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
  243. return 0;
  244. }
  245. /*
  246. * Bring up MAC + PHY Chips and program PLL
  247. * TODO: Half/Quarter rate support
  248. */
  249. int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
  250. {
  251. struct pci_dev *pdev = ah->ah_sc->pdev;
  252. u32 turbo, mode, clock, bus_flags;
  253. int ret;
  254. turbo = 0;
  255. mode = 0;
  256. clock = 0;
  257. ATH5K_TRACE(ah->ah_sc);
  258. /* Wakeup the device */
  259. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  260. if (ret) {
  261. ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
  262. return ret;
  263. }
  264. if (ah->ah_version != AR5K_AR5210) {
  265. /*
  266. * Get channel mode flags
  267. */
  268. if (ah->ah_radio >= AR5K_RF5112) {
  269. mode = AR5K_PHY_MODE_RAD_RF5112;
  270. clock = AR5K_PHY_PLL_RF5112;
  271. } else {
  272. mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
  273. clock = AR5K_PHY_PLL_RF5111; /*Zero*/
  274. }
  275. if (flags & CHANNEL_2GHZ) {
  276. mode |= AR5K_PHY_MODE_FREQ_2GHZ;
  277. clock |= AR5K_PHY_PLL_44MHZ;
  278. if (flags & CHANNEL_CCK) {
  279. mode |= AR5K_PHY_MODE_MOD_CCK;
  280. } else if (flags & CHANNEL_OFDM) {
  281. /* XXX Dynamic OFDM/CCK is not supported by the
  282. * AR5211 so we set MOD_OFDM for plain g (no
  283. * CCK headers) operation. We need to test
  284. * this, 5211 might support ofdm-only g after
  285. * all, there are also initial register values
  286. * in the code for g mode (see initvals.c). */
  287. if (ah->ah_version == AR5K_AR5211)
  288. mode |= AR5K_PHY_MODE_MOD_OFDM;
  289. else
  290. mode |= AR5K_PHY_MODE_MOD_DYN;
  291. } else {
  292. ATH5K_ERR(ah->ah_sc,
  293. "invalid radio modulation mode\n");
  294. return -EINVAL;
  295. }
  296. } else if (flags & CHANNEL_5GHZ) {
  297. mode |= AR5K_PHY_MODE_FREQ_5GHZ;
  298. if (ah->ah_radio == AR5K_RF5413)
  299. clock = AR5K_PHY_PLL_40MHZ_5413;
  300. else
  301. clock |= AR5K_PHY_PLL_40MHZ;
  302. if (flags & CHANNEL_OFDM)
  303. mode |= AR5K_PHY_MODE_MOD_OFDM;
  304. else {
  305. ATH5K_ERR(ah->ah_sc,
  306. "invalid radio modulation mode\n");
  307. return -EINVAL;
  308. }
  309. } else {
  310. ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
  311. return -EINVAL;
  312. }
  313. if (flags & CHANNEL_TURBO)
  314. turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
  315. } else { /* Reset the device */
  316. /* ...enable Atheros turbo mode if requested */
  317. if (flags & CHANNEL_TURBO)
  318. ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
  319. AR5K_PHY_TURBO);
  320. }
  321. /* reseting PCI on PCI-E cards results card to hang
  322. * and always return 0xffff... so we ingore that flag
  323. * for PCI-E cards */
  324. bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
  325. /* Reset chipset */
  326. if (ah->ah_version == AR5K_AR5210) {
  327. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  328. AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
  329. AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
  330. mdelay(2);
  331. } else {
  332. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  333. AR5K_RESET_CTL_BASEBAND | bus_flags);
  334. }
  335. if (ret) {
  336. ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
  337. return -EIO;
  338. }
  339. /* ...wakeup again!*/
  340. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  341. if (ret) {
  342. ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
  343. return ret;
  344. }
  345. /* ...final warm reset */
  346. if (ath5k_hw_nic_reset(ah, 0)) {
  347. ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
  348. return -EIO;
  349. }
  350. if (ah->ah_version != AR5K_AR5210) {
  351. /* ...update PLL if needed */
  352. if (ath5k_hw_reg_read(ah, AR5K_PHY_PLL) != clock) {
  353. ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
  354. udelay(300);
  355. }
  356. /* ...set the PHY operating mode */
  357. ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
  358. ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
  359. }
  360. return 0;
  361. }
  362. /*
  363. * If there is an external 32KHz crystal available, use it
  364. * as ref. clock instead of 32/40MHz clock and baseband clocks
  365. * to save power during sleep or restore normal 32/40MHz
  366. * operation.
  367. *
  368. * XXX: When operating on 32KHz certain PHY registers (27 - 31,
  369. * 123 - 127) require delay on access.
  370. */
  371. static void ath5k_hw_set_sleep_clock(struct ath5k_hw *ah, bool enable)
  372. {
  373. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  374. u32 scal, spending, usec32;
  375. /* Only set 32KHz settings if we have an external
  376. * 32KHz crystal present */
  377. if ((AR5K_EEPROM_HAS32KHZCRYSTAL(ee->ee_misc1) ||
  378. AR5K_EEPROM_HAS32KHZCRYSTAL_OLD(ee->ee_misc1)) &&
  379. enable) {
  380. /* 1 usec/cycle */
  381. AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, 1);
  382. /* Set up tsf increment on each cycle */
  383. AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 61);
  384. /* Set baseband sleep control registers
  385. * and sleep control rate */
  386. ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
  387. if ((ah->ah_radio == AR5K_RF5112) ||
  388. (ah->ah_radio == AR5K_RF5413) ||
  389. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
  390. spending = 0x14;
  391. else
  392. spending = 0x18;
  393. ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
  394. if ((ah->ah_radio == AR5K_RF5112) ||
  395. (ah->ah_radio == AR5K_RF5413) ||
  396. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
  397. ath5k_hw_reg_write(ah, 0x26, AR5K_PHY_SLMT);
  398. ath5k_hw_reg_write(ah, 0x0d, AR5K_PHY_SCAL);
  399. ath5k_hw_reg_write(ah, 0x07, AR5K_PHY_SCLOCK);
  400. ath5k_hw_reg_write(ah, 0x3f, AR5K_PHY_SDELAY);
  401. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  402. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x02);
  403. } else {
  404. ath5k_hw_reg_write(ah, 0x0a, AR5K_PHY_SLMT);
  405. ath5k_hw_reg_write(ah, 0x0c, AR5K_PHY_SCAL);
  406. ath5k_hw_reg_write(ah, 0x03, AR5K_PHY_SCLOCK);
  407. ath5k_hw_reg_write(ah, 0x20, AR5K_PHY_SDELAY);
  408. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  409. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x03);
  410. }
  411. /* Enable sleep clock operation */
  412. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG,
  413. AR5K_PCICFG_SLEEP_CLOCK_EN);
  414. } else {
  415. /* Disable sleep clock operation and
  416. * restore default parameters */
  417. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
  418. AR5K_PCICFG_SLEEP_CLOCK_EN);
  419. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  420. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0);
  421. ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
  422. ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
  423. if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
  424. scal = AR5K_PHY_SCAL_32MHZ_2417;
  425. else if (ee->ee_is_hb63)
  426. scal = AR5K_PHY_SCAL_32MHZ_HB63;
  427. else
  428. scal = AR5K_PHY_SCAL_32MHZ;
  429. ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
  430. ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
  431. ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
  432. if ((ah->ah_radio == AR5K_RF5112) ||
  433. (ah->ah_radio == AR5K_RF5413) ||
  434. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
  435. spending = 0x14;
  436. else
  437. spending = 0x18;
  438. ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
  439. if ((ah->ah_radio == AR5K_RF5112) ||
  440. (ah->ah_radio == AR5K_RF5413))
  441. usec32 = 39;
  442. else
  443. usec32 = 31;
  444. AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, usec32);
  445. AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 1);
  446. }
  447. return;
  448. }
  449. /* TODO: Half/Quarter rate */
  450. static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
  451. struct ieee80211_channel *channel)
  452. {
  453. if (ah->ah_version == AR5K_AR5212 &&
  454. ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
  455. /* Setup ADC control */
  456. ath5k_hw_reg_write(ah,
  457. (AR5K_REG_SM(2,
  458. AR5K_PHY_ADC_CTL_INBUFGAIN_OFF) |
  459. AR5K_REG_SM(2,
  460. AR5K_PHY_ADC_CTL_INBUFGAIN_ON) |
  461. AR5K_PHY_ADC_CTL_PWD_DAC_OFF |
  462. AR5K_PHY_ADC_CTL_PWD_ADC_OFF),
  463. AR5K_PHY_ADC_CTL);
  464. /* Disable barker RSSI threshold */
  465. AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
  466. AR5K_PHY_DAG_CCK_CTL_EN_RSSI_THR);
  467. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
  468. AR5K_PHY_DAG_CCK_CTL_RSSI_THR, 2);
  469. /* Set the mute mask */
  470. ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
  471. }
  472. /* Clear PHY_BLUETOOTH to allow RX_CLEAR line debug */
  473. if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212B)
  474. ath5k_hw_reg_write(ah, 0, AR5K_PHY_BLUETOOTH);
  475. /* Enable DCU double buffering */
  476. if (ah->ah_phy_revision > AR5K_SREV_PHY_5212B)
  477. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  478. AR5K_TXCFG_DCU_DBL_BUF_DIS);
  479. /* Set DAC/ADC delays */
  480. if (ah->ah_version == AR5K_AR5212) {
  481. u32 scal;
  482. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  483. if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
  484. scal = AR5K_PHY_SCAL_32MHZ_2417;
  485. else if (ee->ee_is_hb63)
  486. scal = AR5K_PHY_SCAL_32MHZ_HB63;
  487. else
  488. scal = AR5K_PHY_SCAL_32MHZ;
  489. ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
  490. }
  491. /* Set fast ADC */
  492. if ((ah->ah_radio == AR5K_RF5413) ||
  493. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
  494. u32 fast_adc = true;
  495. if (channel->center_freq == 2462 ||
  496. channel->center_freq == 2467)
  497. fast_adc = 0;
  498. /* Only update if needed */
  499. if (ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ADC) != fast_adc)
  500. ath5k_hw_reg_write(ah, fast_adc,
  501. AR5K_PHY_FAST_ADC);
  502. }
  503. /* Fix for first revision of the RF5112 RF chipset */
  504. if (ah->ah_radio == AR5K_RF5112 &&
  505. ah->ah_radio_5ghz_revision <
  506. AR5K_SREV_RAD_5112A) {
  507. u32 data;
  508. ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
  509. AR5K_PHY_CCKTXCTL);
  510. if (channel->hw_value & CHANNEL_5GHZ)
  511. data = 0xffb81020;
  512. else
  513. data = 0xffb80d20;
  514. ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
  515. }
  516. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  517. u32 usec_reg;
  518. /* 5311 has different tx/rx latency masks
  519. * from 5211, since we deal 5311 the same
  520. * as 5211 when setting initvals, shift
  521. * values here to their proper locations */
  522. usec_reg = ath5k_hw_reg_read(ah, AR5K_USEC_5211);
  523. ath5k_hw_reg_write(ah, usec_reg & (AR5K_USEC_1 |
  524. AR5K_USEC_32 |
  525. AR5K_USEC_TX_LATENCY_5211 |
  526. AR5K_REG_SM(29,
  527. AR5K_USEC_RX_LATENCY_5210)),
  528. AR5K_USEC_5211);
  529. /* Clear QCU/DCU clock gating register */
  530. ath5k_hw_reg_write(ah, 0, AR5K_QCUDCU_CLKGT);
  531. /* Set DAC/ADC delays */
  532. ath5k_hw_reg_write(ah, 0x08, AR5K_PHY_SCAL);
  533. /* Enable PCU FIFO corruption ECO */
  534. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
  535. AR5K_DIAG_SW_ECO_ENABLE);
  536. }
  537. }
  538. static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
  539. struct ieee80211_channel *channel, u8 *ant, u8 ee_mode)
  540. {
  541. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  542. s16 cck_ofdm_pwr_delta;
  543. /* Adjust power delta for channel 14 */
  544. if (channel->center_freq == 2484)
  545. cck_ofdm_pwr_delta =
  546. ((ee->ee_cck_ofdm_power_delta -
  547. ee->ee_scaled_cck_delta) * 2) / 10;
  548. else
  549. cck_ofdm_pwr_delta =
  550. (ee->ee_cck_ofdm_power_delta * 2) / 10;
  551. /* Set CCK to OFDM power delta on tx power
  552. * adjustment register */
  553. if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
  554. if (channel->hw_value == CHANNEL_G)
  555. ath5k_hw_reg_write(ah,
  556. AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1),
  557. AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) |
  558. AR5K_REG_SM((cck_ofdm_pwr_delta * -1),
  559. AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX),
  560. AR5K_PHY_TX_PWR_ADJ);
  561. else
  562. ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ);
  563. } else {
  564. /* For older revs we scale power on sw during tx power
  565. * setup */
  566. ah->ah_txpower.txp_cck_ofdm_pwr_delta = cck_ofdm_pwr_delta;
  567. ah->ah_txpower.txp_cck_ofdm_gainf_delta =
  568. ee->ee_cck_ofdm_gain_delta;
  569. }
  570. /* Set antenna idle switch table */
  571. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_ANT_CTL,
  572. AR5K_PHY_ANT_CTL_SWTABLE_IDLE,
  573. (ah->ah_ant_ctl[ee_mode][0] |
  574. AR5K_PHY_ANT_CTL_TXRX_EN));
  575. /* Set antenna switch tables */
  576. ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[0]],
  577. AR5K_PHY_ANT_SWITCH_TABLE_0);
  578. ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[1]],
  579. AR5K_PHY_ANT_SWITCH_TABLE_1);
  580. /* Noise floor threshold */
  581. ath5k_hw_reg_write(ah,
  582. AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
  583. AR5K_PHY_NFTHRES);
  584. if ((channel->hw_value & CHANNEL_TURBO) &&
  585. (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0)) {
  586. /* Switch settling time (Turbo) */
  587. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  588. AR5K_PHY_SETTLING_SWITCH,
  589. ee->ee_switch_settling_turbo[ee_mode]);
  590. /* Tx/Rx attenuation (Turbo) */
  591. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
  592. AR5K_PHY_GAIN_TXRX_ATTEN,
  593. ee->ee_atn_tx_rx_turbo[ee_mode]);
  594. /* ADC/PGA desired size (Turbo) */
  595. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  596. AR5K_PHY_DESIRED_SIZE_ADC,
  597. ee->ee_adc_desired_size_turbo[ee_mode]);
  598. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  599. AR5K_PHY_DESIRED_SIZE_PGA,
  600. ee->ee_pga_desired_size_turbo[ee_mode]);
  601. /* Tx/Rx margin (Turbo) */
  602. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  603. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  604. ee->ee_margin_tx_rx_turbo[ee_mode]);
  605. } else {
  606. /* Switch settling time */
  607. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  608. AR5K_PHY_SETTLING_SWITCH,
  609. ee->ee_switch_settling[ee_mode]);
  610. /* Tx/Rx attenuation */
  611. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
  612. AR5K_PHY_GAIN_TXRX_ATTEN,
  613. ee->ee_atn_tx_rx[ee_mode]);
  614. /* ADC/PGA desired size */
  615. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  616. AR5K_PHY_DESIRED_SIZE_ADC,
  617. ee->ee_adc_desired_size[ee_mode]);
  618. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  619. AR5K_PHY_DESIRED_SIZE_PGA,
  620. ee->ee_pga_desired_size[ee_mode]);
  621. /* Tx/Rx margin */
  622. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  623. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  624. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  625. ee->ee_margin_tx_rx[ee_mode]);
  626. }
  627. /* XPA delays */
  628. ath5k_hw_reg_write(ah,
  629. (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
  630. (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
  631. (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
  632. (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
  633. /* XLNA delay */
  634. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RF_CTL3,
  635. AR5K_PHY_RF_CTL3_TXE2XLNA_ON,
  636. ee->ee_tx_end2xlna_enable[ee_mode]);
  637. /* Thresh64 (ANI) */
  638. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_NF,
  639. AR5K_PHY_NF_THRESH62,
  640. ee->ee_thr_62[ee_mode]);
  641. /* False detect backoff for channels
  642. * that have spur noise. Write the new
  643. * cyclic power RSSI threshold. */
  644. if (ath5k_hw_chan_has_spur_noise(ah, channel))
  645. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
  646. AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
  647. AR5K_INIT_CYCRSSI_THR1 +
  648. ee->ee_false_detect[ee_mode]);
  649. else
  650. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
  651. AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
  652. AR5K_INIT_CYCRSSI_THR1);
  653. /* I/Q correction
  654. * TODO: Per channel i/q infos ? */
  655. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  656. AR5K_PHY_IQ_CORR_ENABLE |
  657. (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
  658. ee->ee_q_cal[ee_mode]);
  659. /* Heavy clipping -disable for now */
  660. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_1)
  661. ath5k_hw_reg_write(ah, 0, AR5K_PHY_HEAVY_CLIP_ENABLE);
  662. return;
  663. }
  664. /*
  665. * Main reset function
  666. */
  667. int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
  668. struct ieee80211_channel *channel, bool change_channel)
  669. {
  670. u32 s_seq[10], s_ant, s_led[3], staid1_flags, tsf_up, tsf_lo;
  671. u32 phy_tst1;
  672. u8 mode, freq, ee_mode, ant[2];
  673. int i, ret;
  674. ATH5K_TRACE(ah->ah_sc);
  675. s_ant = 0;
  676. ee_mode = 0;
  677. staid1_flags = 0;
  678. tsf_up = 0;
  679. tsf_lo = 0;
  680. freq = 0;
  681. mode = 0;
  682. /*
  683. * Save some registers before a reset
  684. */
  685. /*DCU/Antenna selection not available on 5210*/
  686. if (ah->ah_version != AR5K_AR5210) {
  687. switch (channel->hw_value & CHANNEL_MODES) {
  688. case CHANNEL_A:
  689. mode = AR5K_MODE_11A;
  690. freq = AR5K_INI_RFGAIN_5GHZ;
  691. ee_mode = AR5K_EEPROM_MODE_11A;
  692. break;
  693. case CHANNEL_G:
  694. mode = AR5K_MODE_11G;
  695. freq = AR5K_INI_RFGAIN_2GHZ;
  696. ee_mode = AR5K_EEPROM_MODE_11G;
  697. break;
  698. case CHANNEL_B:
  699. mode = AR5K_MODE_11B;
  700. freq = AR5K_INI_RFGAIN_2GHZ;
  701. ee_mode = AR5K_EEPROM_MODE_11B;
  702. break;
  703. case CHANNEL_T:
  704. mode = AR5K_MODE_11A_TURBO;
  705. freq = AR5K_INI_RFGAIN_5GHZ;
  706. ee_mode = AR5K_EEPROM_MODE_11A;
  707. break;
  708. case CHANNEL_TG:
  709. if (ah->ah_version == AR5K_AR5211) {
  710. ATH5K_ERR(ah->ah_sc,
  711. "TurboG mode not available on 5211");
  712. return -EINVAL;
  713. }
  714. mode = AR5K_MODE_11G_TURBO;
  715. freq = AR5K_INI_RFGAIN_2GHZ;
  716. ee_mode = AR5K_EEPROM_MODE_11G;
  717. break;
  718. case CHANNEL_XR:
  719. if (ah->ah_version == AR5K_AR5211) {
  720. ATH5K_ERR(ah->ah_sc,
  721. "XR mode not available on 5211");
  722. return -EINVAL;
  723. }
  724. mode = AR5K_MODE_XR;
  725. freq = AR5K_INI_RFGAIN_5GHZ;
  726. ee_mode = AR5K_EEPROM_MODE_11A;
  727. break;
  728. default:
  729. ATH5K_ERR(ah->ah_sc,
  730. "invalid channel: %d\n", channel->center_freq);
  731. return -EINVAL;
  732. }
  733. if (change_channel) {
  734. /*
  735. * Save frame sequence count
  736. * For revs. after Oahu, only save
  737. * seq num for DCU 0 (Global seq num)
  738. */
  739. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  740. for (i = 0; i < 10; i++)
  741. s_seq[i] = ath5k_hw_reg_read(ah,
  742. AR5K_QUEUE_DCU_SEQNUM(i));
  743. } else {
  744. s_seq[0] = ath5k_hw_reg_read(ah,
  745. AR5K_QUEUE_DCU_SEQNUM(0));
  746. }
  747. /* TSF accelerates on AR5211 durring reset
  748. * As a workaround save it here and restore
  749. * it later so that it's back in time after
  750. * reset. This way it'll get re-synced on the
  751. * next beacon without breaking ad-hoc.
  752. *
  753. * On AR5212 TSF is almost preserved across a
  754. * reset so it stays back in time anyway and
  755. * we don't have to save/restore it.
  756. *
  757. * XXX: Since this breaks power saving we have
  758. * to disable power saving until we receive the
  759. * next beacon, so we can resync beacon timers */
  760. if (ah->ah_version == AR5K_AR5211) {
  761. tsf_up = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
  762. tsf_lo = ath5k_hw_reg_read(ah, AR5K_TSF_L32);
  763. }
  764. }
  765. /* Save default antenna */
  766. s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
  767. if (ah->ah_version == AR5K_AR5212) {
  768. /* Restore normal 32/40MHz clock operation
  769. * to avoid register access delay on certain
  770. * PHY registers */
  771. ath5k_hw_set_sleep_clock(ah, false);
  772. /* Since we are going to write rf buffer
  773. * check if we have any pending gain_F
  774. * optimization settings */
  775. if (change_channel && ah->ah_rf_banks != NULL)
  776. ath5k_hw_gainf_calibrate(ah);
  777. }
  778. }
  779. /*GPIOs*/
  780. s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  781. AR5K_PCICFG_LEDSTATE;
  782. s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
  783. s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  784. /* AR5K_STA_ID1 flags, only preserve antenna
  785. * settings and ack/cts rate mode */
  786. staid1_flags = ath5k_hw_reg_read(ah, AR5K_STA_ID1) &
  787. (AR5K_STA_ID1_DEFAULT_ANTENNA |
  788. AR5K_STA_ID1_DESC_ANTENNA |
  789. AR5K_STA_ID1_RTS_DEF_ANTENNA |
  790. AR5K_STA_ID1_ACKCTS_6MB |
  791. AR5K_STA_ID1_BASE_RATE_11B |
  792. AR5K_STA_ID1_SELFGEN_DEF_ANT);
  793. /* Wakeup the device */
  794. ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
  795. if (ret)
  796. return ret;
  797. /*
  798. * Initialize operating mode
  799. */
  800. ah->ah_op_mode = op_mode;
  801. /* PHY access enable */
  802. if (ah->ah_mac_srev >= AR5K_SREV_AR5211)
  803. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
  804. else
  805. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ | 0x40,
  806. AR5K_PHY(0));
  807. /* Write initial settings */
  808. ret = ath5k_hw_write_initvals(ah, mode, change_channel);
  809. if (ret)
  810. return ret;
  811. /*
  812. * 5211/5212 Specific
  813. */
  814. if (ah->ah_version != AR5K_AR5210) {
  815. /*
  816. * Write initial RF gain settings
  817. * This should work for both 5111/5112
  818. */
  819. ret = ath5k_hw_rfgain_init(ah, freq);
  820. if (ret)
  821. return ret;
  822. mdelay(1);
  823. /*
  824. * Tweak initval settings for revised
  825. * chipsets and add some more config
  826. * bits
  827. */
  828. ath5k_hw_tweak_initval_settings(ah, channel);
  829. /*
  830. * Set TX power
  831. */
  832. ret = ath5k_hw_txpower(ah, channel, ee_mode,
  833. ah->ah_txpower.txp_max_pwr / 2);
  834. if (ret)
  835. return ret;
  836. /* Write rate duration table only on AR5212 and if
  837. * virtual interface has already been brought up
  838. * XXX: rethink this after new mode changes to
  839. * mac80211 are integrated */
  840. if (ah->ah_version == AR5K_AR5212 &&
  841. ah->ah_sc->vif != NULL)
  842. ath5k_hw_write_rate_duration(ah, mode);
  843. /*
  844. * Write RF buffer
  845. */
  846. ret = ath5k_hw_rfregs_init(ah, channel, mode);
  847. if (ret)
  848. return ret;
  849. /* Write OFDM timings on 5212*/
  850. if (ah->ah_version == AR5K_AR5212 &&
  851. channel->hw_value & CHANNEL_OFDM) {
  852. struct ath5k_eeprom_info *ee =
  853. &ah->ah_capabilities.cap_eeprom;
  854. ret = ath5k_hw_write_ofdm_timings(ah, channel);
  855. if (ret)
  856. return ret;
  857. /* Note: According to docs we can have a newer
  858. * EEPROM on old hardware, so we need to verify
  859. * that our hardware is new enough to have spur
  860. * mitigation registers (delta phase etc) */
  861. if (ah->ah_mac_srev >= AR5K_SREV_AR5424 ||
  862. (ah->ah_mac_srev >= AR5K_SREV_AR5424 &&
  863. ee->ee_version >= AR5K_EEPROM_VERSION_5_3))
  864. ath5k_hw_set_spur_mitigation_filter(ah,
  865. channel);
  866. }
  867. /*Enable/disable 802.11b mode on 5111
  868. (enable 2111 frequency converter + CCK)*/
  869. if (ah->ah_radio == AR5K_RF5111) {
  870. if (mode == AR5K_MODE_11B)
  871. AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
  872. AR5K_TXCFG_B_MODE);
  873. else
  874. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  875. AR5K_TXCFG_B_MODE);
  876. }
  877. /*
  878. * In case a fixed antenna was set as default
  879. * use the same switch table twice.
  880. */
  881. if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_A)
  882. ant[0] = ant[1] = AR5K_ANT_SWTABLE_A;
  883. else if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_B)
  884. ant[0] = ant[1] = AR5K_ANT_SWTABLE_B;
  885. else {
  886. ant[0] = AR5K_ANT_SWTABLE_A;
  887. ant[1] = AR5K_ANT_SWTABLE_B;
  888. }
  889. /* Commit values from EEPROM */
  890. ath5k_hw_commit_eeprom_settings(ah, channel, ant, ee_mode);
  891. } else {
  892. /*
  893. * For 5210 we do all initialization using
  894. * initvals, so we don't have to modify
  895. * any settings (5210 also only supports
  896. * a/aturbo modes)
  897. */
  898. mdelay(1);
  899. /* Disable phy and wait */
  900. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
  901. mdelay(1);
  902. }
  903. /*
  904. * Restore saved values
  905. */
  906. /*DCU/Antenna selection not available on 5210*/
  907. if (ah->ah_version != AR5K_AR5210) {
  908. if (change_channel) {
  909. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  910. for (i = 0; i < 10; i++)
  911. ath5k_hw_reg_write(ah, s_seq[i],
  912. AR5K_QUEUE_DCU_SEQNUM(i));
  913. } else {
  914. ath5k_hw_reg_write(ah, s_seq[0],
  915. AR5K_QUEUE_DCU_SEQNUM(0));
  916. }
  917. if (ah->ah_version == AR5K_AR5211) {
  918. ath5k_hw_reg_write(ah, tsf_up, AR5K_TSF_U32);
  919. ath5k_hw_reg_write(ah, tsf_lo, AR5K_TSF_L32);
  920. }
  921. }
  922. ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
  923. }
  924. /* Ledstate */
  925. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
  926. /* Gpio settings */
  927. ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
  928. ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
  929. /* Restore sta_id flags and preserve our mac address*/
  930. ath5k_hw_reg_write(ah, AR5K_LOW_ID(ah->ah_sta_id),
  931. AR5K_STA_ID0);
  932. ath5k_hw_reg_write(ah, staid1_flags | AR5K_HIGH_ID(ah->ah_sta_id),
  933. AR5K_STA_ID1);
  934. /*
  935. * Configure PCU
  936. */
  937. /* Restore bssid and bssid mask */
  938. /* XXX: add ah->aid once mac80211 gives this to us */
  939. ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
  940. /* Set PCU config */
  941. ath5k_hw_set_opmode(ah);
  942. /* Clear any pending interrupts
  943. * PISR/SISR Not available on 5210 */
  944. if (ah->ah_version != AR5K_AR5210)
  945. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
  946. /* Set RSSI/BRSSI thresholds
  947. *
  948. * Note: If we decide to set this value
  949. * dynamicaly, have in mind that when AR5K_RSSI_THR
  950. * register is read it might return 0x40 if we haven't
  951. * wrote anything to it plus BMISS RSSI threshold is zeroed.
  952. * So doing a save/restore procedure here isn't the right
  953. * choice. Instead store it on ath5k_hw */
  954. ath5k_hw_reg_write(ah, (AR5K_TUNE_RSSI_THRES |
  955. AR5K_TUNE_BMISS_THRES <<
  956. AR5K_RSSI_THR_BMISS_S),
  957. AR5K_RSSI_THR);
  958. /* MIC QoS support */
  959. if (ah->ah_mac_srev >= AR5K_SREV_AR2413) {
  960. ath5k_hw_reg_write(ah, 0x000100aa, AR5K_MIC_QOS_CTL);
  961. ath5k_hw_reg_write(ah, 0x00003210, AR5K_MIC_QOS_SEL);
  962. }
  963. /* QoS NOACK Policy */
  964. if (ah->ah_version == AR5K_AR5212) {
  965. ath5k_hw_reg_write(ah,
  966. AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES) |
  967. AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET) |
  968. AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET),
  969. AR5K_QOS_NOACK);
  970. }
  971. /*
  972. * Configure PHY
  973. */
  974. /* Set channel on PHY */
  975. ret = ath5k_hw_channel(ah, channel);
  976. if (ret)
  977. return ret;
  978. /*
  979. * Enable the PHY and wait until completion
  980. * This includes BaseBand and Synthesizer
  981. * activation.
  982. */
  983. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
  984. /*
  985. * On 5211+ read activation -> rx delay
  986. * and use it.
  987. *
  988. * TODO: Half/quarter rate support
  989. */
  990. if (ah->ah_version != AR5K_AR5210) {
  991. u32 delay;
  992. delay = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
  993. AR5K_PHY_RX_DELAY_M;
  994. delay = (channel->hw_value & CHANNEL_CCK) ?
  995. ((delay << 2) / 22) : (delay / 10);
  996. udelay(100 + (2 * delay));
  997. } else {
  998. mdelay(1);
  999. }
  1000. /*
  1001. * Perform ADC test to see if baseband is ready
  1002. * Set tx hold and check adc test register
  1003. */
  1004. phy_tst1 = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
  1005. ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
  1006. for (i = 0; i <= 20; i++) {
  1007. if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
  1008. break;
  1009. udelay(200);
  1010. }
  1011. ath5k_hw_reg_write(ah, phy_tst1, AR5K_PHY_TST1);
  1012. /*
  1013. * Start automatic gain control calibration
  1014. *
  1015. * During AGC calibration RX path is re-routed to
  1016. * a power detector so we don't receive anything.
  1017. *
  1018. * This method is used to calibrate some static offsets
  1019. * used together with on-the fly I/Q calibration (the
  1020. * one performed via ath5k_hw_phy_calibrate), that doesn't
  1021. * interrupt rx path.
  1022. *
  1023. * While rx path is re-routed to the power detector we also
  1024. * start a noise floor calibration, to measure the
  1025. * card's noise floor (the noise we measure when we are not
  1026. * transmiting or receiving anything).
  1027. *
  1028. * If we are in a noisy environment AGC calibration may time
  1029. * out and/or noise floor calibration might timeout.
  1030. */
  1031. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
  1032. AR5K_PHY_AGCCTL_CAL);
  1033. /* At the same time start I/Q calibration for QAM constellation
  1034. * -no need for CCK- */
  1035. ah->ah_calibration = false;
  1036. if (!(mode == AR5K_MODE_11B)) {
  1037. ah->ah_calibration = true;
  1038. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
  1039. AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
  1040. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  1041. AR5K_PHY_IQ_RUN);
  1042. }
  1043. /* Wait for gain calibration to finish (we check for I/Q calibration
  1044. * during ath5k_phy_calibrate) */
  1045. if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
  1046. AR5K_PHY_AGCCTL_CAL, 0, false)) {
  1047. ATH5K_ERR(ah->ah_sc, "gain calibration timeout (%uMHz)\n",
  1048. channel->center_freq);
  1049. }
  1050. /*
  1051. * If we run NF calibration before AGC, it always times out.
  1052. * Binary HAL starts NF and AGC calibration at the same time
  1053. * and only waits for AGC to finish. Also if AGC or NF cal.
  1054. * times out, reset doesn't fail on binary HAL. I believe
  1055. * that's wrong because since rx path is routed to a detector,
  1056. * if cal. doesn't finish we won't have RX. Sam's HAL for AR5210/5211
  1057. * enables noise floor calibration after offset calibration and if noise
  1058. * floor calibration fails, reset fails. I believe that's
  1059. * a better approach, we just need to find a polling interval
  1060. * that suits best, even if reset continues we need to make
  1061. * sure that rx path is ready.
  1062. */
  1063. ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
  1064. /* Restore antenna mode */
  1065. ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
  1066. /*
  1067. * Configure QCUs/DCUs
  1068. */
  1069. /* TODO: HW Compression support for data queues */
  1070. /* TODO: Burst prefetch for data queues */
  1071. /*
  1072. * Reset queues and start beacon timers at the end of the reset routine
  1073. * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
  1074. * Note: If we want we can assign multiple qcus on one dcu.
  1075. */
  1076. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
  1077. ret = ath5k_hw_reset_tx_queue(ah, i);
  1078. if (ret) {
  1079. ATH5K_ERR(ah->ah_sc,
  1080. "failed to reset TX queue #%d\n", i);
  1081. return ret;
  1082. }
  1083. }
  1084. /*
  1085. * Configure DMA/Interrupts
  1086. */
  1087. /*
  1088. * Set Rx/Tx DMA Configuration
  1089. *
  1090. * Set standard DMA size (128). Note that
  1091. * a DMA size of 512 causes rx overruns and tx errors
  1092. * on pci-e cards (tested on 5424 but since rx overruns
  1093. * also occur on 5416/5418 with madwifi we set 128
  1094. * for all PCI-E cards to be safe).
  1095. *
  1096. * XXX: need to check 5210 for this
  1097. * TODO: Check out tx triger level, it's always 64 on dumps but I
  1098. * guess we can tweak it and see how it goes ;-)
  1099. */
  1100. if (ah->ah_version != AR5K_AR5210) {
  1101. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  1102. AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
  1103. AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
  1104. AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
  1105. }
  1106. /* Pre-enable interrupts on 5211/5212*/
  1107. if (ah->ah_version != AR5K_AR5210)
  1108. ath5k_hw_set_imr(ah, ah->ah_imr);
  1109. /* Enable 32KHz clock function for AR5212+ chips
  1110. * Set clocks to 32KHz operation and use an
  1111. * external 32KHz crystal when sleeping if one
  1112. * exists */
  1113. if (ah->ah_version == AR5K_AR5212)
  1114. ath5k_hw_set_sleep_clock(ah, true);
  1115. /*
  1116. * Disable beacons and reset the register
  1117. */
  1118. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
  1119. AR5K_BEACON_RESET_TSF);
  1120. return 0;
  1121. }
  1122. #undef _ATH5K_RESET