aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Victor <andrew@sanpeople.com>2006-01-22 13:32:13 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-20 17:49:55 -0500
commit39a269c09f854d3d98cbb755b3568175f04efa10 (patch)
treedcba12509961393e9f2920b23a337af8d6c4aec3
parentd0852299381326c5d8eb67771aa98108050e6901 (diff)
[PATCH] USB: add support for OCHI on AT91rm9200
This adds support for OHCI on AT91rm9200 based boards. Possibly of interest here is the way this uses <linux/clk.h> to gate clocks on/off during system pm state transitions. That's typical for non-PCI systems. Some can go further; Mini-A host side connectors enable ID-pin sensing. From: Andrew Victor <andrew@sanpeople.com> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/Kconfig1
-rw-r--r--drivers/usb/Makefile1
-rw-r--r--drivers/usb/host/ohci-at91.c306
-rw-r--r--drivers/usb/host/ohci-hcd.c5
4 files changed, 313 insertions, 0 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 0e865975899f..b1222cd4aa46 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -23,6 +23,7 @@ config USB_ARCH_HAS_OHCI
23 default y if ARCH_LH7A404 23 default y if ARCH_LH7A404
24 default y if ARCH_S3C2410 24 default y if ARCH_S3C2410
25 default y if PXA27x 25 default y if PXA27x
26 default y if ARCH_AT91RM9200
26 # PPC: 27 # PPC:
27 default y if STB03xxx 28 default y if STB03xxx
28 default y if PPC_MPC52xx 29 default y if PPC_MPC52xx
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 7796ecfc0765..bb36a1c1dbb3 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_USB_OHCI_HCD) += host/
15obj-$(CONFIG_USB_UHCI_HCD) += host/ 15obj-$(CONFIG_USB_UHCI_HCD) += host/
16obj-$(CONFIG_USB_SL811_HCD) += host/ 16obj-$(CONFIG_USB_SL811_HCD) += host/
17obj-$(CONFIG_ETRAX_USB_HOST) += host/ 17obj-$(CONFIG_ETRAX_USB_HOST) += host/
18obj-$(CONFIG_USB_OHCI_AT91) += host/
18 19
19obj-$(CONFIG_USB_ACM) += class/ 20obj-$(CONFIG_USB_ACM) += class/
20obj-$(CONFIG_USB_PRINTER) += class/ 21obj-$(CONFIG_USB_PRINTER) += class/
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
new file mode 100644
index 000000000000..980030d684d5
--- /dev/null
+++ b/drivers/usb/host/ohci-at91.c
@@ -0,0 +1,306 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * Copyright (C) 2004 SAN People (Pty) Ltd.
5 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
6 *
7 * AT91RM9200 Bus Glue
8 *
9 * Based on fragments of 2.4 driver by Rick Bronson.
10 * Based on ohci-omap.c
11 *
12 * This file is licenced under the GPL.
13 */
14
15#include <linux/clk.h>
16#include <linux/platform_device.h>
17
18#include <asm/mach-types.h>
19#include <asm/hardware.h>
20#include <asm/arch/board.h>
21
22#ifndef CONFIG_ARCH_AT91RM9200
23#error "This file is AT91RM9200 bus glue. CONFIG_ARCH_AT91RM9200 must be defined."
24#endif
25
26/* interface and function clocks */
27static struct clk *iclk, *fclk;
28
29extern int usb_disabled(void);
30
31/*-------------------------------------------------------------------------*/
32
33static void at91_start_hc(struct platform_device *pdev)
34{
35 struct usb_hcd *hcd = platform_get_drvdata(pdev);
36 struct ohci_regs __iomem *regs = hcd->regs;
37
38 dev_dbg(&pdev->dev, "starting AT91RM9200 OHCI USB Controller\n");
39
40 /*
41 * Start the USB clocks.
42 */
43 clk_enable(iclk);
44 clk_enable(fclk);
45
46 /*
47 * The USB host controller must remain in reset.
48 */
49 writel(0, &regs->control);
50}
51
52static void at91_stop_hc(struct platform_device *pdev)
53{
54 struct usb_hcd *hcd = platform_get_drvdata(pdev);
55 struct ohci_regs __iomem *regs = hcd->regs;
56
57 dev_dbg(&pdev->dev, "stopping AT91RM9200 OHCI USB Controller\n");
58
59 /*
60 * Put the USB host controller into reset.
61 */
62 writel(0, &regs->control);
63
64 /*
65 * Stop the USB clocks.
66 */
67 clk_disable(fclk);
68 clk_disable(iclk);
69}
70
71
72/*-------------------------------------------------------------------------*/
73
74static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
75
76/* configure so an HC device and id are always provided */
77/* always called with process context; sleeping is OK */
78
79
80/**
81 * usb_hcd_at91_probe - initialize AT91RM9200-based HCDs
82 * Context: !in_interrupt()
83 *
84 * Allocates basic resources for this USB host controller, and
85 * then invokes the start() method for the HCD associated with it
86 * through the hotplug entry's driver_data.
87 *
88 * Store this function in the HCD's struct pci_driver as probe().
89 */
90int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *pdev)
91{
92 int retval;
93 struct usb_hcd *hcd = NULL;
94
95 if (pdev->num_resources != 2) {
96 pr_debug("hcd probe: invalid num_resources");
97 return -ENODEV;
98 }
99
100 if ((pdev->resource[0].flags != IORESOURCE_MEM) || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
101 pr_debug("hcd probe: invalid resource type\n");
102 return -ENODEV;
103 }
104
105 hcd = usb_create_hcd(driver, &pdev->dev, "at91rm9200");
106 if (!hcd)
107 return -ENOMEM;
108 hcd->rsrc_start = pdev->resource[0].start;
109 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
110
111 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
112 pr_debug("request_mem_region failed\n");
113 retval = -EBUSY;
114 goto err1;
115 }
116
117 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
118 if (!hcd->regs) {
119 pr_debug("ioremap failed\n");
120 retval = -EIO;
121 goto err2;
122 }
123
124 iclk = clk_get(&pdev->dev, "ohci_clk");
125 fclk = clk_get(&pdev->dev, "uhpck");
126
127 at91_start_hc(pdev);
128 ohci_hcd_init(hcd_to_ohci(hcd));
129
130 retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
131 if (retval == 0)
132 return retval;
133
134 /* Error handling */
135 at91_stop_hc(pdev);
136
137 clk_put(fclk);
138 clk_put(iclk);
139
140 iounmap(hcd->regs);
141
142 err2:
143 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
144
145 err1:
146 usb_put_hcd(hcd);
147 return retval;
148}
149
150
151/* may be called without controller electrically present */
152/* may be called with controller, bus, and devices active */
153
154/**
155 * usb_hcd_at91_remove - shutdown processing for AT91RM9200-based HCDs
156 * @dev: USB Host Controller being removed
157 * Context: !in_interrupt()
158 *
159 * Reverses the effect of usb_hcd_at91_probe(), first invoking
160 * the HCD's stop() method. It is always called from a thread
161 * context, normally "rmmod", "apmd", or something similar.
162 *
163 */
164static int usb_hcd_at91_remove (struct usb_hcd *hcd, struct platform_device *pdev)
165{
166 usb_remove_hcd(hcd);
167 at91_stop_hc(pdev);
168 iounmap(hcd->regs);
169 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
170
171 clk_put(fclk);
172 clk_put(iclk);
173 fclk = iclk = NULL;
174
175 dev_set_drvdata(&pdev->dev, NULL);
176 return 0;
177}
178
179/*-------------------------------------------------------------------------*/
180
181static int __devinit
182ohci_at91_start (struct usb_hcd *hcd)
183{
184// struct at91_ohci_data *board = hcd->self.controller->platform_data;
185 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
186 int ret;
187
188 if ((ret = ohci_init(ohci)) < 0)
189 return ret;
190
191 if ((ret = ohci_run(ohci)) < 0) {
192 err("can't start %s", hcd->self.bus_name);
193 ohci_stop(hcd);
194 return ret;
195 }
196// hcd->self.root_hub->maxchild = board->ports;
197 return 0;
198}
199
200/*-------------------------------------------------------------------------*/
201
202static const struct hc_driver ohci_at91_hc_driver = {
203 .description = hcd_name,
204 .product_desc = "AT91RM9200 OHCI",
205 .hcd_priv_size = sizeof(struct ohci_hcd),
206
207 /*
208 * generic hardware linkage
209 */
210 .irq = ohci_irq,
211 .flags = HCD_USB11 | HCD_MEMORY,
212
213 /*
214 * basic lifecycle operations
215 */
216 .start = ohci_at91_start,
217 .stop = ohci_stop,
218
219 /*
220 * managing i/o requests and associated device resources
221 */
222 .urb_enqueue = ohci_urb_enqueue,
223 .urb_dequeue = ohci_urb_dequeue,
224 .endpoint_disable = ohci_endpoint_disable,
225
226 /*
227 * scheduling support
228 */
229 .get_frame_number = ohci_get_frame,
230
231 /*
232 * root hub support
233 */
234 .hub_status_data = ohci_hub_status_data,
235 .hub_control = ohci_hub_control,
236
237#ifdef CONFIG_PM
238 .hub_suspend = ohci_hub_suspend,
239 .hub_resume = ohci_hub_resume,
240#endif
241 .start_port_reset = ohci_start_port_reset,
242};
243
244/*-------------------------------------------------------------------------*/
245
246static int ohci_hcd_at91_drv_probe(struct platform_device *dev)
247{
248 return usb_hcd_at91_probe(&ohci_at91_hc_driver, dev);
249}
250
251static int ohci_hcd_at91_drv_remove(struct platform_device *dev)
252{
253 return usb_hcd_at91_remove(platform_get_drvdata(dev), dev);
254}
255
256#ifdef CONFIG_PM
257static int ohci_hcd_at91_drv_suspend(struct platform_device *dev, u32 state, u32 level)
258{
259 printk("%s(%s:%d): not implemented yet\n",
260 __func__, __FILE__, __LINE__);
261
262 clk_disable(fclk);
263
264 return 0;
265}
266
267static int ohci_hcd_at91_drv_resume(struct platform_device *dev, u32 state)
268{
269 printk("%s(%s:%d): not implemented yet\n",
270 __func__, __FILE__, __LINE__);
271
272 clk_enable(fclk);
273
274 return 0;
275}
276#else
277#define ohci_hcd_at91_drv_suspend NULL
278#define ohci_hcd_at91_drv_resume NULL
279#endif
280
281static struct platform_driver ohci_hcd_at91_driver = {
282 .probe = ohci_hcd_at91_drv_probe,
283 .remove = ohci_hcd_at91_drv_remove,
284 .suspend = ohci_hcd_at91_drv_suspend,
285 .resume = ohci_hcd_at91_drv_resume,
286 .driver = {
287 .name = "at91rm9200-ohci",
288 .owner = THIS_MODULE,
289 },
290};
291
292static int __init ohci_hcd_at91_init (void)
293{
294 if (usb_disabled())
295 return -ENODEV;
296
297 return platform_driver_register(&ohci_hcd_at91_driver);
298}
299
300static void __exit ohci_hcd_at91_cleanup (void)
301{
302 platform_driver_unregister(&ohci_hcd_at91_driver);
303}
304
305module_init (ohci_hcd_at91_init);
306module_exit (ohci_hcd_at91_cleanup);
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index a4b12404ae08..2990be269000 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -905,6 +905,10 @@ MODULE_LICENSE ("GPL");
905#include "ohci-ppc-soc.c" 905#include "ohci-ppc-soc.c"
906#endif 906#endif
907 907
908#ifdef CONFIG_ARCH_AT91RM9200
909#include "ohci-at91.c"
910#endif
911
908#if !(defined(CONFIG_PCI) \ 912#if !(defined(CONFIG_PCI) \
909 || defined(CONFIG_SA1111) \ 913 || defined(CONFIG_SA1111) \
910 || defined(CONFIG_ARCH_S3C2410) \ 914 || defined(CONFIG_ARCH_S3C2410) \
@@ -913,6 +917,7 @@ MODULE_LICENSE ("GPL");
913 || defined (CONFIG_PXA27x) \ 917 || defined (CONFIG_PXA27x) \
914 || defined (CONFIG_SOC_AU1X00) \ 918 || defined (CONFIG_SOC_AU1X00) \
915 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \ 919 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \
920 || defined (CONFIG_ARCH_AT91RM9200) \
916 ) 921 )
917#error "missing bus glue for ohci-hcd" 922#error "missing bus glue for ohci-hcd"
918#endif 923#endif