dw_mmc-pltfm.c 3.5 KB

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