blob: 17a6043c1fa072cba3d84c01fe8f6ba83005fff3 [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>
Uwe Kleine-Königac310bb2008-07-10 17:30:46 -070011 * Based on fragments of previous driver by Russell King et al.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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
Manuel Lauss53c81a32008-06-23 09:08:29 +020037#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \
38 USBH_ENABLE_BE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#else
40#error not byte order defined
41#endif
42
Jordan Croused5fb7f12006-01-20 14:09:54 -080043#else /* Au1200 */
44
45#define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
46#define USB_MCFG_PFEN (1<<31)
47#define USB_MCFG_RDCOMB (1<<30)
48#define USB_MCFG_SSDEN (1<<23)
49#define USB_MCFG_OHCCLKEN (1<<16)
Manuel Lauss53c81a32008-06-23 09:08:29 +020050#ifdef CONFIG_DMA_COHERENT
Jordan Croused5fb7f12006-01-20 14:09:54 -080051#define USB_MCFG_UCAM (1<<7)
Manuel Lauss53c81a32008-06-23 09:08:29 +020052#else
53#define USB_MCFG_UCAM (0)
54#endif
Jordan Croused5fb7f12006-01-20 14:09:54 -080055#define USB_MCFG_OBMEN (1<<1)
56#define USB_MCFG_OMEMEN (1<<0)
57
58#define USBH_ENABLE_CE USB_MCFG_OHCCLKEN
Manuel Lauss53c81a32008-06-23 09:08:29 +020059
60#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
61 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
62 USB_MCFG_UCAM | \
63 USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
64
Jordan Croused5fb7f12006-01-20 14:09:54 -080065#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
Manuel Lauss53c81a32008-06-23 09:08:29 +020071static void au1xxx_start_ohc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 /* enable host controller */
Jordan Croused5fb7f12006-01-20 14:09:54 -080074#ifndef CONFIG_SOC_AU1200
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
Manuel Lauss53c81a32008-06-23 09:08:29 +020076 au_sync();
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 udelay(1000);
78
Manuel Lauss53c81a32008-06-23 09:08:29 +020079 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
80 au_sync();
Jordan Croused5fb7f12006-01-20 14:09:54 -080081 udelay(1000);
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 /* wait for reset complete (read register twice; see au1500 errata) */
84 while (au_readl(USB_HOST_CONFIG),
85 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
86 udelay(1000);
87
Jordan Croused5fb7f12006-01-20 14:09:54 -080088#else /* Au1200 */
Manuel Lauss53c81a32008-06-23 09:08:29 +020089 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
90 au_sync();
Jordan Croused5fb7f12006-01-20 14:09:54 -080091 udelay(1000);
Manuel Lauss53c81a32008-06-23 09:08:29 +020092
93 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
94 au_sync();
95 udelay(2000);
Jordan Croused5fb7f12006-01-20 14:09:54 -080096#endif /* Au1200 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Manuel Lauss53c81a32008-06-23 09:08:29 +020099static void au1xxx_stop_ohc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
Manuel Lauss53c81a32008-06-23 09:08:29 +0200101#ifdef CONFIG_SOC_AU1200
102 /* Disable mem */
103 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
104 au_sync();
105 udelay(1000);
Jordan Croused5fb7f12006-01-20 14:09:54 -0800106#endif
Manuel Lauss53c81a32008-06-23 09:08:29 +0200107 /* Disable clock */
108 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
109 au_sync();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Manuel Lauss53c81a32008-06-23 09:08:29 +0200112static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Manuel Lauss53c81a32008-06-23 09:08:29 +0200114 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
115 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Manuel Lauss53c81a32008-06-23 09:08:29 +0200117 ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Manuel Lauss53c81a32008-06-23 09:08:29 +0200119 if ((ret = ohci_init(ohci)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return ret;
121
Manuel Lauss53c81a32008-06-23 09:08:29 +0200122 if ((ret = ohci_run(ohci)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 err ("can't start %s", hcd->self.bus_name);
Manuel Lauss53c81a32008-06-23 09:08:29 +0200124 ohci_stop(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 return ret;
126 }
127
128 return 0;
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131static const struct hc_driver ohci_au1xxx_hc_driver = {
132 .description = hcd_name,
133 .product_desc = "Au1xxx OHCI",
134 .hcd_priv_size = sizeof(struct ohci_hcd),
135
136 /*
137 * generic hardware linkage
138 */
139 .irq = ohci_irq,
140 .flags = HCD_USB11 | HCD_MEMORY,
141
142 /*
143 * basic lifecycle operations
144 */
145 .start = ohci_au1xxx_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 .stop = ohci_stop,
David Brownelldd9048a2006-12-05 03:18:31 -0800147 .shutdown = ohci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 /*
150 * managing i/o requests and associated device resources
151 */
152 .urb_enqueue = ohci_urb_enqueue,
153 .urb_dequeue = ohci_urb_dequeue,
154 .endpoint_disable = ohci_endpoint_disable,
155
156 /*
157 * scheduling support
158 */
159 .get_frame_number = ohci_get_frame,
160
161 /*
162 * root hub support
163 */
164 .hub_status_data = ohci_hub_status_data,
165 .hub_control = ohci_hub_control,
David Brownell92936772005-09-22 22:32:11 -0700166#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400167 .bus_suspend = ohci_bus_suspend,
168 .bus_resume = ohci_bus_resume,
David Brownell92936772005-09-22 22:32:11 -0700169#endif
170 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
Russell King3ae5eae2005-11-09 22:32:44 +0000173static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 int ret;
Manuel Lauss53c81a32008-06-23 09:08:29 +0200176 struct usb_hcd *hcd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 if (usb_disabled())
179 return -ENODEV;
180
Manuel Lauss53c81a32008-06-23 09:08:29 +0200181#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
182 /* Au1200 AB USB does not support coherent memory */
183 if (!(read_c0_prid() & 0xff)) {
184 printk(KERN_INFO "%s: this is chip revision AB !!\n",
185 pdev->name);
186 printk(KERN_INFO "%s: update your board or re-configure "
187 "the kernel\n", pdev->name);
188 return -ENODEV;
189 }
190#endif
191
192 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
193 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
194 return -ENOMEM;
195 }
196
197 hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx");
198 if (!hcd)
199 return -ENOMEM;
200
201 hcd->rsrc_start = pdev->resource[0].start;
202 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
203
204 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
205 pr_debug("request_mem_region failed\n");
206 ret = -EBUSY;
207 goto err1;
208 }
209
210 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
211 if (!hcd->regs) {
212 pr_debug("ioremap failed\n");
213 ret = -ENOMEM;
214 goto err2;
215 }
216
217 au1xxx_start_ohc();
218 ohci_hcd_init(hcd_to_ohci(hcd));
219
220 ret = usb_add_hcd(hcd, pdev->resource[1].start,
221 IRQF_DISABLED | IRQF_SHARED);
222 if (ret == 0) {
223 platform_set_drvdata(pdev, hcd);
224 return ret;
225 }
226
227 au1xxx_stop_ohc();
228 iounmap(hcd->regs);
229err2:
230 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
231err1:
232 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return ret;
234}
235
Russell King3ae5eae2005-11-09 22:32:44 +0000236static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Russell King3ae5eae2005-11-09 22:32:44 +0000238 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Manuel Lauss53c81a32008-06-23 09:08:29 +0200240 usb_remove_hcd(hcd);
241 au1xxx_stop_ohc();
242 iounmap(hcd->regs);
243 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
244 usb_put_hcd(hcd);
245 platform_set_drvdata(pdev, NULL);
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 return 0;
248}
Manuel Lauss53c81a32008-06-23 09:08:29 +0200249
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200250#ifdef CONFIG_PM
Manuel Lauss807fcb52009-07-29 19:13:13 +0200251static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Manuel Lauss807fcb52009-07-29 19:13:13 +0200253 struct usb_hcd *hcd = dev_get_drvdata(dev);
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200254 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
255 unsigned long flags;
256 int rc;
257
258 rc = 0;
259
260 /* Root hub was already suspended. Disable irq emission and
261 * mark HW unaccessible, bail out if RH has been resumed. Use
262 * the spinlock to properly synchronize with possible pending
263 * RH suspend or resume activity.
264 *
265 * This is still racy as hcd->state is manipulated outside of
266 * any locks =P But that will be a different fix.
267 */
268 spin_lock_irqsave(&ohci->lock, flags);
269 if (hcd->state != HC_STATE_SUSPENDED) {
270 rc = -EINVAL;
271 goto bail;
272 }
273 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
274 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
275
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200276 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
277
278 au1xxx_stop_ohc();
279bail:
280 spin_unlock_irqrestore(&ohci->lock, flags);
281
282 return rc;
283}
284
Manuel Lauss807fcb52009-07-29 19:13:13 +0200285static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200286{
Manuel Lauss807fcb52009-07-29 19:13:13 +0200287 struct usb_hcd *hcd = dev_get_drvdata(dev);
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200288
289 au1xxx_start_ohc();
290
291 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
292 ohci_finish_controller_resume(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 return 0;
295}
Manuel Lauss807fcb52009-07-29 19:13:13 +0200296
Alexey Dobriyan47145212009-12-14 18:00:08 -0800297static const struct dev_pm_ops au1xxx_ohci_pmops = {
Manuel Lauss807fcb52009-07-29 19:13:13 +0200298 .suspend = ohci_hcd_au1xxx_drv_suspend,
299 .resume = ohci_hcd_au1xxx_drv_resume,
300};
301
302#define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops
303
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200304#else
Manuel Lauss807fcb52009-07-29 19:13:13 +0200305#define AU1XXX_OHCI_PMOPS NULL
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200306#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Russell King3ae5eae2005-11-09 22:32:44 +0000308static struct platform_driver ohci_hcd_au1xxx_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 .probe = ohci_hcd_au1xxx_drv_probe,
310 .remove = ohci_hcd_au1xxx_drv_remove,
David Brownelldd9048a2006-12-05 03:18:31 -0800311 .shutdown = usb_hcd_platform_shutdown,
Russell King3ae5eae2005-11-09 22:32:44 +0000312 .driver = {
313 .name = "au1xxx-ohci",
314 .owner = THIS_MODULE,
Manuel Lauss807fcb52009-07-29 19:13:13 +0200315 .pm = AU1XXX_OHCI_PMOPS,
Russell King3ae5eae2005-11-09 22:32:44 +0000316 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317};
318
Kay Sieversf4fce612008-04-10 21:29:22 -0700319MODULE_ALIAS("platform:au1xxx-ohci");