dw_mmc-pltfm.c 3.4 KB

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