diff options
Diffstat (limited to 'drivers/mmc/host/mmci.c')
-rw-r--r-- | drivers/mmc/host/mmci.c | 111 |
1 files changed, 86 insertions, 25 deletions
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 8741d0f5146a..705a5894a6bb 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c | |||
@@ -22,12 +22,13 @@ | |||
22 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
23 | #include <linux/scatterlist.h> | 23 | #include <linux/scatterlist.h> |
24 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
25 | #include <linux/amba/mmci.h> | ||
26 | #include <linux/regulator/consumer.h> | ||
25 | 27 | ||
26 | #include <asm/cacheflush.h> | 28 | #include <asm/cacheflush.h> |
27 | #include <asm/div64.h> | 29 | #include <asm/div64.h> |
28 | #include <asm/io.h> | 30 | #include <asm/io.h> |
29 | #include <asm/sizes.h> | 31 | #include <asm/sizes.h> |
30 | #include <asm/mach/mmc.h> | ||
31 | 32 | ||
32 | #include "mmci.h" | 33 | #include "mmci.h" |
33 | 34 | ||
@@ -38,6 +39,36 @@ | |||
38 | 39 | ||
39 | static unsigned int fmax = 515633; | 40 | static unsigned int fmax = 515633; |
40 | 41 | ||
42 | /* | ||
43 | * This must be called with host->lock held | ||
44 | */ | ||
45 | static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) | ||
46 | { | ||
47 | u32 clk = 0; | ||
48 | |||
49 | if (desired) { | ||
50 | if (desired >= host->mclk) { | ||
51 | clk = MCI_CLK_BYPASS; | ||
52 | host->cclk = host->mclk; | ||
53 | } else { | ||
54 | clk = host->mclk / (2 * desired) - 1; | ||
55 | if (clk >= 256) | ||
56 | clk = 255; | ||
57 | host->cclk = host->mclk / (2 * (clk + 1)); | ||
58 | } | ||
59 | if (host->hw_designer == 0x80) | ||
60 | clk |= MCI_FCEN; /* Bug fix in ST IP block */ | ||
61 | clk |= MCI_CLK_ENABLE; | ||
62 | /* This hasn't proven to be worthwhile */ | ||
63 | /* clk |= MCI_CLK_PWRSAVE; */ | ||
64 | } | ||
65 | |||
66 | if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4) | ||
67 | clk |= MCI_WIDE_BUS; | ||
68 | |||
69 | writel(clk, host->base + MMCICLOCK); | ||
70 | } | ||
71 | |||
41 | static void | 72 | static void |
42 | mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) | 73 | mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) |
43 | { | 74 | { |
@@ -419,30 +450,31 @@ static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
419 | static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | 450 | static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
420 | { | 451 | { |
421 | struct mmci_host *host = mmc_priv(mmc); | 452 | struct mmci_host *host = mmc_priv(mmc); |
422 | u32 clk = 0, pwr = 0; | 453 | u32 pwr = 0; |
423 | 454 | unsigned long flags; | |
424 | if (ios->clock) { | ||
425 | if (ios->clock >= host->mclk) { | ||
426 | clk = MCI_CLK_BYPASS; | ||
427 | host->cclk = host->mclk; | ||
428 | } else { | ||
429 | clk = host->mclk / (2 * ios->clock) - 1; | ||
430 | if (clk >= 256) | ||
431 | clk = 255; | ||
432 | host->cclk = host->mclk / (2 * (clk + 1)); | ||
433 | } | ||
434 | if (host->hw_designer == AMBA_VENDOR_ST) | ||
435 | clk |= MCI_FCEN; /* Bug fix in ST IP block */ | ||
436 | clk |= MCI_CLK_ENABLE; | ||
437 | } | ||
438 | |||
439 | if (host->plat->translate_vdd) | ||
440 | pwr |= host->plat->translate_vdd(mmc_dev(mmc), ios->vdd); | ||
441 | 455 | ||
442 | switch (ios->power_mode) { | 456 | switch (ios->power_mode) { |
443 | case MMC_POWER_OFF: | 457 | case MMC_POWER_OFF: |
458 | if(host->vcc && | ||
459 | regulator_is_enabled(host->vcc)) | ||
460 | regulator_disable(host->vcc); | ||
444 | break; | 461 | break; |
445 | case MMC_POWER_UP: | 462 | case MMC_POWER_UP: |
463 | #ifdef CONFIG_REGULATOR | ||
464 | if (host->vcc) | ||
465 | /* This implicitly enables the regulator */ | ||
466 | mmc_regulator_set_ocr(host->vcc, ios->vdd); | ||
467 | #endif | ||
468 | /* | ||
469 | * The translate_vdd function is not used if you have | ||
470 | * an external regulator, or your design is really weird. | ||
471 | * Using it would mean sending in power control BOTH using | ||
472 | * a regulator AND the 4 MMCIPWR bits. If we don't have | ||
473 | * a regulator, we might have some other platform specific | ||
474 | * power control behind this translate function. | ||
475 | */ | ||
476 | if (!host->vcc && host->plat->translate_vdd) | ||
477 | pwr |= host->plat->translate_vdd(mmc_dev(mmc), ios->vdd); | ||
446 | /* The ST version does not have this, fall through to POWER_ON */ | 478 | /* The ST version does not have this, fall through to POWER_ON */ |
447 | if (host->hw_designer != AMBA_VENDOR_ST) { | 479 | if (host->hw_designer != AMBA_VENDOR_ST) { |
448 | pwr |= MCI_PWR_UP; | 480 | pwr |= MCI_PWR_UP; |
@@ -465,12 +497,16 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
465 | } | 497 | } |
466 | } | 498 | } |
467 | 499 | ||
468 | writel(clk, host->base + MMCICLOCK); | 500 | spin_lock_irqsave(&host->lock, flags); |
501 | |||
502 | mmci_set_clkreg(host, ios->clock); | ||
469 | 503 | ||
470 | if (host->pwr != pwr) { | 504 | if (host->pwr != pwr) { |
471 | host->pwr = pwr; | 505 | host->pwr = pwr; |
472 | writel(pwr, host->base + MMCIPOWER); | 506 | writel(pwr, host->base + MMCIPOWER); |
473 | } | 507 | } |
508 | |||
509 | spin_unlock_irqrestore(&host->lock, flags); | ||
474 | } | 510 | } |
475 | 511 | ||
476 | static int mmci_get_ro(struct mmc_host *mmc) | 512 | static int mmci_get_ro(struct mmc_host *mmc) |
@@ -517,7 +553,7 @@ static void mmci_check_status(unsigned long data) | |||
517 | 553 | ||
518 | static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | 554 | static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) |
519 | { | 555 | { |
520 | struct mmc_platform_data *plat = dev->dev.platform_data; | 556 | struct mmci_platform_data *plat = dev->dev.platform_data; |
521 | struct mmci_host *host; | 557 | struct mmci_host *host; |
522 | struct mmc_host *mmc; | 558 | struct mmc_host *mmc; |
523 | int ret; | 559 | int ret; |
@@ -583,7 +619,30 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | |||
583 | mmc->ops = &mmci_ops; | 619 | mmc->ops = &mmci_ops; |
584 | mmc->f_min = (host->mclk + 511) / 512; | 620 | mmc->f_min = (host->mclk + 511) / 512; |
585 | mmc->f_max = min(host->mclk, fmax); | 621 | mmc->f_max = min(host->mclk, fmax); |
586 | mmc->ocr_avail = plat->ocr_mask; | 622 | #ifdef CONFIG_REGULATOR |
623 | /* If we're using the regulator framework, try to fetch a regulator */ | ||
624 | host->vcc = regulator_get(&dev->dev, "vmmc"); | ||
625 | if (IS_ERR(host->vcc)) | ||
626 | host->vcc = NULL; | ||
627 | else { | ||
628 | int mask = mmc_regulator_get_ocrmask(host->vcc); | ||
629 | |||
630 | if (mask < 0) | ||
631 | dev_err(&dev->dev, "error getting OCR mask (%d)\n", | ||
632 | mask); | ||
633 | else { | ||
634 | host->mmc->ocr_avail = (u32) mask; | ||
635 | if (plat->ocr_mask) | ||
636 | dev_warn(&dev->dev, | ||
637 | "Provided ocr_mask/setpower will not be used " | ||
638 | "(using regulator instead)\n"); | ||
639 | } | ||
640 | } | ||
641 | #endif | ||
642 | /* Fall back to platform data if no regulator is found */ | ||
643 | if (host->vcc == NULL) | ||
644 | mmc->ocr_avail = plat->ocr_mask; | ||
645 | mmc->caps = plat->capabilities; | ||
587 | 646 | ||
588 | /* | 647 | /* |
589 | * We can do SGIO | 648 | * We can do SGIO |
@@ -619,7 +678,6 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | |||
619 | writel(0, host->base + MMCIMASK1); | 678 | writel(0, host->base + MMCIMASK1); |
620 | writel(0xfff, host->base + MMCICLEAR); | 679 | writel(0xfff, host->base + MMCICLEAR); |
621 | 680 | ||
622 | #ifdef CONFIG_GPIOLIB | ||
623 | if (gpio_is_valid(plat->gpio_cd)) { | 681 | if (gpio_is_valid(plat->gpio_cd)) { |
624 | ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)"); | 682 | ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)"); |
625 | if (ret == 0) | 683 | if (ret == 0) |
@@ -638,7 +696,6 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) | |||
638 | else if (ret != -ENOSYS) | 696 | else if (ret != -ENOSYS) |
639 | goto err_gpio_wp; | 697 | goto err_gpio_wp; |
640 | } | 698 | } |
641 | #endif | ||
642 | 699 | ||
643 | ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host); | 700 | ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host); |
644 | if (ret) | 701 | if (ret) |
@@ -720,6 +777,10 @@ static int __devexit mmci_remove(struct amba_device *dev) | |||
720 | clk_disable(host->clk); | 777 | clk_disable(host->clk); |
721 | clk_put(host->clk); | 778 | clk_put(host->clk); |
722 | 779 | ||
780 | if (regulator_is_enabled(host->vcc)) | ||
781 | regulator_disable(host->vcc); | ||
782 | regulator_put(host->vcc); | ||
783 | |||
723 | mmc_free_host(mmc); | 784 | mmc_free_host(mmc); |
724 | 785 | ||
725 | amba_release_regions(dev); | 786 | amba_release_regions(dev); |