Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * OHCI HCD (Host Controller Driver) for USB. |
| 3 | * |
| 4 | * Copyright (C) 2004 SAN People (Pty) Ltd. |
| 5 | * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org> |
| 6 | * |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 7 | * AT91 Bus Glue |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 8 | * |
| 9 | * Based on fragments of 2.4 driver by Rick Bronson. |
| 10 | * Based on ohci-omap.c |
| 11 | * |
| 12 | * This file is licenced under the GPL. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/clk.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 18 | #include <mach/hardware.h> |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 19 | #include <asm/gpio.h> |
| 20 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 21 | #include <mach/board.h> |
| 22 | #include <mach/cpu.h> |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 23 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 24 | #ifndef CONFIG_ARCH_AT91 |
| 25 | #error "CONFIG_ARCH_AT91 must be defined." |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 26 | #endif |
| 27 | |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 28 | /* interface and function clocks; sometimes also an AHB clock */ |
| 29 | static struct clk *iclk, *fclk, *hclk; |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 30 | static int clocked; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 31 | |
| 32 | extern int usb_disabled(void); |
| 33 | |
| 34 | /*-------------------------------------------------------------------------*/ |
| 35 | |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 36 | static void at91_start_clock(void) |
| 37 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0af4316 | 2011-08-30 03:29:28 +0200 | [diff] [blame] | 38 | clk_enable(hclk); |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 39 | clk_enable(iclk); |
| 40 | clk_enable(fclk); |
| 41 | clocked = 1; |
| 42 | } |
| 43 | |
| 44 | static void at91_stop_clock(void) |
| 45 | { |
| 46 | clk_disable(fclk); |
| 47 | clk_disable(iclk); |
Jean-Christophe PLAGNIOL-VILLARD | 0af4316 | 2011-08-30 03:29:28 +0200 | [diff] [blame] | 48 | clk_disable(hclk); |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 49 | clocked = 0; |
| 50 | } |
| 51 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 52 | static void at91_start_hc(struct platform_device *pdev) |
| 53 | { |
| 54 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 55 | struct ohci_regs __iomem *regs = hcd->regs; |
| 56 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 57 | dev_dbg(&pdev->dev, "start\n"); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Start the USB clocks. |
| 61 | */ |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 62 | at91_start_clock(); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * The USB host controller must remain in reset. |
| 66 | */ |
| 67 | writel(0, ®s->control); |
| 68 | } |
| 69 | |
| 70 | static void at91_stop_hc(struct platform_device *pdev) |
| 71 | { |
| 72 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 73 | struct ohci_regs __iomem *regs = hcd->regs; |
| 74 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 75 | dev_dbg(&pdev->dev, "stop\n"); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Put the USB host controller into reset. |
| 79 | */ |
| 80 | writel(0, ®s->control); |
| 81 | |
| 82 | /* |
| 83 | * Stop the USB clocks. |
| 84 | */ |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 85 | at91_stop_clock(); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
| 89 | /*-------------------------------------------------------------------------*/ |
| 90 | |
Pete Zaitcev | 421b4bf | 2008-06-01 14:38:43 -0700 | [diff] [blame] | 91 | static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 92 | |
| 93 | /* configure so an HC device and id are always provided */ |
| 94 | /* always called with process context; sleeping is OK */ |
| 95 | |
| 96 | |
| 97 | /** |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 98 | * usb_hcd_at91_probe - initialize AT91-based HCDs |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 99 | * Context: !in_interrupt() |
| 100 | * |
| 101 | * Allocates basic resources for this USB host controller, and |
| 102 | * then invokes the start() method for the HCD associated with it |
| 103 | * through the hotplug entry's driver_data. |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 104 | */ |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 105 | static int usb_hcd_at91_probe(const struct hc_driver *driver, |
| 106 | struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 107 | { |
| 108 | int retval; |
| 109 | struct usb_hcd *hcd = NULL; |
| 110 | |
| 111 | if (pdev->num_resources != 2) { |
| 112 | pr_debug("hcd probe: invalid num_resources"); |
| 113 | return -ENODEV; |
| 114 | } |
| 115 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 116 | if ((pdev->resource[0].flags != IORESOURCE_MEM) |
| 117 | || (pdev->resource[1].flags != IORESOURCE_IRQ)) { |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 118 | pr_debug("hcd probe: invalid resource type\n"); |
| 119 | return -ENODEV; |
| 120 | } |
| 121 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 122 | hcd = usb_create_hcd(driver, &pdev->dev, "at91"); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 123 | if (!hcd) |
| 124 | return -ENOMEM; |
| 125 | hcd->rsrc_start = pdev->resource[0].start; |
| 126 | hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; |
| 127 | |
| 128 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 129 | pr_debug("request_mem_region failed\n"); |
| 130 | retval = -EBUSY; |
| 131 | goto err1; |
| 132 | } |
| 133 | |
| 134 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 135 | if (!hcd->regs) { |
| 136 | pr_debug("ioremap failed\n"); |
| 137 | retval = -EIO; |
| 138 | goto err2; |
| 139 | } |
| 140 | |
| 141 | iclk = clk_get(&pdev->dev, "ohci_clk"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 142 | if (IS_ERR(iclk)) { |
| 143 | dev_err(&pdev->dev, "failed to get ohci_clk\n"); |
| 144 | retval = PTR_ERR(iclk); |
| 145 | goto err3; |
| 146 | } |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 147 | fclk = clk_get(&pdev->dev, "uhpck"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 148 | if (IS_ERR(fclk)) { |
| 149 | dev_err(&pdev->dev, "failed to get uhpck\n"); |
| 150 | retval = PTR_ERR(fclk); |
| 151 | goto err4; |
| 152 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0af4316 | 2011-08-30 03:29:28 +0200 | [diff] [blame] | 153 | hclk = clk_get(&pdev->dev, "hclk"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 154 | if (IS_ERR(hclk)) { |
| 155 | dev_err(&pdev->dev, "failed to get hclk\n"); |
| 156 | retval = PTR_ERR(hclk); |
| 157 | goto err5; |
| 158 | } |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 159 | |
| 160 | at91_start_hc(pdev); |
| 161 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 162 | |
Nicolas Ferre | 2f2cac3 | 2009-07-27 14:59:24 -0700 | [diff] [blame] | 163 | retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 164 | if (retval == 0) |
| 165 | return retval; |
| 166 | |
| 167 | /* Error handling */ |
| 168 | at91_stop_hc(pdev); |
| 169 | |
Jean-Christophe PLAGNIOL-VILLARD | 0af4316 | 2011-08-30 03:29:28 +0200 | [diff] [blame] | 170 | clk_put(hclk); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 171 | err5: |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 172 | clk_put(fclk); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 173 | err4: |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 174 | clk_put(iclk); |
| 175 | |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 176 | err3: |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 177 | iounmap(hcd->regs); |
| 178 | |
| 179 | err2: |
| 180 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 181 | |
| 182 | err1: |
| 183 | usb_put_hcd(hcd); |
| 184 | return retval; |
| 185 | } |
| 186 | |
| 187 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 188 | /* may be called with controller, bus, and devices active */ |
| 189 | |
| 190 | /** |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 191 | * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 192 | * @dev: USB Host Controller being removed |
| 193 | * Context: !in_interrupt() |
| 194 | * |
| 195 | * Reverses the effect of usb_hcd_at91_probe(), first invoking |
| 196 | * the HCD's stop() method. It is always called from a thread |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 197 | * context, "rmmod" or something similar. |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 198 | * |
| 199 | */ |
Pete Zaitcev | 421b4bf | 2008-06-01 14:38:43 -0700 | [diff] [blame] | 200 | static void usb_hcd_at91_remove(struct usb_hcd *hcd, |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 201 | struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 202 | { |
| 203 | usb_remove_hcd(hcd); |
| 204 | at91_stop_hc(pdev); |
| 205 | iounmap(hcd->regs); |
David Brownell | 68ba61b | 2006-04-02 20:26:21 -0800 | [diff] [blame] | 206 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
Pete Zaitcev | 421b4bf | 2008-06-01 14:38:43 -0700 | [diff] [blame] | 207 | usb_put_hcd(hcd); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 208 | |
Jean-Christophe PLAGNIOL-VILLARD | 0af4316 | 2011-08-30 03:29:28 +0200 | [diff] [blame] | 209 | clk_put(hclk); |
David Brownell | 68ba61b | 2006-04-02 20:26:21 -0800 | [diff] [blame] | 210 | clk_put(fclk); |
| 211 | clk_put(iclk); |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 212 | fclk = iclk = hclk = NULL; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 213 | |
| 214 | dev_set_drvdata(&pdev->dev, NULL); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /*-------------------------------------------------------------------------*/ |
| 218 | |
| 219 | static int __devinit |
| 220 | ohci_at91_start (struct usb_hcd *hcd) |
| 221 | { |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 222 | struct at91_usbh_data *board = hcd->self.controller->platform_data; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 223 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 224 | int ret; |
| 225 | |
| 226 | if ((ret = ohci_init(ohci)) < 0) |
| 227 | return ret; |
| 228 | |
David Brownell | cd22afd | 2006-09-03 12:21:50 -0700 | [diff] [blame] | 229 | ohci->num_ports = board->ports; |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 230 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 231 | if ((ret = ohci_run(ohci)) < 0) { |
| 232 | err("can't start %s", hcd->self.bus_name); |
| 233 | ohci_stop(hcd); |
| 234 | return ret; |
| 235 | } |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 236 | return 0; |
| 237 | } |
| 238 | |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 239 | static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) |
| 240 | { |
| 241 | if (port < 0 || port >= 2) |
| 242 | return; |
| 243 | |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 244 | if (!gpio_is_valid(pdata->vbus_pin[port])) |
Jean-Christophe PLAGNIOL-VILLARD | 770f0ba | 2011-11-12 16:46:13 +0100 | [diff] [blame] | 245 | return; |
| 246 | |
Jean-Christophe PLAGNIOL-VILLARD | 8134ff5 | 2011-12-08 16:32:01 +0100 | [diff] [blame^] | 247 | gpio_set_value(pdata->vbus_pin[port], |
| 248 | !pdata->vbus_pin_active_low[port] ^ enable); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) |
| 252 | { |
| 253 | if (port < 0 || port >= 2) |
| 254 | return -EINVAL; |
| 255 | |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 256 | if (!gpio_is_valid(pdata->vbus_pin[port])) |
Jean-Christophe PLAGNIOL-VILLARD | 770f0ba | 2011-11-12 16:46:13 +0100 | [diff] [blame] | 257 | return -EINVAL; |
| 258 | |
Jean-Christophe PLAGNIOL-VILLARD | 8134ff5 | 2011-12-08 16:32:01 +0100 | [diff] [blame^] | 259 | return gpio_get_value(pdata->vbus_pin[port]) ^ |
| 260 | !pdata->vbus_pin_active_low[port]; |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* |
| 264 | * Update the status data from the hub with the over-current indicator change. |
| 265 | */ |
| 266 | static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 267 | { |
| 268 | struct at91_usbh_data *pdata = hcd->self.controller->platform_data; |
| 269 | int length = ohci_hub_status_data(hcd, buf); |
| 270 | int port; |
| 271 | |
| 272 | for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) { |
| 273 | if (pdata->overcurrent_changed[port]) { |
| 274 | if (! length) |
| 275 | length = 1; |
| 276 | buf[0] |= 1 << (port + 1); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | return length; |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * Look at the control requests to the root hub and see if we need to override. |
| 285 | */ |
| 286 | static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
| 287 | u16 wIndex, char *buf, u16 wLength) |
| 288 | { |
| 289 | struct at91_usbh_data *pdata = hcd->self.controller->platform_data; |
| 290 | struct usb_hub_descriptor *desc; |
| 291 | int ret = -EINVAL; |
| 292 | u32 *data = (u32 *)buf; |
| 293 | |
| 294 | dev_dbg(hcd->self.controller, |
| 295 | "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", |
| 296 | hcd, typeReq, wValue, wIndex, buf, wLength); |
| 297 | |
| 298 | switch (typeReq) { |
| 299 | case SetPortFeature: |
| 300 | if (wValue == USB_PORT_FEAT_POWER) { |
| 301 | dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); |
| 302 | ohci_at91_usb_set_power(pdata, wIndex - 1, 1); |
| 303 | goto out; |
| 304 | } |
| 305 | break; |
| 306 | |
| 307 | case ClearPortFeature: |
| 308 | switch (wValue) { |
| 309 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 310 | dev_dbg(hcd->self.controller, |
| 311 | "ClearPortFeature: C_OVER_CURRENT\n"); |
| 312 | |
| 313 | if (wIndex == 1 || wIndex == 2) { |
| 314 | pdata->overcurrent_changed[wIndex-1] = 0; |
| 315 | pdata->overcurrent_status[wIndex-1] = 0; |
| 316 | } |
| 317 | |
| 318 | goto out; |
| 319 | |
| 320 | case USB_PORT_FEAT_OVER_CURRENT: |
| 321 | dev_dbg(hcd->self.controller, |
| 322 | "ClearPortFeature: OVER_CURRENT\n"); |
| 323 | |
| 324 | if (wIndex == 1 || wIndex == 2) { |
| 325 | pdata->overcurrent_status[wIndex-1] = 0; |
| 326 | } |
| 327 | |
| 328 | goto out; |
| 329 | |
| 330 | case USB_PORT_FEAT_POWER: |
| 331 | dev_dbg(hcd->self.controller, |
| 332 | "ClearPortFeature: POWER\n"); |
| 333 | |
| 334 | if (wIndex == 1 || wIndex == 2) { |
| 335 | ohci_at91_usb_set_power(pdata, wIndex - 1, 0); |
| 336 | return 0; |
| 337 | } |
| 338 | } |
| 339 | break; |
| 340 | } |
| 341 | |
| 342 | ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
| 343 | if (ret) |
| 344 | goto out; |
| 345 | |
| 346 | switch (typeReq) { |
| 347 | case GetHubDescriptor: |
| 348 | |
| 349 | /* update the hub's descriptor */ |
| 350 | |
| 351 | desc = (struct usb_hub_descriptor *)buf; |
| 352 | |
| 353 | dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n", |
| 354 | desc->wHubCharacteristics); |
| 355 | |
| 356 | /* remove the old configurations for power-switching, and |
| 357 | * over-current protection, and insert our new configuration |
| 358 | */ |
| 359 | |
| 360 | desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM); |
| 361 | desc->wHubCharacteristics |= cpu_to_le16(0x0001); |
| 362 | |
| 363 | if (pdata->overcurrent_supported) { |
| 364 | desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM); |
| 365 | desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001); |
| 366 | } |
| 367 | |
| 368 | dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", |
| 369 | desc->wHubCharacteristics); |
| 370 | |
| 371 | return ret; |
| 372 | |
| 373 | case GetPortStatus: |
| 374 | /* check port status */ |
| 375 | |
| 376 | dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); |
| 377 | |
| 378 | if (wIndex == 1 || wIndex == 2) { |
| 379 | if (! ohci_at91_usb_get_power(pdata, wIndex-1)) { |
| 380 | *data &= ~cpu_to_le32(RH_PS_PPS); |
| 381 | } |
| 382 | |
| 383 | if (pdata->overcurrent_changed[wIndex-1]) { |
| 384 | *data |= cpu_to_le32(RH_PS_OCIC); |
| 385 | } |
| 386 | |
| 387 | if (pdata->overcurrent_status[wIndex-1]) { |
| 388 | *data |= cpu_to_le32(RH_PS_POCI); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | out: |
| 394 | return ret; |
| 395 | } |
| 396 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 397 | /*-------------------------------------------------------------------------*/ |
| 398 | |
| 399 | static const struct hc_driver ohci_at91_hc_driver = { |
| 400 | .description = hcd_name, |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 401 | .product_desc = "AT91 OHCI", |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 402 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 403 | |
| 404 | /* |
| 405 | * generic hardware linkage |
| 406 | */ |
| 407 | .irq = ohci_irq, |
| 408 | .flags = HCD_USB11 | HCD_MEMORY, |
| 409 | |
| 410 | /* |
| 411 | * basic lifecycle operations |
| 412 | */ |
| 413 | .start = ohci_at91_start, |
| 414 | .stop = ohci_stop, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 415 | .shutdown = ohci_shutdown, |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 416 | |
| 417 | /* |
| 418 | * managing i/o requests and associated device resources |
| 419 | */ |
| 420 | .urb_enqueue = ohci_urb_enqueue, |
| 421 | .urb_dequeue = ohci_urb_dequeue, |
| 422 | .endpoint_disable = ohci_endpoint_disable, |
| 423 | |
| 424 | /* |
| 425 | * scheduling support |
| 426 | */ |
| 427 | .get_frame_number = ohci_get_frame, |
| 428 | |
| 429 | /* |
| 430 | * root hub support |
| 431 | */ |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 432 | .hub_status_data = ohci_at91_hub_status_data, |
| 433 | .hub_control = ohci_at91_hub_control, |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 434 | #ifdef CONFIG_PM |
David Brownell | 68ba61b | 2006-04-02 20:26:21 -0800 | [diff] [blame] | 435 | .bus_suspend = ohci_bus_suspend, |
| 436 | .bus_resume = ohci_bus_resume, |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 437 | #endif |
| 438 | .start_port_reset = ohci_start_port_reset, |
| 439 | }; |
| 440 | |
| 441 | /*-------------------------------------------------------------------------*/ |
| 442 | |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 443 | static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) |
| 444 | { |
| 445 | struct platform_device *pdev = data; |
| 446 | struct at91_usbh_data *pdata = pdev->dev.platform_data; |
| 447 | int val, gpio, port; |
| 448 | |
| 449 | /* From the GPIO notifying the over-current situation, find |
| 450 | * out the corresponding port */ |
| 451 | gpio = irq_to_gpio(irq); |
| 452 | for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) { |
| 453 | if (pdata->overcurrent_pin[port] == gpio) |
| 454 | break; |
| 455 | } |
| 456 | |
| 457 | if (port == ARRAY_SIZE(pdata->overcurrent_pin)) { |
| 458 | dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n"); |
| 459 | return IRQ_HANDLED; |
| 460 | } |
| 461 | |
| 462 | val = gpio_get_value(gpio); |
| 463 | |
| 464 | /* When notified of an over-current situation, disable power |
| 465 | on the corresponding port, and mark this port in |
| 466 | over-current. */ |
| 467 | if (! val) { |
| 468 | ohci_at91_usb_set_power(pdata, port, 0); |
| 469 | pdata->overcurrent_status[port] = 1; |
| 470 | pdata->overcurrent_changed[port] = 1; |
| 471 | } |
| 472 | |
| 473 | dev_dbg(& pdev->dev, "overcurrent situation %s\n", |
| 474 | val ? "exited" : "notified"); |
| 475 | |
| 476 | return IRQ_HANDLED; |
| 477 | } |
| 478 | |
| 479 | /*-------------------------------------------------------------------------*/ |
| 480 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 481 | static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 482 | { |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 483 | struct at91_usbh_data *pdata = pdev->dev.platform_data; |
| 484 | int i; |
| 485 | |
| 486 | if (pdata) { |
Justin Waters | 3d6fdf7 | 2009-04-03 21:06:53 +0100 | [diff] [blame] | 487 | for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 488 | if (!gpio_is_valid(pdata->vbus_pin[i])) |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 489 | continue; |
| 490 | gpio_request(pdata->vbus_pin[i], "ohci_vbus"); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 491 | ohci_at91_usb_set_power(pdata, i, 1); |
| 492 | } |
| 493 | |
| 494 | for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) { |
| 495 | int ret; |
| 496 | |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 497 | if (!gpio_is_valid(pdata->overcurrent_pin[i])) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 498 | continue; |
| 499 | gpio_request(pdata->overcurrent_pin[i], "ohci_overcurrent"); |
| 500 | |
| 501 | ret = request_irq(gpio_to_irq(pdata->overcurrent_pin[i]), |
| 502 | ohci_hcd_at91_overcurrent_irq, |
| 503 | IRQF_SHARED, "ohci_overcurrent", pdev); |
| 504 | if (ret) { |
| 505 | gpio_free(pdata->overcurrent_pin[i]); |
| 506 | dev_warn(& pdev->dev, "cannot get GPIO IRQ for overcurrent\n"); |
| 507 | } |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 511 | device_init_wakeup(&pdev->dev, 1); |
| 512 | return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 513 | } |
| 514 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 515 | static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 516 | { |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 517 | struct at91_usbh_data *pdata = pdev->dev.platform_data; |
| 518 | int i; |
| 519 | |
| 520 | if (pdata) { |
Justin Waters | 3d6fdf7 | 2009-04-03 21:06:53 +0100 | [diff] [blame] | 521 | for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 522 | if (!gpio_is_valid(pdata->vbus_pin[i])) |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 523 | continue; |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 524 | ohci_at91_usb_set_power(pdata, i, 0); |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 525 | gpio_free(pdata->vbus_pin[i]); |
| 526 | } |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 527 | |
| 528 | for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) { |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 529 | if (!gpio_is_valid(pdata->overcurrent_pin[i])) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 530 | continue; |
| 531 | free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev); |
| 532 | gpio_free(pdata->overcurrent_pin[i]); |
| 533 | } |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 534 | } |
| 535 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 536 | device_init_wakeup(&pdev->dev, 0); |
Pete Zaitcev | 421b4bf | 2008-06-01 14:38:43 -0700 | [diff] [blame] | 537 | usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev); |
| 538 | return 0; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | #ifdef CONFIG_PM |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 542 | |
David Brownell | 68ba61b | 2006-04-02 20:26:21 -0800 | [diff] [blame] | 543 | static int |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 544 | ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg) |
David Brownell | 68ba61b | 2006-04-02 20:26:21 -0800 | [diff] [blame] | 545 | { |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 546 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 547 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 548 | |
| 549 | if (device_may_wakeup(&pdev->dev)) |
| 550 | enable_irq_wake(hcd->irq); |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 551 | |
| 552 | /* |
| 553 | * The integrated transceivers seem unable to notice disconnect, |
| 554 | * reconnect, or wakeup without the 48 MHz clock active. so for |
| 555 | * correctness, always discard connection state (using reset). |
| 556 | * |
| 557 | * REVISIT: some boards will be able to turn VBUS off... |
| 558 | */ |
| 559 | if (at91_suspend_entering_slow_clock()) { |
| 560 | ohci_usb_reset (ohci); |
Patrice Vilchez | 869aa98 | 2010-04-28 13:45:40 +0200 | [diff] [blame] | 561 | /* flush the writes */ |
| 562 | (void) ohci_readl (ohci, &ohci->regs->control); |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 563 | at91_stop_clock(); |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 564 | } |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 569 | static int ohci_hcd_at91_drv_resume(struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 570 | { |
Marc Pignat | 6dde896 | 2007-01-09 14:00:11 -0800 | [diff] [blame] | 571 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 572 | |
| 573 | if (device_may_wakeup(&pdev->dev)) |
| 574 | disable_irq_wake(hcd->irq); |
| 575 | |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 576 | if (!clocked) |
| 577 | at91_start_clock(); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 578 | |
Alan Stern | 43bbb7e | 2008-04-03 18:03:17 -0400 | [diff] [blame] | 579 | ohci_finish_controller_resume(hcd); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 580 | return 0; |
| 581 | } |
| 582 | #else |
| 583 | #define ohci_hcd_at91_drv_suspend NULL |
| 584 | #define ohci_hcd_at91_drv_resume NULL |
| 585 | #endif |
| 586 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 587 | MODULE_ALIAS("platform:at91_ohci"); |
David Brownell | 68ba61b | 2006-04-02 20:26:21 -0800 | [diff] [blame] | 588 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 589 | static struct platform_driver ohci_hcd_at91_driver = { |
| 590 | .probe = ohci_hcd_at91_drv_probe, |
| 591 | .remove = ohci_hcd_at91_drv_remove, |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 592 | .shutdown = usb_hcd_platform_shutdown, |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 593 | .suspend = ohci_hcd_at91_drv_suspend, |
| 594 | .resume = ohci_hcd_at91_drv_resume, |
| 595 | .driver = { |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 596 | .name = "at91_ohci", |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 597 | .owner = THIS_MODULE, |
| 598 | }, |
| 599 | }; |