tc-dwc-g210-pci.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Synopsys G210 Test Chip driver
  3. *
  4. * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * Authors: Joao Pinto <jpinto@synopsys.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include "ufshcd.h"
  13. #include "ufshcd-dwc.h"
  14. #include "tc-dwc-g210.h"
  15. #include <linux/pci.h>
  16. #include <linux/pm_runtime.h>
  17. /* Test Chip type expected values */
  18. #define TC_G210_20BIT 20
  19. #define TC_G210_40BIT 40
  20. #define TC_G210_INV 0
  21. static int tc_type = TC_G210_INV;
  22. module_param(tc_type, int, 0);
  23. MODULE_PARM_DESC(tc_type, "Test Chip Type (20 = 20-bit, 40 = 40-bit)");
  24. static int tc_dwc_g210_pci_suspend(struct device *dev)
  25. {
  26. return ufshcd_system_suspend(dev_get_drvdata(dev));
  27. }
  28. static int tc_dwc_g210_pci_resume(struct device *dev)
  29. {
  30. return ufshcd_system_resume(dev_get_drvdata(dev));
  31. }
  32. static int tc_dwc_g210_pci_runtime_suspend(struct device *dev)
  33. {
  34. return ufshcd_runtime_suspend(dev_get_drvdata(dev));
  35. }
  36. static int tc_dwc_g210_pci_runtime_resume(struct device *dev)
  37. {
  38. return ufshcd_runtime_resume(dev_get_drvdata(dev));
  39. }
  40. static int tc_dwc_g210_pci_runtime_idle(struct device *dev)
  41. {
  42. return ufshcd_runtime_idle(dev_get_drvdata(dev));
  43. }
  44. /**
  45. * struct ufs_hba_dwc_vops - UFS DWC specific variant operations
  46. */
  47. static struct ufs_hba_variant_ops tc_dwc_g210_pci_hba_vops = {
  48. .name = "tc-dwc-g210-pci",
  49. .link_startup_notify = ufshcd_dwc_link_startup_notify,
  50. };
  51. /**
  52. * tc_dwc_g210_pci_shutdown - main function to put the controller in reset state
  53. * @pdev: pointer to PCI device handle
  54. */
  55. static void tc_dwc_g210_pci_shutdown(struct pci_dev *pdev)
  56. {
  57. ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
  58. }
  59. /**
  60. * tc_dwc_g210_pci_remove - de-allocate PCI/SCSI host and host memory space
  61. * data structure memory
  62. * @pdev - pointer to PCI handle
  63. */
  64. static void tc_dwc_g210_pci_remove(struct pci_dev *pdev)
  65. {
  66. struct ufs_hba *hba = pci_get_drvdata(pdev);
  67. pm_runtime_forbid(&pdev->dev);
  68. pm_runtime_get_noresume(&pdev->dev);
  69. ufshcd_remove(hba);
  70. }
  71. /**
  72. * tc_dwc_g210_pci_probe - probe routine of the driver
  73. * @pdev: pointer to PCI device handle
  74. * @id: PCI device id
  75. *
  76. * Returns 0 on success, non-zero value on failure
  77. */
  78. static int
  79. tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  80. {
  81. struct ufs_hba *hba;
  82. void __iomem *mmio_base;
  83. int err;
  84. /* Check Test Chip type and set the specific setup routine */
  85. if (tc_type == TC_G210_20BIT) {
  86. tc_dwc_g210_pci_hba_vops.phy_initialization =
  87. tc_dwc_g210_config_20_bit;
  88. } else if (tc_type == TC_G210_40BIT) {
  89. tc_dwc_g210_pci_hba_vops.phy_initialization =
  90. tc_dwc_g210_config_40_bit;
  91. } else {
  92. dev_err(&pdev->dev, "test chip version not specified\n");
  93. return -EPERM;
  94. }
  95. err = pcim_enable_device(pdev);
  96. if (err) {
  97. dev_err(&pdev->dev, "pcim_enable_device failed\n");
  98. return err;
  99. }
  100. pci_set_master(pdev);
  101. err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
  102. if (err < 0) {
  103. dev_err(&pdev->dev, "request and iomap failed\n");
  104. return err;
  105. }
  106. mmio_base = pcim_iomap_table(pdev)[0];
  107. err = ufshcd_alloc_host(&pdev->dev, &hba);
  108. if (err) {
  109. dev_err(&pdev->dev, "Allocation failed\n");
  110. return err;
  111. }
  112. INIT_LIST_HEAD(&hba->clk_list_head);
  113. hba->vops = &tc_dwc_g210_pci_hba_vops;
  114. err = ufshcd_init(hba, mmio_base, pdev->irq);
  115. if (err) {
  116. dev_err(&pdev->dev, "Initialization failed\n");
  117. return err;
  118. }
  119. pci_set_drvdata(pdev, hba);
  120. pm_runtime_put_noidle(&pdev->dev);
  121. pm_runtime_allow(&pdev->dev);
  122. return 0;
  123. }
  124. static const struct dev_pm_ops tc_dwc_g210_pci_pm_ops = {
  125. .suspend = tc_dwc_g210_pci_suspend,
  126. .resume = tc_dwc_g210_pci_resume,
  127. .runtime_suspend = tc_dwc_g210_pci_runtime_suspend,
  128. .runtime_resume = tc_dwc_g210_pci_runtime_resume,
  129. .runtime_idle = tc_dwc_g210_pci_runtime_idle,
  130. };
  131. static const struct pci_device_id tc_dwc_g210_pci_tbl[] = {
  132. { PCI_VENDOR_ID_SYNOPSYS, 0xB101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  133. { PCI_VENDOR_ID_SYNOPSYS, 0xB102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  134. { } /* terminate list */
  135. };
  136. MODULE_DEVICE_TABLE(pci, tc_dwc_g210_pci_tbl);
  137. static struct pci_driver tc_dwc_g210_pci_driver = {
  138. .name = "tc-dwc-g210-pci",
  139. .id_table = tc_dwc_g210_pci_tbl,
  140. .probe = tc_dwc_g210_pci_probe,
  141. .remove = tc_dwc_g210_pci_remove,
  142. .shutdown = tc_dwc_g210_pci_shutdown,
  143. .driver = {
  144. .pm = &tc_dwc_g210_pci_pm_ops
  145. },
  146. };
  147. module_pci_driver(tc_dwc_g210_pci_driver);
  148. MODULE_AUTHOR("Joao Pinto <Joao.Pinto@synopsys.com>");
  149. MODULE_DESCRIPTION("Synopsys Test Chip G210 PCI glue driver");
  150. MODULE_LICENSE("Dual BSD/GPL");