dw_mmc-pltfm.c 3.2 KB

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