| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Intel Wireless Multicomm 3200 WiFi driver | 
 | 3 |  * | 
 | 4 |  * Copyright (C) 2009 Intel Corporation. All rights reserved. | 
 | 5 |  * | 
 | 6 |  * Redistribution and use in source and binary forms, with or without | 
 | 7 |  * modification, are permitted provided that the following conditions | 
 | 8 |  * are met: | 
 | 9 |  * | 
 | 10 |  *   * Redistributions of source code must retain the above copyright | 
 | 11 |  *     notice, this list of conditions and the following disclaimer. | 
 | 12 |  *   * Redistributions in binary form must reproduce the above copyright | 
 | 13 |  *     notice, this list of conditions and the following disclaimer in | 
 | 14 |  *     the documentation and/or other materials provided with the | 
 | 15 |  *     distribution. | 
 | 16 |  *   * Neither the name of Intel Corporation nor the names of its | 
 | 17 |  *     contributors may be used to endorse or promote products derived | 
 | 18 |  *     from this software without specific prior written permission. | 
 | 19 |  * | 
 | 20 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
 | 21 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
 | 22 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
 | 23 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
 | 24 |  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
 | 25 |  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
 | 26 |  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
 | 27 |  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
 | 28 |  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
 | 29 |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
 | 30 |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
 | 31 |  * | 
 | 32 |  * | 
 | 33 |  * Intel Corporation <ilw@linux.intel.com> | 
 | 34 |  * Samuel Ortiz <samuel.ortiz@intel.com> | 
 | 35 |  * Zhu Yi <yi.zhu@intel.com> | 
 | 36 |  * | 
 | 37 |  */ | 
 | 38 |  | 
 | 39 | /* | 
 | 40 |  * This is the SDIO bus specific hooks for iwm. | 
 | 41 |  * It also is the module's entry point. | 
 | 42 |  * | 
 | 43 |  * Interesting code paths: | 
 | 44 |  * iwm_sdio_probe() (Called by an SDIO bus scan) | 
 | 45 |  *  -> iwm_if_alloc() (netdev.c) | 
 | 46 |  *      -> iwm_wdev_alloc() (cfg80211.c, allocates and register our wiphy) | 
 | 47 |  *          -> wiphy_new() | 
 | 48 |  *          -> wiphy_register() | 
 | 49 |  *      -> alloc_netdev_mq() | 
 | 50 |  *      -> register_netdev() | 
 | 51 |  * | 
 | 52 |  * iwm_sdio_remove() | 
 | 53 |  *  -> iwm_if_free() (netdev.c) | 
 | 54 |  *      -> unregister_netdev() | 
 | 55 |  *      -> iwm_wdev_free() (cfg80211.c) | 
 | 56 |  *          -> wiphy_unregister() | 
 | 57 |  *          -> wiphy_free() | 
 | 58 |  * | 
 | 59 |  * iwm_sdio_isr() (called in process context from the SDIO core code) | 
 | 60 |  *  -> queue_work(.., isr_worker) | 
 | 61 |  *      -- [async] --> iwm_sdio_isr_worker() | 
 | 62 |  *                      -> iwm_rx_handle() | 
 | 63 |  */ | 
 | 64 |  | 
 | 65 | #include <linux/kernel.h> | 
| Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 66 | #include <linux/module.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 67 | #include <linux/slab.h> | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 68 | #include <linux/netdevice.h> | 
 | 69 | #include <linux/debugfs.h> | 
