Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * iwmc3200top - Intel Wireless MultiCom 3200 Top Driver |
| 3 | * drivers/misc/iwmc3200top/main.c |
| 4 | * |
| 5 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License version |
| 9 | * 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 | * 02110-1301, USA. |
| 20 | * |
| 21 | * |
| 22 | * Author Name: Maxim Grabarnik <maxim.grabarnink@intel.com> |
| 23 | * - |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/debugfs.h> |
| 31 | #include <linux/mmc/sdio_ids.h> |
| 32 | #include <linux/mmc/sdio_func.h> |
| 33 | #include <linux/mmc/sdio.h> |
| 34 | |
| 35 | #include "iwmc3200top.h" |
| 36 | #include "log.h" |
| 37 | #include "fw-msg.h" |
| 38 | #include "debugfs.h" |
| 39 | |
| 40 | |
| 41 | #define DRIVER_DESCRIPTION "Intel(R) IWMC 3200 Top Driver" |
| 42 | #define DRIVER_COPYRIGHT "Copyright (c) 2008 Intel Corporation." |
| 43 | |
| 44 | #define IWMCT_VERSION "0.1.62" |
| 45 | |
| 46 | #ifdef REPOSITORY_LABEL |
| 47 | #define RL REPOSITORY_LABEL |
| 48 | #else |
| 49 | #define RL local |
| 50 | #endif |
| 51 | |
| 52 | #ifdef CONFIG_IWMC3200TOP_DEBUG |
| 53 | #define VD "-d" |
| 54 | #else |
| 55 | #define VD |
| 56 | #endif |
| 57 | |
| 58 | #define DRIVER_VERSION IWMCT_VERSION "-" __stringify(RL) VD |
| 59 | |
| 60 | MODULE_DESCRIPTION(DRIVER_DESCRIPTION); |
| 61 | MODULE_VERSION(DRIVER_VERSION); |
| 62 | MODULE_LICENSE("GPL"); |
| 63 | MODULE_AUTHOR(DRIVER_COPYRIGHT); |
| 64 | |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 65 | /* |
| 66 | * This workers main task is to wait for OP_OPR_ALIVE |
| 67 | * from TOP FW until ALIVE_MSG_TIMOUT timeout is elapsed. |
| 68 | * When OP_OPR_ALIVE received it will issue |
| 69 | * a call to "bus_rescan_devices". |
| 70 | */ |
| 71 | static void iwmct_rescan_worker(struct work_struct *ws) |
| 72 | { |
| 73 | struct iwmct_priv *priv; |
| 74 | int ret; |
| 75 | |
| 76 | priv = container_of(ws, struct iwmct_priv, bus_rescan_worker); |
| 77 | |
| 78 | LOG_INFO(priv, FW_MSG, "Calling bus_rescan\n"); |
| 79 | |
| 80 | ret = bus_rescan_devices(priv->func->dev.bus); |
| 81 | if (ret < 0) |
| 82 | LOG_INFO(priv, FW_DOWNLOAD, "bus_rescan_devices FAILED!!!\n"); |
| 83 | } |
| 84 | |
| 85 | static void op_top_message(struct iwmct_priv *priv, struct top_msg *msg) |
| 86 | { |
| 87 | switch (msg->hdr.opcode) { |
| 88 | case OP_OPR_ALIVE: |
| 89 | LOG_INFO(priv, FW_MSG, "Got ALIVE from device, wake rescan\n"); |
| 90 | queue_work(priv->bus_rescan_wq, &priv->bus_rescan_worker); |
| 91 | break; |
| 92 | default: |
| 93 | LOG_INFO(priv, FW_MSG, "Received msg opcode 0x%X\n", |
| 94 | msg->hdr.opcode); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | |
| 100 | static void handle_top_message(struct iwmct_priv *priv, u8 *buf, int len) |
| 101 | { |
| 102 | struct top_msg *msg; |
| 103 | |
| 104 | msg = (struct top_msg *)buf; |
| 105 | |
| 106 | if (msg->hdr.type != COMM_TYPE_D2H) { |
| 107 | LOG_ERROR(priv, FW_MSG, |
| 108 | "Message from TOP with invalid message type 0x%X\n", |
| 109 | msg->hdr.type); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | if (len < sizeof(msg->hdr)) { |
| 114 | LOG_ERROR(priv, FW_MSG, |
| 115 | "Message from TOP is too short for message header " |
| 116 | "received %d bytes, expected at least %zd bytes\n", |
| 117 | len, sizeof(msg->hdr)); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | if (len < le16_to_cpu(msg->hdr.length) + sizeof(msg->hdr)) { |
| 122 | LOG_ERROR(priv, FW_MSG, |
| 123 | "Message length (%d bytes) is shorter than " |
| 124 | "in header (%d bytes)\n", |
| 125 | len, le16_to_cpu(msg->hdr.length)); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | switch (msg->hdr.category) { |
| 130 | case COMM_CATEGORY_OPERATIONAL: |
| 131 | op_top_message(priv, (struct top_msg *)buf); |
| 132 | break; |
| 133 | |
| 134 | case COMM_CATEGORY_DEBUG: |
| 135 | case COMM_CATEGORY_TESTABILITY: |
| 136 | case COMM_CATEGORY_DIAGNOSTICS: |
| 137 | iwmct_log_top_message(priv, buf, len); |
| 138 | break; |
| 139 | |
| 140 | default: |
| 141 | LOG_ERROR(priv, FW_MSG, |
| 142 | "Message from TOP with unknown category 0x%X\n", |
| 143 | msg->hdr.category); |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | int iwmct_send_hcmd(struct iwmct_priv *priv, u8 *cmd, u16 len) |
| 149 | { |
| 150 | int ret; |
| 151 | u8 *buf; |
| 152 | |
| 153 | LOG_INFOEX(priv, FW_MSG, "Sending hcmd:\n"); |
| 154 | |
| 155 | /* add padding to 256 for IWMC */ |
| 156 | ((struct top_msg *)cmd)->hdr.flags |= CMD_FLAG_PADDING_256; |
| 157 | |
| 158 | LOG_HEXDUMP(FW_MSG, cmd, len); |
| 159 | |
| 160 | if (len > FW_HCMD_BLOCK_SIZE) { |
| 161 | LOG_ERROR(priv, FW_MSG, "size %d exceeded hcmd max size %d\n", |
| 162 | len, FW_HCMD_BLOCK_SIZE); |
| 163 | return -1; |
| 164 | } |
| 165 | |
| 166 | buf = kzalloc(FW_HCMD_BLOCK_SIZE, GFP_KERNEL); |
| 167 | if (!buf) { |
| 168 | LOG_ERROR(priv, FW_MSG, "kzalloc error, buf size %d\n", |
| 169 | FW_HCMD_BLOCK_SIZE); |
| 170 | return -1; |
| 171 | } |
| 172 | |
| 173 | memcpy(buf, cmd, len); |
| 174 | |
| 175 | sdio_claim_host(priv->func); |
| 176 | ret = sdio_memcpy_toio(priv->func, IWMC_SDIO_DATA_ADDR, buf, |
| 177 | FW_HCMD_BLOCK_SIZE); |
| 178 | sdio_release_host(priv->func); |
| 179 | |
| 180 | kfree(buf); |
| 181 | return ret; |
| 182 | } |
| 183 | |
| 184 | int iwmct_tx(struct iwmct_priv *priv, unsigned int addr, |
| 185 | void *src, int count) |
| 186 | { |
| 187 | int ret; |
| 188 | |
| 189 | sdio_claim_host(priv->func); |
| 190 | ret = sdio_memcpy_toio(priv->func, addr, src, count); |
| 191 | sdio_release_host(priv->func); |
| 192 | |
| 193 | return ret; |
| 194 | } |
| 195 | |
| 196 | static void iwmct_irq_read_worker(struct work_struct *ws) |
| 197 | { |
| 198 | struct iwmct_priv *priv; |
| 199 | struct iwmct_work_struct *read_req; |
| 200 | __le32 *buf = NULL; |
| 201 | int ret; |
| 202 | int iosize; |
| 203 | u32 barker; |
| 204 | bool is_barker; |
| 205 | |
| 206 | priv = container_of(ws, struct iwmct_priv, isr_worker); |
| 207 | |
| 208 | LOG_INFO(priv, IRQ, "enter iwmct_irq_read_worker %p\n", ws); |
| 209 | |
| 210 | /* --------------------- Handshake with device -------------------- */ |
| 211 | sdio_claim_host(priv->func); |
| 212 | |
| 213 | /* all list manipulations have to be protected by |
| 214 | * sdio_claim_host/sdio_release_host */ |
| 215 | if (list_empty(&priv->read_req_list)) { |
| 216 | LOG_ERROR(priv, IRQ, "read_req_list empty in read worker\n"); |
| 217 | goto exit_release; |
| 218 | } |
| 219 | |
| 220 | read_req = list_entry(priv->read_req_list.next, |
| 221 | struct iwmct_work_struct, list); |
| 222 | |
| 223 | list_del(&read_req->list); |
| 224 | iosize = read_req->iosize; |
| 225 | kfree(read_req); |
| 226 | |
| 227 | buf = kzalloc(iosize, GFP_KERNEL); |
| 228 | if (!buf) { |
| 229 | LOG_ERROR(priv, IRQ, "kzalloc error, buf size %d\n", iosize); |
| 230 | goto exit_release; |
| 231 | } |
| 232 | |
| 233 | LOG_INFO(priv, IRQ, "iosize=%d, buf=%p, func=%d\n", |
| 234 | iosize, buf, priv->func->num); |
| 235 | |
| 236 | /* read from device */ |
| 237 | ret = sdio_memcpy_fromio(priv->func, buf, IWMC_SDIO_DATA_ADDR, iosize); |
| 238 | if (ret) { |
| 239 | LOG_ERROR(priv, IRQ, "error %d reading buffer\n", ret); |
| 240 | goto exit_release; |
| 241 | } |
| 242 | |
| 243 | LOG_HEXDUMP(IRQ, (u8 *)buf, iosize); |
| 244 | |
| 245 | barker = le32_to_cpu(buf[0]); |
| 246 | |
| 247 | /* Verify whether it's a barker and if not - treat as regular Rx */ |
| 248 | if (barker == IWMC_BARKER_ACK || |
| 249 | (barker & BARKER_DNLOAD_BARKER_MSK) == IWMC_BARKER_REBOOT) { |
| 250 | |
| 251 | /* Valid Barker is equal on first 4 dwords */ |
| 252 | is_barker = (buf[1] == buf[0]) && |
| 253 | (buf[2] == buf[0]) && |
| 254 | (buf[3] == buf[0]); |
| 255 | |
| 256 | if (!is_barker) { |
| 257 | LOG_WARNING(priv, IRQ, |
| 258 | "Potentially inconsistent barker " |
| 259 | "%08X_%08X_%08X_%08X\n", |
| 260 | le32_to_cpu(buf[0]), le32_to_cpu(buf[1]), |
| 261 | le32_to_cpu(buf[2]), le32_to_cpu(buf[3])); |
| 262 | } |
| 263 | } else { |
| 264 | is_barker = false; |
| 265 | } |
| 266 | |
| 267 | /* Handle Top CommHub message */ |
| 268 | if (!is_barker) { |
| 269 | sdio_release_host(priv->func); |
| 270 | handle_top_message(priv, (u8 *)buf, iosize); |
| 271 | goto exit; |
| 272 | } else if (barker == IWMC_BARKER_ACK) { /* Handle barkers */ |
| 273 | if (atomic_read(&priv->dev_sync) == 0) { |
| 274 | LOG_ERROR(priv, IRQ, |
| 275 | "ACK barker arrived out-of-sync\n"); |
| 276 | goto exit_release; |
| 277 | } |
| 278 | |
| 279 | /* Continuing to FW download (after Sync is completed)*/ |
| 280 | atomic_set(&priv->dev_sync, 0); |
| 281 | LOG_INFO(priv, IRQ, "ACK barker arrived " |
| 282 | "- starting FW download\n"); |
| 283 | } else { /* REBOOT barker */ |
| 284 | LOG_INFO(priv, IRQ, "Recieved reboot barker: %x\n", barker); |
| 285 | priv->barker = barker; |
| 286 | |
| 287 | if (barker & BARKER_DNLOAD_SYNC_MSK) { |
| 288 | /* Send the same barker back */ |
| 289 | ret = sdio_memcpy_toio(priv->func, IWMC_SDIO_DATA_ADDR, |
| 290 | buf, iosize); |
| 291 | if (ret) { |
| 292 | LOG_ERROR(priv, IRQ, |
| 293 | "error %d echoing barker\n", ret); |
| 294 | goto exit_release; |
| 295 | } |
| 296 | LOG_INFO(priv, IRQ, "Echoing barker to device\n"); |
| 297 | atomic_set(&priv->dev_sync, 1); |
| 298 | goto exit_release; |
| 299 | } |
| 300 | |
| 301 | /* Continuing to FW download (without Sync) */ |
| 302 | LOG_INFO(priv, IRQ, "No sync requested " |
| 303 | "- starting FW download\n"); |
| 304 | } |
| 305 | |
| 306 | sdio_release_host(priv->func); |
| 307 | |
| 308 | |
| 309 | LOG_INFO(priv, IRQ, "barker download request 0x%x is:\n", priv->barker); |
| 310 | LOG_INFO(priv, IRQ, "******* Top FW %s requested ********\n", |
| 311 | (priv->barker & BARKER_DNLOAD_TOP_MSK) ? "was" : "not"); |
| 312 | LOG_INFO(priv, IRQ, "******* GPS FW %s requested ********\n", |
| 313 | (priv->barker & BARKER_DNLOAD_GPS_MSK) ? "was" : "not"); |
| 314 | LOG_INFO(priv, IRQ, "******* BT FW %s requested ********\n", |
| 315 | (priv->barker & BARKER_DNLOAD_BT_MSK) ? "was" : "not"); |
| 316 | |
| 317 | if (priv->dbg.fw_download) |
| 318 | iwmct_fw_load(priv); |
| 319 | else |
| 320 | LOG_ERROR(priv, IRQ, "FW download not allowed\n"); |
| 321 | |
| 322 | goto exit; |
| 323 | |
| 324 | exit_release: |
| 325 | sdio_release_host(priv->func); |
| 326 | exit: |
| 327 | kfree(buf); |
| 328 | LOG_INFO(priv, IRQ, "exit iwmct_irq_read_worker\n"); |
| 329 | } |
| 330 | |
| 331 | static void iwmct_irq(struct sdio_func *func) |
| 332 | { |
| 333 | struct iwmct_priv *priv; |
| 334 | int val, ret; |
| 335 | int iosize; |
| 336 | int addr = IWMC_SDIO_INTR_GET_SIZE_ADDR; |
| 337 | struct iwmct_work_struct *read_req; |
| 338 | |
| 339 | priv = sdio_get_drvdata(func); |
| 340 | |
| 341 | LOG_INFO(priv, IRQ, "enter iwmct_irq\n"); |
| 342 | |
| 343 | /* read the function's status register */ |
| 344 | val = sdio_readb(func, IWMC_SDIO_INTR_STATUS_ADDR, &ret); |
| 345 | |
| 346 | LOG_INFO(priv, IRQ, "iir value = %d, ret=%d\n", val, ret); |
| 347 | |
| 348 | if (!val) { |
| 349 | LOG_ERROR(priv, IRQ, "iir = 0, exiting ISR\n"); |
| 350 | goto exit_clear_intr; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | /* |
| 355 | * read 2 bytes of the transaction size |
| 356 | * IMPORTANT: sdio transaction size has to be read before clearing |
| 357 | * sdio interrupt!!! |
| 358 | */ |
| 359 | val = sdio_readb(priv->func, addr++, &ret); |
| 360 | iosize = val; |
| 361 | val = sdio_readb(priv->func, addr++, &ret); |
| 362 | iosize += val << 8; |
| 363 | |
| 364 | LOG_INFO(priv, IRQ, "READ size %d\n", iosize); |
| 365 | |
| 366 | if (iosize == 0) { |
| 367 | LOG_ERROR(priv, IRQ, "READ size %d, exiting ISR\n", iosize); |
| 368 | goto exit_clear_intr; |
| 369 | } |
| 370 | |
| 371 | /* allocate a work structure to pass iosize to the worker */ |
| 372 | read_req = kzalloc(sizeof(struct iwmct_work_struct), GFP_KERNEL); |
| 373 | if (!read_req) { |
| 374 | LOG_ERROR(priv, IRQ, "failed to allocate read_req, exit ISR\n"); |
| 375 | goto exit_clear_intr; |
| 376 | } |
| 377 | |
| 378 | INIT_LIST_HEAD(&read_req->list); |
| 379 | read_req->iosize = iosize; |
| 380 | |
| 381 | list_add_tail(&priv->read_req_list, &read_req->list); |
| 382 | |
| 383 | /* clear the function's interrupt request bit (write 1 to clear) */ |
| 384 | sdio_writeb(func, 1, IWMC_SDIO_INTR_CLEAR_ADDR, &ret); |
| 385 | |
| 386 | queue_work(priv->wq, &priv->isr_worker); |
| 387 | |
| 388 | LOG_INFO(priv, IRQ, "exit iwmct_irq\n"); |
| 389 | |
| 390 | return; |
| 391 | |
| 392 | exit_clear_intr: |
| 393 | /* clear the function's interrupt request bit (write 1 to clear) */ |
| 394 | sdio_writeb(func, 1, IWMC_SDIO_INTR_CLEAR_ADDR, &ret); |
| 395 | } |
| 396 | |
| 397 | |
| 398 | static int blocks; |
| 399 | module_param(blocks, int, 0604); |
| 400 | MODULE_PARM_DESC(blocks, "max_blocks_to_send"); |
| 401 | |
| 402 | static int dump; |
| 403 | module_param(dump, bool, 0604); |
| 404 | MODULE_PARM_DESC(dump, "dump_hex_content"); |
| 405 | |
| 406 | static int jump = 1; |
| 407 | module_param(jump, bool, 0604); |
| 408 | |
| 409 | static int direct = 1; |
| 410 | module_param(direct, bool, 0604); |
| 411 | |
| 412 | static int checksum = 1; |
| 413 | module_param(checksum, bool, 0604); |
| 414 | |
| 415 | static int fw_download = 1; |
| 416 | module_param(fw_download, bool, 0604); |
| 417 | |
| 418 | static int block_size = IWMC_SDIO_BLK_SIZE; |
| 419 | module_param(block_size, int, 0404); |
| 420 | |
| 421 | static int download_trans_blks = IWMC_DEFAULT_TR_BLK; |
| 422 | module_param(download_trans_blks, int, 0604); |
| 423 | |
| 424 | static int rubbish_barker; |
| 425 | module_param(rubbish_barker, bool, 0604); |
| 426 | |
| 427 | #ifdef CONFIG_IWMC3200TOP_DEBUG |
| 428 | static int log_level[LOG_SRC_MAX]; |
| 429 | static unsigned int log_level_argc; |
| 430 | module_param_array(log_level, int, &log_level_argc, 0604); |
| 431 | MODULE_PARM_DESC(log_level, "log_level"); |
| 432 | |
| 433 | static int log_level_fw[FW_LOG_SRC_MAX]; |
| 434 | static unsigned int log_level_fw_argc; |
| 435 | module_param_array(log_level_fw, int, &log_level_fw_argc, 0604); |
| 436 | MODULE_PARM_DESC(log_level_fw, "log_level_fw"); |
| 437 | #endif |
| 438 | |
| 439 | void iwmct_dbg_init_params(struct iwmct_priv *priv) |
| 440 | { |
| 441 | #ifdef CONFIG_IWMC3200TOP_DEBUG |
| 442 | int i; |
| 443 | |
| 444 | for (i = 0; i < log_level_argc; i++) { |
| 445 | dev_notice(&priv->func->dev, "log_level[%d]=0x%X\n", |
| 446 | i, log_level[i]); |
| 447 | iwmct_log_set_filter((log_level[i] >> 8) & 0xFF, |
| 448 | log_level[i] & 0xFF); |
| 449 | } |
| 450 | for (i = 0; i < log_level_fw_argc; i++) { |
| 451 | dev_notice(&priv->func->dev, "log_level_fw[%d]=0x%X\n", |
| 452 | i, log_level_fw[i]); |
| 453 | iwmct_log_set_fw_filter((log_level_fw[i] >> 8) & 0xFF, |
| 454 | log_level_fw[i] & 0xFF); |
| 455 | } |
| 456 | #endif |
| 457 | |
| 458 | priv->dbg.blocks = blocks; |
| 459 | LOG_INFO(priv, INIT, "blocks=%d\n", blocks); |
| 460 | priv->dbg.dump = (bool)dump; |
| 461 | LOG_INFO(priv, INIT, "dump=%d\n", dump); |
| 462 | priv->dbg.jump = (bool)jump; |
| 463 | LOG_INFO(priv, INIT, "jump=%d\n", jump); |
| 464 | priv->dbg.direct = (bool)direct; |
| 465 | LOG_INFO(priv, INIT, "direct=%d\n", direct); |
| 466 | priv->dbg.checksum = (bool)checksum; |
| 467 | LOG_INFO(priv, INIT, "checksum=%d\n", checksum); |
| 468 | priv->dbg.fw_download = (bool)fw_download; |
| 469 | LOG_INFO(priv, INIT, "fw_download=%d\n", fw_download); |
| 470 | priv->dbg.block_size = block_size; |
| 471 | LOG_INFO(priv, INIT, "block_size=%d\n", block_size); |
| 472 | priv->dbg.download_trans_blks = download_trans_blks; |
| 473 | LOG_INFO(priv, INIT, "download_trans_blks=%d\n", download_trans_blks); |
| 474 | } |
| 475 | |
| 476 | /***************************************************************************** |
| 477 | * |
| 478 | * sysfs attributes |
| 479 | * |
| 480 | *****************************************************************************/ |
| 481 | static ssize_t show_iwmct_fw_version(struct device *d, |
| 482 | struct device_attribute *attr, char *buf) |
| 483 | { |
| 484 | struct iwmct_priv *priv = dev_get_drvdata(d); |
| 485 | return sprintf(buf, "%s\n", priv->dbg.label_fw); |
| 486 | } |
| 487 | static DEVICE_ATTR(cc_label_fw, S_IRUGO, show_iwmct_fw_version, NULL); |
| 488 | |
| 489 | #ifdef CONFIG_IWMC3200TOP_DEBUG |
| 490 | static DEVICE_ATTR(log_level, S_IWUSR | S_IRUGO, |
| 491 | show_iwmct_log_level, store_iwmct_log_level); |
| 492 | static DEVICE_ATTR(log_level_fw, S_IWUSR | S_IRUGO, |
| 493 | show_iwmct_log_level_fw, store_iwmct_log_level_fw); |
| 494 | #endif |
| 495 | |
| 496 | static struct attribute *iwmct_sysfs_entries[] = { |
| 497 | &dev_attr_cc_label_fw.attr, |
| 498 | #ifdef CONFIG_IWMC3200TOP_DEBUG |
| 499 | &dev_attr_log_level.attr, |
| 500 | &dev_attr_log_level_fw.attr, |
| 501 | #endif |
| 502 | NULL |
| 503 | }; |
| 504 | |
| 505 | static struct attribute_group iwmct_attribute_group = { |
| 506 | .name = NULL, /* put in device directory */ |
| 507 | .attrs = iwmct_sysfs_entries, |
| 508 | }; |
| 509 | |
| 510 | |
| 511 | static int iwmct_probe(struct sdio_func *func, |
| 512 | const struct sdio_device_id *id) |
| 513 | { |
| 514 | struct iwmct_priv *priv; |
| 515 | int ret; |
| 516 | int val = 1; |
| 517 | int addr = IWMC_SDIO_INTR_ENABLE_ADDR; |
| 518 | |
| 519 | dev_dbg(&func->dev, "enter iwmct_probe\n"); |
| 520 | |
| 521 | dev_dbg(&func->dev, "IRQ polling period id %u msecs, HZ is %d\n", |
| 522 | jiffies_to_msecs(2147483647), HZ); |
| 523 | |
| 524 | priv = kzalloc(sizeof(struct iwmct_priv), GFP_KERNEL); |
| 525 | if (!priv) { |
| 526 | dev_err(&func->dev, "kzalloc error\n"); |
| 527 | return -ENOMEM; |
| 528 | } |
| 529 | priv->func = func; |
| 530 | sdio_set_drvdata(func, priv); |
| 531 | |
| 532 | |
| 533 | /* create drivers work queue */ |
| 534 | priv->wq = create_workqueue(DRV_NAME "_wq"); |
| 535 | priv->bus_rescan_wq = create_workqueue(DRV_NAME "_rescan_wq"); |
| 536 | INIT_WORK(&priv->bus_rescan_worker, iwmct_rescan_worker); |
| 537 | INIT_WORK(&priv->isr_worker, iwmct_irq_read_worker); |
| 538 | |
| 539 | init_waitqueue_head(&priv->wait_q); |
| 540 | |
| 541 | sdio_claim_host(func); |
| 542 | /* FIXME: Remove after it is fixed in the Boot ROM upgrade */ |
| 543 | func->enable_timeout = 10; |
| 544 | |
| 545 | /* In our HW, setting the block size also wakes up the boot rom. */ |
| 546 | ret = sdio_set_block_size(func, priv->dbg.block_size); |
| 547 | if (ret) { |
| 548 | LOG_ERROR(priv, INIT, |
| 549 | "sdio_set_block_size() failure: %d\n", ret); |
| 550 | goto error_sdio_enable; |
| 551 | } |
| 552 | |
| 553 | ret = sdio_enable_func(func); |
| 554 | if (ret) { |
| 555 | LOG_ERROR(priv, INIT, "sdio_enable_func() failure: %d\n", ret); |
| 556 | goto error_sdio_enable; |
| 557 | } |
| 558 | |
| 559 | /* init reset and dev_sync states */ |
| 560 | atomic_set(&priv->reset, 0); |
| 561 | atomic_set(&priv->dev_sync, 0); |
| 562 | |
| 563 | /* init read req queue */ |
| 564 | INIT_LIST_HEAD(&priv->read_req_list); |
| 565 | |
| 566 | /* process configurable parameters */ |
| 567 | iwmct_dbg_init_params(priv); |
| 568 | ret = sysfs_create_group(&func->dev.kobj, &iwmct_attribute_group); |
| 569 | if (ret) { |
| 570 | LOG_ERROR(priv, INIT, "Failed to register attributes and " |
| 571 | "initialize module_params\n"); |
| 572 | goto error_dev_attrs; |
| 573 | } |
| 574 | |
| 575 | iwmct_dbgfs_register(priv, DRV_NAME); |
| 576 | |
| 577 | if (!priv->dbg.direct && priv->dbg.download_trans_blks > 8) { |
| 578 | LOG_INFO(priv, INIT, |
| 579 | "Reducing transaction to 8 blocks = 2K (from %d)\n", |
| 580 | priv->dbg.download_trans_blks); |
| 581 | priv->dbg.download_trans_blks = 8; |
| 582 | } |
| 583 | priv->trans_len = priv->dbg.download_trans_blks * priv->dbg.block_size; |
| 584 | LOG_INFO(priv, INIT, "Transaction length = %d\n", priv->trans_len); |
| 585 | |
| 586 | ret = sdio_claim_irq(func, iwmct_irq); |
| 587 | if (ret) { |
| 588 | LOG_ERROR(priv, INIT, "sdio_claim_irq() failure: %d\n", ret); |
| 589 | goto error_claim_irq; |
| 590 | } |
| 591 | |
| 592 | |
| 593 | /* Enable function's interrupt */ |
| 594 | sdio_writeb(priv->func, val, addr, &ret); |
| 595 | if (ret) { |
| 596 | LOG_ERROR(priv, INIT, "Failure writing to " |
| 597 | "Interrupt Enable Register (%d): %d\n", addr, ret); |
| 598 | goto error_enable_int; |
| 599 | } |
| 600 | |
| 601 | sdio_release_host(func); |
| 602 | |
| 603 | LOG_INFO(priv, INIT, "exit iwmct_probe\n"); |
| 604 | |
| 605 | return ret; |
| 606 | |
| 607 | error_enable_int: |
| 608 | sdio_release_irq(func); |
| 609 | error_claim_irq: |
| 610 | sdio_disable_func(func); |
| 611 | error_dev_attrs: |
| 612 | iwmct_dbgfs_unregister(priv->dbgfs); |
| 613 | sysfs_remove_group(&func->dev.kobj, &iwmct_attribute_group); |
| 614 | error_sdio_enable: |
| 615 | sdio_release_host(func); |
| 616 | return ret; |
| 617 | } |
| 618 | |
| 619 | static void iwmct_remove(struct sdio_func *func) |
| 620 | { |
| 621 | struct iwmct_work_struct *read_req; |
| 622 | struct iwmct_priv *priv = sdio_get_drvdata(func); |
| 623 | |
| 624 | priv = sdio_get_drvdata(func); |
| 625 | |
| 626 | LOG_INFO(priv, INIT, "enter\n"); |
| 627 | |
| 628 | sdio_claim_host(func); |
| 629 | sdio_release_irq(func); |
| 630 | sdio_release_host(func); |
| 631 | |
| 632 | /* Safely destroy osc workqueue */ |
| 633 | destroy_workqueue(priv->bus_rescan_wq); |
| 634 | destroy_workqueue(priv->wq); |
| 635 | |
| 636 | sdio_claim_host(func); |
| 637 | sdio_disable_func(func); |
| 638 | sysfs_remove_group(&func->dev.kobj, &iwmct_attribute_group); |
| 639 | iwmct_dbgfs_unregister(priv->dbgfs); |
| 640 | sdio_release_host(func); |
| 641 | |
| 642 | /* free read requests */ |
| 643 | while (!list_empty(&priv->read_req_list)) { |
| 644 | read_req = list_entry(priv->read_req_list.next, |
| 645 | struct iwmct_work_struct, list); |
| 646 | |
| 647 | list_del(&read_req->list); |
| 648 | kfree(read_req); |
| 649 | } |
| 650 | |
| 651 | kfree(priv); |
| 652 | } |
| 653 | |
| 654 | |
| 655 | static const struct sdio_device_id iwmct_ids[] = { |
Tomas Winkler | 11e2521 | 2009-11-14 08:36:35 +0000 | [diff] [blame^] | 656 | /* Intel Wireless MultiCom 3200 Top Driver */ |
| 657 | { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL, 0x1404)}, |
| 658 | { }, /* Terminating entry */ |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 659 | }; |
| 660 | |
| 661 | MODULE_DEVICE_TABLE(sdio, iwmct_ids); |
| 662 | |
| 663 | static struct sdio_driver iwmct_driver = { |
| 664 | .probe = iwmct_probe, |
| 665 | .remove = iwmct_remove, |
| 666 | .name = DRV_NAME, |
| 667 | .id_table = iwmct_ids, |
| 668 | }; |
| 669 | |
| 670 | static int __init iwmct_init(void) |
| 671 | { |
| 672 | int rc; |
| 673 | |
| 674 | /* Default log filter settings */ |
| 675 | iwmct_log_set_filter(LOG_SRC_ALL, LOG_SEV_FILTER_RUNTIME); |
| 676 | iwmct_log_set_filter(LOG_SRC_FW_MSG, LOG_SEV_FILTER_ALL); |
| 677 | iwmct_log_set_fw_filter(LOG_SRC_ALL, FW_LOG_SEV_FILTER_RUNTIME); |
| 678 | |
| 679 | rc = sdio_register_driver(&iwmct_driver); |
| 680 | |
| 681 | return rc; |
| 682 | } |
| 683 | |
| 684 | static void __exit iwmct_exit(void) |
| 685 | { |
| 686 | sdio_unregister_driver(&iwmct_driver); |
| 687 | } |
| 688 | |
| 689 | module_init(iwmct_init); |
| 690 | module_exit(iwmct_exit); |
| 691 | |