dw_mmc-pltfm.c 3.5 KB

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