3 Driver for the Marvell 8385 based compact flash WLAN cards.
5 (C) 2007 by Holger Schurig <hs4233@mail.mn-solutions.de>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
20 Boston, MA 02110-1301, USA.
24 #include <linux/module.h>
25 #include <linux/delay.h>
26 #include <linux/moduleparam.h>
27 #include <linux/firmware.h>
28 #include <linux/netdevice.h>
30 #include <pcmcia/cs_types.h>
31 #include <pcmcia/cs.h>
32 #include <pcmcia/cistpl.h>
33 #include <pcmcia/ds.h>
37 #define DRV_NAME "libertas_cs"
44 /********************************************************************/
46 /********************************************************************/
48 MODULE_AUTHOR("Holger Schurig <hs4233@mail.mn-solutions.de>");
49 MODULE_DESCRIPTION("Driver for Marvell 83xx compact flash WLAN cards");
50 MODULE_LICENSE("GPL");
54 /********************************************************************/
56 /********************************************************************/
59 struct pcmcia_device *p_dev;
66 /********************************************************************/
68 /********************************************************************/
70 /* This define enables wrapper functions which allow you
71 to dump all register accesses. You normally won't this,
72 except for development */
73 /* #define DEBUG_IO */
76 static int debug_output = 0;
78 /* This way the compiler optimizes the printk's away */
79 #define debug_output 0
82 static inline unsigned int if_cs_read8(struct if_cs_card *card, uint reg)
84 unsigned int val = ioread8(card->iobase + reg);
86 printk(KERN_INFO "##inb %08x<%02x\n", reg, val);
89 static inline unsigned int if_cs_read16(struct if_cs_card *card, uint reg)
91 unsigned int val = ioread16(card->iobase + reg);
93 printk(KERN_INFO "##inw %08x<%04x\n", reg, val);
96 static inline void if_cs_read16_rep(
97 struct if_cs_card *card,
103 printk(KERN_INFO "##insw %08x<(0x%lx words)\n",
105 ioread16_rep(card->iobase + reg, buf, count);
108 static inline void if_cs_write8(struct if_cs_card *card, uint reg, u8 val)
111 printk(KERN_INFO "##outb %08x>%02x\n", reg, val);
112 iowrite8(val, card->iobase + reg);
115 static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val)
118 printk(KERN_INFO "##outw %08x>%04x\n", reg, val);
119 iowrite16(val, card->iobase + reg);
122 static inline void if_cs_write16_rep(
123 struct if_cs_card *card,
129 printk(KERN_INFO "##outsw %08x>(0x%lx words)\n",
131 iowrite16_rep(card->iobase + reg, buf, count);
136 * I know that polling/delaying is frowned upon. However, this procedure
137 * with polling is needed while downloading the firmware. At this stage,
138 * the hardware does unfortunately not create any interrupts.
140 * Fortunately, this function is never used once the firmware is in
143 * As a reference, see the "Firmware Specification v5.1", page 18
144 * and 19. I did not follow their suggested timing to the word,
145 * but this works nice & fast anyway.
147 static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 reg)
151 for (i = 0; i < 1000; i++) {
152 u8 val = if_cs_read8(card, addr);
162 /* Host control registers and their bit definitions */
164 #define IF_CS_H_STATUS 0x00000000
165 #define IF_CS_H_STATUS_TX_OVER 0x0001
166 #define IF_CS_H_STATUS_RX_OVER 0x0002
167 #define IF_CS_H_STATUS_DNLD_OVER 0x0004
169 #define IF_CS_H_INT_CAUSE 0x00000002
170 #define IF_CS_H_IC_TX_OVER 0x0001
171 #define IF_CS_H_IC_RX_OVER 0x0002
172 #define IF_CS_H_IC_DNLD_OVER 0x0004
173 #define IF_CS_H_IC_POWER_DOWN 0x0008
174 #define IF_CS_H_IC_HOST_EVENT 0x0010
175 #define IF_CS_H_IC_MASK 0x001f
177 #define IF_CS_H_INT_MASK 0x00000004
178 #define IF_CS_H_IM_MASK 0x001f
180 #define IF_CS_H_WRITE_LEN 0x00000014
182 #define IF_CS_H_WRITE 0x00000016
184 #define IF_CS_H_CMD_LEN 0x00000018
186 #define IF_CS_H_CMD 0x0000001A
188 #define IF_CS_C_READ_LEN 0x00000024
190 #define IF_CS_H_READ 0x00000010
192 /* Card control registers and their bit definitions */
194 #define IF_CS_C_STATUS 0x00000020
195 #define IF_CS_C_S_TX_DNLD_RDY 0x0001
196 #define IF_CS_C_S_RX_UPLD_RDY 0x0002
197 #define IF_CS_C_S_CMD_DNLD_RDY 0x0004
198 #define IF_CS_C_S_CMD_UPLD_RDY 0x0008
199 #define IF_CS_C_S_CARDEVENT 0x0010
200 #define IF_CS_C_S_MASK 0x001f
201 #define IF_CS_C_S_STATUS_MASK 0x7f00
202 /* The following definitions should be the same as the MRVDRV_ ones */
204 #if MRVDRV_CMD_DNLD_RDY != IF_CS_C_S_CMD_DNLD_RDY
205 #error MRVDRV_CMD_DNLD_RDY and IF_CS_C_S_CMD_DNLD_RDY not in sync
207 #if MRVDRV_CMD_UPLD_RDY != IF_CS_C_S_CMD_UPLD_RDY
208 #error MRVDRV_CMD_UPLD_RDY and IF_CS_C_S_CMD_UPLD_RDY not in sync
210 #if MRVDRV_CARDEVENT != IF_CS_C_S_CARDEVENT
211 #error MRVDRV_CARDEVENT and IF_CS_C_S_CARDEVENT not in sync
214 #define IF_CS_C_INT_CAUSE 0x00000022
215 #define IF_CS_C_IC_MASK 0x001f
217 #define IF_CS_C_SQ_READ_LOW 0x00000028
218 #define IF_CS_C_SQ_HELPER_OK 0x10
220 #define IF_CS_C_CMD_LEN 0x00000030
222 #define IF_CS_C_CMD 0x00000012
224 #define IF_CS_SCRATCH 0x0000003F
228 /********************************************************************/
230 /********************************************************************/
232 static inline void if_cs_enable_ints(struct if_cs_card *card)
234 lbs_deb_enter(LBS_DEB_CS);
235 if_cs_write16(card, IF_CS_H_INT_MASK, 0);
238 static inline void if_cs_disable_ints(struct if_cs_card *card)
240 lbs_deb_enter(LBS_DEB_CS);
241 if_cs_write16(card, IF_CS_H_INT_MASK, IF_CS_H_IM_MASK);
244 static irqreturn_t if_cs_interrupt(int irq, void *data)
246 struct if_cs_card *card = (struct if_cs_card *)data;
249 lbs_deb_enter(LBS_DEB_CS);
251 int_cause = if_cs_read16(card, IF_CS_C_INT_CAUSE);
252 if(int_cause == 0x0) {
256 } else if(int_cause == 0xffff) {
257 /* Read in junk, the card has probably been removed */
258 card->priv->adapter->surpriseremoved = 1;
261 if(int_cause & IF_CS_H_IC_TX_OVER) {
262 card->priv->dnld_sent = DNLD_RES_RECEIVED;
263 if (!card->priv->adapter->cur_cmd)
264 wake_up_interruptible(&card->priv->waitq);
266 if (card->priv->adapter->connect_status == LIBERTAS_CONNECTED)
267 netif_wake_queue(card->priv->dev);
270 /* clear interrupt */
271 if_cs_write16(card, IF_CS_C_INT_CAUSE, int_cause & IF_CS_C_IC_MASK);
274 libertas_interrupt(card->priv->dev);
282 /********************************************************************/
284 /********************************************************************/
287 * Called from if_cs_host_to_card to send a command to the hardware
289 static int if_cs_send_cmd(wlan_private *priv, u8 *buf, u16 nb)
291 struct if_cs_card *card = (struct if_cs_card *)priv->card;
295 lbs_deb_enter(LBS_DEB_CS);
297 /* Is hardware ready? */
299 u16 val = if_cs_read16(card, IF_CS_C_STATUS);
300 if (val & IF_CS_C_S_CMD_DNLD_RDY)
303 lbs_pr_err("card not ready for commands\n");
309 if_cs_write16(card, IF_CS_H_CMD_LEN, nb);
311 if_cs_write16_rep(card, IF_CS_H_CMD, buf, nb / 2);
312 /* Are we supposed to transfer an odd amount of bytes? */
314 if_cs_write8(card, IF_CS_H_CMD, buf[nb-1]);
316 /* "Assert the download over interrupt command in the Host
317 * status register" */
318 if_cs_write16(card, IF_CS_H_STATUS, IF_CS_H_STATUS_DNLD_OVER);
320 /* "Assert the download over interrupt command in the Card
321 * interrupt case register" */
322 if_cs_write16(card, IF_CS_H_INT_CAUSE, IF_CS_H_IC_DNLD_OVER);
326 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
332 * Called from if_cs_host_to_card to send a data to the hardware
334 static void if_cs_send_data(wlan_private *priv, u8 *buf, u16 nb)
336 struct if_cs_card *card = (struct if_cs_card *)priv->card;
338 lbs_deb_enter(LBS_DEB_CS);
340 if_cs_write16(card, IF_CS_H_WRITE_LEN, nb);
342 /* write even number of bytes, then odd byte if necessary */
343 if_cs_write16_rep(card, IF_CS_H_WRITE, buf, nb / 2);
345 if_cs_write8(card, IF_CS_H_WRITE, buf[nb-1]);
347 if_cs_write16(card, IF_CS_H_STATUS, IF_CS_H_STATUS_TX_OVER);
348 if_cs_write16(card, IF_CS_H_INT_CAUSE, IF_CS_H_STATUS_TX_OVER);
350 lbs_deb_leave(LBS_DEB_CS);
355 * Get the command result out of the card.
357 static int if_cs_receive_cmdres(wlan_private *priv, u8* data, u32 *len)
362 lbs_deb_enter(LBS_DEB_CS);
364 /* is hardware ready? */
365 val = if_cs_read16(priv->card, IF_CS_C_STATUS);
366 if ((val & IF_CS_C_S_CMD_UPLD_RDY) == 0) {
367 lbs_pr_err("card not ready for CMD\n");
371 *len = if_cs_read16(priv->card, IF_CS_C_CMD_LEN);
372 if ((*len == 0) || (*len > MRVDRV_SIZE_OF_CMD_BUFFER)) {
373 lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len);
377 /* read even number of bytes, then odd byte if necessary */
378 if_cs_read16_rep(priv->card, IF_CS_C_CMD, data, *len/sizeof(u16));
380 data[*len-1] = if_cs_read8(priv->card, IF_CS_C_CMD);
384 lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len);
389 static struct sk_buff *if_cs_receive_data(wlan_private *priv)
391 struct sk_buff *skb = NULL;
395 lbs_deb_enter(LBS_DEB_CS);
397 len = if_cs_read16(priv->card, IF_CS_C_READ_LEN);
398 if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
399 lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len);
400 priv->stats.rx_dropped++;
401 printk(KERN_INFO "##HS %s:%d TODO\n", __FUNCTION__, __LINE__);
405 //TODO: skb = dev_alloc_skb(len+ETH_FRAME_LEN+MRVDRV_SNAP_HEADER_LEN+EXTRA_LEN);
406 skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
410 skb_reserve(skb, 2);/* 16 byte align */
413 /* read even number of bytes, then odd byte if necessary */
414 if_cs_read16_rep(priv->card, IF_CS_H_READ, data, len/sizeof(u16));
416 data[len-1] = if_cs_read8(priv->card, IF_CS_H_READ);
419 if_cs_write16(priv->card, IF_CS_H_STATUS, IF_CS_H_STATUS_RX_OVER);
420 if_cs_write16(priv->card, IF_CS_H_INT_CAUSE, IF_CS_H_IC_RX_OVER);
423 lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb);
429 /********************************************************************/
431 /********************************************************************/
434 * Tries to program the helper firmware.
436 * Return 0 on success
438 static int if_cs_prog_helper(struct if_cs_card *card)
443 const struct firmware *fw;
445 lbs_deb_enter(LBS_DEB_CS);
447 scratch = if_cs_read8(card, IF_CS_SCRATCH);
449 /* "If the value is 0x5a, the firmware is already
450 * downloaded successfully"
455 /* "If the value is != 00, it is invalid value of register */
456 if (scratch != 0x00) {
461 /* TODO: make firmware file configurable */
462 ret = request_firmware(&fw, "libertas_cs_helper.fw",
463 &handle_to_dev(card->p_dev));
465 lbs_pr_err("can't load helper firmware\n");
469 lbs_deb_cs("helper size %td\n", fw->size);
471 /* "Set the 5 bytes of the helper image to 0" */
472 /* Not needed, this contains an ARM branch instruction */
475 /* "the number of bytes to send is 256" */
477 int remain = fw->size - sent;
481 /* printk(KERN_INFO "//HS %d loading %d of %d bytes\n",
482 __LINE__, sent, fw->size); */
484 /* "write the number of bytes to be sent to the I/O Command
485 * write length register" */
486 if_cs_write16(card, IF_CS_H_CMD_LEN, count);
488 /* "write this to I/O Command port register as 16 bit writes */
490 if_cs_write16_rep(card, IF_CS_H_CMD,
494 /* "Assert the download over interrupt command in the Host
495 * status register" */
496 if_cs_write8(card, IF_CS_H_STATUS, IF_CS_H_STATUS_DNLD_OVER);
498 /* "Assert the download over interrupt command in the Card
499 * interrupt case register" */
500 if_cs_write16(card, IF_CS_H_INT_CAUSE, IF_CS_H_IC_DNLD_OVER);
502 /* "The host polls the Card Status register ... for 50 ms before
503 declaring a failure */
504 ret = if_cs_poll_while_fw_download(card, IF_CS_C_STATUS,
505 IF_CS_C_S_CMD_DNLD_RDY);
507 lbs_pr_err("can't download helper at 0x%x, ret %d\n",
518 release_firmware(fw);
522 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
527 static int if_cs_prog_real(struct if_cs_card *card)
529 const struct firmware *fw;
535 lbs_deb_enter(LBS_DEB_CS);
537 /* TODO: make firmware file configurable */
538 ret = request_firmware(&fw, "libertas_cs.fw",
539 &handle_to_dev(card->p_dev));
541 lbs_pr_err("can't load firmware\n");
545 lbs_deb_cs("fw size %td\n", fw->size);
547 ret = if_cs_poll_while_fw_download(card, IF_CS_C_SQ_READ_LOW, IF_CS_C_SQ_HELPER_OK);
550 lbs_pr_err("helper firmware doesn't answer\n");
551 for (i = 0; i < 0x50; i += 2)
552 printk(KERN_INFO "## HS %02x: %04x\n",
553 i, if_cs_read16(card, i));
557 for (sent = 0; sent < fw->size; sent += len) {
558 len = if_cs_read16(card, IF_CS_C_SQ_READ_LOW);
559 /* printk(KERN_INFO "//HS %d loading %d of %d bytes\n",
560 __LINE__, sent, fw->size); */
563 lbs_pr_info("odd, need to retry this firmware block\n");
569 lbs_pr_err("could not download firmware\n");
578 if_cs_write16(card, IF_CS_H_CMD_LEN, len);
580 if_cs_write16_rep(card, IF_CS_H_CMD,
583 if_cs_write8(card, IF_CS_H_STATUS, IF_CS_H_STATUS_DNLD_OVER);
584 if_cs_write16(card, IF_CS_H_INT_CAUSE, IF_CS_H_IC_DNLD_OVER);
586 ret = if_cs_poll_while_fw_download(card, IF_CS_C_STATUS,
587 IF_CS_C_S_CMD_DNLD_RDY);
589 lbs_pr_err("can't download firmware at 0x%x\n", sent);
594 ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a);
596 lbs_pr_err("firmware download failed\n");
605 release_firmware(fw);
608 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
614 /********************************************************************/
615 /* Callback functions for libertas.ko */
616 /********************************************************************/
618 /* Send commands or data packets to the card */
619 static int if_cs_host_to_card(wlan_private *priv, u8 type, u8 *buf, u16 nb)
623 lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb);
627 priv->dnld_sent = DNLD_DATA_SENT;
628 if_cs_send_data(priv, buf, nb);
632 priv->dnld_sent = DNLD_CMD_SENT;
633 ret = if_cs_send_cmd(priv, buf, nb);
636 lbs_pr_err("%s: unsupported type %d\n", __FUNCTION__, type);
639 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
644 static int if_cs_get_int_status(wlan_private *priv, u8 *ireg)
646 struct if_cs_card *card = (struct if_cs_card *)priv->card;
647 //wlan_adapter *adapter = priv->adapter;
653 lbs_deb_enter(LBS_DEB_CS);
655 if (priv->adapter->surpriseremoved)
658 int_cause = if_cs_read16(card, IF_CS_C_INT_CAUSE) & IF_CS_C_IC_MASK;
659 if_cs_write16(card, IF_CS_C_INT_CAUSE, int_cause);
661 *ireg = if_cs_read16(card, IF_CS_C_STATUS) & IF_CS_C_S_MASK;
664 goto sbi_get_int_status_exit;
666 sbi_get_int_status_exit:
668 /* is there a data packet for us? */
669 if (*ireg & IF_CS_C_S_RX_UPLD_RDY) {
670 struct sk_buff *skb = if_cs_receive_data(priv);
671 libertas_process_rxed_packet(priv, skb);
672 *ireg &= ~IF_CS_C_S_RX_UPLD_RDY;
675 if (*ireg & IF_CS_C_S_TX_DNLD_RDY) {
676 priv->dnld_sent = DNLD_RES_RECEIVED;
679 /* Card has a command result for us */
680 if (*ireg & IF_CS_C_S_CMD_UPLD_RDY) {
681 spin_lock(&priv->adapter->driver_lock);
682 if (!priv->adapter->cur_cmd) {
683 cmdbuf = priv->upld_buf;
684 priv->adapter->hisregcpy &= ~IF_CS_C_S_RX_UPLD_RDY;
686 cmdbuf = priv->adapter->cur_cmd->bufvirtualaddr;
689 ret = if_cs_receive_cmdres(priv, cmdbuf, &priv->upld_len);
690 spin_unlock(&priv->adapter->driver_lock);
692 lbs_pr_err("could not receive cmd from card\n");
696 lbs_deb_leave_args(LBS_DEB_CS, "ret %d, ireg 0x%x, hisregcpy 0x%x", ret, *ireg, priv->adapter->hisregcpy);
701 static int if_cs_read_event_cause(wlan_private *priv)
703 lbs_deb_enter(LBS_DEB_CS);
705 priv->adapter->eventcause = (if_cs_read16(priv->card, IF_CS_C_STATUS) & IF_CS_C_S_STATUS_MASK) >> 5;
706 if_cs_write16(priv->card, IF_CS_H_INT_CAUSE, IF_CS_H_IC_HOST_EVENT);
713 /********************************************************************/
715 /********************************************************************/
718 * After a card is removed, if_cs_release() will unregister the
719 * device, and release the PCMCIA configuration. If the device is
720 * still open, this will be postponed until it is closed.
722 static void if_cs_release(struct pcmcia_device *p_dev)
724 struct if_cs_card *card = p_dev->priv;
726 lbs_deb_enter(LBS_DEB_CS);
728 pcmcia_disable_device(p_dev);
729 free_irq(p_dev->irq.AssignedIRQ, card);
731 ioport_unmap(card->iobase);
733 lbs_deb_leave(LBS_DEB_CS);
738 * This creates an "instance" of the driver, allocating local data
739 * structures for one device. The device is registered with Card
742 * The dev_link structure is initialized, but we don't actually
743 * configure the card at this point -- we wait until we receive a card
746 static int if_cs_probe(struct pcmcia_device *p_dev)
750 struct if_cs_card *card;
754 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
755 cistpl_io_t *io = &cfg->io;
758 lbs_deb_enter(LBS_DEB_CS);
760 card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL);
762 lbs_pr_err("error in kzalloc\n");
768 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
769 p_dev->irq.Handler = NULL;
770 p_dev->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
772 p_dev->conf.Attributes = 0;
773 p_dev->conf.IntType = INT_MEMORY_AND_IO;
775 tuple.Attributes = 0;
776 tuple.TupleData = buf;
777 tuple.TupleDataMax = sizeof(buf);
778 tuple.TupleOffset = 0;
780 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
781 if ((ret = pcmcia_get_first_tuple(p_dev, &tuple)) != 0 ||
782 (ret = pcmcia_get_tuple_data(p_dev, &tuple)) != 0 ||
783 (ret = pcmcia_parse_tuple(p_dev, &tuple, &parse)) != 0)
785 lbs_pr_err("error in pcmcia_get_first_tuple etc\n");
789 p_dev->conf.ConfigIndex = cfg->index;
791 /* Do we need to allocate an interrupt? */
792 if (cfg->irq.IRQInfo1) {
793 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
796 /* IO window settings */
797 if (cfg->io.nwin != 1) {
798 lbs_pr_err("wrong CIS (check number of IO windows)\n");
802 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
803 p_dev->io.BasePort1 = io->win[0].base;
804 p_dev->io.NumPorts1 = io->win[0].len;
806 /* This reserves IO space but doesn't actually enable it */
807 ret = pcmcia_request_io(p_dev, &p_dev->io);
809 lbs_pr_err("error in pcmcia_request_io\n");
814 * Allocate an interrupt line. Note that this does not assign
815 * a handler to the interrupt, unless the 'Handler' member of
816 * the irq structure is initialized.
818 if (p_dev->conf.Attributes & CONF_ENABLE_IRQ) {
819 ret = pcmcia_request_irq(p_dev, &p_dev->irq);
821 lbs_pr_err("error in pcmcia_request_irq\n");
826 /* Initialize io access */
827 card->iobase = ioport_map(p_dev->io.BasePort1, p_dev->io.NumPorts1);
829 lbs_pr_err("error in ioport_map\n");
835 * This actually configures the PCMCIA socket -- setting up
836 * the I/O windows and the interrupt mapping, and putting the
837 * card and host interface into "Memory and IO" mode.
839 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
841 lbs_pr_err("error in pcmcia_request_configuration\n");
845 /* Finally, report what we've done */
846 lbs_deb_cs("irq %d, io 0x%04x-0x%04x\n",
847 p_dev->irq.AssignedIRQ, p_dev->io.BasePort1,
848 p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1);
851 /* Load the firmware early, before calling into libertas.ko */
852 ret = if_cs_prog_helper(card);
854 ret = if_cs_prog_real(card);
858 /* Make this card known to the libertas driver */
859 priv = libertas_add_card(card, &p_dev->dev);
865 /* Store pointers to our call-back functions */
868 priv->hw_host_to_card = if_cs_host_to_card;
869 priv->hw_get_int_status = if_cs_get_int_status;
870 priv->hw_read_event_cause = if_cs_read_event_cause;
872 priv->adapter->fw_ready = 1;
874 /* Now actually get the IRQ */
875 ret = request_irq(p_dev->irq.AssignedIRQ, if_cs_interrupt,
876 IRQF_SHARED, DRV_NAME, card);
878 lbs_pr_err("error in request_irq\n");
882 /* Clear any interrupt cause that happend while sending
883 * firmware/initializing card */
884 if_cs_write16(card, IF_CS_C_INT_CAUSE, IF_CS_C_IC_MASK);
885 if_cs_enable_ints(card);
887 /* And finally bring the card up */
888 if (libertas_start_card(priv) != 0) {
889 lbs_pr_err("could not activate card\n");
897 libertas_remove_card(priv);
899 ioport_unmap(card->iobase);
901 pcmcia_disable_device(p_dev);
903 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
909 * This deletes a driver "instance". The device is de-registered with
910 * Card Services. If it has been released, all local data structures
911 * are freed. Otherwise, the structures will be freed when the device
914 static void if_cs_detach(struct pcmcia_device *p_dev)
916 struct if_cs_card *card = p_dev->priv;
918 lbs_deb_enter(LBS_DEB_CS);
920 libertas_stop_card(card->priv);
921 libertas_remove_card(card->priv);
922 if_cs_disable_ints(card);
923 if_cs_release(p_dev);
926 lbs_deb_leave(LBS_DEB_CS);
931 /********************************************************************/
932 /* Module initialization */
933 /********************************************************************/
935 static struct pcmcia_device_id if_cs_ids[] = {
936 PCMCIA_DEVICE_MANF_CARD(0x02df, 0x8103),
939 MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
942 static struct pcmcia_driver libertas_driver = {
943 .owner = THIS_MODULE,
947 .probe = if_cs_probe,
948 .remove = if_cs_detach,
949 .id_table = if_cs_ids,
953 static int __init if_cs_init(void)
957 lbs_deb_enter(LBS_DEB_CS);
958 ret = pcmcia_register_driver(&libertas_driver);
959 lbs_deb_leave(LBS_DEB_CS);
964 static void __exit if_cs_exit(void)
966 lbs_deb_enter(LBS_DEB_CS);
967 pcmcia_unregister_driver(&libertas_driver);
968 lbs_deb_leave(LBS_DEB_CS);
972 module_init(if_cs_init);
973 module_exit(if_cs_exit);