tc-dwc-g210-pci.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Synopsys G210 Test Chip driver
  4. *
  5. * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
  6. *
  7. * Authors: Joao Pinto <[email protected]>
  8. */
  9. #include <ufs/ufshcd.h>
  10. #include "ufshcd-dwc.h"
  11. #include "tc-dwc-g210.h"
  12. #include <linux/module.h>
  13. #include <linux/pci.h>
  14. #include <linux/pm_runtime.h>
  15. /* Test Chip type expected values */
  16. #define TC_G210_20BIT 20
  17. #define TC_G210_40BIT 40
  18. #define TC_G210_INV 0
  19. static int tc_type = TC_G210_INV;
  20. module_param(tc_type, int, 0);
  21. MODULE_PARM_DESC(tc_type, "Test Chip Type (20 = 20-bit, 40 = 40-bit)");
  22. /*
  23. * struct ufs_hba_dwc_vops - UFS DWC specific variant operations
  24. */
  25. static struct ufs_hba_variant_ops tc_dwc_g210_pci_hba_vops = {
  26. .name = "tc-dwc-g210-pci",
  27. .link_startup_notify = ufshcd_dwc_link_startup_notify,
  28. };
  29. /**
  30. * tc_dwc_g210_pci_shutdown - main function to put the controller in reset state
  31. * @pdev: pointer to PCI device handle
  32. */
  33. static void tc_dwc_g210_pci_shutdown(struct pci_dev *pdev)
  34. {
  35. ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
  36. }
  37. /**
  38. * tc_dwc_g210_pci_remove - de-allocate PCI/SCSI host and host memory space
  39. * data structure memory
  40. * @pdev: pointer to PCI handle
  41. */
  42. static void tc_dwc_g210_pci_remove(struct pci_dev *pdev)
  43. {
  44. struct ufs_hba *hba = pci_get_drvdata(pdev);
  45. pm_runtime_forbid(&pdev->dev);
  46. pm_runtime_get_noresume(&pdev->dev);
  47. ufshcd_remove(hba);
  48. }
  49. /**
  50. * tc_dwc_g210_pci_probe - probe routine of the driver
  51. * @pdev: pointer to PCI device handle
  52. * @id: PCI device id
  53. *
  54. * Returns 0 on success, non-zero value on failure
  55. */
  56. static int
  57. tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  58. {
  59. struct ufs_hba *hba;
  60. void __iomem *mmio_base;
  61. int err;
  62. /* Check Test Chip type and set the specific setup routine */
  63. if (tc_type == TC_G210_20BIT) {
  64. tc_dwc_g210_pci_hba_vops.phy_initialization =
  65. tc_dwc_g210_config_20_bit;
  66. } else if (tc_type == TC_G210_40BIT) {
  67. tc_dwc_g210_pci_hba_vops.phy_initialization =
  68. tc_dwc_g210_config_40_bit;
  69. } else {
  70. dev_err(&pdev->dev, "test chip version not specified\n");
  71. return -EPERM;
  72. }
  73. err = pcim_enable_device(pdev);
  74. if (err) {
  75. dev_err(&pdev->dev, "pcim_enable_device failed\n");
  76. return err;
  77. }
  78. pci_set_master(pdev);
  79. err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
  80. if (err < 0) {
  81. dev_err(&pdev->dev, "request and iomap failed\n");
  82. return err;
  83. }
  84. mmio_base = pcim_iomap_table(pdev)[0];
  85. err = ufshcd_alloc_host(&pdev->dev, &hba);
  86. if (err) {
  87. dev_err(&pdev->dev, "Allocation failed\n");
  88. return err;
  89. }
  90. hba->vops = &tc_dwc_g210_pci_hba_vops;
  91. err = ufshcd_init(hba, mmio_base, pdev->irq);
  92. if (err) {
  93. dev_err(&pdev->dev, "Initialization failed\n");
  94. return err;
  95. }
  96. pm_runtime_put_noidle(&pdev->dev);
  97. pm_runtime_allow(&pdev->dev);
  98. return 0;
  99. }
  100. static const struct dev_pm_ops tc_dwc_g210_pci_pm_ops = {
  101. SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume)
  102. SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL)
  103. .prepare = ufshcd_suspend_prepare,
  104. .complete = ufshcd_resume_complete,
  105. };
  106. static const struct pci_device_id tc_dwc_g210_pci_tbl[] = {
  107. { PCI_VENDOR_ID_SYNOPSYS, 0xB101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  108. { PCI_VENDOR_ID_SYNOPSYS, 0xB102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  109. { } /* terminate list */
  110. };
  111. MODULE_DEVICE_TABLE(pci, tc_dwc_g210_pci_tbl);
  112. static struct pci_driver tc_dwc_g210_pci_driver = {
  113. .name = "tc-dwc-g210-pci",
  114. .id_table = tc_dwc_g210_pci_tbl,
  115. .probe = tc_dwc_g210_pci_probe,
  116. .remove = tc_dwc_g210_pci_remove,
  117. .shutdown = tc_dwc_g210_pci_shutdown,
  118. .driver = {
  119. .pm = &tc_dwc_g210_pci_pm_ops
  120. },
  121. };
  122. module_pci_driver(tc_dwc_g210_pci_driver);
  123. MODULE_AUTHOR("Joao Pinto <[email protected]>");
  124. MODULE_DESCRIPTION("Synopsys Test Chip G210 PCI glue driver");
  125. MODULE_LICENSE("Dual BSD/GPL");