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