]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/usb/host/ohci-pxa27x.c
Merge iSeries include file move
[karo-tx-linux.git] / drivers / usb / host / ohci-pxa27x.c
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>
23 #include <linux/signal.h>
24 #include <asm/mach-types.h>
25 #include <asm/hardware.h>
26 #include <asm/arch/pxa-regs.h>
27
28
29 #define PMM_NPS_MODE           1
30 #define PMM_GLOBAL_MODE        2
31 #define PMM_PERPORT_MODE       3
32
33 #define PXA_UHC_MAX_PORTNUM    3
34
35 #define UHCRHPS(x)              __REG2( 0x4C000050, (x)<<2 )
36
37 static int pxa27x_ohci_pmm_state;
38
39 /*
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  */
49 static int pxa27x_ohci_select_pmm( int mode )
50 {
51         pxa27x_ohci_pmm_state = mode;
52
53         switch ( mode ) {
54         case PMM_NPS_MODE:
55                 UHCRHDA |= RH_A_NPS;
56                 break; 
57         case PMM_GLOBAL_MODE:
58                 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
59                 break;
60         case PMM_PERPORT_MODE:
61                 UHCRHDA &= ~(RH_A_NPS);
62                 UHCRHDA |= RH_A_PSM;
63
64                 /* Set port power control mask bits, only 3 ports. */
65                 UHCRHDB |= (0x7<<17);
66                 break;
67         default:
68                 printk( KERN_ERR
69                         "Invalid mode %d, set to non-power switch mode.\n", 
70                         mode );
71
72                 pxa27x_ohci_pmm_state = PMM_NPS_MODE;
73                 UHCRHDA |= RH_A_NPS;
74         }
75
76         return 0;
77 }
78
79 extern int usb_disabled(void);
80
81 /*-------------------------------------------------------------------------*/
82
83 static void pxa27x_start_hc(struct platform_device *dev)
84 {
85         pxa_set_cken(CKEN10_USBHOST, 1);
86
87         UHCHR |= UHCHR_FHR;
88         udelay(11);
89         UHCHR &= ~UHCHR_FHR;
90
91         UHCHR |= UHCHR_FSBIR;
92         while (UHCHR & UHCHR_FSBIR)
93                 cpu_relax();
94
95         /* This could be properly abstracted away through the
96            device data the day more machines are supported and
97            their differences can be figured out correctly. */
98         if (machine_is_mainstone()) {
99                 /* setup Port1 GPIO pin. */
100                 pxa_gpio_mode( 88 | GPIO_ALT_FN_1_IN);  /* USBHPWR1 */
101                 pxa_gpio_mode( 89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */
102
103                 /* Set the Power Control Polarity Low and Power Sense
104                    Polarity Low to active low. Supply power to USB ports. */
105                 UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
106                         ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
107
108                 pxa27x_ohci_pmm_state = PMM_PERPORT_MODE;
109         }
110
111         UHCHR &= ~UHCHR_SSE;
112
113         UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
114
115         /* Clear any OTG Pin Hold */
116         if (PSSR & PSSR_OTGPH)
117                 PSSR |= PSSR_OTGPH;
118 }
119
120 static void pxa27x_stop_hc(struct platform_device *dev)
121 {
122         UHCHR |= UHCHR_FHR;
123         udelay(11);
124         UHCHR &= ~UHCHR_FHR;
125
126         UHCCOMS |= 1;
127         udelay(10);
128
129         pxa_set_cken(CKEN10_USBHOST, 0);
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  */
148 int usb_hcd_pxa27x_probe (const struct hc_driver *driver,
149                           struct platform_device *dev)
150 {
151         int retval;
152         struct usb_hcd *hcd;
153
154         if (dev->resource[1].flags != IORESOURCE_IRQ) {
155                 pr_debug ("resource[1] is not IORESOURCE_IRQ");
156                 return -ENOMEM;
157         }
158
159         hcd = usb_create_hcd (driver, &dev->dev, "pxa27x");
160         if (!hcd)
161                 return -ENOMEM;
162         hcd->rsrc_start = dev->resource[0].start;
163         hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
164
165         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
166                 pr_debug("request_mem_region failed");
167                 retval = -EBUSY;
168                 goto err1;
169         }
170
171         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
172         if (!hcd->regs) {
173                 pr_debug("ioremap failed");
174                 retval = -ENOMEM;
175                 goto err2;
176         }
177
178         pxa27x_start_hc(dev);
179
180         /* Select Power Management Mode */
181         pxa27x_ohci_select_pmm(pxa27x_ohci_pmm_state);
182
183         ohci_hcd_init(hcd_to_ohci(hcd));
184
185         retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
186         if (retval == 0)
187                 return retval;
188
189         pxa27x_stop_hc(dev);
190         iounmap(hcd->regs);
191  err2:
192         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
193  err1:
194         usb_put_hcd(hcd);
195         return retval;
196 }
197
198
199 /* may be called without controller electrically present */
200 /* may be called with controller, bus, and devices active */
201
202 /**
203  * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
204  * @dev: USB Host Controller being removed
205  * Context: !in_interrupt()
206  *
207  * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
208  * the HCD's stop() method.  It is always called from a thread
209  * context, normally "rmmod", "apmd", or something similar.
210  *
211  */
212 void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *dev)
213 {
214         usb_remove_hcd(hcd);
215         pxa27x_stop_hc(dev);
216         iounmap(hcd->regs);
217         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
218         usb_put_hcd(hcd);
219 }
220
221 /*-------------------------------------------------------------------------*/
222
223 static int __devinit
224 ohci_pxa27x_start (struct usb_hcd *hcd)
225 {
226         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
227         int             ret;
228
229         ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
230
231         /* The value of NDP in roothub_a is incorrect on this hardware */
232         ohci->num_ports = 3;
233
234         if ((ret = ohci_init(ohci)) < 0)
235                 return ret;
236
237         if ((ret = ohci_run (ohci)) < 0) {
238                 err ("can't start %s", hcd->self.bus_name);
239                 ohci_stop (hcd);
240                 return ret;
241         }
242
243         return 0;
244 }
245
246 /*-------------------------------------------------------------------------*/
247
248 static const struct hc_driver ohci_pxa27x_hc_driver = {
249         .description =          hcd_name,
250         .product_desc =         "PXA27x OHCI",
251         .hcd_priv_size =        sizeof(struct ohci_hcd),
252
253         /*
254          * generic hardware linkage
255          */
256         .irq =                  ohci_irq,
257         .flags =                HCD_USB11 | HCD_MEMORY,
258
259         /*
260          * basic lifecycle operations
261          */
262         .start =                ohci_pxa27x_start,
263         .stop =                 ohci_stop,
264
265         /*
266          * managing i/o requests and associated device resources
267          */
268         .urb_enqueue =          ohci_urb_enqueue,
269         .urb_dequeue =          ohci_urb_dequeue,
270         .endpoint_disable =     ohci_endpoint_disable,
271
272         /*
273          * scheduling support
274          */
275         .get_frame_number =     ohci_get_frame,
276
277         /*
278          * root hub support
279          */
280         .hub_status_data =      ohci_hub_status_data,
281         .hub_control =          ohci_hub_control,
282 #ifdef  CONFIG_PM
283         .bus_suspend =          ohci_bus_suspend,
284         .bus_resume =           ohci_bus_resume,
285 #endif
286         .start_port_reset =     ohci_start_port_reset,
287 };
288
289 /*-------------------------------------------------------------------------*/
290
291 static int ohci_hcd_pxa27x_drv_probe(struct device *dev)
292 {
293         struct platform_device *pdev = to_platform_device(dev);
294         int ret;
295
296         pr_debug ("In ohci_hcd_pxa27x_drv_probe");
297
298         if (usb_disabled())
299                 return -ENODEV;
300
301         ret = usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
302         return ret;
303 }
304
305 static int ohci_hcd_pxa27x_drv_remove(struct device *dev)
306 {
307         struct platform_device *pdev = to_platform_device(dev);
308         struct usb_hcd *hcd = dev_get_drvdata(dev);
309
310         usb_hcd_pxa27x_remove(hcd, pdev);
311         return 0;
312 }
313
314 static int ohci_hcd_pxa27x_drv_suspend(struct device *dev, pm_message_t state)
315 {
316 //      struct platform_device *pdev = to_platform_device(dev);
317 //      struct usb_hcd *hcd = dev_get_drvdata(dev);
318         printk("%s: not implemented yet\n", __FUNCTION__);
319
320         return 0;
321 }
322
323 static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
324 {
325 //      struct platform_device *pdev = to_platform_device(dev);
326 //      struct usb_hcd *hcd = dev_get_drvdata(dev);
327         printk("%s: not implemented yet\n", __FUNCTION__);
328
329         return 0;
330 }
331
332
333 static struct device_driver ohci_hcd_pxa27x_driver = {
334         .name           = "pxa27x-ohci",
335         .bus            = &platform_bus_type,
336         .probe          = ohci_hcd_pxa27x_drv_probe,
337         .remove         = ohci_hcd_pxa27x_drv_remove,
338         .suspend        = ohci_hcd_pxa27x_drv_suspend, 
339         .resume         = ohci_hcd_pxa27x_drv_resume, 
340 };
341
342 static int __init ohci_hcd_pxa27x_init (void)
343 {
344         pr_debug (DRIVER_INFO " (pxa27x)");
345         pr_debug ("block sizes: ed %d td %d\n",
346                 sizeof (struct ed), sizeof (struct td));
347
348         return driver_register(&ohci_hcd_pxa27x_driver);
349 }
350
351 static void __exit ohci_hcd_pxa27x_cleanup (void)
352 {
353         driver_unregister(&ohci_hcd_pxa27x_driver);
354 }
355
356 module_init (ohci_hcd_pxa27x_init);
357 module_exit (ohci_hcd_pxa27x_cleanup);