dw_mmc-pltfm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/interrupt.h>
  13. #include <linux/module.h>
  14. #include <linux/io.h>
  15. #include <linux/irq.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/slab.h>
  18. #include <linux/mmc/host.h>
  19. #include <linux/mmc/mmc.h>
  20. #include <linux/mmc/dw_mmc.h>
  21. #include "dw_mmc.h"
  22. static int dw_mci_pltfm_probe(struct platform_device *pdev)
  23. {
  24. struct dw_mci *host;
  25. struct resource *regs;
  26. int ret;
  27. host = kzalloc(sizeof(struct dw_mci), GFP_KERNEL);
  28. if (!host)
  29. return -ENOMEM;
  30. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31. if (!regs) {
  32. ret = -ENXIO;
  33. goto err_free;
  34. }
  35. host->irq = platform_get_irq(pdev, 0);
  36. if (host->irq < 0) {
  37. ret = host->irq;
  38. goto err_free;
  39. }
  40. host->dev = pdev->dev;
  41. host->irq_flags = 0;
  42. host->pdata = pdev->dev.platform_data;
  43. ret = -ENOMEM;
  44. host->regs = ioremap(regs->start, resource_size(regs));
  45. if (!host->regs)
  46. goto err_free;
  47. platform_set_drvdata(pdev, host);
  48. ret = dw_mci_probe(host);
  49. if (ret)
  50. goto err_out;
  51. return ret;
  52. err_out:
  53. iounmap(host->regs);
  54. err_free:
  55. kfree(host);
  56. return ret;
  57. }
  58. static int __exit dw_mci_pltfm_remove(struct platform_device *pdev)
  59. {
  60. struct dw_mci *host = platform_get_drvdata(pdev);
  61. platform_set_drvdata(pdev, NULL);
  62. dw_mci_remove(host);
  63. iounmap(host->regs);
  64. kfree(host);
  65. return 0;
  66. }
  67. #ifdef CONFIG_PM_SLEEP
  68. /*
  69. * TODO: we should probably disable the clock to the card in the suspend path.
  70. */
  71. static int dw_mci_pltfm_suspend(struct device *dev)
  72. {
  73. int ret;
  74. struct dw_mci *host = dev_get_drvdata(dev);
  75. ret = dw_mci_suspend(host);
  76. if (ret)
  77. return ret;
  78. return 0;
  79. }
  80. static int dw_mci_pltfm_resume(struct device *dev)
  81. {
  82. int ret;
  83. struct dw_mci *host = dev_get_drvdata(dev);
  84. ret = dw_mci_resume(host);
  85. if (ret)
  86. return ret;
  87. return 0;
  88. }
  89. #else
  90. #define dw_mci_pltfm_suspend NULL
  91. #define dw_mci_pltfm_resume NULL
  92. #endif /* CONFIG_PM_SLEEP */
  93. static SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume);
  94. static struct platform_driver dw_mci_pltfm_driver = {
  95. .remove = __exit_p(dw_mci_pltfm_remove),
  96. .driver = {
  97. .name = "dw_mmc",
  98. .pm = &dw_mci_pltfm_pmops,
  99. },
  100. };
  101. static int __init dw_mci_init(void)
  102. {
  103. return platform_driver_probe(&dw_mci_pltfm_driver, dw_mci_pltfm_probe);
  104. }
  105. static void __exit dw_mci_exit(void)
  106. {
  107. platform_driver_unregister(&dw_mci_pltfm_driver);
  108. }
  109. module_init(dw_mci_init);
  110. module_exit(dw_mci_exit);
  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");