tmio_mmc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 __devinit 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. 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. ret = tmio_mmc_host_probe(&host, pdev, pdata);
  72. if (ret)
  73. goto cell_disable;
  74. ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING,
  75. dev_name(&pdev->dev), host);
  76. if (ret)
  77. goto host_remove;
  78. pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
  79. (unsigned long)host->ctl, irq);
  80. return 0;
  81. host_remove:
  82. tmio_mmc_host_remove(host);
  83. cell_disable:
  84. if (cell->disable)
  85. cell->disable(pdev);
  86. out:
  87. return ret;
  88. }
  89. static int __devexit tmio_mmc_remove(struct platform_device *pdev)
  90. {
  91. const struct mfd_cell *cell = mfd_get_cell(pdev);
  92. struct mmc_host *mmc = platform_get_drvdata(pdev);
  93. platform_set_drvdata(pdev, NULL);
  94. if (mmc) {
  95. struct tmio_mmc_host *host = mmc_priv(mmc);
  96. free_irq(platform_get_irq(pdev, 0), host);
  97. tmio_mmc_host_remove(host);
  98. if (cell->disable)
  99. cell->disable(pdev);
  100. }
  101. return 0;
  102. }
  103. /* ------------------- device registration ----------------------- */
  104. static struct platform_driver tmio_mmc_driver = {
  105. .driver = {
  106. .name = "tmio-mmc",
  107. .owner = THIS_MODULE,
  108. },
  109. .probe = tmio_mmc_probe,
  110. .remove = __devexit_p(tmio_mmc_remove),
  111. .suspend = tmio_mmc_suspend,
  112. .resume = tmio_mmc_resume,
  113. };
  114. module_platform_driver(tmio_mmc_driver);
  115. MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
  116. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  117. MODULE_LICENSE("GPL v2");
  118. MODULE_ALIAS("platform:tmio-mmc");