eeprom.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "hw.h"
  17. #include <linux/ath9k_platform.h>
  18. void ath9k_hw_analog_shift_regwrite(struct ath_hw *ah, u32 reg, u32 val)
  19. {
  20. REG_WRITE(ah, reg, val);
  21. if (ah->config.analog_shiftreg)
  22. udelay(100);
  23. }
  24. void ath9k_hw_analog_shift_rmw(struct ath_hw *ah, u32 reg, u32 mask,
  25. u32 shift, u32 val)
  26. {
  27. REG_RMW(ah, reg, ((val << shift) & mask), mask);
  28. if (ah->config.analog_shiftreg)
  29. udelay(100);
  30. }
  31. int16_t ath9k_hw_interpolate(u16 target, u16 srcLeft, u16 srcRight,
  32. int16_t targetLeft, int16_t targetRight)
  33. {
  34. int16_t rv;
  35. if (srcRight == srcLeft) {
  36. rv = targetLeft;
  37. } else {
  38. rv = (int16_t) (((target - srcLeft) * targetRight +
  39. (srcRight - target) * targetLeft) /
  40. (srcRight - srcLeft));
  41. }
  42. return rv;
  43. }
  44. bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList, u16 listSize,
  45. u16 *indexL, u16 *indexR)
  46. {
  47. u16 i;
  48. if (target <= pList[0]) {
  49. *indexL = *indexR = 0;
  50. return true;
  51. }
  52. if (target >= pList[listSize - 1]) {
  53. *indexL = *indexR = (u16) (listSize - 1);
  54. return true;
  55. }
  56. for (i = 0; i < listSize - 1; i++) {
  57. if (pList[i] == target) {
  58. *indexL = *indexR = i;
  59. return true;
  60. }
  61. if (target < pList[i + 1]) {
  62. *indexL = i;
  63. *indexR = (u16) (i + 1);
  64. return false;
  65. }
  66. }
  67. return false;
  68. }
  69. void ath9k_hw_usb_gen_fill_eeprom(struct ath_hw *ah, u16 *eep_data,
  70. int eep_start_loc, int size)
  71. {
  72. int i = 0, j, addr;
  73. u32 addrdata[8];
  74. u32 data[8];
  75. for (addr = 0; addr < size; addr++) {
  76. addrdata[i] = AR5416_EEPROM_OFFSET +
  77. ((addr + eep_start_loc) << AR5416_EEPROM_S);
  78. i++;
  79. if (i == 8) {
  80. REG_READ_MULTI(ah, addrdata, data, i);
  81. for (j = 0; j < i; j++) {
  82. *eep_data = data[j];
  83. eep_data++;
  84. }
  85. i = 0;
  86. }
  87. }
  88. if (i != 0) {
  89. REG_READ_MULTI(ah, addrdata, data, i);
  90. for (j = 0; j < i; j++) {
  91. *eep_data = data[j];
  92. eep_data++;
  93. }
  94. }
  95. }
  96. static bool ath9k_hw_nvram_read_array(u16 *blob, size_t blob_size,
  97. off_t offset, u16 *data)
  98. {
  99. if (offset > blob_size)
  100. return false;
  101. *data = blob[offset];
  102. return true;
  103. }
  104. static bool ath9k_hw_nvram_read_pdata(struct ath9k_platform_data *pdata,
  105. off_t offset, u16 *data)
  106. {
  107. return ath9k_hw_nvram_read_array(pdata->eeprom_data,
  108. ARRAY_SIZE(pdata->eeprom_data),
  109. offset, data);
  110. }
  111. static bool ath9k_hw_nvram_read_firmware(const struct firmware *eeprom_blob,
  112. off_t offset, u16 *data)
  113. {
  114. return ath9k_hw_nvram_read_array((u16 *) eeprom_blob->data,
  115. eeprom_blob->size / sizeof(u16),
  116. offset, data);
  117. }
  118. bool ath9k_hw_nvram_read(struct ath_hw *ah, u32 off, u16 *data)
  119. {
  120. struct ath_common *common = ath9k_hw_common(ah);
  121. struct ath9k_platform_data *pdata = ah->dev->platform_data;
  122. bool ret;
  123. if (ah->eeprom_blob)
  124. ret = ath9k_hw_nvram_read_firmware(ah->eeprom_blob, off, data);
  125. else if (pdata && !pdata->use_eeprom && pdata->eeprom_data)
  126. ret = ath9k_hw_nvram_read_pdata(pdata, off, data);
  127. else
  128. ret = common->bus_ops->eeprom_read(common, off, data);
  129. if (!ret)
  130. ath_dbg(common, EEPROM,
  131. "unable to read eeprom region at offset %u\n", off);
  132. return ret;
  133. }
  134. int ath9k_hw_nvram_swap_data(struct ath_hw *ah, bool *swap_needed, int size)
  135. {
  136. u16 magic;
  137. u16 *eepdata;
  138. int i;
  139. struct ath_common *common = ath9k_hw_common(ah);
  140. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  141. ath_err(common, "Reading Magic # failed\n");
  142. return -EIO;
  143. }
  144. *swap_needed = false;
  145. if (swab16(magic) == AR5416_EEPROM_MAGIC) {
  146. if (ah->ah_flags & AH_NO_EEP_SWAP) {
  147. ath_info(common,
  148. "Ignoring endianness difference in EEPROM magic bytes.\n");
  149. } else {
  150. *swap_needed = true;
  151. }
  152. } else if (magic != AR5416_EEPROM_MAGIC) {
  153. if (ath9k_hw_use_flash(ah))
  154. return 0;
  155. ath_err(common,
  156. "Invalid EEPROM Magic (0x%04x).\n", magic);
  157. return -EINVAL;
  158. }
  159. eepdata = (u16 *)(&ah->eeprom);
  160. if (*swap_needed) {
  161. ath_dbg(common, EEPROM,
  162. "EEPROM Endianness is not native.. Changing.\n");
  163. for (i = 0; i < size; i++)
  164. eepdata[i] = swab16(eepdata[i]);
  165. }
  166. return 0;
  167. }
  168. bool ath9k_hw_nvram_validate_checksum(struct ath_hw *ah, int size)
  169. {
  170. u32 i, sum = 0;
  171. u16 *eepdata = (u16 *)(&ah->eeprom);
  172. struct ath_common *common = ath9k_hw_common(ah);
  173. for (i = 0; i < size; i++)
  174. sum ^= eepdata[i];
  175. if (sum != 0xffff) {
  176. ath_err(common, "Bad EEPROM checksum 0x%x\n", sum);
  177. return false;
  178. }
  179. return true;
  180. }
  181. bool ath9k_hw_nvram_check_version(struct ath_hw *ah, int version, int minrev)
  182. {
  183. struct ath_common *common = ath9k_hw_common(ah);
  184. if (ah->eep_ops->get_eeprom_ver(ah) != version ||
  185. ah->eep_ops->get_eeprom_rev(ah) < minrev) {
  186. ath_err(common, "Bad EEPROM VER 0x%04x or REV 0x%04x\n",
  187. ah->eep_ops->get_eeprom_ver(ah),
  188. ah->eep_ops->get_eeprom_rev(ah));
  189. return false;
  190. }
  191. return true;
  192. }
  193. void ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList,
  194. u8 *pVpdList, u16 numIntercepts,
  195. u8 *pRetVpdList)
  196. {
  197. u16 i, k;
  198. u8 currPwr = pwrMin;
  199. u16 idxL = 0, idxR = 0;
  200. for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
  201. ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
  202. numIntercepts, &(idxL),
  203. &(idxR));
  204. if (idxR < 1)
  205. idxR = 1;
  206. if (idxL == numIntercepts - 1)
  207. idxL = (u16) (numIntercepts - 2);
  208. if (pPwrList[idxL] == pPwrList[idxR])
  209. k = pVpdList[idxL];
  210. else
  211. k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
  212. (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
  213. (pPwrList[idxR] - pPwrList[idxL]));
  214. pRetVpdList[i] = (u8) k;
  215. currPwr += 2;
  216. }
  217. }
  218. void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah,
  219. struct ath9k_channel *chan,
  220. struct cal_target_power_leg *powInfo,
  221. u16 numChannels,
  222. struct cal_target_power_leg *pNewPower,
  223. u16 numRates, bool isExtTarget)
  224. {
  225. struct chan_centers centers;
  226. u16 clo, chi;
  227. int i;
  228. int matchIndex = -1, lowIndex = -1;
  229. u16 freq;
  230. ath9k_hw_get_channel_centers(ah, chan, &centers);
  231. freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
  232. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
  233. IS_CHAN_2GHZ(chan))) {
  234. matchIndex = 0;
  235. } else {
  236. for (i = 0; (i < numChannels) &&
  237. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  238. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  239. IS_CHAN_2GHZ(chan))) {
  240. matchIndex = i;
  241. break;
  242. } else if (freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  243. IS_CHAN_2GHZ(chan)) && i > 0 &&
  244. freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  245. IS_CHAN_2GHZ(chan))) {
  246. lowIndex = i - 1;
  247. break;
  248. }
  249. }
  250. if ((matchIndex == -1) && (lowIndex == -1))
  251. matchIndex = i - 1;
  252. }
  253. if (matchIndex != -1) {
  254. *pNewPower = powInfo[matchIndex];
  255. } else {
  256. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  257. IS_CHAN_2GHZ(chan));
  258. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  259. IS_CHAN_2GHZ(chan));
  260. for (i = 0; i < numRates; i++) {
  261. pNewPower->tPow2x[i] =
  262. (u8)ath9k_hw_interpolate(freq, clo, chi,
  263. powInfo[lowIndex].tPow2x[i],
  264. powInfo[lowIndex + 1].tPow2x[i]);
  265. }
  266. }
  267. }
  268. void ath9k_hw_get_target_powers(struct ath_hw *ah,
  269. struct ath9k_channel *chan,
  270. struct cal_target_power_ht *powInfo,
  271. u16 numChannels,
  272. struct cal_target_power_ht *pNewPower,
  273. u16 numRates, bool isHt40Target)
  274. {
  275. struct chan_centers centers;
  276. u16 clo, chi;
  277. int i;
  278. int matchIndex = -1, lowIndex = -1;
  279. u16 freq;
  280. ath9k_hw_get_channel_centers(ah, chan, &centers);
  281. freq = isHt40Target ? centers.synth_center : centers.ctl_center;
  282. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
  283. matchIndex = 0;
  284. } else {
  285. for (i = 0; (i < numChannels) &&
  286. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  287. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  288. IS_CHAN_2GHZ(chan))) {
  289. matchIndex = i;
  290. break;
  291. } else
  292. if (freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  293. IS_CHAN_2GHZ(chan)) && i > 0 &&
  294. freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  295. IS_CHAN_2GHZ(chan))) {
  296. lowIndex = i - 1;
  297. break;
  298. }
  299. }
  300. if ((matchIndex == -1) && (lowIndex == -1))
  301. matchIndex = i - 1;
  302. }
  303. if (matchIndex != -1) {
  304. *pNewPower = powInfo[matchIndex];
  305. } else {
  306. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  307. IS_CHAN_2GHZ(chan));
  308. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  309. IS_CHAN_2GHZ(chan));
  310. for (i = 0; i < numRates; i++) {
  311. pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
  312. clo, chi,
  313. powInfo[lowIndex].tPow2x[i],
  314. powInfo[lowIndex + 1].tPow2x[i]);
  315. }
  316. }
  317. }
  318. u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower,
  319. bool is2GHz, int num_band_edges)
  320. {
  321. u16 twiceMaxEdgePower = MAX_RATE_POWER;
  322. int i;
  323. for (i = 0; (i < num_band_edges) &&
  324. (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  325. if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
  326. twiceMaxEdgePower = CTL_EDGE_TPOWER(pRdEdgesPower[i].ctl);
  327. break;
  328. } else if ((i > 0) &&
  329. (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
  330. is2GHz))) {
  331. if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
  332. is2GHz) < freq &&
  333. CTL_EDGE_FLAGS(pRdEdgesPower[i - 1].ctl)) {
  334. twiceMaxEdgePower =
  335. CTL_EDGE_TPOWER(pRdEdgesPower[i - 1].ctl);
  336. }
  337. break;
  338. }
  339. }
  340. return twiceMaxEdgePower;
  341. }
  342. u16 ath9k_hw_get_scaled_power(struct ath_hw *ah, u16 power_limit,
  343. u8 antenna_reduction)
  344. {
  345. u16 reduction = antenna_reduction;
  346. /*
  347. * Reduce scaled Power by number of chains active
  348. * to get the per chain tx power level.
  349. */
  350. switch (ar5416_get_ntxchains(ah->txchainmask)) {
  351. case 1:
  352. break;
  353. case 2:
  354. reduction += POWER_CORRECTION_FOR_TWO_CHAIN;
  355. break;
  356. case 3:
  357. reduction += POWER_CORRECTION_FOR_THREE_CHAIN;
  358. break;
  359. }
  360. if (power_limit > reduction)
  361. power_limit -= reduction;
  362. else
  363. power_limit = 0;
  364. return power_limit;
  365. }
  366. void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah)
  367. {
  368. struct ath_common *common = ath9k_hw_common(ah);
  369. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  370. switch (ar5416_get_ntxchains(ah->txchainmask)) {
  371. case 1:
  372. break;
  373. case 2:
  374. regulatory->max_power_level += POWER_CORRECTION_FOR_TWO_CHAIN;
  375. break;
  376. case 3:
  377. regulatory->max_power_level += POWER_CORRECTION_FOR_THREE_CHAIN;
  378. break;
  379. default:
  380. ath_dbg(common, EEPROM, "Invalid chainmask configuration\n");
  381. break;
  382. }
  383. }
  384. void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hw *ah,
  385. struct ath9k_channel *chan,
  386. void *pRawDataSet,
  387. u8 *bChans, u16 availPiers,
  388. u16 tPdGainOverlap,
  389. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  390. u16 numXpdGains)
  391. {
  392. int i, j, k;
  393. int16_t ss;
  394. u16 idxL = 0, idxR = 0, numPiers;
  395. static u8 vpdTableL[AR5416_NUM_PD_GAINS]
  396. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  397. static u8 vpdTableR[AR5416_NUM_PD_GAINS]
  398. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  399. static u8 vpdTableI[AR5416_NUM_PD_GAINS]
  400. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  401. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  402. u8 minPwrT4[AR5416_NUM_PD_GAINS];
  403. u8 maxPwrT4[AR5416_NUM_PD_GAINS];
  404. int16_t vpdStep;
  405. int16_t tmpVal;
  406. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  407. bool match;
  408. int16_t minDelta = 0;
  409. struct chan_centers centers;
  410. int pdgain_boundary_default;
  411. struct cal_data_per_freq *data_def = pRawDataSet;
  412. struct cal_data_per_freq_4k *data_4k = pRawDataSet;
  413. struct cal_data_per_freq_ar9287 *data_9287 = pRawDataSet;
  414. bool eeprom_4k = AR_SREV_9285(ah) || AR_SREV_9271(ah);
  415. int intercepts;
  416. if (AR_SREV_9287(ah))
  417. intercepts = AR9287_PD_GAIN_ICEPTS;
  418. else
  419. intercepts = AR5416_PD_GAIN_ICEPTS;
  420. memset(&minPwrT4, 0, AR5416_NUM_PD_GAINS);
  421. ath9k_hw_get_channel_centers(ah, chan, &centers);
  422. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  423. if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
  424. break;
  425. }
  426. match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
  427. IS_CHAN_2GHZ(chan)),
  428. bChans, numPiers, &idxL, &idxR);
  429. if (match) {
  430. if (AR_SREV_9287(ah)) {
  431. for (i = 0; i < numXpdGains; i++) {
  432. minPwrT4[i] = data_9287[idxL].pwrPdg[i][0];
  433. maxPwrT4[i] = data_9287[idxL].pwrPdg[i][intercepts - 1];
  434. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  435. data_9287[idxL].pwrPdg[i],
  436. data_9287[idxL].vpdPdg[i],
  437. intercepts,
  438. vpdTableI[i]);
  439. }
  440. } else if (eeprom_4k) {
  441. for (i = 0; i < numXpdGains; i++) {
  442. minPwrT4[i] = data_4k[idxL].pwrPdg[i][0];
  443. maxPwrT4[i] = data_4k[idxL].pwrPdg[i][intercepts - 1];
  444. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  445. data_4k[idxL].pwrPdg[i],
  446. data_4k[idxL].vpdPdg[i],
  447. intercepts,
  448. vpdTableI[i]);
  449. }
  450. } else {
  451. for (i = 0; i < numXpdGains; i++) {
  452. minPwrT4[i] = data_def[idxL].pwrPdg[i][0];
  453. maxPwrT4[i] = data_def[idxL].pwrPdg[i][intercepts - 1];
  454. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  455. data_def[idxL].pwrPdg[i],
  456. data_def[idxL].vpdPdg[i],
  457. intercepts,
  458. vpdTableI[i]);
  459. }
  460. }
  461. } else {
  462. for (i = 0; i < numXpdGains; i++) {
  463. if (AR_SREV_9287(ah)) {
  464. pVpdL = data_9287[idxL].vpdPdg[i];
  465. pPwrL = data_9287[idxL].pwrPdg[i];
  466. pVpdR = data_9287[idxR].vpdPdg[i];
  467. pPwrR = data_9287[idxR].pwrPdg[i];
  468. } else if (eeprom_4k) {
  469. pVpdL = data_4k[idxL].vpdPdg[i];
  470. pPwrL = data_4k[idxL].pwrPdg[i];
  471. pVpdR = data_4k[idxR].vpdPdg[i];
  472. pPwrR = data_4k[idxR].pwrPdg[i];
  473. } else {
  474. pVpdL = data_def[idxL].vpdPdg[i];
  475. pPwrL = data_def[idxL].pwrPdg[i];
  476. pVpdR = data_def[idxR].vpdPdg[i];
  477. pPwrR = data_def[idxR].pwrPdg[i];
  478. }
  479. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  480. maxPwrT4[i] =
  481. min(pPwrL[intercepts - 1],
  482. pPwrR[intercepts - 1]);
  483. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  484. pPwrL, pVpdL,
  485. intercepts,
  486. vpdTableL[i]);
  487. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  488. pPwrR, pVpdR,
  489. intercepts,
  490. vpdTableR[i]);
  491. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  492. vpdTableI[i][j] =
  493. (u8)(ath9k_hw_interpolate((u16)
  494. FREQ2FBIN(centers.
  495. synth_center,
  496. IS_CHAN_2GHZ
  497. (chan)),
  498. bChans[idxL], bChans[idxR],
  499. vpdTableL[i][j], vpdTableR[i][j]));
  500. }
  501. }
  502. }
  503. k = 0;
  504. for (i = 0; i < numXpdGains; i++) {
  505. if (i == (numXpdGains - 1))
  506. pPdGainBoundaries[i] =
  507. (u16)(maxPwrT4[i] / 2);
  508. else
  509. pPdGainBoundaries[i] =
  510. (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
  511. pPdGainBoundaries[i] =
  512. min((u16)MAX_RATE_POWER, pPdGainBoundaries[i]);
  513. minDelta = 0;
  514. if (i == 0) {
  515. if (AR_SREV_9280_20_OR_LATER(ah))
  516. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  517. else
  518. ss = 0;
  519. } else {
  520. ss = (int16_t)((pPdGainBoundaries[i - 1] -
  521. (minPwrT4[i] / 2)) -
  522. tPdGainOverlap + 1 + minDelta);
  523. }
  524. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  525. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  526. while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  527. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  528. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  529. ss++;
  530. }
  531. sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  532. tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
  533. (minPwrT4[i] / 2));
  534. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  535. tgtIndex : sizeCurrVpdTable;
  536. while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  537. pPDADCValues[k++] = vpdTableI[i][ss++];
  538. }
  539. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  540. vpdTableI[i][sizeCurrVpdTable - 2]);
  541. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  542. if (tgtIndex >= maxIndex) {
  543. while ((ss <= tgtIndex) &&
  544. (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  545. tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
  546. (ss - maxIndex + 1) * vpdStep));
  547. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  548. 255 : tmpVal);
  549. ss++;
  550. }
  551. }
  552. }
  553. if (eeprom_4k)
  554. pdgain_boundary_default = 58;
  555. else
  556. pdgain_boundary_default = pPdGainBoundaries[i - 1];
  557. while (i < AR5416_PD_GAINS_IN_MASK) {
  558. pPdGainBoundaries[i] = pdgain_boundary_default;
  559. i++;
  560. }
  561. while (k < AR5416_NUM_PDADC_VALUES) {
  562. pPDADCValues[k] = pPDADCValues[k - 1];
  563. k++;
  564. }
  565. }
  566. int ath9k_hw_eeprom_init(struct ath_hw *ah)
  567. {
  568. int status;
  569. if (AR_SREV_9300_20_OR_LATER(ah))
  570. ah->eep_ops = &eep_ar9300_ops;
  571. else if (AR_SREV_9287(ah)) {
  572. ah->eep_ops = &eep_ar9287_ops;
  573. } else if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
  574. ah->eep_ops = &eep_4k_ops;
  575. } else {
  576. ah->eep_ops = &eep_def_ops;
  577. }
  578. if (!ah->eep_ops->fill_eeprom(ah))
  579. return -EIO;
  580. status = ah->eep_ops->check_eeprom(ah);
  581. return status;
  582. }