eeprom.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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. static bool ath9k_hw_nvram_read_nvmem(struct ath_hw *ah, off_t offset,
  119. u16 *data)
  120. {
  121. return ath9k_hw_nvram_read_array(ah->nvmem_blob,
  122. ah->nvmem_blob_len / sizeof(u16),
  123. offset, data);
  124. }
  125. bool ath9k_hw_nvram_read(struct ath_hw *ah, u32 off, u16 *data)
  126. {
  127. struct ath_common *common = ath9k_hw_common(ah);
  128. struct ath9k_platform_data *pdata = ah->dev->platform_data;
  129. bool ret;
  130. if (ah->nvmem_blob)
  131. ret = ath9k_hw_nvram_read_nvmem(ah, off, data);
  132. else if (ah->eeprom_blob)
  133. ret = ath9k_hw_nvram_read_firmware(ah->eeprom_blob, off, data);
  134. else if (pdata && !pdata->use_eeprom)
  135. ret = ath9k_hw_nvram_read_pdata(pdata, off, data);
  136. else
  137. ret = common->bus_ops->eeprom_read(common, off, data);
  138. if (!ret)
  139. ath_dbg(common, EEPROM,
  140. "unable to read eeprom region at offset %u\n", off);
  141. return ret;
  142. }
  143. int ath9k_hw_nvram_swap_data(struct ath_hw *ah, bool *swap_needed, int size)
  144. {
  145. u16 magic;
  146. u16 *eepdata;
  147. int i;
  148. bool needs_byteswap = false;
  149. struct ath_common *common = ath9k_hw_common(ah);
  150. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  151. ath_err(common, "Reading Magic # failed\n");
  152. return -EIO;
  153. }
  154. if (swab16(magic) == AR5416_EEPROM_MAGIC) {
  155. needs_byteswap = true;
  156. ath_dbg(common, EEPROM,
  157. "EEPROM needs byte-swapping to correct endianness.\n");
  158. } else if (magic != AR5416_EEPROM_MAGIC) {
  159. if (ath9k_hw_use_flash(ah)) {
  160. ath_dbg(common, EEPROM,
  161. "Ignoring invalid EEPROM magic (0x%04x).\n",
  162. magic);
  163. } else {
  164. ath_err(common,
  165. "Invalid EEPROM magic (0x%04x).\n", magic);
  166. return -EINVAL;
  167. }
  168. }
  169. if (needs_byteswap) {
  170. if (ah->ah_flags & AH_NO_EEP_SWAP) {
  171. ath_info(common,
  172. "Ignoring endianness difference in EEPROM magic bytes.\n");
  173. } else {
  174. eepdata = (u16 *)(&ah->eeprom);
  175. for (i = 0; i < size; i++)
  176. eepdata[i] = swab16(eepdata[i]);
  177. }
  178. }
  179. if (ah->eep_ops->get_eepmisc(ah) & AR5416_EEPMISC_BIG_ENDIAN) {
  180. *swap_needed = true;
  181. ath_dbg(common, EEPROM,
  182. "Big Endian EEPROM detected according to EEPMISC register.\n");
  183. } else {
  184. *swap_needed = false;
  185. }
  186. return 0;
  187. }
  188. bool ath9k_hw_nvram_validate_checksum(struct ath_hw *ah, int size)
  189. {
  190. u32 i, sum = 0;
  191. u16 *eepdata = (u16 *)(&ah->eeprom);
  192. struct ath_common *common = ath9k_hw_common(ah);
  193. for (i = 0; i < size; i++)
  194. sum ^= eepdata[i];
  195. if (sum != 0xffff) {
  196. ath_err(common, "Bad EEPROM checksum 0x%x\n", sum);
  197. return false;
  198. }
  199. return true;
  200. }
  201. bool ath9k_hw_nvram_check_version(struct ath_hw *ah, int version, int minrev)
  202. {
  203. struct ath_common *common = ath9k_hw_common(ah);
  204. if (ah->eep_ops->get_eeprom_ver(ah) != version ||
  205. ah->eep_ops->get_eeprom_rev(ah) < minrev) {
  206. ath_err(common, "Bad EEPROM VER 0x%04x or REV 0x%04x\n",
  207. ah->eep_ops->get_eeprom_ver(ah),
  208. ah->eep_ops->get_eeprom_rev(ah));
  209. return false;
  210. }
  211. return true;
  212. }
  213. void ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList,
  214. u8 *pVpdList, u16 numIntercepts,
  215. u8 *pRetVpdList)
  216. {
  217. u16 i, k;
  218. u8 currPwr = pwrMin;
  219. u16 idxL = 0, idxR = 0;
  220. for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
  221. ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
  222. numIntercepts, &(idxL),
  223. &(idxR));
  224. if (idxR < 1)
  225. idxR = 1;
  226. if (idxL == numIntercepts - 1)
  227. idxL = (u16) (numIntercepts - 2);
  228. if (pPwrList[idxL] == pPwrList[idxR])
  229. k = pVpdList[idxL];
  230. else
  231. k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
  232. (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
  233. (pPwrList[idxR] - pPwrList[idxL]));
  234. pRetVpdList[i] = (u8) k;
  235. currPwr += 2;
  236. }
  237. }
  238. void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah,
  239. struct ath9k_channel *chan,
  240. struct cal_target_power_leg *powInfo,
  241. u16 numChannels,
  242. struct cal_target_power_leg *pNewPower,
  243. u16 numRates, bool isExtTarget)
  244. {
  245. struct chan_centers centers;
  246. u16 clo, chi;
  247. int i;
  248. int matchIndex = -1, lowIndex = -1;
  249. u16 freq;
  250. ath9k_hw_get_channel_centers(ah, chan, &centers);
  251. freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
  252. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
  253. IS_CHAN_2GHZ(chan))) {
  254. matchIndex = 0;
  255. } else {
  256. for (i = 0; (i < numChannels) &&
  257. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  258. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  259. IS_CHAN_2GHZ(chan))) {
  260. matchIndex = i;
  261. break;
  262. } else if (freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  263. IS_CHAN_2GHZ(chan)) && i > 0 &&
  264. freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  265. IS_CHAN_2GHZ(chan))) {
  266. lowIndex = i - 1;
  267. break;
  268. }
  269. }
  270. if ((matchIndex == -1) && (lowIndex == -1))
  271. matchIndex = i - 1;
  272. }
  273. if (matchIndex != -1) {
  274. *pNewPower = powInfo[matchIndex];
  275. } else {
  276. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  277. IS_CHAN_2GHZ(chan));
  278. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  279. IS_CHAN_2GHZ(chan));
  280. for (i = 0; i < numRates; i++) {
  281. pNewPower->tPow2x[i] =
  282. (u8)ath9k_hw_interpolate(freq, clo, chi,
  283. powInfo[lowIndex].tPow2x[i],
  284. powInfo[lowIndex + 1].tPow2x[i]);
  285. }
  286. }
  287. }
  288. void ath9k_hw_get_target_powers(struct ath_hw *ah,
  289. struct ath9k_channel *chan,
  290. struct cal_target_power_ht *powInfo,
  291. u16 numChannels,
  292. struct cal_target_power_ht *pNewPower,
  293. u16 numRates, bool isHt40Target)
  294. {
  295. struct chan_centers centers;
  296. u16 clo, chi;
  297. int i;
  298. int matchIndex = -1, lowIndex = -1;
  299. u16 freq;
  300. ath9k_hw_get_channel_centers(ah, chan, &centers);
  301. freq = isHt40Target ? centers.synth_center : centers.ctl_center;
  302. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
  303. matchIndex = 0;
  304. } else {
  305. for (i = 0; (i < numChannels) &&
  306. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  307. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  308. IS_CHAN_2GHZ(chan))) {
  309. matchIndex = i;
  310. break;
  311. } else
  312. if (freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  313. IS_CHAN_2GHZ(chan)) && i > 0 &&
  314. freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  315. IS_CHAN_2GHZ(chan))) {
  316. lowIndex = i - 1;
  317. break;
  318. }
  319. }
  320. if ((matchIndex == -1) && (lowIndex == -1))
  321. matchIndex = i - 1;
  322. }
  323. if (matchIndex != -1) {
  324. *pNewPower = powInfo[matchIndex];
  325. } else {
  326. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  327. IS_CHAN_2GHZ(chan));
  328. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  329. IS_CHAN_2GHZ(chan));
  330. for (i = 0; i < numRates; i++) {
  331. pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
  332. clo, chi,
  333. powInfo[lowIndex].tPow2x[i],
  334. powInfo[lowIndex + 1].tPow2x[i]);
  335. }
  336. }
  337. }
  338. u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower,
  339. bool is2GHz, int num_band_edges)
  340. {
  341. u16 twiceMaxEdgePower = MAX_RATE_POWER;
  342. int i;
  343. for (i = 0; (i < num_band_edges) &&
  344. (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  345. if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
  346. twiceMaxEdgePower = CTL_EDGE_TPOWER(pRdEdgesPower[i].ctl);
  347. break;
  348. } else if ((i > 0) &&
  349. (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
  350. is2GHz))) {
  351. if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
  352. is2GHz) < freq &&
  353. CTL_EDGE_FLAGS(pRdEdgesPower[i - 1].ctl)) {
  354. twiceMaxEdgePower =
  355. CTL_EDGE_TPOWER(pRdEdgesPower[i - 1].ctl);
  356. }
  357. break;
  358. }
  359. }
  360. return twiceMaxEdgePower;
  361. }
  362. u16 ath9k_hw_get_scaled_power(struct ath_hw *ah, u16 power_limit,
  363. u8 antenna_reduction)
  364. {
  365. u16 reduction = antenna_reduction;
  366. /*
  367. * Reduce scaled Power by number of chains active
  368. * to get the per chain tx power level.
  369. */
  370. switch (ar5416_get_ntxchains(ah->txchainmask)) {
  371. case 1:
  372. break;
  373. case 2:
  374. reduction += POWER_CORRECTION_FOR_TWO_CHAIN;
  375. break;
  376. case 3:
  377. reduction += POWER_CORRECTION_FOR_THREE_CHAIN;
  378. break;
  379. }
  380. if (power_limit > reduction)
  381. power_limit -= reduction;
  382. else
  383. power_limit = 0;
  384. return min_t(u16, power_limit, MAX_RATE_POWER);
  385. }
  386. void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah)
  387. {
  388. struct ath_common *common = ath9k_hw_common(ah);
  389. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  390. switch (ar5416_get_ntxchains(ah->txchainmask)) {
  391. case 1:
  392. break;
  393. case 2:
  394. regulatory->max_power_level += POWER_CORRECTION_FOR_TWO_CHAIN;
  395. break;
  396. case 3:
  397. regulatory->max_power_level += POWER_CORRECTION_FOR_THREE_CHAIN;
  398. break;
  399. default:
  400. ath_dbg(common, EEPROM, "Invalid chainmask configuration\n");
  401. break;
  402. }
  403. }
  404. void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hw *ah,
  405. struct ath9k_channel *chan,
  406. void *pRawDataSet,
  407. u8 *bChans, u16 availPiers,
  408. u16 tPdGainOverlap,
  409. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  410. u16 numXpdGains)
  411. {
  412. int i, j, k;
  413. int16_t ss;
  414. u16 idxL = 0, idxR = 0, numPiers;
  415. static u8 vpdTableL[AR5416_NUM_PD_GAINS]
  416. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  417. static u8 vpdTableR[AR5416_NUM_PD_GAINS]
  418. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  419. static u8 vpdTableI[AR5416_NUM_PD_GAINS]
  420. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  421. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  422. u8 minPwrT4[AR5416_NUM_PD_GAINS];
  423. u8 maxPwrT4[AR5416_NUM_PD_GAINS];
  424. int16_t vpdStep;
  425. int16_t tmpVal;
  426. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  427. bool match;
  428. int16_t minDelta = 0;
  429. struct chan_centers centers;
  430. int pdgain_boundary_default;
  431. struct cal_data_per_freq *data_def = pRawDataSet;
  432. struct cal_data_per_freq_4k *data_4k = pRawDataSet;
  433. struct cal_data_per_freq_ar9287 *data_9287 = pRawDataSet;
  434. bool eeprom_4k = AR_SREV_9285(ah) || AR_SREV_9271(ah);
  435. int intercepts;
  436. if (AR_SREV_9287(ah))
  437. intercepts = AR9287_PD_GAIN_ICEPTS;
  438. else
  439. intercepts = AR5416_PD_GAIN_ICEPTS;
  440. memset(&minPwrT4, 0, AR5416_NUM_PD_GAINS);
  441. ath9k_hw_get_channel_centers(ah, chan, &centers);
  442. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  443. if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
  444. break;
  445. }
  446. match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
  447. IS_CHAN_2GHZ(chan)),
  448. bChans, numPiers, &idxL, &idxR);
  449. if (match) {
  450. if (AR_SREV_9287(ah)) {
  451. for (i = 0; i < numXpdGains; i++) {
  452. minPwrT4[i] = data_9287[idxL].pwrPdg[i][0];
  453. maxPwrT4[i] = data_9287[idxL].pwrPdg[i][intercepts - 1];
  454. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  455. data_9287[idxL].pwrPdg[i],
  456. data_9287[idxL].vpdPdg[i],
  457. intercepts,
  458. vpdTableI[i]);
  459. }
  460. } else if (eeprom_4k) {
  461. for (i = 0; i < numXpdGains; i++) {
  462. minPwrT4[i] = data_4k[idxL].pwrPdg[i][0];
  463. maxPwrT4[i] = data_4k[idxL].pwrPdg[i][intercepts - 1];
  464. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  465. data_4k[idxL].pwrPdg[i],
  466. data_4k[idxL].vpdPdg[i],
  467. intercepts,
  468. vpdTableI[i]);
  469. }
  470. } else {
  471. for (i = 0; i < numXpdGains; i++) {
  472. minPwrT4[i] = data_def[idxL].pwrPdg[i][0];
  473. maxPwrT4[i] = data_def[idxL].pwrPdg[i][intercepts - 1];
  474. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  475. data_def[idxL].pwrPdg[i],
  476. data_def[idxL].vpdPdg[i],
  477. intercepts,
  478. vpdTableI[i]);
  479. }
  480. }
  481. } else {
  482. for (i = 0; i < numXpdGains; i++) {
  483. if (AR_SREV_9287(ah)) {
  484. pVpdL = data_9287[idxL].vpdPdg[i];
  485. pPwrL = data_9287[idxL].pwrPdg[i];
  486. pVpdR = data_9287[idxR].vpdPdg[i];
  487. pPwrR = data_9287[idxR].pwrPdg[i];
  488. } else if (eeprom_4k) {
  489. pVpdL = data_4k[idxL].vpdPdg[i];
  490. pPwrL = data_4k[idxL].pwrPdg[i];
  491. pVpdR = data_4k[idxR].vpdPdg[i];
  492. pPwrR = data_4k[idxR].pwrPdg[i];
  493. } else {
  494. pVpdL = data_def[idxL].vpdPdg[i];
  495. pPwrL = data_def[idxL].pwrPdg[i];
  496. pVpdR = data_def[idxR].vpdPdg[i];
  497. pPwrR = data_def[idxR].pwrPdg[i];
  498. }
  499. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  500. maxPwrT4[i] =
  501. min(pPwrL[intercepts - 1],
  502. pPwrR[intercepts - 1]);
  503. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  504. pPwrL, pVpdL,
  505. intercepts,
  506. vpdTableL[i]);
  507. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  508. pPwrR, pVpdR,
  509. intercepts,
  510. vpdTableR[i]);
  511. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  512. vpdTableI[i][j] =
  513. (u8)(ath9k_hw_interpolate((u16)
  514. FREQ2FBIN(centers.
  515. synth_center,
  516. IS_CHAN_2GHZ
  517. (chan)),
  518. bChans[idxL], bChans[idxR],
  519. vpdTableL[i][j], vpdTableR[i][j]));
  520. }
  521. }
  522. }
  523. k = 0;
  524. for (i = 0; i < numXpdGains; i++) {
  525. if (i == (numXpdGains - 1))
  526. pPdGainBoundaries[i] =
  527. (u16)(maxPwrT4[i] / 2);
  528. else
  529. pPdGainBoundaries[i] =
  530. (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
  531. pPdGainBoundaries[i] =
  532. min((u16)MAX_RATE_POWER, pPdGainBoundaries[i]);
  533. minDelta = 0;
  534. if (i == 0) {
  535. if (AR_SREV_9280_20_OR_LATER(ah))
  536. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  537. else
  538. ss = 0;
  539. } else {
  540. ss = (int16_t)((pPdGainBoundaries[i - 1] -
  541. (minPwrT4[i] / 2)) -
  542. tPdGainOverlap + 1 + minDelta);
  543. }
  544. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  545. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  546. while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  547. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  548. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  549. ss++;
  550. }
  551. sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  552. tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
  553. (minPwrT4[i] / 2));
  554. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  555. tgtIndex : sizeCurrVpdTable;
  556. while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  557. pPDADCValues[k++] = vpdTableI[i][ss++];
  558. }
  559. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  560. vpdTableI[i][sizeCurrVpdTable - 2]);
  561. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  562. if (tgtIndex >= maxIndex) {
  563. while ((ss <= tgtIndex) &&
  564. (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  565. tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
  566. (ss - maxIndex + 1) * vpdStep));
  567. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  568. 255 : tmpVal);
  569. ss++;
  570. }
  571. }
  572. }
  573. if (eeprom_4k)
  574. pdgain_boundary_default = 58;
  575. else
  576. pdgain_boundary_default = pPdGainBoundaries[i - 1];
  577. while (i < AR5416_PD_GAINS_IN_MASK) {
  578. pPdGainBoundaries[i] = pdgain_boundary_default;
  579. i++;
  580. }
  581. while (k < AR5416_NUM_PDADC_VALUES) {
  582. pPDADCValues[k] = pPDADCValues[k - 1];
  583. k++;
  584. }
  585. }
  586. int ath9k_hw_eeprom_init(struct ath_hw *ah)
  587. {
  588. if (AR_SREV_9300_20_OR_LATER(ah))
  589. ah->eep_ops = &eep_ar9300_ops;
  590. else if (AR_SREV_9287(ah)) {
  591. ah->eep_ops = &eep_ar9287_ops;
  592. } else if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
  593. ah->eep_ops = &eep_4k_ops;
  594. } else {
  595. ah->eep_ops = &eep_def_ops;
  596. }
  597. if (!ah->eep_ops->fill_eeprom(ah))
  598. return -EIO;
  599. return ah->eep_ops->check_eeprom(ah);
  600. }