1 /*
2 * BCMSDH interface glue
3 * implement bcmsdh API for SDIOH driver
4 *
5 * Copyright (C) 1999-2017, Broadcom Corporation
6 *
7 * Unless you and Broadcom execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the "GPL"),
10 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 * following added to such license:
12 *
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions of
17 * the license of that module. An independent module is a module which is not
18 * derived from this software. The special exception does not apply to any
19 * modifications of the software.
20 *
21 * Notwithstanding the above, under no circumstances may you combine this
22 * software in any way with any other Broadcom software provided under a license
23 * other than the GPL, without Broadcom's express prior written consent.
24 *
25 *
26 * <<Broadcom-WL-IPTag/Open:>>
27 *
28 * $Id: bcmsdh.c 671319 2016-11-21 14:27:29Z $
29 */
30
31 /**
32 * @file bcmsdh.c
33 */
34
35 /* ****************** BCMSDH Interface Functions *************************** */
36
37 #include <typedefs.h>
38 #include <bcmdevs.h>
39 #include <bcmendian.h>
40 #include <bcmutils.h>
41 #include <hndsoc.h>
42 #include <siutils.h>
43 #include <osl.h>
44
45 #include <bcmsdh.h> /* BRCM API for SDIO clients (such as wl, dhd) */
46 #include <bcmsdbus.h> /* common SDIO/controller interface */
47 #include <sbsdio.h> /* SDIO device core hardware definitions. */
48 #include <sdio.h> /* SDIO Device and Protocol Specs */
49
50 #if defined(BT_OVER_SDIO)
51 #include <dhd_bt_interface.h>
52 #endif /* defined (BT_OVER_SDIO) */
53
54 #define SDIOH_API_ACCESS_RETRY_LIMIT 2
55 const uint bcmsdh_msglevel = BCMSDH_ERROR_VAL;
56
57 /* local copy of bcm sd handler */
58 bcmsdh_info_t *l_bcmsdh = NULL;
59
60 #if defined(BT_OVER_SDIO)
61 struct sdio_func *func_f3 = NULL;
62 static f3intr_handler processf3intr = NULL;
63 static dhd_hang_notification process_dhd_hang_notification = NULL;
64 static dhd_hang_state_t g_dhd_hang_state = NO_HANG_STATE;
65 #endif /* defined (BT_OVER_SDIO) */
66
67
68 #if defined(OOB_INTR_ONLY) && defined(HW_OOB) || defined(FORCE_WOWLAN)
69 extern int
70 sdioh_enable_hw_oob_intr(void *sdioh, bool enable);
71
72 void
bcmsdh_enable_hw_oob_intr(bcmsdh_info_t * sdh,bool enable)73 bcmsdh_enable_hw_oob_intr(bcmsdh_info_t *sdh, bool enable)
74 {
75 sdioh_enable_hw_oob_intr(sdh->sdioh, enable);
76 }
77 #endif
78
79 #if defined(BT_OVER_SDIO)
bcmsdh_btsdio_process_hang_state(dhd_hang_state_t new_state)80 void bcmsdh_btsdio_process_hang_state(dhd_hang_state_t new_state)
81 {
82 bool state_change = false;
83
84 BCMSDH_ERROR(("%s: DHD hang state changed - [%d] -> [%d]\n",
85 __FUNCTION__, g_dhd_hang_state, new_state));
86
87 if (g_dhd_hang_state == new_state)
88 return;
89
90 switch (g_dhd_hang_state) {
91 case NO_HANG_STATE:
92 if (HANG_START_STATE == new_state)
93 state_change = true;
94 break;
95
96 case HANG_START_STATE:
97 if (HANG_RECOVERY_STATE == new_state ||
98 NO_HANG_STATE == new_state)
99 state_change = true;
100 break;
101
102 case HANG_RECOVERY_STATE:
103 if (NO_HANG_STATE == new_state)
104 state_change = true;
105 break;
106
107 default:
108 BCMSDH_ERROR(("%s: Unhandled Hang state\n", __FUNCTION__));
109 break;
110 }
111
112 if (!state_change) {
113 BCMSDH_ERROR(("%s: Hang state cannot be changed\n", __FUNCTION__));
114 return;
115 }
116
117 g_dhd_hang_state = new_state;
118 }
119
bcmsdh_btsdio_process_f3_intr(void)120 void bcmsdh_btsdio_process_f3_intr(void)
121 {
122 if (processf3intr && (g_dhd_hang_state == NO_HANG_STATE))
123 processf3intr(func_f3);
124 }
125
bcmsdh_btsdio_process_dhd_hang_notification(bool wifi_recovery_completed)126 void bcmsdh_btsdio_process_dhd_hang_notification(bool wifi_recovery_completed)
127 {
128 bcmsdh_btsdio_process_hang_state(HANG_START_STATE);
129
130 if (process_dhd_hang_notification)
131 process_dhd_hang_notification(func_f3, wifi_recovery_completed);
132
133 /* WiFi was off, so HANG_RECOVERY_STATE is not needed */
134 if (wifi_recovery_completed)
135 bcmsdh_btsdio_process_hang_state(NO_HANG_STATE);
136 else {
137 bcmsdh_btsdio_process_hang_state(HANG_RECOVERY_STATE);
138 }
139 }
140
bcmsdh_btsdio_interface_init(struct sdio_func * func,f3intr_handler f3intr_fun,dhd_hang_notification hang_notification)141 void bcmsdh_btsdio_interface_init(struct sdio_func *func,
142 f3intr_handler f3intr_fun, dhd_hang_notification hang_notification)
143 {
144 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)l_bcmsdh;
145 BCMSDH_INFO(("%s: func %p \n", __FUNCTION__, func));
146 func_f3 = func;
147 processf3intr = f3intr_fun;
148 sdioh_sdmmc_card_enable_func_f3(bcmsdh->sdioh, func);
149 process_dhd_hang_notification = hang_notification;
150 } EXPORT_SYMBOL(bcmsdh_btsdio_interface_init);
151 #endif /* defined (BT_OVER_SDIO) */
152
153 /* Attach BCMSDH layer to SDIO Host Controller Driver
154 *
155 * @param osh OSL Handle.
156 * @param cfghdl Configuration Handle.
157 * @param regsva Virtual address of controller registers.
158 * @param irq Interrupt number of SDIO controller.
159 *
160 * @return bcmsdh_info_t Handle to BCMSDH context.
161 */
162 bcmsdh_info_t *
bcmsdh_attach(osl_t * osh,void * sdioh,ulong * regsva)163 bcmsdh_attach(osl_t *osh, void *sdioh, ulong *regsva)
164 {
165 bcmsdh_info_t *bcmsdh;
166
167 if ((bcmsdh = (bcmsdh_info_t *)MALLOC(osh, sizeof(bcmsdh_info_t))) == NULL) {
168 BCMSDH_ERROR(("bcmsdh_attach: out of memory, malloced %d bytes\n", MALLOCED(osh)));
169 return NULL;
170 }
171 bzero((char *)bcmsdh, sizeof(bcmsdh_info_t));
172 bcmsdh->sdioh = sdioh;
173 bcmsdh->osh = osh;
174 bcmsdh->init_success = TRUE;
175 *regsva = SI_ENUM_BASE;
176
177 bcmsdh_force_sbwad_calc(bcmsdh, FALSE);
178
179 /* Report the BAR, to fix if needed */
180 bcmsdh->sbwad = SI_ENUM_BASE;
181
182 /* save the handler locally */
183 l_bcmsdh = bcmsdh;
184
185 return bcmsdh;
186 }
187
188 int
bcmsdh_detach(osl_t * osh,void * sdh)189 bcmsdh_detach(osl_t *osh, void *sdh)
190 {
191 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
192
193 if (bcmsdh != NULL) {
194 MFREE(osh, bcmsdh, sizeof(bcmsdh_info_t));
195 }
196
197 l_bcmsdh = NULL;
198
199 return 0;
200 }
201
202 int
bcmsdh_iovar_op(void * sdh,const char * name,void * params,int plen,void * arg,int len,bool set)203 bcmsdh_iovar_op(void *sdh, const char *name,
204 void *params, int plen, void *arg, int len, bool set)
205 {
206 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
207 return sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, len, set);
208 }
209
210 bool
bcmsdh_intr_query(void * sdh)211 bcmsdh_intr_query(void *sdh)
212 {
213 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
214 SDIOH_API_RC status;
215 bool on;
216
217 ASSERT(bcmsdh);
218 status = sdioh_interrupt_query(bcmsdh->sdioh, &on);
219 if (SDIOH_API_SUCCESS(status))
220 return FALSE;
221 else
222 return on;
223 }
224
225 int
bcmsdh_intr_enable(void * sdh)226 bcmsdh_intr_enable(void *sdh)
227 {
228 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
229 SDIOH_API_RC status;
230 ASSERT(bcmsdh);
231
232 status = sdioh_interrupt_set(bcmsdh->sdioh, TRUE);
233 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
234 }
235
236 int
bcmsdh_intr_disable(void * sdh)237 bcmsdh_intr_disable(void *sdh)
238 {
239 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
240 SDIOH_API_RC status;
241 ASSERT(bcmsdh);
242
243 status = sdioh_interrupt_set(bcmsdh->sdioh, FALSE);
244 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
245 }
246
247 int
bcmsdh_intr_reg(void * sdh,bcmsdh_cb_fn_t fn,void * argh)248 bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh)
249 {
250 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
251 SDIOH_API_RC status;
252
253 if (!bcmsdh)
254 bcmsdh = l_bcmsdh;
255
256 ASSERT(bcmsdh);
257
258 status = sdioh_interrupt_register(bcmsdh->sdioh, fn, argh);
259 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
260 }
261
262 int
bcmsdh_intr_dereg(void * sdh)263 bcmsdh_intr_dereg(void *sdh)
264 {
265 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
266 SDIOH_API_RC status;
267
268 if (!bcmsdh)
269 bcmsdh = l_bcmsdh;
270
271 ASSERT(bcmsdh);
272
273 status = sdioh_interrupt_deregister(bcmsdh->sdioh);
274 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
275 }
276
277 #if defined(DHD_DEBUG)
278 bool
bcmsdh_intr_pending(void * sdh)279 bcmsdh_intr_pending(void *sdh)
280 {
281 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
282
283 ASSERT(sdh);
284 return sdioh_interrupt_pending(bcmsdh->sdioh);
285 }
286 #endif
287
288
289 int
bcmsdh_devremove_reg(void * sdh,bcmsdh_cb_fn_t fn,void * argh)290 bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh)
291 {
292 ASSERT(sdh);
293
294 /* don't support yet */
295 return BCME_UNSUPPORTED;
296 }
297
298 /**
299 * Read from SDIO Configuration Space
300 * @param sdh SDIO Host context.
301 * @param func_num Function number to read from.
302 * @param addr Address to read from.
303 * @param err Error return.
304 * @return value read from SDIO configuration space.
305 */
306 uint8
bcmsdh_cfg_read(void * sdh,uint fnc_num,uint32 addr,int * err)307 bcmsdh_cfg_read(void *sdh, uint fnc_num, uint32 addr, int *err)
308 {
309 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
310 SDIOH_API_RC status;
311 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
312 int32 retry = 0;
313 #endif
314 uint8 data = 0;
315
316 if (!bcmsdh)
317 bcmsdh = l_bcmsdh;
318
319 ASSERT(bcmsdh->init_success);
320
321 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
322 do {
323 if (retry) /* wait for 1 ms till bus get settled down */
324 OSL_DELAY(1000);
325 #endif
326 status = sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr, (uint8 *)&data);
327 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
328 } while (!SDIOH_API_SUCCESS(status) && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
329 #endif
330 if (err)
331 *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
332
333 BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", __FUNCTION__,
334 fnc_num, addr, data));
335
336 return data;
337 } EXPORT_SYMBOL(bcmsdh_cfg_read);
338
339 void
bcmsdh_cfg_write(void * sdh,uint fnc_num,uint32 addr,uint8 data,int * err)340 bcmsdh_cfg_write(void *sdh, uint fnc_num, uint32 addr, uint8 data, int *err)
341 {
342 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
343 SDIOH_API_RC status;
344 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
345 int32 retry = 0;
346 #endif
347
348 if (!bcmsdh)
349 bcmsdh = l_bcmsdh;
350
351 ASSERT(bcmsdh->init_success);
352
353 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
354 do {
355 if (retry) /* wait for 1 ms till bus get settled down */
356 OSL_DELAY(1000);
357 #endif
358 status = sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr, (uint8 *)&data);
359 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
360 } while (!SDIOH_API_SUCCESS(status) && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
361 #endif
362 if (err)
363 *err = SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR;
364
365 BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", __FUNCTION__,
366 fnc_num, addr, data));
367 } EXPORT_SYMBOL(bcmsdh_cfg_write);
368
369 uint32
bcmsdh_cfg_read_word(void * sdh,uint fnc_num,uint32 addr,int * err)370 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, int *err)
371 {
372 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
373 SDIOH_API_RC status;
374 uint32 data = 0;
375
376 if (!bcmsdh)
377 bcmsdh = l_bcmsdh;
378
379 ASSERT(bcmsdh->init_success);
380
381 status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_READ, fnc_num,
382 addr, &data, 4);
383
384 if (err)
385 *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
386
387 BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", __FUNCTION__,
388 fnc_num, addr, data));
389
390 return data;
391 }
392
393 void
bcmsdh_cfg_write_word(void * sdh,uint fnc_num,uint32 addr,uint32 data,int * err)394 bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, uint32 data, int *err)
395 {
396 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
397 SDIOH_API_RC status;
398
399 if (!bcmsdh)
400 bcmsdh = l_bcmsdh;
401
402 ASSERT(bcmsdh->init_success);
403
404 status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_WRITE, fnc_num,
405 addr, &data, 4);
406
407 if (err)
408 *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
409
410 BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", __FUNCTION__, fnc_num,
411 addr, data));
412 }
413
414
415 int
bcmsdh_cis_read(void * sdh,uint func,uint8 * cis,uint length)416 bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length)
417 {
418 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
419 SDIOH_API_RC status;
420
421 uint8 *tmp_buf, *tmp_ptr;
422 uint8 *ptr;
423 bool ascii = func & ~0xf;
424 func &= 0x7;
425
426 if (!bcmsdh)
427 bcmsdh = l_bcmsdh;
428
429 ASSERT(bcmsdh->init_success);
430 ASSERT(cis);
431 ASSERT(length <= SBSDIO_CIS_SIZE_LIMIT);
432
433 status = sdioh_cis_read(bcmsdh->sdioh, func, cis, length);
434
435 if (ascii) {
436 /* Move binary bits to tmp and format them into the provided buffer. */
437 if ((tmp_buf = (uint8 *)MALLOC(bcmsdh->osh, length)) == NULL) {
438 BCMSDH_ERROR(("%s: out of memory\n", __FUNCTION__));
439 return BCME_NOMEM;
440 }
441 bcopy(cis, tmp_buf, length);
442 for (tmp_ptr = tmp_buf, ptr = cis; ptr < (cis + length - 4); tmp_ptr++) {
443 ptr += snprintf((char*)ptr, (cis + length - ptr - 4),
444 "%.2x ", *tmp_ptr & 0xff);
445 if ((((tmp_ptr - tmp_buf) + 1) & 0xf) == 0)
446 ptr += snprintf((char *)ptr, (cis + length - ptr -4), "\n");
447 }
448 MFREE(bcmsdh->osh, tmp_buf, length);
449 }
450
451 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
452 }
453
454 int
bcmsdh_cisaddr_read(void * sdh,uint func,uint8 * cisd,uint32 offset)455 bcmsdh_cisaddr_read(void *sdh, uint func, uint8 *cisd, uint32 offset)
456 {
457 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
458 SDIOH_API_RC status;
459
460 func &= 0x7;
461
462 if (!bcmsdh)
463 bcmsdh = l_bcmsdh;
464
465 ASSERT(bcmsdh->init_success);
466 ASSERT(cisd);
467
468 status = sdioh_cisaddr_read(bcmsdh->sdioh, func, cisd, offset);
469
470 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
471 }
472
473
474 int
bcmsdhsdio_set_sbaddr_window(void * sdh,uint32 address,bool force_set)475 bcmsdhsdio_set_sbaddr_window(void *sdh, uint32 address, bool force_set)
476 {
477 int err = 0;
478 uint bar0 = address & ~SBSDIO_SB_OFT_ADDR_MASK;
479 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
480
481 if (bar0 != bcmsdh->sbwad || force_set) {
482 bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
483 (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err);
484 if (!err)
485 bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID,
486 (address >> 16) & SBSDIO_SBADDRMID_MASK, &err);
487 if (!err)
488 bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH,
489 (address >> 24) & SBSDIO_SBADDRHIGH_MASK, &err);
490
491 if (!err)
492 bcmsdh->sbwad = bar0;
493 else
494 /* invalidate cached window var */
495 bcmsdh->sbwad = 0;
496 }
497
498 return err;
499 }
500
501 uint32
bcmsdh_reg_read(void * sdh,uintptr addr,uint size)502 bcmsdh_reg_read(void *sdh, uintptr addr, uint size)
503 {
504 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
505 SDIOH_API_RC status;
506 uint32 word = 0;
507
508 BCMSDH_INFO(("%s:fun = 1, addr = 0x%x\n", __FUNCTION__, (unsigned int)addr));
509
510 if (!bcmsdh)
511 bcmsdh = l_bcmsdh;
512
513 ASSERT(bcmsdh->init_success);
514
515 if (bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)) {
516 bcmsdh->regfail = TRUE; // terence 20130621: prevent dhd_dpc in dead lock
517 return 0xFFFFFFFF;
518 }
519
520 addr &= SBSDIO_SB_OFT_ADDR_MASK;
521 if (size == 4)
522 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
523
524 status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL,
525 SDIOH_READ, SDIO_FUNC_1, addr, &word, size);
526
527 bcmsdh->regfail = !(SDIOH_API_SUCCESS(status));
528
529 BCMSDH_INFO(("uint32data = 0x%x\n", word));
530
531 /* if ok, return appropriately masked word */
532 if (SDIOH_API_SUCCESS(status)) {
533 switch (size) {
534 case sizeof(uint8):
535 return (word & 0xff);
536 case sizeof(uint16):
537 return (word & 0xffff);
538 case sizeof(uint32):
539 return word;
540 default:
541 bcmsdh->regfail = TRUE;
542 }
543 }
544
545 /* otherwise, bad sdio access or invalid size */
546 BCMSDH_ERROR(("%s: error reading addr 0x%x size %d\n",
547 __FUNCTION__, (unsigned int)addr, size));
548 return 0xFFFFFFFF;
549 }
550
551 uint32
bcmsdh_reg_write(void * sdh,uintptr addr,uint size,uint32 data)552 bcmsdh_reg_write(void *sdh, uintptr addr, uint size, uint32 data)
553 {
554 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
555 SDIOH_API_RC status;
556 int err = 0;
557
558 BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n",
559 __FUNCTION__, (unsigned int)addr, size*8, data));
560
561 if (!bcmsdh)
562 bcmsdh = l_bcmsdh;
563
564 ASSERT(bcmsdh->init_success);
565
566 if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, bcmsdh->force_sbwad_calc))) {
567 bcmsdh->regfail = TRUE; // terence 20130621:
568 return err;
569 }
570
571 addr &= SBSDIO_SB_OFT_ADDR_MASK;
572 if (size == 4)
573 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
574 status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_WRITE, SDIO_FUNC_1,
575 addr, &data, size);
576 bcmsdh->regfail = !(SDIOH_API_SUCCESS(status));
577
578 if (SDIOH_API_SUCCESS(status))
579 return 0;
580
581 BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n",
582 __FUNCTION__, data, (unsigned int)addr, size));
583 return 0xFFFFFFFF;
584 }
585
586 bool
bcmsdh_regfail(void * sdh)587 bcmsdh_regfail(void *sdh)
588 {
589 return ((bcmsdh_info_t *)sdh)->regfail;
590 }
591
592 int
bcmsdh_recv_buf(void * sdh,uint32 addr,uint fn,uint flags,uint8 * buf,uint nbytes,void * pkt,bcmsdh_cmplt_fn_t complete_fn,void * handle)593 bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags,
594 uint8 *buf, uint nbytes, void *pkt,
595 bcmsdh_cmplt_fn_t complete_fn, void *handle)
596 {
597 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
598 SDIOH_API_RC status;
599 uint incr_fix;
600 uint width;
601 int err = 0;
602
603 ASSERT(bcmsdh);
604 ASSERT(bcmsdh->init_success);
605
606 BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
607 __FUNCTION__, fn, addr, nbytes));
608
609 /* Async not implemented yet */
610 ASSERT(!(flags & SDIO_REQ_ASYNC));
611 if (flags & SDIO_REQ_ASYNC)
612 return BCME_UNSUPPORTED;
613
614 if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)))
615 return err;
616
617 addr &= SBSDIO_SB_OFT_ADDR_MASK;
618
619 incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
620 width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
621 if (width == 4)
622 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
623
624 status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix,
625 SDIOH_READ, fn, addr, width, nbytes, buf, pkt);
626
627 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
628 }
629
630 int
bcmsdh_send_buf(void * sdh,uint32 addr,uint fn,uint flags,uint8 * buf,uint nbytes,void * pkt,bcmsdh_cmplt_fn_t complete_fn,void * handle)631 bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags,
632 uint8 *buf, uint nbytes, void *pkt,
633 bcmsdh_cmplt_fn_t complete_fn, void *handle)
634 {
635 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
636 SDIOH_API_RC status;
637 uint incr_fix;
638 uint width;
639 int err = 0;
640
641 ASSERT(bcmsdh);
642 ASSERT(bcmsdh->init_success);
643
644 BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
645 __FUNCTION__, fn, addr, nbytes));
646
647 /* Async not implemented yet */
648 ASSERT(!(flags & SDIO_REQ_ASYNC));
649 if (flags & SDIO_REQ_ASYNC)
650 return BCME_UNSUPPORTED;
651
652 if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)))
653 return err;
654
655 addr &= SBSDIO_SB_OFT_ADDR_MASK;
656
657 incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
658 width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
659 if (width == 4)
660 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
661
662 status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix,
663 SDIOH_WRITE, fn, addr, width, nbytes, buf, pkt);
664
665 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
666 }
667
668 int
bcmsdh_rwdata(void * sdh,uint rw,uint32 addr,uint8 * buf,uint nbytes)669 bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes)
670 {
671 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
672 SDIOH_API_RC status;
673
674 ASSERT(bcmsdh);
675 ASSERT(bcmsdh->init_success);
676 ASSERT((addr & SBSDIO_SBWINDOW_MASK) == 0);
677
678 addr &= SBSDIO_SB_OFT_ADDR_MASK;
679 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
680
681 status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, SDIOH_DATA_INC,
682 (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1,
683 addr, 4, nbytes, buf, NULL);
684
685 return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
686 }
687
688 int
bcmsdh_abort(void * sdh,uint fn)689 bcmsdh_abort(void *sdh, uint fn)
690 {
691 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
692
693 return sdioh_abort(bcmsdh->sdioh, fn);
694 }
695
696 int
bcmsdh_start(void * sdh,int stage)697 bcmsdh_start(void *sdh, int stage)
698 {
699 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
700
701 return sdioh_start(bcmsdh->sdioh, stage);
702 }
703
704 int
bcmsdh_stop(void * sdh)705 bcmsdh_stop(void *sdh)
706 {
707 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
708
709 return sdioh_stop(bcmsdh->sdioh);
710 }
711
712 int
bcmsdh_waitlockfree(void * sdh)713 bcmsdh_waitlockfree(void *sdh)
714 {
715 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
716
717 return sdioh_waitlockfree(bcmsdh->sdioh);
718 }
719
720 int
bcmsdh_query_device(void * sdh)721 bcmsdh_query_device(void *sdh)
722 {
723 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
724 bcmsdh->vendevid = (VENDOR_BROADCOM << 16) | 0;
725 return (bcmsdh->vendevid);
726 }
727
728 uint
bcmsdh_query_iofnum(void * sdh)729 bcmsdh_query_iofnum(void *sdh)
730 {
731 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
732
733 if (!bcmsdh)
734 bcmsdh = l_bcmsdh;
735
736 return (sdioh_query_iofnum(bcmsdh->sdioh));
737 }
738
739 int
bcmsdh_reset(bcmsdh_info_t * sdh)740 bcmsdh_reset(bcmsdh_info_t *sdh)
741 {
742 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
743
744 return sdioh_sdio_reset(bcmsdh->sdioh);
745 }
746
bcmsdh_get_sdioh(bcmsdh_info_t * sdh)747 void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh)
748 {
749 ASSERT(sdh);
750 return sdh->sdioh;
751 }
752
753 /* Function to pass device-status bits to DHD. */
754 uint32
bcmsdh_get_dstatus(void * sdh)755 bcmsdh_get_dstatus(void *sdh)
756 {
757 return 0;
758 }
759 uint32
bcmsdh_cur_sbwad(void * sdh)760 bcmsdh_cur_sbwad(void *sdh)
761 {
762 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
763
764 if (!bcmsdh)
765 bcmsdh = l_bcmsdh;
766
767 return (bcmsdh->sbwad);
768 }
769
770 /* example usage: if force is TRUE, forces the bcmsdhsdio_set_sbaddr_window to
771 * calculate sbwad always instead of caching.
772 */
773 void
bcmsdh_force_sbwad_calc(void * sdh,bool force)774 bcmsdh_force_sbwad_calc(void *sdh, bool force)
775 {
776 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
777
778 if (!bcmsdh)
779 bcmsdh = l_bcmsdh;
780 bcmsdh->force_sbwad_calc = force;
781 }
782
783 void
bcmsdh_chipinfo(void * sdh,uint32 chip,uint32 chiprev)784 bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev)
785 {
786 return;
787 }
788
789
790 int
bcmsdh_sleep(void * sdh,bool enab)791 bcmsdh_sleep(void *sdh, bool enab)
792 {
793 #ifdef SDIOH_SLEEP_ENABLED
794 bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
795 sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
796
797 return sdioh_sleep(sd, enab);
798 #else
799 return BCME_UNSUPPORTED;
800 #endif
801 }
802
803 int
bcmsdh_gpio_init(void * sdh)804 bcmsdh_gpio_init(void *sdh)
805 {
806 bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
807 sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
808
809 return sdioh_gpio_init(sd);
810 }
811
812 bool
bcmsdh_gpioin(void * sdh,uint32 gpio)813 bcmsdh_gpioin(void *sdh, uint32 gpio)
814 {
815 bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
816 sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
817
818 return sdioh_gpioin(sd, gpio);
819 }
820
821 int
bcmsdh_gpioouten(void * sdh,uint32 gpio)822 bcmsdh_gpioouten(void *sdh, uint32 gpio)
823 {
824 bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
825 sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
826
827 return sdioh_gpioouten(sd, gpio);
828 }
829
830 int
bcmsdh_gpioout(void * sdh,uint32 gpio,bool enab)831 bcmsdh_gpioout(void *sdh, uint32 gpio, bool enab)
832 {
833 bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
834 sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
835
836 return sdioh_gpioout(sd, gpio, enab);
837 }
838
839 uint
bcmsdh_set_mode(void * sdh,uint mode)840 bcmsdh_set_mode(void *sdh, uint mode)
841 {
842 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
843 return (sdioh_set_mode(bcmsdh->sdioh, mode));
844 }
845