1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Synopsys DesignWare Multimedia Card Interface driver 4 * 5 * Copyright (C) 2009 NXP Semiconductors 6 * Copyright (C) 2009, 2010 Imagination Technologies Ltd. 7 */ 8 9 #include <linux/err.h> 10 #include <linux/interrupt.h> 11 #include <linux/module.h> 12 #include <linux/io.h> 13 #include <linux/irq.h> 14 #include <linux/platform_device.h> 15 #include <linux/pm_runtime.h> 16 #include <linux/slab.h> 17 #include <linux/mmc/host.h> 18 #include <linux/mmc/mmc.h> 19 #include <linux/of.h> 20 21 #include "dw_mmc.h" 22 #include "dw_mmc-pltfm.h" 23 24 int dw_mci_pltfm_register(struct platform_device *pdev, 25 const struct dw_mci_drv_data *drv_data) 26 { 27 struct dw_mci *host; 28 struct resource *regs; 29 30 host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL); 31 if (!host) 32 return -ENOMEM; 33 34 host->irq = platform_get_irq(pdev, 0); 35 if (host->irq < 0) 36 return host->irq; 37 38 host->drv_data = drv_data; 39 host->dev = &pdev->dev; 40 host->irq_flags = 0; 41 host->pdata = pdev->dev.platform_data; 42 43 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 44 host->regs = devm_ioremap_resource(&pdev->dev, regs); 45 if (IS_ERR(host->regs)) 46 return PTR_ERR(host->regs); 47 48 /* Get registers' physical base address */ 49 host->phy_regs = regs->start; 50 51 platform_set_drvdata(pdev, host); 52 return dw_mci_probe(host); 53 } 54 EXPORT_SYMBOL_GPL(dw_mci_pltfm_register); 55 56 const struct dev_pm_ops dw_mci_pltfm_pmops = { 57 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 58 pm_runtime_force_resume) 59 SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend, 60 dw_mci_runtime_resume, 61 NULL) 62 }; 63 EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops); 64 65 static const struct of_device_id dw_mci_pltfm_match[] = { 66 { .compatible = "snps,dw-mshc", }, 67 { .compatible = "altr,socfpga-dw-mshc", }, 68 { .compatible = "img,pistachio-dw-mshc", }, 69 {}, 70 }; 71 MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match); 72 73 static int dw_mci_pltfm_probe(struct platform_device *pdev) 74 { 75 const struct dw_mci_drv_data *drv_data = NULL; 76 const struct of_device_id *match; 77 78 if (pdev->dev.of_node) { 79 match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node); 80 drv_data = match->data; 81 } 82 83 return dw_mci_pltfm_register(pdev, drv_data); 84 } 85 86 int dw_mci_pltfm_remove(struct platform_device *pdev) 87 { 88 struct dw_mci *host = platform_get_drvdata(pdev); 89 90 dw_mci_remove(host); 91 return 0; 92 } 93 EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove); 94 95 static struct platform_driver dw_mci_pltfm_driver = { 96 .probe = dw_mci_pltfm_probe, 97 .remove = dw_mci_pltfm_remove, 98 .driver = { 99 .name = "dw_mmc", 100 .probe_type = PROBE_PREFER_ASYNCHRONOUS, 101 .of_match_table = dw_mci_pltfm_match, 102 .pm = &dw_mci_pltfm_pmops, 103 }, 104 }; 105 106 module_platform_driver(dw_mci_pltfm_driver); 107 108 MODULE_DESCRIPTION("DW Multimedia Card Interface driver"); 109 MODULE_AUTHOR("NXP Semiconductor VietNam"); 110 MODULE_AUTHOR("Imagination Technologies Ltd"); 111 MODULE_LICENSE("GPL v2"); 112