reset.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  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. /*****************************\
  22. Reset functions and helpers
  23. \*****************************/
  24. #include <asm/unaligned.h>
  25. #include <linux/pci.h> /* To determine if a card is pci-e */
  26. #include <linux/log2.h>
  27. #include <linux/platform_device.h>
  28. #include "ath5k.h"
  29. #include "reg.h"
  30. #include "base.h"
  31. #include "debug.h"
  32. /******************\
  33. * Helper functions *
  34. \******************/
  35. /*
  36. * Check if a register write has been completed
  37. */
  38. int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
  39. bool is_set)
  40. {
  41. int i;
  42. u32 data;
  43. for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
  44. data = ath5k_hw_reg_read(ah, reg);
  45. if (is_set && (data & flag))
  46. break;
  47. else if ((data & flag) == val)
  48. break;
  49. udelay(15);
  50. }
  51. return (i <= 0) ? -EAGAIN : 0;
  52. }
  53. /*************************\
  54. * Clock related functions *
  55. \*************************/
  56. /**
  57. * ath5k_hw_htoclock - Translate usec to hw clock units
  58. *
  59. * @ah: The &struct ath5k_hw
  60. * @usec: value in microseconds
  61. */
  62. unsigned int ath5k_hw_htoclock(struct ath5k_hw *ah, unsigned int usec)
  63. {
  64. struct ath_common *common = ath5k_hw_common(ah);
  65. return usec * common->clockrate;
  66. }
  67. /**
  68. * ath5k_hw_clocktoh - Translate hw clock units to usec
  69. * @clock: value in hw clock units
  70. */
  71. unsigned int ath5k_hw_clocktoh(struct ath5k_hw *ah, unsigned int clock)
  72. {
  73. struct ath_common *common = ath5k_hw_common(ah);
  74. return clock / common->clockrate;
  75. }
  76. /**
  77. * ath5k_hw_init_core_clock - Initialize core clock
  78. *
  79. * @ah The &struct ath5k_hw
  80. *
  81. * Initialize core clock parameters (usec, usec32, latencies etc).
  82. */
  83. static void ath5k_hw_init_core_clock(struct ath5k_hw *ah)
  84. {
  85. struct ieee80211_channel *channel = ah->ah_current_channel;
  86. struct ath_common *common = ath5k_hw_common(ah);
  87. u32 usec_reg, txlat, rxlat, usec, clock, sclock, txf2txs;
  88. /*
  89. * Set core clock frequency
  90. */
  91. if (channel->hw_value & CHANNEL_5GHZ)
  92. clock = 40; /* 802.11a */
  93. else if (channel->hw_value & CHANNEL_CCK)
  94. clock = 22; /* 802.11b */
  95. else
  96. clock = 44; /* 802.11g */
  97. /* Use clock multiplier for non-default
  98. * bwmode */
  99. switch (ah->ah_bwmode) {
  100. case AR5K_BWMODE_40MHZ:
  101. clock *= 2;
  102. break;
  103. case AR5K_BWMODE_10MHZ:
  104. clock /= 2;
  105. break;
  106. case AR5K_BWMODE_5MHZ:
  107. clock /= 4;
  108. break;
  109. default:
  110. break;
  111. }
  112. common->clockrate = clock;
  113. /*
  114. * Set USEC parameters
  115. */
  116. /* Set USEC counter on PCU*/
  117. usec = clock - 1;
  118. usec = AR5K_REG_SM(usec, AR5K_USEC_1);
  119. /* Set usec duration on DCU */
  120. if (ah->ah_version != AR5K_AR5210)
  121. AR5K_REG_WRITE_BITS(ah, AR5K_DCU_GBL_IFS_MISC,
  122. AR5K_DCU_GBL_IFS_MISC_USEC_DUR,
  123. clock);
  124. /* Set 32MHz USEC counter */
  125. if ((ah->ah_radio == AR5K_RF5112) ||
  126. (ah->ah_radio == AR5K_RF2413) ||
  127. (ah->ah_radio == AR5K_RF5413) ||
  128. (ah->ah_radio == AR5K_RF2316) ||
  129. (ah->ah_radio == AR5K_RF2317))
  130. /* Remain on 40MHz clock ? */
  131. sclock = 40 - 1;
  132. else
  133. sclock = 32 - 1;
  134. sclock = AR5K_REG_SM(sclock, AR5K_USEC_32);
  135. /*
  136. * Set tx/rx latencies
  137. */
  138. usec_reg = ath5k_hw_reg_read(ah, AR5K_USEC_5211);
  139. txlat = AR5K_REG_MS(usec_reg, AR5K_USEC_TX_LATENCY_5211);
  140. rxlat = AR5K_REG_MS(usec_reg, AR5K_USEC_RX_LATENCY_5211);
  141. /*
  142. * Set default Tx frame to Tx data start delay
  143. */
  144. txf2txs = AR5K_INIT_TXF2TXD_START_DEFAULT;
  145. /*
  146. * 5210 initvals don't include usec settings
  147. * so we need to use magic values here for
  148. * tx/rx latencies
  149. */
  150. if (ah->ah_version == AR5K_AR5210) {
  151. /* same for turbo */
  152. txlat = AR5K_INIT_TX_LATENCY_5210;
  153. rxlat = AR5K_INIT_RX_LATENCY_5210;
  154. }
  155. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  156. /* 5311 has different tx/rx latency masks
  157. * from 5211, since we deal 5311 the same
  158. * as 5211 when setting initvals, shift
  159. * values here to their proper locations
  160. *
  161. * Note: Initvals indicate tx/rx/ latencies
  162. * are the same for turbo mode */
  163. txlat = AR5K_REG_SM(txlat, AR5K_USEC_TX_LATENCY_5210);
  164. rxlat = AR5K_REG_SM(rxlat, AR5K_USEC_RX_LATENCY_5210);
  165. } else
  166. switch (ah->ah_bwmode) {
  167. case AR5K_BWMODE_10MHZ:
  168. txlat = AR5K_REG_SM(txlat * 2,
  169. AR5K_USEC_TX_LATENCY_5211);
  170. rxlat = AR5K_REG_SM(AR5K_INIT_RX_LAT_MAX,
  171. AR5K_USEC_RX_LATENCY_5211);
  172. txf2txs = AR5K_INIT_TXF2TXD_START_DELAY_10MHZ;
  173. break;
  174. case AR5K_BWMODE_5MHZ:
  175. txlat = AR5K_REG_SM(txlat * 4,
  176. AR5K_USEC_TX_LATENCY_5211);
  177. rxlat = AR5K_REG_SM(AR5K_INIT_RX_LAT_MAX,
  178. AR5K_USEC_RX_LATENCY_5211);
  179. txf2txs = AR5K_INIT_TXF2TXD_START_DELAY_5MHZ;
  180. break;
  181. case AR5K_BWMODE_40MHZ:
  182. txlat = AR5K_INIT_TX_LAT_MIN;
  183. rxlat = AR5K_REG_SM(rxlat / 2,
  184. AR5K_USEC_RX_LATENCY_5211);
  185. txf2txs = AR5K_INIT_TXF2TXD_START_DEFAULT;
  186. break;
  187. default:
  188. break;
  189. }
  190. usec_reg = (usec | sclock | txlat | rxlat);
  191. ath5k_hw_reg_write(ah, usec_reg, AR5K_USEC);
  192. /* On 5112 set tx frame to tx data start delay */
  193. if (ah->ah_radio == AR5K_RF5112) {
  194. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RF_CTL2,
  195. AR5K_PHY_RF_CTL2_TXF2TXD_START,
  196. txf2txs);
  197. }
  198. }
  199. /*
  200. * If there is an external 32KHz crystal available, use it
  201. * as ref. clock instead of 32/40MHz clock and baseband clocks
  202. * to save power during sleep or restore normal 32/40MHz
  203. * operation.
  204. *
  205. * XXX: When operating on 32KHz certain PHY registers (27 - 31,
  206. * 123 - 127) require delay on access.
  207. */
  208. static void ath5k_hw_set_sleep_clock(struct ath5k_hw *ah, bool enable)
  209. {
  210. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  211. u32 scal, spending, sclock;
  212. /* Only set 32KHz settings if we have an external
  213. * 32KHz crystal present */
  214. if ((AR5K_EEPROM_HAS32KHZCRYSTAL(ee->ee_misc1) ||
  215. AR5K_EEPROM_HAS32KHZCRYSTAL_OLD(ee->ee_misc1)) &&
  216. enable) {
  217. /* 1 usec/cycle */
  218. AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, 1);
  219. /* Set up tsf increment on each cycle */
  220. AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 61);
  221. /* Set baseband sleep control registers
  222. * and sleep control rate */
  223. ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
  224. if ((ah->ah_radio == AR5K_RF5112) ||
  225. (ah->ah_radio == AR5K_RF5413) ||
  226. (ah->ah_radio == AR5K_RF2316) ||
  227. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
  228. spending = 0x14;
  229. else
  230. spending = 0x18;
  231. ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
  232. if ((ah->ah_radio == AR5K_RF5112) ||
  233. (ah->ah_radio == AR5K_RF5413) ||
  234. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
  235. ath5k_hw_reg_write(ah, 0x26, AR5K_PHY_SLMT);
  236. ath5k_hw_reg_write(ah, 0x0d, AR5K_PHY_SCAL);
  237. ath5k_hw_reg_write(ah, 0x07, AR5K_PHY_SCLOCK);
  238. ath5k_hw_reg_write(ah, 0x3f, AR5K_PHY_SDELAY);
  239. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  240. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x02);
  241. } else {
  242. ath5k_hw_reg_write(ah, 0x0a, AR5K_PHY_SLMT);
  243. ath5k_hw_reg_write(ah, 0x0c, AR5K_PHY_SCAL);
  244. ath5k_hw_reg_write(ah, 0x03, AR5K_PHY_SCLOCK);
  245. ath5k_hw_reg_write(ah, 0x20, AR5K_PHY_SDELAY);
  246. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  247. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x03);
  248. }
  249. /* Enable sleep clock operation */
  250. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG,
  251. AR5K_PCICFG_SLEEP_CLOCK_EN);
  252. } else {
  253. /* Disable sleep clock operation and
  254. * restore default parameters */
  255. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
  256. AR5K_PCICFG_SLEEP_CLOCK_EN);
  257. AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
  258. AR5K_PCICFG_SLEEP_CLOCK_RATE, 0);
  259. /* Set DAC/ADC delays */
  260. ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
  261. ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
  262. if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
  263. scal = AR5K_PHY_SCAL_32MHZ_2417;
  264. else if (ee->ee_is_hb63)
  265. scal = AR5K_PHY_SCAL_32MHZ_HB63;
  266. else
  267. scal = AR5K_PHY_SCAL_32MHZ;
  268. ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
  269. ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
  270. ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
  271. if ((ah->ah_radio == AR5K_RF5112) ||
  272. (ah->ah_radio == AR5K_RF5413) ||
  273. (ah->ah_radio == AR5K_RF2316) ||
  274. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
  275. spending = 0x14;
  276. else
  277. spending = 0x18;
  278. ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
  279. /* Set up tsf increment on each cycle */
  280. AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 1);
  281. if ((ah->ah_radio == AR5K_RF5112) ||
  282. (ah->ah_radio == AR5K_RF5413) ||
  283. (ah->ah_radio == AR5K_RF2316) ||
  284. (ah->ah_radio == AR5K_RF2317))
  285. sclock = 40 - 1;
  286. else
  287. sclock = 32 - 1;
  288. AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, sclock);
  289. }
  290. }
  291. /*********************\
  292. * Reset/Sleep control *
  293. \*********************/
  294. /*
  295. * Reset chipset
  296. */
  297. static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
  298. {
  299. int ret;
  300. u32 mask = val ? val : ~0U;
  301. /* Read-and-clear RX Descriptor Pointer*/
  302. ath5k_hw_reg_read(ah, AR5K_RXDP);
  303. /*
  304. * Reset the device and wait until success
  305. */
  306. ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
  307. /* Wait at least 128 PCI clocks */
  308. udelay(15);
  309. if (ah->ah_version == AR5K_AR5210) {
  310. val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
  311. | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
  312. mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
  313. | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
  314. } else {
  315. val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  316. mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  317. }
  318. ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
  319. /*
  320. * Reset configuration register (for hw byte-swap). Note that this
  321. * is only set for big endian. We do the necessary magic in
  322. * AR5K_INIT_CFG.
  323. */
  324. if ((val & AR5K_RESET_CTL_PCU) == 0)
  325. ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
  326. return ret;
  327. }
  328. /*
  329. * Reset AHB chipset
  330. * AR5K_RESET_CTL_PCU flag resets WMAC
  331. * AR5K_RESET_CTL_BASEBAND flag resets WBB
  332. */
  333. static int ath5k_hw_wisoc_reset(struct ath5k_hw *ah, u32 flags)
  334. {
  335. u32 mask = flags ? flags : ~0U;
  336. u32 __iomem *reg;
  337. u32 regval;
  338. u32 val = 0;
  339. /* ah->ah_mac_srev is not available at this point yet */
  340. if (ah->devid >= AR5K_SREV_AR2315_R6) {
  341. reg = (u32 __iomem *) AR5K_AR2315_RESET;
  342. if (mask & AR5K_RESET_CTL_PCU)
  343. val |= AR5K_AR2315_RESET_WMAC;
  344. if (mask & AR5K_RESET_CTL_BASEBAND)
  345. val |= AR5K_AR2315_RESET_BB_WARM;
  346. } else {
  347. reg = (u32 __iomem *) AR5K_AR5312_RESET;
  348. if (to_platform_device(ah->dev)->id == 0) {
  349. if (mask & AR5K_RESET_CTL_PCU)
  350. val |= AR5K_AR5312_RESET_WMAC0;
  351. if (mask & AR5K_RESET_CTL_BASEBAND)
  352. val |= AR5K_AR5312_RESET_BB0_COLD |
  353. AR5K_AR5312_RESET_BB0_WARM;
  354. } else {
  355. if (mask & AR5K_RESET_CTL_PCU)
  356. val |= AR5K_AR5312_RESET_WMAC1;
  357. if (mask & AR5K_RESET_CTL_BASEBAND)
  358. val |= AR5K_AR5312_RESET_BB1_COLD |
  359. AR5K_AR5312_RESET_BB1_WARM;
  360. }
  361. }
  362. /* Put BB/MAC into reset */
  363. regval = __raw_readl(reg);
  364. __raw_writel(regval | val, reg);
  365. regval = __raw_readl(reg);
  366. udelay(100);
  367. /* Bring BB/MAC out of reset */
  368. __raw_writel(regval & ~val, reg);
  369. regval = __raw_readl(reg);
  370. /*
  371. * Reset configuration register (for hw byte-swap). Note that this
  372. * is only set for big endian. We do the necessary magic in
  373. * AR5K_INIT_CFG.
  374. */
  375. if ((flags & AR5K_RESET_CTL_PCU) == 0)
  376. ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
  377. return 0;
  378. }
  379. /*
  380. * Sleep control
  381. */
  382. static int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
  383. bool set_chip, u16 sleep_duration)
  384. {
  385. unsigned int i;
  386. u32 staid, data;
  387. staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
  388. switch (mode) {
  389. case AR5K_PM_AUTO:
  390. staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
  391. /* fallthrough */
  392. case AR5K_PM_NETWORK_SLEEP:
  393. if (set_chip)
  394. ath5k_hw_reg_write(ah,
  395. AR5K_SLEEP_CTL_SLE_ALLOW |
  396. sleep_duration,
  397. AR5K_SLEEP_CTL);
  398. staid |= AR5K_STA_ID1_PWR_SV;
  399. break;
  400. case AR5K_PM_FULL_SLEEP:
  401. if (set_chip)
  402. ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
  403. AR5K_SLEEP_CTL);
  404. staid |= AR5K_STA_ID1_PWR_SV;
  405. break;
  406. case AR5K_PM_AWAKE:
  407. staid &= ~AR5K_STA_ID1_PWR_SV;
  408. if (!set_chip)
  409. goto commit;
  410. data = ath5k_hw_reg_read(ah, AR5K_SLEEP_CTL);
  411. /* If card is down we 'll get 0xffff... so we
  412. * need to clean this up before we write the register
  413. */
  414. if (data & 0xffc00000)
  415. data = 0;
  416. else
  417. /* Preserve sleep duration etc */
  418. data = data & ~AR5K_SLEEP_CTL_SLE;
  419. ath5k_hw_reg_write(ah, data | AR5K_SLEEP_CTL_SLE_WAKE,
  420. AR5K_SLEEP_CTL);
  421. udelay(15);
  422. for (i = 200; i > 0; i--) {
  423. /* Check if the chip did wake up */
  424. if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  425. AR5K_PCICFG_SPWR_DN) == 0)
  426. break;
  427. /* Wait a bit and retry */
  428. udelay(50);
  429. ath5k_hw_reg_write(ah, data | AR5K_SLEEP_CTL_SLE_WAKE,
  430. AR5K_SLEEP_CTL);
  431. }
  432. /* Fail if the chip didn't wake up */
  433. if (i == 0)
  434. return -EIO;
  435. break;
  436. default:
  437. return -EINVAL;
  438. }
  439. commit:
  440. ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
  441. return 0;
  442. }
  443. /*
  444. * Put device on hold
  445. *
  446. * Put MAC and Baseband on warm reset and
  447. * keep that state (don't clean sleep control
  448. * register). After this MAC and Baseband are
  449. * disabled and a full reset is needed to come
  450. * back. This way we save as much power as possible
  451. * without putting the card on full sleep.
  452. */
  453. int ath5k_hw_on_hold(struct ath5k_hw *ah)
  454. {
  455. struct pci_dev *pdev = ah->pdev;
  456. u32 bus_flags;
  457. int ret;
  458. if (ath5k_get_bus_type(ah) == ATH_AHB)
  459. return 0;
  460. /* Make sure device is awake */
  461. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  462. if (ret) {
  463. ATH5K_ERR(ah, "failed to wakeup the MAC Chip\n");
  464. return ret;
  465. }
  466. /*
  467. * Put chipset on warm reset...
  468. *
  469. * Note: putting PCI core on warm reset on PCI-E cards
  470. * results card to hang and always return 0xffff... so
  471. * we ignore that flag for PCI-E cards. On PCI cards
  472. * this flag gets cleared after 64 PCI clocks.
  473. */
  474. bus_flags = (pdev && pci_is_pcie(pdev)) ? 0 : AR5K_RESET_CTL_PCI;
  475. if (ah->ah_version == AR5K_AR5210) {
  476. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  477. AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
  478. AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
  479. mdelay(2);
  480. } else {
  481. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  482. AR5K_RESET_CTL_BASEBAND | bus_flags);
  483. }
  484. if (ret) {
  485. ATH5K_ERR(ah, "failed to put device on warm reset\n");
  486. return -EIO;
  487. }
  488. /* ...wakeup again!*/
  489. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  490. if (ret) {
  491. ATH5K_ERR(ah, "failed to put device on hold\n");
  492. return ret;
  493. }
  494. return ret;
  495. }
  496. /*
  497. * Bring up MAC + PHY Chips and program PLL
  498. */
  499. int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
  500. {
  501. struct pci_dev *pdev = ah->pdev;
  502. u32 turbo, mode, clock, bus_flags;
  503. int ret;
  504. turbo = 0;
  505. mode = 0;
  506. clock = 0;
  507. if ((ath5k_get_bus_type(ah) != ATH_AHB) || !initial) {
  508. /* Wakeup the device */
  509. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  510. if (ret) {
  511. ATH5K_ERR(ah, "failed to wakeup the MAC Chip\n");
  512. return ret;
  513. }
  514. }
  515. /*
  516. * Put chipset on warm reset...
  517. *
  518. * Note: putting PCI core on warm reset on PCI-E cards
  519. * results card to hang and always return 0xffff... so
  520. * we ignore that flag for PCI-E cards. On PCI cards
  521. * this flag gets cleared after 64 PCI clocks.
  522. */
  523. bus_flags = (pdev && pci_is_pcie(pdev)) ? 0 : AR5K_RESET_CTL_PCI;
  524. if (ah->ah_version == AR5K_AR5210) {
  525. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  526. AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
  527. AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
  528. mdelay(2);
  529. } else {
  530. if (ath5k_get_bus_type(ah) == ATH_AHB)
  531. ret = ath5k_hw_wisoc_reset(ah, AR5K_RESET_CTL_PCU |
  532. AR5K_RESET_CTL_BASEBAND);
  533. else
  534. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  535. AR5K_RESET_CTL_BASEBAND | bus_flags);
  536. }
  537. if (ret) {
  538. ATH5K_ERR(ah, "failed to reset the MAC Chip\n");
  539. return -EIO;
  540. }
  541. /* ...wakeup again!...*/
  542. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  543. if (ret) {
  544. ATH5K_ERR(ah, "failed to resume the MAC Chip\n");
  545. return ret;
  546. }
  547. /* ...reset configuration register on Wisoc ...
  548. * ...clear reset control register and pull device out of
  549. * warm reset on others */
  550. if (ath5k_get_bus_type(ah) == ATH_AHB)
  551. ret = ath5k_hw_wisoc_reset(ah, 0);
  552. else
  553. ret = ath5k_hw_nic_reset(ah, 0);
  554. if (ret) {
  555. ATH5K_ERR(ah, "failed to warm reset the MAC Chip\n");
  556. return -EIO;
  557. }
  558. /* On initialization skip PLL programming since we don't have
  559. * a channel / mode set yet */
  560. if (initial)
  561. return 0;
  562. if (ah->ah_version != AR5K_AR5210) {
  563. /*
  564. * Get channel mode flags
  565. */
  566. if (ah->ah_radio >= AR5K_RF5112) {
  567. mode = AR5K_PHY_MODE_RAD_RF5112;
  568. clock = AR5K_PHY_PLL_RF5112;
  569. } else {
  570. mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
  571. clock = AR5K_PHY_PLL_RF5111; /*Zero*/
  572. }
  573. if (flags & CHANNEL_2GHZ) {
  574. mode |= AR5K_PHY_MODE_FREQ_2GHZ;
  575. clock |= AR5K_PHY_PLL_44MHZ;
  576. if (flags & CHANNEL_CCK) {
  577. mode |= AR5K_PHY_MODE_MOD_CCK;
  578. } else if (flags & CHANNEL_OFDM) {
  579. /* XXX Dynamic OFDM/CCK is not supported by the
  580. * AR5211 so we set MOD_OFDM for plain g (no
  581. * CCK headers) operation. We need to test
  582. * this, 5211 might support ofdm-only g after
  583. * all, there are also initial register values
  584. * in the code for g mode (see initvals.c).
  585. */
  586. if (ah->ah_version == AR5K_AR5211)
  587. mode |= AR5K_PHY_MODE_MOD_OFDM;
  588. else
  589. mode |= AR5K_PHY_MODE_MOD_DYN;
  590. } else {
  591. ATH5K_ERR(ah,
  592. "invalid radio modulation mode\n");
  593. return -EINVAL;
  594. }
  595. } else if (flags & CHANNEL_5GHZ) {
  596. mode |= AR5K_PHY_MODE_FREQ_5GHZ;
  597. /* Different PLL setting for 5413 */
  598. if (ah->ah_radio == AR5K_RF5413)
  599. clock = AR5K_PHY_PLL_40MHZ_5413;
  600. else
  601. clock |= AR5K_PHY_PLL_40MHZ;
  602. if (flags & CHANNEL_OFDM)
  603. mode |= AR5K_PHY_MODE_MOD_OFDM;
  604. else {
  605. ATH5K_ERR(ah,
  606. "invalid radio modulation mode\n");
  607. return -EINVAL;
  608. }
  609. } else {
  610. ATH5K_ERR(ah, "invalid radio frequency mode\n");
  611. return -EINVAL;
  612. }
  613. /*XXX: Can bwmode be used with dynamic mode ?
  614. * (I don't think it supports 44MHz) */
  615. /* On 2425 initvals TURBO_SHORT is not present */
  616. if (ah->ah_bwmode == AR5K_BWMODE_40MHZ) {
  617. turbo = AR5K_PHY_TURBO_MODE |
  618. (ah->ah_radio == AR5K_RF2425) ? 0 :
  619. AR5K_PHY_TURBO_SHORT;
  620. } else if (ah->ah_bwmode != AR5K_BWMODE_DEFAULT) {
  621. if (ah->ah_radio == AR5K_RF5413) {
  622. mode |= (ah->ah_bwmode == AR5K_BWMODE_10MHZ) ?
  623. AR5K_PHY_MODE_HALF_RATE :
  624. AR5K_PHY_MODE_QUARTER_RATE;
  625. } else if (ah->ah_version == AR5K_AR5212) {
  626. clock |= (ah->ah_bwmode == AR5K_BWMODE_10MHZ) ?
  627. AR5K_PHY_PLL_HALF_RATE :
  628. AR5K_PHY_PLL_QUARTER_RATE;
  629. }
  630. }
  631. } else { /* Reset the device */
  632. /* ...enable Atheros turbo mode if requested */
  633. if (ah->ah_bwmode == AR5K_BWMODE_40MHZ)
  634. ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
  635. AR5K_PHY_TURBO);
  636. }
  637. if (ah->ah_version != AR5K_AR5210) {
  638. /* ...update PLL if needed */
  639. if (ath5k_hw_reg_read(ah, AR5K_PHY_PLL) != clock) {
  640. ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
  641. udelay(300);
  642. }
  643. /* ...set the PHY operating mode */
  644. ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
  645. ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
  646. }
  647. return 0;
  648. }
  649. /**************************************\
  650. * Post-initvals register modifications *
  651. \**************************************/
  652. /* TODO: Half/Quarter rate */
  653. static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
  654. struct ieee80211_channel *channel)
  655. {
  656. if (ah->ah_version == AR5K_AR5212 &&
  657. ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
  658. /* Setup ADC control */
  659. ath5k_hw_reg_write(ah,
  660. (AR5K_REG_SM(2,
  661. AR5K_PHY_ADC_CTL_INBUFGAIN_OFF) |
  662. AR5K_REG_SM(2,
  663. AR5K_PHY_ADC_CTL_INBUFGAIN_ON) |
  664. AR5K_PHY_ADC_CTL_PWD_DAC_OFF |
  665. AR5K_PHY_ADC_CTL_PWD_ADC_OFF),
  666. AR5K_PHY_ADC_CTL);
  667. /* Disable barker RSSI threshold */
  668. AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
  669. AR5K_PHY_DAG_CCK_CTL_EN_RSSI_THR);
  670. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
  671. AR5K_PHY_DAG_CCK_CTL_RSSI_THR, 2);
  672. /* Set the mute mask */
  673. ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
  674. }
  675. /* Clear PHY_BLUETOOTH to allow RX_CLEAR line debug */
  676. if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212B)
  677. ath5k_hw_reg_write(ah, 0, AR5K_PHY_BLUETOOTH);
  678. /* Enable DCU double buffering */
  679. if (ah->ah_phy_revision > AR5K_SREV_PHY_5212B)
  680. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  681. AR5K_TXCFG_DCU_DBL_BUF_DIS);
  682. /* Set fast ADC */
  683. if ((ah->ah_radio == AR5K_RF5413) ||
  684. (ah->ah_radio == AR5K_RF2317) ||
  685. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
  686. u32 fast_adc = true;
  687. if (channel->center_freq == 2462 ||
  688. channel->center_freq == 2467)
  689. fast_adc = 0;
  690. /* Only update if needed */
  691. if (ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ADC) != fast_adc)
  692. ath5k_hw_reg_write(ah, fast_adc,
  693. AR5K_PHY_FAST_ADC);
  694. }
  695. /* Fix for first revision of the RF5112 RF chipset */
  696. if (ah->ah_radio == AR5K_RF5112 &&
  697. ah->ah_radio_5ghz_revision <
  698. AR5K_SREV_RAD_5112A) {
  699. u32 data;
  700. ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
  701. AR5K_PHY_CCKTXCTL);
  702. if (channel->hw_value & CHANNEL_5GHZ)
  703. data = 0xffb81020;
  704. else
  705. data = 0xffb80d20;
  706. ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
  707. }
  708. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  709. /* Clear QCU/DCU clock gating register */
  710. ath5k_hw_reg_write(ah, 0, AR5K_QCUDCU_CLKGT);
  711. /* Set DAC/ADC delays */
  712. ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ_5311,
  713. AR5K_PHY_SCAL);
  714. /* Enable PCU FIFO corruption ECO */
  715. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
  716. AR5K_DIAG_SW_ECO_ENABLE);
  717. }
  718. if (ah->ah_bwmode) {
  719. /* Increase PHY switch and AGC settling time
  720. * on turbo mode (ath5k_hw_commit_eeprom_settings
  721. * will override settling time if available) */
  722. if (ah->ah_bwmode == AR5K_BWMODE_40MHZ) {
  723. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  724. AR5K_PHY_SETTLING_AGC,
  725. AR5K_AGC_SETTLING_TURBO);
  726. /* XXX: Initvals indicate we only increase
  727. * switch time on AR5212, 5211 and 5210
  728. * only change agc time (bug?) */
  729. if (ah->ah_version == AR5K_AR5212)
  730. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  731. AR5K_PHY_SETTLING_SWITCH,
  732. AR5K_SWITCH_SETTLING_TURBO);
  733. if (ah->ah_version == AR5K_AR5210) {
  734. /* Set Frame Control Register */
  735. ath5k_hw_reg_write(ah,
  736. (AR5K_PHY_FRAME_CTL_INI |
  737. AR5K_PHY_TURBO_MODE |
  738. AR5K_PHY_TURBO_SHORT | 0x2020),
  739. AR5K_PHY_FRAME_CTL_5210);
  740. }
  741. /* On 5413 PHY force window length for half/quarter rate*/
  742. } else if ((ah->ah_mac_srev >= AR5K_SREV_AR5424) &&
  743. (ah->ah_mac_srev <= AR5K_SREV_AR5414)) {
  744. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL_5211,
  745. AR5K_PHY_FRAME_CTL_WIN_LEN,
  746. 3);
  747. }
  748. } else if (ah->ah_version == AR5K_AR5210) {
  749. /* Set Frame Control Register for normal operation */
  750. ath5k_hw_reg_write(ah, (AR5K_PHY_FRAME_CTL_INI | 0x1020),
  751. AR5K_PHY_FRAME_CTL_5210);
  752. }
  753. }
  754. static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
  755. struct ieee80211_channel *channel)
  756. {
  757. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  758. s16 cck_ofdm_pwr_delta;
  759. u8 ee_mode;
  760. /* TODO: Add support for AR5210 EEPROM */
  761. if (ah->ah_version == AR5K_AR5210)
  762. return;
  763. ee_mode = ath5k_eeprom_mode_from_channel(channel);
  764. /* Adjust power delta for channel 14 */
  765. if (channel->center_freq == 2484)
  766. cck_ofdm_pwr_delta =
  767. ((ee->ee_cck_ofdm_power_delta -
  768. ee->ee_scaled_cck_delta) * 2) / 10;
  769. else
  770. cck_ofdm_pwr_delta =
  771. (ee->ee_cck_ofdm_power_delta * 2) / 10;
  772. /* Set CCK to OFDM power delta on tx power
  773. * adjustment register */
  774. if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
  775. if (channel->hw_value == CHANNEL_G)
  776. ath5k_hw_reg_write(ah,
  777. AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1),
  778. AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) |
  779. AR5K_REG_SM((cck_ofdm_pwr_delta * -1),
  780. AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX),
  781. AR5K_PHY_TX_PWR_ADJ);
  782. else
  783. ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ);
  784. } else {
  785. /* For older revs we scale power on sw during tx power
  786. * setup */
  787. ah->ah_txpower.txp_cck_ofdm_pwr_delta = cck_ofdm_pwr_delta;
  788. ah->ah_txpower.txp_cck_ofdm_gainf_delta =
  789. ee->ee_cck_ofdm_gain_delta;
  790. }
  791. /* XXX: necessary here? is called from ath5k_hw_set_antenna_mode()
  792. * too */
  793. ath5k_hw_set_antenna_switch(ah, ee_mode);
  794. /* Noise floor threshold */
  795. ath5k_hw_reg_write(ah,
  796. AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
  797. AR5K_PHY_NFTHRES);
  798. if ((ah->ah_bwmode == AR5K_BWMODE_40MHZ) &&
  799. (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0)) {
  800. /* Switch settling time (Turbo) */
  801. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  802. AR5K_PHY_SETTLING_SWITCH,
  803. ee->ee_switch_settling_turbo[ee_mode]);
  804. /* Tx/Rx attenuation (Turbo) */
  805. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
  806. AR5K_PHY_GAIN_TXRX_ATTEN,
  807. ee->ee_atn_tx_rx_turbo[ee_mode]);
  808. /* ADC/PGA desired size (Turbo) */
  809. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  810. AR5K_PHY_DESIRED_SIZE_ADC,
  811. ee->ee_adc_desired_size_turbo[ee_mode]);
  812. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  813. AR5K_PHY_DESIRED_SIZE_PGA,
  814. ee->ee_pga_desired_size_turbo[ee_mode]);
  815. /* Tx/Rx margin (Turbo) */
  816. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  817. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  818. ee->ee_margin_tx_rx_turbo[ee_mode]);
  819. } else {
  820. /* Switch settling time */
  821. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  822. AR5K_PHY_SETTLING_SWITCH,
  823. ee->ee_switch_settling[ee_mode]);
  824. /* Tx/Rx attenuation */
  825. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
  826. AR5K_PHY_GAIN_TXRX_ATTEN,
  827. ee->ee_atn_tx_rx[ee_mode]);
  828. /* ADC/PGA desired size */
  829. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  830. AR5K_PHY_DESIRED_SIZE_ADC,
  831. ee->ee_adc_desired_size[ee_mode]);
  832. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  833. AR5K_PHY_DESIRED_SIZE_PGA,
  834. ee->ee_pga_desired_size[ee_mode]);
  835. /* Tx/Rx margin */
  836. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  837. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  838. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  839. ee->ee_margin_tx_rx[ee_mode]);
  840. }
  841. /* XPA delays */
  842. ath5k_hw_reg_write(ah,
  843. (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
  844. (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
  845. (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
  846. (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
  847. /* XLNA delay */
  848. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RF_CTL3,
  849. AR5K_PHY_RF_CTL3_TXE2XLNA_ON,
  850. ee->ee_tx_end2xlna_enable[ee_mode]);
  851. /* Thresh64 (ANI) */
  852. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_NF,
  853. AR5K_PHY_NF_THRESH62,
  854. ee->ee_thr_62[ee_mode]);
  855. /* False detect backoff for channels
  856. * that have spur noise. Write the new
  857. * cyclic power RSSI threshold. */
  858. if (ath5k_hw_chan_has_spur_noise(ah, channel))
  859. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
  860. AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
  861. AR5K_INIT_CYCRSSI_THR1 +
  862. ee->ee_false_detect[ee_mode]);
  863. else
  864. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
  865. AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
  866. AR5K_INIT_CYCRSSI_THR1);
  867. /* I/Q correction (set enable bit last to match HAL sources) */
  868. /* TODO: Per channel i/q infos ? */
  869. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
  870. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_Q_I_COFF,
  871. ee->ee_i_cal[ee_mode]);
  872. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_Q_Q_COFF,
  873. ee->ee_q_cal[ee_mode]);
  874. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_ENABLE);
  875. }
  876. /* Heavy clipping -disable for now */
  877. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_1)
  878. ath5k_hw_reg_write(ah, 0, AR5K_PHY_HEAVY_CLIP_ENABLE);
  879. }
  880. /*********************\
  881. * Main reset function *
  882. \*********************/
  883. int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
  884. struct ieee80211_channel *channel, bool fast, bool skip_pcu)
  885. {
  886. u32 s_seq[10], s_led[3], tsf_up, tsf_lo;
  887. u8 mode;
  888. int i, ret;
  889. tsf_up = 0;
  890. tsf_lo = 0;
  891. mode = 0;
  892. /*
  893. * Sanity check for fast flag
  894. * Fast channel change only available
  895. * on AR2413/AR5413.
  896. */
  897. if (fast && (ah->ah_radio != AR5K_RF2413) &&
  898. (ah->ah_radio != AR5K_RF5413))
  899. fast = 0;
  900. /* Disable sleep clock operation
  901. * to avoid register access delay on certain
  902. * PHY registers */
  903. if (ah->ah_version == AR5K_AR5212)
  904. ath5k_hw_set_sleep_clock(ah, false);
  905. /*
  906. * Stop PCU
  907. */
  908. ath5k_hw_stop_rx_pcu(ah);
  909. /*
  910. * Stop DMA
  911. *
  912. * Note: If DMA didn't stop continue
  913. * since only a reset will fix it.
  914. */
  915. ret = ath5k_hw_dma_stop(ah);
  916. /* RF Bus grant won't work if we have pending
  917. * frames */
  918. if (ret && fast) {
  919. ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
  920. "DMA didn't stop, falling back to normal reset\n");
  921. fast = 0;
  922. /* Non fatal, just continue with
  923. * normal reset */
  924. ret = 0;
  925. }
  926. switch (channel->hw_value & CHANNEL_MODES) {
  927. case CHANNEL_A:
  928. mode = AR5K_MODE_11A;
  929. break;
  930. case CHANNEL_G:
  931. if (ah->ah_version <= AR5K_AR5211) {
  932. ATH5K_ERR(ah,
  933. "G mode not available on 5210/5211");
  934. return -EINVAL;
  935. }
  936. mode = AR5K_MODE_11G;
  937. break;
  938. case CHANNEL_B:
  939. if (ah->ah_version < AR5K_AR5211) {
  940. ATH5K_ERR(ah,
  941. "B mode not available on 5210");
  942. return -EINVAL;
  943. }
  944. mode = AR5K_MODE_11B;
  945. break;
  946. case CHANNEL_XR:
  947. if (ah->ah_version == AR5K_AR5211) {
  948. ATH5K_ERR(ah,
  949. "XR mode not available on 5211");
  950. return -EINVAL;
  951. }
  952. mode = AR5K_MODE_XR;
  953. break;
  954. default:
  955. ATH5K_ERR(ah,
  956. "invalid channel: %d\n", channel->center_freq);
  957. return -EINVAL;
  958. }
  959. /*
  960. * If driver requested fast channel change and DMA has stopped
  961. * go on. If it fails continue with a normal reset.
  962. */
  963. if (fast) {
  964. ret = ath5k_hw_phy_init(ah, channel, mode, true);
  965. if (ret) {
  966. ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
  967. "fast chan change failed, falling back to normal reset\n");
  968. /* Non fatal, can happen eg.
  969. * on mode change */
  970. ret = 0;
  971. } else {
  972. ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
  973. "fast chan change successful\n");
  974. return 0;
  975. }
  976. }
  977. /*
  978. * Save some registers before a reset
  979. */
  980. if (ah->ah_version != AR5K_AR5210) {
  981. /*
  982. * Save frame sequence count
  983. * For revs. after Oahu, only save
  984. * seq num for DCU 0 (Global seq num)
  985. */
  986. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  987. for (i = 0; i < 10; i++)
  988. s_seq[i] = ath5k_hw_reg_read(ah,
  989. AR5K_QUEUE_DCU_SEQNUM(i));
  990. } else {
  991. s_seq[0] = ath5k_hw_reg_read(ah,
  992. AR5K_QUEUE_DCU_SEQNUM(0));
  993. }
  994. /* TSF accelerates on AR5211 during reset
  995. * As a workaround save it here and restore
  996. * it later so that it's back in time after
  997. * reset. This way it'll get re-synced on the
  998. * next beacon without breaking ad-hoc.
  999. *
  1000. * On AR5212 TSF is almost preserved across a
  1001. * reset so it stays back in time anyway and
  1002. * we don't have to save/restore it.
  1003. *
  1004. * XXX: Since this breaks power saving we have
  1005. * to disable power saving until we receive the
  1006. * next beacon, so we can resync beacon timers */
  1007. if (ah->ah_version == AR5K_AR5211) {
  1008. tsf_up = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
  1009. tsf_lo = ath5k_hw_reg_read(ah, AR5K_TSF_L32);
  1010. }
  1011. }
  1012. /*GPIOs*/
  1013. s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  1014. AR5K_PCICFG_LEDSTATE;
  1015. s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
  1016. s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  1017. /*
  1018. * Since we are going to write rf buffer
  1019. * check if we have any pending gain_F
  1020. * optimization settings
  1021. */
  1022. if (ah->ah_version == AR5K_AR5212 &&
  1023. (ah->ah_radio <= AR5K_RF5112)) {
  1024. if (!fast && ah->ah_rf_banks != NULL)
  1025. ath5k_hw_gainf_calibrate(ah);
  1026. }
  1027. /* Wakeup the device */
  1028. ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
  1029. if (ret)
  1030. return ret;
  1031. /* PHY access enable */
  1032. if (ah->ah_mac_srev >= AR5K_SREV_AR5211)
  1033. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
  1034. else
  1035. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ | 0x40,
  1036. AR5K_PHY(0));
  1037. /* Write initial settings */
  1038. ret = ath5k_hw_write_initvals(ah, mode, skip_pcu);
  1039. if (ret)
  1040. return ret;
  1041. /* Initialize core clock settings */
  1042. ath5k_hw_init_core_clock(ah);
  1043. /*
  1044. * Tweak initval settings for revised
  1045. * chipsets and add some more config
  1046. * bits
  1047. */
  1048. ath5k_hw_tweak_initval_settings(ah, channel);
  1049. /* Commit values from EEPROM */
  1050. ath5k_hw_commit_eeprom_settings(ah, channel);
  1051. /*
  1052. * Restore saved values
  1053. */
  1054. /* Seqnum, TSF */
  1055. if (ah->ah_version != AR5K_AR5210) {
  1056. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  1057. for (i = 0; i < 10; i++)
  1058. ath5k_hw_reg_write(ah, s_seq[i],
  1059. AR5K_QUEUE_DCU_SEQNUM(i));
  1060. } else {
  1061. ath5k_hw_reg_write(ah, s_seq[0],
  1062. AR5K_QUEUE_DCU_SEQNUM(0));
  1063. }
  1064. if (ah->ah_version == AR5K_AR5211) {
  1065. ath5k_hw_reg_write(ah, tsf_up, AR5K_TSF_U32);
  1066. ath5k_hw_reg_write(ah, tsf_lo, AR5K_TSF_L32);
  1067. }
  1068. }
  1069. /* Ledstate */
  1070. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
  1071. /* Gpio settings */
  1072. ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
  1073. ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
  1074. /*
  1075. * Initialize PCU
  1076. */
  1077. ath5k_hw_pcu_init(ah, op_mode, mode);
  1078. /*
  1079. * Initialize PHY
  1080. */
  1081. ret = ath5k_hw_phy_init(ah, channel, mode, false);
  1082. if (ret) {
  1083. ATH5K_ERR(ah,
  1084. "failed to initialize PHY (%i) !\n", ret);
  1085. return ret;
  1086. }
  1087. /*
  1088. * Configure QCUs/DCUs
  1089. */
  1090. ret = ath5k_hw_init_queues(ah);
  1091. if (ret)
  1092. return ret;
  1093. /*
  1094. * Initialize DMA/Interrupts
  1095. */
  1096. ath5k_hw_dma_init(ah);
  1097. /*
  1098. * Enable 32KHz clock function for AR5212+ chips
  1099. * Set clocks to 32KHz operation and use an
  1100. * external 32KHz crystal when sleeping if one
  1101. * exists.
  1102. * Disabled by default because it is also disabled in
  1103. * other drivers and it is known to cause stability
  1104. * issues on some devices
  1105. */
  1106. if (ah->ah_use_32khz_clock && ah->ah_version == AR5K_AR5212 &&
  1107. op_mode != NL80211_IFTYPE_AP)
  1108. ath5k_hw_set_sleep_clock(ah, true);
  1109. /*
  1110. * Disable beacons and reset the TSF
  1111. */
  1112. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
  1113. ath5k_hw_reset_tsf(ah);
  1114. return 0;
  1115. }