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#include <linux/dma-mapping.h>
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/of.h>
36#include <linux/usb/otg.h>
37#include <linux/platform_device.h>
38#include <linux/pm_runtime.h>
39#include <linux/usb.h>
40#include <linux/usb/hcd.h>
41
42#include "ohci.h"
43
44#define DRIVER_DESC "OHCI OMAP3 driver"
45
46static const char hcd_name[] = "ohci-omap3";
47static struct hc_driver __read_mostly ohci_omap3_hc_driver;
48
49
50
51
52
53
54
55
56
57
58
59
60
61static int ohci_hcd_omap3_probe(struct platform_device *pdev)
62{
63 struct device *dev = &pdev->dev;
64 struct ohci_hcd *ohci;
65 struct usb_hcd *hcd = NULL;
66 void __iomem *regs = NULL;
67 struct resource *res;
68 int ret;
69 int irq;
70
71 if (usb_disabled())
72 return -ENODEV;
73
74 if (!dev->parent) {
75 dev_err(dev, "Missing parent device\n");
76 return -ENODEV;
77 }
78
79 irq = platform_get_irq(pdev, 0);
80 if (irq < 0) {
81 dev_err(dev, "OHCI irq failed\n");
82 return -ENODEV;
83 }
84
85 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
86 if (!res) {
87 dev_err(dev, "UHH OHCI get resource failed\n");
88 return -ENOMEM;
89 }
90
91 regs = ioremap(res->start, resource_size(res));
92 if (!regs) {
93 dev_err(dev, "UHH OHCI ioremap failed\n");
94 return -ENOMEM;
95 }
96
97
98
99
100
101
102 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
103 if (ret)
104 goto err_io;
105
106 ret = -ENODEV;
107 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
108 dev_name(dev));
109 if (!hcd) {
110 dev_err(dev, "usb_create_hcd failed\n");
111 goto err_io;
112 }
113
114 hcd->rsrc_start = res->start;
115 hcd->rsrc_len = resource_size(res);
116 hcd->regs = regs;
117
118 pm_runtime_enable(dev);
119 pm_runtime_get_sync(dev);
120
121 ohci = hcd_to_ohci(hcd);
122
123
124
125
126 ohci->hc_control = OHCI_CTRL_RWC;
127
128 ret = usb_add_hcd(hcd, irq, 0);
129 if (ret) {
130 dev_dbg(dev, "failed to add hcd with err %d\n", ret);
131 goto err_add_hcd;
132 }
133 device_wakeup_enable(hcd->self.controller);
134
135 return 0;
136
137err_add_hcd:
138 pm_runtime_put_sync(dev);
139 usb_put_hcd(hcd);
140
141err_io:
142 iounmap(regs);
143
144 return ret;
145}
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160static int ohci_hcd_omap3_remove(struct platform_device *pdev)
161{
162 struct device *dev = &pdev->dev;
163 struct usb_hcd *hcd = dev_get_drvdata(dev);
164
165 iounmap(hcd->regs);
166 usb_remove_hcd(hcd);
167 pm_runtime_put_sync(dev);
168 pm_runtime_disable(dev);
169 usb_put_hcd(hcd);
170 return 0;
171}
172
173static const struct of_device_id omap_ohci_dt_ids[] = {
174 { .compatible = "ti,ohci-omap3" },
175 { }
176};
177
178MODULE_DEVICE_TABLE(of, omap_ohci_dt_ids);
179
180static struct platform_driver ohci_hcd_omap3_driver = {
181 .probe = ohci_hcd_omap3_probe,
182 .remove = ohci_hcd_omap3_remove,
183 .shutdown = usb_hcd_platform_shutdown,
184 .driver = {
185 .name = "ohci-omap3",
186 .of_match_table = omap_ohci_dt_ids,
187 },
188};
189
190static int __init ohci_omap3_init(void)
191{
192 if (usb_disabled())
193 return -ENODEV;
194
195 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
196
197 ohci_init_driver(&ohci_omap3_hc_driver, NULL);
198 return platform_driver_register(&ohci_hcd_omap3_driver);
199}
200module_init(ohci_omap3_init);
201
202static void __exit ohci_omap3_cleanup(void)
203{
204 platform_driver_unregister(&ohci_hcd_omap3_driver);
205}
206module_exit(ohci_omap3_cleanup);
207
208MODULE_DESCRIPTION(DRIVER_DESC);
209MODULE_ALIAS("platform:ohci-omap3");
210MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");
211MODULE_LICENSE("GPL");
212