Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/net/wireless/libertas/if_sdio.c |
| 3 | * |
Pierre Ossman | ad3868b | 2008-06-28 12:52:45 +0200 | [diff] [blame] | 4 | * Copyright 2007-2008 Pierre Ossman |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 5 | * |
| 6 | * Inspired by if_cs.c, Copyright 2007 Holger Schurig |
| 7 | * |
| 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. |
| 12 | * |
| 13 | * This hardware has more or less no CMD53 support, so all registers |
| 14 | * must be accessed using sdio_readb()/sdio_writeb(). |
| 15 | * |
| 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 |
| 19 | * current block size. |
| 20 | * |
| 21 | * As SDIO is still new to the kernel, it is unfortunately common with |
David Woodhouse | 7e22627 | 2007-12-14 22:53:41 -0500 | [diff] [blame] | 22 | * bugs in the host controllers related to that. One such bug is that |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 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. |
| 27 | */ |
| 28 | |
Ilpo Järvinen | 2382792 | 2008-12-13 21:33:13 +0200 | [diff] [blame] | 29 | #include <linux/kernel.h> |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 30 | #include <linux/moduleparam.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 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> |
Daniel Mack | 8a64c0f | 2010-04-06 10:52:44 +0200 | [diff] [blame] | 38 | #include <linux/mmc/sdio.h> |
| 39 | #include <linux/mmc/host.h> |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 40 | |
| 41 | #include "host.h" |
| 42 | #include "decl.h" |
| 43 | #include "defs.h" |
| 44 | #include "dev.h" |
Bing Zhao | 6bc61f4 | 2009-06-01 18:04:36 -0700 | [diff] [blame] | 45 | #include "cmd.h" |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 46 | #include "if_sdio.h" |
| 47 | |
Bing Zhao | 6bc61f4 | 2009-06-01 18:04:36 -0700 | [diff] [blame] | 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. |
| 55 | * |
| 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. |
| 60 | */ |
| 61 | static u8 user_rmmod; |
| 62 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 63 | static char *lbs_helper_name = NULL; |
| 64 | module_param_named(helper_name, lbs_helper_name, charp, 0644); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 65 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 66 | static char *lbs_fw_name = NULL; |
| 67 | module_param_named(fw_name, lbs_fw_name, charp, 0644); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 68 | |
| 69 | static const struct sdio_device_id if_sdio_ids[] = { |
Bing Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 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 */ }, |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | MODULE_DEVICE_TABLE(sdio, if_sdio_ids); |
| 78 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 79 | #define MODEL_8385 0x04 |
| 80 | #define MODEL_8686 0x0b |
| 81 | #define MODEL_8688 0x10 |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 82 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 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" }, |
| 91 | { 0, NULL, NULL } |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 92 | }; |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 93 | MODULE_FIRMWARE("libertas/sd8385_helper.bin"); |
| 94 | MODULE_FIRMWARE("libertas/sd8385.bin"); |
Ben Hutchings | a974a4b | 2009-11-07 22:00:03 +0000 | [diff] [blame] | 95 | MODULE_FIRMWARE("sd8385_helper.bin"); |
| 96 | MODULE_FIRMWARE("sd8385.bin"); |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 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"); |
Ben Hutchings | a974a4b | 2009-11-07 22:00:03 +0000 | [diff] [blame] | 101 | MODULE_FIRMWARE("sd8686_helper.bin"); |
| 102 | MODULE_FIRMWARE("sd8686.bin"); |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 103 | MODULE_FIRMWARE("libertas/sd8688_helper.bin"); |
| 104 | MODULE_FIRMWARE("libertas/sd8688.bin"); |
Ben Hutchings | a974a4b | 2009-11-07 22:00:03 +0000 | [diff] [blame] | 105 | MODULE_FIRMWARE("sd8688_helper.bin"); |
| 106 | MODULE_FIRMWARE("sd8688.bin"); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 107 | |
| 108 | struct if_sdio_packet { |
| 109 | struct if_sdio_packet *next; |
| 110 | u16 nb; |
| 111 | u8 buffer[0] __attribute__((aligned(4))); |
| 112 | }; |
| 113 | |
| 114 | struct if_sdio_card { |
| 115 | struct sdio_func *func; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 116 | struct lbs_private *priv; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 117 | |
| 118 | int model; |
| 119 | unsigned long ioport; |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 120 | unsigned int scratch_reg; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 121 | |
| 122 | const char *helper; |
| 123 | const char *firmware; |
| 124 | |
| 125 | u8 buffer[65536]; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 126 | |
| 127 | spinlock_t lock; |
| 128 | struct if_sdio_packet *packets; |
Dan Williams | 9b02f41 | 2009-02-20 12:27:38 -0500 | [diff] [blame] | 129 | |
| 130 | struct workqueue_struct *workqueue; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 131 | struct work_struct packet_worker; |
Bing Zhao | b136a14 | 2009-05-19 19:48:19 -0700 | [diff] [blame] | 132 | |
| 133 | u8 rx_unit; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | /********************************************************************/ |
| 137 | /* I/O */ |
| 138 | /********************************************************************/ |
| 139 | |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 140 | /* |
| 141 | * For SD8385/SD8686, this function reads firmware status after |
| 142 | * the image is downloaded, or reads RX packet length when |
| 143 | * interrupt (with IF_SDIO_H_INT_UPLD bit set) is received. |
| 144 | * For SD8688, this function reads firmware status only. |
| 145 | */ |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 146 | static u16 if_sdio_read_scratch(struct if_sdio_card *card, int *err) |
| 147 | { |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 148 | int ret; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 149 | u16 scratch; |
| 150 | |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 151 | scratch = sdio_readb(card->func, card->scratch_reg, &ret); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 152 | if (!ret) |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 153 | scratch |= sdio_readb(card->func, card->scratch_reg + 1, |
| 154 | &ret) << 8; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 155 | |
| 156 | if (err) |
| 157 | *err = ret; |
| 158 | |
| 159 | if (ret) |
| 160 | return 0xffff; |
| 161 | |
| 162 | return scratch; |
| 163 | } |
| 164 | |
Bing Zhao | b136a14 | 2009-05-19 19:48:19 -0700 | [diff] [blame] | 165 | static u8 if_sdio_read_rx_unit(struct if_sdio_card *card) |
| 166 | { |
| 167 | int ret; |
| 168 | u8 rx_unit; |
| 169 | |
| 170 | rx_unit = sdio_readb(card->func, IF_SDIO_RX_UNIT, &ret); |
| 171 | |
| 172 | if (ret) |
| 173 | rx_unit = 0; |
| 174 | |
| 175 | return rx_unit; |
| 176 | } |
| 177 | |
| 178 | static u16 if_sdio_read_rx_len(struct if_sdio_card *card, int *err) |
| 179 | { |
| 180 | int ret; |
| 181 | u16 rx_len; |
| 182 | |
| 183 | switch (card->model) { |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 184 | case MODEL_8385: |
| 185 | case MODEL_8686: |
Bing Zhao | b136a14 | 2009-05-19 19:48:19 -0700 | [diff] [blame] | 186 | rx_len = if_sdio_read_scratch(card, &ret); |
| 187 | break; |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 188 | case MODEL_8688: |
Bing Zhao | b136a14 | 2009-05-19 19:48:19 -0700 | [diff] [blame] | 189 | default: /* for newer chipsets */ |
| 190 | rx_len = sdio_readb(card->func, IF_SDIO_RX_LEN, &ret); |
| 191 | if (!ret) |
| 192 | rx_len <<= card->rx_unit; |
| 193 | else |
| 194 | rx_len = 0xffff; /* invalid length */ |
| 195 | |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | if (err) |
| 200 | *err = ret; |
| 201 | |
| 202 | return rx_len; |
| 203 | } |
| 204 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 205 | static int if_sdio_handle_cmd(struct if_sdio_card *card, |
| 206 | u8 *buffer, unsigned size) |
| 207 | { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 208 | struct lbs_private *priv = card->priv; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 209 | int ret; |
| 210 | unsigned long flags; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 211 | u8 i; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 212 | |
| 213 | lbs_deb_enter(LBS_DEB_SDIO); |
| 214 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 215 | if (size > LBS_CMD_BUFFER_SIZE) { |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 216 | lbs_deb_sdio("response packet too large (%d bytes)\n", |
| 217 | (int)size); |
| 218 | ret = -E2BIG; |
| 219 | goto out; |
| 220 | } |
| 221 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 222 | spin_lock_irqsave(&priv->driver_lock, flags); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 223 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 224 | i = (priv->resp_idx == 0) ? 1 : 0; |
| 225 | BUG_ON(priv->resp_len[i]); |
| 226 | priv->resp_len[i] = size; |
| 227 | memcpy(priv->resp_buf[i], buffer, size); |
| 228 | lbs_notify_command_response(priv, i); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 229 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 230 | spin_unlock_irqrestore(&card->priv->driver_lock, flags); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 231 | |
| 232 | ret = 0; |
| 233 | |
| 234 | out: |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 235 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | static int if_sdio_handle_data(struct if_sdio_card *card, |
| 240 | u8 *buffer, unsigned size) |
| 241 | { |
| 242 | int ret; |
| 243 | struct sk_buff *skb; |
| 244 | char *data; |
| 245 | |
| 246 | lbs_deb_enter(LBS_DEB_SDIO); |
| 247 | |
| 248 | if (size > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) { |
| 249 | lbs_deb_sdio("response packet too large (%d bytes)\n", |
| 250 | (int)size); |
| 251 | ret = -E2BIG; |
| 252 | goto out; |
| 253 | } |
| 254 | |
Pierre Ossman | 51e6b71 | 2007-10-22 19:05:32 +0200 | [diff] [blame] | 255 | skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + NET_IP_ALIGN); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 256 | if (!skb) { |
| 257 | ret = -ENOMEM; |
| 258 | goto out; |
| 259 | } |
| 260 | |
Pierre Ossman | 51e6b71 | 2007-10-22 19:05:32 +0200 | [diff] [blame] | 261 | skb_reserve(skb, NET_IP_ALIGN); |
| 262 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 263 | data = skb_put(skb, size); |
| 264 | |
| 265 | memcpy(data, buffer, size); |
| 266 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 267 | lbs_process_rxed_packet(card->priv, skb); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 268 | |
| 269 | ret = 0; |
| 270 | |
| 271 | out: |
| 272 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 273 | |
| 274 | return ret; |
| 275 | } |
| 276 | |
| 277 | static int if_sdio_handle_event(struct if_sdio_card *card, |
| 278 | u8 *buffer, unsigned size) |
| 279 | { |
| 280 | int ret; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 281 | u32 event; |
| 282 | |
| 283 | lbs_deb_enter(LBS_DEB_SDIO); |
| 284 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 285 | if (card->model == MODEL_8385) { |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 286 | event = sdio_readb(card->func, IF_SDIO_EVENT, &ret); |
| 287 | if (ret) |
| 288 | goto out; |
Bing Zhao | f5ac2b9 | 2009-02-04 22:22:39 -0800 | [diff] [blame] | 289 | |
| 290 | /* right shift 3 bits to get the event id */ |
| 291 | event >>= 3; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 292 | } else { |
| 293 | if (size < 4) { |
| 294 | lbs_deb_sdio("event packet too small (%d bytes)\n", |
| 295 | (int)size); |
| 296 | ret = -EINVAL; |
| 297 | goto out; |
| 298 | } |
| 299 | event = buffer[3] << 24; |
| 300 | event |= buffer[2] << 16; |
| 301 | event |= buffer[1] << 8; |
| 302 | event |= buffer[0] << 0; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 305 | lbs_queue_event(card->priv, event & 0xFF); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 306 | ret = 0; |
| 307 | |
| 308 | out: |
| 309 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 310 | |
| 311 | return ret; |
| 312 | } |
| 313 | |
Dan Williams | 96021f0 | 2010-04-15 13:27:44 -0700 | [diff] [blame] | 314 | static int if_sdio_wait_status(struct if_sdio_card *card, const u8 condition) |
| 315 | { |
| 316 | u8 status; |
| 317 | unsigned long timeout; |
| 318 | int ret = 0; |
| 319 | |
| 320 | timeout = jiffies + HZ; |
| 321 | while (1) { |
| 322 | status = sdio_readb(card->func, IF_SDIO_STATUS, &ret); |
Dan Williams | ca962557 | 2010-04-28 12:37:46 -0700 | [diff] [blame] | 323 | if (ret) |
| 324 | return ret; |
| 325 | if ((status & condition) == condition) |
Dan Williams | 96021f0 | 2010-04-15 13:27:44 -0700 | [diff] [blame] | 326 | break; |
| 327 | if (time_after(jiffies, timeout)) |
| 328 | return -ETIMEDOUT; |
| 329 | mdelay(1); |
| 330 | } |
| 331 | return ret; |
| 332 | } |
| 333 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 334 | static int if_sdio_card_to_host(struct if_sdio_card *card) |
| 335 | { |
| 336 | int ret; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 337 | u16 size, type, chunk; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 338 | |
| 339 | lbs_deb_enter(LBS_DEB_SDIO); |
| 340 | |
Bing Zhao | b136a14 | 2009-05-19 19:48:19 -0700 | [diff] [blame] | 341 | size = if_sdio_read_rx_len(card, &ret); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 342 | if (ret) |
| 343 | goto out; |
| 344 | |
| 345 | if (size < 4) { |
| 346 | lbs_deb_sdio("invalid packet size (%d bytes) from firmware\n", |
| 347 | (int)size); |
| 348 | ret = -EINVAL; |
| 349 | goto out; |
| 350 | } |
| 351 | |
Dan Williams | 96021f0 | 2010-04-15 13:27:44 -0700 | [diff] [blame] | 352 | ret = if_sdio_wait_status(card, IF_SDIO_IO_RDY); |
| 353 | if (ret) |
| 354 | goto out; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 355 | |
| 356 | /* |
| 357 | * The transfer must be in one transaction or the firmware |
Pierre Ossman | ad3868b | 2008-06-28 12:52:45 +0200 | [diff] [blame] | 358 | * goes suicidal. There's no way to guarantee that for all |
| 359 | * controllers, but we can at least try. |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 360 | */ |
Pierre Ossman | ad3868b | 2008-06-28 12:52:45 +0200 | [diff] [blame] | 361 | chunk = sdio_align_size(card->func, size); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 362 | |
| 363 | ret = sdio_readsb(card->func, card->buffer, card->ioport, chunk); |
| 364 | if (ret) |
| 365 | goto out; |
| 366 | |
| 367 | chunk = card->buffer[0] | (card->buffer[1] << 8); |
| 368 | type = card->buffer[2] | (card->buffer[3] << 8); |
| 369 | |
| 370 | lbs_deb_sdio("packet of type %d and size %d bytes\n", |
| 371 | (int)type, (int)chunk); |
| 372 | |
| 373 | if (chunk > size) { |
| 374 | lbs_deb_sdio("packet fragment (%d > %d)\n", |
| 375 | (int)chunk, (int)size); |
| 376 | ret = -EINVAL; |
| 377 | goto out; |
| 378 | } |
| 379 | |
| 380 | if (chunk < size) { |
| 381 | lbs_deb_sdio("packet fragment (%d < %d)\n", |
| 382 | (int)chunk, (int)size); |
| 383 | } |
| 384 | |
| 385 | switch (type) { |
| 386 | case MVMS_CMD: |
| 387 | ret = if_sdio_handle_cmd(card, card->buffer + 4, chunk - 4); |
| 388 | if (ret) |
| 389 | goto out; |
| 390 | break; |
| 391 | case MVMS_DAT: |
| 392 | ret = if_sdio_handle_data(card, card->buffer + 4, chunk - 4); |
| 393 | if (ret) |
| 394 | goto out; |
| 395 | break; |
| 396 | case MVMS_EVENT: |
| 397 | ret = if_sdio_handle_event(card, card->buffer + 4, chunk - 4); |
| 398 | if (ret) |
| 399 | goto out; |
| 400 | break; |
| 401 | default: |
| 402 | lbs_deb_sdio("invalid type (%d) from firmware\n", |
| 403 | (int)type); |
| 404 | ret = -EINVAL; |
| 405 | goto out; |
| 406 | } |
| 407 | |
| 408 | out: |
| 409 | if (ret) |
| 410 | lbs_pr_err("problem fetching packet from firmware\n"); |
| 411 | |
| 412 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 413 | |
| 414 | return ret; |
| 415 | } |
| 416 | |
| 417 | static void if_sdio_host_to_card_worker(struct work_struct *work) |
| 418 | { |
| 419 | struct if_sdio_card *card; |
| 420 | struct if_sdio_packet *packet; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 421 | int ret; |
| 422 | unsigned long flags; |
| 423 | |
| 424 | lbs_deb_enter(LBS_DEB_SDIO); |
| 425 | |
| 426 | card = container_of(work, struct if_sdio_card, packet_worker); |
| 427 | |
| 428 | while (1) { |
| 429 | spin_lock_irqsave(&card->lock, flags); |
| 430 | packet = card->packets; |
| 431 | if (packet) |
| 432 | card->packets = packet->next; |
| 433 | spin_unlock_irqrestore(&card->lock, flags); |
| 434 | |
| 435 | if (!packet) |
| 436 | break; |
| 437 | |
| 438 | sdio_claim_host(card->func); |
| 439 | |
Dan Williams | 96021f0 | 2010-04-15 13:27:44 -0700 | [diff] [blame] | 440 | ret = if_sdio_wait_status(card, IF_SDIO_IO_RDY); |
| 441 | if (ret == 0) { |
| 442 | ret = sdio_writesb(card->func, card->ioport, |
| 443 | packet->buffer, packet->nb); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 446 | if (ret) |
Dan Williams | 96021f0 | 2010-04-15 13:27:44 -0700 | [diff] [blame] | 447 | lbs_pr_err("error %d sending packet to firmware\n", ret); |
| 448 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 449 | sdio_release_host(card->func); |
| 450 | |
| 451 | kfree(packet); |
| 452 | } |
| 453 | |
| 454 | lbs_deb_leave(LBS_DEB_SDIO); |
| 455 | } |
| 456 | |
| 457 | /********************************************************************/ |
| 458 | /* Firmware */ |
| 459 | /********************************************************************/ |
| 460 | |
Dan Williams | 96021f0 | 2010-04-15 13:27:44 -0700 | [diff] [blame] | 461 | #define FW_DL_READY_STATUS (IF_SDIO_IO_RDY | IF_SDIO_DL_RDY) |
| 462 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 463 | static int if_sdio_prog_helper(struct if_sdio_card *card, |
| 464 | const struct firmware *fw) |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 465 | { |
| 466 | int ret; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 467 | unsigned long timeout; |
| 468 | u8 *chunk_buffer; |
| 469 | u32 chunk_size; |
David Woodhouse | 6dfff89 | 2008-05-23 18:37:51 +0100 | [diff] [blame] | 470 | const u8 *firmware; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 471 | size_t size; |
| 472 | |
| 473 | lbs_deb_enter(LBS_DEB_SDIO); |
| 474 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 475 | chunk_buffer = kzalloc(64, GFP_KERNEL); |
| 476 | if (!chunk_buffer) { |
| 477 | ret = -ENOMEM; |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 478 | goto out; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | sdio_claim_host(card->func); |
| 482 | |
| 483 | ret = sdio_set_block_size(card->func, 32); |
| 484 | if (ret) |
| 485 | goto release; |
| 486 | |
| 487 | firmware = fw->data; |
| 488 | size = fw->size; |
| 489 | |
| 490 | while (size) { |
Dan Williams | 96021f0 | 2010-04-15 13:27:44 -0700 | [diff] [blame] | 491 | ret = if_sdio_wait_status(card, FW_DL_READY_STATUS); |
| 492 | if (ret) |
| 493 | goto release; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 494 | |
Dan Williams | ac1a474 | 2010-04-15 13:32:58 -0700 | [diff] [blame] | 495 | /* On some platforms (like Davinci) the chip needs more time |
| 496 | * between helper blocks. |
| 497 | */ |
| 498 | mdelay(2); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 499 | |
| 500 | chunk_size = min(size, (size_t)60); |
| 501 | |
Holger Schurig | c2df2ef | 2007-12-07 15:30:44 +0000 | [diff] [blame] | 502 | *((__le32*)chunk_buffer) = cpu_to_le32(chunk_size); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 503 | memcpy(chunk_buffer + 4, firmware, chunk_size); |
| 504 | /* |
| 505 | lbs_deb_sdio("sending %d bytes chunk\n", chunk_size); |
| 506 | */ |
| 507 | ret = sdio_writesb(card->func, card->ioport, |
| 508 | chunk_buffer, 64); |
| 509 | if (ret) |
| 510 | goto release; |
| 511 | |
| 512 | firmware += chunk_size; |
| 513 | size -= chunk_size; |
| 514 | } |
| 515 | |
| 516 | /* an empty block marks the end of the transfer */ |
| 517 | memset(chunk_buffer, 0, 4); |
| 518 | ret = sdio_writesb(card->func, card->ioport, chunk_buffer, 64); |
| 519 | if (ret) |
| 520 | goto release; |
| 521 | |
| 522 | lbs_deb_sdio("waiting for helper to boot...\n"); |
| 523 | |
| 524 | /* wait for the helper to boot by looking at the size register */ |
| 525 | timeout = jiffies + HZ; |
| 526 | while (1) { |
| 527 | u16 req_size; |
| 528 | |
| 529 | req_size = sdio_readb(card->func, IF_SDIO_RD_BASE, &ret); |
| 530 | if (ret) |
| 531 | goto release; |
| 532 | |
| 533 | req_size |= sdio_readb(card->func, IF_SDIO_RD_BASE + 1, &ret) << 8; |
| 534 | if (ret) |
| 535 | goto release; |
| 536 | |
| 537 | if (req_size != 0) |
| 538 | break; |
| 539 | |
| 540 | if (time_after(jiffies, timeout)) { |
| 541 | ret = -ETIMEDOUT; |
| 542 | goto release; |
| 543 | } |
| 544 | |
| 545 | msleep(10); |
| 546 | } |
| 547 | |
| 548 | ret = 0; |
| 549 | |
| 550 | release: |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 551 | sdio_release_host(card->func); |
| 552 | kfree(chunk_buffer); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 553 | |
| 554 | out: |
| 555 | if (ret) |
| 556 | lbs_pr_err("failed to load helper firmware\n"); |
| 557 | |
| 558 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 559 | return ret; |
| 560 | } |
| 561 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 562 | static int if_sdio_prog_real(struct if_sdio_card *card, |
| 563 | const struct firmware *fw) |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 564 | { |
| 565 | int ret; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 566 | unsigned long timeout; |
| 567 | u8 *chunk_buffer; |
| 568 | u32 chunk_size; |
David Woodhouse | 6dfff89 | 2008-05-23 18:37:51 +0100 | [diff] [blame] | 569 | const u8 *firmware; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 570 | size_t size, req_size; |
| 571 | |
| 572 | lbs_deb_enter(LBS_DEB_SDIO); |
| 573 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 574 | chunk_buffer = kzalloc(512, GFP_KERNEL); |
| 575 | if (!chunk_buffer) { |
| 576 | ret = -ENOMEM; |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 577 | goto out; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | sdio_claim_host(card->func); |
| 581 | |
| 582 | ret = sdio_set_block_size(card->func, 32); |
| 583 | if (ret) |
| 584 | goto release; |
| 585 | |
| 586 | firmware = fw->data; |
| 587 | size = fw->size; |
| 588 | |
| 589 | while (size) { |
Dan Williams | 96021f0 | 2010-04-15 13:27:44 -0700 | [diff] [blame] | 590 | ret = if_sdio_wait_status(card, FW_DL_READY_STATUS); |
| 591 | if (ret) |
| 592 | goto release; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 593 | |
| 594 | req_size = sdio_readb(card->func, IF_SDIO_RD_BASE, &ret); |
| 595 | if (ret) |
| 596 | goto release; |
| 597 | |
| 598 | req_size |= sdio_readb(card->func, IF_SDIO_RD_BASE + 1, &ret) << 8; |
| 599 | if (ret) |
| 600 | goto release; |
| 601 | /* |
| 602 | lbs_deb_sdio("firmware wants %d bytes\n", (int)req_size); |
| 603 | */ |
| 604 | if (req_size == 0) { |
| 605 | lbs_deb_sdio("firmware helper gave up early\n"); |
| 606 | ret = -EIO; |
| 607 | goto release; |
| 608 | } |
| 609 | |
| 610 | if (req_size & 0x01) { |
| 611 | lbs_deb_sdio("firmware helper signalled error\n"); |
| 612 | ret = -EIO; |
| 613 | goto release; |
| 614 | } |
| 615 | |
| 616 | if (req_size > size) |
| 617 | req_size = size; |
| 618 | |
| 619 | while (req_size) { |
| 620 | chunk_size = min(req_size, (size_t)512); |
| 621 | |
| 622 | memcpy(chunk_buffer, firmware, chunk_size); |
| 623 | /* |
| 624 | lbs_deb_sdio("sending %d bytes (%d bytes) chunk\n", |
| 625 | chunk_size, (chunk_size + 31) / 32 * 32); |
| 626 | */ |
| 627 | ret = sdio_writesb(card->func, card->ioport, |
Ilpo Järvinen | 2382792 | 2008-12-13 21:33:13 +0200 | [diff] [blame] | 628 | chunk_buffer, roundup(chunk_size, 32)); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 629 | if (ret) |
| 630 | goto release; |
| 631 | |
| 632 | firmware += chunk_size; |
| 633 | size -= chunk_size; |
| 634 | req_size -= chunk_size; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | ret = 0; |
| 639 | |
| 640 | lbs_deb_sdio("waiting for firmware to boot...\n"); |
| 641 | |
| 642 | /* wait for the firmware to boot */ |
| 643 | timeout = jiffies + HZ; |
| 644 | while (1) { |
| 645 | u16 scratch; |
| 646 | |
| 647 | scratch = if_sdio_read_scratch(card, &ret); |
| 648 | if (ret) |
| 649 | goto release; |
| 650 | |
| 651 | if (scratch == IF_SDIO_FIRMWARE_OK) |
| 652 | break; |
| 653 | |
| 654 | if (time_after(jiffies, timeout)) { |
| 655 | ret = -ETIMEDOUT; |
| 656 | goto release; |
| 657 | } |
| 658 | |
| 659 | msleep(10); |
| 660 | } |
| 661 | |
| 662 | ret = 0; |
| 663 | |
| 664 | release: |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 665 | sdio_release_host(card->func); |
| 666 | kfree(chunk_buffer); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 667 | |
| 668 | out: |
| 669 | if (ret) |
| 670 | lbs_pr_err("failed to load firmware\n"); |
| 671 | |
| 672 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 673 | return ret; |
| 674 | } |
| 675 | |
| 676 | static int if_sdio_prog_firmware(struct if_sdio_card *card) |
| 677 | { |
| 678 | int ret; |
| 679 | u16 scratch; |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 680 | const struct firmware *helper = NULL; |
| 681 | const struct firmware *mainfw = NULL; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 682 | |
| 683 | lbs_deb_enter(LBS_DEB_SDIO); |
| 684 | |
| 685 | sdio_claim_host(card->func); |
| 686 | scratch = if_sdio_read_scratch(card, &ret); |
| 687 | sdio_release_host(card->func); |
| 688 | |
| 689 | if (ret) |
| 690 | goto out; |
| 691 | |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 692 | lbs_deb_sdio("firmware status = %#x\n", scratch); |
| 693 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 694 | if (scratch == IF_SDIO_FIRMWARE_OK) { |
| 695 | lbs_deb_sdio("firmware already loaded\n"); |
| 696 | goto success; |
| 697 | } |
| 698 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 699 | ret = lbs_get_firmware(&card->func->dev, lbs_helper_name, lbs_fw_name, |
| 700 | card->model, &fw_table[0], &helper, &mainfw); |
| 701 | if (ret) { |
| 702 | lbs_pr_err("failed to find firmware (%d)\n", ret); |
| 703 | goto out; |
| 704 | } |
| 705 | |
| 706 | ret = if_sdio_prog_helper(card, helper); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 707 | if (ret) |
| 708 | goto out; |
| 709 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 710 | ret = if_sdio_prog_real(card, mainfw); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 711 | if (ret) |
| 712 | goto out; |
| 713 | |
| 714 | success: |
Bing Zhao | d26285f8 | 2009-05-19 19:48:20 -0700 | [diff] [blame] | 715 | sdio_claim_host(card->func); |
| 716 | sdio_set_block_size(card->func, IF_SDIO_BLOCK_SIZE); |
| 717 | sdio_release_host(card->func); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 718 | ret = 0; |
| 719 | |
| 720 | out: |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 721 | if (helper) |
| 722 | release_firmware(helper); |
| 723 | if (mainfw) |
| 724 | release_firmware(mainfw); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 725 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 726 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 727 | return ret; |
| 728 | } |
| 729 | |
| 730 | /*******************************************************************/ |
| 731 | /* Libertas callbacks */ |
| 732 | /*******************************************************************/ |
| 733 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 734 | static int if_sdio_host_to_card(struct lbs_private *priv, |
| 735 | u8 type, u8 *buf, u16 nb) |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 736 | { |
| 737 | int ret; |
| 738 | struct if_sdio_card *card; |
| 739 | struct if_sdio_packet *packet, *cur; |
| 740 | u16 size; |
| 741 | unsigned long flags; |
| 742 | |
| 743 | lbs_deb_enter_args(LBS_DEB_SDIO, "type %d, bytes %d", type, nb); |
| 744 | |
| 745 | card = priv->card; |
| 746 | |
| 747 | if (nb > (65536 - sizeof(struct if_sdio_packet) - 4)) { |
| 748 | ret = -EINVAL; |
| 749 | goto out; |
| 750 | } |
| 751 | |
| 752 | /* |
| 753 | * The transfer must be in one transaction or the firmware |
Pierre Ossman | ad3868b | 2008-06-28 12:52:45 +0200 | [diff] [blame] | 754 | * goes suicidal. There's no way to guarantee that for all |
| 755 | * controllers, but we can at least try. |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 756 | */ |
Pierre Ossman | ad3868b | 2008-06-28 12:52:45 +0200 | [diff] [blame] | 757 | size = sdio_align_size(card->func, nb + 4); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 758 | |
| 759 | packet = kzalloc(sizeof(struct if_sdio_packet) + size, |
| 760 | GFP_ATOMIC); |
| 761 | if (!packet) { |
| 762 | ret = -ENOMEM; |
| 763 | goto out; |
| 764 | } |
| 765 | |
| 766 | packet->next = NULL; |
| 767 | packet->nb = size; |
| 768 | |
| 769 | /* |
| 770 | * SDIO specific header. |
| 771 | */ |
| 772 | packet->buffer[0] = (nb + 4) & 0xff; |
| 773 | packet->buffer[1] = ((nb + 4) >> 8) & 0xff; |
| 774 | packet->buffer[2] = type; |
| 775 | packet->buffer[3] = 0; |
| 776 | |
| 777 | memcpy(packet->buffer + 4, buf, nb); |
| 778 | |
| 779 | spin_lock_irqsave(&card->lock, flags); |
| 780 | |
| 781 | if (!card->packets) |
| 782 | card->packets = packet; |
| 783 | else { |
| 784 | cur = card->packets; |
| 785 | while (cur->next) |
| 786 | cur = cur->next; |
| 787 | cur->next = packet; |
| 788 | } |
| 789 | |
| 790 | switch (type) { |
| 791 | case MVMS_CMD: |
| 792 | priv->dnld_sent = DNLD_CMD_SENT; |
| 793 | break; |
| 794 | case MVMS_DAT: |
| 795 | priv->dnld_sent = DNLD_DATA_SENT; |
| 796 | break; |
| 797 | default: |
| 798 | lbs_deb_sdio("unknown packet type %d\n", (int)type); |
| 799 | } |
| 800 | |
| 801 | spin_unlock_irqrestore(&card->lock, flags); |
| 802 | |
Dan Williams | 9b02f41 | 2009-02-20 12:27:38 -0500 | [diff] [blame] | 803 | queue_work(card->workqueue, &card->packet_worker); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 804 | |
| 805 | ret = 0; |
| 806 | |
| 807 | out: |
| 808 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 809 | |
| 810 | return ret; |
| 811 | } |
| 812 | |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 813 | static int if_sdio_enter_deep_sleep(struct lbs_private *priv) |
| 814 | { |
| 815 | int ret = -1; |
| 816 | struct cmd_header cmd; |
| 817 | |
| 818 | memset(&cmd, 0, sizeof(cmd)); |
| 819 | |
| 820 | lbs_deb_sdio("send DEEP_SLEEP command\n"); |
| 821 | ret = __lbs_cmd(priv, CMD_802_11_DEEP_SLEEP, &cmd, sizeof(cmd), |
| 822 | lbs_cmd_copyback, (unsigned long) &cmd); |
| 823 | if (ret) |
| 824 | lbs_pr_err("DEEP_SLEEP cmd failed\n"); |
| 825 | |
| 826 | mdelay(200); |
| 827 | return ret; |
| 828 | } |
| 829 | |
| 830 | static int if_sdio_exit_deep_sleep(struct lbs_private *priv) |
| 831 | { |
| 832 | struct if_sdio_card *card = priv->card; |
| 833 | int ret = -1; |
| 834 | |
| 835 | lbs_deb_enter(LBS_DEB_SDIO); |
| 836 | sdio_claim_host(card->func); |
| 837 | |
| 838 | sdio_writeb(card->func, HOST_POWER_UP, CONFIGURATION_REG, &ret); |
| 839 | if (ret) |
| 840 | lbs_pr_err("sdio_writeb failed!\n"); |
| 841 | |
| 842 | sdio_release_host(card->func); |
| 843 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 844 | return ret; |
| 845 | } |
| 846 | |
| 847 | static int if_sdio_reset_deep_sleep_wakeup(struct lbs_private *priv) |
| 848 | { |
| 849 | struct if_sdio_card *card = priv->card; |
| 850 | int ret = -1; |
| 851 | |
| 852 | lbs_deb_enter(LBS_DEB_SDIO); |
| 853 | sdio_claim_host(card->func); |
| 854 | |
| 855 | sdio_writeb(card->func, 0, CONFIGURATION_REG, &ret); |
| 856 | if (ret) |
| 857 | lbs_pr_err("sdio_writeb failed!\n"); |
| 858 | |
| 859 | sdio_release_host(card->func); |
| 860 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 861 | return ret; |
| 862 | |
| 863 | } |
| 864 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 865 | /*******************************************************************/ |
| 866 | /* SDIO callbacks */ |
| 867 | /*******************************************************************/ |
| 868 | |
| 869 | static void if_sdio_interrupt(struct sdio_func *func) |
| 870 | { |
| 871 | int ret; |
| 872 | struct if_sdio_card *card; |
| 873 | u8 cause; |
| 874 | |
| 875 | lbs_deb_enter(LBS_DEB_SDIO); |
| 876 | |
| 877 | card = sdio_get_drvdata(func); |
| 878 | |
| 879 | cause = sdio_readb(card->func, IF_SDIO_H_INT_STATUS, &ret); |
| 880 | if (ret) |
| 881 | goto out; |
| 882 | |
| 883 | lbs_deb_sdio("interrupt: 0x%X\n", (unsigned)cause); |
| 884 | |
| 885 | sdio_writeb(card->func, ~cause, IF_SDIO_H_INT_STATUS, &ret); |
| 886 | if (ret) |
| 887 | goto out; |
| 888 | |
| 889 | /* |
| 890 | * Ignore the define name, this really means the card has |
| 891 | * successfully received the command. |
| 892 | */ |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 893 | card->priv->is_activity_detected = 1; |
David Woodhouse | e775ed7 | 2007-12-06 14:36:11 +0000 | [diff] [blame] | 894 | if (cause & IF_SDIO_H_INT_DNLD) |
| 895 | lbs_host_to_card_done(card->priv); |
| 896 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 897 | |
| 898 | if (cause & IF_SDIO_H_INT_UPLD) { |
| 899 | ret = if_sdio_card_to_host(card); |
| 900 | if (ret) |
| 901 | goto out; |
| 902 | } |
| 903 | |
| 904 | ret = 0; |
| 905 | |
| 906 | out: |
| 907 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 908 | } |
| 909 | |
| 910 | static int if_sdio_probe(struct sdio_func *func, |
| 911 | const struct sdio_device_id *id) |
| 912 | { |
| 913 | struct if_sdio_card *card; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 914 | struct lbs_private *priv; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 915 | int ret, i; |
| 916 | unsigned int model; |
| 917 | struct if_sdio_packet *packet; |
Daniel Mack | 8a64c0f | 2010-04-06 10:52:44 +0200 | [diff] [blame] | 918 | struct mmc_host *host = func->card->host; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 919 | |
| 920 | lbs_deb_enter(LBS_DEB_SDIO); |
| 921 | |
| 922 | for (i = 0;i < func->card->num_info;i++) { |
| 923 | if (sscanf(func->card->info[i], |
| 924 | "802.11 SDIO ID: %x", &model) == 1) |
| 925 | break; |
| 926 | if (sscanf(func->card->info[i], |
| 927 | "ID: %x", &model) == 1) |
| 928 | break; |
Bing Zhao | e70a5ac | 2009-05-19 19:48:18 -0700 | [diff] [blame] | 929 | if (!strcmp(func->card->info[i], "IBIS Wireless SDIO Card")) { |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 930 | model = MODEL_8385; |
Bing Zhao | e70a5ac | 2009-05-19 19:48:18 -0700 | [diff] [blame] | 931 | break; |
| 932 | } |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | if (i == func->card->num_info) { |
| 936 | lbs_pr_err("unable to identify card model\n"); |
| 937 | return -ENODEV; |
| 938 | } |
| 939 | |
| 940 | card = kzalloc(sizeof(struct if_sdio_card), GFP_KERNEL); |
| 941 | if (!card) |
| 942 | return -ENOMEM; |
| 943 | |
| 944 | card->func = func; |
| 945 | card->model = model; |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 946 | |
| 947 | switch (card->model) { |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 948 | case MODEL_8385: |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 949 | card->scratch_reg = IF_SDIO_SCRATCH_OLD; |
| 950 | break; |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 951 | case MODEL_8686: |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 952 | card->scratch_reg = IF_SDIO_SCRATCH; |
| 953 | break; |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 954 | case MODEL_8688: |
Bing Zhao | 2c7e579 | 2009-05-21 11:32:34 -0700 | [diff] [blame] | 955 | default: /* for newer chipsets */ |
| 956 | card->scratch_reg = IF_SDIO_FW_STATUS; |
| 957 | break; |
| 958 | } |
| 959 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 960 | spin_lock_init(&card->lock); |
Dan Williams | 9b02f41 | 2009-02-20 12:27:38 -0500 | [diff] [blame] | 961 | card->workqueue = create_workqueue("libertas_sdio"); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 962 | INIT_WORK(&card->packet_worker, if_sdio_host_to_card_worker); |
| 963 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 964 | /* Check if we support this card */ |
| 965 | for (i = 0; i < ARRAY_SIZE(fw_table); i++) { |
| 966 | if (card->model == fw_table[i].model) |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 967 | break; |
| 968 | } |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 969 | if (i == ARRAY_SIZE(fw_table)) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 970 | lbs_pr_err("unknown card model 0x%x\n", card->model); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 971 | ret = -ENODEV; |
| 972 | goto free; |
| 973 | } |
| 974 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 975 | sdio_claim_host(func); |
| 976 | |
| 977 | ret = sdio_enable_func(func); |
| 978 | if (ret) |
| 979 | goto release; |
| 980 | |
| 981 | ret = sdio_claim_irq(func, if_sdio_interrupt); |
| 982 | if (ret) |
| 983 | goto disable; |
| 984 | |
Daniel Mack | 8a64c0f | 2010-04-06 10:52:44 +0200 | [diff] [blame] | 985 | /* For 1-bit transfers to the 8686 model, we need to enable the |
| 986 | * interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0 |
| 987 | * bit to allow access to non-vendor registers. */ |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 988 | if ((card->model == MODEL_8686) && |
Daniel Mack | 8a64c0f | 2010-04-06 10:52:44 +0200 | [diff] [blame] | 989 | (host->caps & MMC_CAP_SDIO_IRQ) && |
| 990 | (host->ios.bus_width == MMC_BUS_WIDTH_1)) { |
| 991 | u8 reg; |
| 992 | |
| 993 | func->card->quirks |= MMC_QUIRK_LENIENT_FN0; |
| 994 | reg = sdio_f0_readb(func, SDIO_CCCR_IF, &ret); |
| 995 | if (ret) |
| 996 | goto release_int; |
| 997 | |
| 998 | reg |= SDIO_BUS_ECSI; |
| 999 | sdio_f0_writeb(func, reg, SDIO_CCCR_IF, &ret); |
| 1000 | if (ret) |
| 1001 | goto release_int; |
| 1002 | } |
| 1003 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1004 | card->ioport = sdio_readb(func, IF_SDIO_IOPORT, &ret); |
| 1005 | if (ret) |
| 1006 | goto release_int; |
| 1007 | |
| 1008 | card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 1, &ret) << 8; |
| 1009 | if (ret) |
| 1010 | goto release_int; |
| 1011 | |
| 1012 | card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 2, &ret) << 16; |
| 1013 | if (ret) |
| 1014 | goto release_int; |
| 1015 | |
| 1016 | sdio_release_host(func); |
| 1017 | |
| 1018 | sdio_set_drvdata(func, card); |
| 1019 | |
| 1020 | lbs_deb_sdio("class = 0x%X, vendor = 0x%X, " |
| 1021 | "device = 0x%X, model = 0x%X, ioport = 0x%X\n", |
| 1022 | func->class, func->vendor, func->device, |
| 1023 | model, (unsigned)card->ioport); |
| 1024 | |
| 1025 | ret = if_sdio_prog_firmware(card); |
| 1026 | if (ret) |
| 1027 | goto reclaim; |
| 1028 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1029 | priv = lbs_add_card(card, &func->dev); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1030 | if (!priv) { |
| 1031 | ret = -ENOMEM; |
| 1032 | goto reclaim; |
| 1033 | } |
| 1034 | |
| 1035 | card->priv = priv; |
| 1036 | |
| 1037 | priv->card = card; |
| 1038 | priv->hw_host_to_card = if_sdio_host_to_card; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 1039 | priv->enter_deep_sleep = if_sdio_enter_deep_sleep; |
| 1040 | priv->exit_deep_sleep = if_sdio_exit_deep_sleep; |
| 1041 | priv->reset_deep_sleep_wakeup = if_sdio_reset_deep_sleep_wakeup; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1042 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1043 | priv->fw_ready = 1; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1044 | |
Bing Zhao | b136a14 | 2009-05-19 19:48:19 -0700 | [diff] [blame] | 1045 | sdio_claim_host(func); |
| 1046 | |
| 1047 | /* |
| 1048 | * Get rx_unit if the chip is SD8688 or newer. |
| 1049 | * SD8385 & SD8686 do not have rx_unit. |
| 1050 | */ |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 1051 | if ((card->model != MODEL_8385) |
| 1052 | && (card->model != MODEL_8686)) |
Bing Zhao | b136a14 | 2009-05-19 19:48:19 -0700 | [diff] [blame] | 1053 | card->rx_unit = if_sdio_read_rx_unit(card); |
| 1054 | else |
| 1055 | card->rx_unit = 0; |
| 1056 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1057 | /* |
| 1058 | * Enable interrupts now that everything is set up |
| 1059 | */ |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1060 | sdio_writeb(func, 0x0f, IF_SDIO_H_INT_MASK, &ret); |
| 1061 | sdio_release_host(func); |
| 1062 | if (ret) |
| 1063 | goto reclaim; |
| 1064 | |
Bing Zhao | d26285f8 | 2009-05-19 19:48:20 -0700 | [diff] [blame] | 1065 | /* |
| 1066 | * FUNC_INIT is required for SD8688 WLAN/BT multiple functions |
| 1067 | */ |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 1068 | if (card->model == MODEL_8688) { |
Bing Zhao | 6bc61f4 | 2009-06-01 18:04:36 -0700 | [diff] [blame] | 1069 | struct cmd_header cmd; |
| 1070 | |
| 1071 | memset(&cmd, 0, sizeof(cmd)); |
| 1072 | |
| 1073 | lbs_deb_sdio("send function INIT command\n"); |
| 1074 | if (__lbs_cmd(priv, CMD_FUNC_INIT, &cmd, sizeof(cmd), |
| 1075 | lbs_cmd_copyback, (unsigned long) &cmd)) |
| 1076 | lbs_pr_alert("CMD_FUNC_INIT cmd failed\n"); |
| 1077 | } |
Bing Zhao | d26285f8 | 2009-05-19 19:48:20 -0700 | [diff] [blame] | 1078 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1079 | ret = lbs_start_card(priv); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1080 | if (ret) |
| 1081 | goto err_activate_card; |
| 1082 | |
| 1083 | out: |
| 1084 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 1085 | |
| 1086 | return ret; |
| 1087 | |
| 1088 | err_activate_card: |
Dan Williams | 9b02f41 | 2009-02-20 12:27:38 -0500 | [diff] [blame] | 1089 | flush_workqueue(card->workqueue); |
| 1090 | lbs_remove_card(priv); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1091 | reclaim: |
| 1092 | sdio_claim_host(func); |
| 1093 | release_int: |
| 1094 | sdio_release_irq(func); |
| 1095 | disable: |
| 1096 | sdio_disable_func(func); |
| 1097 | release: |
| 1098 | sdio_release_host(func); |
| 1099 | free: |
Dan Williams | 9b02f41 | 2009-02-20 12:27:38 -0500 | [diff] [blame] | 1100 | destroy_workqueue(card->workqueue); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1101 | while (card->packets) { |
| 1102 | packet = card->packets; |
| 1103 | card->packets = card->packets->next; |
| 1104 | kfree(packet); |
| 1105 | } |
| 1106 | |
| 1107 | kfree(card); |
| 1108 | |
| 1109 | goto out; |
| 1110 | } |
| 1111 | |
| 1112 | static void if_sdio_remove(struct sdio_func *func) |
| 1113 | { |
| 1114 | struct if_sdio_card *card; |
| 1115 | struct if_sdio_packet *packet; |
| 1116 | |
| 1117 | lbs_deb_enter(LBS_DEB_SDIO); |
| 1118 | |
| 1119 | card = sdio_get_drvdata(func); |
| 1120 | |
Dan Williams | 3d32a58 | 2010-08-07 21:15:52 -0500 | [diff] [blame^] | 1121 | if (user_rmmod && (card->model == MODEL_8688)) { |
Bing Zhao | 6bc61f4 | 2009-06-01 18:04:36 -0700 | [diff] [blame] | 1122 | /* |
| 1123 | * FUNC_SHUTDOWN is required for SD8688 WLAN/BT |
| 1124 | * multiple functions |
| 1125 | */ |
| 1126 | struct cmd_header cmd; |
| 1127 | |
| 1128 | memset(&cmd, 0, sizeof(cmd)); |
| 1129 | |
| 1130 | lbs_deb_sdio("send function SHUTDOWN command\n"); |
| 1131 | if (__lbs_cmd(card->priv, CMD_FUNC_SHUTDOWN, |
| 1132 | &cmd, sizeof(cmd), lbs_cmd_copyback, |
| 1133 | (unsigned long) &cmd)) |
| 1134 | lbs_pr_alert("CMD_FUNC_SHUTDOWN cmd failed\n"); |
| 1135 | } |
Bing Zhao | d26285f8 | 2009-05-19 19:48:20 -0700 | [diff] [blame] | 1136 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1137 | |
| 1138 | lbs_deb_sdio("call remove card\n"); |
Bing Zhao | 6bc61f4 | 2009-06-01 18:04:36 -0700 | [diff] [blame] | 1139 | lbs_stop_card(card->priv); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1140 | lbs_remove_card(card->priv); |
Andrey Yurovsky | 23b149c | 2009-06-17 19:15:19 -0700 | [diff] [blame] | 1141 | card->priv->surpriseremoved = 1; |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1142 | |
Dan Williams | 9b02f41 | 2009-02-20 12:27:38 -0500 | [diff] [blame] | 1143 | flush_workqueue(card->workqueue); |
| 1144 | destroy_workqueue(card->workqueue); |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1145 | |
| 1146 | sdio_claim_host(func); |
| 1147 | sdio_release_irq(func); |
| 1148 | sdio_disable_func(func); |
| 1149 | sdio_release_host(func); |
| 1150 | |
| 1151 | while (card->packets) { |
| 1152 | packet = card->packets; |
| 1153 | card->packets = card->packets->next; |
| 1154 | kfree(packet); |
| 1155 | } |
| 1156 | |
| 1157 | kfree(card); |
| 1158 | |
| 1159 | lbs_deb_leave(LBS_DEB_SDIO); |
| 1160 | } |
| 1161 | |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 1162 | static int if_sdio_suspend(struct device *dev) |
| 1163 | { |
| 1164 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 1165 | int ret; |
| 1166 | struct if_sdio_card *card = sdio_get_drvdata(func); |
| 1167 | |
| 1168 | mmc_pm_flag_t flags = sdio_get_host_pm_caps(func); |
| 1169 | |
| 1170 | lbs_pr_info("%s: suspend: PM flags = 0x%x\n", |
| 1171 | sdio_func_id(func), flags); |
| 1172 | |
| 1173 | /* If we aren't being asked to wake on anything, we should bail out |
| 1174 | * and let the SD stack power down the card. |
| 1175 | */ |
| 1176 | if (card->priv->wol_criteria == EHS_REMOVE_WAKEUP) { |
| 1177 | lbs_pr_info("Suspend without wake params -- " |
| 1178 | "powering down card."); |
| 1179 | return -ENOSYS; |
| 1180 | } |
| 1181 | |
| 1182 | if (!(flags & MMC_PM_KEEP_POWER)) { |
| 1183 | lbs_pr_err("%s: cannot remain alive while host is suspended\n", |
| 1184 | sdio_func_id(func)); |
| 1185 | return -ENOSYS; |
| 1186 | } |
| 1187 | |
| 1188 | ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); |
| 1189 | if (ret) |
| 1190 | return ret; |
| 1191 | |
| 1192 | ret = lbs_suspend(card->priv); |
| 1193 | if (ret) |
| 1194 | return ret; |
| 1195 | |
| 1196 | return sdio_set_host_pm_flags(func, MMC_PM_WAKE_SDIO_IRQ); |
| 1197 | } |
| 1198 | |
| 1199 | static int if_sdio_resume(struct device *dev) |
| 1200 | { |
| 1201 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 1202 | struct if_sdio_card *card = sdio_get_drvdata(func); |
| 1203 | int ret; |
| 1204 | |
| 1205 | lbs_pr_info("%s: resume: we're back\n", sdio_func_id(func)); |
| 1206 | |
| 1207 | ret = lbs_resume(card->priv); |
| 1208 | |
| 1209 | return ret; |
| 1210 | } |
| 1211 | |
| 1212 | static const struct dev_pm_ops if_sdio_pm_ops = { |
| 1213 | .suspend = if_sdio_suspend, |
| 1214 | .resume = if_sdio_resume, |
| 1215 | }; |
| 1216 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1217 | static struct sdio_driver if_sdio_driver = { |
| 1218 | .name = "libertas_sdio", |
| 1219 | .id_table = if_sdio_ids, |
| 1220 | .probe = if_sdio_probe, |
| 1221 | .remove = if_sdio_remove, |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 1222 | .drv = { |
| 1223 | .pm = &if_sdio_pm_ops, |
| 1224 | }, |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1225 | }; |
| 1226 | |
| 1227 | /*******************************************************************/ |
| 1228 | /* Module functions */ |
| 1229 | /*******************************************************************/ |
| 1230 | |
Andres Salomon | 4fb910f | 2007-11-20 17:43:45 -0500 | [diff] [blame] | 1231 | static int __init if_sdio_init_module(void) |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1232 | { |
| 1233 | int ret = 0; |
| 1234 | |
| 1235 | lbs_deb_enter(LBS_DEB_SDIO); |
| 1236 | |
| 1237 | printk(KERN_INFO "libertas_sdio: Libertas SDIO driver\n"); |
| 1238 | printk(KERN_INFO "libertas_sdio: Copyright Pierre Ossman\n"); |
| 1239 | |
| 1240 | ret = sdio_register_driver(&if_sdio_driver); |
| 1241 | |
Bing Zhao | 6bc61f4 | 2009-06-01 18:04:36 -0700 | [diff] [blame] | 1242 | /* Clear the flag in case user removes the card. */ |
| 1243 | user_rmmod = 0; |
| 1244 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1245 | lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); |
| 1246 | |
| 1247 | return ret; |
| 1248 | } |
| 1249 | |
Andres Salomon | 4fb910f | 2007-11-20 17:43:45 -0500 | [diff] [blame] | 1250 | static void __exit if_sdio_exit_module(void) |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1251 | { |
| 1252 | lbs_deb_enter(LBS_DEB_SDIO); |
| 1253 | |
Bing Zhao | 6bc61f4 | 2009-06-01 18:04:36 -0700 | [diff] [blame] | 1254 | /* Set the flag as user is removing this module. */ |
| 1255 | user_rmmod = 1; |
Bing Zhao | d26285f8 | 2009-05-19 19:48:20 -0700 | [diff] [blame] | 1256 | |
Pierre Ossman | 727c26e | 2007-10-17 22:24:24 +0200 | [diff] [blame] | 1257 | sdio_unregister_driver(&if_sdio_driver); |
| 1258 | |
| 1259 | lbs_deb_leave(LBS_DEB_SDIO); |
| 1260 | } |
| 1261 | |
| 1262 | module_init(if_sdio_init_module); |
| 1263 | module_exit(if_sdio_exit_module); |
| 1264 | |
| 1265 | MODULE_DESCRIPTION("Libertas SDIO WLAN Driver"); |
| 1266 | MODULE_AUTHOR("Pierre Ossman"); |
| 1267 | MODULE_LICENSE("GPL"); |