2 * Copyright (c) 2010 Broadcom Corporation
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 ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #include <linux/types.h>
17 #include <linux/netdevice.h>
18 #include <linux/mmc/sdio.h>
19 #include <linux/mmc/core.h>
20 #include <linux/mmc/sdio_func.h>
21 #include <linux/mmc/sdio_ids.h>
22 #include <linux/suspend.h>
23 #include <linux/errno.h>
26 #include <brcm_hw_ids.h>
27 #include <brcmu_utils.h>
28 #include <brcmu_wifi.h>
29 #include "sdio_host.h"
30 #include "bcmsdbus.h" /* bcmsdh to/from specific controller APIs */
31 #include "sdiovar.h" /* ioctl/iovars */
32 #include "dngl_stats.h"
34 #include "bcmsdh_sdmmc.h"
36 static void brcmf_sdioh_irqhandler(struct sdio_func
*func
);
37 static void brcmf_sdioh_irqhandler_f2(struct sdio_func
*func
);
38 static int brcmf_sdioh_get_cisaddr(struct sdioh_info
*sd
, u32 regaddr
);
40 uint sd_f2_blocksize
= 512; /* Default blocksize */
42 uint sd_msglevel
= 0x01;
43 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_byte_wait
);
44 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_word_wait
);
45 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_packet_wait
);
46 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait
);
48 #define DMA_ALIGN_MASK 0x03
51 brcmf_sdioh_card_regread(struct sdioh_info
*sd
, int func
, u32 regaddr
,
52 int regsize
, u32
*data
);
54 static int brcmf_sdioh_enablefuncs(struct sdioh_info
*sd
)
60 sd_trace(("%s\n", __func__
));
62 /* Get the Card's common CIS address */
63 sd
->com_cis_ptr
= brcmf_sdioh_get_cisaddr(sd
, SDIO_CCCR_CIS
);
64 sd
->func_cis_ptr
[0] = sd
->com_cis_ptr
;
65 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__
,
68 /* Get the Card's function CIS (for each function) */
69 for (fbraddr
= SDIO_FBR_BASE(1), func
= 1;
70 func
<= sd
->num_funcs
; func
++, fbraddr
+= SDIOD_FBR_SIZE
) {
71 sd
->func_cis_ptr
[func
] =
72 brcmf_sdioh_get_cisaddr(sd
, SDIO_FBR_CIS
+ fbraddr
);
73 sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__
, func
,
74 sd
->func_cis_ptr
[func
]));
77 sd
->func_cis_ptr
[0] = sd
->com_cis_ptr
;
78 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__
,
81 /* Enable Function 1 */
82 sdio_claim_host(gInstance
->func
[1]);
83 err_ret
= sdio_enable_func(gInstance
->func
[1]);
84 sdio_release_host(gInstance
->func
[1]);
86 sd_err(("bcmsdh_sdmmc: Failed to enable F1 Err: 0x%08x",
94 * Public entry points & extern's
96 struct sdioh_info
*brcmf_sdioh_attach(void *bar0
, uint irq
)
98 struct sdioh_info
*sd
;
101 sd_trace(("%s\n", __func__
));
103 if (gInstance
== NULL
) {
104 sd_err(("%s: SDIO Device not present\n", __func__
));
108 sd
= kzalloc(sizeof(struct sdioh_info
), GFP_ATOMIC
);
110 sd_err(("sdioh_attach: out of memory\n"));
113 if (brcmf_sdioh_osinit(sd
) != 0) {
114 sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__
));
120 sd
->use_client_ints
= true;
121 sd
->client_block_size
[0] = 64;
125 /* Claim host controller */
126 sdio_claim_host(gInstance
->func
[1]);
128 sd
->client_block_size
[1] = 64;
129 err_ret
= sdio_set_block_size(gInstance
->func
[1], 64);
131 sd_err(("bcmsdh_sdmmc: Failed to set F1 blocksize\n"));
133 /* Release host controller F1 */
134 sdio_release_host(gInstance
->func
[1]);
136 if (gInstance
->func
[2]) {
137 /* Claim host controller F2 */
138 sdio_claim_host(gInstance
->func
[2]);
140 sd
->client_block_size
[2] = sd_f2_blocksize
;
142 sdio_set_block_size(gInstance
->func
[2], sd_f2_blocksize
);
144 sd_err(("bcmsdh_sdmmc: Failed to set F2 blocksize "
145 "to %d\n", sd_f2_blocksize
));
147 /* Release host controller F2 */
148 sdio_release_host(gInstance
->func
[2]);
151 brcmf_sdioh_enablefuncs(sd
);
153 sd_trace(("%s: Done\n", __func__
));
157 extern int brcmf_sdioh_detach(struct sdioh_info
*sd
)
159 sd_trace(("%s\n", __func__
));
163 /* Disable Function 2 */
164 sdio_claim_host(gInstance
->func
[2]);
165 sdio_disable_func(gInstance
->func
[2]);
166 sdio_release_host(gInstance
->func
[2]);
168 /* Disable Function 1 */
169 sdio_claim_host(gInstance
->func
[1]);
170 sdio_disable_func(gInstance
->func
[1]);
171 sdio_release_host(gInstance
->func
[1]);
174 brcmf_sdioh_osfree(sd
);
181 /* Configure callback to client when we receive client interrupt */
183 brcmf_sdioh_interrupt_register(struct sdioh_info
*sd
, sdioh_cb_fn_t fn
,
186 sd_trace(("%s: Entering\n", __func__
));
188 sd_err(("%s: interrupt handler is NULL, not registering\n",
193 sd
->intr_handler
= fn
;
194 sd
->intr_handler_arg
= argh
;
195 sd
->intr_handler_valid
= true;
197 /* register and unmask irq */
198 if (gInstance
->func
[2]) {
199 sdio_claim_host(gInstance
->func
[2]);
200 sdio_claim_irq(gInstance
->func
[2], brcmf_sdioh_irqhandler_f2
);
201 sdio_release_host(gInstance
->func
[2]);
204 if (gInstance
->func
[1]) {
205 sdio_claim_host(gInstance
->func
[1]);
206 sdio_claim_irq(gInstance
->func
[1], brcmf_sdioh_irqhandler
);
207 sdio_release_host(gInstance
->func
[1]);
213 extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info
*sd
)
215 sd_trace(("%s: Entering\n", __func__
));
217 if (gInstance
->func
[1]) {
218 /* register and unmask irq */
219 sdio_claim_host(gInstance
->func
[1]);
220 sdio_release_irq(gInstance
->func
[1]);
221 sdio_release_host(gInstance
->func
[1]);
224 if (gInstance
->func
[2]) {
225 /* Claim host controller F2 */
226 sdio_claim_host(gInstance
->func
[2]);
227 sdio_release_irq(gInstance
->func
[2]);
228 /* Release host controller F2 */
229 sdio_release_host(gInstance
->func
[2]);
232 sd
->intr_handler_valid
= false;
233 sd
->intr_handler
= NULL
;
234 sd
->intr_handler_arg
= NULL
;
240 brcmf_sdioh_interrupt_query(struct sdioh_info
*sd
, bool *onoff
)
242 sd_trace(("%s: Entering\n", __func__
));
243 *onoff
= sd
->client_intr_enabled
;
248 extern bool brcmf_sdioh_interrupt_pending(struct sdioh_info
*sd
)
254 uint
brcmf_sdioh_query_iofnum(struct sdioh_info
*sd
)
256 return sd
->num_funcs
;
270 const struct brcmu_iovar sdioh_iovars
[] = {
271 {"sd_msglevel", IOV_MSGLEVEL
, 0, IOVT_UINT32
, 0},
272 {"sd_blocksize", IOV_BLOCKSIZE
, 0, IOVT_UINT32
, 0},/* ((fn << 16) |
274 {"sd_ints", IOV_USEINTS
, 0, IOVT_BOOL
, 0},
275 {"sd_numints", IOV_NUMINTS
, 0, IOVT_UINT32
, 0},
276 {"sd_devreg", IOV_DEVREG
, 0, IOVT_BUFFER
, sizeof(struct brcmf_sdreg
)}
278 {"sd_rxchain", IOV_RXCHAIN
, 0, IOVT_BOOL
, 0}
284 brcmf_sdioh_iovar_op(struct sdioh_info
*si
, const char *name
,
285 void *params
, int plen
, void *arg
, int len
, bool set
)
287 const struct brcmu_iovar
*vi
= NULL
;
297 /* Get must have return space; Set does not take qualifiers */
298 ASSERT(set
|| (arg
&& len
));
299 ASSERT(!set
|| (!params
&& !plen
));
301 sd_trace(("%s: Enter (%s %s)\n", __func__
, (set
? "set" : "get"),
304 vi
= brcmu_iovar_lookup(sdioh_iovars
, name
);
306 bcmerror
= -ENOTSUPP
;
310 bcmerror
= brcmu_iovar_lencheck(vi
, arg
, len
, set
);
314 /* Set up params so get and set can share the convenience variables */
315 if (params
== NULL
) {
320 if (vi
->type
== IOVT_VOID
)
322 else if (vi
->type
== IOVT_BUFFER
)
325 val_size
= sizeof(int);
327 if (plen
>= (int)sizeof(int_val
))
328 memcpy(&int_val
, params
, sizeof(int_val
));
330 bool_val
= (int_val
!= 0) ? true : false;
332 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
334 case IOV_GVAL(IOV_MSGLEVEL
):
335 int_val
= (s32
) sd_msglevel
;
336 memcpy(arg
, &int_val
, val_size
);
339 case IOV_SVAL(IOV_MSGLEVEL
):
340 sd_msglevel
= int_val
;
343 case IOV_GVAL(IOV_BLOCKSIZE
):
344 if ((u32
) int_val
> si
->num_funcs
) {
348 int_val
= (s32
) si
->client_block_size
[int_val
];
349 memcpy(arg
, &int_val
, val_size
);
352 case IOV_SVAL(IOV_BLOCKSIZE
):
354 uint func
= ((u32
) int_val
>> 16);
355 uint blksize
= (u16
) int_val
;
358 if (func
> si
->num_funcs
) {
368 maxsize
= BLOCK_SIZE_4318
;
371 maxsize
= BLOCK_SIZE_4328
;
376 if (blksize
> maxsize
) {
384 si
->client_block_size
[func
] = blksize
;
389 case IOV_GVAL(IOV_RXCHAIN
):
391 memcpy(arg
, &int_val
, val_size
);
394 case IOV_GVAL(IOV_USEINTS
):
395 int_val
= (s32
) si
->use_client_ints
;
396 memcpy(arg
, &int_val
, val_size
);
399 case IOV_SVAL(IOV_USEINTS
):
400 si
->use_client_ints
= (bool) int_val
;
401 if (si
->use_client_ints
)
402 si
->intmask
|= CLIENT_INTR
;
404 si
->intmask
&= ~CLIENT_INTR
;
408 case IOV_GVAL(IOV_NUMINTS
):
409 int_val
= (s32
) si
->intrcount
;
410 memcpy(arg
, &int_val
, val_size
);
413 case IOV_GVAL(IOV_DEVREG
):
415 struct brcmf_sdreg
*sd_ptr
=
416 (struct brcmf_sdreg
*) params
;
419 if (brcmf_sdioh_cfg_read
420 (si
, sd_ptr
->func
, sd_ptr
->offset
, &data
)) {
426 memcpy(arg
, &int_val
, sizeof(int_val
));
430 case IOV_SVAL(IOV_DEVREG
):
432 struct brcmf_sdreg
*sd_ptr
=
433 (struct brcmf_sdreg
*) params
;
434 u8 data
= (u8
) sd_ptr
->value
;
436 if (brcmf_sdioh_cfg_write
437 (si
, sd_ptr
->func
, sd_ptr
->offset
, &data
)) {
445 bcmerror
= -ENOTSUPP
;
454 brcmf_sdioh_cfg_read(struct sdioh_info
*sd
, uint fnc_num
, u32 addr
, u8
*data
)
457 /* No lock needed since brcmf_sdioh_request_byte does locking */
458 status
= brcmf_sdioh_request_byte(sd
, SDIOH_READ
, fnc_num
, addr
, data
);
463 brcmf_sdioh_cfg_write(struct sdioh_info
*sd
, uint fnc_num
, u32 addr
, u8
*data
)
465 /* No lock needed since brcmf_sdioh_request_byte does locking */
467 status
= brcmf_sdioh_request_byte(sd
, SDIOH_WRITE
, fnc_num
, addr
, data
);
471 static int brcmf_sdioh_get_cisaddr(struct sdioh_info
*sd
, u32 regaddr
)
473 /* read 24 bits and return valid 17 bit addr */
475 u32 scratch
, regdata
;
476 u8
*ptr
= (u8
*)&scratch
;
477 for (i
= 0; i
< 3; i
++) {
478 if ((brcmf_sdioh_card_regread(sd
, 0, regaddr
, 1, ®data
)) !=
480 sd_err(("%s: Can't read!\n", __func__
));
482 *ptr
++ = (u8
) regdata
;
486 /* Only the lower 17-bits are valid */
487 scratch
= le32_to_cpu(scratch
);
488 scratch
&= 0x0001FFFF;
493 brcmf_sdioh_cis_read(struct sdioh_info
*sd
, uint func
, u8
*cisd
, u32 length
)
500 sd_trace(("%s: Func = %d\n", __func__
, func
));
502 if (!sd
->func_cis_ptr
[func
]) {
503 memset(cis
, 0, length
);
504 sd_err(("%s: no func_cis_ptr[%d]\n", __func__
, func
));
508 sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__
, func
,
509 sd
->func_cis_ptr
[func
]));
511 for (count
= 0; count
< length
; count
++) {
512 offset
= sd
->func_cis_ptr
[func
] + count
;
513 if (brcmf_sdioh_card_regread(sd
, 0, offset
, 1, &foo
) < 0) {
514 sd_err(("%s: regread failed: Can't read CIS\n",
519 *cis
= (u8
) (foo
& 0xff);
527 brcmf_sdioh_request_byte(struct sdioh_info
*sd
, uint rw
, uint func
,
528 uint regaddr
, u8
*byte
)
532 sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__
, rw
, func
,
535 BRCMF_PM_RESUME_WAIT(sdioh_request_byte_wait
);
536 BRCMF_PM_RESUME_RETURN_ERROR(-EIO
);
537 if (rw
) { /* CMD52 Write */
539 /* Can only directly write to some F0 registers.
543 if (regaddr
== SDIO_CCCR_IOEx
) {
544 if (gInstance
->func
[2]) {
545 sdio_claim_host(gInstance
->func
[2]);
546 if (*byte
& SDIO_FUNC_ENABLE_2
) {
547 /* Enable Function 2 */
550 (gInstance
->func
[2]);
552 sd_err(("bcmsdh_sdmmc: enable F2 failed:%d",
555 /* Disable Function 2 */
558 (gInstance
->func
[2]);
560 sd_err(("bcmsdh_sdmmc: Disab F2 failed:%d",
563 sdio_release_host(gInstance
->func
[2]);
566 /* to allow abort command through F1 */
567 else if (regaddr
== SDIO_CCCR_ABORT
) {
568 sdio_claim_host(gInstance
->func
[func
]);
570 * this sdio_f0_writeb() can be replaced
572 * depending upon MMC driver change.
573 * As of this time, this is temporaray one
575 sdio_writeb(gInstance
->func
[func
], *byte
,
577 sdio_release_host(gInstance
->func
[func
]);
579 else if (regaddr
< 0xF0) {
580 sd_err(("bcmsdh_sdmmc: F0 Wr:0x%02x: write "
581 "disallowed\n", regaddr
));
583 /* Claim host controller, perform F0 write,
585 sdio_claim_host(gInstance
->func
[func
]);
586 sdio_f0_writeb(gInstance
->func
[func
], *byte
,
588 sdio_release_host(gInstance
->func
[func
]);
591 /* Claim host controller, perform Fn write,
593 sdio_claim_host(gInstance
->func
[func
]);
594 sdio_writeb(gInstance
->func
[func
], *byte
, regaddr
,
596 sdio_release_host(gInstance
->func
[func
]);
598 } else { /* CMD52 Read */
599 /* Claim host controller, perform Fn read, and release */
600 sdio_claim_host(gInstance
->func
[func
]);
604 sdio_f0_readb(gInstance
->func
[func
], regaddr
,
608 sdio_readb(gInstance
->func
[func
], regaddr
,
612 sdio_release_host(gInstance
->func
[func
]);
616 sd_err(("bcmsdh_sdmmc: Failed to %s byte F%d:@0x%05x=%02x, "
617 "Err: %d\n", rw
? "Write" : "Read", func
, regaddr
,
624 brcmf_sdioh_request_word(struct sdioh_info
*sd
, uint cmd_type
, uint rw
,
625 uint func
, uint addr
, u32
*word
, uint nbytes
)
630 sd_err(("%s: Only CMD52 allowed to F0.\n", __func__
));
634 sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
635 __func__
, cmd_type
, rw
, func
, addr
, nbytes
));
637 BRCMF_PM_RESUME_WAIT(sdioh_request_word_wait
);
638 BRCMF_PM_RESUME_RETURN_ERROR(-EIO
);
639 /* Claim host controller */
640 sdio_claim_host(gInstance
->func
[func
]);
642 if (rw
) { /* CMD52 Write */
644 sdio_writel(gInstance
->func
[func
], *word
, addr
,
646 } else if (nbytes
== 2) {
647 sdio_writew(gInstance
->func
[func
], (*word
& 0xFFFF),
650 sd_err(("%s: Invalid nbytes: %d\n", __func__
, nbytes
));
652 } else { /* CMD52 Read */
655 sdio_readl(gInstance
->func
[func
], addr
, &err_ret
);
656 } else if (nbytes
== 2) {
658 sdio_readw(gInstance
->func
[func
], addr
,
661 sd_err(("%s: Invalid nbytes: %d\n", __func__
, nbytes
));
665 /* Release host controller */
666 sdio_release_host(gInstance
->func
[func
]);
669 sd_err(("bcmsdh_sdmmc: Failed to %s word, Err: 0x%08x",
670 rw
? "Write" : "Read", err_ret
));
677 brcmf_sdioh_request_packet(struct sdioh_info
*sd
, uint fix_inc
, uint write
,
678 uint func
, uint addr
, struct sk_buff
*pkt
)
680 bool fifo
= (fix_inc
== SDIOH_DATA_FIX
);
684 struct sk_buff
*pnext
;
686 sd_trace(("%s: Enter\n", __func__
));
689 BRCMF_PM_RESUME_WAIT(sdioh_request_packet_wait
);
690 BRCMF_PM_RESUME_RETURN_ERROR(-EIO
);
692 /* Claim host controller */
693 sdio_claim_host(gInstance
->func
[func
]);
694 for (pnext
= pkt
; pnext
; pnext
= pnext
->next
) {
695 uint pkt_len
= pnext
->len
;
697 pkt_len
&= 0xFFFFFFFC;
699 /* Make sure the packet is aligned properly.
700 * If it isn't, then this
701 * is the fault of brcmf_sdioh_request_buffer() which
702 * is supposed to give
703 * us something we can work with.
705 ASSERT(((u32
) (pkt
->data
) & DMA_ALIGN_MASK
) == 0);
707 if ((write
) && (!fifo
)) {
708 err_ret
= sdio_memcpy_toio(gInstance
->func
[func
], addr
,
709 ((u8
*) (pnext
->data
)),
712 err_ret
= sdio_memcpy_toio(gInstance
->func
[func
], addr
,
713 ((u8
*) (pnext
->data
)),
716 err_ret
= sdio_readsb(gInstance
->func
[func
],
717 ((u8
*) (pnext
->data
)),
720 err_ret
= sdio_memcpy_fromio(gInstance
->func
[func
],
721 ((u8
*) (pnext
->data
)),
726 sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d,"
727 "ERR=0x%08x\n", __func__
,
728 (write
) ? "TX" : "RX",
729 pnext
, SGCount
, addr
, pkt_len
, err_ret
));
731 sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
733 (write
) ? "TX" : "RX",
734 pnext
, SGCount
, addr
, pkt_len
));
743 /* Release host controller */
744 sdio_release_host(gInstance
->func
[func
]);
746 sd_trace(("%s: Exit\n", __func__
));
751 * This function takes a buffer or packet, and fixes everything up
752 * so that in the end, a DMA-able packet is created.
754 * A buffer does not have an associated packet pointer,
755 * and may or may not be aligned.
756 * A packet may consist of a single packet, or a packet chain.
757 * If it is a packet chain, then all the packets in the chain
758 * must be properly aligned.
760 * If the packet data is not aligned, then there may only be
761 * one packet, and in this case, it is copied to a new
766 brcmf_sdioh_request_buffer(struct sdioh_info
*sd
, uint pio_dma
, uint fix_inc
,
767 uint write
, uint func
, uint addr
, uint reg_width
,
768 uint buflen_u
, u8
*buffer
, struct sk_buff
*pkt
)
771 struct sk_buff
*mypkt
= NULL
;
773 sd_trace(("%s: Enter\n", __func__
));
775 BRCMF_PM_RESUME_WAIT(sdioh_request_buffer_wait
);
776 BRCMF_PM_RESUME_RETURN_ERROR(-EIO
);
777 /* Case 1: we don't have a packet. */
779 sd_data(("%s: Creating new %s Packet, len=%d\n",
780 __func__
, write
? "TX" : "RX", buflen_u
));
781 mypkt
= brcmu_pkt_buf_get_skb(buflen_u
);
783 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
784 __func__
, buflen_u
));
788 /* For a write, copy the buffer data into the packet. */
790 memcpy(mypkt
->data
, buffer
, buflen_u
);
792 Status
= brcmf_sdioh_request_packet(sd
, fix_inc
, write
, func
,
795 /* For a read, copy the packet data back to the buffer. */
797 memcpy(buffer
, mypkt
->data
, buflen_u
);
799 brcmu_pkt_buf_free_skb(mypkt
);
800 } else if (((u32
) (pkt
->data
) & DMA_ALIGN_MASK
) != 0) {
801 /* Case 2: We have a packet, but it is unaligned. */
803 /* In this case, we cannot have a chain. */
804 ASSERT(pkt
->next
== NULL
);
806 sd_data(("%s: Creating aligned %s Packet, len=%d\n",
807 __func__
, write
? "TX" : "RX", pkt
->len
));
808 mypkt
= brcmu_pkt_buf_get_skb(pkt
->len
);
810 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
811 __func__
, pkt
->len
));
815 /* For a write, copy the buffer data into the packet. */
817 memcpy(mypkt
->data
, pkt
->data
, pkt
->len
);
819 Status
= brcmf_sdioh_request_packet(sd
, fix_inc
, write
, func
,
822 /* For a read, copy the packet data back to the buffer. */
824 memcpy(pkt
->data
, mypkt
->data
, mypkt
->len
);
826 brcmu_pkt_buf_free_skb(mypkt
);
827 } else { /* case 3: We have a packet and
829 sd_data(("%s: Aligned %s Packet, direct DMA\n",
830 __func__
, write
? "Tx" : "Rx"));
831 Status
= brcmf_sdioh_request_packet(sd
, fix_inc
, write
, func
,
838 /* this function performs "abort" for both of host & device */
839 extern int brcmf_sdioh_abort(struct sdioh_info
*sd
, uint func
)
841 char t_func
= (char)func
;
842 sd_trace(("%s: Enter\n", __func__
));
844 /* issue abort cmd52 command through F0 */
845 brcmf_sdioh_request_byte(sd
, SDIOH_WRITE
, SDIO_FUNC_0
, SDIO_CCCR_ABORT
,
848 sd_trace(("%s: Exit\n", __func__
));
852 /* Reset and re-initialize the device */
853 int brcmf_sdioh_reset(struct sdioh_info
*si
)
855 sd_trace(("%s: Enter\n", __func__
));
856 sd_trace(("%s: Exit\n", __func__
));
860 /* Disable device interrupt */
861 void brcmf_sdioh_dev_intr_off(struct sdioh_info
*sd
)
863 sd_trace(("%s: %d\n", __func__
, sd
->use_client_ints
));
864 sd
->intmask
&= ~CLIENT_INTR
;
867 /* Enable device interrupt */
868 void brcmf_sdioh_dev_intr_on(struct sdioh_info
*sd
)
870 sd_trace(("%s: %d\n", __func__
, sd
->use_client_ints
));
871 sd
->intmask
|= CLIENT_INTR
;
874 /* Read client card reg */
876 brcmf_sdioh_card_regread(struct sdioh_info
*sd
, int func
, u32 regaddr
,
877 int regsize
, u32
*data
)
880 if ((func
== 0) || (regsize
== 1)) {
883 brcmf_sdioh_request_byte(sd
, SDIOH_READ
, func
, regaddr
, &temp
);
886 sd_data(("%s: byte read data=0x%02x\n", __func__
, *data
));
888 brcmf_sdioh_request_word(sd
, 0, SDIOH_READ
, func
, regaddr
, data
,
893 sd_data(("%s: word read data=0x%08x\n", __func__
, *data
));
899 /* bcmsdh_sdmmc interrupt handler */
900 static void brcmf_sdioh_irqhandler(struct sdio_func
*func
)
902 struct sdioh_info
*sd
;
904 sd_trace(("bcmsdh_sdmmc: ***IRQHandler\n"));
908 sdio_release_host(gInstance
->func
[0]);
910 if (sd
->use_client_ints
) {
912 ASSERT(sd
->intr_handler
);
913 ASSERT(sd
->intr_handler_arg
);
914 (sd
->intr_handler
) (sd
->intr_handler_arg
);
916 sd_err(("bcmsdh_sdmmc: ***IRQHandler\n"));
918 sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
919 __func__
, sd
->client_intr_enabled
, sd
->intr_handler
));
922 sdio_claim_host(gInstance
->func
[0]);
925 /* bcmsdh_sdmmc interrupt handler for F2 (dummy handler) */
926 static void brcmf_sdioh_irqhandler_f2(struct sdio_func
*func
)
928 struct sdioh_info
*sd
;
930 sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n"));
937 int brcmf_sdioh_start(struct sdioh_info
*si
, int stage
)
942 int brcmf_sdioh_stop(struct sdioh_info
*si
)