diff options
Diffstat (limited to 'drivers/mmc/core/sdio.c')
-rw-r--r-- | drivers/mmc/core/sdio.c | 210 |
1 files changed, 168 insertions, 42 deletions
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index b9dee28ee7d0..bd2755e8d9a3 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c | |||
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include "core.h" | 19 | #include "core.h" |
20 | #include "bus.h" | 20 | #include "bus.h" |
21 | #include "sd.h" | ||
21 | #include "sdio_bus.h" | 22 | #include "sdio_bus.h" |
22 | #include "mmc_ops.h" | 23 | #include "mmc_ops.h" |
23 | #include "sd_ops.h" | 24 | #include "sd_ops.h" |
@@ -62,13 +63,19 @@ static int sdio_init_func(struct mmc_card *card, unsigned int fn) | |||
62 | 63 | ||
63 | func->num = fn; | 64 | func->num = fn; |
64 | 65 | ||
65 | ret = sdio_read_fbr(func); | 66 | if (!(card->quirks & MMC_QUIRK_NONSTD_SDIO)) { |
66 | if (ret) | 67 | ret = sdio_read_fbr(func); |
67 | goto fail; | 68 | if (ret) |
69 | goto fail; | ||
68 | 70 | ||
69 | ret = sdio_read_func_cis(func); | 71 | ret = sdio_read_func_cis(func); |
70 | if (ret) | 72 | if (ret) |
71 | goto fail; | 73 | goto fail; |
74 | } else { | ||
75 | func->vendor = func->card->cis.vendor; | ||
76 | func->device = func->card->cis.device; | ||
77 | func->max_blksize = func->card->cis.blksize; | ||
78 | } | ||
72 | 79 | ||
73 | card->sdio_func[fn - 1] = func; | 80 | card->sdio_func[fn - 1] = func; |
74 | 81 | ||
@@ -159,9 +166,7 @@ static int sdio_enable_wide(struct mmc_card *card) | |||
159 | if (ret) | 166 | if (ret) |
160 | return ret; | 167 | return ret; |
161 | 168 | ||
162 | mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); | 169 | return 1; |
163 | |||
164 | return 0; | ||
165 | } | 170 | } |
166 | 171 | ||
167 | /* | 172 | /* |
@@ -221,10 +226,34 @@ static int sdio_disable_wide(struct mmc_card *card) | |||
221 | return 0; | 226 | return 0; |
222 | } | 227 | } |
223 | 228 | ||
229 | |||
230 | static int sdio_enable_4bit_bus(struct mmc_card *card) | ||
231 | { | ||
232 | int err; | ||
233 | |||
234 | if (card->type == MMC_TYPE_SDIO) | ||
235 | return sdio_enable_wide(card); | ||
236 | |||
237 | if ((card->host->caps & MMC_CAP_4_BIT_DATA) && | ||
238 | (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { | ||
239 | err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); | ||
240 | if (err) | ||
241 | return err; | ||
242 | } else | ||
243 | return 0; | ||
244 | |||
245 | err = sdio_enable_wide(card); | ||
246 | if (err <= 0) | ||
247 | mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1); | ||
248 | |||
249 | return err; | ||
250 | } | ||
251 | |||
252 | |||
224 | /* | 253 | /* |
225 | * Test if the card supports high-speed mode and, if so, switch to it. | 254 | * Test if the card supports high-speed mode and, if so, switch to it. |
226 | */ | 255 | */ |
227 | static int sdio_enable_hs(struct mmc_card *card) | 256 | static int mmc_sdio_switch_hs(struct mmc_card *card, int enable) |
228 | { | 257 | { |
229 | int ret; | 258 | int ret; |
230 | u8 speed; | 259 | u8 speed; |
@@ -239,16 +268,56 @@ static int sdio_enable_hs(struct mmc_card *card) | |||
239 | if (ret) | 268 | if (ret) |
240 | return ret; | 269 | return ret; |
241 | 270 | ||
242 | speed |= SDIO_SPEED_EHS; | 271 | if (enable) |
272 | speed |= SDIO_SPEED_EHS; | ||
273 | else | ||
274 | speed &= ~SDIO_SPEED_EHS; | ||
243 | 275 | ||
244 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL); | 276 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL); |
245 | if (ret) | 277 | if (ret) |
246 | return ret; | 278 | return ret; |
247 | 279 | ||
248 | mmc_card_set_highspeed(card); | 280 | return 1; |
249 | mmc_set_timing(card->host, MMC_TIMING_SD_HS); | 281 | } |
250 | 282 | ||
251 | return 0; | 283 | /* |
284 | * Enable SDIO/combo card's high-speed mode. Return 0/1 if [not]supported. | ||
285 | */ | ||
286 | static int sdio_enable_hs(struct mmc_card *card) | ||
287 | { | ||
288 | int ret; | ||
289 | |||
290 | ret = mmc_sdio_switch_hs(card, true); | ||
291 | if (ret <= 0 || card->type == MMC_TYPE_SDIO) | ||
292 | return ret; | ||
293 | |||
294 | ret = mmc_sd_switch_hs(card); | ||
295 | if (ret <= 0) | ||
296 | mmc_sdio_switch_hs(card, false); | ||
297 | |||
298 | return ret; | ||
299 | } | ||
300 | |||
301 | static unsigned mmc_sdio_get_max_clock(struct mmc_card *card) | ||
302 | { | ||
303 | unsigned max_dtr; | ||
304 | |||
305 | if (mmc_card_highspeed(card)) { | ||
306 | /* | ||
307 | * The SDIO specification doesn't mention how | ||
308 | * the CIS transfer speed register relates to | ||
309 | * high-speed, but it seems that 50 MHz is | ||
310 | * mandatory. | ||
311 | */ | ||
312 | max_dtr = 50000000; | ||
313 | } else { | ||
314 | max_dtr = card->cis.max_dtr; | ||
315 | } | ||
316 | |||
317 | if (card->type == MMC_TYPE_SD_COMBO) | ||
318 | max_dtr = min(max_dtr, mmc_sd_get_max_clock(card)); | ||
319 | |||
320 | return max_dtr; | ||
252 | } | 321 | } |
253 | 322 | ||
254 | /* | 323 | /* |
@@ -293,7 +362,24 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
293 | goto err; | 362 | goto err; |
294 | } | 363 | } |
295 | 364 | ||
296 | card->type = MMC_TYPE_SDIO; | 365 | err = mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid); |
366 | |||
367 | if (!err) { | ||
368 | card->type = MMC_TYPE_SD_COMBO; | ||
369 | |||
370 | if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO || | ||
371 | memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) { | ||
372 | mmc_remove_card(card); | ||
373 | return -ENOENT; | ||
374 | } | ||
375 | } else { | ||
376 | card->type = MMC_TYPE_SDIO; | ||
377 | |||
378 | if (oldcard && oldcard->type != MMC_TYPE_SDIO) { | ||
379 | mmc_remove_card(card); | ||
380 | return -ENOENT; | ||
381 | } | ||
382 | } | ||
297 | 383 | ||
298 | /* | 384 | /* |
299 | * Call the optional HC's init_card function to handle quirks. | 385 | * Call the optional HC's init_card function to handle quirks. |
@@ -313,6 +399,17 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
313 | } | 399 | } |
314 | 400 | ||
315 | /* | 401 | /* |
402 | * Read CSD, before selecting the card | ||
403 | */ | ||
404 | if (!oldcard && card->type == MMC_TYPE_SD_COMBO) { | ||
405 | err = mmc_sd_get_csd(host, card); | ||
406 | if (err) | ||
407 | return err; | ||
408 | |||
409 | mmc_decode_cid(card); | ||
410 | } | ||
411 | |||
412 | /* | ||
316 | * Select card, as all following commands rely on that. | 413 | * Select card, as all following commands rely on that. |
317 | */ | 414 | */ |
318 | if (!powered_resume && !mmc_host_is_spi(host)) { | 415 | if (!powered_resume && !mmc_host_is_spi(host)) { |
@@ -321,6 +418,23 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
321 | goto remove; | 418 | goto remove; |
322 | } | 419 | } |
323 | 420 | ||
421 | if (card->quirks & MMC_QUIRK_NONSTD_SDIO) { | ||
422 | /* | ||
423 | * This is non-standard SDIO device, meaning it doesn't | ||
424 | * have any CIA (Common I/O area) registers present. | ||
425 | * It's host's responsibility to fill cccr and cis | ||
426 | * structures in init_card(). | ||
427 | */ | ||
428 | mmc_set_clock(host, card->cis.max_dtr); | ||
429 | |||
430 | if (card->cccr.high_speed) { | ||
431 | mmc_card_set_highspeed(card); | ||
432 | mmc_set_timing(card->host, MMC_TIMING_SD_HS); | ||
433 | } | ||
434 | |||
435 | goto finish; | ||
436 | } | ||
437 | |||
324 | /* | 438 | /* |
325 | * Read the common registers. | 439 | * Read the common registers. |
326 | */ | 440 | */ |
@@ -339,43 +453,57 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
339 | int same = (card->cis.vendor == oldcard->cis.vendor && | 453 | int same = (card->cis.vendor == oldcard->cis.vendor && |
340 | card->cis.device == oldcard->cis.device); | 454 | card->cis.device == oldcard->cis.device); |
341 | mmc_remove_card(card); | 455 | mmc_remove_card(card); |
342 | if (!same) { | 456 | if (!same) |
343 | err = -ENOENT; | 457 | return -ENOENT; |
344 | goto err; | 458 | |
345 | } | ||
346 | card = oldcard; | 459 | card = oldcard; |
347 | return 0; | 460 | return 0; |
348 | } | 461 | } |
349 | 462 | ||
463 | if (card->type == MMC_TYPE_SD_COMBO) { | ||
464 | err = mmc_sd_setup_card(host, card, oldcard != NULL); | ||
465 | /* handle as SDIO-only card if memory init failed */ | ||
466 | if (err) { | ||
467 | mmc_go_idle(host); | ||
468 | if (mmc_host_is_spi(host)) | ||
469 | /* should not fail, as it worked previously */ | ||
470 | mmc_spi_set_crc(host, use_spi_crc); | ||
471 | card->type = MMC_TYPE_SDIO; | ||
472 | } else | ||
473 | card->dev.type = &sd_type; | ||
474 | } | ||
475 | |||
476 | /* | ||
477 | * If needed, disconnect card detection pull-up resistor. | ||
478 | */ | ||
479 | err = sdio_disable_cd(card); | ||
480 | if (err) | ||
481 | goto remove; | ||
482 | |||
350 | /* | 483 | /* |
351 | * Switch to high-speed (if supported). | 484 | * Switch to high-speed (if supported). |
352 | */ | 485 | */ |
353 | err = sdio_enable_hs(card); | 486 | err = sdio_enable_hs(card); |
354 | if (err) | 487 | if (err > 0) |
488 | mmc_sd_go_highspeed(card); | ||
489 | else if (err) | ||
355 | goto remove; | 490 | goto remove; |
356 | 491 | ||
357 | /* | 492 | /* |
358 | * Change to the card's maximum speed. | 493 | * Change to the card's maximum speed. |
359 | */ | 494 | */ |
360 | if (mmc_card_highspeed(card)) { | 495 | mmc_set_clock(host, mmc_sdio_get_max_clock(card)); |
361 | /* | ||
362 | * The SDIO specification doesn't mention how | ||
363 | * the CIS transfer speed register relates to | ||
364 | * high-speed, but it seems that 50 MHz is | ||
365 | * mandatory. | ||
366 | */ | ||
367 | mmc_set_clock(host, 50000000); | ||
368 | } else { | ||
369 | mmc_set_clock(host, card->cis.max_dtr); | ||
370 | } | ||
371 | 496 | ||
372 | /* | 497 | /* |
373 | * Switch to wider bus (if supported). | 498 | * Switch to wider bus (if supported). |
374 | */ | 499 | */ |
375 | err = sdio_enable_wide(card); | 500 | err = sdio_enable_4bit_bus(card); |
376 | if (err) | 501 | if (err > 0) |
502 | mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); | ||
503 | else if (err) | ||
377 | goto remove; | 504 | goto remove; |
378 | 505 | ||
506 | finish: | ||
379 | if (!oldcard) | 507 | if (!oldcard) |
380 | host->card = card; | 508 | host->card = card; |
381 | return 0; | 509 | return 0; |
@@ -487,9 +615,14 @@ static int mmc_sdio_resume(struct mmc_host *host) | |||
487 | mmc_claim_host(host); | 615 | mmc_claim_host(host); |
488 | err = mmc_sdio_init_card(host, host->ocr, host->card, | 616 | err = mmc_sdio_init_card(host, host->ocr, host->card, |
489 | (host->pm_flags & MMC_PM_KEEP_POWER)); | 617 | (host->pm_flags & MMC_PM_KEEP_POWER)); |
490 | if (!err) | 618 | if (!err) { |
491 | /* We may have switched to 1-bit mode during suspend. */ | 619 | /* We may have switched to 1-bit mode during suspend. */ |
492 | err = sdio_enable_wide(host->card); | 620 | err = sdio_enable_4bit_bus(host->card); |
621 | if (err > 0) { | ||
622 | mmc_set_bus_width(host, MMC_BUS_WIDTH_4); | ||
623 | err = 0; | ||
624 | } | ||
625 | } | ||
493 | if (!err && host->sdio_irqs) | 626 | if (!err && host->sdio_irqs) |
494 | mmc_signal_sdio_irq(host); | 627 | mmc_signal_sdio_irq(host); |
495 | mmc_release_host(host); | 628 | mmc_release_host(host); |
@@ -574,13 +707,6 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr) | |||
574 | card->sdio_funcs = 0; | 707 | card->sdio_funcs = 0; |
575 | 708 | ||
576 | /* | 709 | /* |
577 | * If needed, disconnect card detection pull-up resistor. | ||
578 | */ | ||
579 | err = sdio_disable_cd(card); | ||
580 | if (err) | ||
581 | goto remove; | ||
582 | |||
583 | /* | ||
584 | * Initialize (but don't add) all present functions. | 710 | * Initialize (but don't add) all present functions. |
585 | */ | 711 | */ |
586 | for (i = 0; i < funcs; i++, card->sdio_funcs++) { | 712 | for (i = 0; i < funcs; i++, card->sdio_funcs++) { |