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 | |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 44 | #if 0 |
| 45 | static void dump_hci_status(struct usb_hcd *hcd, const char *label) |
| 46 | { |
| 47 | unsigned long status = sa1111_readl(hcd->regs + USB_STATUS); |
| 48 | |
Greg Kroah-Hartman | 3879e30 | 2012-05-01 21:33:39 -0700 | [diff] [blame] | 49 | printk(KERN_DEBUG "%s USB_STATUS = { %s%s%s%s%s}\n", label, |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 50 | ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""), |
| 51 | ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""), |
| 52 | ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "), |
| 53 | ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "), |
| 54 | ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : "")); |
| 55 | } |
| 56 | #endif |
| 57 | |
Russell King | 81e6ca3 | 2012-01-26 11:45:27 +0000 | [diff] [blame] | 58 | static int ohci_sa1111_reset(struct usb_hcd *hcd) |
| 59 | { |
| 60 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 61 | |
| 62 | ohci_hcd_init(ohci); |
| 63 | return ohci_init(ohci); |
| 64 | } |
| 65 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 66 | static int ohci_sa1111_start(struct usb_hcd *hcd) |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 67 | { |
| 68 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 69 | int ret; |
| 70 | |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 71 | ret = ohci_run(ohci); |
| 72 | if (ret < 0) { |
Russell King | 81e6ca3 | 2012-01-26 11:45:27 +0000 | [diff] [blame] | 73 | ohci_err(ohci, "can't start\n"); |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 74 | ohci_stop(hcd); |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 75 | } |
Russell King | 81e6ca3 | 2012-01-26 11:45:27 +0000 | [diff] [blame] | 76 | return ret; |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static const struct hc_driver ohci_sa1111_hc_driver = { |
| 80 | .description = hcd_name, |
| 81 | .product_desc = "SA-1111 OHCI", |
| 82 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 83 | |
| 84 | /* |
| 85 | * generic hardware linkage |
| 86 | */ |
| 87 | .irq = ohci_irq, |
| 88 | .flags = HCD_USB11 | HCD_MEMORY, |
| 89 | |
| 90 | /* |
| 91 | * basic lifecycle operations |
| 92 | */ |
Russell King | 81e6ca3 | 2012-01-26 11:45:27 +0000 | [diff] [blame] | 93 | .reset = ohci_sa1111_reset, |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 94 | .start = ohci_sa1111_start, |
| 95 | .stop = ohci_stop, |
Russell King | 846a704 | 2012-01-26 11:10:20 +0000 | [diff] [blame] | 96 | .shutdown = ohci_shutdown, |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * managing i/o requests and associated device resources |
| 100 | */ |
| 101 | .urb_enqueue = ohci_urb_enqueue, |
| 102 | .urb_dequeue = ohci_urb_dequeue, |
| 103 | .endpoint_disable = ohci_endpoint_disable, |
| 104 | |
| 105 | /* |
| 106 | * scheduling support |
| 107 | */ |
| 108 | .get_frame_number = ohci_get_frame, |
| 109 | |
| 110 | /* |
| 111 | * root hub support |
| 112 | */ |
| 113 | .hub_status_data = ohci_hub_status_data, |
| 114 | .hub_control = ohci_hub_control, |
| 115 | #ifdef CONFIG_PM |
| 116 | .bus_suspend = ohci_bus_suspend, |
| 117 | .bus_resume = ohci_bus_resume, |
| 118 | #endif |
| 119 | .start_port_reset = ohci_start_port_reset, |
| 120 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 122 | static int sa1111_start_hc(struct sa1111_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | unsigned int usb_rst = 0; |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 125 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Russell King | 3f878db | 2012-01-26 10:39:57 +0000 | [diff] [blame] | 127 | dev_dbg(&dev->dev, "starting SA-1111 OHCI USB Controller\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | if (machine_is_xp860() || |
| 130 | machine_has_neponset() || |
| 131 | machine_is_pfs168() || |
| 132 | machine_is_badge4()) |
| 133 | usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW; |
| 134 | |
| 135 | /* |
| 136 | * Configure the power sense and control lines. Place the USB |
| 137 | * host controller in reset. |
| 138 | */ |
| 139 | sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET, |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 140 | dev->mapbase + USB_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * Now, carefully enable the USB clock, and take |
| 144 | * the USB host controller out of reset. |
| 145 | */ |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 146 | ret = sa1111_enable_device(dev); |
| 147 | if (ret == 0) { |
| 148 | udelay(11); |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 149 | sa1111_writel(usb_rst, dev->mapbase + USB_RESET); |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static void sa1111_stop_hc(struct sa1111_dev *dev) |
| 156 | { |
| 157 | unsigned int usb_rst; |
Russell King | 9cb0f81 | 2012-01-26 10:37:46 +0000 | [diff] [blame] | 158 | |
Russell King | 3f878db | 2012-01-26 10:39:57 +0000 | [diff] [blame] | 159 | dev_dbg(&dev->dev, "stopping SA-1111 OHCI USB Controller\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * Put the USB host controller into reset. |
| 163 | */ |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 164 | usb_rst = sa1111_readl(dev->mapbase + USB_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET, |
Russell King | 2213536 | 2012-01-16 11:37:03 +0000 | [diff] [blame] | 166 | dev->mapbase + USB_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | * Stop the USB clock. |
| 170 | */ |
| 171 | sa1111_disable_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | /** |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 175 | * ohci_hcd_sa1111_probe - initialize SA-1111-based HCDs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | * |
| 177 | * Allocates basic resources for this USB host controller, and |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 178 | * then invokes the start() method for the HCD associated with it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | */ |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 180 | static int ohci_hcd_sa1111_probe(struct sa1111_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
| 182 | struct usb_hcd *hcd; |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 183 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 185 | if (usb_disabled()) |
| 186 | return -ENODEV; |
| 187 | |
Russell King | 4ffb431 | 2013-06-27 11:10:40 +0100 | [diff] [blame] | 188 | /* |
| 189 | * We don't call dma_set_mask_and_coherent() here because the |
| 190 | * DMA mask has already been appropraitely setup by the core |
| 191 | * SA-1111 bus code (which includes bug workarounds.) |
| 192 | */ |
| 193 | |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 194 | hcd = usb_create_hcd(&ohci_sa1111_hc_driver, &dev->dev, "sa1111"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if (!hcd) |
| 196 | return -ENOMEM; |
Russell King | 9cb0f81 | 2012-01-26 10:37:46 +0000 | [diff] [blame] | 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | hcd->rsrc_start = dev->res.start; |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 199 | hcd->rsrc_len = resource_size(&dev->res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
Greg Kroah-Hartman | 3879e30 | 2012-05-01 21:33:39 -0700 | [diff] [blame] | 202 | dev_dbg(&dev->dev, "request_mem_region failed\n"); |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 203 | ret = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | goto err1; |
| 205 | } |
Russell King | 9cb0f81 | 2012-01-26 10:37:46 +0000 | [diff] [blame] | 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | hcd->regs = dev->mapbase; |
| 208 | |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 209 | ret = sa1111_start_hc(dev); |
| 210 | if (ret) |
| 211 | goto err2; |
| 212 | |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 213 | ret = usb_add_hcd(hcd, dev->irq[1], 0); |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 214 | if (ret == 0) { |
| 215 | device_wakeup_enable(hcd->self.controller); |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 216 | return ret; |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | sa1111_stop_hc(dev); |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 220 | err2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 222 | err1: |
| 223 | usb_put_hcd(hcd); |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 224 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /** |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 228 | * ohci_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | * @dev: USB Host Controller being removed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | * |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 231 | * Reverses the effect of ohci_hcd_sa1111_probe(), first invoking |
| 232 | * the HCD's stop() method. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | */ |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 234 | static int ohci_hcd_sa1111_remove(struct sa1111_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 236 | struct usb_hcd *hcd = sa1111_get_drvdata(dev); |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | usb_remove_hcd(hcd); |
| 239 | sa1111_stop_hc(dev); |
| 240 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 241 | usb_put_hcd(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | |
Russell King | 846a704 | 2012-01-26 11:10:20 +0000 | [diff] [blame] | 246 | static void ohci_hcd_sa1111_shutdown(struct sa1111_dev *dev) |
| 247 | { |
| 248 | struct usb_hcd *hcd = sa1111_get_drvdata(dev); |
| 249 | |
| 250 | if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { |
| 251 | hcd->driver->shutdown(hcd); |
| 252 | sa1111_stop_hc(dev); |
| 253 | } |
| 254 | } |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | static struct sa1111_driver ohci_hcd_sa1111_driver = { |
| 257 | .drv = { |
| 258 | .name = "sa1111-ohci", |
Russell King | 1ebcd76 | 2012-01-26 11:19:48 +0000 | [diff] [blame] | 259 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | }, |
| 261 | .devid = SA1111_DEVID_USB, |
Russell King | 132db99 | 2012-01-26 10:52:34 +0000 | [diff] [blame] | 262 | .probe = ohci_hcd_sa1111_probe, |
| 263 | .remove = ohci_hcd_sa1111_remove, |
Russell King | 846a704 | 2012-01-26 11:10:20 +0000 | [diff] [blame] | 264 | .shutdown = ohci_hcd_sa1111_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | }; |