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/cs_types.h>
32 #include <pcmcia/cs.h>
33 #include <pcmcia/cistpl.h>
34 #include <pcmcia/ds.h>
38 #define DRV_NAME "libertas_cs"
45 /********************************************************************/
47 /********************************************************************/
49 MODULE_AUTHOR("Holger Schurig <hs4233@mail.mn-solutions.de>");
50 MODULE_DESCRIPTION("Driver for Marvell 83xx compact flash WLAN cards");
51 MODULE_LICENSE("GPL");
52 MODULE_FIRMWARE("libertas_cs_helper.fw");
56 /********************************************************************/
58 /********************************************************************/
61 struct pcmcia_device *p_dev;
62 struct lbs_private *priv;
69 /********************************************************************/
71 /********************************************************************/
73 /* This define enables wrapper functions which allow you
74 to dump all register accesses. You normally won't this,
75 except for development */
76 /* #define DEBUG_IO */
79 static int debug_output = 0;
81 /* This way the compiler optimizes the printk's away */
82 #define debug_output 0
85 static inline unsigned int if_cs_read8(struct if_cs_card *card, uint reg)
87 unsigned int val = ioread8(card->iobase + reg);
89 printk(KERN_INFO "inb %08x<%02x\n", reg, val);
92 static inline unsigned int if_cs_read16(struct if_cs_card *card, uint reg)
94 unsigned int val = ioread16(card->iobase + reg);
96 printk(KERN_INFO "inw %08x<%04x\n", reg, val);
99 static inline void if_cs_read16_rep(
100 struct if_cs_card *card,
106 printk(KERN_INFO "insw %08x<(0x%lx words)\n",
108 ioread16_rep(card->iobase + reg, buf, count);
111 static inline void if_cs_write8(struct if_cs_card *card, uint reg, u8 val)
114 printk(KERN_INFO "outb %08x>%02x\n", reg, val);
115 iowrite8(val, card->iobase + reg);
118 static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val)
121 printk(KERN_INFO "outw %08x>%04x\n", reg, val);
122 iowrite16(val, card->iobase + reg);
125 static inline void if_cs_write16_rep(
126 struct if_cs_card *card,
132 printk(KERN_INFO "outsw %08x>(0x%lx words)\n",
134 iowrite16_rep(card->iobase + reg, buf, count);
139 * I know that polling/delaying is frowned upon. However, this procedure
140 * with polling is needed while downloading the firmware. At this stage,
141 * the hardware does unfortunately not create any interrupts.
143 * Fortunately, this function is never used once the firmware is in
146 * As a reference, see the "Firmware Specification v5.1", page 18
147 * and 19. I did not follow their suggested timing to the word,
148 * but this works nice & fast anyway.
150 static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 reg)
154 for (i = 0; i < 100000; i++) {
155 u8 val = if_cs_read8(card, addr);
166 * First the bitmasks for the host/card interrupt/status registers:
168 #define IF_CS_BIT_TX 0x0001
169 #define IF_CS_BIT_RX 0x0002
170 #define IF_CS_BIT_COMMAND 0x0004
171 #define IF_CS_BIT_RESP 0x0008
172 #define IF_CS_BIT_EVENT 0x0010
173 #define IF_CS_BIT_MASK 0x001f
178 * It's not really clear to me what the host status register is for. It
179 * needs to be set almost in union with "host int cause". The following
180 * bits from above are used:
182 * IF_CS_BIT_TX driver downloaded a data packet
183 * IF_CS_BIT_RX driver got a data packet
184 * IF_CS_BIT_COMMAND driver downloaded a command
185 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
186 * IF_CS_BIT_EVENT driver read a host event
188 #define IF_CS_HOST_STATUS 0x00000000
191 * With the host int cause register can the host (that is, Linux) cause
192 * an interrupt in the firmware, to tell the firmware about those events:
194 * IF_CS_BIT_TX a data packet has been downloaded
195 * IF_CS_BIT_RX a received data packet has retrieved
196 * IF_CS_BIT_COMMAND a firmware block or a command has been downloaded
197 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
198 * IF_CS_BIT_EVENT a host event (link lost etc) has been retrieved
200 #define IF_CS_HOST_INT_CAUSE 0x00000002
203 * The host int mask register is used to enable/disable interrupt. However,
204 * I have the suspicion that disabled interrupts are lost.
206 #define IF_CS_HOST_INT_MASK 0x00000004
209 * Used to send or receive data packets:
211 #define IF_CS_WRITE 0x00000016
212 #define IF_CS_WRITE_LEN 0x00000014
213 #define IF_CS_READ 0x00000010
214 #define IF_CS_READ_LEN 0x00000024
217 * Used to send commands (and to send firmware block) and to
218 * receive command responses:
220 #define IF_CS_CMD 0x0000001A
221 #define IF_CS_CMD_LEN 0x00000018
222 #define IF_CS_RESP 0x00000012
223 #define IF_CS_RESP_LEN 0x00000030
226 * The card status registers shows what the card/firmware actually
229 * IF_CS_BIT_TX you may send a data packet
230 * IF_CS_BIT_RX you may retrieve a data packet
231 * IF_CS_BIT_COMMAND you may send a command
232 * IF_CS_BIT_RESP you may retrieve a command response
233 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
235 * When reading this register several times, you will get back the same
236 * results --- with one exception: the IF_CS_BIT_EVENT clear itself
239 * Not that we don't rely on BIT_RX,_BIT_RESP or BIT_EVENT because
240 * we handle this via the card int cause register.
242 #define IF_CS_CARD_STATUS 0x00000020
243 #define IF_CS_CARD_STATUS_MASK 0x7f00
246 * The card int cause register is used by the card/firmware to notify us
247 * about the following events:
249 * IF_CS_BIT_TX a data packet has successfully been sentx
250 * IF_CS_BIT_RX a data packet has been received and can be retrieved
251 * IF_CS_BIT_COMMAND not used
252 * IF_CS_BIT_RESP the firmware has a command response for us
253 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
255 #define IF_CS_CARD_INT_CAUSE 0x00000022
258 * This is used to for handshaking with the card's bootloader/helper image
259 * to synchronize downloading of firmware blocks.
261 #define IF_CS_SQ_READ_LOW 0x00000028
262 #define IF_CS_SQ_HELPER_OK 0x10
265 * The scratch register tells us ...
267 * IF_CS_SCRATCH_BOOT_OK the bootloader runs
268 * IF_CS_SCRATCH_HELPER_OK the helper firmware already runs
270 #define IF_CS_SCRATCH 0x0000003F
271 #define IF_CS_SCRATCH_BOOT_OK 0x00
272 #define IF_CS_SCRATCH_HELPER_OK 0x5a
275 * Used to detect ancient chips:
277 #define IF_CS_PRODUCT_ID 0x0000001C
278 #define IF_CS_CF8385_B1_REV 0x12
279 #define IF_CS_CF8381_B3_REV 0x04
280 #define IF_CS_CF8305_B1_REV 0x03
283 * Used to detect other cards than CF8385 since their revisions of silicon
284 * doesn't match those from CF8385, eg. CF8381 B3 works with this driver.
286 #define CF8305_MANFID 0x02db
287 #define CF8305_CARDID 0x8103
288 #define CF8381_MANFID 0x02db
289 #define CF8381_CARDID 0x6064
290 #define CF8385_MANFID 0x02df
291 #define CF8385_CARDID 0x8103
293 static inline int if_cs_hw_is_cf8305(struct pcmcia_device *p_dev)
295 return (p_dev->manf_id == CF8305_MANFID &&
296 p_dev->card_id == CF8305_CARDID);
299 static inline int if_cs_hw_is_cf8381(struct pcmcia_device *p_dev)
301 return (p_dev->manf_id == CF8381_MANFID &&
302 p_dev->card_id == CF8381_CARDID);
305 static inline int if_cs_hw_is_cf8385(struct pcmcia_device *p_dev)
307 return (p_dev->manf_id == CF8385_MANFID &&
308 p_dev->card_id == CF8385_CARDID);
311 /********************************************************************/
312 /* I/O and interrupt handling */
313 /********************************************************************/
315 static inline void if_cs_enable_ints(struct if_cs_card *card)
317 lbs_deb_enter(LBS_DEB_CS);
318 if_cs_write16(card, IF_CS_HOST_INT_MASK, 0);
321 static inline void if_cs_disable_ints(struct if_cs_card *card)
323 lbs_deb_enter(LBS_DEB_CS);
324 if_cs_write16(card, IF_CS_HOST_INT_MASK, IF_CS_BIT_MASK);
328 * Called from if_cs_host_to_card to send a command to the hardware
330 static int if_cs_send_cmd(struct lbs_private *priv, u8 *buf, u16 nb)
332 struct if_cs_card *card = (struct if_cs_card *)priv->card;
336 lbs_deb_enter(LBS_DEB_CS);
337 if_cs_disable_ints(card);
339 /* Is hardware ready? */
341 u16 status = if_cs_read16(card, IF_CS_CARD_STATUS);
342 if (status & IF_CS_BIT_COMMAND)
345 lbs_pr_err("card not ready for commands\n");
351 if_cs_write16(card, IF_CS_CMD_LEN, nb);
353 if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2);
354 /* Are we supposed to transfer an odd amount of bytes? */
356 if_cs_write8(card, IF_CS_CMD, buf[nb-1]);
358 /* "Assert the download over interrupt command in the Host
359 * status register" */
360 if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
362 /* "Assert the download over interrupt command in the Card
363 * interrupt case register" */
364 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
368 if_cs_enable_ints(card);
369 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
374 * Called from if_cs_host_to_card to send a data to the hardware
376 static void if_cs_send_data(struct lbs_private *priv, u8 *buf, u16 nb)
378 struct if_cs_card *card = (struct if_cs_card *)priv->card;
381 lbs_deb_enter(LBS_DEB_CS);
382 if_cs_disable_ints(card);
384 status = if_cs_read16(card, IF_CS_CARD_STATUS);
385 BUG_ON((status & IF_CS_BIT_TX) == 0);
387 if_cs_write16(card, IF_CS_WRITE_LEN, nb);
389 /* write even number of bytes, then odd byte if necessary */
390 if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2);
392 if_cs_write8(card, IF_CS_WRITE, buf[nb-1]);
394 if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_TX);
395 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_TX);
396 if_cs_enable_ints(card);
398 lbs_deb_leave(LBS_DEB_CS);
402 * Get the command result out of the card.
404 static int if_cs_receive_cmdres(struct lbs_private *priv, u8 *data, u32 *len)
410 lbs_deb_enter(LBS_DEB_CS);
412 /* is hardware ready? */
413 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
414 if ((status & IF_CS_BIT_RESP) == 0) {
415 lbs_pr_err("no cmd response in card\n");
420 *len = if_cs_read16(priv->card, IF_CS_RESP_LEN);
421 if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) {
422 lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len);
426 /* read even number of bytes, then odd byte if necessary */
427 if_cs_read16_rep(priv->card, IF_CS_RESP, data, *len/sizeof(u16));
429 data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP);
431 /* This is a workaround for a firmware that reports too much
436 /* Clear this flag again */
437 spin_lock_irqsave(&priv->driver_lock, flags);
438 priv->dnld_sent = DNLD_RES_RECEIVED;
439 spin_unlock_irqrestore(&priv->driver_lock, flags);
442 lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len);
446 static struct sk_buff *if_cs_receive_data(struct lbs_private *priv)
448 struct sk_buff *skb = NULL;
452 lbs_deb_enter(LBS_DEB_CS);
454 len = if_cs_read16(priv->card, IF_CS_READ_LEN);
455 if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
456 lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len);
457 priv->dev->stats.rx_dropped++;
461 skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
465 skb_reserve(skb, 2);/* 16 byte align */
468 /* read even number of bytes, then odd byte if necessary */
469 if_cs_read16_rep(priv->card, IF_CS_READ, data, len/sizeof(u16));
471 data[len-1] = if_cs_read8(priv->card, IF_CS_READ);
474 if_cs_write16(priv->card, IF_CS_HOST_STATUS, IF_CS_BIT_RX);
475 if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_RX);
478 lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb);
482 static irqreturn_t if_cs_interrupt(int irq, void *data)
484 struct if_cs_card *card = data;
485 struct lbs_private *priv = card->priv;
488 lbs_deb_enter(LBS_DEB_CS);
490 /* Ask card interrupt cause register if there is something for us */
491 cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE);
492 lbs_deb_cs("cause 0x%04x\n", cause);
499 if (cause == 0xffff) {
500 /* Read in junk, the card has probably been removed */
501 card->priv->surpriseremoved = 1;
505 if (cause & IF_CS_BIT_RX) {
507 lbs_deb_cs("rx packet\n");
508 skb = if_cs_receive_data(priv);
510 lbs_process_rxed_packet(priv, skb);
513 if (cause & IF_CS_BIT_TX) {
514 lbs_deb_cs("tx done\n");
515 lbs_host_to_card_done(priv);
518 if (cause & IF_CS_BIT_RESP) {
522 lbs_deb_cs("cmd resp\n");
523 spin_lock_irqsave(&priv->driver_lock, flags);
524 i = (priv->resp_idx == 0) ? 1 : 0;
525 spin_unlock_irqrestore(&priv->driver_lock, flags);
527 BUG_ON(priv->resp_len[i]);
528 if_cs_receive_cmdres(priv, priv->resp_buf[i],
531 spin_lock_irqsave(&priv->driver_lock, flags);
532 lbs_notify_command_response(priv, i);
533 spin_unlock_irqrestore(&priv->driver_lock, flags);
536 if (cause & IF_CS_BIT_EVENT) {
537 u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
538 if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE,
540 lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8);
543 /* Clear interrupt cause */
544 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK);
546 lbs_deb_leave(LBS_DEB_CS);
553 /********************************************************************/
555 /********************************************************************/
558 * Tries to program the helper firmware.
560 * Return 0 on success
562 static int if_cs_prog_helper(struct if_cs_card *card)
567 const struct firmware *fw;
569 lbs_deb_enter(LBS_DEB_CS);
572 * This is the only place where an unaligned register access happens on
573 * the CF8305 card, therefore for the sake of speed of the driver, we do
574 * the alignment correction here.
576 if (card->align_regs)
577 scratch = if_cs_read16(card, IF_CS_SCRATCH) >> 8;
579 scratch = if_cs_read8(card, IF_CS_SCRATCH);
581 /* "If the value is 0x5a, the firmware is already
582 * downloaded successfully"
584 if (scratch == IF_CS_SCRATCH_HELPER_OK)
587 /* "If the value is != 00, it is invalid value of register */
588 if (scratch != IF_CS_SCRATCH_BOOT_OK) {
593 /* TODO: make firmware file configurable */
594 ret = request_firmware(&fw, "libertas_cs_helper.fw",
597 lbs_pr_err("can't load helper firmware\n");
601 lbs_deb_cs("helper size %td\n", fw->size);
603 /* "Set the 5 bytes of the helper image to 0" */
604 /* Not needed, this contains an ARM branch instruction */
607 /* "the number of bytes to send is 256" */
609 int remain = fw->size - sent;
614 /* "write the number of bytes to be sent to the I/O Command
615 * write length register" */
616 if_cs_write16(card, IF_CS_CMD_LEN, count);
618 /* "write this to I/O Command port register as 16 bit writes */
620 if_cs_write16_rep(card, IF_CS_CMD,
624 /* "Assert the download over interrupt command in the Host
625 * status register" */
626 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
628 /* "Assert the download over interrupt command in the Card
629 * interrupt case register" */
630 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
632 /* "The host polls the Card Status register ... for 50 ms before
633 declaring a failure */
634 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
637 lbs_pr_err("can't download helper at 0x%x, ret %d\n",
649 release_firmware(fw);
651 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
656 static int if_cs_prog_real(struct if_cs_card *card)
658 const struct firmware *fw;
664 lbs_deb_enter(LBS_DEB_CS);
666 /* TODO: make firmware file configurable */
667 ret = request_firmware(&fw, "libertas_cs.fw",
670 lbs_pr_err("can't load firmware\n");
674 lbs_deb_cs("fw size %td\n", fw->size);
676 ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW,
679 lbs_pr_err("helper firmware doesn't answer\n");
683 for (sent = 0; sent < fw->size; sent += len) {
684 len = if_cs_read16(card, IF_CS_SQ_READ_LOW);
687 lbs_pr_info("odd, need to retry this firmware block\n");
693 lbs_pr_err("could not download firmware\n");
702 if_cs_write16(card, IF_CS_CMD_LEN, len);
704 if_cs_write16_rep(card, IF_CS_CMD,
707 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
708 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
710 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
713 lbs_pr_err("can't download firmware at 0x%x\n", sent);
718 ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a);
720 lbs_pr_err("firmware download failed\n");
723 release_firmware(fw);
726 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
732 /********************************************************************/
733 /* Callback functions for libertas.ko */
734 /********************************************************************/
736 /* Send commands or data packets to the card */
737 static int if_cs_host_to_card(struct lbs_private *priv,
744 lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb);
748 priv->dnld_sent = DNLD_DATA_SENT;
749 if_cs_send_data(priv, buf, nb);
753 priv->dnld_sent = DNLD_CMD_SENT;
754 ret = if_cs_send_cmd(priv, buf, nb);
757 lbs_pr_err("%s: unsupported type %d\n", __func__, type);
760 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
765 /********************************************************************/
767 /********************************************************************/
770 * After a card is removed, if_cs_release() will unregister the
771 * device, and release the PCMCIA configuration. If the device is
772 * still open, this will be postponed until it is closed.
774 static void if_cs_release(struct pcmcia_device *p_dev)
776 struct if_cs_card *card = p_dev->priv;
778 lbs_deb_enter(LBS_DEB_CS);
780 free_irq(p_dev->irq, card);
781 pcmcia_disable_device(p_dev);
783 ioport_unmap(card->iobase);
785 lbs_deb_leave(LBS_DEB_CS);
790 * This creates an "instance" of the driver, allocating local data
791 * structures for one device. The device is registered with Card
794 * The dev_link structure is initialized, but we don't actually
795 * configure the card at this point -- we wait until we receive a card
799 static int if_cs_ioprobe(struct pcmcia_device *p_dev,
800 cistpl_cftable_entry_t *cfg,
801 cistpl_cftable_entry_t *dflt,
805 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
806 p_dev->io.BasePort1 = cfg->io.win[0].base;
807 p_dev->io.NumPorts1 = cfg->io.win[0].len;
809 /* Do we need to allocate an interrupt? */
810 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
812 /* IO window settings */
813 if (cfg->io.nwin != 1) {
814 lbs_pr_err("wrong CIS (check number of IO windows)\n");
818 /* This reserves IO space but doesn't actually enable it */
819 return pcmcia_request_io(p_dev, &p_dev->io);
822 static int if_cs_probe(struct pcmcia_device *p_dev)
825 unsigned int prod_id;
826 struct lbs_private *priv;
827 struct if_cs_card *card;
829 lbs_deb_enter(LBS_DEB_CS);
831 card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL);
833 lbs_pr_err("error in kzalloc\n");
839 p_dev->conf.Attributes = 0;
840 p_dev->conf.IntType = INT_MEMORY_AND_IO;
842 if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) {
843 lbs_pr_err("error in pcmcia_loop_config\n");
849 * Allocate an interrupt line. Note that this does not assign
850 * a handler to the interrupt, unless the 'Handler' member of
851 * the irq structure is initialized.
856 /* Initialize io access */
857 card->iobase = ioport_map(p_dev->io.BasePort1, p_dev->io.NumPorts1);
859 lbs_pr_err("error in ioport_map\n");
865 * This actually configures the PCMCIA socket -- setting up
866 * the I/O windows and the interrupt mapping, and putting the
867 * card and host interface into "Memory and IO" mode.
869 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
871 lbs_pr_err("error in pcmcia_request_configuration\n");
875 /* Finally, report what we've done */
876 lbs_deb_cs("irq %d, io 0x%04x-0x%04x\n",
877 p_dev->irq, p_dev->io.BasePort1,
878 p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1);
881 * Most of the libertas cards can do unaligned register access, but some
882 * weird ones can not. That's especially true for the CF8305 card.
884 card->align_regs = 0;
886 /* Check if we have a current silicon */
887 prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID);
888 if (if_cs_hw_is_cf8305(p_dev)) {
889 card->align_regs = 1;
890 if (prod_id < IF_CS_CF8305_B1_REV) {
891 lbs_pr_err("old chips like 8305 rev B3 "
892 "aren't supported\n");
898 if (if_cs_hw_is_cf8381(p_dev) && prod_id < IF_CS_CF8381_B3_REV) {
899 lbs_pr_err("old chips like 8381 rev B3 aren't supported\n");
904 if (if_cs_hw_is_cf8385(p_dev) && prod_id < IF_CS_CF8385_B1_REV) {
905 lbs_pr_err("old chips like 8385 rev B1 aren't supported\n");
910 /* Load the firmware early, before calling into libertas.ko */
911 ret = if_cs_prog_helper(card);
912 if (ret == 0 && !if_cs_hw_is_cf8305(p_dev))
913 ret = if_cs_prog_real(card);
917 /* Make this card known to the libertas driver */
918 priv = lbs_add_card(card, &p_dev->dev);
924 /* Finish setting up fields in lbs_private */
927 priv->hw_host_to_card = if_cs_host_to_card;
928 priv->enter_deep_sleep = NULL;
929 priv->exit_deep_sleep = NULL;
930 priv->reset_deep_sleep_wakeup = NULL;
933 /* Now actually get the IRQ */
934 ret = request_irq(p_dev->irq, if_cs_interrupt,
935 IRQF_SHARED, DRV_NAME, card);
937 lbs_pr_err("error in request_irq\n");
941 /* Clear any interrupt cause that happend while sending
942 * firmware/initializing card */
943 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK);
944 if_cs_enable_ints(card);
946 /* And finally bring the card up */
947 if (lbs_start_card(priv) != 0) {
948 lbs_pr_err("could not activate card\n");
956 lbs_remove_card(priv);
958 ioport_unmap(card->iobase);
960 pcmcia_disable_device(p_dev);
962 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
968 * This deletes a driver "instance". The device is de-registered with
969 * Card Services. If it has been released, all local data structures
970 * are freed. Otherwise, the structures will be freed when the device
973 static void if_cs_detach(struct pcmcia_device *p_dev)
975 struct if_cs_card *card = p_dev->priv;
977 lbs_deb_enter(LBS_DEB_CS);
979 lbs_stop_card(card->priv);
980 lbs_remove_card(card->priv);
981 if_cs_disable_ints(card);
982 if_cs_release(p_dev);
985 lbs_deb_leave(LBS_DEB_CS);
990 /********************************************************************/
991 /* Module initialization */
992 /********************************************************************/
994 static struct pcmcia_device_id if_cs_ids[] = {
995 PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID),
996 PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID),
997 PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID),
1000 MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
1003 static struct pcmcia_driver lbs_driver = {
1004 .owner = THIS_MODULE,
1008 .probe = if_cs_probe,
1009 .remove = if_cs_detach,
1010 .id_table = if_cs_ids,
1014 static int __init if_cs_init(void)
1018 lbs_deb_enter(LBS_DEB_CS);
1019 ret = pcmcia_register_driver(&lbs_driver);
1020 lbs_deb_leave(LBS_DEB_CS);
1025 static void __exit if_cs_exit(void)
1027 lbs_deb_enter(LBS_DEB_CS);
1028 pcmcia_unregister_driver(&lbs_driver);
1029 lbs_deb_leave(LBS_DEB_CS);
1033 module_init(if_cs_init);
1034 module_exit(if_cs_exit);