blob: 14d49eb8054aa7c1c6798267c5116ef41917fb3f [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>
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>
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053026
Ido Shayevitzd1cb16c2012-03-28 18:57:47 +020027/*
28 * The following are bit fields describing the usb_request.udc_priv word.
29 * These bit fields are set by function drivers that wish to queue
30 * usb_requests with sps/bam parameters.
31 */
32#define MSM_PIPE_ID_MASK (0x1F)
33#define MSM_TX_PIPE_ID_OFS (16)
34#define MSM_SPS_MODE BIT(5)
35#define MSM_IS_FINITE_TRANSFER BIT(6)
36#define MSM_PRODUCER BIT(7)
37#define MSM_DISABLE_WB BIT(8)
38#define MSM_ETD_IOC BIT(9)
39#define MSM_INTERNAL_MEM BIT(10)
40#define MSM_VENDOR_ID BIT(16)
41
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053042/**
43 * Supported USB modes
44 *
45 * USB_PERIPHERAL Only peripheral mode is supported.
46 * USB_HOST Only host mode is supported.
47 * USB_OTG OTG mode is supported.
48 *
49 */
50enum usb_mode_type {
51 USB_NONE = 0,
52 USB_PERIPHERAL,
53 USB_HOST,
54 USB_OTG,
55};
56
57/**
58 * OTG control
59 *
60 * OTG_NO_CONTROL Id/VBUS notifications not required. Useful in host
61 * only configuration.
62 * OTG_PHY_CONTROL Id/VBUS notifications comes form USB PHY.
63 * OTG_PMIC_CONTROL Id/VBUS notifications comes from PMIC hardware.
64 * OTG_USER_CONTROL Id/VBUS notifcations comes from User via sysfs.
65 *
66 */
67enum otg_control_type {
68 OTG_NO_CONTROL = 0,
69 OTG_PHY_CONTROL,
70 OTG_PMIC_CONTROL,
71 OTG_USER_CONTROL,
72};
73
74/**
Pavankumar Kondetid8608522011-05-04 10:19:47 +053075 * PHY used in
76 *
77 * INVALID_PHY Unsupported PHY
78 * CI_45NM_INTEGRATED_PHY Chipidea 45nm integrated PHY
79 * SNPS_28NM_INTEGRATED_PHY Synopsis 28nm integrated PHY
80 *
81 */
82enum msm_usb_phy_type {
83 INVALID_PHY = 0,
84 CI_45NM_INTEGRATED_PHY,
85 SNPS_28NM_INTEGRATED_PHY,
86};
87
88#define IDEV_CHG_MAX 1500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089#define IDEV_CHG_MIN 500
Pavankumar Kondetid8608522011-05-04 10:19:47 +053090#define IUNIT 100
91
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +053092#define IDEV_ACA_CHG_MAX 1500
93#define IDEV_ACA_CHG_LIMIT 500
94
Pavankumar Kondetid8608522011-05-04 10:19:47 +053095/**
96 * Different states involved in USB charger detection.
97 *
98 * USB_CHG_STATE_UNDEFINED USB charger is not connected or detection
99 * process is not yet started.
100 * USB_CHG_STATE_WAIT_FOR_DCD Waiting for Data pins contact.
101 * USB_CHG_STATE_DCD_DONE Data pin contact is detected.
102 * USB_CHG_STATE_PRIMARY_DONE Primary detection is completed (Detects
103 * between SDP and DCP/CDP).
104 * USB_CHG_STATE_SECONDARY_DONE Secondary detection is completed (Detects
105 * between DCP and CDP).
106 * USB_CHG_STATE_DETECTED USB charger type is determined.
107 *
108 */
109enum usb_chg_state {
110 USB_CHG_STATE_UNDEFINED = 0,
111 USB_CHG_STATE_WAIT_FOR_DCD,
112 USB_CHG_STATE_DCD_DONE,
113 USB_CHG_STATE_PRIMARY_DONE,
114 USB_CHG_STATE_SECONDARY_DONE,
115 USB_CHG_STATE_DETECTED,
116};
117
118/**
119 * USB charger types
120 *
121 * USB_INVALID_CHARGER Invalid USB charger.
122 * USB_SDP_CHARGER Standard downstream port. Refers to a downstream port
123 * on USB2.0 compliant host/hub.
124 * USB_DCP_CHARGER Dedicated charger port (AC charger/ Wall charger).
125 * USB_CDP_CHARGER Charging downstream port. Enumeration can happen and
126 * IDEV_CHG_MAX can be drawn irrespective of USB state.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700127 * USB_ACA_A_CHARGER B-device is connected on accessory port with charger
128 * connected on charging port. This configuration allows
129 * charging in host mode.
130 * USB_ACA_B_CHARGER No device (or A-device without VBUS) is connected on
131 * accessory port with charger connected on charging port.
132 * USB_ACA_C_CHARGER A-device (with VBUS) is connected on
133 * accessory port with charger connected on charging port.
134 * USB_ACA_DOCK_CHARGER A docking station that has one upstream port and one
135 * or more downstream ports. Capable of supplying
136 * IDEV_CHG_MAX irrespective of devices connected on
137 * accessory ports.
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530138 */
139enum usb_chg_type {
140 USB_INVALID_CHARGER = 0,
141 USB_SDP_CHARGER,
142 USB_DCP_CHARGER,
143 USB_CDP_CHARGER,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700144 USB_ACA_A_CHARGER,
145 USB_ACA_B_CHARGER,
146 USB_ACA_C_CHARGER,
147 USB_ACA_DOCK_CHARGER,
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530148};
149
150/**
Mayank Rana248698c2012-04-19 00:03:16 +0530151 * Used different VDDCX voltage voting mechnism
152 * VDDCX_CORNER Vote for VDDCX Corner voltage
153 * VDDCX Vote for VDDCX Absolute voltage
154 */
155enum usb_vdd_type {
156 VDDCX_CORNER = 0,
157 VDDCX,
158 VDD_TYPE_MAX,
159};
160
161/**
Ofir Cohenc7827e42011-12-13 20:10:01 +0200162 * SPS Pipes direction.
163 *
164 * USB_TO_PEER_PERIPHERAL USB (as Producer) to other
165 * peer peripheral.
166 * PEER_PERIPHERAL_TO_USB Other Peripheral to
167 * USB (as consumer).
168 */
169enum usb_bam_pipe_dir {
170 USB_TO_PEER_PERIPHERAL,
171 PEER_PERIPHERAL_TO_USB,
172};
173
174/**
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530175 * struct msm_otg_platform_data - platform device data
Pavankumar Kondetidfb21302011-03-04 22:45:02 +0530176 * for msm_otg driver.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530177 * @phy_init_seq: PHY configuration sequence. val, reg pairs
178 * terminated by -1.
Mayank Rana8549e632012-01-23 12:49:54 +0530179 * @vbus_power: VBUS power on/off routine.It should return result
180 * as success(zero value) or failure(non-zero value).
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530181 * @power_budget: VBUS power budget in mA (0 will be treated as 500mA).
182 * @mode: Supported mode (OTG/peripheral/host).
183 * @otg_control: OTG switch controlled by user/Id pin
184 * @default_mode: Default operational mode. Applicable only if
185 * OTG switch is controller by user.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186 * @pmic_id_irq: IRQ number assigned for PMIC USB ID line.
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530187 * @mhl_enable: indicates MHL connector or not.
Ofir Cohen4da266f2012-01-03 10:19:29 +0200188 * @disable_reset_on_disconnect: perform USB PHY and LINK reset
189 * on USB cable disconnection.
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +0530190 * @enable_dcd: Enable Data Contact Detection circuit. if not set
191 * wait for 600msec before proceeding to primary
192 * detection.
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530193 * @bus_scale_table: parameters for bus bandwidth requirements
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530194 */
195struct msm_otg_platform_data {
196 int *phy_init_seq;
Mayank Rana8549e632012-01-23 12:49:54 +0530197 int (*vbus_power)(bool on);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530198 unsigned power_budget;
199 enum usb_mode_type mode;
200 enum otg_control_type otg_control;
201 enum usb_mode_type default_mode;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530202 enum msm_usb_phy_type phy_type;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530203 void (*setup_gpio)(enum usb_otg_state state);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204 int pmic_id_irq;
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530205 bool mhl_enable;
Ofir Cohen4da266f2012-01-03 10:19:29 +0200206 bool disable_reset_on_disconnect;
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +0530207 bool enable_dcd;
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530208 struct msm_bus_scale_pdata *bus_scale_table;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530209};
210
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530211/* Timeout (in msec) values (min - max) associated with OTG timers */
212
213#define TA_WAIT_VRISE 100 /* ( - 100) */
214#define TA_WAIT_VFALL 500 /* ( - 1000) */
215
216/*
217 * This option is set for embedded hosts or OTG devices in which leakage
218 * currents are very minimal.
219 */
220#ifdef CONFIG_USB_OTG
221#define TA_WAIT_BCON 30000 /* (1100 - 30000) */
222#else
223#define TA_WAIT_BCON -1
224#endif
225
226#define TA_AIDL_BDIS 500 /* (200 - ) */
227#define TA_BIDL_ADIS 155 /* (155 - 200) */
228#define TB_SRP_FAIL 6000 /* (5000 - 6000) */
229#define TB_ASE0_BRST 200 /* (155 - ) */
230
231/* TB_SSEND_SRP and TB_SE0_SRP are combined */
232#define TB_SRP_INIT 2000 /* (1500 - ) */
233
234#define TA_TST_MAINT 10100 /* (9900 - 10100) */
235#define TB_TST_SRP 3000 /* ( - 5000) */
236#define TB_TST_CONFIG 300
237
238/* Timeout variables */
239
240#define A_WAIT_VRISE 0
241#define A_WAIT_VFALL 1
242#define A_WAIT_BCON 2
243#define A_AIDL_BDIS 3
244#define A_BIDL_ADIS 4
245#define B_SRP_FAIL 5
246#define B_ASE0_BRST 6
247#define A_TST_MAINT 7
248#define B_TST_SRP 8
249#define B_TST_CONFIG 9
250
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530251/**
252 * struct msm_otg: OTG driver data. Shared by HCD and DCD.
253 * @otg: USB OTG Transceiver structure.
254 * @pdata: otg device platform data.
255 * @irq: IRQ number assigned for HSUSB controller.
Manu Gautam5143b252012-01-05 19:25:23 -0800256 * @clk: clock struct of alt_core_clk.
257 * @pclk: clock struct of iface_clk.
258 * @phy_reset_clk: clock struct of phy_clk.
259 * @core_clk: clock struct of core_bus_clk.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530260 * @regs: ioremapped register base address.
261 * @inputs: OTG state machine inputs(Id, SessValid etc).
262 * @sm_work: OTG state machine work.
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530263 * @in_lpm: indicates low power mode (LPM) state.
264 * @async_int: Async interrupt arrived.
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530265 * @cur_power: The amount of mA available from downstream port.
266 * @chg_work: Charger detection work.
267 * @chg_state: The state of charger detection process.
268 * @chg_type: The type of charger attached.
269 * @dcd_retires: The retry count used to track Data contact
270 * detection process.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700271 * @wlock: Wake lock struct to prevent system suspend when
272 * USB is active.
273 * @usbdev_nb: The notifier block used to know about the B-device
274 * connected. Useful only when ACA_A charger is
275 * connected.
276 * @mA_port: The amount of current drawn by the attached B-device.
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530277 * @id_timer: The timer used for polling ID line to detect ACA states.
Anji jonnala7da3f262011-12-02 17:22:14 -0800278 * @xo_handle: TCXO buffer handle
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530279 * @bus_perf_client: Bus performance client handle to request BUS bandwidth
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530280 */
281struct msm_otg {
282 struct otg_transceiver otg;
283 struct msm_otg_platform_data *pdata;
284 int irq;
285 struct clk *clk;
286 struct clk *pclk;
287 struct clk *phy_reset_clk;
288 struct clk *core_clk;
289 void __iomem *regs;
290#define ID 0
291#define B_SESS_VLD 1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700292#define ID_A 2
293#define ID_B 3
294#define ID_C 4
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530295#define A_BUS_DROP 5
296#define A_BUS_REQ 6
297#define A_SRP_DET 7
298#define A_VBUS_VLD 8
299#define B_CONN 9
300#define ADP_CHANGE 10
301#define POWER_UP 11
302#define A_CLR_ERR 12
303#define A_BUS_RESUME 13
304#define A_BUS_SUSPEND 14
305#define A_CONN 15
306#define B_BUS_REQ 16
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530307 unsigned long inputs;
308 struct work_struct sm_work;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530309 atomic_t in_lpm;
310 int async_int;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530311 unsigned cur_power;
312 struct delayed_work chg_work;
313 enum usb_chg_state chg_state;
314 enum usb_chg_type chg_type;
315 u8 dcd_retries;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700316 struct wake_lock wlock;
317 struct notifier_block usbdev_nb;
318 unsigned mA_port;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530319 struct timer_list id_timer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320 unsigned long caps;
Stephen Boyd30ad10b2012-03-01 14:51:04 -0800321 struct msm_xo_voter *xo_handle;
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530322 uint32_t bus_perf_client;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700323 /*
324 * Allowing PHY power collpase turns off the HSUSB 3.3v and 1.8v
325 * analog regulators while going to low power mode.
326 * Currently only 8960(28nm PHY) has the support to allowing PHY
327 * power collapse since it doesn't have leakage currents while
328 * turning off the power rails.
329 */
330#define ALLOW_PHY_POWER_COLLAPSE BIT(0)
331 /*
332 * Allow PHY RETENTION mode before turning off the digital
333 * voltage regulator(VDDCX).
334 */
335#define ALLOW_PHY_RETENTION BIT(1)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336 unsigned long lpm_flags;
337#define PHY_PWR_COLLAPSED BIT(0)
338#define PHY_RETENTIONED BIT(1)
Ofir Cohen4da266f2012-01-03 10:19:29 +0200339 int reset_counter;
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530340 unsigned long b_last_se0_sess;
341 unsigned long tmouts;
342 u8 active_tmout;
343 struct hrtimer timer;
Mayank Rana248698c2012-04-19 00:03:16 +0530344 enum usb_vdd_type vdd_type;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530345};
346
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530347struct msm_hsic_host_platform_data {
348 unsigned strobe;
349 unsigned data;
Hemant Kumare6275972012-02-29 20:06:21 -0800350 struct msm_bus_scale_pdata *bus_scale_table;
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530351};
352
Manu Gautam91223e02011-11-08 15:27:22 +0530353struct msm_usb_host_platform_data {
354 unsigned int power_budget;
Hemant Kumar56925352012-02-13 16:59:52 -0800355 unsigned int dock_connect_irq;
Manu Gautam91223e02011-11-08 15:27:22 +0530356};
357
Ofir Cohenc7827e42011-12-13 20:10:01 +0200358struct usb_bam_pipe_connect {
359 u32 src_phy_addr;
360 int src_pipe_index;
361 u32 dst_phy_addr;
362 int dst_pipe_index;
363 u32 data_fifo_base_offset;
364 u32 data_fifo_size;
365 u32 desc_fifo_base_offset;
366 u32 desc_fifo_size;
367};
368
369struct msm_usb_bam_platform_data {
370 struct usb_bam_pipe_connect *connections;
Ofir Cohen010009b2012-01-26 16:49:17 +0200371 int usb_active_bam;
Ofir Cohenc7827e42011-12-13 20:10:01 +0200372 int usb_bam_num_pipes;
373};
Ofir Cohen010009b2012-01-26 16:49:17 +0200374
375enum usb_bam {
376 HSUSB_BAM = 0,
377 HSIC_BAM,
378};
Ido Shayevitzd1cb16c2012-03-28 18:57:47 +0200379
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300380int msm_ep_config(struct usb_ep *ep);
381int msm_ep_unconfig(struct usb_ep *ep);
382int msm_data_fifo_config(struct usb_ep *ep, u32 addr, u32 size);
383
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530384#endif