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/slab.h>
26 #include <linux/delay.h>
27 #include <linux/moduleparam.h>
28 #include <linux/firmware.h>
29 #include <linux/netdevice.h>
31 #include <pcmcia/cistpl.h>
32 #include <pcmcia/ds.h>
36 #define DRV_NAME "libertas_cs"
43 /********************************************************************/
45 /********************************************************************/
47 MODULE_AUTHOR("Holger Schurig <hs4233@mail.mn-solutions.de>");
48 MODULE_DESCRIPTION("Driver for Marvell 83xx compact flash WLAN cards");
49 MODULE_LICENSE("GPL");
50 MODULE_FIRMWARE("libertas_cs_helper.fw");
54 /********************************************************************/
56 /********************************************************************/
59 struct pcmcia_device *p_dev;
60 struct lbs_private *priv;
67 /********************************************************************/
69 /********************************************************************/
71 /* This define enables wrapper functions which allow you
72 to dump all register accesses. You normally won't this,
73 except for development */
74 /* #define DEBUG_IO */
77 static int debug_output = 0;
79 /* This way the compiler optimizes the printk's away */
80 #define debug_output 0
83 static inline unsigned int if_cs_read8(struct if_cs_card *card, uint reg)
85 unsigned int val = ioread8(card->iobase + reg);
87 printk(KERN_INFO "inb %08x<%02x\n", reg, val);
90 static inline unsigned int if_cs_read16(struct if_cs_card *card, uint reg)
92 unsigned int val = ioread16(card->iobase + reg);
94 printk(KERN_INFO "inw %08x<%04x\n", reg, val);
97 static inline void if_cs_read16_rep(
98 struct if_cs_card *card,
104 printk(KERN_INFO "insw %08x<(0x%lx words)\n",
106 ioread16_rep(card->iobase + reg, buf, count);
109 static inline void if_cs_write8(struct if_cs_card *card, uint reg, u8 val)
112 printk(KERN_INFO "outb %08x>%02x\n", reg, val);
113 iowrite8(val, card->iobase + reg);
116 static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val)
119 printk(KERN_INFO "outw %08x>%04x\n", reg, val);
120 iowrite16(val, card->iobase + reg);
123 static inline void if_cs_write16_rep(
124 struct if_cs_card *card,
130 printk(KERN_INFO "outsw %08x>(0x%lx words)\n",
132 iowrite16_rep(card->iobase + reg, buf, count);
137 * I know that polling/delaying is frowned upon. However, this procedure
138 * with polling is needed while downloading the firmware. At this stage,
139 * the hardware does unfortunately not create any interrupts.
141 * Fortunately, this function is never used once the firmware is in
144 * As a reference, see the "Firmware Specification v5.1", page 18
145 * and 19. I did not follow their suggested timing to the word,
146 * but this works nice & fast anyway.
148 static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 reg)
152 for (i = 0; i < 100000; i++) {
153 u8 val = if_cs_read8(card, addr);
164 * First the bitmasks for the host/card interrupt/status registers:
166 #define IF_CS_BIT_TX 0x0001
167 #define IF_CS_BIT_RX 0x0002
168 #define IF_CS_BIT_COMMAND 0x0004
169 #define IF_CS_BIT_RESP 0x0008
170 #define IF_CS_BIT_EVENT 0x0010
171 #define IF_CS_BIT_MASK 0x001f
176 * It's not really clear to me what the host status register is for. It
177 * needs to be set almost in union with "host int cause". The following
178 * bits from above are used:
180 * IF_CS_BIT_TX driver downloaded a data packet
181 * IF_CS_BIT_RX driver got a data packet
182 * IF_CS_BIT_COMMAND driver downloaded a command
183 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
184 * IF_CS_BIT_EVENT driver read a host event
186 #define IF_CS_HOST_STATUS 0x00000000
189 * With the host int cause register can the host (that is, Linux) cause
190 * an interrupt in the firmware, to tell the firmware about those events:
192 * IF_CS_BIT_TX a data packet has been downloaded
193 * IF_CS_BIT_RX a received data packet has retrieved
194 * IF_CS_BIT_COMMAND a firmware block or a command has been downloaded
195 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
196 * IF_CS_BIT_EVENT a host event (link lost etc) has been retrieved
198 #define IF_CS_HOST_INT_CAUSE 0x00000002
201 * The host int mask register is used to enable/disable interrupt. However,
202 * I have the suspicion that disabled interrupts are lost.
204 #define IF_CS_HOST_INT_MASK 0x00000004
207 * Used to send or receive data packets:
209 #define IF_CS_WRITE 0x00000016
210 #define IF_CS_WRITE_LEN 0x00000014
211 #define IF_CS_READ 0x00000010
212 #define IF_CS_READ_LEN 0x00000024
215 * Used to send commands (and to send firmware block) and to
216 * receive command responses:
218 #define IF_CS_CMD 0x0000001A
219 #define IF_CS_CMD_LEN 0x00000018
220 #define IF_CS_RESP 0x00000012
221 #define IF_CS_RESP_LEN 0x00000030
224 * The card status registers shows what the card/firmware actually
227 * IF_CS_BIT_TX you may send a data packet
228 * IF_CS_BIT_RX you may retrieve a data packet
229 * IF_CS_BIT_COMMAND you may send a command
230 * IF_CS_BIT_RESP you may retrieve a command response
231 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
233 * When reading this register several times, you will get back the same
234 * results --- with one exception: the IF_CS_BIT_EVENT clear itself
237 * Not that we don't rely on BIT_RX,_BIT_RESP or BIT_EVENT because
238 * we handle this via the card int cause register.
240 #define IF_CS_CARD_STATUS 0x00000020
241 #define IF_CS_CARD_STATUS_MASK 0x7f00
244 * The card int cause register is used by the card/firmware to notify us
245 * about the following events:
247 * IF_CS_BIT_TX a data packet has successfully been sentx
248 * IF_CS_BIT_RX a data packet has been received and can be retrieved
249 * IF_CS_BIT_COMMAND not used
250 * IF_CS_BIT_RESP the firmware has a command response for us
251 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
253 #define IF_CS_CARD_INT_CAUSE 0x00000022
256 * This is used to for handshaking with the card's bootloader/helper image
257 * to synchronize downloading of firmware blocks.
259 #define IF_CS_SQ_READ_LOW 0x00000028
260 #define IF_CS_SQ_HELPER_OK 0x10
263 * The scratch register tells us ...
265 * IF_CS_SCRATCH_BOOT_OK the bootloader runs
266 * IF_CS_SCRATCH_HELPER_OK the helper firmware already runs
268 #define IF_CS_SCRATCH 0x0000003F
269 #define IF_CS_SCRATCH_BOOT_OK 0x00
270 #define IF_CS_SCRATCH_HELPER_OK 0x5a
273 * Used to detect ancient chips:
275 #define IF_CS_PRODUCT_ID 0x0000001C
276 #define IF_CS_CF8385_B1_REV 0x12
277 #define IF_CS_CF8381_B3_REV 0x04
278 #define IF_CS_CF8305_B1_REV 0x03
281 * Used to detect other cards than CF8385 since their revisions of silicon
282 * doesn't match those from CF8385, eg. CF8381 B3 works with this driver.
284 #define CF8305_MANFID 0x02db
285 #define CF8305_CARDID 0x8103
286 #define CF8381_MANFID 0x02db
287 #define CF8381_CARDID 0x6064
288 #define CF8385_MANFID 0x02df
289 #define CF8385_CARDID 0x8103
291 static inline int if_cs_hw_is_cf8305(struct pcmcia_device *p_dev)
293 return (p_dev->manf_id == CF8305_MANFID &&
294 p_dev->card_id == CF8305_CARDID);
297 static inline int if_cs_hw_is_cf8381(struct pcmcia_device *p_dev)
299 return (p_dev->manf_id == CF8381_MANFID &&
300 p_dev->card_id == CF8381_CARDID);
303 static inline int if_cs_hw_is_cf8385(struct pcmcia_device *p_dev)
305 return (p_dev->manf_id == CF8385_MANFID &&
306 p_dev->card_id == CF8385_CARDID);
309 /********************************************************************/
310 /* I/O and interrupt handling */
311 /********************************************************************/
313 static inline void if_cs_enable_ints(struct if_cs_card *card)
315 lbs_deb_enter(LBS_DEB_CS);
316 if_cs_write16(card, IF_CS_HOST_INT_MASK, 0);
319 static inline void if_cs_disable_ints(struct if_cs_card *card)
321 lbs_deb_enter(LBS_DEB_CS);
322 if_cs_write16(card, IF_CS_HOST_INT_MASK, IF_CS_BIT_MASK);
326 * Called from if_cs_host_to_card to send a command to the hardware
328 static int if_cs_send_cmd(struct lbs_private *priv, u8 *buf, u16 nb)
330 struct if_cs_card *card = (struct if_cs_card *)priv->card;
334 lbs_deb_enter(LBS_DEB_CS);
335 if_cs_disable_ints(card);
337 /* Is hardware ready? */
339 u16 status = if_cs_read16(card, IF_CS_CARD_STATUS);
340 if (status & IF_CS_BIT_COMMAND)
343 lbs_pr_err("card not ready for commands\n");
349 if_cs_write16(card, IF_CS_CMD_LEN, nb);
351 if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2);
352 /* Are we supposed to transfer an odd amount of bytes? */
354 if_cs_write8(card, IF_CS_CMD, buf[nb-1]);
356 /* "Assert the download over interrupt command in the Host
357 * status register" */
358 if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
360 /* "Assert the download over interrupt command in the Card
361 * interrupt case register" */
362 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
366 if_cs_enable_ints(card);
367 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
372 * Called from if_cs_host_to_card to send a data to the hardware
374 static void if_cs_send_data(struct lbs_private *priv, u8 *buf, u16 nb)
376 struct if_cs_card *card = (struct if_cs_card *)priv->card;
379 lbs_deb_enter(LBS_DEB_CS);
380 if_cs_disable_ints(card);
382 status = if_cs_read16(card, IF_CS_CARD_STATUS);
383 BUG_ON((status & IF_CS_BIT_TX) == 0);
385 if_cs_write16(card, IF_CS_WRITE_LEN, nb);
387 /* write even number of bytes, then odd byte if necessary */
388 if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2);
390 if_cs_write8(card, IF_CS_WRITE, buf[nb-1]);
392 if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_TX);
393 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_TX);
394 if_cs_enable_ints(card);
396 lbs_deb_leave(LBS_DEB_CS);
400 * Get the command result out of the card.
402 static int if_cs_receive_cmdres(struct lbs_private *priv, u8 *data, u32 *len)
408 lbs_deb_enter(LBS_DEB_CS);
410 /* is hardware ready? */
411 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
412 if ((status & IF_CS_BIT_RESP) == 0) {
413 lbs_pr_err("no cmd response in card\n");
418 *len = if_cs_read16(priv->card, IF_CS_RESP_LEN);
419 if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) {
420 lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len);
424 /* read even number of bytes, then odd byte if necessary */
425 if_cs_read16_rep(priv->card, IF_CS_RESP, data, *len/sizeof(u16));
427 data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP);
429 /* This is a workaround for a firmware that reports too much
434 /* Clear this flag again */
435 spin_lock_irqsave(&priv->driver_lock, flags);
436 priv->dnld_sent = DNLD_RES_RECEIVED;
437 spin_unlock_irqrestore(&priv->driver_lock, flags);
440 lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len);
444 static struct sk_buff *if_cs_receive_data(struct lbs_private *priv)
446 struct sk_buff *skb = NULL;
450 lbs_deb_enter(LBS_DEB_CS);
452 len = if_cs_read16(priv->card, IF_CS_READ_LEN);
453 if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
454 lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len);
455 priv->dev->stats.rx_dropped++;
459 skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
463 skb_reserve(skb, 2);/* 16 byte align */
466 /* read even number of bytes, then odd byte if necessary */
467 if_cs_read16_rep(priv->card, IF_CS_READ, data, len/sizeof(u16));
469 data[len-1] = if_cs_read8(priv->card, IF_CS_READ);
472 if_cs_write16(priv->card, IF_CS_HOST_STATUS, IF_CS_BIT_RX);
473 if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_RX);
476 lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb);
480 static irqreturn_t if_cs_interrupt(int irq, void *data)
482 struct if_cs_card *card = data;
483 struct lbs_private *priv = card->priv;
486 lbs_deb_enter(LBS_DEB_CS);
488 /* Ask card interrupt cause register if there is something for us */
489 cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE);
490 lbs_deb_cs("cause 0x%04x\n", cause);
497 if (cause == 0xffff) {
498 /* Read in junk, the card has probably been removed */
499 card->priv->surpriseremoved = 1;
503 if (cause & IF_CS_BIT_RX) {
505 lbs_deb_cs("rx packet\n");
506 skb = if_cs_receive_data(priv);
508 lbs_process_rxed_packet(priv, skb);
511 if (cause & IF_CS_BIT_TX) {
512 lbs_deb_cs("tx done\n");
513 lbs_host_to_card_done(priv);
516 if (cause & IF_CS_BIT_RESP) {
520 lbs_deb_cs("cmd resp\n");
521 spin_lock_irqsave(&priv->driver_lock, flags);
522 i = (priv->resp_idx == 0) ? 1 : 0;
523 spin_unlock_irqrestore(&priv->driver_lock, flags);
525 BUG_ON(priv->resp_len[i]);
526 if_cs_receive_cmdres(priv, priv->resp_buf[i],
529 spin_lock_irqsave(&priv->driver_lock, flags);
530 lbs_notify_command_response(priv, i);
531 spin_unlock_irqrestore(&priv->driver_lock, flags);
534 if (cause & IF_CS_BIT_EVENT) {
535 u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
536 if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE,
538 lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8);
541 /* Clear interrupt cause */
542 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK);
544 lbs_deb_leave(LBS_DEB_CS);
551 /********************************************************************/
553 /********************************************************************/
556 * Tries to program the helper firmware.
558 * Return 0 on success
560 static int if_cs_prog_helper(struct if_cs_card *card)
565 const struct firmware *fw;
567 lbs_deb_enter(LBS_DEB_CS);
570 * This is the only place where an unaligned register access happens on
571 * the CF8305 card, therefore for the sake of speed of the driver, we do
572 * the alignment correction here.
574 if (card->align_regs)
575 scratch = if_cs_read16(card, IF_CS_SCRATCH) >> 8;
577 scratch = if_cs_read8(card, IF_CS_SCRATCH);
579 /* "If the value is 0x5a, the firmware is already
580 * downloaded successfully"
582 if (scratch == IF_CS_SCRATCH_HELPER_OK)
585 /* "If the value is != 00, it is invalid value of register */
586 if (scratch != IF_CS_SCRATCH_BOOT_OK) {
591 /* TODO: make firmware file configurable */
592 ret = request_firmware(&fw, "libertas_cs_helper.fw",
595 lbs_pr_err("can't load helper firmware\n");
599 lbs_deb_cs("helper size %td\n", fw->size);
601 /* "Set the 5 bytes of the helper image to 0" */
602 /* Not needed, this contains an ARM branch instruction */
605 /* "the number of bytes to send is 256" */
607 int remain = fw->size - sent;
612 /* "write the number of bytes to be sent to the I/O Command
613 * write length register" */
614 if_cs_write16(card, IF_CS_CMD_LEN, count);
616 /* "write this to I/O Command port register as 16 bit writes */
618 if_cs_write16_rep(card, IF_CS_CMD,
622 /* "Assert the download over interrupt command in the Host
623 * status register" */
624 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
626 /* "Assert the download over interrupt command in the Card
627 * interrupt case register" */
628 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
630 /* "The host polls the Card Status register ... for 50 ms before
631 declaring a failure */
632 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
635 lbs_pr_err("can't download helper at 0x%x, ret %d\n",
647 release_firmware(fw);
649 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
654 static int if_cs_prog_real(struct if_cs_card *card)
656 const struct firmware *fw;
662 lbs_deb_enter(LBS_DEB_CS);
664 /* TODO: make firmware file configurable */
665 ret = request_firmware(&fw, "libertas_cs.fw",
668 lbs_pr_err("can't load firmware\n");
672 lbs_deb_cs("fw size %td\n", fw->size);
674 ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW,
677 lbs_pr_err("helper firmware doesn't answer\n");
681 for (sent = 0; sent < fw->size; sent += len) {
682 len = if_cs_read16(card, IF_CS_SQ_READ_LOW);
685 lbs_pr_info("odd, need to retry this firmware block\n");
691 lbs_pr_err("could not download firmware\n");
700 if_cs_write16(card, IF_CS_CMD_LEN, len);
702 if_cs_write16_rep(card, IF_CS_CMD,
705 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
706 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
708 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
711 lbs_pr_err("can't download firmware at 0x%x\n", sent);
716 ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a);
718 lbs_pr_err("firmware download failed\n");
721 release_firmware(fw);
724 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
730 /********************************************************************/
731 /* Callback functions for libertas.ko */
732 /********************************************************************/
734 /* Send commands or data packets to the card */
735 static int if_cs_host_to_card(struct lbs_private *priv,
742 lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb);
746 priv->dnld_sent = DNLD_DATA_SENT;
747 if_cs_send_data(priv, buf, nb);
751 priv->dnld_sent = DNLD_CMD_SENT;
752 ret = if_cs_send_cmd(priv, buf, nb);
755 lbs_pr_err("%s: unsupported type %d\n", __func__, type);
758 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
763 /********************************************************************/
765 /********************************************************************/
768 * After a card is removed, if_cs_release() will unregister the
769 * device, and release the PCMCIA configuration. If the device is
770 * still open, this will be postponed until it is closed.
772 static void if_cs_release(struct pcmcia_device *p_dev)
774 struct if_cs_card *card = p_dev->priv;
776 lbs_deb_enter(LBS_DEB_CS);
778 free_irq(p_dev->irq, card);
779 pcmcia_disable_device(p_dev);
781 ioport_unmap(card->iobase);
783 lbs_deb_leave(LBS_DEB_CS);
788 * This creates an "instance" of the driver, allocating local data
789 * structures for one device. The device is registered with Card
792 * The dev_link structure is initialized, but we don't actually
793 * configure the card at this point -- we wait until we receive a card
797 static int if_cs_ioprobe(struct pcmcia_device *p_dev, void *priv_data)
799 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
800 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
802 if (p_dev->resource[1]->end) {
803 lbs_pr_err("wrong CIS (check number of IO windows)\n");
807 /* This reserves IO space but doesn't actually enable it */
808 return pcmcia_request_io(p_dev);
811 static int if_cs_probe(struct pcmcia_device *p_dev)
814 unsigned int prod_id;
815 struct lbs_private *priv;
816 struct if_cs_card *card;
818 lbs_deb_enter(LBS_DEB_CS);
820 card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL);
822 lbs_pr_err("error in kzalloc\n");
828 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
830 if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) {
831 lbs_pr_err("error in pcmcia_loop_config\n");
836 * Allocate an interrupt line. Note that this does not assign
837 * a handler to the interrupt, unless the 'Handler' member of
838 * the irq structure is initialized.
843 /* Initialize io access */
844 card->iobase = ioport_map(p_dev->resource[0]->start,
845 resource_size(p_dev->resource[0]));
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_enable_device(p_dev);
859 lbs_pr_err("error in pcmcia_enable_device\n");
863 /* Finally, report what we've done */
864 lbs_deb_cs("irq %d, io %pR", p_dev->irq, p_dev->resource[0]);
867 * Most of the libertas cards can do unaligned register access, but some
868 * weird ones can not. That's especially true for the CF8305 card.
870 card->align_regs = 0;
872 /* Check if we have a current silicon */
873 prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID);
874 if (if_cs_hw_is_cf8305(p_dev)) {
875 card->align_regs = 1;
876 if (prod_id < IF_CS_CF8305_B1_REV) {
877 lbs_pr_err("old chips like 8305 rev B3 "
878 "aren't supported\n");
884 if (if_cs_hw_is_cf8381(p_dev) && prod_id < IF_CS_CF8381_B3_REV) {
885 lbs_pr_err("old chips like 8381 rev B3 aren't supported\n");
890 if (if_cs_hw_is_cf8385(p_dev) && prod_id < IF_CS_CF8385_B1_REV) {
891 lbs_pr_err("old chips like 8385 rev B1 aren't supported\n");
896 /* Load the firmware early, before calling into libertas.ko */
897 ret = if_cs_prog_helper(card);
898 if (ret == 0 && !if_cs_hw_is_cf8305(p_dev))
899 ret = if_cs_prog_real(card);
903 /* Make this card known to the libertas driver */
904 priv = lbs_add_card(card, &p_dev->dev);
910 /* Finish setting up fields in lbs_private */
913 priv->hw_host_to_card = if_cs_host_to_card;
914 priv->enter_deep_sleep = NULL;
915 priv->exit_deep_sleep = NULL;
916 priv->reset_deep_sleep_wakeup = NULL;
919 /* Now actually get the IRQ */
920 ret = request_irq(p_dev->irq, if_cs_interrupt,
921 IRQF_SHARED, DRV_NAME, card);
923 lbs_pr_err("error in request_irq\n");
927 /* Clear any interrupt cause that happend while sending
928 * firmware/initializing card */
929 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK);
930 if_cs_enable_ints(card);
932 /* And finally bring the card up */
933 if (lbs_start_card(priv) != 0) {
934 lbs_pr_err("could not activate card\n");
942 lbs_remove_card(priv);
944 ioport_unmap(card->iobase);
946 pcmcia_disable_device(p_dev);
948 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
954 * This deletes a driver "instance". The device is de-registered with
955 * Card Services. If it has been released, all local data structures
956 * are freed. Otherwise, the structures will be freed when the device
959 static void if_cs_detach(struct pcmcia_device *p_dev)
961 struct if_cs_card *card = p_dev->priv;
963 lbs_deb_enter(LBS_DEB_CS);
965 lbs_stop_card(card->priv);
966 lbs_remove_card(card->priv);
967 if_cs_disable_ints(card);
968 if_cs_release(p_dev);
971 lbs_deb_leave(LBS_DEB_CS);
976 /********************************************************************/
977 /* Module initialization */
978 /********************************************************************/
980 static struct pcmcia_device_id if_cs_ids[] = {
981 PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID),
982 PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID),
983 PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID),
986 MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
989 static struct pcmcia_driver lbs_driver = {
990 .owner = THIS_MODULE,
994 .probe = if_cs_probe,
995 .remove = if_cs_detach,
996 .id_table = if_cs_ids,
1000 static int __init if_cs_init(void)
1004 lbs_deb_enter(LBS_DEB_CS);
1005 ret = pcmcia_register_driver(&lbs_driver);
1006 lbs_deb_leave(LBS_DEB_CS);
1011 static void __exit if_cs_exit(void)
1013 lbs_deb_enter(LBS_DEB_CS);
1014 pcmcia_unregister_driver(&lbs_driver);
1015 lbs_deb_leave(LBS_DEB_CS);
1019 module_init(if_cs_init);
1020 module_exit(if_cs_exit);