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.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;
74 static const struct lbs_fw_table fw_table[] = {
75 { MODEL_8305, "libertas/cf8305.bin", NULL },
76 { MODEL_8305, "libertas_cs_helper.fw", NULL },
77 { MODEL_8381, "libertas/cf8381_helper.bin", "libertas/cf8381.bin" },
78 { MODEL_8381, "libertas_cs_helper.fw", "libertas_cs.fw" },
79 { MODEL_8385, "libertas/cf8385_helper.bin", "libertas/cf8385.bin" },
80 { MODEL_8385, "libertas_cs_helper.fw", "libertas_cs.fw" },
83 MODULE_FIRMWARE("libertas/cf8305.bin");
84 MODULE_FIRMWARE("libertas/cf8381_helper.bin");
85 MODULE_FIRMWARE("libertas/cf8381.bin");
86 MODULE_FIRMWARE("libertas/cf8385_helper.bin");
87 MODULE_FIRMWARE("libertas/cf8385.bin");
88 MODULE_FIRMWARE("libertas_cs_helper.fw");
89 MODULE_FIRMWARE("libertas_cs.fw");
92 /********************************************************************/
94 /********************************************************************/
96 /* This define enables wrapper functions which allow you
97 to dump all register accesses. You normally won't this,
98 except for development */
99 /* #define DEBUG_IO */
102 static int debug_output = 0;
104 /* This way the compiler optimizes the printk's away */
105 #define debug_output 0
108 static inline unsigned int if_cs_read8(struct if_cs_card *card, uint reg)
110 unsigned int val = ioread8(card->iobase + reg);
112 printk(KERN_INFO "inb %08x<%02x\n", reg, val);
115 static inline unsigned int if_cs_read16(struct if_cs_card *card, uint reg)
117 unsigned int val = ioread16(card->iobase + reg);
119 printk(KERN_INFO "inw %08x<%04x\n", reg, val);
122 static inline void if_cs_read16_rep(
123 struct if_cs_card *card,
129 printk(KERN_INFO "insw %08x<(0x%lx words)\n",
131 ioread16_rep(card->iobase + reg, buf, count);
134 static inline void if_cs_write8(struct if_cs_card *card, uint reg, u8 val)
137 printk(KERN_INFO "outb %08x>%02x\n", reg, val);
138 iowrite8(val, card->iobase + reg);
141 static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val)
144 printk(KERN_INFO "outw %08x>%04x\n", reg, val);
145 iowrite16(val, card->iobase + reg);
148 static inline void if_cs_write16_rep(
149 struct if_cs_card *card,
155 printk(KERN_INFO "outsw %08x>(0x%lx words)\n",
157 iowrite16_rep(card->iobase + reg, buf, count);
162 * I know that polling/delaying is frowned upon. However, this procedure
163 * with polling is needed while downloading the firmware. At this stage,
164 * the hardware does unfortunately not create any interrupts.
166 * Fortunately, this function is never used once the firmware is in
169 * As a reference, see the "Firmware Specification v5.1", page 18
170 * and 19. I did not follow their suggested timing to the word,
171 * but this works nice & fast anyway.
173 static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 reg)
177 for (i = 0; i < 100000; i++) {
178 u8 val = if_cs_read8(card, addr);
189 * First the bitmasks for the host/card interrupt/status registers:
191 #define IF_CS_BIT_TX 0x0001
192 #define IF_CS_BIT_RX 0x0002
193 #define IF_CS_BIT_COMMAND 0x0004
194 #define IF_CS_BIT_RESP 0x0008
195 #define IF_CS_BIT_EVENT 0x0010
196 #define IF_CS_BIT_MASK 0x001f
201 * It's not really clear to me what the host status register is for. It
202 * needs to be set almost in union with "host int cause". The following
203 * bits from above are used:
205 * IF_CS_BIT_TX driver downloaded a data packet
206 * IF_CS_BIT_RX driver got a data packet
207 * IF_CS_BIT_COMMAND driver downloaded a command
208 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
209 * IF_CS_BIT_EVENT driver read a host event
211 #define IF_CS_HOST_STATUS 0x00000000
214 * With the host int cause register can the host (that is, Linux) cause
215 * an interrupt in the firmware, to tell the firmware about those events:
217 * IF_CS_BIT_TX a data packet has been downloaded
218 * IF_CS_BIT_RX a received data packet has retrieved
219 * IF_CS_BIT_COMMAND a firmware block or a command has been downloaded
220 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
221 * IF_CS_BIT_EVENT a host event (link lost etc) has been retrieved
223 #define IF_CS_HOST_INT_CAUSE 0x00000002
226 * The host int mask register is used to enable/disable interrupt. However,
227 * I have the suspicion that disabled interrupts are lost.
229 #define IF_CS_HOST_INT_MASK 0x00000004
232 * Used to send or receive data packets:
234 #define IF_CS_WRITE 0x00000016
235 #define IF_CS_WRITE_LEN 0x00000014
236 #define IF_CS_READ 0x00000010
237 #define IF_CS_READ_LEN 0x00000024
240 * Used to send commands (and to send firmware block) and to
241 * receive command responses:
243 #define IF_CS_CMD 0x0000001A
244 #define IF_CS_CMD_LEN 0x00000018
245 #define IF_CS_RESP 0x00000012
246 #define IF_CS_RESP_LEN 0x00000030
249 * The card status registers shows what the card/firmware actually
252 * IF_CS_BIT_TX you may send a data packet
253 * IF_CS_BIT_RX you may retrieve a data packet
254 * IF_CS_BIT_COMMAND you may send a command
255 * IF_CS_BIT_RESP you may retrieve a command response
256 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
258 * When reading this register several times, you will get back the same
259 * results --- with one exception: the IF_CS_BIT_EVENT clear itself
262 * Not that we don't rely on BIT_RX,_BIT_RESP or BIT_EVENT because
263 * we handle this via the card int cause register.
265 #define IF_CS_CARD_STATUS 0x00000020
266 #define IF_CS_CARD_STATUS_MASK 0x7f00
269 * The card int cause register is used by the card/firmware to notify us
270 * about the following events:
272 * IF_CS_BIT_TX a data packet has successfully been sentx
273 * IF_CS_BIT_RX a data packet has been received and can be retrieved
274 * IF_CS_BIT_COMMAND not used
275 * IF_CS_BIT_RESP the firmware has a command response for us
276 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
278 #define IF_CS_CARD_INT_CAUSE 0x00000022
281 * This is used to for handshaking with the card's bootloader/helper image
282 * to synchronize downloading of firmware blocks.
284 #define IF_CS_SQ_READ_LOW 0x00000028
285 #define IF_CS_SQ_HELPER_OK 0x10
288 * The scratch register tells us ...
290 * IF_CS_SCRATCH_BOOT_OK the bootloader runs
291 * IF_CS_SCRATCH_HELPER_OK the helper firmware already runs
293 #define IF_CS_SCRATCH 0x0000003F
294 #define IF_CS_SCRATCH_BOOT_OK 0x00
295 #define IF_CS_SCRATCH_HELPER_OK 0x5a
298 * Used to detect ancient chips:
300 #define IF_CS_PRODUCT_ID 0x0000001C
301 #define IF_CS_CF8385_B1_REV 0x12
302 #define IF_CS_CF8381_B3_REV 0x04
303 #define IF_CS_CF8305_B1_REV 0x03
306 * Used to detect other cards than CF8385 since their revisions of silicon
307 * doesn't match those from CF8385, eg. CF8381 B3 works with this driver.
309 #define CF8305_MANFID 0x02db
310 #define CF8305_CARDID 0x8103
311 #define CF8381_MANFID 0x02db
312 #define CF8381_CARDID 0x6064
313 #define CF8385_MANFID 0x02df
314 #define CF8385_CARDID 0x8103
316 /* FIXME: just use the 'driver_info' field of 'struct pcmcia_device_id' when
317 * that gets fixed. Currently there's no way to access it from the probe hook.
319 static inline u32 get_model(u16 manf_id, u16 card_id)
321 /* NOTE: keep in sync with if_cs_ids */
322 if (manf_id == CF8305_MANFID && card_id == CF8305_CARDID)
324 else if (manf_id == CF8381_MANFID && card_id == CF8381_CARDID)
326 else if (manf_id == CF8385_MANFID && card_id == CF8385_CARDID)
328 return MODEL_UNKNOWN;
331 /********************************************************************/
332 /* I/O and interrupt handling */
333 /********************************************************************/
335 static inline void if_cs_enable_ints(struct if_cs_card *card)
337 lbs_deb_enter(LBS_DEB_CS);
338 if_cs_write16(card, IF_CS_HOST_INT_MASK, 0);
341 static inline void if_cs_disable_ints(struct if_cs_card *card)
343 lbs_deb_enter(LBS_DEB_CS);
344 if_cs_write16(card, IF_CS_HOST_INT_MASK, IF_CS_BIT_MASK);
348 * Called from if_cs_host_to_card to send a command to the hardware
350 static int if_cs_send_cmd(struct lbs_private *priv, u8 *buf, u16 nb)
352 struct if_cs_card *card = (struct if_cs_card *)priv->card;
356 lbs_deb_enter(LBS_DEB_CS);
357 if_cs_disable_ints(card);
359 /* Is hardware ready? */
361 u16 status = if_cs_read16(card, IF_CS_CARD_STATUS);
362 if (status & IF_CS_BIT_COMMAND)
365 lbs_pr_err("card not ready for commands\n");
371 if_cs_write16(card, IF_CS_CMD_LEN, nb);
373 if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2);
374 /* Are we supposed to transfer an odd amount of bytes? */
376 if_cs_write8(card, IF_CS_CMD, buf[nb-1]);
378 /* "Assert the download over interrupt command in the Host
379 * status register" */
380 if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
382 /* "Assert the download over interrupt command in the Card
383 * interrupt case register" */
384 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
388 if_cs_enable_ints(card);
389 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
394 * Called from if_cs_host_to_card to send a data to the hardware
396 static void if_cs_send_data(struct lbs_private *priv, u8 *buf, u16 nb)
398 struct if_cs_card *card = (struct if_cs_card *)priv->card;
401 lbs_deb_enter(LBS_DEB_CS);
402 if_cs_disable_ints(card);
404 status = if_cs_read16(card, IF_CS_CARD_STATUS);
405 BUG_ON((status & IF_CS_BIT_TX) == 0);
407 if_cs_write16(card, IF_CS_WRITE_LEN, nb);
409 /* write even number of bytes, then odd byte if necessary */
410 if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2);
412 if_cs_write8(card, IF_CS_WRITE, buf[nb-1]);
414 if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_TX);
415 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_TX);
416 if_cs_enable_ints(card);
418 lbs_deb_leave(LBS_DEB_CS);
422 * Get the command result out of the card.
424 static int if_cs_receive_cmdres(struct lbs_private *priv, u8 *data, u32 *len)
430 lbs_deb_enter(LBS_DEB_CS);
432 /* is hardware ready? */
433 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
434 if ((status & IF_CS_BIT_RESP) == 0) {
435 lbs_pr_err("no cmd response in card\n");
440 *len = if_cs_read16(priv->card, IF_CS_RESP_LEN);
441 if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) {
442 lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len);
446 /* read even number of bytes, then odd byte if necessary */
447 if_cs_read16_rep(priv->card, IF_CS_RESP, data, *len/sizeof(u16));
449 data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP);
451 /* This is a workaround for a firmware that reports too much
456 /* Clear this flag again */
457 spin_lock_irqsave(&priv->driver_lock, flags);
458 priv->dnld_sent = DNLD_RES_RECEIVED;
459 spin_unlock_irqrestore(&priv->driver_lock, flags);
462 lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len);
466 static struct sk_buff *if_cs_receive_data(struct lbs_private *priv)
468 struct sk_buff *skb = NULL;
472 lbs_deb_enter(LBS_DEB_CS);
474 len = if_cs_read16(priv->card, IF_CS_READ_LEN);
475 if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
476 lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len);
477 priv->dev->stats.rx_dropped++;
481 skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
485 skb_reserve(skb, 2);/* 16 byte align */
488 /* read even number of bytes, then odd byte if necessary */
489 if_cs_read16_rep(priv->card, IF_CS_READ, data, len/sizeof(u16));
491 data[len-1] = if_cs_read8(priv->card, IF_CS_READ);
494 if_cs_write16(priv->card, IF_CS_HOST_STATUS, IF_CS_BIT_RX);
495 if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_RX);
498 lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb);
502 static irqreturn_t if_cs_interrupt(int irq, void *data)
504 struct if_cs_card *card = data;
505 struct lbs_private *priv = card->priv;
508 lbs_deb_enter(LBS_DEB_CS);
510 /* Ask card interrupt cause register if there is something for us */
511 cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE);
512 lbs_deb_cs("cause 0x%04x\n", cause);
519 if (cause == 0xffff) {
520 /* Read in junk, the card has probably been removed */
521 card->priv->surpriseremoved = 1;
525 if (cause & IF_CS_BIT_RX) {
527 lbs_deb_cs("rx packet\n");
528 skb = if_cs_receive_data(priv);
530 lbs_process_rxed_packet(priv, skb);
533 if (cause & IF_CS_BIT_TX) {
534 lbs_deb_cs("tx done\n");
535 lbs_host_to_card_done(priv);
538 if (cause & IF_CS_BIT_RESP) {
542 lbs_deb_cs("cmd resp\n");
543 spin_lock_irqsave(&priv->driver_lock, flags);
544 i = (priv->resp_idx == 0) ? 1 : 0;
545 spin_unlock_irqrestore(&priv->driver_lock, flags);
547 BUG_ON(priv->resp_len[i]);
548 if_cs_receive_cmdres(priv, priv->resp_buf[i],
551 spin_lock_irqsave(&priv->driver_lock, flags);
552 lbs_notify_command_response(priv, i);
553 spin_unlock_irqrestore(&priv->driver_lock, flags);
556 if (cause & IF_CS_BIT_EVENT) {
557 u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
558 if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE,
560 lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8);
563 /* Clear interrupt cause */
564 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK);
566 lbs_deb_leave(LBS_DEB_CS);
573 /********************************************************************/
575 /********************************************************************/
578 * Tries to program the helper firmware.
580 * Return 0 on success
582 static int if_cs_prog_helper(struct if_cs_card *card, const struct firmware *fw)
588 lbs_deb_enter(LBS_DEB_CS);
591 * This is the only place where an unaligned register access happens on
592 * the CF8305 card, therefore for the sake of speed of the driver, we do
593 * the alignment correction here.
595 if (card->align_regs)
596 scratch = if_cs_read16(card, IF_CS_SCRATCH) >> 8;
598 scratch = if_cs_read8(card, IF_CS_SCRATCH);
600 /* "If the value is 0x5a, the firmware is already
601 * downloaded successfully"
603 if (scratch == IF_CS_SCRATCH_HELPER_OK)
606 /* "If the value is != 00, it is invalid value of register */
607 if (scratch != IF_CS_SCRATCH_BOOT_OK) {
612 lbs_deb_cs("helper size %td\n", fw->size);
614 /* "Set the 5 bytes of the helper image to 0" */
615 /* Not needed, this contains an ARM branch instruction */
618 /* "the number of bytes to send is 256" */
620 int remain = fw->size - sent;
625 /* "write the number of bytes to be sent to the I/O Command
626 * write length register" */
627 if_cs_write16(card, IF_CS_CMD_LEN, count);
629 /* "write this to I/O Command port register as 16 bit writes */
631 if_cs_write16_rep(card, IF_CS_CMD,
635 /* "Assert the download over interrupt command in the Host
636 * status register" */
637 if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
639 /* "Assert the download over interrupt command in the Card
640 * interrupt case register" */
641 if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
643 /* "The host polls the Card Status register ... for 50 ms before
644 declaring a failure */
645 ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
648 lbs_pr_err("can't download helper at 0x%x, ret %d\n",
660 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
665 static int if_cs_prog_real(struct if_cs_card *card, const struct firmware *fw)
672 lbs_deb_enter(LBS_DEB_CS);
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 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
729 /********************************************************************/
730 /* Callback functions for libertas.ko */
731 /********************************************************************/
733 /* Send commands or data packets to the card */
734 static int if_cs_host_to_card(struct lbs_private *priv,
741 lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb);
745 priv->dnld_sent = DNLD_DATA_SENT;
746 if_cs_send_data(priv, buf, nb);
750 priv->dnld_sent = DNLD_CMD_SENT;
751 ret = if_cs_send_cmd(priv, buf, nb);
754 lbs_pr_err("%s: unsupported type %d\n", __func__, type);
757 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
762 /********************************************************************/
764 /********************************************************************/
767 * After a card is removed, if_cs_release() will unregister the
768 * device, and release the PCMCIA configuration. If the device is
769 * still open, this will be postponed until it is closed.
771 static void if_cs_release(struct pcmcia_device *p_dev)
773 struct if_cs_card *card = p_dev->priv;
775 lbs_deb_enter(LBS_DEB_CS);
777 free_irq(p_dev->irq, card);
778 pcmcia_disable_device(p_dev);
780 ioport_unmap(card->iobase);
782 lbs_deb_leave(LBS_DEB_CS);
787 * This creates an "instance" of the driver, allocating local data
788 * structures for one device. The device is registered with Card
791 * The dev_link structure is initialized, but we don't actually
792 * configure the card at this point -- we wait until we receive a card
796 static int if_cs_ioprobe(struct pcmcia_device *p_dev,
797 cistpl_cftable_entry_t *cfg,
798 cistpl_cftable_entry_t *dflt,
802 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
803 p_dev->resource[0]->start = cfg->io.win[0].base;
804 p_dev->resource[0]->end = cfg->io.win[0].len;
806 /* Do we need to allocate an interrupt? */
807 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
809 /* IO window settings */
810 if (cfg->io.nwin != 1) {
811 lbs_pr_err("wrong CIS (check number of IO windows)\n");
815 /* This reserves IO space but doesn't actually enable it */
816 return pcmcia_request_io(p_dev);
819 static int if_cs_probe(struct pcmcia_device *p_dev)
822 unsigned int prod_id;
823 struct lbs_private *priv;
824 struct if_cs_card *card;
825 const struct firmware *helper = NULL;
826 const struct firmware *mainfw = NULL;
828 lbs_deb_enter(LBS_DEB_CS);
830 card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL);
832 lbs_pr_err("error in kzalloc\n");
838 p_dev->conf.Attributes = 0;
839 p_dev->conf.IntType = INT_MEMORY_AND_IO;
841 if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) {
842 lbs_pr_err("error in pcmcia_loop_config\n");
847 * Allocate an interrupt line. Note that this does not assign
848 * a handler to the interrupt, unless the 'Handler' member of
849 * the irq structure is initialized.
854 /* Initialize io access */
855 card->iobase = ioport_map(p_dev->resource[0]->start,
856 resource_size(p_dev->resource[0]));
858 lbs_pr_err("error in ioport_map\n");
864 * This actually configures the PCMCIA socket -- setting up
865 * the I/O windows and the interrupt mapping, and putting the
866 * card and host interface into "Memory and IO" mode.
868 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
870 lbs_pr_err("error in pcmcia_request_configuration\n");
874 /* Finally, report what we've done */
875 lbs_deb_cs("irq %d, io %pR", p_dev->irq, p_dev->resource[0]);
878 * Most of the libertas cards can do unaligned register access, but some
879 * weird ones can not. That's especially true for the CF8305 card.
881 card->align_regs = 0;
883 card->model = get_model(p_dev->manf_id, p_dev->card_id);
884 if (card->model == MODEL_UNKNOWN) {
885 lbs_pr_err("unsupported manf_id 0x%04x / card_id 0x%04x\n",
886 p_dev->manf_id, p_dev->card_id);
890 /* Check if we have a current silicon */
891 prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID);
892 if (card->model == MODEL_8305) {
893 card->align_regs = 1;
894 if (prod_id < IF_CS_CF8305_B1_REV) {
895 lbs_pr_err("8305 rev B0 and older are not supported\n");
901 if ((card->model == MODEL_8381) && prod_id < IF_CS_CF8381_B3_REV) {
902 lbs_pr_err("8381 rev B2 and older are not supported\n");
907 if ((card->model == MODEL_8385) && prod_id < IF_CS_CF8385_B1_REV) {
908 lbs_pr_err("8385 rev B0 and older are not supported\n");
913 ret = lbs_get_firmware(&p_dev->dev, NULL, NULL, card->model,
914 &fw_table[0], &helper, &mainfw);
916 lbs_pr_err("failed to find firmware (%d)\n", ret);
920 /* Load the firmware early, before calling into libertas.ko */
921 ret = if_cs_prog_helper(card, helper);
922 if (ret == 0 && (card->model != MODEL_8305))
923 ret = if_cs_prog_real(card, mainfw);
927 /* Make this card known to the libertas driver */
928 priv = lbs_add_card(card, &p_dev->dev);
934 /* Finish setting up fields in lbs_private */
937 priv->hw_host_to_card = if_cs_host_to_card;
938 priv->enter_deep_sleep = NULL;
939 priv->exit_deep_sleep = NULL;
940 priv->reset_deep_sleep_wakeup = NULL;
943 /* Now actually get the IRQ */
944 ret = request_irq(p_dev->irq, if_cs_interrupt,
945 IRQF_SHARED, DRV_NAME, card);
947 lbs_pr_err("error in request_irq\n");
951 /* Clear any interrupt cause that happend while sending
952 * firmware/initializing card */
953 if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK);
954 if_cs_enable_ints(card);
956 /* And finally bring the card up */
957 if (lbs_start_card(priv) != 0) {
958 lbs_pr_err("could not activate card\n");
966 lbs_remove_card(priv);
968 ioport_unmap(card->iobase);
970 pcmcia_disable_device(p_dev);
973 release_firmware(helper);
975 release_firmware(mainfw);
977 lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
983 * This deletes a driver "instance". The device is de-registered with
984 * Card Services. If it has been released, all local data structures
985 * are freed. Otherwise, the structures will be freed when the device
988 static void if_cs_detach(struct pcmcia_device *p_dev)
990 struct if_cs_card *card = p_dev->priv;
992 lbs_deb_enter(LBS_DEB_CS);
994 lbs_stop_card(card->priv);
995 lbs_remove_card(card->priv);
996 if_cs_disable_ints(card);
997 if_cs_release(p_dev);
1000 lbs_deb_leave(LBS_DEB_CS);
1005 /********************************************************************/
1006 /* Module initialization */
1007 /********************************************************************/
1009 static struct pcmcia_device_id if_cs_ids[] = {
1010 PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID),
1011 PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID),
1012 PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID),
1013 /* NOTE: keep in sync with get_model() */
1016 MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
1019 static struct pcmcia_driver lbs_driver = {
1020 .owner = THIS_MODULE,
1024 .probe = if_cs_probe,
1025 .remove = if_cs_detach,
1026 .id_table = if_cs_ids,
1030 static int __init if_cs_init(void)
1034 lbs_deb_enter(LBS_DEB_CS);
1035 ret = pcmcia_register_driver(&lbs_driver);
1036 lbs_deb_leave(LBS_DEB_CS);
1041 static void __exit if_cs_exit(void)
1043 lbs_deb_enter(LBS_DEB_CS);
1044 pcmcia_unregister_driver(&lbs_driver);
1045 lbs_deb_leave(LBS_DEB_CS);
1049 module_init(if_cs_init);
1050 module_exit(if_cs_exit);