Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as |
Pavel Roskin | 4ebe2eb | 2006-04-07 04:10:32 -0400 | [diff] [blame] | 3 | * Symbol Wireless Networker LA4137, CompactFlash cards by Socket |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 4 | * Communications and Intel PRO/Wireless 2011B. |
| 5 | * |
| 6 | * The driver implements Symbol firmware download. The rest is handled |
| 7 | * in hermes.c and orinoco.c. |
| 8 | * |
| 9 | * Utilities for downloading the Symbol firmware are available at |
| 10 | * http://sourceforge.net/projects/orinoco/ |
| 11 | * |
| 12 | * Copyright (C) 2002-2005 Pavel Roskin <proski@gnu.org> |
| 13 | * Portions based on orinoco_cs.c: |
| 14 | * Copyright (C) David Gibson, Linuxcare Australia |
| 15 | * Portions based on Spectrum24tDnld.c from original spectrum24 driver: |
| 16 | * Copyright (C) Symbol Technologies. |
| 17 | * |
| 18 | * See copyright notice in file orinoco.c. |
| 19 | */ |
| 20 | |
| 21 | #define DRIVER_NAME "spectrum_cs" |
| 22 | #define PFX DRIVER_NAME ": " |
| 23 | |
| 24 | #include <linux/config.h> |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/init.h> |
Pavel Roskin | ef846bf | 2005-09-23 04:18:07 -0400 | [diff] [blame] | 28 | #include <linux/delay.h> |
Pavel Roskin | 65853b1 | 2005-09-16 02:15:13 -0400 | [diff] [blame] | 29 | #include <linux/firmware.h> |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 30 | #include <pcmcia/cs_types.h> |
| 31 | #include <pcmcia/cs.h> |
| 32 | #include <pcmcia/cistpl.h> |
| 33 | #include <pcmcia/cisreg.h> |
| 34 | #include <pcmcia/ds.h> |
| 35 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 36 | #include "orinoco.h" |
| 37 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 38 | static unsigned char *primsym; |
| 39 | static unsigned char *secsym; |
| 40 | static const char primary_fw_name[] = "symbol_sp24t_prim_fw"; |
| 41 | static const char secondary_fw_name[] = "symbol_sp24t_sec_fw"; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 42 | |
| 43 | /********************************************************************/ |
| 44 | /* Module stuff */ |
| 45 | /********************************************************************/ |
| 46 | |
| 47 | MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>"); |
| 48 | MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader"); |
| 49 | MODULE_LICENSE("Dual MPL/GPL"); |
| 50 | |
| 51 | /* Module parameters */ |
| 52 | |
| 53 | /* Some D-Link cards have buggy CIS. They do work at 5v properly, but |
| 54 | * don't have any CIS entry for it. This workaround it... */ |
| 55 | static int ignore_cis_vcc; /* = 0 */ |
| 56 | module_param(ignore_cis_vcc, int, 0); |
| 57 | MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket"); |
| 58 | |
| 59 | /********************************************************************/ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 60 | /* Data structures */ |
| 61 | /********************************************************************/ |
| 62 | |
| 63 | /* PCMCIA specific device information (goes in the card field of |
| 64 | * struct orinoco_private */ |
| 65 | struct orinoco_pccard { |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 66 | struct pcmcia_device *p_dev; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 67 | dev_node_t node; |
| 68 | }; |
| 69 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 70 | /********************************************************************/ |
| 71 | /* Function prototypes */ |
| 72 | /********************************************************************/ |
| 73 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 74 | static int spectrum_cs_config(struct pcmcia_device *link); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 75 | static void spectrum_cs_release(struct pcmcia_device *link); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 76 | |
| 77 | /********************************************************************/ |
| 78 | /* Firmware downloader */ |
| 79 | /********************************************************************/ |
| 80 | |
| 81 | /* Position of PDA in the adapter memory */ |
| 82 | #define EEPROM_ADDR 0x3000 |
| 83 | #define EEPROM_LEN 0x200 |
| 84 | #define PDA_OFFSET 0x100 |
| 85 | |
| 86 | #define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET) |
| 87 | #define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2) |
| 88 | |
| 89 | /* Constants for the CISREG_CCSR register */ |
| 90 | #define HCR_RUN 0x07 /* run firmware after reset */ |
| 91 | #define HCR_IDLE 0x0E /* don't run firmware after reset */ |
| 92 | #define HCR_MEM16 0x10 /* memory width bit, should be preserved */ |
| 93 | |
| 94 | /* |
| 95 | * AUX port access. To unlock the AUX port write the access keys to the |
| 96 | * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL |
| 97 | * register. Then read it and make sure it's HERMES_AUX_ENABLED. |
| 98 | */ |
| 99 | #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */ |
| 100 | #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */ |
| 101 | #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */ |
| 102 | |
| 103 | #define HERMES_AUX_PW0 0xFE01 |
| 104 | #define HERMES_AUX_PW1 0xDC23 |
| 105 | #define HERMES_AUX_PW2 0xBA45 |
| 106 | |
| 107 | /* End markers */ |
| 108 | #define PDI_END 0x00000000 /* End of PDA */ |
| 109 | #define BLOCK_END 0xFFFFFFFF /* Last image block */ |
| 110 | #define TEXT_END 0x1A /* End of text header */ |
| 111 | |
| 112 | /* |
| 113 | * The following structures have little-endian fields denoted by |
| 114 | * the leading underscore. Don't access them directly - use inline |
| 115 | * functions defined below. |
| 116 | */ |
| 117 | |
| 118 | /* |
| 119 | * The binary image to be downloaded consists of series of data blocks. |
| 120 | * Each block has the following structure. |
| 121 | */ |
| 122 | struct dblock { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 123 | __le32 addr; /* adapter address where to write the block */ |
| 124 | __le16 len; /* length of the data only, in bytes */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 125 | char data[0]; /* data to be written */ |
| 126 | } __attribute__ ((packed)); |
| 127 | |
| 128 | /* |
| 129 | * Plug Data References are located in in the image after the last data |
| 130 | * block. They refer to areas in the adapter memory where the plug data |
| 131 | * items with matching ID should be written. |
| 132 | */ |
| 133 | struct pdr { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 134 | __le32 id; /* record ID */ |
| 135 | __le32 addr; /* adapter address where to write the data */ |
| 136 | __le32 len; /* expected length of the data, in bytes */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 137 | char next[0]; /* next PDR starts here */ |
| 138 | } __attribute__ ((packed)); |
| 139 | |
| 140 | |
| 141 | /* |
| 142 | * Plug Data Items are located in the EEPROM read from the adapter by |
| 143 | * primary firmware. They refer to the device-specific data that should |
| 144 | * be plugged into the secondary firmware. |
| 145 | */ |
| 146 | struct pdi { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 147 | __le16 len; /* length of ID and data, in words */ |
| 148 | __le16 id; /* record ID */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 149 | char data[0]; /* plug data */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 150 | } __attribute__ ((packed)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 151 | |
| 152 | |
| 153 | /* Functions for access to little-endian data */ |
| 154 | static inline u32 |
| 155 | dblock_addr(const struct dblock *blk) |
| 156 | { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 157 | return le32_to_cpu(blk->addr); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static inline u32 |
| 161 | dblock_len(const struct dblock *blk) |
| 162 | { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 163 | return le16_to_cpu(blk->len); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static inline u32 |
| 167 | pdr_id(const struct pdr *pdr) |
| 168 | { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 169 | return le32_to_cpu(pdr->id); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static inline u32 |
| 173 | pdr_addr(const struct pdr *pdr) |
| 174 | { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 175 | return le32_to_cpu(pdr->addr); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static inline u32 |
| 179 | pdr_len(const struct pdr *pdr) |
| 180 | { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 181 | return le32_to_cpu(pdr->len); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static inline u32 |
| 185 | pdi_id(const struct pdi *pdi) |
| 186 | { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 187 | return le16_to_cpu(pdi->id); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* Return length of the data only, in bytes */ |
| 191 | static inline u32 |
| 192 | pdi_len(const struct pdi *pdi) |
| 193 | { |
Pavel Roskin | 7eeae2f | 2006-04-07 04:10:24 -0400 | [diff] [blame] | 194 | return 2 * (le16_to_cpu(pdi->len) - 1); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | |
| 198 | /* Set address of the auxiliary port */ |
| 199 | static inline void |
| 200 | spectrum_aux_setaddr(hermes_t *hw, u32 addr) |
| 201 | { |
| 202 | hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7)); |
| 203 | hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F)); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /* Open access to the auxiliary port */ |
| 208 | static int |
| 209 | spectrum_aux_open(hermes_t *hw) |
| 210 | { |
| 211 | int i; |
| 212 | |
| 213 | /* Already open? */ |
| 214 | if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED) |
| 215 | return 0; |
| 216 | |
| 217 | hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0); |
| 218 | hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1); |
| 219 | hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2); |
| 220 | hermes_write_reg(hw, HERMES_CONTROL, HERMES_AUX_ENABLE); |
| 221 | |
| 222 | for (i = 0; i < 20; i++) { |
| 223 | udelay(10); |
| 224 | if (hermes_read_reg(hw, HERMES_CONTROL) == |
| 225 | HERMES_AUX_ENABLED) |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | return -EBUSY; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | #define CS_CHECK(fn, ret) \ |
| 234 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) |
| 235 | |
| 236 | /* |
| 237 | * Reset the card using configuration registers COR and CCSR. |
| 238 | * If IDLE is 1, stop the firmware, so that it can be safely rewritten. |
| 239 | */ |
| 240 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 241 | spectrum_reset(struct pcmcia_device *link, int idle) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 242 | { |
| 243 | int last_ret, last_fn; |
| 244 | conf_reg_t reg; |
| 245 | u_int save_cor; |
| 246 | |
| 247 | /* Doing it if hardware is gone is guaranteed crash */ |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 248 | if (pcmcia_dev_present(link)) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 249 | return -ENODEV; |
| 250 | |
| 251 | /* Save original COR value */ |
| 252 | reg.Function = 0; |
| 253 | reg.Action = CS_READ; |
| 254 | reg.Offset = CISREG_COR; |
| 255 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 256 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 257 | save_cor = reg.Value; |
| 258 | |
| 259 | /* Soft-Reset card */ |
| 260 | reg.Action = CS_WRITE; |
| 261 | reg.Offset = CISREG_COR; |
| 262 | reg.Value = (save_cor | COR_SOFT_RESET); |
| 263 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 264 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 265 | udelay(1000); |
| 266 | |
| 267 | /* Read CCSR */ |
| 268 | reg.Action = CS_READ; |
| 269 | reg.Offset = CISREG_CCSR; |
| 270 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 271 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 272 | |
| 273 | /* |
| 274 | * Start or stop the firmware. Memory width bit should be |
| 275 | * preserved from the value we've just read. |
| 276 | */ |
| 277 | reg.Action = CS_WRITE; |
| 278 | reg.Offset = CISREG_CCSR; |
| 279 | reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16); |
| 280 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 281 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 282 | udelay(1000); |
| 283 | |
| 284 | /* Restore original COR configuration index */ |
| 285 | reg.Action = CS_WRITE; |
| 286 | reg.Offset = CISREG_COR; |
| 287 | reg.Value = (save_cor & ~COR_SOFT_RESET); |
| 288 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 289 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 290 | udelay(1000); |
| 291 | return 0; |
| 292 | |
| 293 | cs_failed: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 294 | cs_error(link, last_fn, last_ret); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 295 | return -ENODEV; |
| 296 | } |
| 297 | |
| 298 | |
| 299 | /* |
| 300 | * Scan PDR for the record with the specified RECORD_ID. |
| 301 | * If it's not found, return NULL. |
| 302 | */ |
| 303 | static struct pdr * |
| 304 | spectrum_find_pdr(struct pdr *first_pdr, u32 record_id) |
| 305 | { |
| 306 | struct pdr *pdr = first_pdr; |
| 307 | |
| 308 | while (pdr_id(pdr) != PDI_END) { |
| 309 | /* |
| 310 | * PDR area is currently not terminated by PDI_END. |
| 311 | * It's followed by CRC records, which have the type |
| 312 | * field where PDR has length. The type can be 0 or 1. |
| 313 | */ |
| 314 | if (pdr_len(pdr) < 2) |
| 315 | return NULL; |
| 316 | |
| 317 | /* If the record ID matches, we are done */ |
| 318 | if (pdr_id(pdr) == record_id) |
| 319 | return pdr; |
| 320 | |
| 321 | pdr = (struct pdr *) pdr->next; |
| 322 | } |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /* Process one Plug Data Item - find corresponding PDR and plug it */ |
| 328 | static int |
| 329 | spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi) |
| 330 | { |
| 331 | struct pdr *pdr; |
| 332 | |
| 333 | /* Find the PDI corresponding to this PDR */ |
| 334 | pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi)); |
| 335 | |
| 336 | /* No match is found, safe to ignore */ |
| 337 | if (!pdr) |
| 338 | return 0; |
| 339 | |
| 340 | /* Lengths of the data in PDI and PDR must match */ |
| 341 | if (pdi_len(pdi) != pdr_len(pdr)) |
| 342 | return -EINVAL; |
| 343 | |
| 344 | /* do the actual plugging */ |
| 345 | spectrum_aux_setaddr(hw, pdr_addr(pdr)); |
Pavel Roskin | 6b616262 | 2006-04-07 04:10:39 -0400 | [diff] [blame] | 346 | hermes_write_bytes(hw, HERMES_AUXDATA, pdi->data, pdi_len(pdi)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | |
| 352 | /* Read PDA from the adapter */ |
| 353 | static int |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 354 | spectrum_read_pda(hermes_t *hw, __le16 *pda, int pda_len) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 355 | { |
| 356 | int ret; |
| 357 | int pda_size; |
| 358 | |
| 359 | /* Issue command to read EEPROM */ |
| 360 | ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL); |
| 361 | if (ret) |
| 362 | return ret; |
| 363 | |
| 364 | /* Open auxiliary port */ |
| 365 | ret = spectrum_aux_open(hw); |
| 366 | if (ret) |
| 367 | return ret; |
| 368 | |
| 369 | /* read PDA from EEPROM */ |
| 370 | spectrum_aux_setaddr(hw, PDA_ADDR); |
| 371 | hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2); |
| 372 | |
| 373 | /* Check PDA length */ |
| 374 | pda_size = le16_to_cpu(pda[0]); |
| 375 | if (pda_size > pda_len) |
| 376 | return -EINVAL; |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | |
| 382 | /* Parse PDA and write the records into the adapter */ |
| 383 | static int |
| 384 | spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block, |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 385 | __le16 *pda) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 386 | { |
| 387 | int ret; |
| 388 | struct pdi *pdi; |
| 389 | struct pdr *first_pdr; |
| 390 | const struct dblock *blk = first_block; |
| 391 | |
| 392 | /* Skip all blocks to locate Plug Data References */ |
| 393 | while (dblock_addr(blk) != BLOCK_END) |
| 394 | blk = (struct dblock *) &blk->data[dblock_len(blk)]; |
| 395 | |
| 396 | first_pdr = (struct pdr *) blk; |
| 397 | |
| 398 | /* Go through every PDI and plug them into the adapter */ |
| 399 | pdi = (struct pdi *) (pda + 2); |
| 400 | while (pdi_id(pdi) != PDI_END) { |
| 401 | ret = spectrum_plug_pdi(hw, first_pdr, pdi); |
| 402 | if (ret) |
| 403 | return ret; |
| 404 | |
| 405 | /* Increment to the next PDI */ |
| 406 | pdi = (struct pdi *) &pdi->data[pdi_len(pdi)]; |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | |
| 412 | /* Load firmware blocks into the adapter */ |
| 413 | static int |
| 414 | spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block) |
| 415 | { |
| 416 | const struct dblock *blk; |
| 417 | u32 blkaddr; |
| 418 | u32 blklen; |
| 419 | |
| 420 | blk = first_block; |
| 421 | blkaddr = dblock_addr(blk); |
| 422 | blklen = dblock_len(blk); |
| 423 | |
| 424 | while (dblock_addr(blk) != BLOCK_END) { |
| 425 | spectrum_aux_setaddr(hw, blkaddr); |
Pavel Roskin | 6b616262 | 2006-04-07 04:10:39 -0400 | [diff] [blame] | 426 | hermes_write_bytes(hw, HERMES_AUXDATA, blk->data, |
| 427 | blklen); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 428 | |
| 429 | blk = (struct dblock *) &blk->data[blklen]; |
| 430 | blkaddr = dblock_addr(blk); |
| 431 | blklen = dblock_len(blk); |
| 432 | } |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | /* |
| 438 | * Process a firmware image - stop the card, load the firmware, reset |
| 439 | * the card and make sure it responds. For the secondary firmware take |
| 440 | * care of the PDA - read it and then write it on top of the firmware. |
| 441 | */ |
| 442 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 443 | spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link, |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 444 | const unsigned char *image) |
| 445 | { |
| 446 | int ret; |
| 447 | const unsigned char *ptr; |
| 448 | const struct dblock *first_block; |
| 449 | |
| 450 | /* Plug Data Area (PDA) */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 451 | __le16 pda[PDA_WORDS]; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 452 | |
| 453 | /* Binary block begins after the 0x1A marker */ |
| 454 | ptr = image; |
| 455 | while (*ptr++ != TEXT_END); |
| 456 | first_block = (const struct dblock *) ptr; |
| 457 | |
| 458 | /* Read the PDA */ |
| 459 | if (image != primsym) { |
| 460 | ret = spectrum_read_pda(hw, pda, sizeof(pda)); |
| 461 | if (ret) |
| 462 | return ret; |
| 463 | } |
| 464 | |
| 465 | /* Stop the firmware, so that it can be safely rewritten */ |
| 466 | ret = spectrum_reset(link, 1); |
| 467 | if (ret) |
| 468 | return ret; |
| 469 | |
| 470 | /* Program the adapter with new firmware */ |
| 471 | ret = spectrum_load_blocks(hw, first_block); |
| 472 | if (ret) |
| 473 | return ret; |
| 474 | |
| 475 | /* Write the PDA to the adapter */ |
| 476 | if (image != primsym) { |
| 477 | ret = spectrum_apply_pda(hw, first_block, pda); |
| 478 | if (ret) |
| 479 | return ret; |
| 480 | } |
| 481 | |
| 482 | /* Run the firmware */ |
| 483 | ret = spectrum_reset(link, 0); |
| 484 | if (ret) |
| 485 | return ret; |
| 486 | |
| 487 | /* Reset hermes chip and make sure it responds */ |
| 488 | ret = hermes_init(hw); |
| 489 | |
| 490 | /* hermes_reset() should return 0 with the secondary firmware */ |
| 491 | if (image != primsym && ret != 0) |
| 492 | return -ENODEV; |
| 493 | |
| 494 | /* And this should work with any firmware */ |
| 495 | if (!hermes_present(hw)) |
| 496 | return -ENODEV; |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | |
| 502 | /* |
| 503 | * Download the firmware into the card, this also does a PCMCIA soft |
| 504 | * reset on the card, to make sure it's in a sane state. |
| 505 | */ |
| 506 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 507 | spectrum_dl_firmware(hermes_t *hw, struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 508 | { |
| 509 | int ret; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 510 | const struct firmware *fw_entry; |
| 511 | |
| 512 | if (request_firmware(&fw_entry, primary_fw_name, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 513 | &handle_to_dev(link)) == 0) { |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 514 | primsym = fw_entry->data; |
| 515 | } else { |
| 516 | printk(KERN_ERR PFX "Cannot find firmware: %s\n", |
| 517 | primary_fw_name); |
| 518 | return -ENOENT; |
| 519 | } |
| 520 | |
| 521 | if (request_firmware(&fw_entry, secondary_fw_name, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 522 | &handle_to_dev(link)) == 0) { |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 523 | secsym = fw_entry->data; |
| 524 | } else { |
| 525 | printk(KERN_ERR PFX "Cannot find firmware: %s\n", |
| 526 | secondary_fw_name); |
| 527 | return -ENOENT; |
| 528 | } |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 529 | |
| 530 | /* Load primary firmware */ |
| 531 | ret = spectrum_dl_image(hw, link, primsym); |
| 532 | if (ret) { |
| 533 | printk(KERN_ERR PFX "Primary firmware download failed\n"); |
| 534 | return ret; |
| 535 | } |
| 536 | |
| 537 | /* Load secondary firmware */ |
| 538 | ret = spectrum_dl_image(hw, link, secsym); |
| 539 | |
| 540 | if (ret) { |
| 541 | printk(KERN_ERR PFX "Secondary firmware download failed\n"); |
| 542 | } |
| 543 | |
| 544 | return ret; |
| 545 | } |
| 546 | |
| 547 | /********************************************************************/ |
| 548 | /* Device methods */ |
| 549 | /********************************************************************/ |
| 550 | |
| 551 | static int |
| 552 | spectrum_cs_hard_reset(struct orinoco_private *priv) |
| 553 | { |
| 554 | struct orinoco_pccard *card = priv->card; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 555 | struct pcmcia_device *link = card->p_dev; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 556 | int err; |
| 557 | |
| 558 | if (!hermes_present(&priv->hw)) { |
| 559 | /* The firmware needs to be reloaded */ |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 560 | if (spectrum_dl_firmware(&priv->hw, link) != 0) { |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 561 | printk(KERN_ERR PFX "Firmware download failed\n"); |
| 562 | err = -ENODEV; |
| 563 | } |
| 564 | } else { |
| 565 | /* Soft reset using COR and HCR */ |
| 566 | spectrum_reset(link, 0); |
| 567 | } |
| 568 | |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | /********************************************************************/ |
| 573 | /* PCMCIA stuff */ |
| 574 | /********************************************************************/ |
| 575 | |
| 576 | /* |
| 577 | * This creates an "instance" of the driver, allocating local data |
| 578 | * structures for one device. The device is registered with Card |
| 579 | * Services. |
| 580 | * |
| 581 | * The dev_link structure is initialized, but we don't actually |
| 582 | * configure the card at this point -- we wait until we receive a card |
| 583 | * insertion event. */ |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 584 | static int |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 585 | spectrum_cs_probe(struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 586 | { |
| 587 | struct net_device *dev; |
| 588 | struct orinoco_private *priv; |
| 589 | struct orinoco_pccard *card; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 590 | |
| 591 | dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset); |
| 592 | if (! dev) |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 593 | return -ENOMEM; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 594 | priv = netdev_priv(dev); |
| 595 | card = priv->card; |
| 596 | |
| 597 | /* Link both structures together */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 598 | card->p_dev = link; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 599 | link->priv = dev; |
| 600 | |
| 601 | /* Interrupt setup */ |
| 602 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; |
| 603 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; |
| 604 | link->irq.Handler = orinoco_interrupt; |
| 605 | link->irq.Instance = dev; |
| 606 | |
| 607 | /* General socket configuration defaults can go here. In this |
| 608 | * client, we assume very little, and rely on the CIS for |
| 609 | * almost everything. In most clients, many details (i.e., |
| 610 | * number, sizes, and attributes of IO windows) are fixed by |
| 611 | * the nature of the device, and can be hard-wired here. */ |
| 612 | link->conf.Attributes = 0; |
| 613 | link->conf.IntType = INT_MEMORY_AND_IO; |
| 614 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 615 | return spectrum_cs_config(link); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 616 | } /* spectrum_cs_attach */ |
| 617 | |
| 618 | /* |
| 619 | * This deletes a driver "instance". The device is de-registered with |
| 620 | * Card Services. If it has been released, all local data structures |
| 621 | * are freed. Otherwise, the structures will be freed when the device |
| 622 | * is released. |
| 623 | */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 624 | static void spectrum_cs_detach(struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 625 | { |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 626 | struct net_device *dev = link->priv; |
| 627 | |
Pavel Roskin | e4f4f98 | 2006-05-01 02:13:24 -0400 | [diff] [blame] | 628 | if (link->dev_node) |
| 629 | unregister_netdev(dev); |
| 630 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 631 | spectrum_cs_release(link); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 632 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 633 | free_orinocodev(dev); |
| 634 | } /* spectrum_cs_detach */ |
| 635 | |
| 636 | /* |
| 637 | * spectrum_cs_config() is scheduled to run after a CARD_INSERTION |
| 638 | * event is received, to configure the PCMCIA socket, and to make the |
| 639 | * device available to the system. |
| 640 | */ |
| 641 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 642 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 643 | spectrum_cs_config(struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 644 | { |
| 645 | struct net_device *dev = link->priv; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 646 | struct orinoco_private *priv = netdev_priv(dev); |
| 647 | struct orinoco_pccard *card = priv->card; |
| 648 | hermes_t *hw = &priv->hw; |
| 649 | int last_fn, last_ret; |
| 650 | u_char buf[64]; |
| 651 | config_info_t conf; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 652 | tuple_t tuple; |
| 653 | cisparse_t parse; |
| 654 | void __iomem *mem; |
| 655 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 656 | /* |
| 657 | * This reads the card's CONFIG tuple to find its |
| 658 | * configuration registers. |
| 659 | */ |
| 660 | tuple.DesiredTuple = CISTPL_CONFIG; |
| 661 | tuple.Attributes = 0; |
| 662 | tuple.TupleData = buf; |
| 663 | tuple.TupleDataMax = sizeof(buf); |
| 664 | tuple.TupleOffset = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 665 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
| 666 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); |
| 667 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 668 | link->conf.ConfigBase = parse.config.base; |
| 669 | link->conf.Present = parse.config.rmask[0]; |
| 670 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 671 | /* Look up the current Vcc */ |
| 672 | CS_CHECK(GetConfigurationInfo, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 673 | pcmcia_get_configuration_info(link, &conf)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 674 | |
| 675 | /* |
| 676 | * In this loop, we scan the CIS for configuration table |
| 677 | * entries, each of which describes a valid card |
| 678 | * configuration, including voltage, IO window, memory window, |
| 679 | * and interrupt settings. |
| 680 | * |
| 681 | * We make no assumptions about the card to be configured: we |
| 682 | * use just the information available in the CIS. In an ideal |
| 683 | * world, this would work for any PCMCIA card, but it requires |
| 684 | * a complete and accurate CIS. In practice, a driver usually |
| 685 | * "knows" most of these things without consulting the CIS, |
| 686 | * and most client drivers will only use the CIS to fill in |
| 687 | * implementation-defined details. |
| 688 | */ |
| 689 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 690 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 691 | while (1) { |
| 692 | cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); |
| 693 | cistpl_cftable_entry_t dflt = { .index = 0 }; |
| 694 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 695 | if ( (pcmcia_get_tuple_data(link, &tuple) != 0) |
| 696 | || (pcmcia_parse_tuple(link, &tuple, &parse) != 0)) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 697 | goto next_entry; |
| 698 | |
| 699 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) |
| 700 | dflt = *cfg; |
| 701 | if (cfg->index == 0) |
| 702 | goto next_entry; |
| 703 | link->conf.ConfigIndex = cfg->index; |
| 704 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 705 | /* Use power settings for Vcc and Vpp if present */ |
| 706 | /* Note that the CIS values need to be rescaled */ |
| 707 | if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 708 | if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) { |
| 709 | DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000); |
| 710 | if (!ignore_cis_vcc) |
| 711 | goto next_entry; |
| 712 | } |
| 713 | } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 714 | if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) { |
| 715 | DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000); |
| 716 | if(!ignore_cis_vcc) |
| 717 | goto next_entry; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 722 | link->conf.Vpp = |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 723 | cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 724 | else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 725 | link->conf.Vpp = |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 726 | dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 727 | |
| 728 | /* Do we need to allocate an interrupt? */ |
| 729 | link->conf.Attributes |= CONF_ENABLE_IRQ; |
| 730 | |
| 731 | /* IO window settings */ |
| 732 | link->io.NumPorts1 = link->io.NumPorts2 = 0; |
| 733 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { |
| 734 | cistpl_io_t *io = |
| 735 | (cfg->io.nwin) ? &cfg->io : &dflt.io; |
| 736 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 737 | if (!(io->flags & CISTPL_IO_8BIT)) |
| 738 | link->io.Attributes1 = |
| 739 | IO_DATA_PATH_WIDTH_16; |
| 740 | if (!(io->flags & CISTPL_IO_16BIT)) |
| 741 | link->io.Attributes1 = |
| 742 | IO_DATA_PATH_WIDTH_8; |
| 743 | link->io.IOAddrLines = |
| 744 | io->flags & CISTPL_IO_LINES_MASK; |
| 745 | link->io.BasePort1 = io->win[0].base; |
| 746 | link->io.NumPorts1 = io->win[0].len; |
| 747 | if (io->nwin > 1) { |
| 748 | link->io.Attributes2 = |
| 749 | link->io.Attributes1; |
| 750 | link->io.BasePort2 = io->win[1].base; |
| 751 | link->io.NumPorts2 = io->win[1].len; |
| 752 | } |
| 753 | |
| 754 | /* This reserves IO space but doesn't actually enable it */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 755 | if (pcmcia_request_io(link, &link->io) != 0) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 756 | goto next_entry; |
| 757 | } |
| 758 | |
| 759 | |
| 760 | /* If we got this far, we're cool! */ |
| 761 | |
| 762 | break; |
| 763 | |
| 764 | next_entry: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 765 | pcmcia_disable_device(link); |
| 766 | last_ret = pcmcia_get_next_tuple(link, &tuple); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 767 | if (last_ret == CS_NO_MORE_ITEMS) { |
| 768 | printk(KERN_ERR PFX "GetNextTuple(): No matching " |
| 769 | "CIS configuration. Maybe you need the " |
| 770 | "ignore_cis_vcc=1 parameter.\n"); |
| 771 | goto cs_failed; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | /* |
| 776 | * Allocate an interrupt line. Note that this does not assign |
| 777 | * a handler to the interrupt, unless the 'Handler' member of |
| 778 | * the irq structure is initialized. |
| 779 | */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 780 | CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 781 | |
| 782 | /* We initialize the hermes structure before completing PCMCIA |
| 783 | * configuration just in case the interrupt handler gets |
| 784 | * called. */ |
| 785 | mem = ioport_map(link->io.BasePort1, link->io.NumPorts1); |
| 786 | if (!mem) |
| 787 | goto cs_failed; |
| 788 | |
| 789 | hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); |
| 790 | |
| 791 | /* |
| 792 | * This actually configures the PCMCIA socket -- setting up |
| 793 | * the I/O windows and the interrupt mapping, and putting the |
| 794 | * card and host interface into "Memory and IO" mode. |
| 795 | */ |
| 796 | CS_CHECK(RequestConfiguration, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 797 | pcmcia_request_configuration(link, &link->conf)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 798 | |
| 799 | /* Ok, we have the configuration, prepare to register the netdev */ |
| 800 | dev->base_addr = link->io.BasePort1; |
| 801 | dev->irq = link->irq.AssignedIRQ; |
| 802 | SET_MODULE_OWNER(dev); |
| 803 | card->node.major = card->node.minor = 0; |
| 804 | |
| 805 | /* Reset card and download firmware */ |
| 806 | if (spectrum_cs_hard_reset(priv) != 0) { |
| 807 | goto failed; |
| 808 | } |
| 809 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 810 | SET_NETDEV_DEV(dev, &handle_to_dev(link)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 811 | /* Tell the stack we exist */ |
| 812 | if (register_netdev(dev) != 0) { |
| 813 | printk(KERN_ERR PFX "register_netdev() failed\n"); |
| 814 | goto failed; |
| 815 | } |
| 816 | |
| 817 | /* At this point, the dev_node_t structure(s) needs to be |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 818 | * initialized and arranged in a linked list at link->dev_node. */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 819 | strcpy(card->node.dev_name, dev->name); |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 820 | link->dev_node = &card->node; /* link->dev_node being non-NULL is also |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 821 | used to indicate that the |
| 822 | net_device has been registered */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 823 | |
| 824 | /* Finally, report what we've done */ |
Pavel Roskin | 9a568da | 2006-05-01 02:13:26 -0400 | [diff] [blame^] | 825 | printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io " |
| 826 | "0x%04x-0x%04x\n", dev->name, dev->class_dev.dev->bus_id, |
| 827 | link->irq.AssignedIRQ, link->io.BasePort1, |
| 828 | link->io.BasePort1 + link->io.NumPorts1 - 1); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 829 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 830 | return 0; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 831 | |
| 832 | cs_failed: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 833 | cs_error(link, last_fn, last_ret); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 834 | |
| 835 | failed: |
| 836 | spectrum_cs_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 837 | return -ENODEV; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 838 | } /* spectrum_cs_config */ |
| 839 | |
| 840 | /* |
| 841 | * After a card is removed, spectrum_cs_release() will unregister the |
| 842 | * device, and release the PCMCIA configuration. If the device is |
| 843 | * still open, this will be postponed until it is closed. |
| 844 | */ |
| 845 | static void |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 846 | spectrum_cs_release(struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 847 | { |
| 848 | struct net_device *dev = link->priv; |
| 849 | struct orinoco_private *priv = netdev_priv(dev); |
| 850 | unsigned long flags; |
| 851 | |
| 852 | /* We're committed to taking the device away now, so mark the |
| 853 | * hardware as unavailable */ |
| 854 | spin_lock_irqsave(&priv->lock, flags); |
| 855 | priv->hw_unavailable++; |
| 856 | spin_unlock_irqrestore(&priv->lock, flags); |
| 857 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 858 | pcmcia_disable_device(link); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 859 | if (priv->hw.iobase) |
| 860 | ioport_unmap(priv->hw.iobase); |
| 861 | } /* spectrum_cs_release */ |
| 862 | |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 863 | |
| 864 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 865 | spectrum_cs_suspend(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 866 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 867 | struct net_device *dev = link->priv; |
| 868 | struct orinoco_private *priv = netdev_priv(dev); |
| 869 | unsigned long flags; |
| 870 | int err = 0; |
| 871 | |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 872 | /* Mark the device as stopped, to block IO until later */ |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 873 | spin_lock_irqsave(&priv->lock, flags); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 874 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 875 | err = __orinoco_down(dev); |
| 876 | if (err) |
| 877 | printk(KERN_WARNING "%s: Error %d downing interface\n", |
| 878 | dev->name, err); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 879 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 880 | netif_device_detach(dev); |
| 881 | priv->hw_unavailable++; |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 882 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 883 | spin_unlock_irqrestore(&priv->lock, flags); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 889 | spectrum_cs_resume(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 890 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 891 | struct net_device *dev = link->priv; |
| 892 | struct orinoco_private *priv = netdev_priv(dev); |
| 893 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 894 | netif_device_attach(dev); |
| 895 | priv->hw_unavailable--; |
| 896 | schedule_work(&priv->reset_work); |
| 897 | |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 898 | return 0; |
| 899 | } |
| 900 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 901 | |
| 902 | /********************************************************************/ |
| 903 | /* Module initialization */ |
| 904 | /********************************************************************/ |
| 905 | |
| 906 | /* Can't be declared "const" or the whole __initdata section will |
| 907 | * become const */ |
| 908 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION |
| 909 | " (Pavel Roskin <proski@gnu.org>," |
| 910 | " David Gibson <hermes@gibson.dropbear.id.au>, et al)"; |
| 911 | |
| 912 | static struct pcmcia_device_id spectrum_cs_ids[] = { |
Pavel Roskin | 4ebe2eb | 2006-04-07 04:10:32 -0400 | [diff] [blame] | 913 | PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 914 | PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */ |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame] | 915 | PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 916 | PCMCIA_DEVICE_NULL, |
| 917 | }; |
| 918 | MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids); |
| 919 | |
| 920 | static struct pcmcia_driver orinoco_driver = { |
| 921 | .owner = THIS_MODULE, |
| 922 | .drv = { |
| 923 | .name = DRIVER_NAME, |
| 924 | }, |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 925 | .probe = spectrum_cs_probe, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 926 | .remove = spectrum_cs_detach, |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 927 | .suspend = spectrum_cs_suspend, |
| 928 | .resume = spectrum_cs_resume, |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 929 | .id_table = spectrum_cs_ids, |
| 930 | }; |
| 931 | |
| 932 | static int __init |
| 933 | init_spectrum_cs(void) |
| 934 | { |
| 935 | printk(KERN_DEBUG "%s\n", version); |
| 936 | |
| 937 | return pcmcia_register_driver(&orinoco_driver); |
| 938 | } |
| 939 | |
| 940 | static void __exit |
| 941 | exit_spectrum_cs(void) |
| 942 | { |
| 943 | pcmcia_unregister_driver(&orinoco_driver); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | module_init(init_spectrum_cs); |
| 947 | module_exit(exit_spectrum_cs); |