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>
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_AT91
23 #error "CONFIG_ARCH_AT91 must be defined."
26 /* interface and function clocks */
27 static struct clk *iclk, *fclk;
30 extern int usb_disabled(void);
32 /*-------------------------------------------------------------------------*/
34 static void at91_start_hc(struct platform_device *pdev)
36 struct usb_hcd *hcd = platform_get_drvdata(pdev);
37 struct ohci_regs __iomem *regs = hcd->regs;
39 dev_dbg(&pdev->dev, "start\n");
42 * Start the USB clocks.
49 * The USB host controller must remain in reset.
51 writel(0, ®s->control);
54 static void at91_stop_hc(struct platform_device *pdev)
56 struct usb_hcd *hcd = platform_get_drvdata(pdev);
57 struct ohci_regs __iomem *regs = hcd->regs;
59 dev_dbg(&pdev->dev, "stop\n");
62 * Put the USB host controller into reset.
64 writel(0, ®s->control);
67 * Stop the USB clocks.
75 /*-------------------------------------------------------------------------*/
77 static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
79 /* configure so an HC device and id are always provided */
80 /* always called with process context; sleeping is OK */
84 * usb_hcd_at91_probe - initialize AT91-based HCDs
85 * Context: !in_interrupt()
87 * Allocates basic resources for this USB host controller, and
88 * then invokes the start() method for the HCD associated with it
89 * through the hotplug entry's driver_data.
91 static int usb_hcd_at91_probe(const struct hc_driver *driver,
92 struct platform_device *pdev)
95 struct usb_hcd *hcd = NULL;
97 if (pdev->num_resources != 2) {
98 pr_debug("hcd probe: invalid num_resources");
102 if ((pdev->resource[0].flags != IORESOURCE_MEM)
103 || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
104 pr_debug("hcd probe: invalid resource type\n");
108 hcd = usb_create_hcd(driver, &pdev->dev, "at91");
111 hcd->rsrc_start = pdev->resource[0].start;
112 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
114 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
115 pr_debug("request_mem_region failed\n");
120 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
122 pr_debug("ioremap failed\n");
127 iclk = clk_get(&pdev->dev, "ohci_clk");
128 fclk = clk_get(&pdev->dev, "uhpck");
131 ohci_hcd_init(hcd_to_ohci(hcd));
133 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
146 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
154 /* may be called with controller, bus, and devices active */
157 * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
158 * @dev: USB Host Controller being removed
159 * Context: !in_interrupt()
161 * Reverses the effect of usb_hcd_at91_probe(), first invoking
162 * the HCD's stop() method. It is always called from a thread
163 * context, "rmmod" or something similar.
166 static int usb_hcd_at91_remove(struct usb_hcd *hcd,
167 struct platform_device *pdev)
172 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
178 dev_set_drvdata(&pdev->dev, NULL);
182 /*-------------------------------------------------------------------------*/
185 ohci_at91_start (struct usb_hcd *hcd)
187 struct at91_usbh_data *board = hcd->self.controller->platform_data;
188 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
191 if ((ret = ohci_init(ohci)) < 0)
194 ohci->num_ports = board->ports;
196 if ((ret = ohci_run(ohci)) < 0) {
197 err("can't start %s", hcd->self.bus_name);
204 /*-------------------------------------------------------------------------*/
206 static const struct hc_driver ohci_at91_hc_driver = {
207 .description = hcd_name,
208 .product_desc = "AT91 OHCI",
209 .hcd_priv_size = sizeof(struct ohci_hcd),
212 * generic hardware linkage
215 .flags = HCD_USB11 | HCD_MEMORY,
218 * basic lifecycle operations
220 .start = ohci_at91_start,
222 .shutdown = ohci_shutdown,
225 * managing i/o requests and associated device resources
227 .urb_enqueue = ohci_urb_enqueue,
228 .urb_dequeue = ohci_urb_dequeue,
229 .endpoint_disable = ohci_endpoint_disable,
234 .get_frame_number = ohci_get_frame,
239 .hub_status_data = ohci_hub_status_data,
240 .hub_control = ohci_hub_control,
241 .hub_irq_enable = ohci_rhsc_enable,
243 .bus_suspend = ohci_bus_suspend,
244 .bus_resume = ohci_bus_resume,
246 .start_port_reset = ohci_start_port_reset,
249 /*-------------------------------------------------------------------------*/
251 static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
253 device_init_wakeup(&pdev->dev, 1);
254 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
257 static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
259 device_init_wakeup(&pdev->dev, 0);
260 return usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
266 ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
268 struct usb_hcd *hcd = platform_get_drvdata(pdev);
269 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
271 if (device_may_wakeup(&pdev->dev))
272 enable_irq_wake(hcd->irq);
275 * The integrated transceivers seem unable to notice disconnect,
276 * reconnect, or wakeup without the 48 MHz clock active. so for
277 * correctness, always discard connection state (using reset).
279 * REVISIT: some boards will be able to turn VBUS off...
281 if (at91_suspend_entering_slow_clock()) {
282 ohci_usb_reset (ohci);
291 static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
293 struct usb_hcd *hcd = platform_get_drvdata(pdev);
295 if (device_may_wakeup(&pdev->dev))
296 disable_irq_wake(hcd->irq);
307 #define ohci_hcd_at91_drv_suspend NULL
308 #define ohci_hcd_at91_drv_resume NULL
311 MODULE_ALIAS("at91_ohci");
313 static struct platform_driver ohci_hcd_at91_driver = {
314 .probe = ohci_hcd_at91_drv_probe,
315 .remove = ohci_hcd_at91_drv_remove,
316 .shutdown = usb_hcd_platform_shutdown,
317 .suspend = ohci_hcd_at91_drv_suspend,
318 .resume = ohci_hcd_at91_drv_resume,
321 .owner = THIS_MODULE,