2 * Hermes download helper driver.
4 * This could be entirely merged into hermes.c.
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.
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
19 * Copyright (C) 2007, David Kilroy
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
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/
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.
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.
48 #include <linux/module.h>
49 #include <linux/delay.h>
51 #include "hermes_dld.h"
53 MODULE_DESCRIPTION("Download helper for Lucent Hermes chipset");
54 MODULE_AUTHOR("David Kilroy <kilroyd@gmail.com>");
55 MODULE_LICENSE("Dual MPL/GPL");
57 #define PFX "hermes_dld: "
60 * AUX port access. To unlock the AUX port write the access keys to the
61 * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
62 * register. Then read it and make sure it's HERMES_AUX_ENABLED.
64 #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
65 #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
66 #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
68 #define HERMES_AUX_PW0 0xFE01
69 #define HERMES_AUX_PW1 0xDC23
70 #define HERMES_AUX_PW2 0xBA45
73 #define PDI_END 0x00000000 /* End of PDA */
74 #define BLOCK_END 0xFFFFFFFF /* Last image block */
77 * The following structures have little-endian fields denoted by
78 * the leading underscore. Don't access them directly - use inline
79 * functions defined below.
83 * The binary image to be downloaded consists of series of data blocks.
84 * Each block has the following structure.
87 __le32 addr; /* adapter address where to write the block */
88 __le16 len; /* length of the data only, in bytes */
89 char data[0]; /* data to be written */
90 } __attribute__ ((packed));
93 * Plug Data References are located in in the image after the last data
94 * block. They refer to areas in the adapter memory where the plug data
95 * items with matching ID should be written.
98 __le32 id; /* record ID */
99 __le32 addr; /* adapter address where to write the data */
100 __le32 len; /* expected length of the data, in bytes */
101 char next[0]; /* next PDR starts here */
102 } __attribute__ ((packed));
105 * Plug Data Items are located in the EEPROM read from the adapter by
106 * primary firmware. They refer to the device-specific data that should
107 * be plugged into the secondary firmware.
110 __le16 len; /* length of ID and data, in words */
111 __le16 id; /* record ID */
112 char data[0]; /* plug data */
113 } __attribute__ ((packed));
115 /* Functions for access to little-endian data */
117 dblock_addr(const struct dblock *blk)
119 return le32_to_cpu(blk->addr);
123 dblock_len(const struct dblock *blk)
125 return le16_to_cpu(blk->len);
129 pdr_id(const struct pdr *pdr)
131 return le32_to_cpu(pdr->id);
135 pdr_addr(const struct pdr *pdr)
137 return le32_to_cpu(pdr->addr);
141 pdr_len(const struct pdr *pdr)
143 return le32_to_cpu(pdr->len);
147 pdi_id(const struct pdi *pdi)
149 return le16_to_cpu(pdi->id);
152 /* Return length of the data only, in bytes */
154 pdi_len(const struct pdi *pdi)
156 return 2 * (le16_to_cpu(pdi->len) - 1);
159 /* Set address of the auxiliary port */
161 spectrum_aux_setaddr(hermes_t *hw, u32 addr)
163 hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
164 hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
167 /* Open access to the auxiliary port */
169 spectrum_aux_open(hermes_t *hw)
174 if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED)
177 hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
178 hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
179 hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
180 hermes_write_reg(hw, HERMES_CONTROL, HERMES_AUX_ENABLE);
182 for (i = 0; i < 20; i++) {
184 if (hermes_read_reg(hw, HERMES_CONTROL) ==
193 * Scan PDR for the record with the specified RECORD_ID.
194 * If it's not found, return NULL.
197 spectrum_find_pdr(struct pdr *first_pdr, u32 record_id)
199 struct pdr *pdr = first_pdr;
201 while (pdr_id(pdr) != PDI_END) {
203 * PDR area is currently not terminated by PDI_END.
204 * It's followed by CRC records, which have the type
205 * field where PDR has length. The type can be 0 or 1.
207 if (pdr_len(pdr) < 2)
210 /* If the record ID matches, we are done */
211 if (pdr_id(pdr) == record_id)
214 pdr = (struct pdr *) pdr->next;
219 /* Process one Plug Data Item - find corresponding PDR and plug it */
221 spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi)
225 /* Find the PDI corresponding to this PDR */
226 pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi));
228 /* No match is found, safe to ignore */
232 /* Lengths of the data in PDI and PDR must match */
233 if (pdi_len(pdi) != pdr_len(pdr))
236 /* do the actual plugging */
237 spectrum_aux_setaddr(hw, pdr_addr(pdr));
238 hermes_write_bytes(hw, HERMES_AUXDATA, pdi->data, pdi_len(pdi));
243 /* Read PDA from the adapter */
245 spectrum_read_pda(hermes_t *hw, __le16 *pda, int pda_len)
250 /* Issue command to read EEPROM */
251 ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
255 /* Open auxiliary port */
256 ret = spectrum_aux_open(hw);
260 /* read PDA from EEPROM */
261 spectrum_aux_setaddr(hw, PDA_ADDR);
262 hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2);
264 /* Check PDA length */
265 pda_size = le16_to_cpu(pda[0]);
266 if (pda_size > pda_len)
271 EXPORT_SYMBOL(spectrum_read_pda);
273 /* Parse PDA and write the records into the adapter */
275 spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block,
280 struct pdr *first_pdr;
281 const struct dblock *blk = first_block;
283 /* Skip all blocks to locate Plug Data References */
284 while (dblock_addr(blk) != BLOCK_END)
285 blk = (struct dblock *) &blk->data[dblock_len(blk)];
287 first_pdr = (struct pdr *) blk;
289 /* Go through every PDI and plug them into the adapter */
290 pdi = (struct pdi *) (pda + 2);
291 while (pdi_id(pdi) != PDI_END) {
292 ret = spectrum_plug_pdi(hw, first_pdr, pdi);
296 /* Increment to the next PDI */
297 pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];
301 EXPORT_SYMBOL(spectrum_apply_pda);
303 /* Load firmware blocks into the adapter */
305 spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block)
307 const struct dblock *blk;
312 blkaddr = dblock_addr(blk);
313 blklen = dblock_len(blk);
315 while (dblock_addr(blk) != BLOCK_END) {
316 spectrum_aux_setaddr(hw, blkaddr);
317 hermes_write_bytes(hw, HERMES_AUXDATA, blk->data,
320 blk = (struct dblock *) &blk->data[blklen];
321 blkaddr = dblock_addr(blk);
322 blklen = dblock_len(blk);
326 EXPORT_SYMBOL(spectrum_load_blocks);
328 static int __init init_hermes_dld(void)
333 static void __exit exit_hermes_dld(void)
337 module_init(init_hermes_dld);
338 module_exit(exit_hermes_dld);