blob: 6dd65e866f8268840805de03e21a46eb0ed2feb9 [file] [log] [blame]
Manu Gautam5143b252012-01-05 19:25:23 -08001/* Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053012 */
13
14#include <linux/module.h>
15#include <linux/device.h>
16#include <linux/platform_device.h>
17#include <linux/clk.h>
18#include <linux/slab.h>
19#include <linux/interrupt.h>
20#include <linux/err.h>
21#include <linux/delay.h>
22#include <linux/io.h>
23#include <linux/ioport.h>
24#include <linux/uaccess.h>
25#include <linux/debugfs.h>
26#include <linux/seq_file.h>
Pavankumar Kondeti87c01042010-12-07 17:53:58 +053027#include <linux/pm_runtime.h>
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +053028#include <linux/of.h>
29#include <linux/dma-mapping.h>
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053030
31#include <linux/usb.h>
32#include <linux/usb/otg.h>
33#include <linux/usb/ulpi.h>
34#include <linux/usb/gadget.h>
35#include <linux/usb/hcd.h>
36#include <linux/usb/msm_hsusb.h>
37#include <linux/usb/msm_hsusb_hw.h>
Anji jonnala11aa5c42011-05-04 10:19:48 +053038#include <linux/regulator/consumer.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039#include <linux/mfd/pm8xxx/pm8921-charger.h>
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +053040#include <linux/pm_qos_params.h>
Amit Blay0f7edf72012-01-15 10:11:27 +020041#include <linux/power_supply.h>
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053042
43#include <mach/clk.h>
Anji jonnala7da3f262011-12-02 17:22:14 -080044#include <mach/msm_xo.h>
Manu Gautamcd82e9d2011-12-20 14:17:28 +053045#include <mach/msm_bus.h>
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053046
47#define MSM_USB_BASE (motg->regs)
48#define DRIVER_NAME "msm_otg"
49
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +053050#define ID_TIMER_FREQ (jiffies + msecs_to_jiffies(2000))
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053051#define ULPI_IO_TIMEOUT_USEC (10 * 1000)
Anji jonnala11aa5c42011-05-04 10:19:48 +053052
53#define USB_PHY_3P3_VOL_MIN 3050000 /* uV */
54#define USB_PHY_3P3_VOL_MAX 3300000 /* uV */
55#define USB_PHY_3P3_HPM_LOAD 50000 /* uA */
56#define USB_PHY_3P3_LPM_LOAD 4000 /* uA */
57
58#define USB_PHY_1P8_VOL_MIN 1800000 /* uV */
59#define USB_PHY_1P8_VOL_MAX 1800000 /* uV */
60#define USB_PHY_1P8_HPM_LOAD 50000 /* uA */
61#define USB_PHY_1P8_LPM_LOAD 4000 /* uA */
62
Vamsi Krishna132b2762011-11-11 16:09:20 -080063#define USB_PHY_VDD_DIG_VOL_MIN 1045000 /* uV */
Anji jonnala11aa5c42011-05-04 10:19:48 +053064#define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */
65
Pavankumar Kondeti4960f312011-12-06 15:46:14 +053066static DECLARE_COMPLETION(pmic_vbus_init);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067static struct msm_otg *the_msm_otg;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +053068static bool debug_aca_enabled;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070069
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +053070/* Prevent idle power collapse(pc) while operating in peripheral mode */
71static void otg_pm_qos_update_latency(struct msm_otg *dev, int vote)
72{
73 struct msm_otg_platform_data *pdata = dev->pdata;
74 u32 swfi_latency = 0;
75
76 if (!pdata || !pdata->swfi_latency)
77 return;
78
79 swfi_latency = pdata->swfi_latency + 1;
80
81 if (vote)
82 pm_qos_update_request(&dev->pm_qos_req_dma,
83 swfi_latency);
84 else
85 pm_qos_update_request(&dev->pm_qos_req_dma,
86 PM_QOS_DEFAULT_VALUE);
87}
88
Anji jonnala11aa5c42011-05-04 10:19:48 +053089static struct regulator *hsusb_3p3;
90static struct regulator *hsusb_1p8;
91static struct regulator *hsusb_vddcx;
Mayank Ranae3926882011-12-26 09:47:54 +053092static struct regulator *vbus_otg;
Anji jonnala11aa5c42011-05-04 10:19:48 +053093
Pavankumar Kondeti4960f312011-12-06 15:46:14 +053094static bool aca_id_turned_on;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +053095static inline bool aca_enabled(void)
96{
97#ifdef CONFIG_USB_MSM_ACA
98 return true;
99#else
100 return debug_aca_enabled;
101#endif
102}
103
Anji jonnala11aa5c42011-05-04 10:19:48 +0530104static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
105{
106 int ret = 0;
107
108 if (init) {
109 hsusb_vddcx = regulator_get(motg->otg.dev, "HSUSB_VDDCX");
110 if (IS_ERR(hsusb_vddcx)) {
111 dev_err(motg->otg.dev, "unable to get hsusb vddcx\n");
112 return PTR_ERR(hsusb_vddcx);
113 }
114
115 ret = regulator_set_voltage(hsusb_vddcx,
116 USB_PHY_VDD_DIG_VOL_MIN,
117 USB_PHY_VDD_DIG_VOL_MAX);
118 if (ret) {
119 dev_err(motg->otg.dev, "unable to set the voltage "
120 "for hsusb vddcx\n");
121 regulator_put(hsusb_vddcx);
122 return ret;
123 }
124
125 ret = regulator_enable(hsusb_vddcx);
126 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700127 regulator_set_voltage(hsusb_vddcx, 0,
128 USB_PHY_VDD_DIG_VOL_MIN);
Anji jonnala11aa5c42011-05-04 10:19:48 +0530129 regulator_put(hsusb_vddcx);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130 dev_err(motg->otg.dev, "unable to enable the hsusb vddcx\n");
131 return ret;
Anji jonnala11aa5c42011-05-04 10:19:48 +0530132 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133
Anji jonnala11aa5c42011-05-04 10:19:48 +0530134 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700135
Anji jonnala11aa5c42011-05-04 10:19:48 +0530136 ret = regulator_disable(hsusb_vddcx);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700137 if (ret) {
Anji jonnala11aa5c42011-05-04 10:19:48 +0530138 dev_err(motg->otg.dev, "unable to disable hsusb vddcx\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139 return ret;
140 }
141
142 ret = regulator_set_voltage(hsusb_vddcx, 0,
143 USB_PHY_VDD_DIG_VOL_MIN);
144 if (ret) {
145 dev_err(motg->otg.dev, "unable to set the voltage"
146 "for hsusb vddcx\n");
147 return ret;
148 }
Anji jonnala11aa5c42011-05-04 10:19:48 +0530149
150 regulator_put(hsusb_vddcx);
151 }
152
153 return ret;
154}
155
156static int msm_hsusb_ldo_init(struct msm_otg *motg, int init)
157{
158 int rc = 0;
159
160 if (init) {
161 hsusb_3p3 = regulator_get(motg->otg.dev, "HSUSB_3p3");
162 if (IS_ERR(hsusb_3p3)) {
163 dev_err(motg->otg.dev, "unable to get hsusb 3p3\n");
164 return PTR_ERR(hsusb_3p3);
165 }
166
167 rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN,
168 USB_PHY_3P3_VOL_MAX);
169 if (rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170 dev_err(motg->otg.dev, "unable to set voltage level for"
171 "hsusb 3p3\n");
Anji jonnala11aa5c42011-05-04 10:19:48 +0530172 goto put_3p3;
173 }
174 hsusb_1p8 = regulator_get(motg->otg.dev, "HSUSB_1p8");
175 if (IS_ERR(hsusb_1p8)) {
176 dev_err(motg->otg.dev, "unable to get hsusb 1p8\n");
177 rc = PTR_ERR(hsusb_1p8);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178 goto put_3p3_lpm;
Anji jonnala11aa5c42011-05-04 10:19:48 +0530179 }
180 rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN,
181 USB_PHY_1P8_VOL_MAX);
182 if (rc) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183 dev_err(motg->otg.dev, "unable to set voltage level for"
184 "hsusb 1p8\n");
Anji jonnala11aa5c42011-05-04 10:19:48 +0530185 goto put_1p8;
186 }
187
188 return 0;
189 }
190
Anji jonnala11aa5c42011-05-04 10:19:48 +0530191put_1p8:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192 regulator_set_voltage(hsusb_1p8, 0, USB_PHY_1P8_VOL_MAX);
Anji jonnala11aa5c42011-05-04 10:19:48 +0530193 regulator_put(hsusb_1p8);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194put_3p3_lpm:
195 regulator_set_voltage(hsusb_3p3, 0, USB_PHY_3P3_VOL_MAX);
Anji jonnala11aa5c42011-05-04 10:19:48 +0530196put_3p3:
197 regulator_put(hsusb_3p3);
198 return rc;
199}
200
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530201#ifdef CONFIG_PM_SLEEP
202#define USB_PHY_SUSP_DIG_VOL 500000
203static int msm_hsusb_config_vddcx(int high)
204{
205 int max_vol = USB_PHY_VDD_DIG_VOL_MAX;
206 int min_vol;
207 int ret;
208
209 if (high)
210 min_vol = USB_PHY_VDD_DIG_VOL_MIN;
211 else
212 min_vol = USB_PHY_SUSP_DIG_VOL;
213
214 ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol);
215 if (ret) {
216 pr_err("%s: unable to set the voltage for regulator "
217 "HSUSB_VDDCX\n", __func__);
218 return ret;
219 }
220
221 pr_debug("%s: min_vol:%d max_vol:%d\n", __func__, min_vol, max_vol);
222
223 return ret;
224}
Hemant Kumar8e7bd072011-08-01 14:14:24 -0700225#else
226static int msm_hsusb_config_vddcx(int high)
227{
228 return 0;
229}
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530230#endif
231
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700232static int msm_hsusb_ldo_enable(struct msm_otg *motg, int on)
Anji jonnala11aa5c42011-05-04 10:19:48 +0530233{
234 int ret = 0;
235
Pavankumar Kondeti68964c92011-10-27 14:58:56 +0530236 if (IS_ERR(hsusb_1p8)) {
Anji jonnala11aa5c42011-05-04 10:19:48 +0530237 pr_err("%s: HSUSB_1p8 is not initialized\n", __func__);
238 return -ENODEV;
239 }
240
Pavankumar Kondeti68964c92011-10-27 14:58:56 +0530241 if (IS_ERR(hsusb_3p3)) {
Anji jonnala11aa5c42011-05-04 10:19:48 +0530242 pr_err("%s: HSUSB_3p3 is not initialized\n", __func__);
243 return -ENODEV;
244 }
245
246 if (on) {
247 ret = regulator_set_optimum_mode(hsusb_1p8,
248 USB_PHY_1P8_HPM_LOAD);
249 if (ret < 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250 pr_err("%s: Unable to set HPM of the regulator:"
Anji jonnala11aa5c42011-05-04 10:19:48 +0530251 "HSUSB_1p8\n", __func__);
252 return ret;
253 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700254
255 ret = regulator_enable(hsusb_1p8);
256 if (ret) {
257 dev_err(motg->otg.dev, "%s: unable to enable the hsusb 1p8\n",
258 __func__);
259 regulator_set_optimum_mode(hsusb_1p8, 0);
260 return ret;
261 }
262
Anji jonnala11aa5c42011-05-04 10:19:48 +0530263 ret = regulator_set_optimum_mode(hsusb_3p3,
264 USB_PHY_3P3_HPM_LOAD);
265 if (ret < 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700266 pr_err("%s: Unable to set HPM of the regulator:"
Anji jonnala11aa5c42011-05-04 10:19:48 +0530267 "HSUSB_3p3\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700268 regulator_set_optimum_mode(hsusb_1p8, 0);
269 regulator_disable(hsusb_1p8);
Anji jonnala11aa5c42011-05-04 10:19:48 +0530270 return ret;
271 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272
273 ret = regulator_enable(hsusb_3p3);
274 if (ret) {
275 dev_err(motg->otg.dev, "%s: unable to enable the hsusb 3p3\n",
276 __func__);
277 regulator_set_optimum_mode(hsusb_3p3, 0);
278 regulator_set_optimum_mode(hsusb_1p8, 0);
279 regulator_disable(hsusb_1p8);
280 return ret;
281 }
282
Anji jonnala11aa5c42011-05-04 10:19:48 +0530283 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700284 ret = regulator_disable(hsusb_1p8);
285 if (ret) {
286 dev_err(motg->otg.dev, "%s: unable to disable the hsusb 1p8\n",
287 __func__);
288 return ret;
289 }
290
291 ret = regulator_set_optimum_mode(hsusb_1p8, 0);
Anji jonnala11aa5c42011-05-04 10:19:48 +0530292 if (ret < 0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293 pr_err("%s: Unable to set LPM of the regulator:"
Anji jonnala11aa5c42011-05-04 10:19:48 +0530294 "HSUSB_1p8\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700295
296 ret = regulator_disable(hsusb_3p3);
297 if (ret) {
298 dev_err(motg->otg.dev, "%s: unable to disable the hsusb 3p3\n",
299 __func__);
300 return ret;
301 }
302 ret = regulator_set_optimum_mode(hsusb_3p3, 0);
Anji jonnala11aa5c42011-05-04 10:19:48 +0530303 if (ret < 0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700304 pr_err("%s: Unable to set LPM of the regulator:"
Anji jonnala11aa5c42011-05-04 10:19:48 +0530305 "HSUSB_3p3\n", __func__);
306 }
307
308 pr_debug("reg (%s)\n", on ? "HPM" : "LPM");
309 return ret < 0 ? ret : 0;
310}
311
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530312static void msm_hsusb_mhl_switch_enable(struct msm_otg *motg, bool on)
313{
314 static struct regulator *mhl_analog_switch;
315 struct msm_otg_platform_data *pdata = motg->pdata;
316
317 if (!pdata->mhl_enable)
318 return;
319
320 if (on) {
321 mhl_analog_switch = regulator_get(motg->otg.dev,
322 "mhl_ext_3p3v");
323 if (IS_ERR(mhl_analog_switch)) {
324 pr_err("Unable to get mhl_analog_switch\n");
325 return;
326 }
327
328 if (regulator_enable(mhl_analog_switch)) {
329 pr_err("unable to enable mhl_analog_switch\n");
330 goto put_analog_switch;
331 }
332 return;
333 }
334
335 regulator_disable(mhl_analog_switch);
336put_analog_switch:
337 regulator_put(mhl_analog_switch);
338}
339
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530340static int ulpi_read(struct otg_transceiver *otg, u32 reg)
341{
342 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
343 int cnt = 0;
344
345 /* initiate read operation */
346 writel(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg),
347 USB_ULPI_VIEWPORT);
348
349 /* wait for completion */
350 while (cnt < ULPI_IO_TIMEOUT_USEC) {
351 if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN))
352 break;
353 udelay(1);
354 cnt++;
355 }
356
357 if (cnt >= ULPI_IO_TIMEOUT_USEC) {
358 dev_err(otg->dev, "ulpi_read: timeout %08x\n",
359 readl(USB_ULPI_VIEWPORT));
360 return -ETIMEDOUT;
361 }
362 return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT));
363}
364
365static int ulpi_write(struct otg_transceiver *otg, u32 val, u32 reg)
366{
367 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
368 int cnt = 0;
369
370 /* initiate write operation */
371 writel(ULPI_RUN | ULPI_WRITE |
372 ULPI_ADDR(reg) | ULPI_DATA(val),
373 USB_ULPI_VIEWPORT);
374
375 /* wait for completion */
376 while (cnt < ULPI_IO_TIMEOUT_USEC) {
377 if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN))
378 break;
379 udelay(1);
380 cnt++;
381 }
382
383 if (cnt >= ULPI_IO_TIMEOUT_USEC) {
384 dev_err(otg->dev, "ulpi_write: timeout\n");
385 return -ETIMEDOUT;
386 }
387 return 0;
388}
389
390static struct otg_io_access_ops msm_otg_io_ops = {
391 .read = ulpi_read,
392 .write = ulpi_write,
393};
394
395static void ulpi_init(struct msm_otg *motg)
396{
397 struct msm_otg_platform_data *pdata = motg->pdata;
398 int *seq = pdata->phy_init_seq;
399
400 if (!seq)
401 return;
402
403 while (seq[0] >= 0) {
404 dev_vdbg(motg->otg.dev, "ulpi: write 0x%02x to 0x%02x\n",
405 seq[0], seq[1]);
406 ulpi_write(&motg->otg, seq[0], seq[1]);
407 seq += 2;
408 }
409}
410
411static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert)
412{
413 int ret;
414
415 if (assert) {
416 ret = clk_reset(motg->clk, CLK_RESET_ASSERT);
417 if (ret)
418 dev_err(motg->otg.dev, "usb hs_clk assert failed\n");
419 } else {
420 ret = clk_reset(motg->clk, CLK_RESET_DEASSERT);
421 if (ret)
422 dev_err(motg->otg.dev, "usb hs_clk deassert failed\n");
423 }
424 return ret;
425}
426
427static int msm_otg_phy_clk_reset(struct msm_otg *motg)
428{
429 int ret;
430
Amit Blay02eff132011-09-21 16:46:24 +0300431 if (IS_ERR(motg->phy_reset_clk))
432 return 0;
433
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530434 ret = clk_reset(motg->phy_reset_clk, CLK_RESET_ASSERT);
435 if (ret) {
436 dev_err(motg->otg.dev, "usb phy clk assert failed\n");
437 return ret;
438 }
439 usleep_range(10000, 12000);
440 ret = clk_reset(motg->phy_reset_clk, CLK_RESET_DEASSERT);
441 if (ret)
442 dev_err(motg->otg.dev, "usb phy clk deassert failed\n");
443 return ret;
444}
445
446static int msm_otg_phy_reset(struct msm_otg *motg)
447{
448 u32 val;
449 int ret;
450 int retries;
451
452 ret = msm_otg_link_clk_reset(motg, 1);
453 if (ret)
454 return ret;
455 ret = msm_otg_phy_clk_reset(motg);
456 if (ret)
457 return ret;
458 ret = msm_otg_link_clk_reset(motg, 0);
459 if (ret)
460 return ret;
461
462 val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK;
463 writel(val | PORTSC_PTS_ULPI, USB_PORTSC);
464
465 for (retries = 3; retries > 0; retries--) {
466 ret = ulpi_write(&motg->otg, ULPI_FUNC_CTRL_SUSPENDM,
467 ULPI_CLR(ULPI_FUNC_CTRL));
468 if (!ret)
469 break;
470 ret = msm_otg_phy_clk_reset(motg);
471 if (ret)
472 return ret;
473 }
474 if (!retries)
475 return -ETIMEDOUT;
476
477 /* This reset calibrates the phy, if the above write succeeded */
478 ret = msm_otg_phy_clk_reset(motg);
479 if (ret)
480 return ret;
481
482 for (retries = 3; retries > 0; retries--) {
483 ret = ulpi_read(&motg->otg, ULPI_DEBUG);
484 if (ret != -ETIMEDOUT)
485 break;
486 ret = msm_otg_phy_clk_reset(motg);
487 if (ret)
488 return ret;
489 }
490 if (!retries)
491 return -ETIMEDOUT;
492
493 dev_info(motg->otg.dev, "phy_reset: success\n");
494 return 0;
495}
496
497#define LINK_RESET_TIMEOUT_USEC (250 * 1000)
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530498static int msm_otg_link_reset(struct msm_otg *motg)
499{
500 int cnt = 0;
501
502 writel_relaxed(USBCMD_RESET, USB_USBCMD);
503 while (cnt < LINK_RESET_TIMEOUT_USEC) {
504 if (!(readl_relaxed(USB_USBCMD) & USBCMD_RESET))
505 break;
506 udelay(1);
507 cnt++;
508 }
509 if (cnt >= LINK_RESET_TIMEOUT_USEC)
510 return -ETIMEDOUT;
511
512 /* select ULPI phy */
513 writel_relaxed(0x80000000, USB_PORTSC);
514 writel_relaxed(0x0, USB_AHBBURST);
515 writel_relaxed(0x00, USB_AHBMODE);
516
517 return 0;
518}
519
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530520static int msm_otg_reset(struct otg_transceiver *otg)
521{
522 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
523 struct msm_otg_platform_data *pdata = motg->pdata;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530524 int ret;
525 u32 val = 0;
526 u32 ulpi_val = 0;
527
Ofir Cohen4da266f2012-01-03 10:19:29 +0200528 /*
529 * USB PHY and Link reset also reset the USB BAM.
530 * Thus perform reset operation only once to avoid
531 * USB BAM reset on other cases e.g. USB cable disconnections.
532 */
533 if (pdata->disable_reset_on_disconnect) {
534 if (motg->reset_counter)
535 return 0;
536 else
537 motg->reset_counter++;
538 }
539
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700540 clk_enable(motg->clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530541 ret = msm_otg_phy_reset(motg);
542 if (ret) {
543 dev_err(otg->dev, "phy_reset failed\n");
544 return ret;
545 }
546
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530547 aca_id_turned_on = false;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530548 ret = msm_otg_link_reset(motg);
549 if (ret) {
550 dev_err(otg->dev, "link reset failed\n");
551 return ret;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530552 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530553 msleep(100);
Anji jonnalaa8b8d732011-12-06 10:03:24 +0530554
555 ulpi_init(motg);
556
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700557 /* Ensure that RESET operation is completed before turning off clock */
558 mb();
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530559
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700560 clk_disable(motg->clk);
561
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530562 if (pdata->otg_control == OTG_PHY_CONTROL) {
563 val = readl_relaxed(USB_OTGSC);
564 if (pdata->mode == USB_OTG) {
565 ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID;
566 val |= OTGSC_IDIE | OTGSC_BSVIE;
567 } else if (pdata->mode == USB_PERIPHERAL) {
568 ulpi_val = ULPI_INT_SESS_VALID;
569 val |= OTGSC_BSVIE;
570 }
571 writel_relaxed(val, USB_OTGSC);
572 ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_RISE);
573 ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_FALL);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530574 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530576 return 0;
577}
578
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530579static int msm_otg_set_suspend(struct otg_transceiver *otg, int suspend)
580{
581 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
582
583 /*
584 * Allow bus suspend only for host mode. Device mode bus suspend
585 * is not implemented yet.
586 */
587 if (!test_bit(ID, &motg->inputs) || test_bit(ID_A, &motg->inputs)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530588 /*
589 * ID_GND --> ID_A transition can not be detected in LPM.
590 * Disallow host bus suspend when ACA is enabled.
591 */
592 if (suspend && !aca_enabled())
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530593 pm_runtime_put(otg->dev);
594 else
595 pm_runtime_resume(otg->dev);
596 }
597
598 return 0;
599}
600
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530601#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000)
Pavankumar Kondeti70187732011-02-15 09:42:34 +0530602#define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
603
604#ifdef CONFIG_PM_SLEEP
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530605static int msm_otg_suspend(struct msm_otg *motg)
606{
607 struct otg_transceiver *otg = &motg->otg;
608 struct usb_bus *bus = otg->host;
609 struct msm_otg_platform_data *pdata = motg->pdata;
610 int cnt = 0;
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530611 bool host_bus_suspend;
612 u32 phy_ctrl_val = 0, cmd_val;
Rajkumar Raghupathy242565d2011-12-13 12:10:59 +0530613 u32 portsc;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530614
615 if (atomic_read(&motg->in_lpm))
616 return 0;
617
618 disable_irq(motg->irq);
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530619 host_bus_suspend = otg->host && !test_bit(ID, &motg->inputs);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530620 /*
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530621 * Chipidea 45-nm PHY suspend sequence:
622 *
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530623 * Interrupt Latch Register auto-clear feature is not present
624 * in all PHY versions. Latch register is clear on read type.
625 * Clear latch register to avoid spurious wakeup from
626 * low power mode (LPM).
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530627 *
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530628 * PHY comparators are disabled when PHY enters into low power
629 * mode (LPM). Keep PHY comparators ON in LPM only when we expect
630 * VBUS/Id notifications from USB PHY. Otherwise turn off USB
631 * PHY comparators. This save significant amount of power.
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530632 *
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530633 * PLL is not turned off when PHY enters into low power mode (LPM).
634 * Disable PLL for maximum power savings.
635 */
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530636
637 if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) {
638 ulpi_read(otg, 0x14);
639 if (pdata->otg_control == OTG_PHY_CONTROL)
640 ulpi_write(otg, 0x01, 0x30);
641 ulpi_write(otg, 0x08, 0x09);
642 }
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530643
644 /*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700645 * Turn off the OTG comparators, if depends on PMIC for
646 * VBUS and ID notifications.
647 */
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530648 if ((motg->caps & ALLOW_PHY_COMP_DISABLE) && !host_bus_suspend) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649 ulpi_write(otg, OTG_COMP_DISABLE,
650 ULPI_SET(ULPI_PWR_CLK_MNG_REG));
651 motg->lpm_flags |= PHY_OTG_COMP_DISABLED;
652 }
653
Rajkumar Raghupathy242565d2011-12-13 12:10:59 +0530654 /* Set the PHCD bit, only if it is not set by the controller.
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530655 * PHY may take some time or even fail to enter into low power
656 * mode (LPM). Hence poll for 500 msec and reset the PHY and link
657 * in failure case.
658 */
Rajkumar Raghupathy242565d2011-12-13 12:10:59 +0530659 portsc = readl_relaxed(USB_PORTSC);
660 if (!(portsc & PORTSC_PHCD)) {
661 writel_relaxed(portsc | PORTSC_PHCD,
662 USB_PORTSC);
663 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
664 if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD)
665 break;
666 udelay(1);
667 cnt++;
668 }
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530669 }
670
671 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) {
672 dev_err(otg->dev, "Unable to suspend PHY\n");
673 msm_otg_reset(otg);
674 enable_irq(motg->irq);
675 return -ETIMEDOUT;
676 }
677
678 /*
679 * PHY has capability to generate interrupt asynchronously in low
680 * power mode (LPM). This interrupt is level triggered. So USB IRQ
681 * line must be disabled till async interrupt enable bit is cleared
682 * in USBCMD register. Assert STP (ULPI interface STOP signal) to
683 * block data communication from PHY.
684 */
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530685 cmd_val = readl_relaxed(USB_USBCMD);
686 if (host_bus_suspend)
687 cmd_val |= ASYNC_INTR_CTRL | ULPI_STP_CTRL;
688 else
689 cmd_val |= ULPI_STP_CTRL;
690 writel_relaxed(cmd_val, USB_USBCMD);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530691
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530692 if (motg->caps & ALLOW_PHY_RETENTION && !host_bus_suspend) {
Amit Blay58b31472011-11-18 09:39:39 +0200693 phy_ctrl_val = readl_relaxed(USB_PHY_CTRL);
694 if (motg->pdata->otg_control == OTG_PHY_CONTROL)
695 /* Enable PHY HV interrupts to wake MPM/Link */
696 phy_ctrl_val |=
697 (PHY_IDHV_INTEN | PHY_OTGSESSVLDHV_INTEN);
698
699 writel_relaxed(phy_ctrl_val & ~PHY_RETEN, USB_PHY_CTRL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700700 motg->lpm_flags |= PHY_RETENTIONED;
701 }
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530702
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700703 /* Ensure that above operation is completed before turning off clocks */
704 mb();
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530705 clk_disable(motg->pclk);
Manu Gautam5143b252012-01-05 19:25:23 -0800706 clk_disable(motg->core_clk);
Anji jonnala0f73cac2011-05-04 10:19:46 +0530707
Anji jonnala7da3f262011-12-02 17:22:14 -0800708 /* usb phy no more require TCXO clock, hence vote for TCXO disable */
Stephen Boyd7dd22662012-01-26 16:09:31 -0800709 clk_disable_unprepare(motg->xo_handle);
Anji jonnala7da3f262011-12-02 17:22:14 -0800710
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530711 if (motg->caps & ALLOW_PHY_POWER_COLLAPSE && !host_bus_suspend) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700712 msm_hsusb_ldo_enable(motg, 0);
713 motg->lpm_flags |= PHY_PWR_COLLAPSED;
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530714 }
715
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530716 if (motg->lpm_flags & PHY_RETENTIONED) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700717 msm_hsusb_config_vddcx(0);
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530718 msm_hsusb_mhl_switch_enable(motg, 0);
719 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700720
721 if (device_may_wakeup(otg->dev)) {
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530722 enable_irq_wake(motg->irq);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700723 if (motg->pdata->pmic_id_irq)
724 enable_irq_wake(motg->pdata->pmic_id_irq);
725 }
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530726 if (bus)
727 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags);
728
729 atomic_set(&motg->in_lpm, 1);
730 enable_irq(motg->irq);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700731 wake_unlock(&motg->wlock);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530732
733 dev_info(otg->dev, "USB in low power mode\n");
734
735 return 0;
736}
737
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530738static int msm_otg_resume(struct msm_otg *motg)
739{
740 struct otg_transceiver *otg = &motg->otg;
741 struct usb_bus *bus = otg->host;
742 int cnt = 0;
743 unsigned temp;
Amit Blay58b31472011-11-18 09:39:39 +0200744 u32 phy_ctrl_val = 0;
Anji jonnala7da3f262011-12-02 17:22:14 -0800745 unsigned ret;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530746
747 if (!atomic_read(&motg->in_lpm))
748 return 0;
749
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700750 wake_lock(&motg->wlock);
Anji jonnala7da3f262011-12-02 17:22:14 -0800751
752 /* Vote for TCXO when waking up the phy */
Stephen Boyd7dd22662012-01-26 16:09:31 -0800753 ret = clk_prepare_enable(motg->xo_handle);
Anji jonnala7da3f262011-12-02 17:22:14 -0800754 if (ret)
755 dev_err(otg->dev, "%s failed to vote for "
756 "TCXO D0 buffer%d\n", __func__, ret);
757
Manu Gautam5143b252012-01-05 19:25:23 -0800758 clk_enable(motg->core_clk);
Amit Blay137575f2011-11-06 15:20:54 +0200759
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530760 clk_enable(motg->pclk);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530761
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700762 if (motg->lpm_flags & PHY_PWR_COLLAPSED) {
763 msm_hsusb_ldo_enable(motg, 1);
764 motg->lpm_flags &= ~PHY_PWR_COLLAPSED;
765 }
766
767 if (motg->lpm_flags & PHY_RETENTIONED) {
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530768 msm_hsusb_mhl_switch_enable(motg, 1);
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530769 msm_hsusb_config_vddcx(1);
Amit Blay58b31472011-11-18 09:39:39 +0200770 phy_ctrl_val = readl_relaxed(USB_PHY_CTRL);
771 phy_ctrl_val |= PHY_RETEN;
772 if (motg->pdata->otg_control == OTG_PHY_CONTROL)
773 /* Disable PHY HV interrupts */
774 phy_ctrl_val &=
775 ~(PHY_IDHV_INTEN | PHY_OTGSESSVLDHV_INTEN);
776 writel_relaxed(phy_ctrl_val, USB_PHY_CTRL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700777 motg->lpm_flags &= ~PHY_RETENTIONED;
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530778 }
779
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530780 temp = readl(USB_USBCMD);
781 temp &= ~ASYNC_INTR_CTRL;
782 temp &= ~ULPI_STP_CTRL;
783 writel(temp, USB_USBCMD);
784
785 /*
786 * PHY comes out of low power mode (LPM) in case of wakeup
787 * from asynchronous interrupt.
788 */
789 if (!(readl(USB_PORTSC) & PORTSC_PHCD))
790 goto skip_phy_resume;
791
792 writel(readl(USB_PORTSC) & ~PORTSC_PHCD, USB_PORTSC);
793 while (cnt < PHY_RESUME_TIMEOUT_USEC) {
794 if (!(readl(USB_PORTSC) & PORTSC_PHCD))
795 break;
796 udelay(1);
797 cnt++;
798 }
799
800 if (cnt >= PHY_RESUME_TIMEOUT_USEC) {
801 /*
802 * This is a fatal error. Reset the link and
803 * PHY. USB state can not be restored. Re-insertion
804 * of USB cable is the only way to get USB working.
805 */
806 dev_err(otg->dev, "Unable to resume USB."
807 "Re-plugin the cable\n");
808 msm_otg_reset(otg);
809 }
810
811skip_phy_resume:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700812 /* Turn on the OTG comparators on resume */
813 if (motg->lpm_flags & PHY_OTG_COMP_DISABLED) {
814 ulpi_write(otg, OTG_COMP_DISABLE,
815 ULPI_CLR(ULPI_PWR_CLK_MNG_REG));
816 motg->lpm_flags &= ~PHY_OTG_COMP_DISABLED;
817 }
818 if (device_may_wakeup(otg->dev)) {
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530819 disable_irq_wake(motg->irq);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700820 if (motg->pdata->pmic_id_irq)
821 disable_irq_wake(motg->pdata->pmic_id_irq);
822 }
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530823 if (bus)
824 set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags);
825
Pavankumar Kondeti2ce2c3a2011-05-02 11:56:33 +0530826 atomic_set(&motg->in_lpm, 0);
827
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530828 if (motg->async_int) {
829 motg->async_int = 0;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530830 enable_irq(motg->irq);
831 }
832
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530833 dev_info(otg->dev, "USB exited from low power mode\n");
834
835 return 0;
836}
Pavankumar Kondeti70187732011-02-15 09:42:34 +0530837#endif
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530838
Chiranjeevi Velempati39f9b952012-01-24 10:46:12 +0530839static int msm_otg_notify_chg_type(struct msm_otg *motg)
840{
841 static int charger_type;
842 /*
843 * TODO
844 * Unify OTG driver charger types and power supply charger types
845 */
846 if (charger_type == motg->chg_type)
847 return 0;
848
849 if (motg->chg_type == USB_SDP_CHARGER)
850 charger_type = POWER_SUPPLY_TYPE_USB;
851 else if (motg->chg_type == USB_CDP_CHARGER)
852 charger_type = POWER_SUPPLY_TYPE_USB_CDP;
853 else if (motg->chg_type == USB_DCP_CHARGER)
854 charger_type = POWER_SUPPLY_TYPE_USB_DCP;
855 else if ((motg->chg_type == USB_ACA_DOCK_CHARGER ||
856 motg->chg_type == USB_ACA_A_CHARGER ||
857 motg->chg_type == USB_ACA_B_CHARGER ||
858 motg->chg_type == USB_ACA_C_CHARGER))
859 charger_type = POWER_SUPPLY_TYPE_USB_ACA;
860 else
861 charger_type = POWER_SUPPLY_TYPE_BATTERY;
862
863 return pm8921_set_usb_power_supply_type(charger_type);
864}
865
Amit Blay0f7edf72012-01-15 10:11:27 +0200866static int msm_otg_notify_power_supply(struct msm_otg *motg, unsigned mA)
867{
868 struct power_supply *psy;
869
870 psy = power_supply_get_by_name("usb");
871 if (!psy)
872 goto psy_not_supported;
873
874 if (motg->cur_power == 0 && mA > 0) {
875 /* Enable charging */
876 if (power_supply_set_online(psy, true))
877 goto psy_not_supported;
878 } else if (motg->cur_power > 0 && mA == 0) {
879 /* Disable charging */
880 if (power_supply_set_online(psy, false))
881 goto psy_not_supported;
882 return 0;
883 }
884 /* Set max current limit */
885 if (power_supply_set_current_limit(psy, 1000*mA))
886 goto psy_not_supported;
887
888 return 0;
889
890psy_not_supported:
891 dev_dbg(motg->otg.dev, "Power Supply doesn't support USB charger\n");
892 return -ENXIO;
893}
894
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530895static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA)
896{
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530897 if ((motg->chg_type == USB_ACA_DOCK_CHARGER ||
898 motg->chg_type == USB_ACA_A_CHARGER ||
899 motg->chg_type == USB_ACA_B_CHARGER ||
900 motg->chg_type == USB_ACA_C_CHARGER) &&
901 mA > IDEV_ACA_CHG_LIMIT)
902 mA = IDEV_ACA_CHG_LIMIT;
903
Chiranjeevi Velempati39f9b952012-01-24 10:46:12 +0530904 if (msm_otg_notify_chg_type(motg))
905 dev_err(motg->otg.dev,
906 "Failed notifying %d charger type to PMIC\n",
907 motg->chg_type);
908
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530909 if (motg->cur_power == mA)
910 return;
911
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530912 dev_info(motg->otg.dev, "Avail curr from USB = %u\n", mA);
Amit Blay0f7edf72012-01-15 10:11:27 +0200913
914 /*
915 * Use Power Supply API if supported, otherwise fallback
916 * to legacy pm8921 API.
917 */
918 if (msm_otg_notify_power_supply(motg, mA))
919 pm8921_charger_vbus_draw(mA);
920
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530921 motg->cur_power = mA;
922}
923
924static int msm_otg_set_power(struct otg_transceiver *otg, unsigned mA)
925{
926 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
927
928 /*
929 * Gadget driver uses set_power method to notify about the
930 * available current based on suspend/configured states.
931 *
932 * IDEV_CHG can be drawn irrespective of suspend/un-configured
933 * states when CDP/ACA is connected.
934 */
935 if (motg->chg_type == USB_SDP_CHARGER)
936 msm_otg_notify_charger(motg, mA);
937
938 return 0;
939}
940
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530941static void msm_otg_start_host(struct otg_transceiver *otg, int on)
942{
943 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
944 struct msm_otg_platform_data *pdata = motg->pdata;
945 struct usb_hcd *hcd;
946
947 if (!otg->host)
948 return;
949
950 hcd = bus_to_hcd(otg->host);
951
952 if (on) {
953 dev_dbg(otg->dev, "host on\n");
954
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530955 /*
956 * Some boards have a switch cotrolled by gpio
957 * to enable/disable internal HUB. Enable internal
958 * HUB before kicking the host.
959 */
960 if (pdata->setup_gpio)
961 pdata->setup_gpio(OTG_STATE_A_HOST);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530962 usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530963 } else {
964 dev_dbg(otg->dev, "host off\n");
965
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530966 usb_remove_hcd(hcd);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530967 /* HCD core reset all bits of PORTSC. select ULPI phy */
968 writel_relaxed(0x80000000, USB_PORTSC);
969
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530970 if (pdata->setup_gpio)
971 pdata->setup_gpio(OTG_STATE_UNDEFINED);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530972 }
973}
974
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975static int msm_otg_usbdev_notify(struct notifier_block *self,
976 unsigned long action, void *priv)
977{
978 struct msm_otg *motg = container_of(self, struct msm_otg, usbdev_nb);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530979 struct usb_device *udev = priv;
980
981 if (!aca_enabled())
982 goto out;
983
984 if (action == USB_BUS_ADD || action == USB_BUS_REMOVE)
985 goto out;
986
987 if (udev->bus != motg->otg.host)
988 goto out;
989 /*
990 * Interested in devices connected directly to the root hub.
991 * ACA dock can supply IDEV_CHG irrespective devices connected
992 * on the accessory port.
993 */
994 if (!udev->parent || udev->parent->parent ||
995 motg->chg_type == USB_ACA_DOCK_CHARGER)
996 goto out;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700997
998 switch (action) {
999 case USB_DEVICE_ADD:
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301000 usb_disable_autosuspend(udev);
1001 /* fall through */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001002 case USB_DEVICE_CONFIG:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001003 if (udev->actconfig)
1004 motg->mA_port = udev->actconfig->desc.bMaxPower * 2;
1005 else
1006 motg->mA_port = IUNIT;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301007 break;
1008 case USB_DEVICE_REMOVE:
1009 motg->mA_port = IUNIT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001010 break;
1011 default:
1012 break;
1013 }
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301014 if (test_bit(ID_A, &motg->inputs))
1015 msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX -
1016 motg->mA_port);
1017out:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001018 return NOTIFY_OK;
1019}
1020
Mayank Ranae3926882011-12-26 09:47:54 +05301021static void msm_hsusb_vbus_power(struct msm_otg *motg, bool on)
1022{
1023 int ret;
1024 static bool vbus_is_on;
1025
1026 if (vbus_is_on == on)
1027 return;
1028
1029 if (motg->pdata->vbus_power) {
Mayank Rana91f597e2012-01-20 10:12:06 +05301030 ret = motg->pdata->vbus_power(on);
1031 if (!ret)
1032 vbus_is_on = on;
Mayank Ranae3926882011-12-26 09:47:54 +05301033 return;
1034 }
1035
1036 if (!vbus_otg) {
1037 pr_err("vbus_otg is NULL.");
1038 return;
1039 }
1040
Abhijeet Dharmapurikarbe054882012-01-03 20:27:07 -08001041 /*
1042 * if entering host mode tell the charger to not draw any current
1043 * from usb - if exiting host mode let the charger draw current
1044 */
1045 pm8921_disable_source_current(on);
Mayank Ranae3926882011-12-26 09:47:54 +05301046 if (on) {
1047 ret = regulator_enable(vbus_otg);
1048 if (ret) {
1049 pr_err("unable to enable vbus_otg\n");
1050 return;
1051 }
1052 vbus_is_on = true;
1053 } else {
1054 ret = regulator_disable(vbus_otg);
1055 if (ret) {
1056 pr_err("unable to disable vbus_otg\n");
1057 return;
1058 }
1059 vbus_is_on = false;
1060 }
1061}
1062
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301063static int msm_otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1064{
1065 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
1066 struct usb_hcd *hcd;
1067
1068 /*
1069 * Fail host registration if this board can support
1070 * only peripheral configuration.
1071 */
1072 if (motg->pdata->mode == USB_PERIPHERAL) {
1073 dev_info(otg->dev, "Host mode is not supported\n");
1074 return -ENODEV;
1075 }
1076
Mayank Ranae3926882011-12-26 09:47:54 +05301077 if (!motg->pdata->vbus_power && host) {
1078 vbus_otg = regulator_get(motg->otg.dev, "vbus_otg");
1079 if (IS_ERR(vbus_otg)) {
1080 pr_err("Unable to get vbus_otg\n");
1081 return -ENODEV;
1082 }
1083 }
1084
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301085 if (!host) {
1086 if (otg->state == OTG_STATE_A_HOST) {
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301087 pm_runtime_get_sync(otg->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001088 usb_unregister_notify(&motg->usbdev_nb);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301089 msm_otg_start_host(otg, 0);
Mayank Ranae3926882011-12-26 09:47:54 +05301090 msm_hsusb_vbus_power(motg, 0);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301091 otg->host = NULL;
1092 otg->state = OTG_STATE_UNDEFINED;
1093 schedule_work(&motg->sm_work);
1094 } else {
1095 otg->host = NULL;
1096 }
1097
Mayank Ranae3926882011-12-26 09:47:54 +05301098 if (vbus_otg)
1099 regulator_put(vbus_otg);
1100
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301101 return 0;
1102 }
1103
1104 hcd = bus_to_hcd(host);
1105 hcd->power_budget = motg->pdata->power_budget;
1106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001107 motg->usbdev_nb.notifier_call = msm_otg_usbdev_notify;
1108 usb_register_notify(&motg->usbdev_nb);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301109 otg->host = host;
1110 dev_dbg(otg->dev, "host driver registered w/ tranceiver\n");
1111
1112 /*
1113 * Kick the state machine work, if peripheral is not supported
1114 * or peripheral is already registered with us.
1115 */
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301116 if (motg->pdata->mode == USB_HOST || otg->gadget) {
1117 pm_runtime_get_sync(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301118 schedule_work(&motg->sm_work);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301119 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301120
1121 return 0;
1122}
1123
1124static void msm_otg_start_peripheral(struct otg_transceiver *otg, int on)
1125{
Manu Gautamcd82e9d2011-12-20 14:17:28 +05301126 int ret;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301127 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
1128 struct msm_otg_platform_data *pdata = motg->pdata;
1129
1130 if (!otg->gadget)
1131 return;
1132
1133 if (on) {
1134 dev_dbg(otg->dev, "gadget on\n");
1135 /*
1136 * Some boards have a switch cotrolled by gpio
1137 * to enable/disable internal HUB. Disable internal
1138 * HUB before kicking the gadget.
1139 */
1140 if (pdata->setup_gpio)
1141 pdata->setup_gpio(OTG_STATE_B_PERIPHERAL);
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05301142 /*
1143 * vote for minimum dma_latency to prevent idle
1144 * power collapse(pc) while running in peripheral mode.
1145 */
1146 otg_pm_qos_update_latency(motg, 1);
Manu Gautamcd82e9d2011-12-20 14:17:28 +05301147 /* Configure BUS performance parameters for MAX bandwidth */
1148 if (motg->bus_perf_client) {
1149 ret = msm_bus_scale_client_update_request(
1150 motg->bus_perf_client, 1);
1151 if (ret)
1152 dev_err(motg->otg.dev, "%s: Failed to vote for "
1153 "bus bandwidth %d\n", __func__, ret);
1154 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301155 usb_gadget_vbus_connect(otg->gadget);
1156 } else {
1157 dev_dbg(otg->dev, "gadget off\n");
1158 usb_gadget_vbus_disconnect(otg->gadget);
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05301159 otg_pm_qos_update_latency(motg, 0);
Manu Gautamcd82e9d2011-12-20 14:17:28 +05301160 /* Configure BUS performance parameters to default */
1161 if (motg->bus_perf_client) {
1162 ret = msm_bus_scale_client_update_request(
1163 motg->bus_perf_client, 0);
1164 if (ret)
1165 dev_err(motg->otg.dev, "%s: Failed to devote "
1166 "for bus bw %d\n", __func__, ret);
1167 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301168 if (pdata->setup_gpio)
1169 pdata->setup_gpio(OTG_STATE_UNDEFINED);
1170 }
1171
1172}
1173
1174static int msm_otg_set_peripheral(struct otg_transceiver *otg,
1175 struct usb_gadget *gadget)
1176{
1177 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
1178
1179 /*
1180 * Fail peripheral registration if this board can support
1181 * only host configuration.
1182 */
1183 if (motg->pdata->mode == USB_HOST) {
1184 dev_info(otg->dev, "Peripheral mode is not supported\n");
1185 return -ENODEV;
1186 }
1187
1188 if (!gadget) {
1189 if (otg->state == OTG_STATE_B_PERIPHERAL) {
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301190 pm_runtime_get_sync(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301191 msm_otg_start_peripheral(otg, 0);
1192 otg->gadget = NULL;
1193 otg->state = OTG_STATE_UNDEFINED;
1194 schedule_work(&motg->sm_work);
1195 } else {
1196 otg->gadget = NULL;
1197 }
1198
1199 return 0;
1200 }
1201 otg->gadget = gadget;
1202 dev_dbg(otg->dev, "peripheral driver registered w/ tranceiver\n");
1203
1204 /*
1205 * Kick the state machine work, if host is not supported
1206 * or host is already registered with us.
1207 */
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301208 if (motg->pdata->mode == USB_PERIPHERAL || otg->host) {
1209 pm_runtime_get_sync(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301210 schedule_work(&motg->sm_work);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301211 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301212
1213 return 0;
1214}
1215
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001216static bool msm_chg_aca_detect(struct msm_otg *motg)
1217{
1218 struct otg_transceiver *otg = &motg->otg;
1219 u32 int_sts;
1220 bool ret = false;
1221
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301222 if (!aca_enabled())
1223 goto out;
1224
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001225 if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY)
1226 goto out;
1227
1228 int_sts = ulpi_read(otg, 0x87);
1229 switch (int_sts & 0x1C) {
1230 case 0x08:
1231 if (!test_and_set_bit(ID_A, &motg->inputs)) {
1232 dev_dbg(otg->dev, "ID_A\n");
1233 motg->chg_type = USB_ACA_A_CHARGER;
1234 motg->chg_state = USB_CHG_STATE_DETECTED;
1235 clear_bit(ID_B, &motg->inputs);
1236 clear_bit(ID_C, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301237 set_bit(ID, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001238 ret = true;
1239 }
1240 break;
1241 case 0x0C:
1242 if (!test_and_set_bit(ID_B, &motg->inputs)) {
1243 dev_dbg(otg->dev, "ID_B\n");
1244 motg->chg_type = USB_ACA_B_CHARGER;
1245 motg->chg_state = USB_CHG_STATE_DETECTED;
1246 clear_bit(ID_A, &motg->inputs);
1247 clear_bit(ID_C, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301248 set_bit(ID, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001249 ret = true;
1250 }
1251 break;
1252 case 0x10:
1253 if (!test_and_set_bit(ID_C, &motg->inputs)) {
1254 dev_dbg(otg->dev, "ID_C\n");
1255 motg->chg_type = USB_ACA_C_CHARGER;
1256 motg->chg_state = USB_CHG_STATE_DETECTED;
1257 clear_bit(ID_A, &motg->inputs);
1258 clear_bit(ID_B, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301259 set_bit(ID, &motg->inputs);
1260 ret = true;
1261 }
1262 break;
1263 case 0x04:
1264 if (test_and_clear_bit(ID, &motg->inputs)) {
1265 dev_dbg(otg->dev, "ID_GND\n");
1266 motg->chg_type = USB_INVALID_CHARGER;
1267 motg->chg_state = USB_CHG_STATE_UNDEFINED;
1268 clear_bit(ID_A, &motg->inputs);
1269 clear_bit(ID_B, &motg->inputs);
1270 clear_bit(ID_C, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001271 ret = true;
1272 }
1273 break;
1274 default:
1275 ret = test_and_clear_bit(ID_A, &motg->inputs) |
1276 test_and_clear_bit(ID_B, &motg->inputs) |
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301277 test_and_clear_bit(ID_C, &motg->inputs) |
1278 !test_and_set_bit(ID, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001279 if (ret) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301280 dev_dbg(otg->dev, "ID A/B/C/GND is no more\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001281 motg->chg_type = USB_INVALID_CHARGER;
1282 motg->chg_state = USB_CHG_STATE_UNDEFINED;
1283 }
1284 }
1285out:
1286 return ret;
1287}
1288
1289static void msm_chg_enable_aca_det(struct msm_otg *motg)
1290{
1291 struct otg_transceiver *otg = &motg->otg;
1292
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301293 if (!aca_enabled())
1294 return;
1295
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001296 switch (motg->pdata->phy_type) {
1297 case SNPS_28NM_INTEGRATED_PHY:
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301298 /* Disable ID_GND in link and PHY */
1299 writel_relaxed(readl_relaxed(USB_OTGSC) & ~(OTGSC_IDPU |
1300 OTGSC_IDIE), USB_OTGSC);
1301 ulpi_write(otg, 0x01, 0x0C);
1302 ulpi_write(otg, 0x10, 0x0F);
1303 ulpi_write(otg, 0x10, 0x12);
1304 /* Enable ACA ID detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001305 ulpi_write(otg, 0x20, 0x85);
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301306 aca_id_turned_on = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001307 break;
1308 default:
1309 break;
1310 }
1311}
1312
1313static void msm_chg_enable_aca_intr(struct msm_otg *motg)
1314{
1315 struct otg_transceiver *otg = &motg->otg;
1316
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301317 if (!aca_enabled())
1318 return;
1319
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001320 switch (motg->pdata->phy_type) {
1321 case SNPS_28NM_INTEGRATED_PHY:
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301322 /* Enable ACA Detection interrupt (on any RID change) */
1323 ulpi_write(otg, 0x01, 0x94);
1324 break;
1325 default:
1326 break;
1327 }
1328}
1329
1330static void msm_chg_disable_aca_intr(struct msm_otg *motg)
1331{
1332 struct otg_transceiver *otg = &motg->otg;
1333
1334 if (!aca_enabled())
1335 return;
1336
1337 switch (motg->pdata->phy_type) {
1338 case SNPS_28NM_INTEGRATED_PHY:
1339 ulpi_write(otg, 0x01, 0x95);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001340 break;
1341 default:
1342 break;
1343 }
1344}
1345
1346static bool msm_chg_check_aca_intr(struct msm_otg *motg)
1347{
1348 struct otg_transceiver *otg = &motg->otg;
1349 bool ret = false;
1350
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301351 if (!aca_enabled())
1352 return ret;
1353
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001354 switch (motg->pdata->phy_type) {
1355 case SNPS_28NM_INTEGRATED_PHY:
1356 if (ulpi_read(otg, 0x91) & 1) {
1357 dev_dbg(otg->dev, "RID change\n");
1358 ulpi_write(otg, 0x01, 0x92);
1359 ret = msm_chg_aca_detect(motg);
1360 }
1361 default:
1362 break;
1363 }
1364 return ret;
1365}
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301366
1367static void msm_otg_id_timer_func(unsigned long data)
1368{
1369 struct msm_otg *motg = (struct msm_otg *) data;
1370
1371 if (!aca_enabled())
1372 return;
1373
1374 if (atomic_read(&motg->in_lpm)) {
1375 dev_dbg(motg->otg.dev, "timer: in lpm\n");
1376 return;
1377 }
1378
1379 if (msm_chg_check_aca_intr(motg)) {
1380 dev_dbg(motg->otg.dev, "timer: aca work\n");
1381 schedule_work(&motg->sm_work);
1382 }
1383
1384 if (!test_bit(ID, &motg->inputs) || test_bit(ID_A, &motg->inputs))
1385 mod_timer(&motg->id_timer, ID_TIMER_FREQ);
1386}
1387
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301388static bool msm_chg_check_secondary_det(struct msm_otg *motg)
1389{
1390 struct otg_transceiver *otg = &motg->otg;
1391 u32 chg_det;
1392 bool ret = false;
1393
1394 switch (motg->pdata->phy_type) {
1395 case CI_45NM_INTEGRATED_PHY:
1396 chg_det = ulpi_read(otg, 0x34);
1397 ret = chg_det & (1 << 4);
1398 break;
1399 case SNPS_28NM_INTEGRATED_PHY:
1400 chg_det = ulpi_read(otg, 0x87);
1401 ret = chg_det & 1;
1402 break;
1403 default:
1404 break;
1405 }
1406 return ret;
1407}
1408
1409static void msm_chg_enable_secondary_det(struct msm_otg *motg)
1410{
1411 struct otg_transceiver *otg = &motg->otg;
1412 u32 chg_det;
1413
1414 switch (motg->pdata->phy_type) {
1415 case CI_45NM_INTEGRATED_PHY:
1416 chg_det = ulpi_read(otg, 0x34);
1417 /* Turn off charger block */
1418 chg_det |= ~(1 << 1);
1419 ulpi_write(otg, chg_det, 0x34);
1420 udelay(20);
1421 /* control chg block via ULPI */
1422 chg_det &= ~(1 << 3);
1423 ulpi_write(otg, chg_det, 0x34);
1424 /* put it in host mode for enabling D- source */
1425 chg_det &= ~(1 << 2);
1426 ulpi_write(otg, chg_det, 0x34);
1427 /* Turn on chg detect block */
1428 chg_det &= ~(1 << 1);
1429 ulpi_write(otg, chg_det, 0x34);
1430 udelay(20);
1431 /* enable chg detection */
1432 chg_det &= ~(1 << 0);
1433 ulpi_write(otg, chg_det, 0x34);
1434 break;
1435 case SNPS_28NM_INTEGRATED_PHY:
1436 /*
1437 * Configure DM as current source, DP as current sink
1438 * and enable battery charging comparators.
1439 */
1440 ulpi_write(otg, 0x8, 0x85);
1441 ulpi_write(otg, 0x2, 0x85);
1442 ulpi_write(otg, 0x1, 0x85);
1443 break;
1444 default:
1445 break;
1446 }
1447}
1448
1449static bool msm_chg_check_primary_det(struct msm_otg *motg)
1450{
1451 struct otg_transceiver *otg = &motg->otg;
1452 u32 chg_det;
1453 bool ret = false;
1454
1455 switch (motg->pdata->phy_type) {
1456 case CI_45NM_INTEGRATED_PHY:
1457 chg_det = ulpi_read(otg, 0x34);
1458 ret = chg_det & (1 << 4);
1459 break;
1460 case SNPS_28NM_INTEGRATED_PHY:
1461 chg_det = ulpi_read(otg, 0x87);
1462 ret = chg_det & 1;
1463 break;
1464 default:
1465 break;
1466 }
1467 return ret;
1468}
1469
1470static void msm_chg_enable_primary_det(struct msm_otg *motg)
1471{
1472 struct otg_transceiver *otg = &motg->otg;
1473 u32 chg_det;
1474
1475 switch (motg->pdata->phy_type) {
1476 case CI_45NM_INTEGRATED_PHY:
1477 chg_det = ulpi_read(otg, 0x34);
1478 /* enable chg detection */
1479 chg_det &= ~(1 << 0);
1480 ulpi_write(otg, chg_det, 0x34);
1481 break;
1482 case SNPS_28NM_INTEGRATED_PHY:
1483 /*
1484 * Configure DP as current source, DM as current sink
1485 * and enable battery charging comparators.
1486 */
1487 ulpi_write(otg, 0x2, 0x85);
1488 ulpi_write(otg, 0x1, 0x85);
1489 break;
1490 default:
1491 break;
1492 }
1493}
1494
1495static bool msm_chg_check_dcd(struct msm_otg *motg)
1496{
1497 struct otg_transceiver *otg = &motg->otg;
1498 u32 line_state;
1499 bool ret = false;
1500
1501 switch (motg->pdata->phy_type) {
1502 case CI_45NM_INTEGRATED_PHY:
1503 line_state = ulpi_read(otg, 0x15);
1504 ret = !(line_state & 1);
1505 break;
1506 case SNPS_28NM_INTEGRATED_PHY:
1507 line_state = ulpi_read(otg, 0x87);
1508 ret = line_state & 2;
1509 break;
1510 default:
1511 break;
1512 }
1513 return ret;
1514}
1515
1516static void msm_chg_disable_dcd(struct msm_otg *motg)
1517{
1518 struct otg_transceiver *otg = &motg->otg;
1519 u32 chg_det;
1520
1521 switch (motg->pdata->phy_type) {
1522 case CI_45NM_INTEGRATED_PHY:
1523 chg_det = ulpi_read(otg, 0x34);
1524 chg_det &= ~(1 << 5);
1525 ulpi_write(otg, chg_det, 0x34);
1526 break;
1527 case SNPS_28NM_INTEGRATED_PHY:
1528 ulpi_write(otg, 0x10, 0x86);
1529 break;
1530 default:
1531 break;
1532 }
1533}
1534
1535static void msm_chg_enable_dcd(struct msm_otg *motg)
1536{
1537 struct otg_transceiver *otg = &motg->otg;
1538 u32 chg_det;
1539
1540 switch (motg->pdata->phy_type) {
1541 case CI_45NM_INTEGRATED_PHY:
1542 chg_det = ulpi_read(otg, 0x34);
1543 /* Turn on D+ current source */
1544 chg_det |= (1 << 5);
1545 ulpi_write(otg, chg_det, 0x34);
1546 break;
1547 case SNPS_28NM_INTEGRATED_PHY:
1548 /* Data contact detection enable */
1549 ulpi_write(otg, 0x10, 0x85);
1550 break;
1551 default:
1552 break;
1553 }
1554}
1555
1556static void msm_chg_block_on(struct msm_otg *motg)
1557{
1558 struct otg_transceiver *otg = &motg->otg;
1559 u32 func_ctrl, chg_det;
1560
1561 /* put the controller in non-driving mode */
1562 func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL);
1563 func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
1564 func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
1565 ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL);
1566
1567 switch (motg->pdata->phy_type) {
1568 case CI_45NM_INTEGRATED_PHY:
1569 chg_det = ulpi_read(otg, 0x34);
1570 /* control chg block via ULPI */
1571 chg_det &= ~(1 << 3);
1572 ulpi_write(otg, chg_det, 0x34);
1573 /* Turn on chg detect block */
1574 chg_det &= ~(1 << 1);
1575 ulpi_write(otg, chg_det, 0x34);
1576 udelay(20);
1577 break;
1578 case SNPS_28NM_INTEGRATED_PHY:
1579 /* Clear charger detecting control bits */
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301580 ulpi_write(otg, 0x1F, 0x86);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301581 /* Clear alt interrupt latch and enable bits */
1582 ulpi_write(otg, 0x1F, 0x92);
1583 ulpi_write(otg, 0x1F, 0x95);
1584 udelay(100);
1585 break;
1586 default:
1587 break;
1588 }
1589}
1590
1591static void msm_chg_block_off(struct msm_otg *motg)
1592{
1593 struct otg_transceiver *otg = &motg->otg;
1594 u32 func_ctrl, chg_det;
1595
1596 switch (motg->pdata->phy_type) {
1597 case CI_45NM_INTEGRATED_PHY:
1598 chg_det = ulpi_read(otg, 0x34);
1599 /* Turn off charger block */
1600 chg_det |= ~(1 << 1);
1601 ulpi_write(otg, chg_det, 0x34);
1602 break;
1603 case SNPS_28NM_INTEGRATED_PHY:
1604 /* Clear charger detecting control bits */
1605 ulpi_write(otg, 0x3F, 0x86);
1606 /* Clear alt interrupt latch and enable bits */
1607 ulpi_write(otg, 0x1F, 0x92);
1608 ulpi_write(otg, 0x1F, 0x95);
1609 break;
1610 default:
1611 break;
1612 }
1613
1614 /* put the controller in normal mode */
1615 func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL);
1616 func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
1617 func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL;
1618 ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL);
1619}
1620
Anji jonnalad270e2d2011-08-09 11:28:32 +05301621static const char *chg_to_string(enum usb_chg_type chg_type)
1622{
1623 switch (chg_type) {
1624 case USB_SDP_CHARGER: return "USB_SDP_CHARGER";
1625 case USB_DCP_CHARGER: return "USB_DCP_CHARGER";
1626 case USB_CDP_CHARGER: return "USB_CDP_CHARGER";
1627 case USB_ACA_A_CHARGER: return "USB_ACA_A_CHARGER";
1628 case USB_ACA_B_CHARGER: return "USB_ACA_B_CHARGER";
1629 case USB_ACA_C_CHARGER: return "USB_ACA_C_CHARGER";
1630 case USB_ACA_DOCK_CHARGER: return "USB_ACA_DOCK_CHARGER";
1631 default: return "INVALID_CHARGER";
1632 }
1633}
1634
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301635#define MSM_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */
1636#define MSM_CHG_DCD_MAX_RETRIES 6 /* Tdcd_tmout = 6 * 100 msec */
1637#define MSM_CHG_PRIMARY_DET_TIME (40 * HZ/1000) /* TVDPSRC_ON */
1638#define MSM_CHG_SECONDARY_DET_TIME (40 * HZ/1000) /* TVDMSRC_ON */
1639static void msm_chg_detect_work(struct work_struct *w)
1640{
1641 struct msm_otg *motg = container_of(w, struct msm_otg, chg_work.work);
1642 struct otg_transceiver *otg = &motg->otg;
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +05301643 bool is_dcd = false, tmout, vout, is_aca;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301644 unsigned long delay;
1645
1646 dev_dbg(otg->dev, "chg detection work\n");
1647 switch (motg->chg_state) {
1648 case USB_CHG_STATE_UNDEFINED:
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301649 msm_chg_block_on(motg);
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +05301650 if (motg->pdata->enable_dcd)
1651 msm_chg_enable_dcd(motg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001652 msm_chg_enable_aca_det(motg);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301653 motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD;
1654 motg->dcd_retries = 0;
1655 delay = MSM_CHG_DCD_POLL_TIME;
1656 break;
1657 case USB_CHG_STATE_WAIT_FOR_DCD:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001658 is_aca = msm_chg_aca_detect(motg);
1659 if (is_aca) {
1660 /*
1661 * ID_A can be ACA dock too. continue
1662 * primary detection after DCD.
1663 */
1664 if (test_bit(ID_A, &motg->inputs)) {
1665 motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD;
1666 } else {
1667 delay = 0;
1668 break;
1669 }
1670 }
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +05301671 if (motg->pdata->enable_dcd)
1672 is_dcd = msm_chg_check_dcd(motg);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301673 tmout = ++motg->dcd_retries == MSM_CHG_DCD_MAX_RETRIES;
1674 if (is_dcd || tmout) {
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +05301675 if (motg->pdata->enable_dcd)
1676 msm_chg_disable_dcd(motg);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301677 msm_chg_enable_primary_det(motg);
1678 delay = MSM_CHG_PRIMARY_DET_TIME;
1679 motg->chg_state = USB_CHG_STATE_DCD_DONE;
1680 } else {
1681 delay = MSM_CHG_DCD_POLL_TIME;
1682 }
1683 break;
1684 case USB_CHG_STATE_DCD_DONE:
1685 vout = msm_chg_check_primary_det(motg);
1686 if (vout) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301687 if (test_bit(ID_A, &motg->inputs)) {
1688 motg->chg_type = USB_ACA_DOCK_CHARGER;
1689 motg->chg_state = USB_CHG_STATE_DETECTED;
1690 delay = 0;
1691 break;
1692 }
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301693 msm_chg_enable_secondary_det(motg);
1694 delay = MSM_CHG_SECONDARY_DET_TIME;
1695 motg->chg_state = USB_CHG_STATE_PRIMARY_DONE;
1696 } else {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301697 if (test_bit(ID_A, &motg->inputs)) {
1698 motg->chg_type = USB_ACA_A_CHARGER;
1699 motg->chg_state = USB_CHG_STATE_DETECTED;
1700 delay = 0;
1701 break;
1702 }
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301703 motg->chg_type = USB_SDP_CHARGER;
1704 motg->chg_state = USB_CHG_STATE_DETECTED;
1705 delay = 0;
1706 }
1707 break;
1708 case USB_CHG_STATE_PRIMARY_DONE:
1709 vout = msm_chg_check_secondary_det(motg);
1710 if (vout)
1711 motg->chg_type = USB_DCP_CHARGER;
1712 else
1713 motg->chg_type = USB_CDP_CHARGER;
1714 motg->chg_state = USB_CHG_STATE_SECONDARY_DONE;
1715 /* fall through */
1716 case USB_CHG_STATE_SECONDARY_DONE:
1717 motg->chg_state = USB_CHG_STATE_DETECTED;
1718 case USB_CHG_STATE_DETECTED:
1719 msm_chg_block_off(motg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001720 msm_chg_enable_aca_det(motg);
1721 msm_chg_enable_aca_intr(motg);
Anji jonnalad270e2d2011-08-09 11:28:32 +05301722 dev_dbg(otg->dev, "chg_type = %s\n",
1723 chg_to_string(motg->chg_type));
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301724 schedule_work(&motg->sm_work);
1725 return;
1726 default:
1727 return;
1728 }
1729
1730 schedule_delayed_work(&motg->chg_work, delay);
1731}
1732
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301733/*
1734 * We support OTG, Peripheral only and Host only configurations. In case
1735 * of OTG, mode switch (host-->peripheral/peripheral-->host) can happen
1736 * via Id pin status or user request (debugfs). Id/BSV interrupts are not
1737 * enabled when switch is controlled by user and default mode is supplied
1738 * by board file, which can be changed by userspace later.
1739 */
1740static void msm_otg_init_sm(struct msm_otg *motg)
1741{
1742 struct msm_otg_platform_data *pdata = motg->pdata;
1743 u32 otgsc = readl(USB_OTGSC);
1744
1745 switch (pdata->mode) {
1746 case USB_OTG:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001747 if (pdata->otg_control == OTG_USER_CONTROL) {
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301748 if (pdata->default_mode == USB_HOST) {
1749 clear_bit(ID, &motg->inputs);
1750 } else if (pdata->default_mode == USB_PERIPHERAL) {
1751 set_bit(ID, &motg->inputs);
1752 set_bit(B_SESS_VLD, &motg->inputs);
1753 } else {
1754 set_bit(ID, &motg->inputs);
1755 clear_bit(B_SESS_VLD, &motg->inputs);
1756 }
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301757 } else if (pdata->otg_control == OTG_PHY_CONTROL) {
1758 if (otgsc & OTGSC_ID)
1759 set_bit(ID, &motg->inputs);
1760 else
1761 clear_bit(ID, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001762 if (otgsc & OTGSC_BSV)
1763 set_bit(B_SESS_VLD, &motg->inputs);
1764 else
1765 clear_bit(B_SESS_VLD, &motg->inputs);
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301766 } else if (pdata->otg_control == OTG_PMIC_CONTROL) {
Pavankumar Kondeti0d81f312012-01-13 11:34:10 +05301767 if (pdata->pmic_id_irq) {
1768 if (irq_read_line(pdata->pmic_id_irq))
1769 set_bit(ID, &motg->inputs);
1770 else
1771 clear_bit(ID, &motg->inputs);
1772 }
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301773 /*
1774 * VBUS initial state is reported after PMIC
1775 * driver initialization. Wait for it.
1776 */
1777 wait_for_completion(&pmic_vbus_init);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301778 }
1779 break;
1780 case USB_HOST:
1781 clear_bit(ID, &motg->inputs);
1782 break;
1783 case USB_PERIPHERAL:
1784 set_bit(ID, &motg->inputs);
Pavankumar Kondeti0d81f312012-01-13 11:34:10 +05301785 if (pdata->otg_control == OTG_PHY_CONTROL) {
1786 if (otgsc & OTGSC_BSV)
1787 set_bit(B_SESS_VLD, &motg->inputs);
1788 else
1789 clear_bit(B_SESS_VLD, &motg->inputs);
1790 } else if (pdata->otg_control == OTG_PMIC_CONTROL) {
1791 /*
1792 * VBUS initial state is reported after PMIC
1793 * driver initialization. Wait for it.
1794 */
1795 wait_for_completion(&pmic_vbus_init);
1796 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301797 break;
1798 default:
1799 break;
1800 }
1801}
1802
1803static void msm_otg_sm_work(struct work_struct *w)
1804{
1805 struct msm_otg *motg = container_of(w, struct msm_otg, sm_work);
1806 struct otg_transceiver *otg = &motg->otg;
1807
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05301808 pm_runtime_resume(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301809 switch (otg->state) {
1810 case OTG_STATE_UNDEFINED:
1811 dev_dbg(otg->dev, "OTG_STATE_UNDEFINED state\n");
1812 msm_otg_reset(otg);
1813 msm_otg_init_sm(motg);
1814 otg->state = OTG_STATE_B_IDLE;
Pavankumar Kondeti8a379b42011-12-12 13:07:23 +05301815 if (!test_bit(B_SESS_VLD, &motg->inputs) &&
1816 test_bit(ID, &motg->inputs)) {
1817 pm_runtime_put_noidle(otg->dev);
1818 pm_runtime_suspend(otg->dev);
1819 break;
1820 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301821 /* FALL THROUGH */
1822 case OTG_STATE_B_IDLE:
1823 dev_dbg(otg->dev, "OTG_STATE_B_IDLE state\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001824 if ((!test_bit(ID, &motg->inputs) ||
1825 test_bit(ID_A, &motg->inputs)) && otg->host) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001826 if (motg->chg_type == USB_ACA_DOCK_CHARGER)
1827 msm_otg_notify_charger(motg,
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301828 IDEV_ACA_CHG_MAX);
1829 else if (test_bit(ID_A, &motg->inputs))
1830 msm_otg_notify_charger(motg,
1831 IDEV_ACA_CHG_MAX - IUNIT);
Mayank Ranae3926882011-12-26 09:47:54 +05301832 else
1833 msm_hsusb_vbus_power(motg, 1);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301834 msm_otg_start_host(otg, 1);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301835 /*
1836 * Link can not generate PHY_ALT interrupt
1837 * in host mode when no device is attached
1838 * to the port. It is also observed PHY_ALT
1839 * interrupt missing upon Micro-A cable disconnect.
1840 * Hence disable PHY_ALT interrupt and perform
1841 * polling to detect RID change.
1842 */
1843 msm_chg_enable_aca_det(motg);
1844 msm_chg_disable_aca_intr(motg);
1845 mod_timer(&motg->id_timer, ID_TIMER_FREQ);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301846 otg->state = OTG_STATE_A_HOST;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301847 } else if (test_bit(B_SESS_VLD, &motg->inputs)) {
1848 switch (motg->chg_state) {
1849 case USB_CHG_STATE_UNDEFINED:
1850 msm_chg_detect_work(&motg->chg_work.work);
1851 break;
1852 case USB_CHG_STATE_DETECTED:
1853 switch (motg->chg_type) {
1854 case USB_DCP_CHARGER:
1855 msm_otg_notify_charger(motg,
1856 IDEV_CHG_MAX);
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05301857 pm_runtime_put_noidle(otg->dev);
1858 pm_runtime_suspend(otg->dev);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301859 break;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301860 case USB_ACA_B_CHARGER:
1861 msm_otg_notify_charger(motg,
1862 IDEV_ACA_CHG_MAX);
1863 /*
1864 * (ID_B --> ID_C) PHY_ALT interrupt can
1865 * not be detected in LPM.
1866 */
1867 break;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301868 case USB_CDP_CHARGER:
1869 msm_otg_notify_charger(motg,
1870 IDEV_CHG_MAX);
1871 msm_otg_start_peripheral(otg, 1);
1872 otg->state = OTG_STATE_B_PERIPHERAL;
1873 break;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301874 case USB_ACA_C_CHARGER:
1875 msm_otg_notify_charger(motg,
1876 IDEV_ACA_CHG_MAX);
1877 msm_otg_start_peripheral(otg, 1);
1878 otg->state = OTG_STATE_B_PERIPHERAL;
1879 break;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301880 case USB_SDP_CHARGER:
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301881 msm_otg_start_peripheral(otg, 1);
1882 otg->state = OTG_STATE_B_PERIPHERAL;
1883 break;
1884 default:
1885 break;
1886 }
1887 break;
1888 default:
1889 break;
1890 }
1891 } else {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301892 cancel_delayed_work_sync(&motg->chg_work);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301893 msm_otg_notify_charger(motg, 0);
1894 motg->chg_state = USB_CHG_STATE_UNDEFINED;
1895 motg->chg_type = USB_INVALID_CHARGER;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301896 msm_otg_reset(otg);
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05301897 pm_runtime_put_noidle(otg->dev);
1898 pm_runtime_suspend(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301899 }
1900 break;
1901 case OTG_STATE_B_PERIPHERAL:
1902 dev_dbg(otg->dev, "OTG_STATE_B_PERIPHERAL state\n");
1903 if (!test_bit(B_SESS_VLD, &motg->inputs) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001904 !test_bit(ID, &motg->inputs) ||
1905 !test_bit(ID_C, &motg->inputs)) {
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301906 msm_otg_start_peripheral(otg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001907 otg->state = OTG_STATE_B_IDLE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001908 schedule_work(w);
1909 } else if (test_bit(ID_C, &motg->inputs)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301910 msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001911 }
1912 break;
1913 case OTG_STATE_A_HOST:
1914 dev_dbg(otg->dev, "OTG_STATE_A_HOST state\n");
1915 if (test_bit(ID, &motg->inputs) &&
1916 !test_bit(ID_A, &motg->inputs)) {
1917 msm_otg_start_host(otg, 0);
Mayank Ranae3926882011-12-26 09:47:54 +05301918 msm_hsusb_vbus_power(motg, 0);
1919 msleep(100); /* TA_WAIT_VFALL */
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301920 /*
1921 * Exit point of host mode.
1922 *
1923 * 1. Micro-A cable disconnect: Just schedule
1924 * the work. PHY is reset in B_IDLE and LPM
1925 * is allowed.
1926 * 2. ID_GND --> ID_B: No need to reset the PHY.
1927 * HCD core clears all PORTSC bits and initializes
1928 * the controller to host mode in remove_hcd.
1929 * Restore PORTSC transceiver select bits (ULPI)
1930 * and reset the controller to change MODE bits.
1931 * PHY_ALT interrupt can not occur in host mode.
1932 */
1933 del_timer_sync(&motg->id_timer);
1934 if (motg->chg_state != USB_CHG_STATE_UNDEFINED) {
1935 msm_otg_link_reset(motg);
1936 msm_chg_enable_aca_intr(motg);
1937 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301938 otg->state = OTG_STATE_B_IDLE;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301939 schedule_work(w);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001940 } else if (test_bit(ID_A, &motg->inputs)) {
Mayank Ranae3926882011-12-26 09:47:54 +05301941 msm_hsusb_vbus_power(motg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001942 msm_otg_notify_charger(motg,
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301943 IDEV_ACA_CHG_MAX - motg->mA_port);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001944 } else if (!test_bit(ID, &motg->inputs)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001945 msm_otg_notify_charger(motg, 0);
Mayank Ranae3926882011-12-26 09:47:54 +05301946 msm_hsusb_vbus_power(motg, 1);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301947 }
1948 break;
1949 default:
1950 break;
1951 }
1952}
1953
1954static irqreturn_t msm_otg_irq(int irq, void *data)
1955{
1956 struct msm_otg *motg = data;
1957 struct otg_transceiver *otg = &motg->otg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001958 u32 otgsc = 0, usbsts;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301959
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301960 if (atomic_read(&motg->in_lpm)) {
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301961 pr_debug("OTG IRQ: in LPM\n");
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301962 disable_irq_nosync(irq);
1963 motg->async_int = 1;
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05301964 pm_request_resume(otg->dev);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301965 return IRQ_HANDLED;
1966 }
1967
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001968 usbsts = readl(USB_USBSTS);
1969 if ((usbsts & PHY_ALT_INT)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301970 dev_dbg(otg->dev, "PHY_ALT interrupt\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001971 writel(PHY_ALT_INT, USB_USBSTS);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301972 if (msm_chg_check_aca_intr(motg)) {
1973 dev_dbg(otg->dev, "ACA work from IRQ\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001974 schedule_work(&motg->sm_work);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301975 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001976 return IRQ_HANDLED;
1977 }
1978
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301979 otgsc = readl(USB_OTGSC);
1980 if (!(otgsc & (OTGSC_IDIS | OTGSC_BSVIS)))
1981 return IRQ_NONE;
1982
1983 if ((otgsc & OTGSC_IDIS) && (otgsc & OTGSC_IDIE)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301984 if (otgsc & OTGSC_ID) {
1985 dev_dbg(otg->dev, "ID set\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301986 set_bit(ID, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301987 } else {
1988 dev_dbg(otg->dev, "ID clear\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301989 clear_bit(ID, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301990 msm_chg_enable_aca_det(motg);
1991 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001992 schedule_work(&motg->sm_work);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301993 } else if ((otgsc & OTGSC_BSVIS) && (otgsc & OTGSC_BSVIE)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301994 if (otgsc & OTGSC_BSV) {
1995 dev_dbg(otg->dev, "BSV set\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301996 set_bit(B_SESS_VLD, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301997 } else {
1998 dev_dbg(otg->dev, "BSV clear\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301999 clear_bit(B_SESS_VLD, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302000 msm_chg_check_aca_intr(motg);
2001 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002002 schedule_work(&motg->sm_work);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302003 }
2004
2005 writel(otgsc, USB_OTGSC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002006 return IRQ_HANDLED;
2007}
2008
2009static void msm_otg_set_vbus_state(int online)
2010{
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05302011 static bool init;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002012 struct msm_otg *motg = the_msm_otg;
2013
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05302014 if (online) {
2015 pr_debug("PMIC: BSV set\n");
2016 set_bit(B_SESS_VLD, &motg->inputs);
2017 } else {
2018 pr_debug("PMIC: BSV clear\n");
2019 clear_bit(B_SESS_VLD, &motg->inputs);
2020 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002021
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05302022 if (!init) {
2023 init = true;
2024 complete(&pmic_vbus_init);
2025 pr_debug("PMIC: BSV init complete\n");
2026 return;
2027 }
2028
2029 schedule_work(&motg->sm_work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002030}
2031
2032static irqreturn_t msm_pmic_id_irq(int irq, void *data)
2033{
2034 struct msm_otg *motg = data;
2035
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05302036 if (aca_id_turned_on)
2037 return IRQ_HANDLED;
2038
2039 if (irq_read_line(motg->pdata->pmic_id_irq)) {
2040 pr_debug("PMIC: ID set\n");
2041 set_bit(ID, &motg->inputs);
2042 } else {
2043 pr_debug("PMIC: ID clear\n");
2044 clear_bit(ID, &motg->inputs);
2045 }
2046
2047 if (motg->otg.state != OTG_STATE_UNDEFINED)
2048 schedule_work(&motg->sm_work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002049
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302050 return IRQ_HANDLED;
2051}
2052
2053static int msm_otg_mode_show(struct seq_file *s, void *unused)
2054{
2055 struct msm_otg *motg = s->private;
2056 struct otg_transceiver *otg = &motg->otg;
2057
2058 switch (otg->state) {
2059 case OTG_STATE_A_HOST:
2060 seq_printf(s, "host\n");
2061 break;
2062 case OTG_STATE_B_PERIPHERAL:
2063 seq_printf(s, "peripheral\n");
2064 break;
2065 default:
2066 seq_printf(s, "none\n");
2067 break;
2068 }
2069
2070 return 0;
2071}
2072
2073static int msm_otg_mode_open(struct inode *inode, struct file *file)
2074{
2075 return single_open(file, msm_otg_mode_show, inode->i_private);
2076}
2077
2078static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
2079 size_t count, loff_t *ppos)
2080{
Pavankumar Kondetie2904ee2011-02-15 09:42:35 +05302081 struct seq_file *s = file->private_data;
2082 struct msm_otg *motg = s->private;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302083 char buf[16];
2084 struct otg_transceiver *otg = &motg->otg;
2085 int status = count;
2086 enum usb_mode_type req_mode;
2087
2088 memset(buf, 0x00, sizeof(buf));
2089
2090 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) {
2091 status = -EFAULT;
2092 goto out;
2093 }
2094
2095 if (!strncmp(buf, "host", 4)) {
2096 req_mode = USB_HOST;
2097 } else if (!strncmp(buf, "peripheral", 10)) {
2098 req_mode = USB_PERIPHERAL;
2099 } else if (!strncmp(buf, "none", 4)) {
2100 req_mode = USB_NONE;
2101 } else {
2102 status = -EINVAL;
2103 goto out;
2104 }
2105
2106 switch (req_mode) {
2107 case USB_NONE:
2108 switch (otg->state) {
2109 case OTG_STATE_A_HOST:
2110 case OTG_STATE_B_PERIPHERAL:
2111 set_bit(ID, &motg->inputs);
2112 clear_bit(B_SESS_VLD, &motg->inputs);
2113 break;
2114 default:
2115 goto out;
2116 }
2117 break;
2118 case USB_PERIPHERAL:
2119 switch (otg->state) {
2120 case OTG_STATE_B_IDLE:
2121 case OTG_STATE_A_HOST:
2122 set_bit(ID, &motg->inputs);
2123 set_bit(B_SESS_VLD, &motg->inputs);
2124 break;
2125 default:
2126 goto out;
2127 }
2128 break;
2129 case USB_HOST:
2130 switch (otg->state) {
2131 case OTG_STATE_B_IDLE:
2132 case OTG_STATE_B_PERIPHERAL:
2133 clear_bit(ID, &motg->inputs);
2134 break;
2135 default:
2136 goto out;
2137 }
2138 break;
2139 default:
2140 goto out;
2141 }
2142
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302143 pm_runtime_resume(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302144 schedule_work(&motg->sm_work);
2145out:
2146 return status;
2147}
2148
2149const struct file_operations msm_otg_mode_fops = {
2150 .open = msm_otg_mode_open,
2151 .read = seq_read,
2152 .write = msm_otg_mode_write,
2153 .llseek = seq_lseek,
2154 .release = single_release,
2155};
2156
Anji jonnalad270e2d2011-08-09 11:28:32 +05302157static int msm_otg_show_chg_type(struct seq_file *s, void *unused)
2158{
2159 struct msm_otg *motg = s->private;
2160
Pavankumar Kondeti9ef69cb2011-12-12 14:18:22 +05302161 seq_printf(s, "%s\n", chg_to_string(motg->chg_type));
Anji jonnalad270e2d2011-08-09 11:28:32 +05302162 return 0;
2163}
2164
2165static int msm_otg_chg_open(struct inode *inode, struct file *file)
2166{
2167 return single_open(file, msm_otg_show_chg_type, inode->i_private);
2168}
2169
2170const struct file_operations msm_otg_chg_fops = {
2171 .open = msm_otg_chg_open,
2172 .read = seq_read,
2173 .llseek = seq_lseek,
2174 .release = single_release,
2175};
2176
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302177static int msm_otg_aca_show(struct seq_file *s, void *unused)
2178{
2179 if (debug_aca_enabled)
2180 seq_printf(s, "enabled\n");
2181 else
2182 seq_printf(s, "disabled\n");
2183
2184 return 0;
2185}
2186
2187static int msm_otg_aca_open(struct inode *inode, struct file *file)
2188{
2189 return single_open(file, msm_otg_aca_show, inode->i_private);
2190}
2191
2192static ssize_t msm_otg_aca_write(struct file *file, const char __user *ubuf,
2193 size_t count, loff_t *ppos)
2194{
2195 char buf[8];
2196
2197 memset(buf, 0x00, sizeof(buf));
2198
2199 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
2200 return -EFAULT;
2201
2202 if (!strncmp(buf, "enable", 6))
2203 debug_aca_enabled = true;
2204 else
2205 debug_aca_enabled = false;
2206
2207 return count;
2208}
2209
2210const struct file_operations msm_otg_aca_fops = {
2211 .open = msm_otg_aca_open,
2212 .read = seq_read,
2213 .write = msm_otg_aca_write,
2214 .llseek = seq_lseek,
2215 .release = single_release,
2216};
2217
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302218static struct dentry *msm_otg_dbg_root;
2219static struct dentry *msm_otg_dbg_mode;
Anji jonnalad270e2d2011-08-09 11:28:32 +05302220static struct dentry *msm_otg_chg_type;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302221static struct dentry *msm_otg_dbg_aca;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302222
2223static int msm_otg_debugfs_init(struct msm_otg *motg)
2224{
Anji jonnalad270e2d2011-08-09 11:28:32 +05302225
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302226 msm_otg_dbg_root = debugfs_create_dir("msm_otg", NULL);
2227
2228 if (!msm_otg_dbg_root || IS_ERR(msm_otg_dbg_root))
2229 return -ENODEV;
2230
Anji jonnalad270e2d2011-08-09 11:28:32 +05302231 if (motg->pdata->mode == USB_OTG &&
2232 motg->pdata->otg_control == OTG_USER_CONTROL) {
2233
2234 msm_otg_dbg_mode = debugfs_create_file("mode", S_IRUGO |
2235 S_IWUSR, msm_otg_dbg_root, motg,
2236 &msm_otg_mode_fops);
2237
2238 if (!msm_otg_dbg_mode) {
2239 debugfs_remove(msm_otg_dbg_root);
2240 msm_otg_dbg_root = NULL;
2241 return -ENODEV;
2242 }
2243 }
2244
2245 msm_otg_chg_type = debugfs_create_file("chg_type", S_IRUGO,
2246 msm_otg_dbg_root, motg,
2247 &msm_otg_chg_fops);
2248
2249 if (!msm_otg_chg_type) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302250 debugfs_remove_recursive(msm_otg_dbg_root);
2251 return -ENODEV;
2252 }
2253
2254 msm_otg_dbg_aca = debugfs_create_file("aca", S_IRUGO | S_IWUSR,
2255 msm_otg_dbg_root, motg,
2256 &msm_otg_aca_fops);
2257
2258 if (!msm_otg_dbg_aca) {
2259 debugfs_remove_recursive(msm_otg_dbg_root);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302260 return -ENODEV;
2261 }
2262
2263 return 0;
2264}
2265
2266static void msm_otg_debugfs_cleanup(void)
2267{
Anji jonnalad270e2d2011-08-09 11:28:32 +05302268 debugfs_remove_recursive(msm_otg_dbg_root);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302269}
2270
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302271static u64 msm_otg_dma_mask = DMA_BIT_MASK(64);
2272static struct platform_device *msm_otg_add_pdev(
2273 struct platform_device *ofdev, const char *name)
2274{
2275 struct platform_device *pdev;
2276 const struct resource *res = ofdev->resource;
2277 unsigned int num = ofdev->num_resources;
2278 int retval;
2279
2280 pdev = platform_device_alloc(name, -1);
2281 if (!pdev) {
2282 retval = -ENOMEM;
2283 goto error;
2284 }
2285
2286 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
2287 pdev->dev.dma_mask = &msm_otg_dma_mask;
2288
2289 if (num) {
2290 retval = platform_device_add_resources(pdev, res, num);
2291 if (retval)
2292 goto error;
2293 }
2294
2295 retval = platform_device_add(pdev);
2296 if (retval)
2297 goto error;
2298
2299 return pdev;
2300
2301error:
2302 platform_device_put(pdev);
2303 return ERR_PTR(retval);
2304}
2305
2306static int msm_otg_setup_devices(struct platform_device *ofdev,
2307 enum usb_mode_type mode, bool init)
2308{
2309 const char *gadget_name = "msm_hsusb";
2310 const char *host_name = "msm_hsusb_host";
2311 static struct platform_device *gadget_pdev;
2312 static struct platform_device *host_pdev;
2313 int retval = 0;
2314
2315 if (!init) {
2316 if (gadget_pdev)
2317 platform_device_unregister(gadget_pdev);
2318 if (host_pdev)
2319 platform_device_unregister(host_pdev);
2320 return 0;
2321 }
2322
2323 switch (mode) {
2324 case USB_OTG:
2325 /* fall through */
2326 case USB_PERIPHERAL:
2327 gadget_pdev = msm_otg_add_pdev(ofdev, gadget_name);
2328 if (IS_ERR(gadget_pdev)) {
2329 retval = PTR_ERR(gadget_pdev);
2330 break;
2331 }
2332 if (mode == USB_PERIPHERAL)
2333 break;
2334 /* fall through */
2335 case USB_HOST:
2336 host_pdev = msm_otg_add_pdev(ofdev, host_name);
2337 if (IS_ERR(host_pdev)) {
2338 retval = PTR_ERR(host_pdev);
2339 if (mode == USB_OTG)
2340 platform_device_unregister(gadget_pdev);
2341 }
2342 break;
2343 default:
2344 break;
2345 }
2346
2347 return retval;
2348}
2349
2350struct msm_otg_platform_data *msm_otg_dt_to_pdata(struct platform_device *pdev)
2351{
2352 struct device_node *node = pdev->dev.of_node;
2353 struct msm_otg_platform_data *pdata;
2354 int len = 0;
2355
2356 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
2357 if (!pdata) {
2358 pr_err("unable to allocate platform data\n");
2359 return NULL;
2360 }
2361 of_get_property(node, "qcom,hsusb-otg-phy-init-seq", &len);
2362 if (len) {
2363 pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
2364 if (!pdata->phy_init_seq)
2365 return NULL;
2366 of_property_read_u32_array(node, "qcom,hsusb-otg-phy-init-seq",
2367 pdata->phy_init_seq,
2368 len/sizeof(*pdata->phy_init_seq));
2369 }
2370 of_property_read_u32(node, "qcom,hsusb-otg-power-budget",
2371 &pdata->power_budget);
2372 of_property_read_u32(node, "qcom,hsusb-otg-mode",
2373 &pdata->mode);
2374 of_property_read_u32(node, "qcom,hsusb-otg-otg-control",
2375 &pdata->otg_control);
2376 of_property_read_u32(node, "qcom,hsusb-otg-default-mode",
2377 &pdata->default_mode);
2378 of_property_read_u32(node, "qcom,hsusb-otg-phy-type",
2379 &pdata->phy_type);
2380 of_property_read_u32(node, "qcom,hsusb-otg-pmic-id-irq",
2381 &pdata->pmic_id_irq);
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302382 return pdata;
2383}
2384
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302385static int __init msm_otg_probe(struct platform_device *pdev)
2386{
2387 int ret = 0;
2388 struct resource *res;
2389 struct msm_otg *motg;
2390 struct otg_transceiver *otg;
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302391 struct msm_otg_platform_data *pdata;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302392
2393 dev_info(&pdev->dev, "msm_otg probe\n");
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302394
2395 if (pdev->dev.of_node) {
2396 dev_dbg(&pdev->dev, "device tree enabled\n");
2397 pdata = msm_otg_dt_to_pdata(pdev);
2398 if (!pdata)
2399 return -ENOMEM;
2400 ret = msm_otg_setup_devices(pdev, pdata->mode, true);
2401 if (ret) {
2402 dev_err(&pdev->dev, "devices setup failed\n");
2403 return ret;
2404 }
2405 } else if (!pdev->dev.platform_data) {
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302406 dev_err(&pdev->dev, "No platform data given. Bailing out\n");
2407 return -ENODEV;
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302408 } else {
2409 pdata = pdev->dev.platform_data;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302410 }
2411
2412 motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL);
2413 if (!motg) {
2414 dev_err(&pdev->dev, "unable to allocate msm_otg\n");
2415 return -ENOMEM;
2416 }
2417
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002418 the_msm_otg = motg;
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302419 motg->pdata = pdata;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302420 otg = &motg->otg;
2421 otg->dev = &pdev->dev;
2422
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302423 /*
2424 * ACA ID_GND threshold range is overlapped with OTG ID_FLOAT. Hence
2425 * PHY treat ACA ID_GND as float and no interrupt is generated. But
2426 * PMIC can detect ACA ID_GND and generate an interrupt.
2427 */
2428 if (aca_enabled() && motg->pdata->otg_control != OTG_PMIC_CONTROL) {
2429 dev_err(&pdev->dev, "ACA can not be enabled without PMIC\n");
2430 ret = -EINVAL;
2431 goto free_motg;
2432 }
2433
Ofir Cohen4da266f2012-01-03 10:19:29 +02002434 /* initialize reset counter */
2435 motg->reset_counter = 0;
2436
Amit Blay02eff132011-09-21 16:46:24 +03002437 /* Some targets don't support PHY clock. */
Manu Gautam5143b252012-01-05 19:25:23 -08002438 motg->phy_reset_clk = clk_get(&pdev->dev, "phy_clk");
Amit Blay02eff132011-09-21 16:46:24 +03002439 if (IS_ERR(motg->phy_reset_clk))
Manu Gautam5143b252012-01-05 19:25:23 -08002440 dev_err(&pdev->dev, "failed to get phy_clk\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302441
Manu Gautam5143b252012-01-05 19:25:23 -08002442 motg->clk = clk_get(&pdev->dev, "alt_core_clk");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302443 if (IS_ERR(motg->clk)) {
Manu Gautam5143b252012-01-05 19:25:23 -08002444 dev_err(&pdev->dev, "failed to get alt_core_clk\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302445 ret = PTR_ERR(motg->clk);
2446 goto put_phy_reset_clk;
2447 }
Anji jonnala0f73cac2011-05-04 10:19:46 +05302448 clk_set_rate(motg->clk, 60000000);
2449
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05302450 /* pm qos request to prevent apps idle power collapse */
2451 if (motg->pdata->swfi_latency)
2452 pm_qos_add_request(&motg->pm_qos_req_dma,
2453 PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Manu Gautam5143b252012-01-05 19:25:23 -08002454
Anji jonnala0f73cac2011-05-04 10:19:46 +05302455 /*
Manu Gautam5143b252012-01-05 19:25:23 -08002456 * USB Core is running its protocol engine based on CORE CLK,
Anji jonnala0f73cac2011-05-04 10:19:46 +05302457 * CORE CLK must be running at >55Mhz for correct HSUSB
2458 * operation and USB core cannot tolerate frequency changes on
2459 * CORE CLK. For such USB cores, vote for maximum clk frequency
2460 * on pclk source
2461 */
Manu Gautam5143b252012-01-05 19:25:23 -08002462 motg->core_clk = clk_get(&pdev->dev, "core_clk");
2463 if (IS_ERR(motg->core_clk)) {
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302464 motg->core_clk = NULL;
Manu Gautam5143b252012-01-05 19:25:23 -08002465 dev_err(&pdev->dev, "failed to get core_clk\n");
2466 ret = PTR_ERR(motg->clk);
2467 goto put_clk;
2468 }
2469 clk_set_rate(motg->core_clk, INT_MAX);
2470
2471 motg->pclk = clk_get(&pdev->dev, "iface_clk");
2472 if (IS_ERR(motg->pclk)) {
2473 dev_err(&pdev->dev, "failed to get iface_clk\n");
2474 ret = PTR_ERR(motg->pclk);
2475 goto put_core_clk;
2476 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302477
2478 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2479 if (!res) {
2480 dev_err(&pdev->dev, "failed to get platform resource mem\n");
2481 ret = -ENODEV;
Manu Gautam5143b252012-01-05 19:25:23 -08002482 goto put_pclk;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302483 }
2484
2485 motg->regs = ioremap(res->start, resource_size(res));
2486 if (!motg->regs) {
2487 dev_err(&pdev->dev, "ioremap failed\n");
2488 ret = -ENOMEM;
Manu Gautam5143b252012-01-05 19:25:23 -08002489 goto put_pclk;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302490 }
2491 dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs);
2492
2493 motg->irq = platform_get_irq(pdev, 0);
2494 if (!motg->irq) {
2495 dev_err(&pdev->dev, "platform_get_irq failed\n");
2496 ret = -ENODEV;
2497 goto free_regs;
2498 }
2499
Stephen Boyd7dd22662012-01-26 16:09:31 -08002500 motg->xo_handle = clk_get(&pdev->dev, "xo");
Anji jonnala7da3f262011-12-02 17:22:14 -08002501 if (IS_ERR(motg->xo_handle)) {
2502 dev_err(&pdev->dev, "%s not able to get the handle "
2503 "to vote for TCXO D0 buffer\n", __func__);
2504 ret = PTR_ERR(motg->xo_handle);
2505 goto free_regs;
2506 }
2507
Stephen Boyd7dd22662012-01-26 16:09:31 -08002508 ret = clk_prepare_enable(motg->xo_handle);
Anji jonnala7da3f262011-12-02 17:22:14 -08002509 if (ret) {
2510 dev_err(&pdev->dev, "%s failed to vote for TCXO "
2511 "D0 buffer%d\n", __func__, ret);
2512 goto free_xo_handle;
2513 }
2514
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302515 clk_enable(motg->pclk);
Anji jonnala11aa5c42011-05-04 10:19:48 +05302516
2517 ret = msm_hsusb_init_vddcx(motg, 1);
2518 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002519 dev_err(&pdev->dev, "hsusb vddcx init failed\n");
Anji jonnala7da3f262011-12-02 17:22:14 -08002520 goto devote_xo_handle;
Anji jonnala11aa5c42011-05-04 10:19:48 +05302521 }
2522
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002523 ret = msm_hsusb_config_vddcx(1);
2524 if (ret) {
2525 dev_err(&pdev->dev, "hsusb vddcx configuration failed\n");
2526 goto free_init_vddcx;
2527 }
2528
Anji jonnala11aa5c42011-05-04 10:19:48 +05302529 ret = msm_hsusb_ldo_init(motg, 1);
2530 if (ret) {
2531 dev_err(&pdev->dev, "hsusb vreg configuration failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002532 goto free_init_vddcx;
Anji jonnala11aa5c42011-05-04 10:19:48 +05302533 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002534
2535 ret = msm_hsusb_ldo_enable(motg, 1);
Anji jonnala11aa5c42011-05-04 10:19:48 +05302536 if (ret) {
2537 dev_err(&pdev->dev, "hsusb vreg enable failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002538 goto free_ldo_init;
Anji jonnala11aa5c42011-05-04 10:19:48 +05302539 }
Manu Gautam5143b252012-01-05 19:25:23 -08002540 clk_enable(motg->core_clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302541
2542 writel(0, USB_USBINTR);
2543 writel(0, USB_OTGSC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002544 /* Ensure that above STOREs are completed before enabling interrupts */
2545 mb();
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302546
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002547 wake_lock_init(&motg->wlock, WAKE_LOCK_SUSPEND, "msm_otg");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302548 INIT_WORK(&motg->sm_work, msm_otg_sm_work);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05302549 INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302550 setup_timer(&motg->id_timer, msm_otg_id_timer_func,
2551 (unsigned long) motg);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302552 ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED,
2553 "msm_otg", motg);
2554 if (ret) {
2555 dev_err(&pdev->dev, "request irq failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002556 goto destroy_wlock;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302557 }
2558
2559 otg->init = msm_otg_reset;
2560 otg->set_host = msm_otg_set_host;
2561 otg->set_peripheral = msm_otg_set_peripheral;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05302562 otg->set_power = msm_otg_set_power;
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302563 otg->set_suspend = msm_otg_set_suspend;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302564
2565 otg->io_ops = &msm_otg_io_ops;
2566
2567 ret = otg_set_transceiver(&motg->otg);
2568 if (ret) {
2569 dev_err(&pdev->dev, "otg_set_transceiver failed\n");
2570 goto free_irq;
2571 }
2572
Pavankumar Kondeti0d81f312012-01-13 11:34:10 +05302573 if (motg->pdata->mode == USB_OTG &&
2574 motg->pdata->otg_control == OTG_PMIC_CONTROL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002575 if (motg->pdata->pmic_id_irq) {
2576 ret = request_irq(motg->pdata->pmic_id_irq,
2577 msm_pmic_id_irq,
2578 IRQF_TRIGGER_RISING |
2579 IRQF_TRIGGER_FALLING,
2580 "msm_otg", motg);
2581 if (ret) {
2582 dev_err(&pdev->dev, "request irq failed for PMIC ID\n");
2583 goto remove_otg;
2584 }
2585 } else {
2586 ret = -ENODEV;
2587 dev_err(&pdev->dev, "PMIC IRQ for ID notifications doesn't exist\n");
2588 goto remove_otg;
2589 }
2590 }
2591
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +05302592 msm_hsusb_mhl_switch_enable(motg, 1);
2593
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302594 platform_set_drvdata(pdev, motg);
2595 device_init_wakeup(&pdev->dev, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002596 motg->mA_port = IUNIT;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302597
Anji jonnalad270e2d2011-08-09 11:28:32 +05302598 ret = msm_otg_debugfs_init(motg);
2599 if (ret)
2600 dev_dbg(&pdev->dev, "mode debugfs file is"
2601 "not available\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302602
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002603 if (motg->pdata->otg_control == OTG_PMIC_CONTROL)
2604 pm8921_charger_register_vbus_sn(&msm_otg_set_vbus_state);
2605
Amit Blay58b31472011-11-18 09:39:39 +02002606 if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY) {
2607 if (motg->pdata->otg_control == OTG_PMIC_CONTROL &&
Pavankumar Kondeti0d81f312012-01-13 11:34:10 +05302608 (!(motg->pdata->mode == USB_OTG) ||
2609 motg->pdata->pmic_id_irq))
Amit Blay58b31472011-11-18 09:39:39 +02002610 motg->caps = ALLOW_PHY_POWER_COLLAPSE |
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002611 ALLOW_PHY_RETENTION |
2612 ALLOW_PHY_COMP_DISABLE;
2613
Amit Blay58b31472011-11-18 09:39:39 +02002614 if (motg->pdata->otg_control == OTG_PHY_CONTROL)
2615 motg->caps = ALLOW_PHY_RETENTION;
2616 }
2617
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002618 wake_lock(&motg->wlock);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302619 pm_runtime_set_active(&pdev->dev);
2620 pm_runtime_enable(&pdev->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302621
Manu Gautamcd82e9d2011-12-20 14:17:28 +05302622 if (motg->pdata->bus_scale_table) {
2623 motg->bus_perf_client =
2624 msm_bus_scale_register_client(motg->pdata->bus_scale_table);
2625 if (!motg->bus_perf_client)
2626 dev_err(motg->otg.dev, "%s: Failed to register BUS "
2627 "scaling client!!\n", __func__);
2628 }
2629
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302630 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002631
2632remove_otg:
2633 otg_set_transceiver(NULL);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302634free_irq:
2635 free_irq(motg->irq, motg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002636destroy_wlock:
2637 wake_lock_destroy(&motg->wlock);
Manu Gautam5143b252012-01-05 19:25:23 -08002638 clk_disable(motg->core_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002639 msm_hsusb_ldo_enable(motg, 0);
2640free_ldo_init:
Anji jonnala11aa5c42011-05-04 10:19:48 +05302641 msm_hsusb_ldo_init(motg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002642free_init_vddcx:
Anji jonnala11aa5c42011-05-04 10:19:48 +05302643 msm_hsusb_init_vddcx(motg, 0);
Anji jonnala7da3f262011-12-02 17:22:14 -08002644devote_xo_handle:
Manu Gautam5143b252012-01-05 19:25:23 -08002645 clk_disable(motg->pclk);
Stephen Boyd7dd22662012-01-26 16:09:31 -08002646 clk_disable_unprepare(motg->xo_handle);
Anji jonnala7da3f262011-12-02 17:22:14 -08002647free_xo_handle:
Stephen Boyd7dd22662012-01-26 16:09:31 -08002648 clk_put(motg->xo_handle);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302649free_regs:
2650 iounmap(motg->regs);
Manu Gautam5143b252012-01-05 19:25:23 -08002651put_pclk:
2652 clk_put(motg->pclk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302653put_core_clk:
Manu Gautam5143b252012-01-05 19:25:23 -08002654 clk_put(motg->core_clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302655put_clk:
2656 clk_put(motg->clk);
2657put_phy_reset_clk:
Amit Blay02eff132011-09-21 16:46:24 +03002658 if (!IS_ERR(motg->phy_reset_clk))
2659 clk_put(motg->phy_reset_clk);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302660free_motg:
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05302661 if (motg->pdata->swfi_latency)
2662 pm_qos_remove_request(&motg->pm_qos_req_dma);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302663 kfree(motg);
2664 return ret;
2665}
2666
2667static int __devexit msm_otg_remove(struct platform_device *pdev)
2668{
2669 struct msm_otg *motg = platform_get_drvdata(pdev);
2670 struct otg_transceiver *otg = &motg->otg;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302671 int cnt = 0;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302672
2673 if (otg->host || otg->gadget)
2674 return -EBUSY;
2675
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302676 if (pdev->dev.of_node)
2677 msm_otg_setup_devices(pdev, motg->pdata->mode, false);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002678 if (motg->pdata->otg_control == OTG_PMIC_CONTROL)
2679 pm8921_charger_unregister_vbus_sn(0);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302680 msm_otg_debugfs_cleanup();
Pavankumar Kondetid8608522011-05-04 10:19:47 +05302681 cancel_delayed_work_sync(&motg->chg_work);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302682 cancel_work_sync(&motg->sm_work);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302683
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302684 pm_runtime_resume(&pdev->dev);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302685
2686 device_init_wakeup(&pdev->dev, 0);
2687 pm_runtime_disable(&pdev->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002688 wake_lock_destroy(&motg->wlock);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302689
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +05302690 msm_hsusb_mhl_switch_enable(motg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002691 if (motg->pdata->pmic_id_irq)
2692 free_irq(motg->pdata->pmic_id_irq, motg);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302693 otg_set_transceiver(NULL);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302694 free_irq(motg->irq, motg);
2695
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302696 /*
2697 * Put PHY in low power mode.
2698 */
2699 ulpi_read(otg, 0x14);
2700 ulpi_write(otg, 0x08, 0x09);
2701
2702 writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC);
2703 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
2704 if (readl(USB_PORTSC) & PORTSC_PHCD)
2705 break;
2706 udelay(1);
2707 cnt++;
2708 }
2709 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC)
2710 dev_err(otg->dev, "Unable to suspend PHY\n");
2711
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302712 clk_disable(motg->pclk);
Manu Gautam5143b252012-01-05 19:25:23 -08002713 clk_disable(motg->core_clk);
Stephen Boyd7dd22662012-01-26 16:09:31 -08002714 clk_put(motg->xo_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002715 msm_hsusb_ldo_enable(motg, 0);
Anji jonnala11aa5c42011-05-04 10:19:48 +05302716 msm_hsusb_ldo_init(motg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002717 msm_hsusb_init_vddcx(motg, 0);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302718
2719 iounmap(motg->regs);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302720 pm_runtime_set_suspended(&pdev->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302721
Amit Blay02eff132011-09-21 16:46:24 +03002722 if (!IS_ERR(motg->phy_reset_clk))
2723 clk_put(motg->phy_reset_clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302724 clk_put(motg->pclk);
2725 clk_put(motg->clk);
Manu Gautam5143b252012-01-05 19:25:23 -08002726 clk_put(motg->core_clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302727
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05302728 if (motg->pdata->swfi_latency)
2729 pm_qos_remove_request(&motg->pm_qos_req_dma);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302730
Manu Gautamcd82e9d2011-12-20 14:17:28 +05302731 if (motg->bus_perf_client)
2732 msm_bus_scale_unregister_client(motg->bus_perf_client);
2733
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05302734 kfree(motg);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302735 return 0;
2736}
2737
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302738#ifdef CONFIG_PM_RUNTIME
2739static int msm_otg_runtime_idle(struct device *dev)
2740{
2741 struct msm_otg *motg = dev_get_drvdata(dev);
2742 struct otg_transceiver *otg = &motg->otg;
2743
2744 dev_dbg(dev, "OTG runtime idle\n");
2745
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302746 if (otg->state == OTG_STATE_UNDEFINED)
2747 return -EAGAIN;
2748 else
2749 return 0;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302750}
2751
2752static int msm_otg_runtime_suspend(struct device *dev)
2753{
2754 struct msm_otg *motg = dev_get_drvdata(dev);
2755
2756 dev_dbg(dev, "OTG runtime suspend\n");
2757 return msm_otg_suspend(motg);
2758}
2759
2760static int msm_otg_runtime_resume(struct device *dev)
2761{
2762 struct msm_otg *motg = dev_get_drvdata(dev);
2763
2764 dev_dbg(dev, "OTG runtime resume\n");
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302765 pm_runtime_get_noresume(dev);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302766 return msm_otg_resume(motg);
2767}
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302768#endif
2769
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302770#ifdef CONFIG_PM_SLEEP
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302771static int msm_otg_pm_suspend(struct device *dev)
2772{
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302773 int ret;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302774
2775 dev_dbg(dev, "OTG PM suspend\n");
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302776
2777#ifdef CONFIG_PM_RUNTIME
2778 ret = pm_runtime_suspend(dev);
2779 if (ret > 0)
2780 ret = 0;
2781#else
2782 ret = msm_otg_suspend(dev_get_drvdata(dev));
2783#endif
2784 return ret;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302785}
2786
2787static int msm_otg_pm_resume(struct device *dev)
2788{
2789 struct msm_otg *motg = dev_get_drvdata(dev);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302790
2791 dev_dbg(dev, "OTG PM resume\n");
2792
Manu Gautamf284c052011-09-08 16:52:48 +05302793#ifdef CONFIG_PM_RUNTIME
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302794 /*
Manu Gautamf284c052011-09-08 16:52:48 +05302795 * Do not resume hardware as part of system resume,
2796 * rather, wait for the ASYNC INT from the h/w
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302797 */
Gregory Beanebd8ca22011-10-11 12:02:35 -07002798 return 0;
Manu Gautamf284c052011-09-08 16:52:48 +05302799#endif
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302800
Manu Gautamf284c052011-09-08 16:52:48 +05302801 return msm_otg_resume(motg);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302802}
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302803#endif
2804
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302805#ifdef CONFIG_PM
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302806static const struct dev_pm_ops msm_otg_dev_pm_ops = {
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302807 SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume)
2808 SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume,
2809 msm_otg_runtime_idle)
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302810};
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302811#endif
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302812
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302813static struct of_device_id msm_otg_dt_match[] = {
2814 { .compatible = "qcom,hsusb-otg",
2815 },
2816 {}
2817};
2818
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302819static struct platform_driver msm_otg_driver = {
2820 .remove = __devexit_p(msm_otg_remove),
2821 .driver = {
2822 .name = DRIVER_NAME,
2823 .owner = THIS_MODULE,
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302824#ifdef CONFIG_PM
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302825 .pm = &msm_otg_dev_pm_ops,
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302826#endif
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302827 .of_match_table = msm_otg_dt_match,
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302828 },
2829};
2830
2831static int __init msm_otg_init(void)
2832{
2833 return platform_driver_probe(&msm_otg_driver, msm_otg_probe);
2834}
2835
2836static void __exit msm_otg_exit(void)
2837{
2838 platform_driver_unregister(&msm_otg_driver);
2839}
2840
2841module_init(msm_otg_init);
2842module_exit(msm_otg_exit);
2843
2844MODULE_LICENSE("GPL v2");
2845MODULE_DESCRIPTION("MSM USB transceiver driver");