Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * gpio-vbus.c - simple GPIO VBUS sensing driver for B peripheral devices |
| 3 | * |
| 4 | * Copyright (c) 2008 Philipp Zabel <philipp.zabel@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/gpio.h> |
Paul Gortmaker | 6eb0de8 | 2011-07-03 16:09:31 -0400 | [diff] [blame] | 14 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/usb.h> |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 18 | #include <linux/workqueue.h> |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 19 | |
| 20 | #include <linux/regulator/consumer.h> |
| 21 | |
| 22 | #include <linux/usb/gadget.h> |
| 23 | #include <linux/usb/gpio_vbus.h> |
| 24 | #include <linux/usb/otg.h> |
| 25 | |
| 26 | |
| 27 | /* |
| 28 | * A simple GPIO VBUS sensing driver for B peripheral only devices |
| 29 | * with internal transceivers. It can control a D+ pullup GPIO and |
| 30 | * a regulator to limit the current drawn from VBUS. |
| 31 | * |
| 32 | * Needs to be loaded before the UDC driver that will use it. |
| 33 | */ |
| 34 | struct gpio_vbus_data { |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 35 | struct usb_phy phy; |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 36 | struct device *dev; |
| 37 | struct regulator *vbus_draw; |
| 38 | int vbus_draw_enabled; |
| 39 | unsigned mA; |
Shinya Kuribayashi | 934ccec | 2012-05-10 10:31:21 +0900 | [diff] [blame^] | 40 | struct delayed_work work; |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | |
| 44 | /* |
| 45 | * This driver relies on "both edges" triggering. VBUS has 100 msec to |
| 46 | * stabilize, so the peripheral controller driver may need to cope with |
| 47 | * some bouncing due to current surges (e.g. charging local capacitance) |
| 48 | * and contact chatter. |
| 49 | * |
| 50 | * REVISIT in desperate straits, toggling between rising and falling |
| 51 | * edges might be workable. |
| 52 | */ |
| 53 | #define VBUS_IRQ_FLAGS \ |
| 54 | ( IRQF_SAMPLE_RANDOM | IRQF_SHARED \ |
| 55 | | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING ) |
| 56 | |
| 57 | |
| 58 | /* interface to regulator framework */ |
| 59 | static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA) |
| 60 | { |
| 61 | struct regulator *vbus_draw = gpio_vbus->vbus_draw; |
| 62 | int enabled; |
| 63 | |
| 64 | if (!vbus_draw) |
| 65 | return; |
| 66 | |
| 67 | enabled = gpio_vbus->vbus_draw_enabled; |
| 68 | if (mA) { |
| 69 | regulator_set_current_limit(vbus_draw, 0, 1000 * mA); |
| 70 | if (!enabled) { |
| 71 | regulator_enable(vbus_draw); |
| 72 | gpio_vbus->vbus_draw_enabled = 1; |
| 73 | } |
| 74 | } else { |
| 75 | if (enabled) { |
| 76 | regulator_disable(vbus_draw); |
| 77 | gpio_vbus->vbus_draw_enabled = 0; |
| 78 | } |
| 79 | } |
| 80 | gpio_vbus->mA = mA; |
| 81 | } |
| 82 | |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 83 | static int is_vbus_powered(struct gpio_vbus_mach_info *pdata) |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 84 | { |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 85 | int vbus; |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 86 | |
| 87 | vbus = gpio_get_value(pdata->gpio_vbus); |
| 88 | if (pdata->gpio_vbus_inverted) |
| 89 | vbus = !vbus; |
| 90 | |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 91 | return vbus; |
| 92 | } |
| 93 | |
| 94 | static void gpio_vbus_work(struct work_struct *work) |
| 95 | { |
| 96 | struct gpio_vbus_data *gpio_vbus = |
Shinya Kuribayashi | 934ccec | 2012-05-10 10:31:21 +0900 | [diff] [blame^] | 97 | container_of(work, struct gpio_vbus_data, work.work); |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 98 | struct gpio_vbus_mach_info *pdata = gpio_vbus->dev->platform_data; |
Heiko Stübner | 662c738 | 2012-02-29 23:03:11 +0100 | [diff] [blame] | 99 | int gpio, status; |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 100 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 101 | if (!gpio_vbus->phy.otg->gadget) |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 102 | return; |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 103 | |
| 104 | /* Peripheral controllers which manage the pullup themselves won't have |
| 105 | * gpio_pullup configured here. If it's configured here, we'll do what |
| 106 | * isp1301_omap::b_peripheral() does and enable the pullup here... although |
| 107 | * that may complicate usb_gadget_{,dis}connect() support. |
| 108 | */ |
| 109 | gpio = pdata->gpio_pullup; |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 110 | if (is_vbus_powered(pdata)) { |
Heiko Stübner | 662c738 | 2012-02-29 23:03:11 +0100 | [diff] [blame] | 111 | status = USB_EVENT_VBUS; |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 112 | gpio_vbus->phy.state = OTG_STATE_B_PERIPHERAL; |
Heiko Stübner | 662c738 | 2012-02-29 23:03:11 +0100 | [diff] [blame] | 113 | gpio_vbus->phy.last_event = status; |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 114 | usb_gadget_vbus_connect(gpio_vbus->phy.otg->gadget); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 115 | |
| 116 | /* drawing a "unit load" is *always* OK, except for OTG */ |
| 117 | set_vbus_draw(gpio_vbus, 100); |
| 118 | |
| 119 | /* optionally enable D+ pullup */ |
| 120 | if (gpio_is_valid(gpio)) |
| 121 | gpio_set_value(gpio, !pdata->gpio_pullup_inverted); |
Heiko Stübner | 662c738 | 2012-02-29 23:03:11 +0100 | [diff] [blame] | 122 | |
| 123 | atomic_notifier_call_chain(&gpio_vbus->phy.notifier, |
| 124 | status, gpio_vbus->phy.otg->gadget); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 125 | } else { |
| 126 | /* optionally disable D+ pullup */ |
| 127 | if (gpio_is_valid(gpio)) |
| 128 | gpio_set_value(gpio, pdata->gpio_pullup_inverted); |
| 129 | |
| 130 | set_vbus_draw(gpio_vbus, 0); |
| 131 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 132 | usb_gadget_vbus_disconnect(gpio_vbus->phy.otg->gadget); |
Heiko Stübner | 662c738 | 2012-02-29 23:03:11 +0100 | [diff] [blame] | 133 | status = USB_EVENT_NONE; |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 134 | gpio_vbus->phy.state = OTG_STATE_B_IDLE; |
Heiko Stübner | 662c738 | 2012-02-29 23:03:11 +0100 | [diff] [blame] | 135 | gpio_vbus->phy.last_event = status; |
| 136 | |
| 137 | atomic_notifier_call_chain(&gpio_vbus->phy.notifier, |
| 138 | status, gpio_vbus->phy.otg->gadget); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 139 | } |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* VBUS change IRQ handler */ |
| 143 | static irqreturn_t gpio_vbus_irq(int irq, void *data) |
| 144 | { |
| 145 | struct platform_device *pdev = data; |
| 146 | struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; |
| 147 | struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 148 | struct usb_otg *otg = gpio_vbus->phy.otg; |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 149 | |
| 150 | dev_dbg(&pdev->dev, "VBUS %s (gadget: %s)\n", |
| 151 | is_vbus_powered(pdata) ? "supplied" : "inactive", |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 152 | otg->gadget ? otg->gadget->name : "none"); |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 153 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 154 | if (otg->gadget) |
Shinya Kuribayashi | 934ccec | 2012-05-10 10:31:21 +0900 | [diff] [blame^] | 155 | schedule_delayed_work(&gpio_vbus->work, msecs_to_jiffies(100)); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 156 | |
| 157 | return IRQ_HANDLED; |
| 158 | } |
| 159 | |
| 160 | /* OTG transceiver interface */ |
| 161 | |
| 162 | /* bind/unbind the peripheral controller */ |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 163 | static int gpio_vbus_set_peripheral(struct usb_otg *otg, |
| 164 | struct usb_gadget *gadget) |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 165 | { |
| 166 | struct gpio_vbus_data *gpio_vbus; |
| 167 | struct gpio_vbus_mach_info *pdata; |
| 168 | struct platform_device *pdev; |
| 169 | int gpio, irq; |
| 170 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 171 | gpio_vbus = container_of(otg->phy, struct gpio_vbus_data, phy); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 172 | pdev = to_platform_device(gpio_vbus->dev); |
| 173 | pdata = gpio_vbus->dev->platform_data; |
| 174 | irq = gpio_to_irq(pdata->gpio_vbus); |
| 175 | gpio = pdata->gpio_pullup; |
| 176 | |
| 177 | if (!gadget) { |
| 178 | dev_dbg(&pdev->dev, "unregistering gadget '%s'\n", |
| 179 | otg->gadget->name); |
| 180 | |
| 181 | /* optionally disable D+ pullup */ |
| 182 | if (gpio_is_valid(gpio)) |
| 183 | gpio_set_value(gpio, pdata->gpio_pullup_inverted); |
| 184 | |
| 185 | set_vbus_draw(gpio_vbus, 0); |
| 186 | |
| 187 | usb_gadget_vbus_disconnect(otg->gadget); |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 188 | otg->phy->state = OTG_STATE_UNDEFINED; |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 189 | |
| 190 | otg->gadget = NULL; |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | otg->gadget = gadget; |
| 195 | dev_dbg(&pdev->dev, "registered gadget '%s'\n", gadget->name); |
| 196 | |
| 197 | /* initialize connection state */ |
| 198 | gpio_vbus_irq(irq, pdev); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | /* effective for B devices, ignored for A-peripheral */ |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 203 | static int gpio_vbus_set_power(struct usb_phy *phy, unsigned mA) |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 204 | { |
| 205 | struct gpio_vbus_data *gpio_vbus; |
| 206 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 207 | gpio_vbus = container_of(phy, struct gpio_vbus_data, phy); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 208 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 209 | if (phy->state == OTG_STATE_B_PERIPHERAL) |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 210 | set_vbus_draw(gpio_vbus, mA); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /* for non-OTG B devices: set/clear transceiver suspend mode */ |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 215 | static int gpio_vbus_set_suspend(struct usb_phy *phy, int suspend) |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 216 | { |
| 217 | struct gpio_vbus_data *gpio_vbus; |
| 218 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 219 | gpio_vbus = container_of(phy, struct gpio_vbus_data, phy); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 220 | |
| 221 | /* draw max 0 mA from vbus in suspend mode; or the previously |
| 222 | * recorded amount of current if not suspended |
| 223 | * |
| 224 | * NOTE: high powered configs (mA > 100) may draw up to 2.5 mA |
| 225 | * if they're wake-enabled ... we don't handle that yet. |
| 226 | */ |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 227 | return gpio_vbus_set_power(phy, suspend ? 0 : gpio_vbus->mA); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* platform driver interface */ |
| 231 | |
| 232 | static int __init gpio_vbus_probe(struct platform_device *pdev) |
| 233 | { |
| 234 | struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; |
| 235 | struct gpio_vbus_data *gpio_vbus; |
| 236 | struct resource *res; |
| 237 | int err, gpio, irq; |
| 238 | |
| 239 | if (!pdata || !gpio_is_valid(pdata->gpio_vbus)) |
| 240 | return -EINVAL; |
| 241 | gpio = pdata->gpio_vbus; |
| 242 | |
| 243 | gpio_vbus = kzalloc(sizeof(struct gpio_vbus_data), GFP_KERNEL); |
| 244 | if (!gpio_vbus) |
| 245 | return -ENOMEM; |
| 246 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 247 | gpio_vbus->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); |
| 248 | if (!gpio_vbus->phy.otg) { |
| 249 | kfree(gpio_vbus); |
| 250 | return -ENOMEM; |
| 251 | } |
| 252 | |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 253 | platform_set_drvdata(pdev, gpio_vbus); |
| 254 | gpio_vbus->dev = &pdev->dev; |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 255 | gpio_vbus->phy.label = "gpio-vbus"; |
| 256 | gpio_vbus->phy.set_power = gpio_vbus_set_power; |
| 257 | gpio_vbus->phy.set_suspend = gpio_vbus_set_suspend; |
| 258 | gpio_vbus->phy.state = OTG_STATE_UNDEFINED; |
| 259 | |
| 260 | gpio_vbus->phy.otg->phy = &gpio_vbus->phy; |
| 261 | gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral; |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 262 | |
| 263 | err = gpio_request(gpio, "vbus_detect"); |
| 264 | if (err) { |
| 265 | dev_err(&pdev->dev, "can't request vbus gpio %d, err: %d\n", |
| 266 | gpio, err); |
| 267 | goto err_gpio; |
| 268 | } |
| 269 | gpio_direction_input(gpio); |
| 270 | |
| 271 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 272 | if (res) { |
| 273 | irq = res->start; |
| 274 | res->flags &= IRQF_TRIGGER_MASK; |
| 275 | res->flags |= IRQF_SAMPLE_RANDOM | IRQF_SHARED; |
| 276 | } else |
| 277 | irq = gpio_to_irq(gpio); |
| 278 | |
| 279 | /* if data line pullup is in use, initialize it to "not pulling up" */ |
| 280 | gpio = pdata->gpio_pullup; |
| 281 | if (gpio_is_valid(gpio)) { |
| 282 | err = gpio_request(gpio, "udc_pullup"); |
| 283 | if (err) { |
| 284 | dev_err(&pdev->dev, |
| 285 | "can't request pullup gpio %d, err: %d\n", |
| 286 | gpio, err); |
| 287 | gpio_free(pdata->gpio_vbus); |
| 288 | goto err_gpio; |
| 289 | } |
| 290 | gpio_direction_output(gpio, pdata->gpio_pullup_inverted); |
| 291 | } |
| 292 | |
| 293 | err = request_irq(irq, gpio_vbus_irq, VBUS_IRQ_FLAGS, |
| 294 | "vbus_detect", pdev); |
| 295 | if (err) { |
| 296 | dev_err(&pdev->dev, "can't request irq %i, err: %d\n", |
| 297 | irq, err); |
| 298 | goto err_irq; |
| 299 | } |
Heiko Stübner | 662c738 | 2012-02-29 23:03:11 +0100 | [diff] [blame] | 300 | |
| 301 | ATOMIC_INIT_NOTIFIER_HEAD(&gpio_vbus->phy.notifier); |
| 302 | |
Shinya Kuribayashi | 934ccec | 2012-05-10 10:31:21 +0900 | [diff] [blame^] | 303 | INIT_DELAYED_WORK(&gpio_vbus->work, gpio_vbus_work); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 304 | |
Dmitry Eremin-Solenikov | 2887ba9 | 2011-05-03 12:46:46 +0400 | [diff] [blame] | 305 | gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw"); |
| 306 | if (IS_ERR(gpio_vbus->vbus_draw)) { |
| 307 | dev_dbg(&pdev->dev, "can't get vbus_draw regulator, err: %ld\n", |
| 308 | PTR_ERR(gpio_vbus->vbus_draw)); |
| 309 | gpio_vbus->vbus_draw = NULL; |
| 310 | } |
| 311 | |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 312 | /* only active when a gadget is registered */ |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 313 | err = usb_set_transceiver(&gpio_vbus->phy); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 314 | if (err) { |
| 315 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", |
| 316 | err); |
| 317 | goto err_otg; |
| 318 | } |
| 319 | |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 320 | return 0; |
| 321 | err_otg: |
Shinya Kuribayashi | 0d13eeb | 2012-05-10 10:31:51 +0900 | [diff] [blame] | 322 | free_irq(irq, pdev); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 323 | err_irq: |
| 324 | if (gpio_is_valid(pdata->gpio_pullup)) |
| 325 | gpio_free(pdata->gpio_pullup); |
| 326 | gpio_free(pdata->gpio_vbus); |
| 327 | err_gpio: |
| 328 | platform_set_drvdata(pdev, NULL); |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 329 | kfree(gpio_vbus->phy.otg); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 330 | kfree(gpio_vbus); |
| 331 | return err; |
| 332 | } |
| 333 | |
| 334 | static int __exit gpio_vbus_remove(struct platform_device *pdev) |
| 335 | { |
| 336 | struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); |
| 337 | struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; |
| 338 | int gpio = pdata->gpio_vbus; |
| 339 | |
| 340 | regulator_put(gpio_vbus->vbus_draw); |
| 341 | |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 342 | usb_set_transceiver(NULL); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 343 | |
Shinya Kuribayashi | 0d13eeb | 2012-05-10 10:31:51 +0900 | [diff] [blame] | 344 | free_irq(gpio_to_irq(gpio), pdev); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 345 | if (gpio_is_valid(pdata->gpio_pullup)) |
| 346 | gpio_free(pdata->gpio_pullup); |
| 347 | gpio_free(gpio); |
| 348 | platform_set_drvdata(pdev, NULL); |
Heikki Krogerus | 16bc1bb | 2012-02-13 13:24:07 +0200 | [diff] [blame] | 349 | kfree(gpio_vbus->phy.otg); |
Philipp Zabel | 6084f1b | 2008-11-24 12:00:01 -0800 | [diff] [blame] | 350 | kfree(gpio_vbus); |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | /* NOTE: the gpio-vbus device may *NOT* be hotplugged */ |
| 356 | |
| 357 | MODULE_ALIAS("platform:gpio-vbus"); |
| 358 | |
| 359 | static struct platform_driver gpio_vbus_driver = { |
| 360 | .driver = { |
| 361 | .name = "gpio-vbus", |
| 362 | .owner = THIS_MODULE, |
| 363 | }, |
| 364 | .remove = __exit_p(gpio_vbus_remove), |
| 365 | }; |
| 366 | |
| 367 | static int __init gpio_vbus_init(void) |
| 368 | { |
| 369 | return platform_driver_probe(&gpio_vbus_driver, gpio_vbus_probe); |
| 370 | } |
| 371 | module_init(gpio_vbus_init); |
| 372 | |
| 373 | static void __exit gpio_vbus_exit(void) |
| 374 | { |
| 375 | platform_driver_unregister(&gpio_vbus_driver); |
| 376 | } |
| 377 | module_exit(gpio_vbus_exit); |
| 378 | |
| 379 | MODULE_DESCRIPTION("simple GPIO controlled OTG transceiver driver"); |
| 380 | MODULE_AUTHOR("Philipp Zabel"); |
| 381 | MODULE_LICENSE("GPL"); |