staging: brcm80211: removed last amd64 compiler warnings
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / brcm80211 / brcmfmac / bcmsdh_sdmmc.c
blob4c0a03184b0ef22466a9d0ca613afa7ad9c10d6d
1 /*
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>
23 #include <linux/errno.h>
25 #include <defs.h>
26 #include <brcm_hw_ids.h>
27 #include <brcmu_utils.h>
28 #include <brcmu_wifi.h>
29 #include "sdio_host.h"
30 #include "bcmsdbus.h"
31 #include "dngl_stats.h"
32 #include "dhd.h"
34 #define BLOCK_SIZE_64 64
35 #define BLOCK_SIZE_512 512
36 #define BLOCK_SIZE_4318 64
37 #define BLOCK_SIZE_4328 512
39 /* private bus modes */
40 #define SDIOH_MODE_SD4 2
42 #define CLIENT_INTR 0x100 /* Get rid of this! */
44 static void brcmf_sdioh_irqhandler(struct sdio_func *func);
45 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func);
46 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr);
48 uint sd_f2_blocksize = 512; /* Default blocksize */
50 uint sd_msglevel = 0x01;
51 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_byte_wait);
52 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_word_wait);
53 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_packet_wait);
54 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait);
56 #define DMA_ALIGN_MASK 0x03
58 static int
59 brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
60 int regsize, u32 *data);
62 static int brcmf_sdioh_enablefuncs(struct sdioh_info *sd)
64 int err_ret;
65 u32 fbraddr;
66 u8 func;
68 sd_trace(("%s\n", __func__));
70 /* Get the Card's common CIS address */
71 sd->com_cis_ptr = brcmf_sdioh_get_cisaddr(sd, SDIO_CCCR_CIS);
72 sd->func_cis_ptr[0] = sd->com_cis_ptr;
73 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
74 sd->com_cis_ptr));
76 /* Get the Card's function CIS (for each function) */
77 for (fbraddr = SDIO_FBR_BASE(1), func = 1;
78 func <= sd->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) {
79 sd->func_cis_ptr[func] =
80 brcmf_sdioh_get_cisaddr(sd, SDIO_FBR_CIS + fbraddr);
81 sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__, func,
82 sd->func_cis_ptr[func]));
85 sd->func_cis_ptr[0] = sd->com_cis_ptr;
86 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
87 sd->com_cis_ptr));
89 /* Enable Function 1 */
90 sdio_claim_host(gInstance->func[1]);
91 err_ret = sdio_enable_func(gInstance->func[1]);
92 sdio_release_host(gInstance->func[1]);
93 if (err_ret) {
94 sd_err(("brcmf_sdioh_enablefuncs: Failed to enable F1 "
95 "Err: 0x%08x", err_ret));
98 return false;
102 * Public entry points & extern's
104 struct sdioh_info *brcmf_sdioh_attach(void *bar0, uint irq)
106 struct sdioh_info *sd;
107 int err_ret;
109 sd_trace(("%s\n", __func__));
111 if (gInstance == NULL) {
112 sd_err(("%s: SDIO Device not present\n", __func__));
113 return NULL;
116 sd = kzalloc(sizeof(struct sdioh_info), GFP_ATOMIC);
117 if (sd == NULL) {
118 sd_err(("sdioh_attach: out of memory\n"));
119 return NULL;
121 if (brcmf_sdioh_osinit(sd) != 0) {
122 sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__));
123 kfree(sd);
124 return NULL;
127 sd->num_funcs = 2;
128 sd->use_client_ints = true;
129 sd->client_block_size[0] = 64;
131 gInstance->sd = sd;
133 /* Claim host controller */
134 sdio_claim_host(gInstance->func[1]);
136 sd->client_block_size[1] = 64;
137 err_ret = sdio_set_block_size(gInstance->func[1], 64);
138 if (err_ret)
139 sd_err(("brcmf_sdioh_attach: Failed to set F1 blocksize\n"));
141 /* Release host controller F1 */
142 sdio_release_host(gInstance->func[1]);
144 if (gInstance->func[2]) {
145 /* Claim host controller F2 */
146 sdio_claim_host(gInstance->func[2]);
148 sd->client_block_size[2] = sd_f2_blocksize;
149 err_ret =
150 sdio_set_block_size(gInstance->func[2], sd_f2_blocksize);
151 if (err_ret)
152 sd_err(("brcmf_sdioh_attach: Failed to set F2 blocksize"
153 " to %d\n", sd_f2_blocksize));
155 /* Release host controller F2 */
156 sdio_release_host(gInstance->func[2]);
159 brcmf_sdioh_enablefuncs(sd);
161 sd_trace(("%s: Done\n", __func__));
162 return sd;
165 extern int brcmf_sdioh_detach(struct sdioh_info *sd)
167 sd_trace(("%s\n", __func__));
169 if (sd) {
171 /* Disable Function 2 */
172 sdio_claim_host(gInstance->func[2]);
173 sdio_disable_func(gInstance->func[2]);
174 sdio_release_host(gInstance->func[2]);
176 /* Disable Function 1 */
177 sdio_claim_host(gInstance->func[1]);
178 sdio_disable_func(gInstance->func[1]);
179 sdio_release_host(gInstance->func[1]);
181 /* deregister irq */
182 brcmf_sdioh_osfree(sd);
184 kfree(sd);
186 return 0;
189 /* Configure callback to client when we receive client interrupt */
190 extern int
191 brcmf_sdioh_interrupt_register(struct sdioh_info *sd, void (*fn)(void *),
192 void *argh)
194 sd_trace(("%s: Entering\n", __func__));
195 if (fn == NULL) {
196 sd_err(("%s: interrupt handler is NULL, not registering\n",
197 __func__));
198 return -EINVAL;
201 sd->intr_handler = fn;
202 sd->intr_handler_arg = argh;
203 sd->intr_handler_valid = true;
205 /* register and unmask irq */
206 if (gInstance->func[2]) {
207 sdio_claim_host(gInstance->func[2]);
208 sdio_claim_irq(gInstance->func[2], brcmf_sdioh_irqhandler_f2);
209 sdio_release_host(gInstance->func[2]);
212 if (gInstance->func[1]) {
213 sdio_claim_host(gInstance->func[1]);
214 sdio_claim_irq(gInstance->func[1], brcmf_sdioh_irqhandler);
215 sdio_release_host(gInstance->func[1]);
218 return 0;
221 extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *sd)
223 sd_trace(("%s: Entering\n", __func__));
225 if (gInstance->func[1]) {
226 /* register and unmask irq */
227 sdio_claim_host(gInstance->func[1]);
228 sdio_release_irq(gInstance->func[1]);
229 sdio_release_host(gInstance->func[1]);
232 if (gInstance->func[2]) {
233 /* Claim host controller F2 */
234 sdio_claim_host(gInstance->func[2]);
235 sdio_release_irq(gInstance->func[2]);
236 /* Release host controller F2 */
237 sdio_release_host(gInstance->func[2]);
240 sd->intr_handler_valid = false;
241 sd->intr_handler = NULL;
242 sd->intr_handler_arg = NULL;
244 return 0;
247 /* IOVar table */
248 enum {
249 IOV_MSGLEVEL = 1,
250 IOV_BLOCKSIZE,
251 IOV_USEINTS,
252 IOV_NUMINTS,
253 IOV_DEVREG,
254 IOV_HCIREGS,
255 IOV_RXCHAIN
258 const struct brcmu_iovar sdioh_iovars[] = {
259 {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0},
260 {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0},/* ((fn << 16) |
261 size) */
262 {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0},
263 {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0},
264 {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
266 {"sd_rxchain", IOV_RXCHAIN, 0, IOVT_BOOL, 0}
268 {NULL, 0, 0, 0, 0}
272 brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name,
273 void *params, int plen, void *arg, int len, bool set)
275 const struct brcmu_iovar *vi = NULL;
276 int bcmerror = 0;
277 int val_size;
278 s32 int_val = 0;
279 bool bool_val;
280 u32 actionid;
282 ASSERT(name);
283 ASSERT(len >= 0);
285 /* Get must have return space; Set does not take qualifiers */
286 ASSERT(set || (arg && len));
287 ASSERT(!set || (!params && !plen));
289 sd_trace(("%s: Enter (%s %s)\n", __func__, (set ? "set" : "get"),
290 name));
292 vi = brcmu_iovar_lookup(sdioh_iovars, name);
293 if (vi == NULL) {
294 bcmerror = -ENOTSUPP;
295 goto exit;
298 bcmerror = brcmu_iovar_lencheck(vi, arg, len, set);
299 if (bcmerror != 0)
300 goto exit;
302 /* Set up params so get and set can share the convenience variables */
303 if (params == NULL) {
304 params = arg;
305 plen = len;
308 if (vi->type == IOVT_VOID)
309 val_size = 0;
310 else if (vi->type == IOVT_BUFFER)
311 val_size = len;
312 else
313 val_size = sizeof(int);
315 if (plen >= (int)sizeof(int_val))
316 memcpy(&int_val, params, sizeof(int_val));
318 bool_val = (int_val != 0) ? true : false;
320 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
321 switch (actionid) {
322 case IOV_GVAL(IOV_MSGLEVEL):
323 int_val = (s32) sd_msglevel;
324 memcpy(arg, &int_val, val_size);
325 break;
327 case IOV_SVAL(IOV_MSGLEVEL):
328 sd_msglevel = int_val;
329 break;
331 case IOV_GVAL(IOV_BLOCKSIZE):
332 if ((u32) int_val > si->num_funcs) {
333 bcmerror = -EINVAL;
334 break;
336 int_val = (s32) si->client_block_size[int_val];
337 memcpy(arg, &int_val, val_size);
338 break;
340 case IOV_SVAL(IOV_BLOCKSIZE):
342 uint func = ((u32) int_val >> 16);
343 uint blksize = (u16) int_val;
344 uint maxsize;
346 if (func > si->num_funcs) {
347 bcmerror = -EINVAL;
348 break;
351 switch (func) {
352 case 0:
353 maxsize = 32;
354 break;
355 case 1:
356 maxsize = BLOCK_SIZE_4318;
357 break;
358 case 2:
359 maxsize = BLOCK_SIZE_4328;
360 break;
361 default:
362 maxsize = 0;
364 if (blksize > maxsize) {
365 bcmerror = -EINVAL;
366 break;
368 if (!blksize)
369 blksize = maxsize;
371 /* Now set it */
372 si->client_block_size[func] = blksize;
374 break;
377 case IOV_GVAL(IOV_RXCHAIN):
378 int_val = false;
379 memcpy(arg, &int_val, val_size);
380 break;
382 case IOV_GVAL(IOV_USEINTS):
383 int_val = (s32) si->use_client_ints;
384 memcpy(arg, &int_val, val_size);
385 break;
387 case IOV_SVAL(IOV_USEINTS):
388 si->use_client_ints = (bool) int_val;
389 if (si->use_client_ints)
390 si->intmask |= CLIENT_INTR;
391 else
392 si->intmask &= ~CLIENT_INTR;
394 break;
396 case IOV_GVAL(IOV_NUMINTS):
397 int_val = (s32) si->intrcount;
398 memcpy(arg, &int_val, val_size);
399 break;
401 case IOV_GVAL(IOV_DEVREG):
403 struct brcmf_sdreg *sd_ptr =
404 (struct brcmf_sdreg *) params;
405 u8 data = 0;
407 if (brcmf_sdioh_cfg_read
408 (si, sd_ptr->func, sd_ptr->offset, &data)) {
409 bcmerror = -EIO;
410 break;
413 int_val = (int)data;
414 memcpy(arg, &int_val, sizeof(int_val));
415 break;
418 case IOV_SVAL(IOV_DEVREG):
420 struct brcmf_sdreg *sd_ptr =
421 (struct brcmf_sdreg *) params;
422 u8 data = (u8) sd_ptr->value;
424 if (brcmf_sdioh_cfg_write
425 (si, sd_ptr->func, sd_ptr->offset, &data)) {
426 bcmerror = -EIO;
427 break;
429 break;
432 default:
433 bcmerror = -ENOTSUPP;
434 break;
436 exit:
438 return bcmerror;
441 extern int
442 brcmf_sdioh_cfg_read(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
444 int status;
445 /* No lock needed since brcmf_sdioh_request_byte does locking */
446 status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
447 return status;
450 extern int
451 brcmf_sdioh_cfg_write(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
453 /* No lock needed since brcmf_sdioh_request_byte does locking */
454 int status;
455 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
456 return status;
459 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr)
461 /* read 24 bits and return valid 17 bit addr */
462 int i;
463 u32 scratch, regdata;
464 u8 *ptr = (u8 *)&scratch;
465 for (i = 0; i < 3; i++) {
466 if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, &regdata)) !=
467 SUCCESS)
468 sd_err(("%s: Can't read!\n", __func__));
470 *ptr++ = (u8) regdata;
471 regaddr++;
474 /* Only the lower 17-bits are valid */
475 scratch = le32_to_cpu(scratch);
476 scratch &= 0x0001FFFF;
477 return scratch;
480 extern int
481 brcmf_sdioh_cis_read(struct sdioh_info *sd, uint func, u8 *cisd, u32 length)
483 u32 count;
484 int offset;
485 u32 foo;
486 u8 *cis = cisd;
488 sd_trace(("%s: Func = %d\n", __func__, func));
490 if (!sd->func_cis_ptr[func]) {
491 memset(cis, 0, length);
492 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
493 return -ENOTSUPP;
496 sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func,
497 sd->func_cis_ptr[func]));
499 for (count = 0; count < length; count++) {
500 offset = sd->func_cis_ptr[func] + count;
501 if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) {
502 sd_err(("%s: regread failed: Can't read CIS\n",
503 __func__));
504 return -EIO;
507 *cis = (u8) (foo & 0xff);
508 cis++;
511 return 0;
514 extern int
515 brcmf_sdioh_request_byte(struct sdioh_info *sd, uint rw, uint func,
516 uint regaddr, u8 *byte)
518 int err_ret;
520 sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func,
521 regaddr));
523 BRCMF_PM_RESUME_WAIT(sdioh_request_byte_wait);
524 BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
525 if (rw) { /* CMD52 Write */
526 if (func == 0) {
527 /* Can only directly write to some F0 registers.
528 * Handle F2 enable
529 * as a special case.
531 if (regaddr == SDIO_CCCR_IOEx) {
532 if (gInstance->func[2]) {
533 sdio_claim_host(gInstance->func[2]);
534 if (*byte & SDIO_FUNC_ENABLE_2) {
535 /* Enable Function 2 */
536 err_ret =
537 sdio_enable_func
538 (gInstance->func[2]);
539 if (err_ret)
540 sd_err(("request_byte: "
541 "enable F2 "
542 "failed:%d",
543 err_ret));
544 } else {
545 /* Disable Function 2 */
546 err_ret =
547 sdio_disable_func
548 (gInstance->func[2]);
549 if (err_ret)
550 sd_err(("request_byte: "
551 "Disab F2 "
552 "failed:%d",
553 err_ret));
555 sdio_release_host(gInstance->func[2]);
558 /* to allow abort command through F1 */
559 else if (regaddr == SDIO_CCCR_ABORT) {
560 sdio_claim_host(gInstance->func[func]);
562 * this sdio_f0_writeb() can be replaced
563 * with another api
564 * depending upon MMC driver change.
565 * As of this time, this is temporaray one
567 sdio_writeb(gInstance->func[func], *byte,
568 regaddr, &err_ret);
569 sdio_release_host(gInstance->func[func]);
571 else if (regaddr < 0xF0) {
572 sd_err(("brcmf: F0 Wr:0x%02x: write "
573 "disallowed\n", regaddr));
574 } else {
575 /* Claim host controller, perform F0 write,
576 and release */
577 sdio_claim_host(gInstance->func[func]);
578 sdio_f0_writeb(gInstance->func[func], *byte,
579 regaddr, &err_ret);
580 sdio_release_host(gInstance->func[func]);
582 } else {
583 /* Claim host controller, perform Fn write,
584 and release */
585 sdio_claim_host(gInstance->func[func]);
586 sdio_writeb(gInstance->func[func], *byte, regaddr,
587 &err_ret);
588 sdio_release_host(gInstance->func[func]);
590 } else { /* CMD52 Read */
591 /* Claim host controller, perform Fn read, and release */
592 sdio_claim_host(gInstance->func[func]);
594 if (func == 0) {
595 *byte =
596 sdio_f0_readb(gInstance->func[func], regaddr,
597 &err_ret);
598 } else {
599 *byte =
600 sdio_readb(gInstance->func[func], regaddr,
601 &err_ret);
604 sdio_release_host(gInstance->func[func]);
607 if (err_ret)
608 sd_err(("brcmf: Failed to %s byte F%d:@0x%05x=%02x, "
609 "Err: %d\n", rw ? "Write" : "Read", func, regaddr,
610 *byte, err_ret));
612 return err_ret;
615 extern int
616 brcmf_sdioh_request_word(struct sdioh_info *sd, uint cmd_type, uint rw,
617 uint func, uint addr, u32 *word, uint nbytes)
619 int err_ret = -EIO;
621 if (func == 0) {
622 sd_err(("%s: Only CMD52 allowed to F0.\n", __func__));
623 return -EINVAL;
626 sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
627 __func__, cmd_type, rw, func, addr, nbytes));
629 BRCMF_PM_RESUME_WAIT(sdioh_request_word_wait);
630 BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
631 /* Claim host controller */
632 sdio_claim_host(gInstance->func[func]);
634 if (rw) { /* CMD52 Write */
635 if (nbytes == 4) {
636 sdio_writel(gInstance->func[func], *word, addr,
637 &err_ret);
638 } else if (nbytes == 2) {
639 sdio_writew(gInstance->func[func], (*word & 0xFFFF),
640 addr, &err_ret);
641 } else {
642 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
644 } else { /* CMD52 Read */
645 if (nbytes == 4) {
646 *word =
647 sdio_readl(gInstance->func[func], addr, &err_ret);
648 } else if (nbytes == 2) {
649 *word =
650 sdio_readw(gInstance->func[func], addr,
651 &err_ret) & 0xFFFF;
652 } else {
653 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
657 /* Release host controller */
658 sdio_release_host(gInstance->func[func]);
660 if (err_ret) {
661 sd_err(("brcmf: Failed to %s word, Err: 0x%08x",
662 rw ? "Write" : "Read", err_ret));
665 return err_ret;
668 static int
669 brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
670 uint func, uint addr, struct sk_buff *pkt)
672 bool fifo = (fix_inc == SDIOH_DATA_FIX);
673 u32 SGCount = 0;
674 int err_ret = 0;
676 struct sk_buff *pnext;
678 sd_trace(("%s: Enter\n", __func__));
680 ASSERT(pkt);
681 BRCMF_PM_RESUME_WAIT(sdioh_request_packet_wait);
682 BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
684 /* Claim host controller */
685 sdio_claim_host(gInstance->func[func]);
686 for (pnext = pkt; pnext; pnext = pnext->next) {
687 uint pkt_len = pnext->len;
688 pkt_len += 3;
689 pkt_len &= 0xFFFFFFFC;
691 /* Make sure the packet is aligned properly.
692 * If it isn't, then this
693 * is the fault of brcmf_sdioh_request_buffer() which
694 * is supposed to give
695 * us something we can work with.
697 ASSERT(((ulong) (pkt->data) & DMA_ALIGN_MASK) == 0);
699 if ((write) && (!fifo)) {
700 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
701 ((u8 *) (pnext->data)),
702 pkt_len);
703 } else if (write) {
704 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
705 ((u8 *) (pnext->data)),
706 pkt_len);
707 } else if (fifo) {
708 err_ret = sdio_readsb(gInstance->func[func],
709 ((u8 *) (pnext->data)),
710 addr, pkt_len);
711 } else {
712 err_ret = sdio_memcpy_fromio(gInstance->func[func],
713 ((u8 *) (pnext->data)),
714 addr, pkt_len);
717 if (err_ret) {
718 sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d,"
719 "ERR=0x%08x\n", __func__,
720 (write) ? "TX" : "RX",
721 pnext, SGCount, addr, pkt_len, err_ret));
722 } else {
723 sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
724 __func__,
725 (write) ? "TX" : "RX",
726 pnext, SGCount, addr, pkt_len));
729 if (!fifo)
730 addr += pkt_len;
731 SGCount++;
735 /* Release host controller */
736 sdio_release_host(gInstance->func[func]);
738 sd_trace(("%s: Exit\n", __func__));
739 return err_ret;
743 * This function takes a buffer or packet, and fixes everything up
744 * so that in the end, a DMA-able packet is created.
746 * A buffer does not have an associated packet pointer,
747 * and may or may not be aligned.
748 * A packet may consist of a single packet, or a packet chain.
749 * If it is a packet chain, then all the packets in the chain
750 * must be properly aligned.
752 * If the packet data is not aligned, then there may only be
753 * one packet, and in this case, it is copied to a new
754 * aligned packet.
757 extern int
758 brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
759 uint write, uint func, uint addr, uint reg_width,
760 uint buflen_u, u8 *buffer, struct sk_buff *pkt)
762 int Status;
763 struct sk_buff *mypkt = NULL;
765 sd_trace(("%s: Enter\n", __func__));
767 BRCMF_PM_RESUME_WAIT(sdioh_request_buffer_wait);
768 BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
769 /* Case 1: we don't have a packet. */
770 if (pkt == NULL) {
771 sd_data(("%s: Creating new %s Packet, len=%d\n",
772 __func__, write ? "TX" : "RX", buflen_u));
773 mypkt = brcmu_pkt_buf_get_skb(buflen_u);
774 if (!mypkt) {
775 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
776 __func__, buflen_u));
777 return -EIO;
780 /* For a write, copy the buffer data into the packet. */
781 if (write)
782 memcpy(mypkt->data, buffer, buflen_u);
784 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
785 addr, mypkt);
787 /* For a read, copy the packet data back to the buffer. */
788 if (!write)
789 memcpy(buffer, mypkt->data, buflen_u);
791 brcmu_pkt_buf_free_skb(mypkt);
792 } else if (((ulong) (pkt->data) & DMA_ALIGN_MASK) != 0) {
793 /* Case 2: We have a packet, but it is unaligned. */
795 /* In this case, we cannot have a chain. */
796 ASSERT(pkt->next == NULL);
798 sd_data(("%s: Creating aligned %s Packet, len=%d\n",
799 __func__, write ? "TX" : "RX", pkt->len));
800 mypkt = brcmu_pkt_buf_get_skb(pkt->len);
801 if (!mypkt) {
802 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
803 __func__, pkt->len));
804 return -EIO;
807 /* For a write, copy the buffer data into the packet. */
808 if (write)
809 memcpy(mypkt->data, pkt->data, pkt->len);
811 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
812 addr, mypkt);
814 /* For a read, copy the packet data back to the buffer. */
815 if (!write)
816 memcpy(pkt->data, mypkt->data, mypkt->len);
818 brcmu_pkt_buf_free_skb(mypkt);
819 } else { /* case 3: We have a packet and
820 it is aligned. */
821 sd_data(("%s: Aligned %s Packet, direct DMA\n",
822 __func__, write ? "Tx" : "Rx"));
823 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
824 addr, pkt);
827 return Status;
830 /* this function performs "abort" for both of host & device */
831 extern int brcmf_sdioh_abort(struct sdioh_info *sd, uint func)
833 char t_func = (char)func;
834 sd_trace(("%s: Enter\n", __func__));
836 /* issue abort cmd52 command through F0 */
837 brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT,
838 &t_func);
840 sd_trace(("%s: Exit\n", __func__));
841 return 0;
844 /* Disable device interrupt */
845 void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd)
847 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
848 sd->intmask &= ~CLIENT_INTR;
851 /* Enable device interrupt */
852 void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd)
854 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
855 sd->intmask |= CLIENT_INTR;
858 /* Read client card reg */
860 brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
861 int regsize, u32 *data)
864 if ((func == 0) || (regsize == 1)) {
865 u8 temp = 0;
867 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
868 *data = temp;
869 *data &= 0xff;
870 sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
871 } else {
872 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data,
873 regsize);
874 if (regsize == 2)
875 *data &= 0xffff;
877 sd_data(("%s: word read data=0x%08x\n", __func__, *data));
880 return SUCCESS;
883 static void brcmf_sdioh_irqhandler(struct sdio_func *func)
885 struct sdioh_info *sd;
887 sd_trace(("brcmf: ***IRQHandler\n"));
888 sd = gInstance->sd;
890 ASSERT(sd != NULL);
891 sdio_release_host(gInstance->func[0]);
893 if (sd->use_client_ints) {
894 sd->intrcount++;
895 ASSERT(sd->intr_handler);
896 ASSERT(sd->intr_handler_arg);
897 (sd->intr_handler) (sd->intr_handler_arg);
898 } else {
899 sd_err(("brcmf: ***IRQHandler\n"));
901 sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
902 __func__, sd->client_intr_enabled, sd->intr_handler));
905 sdio_claim_host(gInstance->func[0]);
908 /* interrupt handler for F2 (dummy handler) */
909 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func)
911 struct sdioh_info *sd;
913 sd_trace(("brcmf: ***IRQHandlerF2\n"));
915 sd = gInstance->sd;
917 ASSERT(sd != NULL);