Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Synopsys DesignWare Multimedia Card Interface driver
0004  *
0005  * Copyright (C) 2009 NXP Semiconductors
0006  * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
0007  */
0008 
0009 #include <linux/err.h>
0010 #include <linux/interrupt.h>
0011 #include <linux/module.h>
0012 #include <linux/io.h>
0013 #include <linux/irq.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/pm_runtime.h>
0016 #include <linux/slab.h>
0017 #include <linux/mmc/host.h>
0018 #include <linux/mmc/mmc.h>
0019 #include <linux/of.h>
0020 
0021 #include "dw_mmc.h"
0022 #include "dw_mmc-pltfm.h"
0023 
0024 int dw_mci_pltfm_register(struct platform_device *pdev,
0025               const struct dw_mci_drv_data *drv_data)
0026 {
0027     struct dw_mci *host;
0028     struct resource *regs;
0029 
0030     host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
0031     if (!host)
0032         return -ENOMEM;
0033 
0034     host->irq = platform_get_irq(pdev, 0);
0035     if (host->irq < 0)
0036         return host->irq;
0037 
0038     host->drv_data = drv_data;
0039     host->dev = &pdev->dev;
0040     host->irq_flags = 0;
0041     host->pdata = pdev->dev.platform_data;
0042 
0043     regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0044     host->regs = devm_ioremap_resource(&pdev->dev, regs);
0045     if (IS_ERR(host->regs))
0046         return PTR_ERR(host->regs);
0047 
0048     /* Get registers' physical base address */
0049     host->phy_regs = regs->start;
0050 
0051     platform_set_drvdata(pdev, host);
0052     return dw_mci_probe(host);
0053 }
0054 EXPORT_SYMBOL_GPL(dw_mci_pltfm_register);
0055 
0056 const struct dev_pm_ops dw_mci_pltfm_pmops = {
0057     SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
0058                 pm_runtime_force_resume)
0059     SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
0060                dw_mci_runtime_resume,
0061                NULL)
0062 };
0063 EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops);
0064 
0065 static const struct of_device_id dw_mci_pltfm_match[] = {
0066     { .compatible = "snps,dw-mshc", },
0067     { .compatible = "altr,socfpga-dw-mshc", },
0068     { .compatible = "img,pistachio-dw-mshc", },
0069     {},
0070 };
0071 MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match);
0072 
0073 static int dw_mci_pltfm_probe(struct platform_device *pdev)
0074 {
0075     const struct dw_mci_drv_data *drv_data = NULL;
0076     const struct of_device_id *match;
0077 
0078     if (pdev->dev.of_node) {
0079         match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node);
0080         drv_data = match->data;
0081     }
0082 
0083     return dw_mci_pltfm_register(pdev, drv_data);
0084 }
0085 
0086 int dw_mci_pltfm_remove(struct platform_device *pdev)
0087 {
0088     struct dw_mci *host = platform_get_drvdata(pdev);
0089 
0090     dw_mci_remove(host);
0091     return 0;
0092 }
0093 EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove);
0094 
0095 static struct platform_driver dw_mci_pltfm_driver = {
0096     .probe      = dw_mci_pltfm_probe,
0097     .remove     = dw_mci_pltfm_remove,
0098     .driver     = {
0099         .name       = "dw_mmc",
0100         .probe_type = PROBE_PREFER_ASYNCHRONOUS,
0101         .of_match_table = dw_mci_pltfm_match,
0102         .pm     = &dw_mci_pltfm_pmops,
0103     },
0104 };
0105 
0106 module_platform_driver(dw_mci_pltfm_driver);
0107 
0108 MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
0109 MODULE_AUTHOR("NXP Semiconductor VietNam");
0110 MODULE_AUTHOR("Imagination Technologies Ltd");
0111 MODULE_LICENSE("GPL v2");