Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth...
[sfrench/cifs-2.6.git] / drivers / mmc / host / dw_mmc-pltfm.c
index 92ec3eb3aae767bece2b75da7fc272f7982cd730..c960ca7ffbe694fa367ff7ca88c83003b3da59a6 100644 (file)
 #include <linux/mmc/host.h>
 #include <linux/mmc/mmc.h>
 #include <linux/mmc/dw_mmc.h>
+#include <linux/of.h>
+
 #include "dw_mmc.h"
 
-static int dw_mci_pltfm_probe(struct platform_device *pdev)
+int dw_mci_pltfm_register(struct platform_device *pdev,
+                               struct dw_mci_drv_data *drv_data)
 {
        struct dw_mci *host;
        struct resource *regs;
        int ret;
 
-       host = kzalloc(sizeof(struct dw_mci), GFP_KERNEL);
+       host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
        if (!host)
                return -ENOMEM;
 
        regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!regs) {
-               ret = -ENXIO;
-               goto err_free;
-       }
+       if (!regs)
+               return -ENXIO;
 
        host->irq = platform_get_irq(pdev, 0);
-       if (host->irq < 0) {
-               ret = host->irq;
-               goto err_free;
-       }
+       if (host->irq < 0)
+               return host->irq;
 
-       host->dev = pdev->dev;
+       host->drv_data = drv_data;
+       host->dev = &pdev->dev;
        host->irq_flags = 0;
        host->pdata = pdev->dev.platform_data;
-       ret = -ENOMEM;
-       host->regs = ioremap(regs->start, resource_size(regs));
+       host->regs = devm_request_and_ioremap(&pdev->dev, regs);
        if (!host->regs)
-               goto err_free;
+               return -ENOMEM;
+
+       if (host->drv_data->init) {
+               ret = host->drv_data->init(host);
+               if (ret)
+                       return ret;
+       }
+
        platform_set_drvdata(pdev, host);
        ret = dw_mci_probe(host);
-       if (ret)
-               goto err_out;
-       return ret;
-err_out:
-       iounmap(host->regs);
-err_free:
-       kfree(host);
        return ret;
 }
+EXPORT_SYMBOL_GPL(dw_mci_pltfm_register);
 
-static int __exit dw_mci_pltfm_remove(struct platform_device *pdev)
+static int __devinit dw_mci_pltfm_probe(struct platform_device *pdev)
+{
+       return dw_mci_pltfm_register(pdev, NULL);
+}
+
+static int __devexit dw_mci_pltfm_remove(struct platform_device *pdev)
 {
        struct dw_mci *host = platform_get_drvdata(pdev);
 
        platform_set_drvdata(pdev, NULL);
        dw_mci_remove(host);
-       iounmap(host->regs);
-       kfree(host);
        return 0;
 }
+EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove);
 
 #ifdef CONFIG_PM_SLEEP
 /*
@@ -105,12 +109,20 @@ static int dw_mci_pltfm_resume(struct device *dev)
 #define dw_mci_pltfm_resume    NULL
 #endif /* CONFIG_PM_SLEEP */
 
-static SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume);
+SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume);
+EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops);
+
+static const struct of_device_id dw_mci_pltfm_match[] = {
+       { .compatible = "snps,dw-mshc", },
+       {},
+};
+MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match);
 
 static struct platform_driver dw_mci_pltfm_driver = {
        .remove         = __exit_p(dw_mci_pltfm_remove),
        .driver         = {
                .name           = "dw_mmc",
+               .of_match_table = of_match_ptr(dw_mci_pltfm_match),
                .pm             = &dw_mci_pltfm_pmops,
        },
 };