aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/mmci.c73
-rw-r--r--drivers/mmc/host/mmci.h2
2 files changed, 69 insertions, 6 deletions
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index e1aa8471ab1c..a923ee27c09e 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -21,6 +21,7 @@
21#include <linux/amba/bus.h> 21#include <linux/amba/bus.h>
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 25
25#include <asm/cacheflush.h> 26#include <asm/cacheflush.h>
26#include <asm/div64.h> 27#include <asm/div64.h>
@@ -472,17 +473,41 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
472 } 473 }
473} 474}
474 475
476static int mmci_get_ro(struct mmc_host *mmc)
477{
478 struct mmci_host *host = mmc_priv(mmc);
479
480 if (host->gpio_wp == -ENOSYS)
481 return -ENOSYS;
482
483 return gpio_get_value(host->gpio_wp);
484}
485
486static int mmci_get_cd(struct mmc_host *mmc)
487{
488 struct mmci_host *host = mmc_priv(mmc);
489 unsigned int status;
490
491 if (host->gpio_cd == -ENOSYS)
492 status = host->plat->status(mmc_dev(host->mmc));
493 else
494 status = gpio_get_value(host->gpio_cd);
495
496 return !status;
497}
498
475static const struct mmc_host_ops mmci_ops = { 499static const struct mmc_host_ops mmci_ops = {
476 .request = mmci_request, 500 .request = mmci_request,
477 .set_ios = mmci_set_ios, 501 .set_ios = mmci_set_ios,
502 .get_ro = mmci_get_ro,
503 .get_cd = mmci_get_cd,
478}; 504};
479 505
480static void mmci_check_status(unsigned long data) 506static void mmci_check_status(unsigned long data)
481{ 507{
482 struct mmci_host *host = (struct mmci_host *)data; 508 struct mmci_host *host = (struct mmci_host *)data;
483 unsigned int status; 509 unsigned int status = mmci_get_cd(host->mmc);
484 510
485 status = host->plat->status(mmc_dev(host->mmc));
486 if (status ^ host->oldstat) 511 if (status ^ host->oldstat)
487 mmc_detect_change(host->mmc, 0); 512 mmc_detect_change(host->mmc, 0);
488 513
@@ -515,12 +540,15 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
515 540
516 host = mmc_priv(mmc); 541 host = mmc_priv(mmc);
517 host->mmc = mmc; 542 host->mmc = mmc;
518 /* Bits 12 thru 19 is the designer */ 543
519 host->hw_designer = (dev->periphid >> 12) & 0xff; 544 host->gpio_wp = -ENOSYS;
520 /* Bits 20 thru 23 is the revison */ 545 host->gpio_cd = -ENOSYS;
521 host->hw_revision = (dev->periphid >> 20) & 0xf; 546
547 host->hw_designer = amba_manf(dev);
548 host->hw_revision = amba_rev(dev);
522 DBG(host, "designer ID = 0x%02x\n", host->hw_designer); 549 DBG(host, "designer ID = 0x%02x\n", host->hw_designer);
523 DBG(host, "revision = 0x%01x\n", host->hw_revision); 550 DBG(host, "revision = 0x%01x\n", host->hw_revision);
551
524 host->clk = clk_get(&dev->dev, NULL); 552 host->clk = clk_get(&dev->dev, NULL);
525 if (IS_ERR(host->clk)) { 553 if (IS_ERR(host->clk)) {
526 ret = PTR_ERR(host->clk); 554 ret = PTR_ERR(host->clk);
@@ -591,6 +619,27 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
591 writel(0, host->base + MMCIMASK1); 619 writel(0, host->base + MMCIMASK1);
592 writel(0xfff, host->base + MMCICLEAR); 620 writel(0xfff, host->base + MMCICLEAR);
593 621
622#ifdef CONFIG_GPIOLIB
623 if (gpio_is_valid(plat->gpio_cd)) {
624 ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)");
625 if (ret == 0)
626 ret = gpio_direction_input(plat->gpio_cd);
627 if (ret == 0)
628 host->gpio_cd = plat->gpio_cd;
629 else if (ret != -ENOSYS)
630 goto err_gpio_cd;
631 }
632 if (gpio_is_valid(plat->gpio_wp)) {
633 ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)");
634 if (ret == 0)
635 ret = gpio_direction_input(plat->gpio_wp);
636 if (ret == 0)
637 host->gpio_wp = plat->gpio_wp;
638 else if (ret != -ENOSYS)
639 goto err_gpio_wp;
640 }
641#endif
642
594 ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host); 643 ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host);
595 if (ret) 644 if (ret)
596 goto unmap; 645 goto unmap;
@@ -602,6 +651,7 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
602 writel(MCI_IRQENABLE, host->base + MMCIMASK0); 651 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
603 652
604 amba_set_drvdata(dev, mmc); 653 amba_set_drvdata(dev, mmc);
654 host->oldstat = mmci_get_cd(host->mmc);
605 655
606 mmc_add_host(mmc); 656 mmc_add_host(mmc);
607 657
@@ -620,6 +670,12 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
620 irq0_free: 670 irq0_free:
621 free_irq(dev->irq[0], host); 671 free_irq(dev->irq[0], host);
622 unmap: 672 unmap:
673 if (host->gpio_wp != -ENOSYS)
674 gpio_free(host->gpio_wp);
675 err_gpio_wp:
676 if (host->gpio_cd != -ENOSYS)
677 gpio_free(host->gpio_cd);
678 err_gpio_cd:
623 iounmap(host->base); 679 iounmap(host->base);
624 clk_disable: 680 clk_disable:
625 clk_disable(host->clk); 681 clk_disable(host->clk);
@@ -655,6 +711,11 @@ static int __devexit mmci_remove(struct amba_device *dev)
655 free_irq(dev->irq[0], host); 711 free_irq(dev->irq[0], host);
656 free_irq(dev->irq[1], host); 712 free_irq(dev->irq[1], host);
657 713
714 if (host->gpio_wp != -ENOSYS)
715 gpio_free(host->gpio_wp);
716 if (host->gpio_cd != -ENOSYS)
717 gpio_free(host->gpio_cd);
718
658 iounmap(host->base); 719 iounmap(host->base);
659 clk_disable(host->clk); 720 clk_disable(host->clk);
660 clk_put(host->clk); 721 clk_put(host->clk);
diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
index 0441bac1c0ec..839f264c9725 100644
--- a/drivers/mmc/host/mmci.h
+++ b/drivers/mmc/host/mmci.h
@@ -151,6 +151,8 @@ struct mmci_host {
151 struct mmc_data *data; 151 struct mmc_data *data;
152 struct mmc_host *mmc; 152 struct mmc_host *mmc;
153 struct clk *clk; 153 struct clk *clk;
154 int gpio_cd;
155 int gpio_wp;
154 156
155 unsigned int data_xfered; 157 unsigned int data_xfered;
156 158