You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath5k_eeprom.c 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  1. /*
  2. * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
  4. * Copyright (c) 2008-2009 Felix Fietkau <nbd@openwrt.org>
  5. *
  6. * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
  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. FILE_LICENCE ( MIT );
  22. /*************************************\
  23. * EEPROM access functions and helpers *
  24. \*************************************/
  25. #include <unistd.h>
  26. #include <stdlib.h>
  27. #include "ath5k.h"
  28. #include "reg.h"
  29. #include "base.h"
  30. /*
  31. * Read from eeprom
  32. */
  33. static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
  34. {
  35. u32 status, timeout;
  36. /*
  37. * Initialize EEPROM access
  38. */
  39. if (ah->ah_version == AR5K_AR5210) {
  40. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
  41. (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
  42. } else {
  43. ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
  44. AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
  45. AR5K_EEPROM_CMD_READ);
  46. }
  47. for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
  48. status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
  49. if (status & AR5K_EEPROM_STAT_RDDONE) {
  50. if (status & AR5K_EEPROM_STAT_RDERR)
  51. return -EIO;
  52. *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
  53. 0xffff);
  54. return 0;
  55. }
  56. udelay(15);
  57. }
  58. return -ETIMEDOUT;
  59. }
  60. /*
  61. * Translate binary channel representation in EEPROM to frequency
  62. */
  63. static u16 ath5k_eeprom_bin2freq(struct ath5k_eeprom_info *ee, u16 bin,
  64. unsigned int mode)
  65. {
  66. u16 val;
  67. if (bin == AR5K_EEPROM_CHANNEL_DIS)
  68. return bin;
  69. if (mode == AR5K_EEPROM_MODE_11A) {
  70. if (ee->ee_version > AR5K_EEPROM_VERSION_3_2)
  71. val = (5 * bin) + 4800;
  72. else
  73. val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
  74. (bin * 10) + 5100;
  75. } else {
  76. if (ee->ee_version > AR5K_EEPROM_VERSION_3_2)
  77. val = bin + 2300;
  78. else
  79. val = bin + 2400;
  80. }
  81. return val;
  82. }
  83. /*
  84. * Initialize eeprom & capabilities structs
  85. */
  86. static int
  87. ath5k_eeprom_init_header(struct ath5k_hw *ah)
  88. {
  89. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  90. int ret;
  91. u16 val;
  92. /*
  93. * Read values from EEPROM and store them in the capability structure
  94. */
  95. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
  96. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
  97. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
  98. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
  99. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
  100. /* Return if we have an old EEPROM */
  101. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
  102. return 0;
  103. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
  104. ee_ant_gain);
  105. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
  106. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
  107. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
  108. /* XXX: Don't know which versions include these two */
  109. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC2, ee_misc2);
  110. if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3)
  111. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC3, ee_misc3);
  112. if (ee->ee_version >= AR5K_EEPROM_VERSION_5_0) {
  113. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC4, ee_misc4);
  114. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC5, ee_misc5);
  115. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC6, ee_misc6);
  116. }
  117. }
  118. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
  119. AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
  120. ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
  121. ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
  122. AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
  123. ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
  124. ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
  125. }
  126. return 0;
  127. }
  128. /*
  129. * Read antenna infos from eeprom
  130. */
  131. static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
  132. unsigned int mode)
  133. {
  134. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  135. u32 o = *offset;
  136. u16 val;
  137. int ret, i = 0;
  138. AR5K_EEPROM_READ(o++, val);
  139. ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
  140. ee->ee_atn_tx_rx[mode] = (val >> 2) & 0x3f;
  141. ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
  142. AR5K_EEPROM_READ(o++, val);
  143. ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
  144. ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
  145. ee->ee_ant_control[mode][i++] = val & 0x3f;
  146. AR5K_EEPROM_READ(o++, val);
  147. ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
  148. ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
  149. ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
  150. AR5K_EEPROM_READ(o++, val);
  151. ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
  152. ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
  153. ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
  154. ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
  155. AR5K_EEPROM_READ(o++, val);
  156. ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
  157. ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
  158. ee->ee_ant_control[mode][i++] = val & 0x3f;
  159. /* Get antenna modes */
  160. ah->ah_antenna[mode][0] =
  161. (ee->ee_ant_control[mode][0] << 4);
  162. ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
  163. ee->ee_ant_control[mode][1] |
  164. (ee->ee_ant_control[mode][2] << 6) |
  165. (ee->ee_ant_control[mode][3] << 12) |
  166. (ee->ee_ant_control[mode][4] << 18) |
  167. (ee->ee_ant_control[mode][5] << 24);
  168. ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
  169. ee->ee_ant_control[mode][6] |
  170. (ee->ee_ant_control[mode][7] << 6) |
  171. (ee->ee_ant_control[mode][8] << 12) |
  172. (ee->ee_ant_control[mode][9] << 18) |
  173. (ee->ee_ant_control[mode][10] << 24);
  174. /* return new offset */
  175. *offset = o;
  176. return 0;
  177. }
  178. /*
  179. * Read supported modes and some mode-specific calibration data
  180. * from eeprom
  181. */
  182. static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
  183. unsigned int mode)
  184. {
  185. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  186. u32 o = *offset;
  187. u16 val;
  188. int ret;
  189. ee->ee_n_piers[mode] = 0;
  190. AR5K_EEPROM_READ(o++, val);
  191. ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
  192. switch(mode) {
  193. case AR5K_EEPROM_MODE_11A:
  194. ee->ee_ob[mode][3] = (val >> 5) & 0x7;
  195. ee->ee_db[mode][3] = (val >> 2) & 0x7;
  196. ee->ee_ob[mode][2] = (val << 1) & 0x7;
  197. AR5K_EEPROM_READ(o++, val);
  198. ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
  199. ee->ee_db[mode][2] = (val >> 12) & 0x7;
  200. ee->ee_ob[mode][1] = (val >> 9) & 0x7;
  201. ee->ee_db[mode][1] = (val >> 6) & 0x7;
  202. ee->ee_ob[mode][0] = (val >> 3) & 0x7;
  203. ee->ee_db[mode][0] = val & 0x7;
  204. break;
  205. case AR5K_EEPROM_MODE_11G:
  206. case AR5K_EEPROM_MODE_11B:
  207. ee->ee_ob[mode][1] = (val >> 4) & 0x7;
  208. ee->ee_db[mode][1] = val & 0x7;
  209. break;
  210. }
  211. AR5K_EEPROM_READ(o++, val);
  212. ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
  213. ee->ee_thr_62[mode] = val & 0xff;
  214. if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
  215. ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
  216. AR5K_EEPROM_READ(o++, val);
  217. ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
  218. ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
  219. AR5K_EEPROM_READ(o++, val);
  220. ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
  221. if ((val & 0xff) & 0x80)
  222. ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
  223. else
  224. ee->ee_noise_floor_thr[mode] = val & 0xff;
  225. if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
  226. ee->ee_noise_floor_thr[mode] =
  227. mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
  228. AR5K_EEPROM_READ(o++, val);
  229. ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
  230. ee->ee_x_gain[mode] = (val >> 1) & 0xf;
  231. ee->ee_xpd[mode] = val & 0x1;
  232. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
  233. ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
  234. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
  235. AR5K_EEPROM_READ(o++, val);
  236. ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
  237. if (mode == AR5K_EEPROM_MODE_11A)
  238. ee->ee_xr_power[mode] = val & 0x3f;
  239. else {
  240. ee->ee_ob[mode][0] = val & 0x7;
  241. ee->ee_db[mode][0] = (val >> 3) & 0x7;
  242. }
  243. }
  244. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
  245. ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
  246. ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
  247. } else {
  248. ee->ee_i_gain[mode] = (val >> 13) & 0x7;
  249. AR5K_EEPROM_READ(o++, val);
  250. ee->ee_i_gain[mode] |= (val << 3) & 0x38;
  251. if (mode == AR5K_EEPROM_MODE_11G) {
  252. ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
  253. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6)
  254. ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
  255. }
  256. }
  257. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
  258. mode == AR5K_EEPROM_MODE_11A) {
  259. ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
  260. ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
  261. }
  262. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_0)
  263. goto done;
  264. /* Note: >= v5 have bg freq piers on another location
  265. * so these freq piers are ignored for >= v5 (should be 0xff
  266. * anyway) */
  267. switch(mode) {
  268. case AR5K_EEPROM_MODE_11A:
  269. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_1)
  270. break;
  271. AR5K_EEPROM_READ(o++, val);
  272. ee->ee_margin_tx_rx[mode] = val & 0x3f;
  273. break;
  274. case AR5K_EEPROM_MODE_11B:
  275. AR5K_EEPROM_READ(o++, val);
  276. ee->ee_pwr_cal_b[0].freq =
  277. ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
  278. if (ee->ee_pwr_cal_b[0].freq != AR5K_EEPROM_CHANNEL_DIS)
  279. ee->ee_n_piers[mode]++;
  280. ee->ee_pwr_cal_b[1].freq =
  281. ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
  282. if (ee->ee_pwr_cal_b[1].freq != AR5K_EEPROM_CHANNEL_DIS)
  283. ee->ee_n_piers[mode]++;
  284. AR5K_EEPROM_READ(o++, val);
  285. ee->ee_pwr_cal_b[2].freq =
  286. ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
  287. if (ee->ee_pwr_cal_b[2].freq != AR5K_EEPROM_CHANNEL_DIS)
  288. ee->ee_n_piers[mode]++;
  289. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  290. ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
  291. break;
  292. case AR5K_EEPROM_MODE_11G:
  293. AR5K_EEPROM_READ(o++, val);
  294. ee->ee_pwr_cal_g[0].freq =
  295. ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
  296. if (ee->ee_pwr_cal_g[0].freq != AR5K_EEPROM_CHANNEL_DIS)
  297. ee->ee_n_piers[mode]++;
  298. ee->ee_pwr_cal_g[1].freq =
  299. ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
  300. if (ee->ee_pwr_cal_g[1].freq != AR5K_EEPROM_CHANNEL_DIS)
  301. ee->ee_n_piers[mode]++;
  302. AR5K_EEPROM_READ(o++, val);
  303. ee->ee_turbo_max_power[mode] = val & 0x7f;
  304. ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
  305. AR5K_EEPROM_READ(o++, val);
  306. ee->ee_pwr_cal_g[2].freq =
  307. ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
  308. if (ee->ee_pwr_cal_g[2].freq != AR5K_EEPROM_CHANNEL_DIS)
  309. ee->ee_n_piers[mode]++;
  310. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  311. ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
  312. AR5K_EEPROM_READ(o++, val);
  313. ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
  314. ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
  315. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
  316. AR5K_EEPROM_READ(o++, val);
  317. ee->ee_cck_ofdm_gain_delta = val & 0xff;
  318. }
  319. break;
  320. }
  321. done:
  322. /* return new offset */
  323. *offset = o;
  324. return 0;
  325. }
  326. /*
  327. * Read turbo mode information on newer EEPROM versions
  328. */
  329. static int
  330. ath5k_eeprom_read_turbo_modes(struct ath5k_hw *ah,
  331. u32 *offset, unsigned int mode)
  332. {
  333. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  334. u32 o = *offset;
  335. u16 val;
  336. int ret;
  337. if (ee->ee_version < AR5K_EEPROM_VERSION_5_0)
  338. return 0;
  339. switch (mode){
  340. case AR5K_EEPROM_MODE_11A:
  341. ee->ee_switch_settling_turbo[mode] = (val >> 6) & 0x7f;
  342. ee->ee_atn_tx_rx_turbo[mode] = (val >> 13) & 0x7;
  343. AR5K_EEPROM_READ(o++, val);
  344. ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x7) << 3;
  345. ee->ee_margin_tx_rx_turbo[mode] = (val >> 3) & 0x3f;
  346. ee->ee_adc_desired_size_turbo[mode] = (val >> 9) & 0x7f;
  347. AR5K_EEPROM_READ(o++, val);
  348. ee->ee_adc_desired_size_turbo[mode] |= (val & 0x1) << 7;
  349. ee->ee_pga_desired_size_turbo[mode] = (val >> 1) & 0xff;
  350. if (AR5K_EEPROM_EEMAP(ee->ee_misc0) >=2)
  351. ee->ee_pd_gain_overlap = (val >> 9) & 0xf;
  352. break;
  353. case AR5K_EEPROM_MODE_11G:
  354. ee->ee_switch_settling_turbo[mode] = (val >> 8) & 0x7f;
  355. ee->ee_atn_tx_rx_turbo[mode] = (val >> 15) & 0x7;
  356. AR5K_EEPROM_READ(o++, val);
  357. ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x1f) << 1;
  358. ee->ee_margin_tx_rx_turbo[mode] = (val >> 5) & 0x3f;
  359. ee->ee_adc_desired_size_turbo[mode] = (val >> 11) & 0x7f;
  360. AR5K_EEPROM_READ(o++, val);
  361. ee->ee_adc_desired_size_turbo[mode] |= (val & 0x7) << 5;
  362. ee->ee_pga_desired_size_turbo[mode] = (val >> 3) & 0xff;
  363. break;
  364. }
  365. /* return new offset */
  366. *offset = o;
  367. return 0;
  368. }
  369. /* Read mode-specific data (except power calibration data) */
  370. static int
  371. ath5k_eeprom_init_modes(struct ath5k_hw *ah)
  372. {
  373. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  374. u32 mode_offset[3];
  375. unsigned int mode;
  376. u32 offset;
  377. int ret;
  378. /*
  379. * Get values for all modes
  380. */
  381. mode_offset[AR5K_EEPROM_MODE_11A] = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
  382. mode_offset[AR5K_EEPROM_MODE_11B] = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
  383. mode_offset[AR5K_EEPROM_MODE_11G] = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
  384. ee->ee_turbo_max_power[AR5K_EEPROM_MODE_11A] =
  385. AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
  386. for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++) {
  387. offset = mode_offset[mode];
  388. ret = ath5k_eeprom_read_ants(ah, &offset, mode);
  389. if (ret)
  390. return ret;
  391. ret = ath5k_eeprom_read_modes(ah, &offset, mode);
  392. if (ret)
  393. return ret;
  394. ret = ath5k_eeprom_read_turbo_modes(ah, &offset, mode);
  395. if (ret)
  396. return ret;
  397. }
  398. /* override for older eeprom versions for better performance */
  399. if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2) {
  400. ee->ee_thr_62[AR5K_EEPROM_MODE_11A] = 15;
  401. ee->ee_thr_62[AR5K_EEPROM_MODE_11B] = 28;
  402. ee->ee_thr_62[AR5K_EEPROM_MODE_11G] = 28;
  403. }
  404. return 0;
  405. }
  406. /* Read the frequency piers for each mode (mostly used on newer eeproms with 0xff
  407. * frequency mask) */
  408. static inline int
  409. ath5k_eeprom_read_freq_list(struct ath5k_hw *ah, int *offset, int max,
  410. struct ath5k_chan_pcal_info *pc, unsigned int mode)
  411. {
  412. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  413. int o = *offset;
  414. int i = 0;
  415. u8 freq1, freq2;
  416. int ret;
  417. u16 val;
  418. ee->ee_n_piers[mode] = 0;
  419. while(i < max) {
  420. AR5K_EEPROM_READ(o++, val);
  421. freq1 = val & 0xff;
  422. if (!freq1)
  423. break;
  424. pc[i++].freq = ath5k_eeprom_bin2freq(ee,
  425. freq1, mode);
  426. ee->ee_n_piers[mode]++;
  427. freq2 = (val >> 8) & 0xff;
  428. if (!freq2)
  429. break;
  430. pc[i++].freq = ath5k_eeprom_bin2freq(ee,
  431. freq2, mode);
  432. ee->ee_n_piers[mode]++;
  433. }
  434. /* return new offset */
  435. *offset = o;
  436. return 0;
  437. }
  438. /* Read frequency piers for 802.11a */
  439. static int
  440. ath5k_eeprom_init_11a_pcal_freq(struct ath5k_hw *ah, int offset)
  441. {
  442. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  443. struct ath5k_chan_pcal_info *pcal = ee->ee_pwr_cal_a;
  444. int i, ret;
  445. u16 val;
  446. u8 mask;
  447. if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
  448. ath5k_eeprom_read_freq_list(ah, &offset,
  449. AR5K_EEPROM_N_5GHZ_CHAN, pcal,
  450. AR5K_EEPROM_MODE_11A);
  451. } else {
  452. mask = AR5K_EEPROM_FREQ_M(ah->ah_ee_version);
  453. AR5K_EEPROM_READ(offset++, val);
  454. pcal[0].freq = (val >> 9) & mask;
  455. pcal[1].freq = (val >> 2) & mask;
  456. pcal[2].freq = (val << 5) & mask;
  457. AR5K_EEPROM_READ(offset++, val);
  458. pcal[2].freq |= (val >> 11) & 0x1f;
  459. pcal[3].freq = (val >> 4) & mask;
  460. pcal[4].freq = (val << 3) & mask;
  461. AR5K_EEPROM_READ(offset++, val);
  462. pcal[4].freq |= (val >> 13) & 0x7;
  463. pcal[5].freq = (val >> 6) & mask;
  464. pcal[6].freq = (val << 1) & mask;
  465. AR5K_EEPROM_READ(offset++, val);
  466. pcal[6].freq |= (val >> 15) & 0x1;
  467. pcal[7].freq = (val >> 8) & mask;
  468. pcal[8].freq = (val >> 1) & mask;
  469. pcal[9].freq = (val << 6) & mask;
  470. AR5K_EEPROM_READ(offset++, val);
  471. pcal[9].freq |= (val >> 10) & 0x3f;
  472. /* Fixed number of piers */
  473. ee->ee_n_piers[AR5K_EEPROM_MODE_11A] = 10;
  474. for (i = 0; i < AR5K_EEPROM_N_5GHZ_CHAN; i++) {
  475. pcal[i].freq = ath5k_eeprom_bin2freq(ee,
  476. pcal[i].freq, AR5K_EEPROM_MODE_11A);
  477. }
  478. }
  479. return 0;
  480. }
  481. /* Read frequency piers for 802.11bg on eeprom versions >= 5 and eemap >= 2 */
  482. static inline int
  483. ath5k_eeprom_init_11bg_2413(struct ath5k_hw *ah, unsigned int mode, int offset)
  484. {
  485. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  486. struct ath5k_chan_pcal_info *pcal;
  487. switch(mode) {
  488. case AR5K_EEPROM_MODE_11B:
  489. pcal = ee->ee_pwr_cal_b;
  490. break;
  491. case AR5K_EEPROM_MODE_11G:
  492. pcal = ee->ee_pwr_cal_g;
  493. break;
  494. default:
  495. return -EINVAL;
  496. }
  497. ath5k_eeprom_read_freq_list(ah, &offset,
  498. AR5K_EEPROM_N_2GHZ_CHAN_2413, pcal,
  499. mode);
  500. return 0;
  501. }
  502. /*
  503. * Read power calibration for RF5111 chips
  504. *
  505. * For RF5111 we have an XPD -eXternal Power Detector- curve
  506. * for each calibrated channel. Each curve has 0,5dB Power steps
  507. * on x axis and PCDAC steps (offsets) on y axis and looks like an
  508. * exponential function. To recreate the curve we read 11 points
  509. * here and interpolate later.
  510. */
  511. /* Used to match PCDAC steps with power values on RF5111 chips
  512. * (eeprom versions < 4). For RF5111 we have 11 pre-defined PCDAC
  513. * steps that match with the power values we read from eeprom. On
  514. * older eeprom versions (< 3.2) these steps are equaly spaced at
  515. * 10% of the pcdac curve -until the curve reaches it's maximum-
  516. * (11 steps from 0 to 100%) but on newer eeprom versions (>= 3.2)
  517. * these 11 steps are spaced in a different way. This function returns
  518. * the pcdac steps based on eeprom version and curve min/max so that we
  519. * can have pcdac/pwr points.
  520. */
  521. static inline void
  522. ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp)
  523. {
  524. static const u16 intercepts3[] =
  525. { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 };
  526. static const u16 intercepts3_2[] =
  527. { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
  528. const u16 *ip;
  529. unsigned i;
  530. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_2)
  531. ip = intercepts3_2;
  532. else
  533. ip = intercepts3;
  534. for (i = 0; i < ARRAY_SIZE(intercepts3); i++)
  535. vp[i] = (ip[i] * max + (100 - ip[i]) * min) / 100;
  536. }
  537. /* Convert RF5111 specific data to generic raw data
  538. * used by interpolation code */
  539. static int
  540. ath5k_eeprom_convert_pcal_info_5111(struct ath5k_hw *ah, int mode,
  541. struct ath5k_chan_pcal_info *chinfo)
  542. {
  543. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  544. struct ath5k_chan_pcal_info_rf5111 *pcinfo;
  545. struct ath5k_pdgain_info *pd;
  546. u8 pier, point, idx;
  547. u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
  548. /* Fill raw data for each calibration pier */
  549. for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
  550. pcinfo = &chinfo[pier].rf5111_info;
  551. /* Allocate pd_curves for this cal pier */
  552. chinfo[pier].pd_curves =
  553. calloc(AR5K_EEPROM_N_PD_CURVES,
  554. sizeof(struct ath5k_pdgain_info));
  555. if (!chinfo[pier].pd_curves)
  556. return -ENOMEM;
  557. /* Only one curve for RF5111
  558. * find out which one and place
  559. * in in pd_curves.
  560. * Note: ee_x_gain is reversed here */
  561. for (idx = 0; idx < AR5K_EEPROM_N_PD_CURVES; idx++) {
  562. if (!((ee->ee_x_gain[mode] >> idx) & 0x1)) {
  563. pdgain_idx[0] = idx;
  564. break;
  565. }
  566. }
  567. ee->ee_pd_gains[mode] = 1;
  568. pd = &chinfo[pier].pd_curves[idx];
  569. pd->pd_points = AR5K_EEPROM_N_PWR_POINTS_5111;
  570. /* Allocate pd points for this curve */
  571. pd->pd_step = calloc(AR5K_EEPROM_N_PWR_POINTS_5111, sizeof(u8));
  572. if (!pd->pd_step)
  573. return -ENOMEM;
  574. pd->pd_pwr = calloc(AR5K_EEPROM_N_PWR_POINTS_5111, sizeof(s16));
  575. if (!pd->pd_pwr)
  576. return -ENOMEM;
  577. /* Fill raw dataset
  578. * (convert power to 0.25dB units
  579. * for RF5112 combatibility) */
  580. for (point = 0; point < pd->pd_points; point++) {
  581. /* Absolute values */
  582. pd->pd_pwr[point] = 2 * pcinfo->pwr[point];
  583. /* Already sorted */
  584. pd->pd_step[point] = pcinfo->pcdac[point];
  585. }
  586. /* Set min/max pwr */
  587. chinfo[pier].min_pwr = pd->pd_pwr[0];
  588. chinfo[pier].max_pwr = pd->pd_pwr[10];
  589. }
  590. return 0;
  591. }
  592. /* Parse EEPROM data */
  593. static int
  594. ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode)
  595. {
  596. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  597. struct ath5k_chan_pcal_info *pcal;
  598. int offset, ret;
  599. int i;
  600. u16 val;
  601. offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
  602. switch(mode) {
  603. case AR5K_EEPROM_MODE_11A:
  604. if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
  605. return 0;
  606. ret = ath5k_eeprom_init_11a_pcal_freq(ah,
  607. offset + AR5K_EEPROM_GROUP1_OFFSET);
  608. if (ret < 0)
  609. return ret;
  610. offset += AR5K_EEPROM_GROUP2_OFFSET;
  611. pcal = ee->ee_pwr_cal_a;
  612. break;
  613. case AR5K_EEPROM_MODE_11B:
  614. if (!AR5K_EEPROM_HDR_11B(ee->ee_header) &&
  615. !AR5K_EEPROM_HDR_11G(ee->ee_header))
  616. return 0;
  617. pcal = ee->ee_pwr_cal_b;
  618. offset += AR5K_EEPROM_GROUP3_OFFSET;
  619. /* fixed piers */
  620. pcal[0].freq = 2412;
  621. pcal[1].freq = 2447;
  622. pcal[2].freq = 2484;
  623. ee->ee_n_piers[mode] = 3;
  624. break;
  625. case AR5K_EEPROM_MODE_11G:
  626. if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
  627. return 0;
  628. pcal = ee->ee_pwr_cal_g;
  629. offset += AR5K_EEPROM_GROUP4_OFFSET;
  630. /* fixed piers */
  631. pcal[0].freq = 2312;
  632. pcal[1].freq = 2412;
  633. pcal[2].freq = 2484;
  634. ee->ee_n_piers[mode] = 3;
  635. break;
  636. default:
  637. return -EINVAL;
  638. }
  639. for (i = 0; i < ee->ee_n_piers[mode]; i++) {
  640. struct ath5k_chan_pcal_info_rf5111 *cdata =
  641. &pcal[i].rf5111_info;
  642. AR5K_EEPROM_READ(offset++, val);
  643. cdata->pcdac_max = ((val >> 10) & AR5K_EEPROM_PCDAC_M);
  644. cdata->pcdac_min = ((val >> 4) & AR5K_EEPROM_PCDAC_M);
  645. cdata->pwr[0] = ((val << 2) & AR5K_EEPROM_POWER_M);
  646. AR5K_EEPROM_READ(offset++, val);
  647. cdata->pwr[0] |= ((val >> 14) & 0x3);
  648. cdata->pwr[1] = ((val >> 8) & AR5K_EEPROM_POWER_M);
  649. cdata->pwr[2] = ((val >> 2) & AR5K_EEPROM_POWER_M);
  650. cdata->pwr[3] = ((val << 4) & AR5K_EEPROM_POWER_M);
  651. AR5K_EEPROM_READ(offset++, val);
  652. cdata->pwr[3] |= ((val >> 12) & 0xf);
  653. cdata->pwr[4] = ((val >> 6) & AR5K_EEPROM_POWER_M);
  654. cdata->pwr[5] = (val & AR5K_EEPROM_POWER_M);
  655. AR5K_EEPROM_READ(offset++, val);
  656. cdata->pwr[6] = ((val >> 10) & AR5K_EEPROM_POWER_M);
  657. cdata->pwr[7] = ((val >> 4) & AR5K_EEPROM_POWER_M);
  658. cdata->pwr[8] = ((val << 2) & AR5K_EEPROM_POWER_M);
  659. AR5K_EEPROM_READ(offset++, val);
  660. cdata->pwr[8] |= ((val >> 14) & 0x3);
  661. cdata->pwr[9] = ((val >> 8) & AR5K_EEPROM_POWER_M);
  662. cdata->pwr[10] = ((val >> 2) & AR5K_EEPROM_POWER_M);
  663. ath5k_get_pcdac_intercepts(ah, cdata->pcdac_min,
  664. cdata->pcdac_max, cdata->pcdac);
  665. }
  666. return ath5k_eeprom_convert_pcal_info_5111(ah, mode, pcal);
  667. }
  668. /*
  669. * Read power calibration for RF5112 chips
  670. *
  671. * For RF5112 we have 4 XPD -eXternal Power Detector- curves
  672. * for each calibrated channel on 0, -6, -12 and -18dbm but we only
  673. * use the higher (3) and the lower (0) curves. Each curve has 0.5dB
  674. * power steps on x axis and PCDAC steps on y axis and looks like a
  675. * linear function. To recreate the curve and pass the power values
  676. * on hw, we read 4 points for xpd 0 (lower gain -> max power)
  677. * and 3 points for xpd 3 (higher gain -> lower power) here and
  678. * interpolate later.
  679. *
  680. * Note: Many vendors just use xpd 0 so xpd 3 is zeroed.
  681. */
  682. /* Convert RF5112 specific data to generic raw data
  683. * used by interpolation code */
  684. static int
  685. ath5k_eeprom_convert_pcal_info_5112(struct ath5k_hw *ah, int mode,
  686. struct ath5k_chan_pcal_info *chinfo)
  687. {
  688. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  689. struct ath5k_chan_pcal_info_rf5112 *pcinfo;
  690. u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
  691. unsigned int pier, pdg, point;
  692. /* Fill raw data for each calibration pier */
  693. for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
  694. pcinfo = &chinfo[pier].rf5112_info;
  695. /* Allocate pd_curves for this cal pier */
  696. chinfo[pier].pd_curves =
  697. calloc(AR5K_EEPROM_N_PD_CURVES,
  698. sizeof(struct ath5k_pdgain_info));
  699. if (!chinfo[pier].pd_curves)
  700. return -ENOMEM;
  701. /* Fill pd_curves */
  702. for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
  703. u8 idx = pdgain_idx[pdg];
  704. struct ath5k_pdgain_info *pd =
  705. &chinfo[pier].pd_curves[idx];
  706. /* Lowest gain curve (max power) */
  707. if (pdg == 0) {
  708. /* One more point for better accuracy */
  709. pd->pd_points = AR5K_EEPROM_N_XPD0_POINTS;
  710. /* Allocate pd points for this curve */
  711. pd->pd_step = calloc(pd->pd_points, sizeof(u8));
  712. if (!pd->pd_step)
  713. return -ENOMEM;
  714. pd->pd_pwr = calloc(pd->pd_points, sizeof(s16));
  715. if (!pd->pd_pwr)
  716. return -ENOMEM;
  717. /* Fill raw dataset
  718. * (all power levels are in 0.25dB units) */
  719. pd->pd_step[0] = pcinfo->pcdac_x0[0];
  720. pd->pd_pwr[0] = pcinfo->pwr_x0[0];
  721. for (point = 1; point < pd->pd_points;
  722. point++) {
  723. /* Absolute values */
  724. pd->pd_pwr[point] =
  725. pcinfo->pwr_x0[point];
  726. /* Deltas */
  727. pd->pd_step[point] =
  728. pd->pd_step[point - 1] +
  729. pcinfo->pcdac_x0[point];
  730. }
  731. /* Set min power for this frequency */
  732. chinfo[pier].min_pwr = pd->pd_pwr[0];
  733. /* Highest gain curve (min power) */
  734. } else if (pdg == 1) {
  735. pd->pd_points = AR5K_EEPROM_N_XPD3_POINTS;
  736. /* Allocate pd points for this curve */
  737. pd->pd_step = calloc(pd->pd_points, sizeof(u8));
  738. if (!pd->pd_step)
  739. return -ENOMEM;
  740. pd->pd_pwr = calloc(pd->pd_points, sizeof(s16));
  741. if (!pd->pd_pwr)
  742. return -ENOMEM;
  743. /* Fill raw dataset
  744. * (all power levels are in 0.25dB units) */
  745. for (point = 0; point < pd->pd_points;
  746. point++) {
  747. /* Absolute values */
  748. pd->pd_pwr[point] =
  749. pcinfo->pwr_x3[point];
  750. /* Fixed points */
  751. pd->pd_step[point] =
  752. pcinfo->pcdac_x3[point];
  753. }
  754. /* Since we have a higher gain curve
  755. * override min power */
  756. chinfo[pier].min_pwr = pd->pd_pwr[0];
  757. }
  758. }
  759. }
  760. return 0;
  761. }
  762. /* Parse EEPROM data */
  763. static int
  764. ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode)
  765. {
  766. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  767. struct ath5k_chan_pcal_info_rf5112 *chan_pcal_info;
  768. struct ath5k_chan_pcal_info *gen_chan_info;
  769. u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
  770. u32 offset;
  771. u8 i, c;
  772. u16 val;
  773. int ret;
  774. u8 pd_gains = 0;
  775. /* Count how many curves we have and
  776. * identify them (which one of the 4
  777. * available curves we have on each count).
  778. * Curves are stored from lower (x0) to
  779. * higher (x3) gain */
  780. for (i = 0; i < AR5K_EEPROM_N_PD_CURVES; i++) {
  781. /* ee_x_gain[mode] is x gain mask */
  782. if ((ee->ee_x_gain[mode] >> i) & 0x1)
  783. pdgain_idx[pd_gains++] = i;
  784. }
  785. ee->ee_pd_gains[mode] = pd_gains;
  786. if (pd_gains == 0 || pd_gains > 2)
  787. return -EINVAL;
  788. switch (mode) {
  789. case AR5K_EEPROM_MODE_11A:
  790. /*
  791. * Read 5GHz EEPROM channels
  792. */
  793. offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
  794. ath5k_eeprom_init_11a_pcal_freq(ah, offset);
  795. offset += AR5K_EEPROM_GROUP2_OFFSET;
  796. gen_chan_info = ee->ee_pwr_cal_a;
  797. break;
  798. case AR5K_EEPROM_MODE_11B:
  799. offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
  800. if (AR5K_EEPROM_HDR_11A(ee->ee_header))
  801. offset += AR5K_EEPROM_GROUP3_OFFSET;
  802. /* NB: frequency piers parsed during mode init */
  803. gen_chan_info = ee->ee_pwr_cal_b;
  804. break;
  805. case AR5K_EEPROM_MODE_11G:
  806. offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
  807. if (AR5K_EEPROM_HDR_11A(ee->ee_header))
  808. offset += AR5K_EEPROM_GROUP4_OFFSET;
  809. else if (AR5K_EEPROM_HDR_11B(ee->ee_header))
  810. offset += AR5K_EEPROM_GROUP2_OFFSET;
  811. /* NB: frequency piers parsed during mode init */
  812. gen_chan_info = ee->ee_pwr_cal_g;
  813. break;
  814. default:
  815. return -EINVAL;
  816. }
  817. for (i = 0; i < ee->ee_n_piers[mode]; i++) {
  818. chan_pcal_info = &gen_chan_info[i].rf5112_info;
  819. /* Power values in quarter dB
  820. * for the lower xpd gain curve
  821. * (0 dBm -> higher output power) */
  822. for (c = 0; c < AR5K_EEPROM_N_XPD0_POINTS; c++) {
  823. AR5K_EEPROM_READ(offset++, val);
  824. chan_pcal_info->pwr_x0[c] = (s8) (val & 0xff);
  825. chan_pcal_info->pwr_x0[++c] = (s8) ((val >> 8) & 0xff);
  826. }
  827. /* PCDAC steps
  828. * corresponding to the above power
  829. * measurements */
  830. AR5K_EEPROM_READ(offset++, val);
  831. chan_pcal_info->pcdac_x0[1] = (val & 0x1f);
  832. chan_pcal_info->pcdac_x0[2] = ((val >> 5) & 0x1f);
  833. chan_pcal_info->pcdac_x0[3] = ((val >> 10) & 0x1f);
  834. /* Power values in quarter dB
  835. * for the higher xpd gain curve
  836. * (18 dBm -> lower output power) */
  837. AR5K_EEPROM_READ(offset++, val);
  838. chan_pcal_info->pwr_x3[0] = (s8) (val & 0xff);
  839. chan_pcal_info->pwr_x3[1] = (s8) ((val >> 8) & 0xff);
  840. AR5K_EEPROM_READ(offset++, val);
  841. chan_pcal_info->pwr_x3[2] = (val & 0xff);
  842. /* PCDAC steps
  843. * corresponding to the above power
  844. * measurements (fixed) */
  845. chan_pcal_info->pcdac_x3[0] = 20;
  846. chan_pcal_info->pcdac_x3[1] = 35;
  847. chan_pcal_info->pcdac_x3[2] = 63;
  848. if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) {
  849. chan_pcal_info->pcdac_x0[0] = ((val >> 8) & 0x3f);
  850. /* Last xpd0 power level is also channel maximum */
  851. gen_chan_info[i].max_pwr = chan_pcal_info->pwr_x0[3];
  852. } else {
  853. chan_pcal_info->pcdac_x0[0] = 1;
  854. gen_chan_info[i].max_pwr = (s8) ((val >> 8) & 0xff);
  855. }
  856. }
  857. return ath5k_eeprom_convert_pcal_info_5112(ah, mode, gen_chan_info);
  858. }
  859. /*
  860. * Read power calibration for RF2413 chips
  861. *
  862. * For RF2413 we have a Power to PDDAC table (Power Detector)
  863. * instead of a PCDAC and 4 pd gain curves for each calibrated channel.
  864. * Each curve has power on x axis in 0.5 db steps and PDDADC steps on y
  865. * axis and looks like an exponential function like the RF5111 curve.
  866. *
  867. * To recreate the curves we read here the points and interpolate
  868. * later. Note that in most cases only 2 (higher and lower) curves are
  869. * used (like RF5112) but vendors have the oportunity to include all
  870. * 4 curves on eeprom. The final curve (higher power) has an extra
  871. * point for better accuracy like RF5112.
  872. */
  873. /* For RF2413 power calibration data doesn't start on a fixed location and
  874. * if a mode is not supported, it's section is missing -not zeroed-.
  875. * So we need to calculate the starting offset for each section by using
  876. * these two functions */
  877. /* Return the size of each section based on the mode and the number of pd
  878. * gains available (maximum 4). */
  879. static inline unsigned int
  880. ath5k_pdgains_size_2413(struct ath5k_eeprom_info *ee, unsigned int mode)
  881. {
  882. static const unsigned int pdgains_size[] = { 4, 6, 9, 12 };
  883. unsigned int sz;
  884. sz = pdgains_size[ee->ee_pd_gains[mode] - 1];
  885. sz *= ee->ee_n_piers[mode];
  886. return sz;
  887. }
  888. /* Return the starting offset for a section based on the modes supported
  889. * and each section's size. */
  890. static unsigned int
  891. ath5k_cal_data_offset_2413(struct ath5k_eeprom_info *ee, int mode)
  892. {
  893. u32 offset = AR5K_EEPROM_CAL_DATA_START(ee->ee_misc4);
  894. switch(mode) {
  895. case AR5K_EEPROM_MODE_11G:
  896. if (AR5K_EEPROM_HDR_11B(ee->ee_header))
  897. offset += ath5k_pdgains_size_2413(ee,
  898. AR5K_EEPROM_MODE_11B) +
  899. AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
  900. /* fall through */
  901. case AR5K_EEPROM_MODE_11B:
  902. if (AR5K_EEPROM_HDR_11A(ee->ee_header))
  903. offset += ath5k_pdgains_size_2413(ee,
  904. AR5K_EEPROM_MODE_11A) +
  905. AR5K_EEPROM_N_5GHZ_CHAN / 2;
  906. /* fall through */
  907. case AR5K_EEPROM_MODE_11A:
  908. break;
  909. default:
  910. break;
  911. }
  912. return offset;
  913. }
  914. /* Convert RF2413 specific data to generic raw data
  915. * used by interpolation code */
  916. static int
  917. ath5k_eeprom_convert_pcal_info_2413(struct ath5k_hw *ah, int mode,
  918. struct ath5k_chan_pcal_info *chinfo)
  919. {
  920. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  921. struct ath5k_chan_pcal_info_rf2413 *pcinfo;
  922. u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
  923. unsigned int pier, point;
  924. int pdg;
  925. /* Fill raw data for each calibration pier */
  926. for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
  927. pcinfo = &chinfo[pier].rf2413_info;
  928. /* Allocate pd_curves for this cal pier */
  929. chinfo[pier].pd_curves =
  930. calloc(AR5K_EEPROM_N_PD_CURVES,
  931. sizeof(struct ath5k_pdgain_info));
  932. if (!chinfo[pier].pd_curves)
  933. return -ENOMEM;
  934. /* Fill pd_curves */
  935. for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
  936. u8 idx = pdgain_idx[pdg];
  937. struct ath5k_pdgain_info *pd =
  938. &chinfo[pier].pd_curves[idx];
  939. /* One more point for the highest power
  940. * curve (lowest gain) */
  941. if (pdg == ee->ee_pd_gains[mode] - 1)
  942. pd->pd_points = AR5K_EEPROM_N_PD_POINTS;
  943. else
  944. pd->pd_points = AR5K_EEPROM_N_PD_POINTS - 1;
  945. /* Allocate pd points for this curve */
  946. pd->pd_step = calloc(pd->pd_points, sizeof(u8));
  947. if (!pd->pd_step)
  948. return -ENOMEM;
  949. pd->pd_pwr = calloc(pd->pd_points, sizeof(s16));
  950. if (!pd->pd_pwr)
  951. return -ENOMEM;
  952. /* Fill raw dataset
  953. * convert all pwr levels to
  954. * quarter dB for RF5112 combatibility */
  955. pd->pd_step[0] = pcinfo->pddac_i[pdg];
  956. pd->pd_pwr[0] = 4 * pcinfo->pwr_i[pdg];
  957. for (point = 1; point < pd->pd_points; point++) {
  958. pd->pd_pwr[point] = pd->pd_pwr[point - 1] +
  959. 2 * pcinfo->pwr[pdg][point - 1];
  960. pd->pd_step[point] = pd->pd_step[point - 1] +
  961. pcinfo->pddac[pdg][point - 1];
  962. }
  963. /* Highest gain curve -> min power */
  964. if (pdg == 0)
  965. chinfo[pier].min_pwr = pd->pd_pwr[0];
  966. /* Lowest gain curve -> max power */
  967. if (pdg == ee->ee_pd_gains[mode] - 1)
  968. chinfo[pier].max_pwr =
  969. pd->pd_pwr[pd->pd_points - 1];
  970. }
  971. }
  972. return 0;
  973. }
  974. /* Parse EEPROM data */
  975. static int
  976. ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode)
  977. {
  978. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  979. struct ath5k_chan_pcal_info_rf2413 *pcinfo;
  980. struct ath5k_chan_pcal_info *chinfo;
  981. u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
  982. u32 offset;
  983. int idx, i, ret;
  984. u16 val;
  985. u8 pd_gains = 0;
  986. /* Count how many curves we have and
  987. * identify them (which one of the 4
  988. * available curves we have on each count).
  989. * Curves are stored from higher to
  990. * lower gain so we go backwards */
  991. for (idx = AR5K_EEPROM_N_PD_CURVES - 1; idx >= 0; idx--) {
  992. /* ee_x_gain[mode] is x gain mask */
  993. if ((ee->ee_x_gain[mode] >> idx) & 0x1)
  994. pdgain_idx[pd_gains++] = idx;
  995. }
  996. ee->ee_pd_gains[mode] = pd_gains;
  997. if (pd_gains == 0)
  998. return -EINVAL;
  999. offset = ath5k_cal_data_offset_2413(ee, mode);
  1000. switch (mode) {
  1001. case AR5K_EEPROM_MODE_11A:
  1002. if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
  1003. return 0;
  1004. ath5k_eeprom_init_11a_pcal_freq(ah, offset);
  1005. offset += AR5K_EEPROM_N_5GHZ_CHAN / 2;
  1006. chinfo = ee->ee_pwr_cal_a;
  1007. break;
  1008. case AR5K_EEPROM_MODE_11B:
  1009. if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
  1010. return 0;
  1011. ath5k_eeprom_init_11bg_2413(ah, mode, offset);
  1012. offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
  1013. chinfo = ee->ee_pwr_cal_b;
  1014. break;
  1015. case AR5K_EEPROM_MODE_11G:
  1016. if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
  1017. return 0;
  1018. ath5k_eeprom_init_11bg_2413(ah, mode, offset);
  1019. offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
  1020. chinfo = ee->ee_pwr_cal_g;
  1021. break;
  1022. default:
  1023. return -EINVAL;
  1024. }
  1025. for (i = 0; i < ee->ee_n_piers[mode]; i++) {
  1026. pcinfo = &chinfo[i].rf2413_info;
  1027. /*
  1028. * Read pwr_i, pddac_i and the first
  1029. * 2 pd points (pwr, pddac)
  1030. */
  1031. AR5K_EEPROM_READ(offset++, val);
  1032. pcinfo->pwr_i[0] = val & 0x1f;
  1033. pcinfo->pddac_i[0] = (val >> 5) & 0x7f;
  1034. pcinfo->pwr[0][0] = (val >> 12) & 0xf;
  1035. AR5K_EEPROM_READ(offset++, val);
  1036. pcinfo->pddac[0][0] = val & 0x3f;
  1037. pcinfo->pwr[0][1] = (val >> 6) & 0xf;
  1038. pcinfo->pddac[0][1] = (val >> 10) & 0x3f;
  1039. AR5K_EEPROM_READ(offset++, val);
  1040. pcinfo->pwr[0][2] = val & 0xf;
  1041. pcinfo->pddac[0][2] = (val >> 4) & 0x3f;
  1042. pcinfo->pwr[0][3] = 0;
  1043. pcinfo->pddac[0][3] = 0;
  1044. if (pd_gains > 1) {
  1045. /*
  1046. * Pd gain 0 is not the last pd gain
  1047. * so it only has 2 pd points.
  1048. * Continue wih pd gain 1.
  1049. */
  1050. pcinfo->pwr_i[1] = (val >> 10) & 0x1f;
  1051. pcinfo->pddac_i[1] = (val >> 15) & 0x1;
  1052. AR5K_EEPROM_READ(offset++, val);
  1053. pcinfo->pddac_i[1] |= (val & 0x3F) << 1;
  1054. pcinfo->pwr[1][0] = (val >> 6) & 0xf;
  1055. pcinfo->pddac[1][0] = (val >> 10) & 0x3f;
  1056. AR5K_EEPROM_READ(offset++, val);
  1057. pcinfo->pwr[1][1] = val & 0xf;
  1058. pcinfo->pddac[1][1] = (val >> 4) & 0x3f;
  1059. pcinfo->pwr[1][2] = (val >> 10) & 0xf;
  1060. pcinfo->pddac[1][2] = (val >> 14) & 0x3;
  1061. AR5K_EEPROM_READ(offset++, val);
  1062. pcinfo->pddac[1][2] |= (val & 0xF) << 2;
  1063. pcinfo->pwr[1][3] = 0;
  1064. pcinfo->pddac[1][3] = 0;
  1065. } else if (pd_gains == 1) {
  1066. /*
  1067. * Pd gain 0 is the last one so
  1068. * read the extra point.
  1069. */
  1070. pcinfo->pwr[0][3] = (val >> 10) & 0xf;
  1071. pcinfo->pddac[0][3] = (val >> 14) & 0x3;
  1072. AR5K_EEPROM_READ(offset++, val);
  1073. pcinfo->pddac[0][3] |= (val & 0xF) << 2;
  1074. }
  1075. /*
  1076. * Proceed with the other pd_gains
  1077. * as above.
  1078. */
  1079. if (pd_gains > 2) {
  1080. pcinfo->pwr_i[2] = (val >> 4) & 0x1f;
  1081. pcinfo->pddac_i[2] = (val >> 9) & 0x7f;
  1082. AR5K_EEPROM_READ(offset++, val);
  1083. pcinfo->pwr[2][0] = (val >> 0) & 0xf;
  1084. pcinfo->pddac[2][0] = (val >> 4) & 0x3f;
  1085. pcinfo->pwr[2][1] = (val >> 10) & 0xf;
  1086. pcinfo->pddac[2][1] = (val >> 14) & 0x3;
  1087. AR5K_EEPROM_READ(offset++, val);
  1088. pcinfo->pddac[2][1] |= (val & 0xF) << 2;
  1089. pcinfo->pwr[2][2] = (val >> 4) & 0xf;
  1090. pcinfo->pddac[2][2] = (val >> 8) & 0x3f;
  1091. pcinfo->pwr[2][3] = 0;
  1092. pcinfo->pddac[2][3] = 0;
  1093. } else if (pd_gains == 2) {
  1094. pcinfo->pwr[1][3] = (val >> 4) & 0xf;
  1095. pcinfo->pddac[1][3] = (val >> 8) & 0x3f;
  1096. }
  1097. if (pd_gains > 3) {
  1098. pcinfo->pwr_i[3] = (val >> 14) & 0x3;
  1099. AR5K_EEPROM_READ(offset++, val);
  1100. pcinfo->pwr_i[3] |= ((val >> 0) & 0x7) << 2;
  1101. pcinfo->pddac_i[3] = (val >> 3) & 0x7f;
  1102. pcinfo->pwr[3][0] = (val >> 10) & 0xf;
  1103. pcinfo->pddac[3][0] = (val >> 14) & 0x3;
  1104. AR5K_EEPROM_READ(offset++, val);
  1105. pcinfo->pddac[3][0] |= (val & 0xF) << 2;
  1106. pcinfo->pwr[3][1] = (val >> 4) & 0xf;
  1107. pcinfo->pddac[3][1] = (val >> 8) & 0x3f;
  1108. pcinfo->pwr[3][2] = (val >> 14) & 0x3;
  1109. AR5K_EEPROM_READ(offset++, val);
  1110. pcinfo->pwr[3][2] |= ((val >> 0) & 0x3) << 2;
  1111. pcinfo->pddac[3][2] = (val >> 2) & 0x3f;
  1112. pcinfo->pwr[3][3] = (val >> 8) & 0xf;
  1113. pcinfo->pddac[3][3] = (val >> 12) & 0xF;
  1114. AR5K_EEPROM_READ(offset++, val);
  1115. pcinfo->pddac[3][3] |= ((val >> 0) & 0x3) << 4;
  1116. } else if (pd_gains == 3) {
  1117. pcinfo->pwr[2][3] = (val >> 14) & 0x3;
  1118. AR5K_EEPROM_READ(offset++, val);
  1119. pcinfo->pwr[2][3] |= ((val >> 0) & 0x3) << 2;
  1120. pcinfo->pddac[2][3] = (val >> 2) & 0x3f;
  1121. }
  1122. }
  1123. return ath5k_eeprom_convert_pcal_info_2413(ah, mode, chinfo);
  1124. }
  1125. /*
  1126. * Read per rate target power (this is the maximum tx power
  1127. * supported by the card). This info is used when setting
  1128. * tx power, no matter the channel.
  1129. *
  1130. * This also works for v5 EEPROMs.
  1131. */
  1132. static int
  1133. ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw *ah, unsigned int mode)
  1134. {
  1135. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1136. struct ath5k_rate_pcal_info *rate_pcal_info;
  1137. u8 *rate_target_pwr_num;
  1138. u32 offset;
  1139. u16 val;
  1140. int ret, i;
  1141. offset = AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1);
  1142. rate_target_pwr_num = &ee->ee_rate_target_pwr_num[mode];
  1143. switch (mode) {
  1144. case AR5K_EEPROM_MODE_11A:
  1145. offset += AR5K_EEPROM_TARGET_PWR_OFF_11A(ee->ee_version);
  1146. rate_pcal_info = ee->ee_rate_tpwr_a;
  1147. ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_5GHZ_CHAN;
  1148. break;
  1149. case AR5K_EEPROM_MODE_11B:
  1150. offset += AR5K_EEPROM_TARGET_PWR_OFF_11B(ee->ee_version);
  1151. rate_pcal_info = ee->ee_rate_tpwr_b;
  1152. ee->ee_rate_target_pwr_num[mode] = 2; /* 3rd is g mode's 1st */
  1153. break;
  1154. case AR5K_EEPROM_MODE_11G:
  1155. offset += AR5K_EEPROM_TARGET_PWR_OFF_11G(ee->ee_version);
  1156. rate_pcal_info = ee->ee_rate_tpwr_g;
  1157. ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_2GHZ_CHAN;
  1158. break;
  1159. default:
  1160. return -EINVAL;
  1161. }
  1162. /* Different freq mask for older eeproms (<= v3.2) */
  1163. if (ee->ee_version <= AR5K_EEPROM_VERSION_3_2) {
  1164. for (i = 0; i < (*rate_target_pwr_num); i++) {
  1165. AR5K_EEPROM_READ(offset++, val);
  1166. rate_pcal_info[i].freq =
  1167. ath5k_eeprom_bin2freq(ee, (val >> 9) & 0x7f, mode);
  1168. rate_pcal_info[i].target_power_6to24 = ((val >> 3) & 0x3f);
  1169. rate_pcal_info[i].target_power_36 = (val << 3) & 0x3f;
  1170. AR5K_EEPROM_READ(offset++, val);
  1171. if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
  1172. val == 0) {
  1173. (*rate_target_pwr_num) = i;
  1174. break;
  1175. }
  1176. rate_pcal_info[i].target_power_36 |= ((val >> 13) & 0x7);
  1177. rate_pcal_info[i].target_power_48 = ((val >> 7) & 0x3f);
  1178. rate_pcal_info[i].target_power_54 = ((val >> 1) & 0x3f);
  1179. }
  1180. } else {
  1181. for (i = 0; i < (*rate_target_pwr_num); i++) {
  1182. AR5K_EEPROM_READ(offset++, val);
  1183. rate_pcal_info[i].freq =
  1184. ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
  1185. rate_pcal_info[i].target_power_6to24 = ((val >> 2) & 0x3f);
  1186. rate_pcal_info[i].target_power_36 = (val << 4) & 0x3f;
  1187. AR5K_EEPROM_READ(offset++, val);
  1188. if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
  1189. val == 0) {
  1190. (*rate_target_pwr_num) = i;
  1191. break;
  1192. }
  1193. rate_pcal_info[i].target_power_36 |= (val >> 12) & 0xf;
  1194. rate_pcal_info[i].target_power_48 = ((val >> 6) & 0x3f);
  1195. rate_pcal_info[i].target_power_54 = (val & 0x3f);
  1196. }
  1197. }
  1198. return 0;
  1199. }
  1200. /*
  1201. * Read per channel calibration info from EEPROM
  1202. *
  1203. * This info is used to calibrate the baseband power table. Imagine
  1204. * that for each channel there is a power curve that's hw specific
  1205. * (depends on amplifier etc) and we try to "correct" this curve using
  1206. * offests we pass on to phy chip (baseband -> before amplifier) so that
  1207. * it can use accurate power values when setting tx power (takes amplifier's
  1208. * performance on each channel into account).
  1209. *
  1210. * EEPROM provides us with the offsets for some pre-calibrated channels
  1211. * and we have to interpolate to create the full table for these channels and
  1212. * also the table for any channel.
  1213. */
  1214. static int
  1215. ath5k_eeprom_read_pcal_info(struct ath5k_hw *ah)
  1216. {
  1217. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1218. int (*read_pcal)(struct ath5k_hw *hw, int mode);
  1219. int mode;
  1220. int err;
  1221. if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) &&
  1222. (AR5K_EEPROM_EEMAP(ee->ee_misc0) == 1))
  1223. read_pcal = ath5k_eeprom_read_pcal_info_5112;
  1224. else if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0) &&
  1225. (AR5K_EEPROM_EEMAP(ee->ee_misc0) == 2))
  1226. read_pcal = ath5k_eeprom_read_pcal_info_2413;
  1227. else
  1228. read_pcal = ath5k_eeprom_read_pcal_info_5111;
  1229. for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G;
  1230. mode++) {
  1231. err = read_pcal(ah, mode);
  1232. if (err)
  1233. return err;
  1234. err = ath5k_eeprom_read_target_rate_pwr_info(ah, mode);
  1235. if (err < 0)
  1236. return err;
  1237. }
  1238. return 0;
  1239. }
  1240. static int
  1241. ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode)
  1242. {
  1243. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1244. struct ath5k_chan_pcal_info *chinfo;
  1245. u8 pier, pdg;
  1246. switch (mode) {
  1247. case AR5K_EEPROM_MODE_11A:
  1248. if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
  1249. return 0;
  1250. chinfo = ee->ee_pwr_cal_a;
  1251. break;
  1252. case AR5K_EEPROM_MODE_11B:
  1253. if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
  1254. return 0;
  1255. chinfo = ee->ee_pwr_cal_b;
  1256. break;
  1257. case AR5K_EEPROM_MODE_11G:
  1258. if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
  1259. return 0;
  1260. chinfo = ee->ee_pwr_cal_g;
  1261. break;
  1262. default:
  1263. return -EINVAL;
  1264. }
  1265. for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
  1266. if (!chinfo[pier].pd_curves)
  1267. continue;
  1268. for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
  1269. struct ath5k_pdgain_info *pd =
  1270. &chinfo[pier].pd_curves[pdg];
  1271. if (pd != NULL) {
  1272. free(pd->pd_step);
  1273. free(pd->pd_pwr);
  1274. }
  1275. }
  1276. free(chinfo[pier].pd_curves);
  1277. }
  1278. return 0;
  1279. }
  1280. void
  1281. ath5k_eeprom_detach(struct ath5k_hw *ah)
  1282. {
  1283. u8 mode;
  1284. for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++)
  1285. ath5k_eeprom_free_pcal_info(ah, mode);
  1286. }
  1287. /* Read conformance test limits used for regulatory control */
  1288. static int
  1289. ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah)
  1290. {
  1291. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1292. struct ath5k_edge_power *rep;
  1293. unsigned int fmask, pmask;
  1294. unsigned int ctl_mode;
  1295. int ret, i, j;
  1296. u32 offset;
  1297. u16 val;
  1298. pmask = AR5K_EEPROM_POWER_M;
  1299. fmask = AR5K_EEPROM_FREQ_M(ee->ee_version);
  1300. offset = AR5K_EEPROM_CTL(ee->ee_version);
  1301. ee->ee_ctls = AR5K_EEPROM_N_CTLS(ee->ee_version);
  1302. for (i = 0; i < ee->ee_ctls; i += 2) {
  1303. AR5K_EEPROM_READ(offset++, val);
  1304. ee->ee_ctl[i] = (val >> 8) & 0xff;
  1305. ee->ee_ctl[i + 1] = val & 0xff;
  1306. }
  1307. offset = AR5K_EEPROM_GROUP8_OFFSET;
  1308. if (ee->ee_version >= AR5K_EEPROM_VERSION_4_0)
  1309. offset += AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1) -
  1310. AR5K_EEPROM_GROUP5_OFFSET;
  1311. else
  1312. offset += AR5K_EEPROM_GROUPS_START(ee->ee_version);
  1313. rep = ee->ee_ctl_pwr;
  1314. for(i = 0; i < ee->ee_ctls; i++) {
  1315. switch(ee->ee_ctl[i] & AR5K_CTL_MODE_M) {
  1316. case AR5K_CTL_11A:
  1317. case AR5K_CTL_TURBO:
  1318. ctl_mode = AR5K_EEPROM_MODE_11A;
  1319. break;
  1320. default:
  1321. ctl_mode = AR5K_EEPROM_MODE_11G;
  1322. break;
  1323. }
  1324. if (ee->ee_ctl[i] == 0) {
  1325. if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3)
  1326. offset += 8;
  1327. else
  1328. offset += 7;
  1329. rep += AR5K_EEPROM_N_EDGES;
  1330. continue;
  1331. }
  1332. if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
  1333. for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
  1334. AR5K_EEPROM_READ(offset++, val);
  1335. rep[j].freq = (val >> 8) & fmask;
  1336. rep[j + 1].freq = val & fmask;
  1337. }
  1338. for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
  1339. AR5K_EEPROM_READ(offset++, val);
  1340. rep[j].edge = (val >> 8) & pmask;
  1341. rep[j].flag = (val >> 14) & 1;
  1342. rep[j + 1].edge = val & pmask;
  1343. rep[j + 1].flag = (val >> 6) & 1;
  1344. }
  1345. } else {
  1346. AR5K_EEPROM_READ(offset++, val);
  1347. rep[0].freq = (val >> 9) & fmask;
  1348. rep[1].freq = (val >> 2) & fmask;
  1349. rep[2].freq = (val << 5) & fmask;
  1350. AR5K_EEPROM_READ(offset++, val);
  1351. rep[2].freq |= (val >> 11) & 0x1f;
  1352. rep[3].freq = (val >> 4) & fmask;
  1353. rep[4].freq = (val << 3) & fmask;
  1354. AR5K_EEPROM_READ(offset++, val);
  1355. rep[4].freq |= (val >> 13) & 0x7;
  1356. rep[5].freq = (val >> 6) & fmask;
  1357. rep[6].freq = (val << 1) & fmask;
  1358. AR5K_EEPROM_READ(offset++, val);
  1359. rep[6].freq |= (val >> 15) & 0x1;
  1360. rep[7].freq = (val >> 8) & fmask;
  1361. rep[0].edge = (val >> 2) & pmask;
  1362. rep[1].edge = (val << 4) & pmask;
  1363. AR5K_EEPROM_READ(offset++, val);
  1364. rep[1].edge |= (val >> 12) & 0xf;
  1365. rep[2].edge = (val >> 6) & pmask;
  1366. rep[3].edge = val & pmask;
  1367. AR5K_EEPROM_READ(offset++, val);
  1368. rep[4].edge = (val >> 10) & pmask;
  1369. rep[5].edge = (val >> 4) & pmask;
  1370. rep[6].edge = (val << 2) & pmask;
  1371. AR5K_EEPROM_READ(offset++, val);
  1372. rep[6].edge |= (val >> 14) & 0x3;
  1373. rep[7].edge = (val >> 8) & pmask;
  1374. }
  1375. for (j = 0; j < AR5K_EEPROM_N_EDGES; j++) {
  1376. rep[j].freq = ath5k_eeprom_bin2freq(ee,
  1377. rep[j].freq, ctl_mode);
  1378. }
  1379. rep += AR5K_EEPROM_N_EDGES;
  1380. }
  1381. return 0;
  1382. }
  1383. /*
  1384. * Initialize eeprom power tables
  1385. */
  1386. int
  1387. ath5k_eeprom_init(struct ath5k_hw *ah)
  1388. {
  1389. int err;
  1390. err = ath5k_eeprom_init_header(ah);
  1391. if (err < 0)
  1392. return err;
  1393. err = ath5k_eeprom_init_modes(ah);
  1394. if (err < 0)
  1395. return err;
  1396. err = ath5k_eeprom_read_pcal_info(ah);
  1397. if (err < 0)
  1398. return err;
  1399. err = ath5k_eeprom_read_ctl_info(ah);
  1400. if (err < 0)
  1401. return err;
  1402. return 0;
  1403. }
  1404. /*
  1405. * Read the MAC address from eeprom
  1406. */
  1407. int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
  1408. {
  1409. u8 mac_d[ETH_ALEN] = {};
  1410. u32 total, offset;
  1411. u16 data;
  1412. int octet, ret;
  1413. ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
  1414. if (ret)
  1415. return ret;
  1416. for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
  1417. ret = ath5k_hw_eeprom_read(ah, offset, &data);
  1418. if (ret)
  1419. return ret;
  1420. total += data;
  1421. mac_d[octet + 1] = data & 0xff;
  1422. mac_d[octet] = data >> 8;
  1423. octet += 2;
  1424. }
  1425. if (!total || total == 3 * 0xffff)
  1426. return -EINVAL;
  1427. memcpy(mac, mac_d, ETH_ALEN);
  1428. return 0;
  1429. }
  1430. int ath5k_eeprom_is_hb63(struct ath5k_hw *ah)
  1431. {
  1432. u16 data;
  1433. ath5k_hw_eeprom_read(ah, AR5K_EEPROM_IS_HB63, &data);
  1434. if ((ah->ah_mac_version == (AR5K_SREV_AR2425 >> 4)) && data)
  1435. return 1;
  1436. else
  1437. return 0;
  1438. }