ufshcd-pci.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Universal Flash Storage Host controller PCI glue driver
  3. *
  4. * This code is based on drivers/scsi/ufs/ufshcd-pci.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/pci.h>
  37. #ifdef CONFIG_PM
  38. /**
  39. * ufshcd_pci_suspend - suspend power management function
  40. * @pdev: pointer to PCI device handle
  41. * @state: power state
  42. *
  43. * Returns -ENOSYS
  44. */
  45. static int ufshcd_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  46. {
  47. /*
  48. * TODO:
  49. * 1. Call ufshcd_suspend
  50. * 2. Do bus specific power management
  51. */
  52. return -ENOSYS;
  53. }
  54. /**
  55. * ufshcd_pci_resume - resume power management function
  56. * @pdev: pointer to PCI device handle
  57. *
  58. * Returns -ENOSYS
  59. */
  60. static int ufshcd_pci_resume(struct pci_dev *pdev)
  61. {
  62. /*
  63. * TODO:
  64. * 1. Call ufshcd_resume.
  65. * 2. Do bus specific wake up
  66. */
  67. return -ENOSYS;
  68. }
  69. #endif /* CONFIG_PM */
  70. /**
  71. * ufshcd_pci_shutdown - main function to put the controller in reset state
  72. * @pdev: pointer to PCI device handle
  73. */
  74. static void ufshcd_pci_shutdown(struct pci_dev *pdev)
  75. {
  76. ufshcd_hba_stop((struct ufs_hba *)pci_get_drvdata(pdev));
  77. }
  78. /**
  79. * ufshcd_pci_remove - de-allocate PCI/SCSI host and host memory space
  80. * data structure memory
  81. * @pdev - pointer to PCI handle
  82. */
  83. static void ufshcd_pci_remove(struct pci_dev *pdev)
  84. {
  85. struct ufs_hba *hba = pci_get_drvdata(pdev);
  86. disable_irq(pdev->irq);
  87. ufshcd_remove(hba);
  88. pci_release_regions(pdev);
  89. pci_set_drvdata(pdev, NULL);
  90. pci_clear_master(pdev);
  91. pci_disable_device(pdev);
  92. }
  93. /**
  94. * ufshcd_set_dma_mask - Set dma mask based on the controller
  95. * addressing capability
  96. * @pdev: PCI device structure
  97. *
  98. * Returns 0 for success, non-zero for failure
  99. */
  100. static int ufshcd_set_dma_mask(struct pci_dev *pdev)
  101. {
  102. int err;
  103. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
  104. && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
  105. return 0;
  106. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  107. if (!err)
  108. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  109. return err;
  110. }
  111. /**
  112. * ufshcd_pci_probe - probe routine of the driver
  113. * @pdev: pointer to PCI device handle
  114. * @id: PCI device id
  115. *
  116. * Returns 0 on success, non-zero value on failure
  117. */
  118. static int
  119. ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  120. {
  121. struct ufs_hba *hba;
  122. void __iomem *mmio_base;
  123. int err;
  124. err = pci_enable_device(pdev);
  125. if (err) {
  126. dev_err(&pdev->dev, "pci_enable_device failed\n");
  127. goto out_error;
  128. }
  129. pci_set_master(pdev);
  130. err = pci_request_regions(pdev, UFSHCD);
  131. if (err < 0) {
  132. dev_err(&pdev->dev, "request regions failed\n");
  133. goto out_disable;
  134. }
  135. mmio_base = pci_ioremap_bar(pdev, 0);
  136. if (!mmio_base) {
  137. dev_err(&pdev->dev, "memory map failed\n");
  138. err = -ENOMEM;
  139. goto out_release_regions;
  140. }
  141. err = ufshcd_set_dma_mask(pdev);
  142. if (err) {
  143. dev_err(&pdev->dev, "set dma mask failed\n");
  144. goto out_iounmap;
  145. }
  146. err = ufshcd_init(&pdev->dev, &hba, mmio_base, pdev->irq);
  147. if (err) {
  148. dev_err(&pdev->dev, "Initialization failed\n");
  149. goto out_iounmap;
  150. }
  151. pci_set_drvdata(pdev, hba);
  152. return 0;
  153. out_iounmap:
  154. iounmap(mmio_base);
  155. out_release_regions:
  156. pci_release_regions(pdev);
  157. out_disable:
  158. pci_clear_master(pdev);
  159. pci_disable_device(pdev);
  160. out_error:
  161. return err;
  162. }
  163. static DEFINE_PCI_DEVICE_TABLE(ufshcd_pci_tbl) = {
  164. { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  165. { } /* terminate list */
  166. };
  167. MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
  168. static struct pci_driver ufshcd_pci_driver = {
  169. .name = UFSHCD,
  170. .id_table = ufshcd_pci_tbl,
  171. .probe = ufshcd_pci_probe,
  172. .remove = ufshcd_pci_remove,
  173. .shutdown = ufshcd_pci_shutdown,
  174. #ifdef CONFIG_PM
  175. .suspend = ufshcd_pci_suspend,
  176. .resume = ufshcd_pci_resume,
  177. #endif
  178. };
  179. module_pci_driver(ufshcd_pci_driver);
  180. MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
  181. MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
  182. MODULE_DESCRIPTION("UFS host controller PCI glue driver");
  183. MODULE_LICENSE("GPL");
  184. MODULE_VERSION(UFSHCD_DRIVER_VERSION);