blob: 6907d8df7a2715b3c8fc06e290f593cb94f737bb [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>
28#include <linux/usb/otg.h>
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +053029#include <linux/usb/musb-omap.h>
Hema HKc33fad02010-12-10 17:58:20 +053030#include <linux/i2c/twl.h>
31#include <linux/regulator/consumer.h>
32#include <linux/err.h>
Hema HKc33fad02010-12-10 17:58:20 +053033#include <linux/slab.h>
Hema HK603ab522011-03-22 16:54:21 +053034#include <linux/delay.h>
Hema HKc33fad02010-12-10 17:58:20 +053035
36/* usb register definitions */
37#define USB_VENDOR_ID_LSB 0x00
38#define USB_VENDOR_ID_MSB 0x01
39#define USB_PRODUCT_ID_LSB 0x02
40#define USB_PRODUCT_ID_MSB 0x03
41#define USB_VBUS_CTRL_SET 0x04
42#define USB_VBUS_CTRL_CLR 0x05
43#define USB_ID_CTRL_SET 0x06
44#define USB_ID_CTRL_CLR 0x07
45#define USB_VBUS_INT_SRC 0x08
46#define USB_VBUS_INT_LATCH_SET 0x09
47#define USB_VBUS_INT_LATCH_CLR 0x0A
48#define USB_VBUS_INT_EN_LO_SET 0x0B
49#define USB_VBUS_INT_EN_LO_CLR 0x0C
50#define USB_VBUS_INT_EN_HI_SET 0x0D
51#define USB_VBUS_INT_EN_HI_CLR 0x0E
52#define USB_ID_INT_SRC 0x0F
53#define USB_ID_INT_LATCH_SET 0x10
54#define USB_ID_INT_LATCH_CLR 0x11
55
56#define USB_ID_INT_EN_LO_SET 0x12
57#define USB_ID_INT_EN_LO_CLR 0x13
58#define USB_ID_INT_EN_HI_SET 0x14
59#define USB_ID_INT_EN_HI_CLR 0x15
60#define USB_OTG_ADP_CTRL 0x16
61#define USB_OTG_ADP_HIGH 0x17
62#define USB_OTG_ADP_LOW 0x18
63#define USB_OTG_ADP_RISE 0x19
64#define USB_OTG_REVISION 0x1A
65
66/* to be moved to LDO */
67#define TWL6030_MISC2 0xE5
68#define TWL6030_CFG_LDO_PD2 0xF5
69#define TWL6030_BACKUP_REG 0xFA
70
71#define STS_HW_CONDITIONS 0x21
72
73/* In module TWL6030_MODULE_PM_MASTER */
74#define STS_HW_CONDITIONS 0x21
75#define STS_USB_ID BIT(2)
76
77/* In module TWL6030_MODULE_PM_RECEIVER */
78#define VUSB_CFG_TRANS 0x71
79#define VUSB_CFG_STATE 0x72
80#define VUSB_CFG_VOLTAGE 0x73
81
82/* in module TWL6030_MODULE_MAIN_CHARGE */
83
84#define CHARGERUSB_CTRL1 0x8
85
86#define CONTROLLER_STAT1 0x03
87#define VBUS_DET BIT(2)
88
89struct twl6030_usb {
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +020090 struct usb_phy phy;
Hema HKc33fad02010-12-10 17:58:20 +053091 struct device *dev;
92
93 /* for vbus reporting with irqs disabled */
94 spinlock_t lock;
95
96 struct regulator *usb3v3;
97
Moiz Sonasath5bf54502011-06-27 10:01:01 -050098 /* used to set vbus, in atomic path */
99 struct work_struct set_vbus_work;
100
Hema HKc33fad02010-12-10 17:58:20 +0530101 int irq1;
102 int irq2;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530103 enum omap_musb_vbus_id_status linkstat;
Hema HKc33fad02010-12-10 17:58:20 +0530104 u8 asleep;
105 bool irq_enabled;
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500106 bool vbus_enable;
Graeme Gregory5ccee4a2011-05-22 21:21:24 +0100107 unsigned long features;
Hema HKc33fad02010-12-10 17:58:20 +0530108};
109
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200110#define phy_to_twl(x) container_of((x), struct twl6030_usb, phy)
Hema HKc33fad02010-12-10 17:58:20 +0530111
112/*-------------------------------------------------------------------------*/
113
114static inline int twl6030_writeb(struct twl6030_usb *twl, u8 module,
115 u8 data, u8 address)
116{
117 int ret = 0;
118
119 ret = twl_i2c_write_u8(module, data, address);
120 if (ret < 0)
121 dev_err(twl->dev,
122 "Write[0x%x] Error %d\n", address, ret);
123 return ret;
124}
125
126static inline u8 twl6030_readb(struct twl6030_usb *twl, u8 module, u8 address)
127{
128 u8 data, ret = 0;
129
130 ret = twl_i2c_read_u8(module, &data, address);
131 if (ret >= 0)
132 ret = data;
133 else
134 dev_err(twl->dev,
135 "readb[0x%x,0x%x] Error %d\n",
136 module, address, ret);
137 return ret;
138}
139
Heikki Krogerus86753812012-02-13 13:24:02 +0200140static int twl6030_phy_init(struct usb_phy *x)
Hema HKc33fad02010-12-10 17:58:20 +0530141{
Hema HKc33fad02010-12-10 17:58:20 +0530142 struct twl6030_usb *twl;
143 struct device *dev;
144 struct twl4030_usb_data *pdata;
145
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200146 twl = phy_to_twl(x);
Hema HKc33fad02010-12-10 17:58:20 +0530147 dev = twl->dev;
148 pdata = dev->platform_data;
149
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530150 if (twl->linkstat == OMAP_MUSB_ID_GROUND)
Hema HKc33fad02010-12-10 17:58:20 +0530151 pdata->phy_power(twl->dev, 1, 1);
152 else
153 pdata->phy_power(twl->dev, 0, 1);
154
155 return 0;
156}
157
Heikki Krogerus86753812012-02-13 13:24:02 +0200158static void twl6030_phy_shutdown(struct usb_phy *x)
Hema HKc33fad02010-12-10 17:58:20 +0530159{
160 struct twl6030_usb *twl;
161 struct device *dev;
162 struct twl4030_usb_data *pdata;
163
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200164 twl = phy_to_twl(x);
Hema HKc33fad02010-12-10 17:58:20 +0530165 dev = twl->dev;
166 pdata = dev->platform_data;
167 pdata->phy_power(twl->dev, 0, 0);
Hema HKc33fad02010-12-10 17:58:20 +0530168}
169
Heikki Krogerus86753812012-02-13 13:24:02 +0200170static int twl6030_phy_suspend(struct usb_phy *x, int suspend)
Hema HK070b8ed2011-02-17 12:06:08 +0530171{
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200172 struct twl6030_usb *twl = phy_to_twl(x);
Hema HK070b8ed2011-02-17 12:06:08 +0530173 struct device *dev = twl->dev;
174 struct twl4030_usb_data *pdata = dev->platform_data;
175
176 pdata->phy_suspend(dev, suspend);
177
178 return 0;
179}
180
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200181static int twl6030_start_srp(struct usb_otg *otg)
Hema HK603ab522011-03-22 16:54:21 +0530182{
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200183 struct twl6030_usb *twl = phy_to_twl(otg->phy);
Hema HK603ab522011-03-22 16:54:21 +0530184
185 twl6030_writeb(twl, TWL_MODULE_USB, 0x24, USB_VBUS_CTRL_SET);
186 twl6030_writeb(twl, TWL_MODULE_USB, 0x84, USB_VBUS_CTRL_SET);
187
188 mdelay(100);
189 twl6030_writeb(twl, TWL_MODULE_USB, 0xa0, USB_VBUS_CTRL_CLR);
190
191 return 0;
192}
193
Hema HKc33fad02010-12-10 17:58:20 +0530194static int twl6030_usb_ldo_init(struct twl6030_usb *twl)
195{
Graeme Gregory5ccee4a2011-05-22 21:21:24 +0100196 char *regulator_name;
197
198 if (twl->features & TWL6025_SUBCLASS)
199 regulator_name = "ldousb";
200 else
201 regulator_name = "vusb";
Hema HKc33fad02010-12-10 17:58:20 +0530202
203 /* Set to OTG_REV 1.3 and turn on the ID_WAKEUP_COMP */
204 twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x1, TWL6030_BACKUP_REG);
205
206 /* Program CFG_LDO_PD2 register and set VUSB bit */
207 twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x1, TWL6030_CFG_LDO_PD2);
208
209 /* Program MISC2 register and set bit VUSB_IN_VBAT */
210 twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x10, TWL6030_MISC2);
211
Graeme Gregory5ccee4a2011-05-22 21:21:24 +0100212 twl->usb3v3 = regulator_get(twl->dev, regulator_name);
Hema HKc33fad02010-12-10 17:58:20 +0530213 if (IS_ERR(twl->usb3v3))
214 return -ENODEV;
215
Hema HKc33fad02010-12-10 17:58:20 +0530216 /* Program the USB_VBUS_CTRL_SET and set VBUS_ACT_COMP bit */
217 twl6030_writeb(twl, TWL_MODULE_USB, 0x4, USB_VBUS_CTRL_SET);
218
219 /*
220 * Program the USB_ID_CTRL_SET register to enable GND drive
221 * and the ID comparators
222 */
223 twl6030_writeb(twl, TWL_MODULE_USB, 0x14, USB_ID_CTRL_SET);
224
225 return 0;
226}
227
228static ssize_t twl6030_usb_vbus_show(struct device *dev,
229 struct device_attribute *attr, char *buf)
230{
231 struct twl6030_usb *twl = dev_get_drvdata(dev);
232 unsigned long flags;
233 int ret = -EINVAL;
234
235 spin_lock_irqsave(&twl->lock, flags);
236
237 switch (twl->linkstat) {
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530238 case OMAP_MUSB_VBUS_VALID:
Hema HKc33fad02010-12-10 17:58:20 +0530239 ret = snprintf(buf, PAGE_SIZE, "vbus\n");
240 break;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530241 case OMAP_MUSB_ID_GROUND:
Hema HKc33fad02010-12-10 17:58:20 +0530242 ret = snprintf(buf, PAGE_SIZE, "id\n");
243 break;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530244 case OMAP_MUSB_VBUS_OFF:
Hema HKc33fad02010-12-10 17:58:20 +0530245 ret = snprintf(buf, PAGE_SIZE, "none\n");
246 break;
247 default:
248 ret = snprintf(buf, PAGE_SIZE, "UNKNOWN\n");
249 }
250 spin_unlock_irqrestore(&twl->lock, flags);
251
252 return ret;
253}
254static DEVICE_ATTR(vbus, 0444, twl6030_usb_vbus_show, NULL);
255
256static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
257{
258 struct twl6030_usb *twl = _twl;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530259 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
Hema HKc33fad02010-12-10 17:58:20 +0530260 u8 vbus_state, hw_state;
261
262 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
263
264 vbus_state = twl6030_readb(twl, TWL_MODULE_MAIN_CHARGE,
265 CONTROLLER_STAT1);
266 if (!(hw_state & STS_USB_ID)) {
267 if (vbus_state & VBUS_DET) {
Hema HK6dc25032011-02-17 12:06:04 +0530268 regulator_enable(twl->usb3v3);
269 twl->asleep = 1;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530270 status = OMAP_MUSB_VBUS_VALID;
Hema HKc33fad02010-12-10 17:58:20 +0530271 twl->linkstat = status;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530272 omap_musb_mailbox(status);
Hema HK6dc25032011-02-17 12:06:04 +0530273 } else {
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530274 if (twl->linkstat != OMAP_MUSB_UNKNOWN) {
275 status = OMAP_MUSB_VBUS_OFF;
276 twl->linkstat = status;
277 omap_musb_mailbox(status);
278 if (twl->asleep) {
279 regulator_disable(twl->usb3v3);
280 twl->asleep = 0;
281 }
Hema HK6dc25032011-02-17 12:06:04 +0530282 }
Hema HKc33fad02010-12-10 17:58:20 +0530283 }
284 }
285 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
286
287 return IRQ_HANDLED;
288}
289
290static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
291{
292 struct twl6030_usb *twl = _twl;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530293 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
Hema HKc33fad02010-12-10 17:58:20 +0530294 u8 hw_state;
295
296 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
297
298 if (hw_state & STS_USB_ID) {
299
Hema HK6dc25032011-02-17 12:06:04 +0530300 regulator_enable(twl->usb3v3);
301 twl->asleep = 1;
Moiz Sonasathdc8738d2012-06-12 20:17:12 +0300302 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR);
303 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET);
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530304 status = OMAP_MUSB_ID_GROUND;
Hema HK31e99922011-02-17 12:06:05 +0530305 twl->linkstat = status;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530306 omap_musb_mailbox(status);
Hema HKc33fad02010-12-10 17:58:20 +0530307 } else {
Moiz Sonasathdc8738d2012-06-12 20:17:12 +0300308 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_CLR);
309 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET);
Hema HKc33fad02010-12-10 17:58:20 +0530310 }
Moiz Sonasathdc8738d2012-06-12 20:17:12 +0300311 twl6030_writeb(twl, TWL_MODULE_USB, status, USB_ID_INT_LATCH_CLR);
Hema HKc33fad02010-12-10 17:58:20 +0530312
313 return IRQ_HANDLED;
314}
315
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200316static int twl6030_set_peripheral(struct usb_otg *otg,
Hema HKc33fad02010-12-10 17:58:20 +0530317 struct usb_gadget *gadget)
318{
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200319 if (!otg)
Hema HKc33fad02010-12-10 17:58:20 +0530320 return -ENODEV;
321
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200322 otg->gadget = gadget;
Hema HKc33fad02010-12-10 17:58:20 +0530323 if (!gadget)
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200324 otg->phy->state = OTG_STATE_UNDEFINED;
Hema HKc33fad02010-12-10 17:58:20 +0530325
326 return 0;
327}
328
Heikki Krogerus86753812012-02-13 13:24:02 +0200329static int twl6030_enable_irq(struct usb_phy *x)
Hema HKc33fad02010-12-10 17:58:20 +0530330{
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200331 struct twl6030_usb *twl = phy_to_twl(x);
Hema HKc33fad02010-12-10 17:58:20 +0530332
Moiz Sonasathdc8738d2012-06-12 20:17:12 +0300333 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET);
Hema HKc33fad02010-12-10 17:58:20 +0530334 twl6030_interrupt_unmask(0x05, REG_INT_MSK_LINE_C);
335 twl6030_interrupt_unmask(0x05, REG_INT_MSK_STS_C);
336
337 twl6030_interrupt_unmask(TWL6030_CHARGER_CTRL_INT_MASK,
338 REG_INT_MSK_LINE_C);
339 twl6030_interrupt_unmask(TWL6030_CHARGER_CTRL_INT_MASK,
340 REG_INT_MSK_STS_C);
341 twl6030_usb_irq(twl->irq2, twl);
342 twl6030_usbotg_irq(twl->irq1, twl);
343
344 return 0;
345}
346
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500347static void otg_set_vbus_work(struct work_struct *data)
Hema HKc33fad02010-12-10 17:58:20 +0530348{
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500349 struct twl6030_usb *twl = container_of(data, struct twl6030_usb,
350 set_vbus_work);
Hema HKc33fad02010-12-10 17:58:20 +0530351
352 /*
353 * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1
354 * register. This enables boost mode.
355 */
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500356
357 if (twl->vbus_enable)
Hema HKc33fad02010-12-10 17:58:20 +0530358 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x40,
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500359 CHARGERUSB_CTRL1);
360 else
Hema HKc33fad02010-12-10 17:58:20 +0530361 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x00,
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500362 CHARGERUSB_CTRL1);
363}
364
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200365static int twl6030_set_vbus(struct usb_otg *otg, bool enabled)
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500366{
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200367 struct twl6030_usb *twl = phy_to_twl(otg->phy);
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500368
369 twl->vbus_enable = enabled;
370 schedule_work(&twl->set_vbus_work);
371
Hema HKc33fad02010-12-10 17:58:20 +0530372 return 0;
373}
374
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200375static int twl6030_set_host(struct usb_otg *otg, struct usb_bus *host)
Hema HKc33fad02010-12-10 17:58:20 +0530376{
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200377 if (!otg)
Hema HKc33fad02010-12-10 17:58:20 +0530378 return -ENODEV;
379
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200380 otg->host = host;
Hema HKc33fad02010-12-10 17:58:20 +0530381 if (!host)
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200382 otg->phy->state = OTG_STATE_UNDEFINED;
Hema HKc33fad02010-12-10 17:58:20 +0530383 return 0;
384}
385
386static int __devinit twl6030_usb_probe(struct platform_device *pdev)
387{
388 struct twl6030_usb *twl;
389 int status, err;
390 struct twl4030_usb_data *pdata;
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200391 struct usb_otg *otg;
Hema HKc33fad02010-12-10 17:58:20 +0530392 struct device *dev = &pdev->dev;
393 pdata = dev->platform_data;
394
Kishon Vijay Abraham Ib8a3efa2012-06-22 17:40:55 +0530395 twl = devm_kzalloc(dev, sizeof *twl, GFP_KERNEL);
Hema HKc33fad02010-12-10 17:58:20 +0530396 if (!twl)
397 return -ENOMEM;
398
Kishon Vijay Abraham Ib8a3efa2012-06-22 17:40:55 +0530399 otg = devm_kzalloc(dev, sizeof *otg, GFP_KERNEL);
400 if (!otg)
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200401 return -ENOMEM;
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200402
Hema HKc33fad02010-12-10 17:58:20 +0530403 twl->dev = &pdev->dev;
404 twl->irq1 = platform_get_irq(pdev, 0);
405 twl->irq2 = platform_get_irq(pdev, 1);
Graeme Gregory5ccee4a2011-05-22 21:21:24 +0100406 twl->features = pdata->features;
Kishon Vijay Abraham Ic9721432012-06-22 17:40:52 +0530407 twl->linkstat = OMAP_MUSB_UNKNOWN;
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200408
409 twl->phy.dev = twl->dev;
410 twl->phy.label = "twl6030";
411 twl->phy.otg = otg;
412 twl->phy.init = twl6030_phy_init;
413 twl->phy.shutdown = twl6030_phy_shutdown;
414 twl->phy.set_suspend = twl6030_phy_suspend;
415
416 otg->phy = &twl->phy;
417 otg->set_host = twl6030_set_host;
418 otg->set_peripheral = twl6030_set_peripheral;
419 otg->set_vbus = twl6030_set_vbus;
420 otg->start_srp = twl6030_start_srp;
Hema HKc33fad02010-12-10 17:58:20 +0530421
422 /* init spinlock for workqueue */
423 spin_lock_init(&twl->lock);
424
425 err = twl6030_usb_ldo_init(twl);
426 if (err) {
427 dev_err(&pdev->dev, "ldo init failed\n");
Hema HKc33fad02010-12-10 17:58:20 +0530428 return err;
429 }
Kishon Vijay Abraham I662dca52012-06-22 17:02:46 +0530430 usb_add_phy(&twl->phy, USB_PHY_TYPE_USB2);
Hema HKc33fad02010-12-10 17:58:20 +0530431
432 platform_set_drvdata(pdev, twl);
433 if (device_create_file(&pdev->dev, &dev_attr_vbus))
434 dev_warn(&pdev->dev, "could not create sysfs file\n");
435
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500436 INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
437
Hema HKc33fad02010-12-10 17:58:20 +0530438 twl->irq_enabled = true;
439 status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq,
Ming Lei8f9d9732012-05-17 11:38:24 +0800440 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Hema HKc33fad02010-12-10 17:58:20 +0530441 "twl6030_usb", twl);
442 if (status < 0) {
443 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
444 twl->irq1, status);
445 device_remove_file(twl->dev, &dev_attr_vbus);
Hema HKc33fad02010-12-10 17:58:20 +0530446 return status;
447 }
448
449 status = request_threaded_irq(twl->irq2, NULL, twl6030_usb_irq,
Ming Lei8f9d9732012-05-17 11:38:24 +0800450 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Hema HKc33fad02010-12-10 17:58:20 +0530451 "twl6030_usb", twl);
452 if (status < 0) {
453 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
454 twl->irq2, status);
455 free_irq(twl->irq1, twl);
456 device_remove_file(twl->dev, &dev_attr_vbus);
Hema HKc33fad02010-12-10 17:58:20 +0530457 return status;
458 }
459
Hema HK6dc25032011-02-17 12:06:04 +0530460 twl->asleep = 0;
Hema HKc33fad02010-12-10 17:58:20 +0530461 pdata->phy_init(dev);
Heikki Krogerus46b8f6b2012-02-13 13:24:12 +0200462 twl6030_phy_suspend(&twl->phy, 0);
463 twl6030_enable_irq(&twl->phy);
Hema HKc33fad02010-12-10 17:58:20 +0530464 dev_info(&pdev->dev, "Initialized TWL6030 USB module\n");
465
466 return 0;
467}
468
469static int __exit twl6030_usb_remove(struct platform_device *pdev)
470{
471 struct twl6030_usb *twl = platform_get_drvdata(pdev);
472
473 struct twl4030_usb_data *pdata;
474 struct device *dev = &pdev->dev;
475 pdata = dev->platform_data;
476
477 twl6030_interrupt_mask(TWL6030_USBOTG_INT_MASK,
478 REG_INT_MSK_LINE_C);
479 twl6030_interrupt_mask(TWL6030_USBOTG_INT_MASK,
480 REG_INT_MSK_STS_C);
481 free_irq(twl->irq1, twl);
482 free_irq(twl->irq2, twl);
483 regulator_put(twl->usb3v3);
484 pdata->phy_exit(twl->dev);
485 device_remove_file(twl->dev, &dev_attr_vbus);
Moiz Sonasath5bf54502011-06-27 10:01:01 -0500486 cancel_work_sync(&twl->set_vbus_work);
Hema HKc33fad02010-12-10 17:58:20 +0530487
488 return 0;
489}
490
491static struct platform_driver twl6030_usb_driver = {
492 .probe = twl6030_usb_probe,
493 .remove = __exit_p(twl6030_usb_remove),
494 .driver = {
495 .name = "twl6030_usb",
496 .owner = THIS_MODULE,
497 },
498};
499
500static int __init twl6030_usb_init(void)
501{
502 return platform_driver_register(&twl6030_usb_driver);
503}
504subsys_initcall(twl6030_usb_init);
505
506static void __exit twl6030_usb_exit(void)
507{
508 platform_driver_unregister(&twl6030_usb_driver);
509}
510module_exit(twl6030_usb_exit);
511
512MODULE_ALIAS("platform:twl6030_usb");
513MODULE_AUTHOR("Hema HK <hemahk@ti.com>");
514MODULE_DESCRIPTION("TWL6030 USB transceiver driver");
515MODULE_LICENSE("GPL");