dw_mmc-pltfm.c 2.8 KB

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