162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
262306a36Sopenharmony_ci/* Copyright (C) 2007,2008 Freescale Semiconductor, Inc. */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#include <linux/usb/otg-fsm.h>
562306a36Sopenharmony_ci#include <linux/usb/otg.h>
662306a36Sopenharmony_ci#include <linux/ioctl.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci/* USB Command Register Bit Masks */
962306a36Sopenharmony_ci#define USB_CMD_RUN_STOP		(0x1<<0)
1062306a36Sopenharmony_ci#define USB_CMD_CTRL_RESET		(0x1<<1)
1162306a36Sopenharmony_ci#define USB_CMD_PERIODIC_SCHEDULE_EN	(0x1<<4)
1262306a36Sopenharmony_ci#define USB_CMD_ASYNC_SCHEDULE_EN	(0x1<<5)
1362306a36Sopenharmony_ci#define USB_CMD_INT_AA_DOORBELL		(0x1<<6)
1462306a36Sopenharmony_ci#define USB_CMD_ASP			(0x3<<8)
1562306a36Sopenharmony_ci#define USB_CMD_ASYNC_SCH_PARK_EN	(0x1<<11)
1662306a36Sopenharmony_ci#define USB_CMD_SUTW			(0x1<<13)
1762306a36Sopenharmony_ci#define USB_CMD_ATDTW			(0x1<<14)
1862306a36Sopenharmony_ci#define USB_CMD_ITC			(0xFF<<16)
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* bit 15,3,2 are frame list size */
2162306a36Sopenharmony_ci#define USB_CMD_FRAME_SIZE_1024		(0x0<<15 | 0x0<<2)
2262306a36Sopenharmony_ci#define USB_CMD_FRAME_SIZE_512		(0x0<<15 | 0x1<<2)
2362306a36Sopenharmony_ci#define USB_CMD_FRAME_SIZE_256		(0x0<<15 | 0x2<<2)
2462306a36Sopenharmony_ci#define USB_CMD_FRAME_SIZE_128		(0x0<<15 | 0x3<<2)
2562306a36Sopenharmony_ci#define USB_CMD_FRAME_SIZE_64		(0x1<<15 | 0x0<<2)
2662306a36Sopenharmony_ci#define USB_CMD_FRAME_SIZE_32		(0x1<<15 | 0x1<<2)
2762306a36Sopenharmony_ci#define USB_CMD_FRAME_SIZE_16		(0x1<<15 | 0x2<<2)
2862306a36Sopenharmony_ci#define USB_CMD_FRAME_SIZE_8		(0x1<<15 | 0x3<<2)
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci/* bit 9-8 are async schedule park mode count */
3162306a36Sopenharmony_ci#define USB_CMD_ASP_00			(0x0<<8)
3262306a36Sopenharmony_ci#define USB_CMD_ASP_01			(0x1<<8)
3362306a36Sopenharmony_ci#define USB_CMD_ASP_10			(0x2<<8)
3462306a36Sopenharmony_ci#define USB_CMD_ASP_11			(0x3<<8)
3562306a36Sopenharmony_ci#define USB_CMD_ASP_BIT_POS		(8)
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci/* bit 23-16 are interrupt threshold control */
3862306a36Sopenharmony_ci#define USB_CMD_ITC_NO_THRESHOLD	(0x00<<16)
3962306a36Sopenharmony_ci#define USB_CMD_ITC_1_MICRO_FRM		(0x01<<16)
4062306a36Sopenharmony_ci#define USB_CMD_ITC_2_MICRO_FRM		(0x02<<16)
4162306a36Sopenharmony_ci#define USB_CMD_ITC_4_MICRO_FRM		(0x04<<16)
4262306a36Sopenharmony_ci#define USB_CMD_ITC_8_MICRO_FRM		(0x08<<16)
4362306a36Sopenharmony_ci#define USB_CMD_ITC_16_MICRO_FRM	(0x10<<16)
4462306a36Sopenharmony_ci#define USB_CMD_ITC_32_MICRO_FRM	(0x20<<16)
4562306a36Sopenharmony_ci#define USB_CMD_ITC_64_MICRO_FRM	(0x40<<16)
4662306a36Sopenharmony_ci#define USB_CMD_ITC_BIT_POS		(16)
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci/* USB Status Register Bit Masks */
4962306a36Sopenharmony_ci#define USB_STS_INT			(0x1<<0)
5062306a36Sopenharmony_ci#define USB_STS_ERR			(0x1<<1)
5162306a36Sopenharmony_ci#define USB_STS_PORT_CHANGE		(0x1<<2)
5262306a36Sopenharmony_ci#define USB_STS_FRM_LST_ROLL		(0x1<<3)
5362306a36Sopenharmony_ci#define USB_STS_SYS_ERR			(0x1<<4)
5462306a36Sopenharmony_ci#define USB_STS_IAA			(0x1<<5)
5562306a36Sopenharmony_ci#define USB_STS_RESET_RECEIVED		(0x1<<6)
5662306a36Sopenharmony_ci#define USB_STS_SOF			(0x1<<7)
5762306a36Sopenharmony_ci#define USB_STS_DCSUSPEND		(0x1<<8)
5862306a36Sopenharmony_ci#define USB_STS_HC_HALTED		(0x1<<12)
5962306a36Sopenharmony_ci#define USB_STS_RCL			(0x1<<13)
6062306a36Sopenharmony_ci#define USB_STS_PERIODIC_SCHEDULE	(0x1<<14)
6162306a36Sopenharmony_ci#define USB_STS_ASYNC_SCHEDULE		(0x1<<15)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* USB Interrupt Enable Register Bit Masks */
6462306a36Sopenharmony_ci#define USB_INTR_INT_EN			(0x1<<0)
6562306a36Sopenharmony_ci#define USB_INTR_ERR_INT_EN		(0x1<<1)
6662306a36Sopenharmony_ci#define USB_INTR_PC_DETECT_EN		(0x1<<2)
6762306a36Sopenharmony_ci#define USB_INTR_FRM_LST_ROLL_EN	(0x1<<3)
6862306a36Sopenharmony_ci#define USB_INTR_SYS_ERR_EN		(0x1<<4)
6962306a36Sopenharmony_ci#define USB_INTR_ASYN_ADV_EN		(0x1<<5)
7062306a36Sopenharmony_ci#define USB_INTR_RESET_EN		(0x1<<6)
7162306a36Sopenharmony_ci#define USB_INTR_SOF_EN			(0x1<<7)
7262306a36Sopenharmony_ci#define USB_INTR_DEVICE_SUSPEND		(0x1<<8)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/* Device Address bit masks */
7562306a36Sopenharmony_ci#define USB_DEVICE_ADDRESS_MASK		(0x7F<<25)
7662306a36Sopenharmony_ci#define USB_DEVICE_ADDRESS_BIT_POS	(25)
7762306a36Sopenharmony_ci/* PORTSC  Register Bit Masks,Only one PORT in OTG mode*/
7862306a36Sopenharmony_ci#define PORTSC_CURRENT_CONNECT_STATUS	(0x1<<0)
7962306a36Sopenharmony_ci#define PORTSC_CONNECT_STATUS_CHANGE	(0x1<<1)
8062306a36Sopenharmony_ci#define PORTSC_PORT_ENABLE		(0x1<<2)
8162306a36Sopenharmony_ci#define PORTSC_PORT_EN_DIS_CHANGE	(0x1<<3)
8262306a36Sopenharmony_ci#define PORTSC_OVER_CURRENT_ACT		(0x1<<4)
8362306a36Sopenharmony_ci#define PORTSC_OVER_CUURENT_CHG		(0x1<<5)
8462306a36Sopenharmony_ci#define PORTSC_PORT_FORCE_RESUME	(0x1<<6)
8562306a36Sopenharmony_ci#define PORTSC_PORT_SUSPEND		(0x1<<7)
8662306a36Sopenharmony_ci#define PORTSC_PORT_RESET		(0x1<<8)
8762306a36Sopenharmony_ci#define PORTSC_LINE_STATUS_BITS		(0x3<<10)
8862306a36Sopenharmony_ci#define PORTSC_PORT_POWER		(0x1<<12)
8962306a36Sopenharmony_ci#define PORTSC_PORT_INDICTOR_CTRL	(0x3<<14)
9062306a36Sopenharmony_ci#define PORTSC_PORT_TEST_CTRL		(0xF<<16)
9162306a36Sopenharmony_ci#define PORTSC_WAKE_ON_CONNECT_EN	(0x1<<20)
9262306a36Sopenharmony_ci#define PORTSC_WAKE_ON_CONNECT_DIS	(0x1<<21)
9362306a36Sopenharmony_ci#define PORTSC_WAKE_ON_OVER_CURRENT	(0x1<<22)
9462306a36Sopenharmony_ci#define PORTSC_PHY_LOW_POWER_SPD	(0x1<<23)
9562306a36Sopenharmony_ci#define PORTSC_PORT_FORCE_FULL_SPEED	(0x1<<24)
9662306a36Sopenharmony_ci#define PORTSC_PORT_SPEED_MASK		(0x3<<26)
9762306a36Sopenharmony_ci#define PORTSC_TRANSCEIVER_WIDTH	(0x1<<28)
9862306a36Sopenharmony_ci#define PORTSC_PHY_TYPE_SEL		(0x3<<30)
9962306a36Sopenharmony_ci/* bit 11-10 are line status */
10062306a36Sopenharmony_ci#define PORTSC_LINE_STATUS_SE0		(0x0<<10)
10162306a36Sopenharmony_ci#define PORTSC_LINE_STATUS_JSTATE	(0x1<<10)
10262306a36Sopenharmony_ci#define PORTSC_LINE_STATUS_KSTATE	(0x2<<10)
10362306a36Sopenharmony_ci#define PORTSC_LINE_STATUS_UNDEF	(0x3<<10)
10462306a36Sopenharmony_ci#define PORTSC_LINE_STATUS_BIT_POS	(10)
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/* bit 15-14 are port indicator control */
10762306a36Sopenharmony_ci#define PORTSC_PIC_OFF			(0x0<<14)
10862306a36Sopenharmony_ci#define PORTSC_PIC_AMBER		(0x1<<14)
10962306a36Sopenharmony_ci#define PORTSC_PIC_GREEN		(0x2<<14)
11062306a36Sopenharmony_ci#define PORTSC_PIC_UNDEF		(0x3<<14)
11162306a36Sopenharmony_ci#define PORTSC_PIC_BIT_POS		(14)
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* bit 19-16 are port test control */
11462306a36Sopenharmony_ci#define PORTSC_PTC_DISABLE		(0x0<<16)
11562306a36Sopenharmony_ci#define PORTSC_PTC_JSTATE		(0x1<<16)
11662306a36Sopenharmony_ci#define PORTSC_PTC_KSTATE		(0x2<<16)
11762306a36Sopenharmony_ci#define PORTSC_PTC_SEQNAK		(0x3<<16)
11862306a36Sopenharmony_ci#define PORTSC_PTC_PACKET		(0x4<<16)
11962306a36Sopenharmony_ci#define PORTSC_PTC_FORCE_EN		(0x5<<16)
12062306a36Sopenharmony_ci#define PORTSC_PTC_BIT_POS		(16)
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci/* bit 27-26 are port speed */
12362306a36Sopenharmony_ci#define PORTSC_PORT_SPEED_FULL		(0x0<<26)
12462306a36Sopenharmony_ci#define PORTSC_PORT_SPEED_LOW		(0x1<<26)
12562306a36Sopenharmony_ci#define PORTSC_PORT_SPEED_HIGH		(0x2<<26)
12662306a36Sopenharmony_ci#define PORTSC_PORT_SPEED_UNDEF		(0x3<<26)
12762306a36Sopenharmony_ci#define PORTSC_SPEED_BIT_POS		(26)
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci/* bit 28 is parallel transceiver width for UTMI interface */
13062306a36Sopenharmony_ci#define PORTSC_PTW			(0x1<<28)
13162306a36Sopenharmony_ci#define PORTSC_PTW_8BIT			(0x0<<28)
13262306a36Sopenharmony_ci#define PORTSC_PTW_16BIT		(0x1<<28)
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci/* bit 31-30 are port transceiver select */
13562306a36Sopenharmony_ci#define PORTSC_PTS_UTMI			(0x0<<30)
13662306a36Sopenharmony_ci#define PORTSC_PTS_ULPI			(0x2<<30)
13762306a36Sopenharmony_ci#define PORTSC_PTS_FSLS_SERIAL		(0x3<<30)
13862306a36Sopenharmony_ci#define PORTSC_PTS_BIT_POS		(30)
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci#define PORTSC_W1C_BITS			\
14162306a36Sopenharmony_ci	(PORTSC_CONNECT_STATUS_CHANGE |	\
14262306a36Sopenharmony_ci	 PORTSC_PORT_EN_DIS_CHANGE    |	\
14362306a36Sopenharmony_ci	 PORTSC_OVER_CUURENT_CHG)
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/* OTG Status Control Register Bit Masks */
14662306a36Sopenharmony_ci#define OTGSC_CTRL_VBUS_DISCHARGE	(0x1<<0)
14762306a36Sopenharmony_ci#define OTGSC_CTRL_VBUS_CHARGE		(0x1<<1)
14862306a36Sopenharmony_ci#define OTGSC_CTRL_OTG_TERMINATION	(0x1<<3)
14962306a36Sopenharmony_ci#define OTGSC_CTRL_DATA_PULSING		(0x1<<4)
15062306a36Sopenharmony_ci#define OTGSC_CTRL_ID_PULL_EN		(0x1<<5)
15162306a36Sopenharmony_ci#define OTGSC_HA_DATA_PULSE		(0x1<<6)
15262306a36Sopenharmony_ci#define OTGSC_HA_BA			(0x1<<7)
15362306a36Sopenharmony_ci#define OTGSC_STS_USB_ID		(0x1<<8)
15462306a36Sopenharmony_ci#define OTGSC_STS_A_VBUS_VALID		(0x1<<9)
15562306a36Sopenharmony_ci#define OTGSC_STS_A_SESSION_VALID	(0x1<<10)
15662306a36Sopenharmony_ci#define OTGSC_STS_B_SESSION_VALID	(0x1<<11)
15762306a36Sopenharmony_ci#define OTGSC_STS_B_SESSION_END		(0x1<<12)
15862306a36Sopenharmony_ci#define OTGSC_STS_1MS_TOGGLE		(0x1<<13)
15962306a36Sopenharmony_ci#define OTGSC_STS_DATA_PULSING		(0x1<<14)
16062306a36Sopenharmony_ci#define OTGSC_INTSTS_USB_ID		(0x1<<16)
16162306a36Sopenharmony_ci#define OTGSC_INTSTS_A_VBUS_VALID	(0x1<<17)
16262306a36Sopenharmony_ci#define OTGSC_INTSTS_A_SESSION_VALID	(0x1<<18)
16362306a36Sopenharmony_ci#define OTGSC_INTSTS_B_SESSION_VALID	(0x1<<19)
16462306a36Sopenharmony_ci#define OTGSC_INTSTS_B_SESSION_END	(0x1<<20)
16562306a36Sopenharmony_ci#define OTGSC_INTSTS_1MS		(0x1<<21)
16662306a36Sopenharmony_ci#define OTGSC_INTSTS_DATA_PULSING	(0x1<<22)
16762306a36Sopenharmony_ci#define OTGSC_INTR_USB_ID_EN		(0x1<<24)
16862306a36Sopenharmony_ci#define OTGSC_INTR_A_VBUS_VALID_EN	(0x1<<25)
16962306a36Sopenharmony_ci#define OTGSC_INTR_A_SESSION_VALID_EN	(0x1<<26)
17062306a36Sopenharmony_ci#define OTGSC_INTR_B_SESSION_VALID_EN	(0x1<<27)
17162306a36Sopenharmony_ci#define OTGSC_INTR_B_SESSION_END_EN	(0x1<<28)
17262306a36Sopenharmony_ci#define OTGSC_INTR_1MS_TIMER_EN		(0x1<<29)
17362306a36Sopenharmony_ci#define OTGSC_INTR_DATA_PULSING_EN	(0x1<<30)
17462306a36Sopenharmony_ci#define OTGSC_INTSTS_MASK		(0x00ff0000)
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci/* USB MODE Register Bit Masks */
17762306a36Sopenharmony_ci#define  USB_MODE_CTRL_MODE_IDLE	(0x0<<0)
17862306a36Sopenharmony_ci#define  USB_MODE_CTRL_MODE_DEVICE	(0x2<<0)
17962306a36Sopenharmony_ci#define  USB_MODE_CTRL_MODE_HOST	(0x3<<0)
18062306a36Sopenharmony_ci#define  USB_MODE_CTRL_MODE_RSV		(0x1<<0)
18162306a36Sopenharmony_ci#define  USB_MODE_SETUP_LOCK_OFF	(0x1<<3)
18262306a36Sopenharmony_ci#define  USB_MODE_STREAM_DISABLE	(0x1<<4)
18362306a36Sopenharmony_ci#define  USB_MODE_ES			(0x1<<2) /* Endian Select */
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci/* control Register Bit Masks */
18662306a36Sopenharmony_ci#define  USB_CTRL_IOENB			(0x1<<2)
18762306a36Sopenharmony_ci#define  USB_CTRL_ULPI_INT0EN		(0x1<<0)
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci/* BCSR5 */
19062306a36Sopenharmony_ci#define BCSR5_INT_USB			(0x02)
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci/* USB module clk cfg */
19362306a36Sopenharmony_ci#define SCCR_OFFS			(0xA08)
19462306a36Sopenharmony_ci#define SCCR_USB_CLK_DISABLE		(0x00000000)	/* USB clk disable */
19562306a36Sopenharmony_ci#define SCCR_USB_MPHCM_11		(0x00c00000)
19662306a36Sopenharmony_ci#define SCCR_USB_MPHCM_01		(0x00400000)
19762306a36Sopenharmony_ci#define SCCR_USB_MPHCM_10		(0x00800000)
19862306a36Sopenharmony_ci#define SCCR_USB_DRCM_11		(0x00300000)
19962306a36Sopenharmony_ci#define SCCR_USB_DRCM_01		(0x00100000)
20062306a36Sopenharmony_ci#define SCCR_USB_DRCM_10		(0x00200000)
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci#define SICRL_OFFS			(0x114)
20362306a36Sopenharmony_ci#define SICRL_USB0			(0x40000000)
20462306a36Sopenharmony_ci#define SICRL_USB1			(0x20000000)
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ci#define SICRH_OFFS			(0x118)
20762306a36Sopenharmony_ci#define SICRH_USB_UTMI			(0x00020000)
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci/* OTG interrupt enable bit masks */
21062306a36Sopenharmony_ci#define  OTGSC_INTERRUPT_ENABLE_BITS_MASK  \
21162306a36Sopenharmony_ci	(OTGSC_INTR_USB_ID_EN            | \
21262306a36Sopenharmony_ci	OTGSC_INTR_1MS_TIMER_EN		 | \
21362306a36Sopenharmony_ci	OTGSC_INTR_A_VBUS_VALID_EN       | \
21462306a36Sopenharmony_ci	OTGSC_INTR_A_SESSION_VALID_EN    | \
21562306a36Sopenharmony_ci	OTGSC_INTR_B_SESSION_VALID_EN    | \
21662306a36Sopenharmony_ci	OTGSC_INTR_B_SESSION_END_EN      | \
21762306a36Sopenharmony_ci	OTGSC_INTR_DATA_PULSING_EN)
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci/* OTG interrupt status bit masks */
22062306a36Sopenharmony_ci#define  OTGSC_INTERRUPT_STATUS_BITS_MASK  \
22162306a36Sopenharmony_ci	(OTGSC_INTSTS_USB_ID          |    \
22262306a36Sopenharmony_ci	OTGSC_INTR_1MS_TIMER_EN       |    \
22362306a36Sopenharmony_ci	OTGSC_INTSTS_A_VBUS_VALID     |    \
22462306a36Sopenharmony_ci	OTGSC_INTSTS_A_SESSION_VALID  |    \
22562306a36Sopenharmony_ci	OTGSC_INTSTS_B_SESSION_VALID  |    \
22662306a36Sopenharmony_ci	OTGSC_INTSTS_B_SESSION_END    |    \
22762306a36Sopenharmony_ci	OTGSC_INTSTS_DATA_PULSING)
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci/*
23062306a36Sopenharmony_ci *  A-DEVICE timing  constants
23162306a36Sopenharmony_ci */
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ci/* Wait for VBUS Rise  */
23462306a36Sopenharmony_ci#define TA_WAIT_VRISE	(100)	/* a_wait_vrise 100 ms, section: 6.6.5.1 */
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci/* Wait for B-Connect */
23762306a36Sopenharmony_ci#define TA_WAIT_BCON	(10000)  /* a_wait_bcon > 1 sec, section: 6.6.5.2
23862306a36Sopenharmony_ci				  * This is only used to get out of
23962306a36Sopenharmony_ci				  * OTG_STATE_A_WAIT_BCON state if there was
24062306a36Sopenharmony_ci				  * no connection for these many milliseconds
24162306a36Sopenharmony_ci				  */
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci/* A-Idle to B-Disconnect */
24462306a36Sopenharmony_ci/* It is necessary for this timer to be more than 750 ms because of a bug in OPT
24562306a36Sopenharmony_ci * test 5.4 in which B OPT disconnects after 750 ms instead of 75ms as stated
24662306a36Sopenharmony_ci * in the test description
24762306a36Sopenharmony_ci */
24862306a36Sopenharmony_ci#define TA_AIDL_BDIS	(5000)	/* a_suspend minimum 200 ms, section: 6.6.5.3 */
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ci/* B-Idle to A-Disconnect */
25162306a36Sopenharmony_ci#define TA_BIDL_ADIS	(12)	/* 3 to 200 ms */
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci/* B-device timing constants */
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci/* Data-Line Pulse Time*/
25762306a36Sopenharmony_ci#define TB_DATA_PLS	(10)	/* b_srp_init,continue 5~10ms, section:5.3.3 */
25862306a36Sopenharmony_ci#define TB_DATA_PLS_MIN	(5)	/* minimum 5 ms */
25962306a36Sopenharmony_ci#define TB_DATA_PLS_MAX	(10)	/* maximum 10 ms */
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci/* SRP Initiate Time  */
26262306a36Sopenharmony_ci#define TB_SRP_INIT	(100)	/* b_srp_init,maximum 100 ms, section:5.3.8 */
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci/* SRP Fail Time  */
26562306a36Sopenharmony_ci#define TB_SRP_FAIL	(7000)	/* b_srp_init,Fail time 5~30s, section:6.8.2.2*/
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci/* SRP result wait time */
26862306a36Sopenharmony_ci#define TB_SRP_WAIT	(60)
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci/* VBus time */
27162306a36Sopenharmony_ci#define TB_VBUS_PLS	(30)	/* time to keep vbus pulsing asserted */
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci/* Discharge time */
27462306a36Sopenharmony_ci/* This time should be less than 10ms. It varies from system to system. */
27562306a36Sopenharmony_ci#define TB_VBUS_DSCHRG	(8)
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci/* A-SE0 to B-Reset  */
27862306a36Sopenharmony_ci#define TB_ASE0_BRST	(20)	/* b_wait_acon, mini 3.125 ms,section:6.8.2.4 */
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci/* A bus suspend timer before we can switch to b_wait_aconn */
28162306a36Sopenharmony_ci#define TB_A_SUSPEND	(7)
28262306a36Sopenharmony_ci#define TB_BUS_RESUME	(12)
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci/* SE0 Time Before SRP */
28562306a36Sopenharmony_ci#define TB_SE0_SRP	(2)	/* b_idle,minimum 2 ms, section:5.3.2 */
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci#define SET_OTG_STATE(phy, newstate)	((phy)->otg->state = newstate)
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_cistruct usb_dr_mmap {
29062306a36Sopenharmony_ci	/* Capability register */
29162306a36Sopenharmony_ci	u8 res1[256];
29262306a36Sopenharmony_ci	u16 caplength;		/* Capability Register Length */
29362306a36Sopenharmony_ci	u16 hciversion;		/* Host Controller Interface Version */
29462306a36Sopenharmony_ci	u32 hcsparams;		/* Host Controller Structual Parameters */
29562306a36Sopenharmony_ci	u32 hccparams;		/* Host Controller Capability Parameters */
29662306a36Sopenharmony_ci	u8 res2[20];
29762306a36Sopenharmony_ci	u32 dciversion;		/* Device Controller Interface Version */
29862306a36Sopenharmony_ci	u32 dccparams;		/* Device Controller Capability Parameters */
29962306a36Sopenharmony_ci	u8 res3[24];
30062306a36Sopenharmony_ci	/* Operation register */
30162306a36Sopenharmony_ci	u32 usbcmd;		/* USB Command Register */
30262306a36Sopenharmony_ci	u32 usbsts;		/* USB Status Register */
30362306a36Sopenharmony_ci	u32 usbintr;		/* USB Interrupt Enable Register */
30462306a36Sopenharmony_ci	u32 frindex;		/* Frame Index Register */
30562306a36Sopenharmony_ci	u8 res4[4];
30662306a36Sopenharmony_ci	u32 deviceaddr;		/* Device Address */
30762306a36Sopenharmony_ci	u32 endpointlistaddr;	/* Endpoint List Address Register */
30862306a36Sopenharmony_ci	u8 res5[4];
30962306a36Sopenharmony_ci	u32 burstsize;		/* Master Interface Data Burst Size Register */
31062306a36Sopenharmony_ci	u32 txttfilltuning;	/* Transmit FIFO Tuning Controls Register */
31162306a36Sopenharmony_ci	u8 res6[8];
31262306a36Sopenharmony_ci	u32 ulpiview;		/* ULPI register access */
31362306a36Sopenharmony_ci	u8 res7[12];
31462306a36Sopenharmony_ci	u32 configflag;		/* Configure Flag Register */
31562306a36Sopenharmony_ci	u32 portsc;		/* Port 1 Status and Control Register */
31662306a36Sopenharmony_ci	u8 res8[28];
31762306a36Sopenharmony_ci	u32 otgsc;		/* On-The-Go Status and Control */
31862306a36Sopenharmony_ci	u32 usbmode;		/* USB Mode Register */
31962306a36Sopenharmony_ci	u32 endptsetupstat;	/* Endpoint Setup Status Register */
32062306a36Sopenharmony_ci	u32 endpointprime;	/* Endpoint Initialization Register */
32162306a36Sopenharmony_ci	u32 endptflush;		/* Endpoint Flush Register */
32262306a36Sopenharmony_ci	u32 endptstatus;	/* Endpoint Status Register */
32362306a36Sopenharmony_ci	u32 endptcomplete;	/* Endpoint Complete Register */
32462306a36Sopenharmony_ci	u32 endptctrl[6];	/* Endpoint Control Registers */
32562306a36Sopenharmony_ci	u8 res9[552];
32662306a36Sopenharmony_ci	u32 snoop1;
32762306a36Sopenharmony_ci	u32 snoop2;
32862306a36Sopenharmony_ci	u32 age_cnt_thresh;	/* Age Count Threshold Register */
32962306a36Sopenharmony_ci	u32 pri_ctrl;		/* Priority Control Register */
33062306a36Sopenharmony_ci	u32 si_ctrl;		/* System Interface Control Register */
33162306a36Sopenharmony_ci	u8 res10[236];
33262306a36Sopenharmony_ci	u32 control;		/* General Purpose Control Register */
33362306a36Sopenharmony_ci};
33462306a36Sopenharmony_ci
33562306a36Sopenharmony_cistruct fsl_otg_timer {
33662306a36Sopenharmony_ci	unsigned long expires;	/* Number of count increase to timeout */
33762306a36Sopenharmony_ci	unsigned long count;	/* Tick counter */
33862306a36Sopenharmony_ci	void (*function)(unsigned long);	/* Timeout function */
33962306a36Sopenharmony_ci	unsigned long data;	/* Data passed to function */
34062306a36Sopenharmony_ci	struct list_head list;
34162306a36Sopenharmony_ci};
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ciinline struct fsl_otg_timer *otg_timer_initializer
34462306a36Sopenharmony_ci(void (*function)(unsigned long), unsigned long expires, unsigned long data)
34562306a36Sopenharmony_ci{
34662306a36Sopenharmony_ci	struct fsl_otg_timer *timer;
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_ci	timer = kmalloc(sizeof(struct fsl_otg_timer), GFP_KERNEL);
34962306a36Sopenharmony_ci	if (!timer)
35062306a36Sopenharmony_ci		return NULL;
35162306a36Sopenharmony_ci	timer->function = function;
35262306a36Sopenharmony_ci	timer->expires = expires;
35362306a36Sopenharmony_ci	timer->data = data;
35462306a36Sopenharmony_ci	return timer;
35562306a36Sopenharmony_ci}
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_cistruct fsl_otg {
35862306a36Sopenharmony_ci	struct usb_phy phy;
35962306a36Sopenharmony_ci	struct otg_fsm fsm;
36062306a36Sopenharmony_ci	struct usb_dr_mmap *dr_mem_map;
36162306a36Sopenharmony_ci	struct delayed_work otg_event;
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci	/* used for usb host */
36462306a36Sopenharmony_ci	struct work_struct work_wq;
36562306a36Sopenharmony_ci	u8	host_working;
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci	int irq;
36862306a36Sopenharmony_ci};
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_cistruct fsl_otg_config {
37162306a36Sopenharmony_ci	u8 otg_port;
37262306a36Sopenharmony_ci};
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ci#define FSL_OTG_NAME		"fsl-usb2-otg"
37562306a36Sopenharmony_ci
37662306a36Sopenharmony_civoid fsl_otg_add_timer(struct otg_fsm *fsm, void *timer);
37762306a36Sopenharmony_civoid fsl_otg_del_timer(struct otg_fsm *fsm, void *timer);
37862306a36Sopenharmony_civoid fsl_otg_pulse_vbus(void);
379