dw_mmc-pltfm.c 3.0 KB

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