Merge branch 'for-3.11' of git://linux-nfs.org/~bfields/linux
[linux-2.6.git] / drivers / usb / host / ehci-grlib.c
bloba77bd8dc33f42fe6662cd88b9b2fbb8f879a6aa2
1 /*
2 * Driver for Aeroflex Gaisler GRLIB GRUSBHC EHCI host controller
4 * GRUSBHC is typically found on LEON/GRLIB SoCs
6 * (c) Jan Andersson <jan@gaisler.com>
8 * Based on ehci-ppc-of.c which is:
9 * (c) Valentine Barshak <vbarshak@ru.mvista.com>
10 * and in turn based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
11 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <linux/err.h>
29 #include <linux/signal.h>
31 #include <linux/of_irq.h>
32 #include <linux/of_address.h>
33 #include <linux/of_platform.h>
35 #define GRUSBHC_HCIVERSION 0x0100 /* Known value of cap. reg. HCIVERSION */
37 static const struct hc_driver ehci_grlib_hc_driver = {
38 .description = hcd_name,
39 .product_desc = "GRLIB GRUSBHC EHCI",
40 .hcd_priv_size = sizeof(struct ehci_hcd),
43 * generic hardware linkage
45 .irq = ehci_irq,
46 .flags = HCD_MEMORY | HCD_USB2,
49 * basic lifecycle operations
51 .reset = ehci_setup,
52 .start = ehci_run,
53 .stop = ehci_stop,
54 .shutdown = ehci_shutdown,
57 * managing i/o requests and associated device resources
59 .urb_enqueue = ehci_urb_enqueue,
60 .urb_dequeue = ehci_urb_dequeue,
61 .endpoint_disable = ehci_endpoint_disable,
62 .endpoint_reset = ehci_endpoint_reset,
65 * scheduling support
67 .get_frame_number = ehci_get_frame,
70 * root hub support
72 .hub_status_data = ehci_hub_status_data,
73 .hub_control = ehci_hub_control,
74 #ifdef CONFIG_PM
75 .bus_suspend = ehci_bus_suspend,
76 .bus_resume = ehci_bus_resume,
77 #endif
78 .relinquish_port = ehci_relinquish_port,
79 .port_handed_over = ehci_port_handed_over,
81 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
85 static int ehci_hcd_grlib_probe(struct platform_device *op)
87 struct device_node *dn = op->dev.of_node;
88 struct usb_hcd *hcd;
89 struct ehci_hcd *ehci = NULL;
90 struct resource res;
91 u32 hc_capbase;
92 int irq;
93 int rv;
95 if (usb_disabled())
96 return -ENODEV;
98 dev_dbg(&op->dev, "initializing GRUSBHC EHCI USB Controller\n");
100 rv = of_address_to_resource(dn, 0, &res);
101 if (rv)
102 return rv;
104 /* usb_create_hcd requires dma_mask != NULL */
105 op->dev.dma_mask = &op->dev.coherent_dma_mask;
106 hcd = usb_create_hcd(&ehci_grlib_hc_driver, &op->dev,
107 "GRUSBHC EHCI USB");
108 if (!hcd)
109 return -ENOMEM;
111 hcd->rsrc_start = res.start;
112 hcd->rsrc_len = resource_size(&res);
114 irq = irq_of_parse_and_map(dn, 0);
115 if (irq == NO_IRQ) {
116 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
117 rv = -EBUSY;
118 goto err_irq;
121 hcd->regs = devm_ioremap_resource(&op->dev, &res);
122 if (IS_ERR(hcd->regs)) {
123 rv = PTR_ERR(hcd->regs);
124 goto err_ioremap;
127 ehci = hcd_to_ehci(hcd);
129 ehci->caps = hcd->regs;
131 /* determine endianness of this implementation */
132 hc_capbase = ehci_readl(ehci, &ehci->caps->hc_capbase);
133 if (HC_VERSION(ehci, hc_capbase) != GRUSBHC_HCIVERSION) {
134 ehci->big_endian_mmio = 1;
135 ehci->big_endian_desc = 1;
136 ehci->big_endian_capbase = 1;
139 rv = usb_add_hcd(hcd, irq, 0);
140 if (rv)
141 goto err_ioremap;
143 return 0;
145 err_ioremap:
146 irq_dispose_mapping(irq);
147 err_irq:
148 usb_put_hcd(hcd);
150 return rv;
154 static int ehci_hcd_grlib_remove(struct platform_device *op)
156 struct usb_hcd *hcd = platform_get_drvdata(op);
158 dev_dbg(&op->dev, "stopping GRLIB GRUSBHC EHCI USB Controller\n");
160 usb_remove_hcd(hcd);
162 irq_dispose_mapping(hcd->irq);
164 usb_put_hcd(hcd);
166 return 0;
170 static void ehci_hcd_grlib_shutdown(struct platform_device *op)
172 struct usb_hcd *hcd = platform_get_drvdata(op);
174 if (hcd->driver->shutdown)
175 hcd->driver->shutdown(hcd);
179 static const struct of_device_id ehci_hcd_grlib_of_match[] = {
181 .name = "GAISLER_EHCI",
184 .name = "01_026",
188 MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match);
191 static struct platform_driver ehci_grlib_driver = {
192 .probe = ehci_hcd_grlib_probe,
193 .remove = ehci_hcd_grlib_remove,
194 .shutdown = ehci_hcd_grlib_shutdown,
195 .driver = {
196 .name = "grlib-ehci",
197 .owner = THIS_MODULE,
198 .of_match_table = ehci_hcd_grlib_of_match,