Merge master.kernel.org:/home/rmk/linux-2.6-arm
[linux-2.6] / drivers / usb / host / ohci-au1xxx.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 AMD Alchemy Au1xxx
9  *
10  * Written by Christopher Hoover <ch@hpl.hp.com>
11  * Based on fragments of previous driver by Rusell King et al.
12  *
13  * Modified for LH7A404 from ohci-sa1111.c
14  *  by Durgesh Pattamatta <pattamattad@sharpsec.com>
15  * Modified for AMD Alchemy Au1xxx
16  *  by Matt Porter <mporter@kernel.crashing.org>
17  *
18  * This file is licenced under the GPL.
19  */
20
21 #include <linux/platform_device.h>
22 #include <linux/signal.h>
23
24 #include <asm/mach-au1x00/au1000.h>
25
26 #ifndef CONFIG_SOC_AU1200
27
28 #define USBH_ENABLE_BE (1<<0)
29 #define USBH_ENABLE_C  (1<<1)
30 #define USBH_ENABLE_E  (1<<2)
31 #define USBH_ENABLE_CE (1<<3)
32 #define USBH_ENABLE_RD (1<<4)
33
34 #ifdef __LITTLE_ENDIAN
35 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
36 #elif __BIG_ENDIAN
37 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE)
38 #else
39 #error not byte order defined
40 #endif
41
42 #else   /* Au1200 */
43
44 #define USB_HOST_CONFIG    (USB_MSR_BASE + USB_MSR_MCFG)
45 #define USB_MCFG_PFEN     (1<<31)
46 #define USB_MCFG_RDCOMB   (1<<30)
47 #define USB_MCFG_SSDEN    (1<<23)
48 #define USB_MCFG_OHCCLKEN (1<<16)
49 #define USB_MCFG_UCAM     (1<<7)
50 #define USB_MCFG_OBMEN    (1<<1)
51 #define USB_MCFG_OMEMEN   (1<<0)
52
53 #define USBH_ENABLE_CE    USB_MCFG_OHCCLKEN
54 #ifdef CONFIG_DMA_COHERENT
55 #define USBH_ENABLE_INIT  (USB_MCFG_OHCCLKEN \
56                          | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
57                          | USB_MCFG_SSDEN | USB_MCFG_UCAM \
58                          | USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
59 #else
60 #define USBH_ENABLE_INIT  (USB_MCFG_OHCCLKEN \
61                          | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
62                          | USB_MCFG_SSDEN \
63                          | USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
64 #endif
65 #define USBH_DISABLE      (USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
66
67 #endif  /* Au1200 */
68
69 extern int usb_disabled(void);
70
71 /*-------------------------------------------------------------------------*/
72
73 static void au1xxx_start_ohc(struct platform_device *dev)
74 {
75         printk(KERN_DEBUG __FILE__
76                 ": starting Au1xxx OHCI USB Controller\n");
77
78         /* enable host controller */
79
80 #ifndef CONFIG_SOC_AU1200
81
82         au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
83         udelay(1000);
84         au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
85         udelay(1000);
86
87 #else   /* Au1200 */
88
89         /* write HW defaults again in case Yamon cleared them */
90         if (au_readl(USB_HOST_CONFIG) == 0) {
91                 au_writel(0x00d02000, USB_HOST_CONFIG);
92                 au_readl(USB_HOST_CONFIG);
93                 udelay(1000);
94         }
95         au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
96         au_readl(USB_HOST_CONFIG);
97         udelay(1000);
98         au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
99         au_readl(USB_HOST_CONFIG);
100         udelay(1000);
101
102 #endif  /* Au1200 */
103
104 #ifndef CONFIG_SOC_AU1200
105         /* wait for reset complete (read register twice; see au1500 errata) */
106         while (au_readl(USB_HOST_CONFIG),
107                 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
108 #endif
109                 udelay(1000);
110
111         printk(KERN_DEBUG __FILE__
112         ": Clock to USB host has been enabled \n");
113 #endif
114 }
115
116 static void au1xxx_stop_ohc(struct platform_device *dev)
117 {
118         printk(KERN_DEBUG __FILE__
119                ": stopping Au1xxx OHCI USB Controller\n");
120
121 #ifndef CONFIG_SOC_AU1200
122
123         /* Disable clock */
124         au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
125
126 #else   /* Au1200 */
127
128         /* Disable mem */
129         au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
130         udelay(1000);
131         /* Disable clock */
132         au_writel(~USBH_ENABLE_CE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
133         au_readl(USB_HOST_CONFIG);
134 #endif  /* Au1200 */
135 }
136
137
138 /*-------------------------------------------------------------------------*/
139
140 /* configure so an HC device and id are always provided */
141 /* always called with process context; sleeping is OK */
142
143
144 /**
145  * usb_ohci_au1xxx_probe - initialize Au1xxx-based HCDs
146  * Context: !in_interrupt()
147  *
148  * Allocates basic resources for this USB host controller, and
149  * then invokes the start() method for the HCD associated with it
150  * through the hotplug entry's driver_data.
151  *
152  */
153 static int usb_ohci_au1xxx_probe(const struct hc_driver *driver,
154                           struct platform_device *dev)
155 {
156         int retval;
157         struct usb_hcd *hcd;
158
159 #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
160         /* Au1200 AB USB does not support coherent memory */
161         if (!(read_c0_prid() & 0xff)) {
162                 pr_info("%s: this is chip revision AB !!\n",
163                         dev->name);
164                 pr_info("%s: update your board or re-configure the kernel\n",
165                         dev->name);
166                 return -ENODEV;
167         }
168 #endif
169
170         if (dev->resource[1].flags != IORESOURCE_IRQ) {
171                 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
172                 return -ENOMEM;
173         }
174
175         hcd = usb_create_hcd(driver, &dev->dev, "au1xxx");
176         if (!hcd)
177                 return -ENOMEM;
178         hcd->rsrc_start = dev->resource[0].start;
179         hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
180
181         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
182                 pr_debug("request_mem_region failed\n");
183                 retval = -EBUSY;
184                 goto err1;
185         }
186
187         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
188         if (!hcd->regs) {
189                 pr_debug("ioremap failed\n");
190                 retval = -ENOMEM;
191                 goto err2;
192         }
193
194         au1xxx_start_ohc(dev);
195         ohci_hcd_init(hcd_to_ohci(hcd));
196
197         retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED);
198         if (retval == 0)
199                 return retval;
200
201         au1xxx_stop_ohc(dev);
202         iounmap(hcd->regs);
203  err2:
204         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
205  err1:
206         usb_put_hcd(hcd);
207         return retval;
208 }
209
210
211 /* may be called without controller electrically present */
212 /* may be called with controller, bus, and devices active */
213
214 /**
215  * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
216  * @dev: USB Host Controller being removed
217  * Context: !in_interrupt()
218  *
219  * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
220  * the HCD's stop() method.  It is always called from a thread
221  * context, normally "rmmod", "apmd", or something similar.
222  *
223  */
224 static void usb_ohci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
225 {
226         usb_remove_hcd(hcd);
227         au1xxx_stop_ohc(dev);
228         iounmap(hcd->regs);
229         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
230         usb_put_hcd(hcd);
231 }
232
233 /*-------------------------------------------------------------------------*/
234
235 static int __devinit
236 ohci_au1xxx_start (struct usb_hcd *hcd)
237 {
238         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
239         int             ret;
240
241         ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci);
242
243         if ((ret = ohci_init (ohci)) < 0)
244                 return ret;
245
246         if ((ret = ohci_run (ohci)) < 0) {
247                 err ("can't start %s", hcd->self.bus_name);
248                 ohci_stop (hcd);
249                 return ret;
250         }
251
252         return 0;
253 }
254
255 /*-------------------------------------------------------------------------*/
256
257 static const struct hc_driver ohci_au1xxx_hc_driver = {
258         .description =          hcd_name,
259         .product_desc =         "Au1xxx OHCI",
260         .hcd_priv_size =        sizeof(struct ohci_hcd),
261
262         /*
263          * generic hardware linkage
264          */
265         .irq =                  ohci_irq,
266         .flags =                HCD_USB11 | HCD_MEMORY,
267
268         /*
269          * basic lifecycle operations
270          */
271         .start =                ohci_au1xxx_start,
272 #ifdef  CONFIG_PM
273         /* suspend:             ohci_au1xxx_suspend,  -- tbd */
274         /* resume:              ohci_au1xxx_resume,   -- tbd */
275 #endif /*CONFIG_PM*/
276         .stop =                 ohci_stop,
277
278         /*
279          * managing i/o requests and associated device resources
280          */
281         .urb_enqueue =          ohci_urb_enqueue,
282         .urb_dequeue =          ohci_urb_dequeue,
283         .endpoint_disable =     ohci_endpoint_disable,
284
285         /*
286          * scheduling support
287          */
288         .get_frame_number =     ohci_get_frame,
289
290         /*
291          * root hub support
292          */
293         .hub_status_data =      ohci_hub_status_data,
294         .hub_control =          ohci_hub_control,
295 #ifdef  CONFIG_PM
296         .bus_suspend =          ohci_bus_suspend,
297         .bus_resume =           ohci_bus_resume,
298 #endif
299         .start_port_reset =     ohci_start_port_reset,
300 };
301
302 /*-------------------------------------------------------------------------*/
303
304 static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
305 {
306         int ret;
307
308         pr_debug ("In ohci_hcd_au1xxx_drv_probe");
309
310         if (usb_disabled())
311                 return -ENODEV;
312
313         ret = usb_ohci_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev);
314         return ret;
315 }
316
317 static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
318 {
319         struct usb_hcd *hcd = platform_get_drvdata(pdev);
320
321         usb_ohci_au1xxx_remove(hcd, pdev);
322         return 0;
323 }
324         /*TBD*/
325 /*static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *dev)
326 {
327         struct usb_hcd *hcd = platform_get_drvdata(dev);
328
329         return 0;
330 }
331 static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev)
332 {
333         struct usb_hcd *hcd = platform_get_drvdata(dev);
334
335         return 0;
336 }
337 */
338
339 static struct platform_driver ohci_hcd_au1xxx_driver = {
340         .probe          = ohci_hcd_au1xxx_drv_probe,
341         .remove         = ohci_hcd_au1xxx_drv_remove,
342         /*.suspend      = ohci_hcd_au1xxx_drv_suspend, */
343         /*.resume       = ohci_hcd_au1xxx_drv_resume, */
344         .driver         = {
345                 .name   = "au1xxx-ohci",
346                 .owner  = THIS_MODULE,
347         },
348 };
349
350 static int __init ohci_hcd_au1xxx_init (void)
351 {
352         pr_debug (DRIVER_INFO " (Au1xxx)");
353         pr_debug ("block sizes: ed %d td %d\n",
354                 sizeof (struct ed), sizeof (struct td));
355
356         return platform_driver_register(&ohci_hcd_au1xxx_driver);
357 }
358
359 static void __exit ohci_hcd_au1xxx_cleanup (void)
360 {
361         platform_driver_unregister(&ohci_hcd_au1xxx_driver);
362 }
363
364 module_init (ohci_hcd_au1xxx_init);
365 module_exit (ohci_hcd_au1xxx_cleanup);