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