1 // SPDX-License-Identifier: GPL-2.0-only
3 * Synopsys G210 Test Chip driver
5 * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
7 * Authors: Joao Pinto <jpinto@synopsys.com>
11 #include "ufshcd-dwc.h"
12 #include "tc-dwc-g210.h"
14 #include <linux/pci.h>
15 #include <linux/pm_runtime.h>
17 /* Test Chip type expected values */
18 #define TC_G210_20BIT 20
19 #define TC_G210_40BIT 40
22 static int tc_type = TC_G210_INV;
23 module_param(tc_type, int, 0);
24 MODULE_PARM_DESC(tc_type, "Test Chip Type (20 = 20-bit, 40 = 40-bit)");
27 * struct ufs_hba_dwc_vops - UFS DWC specific variant operations
29 static struct ufs_hba_variant_ops tc_dwc_g210_pci_hba_vops = {
30 .name = "tc-dwc-g210-pci",
31 .link_startup_notify = ufshcd_dwc_link_startup_notify,
35 * tc_dwc_g210_pci_shutdown - main function to put the controller in reset state
36 * @pdev: pointer to PCI device handle
38 static void tc_dwc_g210_pci_shutdown(struct pci_dev *pdev)
40 ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
44 * tc_dwc_g210_pci_remove - de-allocate PCI/SCSI host and host memory space
45 * data structure memory
46 * @pdev: pointer to PCI handle
48 static void tc_dwc_g210_pci_remove(struct pci_dev *pdev)
50 struct ufs_hba *hba = pci_get_drvdata(pdev);
52 pm_runtime_forbid(&pdev->dev);
53 pm_runtime_get_noresume(&pdev->dev);
58 * tc_dwc_g210_pci_probe - probe routine of the driver
59 * @pdev: pointer to PCI device handle
62 * Returns 0 on success, non-zero value on failure
65 tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
68 void __iomem *mmio_base;
71 /* Check Test Chip type and set the specific setup routine */
72 if (tc_type == TC_G210_20BIT) {
73 tc_dwc_g210_pci_hba_vops.phy_initialization =
74 tc_dwc_g210_config_20_bit;
75 } else if (tc_type == TC_G210_40BIT) {
76 tc_dwc_g210_pci_hba_vops.phy_initialization =
77 tc_dwc_g210_config_40_bit;
79 dev_err(&pdev->dev, "test chip version not specified\n");
83 err = pcim_enable_device(pdev);
85 dev_err(&pdev->dev, "pcim_enable_device failed\n");
91 err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
93 dev_err(&pdev->dev, "request and iomap failed\n");
97 mmio_base = pcim_iomap_table(pdev)[0];
99 err = ufshcd_alloc_host(&pdev->dev, &hba);
101 dev_err(&pdev->dev, "Allocation failed\n");
105 hba->vops = &tc_dwc_g210_pci_hba_vops;
107 err = ufshcd_init(hba, mmio_base, pdev->irq);
109 dev_err(&pdev->dev, "Initialization failed\n");
113 pm_runtime_put_noidle(&pdev->dev);
114 pm_runtime_allow(&pdev->dev);
119 static const struct dev_pm_ops tc_dwc_g210_pci_pm_ops = {
120 SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume)
121 SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL)
122 .prepare = ufshcd_suspend_prepare,
123 .complete = ufshcd_resume_complete,
126 static const struct pci_device_id tc_dwc_g210_pci_tbl[] = {
127 { PCI_VENDOR_ID_SYNOPSYS, 0xB101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
128 { PCI_VENDOR_ID_SYNOPSYS, 0xB102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
129 { } /* terminate list */
132 MODULE_DEVICE_TABLE(pci, tc_dwc_g210_pci_tbl);
134 static struct pci_driver tc_dwc_g210_pci_driver = {
135 .name = "tc-dwc-g210-pci",
136 .id_table = tc_dwc_g210_pci_tbl,
137 .probe = tc_dwc_g210_pci_probe,
138 .remove = tc_dwc_g210_pci_remove,
139 .shutdown = tc_dwc_g210_pci_shutdown,
141 .pm = &tc_dwc_g210_pci_pm_ops
145 module_pci_driver(tc_dwc_g210_pci_driver);
147 MODULE_AUTHOR("Joao Pinto <Joao.Pinto@synopsys.com>");
148 MODULE_DESCRIPTION("Synopsys Test Chip G210 PCI glue driver");
149 MODULE_LICENSE("Dual BSD/GPL");