proc: use seq_puts()/seq_putc() where possible
[linux-2.6/next.git] / drivers / usb / host / ehci-xilinx-of.c
blobe8f4f36fdf0b457ad917481fe89f269c171d37a2
1 /*
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
20 * for more details.
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>
30 #include <linux/of.h>
31 #include <linux/of_platform.h>
33 /**
34 * ehci_xilinx_of_setup - Initialize the device for ehci_reset()
35 * @hcd: Pointer to the usb_hcd device to which the host controller bound
37 * called during probe() after chip reset completes.
39 static int ehci_xilinx_of_setup(struct usb_hcd *hcd)
41 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
42 int retval;
44 retval = ehci_halt(ehci);
45 if (retval)
46 return retval;
48 retval = ehci_init(hcd);
49 if (retval)
50 return retval;
52 ehci->sbrn = 0x20;
54 return ehci_reset(ehci);
57 /**
58 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
59 * @hcd: Pointer to the usb_hcd device to which the host controller bound
60 * @portnum:Port number to which the device is attached.
62 * This function is used as a place to tell the user that the Xilinx USB host
63 * controller does support LS devices. And in an HS only configuration, it
64 * does not support FS devices either. It is hoped that this can help a
65 * confused user.
67 * There are cases when the host controller fails to enable the port due to,
68 * for example, insufficient power that can be supplied to the device from
69 * the USB bus. In those cases, the messages printed here are not helpful.
71 static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
73 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
74 if (hcd->has_tt) {
75 dev_warn(hcd->self.controller,
76 "Maybe you have connected a low speed device?\n");
78 dev_warn(hcd->self.controller,
79 "We do not support low speed devices\n");
80 } else {
81 dev_warn(hcd->self.controller,
82 "Maybe your device is not a high speed device?\n");
83 dev_warn(hcd->self.controller,
84 "The USB host controller does not support full speed "
85 "nor low speed devices\n");
86 dev_warn(hcd->self.controller,
87 "You can reconfigure the host controller to have "
88 "full speed support\n");
91 return 0;
95 static const struct hc_driver ehci_xilinx_of_hc_driver = {
96 .description = hcd_name,
97 .product_desc = "OF EHCI",
98 .hcd_priv_size = sizeof(struct ehci_hcd),
101 * generic hardware linkage
103 .irq = ehci_irq,
104 .flags = HCD_MEMORY | HCD_USB2,
107 * basic lifecycle operations
109 .reset = ehci_xilinx_of_setup,
110 .start = ehci_run,
111 .stop = ehci_stop,
112 .shutdown = ehci_shutdown,
115 * managing i/o requests and associated device resources
117 .urb_enqueue = ehci_urb_enqueue,
118 .urb_dequeue = ehci_urb_dequeue,
119 .endpoint_disable = ehci_endpoint_disable,
120 .endpoint_reset = ehci_endpoint_reset,
123 * scheduling support
125 .get_frame_number = ehci_get_frame,
128 * root hub support
130 .hub_status_data = ehci_hub_status_data,
131 .hub_control = ehci_hub_control,
132 #ifdef CONFIG_PM
133 .bus_suspend = ehci_bus_suspend,
134 .bus_resume = ehci_bus_resume,
135 #endif
136 .relinquish_port = NULL,
137 .port_handed_over = ehci_xilinx_port_handed_over,
139 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
143 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
144 * @op: pointer to the platform_device bound to the host controller
145 * @match: pointer to of_device_id structure, not used
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.
152 static int __devinit
153 ehci_hcd_xilinx_of_probe(struct platform_device *op, const struct of_device_id *match)
155 struct device_node *dn = op->dev.of_node;
156 struct usb_hcd *hcd;
157 struct ehci_hcd *ehci;
158 struct resource res;
159 int irq;
160 int rv;
161 int *value;
163 if (usb_disabled())
164 return -ENODEV;
166 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
168 rv = of_address_to_resource(dn, 0, &res);
169 if (rv)
170 return rv;
172 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
173 "XILINX-OF USB");
174 if (!hcd)
175 return -ENOMEM;
177 hcd->rsrc_start = res.start;
178 hcd->rsrc_len = res.end - res.start + 1;
180 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
181 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
182 rv = -EBUSY;
183 goto err_rmr;
186 irq = irq_of_parse_and_map(dn, 0);
187 if (irq == NO_IRQ) {
188 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
189 rv = -EBUSY;
190 goto err_irq;
193 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
194 if (!hcd->regs) {
195 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
196 rv = -ENOMEM;
197 goto err_ioremap;
200 ehci = hcd_to_ehci(hcd);
202 /* This core always has big-endian register interface and uses
203 * big-endian memory descriptors.
205 ehci->big_endian_mmio = 1;
206 ehci->big_endian_desc = 1;
208 /* Check whether the FS support option is selected in the hardware.
210 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
211 if (value && (*value == 1)) {
212 ehci_dbg(ehci, "USB host controller supports FS devices\n");
213 hcd->has_tt = 1;
214 } else {
215 ehci_dbg(ehci,
216 "USB host controller is HS only\n");
217 hcd->has_tt = 0;
220 /* Debug registers are at the first 0x100 region
222 ehci->caps = hcd->regs + 0x100;
223 ehci->regs = hcd->regs + 0x100 +
224 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
226 /* cache this readonly data; minimize chip reads */
227 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
229 rv = usb_add_hcd(hcd, irq, 0);
230 if (rv == 0)
231 return 0;
233 iounmap(hcd->regs);
235 err_ioremap:
236 err_irq:
237 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
238 err_rmr:
239 usb_put_hcd(hcd);
241 return rv;
245 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
246 * @op: pointer to platform_device structure that is to be removed
248 * Remove the hcd structure, and release resources that has been requested
249 * during probe.
251 static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
253 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
254 dev_set_drvdata(&op->dev, NULL);
256 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
258 usb_remove_hcd(hcd);
260 iounmap(hcd->regs);
261 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
263 usb_put_hcd(hcd);
265 return 0;
269 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
270 * @op: pointer to platform_device structure that is to be removed
272 * Properly shutdown the hcd, call driver's shutdown routine.
274 static int ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
276 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
278 if (hcd->driver->shutdown)
279 hcd->driver->shutdown(hcd);
281 return 0;
285 static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
286 {.compatible = "xlnx,xps-usb-host-1.00.a",},
289 MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
291 static struct of_platform_driver ehci_hcd_xilinx_of_driver = {
292 .probe = ehci_hcd_xilinx_of_probe,
293 .remove = ehci_hcd_xilinx_of_remove,
294 .shutdown = ehci_hcd_xilinx_of_shutdown,
295 .driver = {
296 .name = "xilinx-of-ehci",
297 .owner = THIS_MODULE,
298 .of_match_table = ehci_hcd_xilinx_of_match,