blob: 30cbdd8e197bd1250cdbaa28ce6d25e7848340d5 [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 Kondeti283146f2012-01-12 12:51:19 +0530611 bool host_bus_suspend, dcp;
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530612 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 Kondeti283146f2012-01-12 12:51:19 +0530620 dcp = motg->chg_type == USB_DCP_CHARGER;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530621 /*
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530622 * Chipidea 45-nm PHY suspend sequence:
623 *
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530624 * Interrupt Latch Register auto-clear feature is not present
625 * in all PHY versions. Latch register is clear on read type.
626 * Clear latch register to avoid spurious wakeup from
627 * low power mode (LPM).
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530628 *
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530629 * PHY comparators are disabled when PHY enters into low power
630 * mode (LPM). Keep PHY comparators ON in LPM only when we expect
631 * VBUS/Id notifications from USB PHY. Otherwise turn off USB
632 * PHY comparators. This save significant amount of power.
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530633 *
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530634 * PLL is not turned off when PHY enters into low power mode (LPM).
635 * Disable PLL for maximum power savings.
636 */
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530637
638 if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) {
639 ulpi_read(otg, 0x14);
640 if (pdata->otg_control == OTG_PHY_CONTROL)
641 ulpi_write(otg, 0x01, 0x30);
642 ulpi_write(otg, 0x08, 0x09);
643 }
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530644
645 /*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700646 * Turn off the OTG comparators, if depends on PMIC for
647 * VBUS and ID notifications.
648 */
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530649 if ((motg->caps & ALLOW_PHY_COMP_DISABLE) && !host_bus_suspend) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700650 ulpi_write(otg, OTG_COMP_DISABLE,
651 ULPI_SET(ULPI_PWR_CLK_MNG_REG));
652 motg->lpm_flags |= PHY_OTG_COMP_DISABLED;
653 }
654
Rajkumar Raghupathy242565d2011-12-13 12:10:59 +0530655 /* Set the PHCD bit, only if it is not set by the controller.
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530656 * PHY may take some time or even fail to enter into low power
657 * mode (LPM). Hence poll for 500 msec and reset the PHY and link
658 * in failure case.
659 */
Rajkumar Raghupathy242565d2011-12-13 12:10:59 +0530660 portsc = readl_relaxed(USB_PORTSC);
661 if (!(portsc & PORTSC_PHCD)) {
662 writel_relaxed(portsc | PORTSC_PHCD,
663 USB_PORTSC);
664 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
665 if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD)
666 break;
667 udelay(1);
668 cnt++;
669 }
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530670 }
671
672 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) {
673 dev_err(otg->dev, "Unable to suspend PHY\n");
674 msm_otg_reset(otg);
675 enable_irq(motg->irq);
676 return -ETIMEDOUT;
677 }
678
679 /*
680 * PHY has capability to generate interrupt asynchronously in low
681 * power mode (LPM). This interrupt is level triggered. So USB IRQ
682 * line must be disabled till async interrupt enable bit is cleared
683 * in USBCMD register. Assert STP (ULPI interface STOP signal) to
684 * block data communication from PHY.
685 */
Pavankumar Kondeti4960f312011-12-06 15:46:14 +0530686 cmd_val = readl_relaxed(USB_USBCMD);
687 if (host_bus_suspend)
688 cmd_val |= ASYNC_INTR_CTRL | ULPI_STP_CTRL;
689 else
690 cmd_val |= ULPI_STP_CTRL;
691 writel_relaxed(cmd_val, USB_USBCMD);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530692
Pavankumar Kondeti283146f2012-01-12 12:51:19 +0530693 /*
694 * BC1.2 spec mandates PD to enable VDP_SRC when charging from DCP.
695 * PHY retention and collapse can not happen with VDP_SRC enabled.
696 */
697 if (motg->caps & ALLOW_PHY_RETENTION && !host_bus_suspend && !dcp) {
Amit Blay58b31472011-11-18 09:39:39 +0200698 phy_ctrl_val = readl_relaxed(USB_PHY_CTRL);
699 if (motg->pdata->otg_control == OTG_PHY_CONTROL)
700 /* Enable PHY HV interrupts to wake MPM/Link */
701 phy_ctrl_val |=
702 (PHY_IDHV_INTEN | PHY_OTGSESSVLDHV_INTEN);
703
704 writel_relaxed(phy_ctrl_val & ~PHY_RETEN, USB_PHY_CTRL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700705 motg->lpm_flags |= PHY_RETENTIONED;
706 }
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530707
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700708 /* Ensure that above operation is completed before turning off clocks */
709 mb();
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530710 clk_disable(motg->pclk);
Manu Gautam5143b252012-01-05 19:25:23 -0800711 clk_disable(motg->core_clk);
Anji jonnala0f73cac2011-05-04 10:19:46 +0530712
Anji jonnala7da3f262011-12-02 17:22:14 -0800713 /* usb phy no more require TCXO clock, hence vote for TCXO disable */
Stephen Boyd7dd22662012-01-26 16:09:31 -0800714 clk_disable_unprepare(motg->xo_handle);
Anji jonnala7da3f262011-12-02 17:22:14 -0800715
Pavankumar Kondeti283146f2012-01-12 12:51:19 +0530716 if (motg->caps & ALLOW_PHY_POWER_COLLAPSE &&
717 !host_bus_suspend && !dcp) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700718 msm_hsusb_ldo_enable(motg, 0);
719 motg->lpm_flags |= PHY_PWR_COLLAPSED;
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530720 }
721
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530722 if (motg->lpm_flags & PHY_RETENTIONED) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700723 msm_hsusb_config_vddcx(0);
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530724 msm_hsusb_mhl_switch_enable(motg, 0);
725 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700726
727 if (device_may_wakeup(otg->dev)) {
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530728 enable_irq_wake(motg->irq);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700729 if (motg->pdata->pmic_id_irq)
730 enable_irq_wake(motg->pdata->pmic_id_irq);
731 }
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530732 if (bus)
733 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags);
734
735 atomic_set(&motg->in_lpm, 1);
736 enable_irq(motg->irq);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700737 wake_unlock(&motg->wlock);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530738
739 dev_info(otg->dev, "USB in low power mode\n");
740
741 return 0;
742}
743
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530744static int msm_otg_resume(struct msm_otg *motg)
745{
746 struct otg_transceiver *otg = &motg->otg;
747 struct usb_bus *bus = otg->host;
748 int cnt = 0;
749 unsigned temp;
Amit Blay58b31472011-11-18 09:39:39 +0200750 u32 phy_ctrl_val = 0;
Anji jonnala7da3f262011-12-02 17:22:14 -0800751 unsigned ret;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530752
753 if (!atomic_read(&motg->in_lpm))
754 return 0;
755
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700756 wake_lock(&motg->wlock);
Anji jonnala7da3f262011-12-02 17:22:14 -0800757
758 /* Vote for TCXO when waking up the phy */
Stephen Boyd7dd22662012-01-26 16:09:31 -0800759 ret = clk_prepare_enable(motg->xo_handle);
Anji jonnala7da3f262011-12-02 17:22:14 -0800760 if (ret)
761 dev_err(otg->dev, "%s failed to vote for "
762 "TCXO D0 buffer%d\n", __func__, ret);
763
Manu Gautam5143b252012-01-05 19:25:23 -0800764 clk_enable(motg->core_clk);
Amit Blay137575f2011-11-06 15:20:54 +0200765
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530766 clk_enable(motg->pclk);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530767
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700768 if (motg->lpm_flags & PHY_PWR_COLLAPSED) {
769 msm_hsusb_ldo_enable(motg, 1);
770 motg->lpm_flags &= ~PHY_PWR_COLLAPSED;
771 }
772
773 if (motg->lpm_flags & PHY_RETENTIONED) {
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530774 msm_hsusb_mhl_switch_enable(motg, 1);
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530775 msm_hsusb_config_vddcx(1);
Amit Blay58b31472011-11-18 09:39:39 +0200776 phy_ctrl_val = readl_relaxed(USB_PHY_CTRL);
777 phy_ctrl_val |= PHY_RETEN;
778 if (motg->pdata->otg_control == OTG_PHY_CONTROL)
779 /* Disable PHY HV interrupts */
780 phy_ctrl_val &=
781 ~(PHY_IDHV_INTEN | PHY_OTGSESSVLDHV_INTEN);
782 writel_relaxed(phy_ctrl_val, USB_PHY_CTRL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700783 motg->lpm_flags &= ~PHY_RETENTIONED;
Pavankumar Kondeti04aebcb2011-05-04 10:19:49 +0530784 }
785
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530786 temp = readl(USB_USBCMD);
787 temp &= ~ASYNC_INTR_CTRL;
788 temp &= ~ULPI_STP_CTRL;
789 writel(temp, USB_USBCMD);
790
791 /*
792 * PHY comes out of low power mode (LPM) in case of wakeup
793 * from asynchronous interrupt.
794 */
795 if (!(readl(USB_PORTSC) & PORTSC_PHCD))
796 goto skip_phy_resume;
797
798 writel(readl(USB_PORTSC) & ~PORTSC_PHCD, USB_PORTSC);
799 while (cnt < PHY_RESUME_TIMEOUT_USEC) {
800 if (!(readl(USB_PORTSC) & PORTSC_PHCD))
801 break;
802 udelay(1);
803 cnt++;
804 }
805
806 if (cnt >= PHY_RESUME_TIMEOUT_USEC) {
807 /*
808 * This is a fatal error. Reset the link and
809 * PHY. USB state can not be restored. Re-insertion
810 * of USB cable is the only way to get USB working.
811 */
812 dev_err(otg->dev, "Unable to resume USB."
813 "Re-plugin the cable\n");
814 msm_otg_reset(otg);
815 }
816
817skip_phy_resume:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700818 /* Turn on the OTG comparators on resume */
819 if (motg->lpm_flags & PHY_OTG_COMP_DISABLED) {
820 ulpi_write(otg, OTG_COMP_DISABLE,
821 ULPI_CLR(ULPI_PWR_CLK_MNG_REG));
822 motg->lpm_flags &= ~PHY_OTG_COMP_DISABLED;
823 }
824 if (device_may_wakeup(otg->dev)) {
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530825 disable_irq_wake(motg->irq);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700826 if (motg->pdata->pmic_id_irq)
827 disable_irq_wake(motg->pdata->pmic_id_irq);
828 }
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530829 if (bus)
830 set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags);
831
Pavankumar Kondeti2ce2c3a2011-05-02 11:56:33 +0530832 atomic_set(&motg->in_lpm, 0);
833
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530834 if (motg->async_int) {
835 motg->async_int = 0;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530836 enable_irq(motg->irq);
837 }
838
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530839 dev_info(otg->dev, "USB exited from low power mode\n");
840
841 return 0;
842}
Pavankumar Kondeti70187732011-02-15 09:42:34 +0530843#endif
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530844
Chiranjeevi Velempati39f9b952012-01-24 10:46:12 +0530845static int msm_otg_notify_chg_type(struct msm_otg *motg)
846{
847 static int charger_type;
848 /*
849 * TODO
850 * Unify OTG driver charger types and power supply charger types
851 */
852 if (charger_type == motg->chg_type)
853 return 0;
854
855 if (motg->chg_type == USB_SDP_CHARGER)
856 charger_type = POWER_SUPPLY_TYPE_USB;
857 else if (motg->chg_type == USB_CDP_CHARGER)
858 charger_type = POWER_SUPPLY_TYPE_USB_CDP;
859 else if (motg->chg_type == USB_DCP_CHARGER)
860 charger_type = POWER_SUPPLY_TYPE_USB_DCP;
861 else if ((motg->chg_type == USB_ACA_DOCK_CHARGER ||
862 motg->chg_type == USB_ACA_A_CHARGER ||
863 motg->chg_type == USB_ACA_B_CHARGER ||
864 motg->chg_type == USB_ACA_C_CHARGER))
865 charger_type = POWER_SUPPLY_TYPE_USB_ACA;
866 else
867 charger_type = POWER_SUPPLY_TYPE_BATTERY;
868
869 return pm8921_set_usb_power_supply_type(charger_type);
870}
871
Amit Blay0f7edf72012-01-15 10:11:27 +0200872static int msm_otg_notify_power_supply(struct msm_otg *motg, unsigned mA)
873{
874 struct power_supply *psy;
875
876 psy = power_supply_get_by_name("usb");
877 if (!psy)
878 goto psy_not_supported;
879
880 if (motg->cur_power == 0 && mA > 0) {
881 /* Enable charging */
882 if (power_supply_set_online(psy, true))
883 goto psy_not_supported;
884 } else if (motg->cur_power > 0 && mA == 0) {
885 /* Disable charging */
886 if (power_supply_set_online(psy, false))
887 goto psy_not_supported;
888 return 0;
889 }
890 /* Set max current limit */
891 if (power_supply_set_current_limit(psy, 1000*mA))
892 goto psy_not_supported;
893
894 return 0;
895
896psy_not_supported:
897 dev_dbg(motg->otg.dev, "Power Supply doesn't support USB charger\n");
898 return -ENXIO;
899}
900
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530901static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA)
902{
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530903 if ((motg->chg_type == USB_ACA_DOCK_CHARGER ||
904 motg->chg_type == USB_ACA_A_CHARGER ||
905 motg->chg_type == USB_ACA_B_CHARGER ||
906 motg->chg_type == USB_ACA_C_CHARGER) &&
907 mA > IDEV_ACA_CHG_LIMIT)
908 mA = IDEV_ACA_CHG_LIMIT;
909
Chiranjeevi Velempati39f9b952012-01-24 10:46:12 +0530910 if (msm_otg_notify_chg_type(motg))
911 dev_err(motg->otg.dev,
912 "Failed notifying %d charger type to PMIC\n",
913 motg->chg_type);
914
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530915 if (motg->cur_power == mA)
916 return;
917
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530918 dev_info(motg->otg.dev, "Avail curr from USB = %u\n", mA);
Amit Blay0f7edf72012-01-15 10:11:27 +0200919
920 /*
921 * Use Power Supply API if supported, otherwise fallback
922 * to legacy pm8921 API.
923 */
924 if (msm_otg_notify_power_supply(motg, mA))
925 pm8921_charger_vbus_draw(mA);
926
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530927 motg->cur_power = mA;
928}
929
930static int msm_otg_set_power(struct otg_transceiver *otg, unsigned mA)
931{
932 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
933
934 /*
935 * Gadget driver uses set_power method to notify about the
936 * available current based on suspend/configured states.
937 *
938 * IDEV_CHG can be drawn irrespective of suspend/un-configured
939 * states when CDP/ACA is connected.
940 */
941 if (motg->chg_type == USB_SDP_CHARGER)
942 msm_otg_notify_charger(motg, mA);
943
944 return 0;
945}
946
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530947static void msm_otg_start_host(struct otg_transceiver *otg, int on)
948{
949 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
950 struct msm_otg_platform_data *pdata = motg->pdata;
951 struct usb_hcd *hcd;
952
953 if (!otg->host)
954 return;
955
956 hcd = bus_to_hcd(otg->host);
957
958 if (on) {
959 dev_dbg(otg->dev, "host on\n");
960
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530961 /*
962 * Some boards have a switch cotrolled by gpio
963 * to enable/disable internal HUB. Enable internal
964 * HUB before kicking the host.
965 */
966 if (pdata->setup_gpio)
967 pdata->setup_gpio(OTG_STATE_A_HOST);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530968 usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530969 } else {
970 dev_dbg(otg->dev, "host off\n");
971
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530972 usb_remove_hcd(hcd);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530973 /* HCD core reset all bits of PORTSC. select ULPI phy */
974 writel_relaxed(0x80000000, USB_PORTSC);
975
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530976 if (pdata->setup_gpio)
977 pdata->setup_gpio(OTG_STATE_UNDEFINED);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530978 }
979}
980
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700981static int msm_otg_usbdev_notify(struct notifier_block *self,
982 unsigned long action, void *priv)
983{
984 struct msm_otg *motg = container_of(self, struct msm_otg, usbdev_nb);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530985 struct usb_device *udev = priv;
986
987 if (!aca_enabled())
988 goto out;
989
990 if (action == USB_BUS_ADD || action == USB_BUS_REMOVE)
991 goto out;
992
993 if (udev->bus != motg->otg.host)
994 goto out;
995 /*
996 * Interested in devices connected directly to the root hub.
997 * ACA dock can supply IDEV_CHG irrespective devices connected
998 * on the accessory port.
999 */
1000 if (!udev->parent || udev->parent->parent ||
1001 motg->chg_type == USB_ACA_DOCK_CHARGER)
1002 goto out;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001003
1004 switch (action) {
1005 case USB_DEVICE_ADD:
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301006 usb_disable_autosuspend(udev);
1007 /* fall through */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001008 case USB_DEVICE_CONFIG:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001009 if (udev->actconfig)
1010 motg->mA_port = udev->actconfig->desc.bMaxPower * 2;
1011 else
1012 motg->mA_port = IUNIT;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301013 break;
1014 case USB_DEVICE_REMOVE:
1015 motg->mA_port = IUNIT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001016 break;
1017 default:
1018 break;
1019 }
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301020 if (test_bit(ID_A, &motg->inputs))
1021 msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX -
1022 motg->mA_port);
1023out:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001024 return NOTIFY_OK;
1025}
1026
Mayank Ranae3926882011-12-26 09:47:54 +05301027static void msm_hsusb_vbus_power(struct msm_otg *motg, bool on)
1028{
1029 int ret;
1030 static bool vbus_is_on;
1031
1032 if (vbus_is_on == on)
1033 return;
1034
1035 if (motg->pdata->vbus_power) {
Mayank Rana91f597e2012-01-20 10:12:06 +05301036 ret = motg->pdata->vbus_power(on);
1037 if (!ret)
1038 vbus_is_on = on;
Mayank Ranae3926882011-12-26 09:47:54 +05301039 return;
1040 }
1041
1042 if (!vbus_otg) {
1043 pr_err("vbus_otg is NULL.");
1044 return;
1045 }
1046
Abhijeet Dharmapurikarbe054882012-01-03 20:27:07 -08001047 /*
1048 * if entering host mode tell the charger to not draw any current
1049 * from usb - if exiting host mode let the charger draw current
1050 */
1051 pm8921_disable_source_current(on);
Mayank Ranae3926882011-12-26 09:47:54 +05301052 if (on) {
1053 ret = regulator_enable(vbus_otg);
1054 if (ret) {
1055 pr_err("unable to enable vbus_otg\n");
1056 return;
1057 }
1058 vbus_is_on = true;
1059 } else {
1060 ret = regulator_disable(vbus_otg);
1061 if (ret) {
1062 pr_err("unable to disable vbus_otg\n");
1063 return;
1064 }
1065 vbus_is_on = false;
1066 }
1067}
1068
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301069static int msm_otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1070{
1071 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
1072 struct usb_hcd *hcd;
1073
1074 /*
1075 * Fail host registration if this board can support
1076 * only peripheral configuration.
1077 */
1078 if (motg->pdata->mode == USB_PERIPHERAL) {
1079 dev_info(otg->dev, "Host mode is not supported\n");
1080 return -ENODEV;
1081 }
1082
Mayank Ranae3926882011-12-26 09:47:54 +05301083 if (!motg->pdata->vbus_power && host) {
1084 vbus_otg = regulator_get(motg->otg.dev, "vbus_otg");
1085 if (IS_ERR(vbus_otg)) {
1086 pr_err("Unable to get vbus_otg\n");
1087 return -ENODEV;
1088 }
1089 }
1090
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301091 if (!host) {
1092 if (otg->state == OTG_STATE_A_HOST) {
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301093 pm_runtime_get_sync(otg->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001094 usb_unregister_notify(&motg->usbdev_nb);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301095 msm_otg_start_host(otg, 0);
Mayank Ranae3926882011-12-26 09:47:54 +05301096 msm_hsusb_vbus_power(motg, 0);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301097 otg->host = NULL;
1098 otg->state = OTG_STATE_UNDEFINED;
1099 schedule_work(&motg->sm_work);
1100 } else {
1101 otg->host = NULL;
1102 }
1103
Mayank Ranae3926882011-12-26 09:47:54 +05301104 if (vbus_otg)
1105 regulator_put(vbus_otg);
1106
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301107 return 0;
1108 }
1109
1110 hcd = bus_to_hcd(host);
1111 hcd->power_budget = motg->pdata->power_budget;
1112
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001113 motg->usbdev_nb.notifier_call = msm_otg_usbdev_notify;
1114 usb_register_notify(&motg->usbdev_nb);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301115 otg->host = host;
1116 dev_dbg(otg->dev, "host driver registered w/ tranceiver\n");
1117
1118 /*
1119 * Kick the state machine work, if peripheral is not supported
1120 * or peripheral is already registered with us.
1121 */
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301122 if (motg->pdata->mode == USB_HOST || otg->gadget) {
1123 pm_runtime_get_sync(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301124 schedule_work(&motg->sm_work);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301125 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301126
1127 return 0;
1128}
1129
1130static void msm_otg_start_peripheral(struct otg_transceiver *otg, int on)
1131{
Manu Gautamcd82e9d2011-12-20 14:17:28 +05301132 int ret;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301133 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
1134 struct msm_otg_platform_data *pdata = motg->pdata;
1135
1136 if (!otg->gadget)
1137 return;
1138
1139 if (on) {
1140 dev_dbg(otg->dev, "gadget on\n");
1141 /*
1142 * Some boards have a switch cotrolled by gpio
1143 * to enable/disable internal HUB. Disable internal
1144 * HUB before kicking the gadget.
1145 */
1146 if (pdata->setup_gpio)
1147 pdata->setup_gpio(OTG_STATE_B_PERIPHERAL);
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05301148 /*
1149 * vote for minimum dma_latency to prevent idle
1150 * power collapse(pc) while running in peripheral mode.
1151 */
1152 otg_pm_qos_update_latency(motg, 1);
Manu Gautamcd82e9d2011-12-20 14:17:28 +05301153 /* Configure BUS performance parameters for MAX bandwidth */
1154 if (motg->bus_perf_client) {
1155 ret = msm_bus_scale_client_update_request(
1156 motg->bus_perf_client, 1);
1157 if (ret)
1158 dev_err(motg->otg.dev, "%s: Failed to vote for "
1159 "bus bandwidth %d\n", __func__, ret);
1160 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301161 usb_gadget_vbus_connect(otg->gadget);
1162 } else {
1163 dev_dbg(otg->dev, "gadget off\n");
1164 usb_gadget_vbus_disconnect(otg->gadget);
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05301165 otg_pm_qos_update_latency(motg, 0);
Manu Gautamcd82e9d2011-12-20 14:17:28 +05301166 /* Configure BUS performance parameters to default */
1167 if (motg->bus_perf_client) {
1168 ret = msm_bus_scale_client_update_request(
1169 motg->bus_perf_client, 0);
1170 if (ret)
1171 dev_err(motg->otg.dev, "%s: Failed to devote "
1172 "for bus bw %d\n", __func__, ret);
1173 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301174 if (pdata->setup_gpio)
1175 pdata->setup_gpio(OTG_STATE_UNDEFINED);
1176 }
1177
1178}
1179
1180static int msm_otg_set_peripheral(struct otg_transceiver *otg,
1181 struct usb_gadget *gadget)
1182{
1183 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
1184
1185 /*
1186 * Fail peripheral registration if this board can support
1187 * only host configuration.
1188 */
1189 if (motg->pdata->mode == USB_HOST) {
1190 dev_info(otg->dev, "Peripheral mode is not supported\n");
1191 return -ENODEV;
1192 }
1193
1194 if (!gadget) {
1195 if (otg->state == OTG_STATE_B_PERIPHERAL) {
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301196 pm_runtime_get_sync(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301197 msm_otg_start_peripheral(otg, 0);
1198 otg->gadget = NULL;
1199 otg->state = OTG_STATE_UNDEFINED;
1200 schedule_work(&motg->sm_work);
1201 } else {
1202 otg->gadget = NULL;
1203 }
1204
1205 return 0;
1206 }
1207 otg->gadget = gadget;
1208 dev_dbg(otg->dev, "peripheral driver registered w/ tranceiver\n");
1209
1210 /*
1211 * Kick the state machine work, if host is not supported
1212 * or host is already registered with us.
1213 */
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301214 if (motg->pdata->mode == USB_PERIPHERAL || otg->host) {
1215 pm_runtime_get_sync(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301216 schedule_work(&motg->sm_work);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301217 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301218
1219 return 0;
1220}
1221
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001222static bool msm_chg_aca_detect(struct msm_otg *motg)
1223{
1224 struct otg_transceiver *otg = &motg->otg;
1225 u32 int_sts;
1226 bool ret = false;
1227
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301228 if (!aca_enabled())
1229 goto out;
1230
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001231 if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY)
1232 goto out;
1233
1234 int_sts = ulpi_read(otg, 0x87);
1235 switch (int_sts & 0x1C) {
1236 case 0x08:
1237 if (!test_and_set_bit(ID_A, &motg->inputs)) {
1238 dev_dbg(otg->dev, "ID_A\n");
1239 motg->chg_type = USB_ACA_A_CHARGER;
1240 motg->chg_state = USB_CHG_STATE_DETECTED;
1241 clear_bit(ID_B, &motg->inputs);
1242 clear_bit(ID_C, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301243 set_bit(ID, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001244 ret = true;
1245 }
1246 break;
1247 case 0x0C:
1248 if (!test_and_set_bit(ID_B, &motg->inputs)) {
1249 dev_dbg(otg->dev, "ID_B\n");
1250 motg->chg_type = USB_ACA_B_CHARGER;
1251 motg->chg_state = USB_CHG_STATE_DETECTED;
1252 clear_bit(ID_A, &motg->inputs);
1253 clear_bit(ID_C, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301254 set_bit(ID, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001255 ret = true;
1256 }
1257 break;
1258 case 0x10:
1259 if (!test_and_set_bit(ID_C, &motg->inputs)) {
1260 dev_dbg(otg->dev, "ID_C\n");
1261 motg->chg_type = USB_ACA_C_CHARGER;
1262 motg->chg_state = USB_CHG_STATE_DETECTED;
1263 clear_bit(ID_A, &motg->inputs);
1264 clear_bit(ID_B, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301265 set_bit(ID, &motg->inputs);
1266 ret = true;
1267 }
1268 break;
1269 case 0x04:
1270 if (test_and_clear_bit(ID, &motg->inputs)) {
1271 dev_dbg(otg->dev, "ID_GND\n");
1272 motg->chg_type = USB_INVALID_CHARGER;
1273 motg->chg_state = USB_CHG_STATE_UNDEFINED;
1274 clear_bit(ID_A, &motg->inputs);
1275 clear_bit(ID_B, &motg->inputs);
1276 clear_bit(ID_C, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001277 ret = true;
1278 }
1279 break;
1280 default:
1281 ret = test_and_clear_bit(ID_A, &motg->inputs) |
1282 test_and_clear_bit(ID_B, &motg->inputs) |
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301283 test_and_clear_bit(ID_C, &motg->inputs) |
1284 !test_and_set_bit(ID, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001285 if (ret) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301286 dev_dbg(otg->dev, "ID A/B/C/GND is no more\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001287 motg->chg_type = USB_INVALID_CHARGER;
1288 motg->chg_state = USB_CHG_STATE_UNDEFINED;
1289 }
1290 }
1291out:
1292 return ret;
1293}
1294
1295static void msm_chg_enable_aca_det(struct msm_otg *motg)
1296{
1297 struct otg_transceiver *otg = &motg->otg;
1298
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301299 if (!aca_enabled())
1300 return;
1301
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001302 switch (motg->pdata->phy_type) {
1303 case SNPS_28NM_INTEGRATED_PHY:
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301304 /* Disable ID_GND in link and PHY */
1305 writel_relaxed(readl_relaxed(USB_OTGSC) & ~(OTGSC_IDPU |
1306 OTGSC_IDIE), USB_OTGSC);
1307 ulpi_write(otg, 0x01, 0x0C);
1308 ulpi_write(otg, 0x10, 0x0F);
1309 ulpi_write(otg, 0x10, 0x12);
1310 /* Enable ACA ID detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001311 ulpi_write(otg, 0x20, 0x85);
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301312 aca_id_turned_on = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001313 break;
1314 default:
1315 break;
1316 }
1317}
1318
1319static void msm_chg_enable_aca_intr(struct msm_otg *motg)
1320{
1321 struct otg_transceiver *otg = &motg->otg;
1322
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301323 if (!aca_enabled())
1324 return;
1325
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001326 switch (motg->pdata->phy_type) {
1327 case SNPS_28NM_INTEGRATED_PHY:
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301328 /* Enable ACA Detection interrupt (on any RID change) */
1329 ulpi_write(otg, 0x01, 0x94);
1330 break;
1331 default:
1332 break;
1333 }
1334}
1335
1336static void msm_chg_disable_aca_intr(struct msm_otg *motg)
1337{
1338 struct otg_transceiver *otg = &motg->otg;
1339
1340 if (!aca_enabled())
1341 return;
1342
1343 switch (motg->pdata->phy_type) {
1344 case SNPS_28NM_INTEGRATED_PHY:
1345 ulpi_write(otg, 0x01, 0x95);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001346 break;
1347 default:
1348 break;
1349 }
1350}
1351
1352static bool msm_chg_check_aca_intr(struct msm_otg *motg)
1353{
1354 struct otg_transceiver *otg = &motg->otg;
1355 bool ret = false;
1356
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301357 if (!aca_enabled())
1358 return ret;
1359
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001360 switch (motg->pdata->phy_type) {
1361 case SNPS_28NM_INTEGRATED_PHY:
1362 if (ulpi_read(otg, 0x91) & 1) {
1363 dev_dbg(otg->dev, "RID change\n");
1364 ulpi_write(otg, 0x01, 0x92);
1365 ret = msm_chg_aca_detect(motg);
1366 }
1367 default:
1368 break;
1369 }
1370 return ret;
1371}
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301372
1373static void msm_otg_id_timer_func(unsigned long data)
1374{
1375 struct msm_otg *motg = (struct msm_otg *) data;
1376
1377 if (!aca_enabled())
1378 return;
1379
1380 if (atomic_read(&motg->in_lpm)) {
1381 dev_dbg(motg->otg.dev, "timer: in lpm\n");
1382 return;
1383 }
1384
1385 if (msm_chg_check_aca_intr(motg)) {
1386 dev_dbg(motg->otg.dev, "timer: aca work\n");
1387 schedule_work(&motg->sm_work);
1388 }
1389
1390 if (!test_bit(ID, &motg->inputs) || test_bit(ID_A, &motg->inputs))
1391 mod_timer(&motg->id_timer, ID_TIMER_FREQ);
1392}
1393
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301394static bool msm_chg_check_secondary_det(struct msm_otg *motg)
1395{
1396 struct otg_transceiver *otg = &motg->otg;
1397 u32 chg_det;
1398 bool ret = false;
1399
1400 switch (motg->pdata->phy_type) {
1401 case CI_45NM_INTEGRATED_PHY:
1402 chg_det = ulpi_read(otg, 0x34);
1403 ret = chg_det & (1 << 4);
1404 break;
1405 case SNPS_28NM_INTEGRATED_PHY:
1406 chg_det = ulpi_read(otg, 0x87);
1407 ret = chg_det & 1;
1408 break;
1409 default:
1410 break;
1411 }
1412 return ret;
1413}
1414
1415static void msm_chg_enable_secondary_det(struct msm_otg *motg)
1416{
1417 struct otg_transceiver *otg = &motg->otg;
1418 u32 chg_det;
1419
1420 switch (motg->pdata->phy_type) {
1421 case CI_45NM_INTEGRATED_PHY:
1422 chg_det = ulpi_read(otg, 0x34);
1423 /* Turn off charger block */
1424 chg_det |= ~(1 << 1);
1425 ulpi_write(otg, chg_det, 0x34);
1426 udelay(20);
1427 /* control chg block via ULPI */
1428 chg_det &= ~(1 << 3);
1429 ulpi_write(otg, chg_det, 0x34);
1430 /* put it in host mode for enabling D- source */
1431 chg_det &= ~(1 << 2);
1432 ulpi_write(otg, chg_det, 0x34);
1433 /* Turn on chg detect block */
1434 chg_det &= ~(1 << 1);
1435 ulpi_write(otg, chg_det, 0x34);
1436 udelay(20);
1437 /* enable chg detection */
1438 chg_det &= ~(1 << 0);
1439 ulpi_write(otg, chg_det, 0x34);
1440 break;
1441 case SNPS_28NM_INTEGRATED_PHY:
Pavankumar Kondeti283146f2012-01-12 12:51:19 +05301442 /* Turn off VDP_SRC */
1443 ulpi_write(otg, 0x3, 0x86);
1444 msleep(20);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301445 /*
1446 * Configure DM as current source, DP as current sink
1447 * and enable battery charging comparators.
1448 */
1449 ulpi_write(otg, 0x8, 0x85);
1450 ulpi_write(otg, 0x2, 0x85);
1451 ulpi_write(otg, 0x1, 0x85);
1452 break;
1453 default:
1454 break;
1455 }
1456}
1457
1458static bool msm_chg_check_primary_det(struct msm_otg *motg)
1459{
1460 struct otg_transceiver *otg = &motg->otg;
1461 u32 chg_det;
1462 bool ret = false;
1463
1464 switch (motg->pdata->phy_type) {
1465 case CI_45NM_INTEGRATED_PHY:
1466 chg_det = ulpi_read(otg, 0x34);
1467 ret = chg_det & (1 << 4);
1468 break;
1469 case SNPS_28NM_INTEGRATED_PHY:
1470 chg_det = ulpi_read(otg, 0x87);
1471 ret = chg_det & 1;
1472 break;
1473 default:
1474 break;
1475 }
1476 return ret;
1477}
1478
1479static void msm_chg_enable_primary_det(struct msm_otg *motg)
1480{
1481 struct otg_transceiver *otg = &motg->otg;
1482 u32 chg_det;
1483
1484 switch (motg->pdata->phy_type) {
1485 case CI_45NM_INTEGRATED_PHY:
1486 chg_det = ulpi_read(otg, 0x34);
1487 /* enable chg detection */
1488 chg_det &= ~(1 << 0);
1489 ulpi_write(otg, chg_det, 0x34);
1490 break;
1491 case SNPS_28NM_INTEGRATED_PHY:
1492 /*
1493 * Configure DP as current source, DM as current sink
1494 * and enable battery charging comparators.
1495 */
1496 ulpi_write(otg, 0x2, 0x85);
1497 ulpi_write(otg, 0x1, 0x85);
1498 break;
1499 default:
1500 break;
1501 }
1502}
1503
1504static bool msm_chg_check_dcd(struct msm_otg *motg)
1505{
1506 struct otg_transceiver *otg = &motg->otg;
1507 u32 line_state;
1508 bool ret = false;
1509
1510 switch (motg->pdata->phy_type) {
1511 case CI_45NM_INTEGRATED_PHY:
1512 line_state = ulpi_read(otg, 0x15);
1513 ret = !(line_state & 1);
1514 break;
1515 case SNPS_28NM_INTEGRATED_PHY:
1516 line_state = ulpi_read(otg, 0x87);
1517 ret = line_state & 2;
1518 break;
1519 default:
1520 break;
1521 }
1522 return ret;
1523}
1524
1525static void msm_chg_disable_dcd(struct msm_otg *motg)
1526{
1527 struct otg_transceiver *otg = &motg->otg;
1528 u32 chg_det;
1529
1530 switch (motg->pdata->phy_type) {
1531 case CI_45NM_INTEGRATED_PHY:
1532 chg_det = ulpi_read(otg, 0x34);
1533 chg_det &= ~(1 << 5);
1534 ulpi_write(otg, chg_det, 0x34);
1535 break;
1536 case SNPS_28NM_INTEGRATED_PHY:
1537 ulpi_write(otg, 0x10, 0x86);
1538 break;
1539 default:
1540 break;
1541 }
1542}
1543
1544static void msm_chg_enable_dcd(struct msm_otg *motg)
1545{
1546 struct otg_transceiver *otg = &motg->otg;
1547 u32 chg_det;
1548
1549 switch (motg->pdata->phy_type) {
1550 case CI_45NM_INTEGRATED_PHY:
1551 chg_det = ulpi_read(otg, 0x34);
1552 /* Turn on D+ current source */
1553 chg_det |= (1 << 5);
1554 ulpi_write(otg, chg_det, 0x34);
1555 break;
1556 case SNPS_28NM_INTEGRATED_PHY:
1557 /* Data contact detection enable */
1558 ulpi_write(otg, 0x10, 0x85);
1559 break;
1560 default:
1561 break;
1562 }
1563}
1564
1565static void msm_chg_block_on(struct msm_otg *motg)
1566{
1567 struct otg_transceiver *otg = &motg->otg;
1568 u32 func_ctrl, chg_det;
1569
1570 /* put the controller in non-driving mode */
1571 func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL);
1572 func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
1573 func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
1574 ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL);
1575
1576 switch (motg->pdata->phy_type) {
1577 case CI_45NM_INTEGRATED_PHY:
1578 chg_det = ulpi_read(otg, 0x34);
1579 /* control chg block via ULPI */
1580 chg_det &= ~(1 << 3);
1581 ulpi_write(otg, chg_det, 0x34);
1582 /* Turn on chg detect block */
1583 chg_det &= ~(1 << 1);
1584 ulpi_write(otg, chg_det, 0x34);
1585 udelay(20);
1586 break;
1587 case SNPS_28NM_INTEGRATED_PHY:
1588 /* Clear charger detecting control bits */
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301589 ulpi_write(otg, 0x1F, 0x86);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301590 /* Clear alt interrupt latch and enable bits */
1591 ulpi_write(otg, 0x1F, 0x92);
1592 ulpi_write(otg, 0x1F, 0x95);
1593 udelay(100);
1594 break;
1595 default:
1596 break;
1597 }
1598}
1599
1600static void msm_chg_block_off(struct msm_otg *motg)
1601{
1602 struct otg_transceiver *otg = &motg->otg;
1603 u32 func_ctrl, chg_det;
1604
1605 switch (motg->pdata->phy_type) {
1606 case CI_45NM_INTEGRATED_PHY:
1607 chg_det = ulpi_read(otg, 0x34);
1608 /* Turn off charger block */
1609 chg_det |= ~(1 << 1);
1610 ulpi_write(otg, chg_det, 0x34);
1611 break;
1612 case SNPS_28NM_INTEGRATED_PHY:
1613 /* Clear charger detecting control bits */
1614 ulpi_write(otg, 0x3F, 0x86);
1615 /* Clear alt interrupt latch and enable bits */
1616 ulpi_write(otg, 0x1F, 0x92);
1617 ulpi_write(otg, 0x1F, 0x95);
1618 break;
1619 default:
1620 break;
1621 }
1622
1623 /* put the controller in normal mode */
1624 func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL);
1625 func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
1626 func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL;
1627 ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL);
1628}
1629
Anji jonnalad270e2d2011-08-09 11:28:32 +05301630static const char *chg_to_string(enum usb_chg_type chg_type)
1631{
1632 switch (chg_type) {
1633 case USB_SDP_CHARGER: return "USB_SDP_CHARGER";
1634 case USB_DCP_CHARGER: return "USB_DCP_CHARGER";
1635 case USB_CDP_CHARGER: return "USB_CDP_CHARGER";
1636 case USB_ACA_A_CHARGER: return "USB_ACA_A_CHARGER";
1637 case USB_ACA_B_CHARGER: return "USB_ACA_B_CHARGER";
1638 case USB_ACA_C_CHARGER: return "USB_ACA_C_CHARGER";
1639 case USB_ACA_DOCK_CHARGER: return "USB_ACA_DOCK_CHARGER";
1640 default: return "INVALID_CHARGER";
1641 }
1642}
1643
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301644#define MSM_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */
1645#define MSM_CHG_DCD_MAX_RETRIES 6 /* Tdcd_tmout = 6 * 100 msec */
Pavankumar Kondeti283146f2012-01-12 12:51:19 +05301646#define MSM_CHG_PRIMARY_DET_TIME (50 * HZ/1000) /* TVDPSRC_ON */
1647#define MSM_CHG_SECONDARY_DET_TIME (50 * HZ/1000) /* TVDMSRC_ON */
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301648static void msm_chg_detect_work(struct work_struct *w)
1649{
1650 struct msm_otg *motg = container_of(w, struct msm_otg, chg_work.work);
1651 struct otg_transceiver *otg = &motg->otg;
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +05301652 bool is_dcd = false, tmout, vout, is_aca;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301653 unsigned long delay;
1654
1655 dev_dbg(otg->dev, "chg detection work\n");
1656 switch (motg->chg_state) {
1657 case USB_CHG_STATE_UNDEFINED:
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301658 msm_chg_block_on(motg);
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +05301659 if (motg->pdata->enable_dcd)
1660 msm_chg_enable_dcd(motg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001661 msm_chg_enable_aca_det(motg);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301662 motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD;
1663 motg->dcd_retries = 0;
1664 delay = MSM_CHG_DCD_POLL_TIME;
1665 break;
1666 case USB_CHG_STATE_WAIT_FOR_DCD:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001667 is_aca = msm_chg_aca_detect(motg);
1668 if (is_aca) {
1669 /*
1670 * ID_A can be ACA dock too. continue
1671 * primary detection after DCD.
1672 */
1673 if (test_bit(ID_A, &motg->inputs)) {
1674 motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD;
1675 } else {
1676 delay = 0;
1677 break;
1678 }
1679 }
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +05301680 if (motg->pdata->enable_dcd)
1681 is_dcd = msm_chg_check_dcd(motg);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301682 tmout = ++motg->dcd_retries == MSM_CHG_DCD_MAX_RETRIES;
1683 if (is_dcd || tmout) {
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +05301684 if (motg->pdata->enable_dcd)
1685 msm_chg_disable_dcd(motg);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301686 msm_chg_enable_primary_det(motg);
1687 delay = MSM_CHG_PRIMARY_DET_TIME;
1688 motg->chg_state = USB_CHG_STATE_DCD_DONE;
1689 } else {
1690 delay = MSM_CHG_DCD_POLL_TIME;
1691 }
1692 break;
1693 case USB_CHG_STATE_DCD_DONE:
1694 vout = msm_chg_check_primary_det(motg);
1695 if (vout) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301696 if (test_bit(ID_A, &motg->inputs)) {
1697 motg->chg_type = USB_ACA_DOCK_CHARGER;
1698 motg->chg_state = USB_CHG_STATE_DETECTED;
1699 delay = 0;
1700 break;
1701 }
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301702 msm_chg_enable_secondary_det(motg);
1703 delay = MSM_CHG_SECONDARY_DET_TIME;
1704 motg->chg_state = USB_CHG_STATE_PRIMARY_DONE;
1705 } else {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301706 if (test_bit(ID_A, &motg->inputs)) {
1707 motg->chg_type = USB_ACA_A_CHARGER;
1708 motg->chg_state = USB_CHG_STATE_DETECTED;
1709 delay = 0;
1710 break;
1711 }
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301712 motg->chg_type = USB_SDP_CHARGER;
1713 motg->chg_state = USB_CHG_STATE_DETECTED;
1714 delay = 0;
1715 }
1716 break;
1717 case USB_CHG_STATE_PRIMARY_DONE:
1718 vout = msm_chg_check_secondary_det(motg);
1719 if (vout)
1720 motg->chg_type = USB_DCP_CHARGER;
1721 else
1722 motg->chg_type = USB_CDP_CHARGER;
1723 motg->chg_state = USB_CHG_STATE_SECONDARY_DONE;
1724 /* fall through */
1725 case USB_CHG_STATE_SECONDARY_DONE:
1726 motg->chg_state = USB_CHG_STATE_DETECTED;
1727 case USB_CHG_STATE_DETECTED:
1728 msm_chg_block_off(motg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001729 msm_chg_enable_aca_det(motg);
1730 msm_chg_enable_aca_intr(motg);
Anji jonnalad270e2d2011-08-09 11:28:32 +05301731 dev_dbg(otg->dev, "chg_type = %s\n",
1732 chg_to_string(motg->chg_type));
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301733 schedule_work(&motg->sm_work);
1734 return;
1735 default:
1736 return;
1737 }
1738
1739 schedule_delayed_work(&motg->chg_work, delay);
1740}
1741
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301742/*
1743 * We support OTG, Peripheral only and Host only configurations. In case
1744 * of OTG, mode switch (host-->peripheral/peripheral-->host) can happen
1745 * via Id pin status or user request (debugfs). Id/BSV interrupts are not
1746 * enabled when switch is controlled by user and default mode is supplied
1747 * by board file, which can be changed by userspace later.
1748 */
1749static void msm_otg_init_sm(struct msm_otg *motg)
1750{
1751 struct msm_otg_platform_data *pdata = motg->pdata;
1752 u32 otgsc = readl(USB_OTGSC);
1753
1754 switch (pdata->mode) {
1755 case USB_OTG:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001756 if (pdata->otg_control == OTG_USER_CONTROL) {
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301757 if (pdata->default_mode == USB_HOST) {
1758 clear_bit(ID, &motg->inputs);
1759 } else if (pdata->default_mode == USB_PERIPHERAL) {
1760 set_bit(ID, &motg->inputs);
1761 set_bit(B_SESS_VLD, &motg->inputs);
1762 } else {
1763 set_bit(ID, &motg->inputs);
1764 clear_bit(B_SESS_VLD, &motg->inputs);
1765 }
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301766 } else if (pdata->otg_control == OTG_PHY_CONTROL) {
1767 if (otgsc & OTGSC_ID)
1768 set_bit(ID, &motg->inputs);
1769 else
1770 clear_bit(ID, &motg->inputs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001771 if (otgsc & OTGSC_BSV)
1772 set_bit(B_SESS_VLD, &motg->inputs);
1773 else
1774 clear_bit(B_SESS_VLD, &motg->inputs);
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301775 } else if (pdata->otg_control == OTG_PMIC_CONTROL) {
Pavankumar Kondeti0d81f312012-01-13 11:34:10 +05301776 if (pdata->pmic_id_irq) {
1777 if (irq_read_line(pdata->pmic_id_irq))
1778 set_bit(ID, &motg->inputs);
1779 else
1780 clear_bit(ID, &motg->inputs);
1781 }
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301782 /*
1783 * VBUS initial state is reported after PMIC
1784 * driver initialization. Wait for it.
1785 */
1786 wait_for_completion(&pmic_vbus_init);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301787 }
1788 break;
1789 case USB_HOST:
1790 clear_bit(ID, &motg->inputs);
1791 break;
1792 case USB_PERIPHERAL:
1793 set_bit(ID, &motg->inputs);
Pavankumar Kondeti0d81f312012-01-13 11:34:10 +05301794 if (pdata->otg_control == OTG_PHY_CONTROL) {
1795 if (otgsc & OTGSC_BSV)
1796 set_bit(B_SESS_VLD, &motg->inputs);
1797 else
1798 clear_bit(B_SESS_VLD, &motg->inputs);
1799 } else if (pdata->otg_control == OTG_PMIC_CONTROL) {
1800 /*
1801 * VBUS initial state is reported after PMIC
1802 * driver initialization. Wait for it.
1803 */
1804 wait_for_completion(&pmic_vbus_init);
1805 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301806 break;
1807 default:
1808 break;
1809 }
1810}
1811
1812static void msm_otg_sm_work(struct work_struct *w)
1813{
1814 struct msm_otg *motg = container_of(w, struct msm_otg, sm_work);
1815 struct otg_transceiver *otg = &motg->otg;
1816
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05301817 pm_runtime_resume(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301818 switch (otg->state) {
1819 case OTG_STATE_UNDEFINED:
1820 dev_dbg(otg->dev, "OTG_STATE_UNDEFINED state\n");
1821 msm_otg_reset(otg);
1822 msm_otg_init_sm(motg);
1823 otg->state = OTG_STATE_B_IDLE;
Pavankumar Kondeti8a379b42011-12-12 13:07:23 +05301824 if (!test_bit(B_SESS_VLD, &motg->inputs) &&
1825 test_bit(ID, &motg->inputs)) {
1826 pm_runtime_put_noidle(otg->dev);
1827 pm_runtime_suspend(otg->dev);
1828 break;
1829 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301830 /* FALL THROUGH */
1831 case OTG_STATE_B_IDLE:
1832 dev_dbg(otg->dev, "OTG_STATE_B_IDLE state\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001833 if ((!test_bit(ID, &motg->inputs) ||
1834 test_bit(ID_A, &motg->inputs)) && otg->host) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001835 if (motg->chg_type == USB_ACA_DOCK_CHARGER)
1836 msm_otg_notify_charger(motg,
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301837 IDEV_ACA_CHG_MAX);
1838 else if (test_bit(ID_A, &motg->inputs))
1839 msm_otg_notify_charger(motg,
1840 IDEV_ACA_CHG_MAX - IUNIT);
Mayank Ranae3926882011-12-26 09:47:54 +05301841 else
1842 msm_hsusb_vbus_power(motg, 1);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301843 msm_otg_start_host(otg, 1);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301844 /*
1845 * Link can not generate PHY_ALT interrupt
1846 * in host mode when no device is attached
1847 * to the port. It is also observed PHY_ALT
1848 * interrupt missing upon Micro-A cable disconnect.
1849 * Hence disable PHY_ALT interrupt and perform
1850 * polling to detect RID change.
1851 */
1852 msm_chg_enable_aca_det(motg);
1853 msm_chg_disable_aca_intr(motg);
1854 mod_timer(&motg->id_timer, ID_TIMER_FREQ);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301855 otg->state = OTG_STATE_A_HOST;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301856 } else if (test_bit(B_SESS_VLD, &motg->inputs)) {
1857 switch (motg->chg_state) {
1858 case USB_CHG_STATE_UNDEFINED:
1859 msm_chg_detect_work(&motg->chg_work.work);
1860 break;
1861 case USB_CHG_STATE_DETECTED:
1862 switch (motg->chg_type) {
1863 case USB_DCP_CHARGER:
Pavankumar Kondeti283146f2012-01-12 12:51:19 +05301864 /* Enable VDP_SRC */
1865 ulpi_write(otg, 0x2, 0x85);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301866 msm_otg_notify_charger(motg,
1867 IDEV_CHG_MAX);
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05301868 pm_runtime_put_noidle(otg->dev);
1869 pm_runtime_suspend(otg->dev);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301870 break;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301871 case USB_ACA_B_CHARGER:
1872 msm_otg_notify_charger(motg,
1873 IDEV_ACA_CHG_MAX);
1874 /*
1875 * (ID_B --> ID_C) PHY_ALT interrupt can
1876 * not be detected in LPM.
1877 */
1878 break;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301879 case USB_CDP_CHARGER:
1880 msm_otg_notify_charger(motg,
1881 IDEV_CHG_MAX);
1882 msm_otg_start_peripheral(otg, 1);
1883 otg->state = OTG_STATE_B_PERIPHERAL;
1884 break;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301885 case USB_ACA_C_CHARGER:
1886 msm_otg_notify_charger(motg,
1887 IDEV_ACA_CHG_MAX);
1888 msm_otg_start_peripheral(otg, 1);
1889 otg->state = OTG_STATE_B_PERIPHERAL;
1890 break;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301891 case USB_SDP_CHARGER:
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301892 msm_otg_start_peripheral(otg, 1);
1893 otg->state = OTG_STATE_B_PERIPHERAL;
1894 break;
1895 default:
1896 break;
1897 }
1898 break;
1899 default:
1900 break;
1901 }
1902 } else {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301903 cancel_delayed_work_sync(&motg->chg_work);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05301904 msm_otg_notify_charger(motg, 0);
1905 motg->chg_state = USB_CHG_STATE_UNDEFINED;
1906 motg->chg_type = USB_INVALID_CHARGER;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301907 msm_otg_reset(otg);
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05301908 pm_runtime_put_noidle(otg->dev);
1909 pm_runtime_suspend(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301910 }
1911 break;
1912 case OTG_STATE_B_PERIPHERAL:
1913 dev_dbg(otg->dev, "OTG_STATE_B_PERIPHERAL state\n");
1914 if (!test_bit(B_SESS_VLD, &motg->inputs) ||
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001915 !test_bit(ID, &motg->inputs) ||
1916 !test_bit(ID_C, &motg->inputs)) {
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301917 msm_otg_start_peripheral(otg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001918 otg->state = OTG_STATE_B_IDLE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001919 schedule_work(w);
1920 } else if (test_bit(ID_C, &motg->inputs)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301921 msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001922 }
1923 break;
1924 case OTG_STATE_A_HOST:
1925 dev_dbg(otg->dev, "OTG_STATE_A_HOST state\n");
1926 if (test_bit(ID, &motg->inputs) &&
1927 !test_bit(ID_A, &motg->inputs)) {
1928 msm_otg_start_host(otg, 0);
Mayank Ranae3926882011-12-26 09:47:54 +05301929 msm_hsusb_vbus_power(motg, 0);
1930 msleep(100); /* TA_WAIT_VFALL */
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301931 /*
1932 * Exit point of host mode.
1933 *
1934 * 1. Micro-A cable disconnect: Just schedule
1935 * the work. PHY is reset in B_IDLE and LPM
1936 * is allowed.
1937 * 2. ID_GND --> ID_B: No need to reset the PHY.
1938 * HCD core clears all PORTSC bits and initializes
1939 * the controller to host mode in remove_hcd.
1940 * Restore PORTSC transceiver select bits (ULPI)
1941 * and reset the controller to change MODE bits.
1942 * PHY_ALT interrupt can not occur in host mode.
1943 */
1944 del_timer_sync(&motg->id_timer);
1945 if (motg->chg_state != USB_CHG_STATE_UNDEFINED) {
1946 msm_otg_link_reset(motg);
1947 msm_chg_enable_aca_intr(motg);
1948 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301949 otg->state = OTG_STATE_B_IDLE;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301950 schedule_work(w);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001951 } else if (test_bit(ID_A, &motg->inputs)) {
Mayank Ranae3926882011-12-26 09:47:54 +05301952 msm_hsusb_vbus_power(motg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001953 msm_otg_notify_charger(motg,
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301954 IDEV_ACA_CHG_MAX - motg->mA_port);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001955 } else if (!test_bit(ID, &motg->inputs)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001956 msm_otg_notify_charger(motg, 0);
Mayank Ranae3926882011-12-26 09:47:54 +05301957 msm_hsusb_vbus_power(motg, 1);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301958 }
1959 break;
1960 default:
1961 break;
1962 }
1963}
1964
1965static irqreturn_t msm_otg_irq(int irq, void *data)
1966{
1967 struct msm_otg *motg = data;
1968 struct otg_transceiver *otg = &motg->otg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001969 u32 otgsc = 0, usbsts;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301970
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301971 if (atomic_read(&motg->in_lpm)) {
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05301972 pr_debug("OTG IRQ: in LPM\n");
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301973 disable_irq_nosync(irq);
1974 motg->async_int = 1;
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05301975 pm_request_resume(otg->dev);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05301976 return IRQ_HANDLED;
1977 }
1978
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001979 usbsts = readl(USB_USBSTS);
1980 if ((usbsts & PHY_ALT_INT)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301981 dev_dbg(otg->dev, "PHY_ALT interrupt\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001982 writel(PHY_ALT_INT, USB_USBSTS);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301983 if (msm_chg_check_aca_intr(motg)) {
1984 dev_dbg(otg->dev, "ACA work from IRQ\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001985 schedule_work(&motg->sm_work);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301986 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001987 return IRQ_HANDLED;
1988 }
1989
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301990 otgsc = readl(USB_OTGSC);
1991 if (!(otgsc & (OTGSC_IDIS | OTGSC_BSVIS)))
1992 return IRQ_NONE;
1993
1994 if ((otgsc & OTGSC_IDIS) && (otgsc & OTGSC_IDIE)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301995 if (otgsc & OTGSC_ID) {
1996 dev_dbg(otg->dev, "ID set\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301997 set_bit(ID, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05301998 } else {
1999 dev_dbg(otg->dev, "ID clear\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302000 clear_bit(ID, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302001 msm_chg_enable_aca_det(motg);
2002 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002003 schedule_work(&motg->sm_work);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302004 } else if ((otgsc & OTGSC_BSVIS) && (otgsc & OTGSC_BSVIE)) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302005 if (otgsc & OTGSC_BSV) {
2006 dev_dbg(otg->dev, "BSV set\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302007 set_bit(B_SESS_VLD, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302008 } else {
2009 dev_dbg(otg->dev, "BSV clear\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302010 clear_bit(B_SESS_VLD, &motg->inputs);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302011 msm_chg_check_aca_intr(motg);
2012 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002013 schedule_work(&motg->sm_work);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302014 }
2015
2016 writel(otgsc, USB_OTGSC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002017 return IRQ_HANDLED;
2018}
2019
2020static void msm_otg_set_vbus_state(int online)
2021{
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05302022 static bool init;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002023 struct msm_otg *motg = the_msm_otg;
2024
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05302025 if (online) {
2026 pr_debug("PMIC: BSV set\n");
2027 set_bit(B_SESS_VLD, &motg->inputs);
2028 } else {
2029 pr_debug("PMIC: BSV clear\n");
2030 clear_bit(B_SESS_VLD, &motg->inputs);
2031 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002032
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05302033 if (!init) {
2034 init = true;
2035 complete(&pmic_vbus_init);
2036 pr_debug("PMIC: BSV init complete\n");
2037 return;
2038 }
2039
2040 schedule_work(&motg->sm_work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002041}
2042
2043static irqreturn_t msm_pmic_id_irq(int irq, void *data)
2044{
2045 struct msm_otg *motg = data;
2046
Pavankumar Kondeti4960f312011-12-06 15:46:14 +05302047 if (aca_id_turned_on)
2048 return IRQ_HANDLED;
2049
2050 if (irq_read_line(motg->pdata->pmic_id_irq)) {
2051 pr_debug("PMIC: ID set\n");
2052 set_bit(ID, &motg->inputs);
2053 } else {
2054 pr_debug("PMIC: ID clear\n");
2055 clear_bit(ID, &motg->inputs);
2056 }
2057
2058 if (motg->otg.state != OTG_STATE_UNDEFINED)
2059 schedule_work(&motg->sm_work);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002060
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302061 return IRQ_HANDLED;
2062}
2063
2064static int msm_otg_mode_show(struct seq_file *s, void *unused)
2065{
2066 struct msm_otg *motg = s->private;
2067 struct otg_transceiver *otg = &motg->otg;
2068
2069 switch (otg->state) {
2070 case OTG_STATE_A_HOST:
2071 seq_printf(s, "host\n");
2072 break;
2073 case OTG_STATE_B_PERIPHERAL:
2074 seq_printf(s, "peripheral\n");
2075 break;
2076 default:
2077 seq_printf(s, "none\n");
2078 break;
2079 }
2080
2081 return 0;
2082}
2083
2084static int msm_otg_mode_open(struct inode *inode, struct file *file)
2085{
2086 return single_open(file, msm_otg_mode_show, inode->i_private);
2087}
2088
2089static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
2090 size_t count, loff_t *ppos)
2091{
Pavankumar Kondetie2904ee2011-02-15 09:42:35 +05302092 struct seq_file *s = file->private_data;
2093 struct msm_otg *motg = s->private;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302094 char buf[16];
2095 struct otg_transceiver *otg = &motg->otg;
2096 int status = count;
2097 enum usb_mode_type req_mode;
2098
2099 memset(buf, 0x00, sizeof(buf));
2100
2101 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) {
2102 status = -EFAULT;
2103 goto out;
2104 }
2105
2106 if (!strncmp(buf, "host", 4)) {
2107 req_mode = USB_HOST;
2108 } else if (!strncmp(buf, "peripheral", 10)) {
2109 req_mode = USB_PERIPHERAL;
2110 } else if (!strncmp(buf, "none", 4)) {
2111 req_mode = USB_NONE;
2112 } else {
2113 status = -EINVAL;
2114 goto out;
2115 }
2116
2117 switch (req_mode) {
2118 case USB_NONE:
2119 switch (otg->state) {
2120 case OTG_STATE_A_HOST:
2121 case OTG_STATE_B_PERIPHERAL:
2122 set_bit(ID, &motg->inputs);
2123 clear_bit(B_SESS_VLD, &motg->inputs);
2124 break;
2125 default:
2126 goto out;
2127 }
2128 break;
2129 case USB_PERIPHERAL:
2130 switch (otg->state) {
2131 case OTG_STATE_B_IDLE:
2132 case OTG_STATE_A_HOST:
2133 set_bit(ID, &motg->inputs);
2134 set_bit(B_SESS_VLD, &motg->inputs);
2135 break;
2136 default:
2137 goto out;
2138 }
2139 break;
2140 case USB_HOST:
2141 switch (otg->state) {
2142 case OTG_STATE_B_IDLE:
2143 case OTG_STATE_B_PERIPHERAL:
2144 clear_bit(ID, &motg->inputs);
2145 break;
2146 default:
2147 goto out;
2148 }
2149 break;
2150 default:
2151 goto out;
2152 }
2153
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302154 pm_runtime_resume(otg->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302155 schedule_work(&motg->sm_work);
2156out:
2157 return status;
2158}
2159
2160const struct file_operations msm_otg_mode_fops = {
2161 .open = msm_otg_mode_open,
2162 .read = seq_read,
2163 .write = msm_otg_mode_write,
2164 .llseek = seq_lseek,
2165 .release = single_release,
2166};
2167
Anji jonnalad270e2d2011-08-09 11:28:32 +05302168static int msm_otg_show_chg_type(struct seq_file *s, void *unused)
2169{
2170 struct msm_otg *motg = s->private;
2171
Pavankumar Kondeti9ef69cb2011-12-12 14:18:22 +05302172 seq_printf(s, "%s\n", chg_to_string(motg->chg_type));
Anji jonnalad270e2d2011-08-09 11:28:32 +05302173 return 0;
2174}
2175
2176static int msm_otg_chg_open(struct inode *inode, struct file *file)
2177{
2178 return single_open(file, msm_otg_show_chg_type, inode->i_private);
2179}
2180
2181const struct file_operations msm_otg_chg_fops = {
2182 .open = msm_otg_chg_open,
2183 .read = seq_read,
2184 .llseek = seq_lseek,
2185 .release = single_release,
2186};
2187
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302188static int msm_otg_aca_show(struct seq_file *s, void *unused)
2189{
2190 if (debug_aca_enabled)
2191 seq_printf(s, "enabled\n");
2192 else
2193 seq_printf(s, "disabled\n");
2194
2195 return 0;
2196}
2197
2198static int msm_otg_aca_open(struct inode *inode, struct file *file)
2199{
2200 return single_open(file, msm_otg_aca_show, inode->i_private);
2201}
2202
2203static ssize_t msm_otg_aca_write(struct file *file, const char __user *ubuf,
2204 size_t count, loff_t *ppos)
2205{
2206 char buf[8];
2207
2208 memset(buf, 0x00, sizeof(buf));
2209
2210 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
2211 return -EFAULT;
2212
2213 if (!strncmp(buf, "enable", 6))
2214 debug_aca_enabled = true;
2215 else
2216 debug_aca_enabled = false;
2217
2218 return count;
2219}
2220
2221const struct file_operations msm_otg_aca_fops = {
2222 .open = msm_otg_aca_open,
2223 .read = seq_read,
2224 .write = msm_otg_aca_write,
2225 .llseek = seq_lseek,
2226 .release = single_release,
2227};
2228
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302229static struct dentry *msm_otg_dbg_root;
2230static struct dentry *msm_otg_dbg_mode;
Anji jonnalad270e2d2011-08-09 11:28:32 +05302231static struct dentry *msm_otg_chg_type;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302232static struct dentry *msm_otg_dbg_aca;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302233
2234static int msm_otg_debugfs_init(struct msm_otg *motg)
2235{
Anji jonnalad270e2d2011-08-09 11:28:32 +05302236
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302237 msm_otg_dbg_root = debugfs_create_dir("msm_otg", NULL);
2238
2239 if (!msm_otg_dbg_root || IS_ERR(msm_otg_dbg_root))
2240 return -ENODEV;
2241
Anji jonnalad270e2d2011-08-09 11:28:32 +05302242 if (motg->pdata->mode == USB_OTG &&
2243 motg->pdata->otg_control == OTG_USER_CONTROL) {
2244
2245 msm_otg_dbg_mode = debugfs_create_file("mode", S_IRUGO |
2246 S_IWUSR, msm_otg_dbg_root, motg,
2247 &msm_otg_mode_fops);
2248
2249 if (!msm_otg_dbg_mode) {
2250 debugfs_remove(msm_otg_dbg_root);
2251 msm_otg_dbg_root = NULL;
2252 return -ENODEV;
2253 }
2254 }
2255
2256 msm_otg_chg_type = debugfs_create_file("chg_type", S_IRUGO,
2257 msm_otg_dbg_root, motg,
2258 &msm_otg_chg_fops);
2259
2260 if (!msm_otg_chg_type) {
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302261 debugfs_remove_recursive(msm_otg_dbg_root);
2262 return -ENODEV;
2263 }
2264
2265 msm_otg_dbg_aca = debugfs_create_file("aca", S_IRUGO | S_IWUSR,
2266 msm_otg_dbg_root, motg,
2267 &msm_otg_aca_fops);
2268
2269 if (!msm_otg_dbg_aca) {
2270 debugfs_remove_recursive(msm_otg_dbg_root);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302271 return -ENODEV;
2272 }
2273
2274 return 0;
2275}
2276
2277static void msm_otg_debugfs_cleanup(void)
2278{
Anji jonnalad270e2d2011-08-09 11:28:32 +05302279 debugfs_remove_recursive(msm_otg_dbg_root);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302280}
2281
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302282static u64 msm_otg_dma_mask = DMA_BIT_MASK(64);
2283static struct platform_device *msm_otg_add_pdev(
2284 struct platform_device *ofdev, const char *name)
2285{
2286 struct platform_device *pdev;
2287 const struct resource *res = ofdev->resource;
2288 unsigned int num = ofdev->num_resources;
2289 int retval;
2290
2291 pdev = platform_device_alloc(name, -1);
2292 if (!pdev) {
2293 retval = -ENOMEM;
2294 goto error;
2295 }
2296
2297 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
2298 pdev->dev.dma_mask = &msm_otg_dma_mask;
2299
2300 if (num) {
2301 retval = platform_device_add_resources(pdev, res, num);
2302 if (retval)
2303 goto error;
2304 }
2305
2306 retval = platform_device_add(pdev);
2307 if (retval)
2308 goto error;
2309
2310 return pdev;
2311
2312error:
2313 platform_device_put(pdev);
2314 return ERR_PTR(retval);
2315}
2316
2317static int msm_otg_setup_devices(struct platform_device *ofdev,
2318 enum usb_mode_type mode, bool init)
2319{
2320 const char *gadget_name = "msm_hsusb";
2321 const char *host_name = "msm_hsusb_host";
2322 static struct platform_device *gadget_pdev;
2323 static struct platform_device *host_pdev;
2324 int retval = 0;
2325
2326 if (!init) {
2327 if (gadget_pdev)
2328 platform_device_unregister(gadget_pdev);
2329 if (host_pdev)
2330 platform_device_unregister(host_pdev);
2331 return 0;
2332 }
2333
2334 switch (mode) {
2335 case USB_OTG:
2336 /* fall through */
2337 case USB_PERIPHERAL:
2338 gadget_pdev = msm_otg_add_pdev(ofdev, gadget_name);
2339 if (IS_ERR(gadget_pdev)) {
2340 retval = PTR_ERR(gadget_pdev);
2341 break;
2342 }
2343 if (mode == USB_PERIPHERAL)
2344 break;
2345 /* fall through */
2346 case USB_HOST:
2347 host_pdev = msm_otg_add_pdev(ofdev, host_name);
2348 if (IS_ERR(host_pdev)) {
2349 retval = PTR_ERR(host_pdev);
2350 if (mode == USB_OTG)
2351 platform_device_unregister(gadget_pdev);
2352 }
2353 break;
2354 default:
2355 break;
2356 }
2357
2358 return retval;
2359}
2360
2361struct msm_otg_platform_data *msm_otg_dt_to_pdata(struct platform_device *pdev)
2362{
2363 struct device_node *node = pdev->dev.of_node;
2364 struct msm_otg_platform_data *pdata;
2365 int len = 0;
2366
2367 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
2368 if (!pdata) {
2369 pr_err("unable to allocate platform data\n");
2370 return NULL;
2371 }
2372 of_get_property(node, "qcom,hsusb-otg-phy-init-seq", &len);
2373 if (len) {
2374 pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
2375 if (!pdata->phy_init_seq)
2376 return NULL;
2377 of_property_read_u32_array(node, "qcom,hsusb-otg-phy-init-seq",
2378 pdata->phy_init_seq,
2379 len/sizeof(*pdata->phy_init_seq));
2380 }
2381 of_property_read_u32(node, "qcom,hsusb-otg-power-budget",
2382 &pdata->power_budget);
2383 of_property_read_u32(node, "qcom,hsusb-otg-mode",
2384 &pdata->mode);
2385 of_property_read_u32(node, "qcom,hsusb-otg-otg-control",
2386 &pdata->otg_control);
2387 of_property_read_u32(node, "qcom,hsusb-otg-default-mode",
2388 &pdata->default_mode);
2389 of_property_read_u32(node, "qcom,hsusb-otg-phy-type",
2390 &pdata->phy_type);
2391 of_property_read_u32(node, "qcom,hsusb-otg-pmic-id-irq",
2392 &pdata->pmic_id_irq);
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302393 return pdata;
2394}
2395
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302396static int __init msm_otg_probe(struct platform_device *pdev)
2397{
2398 int ret = 0;
2399 struct resource *res;
2400 struct msm_otg *motg;
2401 struct otg_transceiver *otg;
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302402 struct msm_otg_platform_data *pdata;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302403
2404 dev_info(&pdev->dev, "msm_otg probe\n");
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302405
2406 if (pdev->dev.of_node) {
2407 dev_dbg(&pdev->dev, "device tree enabled\n");
2408 pdata = msm_otg_dt_to_pdata(pdev);
2409 if (!pdata)
2410 return -ENOMEM;
2411 ret = msm_otg_setup_devices(pdev, pdata->mode, true);
2412 if (ret) {
2413 dev_err(&pdev->dev, "devices setup failed\n");
2414 return ret;
2415 }
2416 } else if (!pdev->dev.platform_data) {
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302417 dev_err(&pdev->dev, "No platform data given. Bailing out\n");
2418 return -ENODEV;
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302419 } else {
2420 pdata = pdev->dev.platform_data;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302421 }
2422
2423 motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL);
2424 if (!motg) {
2425 dev_err(&pdev->dev, "unable to allocate msm_otg\n");
2426 return -ENOMEM;
2427 }
2428
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002429 the_msm_otg = motg;
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302430 motg->pdata = pdata;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302431 otg = &motg->otg;
2432 otg->dev = &pdev->dev;
2433
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302434 /*
2435 * ACA ID_GND threshold range is overlapped with OTG ID_FLOAT. Hence
2436 * PHY treat ACA ID_GND as float and no interrupt is generated. But
2437 * PMIC can detect ACA ID_GND and generate an interrupt.
2438 */
2439 if (aca_enabled() && motg->pdata->otg_control != OTG_PMIC_CONTROL) {
2440 dev_err(&pdev->dev, "ACA can not be enabled without PMIC\n");
2441 ret = -EINVAL;
2442 goto free_motg;
2443 }
2444
Ofir Cohen4da266f2012-01-03 10:19:29 +02002445 /* initialize reset counter */
2446 motg->reset_counter = 0;
2447
Amit Blay02eff132011-09-21 16:46:24 +03002448 /* Some targets don't support PHY clock. */
Manu Gautam5143b252012-01-05 19:25:23 -08002449 motg->phy_reset_clk = clk_get(&pdev->dev, "phy_clk");
Amit Blay02eff132011-09-21 16:46:24 +03002450 if (IS_ERR(motg->phy_reset_clk))
Manu Gautam5143b252012-01-05 19:25:23 -08002451 dev_err(&pdev->dev, "failed to get phy_clk\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302452
Manu Gautam5143b252012-01-05 19:25:23 -08002453 motg->clk = clk_get(&pdev->dev, "alt_core_clk");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302454 if (IS_ERR(motg->clk)) {
Manu Gautam5143b252012-01-05 19:25:23 -08002455 dev_err(&pdev->dev, "failed to get alt_core_clk\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302456 ret = PTR_ERR(motg->clk);
2457 goto put_phy_reset_clk;
2458 }
Anji jonnala0f73cac2011-05-04 10:19:46 +05302459 clk_set_rate(motg->clk, 60000000);
2460
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05302461 /* pm qos request to prevent apps idle power collapse */
2462 if (motg->pdata->swfi_latency)
2463 pm_qos_add_request(&motg->pm_qos_req_dma,
2464 PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Manu Gautam5143b252012-01-05 19:25:23 -08002465
Anji jonnala0f73cac2011-05-04 10:19:46 +05302466 /*
Manu Gautam5143b252012-01-05 19:25:23 -08002467 * USB Core is running its protocol engine based on CORE CLK,
Anji jonnala0f73cac2011-05-04 10:19:46 +05302468 * CORE CLK must be running at >55Mhz for correct HSUSB
2469 * operation and USB core cannot tolerate frequency changes on
2470 * CORE CLK. For such USB cores, vote for maximum clk frequency
2471 * on pclk source
2472 */
Manu Gautam5143b252012-01-05 19:25:23 -08002473 motg->core_clk = clk_get(&pdev->dev, "core_clk");
2474 if (IS_ERR(motg->core_clk)) {
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302475 motg->core_clk = NULL;
Manu Gautam5143b252012-01-05 19:25:23 -08002476 dev_err(&pdev->dev, "failed to get core_clk\n");
2477 ret = PTR_ERR(motg->clk);
2478 goto put_clk;
2479 }
2480 clk_set_rate(motg->core_clk, INT_MAX);
2481
2482 motg->pclk = clk_get(&pdev->dev, "iface_clk");
2483 if (IS_ERR(motg->pclk)) {
2484 dev_err(&pdev->dev, "failed to get iface_clk\n");
2485 ret = PTR_ERR(motg->pclk);
2486 goto put_core_clk;
2487 }
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302488
2489 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2490 if (!res) {
2491 dev_err(&pdev->dev, "failed to get platform resource mem\n");
2492 ret = -ENODEV;
Manu Gautam5143b252012-01-05 19:25:23 -08002493 goto put_pclk;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302494 }
2495
2496 motg->regs = ioremap(res->start, resource_size(res));
2497 if (!motg->regs) {
2498 dev_err(&pdev->dev, "ioremap failed\n");
2499 ret = -ENOMEM;
Manu Gautam5143b252012-01-05 19:25:23 -08002500 goto put_pclk;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302501 }
2502 dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs);
2503
2504 motg->irq = platform_get_irq(pdev, 0);
2505 if (!motg->irq) {
2506 dev_err(&pdev->dev, "platform_get_irq failed\n");
2507 ret = -ENODEV;
2508 goto free_regs;
2509 }
2510
Stephen Boyd7dd22662012-01-26 16:09:31 -08002511 motg->xo_handle = clk_get(&pdev->dev, "xo");
Anji jonnala7da3f262011-12-02 17:22:14 -08002512 if (IS_ERR(motg->xo_handle)) {
2513 dev_err(&pdev->dev, "%s not able to get the handle "
2514 "to vote for TCXO D0 buffer\n", __func__);
2515 ret = PTR_ERR(motg->xo_handle);
2516 goto free_regs;
2517 }
2518
Stephen Boyd7dd22662012-01-26 16:09:31 -08002519 ret = clk_prepare_enable(motg->xo_handle);
Anji jonnala7da3f262011-12-02 17:22:14 -08002520 if (ret) {
2521 dev_err(&pdev->dev, "%s failed to vote for TCXO "
2522 "D0 buffer%d\n", __func__, ret);
2523 goto free_xo_handle;
2524 }
2525
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302526 clk_enable(motg->pclk);
Anji jonnala11aa5c42011-05-04 10:19:48 +05302527
2528 ret = msm_hsusb_init_vddcx(motg, 1);
2529 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002530 dev_err(&pdev->dev, "hsusb vddcx init failed\n");
Anji jonnala7da3f262011-12-02 17:22:14 -08002531 goto devote_xo_handle;
Anji jonnala11aa5c42011-05-04 10:19:48 +05302532 }
2533
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002534 ret = msm_hsusb_config_vddcx(1);
2535 if (ret) {
2536 dev_err(&pdev->dev, "hsusb vddcx configuration failed\n");
2537 goto free_init_vddcx;
2538 }
2539
Anji jonnala11aa5c42011-05-04 10:19:48 +05302540 ret = msm_hsusb_ldo_init(motg, 1);
2541 if (ret) {
2542 dev_err(&pdev->dev, "hsusb vreg configuration failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002543 goto free_init_vddcx;
Anji jonnala11aa5c42011-05-04 10:19:48 +05302544 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002545
2546 ret = msm_hsusb_ldo_enable(motg, 1);
Anji jonnala11aa5c42011-05-04 10:19:48 +05302547 if (ret) {
2548 dev_err(&pdev->dev, "hsusb vreg enable failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002549 goto free_ldo_init;
Anji jonnala11aa5c42011-05-04 10:19:48 +05302550 }
Manu Gautam5143b252012-01-05 19:25:23 -08002551 clk_enable(motg->core_clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302552
2553 writel(0, USB_USBINTR);
2554 writel(0, USB_OTGSC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002555 /* Ensure that above STOREs are completed before enabling interrupts */
2556 mb();
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302557
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002558 wake_lock_init(&motg->wlock, WAKE_LOCK_SUSPEND, "msm_otg");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302559 INIT_WORK(&motg->sm_work, msm_otg_sm_work);
Pavankumar Kondetid8608522011-05-04 10:19:47 +05302560 INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302561 setup_timer(&motg->id_timer, msm_otg_id_timer_func,
2562 (unsigned long) motg);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302563 ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED,
2564 "msm_otg", motg);
2565 if (ret) {
2566 dev_err(&pdev->dev, "request irq failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002567 goto destroy_wlock;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302568 }
2569
2570 otg->init = msm_otg_reset;
2571 otg->set_host = msm_otg_set_host;
2572 otg->set_peripheral = msm_otg_set_peripheral;
Pavankumar Kondetid8608522011-05-04 10:19:47 +05302573 otg->set_power = msm_otg_set_power;
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302574 otg->set_suspend = msm_otg_set_suspend;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302575
2576 otg->io_ops = &msm_otg_io_ops;
2577
2578 ret = otg_set_transceiver(&motg->otg);
2579 if (ret) {
2580 dev_err(&pdev->dev, "otg_set_transceiver failed\n");
2581 goto free_irq;
2582 }
2583
Pavankumar Kondeti0d81f312012-01-13 11:34:10 +05302584 if (motg->pdata->mode == USB_OTG &&
2585 motg->pdata->otg_control == OTG_PMIC_CONTROL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002586 if (motg->pdata->pmic_id_irq) {
2587 ret = request_irq(motg->pdata->pmic_id_irq,
2588 msm_pmic_id_irq,
2589 IRQF_TRIGGER_RISING |
2590 IRQF_TRIGGER_FALLING,
2591 "msm_otg", motg);
2592 if (ret) {
2593 dev_err(&pdev->dev, "request irq failed for PMIC ID\n");
2594 goto remove_otg;
2595 }
2596 } else {
2597 ret = -ENODEV;
2598 dev_err(&pdev->dev, "PMIC IRQ for ID notifications doesn't exist\n");
2599 goto remove_otg;
2600 }
2601 }
2602
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +05302603 msm_hsusb_mhl_switch_enable(motg, 1);
2604
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302605 platform_set_drvdata(pdev, motg);
2606 device_init_wakeup(&pdev->dev, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002607 motg->mA_port = IUNIT;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302608
Anji jonnalad270e2d2011-08-09 11:28:32 +05302609 ret = msm_otg_debugfs_init(motg);
2610 if (ret)
2611 dev_dbg(&pdev->dev, "mode debugfs file is"
2612 "not available\n");
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302613
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002614 if (motg->pdata->otg_control == OTG_PMIC_CONTROL)
2615 pm8921_charger_register_vbus_sn(&msm_otg_set_vbus_state);
2616
Amit Blay58b31472011-11-18 09:39:39 +02002617 if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY) {
2618 if (motg->pdata->otg_control == OTG_PMIC_CONTROL &&
Pavankumar Kondeti0d81f312012-01-13 11:34:10 +05302619 (!(motg->pdata->mode == USB_OTG) ||
2620 motg->pdata->pmic_id_irq))
Amit Blay58b31472011-11-18 09:39:39 +02002621 motg->caps = ALLOW_PHY_POWER_COLLAPSE |
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002622 ALLOW_PHY_RETENTION |
2623 ALLOW_PHY_COMP_DISABLE;
2624
Amit Blay58b31472011-11-18 09:39:39 +02002625 if (motg->pdata->otg_control == OTG_PHY_CONTROL)
2626 motg->caps = ALLOW_PHY_RETENTION;
2627 }
2628
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002629 wake_lock(&motg->wlock);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302630 pm_runtime_set_active(&pdev->dev);
2631 pm_runtime_enable(&pdev->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302632
Manu Gautamcd82e9d2011-12-20 14:17:28 +05302633 if (motg->pdata->bus_scale_table) {
2634 motg->bus_perf_client =
2635 msm_bus_scale_register_client(motg->pdata->bus_scale_table);
2636 if (!motg->bus_perf_client)
2637 dev_err(motg->otg.dev, "%s: Failed to register BUS "
2638 "scaling client!!\n", __func__);
2639 }
2640
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302641 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002642
2643remove_otg:
2644 otg_set_transceiver(NULL);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302645free_irq:
2646 free_irq(motg->irq, motg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002647destroy_wlock:
2648 wake_lock_destroy(&motg->wlock);
Manu Gautam5143b252012-01-05 19:25:23 -08002649 clk_disable(motg->core_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002650 msm_hsusb_ldo_enable(motg, 0);
2651free_ldo_init:
Anji jonnala11aa5c42011-05-04 10:19:48 +05302652 msm_hsusb_ldo_init(motg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002653free_init_vddcx:
Anji jonnala11aa5c42011-05-04 10:19:48 +05302654 msm_hsusb_init_vddcx(motg, 0);
Anji jonnala7da3f262011-12-02 17:22:14 -08002655devote_xo_handle:
Manu Gautam5143b252012-01-05 19:25:23 -08002656 clk_disable(motg->pclk);
Stephen Boyd7dd22662012-01-26 16:09:31 -08002657 clk_disable_unprepare(motg->xo_handle);
Anji jonnala7da3f262011-12-02 17:22:14 -08002658free_xo_handle:
Stephen Boyd7dd22662012-01-26 16:09:31 -08002659 clk_put(motg->xo_handle);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302660free_regs:
2661 iounmap(motg->regs);
Manu Gautam5143b252012-01-05 19:25:23 -08002662put_pclk:
2663 clk_put(motg->pclk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302664put_core_clk:
Manu Gautam5143b252012-01-05 19:25:23 -08002665 clk_put(motg->core_clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302666put_clk:
2667 clk_put(motg->clk);
2668put_phy_reset_clk:
Amit Blay02eff132011-09-21 16:46:24 +03002669 if (!IS_ERR(motg->phy_reset_clk))
2670 clk_put(motg->phy_reset_clk);
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +05302671free_motg:
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05302672 if (motg->pdata->swfi_latency)
2673 pm_qos_remove_request(&motg->pm_qos_req_dma);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302674 kfree(motg);
2675 return ret;
2676}
2677
2678static int __devexit msm_otg_remove(struct platform_device *pdev)
2679{
2680 struct msm_otg *motg = platform_get_drvdata(pdev);
2681 struct otg_transceiver *otg = &motg->otg;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302682 int cnt = 0;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302683
2684 if (otg->host || otg->gadget)
2685 return -EBUSY;
2686
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302687 if (pdev->dev.of_node)
2688 msm_otg_setup_devices(pdev, motg->pdata->mode, false);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002689 if (motg->pdata->otg_control == OTG_PMIC_CONTROL)
2690 pm8921_charger_unregister_vbus_sn(0);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302691 msm_otg_debugfs_cleanup();
Pavankumar Kondetid8608522011-05-04 10:19:47 +05302692 cancel_delayed_work_sync(&motg->chg_work);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302693 cancel_work_sync(&motg->sm_work);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302694
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302695 pm_runtime_resume(&pdev->dev);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302696
2697 device_init_wakeup(&pdev->dev, 0);
2698 pm_runtime_disable(&pdev->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002699 wake_lock_destroy(&motg->wlock);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302700
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +05302701 msm_hsusb_mhl_switch_enable(motg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002702 if (motg->pdata->pmic_id_irq)
2703 free_irq(motg->pdata->pmic_id_irq, motg);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302704 otg_set_transceiver(NULL);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302705 free_irq(motg->irq, motg);
2706
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302707 /*
2708 * Put PHY in low power mode.
2709 */
2710 ulpi_read(otg, 0x14);
2711 ulpi_write(otg, 0x08, 0x09);
2712
2713 writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC);
2714 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
2715 if (readl(USB_PORTSC) & PORTSC_PHCD)
2716 break;
2717 udelay(1);
2718 cnt++;
2719 }
2720 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC)
2721 dev_err(otg->dev, "Unable to suspend PHY\n");
2722
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302723 clk_disable(motg->pclk);
Manu Gautam5143b252012-01-05 19:25:23 -08002724 clk_disable(motg->core_clk);
Stephen Boyd7dd22662012-01-26 16:09:31 -08002725 clk_put(motg->xo_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002726 msm_hsusb_ldo_enable(motg, 0);
Anji jonnala11aa5c42011-05-04 10:19:48 +05302727 msm_hsusb_ldo_init(motg, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002728 msm_hsusb_init_vddcx(motg, 0);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302729
2730 iounmap(motg->regs);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302731 pm_runtime_set_suspended(&pdev->dev);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302732
Amit Blay02eff132011-09-21 16:46:24 +03002733 if (!IS_ERR(motg->phy_reset_clk))
2734 clk_put(motg->phy_reset_clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302735 clk_put(motg->pclk);
2736 clk_put(motg->clk);
Manu Gautam5143b252012-01-05 19:25:23 -08002737 clk_put(motg->core_clk);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302738
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05302739 if (motg->pdata->swfi_latency)
2740 pm_qos_remove_request(&motg->pm_qos_req_dma);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302741
Manu Gautamcd82e9d2011-12-20 14:17:28 +05302742 if (motg->bus_perf_client)
2743 msm_bus_scale_unregister_client(motg->bus_perf_client);
2744
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +05302745 kfree(motg);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302746 return 0;
2747}
2748
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302749#ifdef CONFIG_PM_RUNTIME
2750static int msm_otg_runtime_idle(struct device *dev)
2751{
2752 struct msm_otg *motg = dev_get_drvdata(dev);
2753 struct otg_transceiver *otg = &motg->otg;
2754
2755 dev_dbg(dev, "OTG runtime idle\n");
2756
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302757 if (otg->state == OTG_STATE_UNDEFINED)
2758 return -EAGAIN;
2759 else
2760 return 0;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302761}
2762
2763static int msm_otg_runtime_suspend(struct device *dev)
2764{
2765 struct msm_otg *motg = dev_get_drvdata(dev);
2766
2767 dev_dbg(dev, "OTG runtime suspend\n");
2768 return msm_otg_suspend(motg);
2769}
2770
2771static int msm_otg_runtime_resume(struct device *dev)
2772{
2773 struct msm_otg *motg = dev_get_drvdata(dev);
2774
2775 dev_dbg(dev, "OTG runtime resume\n");
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302776 pm_runtime_get_noresume(dev);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302777 return msm_otg_resume(motg);
2778}
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302779#endif
2780
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302781#ifdef CONFIG_PM_SLEEP
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302782static int msm_otg_pm_suspend(struct device *dev)
2783{
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302784 int ret;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302785
2786 dev_dbg(dev, "OTG PM suspend\n");
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +05302787
2788#ifdef CONFIG_PM_RUNTIME
2789 ret = pm_runtime_suspend(dev);
2790 if (ret > 0)
2791 ret = 0;
2792#else
2793 ret = msm_otg_suspend(dev_get_drvdata(dev));
2794#endif
2795 return ret;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302796}
2797
2798static int msm_otg_pm_resume(struct device *dev)
2799{
2800 struct msm_otg *motg = dev_get_drvdata(dev);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302801
2802 dev_dbg(dev, "OTG PM resume\n");
2803
Manu Gautamf284c052011-09-08 16:52:48 +05302804#ifdef CONFIG_PM_RUNTIME
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302805 /*
Manu Gautamf284c052011-09-08 16:52:48 +05302806 * Do not resume hardware as part of system resume,
2807 * rather, wait for the ASYNC INT from the h/w
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302808 */
Gregory Beanebd8ca22011-10-11 12:02:35 -07002809 return 0;
Manu Gautamf284c052011-09-08 16:52:48 +05302810#endif
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302811
Manu Gautamf284c052011-09-08 16:52:48 +05302812 return msm_otg_resume(motg);
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302813}
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302814#endif
2815
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302816#ifdef CONFIG_PM
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302817static const struct dev_pm_ops msm_otg_dev_pm_ops = {
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302818 SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume)
2819 SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume,
2820 msm_otg_runtime_idle)
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302821};
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302822#endif
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302823
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302824static struct of_device_id msm_otg_dt_match[] = {
2825 { .compatible = "qcom,hsusb-otg",
2826 },
2827 {}
2828};
2829
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302830static struct platform_driver msm_otg_driver = {
2831 .remove = __devexit_p(msm_otg_remove),
2832 .driver = {
2833 .name = DRIVER_NAME,
2834 .owner = THIS_MODULE,
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302835#ifdef CONFIG_PM
Pavankumar Kondeti87c01042010-12-07 17:53:58 +05302836 .pm = &msm_otg_dev_pm_ops,
Pavankumar Kondeti70187732011-02-15 09:42:34 +05302837#endif
Pavankumar Kondetieaea7fe2011-10-27 14:46:45 +05302838 .of_match_table = msm_otg_dt_match,
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302839 },
2840};
2841
2842static int __init msm_otg_init(void)
2843{
2844 return platform_driver_probe(&msm_otg_driver, msm_otg_probe);
2845}
2846
2847static void __exit msm_otg_exit(void)
2848{
2849 platform_driver_unregister(&msm_otg_driver);
2850}
2851
2852module_init(msm_otg_init);
2853module_exit(msm_otg_exit);
2854
2855MODULE_LICENSE("GPL v2");
2856MODULE_DESCRIPTION("MSM USB transceiver driver");