Loading...
1/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
4 * Bus Glue for Xilinx EHCI core on the of_platform bus
5 *
6 * Copyright (c) 2009 Xilinx, Inc.
7 *
8 * Based on "ehci-ppc-of.c" by Valentine Barshak <vbarshak@ru.mvista.com>
9 * and "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
10 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 */
27
28#include <linux/signal.h>
29
30#include <linux/of.h>
31#include <linux/of_platform.h>
32#include <linux/of_address.h>
33
34/**
35 * ehci_xilinx_of_setup - Initialize the device for ehci_reset()
36 * @hcd: Pointer to the usb_hcd device to which the host controller bound
37 *
38 * called during probe() after chip reset completes.
39 */
40static int ehci_xilinx_of_setup(struct usb_hcd *hcd)
41{
42 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
43 int retval;
44
45 retval = ehci_halt(ehci);
46 if (retval)
47 return retval;
48
49 retval = ehci_init(hcd);
50 if (retval)
51 return retval;
52
53 ehci->sbrn = 0x20;
54
55 return ehci_reset(ehci);
56}
57
58/**
59 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
60 * @hcd: Pointer to the usb_hcd device to which the host controller bound
61 * @portnum:Port number to which the device is attached.
62 *
63 * This function is used as a place to tell the user that the Xilinx USB host
64 * controller does support LS devices. And in an HS only configuration, it
65 * does not support FS devices either. It is hoped that this can help a
66 * confused user.
67 *
68 * There are cases when the host controller fails to enable the port due to,
69 * for example, insufficient power that can be supplied to the device from
70 * the USB bus. In those cases, the messages printed here are not helpful.
71 */
72static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
73{
74 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
75 if (hcd->has_tt) {
76 dev_warn(hcd->self.controller,
77 "Maybe you have connected a low speed device?\n");
78
79 dev_warn(hcd->self.controller,
80 "We do not support low speed devices\n");
81 } else {
82 dev_warn(hcd->self.controller,
83 "Maybe your device is not a high speed device?\n");
84 dev_warn(hcd->self.controller,
85 "The USB host controller does not support full speed "
86 "nor low speed devices\n");
87 dev_warn(hcd->self.controller,
88 "You can reconfigure the host controller to have "
89 "full speed support\n");
90 }
91
92 return 0;
93}
94
95
96static const struct hc_driver ehci_xilinx_of_hc_driver = {
97 .description = hcd_name,
98 .product_desc = "OF EHCI",
99 .hcd_priv_size = sizeof(struct ehci_hcd),
100
101 /*
102 * generic hardware linkage
103 */
104 .irq = ehci_irq,
105 .flags = HCD_MEMORY | HCD_USB2,
106
107 /*
108 * basic lifecycle operations
109 */
110 .reset = ehci_xilinx_of_setup,
111 .start = ehci_run,
112 .stop = ehci_stop,
113 .shutdown = ehci_shutdown,
114
115 /*
116 * managing i/o requests and associated device resources
117 */
118 .urb_enqueue = ehci_urb_enqueue,
119 .urb_dequeue = ehci_urb_dequeue,
120 .endpoint_disable = ehci_endpoint_disable,
121 .endpoint_reset = ehci_endpoint_reset,
122
123 /*
124 * scheduling support
125 */
126 .get_frame_number = ehci_get_frame,
127
128 /*
129 * root hub support
130 */
131 .hub_status_data = ehci_hub_status_data,
132 .hub_control = ehci_hub_control,
133#ifdef CONFIG_PM
134 .bus_suspend = ehci_bus_suspend,
135 .bus_resume = ehci_bus_resume,
136#endif
137 .relinquish_port = NULL,
138 .port_handed_over = ehci_xilinx_port_handed_over,
139
140 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
141};
142
143/**
144 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
145 * @op: pointer to the platform_device bound to the host controller
146 *
147 * This function requests resources and sets up appropriate properties for the
148 * host controller. Because the Xilinx USB host controller can be configured
149 * as HS only or HS/FS only, it checks the configuration in the device tree
150 * entry, and sets an appropriate value for hcd->has_tt.
151 */
152static int __devinit ehci_hcd_xilinx_of_probe(struct platform_device *op)
153{
154 struct device_node *dn = op->dev.of_node;
155 struct usb_hcd *hcd;
156 struct ehci_hcd *ehci;
157 struct resource res;
158 int irq;
159 int rv;
160 int *value;
161
162 if (usb_disabled())
163 return -ENODEV;
164
165 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
166
167 rv = of_address_to_resource(dn, 0, &res);
168 if (rv)
169 return rv;
170
171 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
172 "XILINX-OF USB");
173 if (!hcd)
174 return -ENOMEM;
175
176 hcd->rsrc_start = res.start;
177 hcd->rsrc_len = resource_size(&res);
178
179 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
180 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
181 rv = -EBUSY;
182 goto err_rmr;
183 }
184
185 irq = irq_of_parse_and_map(dn, 0);
186 if (irq == NO_IRQ) {
187 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
188 rv = -EBUSY;
189 goto err_irq;
190 }
191
192 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
193 if (!hcd->regs) {
194 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
195 rv = -ENOMEM;
196 goto err_ioremap;
197 }
198
199 ehci = hcd_to_ehci(hcd);
200
201 /* This core always has big-endian register interface and uses
202 * big-endian memory descriptors.
203 */
204 ehci->big_endian_mmio = 1;
205 ehci->big_endian_desc = 1;
206
207 /* Check whether the FS support option is selected in the hardware.
208 */
209 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
210 if (value && (*value == 1)) {
211 ehci_dbg(ehci, "USB host controller supports FS devices\n");
212 hcd->has_tt = 1;
213 } else {
214 ehci_dbg(ehci,
215 "USB host controller is HS only\n");
216 hcd->has_tt = 0;
217 }
218
219 /* Debug registers are at the first 0x100 region
220 */
221 ehci->caps = hcd->regs + 0x100;
222 ehci->regs = hcd->regs + 0x100 +
223 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
224
225 /* cache this readonly data; minimize chip reads */
226 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
227
228 rv = usb_add_hcd(hcd, irq, 0);
229 if (rv == 0)
230 return 0;
231
232 iounmap(hcd->regs);
233
234err_ioremap:
235err_irq:
236 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
237err_rmr:
238 usb_put_hcd(hcd);
239
240 return rv;
241}
242
243/**
244 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
245 * @op: pointer to platform_device structure that is to be removed
246 *
247 * Remove the hcd structure, and release resources that has been requested
248 * during probe.
249 */
250static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
251{
252 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
253 dev_set_drvdata(&op->dev, NULL);
254
255 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
256
257 usb_remove_hcd(hcd);
258
259 iounmap(hcd->regs);
260 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
261
262 usb_put_hcd(hcd);
263
264 return 0;
265}
266
267/**
268 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
269 * @op: pointer to platform_device structure that is to be removed
270 *
271 * Properly shutdown the hcd, call driver's shutdown routine.
272 */
273static int ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
274{
275 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
276
277 if (hcd->driver->shutdown)
278 hcd->driver->shutdown(hcd);
279
280 return 0;
281}
282
283
284static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
285 {.compatible = "xlnx,xps-usb-host-1.00.a",},
286 {},
287};
288MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
289
290static struct platform_driver ehci_hcd_xilinx_of_driver = {
291 .probe = ehci_hcd_xilinx_of_probe,
292 .remove = ehci_hcd_xilinx_of_remove,
293 .shutdown = ehci_hcd_xilinx_of_shutdown,
294 .driver = {
295 .name = "xilinx-of-ehci",
296 .owner = THIS_MODULE,
297 .of_match_table = ehci_hcd_xilinx_of_match,
298 },
299};
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * EHCI HCD (Host Controller Driver) for USB.
4 *
5 * Bus Glue for Xilinx EHCI core on the of_platform bus
6 *
7 * Copyright (c) 2009 Xilinx, Inc.
8 *
9 * Based on "ehci-ppc-of.c" by Valentine Barshak <vbarshak@ru.mvista.com>
10 * and "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
11 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
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 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
24 * @hcd: Pointer to the usb_hcd device to which the host controller bound
25 * @portnum:Port number to which the device is attached.
26 *
27 * This function is used as a place to tell the user that the Xilinx USB host
28 * controller does support LS devices. And in an HS only configuration, it
29 * does not support FS devices either. It is hoped that this can help a
30 * confused user.
31 *
32 * There are cases when the host controller fails to enable the port due to,
33 * for example, insufficient power that can be supplied to the device from
34 * the USB bus. In those cases, the messages printed here are not helpful.
35 *
36 * Return: Always return 0
37 */
38static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
39{
40 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
41 if (hcd->has_tt) {
42 dev_warn(hcd->self.controller,
43 "Maybe you have connected a low speed device?\n");
44
45 dev_warn(hcd->self.controller,
46 "We do not support low speed devices\n");
47 } else {
48 dev_warn(hcd->self.controller,
49 "Maybe your device is not a high speed device?\n");
50 dev_warn(hcd->self.controller,
51 "The USB host controller does not support full speed nor low speed devices\n");
52 dev_warn(hcd->self.controller,
53 "You can reconfigure the host controller to have 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 * generic hardware linkage
67 */
68 .irq = ehci_irq,
69 .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH,
70
71 /*
72 * basic lifecycle operations
73 */
74 .reset = ehci_setup,
75 .start = ehci_run,
76 .stop = ehci_stop,
77 .shutdown = ehci_shutdown,
78
79 /*
80 * managing i/o requests and associated device resources
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 * scheduling support
89 */
90 .get_frame_number = ehci_get_frame,
91
92 /*
93 * root hub support
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 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
109 * @op: pointer to the platform_device bound to the host controller
110 *
111 * This function requests resources and sets up appropriate properties for the
112 * host controller. Because the Xilinx USB host controller can be configured
113 * as HS only or HS/FS only, it checks the configuration in the device tree
114 * entry, and sets an appropriate value for hcd->has_tt.
115 *
116 * Return: zero on success, negative error code otherwise
117 */
118static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
119{
120 struct device_node *dn = op->dev.of_node;
121 struct usb_hcd *hcd;
122 struct ehci_hcd *ehci;
123 struct resource res;
124 int irq;
125 int rv;
126 int *value;
127
128 if (usb_disabled())
129 return -ENODEV;
130
131 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
132
133 rv = of_address_to_resource(dn, 0, &res);
134 if (rv)
135 return rv;
136
137 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
138 "XILINX-OF USB");
139 if (!hcd)
140 return -ENOMEM;
141
142 hcd->rsrc_start = res.start;
143 hcd->rsrc_len = resource_size(&res);
144
145 irq = irq_of_parse_and_map(dn, 0);
146 if (!irq) {
147 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
148 __FILE__);
149 rv = -EBUSY;
150 goto err_irq;
151 }
152
153 hcd->regs = devm_ioremap_resource(&op->dev, &res);
154 if (IS_ERR(hcd->regs)) {
155 rv = PTR_ERR(hcd->regs);
156 goto err_irq;
157 }
158
159 ehci = hcd_to_ehci(hcd);
160
161 /* This core always has big-endian register interface and uses
162 * big-endian memory descriptors.
163 */
164 ehci->big_endian_mmio = 1;
165 ehci->big_endian_desc = 1;
166
167 /* Check whether the FS support option is selected in the hardware.
168 */
169 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
170 if (value && (*value == 1)) {
171 ehci_dbg(ehci, "USB host controller supports FS devices\n");
172 hcd->has_tt = 1;
173 } else {
174 ehci_dbg(ehci,
175 "USB host controller is HS only\n");
176 hcd->has_tt = 0;
177 }
178
179 /* Debug registers are at the first 0x100 region
180 */
181 ehci->caps = hcd->regs + 0x100;
182
183 rv = usb_add_hcd(hcd, irq, 0);
184 if (rv == 0) {
185 device_wakeup_enable(hcd->self.controller);
186 return 0;
187 }
188
189err_irq:
190 usb_put_hcd(hcd);
191
192 return rv;
193}
194
195/**
196 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
197 * @op: pointer to platform_device structure that is to be removed
198 *
199 * Remove the hcd structure, and release resources that has been requested
200 * during probe.
201 *
202 * Return: Always return 0
203 */
204static void ehci_hcd_xilinx_of_remove(struct platform_device *op)
205{
206 struct usb_hcd *hcd = platform_get_drvdata(op);
207
208 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
209
210 usb_remove_hcd(hcd);
211
212 usb_put_hcd(hcd);
213}
214
215static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
216 {.compatible = "xlnx,xps-usb-host-1.00.a",},
217 {},
218};
219MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
220
221static struct platform_driver ehci_hcd_xilinx_of_driver = {
222 .probe = ehci_hcd_xilinx_of_probe,
223 .remove = ehci_hcd_xilinx_of_remove,
224 .shutdown = usb_hcd_platform_shutdown,
225 .driver = {
226 .name = "xilinx-of-ehci",
227 .of_match_table = ehci_hcd_xilinx_of_match,
228 },
229};