blob: 579873d0e8c90be47453bc779b883ca9808d8bbb [file] [log] [blame]
Pavel Roskin3a48c4c2005-09-01 20:10:06 -04001/*
2 * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as
Pavel Roskin4ebe2eb2006-04-07 04:10:32 -04003 * Symbol Wireless Networker LA4137, CompactFlash cards by Socket
Pavel Roskin3a48c4c2005-09-01 20:10:06 -04004 * 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 Roskin3a48c4c2005-09-01 20:10:06 -040024#include <linux/module.h>
25#include <linux/kernel.h>
26#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040027#include <linux/delay.h>
Pavel Roskin65853b12005-09-16 02:15:13 -040028#include <linux/firmware.h>
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040029#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 Roskin3a48c4c2005-09-01 20:10:06 -040035#include "orinoco.h"
David Kilroyf482eb72008-08-21 23:27:51 +010036#include "hermes_dld.h"
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040037
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040038static const char primary_fw_name[] = "symbol_sp24t_prim_fw";
39static const char secondary_fw_name[] = "symbol_sp24t_sec_fw";
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040040
41/********************************************************************/
42/* Module stuff */
43/********************************************************************/
44
45MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
46MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader");
47MODULE_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... */
53static int ignore_cis_vcc; /* = 0 */
54module_param(ignore_cis_vcc, int, 0);
55MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket");
56
57/********************************************************************/
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040058/* Data structures */
59/********************************************************************/
60
61/* PCMCIA specific device information (goes in the card field of
62 * struct orinoco_private */
63struct orinoco_pccard {
Dominik Brodowskifd238232006-03-05 10:45:09 +010064 struct pcmcia_device *p_dev;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040065 dev_node_t node;
66};
67
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040068/********************************************************************/
69/* Function prototypes */
70/********************************************************************/
71
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020072static int spectrum_cs_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020073static void spectrum_cs_release(struct pcmcia_device *link);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040074
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 Roskin3a48c4c2005-09-01 20:10:06 -040092/* End markers */
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040093#define TEXT_END 0x1A /* End of text header */
94
Pavel Roskin3a48c4c2005-09-01 20:10:06 -040095
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 */
103static int
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200104spectrum_reset(struct pcmcia_device *link, int idle)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400105{
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 Purdiec5ab9642006-08-22 18:55:44 +0100111 if (!pcmcia_dev_present(link))
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400112 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 Brodowskifba395e2006-03-31 17:21:06 +0200119 pcmcia_access_configuration_register(link, &reg));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400120 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 Brodowskifba395e2006-03-31 17:21:06 +0200127 pcmcia_access_configuration_register(link, &reg));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400128 udelay(1000);
129
130 /* Read CCSR */
131 reg.Action = CS_READ;
132 reg.Offset = CISREG_CCSR;
133 CS_CHECK(AccessConfigurationRegister,
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200134 pcmcia_access_configuration_register(link, &reg));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400135
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 Brodowskifba395e2006-03-31 17:21:06 +0200144 pcmcia_access_configuration_register(link, &reg));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400145 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 Brodowskifba395e2006-03-31 17:21:06 +0200152 pcmcia_access_configuration_register(link, &reg));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400153 udelay(1000);
154 return 0;
155
156 cs_failed:
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200157 cs_error(link, last_fn, last_ret);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400158 return -ENODEV;
159}
160
161
162/*
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400163 * 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 */
167static int
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200168spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link,
Magnus Damm73ca66b2006-07-10 04:44:09 -0700169 const unsigned char *image, int secondary)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400170{
171 int ret;
172 const unsigned char *ptr;
173 const struct dblock *first_block;
174
175 /* Plug Data Area (PDA) */
Pavel Roskind133ae42005-09-23 04:18:06 -0400176 __le16 pda[PDA_WORDS];
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400177
178 /* Binary block begins after the 0x1A marker */
179 ptr = image;
180 while (*ptr++ != TEXT_END);
181 first_block = (const struct dblock *) ptr;
182
183 /* Read the PDA */
Magnus Damm73ca66b2006-07-10 04:44:09 -0700184 if (secondary) {
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400185 ret = spectrum_read_pda(hw, pda, sizeof(pda));
186 if (ret)
187 return ret;
188 }
189
190 /* Stop the firmware, so that it can be safely rewritten */
191 ret = spectrum_reset(link, 1);
192 if (ret)
193 return ret;
194
195 /* Program the adapter with new firmware */
196 ret = spectrum_load_blocks(hw, first_block);
197 if (ret)
198 return ret;
199
200 /* Write the PDA to the adapter */
Magnus Damm73ca66b2006-07-10 04:44:09 -0700201 if (secondary) {
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400202 ret = spectrum_apply_pda(hw, first_block, pda);
203 if (ret)
204 return ret;
205 }
206
207 /* Run the firmware */
208 ret = spectrum_reset(link, 0);
209 if (ret)
210 return ret;
211
212 /* Reset hermes chip and make sure it responds */
213 ret = hermes_init(hw);
214
215 /* hermes_reset() should return 0 with the secondary firmware */
Magnus Damm73ca66b2006-07-10 04:44:09 -0700216 if (secondary && ret != 0)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400217 return -ENODEV;
218
219 /* And this should work with any firmware */
220 if (!hermes_present(hw))
221 return -ENODEV;
222
223 return 0;
224}
225
226
227/*
228 * Download the firmware into the card, this also does a PCMCIA soft
229 * reset on the card, to make sure it's in a sane state.
230 */
231static int
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200232spectrum_dl_firmware(hermes_t *hw, struct pcmcia_device *link)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400233{
234 int ret;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400235 const struct firmware *fw_entry;
236
237 if (request_firmware(&fw_entry, primary_fw_name,
Magnus Damm73ca66b2006-07-10 04:44:09 -0700238 &handle_to_dev(link)) != 0) {
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400239 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
240 primary_fw_name);
241 return -ENOENT;
242 }
243
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400244 /* Load primary firmware */
Magnus Damm73ca66b2006-07-10 04:44:09 -0700245 ret = spectrum_dl_image(hw, link, fw_entry->data, 0);
246 release_firmware(fw_entry);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400247 if (ret) {
248 printk(KERN_ERR PFX "Primary firmware download failed\n");
249 return ret;
250 }
251
Magnus Damm73ca66b2006-07-10 04:44:09 -0700252 if (request_firmware(&fw_entry, secondary_fw_name,
253 &handle_to_dev(link)) != 0) {
254 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
255 secondary_fw_name);
256 return -ENOENT;
257 }
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400258
Magnus Damm73ca66b2006-07-10 04:44:09 -0700259 /* Load secondary firmware */
260 ret = spectrum_dl_image(hw, link, fw_entry->data, 1);
261 release_firmware(fw_entry);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400262 if (ret) {
263 printk(KERN_ERR PFX "Secondary firmware download failed\n");
264 }
265
266 return ret;
267}
268
269/********************************************************************/
270/* Device methods */
271/********************************************************************/
272
273static int
274spectrum_cs_hard_reset(struct orinoco_private *priv)
275{
276 struct orinoco_pccard *card = priv->card;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200277 struct pcmcia_device *link = card->p_dev;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400278 int err;
279
280 if (!hermes_present(&priv->hw)) {
281 /* The firmware needs to be reloaded */
Dominik Brodowskifd238232006-03-05 10:45:09 +0100282 if (spectrum_dl_firmware(&priv->hw, link) != 0) {
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400283 printk(KERN_ERR PFX "Firmware download failed\n");
284 err = -ENODEV;
285 }
286 } else {
287 /* Soft reset using COR and HCR */
288 spectrum_reset(link, 0);
289 }
290
291 return 0;
292}
293
294/********************************************************************/
295/* PCMCIA stuff */
296/********************************************************************/
297
298/*
299 * This creates an "instance" of the driver, allocating local data
300 * structures for one device. The device is registered with Card
301 * Services.
302 *
303 * The dev_link structure is initialized, but we don't actually
304 * configure the card at this point -- we wait until we receive a card
305 * insertion event. */
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100306static int
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200307spectrum_cs_probe(struct pcmcia_device *link)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400308{
309 struct net_device *dev;
310 struct orinoco_private *priv;
311 struct orinoco_pccard *card;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400312
313 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset);
314 if (! dev)
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100315 return -ENOMEM;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400316 priv = netdev_priv(dev);
317 card = priv->card;
318
319 /* Link both structures together */
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200320 card->p_dev = link;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400321 link->priv = dev;
322
323 /* Interrupt setup */
324 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
325 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
326 link->irq.Handler = orinoco_interrupt;
327 link->irq.Instance = dev;
328
329 /* General socket configuration defaults can go here. In this
330 * client, we assume very little, and rely on the CIS for
331 * almost everything. In most clients, many details (i.e.,
332 * number, sizes, and attributes of IO windows) are fixed by
333 * the nature of the device, and can be hard-wired here. */
334 link->conf.Attributes = 0;
335 link->conf.IntType = INT_MEMORY_AND_IO;
336
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200337 return spectrum_cs_config(link);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400338} /* spectrum_cs_attach */
339
340/*
341 * This deletes a driver "instance". The device is de-registered with
342 * Card Services. If it has been released, all local data structures
343 * are freed. Otherwise, the structures will be freed when the device
344 * is released.
345 */
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200346static void spectrum_cs_detach(struct pcmcia_device *link)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400347{
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400348 struct net_device *dev = link->priv;
349
Pavel Roskine4f4f982006-05-01 02:13:24 -0400350 if (link->dev_node)
351 unregister_netdev(dev);
352
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100353 spectrum_cs_release(link);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400354
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400355 free_orinocodev(dev);
356} /* spectrum_cs_detach */
357
358/*
359 * spectrum_cs_config() is scheduled to run after a CARD_INSERTION
360 * event is received, to configure the PCMCIA socket, and to make the
361 * device available to the system.
362 */
363
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200364static int
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200365spectrum_cs_config(struct pcmcia_device *link)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400366{
367 struct net_device *dev = link->priv;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400368 struct orinoco_private *priv = netdev_priv(dev);
369 struct orinoco_pccard *card = priv->card;
370 hermes_t *hw = &priv->hw;
371 int last_fn, last_ret;
372 u_char buf[64];
373 config_info_t conf;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400374 tuple_t tuple;
375 cisparse_t parse;
376 void __iomem *mem;
377
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400378 /* Look up the current Vcc */
379 CS_CHECK(GetConfigurationInfo,
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200380 pcmcia_get_configuration_info(link, &conf));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400381
382 /*
383 * In this loop, we scan the CIS for configuration table
384 * entries, each of which describes a valid card
385 * configuration, including voltage, IO window, memory window,
386 * and interrupt settings.
387 *
388 * We make no assumptions about the card to be configured: we
389 * use just the information available in the CIS. In an ideal
390 * world, this would work for any PCMCIA card, but it requires
391 * a complete and accurate CIS. In practice, a driver usually
392 * "knows" most of these things without consulting the CIS,
393 * and most client drivers will only use the CIS to fill in
394 * implementation-defined details.
395 */
396 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
Dominik Brodowskiaf2b3b52006-10-25 21:49:27 -0400397 tuple.Attributes = 0;
398 tuple.TupleData = buf;
399 tuple.TupleDataMax = sizeof(buf);
400 tuple.TupleOffset = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200401 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400402 while (1) {
403 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
404 cistpl_cftable_entry_t dflt = { .index = 0 };
405
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200406 if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
407 || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400408 goto next_entry;
409
410 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
411 dflt = *cfg;
412 if (cfg->index == 0)
413 goto next_entry;
414 link->conf.ConfigIndex = cfg->index;
415
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400416 /* Use power settings for Vcc and Vpp if present */
417 /* Note that the CIS values need to be rescaled */
418 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
419 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
420 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
421 if (!ignore_cis_vcc)
422 goto next_entry;
423 }
424 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
425 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
426 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
427 if(!ignore_cis_vcc)
428 goto next_entry;
429 }
430 }
431
432 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
Dominik Brodowski70294b42006-01-15 12:43:16 +0100433 link->conf.Vpp =
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400434 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
435 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
Dominik Brodowski70294b42006-01-15 12:43:16 +0100436 link->conf.Vpp =
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400437 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
438
439 /* Do we need to allocate an interrupt? */
440 link->conf.Attributes |= CONF_ENABLE_IRQ;
441
442 /* IO window settings */
443 link->io.NumPorts1 = link->io.NumPorts2 = 0;
444 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
445 cistpl_io_t *io =
446 (cfg->io.nwin) ? &cfg->io : &dflt.io;
447 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
448 if (!(io->flags & CISTPL_IO_8BIT))
449 link->io.Attributes1 =
450 IO_DATA_PATH_WIDTH_16;
451 if (!(io->flags & CISTPL_IO_16BIT))
452 link->io.Attributes1 =
453 IO_DATA_PATH_WIDTH_8;
454 link->io.IOAddrLines =
455 io->flags & CISTPL_IO_LINES_MASK;
456 link->io.BasePort1 = io->win[0].base;
457 link->io.NumPorts1 = io->win[0].len;
458 if (io->nwin > 1) {
459 link->io.Attributes2 =
460 link->io.Attributes1;
461 link->io.BasePort2 = io->win[1].base;
462 link->io.NumPorts2 = io->win[1].len;
463 }
464
465 /* This reserves IO space but doesn't actually enable it */
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200466 if (pcmcia_request_io(link, &link->io) != 0)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400467 goto next_entry;
468 }
469
470
471 /* If we got this far, we're cool! */
472
473 break;
474
475 next_entry:
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200476 pcmcia_disable_device(link);
477 last_ret = pcmcia_get_next_tuple(link, &tuple);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400478 if (last_ret == CS_NO_MORE_ITEMS) {
479 printk(KERN_ERR PFX "GetNextTuple(): No matching "
480 "CIS configuration. Maybe you need the "
481 "ignore_cis_vcc=1 parameter.\n");
482 goto cs_failed;
483 }
484 }
485
486 /*
487 * Allocate an interrupt line. Note that this does not assign
488 * a handler to the interrupt, unless the 'Handler' member of
489 * the irq structure is initialized.
490 */
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200491 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400492
493 /* We initialize the hermes structure before completing PCMCIA
494 * configuration just in case the interrupt handler gets
495 * called. */
496 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1);
497 if (!mem)
498 goto cs_failed;
499
500 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
501
502 /*
503 * This actually configures the PCMCIA socket -- setting up
504 * the I/O windows and the interrupt mapping, and putting the
505 * card and host interface into "Memory and IO" mode.
506 */
507 CS_CHECK(RequestConfiguration,
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200508 pcmcia_request_configuration(link, &link->conf));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400509
510 /* Ok, we have the configuration, prepare to register the netdev */
511 dev->base_addr = link->io.BasePort1;
512 dev->irq = link->irq.AssignedIRQ;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400513 card->node.major = card->node.minor = 0;
514
515 /* Reset card and download firmware */
516 if (spectrum_cs_hard_reset(priv) != 0) {
517 goto failed;
518 }
519
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200520 SET_NETDEV_DEV(dev, &handle_to_dev(link));
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400521 /* Tell the stack we exist */
522 if (register_netdev(dev) != 0) {
523 printk(KERN_ERR PFX "register_netdev() failed\n");
524 goto failed;
525 }
526
527 /* At this point, the dev_node_t structure(s) needs to be
Dominik Brodowskifd238232006-03-05 10:45:09 +0100528 * initialized and arranged in a linked list at link->dev_node. */
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400529 strcpy(card->node.dev_name, dev->name);
Dominik Brodowskifd238232006-03-05 10:45:09 +0100530 link->dev_node = &card->node; /* link->dev_node being non-NULL is also
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400531 used to indicate that the
532 net_device has been registered */
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400533
534 /* Finally, report what we've done */
Pavel Roskin9a568da2006-05-01 02:13:26 -0400535 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io "
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700536 "0x%04x-0x%04x\n", dev->name, dev->dev.parent->bus_id,
Pavel Roskin9a568da2006-05-01 02:13:26 -0400537 link->irq.AssignedIRQ, link->io.BasePort1,
538 link->io.BasePort1 + link->io.NumPorts1 - 1);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400539
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200540 return 0;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400541
542 cs_failed:
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200543 cs_error(link, last_fn, last_ret);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400544
545 failed:
546 spectrum_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200547 return -ENODEV;
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400548} /* spectrum_cs_config */
549
550/*
551 * After a card is removed, spectrum_cs_release() will unregister the
552 * device, and release the PCMCIA configuration. If the device is
553 * still open, this will be postponed until it is closed.
554 */
555static void
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200556spectrum_cs_release(struct pcmcia_device *link)
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400557{
558 struct net_device *dev = link->priv;
559 struct orinoco_private *priv = netdev_priv(dev);
560 unsigned long flags;
561
562 /* We're committed to taking the device away now, so mark the
563 * hardware as unavailable */
564 spin_lock_irqsave(&priv->lock, flags);
565 priv->hw_unavailable++;
566 spin_unlock_irqrestore(&priv->lock, flags);
567
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200568 pcmcia_disable_device(link);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400569 if (priv->hw.iobase)
570 ioport_unmap(priv->hw.iobase);
571} /* spectrum_cs_release */
572
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100573
574static int
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200575spectrum_cs_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100576{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100577 struct net_device *dev = link->priv;
578 struct orinoco_private *priv = netdev_priv(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100579 int err = 0;
580
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100581 /* Mark the device as stopped, to block IO until later */
Pavel Roskin6cbaa332006-05-01 02:13:28 -0400582 spin_lock(&priv->lock);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100583
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100584 err = __orinoco_down(dev);
585 if (err)
586 printk(KERN_WARNING "%s: Error %d downing interface\n",
587 dev->name, err);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100588
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100589 netif_device_detach(dev);
590 priv->hw_unavailable++;
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100591
Pavel Roskin6cbaa332006-05-01 02:13:28 -0400592 spin_unlock(&priv->lock);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100593
Pavel Roskin6cbaa332006-05-01 02:13:28 -0400594 return err;
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100595}
596
597static int
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200598spectrum_cs_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100599{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100600 struct net_device *dev = link->priv;
601 struct orinoco_private *priv = netdev_priv(dev);
602
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100603 netif_device_attach(dev);
604 priv->hw_unavailable--;
605 schedule_work(&priv->reset_work);
606
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100607 return 0;
608}
609
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400610
611/********************************************************************/
612/* Module initialization */
613/********************************************************************/
614
615/* Can't be declared "const" or the whole __initdata section will
616 * become const */
617static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
618 " (Pavel Roskin <proski@gnu.org>,"
619 " David Gibson <hermes@gibson.dropbear.id.au>, et al)";
620
621static struct pcmcia_device_id spectrum_cs_ids[] = {
Pavel Roskin4ebe2eb2006-04-07 04:10:32 -0400622 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400623 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
Pavel Roskin9c8a11d2005-09-16 02:18:31 -0400624 PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400625 PCMCIA_DEVICE_NULL,
626};
627MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
628
629static struct pcmcia_driver orinoco_driver = {
630 .owner = THIS_MODULE,
631 .drv = {
632 .name = DRIVER_NAME,
633 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200634 .probe = spectrum_cs_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100635 .remove = spectrum_cs_detach,
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100636 .suspend = spectrum_cs_suspend,
637 .resume = spectrum_cs_resume,
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400638 .id_table = spectrum_cs_ids,
639};
640
641static int __init
642init_spectrum_cs(void)
643{
644 printk(KERN_DEBUG "%s\n", version);
645
646 return pcmcia_register_driver(&orinoco_driver);
647}
648
649static void __exit
650exit_spectrum_cs(void)
651{
652 pcmcia_unregister_driver(&orinoco_driver);
Pavel Roskin3a48c4c2005-09-01 20:10:06 -0400653}
654
655module_init(init_spectrum_cs);
656module_exit(exit_spectrum_cs);