2 * Copyright (c) 2004-2011 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/mmc/card.h>
18 #include <linux/mmc/mmc.h>
19 #include <linux/mmc/host.h>
20 #include <linux/mmc/sdio_func.h>
21 #include <linux/mmc/sdio_ids.h>
22 #include <linux/mmc/sdio.h>
23 #include <linux/mmc/sd.h>
30 struct sdio_func *func;
35 struct list_head bus_req_freeq;
37 /* available bus requests */
38 struct bus_request bus_req[BUS_REQUEST_MAX_NUM];
43 /* scatter request list head */
44 struct list_head scat_req;
48 atomic_t irq_handling;
49 const struct sdio_device_id *id;
50 struct work_struct wr_async_work;
51 struct list_head wr_asyncq;
52 spinlock_t wr_async_lock;
55 #define CMD53_ARG_READ 0
56 #define CMD53_ARG_WRITE 1
57 #define CMD53_ARG_BLOCK_BASIS 1
58 #define CMD53_ARG_FIXED_ADDRESS 0
59 #define CMD53_ARG_INCR_ADDRESS 1
61 static inline struct ath6kl_sdio *ath6kl_sdio_priv(struct ath6kl *ar)
67 * Macro to check if DMA buffer is WORD-aligned and DMA-able.
68 * Most host controllers assume the buffer is DMA'able and will
69 * bug-check otherwise (i.e. buffers on the stack). virt_addr_valid
70 * check fails on stack memory.
72 static inline bool buf_needs_bounce(u8 *buf)
74 return ((unsigned long) buf & 0x3) || !virt_addr_valid(buf);
77 static void ath6kl_sdio_set_mbox_info(struct ath6kl *ar)
79 struct ath6kl_mbox_info *mbox_info = &ar->mbox_info;
81 /* EP1 has an extended range */
82 mbox_info->htc_addr = HIF_MBOX_BASE_ADDR;
83 mbox_info->htc_ext_addr = HIF_MBOX0_EXT_BASE_ADDR;
84 mbox_info->htc_ext_sz = HIF_MBOX0_EXT_WIDTH;
85 mbox_info->block_size = HIF_MBOX_BLOCK_SIZE;
86 mbox_info->gmbox_addr = HIF_GMBOX_BASE_ADDR;
87 mbox_info->gmbox_sz = HIF_GMBOX_WIDTH;
90 static inline void ath6kl_sdio_set_cmd53_arg(u32 *arg, u8 rw, u8 func,
91 u8 mode, u8 opcode, u32 addr,
94 *arg = (((rw & 1) << 31) |
95 ((func & 0x7) << 28) |
97 ((opcode & 1) << 26) |
98 ((addr & 0x1FFFF) << 9) |
102 static inline void ath6kl_sdio_set_cmd52_arg(u32 *arg, u8 write, u8 raw,
103 unsigned int address,
108 *arg = ((write & 1) << 31) |
109 ((func & 0x7) << 28) |
112 ((address & 0x1FFFF) << 9) |
117 static int ath6kl_sdio_func0_cmd52_wr_byte(struct mmc_card *card,
118 unsigned int address,
121 struct mmc_command io_cmd;
123 memset(&io_cmd, 0, sizeof(io_cmd));
124 ath6kl_sdio_set_cmd52_arg(&io_cmd.arg, 1, 0, address, byte);
125 io_cmd.opcode = SD_IO_RW_DIRECT;
126 io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
128 return mmc_wait_for_cmd(card->host, &io_cmd, 0);
131 static int ath6kl_sdio_io(struct sdio_func *func, u32 request, u32 addr,
136 if (request & HIF_WRITE) {
137 if (addr >= HIF_MBOX_BASE_ADDR &&
138 addr <= HIF_MBOX_END_ADDR)
139 addr += (HIF_MBOX_WIDTH - len);
141 if (addr == HIF_MBOX0_EXT_BASE_ADDR)
142 addr += HIF_MBOX0_EXT_WIDTH - len;
144 if (request & HIF_FIXED_ADDRESS)
145 ret = sdio_writesb(func, addr, buf, len);
147 ret = sdio_memcpy_toio(func, addr, buf, len);
149 if (request & HIF_FIXED_ADDRESS)
150 ret = sdio_readsb(func, buf, addr, len);
152 ret = sdio_memcpy_fromio(func, buf, addr, len);
158 static struct bus_request *ath6kl_sdio_alloc_busreq(struct ath6kl_sdio *ar_sdio)
160 struct bus_request *bus_req;
163 spin_lock_irqsave(&ar_sdio->lock, flag);
165 if (list_empty(&ar_sdio->bus_req_freeq)) {
166 spin_unlock_irqrestore(&ar_sdio->lock, flag);
170 bus_req = list_first_entry(&ar_sdio->bus_req_freeq,
171 struct bus_request, list);
172 list_del(&bus_req->list);
174 spin_unlock_irqrestore(&ar_sdio->lock, flag);
175 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: bus request 0x%p\n", __func__, bus_req);
180 static void ath6kl_sdio_free_bus_req(struct ath6kl_sdio *ar_sdio,
181 struct bus_request *bus_req)
185 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: bus request 0x%p\n", __func__, bus_req);
187 spin_lock_irqsave(&ar_sdio->lock, flag);
188 list_add_tail(&bus_req->list, &ar_sdio->bus_req_freeq);
189 spin_unlock_irqrestore(&ar_sdio->lock, flag);
192 static void ath6kl_sdio_setup_scat_data(struct hif_scatter_req *scat_req,
193 struct mmc_data *data)
195 struct scatterlist *sg;
198 data->blksz = HIF_MBOX_BLOCK_SIZE;
199 data->blocks = scat_req->len / HIF_MBOX_BLOCK_SIZE;
201 ath6kl_dbg(ATH6KL_DBG_SCATTER,
202 "hif-scatter: (%s) addr: 0x%X, (block len: %d, block count: %d) , (tot:%d,sg:%d)\n",
203 (scat_req->req & HIF_WRITE) ? "WR" : "RD", scat_req->addr,
204 data->blksz, data->blocks, scat_req->len,
205 scat_req->scat_entries);
207 data->flags = (scat_req->req & HIF_WRITE) ? MMC_DATA_WRITE :
210 /* fill SG entries */
211 sg = scat_req->sgentries;
212 sg_init_table(sg, scat_req->scat_entries);
214 /* assemble SG list */
215 for (i = 0; i < scat_req->scat_entries; i++, sg++) {
216 ath6kl_dbg(ATH6KL_DBG_SCATTER, "%d: addr:0x%p, len:%d\n",
217 i, scat_req->scat_list[i].buf,
218 scat_req->scat_list[i].len);
220 sg_set_buf(sg, scat_req->scat_list[i].buf,
221 scat_req->scat_list[i].len);
224 /* set scatter-gather table for request */
225 data->sg = scat_req->sgentries;
226 data->sg_len = scat_req->scat_entries;
229 static int ath6kl_sdio_scat_rw(struct ath6kl_sdio *ar_sdio,
230 struct bus_request *req)
232 struct mmc_request mmc_req;
233 struct mmc_command cmd;
234 struct mmc_data data;
235 struct hif_scatter_req *scat_req;
239 scat_req = req->scat_req;
241 if (scat_req->virt_scat) {
243 if (scat_req->req & HIF_BLOCK_BASIS)
244 len = round_down(len, HIF_MBOX_BLOCK_SIZE);
246 status = ath6kl_sdio_io(ar_sdio->func, scat_req->req,
247 scat_req->addr, scat_req->virt_dma_buf,
252 memset(&mmc_req, 0, sizeof(struct mmc_request));
253 memset(&cmd, 0, sizeof(struct mmc_command));
254 memset(&data, 0, sizeof(struct mmc_data));
256 ath6kl_sdio_setup_scat_data(scat_req, &data);
258 opcode = (scat_req->req & HIF_FIXED_ADDRESS) ?
259 CMD53_ARG_FIXED_ADDRESS : CMD53_ARG_INCR_ADDRESS;
261 rw = (scat_req->req & HIF_WRITE) ? CMD53_ARG_WRITE : CMD53_ARG_READ;
263 /* Fixup the address so that the last byte will fall on MBOX EOM */
264 if (scat_req->req & HIF_WRITE) {
265 if (scat_req->addr == HIF_MBOX_BASE_ADDR)
266 scat_req->addr += HIF_MBOX_WIDTH - scat_req->len;
268 /* Uses extended address range */
269 scat_req->addr += HIF_MBOX0_EXT_WIDTH - scat_req->len;
272 /* set command argument */
273 ath6kl_sdio_set_cmd53_arg(&cmd.arg, rw, ar_sdio->func->num,
274 CMD53_ARG_BLOCK_BASIS, opcode, scat_req->addr,
277 cmd.opcode = SD_IO_RW_EXTENDED;
278 cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
281 mmc_req.data = &data;
283 mmc_set_data_timeout(&data, ar_sdio->func->card);
284 /* synchronous call to process request */
285 mmc_wait_for_req(ar_sdio->func->card->host, &mmc_req);
287 status = cmd.error ? cmd.error : data.error;
290 scat_req->status = status;
292 if (scat_req->status)
293 ath6kl_err("Scatter write request failed:%d\n",
296 if (scat_req->req & HIF_ASYNCHRONOUS)
297 scat_req->complete(ar_sdio->ar->htc_target, scat_req);
302 static int ath6kl_sdio_alloc_prep_scat_req(struct ath6kl_sdio *ar_sdio,
303 int n_scat_entry, int n_scat_req,
306 struct hif_scatter_req *s_req;
307 struct bus_request *bus_req;
308 int i, scat_req_sz, scat_list_sz, sg_sz, buf_sz;
311 scat_list_sz = (n_scat_entry - 1) * sizeof(struct hif_scatter_item);
312 scat_req_sz = sizeof(*s_req) + scat_list_sz;
315 sg_sz = sizeof(struct scatterlist) * n_scat_entry;
317 buf_sz = 2 * L1_CACHE_BYTES +
318 ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER;
320 for (i = 0; i < n_scat_req; i++) {
321 /* allocate the scatter request */
322 s_req = kzalloc(scat_req_sz, GFP_KERNEL);
327 virt_buf = kzalloc(buf_sz, GFP_KERNEL);
333 s_req->virt_dma_buf =
334 (u8 *)L1_CACHE_ALIGN((unsigned long)virt_buf);
336 /* allocate sglist */
337 s_req->sgentries = kzalloc(sg_sz, GFP_KERNEL);
339 if (!s_req->sgentries) {
345 /* allocate a bus request for this scatter request */
346 bus_req = ath6kl_sdio_alloc_busreq(ar_sdio);
348 kfree(s_req->sgentries);
349 kfree(s_req->virt_dma_buf);
354 /* assign the scatter request to this bus request */
355 bus_req->scat_req = s_req;
356 s_req->busrequest = bus_req;
358 s_req->virt_scat = virt_scat;
360 /* add it to the scatter pool */
361 hif_scatter_req_add(ar_sdio->ar, s_req);
367 static int ath6kl_sdio_read_write_sync(struct ath6kl *ar, u32 addr, u8 *buf,
368 u32 len, u32 request)
370 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
373 bool bounced = false;
375 if (request & HIF_BLOCK_BASIS)
376 len = round_down(len, HIF_MBOX_BLOCK_SIZE);
378 if (buf_needs_bounce(buf)) {
379 if (!ar_sdio->dma_buffer)
381 tbuf = ar_sdio->dma_buffer;
382 memcpy(tbuf, buf, len);
387 sdio_claim_host(ar_sdio->func);
388 ret = ath6kl_sdio_io(ar_sdio->func, request, addr, tbuf, len);
389 if ((request & HIF_READ) && bounced)
390 memcpy(buf, tbuf, len);
391 sdio_release_host(ar_sdio->func);
396 static void __ath6kl_sdio_write_async(struct ath6kl_sdio *ar_sdio,
397 struct bus_request *req)
400 ath6kl_sdio_scat_rw(ar_sdio, req);
405 status = ath6kl_sdio_read_write_sync(ar_sdio->ar, req->address,
406 req->buffer, req->length,
408 context = req->packet;
409 ath6kl_sdio_free_bus_req(ar_sdio, req);
410 ath6kldev_rw_comp_handler(context, status);
414 static void ath6kl_sdio_write_async_work(struct work_struct *work)
416 struct ath6kl_sdio *ar_sdio;
418 struct bus_request *req, *tmp_req;
420 ar_sdio = container_of(work, struct ath6kl_sdio, wr_async_work);
421 sdio_claim_host(ar_sdio->func);
423 spin_lock_irqsave(&ar_sdio->wr_async_lock, flags);
424 list_for_each_entry_safe(req, tmp_req, &ar_sdio->wr_asyncq, list) {
425 list_del(&req->list);
426 spin_unlock_irqrestore(&ar_sdio->wr_async_lock, flags);
427 __ath6kl_sdio_write_async(ar_sdio, req);
428 spin_lock_irqsave(&ar_sdio->wr_async_lock, flags);
430 spin_unlock_irqrestore(&ar_sdio->wr_async_lock, flags);
432 sdio_release_host(ar_sdio->func);
435 static void ath6kl_sdio_irq_handler(struct sdio_func *func)
438 struct ath6kl_sdio *ar_sdio;
440 ar_sdio = sdio_get_drvdata(func);
441 atomic_set(&ar_sdio->irq_handling, 1);
444 * Release the host during interrups so we can pick it back up when
445 * we process commands.
447 sdio_release_host(ar_sdio->func);
449 status = ath6kldev_intr_bh_handler(ar_sdio->ar);
450 sdio_claim_host(ar_sdio->func);
451 atomic_set(&ar_sdio->irq_handling, 0);
452 WARN_ON(status && status != -ECANCELED);
455 static int ath6kl_sdio_power_on(struct ath6kl_sdio *ar_sdio)
457 struct sdio_func *func = ar_sdio->func;
460 if (!ar_sdio->is_disabled)
463 sdio_claim_host(func);
465 ret = sdio_enable_func(func);
467 ath6kl_err("Unable to enable sdio func: %d)\n", ret);
468 sdio_release_host(func);
472 sdio_release_host(func);
475 * Wait for hardware to initialise. It should take a lot less than
476 * 10 ms but let's be conservative here.
480 ar_sdio->is_disabled = false;
485 static int ath6kl_sdio_power_off(struct ath6kl_sdio *ar_sdio)
489 if (ar_sdio->is_disabled)
492 /* Disable the card */
493 sdio_claim_host(ar_sdio->func);
494 ret = sdio_disable_func(ar_sdio->func);
495 sdio_release_host(ar_sdio->func);
500 ar_sdio->is_disabled = true;
505 static int ath6kl_sdio_write_async(struct ath6kl *ar, u32 address, u8 *buffer,
506 u32 length, u32 request,
507 struct htc_packet *packet)
509 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
510 struct bus_request *bus_req;
513 bus_req = ath6kl_sdio_alloc_busreq(ar_sdio);
518 bus_req->address = address;
519 bus_req->buffer = buffer;
520 bus_req->length = length;
521 bus_req->request = request;
522 bus_req->packet = packet;
524 spin_lock_irqsave(&ar_sdio->wr_async_lock, flags);
525 list_add_tail(&bus_req->list, &ar_sdio->wr_asyncq);
526 spin_unlock_irqrestore(&ar_sdio->wr_async_lock, flags);
527 queue_work(ar->ath6kl_wq, &ar_sdio->wr_async_work);
532 static void ath6kl_sdio_irq_enable(struct ath6kl *ar)
534 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
537 sdio_claim_host(ar_sdio->func);
539 /* Register the isr */
540 ret = sdio_claim_irq(ar_sdio->func, ath6kl_sdio_irq_handler);
542 ath6kl_err("Failed to claim sdio irq: %d\n", ret);
544 sdio_release_host(ar_sdio->func);
547 static void ath6kl_sdio_irq_disable(struct ath6kl *ar)
549 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
552 sdio_claim_host(ar_sdio->func);
554 /* Mask our function IRQ */
555 while (atomic_read(&ar_sdio->irq_handling)) {
556 sdio_release_host(ar_sdio->func);
557 schedule_timeout(HZ / 10);
558 sdio_claim_host(ar_sdio->func);
561 ret = sdio_release_irq(ar_sdio->func);
563 ath6kl_err("Failed to release sdio irq: %d\n", ret);
565 sdio_release_host(ar_sdio->func);
568 static struct hif_scatter_req *ath6kl_sdio_scatter_req_get(struct ath6kl *ar)
570 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
571 struct hif_scatter_req *node = NULL;
574 spin_lock_irqsave(&ar_sdio->scat_lock, flag);
576 if (!list_empty(&ar_sdio->scat_req)) {
577 node = list_first_entry(&ar_sdio->scat_req,
578 struct hif_scatter_req, list);
579 list_del(&node->list);
582 spin_unlock_irqrestore(&ar_sdio->scat_lock, flag);
587 static void ath6kl_sdio_scatter_req_add(struct ath6kl *ar,
588 struct hif_scatter_req *s_req)
590 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
593 spin_lock_irqsave(&ar_sdio->scat_lock, flag);
595 list_add_tail(&s_req->list, &ar_sdio->scat_req);
597 spin_unlock_irqrestore(&ar_sdio->scat_lock, flag);
601 /* scatter gather read write request */
602 static int ath6kl_sdio_async_rw_scatter(struct ath6kl *ar,
603 struct hif_scatter_req *scat_req)
605 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
606 u32 request = scat_req->req;
613 ath6kl_dbg(ATH6KL_DBG_SCATTER,
614 "hif-scatter: total len: %d scatter entries: %d\n",
615 scat_req->len, scat_req->scat_entries);
617 if (request & HIF_SYNCHRONOUS) {
618 sdio_claim_host(ar_sdio->func);
619 status = ath6kl_sdio_scat_rw(ar_sdio, scat_req->busrequest);
620 sdio_release_host(ar_sdio->func);
622 spin_lock_irqsave(&ar_sdio->wr_async_lock, flags);
623 list_add_tail(&scat_req->busrequest->list, &ar_sdio->wr_asyncq);
624 spin_unlock_irqrestore(&ar_sdio->wr_async_lock, flags);
625 queue_work(ar->ath6kl_wq, &ar_sdio->wr_async_work);
631 /* clean up scatter support */
632 static void ath6kl_sdio_cleanup_scatter(struct ath6kl *ar)
634 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
635 struct hif_scatter_req *s_req, *tmp_req;
638 /* empty the free list */
639 spin_lock_irqsave(&ar_sdio->scat_lock, flag);
640 list_for_each_entry_safe(s_req, tmp_req, &ar_sdio->scat_req, list) {
641 list_del(&s_req->list);
642 spin_unlock_irqrestore(&ar_sdio->scat_lock, flag);
644 if (s_req->busrequest)
645 ath6kl_sdio_free_bus_req(ar_sdio, s_req->busrequest);
646 kfree(s_req->virt_dma_buf);
647 kfree(s_req->sgentries);
650 spin_lock_irqsave(&ar_sdio->scat_lock, flag);
652 spin_unlock_irqrestore(&ar_sdio->scat_lock, flag);
655 /* setup of HIF scatter resources */
656 static int ath6kl_sdio_enable_scatter(struct ath6kl *ar)
658 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
659 struct htc_target *target = ar->htc_target;
661 bool virt_scat = false;
663 /* check if host supports scatter and it meets our requirements */
664 if (ar_sdio->func->card->host->max_segs < MAX_SCATTER_ENTRIES_PER_REQ) {
665 ath6kl_err("host only supports scatter of :%d entries, need: %d\n",
666 ar_sdio->func->card->host->max_segs,
667 MAX_SCATTER_ENTRIES_PER_REQ);
672 ret = ath6kl_sdio_alloc_prep_scat_req(ar_sdio,
673 MAX_SCATTER_ENTRIES_PER_REQ,
674 MAX_SCATTER_REQUESTS, virt_scat);
677 ath6kl_dbg(ATH6KL_DBG_ANY,
678 "hif-scatter enabled: max scatter req : %d entries: %d\n",
679 MAX_SCATTER_REQUESTS,
680 MAX_SCATTER_ENTRIES_PER_REQ);
682 target->max_scat_entries = MAX_SCATTER_ENTRIES_PER_REQ;
683 target->max_xfer_szper_scatreq =
684 MAX_SCATTER_REQ_TRANSFER_SIZE;
686 ath6kl_sdio_cleanup_scatter(ar);
687 ath6kl_warn("hif scatter resource setup failed, trying virtual scatter method\n");
691 if (virt_scat || ret) {
692 ret = ath6kl_sdio_alloc_prep_scat_req(ar_sdio,
693 ATH6KL_SCATTER_ENTRIES_PER_REQ,
694 ATH6KL_SCATTER_REQS, virt_scat);
697 ath6kl_err("failed to alloc virtual scatter resources !\n");
698 ath6kl_sdio_cleanup_scatter(ar);
702 ath6kl_dbg(ATH6KL_DBG_ANY,
703 "Vitual scatter enabled, max_scat_req:%d, entries:%d\n",
704 ATH6KL_SCATTER_REQS, ATH6KL_SCATTER_ENTRIES_PER_REQ);
706 target->max_scat_entries = ATH6KL_SCATTER_ENTRIES_PER_REQ;
707 target->max_xfer_szper_scatreq =
708 ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER;
714 static int ath6kl_sdio_suspend(struct ath6kl *ar)
716 struct ath6kl_sdio *ar_sdio = ath6kl_sdio_priv(ar);
717 struct sdio_func *func = ar_sdio->func;
721 flags = sdio_get_host_pm_caps(func);
723 if (!(flags & MMC_PM_KEEP_POWER))
724 /* as host doesn't support keep power we need to bail out */
727 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
729 printk(KERN_ERR "ath6kl: set sdio pm flags failed: %d\n",
734 ath6kl_deep_sleep_enable(ar);
739 static const struct ath6kl_hif_ops ath6kl_sdio_ops = {
740 .read_write_sync = ath6kl_sdio_read_write_sync,
741 .write_async = ath6kl_sdio_write_async,
742 .irq_enable = ath6kl_sdio_irq_enable,
743 .irq_disable = ath6kl_sdio_irq_disable,
744 .scatter_req_get = ath6kl_sdio_scatter_req_get,
745 .scatter_req_add = ath6kl_sdio_scatter_req_add,
746 .enable_scatter = ath6kl_sdio_enable_scatter,
747 .scat_req_rw = ath6kl_sdio_async_rw_scatter,
748 .cleanup_scatter = ath6kl_sdio_cleanup_scatter,
749 .suspend = ath6kl_sdio_suspend,
752 static int ath6kl_sdio_probe(struct sdio_func *func,
753 const struct sdio_device_id *id)
756 struct ath6kl_sdio *ar_sdio;
760 ath6kl_dbg(ATH6KL_DBG_TRC,
761 "%s: func: 0x%X, vendor id: 0x%X, dev id: 0x%X, block size: 0x%X/0x%X\n",
762 __func__, func->num, func->vendor,
763 func->device, func->max_blksize, func->cur_blksize);
765 ar_sdio = kzalloc(sizeof(struct ath6kl_sdio), GFP_KERNEL);
769 ar_sdio->dma_buffer = kzalloc(HIF_DMA_BUFFER_SIZE, GFP_KERNEL);
770 if (!ar_sdio->dma_buffer) {
775 ar_sdio->func = func;
776 sdio_set_drvdata(func, ar_sdio);
779 ar_sdio->is_disabled = true;
781 spin_lock_init(&ar_sdio->lock);
782 spin_lock_init(&ar_sdio->scat_lock);
783 spin_lock_init(&ar_sdio->wr_async_lock);
785 INIT_LIST_HEAD(&ar_sdio->scat_req);
786 INIT_LIST_HEAD(&ar_sdio->bus_req_freeq);
787 INIT_LIST_HEAD(&ar_sdio->wr_asyncq);
789 INIT_WORK(&ar_sdio->wr_async_work, ath6kl_sdio_write_async_work);
791 for (count = 0; count < BUS_REQUEST_MAX_NUM; count++)
792 ath6kl_sdio_free_bus_req(ar_sdio, &ar_sdio->bus_req[count]);
794 ar = ath6kl_core_alloc(&ar_sdio->func->dev);
796 ath6kl_err("Failed to alloc ath6kl core\n");
802 ar->hif_priv = ar_sdio;
803 ar->hif_ops = &ath6kl_sdio_ops;
805 ath6kl_sdio_set_mbox_info(ar);
807 sdio_claim_host(func);
809 if ((ar_sdio->id->device & MANUFACTURER_ID_ATH6KL_BASE_MASK) >=
810 MANUFACTURER_ID_AR6003_BASE) {
811 /* enable 4-bit ASYNC interrupt on AR6003 or later */
812 ret = ath6kl_sdio_func0_cmd52_wr_byte(func->card,
813 CCCR_SDIO_IRQ_MODE_REG,
814 SDIO_IRQ_MODE_ASYNC_4BIT_IRQ);
816 ath6kl_err("Failed to enable 4-bit async irq mode %d\n",
818 sdio_release_host(func);
822 ath6kl_dbg(ATH6KL_DBG_TRC, "4-bit async irq mode enabled\n");
825 /* give us some time to enable, in ms */
826 func->enable_timeout = 100;
828 sdio_release_host(func);
830 ret = ath6kl_sdio_power_on(ar_sdio);
834 sdio_claim_host(func);
836 ret = sdio_set_block_size(func, HIF_MBOX_BLOCK_SIZE);
838 ath6kl_err("Set sdio block size %d failed: %d)\n",
839 HIF_MBOX_BLOCK_SIZE, ret);
840 sdio_release_host(func);
844 sdio_release_host(func);
846 ret = ath6kl_core_init(ar);
848 ath6kl_err("Failed to init ath6kl core\n");
855 ath6kl_sdio_power_off(ar_sdio);
857 kfree(ar_sdio->dma_buffer);
864 static void ath6kl_sdio_remove(struct sdio_func *func)
866 struct ath6kl_sdio *ar_sdio;
868 ar_sdio = sdio_get_drvdata(func);
870 ath6kl_stop_txrx(ar_sdio->ar);
871 cancel_work_sync(&ar_sdio->wr_async_work);
873 ath6kl_unavail_ev(ar_sdio->ar);
875 ath6kl_sdio_power_off(ar_sdio);
877 kfree(ar_sdio->dma_buffer);
881 static const struct sdio_device_id ath6kl_sdio_devices[] = {
882 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x0))},
883 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x1))},
887 MODULE_DEVICE_TABLE(sdio, ath6kl_sdio_devices);
889 static struct sdio_driver ath6kl_sdio_driver = {
890 .name = "ath6kl_sdio",
891 .id_table = ath6kl_sdio_devices,
892 .probe = ath6kl_sdio_probe,
893 .remove = ath6kl_sdio_remove,
896 static int __init ath6kl_sdio_init(void)
900 ret = sdio_register_driver(&ath6kl_sdio_driver);
902 ath6kl_err("sdio driver registration failed: %d\n", ret);
907 static void __exit ath6kl_sdio_exit(void)
909 sdio_unregister_driver(&ath6kl_sdio_driver);
912 module_init(ath6kl_sdio_init);
913 module_exit(ath6kl_sdio_exit);
915 MODULE_AUTHOR("Atheros Communications, Inc.");
916 MODULE_DESCRIPTION("Driver support for Atheros AR600x SDIO devices");
917 MODULE_LICENSE("Dual BSD/GPL");
919 MODULE_FIRMWARE(AR6003_REV2_OTP_FILE);
920 MODULE_FIRMWARE(AR6003_REV2_FIRMWARE_FILE);
921 MODULE_FIRMWARE(AR6003_REV2_PATCH_FILE);
922 MODULE_FIRMWARE(AR6003_REV2_BOARD_DATA_FILE);
923 MODULE_FIRMWARE(AR6003_REV2_DEFAULT_BOARD_DATA_FILE);
924 MODULE_FIRMWARE(AR6003_REV3_OTP_FILE);
925 MODULE_FIRMWARE(AR6003_REV3_FIRMWARE_FILE);
926 MODULE_FIRMWARE(AR6003_REV3_PATCH_FILE);
927 MODULE_FIRMWARE(AR6003_REV3_BOARD_DATA_FILE);
928 MODULE_FIRMWARE(AR6003_REV3_DEFAULT_BOARD_DATA_FILE);