tmio_mmc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 = tmio_mmc_host_suspend(&dev->dev);
  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. ret = tmio_mmc_host_resume(&dev->dev);
  45. return ret;
  46. }
  47. #else
  48. #define tmio_mmc_suspend NULL
  49. #define tmio_mmc_resume NULL
  50. #endif
  51. static int __devinit tmio_mmc_probe(struct platform_device *pdev)
  52. {
  53. const struct mfd_cell *cell = mfd_get_cell(pdev);
  54. struct tmio_mmc_data *pdata;
  55. struct tmio_mmc_host *host;
  56. int ret = -EINVAL, irq;
  57. if (pdev->num_resources != 2)
  58. goto out;
  59. pdata = pdev->dev.platform_data;
  60. if (!pdata || !pdata->hclk)
  61. goto out;
  62. irq = platform_get_irq(pdev, 0);
  63. if (irq < 0) {
  64. ret = irq;
  65. goto out;
  66. }
  67. /* Tell the MFD core we are ready to be enabled */
  68. if (cell->enable) {
  69. ret = cell->enable(pdev);
  70. if (ret)
  71. goto out;
  72. }
  73. ret = tmio_mmc_host_probe(&host, pdev, pdata);
  74. if (ret)
  75. goto cell_disable;
  76. ret = request_irq(irq, tmio_mmc_irq, IRQF_DISABLED |
  77. IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), host);
  78. if (ret)
  79. goto host_remove;
  80. pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
  81. (unsigned long)host->ctl, irq);
  82. return 0;
  83. host_remove:
  84. tmio_mmc_host_remove(host);
  85. cell_disable:
  86. if (cell->disable)
  87. cell->disable(pdev);
  88. out:
  89. return ret;
  90. }
  91. static int __devexit tmio_mmc_remove(struct platform_device *pdev)
  92. {
  93. const struct mfd_cell *cell = mfd_get_cell(pdev);
  94. struct mmc_host *mmc = platform_get_drvdata(pdev);
  95. platform_set_drvdata(pdev, NULL);
  96. if (mmc) {
  97. struct tmio_mmc_host *host = mmc_priv(mmc);
  98. free_irq(platform_get_irq(pdev, 0), host);
  99. tmio_mmc_host_remove(host);
  100. if (cell->disable)
  101. cell->disable(pdev);
  102. }
  103. return 0;
  104. }
  105. /* ------------------- device registration ----------------------- */
  106. static struct platform_driver tmio_mmc_driver = {
  107. .driver = {
  108. .name = "tmio-mmc",
  109. .owner = THIS_MODULE,
  110. },
  111. .probe = tmio_mmc_probe,
  112. .remove = __devexit_p(tmio_mmc_remove),
  113. .suspend = tmio_mmc_suspend,
  114. .resume = tmio_mmc_resume,
  115. };
  116. static int __init tmio_mmc_init(void)
  117. {
  118. return platform_driver_register(&tmio_mmc_driver);
  119. }
  120. static void __exit tmio_mmc_exit(void)
  121. {
  122. platform_driver_unregister(&tmio_mmc_driver);
  123. }
  124. module_init(tmio_mmc_init);
  125. module_exit(tmio_mmc_exit);
  126. MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
  127. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  128. MODULE_LICENSE("GPL v2");
  129. MODULE_ALIAS("platform:tmio-mmc");