ufshcd-pltfrm.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 "ufshcd.h"
  36. #include <linux/platform_device.h>
  37. #ifdef CONFIG_PM
  38. /**
  39. * ufshcd_pltfrm_suspend - suspend power management function
  40. * @dev: pointer to device handle
  41. *
  42. *
  43. * Returns 0
  44. */
  45. static int ufshcd_pltfrm_suspend(struct device *dev)
  46. {
  47. struct platform_device *pdev = to_platform_device(dev);
  48. struct ufs_hba *hba = platform_get_drvdata(pdev);
  49. /*
  50. * TODO:
  51. * 1. Call ufshcd_suspend
  52. * 2. Do bus specific power management
  53. */
  54. disable_irq(hba->irq);
  55. return 0;
  56. }
  57. /**
  58. * ufshcd_pltfrm_resume - resume power management function
  59. * @dev: pointer to device handle
  60. *
  61. * Returns 0
  62. */
  63. static int ufshcd_pltfrm_resume(struct device *dev)
  64. {
  65. struct platform_device *pdev = to_platform_device(dev);
  66. struct ufs_hba *hba = platform_get_drvdata(pdev);
  67. /*
  68. * TODO:
  69. * 1. Call ufshcd_resume.
  70. * 2. Do bus specific wake up
  71. */
  72. enable_irq(hba->irq);
  73. return 0;
  74. }
  75. #else
  76. #define ufshcd_pltfrm_suspend NULL
  77. #define ufshcd_pltfrm_resume NULL
  78. #endif
  79. /**
  80. * ufshcd_pltfrm_probe - probe routine of the driver
  81. * @pdev: pointer to Platform device handle
  82. *
  83. * Returns 0 on success, non-zero value on failure
  84. */
  85. static int ufshcd_pltfrm_probe(struct platform_device *pdev)
  86. {
  87. struct ufs_hba *hba;
  88. void __iomem *mmio_base;
  89. struct resource *mem_res;
  90. struct resource *irq_res;
  91. resource_size_t mem_size;
  92. int err;
  93. struct device *dev = &pdev->dev;
  94. mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  95. if (!mem_res) {
  96. dev_err(&pdev->dev,
  97. "Memory resource not available\n");
  98. err = -ENODEV;
  99. goto out_error;
  100. }
  101. mem_size = resource_size(mem_res);
  102. if (!request_mem_region(mem_res->start, mem_size, "ufshcd")) {
  103. dev_err(&pdev->dev,
  104. "Cannot reserve the memory resource\n");
  105. err = -EBUSY;
  106. goto out_error;
  107. }
  108. mmio_base = ioremap_nocache(mem_res->start, mem_size);
  109. if (!mmio_base) {
  110. dev_err(&pdev->dev, "memory map failed\n");
  111. err = -ENOMEM;
  112. goto out_release_regions;
  113. }
  114. irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  115. if (!irq_res) {
  116. dev_err(&pdev->dev, "IRQ resource not available\n");
  117. err = -ENODEV;
  118. goto out_iounmap;
  119. }
  120. err = dma_set_coherent_mask(dev, dev->coherent_dma_mask);
  121. if (err) {
  122. dev_err(&pdev->dev, "set dma mask failed\n");
  123. goto out_iounmap;
  124. }
  125. err = ufshcd_init(&pdev->dev, &hba, mmio_base, irq_res->start);
  126. if (err) {
  127. dev_err(&pdev->dev, "Intialization failed\n");
  128. goto out_iounmap;
  129. }
  130. platform_set_drvdata(pdev, hba);
  131. return 0;
  132. out_iounmap:
  133. iounmap(mmio_base);
  134. out_release_regions:
  135. release_mem_region(mem_res->start, mem_size);
  136. out_error:
  137. return err;
  138. }
  139. /**
  140. * ufshcd_pltfrm_remove - remove platform driver routine
  141. * @pdev: pointer to platform device handle
  142. *
  143. * Returns 0 on success, non-zero value on failure
  144. */
  145. static int ufshcd_pltfrm_remove(struct platform_device *pdev)
  146. {
  147. struct resource *mem_res;
  148. resource_size_t mem_size;
  149. struct ufs_hba *hba = platform_get_drvdata(pdev);
  150. disable_irq(hba->irq);
  151. /* Some buggy controllers raise interrupt after
  152. * the resources are removed. So first we unregister the
  153. * irq handler and then the resources used by driver
  154. */
  155. free_irq(hba->irq, hba);
  156. ufshcd_remove(hba);
  157. mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  158. if (!mem_res)
  159. dev_err(&pdev->dev, "ufshcd: Memory resource not available\n");
  160. else {
  161. mem_size = resource_size(mem_res);
  162. release_mem_region(mem_res->start, mem_size);
  163. }
  164. platform_set_drvdata(pdev, NULL);
  165. return 0;
  166. }
  167. static const struct of_device_id ufs_of_match[] = {
  168. { .compatible = "jedec,ufs-1.1"},
  169. };
  170. static const struct dev_pm_ops ufshcd_dev_pm_ops = {
  171. .suspend = ufshcd_pltfrm_suspend,
  172. .resume = ufshcd_pltfrm_resume,
  173. };
  174. static struct platform_driver ufshcd_pltfrm_driver = {
  175. .probe = ufshcd_pltfrm_probe,
  176. .remove = ufshcd_pltfrm_remove,
  177. .driver = {
  178. .name = "ufshcd",
  179. .owner = THIS_MODULE,
  180. .pm = &ufshcd_dev_pm_ops,
  181. .of_match_table = ufs_of_match,
  182. },
  183. };
  184. module_platform_driver(ufshcd_pltfrm_driver);
  185. MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
  186. MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
  187. MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver");
  188. MODULE_LICENSE("GPL");
  189. MODULE_VERSION(UFSHCD_DRIVER_VERSION);