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 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/init.h> |
Pavel Roskin | ef846bf | 2005-09-23 04:18:07 -0400 | [diff] [blame] | 27 | #include <linux/delay.h> |
Pavel Roskin | 65853b1 | 2005-09-16 02:15:13 -0400 | [diff] [blame] | 28 | #include <linux/firmware.h> |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 29 | #include <pcmcia/cs_types.h> |
| 30 | #include <pcmcia/cs.h> |
| 31 | #include <pcmcia/cistpl.h> |
| 32 | #include <pcmcia/cisreg.h> |
| 33 | #include <pcmcia/ds.h> |
| 34 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 35 | #include "orinoco.h" |
David Kilroy | f482eb7 | 2008-08-21 23:27:51 +0100 | [diff] [blame] | 36 | #include "hermes_dld.h" |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 37 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 38 | static const char primary_fw_name[] = "symbol_sp24t_prim_fw"; |
| 39 | static const char secondary_fw_name[] = "symbol_sp24t_sec_fw"; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 40 | |
| 41 | /********************************************************************/ |
| 42 | /* Module stuff */ |
| 43 | /********************************************************************/ |
| 44 | |
| 45 | MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>"); |
| 46 | MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader"); |
| 47 | MODULE_LICENSE("Dual MPL/GPL"); |
| 48 | |
| 49 | /* Module parameters */ |
| 50 | |
| 51 | /* Some D-Link cards have buggy CIS. They do work at 5v properly, but |
| 52 | * don't have any CIS entry for it. This workaround it... */ |
| 53 | static int ignore_cis_vcc; /* = 0 */ |
| 54 | module_param(ignore_cis_vcc, int, 0); |
| 55 | MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket"); |
| 56 | |
| 57 | /********************************************************************/ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 58 | /* Data structures */ |
| 59 | /********************************************************************/ |
| 60 | |
| 61 | /* PCMCIA specific device information (goes in the card field of |
| 62 | * struct orinoco_private */ |
| 63 | struct orinoco_pccard { |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 64 | struct pcmcia_device *p_dev; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 65 | dev_node_t node; |
| 66 | }; |
| 67 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 68 | /********************************************************************/ |
| 69 | /* Function prototypes */ |
| 70 | /********************************************************************/ |
| 71 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 72 | static int spectrum_cs_config(struct pcmcia_device *link); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 73 | static void spectrum_cs_release(struct pcmcia_device *link); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 74 | |
| 75 | /********************************************************************/ |
| 76 | /* Firmware downloader */ |
| 77 | /********************************************************************/ |
| 78 | |
| 79 | /* Position of PDA in the adapter memory */ |
| 80 | #define EEPROM_ADDR 0x3000 |
| 81 | #define EEPROM_LEN 0x200 |
| 82 | #define PDA_OFFSET 0x100 |
| 83 | |
| 84 | #define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET) |
| 85 | #define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2) |
| 86 | |
| 87 | /* Constants for the CISREG_CCSR register */ |
| 88 | #define HCR_RUN 0x07 /* run firmware after reset */ |
| 89 | #define HCR_IDLE 0x0E /* don't run firmware after reset */ |
| 90 | #define HCR_MEM16 0x10 /* memory width bit, should be preserved */ |
| 91 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 92 | /* End markers */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 93 | #define TEXT_END 0x1A /* End of text header */ |
| 94 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 95 | |
| 96 | #define CS_CHECK(fn, ret) \ |
| 97 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) |
| 98 | |
| 99 | /* |
| 100 | * Reset the card using configuration registers COR and CCSR. |
| 101 | * If IDLE is 1, stop the firmware, so that it can be safely rewritten. |
| 102 | */ |
| 103 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 104 | spectrum_reset(struct pcmcia_device *link, int idle) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 105 | { |
| 106 | int last_ret, last_fn; |
| 107 | conf_reg_t reg; |
| 108 | u_int save_cor; |
| 109 | |
| 110 | /* Doing it if hardware is gone is guaranteed crash */ |
Richard Purdie | c5ab964 | 2006-08-22 18:55:44 +0100 | [diff] [blame] | 111 | if (!pcmcia_dev_present(link)) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 112 | return -ENODEV; |
| 113 | |
| 114 | /* Save original COR value */ |
| 115 | reg.Function = 0; |
| 116 | reg.Action = CS_READ; |
| 117 | reg.Offset = CISREG_COR; |
| 118 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 119 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 120 | save_cor = reg.Value; |
| 121 | |
| 122 | /* Soft-Reset card */ |
| 123 | reg.Action = CS_WRITE; |
| 124 | reg.Offset = CISREG_COR; |
| 125 | reg.Value = (save_cor | COR_SOFT_RESET); |
| 126 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 127 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 128 | udelay(1000); |
| 129 | |
| 130 | /* Read CCSR */ |
| 131 | reg.Action = CS_READ; |
| 132 | reg.Offset = CISREG_CCSR; |
| 133 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 134 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * Start or stop the firmware. Memory width bit should be |
| 138 | * preserved from the value we've just read. |
| 139 | */ |
| 140 | reg.Action = CS_WRITE; |
| 141 | reg.Offset = CISREG_CCSR; |
| 142 | reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16); |
| 143 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 144 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 145 | udelay(1000); |
| 146 | |
| 147 | /* Restore original COR configuration index */ |
| 148 | reg.Action = CS_WRITE; |
| 149 | reg.Offset = CISREG_COR; |
| 150 | reg.Value = (save_cor & ~COR_SOFT_RESET); |
| 151 | CS_CHECK(AccessConfigurationRegister, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 152 | pcmcia_access_configuration_register(link, ®)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 153 | udelay(1000); |
| 154 | return 0; |
| 155 | |
| 156 | cs_failed: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 157 | cs_error(link, last_fn, last_ret); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 158 | return -ENODEV; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /* |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 163 | * Process a firmware image - stop the card, load the firmware, reset |
| 164 | * the card and make sure it responds. For the secondary firmware take |
| 165 | * care of the PDA - read it and then write it on top of the firmware. |
| 166 | */ |
| 167 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 168 | spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link, |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 169 | const unsigned char *image, const unsigned char *end, |
| 170 | int secondary) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 171 | { |
| 172 | int ret; |
| 173 | const unsigned char *ptr; |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 174 | const unsigned char *first_block; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 175 | |
| 176 | /* Plug Data Area (PDA) */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 177 | __le16 pda[PDA_WORDS]; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 178 | |
| 179 | /* Binary block begins after the 0x1A marker */ |
| 180 | ptr = image; |
| 181 | while (*ptr++ != TEXT_END); |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 182 | first_block = ptr; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 183 | |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 184 | /* Read the PDA from EEPROM */ |
Magnus Damm | 73ca66b | 2006-07-10 04:44:09 -0700 | [diff] [blame] | 185 | if (secondary) { |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 186 | ret = hermes_read_pda(hw, pda, PDA_ADDR, sizeof(pda), 1); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 187 | if (ret) |
| 188 | return ret; |
| 189 | } |
| 190 | |
| 191 | /* Stop the firmware, so that it can be safely rewritten */ |
| 192 | ret = spectrum_reset(link, 1); |
| 193 | if (ret) |
| 194 | return ret; |
| 195 | |
| 196 | /* Program the adapter with new firmware */ |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 197 | ret = hermes_program(hw, first_block, end); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 198 | if (ret) |
| 199 | return ret; |
| 200 | |
| 201 | /* Write the PDA to the adapter */ |
Magnus Damm | 73ca66b | 2006-07-10 04:44:09 -0700 | [diff] [blame] | 202 | if (secondary) { |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 203 | size_t len = hermes_blocks_length(first_block); |
| 204 | ptr = first_block + len; |
| 205 | ret = hermes_apply_pda(hw, ptr, pda); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 206 | if (ret) |
| 207 | return ret; |
| 208 | } |
| 209 | |
| 210 | /* Run the firmware */ |
| 211 | ret = spectrum_reset(link, 0); |
| 212 | if (ret) |
| 213 | return ret; |
| 214 | |
| 215 | /* Reset hermes chip and make sure it responds */ |
| 216 | ret = hermes_init(hw); |
| 217 | |
| 218 | /* hermes_reset() should return 0 with the secondary firmware */ |
Magnus Damm | 73ca66b | 2006-07-10 04:44:09 -0700 | [diff] [blame] | 219 | if (secondary && ret != 0) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 220 | return -ENODEV; |
| 221 | |
| 222 | /* And this should work with any firmware */ |
| 223 | if (!hermes_present(hw)) |
| 224 | return -ENODEV; |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | /* |
| 231 | * Download the firmware into the card, this also does a PCMCIA soft |
| 232 | * reset on the card, to make sure it's in a sane state. |
| 233 | */ |
| 234 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 235 | spectrum_dl_firmware(hermes_t *hw, struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 236 | { |
| 237 | int ret; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 238 | const struct firmware *fw_entry; |
| 239 | |
| 240 | if (request_firmware(&fw_entry, primary_fw_name, |
Magnus Damm | 73ca66b | 2006-07-10 04:44:09 -0700 | [diff] [blame] | 241 | &handle_to_dev(link)) != 0) { |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 242 | printk(KERN_ERR PFX "Cannot find firmware: %s\n", |
| 243 | primary_fw_name); |
| 244 | return -ENOENT; |
| 245 | } |
| 246 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 247 | /* Load primary firmware */ |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 248 | ret = spectrum_dl_image(hw, link, fw_entry->data, |
| 249 | fw_entry->data + fw_entry->size, 0); |
Magnus Damm | 73ca66b | 2006-07-10 04:44:09 -0700 | [diff] [blame] | 250 | release_firmware(fw_entry); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 251 | if (ret) { |
| 252 | printk(KERN_ERR PFX "Primary firmware download failed\n"); |
| 253 | return ret; |
| 254 | } |
| 255 | |
Magnus Damm | 73ca66b | 2006-07-10 04:44:09 -0700 | [diff] [blame] | 256 | if (request_firmware(&fw_entry, secondary_fw_name, |
| 257 | &handle_to_dev(link)) != 0) { |
| 258 | printk(KERN_ERR PFX "Cannot find firmware: %s\n", |
| 259 | secondary_fw_name); |
| 260 | return -ENOENT; |
| 261 | } |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 262 | |
Magnus Damm | 73ca66b | 2006-07-10 04:44:09 -0700 | [diff] [blame] | 263 | /* Load secondary firmware */ |
David Kilroy | e233418 | 2008-08-21 23:27:52 +0100 | [diff] [blame^] | 264 | ret = spectrum_dl_image(hw, link, fw_entry->data, |
| 265 | fw_entry->data + fw_entry->size, 1); |
Magnus Damm | 73ca66b | 2006-07-10 04:44:09 -0700 | [diff] [blame] | 266 | release_firmware(fw_entry); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 267 | if (ret) { |
| 268 | printk(KERN_ERR PFX "Secondary firmware download failed\n"); |
| 269 | } |
| 270 | |
| 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | /********************************************************************/ |
| 275 | /* Device methods */ |
| 276 | /********************************************************************/ |
| 277 | |
| 278 | static int |
| 279 | spectrum_cs_hard_reset(struct orinoco_private *priv) |
| 280 | { |
| 281 | struct orinoco_pccard *card = priv->card; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 282 | struct pcmcia_device *link = card->p_dev; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 283 | int err; |
| 284 | |
| 285 | if (!hermes_present(&priv->hw)) { |
| 286 | /* The firmware needs to be reloaded */ |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 287 | if (spectrum_dl_firmware(&priv->hw, link) != 0) { |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 288 | printk(KERN_ERR PFX "Firmware download failed\n"); |
| 289 | err = -ENODEV; |
| 290 | } |
| 291 | } else { |
| 292 | /* Soft reset using COR and HCR */ |
| 293 | spectrum_reset(link, 0); |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | /********************************************************************/ |
| 300 | /* PCMCIA stuff */ |
| 301 | /********************************************************************/ |
| 302 | |
| 303 | /* |
| 304 | * This creates an "instance" of the driver, allocating local data |
| 305 | * structures for one device. The device is registered with Card |
| 306 | * Services. |
| 307 | * |
| 308 | * The dev_link structure is initialized, but we don't actually |
| 309 | * configure the card at this point -- we wait until we receive a card |
| 310 | * insertion event. */ |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 311 | static int |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 312 | spectrum_cs_probe(struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 313 | { |
| 314 | struct net_device *dev; |
| 315 | struct orinoco_private *priv; |
| 316 | struct orinoco_pccard *card; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 317 | |
| 318 | dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset); |
| 319 | if (! dev) |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 320 | return -ENOMEM; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 321 | priv = netdev_priv(dev); |
| 322 | card = priv->card; |
| 323 | |
| 324 | /* Link both structures together */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 325 | card->p_dev = link; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 326 | link->priv = dev; |
| 327 | |
| 328 | /* Interrupt setup */ |
| 329 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; |
| 330 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; |
| 331 | link->irq.Handler = orinoco_interrupt; |
| 332 | link->irq.Instance = dev; |
| 333 | |
| 334 | /* General socket configuration defaults can go here. In this |
| 335 | * client, we assume very little, and rely on the CIS for |
| 336 | * almost everything. In most clients, many details (i.e., |
| 337 | * number, sizes, and attributes of IO windows) are fixed by |
| 338 | * the nature of the device, and can be hard-wired here. */ |
| 339 | link->conf.Attributes = 0; |
| 340 | link->conf.IntType = INT_MEMORY_AND_IO; |
| 341 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 342 | return spectrum_cs_config(link); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 343 | } /* spectrum_cs_attach */ |
| 344 | |
| 345 | /* |
| 346 | * This deletes a driver "instance". The device is de-registered with |
| 347 | * Card Services. If it has been released, all local data structures |
| 348 | * are freed. Otherwise, the structures will be freed when the device |
| 349 | * is released. |
| 350 | */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 351 | static void spectrum_cs_detach(struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 352 | { |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 353 | struct net_device *dev = link->priv; |
| 354 | |
Pavel Roskin | e4f4f98 | 2006-05-01 02:13:24 -0400 | [diff] [blame] | 355 | if (link->dev_node) |
| 356 | unregister_netdev(dev); |
| 357 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 358 | spectrum_cs_release(link); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 359 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 360 | free_orinocodev(dev); |
| 361 | } /* spectrum_cs_detach */ |
| 362 | |
| 363 | /* |
| 364 | * spectrum_cs_config() is scheduled to run after a CARD_INSERTION |
| 365 | * event is received, to configure the PCMCIA socket, and to make the |
| 366 | * device available to the system. |
| 367 | */ |
| 368 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 369 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 370 | spectrum_cs_config(struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 371 | { |
| 372 | struct net_device *dev = link->priv; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 373 | struct orinoco_private *priv = netdev_priv(dev); |
| 374 | struct orinoco_pccard *card = priv->card; |
| 375 | hermes_t *hw = &priv->hw; |
| 376 | int last_fn, last_ret; |
| 377 | u_char buf[64]; |
| 378 | config_info_t conf; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 379 | tuple_t tuple; |
| 380 | cisparse_t parse; |
| 381 | void __iomem *mem; |
| 382 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 383 | /* Look up the current Vcc */ |
| 384 | CS_CHECK(GetConfigurationInfo, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 385 | pcmcia_get_configuration_info(link, &conf)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * In this loop, we scan the CIS for configuration table |
| 389 | * entries, each of which describes a valid card |
| 390 | * configuration, including voltage, IO window, memory window, |
| 391 | * and interrupt settings. |
| 392 | * |
| 393 | * We make no assumptions about the card to be configured: we |
| 394 | * use just the information available in the CIS. In an ideal |
| 395 | * world, this would work for any PCMCIA card, but it requires |
| 396 | * a complete and accurate CIS. In practice, a driver usually |
| 397 | * "knows" most of these things without consulting the CIS, |
| 398 | * and most client drivers will only use the CIS to fill in |
| 399 | * implementation-defined details. |
| 400 | */ |
| 401 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; |
Dominik Brodowski | af2b3b5 | 2006-10-25 21:49:27 -0400 | [diff] [blame] | 402 | tuple.Attributes = 0; |
| 403 | tuple.TupleData = buf; |
| 404 | tuple.TupleDataMax = sizeof(buf); |
| 405 | tuple.TupleOffset = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 406 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 407 | while (1) { |
| 408 | cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); |
| 409 | cistpl_cftable_entry_t dflt = { .index = 0 }; |
| 410 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 411 | if ( (pcmcia_get_tuple_data(link, &tuple) != 0) |
| 412 | || (pcmcia_parse_tuple(link, &tuple, &parse) != 0)) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 413 | goto next_entry; |
| 414 | |
| 415 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) |
| 416 | dflt = *cfg; |
| 417 | if (cfg->index == 0) |
| 418 | goto next_entry; |
| 419 | link->conf.ConfigIndex = cfg->index; |
| 420 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 421 | /* Use power settings for Vcc and Vpp if present */ |
| 422 | /* Note that the CIS values need to be rescaled */ |
| 423 | if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 424 | if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) { |
| 425 | DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000); |
| 426 | if (!ignore_cis_vcc) |
| 427 | goto next_entry; |
| 428 | } |
| 429 | } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 430 | if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) { |
| 431 | DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000); |
| 432 | if(!ignore_cis_vcc) |
| 433 | goto next_entry; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 438 | link->conf.Vpp = |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 439 | cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 440 | else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 441 | link->conf.Vpp = |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 442 | dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 443 | |
| 444 | /* Do we need to allocate an interrupt? */ |
| 445 | link->conf.Attributes |= CONF_ENABLE_IRQ; |
| 446 | |
| 447 | /* IO window settings */ |
| 448 | link->io.NumPorts1 = link->io.NumPorts2 = 0; |
| 449 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { |
| 450 | cistpl_io_t *io = |
| 451 | (cfg->io.nwin) ? &cfg->io : &dflt.io; |
| 452 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 453 | if (!(io->flags & CISTPL_IO_8BIT)) |
| 454 | link->io.Attributes1 = |
| 455 | IO_DATA_PATH_WIDTH_16; |
| 456 | if (!(io->flags & CISTPL_IO_16BIT)) |
| 457 | link->io.Attributes1 = |
| 458 | IO_DATA_PATH_WIDTH_8; |
| 459 | link->io.IOAddrLines = |
| 460 | io->flags & CISTPL_IO_LINES_MASK; |
| 461 | link->io.BasePort1 = io->win[0].base; |
| 462 | link->io.NumPorts1 = io->win[0].len; |
| 463 | if (io->nwin > 1) { |
| 464 | link->io.Attributes2 = |
| 465 | link->io.Attributes1; |
| 466 | link->io.BasePort2 = io->win[1].base; |
| 467 | link->io.NumPorts2 = io->win[1].len; |
| 468 | } |
| 469 | |
| 470 | /* This reserves IO space but doesn't actually enable it */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 471 | if (pcmcia_request_io(link, &link->io) != 0) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 472 | goto next_entry; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | /* If we got this far, we're cool! */ |
| 477 | |
| 478 | break; |
| 479 | |
| 480 | next_entry: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 481 | pcmcia_disable_device(link); |
| 482 | last_ret = pcmcia_get_next_tuple(link, &tuple); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 483 | if (last_ret == CS_NO_MORE_ITEMS) { |
| 484 | printk(KERN_ERR PFX "GetNextTuple(): No matching " |
| 485 | "CIS configuration. Maybe you need the " |
| 486 | "ignore_cis_vcc=1 parameter.\n"); |
| 487 | goto cs_failed; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /* |
| 492 | * Allocate an interrupt line. Note that this does not assign |
| 493 | * a handler to the interrupt, unless the 'Handler' member of |
| 494 | * the irq structure is initialized. |
| 495 | */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 496 | CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 497 | |
| 498 | /* We initialize the hermes structure before completing PCMCIA |
| 499 | * configuration just in case the interrupt handler gets |
| 500 | * called. */ |
| 501 | mem = ioport_map(link->io.BasePort1, link->io.NumPorts1); |
| 502 | if (!mem) |
| 503 | goto cs_failed; |
| 504 | |
| 505 | hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); |
| 506 | |
| 507 | /* |
| 508 | * This actually configures the PCMCIA socket -- setting up |
| 509 | * the I/O windows and the interrupt mapping, and putting the |
| 510 | * card and host interface into "Memory and IO" mode. |
| 511 | */ |
| 512 | CS_CHECK(RequestConfiguration, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 513 | pcmcia_request_configuration(link, &link->conf)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 514 | |
| 515 | /* Ok, we have the configuration, prepare to register the netdev */ |
| 516 | dev->base_addr = link->io.BasePort1; |
| 517 | dev->irq = link->irq.AssignedIRQ; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 518 | card->node.major = card->node.minor = 0; |
| 519 | |
| 520 | /* Reset card and download firmware */ |
| 521 | if (spectrum_cs_hard_reset(priv) != 0) { |
| 522 | goto failed; |
| 523 | } |
| 524 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 525 | SET_NETDEV_DEV(dev, &handle_to_dev(link)); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 526 | /* Tell the stack we exist */ |
| 527 | if (register_netdev(dev) != 0) { |
| 528 | printk(KERN_ERR PFX "register_netdev() failed\n"); |
| 529 | goto failed; |
| 530 | } |
| 531 | |
| 532 | /* At this point, the dev_node_t structure(s) needs to be |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 533 | * initialized and arranged in a linked list at link->dev_node. */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 534 | strcpy(card->node.dev_name, dev->name); |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 535 | 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] | 536 | used to indicate that the |
| 537 | net_device has been registered */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 538 | |
| 539 | /* Finally, report what we've done */ |
Pavel Roskin | 9a568da | 2006-05-01 02:13:26 -0400 | [diff] [blame] | 540 | printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io " |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 541 | "0x%04x-0x%04x\n", dev->name, dev->dev.parent->bus_id, |
Pavel Roskin | 9a568da | 2006-05-01 02:13:26 -0400 | [diff] [blame] | 542 | link->irq.AssignedIRQ, link->io.BasePort1, |
| 543 | link->io.BasePort1 + link->io.NumPorts1 - 1); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 544 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 545 | return 0; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 546 | |
| 547 | cs_failed: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 548 | cs_error(link, last_fn, last_ret); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 549 | |
| 550 | failed: |
| 551 | spectrum_cs_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 552 | return -ENODEV; |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 553 | } /* spectrum_cs_config */ |
| 554 | |
| 555 | /* |
| 556 | * After a card is removed, spectrum_cs_release() will unregister the |
| 557 | * device, and release the PCMCIA configuration. If the device is |
| 558 | * still open, this will be postponed until it is closed. |
| 559 | */ |
| 560 | static void |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 561 | spectrum_cs_release(struct pcmcia_device *link) |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 562 | { |
| 563 | struct net_device *dev = link->priv; |
| 564 | struct orinoco_private *priv = netdev_priv(dev); |
| 565 | unsigned long flags; |
| 566 | |
| 567 | /* We're committed to taking the device away now, so mark the |
| 568 | * hardware as unavailable */ |
| 569 | spin_lock_irqsave(&priv->lock, flags); |
| 570 | priv->hw_unavailable++; |
| 571 | spin_unlock_irqrestore(&priv->lock, flags); |
| 572 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 573 | pcmcia_disable_device(link); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 574 | if (priv->hw.iobase) |
| 575 | ioport_unmap(priv->hw.iobase); |
| 576 | } /* spectrum_cs_release */ |
| 577 | |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 578 | |
| 579 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 580 | spectrum_cs_suspend(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 581 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 582 | struct net_device *dev = link->priv; |
| 583 | struct orinoco_private *priv = netdev_priv(dev); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 584 | int err = 0; |
| 585 | |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 586 | /* Mark the device as stopped, to block IO until later */ |
Pavel Roskin | 6cbaa33 | 2006-05-01 02:13:28 -0400 | [diff] [blame] | 587 | spin_lock(&priv->lock); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 588 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 589 | err = __orinoco_down(dev); |
| 590 | if (err) |
| 591 | printk(KERN_WARNING "%s: Error %d downing interface\n", |
| 592 | dev->name, err); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 593 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 594 | netif_device_detach(dev); |
| 595 | priv->hw_unavailable++; |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 596 | |
Pavel Roskin | 6cbaa33 | 2006-05-01 02:13:28 -0400 | [diff] [blame] | 597 | spin_unlock(&priv->lock); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 598 | |
Pavel Roskin | 6cbaa33 | 2006-05-01 02:13:28 -0400 | [diff] [blame] | 599 | return err; |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | static int |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 603 | spectrum_cs_resume(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 604 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 605 | struct net_device *dev = link->priv; |
| 606 | struct orinoco_private *priv = netdev_priv(dev); |
| 607 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 608 | netif_device_attach(dev); |
| 609 | priv->hw_unavailable--; |
| 610 | schedule_work(&priv->reset_work); |
| 611 | |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 612 | return 0; |
| 613 | } |
| 614 | |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 615 | |
| 616 | /********************************************************************/ |
| 617 | /* Module initialization */ |
| 618 | /********************************************************************/ |
| 619 | |
| 620 | /* Can't be declared "const" or the whole __initdata section will |
| 621 | * become const */ |
| 622 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION |
| 623 | " (Pavel Roskin <proski@gnu.org>," |
| 624 | " David Gibson <hermes@gibson.dropbear.id.au>, et al)"; |
| 625 | |
| 626 | static struct pcmcia_device_id spectrum_cs_ids[] = { |
Pavel Roskin | 4ebe2eb | 2006-04-07 04:10:32 -0400 | [diff] [blame] | 627 | PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */ |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 628 | PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */ |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame] | 629 | 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] | 630 | PCMCIA_DEVICE_NULL, |
| 631 | }; |
| 632 | MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids); |
| 633 | |
| 634 | static struct pcmcia_driver orinoco_driver = { |
| 635 | .owner = THIS_MODULE, |
| 636 | .drv = { |
| 637 | .name = DRIVER_NAME, |
| 638 | }, |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 639 | .probe = spectrum_cs_probe, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 640 | .remove = spectrum_cs_detach, |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 641 | .suspend = spectrum_cs_suspend, |
| 642 | .resume = spectrum_cs_resume, |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 643 | .id_table = spectrum_cs_ids, |
| 644 | }; |
| 645 | |
| 646 | static int __init |
| 647 | init_spectrum_cs(void) |
| 648 | { |
| 649 | printk(KERN_DEBUG "%s\n", version); |
| 650 | |
| 651 | return pcmcia_register_driver(&orinoco_driver); |
| 652 | } |
| 653 | |
| 654 | static void __exit |
| 655 | exit_spectrum_cs(void) |
| 656 | { |
| 657 | pcmcia_unregister_driver(&orinoco_driver); |
Pavel Roskin | 3a48c4c | 2005-09-01 20:10:06 -0400 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | module_init(init_spectrum_cs); |
| 661 | module_exit(exit_spectrum_cs); |