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