ufshcd-pltfrm.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Universal Flash Storage Host controller Platform bus based glue driver
  3. *
  4. * This code is based on drivers/scsi/ufs/ufshcd-pltfrm.c
  5. * Copyright (C) 2011-2013 Samsung India Software Operations
  6. *
  7. * Authors:
  8. * Santosh Yaraganavi <santosh.sy@samsung.com>
  9. * Vinayak Holikatti <h.vinayak@samsung.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. * See the COPYING file in the top-level directory or visit
  16. * <http://www.gnu.org/licenses/gpl-2.0.html>
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * This program is provided "AS IS" and "WITH ALL FAULTS" and
  24. * without warranty of any kind. You are solely responsible for
  25. * determining the appropriateness of using and distributing
  26. * the program and assume all risks associated with your exercise
  27. * of rights with respect to the program, including but not limited
  28. * to infringement of third party rights, the risks and costs of
  29. * program errors, damage to or loss of data, programs or equipment,
  30. * and unavailability or interruption of operations. Under no
  31. * circumstances will the contributor of this Program be liable for
  32. * any damages of any kind arising from your use or distribution of
  33. * this program.
  34. */
  35. #include <linux/platform_device.h>
  36. #include <linux/pm_runtime.h>
  37. #include "ufshcd.h"
  38. #ifdef CONFIG_PM
  39. /**
  40. * ufshcd_pltfrm_suspend - suspend power management function
  41. * @dev: pointer to device handle
  42. *
  43. *
  44. * Returns 0
  45. */
  46. static int ufshcd_pltfrm_suspend(struct device *dev)
  47. {
  48. struct platform_device *pdev = to_platform_device(dev);
  49. struct ufs_hba *hba = platform_get_drvdata(pdev);
  50. /*
  51. * TODO:
  52. * 1. Call ufshcd_suspend
  53. * 2. Do bus specific power management
  54. */
  55. disable_irq(hba->irq);
  56. return 0;
  57. }
  58. /**
  59. * ufshcd_pltfrm_resume - resume power management function
  60. * @dev: pointer to device handle
  61. *
  62. * Returns 0
  63. */
  64. static int ufshcd_pltfrm_resume(struct device *dev)
  65. {
  66. struct platform_device *pdev = to_platform_device(dev);
  67. struct ufs_hba *hba = platform_get_drvdata(pdev);
  68. /*
  69. * TODO:
  70. * 1. Call ufshcd_resume.
  71. * 2. Do bus specific wake up
  72. */
  73. enable_irq(hba->irq);
  74. return 0;
  75. }
  76. #else
  77. #define ufshcd_pltfrm_suspend NULL
  78. #define ufshcd_pltfrm_resume NULL
  79. #endif
  80. #ifdef CONFIG_PM_RUNTIME
  81. static int ufshcd_pltfrm_runtime_suspend(struct device *dev)
  82. {
  83. struct ufs_hba *hba = dev_get_drvdata(dev);
  84. if (!hba)
  85. return 0;
  86. return ufshcd_runtime_suspend(hba);
  87. }
  88. static int ufshcd_pltfrm_runtime_resume(struct device *dev)
  89. {
  90. struct ufs_hba *hba = dev_get_drvdata(dev);
  91. if (!hba)
  92. return 0;
  93. return ufshcd_runtime_resume(hba);
  94. }
  95. static int ufshcd_pltfrm_runtime_idle(struct device *dev)
  96. {
  97. struct ufs_hba *hba = dev_get_drvdata(dev);
  98. if (!hba)
  99. return 0;
  100. return ufshcd_runtime_idle(hba);
  101. }
  102. #else /* !CONFIG_PM_RUNTIME */
  103. #define ufshcd_pltfrm_runtime_suspend NULL
  104. #define ufshcd_pltfrm_runtime_resume NULL
  105. #define ufshcd_pltfrm_runtime_idle NULL
  106. #endif /* CONFIG_PM_RUNTIME */
  107. /**
  108. * ufshcd_pltfrm_probe - probe routine of the driver
  109. * @pdev: pointer to Platform device handle
  110. *
  111. * Returns 0 on success, non-zero value on failure
  112. */
  113. static int ufshcd_pltfrm_probe(struct platform_device *pdev)
  114. {
  115. struct ufs_hba *hba;
  116. void __iomem *mmio_base;
  117. struct resource *mem_res;
  118. int irq, err;
  119. struct device *dev = &pdev->dev;
  120. mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  121. if (!mem_res) {
  122. dev_err(dev, "Memory resource not available\n");
  123. err = -ENODEV;
  124. goto out;
  125. }
  126. mmio_base = devm_ioremap_resource(dev, mem_res);
  127. if (IS_ERR(mmio_base)) {
  128. err = PTR_ERR(mmio_base);
  129. goto out;
  130. }
  131. irq = platform_get_irq(pdev, 0);
  132. if (irq < 0) {
  133. dev_err(dev, "IRQ resource not available\n");
  134. err = -ENODEV;
  135. goto out;
  136. }
  137. pm_runtime_set_active(&pdev->dev);
  138. pm_runtime_enable(&pdev->dev);
  139. err = ufshcd_init(dev, &hba, mmio_base, irq);
  140. if (err) {
  141. dev_err(dev, "Intialization failed\n");
  142. goto out_disable_rpm;
  143. }
  144. platform_set_drvdata(pdev, hba);
  145. return 0;
  146. out_disable_rpm:
  147. pm_runtime_disable(&pdev->dev);
  148. pm_runtime_set_suspended(&pdev->dev);
  149. out:
  150. return err;
  151. }
  152. /**
  153. * ufshcd_pltfrm_remove - remove platform driver routine
  154. * @pdev: pointer to platform device handle
  155. *
  156. * Returns 0 on success, non-zero value on failure
  157. */
  158. static int ufshcd_pltfrm_remove(struct platform_device *pdev)
  159. {
  160. struct ufs_hba *hba = platform_get_drvdata(pdev);
  161. pm_runtime_get_sync(&(pdev)->dev);
  162. ufshcd_remove(hba);
  163. return 0;
  164. }
  165. static const struct of_device_id ufs_of_match[] = {
  166. { .compatible = "jedec,ufs-1.1"},
  167. {},
  168. };
  169. static const struct dev_pm_ops ufshcd_dev_pm_ops = {
  170. .suspend = ufshcd_pltfrm_suspend,
  171. .resume = ufshcd_pltfrm_resume,
  172. .runtime_suspend = ufshcd_pltfrm_runtime_suspend,
  173. .runtime_resume = ufshcd_pltfrm_runtime_resume,
  174. .runtime_idle = ufshcd_pltfrm_runtime_idle,
  175. };
  176. static struct platform_driver ufshcd_pltfrm_driver = {
  177. .probe = ufshcd_pltfrm_probe,
  178. .remove = ufshcd_pltfrm_remove,
  179. .driver = {
  180. .name = "ufshcd",
  181. .owner = THIS_MODULE,
  182. .pm = &ufshcd_dev_pm_ops,
  183. .of_match_table = ufs_of_match,
  184. },
  185. };
  186. module_platform_driver(ufshcd_pltfrm_driver);
  187. MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
  188. MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
  189. MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver");
  190. MODULE_LICENSE("GPL");
  191. MODULE_VERSION(UFSHCD_DRIVER_VERSION);