2 * EHCI HCD (Host Controller Driver) for USB.
4 * Bus Glue for Xilinx EHCI core on the of_platform bus
6 * Copyright (c) 2009 Xilinx, Inc.
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>
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.
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
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.
28 #include <linux/signal.h>
31 #include <linux/of_platform.h>
32 #include <linux/of_address.h>
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
38 * called during probe() after chip reset completes.
40 static int ehci_xilinx_of_setup(struct usb_hcd
*hcd
)
42 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
45 retval
= ehci_halt(ehci
);
49 retval
= ehci_init(hcd
);
55 return ehci_reset(ehci
);
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.
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
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.
72 static int ehci_xilinx_port_handed_over(struct usb_hcd
*hcd
, int portnum
)
74 dev_warn(hcd
->self
.controller
, "port %d cannot be enabled\n", portnum
);
76 dev_warn(hcd
->self
.controller
,
77 "Maybe you have connected a low speed device?\n");
79 dev_warn(hcd
->self
.controller
,
80 "We do not support low speed devices\n");
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");
96 static 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
),
102 * generic hardware linkage
105 .flags
= HCD_MEMORY
| HCD_USB2
,
108 * basic lifecycle operations
110 .reset
= ehci_xilinx_of_setup
,
113 .shutdown
= ehci_shutdown
,
116 * managing i/o requests and associated device resources
118 .urb_enqueue
= ehci_urb_enqueue
,
119 .urb_dequeue
= ehci_urb_dequeue
,
120 .endpoint_disable
= ehci_endpoint_disable
,
121 .endpoint_reset
= ehci_endpoint_reset
,
126 .get_frame_number
= ehci_get_frame
,
131 .hub_status_data
= ehci_hub_status_data
,
132 .hub_control
= ehci_hub_control
,
134 .bus_suspend
= ehci_bus_suspend
,
135 .bus_resume
= ehci_bus_resume
,
137 .relinquish_port
= NULL
,
138 .port_handed_over
= ehci_xilinx_port_handed_over
,
140 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
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 * @match: pointer to of_device_id structure, not used
148 * This function requests resources and sets up appropriate properties for the
149 * host controller. Because the Xilinx USB host controller can be configured
150 * as HS only or HS/FS only, it checks the configuration in the device tree
151 * entry, and sets an appropriate value for hcd->has_tt.
154 ehci_hcd_xilinx_of_probe(struct platform_device
*op
, const struct of_device_id
*match
)
156 struct device_node
*dn
= op
->dev
.of_node
;
158 struct ehci_hcd
*ehci
;
167 dev_dbg(&op
->dev
, "initializing XILINX-OF USB Controller\n");
169 rv
= of_address_to_resource(dn
, 0, &res
);
173 hcd
= usb_create_hcd(&ehci_xilinx_of_hc_driver
, &op
->dev
,
178 hcd
->rsrc_start
= res
.start
;
179 hcd
->rsrc_len
= res
.end
- res
.start
+ 1;
181 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, hcd_name
)) {
182 printk(KERN_ERR
"%s: request_mem_region failed\n", __FILE__
);
187 irq
= irq_of_parse_and_map(dn
, 0);
189 printk(KERN_ERR
"%s: irq_of_parse_and_map failed\n", __FILE__
);
194 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
196 printk(KERN_ERR
"%s: ioremap failed\n", __FILE__
);
201 ehci
= hcd_to_ehci(hcd
);
203 /* This core always has big-endian register interface and uses
204 * big-endian memory descriptors.
206 ehci
->big_endian_mmio
= 1;
207 ehci
->big_endian_desc
= 1;
209 /* Check whether the FS support option is selected in the hardware.
211 value
= (int *)of_get_property(dn
, "xlnx,support-usb-fs", NULL
);
212 if (value
&& (*value
== 1)) {
213 ehci_dbg(ehci
, "USB host controller supports FS devices\n");
217 "USB host controller is HS only\n");
221 /* Debug registers are at the first 0x100 region
223 ehci
->caps
= hcd
->regs
+ 0x100;
224 ehci
->regs
= hcd
->regs
+ 0x100 +
225 HC_LENGTH(ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
227 /* cache this readonly data; minimize chip reads */
228 ehci
->hcs_params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
230 rv
= usb_add_hcd(hcd
, irq
, 0);
238 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
246 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
247 * @op: pointer to platform_device structure that is to be removed
249 * Remove the hcd structure, and release resources that has been requested
252 static int ehci_hcd_xilinx_of_remove(struct platform_device
*op
)
254 struct usb_hcd
*hcd
= dev_get_drvdata(&op
->dev
);
255 dev_set_drvdata(&op
->dev
, NULL
);
257 dev_dbg(&op
->dev
, "stopping XILINX-OF USB Controller\n");
262 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
270 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
271 * @op: pointer to platform_device structure that is to be removed
273 * Properly shutdown the hcd, call driver's shutdown routine.
275 static int ehci_hcd_xilinx_of_shutdown(struct platform_device
*op
)
277 struct usb_hcd
*hcd
= dev_get_drvdata(&op
->dev
);
279 if (hcd
->driver
->shutdown
)
280 hcd
->driver
->shutdown(hcd
);
286 static const struct of_device_id ehci_hcd_xilinx_of_match
[] = {
287 {.compatible
= "xlnx,xps-usb-host-1.00.a",},
290 MODULE_DEVICE_TABLE(of
, ehci_hcd_xilinx_of_match
);
292 static struct of_platform_driver ehci_hcd_xilinx_of_driver
= {
293 .probe
= ehci_hcd_xilinx_of_probe
,
294 .remove
= ehci_hcd_xilinx_of_remove
,
295 .shutdown
= ehci_hcd_xilinx_of_shutdown
,
297 .name
= "xilinx-of-ehci",
298 .owner
= THIS_MODULE
,
299 .of_match_table
= ehci_hcd_xilinx_of_match
,