1
2
3
4
5
6
7
8
9
10
11
12
13#include "ufshcd.h"
14#include "ufshcd-dwc.h"
15#include "tc-dwc-g210.h"
16
17#include <linux/pci.h>
18#include <linux/pm_runtime.h>
19
20
21#define TC_G210_20BIT 20
22#define TC_G210_40BIT 40
23#define TC_G210_INV 0
24
25static int tc_type = TC_G210_INV;
26module_param(tc_type, int, 0);
27MODULE_PARM_DESC(tc_type, "Test Chip Type (20 = 20-bit, 40 = 40-bit)");
28
29static int tc_dwc_g210_pci_suspend(struct device *dev)
30{
31 return ufshcd_system_suspend(dev_get_drvdata(dev));
32}
33
34static int tc_dwc_g210_pci_resume(struct device *dev)
35{
36 return ufshcd_system_resume(dev_get_drvdata(dev));
37}
38
39static int tc_dwc_g210_pci_runtime_suspend(struct device *dev)
40{
41 return ufshcd_runtime_suspend(dev_get_drvdata(dev));
42}
43
44static int tc_dwc_g210_pci_runtime_resume(struct device *dev)
45{
46 return ufshcd_runtime_resume(dev_get_drvdata(dev));
47}
48
49static int tc_dwc_g210_pci_runtime_idle(struct device *dev)
50{
51 return ufshcd_runtime_idle(dev_get_drvdata(dev));
52}
53
54
55
56
57static struct ufs_hba_variant_ops tc_dwc_g210_pci_hba_vops = {
58 .name = "tc-dwc-g210-pci",
59 .link_startup_notify = ufshcd_dwc_link_startup_notify,
60};
61
62
63
64
65
66static void tc_dwc_g210_pci_shutdown(struct pci_dev *pdev)
67{
68 ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
69}
70
71
72
73
74
75
76static void tc_dwc_g210_pci_remove(struct pci_dev *pdev)
77{
78 struct ufs_hba *hba = pci_get_drvdata(pdev);
79
80 pm_runtime_forbid(&pdev->dev);
81 pm_runtime_get_noresume(&pdev->dev);
82 ufshcd_remove(hba);
83}
84
85
86
87
88
89
90
91
92static int
93tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
94{
95 struct ufs_hba *hba;
96 void __iomem *mmio_base;
97 int err;
98
99
100 if (tc_type == TC_G210_20BIT) {
101 tc_dwc_g210_pci_hba_vops.phy_initialization =
102 tc_dwc_g210_config_20_bit;
103 } else if (tc_type == TC_G210_40BIT) {
104 tc_dwc_g210_pci_hba_vops.phy_initialization =
105 tc_dwc_g210_config_40_bit;
106 } else {
107 dev_err(&pdev->dev, "test chip version not specified\n");
108 return -EPERM;
109 }
110
111 err = pcim_enable_device(pdev);
112 if (err) {
113 dev_err(&pdev->dev, "pcim_enable_device failed\n");
114 return err;
115 }
116
117 pci_set_master(pdev);
118
119 err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
120 if (err < 0) {
121 dev_err(&pdev->dev, "request and iomap failed\n");
122 return err;
123 }
124
125 mmio_base = pcim_iomap_table(pdev)[0];
126
127 err = ufshcd_alloc_host(&pdev->dev, &hba);
128 if (err) {
129 dev_err(&pdev->dev, "Allocation failed\n");
130 return err;
131 }
132
133 hba->vops = &tc_dwc_g210_pci_hba_vops;
134
135 err = ufshcd_init(hba, mmio_base, pdev->irq);
136 if (err) {
137 dev_err(&pdev->dev, "Initialization failed\n");
138 return err;
139 }
140
141 pci_set_drvdata(pdev, hba);
142 pm_runtime_put_noidle(&pdev->dev);
143 pm_runtime_allow(&pdev->dev);
144
145 return 0;
146}
147
148static const struct dev_pm_ops tc_dwc_g210_pci_pm_ops = {
149 .suspend = tc_dwc_g210_pci_suspend,
150 .resume = tc_dwc_g210_pci_resume,
151 .runtime_suspend = tc_dwc_g210_pci_runtime_suspend,
152 .runtime_resume = tc_dwc_g210_pci_runtime_resume,
153 .runtime_idle = tc_dwc_g210_pci_runtime_idle,
154};
155
156static const struct pci_device_id tc_dwc_g210_pci_tbl[] = {
157 { PCI_VENDOR_ID_SYNOPSYS, 0xB101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
158 { PCI_VENDOR_ID_SYNOPSYS, 0xB102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
159 { }
160};
161
162MODULE_DEVICE_TABLE(pci, tc_dwc_g210_pci_tbl);
163
164static struct pci_driver tc_dwc_g210_pci_driver = {
165 .name = "tc-dwc-g210-pci",
166 .id_table = tc_dwc_g210_pci_tbl,
167 .probe = tc_dwc_g210_pci_probe,
168 .remove = tc_dwc_g210_pci_remove,
169 .shutdown = tc_dwc_g210_pci_shutdown,
170 .driver = {
171 .pm = &tc_dwc_g210_pci_pm_ops
172 },
173};
174
175module_pci_driver(tc_dwc_g210_pci_driver);
176
177MODULE_AUTHOR("Joao Pinto <Joao.Pinto@synopsys.com>");
178MODULE_DESCRIPTION("Synopsys Test Chip G210 PCI glue driver");
179MODULE_LICENSE("Dual BSD/GPL");
180