Commit | Line | Data |
---|---|---|
cf2b4488 HP |
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 | ||
a1c16ed2 | 18 | #include <linux/types.h> |
c6ac24e9 | 19 | #include <linux/netdevice.h> |
be1c09f9 | 20 | #include <linux/pci_ids.h> |
7c6100ee | 21 | #include <linux/sched.h> |
c4daa849 | 22 | |
cc3cea5a RV |
23 | #include <defs.h> |
24 | #include <brcm_hw_ids.h> | |
f97e956a RV |
25 | #include <brcmu_utils.h> |
26 | #include <brcmu_wifi.h> | |
cc3cea5a | 27 | #include <soc.h> |
c4daa849 RV |
28 | #include "bcmsdbus.h" /* common SDIO/controller interface */ |
29 | #include "sbsdio.h" /* BRCM sdio device core */ | |
13f401cb RV |
30 | #include "dngl_stats.h" |
31 | #include "dhd.h" | |
cf2b4488 HP |
32 | |
33 | #define SDIOH_API_ACCESS_RETRY_LIMIT 2 | |
34 | const uint bcmsdh_msglevel = BCMSDH_ERROR_VAL; | |
35 | ||
677226aa | 36 | struct brcmf_sdio { |
cf2b4488 HP |
37 | bool init_success; /* underlying driver successfully attached */ |
38 | void *sdioh; /* handler for sdioh */ | |
66cbd3ab | 39 | u32 vendevid; /* Target Vendor and Device ID on SD bus */ |
cf2b4488 HP |
40 | bool regfail; /* Save status of last |
41 | reg_read/reg_write call */ | |
66cbd3ab | 42 | u32 sbwad; /* Save backplane window address */ |
cf2b4488 HP |
43 | }; |
44 | /* local copy of bcm sd handler */ | |
677226aa | 45 | struct brcmf_sdio *l_bcmsdh; |
cf2b4488 | 46 | |
677226aa | 47 | struct brcmf_sdio *brcmf_sdcard_attach(void *cfghdl, void **regsva, uint irq) |
cf2b4488 | 48 | { |
677226aa | 49 | struct brcmf_sdio *bcmsdh; |
cf2b4488 | 50 | |
677226aa | 51 | bcmsdh = kzalloc(sizeof(struct brcmf_sdio), GFP_ATOMIC); |
c74c95cd | 52 | if (bcmsdh == NULL) { |
97e17d0e | 53 | BCMSDH_ERROR(("bcmsdh_attach: out of memory")); |
cf2b4488 HP |
54 | return NULL; |
55 | } | |
cf2b4488 HP |
56 | |
57 | /* save the handler locally */ | |
58 | l_bcmsdh = bcmsdh; | |
59 | ||
54ca2969 | 60 | bcmsdh->sdioh = brcmf_sdioh_attach(cfghdl, irq); |
c74c95cd | 61 | if (!bcmsdh->sdioh) { |
54ca2969 | 62 | brcmf_sdcard_detach(bcmsdh); |
cf2b4488 HP |
63 | return NULL; |
64 | } | |
65 | ||
0f0881b0 | 66 | bcmsdh->init_success = true; |
cf2b4488 | 67 | |
66cbd3ab | 68 | *regsva = (u32 *) SI_ENUM_BASE; |
cf2b4488 HP |
69 | |
70 | /* Report the BAR, to fix if needed */ | |
71 | bcmsdh->sbwad = SI_ENUM_BASE; | |
72 | return bcmsdh; | |
73 | } | |
74 | ||
54ca2969 | 75 | int brcmf_sdcard_detach(void *sdh) |
cf2b4488 | 76 | { |
677226aa | 77 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
78 | |
79 | if (bcmsdh != NULL) { | |
80 | if (bcmsdh->sdioh) { | |
54ca2969 | 81 | brcmf_sdioh_detach(bcmsdh->sdioh); |
cf2b4488 HP |
82 | bcmsdh->sdioh = NULL; |
83 | } | |
182acb3c | 84 | kfree(bcmsdh); |
cf2b4488 HP |
85 | } |
86 | ||
87 | l_bcmsdh = NULL; | |
88 | return 0; | |
89 | } | |
90 | ||
91 | int | |
54ca2969 | 92 | brcmf_sdcard_iovar_op(void *sdh, const char *name, |
cf2b4488 HP |
93 | void *params, int plen, void *arg, int len, bool set) |
94 | { | |
677226aa | 95 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
54ca2969 RV |
96 | return brcmf_sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, |
97 | len, set); | |
cf2b4488 HP |
98 | } |
99 | ||
54ca2969 | 100 | bool brcmf_sdcard_intr_query(void *sdh) |
cf2b4488 | 101 | { |
677226aa | 102 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
3c793822 | 103 | int status; |
cf2b4488 HP |
104 | bool on; |
105 | ||
106 | ASSERT(bcmsdh); | |
54ca2969 | 107 | status = brcmf_sdioh_interrupt_query(bcmsdh->sdioh, &on); |
67f72bef | 108 | if (status == 0) |
0965ae88 | 109 | return false; |
cf2b4488 HP |
110 | else |
111 | return on; | |
112 | } | |
113 | ||
54ca2969 | 114 | int brcmf_sdcard_intr_enable(void *sdh) |
cf2b4488 | 115 | { |
677226aa | 116 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
117 | ASSERT(bcmsdh); |
118 | ||
67f72bef | 119 | return brcmf_sdioh_interrupt_set(bcmsdh->sdioh, true); |
cf2b4488 HP |
120 | } |
121 | ||
54ca2969 | 122 | int brcmf_sdcard_intr_disable(void *sdh) |
cf2b4488 | 123 | { |
677226aa | 124 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
125 | ASSERT(bcmsdh); |
126 | ||
67f72bef | 127 | return brcmf_sdioh_interrupt_set(bcmsdh->sdioh, false); |
cf2b4488 HP |
128 | } |
129 | ||
54ca2969 | 130 | int brcmf_sdcard_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
cf2b4488 | 131 | { |
677226aa | 132 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
133 | ASSERT(bcmsdh); |
134 | ||
67f72bef | 135 | return brcmf_sdioh_interrupt_register(bcmsdh->sdioh, fn, argh); |
cf2b4488 HP |
136 | } |
137 | ||
54ca2969 | 138 | int brcmf_sdcard_intr_dereg(void *sdh) |
cf2b4488 | 139 | { |
677226aa | 140 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
141 | ASSERT(bcmsdh); |
142 | ||
67f72bef | 143 | return brcmf_sdioh_interrupt_deregister(bcmsdh->sdioh); |
cf2b4488 HP |
144 | } |
145 | ||
762c2a36 | 146 | #if defined(BCMDBG) |
54ca2969 | 147 | bool brcmf_sdcard_intr_pending(void *sdh) |
cf2b4488 | 148 | { |
677226aa | 149 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
150 | |
151 | ASSERT(sdh); | |
54ca2969 | 152 | return brcmf_sdioh_interrupt_pending(bcmsdh->sdioh); |
cf2b4488 HP |
153 | } |
154 | #endif | |
155 | ||
54ca2969 | 156 | int brcmf_sdcard_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
cf2b4488 HP |
157 | { |
158 | ASSERT(sdh); | |
159 | ||
160 | /* don't support yet */ | |
e10d82d4 | 161 | return -ENOTSUPP; |
cf2b4488 HP |
162 | } |
163 | ||
54ca2969 | 164 | u8 brcmf_sdcard_cfg_read(void *sdh, uint fnc_num, u32 addr, int *err) |
cf2b4488 | 165 | { |
677226aa | 166 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
3c793822 | 167 | int status; |
cf2b4488 | 168 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
3e26416e | 169 | s32 retry = 0; |
cf2b4488 | 170 | #endif |
3fd79f7c | 171 | u8 data = 0; |
cf2b4488 HP |
172 | |
173 | if (!bcmsdh) | |
174 | bcmsdh = l_bcmsdh; | |
175 | ||
176 | ASSERT(bcmsdh->init_success); | |
177 | ||
178 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT | |
179 | do { | |
180 | if (retry) /* wait for 1 ms till bus get settled down */ | |
7383141b | 181 | udelay(1000); |
cf2b4488 HP |
182 | #endif |
183 | status = | |
54ca2969 | 184 | brcmf_sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr, |
3fd79f7c | 185 | (u8 *) &data); |
cf2b4488 | 186 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
67f72bef | 187 | } while (status != 0 |
cf2b4488 HP |
188 | && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
189 | #endif | |
190 | if (err) | |
67f72bef | 191 | *err = status; |
cf2b4488 | 192 | |
3fd79f7c | 193 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n", |
cf2b4488 HP |
194 | __func__, fnc_num, addr, data)); |
195 | ||
196 | return data; | |
197 | } | |
198 | ||
199 | void | |
54ca2969 | 200 | brcmf_sdcard_cfg_write(void *sdh, uint fnc_num, u32 addr, u8 data, int *err) |
cf2b4488 | 201 | { |
677226aa | 202 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
3c793822 | 203 | int status; |
cf2b4488 | 204 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
3e26416e | 205 | s32 retry = 0; |
cf2b4488 HP |
206 | #endif |
207 | ||
208 | if (!bcmsdh) | |
209 | bcmsdh = l_bcmsdh; | |
210 | ||
211 | ASSERT(bcmsdh->init_success); | |
212 | ||
213 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT | |
214 | do { | |
215 | if (retry) /* wait for 1 ms till bus get settled down */ | |
7383141b | 216 | udelay(1000); |
cf2b4488 HP |
217 | #endif |
218 | status = | |
54ca2969 | 219 | brcmf_sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr, |
3fd79f7c | 220 | (u8 *) &data); |
cf2b4488 | 221 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
67f72bef | 222 | } while (status != 0 |
cf2b4488 HP |
223 | && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
224 | #endif | |
225 | if (err) | |
67f72bef | 226 | *err = status; |
cf2b4488 | 227 | |
3fd79f7c | 228 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n", |
cf2b4488 HP |
229 | __func__, fnc_num, addr, data)); |
230 | } | |
231 | ||
54ca2969 | 232 | u32 brcmf_sdcard_cfg_read_word(void *sdh, uint fnc_num, u32 addr, int *err) |
cf2b4488 | 233 | { |
677226aa | 234 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
3c793822 | 235 | int status; |
66cbd3ab | 236 | u32 data = 0; |
cf2b4488 HP |
237 | |
238 | if (!bcmsdh) | |
239 | bcmsdh = l_bcmsdh; | |
240 | ||
241 | ASSERT(bcmsdh->init_success); | |
242 | ||
54ca2969 RV |
243 | status = brcmf_sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
244 | SDIOH_READ, fnc_num, addr, &data, 4); | |
cf2b4488 HP |
245 | |
246 | if (err) | |
67f72bef | 247 | *err = status; |
cf2b4488 | 248 | |
66cbd3ab | 249 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u32data = 0x%x\n", |
cf2b4488 HP |
250 | __func__, fnc_num, addr, data)); |
251 | ||
252 | return data; | |
253 | } | |
254 | ||
255 | void | |
54ca2969 | 256 | brcmf_sdcard_cfg_write_word(void *sdh, uint fnc_num, u32 addr, u32 data, |
cf2b4488 HP |
257 | int *err) |
258 | { | |
677226aa | 259 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
3c793822 | 260 | int status; |
cf2b4488 HP |
261 | |
262 | if (!bcmsdh) | |
263 | bcmsdh = l_bcmsdh; | |
264 | ||
265 | ASSERT(bcmsdh->init_success); | |
266 | ||
267 | status = | |
54ca2969 | 268 | brcmf_sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
cf2b4488 HP |
269 | SDIOH_WRITE, fnc_num, addr, &data, 4); |
270 | ||
271 | if (err) | |
67f72bef | 272 | *err = status; |
cf2b4488 | 273 | |
66cbd3ab | 274 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u32data = 0x%x\n", |
cf2b4488 HP |
275 | __func__, fnc_num, addr, data)); |
276 | } | |
277 | ||
54ca2969 | 278 | int brcmf_sdcard_cis_read(void *sdh, uint func, u8 * cis, uint length) |
cf2b4488 | 279 | { |
677226aa | 280 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
3c793822 | 281 | int status; |
cf2b4488 | 282 | |
3fd79f7c GKH |
283 | u8 *tmp_buf, *tmp_ptr; |
284 | u8 *ptr; | |
cf2b4488 HP |
285 | bool ascii = func & ~0xf; |
286 | func &= 0x7; | |
287 | ||
288 | if (!bcmsdh) | |
289 | bcmsdh = l_bcmsdh; | |
290 | ||
291 | ASSERT(bcmsdh->init_success); | |
292 | ASSERT(cis); | |
293 | ASSERT(length <= SBSDIO_CIS_SIZE_LIMIT); | |
294 | ||
54ca2969 | 295 | status = brcmf_sdioh_cis_read(bcmsdh->sdioh, func, cis, length); |
cf2b4488 HP |
296 | |
297 | if (ascii) { | |
298 | /* Move binary bits to tmp and format them | |
299 | into the provided buffer. */ | |
5fcc1fcb | 300 | tmp_buf = kmalloc(length, GFP_ATOMIC); |
c74c95cd | 301 | if (tmp_buf == NULL) { |
cf2b4488 | 302 | BCMSDH_ERROR(("%s: out of memory\n", __func__)); |
e10d82d4 | 303 | return -ENOMEM; |
cf2b4488 | 304 | } |
02160695 | 305 | memcpy(tmp_buf, cis, length); |
cf2b4488 HP |
306 | for (tmp_ptr = tmp_buf, ptr = cis; ptr < (cis + length - 4); |
307 | tmp_ptr++) { | |
308 | ptr += sprintf((char *)ptr, "%.2x ", *tmp_ptr & 0xff); | |
309 | if ((((tmp_ptr - tmp_buf) + 1) & 0xf) == 0) | |
310 | ptr += sprintf((char *)ptr, "\n"); | |
311 | } | |
182acb3c | 312 | kfree(tmp_buf); |
cf2b4488 HP |
313 | } |
314 | ||
67f72bef | 315 | return status; |
cf2b4488 HP |
316 | } |
317 | ||
54ca2969 | 318 | static int brcmf_sdcard_set_sbaddr_window(void *sdh, u32 address) |
cf2b4488 HP |
319 | { |
320 | int err = 0; | |
677226aa | 321 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
54ca2969 | 322 | brcmf_sdcard_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
cf2b4488 HP |
323 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
324 | if (!err) | |
54ca2969 RV |
325 | brcmf_sdcard_cfg_write(bcmsdh, SDIO_FUNC_1, |
326 | SBSDIO_FUNC1_SBADDRMID, | |
327 | (address >> 16) & SBSDIO_SBADDRMID_MASK, | |
328 | &err); | |
cf2b4488 | 329 | if (!err) |
54ca2969 RV |
330 | brcmf_sdcard_cfg_write(bcmsdh, SDIO_FUNC_1, |
331 | SBSDIO_FUNC1_SBADDRHIGH, | |
332 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, | |
333 | &err); | |
cf2b4488 HP |
334 | |
335 | return err; | |
336 | } | |
337 | ||
54ca2969 | 338 | u32 brcmf_sdcard_reg_read(void *sdh, u32 addr, uint size) |
cf2b4488 | 339 | { |
677226aa | 340 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
3c793822 | 341 | int status; |
66cbd3ab | 342 | u32 word = 0; |
cf2b4488 HP |
343 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
344 | ||
345 | BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, ", __func__, addr)); | |
346 | ||
347 | if (!bcmsdh) | |
348 | bcmsdh = l_bcmsdh; | |
349 | ||
350 | ASSERT(bcmsdh->init_success); | |
351 | ||
352 | if (bar0 != bcmsdh->sbwad) { | |
54ca2969 | 353 | if (brcmf_sdcard_set_sbaddr_window(bcmsdh, bar0)) |
cf2b4488 HP |
354 | return 0xFFFFFFFF; |
355 | ||
356 | bcmsdh->sbwad = bar0; | |
357 | } | |
358 | ||
359 | addr &= SBSDIO_SB_OFT_ADDR_MASK; | |
360 | if (size == 4) | |
361 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; | |
362 | ||
54ca2969 | 363 | status = brcmf_sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
cf2b4488 HP |
364 | SDIOH_READ, SDIO_FUNC_1, addr, &word, size); |
365 | ||
67f72bef | 366 | bcmsdh->regfail = (status != 0); |
cf2b4488 | 367 | |
66cbd3ab | 368 | BCMSDH_INFO(("u32data = 0x%x\n", word)); |
cf2b4488 HP |
369 | |
370 | /* if ok, return appropriately masked word */ | |
67f72bef | 371 | if (status == 0) { |
cf2b4488 | 372 | switch (size) { |
3fd79f7c | 373 | case sizeof(u8): |
cf2b4488 | 374 | return word & 0xff; |
7d4df48e | 375 | case sizeof(u16): |
cf2b4488 | 376 | return word & 0xffff; |
66cbd3ab | 377 | case sizeof(u32): |
cf2b4488 HP |
378 | return word; |
379 | default: | |
0f0881b0 | 380 | bcmsdh->regfail = true; |
cf2b4488 HP |
381 | |
382 | } | |
383 | } | |
384 | ||
385 | /* otherwise, bad sdio access or invalid size */ | |
386 | BCMSDH_ERROR(("%s: error reading addr 0x%04x size %d\n", __func__, | |
387 | addr, size)); | |
388 | return 0xFFFFFFFF; | |
389 | } | |
390 | ||
54ca2969 | 391 | u32 brcmf_sdcard_reg_write(void *sdh, u32 addr, uint size, u32 data) |
cf2b4488 | 392 | { |
677226aa | 393 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
3c793822 | 394 | int status; |
cf2b4488 HP |
395 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
396 | int err = 0; | |
397 | ||
398 | BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n", | |
399 | __func__, addr, size * 8, data)); | |
400 | ||
401 | if (!bcmsdh) | |
402 | bcmsdh = l_bcmsdh; | |
403 | ||
404 | ASSERT(bcmsdh->init_success); | |
405 | ||
406 | if (bar0 != bcmsdh->sbwad) { | |
54ca2969 | 407 | err = brcmf_sdcard_set_sbaddr_window(bcmsdh, bar0); |
c74c95cd | 408 | if (err) |
cf2b4488 HP |
409 | return err; |
410 | ||
411 | bcmsdh->sbwad = bar0; | |
412 | } | |
413 | ||
414 | addr &= SBSDIO_SB_OFT_ADDR_MASK; | |
415 | if (size == 4) | |
416 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; | |
417 | status = | |
54ca2969 | 418 | brcmf_sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
cf2b4488 | 419 | SDIOH_WRITE, SDIO_FUNC_1, addr, &data, size); |
67f72bef | 420 | bcmsdh->regfail = (status != 0); |
cf2b4488 | 421 | |
67f72bef | 422 | if (status == 0) |
cf2b4488 HP |
423 | return 0; |
424 | ||
425 | BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n", | |
426 | __func__, data, addr, size)); | |
427 | return 0xFFFFFFFF; | |
428 | } | |
429 | ||
54ca2969 | 430 | bool brcmf_sdcard_regfail(void *sdh) |
cf2b4488 | 431 | { |
677226aa | 432 | return ((struct brcmf_sdio *) sdh)->regfail; |
cf2b4488 HP |
433 | } |
434 | ||
435 | int | |
677226aa | 436 | brcmf_sdcard_recv_buf(struct brcmf_sdio *bcmsdh, u32 addr, uint fn, uint flags, |
c26b1378 | 437 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
cf2b4488 HP |
438 | bcmsdh_cmplt_fn_t complete, void *handle) |
439 | { | |
3c793822 | 440 | int status; |
cf2b4488 HP |
441 | uint incr_fix; |
442 | uint width; | |
443 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; | |
444 | int err = 0; | |
445 | ||
446 | ASSERT(bcmsdh); | |
447 | ASSERT(bcmsdh->init_success); | |
448 | ||
449 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", | |
450 | __func__, fn, addr, nbytes)); | |
451 | ||
452 | /* Async not implemented yet */ | |
453 | ASSERT(!(flags & SDIO_REQ_ASYNC)); | |
454 | if (flags & SDIO_REQ_ASYNC) | |
e10d82d4 | 455 | return -ENOTSUPP; |
cf2b4488 HP |
456 | |
457 | if (bar0 != bcmsdh->sbwad) { | |
54ca2969 | 458 | err = brcmf_sdcard_set_sbaddr_window(bcmsdh, bar0); |
c74c95cd | 459 | if (err) |
cf2b4488 HP |
460 | return err; |
461 | ||
462 | bcmsdh->sbwad = bar0; | |
463 | } | |
464 | ||
465 | addr &= SBSDIO_SB_OFT_ADDR_MASK; | |
466 | ||
467 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; | |
468 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; | |
469 | if (width == 4) | |
470 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; | |
471 | ||
54ca2969 RV |
472 | status = brcmf_sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, |
473 | incr_fix, SDIOH_READ, fn, addr, width, nbytes, buf, pkt); | |
cf2b4488 | 474 | |
67f72bef | 475 | return status; |
cf2b4488 HP |
476 | } |
477 | ||
478 | int | |
54ca2969 | 479 | brcmf_sdcard_send_buf(void *sdh, u32 addr, uint fn, uint flags, |
3fd79f7c | 480 | u8 *buf, uint nbytes, void *pkt, |
cf2b4488 HP |
481 | bcmsdh_cmplt_fn_t complete, void *handle) |
482 | { | |
677226aa | 483 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
484 | uint incr_fix; |
485 | uint width; | |
486 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; | |
487 | int err = 0; | |
488 | ||
489 | ASSERT(bcmsdh); | |
490 | ASSERT(bcmsdh->init_success); | |
491 | ||
492 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", | |
493 | __func__, fn, addr, nbytes)); | |
494 | ||
495 | /* Async not implemented yet */ | |
496 | ASSERT(!(flags & SDIO_REQ_ASYNC)); | |
497 | if (flags & SDIO_REQ_ASYNC) | |
e10d82d4 | 498 | return -ENOTSUPP; |
cf2b4488 HP |
499 | |
500 | if (bar0 != bcmsdh->sbwad) { | |
54ca2969 | 501 | err = brcmf_sdcard_set_sbaddr_window(bcmsdh, bar0); |
c74c95cd | 502 | if (err) |
cf2b4488 HP |
503 | return err; |
504 | ||
505 | bcmsdh->sbwad = bar0; | |
506 | } | |
507 | ||
508 | addr &= SBSDIO_SB_OFT_ADDR_MASK; | |
509 | ||
510 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; | |
511 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; | |
512 | if (width == 4) | |
513 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; | |
514 | ||
67f72bef | 515 | return brcmf_sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, |
54ca2969 | 516 | incr_fix, SDIOH_WRITE, fn, addr, width, nbytes, buf, pkt); |
cf2b4488 HP |
517 | } |
518 | ||
54ca2969 | 519 | int brcmf_sdcard_rwdata(void *sdh, uint rw, u32 addr, u8 *buf, uint nbytes) |
cf2b4488 | 520 | { |
677226aa | 521 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
522 | |
523 | ASSERT(bcmsdh); | |
524 | ASSERT(bcmsdh->init_success); | |
525 | ASSERT((addr & SBSDIO_SBWINDOW_MASK) == 0); | |
526 | ||
527 | addr &= SBSDIO_SB_OFT_ADDR_MASK; | |
528 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; | |
529 | ||
67f72bef | 530 | return brcmf_sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, |
54ca2969 RV |
531 | SDIOH_DATA_INC, (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1, |
532 | addr, 4, nbytes, buf, NULL); | |
cf2b4488 HP |
533 | } |
534 | ||
54ca2969 | 535 | int brcmf_sdcard_abort(void *sdh, uint fn) |
cf2b4488 | 536 | { |
677226aa | 537 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 | 538 | |
54ca2969 | 539 | return brcmf_sdioh_abort(bcmsdh->sdioh, fn); |
cf2b4488 HP |
540 | } |
541 | ||
54ca2969 | 542 | int brcmf_sdcard_start(void *sdh, int stage) |
cf2b4488 | 543 | { |
677226aa | 544 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 | 545 | |
54ca2969 | 546 | return brcmf_sdioh_start(bcmsdh->sdioh, stage); |
cf2b4488 HP |
547 | } |
548 | ||
54ca2969 | 549 | int brcmf_sdcard_stop(void *sdh) |
cf2b4488 | 550 | { |
677226aa | 551 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 | 552 | |
54ca2969 | 553 | return brcmf_sdioh_stop(bcmsdh->sdioh); |
cf2b4488 HP |
554 | } |
555 | ||
54ca2969 | 556 | int brcmf_sdcard_query_device(void *sdh) |
cf2b4488 | 557 | { |
677226aa | 558 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
be1c09f9 | 559 | bcmsdh->vendevid = (PCI_VENDOR_ID_BROADCOM << 16) | 0; |
cf2b4488 HP |
560 | return bcmsdh->vendevid; |
561 | } | |
562 | ||
54ca2969 | 563 | uint brcmf_sdcard_query_iofnum(void *sdh) |
cf2b4488 | 564 | { |
677226aa | 565 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
566 | |
567 | if (!bcmsdh) | |
568 | bcmsdh = l_bcmsdh; | |
569 | ||
54ca2969 | 570 | return brcmf_sdioh_query_iofnum(bcmsdh->sdioh); |
cf2b4488 HP |
571 | } |
572 | ||
677226aa | 573 | int brcmf_sdcard_reset(struct brcmf_sdio *sdh) |
cf2b4488 | 574 | { |
677226aa | 575 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 | 576 | |
54ca2969 | 577 | return brcmf_sdioh_reset(bcmsdh->sdioh); |
cf2b4488 HP |
578 | } |
579 | ||
677226aa | 580 | void *brcmf_sdcard_get_sdioh(struct brcmf_sdio *sdh) |
cf2b4488 HP |
581 | { |
582 | ASSERT(sdh); | |
583 | return sdh->sdioh; | |
584 | } | |
585 | ||
586 | /* Function to pass device-status bits to DHD. */ | |
54ca2969 | 587 | u32 brcmf_sdcard_get_dstatus(void *sdh) |
cf2b4488 HP |
588 | { |
589 | return 0; | |
590 | } | |
591 | ||
54ca2969 | 592 | u32 brcmf_sdcard_cur_sbwad(void *sdh) |
cf2b4488 | 593 | { |
677226aa | 594 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
cf2b4488 HP |
595 | |
596 | if (!bcmsdh) | |
597 | bcmsdh = l_bcmsdh; | |
598 | ||
599 | return bcmsdh->sbwad; | |
600 | } | |
601 | ||
54ca2969 | 602 | void brcmf_sdcard_chipinfo(void *sdh, u32 chip, u32 chiprev) |
cf2b4488 HP |
603 | { |
604 | return; | |
605 | } |