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
48
49static int ufshcd_pci_suspend(struct device *dev)
50{
51 return ufshcd_system_suspend(dev_get_drvdata(dev));
52}
53
54
55
56
57
58
59
60
61static int ufshcd_pci_resume(struct device *dev)
62{
63 return ufshcd_system_resume(dev_get_drvdata(dev));
64}
65
66static int ufshcd_pci_runtime_suspend(struct device *dev)
67{
68 return ufshcd_runtime_suspend(dev_get_drvdata(dev));
69}
70static int ufshcd_pci_runtime_resume(struct device *dev)
71{
72 return ufshcd_runtime_resume(dev_get_drvdata(dev));
73}
74static int ufshcd_pci_runtime_idle(struct device *dev)
75{
76 return ufshcd_runtime_idle(dev_get_drvdata(dev));
77}
78#else
79#define ufshcd_pci_suspend NULL
80#define ufshcd_pci_resume NULL
81#define ufshcd_pci_runtime_suspend NULL
82#define ufshcd_pci_runtime_resume NULL
83#define ufshcd_pci_runtime_idle NULL
84#endif
85
86
87
88
89
90static void ufshcd_pci_shutdown(struct pci_dev *pdev)
91{
92 ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
93}
94
95
96
97
98
99
100static void ufshcd_pci_remove(struct pci_dev *pdev)
101{
102 struct ufs_hba *hba = pci_get_drvdata(pdev);
103
104 pm_runtime_forbid(&pdev->dev);
105 pm_runtime_get_noresume(&pdev->dev);
106 ufshcd_remove(hba);
107 ufshcd_dealloc_host(hba);
108}
109
110
111
112
113
114
115
116
117static int
118ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
119{
120 struct ufs_hba *hba;
121 void __iomem *mmio_base;
122 int err;
123
124 err = pcim_enable_device(pdev);
125 if (err) {
126 dev_err(&pdev->dev, "pcim_enable_device failed\n");
127 return err;
128 }
129
130 pci_set_master(pdev);
131
132 err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
133 if (err < 0) {
134 dev_err(&pdev->dev, "request and iomap failed\n");
135 return err;
136 }
137
138 mmio_base = pcim_iomap_table(pdev)[0];
139
140 err = ufshcd_alloc_host(&pdev->dev, &hba);
141 if (err) {
142 dev_err(&pdev->dev, "Allocation failed\n");
143 return err;
144 }
145
146 INIT_LIST_HEAD(&hba->clk_list_head);
147
148 err = ufshcd_init(hba, mmio_base, pdev->irq);
149 if (err) {
150 dev_err(&pdev->dev, "Initialization failed\n");
151 ufshcd_dealloc_host(hba);
152 return err;
153 }
154
155 pci_set_drvdata(pdev, hba);
156 pm_runtime_put_noidle(&pdev->dev);
157 pm_runtime_allow(&pdev->dev);
158
159 return 0;
160}
161
162static const struct dev_pm_ops ufshcd_pci_pm_ops = {
163 .suspend = ufshcd_pci_suspend,
164 .resume = ufshcd_pci_resume,
165 .runtime_suspend = ufshcd_pci_runtime_suspend,
166 .runtime_resume = ufshcd_pci_runtime_resume,
167 .runtime_idle = ufshcd_pci_runtime_idle,
168};
169
170static const struct pci_device_id ufshcd_pci_tbl[] = {
171 { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
172 { }
173};
174
175MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
176
177static struct pci_driver ufshcd_pci_driver = {
178 .name = UFSHCD,
179 .id_table = ufshcd_pci_tbl,
180 .probe = ufshcd_pci_probe,
181 .remove = ufshcd_pci_remove,
182 .shutdown = ufshcd_pci_shutdown,
183 .driver = {
184 .pm = &ufshcd_pci_pm_ops
185 },
186};
187
188module_pci_driver(ufshcd_pci_driver);
189
190MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
191MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
192MODULE_DESCRIPTION("UFS host controller PCI glue driver");
193MODULE_LICENSE("GPL");
194MODULE_VERSION(UFSHCD_DRIVER_VERSION);
195