Commit 85d6509d authored by Shawn Guo's avatar Shawn Guo Committed by Chris Ball

mmc: sdhci: make sdhci-pltfm device drivers self registered

The patch turns the common stuff in sdhci-pltfm.c into functions, and
add device drivers their own .probe and .remove which in turn call
into the common functions, so that those sdhci-pltfm device drivers
register itself and keep all device specific things away from common
sdhci-pltfm file.
Signed-off-by: default avatarShawn Guo <shawn.guo@linaro.org>
Reviewed-by: default avatarGrant Likely <grant.likely@secretlab.ca>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarAnton Vorontsov <cbouatmailru@gmail.com>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent 3a5c3743
...@@ -112,29 +112,19 @@ config MMC_SDHCI_OF_HLWD ...@@ -112,29 +112,19 @@ config MMC_SDHCI_OF_HLWD
If unsure, say N. If unsure, say N.
config MMC_SDHCI_PLTFM
tristate "SDHCI support on the platform specific bus"
depends on MMC_SDHCI
help
This selects the platform specific bus support for Secure Digital Host
Controller Interface.
If you have a controller with this interface, say Y or M here.
If unsure, say N.
config MMC_SDHCI_CNS3XXX config MMC_SDHCI_CNS3XXX
bool "SDHCI support on the Cavium Networks CNS3xxx SoC" tristate "SDHCI support on the Cavium Networks CNS3xxx SoC"
depends on ARCH_CNS3XXX depends on ARCH_CNS3XXX
depends on MMC_SDHCI_PLTFM depends on MMC_SDHCI
help help
This selects the SDHCI support for CNS3xxx System-on-Chip devices. This selects the SDHCI support for CNS3xxx System-on-Chip devices.
If unsure, say N. If unsure, say N.
config MMC_SDHCI_ESDHC_IMX config MMC_SDHCI_ESDHC_IMX
bool "SDHCI platform support for the Freescale eSDHC i.MX controller" tristate "SDHCI platform support for the Freescale eSDHC i.MX controller"
depends on MMC_SDHCI_PLTFM && (ARCH_MX25 || ARCH_MX35 || ARCH_MX5) depends on ARCH_MX25 || ARCH_MX35 || ARCH_MX5
depends on MMC_SDHCI
select MMC_SDHCI_IO_ACCESSORS select MMC_SDHCI_IO_ACCESSORS
help help
This selects the Freescale eSDHC controller support on the platform This selects the Freescale eSDHC controller support on the platform
...@@ -143,9 +133,9 @@ config MMC_SDHCI_ESDHC_IMX ...@@ -143,9 +133,9 @@ config MMC_SDHCI_ESDHC_IMX
If unsure, say N. If unsure, say N.
config MMC_SDHCI_DOVE config MMC_SDHCI_DOVE
bool "SDHCI support on Marvell's Dove SoC" tristate "SDHCI support on Marvell's Dove SoC"
depends on ARCH_DOVE depends on ARCH_DOVE
depends on MMC_SDHCI_PLTFM depends on MMC_SDHCI
select MMC_SDHCI_IO_ACCESSORS select MMC_SDHCI_IO_ACCESSORS
help help
This selects the Secure Digital Host Controller Interface in This selects the Secure Digital Host Controller Interface in
...@@ -154,8 +144,9 @@ config MMC_SDHCI_DOVE ...@@ -154,8 +144,9 @@ config MMC_SDHCI_DOVE
If unsure, say N. If unsure, say N.
config MMC_SDHCI_TEGRA config MMC_SDHCI_TEGRA
bool "SDHCI platform support for the Tegra SD/MMC Controller" tristate "SDHCI platform support for the Tegra SD/MMC Controller"
depends on MMC_SDHCI_PLTFM && ARCH_TEGRA depends on ARCH_TEGRA
depends on MMC_SDHCI
select MMC_SDHCI_IO_ACCESSORS select MMC_SDHCI_IO_ACCESSORS
help help
This selects the Tegra SD/MMC controller. If you have a Tegra This selects the Tegra SD/MMC controller. If you have a Tegra
......
...@@ -44,12 +44,14 @@ obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o ...@@ -44,12 +44,14 @@ obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o
obj-$(CONFIG_MMC_VUB300) += vub300.o obj-$(CONFIG_MMC_VUB300) += vub300.o
obj-$(CONFIG_MMC_USHC) += ushc.o obj-$(CONFIG_MMC_USHC) += ushc.o
obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-platform.o obj-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o
sdhci-platform-y := sdhci-pltfm.o sdhci-cns3xxx-objs := sdhci-pltfm.o
sdhci-platform-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o obj-$(CONFIG_MMC_SDHCI_ESDHC_IMX) += sdhci-esdhc-imx.o
sdhci-platform-$(CONFIG_MMC_SDHCI_ESDHC_IMX) += sdhci-esdhc-imx.o sdhci-esdhc-imx-objs := sdhci-pltfm.o
sdhci-platform-$(CONFIG_MMC_SDHCI_DOVE) += sdhci-dove.o obj-$(CONFIG_MMC_SDHCI_DOVE) += sdhci-dove.o
sdhci-platform-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o sdhci-dove-objs := sdhci-pltfm.o
obj-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o
sdhci-tegra-objs := sdhci-pltfm.o
obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o
sdhci-of-y := sdhci-of-core.o sdhci-of-y := sdhci-of-core.o
......
...@@ -86,7 +86,7 @@ static struct sdhci_ops sdhci_cns3xxx_ops = { ...@@ -86,7 +86,7 @@ static struct sdhci_ops sdhci_cns3xxx_ops = {
.set_clock = sdhci_cns3xxx_set_clock, .set_clock = sdhci_cns3xxx_set_clock,
}; };
struct sdhci_pltfm_data sdhci_cns3xxx_pdata = { static struct sdhci_pltfm_data sdhci_cns3xxx_pdata = {
.ops = &sdhci_cns3xxx_ops, .ops = &sdhci_cns3xxx_ops,
.quirks = SDHCI_QUIRK_BROKEN_DMA | .quirks = SDHCI_QUIRK_BROKEN_DMA |
SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
...@@ -95,3 +95,43 @@ struct sdhci_pltfm_data sdhci_cns3xxx_pdata = { ...@@ -95,3 +95,43 @@ struct sdhci_pltfm_data sdhci_cns3xxx_pdata = {
SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
SDHCI_QUIRK_NONSTANDARD_CLOCK, SDHCI_QUIRK_NONSTANDARD_CLOCK,
}; };
static int __devinit sdhci_cns3xxx_probe(struct platform_device *pdev)
{
return sdhci_pltfm_register(pdev, &sdhci_cns3xxx_pdata);
}
static int __devexit sdhci_cns3xxx_remove(struct platform_device *pdev)
{
return sdhci_pltfm_unregister(pdev);
}
static struct platform_driver sdhci_cns3xxx_driver = {
.driver = {
.name = "sdhci-cns3xxx",
.owner = THIS_MODULE,
},
.probe = sdhci_cns3xxx_probe,
.remove = __devexit_p(sdhci_cns3xxx_remove),
#ifdef CONFIG_PM
.suspend = sdhci_pltfm_suspend,
.resume = sdhci_pltfm_resume,
#endif
};
static int __init sdhci_cns3xxx_init(void)
{
return platform_driver_register(&sdhci_cns3xxx_driver);
}
module_init(sdhci_cns3xxx_init);
static void __exit sdhci_cns3xxx_exit(void)
{
platform_driver_unregister(&sdhci_cns3xxx_driver);
}
module_exit(sdhci_cns3xxx_exit);
MODULE_DESCRIPTION("SDHCI driver for CNS3xxx");
MODULE_AUTHOR("Scott Shu, "
"Anton Vorontsov <avorontsov@mvista.com>");
MODULE_LICENSE("GPL v2");
...@@ -61,10 +61,50 @@ static struct sdhci_ops sdhci_dove_ops = { ...@@ -61,10 +61,50 @@ static struct sdhci_ops sdhci_dove_ops = {
.read_l = sdhci_dove_readl, .read_l = sdhci_dove_readl,
}; };
struct sdhci_pltfm_data sdhci_dove_pdata = { static struct sdhci_pltfm_data sdhci_dove_pdata = {
.ops = &sdhci_dove_ops, .ops = &sdhci_dove_ops,
.quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
SDHCI_QUIRK_NO_BUSY_IRQ | SDHCI_QUIRK_NO_BUSY_IRQ |
SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
SDHCI_QUIRK_FORCE_DMA, SDHCI_QUIRK_FORCE_DMA,
}; };
static int __devinit sdhci_dove_probe(struct platform_device *pdev)
{
return sdhci_pltfm_register(pdev, &sdhci_dove_pdata);
}
static int __devexit sdhci_dove_remove(struct platform_device *pdev)
{
return sdhci_pltfm_unregister(pdev);
}
static struct platform_driver sdhci_dove_driver = {
.driver = {
.name = "sdhci-dove",
.owner = THIS_MODULE,
},
.probe = sdhci_dove_probe,
.remove = __devexit_p(sdhci_dove_remove),
#ifdef CONFIG_PM
.suspend = sdhci_pltfm_suspend,
.resume = sdhci_pltfm_resume,
#endif
};
static int __init sdhci_dove_init(void)
{
return platform_driver_register(&sdhci_dove_driver);
}
module_init(sdhci_dove_init);
static void __exit sdhci_dove_exit(void)
{
platform_driver_unregister(&sdhci_dove_driver);
}
module_exit(sdhci_dove_exit);
MODULE_DESCRIPTION("SDHCI driver for Dove");
MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, "
"Mike Rapoport <mike@compulab.co.il>");
MODULE_LICENSE("GPL v2");
...@@ -191,16 +191,6 @@ static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host) ...@@ -191,16 +191,6 @@ static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
return clk_get_rate(pltfm_host->clk) / 256 / 16; return clk_get_rate(pltfm_host->clk) / 256 / 16;
} }
static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host)
{
struct esdhc_platform_data *boarddata = host->mmc->parent->platform_data;
if (boarddata && gpio_is_valid(boarddata->wp_gpio))
return gpio_get_value(boarddata->wp_gpio);
else
return -ENOSYS;
}
static struct sdhci_ops sdhci_esdhc_ops = { static struct sdhci_ops sdhci_esdhc_ops = {
.read_l = esdhc_readl_le, .read_l = esdhc_readl_le,
.read_w = esdhc_readw_le, .read_w = esdhc_readw_le,
...@@ -212,6 +202,24 @@ static struct sdhci_ops sdhci_esdhc_ops = { ...@@ -212,6 +202,24 @@ static struct sdhci_ops sdhci_esdhc_ops = {
.get_min_clock = esdhc_pltfm_get_min_clock, .get_min_clock = esdhc_pltfm_get_min_clock,
}; };
static struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
.quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA
| SDHCI_QUIRK_BROKEN_CARD_DETECTION,
/* ADMA has issues. Might be fixable */
.ops = &sdhci_esdhc_ops,
};
static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host)
{
struct esdhc_platform_data *boarddata =
host->mmc->parent->platform_data;
if (boarddata && gpio_is_valid(boarddata->wp_gpio))
return gpio_get_value(boarddata->wp_gpio);
else
return -ENOSYS;
}
static irqreturn_t cd_irq(int irq, void *data) static irqreturn_t cd_irq(int irq, void *data)
{ {
struct sdhci_host *sdhost = (struct sdhci_host *)data; struct sdhci_host *sdhost = (struct sdhci_host *)data;
...@@ -220,30 +228,35 @@ static irqreturn_t cd_irq(int irq, void *data) ...@@ -220,30 +228,35 @@ static irqreturn_t cd_irq(int irq, void *data)
return IRQ_HANDLED; return IRQ_HANDLED;
}; };
static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pdata) static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
{ {
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_pltfm_host *pltfm_host;
struct esdhc_platform_data *boarddata = host->mmc->parent->platform_data; struct sdhci_host *host;
struct esdhc_platform_data *boarddata;
struct clk *clk; struct clk *clk;
int err; int err;
struct pltfm_imx_data *imx_data; struct pltfm_imx_data *imx_data;
host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata);
if (IS_ERR(host))
return PTR_ERR(host);
pltfm_host = sdhci_priv(host);
imx_data = kzalloc(sizeof(struct pltfm_imx_data), GFP_KERNEL);
if (!imx_data)
return -ENOMEM;
pltfm_host->priv = imx_data;
clk = clk_get(mmc_dev(host->mmc), NULL); clk = clk_get(mmc_dev(host->mmc), NULL);
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
dev_err(mmc_dev(host->mmc), "clk err\n"); dev_err(mmc_dev(host->mmc), "clk err\n");
return PTR_ERR(clk); err = PTR_ERR(clk);
goto err_clk_get;
} }
clk_enable(clk); clk_enable(clk);
pltfm_host->clk = clk; pltfm_host->clk = clk;
imx_data = kzalloc(sizeof(struct pltfm_imx_data), GFP_KERNEL);
if (!imx_data) {
clk_disable(pltfm_host->clk);
clk_put(pltfm_host->clk);
return -ENOMEM;
}
pltfm_host->priv = imx_data;
if (!cpu_is_mx25()) if (!cpu_is_mx25())
host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
...@@ -257,6 +270,7 @@ static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pd ...@@ -257,6 +270,7 @@ static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pd
if (!(cpu_is_mx25() || cpu_is_mx35() || cpu_is_mx51())) if (!(cpu_is_mx25() || cpu_is_mx35() || cpu_is_mx51()))
imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT; imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT;
boarddata = host->mmc->parent->platform_data;
if (boarddata) { if (boarddata) {
err = gpio_request_one(boarddata->wp_gpio, GPIOF_IN, "ESDHC_WP"); err = gpio_request_one(boarddata->wp_gpio, GPIOF_IN, "ESDHC_WP");
if (err) { if (err) {
...@@ -289,6 +303,10 @@ static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pd ...@@ -289,6 +303,10 @@ static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pd
host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
} }
err = sdhci_add_host(host);
if (err)
goto err_add_host;
return 0; return 0;
no_card_detect_irq: no_card_detect_irq:
...@@ -297,14 +315,23 @@ static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pd ...@@ -297,14 +315,23 @@ static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pd
boarddata->cd_gpio = err; boarddata->cd_gpio = err;
not_supported: not_supported:
kfree(imx_data); kfree(imx_data);
return 0; err_add_host:
clk_disable(pltfm_host->clk);
clk_put(pltfm_host->clk);
err_clk_get:
sdhci_pltfm_free(pdev);
return err;
} }
static void esdhc_pltfm_exit(struct sdhci_host *host) static int __devexit sdhci_esdhc_imx_remove(struct platform_device *pdev)
{ {
struct sdhci_host *host = platform_get_drvdata(pdev);
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct esdhc_platform_data *boarddata = host->mmc->parent->platform_data; struct esdhc_platform_data *boarddata = host->mmc->parent->platform_data;
struct pltfm_imx_data *imx_data = pltfm_host->priv; struct pltfm_imx_data *imx_data = pltfm_host->priv;
int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
sdhci_remove_host(host, dead);
if (boarddata && gpio_is_valid(boarddata->wp_gpio)) if (boarddata && gpio_is_valid(boarddata->wp_gpio))
gpio_free(boarddata->wp_gpio); gpio_free(boarddata->wp_gpio);
...@@ -319,13 +346,37 @@ static void esdhc_pltfm_exit(struct sdhci_host *host) ...@@ -319,13 +346,37 @@ static void esdhc_pltfm_exit(struct sdhci_host *host)
clk_disable(pltfm_host->clk); clk_disable(pltfm_host->clk);
clk_put(pltfm_host->clk); clk_put(pltfm_host->clk);
kfree(imx_data); kfree(imx_data);
sdhci_pltfm_free(pdev);
return 0;
} }
struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { static struct platform_driver sdhci_esdhc_imx_driver = {
.quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA .driver = {
| SDHCI_QUIRK_BROKEN_CARD_DETECTION, .name = "sdhci-esdhc-imx",
/* ADMA has issues. Might be fixable */ .owner = THIS_MODULE,
.ops = &sdhci_esdhc_ops, },
.init = esdhc_pltfm_init, .probe = sdhci_esdhc_imx_probe,
.exit = esdhc_pltfm_exit, .remove = __devexit_p(sdhci_esdhc_imx_remove),
#ifdef CONFIG_PM
.suspend = sdhci_pltfm_suspend,
.resume = sdhci_pltfm_resume,
#endif
}; };
static int __init sdhci_esdhc_imx_init(void)
{
return platform_driver_register(&sdhci_esdhc_imx_driver);
}
module_init(sdhci_esdhc_imx_init);
static void __exit sdhci_esdhc_imx_exit(void)
{
platform_driver_unregister(&sdhci_esdhc_imx_driver);
}
module_exit(sdhci_esdhc_imx_exit);
MODULE_DESCRIPTION("SDHCI driver for Freescale i.MX eSDHC");
MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
MODULE_LICENSE("GPL v2");
...@@ -22,48 +22,22 @@ ...@@ -22,48 +22,22 @@
* Inspired by sdhci-pci.c, by Pierre Ossman * Inspired by sdhci-pci.c, by Pierre Ossman
*/ */
#include <linux/delay.h> #include <linux/err.h>
#include <linux/highmem.h>
#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>
#include <linux/mmc/host.h>
#include <linux/io.h>
#include <linux/mmc/sdhci-pltfm.h>
#include "sdhci.h" #include "sdhci.h"
#include "sdhci-pltfm.h" #include "sdhci-pltfm.h"
/*****************************************************************************\
* *
* SDHCI core callbacks *
* *
\*****************************************************************************/
static struct sdhci_ops sdhci_pltfm_ops = { static struct sdhci_ops sdhci_pltfm_ops = {
}; };
/*****************************************************************************\ struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
* * struct sdhci_pltfm_data *pdata)
* Device probing/removal *
* *
\*****************************************************************************/
static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
{ {
const struct platform_device_id *platid = platform_get_device_id(pdev);
struct sdhci_pltfm_data *pdata;
struct sdhci_host *host; struct sdhci_host *host;
struct sdhci_pltfm_host *pltfm_host; struct sdhci_pltfm_host *pltfm_host;
struct resource *iomem; struct resource *iomem;
int ret; int ret;
if (platid && platid->driver_data)
pdata = (void *)platid->driver_data;
else
pdata = pdev->dev.platform_data;
iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!iomem) { if (!iomem) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -71,8 +45,7 @@ static int __devinit sdhci_pltfm_probe(struct platform_device *pdev) ...@@ -71,8 +45,7 @@ static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
} }
if (resource_size(iomem) < 0x100) if (resource_size(iomem) < 0x100)
dev_err(&pdev->dev, "Invalid iomem size. You may " dev_err(&pdev->dev, "Invalid iomem size!\n");
"experience problems.\n");
/* Some PCI-based MFD need the parent here */ /* Some PCI-based MFD need the parent here */
if (pdev->dev.parent != &platform_bus) if (pdev->dev.parent != &platform_bus)
...@@ -87,7 +60,7 @@ static int __devinit sdhci_pltfm_probe(struct platform_device *pdev) ...@@ -87,7 +60,7 @@ static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
pltfm_host = sdhci_priv(host); pltfm_host = sdhci_priv(host);
host->hw_name = "platform"; host->hw_name = dev_name(&pdev->dev);
if (pdata && pdata->ops) if (pdata && pdata->ops)
host->ops = pdata->ops; host->ops = pdata->ops;
else else
...@@ -110,126 +83,70 @@ static int __devinit sdhci_pltfm_probe(struct platform_device *pdev) ...@@ -110,126 +83,70 @@ static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
goto err_remap; goto err_remap;
} }
if (pdata && pdata->init) {
ret = pdata->init(host, pdata);
if (ret)
goto err_plat_init;
}
ret = sdhci_add_host(host);
if (ret)
goto err_add_host;
platform_set_drvdata(pdev, host); platform_set_drvdata(pdev, host);
return 0; return host;
err_add_host:
if (pdata && pdata->exit)
pdata->exit(host);
err_plat_init:
iounmap(host->ioaddr);
err_remap: err_remap:
release_mem_region(iomem->start, resource_size(iomem)); release_mem_region(iomem->start, resource_size(iomem));
err_request: err_request:
sdhci_free_host(host); sdhci_free_host(host);
err: err:
printk(KERN_ERR"Probing of sdhci-pltfm failed: %d\n", ret); dev_err(&pdev->dev, "%s failed %d\n", __func__, ret);
return ret; return ERR_PTR(ret);
} }
static int __devexit sdhci_pltfm_remove(struct platform_device *pdev) void sdhci_pltfm_free(struct platform_device *pdev)
{ {
struct sdhci_pltfm_data *pdata = pdev->dev.platform_data;
struct sdhci_host *host = platform_get_drvdata(pdev); struct sdhci_host *host = platform_get_drvdata(pdev);
struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
int dead;
u32 scratch;
dead = 0;
scratch = readl(host->ioaddr + SDHCI_INT_STATUS);
if (scratch == (u32)-1)
dead = 1;
sdhci_remove_host(host, dead);
if (pdata && pdata->exit)
pdata->exit(host);
iounmap(host->ioaddr); iounmap(host->ioaddr);
release_mem_region(iomem->start, resource_size(iomem)); release_mem_region(iomem->start, resource_size(iomem));
sdhci_free_host(host); sdhci_free_host(host);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
}
return 0; int sdhci_pltfm_register(struct platform_device *pdev,
struct sdhci_pltfm_data *pdata)
{
struct sdhci_host *host;
int ret = 0;
host = sdhci_pltfm_init(pdev, pdata);
if (IS_ERR(host))
return PTR_ERR(host);
ret = sdhci_add_host(host);
if (ret)
sdhci_pltfm_free(pdev);
return ret;
} }
static const struct platform_device_id sdhci_pltfm_ids[] = { int sdhci_pltfm_unregister(struct platform_device *pdev)
{ "sdhci", }, {
#ifdef CONFIG_MMC_SDHCI_CNS3XXX struct sdhci_host *host = platform_get_drvdata(pdev);
{ "sdhci-cns3xxx", (kernel_ulong_t)&sdhci_cns3xxx_pdata }, int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
#endif
#ifdef CONFIG_MMC_SDHCI_ESDHC_IMX sdhci_remove_host(host, dead);
{ "sdhci-esdhc-imx", (kernel_ulong_t)&sdhci_esdhc_imx_pdata }, sdhci_pltfm_free(pdev);
#endif
#ifdef CONFIG_MMC_SDHCI_DOVE return 0;
{ "sdhci-dove", (kernel_ulong_t)&sdhci_dove_pdata }, }
#endif
#ifdef CONFIG_MMC_SDHCI_TEGRA
{ "sdhci-tegra", (kernel_ulong_t)&sdhci_tegra_pdata },
#endif
{ },
};
MODULE_DEVICE_TABLE(platform, sdhci_pltfm_ids);
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int sdhci_pltfm_suspend(struct platform_device *dev, pm_message_t state) int sdhci_pltfm_suspend(struct platform_device *dev, pm_message_t state)
{ {
struct sdhci_host *host = platform_get_drvdata(dev); struct sdhci_host *host = platform_get_drvdata(dev);
return sdhci_suspend_host(host, state); return sdhci_suspend_host(host, state);
} }
static int sdhci_pltfm_resume(struct platform_device *dev) int sdhci_pltfm_resume(struct platform_device *dev)
{ {
struct sdhci_host *host = platform_get_drvdata(dev); struct sdhci_host *host = platform_get_drvdata(dev);
return sdhci_resume_host(host); return sdhci_resume_host(host);
} }
#else
#define sdhci_pltfm_suspend NULL
#define sdhci_pltfm_resume NULL
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
static struct platform_driver sdhci_pltfm_driver = {
.driver = {
.name = "sdhci",
.owner = THIS_MODULE,
},
.probe = sdhci_pltfm_probe,
.remove = __devexit_p(sdhci_pltfm_remove),
.id_table = sdhci_pltfm_ids,
.suspend = sdhci_pltfm_suspend,
.resume = sdhci_pltfm_resume,
};
/*****************************************************************************\
* *
* Driver init/exit *
* *
\*****************************************************************************/
static int __init sdhci_drv_init(void)
{
return platform_driver_register(&sdhci_pltfm_driver);
}
static void __exit sdhci_drv_exit(void)
{
platform_driver_unregister(&sdhci_pltfm_driver);
}
module_init(sdhci_drv_init);
module_exit(sdhci_drv_exit);
MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
MODULE_LICENSE("GPL v2");
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/platform_device.h>
#include <linux/mmc/sdhci-pltfm.h> #include <linux/mmc/sdhci-pltfm.h>
struct sdhci_pltfm_host { struct sdhci_pltfm_host {
...@@ -20,9 +21,17 @@ struct sdhci_pltfm_host { ...@@ -20,9 +21,17 @@ struct sdhci_pltfm_host {
void *priv; /* to handle quirks across io-accessor calls */ void *priv; /* to handle quirks across io-accessor calls */
}; };
extern struct sdhci_pltfm_data sdhci_cns3xxx_pdata; extern struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
extern struct sdhci_pltfm_data sdhci_esdhc_imx_pdata; struct sdhci_pltfm_data *pdata);
extern struct sdhci_pltfm_data sdhci_dove_pdata; extern void sdhci_pltfm_free(struct platform_device *pdev);
extern struct sdhci_pltfm_data sdhci_tegra_pdata;
extern int sdhci_pltfm_register(struct platform_device *pdev,
struct sdhci_pltfm_data *pdata);
extern int sdhci_pltfm_unregister(struct platform_device *pdev);
#ifdef CONFIG_PM
extern int sdhci_pltfm_suspend(struct platform_device *dev, pm_message_t state);
extern int sdhci_pltfm_resume(struct platform_device *dev);
#endif
#endif /* _DRIVERS_MMC_SDHCI_PLTFM_H */ #endif /* _DRIVERS_MMC_SDHCI_PLTFM_H */
...@@ -116,20 +116,42 @@ static int tegra_sdhci_8bit(struct sdhci_host *host, int bus_width) ...@@ -116,20 +116,42 @@ static int tegra_sdhci_8bit(struct sdhci_host *host, int bus_width)
return 0; return 0;
} }
static struct sdhci_ops tegra_sdhci_ops = {
.get_ro = tegra_sdhci_get_ro,
.read_l = tegra_sdhci_readl,
.read_w = tegra_sdhci_readw,
.write_l = tegra_sdhci_writel,
.platform_8bit_width = tegra_sdhci_8bit,
};
static struct sdhci_pltfm_data sdhci_tegra_pdata = {
.quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
SDHCI_QUIRK_SINGLE_POWER_WRITE |
SDHCI_QUIRK_NO_HISPD_BIT |
SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC,
.ops = &tegra_sdhci_ops,
};
static int tegra_sdhci_pltfm_init(struct sdhci_host *host, static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
struct sdhci_pltfm_data *pdata)
{ {
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_pltfm_host *pltfm_host;
struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc));
struct tegra_sdhci_platform_data *plat; struct tegra_sdhci_platform_data *plat;
struct sdhci_host *host;
struct clk *clk; struct clk *clk;
int rc; int rc;
host = sdhci_pltfm_init(pdev, &sdhci_tegra_pdata);
if (IS_ERR(host))
return PTR_ERR(host);
pltfm_host = sdhci_priv(host);
plat = pdev->dev.platform_data; plat = pdev->dev.platform_data;
if (plat == NULL) { if (plat == NULL) {
dev_err(mmc_dev(host->mmc), "missing platform data\n"); dev_err(mmc_dev(host->mmc), "missing platform data\n");
return -ENXIO; rc = -ENXIO;
goto err_no_plat;
} }
if (gpio_is_valid(plat->power_gpio)) { if (gpio_is_valid(plat->power_gpio)) {
...@@ -137,7 +159,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host, ...@@ -137,7 +159,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host,
if (rc) { if (rc) {
dev_err(mmc_dev(host->mmc), dev_err(mmc_dev(host->mmc),
"failed to allocate power gpio\n"); "failed to allocate power gpio\n");
goto out; goto err_power_req;
} }
tegra_gpio_enable(plat->power_gpio); tegra_gpio_enable(plat->power_gpio);
gpio_direction_output(plat->power_gpio, 1); gpio_direction_output(plat->power_gpio, 1);
...@@ -148,7 +170,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host, ...@@ -148,7 +170,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host,
if (rc) { if (rc) {
dev_err(mmc_dev(host->mmc), dev_err(mmc_dev(host->mmc),
"failed to allocate cd gpio\n"); "failed to allocate cd gpio\n");
goto out_power; goto err_cd_req;
} }
tegra_gpio_enable(plat->cd_gpio); tegra_gpio_enable(plat->cd_gpio);
gpio_direction_input(plat->cd_gpio); gpio_direction_input(plat->cd_gpio);
...@@ -159,7 +181,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host, ...@@ -159,7 +181,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host,
if (rc) { if (rc) {
dev_err(mmc_dev(host->mmc), "request irq error\n"); dev_err(mmc_dev(host->mmc), "request irq error\n");
goto out_cd; goto err_cd_irq_req;
} }
} }
...@@ -169,7 +191,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host, ...@@ -169,7 +191,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host,
if (rc) { if (rc) {
dev_err(mmc_dev(host->mmc), dev_err(mmc_dev(host->mmc),
"failed to allocate wp gpio\n"); "failed to allocate wp gpio\n");
goto out_irq; goto err_wp_req;
} }
tegra_gpio_enable(plat->wp_gpio); tegra_gpio_enable(plat->wp_gpio);
gpio_direction_input(plat->wp_gpio); gpio_direction_input(plat->wp_gpio);
...@@ -179,7 +201,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host, ...@@ -179,7 +201,7 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host,
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
dev_err(mmc_dev(host->mmc), "clk err\n"); dev_err(mmc_dev(host->mmc), "clk err\n");
rc = PTR_ERR(clk); rc = PTR_ERR(clk);
goto out_wp; goto err_clk_get;
} }
clk_enable(clk); clk_enable(clk);
pltfm_host->clk = clk; pltfm_host->clk = clk;
...@@ -189,38 +211,47 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host, ...@@ -189,38 +211,47 @@ static int tegra_sdhci_pltfm_init(struct sdhci_host *host,
if (plat->is_8bit) if (plat->is_8bit)
host->mmc->caps |= MMC_CAP_8_BIT_DATA; host->mmc->caps |= MMC_CAP_8_BIT_DATA;
rc = sdhci_add_host(host);
if (rc)
goto err_add_host;
return 0; return 0;
out_wp: err_add_host:
clk_disable(pltfm_host->clk);
clk_put(pltfm_host->clk);
err_clk_get:
if (gpio_is_valid(plat->wp_gpio)) { if (gpio_is_valid(plat->wp_gpio)) {
tegra_gpio_disable(plat->wp_gpio); tegra_gpio_disable(plat->wp_gpio);
gpio_free(plat->wp_gpio); gpio_free(plat->wp_gpio);
} }
err_wp_req:
out_irq:
if (gpio_is_valid(plat->cd_gpio)) if (gpio_is_valid(plat->cd_gpio))
free_irq(gpio_to_irq(plat->cd_gpio), host); free_irq(gpio_to_irq(plat->cd_gpio), host);
out_cd: err_cd_irq_req:
if (gpio_is_valid(plat->cd_gpio)) { if (gpio_is_valid(plat->cd_gpio)) {
tegra_gpio_disable(plat->cd_gpio); tegra_gpio_disable(plat->cd_gpio);
gpio_free(plat->cd_gpio); gpio_free(plat->cd_gpio);
} }
err_cd_req:
out_power:
if (gpio_is_valid(plat->power_gpio)) { if (gpio_is_valid(plat->power_gpio)) {
tegra_gpio_disable(plat->power_gpio); tegra_gpio_disable(plat->power_gpio);
gpio_free(plat->power_gpio); gpio_free(plat->power_gpio);
} }
err_power_req:
out: err_no_plat:
sdhci_pltfm_free(pdev);
return rc; return rc;
} }
static void tegra_sdhci_pltfm_exit(struct sdhci_host *host) static int __devexit sdhci_tegra_remove(struct platform_device *pdev)
{ {
struct sdhci_host *host = platform_get_drvdata(pdev);
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc));
struct tegra_sdhci_platform_data *plat; struct tegra_sdhci_platform_data *plat;
int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
sdhci_remove_host(host, dead);
plat = pdev->dev.platform_data; plat = pdev->dev.platform_data;
...@@ -242,22 +273,37 @@ static void tegra_sdhci_pltfm_exit(struct sdhci_host *host) ...@@ -242,22 +273,37 @@ static void tegra_sdhci_pltfm_exit(struct sdhci_host *host)
clk_disable(pltfm_host->clk); clk_disable(pltfm_host->clk);
clk_put(pltfm_host->clk); clk_put(pltfm_host->clk);
sdhci_pltfm_free(pdev);
return 0;
} }
static struct sdhci_ops tegra_sdhci_ops = { static struct platform_driver sdhci_tegra_driver = {
.get_ro = tegra_sdhci_get_ro, .driver = {
.read_l = tegra_sdhci_readl, .name = "sdhci-tegra",
.read_w = tegra_sdhci_readw, .owner = THIS_MODULE,
.write_l = tegra_sdhci_writel, },
.platform_8bit_width = tegra_sdhci_8bit, .probe = sdhci_tegra_probe,
.remove = __devexit_p(sdhci_tegra_remove),
#ifdef CONFIG_PM
.suspend = sdhci_pltfm_suspend,
.resume = sdhci_pltfm_resume,
#endif
}; };
struct sdhci_pltfm_data sdhci_tegra_pdata = { static int __init sdhci_tegra_init(void)
.quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | {
SDHCI_QUIRK_SINGLE_POWER_WRITE | return platform_driver_register(&sdhci_tegra_driver);
SDHCI_QUIRK_NO_HISPD_BIT | }
SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC, module_init(sdhci_tegra_init);
.ops = &tegra_sdhci_ops,
.init = tegra_sdhci_pltfm_init, static void __exit sdhci_tegra_exit(void)
.exit = tegra_sdhci_pltfm_exit, {
}; platform_driver_unregister(&sdhci_tegra_driver);
}
module_exit(sdhci_tegra_exit);
MODULE_DESCRIPTION("SDHCI driver for Tegra");
MODULE_AUTHOR(" Google, Inc.");
MODULE_LICENSE("GPL v2");
...@@ -15,21 +15,15 @@ ...@@ -15,21 +15,15 @@
#define _SDHCI_PLTFM_H #define _SDHCI_PLTFM_H
struct sdhci_ops; struct sdhci_ops;
struct sdhci_host;
/** /**
* struct sdhci_pltfm_data - SDHCI platform-specific information & hooks * struct sdhci_pltfm_data - SDHCI platform-specific information & hooks
* @ops: optional pointer to the platform-provided SDHCI ops * @ops: optional pointer to the platform-provided SDHCI ops
* @quirks: optional SDHCI quirks * @quirks: optional SDHCI quirks
* @init: optional hook that is called during device probe, before the
* driver tries to access any SDHCI registers
* @exit: optional hook that is called during device removal
*/ */
struct sdhci_pltfm_data { struct sdhci_pltfm_data {
struct sdhci_ops *ops; struct sdhci_ops *ops;
unsigned int quirks; unsigned int quirks;
int (*init)(struct sdhci_host *host, struct sdhci_pltfm_data *pdata);
void (*exit)(struct sdhci_host *host);
}; };
#endif /* _SDHCI_PLTFM_H */ #endif /* _SDHCI_PLTFM_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment