2 * SDHCI support for SiRF primaII and marco SoCs
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
6 * Licensed under GPLv2 or later.
9 #include <linux/delay.h>
10 #include <linux/device.h>
11 #include <linux/mmc/host.h>
12 #include <linux/module.h>
14 #include <linux/of_gpio.h>
15 #include <linux/mmc/slot-gpio.h>
16 #include "sdhci-pltfm.h"
18 struct sdhci_sirf_priv {
23 static unsigned int sdhci_sirf_get_max_clk(struct sdhci_host *host)
25 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
26 struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
27 return clk_get_rate(priv->clk);
30 static struct sdhci_ops sdhci_sirf_ops = {
31 .set_clock = sdhci_set_clock,
32 .get_max_clock = sdhci_sirf_get_max_clk,
33 .set_bus_width = sdhci_set_bus_width,
35 .set_uhs_signaling = sdhci_set_uhs_signaling,
38 static struct sdhci_pltfm_data sdhci_sirf_pdata = {
39 .ops = &sdhci_sirf_ops,
40 .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
41 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
42 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
43 SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
44 SDHCI_QUIRK_DELAY_AFTER_POWER,
47 static int sdhci_sirf_probe(struct platform_device *pdev)
49 struct sdhci_host *host;
50 struct sdhci_pltfm_host *pltfm_host;
51 struct sdhci_sirf_priv *priv;
56 clk = devm_clk_get(&pdev->dev, NULL);
58 dev_err(&pdev->dev, "unable to get clock");
62 if (pdev->dev.of_node)
63 gpio_cd = of_get_named_gpio(pdev->dev.of_node, "cd-gpios", 0);
67 host = sdhci_pltfm_init(pdev, &sdhci_sirf_pdata, sizeof(struct sdhci_sirf_priv));
71 pltfm_host = sdhci_priv(host);
72 priv = sdhci_pltfm_priv(pltfm_host);
74 priv->gpio_cd = gpio_cd;
76 sdhci_get_of_property(pdev);
78 ret = clk_prepare_enable(priv->clk);
82 ret = sdhci_add_host(host);
87 * We must request the IRQ after sdhci_add_host(), as the tasklet only
88 * gets setup in sdhci_add_host() and we oops.
90 if (gpio_is_valid(priv->gpio_cd)) {
91 ret = mmc_gpio_request_cd(host->mmc, priv->gpio_cd, 0);
93 dev_err(&pdev->dev, "card detect irq request failed: %d\n",
102 sdhci_remove_host(host, 0);
104 clk_disable_unprepare(priv->clk);
106 sdhci_pltfm_free(pdev);
110 static int sdhci_sirf_remove(struct platform_device *pdev)
112 struct sdhci_host *host = platform_get_drvdata(pdev);
113 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
114 struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
116 sdhci_pltfm_unregister(pdev);
118 if (gpio_is_valid(priv->gpio_cd))
119 mmc_gpio_free_cd(host->mmc);
121 clk_disable_unprepare(priv->clk);
125 #ifdef CONFIG_PM_SLEEP
126 static int sdhci_sirf_suspend(struct device *dev)
128 struct sdhci_host *host = dev_get_drvdata(dev);
129 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
130 struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
133 ret = sdhci_suspend_host(host);
137 clk_disable(priv->clk);
142 static int sdhci_sirf_resume(struct device *dev)
144 struct sdhci_host *host = dev_get_drvdata(dev);
145 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
146 struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
149 ret = clk_enable(priv->clk);
151 dev_dbg(dev, "Resume: Error enabling clock\n");
155 return sdhci_resume_host(host);
158 static SIMPLE_DEV_PM_OPS(sdhci_sirf_pm_ops, sdhci_sirf_suspend, sdhci_sirf_resume);
161 static const struct of_device_id sdhci_sirf_of_match[] = {
162 { .compatible = "sirf,prima2-sdhc" },
165 MODULE_DEVICE_TABLE(of, sdhci_sirf_of_match);
167 static struct platform_driver sdhci_sirf_driver = {
169 .name = "sdhci-sirf",
170 .owner = THIS_MODULE,
171 .of_match_table = sdhci_sirf_of_match,
172 #ifdef CONFIG_PM_SLEEP
173 .pm = &sdhci_sirf_pm_ops,
176 .probe = sdhci_sirf_probe,
177 .remove = sdhci_sirf_remove,
180 module_platform_driver(sdhci_sirf_driver);
182 MODULE_DESCRIPTION("SDHCI driver for SiRFprimaII/SiRFmarco");
183 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
184 MODULE_LICENSE("GPL v2");