blob: 49803372f3f18269ba537d028fd61a5478fea042 [file] [log] [blame]
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +02001/**
2 * dwc3_otg.c - DesignWare USB3 DRD Controller OTG
3 *
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05304 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +02005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <linux/usb.h>
17#include <linux/usb/hcd.h>
18#include <linux/platform_device.h>
Manu Gautamf1fceddf2012-10-12 14:02:50 +053019#include <linux/regulator/consumer.h>
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +020020
21#include "core.h"
22#include "dwc3_otg.h"
23#include "io.h"
24#include "xhci.h"
25
Manu Gautamf1fceddf2012-10-12 14:02:50 +053026static void dwc3_otg_reset(struct dwc3_otg *dotg);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +020027
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +053028static void dwc3_otg_notify_host_mode(struct usb_otg *otg, int host_mode);
29static void dwc3_otg_reset(struct dwc3_otg *dotg);
30
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +020031/**
32 * dwc3_otg_set_host_regs - reset dwc3 otg registers to host operation.
33 *
34 * This function sets the OTG registers to work in A-Device host mode.
35 * This function should be called just before entering to A-Device mode.
36 *
Manu Gautamf1fceddf2012-10-12 14:02:50 +053037 * @w: Pointer to the dwc3 otg struct
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +020038 */
39static void dwc3_otg_set_host_regs(struct dwc3_otg *dotg)
40{
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +053041 u32 reg;
42 struct dwc3 *dwc = dotg->dwc;
43 struct dwc3_ext_xceiv *ext_xceiv = dotg->ext_xceiv;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +020044
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +053045 if (ext_xceiv && !ext_xceiv->otg_capability) {
46 /* Set OCTL[6](PeriMode) to 0 (host) */
47 reg = dwc3_readl(dotg->regs, DWC3_OCTL);
48 reg &= ~DWC3_OTG_OCTL_PERIMODE;
49 dwc3_writel(dotg->regs, DWC3_OCTL, reg);
50 } else {
51 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
52 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
53 reg |= DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_HOST);
54 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
55 }
Manu Gautamf1fceddf2012-10-12 14:02:50 +053056}
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +020057
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +053058static int dwc3_otg_set_suspend(struct usb_phy *phy, int suspend)
59{
60 struct usb_otg *otg = phy->otg;
61 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
62
63 if (dotg->host_bus_suspend == suspend)
64 return 0;
65
66 dotg->host_bus_suspend = suspend;
67 if (suspend) {
68 pm_runtime_put_sync(phy->dev);
69 } else {
70 pm_runtime_get_noresume(phy->dev);
71 pm_runtime_resume(phy->dev);
72 }
73
74 return 0;
75}
76
Manu Gautamf1fceddf2012-10-12 14:02:50 +053077/**
78 * dwc3_otg_set_host_power - Enable port power control for host operation
79 *
80 * This function enables the OTG Port Power required to operate in Host mode
81 * This function should be called only after XHCI driver has set the port
82 * power in PORTSC register.
83 *
84 * @w: Pointer to the dwc3 otg struct
85 */
86void dwc3_otg_set_host_power(struct dwc3_otg *dotg)
87{
88 u32 osts;
89
90 osts = dwc3_readl(dotg->regs, DWC3_OSTS);
91 if (!(osts & 0x8))
92 dev_err(dotg->dwc->dev, "%s: xHCIPrtPower not set\n", __func__);
93
94 dwc3_writel(dotg->regs, DWC3_OCTL, DWC3_OTG_OCTL_PRTPWRCTL);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +020095}
96
97/**
98 * dwc3_otg_set_peripheral_regs - reset dwc3 otg registers to peripheral operation.
99 *
100 * This function sets the OTG registers to work in B-Device peripheral mode.
101 * This function should be called just before entering to B-Device mode.
102 *
103 * @w: Pointer to the dwc3 otg workqueue.
104 */
105static void dwc3_otg_set_peripheral_regs(struct dwc3_otg *dotg)
106{
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +0530107 u32 reg;
108 struct dwc3 *dwc = dotg->dwc;
109 struct dwc3_ext_xceiv *ext_xceiv = dotg->ext_xceiv;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200110
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +0530111 if (ext_xceiv && !ext_xceiv->otg_capability) {
112 /* Set OCTL[6](PeriMode) to 1 (peripheral) */
113 reg = dwc3_readl(dotg->regs, DWC3_OCTL);
114 reg |= DWC3_OTG_OCTL_PERIMODE;
115 dwc3_writel(dotg->regs, DWC3_OCTL, reg);
116 /*
117 * TODO: add more OTG registers writes for PERIPHERAL mode here,
118 * see figure 12-19 B-device flow in dwc3 Synopsis spec
119 */
120 } else {
121 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
122 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
123 reg |= DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_DEVICE);
124 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
125 }
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200126}
127
128/**
129 * dwc3_otg_start_host - helper function for starting/stoping the host controller driver.
130 *
131 * @otg: Pointer to the otg_transceiver structure.
132 * @on: start / stop the host controller driver.
133 *
134 * Returns 0 on success otherwise negative errno.
135 */
136static int dwc3_otg_start_host(struct usb_otg *otg, int on)
137{
138 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +0530139 struct dwc3_ext_xceiv *ext_xceiv = dotg->ext_xceiv;
Manu Gautam61721592012-11-06 18:09:39 +0530140 struct dwc3 *dwc = dotg->dwc;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200141 int ret = 0;
142
Manu Gautam61721592012-11-06 18:09:39 +0530143 if (!dwc->xhci)
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200144 return -EINVAL;
145
Manu Gautam61721592012-11-06 18:09:39 +0530146 if (!dotg->vbus_otg) {
147 dotg->vbus_otg = devm_regulator_get(dwc->dev->parent,
148 "vbus_dwc3");
149 if (IS_ERR(dotg->vbus_otg)) {
150 dev_err(dwc->dev, "Failed to get vbus regulator\n");
151 ret = PTR_ERR(dotg->vbus_otg);
152 dotg->vbus_otg = 0;
153 return ret;
154 }
155 }
156
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200157 if (on) {
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530158 dev_dbg(otg->phy->dev, "%s: turn on host\n", __func__);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200159
160 /*
161 * This should be revisited for more testing post-silicon.
162 * In worst case we may need to disconnect the root hub
163 * before stopping the controller so that it does not
164 * interfere with runtime pm/system pm.
165 * We can also consider registering and unregistering xhci
166 * platform device. It is almost similar to add_hcd and
167 * remove_hcd, But we may not use standard set_host method
168 * anymore.
169 */
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530170 dwc3_otg_set_host_regs(dotg);
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +0530171 /*
172 * FIXME If micro A cable is disconnected during system suspend,
173 * xhci platform device will be removed before runtime pm is
174 * enabled for xhci device. Due to this, disable_depth becomes
175 * greater than one and runtimepm is not enabled for next microA
176 * connect. Fix this by calling pm_runtime_init for xhci device.
177 */
178 pm_runtime_init(&dwc->xhci->dev);
Manu Gautam61721592012-11-06 18:09:39 +0530179 ret = platform_device_add(dwc->xhci);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200180 if (ret) {
181 dev_err(otg->phy->dev,
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530182 "%s: failed to add XHCI pdev ret=%d\n",
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200183 __func__, ret);
184 return ret;
185 }
186
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530187 dwc3_otg_notify_host_mode(otg, on);
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530188 ret = regulator_enable(dotg->vbus_otg);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200189 if (ret) {
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530190 dev_err(otg->phy->dev, "unable to enable vbus_otg\n");
Manu Gautam61721592012-11-06 18:09:39 +0530191 platform_device_del(dwc->xhci);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200192 return ret;
193 }
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530194
195 /* re-init OTG EVTEN register as XHCI reset clears it */
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +0530196 if (ext_xceiv && !ext_xceiv->otg_capability)
197 dwc3_otg_reset(dotg);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200198 } else {
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530199 dev_dbg(otg->phy->dev, "%s: turn off host\n", __func__);
200
Manu Gautam61721592012-11-06 18:09:39 +0530201 platform_device_del(dwc->xhci);
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530202
203 ret = regulator_disable(dotg->vbus_otg);
204 if (ret) {
205 dev_err(otg->phy->dev, "unable to disable vbus_otg\n");
206 return ret;
207 }
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530208 dwc3_otg_notify_host_mode(otg, on);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200209 }
210
211 return 0;
212}
213
214/**
215 * dwc3_otg_set_host - bind/unbind the host controller driver.
216 *
217 * @otg: Pointer to the otg_transceiver structure.
218 * @host: Pointer to the usb_bus structure.
219 *
220 * Returns 0 on success otherwise negative errno.
221 */
222static int dwc3_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
223{
224 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
225
226 if (host) {
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530227 dev_dbg(otg->phy->dev, "%s: set host %s, portpower\n",
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200228 __func__, host->bus_name);
229 otg->host = host;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200230 /*
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530231 * Though XHCI power would be set by now, but some delay is
232 * required for XHCI controller before setting OTG Port Power
233 * TODO: Tune this delay
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200234 */
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530235 msleep(300);
236 dwc3_otg_set_host_power(dotg);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200237 } else {
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530238 otg->host = NULL;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200239 }
240
241 return 0;
242}
243
244/**
245 * dwc3_otg_start_peripheral - bind/unbind the peripheral controller.
246 *
247 * @otg: Pointer to the otg_transceiver structure.
248 * @gadget: pointer to the usb_gadget structure.
249 *
250 * Returns 0 on success otherwise negative errno.
251 */
252static int dwc3_otg_start_peripheral(struct usb_otg *otg, int on)
253{
254 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
Manu Gautama302f612012-12-18 17:33:06 +0530255 struct dwc3_ext_xceiv *ext_xceiv = dotg->ext_xceiv;
256 struct dwc3 *dwc = dotg->dwc;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200257
258 if (!otg->gadget)
259 return -EINVAL;
260
261 if (on) {
262 dev_dbg(otg->phy->dev, "%s: turn on gadget %s\n",
263 __func__, otg->gadget->name);
Manu Gautama302f612012-12-18 17:33:06 +0530264
265 /*
266 * Hardware reset is required to support below scenarios:
267 * 1. Host <-> peripheral switching
268 * 2. Once an endpoint is configured in DBM (BAM) mode, it
269 * can be unconfigured only after RESET
270 */
271 if (ext_xceiv && ext_xceiv->otg_capability &&
272 ext_xceiv->ext_block_reset)
273 ext_xceiv->ext_block_reset();
274
275 /* re-init core and OTG registers as block reset clears these */
276 dwc3_post_host_reset_core_init(dwc);
277 if (ext_xceiv && !ext_xceiv->otg_capability)
278 dwc3_otg_reset(dotg);
279
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200280 dwc3_otg_set_peripheral_regs(dotg);
281 usb_gadget_vbus_connect(otg->gadget);
282 } else {
283 dev_dbg(otg->phy->dev, "%s: turn off gadget %s\n",
284 __func__, otg->gadget->name);
285 usb_gadget_vbus_disconnect(otg->gadget);
286 }
287
288 return 0;
289}
290
291/**
292 * dwc3_otg_set_peripheral - bind/unbind the peripheral controller driver.
293 *
294 * @otg: Pointer to the otg_transceiver structure.
295 * @gadget: pointer to the usb_gadget structure.
296 *
297 * Returns 0 on success otherwise negative errno.
298 */
299static int dwc3_otg_set_peripheral(struct usb_otg *otg,
300 struct usb_gadget *gadget)
301{
302 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
303
304 if (gadget) {
305 dev_dbg(otg->phy->dev, "%s: set gadget %s\n",
306 __func__, gadget->name);
307 otg->gadget = gadget;
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530308 schedule_work(&dotg->sm_work);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200309 } else {
310 if (otg->phy->state == OTG_STATE_B_PERIPHERAL) {
311 dwc3_otg_start_peripheral(otg, 0);
312 otg->gadget = NULL;
313 otg->phy->state = OTG_STATE_UNDEFINED;
314 schedule_work(&dotg->sm_work);
315 } else {
316 otg->gadget = NULL;
317 }
318 }
319
320 return 0;
321}
322
323/**
Manu Gautam8c642812012-06-07 10:35:10 +0530324 * dwc3_ext_chg_det_done - callback to handle charger detection completion
325 * @otg: Pointer to the otg transceiver structure
326 * @charger: Pointer to the external charger structure
327 *
328 * Returns 0 on success
329 */
330static void dwc3_ext_chg_det_done(struct usb_otg *otg, struct dwc3_charger *chg)
331{
332 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
333
334 /*
335 * Ignore chg_detection notification if BSV has gone off by this time.
336 * STOP chg_det as part of !BSV handling would reset the chg_det flags
337 */
338 if (test_bit(B_SESS_VLD, &dotg->inputs))
339 schedule_work(&dotg->sm_work);
340}
341
342/**
343 * dwc3_set_charger - bind/unbind external charger driver
344 * @otg: Pointer to the otg transceiver structure
345 * @charger: Pointer to the external charger structure
346 *
347 * Returns 0 on success
348 */
349int dwc3_set_charger(struct usb_otg *otg, struct dwc3_charger *charger)
350{
351 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
352
353 dotg->charger = charger;
354 if (charger)
355 charger->notify_detection_complete = dwc3_ext_chg_det_done;
356
357 return 0;
358}
359
Manu Gautamb5067272012-07-02 09:53:41 +0530360/**
361 * dwc3_ext_event_notify - callback to handle events from external transceiver
362 * @otg: Pointer to the otg transceiver structure
363 * @event: Event reported by transceiver
364 *
365 * Returns 0 on success
366 */
367static void dwc3_ext_event_notify(struct usb_otg *otg,
368 enum dwc3_ext_events event)
369{
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530370 static bool init;
Manu Gautamb5067272012-07-02 09:53:41 +0530371 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
372 struct dwc3_ext_xceiv *ext_xceiv = dotg->ext_xceiv;
373 struct usb_phy *phy = dotg->otg.phy;
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530374 int ret = 0;
Manu Gautamb5067272012-07-02 09:53:41 +0530375
376 if (event == DWC3_EVENT_PHY_RESUME) {
377 if (!pm_runtime_status_suspended(phy->dev)) {
378 dev_warn(phy->dev, "PHY_RESUME event out of LPM!!!!\n");
379 } else {
380 dev_dbg(phy->dev, "ext PHY_RESUME event received\n");
381 /* ext_xceiver would have taken h/w out of LPM by now */
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530382 ret = pm_runtime_get(phy->dev);
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +0530383 if ((phy->state == OTG_STATE_A_HOST) &&
384 dotg->host_bus_suspend)
385 dotg->host_bus_suspend = 0;
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530386 if (ret == -EACCES) {
387 /* pm_runtime_get may fail during system
388 resume with -EACCES error */
389 pm_runtime_disable(phy->dev);
390 pm_runtime_set_active(phy->dev);
391 pm_runtime_enable(phy->dev);
392 } else if (ret < 0) {
393 dev_warn(phy->dev, "pm_runtime_get failed!\n");
394 }
Manu Gautamb5067272012-07-02 09:53:41 +0530395 }
Manu Gautam377821c2012-09-28 16:53:24 +0530396 } else if (event == DWC3_EVENT_XCEIV_STATE) {
Jack Pham0fc12332012-11-19 13:14:22 -0800397 if (ext_xceiv->id == DWC3_ID_FLOAT) {
Manu Gautama4c3c1f2012-12-18 13:56:43 +0530398 dev_dbg(phy->dev, "XCVR: ID set\n");
399 set_bit(ID, &dotg->inputs);
Jack Pham0fc12332012-11-19 13:14:22 -0800400 } else {
Manu Gautama4c3c1f2012-12-18 13:56:43 +0530401 dev_dbg(phy->dev, "XCVR: ID clear\n");
402 clear_bit(ID, &dotg->inputs);
Jack Pham0fc12332012-11-19 13:14:22 -0800403 }
Manu Gautam377821c2012-09-28 16:53:24 +0530404
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530405 if (ext_xceiv->bsv) {
Manu Gautama4c3c1f2012-12-18 13:56:43 +0530406 dev_dbg(phy->dev, "XCVR: BSV set\n");
407 set_bit(B_SESS_VLD, &dotg->inputs);
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530408 } else {
Manu Gautama4c3c1f2012-12-18 13:56:43 +0530409 dev_dbg(phy->dev, "XCVR: BSV clear\n");
410 clear_bit(B_SESS_VLD, &dotg->inputs);
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530411 }
Manu Gautam377821c2012-09-28 16:53:24 +0530412
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530413 if (!init) {
414 init = true;
415 complete(&dotg->dwc3_xcvr_vbus_init);
416 dev_dbg(phy->dev, "XCVR: BSV init complete\n");
417 return;
418 }
Manu Gautama4c3c1f2012-12-18 13:56:43 +0530419
420 schedule_work(&dotg->sm_work);
Manu Gautamb5067272012-07-02 09:53:41 +0530421 }
Manu Gautamb5067272012-07-02 09:53:41 +0530422}
423
424/**
425 * dwc3_set_ext_xceiv - bind/unbind external transceiver driver
426 * @otg: Pointer to the otg transceiver structure
427 * @ext_xceiv: Pointer to the external transceiver struccture
428 *
429 * Returns 0 on success
430 */
431int dwc3_set_ext_xceiv(struct usb_otg *otg, struct dwc3_ext_xceiv *ext_xceiv)
432{
433 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
434
435 dotg->ext_xceiv = ext_xceiv;
436 if (ext_xceiv)
437 ext_xceiv->notify_ext_events = dwc3_ext_event_notify;
438
439 return 0;
440}
441
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530442static void dwc3_otg_notify_host_mode(struct usb_otg *otg, int host_mode)
443{
444 struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg);
445
446 if (!dotg->psy) {
447 dev_err(otg->phy->dev, "no usb power supply registered\n");
448 return;
449 }
450
451 if (host_mode)
452 power_supply_set_scope(dotg->psy, POWER_SUPPLY_SCOPE_SYSTEM);
453 else
454 power_supply_set_scope(dotg->psy, POWER_SUPPLY_SCOPE_DEVICE);
455}
456
457static int dwc3_otg_set_power(struct usb_phy *phy, unsigned mA)
458{
459 static int power_supply_type;
460 struct dwc3_otg *dotg = container_of(phy->otg, struct dwc3_otg, otg);
461
462
Manu Gautam6c0ff032012-11-02 14:55:35 +0530463 if (!dotg->psy || !dotg->charger) {
464 dev_err(phy->dev, "no usb power supply/charger registered\n");
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530465 return 0;
466 }
467
Manu Gautam6c0ff032012-11-02 14:55:35 +0530468 if (dotg->charger->charging_disabled)
469 return 0;
470
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530471 if (dotg->charger->chg_type == DWC3_SDP_CHARGER)
472 power_supply_type = POWER_SUPPLY_TYPE_USB;
473 else if (dotg->charger->chg_type == DWC3_CDP_CHARGER)
474 power_supply_type = POWER_SUPPLY_TYPE_USB_CDP;
475 else if (dotg->charger->chg_type == DWC3_DCP_CHARGER)
476 power_supply_type = POWER_SUPPLY_TYPE_USB_DCP;
477 else
478 power_supply_type = POWER_SUPPLY_TYPE_BATTERY;
479
480 power_supply_set_supply_type(dotg->psy, power_supply_type);
481
482 if (dotg->charger->max_power == mA)
483 return 0;
484
485 dev_info(phy->dev, "Avail curr from USB = %u\n", mA);
486
487 if (dotg->charger->max_power <= 2 && mA > 2) {
488 /* Enable charging */
489 if (power_supply_set_online(dotg->psy, true))
490 goto psy_error;
491 if (power_supply_set_current_limit(dotg->psy, 1000*mA))
492 goto psy_error;
493 } else if (dotg->charger->max_power > 0 && (mA == 0 || mA == 2)) {
494 /* Disable charging */
495 if (power_supply_set_online(dotg->psy, false))
496 goto psy_error;
497 /* Set max current limit */
498 if (power_supply_set_current_limit(dotg->psy, 0))
499 goto psy_error;
500 }
501
502 power_supply_changed(dotg->psy);
503 dotg->charger->max_power = mA;
504 return 0;
505
506psy_error:
507 dev_dbg(phy->dev, "power supply error when setting property\n");
508 return -ENXIO;
509}
510
Manu Gautam8c642812012-06-07 10:35:10 +0530511/* IRQs which OTG driver is interested in handling */
512#define DWC3_OEVT_MASK (DWC3_OEVTEN_OTGCONIDSTSCHNGEVNT | \
513 DWC3_OEVTEN_OTGBDEVVBUSCHNGEVNT)
514
515/**
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200516 * dwc3_otg_interrupt - interrupt handler for dwc3 otg events.
517 * @_dotg: Pointer to out controller context structure
518 *
519 * Returns IRQ_HANDLED on success otherwise IRQ_NONE.
520 */
521static irqreturn_t dwc3_otg_interrupt(int irq, void *_dotg)
522{
523 struct dwc3_otg *dotg = (struct dwc3_otg *)_dotg;
Manu Gautam8c642812012-06-07 10:35:10 +0530524 u32 osts, oevt_reg;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200525 int ret = IRQ_NONE;
526 int handled_irqs = 0;
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +0530527 struct usb_phy *phy = dotg->otg.phy;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200528
529 oevt_reg = dwc3_readl(dotg->regs, DWC3_OEVT);
530
Manu Gautam8c642812012-06-07 10:35:10 +0530531 if (!(oevt_reg & DWC3_OEVT_MASK))
532 return IRQ_NONE;
533
534 osts = dwc3_readl(dotg->regs, DWC3_OSTS);
535
536 if ((oevt_reg & DWC3_OEVTEN_OTGCONIDSTSCHNGEVNT) ||
537 (oevt_reg & DWC3_OEVTEN_OTGBDEVVBUSCHNGEVNT)) {
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200538 /*
Manu Gautam8c642812012-06-07 10:35:10 +0530539 * ID sts has changed, set inputs later, in the workqueue
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200540 * function, switch from A to B or from B to A.
541 */
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200542
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +0530543 if (oevt_reg & DWC3_OEVTEN_OTGCONIDSTSCHNGEVNT) {
544 if (osts & DWC3_OTG_OSTS_CONIDSTS) {
545 dev_dbg(phy->dev, "ID set\n");
546 set_bit(ID, &dotg->inputs);
547 } else {
548 dev_dbg(phy->dev, "ID clear\n");
549 clear_bit(ID, &dotg->inputs);
550 }
551 handled_irqs |= DWC3_OEVTEN_OTGCONIDSTSCHNGEVNT;
552 }
Manu Gautam8c642812012-06-07 10:35:10 +0530553
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +0530554 if (oevt_reg & DWC3_OEVTEN_OTGBDEVVBUSCHNGEVNT) {
555 if (osts & DWC3_OTG_OSTS_BSESVALID) {
556 dev_dbg(phy->dev, "BSV set\n");
557 set_bit(B_SESS_VLD, &dotg->inputs);
558 } else {
559 dev_dbg(phy->dev, "BSV clear\n");
560 clear_bit(B_SESS_VLD, &dotg->inputs);
561 }
562 handled_irqs |= DWC3_OEVTEN_OTGBDEVVBUSCHNGEVNT;
563 }
Manu Gautam8c642812012-06-07 10:35:10 +0530564
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200565 schedule_work(&dotg->sm_work);
566
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200567 ret = IRQ_HANDLED;
Manu Gautam8c642812012-06-07 10:35:10 +0530568
569 /* Clear the interrupts we handled */
570 dwc3_writel(dotg->regs, DWC3_OEVT, handled_irqs);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200571 }
572
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200573 return ret;
574}
575
576/**
Manu Gautam8c642812012-06-07 10:35:10 +0530577 * dwc3_otg_init_sm - initialize OTG statemachine input
578 * @dotg: Pointer to the dwc3_otg structure
579 *
580 */
581void dwc3_otg_init_sm(struct dwc3_otg *dotg)
582{
583 u32 osts = dwc3_readl(dotg->regs, DWC3_OSTS);
584 struct usb_phy *phy = dotg->otg.phy;
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530585 struct dwc3_ext_xceiv *ext_xceiv;
586 int ret;
Manu Gautam8c642812012-06-07 10:35:10 +0530587
588 dev_dbg(phy->dev, "Initialize OTG inputs, osts: 0x%x\n", osts);
589
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530590 /*
591 * VBUS initial state is reported after PMIC
592 * driver initialization. Wait for it.
593 */
594 ret = wait_for_completion_timeout(&dotg->dwc3_xcvr_vbus_init, HZ * 5);
595 if (!ret)
596 dev_err(phy->dev, "%s: completion timeout\n", __func__);
Manu Gautam8c642812012-06-07 10:35:10 +0530597
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530598 ext_xceiv = dotg->ext_xceiv;
599 dwc3_otg_reset(dotg);
600 if (ext_xceiv && !ext_xceiv->otg_capability) {
601 if (osts & DWC3_OTG_OSTS_CONIDSTS)
602 set_bit(ID, &dotg->inputs);
603 else
604 clear_bit(ID, &dotg->inputs);
605
606 if (osts & DWC3_OTG_OSTS_BSESVALID)
607 set_bit(B_SESS_VLD, &dotg->inputs);
608 else
609 clear_bit(B_SESS_VLD, &dotg->inputs);
610 }
Manu Gautam8c642812012-06-07 10:35:10 +0530611}
612
613/**
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200614 * dwc3_otg_sm_work - workqueue function.
615 *
616 * @w: Pointer to the dwc3 otg workqueue
617 *
618 * NOTE: After any change in phy->state,
619 * we must reschdule the state machine.
620 */
621static void dwc3_otg_sm_work(struct work_struct *w)
622{
623 struct dwc3_otg *dotg = container_of(w, struct dwc3_otg, sm_work);
624 struct usb_phy *phy = dotg->otg.phy;
Manu Gautam8c642812012-06-07 10:35:10 +0530625 struct dwc3_charger *charger = dotg->charger;
626 bool work = 0;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200627
Manu Gautamb5067272012-07-02 09:53:41 +0530628 pm_runtime_resume(phy->dev);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200629 dev_dbg(phy->dev, "%s state\n", otg_state_string(phy->state));
630
631 /* Check OTG state */
632 switch (phy->state) {
633 case OTG_STATE_UNDEFINED:
Manu Gautam8c642812012-06-07 10:35:10 +0530634 dwc3_otg_init_sm(dotg);
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530635 if (!dotg->psy) {
636 dotg->psy = power_supply_get_by_name("usb");
637
638 if (!dotg->psy)
639 dev_err(phy->dev,
640 "couldn't get usb power supply\n");
641 }
642
Manu Gautam8c642812012-06-07 10:35:10 +0530643 /* Switch to A or B-Device according to ID / BSV */
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530644 if (!test_bit(ID, &dotg->inputs)) {
Manu Gautam8c642812012-06-07 10:35:10 +0530645 dev_dbg(phy->dev, "!id\n");
646 phy->state = OTG_STATE_A_IDLE;
647 work = 1;
648 } else if (test_bit(B_SESS_VLD, &dotg->inputs)) {
649 dev_dbg(phy->dev, "b_sess_vld\n");
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200650 phy->state = OTG_STATE_B_IDLE;
Manu Gautam8c642812012-06-07 10:35:10 +0530651 work = 1;
652 } else {
653 phy->state = OTG_STATE_B_IDLE;
Manu Gautamb5067272012-07-02 09:53:41 +0530654 dev_dbg(phy->dev, "No device, trying to suspend\n");
655 pm_runtime_put_sync(phy->dev);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200656 }
657 break;
Manu Gautam8c642812012-06-07 10:35:10 +0530658
659 case OTG_STATE_B_IDLE:
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530660 if (!test_bit(ID, &dotg->inputs)) {
Manu Gautam8c642812012-06-07 10:35:10 +0530661 dev_dbg(phy->dev, "!id\n");
662 phy->state = OTG_STATE_A_IDLE;
663 work = 1;
664 if (charger) {
665 if (charger->chg_type == DWC3_INVALID_CHARGER)
666 charger->start_detection(dotg->charger,
667 false);
668 else
669 charger->chg_type =
670 DWC3_INVALID_CHARGER;
671 }
672 } else if (test_bit(B_SESS_VLD, &dotg->inputs)) {
673 dev_dbg(phy->dev, "b_sess_vld\n");
674 if (charger) {
675 /* Has charger been detected? If no detect it */
676 switch (charger->chg_type) {
677 case DWC3_DCP_CHARGER:
Manu Gautamb5067272012-07-02 09:53:41 +0530678 dev_dbg(phy->dev, "lpm, DCP charger\n");
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530679 dwc3_otg_set_power(phy,
680 DWC3_IDEV_CHG_MAX);
Manu Gautamb5067272012-07-02 09:53:41 +0530681 pm_runtime_put_sync(phy->dev);
Manu Gautam8c642812012-06-07 10:35:10 +0530682 break;
683 case DWC3_CDP_CHARGER:
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530684 dwc3_otg_set_power(phy,
685 DWC3_IDEV_CHG_MAX);
Manu Gautam8c642812012-06-07 10:35:10 +0530686 dwc3_otg_start_peripheral(&dotg->otg,
687 1);
688 phy->state = OTG_STATE_B_PERIPHERAL;
689 work = 1;
690 break;
691 case DWC3_SDP_CHARGER:
692 dwc3_otg_start_peripheral(&dotg->otg,
693 1);
694 phy->state = OTG_STATE_B_PERIPHERAL;
695 work = 1;
696 break;
697 default:
698 dev_dbg(phy->dev, "chg_det started\n");
699 charger->start_detection(charger, true);
700 break;
701 }
702 } else {
703 /* no charger registered, start peripheral */
704 if (dwc3_otg_start_peripheral(&dotg->otg, 1)) {
705 /*
706 * Probably set_peripheral not called
707 * yet. We will re-try as soon as it
708 * will be called
709 */
Manu Gautamb5067272012-07-02 09:53:41 +0530710 dev_err(phy->dev, "enter lpm as\n"
Manu Gautam8c642812012-06-07 10:35:10 +0530711 "unable to start B-device\n");
712 phy->state = OTG_STATE_UNDEFINED;
Manu Gautamb5067272012-07-02 09:53:41 +0530713 pm_runtime_put_sync(phy->dev);
Manu Gautam8c642812012-06-07 10:35:10 +0530714 return;
715 }
716 }
717 } else {
Manu Gautam98013c22012-11-20 17:42:42 +0530718 if (charger)
719 charger->start_detection(dotg->charger, false);
720
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530721 dwc3_otg_set_power(phy, 0);
Manu Gautamb5067272012-07-02 09:53:41 +0530722 dev_dbg(phy->dev, "No device, trying to suspend\n");
723 pm_runtime_put_sync(phy->dev);
Manu Gautam8c642812012-06-07 10:35:10 +0530724 }
725 break;
726
727 case OTG_STATE_B_PERIPHERAL:
728 if (!test_bit(B_SESS_VLD, &dotg->inputs) ||
729 !test_bit(ID, &dotg->inputs)) {
730 dev_dbg(phy->dev, "!id || !bsv\n");
731 dwc3_otg_start_peripheral(&dotg->otg, 0);
732 phy->state = OTG_STATE_B_IDLE;
733 if (charger)
734 charger->chg_type = DWC3_INVALID_CHARGER;
735 work = 1;
736 }
737 break;
738
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200739 case OTG_STATE_A_IDLE:
740 /* Switch to A-Device*/
Manu Gautam8c642812012-06-07 10:35:10 +0530741 if (test_bit(ID, &dotg->inputs)) {
742 dev_dbg(phy->dev, "id\n");
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200743 phy->state = OTG_STATE_B_IDLE;
Manu Gautam8c642812012-06-07 10:35:10 +0530744 work = 1;
745 } else {
Manu Gautama4c3c1f2012-12-18 13:56:43 +0530746 phy->state = OTG_STATE_A_HOST;
747 if (dwc3_otg_start_host(&dotg->otg, 1)) {
Manu Gautam8c642812012-06-07 10:35:10 +0530748 /*
749 * Probably set_host was not called yet.
750 * We will re-try as soon as it will be called
751 */
Manu Gautamb5067272012-07-02 09:53:41 +0530752 dev_dbg(phy->dev, "enter lpm as\n"
Manu Gautam8c642812012-06-07 10:35:10 +0530753 "unable to start A-device\n");
754 phy->state = OTG_STATE_UNDEFINED;
Manu Gautamb5067272012-07-02 09:53:41 +0530755 pm_runtime_put_sync(phy->dev);
Manu Gautam8c642812012-06-07 10:35:10 +0530756 return;
757 }
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200758 }
759 break;
Manu Gautam8c642812012-06-07 10:35:10 +0530760
761 case OTG_STATE_A_HOST:
762 if (test_bit(ID, &dotg->inputs)) {
763 dev_dbg(phy->dev, "id\n");
764 dwc3_otg_start_host(&dotg->otg, 0);
765 phy->state = OTG_STATE_B_IDLE;
766 work = 1;
767 }
768 break;
769
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200770 default:
771 dev_err(phy->dev, "%s: invalid otg-state\n", __func__);
772
773 }
Manu Gautam8c642812012-06-07 10:35:10 +0530774
775 if (work)
776 schedule_work(&dotg->sm_work);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200777}
778
779
780/**
781 * dwc3_otg_reset - reset dwc3 otg registers.
782 *
783 * @w: Pointer to the dwc3 otg workqueue
784 */
785static void dwc3_otg_reset(struct dwc3_otg *dotg)
786{
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530787 static int once;
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530788 struct dwc3_ext_xceiv *ext_xceiv = dotg->ext_xceiv;
789
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200790 /*
791 * OCFG[2] - OTG-Version = 1
792 * OCFG[1] - HNPCap = 0
793 * OCFG[0] - SRPCap = 0
794 */
795 dwc3_writel(dotg->regs, DWC3_OCFG, 0x4);
796
797 /*
798 * OCTL[6] - PeriMode = 1
799 * OCTL[5] - PrtPwrCtl = 0
800 * OCTL[4] - HNPReq = 0
801 * OCTL[3] - SesReq = 0
802 * OCTL[2] - TermSelDLPulse = 0
803 * OCTL[1] - DevSetHNPEn = 0
804 * OCTL[0] - HstSetHNPEn = 0
805 */
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530806 if (!once) {
807 dwc3_writel(dotg->regs, DWC3_OCTL, 0x40);
808 once++;
809 }
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200810
811 /* Clear all otg events (interrupts) indications */
812 dwc3_writel(dotg->regs, DWC3_OEVT, 0xFFFF);
813
Manu Gautam8c642812012-06-07 10:35:10 +0530814 /* Enable ID/BSV StsChngEn event*/
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530815 if (ext_xceiv && !ext_xceiv->otg_capability)
816 dwc3_writel(dotg->regs, DWC3_OEVTEN,
817 DWC3_OEVTEN_OTGCONIDSTSCHNGEVNT |
818 DWC3_OEVTEN_OTGBDEVVBUSCHNGEVNT);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200819}
820
821/**
822 * dwc3_otg_init - Initializes otg related registers
823 * @dwc: Pointer to out controller context structure
824 *
825 * Returns 0 on success otherwise negative errno.
826 */
827int dwc3_otg_init(struct dwc3 *dwc)
828{
829 u32 reg;
830 int ret = 0;
831 struct dwc3_otg *dotg;
832
833 dev_dbg(dwc->dev, "dwc3_otg_init\n");
834
835 /*
836 * GHWPARAMS6[10] bit is SRPSupport.
837 * This bit also reflects DWC_USB3_EN_OTG
838 */
839 reg = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
840 if (!(reg & DWC3_GHWPARAMS6_SRP_SUPPORT)) {
841 /*
842 * No OTG support in the HW core.
843 * We return 0 to indicate no error, since this is acceptable
844 * situation, just continue probe the dwc3 driver without otg.
845 */
846 dev_dbg(dwc->dev, "dwc3_otg address space is not supported\n");
847 return 0;
848 }
849
850 /* Allocate and init otg instance */
851 dotg = kzalloc(sizeof(struct dwc3_otg), GFP_KERNEL);
852 if (!dotg) {
853 dev_err(dwc->dev, "unable to allocate dwc3_otg\n");
854 return -ENOMEM;
855 }
856
Manu Gautam17206c22012-06-21 10:17:53 +0530857 /* DWC3 has separate IRQ line for OTG events (ID/BSV etc.) */
858 dotg->irq = platform_get_irq_byname(to_platform_device(dwc->dev),
859 "otg_irq");
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200860 if (dotg->irq < 0) {
Manu Gautam17206c22012-06-21 10:17:53 +0530861 dev_err(dwc->dev, "%s: missing OTG IRQ\n", __func__);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200862 ret = -ENODEV;
863 goto err1;
864 }
865
866 dotg->regs = dwc->regs;
867
868 dotg->otg.set_peripheral = dwc3_otg_set_peripheral;
869 dotg->otg.set_host = dwc3_otg_set_host;
870
871 /* This reference is used by dwc3 modules for checking otg existance */
872 dwc->dotg = dotg;
873
874 dotg->otg.phy = kzalloc(sizeof(struct usb_phy), GFP_KERNEL);
875 if (!dotg->otg.phy) {
876 dev_err(dwc->dev, "unable to allocate dwc3_otg.phy\n");
877 ret = -ENOMEM;
878 goto err1;
879 }
880
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530881 dotg->dwc = dwc;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200882 dotg->otg.phy->otg = &dotg->otg;
883 dotg->otg.phy->dev = dwc->dev;
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530884 dotg->otg.phy->set_power = dwc3_otg_set_power;
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +0530885 dotg->otg.phy->set_suspend = dwc3_otg_set_suspend;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200886
887 ret = usb_set_transceiver(dotg->otg.phy);
888 if (ret) {
889 dev_err(dotg->otg.phy->dev,
890 "%s: failed to set transceiver, already exists\n",
891 __func__);
892 goto err2;
893 }
894
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200895 dotg->otg.phy->state = OTG_STATE_UNDEFINED;
896
Vijayavardhan Vennapusa42eeea32012-10-22 17:56:11 +0530897 init_completion(&dotg->dwc3_xcvr_vbus_init);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200898 INIT_WORK(&dotg->sm_work, dwc3_otg_sm_work);
899
900 ret = request_irq(dotg->irq, dwc3_otg_interrupt, IRQF_SHARED,
901 "dwc3_otg", dotg);
902 if (ret) {
903 dev_err(dotg->otg.phy->dev, "failed to request irq #%d --> %d\n",
904 dotg->irq, ret);
905 goto err3;
906 }
907
Manu Gautamb5067272012-07-02 09:53:41 +0530908 pm_runtime_get(dwc->dev);
909
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200910 return 0;
911
912err3:
913 cancel_work_sync(&dotg->sm_work);
914 usb_set_transceiver(NULL);
915err2:
916 kfree(dotg->otg.phy);
917err1:
918 dwc->dotg = NULL;
919 kfree(dotg);
920
921 return ret;
922}
923
924/**
925 * dwc3_otg_exit
926 * @dwc: Pointer to out controller context structure
927 *
928 * Returns 0 on success otherwise negative errno.
929 */
930void dwc3_otg_exit(struct dwc3 *dwc)
931{
932 struct dwc3_otg *dotg = dwc->dotg;
933
934 /* dotg is null when GHWPARAMS6[10]=SRPSupport=0, see dwc3_otg_init */
935 if (dotg) {
Manu Gautam8c642812012-06-07 10:35:10 +0530936 if (dotg->charger)
937 dotg->charger->start_detection(dotg->charger, false);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200938 cancel_work_sync(&dotg->sm_work);
939 usb_set_transceiver(NULL);
Manu Gautamb5067272012-07-02 09:53:41 +0530940 pm_runtime_put(dwc->dev);
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200941 free_irq(dotg->irq, dotg);
942 kfree(dotg->otg.phy);
943 kfree(dotg);
944 dwc->dotg = NULL;
945 }
946}