blob: 08b27d6bbd4331b459f001408db933fa0047655f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
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
7 *
8 * Bus Glue for pxa27x
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
12 *
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
15 *
16 * Modified for pxa27x from ohci-lh7a404.c
17 * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
18 *
19 * This file is licenced under the GPL.
20 */
21
22#include <linux/device.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080023#include <linux/signal.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010024#include <linux/platform_device.h>
eric miaoa8bcf412007-12-12 08:53:25 +080025#include <linux/clk.h>
Linus Torvalds4fd5f822005-10-31 07:32:56 -080026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/mach-types.h>
28#include <asm/hardware.h>
29#include <asm/arch/pxa-regs.h>
Philipp Zabeld438ae52008-06-06 18:40:47 +010030#include <asm/arch/pxa2xx-regs.h> /* FIXME: for PSSR */
Richard Purdie81f280e2005-11-12 14:22:11 +000031#include <asm/arch/ohci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#define PXA_UHC_MAX_PORTNUM 3
34
35#define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 )
36
eric miaoa8bcf412007-12-12 08:53:25 +080037static struct clk *usb_clk;
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/*
40 PMM_NPS_MODE -- PMM Non-power switching mode
41 Ports are powered continuously.
42
43 PMM_GLOBAL_MODE -- PMM global switching mode
44 All ports are powered at the same time.
45
46 PMM_PERPORT_MODE -- PMM per port switching mode
47 Ports are powered individually.
48 */
49static int pxa27x_ohci_select_pmm( int mode )
50{
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 switch ( mode ) {
52 case PMM_NPS_MODE:
53 UHCRHDA |= RH_A_NPS;
David Brownelldd9048a2006-12-05 03:18:31 -080054 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 case PMM_GLOBAL_MODE:
56 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
57 break;
58 case PMM_PERPORT_MODE:
59 UHCRHDA &= ~(RH_A_NPS);
60 UHCRHDA |= RH_A_PSM;
61
62 /* Set port power control mask bits, only 3 ports. */
63 UHCRHDB |= (0x7<<17);
64 break;
65 default:
66 printk( KERN_ERR
David Brownelldd9048a2006-12-05 03:18:31 -080067 "Invalid mode %d, set to non-power switch mode.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 mode );
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 UHCRHDA |= RH_A_NPS;
71 }
72
73 return 0;
74}
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int usb_disabled(void);
77
78/*-------------------------------------------------------------------------*/
79
Richard Purdie81f280e2005-11-12 14:22:11 +000080static int pxa27x_start_hc(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Richard Purdie81f280e2005-11-12 14:22:11 +000082 int retval = 0;
83 struct pxaohci_platform_data *inf;
84
85 inf = dev->platform_data;
86
eric miaoa8bcf412007-12-12 08:53:25 +080087 clk_enable(usb_clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 UHCHR |= UHCHR_FHR;
90 udelay(11);
91 UHCHR &= ~UHCHR_FHR;
92
93 UHCHR |= UHCHR_FSBIR;
94 while (UHCHR & UHCHR_FSBIR)
95 cpu_relax();
96
Richard Purdie81f280e2005-11-12 14:22:11 +000097 if (inf->init)
98 retval = inf->init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Richard Purdie81f280e2005-11-12 14:22:11 +0000100 if (retval < 0)
101 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 UHCHR &= ~UHCHR_SSE;
104
105 UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
David Brownell155faf52005-08-31 11:54:09 -0700106
107 /* Clear any OTG Pin Hold */
Philipp Zabeld438ae52008-06-06 18:40:47 +0100108 if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
David Brownell155faf52005-08-31 11:54:09 -0700109 PSSR |= PSSR_OTGPH;
Richard Purdie81f280e2005-11-12 14:22:11 +0000110
111 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
Richard Purdie81f280e2005-11-12 14:22:11 +0000114static void pxa27x_stop_hc(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Richard Purdie81f280e2005-11-12 14:22:11 +0000116 struct pxaohci_platform_data *inf;
117
118 inf = dev->platform_data;
119
120 if (inf->exit)
121 inf->exit(dev);
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 UHCHR |= UHCHR_FHR;
124 udelay(11);
125 UHCHR &= ~UHCHR_FHR;
126
127 UHCCOMS |= 1;
128 udelay(10);
129
eric miaoa8bcf412007-12-12 08:53:25 +0800130 clk_disable(usb_clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133
134/*-------------------------------------------------------------------------*/
135
136/* configure so an HC device and id are always provided */
137/* always called with process context; sleeping is OK */
138
139
140/**
141 * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
142 * Context: !in_interrupt()
143 *
144 * Allocates basic resources for this USB host controller, and
145 * then invokes the start() method for the HCD associated with it
146 * through the hotplug entry's driver_data.
147 *
148 */
Richard Purdie81f280e2005-11-12 14:22:11 +0000149int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
151 int retval;
152 struct usb_hcd *hcd;
Richard Purdie81f280e2005-11-12 14:22:11 +0000153 struct pxaohci_platform_data *inf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Richard Purdie81f280e2005-11-12 14:22:11 +0000155 inf = pdev->dev.platform_data;
156
157 if (!inf)
158 return -ENODEV;
159
160 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 pr_debug ("resource[1] is not IORESOURCE_IRQ");
162 return -ENOMEM;
163 }
164
eric miaoa8bcf412007-12-12 08:53:25 +0800165 usb_clk = clk_get(&pdev->dev, "USBCLK");
166 if (IS_ERR(usb_clk))
167 return PTR_ERR(usb_clk);
168
Richard Purdie81f280e2005-11-12 14:22:11 +0000169 hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 if (!hcd)
171 return -ENOMEM;
Richard Purdie81f280e2005-11-12 14:22:11 +0000172 hcd->rsrc_start = pdev->resource[0].start;
173 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
176 pr_debug("request_mem_region failed");
177 retval = -EBUSY;
178 goto err1;
179 }
180
181 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
182 if (!hcd->regs) {
183 pr_debug("ioremap failed");
184 retval = -ENOMEM;
185 goto err2;
186 }
187
Richard Purdie81f280e2005-11-12 14:22:11 +0000188 if ((retval = pxa27x_start_hc(&pdev->dev)) < 0) {
189 pr_debug("pxa27x_start_hc failed");
190 goto err3;
191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 /* Select Power Management Mode */
Richard Purdie81f280e2005-11-12 14:22:11 +0000194 pxa27x_ohci_select_pmm(inf->port_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Richard Purdie0c27c5d2006-06-08 22:44:07 +0100196 if (inf->power_budget)
197 hcd->power_budget = inf->power_budget;
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 ohci_hcd_init(hcd_to_ohci(hcd));
200
Thomas Gleixnerd54b5ca2006-07-01 19:29:44 -0700201 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (retval == 0)
203 return retval;
204
Richard Purdie81f280e2005-11-12 14:22:11 +0000205 pxa27x_stop_hc(&pdev->dev);
206 err3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 iounmap(hcd->regs);
208 err2:
209 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
210 err1:
211 usb_put_hcd(hcd);
eric miaoa8bcf412007-12-12 08:53:25 +0800212 clk_put(usb_clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 return retval;
214}
215
216
217/* may be called without controller electrically present */
218/* may be called with controller, bus, and devices active */
219
220/**
221 * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
222 * @dev: USB Host Controller being removed
223 * Context: !in_interrupt()
224 *
225 * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
226 * the HCD's stop() method. It is always called from a thread
227 * context, normally "rmmod", "apmd", or something similar.
228 *
229 */
Richard Purdie81f280e2005-11-12 14:22:11 +0000230void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 usb_remove_hcd(hcd);
Richard Purdie81f280e2005-11-12 14:22:11 +0000233 pxa27x_stop_hc(&pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 iounmap(hcd->regs);
235 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
236 usb_put_hcd(hcd);
eric miaoa8bcf412007-12-12 08:53:25 +0800237 clk_put(usb_clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
240/*-------------------------------------------------------------------------*/
241
242static int __devinit
243ohci_pxa27x_start (struct usb_hcd *hcd)
244{
245 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
246 int ret;
247
248 ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
249
David Brownellfdd13b32005-08-31 11:52:57 -0700250 /* The value of NDP in roothub_a is incorrect on this hardware */
251 ohci->num_ports = 3;
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if ((ret = ohci_init(ohci)) < 0)
254 return ret;
255
256 if ((ret = ohci_run (ohci)) < 0) {
257 err ("can't start %s", hcd->self.bus_name);
258 ohci_stop (hcd);
259 return ret;
260 }
261
262 return 0;
263}
264
265/*-------------------------------------------------------------------------*/
266
267static const struct hc_driver ohci_pxa27x_hc_driver = {
268 .description = hcd_name,
269 .product_desc = "PXA27x OHCI",
270 .hcd_priv_size = sizeof(struct ohci_hcd),
271
272 /*
273 * generic hardware linkage
274 */
275 .irq = ohci_irq,
276 .flags = HCD_USB11 | HCD_MEMORY,
277
278 /*
279 * basic lifecycle operations
280 */
281 .start = ohci_pxa27x_start,
282 .stop = ohci_stop,
David Brownelldd9048a2006-12-05 03:18:31 -0800283 .shutdown = ohci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 /*
286 * managing i/o requests and associated device resources
287 */
288 .urb_enqueue = ohci_urb_enqueue,
289 .urb_dequeue = ohci_urb_dequeue,
290 .endpoint_disable = ohci_endpoint_disable,
291
292 /*
293 * scheduling support
294 */
295 .get_frame_number = ohci_get_frame,
296
297 /*
298 * root hub support
299 */
300 .hub_status_data = ohci_hub_status_data,
301 .hub_control = ohci_hub_control,
David Brownell8ad7fe12005-09-13 19:59:11 -0700302#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400303 .bus_suspend = ohci_bus_suspend,
304 .bus_resume = ohci_bus_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305#endif
David Brownell92936772005-09-22 22:32:11 -0700306 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307};
308
309/*-------------------------------------------------------------------------*/
310
Russell King3ae5eae2005-11-09 22:32:44 +0000311static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 pr_debug ("In ohci_hcd_pxa27x_drv_probe");
314
315 if (usb_disabled())
316 return -ENODEV;
317
Richard Purdie81f280e2005-11-12 14:22:11 +0000318 return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
Russell King3ae5eae2005-11-09 22:32:44 +0000321static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Russell King3ae5eae2005-11-09 22:32:44 +0000323 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 usb_hcd_pxa27x_remove(hcd, pdev);
Richard Purdiea5e36d22005-11-28 22:15:46 +0000326 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 return 0;
328}
329
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000330#ifdef CONFIG_PM
331static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Richard Purdiea5e36d22005-11-28 22:15:46 +0000333 struct usb_hcd *hcd = platform_get_drvdata(pdev);
334 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000335
336 if (time_before(jiffies, ohci->next_statechange))
337 msleep(5);
338 ohci->next_statechange = jiffies;
339
340 pxa27x_stop_hc(&pdev->dev);
Richard Purdiea5e36d22005-11-28 22:15:46 +0000341 hcd->state = HC_STATE_SUSPENDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 return 0;
344}
345
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000346static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Richard Purdiea5e36d22005-11-28 22:15:46 +0000348 struct usb_hcd *hcd = platform_get_drvdata(pdev);
349 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000350 int status;
351
352 if (time_before(jiffies, ohci->next_statechange))
353 msleep(5);
354 ohci->next_statechange = jiffies;
355
356 if ((status = pxa27x_start_hc(&pdev->dev)) < 0)
357 return status;
358
Alan Stern43bbb7e2008-04-03 18:03:17 -0400359 ohci_finish_controller_resume(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return 0;
361}
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000362#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Kay Sieversf4fce612008-04-10 21:29:22 -0700364/* work with hotplug and coldplug */
365MODULE_ALIAS("platform:pxa27x-ohci");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Russell King3ae5eae2005-11-09 22:32:44 +0000367static struct platform_driver ohci_hcd_pxa27x_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 .probe = ohci_hcd_pxa27x_drv_probe,
369 .remove = ohci_hcd_pxa27x_drv_remove,
David Brownelldd9048a2006-12-05 03:18:31 -0800370 .shutdown = usb_hcd_platform_shutdown,
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000371#ifdef CONFIG_PM
David Brownelldd9048a2006-12-05 03:18:31 -0800372 .suspend = ohci_hcd_pxa27x_drv_suspend,
Russell King3ae5eae2005-11-09 22:32:44 +0000373 .resume = ohci_hcd_pxa27x_drv_resume,
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000374#endif
Russell King3ae5eae2005-11-09 22:32:44 +0000375 .driver = {
376 .name = "pxa27x-ohci",
Kay Sieversf4fce612008-04-10 21:29:22 -0700377 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +0000378 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379};
380