| Tomas Winkler | 51def0b | 2009-07-22 14:06:56 +0000 | [diff] [blame] | 70 | #include <linux/mmc/sdio_ids.h> | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 71 | #include <linux/mmc/sdio.h> | 
 | 72 | #include <linux/mmc/sdio_func.h> | 
 | 73 |  | 
 | 74 | #include "iwm.h" | 
 | 75 | #include "debug.h" | 
 | 76 | #include "bus.h" | 
 | 77 | #include "sdio.h" | 
 | 78 |  | 
 | 79 | static void iwm_sdio_isr_worker(struct work_struct *work) | 
 | 80 | { | 
 | 81 | 	struct iwm_sdio_priv *hw; | 
 | 82 | 	struct iwm_priv *iwm; | 
 | 83 | 	struct iwm_rx_info *rx_info; | 
 | 84 | 	struct sk_buff *skb; | 
 | 85 | 	u8 *rx_buf; | 
 | 86 | 	unsigned long rx_size; | 
 | 87 |  | 
 | 88 | 	hw = container_of(work, struct iwm_sdio_priv, isr_worker); | 
 | 89 | 	iwm = hw_to_iwm(hw); | 
 | 90 |  | 
 | 91 | 	while (!skb_queue_empty(&iwm->rx_list)) { | 
 | 92 | 		skb = skb_dequeue(&iwm->rx_list); | 
 | 93 | 		rx_info = skb_to_rx_info(skb); | 
 | 94 | 		rx_size = rx_info->rx_size; | 
 | 95 | 		rx_buf = skb->data; | 
 | 96 |  | 
 | 97 | 		IWM_HEXDUMP(iwm, DBG, SDIO, "RX: ", rx_buf, rx_size); | 
 | 98 | 		if (iwm_rx_handle(iwm, rx_buf, rx_size) < 0) | 
 | 99 | 			IWM_WARN(iwm, "RX error\n"); | 
 | 100 |  | 
 | 101 | 		kfree_skb(skb); | 
 | 102 | 	} | 
 | 103 | } | 
 | 104 |  | 
 | 105 | static void iwm_sdio_isr(struct sdio_func *func) | 
 | 106 | { | 
 | 107 | 	struct iwm_priv *iwm; | 
 | 108 | 	struct iwm_sdio_priv *hw; | 
 | 109 | 	struct iwm_rx_info *rx_info; | 
 | 110 | 	struct sk_buff *skb; | 
 | 111 | 	unsigned long buf_size, read_size; | 
 | 112 | 	int ret; | 
 | 113 | 	u8 val; | 
 | 114 |  | 
 | 115 | 	hw = sdio_get_drvdata(func); | 
 | 116 | 	iwm = hw_to_iwm(hw); | 
 | 117 |  | 
 | 118 | 	buf_size = hw->blk_size; | 
 | 119 |  | 
 | 120 | 	/* We're checking the status */ | 
 | 121 | 	val = sdio_readb(func, IWM_SDIO_INTR_STATUS_ADDR, &ret); | 
 | 122 | 	if (val == 0 || ret < 0) { | 
 | 123 | 		IWM_ERR(iwm, "Wrong INTR_STATUS\n"); | 
 | 124 | 		return; | 
 | 125 | 	} | 
 | 126 |  | 
 | 127 | 	/* See if we have free buffers */ | 
 | 128 | 	if (skb_queue_len(&iwm->rx_list) > IWM_RX_LIST_SIZE) { | 
 | 129 | 		IWM_ERR(iwm, "No buffer for more Rx frames\n"); | 
 | 130 | 		return; | 
 | 131 | 	} | 
 | 132 |  | 
 | 133 | 	/* We first read the transaction size */ | 
 | 134 | 	read_size = sdio_readb(func, IWM_SDIO_INTR_GET_SIZE_ADDR + 1, &ret); | 
 | 135 | 	read_size = read_size << 8; | 
 | 136 |  | 
 | 137 | 	if (ret < 0) { | 
 | 138 | 		IWM_ERR(iwm, "Couldn't read the xfer size\n"); | 
 | 139 | 		return; | 
 | 140 | 	} | 
 | 141 |  | 
 | 142 | 	/* We need to clear the INT register */ | 
 | 143 | 	sdio_writeb(func, 1, IWM_SDIO_INTR_CLEAR_ADDR, &ret); | 
 | 144 | 	if (ret < 0) { | 
 | 145 | 		IWM_ERR(iwm, "Couldn't clear the INT register\n"); | 
 | 146 | 		return; | 
 | 147 | 	} | 
 | 148 |  | 
 | 149 | 	while (buf_size < read_size) | 
 | 150 | 		buf_size <<= 1; | 
 | 151 |  | 
 | 152 | 	skb = dev_alloc_skb(buf_size); | 
 | 153 | 	if (!skb) { | 
 | 154 | 		IWM_ERR(iwm, "Couldn't alloc RX skb\n"); | 
 | 155 | 		return; | 
 | 156 | 	} | 
 | 157 | 	rx_info = skb_to_rx_info(skb); | 
 | 158 | 	rx_info->rx_size = read_size; | 
 | 159 | 	rx_info->rx_buf_size = buf_size; | 
 | 160 |  | 
 | 161 | 	/* Now we can read the actual buffer */ | 
 | 162 | 	ret = sdio_memcpy_fromio(func, skb_put(skb, read_size), | 
 | 163 | 				 IWM_SDIO_DATA_ADDR, read_size); | 
 | 164 |  | 
 | 165 | 	/* The skb is put on a driver's specific Rx SKB list */ | 
 | 166 | 	skb_queue_tail(&iwm->rx_list, skb); | 
 | 167 |  | 
 | 168 | 	/* We can now schedule the actual worker */ | 
 | 169 | 	queue_work(hw->isr_wq, &hw->isr_worker); | 
 | 170 | } | 
 | 171 |  | 
 | 172 | static void iwm_sdio_rx_free(struct iwm_sdio_priv *hw) | 
 | 173 | { | 
 | 174 | 	struct iwm_priv *iwm = hw_to_iwm(hw); | 
 | 175 |  | 
 | 176 | 	flush_workqueue(hw->isr_wq); | 
 | 177 |  | 
 | 178 | 	skb_queue_purge(&iwm->rx_list); | 
 | 179 | } | 
 | 180 |  | 
 | 181 | /* Bus ops */ | 
 | 182 | static int if_sdio_enable(struct iwm_priv *iwm) | 
 | 183 | { | 
 | 184 | 	struct iwm_sdio_priv *hw = iwm_to_if_sdio(iwm); | 
 | 185 | 	int ret; | 
 | 186 |  | 
 | 187 | 	sdio_claim_host(hw->func); | 
 | 188 |  | 
 | 189 | 	ret = sdio_enable_func(hw->func); | 
 | 190 | 	if (ret) { | 
 | 191 | 		IWM_ERR(iwm, "Couldn't enable the device: is TOP driver " | 
 | 192 | 			"loaded and functional?\n"); | 
 | 193 | 		goto release_host; | 
 | 194 | 	} | 
 | 195 |  | 
 | 196 | 	iwm_reset(iwm); | 
 | 197 |  | 
 | 198 | 	ret = sdio_claim_irq(hw->func, iwm_sdio_isr); | 
 | 199 | 	if (ret) { | 
 | 200 | 		IWM_ERR(iwm, "Failed to claim irq: %d\n", ret); | 
 | 201 | 		goto release_host; | 
 | 202 | 	} | 
 | 203 |  | 
 | 204 | 	sdio_writeb(hw->func, 1, IWM_SDIO_INTR_ENABLE_ADDR, &ret); | 
 | 205 | 	if (ret < 0) { | 
 | 206 | 		IWM_ERR(iwm, "Couldn't enable INTR: %d\n", ret); | 
 | 207 | 		goto release_irq; | 
 | 208 | 	} | 
 | 209 |  | 
 | 210 | 	sdio_release_host(hw->func); | 
 | 211 |  | 
 | 212 | 	IWM_DBG_SDIO(iwm, INFO, "IWM SDIO enable\n"); | 
 | 213 |  | 
 | 214 | 	return 0; | 
 | 215 |  | 
 | 216 |  release_irq: | 
 | 217 | 	sdio_release_irq(hw->func); | 
 | 218 |  release_host: | 
 | 219 | 	sdio_release_host(hw->func); | 
 | 220 |  | 
 | 221 | 	return ret; | 
 | 222 | } | 
 | 223 |  | 
 | 224 | static int if_sdio_disable(struct iwm_priv *iwm) | 
 | 225 | { | 
 | 226 | 	struct iwm_sdio_priv *hw = iwm_to_if_sdio(iwm); | 
 | 227 | 	int ret; | 
 | 228 |  | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 229 | 	sdio_claim_host(hw->func); | 
 | 230 | 	sdio_writeb(hw->func, 0, IWM_SDIO_INTR_ENABLE_ADDR, &ret); | 
 | 231 | 	if (ret < 0) | 
 | 232 | 		IWM_WARN(iwm, "Couldn't disable INTR: %d\n", ret); | 
 | 233 |  | 
 | 234 | 	sdio_release_irq(hw->func); | 
 | 235 | 	sdio_disable_func(hw->func); | 
 | 236 | 	sdio_release_host(hw->func); | 
 | 237 |  | 
 | 238 | 	iwm_sdio_rx_free(hw); | 
 | 239 |  | 
| Samuel Ortiz | f96cca8 | 2009-10-16 13:18:54 +0800 | [diff] [blame] | 240 | 	iwm_reset(iwm); | 
 | 241 |  | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 242 | 	IWM_DBG_SDIO(iwm, INFO, "IWM SDIO disable\n"); | 
 | 243 |  | 
 | 244 | 	return 0; | 
 | 245 | } | 
 | 246 |  | 
 | 247 | static int if_sdio_send_chunk(struct iwm_priv *iwm, u8 *buf, int count) | 
 | 248 | { | 
 | 249 | 	struct iwm_sdio_priv *hw = iwm_to_if_sdio(iwm); | 
 | 250 | 	int aligned_count = ALIGN(count, hw->blk_size); | 
 | 251 | 	int ret; | 
 | 252 |  | 
 | 253 | 	if ((unsigned long)buf & 0x3) { | 
 | 254 | 		IWM_ERR(iwm, "buf <%p> is not dword aligned\n", buf); | 
 | 255 | 		/* TODO: Is this a hardware limitation? use get_unligned */ | 
 | 256 | 		return -EINVAL; | 
 | 257 | 	} | 
 | 258 |  | 
 | 259 | 	sdio_claim_host(hw->func); | 
 | 260 | 	ret = sdio_memcpy_toio(hw->func, IWM_SDIO_DATA_ADDR, buf, | 
 | 261 | 			       aligned_count); | 
 | 262 | 	sdio_release_host(hw->func); | 
 | 263 |  | 
 | 264 | 	return ret; | 
 | 265 | } | 
 | 266 |  | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 267 | static ssize_t iwm_debugfs_sdio_read(struct file *filp, char __user *buffer, | 
 | 268 | 				     size_t count, loff_t *ppos) | 
 | 269 | { | 
 | 270 | 	struct iwm_priv *iwm = filp->private_data; | 
 | 271 | 	struct iwm_sdio_priv *hw = iwm_to_if_sdio(iwm); | 
 | 272 | 	char *buf; | 
 | 273 | 	u8 cccr; | 
 | 274 | 	int buf_len = 4096, ret; | 
 | 275 | 	size_t len = 0; | 
 | 276 |  | 
 | 277 | 	if (*ppos != 0) | 
 | 278 | 		return 0; | 
 | 279 | 	if (count < sizeof(buf)) | 
 | 280 | 		return -ENOSPC; | 
 | 281 |  | 
 | 282 | 	buf = kzalloc(buf_len, GFP_KERNEL); | 
 | 283 | 	if (!buf) | 
 | 284 | 		return -ENOMEM; | 
 | 285 |  | 
 | 286 | 	sdio_claim_host(hw->func); | 
 | 287 |  | 
 | 288 | 	cccr =  sdio_f0_readb(hw->func, SDIO_CCCR_IOEx, &ret); | 
 | 289 | 	if (ret) { | 
 | 290 | 		IWM_ERR(iwm, "Could not read SDIO_CCCR_IOEx\n"); | 
 | 291 | 		goto err; | 
 | 292 | 	} | 
 | 293 | 	len += snprintf(buf + len, buf_len - len, "CCCR_IOEx:  0x%x\n", cccr); | 
 | 294 |  | 
 | 295 | 	cccr =  sdio_f0_readb(hw->func, SDIO_CCCR_IORx, &ret); | 
 | 296 | 	if (ret) { | 
 | 297 | 		IWM_ERR(iwm, "Could not read SDIO_CCCR_IORx\n"); | 
 | 298 | 		goto err; | 
 | 299 | 	} | 
 | 300 | 	len += snprintf(buf + len, buf_len - len, "CCCR_IORx:  0x%x\n", cccr); | 
 | 301 |  | 
 | 302 |  | 
 | 303 | 	cccr =  sdio_f0_readb(hw->func, SDIO_CCCR_IENx, &ret); | 
 | 304 | 	if (ret) { | 
 | 305 | 		IWM_ERR(iwm, "Could not read SDIO_CCCR_IENx\n"); | 
 | 306 | 		goto err; | 
 | 307 | 	} | 
 | 308 | 	len += snprintf(buf + len, buf_len - len, "CCCR_IENx:  0x%x\n", cccr); | 
 | 309 |  | 
 | 310 |  | 
 | 311 | 	cccr =  sdio_f0_readb(hw->func, SDIO_CCCR_INTx, &ret); | 
 | 312 | 	if (ret) { | 
 | 313 | 		IWM_ERR(iwm, "Could not read SDIO_CCCR_INTx\n"); | 
 | 314 | 		goto err; | 
 | 315 | 	} | 
 | 316 | 	len += snprintf(buf + len, buf_len - len, "CCCR_INTx:  0x%x\n", cccr); | 
 | 317 |  | 
 | 318 |  | 
 | 319 | 	cccr =  sdio_f0_readb(hw->func, SDIO_CCCR_ABORT, &ret); | 
 | 320 | 	if (ret) { | 
 | 321 | 		IWM_ERR(iwm, "Could not read SDIO_CCCR_ABORTx\n"); | 
 | 322 | 		goto err; | 
 | 323 | 	} | 
 | 324 | 	len += snprintf(buf + len, buf_len - len, "CCCR_ABORT: 0x%x\n", cccr); | 
 | 325 |  | 
 | 326 | 	cccr =  sdio_f0_readb(hw->func, SDIO_CCCR_IF, &ret); | 
 | 327 | 	if (ret) { | 
 | 328 | 		IWM_ERR(iwm, "Could not read SDIO_CCCR_IF\n"); | 
 | 329 | 		goto err; | 
 | 330 | 	} | 
 | 331 | 	len += snprintf(buf + len, buf_len - len, "CCCR_IF:    0x%x\n", cccr); | 
 | 332 |  | 
 | 333 |  | 
 | 334 | 	cccr =  sdio_f0_readb(hw->func, SDIO_CCCR_CAPS, &ret); | 
 | 335 | 	if (ret) { | 
 | 336 | 		IWM_ERR(iwm, "Could not read SDIO_CCCR_CAPS\n"); | 
 | 337 | 		goto err; | 
 | 338 | 	} | 
 | 339 | 	len += snprintf(buf + len, buf_len - len, "CCCR_CAPS:  0x%x\n", cccr); | 
 | 340 |  | 
 | 341 | 	cccr =  sdio_f0_readb(hw->func, SDIO_CCCR_CIS, &ret); | 
 | 342 | 	if (ret) { | 
 | 343 | 		IWM_ERR(iwm, "Could not read SDIO_CCCR_CIS\n"); | 
 | 344 | 		goto err; | 
 | 345 | 	} | 
 | 346 | 	len += snprintf(buf + len, buf_len - len, "CCCR_CIS:   0x%x\n", cccr); | 
 | 347 |  | 
 | 348 | 	ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len); | 
 | 349 | err: | 
 | 350 | 	sdio_release_host(hw->func); | 
 | 351 |  | 
 | 352 | 	kfree(buf); | 
 | 353 |  | 
 | 354 | 	return ret; | 
 | 355 | } | 
 | 356 |  | 
 | 357 | static const struct file_operations iwm_debugfs_sdio_fops = { | 
 | 358 | 	.owner =	THIS_MODULE, | 
| Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 359 | 	.open =		simple_open, | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 360 | 	.read =		iwm_debugfs_sdio_read, | 
| Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 361 | 	.llseek =	default_llseek, | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 362 | }; | 
 | 363 |  | 
