blob: c66a447c3dfeea6303776b9a150adfbed1baeb77 [file] [log] [blame]
Hema HKc33fad02010-12-10 17:58:20 +05301/*
2 * twl6030_usb - TWL6030 USB transceiver, talking to OMAP OTG driver.
3 *
4 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Author: Hema HK <hemahk@ti.com>
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/platform_device.h>
27#include <linux/io.h>
Tony Lindgren80555552015-11-30 21:37:12 -080028#include <linux/usb/musb.h>
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +053029#include <linux/usb/phy_companion.h>
Kishon Vijay Abraham I6284be22014-03-03 17:08:14 +053030#include <linux/phy/omap_usb.h>
Hema HKc33fad02010-12-10 17:58:20 +053031#include <linux/i2c/twl.h>
32#include <linux/regulator/consumer.h>
33#include <linux/err.h>
Hema HKc33fad02010-12-10 17:58:20 +053034#include <linux/slab.h>
Hema HK603ab522011-03-22 16:54:21 +053035#include <linux/delay.h>
Sachin Kamat80d7d8a2013-10-17 13:55:06 +053036#include <linux/of.h>
Hema HKc33fad02010-12-10 17:58:20 +053037
38/* usb register definitions */
39#define USB_VENDOR_ID_LSB 0x00
40#define USB_VENDOR_ID_MSB 0x01
41#define USB_PRODUCT_ID_LSB 0x02
42#define USB_PRODUCT_ID_MSB 0x03
43#define USB_VBUS_CTRL_SET 0x04
44#define USB_VBUS_CTRL_CLR 0x05
45#define USB_ID_CTRL_SET 0x06
46#define USB_ID_CTRL_CLR 0x07
47#define USB_VBUS_INT_SRC 0x08
48#define USB_VBUS_INT_LATCH_SET 0x09
49#define USB_VBUS_INT_LATCH_CLR 0x0A
50#define USB_VBUS_INT_EN_LO_SET 0x0B
51#define USB_VBUS_INT_EN_LO_CLR 0x0C
52#define USB_VBUS_INT_EN_HI_SET 0x0D
53#define USB_VBUS_INT_EN_HI_CLR 0x0E
54#define USB_ID_INT_SRC 0x0F
55#define USB_ID_INT_LATCH_SET 0x10
56#define USB_ID_INT_LATCH_CLR 0x11
57
58#define USB_ID_INT_EN_LO_SET 0x12
59#define USB_ID_INT_EN_LO_CLR 0x13
60#define USB_ID_INT_EN_HI_SET 0x14
61#define USB_ID_INT_EN_HI_CLR 0x15
62#define USB_OTG_ADP_CTRL 0x16
63#define USB_OTG_ADP_HIGH 0x17
64#define USB_OTG_ADP_LOW 0x18
65#define USB_OTG_ADP_RISE 0x19
66#define USB_OTG_REVISION 0x1A
67
68/* to be moved to LDO */
69#define TWL6030_MISC2 0xE5
70#define TWL6030_CFG_LDO_PD2 0xF5
71#define TWL6030_BACKUP_REG 0xFA
72
73#define STS_HW_CONDITIONS 0x21
74
75/* In module TWL6030_MODULE_PM_MASTER */
76#define STS_HW_CONDITIONS 0x21
77#define STS_USB_ID BIT(2)
78
79/* In module TWL6030_MODULE_PM_RECEIVER */
80#define VUSB_CFG_TRANS 0x71
81#define VUSB_CFG_STATE 0x72
82#define VUSB_CFG_VOLTAGE 0x73
83
84/* in module TWL6030_MODULE_MAIN_CHARGE */
85
86#define CHARGERUSB_CTRL1 0x8
87
88#define CONTROLLER_STAT1 0x03
89#define VBUS_DET BIT(2)
90
91struct twl6030_usb {
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +053092 struct phy_companion comparator;
Hema HKc33fad02010-12-10 17:58:20 +053093 struct device *dev;
94
95 /* for vbus reporting with irqs disabled */
96 spinlock_t lock;
97
98 struct regulator *usb3v3;
99
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500100 /* used to set vbus, in atomic path */
101 struct work_struct set_vbus_work;
102
Hema HKc33fad02010-12-10 17:58:20 +0530103 int irq1;
104 int irq2;
Tony Lindgren80555552015-11-30 21:37:12 -0800105 enum musb_vbus_id_status linkstat;
Hema HKc33fad02010-12-10 17:58:20 +0530106 u8 asleep;
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500107 bool vbus_enable;
Kishon Vijay Abraham Iff0a1f32012-09-06 20:27:08 +0530108 const char *regulator;
Hema HKc33fad02010-12-10 17:58:20 +0530109};
110
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530111#define comparator_to_twl(x) container_of((x), struct twl6030_usb, comparator)
Hema HKc33fad02010-12-10 17:58:20 +0530112
113/*-------------------------------------------------------------------------*/
114
115static inline int twl6030_writeb(struct twl6030_usb *twl, u8 module,
116 u8 data, u8 address)
117{
118 int ret = 0;
119
120 ret = twl_i2c_write_u8(module, data, address);
121 if (ret < 0)
122 dev_err(twl->dev,
123 "Write[0x%x] Error %d\n", address, ret);
124 return ret;
125}
126
127static inline u8 twl6030_readb(struct twl6030_usb *twl, u8 module, u8 address)
128{
Dan Carpenter0b551492013-11-08 01:43:17 -0800129 u8 data;
130 int ret;
Hema HKc33fad02010-12-10 17:58:20 +0530131
132 ret = twl_i2c_read_u8(module, &data, address);
133 if (ret >= 0)
134 ret = data;
135 else
136 dev_err(twl->dev,
137 "readb[0x%x,0x%x] Error %d\n",
138 module, address, ret);
139 return ret;
140}
141
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530142static int twl6030_start_srp(struct phy_companion *comparator)
Hema HKc33fad02010-12-10 17:58:20 +0530143{
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530144 struct twl6030_usb *twl = comparator_to_twl(comparator);
Hema HK603ab522011-03-22 16:54:21 +0530145
146 twl6030_writeb(twl, TWL_MODULE_USB, 0x24, USB_VBUS_CTRL_SET);
147 twl6030_writeb(twl, TWL_MODULE_USB, 0x84, USB_VBUS_CTRL_SET);
148
149 mdelay(100);
150 twl6030_writeb(twl, TWL_MODULE_USB, 0xa0, USB_VBUS_CTRL_CLR);
151
152 return 0;
153}
154
Hema HKc33fad02010-12-10 17:58:20 +0530155static int twl6030_usb_ldo_init(struct twl6030_usb *twl)
156{
Hema HKc33fad02010-12-10 17:58:20 +0530157 /* Set to OTG_REV 1.3 and turn on the ID_WAKEUP_COMP */
Sandhya Bankar13069bd2016-05-04 08:00:54 +0530158 twl6030_writeb(twl, TWL6030_MODULE_ID0, 0x1, TWL6030_BACKUP_REG);
Hema HKc33fad02010-12-10 17:58:20 +0530159
160 /* Program CFG_LDO_PD2 register and set VUSB bit */
Sandhya Bankar13069bd2016-05-04 08:00:54 +0530161 twl6030_writeb(twl, TWL6030_MODULE_ID0, 0x1, TWL6030_CFG_LDO_PD2);
Hema HKc33fad02010-12-10 17:58:20 +0530162
163 /* Program MISC2 register and set bit VUSB_IN_VBAT */
Sandhya Bankar13069bd2016-05-04 08:00:54 +0530164 twl6030_writeb(twl, TWL6030_MODULE_ID0, 0x10, TWL6030_MISC2);
Hema HKc33fad02010-12-10 17:58:20 +0530165
Kishon Vijay Abraham Iff0a1f32012-09-06 20:27:08 +0530166 twl->usb3v3 = regulator_get(twl->dev, twl->regulator);
Hema HKc33fad02010-12-10 17:58:20 +0530167 if (IS_ERR(twl->usb3v3))
168 return -ENODEV;
169
Hema HKc33fad02010-12-10 17:58:20 +0530170 /* Program the USB_VBUS_CTRL_SET and set VBUS_ACT_COMP bit */
171 twl6030_writeb(twl, TWL_MODULE_USB, 0x4, USB_VBUS_CTRL_SET);
172
173 /*
174 * Program the USB_ID_CTRL_SET register to enable GND drive
175 * and the ID comparators
176 */
177 twl6030_writeb(twl, TWL_MODULE_USB, 0x14, USB_ID_CTRL_SET);
178
179 return 0;
180}
181
182static ssize_t twl6030_usb_vbus_show(struct device *dev,
183 struct device_attribute *attr, char *buf)
184{
185 struct twl6030_usb *twl = dev_get_drvdata(dev);
186 unsigned long flags;
187 int ret = -EINVAL;
188
189 spin_lock_irqsave(&twl->lock, flags);
190
191 switch (twl->linkstat) {
Tony Lindgren80555552015-11-30 21:37:12 -0800192 case MUSB_VBUS_VALID:
Hema HKc33fad02010-12-10 17:58:20 +0530193 ret = snprintf(buf, PAGE_SIZE, "vbus\n");
194 break;
Tony Lindgren80555552015-11-30 21:37:12 -0800195 case MUSB_ID_GROUND:
Hema HKc33fad02010-12-10 17:58:20 +0530196 ret = snprintf(buf, PAGE_SIZE, "id\n");
197 break;
Tony Lindgren80555552015-11-30 21:37:12 -0800198 case MUSB_VBUS_OFF:
Hema HKc33fad02010-12-10 17:58:20 +0530199 ret = snprintf(buf, PAGE_SIZE, "none\n");
200 break;
201 default:
202 ret = snprintf(buf, PAGE_SIZE, "UNKNOWN\n");
203 }
204 spin_unlock_irqrestore(&twl->lock, flags);
205
206 return ret;
207}
208static DEVICE_ATTR(vbus, 0444, twl6030_usb_vbus_show, NULL);
209
210static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
211{
212 struct twl6030_usb *twl = _twl;
Tony Lindgren80555552015-11-30 21:37:12 -0800213 enum musb_vbus_id_status status = MUSB_UNKNOWN;
Hema HKc33fad02010-12-10 17:58:20 +0530214 u8 vbus_state, hw_state;
Fabio Baltieribb545422013-04-03 16:02:27 +0200215 int ret;
Hema HKc33fad02010-12-10 17:58:20 +0530216
217 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
218
219 vbus_state = twl6030_readb(twl, TWL_MODULE_MAIN_CHARGE,
220 CONTROLLER_STAT1);
221 if (!(hw_state & STS_USB_ID)) {
222 if (vbus_state & VBUS_DET) {
Fabio Baltieribb545422013-04-03 16:02:27 +0200223 ret = regulator_enable(twl->usb3v3);
224 if (ret)
225 dev_err(twl->dev, "Failed to enable usb3v3\n");
226
Hema HK6dc25032011-02-17 12:06:04 +0530227 twl->asleep = 1;
Tony Lindgren80555552015-11-30 21:37:12 -0800228 status = MUSB_VBUS_VALID;
Hema HKc33fad02010-12-10 17:58:20 +0530229 twl->linkstat = status;
Tony Lindgren12b7db22016-05-31 10:05:19 -0500230 ret = musb_mailbox(status);
231 if (ret)
232 twl->linkstat = MUSB_UNKNOWN;
Hema HK6dc25032011-02-17 12:06:04 +0530233 } else {
Tony Lindgren80555552015-11-30 21:37:12 -0800234 if (twl->linkstat != MUSB_UNKNOWN) {
235 status = MUSB_VBUS_OFF;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530236 twl->linkstat = status;
Tony Lindgren12b7db22016-05-31 10:05:19 -0500237 ret = musb_mailbox(status);
238 if (ret)
239 twl->linkstat = MUSB_UNKNOWN;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530240 if (twl->asleep) {
241 regulator_disable(twl->usb3v3);
242 twl->asleep = 0;
243 }
Hema HK6dc25032011-02-17 12:06:04 +0530244 }
Hema HKc33fad02010-12-10 17:58:20 +0530245 }
246 }
247 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
248
249 return IRQ_HANDLED;
250}
251
252static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
253{
254 struct twl6030_usb *twl = _twl;
Tony Lindgren80555552015-11-30 21:37:12 -0800255 enum musb_vbus_id_status status = MUSB_UNKNOWN;
Hema HKc33fad02010-12-10 17:58:20 +0530256 u8 hw_state;
Fabio Baltieribb545422013-04-03 16:02:27 +0200257 int ret;
Hema HKc33fad02010-12-10 17:58:20 +0530258
259 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
260
261 if (hw_state & STS_USB_ID) {
Fabio Baltieribb545422013-04-03 16:02:27 +0200262 ret = regulator_enable(twl->usb3v3);
263 if (ret)
264 dev_err(twl->dev, "Failed to enable usb3v3\n");
Hema HKc33fad02010-12-10 17:58:20 +0530265
Hema HK6dc25032011-02-17 12:06:04 +0530266 twl->asleep = 1;
Moiz Sonasathdc8738d2012-06-12 20:17:12 +0300267 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR);
268 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET);
Tony Lindgren80555552015-11-30 21:37:12 -0800269 status = MUSB_ID_GROUND;
Hema HK31e99922011-02-17 12:06:05 +0530270 twl->linkstat = status;
Tony Lindgren12b7db22016-05-31 10:05:19 -0500271 ret = musb_mailbox(status);
272 if (ret)
273 twl->linkstat = MUSB_UNKNOWN;
Hema HKc33fad02010-12-10 17:58:20 +0530274 } else {
Moiz Sonasathdc8738d2012-06-12 20:17:12 +0300275 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_CLR);
276 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET);
Hema HKc33fad02010-12-10 17:58:20 +0530277 }
Moiz Sonasathdc8738d2012-06-12 20:17:12 +0300278 twl6030_writeb(twl, TWL_MODULE_USB, status, USB_ID_INT_LATCH_CLR);
Hema HKc33fad02010-12-10 17:58:20 +0530279
280 return IRQ_HANDLED;
281}
282
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530283static int twl6030_enable_irq(struct twl6030_usb *twl)
Hema HKc33fad02010-12-10 17:58:20 +0530284{
Moiz Sonasathdc8738d2012-06-12 20:17:12 +0300285 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET);
Hema HKc33fad02010-12-10 17:58:20 +0530286 twl6030_interrupt_unmask(0x05, REG_INT_MSK_LINE_C);
287 twl6030_interrupt_unmask(0x05, REG_INT_MSK_STS_C);
288
289 twl6030_interrupt_unmask(TWL6030_CHARGER_CTRL_INT_MASK,
290 REG_INT_MSK_LINE_C);
291 twl6030_interrupt_unmask(TWL6030_CHARGER_CTRL_INT_MASK,
292 REG_INT_MSK_STS_C);
293 twl6030_usb_irq(twl->irq2, twl);
294 twl6030_usbotg_irq(twl->irq1, twl);
295
296 return 0;
297}
298
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500299static void otg_set_vbus_work(struct work_struct *data)
Hema HKc33fad02010-12-10 17:58:20 +0530300{
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500301 struct twl6030_usb *twl = container_of(data, struct twl6030_usb,
302 set_vbus_work);
Hema HKc33fad02010-12-10 17:58:20 +0530303
304 /*
305 * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1
306 * register. This enables boost mode.
307 */
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500308
309 if (twl->vbus_enable)
Sandhya Bankar13069bd2016-05-04 08:00:54 +0530310 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE, 0x40,
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500311 CHARGERUSB_CTRL1);
312 else
Sandhya Bankar13069bd2016-05-04 08:00:54 +0530313 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE, 0x00,
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500314 CHARGERUSB_CTRL1);
315}
316
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530317static int twl6030_set_vbus(struct phy_companion *comparator, bool enabled)
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500318{
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530319 struct twl6030_usb *twl = comparator_to_twl(comparator);
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500320
321 twl->vbus_enable = enabled;
322 schedule_work(&twl->set_vbus_work);
323
Hema HKc33fad02010-12-10 17:58:20 +0530324 return 0;
325}
326
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500327static int twl6030_usb_probe(struct platform_device *pdev)
Hema HKc33fad02010-12-10 17:58:20 +0530328{
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530329 u32 ret;
Hema HKc33fad02010-12-10 17:58:20 +0530330 struct twl6030_usb *twl;
331 int status, err;
Kishon Vijay Abraham Iff0a1f32012-09-06 20:27:08 +0530332 struct device_node *np = pdev->dev.of_node;
333 struct device *dev = &pdev->dev;
Jingoo Han19f9e182013-07-30 17:02:13 +0900334 struct twl4030_usb_data *pdata = dev_get_platdata(dev);
Hema HKc33fad02010-12-10 17:58:20 +0530335
Sachin Kamat2ee8ff32013-12-21 15:20:09 +0530336 twl = devm_kzalloc(dev, sizeof(*twl), GFP_KERNEL);
Hema HKc33fad02010-12-10 17:58:20 +0530337 if (!twl)
338 return -ENOMEM;
339
340 twl->dev = &pdev->dev;
341 twl->irq1 = platform_get_irq(pdev, 0);
342 twl->irq2 = platform_get_irq(pdev, 1);
Tony Lindgren80555552015-11-30 21:37:12 -0800343 twl->linkstat = MUSB_UNKNOWN;
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200344
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530345 twl->comparator.set_vbus = twl6030_set_vbus;
346 twl->comparator.start_srp = twl6030_start_srp;
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200347
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530348 ret = omap_usb2_set_comparator(&twl->comparator);
349 if (ret == -ENODEV) {
350 dev_info(&pdev->dev, "phy not ready, deferring probe");
351 return -EPROBE_DEFER;
352 }
Hema HKc33fad02010-12-10 17:58:20 +0530353
Kishon Vijay Abraham Iff0a1f32012-09-06 20:27:08 +0530354 if (np) {
355 twl->regulator = "usb";
356 } else if (pdata) {
Graeme Gregory89ce43f2013-06-19 15:24:02 +0300357 if (pdata->features & TWL6032_SUBCLASS)
Kishon Vijay Abraham Iff0a1f32012-09-06 20:27:08 +0530358 twl->regulator = "ldousb";
359 else
360 twl->regulator = "vusb";
361 } else {
362 dev_err(&pdev->dev, "twl6030 initialized without pdata\n");
363 return -EINVAL;
364 }
365
Hema HKc33fad02010-12-10 17:58:20 +0530366 /* init spinlock for workqueue */
367 spin_lock_init(&twl->lock);
368
369 err = twl6030_usb_ldo_init(twl);
370 if (err) {
371 dev_err(&pdev->dev, "ldo init failed\n");
Hema HKc33fad02010-12-10 17:58:20 +0530372 return err;
373 }
Hema HKc33fad02010-12-10 17:58:20 +0530374
375 platform_set_drvdata(pdev, twl);
376 if (device_create_file(&pdev->dev, &dev_attr_vbus))
377 dev_warn(&pdev->dev, "could not create sysfs file\n");
378
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500379 INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
380
Hema HKc33fad02010-12-10 17:58:20 +0530381 status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq,
Ming Lei8f9d9732012-05-17 11:38:24 +0800382 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Hema HKc33fad02010-12-10 17:58:20 +0530383 "twl6030_usb", twl);
384 if (status < 0) {
385 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
386 twl->irq1, status);
387 device_remove_file(twl->dev, &dev_attr_vbus);
Hema HKc33fad02010-12-10 17:58:20 +0530388 return status;
389 }
390
391 status = request_threaded_irq(twl->irq2, NULL, twl6030_usb_irq,
Ming Lei8f9d9732012-05-17 11:38:24 +0800392 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Hema HKc33fad02010-12-10 17:58:20 +0530393 "twl6030_usb", twl);
394 if (status < 0) {
395 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
396 twl->irq2, status);
397 free_irq(twl->irq1, twl);
398 device_remove_file(twl->dev, &dev_attr_vbus);
Hema HKc33fad02010-12-10 17:58:20 +0530399 return status;
400 }
401
Hema HK6dc25032011-02-17 12:06:04 +0530402 twl->asleep = 0;
Kishon Vijay Abraham I0e98de62012-09-06 20:27:07 +0530403 twl6030_enable_irq(twl);
Hema HKc33fad02010-12-10 17:58:20 +0530404 dev_info(&pdev->dev, "Initialized TWL6030 USB module\n");
405
406 return 0;
407}
408
Dmitry Torokhov39d35682013-02-24 00:55:07 -0800409static int twl6030_usb_remove(struct platform_device *pdev)
Hema HKc33fad02010-12-10 17:58:20 +0530410{
411 struct twl6030_usb *twl = platform_get_drvdata(pdev);
412
Hema HKc33fad02010-12-10 17:58:20 +0530413 twl6030_interrupt_mask(TWL6030_USBOTG_INT_MASK,
414 REG_INT_MSK_LINE_C);
415 twl6030_interrupt_mask(TWL6030_USBOTG_INT_MASK,
416 REG_INT_MSK_STS_C);
417 free_irq(twl->irq1, twl);
418 free_irq(twl->irq2, twl);
419 regulator_put(twl->usb3v3);
Hema HKc33fad02010-12-10 17:58:20 +0530420 device_remove_file(twl->dev, &dev_attr_vbus);
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500421 cancel_work_sync(&twl->set_vbus_work);
Hema HKc33fad02010-12-10 17:58:20 +0530422
423 return 0;
424}
425
Kishon Vijay Abraham Iff0a1f32012-09-06 20:27:08 +0530426#ifdef CONFIG_OF
427static const struct of_device_id twl6030_usb_id_table[] = {
428 { .compatible = "ti,twl6030-usb" },
429 {}
430};
431MODULE_DEVICE_TABLE(of, twl6030_usb_id_table);
432#endif
433
Hema HKc33fad02010-12-10 17:58:20 +0530434static struct platform_driver twl6030_usb_driver = {
435 .probe = twl6030_usb_probe,
Dmitry Torokhov39d35682013-02-24 00:55:07 -0800436 .remove = twl6030_usb_remove,
Hema HKc33fad02010-12-10 17:58:20 +0530437 .driver = {
438 .name = "twl6030_usb",
Kishon Vijay Abraham Iff0a1f32012-09-06 20:27:08 +0530439 .of_match_table = of_match_ptr(twl6030_usb_id_table),
Hema HKc33fad02010-12-10 17:58:20 +0530440 },
441};
442
443static int __init twl6030_usb_init(void)
444{
445 return platform_driver_register(&twl6030_usb_driver);
446}
447subsys_initcall(twl6030_usb_init);
448
449static void __exit twl6030_usb_exit(void)
450{
451 platform_driver_unregister(&twl6030_usb_driver);
452}
453module_exit(twl6030_usb_exit);
454
455MODULE_ALIAS("platform:twl6030_usb");
456MODULE_AUTHOR("Hema HK <hemahk@ti.com>");
457MODULE_DESCRIPTION("TWL6030 USB transceiver driver");
458MODULE_LICENSE("GPL");