• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  BCMSDH interface glue
3  *  implement bcmsdh API for SDIOH driver
4  *
5  * Copyright (C) 1999-2013, 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  * $Id: bcmsdh.c 373331 2012-12-07 04:46:22Z $
26  */
27 
28 /**
29  * @file bcmsdh.c
30  */
31 
32 /* ****************** BCMSDH Interface Functions *************************** */
33 
34 #include <typedefs.h>
35 #include <bcmdevs.h>
36 #include <bcmendian.h>
37 #include <bcmutils.h>
38 #include <hndsoc.h>
39 #include <siutils.h>
40 #include <osl.h>
41 
42 #include <bcmsdh.h>	/* BRCM API for SDIO clients (such as wl, dhd) */
43 #include <bcmsdbus.h>	/* common SDIO/controller interface */
44 #include <sbsdio.h>	/* SDIO device core hardware definitions. */
45 
46 #include <sdio.h>	/* SDIO Device and Protocol Specs */
47 
48 #define SDIOH_API_ACCESS_RETRY_LIMIT	2
49 const uint bcmsdh_msglevel = BCMSDH_ERROR_VAL;
50 
51 /**
52  * BCMSDH API context
53  */
54 struct bcmsdh_info
55 {
56 	bool	init_success;	/* underlying driver successfully attached */
57 	void	*sdioh;		/* handler for sdioh */
58 	uint32  vendevid;	/* Target Vendor and Device ID on SD bus */
59 	osl_t   *osh;
60 	bool	regfail;	/* Save status of last reg_read/reg_write call */
61 	uint32	sbwad;		/* Save backplane window address */
62 };
63 /* local copy of bcm sd handler */
64 bcmsdh_info_t * l_bcmsdh = NULL;
65 
66 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
67 extern int
68 sdioh_enable_hw_oob_intr(void *sdioh, bool enable);
69 
70 void
bcmsdh_enable_hw_oob_intr(bcmsdh_info_t * sdh,bool enable)71 bcmsdh_enable_hw_oob_intr(bcmsdh_info_t *sdh, bool enable)
72 {
73 	sdioh_enable_hw_oob_intr(sdh->sdioh, enable);
74 }
75 #endif
76 
77 /* Attach BCMSDH layer to SDIO Host Controller Driver
78  *
79  * @param osh OSL Handle.
80  * @param cfghdl Configuration Handle.
81  * @param regsva Virtual address of controller registers.
82  * @param irq Interrupt number of SDIO controller.
83  *
84  * @return bcmsdh_info_t Handle to BCMSDH context.
85  */
86 bcmsdh_info_t *
bcmsdh_attach(osl_t * osh,void * cfghdl,void ** regsva,uint irq)87 bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, uint irq)
88 {
89 	bcmsdh_info_t *bcmsdh;
90 
91 	if ((bcmsdh = (bcmsdh_info_t *)MALLOC(osh, sizeof(bcmsdh_info_t))) == NULL) {
92 		BCMSDH_ERROR(("bcmsdh_attach: out of memory, malloced %d bytes\n", MALLOCED(osh)));
93 		return NULL;
94 	}
95 	bzero((char *)bcmsdh, sizeof(bcmsdh_info_t));
96 
97 	/* save the handler locally */
98 	l_bcmsdh = bcmsdh;
99 
100 	if (!(bcmsdh->sdioh = sdioh_attach(osh, cfghdl, irq))) {
101 		bcmsdh_detach(osh, bcmsdh);
102 		return NULL;
103 	}
104 
105 	bcmsdh->osh = osh;
106 	bcmsdh->init_success = TRUE;
107 
108 	*regsva = (uint32 *)SI_ENUM_BASE;
109 
110 	/* Report the BAR, to fix if needed */
111 	bcmsdh->sbwad = SI_ENUM_BASE;
112 	return bcmsdh;
113 }
114 
115 int
bcmsdh_detach(osl_t * osh,void * sdh)116 bcmsdh_detach(osl_t *osh, void *sdh)
117 {
118 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
119 
120 	if (bcmsdh != NULL) {
121 		if (bcmsdh->sdioh) {
122 			sdioh_detach(osh, bcmsdh->sdioh);
123 			bcmsdh->sdioh = NULL;
124 		}
125 		MFREE(osh, bcmsdh, sizeof(bcmsdh_info_t));
126 	}
127 
128 	l_bcmsdh = NULL;
129 	return 0;
130 }
131 
132 int
bcmsdh_iovar_op(void * sdh,const char * name,void * params,int plen,void * arg,int len,bool set)133 bcmsdh_iovar_op(void *sdh, const char *name,
134                 void *params, int plen, void *arg, int len, bool set)
135 {
136 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
137 	return sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, len, set);
138 }
139 
140 bool
bcmsdh_intr_query(void * sdh)141 bcmsdh_intr_query(void *sdh)
142 {
143 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
144 	SDIOH_API_RC status;
145 	bool on;
146 
147 	ASSERT(bcmsdh);
148 	status = sdioh_interrupt_query(bcmsdh->sdioh, &on);
149 	if (SDIOH_API_SUCCESS(status))
150 		return FALSE;
151 	else
152 		return on;
153 }
154 
155 int
bcmsdh_intr_enable(void * sdh)156 bcmsdh_intr_enable(void *sdh)
157 {
158 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
159 	SDIOH_API_RC status;
160 	ASSERT(bcmsdh);
161 
162 	status = sdioh_interrupt_set(bcmsdh->sdioh, TRUE);
163 	return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
164 }
165 
166 int
bcmsdh_intr_disable(void * sdh)167 bcmsdh_intr_disable(void *sdh)
168 {
169 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
170 	SDIOH_API_RC status;
171 	ASSERT(bcmsdh);
172 
173 	status = sdioh_interrupt_set(bcmsdh->sdioh, FALSE);
174 	return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
175 }
176 
177 int
bcmsdh_intr_reg(void * sdh,bcmsdh_cb_fn_t fn,void * argh)178 bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh)
179 {
180 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
181 	SDIOH_API_RC status;
182 	ASSERT(bcmsdh);
183 
184 	status = sdioh_interrupt_register(bcmsdh->sdioh, fn, argh);
185 	return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
186 }
187 
188 int
bcmsdh_intr_dereg(void * sdh)189 bcmsdh_intr_dereg(void *sdh)
190 {
191 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
192 	SDIOH_API_RC status;
193 	ASSERT(bcmsdh);
194 
195 	status = sdioh_interrupt_deregister(bcmsdh->sdioh);
196 	return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
197 }
198 
199 #if defined(DHD_DEBUG)
200 bool
bcmsdh_intr_pending(void * sdh)201 bcmsdh_intr_pending(void *sdh)
202 {
203 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
204 
205 	ASSERT(sdh);
206 	return sdioh_interrupt_pending(bcmsdh->sdioh);
207 }
208 #endif
209 
210 
211 int
bcmsdh_devremove_reg(void * sdh,bcmsdh_cb_fn_t fn,void * argh)212 bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh)
213 {
214 	ASSERT(sdh);
215 
216 	/* don't support yet */
217 	return BCME_UNSUPPORTED;
218 }
219 
220 /**
221  * Read from SDIO Configuration Space
222  * @param sdh SDIO Host context.
223  * @param func_num Function number to read from.
224  * @param addr Address to read from.
225  * @param err Error return.
226  * @return value read from SDIO configuration space.
227  */
228 uint8
bcmsdh_cfg_read(void * sdh,uint fnc_num,uint32 addr,int * err)229 bcmsdh_cfg_read(void *sdh, uint fnc_num, uint32 addr, int *err)
230 {
231 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
232 	SDIOH_API_RC status;
233 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
234 	int32 retry = 0;
235 #endif
236 	uint8 data = 0;
237 
238 	if (!bcmsdh)
239 		bcmsdh = l_bcmsdh;
240 
241 	ASSERT(bcmsdh->init_success);
242 
243 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
244 	do {
245 		if (retry)	/* wait for 1 ms till bus get settled down */
246 			OSL_DELAY(1000);
247 #endif
248 	status = sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr, (uint8 *)&data);
249 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
250 	} while (!SDIOH_API_SUCCESS(status) && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
251 #endif
252 	if (err)
253 		*err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
254 
255 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", __FUNCTION__,
256 	            fnc_num, addr, data));
257 
258 	return data;
259 }
260 
261 void
bcmsdh_cfg_write(void * sdh,uint fnc_num,uint32 addr,uint8 data,int * err)262 bcmsdh_cfg_write(void *sdh, uint fnc_num, uint32 addr, uint8 data, int *err)
263 {
264 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
265 	SDIOH_API_RC status;
266 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
267 	int32 retry = 0;
268 #endif
269 
270 	if (!bcmsdh)
271 		bcmsdh = l_bcmsdh;
272 
273 	ASSERT(bcmsdh->init_success);
274 
275 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
276 	do {
277 		if (retry)	/* wait for 1 ms till bus get settled down */
278 			OSL_DELAY(1000);
279 #endif
280 	status = sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr, (uint8 *)&data);
281 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
282 	} while (!SDIOH_API_SUCCESS(status) && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
283 #endif
284 	if (err)
285 		*err = SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR;
286 
287 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", __FUNCTION__,
288 	            fnc_num, addr, data));
289 }
290 
291 uint32
bcmsdh_cfg_read_word(void * sdh,uint fnc_num,uint32 addr,int * err)292 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, int *err)
293 {
294 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
295 	SDIOH_API_RC status;
296 	uint32 data = 0;
297 
298 	if (!bcmsdh)
299 		bcmsdh = l_bcmsdh;
300 
301 	ASSERT(bcmsdh->init_success);
302 
303 	status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_READ, fnc_num,
304 	                            addr, &data, 4);
305 
306 	if (err)
307 		*err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
308 
309 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", __FUNCTION__,
310 	            fnc_num, addr, data));
311 
312 	return data;
313 }
314 
315 void
bcmsdh_cfg_write_word(void * sdh,uint fnc_num,uint32 addr,uint32 data,int * err)316 bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, uint32 data, int *err)
317 {
318 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
319 	SDIOH_API_RC status;
320 
321 	if (!bcmsdh)
322 		bcmsdh = l_bcmsdh;
323 
324 	ASSERT(bcmsdh->init_success);
325 
326 	status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_WRITE, fnc_num,
327 	                            addr, &data, 4);
328 
329 	if (err)
330 		*err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
331 
332 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", __FUNCTION__, fnc_num,
333 	             addr, data));
334 }
335 
336 
337 int
bcmsdh_cis_read(void * sdh,uint func,uint8 * cis,uint length)338 bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length)
339 {
340 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
341 	SDIOH_API_RC status;
342 
343 	uint8 *tmp_buf, *tmp_ptr;
344 	uint8 *ptr;
345 	bool ascii = func & ~0xf;
346 	func &= 0x7;
347 
348 	if (!bcmsdh)
349 		bcmsdh = l_bcmsdh;
350 
351 	ASSERT(bcmsdh->init_success);
352 	ASSERT(cis);
353 	ASSERT(length <= SBSDIO_CIS_SIZE_LIMIT);
354 
355 	status = sdioh_cis_read(bcmsdh->sdioh, func, cis, length);
356 
357 	if (ascii) {
358 		/* Move binary bits to tmp and format them into the provided buffer. */
359 		if ((tmp_buf = (uint8 *)MALLOC(bcmsdh->osh, length)) == NULL) {
360 			BCMSDH_ERROR(("%s: out of memory\n", __FUNCTION__));
361 			return BCME_NOMEM;
362 		}
363 		bcopy(cis, tmp_buf, length);
364 		for (tmp_ptr = tmp_buf, ptr = cis; ptr < (cis + length - 4); tmp_ptr++) {
365 			ptr += snprintf((char*)ptr, (cis + length - ptr - 4),
366 				"%.2x ", *tmp_ptr & 0xff);
367 			if ((((tmp_ptr - tmp_buf) + 1) & 0xf) == 0)
368 				ptr += snprintf((char *)ptr, (cis + length - ptr -4), "\n");
369 		}
370 		MFREE(bcmsdh->osh, tmp_buf, length);
371 	}
372 
373 	return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
374 }
375 
376 
377 int
bcmsdhsdio_set_sbaddr_window(void * sdh,uint32 address,bool force_set)378 bcmsdhsdio_set_sbaddr_window(void *sdh, uint32 address, bool force_set)
379 {
380 	int err = 0;
381 	uint bar0 = address & ~SBSDIO_SB_OFT_ADDR_MASK;
382 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
383 
384 	if (bar0 != bcmsdh->sbwad || force_set) {
385 		bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
386 			(address >> 8) & SBSDIO_SBADDRLOW_MASK, &err);
387 		if (!err)
388 			bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID,
389 				(address >> 16) & SBSDIO_SBADDRMID_MASK, &err);
390 		if (!err)
391 			bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH,
392 				(address >> 24) & SBSDIO_SBADDRHIGH_MASK, &err);
393 
394 		if (!err)
395 			bcmsdh->sbwad = bar0;
396 		else
397 			/* invalidate cached window var */
398 			bcmsdh->sbwad = 0;
399 
400 	}
401 
402 	return err;
403 }
404 
405 uint32
bcmsdh_reg_read(void * sdh,uint32 addr,uint size)406 bcmsdh_reg_read(void *sdh, uint32 addr, uint size)
407 {
408 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
409 	SDIOH_API_RC status;
410 	uint32 word = 0;
411 
412 	BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, ", __FUNCTION__, addr));
413 
414 	if (!bcmsdh)
415 		bcmsdh = l_bcmsdh;
416 
417 	ASSERT(bcmsdh->init_success);
418 
419 	if (bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE))
420 		return 0xFFFFFFFF;
421 
422 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
423 	if (size == 4)
424 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
425 
426 	status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL,
427 		SDIOH_READ, SDIO_FUNC_1, addr, &word, size);
428 
429 	bcmsdh->regfail = !(SDIOH_API_SUCCESS(status));
430 
431 	BCMSDH_INFO(("uint32data = 0x%x\n", word));
432 
433 	/* if ok, return appropriately masked word */
434 	if (SDIOH_API_SUCCESS(status)) {
435 		switch (size) {
436 			case sizeof(uint8):
437 				return (word & 0xff);
438 			case sizeof(uint16):
439 				return (word & 0xffff);
440 			case sizeof(uint32):
441 				return word;
442 			default:
443 				bcmsdh->regfail = TRUE;
444 
445 		}
446 	}
447 
448 	/* otherwise, bad sdio access or invalid size */
449 	BCMSDH_ERROR(("%s: error reading addr 0x%04x size %d\n", __FUNCTION__, addr, size));
450 	return 0xFFFFFFFF;
451 }
452 
453 uint32
bcmsdh_reg_write(void * sdh,uint32 addr,uint size,uint32 data)454 bcmsdh_reg_write(void *sdh, uint32 addr, uint size, uint32 data)
455 {
456 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
457 	SDIOH_API_RC status;
458 	int err = 0;
459 
460 	BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n",
461 	             __FUNCTION__, addr, size*8, data));
462 
463 	if (!bcmsdh)
464 		bcmsdh = l_bcmsdh;
465 
466 	ASSERT(bcmsdh->init_success);
467 
468 	if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)))
469 		return err;
470 
471 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
472 	if (size == 4)
473 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
474 	status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_WRITE, SDIO_FUNC_1,
475 	                            addr, &data, size);
476 	bcmsdh->regfail = !(SDIOH_API_SUCCESS(status));
477 
478 	if (SDIOH_API_SUCCESS(status))
479 		return 0;
480 
481 	BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n",
482 	              __FUNCTION__, data, addr, size));
483 	return 0xFFFFFFFF;
484 }
485 
486 bool
bcmsdh_regfail(void * sdh)487 bcmsdh_regfail(void *sdh)
488 {
489 	return ((bcmsdh_info_t *)sdh)->regfail;
490 }
491 
492 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)493 bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags,
494                 uint8 *buf, uint nbytes, void *pkt,
495                 bcmsdh_cmplt_fn_t complete_fn, void *handle)
496 {
497 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
498 	SDIOH_API_RC status;
499 	uint incr_fix;
500 	uint width;
501 	int err = 0;
502 
503 	ASSERT(bcmsdh);
504 	ASSERT(bcmsdh->init_success);
505 
506 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
507 	             __FUNCTION__, fn, addr, nbytes));
508 
509 	/* Async not implemented yet */
510 	ASSERT(!(flags & SDIO_REQ_ASYNC));
511 	if (flags & SDIO_REQ_ASYNC)
512 		return BCME_UNSUPPORTED;
513 
514 	if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)))
515 		return err;
516 
517 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
518 
519 	incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
520 	width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
521 	if (width == 4)
522 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
523 
524 	status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix,
525 	                              SDIOH_READ, fn, addr, width, nbytes, buf, pkt);
526 
527 	return (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
528 }
529 
530 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)531 bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags,
532                 uint8 *buf, uint nbytes, void *pkt,
533                 bcmsdh_cmplt_fn_t complete_fn, void *handle)
534 {
535 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
536 	SDIOH_API_RC status;
537 	uint incr_fix;
538 	uint width;
539 	int err = 0;
540 
541 	ASSERT(bcmsdh);
542 	ASSERT(bcmsdh->init_success);
543 
544 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
545 	            __FUNCTION__, fn, addr, nbytes));
546 
547 	/* Async not implemented yet */
548 	ASSERT(!(flags & SDIO_REQ_ASYNC));
549 	if (flags & SDIO_REQ_ASYNC)
550 		return BCME_UNSUPPORTED;
551 
552 	if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)))
553 		return err;
554 
555 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
556 
557 	incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
558 	width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
559 	if (width == 4)
560 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
561 
562 	status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix,
563 	                              SDIOH_WRITE, fn, addr, width, nbytes, buf, pkt);
564 
565 	return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
566 }
567 
568 int
bcmsdh_rwdata(void * sdh,uint rw,uint32 addr,uint8 * buf,uint nbytes)569 bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes)
570 {
571 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
572 	SDIOH_API_RC status;
573 
574 	ASSERT(bcmsdh);
575 	ASSERT(bcmsdh->init_success);
576 	ASSERT((addr & SBSDIO_SBWINDOW_MASK) == 0);
577 
578 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
579 	addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
580 
581 	status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, SDIOH_DATA_INC,
582 	                              (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1,
583 	                              addr, 4, nbytes, buf, NULL);
584 
585 	return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR);
586 }
587 
588 int
bcmsdh_abort(void * sdh,uint fn)589 bcmsdh_abort(void *sdh, uint fn)
590 {
591 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
592 
593 	return sdioh_abort(bcmsdh->sdioh, fn);
594 }
595 
596 int
bcmsdh_start(void * sdh,int stage)597 bcmsdh_start(void *sdh, int stage)
598 {
599 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
600 
601 	return sdioh_start(bcmsdh->sdioh, stage);
602 }
603 
604 int
bcmsdh_stop(void * sdh)605 bcmsdh_stop(void *sdh)
606 {
607 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
608 
609 	return sdioh_stop(bcmsdh->sdioh);
610 }
611 
612 int
bcmsdh_waitlockfree(void * sdh)613 bcmsdh_waitlockfree(void *sdh)
614 {
615 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
616 	if (!bcmsdh)
617 		bcmsdh = l_bcmsdh;
618 
619 	return sdioh_waitlockfree(bcmsdh->sdioh);
620 }
621 
622 
623 int
bcmsdh_query_device(void * sdh)624 bcmsdh_query_device(void *sdh)
625 {
626 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
627 	bcmsdh->vendevid = (VENDOR_BROADCOM << 16) | 0;
628 	return (bcmsdh->vendevid);
629 }
630 
631 uint
bcmsdh_query_iofnum(void * sdh)632 bcmsdh_query_iofnum(void *sdh)
633 {
634 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
635 
636 	if (!bcmsdh)
637 		bcmsdh = l_bcmsdh;
638 
639 	return (sdioh_query_iofnum(bcmsdh->sdioh));
640 }
641 
642 int
bcmsdh_reset(bcmsdh_info_t * sdh)643 bcmsdh_reset(bcmsdh_info_t *sdh)
644 {
645 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
646 
647 	return sdioh_sdio_reset(bcmsdh->sdioh);
648 }
649 
bcmsdh_get_sdioh(bcmsdh_info_t * sdh)650 void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh)
651 {
652 	ASSERT(sdh);
653 	return sdh->sdioh;
654 }
655 
656 /* Function to pass device-status bits to DHD. */
657 uint32
bcmsdh_get_dstatus(void * sdh)658 bcmsdh_get_dstatus(void *sdh)
659 {
660 	return 0;
661 }
662 uint32
bcmsdh_cur_sbwad(void * sdh)663 bcmsdh_cur_sbwad(void *sdh)
664 {
665 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
666 
667 	if (!bcmsdh)
668 		bcmsdh = l_bcmsdh;
669 
670 	return (bcmsdh->sbwad);
671 }
672 
673 void
bcmsdh_chipinfo(void * sdh,uint32 chip,uint32 chiprev)674 bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev)
675 {
676 	return;
677 }
678 
679 
680 int
bcmsdh_sleep(void * sdh,bool enab)681 bcmsdh_sleep(void *sdh, bool enab)
682 {
683 #ifdef SDIOH_SLEEP_ENABLED
684 	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
685 	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
686 
687 	return sdioh_sleep(sd, enab);
688 #else
689 	return BCME_UNSUPPORTED;
690 #endif
691 }
692 
693 int
bcmsdh_gpio_init(void * sdh)694 bcmsdh_gpio_init(void *sdh)
695 {
696 	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
697 	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
698 
699 	return sdioh_gpio_init(sd);
700 }
701 
702 bool
bcmsdh_gpioin(void * sdh,uint32 gpio)703 bcmsdh_gpioin(void *sdh, uint32 gpio)
704 {
705 	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
706 	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
707 
708 	return sdioh_gpioin(sd, gpio);
709 }
710 
711 int
bcmsdh_gpioouten(void * sdh,uint32 gpio)712 bcmsdh_gpioouten(void *sdh, uint32 gpio)
713 {
714 	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
715 	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
716 
717 	return sdioh_gpioouten(sd, gpio);
718 }
719 
720 int
bcmsdh_gpioout(void * sdh,uint32 gpio,bool enab)721 bcmsdh_gpioout(void *sdh, uint32 gpio, bool enab)
722 {
723 	bcmsdh_info_t *p = (bcmsdh_info_t *)sdh;
724 	sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh);
725 
726 	return sdioh_gpioout(sd, gpio, enab);
727 }
728 
729 #ifdef BCMSDIOH_TXGLOM
730 void
bcmsdh_glom_post(void * sdh,uint8 * frame,void * pkt,uint len)731 bcmsdh_glom_post(void *sdh, uint8 *frame, void *pkt, uint len)
732 {
733 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
734 	sdioh_glom_post(bcmsdh->sdioh, frame, pkt, len);
735 }
736 
737 void
bcmsdh_glom_clear(void * sdh)738 bcmsdh_glom_clear(void *sdh)
739 {
740 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
741 	sdioh_glom_clear(bcmsdh->sdioh);
742 }
743 
744 uint
bcmsdh_set_mode(void * sdh,uint mode)745 bcmsdh_set_mode(void *sdh, uint mode)
746 {
747 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh;
748 	return (sdioh_set_mode(bcmsdh->sdioh, mode));
749 }
750 
751 bool
bcmsdh_glom_enabled(void)752 bcmsdh_glom_enabled(void)
753 {
754 	return (sdioh_glom_enabled());
755 }
756 #endif /* BCMSDIOH_TXGLOM */
757