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 static int brcmf_sdioh_enablefuncs(struct sdioh_info *sd)
64 sd_trace(("%s\n", __func__));
66 /* Get the Card's common CIS address */
67 sd->com_cis_ptr = brcmf_sdioh_get_cisaddr(sd, SDIO_CCCR_CIS);
68 sd->func_cis_ptr[0] = sd->com_cis_ptr;
69 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
72 /* Get the Card's function CIS (for each function) */
73 for (fbraddr = SDIO_FBR_BASE(1), func = 1;
74 func <= sd->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) {
75 sd->func_cis_ptr[func] =
76 brcmf_sdioh_get_cisaddr(sd, SDIO_FBR_CIS + fbraddr);
77 sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__, func,
78 sd->func_cis_ptr[func]));
81 sd->func_cis_ptr[0] = sd->com_cis_ptr;
82 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
85 /* Enable Function 1 */
86 sdio_claim_host(gInstance->func[1]);
87 err_ret = sdio_enable_func(gInstance->func[1]);
88 sdio_release_host(gInstance->func[1]);
90 sd_err(("bcmsdh_sdmmc: Failed to enable F1 Err: 0x%08x",
98 * Public entry points & extern's
100 struct sdioh_info *brcmf_sdioh_attach(void *bar0, uint irq)
102 struct sdioh_info *sd;
105 sd_trace(("%s\n", __func__));
107 if (gInstance == NULL) {
108 sd_err(("%s: SDIO Device not present\n", __func__));
112 sd = kzalloc(sizeof(struct sdioh_info), GFP_ATOMIC);
114 sd_err(("sdioh_attach: out of memory\n"));
117 if (brcmf_sdioh_osinit(sd) != 0) {
118 sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__));
124 sd->use_client_ints = true;
125 sd->client_block_size[0] = 64;
129 /* Claim host controller */
130 sdio_claim_host(gInstance->func[1]);
132 sd->client_block_size[1] = 64;
133 err_ret = sdio_set_block_size(gInstance->func[1], 64);
135 sd_err(("bcmsdh_sdmmc: Failed to set F1 blocksize\n"));
137 /* Release host controller F1 */
138 sdio_release_host(gInstance->func[1]);
140 if (gInstance->func[2]) {
141 /* Claim host controller F2 */
142 sdio_claim_host(gInstance->func[2]);
144 sd->client_block_size[2] = sd_f2_blocksize;
146 sdio_set_block_size(gInstance->func[2], sd_f2_blocksize);
148 sd_err(("bcmsdh_sdmmc: Failed to set F2 blocksize "
149 "to %d\n", sd_f2_blocksize));
151 /* Release host controller F2 */
152 sdio_release_host(gInstance->func[2]);
155 brcmf_sdioh_enablefuncs(sd);
157 sd_trace(("%s: Done\n", __func__));
161 extern int brcmf_sdioh_detach(struct sdioh_info *sd)
163 sd_trace(("%s\n", __func__));
167 /* Disable Function 2 */
168 sdio_claim_host(gInstance->func[2]);
169 sdio_disable_func(gInstance->func[2]);
170 sdio_release_host(gInstance->func[2]);
172 /* Disable Function 1 */
173 sdio_claim_host(gInstance->func[1]);
174 sdio_disable_func(gInstance->func[1]);
175 sdio_release_host(gInstance->func[1]);
178 brcmf_sdioh_osfree(sd);
182 return SDIOH_API_RC_SUCCESS;
185 /* Configure callback to client when we receive client interrupt */
187 brcmf_sdioh_interrupt_register(struct sdioh_info *sd, sdioh_cb_fn_t fn,
190 sd_trace(("%s: Entering\n", __func__));
192 sd_err(("%s: interrupt handler is NULL, not registering\n",
194 return SDIOH_API_RC_FAIL;
197 sd->intr_handler = fn;
198 sd->intr_handler_arg = argh;
199 sd->intr_handler_valid = true;
201 /* register and unmask irq */
202 if (gInstance->func[2]) {
203 sdio_claim_host(gInstance->func[2]);
204 sdio_claim_irq(gInstance->func[2], brcmf_sdioh_irqhandler_f2);
205 sdio_release_host(gInstance->func[2]);
208 if (gInstance->func[1]) {
209 sdio_claim_host(gInstance->func[1]);
210 sdio_claim_irq(gInstance->func[1], brcmf_sdioh_irqhandler);
211 sdio_release_host(gInstance->func[1]);
214 return SDIOH_API_RC_SUCCESS;
217 extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *sd)
219 sd_trace(("%s: Entering\n", __func__));
221 if (gInstance->func[1]) {
222 /* register and unmask irq */
223 sdio_claim_host(gInstance->func[1]);
224 sdio_release_irq(gInstance->func[1]);
225 sdio_release_host(gInstance->func[1]);
228 if (gInstance->func[2]) {
229 /* Claim host controller F2 */
230 sdio_claim_host(gInstance->func[2]);
231 sdio_release_irq(gInstance->func[2]);
232 /* Release host controller F2 */
233 sdio_release_host(gInstance->func[2]);
236 sd->intr_handler_valid = false;
237 sd->intr_handler = NULL;
238 sd->intr_handler_arg = NULL;
240 return SDIOH_API_RC_SUCCESS;
244 brcmf_sdioh_interrupt_query(struct sdioh_info *sd, bool *onoff)
246 sd_trace(("%s: Entering\n", __func__));
247 *onoff = sd->client_intr_enabled;
248 return SDIOH_API_RC_SUCCESS;
252 extern bool brcmf_sdioh_interrupt_pending(struct sdioh_info *sd)
258 uint brcmf_sdioh_query_iofnum(struct sdioh_info *sd)
260 return sd->num_funcs;
274 const struct brcmu_iovar sdioh_iovars[] = {
275 {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0},
276 {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0},/* ((fn << 16) |
278 {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0},
279 {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0},
280 {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
282 {"sd_rxchain", IOV_RXCHAIN, 0, IOVT_BOOL, 0}
288 brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name,
289 void *params, int plen, void *arg, int len, bool set)
291 const struct brcmu_iovar *vi = NULL;
301 /* Get must have return space; Set does not take qualifiers */
302 ASSERT(set || (arg && len));
303 ASSERT(!set || (!params && !plen));
305 sd_trace(("%s: Enter (%s %s)\n", __func__, (set ? "set" : "get"),
308 vi = brcmu_iovar_lookup(sdioh_iovars, name);
310 bcmerror = -ENOTSUPP;
314 bcmerror = brcmu_iovar_lencheck(vi, arg, len, set);
318 /* Set up params so get and set can share the convenience variables */
319 if (params == NULL) {
324 if (vi->type == IOVT_VOID)
326 else if (vi->type == IOVT_BUFFER)
329 val_size = sizeof(int);
331 if (plen >= (int)sizeof(int_val))
332 memcpy(&int_val, params, sizeof(int_val));
334 bool_val = (int_val != 0) ? true : false;
336 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
338 case IOV_GVAL(IOV_MSGLEVEL):
339 int_val = (s32) sd_msglevel;
340 memcpy(arg, &int_val, val_size);
343 case IOV_SVAL(IOV_MSGLEVEL):
344 sd_msglevel = int_val;
347 case IOV_GVAL(IOV_BLOCKSIZE):
348 if ((u32) int_val > si->num_funcs) {
352 int_val = (s32) si->client_block_size[int_val];
353 memcpy(arg, &int_val, val_size);
356 case IOV_SVAL(IOV_BLOCKSIZE):
358 uint func = ((u32) int_val >> 16);
359 uint blksize = (u16) int_val;
362 if (func > si->num_funcs) {
372 maxsize = BLOCK_SIZE_4318;
375 maxsize = BLOCK_SIZE_4328;
380 if (blksize > maxsize) {
388 si->client_block_size[func] = blksize;
393 case IOV_GVAL(IOV_RXCHAIN):
395 memcpy(arg, &int_val, val_size);
398 case IOV_GVAL(IOV_USEINTS):
399 int_val = (s32) si->use_client_ints;
400 memcpy(arg, &int_val, val_size);
403 case IOV_SVAL(IOV_USEINTS):
404 si->use_client_ints = (bool) int_val;
405 if (si->use_client_ints)
406 si->intmask |= CLIENT_INTR;
408 si->intmask &= ~CLIENT_INTR;
412 case IOV_GVAL(IOV_NUMINTS):
413 int_val = (s32) si->intrcount;
414 memcpy(arg, &int_val, val_size);
417 case IOV_GVAL(IOV_DEVREG):
419 struct brcmf_sdreg *sd_ptr =
420 (struct brcmf_sdreg *) params;
423 if (brcmf_sdioh_cfg_read
424 (si, sd_ptr->func, sd_ptr->offset, &data)) {
430 memcpy(arg, &int_val, sizeof(int_val));
434 case IOV_SVAL(IOV_DEVREG):
436 struct brcmf_sdreg *sd_ptr =
437 (struct brcmf_sdreg *) params;
438 u8 data = (u8) sd_ptr->value;
440 if (brcmf_sdioh_cfg_write
441 (si, sd_ptr->func, sd_ptr->offset, &data)) {
449 bcmerror = -ENOTSUPP;
458 brcmf_sdioh_cfg_read(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
461 /* No lock needed since brcmf_sdioh_request_byte does locking */
462 status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
467 brcmf_sdioh_cfg_write(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
469 /* No lock needed since brcmf_sdioh_request_byte does locking */
471 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
475 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr)
477 /* read 24 bits and return valid 17 bit addr */
479 u32 scratch, regdata;
480 u8 *ptr = (u8 *)&scratch;
481 for (i = 0; i < 3; i++) {
482 if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, ®data)) !=
484 sd_err(("%s: Can't read!\n", __func__));
486 *ptr++ = (u8) regdata;
490 /* Only the lower 17-bits are valid */
491 scratch = le32_to_cpu(scratch);
492 scratch &= 0x0001FFFF;
497 brcmf_sdioh_cis_read(struct sdioh_info *sd, uint func, u8 *cisd, u32 length)
504 sd_trace(("%s: Func = %d\n", __func__, func));
506 if (!sd->func_cis_ptr[func]) {
507 memset(cis, 0, length);
508 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
509 return SDIOH_API_RC_FAIL;
512 sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func,
513 sd->func_cis_ptr[func]));
515 for (count = 0; count < length; count++) {
516 offset = sd->func_cis_ptr[func] + count;
517 if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) {
518 sd_err(("%s: regread failed: Can't read CIS\n",
520 return SDIOH_API_RC_FAIL;
523 *cis = (u8) (foo & 0xff);
527 return SDIOH_API_RC_SUCCESS;
531 brcmf_sdioh_request_byte(struct sdioh_info *sd, uint rw, uint func,
532 uint regaddr, u8 *byte)
536 sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func,
539 DHD_PM_RESUME_WAIT(sdioh_request_byte_wait);
540 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
541 if (rw) { /* CMD52 Write */
543 /* Can only directly write to some F0 registers.
547 if (regaddr == SDIO_CCCR_IOEx) {
548 if (gInstance->func[2]) {
549 sdio_claim_host(gInstance->func[2]);
550 if (*byte & SDIO_FUNC_ENABLE_2) {
551 /* Enable Function 2 */
554 (gInstance->func[2]);
556 sd_err(("bcmsdh_sdmmc: enable F2 failed:%d",
559 /* Disable Function 2 */
562 (gInstance->func[2]);
564 sd_err(("bcmsdh_sdmmc: Disab F2 failed:%d",
567 sdio_release_host(gInstance->func[2]);
570 /* to allow abort command through F1 */
571 else if (regaddr == SDIO_CCCR_ABORT) {
572 sdio_claim_host(gInstance->func[func]);
574 * this sdio_f0_writeb() can be replaced
576 * depending upon MMC driver change.
577 * As of this time, this is temporaray one
579 sdio_writeb(gInstance->func[func], *byte,
581 sdio_release_host(gInstance->func[func]);
583 else if (regaddr < 0xF0) {
584 sd_err(("bcmsdh_sdmmc: F0 Wr:0x%02x: write "
585 "disallowed\n", regaddr));
587 /* Claim host controller, perform F0 write,
589 sdio_claim_host(gInstance->func[func]);
590 sdio_f0_writeb(gInstance->func[func], *byte,
592 sdio_release_host(gInstance->func[func]);
595 /* Claim host controller, perform Fn write,
597 sdio_claim_host(gInstance->func[func]);
598 sdio_writeb(gInstance->func[func], *byte, regaddr,
600 sdio_release_host(gInstance->func[func]);
602 } else { /* CMD52 Read */
603 /* Claim host controller, perform Fn read, and release */
604 sdio_claim_host(gInstance->func[func]);
608 sdio_f0_readb(gInstance->func[func], regaddr,
612 sdio_readb(gInstance->func[func], regaddr,
616 sdio_release_host(gInstance->func[func]);
620 sd_err(("bcmsdh_sdmmc: Failed to %s byte F%d:@0x%05x=%02x, "
621 "Err: %d\n", rw ? "Write" : "Read", func, regaddr,
624 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
628 brcmf_sdioh_request_word(struct sdioh_info *sd, uint cmd_type, uint rw,
629 uint func, uint addr, u32 *word, uint nbytes)
631 int err_ret = SDIOH_API_RC_FAIL;
634 sd_err(("%s: Only CMD52 allowed to F0.\n", __func__));
635 return SDIOH_API_RC_FAIL;
638 sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
639 __func__, cmd_type, rw, func, addr, nbytes));
641 DHD_PM_RESUME_WAIT(sdioh_request_word_wait);
642 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
643 /* Claim host controller */
644 sdio_claim_host(gInstance->func[func]);
646 if (rw) { /* CMD52 Write */
648 sdio_writel(gInstance->func[func], *word, addr,
650 } else if (nbytes == 2) {
651 sdio_writew(gInstance->func[func], (*word & 0xFFFF),
654 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
656 } else { /* CMD52 Read */
659 sdio_readl(gInstance->func[func], addr, &err_ret);
660 } else if (nbytes == 2) {
662 sdio_readw(gInstance->func[func], addr,
665 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
669 /* Release host controller */
670 sdio_release_host(gInstance->func[func]);
673 sd_err(("bcmsdh_sdmmc: Failed to %s word, Err: 0x%08x",
674 rw ? "Write" : "Read", err_ret));
677 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
681 brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
682 uint func, uint addr, struct sk_buff *pkt)
684 bool fifo = (fix_inc == SDIOH_DATA_FIX);
688 struct sk_buff *pnext;
690 sd_trace(("%s: Enter\n", __func__));
693 DHD_PM_RESUME_WAIT(sdioh_request_packet_wait);
694 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
696 /* Claim host controller */
697 sdio_claim_host(gInstance->func[func]);
698 for (pnext = pkt; pnext; pnext = pnext->next) {
699 uint pkt_len = pnext->len;
701 pkt_len &= 0xFFFFFFFC;
703 /* Make sure the packet is aligned properly.
704 * If it isn't, then this
705 * is the fault of brcmf_sdioh_request_buffer() which
706 * is supposed to give
707 * us something we can work with.
709 ASSERT(((u32) (pkt->data) & DMA_ALIGN_MASK) == 0);
711 if ((write) && (!fifo)) {
712 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
713 ((u8 *) (pnext->data)),
716 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
717 ((u8 *) (pnext->data)),
720 err_ret = sdio_readsb(gInstance->func[func],
721 ((u8 *) (pnext->data)),
724 err_ret = sdio_memcpy_fromio(gInstance->func[func],
725 ((u8 *) (pnext->data)),
730 sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d,"
731 "ERR=0x%08x\n", __func__,
732 (write) ? "TX" : "RX",
733 pnext, SGCount, addr, pkt_len, err_ret));
735 sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
737 (write) ? "TX" : "RX",
738 pnext, SGCount, addr, pkt_len));
747 /* Release host controller */
748 sdio_release_host(gInstance->func[func]);
750 sd_trace(("%s: Exit\n", __func__));
751 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
755 * This function takes a buffer or packet, and fixes everything up
756 * so that in the end, a DMA-able packet is created.
758 * A buffer does not have an associated packet pointer,
759 * and may or may not be aligned.
760 * A packet may consist of a single packet, or a packet chain.
761 * If it is a packet chain, then all the packets in the chain
762 * must be properly aligned.
764 * If the packet data is not aligned, then there may only be
765 * one packet, and in this case, it is copied to a new
770 brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
771 uint write, uint func, uint addr, uint reg_width,
772 uint buflen_u, u8 *buffer, struct sk_buff *pkt)
775 struct sk_buff *mypkt = NULL;
777 sd_trace(("%s: Enter\n", __func__));
779 DHD_PM_RESUME_WAIT(sdioh_request_buffer_wait);
780 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
781 /* Case 1: we don't have a packet. */
783 sd_data(("%s: Creating new %s Packet, len=%d\n",
784 __func__, write ? "TX" : "RX", buflen_u));
785 mypkt = brcmu_pkt_buf_get_skb(buflen_u);
787 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
788 __func__, buflen_u));
789 return SDIOH_API_RC_FAIL;
792 /* For a write, copy the buffer data into the packet. */
794 memcpy(mypkt->data, buffer, buflen_u);
796 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
799 /* For a read, copy the packet data back to the buffer. */
801 memcpy(buffer, mypkt->data, buflen_u);
803 brcmu_pkt_buf_free_skb(mypkt);
804 } else if (((u32) (pkt->data) & DMA_ALIGN_MASK) != 0) {
805 /* Case 2: We have a packet, but it is unaligned. */
807 /* In this case, we cannot have a chain. */
808 ASSERT(pkt->next == NULL);
810 sd_data(("%s: Creating aligned %s Packet, len=%d\n",
811 __func__, write ? "TX" : "RX", pkt->len));
812 mypkt = brcmu_pkt_buf_get_skb(pkt->len);
814 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
815 __func__, pkt->len));
816 return SDIOH_API_RC_FAIL;
819 /* For a write, copy the buffer data into the packet. */
821 memcpy(mypkt->data, pkt->data, pkt->len);
823 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
826 /* For a read, copy the packet data back to the buffer. */
828 memcpy(pkt->data, mypkt->data, mypkt->len);
830 brcmu_pkt_buf_free_skb(mypkt);
831 } else { /* case 3: We have a packet and
833 sd_data(("%s: Aligned %s Packet, direct DMA\n",
834 __func__, write ? "Tx" : "Rx"));
835 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
842 /* this function performs "abort" for both of host & device */
843 extern int brcmf_sdioh_abort(struct sdioh_info *sd, uint func)
845 char t_func = (char)func;
846 sd_trace(("%s: Enter\n", __func__));
848 /* issue abort cmd52 command through F0 */
849 brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT,
852 sd_trace(("%s: Exit\n", __func__));
853 return SDIOH_API_RC_SUCCESS;
856 /* Reset and re-initialize the device */
857 int brcmf_sdioh_reset(struct sdioh_info *si)
859 sd_trace(("%s: Enter\n", __func__));
860 sd_trace(("%s: Exit\n", __func__));
861 return SDIOH_API_RC_SUCCESS;
864 /* Disable device interrupt */
865 void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd)
867 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
868 sd->intmask &= ~CLIENT_INTR;
871 /* Enable device interrupt */
872 void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd)
874 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
875 sd->intmask |= CLIENT_INTR;
878 /* Read client card reg */
880 brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
881 int regsize, u32 *data)
884 if ((func == 0) || (regsize == 1)) {
887 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
890 sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
892 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data,
897 sd_data(("%s: word read data=0x%08x\n", __func__, *data));
903 /* bcmsdh_sdmmc interrupt handler */
904 static void brcmf_sdioh_irqhandler(struct sdio_func *func)
906 struct sdioh_info *sd;
908 sd_trace(("bcmsdh_sdmmc: ***IRQHandler\n"));
912 sdio_release_host(gInstance->func[0]);
914 if (sd->use_client_ints) {
916 ASSERT(sd->intr_handler);
917 ASSERT(sd->intr_handler_arg);
918 (sd->intr_handler) (sd->intr_handler_arg);
920 sd_err(("bcmsdh_sdmmc: ***IRQHandler\n"));
922 sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
923 __func__, sd->client_intr_enabled, sd->intr_handler));
926 sdio_claim_host(gInstance->func[0]);
929 /* bcmsdh_sdmmc interrupt handler for F2 (dummy handler) */
930 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func)
932 struct sdioh_info *sd;
934 sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n"));
941 int brcmf_sdioh_start(struct sdioh_info *si, int stage)
946 int brcmf_sdioh_stop(struct sdioh_info *si)