18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* Copyright (C) 2007,2008 Freescale Semiconductor, Inc. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include <linux/usb/otg-fsm.h> 58c2ecf20Sopenharmony_ci#include <linux/usb/otg.h> 68c2ecf20Sopenharmony_ci#include <linux/ioctl.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* USB Command Register Bit Masks */ 98c2ecf20Sopenharmony_ci#define USB_CMD_RUN_STOP (0x1<<0) 108c2ecf20Sopenharmony_ci#define USB_CMD_CTRL_RESET (0x1<<1) 118c2ecf20Sopenharmony_ci#define USB_CMD_PERIODIC_SCHEDULE_EN (0x1<<4) 128c2ecf20Sopenharmony_ci#define USB_CMD_ASYNC_SCHEDULE_EN (0x1<<5) 138c2ecf20Sopenharmony_ci#define USB_CMD_INT_AA_DOORBELL (0x1<<6) 148c2ecf20Sopenharmony_ci#define USB_CMD_ASP (0x3<<8) 158c2ecf20Sopenharmony_ci#define USB_CMD_ASYNC_SCH_PARK_EN (0x1<<11) 168c2ecf20Sopenharmony_ci#define USB_CMD_SUTW (0x1<<13) 178c2ecf20Sopenharmony_ci#define USB_CMD_ATDTW (0x1<<14) 188c2ecf20Sopenharmony_ci#define USB_CMD_ITC (0xFF<<16) 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* bit 15,3,2 are frame list size */ 218c2ecf20Sopenharmony_ci#define USB_CMD_FRAME_SIZE_1024 (0x0<<15 | 0x0<<2) 228c2ecf20Sopenharmony_ci#define USB_CMD_FRAME_SIZE_512 (0x0<<15 | 0x1<<2) 238c2ecf20Sopenharmony_ci#define USB_CMD_FRAME_SIZE_256 (0x0<<15 | 0x2<<2) 248c2ecf20Sopenharmony_ci#define USB_CMD_FRAME_SIZE_128 (0x0<<15 | 0x3<<2) 258c2ecf20Sopenharmony_ci#define USB_CMD_FRAME_SIZE_64 (0x1<<15 | 0x0<<2) 268c2ecf20Sopenharmony_ci#define USB_CMD_FRAME_SIZE_32 (0x1<<15 | 0x1<<2) 278c2ecf20Sopenharmony_ci#define USB_CMD_FRAME_SIZE_16 (0x1<<15 | 0x2<<2) 288c2ecf20Sopenharmony_ci#define USB_CMD_FRAME_SIZE_8 (0x1<<15 | 0x3<<2) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* bit 9-8 are async schedule park mode count */ 318c2ecf20Sopenharmony_ci#define USB_CMD_ASP_00 (0x0<<8) 328c2ecf20Sopenharmony_ci#define USB_CMD_ASP_01 (0x1<<8) 338c2ecf20Sopenharmony_ci#define USB_CMD_ASP_10 (0x2<<8) 348c2ecf20Sopenharmony_ci#define USB_CMD_ASP_11 (0x3<<8) 358c2ecf20Sopenharmony_ci#define USB_CMD_ASP_BIT_POS (8) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* bit 23-16 are interrupt threshold control */ 388c2ecf20Sopenharmony_ci#define USB_CMD_ITC_NO_THRESHOLD (0x00<<16) 398c2ecf20Sopenharmony_ci#define USB_CMD_ITC_1_MICRO_FRM (0x01<<16) 408c2ecf20Sopenharmony_ci#define USB_CMD_ITC_2_MICRO_FRM (0x02<<16) 418c2ecf20Sopenharmony_ci#define USB_CMD_ITC_4_MICRO_FRM (0x04<<16) 428c2ecf20Sopenharmony_ci#define USB_CMD_ITC_8_MICRO_FRM (0x08<<16) 438c2ecf20Sopenharmony_ci#define USB_CMD_ITC_16_MICRO_FRM (0x10<<16) 448c2ecf20Sopenharmony_ci#define USB_CMD_ITC_32_MICRO_FRM (0x20<<16) 458c2ecf20Sopenharmony_ci#define USB_CMD_ITC_64_MICRO_FRM (0x40<<16) 468c2ecf20Sopenharmony_ci#define USB_CMD_ITC_BIT_POS (16) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* USB Status Register Bit Masks */ 498c2ecf20Sopenharmony_ci#define USB_STS_INT (0x1<<0) 508c2ecf20Sopenharmony_ci#define USB_STS_ERR (0x1<<1) 518c2ecf20Sopenharmony_ci#define USB_STS_PORT_CHANGE (0x1<<2) 528c2ecf20Sopenharmony_ci#define USB_STS_FRM_LST_ROLL (0x1<<3) 538c2ecf20Sopenharmony_ci#define USB_STS_SYS_ERR (0x1<<4) 548c2ecf20Sopenharmony_ci#define USB_STS_IAA (0x1<<5) 558c2ecf20Sopenharmony_ci#define USB_STS_RESET_RECEIVED (0x1<<6) 568c2ecf20Sopenharmony_ci#define USB_STS_SOF (0x1<<7) 578c2ecf20Sopenharmony_ci#define USB_STS_DCSUSPEND (0x1<<8) 588c2ecf20Sopenharmony_ci#define USB_STS_HC_HALTED (0x1<<12) 598c2ecf20Sopenharmony_ci#define USB_STS_RCL (0x1<<13) 608c2ecf20Sopenharmony_ci#define USB_STS_PERIODIC_SCHEDULE (0x1<<14) 618c2ecf20Sopenharmony_ci#define USB_STS_ASYNC_SCHEDULE (0x1<<15) 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* USB Interrupt Enable Register Bit Masks */ 648c2ecf20Sopenharmony_ci#define USB_INTR_INT_EN (0x1<<0) 658c2ecf20Sopenharmony_ci#define USB_INTR_ERR_INT_EN (0x1<<1) 668c2ecf20Sopenharmony_ci#define USB_INTR_PC_DETECT_EN (0x1<<2) 678c2ecf20Sopenharmony_ci#define USB_INTR_FRM_LST_ROLL_EN (0x1<<3) 688c2ecf20Sopenharmony_ci#define USB_INTR_SYS_ERR_EN (0x1<<4) 698c2ecf20Sopenharmony_ci#define USB_INTR_ASYN_ADV_EN (0x1<<5) 708c2ecf20Sopenharmony_ci#define USB_INTR_RESET_EN (0x1<<6) 718c2ecf20Sopenharmony_ci#define USB_INTR_SOF_EN (0x1<<7) 728c2ecf20Sopenharmony_ci#define USB_INTR_DEVICE_SUSPEND (0x1<<8) 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* Device Address bit masks */ 758c2ecf20Sopenharmony_ci#define USB_DEVICE_ADDRESS_MASK (0x7F<<25) 768c2ecf20Sopenharmony_ci#define USB_DEVICE_ADDRESS_BIT_POS (25) 778c2ecf20Sopenharmony_ci/* PORTSC Register Bit Masks,Only one PORT in OTG mode*/ 788c2ecf20Sopenharmony_ci#define PORTSC_CURRENT_CONNECT_STATUS (0x1<<0) 798c2ecf20Sopenharmony_ci#define PORTSC_CONNECT_STATUS_CHANGE (0x1<<1) 808c2ecf20Sopenharmony_ci#define PORTSC_PORT_ENABLE (0x1<<2) 818c2ecf20Sopenharmony_ci#define PORTSC_PORT_EN_DIS_CHANGE (0x1<<3) 828c2ecf20Sopenharmony_ci#define PORTSC_OVER_CURRENT_ACT (0x1<<4) 838c2ecf20Sopenharmony_ci#define PORTSC_OVER_CUURENT_CHG (0x1<<5) 848c2ecf20Sopenharmony_ci#define PORTSC_PORT_FORCE_RESUME (0x1<<6) 858c2ecf20Sopenharmony_ci#define PORTSC_PORT_SUSPEND (0x1<<7) 868c2ecf20Sopenharmony_ci#define PORTSC_PORT_RESET (0x1<<8) 878c2ecf20Sopenharmony_ci#define PORTSC_LINE_STATUS_BITS (0x3<<10) 888c2ecf20Sopenharmony_ci#define PORTSC_PORT_POWER (0x1<<12) 898c2ecf20Sopenharmony_ci#define PORTSC_PORT_INDICTOR_CTRL (0x3<<14) 908c2ecf20Sopenharmony_ci#define PORTSC_PORT_TEST_CTRL (0xF<<16) 918c2ecf20Sopenharmony_ci#define PORTSC_WAKE_ON_CONNECT_EN (0x1<<20) 928c2ecf20Sopenharmony_ci#define PORTSC_WAKE_ON_CONNECT_DIS (0x1<<21) 938c2ecf20Sopenharmony_ci#define PORTSC_WAKE_ON_OVER_CURRENT (0x1<<22) 948c2ecf20Sopenharmony_ci#define PORTSC_PHY_LOW_POWER_SPD (0x1<<23) 958c2ecf20Sopenharmony_ci#define PORTSC_PORT_FORCE_FULL_SPEED (0x1<<24) 968c2ecf20Sopenharmony_ci#define PORTSC_PORT_SPEED_MASK (0x3<<26) 978c2ecf20Sopenharmony_ci#define PORTSC_TRANSCEIVER_WIDTH (0x1<<28) 988c2ecf20Sopenharmony_ci#define PORTSC_PHY_TYPE_SEL (0x3<<30) 998c2ecf20Sopenharmony_ci/* bit 11-10 are line status */ 1008c2ecf20Sopenharmony_ci#define PORTSC_LINE_STATUS_SE0 (0x0<<10) 1018c2ecf20Sopenharmony_ci#define PORTSC_LINE_STATUS_JSTATE (0x1<<10) 1028c2ecf20Sopenharmony_ci#define PORTSC_LINE_STATUS_KSTATE (0x2<<10) 1038c2ecf20Sopenharmony_ci#define PORTSC_LINE_STATUS_UNDEF (0x3<<10) 1048c2ecf20Sopenharmony_ci#define PORTSC_LINE_STATUS_BIT_POS (10) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* bit 15-14 are port indicator control */ 1078c2ecf20Sopenharmony_ci#define PORTSC_PIC_OFF (0x0<<14) 1088c2ecf20Sopenharmony_ci#define PORTSC_PIC_AMBER (0x1<<14) 1098c2ecf20Sopenharmony_ci#define PORTSC_PIC_GREEN (0x2<<14) 1108c2ecf20Sopenharmony_ci#define PORTSC_PIC_UNDEF (0x3<<14) 1118c2ecf20Sopenharmony_ci#define PORTSC_PIC_BIT_POS (14) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* bit 19-16 are port test control */ 1148c2ecf20Sopenharmony_ci#define PORTSC_PTC_DISABLE (0x0<<16) 1158c2ecf20Sopenharmony_ci#define PORTSC_PTC_JSTATE (0x1<<16) 1168c2ecf20Sopenharmony_ci#define PORTSC_PTC_KSTATE (0x2<<16) 1178c2ecf20Sopenharmony_ci#define PORTSC_PTC_SEQNAK (0x3<<16) 1188c2ecf20Sopenharmony_ci#define PORTSC_PTC_PACKET (0x4<<16) 1198c2ecf20Sopenharmony_ci#define PORTSC_PTC_FORCE_EN (0x5<<16) 1208c2ecf20Sopenharmony_ci#define PORTSC_PTC_BIT_POS (16) 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* bit 27-26 are port speed */ 1238c2ecf20Sopenharmony_ci#define PORTSC_PORT_SPEED_FULL (0x0<<26) 1248c2ecf20Sopenharmony_ci#define PORTSC_PORT_SPEED_LOW (0x1<<26) 1258c2ecf20Sopenharmony_ci#define PORTSC_PORT_SPEED_HIGH (0x2<<26) 1268c2ecf20Sopenharmony_ci#define PORTSC_PORT_SPEED_UNDEF (0x3<<26) 1278c2ecf20Sopenharmony_ci#define PORTSC_SPEED_BIT_POS (26) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* bit 28 is parallel transceiver width for UTMI interface */ 1308c2ecf20Sopenharmony_ci#define PORTSC_PTW (0x1<<28) 1318c2ecf20Sopenharmony_ci#define PORTSC_PTW_8BIT (0x0<<28) 1328c2ecf20Sopenharmony_ci#define PORTSC_PTW_16BIT (0x1<<28) 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci/* bit 31-30 are port transceiver select */ 1358c2ecf20Sopenharmony_ci#define PORTSC_PTS_UTMI (0x0<<30) 1368c2ecf20Sopenharmony_ci#define PORTSC_PTS_ULPI (0x2<<30) 1378c2ecf20Sopenharmony_ci#define PORTSC_PTS_FSLS_SERIAL (0x3<<30) 1388c2ecf20Sopenharmony_ci#define PORTSC_PTS_BIT_POS (30) 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#define PORTSC_W1C_BITS \ 1418c2ecf20Sopenharmony_ci (PORTSC_CONNECT_STATUS_CHANGE | \ 1428c2ecf20Sopenharmony_ci PORTSC_PORT_EN_DIS_CHANGE | \ 1438c2ecf20Sopenharmony_ci PORTSC_OVER_CUURENT_CHG) 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci/* OTG Status Control Register Bit Masks */ 1468c2ecf20Sopenharmony_ci#define OTGSC_CTRL_VBUS_DISCHARGE (0x1<<0) 1478c2ecf20Sopenharmony_ci#define OTGSC_CTRL_VBUS_CHARGE (0x1<<1) 1488c2ecf20Sopenharmony_ci#define OTGSC_CTRL_OTG_TERMINATION (0x1<<3) 1498c2ecf20Sopenharmony_ci#define OTGSC_CTRL_DATA_PULSING (0x1<<4) 1508c2ecf20Sopenharmony_ci#define OTGSC_CTRL_ID_PULL_EN (0x1<<5) 1518c2ecf20Sopenharmony_ci#define OTGSC_HA_DATA_PULSE (0x1<<6) 1528c2ecf20Sopenharmony_ci#define OTGSC_HA_BA (0x1<<7) 1538c2ecf20Sopenharmony_ci#define OTGSC_STS_USB_ID (0x1<<8) 1548c2ecf20Sopenharmony_ci#define OTGSC_STS_A_VBUS_VALID (0x1<<9) 1558c2ecf20Sopenharmony_ci#define OTGSC_STS_A_SESSION_VALID (0x1<<10) 1568c2ecf20Sopenharmony_ci#define OTGSC_STS_B_SESSION_VALID (0x1<<11) 1578c2ecf20Sopenharmony_ci#define OTGSC_STS_B_SESSION_END (0x1<<12) 1588c2ecf20Sopenharmony_ci#define OTGSC_STS_1MS_TOGGLE (0x1<<13) 1598c2ecf20Sopenharmony_ci#define OTGSC_STS_DATA_PULSING (0x1<<14) 1608c2ecf20Sopenharmony_ci#define OTGSC_INTSTS_USB_ID (0x1<<16) 1618c2ecf20Sopenharmony_ci#define OTGSC_INTSTS_A_VBUS_VALID (0x1<<17) 1628c2ecf20Sopenharmony_ci#define OTGSC_INTSTS_A_SESSION_VALID (0x1<<18) 1638c2ecf20Sopenharmony_ci#define OTGSC_INTSTS_B_SESSION_VALID (0x1<<19) 1648c2ecf20Sopenharmony_ci#define OTGSC_INTSTS_B_SESSION_END (0x1<<20) 1658c2ecf20Sopenharmony_ci#define OTGSC_INTSTS_1MS (0x1<<21) 1668c2ecf20Sopenharmony_ci#define OTGSC_INTSTS_DATA_PULSING (0x1<<22) 1678c2ecf20Sopenharmony_ci#define OTGSC_INTR_USB_ID_EN (0x1<<24) 1688c2ecf20Sopenharmony_ci#define OTGSC_INTR_A_VBUS_VALID_EN (0x1<<25) 1698c2ecf20Sopenharmony_ci#define OTGSC_INTR_A_SESSION_VALID_EN (0x1<<26) 1708c2ecf20Sopenharmony_ci#define OTGSC_INTR_B_SESSION_VALID_EN (0x1<<27) 1718c2ecf20Sopenharmony_ci#define OTGSC_INTR_B_SESSION_END_EN (0x1<<28) 1728c2ecf20Sopenharmony_ci#define OTGSC_INTR_1MS_TIMER_EN (0x1<<29) 1738c2ecf20Sopenharmony_ci#define OTGSC_INTR_DATA_PULSING_EN (0x1<<30) 1748c2ecf20Sopenharmony_ci#define OTGSC_INTSTS_MASK (0x00ff0000) 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/* USB MODE Register Bit Masks */ 1778c2ecf20Sopenharmony_ci#define USB_MODE_CTRL_MODE_IDLE (0x0<<0) 1788c2ecf20Sopenharmony_ci#define USB_MODE_CTRL_MODE_DEVICE (0x2<<0) 1798c2ecf20Sopenharmony_ci#define USB_MODE_CTRL_MODE_HOST (0x3<<0) 1808c2ecf20Sopenharmony_ci#define USB_MODE_CTRL_MODE_RSV (0x1<<0) 1818c2ecf20Sopenharmony_ci#define USB_MODE_SETUP_LOCK_OFF (0x1<<3) 1828c2ecf20Sopenharmony_ci#define USB_MODE_STREAM_DISABLE (0x1<<4) 1838c2ecf20Sopenharmony_ci#define USB_MODE_ES (0x1<<2) /* Endian Select */ 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci/* control Register Bit Masks */ 1868c2ecf20Sopenharmony_ci#define USB_CTRL_IOENB (0x1<<2) 1878c2ecf20Sopenharmony_ci#define USB_CTRL_ULPI_INT0EN (0x1<<0) 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* BCSR5 */ 1908c2ecf20Sopenharmony_ci#define BCSR5_INT_USB (0x02) 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/* USB module clk cfg */ 1938c2ecf20Sopenharmony_ci#define SCCR_OFFS (0xA08) 1948c2ecf20Sopenharmony_ci#define SCCR_USB_CLK_DISABLE (0x00000000) /* USB clk disable */ 1958c2ecf20Sopenharmony_ci#define SCCR_USB_MPHCM_11 (0x00c00000) 1968c2ecf20Sopenharmony_ci#define SCCR_USB_MPHCM_01 (0x00400000) 1978c2ecf20Sopenharmony_ci#define SCCR_USB_MPHCM_10 (0x00800000) 1988c2ecf20Sopenharmony_ci#define SCCR_USB_DRCM_11 (0x00300000) 1998c2ecf20Sopenharmony_ci#define SCCR_USB_DRCM_01 (0x00100000) 2008c2ecf20Sopenharmony_ci#define SCCR_USB_DRCM_10 (0x00200000) 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci#define SICRL_OFFS (0x114) 2038c2ecf20Sopenharmony_ci#define SICRL_USB0 (0x40000000) 2048c2ecf20Sopenharmony_ci#define SICRL_USB1 (0x20000000) 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci#define SICRH_OFFS (0x118) 2078c2ecf20Sopenharmony_ci#define SICRH_USB_UTMI (0x00020000) 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci/* OTG interrupt enable bit masks */ 2108c2ecf20Sopenharmony_ci#define OTGSC_INTERRUPT_ENABLE_BITS_MASK \ 2118c2ecf20Sopenharmony_ci (OTGSC_INTR_USB_ID_EN | \ 2128c2ecf20Sopenharmony_ci OTGSC_INTR_1MS_TIMER_EN | \ 2138c2ecf20Sopenharmony_ci OTGSC_INTR_A_VBUS_VALID_EN | \ 2148c2ecf20Sopenharmony_ci OTGSC_INTR_A_SESSION_VALID_EN | \ 2158c2ecf20Sopenharmony_ci OTGSC_INTR_B_SESSION_VALID_EN | \ 2168c2ecf20Sopenharmony_ci OTGSC_INTR_B_SESSION_END_EN | \ 2178c2ecf20Sopenharmony_ci OTGSC_INTR_DATA_PULSING_EN) 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci/* OTG interrupt status bit masks */ 2208c2ecf20Sopenharmony_ci#define OTGSC_INTERRUPT_STATUS_BITS_MASK \ 2218c2ecf20Sopenharmony_ci (OTGSC_INTSTS_USB_ID | \ 2228c2ecf20Sopenharmony_ci OTGSC_INTR_1MS_TIMER_EN | \ 2238c2ecf20Sopenharmony_ci OTGSC_INTSTS_A_VBUS_VALID | \ 2248c2ecf20Sopenharmony_ci OTGSC_INTSTS_A_SESSION_VALID | \ 2258c2ecf20Sopenharmony_ci OTGSC_INTSTS_B_SESSION_VALID | \ 2268c2ecf20Sopenharmony_ci OTGSC_INTSTS_B_SESSION_END | \ 2278c2ecf20Sopenharmony_ci OTGSC_INTSTS_DATA_PULSING) 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci/* 2308c2ecf20Sopenharmony_ci * A-DEVICE timing constants 2318c2ecf20Sopenharmony_ci */ 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci/* Wait for VBUS Rise */ 2348c2ecf20Sopenharmony_ci#define TA_WAIT_VRISE (100) /* a_wait_vrise 100 ms, section: 6.6.5.1 */ 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci/* Wait for B-Connect */ 2378c2ecf20Sopenharmony_ci#define TA_WAIT_BCON (10000) /* a_wait_bcon > 1 sec, section: 6.6.5.2 2388c2ecf20Sopenharmony_ci * This is only used to get out of 2398c2ecf20Sopenharmony_ci * OTG_STATE_A_WAIT_BCON state if there was 2408c2ecf20Sopenharmony_ci * no connection for these many milliseconds 2418c2ecf20Sopenharmony_ci */ 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci/* A-Idle to B-Disconnect */ 2448c2ecf20Sopenharmony_ci/* It is necessary for this timer to be more than 750 ms because of a bug in OPT 2458c2ecf20Sopenharmony_ci * test 5.4 in which B OPT disconnects after 750 ms instead of 75ms as stated 2468c2ecf20Sopenharmony_ci * in the test description 2478c2ecf20Sopenharmony_ci */ 2488c2ecf20Sopenharmony_ci#define TA_AIDL_BDIS (5000) /* a_suspend minimum 200 ms, section: 6.6.5.3 */ 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci/* B-Idle to A-Disconnect */ 2518c2ecf20Sopenharmony_ci#define TA_BIDL_ADIS (12) /* 3 to 200 ms */ 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci/* B-device timing constants */ 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci/* Data-Line Pulse Time*/ 2578c2ecf20Sopenharmony_ci#define TB_DATA_PLS (10) /* b_srp_init,continue 5~10ms, section:5.3.3 */ 2588c2ecf20Sopenharmony_ci#define TB_DATA_PLS_MIN (5) /* minimum 5 ms */ 2598c2ecf20Sopenharmony_ci#define TB_DATA_PLS_MAX (10) /* maximum 10 ms */ 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci/* SRP Initiate Time */ 2628c2ecf20Sopenharmony_ci#define TB_SRP_INIT (100) /* b_srp_init,maximum 100 ms, section:5.3.8 */ 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci/* SRP Fail Time */ 2658c2ecf20Sopenharmony_ci#define TB_SRP_FAIL (7000) /* b_srp_init,Fail time 5~30s, section:6.8.2.2*/ 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci/* SRP result wait time */ 2688c2ecf20Sopenharmony_ci#define TB_SRP_WAIT (60) 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci/* VBus time */ 2718c2ecf20Sopenharmony_ci#define TB_VBUS_PLS (30) /* time to keep vbus pulsing asserted */ 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci/* Discharge time */ 2748c2ecf20Sopenharmony_ci/* This time should be less than 10ms. It varies from system to system. */ 2758c2ecf20Sopenharmony_ci#define TB_VBUS_DSCHRG (8) 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci/* A-SE0 to B-Reset */ 2788c2ecf20Sopenharmony_ci#define TB_ASE0_BRST (20) /* b_wait_acon, mini 3.125 ms,section:6.8.2.4 */ 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci/* A bus suspend timer before we can switch to b_wait_aconn */ 2818c2ecf20Sopenharmony_ci#define TB_A_SUSPEND (7) 2828c2ecf20Sopenharmony_ci#define TB_BUS_RESUME (12) 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci/* SE0 Time Before SRP */ 2858c2ecf20Sopenharmony_ci#define TB_SE0_SRP (2) /* b_idle,minimum 2 ms, section:5.3.2 */ 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci#define SET_OTG_STATE(phy, newstate) ((phy)->otg->state = newstate) 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_cistruct usb_dr_mmap { 2908c2ecf20Sopenharmony_ci /* Capability register */ 2918c2ecf20Sopenharmony_ci u8 res1[256]; 2928c2ecf20Sopenharmony_ci u16 caplength; /* Capability Register Length */ 2938c2ecf20Sopenharmony_ci u16 hciversion; /* Host Controller Interface Version */ 2948c2ecf20Sopenharmony_ci u32 hcsparams; /* Host Controller Structual Parameters */ 2958c2ecf20Sopenharmony_ci u32 hccparams; /* Host Controller Capability Parameters */ 2968c2ecf20Sopenharmony_ci u8 res2[20]; 2978c2ecf20Sopenharmony_ci u32 dciversion; /* Device Controller Interface Version */ 2988c2ecf20Sopenharmony_ci u32 dccparams; /* Device Controller Capability Parameters */ 2998c2ecf20Sopenharmony_ci u8 res3[24]; 3008c2ecf20Sopenharmony_ci /* Operation register */ 3018c2ecf20Sopenharmony_ci u32 usbcmd; /* USB Command Register */ 3028c2ecf20Sopenharmony_ci u32 usbsts; /* USB Status Register */ 3038c2ecf20Sopenharmony_ci u32 usbintr; /* USB Interrupt Enable Register */ 3048c2ecf20Sopenharmony_ci u32 frindex; /* Frame Index Register */ 3058c2ecf20Sopenharmony_ci u8 res4[4]; 3068c2ecf20Sopenharmony_ci u32 deviceaddr; /* Device Address */ 3078c2ecf20Sopenharmony_ci u32 endpointlistaddr; /* Endpoint List Address Register */ 3088c2ecf20Sopenharmony_ci u8 res5[4]; 3098c2ecf20Sopenharmony_ci u32 burstsize; /* Master Interface Data Burst Size Register */ 3108c2ecf20Sopenharmony_ci u32 txttfilltuning; /* Transmit FIFO Tuning Controls Register */ 3118c2ecf20Sopenharmony_ci u8 res6[8]; 3128c2ecf20Sopenharmony_ci u32 ulpiview; /* ULPI register access */ 3138c2ecf20Sopenharmony_ci u8 res7[12]; 3148c2ecf20Sopenharmony_ci u32 configflag; /* Configure Flag Register */ 3158c2ecf20Sopenharmony_ci u32 portsc; /* Port 1 Status and Control Register */ 3168c2ecf20Sopenharmony_ci u8 res8[28]; 3178c2ecf20Sopenharmony_ci u32 otgsc; /* On-The-Go Status and Control */ 3188c2ecf20Sopenharmony_ci u32 usbmode; /* USB Mode Register */ 3198c2ecf20Sopenharmony_ci u32 endptsetupstat; /* Endpoint Setup Status Register */ 3208c2ecf20Sopenharmony_ci u32 endpointprime; /* Endpoint Initialization Register */ 3218c2ecf20Sopenharmony_ci u32 endptflush; /* Endpoint Flush Register */ 3228c2ecf20Sopenharmony_ci u32 endptstatus; /* Endpoint Status Register */ 3238c2ecf20Sopenharmony_ci u32 endptcomplete; /* Endpoint Complete Register */ 3248c2ecf20Sopenharmony_ci u32 endptctrl[6]; /* Endpoint Control Registers */ 3258c2ecf20Sopenharmony_ci u8 res9[552]; 3268c2ecf20Sopenharmony_ci u32 snoop1; 3278c2ecf20Sopenharmony_ci u32 snoop2; 3288c2ecf20Sopenharmony_ci u32 age_cnt_thresh; /* Age Count Threshold Register */ 3298c2ecf20Sopenharmony_ci u32 pri_ctrl; /* Priority Control Register */ 3308c2ecf20Sopenharmony_ci u32 si_ctrl; /* System Interface Control Register */ 3318c2ecf20Sopenharmony_ci u8 res10[236]; 3328c2ecf20Sopenharmony_ci u32 control; /* General Purpose Control Register */ 3338c2ecf20Sopenharmony_ci}; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_cistruct fsl_otg_timer { 3368c2ecf20Sopenharmony_ci unsigned long expires; /* Number of count increase to timeout */ 3378c2ecf20Sopenharmony_ci unsigned long count; /* Tick counter */ 3388c2ecf20Sopenharmony_ci void (*function)(unsigned long); /* Timeout function */ 3398c2ecf20Sopenharmony_ci unsigned long data; /* Data passed to function */ 3408c2ecf20Sopenharmony_ci struct list_head list; 3418c2ecf20Sopenharmony_ci}; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ciinline struct fsl_otg_timer *otg_timer_initializer 3448c2ecf20Sopenharmony_ci(void (*function)(unsigned long), unsigned long expires, unsigned long data) 3458c2ecf20Sopenharmony_ci{ 3468c2ecf20Sopenharmony_ci struct fsl_otg_timer *timer; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci timer = kmalloc(sizeof(struct fsl_otg_timer), GFP_KERNEL); 3498c2ecf20Sopenharmony_ci if (!timer) 3508c2ecf20Sopenharmony_ci return NULL; 3518c2ecf20Sopenharmony_ci timer->function = function; 3528c2ecf20Sopenharmony_ci timer->expires = expires; 3538c2ecf20Sopenharmony_ci timer->data = data; 3548c2ecf20Sopenharmony_ci return timer; 3558c2ecf20Sopenharmony_ci} 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_cistruct fsl_otg { 3588c2ecf20Sopenharmony_ci struct usb_phy phy; 3598c2ecf20Sopenharmony_ci struct otg_fsm fsm; 3608c2ecf20Sopenharmony_ci struct usb_dr_mmap *dr_mem_map; 3618c2ecf20Sopenharmony_ci struct delayed_work otg_event; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci /* used for usb host */ 3648c2ecf20Sopenharmony_ci struct work_struct work_wq; 3658c2ecf20Sopenharmony_ci u8 host_working; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci int irq; 3688c2ecf20Sopenharmony_ci}; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_cistruct fsl_otg_config { 3718c2ecf20Sopenharmony_ci u8 otg_port; 3728c2ecf20Sopenharmony_ci}; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci#define FSL_OTG_NAME "fsl-usb2-otg" 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_civoid fsl_otg_add_timer(struct otg_fsm *fsm, void *timer); 3778c2ecf20Sopenharmony_civoid fsl_otg_del_timer(struct otg_fsm *fsm, void *timer); 3788c2ecf20Sopenharmony_civoid fsl_otg_pulse_vbus(void); 379