hermes_dld.c 19 KB

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