tmio_mmc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_SLEEP
  24. static int tmio_mmc_suspend(struct device *dev)
  25. {
  26. struct platform_device *pdev = to_platform_device(dev);
  27. const struct mfd_cell *cell = mfd_get_cell(pdev);
  28. int ret;
  29. ret = pm_runtime_force_suspend(dev);
  30. /* Tell MFD core it can disable us now.*/
  31. if (!ret && cell->disable)
  32. cell->disable(pdev);
  33. return ret;
  34. }
  35. static int tmio_mmc_resume(struct device *dev)
  36. {
  37. struct platform_device *pdev = to_platform_device(dev);
  38. const struct mfd_cell *cell = mfd_get_cell(pdev);
  39. int ret = 0;
  40. /* Tell the MFD core we are ready to be enabled */
  41. if (cell->resume)
  42. ret = cell->resume(pdev);
  43. if (!ret)
  44. ret = pm_runtime_force_resume(dev);
  45. return ret;
  46. }
  47. #endif
  48. static int tmio_mmc_probe(struct platform_device *pdev)
  49. {
  50. const struct mfd_cell *cell = mfd_get_cell(pdev);
  51. struct tmio_mmc_data *pdata;
  52. struct tmio_mmc_host *host;
  53. struct resource *res;
  54. int ret = -EINVAL, irq;
  55. if (pdev->num_resources != 2)
  56. goto out;
  57. pdata = pdev->dev.platform_data;
  58. if (!pdata || !pdata->hclk)
  59. goto out;
  60. irq = platform_get_irq(pdev, 0);
  61. if (irq < 0) {
  62. ret = irq;
  63. goto out;
  64. }
  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. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  72. if (!res) {
  73. ret = -EINVAL;
  74. goto cell_disable;
  75. }
  76. pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
  77. host = tmio_mmc_host_alloc(pdev);
  78. if (!host)
  79. goto cell_disable;
  80. /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
  81. host->bus_shift = resource_size(res) >> 10;
  82. ret = tmio_mmc_host_probe(host, pdata);
  83. if (ret)
  84. goto host_free;
  85. ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq,
  86. IRQF_TRIGGER_FALLING,
  87. dev_name(&pdev->dev), host);
  88. if (ret)
  89. goto host_remove;
  90. pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
  91. (unsigned long)host->ctl, irq);
  92. return 0;
  93. host_remove:
  94. tmio_mmc_host_remove(host);
  95. host_free:
  96. tmio_mmc_host_free(host);
  97. cell_disable:
  98. if (cell->disable)
  99. cell->disable(pdev);
  100. out:
  101. return ret;
  102. }
  103. static int tmio_mmc_remove(struct platform_device *pdev)
  104. {
  105. const struct mfd_cell *cell = mfd_get_cell(pdev);
  106. struct mmc_host *mmc = platform_get_drvdata(pdev);
  107. if (mmc) {
  108. struct tmio_mmc_host *host = mmc_priv(mmc);
  109. tmio_mmc_host_remove(host);
  110. if (cell->disable)
  111. cell->disable(pdev);
  112. }
  113. return 0;
  114. }
  115. /* ------------------- device registration ----------------------- */
  116. static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
  117. SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
  118. SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
  119. tmio_mmc_host_runtime_resume,
  120. NULL)
  121. };
  122. static struct platform_driver tmio_mmc_driver = {
  123. .driver = {
  124. .name = "tmio-mmc",
  125. .pm = &tmio_mmc_dev_pm_ops,
  126. },
  127. .probe = tmio_mmc_probe,
  128. .remove = tmio_mmc_remove,
  129. };
  130. module_platform_driver(tmio_mmc_driver);
  131. MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
  132. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  133. MODULE_LICENSE("GPL v2");
  134. MODULE_ALIAS("platform:tmio-mmc");