1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/err.h>
15#include <linux/signal.h>
16
17#include <linux/of.h>
18#include <linux/of_platform.h>
19#include <linux/of_address.h>
20#include <linux/of_irq.h>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
37{
38 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
39 if (hcd->has_tt) {
40 dev_warn(hcd->self.controller,
41 "Maybe you have connected a low speed device?\n");
42
43 dev_warn(hcd->self.controller,
44 "We do not support low speed devices\n");
45 } else {
46 dev_warn(hcd->self.controller,
47 "Maybe your device is not a high speed device?\n");
48 dev_warn(hcd->self.controller,
49 "The USB host controller does not support full speed "
50 "nor low speed devices\n");
51 dev_warn(hcd->self.controller,
52 "You can reconfigure the host controller to have "
53 "full speed support\n");
54 }
55
56 return 0;
57}
58
59
60static const struct hc_driver ehci_xilinx_of_hc_driver = {
61 .description = hcd_name,
62 .product_desc = "OF EHCI",
63 .hcd_priv_size = sizeof(struct ehci_hcd),
64
65
66
67
68 .irq = ehci_irq,
69 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
70
71
72
73
74 .reset = ehci_setup,
75 .start = ehci_run,
76 .stop = ehci_stop,
77 .shutdown = ehci_shutdown,
78
79
80
81
82 .urb_enqueue = ehci_urb_enqueue,
83 .urb_dequeue = ehci_urb_dequeue,
84 .endpoint_disable = ehci_endpoint_disable,
85 .endpoint_reset = ehci_endpoint_reset,
86
87
88
89
90 .get_frame_number = ehci_get_frame,
91
92
93
94
95 .hub_status_data = ehci_hub_status_data,
96 .hub_control = ehci_hub_control,
97#ifdef CONFIG_PM
98 .bus_suspend = ehci_bus_suspend,
99 .bus_resume = ehci_bus_resume,
100#endif
101 .relinquish_port = NULL,
102 .port_handed_over = ehci_xilinx_port_handed_over,
103
104 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
105};
106
107
108
109
110
111
112
113
114
115
116static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
117{
118 struct device_node *dn = op->dev.of_node;
119 struct usb_hcd *hcd;
120 struct ehci_hcd *ehci;
121 struct resource res;
122 int irq;
123 int rv;
124 int *value;
125
126 if (usb_disabled())
127 return -ENODEV;
128
129 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
130
131 rv = of_address_to_resource(dn, 0, &res);
132 if (rv)
133 return rv;
134
135 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
136 "XILINX-OF USB");
137 if (!hcd)
138 return -ENOMEM;
139
140 hcd->rsrc_start = res.start;
141 hcd->rsrc_len = resource_size(&res);
142
143 irq = irq_of_parse_and_map(dn, 0);
144 if (!irq) {
145 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
146 __FILE__);
147 rv = -EBUSY;
148 goto err_irq;
149 }
150
151 hcd->regs = devm_ioremap_resource(&op->dev, &res);
152 if (IS_ERR(hcd->regs)) {
153 rv = PTR_ERR(hcd->regs);
154 goto err_irq;
155 }
156
157 ehci = hcd_to_ehci(hcd);
158
159
160
161
162 ehci->big_endian_mmio = 1;
163 ehci->big_endian_desc = 1;
164
165
166
167 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
168 if (value && (*value == 1)) {
169 ehci_dbg(ehci, "USB host controller supports FS devices\n");
170 hcd->has_tt = 1;
171 } else {
172 ehci_dbg(ehci,
173 "USB host controller is HS only\n");
174 hcd->has_tt = 0;
175 }
176
177
178
179 ehci->caps = hcd->regs + 0x100;
180
181 rv = usb_add_hcd(hcd, irq, 0);
182 if (rv == 0) {
183 device_wakeup_enable(hcd->self.controller);
184 return 0;
185 }
186
187err_irq:
188 usb_put_hcd(hcd);
189
190 return rv;
191}
192
193
194
195
196
197
198
199
200static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
201{
202 struct usb_hcd *hcd = platform_get_drvdata(op);
203
204 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
205
206 usb_remove_hcd(hcd);
207
208 usb_put_hcd(hcd);
209
210 return 0;
211}
212
213static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
214 {.compatible = "xlnx,xps-usb-host-1.00.a",},
215 {},
216};
217MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
218
219static struct platform_driver ehci_hcd_xilinx_of_driver = {
220 .probe = ehci_hcd_xilinx_of_probe,
221 .remove = ehci_hcd_xilinx_of_remove,
222 .shutdown = usb_hcd_platform_shutdown,
223 .driver = {
224 .name = "xilinx-of-ehci",
225 .of_match_table = ehci_hcd_xilinx_of_match,
226 },
227};
228