2 * sdhci-pltfm.c Support for SDHCI platform devices
3 * Copyright (c) 2009 Intel Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * SDHCI platform devices
22 * Inspired by sdhci-pci.c, by Pierre Ossman
25 #include <linux/delay.h>
26 #include <linux/highmem.h>
27 #include <linux/mod_devicetable.h>
28 #include <linux/platform_device.h>
30 #include <linux/mmc/host.h>
33 #include <linux/sdhci-pltfm.h>
36 #include "sdhci-pltfm.h"
38 /*****************************************************************************\
40 * SDHCI core callbacks *
42 \*****************************************************************************/
44 static struct sdhci_ops sdhci_pltfm_ops = {
47 /*****************************************************************************\
49 * Device probing/removal *
51 \*****************************************************************************/
53 static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
55 struct sdhci_pltfm_data *pdata = pdev->dev.platform_data;
56 const struct platform_device_id *platid = platform_get_device_id(pdev);
57 struct sdhci_host *host;
58 struct sdhci_pltfm_host *pltfm_host;
59 struct resource *iomem;
62 if (!pdata && platid && platid->driver_data)
63 pdata = (void *)platid->driver_data;
65 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
71 if (resource_size(iomem) < 0x100)
72 dev_err(&pdev->dev, "Invalid iomem size. You may "
73 "experience problems.\n");
75 /* Some PCI-based MFD need the parent here */
76 if (pdev->dev.parent != &platform_bus)
77 host = sdhci_alloc_host(pdev->dev.parent, sizeof(*pltfm_host));
79 host = sdhci_alloc_host(&pdev->dev, sizeof(*pltfm_host));
86 pltfm_host = sdhci_priv(host);
88 host->hw_name = "platform";
89 if (pdata && pdata->ops)
90 host->ops = pdata->ops;
92 host->ops = &sdhci_pltfm_ops;
94 host->quirks = pdata->quirks;
95 host->irq = platform_get_irq(pdev, 0);
97 if (!request_mem_region(iomem->start, resource_size(iomem),
98 mmc_hostname(host->mmc))) {
99 dev_err(&pdev->dev, "cannot request region\n");
104 host->ioaddr = ioremap(iomem->start, resource_size(iomem));
106 dev_err(&pdev->dev, "failed to remap registers\n");
111 if (pdata && pdata->init) {
112 ret = pdata->init(host);
117 ret = sdhci_add_host(host);
121 platform_set_drvdata(pdev, host);
126 if (pdata && pdata->exit)
129 iounmap(host->ioaddr);
131 release_mem_region(iomem->start, resource_size(iomem));
133 sdhci_free_host(host);
135 printk(KERN_ERR"Probing of sdhci-pltfm failed: %d\n", ret);
139 static int __devexit sdhci_pltfm_remove(struct platform_device *pdev)
141 struct sdhci_pltfm_data *pdata = pdev->dev.platform_data;
142 struct sdhci_host *host = platform_get_drvdata(pdev);
143 struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
148 scratch = readl(host->ioaddr + SDHCI_INT_STATUS);
149 if (scratch == (u32)-1)
152 sdhci_remove_host(host, dead);
153 if (pdata && pdata->exit)
155 iounmap(host->ioaddr);
156 release_mem_region(iomem->start, resource_size(iomem));
157 sdhci_free_host(host);
158 platform_set_drvdata(pdev, NULL);
163 static const struct platform_device_id sdhci_pltfm_ids[] = {
165 #ifdef CONFIG_MMC_SDHCI_CNS3XXX
166 { "sdhci-cns3xxx", (kernel_ulong_t)&sdhci_cns3xxx_pdata },
170 MODULE_DEVICE_TABLE(platform, sdhci_pltfm_ids);
173 static int sdhci_pltfm_suspend(struct platform_device *dev, pm_message_t state)
175 struct sdhci_host *host = platform_get_drvdata(dev);
177 return sdhci_suspend_host(host, state);
180 static int sdhci_pltfm_resume(struct platform_device *dev)
182 struct sdhci_host *host = platform_get_drvdata(dev);
184 return sdhci_resume_host(host);
187 #define sdhci_pltfm_suspend NULL
188 #define sdhci_pltfm_resume NULL
189 #endif /* CONFIG_PM */
191 static struct platform_driver sdhci_pltfm_driver = {
194 .owner = THIS_MODULE,
196 .probe = sdhci_pltfm_probe,
197 .remove = __devexit_p(sdhci_pltfm_remove),
198 .id_table = sdhci_pltfm_ids,
199 .suspend = sdhci_pltfm_suspend,
200 .resume = sdhci_pltfm_resume,
203 /*****************************************************************************\
207 \*****************************************************************************/
209 static int __init sdhci_drv_init(void)
211 return platform_driver_register(&sdhci_pltfm_driver);
214 static void __exit sdhci_drv_exit(void)
216 platform_driver_unregister(&sdhci_pltfm_driver);
219 module_init(sdhci_drv_init);
220 module_exit(sdhci_drv_exit);
222 MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
223 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
224 MODULE_LICENSE("GPL v2");