1 // SPDX-License-Identifier: GPL-2.0+
3 * EHCI HCD (Host Controller Driver) for USB.
5 * Bus Glue for Xilinx EHCI core on the of_platform bus
7 * Copyright (c) 2009 Xilinx, Inc.
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>
14 #include <linux/err.h>
15 #include <linux/signal.h>
18 #include <linux/of_platform.h>
19 #include <linux/of_address.h>
20 #include <linux/of_irq.h>
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.
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
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.
36 static int ehci_xilinx_port_handed_over(struct usb_hcd
*hcd
, int portnum
)
38 dev_warn(hcd
->self
.controller
, "port %d cannot be enabled\n", portnum
);
40 dev_warn(hcd
->self
.controller
,
41 "Maybe you have connected a low speed device?\n");
43 dev_warn(hcd
->self
.controller
,
44 "We do not support low speed devices\n");
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");
60 static 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
),
66 * generic hardware linkage
69 .flags
= HCD_MEMORY
| HCD_USB2
| HCD_BH
,
72 * basic lifecycle operations
77 .shutdown
= ehci_shutdown
,
80 * managing i/o requests and associated device resources
82 .urb_enqueue
= ehci_urb_enqueue
,
83 .urb_dequeue
= ehci_urb_dequeue
,
84 .endpoint_disable
= ehci_endpoint_disable
,
85 .endpoint_reset
= ehci_endpoint_reset
,
90 .get_frame_number
= ehci_get_frame
,
95 .hub_status_data
= ehci_hub_status_data
,
96 .hub_control
= ehci_hub_control
,
98 .bus_suspend
= ehci_bus_suspend
,
99 .bus_resume
= ehci_bus_resume
,
101 .relinquish_port
= NULL
,
102 .port_handed_over
= ehci_xilinx_port_handed_over
,
104 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
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
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.
116 static int ehci_hcd_xilinx_of_probe(struct platform_device
*op
)
118 struct device_node
*dn
= op
->dev
.of_node
;
120 struct ehci_hcd
*ehci
;
129 dev_dbg(&op
->dev
, "initializing XILINX-OF USB Controller\n");
131 rv
= of_address_to_resource(dn
, 0, &res
);
135 hcd
= usb_create_hcd(&ehci_xilinx_of_hc_driver
, &op
->dev
,
140 hcd
->rsrc_start
= res
.start
;
141 hcd
->rsrc_len
= resource_size(&res
);
143 irq
= irq_of_parse_and_map(dn
, 0);
145 dev_err(&op
->dev
, "%s: irq_of_parse_and_map failed\n",
151 hcd
->regs
= devm_ioremap_resource(&op
->dev
, &res
);
152 if (IS_ERR(hcd
->regs
)) {
153 rv
= PTR_ERR(hcd
->regs
);
157 ehci
= hcd_to_ehci(hcd
);
159 /* This core always has big-endian register interface and uses
160 * big-endian memory descriptors.
162 ehci
->big_endian_mmio
= 1;
163 ehci
->big_endian_desc
= 1;
165 /* Check whether the FS support option is selected in the hardware.
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");
173 "USB host controller is HS only\n");
177 /* Debug registers are at the first 0x100 region
179 ehci
->caps
= hcd
->regs
+ 0x100;
181 rv
= usb_add_hcd(hcd
, irq
, 0);
183 device_wakeup_enable(hcd
->self
.controller
);
194 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
195 * @op: pointer to platform_device structure that is to be removed
197 * Remove the hcd structure, and release resources that has been requested
200 static int ehci_hcd_xilinx_of_remove(struct platform_device
*op
)
202 struct usb_hcd
*hcd
= platform_get_drvdata(op
);
204 dev_dbg(&op
->dev
, "stopping XILINX-OF USB Controller\n");
213 static const struct of_device_id ehci_hcd_xilinx_of_match
[] = {
214 {.compatible
= "xlnx,xps-usb-host-1.00.a",},
217 MODULE_DEVICE_TABLE(of
, ehci_hcd_xilinx_of_match
);
219 static 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
,
224 .name
= "xilinx-of-ehci",
225 .of_match_table
= ehci_hcd_xilinx_of_match
,