diff options
author | Jan Andersson <jan@gaisler.com> | 2011-05-06 06:00:18 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-05-06 21:24:02 -0400 |
commit | 3db7739c80990ef53621f76f6095a91e70d88546 (patch) | |
tree | 334f92bdf51969eb4d7e4daa7dc48f63a421fc5c /drivers/usb/host/uhci-grlib.c | |
parent | d3219d1c4c9ab7cd959f8f294420faf5f936cf55 (diff) |
USB: UHCI: Add support for GRLIB GRUSBHC controller
This patch adds support for the UHCI part of the GRLIB GRUSBHC controller
found on some LEON/GRLIB SoCs.
The UHCI HCD previously only supported controllers connected over PCI.
This patch adds support for the first non-PCI UHCI HC. I have tried to
replicate the solution used in ehci-hcd.c.
Tested on GR-LEON4-ITX board (LEON4/GRLIB with GRUSBHC) and x86 with Intel
UHCI HC.
Signed-off-by: Jan Andersson <jan@gaisler.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/uhci-grlib.c')
-rw-r--r-- | drivers/usb/host/uhci-grlib.c | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/drivers/usb/host/uhci-grlib.c b/drivers/usb/host/uhci-grlib.c new file mode 100644 index 000000000000..b1addd60a1ef --- /dev/null +++ b/drivers/usb/host/uhci-grlib.c | |||
@@ -0,0 +1,194 @@ | |||
1 | /* | ||
2 | * UHCI HCD (Host Controller Driver) for GRLIB GRUSBHC | ||
3 | * | ||
4 | * Copyright (c) 2011 Jan Andersson <jan@gaisler.com> | ||
5 | * | ||
6 | * This file is based on UHCI PCI HCD: | ||
7 | * (C) Copyright 1999 Linus Torvalds | ||
8 | * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com | ||
9 | * (C) Copyright 1999 Randy Dunlap | ||
10 | * (C) Copyright 1999 Georg Acher, acher@in.tum.de | ||
11 | * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de | ||
12 | * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch | ||
13 | * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at | ||
14 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface | ||
15 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). | ||
16 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) | ||
17 | * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu | ||
18 | */ | ||
19 | |||
20 | #include <linux/of_irq.h> | ||
21 | #include <linux/of_address.h> | ||
22 | #include <linux/of_platform.h> | ||
23 | |||
24 | static int uhci_grlib_init(struct usb_hcd *hcd) | ||
25 | { | ||
26 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | ||
27 | |||
28 | uhci->rh_numports = uhci_count_ports(hcd); | ||
29 | |||
30 | /* Set up pointers to to generic functions */ | ||
31 | uhci->reset_hc = uhci_generic_reset_hc; | ||
32 | uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc; | ||
33 | /* No special actions need to be taken for the functions below */ | ||
34 | uhci->configure_hc = NULL; | ||
35 | uhci->resume_detect_interrupts_are_broken = NULL; | ||
36 | uhci->global_suspend_mode_is_broken = NULL; | ||
37 | |||
38 | /* Reset if the controller isn't already safely quiescent. */ | ||
39 | check_and_reset_hc(uhci); | ||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | static const struct hc_driver uhci_grlib_hc_driver = { | ||
44 | .description = hcd_name, | ||
45 | .product_desc = "GRLIB GRUSBHC UHCI Host Controller", | ||
46 | .hcd_priv_size = sizeof(struct uhci_hcd), | ||
47 | |||
48 | /* Generic hardware linkage */ | ||
49 | .irq = uhci_irq, | ||
50 | .flags = HCD_MEMORY | HCD_USB11, | ||
51 | |||
52 | /* Basic lifecycle operations */ | ||
53 | .reset = uhci_grlib_init, | ||
54 | .start = uhci_start, | ||
55 | #ifdef CONFIG_PM | ||
56 | .pci_suspend = NULL, | ||
57 | .pci_resume = NULL, | ||
58 | .bus_suspend = uhci_rh_suspend, | ||
59 | .bus_resume = uhci_rh_resume, | ||
60 | #endif | ||
61 | .stop = uhci_stop, | ||
62 | |||
63 | .urb_enqueue = uhci_urb_enqueue, | ||
64 | .urb_dequeue = uhci_urb_dequeue, | ||
65 | |||
66 | .endpoint_disable = uhci_hcd_endpoint_disable, | ||
67 | .get_frame_number = uhci_hcd_get_frame_number, | ||
68 | |||
69 | .hub_status_data = uhci_hub_status_data, | ||
70 | .hub_control = uhci_hub_control, | ||
71 | }; | ||
72 | |||
73 | |||
74 | static int __devinit uhci_hcd_grlib_probe(struct platform_device *op) | ||
75 | { | ||
76 | struct device_node *dn = op->dev.of_node; | ||
77 | struct usb_hcd *hcd; | ||
78 | struct uhci_hcd *uhci = NULL; | ||
79 | struct resource res; | ||
80 | int irq; | ||
81 | int rv; | ||
82 | |||
83 | if (usb_disabled()) | ||
84 | return -ENODEV; | ||
85 | |||
86 | dev_dbg(&op->dev, "initializing GRUSBHC UHCI USB Controller\n"); | ||
87 | |||
88 | rv = of_address_to_resource(dn, 0, &res); | ||
89 | if (rv) | ||
90 | return rv; | ||
91 | |||
92 | /* usb_create_hcd requires dma_mask != NULL */ | ||
93 | op->dev.dma_mask = &op->dev.coherent_dma_mask; | ||
94 | hcd = usb_create_hcd(&uhci_grlib_hc_driver, &op->dev, | ||
95 | "GRUSBHC UHCI USB"); | ||
96 | if (!hcd) | ||
97 | return -ENOMEM; | ||
98 | |||
99 | hcd->rsrc_start = res.start; | ||
100 | hcd->rsrc_len = res.end - res.start + 1; | ||
101 | |||
102 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | ||
103 | printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__); | ||
104 | rv = -EBUSY; | ||
105 | goto err_rmr; | ||
106 | } | ||
107 | |||
108 | irq = irq_of_parse_and_map(dn, 0); | ||
109 | if (irq == NO_IRQ) { | ||
110 | printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); | ||
111 | rv = -EBUSY; | ||
112 | goto err_irq; | ||
113 | } | ||
114 | |||
115 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
116 | if (!hcd->regs) { | ||
117 | printk(KERN_ERR "%s: ioremap failed\n", __FILE__); | ||
118 | rv = -ENOMEM; | ||
119 | goto err_ioremap; | ||
120 | } | ||
121 | |||
122 | uhci = hcd_to_uhci(hcd); | ||
123 | |||
124 | uhci->regs = hcd->regs; | ||
125 | |||
126 | rv = usb_add_hcd(hcd, irq, 0); | ||
127 | if (rv) | ||
128 | goto err_uhci; | ||
129 | |||
130 | return 0; | ||
131 | |||
132 | err_uhci: | ||
133 | iounmap(hcd->regs); | ||
134 | err_ioremap: | ||
135 | irq_dispose_mapping(irq); | ||
136 | err_irq: | ||
137 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
138 | err_rmr: | ||
139 | usb_put_hcd(hcd); | ||
140 | |||
141 | return rv; | ||
142 | } | ||
143 | |||
144 | static int uhci_hcd_grlib_remove(struct platform_device *op) | ||
145 | { | ||
146 | struct usb_hcd *hcd = dev_get_drvdata(&op->dev); | ||
147 | |||
148 | dev_set_drvdata(&op->dev, NULL); | ||
149 | |||
150 | dev_dbg(&op->dev, "stopping GRLIB GRUSBHC UHCI USB Controller\n"); | ||
151 | |||
152 | usb_remove_hcd(hcd); | ||
153 | |||
154 | iounmap(hcd->regs); | ||
155 | irq_dispose_mapping(hcd->irq); | ||
156 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
157 | |||
158 | usb_put_hcd(hcd); | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | /* Make sure the controller is quiescent and that we're not using it | ||
164 | * any more. This is mainly for the benefit of programs which, like kexec, | ||
165 | * expect the hardware to be idle: not doing DMA or generating IRQs. | ||
166 | * | ||
167 | * This routine may be called in a damaged or failing kernel. Hence we | ||
168 | * do not acquire the spinlock before shutting down the controller. | ||
169 | */ | ||
170 | static void uhci_hcd_grlib_shutdown(struct platform_device *op) | ||
171 | { | ||
172 | struct usb_hcd *hcd = dev_get_drvdata(&op->dev); | ||
173 | |||
174 | uhci_hc_died(hcd_to_uhci(hcd)); | ||
175 | } | ||
176 | |||
177 | static const struct of_device_id uhci_hcd_grlib_of_match[] = { | ||
178 | { .name = "GAISLER_UHCI", }, | ||
179 | { .name = "01_027", }, | ||
180 | {}, | ||
181 | }; | ||
182 | MODULE_DEVICE_TABLE(of, uhci_hcd_grlib_of_match); | ||
183 | |||
184 | |||
185 | static struct platform_driver uhci_grlib_driver = { | ||
186 | .probe = uhci_hcd_grlib_probe, | ||
187 | .remove = uhci_hcd_grlib_remove, | ||
188 | .shutdown = uhci_hcd_grlib_shutdown, | ||
189 | .driver = { | ||
190 | .name = "grlib-uhci", | ||
191 | .owner = THIS_MODULE, | ||
192 | .of_match_table = uhci_hcd_grlib_of_match, | ||
193 | }, | ||
194 | }; | ||