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 #if !defined(OOB_INTR_ONLY)
39 static void brcmf_sdioh_irqhandler(struct sdio_func *func);
40 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func);
41 #endif /* !defined(OOB_INTR_ONLY) */
42 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr);
43 extern int brcmf_sdioh_reset_comm(struct mmc_card *card);
45 extern PBCMSDH_SDMMC_INSTANCE gInstance;
47 uint sd_f2_blocksize = 512; /* Default blocksize */
49 uint sd_msglevel = 0x01;
50 DHD_PM_RESUME_WAIT_INIT(sdioh_request_byte_wait);
51 DHD_PM_RESUME_WAIT_INIT(sdioh_request_word_wait);
52 DHD_PM_RESUME_WAIT_INIT(sdioh_request_packet_wait);
53 DHD_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait);
55 #define DMA_ALIGN_MASK 0x03
57 int brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
58 int regsize, u32 *data);
60 void brcmf_sdioh_set_host_pm_flags(int flag)
62 if (sdio_set_host_pm_flags(gInstance->func[1], flag))
63 printk(KERN_ERR "%s: Failed to set pm_flags 0x%08x\n",\
64 __func__, (unsigned int)flag);
67 static int brcmf_sdioh_enablefuncs(struct sdioh_info *sd)
73 sd_trace(("%s\n", __func__));
75 /* Get the Card's common CIS address */
76 sd->com_cis_ptr = brcmf_sdioh_get_cisaddr(sd, SDIO_CCCR_CIS);
77 sd->func_cis_ptr[0] = sd->com_cis_ptr;
78 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
81 /* Get the Card's function CIS (for each function) */
82 for (fbraddr = SDIO_FBR_BASE(1), func = 1;
83 func <= sd->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) {
84 sd->func_cis_ptr[func] =
85 brcmf_sdioh_get_cisaddr(sd, SDIO_FBR_CIS + fbraddr);
86 sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__, func,
87 sd->func_cis_ptr[func]));
90 sd->func_cis_ptr[0] = sd->com_cis_ptr;
91 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
94 /* Enable Function 1 */
95 sdio_claim_host(gInstance->func[1]);
96 err_ret = sdio_enable_func(gInstance->func[1]);
97 sdio_release_host(gInstance->func[1]);
99 sd_err(("bcmsdh_sdmmc: Failed to enable F1 Err: 0x%08x",
107 * Public entry points & extern's
109 struct sdioh_info *brcmf_sdioh_attach(void *bar0, uint irq)
111 struct sdioh_info *sd;
114 sd_trace(("%s\n", __func__));
116 if (gInstance == NULL) {
117 sd_err(("%s: SDIO Device not present\n", __func__));
121 sd = kzalloc(sizeof(struct sdioh_info), GFP_ATOMIC);
123 sd_err(("sdioh_attach: out of memory\n"));
126 if (brcmf_sdioh_osinit(sd) != 0) {
127 sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__));
133 sd->use_client_ints = true;
134 sd->client_block_size[0] = 64;
138 /* Claim host controller */
139 sdio_claim_host(gInstance->func[1]);
141 sd->client_block_size[1] = 64;
142 err_ret = sdio_set_block_size(gInstance->func[1], 64);
144 sd_err(("bcmsdh_sdmmc: Failed to set F1 blocksize\n"));
146 /* Release host controller F1 */
147 sdio_release_host(gInstance->func[1]);
149 if (gInstance->func[2]) {
150 /* Claim host controller F2 */
151 sdio_claim_host(gInstance->func[2]);
153 sd->client_block_size[2] = sd_f2_blocksize;
155 sdio_set_block_size(gInstance->func[2], sd_f2_blocksize);
157 sd_err(("bcmsdh_sdmmc: Failed to set F2 blocksize "
158 "to %d\n", sd_f2_blocksize));
160 /* Release host controller F2 */
161 sdio_release_host(gInstance->func[2]);
164 brcmf_sdioh_enablefuncs(sd);
166 sd_trace(("%s: Done\n", __func__));
170 extern int brcmf_sdioh_detach(struct sdioh_info *sd)
172 sd_trace(("%s\n", __func__));
176 /* Disable Function 2 */
177 sdio_claim_host(gInstance->func[2]);
178 sdio_disable_func(gInstance->func[2]);
179 sdio_release_host(gInstance->func[2]);
181 /* Disable Function 1 */
182 sdio_claim_host(gInstance->func[1]);
183 sdio_disable_func(gInstance->func[1]);
184 sdio_release_host(gInstance->func[1]);
187 brcmf_sdioh_osfree(sd);
191 return SDIOH_API_RC_SUCCESS;
194 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
196 extern int brcmf_sdioh_enable_func_intr(void)
201 if (gInstance->func[0]) {
202 sdio_claim_host(gInstance->func[0]);
204 reg = sdio_readb(gInstance->func[0], SDIOD_CCCR_INTEN, &err);
206 sd_err(("%s: error for read SDIO_CCCR_IENx : 0x%x\n",
208 sdio_release_host(gInstance->func[0]);
209 return SDIOH_API_RC_FAIL;
212 /* Enable F1 and F2 interrupts, set master enable */
214 (INTR_CTL_FUNC1_EN | INTR_CTL_FUNC2_EN |
217 sdio_writeb(gInstance->func[0], reg, SDIOD_CCCR_INTEN, &err);
218 sdio_release_host(gInstance->func[0]);
221 sd_err(("%s: error for write SDIO_CCCR_IENx : 0x%x\n",
223 return SDIOH_API_RC_FAIL;
227 return SDIOH_API_RC_SUCCESS;
230 extern int brcmf_sdioh_disable_func_intr(void)
235 if (gInstance->func[0]) {
236 sdio_claim_host(gInstance->func[0]);
237 reg = sdio_readb(gInstance->func[0], SDIOD_CCCR_INTEN, &err);
239 sd_err(("%s: error for read SDIO_CCCR_IENx : 0x%x\n",
241 sdio_release_host(gInstance->func[0]);
242 return SDIOH_API_RC_FAIL;
245 reg &= ~(INTR_CTL_FUNC1_EN | INTR_CTL_FUNC2_EN);
246 /* Disable master interrupt with the last function interrupt */
249 sdio_writeb(gInstance->func[0], reg, SDIOD_CCCR_INTEN, &err);
251 sdio_release_host(gInstance->func[0]);
253 sd_err(("%s: error for write SDIO_CCCR_IENx : 0x%x\n",
255 return SDIOH_API_RC_FAIL;
258 return SDIOH_API_RC_SUCCESS;
260 #endif /* defined(OOB_INTR_ONLY) && defined(HW_OOB) */
262 /* Configure callback to client when we receive client interrupt */
264 brcmf_sdioh_interrupt_register(struct sdioh_info *sd, sdioh_cb_fn_t fn,
267 sd_trace(("%s: Entering\n", __func__));
269 sd_err(("%s: interrupt handler is NULL, not registering\n",
271 return SDIOH_API_RC_FAIL;
273 #if !defined(OOB_INTR_ONLY)
274 sd->intr_handler = fn;
275 sd->intr_handler_arg = argh;
276 sd->intr_handler_valid = true;
278 /* register and unmask irq */
279 if (gInstance->func[2]) {
280 sdio_claim_host(gInstance->func[2]);
281 sdio_claim_irq(gInstance->func[2], brcmf_sdioh_irqhandler_f2);
282 sdio_release_host(gInstance->func[2]);
285 if (gInstance->func[1]) {
286 sdio_claim_host(gInstance->func[1]);
287 sdio_claim_irq(gInstance->func[1], brcmf_sdioh_irqhandler);
288 sdio_release_host(gInstance->func[1]);
290 #elif defined(HW_OOB)
291 brcmf_sdioh_enable_func_intr();
292 #endif /* defined(OOB_INTR_ONLY) */
293 return SDIOH_API_RC_SUCCESS;
296 extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *sd)
298 sd_trace(("%s: Entering\n", __func__));
300 #if !defined(OOB_INTR_ONLY)
301 if (gInstance->func[1]) {
302 /* register and unmask irq */
303 sdio_claim_host(gInstance->func[1]);
304 sdio_release_irq(gInstance->func[1]);
305 sdio_release_host(gInstance->func[1]);
308 if (gInstance->func[2]) {
309 /* Claim host controller F2 */
310 sdio_claim_host(gInstance->func[2]);
311 sdio_release_irq(gInstance->func[2]);
312 /* Release host controller F2 */
313 sdio_release_host(gInstance->func[2]);
316 sd->intr_handler_valid = false;
317 sd->intr_handler = NULL;
318 sd->intr_handler_arg = NULL;
319 #elif defined(HW_OOB)
320 brcmf_sdioh_disable_func_intr();
321 #endif /* !defined(OOB_INTR_ONLY) */
322 return SDIOH_API_RC_SUCCESS;
326 brcmf_sdioh_interrupt_query(struct sdioh_info *sd, bool *onoff)
328 sd_trace(("%s: Entering\n", __func__));
329 *onoff = sd->client_intr_enabled;
330 return SDIOH_API_RC_SUCCESS;
333 #if defined(DHD_DEBUG)
334 extern bool brcmf_sdioh_interrupt_pending(struct sdioh_info *sd)
340 uint brcmf_sdioh_query_iofnum(struct sdioh_info *sd)
342 return sd->num_funcs;
356 const struct brcmu_iovar sdioh_iovars[] = {
357 {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0},
358 {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0},/* ((fn << 16) |
360 {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0},
361 {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0},
362 {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(sdreg_t)}
364 {"sd_rxchain", IOV_RXCHAIN, 0, IOVT_BOOL, 0}
370 brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name,
371 void *params, int plen, void *arg, int len, bool set)
373 const struct brcmu_iovar *vi = NULL;
383 /* Get must have return space; Set does not take qualifiers */
384 ASSERT(set || (arg && len));
385 ASSERT(!set || (!params && !plen));
387 sd_trace(("%s: Enter (%s %s)\n", __func__, (set ? "set" : "get"),
390 vi = brcmu_iovar_lookup(sdioh_iovars, name);
392 bcmerror = -ENOTSUPP;
396 bcmerror = brcmu_iovar_lencheck(vi, arg, len, set);
400 /* Set up params so get and set can share the convenience variables */
401 if (params == NULL) {
406 if (vi->type == IOVT_VOID)
408 else if (vi->type == IOVT_BUFFER)
411 val_size = sizeof(int);
413 if (plen >= (int)sizeof(int_val))
414 memcpy(&int_val, params, sizeof(int_val));
416 bool_val = (int_val != 0) ? true : false;
418 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
420 case IOV_GVAL(IOV_MSGLEVEL):
421 int_val = (s32) sd_msglevel;
422 memcpy(arg, &int_val, val_size);
425 case IOV_SVAL(IOV_MSGLEVEL):
426 sd_msglevel = int_val;
429 case IOV_GVAL(IOV_BLOCKSIZE):
430 if ((u32) int_val > si->num_funcs) {
434 int_val = (s32) si->client_block_size[int_val];
435 memcpy(arg, &int_val, val_size);
438 case IOV_SVAL(IOV_BLOCKSIZE):
440 uint func = ((u32) int_val >> 16);
441 uint blksize = (u16) int_val;
444 if (func > si->num_funcs) {
454 maxsize = BLOCK_SIZE_4318;
457 maxsize = BLOCK_SIZE_4328;
462 if (blksize > maxsize) {
470 si->client_block_size[func] = blksize;
475 case IOV_GVAL(IOV_RXCHAIN):
477 memcpy(arg, &int_val, val_size);
480 case IOV_GVAL(IOV_USEINTS):
481 int_val = (s32) si->use_client_ints;
482 memcpy(arg, &int_val, val_size);
485 case IOV_SVAL(IOV_USEINTS):
486 si->use_client_ints = (bool) int_val;
487 if (si->use_client_ints)
488 si->intmask |= CLIENT_INTR;
490 si->intmask &= ~CLIENT_INTR;
494 case IOV_GVAL(IOV_NUMINTS):
495 int_val = (s32) si->intrcount;
496 memcpy(arg, &int_val, val_size);
499 case IOV_GVAL(IOV_DEVREG):
501 sdreg_t *sd_ptr = (sdreg_t *) params;
504 if (brcmf_sdioh_cfg_read
505 (si, sd_ptr->func, sd_ptr->offset, &data)) {
511 memcpy(arg, &int_val, sizeof(int_val));
515 case IOV_SVAL(IOV_DEVREG):
517 sdreg_t *sd_ptr = (sdreg_t *) params;
518 u8 data = (u8) sd_ptr->value;
520 if (brcmf_sdioh_cfg_write
521 (si, sd_ptr->func, sd_ptr->offset, &data)) {
529 bcmerror = -ENOTSUPP;
537 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
539 int brcmf_sdioh_enable_hw_oob_intr(struct sdioh_info *sd, bool enable)
545 data = 3; /* enable hw oob interrupt */
547 data = 4; /* disable hw oob interrupt */
548 data |= 4; /* Active HIGH */
550 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, 0, 0xf2, &data);
553 #endif /* defined(OOB_INTR_ONLY) && defined(HW_OOB) */
556 brcmf_sdioh_cfg_read(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
559 /* No lock needed since brcmf_sdioh_request_byte does locking */
560 status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
565 brcmf_sdioh_cfg_write(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
567 /* No lock needed since brcmf_sdioh_request_byte does locking */
569 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
573 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr)
575 /* read 24 bits and return valid 17 bit addr */
577 u32 scratch, regdata;
578 u8 *ptr = (u8 *)&scratch;
579 for (i = 0; i < 3; i++) {
580 if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, ®data)) !=
582 sd_err(("%s: Can't read!\n", __func__));
584 *ptr++ = (u8) regdata;
588 /* Only the lower 17-bits are valid */
589 scratch = le32_to_cpu(scratch);
590 scratch &= 0x0001FFFF;
595 brcmf_sdioh_cis_read(struct sdioh_info *sd, uint func, u8 *cisd, u32 length)
602 sd_trace(("%s: Func = %d\n", __func__, func));
604 if (!sd->func_cis_ptr[func]) {
605 memset(cis, 0, length);
606 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
607 return SDIOH_API_RC_FAIL;
610 sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func,
611 sd->func_cis_ptr[func]));
613 for (count = 0; count < length; count++) {
614 offset = sd->func_cis_ptr[func] + count;
615 if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) {
616 sd_err(("%s: regread failed: Can't read CIS\n",
618 return SDIOH_API_RC_FAIL;
621 *cis = (u8) (foo & 0xff);
625 return SDIOH_API_RC_SUCCESS;
629 brcmf_sdioh_request_byte(struct sdioh_info *sd, uint rw, uint func,
630 uint regaddr, u8 *byte)
634 sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func,
637 DHD_PM_RESUME_WAIT(sdioh_request_byte_wait);
638 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
639 if (rw) { /* CMD52 Write */
641 /* Can only directly write to some F0 registers.
645 if (regaddr == SDIO_CCCR_IOEx) {
646 if (gInstance->func[2]) {
647 sdio_claim_host(gInstance->func[2]);
648 if (*byte & SDIO_FUNC_ENABLE_2) {
649 /* Enable Function 2 */
652 (gInstance->func[2]);
654 sd_err(("bcmsdh_sdmmc: enable F2 failed:%d",
657 /* Disable Function 2 */
660 (gInstance->func[2]);
662 sd_err(("bcmsdh_sdmmc: Disab F2 failed:%d",
665 sdio_release_host(gInstance->func[2]);
668 #if defined(MMC_SDIO_ABORT)
669 /* to allow abort command through F1 */
670 else if (regaddr == SDIO_CCCR_ABORT) {
671 sdio_claim_host(gInstance->func[func]);
673 * this sdio_f0_writeb() can be replaced
675 * depending upon MMC driver change.
676 * As of this time, this is temporaray one
678 sdio_writeb(gInstance->func[func], *byte,
680 sdio_release_host(gInstance->func[func]);
682 #endif /* MMC_SDIO_ABORT */
683 else if (regaddr < 0xF0) {
684 sd_err(("bcmsdh_sdmmc: F0 Wr:0x%02x: write "
685 "disallowed\n", regaddr));
687 /* Claim host controller, perform F0 write,
689 sdio_claim_host(gInstance->func[func]);
690 sdio_f0_writeb(gInstance->func[func], *byte,
692 sdio_release_host(gInstance->func[func]);
695 /* Claim host controller, perform Fn write,
697 sdio_claim_host(gInstance->func[func]);
698 sdio_writeb(gInstance->func[func], *byte, regaddr,
700 sdio_release_host(gInstance->func[func]);
702 } else { /* CMD52 Read */
703 /* Claim host controller, perform Fn read, and release */
704 sdio_claim_host(gInstance->func[func]);
708 sdio_f0_readb(gInstance->func[func], regaddr,
712 sdio_readb(gInstance->func[func], regaddr,
716 sdio_release_host(gInstance->func[func]);
720 sd_err(("bcmsdh_sdmmc: Failed to %s byte F%d:@0x%05x=%02x, "
721 "Err: %d\n", rw ? "Write" : "Read", func, regaddr,
724 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
728 brcmf_sdioh_request_word(struct sdioh_info *sd, uint cmd_type, uint rw,
729 uint func, uint addr, u32 *word, uint nbytes)
731 int err_ret = SDIOH_API_RC_FAIL;
734 sd_err(("%s: Only CMD52 allowed to F0.\n", __func__));
735 return SDIOH_API_RC_FAIL;
738 sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
739 __func__, cmd_type, rw, func, addr, nbytes));
741 DHD_PM_RESUME_WAIT(sdioh_request_word_wait);
742 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
743 /* Claim host controller */
744 sdio_claim_host(gInstance->func[func]);
746 if (rw) { /* CMD52 Write */
748 sdio_writel(gInstance->func[func], *word, addr,
750 } else if (nbytes == 2) {
751 sdio_writew(gInstance->func[func], (*word & 0xFFFF),
754 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
756 } else { /* CMD52 Read */
759 sdio_readl(gInstance->func[func], addr, &err_ret);
760 } else if (nbytes == 2) {
762 sdio_readw(gInstance->func[func], addr,
765 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
769 /* Release host controller */
770 sdio_release_host(gInstance->func[func]);
773 sd_err(("bcmsdh_sdmmc: Failed to %s word, Err: 0x%08x",
774 rw ? "Write" : "Read", err_ret));
777 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
781 brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
782 uint func, uint addr, struct sk_buff *pkt)
784 bool fifo = (fix_inc == SDIOH_DATA_FIX);
788 struct sk_buff *pnext;
790 sd_trace(("%s: Enter\n", __func__));
793 DHD_PM_RESUME_WAIT(sdioh_request_packet_wait);
794 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
796 /* Claim host controller */
797 sdio_claim_host(gInstance->func[func]);
798 for (pnext = pkt; pnext; pnext = pnext->next) {
799 uint pkt_len = pnext->len;
801 pkt_len &= 0xFFFFFFFC;
803 #ifdef CONFIG_MMC_MSM7X00A
804 if ((pkt_len % 64) == 32) {
805 sd_trace(("%s: Rounding up TX packet +=32\n",
809 #endif /* CONFIG_MMC_MSM7X00A */
810 /* Make sure the packet is aligned properly.
811 * If it isn't, then this
812 * is the fault of brcmf_sdioh_request_buffer() which
813 * is supposed to give
814 * us something we can work with.
816 ASSERT(((u32) (pkt->data) & DMA_ALIGN_MASK) == 0);
818 if ((write) && (!fifo)) {
819 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
820 ((u8 *) (pnext->data)),
823 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
824 ((u8 *) (pnext->data)),
827 err_ret = sdio_readsb(gInstance->func[func],
828 ((u8 *) (pnext->data)),
831 err_ret = sdio_memcpy_fromio(gInstance->func[func],
832 ((u8 *) (pnext->data)),
837 sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d,"
838 "ERR=0x%08x\n", __func__,
839 (write) ? "TX" : "RX",
840 pnext, SGCount, addr, pkt_len, err_ret));
842 sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
844 (write) ? "TX" : "RX",
845 pnext, SGCount, addr, pkt_len));
854 /* Release host controller */
855 sdio_release_host(gInstance->func[func]);
857 sd_trace(("%s: Exit\n", __func__));
858 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
862 * This function takes a buffer or packet, and fixes everything up
863 * so that in the end, a DMA-able packet is created.
865 * A buffer does not have an associated packet pointer,
866 * and may or may not be aligned.
867 * A packet may consist of a single packet, or a packet chain.
868 * If it is a packet chain, then all the packets in the chain
869 * must be properly aligned.
871 * If the packet data is not aligned, then there may only be
872 * one packet, and in this case, it is copied to a new
877 brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
878 uint write, uint func, uint addr, uint reg_width,
879 uint buflen_u, u8 *buffer, struct sk_buff *pkt)
882 struct sk_buff *mypkt = NULL;
884 sd_trace(("%s: Enter\n", __func__));
886 DHD_PM_RESUME_WAIT(sdioh_request_buffer_wait);
887 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
888 /* Case 1: we don't have a packet. */
890 sd_data(("%s: Creating new %s Packet, len=%d\n",
891 __func__, write ? "TX" : "RX", buflen_u));
892 mypkt = brcmu_pkt_buf_get_skb(buflen_u);
894 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
895 __func__, buflen_u));
896 return SDIOH_API_RC_FAIL;
899 /* For a write, copy the buffer data into the packet. */
901 memcpy(mypkt->data, buffer, buflen_u);
903 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
906 /* For a read, copy the packet data back to the buffer. */
908 memcpy(buffer, mypkt->data, buflen_u);
910 brcmu_pkt_buf_free_skb(mypkt);
911 } else if (((u32) (pkt->data) & DMA_ALIGN_MASK) != 0) {
912 /* Case 2: We have a packet, but it is unaligned. */
914 /* In this case, we cannot have a chain. */
915 ASSERT(pkt->next == NULL);
917 sd_data(("%s: Creating aligned %s Packet, len=%d\n",
918 __func__, write ? "TX" : "RX", pkt->len));
919 mypkt = brcmu_pkt_buf_get_skb(pkt->len);
921 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
922 __func__, pkt->len));
923 return SDIOH_API_RC_FAIL;
926 /* For a write, copy the buffer data into the packet. */
928 memcpy(mypkt->data, pkt->data, pkt->len);
930 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
933 /* For a read, copy the packet data back to the buffer. */
935 memcpy(pkt->data, mypkt->data, mypkt->len);
937 brcmu_pkt_buf_free_skb(mypkt);
938 } else { /* case 3: We have a packet and
940 sd_data(("%s: Aligned %s Packet, direct DMA\n",
941 __func__, write ? "Tx" : "Rx"));
942 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
949 /* this function performs "abort" for both of host & device */
950 extern int brcmf_sdioh_abort(struct sdioh_info *sd, uint func)
952 #if defined(MMC_SDIO_ABORT)
953 char t_func = (char)func;
954 #endif /* defined(MMC_SDIO_ABORT) */
955 sd_trace(("%s: Enter\n", __func__));
957 #if defined(MMC_SDIO_ABORT)
958 /* issue abort cmd52 command through F0 */
959 brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT,
961 #endif /* defined(MMC_SDIO_ABORT) */
963 sd_trace(("%s: Exit\n", __func__));
964 return SDIOH_API_RC_SUCCESS;
967 /* Reset and re-initialize the device */
968 int brcmf_sdioh_reset(struct sdioh_info *si)
970 sd_trace(("%s: Enter\n", __func__));
971 sd_trace(("%s: Exit\n", __func__));
972 return SDIOH_API_RC_SUCCESS;
975 /* Disable device interrupt */
976 void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd)
978 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
979 sd->intmask &= ~CLIENT_INTR;
982 /* Enable device interrupt */
983 void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd)
985 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
986 sd->intmask |= CLIENT_INTR;
989 /* Read client card reg */
991 brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
992 int regsize, u32 *data)
995 if ((func == 0) || (regsize == 1)) {
998 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
1001 sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
1003 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data,
1008 sd_data(("%s: word read data=0x%08x\n", __func__, *data));
1014 #if !defined(OOB_INTR_ONLY)
1015 /* bcmsdh_sdmmc interrupt handler */
1016 static void brcmf_sdioh_irqhandler(struct sdio_func *func)
1018 struct sdioh_info *sd;
1020 sd_trace(("bcmsdh_sdmmc: ***IRQHandler\n"));
1024 sdio_release_host(gInstance->func[0]);
1026 if (sd->use_client_ints) {
1028 ASSERT(sd->intr_handler);
1029 ASSERT(sd->intr_handler_arg);
1030 (sd->intr_handler) (sd->intr_handler_arg);
1032 sd_err(("bcmsdh_sdmmc: ***IRQHandler\n"));
1034 sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
1035 __func__, sd->client_intr_enabled, sd->intr_handler));
1038 sdio_claim_host(gInstance->func[0]);
1041 /* bcmsdh_sdmmc interrupt handler for F2 (dummy handler) */
1042 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func)
1044 struct sdioh_info *sd;
1046 sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n"));
1052 #endif /* !defined(OOB_INTR_ONLY) */
1055 /* Write client card reg */
1057 brcmf_sdioh_card_regwrite(struct sdioh_info *sd, int func, u32 regaddr,
1058 int regsize, u32 data)
1061 if ((func == 0) || (regsize == 1)) {
1065 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
1066 sd_data(("%s: byte write data=0x%02x\n", __func__, data));
1071 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr,
1074 sd_data(("%s: word write data=0x%08x\n", __func__, data));
1079 #endif /* NOTUSED */
1081 int brcmf_sdioh_start(struct sdioh_info *si, int stage)
1086 int brcmf_sdioh_stop(struct sdioh_info *si)