1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
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.
7  *
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.
15  */
16 /* ****************** BCMSDH Interface Functions *************************** */
17 
18 #include <linux/types.h>
19 #include <linux/netdevice.h>
20 #include <bcmdefs.h>
21 #include <bcmdevs.h>
22 #include <bcmutils.h>
23 #include <hndsoc.h>
24 #include <siutils.h>
25 
26 #include <bcmsdh.h>		/* BRCM API for SDIO
27 			 clients (such as wl, dhd) */
28 #include <bcmsdbus.h>		/* common SDIO/controller interface */
29 #include <sbsdio.h>		/* BRCM sdio device core */
30 
31 #include <sdio.h>		/* sdio spec */
32 
33 #define SDIOH_API_ACCESS_RETRY_LIMIT	2
34 const uint bcmsdh_msglevel = BCMSDH_ERROR_VAL;
35 
36 struct bcmsdh_info {
37 	bool init_success;	/* underlying driver successfully attached */
38 	void *sdioh;		/* handler for sdioh */
39 	u32 vendevid;	/* Target Vendor and Device ID on SD bus */
40 	bool regfail;		/* Save status of last
41 				 reg_read/reg_write call */
42 	u32 sbwad;		/* Save backplane window address */
43 };
44 /* local copy of bcm sd handler */
45 bcmsdh_info_t *l_bcmsdh;
46 
47 #if defined(OOB_INTR_ONLY) && defined(HW_OOB)
48 extern int sdioh_enable_hw_oob_intr(void *sdioh, bool enable);
49 
bcmsdh_enable_hw_oob_intr(bcmsdh_info_t * sdh,bool enable)50 void bcmsdh_enable_hw_oob_intr(bcmsdh_info_t *sdh, bool enable)
51 {
52 	sdioh_enable_hw_oob_intr(sdh->sdioh, enable);
53 }
54 #endif
55 
bcmsdh_attach(void * cfghdl,void ** regsva,uint irq)56 bcmsdh_info_t *bcmsdh_attach(void *cfghdl, void **regsva, uint irq)
57 {
58 	bcmsdh_info_t *bcmsdh;
59 
60 	bcmsdh = kzalloc(sizeof(bcmsdh_info_t), GFP_ATOMIC);
61 	if (bcmsdh == NULL) {
62 		BCMSDH_ERROR(("bcmsdh_attach: out of memory"));
63 		return NULL;
64 	}
65 
66 	/* save the handler locally */
67 	l_bcmsdh = bcmsdh;
68 
69 	bcmsdh->sdioh = sdioh_attach(cfghdl, irq);
70 	if (!bcmsdh->sdioh) {
71 		bcmsdh_detach(bcmsdh);
72 		return NULL;
73 	}
74 
75 	bcmsdh->init_success = true;
76 
77 	*regsva = (u32 *) SI_ENUM_BASE;
78 
79 	/* Report the BAR, to fix if needed */
80 	bcmsdh->sbwad = SI_ENUM_BASE;
81 	return bcmsdh;
82 }
83 
bcmsdh_detach(void * sdh)84 int bcmsdh_detach(void *sdh)
85 {
86 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
87 
88 	if (bcmsdh != NULL) {
89 		if (bcmsdh->sdioh) {
90 			sdioh_detach(bcmsdh->sdioh);
91 			bcmsdh->sdioh = NULL;
92 		}
93 		kfree(bcmsdh);
94 	}
95 
96 	l_bcmsdh = NULL;
97 	return 0;
98 }
99 
100 int
bcmsdh_iovar_op(void * sdh,const char * name,void * params,int plen,void * arg,int len,bool set)101 bcmsdh_iovar_op(void *sdh, const char *name,
102 		void *params, int plen, void *arg, int len, bool set)
103 {
104 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
105 	return sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, len, set);
106 }
107 
bcmsdh_intr_query(void * sdh)108 bool bcmsdh_intr_query(void *sdh)
109 {
110 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
111 	SDIOH_API_RC status;
112 	bool on;
113 
114 	ASSERT(bcmsdh);
115 	status = sdioh_interrupt_query(bcmsdh->sdioh, &on);
116 	if (SDIOH_API_SUCCESS(status))
117 		return false;
118 	else
119 		return on;
120 }
121 
bcmsdh_intr_enable(void * sdh)122 int bcmsdh_intr_enable(void *sdh)
123 {
124 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
125 	SDIOH_API_RC status;
126 	ASSERT(bcmsdh);
127 
128 	status = sdioh_interrupt_set(bcmsdh->sdioh, true);
129 	return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR;
130 }
131 
bcmsdh_intr_disable(void * sdh)132 int bcmsdh_intr_disable(void *sdh)
133 {
134 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
135 	SDIOH_API_RC status;
136 	ASSERT(bcmsdh);
137 
138 	status = sdioh_interrupt_set(bcmsdh->sdioh, false);
139 	return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR;
140 }
141 
bcmsdh_intr_reg(void * sdh,bcmsdh_cb_fn_t fn,void * argh)142 int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh)
143 {
144 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
145 	SDIOH_API_RC status;
146 	ASSERT(bcmsdh);
147 
148 	status = sdioh_interrupt_register(bcmsdh->sdioh, fn, argh);
149 	return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR;
150 }
151 
bcmsdh_intr_dereg(void * sdh)152 int bcmsdh_intr_dereg(void *sdh)
153 {
154 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
155 	SDIOH_API_RC status;
156 	ASSERT(bcmsdh);
157 
158 	status = sdioh_interrupt_deregister(bcmsdh->sdioh);
159 	return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR;
160 }
161 
162 #if defined(DHD_DEBUG)
bcmsdh_intr_pending(void * sdh)163 bool bcmsdh_intr_pending(void *sdh)
164 {
165 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
166 
167 	ASSERT(sdh);
168 	return sdioh_interrupt_pending(bcmsdh->sdioh);
169 }
170 #endif
171 
bcmsdh_devremove_reg(void * sdh,bcmsdh_cb_fn_t fn,void * argh)172 int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh)
173 {
174 	ASSERT(sdh);
175 
176 	/* don't support yet */
177 	return BCME_UNSUPPORTED;
178 }
179 
bcmsdh_cfg_read(void * sdh,uint fnc_num,u32 addr,int * err)180 u8 bcmsdh_cfg_read(void *sdh, uint fnc_num, u32 addr, int *err)
181 {
182 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
183 	SDIOH_API_RC status;
184 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
185 	s32 retry = 0;
186 #endif
187 	u8 data = 0;
188 
189 	if (!bcmsdh)
190 		bcmsdh = l_bcmsdh;
191 
192 	ASSERT(bcmsdh->init_success);
193 
194 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
195 	do {
196 		if (retry)	/* wait for 1 ms till bus get settled down */
197 			udelay(1000);
198 #endif
199 		status =
200 		    sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr,
201 				   (u8 *) &data);
202 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
203 	} while (!SDIOH_API_SUCCESS(status)
204 		 && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
205 #endif
206 	if (err)
207 		*err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
208 
209 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n",
210 		     __func__, fnc_num, addr, data));
211 
212 	return data;
213 }
214 
215 void
bcmsdh_cfg_write(void * sdh,uint fnc_num,u32 addr,u8 data,int * err)216 bcmsdh_cfg_write(void *sdh, uint fnc_num, u32 addr, u8 data, int *err)
217 {
218 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
219 	SDIOH_API_RC status;
220 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
221 	s32 retry = 0;
222 #endif
223 
224 	if (!bcmsdh)
225 		bcmsdh = l_bcmsdh;
226 
227 	ASSERT(bcmsdh->init_success);
228 
229 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
230 	do {
231 		if (retry)	/* wait for 1 ms till bus get settled down */
232 			udelay(1000);
233 #endif
234 		status =
235 		    sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr,
236 				    (u8 *) &data);
237 #ifdef SDIOH_API_ACCESS_RETRY_LIMIT
238 	} while (!SDIOH_API_SUCCESS(status)
239 		 && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
240 #endif
241 	if (err)
242 		*err = SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR;
243 
244 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n",
245 		     __func__, fnc_num, addr, data));
246 }
247 
bcmsdh_cfg_read_word(void * sdh,uint fnc_num,u32 addr,int * err)248 u32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, u32 addr, int *err)
249 {
250 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
251 	SDIOH_API_RC status;
252 	u32 data = 0;
253 
254 	if (!bcmsdh)
255 		bcmsdh = l_bcmsdh;
256 
257 	ASSERT(bcmsdh->init_success);
258 
259 	status =
260 	    sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_READ,
261 			       fnc_num, addr, &data, 4);
262 
263 	if (err)
264 		*err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
265 
266 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u32data = 0x%x\n",
267 		     __func__, fnc_num, addr, data));
268 
269 	return data;
270 }
271 
272 void
bcmsdh_cfg_write_word(void * sdh,uint fnc_num,u32 addr,u32 data,int * err)273 bcmsdh_cfg_write_word(void *sdh, uint fnc_num, u32 addr, u32 data,
274 		      int *err)
275 {
276 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
277 	SDIOH_API_RC status;
278 
279 	if (!bcmsdh)
280 		bcmsdh = l_bcmsdh;
281 
282 	ASSERT(bcmsdh->init_success);
283 
284 	status =
285 	    sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL,
286 			       SDIOH_WRITE, fnc_num, addr, &data, 4);
287 
288 	if (err)
289 		*err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR);
290 
291 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u32data = 0x%x\n",
292 		     __func__, fnc_num, addr, data));
293 }
294 
bcmsdh_cis_read(void * sdh,uint func,u8 * cis,uint length)295 int bcmsdh_cis_read(void *sdh, uint func, u8 * cis, uint length)
296 {
297 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
298 	SDIOH_API_RC status;
299 
300 	u8 *tmp_buf, *tmp_ptr;
301 	u8 *ptr;
302 	bool ascii = func & ~0xf;
303 	func &= 0x7;
304 
305 	if (!bcmsdh)
306 		bcmsdh = l_bcmsdh;
307 
308 	ASSERT(bcmsdh->init_success);
309 	ASSERT(cis);
310 	ASSERT(length <= SBSDIO_CIS_SIZE_LIMIT);
311 
312 	status = sdioh_cis_read(bcmsdh->sdioh, func, cis, length);
313 
314 	if (ascii) {
315 		/* Move binary bits to tmp and format them
316 			 into the provided buffer. */
317 		tmp_buf = kmalloc(length, GFP_ATOMIC);
318 		if (tmp_buf == NULL) {
319 			BCMSDH_ERROR(("%s: out of memory\n", __func__));
320 			return BCME_NOMEM;
321 		}
322 		memcpy(tmp_buf, cis, length);
323 		for (tmp_ptr = tmp_buf, ptr = cis; ptr < (cis + length - 4);
324 		     tmp_ptr++) {
325 			ptr += sprintf((char *)ptr, "%.2x ", *tmp_ptr & 0xff);
326 			if ((((tmp_ptr - tmp_buf) + 1) & 0xf) == 0)
327 				ptr += sprintf((char *)ptr, "\n");
328 		}
329 		kfree(tmp_buf);
330 	}
331 
332 	return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR;
333 }
334 
bcmsdhsdio_set_sbaddr_window(void * sdh,u32 address)335 static int bcmsdhsdio_set_sbaddr_window(void *sdh, u32 address)
336 {
337 	int err = 0;
338 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
339 	bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
340 			 (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err);
341 	if (!err)
342 		bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID,
343 				 (address >> 16) & SBSDIO_SBADDRMID_MASK, &err);
344 	if (!err)
345 		bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH,
346 				 (address >> 24) & SBSDIO_SBADDRHIGH_MASK,
347 				 &err);
348 
349 	return err;
350 }
351 
bcmsdh_reg_read(void * sdh,u32 addr,uint size)352 u32 bcmsdh_reg_read(void *sdh, u32 addr, uint size)
353 {
354 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
355 	SDIOH_API_RC status;
356 	u32 word = 0;
357 	uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
358 
359 	BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, ", __func__, addr));
360 
361 	if (!bcmsdh)
362 		bcmsdh = l_bcmsdh;
363 
364 	ASSERT(bcmsdh->init_success);
365 
366 	if (bar0 != bcmsdh->sbwad) {
367 		if (bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0))
368 			return 0xFFFFFFFF;
369 
370 		bcmsdh->sbwad = bar0;
371 	}
372 
373 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
374 	if (size == 4)
375 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
376 
377 	status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL,
378 				    SDIOH_READ, SDIO_FUNC_1, addr, &word, size);
379 
380 	bcmsdh->regfail = !(SDIOH_API_SUCCESS(status));
381 
382 	BCMSDH_INFO(("u32data = 0x%x\n", word));
383 
384 	/* if ok, return appropriately masked word */
385 	if (SDIOH_API_SUCCESS(status)) {
386 		switch (size) {
387 		case sizeof(u8):
388 			return word & 0xff;
389 		case sizeof(u16):
390 			return word & 0xffff;
391 		case sizeof(u32):
392 			return word;
393 		default:
394 			bcmsdh->regfail = true;
395 
396 		}
397 	}
398 
399 	/* otherwise, bad sdio access or invalid size */
400 	BCMSDH_ERROR(("%s: error reading addr 0x%04x size %d\n", __func__,
401 		      addr, size));
402 	return 0xFFFFFFFF;
403 }
404 
bcmsdh_reg_write(void * sdh,u32 addr,uint size,u32 data)405 u32 bcmsdh_reg_write(void *sdh, u32 addr, uint size, u32 data)
406 {
407 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
408 	SDIOH_API_RC status;
409 	uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
410 	int err = 0;
411 
412 	BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n",
413 		     __func__, addr, size * 8, data));
414 
415 	if (!bcmsdh)
416 		bcmsdh = l_bcmsdh;
417 
418 	ASSERT(bcmsdh->init_success);
419 
420 	if (bar0 != bcmsdh->sbwad) {
421 		err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0);
422 		if (err)
423 			return err;
424 
425 		bcmsdh->sbwad = bar0;
426 	}
427 
428 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
429 	if (size == 4)
430 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
431 	status =
432 	    sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL,
433 			       SDIOH_WRITE, SDIO_FUNC_1, addr, &data, size);
434 	bcmsdh->regfail = !(SDIOH_API_SUCCESS(status));
435 
436 	if (SDIOH_API_SUCCESS(status))
437 		return 0;
438 
439 	BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n",
440 		      __func__, data, addr, size));
441 	return 0xFFFFFFFF;
442 }
443 
bcmsdh_regfail(void * sdh)444 bool bcmsdh_regfail(void *sdh)
445 {
446 	return ((bcmsdh_info_t *) sdh)->regfail;
447 }
448 
449 int
bcmsdh_recv_buf(void * sdh,u32 addr,uint fn,uint flags,u8 * buf,uint nbytes,struct sk_buff * pkt,bcmsdh_cmplt_fn_t complete,void * handle)450 bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags,
451 		u8 *buf, uint nbytes, struct sk_buff *pkt,
452 		bcmsdh_cmplt_fn_t complete, void *handle)
453 {
454 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
455 	SDIOH_API_RC status;
456 	uint incr_fix;
457 	uint width;
458 	uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
459 	int err = 0;
460 
461 	ASSERT(bcmsdh);
462 	ASSERT(bcmsdh->init_success);
463 
464 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
465 		     __func__, fn, addr, nbytes));
466 
467 	/* Async not implemented yet */
468 	ASSERT(!(flags & SDIO_REQ_ASYNC));
469 	if (flags & SDIO_REQ_ASYNC)
470 		return BCME_UNSUPPORTED;
471 
472 	if (bar0 != bcmsdh->sbwad) {
473 		err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0);
474 		if (err)
475 			return err;
476 
477 		bcmsdh->sbwad = bar0;
478 	}
479 
480 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
481 
482 	incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
483 	width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
484 	if (width == 4)
485 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
486 
487 	status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix,
488 				      SDIOH_READ, fn, addr, width, nbytes, buf,
489 				      pkt);
490 
491 	return SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR;
492 }
493 
494 int
bcmsdh_send_buf(void * sdh,u32 addr,uint fn,uint flags,u8 * buf,uint nbytes,void * pkt,bcmsdh_cmplt_fn_t complete,void * handle)495 bcmsdh_send_buf(void *sdh, u32 addr, uint fn, uint flags,
496 		u8 *buf, uint nbytes, void *pkt,
497 		bcmsdh_cmplt_fn_t complete, void *handle)
498 {
499 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
500 	SDIOH_API_RC status;
501 	uint incr_fix;
502 	uint width;
503 	uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
504 	int err = 0;
505 
506 	ASSERT(bcmsdh);
507 	ASSERT(bcmsdh->init_success);
508 
509 	BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
510 		     __func__, fn, addr, nbytes));
511 
512 	/* Async not implemented yet */
513 	ASSERT(!(flags & SDIO_REQ_ASYNC));
514 	if (flags & SDIO_REQ_ASYNC)
515 		return BCME_UNSUPPORTED;
516 
517 	if (bar0 != bcmsdh->sbwad) {
518 		err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0);
519 		if (err)
520 			return err;
521 
522 		bcmsdh->sbwad = bar0;
523 	}
524 
525 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
526 
527 	incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC;
528 	width = (flags & SDIO_REQ_4BYTE) ? 4 : 2;
529 	if (width == 4)
530 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
531 
532 	status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix,
533 				      SDIOH_WRITE, fn, addr, width, nbytes, buf,
534 				      pkt);
535 
536 	return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR;
537 }
538 
bcmsdh_rwdata(void * sdh,uint rw,u32 addr,u8 * buf,uint nbytes)539 int bcmsdh_rwdata(void *sdh, uint rw, u32 addr, u8 *buf, uint nbytes)
540 {
541 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
542 	SDIOH_API_RC status;
543 
544 	ASSERT(bcmsdh);
545 	ASSERT(bcmsdh->init_success);
546 	ASSERT((addr & SBSDIO_SBWINDOW_MASK) == 0);
547 
548 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
549 	addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
550 
551 	status =
552 	    sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, SDIOH_DATA_INC,
553 				 (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1,
554 				 addr, 4, nbytes, buf, NULL);
555 
556 	return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR;
557 }
558 
bcmsdh_abort(void * sdh,uint fn)559 int bcmsdh_abort(void *sdh, uint fn)
560 {
561 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
562 
563 	return sdioh_abort(bcmsdh->sdioh, fn);
564 }
565 
bcmsdh_start(void * sdh,int stage)566 int bcmsdh_start(void *sdh, int stage)
567 {
568 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
569 
570 	return sdioh_start(bcmsdh->sdioh, stage);
571 }
572 
bcmsdh_stop(void * sdh)573 int bcmsdh_stop(void *sdh)
574 {
575 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
576 
577 	return sdioh_stop(bcmsdh->sdioh);
578 }
579 
bcmsdh_query_device(void * sdh)580 int bcmsdh_query_device(void *sdh)
581 {
582 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
583 	bcmsdh->vendevid = (VENDOR_BROADCOM << 16) | 0;
584 	return bcmsdh->vendevid;
585 }
586 
bcmsdh_query_iofnum(void * sdh)587 uint bcmsdh_query_iofnum(void *sdh)
588 {
589 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
590 
591 	if (!bcmsdh)
592 		bcmsdh = l_bcmsdh;
593 
594 	return sdioh_query_iofnum(bcmsdh->sdioh);
595 }
596 
bcmsdh_reset(bcmsdh_info_t * sdh)597 int bcmsdh_reset(bcmsdh_info_t *sdh)
598 {
599 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
600 
601 	return sdioh_sdio_reset(bcmsdh->sdioh);
602 }
603 
bcmsdh_get_sdioh(bcmsdh_info_t * sdh)604 void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh)
605 {
606 	ASSERT(sdh);
607 	return sdh->sdioh;
608 }
609 
610 /* Function to pass device-status bits to DHD. */
bcmsdh_get_dstatus(void * sdh)611 u32 bcmsdh_get_dstatus(void *sdh)
612 {
613 	return 0;
614 }
615 
bcmsdh_cur_sbwad(void * sdh)616 u32 bcmsdh_cur_sbwad(void *sdh)
617 {
618 	bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
619 
620 	if (!bcmsdh)
621 		bcmsdh = l_bcmsdh;
622 
623 	return bcmsdh->sbwad;
624 }
625 
bcmsdh_chipinfo(void * sdh,u32 chip,u32 chiprev)626 void bcmsdh_chipinfo(void *sdh, u32 chip, u32 chiprev)
627 {
628 	return;
629 }
630