dw_mmc-pltfm.c 3.0 KB

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