blob: a1c8b3b2fcc7a29c57abcbd75c0b4622e531878c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Russell Kingd052d1b2005-10-29 19:07:23 +010021#include <linux/platform_device.h>
Tim Schmielaude259682006-01-08 01:02:05 -080022#include <linux/signal.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/mach-au1x00/au1000.h>
25
Jordan Croused5fb7f12006-01-20 14:09:54 -080026#ifndef CONFIG_SOC_AU1200
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#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
Jordan Croused5fb7f12006-01-20 14:09:54 -080042#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int usb_disabled(void);
70
71/*-------------------------------------------------------------------------*/
72
Jordan Croused5fb7f12006-01-20 14:09:54 -080073static void au1xxx_start_ohc(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 printk(KERN_DEBUG __FILE__
76 ": starting Au1xxx OHCI USB Controller\n");
77
78 /* enable host controller */
Jordan Croused5fb7f12006-01-20 14:09:54 -080079
80#ifndef CONFIG_SOC_AU1200
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
83 udelay(1000);
84 au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
85 udelay(1000);
86
Jordan Croused5fb7f12006-01-20 14:09:54 -080087#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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 /* wait for reset complete (read register twice; see au1500 errata) */
105 while (au_readl(USB_HOST_CONFIG),
106 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
107 udelay(1000);
108
109 printk(KERN_DEBUG __FILE__
110 ": Clock to USB host has been enabled \n");
111}
112
Jordan Croused5fb7f12006-01-20 14:09:54 -0800113static void au1xxx_stop_ohc(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 printk(KERN_DEBUG __FILE__
116 ": stopping Au1xxx OHCI USB Controller\n");
117
Jordan Croused5fb7f12006-01-20 14:09:54 -0800118#ifndef CONFIG_SOC_AU1200
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 /* Disable clock */
Sergei Shtylylov05090fc2006-01-05 22:50:39 -0800121 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
Jordan Croused5fb7f12006-01-20 14:09:54 -0800122
123#else /* Au1200 */
124
125 /* Disable mem */
126 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
127 udelay(1000);
128 /* Disable clock */
129 au_writel(~USBH_ENABLE_CE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
130 au_readl(USB_HOST_CONFIG);
131#endif /* Au1200 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134
135/*-------------------------------------------------------------------------*/
136
137/* configure so an HC device and id are always provided */
138/* always called with process context; sleeping is OK */
139
140
141/**
Jordan Croused5fb7f12006-01-20 14:09:54 -0800142 * usb_ohci_au1xxx_probe - initialize Au1xxx-based HCDs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 * Context: !in_interrupt()
144 *
145 * Allocates basic resources for this USB host controller, and
146 * then invokes the start() method for the HCD associated with it
147 * through the hotplug entry's driver_data.
148 *
149 */
Jordan Croused5fb7f12006-01-20 14:09:54 -0800150static int usb_ohci_au1xxx_probe(const struct hc_driver *driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 struct platform_device *dev)
152{
153 int retval;
154 struct usb_hcd *hcd;
155
Jordan Croused5fb7f12006-01-20 14:09:54 -0800156#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
157 /* Au1200 AB USB does not support coherent memory */
158 if (!(read_c0_prid() & 0xff)) {
159 pr_info("%s: this is chip revision AB !!\n",
160 dev->dev.name);
161 pr_info("%s: update your board or re-configure the kernel\n",
162 dev->dev.name);
163 return -ENODEV;
164 }
165#endif
166
167 if (dev->resource[1].flags != IORESOURCE_IRQ) {
168 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return -ENOMEM;
170 }
171
172 hcd = usb_create_hcd(driver, &dev->dev, "au1xxx");
173 if (!hcd)
174 return -ENOMEM;
175 hcd->rsrc_start = dev->resource[0].start;
176 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
177
178 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
Jordan Croused5fb7f12006-01-20 14:09:54 -0800179 pr_debug("request_mem_region failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 retval = -EBUSY;
181 goto err1;
182 }
183
184 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
185 if (!hcd->regs) {
Jordan Croused5fb7f12006-01-20 14:09:54 -0800186 pr_debug("ioremap failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 retval = -ENOMEM;
188 goto err2;
189 }
190
Jordan Croused5fb7f12006-01-20 14:09:54 -0800191 au1xxx_start_ohc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 ohci_hcd_init(hcd_to_ohci(hcd));
193
Jordan Croused5fb7f12006-01-20 14:09:54 -0800194 retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT | SA_SHIRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 if (retval == 0)
196 return retval;
197
Jordan Croused5fb7f12006-01-20 14:09:54 -0800198 au1xxx_stop_ohc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 iounmap(hcd->regs);
200 err2:
201 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
202 err1:
203 usb_put_hcd(hcd);
204 return retval;
205}
206
207
208/* may be called without controller electrically present */
209/* may be called with controller, bus, and devices active */
210
211/**
212 * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
213 * @dev: USB Host Controller being removed
214 * Context: !in_interrupt()
215 *
216 * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
217 * the HCD's stop() method. It is always called from a thread
218 * context, normally "rmmod", "apmd", or something similar.
219 *
220 */
Jordan Croused5fb7f12006-01-20 14:09:54 -0800221static void usb_ohci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 usb_remove_hcd(hcd);
Jordan Croused5fb7f12006-01-20 14:09:54 -0800224 au1xxx_stop_ohc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 iounmap(hcd->regs);
226 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
227 usb_put_hcd(hcd);
228}
229
230/*-------------------------------------------------------------------------*/
231
232static int __devinit
233ohci_au1xxx_start (struct usb_hcd *hcd)
234{
235 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
236 int ret;
237
238 ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci);
239
240 if ((ret = ohci_init (ohci)) < 0)
241 return ret;
242
243 if ((ret = ohci_run (ohci)) < 0) {
244 err ("can't start %s", hcd->self.bus_name);
245 ohci_stop (hcd);
246 return ret;
247 }
248
249 return 0;
250}
251
252/*-------------------------------------------------------------------------*/
253
254static const struct hc_driver ohci_au1xxx_hc_driver = {
255 .description = hcd_name,
256 .product_desc = "Au1xxx OHCI",
257 .hcd_priv_size = sizeof(struct ohci_hcd),
258
259 /*
260 * generic hardware linkage
261 */
262 .irq = ohci_irq,
263 .flags = HCD_USB11 | HCD_MEMORY,
264
265 /*
266 * basic lifecycle operations
267 */
268 .start = ohci_au1xxx_start,
269#ifdef CONFIG_PM
270 /* suspend: ohci_au1xxx_suspend, -- tbd */
271 /* resume: ohci_au1xxx_resume, -- tbd */
272#endif /*CONFIG_PM*/
273 .stop = ohci_stop,
274
275 /*
276 * managing i/o requests and associated device resources
277 */
278 .urb_enqueue = ohci_urb_enqueue,
279 .urb_dequeue = ohci_urb_dequeue,
280 .endpoint_disable = ohci_endpoint_disable,
281
282 /*
283 * scheduling support
284 */
285 .get_frame_number = ohci_get_frame,
286
287 /*
288 * root hub support
289 */
290 .hub_status_data = ohci_hub_status_data,
291 .hub_control = ohci_hub_control,
David Brownell92936772005-09-22 22:32:11 -0700292#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400293 .bus_suspend = ohci_bus_suspend,
294 .bus_resume = ohci_bus_resume,
David Brownell92936772005-09-22 22:32:11 -0700295#endif
296 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297};
298
299/*-------------------------------------------------------------------------*/
300
Russell King3ae5eae2005-11-09 22:32:44 +0000301static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 int ret;
304
305 pr_debug ("In ohci_hcd_au1xxx_drv_probe");
306
307 if (usb_disabled())
308 return -ENODEV;
309
Jordan Croused5fb7f12006-01-20 14:09:54 -0800310 ret = usb_ohci_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 return ret;
312}
313
Russell King3ae5eae2005-11-09 22:32:44 +0000314static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Russell King3ae5eae2005-11-09 22:32:44 +0000316 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Jordan Croused5fb7f12006-01-20 14:09:54 -0800318 usb_ohci_au1xxx_remove(hcd, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return 0;
320}
321 /*TBD*/
Russell King3ae5eae2005-11-09 22:32:44 +0000322/*static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Russell King3ae5eae2005-11-09 22:32:44 +0000324 struct usb_hcd *hcd = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 return 0;
327}
Russell King3ae5eae2005-11-09 22:32:44 +0000328static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Russell King3ae5eae2005-11-09 22:32:44 +0000330 struct usb_hcd *hcd = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 return 0;
333}
334*/
335
Russell King3ae5eae2005-11-09 22:32:44 +0000336static struct platform_driver ohci_hcd_au1xxx_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 .probe = ohci_hcd_au1xxx_drv_probe,
338 .remove = ohci_hcd_au1xxx_drv_remove,
339 /*.suspend = ohci_hcd_au1xxx_drv_suspend, */
340 /*.resume = ohci_hcd_au1xxx_drv_resume, */
Russell King3ae5eae2005-11-09 22:32:44 +0000341 .driver = {
342 .name = "au1xxx-ohci",
343 .owner = THIS_MODULE,
344 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345};
346
347static int __init ohci_hcd_au1xxx_init (void)
348{
349 pr_debug (DRIVER_INFO " (Au1xxx)");
350 pr_debug ("block sizes: ed %d td %d\n",
351 sizeof (struct ed), sizeof (struct td));
352
Russell King3ae5eae2005-11-09 22:32:44 +0000353 return platform_driver_register(&ohci_hcd_au1xxx_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
356static void __exit ohci_hcd_au1xxx_cleanup (void)
357{
Russell King3ae5eae2005-11-09 22:32:44 +0000358 platform_driver_unregister(&ohci_hcd_au1xxx_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
361module_init (ohci_hcd_au1xxx_init);
362module_exit (ohci_hcd_au1xxx_cleanup);