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>
25 #include <brcm_hw_ids.h>
26 #include <brcmu_utils.h>
27 #include <brcmu_wifi.h>
28 #include "sdio_host.h"
29 #include "bcmsdbus.h" /* bcmsdh to/from specific controller APIs */
30 #include "sdiovar.h" /* ioctl/iovars */
31 #include "dngl_stats.h"
33 #include "bcmsdh_sdmmc.h"
35 extern int brcmf_sdio_function_init(void);
36 extern void brcmf_sdio_function_cleanup(void);
38 static void brcmf_sdioh_irqhandler(struct sdio_func *func);
39 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func);
40 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr);
41 extern int brcmf_sdioh_reset_comm(struct mmc_card *card);
43 extern PBCMSDH_SDMMC_INSTANCE gInstance;
45 uint sd_f2_blocksize = 512; /* Default blocksize */
47 uint sd_msglevel = 0x01;
48 DHD_PM_RESUME_WAIT_INIT(sdioh_request_byte_wait);
49 DHD_PM_RESUME_WAIT_INIT(sdioh_request_word_wait);
50 DHD_PM_RESUME_WAIT_INIT(sdioh_request_packet_wait);
51 DHD_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait);
53 #define DMA_ALIGN_MASK 0x03
55 int brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
56 int regsize, u32 *data);
58 void brcmf_sdioh_set_host_pm_flags(int flag)
60 if (sdio_set_host_pm_flags(gInstance->func[1], flag))
61 printk(KERN_ERR "%s: Failed to set pm_flags 0x%08x\n",\
62 __func__, (unsigned int)flag);
65 static int brcmf_sdioh_enablefuncs(struct sdioh_info *sd)
71 sd_trace(("%s\n", __func__));
73 /* Get the Card's common CIS address */
74 sd->com_cis_ptr = brcmf_sdioh_get_cisaddr(sd, SDIO_CCCR_CIS);
75 sd->func_cis_ptr[0] = sd->com_cis_ptr;
76 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
79 /* Get the Card's function CIS (for each function) */
80 for (fbraddr = SDIO_FBR_BASE(1), func = 1;
81 func <= sd->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) {
82 sd->func_cis_ptr[func] =
83 brcmf_sdioh_get_cisaddr(sd, SDIO_FBR_CIS + fbraddr);
84 sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__, func,
85 sd->func_cis_ptr[func]));
88 sd->func_cis_ptr[0] = sd->com_cis_ptr;
89 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
92 /* Enable Function 1 */
93 sdio_claim_host(gInstance->func[1]);
94 err_ret = sdio_enable_func(gInstance->func[1]);
95 sdio_release_host(gInstance->func[1]);
97 sd_err(("bcmsdh_sdmmc: Failed to enable F1 Err: 0x%08x",
105 * Public entry points & extern's
107 struct sdioh_info *brcmf_sdioh_attach(void *bar0, uint irq)
109 struct sdioh_info *sd;
112 sd_trace(("%s\n", __func__));
114 if (gInstance == NULL) {
115 sd_err(("%s: SDIO Device not present\n", __func__));
119 sd = kzalloc(sizeof(struct sdioh_info), GFP_ATOMIC);
121 sd_err(("sdioh_attach: out of memory\n"));
124 if (brcmf_sdioh_osinit(sd) != 0) {
125 sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__));
131 sd->use_client_ints = true;
132 sd->client_block_size[0] = 64;
136 /* Claim host controller */
137 sdio_claim_host(gInstance->func[1]);
139 sd->client_block_size[1] = 64;
140 err_ret = sdio_set_block_size(gInstance->func[1], 64);
142 sd_err(("bcmsdh_sdmmc: Failed to set F1 blocksize\n"));
144 /* Release host controller F1 */
145 sdio_release_host(gInstance->func[1]);
147 if (gInstance->func[2]) {
148 /* Claim host controller F2 */
149 sdio_claim_host(gInstance->func[2]);
151 sd->client_block_size[2] = sd_f2_blocksize;
153 sdio_set_block_size(gInstance->func[2], sd_f2_blocksize);
155 sd_err(("bcmsdh_sdmmc: Failed to set F2 blocksize "
156 "to %d\n", sd_f2_blocksize));
158 /* Release host controller F2 */
159 sdio_release_host(gInstance->func[2]);
162 brcmf_sdioh_enablefuncs(sd);
164 sd_trace(("%s: Done\n", __func__));
168 extern int brcmf_sdioh_detach(struct sdioh_info *sd)
170 sd_trace(("%s\n", __func__));
174 /* Disable Function 2 */
175 sdio_claim_host(gInstance->func[2]);
176 sdio_disable_func(gInstance->func[2]);
177 sdio_release_host(gInstance->func[2]);
179 /* Disable Function 1 */
180 sdio_claim_host(gInstance->func[1]);
181 sdio_disable_func(gInstance->func[1]);
182 sdio_release_host(gInstance->func[1]);
185 brcmf_sdioh_osfree(sd);
189 return SDIOH_API_RC_SUCCESS;
192 /* Configure callback to client when we receive client interrupt */
194 brcmf_sdioh_interrupt_register(struct sdioh_info *sd, sdioh_cb_fn_t fn,
197 sd_trace(("%s: Entering\n", __func__));
199 sd_err(("%s: interrupt handler is NULL, not registering\n",
201 return SDIOH_API_RC_FAIL;
204 sd->intr_handler = fn;
205 sd->intr_handler_arg = argh;
206 sd->intr_handler_valid = true;
208 /* register and unmask irq */
209 if (gInstance->func[2]) {
210 sdio_claim_host(gInstance->func[2]);
211 sdio_claim_irq(gInstance->func[2], brcmf_sdioh_irqhandler_f2);
212 sdio_release_host(gInstance->func[2]);
215 if (gInstance->func[1]) {
216 sdio_claim_host(gInstance->func[1]);
217 sdio_claim_irq(gInstance->func[1], brcmf_sdioh_irqhandler);
218 sdio_release_host(gInstance->func[1]);
221 return SDIOH_API_RC_SUCCESS;
224 extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *sd)
226 sd_trace(("%s: Entering\n", __func__));
228 if (gInstance->func[1]) {
229 /* register and unmask irq */
230 sdio_claim_host(gInstance->func[1]);
231 sdio_release_irq(gInstance->func[1]);
232 sdio_release_host(gInstance->func[1]);
235 if (gInstance->func[2]) {
236 /* Claim host controller F2 */
237 sdio_claim_host(gInstance->func[2]);
238 sdio_release_irq(gInstance->func[2]);
239 /* Release host controller F2 */
240 sdio_release_host(gInstance->func[2]);
243 sd->intr_handler_valid = false;
244 sd->intr_handler = NULL;
245 sd->intr_handler_arg = NULL;
247 return SDIOH_API_RC_SUCCESS;
251 brcmf_sdioh_interrupt_query(struct sdioh_info *sd, bool *onoff)
253 sd_trace(("%s: Entering\n", __func__));
254 *onoff = sd->client_intr_enabled;
255 return SDIOH_API_RC_SUCCESS;
259 extern bool brcmf_sdioh_interrupt_pending(struct sdioh_info *sd)
265 uint brcmf_sdioh_query_iofnum(struct sdioh_info *sd)
267 return sd->num_funcs;
281 const struct brcmu_iovar sdioh_iovars[] = {
282 {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0},
283 {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0},/* ((fn << 16) |
285 {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0},
286 {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0},
287 {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
289 {"sd_rxchain", IOV_RXCHAIN, 0, IOVT_BOOL, 0}
295 brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name,
296 void *params, int plen, void *arg, int len, bool set)
298 const struct brcmu_iovar *vi = NULL;
308 /* Get must have return space; Set does not take qualifiers */
309 ASSERT(set || (arg && len));
310 ASSERT(!set || (!params && !plen));
312 sd_trace(("%s: Enter (%s %s)\n", __func__, (set ? "set" : "get"),
315 vi = brcmu_iovar_lookup(sdioh_iovars, name);
317 bcmerror = -ENOTSUPP;
321 bcmerror = brcmu_iovar_lencheck(vi, arg, len, set);
325 /* Set up params so get and set can share the convenience variables */
326 if (params == NULL) {
331 if (vi->type == IOVT_VOID)
333 else if (vi->type == IOVT_BUFFER)
336 val_size = sizeof(int);
338 if (plen >= (int)sizeof(int_val))
339 memcpy(&int_val, params, sizeof(int_val));
341 bool_val = (int_val != 0) ? true : false;
343 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
345 case IOV_GVAL(IOV_MSGLEVEL):
346 int_val = (s32) sd_msglevel;
347 memcpy(arg, &int_val, val_size);
350 case IOV_SVAL(IOV_MSGLEVEL):
351 sd_msglevel = int_val;
354 case IOV_GVAL(IOV_BLOCKSIZE):
355 if ((u32) int_val > si->num_funcs) {
359 int_val = (s32) si->client_block_size[int_val];
360 memcpy(arg, &int_val, val_size);
363 case IOV_SVAL(IOV_BLOCKSIZE):
365 uint func = ((u32) int_val >> 16);
366 uint blksize = (u16) int_val;
369 if (func > si->num_funcs) {
379 maxsize = BLOCK_SIZE_4318;
382 maxsize = BLOCK_SIZE_4328;
387 if (blksize > maxsize) {
395 si->client_block_size[func] = blksize;
400 case IOV_GVAL(IOV_RXCHAIN):
402 memcpy(arg, &int_val, val_size);
405 case IOV_GVAL(IOV_USEINTS):
406 int_val = (s32) si->use_client_ints;
407 memcpy(arg, &int_val, val_size);
410 case IOV_SVAL(IOV_USEINTS):
411 si->use_client_ints = (bool) int_val;
412 if (si->use_client_ints)
413 si->intmask |= CLIENT_INTR;
415 si->intmask &= ~CLIENT_INTR;
419 case IOV_GVAL(IOV_NUMINTS):
420 int_val = (s32) si->intrcount;
421 memcpy(arg, &int_val, val_size);
424 case IOV_GVAL(IOV_DEVREG):
426 struct brcmf_sdreg *sd_ptr =
427 (struct brcmf_sdreg *) params;
430 if (brcmf_sdioh_cfg_read
431 (si, sd_ptr->func, sd_ptr->offset, &data)) {
437 memcpy(arg, &int_val, sizeof(int_val));
441 case IOV_SVAL(IOV_DEVREG):
443 struct brcmf_sdreg *sd_ptr =
444 (struct brcmf_sdreg *) params;
445 u8 data = (u8) sd_ptr->value;
447 if (brcmf_sdioh_cfg_write
448 (si, sd_ptr->func, sd_ptr->offset, &data)) {
456 bcmerror = -ENOTSUPP;
465 brcmf_sdioh_cfg_read(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
468 /* No lock needed since brcmf_sdioh_request_byte does locking */
469 status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
474 brcmf_sdioh_cfg_write(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
476 /* No lock needed since brcmf_sdioh_request_byte does locking */
478 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
482 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr)
484 /* read 24 bits and return valid 17 bit addr */
486 u32 scratch, regdata;
487 u8 *ptr = (u8 *)&scratch;
488 for (i = 0; i < 3; i++) {
489 if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, ®data)) !=
491 sd_err(("%s: Can't read!\n", __func__));
493 *ptr++ = (u8) regdata;
497 /* Only the lower 17-bits are valid */
498 scratch = le32_to_cpu(scratch);
499 scratch &= 0x0001FFFF;
504 brcmf_sdioh_cis_read(struct sdioh_info *sd, uint func, u8 *cisd, u32 length)
511 sd_trace(("%s: Func = %d\n", __func__, func));
513 if (!sd->func_cis_ptr[func]) {
514 memset(cis, 0, length);
515 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
516 return SDIOH_API_RC_FAIL;
519 sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func,
520 sd->func_cis_ptr[func]));
522 for (count = 0; count < length; count++) {
523 offset = sd->func_cis_ptr[func] + count;
524 if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) {
525 sd_err(("%s: regread failed: Can't read CIS\n",
527 return SDIOH_API_RC_FAIL;
530 *cis = (u8) (foo & 0xff);
534 return SDIOH_API_RC_SUCCESS;
538 brcmf_sdioh_request_byte(struct sdioh_info *sd, uint rw, uint func,
539 uint regaddr, u8 *byte)
543 sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func,
546 DHD_PM_RESUME_WAIT(sdioh_request_byte_wait);
547 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
548 if (rw) { /* CMD52 Write */
550 /* Can only directly write to some F0 registers.
554 if (regaddr == SDIO_CCCR_IOEx) {
555 if (gInstance->func[2]) {
556 sdio_claim_host(gInstance->func[2]);
557 if (*byte & SDIO_FUNC_ENABLE_2) {
558 /* Enable Function 2 */
561 (gInstance->func[2]);
563 sd_err(("bcmsdh_sdmmc: enable F2 failed:%d",
566 /* Disable Function 2 */
569 (gInstance->func[2]);
571 sd_err(("bcmsdh_sdmmc: Disab F2 failed:%d",
574 sdio_release_host(gInstance->func[2]);
577 /* to allow abort command through F1 */
578 else if (regaddr == SDIO_CCCR_ABORT) {
579 sdio_claim_host(gInstance->func[func]);
581 * this sdio_f0_writeb() can be replaced
583 * depending upon MMC driver change.
584 * As of this time, this is temporaray one
586 sdio_writeb(gInstance->func[func], *byte,
588 sdio_release_host(gInstance->func[func]);
590 else if (regaddr < 0xF0) {
591 sd_err(("bcmsdh_sdmmc: F0 Wr:0x%02x: write "
592 "disallowed\n", regaddr));
594 /* Claim host controller, perform F0 write,
596 sdio_claim_host(gInstance->func[func]);
597 sdio_f0_writeb(gInstance->func[func], *byte,
599 sdio_release_host(gInstance->func[func]);
602 /* Claim host controller, perform Fn write,
604 sdio_claim_host(gInstance->func[func]);
605 sdio_writeb(gInstance->func[func], *byte, regaddr,
607 sdio_release_host(gInstance->func[func]);
609 } else { /* CMD52 Read */
610 /* Claim host controller, perform Fn read, and release */
611 sdio_claim_host(gInstance->func[func]);
615 sdio_f0_readb(gInstance->func[func], regaddr,
619 sdio_readb(gInstance->func[func], regaddr,
623 sdio_release_host(gInstance->func[func]);
627 sd_err(("bcmsdh_sdmmc: Failed to %s byte F%d:@0x%05x=%02x, "
628 "Err: %d\n", rw ? "Write" : "Read", func, regaddr,
631 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
635 brcmf_sdioh_request_word(struct sdioh_info *sd, uint cmd_type, uint rw,
636 uint func, uint addr, u32 *word, uint nbytes)
638 int err_ret = SDIOH_API_RC_FAIL;
641 sd_err(("%s: Only CMD52 allowed to F0.\n", __func__));
642 return SDIOH_API_RC_FAIL;
645 sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
646 __func__, cmd_type, rw, func, addr, nbytes));
648 DHD_PM_RESUME_WAIT(sdioh_request_word_wait);
649 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
650 /* Claim host controller */
651 sdio_claim_host(gInstance->func[func]);
653 if (rw) { /* CMD52 Write */
655 sdio_writel(gInstance->func[func], *word, addr,
657 } else if (nbytes == 2) {
658 sdio_writew(gInstance->func[func], (*word & 0xFFFF),
661 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
663 } else { /* CMD52 Read */
666 sdio_readl(gInstance->func[func], addr, &err_ret);
667 } else if (nbytes == 2) {
669 sdio_readw(gInstance->func[func], addr,
672 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
676 /* Release host controller */
677 sdio_release_host(gInstance->func[func]);
680 sd_err(("bcmsdh_sdmmc: Failed to %s word, Err: 0x%08x",
681 rw ? "Write" : "Read", err_ret));
684 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
688 brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
689 uint func, uint addr, struct sk_buff *pkt)
691 bool fifo = (fix_inc == SDIOH_DATA_FIX);
695 struct sk_buff *pnext;
697 sd_trace(("%s: Enter\n", __func__));
700 DHD_PM_RESUME_WAIT(sdioh_request_packet_wait);
701 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
703 /* Claim host controller */
704 sdio_claim_host(gInstance->func[func]);
705 for (pnext = pkt; pnext; pnext = pnext->next) {
706 uint pkt_len = pnext->len;
708 pkt_len &= 0xFFFFFFFC;
710 /* Make sure the packet is aligned properly.
711 * If it isn't, then this
712 * is the fault of brcmf_sdioh_request_buffer() which
713 * is supposed to give
714 * us something we can work with.
716 ASSERT(((u32) (pkt->data) & DMA_ALIGN_MASK) == 0);
718 if ((write) && (!fifo)) {
719 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
720 ((u8 *) (pnext->data)),
723 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
724 ((u8 *) (pnext->data)),
727 err_ret = sdio_readsb(gInstance->func[func],
728 ((u8 *) (pnext->data)),
731 err_ret = sdio_memcpy_fromio(gInstance->func[func],
732 ((u8 *) (pnext->data)),
737 sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d,"
738 "ERR=0x%08x\n", __func__,
739 (write) ? "TX" : "RX",
740 pnext, SGCount, addr, pkt_len, err_ret));
742 sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
744 (write) ? "TX" : "RX",
745 pnext, SGCount, addr, pkt_len));
754 /* Release host controller */
755 sdio_release_host(gInstance->func[func]);
757 sd_trace(("%s: Exit\n", __func__));
758 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
762 * This function takes a buffer or packet, and fixes everything up
763 * so that in the end, a DMA-able packet is created.
765 * A buffer does not have an associated packet pointer,
766 * and may or may not be aligned.
767 * A packet may consist of a single packet, or a packet chain.
768 * If it is a packet chain, then all the packets in the chain
769 * must be properly aligned.
771 * If the packet data is not aligned, then there may only be
772 * one packet, and in this case, it is copied to a new
777 brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
778 uint write, uint func, uint addr, uint reg_width,
779 uint buflen_u, u8 *buffer, struct sk_buff *pkt)
782 struct sk_buff *mypkt = NULL;
784 sd_trace(("%s: Enter\n", __func__));
786 DHD_PM_RESUME_WAIT(sdioh_request_buffer_wait);
787 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
788 /* Case 1: we don't have a packet. */
790 sd_data(("%s: Creating new %s Packet, len=%d\n",
791 __func__, write ? "TX" : "RX", buflen_u));
792 mypkt = brcmu_pkt_buf_get_skb(buflen_u);
794 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
795 __func__, buflen_u));
796 return SDIOH_API_RC_FAIL;
799 /* For a write, copy the buffer data into the packet. */
801 memcpy(mypkt->data, buffer, buflen_u);
803 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
806 /* For a read, copy the packet data back to the buffer. */
808 memcpy(buffer, mypkt->data, buflen_u);
810 brcmu_pkt_buf_free_skb(mypkt);
811 } else if (((u32) (pkt->data) & DMA_ALIGN_MASK) != 0) {
812 /* Case 2: We have a packet, but it is unaligned. */
814 /* In this case, we cannot have a chain. */
815 ASSERT(pkt->next == NULL);
817 sd_data(("%s: Creating aligned %s Packet, len=%d\n",
818 __func__, write ? "TX" : "RX", pkt->len));
819 mypkt = brcmu_pkt_buf_get_skb(pkt->len);
821 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
822 __func__, pkt->len));
823 return SDIOH_API_RC_FAIL;
826 /* For a write, copy the buffer data into the packet. */
828 memcpy(mypkt->data, pkt->data, pkt->len);
830 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
833 /* For a read, copy the packet data back to the buffer. */
835 memcpy(pkt->data, mypkt->data, mypkt->len);
837 brcmu_pkt_buf_free_skb(mypkt);
838 } else { /* case 3: We have a packet and
840 sd_data(("%s: Aligned %s Packet, direct DMA\n",
841 __func__, write ? "Tx" : "Rx"));
842 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
849 /* this function performs "abort" for both of host & device */
850 extern int brcmf_sdioh_abort(struct sdioh_info *sd, uint func)
852 char t_func = (char)func;
853 sd_trace(("%s: Enter\n", __func__));
855 /* issue abort cmd52 command through F0 */
856 brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT,
859 sd_trace(("%s: Exit\n", __func__));
860 return SDIOH_API_RC_SUCCESS;
863 /* Reset and re-initialize the device */
864 int brcmf_sdioh_reset(struct sdioh_info *si)
866 sd_trace(("%s: Enter\n", __func__));
867 sd_trace(("%s: Exit\n", __func__));
868 return SDIOH_API_RC_SUCCESS;
871 /* Disable device interrupt */
872 void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd)
874 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
875 sd->intmask &= ~CLIENT_INTR;
878 /* Enable device interrupt */
879 void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd)
881 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
882 sd->intmask |= CLIENT_INTR;
885 /* Read client card reg */
887 brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
888 int regsize, u32 *data)
891 if ((func == 0) || (regsize == 1)) {
894 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
897 sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
899 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data,
904 sd_data(("%s: word read data=0x%08x\n", __func__, *data));
910 /* bcmsdh_sdmmc interrupt handler */
911 static void brcmf_sdioh_irqhandler(struct sdio_func *func)
913 struct sdioh_info *sd;
915 sd_trace(("bcmsdh_sdmmc: ***IRQHandler\n"));
919 sdio_release_host(gInstance->func[0]);
921 if (sd->use_client_ints) {
923 ASSERT(sd->intr_handler);
924 ASSERT(sd->intr_handler_arg);
925 (sd->intr_handler) (sd->intr_handler_arg);
927 sd_err(("bcmsdh_sdmmc: ***IRQHandler\n"));
929 sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
930 __func__, sd->client_intr_enabled, sd->intr_handler));
933 sdio_claim_host(gInstance->func[0]);
936 /* bcmsdh_sdmmc interrupt handler for F2 (dummy handler) */
937 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func)
939 struct sdioh_info *sd;
941 sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n"));
948 int brcmf_sdioh_start(struct sdioh_info *si, int stage)
953 int brcmf_sdioh_stop(struct sdioh_info *si)