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>
20 #include <brcm_hw_ids.h>
21 #include <brcmu_utils.h>
22 #include <brcmu_wifi.h>
23 #include "sdio_host.h"
24 #include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */
25 #include <sdiovar.h> /* ioctl/iovars */
27 #include <linux/mmc/core.h>
28 #include <linux/mmc/sdio_func.h>
29 #include <linux/mmc/sdio_ids.h>
30 #include <linux/suspend.h>
32 #include <dngl_stats.h>
35 #include "bcmsdh_sdmmc.h"
37 extern int sdio_function_init(void);
38 extern void sdio_function_cleanup(void);
40 #if !defined(OOB_INTR_ONLY)
41 static void IRQHandler(struct sdio_func *func);
42 static void IRQHandlerF2(struct sdio_func *func);
43 #endif /* !defined(OOB_INTR_ONLY) */
44 static int sdioh_sdmmc_get_cisaddr(sdioh_info_t *sd, u32 regaddr);
45 extern int sdio_reset_comm(struct mmc_card *card);
47 extern PBCMSDH_SDMMC_INSTANCE gInstance;
49 uint sd_f2_blocksize = 512; /* Default blocksize */
51 uint sd_msglevel = 0x01;
52 DHD_PM_RESUME_WAIT_INIT(sdioh_request_byte_wait);
53 DHD_PM_RESUME_WAIT_INIT(sdioh_request_word_wait);
54 DHD_PM_RESUME_WAIT_INIT(sdioh_request_packet_wait);
55 DHD_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait);
57 #define DMA_ALIGN_MASK 0x03
59 int sdioh_sdmmc_card_regread(sdioh_info_t *sd, int func, u32 regaddr,
60 int regsize, u32 *data);
62 void sdioh_sdio_set_host_pm_flags(int flag)
64 if (sdio_set_host_pm_flags(gInstance->func[1], flag))
65 printk(KERN_ERR "%s: Failed to set pm_flags 0x%08x\n",\
66 __func__, (unsigned int)flag);
69 static int sdioh_sdmmc_card_enablefuncs(sdioh_info_t *sd)
75 sd_trace(("%s\n", __func__));
77 /* Get the Card's common CIS address */
78 sd->com_cis_ptr = sdioh_sdmmc_get_cisaddr(sd, SDIO_CCCR_CIS);
79 sd->func_cis_ptr[0] = sd->com_cis_ptr;
80 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
83 /* Get the Card's function CIS (for each function) */
84 for (fbraddr = SDIO_FBR_BASE(1), func = 1;
85 func <= sd->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) {
86 sd->func_cis_ptr[func] =
87 sdioh_sdmmc_get_cisaddr(sd, SDIO_FBR_CIS + fbraddr);
88 sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__, func,
89 sd->func_cis_ptr[func]));
92 sd->func_cis_ptr[0] = sd->com_cis_ptr;
93 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
96 /* Enable Function 1 */
97 sdio_claim_host(gInstance->func[1]);
98 err_ret = sdio_enable_func(gInstance->func[1]);
99 sdio_release_host(gInstance->func[1]);
101 sd_err(("bcmsdh_sdmmc: Failed to enable F1 Err: 0x%08x",
109 * Public entry points & extern's
111 sdioh_info_t *sdioh_attach(void *bar0, uint irq)
116 sd_trace(("%s\n", __func__));
118 if (gInstance == NULL) {
119 sd_err(("%s: SDIO Device not present\n", __func__));
123 sd = kzalloc(sizeof(sdioh_info_t), GFP_ATOMIC);
125 sd_err(("sdioh_attach: out of memory\n"));
128 if (sdioh_sdmmc_osinit(sd) != 0) {
129 sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__));
135 sd->use_client_ints = true;
136 sd->client_block_size[0] = 64;
140 /* Claim host controller */
141 sdio_claim_host(gInstance->func[1]);
143 sd->client_block_size[1] = 64;
144 err_ret = sdio_set_block_size(gInstance->func[1], 64);
146 sd_err(("bcmsdh_sdmmc: Failed to set F1 blocksize\n"));
148 /* Release host controller F1 */
149 sdio_release_host(gInstance->func[1]);
151 if (gInstance->func[2]) {
152 /* Claim host controller F2 */
153 sdio_claim_host(gInstance->func[2]);
155 sd->client_block_size[2] = sd_f2_blocksize;
157 sdio_set_block_size(gInstance->func[2], sd_f2_blocksize);
159 sd_err(("bcmsdh_sdmmc: Failed to set F2 blocksize "
160 "to %d\n", sd_f2_blocksize));
162 /* Release host controller F2 */
163 sdio_release_host(gInstance->func[2]);
166 sdioh_sdmmc_card_enablefuncs(sd);
168 sd_trace(("%s: Done\n", __func__));
172 extern SDIOH_API_RC sdioh_detach(sdioh_info_t *sd)
174 sd_trace(("%s\n", __func__));
178 /* Disable Function 2 */
179 sdio_claim_host(gInstance->func[2]);
180 sdio_disable_func(gInstance->func[2]);
181 sdio_release_host(gInstance->func[2]);
183 /* Disable Function 1 */
184 sdio_claim_host(gInstance->func[1]);
185 sdio_disable_func(gInstance->func[1]);
186 sdio_release_host(gInstance->func[1]);
189 sdioh_sdmmc_osfree(sd);
193 return SDIOH_API_RC_SUCCESS;
196 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
198 extern SDIOH_API_RC sdioh_enable_func_intr(void)
203 if (gInstance->func[0]) {
204 sdio_claim_host(gInstance->func[0]);
206 reg = sdio_readb(gInstance->func[0], SDIOD_CCCR_INTEN, &err);
208 sd_err(("%s: error for read SDIO_CCCR_IENx : 0x%x\n",
210 sdio_release_host(gInstance->func[0]);
211 return SDIOH_API_RC_FAIL;
214 /* Enable F1 and F2 interrupts, set master enable */
216 (INTR_CTL_FUNC1_EN | INTR_CTL_FUNC2_EN |
219 sdio_writeb(gInstance->func[0], reg, SDIOD_CCCR_INTEN, &err);
220 sdio_release_host(gInstance->func[0]);
223 sd_err(("%s: error for write SDIO_CCCR_IENx : 0x%x\n",
225 return SDIOH_API_RC_FAIL;
229 return SDIOH_API_RC_SUCCESS;
232 extern SDIOH_API_RC sdioh_disable_func_intr(void)
237 if (gInstance->func[0]) {
238 sdio_claim_host(gInstance->func[0]);
239 reg = sdio_readb(gInstance->func[0], SDIOD_CCCR_INTEN, &err);
241 sd_err(("%s: error for read SDIO_CCCR_IENx : 0x%x\n",
243 sdio_release_host(gInstance->func[0]);
244 return SDIOH_API_RC_FAIL;
247 reg &= ~(INTR_CTL_FUNC1_EN | INTR_CTL_FUNC2_EN);
248 /* Disable master interrupt with the last function interrupt */
251 sdio_writeb(gInstance->func[0], reg, SDIOD_CCCR_INTEN, &err);
253 sdio_release_host(gInstance->func[0]);
255 sd_err(("%s: error for write SDIO_CCCR_IENx : 0x%x\n",
257 return SDIOH_API_RC_FAIL;
260 return SDIOH_API_RC_SUCCESS;
262 #endif /* defined(OOB_INTR_ONLY) && defined(HW_OOB) */
264 /* Configure callback to client when we receive client interrupt */
266 sdioh_interrupt_register(sdioh_info_t *sd, sdioh_cb_fn_t fn, void *argh)
268 sd_trace(("%s: Entering\n", __func__));
270 sd_err(("%s: interrupt handler is NULL, not registering\n",
272 return SDIOH_API_RC_FAIL;
274 #if !defined(OOB_INTR_ONLY)
275 sd->intr_handler = fn;
276 sd->intr_handler_arg = argh;
277 sd->intr_handler_valid = true;
279 /* register and unmask irq */
280 if (gInstance->func[2]) {
281 sdio_claim_host(gInstance->func[2]);
282 sdio_claim_irq(gInstance->func[2], IRQHandlerF2);
283 sdio_release_host(gInstance->func[2]);
286 if (gInstance->func[1]) {
287 sdio_claim_host(gInstance->func[1]);
288 sdio_claim_irq(gInstance->func[1], IRQHandler);
289 sdio_release_host(gInstance->func[1]);
291 #elif defined(HW_OOB)
292 sdioh_enable_func_intr();
293 #endif /* defined(OOB_INTR_ONLY) */
294 return SDIOH_API_RC_SUCCESS;
297 extern SDIOH_API_RC sdioh_interrupt_deregister(sdioh_info_t *sd)
299 sd_trace(("%s: Entering\n", __func__));
301 #if !defined(OOB_INTR_ONLY)
302 if (gInstance->func[1]) {
303 /* register and unmask irq */
304 sdio_claim_host(gInstance->func[1]);
305 sdio_release_irq(gInstance->func[1]);
306 sdio_release_host(gInstance->func[1]);
309 if (gInstance->func[2]) {
310 /* Claim host controller F2 */
311 sdio_claim_host(gInstance->func[2]);
312 sdio_release_irq(gInstance->func[2]);
313 /* Release host controller F2 */
314 sdio_release_host(gInstance->func[2]);
317 sd->intr_handler_valid = false;
318 sd->intr_handler = NULL;
319 sd->intr_handler_arg = NULL;
320 #elif defined(HW_OOB)
321 sdioh_disable_func_intr();
322 #endif /* !defined(OOB_INTR_ONLY) */
323 return SDIOH_API_RC_SUCCESS;
326 extern SDIOH_API_RC sdioh_interrupt_query(sdioh_info_t *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 sdioh_interrupt_pending(sdioh_info_t *sd)
340 uint sdioh_query_iofnum(sdioh_info_t *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 sdioh_iovar_op(sdioh_info_t *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;
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;
521 (si, sd_ptr->func, sd_ptr->offset, &data)) {
529 bcmerror = -ENOTSUPP;
537 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
539 SDIOH_API_RC sdioh_enable_hw_oob_intr(sdioh_info_t *sd, bool enable)
545 data = 3; /* enable hw oob interrupt */
547 data = 4; /* disable hw oob interrupt */
548 data |= 4; /* Active HIGH */
550 status = sdioh_request_byte(sd, SDIOH_WRITE, 0, 0xf2, &data);
553 #endif /* defined(OOB_INTR_ONLY) && defined(HW_OOB) */
556 sdioh_cfg_read(sdioh_info_t *sd, uint fnc_num, u32 addr, u8 *data)
559 /* No lock needed since sdioh_request_byte does locking */
560 status = sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
565 sdioh_cfg_write(sdioh_info_t *sd, uint fnc_num, u32 addr, u8 *data)
567 /* No lock needed since sdioh_request_byte does locking */
569 status = sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
573 static int sdioh_sdmmc_get_cisaddr(sdioh_info_t *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 ((sdioh_sdmmc_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 sdioh_cis_read(sdioh_info_t *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 (sdioh_sdmmc_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 sdioh_request_byte(sdioh_info_t *sd, uint rw, uint func, uint regaddr,
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 sdioh_request_word(sdioh_info_t *sd, uint cmd_type, uint rw, uint func,
729 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 sdioh_request_packet(sdioh_info_t *sd, uint fix_inc, uint write, uint func,
782 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 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 sdioh_request_buffer(sdioh_info_t *sd, uint pio_dma, uint fix_inc, uint write,
878 uint func, uint addr, uint reg_width, uint buflen_u,
879 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);
904 sdioh_request_packet(sd, fix_inc, write, func, addr, mypkt);
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);
931 sdioh_request_packet(sd, fix_inc, write, func, addr, mypkt);
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"));
943 sdioh_request_packet(sd, fix_inc, write, func, addr, pkt);
949 /* this function performs "abort" for both of host & device */
950 extern int sdioh_abort(sdioh_info_t *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 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 sdioh_sdio_reset(sdioh_info_t *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 sdioh_sdmmc_devintr_off(sdioh_info_t *sd)
978 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
979 sd->intmask &= ~CLIENT_INTR;
982 /* Enable device interrupt */
983 void sdioh_sdmmc_devintr_on(sdioh_info_t *sd)
985 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
986 sd->intmask |= CLIENT_INTR;
989 /* Read client card reg */
991 sdioh_sdmmc_card_regread(sdioh_info_t *sd, int func, u32 regaddr,
992 int regsize, u32 *data)
995 if ((func == 0) || (regsize == 1)) {
998 sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
1001 sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
1003 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 IRQHandler(struct sdio_func *func)
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 IRQHandlerF2(struct sdio_func *func)
1046 sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n"));
1052 #endif /* !defined(OOB_INTR_ONLY) */
1055 /* Write client card reg */
1057 sdioh_sdmmc_card_regwrite(sdioh_info_t *sd, int func, u32 regaddr,
1058 int regsize, u32 data)
1061 if ((func == 0) || (regsize == 1)) {
1065 sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
1066 sd_data(("%s: byte write data=0x%02x\n", __func__, data));
1071 sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, &data,
1074 sd_data(("%s: word write data=0x%08x\n", __func__, data));
1079 #endif /* NOTUSED */
1081 int sdioh_start(sdioh_info_t *si, int stage)
1086 int sdioh_stop(sdioh_info_t *si)