1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include "ufshcd.h"
37#include <linux/pci.h>
38#include <linux/pm_runtime.h>
39
40static int ufs_intel_disable_lcc(struct ufs_hba *hba)
41{
42 u32 attr = UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE);
43 u32 lcc_enable = 0;
44
45 ufshcd_dme_get(hba, attr, &lcc_enable);
46 if (lcc_enable)
47 ufshcd_dme_set(hba, attr, 0);
48
49 return 0;
50}
51
52static int ufs_intel_link_startup_notify(struct ufs_hba *hba,
53 enum ufs_notify_change_status status)
54{
55 int err = 0;
56
57 switch (status) {
58 case PRE_CHANGE:
59 err = ufs_intel_disable_lcc(hba);
60 break;
61 case POST_CHANGE:
62 break;
63 default:
64 break;
65 }
66
67 return err;
68}
69
70static struct ufs_hba_variant_ops ufs_intel_cnl_hba_vops = {
71 .name = "intel-pci",
72 .link_startup_notify = ufs_intel_link_startup_notify,
73};
74
75#ifdef CONFIG_PM_SLEEP
76
77
78
79
80
81
82
83static int ufshcd_pci_suspend(struct device *dev)
84{
85 return ufshcd_system_suspend(dev_get_drvdata(dev));
86}
87
88
89
90
91
92
93
94
95static int ufshcd_pci_resume(struct device *dev)
96{
97 return ufshcd_system_resume(dev_get_drvdata(dev));
98}
99#endif
100
101#ifdef CONFIG_PM
102static int ufshcd_pci_runtime_suspend(struct device *dev)
103{
104 return ufshcd_runtime_suspend(dev_get_drvdata(dev));
105}
106static int ufshcd_pci_runtime_resume(struct device *dev)
107{
108 return ufshcd_runtime_resume(dev_get_drvdata(dev));
109}
110static int ufshcd_pci_runtime_idle(struct device *dev)
111{
112 return ufshcd_runtime_idle(dev_get_drvdata(dev));
113}
114#endif
115
116
117
118
119
120static void ufshcd_pci_shutdown(struct pci_dev *pdev)
121{
122 ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
123}
124
125
126
127
128
129
130static void ufshcd_pci_remove(struct pci_dev *pdev)
131{
132 struct ufs_hba *hba = pci_get_drvdata(pdev);
133
134 pm_runtime_forbid(&pdev->dev);
135 pm_runtime_get_noresume(&pdev->dev);
136 ufshcd_remove(hba);
137 ufshcd_dealloc_host(hba);
138}
139
140
141
142
143
144
145
146
147static int
148ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
149{
150 struct ufs_hba *hba;
151 void __iomem *mmio_base;
152 int err;
153
154 err = pcim_enable_device(pdev);
155 if (err) {
156 dev_err(&pdev->dev, "pcim_enable_device failed\n");
157 return err;
158 }
159
160 pci_set_master(pdev);
161
162 err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
163 if (err < 0) {
164 dev_err(&pdev->dev, "request and iomap failed\n");
165 return err;
166 }
167
168 mmio_base = pcim_iomap_table(pdev)[0];
169
170 err = ufshcd_alloc_host(&pdev->dev, &hba);
171 if (err) {
172 dev_err(&pdev->dev, "Allocation failed\n");
173 return err;
174 }
175
176 hba->vops = (struct ufs_hba_variant_ops *)id->driver_data;
177
178 err = ufshcd_init(hba, mmio_base, pdev->irq);
179 if (err) {
180 dev_err(&pdev->dev, "Initialization failed\n");
181 ufshcd_dealloc_host(hba);
182 return err;
183 }
184
185 pci_set_drvdata(pdev, hba);
186 pm_runtime_put_noidle(&pdev->dev);
187 pm_runtime_allow(&pdev->dev);
188
189 return 0;
190}
191
192static const struct dev_pm_ops ufshcd_pci_pm_ops = {
193 SET_SYSTEM_SLEEP_PM_OPS(ufshcd_pci_suspend,
194 ufshcd_pci_resume)
195 SET_RUNTIME_PM_OPS(ufshcd_pci_runtime_suspend,
196 ufshcd_pci_runtime_resume,
197 ufshcd_pci_runtime_idle)
198};
199
200static const struct pci_device_id ufshcd_pci_tbl[] = {
201 { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
202 { PCI_VDEVICE(INTEL, 0x9DFA), (kernel_ulong_t)&ufs_intel_cnl_hba_vops },
203 { }
204};
205
206MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
207
208static struct pci_driver ufshcd_pci_driver = {
209 .name = UFSHCD,
210 .id_table = ufshcd_pci_tbl,
211 .probe = ufshcd_pci_probe,
212 .remove = ufshcd_pci_remove,
213 .shutdown = ufshcd_pci_shutdown,
214 .driver = {
215 .pm = &ufshcd_pci_pm_ops
216 },
217};
218
219module_pci_driver(ufshcd_pci_driver);
220
221MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
222MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
223MODULE_DESCRIPTION("UFS host controller PCI glue driver");
224MODULE_LICENSE("GPL");
225MODULE_VERSION(UFSHCD_DRIVER_VERSION);
226