hermes_dld.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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. /*
  68. * PDA == Production Data Area
  69. *
  70. * In principle, the max. size of the PDA is is 4096 words. Currently,
  71. * however, only about 500 bytes of this area are used.
  72. *
  73. * Some USB implementations can't handle sizes in excess of 1016. Note
  74. * that PDA is not actually used in those USB environments, but may be
  75. * retrieved by common code.
  76. */
  77. #define MAX_PDA_SIZE 1000
  78. /* Limit the amout we try to download in a single shot.
  79. * Size is in bytes.
  80. */
  81. #define MAX_DL_SIZE 1024
  82. #define LIMIT_PROGRAM_SIZE 0
  83. /*
  84. * The following structures have little-endian fields denoted by
  85. * the leading underscore. Don't access them directly - use inline
  86. * functions defined below.
  87. */
  88. /*
  89. * The binary image to be downloaded consists of series of data blocks.
  90. * Each block has the following structure.
  91. */
  92. struct dblock {
  93. __le32 addr; /* adapter address where to write the block */
  94. __le16 len; /* length of the data only, in bytes */
  95. char data[0]; /* data to be written */
  96. } __attribute__ ((packed));
  97. /*
  98. * Plug Data References are located in in the image after the last data
  99. * block. They refer to areas in the adapter memory where the plug data
  100. * items with matching ID should be written.
  101. */
  102. struct pdr {
  103. __le32 id; /* record ID */
  104. __le32 addr; /* adapter address where to write the data */
  105. __le32 len; /* expected length of the data, in bytes */
  106. char next[0]; /* next PDR starts here */
  107. } __attribute__ ((packed));
  108. /*
  109. * Plug Data Items are located in the EEPROM read from the adapter by
  110. * primary firmware. They refer to the device-specific data that should
  111. * be plugged into the secondary firmware.
  112. */
  113. struct pdi {
  114. __le16 len; /* length of ID and data, in words */
  115. __le16 id; /* record ID */
  116. char data[0]; /* plug data */
  117. } __attribute__ ((packed));
  118. /*** FW data block access functions ***/
  119. static inline u32
  120. dblock_addr(const struct dblock *blk)
  121. {
  122. return le32_to_cpu(blk->addr);
  123. }
  124. static inline u32
  125. dblock_len(const struct dblock *blk)
  126. {
  127. return le16_to_cpu(blk->len);
  128. }
  129. /*** PDR Access functions ***/
  130. static inline u32
  131. pdr_id(const struct pdr *pdr)
  132. {
  133. return le32_to_cpu(pdr->id);
  134. }
  135. static inline u32
  136. pdr_addr(const struct pdr *pdr)
  137. {
  138. return le32_to_cpu(pdr->addr);
  139. }
  140. static inline u32
  141. pdr_len(const struct pdr *pdr)
  142. {
  143. return le32_to_cpu(pdr->len);
  144. }
  145. /*** PDI Access functions ***/
  146. static inline u32
  147. pdi_id(const struct pdi *pdi)
  148. {
  149. return le16_to_cpu(pdi->id);
  150. }
  151. /* Return length of the data only, in bytes */
  152. static inline u32
  153. pdi_len(const struct pdi *pdi)
  154. {
  155. return 2 * (le16_to_cpu(pdi->len) - 1);
  156. }
  157. /*** Hermes AUX control ***/
  158. static inline void
  159. hermes_aux_setaddr(hermes_t *hw, u32 addr)
  160. {
  161. hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
  162. hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
  163. }
  164. static inline int
  165. hermes_aux_control(hermes_t *hw, int enabled)
  166. {
  167. int desired_state = enabled ? HERMES_AUX_ENABLED : HERMES_AUX_DISABLED;
  168. int action = enabled ? HERMES_AUX_ENABLE : HERMES_AUX_DISABLE;
  169. int i;
  170. /* Already open? */
  171. if (hermes_read_reg(hw, HERMES_CONTROL) == desired_state)
  172. return 0;
  173. hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
  174. hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
  175. hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
  176. hermes_write_reg(hw, HERMES_CONTROL, action);
  177. for (i = 0; i < 20; i++) {
  178. udelay(10);
  179. if (hermes_read_reg(hw, HERMES_CONTROL) ==
  180. desired_state)
  181. return 0;
  182. }
  183. return -EBUSY;
  184. }
  185. /*** Plug Data Functions ***/
  186. /*
  187. * Scan PDR for the record with the specified RECORD_ID.
  188. * If it's not found, return NULL.
  189. */
  190. static struct pdr *
  191. hermes_find_pdr(struct pdr *first_pdr, u32 record_id)
  192. {
  193. struct pdr *pdr = first_pdr;
  194. void *end = (void *)first_pdr + MAX_PDA_SIZE;
  195. while (((void *)pdr < end) &&
  196. (pdr_id(pdr) != PDI_END)) {
  197. /*
  198. * PDR area is currently not terminated by PDI_END.
  199. * It's followed by CRC records, which have the type
  200. * field where PDR has length. The type can be 0 or 1.
  201. */
  202. if (pdr_len(pdr) < 2)
  203. return NULL;
  204. /* If the record ID matches, we are done */
  205. if (pdr_id(pdr) == record_id)
  206. return pdr;
  207. pdr = (struct pdr *) pdr->next;
  208. }
  209. return NULL;
  210. }
  211. /* Scan production data items for a particular entry */
  212. static struct pdi *
  213. hermes_find_pdi(struct pdi *first_pdi, u32 record_id)
  214. {
  215. struct pdi *pdi = first_pdi;
  216. while (pdi_id(pdi) != PDI_END) {
  217. /* If the record ID matches, we are done */
  218. if (pdi_id(pdi) == record_id)
  219. return pdi;
  220. pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];
  221. }
  222. return NULL;
  223. }
  224. /* Process one Plug Data Item - find corresponding PDR and plug it */
  225. static int
  226. hermes_plug_pdi(hermes_t *hw, struct pdr *first_pdr, const struct pdi *pdi)
  227. {
  228. struct pdr *pdr;
  229. /* Find the PDR corresponding to this PDI */
  230. pdr = hermes_find_pdr(first_pdr, pdi_id(pdi));
  231. /* No match is found, safe to ignore */
  232. if (!pdr)
  233. return 0;
  234. /* Lengths of the data in PDI and PDR must match */
  235. if (pdi_len(pdi) != pdr_len(pdr))
  236. return -EINVAL;
  237. /* do the actual plugging */
  238. hermes_aux_setaddr(hw, pdr_addr(pdr));
  239. hermes_write_bytes(hw, HERMES_AUXDATA, pdi->data, pdi_len(pdi));
  240. return 0;
  241. }
  242. /* Read PDA from the adapter */
  243. int hermes_read_pda(hermes_t *hw,
  244. __le16 *pda,
  245. u32 pda_addr,
  246. u16 pda_len,
  247. int use_eeprom) /* can we get this into hw? */
  248. {
  249. int ret;
  250. u16 pda_size;
  251. u16 data_len = pda_len;
  252. __le16 *data = pda;
  253. if (use_eeprom) {
  254. /* PDA of spectrum symbol is in eeprom */
  255. /* Issue command to read EEPROM */
  256. ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
  257. if (ret)
  258. return ret;
  259. } else {
  260. /* wl_lkm does not include PDA size in the PDA area.
  261. * We will pad the information into pda, so other routines
  262. * don't have to be modified */
  263. pda[0] = cpu_to_le16(pda_len - 2);
  264. /* Includes CFG_PROD_DATA but not itself */
  265. pda[1] = cpu_to_le16(0x0800); /* CFG_PROD_DATA */
  266. data_len = pda_len - 4;
  267. data = pda + 2;
  268. }
  269. /* Open auxiliary port */
  270. ret = hermes_aux_control(hw, 1);
  271. printk(KERN_DEBUG PFX "AUX enable returned %d\n", ret);
  272. if (ret)
  273. return ret;
  274. /* read PDA from EEPROM */
  275. hermes_aux_setaddr(hw, pda_addr);
  276. hermes_read_words(hw, HERMES_AUXDATA, data, data_len / 2);
  277. /* Close aux port */
  278. ret = hermes_aux_control(hw, 0);
  279. printk(KERN_DEBUG PFX "AUX disable returned %d\n", ret);
  280. /* Check PDA length */
  281. pda_size = le16_to_cpu(pda[0]);
  282. printk(KERN_DEBUG PFX "Actual PDA length %d, Max allowed %d\n",
  283. pda_size, pda_len);
  284. if (pda_size > pda_len)
  285. return -EINVAL;
  286. return 0;
  287. }
  288. /* Parse PDA and write the records into the adapter
  289. *
  290. * Attempt to write every records that is in the specified pda
  291. * which also has a valid production data record for the firmware.
  292. */
  293. int hermes_apply_pda(hermes_t *hw,
  294. const char *first_pdr,
  295. const __le16 *pda)
  296. {
  297. int ret;
  298. const struct pdi *pdi;
  299. struct pdr *pdr;
  300. pdr = (struct pdr *) first_pdr;
  301. /* Go through every PDI and plug them into the adapter */
  302. pdi = (const struct pdi *) (pda + 2);
  303. while (pdi_id(pdi) != PDI_END) {
  304. ret = hermes_plug_pdi(hw, pdr, pdi);
  305. if (ret)
  306. return ret;
  307. /* Increment to the next PDI */
  308. pdi = (const struct pdi *) &pdi->data[pdi_len(pdi)];
  309. }
  310. return 0;
  311. }
  312. /* Identify the total number of bytes in all blocks
  313. * including the header data.
  314. */
  315. size_t
  316. hermes_blocks_length(const char *first_block)
  317. {
  318. const struct dblock *blk = (const struct dblock *) first_block;
  319. int total_len = 0;
  320. int len;
  321. /* Skip all blocks to locate Plug Data References
  322. * (Spectrum CS) */
  323. while (dblock_addr(blk) != BLOCK_END) {
  324. len = dblock_len(blk);
  325. total_len += sizeof(*blk) + len;
  326. blk = (struct dblock *) &blk->data[len];
  327. }
  328. return total_len;
  329. }
  330. /*** Hermes programming ***/
  331. /* About to start programming data (Hermes I)
  332. * offset is the entry point
  333. *
  334. * Spectrum_cs' Symbol fw does not require this
  335. * wl_lkm Agere fw does
  336. * Don't know about intersil
  337. */
  338. int hermesi_program_init(hermes_t *hw, u32 offset)
  339. {
  340. int err;
  341. /* Disable interrupts?*/
  342. /*hw->inten = 0x0;*/
  343. /*hermes_write_regn(hw, INTEN, 0);*/
  344. /*hermes_set_irqmask(hw, 0);*/
  345. /* Acknowledge any outstanding command */
  346. hermes_write_regn(hw, EVACK, 0xFFFF);
  347. /* Using doicmd_wait rather than docmd_wait */
  348. err = hermes_doicmd_wait(hw,
  349. 0x0100 | HERMES_CMD_INIT,
  350. 0, 0, 0, NULL);
  351. if (err)
  352. return err;
  353. err = hermes_doicmd_wait(hw,
  354. 0x0000 | HERMES_CMD_INIT,
  355. 0, 0, 0, NULL);
  356. if (err)
  357. return err;
  358. err = hermes_aux_control(hw, 1);
  359. printk(KERN_DEBUG PFX "AUX enable returned %d\n", err);
  360. if (err)
  361. return err;
  362. printk(KERN_DEBUG PFX "Enabling volatile, EP 0x%08x\n", offset);
  363. err = hermes_doicmd_wait(hw,
  364. HERMES_PROGRAM_ENABLE_VOLATILE,
  365. offset & 0xFFFFu,
  366. offset >> 16,
  367. 0,
  368. NULL);
  369. printk(KERN_DEBUG PFX "PROGRAM_ENABLE returned %d\n",
  370. err);
  371. return err;
  372. }
  373. /* Done programming data (Hermes I)
  374. *
  375. * Spectrum_cs' Symbol fw does not require this
  376. * wl_lkm Agere fw does
  377. * Don't know about intersil
  378. */
  379. int hermesi_program_end(hermes_t *hw)
  380. {
  381. struct hermes_response resp;
  382. int rc = 0;
  383. int err;
  384. rc = hermes_docmd_wait(hw, HERMES_PROGRAM_DISABLE, 0, &resp);
  385. printk(KERN_DEBUG PFX "PROGRAM_DISABLE returned %d, "
  386. "r0 0x%04x, r1 0x%04x, r2 0x%04x\n",
  387. rc, resp.resp0, resp.resp1, resp.resp2);
  388. if ((rc == 0) &&
  389. ((resp.status & HERMES_STATUS_CMDCODE) != HERMES_CMD_DOWNLD))
  390. rc = -EIO;
  391. err = hermes_aux_control(hw, 0);
  392. printk(KERN_DEBUG PFX "AUX disable returned %d\n", err);
  393. /* Acknowledge any outstanding command */
  394. hermes_write_regn(hw, EVACK, 0xFFFF);
  395. /* Reinitialise, ignoring return */
  396. (void) hermes_doicmd_wait(hw, 0x0000 | HERMES_CMD_INIT,
  397. 0, 0, 0, NULL);
  398. return rc ? rc : err;
  399. }
  400. /* Program the data blocks */
  401. int hermes_program(hermes_t *hw, const char *first_block, const char *end)
  402. {
  403. const struct dblock *blk;
  404. u32 blkaddr;
  405. u32 blklen;
  406. #if LIMIT_PROGRAM_SIZE
  407. u32 addr;
  408. u32 len;
  409. #endif
  410. blk = (const struct dblock *) first_block;
  411. if ((const char *) blk > (end - sizeof(*blk)))
  412. return -EIO;
  413. blkaddr = dblock_addr(blk);
  414. blklen = dblock_len(blk);
  415. while ((blkaddr != BLOCK_END) &&
  416. (((const char *) blk + blklen) <= end)) {
  417. printk(KERN_DEBUG PFX
  418. "Programming block of length %d to address 0x%08x\n",
  419. blklen, blkaddr);
  420. #if !LIMIT_PROGRAM_SIZE
  421. /* wl_lkm driver splits this into writes of 2000 bytes */
  422. hermes_aux_setaddr(hw, blkaddr);
  423. hermes_write_bytes(hw, HERMES_AUXDATA, blk->data,
  424. blklen);
  425. #else
  426. len = (blklen < MAX_DL_SIZE) ? blklen : MAX_DL_SIZE;
  427. addr = blkaddr;
  428. while (addr < (blkaddr + blklen)) {
  429. printk(KERN_DEBUG PFX
  430. "Programming subblock of length %d "
  431. "to address 0x%08x. Data @ %p\n",
  432. len, addr, &blk->data[addr - blkaddr]);
  433. hermes_aux_setaddr(hw, addr);
  434. hermes_write_bytes(hw, HERMES_AUXDATA,
  435. &blk->data[addr - blkaddr],
  436. len);
  437. addr += len;
  438. len = ((blkaddr + blklen - addr) < MAX_DL_SIZE) ?
  439. (blkaddr + blklen - addr) : MAX_DL_SIZE;
  440. }
  441. #endif
  442. blk = (const struct dblock *) &blk->data[blklen];
  443. if ((const char *) blk > (end - sizeof(*blk)))
  444. return -EIO;
  445. blkaddr = dblock_addr(blk);
  446. blklen = dblock_len(blk);
  447. }
  448. return 0;
  449. }
  450. /*** Default plugging data for Hermes I ***/
  451. /* Values from wl_lkm_718/hcf/dhf.c */
  452. #define DEFINE_DEFAULT_PDR(pid, length, data) \
  453. static const struct { \
  454. __le16 len; \
  455. __le16 id; \
  456. u8 val[length]; \
  457. } __attribute__ ((packed)) default_pdr_data_##pid = { \
  458. cpu_to_le16((sizeof(default_pdr_data_##pid)/ \
  459. sizeof(__le16)) - 1), \
  460. cpu_to_le16(pid), \
  461. data \
  462. }
  463. #define DEFAULT_PDR(pid) default_pdr_data_##pid
  464. /* HWIF Compatiblity */
  465. DEFINE_DEFAULT_PDR(0x0005, 10, "\x00\x00\x06\x00\x01\x00\x01\x00\x01\x00");
  466. /* PPPPSign */
  467. DEFINE_DEFAULT_PDR(0x0108, 4, "\x00\x00\x00\x00");
  468. /* PPPPProf */
  469. DEFINE_DEFAULT_PDR(0x0109, 10, "\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00");
  470. /* Antenna diversity */
  471. DEFINE_DEFAULT_PDR(0x0150, 2, "\x00\x3F");
  472. /* Modem VCO band Set-up */
  473. DEFINE_DEFAULT_PDR(0x0160, 28,
  474. "\x00\x00\x00\x00\x00\x00\x00\x00"
  475. "\x00\x00\x00\x00\x00\x00\x00\x00"
  476. "\x00\x00\x00\x00\x00\x00\x00\x00"
  477. "\x00\x00\x00\x00");
  478. /* Modem Rx Gain Table Values */
  479. DEFINE_DEFAULT_PDR(0x0161, 256,
  480. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  481. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  482. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  483. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  484. "\x3F\x01\x3E\01\x3E\x01\x3D\x01"
  485. "\x3D\x01\x3C\01\x3C\x01\x3B\x01"
  486. "\x3B\x01\x3A\01\x3A\x01\x39\x01"
  487. "\x39\x01\x38\01\x38\x01\x37\x01"
  488. "\x37\x01\x36\01\x36\x01\x35\x01"
  489. "\x35\x01\x34\01\x34\x01\x33\x01"
  490. "\x33\x01\x32\x01\x32\x01\x31\x01"
  491. "\x31\x01\x30\x01\x30\x01\x7B\x01"
  492. "\x7B\x01\x7A\x01\x7A\x01\x79\x01"
  493. "\x79\x01\x78\x01\x78\x01\x77\x01"
  494. "\x77\x01\x76\x01\x76\x01\x75\x01"
  495. "\x75\x01\x74\x01\x74\x01\x73\x01"
  496. "\x73\x01\x72\x01\x72\x01\x71\x01"
  497. "\x71\x01\x70\x01\x70\x01\x68\x01"
  498. "\x68\x01\x67\x01\x67\x01\x66\x01"
  499. "\x66\x01\x65\x01\x65\x01\x57\x01"
  500. "\x57\x01\x56\x01\x56\x01\x55\x01"
  501. "\x55\x01\x54\x01\x54\x01\x53\x01"
  502. "\x53\x01\x52\x01\x52\x01\x51\x01"
  503. "\x51\x01\x50\x01\x50\x01\x48\x01"
  504. "\x48\x01\x47\x01\x47\x01\x46\x01"
  505. "\x46\x01\x45\x01\x45\x01\x44\x01"
  506. "\x44\x01\x43\x01\x43\x01\x42\x01"
  507. "\x42\x01\x41\x01\x41\x01\x40\x01"
  508. "\x40\x01\x40\x01\x40\x01\x40\x01"
  509. "\x40\x01\x40\x01\x40\x01\x40\x01"
  510. "\x40\x01\x40\x01\x40\x01\x40\x01"
  511. "\x40\x01\x40\x01\x40\x01\x40\x01");
  512. /* Write PDA according to certain rules.
  513. *
  514. * For every production data record, look for a previous setting in
  515. * the pda, and use that.
  516. *
  517. * For certain records, use defaults if they are not found in pda.
  518. */
  519. int hermes_apply_pda_with_defaults(hermes_t *hw,
  520. const char *first_pdr,
  521. const __le16 *pda)
  522. {
  523. const struct pdr *pdr = (const struct pdr *) first_pdr;
  524. struct pdi *first_pdi = (struct pdi *) &pda[2];
  525. struct pdi *pdi;
  526. struct pdi *default_pdi = NULL;
  527. struct pdi *outdoor_pdi;
  528. void *end = (void *)first_pdr + MAX_PDA_SIZE;
  529. int record_id;
  530. while (((void *)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);
  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. default_pdi = NULL;
  550. if (outdoor_pdi) {
  551. pdi = outdoor_pdi;
  552. printk(KERN_DEBUG PFX
  553. "Using outdoor record 0x%04x at %p\n",
  554. record_id + 1, pdi);
  555. }
  556. break;
  557. case 0x5: /* HWIF Compatiblity */
  558. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0005);
  559. break;
  560. case 0x108: /* PPPPSign */
  561. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0108);
  562. break;
  563. case 0x109: /* PPPPProf */
  564. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0109);
  565. break;
  566. case 0x150: /* Antenna diversity */
  567. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0150);
  568. break;
  569. case 0x160: /* Modem VCO band Set-up */
  570. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0160);
  571. break;
  572. case 0x161: /* Modem Rx Gain Table Values */
  573. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0161);
  574. break;
  575. default:
  576. default_pdi = NULL;
  577. break;
  578. }
  579. if (!pdi && default_pdi) {
  580. /* Use default */
  581. pdi = default_pdi;
  582. printk(KERN_DEBUG PFX
  583. "Using default record 0x%04x at %p\n",
  584. record_id, pdi);
  585. }
  586. if (pdi) {
  587. /* Lengths of the data in PDI and PDR must match */
  588. if (pdi_len(pdi) == pdr_len(pdr)) {
  589. /* do the actual plugging */
  590. hermes_aux_setaddr(hw, pdr_addr(pdr));
  591. hermes_write_bytes(hw, HERMES_AUXDATA,
  592. pdi->data, pdi_len(pdi));
  593. }
  594. }
  595. pdr++;
  596. }
  597. return 0;
  598. }