Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Uwe Kleine-König | ac310bb | 2008-07-10 17:30:46 -0700 | [diff] [blame] | 11 | * Based on fragments of previous driver by Russell King et al. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
Tim Schmielau | de25968 | 2006-01-08 01:02:05 -0800 | [diff] [blame] | 22 | #include <linux/signal.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/mach-au1x00/au1000.h> |
| 25 | |
Jordan Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 26 | #ifndef CONFIG_SOC_AU1200 |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 37 | #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \ |
| 38 | USBH_ENABLE_BE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #else |
| 40 | #error not byte order defined |
| 41 | #endif |
| 42 | |
Jordan Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 43 | #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 Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 50 | #ifdef CONFIG_DMA_COHERENT |
Jordan Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 51 | #define USB_MCFG_UCAM (1<<7) |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 52 | #else |
| 53 | #define USB_MCFG_UCAM (0) |
| 54 | #endif |
Jordan Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 55 | #define USB_MCFG_OBMEN (1<<1) |
| 56 | #define USB_MCFG_OMEMEN (1<<0) |
| 57 | |
| 58 | #define USBH_ENABLE_CE USB_MCFG_OHCCLKEN |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 59 | |
| 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 Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 65 | #define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN) |
| 66 | |
| 67 | #endif /* Au1200 */ |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | extern int usb_disabled(void); |
| 70 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 71 | static void au1xxx_start_ohc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* enable host controller */ |
Jordan Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 74 | #ifndef CONFIG_SOC_AU1200 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 76 | au_sync(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | udelay(1000); |
| 78 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 79 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG); |
| 80 | au_sync(); |
Jordan Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 81 | udelay(1000); |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* 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 Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 88 | #else /* Au1200 */ |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 89 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG); |
| 90 | au_sync(); |
Jordan Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 91 | udelay(1000); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 92 | |
| 93 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG); |
| 94 | au_sync(); |
| 95 | udelay(2000); |
Jordan Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 96 | #endif /* Au1200 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 99 | static void au1xxx_stop_ohc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 101 | #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 Crouse | d5fb7f1 | 2006-01-20 14:09:54 -0800 | [diff] [blame] | 106 | #endif |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 107 | /* Disable clock */ |
| 108 | au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG); |
| 109 | au_sync(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 112 | static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 114 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 115 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 117 | ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 119 | if ((ret = ohci_init(ohci)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | return ret; |
| 121 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 122 | if ((ret = ohci_run(ohci)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | err ("can't start %s", hcd->self.bus_name); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 124 | ohci_stop(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | .stop = ohci_stop, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 147 | .shutdown = ohci_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 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, |
Linus Torvalds | 09ca8ad | 2008-07-06 10:27:25 -0700 | [diff] [blame] | 166 | .hub_irq_enable = ohci_rhsc_enable, |
David Brownell | 9293677 | 2005-09-22 22:32:11 -0700 | [diff] [blame] | 167 | #ifdef CONFIG_PM |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 168 | .bus_suspend = ohci_bus_suspend, |
| 169 | .bus_resume = ohci_bus_resume, |
David Brownell | 9293677 | 2005-09-22 22:32:11 -0700 | [diff] [blame] | 170 | #endif |
| 171 | .start_port_reset = ohci_start_port_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 174 | static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | int ret; |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 177 | struct usb_hcd *hcd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | if (usb_disabled()) |
| 180 | return -ENODEV; |
| 181 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 182 | #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) |
| 183 | /* Au1200 AB USB does not support coherent memory */ |
| 184 | if (!(read_c0_prid() & 0xff)) { |
| 185 | printk(KERN_INFO "%s: this is chip revision AB !!\n", |
| 186 | pdev->name); |
| 187 | printk(KERN_INFO "%s: update your board or re-configure " |
| 188 | "the kernel\n", pdev->name); |
| 189 | return -ENODEV; |
| 190 | } |
| 191 | #endif |
| 192 | |
| 193 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 194 | pr_debug("resource[1] is not IORESOURCE_IRQ\n"); |
| 195 | return -ENOMEM; |
| 196 | } |
| 197 | |
| 198 | hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx"); |
| 199 | if (!hcd) |
| 200 | return -ENOMEM; |
| 201 | |
| 202 | hcd->rsrc_start = pdev->resource[0].start; |
| 203 | hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; |
| 204 | |
| 205 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 206 | pr_debug("request_mem_region failed\n"); |
| 207 | ret = -EBUSY; |
| 208 | goto err1; |
| 209 | } |
| 210 | |
| 211 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 212 | if (!hcd->regs) { |
| 213 | pr_debug("ioremap failed\n"); |
| 214 | ret = -ENOMEM; |
| 215 | goto err2; |
| 216 | } |
| 217 | |
| 218 | au1xxx_start_ohc(); |
| 219 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 220 | |
| 221 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
| 222 | IRQF_DISABLED | IRQF_SHARED); |
| 223 | if (ret == 0) { |
| 224 | platform_set_drvdata(pdev, hcd); |
| 225 | return ret; |
| 226 | } |
| 227 | |
| 228 | au1xxx_stop_ohc(); |
| 229 | iounmap(hcd->regs); |
| 230 | err2: |
| 231 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 232 | err1: |
| 233 | usb_put_hcd(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return ret; |
| 235 | } |
| 236 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 237 | static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 239 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 241 | usb_remove_hcd(hcd); |
| 242 | au1xxx_stop_ohc(); |
| 243 | iounmap(hcd->regs); |
| 244 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 245 | usb_put_hcd(hcd); |
| 246 | platform_set_drvdata(pdev, NULL); |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | return 0; |
| 249 | } |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 250 | |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 251 | #ifdef CONFIG_PM |
| 252 | static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *pdev, |
| 253 | pm_message_t message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 255 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 256 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 257 | unsigned long flags; |
| 258 | int rc; |
| 259 | |
| 260 | rc = 0; |
| 261 | |
| 262 | /* Root hub was already suspended. Disable irq emission and |
| 263 | * mark HW unaccessible, bail out if RH has been resumed. Use |
| 264 | * the spinlock to properly synchronize with possible pending |
| 265 | * RH suspend or resume activity. |
| 266 | * |
| 267 | * This is still racy as hcd->state is manipulated outside of |
| 268 | * any locks =P But that will be a different fix. |
| 269 | */ |
| 270 | spin_lock_irqsave(&ohci->lock, flags); |
| 271 | if (hcd->state != HC_STATE_SUSPENDED) { |
| 272 | rc = -EINVAL; |
| 273 | goto bail; |
| 274 | } |
| 275 | ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
| 276 | (void)ohci_readl(ohci, &ohci->regs->intrdisable); |
| 277 | |
| 278 | /* make sure snapshot being resumed re-enumerates everything */ |
| 279 | if (message.event == PM_EVENT_PRETHAW) |
| 280 | ohci_usb_reset(ohci); |
| 281 | |
| 282 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 283 | |
| 284 | au1xxx_stop_ohc(); |
| 285 | bail: |
| 286 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 287 | |
| 288 | return rc; |
| 289 | } |
| 290 | |
| 291 | static int ohci_hcd_au1xxx_drv_resume(struct platform_device *pdev) |
| 292 | { |
| 293 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 294 | |
| 295 | au1xxx_start_ohc(); |
| 296 | |
| 297 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 298 | ohci_finish_controller_resume(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | return 0; |
| 301 | } |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 302 | #else |
| 303 | #define ohci_hcd_au1xxx_drv_suspend NULL |
| 304 | #define ohci_hcd_au1xxx_drv_resume NULL |
| 305 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 307 | static struct platform_driver ohci_hcd_au1xxx_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | .probe = ohci_hcd_au1xxx_drv_probe, |
| 309 | .remove = ohci_hcd_au1xxx_drv_remove, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 310 | .shutdown = usb_hcd_platform_shutdown, |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 311 | .suspend = ohci_hcd_au1xxx_drv_suspend, |
| 312 | .resume = ohci_hcd_au1xxx_drv_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 313 | .driver = { |
| 314 | .name = "au1xxx-ohci", |
| 315 | .owner = THIS_MODULE, |
| 316 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | }; |
| 318 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 319 | MODULE_ALIAS("platform:au1xxx-ohci"); |