tmio_mmc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * linux/drivers/mmc/host/tmio_mmc.c
  3. *
  4. * Copyright (C) 2007 Ian Molton
  5. * Copyright (C) 2004 Ian Molton
  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 version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Driver for the MMC / SD / SDIO cell found in:
  12. *
  13. * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
  14. */
  15. #include <linux/device.h>
  16. #include <linux/mfd/core.h>
  17. #include <linux/mfd/tmio.h>
  18. #include <linux/mmc/host.h>
  19. #include <linux/module.h>
  20. #include <linux/pagemap.h>
  21. #include <linux/scatterlist.h>
  22. #include "tmio_mmc.h"
  23. #ifdef CONFIG_PM
  24. static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state)
  25. {
  26. const struct mfd_cell *cell = mfd_get_cell(dev);
  27. struct mmc_host *mmc = platform_get_drvdata(dev);
  28. int ret;
  29. ret = mmc_suspend_host(mmc);
  30. /* Tell MFD core it can disable us now.*/
  31. if (!ret && cell->disable)
  32. cell->disable(dev);
  33. return ret;
  34. }
  35. static int tmio_mmc_resume(struct platform_device *dev)
  36. {
  37. const struct mfd_cell *cell = mfd_get_cell(dev);
  38. struct mmc_host *mmc = platform_get_drvdata(dev);
  39. int ret = 0;
  40. /* Tell the MFD core we are ready to be enabled */
  41. if (cell->resume) {
  42. ret = cell->resume(dev);
  43. if (ret)
  44. goto out;
  45. }
  46. mmc_resume_host(mmc);
  47. out:
  48. return ret;
  49. }
  50. #else
  51. #define tmio_mmc_suspend NULL
  52. #define tmio_mmc_resume NULL
  53. #endif
  54. static int __devinit tmio_mmc_probe(struct platform_device *pdev)
  55. {
  56. const struct mfd_cell *cell = mfd_get_cell(pdev);
  57. struct tmio_mmc_data *pdata;
  58. struct tmio_mmc_host *host;
  59. int ret = -EINVAL;
  60. if (pdev->num_resources != 2)
  61. goto out;
  62. pdata = mfd_get_data(pdev);
  63. if (!pdata || !pdata->hclk)
  64. goto out;
  65. /* Tell the MFD core we are ready to be enabled */
  66. if (cell->enable) {
  67. ret = cell->enable(pdev);
  68. if (ret)
  69. goto out;
  70. }
  71. ret = tmio_mmc_host_probe(&host, pdev, pdata);
  72. if (ret)
  73. goto cell_disable;
  74. pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
  75. (unsigned long)host->ctl, host->irq);
  76. return 0;
  77. cell_disable:
  78. if (cell->disable)
  79. cell->disable(pdev);
  80. out:
  81. return ret;
  82. }
  83. static int __devexit tmio_mmc_remove(struct platform_device *pdev)
  84. {
  85. const struct mfd_cell *cell = mfd_get_cell(pdev);
  86. struct mmc_host *mmc = platform_get_drvdata(pdev);
  87. platform_set_drvdata(pdev, NULL);
  88. if (mmc) {
  89. tmio_mmc_host_remove(mmc_priv(mmc));
  90. if (cell->disable)
  91. cell->disable(pdev);
  92. }
  93. return 0;
  94. }
  95. /* ------------------- device registration ----------------------- */
  96. static struct platform_driver tmio_mmc_driver = {
  97. .driver = {
  98. .name = "tmio-mmc",
  99. .owner = THIS_MODULE,
  100. },
  101. .probe = tmio_mmc_probe,
  102. .remove = __devexit_p(tmio_mmc_remove),
  103. .suspend = tmio_mmc_suspend,
  104. .resume = tmio_mmc_resume,
  105. };
  106. static int __init tmio_mmc_init(void)
  107. {
  108. return platform_driver_register(&tmio_mmc_driver);
  109. }
  110. static void __exit tmio_mmc_exit(void)
  111. {
  112. platform_driver_unregister(&tmio_mmc_driver);
  113. }
  114. module_init(tmio_mmc_init);
  115. module_exit(tmio_mmc_exit);
  116. MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
  117. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  118. MODULE_LICENSE("GPL v2");
  119. MODULE_ALIAS("platform:tmio-mmc");