ufshcd-pltfrm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 "ufshcd.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. int irq, err;
  91. struct device *dev = &pdev->dev;
  92. mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  93. if (!mem_res) {
  94. dev_err(dev, "Memory resource not available\n");
  95. err = -ENODEV;
  96. goto out;
  97. }
  98. mmio_base = devm_ioremap_resource(dev, mem_res);
  99. if (IS_ERR(mmio_base)) {
  100. dev_err(dev, "memory map failed\n");
  101. err = PTR_ERR(mmio_base);
  102. goto out;
  103. }
  104. irq = platform_get_irq(pdev, 0);
  105. if (irq < 0) {
  106. dev_err(dev, "IRQ resource not available\n");
  107. err = -ENODEV;
  108. goto out;
  109. }
  110. err = ufshcd_init(dev, &hba, mmio_base, irq);
  111. if (err) {
  112. dev_err(dev, "Intialization failed\n");
  113. goto out;
  114. }
  115. platform_set_drvdata(pdev, hba);
  116. out:
  117. return err;
  118. }
  119. /**
  120. * ufshcd_pltfrm_remove - remove platform driver routine
  121. * @pdev: pointer to platform device handle
  122. *
  123. * Returns 0 on success, non-zero value on failure
  124. */
  125. static int ufshcd_pltfrm_remove(struct platform_device *pdev)
  126. {
  127. struct ufs_hba *hba = platform_get_drvdata(pdev);
  128. disable_irq(hba->irq);
  129. ufshcd_remove(hba);
  130. return 0;
  131. }
  132. static const struct of_device_id ufs_of_match[] = {
  133. { .compatible = "jedec,ufs-1.1"},
  134. {},
  135. };
  136. static const struct dev_pm_ops ufshcd_dev_pm_ops = {
  137. .suspend = ufshcd_pltfrm_suspend,
  138. .resume = ufshcd_pltfrm_resume,
  139. };
  140. static struct platform_driver ufshcd_pltfrm_driver = {
  141. .probe = ufshcd_pltfrm_probe,
  142. .remove = ufshcd_pltfrm_remove,
  143. .driver = {
  144. .name = "ufshcd",
  145. .owner = THIS_MODULE,
  146. .pm = &ufshcd_dev_pm_ops,
  147. .of_match_table = ufs_of_match,
  148. },
  149. };
  150. module_platform_driver(ufshcd_pltfrm_driver);
  151. MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
  152. MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
  153. MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver");
  154. MODULE_LICENSE("GPL");
  155. MODULE_VERSION(UFSHCD_DRIVER_VERSION);