blob: eab0ab976af29ebb0b355f82b01caeb39bd07152 [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
Vasanthakumar Thiagarajan1b2df402012-02-06 20:15:53 +05303 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
Kalle Valobdcd8172011-07-18 00:22:30 +03004 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040018#include <linux/module.h>
Kalle Valobdcd8172011-07-18 00:22:30 +030019#include <linux/mmc/card.h>
20#include <linux/mmc/mmc.h>
21#include <linux/mmc/host.h>
22#include <linux/mmc/sdio_func.h>
23#include <linux/mmc/sdio_ids.h>
24#include <linux/mmc/sdio.h>
25#include <linux/mmc/sd.h>
Kalle Valo2e1cb232011-10-05 12:23:49 +030026#include "hif.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030027#include "hif-ops.h"
28#include "target.h"
29#include "debug.h"
Vivek Natarajan9df337a2011-09-15 20:30:43 +053030#include "cfg80211.h"
Kalle Valoe60c8152013-03-18 13:42:20 +020031#include "trace.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030032
33struct ath6kl_sdio {
34 struct sdio_func *func;
35
Kalle Valo12eb9442012-03-07 20:04:00 +020036 /* protects access to bus_req_freeq */
Kalle Valobdcd8172011-07-18 00:22:30 +030037 spinlock_t lock;
38
39 /* free list */
40 struct list_head bus_req_freeq;
41
42 /* available bus requests */
43 struct bus_request bus_req[BUS_REQUEST_MAX_NUM];
44
45 struct ath6kl *ar;
Raja Manifdb28582011-11-21 12:26:51 +053046
Kalle Valobdcd8172011-07-18 00:22:30 +030047 u8 *dma_buffer;
48
Raja Manifdb28582011-11-21 12:26:51 +053049 /* protects access to dma_buffer */
50 struct mutex dma_buffer_mutex;
51
Kalle Valobdcd8172011-07-18 00:22:30 +030052 /* scatter request list head */
53 struct list_head scat_req;
54
Raja Manid1f41592012-02-09 12:57:12 +053055 atomic_t irq_handling;
56 wait_queue_head_t irq_wq;
Vasanthakumar Thiagarajan9d826822012-01-04 15:57:19 +053057
Kalle Valo12eb9442012-03-07 20:04:00 +020058 /* protects access to scat_req */
Kalle Valobdcd8172011-07-18 00:22:30 +030059 spinlock_t scat_lock;
Kalle Valo12eb9442012-03-07 20:04:00 +020060
Kalle Valo32a07e42011-10-30 21:15:57 +020061 bool scatter_enabled;
62
Kalle Valobdcd8172011-07-18 00:22:30 +030063 bool is_disabled;
Kalle Valobdcd8172011-07-18 00:22:30 +030064 const struct sdio_device_id *id;
65 struct work_struct wr_async_work;
66 struct list_head wr_asyncq;
Kalle Valo12eb9442012-03-07 20:04:00 +020067
68 /* protects access to wr_asyncq */
Kalle Valobdcd8172011-07-18 00:22:30 +030069 spinlock_t wr_async_lock;
70};
71
72#define CMD53_ARG_READ 0
73#define CMD53_ARG_WRITE 1
74#define CMD53_ARG_BLOCK_BASIS 1
75#define CMD53_ARG_FIXED_ADDRESS 0
76#define CMD53_ARG_INCR_ADDRESS 1
77
78static inline struct ath6kl_sdio *ath6kl_sdio_priv(struct ath6kl *ar)
79{
80 return ar->hif_priv;
81}
82
83/*
84 * Macro to check if DMA buffer is WORD-aligned and DMA-able.
85 * Most host controllers assume the buffer is DMA'able and will
86 * bug-check otherwise (i.e. buffers on the stack). virt_addr_valid
87 * check fails on stack memory.
88 */
89static inline bool buf_needs_bounce(u8 *buf)
90{
91 return ((unsigned long) buf & 0x3) || !virt_addr_valid(buf);
92}
93
94static void ath6kl_sdio_set_mbox_info(struct ath6kl *ar)
95{
96 struct ath6kl_mbox_info *mbox_info = &ar->mbox_info;
97
98 /* EP1 has an extended range */
99 mbox_info->htc_addr = HIF_MBOX_BASE_ADDR;
100 mbox_info->htc_ext_addr = HIF_MBOX0_EXT_BASE_ADDR;
101 mbox_info->htc_ext_sz = HIF_MBOX0_EXT_WIDTH;
102 mbox_info->block_size = HIF_MBOX_BLOCK_SIZE;
103 mbox_info->gmbox_addr = HIF_GMBOX_BASE_ADDR;
104 mbox_info->gmbox_sz = HIF_GMBOX_WIDTH;
105}
106
107static inline void ath6kl_sdio_set_cmd53_arg(u32 *arg, u8 rw, u8 func,
108 u8 mode, u8 opcode, u32 addr,
109 u16 blksz)
110{
111 *arg = (((rw & 1) << 31) |
112 ((func & 0x7) << 28) |
113 ((mode & 1) << 27) |
114 ((opcode & 1) << 26) |
115 ((addr & 0x1FFFF) << 9) |
116 (blksz & 0x1FF));
117}
118
119static inline void ath6kl_sdio_set_cmd52_arg(u32 *arg, u8 write, u8 raw,
120 unsigned int address,
121 unsigned char val)
122{
123 const u8 func = 0;
124
125 *arg = ((write & 1) << 31) |
126 ((func & 0x7) << 28) |
127 ((raw & 1) << 27) |
128 (1 << 26) |
129 ((address & 0x1FFFF) << 9) |
130 (1 << 8) |
131 (val & 0xFF);
132}
133
134static int ath6kl_sdio_func0_cmd52_wr_byte(struct mmc_card *card,
135 unsigned int address,
136 unsigned char byte)
137{
138 struct mmc_command io_cmd;
139
140 memset(&io_cmd, 0, sizeof(io_cmd));
141 ath6kl_sdio_set_cmd52_arg(&io_cmd.arg, 1, 0, address, byte);
142 io_cmd.opcode = SD_IO_RW_DIRECT;
143 io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
144
145 return mmc_wait_for_cmd(card->host, &io_cmd, 0);
146}
147
Vasanthakumar Thiagarajanda220692011-07-16 20:29:16 +0530148static int ath6kl_sdio_io(struct sdio_func *func, u32 request, u32 addr,
149 u8 *buf, u32 len)
150{
151 int ret = 0;
152
Vasanthakumar Thiagarajan861dd052011-09-30 21:46:59 +0530153 sdio_claim_host(func);
154
Vasanthakumar Thiagarajanda220692011-07-16 20:29:16 +0530155 if (request & HIF_WRITE) {
Kalle Valof7325b82011-09-27 14:30:58 +0300156 /* FIXME: looks like ugly workaround for something */
Vasanthakumar Thiagarajanda220692011-07-16 20:29:16 +0530157 if (addr >= HIF_MBOX_BASE_ADDR &&
158 addr <= HIF_MBOX_END_ADDR)
159 addr += (HIF_MBOX_WIDTH - len);
160
Kalle Valof7325b82011-09-27 14:30:58 +0300161 /* FIXME: this also looks like ugly workaround */
Vasanthakumar Thiagarajanda220692011-07-16 20:29:16 +0530162 if (addr == HIF_MBOX0_EXT_BASE_ADDR)
163 addr += HIF_MBOX0_EXT_WIDTH - len;
164
165 if (request & HIF_FIXED_ADDRESS)
166 ret = sdio_writesb(func, addr, buf, len);
167 else
168 ret = sdio_memcpy_toio(func, addr, buf, len);
169 } else {
170 if (request & HIF_FIXED_ADDRESS)
171 ret = sdio_readsb(func, buf, addr, len);
172 else
173 ret = sdio_memcpy_fromio(func, buf, addr, len);
174 }
175
Vasanthakumar Thiagarajan861dd052011-09-30 21:46:59 +0530176 sdio_release_host(func);
177
Kalle Valof7325b82011-09-27 14:30:58 +0300178 ath6kl_dbg(ATH6KL_DBG_SDIO, "%s addr 0x%x%s buf 0x%p len %d\n",
179 request & HIF_WRITE ? "wr" : "rd", addr,
180 request & HIF_FIXED_ADDRESS ? " (fixed)" : "", buf, len);
181 ath6kl_dbg_dump(ATH6KL_DBG_SDIO_DUMP, NULL, "sdio ", buf, len);
182
Kalle Valoe60c8152013-03-18 13:42:20 +0200183 trace_ath6kl_sdio(addr, request, buf, len);
184
Vasanthakumar Thiagarajanda220692011-07-16 20:29:16 +0530185 return ret;
186}
187
Kalle Valobdcd8172011-07-18 00:22:30 +0300188static struct bus_request *ath6kl_sdio_alloc_busreq(struct ath6kl_sdio *ar_sdio)
189{
190 struct bus_request *bus_req;
Kalle Valobdcd8172011-07-18 00:22:30 +0300191
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530192 spin_lock_bh(&ar_sdio->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300193
194 if (list_empty(&ar_sdio->bus_req_freeq)) {
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530195 spin_unlock_bh(&ar_sdio->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300196 return NULL;
197 }
198
199 bus_req = list_first_entry(&ar_sdio->bus_req_freeq,
200 struct bus_request, list);
201 list_del(&bus_req->list);
202
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530203 spin_unlock_bh(&ar_sdio->lock);
Kalle Valof7325b82011-09-27 14:30:58 +0300204 ath6kl_dbg(ATH6KL_DBG_SCATTER, "%s: bus request 0x%p\n",
205 __func__, bus_req);
Kalle Valobdcd8172011-07-18 00:22:30 +0300206
207 return bus_req;
208}
209
210static void ath6kl_sdio_free_bus_req(struct ath6kl_sdio *ar_sdio,
211 struct bus_request *bus_req)
212{
Kalle Valof7325b82011-09-27 14:30:58 +0300213 ath6kl_dbg(ATH6KL_DBG_SCATTER, "%s: bus request 0x%p\n",
214 __func__, bus_req);
Kalle Valobdcd8172011-07-18 00:22:30 +0300215
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530216 spin_lock_bh(&ar_sdio->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300217 list_add_tail(&bus_req->list, &ar_sdio->bus_req_freeq);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530218 spin_unlock_bh(&ar_sdio->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300219}
220
221static void ath6kl_sdio_setup_scat_data(struct hif_scatter_req *scat_req,
Kalle Valobdcd8172011-07-18 00:22:30 +0300222 struct mmc_data *data)
223{
224 struct scatterlist *sg;
225 int i;
226
227 data->blksz = HIF_MBOX_BLOCK_SIZE;
228 data->blocks = scat_req->len / HIF_MBOX_BLOCK_SIZE;
229
230 ath6kl_dbg(ATH6KL_DBG_SCATTER,
231 "hif-scatter: (%s) addr: 0x%X, (block len: %d, block count: %d) , (tot:%d,sg:%d)\n",
232 (scat_req->req & HIF_WRITE) ? "WR" : "RD", scat_req->addr,
233 data->blksz, data->blocks, scat_req->len,
234 scat_req->scat_entries);
235
236 data->flags = (scat_req->req & HIF_WRITE) ? MMC_DATA_WRITE :
237 MMC_DATA_READ;
238
239 /* fill SG entries */
Vasanthakumar Thiagarajand4df7892011-07-16 20:29:07 +0530240 sg = scat_req->sgentries;
Kalle Valobdcd8172011-07-18 00:22:30 +0300241 sg_init_table(sg, scat_req->scat_entries);
242
243 /* assemble SG list */
244 for (i = 0; i < scat_req->scat_entries; i++, sg++) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300245 ath6kl_dbg(ATH6KL_DBG_SCATTER, "%d: addr:0x%p, len:%d\n",
246 i, scat_req->scat_list[i].buf,
247 scat_req->scat_list[i].len);
248
249 sg_set_buf(sg, scat_req->scat_list[i].buf,
250 scat_req->scat_list[i].len);
251 }
252
253 /* set scatter-gather table for request */
Vasanthakumar Thiagarajand4df7892011-07-16 20:29:07 +0530254 data->sg = scat_req->sgentries;
Kalle Valobdcd8172011-07-18 00:22:30 +0300255 data->sg_len = scat_req->scat_entries;
256}
257
258static int ath6kl_sdio_scat_rw(struct ath6kl_sdio *ar_sdio,
259 struct bus_request *req)
260{
261 struct mmc_request mmc_req;
262 struct mmc_command cmd;
263 struct mmc_data data;
264 struct hif_scatter_req *scat_req;
265 u8 opcode, rw;
Vasanthakumar Thiagarajan348a8fb2011-07-16 20:29:17 +0530266 int status, len;
Kalle Valobdcd8172011-07-18 00:22:30 +0300267
268 scat_req = req->scat_req;
269
Vasanthakumar Thiagarajan348a8fb2011-07-16 20:29:17 +0530270 if (scat_req->virt_scat) {
271 len = scat_req->len;
272 if (scat_req->req & HIF_BLOCK_BASIS)
273 len = round_down(len, HIF_MBOX_BLOCK_SIZE);
274
275 status = ath6kl_sdio_io(ar_sdio->func, scat_req->req,
276 scat_req->addr, scat_req->virt_dma_buf,
277 len);
278 goto scat_complete;
279 }
280
Kalle Valobdcd8172011-07-18 00:22:30 +0300281 memset(&mmc_req, 0, sizeof(struct mmc_request));
282 memset(&cmd, 0, sizeof(struct mmc_command));
283 memset(&data, 0, sizeof(struct mmc_data));
284
Vasanthakumar Thiagarajand4df7892011-07-16 20:29:07 +0530285 ath6kl_sdio_setup_scat_data(scat_req, &data);
Kalle Valobdcd8172011-07-18 00:22:30 +0300286
287 opcode = (scat_req->req & HIF_FIXED_ADDRESS) ?
288 CMD53_ARG_FIXED_ADDRESS : CMD53_ARG_INCR_ADDRESS;
289
290 rw = (scat_req->req & HIF_WRITE) ? CMD53_ARG_WRITE : CMD53_ARG_READ;
291
292 /* Fixup the address so that the last byte will fall on MBOX EOM */
293 if (scat_req->req & HIF_WRITE) {
294 if (scat_req->addr == HIF_MBOX_BASE_ADDR)
295 scat_req->addr += HIF_MBOX_WIDTH - scat_req->len;
296 else
297 /* Uses extended address range */
298 scat_req->addr += HIF_MBOX0_EXT_WIDTH - scat_req->len;
299 }
300
301 /* set command argument */
302 ath6kl_sdio_set_cmd53_arg(&cmd.arg, rw, ar_sdio->func->num,
303 CMD53_ARG_BLOCK_BASIS, opcode, scat_req->addr,
304 data.blocks);
305
306 cmd.opcode = SD_IO_RW_EXTENDED;
307 cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
308
309 mmc_req.cmd = &cmd;
310 mmc_req.data = &data;
311
Vasanthakumar Thiagarajan861dd052011-09-30 21:46:59 +0530312 sdio_claim_host(ar_sdio->func);
313
Kalle Valobdcd8172011-07-18 00:22:30 +0300314 mmc_set_data_timeout(&data, ar_sdio->func->card);
Kalle Valoe60c8152013-03-18 13:42:20 +0200315
316 trace_ath6kl_sdio_scat(scat_req->addr,
317 scat_req->req,
318 scat_req->len,
319 scat_req->scat_entries,
320 scat_req->scat_list);
321
Kalle Valobdcd8172011-07-18 00:22:30 +0300322 /* synchronous call to process request */
323 mmc_wait_for_req(ar_sdio->func->card->host, &mmc_req);
324
Vasanthakumar Thiagarajan861dd052011-09-30 21:46:59 +0530325 sdio_release_host(ar_sdio->func);
326
Kalle Valobdcd8172011-07-18 00:22:30 +0300327 status = cmd.error ? cmd.error : data.error;
Vasanthakumar Thiagarajan348a8fb2011-07-16 20:29:17 +0530328
329scat_complete:
Kalle Valobdcd8172011-07-18 00:22:30 +0300330 scat_req->status = status;
331
332 if (scat_req->status)
333 ath6kl_err("Scatter write request failed:%d\n",
334 scat_req->status);
335
336 if (scat_req->req & HIF_ASYNCHRONOUS)
Vasanthakumar Thiagarajane041c7f2011-07-16 20:29:09 +0530337 scat_req->complete(ar_sdio->ar->htc_target, scat_req);
Kalle Valobdcd8172011-07-18 00:22:30 +0300338
339 return status;
340}
341
Vasanthakumar Thiagarajan3df505a2011-07-16 20:29:10 +0530342static int ath6kl_sdio_alloc_prep_scat_req(struct ath6kl_sdio *ar_sdio,
343 int n_scat_entry, int n_scat_req,
344 bool virt_scat)
345{
346 struct hif_scatter_req *s_req;
347 struct bus_request *bus_req;
Geert Uytterhoeven37291fc2013-04-24 14:02:34 +0200348 int i, scat_req_sz, scat_list_sz, size;
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530349 u8 *virt_buf;
Vasanthakumar Thiagarajan3df505a2011-07-16 20:29:10 +0530350
Kalle Valo31b9cc92014-03-11 12:58:00 +0200351 scat_list_sz = n_scat_entry * sizeof(struct hif_scatter_item);
Vasanthakumar Thiagarajan3df505a2011-07-16 20:29:10 +0530352 scat_req_sz = sizeof(*s_req) + scat_list_sz;
353
354 if (!virt_scat)
Geert Uytterhoeven37291fc2013-04-24 14:02:34 +0200355 size = sizeof(struct scatterlist) * n_scat_entry;
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530356 else
Geert Uytterhoeven37291fc2013-04-24 14:02:34 +0200357 size = 2 * L1_CACHE_BYTES +
358 ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER;
Vasanthakumar Thiagarajan3df505a2011-07-16 20:29:10 +0530359
360 for (i = 0; i < n_scat_req; i++) {
361 /* allocate the scatter request */
362 s_req = kzalloc(scat_req_sz, GFP_KERNEL);
363 if (!s_req)
364 return -ENOMEM;
365
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530366 if (virt_scat) {
Geert Uytterhoeven37291fc2013-04-24 14:02:34 +0200367 virt_buf = kzalloc(size, GFP_KERNEL);
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530368 if (!virt_buf) {
369 kfree(s_req);
370 return -ENOMEM;
371 }
372
373 s_req->virt_dma_buf =
374 (u8 *)L1_CACHE_ALIGN((unsigned long)virt_buf);
375 } else {
Vasanthakumar Thiagarajan3df505a2011-07-16 20:29:10 +0530376 /* allocate sglist */
Geert Uytterhoeven37291fc2013-04-24 14:02:34 +0200377 s_req->sgentries = kzalloc(size, GFP_KERNEL);
Vasanthakumar Thiagarajan3df505a2011-07-16 20:29:10 +0530378
379 if (!s_req->sgentries) {
380 kfree(s_req);
381 return -ENOMEM;
382 }
383 }
384
385 /* allocate a bus request for this scatter request */
386 bus_req = ath6kl_sdio_alloc_busreq(ar_sdio);
387 if (!bus_req) {
388 kfree(s_req->sgentries);
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530389 kfree(s_req->virt_dma_buf);
Vasanthakumar Thiagarajan3df505a2011-07-16 20:29:10 +0530390 kfree(s_req);
391 return -ENOMEM;
392 }
393
394 /* assign the scatter request to this bus request */
395 bus_req->scat_req = s_req;
396 s_req->busrequest = bus_req;
397
Vasanthakumar Thiagarajan4a005c32011-07-16 20:29:15 +0530398 s_req->virt_scat = virt_scat;
399
Vasanthakumar Thiagarajan3df505a2011-07-16 20:29:10 +0530400 /* add it to the scatter pool */
401 hif_scatter_req_add(ar_sdio->ar, s_req);
402 }
403
404 return 0;
405}
406
Kalle Valobdcd8172011-07-18 00:22:30 +0300407static int ath6kl_sdio_read_write_sync(struct ath6kl *ar, u32 addr, u8 *buf,
408 u32 len, u32 request)
409{
410 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
411 u8 *tbuf = NULL;
412 int ret;
413 bool bounced = false;
414
415 if (request & HIF_BLOCK_BASIS)
416 len = round_down(len, HIF_MBOX_BLOCK_SIZE);
417
418 if (buf_needs_bounce(buf)) {
419 if (!ar_sdio->dma_buffer)
420 return -ENOMEM;
Raja Manifdb28582011-11-21 12:26:51 +0530421 mutex_lock(&ar_sdio->dma_buffer_mutex);
Kalle Valobdcd8172011-07-18 00:22:30 +0300422 tbuf = ar_sdio->dma_buffer;
Raja Manidaa16bc2012-03-02 18:02:08 +0530423
424 if (request & HIF_WRITE)
425 memcpy(tbuf, buf, len);
426
Kalle Valobdcd8172011-07-18 00:22:30 +0300427 bounced = true;
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200428 } else {
Kalle Valobdcd8172011-07-18 00:22:30 +0300429 tbuf = buf;
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200430 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300431
Vasanthakumar Thiagarajanda220692011-07-16 20:29:16 +0530432 ret = ath6kl_sdio_io(ar_sdio->func, request, addr, tbuf, len);
433 if ((request & HIF_READ) && bounced)
434 memcpy(buf, tbuf, len);
Kalle Valobdcd8172011-07-18 00:22:30 +0300435
Raja Manifdb28582011-11-21 12:26:51 +0530436 if (bounced)
437 mutex_unlock(&ar_sdio->dma_buffer_mutex);
438
Kalle Valobdcd8172011-07-18 00:22:30 +0300439 return ret;
440}
441
442static void __ath6kl_sdio_write_async(struct ath6kl_sdio *ar_sdio,
443 struct bus_request *req)
444{
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200445 if (req->scat_req) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300446 ath6kl_sdio_scat_rw(ar_sdio, req);
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200447 } else {
Kalle Valobdcd8172011-07-18 00:22:30 +0300448 void *context;
449 int status;
450
451 status = ath6kl_sdio_read_write_sync(ar_sdio->ar, req->address,
452 req->buffer, req->length,
453 req->request);
454 context = req->packet;
455 ath6kl_sdio_free_bus_req(ar_sdio, req);
Kalle Valo8e8ddb22011-10-05 12:23:33 +0300456 ath6kl_hif_rw_comp_handler(context, status);
Kalle Valobdcd8172011-07-18 00:22:30 +0300457 }
458}
459
460static void ath6kl_sdio_write_async_work(struct work_struct *work)
461{
462 struct ath6kl_sdio *ar_sdio;
Kalle Valobdcd8172011-07-18 00:22:30 +0300463 struct bus_request *req, *tmp_req;
464
465 ar_sdio = container_of(work, struct ath6kl_sdio, wr_async_work);
Kalle Valobdcd8172011-07-18 00:22:30 +0300466
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530467 spin_lock_bh(&ar_sdio->wr_async_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300468 list_for_each_entry_safe(req, tmp_req, &ar_sdio->wr_asyncq, list) {
469 list_del(&req->list);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530470 spin_unlock_bh(&ar_sdio->wr_async_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300471 __ath6kl_sdio_write_async(ar_sdio, req);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530472 spin_lock_bh(&ar_sdio->wr_async_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300473 }
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530474 spin_unlock_bh(&ar_sdio->wr_async_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300475}
476
477static void ath6kl_sdio_irq_handler(struct sdio_func *func)
478{
479 int status;
480 struct ath6kl_sdio *ar_sdio;
481
Kalle Valof7325b82011-09-27 14:30:58 +0300482 ath6kl_dbg(ATH6KL_DBG_SDIO, "irq\n");
483
Kalle Valobdcd8172011-07-18 00:22:30 +0300484 ar_sdio = sdio_get_drvdata(func);
Raja Manid1f41592012-02-09 12:57:12 +0530485 atomic_set(&ar_sdio->irq_handling, 1);
Kalle Valobdcd8172011-07-18 00:22:30 +0300486 /*
487 * Release the host during interrups so we can pick it back up when
488 * we process commands.
489 */
490 sdio_release_host(ar_sdio->func);
491
Kalle Valo8e8ddb22011-10-05 12:23:33 +0300492 status = ath6kl_hif_intr_bh_handler(ar_sdio->ar);
Kalle Valobdcd8172011-07-18 00:22:30 +0300493 sdio_claim_host(ar_sdio->func);
Raja Manid1f41592012-02-09 12:57:12 +0530494
495 atomic_set(&ar_sdio->irq_handling, 0);
496 wake_up(&ar_sdio->irq_wq);
497
Kalle Valobdcd8172011-07-18 00:22:30 +0300498 WARN_ON(status && status != -ECANCELED);
499}
500
Kalle Valob2e75692011-10-27 18:48:14 +0300501static int ath6kl_sdio_power_on(struct ath6kl *ar)
Kalle Valobdcd8172011-07-18 00:22:30 +0300502{
Kalle Valob2e75692011-10-27 18:48:14 +0300503 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +0300504 struct sdio_func *func = ar_sdio->func;
505 int ret = 0;
506
507 if (!ar_sdio->is_disabled)
508 return 0;
509
Kalle Valo3ef987b2011-10-24 12:18:07 +0300510 ath6kl_dbg(ATH6KL_DBG_BOOT, "sdio power on\n");
511
Kalle Valobdcd8172011-07-18 00:22:30 +0300512 sdio_claim_host(func);
513
514 ret = sdio_enable_func(func);
515 if (ret) {
516 ath6kl_err("Unable to enable sdio func: %d)\n", ret);
517 sdio_release_host(func);
518 return ret;
519 }
520
521 sdio_release_host(func);
522
523 /*
524 * Wait for hardware to initialise. It should take a lot less than
525 * 10 ms but let's be conservative here.
526 */
527 msleep(10);
528
529 ar_sdio->is_disabled = false;
530
531 return ret;
532}
533
Kalle Valob2e75692011-10-27 18:48:14 +0300534static int ath6kl_sdio_power_off(struct ath6kl *ar)
Kalle Valobdcd8172011-07-18 00:22:30 +0300535{
Kalle Valob2e75692011-10-27 18:48:14 +0300536 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +0300537 int ret;
538
539 if (ar_sdio->is_disabled)
540 return 0;
541
Kalle Valo3ef987b2011-10-24 12:18:07 +0300542 ath6kl_dbg(ATH6KL_DBG_BOOT, "sdio power off\n");
543
Kalle Valobdcd8172011-07-18 00:22:30 +0300544 /* Disable the card */
545 sdio_claim_host(ar_sdio->func);
546 ret = sdio_disable_func(ar_sdio->func);
547 sdio_release_host(ar_sdio->func);
548
549 if (ret)
550 return ret;
551
552 ar_sdio->is_disabled = true;
553
554 return ret;
555}
556
557static int ath6kl_sdio_write_async(struct ath6kl *ar, u32 address, u8 *buffer,
558 u32 length, u32 request,
559 struct htc_packet *packet)
560{
561 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
562 struct bus_request *bus_req;
Kalle Valobdcd8172011-07-18 00:22:30 +0300563
564 bus_req = ath6kl_sdio_alloc_busreq(ar_sdio);
565
Vasanthakumar Thiagarajan93b42ca2012-04-26 20:26:14 +0530566 if (WARN_ON_ONCE(!bus_req))
Kalle Valobdcd8172011-07-18 00:22:30 +0300567 return -ENOMEM;
568
569 bus_req->address = address;
570 bus_req->buffer = buffer;
571 bus_req->length = length;
572 bus_req->request = request;
573 bus_req->packet = packet;
574
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530575 spin_lock_bh(&ar_sdio->wr_async_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300576 list_add_tail(&bus_req->list, &ar_sdio->wr_asyncq);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530577 spin_unlock_bh(&ar_sdio->wr_async_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300578 queue_work(ar->ath6kl_wq, &ar_sdio->wr_async_work);
579
580 return 0;
581}
582
583static void ath6kl_sdio_irq_enable(struct ath6kl *ar)
584{
585 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
586 int ret;
587
588 sdio_claim_host(ar_sdio->func);
589
590 /* Register the isr */
591 ret = sdio_claim_irq(ar_sdio->func, ath6kl_sdio_irq_handler);
592 if (ret)
593 ath6kl_err("Failed to claim sdio irq: %d\n", ret);
594
595 sdio_release_host(ar_sdio->func);
596}
597
Raja Manid1f41592012-02-09 12:57:12 +0530598static bool ath6kl_sdio_is_on_irq(struct ath6kl *ar)
599{
600 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
601
602 return !atomic_read(&ar_sdio->irq_handling);
603}
604
Kalle Valobdcd8172011-07-18 00:22:30 +0300605static void ath6kl_sdio_irq_disable(struct ath6kl *ar)
606{
607 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
608 int ret;
609
610 sdio_claim_host(ar_sdio->func);
611
Raja Manid1f41592012-02-09 12:57:12 +0530612 if (atomic_read(&ar_sdio->irq_handling)) {
613 sdio_release_host(ar_sdio->func);
614
615 ret = wait_event_interruptible(ar_sdio->irq_wq,
616 ath6kl_sdio_is_on_irq(ar));
617 if (ret)
618 return;
619
620 sdio_claim_host(ar_sdio->func);
621 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300622
623 ret = sdio_release_irq(ar_sdio->func);
624 if (ret)
625 ath6kl_err("Failed to release sdio irq: %d\n", ret);
626
627 sdio_release_host(ar_sdio->func);
628}
629
630static struct hif_scatter_req *ath6kl_sdio_scatter_req_get(struct ath6kl *ar)
631{
632 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
633 struct hif_scatter_req *node = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300634
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530635 spin_lock_bh(&ar_sdio->scat_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300636
637 if (!list_empty(&ar_sdio->scat_req)) {
638 node = list_first_entry(&ar_sdio->scat_req,
639 struct hif_scatter_req, list);
640 list_del(&node->list);
Chilam Ngb29072c2012-02-07 01:33:00 -0800641
642 node->scat_q_depth = get_queue_depth(&ar_sdio->scat_req);
Kalle Valobdcd8172011-07-18 00:22:30 +0300643 }
644
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530645 spin_unlock_bh(&ar_sdio->scat_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300646
647 return node;
648}
649
650static void ath6kl_sdio_scatter_req_add(struct ath6kl *ar,
651 struct hif_scatter_req *s_req)
652{
653 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +0300654
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530655 spin_lock_bh(&ar_sdio->scat_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300656
657 list_add_tail(&s_req->list, &ar_sdio->scat_req);
658
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530659 spin_unlock_bh(&ar_sdio->scat_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300660}
661
Vasanthakumar Thiagarajanc630d182011-07-16 20:29:06 +0530662/* scatter gather read write request */
663static int ath6kl_sdio_async_rw_scatter(struct ath6kl *ar,
664 struct hif_scatter_req *scat_req)
665{
666 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
Vasanthakumar Thiagarajanc630d182011-07-16 20:29:06 +0530667 u32 request = scat_req->req;
668 int status = 0;
Vasanthakumar Thiagarajanc630d182011-07-16 20:29:06 +0530669
670 if (!scat_req->len)
671 return -EINVAL;
672
673 ath6kl_dbg(ATH6KL_DBG_SCATTER,
Kalle Valo96f1fad2012-03-07 20:03:57 +0200674 "hif-scatter: total len: %d scatter entries: %d\n",
675 scat_req->len, scat_req->scat_entries);
Vasanthakumar Thiagarajanc630d182011-07-16 20:29:06 +0530676
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200677 if (request & HIF_SYNCHRONOUS) {
Vasanthakumar Thiagarajand4df7892011-07-16 20:29:07 +0530678 status = ath6kl_sdio_scat_rw(ar_sdio, scat_req->busrequest);
Kalle Valoa5d8f9d2014-03-11 12:58:01 +0200679 } else {
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530680 spin_lock_bh(&ar_sdio->wr_async_lock);
Vasanthakumar Thiagarajand4df7892011-07-16 20:29:07 +0530681 list_add_tail(&scat_req->busrequest->list, &ar_sdio->wr_asyncq);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530682 spin_unlock_bh(&ar_sdio->wr_async_lock);
Vasanthakumar Thiagarajanc630d182011-07-16 20:29:06 +0530683 queue_work(ar->ath6kl_wq, &ar_sdio->wr_async_work);
684 }
685
686 return status;
687}
688
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530689/* clean up scatter support */
690static void ath6kl_sdio_cleanup_scatter(struct ath6kl *ar)
691{
692 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
693 struct hif_scatter_req *s_req, *tmp_req;
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530694
695 /* empty the free list */
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530696 spin_lock_bh(&ar_sdio->scat_lock);
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530697 list_for_each_entry_safe(s_req, tmp_req, &ar_sdio->scat_req, list) {
698 list_del(&s_req->list);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530699 spin_unlock_bh(&ar_sdio->scat_lock);
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530700
Kalle Valo32a07e42011-10-30 21:15:57 +0200701 /*
702 * FIXME: should we also call completion handler with
703 * ath6kl_hif_rw_comp_handler() with status -ECANCELED so
704 * that the packet is properly freed?
705 */
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530706 if (s_req->busrequest)
707 ath6kl_sdio_free_bus_req(ar_sdio, s_req->busrequest);
708 kfree(s_req->virt_dma_buf);
709 kfree(s_req->sgentries);
710 kfree(s_req);
711
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530712 spin_lock_bh(&ar_sdio->scat_lock);
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530713 }
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +0530714 spin_unlock_bh(&ar_sdio->scat_lock);
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530715}
716
717/* setup of HIF scatter resources */
Vasanthakumar Thiagarajan50745af2011-07-18 14:23:29 +0530718static int ath6kl_sdio_enable_scatter(struct ath6kl *ar)
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530719{
720 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
Vasanthakumar Thiagarajan50745af2011-07-18 14:23:29 +0530721 struct htc_target *target = ar->htc_target;
Andi Kleen527f6572012-09-03 22:15:36 +0200722 int ret = 0;
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530723 bool virt_scat = false;
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530724
Kalle Valo32a07e42011-10-30 21:15:57 +0200725 if (ar_sdio->scatter_enabled)
726 return 0;
727
728 ar_sdio->scatter_enabled = true;
729
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530730 /* check if host supports scatter and it meets our requirements */
731 if (ar_sdio->func->card->host->max_segs < MAX_SCATTER_ENTRIES_PER_REQ) {
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530732 ath6kl_err("host only supports scatter of :%d entries, need: %d\n",
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530733 ar_sdio->func->card->host->max_segs,
734 MAX_SCATTER_ENTRIES_PER_REQ);
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530735 virt_scat = true;
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530736 }
737
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530738 if (!virt_scat) {
739 ret = ath6kl_sdio_alloc_prep_scat_req(ar_sdio,
740 MAX_SCATTER_ENTRIES_PER_REQ,
741 MAX_SCATTER_REQUESTS, virt_scat);
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530742
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530743 if (!ret) {
Kalle Valo3ef987b2011-10-24 12:18:07 +0300744 ath6kl_dbg(ATH6KL_DBG_BOOT,
745 "hif-scatter enabled requests %d entries %d\n",
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530746 MAX_SCATTER_REQUESTS,
747 MAX_SCATTER_ENTRIES_PER_REQ);
748
Vasanthakumar Thiagarajan50745af2011-07-18 14:23:29 +0530749 target->max_scat_entries = MAX_SCATTER_ENTRIES_PER_REQ;
750 target->max_xfer_szper_scatreq =
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530751 MAX_SCATTER_REQ_TRANSFER_SIZE;
752 } else {
753 ath6kl_sdio_cleanup_scatter(ar);
754 ath6kl_warn("hif scatter resource setup failed, trying virtual scatter method\n");
755 }
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530756 }
757
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530758 if (virt_scat || ret) {
759 ret = ath6kl_sdio_alloc_prep_scat_req(ar_sdio,
760 ATH6KL_SCATTER_ENTRIES_PER_REQ,
761 ATH6KL_SCATTER_REQS, virt_scat);
762
763 if (ret) {
764 ath6kl_err("failed to alloc virtual scatter resources !\n");
765 ath6kl_sdio_cleanup_scatter(ar);
766 return ret;
767 }
768
Kalle Valo3ef987b2011-10-24 12:18:07 +0300769 ath6kl_dbg(ATH6KL_DBG_BOOT,
770 "virtual scatter enabled requests %d entries %d\n",
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530771 ATH6KL_SCATTER_REQS, ATH6KL_SCATTER_ENTRIES_PER_REQ);
772
Vasanthakumar Thiagarajan50745af2011-07-18 14:23:29 +0530773 target->max_scat_entries = ATH6KL_SCATTER_ENTRIES_PER_REQ;
774 target->max_xfer_szper_scatreq =
Vasanthakumar Thiagarajancfeab102011-07-16 20:29:14 +0530775 ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER;
776 }
777
Vasanthakumar Thiagarajan18a0f932011-07-16 20:29:13 +0530778 return 0;
779}
780
Kalle Valoe28e8102011-11-01 08:44:36 +0200781static int ath6kl_sdio_config(struct ath6kl *ar)
782{
783 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
784 struct sdio_func *func = ar_sdio->func;
785 int ret;
786
787 sdio_claim_host(func);
788
789 if ((ar_sdio->id->device & MANUFACTURER_ID_ATH6KL_BASE_MASK) >=
790 MANUFACTURER_ID_AR6003_BASE) {
791 /* enable 4-bit ASYNC interrupt on AR6003 or later */
792 ret = ath6kl_sdio_func0_cmd52_wr_byte(func->card,
793 CCCR_SDIO_IRQ_MODE_REG,
794 SDIO_IRQ_MODE_ASYNC_4BIT_IRQ);
795 if (ret) {
796 ath6kl_err("Failed to enable 4-bit async irq mode %d\n",
797 ret);
798 goto out;
799 }
800
801 ath6kl_dbg(ATH6KL_DBG_BOOT, "4-bit async irq mode enabled\n");
802 }
803
804 /* give us some time to enable, in ms */
805 func->enable_timeout = 100;
806
807 ret = sdio_set_block_size(func, HIF_MBOX_BLOCK_SIZE);
808 if (ret) {
809 ath6kl_err("Set sdio block size %d failed: %d)\n",
810 HIF_MBOX_BLOCK_SIZE, ret);
Kalle Valoe28e8102011-11-01 08:44:36 +0200811 goto out;
812 }
813
814out:
815 sdio_release_host(func);
816
817 return ret;
818}
819
Raja Manie390af72012-01-30 17:13:09 +0530820static int ath6kl_set_sdio_pm_caps(struct ath6kl *ar)
Kalle Valoabcb3442011-07-22 08:26:20 +0300821{
822 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
823 struct sdio_func *func = ar_sdio->func;
824 mmc_pm_flag_t flags;
825 int ret;
826
827 flags = sdio_get_host_pm_caps(func);
828
Kalle Valob4b2a0b2011-11-01 08:44:44 +0200829 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "sdio suspend pm_caps 0x%x\n", flags);
830
Raja Manie390af72012-01-30 17:13:09 +0530831 if (!(flags & MMC_PM_WAKE_SDIO_IRQ) ||
832 !(flags & MMC_PM_KEEP_POWER))
833 return -EINVAL;
Kalle Valoabcb3442011-07-22 08:26:20 +0300834
835 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
836 if (ret) {
Raja Manie390af72012-01-30 17:13:09 +0530837 ath6kl_err("set sdio keep pwr flag failed: %d\n", ret);
Kalle Valoabcb3442011-07-22 08:26:20 +0300838 return ret;
839 }
840
Kalle Valo10509f92011-12-13 14:52:07 +0200841 /* sdio irq wakes up host */
Raja Manie390af72012-01-30 17:13:09 +0530842 ret = sdio_set_host_pm_flags(func, MMC_PM_WAKE_SDIO_IRQ);
843 if (ret)
844 ath6kl_err("set sdio wake irq flag failed: %d\n", ret);
845
846 return ret;
847}
848
849static int ath6kl_sdio_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
850{
851 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
852 struct sdio_func *func = ar_sdio->func;
853 mmc_pm_flag_t flags;
Raja Mani1e9a9052012-03-06 15:03:59 +0530854 bool try_deepsleep = false;
Raja Manie390af72012-01-30 17:13:09 +0530855 int ret;
Kalle Valo10509f92011-12-13 14:52:07 +0200856
Raja Manie390af72012-01-30 17:13:09 +0530857 if (ar->suspend_mode == WLAN_POWER_STATE_WOW ||
858 (!ar->suspend_mode && wow)) {
Raja Manie390af72012-01-30 17:13:09 +0530859 ret = ath6kl_set_sdio_pm_caps(ar);
860 if (ret)
861 goto cut_pwr;
862
Raja Manid7c44e02011-11-07 22:52:46 +0200863 ret = ath6kl_cfg80211_suspend(ar, ATH6KL_CFG_SUSPEND_WOW, wow);
Raja Mani1e9a9052012-03-06 15:03:59 +0530864 if (ret && ret != -ENOTCONN)
865 ath6kl_err("wow suspend failed: %d\n", ret);
Raja Manid7c44e02011-11-07 22:52:46 +0200866
Kalle Valo7433a492012-03-12 13:23:14 +0200867 if (ret &&
868 (!ar->wow_suspend_mode ||
869 ar->wow_suspend_mode == WLAN_POWER_STATE_DEEP_SLEEP))
870 try_deepsleep = true;
Raja Mani1e9a9052012-03-06 15:03:59 +0530871 else if (ret &&
872 ar->wow_suspend_mode == WLAN_POWER_STATE_CUT_PWR)
Kalle Valo7433a492012-03-12 13:23:14 +0200873 goto cut_pwr;
Raja Mani1e9a9052012-03-06 15:03:59 +0530874 if (!ret)
875 return 0;
Raja Manid7c44e02011-11-07 22:52:46 +0200876 }
877
Raja Manie390af72012-01-30 17:13:09 +0530878 if (ar->suspend_mode == WLAN_POWER_STATE_DEEP_SLEEP ||
Raja Mani1e9a9052012-03-06 15:03:59 +0530879 !ar->suspend_mode || try_deepsleep) {
Raja Manie390af72012-01-30 17:13:09 +0530880 flags = sdio_get_host_pm_caps(func);
881 if (!(flags & MMC_PM_KEEP_POWER))
882 goto cut_pwr;
883
884 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
885 if (ret)
886 goto cut_pwr;
887
Santosh Sajjancca4d5a2012-01-30 22:02:26 +0200888 /*
889 * Workaround to support Deep Sleep with MSM, set the host pm
890 * flag as MMC_PM_WAKE_SDIO_IRQ to allow SDCC deiver to disable
891 * the sdc2_clock and internally allows MSM to enter
892 * TCXO shutdown properly.
893 */
894 if ((flags & MMC_PM_WAKE_SDIO_IRQ)) {
895 ret = sdio_set_host_pm_flags(func,
896 MMC_PM_WAKE_SDIO_IRQ);
897 if (ret)
898 goto cut_pwr;
899 }
900
Raja Manie390af72012-01-30 17:13:09 +0530901 ret = ath6kl_cfg80211_suspend(ar, ATH6KL_CFG_SUSPEND_DEEPSLEEP,
902 NULL);
903 if (ret)
904 goto cut_pwr;
905
906 return 0;
907 }
908
909cut_pwr:
Ming Jiang56992572012-04-18 09:25:04 +0800910 if (func->card && func->card->host)
911 func->card->host->pm_flags &= ~MMC_PM_KEEP_POWER;
912
Raja Manie390af72012-01-30 17:13:09 +0530913 return ath6kl_cfg80211_suspend(ar, ATH6KL_CFG_SUSPEND_CUTPOWER, NULL);
Kalle Valoabcb3442011-07-22 08:26:20 +0300914}
915
Chilam Ngaa6cffc2011-10-05 10:12:52 +0300916static int ath6kl_sdio_resume(struct ath6kl *ar)
917{
Kalle Valob4b2a0b2011-11-01 08:44:44 +0200918 switch (ar->state) {
919 case ATH6KL_STATE_OFF:
920 case ATH6KL_STATE_CUTPOWER:
921 ath6kl_dbg(ATH6KL_DBG_SUSPEND,
922 "sdio resume configuring sdio\n");
923
924 /* need to set sdio settings after power is cut from sdio */
925 ath6kl_sdio_config(ar);
926 break;
927
928 case ATH6KL_STATE_ON:
Kalle Valob4b2a0b2011-11-01 08:44:44 +0200929 break;
930
931 case ATH6KL_STATE_DEEPSLEEP:
932 break;
Raja Manid7c44e02011-11-07 22:52:46 +0200933
934 case ATH6KL_STATE_WOW:
935 break;
Raja Mani390a8c82012-03-07 11:35:04 +0530936
Raja Mani390a8c82012-03-07 11:35:04 +0530937 case ATH6KL_STATE_SUSPENDING:
938 break;
939
940 case ATH6KL_STATE_RESUMING:
941 break;
Vasanthakumar Thiagarajan84caf802012-08-29 19:40:26 +0530942
943 case ATH6KL_STATE_RECOVERY:
944 break;
Kalle Valob4b2a0b2011-11-01 08:44:44 +0200945 }
946
Kalle Valo52d81a62011-11-01 08:44:21 +0200947 ath6kl_cfg80211_resume(ar);
Chilam Ngaa6cffc2011-10-05 10:12:52 +0300948
949 return 0;
950}
951
Kalle Valoc7111492011-11-11 12:17:51 +0200952/* set the window address register (using 4-byte register access ). */
953static int ath6kl_set_addrwin_reg(struct ath6kl *ar, u32 reg_addr, u32 addr)
954{
955 int status;
956 u8 addr_val[4];
957 s32 i;
958
959 /*
960 * Write bytes 1,2,3 of the register to set the upper address bytes,
961 * the LSB is written last to initiate the access cycle
962 */
963
964 for (i = 1; i <= 3; i++) {
965 /*
966 * Fill the buffer with the address byte value we want to
967 * hit 4 times.
968 */
969 memset(addr_val, ((u8 *)&addr)[i], 4);
970
971 /*
972 * Hit each byte of the register address with a 4-byte
973 * write operation to the same address, this is a harmless
974 * operation.
975 */
976 status = ath6kl_sdio_read_write_sync(ar, reg_addr + i, addr_val,
977 4, HIF_WR_SYNC_BYTE_FIX);
978 if (status)
979 break;
980 }
981
982 if (status) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300983 ath6kl_err("%s: failed to write initial bytes of 0x%x to window reg: 0x%X\n",
984 __func__, addr, reg_addr);
Kalle Valoc7111492011-11-11 12:17:51 +0200985 return status;
986 }
987
988 /*
989 * Write the address register again, this time write the whole
990 * 4-byte value. The effect here is that the LSB write causes the
991 * cycle to start, the extra 3 byte write to bytes 1,2,3 has no
992 * effect since we are writing the same values again
993 */
994 status = ath6kl_sdio_read_write_sync(ar, reg_addr, (u8 *)(&addr),
995 4, HIF_WR_SYNC_BYTE_INC);
996
997 if (status) {
998 ath6kl_err("%s: failed to write 0x%x to window reg: 0x%X\n",
999 __func__, addr, reg_addr);
1000 return status;
1001 }
1002
1003 return 0;
1004}
1005
1006static int ath6kl_sdio_diag_read32(struct ath6kl *ar, u32 address, u32 *data)
1007{
1008 int status;
1009
1010 /* set window register to start read cycle */
1011 status = ath6kl_set_addrwin_reg(ar, WINDOW_READ_ADDR_ADDRESS,
1012 address);
1013
1014 if (status)
1015 return status;
1016
1017 /* read the data */
1018 status = ath6kl_sdio_read_write_sync(ar, WINDOW_DATA_ADDRESS,
1019 (u8 *)data, sizeof(u32), HIF_RD_SYNC_BYTE_INC);
1020 if (status) {
1021 ath6kl_err("%s: failed to read from window data addr\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +02001022 __func__);
Kalle Valoc7111492011-11-11 12:17:51 +02001023 return status;
1024 }
1025
1026 return status;
1027}
1028
1029static int ath6kl_sdio_diag_write32(struct ath6kl *ar, u32 address,
1030 __le32 data)
1031{
1032 int status;
1033 u32 val = (__force u32) data;
1034
1035 /* set write data */
1036 status = ath6kl_sdio_read_write_sync(ar, WINDOW_DATA_ADDRESS,
1037 (u8 *) &val, sizeof(u32), HIF_WR_SYNC_BYTE_INC);
1038 if (status) {
1039 ath6kl_err("%s: failed to write 0x%x to window data addr\n",
1040 __func__, data);
1041 return status;
1042 }
1043
1044 /* set window register, which starts the write cycle */
1045 return ath6kl_set_addrwin_reg(ar, WINDOW_WRITE_ADDR_ADDRESS,
1046 address);
1047}
1048
Kalle Valo66b693c2011-11-11 12:17:33 +02001049static int ath6kl_sdio_bmi_credits(struct ath6kl *ar)
1050{
1051 u32 addr;
1052 unsigned long timeout;
1053 int ret;
1054
1055 ar->bmi.cmd_credits = 0;
1056
1057 /* Read the counter register to get the command credits */
1058 addr = COUNT_DEC_ADDRESS + (HTC_MAILBOX_NUM_MAX + ENDPOINT1) * 4;
1059
1060 timeout = jiffies + msecs_to_jiffies(BMI_COMMUNICATION_TIMEOUT);
1061 while (time_before(jiffies, timeout) && !ar->bmi.cmd_credits) {
Kalle Valo66b693c2011-11-11 12:17:33 +02001062 /*
1063 * Hit the credit counter with a 4-byte access, the first byte
1064 * read will hit the counter and cause a decrement, while the
1065 * remaining 3 bytes has no effect. The rationale behind this
1066 * is to make all HIF accesses 4-byte aligned.
1067 */
1068 ret = ath6kl_sdio_read_write_sync(ar, addr,
1069 (u8 *)&ar->bmi.cmd_credits, 4,
1070 HIF_RD_SYNC_BYTE_INC);
1071 if (ret) {
Kalle Valocdeb8602012-04-12 11:02:18 +03001072 ath6kl_err("Unable to decrement the command credit count register: %d\n",
1073 ret);
Kalle Valo66b693c2011-11-11 12:17:33 +02001074 return ret;
1075 }
1076
1077 /* The counter is only 8 bits.
1078 * Ignore anything in the upper 3 bytes
1079 */
1080 ar->bmi.cmd_credits &= 0xFF;
1081 }
1082
1083 if (!ar->bmi.cmd_credits) {
1084 ath6kl_err("bmi communication timeout\n");
1085 return -ETIMEDOUT;
1086 }
1087
1088 return 0;
1089}
1090
1091static int ath6kl_bmi_get_rx_lkahd(struct ath6kl *ar)
1092{
1093 unsigned long timeout;
1094 u32 rx_word = 0;
1095 int ret = 0;
1096
1097 timeout = jiffies + msecs_to_jiffies(BMI_COMMUNICATION_TIMEOUT);
1098 while ((time_before(jiffies, timeout)) && !rx_word) {
1099 ret = ath6kl_sdio_read_write_sync(ar,
1100 RX_LOOKAHEAD_VALID_ADDRESS,
1101 (u8 *)&rx_word, sizeof(rx_word),
1102 HIF_RD_SYNC_BYTE_INC);
1103 if (ret) {
1104 ath6kl_err("unable to read RX_LOOKAHEAD_VALID\n");
1105 return ret;
1106 }
1107
1108 /* all we really want is one bit */
1109 rx_word &= (1 << ENDPOINT1);
1110 }
1111
1112 if (!rx_word) {
1113 ath6kl_err("bmi_recv_buf FIFO empty\n");
1114 return -EINVAL;
1115 }
1116
1117 return ret;
1118}
1119
1120static int ath6kl_sdio_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
1121{
1122 int ret;
1123 u32 addr;
1124
1125 ret = ath6kl_sdio_bmi_credits(ar);
1126 if (ret)
1127 return ret;
1128
1129 addr = ar->mbox_info.htc_addr;
1130
1131 ret = ath6kl_sdio_read_write_sync(ar, addr, buf, len,
1132 HIF_WR_SYNC_BYTE_INC);
Mohammed Shafi Shajakhanbf978142013-02-22 20:20:21 +05301133 if (ret) {
Kalle Valo66b693c2011-11-11 12:17:33 +02001134 ath6kl_err("unable to send the bmi data to the device\n");
Mohammed Shafi Shajakhanbf978142013-02-22 20:20:21 +05301135 return ret;
1136 }
Kalle Valo66b693c2011-11-11 12:17:33 +02001137
Mohammed Shafi Shajakhanbf978142013-02-22 20:20:21 +05301138 return 0;
Kalle Valo66b693c2011-11-11 12:17:33 +02001139}
1140
1141static int ath6kl_sdio_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
1142{
1143 int ret;
1144 u32 addr;
1145
1146 /*
1147 * During normal bootup, small reads may be required.
1148 * Rather than issue an HIF Read and then wait as the Target
1149 * adds successive bytes to the FIFO, we wait here until
1150 * we know that response data is available.
1151 *
1152 * This allows us to cleanly timeout on an unexpected
1153 * Target failure rather than risk problems at the HIF level.
1154 * In particular, this avoids SDIO timeouts and possibly garbage
1155 * data on some host controllers. And on an interconnect
1156 * such as Compact Flash (as well as some SDIO masters) which
1157 * does not provide any indication on data timeout, it avoids
1158 * a potential hang or garbage response.
1159 *
1160 * Synchronization is more difficult for reads larger than the
1161 * size of the MBOX FIFO (128B), because the Target is unable
1162 * to push the 129th byte of data until AFTER the Host posts an
1163 * HIF Read and removes some FIFO data. So for large reads the
1164 * Host proceeds to post an HIF Read BEFORE all the data is
1165 * actually available to read. Fortunately, large BMI reads do
1166 * not occur in practice -- they're supported for debug/development.
1167 *
1168 * So Host/Target BMI synchronization is divided into these cases:
1169 * CASE 1: length < 4
1170 * Should not happen
1171 *
1172 * CASE 2: 4 <= length <= 128
1173 * Wait for first 4 bytes to be in FIFO
1174 * If CONSERVATIVE_BMI_READ is enabled, also wait for
1175 * a BMI command credit, which indicates that the ENTIRE
1176 * response is available in the the FIFO
1177 *
1178 * CASE 3: length > 128
1179 * Wait for the first 4 bytes to be in FIFO
1180 *
1181 * For most uses, a small timeout should be sufficient and we will
1182 * usually see a response quickly; but there may be some unusual
1183 * (debug) cases of BMI_EXECUTE where we want an larger timeout.
1184 * For now, we use an unbounded busy loop while waiting for
1185 * BMI_EXECUTE.
1186 *
1187 * If BMI_EXECUTE ever needs to support longer-latency execution,
1188 * especially in production, this code needs to be enhanced to sleep
1189 * and yield. Also note that BMI_COMMUNICATION_TIMEOUT is currently
1190 * a function of Host processor speed.
1191 */
1192 if (len >= 4) { /* NB: Currently, always true */
1193 ret = ath6kl_bmi_get_rx_lkahd(ar);
1194 if (ret)
1195 return ret;
1196 }
1197
1198 addr = ar->mbox_info.htc_addr;
1199 ret = ath6kl_sdio_read_write_sync(ar, addr, buf, len,
1200 HIF_RD_SYNC_BYTE_INC);
1201 if (ret) {
1202 ath6kl_err("Unable to read the bmi data from the device: %d\n",
1203 ret);
1204 return ret;
1205 }
1206
1207 return 0;
1208}
1209
Kalle Valo32a07e42011-10-30 21:15:57 +02001210static void ath6kl_sdio_stop(struct ath6kl *ar)
1211{
1212 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
1213 struct bus_request *req, *tmp_req;
1214 void *context;
1215
1216 /* FIXME: make sure that wq is not queued again */
1217
1218 cancel_work_sync(&ar_sdio->wr_async_work);
1219
1220 spin_lock_bh(&ar_sdio->wr_async_lock);
1221
1222 list_for_each_entry_safe(req, tmp_req, &ar_sdio->wr_asyncq, list) {
1223 list_del(&req->list);
1224
1225 if (req->scat_req) {
1226 /* this is a scatter gather request */
1227 req->scat_req->status = -ECANCELED;
1228 req->scat_req->complete(ar_sdio->ar->htc_target,
1229 req->scat_req);
1230 } else {
1231 context = req->packet;
1232 ath6kl_sdio_free_bus_req(ar_sdio, req);
1233 ath6kl_hif_rw_comp_handler(context, -ECANCELED);
1234 }
1235 }
1236
1237 spin_unlock_bh(&ar_sdio->wr_async_lock);
1238
1239 WARN_ON(get_queue_depth(&ar_sdio->scat_req) != 4);
1240}
1241
Kalle Valobdcd8172011-07-18 00:22:30 +03001242static const struct ath6kl_hif_ops ath6kl_sdio_ops = {
1243 .read_write_sync = ath6kl_sdio_read_write_sync,
1244 .write_async = ath6kl_sdio_write_async,
1245 .irq_enable = ath6kl_sdio_irq_enable,
1246 .irq_disable = ath6kl_sdio_irq_disable,
1247 .scatter_req_get = ath6kl_sdio_scatter_req_get,
1248 .scatter_req_add = ath6kl_sdio_scatter_req_add,
1249 .enable_scatter = ath6kl_sdio_enable_scatter,
Vasanthakumar Thiagarajanf74a7362011-07-16 20:29:05 +05301250 .scat_req_rw = ath6kl_sdio_async_rw_scatter,
Kalle Valobdcd8172011-07-18 00:22:30 +03001251 .cleanup_scatter = ath6kl_sdio_cleanup_scatter,
Kalle Valoabcb3442011-07-22 08:26:20 +03001252 .suspend = ath6kl_sdio_suspend,
Chilam Ngaa6cffc2011-10-05 10:12:52 +03001253 .resume = ath6kl_sdio_resume,
Kalle Valoc7111492011-11-11 12:17:51 +02001254 .diag_read32 = ath6kl_sdio_diag_read32,
1255 .diag_write32 = ath6kl_sdio_diag_write32,
Kalle Valo66b693c2011-11-11 12:17:33 +02001256 .bmi_read = ath6kl_sdio_bmi_read,
1257 .bmi_write = ath6kl_sdio_bmi_write,
Kalle Valob2e75692011-10-27 18:48:14 +03001258 .power_on = ath6kl_sdio_power_on,
1259 .power_off = ath6kl_sdio_power_off,
Kalle Valo32a07e42011-10-30 21:15:57 +02001260 .stop = ath6kl_sdio_stop,
Kalle Valobdcd8172011-07-18 00:22:30 +03001261};
1262
Kalle Valob4b2a0b2011-11-01 08:44:44 +02001263#ifdef CONFIG_PM_SLEEP
1264
1265/*
1266 * Empty handlers so that mmc subsystem doesn't remove us entirely during
1267 * suspend. We instead follow cfg80211 suspend/resume handlers.
1268 */
1269static int ath6kl_sdio_pm_suspend(struct device *device)
1270{
1271 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "sdio pm suspend\n");
1272
1273 return 0;
1274}
1275
1276static int ath6kl_sdio_pm_resume(struct device *device)
1277{
1278 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "sdio pm resume\n");
1279
1280 return 0;
1281}
1282
1283static SIMPLE_DEV_PM_OPS(ath6kl_sdio_pm_ops, ath6kl_sdio_pm_suspend,
1284 ath6kl_sdio_pm_resume);
1285
1286#define ATH6KL_SDIO_PM_OPS (&ath6kl_sdio_pm_ops)
1287
1288#else
1289
1290#define ATH6KL_SDIO_PM_OPS NULL
1291
1292#endif /* CONFIG_PM_SLEEP */
1293
Kalle Valobdcd8172011-07-18 00:22:30 +03001294static int ath6kl_sdio_probe(struct sdio_func *func,
1295 const struct sdio_device_id *id)
1296{
1297 int ret;
1298 struct ath6kl_sdio *ar_sdio;
1299 struct ath6kl *ar;
1300 int count;
1301
Kalle Valo3ef987b2011-10-24 12:18:07 +03001302 ath6kl_dbg(ATH6KL_DBG_BOOT,
1303 "sdio new func %d vendor 0x%x device 0x%x block 0x%x/0x%x\n",
Kalle Valof7325b82011-09-27 14:30:58 +03001304 func->num, func->vendor, func->device,
1305 func->max_blksize, func->cur_blksize);
Kalle Valobdcd8172011-07-18 00:22:30 +03001306
1307 ar_sdio = kzalloc(sizeof(struct ath6kl_sdio), GFP_KERNEL);
1308 if (!ar_sdio)
1309 return -ENOMEM;
1310
1311 ar_sdio->dma_buffer = kzalloc(HIF_DMA_BUFFER_SIZE, GFP_KERNEL);
1312 if (!ar_sdio->dma_buffer) {
1313 ret = -ENOMEM;
1314 goto err_hif;
1315 }
1316
1317 ar_sdio->func = func;
1318 sdio_set_drvdata(func, ar_sdio);
1319
1320 ar_sdio->id = id;
1321 ar_sdio->is_disabled = true;
1322
1323 spin_lock_init(&ar_sdio->lock);
1324 spin_lock_init(&ar_sdio->scat_lock);
1325 spin_lock_init(&ar_sdio->wr_async_lock);
Raja Manifdb28582011-11-21 12:26:51 +05301326 mutex_init(&ar_sdio->dma_buffer_mutex);
Kalle Valobdcd8172011-07-18 00:22:30 +03001327
1328 INIT_LIST_HEAD(&ar_sdio->scat_req);
1329 INIT_LIST_HEAD(&ar_sdio->bus_req_freeq);
1330 INIT_LIST_HEAD(&ar_sdio->wr_asyncq);
1331
1332 INIT_WORK(&ar_sdio->wr_async_work, ath6kl_sdio_write_async_work);
1333
Raja Manid1f41592012-02-09 12:57:12 +05301334 init_waitqueue_head(&ar_sdio->irq_wq);
1335
Kalle Valobdcd8172011-07-18 00:22:30 +03001336 for (count = 0; count < BUS_REQUEST_MAX_NUM; count++)
1337 ath6kl_sdio_free_bus_req(ar_sdio, &ar_sdio->bus_req[count]);
1338
Kalle Valo45eaa782012-01-17 20:09:05 +02001339 ar = ath6kl_core_create(&ar_sdio->func->dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001340 if (!ar) {
1341 ath6kl_err("Failed to alloc ath6kl core\n");
1342 ret = -ENOMEM;
1343 goto err_dma;
1344 }
1345
1346 ar_sdio->ar = ar;
Kalle Valo77eab1e2011-11-11 12:18:22 +02001347 ar->hif_type = ATH6KL_HIF_TYPE_SDIO;
Kalle Valobdcd8172011-07-18 00:22:30 +03001348 ar->hif_priv = ar_sdio;
1349 ar->hif_ops = &ath6kl_sdio_ops;
Kalle Valo1f4c8942011-11-11 12:17:42 +02001350 ar->bmi.max_data_size = 256;
Kalle Valobdcd8172011-07-18 00:22:30 +03001351
1352 ath6kl_sdio_set_mbox_info(ar);
1353
Kalle Valoe28e8102011-11-01 08:44:36 +02001354 ret = ath6kl_sdio_config(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001355 if (ret) {
Kalle Valoe28e8102011-11-01 08:44:36 +02001356 ath6kl_err("Failed to config sdio: %d\n", ret);
1357 goto err_core_alloc;
Kalle Valobdcd8172011-07-18 00:22:30 +03001358 }
1359
Kalle Valoe76ac2bf2012-03-25 17:15:27 +03001360 ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_MBOX);
Kalle Valobdcd8172011-07-18 00:22:30 +03001361 if (ret) {
1362 ath6kl_err("Failed to init ath6kl core\n");
Kalle Valoe28e8102011-11-01 08:44:36 +02001363 goto err_core_alloc;
Kalle Valobdcd8172011-07-18 00:22:30 +03001364 }
1365
1366 return ret;
1367
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301368err_core_alloc:
Kalle Valo45eaa782012-01-17 20:09:05 +02001369 ath6kl_core_destroy(ar_sdio->ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001370err_dma:
1371 kfree(ar_sdio->dma_buffer);
1372err_hif:
1373 kfree(ar_sdio);
1374
1375 return ret;
1376}
1377
1378static void ath6kl_sdio_remove(struct sdio_func *func)
1379{
1380 struct ath6kl_sdio *ar_sdio;
1381
Kalle Valo3ef987b2011-10-24 12:18:07 +03001382 ath6kl_dbg(ATH6KL_DBG_BOOT,
1383 "sdio removed func %d vendor 0x%x device 0x%x\n",
Kalle Valof7325b82011-09-27 14:30:58 +03001384 func->num, func->vendor, func->device);
1385
Kalle Valobdcd8172011-07-18 00:22:30 +03001386 ar_sdio = sdio_get_drvdata(func);
1387
1388 ath6kl_stop_txrx(ar_sdio->ar);
1389 cancel_work_sync(&ar_sdio->wr_async_work);
1390
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301391 ath6kl_core_cleanup(ar_sdio->ar);
Vasanthakumar Thiagarajan0e7de662012-01-21 15:22:49 +05301392 ath6kl_core_destroy(ar_sdio->ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001393
Kalle Valobdcd8172011-07-18 00:22:30 +03001394 kfree(ar_sdio->dma_buffer);
1395 kfree(ar_sdio);
1396}
1397
1398static const struct sdio_device_id ath6kl_sdio_devices[] = {
1399 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x0))},
1400 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x1))},
Naveen Gangadharand93e2c22011-11-11 12:18:14 +02001401 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x0))},
1402 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x1))},
Srinivas Kandagatlabeb4be82014-08-12 11:45:59 +01001403 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x2))},
Kalle Valobdcd8172011-07-18 00:22:30 +03001404 {},
1405};
1406
1407MODULE_DEVICE_TABLE(sdio, ath6kl_sdio_devices);
1408
1409static struct sdio_driver ath6kl_sdio_driver = {
Kalle Valo241b1282012-01-17 20:09:45 +02001410 .name = "ath6kl_sdio",
Kalle Valobdcd8172011-07-18 00:22:30 +03001411 .id_table = ath6kl_sdio_devices,
1412 .probe = ath6kl_sdio_probe,
1413 .remove = ath6kl_sdio_remove,
Kalle Valob4b2a0b2011-11-01 08:44:44 +02001414 .drv.pm = ATH6KL_SDIO_PM_OPS,
Kalle Valobdcd8172011-07-18 00:22:30 +03001415};
1416
1417static int __init ath6kl_sdio_init(void)
1418{
1419 int ret;
1420
1421 ret = sdio_register_driver(&ath6kl_sdio_driver);
1422 if (ret)
1423 ath6kl_err("sdio driver registration failed: %d\n", ret);
1424
1425 return ret;
1426}
1427
1428static void __exit ath6kl_sdio_exit(void)
1429{
1430 sdio_unregister_driver(&ath6kl_sdio_driver);
1431}
1432
1433module_init(ath6kl_sdio_init);
1434module_exit(ath6kl_sdio_exit);
1435
1436MODULE_AUTHOR("Atheros Communications, Inc.");
1437MODULE_DESCRIPTION("Driver support for Atheros AR600x SDIO devices");
1438MODULE_LICENSE("Dual BSD/GPL");
1439
Kalle Valoc0038972011-12-16 20:53:31 +02001440MODULE_FIRMWARE(AR6003_HW_2_0_FW_DIR "/" AR6003_HW_2_0_OTP_FILE);
1441MODULE_FIRMWARE(AR6003_HW_2_0_FW_DIR "/" AR6003_HW_2_0_FIRMWARE_FILE);
1442MODULE_FIRMWARE(AR6003_HW_2_0_FW_DIR "/" AR6003_HW_2_0_PATCH_FILE);
Kalle Valo0d0192ba2011-11-14 19:31:07 +02001443MODULE_FIRMWARE(AR6003_HW_2_0_BOARD_DATA_FILE);
1444MODULE_FIRMWARE(AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE);
Kalle Valoc0038972011-12-16 20:53:31 +02001445MODULE_FIRMWARE(AR6003_HW_2_1_1_FW_DIR "/" AR6003_HW_2_1_1_OTP_FILE);
1446MODULE_FIRMWARE(AR6003_HW_2_1_1_FW_DIR "/" AR6003_HW_2_1_1_FIRMWARE_FILE);
1447MODULE_FIRMWARE(AR6003_HW_2_1_1_FW_DIR "/" AR6003_HW_2_1_1_PATCH_FILE);
Kalle Valo0d0192ba2011-11-14 19:31:07 +02001448MODULE_FIRMWARE(AR6003_HW_2_1_1_BOARD_DATA_FILE);
1449MODULE_FIRMWARE(AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE);
Kalle Valoc0038972011-12-16 20:53:31 +02001450MODULE_FIRMWARE(AR6004_HW_1_0_FW_DIR "/" AR6004_HW_1_0_FIRMWARE_FILE);
Kalle Valof0ea5d52011-11-14 19:31:15 +02001451MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE);
1452MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE);
Kalle Valoc0038972011-12-16 20:53:31 +02001453MODULE_FIRMWARE(AR6004_HW_1_1_FW_DIR "/" AR6004_HW_1_1_FIRMWARE_FILE);
Kalle Valof0ea5d52011-11-14 19:31:15 +02001454MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE);
1455MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE);
Ray Chen6146ca62012-04-11 10:03:13 +08001456MODULE_FIRMWARE(AR6004_HW_1_2_FW_DIR "/" AR6004_HW_1_2_FIRMWARE_FILE);
1457MODULE_FIRMWARE(AR6004_HW_1_2_BOARD_DATA_FILE);
1458MODULE_FIRMWARE(AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE);
Bala Shanmugambf744f12012-07-17 12:01:55 +05301459MODULE_FIRMWARE(AR6004_HW_1_3_FW_DIR "/" AR6004_HW_1_3_FIRMWARE_FILE);
1460MODULE_FIRMWARE(AR6004_HW_1_3_BOARD_DATA_FILE);
1461MODULE_FIRMWARE(AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE);