blob: 9da199997d7a13d64211ac48e78262c76829a6f8 [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>
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>
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053028
Ido Shayevitzd1cb16c2012-03-28 18:57:47 +020029/*
30 * The following are bit fields describing the usb_request.udc_priv word.
31 * These bit fields are set by function drivers that wish to queue
32 * usb_requests with sps/bam parameters.
33 */
34#define MSM_PIPE_ID_MASK (0x1F)
35#define MSM_TX_PIPE_ID_OFS (16)
36#define MSM_SPS_MODE BIT(5)
37#define MSM_IS_FINITE_TRANSFER BIT(6)
38#define MSM_PRODUCER BIT(7)
39#define MSM_DISABLE_WB BIT(8)
40#define MSM_ETD_IOC BIT(9)
41#define MSM_INTERNAL_MEM BIT(10)
42#define MSM_VENDOR_ID BIT(16)
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +053043
44/**
45 * Supported USB modes
46 *
47 * USB_PERIPHERAL Only peripheral mode is supported.
48 * USB_HOST Only host mode is supported.
49 * USB_OTG OTG mode is supported.
50 *
51 */
52enum usb_mode_type {
53 USB_NONE = 0,
54 USB_PERIPHERAL,
55 USB_HOST,
56 USB_OTG,
57};
58
59/**
60 * OTG control
61 *
62 * OTG_NO_CONTROL Id/VBUS notifications not required. Useful in host
63 * only configuration.
64 * OTG_PHY_CONTROL Id/VBUS notifications comes form USB PHY.
65 * OTG_PMIC_CONTROL Id/VBUS notifications comes from PMIC hardware.
66 * OTG_USER_CONTROL Id/VBUS notifcations comes from User via sysfs.
67 *
68 */
69enum otg_control_type {
70 OTG_NO_CONTROL = 0,
71 OTG_PHY_CONTROL,
72 OTG_PMIC_CONTROL,
73 OTG_USER_CONTROL,
74};
75
76/**
Pavankumar Kondetid8608522011-05-04 10:19:47 +053077 * PHY used in
78 *
79 * INVALID_PHY Unsupported PHY
80 * CI_45NM_INTEGRATED_PHY Chipidea 45nm integrated PHY
81 * SNPS_28NM_INTEGRATED_PHY Synopsis 28nm integrated PHY
82 *
83 */
84enum msm_usb_phy_type {
85 INVALID_PHY = 0,
86 CI_45NM_INTEGRATED_PHY,
87 SNPS_28NM_INTEGRATED_PHY,
88};
89
90#define IDEV_CHG_MAX 1500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091#define IDEV_CHG_MIN 500
Pavankumar Kondetid8608522011-05-04 10:19:47 +053092#define IUNIT 100
93
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +053094#define IDEV_ACA_CHG_MAX 1500
95#define IDEV_ACA_CHG_LIMIT 500
96
Pavankumar Kondetid8608522011-05-04 10:19:47 +053097/**
98 * Different states involved in USB charger detection.
99 *
100 * USB_CHG_STATE_UNDEFINED USB charger is not connected or detection
101 * process is not yet started.
102 * USB_CHG_STATE_WAIT_FOR_DCD Waiting for Data pins contact.
103 * USB_CHG_STATE_DCD_DONE Data pin contact is detected.
104 * USB_CHG_STATE_PRIMARY_DONE Primary detection is completed (Detects
105 * between SDP and DCP/CDP).
106 * USB_CHG_STATE_SECONDARY_DONE Secondary detection is completed (Detects
107 * between DCP and CDP).
108 * USB_CHG_STATE_DETECTED USB charger type is determined.
109 *
110 */
111enum usb_chg_state {
112 USB_CHG_STATE_UNDEFINED = 0,
113 USB_CHG_STATE_WAIT_FOR_DCD,
114 USB_CHG_STATE_DCD_DONE,
115 USB_CHG_STATE_PRIMARY_DONE,
116 USB_CHG_STATE_SECONDARY_DONE,
117 USB_CHG_STATE_DETECTED,
118};
119
120/**
121 * USB charger types
122 *
123 * USB_INVALID_CHARGER Invalid USB charger.
124 * USB_SDP_CHARGER Standard downstream port. Refers to a downstream port
125 * on USB2.0 compliant host/hub.
126 * USB_DCP_CHARGER Dedicated charger port (AC charger/ Wall charger).
127 * USB_CDP_CHARGER Charging downstream port. Enumeration can happen and
128 * IDEV_CHG_MAX can be drawn irrespective of USB state.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129 * USB_ACA_A_CHARGER B-device is connected on accessory port with charger
130 * connected on charging port. This configuration allows
131 * charging in host mode.
132 * USB_ACA_B_CHARGER No device (or A-device without VBUS) is connected on
133 * accessory port with charger connected on charging port.
134 * USB_ACA_C_CHARGER A-device (with VBUS) is connected on
135 * accessory port with charger connected on charging port.
136 * USB_ACA_DOCK_CHARGER A docking station that has one upstream port and one
137 * or more downstream ports. Capable of supplying
138 * IDEV_CHG_MAX irrespective of devices connected on
139 * accessory ports.
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530140 */
141enum usb_chg_type {
142 USB_INVALID_CHARGER = 0,
143 USB_SDP_CHARGER,
144 USB_DCP_CHARGER,
145 USB_CDP_CHARGER,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146 USB_ACA_A_CHARGER,
147 USB_ACA_B_CHARGER,
148 USB_ACA_C_CHARGER,
149 USB_ACA_DOCK_CHARGER,
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530150};
151
152/**
Mayank Rana248698c2012-04-19 00:03:16 +0530153 * Used different VDDCX voltage voting mechnism
154 * VDDCX_CORNER Vote for VDDCX Corner voltage
155 * VDDCX Vote for VDDCX Absolute voltage
156 */
157enum usb_vdd_type {
158 VDDCX_CORNER = 0,
159 VDDCX,
160 VDD_TYPE_MAX,
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530161};
162
163/**
Amit Blayd6ea6102012-06-07 16:26:24 +0300164 * Used different VDDCX voltage values
165 */
166enum usb_vdd_value {
167 VDD_NONE = 0,
168 VDD_MIN,
169 VDD_MAX,
170 VDD_VAL_MAX,
171};
172
173/**
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530174 * struct msm_otg_platform_data - platform device data
Pavankumar Kondetidfb21302011-03-04 22:45:02 +0530175 * for msm_otg driver.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530176 * @phy_init_seq: PHY configuration sequence. val, reg pairs
177 * terminated by -1.
Mayank Rana8549e632012-01-23 12:49:54 +0530178 * @vbus_power: VBUS power on/off routine.It should return result
179 * as success(zero value) or failure(non-zero value).
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530180 * @power_budget: VBUS power budget in mA (0 will be treated as 500mA).
181 * @mode: Supported mode (OTG/peripheral/host).
182 * @otg_control: OTG switch controlled by user/Id pin
183 * @default_mode: Default operational mode. Applicable only if
184 * OTG switch is controller by user.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 * @pmic_id_irq: IRQ number assigned for PMIC USB ID line.
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530186 * @mhl_enable: indicates MHL connector or not.
Ofir Cohen4da266f2012-01-03 10:19:29 +0200187 * @disable_reset_on_disconnect: perform USB PHY and LINK reset
188 * on USB cable disconnection.
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +0530189 * @enable_dcd: Enable Data Contact Detection circuit. if not set
190 * wait for 600msec before proceeding to primary
191 * detection.
Amit Blay6fa647a2012-05-24 14:12:08 +0300192 * @enable_lpm_on_suspend: Enable the USB core to go into Low
193 * Power Mode, when USB bus is suspended but cable
194 * is connected.
Amit Blay9b6e58b2012-06-18 13:12:49 +0300195 * @core_clk_always_on_workaround: Don't disable core_clk when
196 * USB enters LPM.
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530197 * @bus_scale_table: parameters for bus bandwidth requirements
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530198 */
199struct msm_otg_platform_data {
200 int *phy_init_seq;
Mayank Rana8549e632012-01-23 12:49:54 +0530201 int (*vbus_power)(bool on);
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530202 unsigned power_budget;
203 enum usb_mode_type mode;
204 enum otg_control_type otg_control;
205 enum usb_mode_type default_mode;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530206 enum msm_usb_phy_type phy_type;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530207 void (*setup_gpio)(enum usb_otg_state state);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700208 int pmic_id_irq;
Vijayavardhan Vennapusafc464f02011-11-04 21:54:00 +0530209 bool mhl_enable;
Ofir Cohen4da266f2012-01-03 10:19:29 +0200210 bool disable_reset_on_disconnect;
Pavankumar Kondeti2d09e5f2012-01-16 08:56:57 +0530211 bool enable_dcd;
Amit Blay6fa647a2012-05-24 14:12:08 +0300212 bool enable_lpm_on_dev_suspend;
Amit Blay9b6e58b2012-06-18 13:12:49 +0300213 bool core_clk_always_on_workaround;
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530214 struct msm_bus_scale_pdata *bus_scale_table;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530215};
216
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530217/* Timeout (in msec) values (min - max) associated with OTG timers */
218
219#define TA_WAIT_VRISE 100 /* ( - 100) */
220#define TA_WAIT_VFALL 500 /* ( - 1000) */
221
222/*
223 * This option is set for embedded hosts or OTG devices in which leakage
224 * currents are very minimal.
225 */
226#ifdef CONFIG_USB_OTG
227#define TA_WAIT_BCON 30000 /* (1100 - 30000) */
228#else
229#define TA_WAIT_BCON -1
230#endif
231
232#define TA_AIDL_BDIS 500 /* (200 - ) */
233#define TA_BIDL_ADIS 155 /* (155 - 200) */
234#define TB_SRP_FAIL 6000 /* (5000 - 6000) */
235#define TB_ASE0_BRST 200 /* (155 - ) */
236
237/* TB_SSEND_SRP and TB_SE0_SRP are combined */
238#define TB_SRP_INIT 2000 /* (1500 - ) */
239
240#define TA_TST_MAINT 10100 /* (9900 - 10100) */
241#define TB_TST_SRP 3000 /* ( - 5000) */
242#define TB_TST_CONFIG 300
243
244/* Timeout variables */
245
246#define A_WAIT_VRISE 0
247#define A_WAIT_VFALL 1
248#define A_WAIT_BCON 2
249#define A_AIDL_BDIS 3
250#define A_BIDL_ADIS 4
251#define B_SRP_FAIL 5
252#define B_ASE0_BRST 6
253#define A_TST_MAINT 7
254#define B_TST_SRP 8
255#define B_TST_CONFIG 9
256
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530257/**
258 * struct msm_otg: OTG driver data. Shared by HCD and DCD.
259 * @otg: USB OTG Transceiver structure.
260 * @pdata: otg device platform data.
261 * @irq: IRQ number assigned for HSUSB controller.
Manu Gautam5143b252012-01-05 19:25:23 -0800262 * @clk: clock struct of alt_core_clk.
263 * @pclk: clock struct of iface_clk.
264 * @phy_reset_clk: clock struct of phy_clk.
265 * @core_clk: clock struct of core_bus_clk.
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530266 * @regs: ioremapped register base address.
267 * @inputs: OTG state machine inputs(Id, SessValid etc).
268 * @sm_work: OTG state machine work.
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530269 * @in_lpm: indicates low power mode (LPM) state.
270 * @async_int: Async interrupt arrived.
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530271 * @cur_power: The amount of mA available from downstream port.
272 * @chg_work: Charger detection work.
273 * @chg_state: The state of charger detection process.
274 * @chg_type: The type of charger attached.
275 * @dcd_retires: The retry count used to track Data contact
276 * detection process.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700277 * @wlock: Wake lock struct to prevent system suspend when
278 * USB is active.
279 * @usbdev_nb: The notifier block used to know about the B-device
280 * connected. Useful only when ACA_A charger is
281 * connected.
282 * @mA_port: The amount of current drawn by the attached B-device.
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530283 * @id_timer: The timer used for polling ID line to detect ACA states.
Anji jonnala7da3f262011-12-02 17:22:14 -0800284 * @xo_handle: TCXO buffer handle
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530285 * @bus_perf_client: Bus performance client handle to request BUS bandwidth
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530286 */
287struct msm_otg {
Heikki Krogerus1d4c9292012-02-13 13:24:09 +0200288 struct usb_phy phy;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530289 struct msm_otg_platform_data *pdata;
290 int irq;
291 struct clk *clk;
292 struct clk *pclk;
293 struct clk *phy_reset_clk;
294 struct clk *core_clk;
295 void __iomem *regs;
296#define ID 0
297#define B_SESS_VLD 1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298#define ID_A 2
299#define ID_B 3
300#define ID_C 4
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530301#define A_BUS_DROP 5
302#define A_BUS_REQ 6
303#define A_SRP_DET 7
304#define A_VBUS_VLD 8
305#define B_CONN 9
306#define ADP_CHANGE 10
307#define POWER_UP 11
308#define A_CLR_ERR 12
309#define A_BUS_RESUME 13
310#define A_BUS_SUSPEND 14
311#define A_CONN 15
312#define B_BUS_REQ 16
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530313 unsigned long inputs;
314 struct work_struct sm_work;
Jack Pham5ca279b2012-05-14 18:42:54 -0700315 bool sm_work_pending;
316 atomic_t pm_suspended;
Pavankumar Kondeti87c01042010-12-07 17:53:58 +0530317 atomic_t in_lpm;
318 int async_int;
Pavankumar Kondetid8608522011-05-04 10:19:47 +0530319 unsigned cur_power;
320 struct delayed_work chg_work;
321 enum usb_chg_state chg_state;
322 enum usb_chg_type chg_type;
323 u8 dcd_retries;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700324 struct wake_lock wlock;
325 struct notifier_block usbdev_nb;
326 unsigned mA_port;
Pavankumar Kondetiaa449e12011-11-04 11:09:26 +0530327 struct timer_list id_timer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700328 unsigned long caps;
Stephen Boyd30ad10b2012-03-01 14:51:04 -0800329 struct msm_xo_voter *xo_handle;
Manu Gautamcd82e9d2011-12-20 14:17:28 +0530330 uint32_t bus_perf_client;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700331 /*
332 * Allowing PHY power collpase turns off the HSUSB 3.3v and 1.8v
333 * analog regulators while going to low power mode.
334 * Currently only 8960(28nm PHY) has the support to allowing PHY
335 * power collapse since it doesn't have leakage currents while
336 * turning off the power rails.
337 */
338#define ALLOW_PHY_POWER_COLLAPSE BIT(0)
339 /*
340 * Allow PHY RETENTION mode before turning off the digital
341 * voltage regulator(VDDCX).
342 */
343#define ALLOW_PHY_RETENTION BIT(1)
Amit Blay6fa647a2012-05-24 14:12:08 +0300344 /*
345 * Allow putting the core in Low Power mode, when
346 * USB bus is suspended but cable is connected.
347 */
348#define ALLOW_LPM_ON_DEV_SUSPEND BIT(2)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700349 unsigned long lpm_flags;
350#define PHY_PWR_COLLAPSED BIT(0)
351#define PHY_RETENTIONED BIT(1)
Vijayavardhan Vennapusabbdd6082012-06-06 14:14:25 +0530352#define XO_SHUTDOWN BIT(2)
Ofir Cohen4da266f2012-01-03 10:19:29 +0200353 int reset_counter;
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530354 unsigned long b_last_se0_sess;
355 unsigned long tmouts;
356 u8 active_tmout;
357 struct hrtimer timer;
Mayank Rana248698c2012-04-19 00:03:16 +0530358 enum usb_vdd_type vdd_type;
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530359};
360
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530361struct msm_hsic_host_platform_data {
362 unsigned strobe;
363 unsigned data;
Hemant Kumare6275972012-02-29 20:06:21 -0800364 struct msm_bus_scale_pdata *bus_scale_table;
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530365};
366
Manu Gautam91223e02011-11-08 15:27:22 +0530367struct msm_usb_host_platform_data {
368 unsigned int power_budget;
Hemant Kumar56925352012-02-13 16:59:52 -0800369 unsigned int dock_connect_irq;
Manu Gautam91223e02011-11-08 15:27:22 +0530370};
371
Amit Blay9b6e58b2012-06-18 13:12:49 +0300372/**
373 * struct msm_hsic_peripheral_platform_data: HSIC peripheral
374 * platform data.
375 * @core_clk_always_on_workaround: Don't disable core_clk when
376 * HSIC enters LPM.
377 */
Amit Blay4d57d362012-04-28 11:00:21 +0300378struct msm_hsic_peripheral_platform_data {
Amit Blay9b6e58b2012-06-18 13:12:49 +0300379 bool core_clk_always_on_workaround;
Amit Blay4d57d362012-04-28 11:00:21 +0300380};
381
Ofir Cohenc7827e42011-12-13 20:10:01 +0200382struct usb_bam_pipe_connect {
383 u32 src_phy_addr;
384 int src_pipe_index;
385 u32 dst_phy_addr;
386 int dst_pipe_index;
387 u32 data_fifo_base_offset;
388 u32 data_fifo_size;
389 u32 desc_fifo_base_offset;
390 u32 desc_fifo_size;
391};
392
393struct msm_usb_bam_platform_data {
394 struct usb_bam_pipe_connect *connections;
Ofir Cohen010009b2012-01-26 16:49:17 +0200395 int usb_active_bam;
Ofir Cohenc7827e42011-12-13 20:10:01 +0200396 int usb_bam_num_pipes;
397};
Ofir Cohen010009b2012-01-26 16:49:17 +0200398
399enum usb_bam {
400 HSUSB_BAM = 0,
401 HSIC_BAM,
402};
Ido Shayevitzd1cb16c2012-03-28 18:57:47 +0200403
Ido Shayevitz9fb83452012-04-01 17:45:58 +0300404int msm_ep_config(struct usb_ep *ep);
405int msm_ep_unconfig(struct usb_ep *ep);
406int msm_data_fifo_config(struct usb_ep *ep, u32 addr, u32 size);
407
Pavankumar Kondetie0c201f2010-12-07 17:53:55 +0530408#endif