2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
16 * Modified for pxa27x from ohci-lh7a404.c
17 * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
19 * This file is licenced under the GPL.
22 #include <linux/device.h>
23 #include <linux/signal.h>
24 #include <linux/platform_device.h>
25 #include <linux/clk.h>
27 #include <mach/hardware.h>
28 #include <mach/pxa-regs.h>
29 #include <mach/pxa2xx-regs.h> /* FIXME: for PSSR */
30 #include <mach/ohci.h>
32 #define PXA_UHC_MAX_PORTNUM 3
34 #define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 )
36 static struct clk *usb_clk;
39 PMM_NPS_MODE -- PMM Non-power switching mode
40 Ports are powered continuously.
42 PMM_GLOBAL_MODE -- PMM global switching mode
43 All ports are powered at the same time.
45 PMM_PERPORT_MODE -- PMM per port switching mode
46 Ports are powered individually.
48 static int pxa27x_ohci_select_pmm( int mode )
55 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
57 case PMM_PERPORT_MODE:
58 UHCRHDA &= ~(RH_A_NPS);
61 /* Set port power control mask bits, only 3 ports. */
66 "Invalid mode %d, set to non-power switch mode.\n",
75 extern int usb_disabled(void);
77 /*-------------------------------------------------------------------------*/
79 static int pxa27x_start_hc(struct device *dev)
82 struct pxaohci_platform_data *inf;
84 inf = dev->platform_data;
93 while (UHCHR & UHCHR_FSBIR)
97 retval = inf->init(dev);
104 UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
106 /* Clear any OTG Pin Hold */
107 if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
113 static void pxa27x_stop_hc(struct device *dev)
115 struct pxaohci_platform_data *inf;
117 inf = dev->platform_data;
129 clk_disable(usb_clk);
133 /*-------------------------------------------------------------------------*/
135 /* configure so an HC device and id are always provided */
136 /* always called with process context; sleeping is OK */
140 * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
141 * Context: !in_interrupt()
143 * Allocates basic resources for this USB host controller, and
144 * then invokes the start() method for the HCD associated with it
145 * through the hotplug entry's driver_data.
148 int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device *pdev)
152 struct pxaohci_platform_data *inf;
154 inf = pdev->dev.platform_data;
159 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
160 pr_debug ("resource[1] is not IORESOURCE_IRQ");
164 usb_clk = clk_get(&pdev->dev, "USBCLK");
166 return PTR_ERR(usb_clk);
168 hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
171 hcd->rsrc_start = pdev->resource[0].start;
172 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
174 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
175 pr_debug("request_mem_region failed");
180 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
182 pr_debug("ioremap failed");
187 if ((retval = pxa27x_start_hc(&pdev->dev)) < 0) {
188 pr_debug("pxa27x_start_hc failed");
192 /* Select Power Management Mode */
193 pxa27x_ohci_select_pmm(inf->port_mode);
195 if (inf->power_budget)
196 hcd->power_budget = inf->power_budget;
198 ohci_hcd_init(hcd_to_ohci(hcd));
200 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
204 pxa27x_stop_hc(&pdev->dev);
208 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
216 /* may be called without controller electrically present */
217 /* may be called with controller, bus, and devices active */
220 * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
221 * @dev: USB Host Controller being removed
222 * Context: !in_interrupt()
224 * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
225 * the HCD's stop() method. It is always called from a thread
226 * context, normally "rmmod", "apmd", or something similar.
229 void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
232 pxa27x_stop_hc(&pdev->dev);
234 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
239 /*-------------------------------------------------------------------------*/
242 ohci_pxa27x_start (struct usb_hcd *hcd)
244 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
247 ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
249 /* The value of NDP in roothub_a is incorrect on this hardware */
252 if ((ret = ohci_init(ohci)) < 0)
255 if ((ret = ohci_run (ohci)) < 0) {
256 err ("can't start %s", hcd->self.bus_name);
264 /*-------------------------------------------------------------------------*/
266 static const struct hc_driver ohci_pxa27x_hc_driver = {
267 .description = hcd_name,
268 .product_desc = "PXA27x OHCI",
269 .hcd_priv_size = sizeof(struct ohci_hcd),
272 * generic hardware linkage
275 .flags = HCD_USB11 | HCD_MEMORY,
278 * basic lifecycle operations
280 .start = ohci_pxa27x_start,
282 .shutdown = ohci_shutdown,
285 * managing i/o requests and associated device resources
287 .urb_enqueue = ohci_urb_enqueue,
288 .urb_dequeue = ohci_urb_dequeue,
289 .endpoint_disable = ohci_endpoint_disable,
294 .get_frame_number = ohci_get_frame,
299 .hub_status_data = ohci_hub_status_data,
300 .hub_control = ohci_hub_control,
302 .bus_suspend = ohci_bus_suspend,
303 .bus_resume = ohci_bus_resume,
305 .start_port_reset = ohci_start_port_reset,
308 /*-------------------------------------------------------------------------*/
310 static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
312 pr_debug ("In ohci_hcd_pxa27x_drv_probe");
317 return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
320 static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
322 struct usb_hcd *hcd = platform_get_drvdata(pdev);
324 usb_hcd_pxa27x_remove(hcd, pdev);
325 platform_set_drvdata(pdev, NULL);
330 static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state)
332 struct usb_hcd *hcd = platform_get_drvdata(pdev);
333 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
335 if (time_before(jiffies, ohci->next_statechange))
337 ohci->next_statechange = jiffies;
339 pxa27x_stop_hc(&pdev->dev);
340 hcd->state = HC_STATE_SUSPENDED;
345 static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
347 struct usb_hcd *hcd = platform_get_drvdata(pdev);
348 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
351 if (time_before(jiffies, ohci->next_statechange))
353 ohci->next_statechange = jiffies;
355 if ((status = pxa27x_start_hc(&pdev->dev)) < 0)
358 ohci_finish_controller_resume(hcd);
363 /* work with hotplug and coldplug */
364 MODULE_ALIAS("platform:pxa27x-ohci");
366 static struct platform_driver ohci_hcd_pxa27x_driver = {
367 .probe = ohci_hcd_pxa27x_drv_probe,
368 .remove = ohci_hcd_pxa27x_drv_remove,
369 .shutdown = usb_hcd_platform_shutdown,
371 .suspend = ohci_hcd_pxa27x_drv_suspend,
372 .resume = ohci_hcd_pxa27x_drv_resume,
375 .name = "pxa27x-ohci",
376 .owner = THIS_MODULE,