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(sdioh_info_t *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(sdioh_info_t *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(sdioh_info_t *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 sdioh_info_t *brcmf_sdioh_attach(void *bar0, uint irq)
114 sd_trace(("%s\n", __func__));
116 if (gInstance == NULL) {
117 sd_err(("%s: SDIO Device not present\n", __func__));
121 sd = kzalloc(sizeof(sdioh_info_t), 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 SDIOH_API_RC brcmf_sdioh_detach(sdioh_info_t *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 SDIOH_API_RC 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 SDIOH_API_RC 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(sdioh_info_t *sd, sdioh_cb_fn_t fn, void *argh)
266 sd_trace(("%s: Entering\n", __func__));
268 sd_err(("%s: interrupt handler is NULL, not registering\n",
270 return SDIOH_API_RC_FAIL;
272 #if !defined(OOB_INTR_ONLY)
273 sd->intr_handler = fn;
274 sd->intr_handler_arg = argh;
275 sd->intr_handler_valid = true;
277 /* register and unmask irq */
278 if (gInstance->func[2]) {
279 sdio_claim_host(gInstance->func[2]);
280 sdio_claim_irq(gInstance->func[2], brcmf_sdioh_irqhandler_f2);
281 sdio_release_host(gInstance->func[2]);
284 if (gInstance->func[1]) {
285 sdio_claim_host(gInstance->func[1]);
286 sdio_claim_irq(gInstance->func[1], brcmf_sdioh_irqhandler);
287 sdio_release_host(gInstance->func[1]);
289 #elif defined(HW_OOB)
290 brcmf_sdioh_enable_func_intr();
291 #endif /* defined(OOB_INTR_ONLY) */
292 return SDIOH_API_RC_SUCCESS;
295 extern SDIOH_API_RC brcmf_sdioh_interrupt_deregister(sdioh_info_t *sd)
297 sd_trace(("%s: Entering\n", __func__));
299 #if !defined(OOB_INTR_ONLY)
300 if (gInstance->func[1]) {
301 /* register and unmask irq */
302 sdio_claim_host(gInstance->func[1]);
303 sdio_release_irq(gInstance->func[1]);
304 sdio_release_host(gInstance->func[1]);
307 if (gInstance->func[2]) {
308 /* Claim host controller F2 */
309 sdio_claim_host(gInstance->func[2]);
310 sdio_release_irq(gInstance->func[2]);
311 /* Release host controller F2 */
312 sdio_release_host(gInstance->func[2]);
315 sd->intr_handler_valid = false;
316 sd->intr_handler = NULL;
317 sd->intr_handler_arg = NULL;
318 #elif defined(HW_OOB)
319 brcmf_sdioh_disable_func_intr();
320 #endif /* !defined(OOB_INTR_ONLY) */
321 return SDIOH_API_RC_SUCCESS;
324 extern SDIOH_API_RC brcmf_sdioh_interrupt_query(sdioh_info_t *sd, bool *onoff)
326 sd_trace(("%s: Entering\n", __func__));
327 *onoff = sd->client_intr_enabled;
328 return SDIOH_API_RC_SUCCESS;
331 #if defined(DHD_DEBUG)
332 extern bool brcmf_sdioh_interrupt_pending(sdioh_info_t *sd)
338 uint brcmf_sdioh_query_iofnum(sdioh_info_t *sd)
340 return sd->num_funcs;
354 const struct brcmu_iovar sdioh_iovars[] = {
355 {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0},
356 {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0},/* ((fn << 16) |
358 {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0},
359 {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0},
360 {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(sdreg_t)}
362 {"sd_rxchain", IOV_RXCHAIN, 0, IOVT_BOOL, 0}
368 brcmf_sdioh_iovar_op(sdioh_info_t *si, const char *name,
369 void *params, int plen, void *arg, int len, bool set)
371 const struct brcmu_iovar *vi = NULL;
381 /* Get must have return space; Set does not take qualifiers */
382 ASSERT(set || (arg && len));
383 ASSERT(!set || (!params && !plen));
385 sd_trace(("%s: Enter (%s %s)\n", __func__, (set ? "set" : "get"),
388 vi = brcmu_iovar_lookup(sdioh_iovars, name);
390 bcmerror = -ENOTSUPP;
394 bcmerror = brcmu_iovar_lencheck(vi, arg, len, set);
398 /* Set up params so get and set can share the convenience variables */
399 if (params == NULL) {
404 if (vi->type == IOVT_VOID)
406 else if (vi->type == IOVT_BUFFER)
409 val_size = sizeof(int);
411 if (plen >= (int)sizeof(int_val))
412 memcpy(&int_val, params, sizeof(int_val));
414 bool_val = (int_val != 0) ? true : false;
416 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
418 case IOV_GVAL(IOV_MSGLEVEL):
419 int_val = (s32) sd_msglevel;
420 memcpy(arg, &int_val, val_size);
423 case IOV_SVAL(IOV_MSGLEVEL):
424 sd_msglevel = int_val;
427 case IOV_GVAL(IOV_BLOCKSIZE):
428 if ((u32) int_val > si->num_funcs) {
432 int_val = (s32) si->client_block_size[int_val];
433 memcpy(arg, &int_val, val_size);
436 case IOV_SVAL(IOV_BLOCKSIZE):
438 uint func = ((u32) int_val >> 16);
439 uint blksize = (u16) int_val;
442 if (func > si->num_funcs) {
452 maxsize = BLOCK_SIZE_4318;
455 maxsize = BLOCK_SIZE_4328;
460 if (blksize > maxsize) {
468 si->client_block_size[func] = blksize;
473 case IOV_GVAL(IOV_RXCHAIN):
475 memcpy(arg, &int_val, val_size);
478 case IOV_GVAL(IOV_USEINTS):
479 int_val = (s32) si->use_client_ints;
480 memcpy(arg, &int_val, val_size);
483 case IOV_SVAL(IOV_USEINTS):
484 si->use_client_ints = (bool) int_val;
485 if (si->use_client_ints)
486 si->intmask |= CLIENT_INTR;
488 si->intmask &= ~CLIENT_INTR;
492 case IOV_GVAL(IOV_NUMINTS):
493 int_val = (s32) si->intrcount;
494 memcpy(arg, &int_val, val_size);
497 case IOV_GVAL(IOV_DEVREG):
499 sdreg_t *sd_ptr = (sdreg_t *) params;
502 if (brcmf_sdioh_cfg_read
503 (si, sd_ptr->func, sd_ptr->offset, &data)) {
509 memcpy(arg, &int_val, sizeof(int_val));
513 case IOV_SVAL(IOV_DEVREG):
515 sdreg_t *sd_ptr = (sdreg_t *) params;
516 u8 data = (u8) sd_ptr->value;
518 if (brcmf_sdioh_cfg_write
519 (si, sd_ptr->func, sd_ptr->offset, &data)) {
527 bcmerror = -ENOTSUPP;
535 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
537 SDIOH_API_RC brcmf_sdioh_enable_hw_oob_intr(sdioh_info_t *sd, bool enable)
543 data = 3; /* enable hw oob interrupt */
545 data = 4; /* disable hw oob interrupt */
546 data |= 4; /* Active HIGH */
548 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, 0, 0xf2, &data);
551 #endif /* defined(OOB_INTR_ONLY) && defined(HW_OOB) */
554 brcmf_sdioh_cfg_read(sdioh_info_t *sd, uint fnc_num, u32 addr, u8 *data)
557 /* No lock needed since brcmf_sdioh_request_byte does locking */
558 status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
563 brcmf_sdioh_cfg_write(sdioh_info_t *sd, uint fnc_num, u32 addr, u8 *data)
565 /* No lock needed since brcmf_sdioh_request_byte does locking */
567 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
571 static int brcmf_sdioh_get_cisaddr(sdioh_info_t *sd, u32 regaddr)
573 /* read 24 bits and return valid 17 bit addr */
575 u32 scratch, regdata;
576 u8 *ptr = (u8 *)&scratch;
577 for (i = 0; i < 3; i++) {
578 if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, ®data)) !=
580 sd_err(("%s: Can't read!\n", __func__));
582 *ptr++ = (u8) regdata;
586 /* Only the lower 17-bits are valid */
587 scratch = le32_to_cpu(scratch);
588 scratch &= 0x0001FFFF;
593 brcmf_sdioh_cis_read(sdioh_info_t *sd, uint func, u8 *cisd, u32 length)
600 sd_trace(("%s: Func = %d\n", __func__, func));
602 if (!sd->func_cis_ptr[func]) {
603 memset(cis, 0, length);
604 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
605 return SDIOH_API_RC_FAIL;
608 sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func,
609 sd->func_cis_ptr[func]));
611 for (count = 0; count < length; count++) {
612 offset = sd->func_cis_ptr[func] + count;
613 if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) {
614 sd_err(("%s: regread failed: Can't read CIS\n",
616 return SDIOH_API_RC_FAIL;
619 *cis = (u8) (foo & 0xff);
623 return SDIOH_API_RC_SUCCESS;
627 brcmf_sdioh_request_byte(sdioh_info_t *sd, uint rw, uint func, uint regaddr,
632 sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func,
635 DHD_PM_RESUME_WAIT(sdioh_request_byte_wait);
636 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
637 if (rw) { /* CMD52 Write */
639 /* Can only directly write to some F0 registers.
643 if (regaddr == SDIO_CCCR_IOEx) {
644 if (gInstance->func[2]) {
645 sdio_claim_host(gInstance->func[2]);
646 if (*byte & SDIO_FUNC_ENABLE_2) {
647 /* Enable Function 2 */
650 (gInstance->func[2]);
652 sd_err(("bcmsdh_sdmmc: enable F2 failed:%d",
655 /* Disable Function 2 */
658 (gInstance->func[2]);
660 sd_err(("bcmsdh_sdmmc: Disab F2 failed:%d",
663 sdio_release_host(gInstance->func[2]);
666 #if defined(MMC_SDIO_ABORT)
667 /* to allow abort command through F1 */
668 else if (regaddr == SDIO_CCCR_ABORT) {
669 sdio_claim_host(gInstance->func[func]);
671 * this sdio_f0_writeb() can be replaced
673 * depending upon MMC driver change.
674 * As of this time, this is temporaray one
676 sdio_writeb(gInstance->func[func], *byte,
678 sdio_release_host(gInstance->func[func]);
680 #endif /* MMC_SDIO_ABORT */
681 else if (regaddr < 0xF0) {
682 sd_err(("bcmsdh_sdmmc: F0 Wr:0x%02x: write "
683 "disallowed\n", regaddr));
685 /* Claim host controller, perform F0 write,
687 sdio_claim_host(gInstance->func[func]);
688 sdio_f0_writeb(gInstance->func[func], *byte,
690 sdio_release_host(gInstance->func[func]);
693 /* Claim host controller, perform Fn write,
695 sdio_claim_host(gInstance->func[func]);
696 sdio_writeb(gInstance->func[func], *byte, regaddr,
698 sdio_release_host(gInstance->func[func]);
700 } else { /* CMD52 Read */
701 /* Claim host controller, perform Fn read, and release */
702 sdio_claim_host(gInstance->func[func]);
706 sdio_f0_readb(gInstance->func[func], regaddr,
710 sdio_readb(gInstance->func[func], regaddr,
714 sdio_release_host(gInstance->func[func]);
718 sd_err(("bcmsdh_sdmmc: Failed to %s byte F%d:@0x%05x=%02x, "
719 "Err: %d\n", rw ? "Write" : "Read", func, regaddr,
722 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
726 brcmf_sdioh_request_word(sdioh_info_t *sd, uint cmd_type, uint rw, uint func,
727 uint addr, u32 *word, uint nbytes)
729 int err_ret = SDIOH_API_RC_FAIL;
732 sd_err(("%s: Only CMD52 allowed to F0.\n", __func__));
733 return SDIOH_API_RC_FAIL;
736 sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
737 __func__, cmd_type, rw, func, addr, nbytes));
739 DHD_PM_RESUME_WAIT(sdioh_request_word_wait);
740 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
741 /* Claim host controller */
742 sdio_claim_host(gInstance->func[func]);
744 if (rw) { /* CMD52 Write */
746 sdio_writel(gInstance->func[func], *word, addr,
748 } else if (nbytes == 2) {
749 sdio_writew(gInstance->func[func], (*word & 0xFFFF),
752 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
754 } else { /* CMD52 Read */
757 sdio_readl(gInstance->func[func], addr, &err_ret);
758 } else if (nbytes == 2) {
760 sdio_readw(gInstance->func[func], addr,
763 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
767 /* Release host controller */
768 sdio_release_host(gInstance->func[func]);
771 sd_err(("bcmsdh_sdmmc: Failed to %s word, Err: 0x%08x",
772 rw ? "Write" : "Read", err_ret));
775 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
779 brcmf_sdioh_request_packet(sdioh_info_t *sd, uint fix_inc, uint write,
780 uint func, uint addr, struct sk_buff *pkt)
782 bool fifo = (fix_inc == SDIOH_DATA_FIX);
786 struct sk_buff *pnext;
788 sd_trace(("%s: Enter\n", __func__));
791 DHD_PM_RESUME_WAIT(sdioh_request_packet_wait);
792 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
794 /* Claim host controller */
795 sdio_claim_host(gInstance->func[func]);
796 for (pnext = pkt; pnext; pnext = pnext->next) {
797 uint pkt_len = pnext->len;
799 pkt_len &= 0xFFFFFFFC;
801 #ifdef CONFIG_MMC_MSM7X00A
802 if ((pkt_len % 64) == 32) {
803 sd_trace(("%s: Rounding up TX packet +=32\n",
807 #endif /* CONFIG_MMC_MSM7X00A */
808 /* Make sure the packet is aligned properly.
809 * If it isn't, then this
810 * is the fault of brcmf_sdioh_request_buffer() which
811 * is supposed to give
812 * us something we can work with.
814 ASSERT(((u32) (pkt->data) & DMA_ALIGN_MASK) == 0);
816 if ((write) && (!fifo)) {
817 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
818 ((u8 *) (pnext->data)),
821 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
822 ((u8 *) (pnext->data)),
825 err_ret = sdio_readsb(gInstance->func[func],
826 ((u8 *) (pnext->data)),
829 err_ret = sdio_memcpy_fromio(gInstance->func[func],
830 ((u8 *) (pnext->data)),
835 sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d,"
836 "ERR=0x%08x\n", __func__,
837 (write) ? "TX" : "RX",
838 pnext, SGCount, addr, pkt_len, err_ret));
840 sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
842 (write) ? "TX" : "RX",
843 pnext, SGCount, addr, pkt_len));
852 /* Release host controller */
853 sdio_release_host(gInstance->func[func]);
855 sd_trace(("%s: Exit\n", __func__));
856 return ((err_ret == 0) ? SDIOH_API_RC_SUCCESS : SDIOH_API_RC_FAIL);
860 * This function takes a buffer or packet, and fixes everything up
861 * so that in the end, a DMA-able packet is created.
863 * A buffer does not have an associated packet pointer,
864 * and may or may not be aligned.
865 * A packet may consist of a single packet, or a packet chain.
866 * If it is a packet chain, then all the packets in the chain
867 * must be properly aligned.
869 * If the packet data is not aligned, then there may only be
870 * one packet, and in this case, it is copied to a new
875 brcmf_sdioh_request_buffer(sdioh_info_t *sd, uint pio_dma, uint fix_inc,
876 uint write, uint func, uint addr, uint reg_width,
877 uint buflen_u, u8 *buffer, struct sk_buff *pkt)
880 struct sk_buff *mypkt = NULL;
882 sd_trace(("%s: Enter\n", __func__));
884 DHD_PM_RESUME_WAIT(sdioh_request_buffer_wait);
885 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
886 /* Case 1: we don't have a packet. */
888 sd_data(("%s: Creating new %s Packet, len=%d\n",
889 __func__, write ? "TX" : "RX", buflen_u));
890 mypkt = brcmu_pkt_buf_get_skb(buflen_u);
892 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
893 __func__, buflen_u));
894 return SDIOH_API_RC_FAIL;
897 /* For a write, copy the buffer data into the packet. */
899 memcpy(mypkt->data, buffer, buflen_u);
901 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
904 /* For a read, copy the packet data back to the buffer. */
906 memcpy(buffer, mypkt->data, buflen_u);
908 brcmu_pkt_buf_free_skb(mypkt);
909 } else if (((u32) (pkt->data) & DMA_ALIGN_MASK) != 0) {
910 /* Case 2: We have a packet, but it is unaligned. */
912 /* In this case, we cannot have a chain. */
913 ASSERT(pkt->next == NULL);
915 sd_data(("%s: Creating aligned %s Packet, len=%d\n",
916 __func__, write ? "TX" : "RX", pkt->len));
917 mypkt = brcmu_pkt_buf_get_skb(pkt->len);
919 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
920 __func__, pkt->len));
921 return SDIOH_API_RC_FAIL;
924 /* For a write, copy the buffer data into the packet. */
926 memcpy(mypkt->data, pkt->data, pkt->len);
928 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
931 /* For a read, copy the packet data back to the buffer. */
933 memcpy(pkt->data, mypkt->data, mypkt->len);
935 brcmu_pkt_buf_free_skb(mypkt);
936 } else { /* case 3: We have a packet and
938 sd_data(("%s: Aligned %s Packet, direct DMA\n",
939 __func__, write ? "Tx" : "Rx"));
940 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
947 /* this function performs "abort" for both of host & device */
948 extern int brcmf_sdioh_abort(sdioh_info_t *sd, uint func)
950 #if defined(MMC_SDIO_ABORT)
951 char t_func = (char)func;
952 #endif /* defined(MMC_SDIO_ABORT) */
953 sd_trace(("%s: Enter\n", __func__));
955 #if defined(MMC_SDIO_ABORT)
956 /* issue abort cmd52 command through F0 */
957 brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT,
959 #endif /* defined(MMC_SDIO_ABORT) */
961 sd_trace(("%s: Exit\n", __func__));
962 return SDIOH_API_RC_SUCCESS;
965 /* Reset and re-initialize the device */
966 int brcmf_sdioh_reset(sdioh_info_t *si)
968 sd_trace(("%s: Enter\n", __func__));
969 sd_trace(("%s: Exit\n", __func__));
970 return SDIOH_API_RC_SUCCESS;
973 /* Disable device interrupt */
974 void brcmf_sdioh_dev_intr_off(sdioh_info_t *sd)
976 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
977 sd->intmask &= ~CLIENT_INTR;
980 /* Enable device interrupt */
981 void brcmf_sdioh_dev_intr_on(sdioh_info_t *sd)
983 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
984 sd->intmask |= CLIENT_INTR;
987 /* Read client card reg */
989 brcmf_sdioh_card_regread(sdioh_info_t *sd, int func, u32 regaddr,
990 int regsize, u32 *data)
993 if ((func == 0) || (regsize == 1)) {
996 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
999 sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
1001 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data,
1006 sd_data(("%s: word read data=0x%08x\n", __func__, *data));
1012 #if !defined(OOB_INTR_ONLY)
1013 /* bcmsdh_sdmmc interrupt handler */
1014 static void brcmf_sdioh_irqhandler(struct sdio_func *func)
1018 sd_trace(("bcmsdh_sdmmc: ***IRQHandler\n"));
1022 sdio_release_host(gInstance->func[0]);
1024 if (sd->use_client_ints) {
1026 ASSERT(sd->intr_handler);
1027 ASSERT(sd->intr_handler_arg);
1028 (sd->intr_handler) (sd->intr_handler_arg);
1030 sd_err(("bcmsdh_sdmmc: ***IRQHandler\n"));
1032 sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
1033 __func__, sd->client_intr_enabled, sd->intr_handler));
1036 sdio_claim_host(gInstance->func[0]);
1039 /* bcmsdh_sdmmc interrupt handler for F2 (dummy handler) */
1040 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func)
1044 sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n"));
1050 #endif /* !defined(OOB_INTR_ONLY) */
1053 /* Write client card reg */
1055 brcmf_sdioh_card_regwrite(sdioh_info_t *sd, int func, u32 regaddr,
1056 int regsize, u32 data)
1059 if ((func == 0) || (regsize == 1)) {
1063 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
1064 sd_data(("%s: byte write data=0x%02x\n", __func__, data));
1069 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr,
1072 sd_data(("%s: word write data=0x%08x\n", __func__, data));
1077 #endif /* NOTUSED */
1079 int brcmf_sdioh_start(sdioh_info_t *si, int stage)
1084 int brcmf_sdioh_stop(sdioh_info_t *si)