]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/usb/host/ohci-pxa27x.c
[ARM] Move include/asm-arm/arch-* to arch/arm/*/include/mach
[net-next-2.6.git] / drivers / usb / host / ohci-pxa27x.c
CommitLineData
1da177e4
LT
1/*
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>
4e57b681 23#include <linux/signal.h>
d052d1be 24#include <linux/platform_device.h>
a8bcf410 25#include <linux/clk.h>
4fd5f826 26
a09e64fb
RK
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>
1da177e4
LT
31
32#define PXA_UHC_MAX_PORTNUM 3
33
34#define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 )
35
a8bcf410 36static struct clk *usb_clk;
37
1da177e4
LT
38/*
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{
1da177e4
LT
50 switch ( mode ) {
51 case PMM_NPS_MODE:
52 UHCRHDA |= RH_A_NPS;
dd9048af 53 break;
1da177e4
LT
54 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
dd9048af 66 "Invalid mode %d, set to non-power switch mode.\n",
1da177e4
LT
67 mode );
68
1da177e4
LT
69 UHCRHDA |= RH_A_NPS;
70 }
71
72 return 0;
73}
74
1da177e4
LT
75extern int usb_disabled(void);
76
77/*-------------------------------------------------------------------------*/
78
81f280e2 79static int pxa27x_start_hc(struct device *dev)
1da177e4 80{
81f280e2
RP
81 int retval = 0;
82 struct pxaohci_platform_data *inf;
83
84 inf = dev->platform_data;
85
a8bcf410 86 clk_enable(usb_clk);
1da177e4
LT
87
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
81f280e2
RP
96 if (inf->init)
97 retval = inf->init(dev);
155faf5e 98
81f280e2
RP
99 if (retval < 0)
100 return retval;
1da177e4
LT
101
102 UHCHR &= ~UHCHR_SSE;
103
104 UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
155faf5e
DB
105
106 /* Clear any OTG Pin Hold */
d438ae57 107 if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
155faf5e 108 PSSR |= PSSR_OTGPH;
81f280e2
RP
109
110 return 0;
1da177e4
LT
111}
112
81f280e2 113static void pxa27x_stop_hc(struct device *dev)
1da177e4 114{
81f280e2
RP
115 struct pxaohci_platform_data *inf;
116
117 inf = dev->platform_data;
118
119 if (inf->exit)
120 inf->exit(dev);
121
1da177e4
LT
122 UHCHR |= UHCHR_FHR;
123 udelay(11);
124 UHCHR &= ~UHCHR_FHR;
125
126 UHCCOMS |= 1;
127 udelay(10);
128
a8bcf410 129 clk_disable(usb_clk);
1da177e4
LT
130}
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 */
81f280e2 148int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device *pdev)
1da177e4
LT
149{
150 int retval;
151 struct usb_hcd *hcd;
81f280e2
RP
152 struct pxaohci_platform_data *inf;
153
154 inf = pdev->dev.platform_data;
1da177e4 155
81f280e2
RP
156 if (!inf)
157 return -ENODEV;
158
159 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
1da177e4
LT
160 pr_debug ("resource[1] is not IORESOURCE_IRQ");
161 return -ENOMEM;
162 }
163
a8bcf410 164 usb_clk = clk_get(&pdev->dev, "USBCLK");
165 if (IS_ERR(usb_clk))
166 return PTR_ERR(usb_clk);
167
81f280e2 168 hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
1da177e4
LT
169 if (!hcd)
170 return -ENOMEM;
81f280e2
RP
171 hcd->rsrc_start = pdev->resource[0].start;
172 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
1da177e4
LT
173
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
81f280e2
RP
187 if ((retval = pxa27x_start_hc(&pdev->dev)) < 0) {
188 pr_debug("pxa27x_start_hc failed");
189 goto err3;
190 }
1da177e4
LT
191
192 /* Select Power Management Mode */
81f280e2 193 pxa27x_ohci_select_pmm(inf->port_mode);
1da177e4 194
0c27c5d5
RP
195 if (inf->power_budget)
196 hcd->power_budget = inf->power_budget;
197
1da177e4
LT
198 ohci_hcd_init(hcd_to_ohci(hcd));
199
d54b5caa 200 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
1da177e4
LT
201 if (retval == 0)
202 return retval;
203
81f280e2
RP
204 pxa27x_stop_hc(&pdev->dev);
205 err3:
1da177e4
LT
206 iounmap(hcd->regs);
207 err2:
208 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
209 err1:
210 usb_put_hcd(hcd);
a8bcf410 211 clk_put(usb_clk);
1da177e4
LT
212 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 */
81f280e2 229void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
1da177e4
LT
230{
231 usb_remove_hcd(hcd);
81f280e2 232 pxa27x_stop_hc(&pdev->dev);
1da177e4
LT
233 iounmap(hcd->regs);
234 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
235 usb_put_hcd(hcd);
a8bcf410 236 clk_put(usb_clk);
1da177e4
LT
237}
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
fdd13b36
DB
249 /* The value of NDP in roothub_a is incorrect on this hardware */
250 ohci->num_ports = 3;
251
1da177e4
LT
252 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,
dd9048af 282 .shutdown = ohci_shutdown,
1da177e4
LT
283
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,
09ca8adb 301 .hub_irq_enable = ohci_rhsc_enable,
8ad7fe16 302#ifdef CONFIG_PM
0c0382e3
AS
303 .bus_suspend = ohci_bus_suspend,
304 .bus_resume = ohci_bus_resume,
1da177e4 305#endif
9293677a 306 .start_port_reset = ohci_start_port_reset,
1da177e4
LT
307};
308
309/*-------------------------------------------------------------------------*/
310
3ae5eaec 311static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
1da177e4 312{
1da177e4
LT
313 pr_debug ("In ohci_hcd_pxa27x_drv_probe");
314
315 if (usb_disabled())
316 return -ENODEV;
317
81f280e2 318 return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
1da177e4
LT
319}
320
3ae5eaec 321static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
1da177e4 322{
3ae5eaec 323 struct usb_hcd *hcd = platform_get_drvdata(pdev);
1da177e4
LT
324
325 usb_hcd_pxa27x_remove(hcd, pdev);
a5e36d20 326 platform_set_drvdata(pdev, NULL);
1da177e4
LT
327 return 0;
328}
329
2e1dcc16
RP
330#ifdef CONFIG_PM
331static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state)
1da177e4 332{
a5e36d20
RP
333 struct usb_hcd *hcd = platform_get_drvdata(pdev);
334 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
2e1dcc16
RP
335
336 if (time_before(jiffies, ohci->next_statechange))
337 msleep(5);
338 ohci->next_statechange = jiffies;
339
340 pxa27x_stop_hc(&pdev->dev);
a5e36d20 341 hcd->state = HC_STATE_SUSPENDED;
1da177e4
LT
342
343 return 0;
344}
345
2e1dcc16 346static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
1da177e4 347{
a5e36d20
RP
348 struct usb_hcd *hcd = platform_get_drvdata(pdev);
349 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
2e1dcc16
RP
350 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
43bbb7e0 359 ohci_finish_controller_resume(hcd);
1da177e4
LT
360 return 0;
361}
2e1dcc16 362#endif
1da177e4 363
f4fce61d
KS
364/* work with hotplug and coldplug */
365MODULE_ALIAS("platform:pxa27x-ohci");
1da177e4 366
3ae5eaec 367static struct platform_driver ohci_hcd_pxa27x_driver = {
1da177e4
LT
368 .probe = ohci_hcd_pxa27x_drv_probe,
369 .remove = ohci_hcd_pxa27x_drv_remove,
dd9048af 370 .shutdown = usb_hcd_platform_shutdown,
2e1dcc16 371#ifdef CONFIG_PM
dd9048af 372 .suspend = ohci_hcd_pxa27x_drv_suspend,
3ae5eaec 373 .resume = ohci_hcd_pxa27x_drv_resume,
2e1dcc16 374#endif
3ae5eaec
RK
375 .driver = {
376 .name = "pxa27x-ohci",
f4fce61d 377 .owner = THIS_MODULE,
3ae5eaec 378 },
1da177e4
LT
379};
380