2 * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as
3 * Symbol Wireless Networker LA4100, CompactFlash cards by Socket
4 * Communications and Intel PRO/Wireless 2011B.
6 * The driver implements Symbol firmware download. The rest is handled
7 * in hermes.c and orinoco.c.
9 * Utilities for downloading the Symbol firmware are available at
10 * http://sourceforge.net/projects/orinoco/
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.
18 * See copyright notice in file orinoco.c.
21 #define DRIVER_NAME "spectrum_cs"
22 #define PFX DRIVER_NAME ": "
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/firmware.h>
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>
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";
43 /********************************************************************/
45 /********************************************************************/
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");
51 /* Module parameters */
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");
59 /********************************************************************/
61 /********************************************************************/
64 * The dev_info variable is the "key" that is used to match up this
65 * device driver with appropriate cards, through the card
66 * configuration database.
68 static dev_info_t dev_info = DRIVER_NAME;
70 /********************************************************************/
72 /********************************************************************/
74 /* PCMCIA specific device information (goes in the card field of
75 * struct orinoco_private */
76 struct orinoco_pccard {
82 * A linked list of "instances" of the device. Each actual PCMCIA
83 * card corresponds to one device instance, and is described by one
84 * dev_link_t structure (defined in ds.h).
86 static dev_link_t *dev_list; /* = NULL */
88 /********************************************************************/
89 /* Function prototypes */
90 /********************************************************************/
92 static void spectrum_cs_release(dev_link_t *link);
93 static void spectrum_cs_detach(struct pcmcia_device *p_dev);
95 /********************************************************************/
96 /* Firmware downloader */
97 /********************************************************************/
99 /* Position of PDA in the adapter memory */
100 #define EEPROM_ADDR 0x3000
101 #define EEPROM_LEN 0x200
102 #define PDA_OFFSET 0x100
104 #define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET)
105 #define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2)
107 /* Constants for the CISREG_CCSR register */
108 #define HCR_RUN 0x07 /* run firmware after reset */
109 #define HCR_IDLE 0x0E /* don't run firmware after reset */
110 #define HCR_MEM16 0x10 /* memory width bit, should be preserved */
113 * AUX port access. To unlock the AUX port write the access keys to the
114 * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
115 * register. Then read it and make sure it's HERMES_AUX_ENABLED.
117 #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
118 #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
119 #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
121 #define HERMES_AUX_PW0 0xFE01
122 #define HERMES_AUX_PW1 0xDC23
123 #define HERMES_AUX_PW2 0xBA45
126 #define PDI_END 0x00000000 /* End of PDA */
127 #define BLOCK_END 0xFFFFFFFF /* Last image block */
128 #define TEXT_END 0x1A /* End of text header */
131 * The following structures have little-endian fields denoted by
132 * the leading underscore. Don't access them directly - use inline
133 * functions defined below.
137 * The binary image to be downloaded consists of series of data blocks.
138 * Each block has the following structure.
141 __le32 _addr; /* adapter address where to write the block */
142 __le16 _len; /* length of the data only, in bytes */
143 char data[0]; /* data to be written */
144 } __attribute__ ((packed));
147 * Plug Data References are located in in the image after the last data
148 * block. They refer to areas in the adapter memory where the plug data
149 * items with matching ID should be written.
152 __le32 _id; /* record ID */
153 __le32 _addr; /* adapter address where to write the data */
154 __le32 _len; /* expected length of the data, in bytes */
155 char next[0]; /* next PDR starts here */
156 } __attribute__ ((packed));
160 * Plug Data Items are located in the EEPROM read from the adapter by
161 * primary firmware. They refer to the device-specific data that should
162 * be plugged into the secondary firmware.
165 __le16 _len; /* length of ID and data, in words */
166 __le16 _id; /* record ID */
167 char data[0]; /* plug data */
168 } __attribute__ ((packed));;
171 /* Functions for access to little-endian data */
173 dblock_addr(const struct dblock *blk)
175 return le32_to_cpu(blk->_addr);
179 dblock_len(const struct dblock *blk)
181 return le16_to_cpu(blk->_len);
185 pdr_id(const struct pdr *pdr)
187 return le32_to_cpu(pdr->_id);
191 pdr_addr(const struct pdr *pdr)
193 return le32_to_cpu(pdr->_addr);
197 pdr_len(const struct pdr *pdr)
199 return le32_to_cpu(pdr->_len);
203 pdi_id(const struct pdi *pdi)
205 return le16_to_cpu(pdi->_id);
208 /* Return length of the data only, in bytes */
210 pdi_len(const struct pdi *pdi)
212 return 2 * (le16_to_cpu(pdi->_len) - 1);
216 /* Set address of the auxiliary port */
218 spectrum_aux_setaddr(hermes_t *hw, u32 addr)
220 hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
221 hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
225 /* Open access to the auxiliary port */
227 spectrum_aux_open(hermes_t *hw)
232 if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED)
235 hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
236 hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
237 hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
238 hermes_write_reg(hw, HERMES_CONTROL, HERMES_AUX_ENABLE);
240 for (i = 0; i < 20; i++) {
242 if (hermes_read_reg(hw, HERMES_CONTROL) ==
251 #define CS_CHECK(fn, ret) \
252 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
255 * Reset the card using configuration registers COR and CCSR.
256 * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
259 spectrum_reset(dev_link_t *link, int idle)
261 int last_ret, last_fn;
265 /* Doing it if hardware is gone is guaranteed crash */
266 if (!(link->state & DEV_CONFIG))
269 /* Save original COR value */
271 reg.Action = CS_READ;
272 reg.Offset = CISREG_COR;
273 CS_CHECK(AccessConfigurationRegister,
274 pcmcia_access_configuration_register(link->handle, ®));
275 save_cor = reg.Value;
277 /* Soft-Reset card */
278 reg.Action = CS_WRITE;
279 reg.Offset = CISREG_COR;
280 reg.Value = (save_cor | COR_SOFT_RESET);
281 CS_CHECK(AccessConfigurationRegister,
282 pcmcia_access_configuration_register(link->handle, ®));
286 reg.Action = CS_READ;
287 reg.Offset = CISREG_CCSR;
288 CS_CHECK(AccessConfigurationRegister,
289 pcmcia_access_configuration_register(link->handle, ®));
292 * Start or stop the firmware. Memory width bit should be
293 * preserved from the value we've just read.
295 reg.Action = CS_WRITE;
296 reg.Offset = CISREG_CCSR;
297 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16);
298 CS_CHECK(AccessConfigurationRegister,
299 pcmcia_access_configuration_register(link->handle, ®));
302 /* Restore original COR configuration index */
303 reg.Action = CS_WRITE;
304 reg.Offset = CISREG_COR;
305 reg.Value = (save_cor & ~COR_SOFT_RESET);
306 CS_CHECK(AccessConfigurationRegister,
307 pcmcia_access_configuration_register(link->handle, ®));
312 cs_error(link->handle, last_fn, last_ret);
318 * Scan PDR for the record with the specified RECORD_ID.
319 * If it's not found, return NULL.
322 spectrum_find_pdr(struct pdr *first_pdr, u32 record_id)
324 struct pdr *pdr = first_pdr;
326 while (pdr_id(pdr) != PDI_END) {
328 * PDR area is currently not terminated by PDI_END.
329 * It's followed by CRC records, which have the type
330 * field where PDR has length. The type can be 0 or 1.
332 if (pdr_len(pdr) < 2)
335 /* If the record ID matches, we are done */
336 if (pdr_id(pdr) == record_id)
339 pdr = (struct pdr *) pdr->next;
345 /* Process one Plug Data Item - find corresponding PDR and plug it */
347 spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi)
351 /* Find the PDI corresponding to this PDR */
352 pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi));
354 /* No match is found, safe to ignore */
358 /* Lengths of the data in PDI and PDR must match */
359 if (pdi_len(pdi) != pdr_len(pdr))
362 /* do the actual plugging */
363 spectrum_aux_setaddr(hw, pdr_addr(pdr));
364 hermes_write_words(hw, HERMES_AUXDATA, pdi->data,
371 /* Read PDA from the adapter */
373 spectrum_read_pda(hermes_t *hw, __le16 *pda, int pda_len)
378 /* Issue command to read EEPROM */
379 ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
383 /* Open auxiliary port */
384 ret = spectrum_aux_open(hw);
388 /* read PDA from EEPROM */
389 spectrum_aux_setaddr(hw, PDA_ADDR);
390 hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2);
392 /* Check PDA length */
393 pda_size = le16_to_cpu(pda[0]);
394 if (pda_size > pda_len)
401 /* Parse PDA and write the records into the adapter */
403 spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block,
408 struct pdr *first_pdr;
409 const struct dblock *blk = first_block;
411 /* Skip all blocks to locate Plug Data References */
412 while (dblock_addr(blk) != BLOCK_END)
413 blk = (struct dblock *) &blk->data[dblock_len(blk)];
415 first_pdr = (struct pdr *) blk;
417 /* Go through every PDI and plug them into the adapter */
418 pdi = (struct pdi *) (pda + 2);
419 while (pdi_id(pdi) != PDI_END) {
420 ret = spectrum_plug_pdi(hw, first_pdr, pdi);
424 /* Increment to the next PDI */
425 pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];
431 /* Load firmware blocks into the adapter */
433 spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block)
435 const struct dblock *blk;
440 blkaddr = dblock_addr(blk);
441 blklen = dblock_len(blk);
443 while (dblock_addr(blk) != BLOCK_END) {
444 spectrum_aux_setaddr(hw, blkaddr);
445 hermes_write_words(hw, HERMES_AUXDATA, blk->data,
448 blk = (struct dblock *) &blk->data[blklen];
449 blkaddr = dblock_addr(blk);
450 blklen = dblock_len(blk);
457 * Process a firmware image - stop the card, load the firmware, reset
458 * the card and make sure it responds. For the secondary firmware take
459 * care of the PDA - read it and then write it on top of the firmware.
462 spectrum_dl_image(hermes_t *hw, dev_link_t *link,
463 const unsigned char *image)
466 const unsigned char *ptr;
467 const struct dblock *first_block;
469 /* Plug Data Area (PDA) */
470 __le16 pda[PDA_WORDS];
472 /* Binary block begins after the 0x1A marker */
474 while (*ptr++ != TEXT_END);
475 first_block = (const struct dblock *) ptr;
478 if (image != primsym) {
479 ret = spectrum_read_pda(hw, pda, sizeof(pda));
484 /* Stop the firmware, so that it can be safely rewritten */
485 ret = spectrum_reset(link, 1);
489 /* Program the adapter with new firmware */
490 ret = spectrum_load_blocks(hw, first_block);
494 /* Write the PDA to the adapter */
495 if (image != primsym) {
496 ret = spectrum_apply_pda(hw, first_block, pda);
501 /* Run the firmware */
502 ret = spectrum_reset(link, 0);
506 /* Reset hermes chip and make sure it responds */
507 ret = hermes_init(hw);
509 /* hermes_reset() should return 0 with the secondary firmware */
510 if (image != primsym && ret != 0)
513 /* And this should work with any firmware */
514 if (!hermes_present(hw))
522 * Download the firmware into the card, this also does a PCMCIA soft
523 * reset on the card, to make sure it's in a sane state.
526 spectrum_dl_firmware(hermes_t *hw, dev_link_t *link)
529 client_handle_t handle = link->handle;
530 const struct firmware *fw_entry;
532 if (request_firmware(&fw_entry, primary_fw_name,
533 &handle_to_dev(handle)) == 0) {
534 primsym = fw_entry->data;
536 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
541 if (request_firmware(&fw_entry, secondary_fw_name,
542 &handle_to_dev(handle)) == 0) {
543 secsym = fw_entry->data;
545 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
550 /* Load primary firmware */
551 ret = spectrum_dl_image(hw, link, primsym);
553 printk(KERN_ERR PFX "Primary firmware download failed\n");
557 /* Load secondary firmware */
558 ret = spectrum_dl_image(hw, link, secsym);
561 printk(KERN_ERR PFX "Secondary firmware download failed\n");
567 /********************************************************************/
569 /********************************************************************/
572 spectrum_cs_hard_reset(struct orinoco_private *priv)
574 struct orinoco_pccard *card = priv->card;
575 dev_link_t *link = &card->link;
578 if (!hermes_present(&priv->hw)) {
579 /* The firmware needs to be reloaded */
580 if (spectrum_dl_firmware(&priv->hw, &card->link) != 0) {
581 printk(KERN_ERR PFX "Firmware download failed\n");
585 /* Soft reset using COR and HCR */
586 spectrum_reset(link, 0);
592 /********************************************************************/
594 /********************************************************************/
597 * This creates an "instance" of the driver, allocating local data
598 * structures for one device. The device is registered with Card
601 * The dev_link structure is initialized, but we don't actually
602 * configure the card at this point -- we wait until we receive a card
603 * insertion event. */
605 spectrum_cs_attach(void)
607 struct net_device *dev;
608 struct orinoco_private *priv;
609 struct orinoco_pccard *card;
611 client_reg_t client_reg;
614 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset);
617 priv = netdev_priv(dev);
620 /* Link both structures together */
624 /* Interrupt setup */
625 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
626 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
627 link->irq.Handler = orinoco_interrupt;
628 link->irq.Instance = dev;
630 /* General socket configuration defaults can go here. In this
631 * client, we assume very little, and rely on the CIS for
632 * almost everything. In most clients, many details (i.e.,
633 * number, sizes, and attributes of IO windows) are fixed by
634 * the nature of the device, and can be hard-wired here. */
635 link->conf.Attributes = 0;
636 link->conf.IntType = INT_MEMORY_AND_IO;
638 /* Register with Card Services */
639 /* FIXME: need a lock? */
640 link->next = dev_list;
643 client_reg.dev_info = &dev_info;
644 client_reg.Version = 0x0210; /* FIXME: what does this mean? */
645 client_reg.event_callback_args.client_data = link;
647 ret = pcmcia_register_client(&link->handle, &client_reg);
648 if (ret != CS_SUCCESS) {
649 cs_error(link->handle, RegisterClient, ret);
650 spectrum_cs_detach(link->handle);
655 } /* spectrum_cs_attach */
658 * This deletes a driver "instance". The device is de-registered with
659 * Card Services. If it has been released, all local data structures
660 * are freed. Otherwise, the structures will be freed when the device
663 static void spectrum_cs_detach(struct pcmcia_device *p_dev)
665 dev_link_t *link = dev_to_instance(p_dev);
666 struct net_device *dev = link->priv;
668 if (link->state & DEV_CONFIG)
669 spectrum_cs_release(link);
671 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev);
673 DEBUG(0, PFX "About to unregister net device %p\n",
675 unregister_netdev(dev);
677 free_orinocodev(dev);
678 } /* spectrum_cs_detach */
681 * spectrum_cs_config() is scheduled to run after a CARD_INSERTION
682 * event is received, to configure the PCMCIA socket, and to make the
683 * device available to the system.
687 spectrum_cs_config(dev_link_t *link)
689 struct net_device *dev = link->priv;
690 client_handle_t handle = link->handle;
691 struct orinoco_private *priv = netdev_priv(dev);
692 struct orinoco_pccard *card = priv->card;
693 hermes_t *hw = &priv->hw;
694 int last_fn, last_ret;
702 CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info));
705 * This reads the card's CONFIG tuple to find its
706 * configuration registers.
708 tuple.DesiredTuple = CISTPL_CONFIG;
709 tuple.Attributes = 0;
710 tuple.TupleData = buf;
711 tuple.TupleDataMax = sizeof(buf);
712 tuple.TupleOffset = 0;
713 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
714 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
715 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
716 link->conf.ConfigBase = parse.config.base;
717 link->conf.Present = parse.config.rmask[0];
720 link->state |= DEV_CONFIG;
722 /* Look up the current Vcc */
723 CS_CHECK(GetConfigurationInfo,
724 pcmcia_get_configuration_info(handle, &conf));
725 link->conf.Vcc = conf.Vcc;
728 * In this loop, we scan the CIS for configuration table
729 * entries, each of which describes a valid card
730 * configuration, including voltage, IO window, memory window,
731 * and interrupt settings.
733 * We make no assumptions about the card to be configured: we
734 * use just the information available in the CIS. In an ideal
735 * world, this would work for any PCMCIA card, but it requires
736 * a complete and accurate CIS. In practice, a driver usually
737 * "knows" most of these things without consulting the CIS,
738 * and most client drivers will only use the CIS to fill in
739 * implementation-defined details.
741 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
742 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
744 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
745 cistpl_cftable_entry_t dflt = { .index = 0 };
747 if ( (pcmcia_get_tuple_data(handle, &tuple) != 0)
748 || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0))
751 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
755 link->conf.ConfigIndex = cfg->index;
757 /* Does this card need audio output? */
758 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
759 link->conf.Attributes |= CONF_ENABLE_SPKR;
760 link->conf.Status = CCSR_AUDIO_ENA;
763 /* Use power settings for Vcc and Vpp if present */
764 /* Note that the CIS values need to be rescaled */
765 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
766 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
767 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
771 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
772 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
773 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
779 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
780 link->conf.Vpp1 = link->conf.Vpp2 =
781 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
782 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
783 link->conf.Vpp1 = link->conf.Vpp2 =
784 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
786 /* Do we need to allocate an interrupt? */
787 link->conf.Attributes |= CONF_ENABLE_IRQ;
789 /* IO window settings */
790 link->io.NumPorts1 = link->io.NumPorts2 = 0;
791 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
793 (cfg->io.nwin) ? &cfg->io : &dflt.io;
794 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
795 if (!(io->flags & CISTPL_IO_8BIT))
796 link->io.Attributes1 =
797 IO_DATA_PATH_WIDTH_16;
798 if (!(io->flags & CISTPL_IO_16BIT))
799 link->io.Attributes1 =
800 IO_DATA_PATH_WIDTH_8;
801 link->io.IOAddrLines =
802 io->flags & CISTPL_IO_LINES_MASK;
803 link->io.BasePort1 = io->win[0].base;
804 link->io.NumPorts1 = io->win[0].len;
806 link->io.Attributes2 =
807 link->io.Attributes1;
808 link->io.BasePort2 = io->win[1].base;
809 link->io.NumPorts2 = io->win[1].len;
812 /* This reserves IO space but doesn't actually enable it */
813 if (pcmcia_request_io(link->handle, &link->io) != 0)
818 /* If we got this far, we're cool! */
823 if (link->io.NumPorts1)
824 pcmcia_release_io(link->handle, &link->io);
825 last_ret = pcmcia_get_next_tuple(handle, &tuple);
826 if (last_ret == CS_NO_MORE_ITEMS) {
827 printk(KERN_ERR PFX "GetNextTuple(): No matching "
828 "CIS configuration. Maybe you need the "
829 "ignore_cis_vcc=1 parameter.\n");
835 * Allocate an interrupt line. Note that this does not assign
836 * a handler to the interrupt, unless the 'Handler' member of
837 * the irq structure is initialized.
839 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
841 /* We initialize the hermes structure before completing PCMCIA
842 * configuration just in case the interrupt handler gets
844 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1);
848 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
851 * This actually configures the PCMCIA socket -- setting up
852 * the I/O windows and the interrupt mapping, and putting the
853 * card and host interface into "Memory and IO" mode.
855 CS_CHECK(RequestConfiguration,
856 pcmcia_request_configuration(link->handle, &link->conf));
858 /* Ok, we have the configuration, prepare to register the netdev */
859 dev->base_addr = link->io.BasePort1;
860 dev->irq = link->irq.AssignedIRQ;
861 SET_MODULE_OWNER(dev);
862 card->node.major = card->node.minor = 0;
864 /* Reset card and download firmware */
865 if (spectrum_cs_hard_reset(priv) != 0) {
869 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
870 /* Tell the stack we exist */
871 if (register_netdev(dev) != 0) {
872 printk(KERN_ERR PFX "register_netdev() failed\n");
876 /* At this point, the dev_node_t structure(s) needs to be
877 * initialized and arranged in a linked list at link->dev. */
878 strcpy(card->node.dev_name, dev->name);
879 link->dev = &card->node; /* link->dev being non-NULL is also
880 used to indicate that the
881 net_device has been registered */
882 link->state &= ~DEV_CONFIG_PENDING;
884 /* Finally, report what we've done */
885 printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d",
886 dev->name, link->conf.ConfigIndex,
887 link->conf.Vcc / 10, link->conf.Vcc % 10);
889 printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
890 link->conf.Vpp1 % 10);
891 printk(", irq %d", link->irq.AssignedIRQ);
892 if (link->io.NumPorts1)
893 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
894 link->io.BasePort1 + link->io.NumPorts1 - 1);
895 if (link->io.NumPorts2)
896 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
897 link->io.BasePort2 + link->io.NumPorts2 - 1);
903 cs_error(link->handle, last_fn, last_ret);
906 spectrum_cs_release(link);
907 } /* spectrum_cs_config */
910 * After a card is removed, spectrum_cs_release() will unregister the
911 * device, and release the PCMCIA configuration. If the device is
912 * still open, this will be postponed until it is closed.
915 spectrum_cs_release(dev_link_t *link)
917 struct net_device *dev = link->priv;
918 struct orinoco_private *priv = netdev_priv(dev);
921 /* We're committed to taking the device away now, so mark the
922 * hardware as unavailable */
923 spin_lock_irqsave(&priv->lock, flags);
924 priv->hw_unavailable++;
925 spin_unlock_irqrestore(&priv->lock, flags);
927 /* Don't bother checking to see if these succeed or not */
928 pcmcia_release_configuration(link->handle);
929 if (link->io.NumPorts1)
930 pcmcia_release_io(link->handle, &link->io);
931 if (link->irq.AssignedIRQ)
932 pcmcia_release_irq(link->handle, &link->irq);
933 link->state &= ~DEV_CONFIG;
935 ioport_unmap(priv->hw.iobase);
936 } /* spectrum_cs_release */
940 spectrum_cs_suspend(struct pcmcia_device *p_dev)
942 dev_link_t *link = dev_to_instance(p_dev);
943 struct net_device *dev = link->priv;
944 struct orinoco_private *priv = netdev_priv(dev);
948 link->state |= DEV_SUSPEND;
949 /* Mark the device as stopped, to block IO until later */
950 if (link->state & DEV_CONFIG) {
951 spin_lock_irqsave(&priv->lock, flags);
953 err = __orinoco_down(dev);
955 printk(KERN_WARNING "%s: Error %d downing interface\n",
958 netif_device_detach(dev);
959 priv->hw_unavailable++;
961 spin_unlock_irqrestore(&priv->lock, flags);
963 pcmcia_release_configuration(link->handle);
970 spectrum_cs_resume(struct pcmcia_device *p_dev)
972 dev_link_t *link = dev_to_instance(p_dev);
973 struct net_device *dev = link->priv;
974 struct orinoco_private *priv = netdev_priv(dev);
976 link->state &= ~DEV_SUSPEND;
977 if (link->state & DEV_CONFIG) {
978 /* FIXME: should we double check that this is
979 * the same card as we had before */
980 pcmcia_request_configuration(link->handle, &link->conf);
981 netif_device_attach(dev);
982 priv->hw_unavailable--;
983 schedule_work(&priv->reset_work);
989 * The card status event handler. Mostly, this schedules other stuff
990 * to run after an event is received.
993 spectrum_cs_event(event_t event, int priority,
994 event_callback_args_t * args)
996 dev_link_t *link = args->client_data;
999 case CS_EVENT_CARD_INSERTION:
1000 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1001 spectrum_cs_config(link);
1007 } /* spectrum_cs_event */
1009 /********************************************************************/
1010 /* Module initialization */
1011 /********************************************************************/
1013 /* Can't be declared "const" or the whole __initdata section will
1015 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
1016 " (Pavel Roskin <proski@gnu.org>,"
1017 " David Gibson <hermes@gibson.dropbear.id.au>, et al)";
1019 static struct pcmcia_device_id spectrum_cs_ids[] = {
1020 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4100 */
1021 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
1022 PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */
1025 MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
1027 static struct pcmcia_driver orinoco_driver = {
1028 .owner = THIS_MODULE,
1030 .name = DRIVER_NAME,
1032 .attach = spectrum_cs_attach,
1033 .remove = spectrum_cs_detach,
1034 .suspend = spectrum_cs_suspend,
1035 .resume = spectrum_cs_resume,
1036 .event = spectrum_cs_event,
1037 .id_table = spectrum_cs_ids,
1041 init_spectrum_cs(void)
1043 printk(KERN_DEBUG "%s\n", version);
1045 return pcmcia_register_driver(&orinoco_driver);
1049 exit_spectrum_cs(void)
1051 pcmcia_unregister_driver(&orinoco_driver);
1052 BUG_ON(dev_list != NULL);
1055 module_init(init_spectrum_cs);
1056 module_exit(exit_spectrum_cs);