dw_mmc-pltfm.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/slab.h>
  19. #include <linux/mmc/host.h>
  20. #include <linux/mmc/mmc.h>
  21. #include <linux/mmc/dw_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. #ifdef CONFIG_PM_SLEEP
  52. /*
  53. * TODO: we should probably disable the clock to the card in the suspend path.
  54. */
  55. static int dw_mci_pltfm_suspend(struct device *dev)
  56. {
  57. struct dw_mci *host = dev_get_drvdata(dev);
  58. return dw_mci_suspend(host);
  59. }
  60. static int dw_mci_pltfm_resume(struct device *dev)
  61. {
  62. struct dw_mci *host = dev_get_drvdata(dev);
  63. return dw_mci_resume(host);
  64. }
  65. #endif /* CONFIG_PM_SLEEP */
  66. SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume);
  67. EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops);
  68. static const struct of_device_id dw_mci_pltfm_match[] = {
  69. { .compatible = "snps,dw-mshc", },
  70. { .compatible = "altr,socfpga-dw-mshc", },
  71. { .compatible = "img,pistachio-dw-mshc", },
  72. {},
  73. };
  74. MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match);
  75. static int dw_mci_pltfm_probe(struct platform_device *pdev)
  76. {
  77. const struct dw_mci_drv_data *drv_data = NULL;
  78. const struct of_device_id *match;
  79. if (pdev->dev.of_node) {
  80. match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node);
  81. drv_data = match->data;
  82. }
  83. return dw_mci_pltfm_register(pdev, drv_data);
  84. }
  85. int dw_mci_pltfm_remove(struct platform_device *pdev)
  86. {
  87. struct dw_mci *host = platform_get_drvdata(pdev);
  88. dw_mci_remove(host);
  89. return 0;
  90. }
  91. EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove);
  92. static struct platform_driver dw_mci_pltfm_driver = {
  93. .probe = dw_mci_pltfm_probe,
  94. .remove = dw_mci_pltfm_remove,
  95. .driver = {
  96. .name = "dw_mmc",
  97. .of_match_table = dw_mci_pltfm_match,
  98. .pm = &dw_mci_pltfm_pmops,
  99. },
  100. };
  101. module_platform_driver(dw_mci_pltfm_driver);
  102. MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
  103. MODULE_AUTHOR("NXP Semiconductor VietNam");
  104. MODULE_AUTHOR("Imagination Technologies Ltd");
  105. MODULE_LICENSE("GPL v2");