| John W. Linville | 1f55c12 | 2010-05-03 14:46:05 -0400 | [diff] [blame] | 364 | static void if_sdio_debugfs_init(struct iwm_priv *iwm, struct dentry *parent_dir) | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 365 | { | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 366 | 	struct iwm_sdio_priv *hw = iwm_to_if_sdio(iwm); | 
 | 367 |  | 
 | 368 | 	hw->cccr_dentry = debugfs_create_file("cccr", 0200, | 
 | 369 | 					      parent_dir, iwm, | 
 | 370 | 					      &iwm_debugfs_sdio_fops); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 371 | } | 
 | 372 |  | 
 | 373 | static void if_sdio_debugfs_exit(struct iwm_priv *iwm) | 
 | 374 | { | 
 | 375 | 	struct iwm_sdio_priv *hw = iwm_to_if_sdio(iwm); | 
 | 376 |  | 
 | 377 | 	debugfs_remove(hw->cccr_dentry); | 
 | 378 | } | 
 | 379 |  | 
 | 380 | static struct iwm_if_ops if_sdio_ops = { | 
 | 381 | 	.enable = if_sdio_enable, | 
 | 382 | 	.disable = if_sdio_disable, | 
 | 383 | 	.send_chunk = if_sdio_send_chunk, | 
 | 384 | 	.debugfs_init = if_sdio_debugfs_init, | 
 | 385 | 	.debugfs_exit = if_sdio_debugfs_exit, | 
 | 386 | 	.umac_name = "iwmc3200wifi-umac-sdio.bin", | 
| Samuel Ortiz | 939cab8 | 2009-06-02 15:52:20 +0800 | [diff] [blame] | 387 | 	.calib_lmac_name = "iwmc3200wifi-calib-sdio.bin", | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 388 | 	.lmac_name = "iwmc3200wifi-lmac-sdio.bin", | 
 | 389 | }; | 
