dw_mmc-pltfm.c 3.0 KB

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