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