| Ben Hutchings | 328aca3 | 2009-11-07 21:59:38 +0000 | [diff] [blame] | 390 | MODULE_FIRMWARE("iwmc3200wifi-umac-sdio.bin"); | 
 | 391 | MODULE_FIRMWARE("iwmc3200wifi-calib-sdio.bin"); | 
 | 392 | MODULE_FIRMWARE("iwmc3200wifi-lmac-sdio.bin"); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 393 |  | 
 | 394 | static int iwm_sdio_probe(struct sdio_func *func, | 
 | 395 | 			  const struct sdio_device_id *id) | 
 | 396 | { | 
 | 397 | 	struct iwm_priv *iwm; | 
 | 398 | 	struct iwm_sdio_priv *hw; | 
 | 399 | 	struct device *dev = &func->dev; | 
 | 400 | 	int ret; | 
 | 401 |  | 
 | 402 | 	/* check if TOP has already initialized the card */ | 
 | 403 | 	sdio_claim_host(func); | 
 | 404 | 	ret = sdio_enable_func(func); | 
 | 405 | 	if (ret) { | 
 | 406 | 		dev_err(dev, "wait for TOP to enable the device\n"); | 
 | 407 | 		sdio_release_host(func); | 
 | 408 | 		return ret; | 
 | 409 | 	} | 
 | 410 |  | 
 | 411 | 	ret = sdio_set_block_size(func, IWM_SDIO_BLK_SIZE); | 
 | 412 |  | 
 | 413 | 	sdio_disable_func(func); | 
 | 414 | 	sdio_release_host(func); | 
 | 415 |  | 
 | 416 | 	if (ret < 0) { | 
 | 417 | 		dev_err(dev, "Failed to set block size: %d\n", ret); | 
 | 418 | 		return ret; | 
 | 419 | 	} | 
 | 420 |  | 
 | 421 | 	iwm = iwm_if_alloc(sizeof(struct iwm_sdio_priv), dev, &if_sdio_ops); | 
 | 422 | 	if (IS_ERR(iwm)) { | 
 | 423 | 		dev_err(dev, "allocate SDIO interface failed\n"); | 
 | 424 | 		return PTR_ERR(iwm); | 
 | 425 | 	} | 
 | 426 |  | 
 | 427 | 	hw = iwm_private(iwm); | 
 | 428 | 	hw->iwm = iwm; | 
 | 429 |  | 
| John W. Linville | 1f55c12 | 2010-05-03 14:46:05 -0400 | [diff] [blame] | 430 | 	iwm_debugfs_init(iwm); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 431 |  | 
 | 432 | 	sdio_set_drvdata(func, hw); | 
 | 433 |  | 
 | 434 | 	hw->func = func; | 
 | 435 | 	hw->blk_size = IWM_SDIO_BLK_SIZE; | 
 | 436 |  | 
 | 437 | 	hw->isr_wq = create_singlethread_workqueue(KBUILD_MODNAME "_sdio"); | 
 | 438 | 	if (!hw->isr_wq) { | 
 | 439 | 		ret = -ENOMEM; | 
 | 440 | 		goto debugfs_exit; | 
 | 441 | 	} | 
 | 442 |  | 
 | 443 | 	INIT_WORK(&hw->isr_worker, iwm_sdio_isr_worker); | 
 | 444 |  | 
| Zhu Yi | d7e057d | 2009-06-15 21:36:14 +0200 | [diff] [blame] | 445 | 	ret = iwm_if_add(iwm); | 
 | 446 | 	if (ret) { | 
 | 447 | 		dev_err(dev, "add SDIO interface failed\n"); | 
 | 448 | 		goto destroy_wq; | 
 | 449 | 	} | 
 | 450 |  | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 451 | 	dev_info(dev, "IWM SDIO probe\n"); | 
 | 452 |  | 
 | 453 | 	return 0; | 
 | 454 |  | 
| Zhu Yi | d7e057d | 2009-06-15 21:36:14 +0200 | [diff] [blame] | 455 |  destroy_wq: | 
 | 456 | 	destroy_workqueue(hw->isr_wq); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 457 |  debugfs_exit: | 
 | 458 | 	iwm_debugfs_exit(iwm); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 459 | 	iwm_if_free(iwm); | 
 | 460 | 	return ret; | 
 | 461 | } | 
 | 462 |  | 
 | 463 | static void iwm_sdio_remove(struct sdio_func *func) | 
 | 464 | { | 
 | 465 | 	struct iwm_sdio_priv *hw = sdio_get_drvdata(func); | 
 | 466 | 	struct iwm_priv *iwm = hw_to_iwm(hw); | 
 | 467 | 	struct device *dev = &func->dev; | 
 | 468 |  | 
| Zhu Yi | d7e057d | 2009-06-15 21:36:14 +0200 | [diff] [blame] | 469 | 	iwm_if_remove(iwm); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 470 | 	destroy_workqueue(hw->isr_wq); | 
| Zhu Yi | 4e9aa52 | 2009-06-15 21:59:48 +0200 | [diff] [blame] | 471 | 	iwm_debugfs_exit(iwm); | 
 | 472 | 	iwm_if_free(iwm); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 473 |  | 
 | 474 | 	sdio_set_drvdata(func, NULL); | 
 | 475 |  | 
 | 476 | 	dev_info(dev, "IWM SDIO remove\n"); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 477 | } | 
 | 478 |  | 
 | 479 | static const struct sdio_device_id iwm_sdio_ids[] = { | 
| Zhu Yi | 30315ff | 2009-10-16 13:18:45 +0800 | [diff] [blame] | 480 | 	/* Global/AGN SKU */ | 
 | 481 | 	{ SDIO_DEVICE(SDIO_VENDOR_ID_INTEL, 0x1403) }, | 
 | 482 | 	/* BGN SKU */ | 
 | 483 | 	{ SDIO_DEVICE(SDIO_VENDOR_ID_INTEL, 0x1408) }, | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 484 | 	{ /* end: all zeroes */	}, | 
 | 485 | }; | 
 | 486 | MODULE_DEVICE_TABLE(sdio, iwm_sdio_ids); | 
 | 487 |  | 
 | 488 | static struct sdio_driver iwm_sdio_driver = { | 
 | 489 | 	.name		= "iwm_sdio", | 
 | 490 | 	.id_table	= iwm_sdio_ids, | 
 | 491 | 	.probe		= iwm_sdio_probe, | 
 | 492 | 	.remove		= iwm_sdio_remove, | 
 | 493 | }; | 
 | 494 |  | 
 | 495 | static int __init iwm_sdio_init_module(void) | 
 | 496 | { | 
| Zhu Yi | 257862f | 2009-06-15 21:59:56 +0200 | [diff] [blame] | 497 | 	return sdio_register_driver(&iwm_sdio_driver); | 
| Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 498 | } | 
 | 499 |  | 
 | 500 | static void __exit iwm_sdio_exit_module(void) | 
 | 501 | { | 
 | 502 | 	sdio_unregister_driver(&iwm_sdio_driver); | 
 | 503 | } | 
 | 504 |  | 
 | 505 | module_init(iwm_sdio_init_module); | 
 | 506 | module_exit(iwm_sdio_exit_module); | 
 | 507 |  | 
 | 508 | MODULE_LICENSE("GPL"); | 
 | 509 | MODULE_AUTHOR(IWM_COPYRIGHT " " IWM_AUTHOR); |