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> |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 16 | #include <linux/dma-mapping.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 17 | #include <linux/of_platform.h> |
| 18 | #include <linux/of_gpio.h> |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Jean-Christophe PLAGNIOL-VILLARD | bcd2360 | 2012-10-30 05:12:23 +0800 | [diff] [blame] | 20 | #include <linux/platform_data/atmel.h> |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 21 | #include <linux/io.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/usb.h> |
| 25 | #include <linux/usb/hcd.h> |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 26 | |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 27 | #include <asm/gpio.h> |
| 28 | |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 29 | #include "ohci.h" |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 30 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 31 | #define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS) |
| 32 | #define at91_for_each_port(index) \ |
| 33 | for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++) |
| 34 | |
Boris BREZILLON | 6b0a1cf | 2013-08-01 19:09:13 +0200 | [diff] [blame] | 35 | /* interface, function and usb clocks; sometimes also an AHB clock */ |
| 36 | static struct clk *iclk, *fclk, *uclk, *hclk; |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 37 | /* interface and function clocks; sometimes also an AHB clock */ |
| 38 | |
| 39 | #define DRIVER_DESC "OHCI Atmel driver" |
| 40 | |
| 41 | static const char hcd_name[] = "ohci-atmel"; |
| 42 | |
| 43 | static struct hc_driver __read_mostly ohci_at91_hc_driver; |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 44 | static int clocked; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 45 | |
| 46 | extern int usb_disabled(void); |
| 47 | |
| 48 | /*-------------------------------------------------------------------------*/ |
| 49 | |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 50 | static void at91_start_clock(void) |
| 51 | { |
Boris BREZILLON | 6b0a1cf | 2013-08-01 19:09:13 +0200 | [diff] [blame] | 52 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { |
| 53 | clk_set_rate(uclk, 48000000); |
| 54 | clk_prepare_enable(uclk); |
| 55 | } |
Boris BREZILLON | 8e82d8d | 2013-06-19 13:21:08 +0200 | [diff] [blame] | 56 | clk_prepare_enable(hclk); |
| 57 | clk_prepare_enable(iclk); |
| 58 | clk_prepare_enable(fclk); |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 59 | clocked = 1; |
| 60 | } |
| 61 | |
| 62 | static void at91_stop_clock(void) |
| 63 | { |
Boris BREZILLON | 8e82d8d | 2013-06-19 13:21:08 +0200 | [diff] [blame] | 64 | clk_disable_unprepare(fclk); |
| 65 | clk_disable_unprepare(iclk); |
| 66 | clk_disable_unprepare(hclk); |
Boris BREZILLON | 6b0a1cf | 2013-08-01 19:09:13 +0200 | [diff] [blame] | 67 | if (IS_ENABLED(CONFIG_COMMON_CLK)) |
| 68 | clk_disable_unprepare(uclk); |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 69 | clocked = 0; |
| 70 | } |
| 71 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 72 | static void at91_start_hc(struct platform_device *pdev) |
| 73 | { |
| 74 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 75 | struct ohci_regs __iomem *regs = hcd->regs; |
| 76 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 77 | dev_dbg(&pdev->dev, "start\n"); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Start the USB clocks. |
| 81 | */ |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 82 | at91_start_clock(); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * The USB host controller must remain in reset. |
| 86 | */ |
| 87 | writel(0, ®s->control); |
| 88 | } |
| 89 | |
| 90 | static void at91_stop_hc(struct platform_device *pdev) |
| 91 | { |
| 92 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 93 | struct ohci_regs __iomem *regs = hcd->regs; |
| 94 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 95 | dev_dbg(&pdev->dev, "stop\n"); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * Put the USB host controller into reset. |
| 99 | */ |
| 100 | writel(0, ®s->control); |
| 101 | |
| 102 | /* |
| 103 | * Stop the USB clocks. |
| 104 | */ |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 105 | at91_stop_clock(); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
| 109 | /*-------------------------------------------------------------------------*/ |
| 110 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 111 | static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 112 | |
| 113 | /* configure so an HC device and id are always provided */ |
| 114 | /* always called with process context; sleeping is OK */ |
| 115 | |
| 116 | |
| 117 | /** |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 118 | * usb_hcd_at91_probe - initialize AT91-based HCDs |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 119 | * Context: !in_interrupt() |
| 120 | * |
| 121 | * Allocates basic resources for this USB host controller, and |
| 122 | * then invokes the start() method for the HCD associated with it |
| 123 | * through the hotplug entry's driver_data. |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 124 | */ |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 125 | static int usb_hcd_at91_probe(const struct hc_driver *driver, |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 126 | struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 127 | { |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 128 | struct at91_usbh_data *board; |
| 129 | struct ohci_hcd *ohci; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 130 | int retval; |
| 131 | struct usb_hcd *hcd = NULL; |
Boris BREZILLON | fb5f183 | 2013-12-08 15:59:59 +0100 | [diff] [blame] | 132 | struct device *dev = &pdev->dev; |
| 133 | struct resource *res; |
| 134 | int irq; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 135 | |
Boris BREZILLON | fb5f183 | 2013-12-08 15:59:59 +0100 | [diff] [blame] | 136 | irq = platform_get_irq(pdev, 0); |
| 137 | if (irq < 0) { |
| 138 | dev_dbg(dev, "hcd probe: missing irq resource\n"); |
| 139 | return irq; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Boris BREZILLON | 5b218a0 | 2013-12-09 09:51:54 +0100 | [diff] [blame] | 142 | hcd = usb_create_hcd(driver, dev, "at91"); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 143 | if (!hcd) |
| 144 | return -ENOMEM; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 145 | |
Varka Bhadram | 04dc315 | 2014-11-04 07:51:12 +0530 | [diff] [blame] | 146 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Boris BREZILLON | cca2bbb | 2013-12-09 09:51:53 +0100 | [diff] [blame] | 147 | hcd->regs = devm_ioremap_resource(dev, res); |
| 148 | if (IS_ERR(hcd->regs)) { |
| 149 | retval = PTR_ERR(hcd->regs); |
| 150 | goto err; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 151 | } |
Varka Bhadram | 04dc315 | 2014-11-04 07:51:12 +0530 | [diff] [blame] | 152 | hcd->rsrc_start = res->start; |
| 153 | hcd->rsrc_len = resource_size(res); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 154 | |
Boris BREZILLON | fc7a325 | 2013-12-09 09:51:55 +0100 | [diff] [blame] | 155 | iclk = devm_clk_get(dev, "ohci_clk"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 156 | if (IS_ERR(iclk)) { |
Boris BREZILLON | 5b218a0 | 2013-12-09 09:51:54 +0100 | [diff] [blame] | 157 | dev_err(dev, "failed to get ohci_clk\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 158 | retval = PTR_ERR(iclk); |
Boris BREZILLON | cca2bbb | 2013-12-09 09:51:53 +0100 | [diff] [blame] | 159 | goto err; |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 160 | } |
Boris BREZILLON | fc7a325 | 2013-12-09 09:51:55 +0100 | [diff] [blame] | 161 | fclk = devm_clk_get(dev, "uhpck"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 162 | if (IS_ERR(fclk)) { |
Boris BREZILLON | 5b218a0 | 2013-12-09 09:51:54 +0100 | [diff] [blame] | 163 | dev_err(dev, "failed to get uhpck\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 164 | retval = PTR_ERR(fclk); |
Boris BREZILLON | fc7a325 | 2013-12-09 09:51:55 +0100 | [diff] [blame] | 165 | goto err; |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 166 | } |
Boris BREZILLON | fc7a325 | 2013-12-09 09:51:55 +0100 | [diff] [blame] | 167 | hclk = devm_clk_get(dev, "hclk"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 168 | if (IS_ERR(hclk)) { |
Boris BREZILLON | 5b218a0 | 2013-12-09 09:51:54 +0100 | [diff] [blame] | 169 | dev_err(dev, "failed to get hclk\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 170 | retval = PTR_ERR(hclk); |
Boris BREZILLON | fc7a325 | 2013-12-09 09:51:55 +0100 | [diff] [blame] | 171 | goto err; |
Jean-Christophe PLAGNIOL-VILLARD | 6813463 | 2011-12-08 16:32:00 +0100 | [diff] [blame] | 172 | } |
Boris BREZILLON | 6b0a1cf | 2013-08-01 19:09:13 +0200 | [diff] [blame] | 173 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { |
Boris BREZILLON | fc7a325 | 2013-12-09 09:51:55 +0100 | [diff] [blame] | 174 | uclk = devm_clk_get(dev, "usb_clk"); |
Boris BREZILLON | 6b0a1cf | 2013-08-01 19:09:13 +0200 | [diff] [blame] | 175 | if (IS_ERR(uclk)) { |
Boris BREZILLON | 5b218a0 | 2013-12-09 09:51:54 +0100 | [diff] [blame] | 176 | dev_err(dev, "failed to get uclk\n"); |
Boris BREZILLON | 6b0a1cf | 2013-08-01 19:09:13 +0200 | [diff] [blame] | 177 | retval = PTR_ERR(uclk); |
Boris BREZILLON | fc7a325 | 2013-12-09 09:51:55 +0100 | [diff] [blame] | 178 | goto err; |
Boris BREZILLON | 6b0a1cf | 2013-08-01 19:09:13 +0200 | [diff] [blame] | 179 | } |
| 180 | } |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 181 | |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 182 | board = hcd->self.controller->platform_data; |
| 183 | ohci = hcd_to_ohci(hcd); |
| 184 | ohci->num_ports = board->ports; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 185 | at91_start_hc(pdev); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 186 | |
Boris BREZILLON | fb5f183 | 2013-12-08 15:59:59 +0100 | [diff] [blame] | 187 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
Arnd Bergmann | 1f53b48 | 2014-01-07 12:54:58 +0100 | [diff] [blame] | 188 | if (retval == 0) { |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 189 | device_wakeup_enable(hcd->self.controller); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 190 | return retval; |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 191 | } |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 192 | |
| 193 | /* Error handling */ |
| 194 | at91_stop_hc(pdev); |
| 195 | |
Boris BREZILLON | cca2bbb | 2013-12-09 09:51:53 +0100 | [diff] [blame] | 196 | err: |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 197 | usb_put_hcd(hcd); |
| 198 | return retval; |
| 199 | } |
| 200 | |
| 201 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 202 | /* may be called with controller, bus, and devices active */ |
| 203 | |
| 204 | /** |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 205 | * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 206 | * @dev: USB Host Controller being removed |
| 207 | * Context: !in_interrupt() |
| 208 | * |
| 209 | * Reverses the effect of usb_hcd_at91_probe(), first invoking |
| 210 | * the HCD's stop() method. It is always called from a thread |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 211 | * context, "rmmod" or something similar. |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 212 | * |
| 213 | */ |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 214 | static void usb_hcd_at91_remove(struct usb_hcd *hcd, |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 215 | struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 216 | { |
| 217 | usb_remove_hcd(hcd); |
| 218 | at91_stop_hc(pdev); |
Pete Zaitcev | 421b4bf | 2008-06-01 14:38:43 -0700 | [diff] [blame] | 219 | usb_put_hcd(hcd); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /*-------------------------------------------------------------------------*/ |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 223 | static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) |
| 224 | { |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 225 | if (!valid_port(port)) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 226 | return; |
| 227 | |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 228 | if (!gpio_is_valid(pdata->vbus_pin[port])) |
Jean-Christophe PLAGNIOL-VILLARD | 770f0ba | 2011-11-12 16:46:13 +0100 | [diff] [blame] | 229 | return; |
| 230 | |
Jean-Christophe PLAGNIOL-VILLARD | 8134ff5 | 2011-12-08 16:32:01 +0100 | [diff] [blame] | 231 | gpio_set_value(pdata->vbus_pin[port], |
Nicolas Ferre | 1e7caf8 | 2012-03-21 14:38:55 +0100 | [diff] [blame] | 232 | pdata->vbus_pin_active_low[port] ^ enable); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) |
| 236 | { |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 237 | if (!valid_port(port)) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 238 | return -EINVAL; |
| 239 | |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 240 | if (!gpio_is_valid(pdata->vbus_pin[port])) |
Jean-Christophe PLAGNIOL-VILLARD | 770f0ba | 2011-11-12 16:46:13 +0100 | [diff] [blame] | 241 | return -EINVAL; |
| 242 | |
Jean-Christophe PLAGNIOL-VILLARD | 8134ff5 | 2011-12-08 16:32:01 +0100 | [diff] [blame] | 243 | return gpio_get_value(pdata->vbus_pin[port]) ^ |
Nicolas Ferre | 1e7caf8 | 2012-03-21 14:38:55 +0100 | [diff] [blame] | 244 | pdata->vbus_pin_active_low[port]; |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Update the status data from the hub with the over-current indicator change. |
| 249 | */ |
| 250 | static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 251 | { |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 252 | struct at91_usbh_data *pdata = hcd->self.controller->platform_data; |
Laurent Pinchart | 42b59eb | 2014-04-16 18:00:09 +0200 | [diff] [blame] | 253 | int length = ohci_hub_status_data(hcd, buf); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 254 | int port; |
| 255 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 256 | at91_for_each_port(port) { |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 257 | if (pdata->overcurrent_changed[port]) { |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 258 | if (!length) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 259 | length = 1; |
| 260 | buf[0] |= 1 << (port + 1); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | return length; |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * Look at the control requests to the root hub and see if we need to override. |
| 269 | */ |
| 270 | static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
| 271 | u16 wIndex, char *buf, u16 wLength) |
| 272 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 273 | struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 274 | struct usb_hub_descriptor *desc; |
| 275 | int ret = -EINVAL; |
| 276 | u32 *data = (u32 *)buf; |
| 277 | |
| 278 | dev_dbg(hcd->self.controller, |
| 279 | "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", |
| 280 | hcd, typeReq, wValue, wIndex, buf, wLength); |
| 281 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 282 | wIndex--; |
| 283 | |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 284 | switch (typeReq) { |
| 285 | case SetPortFeature: |
| 286 | if (wValue == USB_PORT_FEAT_POWER) { |
| 287 | dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 288 | if (valid_port(wIndex)) { |
| 289 | ohci_at91_usb_set_power(pdata, wIndex, 1); |
| 290 | ret = 0; |
| 291 | } |
| 292 | |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 293 | goto out; |
| 294 | } |
| 295 | break; |
| 296 | |
| 297 | case ClearPortFeature: |
| 298 | switch (wValue) { |
| 299 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 300 | dev_dbg(hcd->self.controller, |
| 301 | "ClearPortFeature: C_OVER_CURRENT\n"); |
| 302 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 303 | if (valid_port(wIndex)) { |
| 304 | pdata->overcurrent_changed[wIndex] = 0; |
| 305 | pdata->overcurrent_status[wIndex] = 0; |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | goto out; |
| 309 | |
| 310 | case USB_PORT_FEAT_OVER_CURRENT: |
| 311 | dev_dbg(hcd->self.controller, |
| 312 | "ClearPortFeature: OVER_CURRENT\n"); |
| 313 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 314 | if (valid_port(wIndex)) |
| 315 | pdata->overcurrent_status[wIndex] = 0; |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 316 | |
| 317 | goto out; |
| 318 | |
| 319 | case USB_PORT_FEAT_POWER: |
| 320 | dev_dbg(hcd->self.controller, |
| 321 | "ClearPortFeature: POWER\n"); |
| 322 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 323 | if (valid_port(wIndex)) { |
| 324 | ohci_at91_usb_set_power(pdata, wIndex, 0); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | } |
| 328 | break; |
| 329 | } |
| 330 | |
Laurent Pinchart | 42b59eb | 2014-04-16 18:00:09 +0200 | [diff] [blame] | 331 | ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 332 | if (ret) |
| 333 | goto out; |
| 334 | |
| 335 | switch (typeReq) { |
| 336 | case GetHubDescriptor: |
| 337 | |
| 338 | /* update the hub's descriptor */ |
| 339 | |
| 340 | desc = (struct usb_hub_descriptor *)buf; |
| 341 | |
| 342 | dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n", |
| 343 | desc->wHubCharacteristics); |
| 344 | |
| 345 | /* remove the old configurations for power-switching, and |
| 346 | * over-current protection, and insert our new configuration |
| 347 | */ |
| 348 | |
| 349 | desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM); |
Sergei Shtylyov | a9c49bc | 2015-01-19 01:39:44 +0300 | [diff] [blame] | 350 | desc->wHubCharacteristics |= |
| 351 | cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 352 | |
| 353 | if (pdata->overcurrent_supported) { |
| 354 | desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM); |
Sergei Shtylyov | a9c49bc | 2015-01-19 01:39:44 +0300 | [diff] [blame] | 355 | desc->wHubCharacteristics |= |
| 356 | cpu_to_le16(HUB_CHAR_INDV_PORT_OCPM); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", |
| 360 | desc->wHubCharacteristics); |
| 361 | |
| 362 | return ret; |
| 363 | |
| 364 | case GetPortStatus: |
| 365 | /* check port status */ |
| 366 | |
| 367 | dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); |
| 368 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 369 | if (valid_port(wIndex)) { |
| 370 | if (!ohci_at91_usb_get_power(pdata, wIndex)) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 371 | *data &= ~cpu_to_le32(RH_PS_PPS); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 372 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 373 | if (pdata->overcurrent_changed[wIndex]) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 374 | *data |= cpu_to_le32(RH_PS_OCIC); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 375 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 376 | if (pdata->overcurrent_status[wIndex]) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 377 | *data |= cpu_to_le32(RH_PS_POCI); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
| 381 | out: |
| 382 | return ret; |
| 383 | } |
| 384 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 385 | /*-------------------------------------------------------------------------*/ |
| 386 | |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 387 | static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) |
| 388 | { |
| 389 | struct platform_device *pdev = data; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 390 | struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 391 | int val, gpio, port; |
| 392 | |
| 393 | /* From the GPIO notifying the over-current situation, find |
| 394 | * out the corresponding port */ |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 395 | at91_for_each_port(port) { |
Joachim Eastwood | 01bb650 | 2012-09-23 22:56:00 +0200 | [diff] [blame] | 396 | if (gpio_is_valid(pdata->overcurrent_pin[port]) && |
| 397 | gpio_to_irq(pdata->overcurrent_pin[port]) == irq) { |
Nicolas Ferre | e449907 | 2012-02-11 14:23:06 +0100 | [diff] [blame] | 398 | gpio = pdata->overcurrent_pin[port]; |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 399 | break; |
Nicolas Ferre | e449907 | 2012-02-11 14:23:06 +0100 | [diff] [blame] | 400 | } |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 403 | if (port == AT91_MAX_USBH_PORTS) { |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 404 | dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n"); |
| 405 | return IRQ_HANDLED; |
| 406 | } |
| 407 | |
| 408 | val = gpio_get_value(gpio); |
| 409 | |
| 410 | /* When notified of an over-current situation, disable power |
| 411 | on the corresponding port, and mark this port in |
| 412 | over-current. */ |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 413 | if (!val) { |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 414 | ohci_at91_usb_set_power(pdata, port, 0); |
| 415 | pdata->overcurrent_status[port] = 1; |
| 416 | pdata->overcurrent_changed[port] = 1; |
| 417 | } |
| 418 | |
| 419 | dev_dbg(& pdev->dev, "overcurrent situation %s\n", |
| 420 | val ? "exited" : "notified"); |
| 421 | |
| 422 | return IRQ_HANDLED; |
| 423 | } |
| 424 | |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 425 | #ifdef CONFIG_OF |
| 426 | static const struct of_device_id at91_ohci_dt_ids[] = { |
| 427 | { .compatible = "atmel,at91rm9200-ohci" }, |
| 428 | { /* sentinel */ } |
| 429 | }; |
| 430 | |
| 431 | MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids); |
| 432 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 433 | static int ohci_at91_of_init(struct platform_device *pdev) |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 434 | { |
| 435 | struct device_node *np = pdev->dev.of_node; |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 436 | int i, gpio, ret; |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 437 | enum of_gpio_flags flags; |
| 438 | struct at91_usbh_data *pdata; |
| 439 | u32 ports; |
| 440 | |
| 441 | if (!np) |
| 442 | return 0; |
| 443 | |
| 444 | /* Right now device-tree probed devices don't get dma_mask set. |
| 445 | * Since shared usb code relies on it, set it here for now. |
| 446 | * Once we have dma capability bindings this can go away. |
| 447 | */ |
Russell King | e1fd734 | 2013-06-27 12:36:37 +0100 | [diff] [blame] | 448 | ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 449 | if (ret) |
| 450 | return ret; |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 451 | |
| 452 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 453 | if (!pdata) |
| 454 | return -ENOMEM; |
| 455 | |
| 456 | if (!of_property_read_u32(np, "num-ports", &ports)) |
| 457 | pdata->ports = ports; |
| 458 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 459 | at91_for_each_port(i) { |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 460 | gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags); |
| 461 | pdata->vbus_pin[i] = gpio; |
| 462 | if (!gpio_is_valid(gpio)) |
| 463 | continue; |
| 464 | pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW; |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 465 | } |
| 466 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 467 | at91_for_each_port(i) |
Nicolas Ferre | aaf9f5f | 2012-03-21 16:58:11 +0100 | [diff] [blame] | 468 | pdata->overcurrent_pin[i] = |
| 469 | of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags); |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 470 | |
| 471 | pdev->dev.platform_data = pdata; |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | #else |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 476 | static int ohci_at91_of_init(struct platform_device *pdev) |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 477 | { |
| 478 | return 0; |
| 479 | } |
| 480 | #endif |
| 481 | |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 482 | /*-------------------------------------------------------------------------*/ |
| 483 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 484 | static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 485 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 486 | struct at91_usbh_data *pdata; |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 487 | int i; |
Nicolas Ferre | aaf9f5f | 2012-03-21 16:58:11 +0100 | [diff] [blame] | 488 | int gpio; |
| 489 | int ret; |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 490 | |
Nicolas Ferre | 1887ab2b | 2012-03-28 11:49:01 +0200 | [diff] [blame] | 491 | ret = ohci_at91_of_init(pdev); |
| 492 | if (ret) |
| 493 | return ret; |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 494 | |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 495 | pdata = dev_get_platdata(&pdev->dev); |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 496 | |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 497 | if (pdata) { |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 498 | at91_for_each_port(i) { |
Nicolas Ferre | 6fffb77 | 2012-08-29 11:49:18 +0200 | [diff] [blame] | 499 | /* |
| 500 | * do not configure PIO if not in relation with |
| 501 | * real USB port on board |
| 502 | */ |
| 503 | if (i >= pdata->ports) { |
| 504 | pdata->vbus_pin[i] = -EINVAL; |
| 505 | pdata->overcurrent_pin[i] = -EINVAL; |
| 506 | break; |
| 507 | } |
| 508 | |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 509 | if (!gpio_is_valid(pdata->vbus_pin[i])) |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 510 | continue; |
Nicolas Ferre | aaf9f5f | 2012-03-21 16:58:11 +0100 | [diff] [blame] | 511 | gpio = pdata->vbus_pin[i]; |
| 512 | |
| 513 | ret = gpio_request(gpio, "ohci_vbus"); |
| 514 | if (ret) { |
| 515 | dev_err(&pdev->dev, |
| 516 | "can't request vbus gpio %d\n", gpio); |
| 517 | continue; |
| 518 | } |
| 519 | ret = gpio_direction_output(gpio, |
| 520 | !pdata->vbus_pin_active_low[i]); |
| 521 | if (ret) { |
| 522 | dev_err(&pdev->dev, |
| 523 | "can't put vbus gpio %d as output %d\n", |
| 524 | gpio, !pdata->vbus_pin_active_low[i]); |
| 525 | gpio_free(gpio); |
| 526 | continue; |
| 527 | } |
| 528 | |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 529 | ohci_at91_usb_set_power(pdata, i, 1); |
| 530 | } |
| 531 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 532 | at91_for_each_port(i) { |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 533 | if (!gpio_is_valid(pdata->overcurrent_pin[i])) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 534 | continue; |
Nicolas Ferre | aaf9f5f | 2012-03-21 16:58:11 +0100 | [diff] [blame] | 535 | gpio = pdata->overcurrent_pin[i]; |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 536 | |
Nicolas Ferre | aaf9f5f | 2012-03-21 16:58:11 +0100 | [diff] [blame] | 537 | ret = gpio_request(gpio, "ohci_overcurrent"); |
| 538 | if (ret) { |
| 539 | dev_err(&pdev->dev, |
| 540 | "can't request overcurrent gpio %d\n", |
| 541 | gpio); |
| 542 | continue; |
| 543 | } |
| 544 | |
| 545 | ret = gpio_direction_input(gpio); |
| 546 | if (ret) { |
| 547 | dev_err(&pdev->dev, |
| 548 | "can't configure overcurrent gpio %d as input\n", |
| 549 | gpio); |
| 550 | gpio_free(gpio); |
| 551 | continue; |
| 552 | } |
| 553 | |
| 554 | ret = request_irq(gpio_to_irq(gpio), |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 555 | ohci_hcd_at91_overcurrent_irq, |
| 556 | IRQF_SHARED, "ohci_overcurrent", pdev); |
| 557 | if (ret) { |
Nicolas Ferre | aaf9f5f | 2012-03-21 16:58:11 +0100 | [diff] [blame] | 558 | gpio_free(gpio); |
| 559 | dev_err(&pdev->dev, |
| 560 | "can't get gpio IRQ for overcurrent\n"); |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 561 | } |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 565 | device_init_wakeup(&pdev->dev, 1); |
| 566 | return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 567 | } |
| 568 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 569 | static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 570 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 571 | struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev); |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 572 | int i; |
| 573 | |
| 574 | if (pdata) { |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 575 | at91_for_each_port(i) { |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 576 | if (!gpio_is_valid(pdata->vbus_pin[i])) |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 577 | continue; |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 578 | ohci_at91_usb_set_power(pdata, i, 0); |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 579 | gpio_free(pdata->vbus_pin[i]); |
| 580 | } |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 581 | |
Nicolas Ferre | 0ee6d1e | 2012-03-21 16:53:09 +0100 | [diff] [blame] | 582 | at91_for_each_port(i) { |
Jean-Christophe PLAGNIOL-VILLARD | 8a7a49d | 2011-09-19 15:32:23 +0800 | [diff] [blame] | 583 | if (!gpio_is_valid(pdata->overcurrent_pin[i])) |
Thomas Petazzoni | aa6e52a | 2011-07-13 11:29:17 +0200 | [diff] [blame] | 584 | continue; |
| 585 | free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev); |
| 586 | gpio_free(pdata->overcurrent_pin[i]); |
| 587 | } |
David Brownell | 4bde4a4 | 2007-12-27 11:19:49 -0800 | [diff] [blame] | 588 | } |
| 589 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 590 | device_init_wakeup(&pdev->dev, 0); |
Pete Zaitcev | 421b4bf | 2008-06-01 14:38:43 -0700 | [diff] [blame] | 591 | usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev); |
| 592 | return 0; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | #ifdef CONFIG_PM |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 596 | |
David Brownell | 68ba61b | 2006-04-02 20:26:21 -0800 | [diff] [blame] | 597 | static int |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 598 | 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] | 599 | { |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 600 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 601 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Majunath Goudar | a9d3840 | 2013-11-13 17:40:17 +0530 | [diff] [blame] | 602 | bool do_wakeup = device_may_wakeup(&pdev->dev); |
| 603 | int ret; |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 604 | |
Majunath Goudar | a9d3840 | 2013-11-13 17:40:17 +0530 | [diff] [blame] | 605 | if (do_wakeup) |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 606 | enable_irq_wake(hcd->irq); |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 607 | |
Majunath Goudar | a9d3840 | 2013-11-13 17:40:17 +0530 | [diff] [blame] | 608 | ret = ohci_suspend(hcd, do_wakeup); |
| 609 | if (ret) { |
| 610 | disable_irq_wake(hcd->irq); |
| 611 | return ret; |
| 612 | } |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 613 | /* |
| 614 | * The integrated transceivers seem unable to notice disconnect, |
| 615 | * reconnect, or wakeup without the 48 MHz clock active. so for |
| 616 | * correctness, always discard connection state (using reset). |
| 617 | * |
| 618 | * REVISIT: some boards will be able to turn VBUS off... |
| 619 | */ |
| 620 | if (at91_suspend_entering_slow_clock()) { |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 621 | ohci->hc_control = ohci_readl(ohci, &ohci->regs->control); |
| 622 | ohci->hc_control &= OHCI_CTRL_RWC; |
| 623 | ohci_writel(ohci, ohci->hc_control, &ohci->regs->control); |
| 624 | ohci->rh_state = OHCI_RH_HALTED; |
| 625 | |
Patrice Vilchez | 869aa98 | 2010-04-28 13:45:40 +0200 | [diff] [blame] | 626 | /* flush the writes */ |
| 627 | (void) ohci_readl (ohci, &ohci->regs->control); |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 628 | at91_stop_clock(); |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 629 | } |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 630 | |
Majunath Goudar | a9d3840 | 2013-11-13 17:40:17 +0530 | [diff] [blame] | 631 | return ret; |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 632 | } |
| 633 | |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 634 | static int ohci_hcd_at91_drv_resume(struct platform_device *pdev) |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 635 | { |
Marc Pignat | 6dde896 | 2007-01-09 14:00:11 -0800 | [diff] [blame] | 636 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 637 | |
| 638 | if (device_may_wakeup(&pdev->dev)) |
| 639 | disable_irq_wake(hcd->irq); |
| 640 | |
Andrew Victor | ed077bb | 2007-02-16 10:18:58 -0800 | [diff] [blame] | 641 | if (!clocked) |
| 642 | at91_start_clock(); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 643 | |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 644 | ohci_resume(hcd, false); |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 645 | return 0; |
| 646 | } |
| 647 | #else |
| 648 | #define ohci_hcd_at91_drv_suspend NULL |
| 649 | #define ohci_hcd_at91_drv_resume NULL |
| 650 | #endif |
| 651 | |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 652 | static struct platform_driver ohci_hcd_at91_driver = { |
| 653 | .probe = ohci_hcd_at91_drv_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 654 | .remove = ohci_hcd_at91_drv_remove, |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 655 | .shutdown = usb_hcd_platform_shutdown, |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 656 | .suspend = ohci_hcd_at91_drv_suspend, |
| 657 | .resume = ohci_hcd_at91_drv_resume, |
| 658 | .driver = { |
David Brownell | 0365ee0 | 2006-06-19 14:27:20 -0700 | [diff] [blame] | 659 | .name = "at91_ohci", |
Jean-Christophe PLAGNIOL-VILLARD | 2419730 | 2011-11-21 06:55:18 +0800 | [diff] [blame] | 660 | .of_match_table = of_match_ptr(at91_ohci_dt_ids), |
Andrew Victor | 39a269c | 2006-01-22 10:32:13 -0800 | [diff] [blame] | 661 | }, |
| 662 | }; |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 663 | |
| 664 | static int __init ohci_at91_init(void) |
| 665 | { |
| 666 | if (usb_disabled()) |
| 667 | return -ENODEV; |
| 668 | |
| 669 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 670 | ohci_init_driver(&ohci_at91_hc_driver, NULL); |
| 671 | |
| 672 | /* |
| 673 | * The Atmel HW has some unusual quirks, which require Atmel-specific |
| 674 | * workarounds. We override certain hc_driver functions here to |
| 675 | * achieve that. We explicitly do not enhance ohci_driver_overrides to |
| 676 | * allow this more easily, since this is an unusual case, and we don't |
| 677 | * want to encourage others to override these functions by making it |
| 678 | * too easy. |
| 679 | */ |
| 680 | |
Manjunath Goudar | e3825b4 | 2013-09-21 16:38:42 +0530 | [diff] [blame] | 681 | ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data; |
| 682 | ohci_at91_hc_driver.hub_control = ohci_at91_hub_control; |
| 683 | |
| 684 | return platform_driver_register(&ohci_hcd_at91_driver); |
| 685 | } |
| 686 | module_init(ohci_at91_init); |
| 687 | |
| 688 | static void __exit ohci_at91_cleanup(void) |
| 689 | { |
| 690 | platform_driver_unregister(&ohci_hcd_at91_driver); |
| 691 | } |
| 692 | module_exit(ohci_at91_cleanup); |
| 693 | |
| 694 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 695 | MODULE_LICENSE("GPL"); |
| 696 | MODULE_ALIAS("platform:at91_ohci"); |