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 if ((unsigned long)scat_req
->scat_list
[i
].buf
& 0x3)
218 * Some scatter engines can handle unaligned
219 * buffers, print this as informational only.
221 ath6kl_dbg(ATH6KL_DBG_SCATTER
,
222 "(%s) scatter buffer is unaligned 0x%p\n",
223 scat_req
->req
& HIF_WRITE
? "WR" : "RD",
224 scat_req
->scat_list
[i
].buf
);
226 ath6kl_dbg(ATH6KL_DBG_SCATTER
, "%d: addr:0x%p, len:%d\n",
227 i
, scat_req
->scat_list
[i
].buf
,
228 scat_req
->scat_list
[i
].len
);
230 sg_set_buf(sg
, scat_req
->scat_list
[i
].buf
,
231 scat_req
->scat_list
[i
].len
);
234 /* set scatter-gather table for request */
235 data
->sg
= scat_req
->sgentries
;
236 data
->sg_len
= scat_req
->scat_entries
;
239 static int ath6kl_sdio_scat_rw(struct ath6kl_sdio
*ar_sdio
,
240 struct bus_request
*req
)
242 struct mmc_request mmc_req
;
243 struct mmc_command cmd
;
244 struct mmc_data data
;
245 struct hif_scatter_req
*scat_req
;
249 scat_req
= req
->scat_req
;
251 if (scat_req
->virt_scat
) {
253 if (scat_req
->req
& HIF_BLOCK_BASIS
)
254 len
= round_down(len
, HIF_MBOX_BLOCK_SIZE
);
256 status
= ath6kl_sdio_io(ar_sdio
->func
, scat_req
->req
,
257 scat_req
->addr
, scat_req
->virt_dma_buf
,
262 memset(&mmc_req
, 0, sizeof(struct mmc_request
));
263 memset(&cmd
, 0, sizeof(struct mmc_command
));
264 memset(&data
, 0, sizeof(struct mmc_data
));
266 ath6kl_sdio_setup_scat_data(scat_req
, &data
);
268 opcode
= (scat_req
->req
& HIF_FIXED_ADDRESS
) ?
269 CMD53_ARG_FIXED_ADDRESS
: CMD53_ARG_INCR_ADDRESS
;
271 rw
= (scat_req
->req
& HIF_WRITE
) ? CMD53_ARG_WRITE
: CMD53_ARG_READ
;
273 /* Fixup the address so that the last byte will fall on MBOX EOM */
274 if (scat_req
->req
& HIF_WRITE
) {
275 if (scat_req
->addr
== HIF_MBOX_BASE_ADDR
)
276 scat_req
->addr
+= HIF_MBOX_WIDTH
- scat_req
->len
;
278 /* Uses extended address range */
279 scat_req
->addr
+= HIF_MBOX0_EXT_WIDTH
- scat_req
->len
;
282 /* set command argument */
283 ath6kl_sdio_set_cmd53_arg(&cmd
.arg
, rw
, ar_sdio
->func
->num
,
284 CMD53_ARG_BLOCK_BASIS
, opcode
, scat_req
->addr
,
287 cmd
.opcode
= SD_IO_RW_EXTENDED
;
288 cmd
.flags
= MMC_RSP_SPI_R5
| MMC_RSP_R5
| MMC_CMD_ADTC
;
291 mmc_req
.data
= &data
;
293 mmc_set_data_timeout(&data
, ar_sdio
->func
->card
);
294 /* synchronous call to process request */
295 mmc_wait_for_req(ar_sdio
->func
->card
->host
, &mmc_req
);
297 status
= cmd
.error
? cmd
.error
: data
.error
;
300 scat_req
->status
= status
;
302 if (scat_req
->status
)
303 ath6kl_err("Scatter write request failed:%d\n",
306 if (scat_req
->req
& HIF_ASYNCHRONOUS
)
307 scat_req
->complete(ar_sdio
->ar
->htc_target
, scat_req
);
312 static int ath6kl_sdio_alloc_prep_scat_req(struct ath6kl_sdio
*ar_sdio
,
313 int n_scat_entry
, int n_scat_req
,
316 struct hif_scatter_req
*s_req
;
317 struct bus_request
*bus_req
;
318 int i
, scat_req_sz
, scat_list_sz
, sg_sz
, buf_sz
;
321 scat_list_sz
= (n_scat_entry
- 1) * sizeof(struct hif_scatter_item
);
322 scat_req_sz
= sizeof(*s_req
) + scat_list_sz
;
325 sg_sz
= sizeof(struct scatterlist
) * n_scat_entry
;
327 buf_sz
= 2 * L1_CACHE_BYTES
+
328 ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER
;
330 for (i
= 0; i
< n_scat_req
; i
++) {
331 /* allocate the scatter request */
332 s_req
= kzalloc(scat_req_sz
, GFP_KERNEL
);
337 virt_buf
= kzalloc(buf_sz
, GFP_KERNEL
);
343 s_req
->virt_dma_buf
=
344 (u8
*)L1_CACHE_ALIGN((unsigned long)virt_buf
);
346 /* allocate sglist */
347 s_req
->sgentries
= kzalloc(sg_sz
, GFP_KERNEL
);
349 if (!s_req
->sgentries
) {
355 /* allocate a bus request for this scatter request */
356 bus_req
= ath6kl_sdio_alloc_busreq(ar_sdio
);
358 kfree(s_req
->sgentries
);
359 kfree(s_req
->virt_dma_buf
);
364 /* assign the scatter request to this bus request */
365 bus_req
->scat_req
= s_req
;
366 s_req
->busrequest
= bus_req
;
368 s_req
->virt_scat
= virt_scat
;
370 /* add it to the scatter pool */
371 hif_scatter_req_add(ar_sdio
->ar
, s_req
);
377 static int ath6kl_sdio_read_write_sync(struct ath6kl
*ar
, u32 addr
, u8
*buf
,
378 u32 len
, u32 request
)
380 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
383 bool bounced
= false;
385 if (request
& HIF_BLOCK_BASIS
)
386 len
= round_down(len
, HIF_MBOX_BLOCK_SIZE
);
388 if (buf_needs_bounce(buf
)) {
389 if (!ar_sdio
->dma_buffer
)
391 tbuf
= ar_sdio
->dma_buffer
;
392 memcpy(tbuf
, buf
, len
);
397 sdio_claim_host(ar_sdio
->func
);
398 ret
= ath6kl_sdio_io(ar_sdio
->func
, request
, addr
, tbuf
, len
);
399 if ((request
& HIF_READ
) && bounced
)
400 memcpy(buf
, tbuf
, len
);
401 sdio_release_host(ar_sdio
->func
);
406 static void __ath6kl_sdio_write_async(struct ath6kl_sdio
*ar_sdio
,
407 struct bus_request
*req
)
410 ath6kl_sdio_scat_rw(ar_sdio
, req
);
415 status
= ath6kl_sdio_read_write_sync(ar_sdio
->ar
, req
->address
,
416 req
->buffer
, req
->length
,
418 context
= req
->packet
;
419 ath6kl_sdio_free_bus_req(ar_sdio
, req
);
420 ath6kldev_rw_comp_handler(context
, status
);
424 static void ath6kl_sdio_write_async_work(struct work_struct
*work
)
426 struct ath6kl_sdio
*ar_sdio
;
428 struct bus_request
*req
, *tmp_req
;
430 ar_sdio
= container_of(work
, struct ath6kl_sdio
, wr_async_work
);
431 sdio_claim_host(ar_sdio
->func
);
433 spin_lock_irqsave(&ar_sdio
->wr_async_lock
, flags
);
434 list_for_each_entry_safe(req
, tmp_req
, &ar_sdio
->wr_asyncq
, list
) {
435 list_del(&req
->list
);
436 spin_unlock_irqrestore(&ar_sdio
->wr_async_lock
, flags
);
437 __ath6kl_sdio_write_async(ar_sdio
, req
);
438 spin_lock_irqsave(&ar_sdio
->wr_async_lock
, flags
);
440 spin_unlock_irqrestore(&ar_sdio
->wr_async_lock
, flags
);
442 sdio_release_host(ar_sdio
->func
);
445 static void ath6kl_sdio_irq_handler(struct sdio_func
*func
)
448 struct ath6kl_sdio
*ar_sdio
;
450 ar_sdio
= sdio_get_drvdata(func
);
451 atomic_set(&ar_sdio
->irq_handling
, 1);
454 * Release the host during interrups so we can pick it back up when
455 * we process commands.
457 sdio_release_host(ar_sdio
->func
);
459 status
= ath6kldev_intr_bh_handler(ar_sdio
->ar
);
460 sdio_claim_host(ar_sdio
->func
);
461 atomic_set(&ar_sdio
->irq_handling
, 0);
462 WARN_ON(status
&& status
!= -ECANCELED
);
465 static int ath6kl_sdio_power_on(struct ath6kl_sdio
*ar_sdio
)
467 struct sdio_func
*func
= ar_sdio
->func
;
470 if (!ar_sdio
->is_disabled
)
473 sdio_claim_host(func
);
475 ret
= sdio_enable_func(func
);
477 ath6kl_err("Unable to enable sdio func: %d)\n", ret
);
478 sdio_release_host(func
);
482 sdio_release_host(func
);
485 * Wait for hardware to initialise. It should take a lot less than
486 * 10 ms but let's be conservative here.
490 ar_sdio
->is_disabled
= false;
495 static int ath6kl_sdio_power_off(struct ath6kl_sdio
*ar_sdio
)
499 if (ar_sdio
->is_disabled
)
502 /* Disable the card */
503 sdio_claim_host(ar_sdio
->func
);
504 ret
= sdio_disable_func(ar_sdio
->func
);
505 sdio_release_host(ar_sdio
->func
);
510 ar_sdio
->is_disabled
= true;
515 static int ath6kl_sdio_write_async(struct ath6kl
*ar
, u32 address
, u8
*buffer
,
516 u32 length
, u32 request
,
517 struct htc_packet
*packet
)
519 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
520 struct bus_request
*bus_req
;
523 bus_req
= ath6kl_sdio_alloc_busreq(ar_sdio
);
528 bus_req
->address
= address
;
529 bus_req
->buffer
= buffer
;
530 bus_req
->length
= length
;
531 bus_req
->request
= request
;
532 bus_req
->packet
= packet
;
534 spin_lock_irqsave(&ar_sdio
->wr_async_lock
, flags
);
535 list_add_tail(&bus_req
->list
, &ar_sdio
->wr_asyncq
);
536 spin_unlock_irqrestore(&ar_sdio
->wr_async_lock
, flags
);
537 queue_work(ar
->ath6kl_wq
, &ar_sdio
->wr_async_work
);
542 static void ath6kl_sdio_irq_enable(struct ath6kl
*ar
)
544 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
547 sdio_claim_host(ar_sdio
->func
);
549 /* Register the isr */
550 ret
= sdio_claim_irq(ar_sdio
->func
, ath6kl_sdio_irq_handler
);
552 ath6kl_err("Failed to claim sdio irq: %d\n", ret
);
554 sdio_release_host(ar_sdio
->func
);
557 static void ath6kl_sdio_irq_disable(struct ath6kl
*ar
)
559 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
562 sdio_claim_host(ar_sdio
->func
);
564 /* Mask our function IRQ */
565 while (atomic_read(&ar_sdio
->irq_handling
)) {
566 sdio_release_host(ar_sdio
->func
);
567 schedule_timeout(HZ
/ 10);
568 sdio_claim_host(ar_sdio
->func
);
571 ret
= sdio_release_irq(ar_sdio
->func
);
573 ath6kl_err("Failed to release sdio irq: %d\n", ret
);
575 sdio_release_host(ar_sdio
->func
);
578 static struct hif_scatter_req
*ath6kl_sdio_scatter_req_get(struct ath6kl
*ar
)
580 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
581 struct hif_scatter_req
*node
= NULL
;
584 spin_lock_irqsave(&ar_sdio
->scat_lock
, flag
);
586 if (!list_empty(&ar_sdio
->scat_req
)) {
587 node
= list_first_entry(&ar_sdio
->scat_req
,
588 struct hif_scatter_req
, list
);
589 list_del(&node
->list
);
592 spin_unlock_irqrestore(&ar_sdio
->scat_lock
, flag
);
597 static void ath6kl_sdio_scatter_req_add(struct ath6kl
*ar
,
598 struct hif_scatter_req
*s_req
)
600 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
603 spin_lock_irqsave(&ar_sdio
->scat_lock
, flag
);
605 list_add_tail(&s_req
->list
, &ar_sdio
->scat_req
);
607 spin_unlock_irqrestore(&ar_sdio
->scat_lock
, flag
);
611 /* scatter gather read write request */
612 static int ath6kl_sdio_async_rw_scatter(struct ath6kl
*ar
,
613 struct hif_scatter_req
*scat_req
)
615 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
616 u32 request
= scat_req
->req
;
623 ath6kl_dbg(ATH6KL_DBG_SCATTER
,
624 "hif-scatter: total len: %d scatter entries: %d\n",
625 scat_req
->len
, scat_req
->scat_entries
);
627 if (request
& HIF_SYNCHRONOUS
) {
628 sdio_claim_host(ar_sdio
->func
);
629 status
= ath6kl_sdio_scat_rw(ar_sdio
, scat_req
->busrequest
);
630 sdio_release_host(ar_sdio
->func
);
632 spin_lock_irqsave(&ar_sdio
->wr_async_lock
, flags
);
633 list_add_tail(&scat_req
->busrequest
->list
, &ar_sdio
->wr_asyncq
);
634 spin_unlock_irqrestore(&ar_sdio
->wr_async_lock
, flags
);
635 queue_work(ar
->ath6kl_wq
, &ar_sdio
->wr_async_work
);
641 /* clean up scatter support */
642 static void ath6kl_sdio_cleanup_scatter(struct ath6kl
*ar
)
644 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
645 struct hif_scatter_req
*s_req
, *tmp_req
;
648 /* empty the free list */
649 spin_lock_irqsave(&ar_sdio
->scat_lock
, flag
);
650 list_for_each_entry_safe(s_req
, tmp_req
, &ar_sdio
->scat_req
, list
) {
651 list_del(&s_req
->list
);
652 spin_unlock_irqrestore(&ar_sdio
->scat_lock
, flag
);
654 if (s_req
->busrequest
)
655 ath6kl_sdio_free_bus_req(ar_sdio
, s_req
->busrequest
);
656 kfree(s_req
->virt_dma_buf
);
657 kfree(s_req
->sgentries
);
660 spin_lock_irqsave(&ar_sdio
->scat_lock
, flag
);
662 spin_unlock_irqrestore(&ar_sdio
->scat_lock
, flag
);
665 /* setup of HIF scatter resources */
666 static int ath6kl_sdio_enable_scatter(struct ath6kl
*ar
)
668 struct ath6kl_sdio
*ar_sdio
= ath6kl_sdio_priv(ar
);
669 struct htc_target
*target
= ar
->htc_target
;
671 bool virt_scat
= false;
673 /* check if host supports scatter and it meets our requirements */
674 if (ar_sdio
->func
->card
->host
->max_segs
< MAX_SCATTER_ENTRIES_PER_REQ
) {
675 ath6kl_err("host only supports scatter of :%d entries, need: %d\n",
676 ar_sdio
->func
->card
->host
->max_segs
,
677 MAX_SCATTER_ENTRIES_PER_REQ
);
682 ret
= ath6kl_sdio_alloc_prep_scat_req(ar_sdio
,
683 MAX_SCATTER_ENTRIES_PER_REQ
,
684 MAX_SCATTER_REQUESTS
, virt_scat
);
687 ath6kl_dbg(ATH6KL_DBG_ANY
,
688 "hif-scatter enabled: max scatter req : %d entries: %d\n",
689 MAX_SCATTER_REQUESTS
,
690 MAX_SCATTER_ENTRIES_PER_REQ
);
692 target
->max_scat_entries
= MAX_SCATTER_ENTRIES_PER_REQ
;
693 target
->max_xfer_szper_scatreq
=
694 MAX_SCATTER_REQ_TRANSFER_SIZE
;
696 ath6kl_sdio_cleanup_scatter(ar
);
697 ath6kl_warn("hif scatter resource setup failed, trying virtual scatter method\n");
701 if (virt_scat
|| ret
) {
702 ret
= ath6kl_sdio_alloc_prep_scat_req(ar_sdio
,
703 ATH6KL_SCATTER_ENTRIES_PER_REQ
,
704 ATH6KL_SCATTER_REQS
, virt_scat
);
707 ath6kl_err("failed to alloc virtual scatter resources !\n");
708 ath6kl_sdio_cleanup_scatter(ar
);
712 ath6kl_dbg(ATH6KL_DBG_ANY
,
713 "Vitual scatter enabled, max_scat_req:%d, entries:%d\n",
714 ATH6KL_SCATTER_REQS
, ATH6KL_SCATTER_ENTRIES_PER_REQ
);
716 target
->max_scat_entries
= ATH6KL_SCATTER_ENTRIES_PER_REQ
;
717 target
->max_xfer_szper_scatreq
=
718 ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER
;
724 static const struct ath6kl_hif_ops ath6kl_sdio_ops
= {
725 .read_write_sync
= ath6kl_sdio_read_write_sync
,
726 .write_async
= ath6kl_sdio_write_async
,
727 .irq_enable
= ath6kl_sdio_irq_enable
,
728 .irq_disable
= ath6kl_sdio_irq_disable
,
729 .scatter_req_get
= ath6kl_sdio_scatter_req_get
,
730 .scatter_req_add
= ath6kl_sdio_scatter_req_add
,
731 .enable_scatter
= ath6kl_sdio_enable_scatter
,
732 .scat_req_rw
= ath6kl_sdio_async_rw_scatter
,
733 .cleanup_scatter
= ath6kl_sdio_cleanup_scatter
,
736 static int ath6kl_sdio_probe(struct sdio_func
*func
,
737 const struct sdio_device_id
*id
)
740 struct ath6kl_sdio
*ar_sdio
;
744 ath6kl_dbg(ATH6KL_DBG_TRC
,
745 "%s: func: 0x%X, vendor id: 0x%X, dev id: 0x%X, block size: 0x%X/0x%X\n",
746 __func__
, func
->num
, func
->vendor
,
747 func
->device
, func
->max_blksize
, func
->cur_blksize
);
749 ar_sdio
= kzalloc(sizeof(struct ath6kl_sdio
), GFP_KERNEL
);
753 ar_sdio
->dma_buffer
= kzalloc(HIF_DMA_BUFFER_SIZE
, GFP_KERNEL
);
754 if (!ar_sdio
->dma_buffer
) {
759 ar_sdio
->func
= func
;
760 sdio_set_drvdata(func
, ar_sdio
);
763 ar_sdio
->is_disabled
= true;
765 spin_lock_init(&ar_sdio
->lock
);
766 spin_lock_init(&ar_sdio
->scat_lock
);
767 spin_lock_init(&ar_sdio
->wr_async_lock
);
769 INIT_LIST_HEAD(&ar_sdio
->scat_req
);
770 INIT_LIST_HEAD(&ar_sdio
->bus_req_freeq
);
771 INIT_LIST_HEAD(&ar_sdio
->wr_asyncq
);
773 INIT_WORK(&ar_sdio
->wr_async_work
, ath6kl_sdio_write_async_work
);
775 for (count
= 0; count
< BUS_REQUEST_MAX_NUM
; count
++)
776 ath6kl_sdio_free_bus_req(ar_sdio
, &ar_sdio
->bus_req
[count
]);
778 ar
= ath6kl_core_alloc(&ar_sdio
->func
->dev
);
780 ath6kl_err("Failed to alloc ath6kl core\n");
786 ar
->hif_priv
= ar_sdio
;
787 ar
->hif_ops
= &ath6kl_sdio_ops
;
789 ath6kl_sdio_set_mbox_info(ar
);
791 sdio_claim_host(func
);
793 if ((ar_sdio
->id
->device
& MANUFACTURER_ID_ATH6KL_BASE_MASK
) >=
794 MANUFACTURER_ID_AR6003_BASE
) {
795 /* enable 4-bit ASYNC interrupt on AR6003 or later */
796 ret
= ath6kl_sdio_func0_cmd52_wr_byte(func
->card
,
797 CCCR_SDIO_IRQ_MODE_REG
,
798 SDIO_IRQ_MODE_ASYNC_4BIT_IRQ
);
800 ath6kl_err("Failed to enable 4-bit async irq mode %d\n",
802 sdio_release_host(func
);
806 ath6kl_dbg(ATH6KL_DBG_TRC
, "4-bit async irq mode enabled\n");
809 /* give us some time to enable, in ms */
810 func
->enable_timeout
= 100;
812 sdio_release_host(func
);
814 ret
= ath6kl_sdio_power_on(ar_sdio
);
818 sdio_claim_host(func
);
820 ret
= sdio_set_block_size(func
, HIF_MBOX_BLOCK_SIZE
);
822 ath6kl_err("Set sdio block size %d failed: %d)\n",
823 HIF_MBOX_BLOCK_SIZE
, ret
);
824 sdio_release_host(func
);
828 sdio_release_host(func
);
830 ret
= ath6kl_core_init(ar
);
832 ath6kl_err("Failed to init ath6kl core\n");
839 ath6kl_sdio_power_off(ar_sdio
);
841 kfree(ar_sdio
->dma_buffer
);
848 static void ath6kl_sdio_remove(struct sdio_func
*func
)
850 struct ath6kl_sdio
*ar_sdio
;
852 ar_sdio
= sdio_get_drvdata(func
);
854 ath6kl_stop_txrx(ar_sdio
->ar
);
855 cancel_work_sync(&ar_sdio
->wr_async_work
);
857 ath6kl_unavail_ev(ar_sdio
->ar
);
859 ath6kl_sdio_power_off(ar_sdio
);
861 kfree(ar_sdio
->dma_buffer
);
865 static const struct sdio_device_id ath6kl_sdio_devices
[] = {
866 {SDIO_DEVICE(MANUFACTURER_CODE
, (MANUFACTURER_ID_AR6003_BASE
| 0x0))},
867 {SDIO_DEVICE(MANUFACTURER_CODE
, (MANUFACTURER_ID_AR6003_BASE
| 0x1))},
871 MODULE_DEVICE_TABLE(sdio
, ath6kl_sdio_devices
);
873 static struct sdio_driver ath6kl_sdio_driver
= {
874 .name
= "ath6kl_sdio",
875 .id_table
= ath6kl_sdio_devices
,
876 .probe
= ath6kl_sdio_probe
,
877 .remove
= ath6kl_sdio_remove
,
880 static int __init
ath6kl_sdio_init(void)
884 ret
= sdio_register_driver(&ath6kl_sdio_driver
);
886 ath6kl_err("sdio driver registration failed: %d\n", ret
);
891 static void __exit
ath6kl_sdio_exit(void)
893 sdio_unregister_driver(&ath6kl_sdio_driver
);
896 module_init(ath6kl_sdio_init
);
897 module_exit(ath6kl_sdio_exit
);
899 MODULE_AUTHOR("Atheros Communications, Inc.");
900 MODULE_DESCRIPTION("Driver support for Atheros AR600x SDIO devices");
901 MODULE_LICENSE("Dual BSD/GPL");
903 MODULE_FIRMWARE(AR6003_REV2_OTP_FILE
);
904 MODULE_FIRMWARE(AR6003_REV2_FIRMWARE_FILE
);
905 MODULE_FIRMWARE(AR6003_REV2_PATCH_FILE
);
906 MODULE_FIRMWARE(AR6003_REV2_BOARD_DATA_FILE
);
907 MODULE_FIRMWARE(AR6003_REV2_DEFAULT_BOARD_DATA_FILE
);
908 MODULE_FIRMWARE(AR6003_REV3_OTP_FILE
);
909 MODULE_FIRMWARE(AR6003_REV3_FIRMWARE_FILE
);
910 MODULE_FIRMWARE(AR6003_REV3_PATCH_FILE
);
911 MODULE_FIRMWARE(AR6003_REV3_BOARD_DATA_FILE
);
912 MODULE_FIRMWARE(AR6003_REV3_DEFAULT_BOARD_DATA_FILE
);