tmio_mmc.c 3.3 KB

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