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>
38 #include <linux/mmc/sdio.h>
39 #include <linux/mmc/host.h>
48 /* The if_sdio_remove() callback function is called when
49 * user removes this module from kernel space or ejects
50 * the card from the slot. The driver handles these 2 cases
51 * differently for SD8688 combo chip.
52 * If the user is removing the module, the FUNC_SHUTDOWN
53 * command for SD8688 is sent to the firmware.
54 * If the card is removed, there is no need to send this command.
56 * The variable 'user_rmmod' is used to distinguish these two
57 * scenarios. This flag is initialized as FALSE in case the card
58 * is removed, and will be set to TRUE for module removal when
59 * module_exit function is called.
63 static char *lbs_helper_name
= NULL
;
64 module_param_named(helper_name
, lbs_helper_name
, charp
, 0644);
66 static char *lbs_fw_name
= NULL
;
67 module_param_named(fw_name
, lbs_fw_name
, charp
, 0644);
69 static const struct sdio_device_id if_sdio_ids
[] = {
70 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
,
71 SDIO_DEVICE_ID_MARVELL_LIBERTAS
) },
72 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
,
73 SDIO_DEVICE_ID_MARVELL_8688WLAN
) },
74 { /* end: all zeroes */ },
77 MODULE_DEVICE_TABLE(sdio
, if_sdio_ids
);
79 #define MODEL_8385 0x04
80 #define MODEL_8686 0x0b
81 #define MODEL_8688 0x10
83 static const struct lbs_fw_table fw_table
[] = {
84 { MODEL_8385
, "libertas/sd8385_helper.bin", "libertas/sd8385.bin" },
85 { MODEL_8385
, "sd8385_helper.bin", "sd8385.bin" },
86 { MODEL_8686
, "libertas/sd8686_v9_helper.bin", "libertas/sd8686_v9.bin" },
87 { MODEL_8686
, "libertas/sd8686_v8_helper.bin", "libertas/sd8686_v8.bin" },
88 { MODEL_8686
, "sd8686_helper.bin", "sd8686.bin" },
89 { MODEL_8688
, "libertas/sd8688_helper.bin", "libertas/sd8688.bin" },
90 { MODEL_8688
, "sd8688_helper.bin", "sd8688.bin" },
93 MODULE_FIRMWARE("libertas/sd8385_helper.bin");
94 MODULE_FIRMWARE("libertas/sd8385.bin");
95 MODULE_FIRMWARE("sd8385_helper.bin");
96 MODULE_FIRMWARE("sd8385.bin");
97 MODULE_FIRMWARE("libertas/sd8686_v9_helper.bin");
98 MODULE_FIRMWARE("libertas/sd8686_v9.bin");
99 MODULE_FIRMWARE("libertas/sd8686_v8_helper.bin");
100 MODULE_FIRMWARE("libertas/sd8686_v8.bin");
101 MODULE_FIRMWARE("sd8686_helper.bin");
102 MODULE_FIRMWARE("sd8686.bin");
103 MODULE_FIRMWARE("libertas/sd8688_helper.bin");
104 MODULE_FIRMWARE("libertas/sd8688.bin");
105 MODULE_FIRMWARE("sd8688_helper.bin");
106 MODULE_FIRMWARE("sd8688.bin");
108 struct if_sdio_packet
{
109 struct if_sdio_packet
*next
;
111 u8 buffer
[0] __attribute__((aligned(4)));
114 struct if_sdio_card
{
115 struct sdio_func
*func
;
116 struct lbs_private
*priv
;
119 unsigned long ioport
;
120 unsigned int scratch_reg
;
123 const char *firmware
;
124 bool helper_allocated
;
125 bool firmware_allocated
;
127 u8 buffer
[65536] __attribute__((aligned(4)));
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
) {
188 rx_len
= if_sdio_read_scratch(card
, &ret
);
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
== 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_wait_status(struct if_sdio_card
*card
, const u8 condition
)
319 unsigned long timeout
;
322 timeout
= jiffies
+ HZ
;
324 status
= sdio_readb(card
->func
, IF_SDIO_STATUS
, &ret
);
327 if ((status
& condition
) == condition
)
329 if (time_after(jiffies
, timeout
))
336 static int if_sdio_card_to_host(struct if_sdio_card
*card
)
339 u16 size
, type
, chunk
;
341 lbs_deb_enter(LBS_DEB_SDIO
);
343 size
= if_sdio_read_rx_len(card
, &ret
);
348 lbs_deb_sdio("invalid packet size (%d bytes) from firmware\n",
354 ret
= if_sdio_wait_status(card
, IF_SDIO_IO_RDY
);
359 * The transfer must be in one transaction or the firmware
360 * goes suicidal. There's no way to guarantee that for all
361 * controllers, but we can at least try.
363 chunk
= sdio_align_size(card
->func
, size
);
365 ret
= sdio_readsb(card
->func
, card
->buffer
, card
->ioport
, chunk
);
369 chunk
= card
->buffer
[0] | (card
->buffer
[1] << 8);
370 type
= card
->buffer
[2] | (card
->buffer
[3] << 8);
372 lbs_deb_sdio("packet of type %d and size %d bytes\n",
373 (int)type
, (int)chunk
);
376 lbs_deb_sdio("packet fragment (%d > %d)\n",
377 (int)chunk
, (int)size
);
383 lbs_deb_sdio("packet fragment (%d < %d)\n",
384 (int)chunk
, (int)size
);
389 ret
= if_sdio_handle_cmd(card
, card
->buffer
+ 4, chunk
- 4);
394 ret
= if_sdio_handle_data(card
, card
->buffer
+ 4, chunk
- 4);
399 ret
= if_sdio_handle_event(card
, card
->buffer
+ 4, chunk
- 4);
404 lbs_deb_sdio("invalid type (%d) from firmware\n",
412 lbs_pr_err("problem fetching packet from firmware\n");
414 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
419 static void if_sdio_host_to_card_worker(struct work_struct
*work
)
421 struct if_sdio_card
*card
;
422 struct if_sdio_packet
*packet
;
426 lbs_deb_enter(LBS_DEB_SDIO
);
428 card
= container_of(work
, struct if_sdio_card
, packet_worker
);
431 spin_lock_irqsave(&card
->lock
, flags
);
432 packet
= card
->packets
;
434 card
->packets
= packet
->next
;
435 spin_unlock_irqrestore(&card
->lock
, flags
);
440 sdio_claim_host(card
->func
);
442 ret
= if_sdio_wait_status(card
, IF_SDIO_IO_RDY
);
444 ret
= sdio_writesb(card
->func
, card
->ioport
,
445 packet
->buffer
, packet
->nb
);
449 lbs_pr_err("error %d sending packet to firmware\n", ret
);
451 sdio_release_host(card
->func
);
456 lbs_deb_leave(LBS_DEB_SDIO
);
459 /********************************************************************/
461 /********************************************************************/
463 #define FW_DL_READY_STATUS (IF_SDIO_IO_RDY | IF_SDIO_DL_RDY)
465 static int if_sdio_prog_helper(struct if_sdio_card
*card
,
466 const struct firmware
*fw
)
469 unsigned long timeout
;
475 lbs_deb_enter(LBS_DEB_SDIO
);
477 chunk_buffer
= kzalloc(64, GFP_KERNEL
);
483 sdio_claim_host(card
->func
);
485 ret
= sdio_set_block_size(card
->func
, 32);
493 ret
= if_sdio_wait_status(card
, FW_DL_READY_STATUS
);
497 /* On some platforms (like Davinci) the chip needs more time
498 * between helper blocks.
502 chunk_size
= min(size
, (size_t)60);
504 *((__le32
*)chunk_buffer
) = cpu_to_le32(chunk_size
);
505 memcpy(chunk_buffer
+ 4, firmware
, chunk_size
);
507 lbs_deb_sdio("sending %d bytes chunk\n", chunk_size);
509 ret
= sdio_writesb(card
->func
, card
->ioport
,
514 firmware
+= chunk_size
;
518 /* an empty block marks the end of the transfer */
519 memset(chunk_buffer
, 0, 4);
520 ret
= sdio_writesb(card
->func
, card
->ioport
, chunk_buffer
, 64);
524 lbs_deb_sdio("waiting for helper to boot...\n");
526 /* wait for the helper to boot by looking at the size register */
527 timeout
= jiffies
+ HZ
;
531 req_size
= sdio_readb(card
->func
, IF_SDIO_RD_BASE
, &ret
);
535 req_size
|= sdio_readb(card
->func
, IF_SDIO_RD_BASE
+ 1, &ret
) << 8;
542 if (time_after(jiffies
, timeout
)) {
553 sdio_release_host(card
->func
);
558 lbs_pr_err("failed to load helper firmware\n");
560 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
564 static int if_sdio_prog_real(struct if_sdio_card
*card
,
565 const struct firmware
*fw
)
568 unsigned long timeout
;
572 size_t size
, req_size
;
574 lbs_deb_enter(LBS_DEB_SDIO
);
576 chunk_buffer
= kzalloc(512, GFP_KERNEL
);
582 sdio_claim_host(card
->func
);
584 ret
= sdio_set_block_size(card
->func
, 32);
592 ret
= if_sdio_wait_status(card
, FW_DL_READY_STATUS
);
596 req_size
= sdio_readb(card
->func
, IF_SDIO_RD_BASE
, &ret
);
600 req_size
|= sdio_readb(card
->func
, IF_SDIO_RD_BASE
+ 1, &ret
) << 8;
604 lbs_deb_sdio("firmware wants %d bytes\n", (int)req_size);
607 lbs_deb_sdio("firmware helper gave up early\n");
612 if (req_size
& 0x01) {
613 lbs_deb_sdio("firmware helper signalled error\n");
622 chunk_size
= min(req_size
, (size_t)512);
624 memcpy(chunk_buffer
, firmware
, chunk_size
);
626 lbs_deb_sdio("sending %d bytes (%d bytes) chunk\n",
627 chunk_size, (chunk_size + 31) / 32 * 32);
629 ret
= sdio_writesb(card
->func
, card
->ioport
,
630 chunk_buffer
, roundup(chunk_size
, 32));
634 firmware
+= chunk_size
;
636 req_size
-= chunk_size
;
642 lbs_deb_sdio("waiting for firmware to boot...\n");
644 /* wait for the firmware to boot */
645 timeout
= jiffies
+ HZ
;
649 scratch
= if_sdio_read_scratch(card
, &ret
);
653 if (scratch
== IF_SDIO_FIRMWARE_OK
)
656 if (time_after(jiffies
, timeout
)) {
667 sdio_release_host(card
->func
);
672 lbs_pr_err("failed to load firmware\n");
674 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
678 static int if_sdio_prog_firmware(struct if_sdio_card
*card
)
682 const struct firmware
*helper
= NULL
;
683 const struct firmware
*mainfw
= NULL
;
685 lbs_deb_enter(LBS_DEB_SDIO
);
690 sdio_claim_host(card
->func
);
691 sdio_writeb(card
->func
, 0x00, IF_SDIO_H_INT_MASK
, &ret
);
692 sdio_release_host(card
->func
);
694 sdio_claim_host(card
->func
);
695 scratch
= if_sdio_read_scratch(card
, &ret
);
696 sdio_release_host(card
->func
);
698 lbs_deb_sdio("firmware status = %#x\n", scratch
);
699 lbs_deb_sdio("scratch ret = %d\n", ret
);
706 * The manual clearly describes that FEDC is the right code to use
707 * to detect firmware presence, but for SD8686 it is not that simple.
708 * Scratch is also used to store the RX packet length, so we lose
709 * the FEDC value early on. So we use a non-zero check in order
710 * to validate firmware presence.
711 * Additionally, the SD8686 in the Gumstix always has the high scratch
712 * bit set, even when the firmware is not loaded. So we have to
713 * exclude that from the test.
715 if (scratch
== IF_SDIO_FIRMWARE_OK
) {
716 lbs_deb_sdio("firmware already loaded\n");
718 } else if ((card
->model
== MODEL_8686
) && (scratch
& 0x7fff)) {
719 lbs_deb_sdio("firmware may be running\n");
723 ret
= lbs_get_firmware(&card
->func
->dev
, lbs_helper_name
, lbs_fw_name
,
724 card
->model
, &fw_table
[0], &helper
, &mainfw
);
726 lbs_pr_err("failed to find firmware (%d)\n", ret
);
730 ret
= if_sdio_prog_helper(card
, helper
);
734 lbs_deb_sdio("Helper firmware loaded\n");
736 ret
= if_sdio_prog_real(card
, mainfw
);
740 lbs_deb_sdio("Firmware loaded\n");
743 sdio_claim_host(card
->func
);
744 sdio_set_block_size(card
->func
, IF_SDIO_BLOCK_SIZE
);
745 sdio_release_host(card
->func
);
750 release_firmware(helper
);
752 release_firmware(mainfw
);
754 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
;
946 struct mmc_host
*host
= func
->card
->host
;
948 lbs_deb_enter(LBS_DEB_SDIO
);
950 for (i
= 0;i
< func
->card
->num_info
;i
++) {
951 if (sscanf(func
->card
->info
[i
],
952 "802.11 SDIO ID: %x", &model
) == 1)
954 if (sscanf(func
->card
->info
[i
],
955 "ID: %x", &model
) == 1)
957 if (!strcmp(func
->card
->info
[i
], "IBIS Wireless SDIO Card")) {
963 if (i
== func
->card
->num_info
) {
964 lbs_pr_err("unable to identify card model\n");
968 card
= kzalloc(sizeof(struct if_sdio_card
), GFP_KERNEL
);
975 switch (card
->model
) {
977 card
->scratch_reg
= IF_SDIO_SCRATCH_OLD
;
980 card
->scratch_reg
= IF_SDIO_SCRATCH
;
983 default: /* for newer chipsets */
984 card
->scratch_reg
= IF_SDIO_FW_STATUS
;
988 spin_lock_init(&card
->lock
);
989 card
->workqueue
= create_workqueue("libertas_sdio");
990 INIT_WORK(&card
->packet_worker
, if_sdio_host_to_card_worker
);
992 /* Check if we support this card */
993 for (i
= 0; i
< ARRAY_SIZE(fw_table
); i
++) {
994 if (card
->model
== fw_table
[i
].model
)
997 if (i
== ARRAY_SIZE(fw_table
)) {
998 lbs_pr_err("unknown card model 0x%x\n", card
->model
);
1003 sdio_claim_host(func
);
1005 ret
= sdio_enable_func(func
);
1009 ret
= sdio_claim_irq(func
, if_sdio_interrupt
);
1013 /* For 1-bit transfers to the 8686 model, we need to enable the
1014 * interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0
1015 * bit to allow access to non-vendor registers. */
1016 if ((card
->model
== MODEL_8686
) &&
1017 (host
->caps
& MMC_CAP_SDIO_IRQ
) &&
1018 (host
->ios
.bus_width
== MMC_BUS_WIDTH_1
)) {
1021 func
->card
->quirks
|= MMC_QUIRK_LENIENT_FN0
;
1022 reg
= sdio_f0_readb(func
, SDIO_CCCR_IF
, &ret
);
1026 reg
|= SDIO_BUS_ECSI
;
1027 sdio_f0_writeb(func
, reg
, SDIO_CCCR_IF
, &ret
);
1032 card
->ioport
= sdio_readb(func
, IF_SDIO_IOPORT
, &ret
);
1036 card
->ioport
|= sdio_readb(func
, IF_SDIO_IOPORT
+ 1, &ret
) << 8;
1040 card
->ioport
|= sdio_readb(func
, IF_SDIO_IOPORT
+ 2, &ret
) << 16;
1044 sdio_release_host(func
);
1046 sdio_set_drvdata(func
, card
);
1048 lbs_deb_sdio("class = 0x%X, vendor = 0x%X, "
1049 "device = 0x%X, model = 0x%X, ioport = 0x%X\n",
1050 func
->class, func
->vendor
, func
->device
,
1051 model
, (unsigned)card
->ioport
);
1053 ret
= if_sdio_prog_firmware(card
);
1057 priv
= lbs_add_card(card
, &func
->dev
);
1066 priv
->hw_host_to_card
= if_sdio_host_to_card
;
1067 priv
->enter_deep_sleep
= if_sdio_enter_deep_sleep
;
1068 priv
->exit_deep_sleep
= if_sdio_exit_deep_sleep
;
1069 priv
->reset_deep_sleep_wakeup
= if_sdio_reset_deep_sleep_wakeup
;
1071 sdio_claim_host(func
);
1074 * Get rx_unit if the chip is SD8688 or newer.
1075 * SD8385 & SD8686 do not have rx_unit.
1077 if ((card
->model
!= MODEL_8385
)
1078 && (card
->model
!= MODEL_8686
))
1079 card
->rx_unit
= if_sdio_read_rx_unit(card
);
1084 * Enable interrupts now that everything is set up
1086 sdio_writeb(func
, 0x0f, IF_SDIO_H_INT_MASK
, &ret
);
1087 sdio_release_host(func
);
1094 * FUNC_INIT is required for SD8688 WLAN/BT multiple functions
1096 if (card
->model
== MODEL_8688
) {
1097 struct cmd_header cmd
;
1099 memset(&cmd
, 0, sizeof(cmd
));
1101 lbs_deb_sdio("send function INIT command\n");
1102 if (__lbs_cmd(priv
, CMD_FUNC_INIT
, &cmd
, sizeof(cmd
),
1103 lbs_cmd_copyback
, (unsigned long) &cmd
))
1104 lbs_pr_alert("CMD_FUNC_INIT cmd failed\n");
1107 ret
= lbs_start_card(priv
);
1109 goto err_activate_card
;
1112 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
1117 flush_workqueue(card
->workqueue
);
1118 lbs_remove_card(priv
);
1120 sdio_claim_host(func
);
1122 sdio_release_irq(func
);
1124 sdio_disable_func(func
);
1126 sdio_release_host(func
);
1128 destroy_workqueue(card
->workqueue
);
1129 while (card
->packets
) {
1130 packet
= card
->packets
;
1131 card
->packets
= card
->packets
->next
;
1135 if (card
->helper_allocated
)
1136 kfree(card
->helper
);
1137 if (card
->firmware_allocated
)
1138 kfree(card
->firmware
);
1144 static void if_sdio_remove(struct sdio_func
*func
)
1146 struct if_sdio_card
*card
;
1147 struct if_sdio_packet
*packet
;
1149 lbs_deb_enter(LBS_DEB_SDIO
);
1151 card
= sdio_get_drvdata(func
);
1153 if (user_rmmod
&& (card
->model
== MODEL_8688
)) {
1155 * FUNC_SHUTDOWN is required for SD8688 WLAN/BT
1156 * multiple functions
1158 struct cmd_header cmd
;
1160 memset(&cmd
, 0, sizeof(cmd
));
1162 lbs_deb_sdio("send function SHUTDOWN command\n");
1163 if (__lbs_cmd(card
->priv
, CMD_FUNC_SHUTDOWN
,
1164 &cmd
, sizeof(cmd
), lbs_cmd_copyback
,
1165 (unsigned long) &cmd
))
1166 lbs_pr_alert("CMD_FUNC_SHUTDOWN cmd failed\n");
1170 lbs_deb_sdio("call remove card\n");
1171 lbs_stop_card(card
->priv
);
1172 lbs_remove_card(card
->priv
);
1174 flush_workqueue(card
->workqueue
);
1175 destroy_workqueue(card
->workqueue
);
1177 sdio_claim_host(func
);
1178 sdio_release_irq(func
);
1179 sdio_disable_func(func
);
1180 sdio_release_host(func
);
1182 while (card
->packets
) {
1183 packet
= card
->packets
;
1184 card
->packets
= card
->packets
->next
;
1188 if (card
->helper_allocated
)
1189 kfree(card
->helper
);
1190 if (card
->firmware_allocated
)
1191 kfree(card
->firmware
);
1194 lbs_deb_leave(LBS_DEB_SDIO
);
1197 static int if_sdio_suspend(struct device
*dev
)
1199 struct sdio_func
*func
= dev_to_sdio_func(dev
);
1201 struct if_sdio_card
*card
= sdio_get_drvdata(func
);
1203 mmc_pm_flag_t flags
= sdio_get_host_pm_caps(func
);
1205 lbs_pr_info("%s: suspend: PM flags = 0x%x\n",
1206 sdio_func_id(func
), flags
);
1208 /* If we aren't being asked to wake on anything, we should bail out
1209 * and let the SD stack power down the card.
1211 if (card
->priv
->wol_criteria
== EHS_REMOVE_WAKEUP
) {
1212 lbs_pr_info("Suspend without wake params -- "
1213 "powering down card.");
1217 if (!(flags
& MMC_PM_KEEP_POWER
)) {
1218 lbs_pr_err("%s: cannot remain alive while host is suspended\n",
1219 sdio_func_id(func
));
1223 ret
= sdio_set_host_pm_flags(func
, MMC_PM_KEEP_POWER
);
1227 ret
= lbs_suspend(card
->priv
);
1231 return sdio_set_host_pm_flags(func
, MMC_PM_WAKE_SDIO_IRQ
);
1234 static int if_sdio_resume(struct device
*dev
)
1236 struct sdio_func
*func
= dev_to_sdio_func(dev
);
1237 struct if_sdio_card
*card
= sdio_get_drvdata(func
);
1240 lbs_pr_info("%s: resume: we're back\n", sdio_func_id(func
));
1242 ret
= lbs_resume(card
->priv
);
1247 static const struct dev_pm_ops if_sdio_pm_ops
= {
1248 .suspend
= if_sdio_suspend
,
1249 .resume
= if_sdio_resume
,
1252 static struct sdio_driver if_sdio_driver
= {
1253 .name
= "libertas_sdio",
1254 .id_table
= if_sdio_ids
,
1255 .probe
= if_sdio_probe
,
1256 .remove
= if_sdio_remove
,
1258 .pm
= &if_sdio_pm_ops
,
1262 /*******************************************************************/
1263 /* Module functions */
1264 /*******************************************************************/
1266 static int __init
if_sdio_init_module(void)
1270 lbs_deb_enter(LBS_DEB_SDIO
);
1272 printk(KERN_INFO
"libertas_sdio: Libertas SDIO driver\n");
1273 printk(KERN_INFO
"libertas_sdio: Copyright Pierre Ossman\n");
1275 ret
= sdio_register_driver(&if_sdio_driver
);
1277 /* Clear the flag in case user removes the card. */
1280 lbs_deb_leave_args(LBS_DEB_SDIO
, "ret %d", ret
);
1285 static void __exit
if_sdio_exit_module(void)
1287 lbs_deb_enter(LBS_DEB_SDIO
);
1289 /* Set the flag as user is removing this module. */
1292 sdio_unregister_driver(&if_sdio_driver
);
1294 lbs_deb_leave(LBS_DEB_SDIO
);
1297 module_init(if_sdio_init_module
);
1298 module_exit(if_sdio_exit_module
);
1300 MODULE_DESCRIPTION("Libertas SDIO WLAN Driver");
1301 MODULE_AUTHOR("Pierre Ossman");
1302 MODULE_LICENSE("GPL");