162ca8034SShashidhar Hiremath /* 262ca8034SShashidhar Hiremath * Synopsys DesignWare Multimedia Card Interface driver 362ca8034SShashidhar Hiremath * 462ca8034SShashidhar Hiremath * Copyright (C) 2009 NXP Semiconductors 562ca8034SShashidhar Hiremath * Copyright (C) 2009, 2010 Imagination Technologies Ltd. 662ca8034SShashidhar Hiremath * 762ca8034SShashidhar Hiremath * This program is free software; you can redistribute it and/or modify 862ca8034SShashidhar Hiremath * it under the terms of the GNU General Public License as published by 962ca8034SShashidhar Hiremath * the Free Software Foundation; either version 2 of the License, or 1062ca8034SShashidhar Hiremath * (at your option) any later version. 1162ca8034SShashidhar Hiremath */ 1262ca8034SShashidhar Hiremath 13a3e2cd7fSThierry Reding #include <linux/err.h> 1462ca8034SShashidhar Hiremath #include <linux/interrupt.h> 1562ca8034SShashidhar Hiremath #include <linux/module.h> 1662ca8034SShashidhar Hiremath #include <linux/io.h> 1762ca8034SShashidhar Hiremath #include <linux/irq.h> 1862ca8034SShashidhar Hiremath #include <linux/platform_device.h> 1962ca8034SShashidhar Hiremath #include <linux/slab.h> 2062ca8034SShashidhar Hiremath #include <linux/mmc/host.h> 2162ca8034SShashidhar Hiremath #include <linux/mmc/mmc.h> 2262ca8034SShashidhar Hiremath #include <linux/mmc/dw_mmc.h> 23c91eab4bSThomas Abraham #include <linux/of.h> 24f629ba2cSAddy Ke #include <linux/clk.h> 25c91eab4bSThomas Abraham 2662ca8034SShashidhar Hiremath #include "dw_mmc.h" 277725a52cSJingoo Han #include "dw_mmc-pltfm.h" 2862ca8034SShashidhar Hiremath 29800d78bfSThomas Abraham int dw_mci_pltfm_register(struct platform_device *pdev, 308e2b36eaSArnd Bergmann const struct dw_mci_drv_data *drv_data) 3162ca8034SShashidhar Hiremath { 3262ca8034SShashidhar Hiremath struct dw_mci *host; 3362ca8034SShashidhar Hiremath struct resource *regs; 3462ca8034SShashidhar Hiremath 35bb8bdc77SThomas Abraham host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL); 3662ca8034SShashidhar Hiremath if (!host) 3762ca8034SShashidhar Hiremath return -ENOMEM; 3862ca8034SShashidhar Hiremath 3962ca8034SShashidhar Hiremath host->irq = platform_get_irq(pdev, 0); 40bb8bdc77SThomas Abraham if (host->irq < 0) 41bb8bdc77SThomas Abraham return host->irq; 4262ca8034SShashidhar Hiremath 43800d78bfSThomas Abraham host->drv_data = drv_data; 444a90920cSThomas Abraham host->dev = &pdev->dev; 4562ca8034SShashidhar Hiremath host->irq_flags = 0; 4662ca8034SShashidhar Hiremath host->pdata = pdev->dev.platform_data; 47bcc87666SAndy Shevchenko 48bcc87666SAndy Shevchenko regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 49a3e2cd7fSThierry Reding host->regs = devm_ioremap_resource(&pdev->dev, regs); 50a3e2cd7fSThierry Reding if (IS_ERR(host->regs)) 51a3e2cd7fSThierry Reding return PTR_ERR(host->regs); 52bb8bdc77SThomas Abraham 5345c7a490SJaehoon Chung /* Get registers' physical base address */ 5445c7a490SJaehoon Chung host->phy_regs = regs->start; 5545c7a490SJaehoon Chung 5662ca8034SShashidhar Hiremath platform_set_drvdata(pdev, host); 57dd369800SAndy Shevchenko return dw_mci_probe(host); 5862ca8034SShashidhar Hiremath } 5917403f23SThomas Abraham EXPORT_SYMBOL_GPL(dw_mci_pltfm_register); 6017403f23SThomas Abraham 6162ca8034SShashidhar Hiremath #ifdef CONFIG_PM_SLEEP 6262ca8034SShashidhar Hiremath /* 6362ca8034SShashidhar Hiremath * TODO: we should probably disable the clock to the card in the suspend path. 6462ca8034SShashidhar Hiremath */ 6562ca8034SShashidhar Hiremath static int dw_mci_pltfm_suspend(struct device *dev) 6662ca8034SShashidhar Hiremath { 6762ca8034SShashidhar Hiremath struct dw_mci *host = dev_get_drvdata(dev); 6862ca8034SShashidhar Hiremath 69dd369800SAndy Shevchenko return dw_mci_suspend(host); 7062ca8034SShashidhar Hiremath } 7162ca8034SShashidhar Hiremath 7262ca8034SShashidhar Hiremath static int dw_mci_pltfm_resume(struct device *dev) 7362ca8034SShashidhar Hiremath { 7462ca8034SShashidhar Hiremath struct dw_mci *host = dev_get_drvdata(dev); 7562ca8034SShashidhar Hiremath 76dd369800SAndy Shevchenko return dw_mci_resume(host); 7762ca8034SShashidhar Hiremath } 7862ca8034SShashidhar Hiremath #endif /* CONFIG_PM_SLEEP */ 7962ca8034SShashidhar Hiremath 8017403f23SThomas Abraham SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume); 8117403f23SThomas Abraham EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops); 8262ca8034SShashidhar Hiremath 83c91eab4bSThomas Abraham static const struct of_device_id dw_mci_pltfm_match[] = { 84c91eab4bSThomas Abraham { .compatible = "snps,dw-mshc", }, 85aaaaeb7aSJaehoon Chung { .compatible = "altr,socfpga-dw-mshc", }, 86aaaaeb7aSJaehoon Chung { .compatible = "img,pistachio-dw-mshc", }, 87c91eab4bSThomas Abraham {}, 88c91eab4bSThomas Abraham }; 89c91eab4bSThomas Abraham MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match); 90c91eab4bSThomas Abraham 91b177a530SHeiko Stübner static int dw_mci_pltfm_probe(struct platform_device *pdev) 92b177a530SHeiko Stübner { 93c73e41c8SHeiko Stübner const struct dw_mci_drv_data *drv_data = NULL; 94c73e41c8SHeiko Stübner const struct of_device_id *match; 95c73e41c8SHeiko Stübner 96c73e41c8SHeiko Stübner if (pdev->dev.of_node) { 97c73e41c8SHeiko Stübner match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node); 98c73e41c8SHeiko Stübner drv_data = match->data; 99c73e41c8SHeiko Stübner } 100c73e41c8SHeiko Stübner 101c73e41c8SHeiko Stübner return dw_mci_pltfm_register(pdev, drv_data); 102b177a530SHeiko Stübner } 103b177a530SHeiko Stübner 104b177a530SHeiko Stübner int dw_mci_pltfm_remove(struct platform_device *pdev) 105b177a530SHeiko Stübner { 106b177a530SHeiko Stübner struct dw_mci *host = platform_get_drvdata(pdev); 107b177a530SHeiko Stübner 108b177a530SHeiko Stübner dw_mci_remove(host); 109b177a530SHeiko Stübner return 0; 110b177a530SHeiko Stübner } 111b177a530SHeiko Stübner EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove); 112b177a530SHeiko Stübner 11362ca8034SShashidhar Hiremath static struct platform_driver dw_mci_pltfm_driver = { 11449480cf2SAndy Shevchenko .probe = dw_mci_pltfm_probe, 1154e608e4eSGreg Kroah-Hartman .remove = dw_mci_pltfm_remove, 11662ca8034SShashidhar Hiremath .driver = { 11762ca8034SShashidhar Hiremath .name = "dw_mmc", 118cf109bc0SSachin Kamat .of_match_table = dw_mci_pltfm_match, 11962ca8034SShashidhar Hiremath .pm = &dw_mci_pltfm_pmops, 12062ca8034SShashidhar Hiremath }, 12162ca8034SShashidhar Hiremath }; 12262ca8034SShashidhar Hiremath 12349480cf2SAndy Shevchenko module_platform_driver(dw_mci_pltfm_driver); 12462ca8034SShashidhar Hiremath 12562ca8034SShashidhar Hiremath MODULE_DESCRIPTION("DW Multimedia Card Interface driver"); 12662ca8034SShashidhar Hiremath MODULE_AUTHOR("NXP Semiconductor VietNam"); 12762ca8034SShashidhar Hiremath MODULE_AUTHOR("Imagination Technologies Ltd"); 12862ca8034SShashidhar Hiremath MODULE_LICENSE("GPL v2"); 129