Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/pci-2.6
[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 #define USBH_ENABLE_BE (1<<0)
27 #define USBH_ENABLE_C  (1<<1)
28 #define USBH_ENABLE_E  (1<<2)
29 #define USBH_ENABLE_CE (1<<3)
30 #define USBH_ENABLE_RD (1<<4)
31
32 #ifdef __LITTLE_ENDIAN
33 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
34 #elif __BIG_ENDIAN
35 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE)
36 #else
37 #error not byte order defined
38 #endif
39
40 extern int usb_disabled(void);
41
42 /*-------------------------------------------------------------------------*/
43
44 static void au1xxx_start_hc(struct platform_device *dev)
45 {
46         printk(KERN_DEBUG __FILE__
47                 ": starting Au1xxx OHCI USB Controller\n");
48
49         /* enable host controller */
50         au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
51         udelay(1000);
52         au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
53         udelay(1000);
54
55         /* wait for reset complete (read register twice; see au1500 errata) */
56         while (au_readl(USB_HOST_CONFIG),
57                 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
58                 udelay(1000);
59
60         printk(KERN_DEBUG __FILE__
61         ": Clock to USB host has been enabled \n");
62 }
63
64 static void au1xxx_stop_hc(struct platform_device *dev)
65 {
66         printk(KERN_DEBUG __FILE__
67                ": stopping Au1xxx OHCI USB Controller\n");
68
69         /* Disable clock */
70         au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
71 }
72
73
74 /*-------------------------------------------------------------------------*/
75
76 /* configure so an HC device and id are always provided */
77 /* always called with process context; sleeping is OK */
78
79
80 /**
81  * usb_hcd_au1xxx_probe - initialize Au1xxx-based HCDs
82  * Context: !in_interrupt()
83  *
84  * Allocates basic resources for this USB host controller, and
85  * then invokes the start() method for the HCD associated with it
86  * through the hotplug entry's driver_data.
87  *
88  */
89 int usb_hcd_au1xxx_probe (const struct hc_driver *driver,
90                           struct platform_device *dev)
91 {
92         int retval;
93         struct usb_hcd *hcd;
94
95         if(dev->resource[1].flags != IORESOURCE_IRQ) {
96                 pr_debug ("resource[1] is not IORESOURCE_IRQ");
97                 return -ENOMEM;
98         }
99
100         hcd = usb_create_hcd(driver, &dev->dev, "au1xxx");
101         if (!hcd)
102                 return -ENOMEM;
103         hcd->rsrc_start = dev->resource[0].start;
104         hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
105
106         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
107                 pr_debug("request_mem_region failed");
108                 retval = -EBUSY;
109                 goto err1;
110         }
111
112         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
113         if (!hcd->regs) {
114                 pr_debug("ioremap failed");
115                 retval = -ENOMEM;
116                 goto err2;
117         }
118
119         au1xxx_start_hc(dev);
120         ohci_hcd_init(hcd_to_ohci(hcd));
121
122         retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
123         if (retval == 0)
124                 return retval;
125
126         au1xxx_stop_hc(dev);
127         iounmap(hcd->regs);
128  err2:
129         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
130  err1:
131         usb_put_hcd(hcd);
132         return retval;
133 }
134
135
136 /* may be called without controller electrically present */
137 /* may be called with controller, bus, and devices active */
138
139 /**
140  * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
141  * @dev: USB Host Controller being removed
142  * Context: !in_interrupt()
143  *
144  * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
145  * the HCD's stop() method.  It is always called from a thread
146  * context, normally "rmmod", "apmd", or something similar.
147  *
148  */
149 void usb_hcd_au1xxx_remove (struct usb_hcd *hcd, struct platform_device *dev)
150 {
151         usb_remove_hcd(hcd);
152         au1xxx_stop_hc(dev);
153         iounmap(hcd->regs);
154         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
155         usb_put_hcd(hcd);
156 }
157
158 /*-------------------------------------------------------------------------*/
159
160 static int __devinit
161 ohci_au1xxx_start (struct usb_hcd *hcd)
162 {
163         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
164         int             ret;
165
166         ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci);
167
168         if ((ret = ohci_init (ohci)) < 0)
169                 return ret;
170
171         if ((ret = ohci_run (ohci)) < 0) {
172                 err ("can't start %s", hcd->self.bus_name);
173                 ohci_stop (hcd);
174                 return ret;
175         }
176
177         return 0;
178 }
179
180 /*-------------------------------------------------------------------------*/
181
182 static const struct hc_driver ohci_au1xxx_hc_driver = {
183         .description =          hcd_name,
184         .product_desc =         "Au1xxx OHCI",
185         .hcd_priv_size =        sizeof(struct ohci_hcd),
186
187         /*
188          * generic hardware linkage
189          */
190         .irq =                  ohci_irq,
191         .flags =                HCD_USB11 | HCD_MEMORY,
192
193         /*
194          * basic lifecycle operations
195          */
196         .start =                ohci_au1xxx_start,
197 #ifdef  CONFIG_PM
198         /* suspend:             ohci_au1xxx_suspend,  -- tbd */
199         /* resume:              ohci_au1xxx_resume,   -- tbd */
200 #endif /*CONFIG_PM*/
201         .stop =                 ohci_stop,
202
203         /*
204          * managing i/o requests and associated device resources
205          */
206         .urb_enqueue =          ohci_urb_enqueue,
207         .urb_dequeue =          ohci_urb_dequeue,
208         .endpoint_disable =     ohci_endpoint_disable,
209
210         /*
211          * scheduling support
212          */
213         .get_frame_number =     ohci_get_frame,
214
215         /*
216          * root hub support
217          */
218         .hub_status_data =      ohci_hub_status_data,
219         .hub_control =          ohci_hub_control,
220 #ifdef  CONFIG_PM
221         .bus_suspend =          ohci_bus_suspend,
222         .bus_resume =           ohci_bus_resume,
223 #endif
224         .start_port_reset =     ohci_start_port_reset,
225 };
226
227 /*-------------------------------------------------------------------------*/
228
229 static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
230 {
231         int ret;
232
233         pr_debug ("In ohci_hcd_au1xxx_drv_probe");
234
235         if (usb_disabled())
236                 return -ENODEV;
237
238         ret = usb_hcd_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev);
239         return ret;
240 }
241
242 static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
243 {
244         struct usb_hcd *hcd = platform_get_drvdata(pdev);
245
246         usb_hcd_au1xxx_remove(hcd, pdev);
247         return 0;
248 }
249         /*TBD*/
250 /*static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *dev)
251 {
252         struct usb_hcd *hcd = platform_get_drvdata(dev);
253
254         return 0;
255 }
256 static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev)
257 {
258         struct usb_hcd *hcd = platform_get_drvdata(dev);
259
260         return 0;
261 }
262 */
263
264 static struct platform_driver ohci_hcd_au1xxx_driver = {
265         .probe          = ohci_hcd_au1xxx_drv_probe,
266         .remove         = ohci_hcd_au1xxx_drv_remove,
267         /*.suspend      = ohci_hcd_au1xxx_drv_suspend, */
268         /*.resume       = ohci_hcd_au1xxx_drv_resume, */
269         .driver         = {
270                 .name   = "au1xxx-ohci",
271                 .owner  = THIS_MODULE,
272         },
273 };
274
275 static int __init ohci_hcd_au1xxx_init (void)
276 {
277         pr_debug (DRIVER_INFO " (Au1xxx)");
278         pr_debug ("block sizes: ed %d td %d\n",
279                 sizeof (struct ed), sizeof (struct td));
280
281         return platform_driver_register(&ohci_hcd_au1xxx_driver);
282 }
283
284 static void __exit ohci_hcd_au1xxx_cleanup (void)
285 {
286         platform_driver_unregister(&ohci_hcd_au1xxx_driver);
287 }
288
289 module_init (ohci_hcd_au1xxx_init);
290 module_exit (ohci_hcd_au1xxx_cleanup);