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;
60 struct lbs_private *priv;
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 < 100000; i++) {
152 u8 val = if_cs_read8(card, addr);
163 * First the bitmasks for the host/card interrupt/status registers:
165 #define IF_CS_BIT_TX 0x0001
166 #define IF_CS_BIT_RX 0x0002
167 #define IF_CS_BIT_COMMAND 0x0004
168 #define IF_CS_BIT_RESP 0x0008
169 #define IF_CS_BIT_EVENT 0x0010
170 #define IF_CS_BIT_MASK 0x001f
175 * It's not really clear to me what the host status register is for. It
176 * needs to be set almost in union with "host int cause". The following
177 * bits from above are used:
179 * IF_CS_BIT_TX driver downloaded a data packet
180 * IF_CS_BIT_RX driver got a data packet
181 * IF_CS_BIT_COMMAND driver downloaded a command
182 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
183 * IF_CS_BIT_EVENT driver read a host event
185 #define IF_CS_HOST_STATUS 0x00000000
188 * With the host int cause register can the host (that is, Linux) cause
189 * an interrupt in the firmware, to tell the firmware about those events:
191 * IF_CS_BIT_TX a data packet has been downloaded
192 * IF_CS_BIT_RX a received data packet has retrieved
193 * IF_CS_BIT_COMMAND a firmware block or a command has been downloaded
194 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
195 * IF_CS_BIT_EVENT a host event (link lost etc) has been retrieved
197 #define IF_CS_HOST_INT_CAUSE 0x00000002
200 * The host int mask register is used to enable/disable interrupt. However,
201 * I have the suspicion that disabled interrupts are lost.
203 #define IF_CS_HOST_INT_MASK 0x00000004
206 * Used to send or receive data packets:
208 #define IF_CS_WRITE 0x00000016
209 #define IF_CS_WRITE_LEN 0x00000014
210 #define IF_CS_READ 0x00000010
211 #define IF_CS_READ_LEN 0x00000024
214 * Used to send commands (and to send firmware block) and to
215 * receive command responses:
217 #define IF_CS_CMD 0x0000001A
218 #define IF_CS_CMD_LEN 0x00000018
219 #define IF_CS_RESP 0x00000012
220 #define IF_CS_RESP_LEN 0x00000030
223 * The card status registers shows what the card/firmware actually
226 * IF_CS_BIT_TX you may send a data packet
227 * IF_CS_BIT_RX you may retrieve a data packet
228 * IF_CS_BIT_COMMAND you may send a command
229 * IF_CS_BIT_RESP you may retrieve a command response
230 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
232 * When reading this register several times, you will get back the same
233 * results --- with one exception: the IF_CS_BIT_EVENT clear itself
236 * Not that we don't rely on BIT_RX,_BIT_RESP or BIT_EVENT because
237 * we handle this via the card int cause register.
239 #define IF_CS_CARD_STATUS 0x00000020
240 #define IF_CS_CARD_STATUS_MASK 0x7f00
243 * The card int cause register is used by the card/firmware to notify us
244 * about the following events:
246 * IF_CS_BIT_TX a data packet has successfully been sentx
247 * IF_CS_BIT_RX a data packet has been received and can be retrieved
248 * IF_CS_BIT_COMMAND not used
249 * IF_CS_BIT_RESP the firmware has a command response for us
250 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
252 #define IF_CS_CARD_INT_CAUSE 0x00000022
255 * This is used to for handshaking with the card's bootloader/helper image
256 * to synchronize downloading of firmware blocks.
258 #define IF_CS_SQ_READ_LOW 0x00000028
259 #define IF_CS_SQ_HELPER_OK 0x10
262 * The scratch register tells us ...
264 * IF_CS_SCRATCH_BOOT_OK the bootloader runs
265 * IF_CS_SCRATCH_HELPER_OK the helper firmware already runs
267 #define IF_CS_SCRATCH 0x0000003F
268 #define IF_CS_SCRATCH_BOOT_OK 0x00
269 #define IF_CS_SCRATCH_HELPER_OK 0x5a
272 * Used to detect ancient chips:
274 #define IF_CS_PRODUCT_ID 0x0000001C
275 #define IF_CS_CF8385_B1_REV 0x12
278 /********************************************************************/
279 /* I/O and interrupt handling */
280 /********************************************************************/
282 static inline void if_cs_enable_ints(struct if_cs_card *card)
284 lbs_deb_enter(LBS_DEB_CS);
285 if_cs_write16(card, IF_CS_HOST_INT_MASK, 0);
288 static inline void if_cs_disable_ints(struct if_cs_card *card)
290 lbs_deb_enter(LBS_DEB_CS);
291 if_cs_write16(card, IF_CS_HOST_INT_MASK, IF_CS_BIT_MASK);
295 * Called from if_cs_host_to_card to send a command to the hardware
297 static int if_cs_send_cmd(struct lbs_private *priv, u8 *buf, u16 nb)
299 struct if_cs_card *card = (struct if_cs_card *)priv->card;
303 lbs_deb_enter(LBS_DEB_CS);
304 if_cs_disable_ints(card);
306 /* Is hardware ready? */
308 u16 status = if_cs_read16(card, IF_CS_CARD_STATUS);
309 if (status & IF_CS_BIT_COMMAND)
312 lbs_pr_err("card not ready for commands\n");
318 if_cs_write16(card, IF_CS_CMD_LEN, nb);
320 if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2);
321 /* Are we supposed to transfer an odd amount of bytes? */
323 if_cs_write8(card, IF_CS_CMD, buf[nb-1]);
325 /* "Assert the download over interrupt command in the Host
326 * status register" */
327 if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
329 /* "Assert the download over interrupt command in the Card
330 * interrupt case register" */
331 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
335 if_cs_enable_ints(card);
336 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
341 * Called from if_cs_host_to_card to send a data to the hardware
343 static void if_cs_send_data(struct lbs_private *priv, u8 *buf, u16 nb)
345 struct if_cs_card *card = (struct if_cs_card *)priv->card;
348 lbs_deb_enter(LBS_DEB_CS);
349 if_cs_disable_ints(card);
351 status = if_cs_read16(card, IF_CS_CARD_STATUS);
352 BUG_ON((status & IF_CS_BIT_TX) == 0);
354 if_cs_write16(card, IF_CS_WRITE_LEN, nb);
356 /* write even number of bytes, then odd byte if necessary */
357 if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2);
359 if_cs_write8(card, IF_CS_WRITE, buf[nb-1]);
361 if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_TX);
362 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_TX);
363 if_cs_enable_ints(card);
365 lbs_deb_leave(LBS_DEB_CS);
369 * Get the command result out of the card.
371 static int if_cs_receive_cmdres(struct lbs_private *priv, u8 *data, u32 *len)
377 lbs_deb_enter(LBS_DEB_CS);
379 /* is hardware ready? */
380 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
381 if ((status & IF_CS_BIT_RESP) == 0) {
382 lbs_pr_err("no cmd response in card\n");
387 *len = if_cs_read16(priv->card, IF_CS_RESP_LEN);
388 if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) {
389 lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len);
393 /* read even number of bytes, then odd byte if necessary */
394 if_cs_read16_rep(priv->card, IF_CS_RESP, data, *len/sizeof(u16));
396 data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP);
398 /* This is a workaround for a firmware that reports too much
403 /* Clear this flag again */
404 spin_lock_irqsave(&priv->driver_lock, flags);
405 priv->dnld_sent = DNLD_RES_RECEIVED;
406 spin_unlock_irqrestore(&priv->driver_lock, flags);
409 lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len);
413 static struct sk_buff *if_cs_receive_data(struct lbs_private *priv)
415 struct sk_buff *skb = NULL;
419 lbs_deb_enter(LBS_DEB_CS);
421 len = if_cs_read16(priv->card, IF_CS_READ_LEN);
422 if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
423 lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len);
424 priv->stats.rx_dropped++;
428 skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
432 skb_reserve(skb, 2);/* 16 byte align */
435 /* read even number of bytes, then odd byte if necessary */
436 if_cs_read16_rep(priv->card, IF_CS_READ, data, len/sizeof(u16));
438 data[len-1] = if_cs_read8(priv->card, IF_CS_READ);
441 if_cs_write16(priv->card, IF_CS_HOST_STATUS, IF_CS_BIT_RX);
442 if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_RX);
445 lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb);
449 static irqreturn_t if_cs_interrupt(int irq, void *data)
451 struct if_cs_card *card = data;
452 struct lbs_private *priv = card->priv;
455 lbs_deb_enter(LBS_DEB_CS);
457 /* Ask card interrupt cause register if there is something for us */
458 cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE);
459 lbs_deb_cs("cause 0x%04x\n", cause);
466 if (cause == 0xffff) {
467 /* Read in junk, the card has probably been removed */
468 card->priv->surpriseremoved = 1;
472 if (cause & IF_CS_BIT_RX) {
474 lbs_deb_cs("rx packet\n");
475 skb = if_cs_receive_data(priv);
477 lbs_process_rxed_packet(priv, skb);
480 if (cause & IF_CS_BIT_TX) {
481 lbs_deb_cs("tx done\n");
482 lbs_host_to_card_done(priv);
485 if (cause & IF_CS_BIT_RESP) {
489 lbs_deb_cs("cmd resp\n");
490 spin_lock_irqsave(&priv->driver_lock, flags);
491 i = (priv->resp_idx == 0) ? 1 : 0;
492 spin_unlock_irqrestore(&priv->driver_lock, flags);
494 BUG_ON(priv->resp_len[i]);
495 if_cs_receive_cmdres(priv, priv->resp_buf[i],
498 spin_lock_irqsave(&priv->driver_lock, flags);
499 lbs_notify_command_response(priv, i);
500 spin_unlock_irqrestore(&priv->driver_lock, flags);
503 if (cause & IF_CS_BIT_EVENT) {
504 u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
505 if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE,
507 lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8);
510 /* Clear interrupt cause */
511 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK);
513 lbs_deb_leave(LBS_DEB_CS);
520 /********************************************************************/
522 /********************************************************************/
525 * Tries to program the helper firmware.
527 * Return 0 on success
529 static int if_cs_prog_helper(struct if_cs_card *card)
534 const struct firmware *fw;
536 lbs_deb_enter(LBS_DEB_CS);
538 scratch = if_cs_read8(card, IF_CS_SCRATCH);
540 /* "If the value is 0x5a, the firmware is already
541 * downloaded successfully"
543 if (scratch == IF_CS_SCRATCH_HELPER_OK)
546 /* "If the value is != 00, it is invalid value of register */
547 if (scratch != IF_CS_SCRATCH_BOOT_OK) {
552 /* TODO: make firmware file configurable */
553 ret = request_firmware(&fw, "libertas_cs_helper.fw",
554 &handle_to_dev(card->p_dev));
556 lbs_pr_err("can't load helper firmware\n");
560 lbs_deb_cs("helper size %td\n", fw->size);
562 /* "Set the 5 bytes of the helper image to 0" */
563 /* Not needed, this contains an ARM branch instruction */
566 /* "the number of bytes to send is 256" */
568 int remain = fw->size - sent;
573 /* "write the number of bytes to be sent to the I/O Command
574 * write length register" */
575 if_cs_write16(card, IF_CS_CMD_LEN, count);
577 /* "write this to I/O Command port register as 16 bit writes */
579 if_cs_write16_rep(card, IF_CS_CMD,
583 /* "Assert the download over interrupt command in the Host
584 * status register" */
585 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
587 /* "Assert the download over interrupt command in the Card
588 * interrupt case register" */
589 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
591 /* "The host polls the Card Status register ... for 50 ms before
592 declaring a failure */
593 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
596 lbs_pr_err("can't download helper at 0x%x, ret %d\n",
607 release_firmware(fw);
611 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
616 static int if_cs_prog_real(struct if_cs_card *card)
618 const struct firmware *fw;
624 lbs_deb_enter(LBS_DEB_CS);
626 /* TODO: make firmware file configurable */
627 ret = request_firmware(&fw, "libertas_cs.fw",
628 &handle_to_dev(card->p_dev));
630 lbs_pr_err("can't load firmware\n");
634 lbs_deb_cs("fw size %td\n", fw->size);
636 ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW,
639 lbs_pr_err("helper firmware doesn't answer\n");
643 for (sent = 0; sent < fw->size; sent += len) {
644 len = if_cs_read16(card, IF_CS_SQ_READ_LOW);
647 lbs_pr_info("odd, need to retry this firmware block\n");
653 lbs_pr_err("could not download firmware\n");
662 if_cs_write16(card, IF_CS_CMD_LEN, len);
664 if_cs_write16_rep(card, IF_CS_CMD,
667 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
668 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
670 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
673 lbs_pr_err("can't download firmware at 0x%x\n", sent);
678 ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a);
680 lbs_pr_err("firmware download failed\n");
689 release_firmware(fw);
692 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
698 /********************************************************************/
699 /* Callback functions for libertas.ko */
700 /********************************************************************/
702 /* Send commands or data packets to the card */
703 static int if_cs_host_to_card(struct lbs_private *priv,
710 lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb);
714 priv->dnld_sent = DNLD_DATA_SENT;
715 if_cs_send_data(priv, buf, nb);
719 priv->dnld_sent = DNLD_CMD_SENT;
720 ret = if_cs_send_cmd(priv, buf, nb);
723 lbs_pr_err("%s: unsupported type %d\n", __func__, type);
726 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
731 /********************************************************************/
733 /********************************************************************/
736 * After a card is removed, if_cs_release() will unregister the
737 * device, and release the PCMCIA configuration. If the device is
738 * still open, this will be postponed until it is closed.
740 static void if_cs_release(struct pcmcia_device *p_dev)
742 struct if_cs_card *card = p_dev->priv;
744 lbs_deb_enter(LBS_DEB_CS);
746 free_irq(p_dev->irq.AssignedIRQ, card);
747 pcmcia_disable_device(p_dev);
749 ioport_unmap(card->iobase);
751 lbs_deb_leave(LBS_DEB_CS);
756 * This creates an "instance" of the driver, allocating local data
757 * structures for one device. The device is registered with Card
760 * The dev_link structure is initialized, but we don't actually
761 * configure the card at this point -- we wait until we receive a card
764 static int if_cs_probe(struct pcmcia_device *p_dev)
767 struct lbs_private *priv;
768 struct if_cs_card *card;
772 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
773 cistpl_io_t *io = &cfg->io;
776 lbs_deb_enter(LBS_DEB_CS);
778 card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL);
780 lbs_pr_err("error in kzalloc\n");
786 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
787 p_dev->irq.Handler = NULL;
788 p_dev->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
790 p_dev->conf.Attributes = 0;
791 p_dev->conf.IntType = INT_MEMORY_AND_IO;
793 tuple.Attributes = 0;
794 tuple.TupleData = buf;
795 tuple.TupleDataMax = sizeof(buf);
796 tuple.TupleOffset = 0;
798 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
799 if ((ret = pcmcia_get_first_tuple(p_dev, &tuple)) != 0 ||
800 (ret = pcmcia_get_tuple_data(p_dev, &tuple)) != 0 ||
801 (ret = pcmcia_parse_tuple(p_dev, &tuple, &parse)) != 0)
803 lbs_pr_err("error in pcmcia_get_first_tuple etc\n");
807 p_dev->conf.ConfigIndex = cfg->index;
809 /* Do we need to allocate an interrupt? */
810 if (cfg->irq.IRQInfo1) {
811 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
814 /* IO window settings */
815 if (cfg->io.nwin != 1) {
816 lbs_pr_err("wrong CIS (check number of IO windows)\n");
820 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
821 p_dev->io.BasePort1 = io->win[0].base;
822 p_dev->io.NumPorts1 = io->win[0].len;
824 /* This reserves IO space but doesn't actually enable it */
825 ret = pcmcia_request_io(p_dev, &p_dev->io);
827 lbs_pr_err("error in pcmcia_request_io\n");
832 * Allocate an interrupt line. Note that this does not assign
833 * a handler to the interrupt, unless the 'Handler' member of
834 * the irq structure is initialized.
836 if (p_dev->conf.Attributes & CONF_ENABLE_IRQ) {
837 ret = pcmcia_request_irq(p_dev, &p_dev->irq);
839 lbs_pr_err("error in pcmcia_request_irq\n");
844 /* Initialize io access */
845 card->iobase = ioport_map(p_dev->io.BasePort1, p_dev->io.NumPorts1);
847 lbs_pr_err("error in ioport_map\n");
853 * This actually configures the PCMCIA socket -- setting up
854 * the I/O windows and the interrupt mapping, and putting the
855 * card and host interface into "Memory and IO" mode.
857 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
859 lbs_pr_err("error in pcmcia_request_configuration\n");
863 /* Finally, report what we've done */
864 lbs_deb_cs("irq %d, io 0x%04x-0x%04x\n",
865 p_dev->irq.AssignedIRQ, p_dev->io.BasePort1,
866 p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1);
868 /* Check if we have a current silicon */
869 if (if_cs_read8(card, IF_CS_PRODUCT_ID) < IF_CS_CF8385_B1_REV) {
870 lbs_pr_err("old chips like 8385 rev B1 aren't supported\n");
875 /* Load the firmware early, before calling into libertas.ko */
876 ret = if_cs_prog_helper(card);
878 ret = if_cs_prog_real(card);
882 /* Make this card known to the libertas driver */
883 priv = lbs_add_card(card, &p_dev->dev);
889 /* Finish setting up fields in lbs_private */
892 priv->hw_host_to_card = if_cs_host_to_card;
895 /* Now actually get the IRQ */
896 ret = request_irq(p_dev->irq.AssignedIRQ, if_cs_interrupt,
897 IRQF_SHARED, DRV_NAME, card);
899 lbs_pr_err("error in request_irq\n");
903 /* Clear any interrupt cause that happend while sending
904 * firmware/initializing card */
905 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK);
906 if_cs_enable_ints(card);
908 /* And finally bring the card up */
909 if (lbs_start_card(priv) != 0) {
910 lbs_pr_err("could not activate card\n");
914 /* The firmware for the CF card supports powersave */
915 priv->ps_supported = 1;
921 lbs_remove_card(priv);
923 ioport_unmap(card->iobase);
925 pcmcia_disable_device(p_dev);
927 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
933 * This deletes a driver "instance". The device is de-registered with
934 * Card Services. If it has been released, all local data structures
935 * are freed. Otherwise, the structures will be freed when the device
938 static void if_cs_detach(struct pcmcia_device *p_dev)
940 struct if_cs_card *card = p_dev->priv;
942 lbs_deb_enter(LBS_DEB_CS);
944 lbs_stop_card(card->priv);
945 lbs_remove_card(card->priv);
946 if_cs_disable_ints(card);
947 if_cs_release(p_dev);
950 lbs_deb_leave(LBS_DEB_CS);
955 /********************************************************************/
956 /* Module initialization */
957 /********************************************************************/
959 static struct pcmcia_device_id if_cs_ids[] = {
960 PCMCIA_DEVICE_MANF_CARD(0x02df, 0x8103),
963 MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
966 static struct pcmcia_driver lbs_driver = {
967 .owner = THIS_MODULE,
971 .probe = if_cs_probe,
972 .remove = if_cs_detach,
973 .id_table = if_cs_ids,
977 static int __init if_cs_init(void)
981 lbs_deb_enter(LBS_DEB_CS);
982 ret = pcmcia_register_driver(&lbs_driver);
983 lbs_deb_leave(LBS_DEB_CS);
988 static void __exit if_cs_exit(void)
990 lbs_deb_enter(LBS_DEB_CS);
991 pcmcia_unregister_driver(&lbs_driver);
992 lbs_deb_leave(LBS_DEB_CS);
996 module_init(if_cs_init);
997 module_exit(if_cs_exit);