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 <mach/hardware.h>
21 #include <mach/board.h>
24 #ifndef CONFIG_ARCH_AT91
25 #error "CONFIG_ARCH_AT91 must be defined."
28 /* interface and function clocks; sometimes also an AHB clock */
29 static struct clk *iclk, *fclk, *hclk;
32 extern int usb_disabled(void);
34 /*-------------------------------------------------------------------------*/
36 static void at91_start_clock(void)
44 static void at91_stop_clock(void)
52 static void at91_start_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, "start\n");
60 * Start the USB clocks.
65 * The USB host controller must remain in reset.
67 writel(0, ®s->control);
70 static void at91_stop_hc(struct platform_device *pdev)
72 struct usb_hcd *hcd = platform_get_drvdata(pdev);
73 struct ohci_regs __iomem *regs = hcd->regs;
75 dev_dbg(&pdev->dev, "stop\n");
78 * Put the USB host controller into reset.
80 writel(0, ®s->control);
83 * Stop the USB clocks.
89 /*-------------------------------------------------------------------------*/
91 static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
93 /* configure so an HC device and id are always provided */
94 /* always called with process context; sleeping is OK */
98 * usb_hcd_at91_probe - initialize AT91-based HCDs
99 * Context: !in_interrupt()
101 * Allocates basic resources for this USB host controller, and
102 * then invokes the start() method for the HCD associated with it
103 * through the hotplug entry's driver_data.
105 static int usb_hcd_at91_probe(const struct hc_driver *driver,
106 struct platform_device *pdev)
109 struct usb_hcd *hcd = NULL;
111 if (pdev->num_resources != 2) {
112 pr_debug("hcd probe: invalid num_resources");
116 if ((pdev->resource[0].flags != IORESOURCE_MEM)
117 || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
118 pr_debug("hcd probe: invalid resource type\n");
122 hcd = usb_create_hcd(driver, &pdev->dev, "at91");
125 hcd->rsrc_start = pdev->resource[0].start;
126 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
128 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
129 pr_debug("request_mem_region failed\n");
134 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
136 pr_debug("ioremap failed\n");
141 iclk = clk_get(&pdev->dev, "ohci_clk");
142 fclk = clk_get(&pdev->dev, "uhpck");
143 hclk = clk_get(&pdev->dev, "hclk");
146 ohci_hcd_init(hcd_to_ohci(hcd));
148 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
162 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
170 /* may be called with controller, bus, and devices active */
173 * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
174 * @dev: USB Host Controller being removed
175 * Context: !in_interrupt()
177 * Reverses the effect of usb_hcd_at91_probe(), first invoking
178 * the HCD's stop() method. It is always called from a thread
179 * context, "rmmod" or something similar.
182 static void usb_hcd_at91_remove(struct usb_hcd *hcd,
183 struct platform_device *pdev)
188 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
194 fclk = iclk = hclk = NULL;
196 dev_set_drvdata(&pdev->dev, NULL);
199 /*-------------------------------------------------------------------------*/
202 ohci_at91_start (struct usb_hcd *hcd)
204 struct at91_usbh_data *board = hcd->self.controller->platform_data;
205 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
208 if ((ret = ohci_init(ohci)) < 0)
211 ohci->num_ports = board->ports;
213 if ((ret = ohci_run(ohci)) < 0) {
214 err("can't start %s", hcd->self.bus_name);
221 /*-------------------------------------------------------------------------*/
223 static const struct hc_driver ohci_at91_hc_driver = {
224 .description = hcd_name,
225 .product_desc = "AT91 OHCI",
226 .hcd_priv_size = sizeof(struct ohci_hcd),
229 * generic hardware linkage
232 .flags = HCD_USB11 | HCD_MEMORY,
235 * basic lifecycle operations
237 .start = ohci_at91_start,
239 .shutdown = ohci_shutdown,
242 * managing i/o requests and associated device resources
244 .urb_enqueue = ohci_urb_enqueue,
245 .urb_dequeue = ohci_urb_dequeue,
246 .endpoint_disable = ohci_endpoint_disable,
251 .get_frame_number = ohci_get_frame,
256 .hub_status_data = ohci_hub_status_data,
257 .hub_control = ohci_hub_control,
259 .bus_suspend = ohci_bus_suspend,
260 .bus_resume = ohci_bus_resume,
262 .start_port_reset = ohci_start_port_reset,
265 /*-------------------------------------------------------------------------*/
267 static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
269 struct at91_usbh_data *pdata = pdev->dev.platform_data;
273 /* REVISIT make the driver support per-port power switching,
274 * and also overcurrent detection. Here we assume the ports
275 * are always powered while this driver is active, and use
276 * active-low power switches.
278 for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) {
279 if (pdata->vbus_pin[i] <= 0)
281 gpio_request(pdata->vbus_pin[i], "ohci_vbus");
282 gpio_direction_output(pdata->vbus_pin[i], 0);
286 device_init_wakeup(&pdev->dev, 1);
287 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
290 static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
292 struct at91_usbh_data *pdata = pdev->dev.platform_data;
296 for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) {
297 if (pdata->vbus_pin[i] <= 0)
299 gpio_direction_output(pdata->vbus_pin[i], 1);
300 gpio_free(pdata->vbus_pin[i]);
304 device_init_wakeup(&pdev->dev, 0);
305 usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
312 ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
314 struct usb_hcd *hcd = platform_get_drvdata(pdev);
315 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
317 if (device_may_wakeup(&pdev->dev))
318 enable_irq_wake(hcd->irq);
321 * The integrated transceivers seem unable to notice disconnect,
322 * reconnect, or wakeup without the 48 MHz clock active. so for
323 * correctness, always discard connection state (using reset).
325 * REVISIT: some boards will be able to turn VBUS off...
327 if (at91_suspend_entering_slow_clock()) {
328 ohci_usb_reset (ohci);
329 /* flush the writes */
330 (void) ohci_readl (ohci, &ohci->regs->control);
337 static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
339 struct usb_hcd *hcd = platform_get_drvdata(pdev);
341 if (device_may_wakeup(&pdev->dev))
342 disable_irq_wake(hcd->irq);
347 ohci_finish_controller_resume(hcd);
351 #define ohci_hcd_at91_drv_suspend NULL
352 #define ohci_hcd_at91_drv_resume NULL
355 MODULE_ALIAS("platform:at91_ohci");
357 static struct platform_driver ohci_hcd_at91_driver = {
358 .probe = ohci_hcd_at91_drv_probe,
359 .remove = ohci_hcd_at91_drv_remove,
360 .shutdown = usb_hcd_platform_shutdown,
361 .suspend = ohci_hcd_at91_drv_suspend,
362 .resume = ohci_hcd_at91_drv_resume,
365 .owner = THIS_MODULE,