mmc: sdhci-bcm-kona: Add basic use of clocks
authorTim Kryger <tim.kryger@linaro.org>
Thu, 5 Dec 2013 19:20:41 +0000 (11:20 -0800)
committerChris Ball <chris@printf.net>
Mon, 24 Feb 2014 19:38:40 +0000 (14:38 -0500)
Enable the external clock needed by the host controller during the
probe and disable it during the remove.

Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Matt Porter <matt.porter@linaro.org>
Signed-off-by: Chris Ball <chris@printf.net>
drivers/mmc/host/sdhci-bcm-kona.c

index 7a190fe4dff1b799958bfedf7bb01dd5d405a0f8..923eefabf801e7a5adcb9e35eb05086546f08c66 100644 (file)
@@ -54,6 +54,7 @@
 
 struct sdhci_bcm_kona_dev {
        struct mutex    write_lock; /* protect back to back writes */
+       struct clk      *external_clk;
 };
 
 
@@ -257,6 +258,24 @@ static int sdhci_bcm_kona_probe(struct platform_device *pdev)
                goto err_pltfm_free;
        }
 
+       /* Get and enable the external clock */
+       kona_dev->external_clk = devm_clk_get(dev, NULL);
+       if (IS_ERR(kona_dev->external_clk)) {
+               dev_err(dev, "Failed to get external clock\n");
+               ret = PTR_ERR(kona_dev->external_clk);
+               goto err_pltfm_free;
+       }
+
+       if (clk_set_rate(kona_dev->external_clk, host->mmc->f_max) != 0) {
+               dev_err(dev, "Failed to set rate external clock\n");
+               goto err_pltfm_free;
+       }
+
+       if (clk_prepare_enable(kona_dev->external_clk) != 0) {
+               dev_err(dev, "Failed to enable external clock\n");
+               goto err_pltfm_free;
+       }
+
        dev_dbg(dev, "non-removable=%c\n",
                (host->mmc->caps & MMC_CAP_NONREMOVABLE) ? 'Y' : 'N');
        dev_dbg(dev, "cd_gpio %c, wp_gpio %c\n",
@@ -271,7 +290,7 @@ static int sdhci_bcm_kona_probe(struct platform_device *pdev)
 
        ret = sdhci_bcm_kona_sd_reset(host);
        if (ret)
-               goto err_pltfm_free;
+               goto err_clk_disable;
 
        sdhci_bcm_kona_sd_init(host);
 
@@ -307,6 +326,9 @@ err_remove_host:
 err_reset:
        sdhci_bcm_kona_sd_reset(host);
 
+err_clk_disable:
+       clk_disable_unprepare(kona_dev->external_clk);
+
 err_pltfm_free:
        sdhci_pltfm_free(pdev);
 
@@ -316,7 +338,18 @@ err_pltfm_free:
 
 static int __exit sdhci_bcm_kona_remove(struct platform_device *pdev)
 {
-       return sdhci_pltfm_unregister(pdev);
+       struct sdhci_host *host = platform_get_drvdata(pdev);
+       struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host);
+       struct sdhci_bcm_kona_dev *kona_dev = sdhci_pltfm_priv(pltfm_priv);
+       int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
+
+       sdhci_remove_host(host, dead);
+
+       clk_disable_unprepare(kona_dev->external_clk);
+
+       sdhci_pltfm_free(pdev);
+
+       return 0;
 }
 
 static struct platform_driver sdhci_bcm_kona_driver = {