dw_mmc-pltfm.c 3.0 KB

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