Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / usb / host / ohci-at91.c
blob6b7350b52419fc57e925081e21ea9757b6e33ef5
1 /*
2 * OHCI HCD (Host Controller Driver) for USB.
4 * Copyright (C) 2004 SAN People (Pty) Ltd.
5 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
7 * AT91RM9200 Bus Glue
9 * Based on fragments of 2.4 driver by Rick Bronson.
10 * Based on ohci-omap.c
12 * This file is licenced under the GPL.
15 #include <linux/clk.h>
16 #include <linux/platform_device.h>
18 #include <asm/mach-types.h>
19 #include <asm/hardware.h>
20 #include <asm/arch/board.h>
22 #ifndef CONFIG_ARCH_AT91RM9200
23 #error "CONFIG_ARCH_AT91RM9200 must be defined."
24 #endif
26 /* interface and function clocks */
27 static struct clk *iclk, *fclk;
29 extern int usb_disabled(void);
31 /*-------------------------------------------------------------------------*/
33 static void at91_start_hc(struct platform_device *pdev)
35 struct usb_hcd *hcd = platform_get_drvdata(pdev);
36 struct ohci_regs __iomem *regs = hcd->regs;
38 dev_dbg(&pdev->dev, "starting AT91RM9200 OHCI USB Controller\n");
41 * Start the USB clocks.
43 clk_enable(iclk);
44 clk_enable(fclk);
47 * The USB host controller must remain in reset.
49 writel(0, &regs->control);
52 static void at91_stop_hc(struct platform_device *pdev)
54 struct usb_hcd *hcd = platform_get_drvdata(pdev);
55 struct ohci_regs __iomem *regs = hcd->regs;
57 dev_dbg(&pdev->dev, "stopping AT91RM9200 OHCI USB Controller\n");
60 * Put the USB host controller into reset.
62 writel(0, &regs->control);
65 * Stop the USB clocks.
67 clk_disable(fclk);
68 clk_disable(iclk);
72 /*-------------------------------------------------------------------------*/
74 static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
76 /* configure so an HC device and id are always provided */
77 /* always called with process context; sleeping is OK */
80 /**
81 * usb_hcd_at91_probe - initialize AT91RM9200-based HCDs
82 * Context: !in_interrupt()
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.
88 int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *pdev)
90 int retval;
91 struct usb_hcd *hcd = NULL;
93 if (pdev->num_resources != 2) {
94 pr_debug("hcd probe: invalid num_resources");
95 return -ENODEV;
98 if ((pdev->resource[0].flags != IORESOURCE_MEM) || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
99 pr_debug("hcd probe: invalid resource type\n");
100 return -ENODEV;
103 hcd = usb_create_hcd(driver, &pdev->dev, "at91rm9200");
104 if (!hcd)
105 return -ENOMEM;
106 hcd->rsrc_start = pdev->resource[0].start;
107 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
109 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
110 pr_debug("request_mem_region failed\n");
111 retval = -EBUSY;
112 goto err1;
115 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
116 if (!hcd->regs) {
117 pr_debug("ioremap failed\n");
118 retval = -EIO;
119 goto err2;
122 iclk = clk_get(&pdev->dev, "ohci_clk");
123 fclk = clk_get(&pdev->dev, "uhpck");
125 at91_start_hc(pdev);
126 ohci_hcd_init(hcd_to_ohci(hcd));
128 retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
129 if (retval == 0)
130 return retval;
132 /* Error handling */
133 at91_stop_hc(pdev);
135 clk_put(fclk);
136 clk_put(iclk);
138 iounmap(hcd->regs);
140 err2:
141 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
143 err1:
144 usb_put_hcd(hcd);
145 return retval;
149 /* may be called with controller, bus, and devices active */
152 * usb_hcd_at91_remove - shutdown processing for AT91RM9200-based HCDs
153 * @dev: USB Host Controller being removed
154 * Context: !in_interrupt()
156 * Reverses the effect of usb_hcd_at91_probe(), first invoking
157 * the HCD's stop() method. It is always called from a thread
158 * context, normally "rmmod", "apmd", or something similar.
161 static int usb_hcd_at91_remove (struct usb_hcd *hcd, struct platform_device *pdev)
163 usb_remove_hcd(hcd);
164 at91_stop_hc(pdev);
165 iounmap(hcd->regs);
166 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
168 clk_put(fclk);
169 clk_put(iclk);
170 fclk = iclk = NULL;
172 dev_set_drvdata(&pdev->dev, NULL);
173 return 0;
176 /*-------------------------------------------------------------------------*/
178 static int __devinit
179 ohci_at91_start (struct usb_hcd *hcd)
181 // struct at91_ohci_data *board = hcd->self.controller->platform_data;
182 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
183 int ret;
185 if ((ret = ohci_init(ohci)) < 0)
186 return ret;
188 if ((ret = ohci_run(ohci)) < 0) {
189 err("can't start %s", hcd->self.bus_name);
190 ohci_stop(hcd);
191 return ret;
193 // hcd->self.root_hub->maxchild = board->ports;
194 return 0;
197 /*-------------------------------------------------------------------------*/
199 static const struct hc_driver ohci_at91_hc_driver = {
200 .description = hcd_name,
201 .product_desc = "AT91RM9200 OHCI",
202 .hcd_priv_size = sizeof(struct ohci_hcd),
205 * generic hardware linkage
207 .irq = ohci_irq,
208 .flags = HCD_USB11 | HCD_MEMORY,
211 * basic lifecycle operations
213 .start = ohci_at91_start,
214 .stop = ohci_stop,
217 * managing i/o requests and associated device resources
219 .urb_enqueue = ohci_urb_enqueue,
220 .urb_dequeue = ohci_urb_dequeue,
221 .endpoint_disable = ohci_endpoint_disable,
224 * scheduling support
226 .get_frame_number = ohci_get_frame,
229 * root hub support
231 .hub_status_data = ohci_hub_status_data,
232 .hub_control = ohci_hub_control,
234 #ifdef CONFIG_PM
235 .bus_suspend = ohci_bus_suspend,
236 .bus_resume = ohci_bus_resume,
237 #endif
238 .start_port_reset = ohci_start_port_reset,
241 /*-------------------------------------------------------------------------*/
243 static int ohci_hcd_at91_drv_probe(struct platform_device *dev)
245 return usb_hcd_at91_probe(&ohci_at91_hc_driver, dev);
248 static int ohci_hcd_at91_drv_remove(struct platform_device *dev)
250 return usb_hcd_at91_remove(platform_get_drvdata(dev), dev);
253 #ifdef CONFIG_PM
255 /* REVISIT suspend/resume look "too" simple here */
257 static int
258 ohci_hcd_at91_drv_suspend(struct platform_device *dev, pm_message_t mesg)
260 clk_disable(fclk);
261 clk_disable(iclk);
263 return 0;
266 static int ohci_hcd_at91_drv_resume(struct platform_device *dev)
268 clk_enable(iclk);
269 clk_enable(fclk);
271 return 0;
273 #else
274 #define ohci_hcd_at91_drv_suspend NULL
275 #define ohci_hcd_at91_drv_resume NULL
276 #endif
278 MODULE_ALIAS("at91rm9200-ohci");
280 static struct platform_driver ohci_hcd_at91_driver = {
281 .probe = ohci_hcd_at91_drv_probe,
282 .remove = ohci_hcd_at91_drv_remove,
283 .suspend = ohci_hcd_at91_drv_suspend,
284 .resume = ohci_hcd_at91_drv_resume,
285 .driver = {
286 .name = "at91rm9200-ohci",
287 .owner = THIS_MODULE,
291 static int __init ohci_hcd_at91_init (void)
293 if (usb_disabled())
294 return -ENODEV;
296 return platform_driver_register(&ohci_hcd_at91_driver);
299 static void __exit ohci_hcd_at91_cleanup (void)
301 platform_driver_unregister(&ohci_hcd_at91_driver);
304 module_init (ohci_hcd_at91_init);
305 module_exit (ohci_hcd_at91_cleanup);