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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/delay.h>
29 #include <linux/moduleparam.h>
30 #include <linux/firmware.h>
31 #include <linux/netdevice.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");
55 /********************************************************************/
57 /********************************************************************/
60 struct pcmcia_device
*p_dev
;
61 struct lbs_private
*priv
;
75 static const struct lbs_fw_table fw_table
[] = {
76 { MODEL_8305
, "libertas/cf8305.bin", NULL
},
77 { MODEL_8305
, "libertas_cs_helper.fw", NULL
},
78 { MODEL_8381
, "libertas/cf8381_helper.bin", "libertas/cf8381.bin" },
79 { MODEL_8381
, "libertas_cs_helper.fw", "libertas_cs.fw" },
80 { MODEL_8385
, "libertas/cf8385_helper.bin", "libertas/cf8385.bin" },
81 { MODEL_8385
, "libertas_cs_helper.fw", "libertas_cs.fw" },
84 MODULE_FIRMWARE("libertas/cf8305.bin");
85 MODULE_FIRMWARE("libertas/cf8381_helper.bin");
86 MODULE_FIRMWARE("libertas/cf8381.bin");
87 MODULE_FIRMWARE("libertas/cf8385_helper.bin");
88 MODULE_FIRMWARE("libertas/cf8385.bin");
89 MODULE_FIRMWARE("libertas_cs_helper.fw");
90 MODULE_FIRMWARE("libertas_cs.fw");
93 /********************************************************************/
95 /********************************************************************/
97 /* This define enables wrapper functions which allow you
98 to dump all register accesses. You normally won't this,
99 except for development */
100 /* #define DEBUG_IO */
103 static int debug_output
= 0;
105 /* This way the compiler optimizes the printk's away */
106 #define debug_output 0
109 static inline unsigned int if_cs_read8(struct if_cs_card
*card
, uint reg
)
111 unsigned int val
= ioread8(card
->iobase
+ reg
);
113 printk(KERN_INFO
"inb %08x<%02x\n", reg
, val
);
116 static inline unsigned int if_cs_read16(struct if_cs_card
*card
, uint reg
)
118 unsigned int val
= ioread16(card
->iobase
+ reg
);
120 printk(KERN_INFO
"inw %08x<%04x\n", reg
, val
);
123 static inline void if_cs_read16_rep(
124 struct if_cs_card
*card
,
130 printk(KERN_INFO
"insw %08x<(0x%lx words)\n",
132 ioread16_rep(card
->iobase
+ reg
, buf
, count
);
135 static inline void if_cs_write8(struct if_cs_card
*card
, uint reg
, u8 val
)
138 printk(KERN_INFO
"outb %08x>%02x\n", reg
, val
);
139 iowrite8(val
, card
->iobase
+ reg
);
142 static inline void if_cs_write16(struct if_cs_card
*card
, uint reg
, u16 val
)
145 printk(KERN_INFO
"outw %08x>%04x\n", reg
, val
);
146 iowrite16(val
, card
->iobase
+ reg
);
149 static inline void if_cs_write16_rep(
150 struct if_cs_card
*card
,
156 printk(KERN_INFO
"outsw %08x>(0x%lx words)\n",
158 iowrite16_rep(card
->iobase
+ reg
, buf
, count
);
163 * I know that polling/delaying is frowned upon. However, this procedure
164 * with polling is needed while downloading the firmware. At this stage,
165 * the hardware does unfortunately not create any interrupts.
167 * Fortunately, this function is never used once the firmware is in
170 * As a reference, see the "Firmware Specification v5.1", page 18
171 * and 19. I did not follow their suggested timing to the word,
172 * but this works nice & fast anyway.
174 static int if_cs_poll_while_fw_download(struct if_cs_card
*card
, uint addr
, u8 reg
)
178 for (i
= 0; i
< 100000; i
++) {
179 u8 val
= if_cs_read8(card
, addr
);
190 * First the bitmasks for the host/card interrupt/status registers:
192 #define IF_CS_BIT_TX 0x0001
193 #define IF_CS_BIT_RX 0x0002
194 #define IF_CS_BIT_COMMAND 0x0004
195 #define IF_CS_BIT_RESP 0x0008
196 #define IF_CS_BIT_EVENT 0x0010
197 #define IF_CS_BIT_MASK 0x001f
202 * It's not really clear to me what the host status register is for. It
203 * needs to be set almost in union with "host int cause". The following
204 * bits from above are used:
206 * IF_CS_BIT_TX driver downloaded a data packet
207 * IF_CS_BIT_RX driver got a data packet
208 * IF_CS_BIT_COMMAND driver downloaded a command
209 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
210 * IF_CS_BIT_EVENT driver read a host event
212 #define IF_CS_HOST_STATUS 0x00000000
215 * With the host int cause register can the host (that is, Linux) cause
216 * an interrupt in the firmware, to tell the firmware about those events:
218 * IF_CS_BIT_TX a data packet has been downloaded
219 * IF_CS_BIT_RX a received data packet has retrieved
220 * IF_CS_BIT_COMMAND a firmware block or a command has been downloaded
221 * IF_CS_BIT_RESP not used (has some meaning with powerdown)
222 * IF_CS_BIT_EVENT a host event (link lost etc) has been retrieved
224 #define IF_CS_HOST_INT_CAUSE 0x00000002
227 * The host int mask register is used to enable/disable interrupt. However,
228 * I have the suspicion that disabled interrupts are lost.
230 #define IF_CS_HOST_INT_MASK 0x00000004
233 * Used to send or receive data packets:
235 #define IF_CS_WRITE 0x00000016
236 #define IF_CS_WRITE_LEN 0x00000014
237 #define IF_CS_READ 0x00000010
238 #define IF_CS_READ_LEN 0x00000024
241 * Used to send commands (and to send firmware block) and to
242 * receive command responses:
244 #define IF_CS_CMD 0x0000001A
245 #define IF_CS_CMD_LEN 0x00000018
246 #define IF_CS_RESP 0x00000012
247 #define IF_CS_RESP_LEN 0x00000030
250 * The card status registers shows what the card/firmware actually
253 * IF_CS_BIT_TX you may send a data packet
254 * IF_CS_BIT_RX you may retrieve a data packet
255 * IF_CS_BIT_COMMAND you may send a command
256 * IF_CS_BIT_RESP you may retrieve a command response
257 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
259 * When reading this register several times, you will get back the same
260 * results --- with one exception: the IF_CS_BIT_EVENT clear itself
263 * Not that we don't rely on BIT_RX,_BIT_RESP or BIT_EVENT because
264 * we handle this via the card int cause register.
266 #define IF_CS_CARD_STATUS 0x00000020
267 #define IF_CS_CARD_STATUS_MASK 0x7f00
270 * The card int cause register is used by the card/firmware to notify us
271 * about the following events:
273 * IF_CS_BIT_TX a data packet has successfully been sentx
274 * IF_CS_BIT_RX a data packet has been received and can be retrieved
275 * IF_CS_BIT_COMMAND not used
276 * IF_CS_BIT_RESP the firmware has a command response for us
277 * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
279 #define IF_CS_CARD_INT_CAUSE 0x00000022
282 * This is used to for handshaking with the card's bootloader/helper image
283 * to synchronize downloading of firmware blocks.
285 #define IF_CS_SQ_READ_LOW 0x00000028
286 #define IF_CS_SQ_HELPER_OK 0x10
289 * The scratch register tells us ...
291 * IF_CS_SCRATCH_BOOT_OK the bootloader runs
292 * IF_CS_SCRATCH_HELPER_OK the helper firmware already runs
294 #define IF_CS_SCRATCH 0x0000003F
295 #define IF_CS_SCRATCH_BOOT_OK 0x00
296 #define IF_CS_SCRATCH_HELPER_OK 0x5a
299 * Used to detect ancient chips:
301 #define IF_CS_PRODUCT_ID 0x0000001C
302 #define IF_CS_CF8385_B1_REV 0x12
303 #define IF_CS_CF8381_B3_REV 0x04
304 #define IF_CS_CF8305_B1_REV 0x03
307 * Used to detect other cards than CF8385 since their revisions of silicon
308 * doesn't match those from CF8385, eg. CF8381 B3 works with this driver.
310 #define CF8305_MANFID 0x02db
311 #define CF8305_CARDID 0x8103
312 #define CF8381_MANFID 0x02db
313 #define CF8381_CARDID 0x6064
314 #define CF8385_MANFID 0x02df
315 #define CF8385_CARDID 0x8103
318 * FIXME: just use the 'driver_info' field of 'struct pcmcia_device_id' when
319 * that gets fixed. Currently there's no way to access it from the probe hook.
321 static inline u32
get_model(u16 manf_id
, u16 card_id
)
323 /* NOTE: keep in sync with if_cs_ids */
324 if (manf_id
== CF8305_MANFID
&& card_id
== CF8305_CARDID
)
326 else if (manf_id
== CF8381_MANFID
&& card_id
== CF8381_CARDID
)
328 else if (manf_id
== CF8385_MANFID
&& card_id
== CF8385_CARDID
)
330 return MODEL_UNKNOWN
;
333 /********************************************************************/
334 /* I/O and interrupt handling */
335 /********************************************************************/
337 static inline void if_cs_enable_ints(struct if_cs_card
*card
)
339 lbs_deb_enter(LBS_DEB_CS
);
340 if_cs_write16(card
, IF_CS_HOST_INT_MASK
, 0);
343 static inline void if_cs_disable_ints(struct if_cs_card
*card
)
345 lbs_deb_enter(LBS_DEB_CS
);
346 if_cs_write16(card
, IF_CS_HOST_INT_MASK
, IF_CS_BIT_MASK
);
350 * Called from if_cs_host_to_card to send a command to the hardware
352 static int if_cs_send_cmd(struct lbs_private
*priv
, u8
*buf
, u16 nb
)
354 struct if_cs_card
*card
= (struct if_cs_card
*)priv
->card
;
358 lbs_deb_enter(LBS_DEB_CS
);
359 if_cs_disable_ints(card
);
361 /* Is hardware ready? */
363 u16 status
= if_cs_read16(card
, IF_CS_CARD_STATUS
);
364 if (status
& IF_CS_BIT_COMMAND
)
367 netdev_err(priv
->dev
, "card not ready for commands\n");
373 if_cs_write16(card
, IF_CS_CMD_LEN
, nb
);
375 if_cs_write16_rep(card
, IF_CS_CMD
, buf
, nb
/ 2);
376 /* Are we supposed to transfer an odd amount of bytes? */
378 if_cs_write8(card
, IF_CS_CMD
, buf
[nb
-1]);
380 /* "Assert the download over interrupt command in the Host
381 * status register" */
382 if_cs_write16(card
, IF_CS_HOST_STATUS
, IF_CS_BIT_COMMAND
);
384 /* "Assert the download over interrupt command in the Card
385 * interrupt case register" */
386 if_cs_write16(card
, IF_CS_HOST_INT_CAUSE
, IF_CS_BIT_COMMAND
);
390 if_cs_enable_ints(card
);
391 lbs_deb_leave_args(LBS_DEB_CS
, "ret %d", ret
);
396 * Called from if_cs_host_to_card to send a data to the hardware
398 static void if_cs_send_data(struct lbs_private
*priv
, u8
*buf
, u16 nb
)
400 struct if_cs_card
*card
= (struct if_cs_card
*)priv
->card
;
403 lbs_deb_enter(LBS_DEB_CS
);
404 if_cs_disable_ints(card
);
406 status
= if_cs_read16(card
, IF_CS_CARD_STATUS
);
407 BUG_ON((status
& IF_CS_BIT_TX
) == 0);
409 if_cs_write16(card
, IF_CS_WRITE_LEN
, nb
);
411 /* write even number of bytes, then odd byte if necessary */
412 if_cs_write16_rep(card
, IF_CS_WRITE
, buf
, nb
/ 2);
414 if_cs_write8(card
, IF_CS_WRITE
, buf
[nb
-1]);
416 if_cs_write16(card
, IF_CS_HOST_STATUS
, IF_CS_BIT_TX
);
417 if_cs_write16(card
, IF_CS_HOST_INT_CAUSE
, IF_CS_BIT_TX
);
418 if_cs_enable_ints(card
);
420 lbs_deb_leave(LBS_DEB_CS
);
424 * Get the command result out of the card.
426 static int if_cs_receive_cmdres(struct lbs_private
*priv
, u8
*data
, u32
*len
)
432 lbs_deb_enter(LBS_DEB_CS
);
434 /* is hardware ready? */
435 status
= if_cs_read16(priv
->card
, IF_CS_CARD_STATUS
);
436 if ((status
& IF_CS_BIT_RESP
) == 0) {
437 netdev_err(priv
->dev
, "no cmd response in card\n");
442 *len
= if_cs_read16(priv
->card
, IF_CS_RESP_LEN
);
443 if ((*len
== 0) || (*len
> LBS_CMD_BUFFER_SIZE
)) {
444 netdev_err(priv
->dev
,
445 "card cmd buffer has invalid # of bytes (%d)\n",
450 /* read even number of bytes, then odd byte if necessary */
451 if_cs_read16_rep(priv
->card
, IF_CS_RESP
, data
, *len
/sizeof(u16
));
453 data
[*len
-1] = if_cs_read8(priv
->card
, IF_CS_RESP
);
455 /* This is a workaround for a firmware that reports too much
460 /* Clear this flag again */
461 spin_lock_irqsave(&priv
->driver_lock
, flags
);
462 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
463 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
466 lbs_deb_leave_args(LBS_DEB_CS
, "ret %d, len %d", ret
, *len
);
470 static struct sk_buff
*if_cs_receive_data(struct lbs_private
*priv
)
472 struct sk_buff
*skb
= NULL
;
476 lbs_deb_enter(LBS_DEB_CS
);
478 len
= if_cs_read16(priv
->card
, IF_CS_READ_LEN
);
479 if (len
== 0 || len
> MRVDRV_ETH_RX_PACKET_BUFFER_SIZE
) {
480 netdev_err(priv
->dev
,
481 "card data buffer has invalid # of bytes (%d)\n",
483 priv
->dev
->stats
.rx_dropped
++;
487 skb
= dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE
+ 2);
491 skb_reserve(skb
, 2);/* 16 byte align */
494 /* read even number of bytes, then odd byte if necessary */
495 if_cs_read16_rep(priv
->card
, IF_CS_READ
, data
, len
/sizeof(u16
));
497 data
[len
-1] = if_cs_read8(priv
->card
, IF_CS_READ
);
500 if_cs_write16(priv
->card
, IF_CS_HOST_STATUS
, IF_CS_BIT_RX
);
501 if_cs_write16(priv
->card
, IF_CS_HOST_INT_CAUSE
, IF_CS_BIT_RX
);
504 lbs_deb_leave_args(LBS_DEB_CS
, "ret %p", skb
);
508 static irqreturn_t
if_cs_interrupt(int irq
, void *data
)
510 struct if_cs_card
*card
= data
;
511 struct lbs_private
*priv
= card
->priv
;
514 lbs_deb_enter(LBS_DEB_CS
);
516 /* Ask card interrupt cause register if there is something for us */
517 cause
= if_cs_read16(card
, IF_CS_CARD_INT_CAUSE
);
518 lbs_deb_cs("cause 0x%04x\n", cause
);
525 if (cause
== 0xffff) {
526 /* Read in junk, the card has probably been removed */
527 card
->priv
->surpriseremoved
= 1;
531 if (cause
& IF_CS_BIT_RX
) {
533 lbs_deb_cs("rx packet\n");
534 skb
= if_cs_receive_data(priv
);
536 lbs_process_rxed_packet(priv
, skb
);
539 if (cause
& IF_CS_BIT_TX
) {
540 lbs_deb_cs("tx done\n");
541 lbs_host_to_card_done(priv
);
544 if (cause
& IF_CS_BIT_RESP
) {
548 lbs_deb_cs("cmd resp\n");
549 spin_lock_irqsave(&priv
->driver_lock
, flags
);
550 i
= (priv
->resp_idx
== 0) ? 1 : 0;
551 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
553 BUG_ON(priv
->resp_len
[i
]);
554 if_cs_receive_cmdres(priv
, priv
->resp_buf
[i
],
557 spin_lock_irqsave(&priv
->driver_lock
, flags
);
558 lbs_notify_command_response(priv
, i
);
559 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
562 if (cause
& IF_CS_BIT_EVENT
) {
563 u16 status
= if_cs_read16(priv
->card
, IF_CS_CARD_STATUS
);
564 if_cs_write16(priv
->card
, IF_CS_HOST_INT_CAUSE
,
566 lbs_queue_event(priv
, (status
& IF_CS_CARD_STATUS_MASK
) >> 8);
569 /* Clear interrupt cause */
570 if_cs_write16(card
, IF_CS_CARD_INT_CAUSE
, cause
& IF_CS_BIT_MASK
);
572 lbs_deb_leave(LBS_DEB_CS
);
579 /********************************************************************/
581 /********************************************************************/
584 * Tries to program the helper firmware.
586 * Return 0 on success
588 static int if_cs_prog_helper(struct if_cs_card
*card
, const struct firmware
*fw
)
594 lbs_deb_enter(LBS_DEB_CS
);
597 * This is the only place where an unaligned register access happens on
598 * the CF8305 card, therefore for the sake of speed of the driver, we do
599 * the alignment correction here.
601 if (card
->align_regs
)
602 scratch
= if_cs_read16(card
, IF_CS_SCRATCH
) >> 8;
604 scratch
= if_cs_read8(card
, IF_CS_SCRATCH
);
606 /* "If the value is 0x5a, the firmware is already
607 * downloaded successfully"
609 if (scratch
== IF_CS_SCRATCH_HELPER_OK
)
612 /* "If the value is != 00, it is invalid value of register */
613 if (scratch
!= IF_CS_SCRATCH_BOOT_OK
) {
618 lbs_deb_cs("helper size %td\n", fw
->size
);
620 /* "Set the 5 bytes of the helper image to 0" */
621 /* Not needed, this contains an ARM branch instruction */
624 /* "the number of bytes to send is 256" */
626 int remain
= fw
->size
- sent
;
632 * "write the number of bytes to be sent to the I/O Command
633 * write length register"
635 if_cs_write16(card
, IF_CS_CMD_LEN
, count
);
637 /* "write this to I/O Command port register as 16 bit writes */
639 if_cs_write16_rep(card
, IF_CS_CMD
,
644 * "Assert the download over interrupt command in the Host
647 if_cs_write8(card
, IF_CS_HOST_STATUS
, IF_CS_BIT_COMMAND
);
650 * "Assert the download over interrupt command in the Card
651 * interrupt case register"
653 if_cs_write16(card
, IF_CS_HOST_INT_CAUSE
, IF_CS_BIT_COMMAND
);
656 * "The host polls the Card Status register ... for 50 ms before
657 * declaring a failure"
659 ret
= if_cs_poll_while_fw_download(card
, IF_CS_CARD_STATUS
,
662 pr_err("can't download helper at 0x%x, ret %d\n",
674 lbs_deb_leave_args(LBS_DEB_CS
, "ret %d", ret
);
679 static int if_cs_prog_real(struct if_cs_card
*card
, const struct firmware
*fw
)
686 lbs_deb_enter(LBS_DEB_CS
);
688 lbs_deb_cs("fw size %td\n", fw
->size
);
690 ret
= if_cs_poll_while_fw_download(card
, IF_CS_SQ_READ_LOW
,
693 pr_err("helper firmware doesn't answer\n");
697 for (sent
= 0; sent
< fw
->size
; sent
+= len
) {
698 len
= if_cs_read16(card
, IF_CS_SQ_READ_LOW
);
701 pr_info("odd, need to retry this firmware block\n");
707 pr_err("could not download firmware\n");
716 if_cs_write16(card
, IF_CS_CMD_LEN
, len
);
718 if_cs_write16_rep(card
, IF_CS_CMD
,
721 if_cs_write8(card
, IF_CS_HOST_STATUS
, IF_CS_BIT_COMMAND
);
722 if_cs_write16(card
, IF_CS_HOST_INT_CAUSE
, IF_CS_BIT_COMMAND
);
724 ret
= if_cs_poll_while_fw_download(card
, IF_CS_CARD_STATUS
,
727 pr_err("can't download firmware at 0x%x\n", sent
);
732 ret
= if_cs_poll_while_fw_download(card
, IF_CS_SCRATCH
, 0x5a);
734 pr_err("firmware download failed\n");
737 lbs_deb_leave_args(LBS_DEB_CS
, "ret %d", ret
);
741 static void if_cs_prog_firmware(struct lbs_private
*priv
, int ret
,
742 const struct firmware
*helper
,
743 const struct firmware
*mainfw
)
745 struct if_cs_card
*card
= priv
->card
;
748 pr_err("failed to find firmware (%d)\n", ret
);
752 /* Load the firmware */
753 ret
= if_cs_prog_helper(card
, helper
);
754 if (ret
== 0 && (card
->model
!= MODEL_8305
))
755 ret
= if_cs_prog_real(card
, mainfw
);
759 /* Now actually get the IRQ */
760 ret
= request_irq(card
->p_dev
->irq
, if_cs_interrupt
,
761 IRQF_SHARED
, DRV_NAME
, card
);
763 pr_err("error in request_irq\n");
768 * Clear any interrupt cause that happened while sending
769 * firmware/initializing card
771 if_cs_write16(card
, IF_CS_CARD_INT_CAUSE
, IF_CS_BIT_MASK
);
772 if_cs_enable_ints(card
);
774 /* And finally bring the card up */
776 if (lbs_start_card(priv
) != 0) {
777 pr_err("could not activate card\n");
778 free_irq(card
->p_dev
->irq
, card
);
783 /********************************************************************/
784 /* Callback functions for libertas.ko */
785 /********************************************************************/
787 /* Send commands or data packets to the card */
788 static int if_cs_host_to_card(struct lbs_private
*priv
,
795 lbs_deb_enter_args(LBS_DEB_CS
, "type %d, bytes %d", type
, nb
);
799 priv
->dnld_sent
= DNLD_DATA_SENT
;
800 if_cs_send_data(priv
, buf
, nb
);
804 priv
->dnld_sent
= DNLD_CMD_SENT
;
805 ret
= if_cs_send_cmd(priv
, buf
, nb
);
808 netdev_err(priv
->dev
, "%s: unsupported type %d\n",
812 lbs_deb_leave_args(LBS_DEB_CS
, "ret %d", ret
);
817 static void if_cs_release(struct pcmcia_device
*p_dev
)
819 struct if_cs_card
*card
= p_dev
->priv
;
821 lbs_deb_enter(LBS_DEB_CS
);
823 free_irq(p_dev
->irq
, card
);
824 pcmcia_disable_device(p_dev
);
826 ioport_unmap(card
->iobase
);
828 lbs_deb_leave(LBS_DEB_CS
);
832 static int if_cs_ioprobe(struct pcmcia_device
*p_dev
, void *priv_data
)
834 p_dev
->resource
[0]->flags
&= ~IO_DATA_PATH_WIDTH
;
835 p_dev
->resource
[0]->flags
|= IO_DATA_PATH_WIDTH_AUTO
;
837 if (p_dev
->resource
[1]->end
) {
838 pr_err("wrong CIS (check number of IO windows)\n");
842 /* This reserves IO space but doesn't actually enable it */
843 return pcmcia_request_io(p_dev
);
846 static int if_cs_probe(struct pcmcia_device
*p_dev
)
849 unsigned int prod_id
;
850 struct lbs_private
*priv
;
851 struct if_cs_card
*card
;
853 lbs_deb_enter(LBS_DEB_CS
);
855 card
= kzalloc(sizeof(struct if_cs_card
), GFP_KERNEL
);
862 p_dev
->config_flags
|= CONF_ENABLE_IRQ
| CONF_AUTO_SET_IO
;
864 if (pcmcia_loop_config(p_dev
, if_cs_ioprobe
, NULL
)) {
865 pr_err("error in pcmcia_loop_config\n");
870 * Allocate an interrupt line. Note that this does not assign
871 * a handler to the interrupt, unless the 'Handler' member of
872 * the irq structure is initialized.
877 /* Initialize io access */
878 card
->iobase
= ioport_map(p_dev
->resource
[0]->start
,
879 resource_size(p_dev
->resource
[0]));
881 pr_err("error in ioport_map\n");
886 ret
= pcmcia_enable_device(p_dev
);
888 pr_err("error in pcmcia_enable_device\n");
892 /* Finally, report what we've done */
893 lbs_deb_cs("irq %d, io %pR", p_dev
->irq
, p_dev
->resource
[0]);
896 * Most of the libertas cards can do unaligned register access, but some
897 * weird ones cannot. That's especially true for the CF8305 card.
899 card
->align_regs
= false;
901 card
->model
= get_model(p_dev
->manf_id
, p_dev
->card_id
);
902 if (card
->model
== MODEL_UNKNOWN
) {
903 pr_err("unsupported manf_id 0x%04x / card_id 0x%04x\n",
904 p_dev
->manf_id
, p_dev
->card_id
);
909 /* Check if we have a current silicon */
910 prod_id
= if_cs_read8(card
, IF_CS_PRODUCT_ID
);
911 if (card
->model
== MODEL_8305
) {
912 card
->align_regs
= true;
913 if (prod_id
< IF_CS_CF8305_B1_REV
) {
914 pr_err("8305 rev B0 and older are not supported\n");
920 if ((card
->model
== MODEL_8381
) && prod_id
< IF_CS_CF8381_B3_REV
) {
921 pr_err("8381 rev B2 and older are not supported\n");
926 if ((card
->model
== MODEL_8385
) && prod_id
< IF_CS_CF8385_B1_REV
) {
927 pr_err("8385 rev B0 and older are not supported\n");
932 /* Make this card known to the libertas driver */
933 priv
= lbs_add_card(card
, &p_dev
->dev
);
939 /* Set up fields in lbs_private */
942 priv
->hw_host_to_card
= if_cs_host_to_card
;
943 priv
->enter_deep_sleep
= NULL
;
944 priv
->exit_deep_sleep
= NULL
;
945 priv
->reset_deep_sleep_wakeup
= NULL
;
948 ret
= lbs_get_firmware_async(priv
, &p_dev
->dev
, card
->model
, fw_table
,
949 if_cs_prog_firmware
);
951 pr_err("failed to find firmware (%d)\n", ret
);
958 lbs_remove_card(priv
);
960 ioport_unmap(card
->iobase
);
962 pcmcia_disable_device(p_dev
);
964 lbs_deb_leave_args(LBS_DEB_CS
, "ret %d", ret
);
969 static void if_cs_detach(struct pcmcia_device
*p_dev
)
971 struct if_cs_card
*card
= p_dev
->priv
;
973 lbs_deb_enter(LBS_DEB_CS
);
975 lbs_stop_card(card
->priv
);
976 lbs_remove_card(card
->priv
);
977 if_cs_disable_ints(card
);
978 if_cs_release(p_dev
);
981 lbs_deb_leave(LBS_DEB_CS
);
986 /********************************************************************/
987 /* Module initialization */
988 /********************************************************************/
990 static const struct pcmcia_device_id if_cs_ids
[] = {
991 PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID
, CF8305_CARDID
),
992 PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID
, CF8381_CARDID
),
993 PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID
, CF8385_CARDID
),
994 /* NOTE: keep in sync with get_model() */
997 MODULE_DEVICE_TABLE(pcmcia
, if_cs_ids
);
999 static struct pcmcia_driver lbs_driver
= {
1000 .owner
= THIS_MODULE
,
1002 .probe
= if_cs_probe
,
1003 .remove
= if_cs_detach
,
1004 .id_table
= if_cs_ids
,
1006 module_pcmcia_driver(lbs_driver
);