blob: 44fe134dc601ad3d10d932e8f3cde70326c74c51 [file] [log] [blame]
Shimrit Malichidbf43d72013-03-16 03:32:27 +02001/* include/linux/usb/msm_hsusb.h
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05302 *
3 * Copyright (C) 2008 Google, Inc.
4 * Author: Brian Swetland <swetland@google.com>
Saket Saurabh2558ea02014-01-10 16:14:27 +05305 * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05306 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#ifndef __ASM_ARCH_MSM_HSUSB_H
19#define __ASM_ARCH_MSM_HSUSB_H
20
21#include <linux/types.h>
Ido Shayevitz9fb83452012-04-01 17:45:58 +030022#include <linux/usb/ch9.h>
23#include <linux/usb/gadget.h>
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053024#include <linux/usb/otg.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025#include <linux/wakelock.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070026#include <linux/pm_qos.h>
Ido Shayevitz5a6178b2012-06-10 16:31:13 +030027#include <linux/hrtimer.h>
David Keitel272ce522012-08-17 16:25:24 -070028#include <linux/power_supply.h>
Pavankumar Kondetif1ffbdd2013-06-27 13:31:36 +053029#include <linux/cdev.h>
Ido Shayevitzd1cb16c2012-03-28 18:57:47 +020030/*
31 * The following are bit fields describing the usb_request.udc_priv word.
32 * These bit fields are set by function drivers that wish to queue
33 * usb_requests with sps/bam parameters.
34 */
35#define MSM_PIPE_ID_MASK (0x1F)
36#define MSM_TX_PIPE_ID_OFS (16)
37#define MSM_SPS_MODE BIT(5)
38#define MSM_IS_FINITE_TRANSFER BIT(6)
39#define MSM_PRODUCER BIT(7)
40#define MSM_DISABLE_WB BIT(8)
41#define MSM_ETD_IOC BIT(9)
42#define MSM_INTERNAL_MEM BIT(10)
43#define MSM_VENDOR_ID BIT(16)
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053044
45/**
Manu Gautame3a39082013-06-11 10:42:56 +053046 * Requested USB votes for BUS bandwidth
47 *
48 * USB_NO_PERF_VOTE BUS Vote for inactive USB session or disconnect
49 * USB_MAX_PERF_VOTE Maximum BUS bandwidth vote
50 * USB_MIN_PERF_VOTE Minimum BUS bandwidth vote (for some hw same as NO_PERF)
51 *
52 */
53enum usb_bus_vote {
54 USB_NO_PERF_VOTE = 0,
55 USB_MAX_PERF_VOTE,
56 USB_MIN_PERF_VOTE,
57};
58
59/**
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053060 * Supported USB modes
61 *
62 * USB_PERIPHERAL Only peripheral mode is supported.
63 * USB_HOST Only host mode is supported.
64 * USB_OTG OTG mode is supported.
65 *
66 */
67enum usb_mode_type {
68 USB_NONE = 0,
69 USB_PERIPHERAL,
70 USB_HOST,
71 USB_OTG,
72};
73
74/**
75 * OTG control
76 *
77 * OTG_NO_CONTROL Id/VBUS notifications not required. Useful in host
78 * only configuration.
79 * OTG_PHY_CONTROL Id/VBUS notifications comes form USB PHY.
80 * OTG_PMIC_CONTROL Id/VBUS notifications comes from PMIC hardware.
81 * OTG_USER_CONTROL Id/VBUS notifcations comes from User via sysfs.
82 *
83 */
84enum otg_control_type {
85 OTG_NO_CONTROL = 0,
86 OTG_PHY_CONTROL,
87 OTG_PMIC_CONTROL,
88 OTG_USER_CONTROL,
89};
90
91/**
Pavankumar Kondetid8608522011-05-04 10:19:47 +053092 * PHY used in
93 *
94 * INVALID_PHY Unsupported PHY
95 * CI_45NM_INTEGRATED_PHY Chipidea 45nm integrated PHY
96 * SNPS_28NM_INTEGRATED_PHY Synopsis 28nm integrated PHY
97 *
98 */
99enum msm_usb_phy_type {
100 INVALID_PHY = 0,
101 CI_45NM_INTEGRATED_PHY,
102 SNPS_28NM_INTEGRATED_PHY,
103};
104
105#define IDEV_CHG_MAX 1500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700106#define IDEV_CHG_MIN 500
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530107#define IUNIT 100
108
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530109#define IDEV_ACA_CHG_MAX 1500
110#define IDEV_ACA_CHG_LIMIT 500
111
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530112/**
113 * Different states involved in USB charger detection.
114 *
115 * USB_CHG_STATE_UNDEFINED USB charger is not connected or detection
116 * process is not yet started.
117 * USB_CHG_STATE_WAIT_FOR_DCD Waiting for Data pins contact.
118 * USB_CHG_STATE_DCD_DONE Data pin contact is detected.
119 * USB_CHG_STATE_PRIMARY_DONE Primary detection is completed (Detects
120 * between SDP and DCP/CDP).
121 * USB_CHG_STATE_SECONDARY_DONE Secondary detection is completed (Detects
122 * between DCP and CDP).
123 * USB_CHG_STATE_DETECTED USB charger type is determined.
124 *
125 */
126enum usb_chg_state {
127 USB_CHG_STATE_UNDEFINED = 0,
128 USB_CHG_STATE_WAIT_FOR_DCD,
129 USB_CHG_STATE_DCD_DONE,
130 USB_CHG_STATE_PRIMARY_DONE,
131 USB_CHG_STATE_SECONDARY_DONE,
132 USB_CHG_STATE_DETECTED,
133};
134
135/**
136 * USB charger types
137 *
138 * USB_INVALID_CHARGER Invalid USB charger.
139 * USB_SDP_CHARGER Standard downstream port. Refers to a downstream port
140 * on USB2.0 compliant host/hub.
141 * USB_DCP_CHARGER Dedicated charger port (AC charger/ Wall charger).
142 * USB_CDP_CHARGER Charging downstream port. Enumeration can happen and
143 * IDEV_CHG_MAX can be drawn irrespective of USB state.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700144 * USB_ACA_A_CHARGER B-device is connected on accessory port with charger
145 * connected on charging port. This configuration allows
146 * charging in host mode.
147 * USB_ACA_B_CHARGER No device (or A-device without VBUS) is connected on
148 * accessory port with charger connected on charging port.
149 * USB_ACA_C_CHARGER A-device (with VBUS) is connected on
150 * accessory port with charger connected on charging port.
151 * USB_ACA_DOCK_CHARGER A docking station that has one upstream port and one
152 * or more downstream ports. Capable of supplying
153 * IDEV_CHG_MAX irrespective of devices connected on
154 * accessory ports.
Pavankumar Kondeti9ec21d32012-05-07 15:50:23 +0530155 * USB_PROPRIETARY_CHARGER A proprietary charger pull DP and DM to specific
156 * voltages between 2.0-3.3v for identification.
157 *
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530158 */
159enum usb_chg_type {
160 USB_INVALID_CHARGER = 0,
161 USB_SDP_CHARGER,
162 USB_DCP_CHARGER,
163 USB_CDP_CHARGER,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164 USB_ACA_A_CHARGER,
165 USB_ACA_B_CHARGER,
166 USB_ACA_C_CHARGER,
167 USB_ACA_DOCK_CHARGER,
Pavankumar Kondeti9ec21d32012-05-07 15:50:23 +0530168 USB_PROPRIETARY_CHARGER,
zhenhuahb6d5edc2013-06-19 14:37:32 +0800169 USB_FLOATED_CHARGER,
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530170};
171
172/**
Mayank Rana248698c2012-04-19 00:03:16 +0530173 * Used different VDDCX voltage voting mechnism
174 * VDDCX_CORNER Vote for VDDCX Corner voltage
175 * VDDCX Vote for VDDCX Absolute voltage
176 */
177enum usb_vdd_type {
178 VDDCX_CORNER = 0,
179 VDDCX,
180 VDD_TYPE_MAX,
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530181};
182
183/**
Amit Blayd6ea6102012-06-07 16:26:24 +0300184 * Used different VDDCX voltage values
185 */
186enum usb_vdd_value {
187 VDD_NONE = 0,
188 VDD_MIN,
189 VDD_MAX,
190 VDD_VAL_MAX,
191};
192
193/**
Saket Saurabh48848182014-05-23 15:15:02 +0530194 * Maintain state for hvdcp external charger status
195 * DEFAULT This is used when DCP is detected
196 * ACTIVE This is used when ioctl is called to block LPM
197 * INACTIVE This is used when ioctl is called to unblock LPM
198 */
199
200enum usb_ext_chg_status {
201 DEFAULT = 1,
202 ACTIVE,
203 INACTIVE,
204};
205
206
207/**
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530208 * struct msm_otg_platform_data - platform device data
Pavankumar Kondetidfb21302011-03-04 22:45:02 +0530209 * for msm_otg driver.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530210 * @phy_init_seq: PHY configuration sequence. val, reg pairs
211 * terminated by -1.
Mayank Rana8549e632012-01-23 12:49:54 +0530212 * @vbus_power: VBUS power on/off routine.It should return result
213 * as success(zero value) or failure(non-zero value).
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530214 * @power_budget: VBUS power budget in mA (0 will be treated as 500mA).
215 * @mode: Supported mode (OTG/peripheral/host).
216 * @otg_control: OTG switch controlled by user/Id pin
217 * @default_mode: Default operational mode. Applicable only if
218 * OTG switch is controller by user.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219 * @pmic_id_irq: IRQ number assigned for PMIC USB ID line.
Jack Pham87f202f2012-08-06 00:24:22 -0700220 * @mpm_otgsessvld_int: MPM wakeup pin assigned for OTG SESSVLD
221 * interrupt. Used when .otg_control == OTG_PHY_CONTROL.
Vijayavardhan Vennapusa2239b2b2013-06-28 13:16:29 +0530222 * @mpm_dpshv_int: MPM wakeup pin assigned for DP SHV interrupt.
223 * Used during host bus suspend.
224 * @mpm_dmshv_int: MPM wakeup pin assigned for DM SHV interrupt.
225 * Used during host bus suspend.
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530226 * @mhl_enable: indicates MHL connector or not.
Ofir Cohen4da266f2012-01-03 10:19:29 +0200227 * @disable_reset_on_disconnect: perform USB PHY and LINK reset
228 * on USB cable disconnection.
Manu Gautam0ddbd922012-09-21 17:17:38 +0530229 * @pnoc_errata_fix: workaround needed for PNOC hardware bug that
230 * affects USB performance.
Amit Blay6fa647a2012-05-24 14:12:08 +0300231 * @enable_lpm_on_suspend: Enable the USB core to go into Low
232 * Power Mode, when USB bus is suspended but cable
233 * is connected.
Amit Blay9b6e58b2012-06-18 13:12:49 +0300234 * @core_clk_always_on_workaround: Don't disable core_clk when
235 * USB enters LPM.
Amit Blayd6f38282012-10-29 13:13:46 +0200236 * @delay_lpm_on_disconnect: Use a delay before entering LPM
237 * upon USB cable disconnection.
Manu Gautam0fd2d0e2013-03-26 18:09:11 +0530238 * @enable_sec_phy: Use second HSPHY with USB2 core
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530239 * @bus_scale_table: parameters for bus bandwidth requirements
Pavankumar Kondeti2aec9f32012-06-13 09:06:03 +0530240 * @mhl_dev_name: MHL device name used to register with MHL driver.
Amit Blayb4f14532013-06-17 22:33:57 +0300241 * @log2_itc: value of 2^(log2_itc-1) will be used as the
242 * interrupt threshold (ITC), when log2_itc is
243 * between 1 to 7.
Shimrit Malichi5a2d5b52013-06-20 19:04:28 +0300244 * @l1_supported: enable link power management support.
Vijayavardhan Vennapusa8997e332013-07-15 09:53:51 +0530245 * @dpdm_pulldown_added: Indicates whether pull down resistors are
Mayank Rana34f6f3e2013-11-11 12:40:00 +0530246 * connected on data lines or not.
247 * @enable_ahb2ahb_bypass: Indicates whether enable AHB2AHB BYPASS
248 * mode with controller in device mode.
Saket Saurabhb06a8c62013-11-25 15:17:23 +0530249 * @disable_retention_with_vdd_min: Indicates whether to enable allowing
250 * VDD min without putting PHY into retention
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530251 */
252struct msm_otg_platform_data {
253 int *phy_init_seq;
Mayank Rana8549e632012-01-23 12:49:54 +0530254 int (*vbus_power)(bool on);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530255 unsigned power_budget;
256 enum usb_mode_type mode;
257 enum otg_control_type otg_control;
258 enum usb_mode_type default_mode;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530259 enum msm_usb_phy_type phy_type;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530260 void (*setup_gpio)(enum usb_otg_state state);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700261 int pmic_id_irq;
Jack Pham87f202f2012-08-06 00:24:22 -0700262 unsigned int mpm_otgsessvld_int;
Vijayavardhan Vennapusa2239b2b2013-06-28 13:16:29 +0530263 unsigned int mpm_dpshv_int;
264 unsigned int mpm_dmshv_int;
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530265 bool mhl_enable;
Ofir Cohen4da266f2012-01-03 10:19:29 +0200266 bool disable_reset_on_disconnect;
Manu Gautam0ddbd922012-09-21 17:17:38 +0530267 bool pnoc_errata_fix;
Amit Blay6fa647a2012-05-24 14:12:08 +0300268 bool enable_lpm_on_dev_suspend;
Amit Blay9b6e58b2012-06-18 13:12:49 +0300269 bool core_clk_always_on_workaround;
Amit Blayd6f38282012-10-29 13:13:46 +0200270 bool delay_lpm_on_disconnect;
Lena Salmanabde35d2013-04-25 15:29:43 +0300271 bool delay_lpm_hndshk_on_disconnect;
Vamsi Krishna1a1684b2013-03-02 16:14:52 -0800272 bool dp_manual_pullup;
Manu Gautam0fd2d0e2013-03-26 18:09:11 +0530273 bool enable_sec_phy;
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530274 struct msm_bus_scale_pdata *bus_scale_table;
Pavankumar Kondeti2aec9f32012-06-13 09:06:03 +0530275 const char *mhl_dev_name;
Amit Blayb4f14532013-06-17 22:33:57 +0300276 int log2_itc;
Shimrit Malichi5a2d5b52013-06-20 19:04:28 +0300277 bool l1_supported;
Vijayavardhan Vennapusa8997e332013-07-15 09:53:51 +0530278 bool dpdm_pulldown_added;
Mayank Rana34f6f3e2013-11-11 12:40:00 +0530279 bool enable_ahb2ahb_bypass;
Saket Saurabhb06a8c62013-11-25 15:17:23 +0530280 bool disable_retention_with_vdd_min;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530281};
282
Vamsi Krishna1a1684b2013-03-02 16:14:52 -0800283/* phy related flags */
284#define ENABLE_DP_MANUAL_PULLUP BIT(0)
Manu Gautam0fd2d0e2013-03-26 18:09:11 +0530285#define ENABLE_SECONDARY_PHY BIT(1)
Vamsi Krishna1a1684b2013-03-02 16:14:52 -0800286
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530287/* Timeout (in msec) values (min - max) associated with OTG timers */
288
289#define TA_WAIT_VRISE 100 /* ( - 100) */
290#define TA_WAIT_VFALL 500 /* ( - 1000) */
291
292/*
293 * This option is set for embedded hosts or OTG devices in which leakage
294 * currents are very minimal.
295 */
296#ifdef CONFIG_USB_OTG
297#define TA_WAIT_BCON 30000 /* (1100 - 30000) */
298#else
299#define TA_WAIT_BCON -1
300#endif
301
302#define TA_AIDL_BDIS 500 /* (200 - ) */
303#define TA_BIDL_ADIS 155 /* (155 - 200) */
304#define TB_SRP_FAIL 6000 /* (5000 - 6000) */
305#define TB_ASE0_BRST 200 /* (155 - ) */
306
307/* TB_SSEND_SRP and TB_SE0_SRP are combined */
308#define TB_SRP_INIT 2000 /* (1500 - ) */
309
310#define TA_TST_MAINT 10100 /* (9900 - 10100) */
311#define TB_TST_SRP 3000 /* ( - 5000) */
312#define TB_TST_CONFIG 300
313
314/* Timeout variables */
315
316#define A_WAIT_VRISE 0
317#define A_WAIT_VFALL 1
318#define A_WAIT_BCON 2
319#define A_AIDL_BDIS 3
320#define A_BIDL_ADIS 4
321#define B_SRP_FAIL 5
322#define B_ASE0_BRST 6
323#define A_TST_MAINT 7
324#define B_TST_SRP 8
325#define B_TST_CONFIG 9
326
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530327/**
328 * struct msm_otg: OTG driver data. Shared by HCD and DCD.
329 * @otg: USB OTG Transceiver structure.
330 * @pdata: otg device platform data.
331 * @irq: IRQ number assigned for HSUSB controller.
Manu Gautamf8c45642012-08-10 10:20:56 -0700332 * @async_irq: IRQ number used by some controllers during low power state
Manu Gautam5143b252012-01-05 19:25:23 -0800333 * @clk: clock struct of alt_core_clk.
334 * @pclk: clock struct of iface_clk.
Manu Gautam5143b252012-01-05 19:25:23 -0800335 * @core_clk: clock struct of core_bus_clk.
Mayank Ranadd1f1dc2013-07-24 17:02:45 +0530336 * @sleep_clk: clock struct of sleep_clk for USB PHY.
Mayank Rana3eaf28d2013-03-27 14:04:04 +0530337 * @core_clk_rate: core clk max frequency
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530338 * @regs: ioremapped register base address.
339 * @inputs: OTG state machine inputs(Id, SessValid etc).
340 * @sm_work: OTG state machine work.
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530341 * @in_lpm: indicates low power mode (LPM) state.
Manu Gautamf8c45642012-08-10 10:20:56 -0700342 * @async_int: IRQ line on which ASYNC interrupt arrived in LPM.
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530343 * @cur_power: The amount of mA available from downstream port.
344 * @chg_work: Charger detection work.
345 * @chg_state: The state of charger detection process.
346 * @chg_type: The type of charger attached.
347 * @dcd_retires: The retry count used to track Data contact
348 * detection process.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700349 * @wlock: Wake lock struct to prevent system suspend when
350 * USB is active.
351 * @usbdev_nb: The notifier block used to know about the B-device
352 * connected. Useful only when ACA_A charger is
353 * connected.
354 * @mA_port: The amount of current drawn by the attached B-device.
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530355 * @id_timer: The timer used for polling ID line to detect ACA states.
Anji jonnala7da3f262011-12-02 17:22:14 -0800356 * @xo_handle: TCXO buffer handle
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530357 * @bus_perf_client: Bus performance client handle to request BUS bandwidth
Pavankumar Kondeti2aec9f32012-06-13 09:06:03 +0530358 * @mhl_enabled: MHL driver registration successful and MHL enabled.
Vijayavardhan Vennapusa2239b2b2013-06-28 13:16:29 +0530359 * @host_bus_suspend: indicates host bus suspend or not.
Pavankumar Kondeti458d8792012-09-28 14:45:18 +0530360 * @chg_check_timer: The timer used to implement the workaround to detect
361 * very slow plug in of wall charger.
Sujeet Kumarceee6e82013-09-06 11:22:49 +0530362 * @ui_enabled: USB Intterupt is enabled or disabled.
Saket Saurabh1a4e2502014-04-22 15:51:38 +0530363 * @pm_done: It is used to increment the pm counter using pm_runtime_get_sync.
364 This handles the race case when PM resume thread returns before
365 the charger detection starts. When USB is disconnected pm_done
366 is set to true.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530367 */
368struct msm_otg {
Heikki Krogerus1d4c9292012-02-13 13:24:09 +0200369 struct usb_phy phy;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530370 struct msm_otg_platform_data *pdata;
371 int irq;
Manu Gautamf8c45642012-08-10 10:20:56 -0700372 int async_irq;
Vijayavardhan Vennapusa0cab6172013-02-20 19:51:15 +0530373 struct clk *xo_clk;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530374 struct clk *clk;
375 struct clk *pclk;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530376 struct clk *core_clk;
Mayank Ranadd1f1dc2013-07-24 17:02:45 +0530377 struct clk *sleep_clk;
Mayank Rana3eaf28d2013-03-27 14:04:04 +0530378 long core_clk_rate;
Pavankumar Kondetif1ffbdd2013-06-27 13:31:36 +0530379 struct resource *io_res;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530380 void __iomem *regs;
381#define ID 0
382#define B_SESS_VLD 1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700383#define ID_A 2
384#define ID_B 3
385#define ID_C 4
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530386#define A_BUS_DROP 5
387#define A_BUS_REQ 6
388#define A_SRP_DET 7
389#define A_VBUS_VLD 8
390#define B_CONN 9
391#define ADP_CHANGE 10
392#define POWER_UP 11
393#define A_CLR_ERR 12
394#define A_BUS_RESUME 13
395#define A_BUS_SUSPEND 14
396#define A_CONN 15
397#define B_BUS_REQ 16
Pavankumar Kondeti2aec9f32012-06-13 09:06:03 +0530398#define MHL 17
Pavankumar Kondeti458d8792012-09-28 14:45:18 +0530399#define B_FALSE_SDP 18
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530400 unsigned long inputs;
401 struct work_struct sm_work;
Jack Pham5ca279b2012-05-14 18:42:54 -0700402 bool sm_work_pending;
403 atomic_t pm_suspended;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530404 atomic_t in_lpm;
405 int async_int;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530406 unsigned cur_power;
407 struct delayed_work chg_work;
Vijayavardhan Vennapusa68d55cf2012-06-27 20:06:12 +0530408 struct delayed_work pmic_id_status_work;
Amit Blayd0fe07b2012-09-05 16:42:09 +0300409 struct delayed_work suspend_work;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530410 enum usb_chg_state chg_state;
411 enum usb_chg_type chg_type;
Pavankumar Kondetiebb4a2d2013-01-04 12:28:10 +0530412 unsigned dcd_time;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700413 struct wake_lock wlock;
414 struct notifier_block usbdev_nb;
415 unsigned mA_port;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530416 struct timer_list id_timer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700417 unsigned long caps;
Stephen Boyd30ad10b2012-03-01 14:51:04 -0800418 struct msm_xo_voter *xo_handle;
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530419 uint32_t bus_perf_client;
Pavankumar Kondeti2aec9f32012-06-13 09:06:03 +0530420 bool mhl_enabled;
Vijayavardhan Vennapusa2239b2b2013-06-28 13:16:29 +0530421 bool host_bus_suspend;
Pavankumar Kondeti458d8792012-09-28 14:45:18 +0530422 struct timer_list chg_check_timer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700423 /*
424 * Allowing PHY power collpase turns off the HSUSB 3.3v and 1.8v
425 * analog regulators while going to low power mode.
Amit Blay81801aa2012-09-19 12:08:12 +0200426 * Currently only 28nm PHY has the support to allowing PHY
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700427 * power collapse since it doesn't have leakage currents while
428 * turning off the power rails.
429 */
430#define ALLOW_PHY_POWER_COLLAPSE BIT(0)
431 /*
432 * Allow PHY RETENTION mode before turning off the digital
433 * voltage regulator(VDDCX).
434 */
435#define ALLOW_PHY_RETENTION BIT(1)
Amit Blay6fa647a2012-05-24 14:12:08 +0300436 /*
437 * Allow putting the core in Low Power mode, when
438 * USB bus is suspended but cable is connected.
439 */
Amit Blay81801aa2012-09-19 12:08:12 +0200440#define ALLOW_LPM_ON_DEV_SUSPEND BIT(2)
441 /*
442 * Allowing PHY regulators LPM puts the HSUSB 3.3v and 1.8v
443 * analog regulators into LPM while going to USB low power mode.
444 */
445#define ALLOW_PHY_REGULATORS_LPM BIT(3)
Vijayavardhan Vennapusa2239b2b2013-06-28 13:16:29 +0530446 /*
447 * Allow PHY RETENTION mode before turning off the digital
448 * voltage regulator(VDDCX) during host mode.
449 */
450#define ALLOW_HOST_PHY_RETENTION BIT(4)
Saket Saurabhb06a8c62013-11-25 15:17:23 +0530451 /*
452 * Allow VDD minimization without putting PHY into retention
453 * for fixing PHY current leakage issue when LDOs are turned off.
454 */
455#define ALLOW_VDD_MIN_WITH_RETENTION_DISABLED BIT(5)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700456 unsigned long lpm_flags;
457#define PHY_PWR_COLLAPSED BIT(0)
458#define PHY_RETENTIONED BIT(1)
Vijayavardhan Vennapusabbdd6082012-06-06 14:14:25 +0530459#define XO_SHUTDOWN BIT(2)
Ido Shayevitzc5c0f572012-07-31 13:58:45 +0300460#define CLOCKS_DOWN BIT(3)
Amit Blay81801aa2012-09-19 12:08:12 +0200461#define PHY_REGULATORS_LPM BIT(4)
Ofir Cohen4da266f2012-01-03 10:19:29 +0200462 int reset_counter;
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530463 unsigned long b_last_se0_sess;
464 unsigned long tmouts;
465 u8 active_tmout;
466 struct hrtimer timer;
Mayank Rana248698c2012-04-19 00:03:16 +0530467 enum usb_vdd_type vdd_type;
David Keitel272ce522012-08-17 16:25:24 -0700468 struct power_supply usb_psy;
469 unsigned int online;
470 unsigned int host_mode;
Pavankumar Kondeti254e38d2013-07-16 11:13:05 +0530471 unsigned int voltage_max;
David Keitel272ce522012-08-17 16:25:24 -0700472 unsigned int current_max;
Wu Fenglin04ae6de2013-09-09 19:15:06 +0800473 unsigned int usbin_health;
Pavankumar Kondetif1ffbdd2013-06-27 13:31:36 +0530474
475 dev_t ext_chg_dev;
476 struct cdev ext_chg_cdev;
477 struct class *ext_chg_class;
478 struct device *ext_chg_device;
479 bool ext_chg_opened;
Saket Saurabh48848182014-05-23 15:15:02 +0530480 enum usb_ext_chg_status ext_chg_active;
Pavankumar Kondetif1ffbdd2013-06-27 13:31:36 +0530481 struct completion ext_chg_wait;
Sujeet Kumarceee6e82013-09-06 11:22:49 +0530482 int ui_enabled;
Saket Saurabh2558ea02014-01-10 16:14:27 +0530483 bool pm_done;
Vijayavardhan Vennapusa29e88802014-02-17 11:09:23 +0530484 struct qpnp_vadc_chip *vadc_dev;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530485};
486
Amit Blayb4f14532013-06-17 22:33:57 +0300487struct ci13xxx_platform_data {
488 u8 usb_core_id;
489 /*
490 * value of 2^(log2_itc-1) will be used as the interrupt threshold
491 * (ITC), when log2_itc is between 1 to 7.
492 */
493 int log2_itc;
494 void *prv_data;
Shimrit Malichi5a2d5b52013-06-20 19:04:28 +0300495 bool l1_supported;
Mayank Rana34f6f3e2013-11-11 12:40:00 +0530496 bool enable_ahb2ahb_bypass;
Amit Blayb4f14532013-06-17 22:33:57 +0300497};
498
Manu Gautamcaa99d42013-07-25 12:01:02 +0530499/**
500 * struct msm_hsic_host_platform_data - platform device data
501 * for msm_hsic_host driver.
502 * @phy_sof_workaround: Enable ALL PHY SOF bug related workarounds for
503 SUSPEND, RESET and RESUME.
504 * @phy_susp_sof_workaround: Enable PHY SOF workaround only for SUSPEND.
505 *
506 */
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530507struct msm_hsic_host_platform_data {
508 unsigned strobe;
509 unsigned data;
Manu Gautam863b74132012-11-21 14:30:04 +0530510 bool ignore_cal_pad_config;
Manu Gautam3c598392013-03-22 16:59:10 +0530511 bool phy_sof_workaround;
Manu Gautamcaa99d42013-07-25 12:01:02 +0530512 bool phy_susp_sof_workaround;
Ming-yi Lin9eed5e02013-07-18 14:06:24 +0800513 u32 reset_delay;
Manu Gautam863b74132012-11-21 14:30:04 +0530514 int strobe_pad_offset;
515 int data_pad_offset;
516
Hemant Kumare6275972012-02-29 20:06:21 -0800517 struct msm_bus_scale_pdata *bus_scale_table;
Hemant Kumar30d361c2012-08-20 14:44:40 -0700518 unsigned log2_irq_thresh;
Hemant Kumarbc8bdf62012-10-17 12:29:51 -0700519
Vamsi Krishnabef91832013-03-11 14:10:20 -0700520 /* gpio used to resume peripheral */
521 unsigned resume_gpio;
522
Hemant Kumarbc8bdf62012-10-17 12:29:51 -0700523 /*swfi latency is required while driving resume on to the bus */
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +0530524 u32 swfi_latency;
Hemant Kumarbc8bdf62012-10-17 12:29:51 -0700525
526 /*standalone latency is required when HSCI is active*/
527 u32 standalone_latency;
Shimrit Malichi36a0c852013-03-10 11:39:10 +0200528 bool pool_64_bit_align;
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +0200529 bool enable_hbm;
Shimrit Malichi08f07342013-04-24 13:09:12 +0300530 bool disable_park_mode;
Ido Shayevitzaa165c52013-05-12 16:01:28 +0200531 bool consider_ipa_handshake;
Amit Blay1dfbbcc2013-05-26 17:33:13 +0300532 bool ahb_async_bridge_bypass;
Vamsi Krishna4f66c2c2013-06-21 11:33:59 -0700533 bool disable_cerr;
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530534};
535
Manu Gautam91223e02011-11-08 15:27:22 +0530536struct msm_usb_host_platform_data {
537 unsigned int power_budget;
Vijayavardhan Vennapusa4fa13692012-08-02 14:35:03 +0530538 int pmic_gpio_dp_irq;
Hemant Kumar56925352012-02-13 16:59:52 -0800539 unsigned int dock_connect_irq;
Vijayavardhan Vennapusa1f5da0b2013-01-08 20:03:57 +0530540 bool use_sec_phy;
Hemant Kumarb8fc9592013-04-17 19:29:39 -0700541 bool no_selective_suspend;
Hemant Kumara7d531d2013-06-18 22:12:18 -0700542 int resume_gpio;
Vijayavardhan Vennapusa94f14432014-03-24 13:45:40 +0530543 bool is_uicc;
Manu Gautam91223e02011-11-08 15:27:22 +0530544};
545
Amit Blay9b6e58b2012-06-18 13:12:49 +0300546/**
547 * struct msm_hsic_peripheral_platform_data: HSIC peripheral
548 * platform data.
549 * @core_clk_always_on_workaround: Don't disable core_clk when
550 * HSIC enters LPM.
551 */
Amit Blay4d57d362012-04-28 11:00:21 +0300552struct msm_hsic_peripheral_platform_data {
Amit Blay9b6e58b2012-06-18 13:12:49 +0300553 bool core_clk_always_on_workaround;
Amit Blay4d57d362012-04-28 11:00:21 +0300554};
555
Jack Phamfadd6432012-12-07 19:03:41 -0800556/**
557 * struct usb_ext_notification: event notification structure
558 * @notify: pointer to client function to call when ID event is detected.
Jack Phamb7209152013-07-03 17:04:53 -0700559 * The function parameter is provided by driver to be called back when
Jack Phamfadd6432012-12-07 19:03:41 -0800560 * external client indicates it is done using the USB. This function
561 * should return 0 if handled successfully, otherise an error code.
562 * @ctxt: client-specific context pointer
563 *
564 * This structure should be used by clients wishing to register (via
565 * msm_register_usb_ext_notification) for event notification whenever a USB
566 * cable is plugged in and ID pin status changes. Clients must provide a
567 * callback function pointer. If this callback returns 0, the USB driver will
568 * assume the client is "taking over" the connection, and will relinquish any
569 * further processing until its callback (passed via the third parameter) is
570 * called with the online parameter set to false.
571 */
572struct usb_ext_notification {
Jack Phamb7209152013-07-03 17:04:53 -0700573 int (*notify)(void *, int, void (*)(void *, int online), void *);
Jack Phamfadd6432012-12-07 19:03:41 -0800574 void *ctxt;
575};
Lena Salmanabde35d2013-04-25 15:29:43 +0300576#ifdef CONFIG_USB_BAM
577bool msm_bam_lpm_ok(void);
Ido Shayevitz44ca03c2013-07-09 15:57:21 +0300578void msm_bam_notify_lpm_resume(void);
Ido Shayevitzaa165c52013-05-12 16:01:28 +0200579void msm_bam_set_hsic_host_dev(struct device *dev);
580void msm_bam_wait_for_hsic_prod_granted(void);
581bool msm_bam_hsic_lpm_ok(void);
582void msm_bam_hsic_notify_on_resume(void);
Lena Salmanabde35d2013-04-25 15:29:43 +0300583#else
584static inline bool msm_bam_lpm_ok(void) { return true; }
Ido Shayevitz44ca03c2013-07-09 15:57:21 +0300585static inline void msm_bam_notify_lpm_resume(void) {}
Ido Shayevitzaa165c52013-05-12 16:01:28 +0200586static inline void msm_bam_set_hsic_host_dev(struct device *dev) {}
587static inline void msm_bam_wait_for_hsic_prod_granted(void) {}
588static inline bool msm_bam_hsic_lpm_ok(void) { return true; }
589static inline void msm_bam_hsic_notify_on_resume(void) {}
Lena Salmanabde35d2013-04-25 15:29:43 +0300590#endif
Amit Blay1572b492012-11-27 16:45:32 +0200591#ifdef CONFIG_USB_CI13XXX_MSM
592void msm_hw_bam_disable(bool bam_disable);
Amit Blay1572b492012-11-27 16:45:32 +0200593#else
594static inline void msm_hw_bam_disable(bool bam_disable)
595{
596}
597#endif
598
Shimrit Malichi255b5342012-08-02 21:01:43 +0300599#ifdef CONFIG_USB_DWC3_MSM
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300600int msm_ep_config(struct usb_ep *ep);
601int msm_ep_unconfig(struct usb_ep *ep);
Vijayavardhan Vennapusafc3db602013-08-20 17:54:54 +0530602void dwc3_tx_fifo_resize_request(struct usb_ep *ep, bool qdss_enable);
Shimrit Malichi255b5342012-08-02 21:01:43 +0300603int msm_data_fifo_config(struct usb_ep *ep, u32 addr, u32 size,
604 u8 dst_pipe_idx);
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300605
Jack Pham62c19a42013-07-09 17:55:09 -0700606void msm_dwc3_restart_usb_session(struct usb_gadget *gadget);
Jack Phamfadd6432012-12-07 19:03:41 -0800607
Manu Gautam6eb13e32013-02-01 15:19:15 +0530608int msm_register_usb_ext_notification(struct usb_ext_notification *info);
Shimrit Malichi255b5342012-08-02 21:01:43 +0300609#else
610static inline int msm_data_fifo_config(struct usb_ep *ep, u32 addr, u32 size,
611 u8 dst_pipe_idx)
612{
613 return -ENODEV;
614}
615
616static inline int msm_ep_config(struct usb_ep *ep)
617{
618 return -ENODEV;
619}
620
621static inline int msm_ep_unconfig(struct usb_ep *ep)
622{
623 return -ENODEV;
624}
Jack Phamfadd6432012-12-07 19:03:41 -0800625
Vijayavardhan Vennapusafc3db602013-08-20 17:54:54 +0530626static inline void dwc3_tx_fifo_resize_request(
627 struct usb_ep *ep, bool qdss_enable)
628{
629 return;
630}
631
Jack Pham62c19a42013-07-09 17:55:09 -0700632static inline void msm_dwc3_restart_usb_session(struct usb_gadget *gadget)
Manu Gautam6eb13e32013-02-01 15:19:15 +0530633{
634 return;
635}
636
Jack Phamfadd6432012-12-07 19:03:41 -0800637static inline int msm_register_usb_ext_notification(
638 struct usb_ext_notification *info)
639{
640 return -ENODEV;
641}
Shimrit Malichi255b5342012-08-02 21:01:43 +0300642#endif
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530643#endif