blob: 7a6765ba7bd4cf04c9ad77aa1121996c19051e34 [file] [log] [blame]
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002 *
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 *
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/platform_device.h>
18#include <linux/dma-mapping.h>
Manu Gautamb5067272012-07-02 09:53:41 +053019#include <linux/pm_runtime.h>
Manu Gautam377821c2012-09-28 16:53:24 +053020#include <linux/ratelimit.h>
Manu Gautamb5067272012-07-02 09:53:41 +053021#include <linux/interrupt.h>
Ido Shayevitzef72ddd2012-03-28 18:55:55 +020022#include <linux/ioport.h>
Manu Gautam1742db22012-06-19 13:33:24 +053023#include <linux/clk.h>
Ido Shayevitzef72ddd2012-03-28 18:55:55 +020024#include <linux/io.h>
25#include <linux/module.h>
26#include <linux/types.h>
Ido Shayevitzef72ddd2012-03-28 18:55:55 +020027#include <linux/delay.h>
28#include <linux/of.h>
Vijayavardhan Vennapusa8eb68732013-03-26 13:05:38 +053029#include <linux/of_platform.h>
Ido Shayevitz9fb83452012-04-01 17:45:58 +030030#include <linux/list.h>
Manu Gautamb5067272012-07-02 09:53:41 +053031#include <linux/debugfs.h>
32#include <linux/uaccess.h>
Ido Shayevitz9fb83452012-04-01 17:45:58 +030033#include <linux/usb/ch9.h>
34#include <linux/usb/gadget.h>
David Keitelad4a0282013-03-19 18:04:27 -070035#include <linux/qpnp-misc.h>
Ido Shayevitz9fb83452012-04-01 17:45:58 +030036#include <linux/usb/msm_hsusb.h>
Manu Gautam60e01352012-05-29 09:00:34 +053037#include <linux/regulator/consumer.h>
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +053038#include <linux/power_supply.h>
Jack Pham0fc12332012-11-19 13:14:22 -080039#include <linux/qpnp/qpnp-adc.h>
Manu Gautam60e01352012-05-29 09:00:34 +053040
41#include <mach/rpm-regulator.h>
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +053042#include <mach/rpm-regulator-smd.h>
Manu Gautam2617deb2012-08-31 17:50:06 -070043#include <mach/msm_bus.h>
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +053044#include <mach/clk.h>
Ido Shayevitz9fb83452012-04-01 17:45:58 +030045
Manu Gautam8c642812012-06-07 10:35:10 +053046#include "dwc3_otg.h"
Ido Shayevitz9fb83452012-04-01 17:45:58 +030047#include "core.h"
48#include "gadget.h"
49
Jack Pham0fc12332012-11-19 13:14:22 -080050/* ADC threshold values */
51static int adc_low_threshold = 700;
52module_param(adc_low_threshold, int, S_IRUGO | S_IWUSR);
53MODULE_PARM_DESC(adc_low_threshold, "ADC ID Low voltage threshold");
54
55static int adc_high_threshold = 950;
56module_param(adc_high_threshold, int, S_IRUGO | S_IWUSR);
57MODULE_PARM_DESC(adc_high_threshold, "ADC ID High voltage threshold");
58
59static int adc_meas_interval = ADC_MEAS1_INTERVAL_1S;
60module_param(adc_meas_interval, int, S_IRUGO | S_IWUSR);
61MODULE_PARM_DESC(adc_meas_interval, "ADC ID polling period");
62
Vijayavardhan Vennapusa26a49602012-12-18 13:51:45 +053063static int override_phy_init;
64module_param(override_phy_init, int, S_IRUGO|S_IWUSR);
65MODULE_PARM_DESC(override_phy_init, "Override HSPHY Init Seq");
66
Jack Pham9b4606b2013-04-02 17:32:25 -070067/* Enable Proprietary charger detection */
68static bool prop_chg_detect;
69module_param(prop_chg_detect, bool, S_IRUGO | S_IWUSR);
70MODULE_PARM_DESC(prop_chg_detect, "Enable Proprietary charger detection");
71
Ido Shayevitz9fb83452012-04-01 17:45:58 +030072/**
73 * USB DBM Hardware registers.
74 *
75 */
Shimrit Malichia00d7322012-08-05 13:56:28 +030076#define DBM_BASE 0x000F8000
77#define DBM_EP_CFG(n) (DBM_BASE + (0x00 + 4 * (n)))
78#define DBM_DATA_FIFO(n) (DBM_BASE + (0x10 + 4 * (n)))
79#define DBM_DATA_FIFO_SIZE(n) (DBM_BASE + (0x20 + 4 * (n)))
80#define DBM_DATA_FIFO_EN (DBM_BASE + (0x30))
81#define DBM_GEVNTADR (DBM_BASE + (0x34))
82#define DBM_GEVNTSIZ (DBM_BASE + (0x38))
83#define DBM_DBG_CNFG (DBM_BASE + (0x3C))
84#define DBM_HW_TRB0_EP(n) (DBM_BASE + (0x40 + 4 * (n)))
85#define DBM_HW_TRB1_EP(n) (DBM_BASE + (0x50 + 4 * (n)))
86#define DBM_HW_TRB2_EP(n) (DBM_BASE + (0x60 + 4 * (n)))
87#define DBM_HW_TRB3_EP(n) (DBM_BASE + (0x70 + 4 * (n)))
88#define DBM_PIPE_CFG (DBM_BASE + (0x80))
89#define DBM_SOFT_RESET (DBM_BASE + (0x84))
90#define DBM_GEN_CFG (DBM_BASE + (0x88))
Ido Shayevitz9fb83452012-04-01 17:45:58 +030091
92/**
93 * USB DBM Hardware registers bitmask.
94 *
95 */
96/* DBM_EP_CFG */
Shimrit Malichia00d7322012-08-05 13:56:28 +030097#define DBM_EN_EP 0x00000001
98#define USB3_EPNUM 0x0000003E
Ido Shayevitz9fb83452012-04-01 17:45:58 +030099#define DBM_BAM_PIPE_NUM 0x000000C0
100#define DBM_PRODUCER 0x00000100
101#define DBM_DISABLE_WB 0x00000200
102#define DBM_INT_RAM_ACC 0x00000400
103
104/* DBM_DATA_FIFO_SIZE */
105#define DBM_DATA_FIFO_SIZE_MASK 0x0000ffff
106
107/* DBM_GEVNTSIZ */
108#define DBM_GEVNTSIZ_MASK 0x0000ffff
109
110/* DBM_DBG_CNFG */
111#define DBM_ENABLE_IOC_MASK 0x0000000f
112
113/* DBM_SOFT_RESET */
114#define DBM_SFT_RST_EP0 0x00000001
115#define DBM_SFT_RST_EP1 0x00000002
116#define DBM_SFT_RST_EP2 0x00000004
117#define DBM_SFT_RST_EP3 0x00000008
Shimrit Malichia00d7322012-08-05 13:56:28 +0300118#define DBM_SFT_RST_EPS_MASK 0x0000000F
119#define DBM_SFT_RST_MASK 0x80000000
120#define DBM_EN_MASK 0x00000002
Ido Shayevitzef72ddd2012-03-28 18:55:55 +0200121
122#define DBM_MAX_EPS 4
123
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300124/* DBM TRB configurations */
125#define DBM_TRB_BIT 0x80000000
126#define DBM_TRB_DATA_SRC 0x40000000
127#define DBM_TRB_DMA 0x20000000
128#define DBM_TRB_EP_NUM(ep) (ep<<24)
Shimrit Malichia00d7322012-08-05 13:56:28 +0300129
Manu Gautam8c642812012-06-07 10:35:10 +0530130/**
131 * USB QSCRATCH Hardware registers
132 *
133 */
134#define QSCRATCH_REG_OFFSET (0x000F8800)
Shimrit Malichia00d7322012-08-05 13:56:28 +0300135#define QSCRATCH_GENERAL_CFG (QSCRATCH_REG_OFFSET + 0x08)
Manu Gautambd0e5782012-08-30 10:39:01 -0700136#define HS_PHY_CTRL_REG (QSCRATCH_REG_OFFSET + 0x10)
Vijayavardhan Vennapusa26a49602012-12-18 13:51:45 +0530137#define PARAMETER_OVERRIDE_X_REG (QSCRATCH_REG_OFFSET + 0x14)
Manu Gautam8c642812012-06-07 10:35:10 +0530138#define CHARGING_DET_CTRL_REG (QSCRATCH_REG_OFFSET + 0x18)
139#define CHARGING_DET_OUTPUT_REG (QSCRATCH_REG_OFFSET + 0x1C)
140#define ALT_INTERRUPT_EN_REG (QSCRATCH_REG_OFFSET + 0x20)
141#define HS_PHY_IRQ_STAT_REG (QSCRATCH_REG_OFFSET + 0x24)
Manu Gautamd4108b72012-12-14 17:35:18 +0530142#define CGCTL_REG (QSCRATCH_REG_OFFSET + 0x28)
Manu Gautambd0e5782012-08-30 10:39:01 -0700143#define SS_PHY_CTRL_REG (QSCRATCH_REG_OFFSET + 0x30)
Vijayavardhan Vennapusa164b0f42013-01-17 19:33:53 +0530144#define SS_PHY_PARAM_CTRL_1 (QSCRATCH_REG_OFFSET + 0x34)
145#define SS_PHY_PARAM_CTRL_2 (QSCRATCH_REG_OFFSET + 0x38)
Vijayavardhan Vennapusad81aed32012-12-05 17:30:40 +0530146#define SS_CR_PROTOCOL_DATA_IN_REG (QSCRATCH_REG_OFFSET + 0x3C)
147#define SS_CR_PROTOCOL_DATA_OUT_REG (QSCRATCH_REG_OFFSET + 0x40)
148#define SS_CR_PROTOCOL_CAP_ADDR_REG (QSCRATCH_REG_OFFSET + 0x44)
149#define SS_CR_PROTOCOL_CAP_DATA_REG (QSCRATCH_REG_OFFSET + 0x48)
150#define SS_CR_PROTOCOL_READ_REG (QSCRATCH_REG_OFFSET + 0x4C)
151#define SS_CR_PROTOCOL_WRITE_REG (QSCRATCH_REG_OFFSET + 0x50)
Manu Gautam8c642812012-06-07 10:35:10 +0530152
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300153struct dwc3_msm_req_complete {
154 struct list_head list_item;
155 struct usb_request *req;
156 void (*orig_complete)(struct usb_ep *ep,
157 struct usb_request *req);
158};
159
Ido Shayevitzef72ddd2012-03-28 18:55:55 +0200160struct dwc3_msm {
Ido Shayevitzef72ddd2012-03-28 18:55:55 +0200161 struct device *dev;
162 void __iomem *base;
163 u32 resource_size;
164 int dbm_num_eps;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300165 u8 ep_num_mapping[DBM_MAX_EPS];
166 const struct usb_ep_ops *original_ep_ops[DWC3_ENDPOINTS_NUM];
167 struct list_head req_complete_list;
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +0530168 struct clk *xo_clk;
Manu Gautam3e9ad352012-08-16 14:44:47 -0700169 struct clk *ref_clk;
Manu Gautam1742db22012-06-19 13:33:24 +0530170 struct clk *core_clk;
Manu Gautam3e9ad352012-08-16 14:44:47 -0700171 struct clk *iface_clk;
172 struct clk *sleep_clk;
173 struct clk *hsphy_sleep_clk;
Jack Pham22698b82013-02-13 17:45:06 -0800174 struct clk *utmi_clk;
Manu Gautam60e01352012-05-29 09:00:34 +0530175 struct regulator *hsusb_3p3;
176 struct regulator *hsusb_1p8;
177 struct regulator *hsusb_vddcx;
178 struct regulator *ssusb_1p8;
179 struct regulator *ssusb_vddcx;
Manu Gautamb5067272012-07-02 09:53:41 +0530180 struct dwc3_ext_xceiv ext_xceiv;
181 bool resume_pending;
182 atomic_t pm_suspended;
183 atomic_t in_lpm;
Manu Gautam377821c2012-09-28 16:53:24 +0530184 int hs_phy_irq;
Vijayavardhan Vennapusa26a49602012-12-18 13:51:45 +0530185 int hsphy_init_seq;
Manu Gautam377821c2012-09-28 16:53:24 +0530186 bool lpm_irq_seen;
Manu Gautamb5067272012-07-02 09:53:41 +0530187 struct delayed_work resume_work;
Manu Gautam6eb13e32013-02-01 15:19:15 +0530188 struct work_struct restart_usb_work;
Manu Gautamb5067272012-07-02 09:53:41 +0530189 struct wake_lock wlock;
Manu Gautam8c642812012-06-07 10:35:10 +0530190 struct dwc3_charger charger;
191 struct usb_phy *otg_xceiv;
192 struct delayed_work chg_work;
193 enum usb_chg_state chg_state;
Jack Pham0cca9412013-03-08 13:22:42 -0800194 int pmic_id_irq;
195 struct work_struct id_work;
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800196 struct qpnp_adc_tm_btm_param adc_param;
Jack Pham0fc12332012-11-19 13:14:22 -0800197 struct delayed_work init_adc_work;
198 bool id_adc_detect;
Manu Gautam8c642812012-06-07 10:35:10 +0530199 u8 dcd_retries;
Manu Gautam2617deb2012-08-31 17:50:06 -0700200 u32 bus_perf_client;
201 struct msm_bus_scale_pdata *bus_scale_table;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +0530202 struct power_supply usb_psy;
Jack Pham9354c6a2012-12-20 19:19:32 -0800203 struct power_supply *ext_vbus_psy;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +0530204 unsigned int online;
205 unsigned int host_mode;
206 unsigned int current_max;
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +0530207 unsigned int vdd_no_vol_level;
208 unsigned int vdd_low_vol_level;
209 unsigned int vdd_high_vol_level;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +0530210 bool vbus_active;
Jack Phamfadd6432012-12-07 19:03:41 -0800211 bool ext_inuse;
Jack Phamf12b7e12012-12-28 14:27:26 -0800212 enum dwc3_id_state id_state;
Manu Gautam60e01352012-05-29 09:00:34 +0530213};
214
215#define USB_HSPHY_3P3_VOL_MIN 3050000 /* uV */
216#define USB_HSPHY_3P3_VOL_MAX 3300000 /* uV */
217#define USB_HSPHY_3P3_HPM_LOAD 16000 /* uA */
218
219#define USB_HSPHY_1P8_VOL_MIN 1800000 /* uV */
220#define USB_HSPHY_1P8_VOL_MAX 1800000 /* uV */
221#define USB_HSPHY_1P8_HPM_LOAD 19000 /* uA */
222
223#define USB_SSPHY_1P8_VOL_MIN 1800000 /* uV */
224#define USB_SSPHY_1P8_VOL_MAX 1800000 /* uV */
225#define USB_SSPHY_1P8_HPM_LOAD 23000 /* uA */
226
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300227static struct dwc3_msm *context;
228
Jack Phamfadd6432012-12-07 19:03:41 -0800229static struct usb_ext_notification *usb_ext;
230
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300231/**
232 *
233 * Read register with debug info.
234 *
235 * @base - DWC3 base virtual address.
236 * @offset - register offset.
237 *
238 * @return u32
239 */
240static inline u32 dwc3_msm_read_reg(void *base, u32 offset)
241{
242 u32 val = ioread32(base + offset);
243 return val;
244}
245
246/**
247 * Read register masked field with debug info.
248 *
249 * @base - DWC3 base virtual address.
250 * @offset - register offset.
251 * @mask - register bitmask.
252 *
253 * @return u32
254 */
255static inline u32 dwc3_msm_read_reg_field(void *base,
256 u32 offset,
257 const u32 mask)
258{
259 u32 shift = find_first_bit((void *)&mask, 32);
260 u32 val = ioread32(base + offset);
261 val &= mask; /* clear other bits */
262 val >>= shift;
263 return val;
264}
265
266/**
267 *
268 * Write register with debug info.
269 *
270 * @base - DWC3 base virtual address.
271 * @offset - register offset.
272 * @val - value to write.
273 *
274 */
275static inline void dwc3_msm_write_reg(void *base, u32 offset, u32 val)
276{
277 iowrite32(val, base + offset);
278}
279
280/**
281 * Write register masked field with debug info.
282 *
283 * @base - DWC3 base virtual address.
284 * @offset - register offset.
285 * @mask - register bitmask.
286 * @val - value to write.
287 *
288 */
289static inline void dwc3_msm_write_reg_field(void *base, u32 offset,
290 const u32 mask, u32 val)
291{
292 u32 shift = find_first_bit((void *)&mask, 32);
293 u32 tmp = ioread32(base + offset);
294
295 tmp &= ~mask; /* clear written bits */
296 val = tmp | (val << shift);
297 iowrite32(val, base + offset);
298}
299
300/**
Manu Gautam8c642812012-06-07 10:35:10 +0530301 * Write register and read back masked value to confirm it is written
302 *
303 * @base - DWC3 base virtual address.
304 * @offset - register offset.
305 * @mask - register bitmask specifying what should be updated
306 * @val - value to write.
307 *
308 */
309static inline void dwc3_msm_write_readback(void *base, u32 offset,
310 const u32 mask, u32 val)
311{
312 u32 write_val, tmp = ioread32(base + offset);
313
314 tmp &= ~mask; /* retain other bits */
315 write_val = tmp | val;
316
317 iowrite32(write_val, base + offset);
318
319 /* Read back to see if val was written */
320 tmp = ioread32(base + offset);
321 tmp &= mask; /* clear other bits */
322
323 if (tmp != val)
324 dev_err(context->dev, "%s: write: %x to QSCRATCH: %x FAILED\n",
325 __func__, val, offset);
326}
327
328/**
Vijayavardhan Vennapusad81aed32012-12-05 17:30:40 +0530329 *
330 * Write SSPHY register with debug info.
331 *
332 * @base - DWC3 base virtual address.
333 * @addr - SSPHY address to write.
334 * @val - value to write.
335 *
336 */
337static void dwc3_msm_ssusb_write_phycreg(void *base, u32 addr, u32 val)
338{
339 iowrite32(addr, base + SS_CR_PROTOCOL_DATA_IN_REG);
340 iowrite32(0x1, base + SS_CR_PROTOCOL_CAP_ADDR_REG);
341 while (ioread32(base + SS_CR_PROTOCOL_CAP_ADDR_REG))
342 cpu_relax();
343
344 iowrite32(val, base + SS_CR_PROTOCOL_DATA_IN_REG);
345 iowrite32(0x1, base + SS_CR_PROTOCOL_CAP_DATA_REG);
346 while (ioread32(base + SS_CR_PROTOCOL_CAP_DATA_REG))
347 cpu_relax();
348
349 iowrite32(0x1, base + SS_CR_PROTOCOL_WRITE_REG);
350 while (ioread32(base + SS_CR_PROTOCOL_WRITE_REG))
351 cpu_relax();
352}
353
354/**
355 *
356 * Read SSPHY register with debug info.
357 *
358 * @base - DWC3 base virtual address.
359 * @addr - SSPHY address to read.
360 *
361 */
362static u32 dwc3_msm_ssusb_read_phycreg(void *base, u32 addr)
363{
364 iowrite32(addr, base + SS_CR_PROTOCOL_DATA_IN_REG);
365 iowrite32(0x1, base + SS_CR_PROTOCOL_CAP_ADDR_REG);
366 while (ioread32(base + SS_CR_PROTOCOL_CAP_ADDR_REG))
367 cpu_relax();
368
369 iowrite32(0x1, base + SS_CR_PROTOCOL_READ_REG);
370 while (ioread32(base + SS_CR_PROTOCOL_READ_REG))
371 cpu_relax();
372
373 return ioread32(base + SS_CR_PROTOCOL_DATA_OUT_REG);
374}
375
376/**
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300377 * Return DBM EP number according to usb endpoint number.
378 *
379 */
380static int dwc3_msm_find_matching_dbm_ep(u8 usb_ep)
381{
382 int i;
383
384 for (i = 0; i < context->dbm_num_eps; i++)
385 if (context->ep_num_mapping[i] == usb_ep)
386 return i;
387
388 return -ENODEV; /* Not found */
389}
390
391/**
392 * Return number of configured DBM endpoints.
393 *
394 */
395static int dwc3_msm_configured_dbm_ep_num(void)
396{
397 int i;
398 int count = 0;
399
400 for (i = 0; i < context->dbm_num_eps; i++)
401 if (context->ep_num_mapping[i])
402 count++;
403
404 return count;
405}
406
407/**
408 * Configure the DBM with the USB3 core event buffer.
409 * This function is called by the SNPS UDC upon initialization.
410 *
411 * @addr - address of the event buffer.
412 * @size - size of the event buffer.
413 *
414 */
415static int dwc3_msm_event_buffer_config(u32 addr, u16 size)
416{
417 dev_dbg(context->dev, "%s\n", __func__);
418
419 dwc3_msm_write_reg(context->base, DBM_GEVNTADR, addr);
420 dwc3_msm_write_reg_field(context->base, DBM_GEVNTSIZ,
421 DBM_GEVNTSIZ_MASK, size);
422
423 return 0;
424}
425
426/**
427 * Reset the DBM registers upon initialization.
428 *
429 */
Shimrit Malichia00d7322012-08-05 13:56:28 +0300430static int dwc3_msm_dbm_soft_reset(int enter_reset)
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300431{
432 dev_dbg(context->dev, "%s\n", __func__);
Shimrit Malichia00d7322012-08-05 13:56:28 +0300433 if (enter_reset) {
434 dev_dbg(context->dev, "enter DBM reset\n");
435 dwc3_msm_write_reg_field(context->base, DBM_SOFT_RESET,
436 DBM_SFT_RST_MASK, 1);
437 } else {
438 dev_dbg(context->dev, "exit DBM reset\n");
439 dwc3_msm_write_reg_field(context->base, DBM_SOFT_RESET,
440 DBM_SFT_RST_MASK, 0);
441 /*enable DBM*/
442 dwc3_msm_write_reg_field(context->base, QSCRATCH_GENERAL_CFG,
443 DBM_EN_MASK, 0x1);
444 }
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300445
446 return 0;
447}
448
449/**
450 * Soft reset specific DBM ep.
451 * This function is called by the function driver upon events
452 * such as transfer aborting, USB re-enumeration and USB
453 * disconnection.
454 *
455 * @dbm_ep - DBM ep number.
456 * @enter_reset - should we enter a reset state or get out of it.
457 *
458 */
459static int dwc3_msm_dbm_ep_soft_reset(u8 dbm_ep, bool enter_reset)
460{
461 dev_dbg(context->dev, "%s\n", __func__);
462
463 if (dbm_ep >= context->dbm_num_eps) {
464 dev_err(context->dev,
465 "%s: Invalid DBM ep index\n", __func__);
466 return -ENODEV;
467 }
468
469 if (enter_reset) {
470 dwc3_msm_write_reg_field(context->base, DBM_SOFT_RESET,
Shimrit Malichia00d7322012-08-05 13:56:28 +0300471 DBM_SFT_RST_EPS_MASK & 1 << dbm_ep, 1);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300472 } else {
473 dwc3_msm_write_reg_field(context->base, DBM_SOFT_RESET,
Shimrit Malichia00d7322012-08-05 13:56:28 +0300474 DBM_SFT_RST_EPS_MASK & 1 << dbm_ep, 0);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300475 }
476
477 return 0;
478}
479
480/**
481 * Configure a USB DBM ep to work in BAM mode.
482 *
483 *
484 * @usb_ep - USB physical EP number.
485 * @producer - producer/consumer.
486 * @disable_wb - disable write back to system memory.
487 * @internal_mem - use internal USB memory for data fifo.
488 * @ioc - enable interrupt on completion.
489 *
490 * @return int - DBM ep number.
491 */
492static int dwc3_msm_dbm_ep_config(u8 usb_ep, u8 bam_pipe,
493 bool producer, bool disable_wb,
494 bool internal_mem, bool ioc)
495{
496 u8 dbm_ep;
Shimrit Malichia00d7322012-08-05 13:56:28 +0300497 u32 ep_cfg;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300498
499 dev_dbg(context->dev, "%s\n", __func__);
500
Shimrit Malichia00d7322012-08-05 13:56:28 +0300501 dbm_ep = dwc3_msm_find_matching_dbm_ep(usb_ep);
502
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300503 if (dbm_ep < 0) {
Shimrit Malichia00d7322012-08-05 13:56:28 +0300504 dev_err(context->dev,
505 "%s: Invalid usb ep index\n", __func__);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300506 return -ENODEV;
507 }
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300508 /* First, reset the dbm endpoint */
Shimrit Malichia00d7322012-08-05 13:56:28 +0300509 dwc3_msm_dbm_ep_soft_reset(dbm_ep, 0);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300510
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300511 /* Set ioc bit for dbm_ep if needed */
512 dwc3_msm_write_reg_field(context->base, DBM_DBG_CNFG,
Shimrit Malichia00d7322012-08-05 13:56:28 +0300513 DBM_ENABLE_IOC_MASK & 1 << dbm_ep, ioc ? 1 : 0);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300514
Shimrit Malichia00d7322012-08-05 13:56:28 +0300515 ep_cfg = (producer ? DBM_PRODUCER : 0) |
516 (disable_wb ? DBM_DISABLE_WB : 0) |
517 (internal_mem ? DBM_INT_RAM_ACC : 0);
518
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300519 dwc3_msm_write_reg_field(context->base, DBM_EP_CFG(dbm_ep),
Shimrit Malichia00d7322012-08-05 13:56:28 +0300520 DBM_PRODUCER | DBM_DISABLE_WB | DBM_INT_RAM_ACC, ep_cfg >> 8);
521
522 dwc3_msm_write_reg_field(context->base, DBM_EP_CFG(dbm_ep), USB3_EPNUM,
523 usb_ep);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300524 dwc3_msm_write_reg_field(context->base, DBM_EP_CFG(dbm_ep),
525 DBM_BAM_PIPE_NUM, bam_pipe);
Shimrit Malichia00d7322012-08-05 13:56:28 +0300526 dwc3_msm_write_reg_field(context->base, DBM_PIPE_CFG, 0x000000ff,
527 0xe4);
528 dwc3_msm_write_reg_field(context->base, DBM_EP_CFG(dbm_ep), DBM_EN_EP,
529 1);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300530
531 return dbm_ep;
532}
533
534/**
535 * Configure a USB DBM ep to work in normal mode.
536 *
537 * @usb_ep - USB ep number.
538 *
539 */
540static int dwc3_msm_dbm_ep_unconfig(u8 usb_ep)
541{
542 u8 dbm_ep;
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +0530543 u32 data;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300544
545 dev_dbg(context->dev, "%s\n", __func__);
546
547 dbm_ep = dwc3_msm_find_matching_dbm_ep(usb_ep);
548
549 if (dbm_ep < 0) {
550 dev_err(context->dev,
551 "%s: Invalid usb ep index\n", __func__);
552 return -ENODEV;
553 }
554
555 context->ep_num_mapping[dbm_ep] = 0;
556
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +0530557 data = dwc3_msm_read_reg(context->base, DBM_EP_CFG(dbm_ep));
558 data &= (~0x1);
559 dwc3_msm_write_reg(context->base, DBM_EP_CFG(dbm_ep), data);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300560
561 /* Reset the dbm endpoint */
562 dwc3_msm_dbm_ep_soft_reset(dbm_ep, true);
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +0530563 /*
564 * 10 usec delay is required before deasserting DBM endpoint reset
565 * according to hardware programming guide.
566 */
567 udelay(10);
568 dwc3_msm_dbm_ep_soft_reset(dbm_ep, false);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300569
570 return 0;
571}
572
573/**
574 * Configure the DBM with the BAM's data fifo.
575 * This function is called by the USB BAM Driver
576 * upon initialization.
577 *
578 * @ep - pointer to usb endpoint.
579 * @addr - address of data fifo.
580 * @size - size of data fifo.
581 *
582 */
Shimrit Malichia00d7322012-08-05 13:56:28 +0300583int msm_data_fifo_config(struct usb_ep *ep, u32 addr, u32 size, u8 dst_pipe_idx)
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300584{
585 u8 dbm_ep;
586 struct dwc3_ep *dep = to_dwc3_ep(ep);
Shimrit Malichia00d7322012-08-05 13:56:28 +0300587 u8 bam_pipe = dst_pipe_idx;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300588
589 dev_dbg(context->dev, "%s\n", __func__);
590
Shimrit Malichia00d7322012-08-05 13:56:28 +0300591 dbm_ep = bam_pipe;
592 context->ep_num_mapping[dbm_ep] = dep->number;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300593
594 dwc3_msm_write_reg(context->base, DBM_DATA_FIFO(dbm_ep), addr);
595 dwc3_msm_write_reg_field(context->base, DBM_DATA_FIFO_SIZE(dbm_ep),
596 DBM_DATA_FIFO_SIZE_MASK, size);
597
598 return 0;
599}
600
601/**
602* Cleanups for msm endpoint on request complete.
603*
604* Also call original request complete.
605*
606* @usb_ep - pointer to usb_ep instance.
607* @request - pointer to usb_request instance.
608*
609* @return int - 0 on success, negetive on error.
610*/
611static void dwc3_msm_req_complete_func(struct usb_ep *ep,
612 struct usb_request *request)
613{
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300614 struct dwc3_ep *dep = to_dwc3_ep(ep);
615 struct dwc3_msm_req_complete *req_complete = NULL;
616
617 /* Find original request complete function and remove it from list */
618 list_for_each_entry(req_complete,
619 &context->req_complete_list,
620 list_item) {
621 if (req_complete->req == request)
622 break;
623 }
624 if (!req_complete || req_complete->req != request) {
625 dev_err(dep->dwc->dev, "%s: could not find the request\n",
626 __func__);
627 return;
628 }
629 list_del(&req_complete->list_item);
630
631 /*
632 * Release another one TRB to the pool since DBM queue took 2 TRBs
633 * (normal and link), and the dwc3/gadget.c :: dwc3_gadget_giveback
634 * released only one.
635 */
Manu Gautam55d34222012-12-19 16:49:47 +0530636 dep->busy_slot++;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300637
638 /* Unconfigure dbm ep */
639 dwc3_msm_dbm_ep_unconfig(dep->number);
640
641 /*
642 * If this is the last endpoint we unconfigured, than reset also
643 * the event buffers.
644 */
645 if (0 == dwc3_msm_configured_dbm_ep_num())
646 dwc3_msm_event_buffer_config(0, 0);
647
648 /*
649 * Call original complete function, notice that dwc->lock is already
650 * taken by the caller of this function (dwc3_gadget_giveback()).
651 */
652 request->complete = req_complete->orig_complete;
Shimrit Malichia00d7322012-08-05 13:56:28 +0300653 if (request->complete)
654 request->complete(ep, request);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300655
656 kfree(req_complete);
657}
658
659/**
660* Helper function.
661* See the header of the dwc3_msm_ep_queue function.
662*
663* @dwc3_ep - pointer to dwc3_ep instance.
664* @req - pointer to dwc3_request instance.
665*
666* @return int - 0 on success, negetive on error.
667*/
668static int __dwc3_msm_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
669{
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300670 struct dwc3_trb *trb;
671 struct dwc3_trb *trb_link;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300672 struct dwc3_gadget_ep_cmd_params params;
673 u32 cmd;
674 int ret = 0;
675
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300676 /* We push the request to the dep->req_queued list to indicate that
677 * this request is issued with start transfer. The request will be out
678 * from this list in 2 cases. The first is that the transfer will be
679 * completed (not if the transfer is endless using a circular TRBs with
680 * with link TRB). The second case is an option to do stop stransfer,
681 * this can be initiated by the function driver when calling dequeue.
682 */
683 req->queued = true;
684 list_add_tail(&req->list, &dep->req_queued);
685
686 /* First, prepare a normal TRB, point to the fake buffer */
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300687 trb = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK];
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300688 dep->free_slot++;
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300689 memset(trb, 0, sizeof(*trb));
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300690
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300691 req->trb = trb;
Shimrit Malichia00d7322012-08-05 13:56:28 +0300692 trb->bph = DBM_TRB_BIT | DBM_TRB_DMA | DBM_TRB_EP_NUM(dep->number);
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300693 trb->size = DWC3_TRB_SIZE_LENGTH(req->request.length);
694 trb->ctrl = DWC3_TRBCTL_NORMAL | DWC3_TRB_CTRL_HWO | DWC3_TRB_CTRL_CHN;
Shimrit Malichia00d7322012-08-05 13:56:28 +0300695 req->trb_dma = dwc3_trb_dma_offset(dep, trb);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300696
697 /* Second, prepare a Link TRB that points to the first TRB*/
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300698 trb_link = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK];
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300699 dep->free_slot++;
Shimrit Malichia00d7322012-08-05 13:56:28 +0300700 memset(trb_link, 0, sizeof *trb_link);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300701
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300702 trb_link->bpl = lower_32_bits(req->trb_dma);
Shimrit Malichia00d7322012-08-05 13:56:28 +0300703 trb_link->bph = DBM_TRB_BIT |
Ido Shayevitzfa65a582012-06-06 14:39:54 +0300704 DBM_TRB_DMA | DBM_TRB_EP_NUM(dep->number);
705 trb_link->size = 0;
706 trb_link->ctrl = DWC3_TRBCTL_LINK_TRB | DWC3_TRB_CTRL_HWO;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300707
708 /*
709 * Now start the transfer
710 */
711 memset(&params, 0, sizeof(params));
Shimrit Malichia00d7322012-08-05 13:56:28 +0300712 params.param0 = 0; /* TDAddr High */
713 params.param1 = lower_32_bits(req->trb_dma); /* DAddr Low */
714
Manu Gautam5b2bf9a2012-10-18 10:52:50 +0530715 /* DBM requires IOC to be set */
716 cmd = DWC3_DEPCMD_STARTTRANSFER | DWC3_DEPCMD_CMDIOC;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300717 ret = dwc3_send_gadget_ep_cmd(dep->dwc, dep->number, cmd, &params);
718 if (ret < 0) {
719 dev_dbg(dep->dwc->dev,
720 "%s: failed to send STARTTRANSFER command\n",
721 __func__);
722
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300723 list_del(&req->list);
724 return ret;
725 }
Manu Gautam4a51a062012-12-07 11:24:39 +0530726 dep->flags |= DWC3_EP_BUSY;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300727
728 return ret;
729}
730
731/**
732* Queue a usb request to the DBM endpoint.
733* This function should be called after the endpoint
734* was enabled by the ep_enable.
735*
736* This function prepares special structure of TRBs which
737* is familier with the DBM HW, so it will possible to use
738* this endpoint in DBM mode.
739*
740* The TRBs prepared by this function, is one normal TRB
741* which point to a fake buffer, followed by a link TRB
742* that points to the first TRB.
743*
744* The API of this function follow the regular API of
745* usb_ep_queue (see usb_ep_ops in include/linuk/usb/gadget.h).
746*
747* @usb_ep - pointer to usb_ep instance.
748* @request - pointer to usb_request instance.
749* @gfp_flags - possible flags.
750*
751* @return int - 0 on success, negetive on error.
752*/
753static int dwc3_msm_ep_queue(struct usb_ep *ep,
754 struct usb_request *request, gfp_t gfp_flags)
755{
756 struct dwc3_request *req = to_dwc3_request(request);
757 struct dwc3_ep *dep = to_dwc3_ep(ep);
758 struct dwc3 *dwc = dep->dwc;
759 struct dwc3_msm_req_complete *req_complete;
760 unsigned long flags;
761 int ret = 0;
762 u8 bam_pipe;
763 bool producer;
764 bool disable_wb;
765 bool internal_mem;
766 bool ioc;
Shimrit Malichia00d7322012-08-05 13:56:28 +0300767 u8 speed;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300768
769 if (!(request->udc_priv & MSM_SPS_MODE)) {
770 /* Not SPS mode, call original queue */
771 dev_vdbg(dwc->dev, "%s: not sps mode, use regular queue\n",
772 __func__);
773
774 return (context->original_ep_ops[dep->number])->queue(ep,
775 request,
776 gfp_flags);
777 }
778
779 if (!dep->endpoint.desc) {
780 dev_err(dwc->dev,
781 "%s: trying to queue request %p to disabled ep %s\n",
782 __func__, request, ep->name);
783 return -EPERM;
784 }
785
786 if (dep->number == 0 || dep->number == 1) {
787 dev_err(dwc->dev,
788 "%s: trying to queue dbm request %p to control ep %s\n",
789 __func__, request, ep->name);
790 return -EPERM;
791 }
792
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300793
Manu Gautam4a51a062012-12-07 11:24:39 +0530794 if (dep->busy_slot != dep->free_slot || !list_empty(&dep->request_list)
795 || !list_empty(&dep->req_queued)) {
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300796 dev_err(dwc->dev,
797 "%s: trying to queue dbm request %p tp ep %s\n",
798 __func__, request, ep->name);
799 return -EPERM;
Manu Gautam4a51a062012-12-07 11:24:39 +0530800 } else {
801 dep->busy_slot = 0;
802 dep->free_slot = 0;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300803 }
804
805 /*
806 * Override req->complete function, but before doing that,
807 * store it's original pointer in the req_complete_list.
808 */
809 req_complete = kzalloc(sizeof(*req_complete), GFP_KERNEL);
810 if (!req_complete) {
811 dev_err(dep->dwc->dev, "%s: not enough memory\n", __func__);
812 return -ENOMEM;
813 }
814 req_complete->req = request;
815 req_complete->orig_complete = request->complete;
816 list_add_tail(&req_complete->list_item, &context->req_complete_list);
817 request->complete = dwc3_msm_req_complete_func;
818
819 /*
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300820 * Configure the DBM endpoint
821 */
Shimrit Malichia00d7322012-08-05 13:56:28 +0300822 bam_pipe = request->udc_priv & MSM_PIPE_ID_MASK;
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300823 producer = ((request->udc_priv & MSM_PRODUCER) ? true : false);
824 disable_wb = ((request->udc_priv & MSM_DISABLE_WB) ? true : false);
825 internal_mem = ((request->udc_priv & MSM_INTERNAL_MEM) ? true : false);
826 ioc = ((request->udc_priv & MSM_ETD_IOC) ? true : false);
827
828 ret = dwc3_msm_dbm_ep_config(dep->number,
829 bam_pipe, producer,
830 disable_wb, internal_mem, ioc);
831 if (ret < 0) {
832 dev_err(context->dev,
833 "error %d after calling dwc3_msm_dbm_ep_config\n",
834 ret);
835 return ret;
836 }
837
838 dev_vdbg(dwc->dev, "%s: queing request %p to ep %s length %d\n",
839 __func__, request, ep->name, request->length);
840
841 /*
842 * We must obtain the lock of the dwc3 core driver,
843 * including disabling interrupts, so we will be sure
844 * that we are the only ones that configure the HW device
845 * core and ensure that we queuing the request will finish
846 * as soon as possible so we will release back the lock.
847 */
848 spin_lock_irqsave(&dwc->lock, flags);
849 ret = __dwc3_msm_ep_queue(dep, req);
850 spin_unlock_irqrestore(&dwc->lock, flags);
851 if (ret < 0) {
852 dev_err(context->dev,
853 "error %d after calling __dwc3_msm_ep_queue\n", ret);
854 return ret;
855 }
856
Shimrit Malichia00d7322012-08-05 13:56:28 +0300857 speed = dwc3_readl(dwc->regs, DWC3_DSTS) & DWC3_DSTS_CONNECTSPD;
858 dwc3_msm_write_reg(context->base, DBM_GEN_CFG, speed >> 2);
859
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300860 return 0;
861}
862
863/**
864 * Configure MSM endpoint.
865 * This function do specific configurations
866 * to an endpoint which need specific implementaion
867 * in the MSM architecture.
868 *
869 * This function should be called by usb function/class
870 * layer which need a support from the specific MSM HW
871 * which wrap the USB3 core. (like DBM specific endpoints)
872 *
873 * @ep - a pointer to some usb_ep instance
874 *
875 * @return int - 0 on success, negetive on error.
876 */
877int msm_ep_config(struct usb_ep *ep)
878{
879 struct dwc3_ep *dep = to_dwc3_ep(ep);
880 struct usb_ep_ops *new_ep_ops;
881
Manu Gautama302f612012-12-18 17:33:06 +0530882 dwc3_msm_event_buffer_config(dwc3_msm_read_reg(context->base,
883 DWC3_GEVNTADRLO(0)),
884 dwc3_msm_read_reg(context->base, DWC3_GEVNTSIZ(0)));
885
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300886 /* Save original ep ops for future restore*/
887 if (context->original_ep_ops[dep->number]) {
888 dev_err(context->dev,
889 "ep [%s,%d] already configured as msm endpoint\n",
890 ep->name, dep->number);
891 return -EPERM;
892 }
893 context->original_ep_ops[dep->number] = ep->ops;
894
895 /* Set new usb ops as we like */
896 new_ep_ops = kzalloc(sizeof(struct usb_ep_ops), GFP_KERNEL);
897 if (!new_ep_ops) {
898 dev_err(context->dev,
899 "%s: unable to allocate mem for new usb ep ops\n",
900 __func__);
901 return -ENOMEM;
902 }
903 (*new_ep_ops) = (*ep->ops);
904 new_ep_ops->queue = dwc3_msm_ep_queue;
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +0530905 new_ep_ops->disable = ep->ops->disable;
906
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300907 ep->ops = new_ep_ops;
908
909 /*
910 * Do HERE more usb endpoint configurations
911 * which are specific to MSM.
912 */
913
914 return 0;
915}
916EXPORT_SYMBOL(msm_ep_config);
917
918/**
919 * Un-configure MSM endpoint.
920 * Tear down configurations done in the
921 * dwc3_msm_ep_config function.
922 *
923 * @ep - a pointer to some usb_ep instance
924 *
925 * @return int - 0 on success, negetive on error.
926 */
927int msm_ep_unconfig(struct usb_ep *ep)
928{
929 struct dwc3_ep *dep = to_dwc3_ep(ep);
930 struct usb_ep_ops *old_ep_ops;
931
932 /* Restore original ep ops */
933 if (!context->original_ep_ops[dep->number]) {
934 dev_err(context->dev,
935 "ep [%s,%d] was not configured as msm endpoint\n",
936 ep->name, dep->number);
937 return -EINVAL;
938 }
939 old_ep_ops = (struct usb_ep_ops *)ep->ops;
940 ep->ops = context->original_ep_ops[dep->number];
941 context->original_ep_ops[dep->number] = NULL;
942 kfree(old_ep_ops);
943
944 /*
945 * Do HERE more usb endpoint un-configurations
946 * which are specific to MSM.
947 */
948
949 return 0;
950}
951EXPORT_SYMBOL(msm_ep_unconfig);
952
Manu Gautam6eb13e32013-02-01 15:19:15 +0530953static void dwc3_restart_usb_work(struct work_struct *w)
954{
955 struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm,
956 restart_usb_work);
957
958 dev_dbg(mdwc->dev, "%s\n", __func__);
959
960 if (atomic_read(&mdwc->in_lpm) || !mdwc->otg_xceiv) {
961 dev_err(mdwc->dev, "%s failed!!!\n", __func__);
962 return;
963 }
964
965 if (!mdwc->ext_xceiv.bsv) {
966 dev_dbg(mdwc->dev, "%s bailing out in disconnect\n", __func__);
967 return;
968 }
969
970 /* Reset active USB connection */
971 mdwc->ext_xceiv.bsv = false;
972 queue_delayed_work(system_nrt_wq, &mdwc->resume_work, 0);
973 /* Make sure disconnect is processed before sending connect */
974 flush_delayed_work(&mdwc->resume_work);
975
976 mdwc->ext_xceiv.bsv = true;
977 queue_delayed_work(system_nrt_wq, &mdwc->resume_work, 0);
978}
979
980/**
981 * Reset USB peripheral connection
982 * Inform OTG for Vbus LOW followed by Vbus HIGH notification.
983 * This performs full hardware reset and re-initialization which
984 * might be required by some DBM client driver during uninit/cleanup.
985 */
986void msm_dwc3_restart_usb_session(void)
987{
988 struct dwc3_msm *mdwc = context;
989
990 dev_dbg(mdwc->dev, "%s\n", __func__);
991 queue_work(system_nrt_wq, &mdwc->restart_usb_work);
992
993 return;
994}
995EXPORT_SYMBOL(msm_dwc3_restart_usb_session);
996
Jack Phamfadd6432012-12-07 19:03:41 -0800997/**
998 * msm_register_usb_ext_notification: register for event notification
999 * @info: pointer to client usb_ext_notification structure. May be NULL.
1000 *
1001 * @return int - 0 on success, negative on error
1002 */
1003int msm_register_usb_ext_notification(struct usb_ext_notification *info)
1004{
1005 pr_debug("%s usb_ext: %p\n", __func__, info);
1006
1007 if (info) {
1008 if (usb_ext) {
1009 pr_err("%s: already registered\n", __func__);
1010 return -EEXIST;
1011 }
1012
1013 if (!info->notify) {
1014 pr_err("%s: notify is NULL\n", __func__);
1015 return -EINVAL;
1016 }
1017 }
1018
1019 usb_ext = info;
1020 return 0;
1021}
1022EXPORT_SYMBOL(msm_register_usb_ext_notification);
1023
Manu Gautam60e01352012-05-29 09:00:34 +05301024/* HSPHY */
1025static int dwc3_hsusb_config_vddcx(int high)
1026{
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +05301027 int min_vol, max_vol, ret;
Manu Gautam60e01352012-05-29 09:00:34 +05301028 struct dwc3_msm *dwc = context;
Manu Gautam60e01352012-05-29 09:00:34 +05301029
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +05301030 max_vol = dwc->vdd_high_vol_level;
1031 min_vol = high ? dwc->vdd_low_vol_level : dwc->vdd_no_vol_level;
Manu Gautam60e01352012-05-29 09:00:34 +05301032 ret = regulator_set_voltage(dwc->hsusb_vddcx, min_vol, max_vol);
1033 if (ret) {
1034 dev_err(dwc->dev, "unable to set voltage for HSUSB_VDDCX\n");
1035 return ret;
1036 }
1037
1038 dev_dbg(dwc->dev, "%s: min_vol:%d max_vol:%d\n", __func__,
1039 min_vol, max_vol);
1040
1041 return ret;
1042}
1043
1044static int dwc3_hsusb_ldo_init(int init)
1045{
1046 int rc = 0;
1047 struct dwc3_msm *dwc = context;
1048
1049 if (!init) {
1050 regulator_set_voltage(dwc->hsusb_1p8, 0, USB_HSPHY_1P8_VOL_MAX);
1051 regulator_set_voltage(dwc->hsusb_3p3, 0, USB_HSPHY_3P3_VOL_MAX);
1052 return 0;
1053 }
1054
1055 dwc->hsusb_3p3 = devm_regulator_get(dwc->dev, "HSUSB_3p3");
1056 if (IS_ERR(dwc->hsusb_3p3)) {
1057 dev_err(dwc->dev, "unable to get hsusb 3p3\n");
1058 return PTR_ERR(dwc->hsusb_3p3);
1059 }
1060
1061 rc = regulator_set_voltage(dwc->hsusb_3p3,
1062 USB_HSPHY_3P3_VOL_MIN, USB_HSPHY_3P3_VOL_MAX);
1063 if (rc) {
1064 dev_err(dwc->dev, "unable to set voltage for hsusb 3p3\n");
1065 return rc;
1066 }
1067 dwc->hsusb_1p8 = devm_regulator_get(dwc->dev, "HSUSB_1p8");
1068 if (IS_ERR(dwc->hsusb_1p8)) {
1069 dev_err(dwc->dev, "unable to get hsusb 1p8\n");
1070 rc = PTR_ERR(dwc->hsusb_1p8);
1071 goto devote_3p3;
1072 }
1073 rc = regulator_set_voltage(dwc->hsusb_1p8,
1074 USB_HSPHY_1P8_VOL_MIN, USB_HSPHY_1P8_VOL_MAX);
1075 if (rc) {
1076 dev_err(dwc->dev, "unable to set voltage for hsusb 1p8\n");
1077 goto devote_3p3;
1078 }
1079
1080 return 0;
1081
1082devote_3p3:
1083 regulator_set_voltage(dwc->hsusb_3p3, 0, USB_HSPHY_3P3_VOL_MAX);
1084
1085 return rc;
1086}
1087
1088static int dwc3_hsusb_ldo_enable(int on)
1089{
1090 int rc = 0;
1091 struct dwc3_msm *dwc = context;
1092
1093 dev_dbg(dwc->dev, "reg (%s)\n", on ? "HPM" : "LPM");
1094
1095 if (!on)
1096 goto disable_regulators;
1097
1098
1099 rc = regulator_set_optimum_mode(dwc->hsusb_1p8, USB_HSPHY_1P8_HPM_LOAD);
1100 if (rc < 0) {
1101 dev_err(dwc->dev, "Unable to set HPM of regulator HSUSB_1p8\n");
1102 return rc;
1103 }
1104
1105 rc = regulator_enable(dwc->hsusb_1p8);
1106 if (rc) {
1107 dev_err(dwc->dev, "Unable to enable HSUSB_1p8\n");
1108 goto put_1p8_lpm;
1109 }
1110
1111 rc = regulator_set_optimum_mode(dwc->hsusb_3p3, USB_HSPHY_3P3_HPM_LOAD);
1112 if (rc < 0) {
1113 dev_err(dwc->dev, "Unable to set HPM of regulator HSUSB_3p3\n");
1114 goto disable_1p8;
1115 }
1116
1117 rc = regulator_enable(dwc->hsusb_3p3);
1118 if (rc) {
1119 dev_err(dwc->dev, "Unable to enable HSUSB_3p3\n");
1120 goto put_3p3_lpm;
1121 }
1122
1123 return 0;
1124
1125disable_regulators:
1126 rc = regulator_disable(dwc->hsusb_3p3);
1127 if (rc)
1128 dev_err(dwc->dev, "Unable to disable HSUSB_3p3\n");
1129
1130put_3p3_lpm:
1131 rc = regulator_set_optimum_mode(dwc->hsusb_3p3, 0);
1132 if (rc < 0)
1133 dev_err(dwc->dev, "Unable to set LPM of regulator HSUSB_3p3\n");
1134
1135disable_1p8:
1136 rc = regulator_disable(dwc->hsusb_1p8);
1137 if (rc)
1138 dev_err(dwc->dev, "Unable to disable HSUSB_1p8\n");
1139
1140put_1p8_lpm:
1141 rc = regulator_set_optimum_mode(dwc->hsusb_1p8, 0);
1142 if (rc < 0)
1143 dev_err(dwc->dev, "Unable to set LPM of regulator HSUSB_1p8\n");
1144
1145 return rc < 0 ? rc : 0;
1146}
1147
1148/* SSPHY */
1149static int dwc3_ssusb_config_vddcx(int high)
1150{
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +05301151 int min_vol, max_vol, ret;
Manu Gautam60e01352012-05-29 09:00:34 +05301152 struct dwc3_msm *dwc = context;
Manu Gautam60e01352012-05-29 09:00:34 +05301153
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +05301154 max_vol = dwc->vdd_high_vol_level;
1155 min_vol = high ? dwc->vdd_low_vol_level : dwc->vdd_no_vol_level;
Manu Gautam60e01352012-05-29 09:00:34 +05301156 ret = regulator_set_voltage(dwc->ssusb_vddcx, min_vol, max_vol);
1157 if (ret) {
1158 dev_err(dwc->dev, "unable to set voltage for SSUSB_VDDCX\n");
1159 return ret;
1160 }
1161
1162 dev_dbg(dwc->dev, "%s: min_vol:%d max_vol:%d\n", __func__,
1163 min_vol, max_vol);
1164 return ret;
1165}
1166
1167/* 3.3v supply not needed for SS PHY */
1168static int dwc3_ssusb_ldo_init(int init)
1169{
1170 int rc = 0;
1171 struct dwc3_msm *dwc = context;
1172
1173 if (!init) {
1174 regulator_set_voltage(dwc->ssusb_1p8, 0, USB_SSPHY_1P8_VOL_MAX);
1175 return 0;
1176 }
1177
1178 dwc->ssusb_1p8 = devm_regulator_get(dwc->dev, "SSUSB_1p8");
1179 if (IS_ERR(dwc->ssusb_1p8)) {
1180 dev_err(dwc->dev, "unable to get ssusb 1p8\n");
1181 return PTR_ERR(dwc->ssusb_1p8);
1182 }
1183 rc = regulator_set_voltage(dwc->ssusb_1p8,
1184 USB_SSPHY_1P8_VOL_MIN, USB_SSPHY_1P8_VOL_MAX);
1185 if (rc)
1186 dev_err(dwc->dev, "unable to set voltage for ssusb 1p8\n");
1187
1188 return rc;
1189}
1190
1191static int dwc3_ssusb_ldo_enable(int on)
1192{
1193 int rc = 0;
1194 struct dwc3_msm *dwc = context;
1195
1196 dev_dbg(context->dev, "reg (%s)\n", on ? "HPM" : "LPM");
1197
1198 if (!on)
1199 goto disable_regulators;
1200
1201
1202 rc = regulator_set_optimum_mode(dwc->ssusb_1p8, USB_SSPHY_1P8_HPM_LOAD);
1203 if (rc < 0) {
1204 dev_err(dwc->dev, "Unable to set HPM of SSUSB_1p8\n");
1205 return rc;
1206 }
1207
1208 rc = regulator_enable(dwc->ssusb_1p8);
1209 if (rc) {
1210 dev_err(dwc->dev, "Unable to enable SSUSB_1p8\n");
1211 goto put_1p8_lpm;
1212 }
1213
1214 return 0;
1215
1216disable_regulators:
1217 rc = regulator_disable(dwc->ssusb_1p8);
1218 if (rc)
1219 dev_err(dwc->dev, "Unable to disable SSUSB_1p8\n");
1220
1221put_1p8_lpm:
1222 rc = regulator_set_optimum_mode(dwc->ssusb_1p8, 0);
1223 if (rc < 0)
1224 dev_err(dwc->dev, "Unable to set LPM of SSUSB_1p8\n");
1225
1226 return rc < 0 ? rc : 0;
1227}
1228
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301229static int dwc3_msm_link_clk_reset(bool assert)
1230{
1231 int ret = 0;
1232 struct dwc3_msm *mdwc = context;
1233
1234 if (assert) {
1235 /* Using asynchronous block reset to the hardware */
1236 dev_dbg(mdwc->dev, "block_reset ASSERT\n");
1237 clk_disable_unprepare(mdwc->ref_clk);
1238 clk_disable_unprepare(mdwc->iface_clk);
1239 clk_disable_unprepare(mdwc->core_clk);
1240 ret = clk_reset(mdwc->core_clk, CLK_RESET_ASSERT);
1241 if (ret)
1242 dev_err(mdwc->dev, "dwc3 core_clk assert failed\n");
1243 } else {
1244 dev_dbg(mdwc->dev, "block_reset DEASSERT\n");
1245 ret = clk_reset(mdwc->core_clk, CLK_RESET_DEASSERT);
1246 ndelay(200);
1247 clk_prepare_enable(mdwc->core_clk);
1248 clk_prepare_enable(mdwc->ref_clk);
1249 clk_prepare_enable(mdwc->iface_clk);
1250 if (ret)
1251 dev_err(mdwc->dev, "dwc3 core_clk deassert failed\n");
1252 }
1253
1254 return ret;
1255}
1256
Vijayavardhan Vennapusa5b286322013-04-12 12:15:00 +05301257/* Reinitialize SSPHY parameters by overriding using QSCRATCH CR interface */
1258static void dwc3_msm_ss_phy_reg_init(struct dwc3_msm *msm)
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301259{
1260 u32 data = 0;
1261
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301262 /*
1263 * WORKAROUND: There is SSPHY suspend bug due to which USB enumerates
1264 * in HS mode instead of SS mode. Workaround it by asserting
1265 * LANE0.TX_ALT_BLOCK.EN_ALT_BUS to enable TX to use alt bus mode
1266 */
1267 data = dwc3_msm_ssusb_read_phycreg(msm->base, 0x102D);
1268 data |= (1 << 7);
1269 dwc3_msm_ssusb_write_phycreg(msm->base, 0x102D, data);
1270
1271 data = dwc3_msm_ssusb_read_phycreg(msm->base, 0x1010);
1272 data &= ~0xFF0;
Vijayavardhan Vennapusa164b0f42013-01-17 19:33:53 +05301273 data |= 0x20;
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301274 dwc3_msm_ssusb_write_phycreg(msm->base, 0x1010, data);
Vijayavardhan Vennapusa164b0f42013-01-17 19:33:53 +05301275
1276 /*
1277 * Fix RX Equalization setting as follows
1278 * LANE0.RX_OVRD_IN_HI. RX_EQ_EN set to 0
1279 * LANE0.RX_OVRD_IN_HI.RX_EQ_EN_OVRD set to 1
1280 * LANE0.RX_OVRD_IN_HI.RX_EQ set to 3
1281 * LANE0.RX_OVRD_IN_HI.RX_EQ_OVRD set to 1
1282 */
1283 data = dwc3_msm_ssusb_read_phycreg(msm->base, 0x1006);
1284 data &= ~(1 << 6);
1285 data |= (1 << 7);
1286 data &= ~(0x7 << 8);
1287 data |= (0x3 << 8);
1288 data |= (0x1 << 11);
1289 dwc3_msm_ssusb_write_phycreg(msm->base, 0x1006, data);
1290
1291 /*
1292 * Set EQ and TX launch amplitudes as follows
1293 * LANE0.TX_OVRD_DRV_LO.PREEMPH set to 22
1294 * LANE0.TX_OVRD_DRV_LO.AMPLITUDE set to 127
1295 * LANE0.TX_OVRD_DRV_LO.EN set to 1.
1296 */
1297 data = dwc3_msm_ssusb_read_phycreg(msm->base, 0x1002);
1298 data &= ~0x3F80;
1299 data |= (0x16 << 7);
1300 data &= ~0x7F;
1301 data |= (0x7F | (1 << 14));
1302 dwc3_msm_ssusb_write_phycreg(msm->base, 0x1002, data);
1303
1304 /* Set LOS_BIAS to 0x5 */
1305 dwc3_msm_write_readback(msm->base, SS_PHY_PARAM_CTRL_1, 0x07, 0x5);
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301306}
1307
Vijayavardhan Vennapusa5b286322013-04-12 12:15:00 +05301308/* Initialize QSCRATCH registers for HSPHY and SSPHY operation */
1309static void dwc3_msm_qscratch_reg_init(struct dwc3_msm *msm)
1310{
1311 /* SSPHY Initialization: Use ref_clk from pads and set its parameters */
1312 dwc3_msm_write_reg(msm->base, SS_PHY_CTRL_REG, 0x10210002);
1313 msleep(30);
1314 /* Assert SSPHY reset */
1315 dwc3_msm_write_reg(msm->base, SS_PHY_CTRL_REG, 0x10210082);
1316 usleep_range(2000, 2200);
1317 /* De-assert SSPHY reset - power and ref_clock must be ON */
1318 dwc3_msm_write_reg(msm->base, SS_PHY_CTRL_REG, 0x10210002);
1319 usleep_range(2000, 2200);
1320 /* Ref clock must be stable now, enable ref clock for HS mode */
1321 dwc3_msm_write_reg(msm->base, SS_PHY_CTRL_REG, 0x10210102);
1322 usleep_range(2000, 2200);
1323 /*
1324 * HSPHY Initialization: Enable UTMI clock and clamp enable HVINTs,
1325 * and disable RETENTION (power-on default is ENABLED)
1326 */
1327 dwc3_msm_write_reg(msm->base, HS_PHY_CTRL_REG, 0x5220bb2);
1328 usleep_range(2000, 2200);
1329 /* Disable (bypass) VBUS and ID filters */
1330 dwc3_msm_write_reg(msm->base, QSCRATCH_GENERAL_CFG, 0x78);
1331 /*
1332 * write HSPHY init value to QSCRATCH reg to set HSPHY parameters like
1333 * VBUS valid threshold, disconnect valid threshold, DC voltage level,
1334 * preempasis and rise/fall time.
1335 */
1336 if (override_phy_init)
1337 msm->hsphy_init_seq = override_phy_init;
1338 if (msm->hsphy_init_seq)
1339 dwc3_msm_write_readback(msm->base,
1340 PARAMETER_OVERRIDE_X_REG, 0x03FFFFFF,
1341 msm->hsphy_init_seq & 0x03FFFFFF);
1342
1343 /* Enable master clock for RAMs to allow BAM to access RAMs when
1344 * RAM clock gating is enabled via DWC3's GCTL. Otherwise, issues
1345 * are seen where RAM clocks get turned OFF in SS mode
1346 */
1347 dwc3_msm_write_reg(msm->base, CGCTL_REG,
1348 dwc3_msm_read_reg(msm->base, CGCTL_REG) | 0x18);
1349
1350 dwc3_msm_ss_phy_reg_init(msm);
1351}
1352
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +05301353static void dwc3_msm_block_reset(bool core_reset)
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301354{
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +05301355
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301356 struct dwc3_msm *mdwc = context;
1357 int ret = 0;
1358
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +05301359 if (core_reset) {
1360 ret = dwc3_msm_link_clk_reset(1);
1361 if (ret)
1362 return;
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301363
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +05301364 usleep_range(1000, 1200);
1365 ret = dwc3_msm_link_clk_reset(0);
1366 if (ret)
1367 return;
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301368
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +05301369 usleep_range(10000, 12000);
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301370
Vijayavardhan Vennapusaf7c01a42013-03-15 15:29:11 +05301371 /* Reinitialize QSCRATCH registers after block reset */
1372 dwc3_msm_qscratch_reg_init(mdwc);
1373 }
Manu Gautama302f612012-12-18 17:33:06 +05301374
1375 /* Reset the DBM */
1376 dwc3_msm_dbm_soft_reset(1);
1377 usleep_range(1000, 1200);
1378 dwc3_msm_dbm_soft_reset(0);
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05301379}
1380
Manu Gautam8c642812012-06-07 10:35:10 +05301381static void dwc3_chg_enable_secondary_det(struct dwc3_msm *mdwc)
1382{
1383 u32 chg_ctrl;
1384
1385 /* Turn off VDP_SRC */
1386 dwc3_msm_write_reg(mdwc->base, CHARGING_DET_CTRL_REG, 0x0);
1387 msleep(20);
1388
1389 /* Before proceeding make sure VDP_SRC is OFF */
1390 chg_ctrl = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_CTRL_REG);
1391 if (chg_ctrl & 0x3F)
1392 dev_err(mdwc->dev, "%s Unable to reset chg_det block: %x\n",
1393 __func__, chg_ctrl);
1394 /*
1395 * Configure DM as current source, DP as current sink
1396 * and enable battery charging comparators.
1397 */
1398 dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x34);
1399}
1400
Manu Gautama1e331d2013-02-07 14:55:05 +05301401static bool dwc3_chg_det_check_linestate(struct dwc3_msm *mdwc)
1402{
1403 u32 chg_det;
Jack Pham9b4606b2013-04-02 17:32:25 -07001404
1405 if (!prop_chg_detect)
1406 return false;
Manu Gautama1e331d2013-02-07 14:55:05 +05301407
1408 chg_det = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_OUTPUT_REG);
Jack Pham9b4606b2013-04-02 17:32:25 -07001409 return chg_det & (3 << 8);
Manu Gautama1e331d2013-02-07 14:55:05 +05301410}
1411
Manu Gautam8c642812012-06-07 10:35:10 +05301412static bool dwc3_chg_det_check_output(struct dwc3_msm *mdwc)
1413{
1414 u32 chg_det;
1415 bool ret = false;
1416
1417 chg_det = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_OUTPUT_REG);
1418 ret = chg_det & 1;
1419
1420 return ret;
1421}
1422
1423static void dwc3_chg_enable_primary_det(struct dwc3_msm *mdwc)
1424{
1425 /*
1426 * Configure DP as current source, DM as current sink
1427 * and enable battery charging comparators.
1428 */
1429 dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x30);
1430}
1431
1432static inline bool dwc3_chg_check_dcd(struct dwc3_msm *mdwc)
1433{
1434 u32 chg_state;
1435 bool ret = false;
1436
1437 chg_state = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_OUTPUT_REG);
1438 ret = chg_state & 2;
1439
1440 return ret;
1441}
1442
1443static inline void dwc3_chg_disable_dcd(struct dwc3_msm *mdwc)
1444{
1445 dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x0);
1446}
1447
1448static inline void dwc3_chg_enable_dcd(struct dwc3_msm *mdwc)
1449{
1450 /* Data contact detection enable, DCDENB */
1451 dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x2);
1452}
1453
1454static void dwc3_chg_block_reset(struct dwc3_msm *mdwc)
1455{
1456 u32 chg_ctrl;
1457
1458 /* Clear charger detecting control bits */
1459 dwc3_msm_write_reg(mdwc->base, CHARGING_DET_CTRL_REG, 0x0);
1460
1461 /* Clear alt interrupt latch and enable bits */
1462 dwc3_msm_write_reg(mdwc->base, HS_PHY_IRQ_STAT_REG, 0xFFF);
1463 dwc3_msm_write_reg(mdwc->base, ALT_INTERRUPT_EN_REG, 0x0);
1464
1465 udelay(100);
1466
1467 /* Before proceeding make sure charger block is RESET */
1468 chg_ctrl = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_CTRL_REG);
1469 if (chg_ctrl & 0x3F)
1470 dev_err(mdwc->dev, "%s Unable to reset chg_det block: %x\n",
1471 __func__, chg_ctrl);
1472}
1473
1474static const char *chg_to_string(enum dwc3_chg_type chg_type)
1475{
1476 switch (chg_type) {
Manu Gautama1e331d2013-02-07 14:55:05 +05301477 case DWC3_SDP_CHARGER: return "USB_SDP_CHARGER";
1478 case DWC3_DCP_CHARGER: return "USB_DCP_CHARGER";
1479 case DWC3_CDP_CHARGER: return "USB_CDP_CHARGER";
1480 case DWC3_PROPRIETARY_CHARGER: return "USB_PROPRIETARY_CHARGER";
Manu Gautam8c642812012-06-07 10:35:10 +05301481 default: return "INVALID_CHARGER";
1482 }
1483}
1484
1485#define DWC3_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */
1486#define DWC3_CHG_DCD_MAX_RETRIES 6 /* Tdcd_tmout = 6 * 100 msec */
1487#define DWC3_CHG_PRIMARY_DET_TIME (50 * HZ/1000) /* TVDPSRC_ON */
1488#define DWC3_CHG_SECONDARY_DET_TIME (50 * HZ/1000) /* TVDMSRC_ON */
1489
1490static void dwc3_chg_detect_work(struct work_struct *w)
1491{
1492 struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, chg_work.work);
1493 bool is_dcd = false, tmout, vout;
1494 unsigned long delay;
1495
1496 dev_dbg(mdwc->dev, "chg detection work\n");
1497 switch (mdwc->chg_state) {
1498 case USB_CHG_STATE_UNDEFINED:
1499 dwc3_chg_block_reset(mdwc);
1500 dwc3_chg_enable_dcd(mdwc);
1501 mdwc->chg_state = USB_CHG_STATE_WAIT_FOR_DCD;
1502 mdwc->dcd_retries = 0;
1503 delay = DWC3_CHG_DCD_POLL_TIME;
1504 break;
1505 case USB_CHG_STATE_WAIT_FOR_DCD:
1506 is_dcd = dwc3_chg_check_dcd(mdwc);
1507 tmout = ++mdwc->dcd_retries == DWC3_CHG_DCD_MAX_RETRIES;
1508 if (is_dcd || tmout) {
1509 dwc3_chg_disable_dcd(mdwc);
Manu Gautama1e331d2013-02-07 14:55:05 +05301510 if (dwc3_chg_det_check_linestate(mdwc)) {
1511 dev_dbg(mdwc->dev, "proprietary charger\n");
1512 mdwc->charger.chg_type =
1513 DWC3_PROPRIETARY_CHARGER;
1514 mdwc->chg_state = USB_CHG_STATE_DETECTED;
1515 delay = 0;
1516 break;
1517 }
Manu Gautam8c642812012-06-07 10:35:10 +05301518 dwc3_chg_enable_primary_det(mdwc);
1519 delay = DWC3_CHG_PRIMARY_DET_TIME;
1520 mdwc->chg_state = USB_CHG_STATE_DCD_DONE;
1521 } else {
1522 delay = DWC3_CHG_DCD_POLL_TIME;
1523 }
1524 break;
1525 case USB_CHG_STATE_DCD_DONE:
1526 vout = dwc3_chg_det_check_output(mdwc);
1527 if (vout) {
1528 dwc3_chg_enable_secondary_det(mdwc);
1529 delay = DWC3_CHG_SECONDARY_DET_TIME;
1530 mdwc->chg_state = USB_CHG_STATE_PRIMARY_DONE;
1531 } else {
Manu Gautama1e331d2013-02-07 14:55:05 +05301532 mdwc->charger.chg_type = DWC3_SDP_CHARGER;
Manu Gautam8c642812012-06-07 10:35:10 +05301533 mdwc->chg_state = USB_CHG_STATE_DETECTED;
1534 delay = 0;
1535 }
1536 break;
1537 case USB_CHG_STATE_PRIMARY_DONE:
1538 vout = dwc3_chg_det_check_output(mdwc);
1539 if (vout)
Manu Gautama1e331d2013-02-07 14:55:05 +05301540 mdwc->charger.chg_type = DWC3_DCP_CHARGER;
Manu Gautam8c642812012-06-07 10:35:10 +05301541 else
Manu Gautama1e331d2013-02-07 14:55:05 +05301542 mdwc->charger.chg_type = DWC3_CDP_CHARGER;
Manu Gautam8c642812012-06-07 10:35:10 +05301543 mdwc->chg_state = USB_CHG_STATE_SECONDARY_DONE;
1544 /* fall through */
1545 case USB_CHG_STATE_SECONDARY_DONE:
1546 mdwc->chg_state = USB_CHG_STATE_DETECTED;
1547 /* fall through */
1548 case USB_CHG_STATE_DETECTED:
1549 dwc3_chg_block_reset(mdwc);
Manu Gautama48296e2012-12-05 17:37:56 +05301550 /* Enable VDP_SRC */
1551 if (mdwc->charger.chg_type == DWC3_DCP_CHARGER)
1552 dwc3_msm_write_readback(mdwc->base,
1553 CHARGING_DET_CTRL_REG, 0x1F, 0x10);
Manu Gautam8c642812012-06-07 10:35:10 +05301554 dev_dbg(mdwc->dev, "chg_type = %s\n",
1555 chg_to_string(mdwc->charger.chg_type));
1556 mdwc->charger.notify_detection_complete(mdwc->otg_xceiv->otg,
1557 &mdwc->charger);
1558 return;
1559 default:
1560 return;
1561 }
1562
1563 queue_delayed_work(system_nrt_wq, &mdwc->chg_work, delay);
1564}
1565
1566static void dwc3_start_chg_det(struct dwc3_charger *charger, bool start)
1567{
1568 struct dwc3_msm *mdwc = context;
1569
1570 if (start == false) {
Jack Pham9354c6a2012-12-20 19:19:32 -08001571 dev_dbg(mdwc->dev, "canceling charging detection work\n");
Manu Gautam8c642812012-06-07 10:35:10 +05301572 cancel_delayed_work_sync(&mdwc->chg_work);
1573 mdwc->chg_state = USB_CHG_STATE_UNDEFINED;
1574 charger->chg_type = DWC3_INVALID_CHARGER;
1575 return;
1576 }
1577
1578 mdwc->chg_state = USB_CHG_STATE_UNDEFINED;
1579 charger->chg_type = DWC3_INVALID_CHARGER;
1580 queue_delayed_work(system_nrt_wq, &mdwc->chg_work, 0);
1581}
1582
Manu Gautamb5067272012-07-02 09:53:41 +05301583static int dwc3_msm_suspend(struct dwc3_msm *mdwc)
1584{
Manu Gautam2617deb2012-08-31 17:50:06 -07001585 int ret;
Manu Gautama48296e2012-12-05 17:37:56 +05301586 bool dcp;
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301587 bool host_bus_suspend;
Manu Gautam2617deb2012-08-31 17:50:06 -07001588
Manu Gautamb5067272012-07-02 09:53:41 +05301589 dev_dbg(mdwc->dev, "%s: entering lpm\n", __func__);
1590
1591 if (atomic_read(&mdwc->in_lpm)) {
1592 dev_dbg(mdwc->dev, "%s: Already suspended\n", __func__);
1593 return 0;
1594 }
1595
Manu Gautama48296e2012-12-05 17:37:56 +05301596 if (mdwc->hs_phy_irq)
1597 disable_irq(mdwc->hs_phy_irq);
1598
Manu Gautam98013c22012-11-20 17:42:42 +05301599 if (cancel_delayed_work_sync(&mdwc->chg_work))
1600 dev_dbg(mdwc->dev, "%s: chg_work was pending\n", __func__);
1601 if (mdwc->chg_state != USB_CHG_STATE_DETECTED) {
1602 /* charger detection wasn't complete; re-init flags */
1603 mdwc->chg_state = USB_CHG_STATE_UNDEFINED;
1604 mdwc->charger.chg_type = DWC3_INVALID_CHARGER;
Manu Gautama48296e2012-12-05 17:37:56 +05301605 dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG,
1606 0x37, 0x0);
Manu Gautam98013c22012-11-20 17:42:42 +05301607 }
1608
Manu Gautama48296e2012-12-05 17:37:56 +05301609 dcp = mdwc->charger.chg_type == DWC3_DCP_CHARGER;
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301610 host_bus_suspend = mdwc->host_mode == 1;
Manu Gautam377821c2012-09-28 16:53:24 +05301611
Vijayavardhan Vennapusa4188de22012-11-06 15:20:18 +05301612 /* Sequence to put SSPHY in low power state:
1613 * 1. Clear REF_SS_PHY_EN in SS_PHY_CTRL_REG
1614 * 2. Clear REF_USE_PAD in SS_PHY_CTRL_REG
1615 * 3. Set TEST_POWERED_DOWN in SS_PHY_CTRL_REG to enable PHY retention
1616 * 4. Disable SSPHY ref clk
1617 */
1618 dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 8), 0x0);
1619 dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 28), 0x0);
1620 dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 26),
1621 (1 << 26));
1622
Manu Gautam377821c2012-09-28 16:53:24 +05301623 usleep_range(1000, 1200);
Manu Gautam3e9ad352012-08-16 14:44:47 -07001624 clk_disable_unprepare(mdwc->ref_clk);
Manu Gautam377821c2012-09-28 16:53:24 +05301625
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301626 if (host_bus_suspend) {
1627 /* Sequence for host bus suspend case:
1628 * 1. Set suspend and sleep bits in GUSB2PHYCONFIG reg
1629 * 2. Clear interrupt latch register and enable BSV, ID HV intr
1630 * 3. Enable DP and DM HV interrupts in ALT_INTERRUPT_EN_REG
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301631 */
1632 dwc3_msm_write_reg(mdwc->base, DWC3_GUSB2PHYCFG(0),
1633 dwc3_msm_read_reg(mdwc->base, DWC3_GUSB2PHYCFG(0)) |
1634 0x00000140);
1635 dwc3_msm_write_reg(mdwc->base, HS_PHY_IRQ_STAT_REG, 0xFFF);
1636 if (mdwc->otg_xceiv && (!mdwc->ext_xceiv.otg_capability))
1637 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG,
1638 0x18000, 0x18000);
Vijayavardhan Vennapusa98bccc52013-01-24 13:07:34 +05301639 dwc3_msm_write_reg(mdwc->base, ALT_INTERRUPT_EN_REG, 0xFC0);
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301640 udelay(5);
1641 } else {
1642 /* Sequence to put hardware in low power state:
1643 * 1. Set OTGDISABLE to disable OTG block in HSPHY (saves power)
1644 * 2. Clear charger detection control fields (performed above)
1645 * 3. SUSPEND PHY and turn OFF core clock after some delay
1646 * 4. Clear interrupt latch register and enable BSV, ID HV intr
1647 * 5. Enable PHY retention
1648 */
1649 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, 0x1000,
1650 0x1000);
1651 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG,
1652 0xC00000, 0x800000);
1653 dwc3_msm_write_reg(mdwc->base, HS_PHY_IRQ_STAT_REG, 0xFFF);
1654 if (mdwc->otg_xceiv && (!mdwc->ext_xceiv.otg_capability))
1655 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG,
1656 0x18000, 0x18000);
1657 if (!dcp)
1658 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG,
1659 0x2, 0x0);
1660 }
Manu Gautam377821c2012-09-28 16:53:24 +05301661
1662 /* make sure above writes are completed before turning off clocks */
1663 wmb();
1664 clk_disable_unprepare(mdwc->core_clk);
1665 clk_disable_unprepare(mdwc->iface_clk);
1666
Jack Pham22698b82013-02-13 17:45:06 -08001667 if (!host_bus_suspend) {
1668 clk_disable_unprepare(mdwc->utmi_clk);
1669
1670 /* USB PHY no more requires TCXO */
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05301671 clk_disable_unprepare(mdwc->xo_clk);
Jack Pham22698b82013-02-13 17:45:06 -08001672 }
Manu Gautamb5067272012-07-02 09:53:41 +05301673
Manu Gautam2617deb2012-08-31 17:50:06 -07001674 if (mdwc->bus_perf_client) {
1675 ret = msm_bus_scale_client_update_request(
1676 mdwc->bus_perf_client, 0);
1677 if (ret)
1678 dev_err(mdwc->dev, "Failed to reset bus bw vote\n");
1679 }
1680
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301681 if (mdwc->otg_xceiv && mdwc->ext_xceiv.otg_capability && !dcp &&
1682 !host_bus_suspend)
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05301683 dwc3_hsusb_ldo_enable(0);
1684
Vijayavardhan Vennapusa6bc06962012-10-31 13:23:38 +05301685 dwc3_ssusb_ldo_enable(0);
1686 dwc3_ssusb_config_vddcx(0);
Vijayavardhan Vennapusa98bccc52013-01-24 13:07:34 +05301687 if (!host_bus_suspend)
1688 dwc3_hsusb_config_vddcx(0);
Manu Gautam377821c2012-09-28 16:53:24 +05301689 wake_unlock(&mdwc->wlock);
Manu Gautamb5067272012-07-02 09:53:41 +05301690 atomic_set(&mdwc->in_lpm, 1);
Manu Gautam377821c2012-09-28 16:53:24 +05301691
Manu Gautamb5067272012-07-02 09:53:41 +05301692 dev_info(mdwc->dev, "DWC3 in low power mode\n");
1693
Manu Gautama48296e2012-12-05 17:37:56 +05301694 if (mdwc->hs_phy_irq)
1695 enable_irq(mdwc->hs_phy_irq);
1696
Manu Gautamb5067272012-07-02 09:53:41 +05301697 return 0;
1698}
1699
1700static int dwc3_msm_resume(struct dwc3_msm *mdwc)
1701{
Manu Gautam2617deb2012-08-31 17:50:06 -07001702 int ret;
Manu Gautama48296e2012-12-05 17:37:56 +05301703 bool dcp;
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301704 bool host_bus_suspend;
Manu Gautam2617deb2012-08-31 17:50:06 -07001705
Manu Gautamb5067272012-07-02 09:53:41 +05301706 dev_dbg(mdwc->dev, "%s: exiting lpm\n", __func__);
1707
1708 if (!atomic_read(&mdwc->in_lpm)) {
1709 dev_dbg(mdwc->dev, "%s: Already resumed\n", __func__);
1710 return 0;
1711 }
1712
Manu Gautam377821c2012-09-28 16:53:24 +05301713 wake_lock(&mdwc->wlock);
1714
Manu Gautam2617deb2012-08-31 17:50:06 -07001715 if (mdwc->bus_perf_client) {
1716 ret = msm_bus_scale_client_update_request(
1717 mdwc->bus_perf_client, 1);
1718 if (ret)
1719 dev_err(mdwc->dev, "Failed to vote for bus scaling\n");
1720 }
1721
Manu Gautama48296e2012-12-05 17:37:56 +05301722 dcp = mdwc->charger.chg_type == DWC3_DCP_CHARGER;
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301723 host_bus_suspend = mdwc->host_mode == 1;
Vijayavardhan Vennapusa98bccc52013-01-24 13:07:34 +05301724
1725 if (!host_bus_suspend) {
1726 /* Vote for TCXO while waking up USB HSPHY */
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05301727 ret = clk_prepare_enable(mdwc->xo_clk);
Vijayavardhan Vennapusa98bccc52013-01-24 13:07:34 +05301728 if (ret)
1729 dev_err(mdwc->dev, "%s failed to vote TCXO buffer%d\n",
1730 __func__, ret);
1731 }
1732
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301733 if (mdwc->otg_xceiv && mdwc->ext_xceiv.otg_capability && !dcp &&
1734 !host_bus_suspend)
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05301735 dwc3_hsusb_ldo_enable(1);
1736
Vijayavardhan Vennapusa6bc06962012-10-31 13:23:38 +05301737 dwc3_ssusb_ldo_enable(1);
1738 dwc3_ssusb_config_vddcx(1);
Jack Pham22698b82013-02-13 17:45:06 -08001739
1740 if (!host_bus_suspend) {
Vijayavardhan Vennapusa98bccc52013-01-24 13:07:34 +05301741 dwc3_hsusb_config_vddcx(1);
Jack Pham22698b82013-02-13 17:45:06 -08001742 clk_prepare_enable(mdwc->utmi_clk);
1743 }
1744
Manu Gautam3e9ad352012-08-16 14:44:47 -07001745 clk_prepare_enable(mdwc->ref_clk);
Manu Gautam377821c2012-09-28 16:53:24 +05301746 usleep_range(1000, 1200);
1747
Manu Gautam3e9ad352012-08-16 14:44:47 -07001748 clk_prepare_enable(mdwc->iface_clk);
Manu Gautam377821c2012-09-28 16:53:24 +05301749 clk_prepare_enable(mdwc->core_clk);
1750
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301751 if (host_bus_suspend) {
1752 /* Disable HV interrupt */
1753 if (mdwc->otg_xceiv && (!mdwc->ext_xceiv.otg_capability))
1754 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG,
1755 0x18000, 0x0);
1756 /* Clear interrupt latch register */
1757 dwc3_msm_write_reg(mdwc->base, HS_PHY_IRQ_STAT_REG, 0x000);
Manu Gautam377821c2012-09-28 16:53:24 +05301758
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301759 /* Disable DP and DM HV interrupt */
1760 dwc3_msm_write_reg(mdwc->base, ALT_INTERRUPT_EN_REG, 0x000);
Manu Gautam377821c2012-09-28 16:53:24 +05301761
Vijayavardhan Vennapusa98bccc52013-01-24 13:07:34 +05301762 /* Clear suspend bit in GUSB2PHYCONFIG register */
1763 dwc3_msm_write_readback(mdwc->base, DWC3_GUSB2PHYCFG(0),
1764 0x40, 0x0);
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05301765 } else {
1766 /* Disable HV interrupt */
1767 if (mdwc->otg_xceiv && (!mdwc->ext_xceiv.otg_capability))
1768 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG,
1769 0x18000, 0x0);
1770 /* Disable Retention */
1771 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, 0x2, 0x2);
1772
1773 dwc3_msm_write_reg(mdwc->base, DWC3_GUSB2PHYCFG(0),
1774 dwc3_msm_read_reg(mdwc->base, DWC3_GUSB2PHYCFG(0)) |
1775 0xF0000000);
1776 /* 10usec delay required before de-asserting PHY RESET */
1777 udelay(10);
1778 dwc3_msm_write_reg(mdwc->base, DWC3_GUSB2PHYCFG(0),
1779 dwc3_msm_read_reg(mdwc->base, DWC3_GUSB2PHYCFG(0)) &
1780 0x7FFFFFFF);
1781
1782 /* Bring PHY out of suspend */
1783 dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, 0xC00000,
1784 0x0);
1785
1786 }
Manu Gautamb5067272012-07-02 09:53:41 +05301787
Vijayavardhan Vennapusa4188de22012-11-06 15:20:18 +05301788 /* Assert SS PHY RESET */
1789 dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 7),
1790 (1 << 7));
1791 dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 28),
1792 (1 << 28));
1793 dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 8),
1794 (1 << 8));
1795 dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 26), 0x0);
1796 /* 10usec delay required before de-asserting SS PHY RESET */
1797 udelay(10);
1798 dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 7), 0x0);
1799
Vijayavardhan Vennapusa5b286322013-04-12 12:15:00 +05301800 /*
1801 * Reinitilize SSPHY parameters as SS_PHY RESET will reset
1802 * the internal registers to default values.
1803 */
1804 dwc3_msm_ss_phy_reg_init(mdwc);
Manu Gautamb5067272012-07-02 09:53:41 +05301805 atomic_set(&mdwc->in_lpm, 0);
Manu Gautam377821c2012-09-28 16:53:24 +05301806
1807 /* match disable_irq call from isr */
1808 if (mdwc->lpm_irq_seen && mdwc->hs_phy_irq) {
1809 enable_irq(mdwc->hs_phy_irq);
1810 mdwc->lpm_irq_seen = false;
1811 }
1812
Manu Gautamb5067272012-07-02 09:53:41 +05301813 dev_info(mdwc->dev, "DWC3 exited from low power mode\n");
1814
1815 return 0;
1816}
1817
1818static void dwc3_resume_work(struct work_struct *w)
1819{
1820 struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm,
1821 resume_work.work);
1822
1823 dev_dbg(mdwc->dev, "%s: dwc3 resume work\n", __func__);
1824 /* handle any event that was queued while work was already running */
1825 if (!atomic_read(&mdwc->in_lpm)) {
1826 dev_dbg(mdwc->dev, "%s: notifying xceiv event\n", __func__);
1827 if (mdwc->otg_xceiv)
1828 mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg,
1829 DWC3_EVENT_XCEIV_STATE);
1830 return;
1831 }
1832
1833 /* bail out if system resume in process, else initiate RESUME */
1834 if (atomic_read(&mdwc->pm_suspended)) {
1835 mdwc->resume_pending = true;
1836 } else {
1837 pm_runtime_get_sync(mdwc->dev);
1838 if (mdwc->otg_xceiv)
1839 mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg,
1840 DWC3_EVENT_PHY_RESUME);
1841 pm_runtime_put_sync(mdwc->dev);
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05301842 if (mdwc->otg_xceiv && (mdwc->ext_xceiv.otg_capability))
1843 mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg,
1844 DWC3_EVENT_XCEIV_STATE);
Manu Gautamb5067272012-07-02 09:53:41 +05301845 }
1846}
1847
Jack Pham0fc12332012-11-19 13:14:22 -08001848static u32 debug_id = true, debug_bsv, debug_connect;
Manu Gautamb5067272012-07-02 09:53:41 +05301849
1850static int dwc3_connect_show(struct seq_file *s, void *unused)
1851{
1852 if (debug_connect)
1853 seq_printf(s, "true\n");
1854 else
1855 seq_printf(s, "false\n");
1856
1857 return 0;
1858}
1859
1860static int dwc3_connect_open(struct inode *inode, struct file *file)
1861{
1862 return single_open(file, dwc3_connect_show, inode->i_private);
1863}
1864
1865static ssize_t dwc3_connect_write(struct file *file, const char __user *ubuf,
1866 size_t count, loff_t *ppos)
1867{
1868 struct seq_file *s = file->private_data;
1869 struct dwc3_msm *mdwc = s->private;
1870 char buf[8];
1871
1872 memset(buf, 0x00, sizeof(buf));
1873
1874 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
1875 return -EFAULT;
1876
1877 if (!strncmp(buf, "enable", 6) || !strncmp(buf, "true", 4)) {
1878 debug_connect = true;
1879 } else {
1880 debug_connect = debug_bsv = false;
1881 debug_id = true;
1882 }
1883
1884 mdwc->ext_xceiv.bsv = debug_bsv;
1885 mdwc->ext_xceiv.id = debug_id ? DWC3_ID_FLOAT : DWC3_ID_GROUND;
1886
1887 if (atomic_read(&mdwc->in_lpm)) {
1888 dev_dbg(mdwc->dev, "%s: calling resume_work\n", __func__);
1889 dwc3_resume_work(&mdwc->resume_work.work);
1890 } else {
1891 dev_dbg(mdwc->dev, "%s: notifying xceiv event\n", __func__);
1892 if (mdwc->otg_xceiv)
1893 mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg,
1894 DWC3_EVENT_XCEIV_STATE);
1895 }
1896
1897 return count;
1898}
1899
1900const struct file_operations dwc3_connect_fops = {
1901 .open = dwc3_connect_open,
1902 .read = seq_read,
1903 .write = dwc3_connect_write,
1904 .llseek = seq_lseek,
1905 .release = single_release,
1906};
1907
1908static struct dentry *dwc3_debugfs_root;
1909
1910static void dwc3_debugfs_init(struct dwc3_msm *mdwc)
1911{
1912 dwc3_debugfs_root = debugfs_create_dir("msm_dwc3", NULL);
1913
1914 if (!dwc3_debugfs_root || IS_ERR(dwc3_debugfs_root))
1915 return;
1916
1917 if (!debugfs_create_bool("id", S_IRUGO | S_IWUSR, dwc3_debugfs_root,
Vijayavardhan Vennapusa54be1d62012-10-06 18:32:06 +05301918 &debug_id))
Manu Gautamb5067272012-07-02 09:53:41 +05301919 goto error;
1920
1921 if (!debugfs_create_bool("bsv", S_IRUGO | S_IWUSR, dwc3_debugfs_root,
Vijayavardhan Vennapusa54be1d62012-10-06 18:32:06 +05301922 &debug_bsv))
Manu Gautamb5067272012-07-02 09:53:41 +05301923 goto error;
1924
1925 if (!debugfs_create_file("connect", S_IRUGO | S_IWUSR,
1926 dwc3_debugfs_root, mdwc, &dwc3_connect_fops))
1927 goto error;
1928
1929 return;
1930
1931error:
1932 debugfs_remove_recursive(dwc3_debugfs_root);
1933}
Manu Gautam8c642812012-06-07 10:35:10 +05301934
Manu Gautam377821c2012-09-28 16:53:24 +05301935static irqreturn_t msm_dwc3_irq(int irq, void *data)
1936{
1937 struct dwc3_msm *mdwc = data;
1938
1939 if (atomic_read(&mdwc->in_lpm)) {
1940 dev_dbg(mdwc->dev, "%s received in LPM\n", __func__);
1941 mdwc->lpm_irq_seen = true;
1942 disable_irq_nosync(irq);
1943 queue_delayed_work(system_nrt_wq, &mdwc->resume_work, 0);
1944 } else {
1945 pr_info_ratelimited("%s: IRQ outside LPM\n", __func__);
1946 }
1947
1948 return IRQ_HANDLED;
1949}
1950
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05301951static int dwc3_msm_power_get_property_usb(struct power_supply *psy,
1952 enum power_supply_property psp,
1953 union power_supply_propval *val)
1954{
1955 struct dwc3_msm *mdwc = container_of(psy, struct dwc3_msm,
1956 usb_psy);
1957 switch (psp) {
1958 case POWER_SUPPLY_PROP_SCOPE:
1959 val->intval = mdwc->host_mode;
1960 break;
1961 case POWER_SUPPLY_PROP_CURRENT_MAX:
1962 val->intval = mdwc->current_max;
1963 break;
1964 case POWER_SUPPLY_PROP_PRESENT:
1965 val->intval = mdwc->vbus_active;
1966 break;
1967 case POWER_SUPPLY_PROP_ONLINE:
1968 val->intval = mdwc->online;
1969 break;
Manu Gautamfa40cae2013-03-01 16:37:12 +05301970 case POWER_SUPPLY_PROP_TYPE:
1971 val->intval = psy->type;
1972 break;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05301973 default:
1974 return -EINVAL;
1975 }
1976 return 0;
1977}
1978
1979static int dwc3_msm_power_set_property_usb(struct power_supply *psy,
1980 enum power_supply_property psp,
1981 const union power_supply_propval *val)
1982{
1983 static bool init;
1984 struct dwc3_msm *mdwc = container_of(psy, struct dwc3_msm,
1985 usb_psy);
1986
1987 switch (psp) {
1988 case POWER_SUPPLY_PROP_SCOPE:
1989 mdwc->host_mode = val->intval;
1990 break;
1991 /* Process PMIC notification in PRESENT prop */
1992 case POWER_SUPPLY_PROP_PRESENT:
1993 dev_dbg(mdwc->dev, "%s: notify xceiv event\n", __func__);
Jack Pham9354c6a2012-12-20 19:19:32 -08001994 if (mdwc->otg_xceiv && !mdwc->ext_inuse &&
1995 (mdwc->ext_xceiv.otg_capability || !init)) {
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05301996 mdwc->ext_xceiv.bsv = val->intval;
Manu Gautamf71d9cb2013-02-07 13:52:12 +05301997 queue_delayed_work(system_nrt_wq,
Jack Pham4d91aab2013-03-08 10:02:16 -08001998 &mdwc->resume_work, 20);
Jack Pham9354c6a2012-12-20 19:19:32 -08001999
2000 if (!init)
2001 init = true;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302002 }
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302003 mdwc->vbus_active = val->intval;
2004 break;
2005 case POWER_SUPPLY_PROP_ONLINE:
2006 mdwc->online = val->intval;
2007 break;
2008 case POWER_SUPPLY_PROP_CURRENT_MAX:
2009 mdwc->current_max = val->intval;
2010 break;
Manu Gautamfa40cae2013-03-01 16:37:12 +05302011 case POWER_SUPPLY_PROP_TYPE:
2012 psy->type = val->intval;
2013 break;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302014 default:
2015 return -EINVAL;
2016 }
2017
2018 power_supply_changed(&mdwc->usb_psy);
2019 return 0;
2020}
2021
Jack Pham9354c6a2012-12-20 19:19:32 -08002022static void dwc3_msm_external_power_changed(struct power_supply *psy)
2023{
2024 struct dwc3_msm *mdwc = container_of(psy, struct dwc3_msm, usb_psy);
2025 union power_supply_propval ret = {0,};
2026
2027 if (!mdwc->ext_vbus_psy)
2028 mdwc->ext_vbus_psy = power_supply_get_by_name("ext-vbus");
2029
2030 if (!mdwc->ext_vbus_psy) {
2031 pr_err("%s: Unable to get ext_vbus power_supply\n", __func__);
2032 return;
2033 }
2034
2035 mdwc->ext_vbus_psy->get_property(mdwc->ext_vbus_psy,
2036 POWER_SUPPLY_PROP_ONLINE, &ret);
2037 if (ret.intval) {
2038 dwc3_start_chg_det(&mdwc->charger, false);
2039 mdwc->ext_vbus_psy->get_property(mdwc->ext_vbus_psy,
2040 POWER_SUPPLY_PROP_CURRENT_MAX, &ret);
2041 power_supply_set_current_limit(&mdwc->usb_psy, ret.intval);
2042 }
2043
2044 power_supply_set_online(&mdwc->usb_psy, ret.intval);
2045 power_supply_changed(&mdwc->usb_psy);
2046}
2047
2048
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302049static char *dwc3_msm_pm_power_supplied_to[] = {
2050 "battery",
2051};
2052
2053static enum power_supply_property dwc3_msm_pm_power_props_usb[] = {
2054 POWER_SUPPLY_PROP_PRESENT,
2055 POWER_SUPPLY_PROP_ONLINE,
2056 POWER_SUPPLY_PROP_CURRENT_MAX,
2057 POWER_SUPPLY_PROP_SCOPE,
2058};
2059
Jack Phamfadd6432012-12-07 19:03:41 -08002060static void dwc3_init_adc_work(struct work_struct *w);
2061
2062static void dwc3_ext_notify_online(int on)
2063{
2064 struct dwc3_msm *mdwc = context;
Jack Phamf12b7e12012-12-28 14:27:26 -08002065 bool notify_otg = false;
Jack Phamfadd6432012-12-07 19:03:41 -08002066
2067 if (!mdwc) {
2068 pr_err("%s: DWC3 driver already removed\n", __func__);
2069 return;
2070 }
2071
2072 dev_dbg(mdwc->dev, "notify %s%s\n", on ? "" : "dis", "connected");
2073
Jack Pham9354c6a2012-12-20 19:19:32 -08002074 if (!mdwc->ext_vbus_psy)
2075 mdwc->ext_vbus_psy = power_supply_get_by_name("ext-vbus");
2076
2077 mdwc->ext_inuse = on;
Jack Phamf12b7e12012-12-28 14:27:26 -08002078 if (on) {
2079 /* force OTG to exit B-peripheral state */
2080 mdwc->ext_xceiv.bsv = false;
2081 notify_otg = true;
Jack Pham9354c6a2012-12-20 19:19:32 -08002082 dwc3_start_chg_det(&mdwc->charger, false);
Jack Phamf12b7e12012-12-28 14:27:26 -08002083 } else {
2084 /* external client offline; tell OTG about cached ID/BSV */
2085 if (mdwc->ext_xceiv.id != mdwc->id_state) {
2086 mdwc->ext_xceiv.id = mdwc->id_state;
2087 notify_otg = true;
2088 }
2089
2090 mdwc->ext_xceiv.bsv = mdwc->vbus_active;
2091 notify_otg |= mdwc->vbus_active;
2092 }
Jack Pham9354c6a2012-12-20 19:19:32 -08002093
2094 if (mdwc->ext_vbus_psy)
2095 power_supply_set_present(mdwc->ext_vbus_psy, on);
Jack Phamf12b7e12012-12-28 14:27:26 -08002096
2097 if (notify_otg)
2098 queue_delayed_work(system_nrt_wq, &mdwc->resume_work, 0);
Jack Phamfadd6432012-12-07 19:03:41 -08002099}
2100
Jack Pham0cca9412013-03-08 13:22:42 -08002101static void dwc3_id_work(struct work_struct *w)
Jack Phamfadd6432012-12-07 19:03:41 -08002102{
Jack Pham0cca9412013-03-08 13:22:42 -08002103 struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, id_work);
Jack Pham5c585062013-03-25 18:39:12 -07002104 int ret;
Jack Phamfadd6432012-12-07 19:03:41 -08002105
Jack Pham0cca9412013-03-08 13:22:42 -08002106 /* Give external client a chance to handle */
Jack Pham5c585062013-03-25 18:39:12 -07002107 if (!mdwc->ext_inuse && usb_ext) {
2108 if (mdwc->pmic_id_irq)
2109 disable_irq(mdwc->pmic_id_irq);
2110
2111 ret = usb_ext->notify(usb_ext->ctxt, mdwc->id_state,
2112 dwc3_ext_notify_online);
2113 dev_dbg(mdwc->dev, "%s: external handler returned %d\n",
2114 __func__, ret);
2115
2116 if (mdwc->pmic_id_irq) {
2117 /* ID may have changed while IRQ disabled; update it */
2118 mdwc->id_state = !!irq_read_line(mdwc->pmic_id_irq);
2119 enable_irq(mdwc->pmic_id_irq);
Jack Pham0cca9412013-03-08 13:22:42 -08002120 }
Jack Pham5c585062013-03-25 18:39:12 -07002121
2122 mdwc->ext_inuse = (ret == 0);
Jack Pham0cca9412013-03-08 13:22:42 -08002123 }
Jack Phamfadd6432012-12-07 19:03:41 -08002124
Jack Pham0cca9412013-03-08 13:22:42 -08002125 if (!mdwc->ext_inuse) { /* notify OTG */
2126 mdwc->ext_xceiv.id = mdwc->id_state;
2127 dwc3_resume_work(&mdwc->resume_work.work);
2128 }
2129}
2130
2131static irqreturn_t dwc3_pmic_id_irq(int irq, void *data)
2132{
2133 struct dwc3_msm *mdwc = data;
Jack Pham5c585062013-03-25 18:39:12 -07002134 enum dwc3_id_state id;
Jack Pham0cca9412013-03-08 13:22:42 -08002135
2136 /* If we can't read ID line state for some reason, treat it as float */
Jack Pham5c585062013-03-25 18:39:12 -07002137 id = !!irq_read_line(irq);
2138 if (mdwc->id_state != id) {
2139 mdwc->id_state = id;
2140 queue_work(system_nrt_wq, &mdwc->id_work);
2141 }
Jack Pham0cca9412013-03-08 13:22:42 -08002142
2143 return IRQ_HANDLED;
Jack Phamfadd6432012-12-07 19:03:41 -08002144}
2145
Jack Pham0fc12332012-11-19 13:14:22 -08002146static void dwc3_adc_notification(enum qpnp_tm_state state, void *ctx)
2147{
2148 struct dwc3_msm *mdwc = ctx;
2149
2150 if (state >= ADC_TM_STATE_NUM) {
2151 pr_err("%s: invalid notification %d\n", __func__, state);
2152 return;
2153 }
2154
2155 dev_dbg(mdwc->dev, "%s: state = %s\n", __func__,
2156 state == ADC_TM_HIGH_STATE ? "high" : "low");
2157
Jack Phamf12b7e12012-12-28 14:27:26 -08002158 /* save ID state, but don't necessarily notify OTG */
Jack Pham0fc12332012-11-19 13:14:22 -08002159 if (state == ADC_TM_HIGH_STATE) {
Jack Phamf12b7e12012-12-28 14:27:26 -08002160 mdwc->id_state = DWC3_ID_FLOAT;
Jack Pham0fc12332012-11-19 13:14:22 -08002161 mdwc->adc_param.state_request = ADC_TM_LOW_THR_ENABLE;
2162 } else {
Jack Phamf12b7e12012-12-28 14:27:26 -08002163 mdwc->id_state = DWC3_ID_GROUND;
Jack Pham0fc12332012-11-19 13:14:22 -08002164 mdwc->adc_param.state_request = ADC_TM_HIGH_THR_ENABLE;
2165 }
2166
Jack Pham0cca9412013-03-08 13:22:42 -08002167 dwc3_id_work(&mdwc->id_work);
2168
Jack Phamfadd6432012-12-07 19:03:41 -08002169 /* re-arm ADC interrupt */
Jack Pham0fc12332012-11-19 13:14:22 -08002170 qpnp_adc_tm_usbid_configure(&mdwc->adc_param);
2171}
2172
2173static void dwc3_init_adc_work(struct work_struct *w)
2174{
2175 struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm,
2176 init_adc_work.work);
2177 int ret;
2178
2179 ret = qpnp_adc_tm_is_ready();
2180 if (ret == -EPROBE_DEFER) {
Jack Pham90b4d122012-12-13 11:46:22 -08002181 queue_delayed_work(system_nrt_wq, to_delayed_work(w),
2182 msecs_to_jiffies(100));
Jack Pham0fc12332012-11-19 13:14:22 -08002183 return;
2184 }
2185
2186 mdwc->adc_param.low_thr = adc_low_threshold;
2187 mdwc->adc_param.high_thr = adc_high_threshold;
2188 mdwc->adc_param.timer_interval = adc_meas_interval;
2189 mdwc->adc_param.state_request = ADC_TM_HIGH_LOW_THR_ENABLE;
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08002190 mdwc->adc_param.btm_ctx = mdwc;
Jack Pham0fc12332012-11-19 13:14:22 -08002191 mdwc->adc_param.threshold_notification = dwc3_adc_notification;
2192
2193 ret = qpnp_adc_tm_usbid_configure(&mdwc->adc_param);
2194 if (ret) {
2195 dev_err(mdwc->dev, "%s: request ADC error %d\n", __func__, ret);
2196 return;
2197 }
2198
2199 mdwc->id_adc_detect = true;
2200}
2201
2202static ssize_t adc_enable_show(struct device *dev,
2203 struct device_attribute *attr, char *buf)
2204{
2205 return snprintf(buf, PAGE_SIZE, "%s\n", context->id_adc_detect ?
2206 "enabled" : "disabled");
2207}
2208
2209static ssize_t adc_enable_store(struct device *dev,
2210 struct device_attribute *attr, const char
2211 *buf, size_t size)
2212{
2213 if (!strnicmp(buf, "enable", 6)) {
2214 if (!context->id_adc_detect)
2215 dwc3_init_adc_work(&context->init_adc_work.work);
2216 return size;
2217 } else if (!strnicmp(buf, "disable", 7)) {
2218 qpnp_adc_tm_usbid_end();
2219 context->id_adc_detect = false;
2220 return size;
2221 }
2222
2223 return -EINVAL;
2224}
2225
2226static DEVICE_ATTR(adc_enable, S_IRUGO | S_IWUSR, adc_enable_show,
2227 adc_enable_store);
2228
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002229static int __devinit dwc3_msm_probe(struct platform_device *pdev)
2230{
2231 struct device_node *node = pdev->dev.of_node;
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002232 struct dwc3_msm *msm;
2233 struct resource *res;
Ido Shayevitz7ad8ded2012-08-28 04:30:58 +03002234 void __iomem *tcsr;
Manu Gautamf08f7b62013-04-02 16:09:42 +05302235 unsigned long flags;
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002236 int ret = 0;
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +05302237 int len = 0;
2238 u32 tmp[3];
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002239
2240 msm = devm_kzalloc(&pdev->dev, sizeof(*msm), GFP_KERNEL);
2241 if (!msm) {
2242 dev_err(&pdev->dev, "not enough memory\n");
2243 return -ENOMEM;
2244 }
2245
2246 platform_set_drvdata(pdev, msm);
Ido Shayevitz9fb83452012-04-01 17:45:58 +03002247 context = msm;
Manu Gautam60e01352012-05-29 09:00:34 +05302248 msm->dev = &pdev->dev;
Ido Shayevitz9fb83452012-04-01 17:45:58 +03002249
2250 INIT_LIST_HEAD(&msm->req_complete_list);
Manu Gautam8c642812012-06-07 10:35:10 +05302251 INIT_DELAYED_WORK(&msm->chg_work, dwc3_chg_detect_work);
Manu Gautamb5067272012-07-02 09:53:41 +05302252 INIT_DELAYED_WORK(&msm->resume_work, dwc3_resume_work);
Manu Gautam6eb13e32013-02-01 15:19:15 +05302253 INIT_WORK(&msm->restart_usb_work, dwc3_restart_usb_work);
Jack Pham0cca9412013-03-08 13:22:42 -08002254 INIT_WORK(&msm->id_work, dwc3_id_work);
Jack Pham0fc12332012-11-19 13:14:22 -08002255 INIT_DELAYED_WORK(&msm->init_adc_work, dwc3_init_adc_work);
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002256
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05302257 msm->xo_clk = clk_get(&pdev->dev, "xo");
2258 if (IS_ERR(msm->xo_clk)) {
Manu Gautam377821c2012-09-28 16:53:24 +05302259 dev_err(&pdev->dev, "%s unable to get TCXO buffer handle\n",
2260 __func__);
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05302261 return PTR_ERR(msm->xo_clk);
Manu Gautam377821c2012-09-28 16:53:24 +05302262 }
2263
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05302264 ret = clk_prepare_enable(msm->xo_clk);
Manu Gautam377821c2012-09-28 16:53:24 +05302265 if (ret) {
2266 dev_err(&pdev->dev, "%s failed to vote for TCXO buffer%d\n",
2267 __func__, ret);
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05302268 goto put_xo;
Manu Gautam377821c2012-09-28 16:53:24 +05302269 }
2270
Manu Gautam1742db22012-06-19 13:33:24 +05302271 /*
2272 * DWC3 Core requires its CORE CLK (aka master / bus clk) to
2273 * run at 125Mhz in SSUSB mode and >60MHZ for HSUSB mode.
2274 */
2275 msm->core_clk = devm_clk_get(&pdev->dev, "core_clk");
2276 if (IS_ERR(msm->core_clk)) {
2277 dev_err(&pdev->dev, "failed to get core_clk\n");
Manu Gautam377821c2012-09-28 16:53:24 +05302278 ret = PTR_ERR(msm->core_clk);
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05302279 goto disable_xo;
Manu Gautam1742db22012-06-19 13:33:24 +05302280 }
2281 clk_set_rate(msm->core_clk, 125000000);
2282 clk_prepare_enable(msm->core_clk);
2283
Manu Gautam3e9ad352012-08-16 14:44:47 -07002284 msm->iface_clk = devm_clk_get(&pdev->dev, "iface_clk");
2285 if (IS_ERR(msm->iface_clk)) {
2286 dev_err(&pdev->dev, "failed to get iface_clk\n");
2287 ret = PTR_ERR(msm->iface_clk);
2288 goto disable_core_clk;
2289 }
2290 clk_prepare_enable(msm->iface_clk);
2291
2292 msm->sleep_clk = devm_clk_get(&pdev->dev, "sleep_clk");
2293 if (IS_ERR(msm->sleep_clk)) {
2294 dev_err(&pdev->dev, "failed to get sleep_clk\n");
2295 ret = PTR_ERR(msm->sleep_clk);
2296 goto disable_iface_clk;
2297 }
2298 clk_prepare_enable(msm->sleep_clk);
2299
2300 msm->hsphy_sleep_clk = devm_clk_get(&pdev->dev, "sleep_a_clk");
2301 if (IS_ERR(msm->hsphy_sleep_clk)) {
2302 dev_err(&pdev->dev, "failed to get sleep_a_clk\n");
2303 ret = PTR_ERR(msm->hsphy_sleep_clk);
2304 goto disable_sleep_clk;
2305 }
2306 clk_prepare_enable(msm->hsphy_sleep_clk);
2307
Jack Pham22698b82013-02-13 17:45:06 -08002308 msm->utmi_clk = devm_clk_get(&pdev->dev, "utmi_clk");
2309 if (IS_ERR(msm->utmi_clk)) {
2310 dev_err(&pdev->dev, "failed to get utmi_clk\n");
2311 ret = PTR_ERR(msm->utmi_clk);
2312 goto disable_sleep_a_clk;
2313 }
2314 clk_prepare_enable(msm->utmi_clk);
2315
Manu Gautam3e9ad352012-08-16 14:44:47 -07002316 msm->ref_clk = devm_clk_get(&pdev->dev, "ref_clk");
2317 if (IS_ERR(msm->ref_clk)) {
2318 dev_err(&pdev->dev, "failed to get ref_clk\n");
2319 ret = PTR_ERR(msm->ref_clk);
Jack Pham22698b82013-02-13 17:45:06 -08002320 goto disable_utmi_clk;
Manu Gautam3e9ad352012-08-16 14:44:47 -07002321 }
2322 clk_prepare_enable(msm->ref_clk);
2323
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +05302324 of_get_property(node, "qcom,vdd-voltage-level", &len);
2325 if (len == sizeof(tmp)) {
2326 of_property_read_u32_array(node, "qcom,vdd-voltage-level",
2327 tmp, len/sizeof(*tmp));
2328 msm->vdd_no_vol_level = tmp[0];
2329 msm->vdd_low_vol_level = tmp[1];
2330 msm->vdd_high_vol_level = tmp[2];
2331 } else {
2332 dev_err(&pdev->dev, "no qcom,vdd-voltage-level property\n");
2333 ret = -EINVAL;
2334 goto disable_ref_clk;
2335 }
2336
Manu Gautam60e01352012-05-29 09:00:34 +05302337 /* SS PHY */
Manu Gautam60e01352012-05-29 09:00:34 +05302338 msm->ssusb_vddcx = devm_regulator_get(&pdev->dev, "ssusb_vdd_dig");
2339 if (IS_ERR(msm->ssusb_vddcx)) {
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +05302340 dev_err(&pdev->dev, "unable to get ssusb vddcx\n");
2341 ret = PTR_ERR(msm->ssusb_vddcx);
2342 goto disable_ref_clk;
Manu Gautam60e01352012-05-29 09:00:34 +05302343 }
2344
2345 ret = dwc3_ssusb_config_vddcx(1);
2346 if (ret) {
2347 dev_err(&pdev->dev, "ssusb vddcx configuration failed\n");
Manu Gautam3e9ad352012-08-16 14:44:47 -07002348 goto disable_ref_clk;
Manu Gautam60e01352012-05-29 09:00:34 +05302349 }
2350
2351 ret = regulator_enable(context->ssusb_vddcx);
2352 if (ret) {
2353 dev_err(&pdev->dev, "unable to enable the ssusb vddcx\n");
2354 goto unconfig_ss_vddcx;
2355 }
2356
2357 ret = dwc3_ssusb_ldo_init(1);
2358 if (ret) {
2359 dev_err(&pdev->dev, "ssusb vreg configuration failed\n");
2360 goto disable_ss_vddcx;
2361 }
2362
2363 ret = dwc3_ssusb_ldo_enable(1);
2364 if (ret) {
2365 dev_err(&pdev->dev, "ssusb vreg enable failed\n");
2366 goto free_ss_ldo_init;
2367 }
2368
2369 /* HS PHY */
Manu Gautam60e01352012-05-29 09:00:34 +05302370 msm->hsusb_vddcx = devm_regulator_get(&pdev->dev, "hsusb_vdd_dig");
2371 if (IS_ERR(msm->hsusb_vddcx)) {
Vijayavardhan Vennapusa993798a2012-11-09 15:11:21 +05302372 dev_err(&pdev->dev, "unable to get hsusb vddcx\n");
2373 ret = PTR_ERR(msm->hsusb_vddcx);
2374 goto disable_ss_ldo;
Manu Gautam60e01352012-05-29 09:00:34 +05302375 }
2376
2377 ret = dwc3_hsusb_config_vddcx(1);
2378 if (ret) {
2379 dev_err(&pdev->dev, "hsusb vddcx configuration failed\n");
2380 goto disable_ss_ldo;
2381 }
2382
2383 ret = regulator_enable(context->hsusb_vddcx);
2384 if (ret) {
2385 dev_err(&pdev->dev, "unable to enable the hsusb vddcx\n");
2386 goto unconfig_hs_vddcx;
2387 }
2388
2389 ret = dwc3_hsusb_ldo_init(1);
2390 if (ret) {
2391 dev_err(&pdev->dev, "hsusb vreg configuration failed\n");
2392 goto disable_hs_vddcx;
2393 }
2394
2395 ret = dwc3_hsusb_ldo_enable(1);
2396 if (ret) {
2397 dev_err(&pdev->dev, "hsusb vreg enable failed\n");
2398 goto free_hs_ldo_init;
2399 }
2400
Jack Pham5c585062013-03-25 18:39:12 -07002401 msm->id_state = msm->ext_xceiv.id = DWC3_ID_FLOAT;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302402 msm->ext_xceiv.otg_capability = of_property_read_bool(node,
Manu Gautam6c0ff032012-11-02 14:55:35 +05302403 "qcom,otg-capability");
2404 msm->charger.charging_disabled = of_property_read_bool(node,
2405 "qcom,charging-disabled");
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302406
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05302407 /*
2408 * DWC3 has separate IRQ line for OTG events (ID/BSV) and for
2409 * DP and DM linestate transitions during low power mode.
2410 */
2411 msm->hs_phy_irq = platform_get_irq_byname(pdev, "hs_phy_irq");
2412 if (msm->hs_phy_irq < 0) {
2413 dev_dbg(&pdev->dev, "pget_irq for hs_phy_irq failed\n");
2414 msm->hs_phy_irq = 0;
Jack Pham0fc12332012-11-19 13:14:22 -08002415 } else {
Jack Pham56a0a632013-03-08 13:18:42 -08002416 ret = devm_request_irq(&pdev->dev, msm->hs_phy_irq,
2417 msm_dwc3_irq, IRQF_TRIGGER_RISING,
2418 "msm_dwc3", msm);
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05302419 if (ret) {
2420 dev_err(&pdev->dev, "irqreq HSPHYINT failed\n");
2421 goto disable_hs_ldo;
2422 }
2423 enable_irq_wake(msm->hs_phy_irq);
2424 }
Jack Pham0cca9412013-03-08 13:22:42 -08002425
Vijayavardhan Vennapusa45145882013-01-03 14:11:58 +05302426 if (msm->ext_xceiv.otg_capability) {
Jack Pham0cca9412013-03-08 13:22:42 -08002427 msm->pmic_id_irq = platform_get_irq_byname(pdev, "pmic_id_irq");
2428 if (msm->pmic_id_irq > 0) {
David Keitelad4a0282013-03-19 18:04:27 -07002429 /* check if PMIC ID IRQ is supported */
2430 ret = qpnp_misc_irqs_available(&pdev->dev);
2431
2432 if (ret == -EPROBE_DEFER) {
2433 /* qpnp hasn't probed yet; defer dwc probe */
Jack Pham0cca9412013-03-08 13:22:42 -08002434 goto disable_hs_ldo;
David Keitelad4a0282013-03-19 18:04:27 -07002435 } else if (ret == 0) {
2436 msm->pmic_id_irq = 0;
2437 } else {
2438 ret = devm_request_irq(&pdev->dev,
2439 msm->pmic_id_irq,
2440 dwc3_pmic_id_irq,
2441 IRQF_TRIGGER_RISING |
2442 IRQF_TRIGGER_FALLING,
2443 "dwc3_msm_pmic_id", msm);
2444 if (ret) {
2445 dev_err(&pdev->dev, "irqreq IDINT failed\n");
2446 goto disable_hs_ldo;
2447 }
Jack Pham9198d9f2013-04-09 17:54:54 -07002448
Manu Gautamf08f7b62013-04-02 16:09:42 +05302449 local_irq_save(flags);
2450 /* Update initial ID state */
Jack Pham9198d9f2013-04-09 17:54:54 -07002451 msm->id_state =
Manu Gautamf08f7b62013-04-02 16:09:42 +05302452 !!irq_read_line(msm->pmic_id_irq);
Jack Pham9198d9f2013-04-09 17:54:54 -07002453 if (msm->id_state == DWC3_ID_GROUND)
2454 queue_work(system_nrt_wq,
2455 &msm->id_work);
Manu Gautamf08f7b62013-04-02 16:09:42 +05302456 local_irq_restore(flags);
David Keitelad4a0282013-03-19 18:04:27 -07002457 enable_irq_wake(msm->pmic_id_irq);
Jack Pham0cca9412013-03-08 13:22:42 -08002458 }
David Keitelad4a0282013-03-19 18:04:27 -07002459 }
2460
2461 if (msm->pmic_id_irq <= 0) {
Jack Pham0cca9412013-03-08 13:22:42 -08002462 /* If no PMIC ID IRQ, use ADC for ID pin detection */
2463 queue_work(system_nrt_wq, &msm->init_adc_work.work);
2464 device_create_file(&pdev->dev, &dev_attr_adc_enable);
2465 msm->pmic_id_irq = 0;
2466 }
Manu Gautam377821c2012-09-28 16:53:24 +05302467 }
2468
Ido Shayevitz7ad8ded2012-08-28 04:30:58 +03002469 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2470 if (!res) {
2471 dev_dbg(&pdev->dev, "missing TCSR memory resource\n");
2472 } else {
2473 tcsr = devm_ioremap_nocache(&pdev->dev, res->start,
2474 resource_size(res));
2475 if (!tcsr) {
2476 dev_dbg(&pdev->dev, "tcsr ioremap failed\n");
2477 } else {
2478 /* Enable USB3 on the primary USB port. */
2479 writel_relaxed(0x1, tcsr);
2480 /*
2481 * Ensure that TCSR write is completed before
2482 * USB registers initialization.
2483 */
2484 mb();
2485 }
2486 }
2487
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002488 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2489 if (!res) {
2490 dev_err(&pdev->dev, "missing memory base resource\n");
Manu Gautam60e01352012-05-29 09:00:34 +05302491 ret = -ENODEV;
Jack Pham56a0a632013-03-08 13:18:42 -08002492 goto disable_hs_ldo;
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002493 }
2494
2495 msm->base = devm_ioremap_nocache(&pdev->dev, res->start,
2496 resource_size(res));
2497 if (!msm->base) {
2498 dev_err(&pdev->dev, "ioremap failed\n");
Manu Gautam60e01352012-05-29 09:00:34 +05302499 ret = -ENODEV;
Jack Pham56a0a632013-03-08 13:18:42 -08002500 goto disable_hs_ldo;
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002501 }
2502
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002503 msm->resource_size = resource_size(res);
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002504
Vijayavardhan Vennapusa26a49602012-12-18 13:51:45 +05302505 if (of_property_read_u32(node, "qcom,dwc-hsphy-init",
2506 &msm->hsphy_init_seq))
2507 dev_dbg(&pdev->dev, "unable to read hsphy init seq\n");
2508 else if (!msm->hsphy_init_seq)
2509 dev_warn(&pdev->dev, "incorrect hsphyinitseq.Using PORvalue\n");
2510
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05302511 dwc3_msm_qscratch_reg_init(msm);
Vijayavardhan Vennapusad81aed32012-12-05 17:30:40 +05302512
Manu Gautamb5067272012-07-02 09:53:41 +05302513 pm_runtime_set_active(msm->dev);
Manu Gautam377821c2012-09-28 16:53:24 +05302514 pm_runtime_enable(msm->dev);
Manu Gautamb5067272012-07-02 09:53:41 +05302515
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002516 if (of_property_read_u32(node, "qcom,dwc-usb3-msm-dbm-eps",
2517 &msm->dbm_num_eps)) {
2518 dev_err(&pdev->dev,
2519 "unable to read platform data num of dbm eps\n");
2520 msm->dbm_num_eps = DBM_MAX_EPS;
2521 }
2522
2523 if (msm->dbm_num_eps > DBM_MAX_EPS) {
2524 dev_err(&pdev->dev,
2525 "Driver doesn't support number of DBM EPs. "
2526 "max: %d, dbm_num_eps: %d\n",
2527 DBM_MAX_EPS, msm->dbm_num_eps);
2528 ret = -ENODEV;
Vijayavardhan Vennapusa8eb68732013-03-26 13:05:38 +05302529 goto disable_hs_ldo;
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002530 }
2531
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302532 msm->usb_psy.name = "usb";
2533 msm->usb_psy.type = POWER_SUPPLY_TYPE_USB;
2534 msm->usb_psy.supplied_to = dwc3_msm_pm_power_supplied_to;
2535 msm->usb_psy.num_supplicants = ARRAY_SIZE(
2536 dwc3_msm_pm_power_supplied_to);
2537 msm->usb_psy.properties = dwc3_msm_pm_power_props_usb;
2538 msm->usb_psy.num_properties = ARRAY_SIZE(dwc3_msm_pm_power_props_usb);
2539 msm->usb_psy.get_property = dwc3_msm_power_get_property_usb;
2540 msm->usb_psy.set_property = dwc3_msm_power_set_property_usb;
Jack Pham9354c6a2012-12-20 19:19:32 -08002541 msm->usb_psy.external_power_changed =
2542 dwc3_msm_external_power_changed;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302543
2544 ret = power_supply_register(&pdev->dev, &msm->usb_psy);
2545 if (ret < 0) {
2546 dev_err(&pdev->dev,
2547 "%s:power_supply_register usb failed\n",
2548 __func__);
Vijayavardhan Vennapusa8eb68732013-03-26 13:05:38 +05302549 goto disable_hs_ldo;
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302550 }
2551
Vijayavardhan Vennapusa8eb68732013-03-26 13:05:38 +05302552 if (node) {
2553 ret = of_platform_populate(node, NULL, NULL, &pdev->dev);
2554 if (ret) {
2555 dev_err(&pdev->dev,
2556 "failed to add create dwc3 core\n");
2557 goto put_psupply;
2558 }
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002559 }
2560
Manu Gautam2617deb2012-08-31 17:50:06 -07002561 msm->bus_scale_table = msm_bus_cl_get_pdata(pdev);
2562 if (!msm->bus_scale_table) {
2563 dev_err(&pdev->dev, "bus scaling is disabled\n");
2564 } else {
2565 msm->bus_perf_client =
2566 msm_bus_scale_register_client(msm->bus_scale_table);
2567 ret = msm_bus_scale_client_update_request(
2568 msm->bus_perf_client, 1);
2569 if (ret)
2570 dev_err(&pdev->dev, "Failed to vote for bus scaling\n");
2571 }
2572
Manu Gautam8c642812012-06-07 10:35:10 +05302573 msm->otg_xceiv = usb_get_transceiver();
2574 if (msm->otg_xceiv) {
2575 msm->charger.start_detection = dwc3_start_chg_det;
2576 ret = dwc3_set_charger(msm->otg_xceiv->otg, &msm->charger);
2577 if (ret || !msm->charger.notify_detection_complete) {
2578 dev_err(&pdev->dev, "failed to register charger: %d\n",
2579 ret);
2580 goto put_xcvr;
2581 }
Manu Gautamb5067272012-07-02 09:53:41 +05302582
Vijayavardhan Vennapusab7434562012-12-12 16:48:49 +05302583 if (msm->ext_xceiv.otg_capability)
2584 msm->ext_xceiv.ext_block_reset = dwc3_msm_block_reset;
Manu Gautamb5067272012-07-02 09:53:41 +05302585 ret = dwc3_set_ext_xceiv(msm->otg_xceiv->otg, &msm->ext_xceiv);
2586 if (ret || !msm->ext_xceiv.notify_ext_events) {
2587 dev_err(&pdev->dev, "failed to register xceiver: %d\n",
2588 ret);
2589 goto put_xcvr;
2590 }
Manu Gautam8c642812012-06-07 10:35:10 +05302591 } else {
2592 dev_err(&pdev->dev, "%s: No OTG transceiver found\n", __func__);
2593 }
2594
Manu Gautamb5067272012-07-02 09:53:41 +05302595 wake_lock_init(&msm->wlock, WAKE_LOCK_SUSPEND, "msm_dwc3");
2596 wake_lock(&msm->wlock);
2597 dwc3_debugfs_init(msm);
2598
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002599 return 0;
2600
Manu Gautam8c642812012-06-07 10:35:10 +05302601put_xcvr:
2602 usb_put_transceiver(msm->otg_xceiv);
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302603put_psupply:
2604 power_supply_unregister(&msm->usb_psy);
Manu Gautam60e01352012-05-29 09:00:34 +05302605disable_hs_ldo:
2606 dwc3_hsusb_ldo_enable(0);
2607free_hs_ldo_init:
2608 dwc3_hsusb_ldo_init(0);
2609disable_hs_vddcx:
2610 regulator_disable(context->hsusb_vddcx);
2611unconfig_hs_vddcx:
2612 dwc3_hsusb_config_vddcx(0);
2613disable_ss_ldo:
2614 dwc3_ssusb_ldo_enable(0);
2615free_ss_ldo_init:
2616 dwc3_ssusb_ldo_init(0);
2617disable_ss_vddcx:
2618 regulator_disable(context->ssusb_vddcx);
2619unconfig_ss_vddcx:
2620 dwc3_ssusb_config_vddcx(0);
Manu Gautam3e9ad352012-08-16 14:44:47 -07002621disable_ref_clk:
2622 clk_disable_unprepare(msm->ref_clk);
Jack Pham22698b82013-02-13 17:45:06 -08002623disable_utmi_clk:
2624 clk_disable_unprepare(msm->utmi_clk);
Manu Gautam3e9ad352012-08-16 14:44:47 -07002625disable_sleep_a_clk:
2626 clk_disable_unprepare(msm->hsphy_sleep_clk);
2627disable_sleep_clk:
2628 clk_disable_unprepare(msm->sleep_clk);
2629disable_iface_clk:
2630 clk_disable_unprepare(msm->iface_clk);
Manu Gautam1742db22012-06-19 13:33:24 +05302631disable_core_clk:
2632 clk_disable_unprepare(msm->core_clk);
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05302633disable_xo:
2634 clk_disable_unprepare(msm->xo_clk);
2635put_xo:
2636 clk_put(msm->xo_clk);
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002637
2638 return ret;
2639}
2640
2641static int __devexit dwc3_msm_remove(struct platform_device *pdev)
2642{
2643 struct dwc3_msm *msm = platform_get_drvdata(pdev);
2644
Jack Pham0fc12332012-11-19 13:14:22 -08002645 if (msm->id_adc_detect)
2646 qpnp_adc_tm_usbid_end();
Manu Gautamb5067272012-07-02 09:53:41 +05302647 if (dwc3_debugfs_root)
2648 debugfs_remove_recursive(dwc3_debugfs_root);
Manu Gautam8c642812012-06-07 10:35:10 +05302649 if (msm->otg_xceiv) {
2650 dwc3_start_chg_det(&msm->charger, false);
2651 usb_put_transceiver(msm->otg_xceiv);
2652 }
Jack Pham0fc12332012-11-19 13:14:22 -08002653
Manu Gautamb5067272012-07-02 09:53:41 +05302654 pm_runtime_disable(msm->dev);
Manu Gautamb5067272012-07-02 09:53:41 +05302655 wake_lock_destroy(&msm->wlock);
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002656
Manu Gautam60e01352012-05-29 09:00:34 +05302657 dwc3_hsusb_ldo_enable(0);
2658 dwc3_hsusb_ldo_init(0);
2659 regulator_disable(msm->hsusb_vddcx);
2660 dwc3_hsusb_config_vddcx(0);
2661 dwc3_ssusb_ldo_enable(0);
2662 dwc3_ssusb_ldo_init(0);
2663 regulator_disable(msm->ssusb_vddcx);
2664 dwc3_ssusb_config_vddcx(0);
Manu Gautam1742db22012-06-19 13:33:24 +05302665 clk_disable_unprepare(msm->core_clk);
Manu Gautam3e9ad352012-08-16 14:44:47 -07002666 clk_disable_unprepare(msm->iface_clk);
2667 clk_disable_unprepare(msm->sleep_clk);
2668 clk_disable_unprepare(msm->hsphy_sleep_clk);
2669 clk_disable_unprepare(msm->ref_clk);
Vijayavardhan Vennapusadec1fe62013-02-12 16:05:14 +05302670 clk_disable_unprepare(msm->xo_clk);
2671 clk_put(msm->xo_clk);
Manu Gautam60e01352012-05-29 09:00:34 +05302672
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002673 return 0;
2674}
2675
Manu Gautamb5067272012-07-02 09:53:41 +05302676static int dwc3_msm_pm_suspend(struct device *dev)
2677{
2678 int ret = 0;
2679 struct dwc3_msm *mdwc = dev_get_drvdata(dev);
2680
2681 dev_dbg(dev, "dwc3-msm PM suspend\n");
2682
Manu Gautam8d98a572013-01-21 16:34:50 +05302683 flush_delayed_work_sync(&mdwc->resume_work);
2684 if (!atomic_read(&mdwc->in_lpm)) {
2685 dev_err(mdwc->dev, "Abort PM suspend!! (USB is outside LPM)\n");
2686 return -EBUSY;
2687 }
2688
Manu Gautamb5067272012-07-02 09:53:41 +05302689 ret = dwc3_msm_suspend(mdwc);
2690 if (!ret)
2691 atomic_set(&mdwc->pm_suspended, 1);
2692
2693 return ret;
2694}
2695
2696static int dwc3_msm_pm_resume(struct device *dev)
2697{
2698 int ret = 0;
2699 struct dwc3_msm *mdwc = dev_get_drvdata(dev);
2700
2701 dev_dbg(dev, "dwc3-msm PM resume\n");
2702
2703 atomic_set(&mdwc->pm_suspended, 0);
2704 if (mdwc->resume_pending) {
2705 mdwc->resume_pending = false;
2706
2707 ret = dwc3_msm_resume(mdwc);
2708 /* Update runtime PM status */
2709 pm_runtime_disable(dev);
2710 pm_runtime_set_active(dev);
2711 pm_runtime_enable(dev);
2712
2713 /* Let OTG know about resume event and update pm_count */
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302714 if (mdwc->otg_xceiv) {
Manu Gautamb5067272012-07-02 09:53:41 +05302715 mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg,
2716 DWC3_EVENT_PHY_RESUME);
Vijayavardhan Vennapusad2993b82012-10-22 13:08:21 +05302717 if (mdwc->ext_xceiv.otg_capability)
2718 mdwc->ext_xceiv.notify_ext_events(
2719 mdwc->otg_xceiv->otg,
2720 DWC3_EVENT_XCEIV_STATE);
2721 }
Manu Gautamb5067272012-07-02 09:53:41 +05302722 }
2723
2724 return ret;
2725}
2726
2727static int dwc3_msm_runtime_idle(struct device *dev)
2728{
2729 dev_dbg(dev, "DWC3-msm runtime idle\n");
2730
2731 return 0;
2732}
2733
2734static int dwc3_msm_runtime_suspend(struct device *dev)
2735{
2736 struct dwc3_msm *mdwc = dev_get_drvdata(dev);
2737
2738 dev_dbg(dev, "DWC3-msm runtime suspend\n");
2739
2740 return dwc3_msm_suspend(mdwc);
2741}
2742
2743static int dwc3_msm_runtime_resume(struct device *dev)
2744{
2745 struct dwc3_msm *mdwc = dev_get_drvdata(dev);
2746
2747 dev_dbg(dev, "DWC3-msm runtime resume\n");
2748
2749 return dwc3_msm_resume(mdwc);
2750}
2751
2752static const struct dev_pm_ops dwc3_msm_dev_pm_ops = {
2753 SET_SYSTEM_SLEEP_PM_OPS(dwc3_msm_pm_suspend, dwc3_msm_pm_resume)
2754 SET_RUNTIME_PM_OPS(dwc3_msm_runtime_suspend, dwc3_msm_runtime_resume,
2755 dwc3_msm_runtime_idle)
2756};
2757
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002758static const struct of_device_id of_dwc3_matach[] = {
2759 {
2760 .compatible = "qcom,dwc-usb3-msm",
2761 },
2762 { },
2763};
2764MODULE_DEVICE_TABLE(of, of_dwc3_matach);
2765
2766static struct platform_driver dwc3_msm_driver = {
2767 .probe = dwc3_msm_probe,
2768 .remove = __devexit_p(dwc3_msm_remove),
2769 .driver = {
2770 .name = "msm-dwc3",
Manu Gautamb5067272012-07-02 09:53:41 +05302771 .pm = &dwc3_msm_dev_pm_ops,
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002772 .of_match_table = of_dwc3_matach,
2773 },
2774};
2775
Manu Gautam377821c2012-09-28 16:53:24 +05302776MODULE_LICENSE("GPL v2");
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02002777MODULE_DESCRIPTION("DesignWare USB3 MSM Glue Layer");
2778
2779static int __devinit dwc3_msm_init(void)
2780{
2781 return platform_driver_register(&dwc3_msm_driver);
2782}
2783module_init(dwc3_msm_init);
2784
2785static void __exit dwc3_msm_exit(void)
2786{
2787 platform_driver_unregister(&dwc3_msm_driver);
2788}
2789module_exit(dwc3_msm_exit);