dw_mmc-pltfm.c 2.8 KB

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