2 * OHCI HCD (Host Controller Driver) for USB.
4 * TI DA8xx (OMAP-L1x) Bus Glue
6 * Derived from: ohci-omap.c and ohci-s3c2410.c
7 * Copyright (C) 2008-2009 MontaVista Software, Inc. <source@mvista.com>
9 * This file is licensed under the terms of the GNU General Public License
10 * version 2. This program is licensed "as is" without any warranty of any
11 * kind, whether express or implied.
14 #include <linux/interrupt.h>
15 #include <linux/jiffies.h>
16 #include <linux/platform_device.h>
17 #include <linux/clk.h>
19 #include <mach/da8xx.h>
22 #ifndef CONFIG_ARCH_DAVINCI_DA8XX
23 #error "This file is DA8xx bus glue. Define CONFIG_ARCH_DAVINCI_DA8XX."
26 #define CFGCHIP2 DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG)
28 static struct clk *usb11_clk;
29 static struct clk *usb20_clk;
31 /* Over-current indicator change bitmask */
32 static volatile u16 ocic_mask;
34 static void ohci_da8xx_clock(int on)
38 cfgchip2 = __raw_readl(CFGCHIP2);
40 clk_enable(usb11_clk);
43 * If USB 1.1 reference clock is sourced from USB 2.0 PHY, we
44 * need to enable the USB 2.0 module clocking, start its PHY,
45 * and not allow it to stop the clock during USB 2.0 suspend.
47 if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX)) {
48 clk_enable(usb20_clk);
50 cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN);
51 cfgchip2 |= CFGCHIP2_PHY_PLLON;
52 __raw_writel(cfgchip2, CFGCHIP2);
54 pr_info("Waiting for USB PHY clock good...\n");
55 while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD))
59 /* Enable USB 1.1 PHY */
60 cfgchip2 |= CFGCHIP2_USB1SUSPENDM;
62 clk_disable(usb11_clk);
63 if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX))
64 clk_disable(usb20_clk);
66 /* Disable USB 1.1 PHY */
67 cfgchip2 &= ~CFGCHIP2_USB1SUSPENDM;
69 __raw_writel(cfgchip2, CFGCHIP2);
73 * Handle the port over-current indicator change.
75 static void ohci_da8xx_ocic_handler(struct da8xx_ohci_root_hub *hub,
78 ocic_mask |= 1 << port;
80 /* Once over-current is detected, the port needs to be powered down */
81 if (hub->get_oci(port) > 0)
82 hub->set_power(port, 0);
85 static int ohci_da8xx_init(struct usb_hcd *hcd)
87 struct device *dev = hcd->self.controller;
88 struct da8xx_ohci_root_hub *hub = dev->platform_data;
89 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
93 dev_dbg(dev, "starting USB controller\n");
98 * DA8xx only have 1 port connected to the pins but the HC root hub
99 * register A reports 2 ports, thus we'll have to override it...
103 result = ohci_init(ohci);
108 * Since we're providing a board-specific root hub port power control
109 * and over-current reporting, we have to override the HC root hub A
110 * register's default value, so that ohci_hub_control() could return
111 * the correct hub descriptor...
113 rh_a = ohci_readl(ohci, &ohci->regs->roothub.a);
114 if (hub->set_power) {
122 rh_a &= ~RH_A_POTPGT;
123 rh_a |= hub->potpgt << 24;
124 ohci_writel(ohci, rh_a, &ohci->regs->roothub.a);
129 static void ohci_da8xx_stop(struct usb_hcd *hcd)
135 static int ohci_da8xx_start(struct usb_hcd *hcd)
137 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
140 result = ohci_run(ohci);
142 ohci_da8xx_stop(hcd);
148 * Update the status data from the hub with the over-current indicator change.
150 static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf)
152 int length = ohci_hub_status_data(hcd, buf);
154 /* See if we have OCIC bit set on port 1 */
155 if (ocic_mask & (1 << 1)) {
156 dev_dbg(hcd->self.controller, "over-current indicator change "
168 * Look at the control requests to the root hub and see if we need to override.
170 static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
171 u16 wIndex, char *buf, u16 wLength)
173 struct device *dev = hcd->self.controller;
174 struct da8xx_ohci_root_hub *hub = dev->platform_data;
179 /* Check the port number */
183 dev_dbg(dev, "GetPortStatus(%u)\n", wIndex);
185 temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1);
187 /* The port power status (PPS) bit defaults to 1 */
188 if (hub->get_power && hub->get_power(wIndex) == 0)
191 /* The port over-current indicator (POCI) bit is always 0 */
192 if (hub->get_oci && hub->get_oci(wIndex) > 0)
195 /* The over-current indicator change (OCIC) bit is 0 too */
196 if (ocic_mask & (1 << wIndex))
199 put_unaligned(cpu_to_le32(temp), (__le32 *)buf);
204 case ClearPortFeature:
208 /* Check the port number */
213 case USB_PORT_FEAT_POWER:
214 dev_dbg(dev, "%sPortFeature(%u): %s\n",
215 temp ? "Set" : "Clear", wIndex, "POWER");
220 return hub->set_power(wIndex, temp) ? -EPIPE : 0;
221 case USB_PORT_FEAT_C_OVER_CURRENT:
222 dev_dbg(dev, "%sPortFeature(%u): %s\n",
223 temp ? "Set" : "Clear", wIndex,
227 ocic_mask |= 1 << wIndex;
229 ocic_mask &= ~(1 << wIndex);
234 return ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
237 static const struct hc_driver ohci_da8xx_hc_driver = {
238 .description = hcd_name,
239 .product_desc = "DA8xx OHCI",
240 .hcd_priv_size = sizeof(struct ohci_hcd),
243 * generic hardware linkage
246 .flags = HCD_USB11 | HCD_MEMORY,
249 * basic lifecycle operations
251 .reset = ohci_da8xx_init,
252 .start = ohci_da8xx_start,
253 .stop = ohci_da8xx_stop,
254 .shutdown = ohci_shutdown,
257 * managing i/o requests and associated device resources
259 .urb_enqueue = ohci_urb_enqueue,
260 .urb_dequeue = ohci_urb_dequeue,
261 .endpoint_disable = ohci_endpoint_disable,
266 .get_frame_number = ohci_get_frame,
271 .hub_status_data = ohci_da8xx_hub_status_data,
272 .hub_control = ohci_da8xx_hub_control,
275 .bus_suspend = ohci_bus_suspend,
276 .bus_resume = ohci_bus_resume,
278 .start_port_reset = ohci_start_port_reset,
281 /*-------------------------------------------------------------------------*/
285 * usb_hcd_da8xx_probe - initialize DA8xx-based HCDs
286 * Context: !in_interrupt()
288 * Allocates basic resources for this USB host controller, and
289 * then invokes the start() method for the HCD associated with it
290 * through the hotplug entry's driver_data.
292 static int usb_hcd_da8xx_probe(const struct hc_driver *driver,
293 struct platform_device *pdev)
295 struct da8xx_ohci_root_hub *hub = pdev->dev.platform_data;
297 struct resource *mem;
303 usb11_clk = clk_get(&pdev->dev, "usb11");
304 if (IS_ERR(usb11_clk))
305 return PTR_ERR(usb11_clk);
307 usb20_clk = clk_get(&pdev->dev, "usb20");
308 if (IS_ERR(usb20_clk)) {
309 error = PTR_ERR(usb20_clk);
313 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
319 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
324 hcd->rsrc_start = mem->start;
325 hcd->rsrc_len = mem->end - mem->start + 1;
327 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
328 dev_dbg(&pdev->dev, "request_mem_region failed\n");
333 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
335 dev_err(&pdev->dev, "ioremap failed\n");
340 ohci_hcd_init(hcd_to_ohci(hcd));
342 irq = platform_get_irq(pdev, 0);
347 error = usb_add_hcd(hcd, irq, IRQF_DISABLED);
351 if (hub->ocic_notify) {
352 error = hub->ocic_notify(ohci_da8xx_ocic_handler);
361 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
372 * usb_hcd_da8xx_remove - shutdown processing for DA8xx-based HCDs
373 * @dev: USB Host Controller being removed
374 * Context: !in_interrupt()
376 * Reverses the effect of usb_hcd_da8xx_probe(), first invoking
377 * the HCD's stop() method. It is always called from a thread
378 * context, normally "rmmod", "apmd", or something similar.
381 usb_hcd_da8xx_remove(struct usb_hcd *hcd, struct platform_device *pdev)
383 struct da8xx_ohci_root_hub *hub = pdev->dev.platform_data;
385 hub->ocic_notify(NULL);
388 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
394 static int ohci_hcd_da8xx_drv_probe(struct platform_device *dev)
396 return usb_hcd_da8xx_probe(&ohci_da8xx_hc_driver, dev);
399 static int ohci_hcd_da8xx_drv_remove(struct platform_device *dev)
401 struct usb_hcd *hcd = platform_get_drvdata(dev);
403 usb_hcd_da8xx_remove(hcd, dev);
404 platform_set_drvdata(dev, NULL);
410 static int ohci_da8xx_suspend(struct platform_device *dev, pm_message_t message)
412 struct usb_hcd *hcd = platform_get_drvdata(dev);
413 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
415 if (time_before(jiffies, ohci->next_statechange))
417 ohci->next_statechange = jiffies;
420 hcd->state = HC_STATE_SUSPENDED;
421 dev->dev.power.power_state = PMSG_SUSPEND;
425 static int ohci_da8xx_resume(struct platform_device *dev)
427 struct usb_hcd *hcd = platform_get_drvdata(dev);
428 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
430 if (time_before(jiffies, ohci->next_statechange))
432 ohci->next_statechange = jiffies;
435 dev->dev.power.power_state = PMSG_ON;
436 usb_hcd_resume_root_hub(hcd);
442 * Driver definition to register with platform structure.
444 static struct platform_driver ohci_hcd_da8xx_driver = {
445 .probe = ohci_hcd_da8xx_drv_probe,
446 .remove = ohci_hcd_da8xx_drv_remove,
447 .shutdown = usb_hcd_platform_shutdown,
449 .suspend = ohci_da8xx_suspend,
450 .resume = ohci_da8xx_resume,
453 .owner = THIS_MODULE,