blob: 69c7c74b419846f60dc86483beeb76a6cd270be9 [file] [log] [blame]
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +05301/* linux/include/asm-arm/arch-msm/hsusb.h
2 *
3 * Copyright (C) 2008 Google, Inc.
4 * Author: Brian Swetland <swetland@google.com>
Manu Gautam5143b252012-01-05 19:25:23 -08005 * Copyright (c) 2009-2012, Code Aurora Forum. 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>
22#include <linux/usb/otg.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023#include <linux/wakelock.h>
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +053024#include <linux/pm_qos_params.h>
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053025
Ido Shayevitzd1cb16c2012-03-28 18:57:47 +020026/*
27 * The following are bit fields describing the usb_request.udc_priv word.
28 * These bit fields are set by function drivers that wish to queue
29 * usb_requests with sps/bam parameters.
30 */
31#define MSM_PIPE_ID_MASK (0x1F)
32#define MSM_TX_PIPE_ID_OFS (16)
33#define MSM_SPS_MODE BIT(5)
34#define MSM_IS_FINITE_TRANSFER BIT(6)
35#define MSM_PRODUCER BIT(7)
36#define MSM_DISABLE_WB BIT(8)
37#define MSM_ETD_IOC BIT(9)
38#define MSM_INTERNAL_MEM BIT(10)
39#define MSM_VENDOR_ID BIT(16)
40
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053041/**
42 * Supported USB modes
43 *
44 * USB_PERIPHERAL Only peripheral mode is supported.
45 * USB_HOST Only host mode is supported.
46 * USB_OTG OTG mode is supported.
47 *
48 */
49enum usb_mode_type {
50 USB_NONE = 0,
51 USB_PERIPHERAL,
52 USB_HOST,
53 USB_OTG,
54};
55
56/**
57 * OTG control
58 *
59 * OTG_NO_CONTROL Id/VBUS notifications not required. Useful in host
60 * only configuration.
61 * OTG_PHY_CONTROL Id/VBUS notifications comes form USB PHY.
62 * OTG_PMIC_CONTROL Id/VBUS notifications comes from PMIC hardware.
63 * OTG_USER_CONTROL Id/VBUS notifcations comes from User via sysfs.
64 *
65 */
66enum otg_control_type {
67 OTG_NO_CONTROL = 0,
68 OTG_PHY_CONTROL,
69 OTG_PMIC_CONTROL,
70 OTG_USER_CONTROL,
71};
72
73/**
Pavankumar Kondetid8608522011-05-04 10:19:47 +053074 * PHY used in
75 *
76 * INVALID_PHY Unsupported PHY
77 * CI_45NM_INTEGRATED_PHY Chipidea 45nm integrated PHY
78 * SNPS_28NM_INTEGRATED_PHY Synopsis 28nm integrated PHY
79 *
80 */
81enum msm_usb_phy_type {
82 INVALID_PHY = 0,
83 CI_45NM_INTEGRATED_PHY,
84 SNPS_28NM_INTEGRATED_PHY,
85};
86
87#define IDEV_CHG_MAX 1500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088#define IDEV_CHG_MIN 500
Pavankumar Kondetid8608522011-05-04 10:19:47 +053089#define IUNIT 100
90
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +053091#define IDEV_ACA_CHG_MAX 1500
92#define IDEV_ACA_CHG_LIMIT 500
93
Pavankumar Kondetid8608522011-05-04 10:19:47 +053094/**
95 * Different states involved in USB charger detection.
96 *
97 * USB_CHG_STATE_UNDEFINED USB charger is not connected or detection
98 * process is not yet started.
99 * USB_CHG_STATE_WAIT_FOR_DCD Waiting for Data pins contact.
100 * USB_CHG_STATE_DCD_DONE Data pin contact is detected.
101 * USB_CHG_STATE_PRIMARY_DONE Primary detection is completed (Detects
102 * between SDP and DCP/CDP).
103 * USB_CHG_STATE_SECONDARY_DONE Secondary detection is completed (Detects
104 * between DCP and CDP).
105 * USB_CHG_STATE_DETECTED USB charger type is determined.
106 *
107 */
108enum usb_chg_state {
109 USB_CHG_STATE_UNDEFINED = 0,
110 USB_CHG_STATE_WAIT_FOR_DCD,
111 USB_CHG_STATE_DCD_DONE,
112 USB_CHG_STATE_PRIMARY_DONE,
113 USB_CHG_STATE_SECONDARY_DONE,
114 USB_CHG_STATE_DETECTED,
115};
116
117/**
118 * USB charger types
119 *
120 * USB_INVALID_CHARGER Invalid USB charger.
121 * USB_SDP_CHARGER Standard downstream port. Refers to a downstream port
122 * on USB2.0 compliant host/hub.
123 * USB_DCP_CHARGER Dedicated charger port (AC charger/ Wall charger).
124 * USB_CDP_CHARGER Charging downstream port. Enumeration can happen and
125 * IDEV_CHG_MAX can be drawn irrespective of USB state.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126 * USB_ACA_A_CHARGER B-device is connected on accessory port with charger
127 * connected on charging port. This configuration allows
128 * charging in host mode.
129 * USB_ACA_B_CHARGER No device (or A-device without VBUS) is connected on
130 * accessory port with charger connected on charging port.
131 * USB_ACA_C_CHARGER A-device (with VBUS) is connected on
132 * accessory port with charger connected on charging port.
133 * USB_ACA_DOCK_CHARGER A docking station that has one upstream port and one
134 * or more downstream ports. Capable of supplying
135 * IDEV_CHG_MAX irrespective of devices connected on
136 * accessory ports.
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530137 */
138enum usb_chg_type {
139 USB_INVALID_CHARGER = 0,
140 USB_SDP_CHARGER,
141 USB_DCP_CHARGER,
142 USB_CDP_CHARGER,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700143 USB_ACA_A_CHARGER,
144 USB_ACA_B_CHARGER,
145 USB_ACA_C_CHARGER,
146 USB_ACA_DOCK_CHARGER,
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530147};
148
149/**
Ofir Cohenc7827e42011-12-13 20:10:01 +0200150 * SPS Pipes direction.
151 *
152 * USB_TO_PEER_PERIPHERAL USB (as Producer) to other
153 * peer peripheral.
154 * PEER_PERIPHERAL_TO_USB Other Peripheral to
155 * USB (as consumer).
156 */
157enum usb_bam_pipe_dir {
158 USB_TO_PEER_PERIPHERAL,
159 PEER_PERIPHERAL_TO_USB,
160};
161
162/**
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530163 * struct msm_otg_platform_data - platform device data
Pavankumar Kondetidfb21302011-03-04 22:45:02 +0530164 * for msm_otg driver.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530165 * @phy_init_seq: PHY configuration sequence. val, reg pairs
166 * terminated by -1.
Mayank Rana8549e632012-01-23 12:49:54 +0530167 * @vbus_power: VBUS power on/off routine.It should return result
168 * as success(zero value) or failure(non-zero value).
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530169 * @power_budget: VBUS power budget in mA (0 will be treated as 500mA).
170 * @mode: Supported mode (OTG/peripheral/host).
171 * @otg_control: OTG switch controlled by user/Id pin
172 * @default_mode: Default operational mode. Applicable only if
173 * OTG switch is controller by user.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 * @pmic_id_irq: IRQ number assigned for PMIC USB ID line.
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530175 * @mhl_enable: indicates MHL connector or not.
Ofir Cohen4da266f2012-01-03 10:19:29 +0200176 * @disable_reset_on_disconnect: perform USB PHY and LINK reset
177 * on USB cable disconnection.
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +0530178 * @swfi_latency: miminum latency to allow swfi.
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +0530179 * @enable_dcd: Enable Data Contact Detection circuit. if not set
180 * wait for 600msec before proceeding to primary
181 * detection.
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530182 * @bus_scale_table: parameters for bus bandwidth requirements
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530183 */
184struct msm_otg_platform_data {
185 int *phy_init_seq;
Mayank Rana8549e632012-01-23 12:49:54 +0530186 int (*vbus_power)(bool on);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530187 unsigned power_budget;
188 enum usb_mode_type mode;
189 enum otg_control_type otg_control;
190 enum usb_mode_type default_mode;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530191 enum msm_usb_phy_type phy_type;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530192 void (*setup_gpio)(enum usb_otg_state state);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700193 int pmic_id_irq;
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530194 bool mhl_enable;
Ofir Cohen4da266f2012-01-03 10:19:29 +0200195 bool disable_reset_on_disconnect;
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +0530196 u32 swfi_latency;
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +0530197 bool enable_dcd;
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530198 struct msm_bus_scale_pdata *bus_scale_table;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530199};
200
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530201/* Timeout (in msec) values (min - max) associated with OTG timers */
202
203#define TA_WAIT_VRISE 100 /* ( - 100) */
204#define TA_WAIT_VFALL 500 /* ( - 1000) */
205
206/*
207 * This option is set for embedded hosts or OTG devices in which leakage
208 * currents are very minimal.
209 */
210#ifdef CONFIG_USB_OTG
211#define TA_WAIT_BCON 30000 /* (1100 - 30000) */
212#else
213#define TA_WAIT_BCON -1
214#endif
215
216#define TA_AIDL_BDIS 500 /* (200 - ) */
217#define TA_BIDL_ADIS 155 /* (155 - 200) */
218#define TB_SRP_FAIL 6000 /* (5000 - 6000) */
219#define TB_ASE0_BRST 200 /* (155 - ) */
220
221/* TB_SSEND_SRP and TB_SE0_SRP are combined */
222#define TB_SRP_INIT 2000 /* (1500 - ) */
223
224#define TA_TST_MAINT 10100 /* (9900 - 10100) */
225#define TB_TST_SRP 3000 /* ( - 5000) */
226#define TB_TST_CONFIG 300
227
228/* Timeout variables */
229
230#define A_WAIT_VRISE 0
231#define A_WAIT_VFALL 1
232#define A_WAIT_BCON 2
233#define A_AIDL_BDIS 3
234#define A_BIDL_ADIS 4
235#define B_SRP_FAIL 5
236#define B_ASE0_BRST 6
237#define A_TST_MAINT 7
238#define B_TST_SRP 8
239#define B_TST_CONFIG 9
240
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530241/**
242 * struct msm_otg: OTG driver data. Shared by HCD and DCD.
243 * @otg: USB OTG Transceiver structure.
244 * @pdata: otg device platform data.
245 * @irq: IRQ number assigned for HSUSB controller.
Manu Gautam5143b252012-01-05 19:25:23 -0800246 * @clk: clock struct of alt_core_clk.
247 * @pclk: clock struct of iface_clk.
248 * @phy_reset_clk: clock struct of phy_clk.
249 * @core_clk: clock struct of core_bus_clk.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530250 * @regs: ioremapped register base address.
251 * @inputs: OTG state machine inputs(Id, SessValid etc).
252 * @sm_work: OTG state machine work.
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530253 * @in_lpm: indicates low power mode (LPM) state.
254 * @async_int: Async interrupt arrived.
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530255 * @cur_power: The amount of mA available from downstream port.
256 * @chg_work: Charger detection work.
257 * @chg_state: The state of charger detection process.
258 * @chg_type: The type of charger attached.
259 * @dcd_retires: The retry count used to track Data contact
260 * detection process.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700261 * @wlock: Wake lock struct to prevent system suspend when
262 * USB is active.
263 * @usbdev_nb: The notifier block used to know about the B-device
264 * connected. Useful only when ACA_A charger is
265 * connected.
266 * @mA_port: The amount of current drawn by the attached B-device.
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +0530267 * @pm_qos_req_dma: miminum DMA latency to vote against idle power
268 collapse when cable is connected.
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530269 * @id_timer: The timer used for polling ID line to detect ACA states.
Anji jonnala7da3f262011-12-02 17:22:14 -0800270 * @xo_handle: TCXO buffer handle
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530271 * @bus_perf_client: Bus performance client handle to request BUS bandwidth
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530272 */
273struct msm_otg {
274 struct otg_transceiver otg;
275 struct msm_otg_platform_data *pdata;
276 int irq;
277 struct clk *clk;
278 struct clk *pclk;
279 struct clk *phy_reset_clk;
280 struct clk *core_clk;
281 void __iomem *regs;
282#define ID 0
283#define B_SESS_VLD 1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700284#define ID_A 2
285#define ID_B 3
286#define ID_C 4
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530287#define A_BUS_DROP 5
288#define A_BUS_REQ 6
289#define A_SRP_DET 7
290#define A_VBUS_VLD 8
291#define B_CONN 9
292#define ADP_CHANGE 10
293#define POWER_UP 11
294#define A_CLR_ERR 12
295#define A_BUS_RESUME 13
296#define A_BUS_SUSPEND 14
297#define A_CONN 15
298#define B_BUS_REQ 16
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530299 unsigned long inputs;
300 struct work_struct sm_work;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530301 atomic_t in_lpm;
302 int async_int;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530303 unsigned cur_power;
304 struct delayed_work chg_work;
305 enum usb_chg_state chg_state;
306 enum usb_chg_type chg_type;
307 u8 dcd_retries;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700308 struct wake_lock wlock;
309 struct notifier_block usbdev_nb;
310 unsigned mA_port;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530311 struct timer_list id_timer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700312 unsigned long caps;
Stephen Boyd30ad10b2012-03-01 14:51:04 -0800313 struct msm_xo_voter *xo_handle;
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530314 uint32_t bus_perf_client;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700315 /*
316 * Allowing PHY power collpase turns off the HSUSB 3.3v and 1.8v
317 * analog regulators while going to low power mode.
318 * Currently only 8960(28nm PHY) has the support to allowing PHY
319 * power collapse since it doesn't have leakage currents while
320 * turning off the power rails.
321 */
322#define ALLOW_PHY_POWER_COLLAPSE BIT(0)
323 /*
324 * Allow PHY RETENTION mode before turning off the digital
325 * voltage regulator(VDDCX).
326 */
327#define ALLOW_PHY_RETENTION BIT(1)
328 /*
329 * Disable the OTG comparators to save more power
330 * if depends on PMIC for VBUS and ID interrupts.
331 */
332#define ALLOW_PHY_COMP_DISABLE BIT(2)
333 unsigned long lpm_flags;
334#define PHY_PWR_COLLAPSED BIT(0)
335#define PHY_RETENTIONED BIT(1)
336#define PHY_OTG_COMP_DISABLED BIT(2)
Anji jonnalaa7c1c5c2011-12-12 12:20:36 +0530337 struct pm_qos_request_list pm_qos_req_dma;
Ofir Cohen4da266f2012-01-03 10:19:29 +0200338 int reset_counter;
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530339 unsigned long b_last_se0_sess;
340 unsigned long tmouts;
341 u8 active_tmout;
342 struct hrtimer timer;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530343};
344
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530345struct msm_hsic_host_platform_data {
346 unsigned strobe;
347 unsigned data;
Hemant Kumare6275972012-02-29 20:06:21 -0800348 struct msm_bus_scale_pdata *bus_scale_table;
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530349};
350
Manu Gautam91223e02011-11-08 15:27:22 +0530351struct msm_usb_host_platform_data {
352 unsigned int power_budget;
Hemant Kumar56925352012-02-13 16:59:52 -0800353 unsigned int dock_connect_irq;
Manu Gautam91223e02011-11-08 15:27:22 +0530354};
355
Ofir Cohenc7827e42011-12-13 20:10:01 +0200356struct usb_bam_pipe_connect {
357 u32 src_phy_addr;
358 int src_pipe_index;
359 u32 dst_phy_addr;
360 int dst_pipe_index;
361 u32 data_fifo_base_offset;
362 u32 data_fifo_size;
363 u32 desc_fifo_base_offset;
364 u32 desc_fifo_size;
365};
366
367struct msm_usb_bam_platform_data {
368 struct usb_bam_pipe_connect *connections;
Ofir Cohen010009b2012-01-26 16:49:17 +0200369 int usb_active_bam;
Ofir Cohenc7827e42011-12-13 20:10:01 +0200370 int usb_bam_num_pipes;
371};
Ofir Cohen010009b2012-01-26 16:49:17 +0200372
373enum usb_bam {
374 HSUSB_BAM = 0,
375 HSIC_BAM,
376};
Ido Shayevitzd1cb16c2012-03-28 18:57:47 +0200377
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530378#endif