2 * linux/drivers/net/wireless/libertas/if_sdio.c
4 * Copyright 2007-2008 Pierre Ossman
6 * Inspired by if_cs.c, Copyright 2007 Holger Schurig
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This hardware has more or less no CMD53 support, so all registers
14 * must be accessed using sdio_readb()/sdio_writeb().
16 * Transfers must be in one transaction or the firmware goes bonkers.
17 * This means that the transfer must either be small enough to do a
18 * byte based transfer or it must be padded to a multiple of the
21 * As SDIO is still new to the kernel, it is unfortunately common with
22 * bugs in the host controllers related to that. One such bug is that
23 * controllers cannot do transfers that aren't a multiple of 4 bytes.
24 * If you don't have time to fix the host controller driver, you can
25 * work around the problem by modifying if_sdio_host_to_card() and
26 * if_sdio_card_to_host() to pad the data.
29 #include <linux/kernel.h>
30 #include <linux/moduleparam.h>
31 #include <linux/slab.h>
32 #include <linux/firmware.h>
33 #include <linux/netdevice.h>
34 #include <linux/delay.h>
35 #include <linux/mmc/card.h>
36 #include <linux/mmc/sdio_func.h>
37 #include <linux/mmc/sdio_ids.h>
46 /* The if_sdio_remove() callback function is called when
47 * user removes this module from kernel space or ejects
48 * the card from the slot. The driver handles these 2 cases
49 * differently for SD8688 combo chip.
50 * If the user is removing the module, the FUNC_SHUTDOWN
51 * command for SD8688 is sent to the firmware.
52 * If the card is removed, there is no need to send this command.
54 * The variable 'user_rmmod' is used to distinguish these two
55 * scenarios. This flag is initialized as FALSE in case the card
56 * is removed, and will be set to TRUE for module removal when
57 * module_exit function is called.
61 static char *lbs_helper_name
= NULL
;
62 module_param_named(helper_name
, lbs_helper_name
, charp
, 0644);
64 static char *lbs_fw_name
= NULL
;
65 module_param_named(fw_name
, lbs_fw_name
, charp
, 0644);
67 static const struct sdio_device_id if_sdio_ids
[] = {
68 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
,
69 SDIO_DEVICE_ID_MARVELL_LIBERTAS
) },
70 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
,
71 SDIO_DEVICE_ID_MARVELL_8688WLAN
) },
72 { /* end: all zeroes */ },
75 MODULE_DEVICE_TABLE(sdio
, if_sdio_ids
);
77 struct if_sdio_model
{
83 static struct if_sdio_model if_sdio_models
[] = {
86 .model
= IF_SDIO_MODEL_8385
,
87 .helper
= "sd8385_helper.bin",
88 .firmware
= "sd8385.bin",
92 .model
= IF_SDIO_MODEL_8686
,
93 .helper
= "sd8686_helper.bin",
94 .firmware
= "sd8686.bin",
98 .model
= IF_SDIO_MODEL_8688
,
99 .helper
= "sd8688_helper.bin",
100 .firmware
= "sd8688.bin",
103 MODULE_FIRMWARE("sd8385_helper.bin");
104 MODULE_FIRMWARE("sd8385.bin");
105 MODULE_FIRMWARE("sd8686_helper.bin");
106 MODULE_FIRMWARE("sd8686.bin");
107 MODULE_FIRMWARE("sd8688_helper.bin");
108 MODULE_FIRMWARE("sd8688.bin");
110 struct if_sdio_packet
{
111 struct if_sdio_packet
*next
;
113 u8 buffer
[0] __attribute__((aligned(4)));
116 struct if_sdio_card
{
117 struct sdio_func
*func
;
118 struct lbs_private
*priv
;
121 unsigned long ioport
;
122 unsigned int scratch_reg
;
125 const char *firmware
;
130 struct if_sdio_packet
*packets
;
132 struct workqueue_struct
*workqueue
;
133 struct work_struct packet_worker
;
138 /********************************************************************/
140 /********************************************************************/
143 * For SD8385/SD8686, this function reads firmware status after
144 * the image is downloaded, or reads RX packet length when
145 * interrupt (with IF_SDIO_H_INT_UPLD bit set) is received.
146 * For SD8688, this function reads firmware status only.
148 static u16
if_sdio_read_scratch(struct if_sdio_card
*card
, int *err
)
153 scratch
= sdio_readb(card
->func
, card
->scratch_reg
, &ret
);
155 scratch
|= sdio_readb(card
->func
, card
->scratch_reg
+ 1,
167 static u8
if_sdio_read_rx_unit(struct if_sdio_card
*card
)
172 rx_unit
= sdio_readb(card
->func
, IF_SDIO_RX_UNIT
, &ret
);
180 static u16
if_sdio_read_rx_len(struct if_sdio_card
*card
, int *err
)
185 switch (card
->model
) {
186 case IF_SDIO_MODEL_8385
:
187 case IF_SDIO_MODEL_8686
:
188 rx_len
= if_sdio_read_scratch(card
, &ret
);
190 case IF_SDIO_MODEL_8688
:
191 default: /* for newer chipsets */
192 rx_len
= sdio_readb(card
->func
, IF_SDIO_RX_LEN
, &ret
);
194 rx_len
<<= card
->rx_unit
;
196 rx_len
= 0xffff; /* invalid length */
207 static int if_sdio_handle_cmd(struct if_sdio_card
*card
,
208 u8
*buffer
, unsigned size
)
210 struct lbs_private
*priv
= card
->priv
;
215 lbs_deb_enter(LBS_DEB_SDIO
);
217 if (size
> LBS_CMD_BUFFER_SIZE
) {
218 lbs_deb_sdio("response packet too large (%d bytes)\n",
224 spin_lock_irqsave(&priv
->driver_lock
, flags
);
226 i
= (priv
->resp_idx
== 0) ? 1 : 0;
227 BUG_ON(priv
->resp_len
[i
]);
228 priv
->resp_len
[i
] = size
;
229 memcpy(priv
->resp_buf
[i
], buffer
, size
);
230 lbs_notify_command_response(priv
, i
);
232 spin_unlock_irqrestore(&card
->priv
->driver_lock
, flags
);
237 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
241 static int if_sdio_handle_data(struct if_sdio_card
*card
,
242 u8
*buffer
, unsigned size
)
248 lbs_deb_enter(LBS_DEB_SDIO
);
250 if (size
> MRVDRV_ETH_RX_PACKET_BUFFER_SIZE
) {
251 lbs_deb_sdio("response packet too large (%d bytes)\n",
257 skb
= dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE
+ NET_IP_ALIGN
);
263 skb_reserve(skb
, NET_IP_ALIGN
);
265 data
= skb_put(skb
, size
);
267 memcpy(data
, buffer
, size
);
269 lbs_process_rxed_packet(card
->priv
, skb
);
274 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
279 static int if_sdio_handle_event(struct if_sdio_card
*card
,
280 u8
*buffer
, unsigned size
)
285 lbs_deb_enter(LBS_DEB_SDIO
);
287 if (card
->model
== IF_SDIO_MODEL_8385
) {
288 event
= sdio_readb(card
->func
, IF_SDIO_EVENT
, &ret
);
292 /* right shift 3 bits to get the event id */
296 lbs_deb_sdio("event packet too small (%d bytes)\n",
301 event
= buffer
[3] << 24;
302 event
|= buffer
[2] << 16;
303 event
|= buffer
[1] << 8;
304 event
|= buffer
[0] << 0;
307 lbs_queue_event(card
->priv
, event
& 0xFF);
311 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
316 static int if_sdio_card_to_host(struct if_sdio_card
*card
)
320 u16 size
, type
, chunk
;
321 unsigned long timeout
;
323 lbs_deb_enter(LBS_DEB_SDIO
);
325 size
= if_sdio_read_rx_len(card
, &ret
);
330 lbs_deb_sdio("invalid packet size (%d bytes) from firmware\n",
336 timeout
= jiffies
+ HZ
;
338 status
= sdio_readb(card
->func
, IF_SDIO_STATUS
, &ret
);
341 if (status
& IF_SDIO_IO_RDY
)
343 if (time_after(jiffies
, timeout
)) {
351 * The transfer must be in one transaction or the firmware
352 * goes suicidal. There's no way to guarantee that for all
353 * controllers, but we can at least try.
355 chunk
= sdio_align_size(card
->func
, size
);
357 ret
= sdio_readsb(card
->func
, card
->buffer
, card
->ioport
, chunk
);
361 chunk
= card
->buffer
[0] | (card
->buffer
[1] << 8);
362 type
= card
->buffer
[2] | (card
->buffer
[3] << 8);
364 lbs_deb_sdio("packet of type %d and size %d bytes\n",
365 (int)type
, (int)chunk
);
368 lbs_deb_sdio("packet fragment (%d > %d)\n",
369 (int)chunk
, (int)size
);
375 lbs_deb_sdio("packet fragment (%d < %d)\n",
376 (int)chunk
, (int)size
);
381 ret
= if_sdio_handle_cmd(card
, card
->buffer
+ 4, chunk
- 4);
386 ret
= if_sdio_handle_data(card
, card
->buffer
+ 4, chunk
- 4);
391 ret
= if_sdio_handle_event(card
, card
->buffer
+ 4, chunk
- 4);
396 lbs_deb_sdio("invalid type (%d) from firmware\n",
404 lbs_pr_err("problem fetching packet from firmware\n");
406 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
411 static void if_sdio_host_to_card_worker(struct work_struct
*work
)
413 struct if_sdio_card
*card
;
414 struct if_sdio_packet
*packet
;
415 unsigned long timeout
;
420 lbs_deb_enter(LBS_DEB_SDIO
);
422 card
= container_of(work
, struct if_sdio_card
, packet_worker
);
425 spin_lock_irqsave(&card
->lock
, flags
);
426 packet
= card
->packets
;
428 card
->packets
= packet
->next
;
429 spin_unlock_irqrestore(&card
->lock
, flags
);
434 sdio_claim_host(card
->func
);
436 timeout
= jiffies
+ HZ
;
438 status
= sdio_readb(card
->func
, IF_SDIO_STATUS
, &ret
);
441 if (status
& IF_SDIO_IO_RDY
)
443 if (time_after(jiffies
, timeout
)) {
450 ret
= sdio_writesb(card
->func
, card
->ioport
,
451 packet
->buffer
, packet
->nb
);
455 sdio_release_host(card
->func
);
460 lbs_deb_leave(LBS_DEB_SDIO
);
463 /********************************************************************/
465 /********************************************************************/
467 static int if_sdio_prog_helper(struct if_sdio_card
*card
)
471 const struct firmware
*fw
;
472 unsigned long timeout
;
478 lbs_deb_enter(LBS_DEB_SDIO
);
480 ret
= request_firmware(&fw
, card
->helper
, &card
->func
->dev
);
482 lbs_pr_err("can't load helper firmware\n");
486 chunk_buffer
= kzalloc(64, GFP_KERNEL
);
492 sdio_claim_host(card
->func
);
494 ret
= sdio_set_block_size(card
->func
, 32);
502 timeout
= jiffies
+ HZ
;
504 status
= sdio_readb(card
->func
, IF_SDIO_STATUS
, &ret
);
507 if ((status
& IF_SDIO_IO_RDY
) &&
508 (status
& IF_SDIO_DL_RDY
))
510 if (time_after(jiffies
, timeout
)) {
517 chunk_size
= min(size
, (size_t)60);
519 *((__le32
*)chunk_buffer
) = cpu_to_le32(chunk_size
);
520 memcpy(chunk_buffer
+ 4, firmware
, chunk_size
);
522 lbs_deb_sdio("sending %d bytes chunk\n", chunk_size);
524 ret
= sdio_writesb(card
->func
, card
->ioport
,
529 firmware
+= chunk_size
;
533 /* an empty block marks the end of the transfer */
534 memset(chunk_buffer
, 0, 4);
535 ret
= sdio_writesb(card
->func
, card
->ioport
, chunk_buffer
, 64);
539 lbs_deb_sdio("waiting for helper to boot...\n");
541 /* wait for the helper to boot by looking at the size register */
542 timeout
= jiffies
+ HZ
;
546 req_size
= sdio_readb(card
->func
, IF_SDIO_RD_BASE
, &ret
);
550 req_size
|= sdio_readb(card
->func
, IF_SDIO_RD_BASE
+ 1, &ret
) << 8;
557 if (time_after(jiffies
, timeout
)) {
568 sdio_release_host(card
->func
);
571 release_firmware(fw
);
575 lbs_pr_err("failed to load helper firmware\n");
577 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
582 static int if_sdio_prog_real(struct if_sdio_card
*card
)
586 const struct firmware
*fw
;
587 unsigned long timeout
;
591 size_t size
, req_size
;
593 lbs_deb_enter(LBS_DEB_SDIO
);
595 ret
= request_firmware(&fw
, card
->firmware
, &card
->func
->dev
);
597 lbs_pr_err("can't load firmware\n");
601 chunk_buffer
= kzalloc(512, GFP_KERNEL
);
607 sdio_claim_host(card
->func
);
609 ret
= sdio_set_block_size(card
->func
, 32);
617 timeout
= jiffies
+ HZ
;
619 status
= sdio_readb(card
->func
, IF_SDIO_STATUS
, &ret
);
622 if ((status
& IF_SDIO_IO_RDY
) &&
623 (status
& IF_SDIO_DL_RDY
))
625 if (time_after(jiffies
, timeout
)) {
632 req_size
= sdio_readb(card
->func
, IF_SDIO_RD_BASE
, &ret
);
636 req_size
|= sdio_readb(card
->func
, IF_SDIO_RD_BASE
+ 1, &ret
) << 8;
640 lbs_deb_sdio("firmware wants %d bytes\n", (int)req_size);
643 lbs_deb_sdio("firmware helper gave up early\n");
648 if (req_size
& 0x01) {
649 lbs_deb_sdio("firmware helper signalled error\n");
658 chunk_size
= min(req_size
, (size_t)512);
660 memcpy(chunk_buffer
, firmware
, chunk_size
);
662 lbs_deb_sdio("sending %d bytes (%d bytes) chunk\n",
663 chunk_size, (chunk_size + 31) / 32 * 32);
665 ret
= sdio_writesb(card
->func
, card
->ioport
,
666 chunk_buffer
, roundup(chunk_size
, 32));
670 firmware
+= chunk_size
;
672 req_size
-= chunk_size
;
678 lbs_deb_sdio("waiting for firmware to boot...\n");
680 /* wait for the firmware to boot */
681 timeout
= jiffies
+ HZ
;
685 scratch
= if_sdio_read_scratch(card
, &ret
);
689 if (scratch
== IF_SDIO_FIRMWARE_OK
)
692 if (time_after(jiffies
, timeout
)) {
703 sdio_release_host(card
->func
);
706 release_firmware(fw
);
710 lbs_pr_err("failed to load firmware\n");
712 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
717 static int if_sdio_prog_firmware(struct if_sdio_card
*card
)
722 lbs_deb_enter(LBS_DEB_SDIO
);
724 sdio_claim_host(card
->func
);
725 scratch
= if_sdio_read_scratch(card
, &ret
);
726 sdio_release_host(card
->func
);
731 lbs_deb_sdio("firmware status = %#x\n", scratch
);
733 if (scratch
== IF_SDIO_FIRMWARE_OK
) {
734 lbs_deb_sdio("firmware already loaded\n");
738 ret
= if_sdio_prog_helper(card
);
742 ret
= if_sdio_prog_real(card
);
747 sdio_claim_host(card
->func
);
748 sdio_set_block_size(card
->func
, IF_SDIO_BLOCK_SIZE
);
749 sdio_release_host(card
->func
);
753 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
758 /*******************************************************************/
759 /* Libertas callbacks */
760 /*******************************************************************/
762 static int if_sdio_host_to_card(struct lbs_private
*priv
,
763 u8 type
, u8
*buf
, u16 nb
)
766 struct if_sdio_card
*card
;
767 struct if_sdio_packet
*packet
, *cur
;
771 lbs_deb_enter_args(LBS_DEB_SDIO
, "type %d, bytes %d", type
, nb
);
775 if (nb
> (65536 - sizeof(struct if_sdio_packet
) - 4)) {
781 * The transfer must be in one transaction or the firmware
782 * goes suicidal. There's no way to guarantee that for all
783 * controllers, but we can at least try.
785 size
= sdio_align_size(card
->func
, nb
+ 4);
787 packet
= kzalloc(sizeof(struct if_sdio_packet
) + size
,
798 * SDIO specific header.
800 packet
->buffer
[0] = (nb
+ 4) & 0xff;
801 packet
->buffer
[1] = ((nb
+ 4) >> 8) & 0xff;
802 packet
->buffer
[2] = type
;
803 packet
->buffer
[3] = 0;
805 memcpy(packet
->buffer
+ 4, buf
, nb
);
807 spin_lock_irqsave(&card
->lock
, flags
);
810 card
->packets
= packet
;
820 priv
->dnld_sent
= DNLD_CMD_SENT
;
823 priv
->dnld_sent
= DNLD_DATA_SENT
;
826 lbs_deb_sdio("unknown packet type %d\n", (int)type
);
829 spin_unlock_irqrestore(&card
->lock
, flags
);
831 queue_work(card
->workqueue
, &card
->packet_worker
);
836 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
841 static int if_sdio_enter_deep_sleep(struct lbs_private
*priv
)
844 struct cmd_header cmd
;
846 memset(&cmd
, 0, sizeof(cmd
));
848 lbs_deb_sdio("send DEEP_SLEEP command\n");
849 ret
= __lbs_cmd(priv
, CMD_802_11_DEEP_SLEEP
, &cmd
, sizeof(cmd
),
850 lbs_cmd_copyback
, (unsigned long) &cmd
);
852 lbs_pr_err("DEEP_SLEEP cmd failed\n");
858 static int if_sdio_exit_deep_sleep(struct lbs_private
*priv
)
860 struct if_sdio_card
*card
= priv
->card
;
863 lbs_deb_enter(LBS_DEB_SDIO
);
864 sdio_claim_host(card
->func
);
866 sdio_writeb(card
->func
, HOST_POWER_UP
, CONFIGURATION_REG
, &ret
);
868 lbs_pr_err("sdio_writeb failed!\n");
870 sdio_release_host(card
->func
);
871 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
875 static int if_sdio_reset_deep_sleep_wakeup(struct lbs_private
*priv
)
877 struct if_sdio_card
*card
= priv
->card
;
880 lbs_deb_enter(LBS_DEB_SDIO
);
881 sdio_claim_host(card
->func
);
883 sdio_writeb(card
->func
, 0, CONFIGURATION_REG
, &ret
);
885 lbs_pr_err("sdio_writeb failed!\n");
887 sdio_release_host(card
->func
);
888 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
893 /*******************************************************************/
895 /*******************************************************************/
897 static void if_sdio_interrupt(struct sdio_func
*func
)
900 struct if_sdio_card
*card
;
903 lbs_deb_enter(LBS_DEB_SDIO
);
905 card
= sdio_get_drvdata(func
);
907 cause
= sdio_readb(card
->func
, IF_SDIO_H_INT_STATUS
, &ret
);
911 lbs_deb_sdio("interrupt: 0x%X\n", (unsigned)cause
);
913 sdio_writeb(card
->func
, ~cause
, IF_SDIO_H_INT_STATUS
, &ret
);
918 * Ignore the define name, this really means the card has
919 * successfully received the command.
921 card
->priv
->is_activity_detected
= 1;
922 if (cause
& IF_SDIO_H_INT_DNLD
)
923 lbs_host_to_card_done(card
->priv
);
926 if (cause
& IF_SDIO_H_INT_UPLD
) {
927 ret
= if_sdio_card_to_host(card
);
935 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
938 static int if_sdio_probe(struct sdio_func
*func
,
939 const struct sdio_device_id
*id
)
941 struct if_sdio_card
*card
;
942 struct lbs_private
*priv
;
945 struct if_sdio_packet
*packet
;
947 lbs_deb_enter(LBS_DEB_SDIO
);
949 for (i
= 0;i
< func
->card
->num_info
;i
++) {
950 if (sscanf(func
->card
->info
[i
],
951 "802.11 SDIO ID: %x", &model
) == 1)
953 if (sscanf(func
->card
->info
[i
],
954 "ID: %x", &model
) == 1)
956 if (!strcmp(func
->card
->info
[i
], "IBIS Wireless SDIO Card")) {
957 model
= IF_SDIO_MODEL_8385
;
962 if (i
== func
->card
->num_info
) {
963 lbs_pr_err("unable to identify card model\n");
967 card
= kzalloc(sizeof(struct if_sdio_card
), GFP_KERNEL
);
974 switch (card
->model
) {
975 case IF_SDIO_MODEL_8385
:
976 card
->scratch_reg
= IF_SDIO_SCRATCH_OLD
;
978 case IF_SDIO_MODEL_8686
:
979 card
->scratch_reg
= IF_SDIO_SCRATCH
;
981 case IF_SDIO_MODEL_8688
:
982 default: /* for newer chipsets */
983 card
->scratch_reg
= IF_SDIO_FW_STATUS
;
987 spin_lock_init(&card
->lock
);
988 card
->workqueue
= create_workqueue("libertas_sdio");
989 INIT_WORK(&card
->packet_worker
, if_sdio_host_to_card_worker
);
991 for (i
= 0;i
< ARRAY_SIZE(if_sdio_models
);i
++) {
992 if (card
->model
== if_sdio_models
[i
].model
)
996 if (i
== ARRAY_SIZE(if_sdio_models
)) {
997 lbs_pr_err("unknown card model 0x%x\n", card
->model
);
1002 card
->helper
= if_sdio_models
[i
].helper
;
1003 card
->firmware
= if_sdio_models
[i
].firmware
;
1005 if (lbs_helper_name
) {
1006 lbs_deb_sdio("overriding helper firmware: %s\n",
1008 card
->helper
= lbs_helper_name
;
1012 lbs_deb_sdio("overriding firmware: %s\n", lbs_fw_name
);
1013 card
->firmware
= lbs_fw_name
;
1016 sdio_claim_host(func
);
1018 ret
= sdio_enable_func(func
);
1022 ret
= sdio_claim_irq(func
, if_sdio_interrupt
);
1026 card
->ioport
= sdio_readb(func
, IF_SDIO_IOPORT
, &ret
);
1030 card
->ioport
|= sdio_readb(func
, IF_SDIO_IOPORT
+ 1, &ret
) << 8;
1034 card
->ioport
|= sdio_readb(func
, IF_SDIO_IOPORT
+ 2, &ret
) << 16;
1038 sdio_release_host(func
);
1040 sdio_set_drvdata(func
, card
);
1042 lbs_deb_sdio("class = 0x%X, vendor = 0x%X, "
1043 "device = 0x%X, model = 0x%X, ioport = 0x%X\n",
1044 func
->class, func
->vendor
, func
->device
,
1045 model
, (unsigned)card
->ioport
);
1047 ret
= if_sdio_prog_firmware(card
);
1051 priv
= lbs_add_card(card
, &func
->dev
);
1060 priv
->hw_host_to_card
= if_sdio_host_to_card
;
1061 priv
->enter_deep_sleep
= if_sdio_enter_deep_sleep
;
1062 priv
->exit_deep_sleep
= if_sdio_exit_deep_sleep
;
1063 priv
->reset_deep_sleep_wakeup
= if_sdio_reset_deep_sleep_wakeup
;
1067 sdio_claim_host(func
);
1070 * Get rx_unit if the chip is SD8688 or newer.
1071 * SD8385 & SD8686 do not have rx_unit.
1073 if ((card
->model
!= IF_SDIO_MODEL_8385
)
1074 && (card
->model
!= IF_SDIO_MODEL_8686
))
1075 card
->rx_unit
= if_sdio_read_rx_unit(card
);
1080 * Enable interrupts now that everything is set up
1082 sdio_writeb(func
, 0x0f, IF_SDIO_H_INT_MASK
, &ret
);
1083 sdio_release_host(func
);
1088 * FUNC_INIT is required for SD8688 WLAN/BT multiple functions
1090 if (card
->model
== IF_SDIO_MODEL_8688
) {
1091 struct cmd_header cmd
;
1093 memset(&cmd
, 0, sizeof(cmd
));
1095 lbs_deb_sdio("send function INIT command\n");
1096 if (__lbs_cmd(priv
, CMD_FUNC_INIT
, &cmd
, sizeof(cmd
),
1097 lbs_cmd_copyback
, (unsigned long) &cmd
))
1098 lbs_pr_alert("CMD_FUNC_INIT cmd failed\n");
1101 ret
= lbs_start_card(priv
);
1103 goto err_activate_card
;
1106 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
1111 flush_workqueue(card
->workqueue
);
1112 lbs_remove_card(priv
);
1114 sdio_claim_host(func
);
1116 sdio_release_irq(func
);
1118 sdio_disable_func(func
);
1120 sdio_release_host(func
);
1122 destroy_workqueue(card
->workqueue
);
1123 while (card
->packets
) {
1124 packet
= card
->packets
;
1125 card
->packets
= card
->packets
->next
;
1134 static void if_sdio_remove(struct sdio_func
*func
)
1136 struct if_sdio_card
*card
;
1137 struct if_sdio_packet
*packet
;
1139 lbs_deb_enter(LBS_DEB_SDIO
);
1141 card
= sdio_get_drvdata(func
);
1143 if (user_rmmod
&& (card
->model
== IF_SDIO_MODEL_8688
)) {
1145 * FUNC_SHUTDOWN is required for SD8688 WLAN/BT
1146 * multiple functions
1148 struct cmd_header cmd
;
1150 memset(&cmd
, 0, sizeof(cmd
));
1152 lbs_deb_sdio("send function SHUTDOWN command\n");
1153 if (__lbs_cmd(card
->priv
, CMD_FUNC_SHUTDOWN
,
1154 &cmd
, sizeof(cmd
), lbs_cmd_copyback
,
1155 (unsigned long) &cmd
))
1156 lbs_pr_alert("CMD_FUNC_SHUTDOWN cmd failed\n");
1160 lbs_deb_sdio("call remove card\n");
1161 lbs_stop_card(card
->priv
);
1162 lbs_remove_card(card
->priv
);
1163 card
->priv
->surpriseremoved
= 1;
1165 flush_workqueue(card
->workqueue
);
1166 destroy_workqueue(card
->workqueue
);
1168 sdio_claim_host(func
);
1169 sdio_release_irq(func
);
1170 sdio_disable_func(func
);
1171 sdio_release_host(func
);
1173 while (card
->packets
) {
1174 packet
= card
->packets
;
1175 card
->packets
= card
->packets
->next
;
1181 lbs_deb_leave(LBS_DEB_SDIO
);
1184 static struct sdio_driver if_sdio_driver
= {
1185 .name
= "libertas_sdio",
1186 .id_table
= if_sdio_ids
,
1187 .probe
= if_sdio_probe
,
1188 .remove
= if_sdio_remove
,
1191 /*******************************************************************/
1192 /* Module functions */
1193 /*******************************************************************/
1195 static int __init
if_sdio_init_module(void)
1199 lbs_deb_enter(LBS_DEB_SDIO
);
1201 printk(KERN_INFO
"libertas_sdio: Libertas SDIO driver\n");
1202 printk(KERN_INFO
"libertas_sdio: Copyright Pierre Ossman\n");
1204 ret
= sdio_register_driver(&if_sdio_driver
);
1206 /* Clear the flag in case user removes the card. */
1209 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
1214 static void __exit
if_sdio_exit_module(void)
1216 lbs_deb_enter(LBS_DEB_SDIO
);
1218 /* Set the flag as user is removing this module. */
1221 sdio_unregister_driver(&if_sdio_driver
);
1223 lbs_deb_leave(LBS_DEB_SDIO
);
1226 module_init(if_sdio_init_module
);
1227 module_exit(if_sdio_exit_module
);
1229 MODULE_DESCRIPTION("Libertas SDIO WLAN Driver");
1230 MODULE_AUTHOR("Pierre Ossman");
1231 MODULE_LICENSE("GPL");