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 |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * SA1111 Bus Glue |
| 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 | * This file is licenced under the GPL. |
| 14 | */ |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 15 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 16 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/mach-types.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 18 | #include <mach/assabet.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/hardware/sa1111.h> |
| 20 | |
| 21 | #ifndef CONFIG_SA1111 |
| 22 | #error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined." |
| 23 | #endif |
| 24 | |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 25 | #define USB_STATUS 0x0118 |
| 26 | #define USB_RESET 0x011c |
| 27 | #define USB_IRQTEST 0x0120 |
| 28 | |
| 29 | #define USB_RESET_FORCEIFRESET (1 << 0) |
| 30 | #define USB_RESET_FORCEHCRESET (1 << 1) |
| 31 | #define USB_RESET_CLKGENRESET (1 << 2) |
| 32 | #define USB_RESET_SIMSCALEDOWN (1 << 3) |
| 33 | #define USB_RESET_USBINTTEST (1 << 4) |
| 34 | #define USB_RESET_SLEEPSTBYEN (1 << 5) |
| 35 | #define USB_RESET_PWRSENSELOW (1 << 6) |
| 36 | #define USB_RESET_PWRCTRLLOW (1 << 7) |
| 37 | |
| 38 | #define USB_STATUS_IRQHCIRMTWKUP (1 << 7) |
| 39 | #define USB_STATUS_IRQHCIBUFFACC (1 << 8) |
| 40 | #define USB_STATUS_NIRQHCIM (1 << 9) |
| 41 | #define USB_STATUS_NHCIMFCLR (1 << 10) |
| 42 | #define USB_STATUS_USBPWRSENSE (1 << 11) |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | extern int usb_disabled(void); |
| 45 | |
| 46 | /*-------------------------------------------------------------------------*/ |
| 47 | |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 48 | static int sa1111_start_hc(struct sa1111_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | unsigned int usb_rst = 0; |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 51 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Joe Perches | f45ba77 | 2010-02-05 17:51:13 -0800 | [diff] [blame] | 53 | printk(KERN_DEBUG "%s: starting SA-1111 OHCI USB Controller\n", |
| 54 | __FILE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | if (machine_is_xp860() || |
| 57 | machine_has_neponset() || |
| 58 | machine_is_pfs168() || |
| 59 | machine_is_badge4()) |
| 60 | usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW; |
| 61 | |
| 62 | /* |
| 63 | * Configure the power sense and control lines. Place the USB |
| 64 | * host controller in reset. |
| 65 | */ |
| 66 | sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET, |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 67 | dev->mapbase + USB_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Now, carefully enable the USB clock, and take |
| 71 | * the USB host controller out of reset. |
| 72 | */ |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 73 | ret = sa1111_enable_device(dev); |
| 74 | if (ret == 0) { |
| 75 | udelay(11); |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 76 | sa1111_writel(usb_rst, dev->mapbase + USB_RESET); |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void sa1111_stop_hc(struct sa1111_dev *dev) |
| 83 | { |
| 84 | unsigned int usb_rst; |
Joe Perches | f45ba77 | 2010-02-05 17:51:13 -0800 | [diff] [blame] | 85 | printk(KERN_DEBUG "%s: stopping SA-1111 OHCI USB Controller\n", |
| 86 | __FILE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Put the USB host controller into reset. |
| 90 | */ |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 91 | usb_rst = sa1111_readl(dev->mapbase + USB_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET, |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 93 | dev->mapbase + USB_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Stop the USB clock. |
| 97 | */ |
| 98 | sa1111_disable_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
| 102 | /*-------------------------------------------------------------------------*/ |
| 103 | |
| 104 | #if 0 |
| 105 | static void dump_hci_status(struct usb_hcd *hcd, const char *label) |
| 106 | { |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 107 | unsigned long status = sa1111_readl(hcd->regs + USB_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | dbg ("%s USB_STATUS = { %s%s%s%s%s}", label, |
| 110 | ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""), |
| 111 | ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""), |
| 112 | ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "), |
| 113 | ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "), |
| 114 | ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : "")); |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | /*-------------------------------------------------------------------------*/ |
| 119 | |
| 120 | /* configure so an HC device and id are always provided */ |
| 121 | /* always called with process context; sleeping is OK */ |
| 122 | |
| 123 | |
| 124 | /** |
| 125 | * usb_hcd_sa1111_probe - initialize SA-1111-based HCDs |
| 126 | * Context: !in_interrupt() |
| 127 | * |
| 128 | * Allocates basic resources for this USB host controller, and |
| 129 | * then invokes the start() method for the HCD associated with it |
| 130 | * through the hotplug entry's driver_data. |
| 131 | * |
| 132 | * Store this function in the HCD's struct pci_driver as probe(). |
| 133 | */ |
| 134 | int usb_hcd_sa1111_probe (const struct hc_driver *driver, |
| 135 | struct sa1111_dev *dev) |
| 136 | { |
| 137 | struct usb_hcd *hcd; |
| 138 | int retval; |
| 139 | |
| 140 | hcd = usb_create_hcd (driver, &dev->dev, "sa1111"); |
| 141 | if (!hcd) |
| 142 | return -ENOMEM; |
| 143 | hcd->rsrc_start = dev->res.start; |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 144 | hcd->rsrc_len = resource_size(&dev->res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 147 | dbg("request_mem_region failed"); |
| 148 | retval = -EBUSY; |
| 149 | goto err1; |
| 150 | } |
| 151 | hcd->regs = dev->mapbase; |
| 152 | |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 153 | ret = sa1111_start_hc(dev); |
| 154 | if (ret) |
| 155 | goto err2; |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 158 | |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 159 | retval = usb_add_hcd(hcd, dev->irq[1], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (retval == 0) |
| 161 | return retval; |
| 162 | |
| 163 | sa1111_stop_hc(dev); |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 164 | err2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 166 | err1: |
| 167 | usb_put_hcd(hcd); |
| 168 | return retval; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /* may be called without controller electrically present */ |
| 173 | /* may be called with controller, bus, and devices active */ |
| 174 | |
| 175 | /** |
| 176 | * usb_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs |
| 177 | * @dev: USB Host Controller being removed |
| 178 | * Context: !in_interrupt() |
| 179 | * |
| 180 | * Reverses the effect of usb_hcd_sa1111_probe(), first invoking |
| 181 | * the HCD's stop() method. It is always called from a thread |
| 182 | * context, normally "rmmod", "apmd", or something similar. |
| 183 | * |
| 184 | */ |
| 185 | void usb_hcd_sa1111_remove (struct usb_hcd *hcd, struct sa1111_dev *dev) |
| 186 | { |
| 187 | usb_remove_hcd(hcd); |
| 188 | sa1111_stop_hc(dev); |
| 189 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 190 | usb_put_hcd(hcd); |
| 191 | } |
| 192 | |
| 193 | /*-------------------------------------------------------------------------*/ |
| 194 | |
| 195 | static int __devinit |
| 196 | ohci_sa1111_start (struct usb_hcd *hcd) |
| 197 | { |
| 198 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 199 | int ret; |
| 200 | |
| 201 | if ((ret = ohci_init(ohci)) < 0) |
| 202 | return ret; |
| 203 | |
| 204 | if ((ret = ohci_run (ohci)) < 0) { |
| 205 | err ("can't start %s", hcd->self.bus_name); |
| 206 | ohci_stop (hcd); |
| 207 | return ret; |
| 208 | } |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | /*-------------------------------------------------------------------------*/ |
| 213 | |
| 214 | static const struct hc_driver ohci_sa1111_hc_driver = { |
| 215 | .description = hcd_name, |
| 216 | .product_desc = "SA-1111 OHCI", |
| 217 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 218 | |
| 219 | /* |
| 220 | * generic hardware linkage |
| 221 | */ |
| 222 | .irq = ohci_irq, |
| 223 | .flags = HCD_USB11 | HCD_MEMORY, |
| 224 | |
| 225 | /* |
| 226 | * basic lifecycle operations |
| 227 | */ |
| 228 | .start = ohci_sa1111_start, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | .stop = ohci_stop, |
| 230 | |
| 231 | /* |
| 232 | * managing i/o requests and associated device resources |
| 233 | */ |
| 234 | .urb_enqueue = ohci_urb_enqueue, |
| 235 | .urb_dequeue = ohci_urb_dequeue, |
| 236 | .endpoint_disable = ohci_endpoint_disable, |
| 237 | |
| 238 | /* |
| 239 | * scheduling support |
| 240 | */ |
| 241 | .get_frame_number = ohci_get_frame, |
| 242 | |
| 243 | /* |
| 244 | * root hub support |
| 245 | */ |
| 246 | .hub_status_data = ohci_hub_status_data, |
| 247 | .hub_control = ohci_hub_control, |
David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 248 | #ifdef CONFIG_PM |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 249 | .bus_suspend = ohci_bus_suspend, |
| 250 | .bus_resume = ohci_bus_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | #endif |
David Brownell | 9293677 | 2005-09-22 22:32:11 -0700 | [diff] [blame] | 252 | .start_port_reset = ohci_start_port_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | /*-------------------------------------------------------------------------*/ |
| 256 | |
| 257 | static int ohci_hcd_sa1111_drv_probe(struct sa1111_dev *dev) |
| 258 | { |
| 259 | int ret; |
| 260 | |
| 261 | if (usb_disabled()) |
| 262 | return -ENODEV; |
| 263 | |
| 264 | ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, dev); |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | static int ohci_hcd_sa1111_drv_remove(struct sa1111_dev *dev) |
| 269 | { |
| 270 | struct usb_hcd *hcd = sa1111_get_drvdata(dev); |
| 271 | |
| 272 | usb_hcd_sa1111_remove(hcd, dev); |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static struct sa1111_driver ohci_hcd_sa1111_driver = { |
| 277 | .drv = { |
| 278 | .name = "sa1111-ohci", |
Russell King | 1ebcd76 | 2012-01-26 11:19:48 +0000 | [diff] [blame] | 279 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | }, |
| 281 | .devid = SA1111_DEVID_USB, |
| 282 | .probe = ohci_hcd_sa1111_drv_probe, |
| 283 | .remove = ohci_hcd_sa1111_drv_remove, |
| 284 | }; |
| 285 | |