hermes_dld.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. * Hermes download helper driver.
  3. *
  4. * This could be entirely merged into hermes.c.
  5. *
  6. * I'm keeping it separate to minimise the amount of merging between
  7. * kernel upgrades. It also means the memory overhead for drivers that
  8. * don't need firmware download low.
  9. *
  10. * This driver:
  11. * - is capable of writing to the volatile area of the hermes device
  12. * - is currently not capable of writing to non-volatile areas
  13. * - provide helpers to identify and update plugin data
  14. * - is not capable of interpreting a fw image directly. That is up to
  15. * the main card driver.
  16. * - deals with Hermes I devices. It can probably be modified to deal
  17. * with Hermes II devices
  18. *
  19. * Copyright (C) 2007, David Kilroy
  20. *
  21. * Plug data code slightly modified from spectrum_cs driver
  22. * Copyright (C) 2002-2005 Pavel Roskin <proski@gnu.org>
  23. * Portions based on information in wl_lkm_718 Agere driver
  24. * COPYRIGHT (C) 2001-2004 by Agere Systems Inc. All Rights Reserved
  25. *
  26. * The contents of this file are subject to the Mozilla Public License
  27. * Version 1.1 (the "License"); you may not use this file except in
  28. * compliance with the License. You may obtain a copy of the License
  29. * at http://www.mozilla.org/MPL/
  30. *
  31. * Software distributed under the License is distributed on an "AS IS"
  32. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  33. * the License for the specific language governing rights and
  34. * limitations under the License.
  35. *
  36. * Alternatively, the contents of this file may be used under the
  37. * terms of the GNU General Public License version 2 (the "GPL"), in
  38. * which case the provisions of the GPL are applicable instead of the
  39. * above. If you wish to allow the use of your version of this file
  40. * only under the terms of the GPL and not to allow others to use your
  41. * version of this file under the MPL, indicate your decision by
  42. * deleting the provisions above and replace them with the notice and
  43. * other provisions required by the GPL. If you do not delete the
  44. * provisions above, a recipient may use your version of this file
  45. * under either the MPL or the GPL.
  46. */
  47. #include <linux/module.h>
  48. #include <linux/delay.h>
  49. #include "hermes.h"
  50. #include "hermes_dld.h"
  51. MODULE_DESCRIPTION("Download helper for Lucent Hermes chipset");
  52. MODULE_AUTHOR("David Kilroy <kilroyd@gmail.com>");
  53. MODULE_LICENSE("Dual MPL/GPL");
  54. #define PFX "hermes_dld: "
  55. /*
  56. * AUX port access. To unlock the AUX port write the access keys to the
  57. * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
  58. * register. Then read it and make sure it's HERMES_AUX_ENABLED.
  59. */
  60. #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
  61. #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
  62. #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
  63. #define HERMES_AUX_DISABLED 0x0000 /* Auxiliary port is closed */
  64. #define HERMES_AUX_PW0 0xFE01
  65. #define HERMES_AUX_PW1 0xDC23
  66. #define HERMES_AUX_PW2 0xBA45
  67. /* HERMES_CMD_DOWNLD */
  68. #define HERMES_PROGRAM_DISABLE (0x0000 | HERMES_CMD_DOWNLD)
  69. #define HERMES_PROGRAM_ENABLE_VOLATILE (0x0100 | HERMES_CMD_DOWNLD)
  70. #define HERMES_PROGRAM_ENABLE_NON_VOLATILE (0x0200 | HERMES_CMD_DOWNLD)
  71. #define HERMES_PROGRAM_NON_VOLATILE (0x0300 | HERMES_CMD_DOWNLD)
  72. /* End markers used in dblocks */
  73. #define PDI_END 0x00000000 /* End of PDA */
  74. #define BLOCK_END 0xFFFFFFFF /* Last image block */
  75. #define TEXT_END 0x1A /* End of text header */
  76. /*
  77. * PDA == Production Data Area
  78. *
  79. * In principle, the max. size of the PDA is is 4096 words. Currently,
  80. * however, only about 500 bytes of this area are used.
  81. *
  82. * Some USB implementations can't handle sizes in excess of 1016. Note
  83. * that PDA is not actually used in those USB environments, but may be
  84. * retrieved by common code.
  85. */
  86. #define MAX_PDA_SIZE 1000
  87. /* Limit the amout we try to download in a single shot.
  88. * Size is in bytes.
  89. */
  90. #define MAX_DL_SIZE 1024
  91. #define LIMIT_PROGRAM_SIZE 0
  92. /*
  93. * The following structures have little-endian fields denoted by
  94. * the leading underscore. Don't access them directly - use inline
  95. * functions defined below.
  96. */
  97. /*
  98. * The binary image to be downloaded consists of series of data blocks.
  99. * Each block has the following structure.
  100. */
  101. struct dblock {
  102. __le32 addr; /* adapter address where to write the block */
  103. __le16 len; /* length of the data only, in bytes */
  104. char data[0]; /* data to be written */
  105. } __attribute__ ((packed));
  106. /*
  107. * Plug Data References are located in in the image after the last data
  108. * block. They refer to areas in the adapter memory where the plug data
  109. * items with matching ID should be written.
  110. */
  111. struct pdr {
  112. __le32 id; /* record ID */
  113. __le32 addr; /* adapter address where to write the data */
  114. __le32 len; /* expected length of the data, in bytes */
  115. char next[0]; /* next PDR starts here */
  116. } __attribute__ ((packed));
  117. /*
  118. * Plug Data Items are located in the EEPROM read from the adapter by
  119. * primary firmware. They refer to the device-specific data that should
  120. * be plugged into the secondary firmware.
  121. */
  122. struct pdi {
  123. __le16 len; /* length of ID and data, in words */
  124. __le16 id; /* record ID */
  125. char data[0]; /* plug data */
  126. } __attribute__ ((packed));
  127. /*** FW data block access functions ***/
  128. static inline u32
  129. dblock_addr(const struct dblock *blk)
  130. {
  131. return le32_to_cpu(blk->addr);
  132. }
  133. static inline u32
  134. dblock_len(const struct dblock *blk)
  135. {
  136. return le16_to_cpu(blk->len);
  137. }
  138. /*** PDR Access functions ***/
  139. static inline u32
  140. pdr_id(const struct pdr *pdr)
  141. {
  142. return le32_to_cpu(pdr->id);
  143. }
  144. static inline u32
  145. pdr_addr(const struct pdr *pdr)
  146. {
  147. return le32_to_cpu(pdr->addr);
  148. }
  149. static inline u32
  150. pdr_len(const struct pdr *pdr)
  151. {
  152. return le32_to_cpu(pdr->len);
  153. }
  154. /*** PDI Access functions ***/
  155. static inline u32
  156. pdi_id(const struct pdi *pdi)
  157. {
  158. return le16_to_cpu(pdi->id);
  159. }
  160. /* Return length of the data only, in bytes */
  161. static inline u32
  162. pdi_len(const struct pdi *pdi)
  163. {
  164. return 2 * (le16_to_cpu(pdi->len) - 1);
  165. }
  166. /*** Hermes AUX control ***/
  167. static inline void
  168. hermes_aux_setaddr(hermes_t *hw, u32 addr)
  169. {
  170. hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
  171. hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
  172. }
  173. static inline int
  174. hermes_aux_control(hermes_t *hw, int enabled)
  175. {
  176. int desired_state = enabled ? HERMES_AUX_ENABLED : HERMES_AUX_DISABLED;
  177. int action = enabled ? HERMES_AUX_ENABLE : HERMES_AUX_DISABLE;
  178. int i;
  179. /* Already open? */
  180. if (hermes_read_reg(hw, HERMES_CONTROL) == desired_state)
  181. return 0;
  182. hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
  183. hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
  184. hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
  185. hermes_write_reg(hw, HERMES_CONTROL, action);
  186. for (i = 0; i < 20; i++) {
  187. udelay(10);
  188. if (hermes_read_reg(hw, HERMES_CONTROL) ==
  189. desired_state)
  190. return 0;
  191. }
  192. return -EBUSY;
  193. }
  194. /*** Plug Data Functions ***/
  195. /*
  196. * Scan PDR for the record with the specified RECORD_ID.
  197. * If it's not found, return NULL.
  198. */
  199. static struct pdr *
  200. hermes_find_pdr(struct pdr *first_pdr, u32 record_id)
  201. {
  202. struct pdr *pdr = first_pdr;
  203. void *end = (void *)first_pdr + MAX_PDA_SIZE;
  204. while (((void *)pdr < end) &&
  205. (pdr_id(pdr) != PDI_END)) {
  206. /*
  207. * PDR area is currently not terminated by PDI_END.
  208. * It's followed by CRC records, which have the type
  209. * field where PDR has length. The type can be 0 or 1.
  210. */
  211. if (pdr_len(pdr) < 2)
  212. return NULL;
  213. /* If the record ID matches, we are done */
  214. if (pdr_id(pdr) == record_id)
  215. return pdr;
  216. pdr = (struct pdr *) pdr->next;
  217. }
  218. return NULL;
  219. }
  220. /* Scan production data items for a particular entry */
  221. static struct pdi *
  222. hermes_find_pdi(struct pdi *first_pdi, u32 record_id)
  223. {
  224. struct pdi *pdi = first_pdi;
  225. while (pdi_id(pdi) != PDI_END) {
  226. /* If the record ID matches, we are done */
  227. if (pdi_id(pdi) == record_id)
  228. return pdi;
  229. pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];
  230. }
  231. return NULL;
  232. }
  233. /* Process one Plug Data Item - find corresponding PDR and plug it */
  234. static int
  235. hermes_plug_pdi(hermes_t *hw, struct pdr *first_pdr, const struct pdi *pdi)
  236. {
  237. struct pdr *pdr;
  238. /* Find the PDR corresponding to this PDI */
  239. pdr = hermes_find_pdr(first_pdr, pdi_id(pdi));
  240. /* No match is found, safe to ignore */
  241. if (!pdr)
  242. return 0;
  243. /* Lengths of the data in PDI and PDR must match */
  244. if (pdi_len(pdi) != pdr_len(pdr))
  245. return -EINVAL;
  246. /* do the actual plugging */
  247. hermes_aux_setaddr(hw, pdr_addr(pdr));
  248. hermes_write_bytes(hw, HERMES_AUXDATA, pdi->data, pdi_len(pdi));
  249. return 0;
  250. }
  251. /* Read PDA from the adapter */
  252. int hermes_read_pda(hermes_t *hw,
  253. __le16 *pda,
  254. u32 pda_addr,
  255. u16 pda_len,
  256. int use_eeprom) /* can we get this into hw? */
  257. {
  258. int ret;
  259. u16 pda_size;
  260. u16 data_len = pda_len;
  261. __le16 *data = pda;
  262. if (use_eeprom) {
  263. /* PDA of spectrum symbol is in eeprom */
  264. /* Issue command to read EEPROM */
  265. ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
  266. if (ret)
  267. return ret;
  268. } else {
  269. /* wl_lkm does not include PDA size in the PDA area.
  270. * We will pad the information into pda, so other routines
  271. * don't have to be modified */
  272. pda[0] = cpu_to_le16(pda_len - 2);
  273. /* Includes CFG_PROD_DATA but not itself */
  274. pda[1] = cpu_to_le16(0x0800); /* CFG_PROD_DATA */
  275. data_len = pda_len - 4;
  276. data = pda + 2;
  277. }
  278. /* Open auxiliary port */
  279. ret = hermes_aux_control(hw, 1);
  280. printk(KERN_DEBUG PFX "AUX enable returned %d\n", ret);
  281. if (ret)
  282. return ret;
  283. /* read PDA from EEPROM */
  284. hermes_aux_setaddr(hw, pda_addr);
  285. hermes_read_words(hw, HERMES_AUXDATA, data, data_len / 2);
  286. /* Close aux port */
  287. ret = hermes_aux_control(hw, 0);
  288. printk(KERN_DEBUG PFX "AUX disable returned %d\n", ret);
  289. /* Check PDA length */
  290. pda_size = le16_to_cpu(pda[0]);
  291. printk(KERN_DEBUG PFX "Actual PDA length %d, Max allowed %d\n",
  292. pda_size, pda_len);
  293. if (pda_size > pda_len)
  294. return -EINVAL;
  295. return 0;
  296. }
  297. EXPORT_SYMBOL(hermes_read_pda);
  298. /* Parse PDA and write the records into the adapter
  299. *
  300. * Attempt to write every records that is in the specified pda
  301. * which also has a valid production data record for the firmware.
  302. */
  303. int hermes_apply_pda(hermes_t *hw,
  304. const char *first_pdr,
  305. const __le16 *pda)
  306. {
  307. int ret;
  308. const struct pdi *pdi;
  309. struct pdr *pdr;
  310. pdr = (struct pdr *) first_pdr;
  311. /* Go through every PDI and plug them into the adapter */
  312. pdi = (const struct pdi *) (pda + 2);
  313. while (pdi_id(pdi) != PDI_END) {
  314. ret = hermes_plug_pdi(hw, pdr, pdi);
  315. if (ret)
  316. return ret;
  317. /* Increment to the next PDI */
  318. pdi = (const struct pdi *) &pdi->data[pdi_len(pdi)];
  319. }
  320. return 0;
  321. }
  322. EXPORT_SYMBOL(hermes_apply_pda);
  323. /* Identify the total number of bytes in all blocks
  324. * including the header data.
  325. */
  326. size_t
  327. hermes_blocks_length(const char *first_block)
  328. {
  329. const struct dblock *blk = (const struct dblock *) first_block;
  330. int total_len = 0;
  331. int len;
  332. /* Skip all blocks to locate Plug Data References
  333. * (Spectrum CS) */
  334. while (dblock_addr(blk) != BLOCK_END) {
  335. len = dblock_len(blk);
  336. total_len += sizeof(*blk) + len;
  337. blk = (struct dblock *) &blk->data[len];
  338. }
  339. return total_len;
  340. }
  341. EXPORT_SYMBOL(hermes_blocks_length);
  342. /*** Hermes programming ***/
  343. /* About to start programming data (Hermes I)
  344. * offset is the entry point
  345. *
  346. * Spectrum_cs' Symbol fw does not require this
  347. * wl_lkm Agere fw does
  348. * Don't know about intersil
  349. */
  350. int hermesi_program_init(hermes_t *hw, u32 offset)
  351. {
  352. int err;
  353. /* Disable interrupts?*/
  354. /*hw->inten = 0x0;*/
  355. /*hermes_write_regn(hw, INTEN, 0);*/
  356. /*hermes_set_irqmask(hw, 0);*/
  357. /* Acknowledge any outstanding command */
  358. hermes_write_regn(hw, EVACK, 0xFFFF);
  359. /* Using doicmd_wait rather than docmd_wait */
  360. err = hermes_doicmd_wait(hw,
  361. 0x0100 | HERMES_CMD_INIT,
  362. 0, 0, 0, NULL);
  363. if (err)
  364. return err;
  365. err = hermes_doicmd_wait(hw,
  366. 0x0000 | HERMES_CMD_INIT,
  367. 0, 0, 0, NULL);
  368. if (err)
  369. return err;
  370. err = hermes_aux_control(hw, 1);
  371. printk(KERN_DEBUG PFX "AUX enable returned %d\n", err);
  372. if (err)
  373. return err;
  374. printk(KERN_DEBUG PFX "Enabling volatile, EP 0x%08x\n", offset);
  375. err = hermes_doicmd_wait(hw,
  376. HERMES_PROGRAM_ENABLE_VOLATILE,
  377. offset & 0xFFFFu,
  378. offset >> 16,
  379. 0,
  380. NULL);
  381. printk(KERN_DEBUG PFX "PROGRAM_ENABLE returned %d\n",
  382. err);
  383. return err;
  384. }
  385. EXPORT_SYMBOL(hermesi_program_init);
  386. /* Done programming data (Hermes I)
  387. *
  388. * Spectrum_cs' Symbol fw does not require this
  389. * wl_lkm Agere fw does
  390. * Don't know about intersil
  391. */
  392. int hermesi_program_end(hermes_t *hw)
  393. {
  394. struct hermes_response resp;
  395. int rc = 0;
  396. int err;
  397. rc = hermes_docmd_wait(hw, HERMES_PROGRAM_DISABLE, 0, &resp);
  398. printk(KERN_DEBUG PFX "PROGRAM_DISABLE returned %d, "
  399. "r0 0x%04x, r1 0x%04x, r2 0x%04x\n",
  400. rc, resp.resp0, resp.resp1, resp.resp2);
  401. if ((rc == 0) &&
  402. ((resp.status & HERMES_STATUS_CMDCODE) != HERMES_CMD_DOWNLD))
  403. rc = -EIO;
  404. err = hermes_aux_control(hw, 0);
  405. printk(KERN_DEBUG PFX "AUX disable returned %d\n", err);
  406. /* Acknowledge any outstanding command */
  407. hermes_write_regn(hw, EVACK, 0xFFFF);
  408. /* Reinitialise, ignoring return */
  409. (void) hermes_doicmd_wait(hw, 0x0000 | HERMES_CMD_INIT,
  410. 0, 0, 0, NULL);
  411. return rc ? rc : err;
  412. }
  413. EXPORT_SYMBOL(hermesi_program_end);
  414. /* Program the data blocks */
  415. int hermes_program(hermes_t *hw, const char *first_block, const char *end)
  416. {
  417. const struct dblock *blk;
  418. u32 blkaddr;
  419. u32 blklen;
  420. #if LIMIT_PROGRAM_SIZE
  421. u32 addr;
  422. u32 len;
  423. #endif
  424. blk = (const struct dblock *) first_block;
  425. if ((const char *) blk > (end - sizeof(*blk)))
  426. return -EIO;
  427. blkaddr = dblock_addr(blk);
  428. blklen = dblock_len(blk);
  429. while ((blkaddr != BLOCK_END) &&
  430. (((const char *) blk + blklen) <= end)) {
  431. printk(KERN_DEBUG PFX
  432. "Programming block of length %d to address 0x%08x\n",
  433. blklen, blkaddr);
  434. #if !LIMIT_PROGRAM_SIZE
  435. /* wl_lkm driver splits this into writes of 2000 bytes */
  436. hermes_aux_setaddr(hw, blkaddr);
  437. hermes_write_bytes(hw, HERMES_AUXDATA, blk->data,
  438. blklen);
  439. #else
  440. len = (blklen < MAX_DL_SIZE) ? blklen : MAX_DL_SIZE;
  441. addr = blkaddr;
  442. while (addr < (blkaddr + blklen)) {
  443. printk(KERN_DEBUG PFX
  444. "Programming subblock of length %d "
  445. "to address 0x%08x. Data @ %p\n",
  446. len, addr, &blk->data[addr - blkaddr]);
  447. hermes_aux_setaddr(hw, addr);
  448. hermes_write_bytes(hw, HERMES_AUXDATA,
  449. &blk->data[addr - blkaddr],
  450. len);
  451. addr += len;
  452. len = ((blkaddr + blklen - addr) < MAX_DL_SIZE) ?
  453. (blkaddr + blklen - addr) : MAX_DL_SIZE;
  454. }
  455. #endif
  456. blk = (const struct dblock *) &blk->data[blklen];
  457. if ((const char *) blk > (end - sizeof(*blk)))
  458. return -EIO;
  459. blkaddr = dblock_addr(blk);
  460. blklen = dblock_len(blk);
  461. }
  462. return 0;
  463. }
  464. EXPORT_SYMBOL(hermes_program);
  465. static int __init init_hermes_dld(void)
  466. {
  467. return 0;
  468. }
  469. static void __exit exit_hermes_dld(void)
  470. {
  471. }
  472. module_init(init_hermes_dld);
  473. module_exit(exit_hermes_dld);
  474. /*** Default plugging data for Hermes I ***/
  475. /* Values from wl_lkm_718/hcf/dhf.c */
  476. #define DEFINE_DEFAULT_PDR(pid, length, data) \
  477. static const struct { \
  478. __le16 len; \
  479. __le16 id; \
  480. u8 val[length]; \
  481. } __attribute__ ((packed)) default_pdr_data_##pid = { \
  482. __constant_cpu_to_le16((sizeof(default_pdr_data_##pid)/ \
  483. sizeof(__le16)) - 1), \
  484. __constant_cpu_to_le16(pid), \
  485. data \
  486. }
  487. #define DEFAULT_PDR(pid) default_pdr_data_##pid
  488. /* HWIF Compatiblity */
  489. DEFINE_DEFAULT_PDR(0x0005, 10, "\x00\x00\x06\x00\x01\x00\x01\x00\x01\x00");
  490. /* PPPPSign */
  491. DEFINE_DEFAULT_PDR(0x0108, 4, "\x00\x00\x00\x00");
  492. /* PPPPProf */
  493. DEFINE_DEFAULT_PDR(0x0109, 10, "\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00");
  494. /* Antenna diversity */
  495. DEFINE_DEFAULT_PDR(0x0150, 2, "\x00\x3F");
  496. /* Modem VCO band Set-up */
  497. DEFINE_DEFAULT_PDR(0x0160, 28,
  498. "\x00\x00\x00\x00\x00\x00\x00\x00"
  499. "\x00\x00\x00\x00\x00\x00\x00\x00"
  500. "\x00\x00\x00\x00\x00\x00\x00\x00"
  501. "\x00\x00\x00\x00");
  502. /* Modem Rx Gain Table Values */
  503. DEFINE_DEFAULT_PDR(0x0161, 256,
  504. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  505. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  506. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  507. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  508. "\x3F\x01\x3E\01\x3E\x01\x3D\x01"
  509. "\x3D\x01\x3C\01\x3C\x01\x3B\x01"
  510. "\x3B\x01\x3A\01\x3A\x01\x39\x01"
  511. "\x39\x01\x38\01\x38\x01\x37\x01"
  512. "\x37\x01\x36\01\x36\x01\x35\x01"
  513. "\x35\x01\x34\01\x34\x01\x33\x01"
  514. "\x33\x01\x32\x01\x32\x01\x31\x01"
  515. "\x31\x01\x30\x01\x30\x01\x7B\x01"
  516. "\x7B\x01\x7A\x01\x7A\x01\x79\x01"
  517. "\x79\x01\x78\x01\x78\x01\x77\x01"
  518. "\x77\x01\x76\x01\x76\x01\x75\x01"
  519. "\x75\x01\x74\x01\x74\x01\x73\x01"
  520. "\x73\x01\x72\x01\x72\x01\x71\x01"
  521. "\x71\x01\x70\x01\x70\x01\x68\x01"
  522. "\x68\x01\x67\x01\x67\x01\x66\x01"
  523. "\x66\x01\x65\x01\x65\x01\x57\x01"
  524. "\x57\x01\x56\x01\x56\x01\x55\x01"
  525. "\x55\x01\x54\x01\x54\x01\x53\x01"
  526. "\x53\x01\x52\x01\x52\x01\x51\x01"
  527. "\x51\x01\x50\x01\x50\x01\x48\x01"
  528. "\x48\x01\x47\x01\x47\x01\x46\x01"
  529. "\x46\x01\x45\x01\x45\x01\x44\x01"
  530. "\x44\x01\x43\x01\x43\x01\x42\x01"
  531. "\x42\x01\x41\x01\x41\x01\x40\x01"
  532. "\x40\x01\x40\x01\x40\x01\x40\x01"
  533. "\x40\x01\x40\x01\x40\x01\x40\x01"
  534. "\x40\x01\x40\x01\x40\x01\x40\x01"
  535. "\x40\x01\x40\x01\x40\x01\x40\x01");
  536. /* Write PDA according to certain rules.
  537. *
  538. * For every production data record, look for a previous setting in
  539. * the pda, and use that.
  540. *
  541. * For certain records, use defaults if they are not found in pda.
  542. */
  543. int hermes_apply_pda_with_defaults(hermes_t *hw,
  544. const char *first_pdr,
  545. const __le16 *pda)
  546. {
  547. const struct pdr *pdr = (const struct pdr *) first_pdr;
  548. struct pdi *first_pdi = (struct pdi *) &pda[2];
  549. struct pdi *pdi;
  550. struct pdi *default_pdi = NULL;
  551. struct pdi *outdoor_pdi;
  552. void *end = (void *)first_pdr + MAX_PDA_SIZE;
  553. int record_id;
  554. while (((void *)pdr < end) &&
  555. (pdr_id(pdr) != PDI_END)) {
  556. /*
  557. * For spectrum_cs firmwares,
  558. * PDR area is currently not terminated by PDI_END.
  559. * It's followed by CRC records, which have the type
  560. * field where PDR has length. The type can be 0 or 1.
  561. */
  562. if (pdr_len(pdr) < 2)
  563. break;
  564. record_id = pdr_id(pdr);
  565. pdi = hermes_find_pdi(first_pdi, record_id);
  566. if (pdi)
  567. printk(KERN_DEBUG PFX "Found record 0x%04x at %p\n",
  568. record_id, pdi);
  569. switch (record_id) {
  570. case 0x110: /* Modem REFDAC values */
  571. case 0x120: /* Modem VGDAC values */
  572. outdoor_pdi = hermes_find_pdi(first_pdi, record_id + 1);
  573. default_pdi = NULL;
  574. if (outdoor_pdi) {
  575. pdi = outdoor_pdi;
  576. printk(KERN_DEBUG PFX
  577. "Using outdoor record 0x%04x at %p\n",
  578. record_id + 1, pdi);
  579. }
  580. break;
  581. case 0x5: /* HWIF Compatiblity */
  582. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0005);
  583. break;
  584. case 0x108: /* PPPPSign */
  585. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0108);
  586. break;
  587. case 0x109: /* PPPPProf */
  588. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0109);
  589. break;
  590. case 0x150: /* Antenna diversity */
  591. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0150);
  592. break;
  593. case 0x160: /* Modem VCO band Set-up */
  594. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0160);
  595. break;
  596. case 0x161: /* Modem Rx Gain Table Values */
  597. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0161);
  598. break;
  599. default:
  600. default_pdi = NULL;
  601. break;
  602. }
  603. if (!pdi && default_pdi) {
  604. /* Use default */
  605. pdi = default_pdi;
  606. printk(KERN_DEBUG PFX
  607. "Using default record 0x%04x at %p\n",
  608. record_id, pdi);
  609. }
  610. if (pdi) {
  611. /* Lengths of the data in PDI and PDR must match */
  612. if (pdi_len(pdi) == pdr_len(pdr)) {
  613. /* do the actual plugging */
  614. hermes_aux_setaddr(hw, pdr_addr(pdr));
  615. hermes_write_bytes(hw, HERMES_AUXDATA,
  616. pdi->data, pdi_len(pdi));
  617. }
  618. }
  619. pdr++;
  620. }
  621. return 0;
  622. }
  623. EXPORT_SYMBOL(hermes_apply_pda_with_defaults);