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
40#ifdef CONFIG_PM
41
42
43
44
45
46
47
48static int ufshcd_pci_suspend(struct device *dev)
49{
50
51
52
53
54
55
56 return -ENOSYS;
57}
58
59
60
61
62
63
64
65static int ufshcd_pci_resume(struct device *dev)
66{
67
68
69
70
71
72
73 return -ENOSYS;
74}
75#else
76#define ufshcd_pci_suspend NULL
77#define ufshcd_pci_resume NULL
78#endif
79
80#ifdef CONFIG_PM_RUNTIME
81static int ufshcd_pci_runtime_suspend(struct device *dev)
82{
83 struct ufs_hba *hba = dev_get_drvdata(dev);
84
85 if (!hba)
86 return 0;
87
88 return ufshcd_runtime_suspend(hba);
89}
90static int ufshcd_pci_runtime_resume(struct device *dev)
91{
92 struct ufs_hba *hba = dev_get_drvdata(dev);
93
94 if (!hba)
95 return 0;
96
97 return ufshcd_runtime_resume(hba);
98}
99static int ufshcd_pci_runtime_idle(struct device *dev)
100{
101 struct ufs_hba *hba = dev_get_drvdata(dev);
102
103 if (!hba)
104 return 0;
105
106 return ufshcd_runtime_idle(hba);
107}
108#else
109#define ufshcd_pci_runtime_suspend NULL
110#define ufshcd_pci_runtime_resume NULL
111#define ufshcd_pci_runtime_idle NULL
112#endif
113
114
115
116
117
118static void ufshcd_pci_shutdown(struct pci_dev *pdev)
119{
120 ufshcd_hba_stop((struct ufs_hba *)pci_get_drvdata(pdev));
121}
122
123
124
125
126
127
128static void ufshcd_pci_remove(struct pci_dev *pdev)
129{
130 struct ufs_hba *hba = pci_get_drvdata(pdev);
131
132 pm_runtime_forbid(&pdev->dev);
133 pm_runtime_get_noresume(&pdev->dev);
134 ufshcd_remove(hba);
135}
136
137
138
139
140
141
142
143
144static int ufshcd_set_dma_mask(struct pci_dev *pdev)
145{
146 int err;
147
148 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
149 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
150 return 0;
151 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
152 if (!err)
153 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
154 return err;
155}
156
157
158
159
160
161
162
163
164static int
165ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
166{
167 struct ufs_hba *hba;
168 void __iomem *mmio_base;
169 int err;
170
171 err = pcim_enable_device(pdev);
172 if (err) {
173 dev_err(&pdev->dev, "pcim_enable_device failed\n");
174 return err;
175 }
176
177 pci_set_master(pdev);
178
179 err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
180 if (err < 0) {
181 dev_err(&pdev->dev, "request and iomap failed\n");
182 return err;
183 }
184
185 mmio_base = pcim_iomap_table(pdev)[0];
186
187 err = ufshcd_set_dma_mask(pdev);
188 if (err) {
189 dev_err(&pdev->dev, "set dma mask failed\n");
190 return err;
191 }
192
193 err = ufshcd_init(&pdev->dev, &hba, mmio_base, pdev->irq);
194 if (err) {
195 dev_err(&pdev->dev, "Initialization failed\n");
196 return err;
197 }
198
199 pci_set_drvdata(pdev, hba);
200 pm_runtime_put_noidle(&pdev->dev);
201 pm_runtime_allow(&pdev->dev);
202
203 return 0;
204}
205
206static const struct dev_pm_ops ufshcd_pci_pm_ops = {
207 .suspend = ufshcd_pci_suspend,
208 .resume = ufshcd_pci_resume,
209 .runtime_suspend = ufshcd_pci_runtime_suspend,
210 .runtime_resume = ufshcd_pci_runtime_resume,
211 .runtime_idle = ufshcd_pci_runtime_idle,
212};
213
214static DEFINE_PCI_DEVICE_TABLE(ufshcd_pci_tbl) = {
215 { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
216 { }
217};
218
219MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
220
221static struct pci_driver ufshcd_pci_driver = {
222 .name = UFSHCD,
223 .id_table = ufshcd_pci_tbl,
224 .probe = ufshcd_pci_probe,
225 .remove = ufshcd_pci_remove,
226 .shutdown = ufshcd_pci_shutdown,
227 .driver = {
228 .pm = &ufshcd_pci_pm_ops
229 },
230};
231
232module_pci_driver(ufshcd_pci_driver);
233
234MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
235MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
236MODULE_DESCRIPTION("UFS host controller PCI glue driver");
237MODULE_LICENSE("GPL");
238MODULE_VERSION(UFSHCD_DRIVER_VERSION);
239