blob: 7f0f35c781858628a995dc85df361c6cae56b264 [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
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/hardware.h>
28#include <mach/pxa-regs.h>
29#include <mach/pxa2xx-regs.h> /* FIXME: for PSSR */
30#include <mach/ohci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#define PXA_UHC_MAX_PORTNUM 3
33
34#define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 )
35
eric miaoa8bcf412007-12-12 08:53:25 +080036static struct clk *usb_clk;
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 PMM_NPS_MODE -- PMM Non-power switching mode
40 Ports are powered continuously.
41
42 PMM_GLOBAL_MODE -- PMM global switching mode
43 All ports are powered at the same time.
44
45 PMM_PERPORT_MODE -- PMM per port switching mode
46 Ports are powered individually.
47 */
48static int pxa27x_ohci_select_pmm( int mode )
49{
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 switch ( mode ) {
51 case PMM_NPS_MODE:
52 UHCRHDA |= RH_A_NPS;
David Brownelldd9048a2006-12-05 03:18:31 -080053 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 case PMM_GLOBAL_MODE:
55 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
56 break;
57 case PMM_PERPORT_MODE:
58 UHCRHDA &= ~(RH_A_NPS);
59 UHCRHDA |= RH_A_PSM;
60
61 /* Set port power control mask bits, only 3 ports. */
62 UHCRHDB |= (0x7<<17);
63 break;
64 default:
65 printk( KERN_ERR
David Brownelldd9048a2006-12-05 03:18:31 -080066 "Invalid mode %d, set to non-power switch mode.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 mode );
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 UHCRHDA |= RH_A_NPS;
70 }
71
72 return 0;
73}
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int usb_disabled(void);
76
77/*-------------------------------------------------------------------------*/
78
Richard Purdie81f280e2005-11-12 14:22:11 +000079static int pxa27x_start_hc(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Richard Purdie81f280e2005-11-12 14:22:11 +000081 int retval = 0;
82 struct pxaohci_platform_data *inf;
83
84 inf = dev->platform_data;
85
eric miaoa8bcf412007-12-12 08:53:25 +080086 clk_enable(usb_clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 UHCHR |= UHCHR_FHR;
89 udelay(11);
90 UHCHR &= ~UHCHR_FHR;
91
92 UHCHR |= UHCHR_FSBIR;
93 while (UHCHR & UHCHR_FSBIR)
94 cpu_relax();
95
Richard Purdie81f280e2005-11-12 14:22:11 +000096 if (inf->init)
97 retval = inf->init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Richard Purdie81f280e2005-11-12 14:22:11 +000099 if (retval < 0)
100 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 UHCHR &= ~UHCHR_SSE;
103
104 UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
David Brownell155faf52005-08-31 11:54:09 -0700105
106 /* Clear any OTG Pin Hold */
Philipp Zabeld438ae52008-06-06 18:40:47 +0100107 if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
David Brownell155faf52005-08-31 11:54:09 -0700108 PSSR |= PSSR_OTGPH;
Richard Purdie81f280e2005-11-12 14:22:11 +0000109
110 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Richard Purdie81f280e2005-11-12 14:22:11 +0000113static void pxa27x_stop_hc(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Richard Purdie81f280e2005-11-12 14:22:11 +0000115 struct pxaohci_platform_data *inf;
116
117 inf = dev->platform_data;
118
119 if (inf->exit)
120 inf->exit(dev);
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 UHCHR |= UHCHR_FHR;
123 udelay(11);
124 UHCHR &= ~UHCHR_FHR;
125
126 UHCCOMS |= 1;
127 udelay(10);
128
eric miaoa8bcf412007-12-12 08:53:25 +0800129 clk_disable(usb_clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
132
133/*-------------------------------------------------------------------------*/
134
135/* configure so an HC device and id are always provided */
136/* always called with process context; sleeping is OK */
137
138
139/**
140 * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
141 * Context: !in_interrupt()
142 *
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.
146 *
147 */
Richard Purdie81f280e2005-11-12 14:22:11 +0000148int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 int retval;
151 struct usb_hcd *hcd;
Richard Purdie81f280e2005-11-12 14:22:11 +0000152 struct pxaohci_platform_data *inf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Richard Purdie81f280e2005-11-12 14:22:11 +0000154 inf = pdev->dev.platform_data;
155
156 if (!inf)
157 return -ENODEV;
158
159 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 pr_debug ("resource[1] is not IORESOURCE_IRQ");
161 return -ENOMEM;
162 }
163
eric miaoa8bcf412007-12-12 08:53:25 +0800164 usb_clk = clk_get(&pdev->dev, "USBCLK");
165 if (IS_ERR(usb_clk))
166 return PTR_ERR(usb_clk);
167
Richard Purdie81f280e2005-11-12 14:22:11 +0000168 hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 if (!hcd)
170 return -ENOMEM;
Richard Purdie81f280e2005-11-12 14:22:11 +0000171 hcd->rsrc_start = pdev->resource[0].start;
172 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
175 pr_debug("request_mem_region failed");
176 retval = -EBUSY;
177 goto err1;
178 }
179
180 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
181 if (!hcd->regs) {
182 pr_debug("ioremap failed");
183 retval = -ENOMEM;
184 goto err2;
185 }
186
Richard Purdie81f280e2005-11-12 14:22:11 +0000187 if ((retval = pxa27x_start_hc(&pdev->dev)) < 0) {
188 pr_debug("pxa27x_start_hc failed");
189 goto err3;
190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 /* Select Power Management Mode */
Richard Purdie81f280e2005-11-12 14:22:11 +0000193 pxa27x_ohci_select_pmm(inf->port_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Richard Purdie0c27c5d2006-06-08 22:44:07 +0100195 if (inf->power_budget)
196 hcd->power_budget = inf->power_budget;
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 ohci_hcd_init(hcd_to_ohci(hcd));
199
Thomas Gleixnerd54b5ca2006-07-01 19:29:44 -0700200 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 if (retval == 0)
202 return retval;
203
Richard Purdie81f280e2005-11-12 14:22:11 +0000204 pxa27x_stop_hc(&pdev->dev);
205 err3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 iounmap(hcd->regs);
207 err2:
208 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
209 err1:
210 usb_put_hcd(hcd);
eric miaoa8bcf412007-12-12 08:53:25 +0800211 clk_put(usb_clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 return retval;
213}
214
215
216/* may be called without controller electrically present */
217/* may be called with controller, bus, and devices active */
218
219/**
220 * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
221 * @dev: USB Host Controller being removed
222 * Context: !in_interrupt()
223 *
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.
227 *
228 */
Richard Purdie81f280e2005-11-12 14:22:11 +0000229void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
231 usb_remove_hcd(hcd);
Richard Purdie81f280e2005-11-12 14:22:11 +0000232 pxa27x_stop_hc(&pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 iounmap(hcd->regs);
234 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
235 usb_put_hcd(hcd);
eric miaoa8bcf412007-12-12 08:53:25 +0800236 clk_put(usb_clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
239/*-------------------------------------------------------------------------*/
240
241static int __devinit
242ohci_pxa27x_start (struct usb_hcd *hcd)
243{
244 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
245 int ret;
246
247 ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
248
David Brownellfdd13b32005-08-31 11:52:57 -0700249 /* The value of NDP in roothub_a is incorrect on this hardware */
250 ohci->num_ports = 3;
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 if ((ret = ohci_init(ohci)) < 0)
253 return ret;
254
255 if ((ret = ohci_run (ohci)) < 0) {
256 err ("can't start %s", hcd->self.bus_name);
257 ohci_stop (hcd);
258 return ret;
259 }
260
261 return 0;
262}
263
264/*-------------------------------------------------------------------------*/
265
266static 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),
270
271 /*
272 * generic hardware linkage
273 */
274 .irq = ohci_irq,
275 .flags = HCD_USB11 | HCD_MEMORY,
276
277 /*
278 * basic lifecycle operations
279 */
280 .start = ohci_pxa27x_start,
281 .stop = ohci_stop,
David Brownelldd9048a2006-12-05 03:18:31 -0800282 .shutdown = ohci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 /*
285 * managing i/o requests and associated device resources
286 */
287 .urb_enqueue = ohci_urb_enqueue,
288 .urb_dequeue = ohci_urb_dequeue,
289 .endpoint_disable = ohci_endpoint_disable,
290
291 /*
292 * scheduling support
293 */
294 .get_frame_number = ohci_get_frame,
295
296 /*
297 * root hub support
298 */
299 .hub_status_data = ohci_hub_status_data,
300 .hub_control = ohci_hub_control,
David Brownell8ad7fe12005-09-13 19:59:11 -0700301#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400302 .bus_suspend = ohci_bus_suspend,
303 .bus_resume = ohci_bus_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304#endif
David Brownell92936772005-09-22 22:32:11 -0700305 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306};
307
308/*-------------------------------------------------------------------------*/
309
Russell King3ae5eae2005-11-09 22:32:44 +0000310static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 pr_debug ("In ohci_hcd_pxa27x_drv_probe");
313
314 if (usb_disabled())
315 return -ENODEV;
316
Richard Purdie81f280e2005-11-12 14:22:11 +0000317 return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318}
319
Russell King3ae5eae2005-11-09 22:32:44 +0000320static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Russell King3ae5eae2005-11-09 22:32:44 +0000322 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 usb_hcd_pxa27x_remove(hcd, pdev);
Richard Purdiea5e36d22005-11-28 22:15:46 +0000325 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 return 0;
327}
328
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000329#ifdef CONFIG_PM
330static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Richard Purdiea5e36d22005-11-28 22:15:46 +0000332 struct usb_hcd *hcd = platform_get_drvdata(pdev);
333 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000334
335 if (time_before(jiffies, ohci->next_statechange))
336 msleep(5);
337 ohci->next_statechange = jiffies;
338
339 pxa27x_stop_hc(&pdev->dev);
Richard Purdiea5e36d22005-11-28 22:15:46 +0000340 hcd->state = HC_STATE_SUSPENDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 return 0;
343}
344
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000345static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Richard Purdiea5e36d22005-11-28 22:15:46 +0000347 struct usb_hcd *hcd = platform_get_drvdata(pdev);
348 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000349 int status;
350
351 if (time_before(jiffies, ohci->next_statechange))
352 msleep(5);
353 ohci->next_statechange = jiffies;
354
355 if ((status = pxa27x_start_hc(&pdev->dev)) < 0)
356 return status;
357
Alan Stern43bbb7e2008-04-03 18:03:17 -0400358 ohci_finish_controller_resume(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return 0;
360}
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000361#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Kay Sieversf4fce612008-04-10 21:29:22 -0700363/* work with hotplug and coldplug */
364MODULE_ALIAS("platform:pxa27x-ohci");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Russell King3ae5eae2005-11-09 22:32:44 +0000366static struct platform_driver ohci_hcd_pxa27x_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 .probe = ohci_hcd_pxa27x_drv_probe,
368 .remove = ohci_hcd_pxa27x_drv_remove,
David Brownelldd9048a2006-12-05 03:18:31 -0800369 .shutdown = usb_hcd_platform_shutdown,
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000370#ifdef CONFIG_PM
David Brownelldd9048a2006-12-05 03:18:31 -0800371 .suspend = ohci_hcd_pxa27x_drv_suspend,
Russell King3ae5eae2005-11-09 22:32:44 +0000372 .resume = ohci_hcd_pxa27x_drv_resume,
Richard Purdie2e1dcc12005-11-12 14:22:14 +0000373#endif
Russell King3ae5eae2005-11-09 22:32:44 +0000374 .driver = {
375 .name = "pxa27x-ohci",
Kay Sieversf4fce612008-04-10 21:29:22 -0700376 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +0000377 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378};
379