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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | extern int usb_disabled(void); |
| 28 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 29 | static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 31 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 32 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 34 | ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 36 | if ((ret = ohci_init(ohci)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | return ret; |
| 38 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 39 | if ((ret = ohci_run(ohci)) < 0) { |
Paul Gortmaker | 3b1f1ad | 2012-05-01 17:39:11 -0400 | [diff] [blame] | 40 | dev_err(hcd->self.controller, "can't start %s", |
| 41 | hcd->self.bus_name); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 42 | ohci_stop(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | static const struct hc_driver ohci_au1xxx_hc_driver = { |
| 50 | .description = hcd_name, |
| 51 | .product_desc = "Au1xxx OHCI", |
| 52 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 53 | |
| 54 | /* |
| 55 | * generic hardware linkage |
| 56 | */ |
| 57 | .irq = ohci_irq, |
| 58 | .flags = HCD_USB11 | HCD_MEMORY, |
| 59 | |
| 60 | /* |
| 61 | * basic lifecycle operations |
| 62 | */ |
| 63 | .start = ohci_au1xxx_start, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | .stop = ohci_stop, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 65 | .shutdown = ohci_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * managing i/o requests and associated device resources |
| 69 | */ |
| 70 | .urb_enqueue = ohci_urb_enqueue, |
| 71 | .urb_dequeue = ohci_urb_dequeue, |
| 72 | .endpoint_disable = ohci_endpoint_disable, |
| 73 | |
| 74 | /* |
| 75 | * scheduling support |
| 76 | */ |
| 77 | .get_frame_number = ohci_get_frame, |
| 78 | |
| 79 | /* |
| 80 | * root hub support |
| 81 | */ |
| 82 | .hub_status_data = ohci_hub_status_data, |
| 83 | .hub_control = ohci_hub_control, |
David Brownell | 9293677 | 2005-09-22 22:32:11 -0700 | [diff] [blame] | 84 | #ifdef CONFIG_PM |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 85 | .bus_suspend = ohci_bus_suspend, |
| 86 | .bus_resume = ohci_bus_resume, |
David Brownell | 9293677 | 2005-09-22 22:32:11 -0700 | [diff] [blame] | 87 | #endif |
| 88 | .start_port_reset = ohci_start_port_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 91 | static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 93 | int ret, unit; |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 94 | struct usb_hcd *hcd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | if (usb_disabled()) |
| 97 | return -ENODEV; |
| 98 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 99 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 100 | pr_debug("resource[1] is not IORESOURCE_IRQ\n"); |
| 101 | return -ENOMEM; |
| 102 | } |
| 103 | |
| 104 | hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx"); |
| 105 | if (!hcd) |
| 106 | return -ENOMEM; |
| 107 | |
| 108 | hcd->rsrc_start = pdev->resource[0].start; |
| 109 | hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; |
| 110 | |
| 111 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 112 | pr_debug("request_mem_region failed\n"); |
| 113 | ret = -EBUSY; |
| 114 | goto err1; |
| 115 | } |
| 116 | |
| 117 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 118 | if (!hcd->regs) { |
| 119 | pr_debug("ioremap failed\n"); |
| 120 | ret = -ENOMEM; |
| 121 | goto err2; |
| 122 | } |
| 123 | |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 124 | unit = (hcd->rsrc_start == AU1300_USB_OHCI1_PHYS_ADDR) ? |
| 125 | ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0; |
| 126 | if (alchemy_usb_control(unit, 1)) { |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 127 | printk(KERN_INFO "%s: controller init failed!\n", pdev->name); |
| 128 | ret = -ENODEV; |
| 129 | goto err3; |
| 130 | } |
| 131 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 132 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 133 | |
| 134 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 135 | IRQF_SHARED); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 136 | if (ret == 0) { |
| 137 | platform_set_drvdata(pdev, hcd); |
| 138 | return ret; |
| 139 | } |
| 140 | |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 141 | alchemy_usb_control(unit, 0); |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 142 | err3: |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 143 | iounmap(hcd->regs); |
| 144 | err2: |
| 145 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 146 | err1: |
| 147 | usb_put_hcd(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | return ret; |
| 149 | } |
| 150 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 151 | static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 153 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 154 | int unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 156 | unit = (hcd->rsrc_start == AU1300_USB_OHCI1_PHYS_ADDR) ? |
| 157 | ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0; |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 158 | usb_remove_hcd(hcd); |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 159 | alchemy_usb_control(unit, 0); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 160 | iounmap(hcd->regs); |
| 161 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 162 | usb_put_hcd(hcd); |
| 163 | platform_set_drvdata(pdev, NULL); |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | return 0; |
| 166 | } |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 167 | |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 168 | #ifdef CONFIG_PM |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 169 | static int ohci_hcd_au1xxx_drv_suspend(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 171 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 172 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 173 | unsigned long flags; |
| 174 | int rc; |
| 175 | |
| 176 | rc = 0; |
| 177 | |
| 178 | /* Root hub was already suspended. Disable irq emission and |
| 179 | * mark HW unaccessible, bail out if RH has been resumed. Use |
| 180 | * the spinlock to properly synchronize with possible pending |
| 181 | * RH suspend or resume activity. |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 182 | */ |
| 183 | spin_lock_irqsave(&ohci->lock, flags); |
Alan Stern | b7463c7 | 2011-11-17 16:41:56 -0500 | [diff] [blame] | 184 | if (ohci->rh_state != OHCI_RH_SUSPENDED) { |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 185 | rc = -EINVAL; |
| 186 | goto bail; |
| 187 | } |
| 188 | ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
| 189 | (void)ohci_readl(ohci, &ohci->regs->intrdisable); |
| 190 | |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 191 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 192 | |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 193 | alchemy_usb_control(ALCHEMY_USB_OHCI0, 0); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 194 | bail: |
| 195 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 196 | |
| 197 | return rc; |
| 198 | } |
| 199 | |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 200 | static int ohci_hcd_au1xxx_drv_resume(struct device *dev) |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 201 | { |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 202 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 203 | |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 204 | alchemy_usb_control(ALCHEMY_USB_OHCI0, 1); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 205 | |
| 206 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 207 | ohci_finish_controller_resume(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | return 0; |
| 210 | } |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 211 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 212 | static const struct dev_pm_ops au1xxx_ohci_pmops = { |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 213 | .suspend = ohci_hcd_au1xxx_drv_suspend, |
| 214 | .resume = ohci_hcd_au1xxx_drv_resume, |
| 215 | }; |
| 216 | |
| 217 | #define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops |
| 218 | |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 219 | #else |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 220 | #define AU1XXX_OHCI_PMOPS NULL |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 221 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 223 | static struct platform_driver ohci_hcd_au1xxx_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | .probe = ohci_hcd_au1xxx_drv_probe, |
| 225 | .remove = ohci_hcd_au1xxx_drv_remove, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 226 | .shutdown = usb_hcd_platform_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 227 | .driver = { |
| 228 | .name = "au1xxx-ohci", |
| 229 | .owner = THIS_MODULE, |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 230 | .pm = AU1XXX_OHCI_PMOPS, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 231 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | }; |
| 233 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 234 | MODULE_ALIAS("platform:au1xxx-ohci"); |