1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/hrtimer.h>
18#include <linux/io.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/err.h>
22#include <linux/platform_device.h>
23#include <linux/usb/ohci_pdriver.h>
24#include <linux/usb.h>
25#include <linux/usb/hcd.h>
26
27#include "ohci.h"
28
29#define DRIVER_DESC "OHCI generic platform driver"
30
31static const char hcd_name[] = "ohci-platform";
32
33static int ohci_platform_reset(struct usb_hcd *hcd)
34{
35 struct platform_device *pdev = to_platform_device(hcd->self.controller);
36 struct usb_ohci_pdata *pdata = pdev->dev.platform_data;
37 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
38
39 if (pdata->big_endian_desc)
40 ohci->flags |= OHCI_QUIRK_BE_DESC;
41 if (pdata->big_endian_mmio)
42 ohci->flags |= OHCI_QUIRK_BE_MMIO;
43 if (pdata->no_big_frame_no)
44 ohci->flags |= OHCI_QUIRK_FRAME_NO;
45 if (pdata->num_ports)
46 ohci->num_ports = pdata->num_ports;
47
48 return ohci_setup(hcd);
49}
50
51static struct hc_driver __read_mostly ohci_platform_hc_driver;
52
53static const struct ohci_driver_overrides platform_overrides __initconst = {
54 .product_desc = "Generic Platform OHCI controller",
55 .reset = ohci_platform_reset,
56};
57
58static int ohci_platform_probe(struct platform_device *dev)
59{
60 struct usb_hcd *hcd;
61 struct resource *res_mem;
62 struct usb_ohci_pdata *pdata = dev->dev.platform_data;
63 int irq;
64 int err = -ENOMEM;
65
66 if (!pdata) {
67 WARN_ON(1);
68 return -ENODEV;
69 }
70
71 if (usb_disabled())
72 return -ENODEV;
73
74 irq = platform_get_irq(dev, 0);
75 if (irq < 0) {
76 dev_err(&dev->dev, "no irq provided");
77 return irq;
78 }
79
80 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
81 if (!res_mem) {
82 dev_err(&dev->dev, "no memory resource provided");
83 return -ENXIO;
84 }
85
86 if (pdata->power_on) {
87 err = pdata->power_on(dev);
88 if (err < 0)
89 return err;
90 }
91
92 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
93 dev_name(&dev->dev));
94 if (!hcd) {
95 err = -ENOMEM;
96 goto err_power;
97 }
98
99 hcd->rsrc_start = res_mem->start;
100 hcd->rsrc_len = resource_size(res_mem);
101
102 hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
103 if (IS_ERR(hcd->regs)) {
104 err = PTR_ERR(hcd->regs);
105 goto err_put_hcd;
106 }
107 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
108 if (err)
109 goto err_put_hcd;
110
111 platform_set_drvdata(dev, hcd);
112
113 return err;
114
115err_put_hcd:
116 usb_put_hcd(hcd);
117err_power:
118 if (pdata->power_off)
119 pdata->power_off(dev);
120
121 return err;
122}
123
124static int ohci_platform_remove(struct platform_device *dev)
125{
126 struct usb_hcd *hcd = platform_get_drvdata(dev);
127 struct usb_ohci_pdata *pdata = dev->dev.platform_data;
128
129 usb_remove_hcd(hcd);
130 usb_put_hcd(hcd);
131 platform_set_drvdata(dev, NULL);
132
133 if (pdata->power_off)
134 pdata->power_off(dev);
135
136 return 0;
137}
138
139#ifdef CONFIG_PM_SLEEP
140static int ohci_platform_suspend(struct device *dev)
141{
142 struct usb_ohci_pdata *pdata = dev->platform_data;
143 struct platform_device *pdev =
144 container_of(dev, struct platform_device, dev);
145
146 if (pdata->power_suspend)
147 pdata->power_suspend(pdev);
148
149 return 0;
150}
151
152static int ohci_platform_resume(struct device *dev)
153{
154 struct usb_hcd *hcd = dev_get_drvdata(dev);
155 struct usb_ohci_pdata *pdata = dev->platform_data;
156 struct platform_device *pdev =
157 container_of(dev, struct platform_device, dev);
158
159 if (pdata->power_on) {
160 int err = pdata->power_on(pdev);
161 if (err < 0)
162 return err;
163 }
164
165 ohci_resume(hcd, false);
166 return 0;
167}
168#endif
169
170static const struct platform_device_id ohci_platform_table[] = {
171 { "ohci-platform", 0 },
172 { }
173};
174MODULE_DEVICE_TABLE(platform, ohci_platform_table);
175
176static SIMPLE_DEV_PM_OPS(ohci_platform_pm_ops, ohci_platform_suspend,
177 ohci_platform_resume);
178
179static struct platform_driver ohci_platform_driver = {
180 .id_table = ohci_platform_table,
181 .probe = ohci_platform_probe,
182 .remove = ohci_platform_remove,
183 .shutdown = usb_hcd_platform_shutdown,
184 .driver = {
185 .owner = THIS_MODULE,
186 .name = "ohci-platform",
187 .pm = &ohci_platform_pm_ops,
188 }
189};
190
191static int __init ohci_platform_init(void)
192{
193 if (usb_disabled())
194 return -ENODEV;
195
196 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
197
198 ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
199 return platform_driver_register(&ohci_platform_driver);
200}
201module_init(ohci_platform_init);
202
203static void __exit ohci_platform_cleanup(void)
204{
205 platform_driver_unregister(&ohci_platform_driver);
206}
207module_exit(ohci_platform_cleanup);
208
209MODULE_DESCRIPTION(DRIVER_DESC);
210MODULE_AUTHOR("Hauke Mehrtens");
211MODULE_AUTHOR("Alan Stern");
212MODULE_LICENSE("GPL");
213