tmio_mmc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Driver for the MMC / SD / SDIO cell found in:
  3. *
  4. * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
  5. *
  6. * Copyright (C) 2017 Renesas Electronics Corporation
  7. * Copyright (C) 2017 Horms Solutions, Simon Horman
  8. * Copyright (C) 2007 Ian Molton
  9. * Copyright (C) 2004 Ian Molton
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  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, pdata);
  78. if (IS_ERR(host)) {
  79. ret = PTR_ERR(host);
  80. goto cell_disable;
  81. }
  82. /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
  83. host->bus_shift = resource_size(res) >> 10;
  84. host->mmc->f_max = pdata->hclk;
  85. host->mmc->f_min = pdata->hclk / 512;
  86. ret = tmio_mmc_host_probe(host);
  87. if (ret)
  88. goto host_free;
  89. ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq,
  90. IRQF_TRIGGER_FALLING,
  91. dev_name(&pdev->dev), host);
  92. if (ret)
  93. goto host_remove;
  94. pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
  95. (unsigned long)host->ctl, irq);
  96. return 0;
  97. host_remove:
  98. tmio_mmc_host_remove(host);
  99. host_free:
  100. tmio_mmc_host_free(host);
  101. cell_disable:
  102. if (cell->disable)
  103. cell->disable(pdev);
  104. out:
  105. return ret;
  106. }
  107. static int tmio_mmc_remove(struct platform_device *pdev)
  108. {
  109. const struct mfd_cell *cell = mfd_get_cell(pdev);
  110. struct tmio_mmc_host *host = platform_get_drvdata(pdev);
  111. tmio_mmc_host_remove(host);
  112. if (cell->disable)
  113. cell->disable(pdev);
  114. return 0;
  115. }
  116. /* ------------------- device registration ----------------------- */
  117. static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
  118. SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
  119. SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
  120. tmio_mmc_host_runtime_resume, 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");