dw_mmc-pltfm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. static void dw_mci_pltfm_prepare_command(struct dw_mci *host, u32 *cmdr)
  27. {
  28. *cmdr |= SDMMC_CMD_USE_HOLD_REG;
  29. }
  30. static const struct dw_mci_drv_data socfpga_drv_data = {
  31. .prepare_command = dw_mci_pltfm_prepare_command,
  32. };
  33. int dw_mci_pltfm_register(struct platform_device *pdev,
  34. const struct dw_mci_drv_data *drv_data)
  35. {
  36. struct dw_mci *host;
  37. struct resource *regs;
  38. host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
  39. if (!host)
  40. return -ENOMEM;
  41. host->irq = platform_get_irq(pdev, 0);
  42. if (host->irq < 0)
  43. return host->irq;
  44. host->drv_data = drv_data;
  45. host->dev = &pdev->dev;
  46. host->irq_flags = 0;
  47. host->pdata = pdev->dev.platform_data;
  48. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  49. host->regs = devm_ioremap_resource(&pdev->dev, regs);
  50. if (IS_ERR(host->regs))
  51. return PTR_ERR(host->regs);
  52. platform_set_drvdata(pdev, host);
  53. return dw_mci_probe(host);
  54. }
  55. EXPORT_SYMBOL_GPL(dw_mci_pltfm_register);
  56. #ifdef CONFIG_PM_SLEEP
  57. /*
  58. * TODO: we should probably disable the clock to the card in the suspend path.
  59. */
  60. static int dw_mci_pltfm_suspend(struct device *dev)
  61. {
  62. struct dw_mci *host = dev_get_drvdata(dev);
  63. return dw_mci_suspend(host);
  64. }
  65. static int dw_mci_pltfm_resume(struct device *dev)
  66. {
  67. struct dw_mci *host = dev_get_drvdata(dev);
  68. return dw_mci_resume(host);
  69. }
  70. #endif /* CONFIG_PM_SLEEP */
  71. SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume);
  72. EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops);
  73. static const struct of_device_id dw_mci_pltfm_match[] = {
  74. { .compatible = "snps,dw-mshc", },
  75. { .compatible = "altr,socfpga-dw-mshc",
  76. .data = &socfpga_drv_data },
  77. {},
  78. };
  79. MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match);
  80. static int dw_mci_pltfm_probe(struct platform_device *pdev)
  81. {
  82. const struct dw_mci_drv_data *drv_data = NULL;
  83. const struct of_device_id *match;
  84. if (pdev->dev.of_node) {
  85. match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node);
  86. drv_data = match->data;
  87. }
  88. return dw_mci_pltfm_register(pdev, drv_data);
  89. }
  90. int dw_mci_pltfm_remove(struct platform_device *pdev)
  91. {
  92. struct dw_mci *host = platform_get_drvdata(pdev);
  93. dw_mci_remove(host);
  94. return 0;
  95. }
  96. EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove);
  97. static struct platform_driver dw_mci_pltfm_driver = {
  98. .probe = dw_mci_pltfm_probe,
  99. .remove = dw_mci_pltfm_remove,
  100. .driver = {
  101. .name = "dw_mmc",
  102. .of_match_table = dw_mci_pltfm_match,
  103. .pm = &dw_mci_pltfm_pmops,
  104. },
  105. };
  106. module_platform_driver(dw_mci_pltfm_driver);
  107. MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
  108. MODULE_AUTHOR("NXP Semiconductor VietNam");
  109. MODULE_AUTHOR("Imagination Technologies Ltd");
  110. MODULE_LICENSE("GPL v2");