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(struct brcmf_sdreg)}
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 struct brcmf_sdreg *sd_ptr =
502 (struct brcmf_sdreg *) params;
505 if (brcmf_sdioh_cfg_read
506 (si, sd_ptr->func, sd_ptr->offset, &data)) {
512 memcpy(arg, &int_val, sizeof(int_val));
516 case IOV_SVAL(IOV_DEVREG):
518 struct brcmf_sdreg *sd_ptr =
519 (struct brcmf_sdreg *) params;
520 u8 data = (u8) sd_ptr->value;
522 if (brcmf_sdioh_cfg_write
523 (si, sd_ptr->func, sd_ptr->offset, &data)) {
531 bcmerror = -ENOTSUPP;
539 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
541 int brcmf_sdioh_enable_hw_oob_intr(struct sdioh_info *sd, bool enable)
547 data = 3; /* enable hw oob interrupt */
549 data = 4; /* disable hw oob interrupt */
550 data |= 4; /* Active HIGH */
552 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, 0, 0xf2, &data);
555 #endif /* defined(OOB_INTR_ONLY) && defined(HW_OOB) */
558 brcmf_sdioh_cfg_read(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
561 /* No lock needed since brcmf_sdioh_request_byte does locking */
562 status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
567 brcmf_sdioh_cfg_write(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
569 /* No lock needed since brcmf_sdioh_request_byte does locking */
571 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
575 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr)
577 /* read 24 bits and return valid 17 bit addr */
579 u32 scratch, regdata;
580 u8 *ptr = (u8 *)&scratch;
581 for (i = 0; i < 3; i++) {
582 if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, ®data)) !=
584 sd_err(("%s: Can't read!\n", __func__));
586 *ptr++ = (u8) regdata;
590 /* Only the lower 17-bits are valid */
591 scratch = le32_to_cpu(scratch);
592 scratch &= 0x0001FFFF;
597 brcmf_sdioh_cis_read(struct sdioh_info *sd, uint func, u8 *cisd, u32 length)
604 sd_trace(("%s: Func = %d\n", __func__, func));
606 if (!sd->func_cis_ptr[func]) {
607 memset(cis, 0, length);
608 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
609 return SDIOH_API_RC_FAIL;
612 sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func,
613 sd->func_cis_ptr[func]));
615 for (count = 0; count < length; count++) {
616 offset = sd->func_cis_ptr[func] + count;
617 if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) {
618 sd_err(("%s: regread failed: Can't read CIS\n",
620 return SDIOH_API_RC_FAIL;
623 *cis = (u8) (foo & 0xff);
627 return SDIOH_API_RC_SUCCESS;
631 brcmf_sdioh_request_byte(struct sdioh_info *sd, uint rw, uint func,
632 uint regaddr, u8 *byte)
636 sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func,
639 DHD_PM_RESUME_WAIT(sdioh_request_byte_wait);
640 DHD_PM_RESUME_RETURN_ERROR(SDIOH_API_RC_FAIL);
641 if (rw) { /* CMD52 Write */
643 /* Can only directly write to some F0 registers.
647 if (regaddr == SDIO_CCCR_IOEx) {
648 if (gInstance->func[2]) {
649 sdio_claim_host(gInstance->func[2]);
650 if (*byte & SDIO_FUNC_ENABLE_2) {
651 /* Enable Function 2 */
654 (gInstance->func[2]);
656 sd_err(("bcmsdh_sdmmc: enable F2 failed:%d",
659 /* Disable Function 2 */
662 (gInstance->func[2]);
664 sd_err(("bcmsdh_sdmmc: Disab F2 failed:%d",
667 sdio_release_host(gInstance->func[2]);
670 /* to allow abort command through F1 */
671 else if (regaddr == SDIO_CCCR_ABORT) {
672 sdio_claim_host(gInstance->func[func]);
674 * this sdio_f0_writeb() can be replaced
676 * depending upon MMC driver change.
677 * As of this time, this is temporaray one
679 sdio_writeb(gInstance->func[func], *byte,
681 sdio_release_host(gInstance->func[func]);
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 char t_func = (char)func;
953 sd_trace(("%s: Enter\n", __func__));
955 /* issue abort cmd52 command through F0 */
956 brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT,
959 sd_trace(("%s: Exit\n", __func__));
960 return SDIOH_API_RC_SUCCESS;
963 /* Reset and re-initialize the device */
964 int brcmf_sdioh_reset(struct sdioh_info *si)
966 sd_trace(("%s: Enter\n", __func__));
967 sd_trace(("%s: Exit\n", __func__));
968 return SDIOH_API_RC_SUCCESS;
971 /* Disable device interrupt */
972 void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd)
974 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
975 sd->intmask &= ~CLIENT_INTR;
978 /* Enable device interrupt */
979 void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd)
981 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
982 sd->intmask |= CLIENT_INTR;
985 /* Read client card reg */
987 brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
988 int regsize, u32 *data)
991 if ((func == 0) || (regsize == 1)) {
994 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
997 sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
999 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data,
1004 sd_data(("%s: word read data=0x%08x\n", __func__, *data));
1010 #if !defined(OOB_INTR_ONLY)
1011 /* bcmsdh_sdmmc interrupt handler */
1012 static void brcmf_sdioh_irqhandler(struct sdio_func *func)
1014 struct sdioh_info *sd;
1016 sd_trace(("bcmsdh_sdmmc: ***IRQHandler\n"));
1020 sdio_release_host(gInstance->func[0]);
1022 if (sd->use_client_ints) {
1024 ASSERT(sd->intr_handler);
1025 ASSERT(sd->intr_handler_arg);
1026 (sd->intr_handler) (sd->intr_handler_arg);
1028 sd_err(("bcmsdh_sdmmc: ***IRQHandler\n"));
1030 sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
1031 __func__, sd->client_intr_enabled, sd->intr_handler));
1034 sdio_claim_host(gInstance->func[0]);
1037 /* bcmsdh_sdmmc interrupt handler for F2 (dummy handler) */
1038 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func)
1040 struct sdioh_info *sd;
1042 sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n"));
1048 #endif /* !defined(OOB_INTR_ONLY) */
1051 /* Write client card reg */
1053 brcmf_sdioh_card_regwrite(struct sdioh_info *sd, int func, u32 regaddr,
1054 int regsize, u32 data)
1057 if ((func == 0) || (regsize == 1)) {
1061 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
1062 sd_data(("%s: byte write data=0x%02x\n", __func__, data));
1067 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr,
1070 sd_data(("%s: word write data=0x%08x\n", __func__, data));
1075 #endif /* NOTUSED */
1077 int brcmf_sdioh_start(struct sdioh_info *si, int stage)
1082 int brcmf_sdioh_stop(struct sdioh_info *si)