18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * USBSS device controller driver header file 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2018-2019 Cadence. 68c2ecf20Sopenharmony_ci * Copyright (C) 2017-2018 NXP 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Author: Pawel Laszczak <pawell@cadence.com> 98c2ecf20Sopenharmony_ci * Pawel Jez <pjez@cadence.com> 108c2ecf20Sopenharmony_ci * Peter Chen <peter.chen@nxp.com> 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci#ifndef __LINUX_CDNS3_GADGET 138c2ecf20Sopenharmony_ci#define __LINUX_CDNS3_GADGET 148c2ecf20Sopenharmony_ci#include <linux/usb/gadget.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* 178c2ecf20Sopenharmony_ci * USBSS-DEV register interface. 188c2ecf20Sopenharmony_ci * This corresponds to the USBSS Device Controller Interface 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/** 228c2ecf20Sopenharmony_ci * struct cdns3_usb_regs - device controller registers. 238c2ecf20Sopenharmony_ci * @usb_conf: Global Configuration. 248c2ecf20Sopenharmony_ci * @usb_sts: Global Status. 258c2ecf20Sopenharmony_ci * @usb_cmd: Global Command. 268c2ecf20Sopenharmony_ci * @usb_itpn: ITP/SOF number. 278c2ecf20Sopenharmony_ci * @usb_lpm: Global Command. 288c2ecf20Sopenharmony_ci * @usb_ien: USB Interrupt Enable. 298c2ecf20Sopenharmony_ci * @usb_ists: USB Interrupt Status. 308c2ecf20Sopenharmony_ci * @ep_sel: Endpoint Select. 318c2ecf20Sopenharmony_ci * @ep_traddr: Endpoint Transfer Ring Address. 328c2ecf20Sopenharmony_ci * @ep_cfg: Endpoint Configuration. 338c2ecf20Sopenharmony_ci * @ep_cmd: Endpoint Command. 348c2ecf20Sopenharmony_ci * @ep_sts: Endpoint Status. 358c2ecf20Sopenharmony_ci * @ep_sts_sid: Endpoint Status. 368c2ecf20Sopenharmony_ci * @ep_sts_en: Endpoint Status Enable. 378c2ecf20Sopenharmony_ci * @drbl: Doorbell. 388c2ecf20Sopenharmony_ci * @ep_ien: EP Interrupt Enable. 398c2ecf20Sopenharmony_ci * @ep_ists: EP Interrupt Status. 408c2ecf20Sopenharmony_ci * @usb_pwr: Global Power Configuration. 418c2ecf20Sopenharmony_ci * @usb_conf2: Global Configuration 2. 428c2ecf20Sopenharmony_ci * @usb_cap1: Capability 1. 438c2ecf20Sopenharmony_ci * @usb_cap2: Capability 2. 448c2ecf20Sopenharmony_ci * @usb_cap3: Capability 3. 458c2ecf20Sopenharmony_ci * @usb_cap4: Capability 4. 468c2ecf20Sopenharmony_ci * @usb_cap5: Capability 5. 478c2ecf20Sopenharmony_ci * @usb_cap6: Capability 6. 488c2ecf20Sopenharmony_ci * @usb_cpkt1: Custom Packet 1. 498c2ecf20Sopenharmony_ci * @usb_cpkt2: Custom Packet 2. 508c2ecf20Sopenharmony_ci * @usb_cpkt3: Custom Packet 3. 518c2ecf20Sopenharmony_ci * @ep_dma_ext_addr: Upper address for DMA operations. 528c2ecf20Sopenharmony_ci * @buf_addr: Address for On-chip Buffer operations. 538c2ecf20Sopenharmony_ci * @buf_data: Data for On-chip Buffer operations. 548c2ecf20Sopenharmony_ci * @buf_ctrl: On-chip Buffer Access Control. 558c2ecf20Sopenharmony_ci * @dtrans: DMA Transfer Mode. 568c2ecf20Sopenharmony_ci * @tdl_from_trb: Source of TD Configuration. 578c2ecf20Sopenharmony_ci * @tdl_beh: TDL Behavior Configuration. 588c2ecf20Sopenharmony_ci * @ep_tdl: Endpoint TDL. 598c2ecf20Sopenharmony_ci * @tdl_beh2: TDL Behavior 2 Configuration. 608c2ecf20Sopenharmony_ci * @dma_adv_td: DMA Advance TD Configuration. 618c2ecf20Sopenharmony_ci * @reserved1: Reserved. 628c2ecf20Sopenharmony_ci * @cfg_regs: Configuration. 638c2ecf20Sopenharmony_ci * @reserved2: Reserved. 648c2ecf20Sopenharmony_ci * @dma_axi_ctrl: AXI Control. 658c2ecf20Sopenharmony_ci * @dma_axi_id: AXI ID register. 668c2ecf20Sopenharmony_ci * @dma_axi_cap: AXI Capability. 678c2ecf20Sopenharmony_ci * @dma_axi_ctrl0: AXI Control 0. 688c2ecf20Sopenharmony_ci * @dma_axi_ctrl1: AXI Control 1. 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_cistruct cdns3_usb_regs { 718c2ecf20Sopenharmony_ci __le32 usb_conf; 728c2ecf20Sopenharmony_ci __le32 usb_sts; 738c2ecf20Sopenharmony_ci __le32 usb_cmd; 748c2ecf20Sopenharmony_ci __le32 usb_itpn; 758c2ecf20Sopenharmony_ci __le32 usb_lpm; 768c2ecf20Sopenharmony_ci __le32 usb_ien; 778c2ecf20Sopenharmony_ci __le32 usb_ists; 788c2ecf20Sopenharmony_ci __le32 ep_sel; 798c2ecf20Sopenharmony_ci __le32 ep_traddr; 808c2ecf20Sopenharmony_ci __le32 ep_cfg; 818c2ecf20Sopenharmony_ci __le32 ep_cmd; 828c2ecf20Sopenharmony_ci __le32 ep_sts; 838c2ecf20Sopenharmony_ci __le32 ep_sts_sid; 848c2ecf20Sopenharmony_ci __le32 ep_sts_en; 858c2ecf20Sopenharmony_ci __le32 drbl; 868c2ecf20Sopenharmony_ci __le32 ep_ien; 878c2ecf20Sopenharmony_ci __le32 ep_ists; 888c2ecf20Sopenharmony_ci __le32 usb_pwr; 898c2ecf20Sopenharmony_ci __le32 usb_conf2; 908c2ecf20Sopenharmony_ci __le32 usb_cap1; 918c2ecf20Sopenharmony_ci __le32 usb_cap2; 928c2ecf20Sopenharmony_ci __le32 usb_cap3; 938c2ecf20Sopenharmony_ci __le32 usb_cap4; 948c2ecf20Sopenharmony_ci __le32 usb_cap5; 958c2ecf20Sopenharmony_ci __le32 usb_cap6; 968c2ecf20Sopenharmony_ci __le32 usb_cpkt1; 978c2ecf20Sopenharmony_ci __le32 usb_cpkt2; 988c2ecf20Sopenharmony_ci __le32 usb_cpkt3; 998c2ecf20Sopenharmony_ci __le32 ep_dma_ext_addr; 1008c2ecf20Sopenharmony_ci __le32 buf_addr; 1018c2ecf20Sopenharmony_ci __le32 buf_data; 1028c2ecf20Sopenharmony_ci __le32 buf_ctrl; 1038c2ecf20Sopenharmony_ci __le32 dtrans; 1048c2ecf20Sopenharmony_ci __le32 tdl_from_trb; 1058c2ecf20Sopenharmony_ci __le32 tdl_beh; 1068c2ecf20Sopenharmony_ci __le32 ep_tdl; 1078c2ecf20Sopenharmony_ci __le32 tdl_beh2; 1088c2ecf20Sopenharmony_ci __le32 dma_adv_td; 1098c2ecf20Sopenharmony_ci __le32 reserved1[26]; 1108c2ecf20Sopenharmony_ci __le32 cfg_reg1; 1118c2ecf20Sopenharmony_ci __le32 dbg_link1; 1128c2ecf20Sopenharmony_ci __le32 dbg_link2; 1138c2ecf20Sopenharmony_ci __le32 cfg_regs[74]; 1148c2ecf20Sopenharmony_ci __le32 reserved2[51]; 1158c2ecf20Sopenharmony_ci __le32 dma_axi_ctrl; 1168c2ecf20Sopenharmony_ci __le32 dma_axi_id; 1178c2ecf20Sopenharmony_ci __le32 dma_axi_cap; 1188c2ecf20Sopenharmony_ci __le32 dma_axi_ctrl0; 1198c2ecf20Sopenharmony_ci __le32 dma_axi_ctrl1; 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* USB_CONF - bitmasks */ 1238c2ecf20Sopenharmony_ci/* Reset USB device configuration. */ 1248c2ecf20Sopenharmony_ci#define USB_CONF_CFGRST BIT(0) 1258c2ecf20Sopenharmony_ci/* Set Configuration. */ 1268c2ecf20Sopenharmony_ci#define USB_CONF_CFGSET BIT(1) 1278c2ecf20Sopenharmony_ci/* Disconnect USB device in SuperSpeed. */ 1288c2ecf20Sopenharmony_ci#define USB_CONF_USB3DIS BIT(3) 1298c2ecf20Sopenharmony_ci/* Disconnect USB device in HS/FS */ 1308c2ecf20Sopenharmony_ci#define USB_CONF_USB2DIS BIT(4) 1318c2ecf20Sopenharmony_ci/* Little Endian access - default */ 1328c2ecf20Sopenharmony_ci#define USB_CONF_LENDIAN BIT(5) 1338c2ecf20Sopenharmony_ci/* 1348c2ecf20Sopenharmony_ci * Big Endian access. Driver assume that byte order for 1358c2ecf20Sopenharmony_ci * SFRs access always is as Little Endian so this bit 1368c2ecf20Sopenharmony_ci * is not used. 1378c2ecf20Sopenharmony_ci */ 1388c2ecf20Sopenharmony_ci#define USB_CONF_BENDIAN BIT(6) 1398c2ecf20Sopenharmony_ci/* Device software reset. */ 1408c2ecf20Sopenharmony_ci#define USB_CONF_SWRST BIT(7) 1418c2ecf20Sopenharmony_ci/* Singular DMA transfer mode. Only for VER < DEV_VER_V3*/ 1428c2ecf20Sopenharmony_ci#define USB_CONF_DSING BIT(8) 1438c2ecf20Sopenharmony_ci/* Multiple DMA transfers mode. Only for VER < DEV_VER_V3 */ 1448c2ecf20Sopenharmony_ci#define USB_CONF_DMULT BIT(9) 1458c2ecf20Sopenharmony_ci/* DMA clock turn-off enable. */ 1468c2ecf20Sopenharmony_ci#define USB_CONF_DMAOFFEN BIT(10) 1478c2ecf20Sopenharmony_ci/* DMA clock turn-off disable. */ 1488c2ecf20Sopenharmony_ci#define USB_CONF_DMAOFFDS BIT(11) 1498c2ecf20Sopenharmony_ci/* Clear Force Full Speed. */ 1508c2ecf20Sopenharmony_ci#define USB_CONF_CFORCE_FS BIT(12) 1518c2ecf20Sopenharmony_ci/* Set Force Full Speed. */ 1528c2ecf20Sopenharmony_ci#define USB_CONF_SFORCE_FS BIT(13) 1538c2ecf20Sopenharmony_ci/* Device enable. */ 1548c2ecf20Sopenharmony_ci#define USB_CONF_DEVEN BIT(14) 1558c2ecf20Sopenharmony_ci/* Device disable. */ 1568c2ecf20Sopenharmony_ci#define USB_CONF_DEVDS BIT(15) 1578c2ecf20Sopenharmony_ci/* L1 LPM state entry enable (used in HS/FS mode). */ 1588c2ecf20Sopenharmony_ci#define USB_CONF_L1EN BIT(16) 1598c2ecf20Sopenharmony_ci/* L1 LPM state entry disable (used in HS/FS mode). */ 1608c2ecf20Sopenharmony_ci#define USB_CONF_L1DS BIT(17) 1618c2ecf20Sopenharmony_ci/* USB 2.0 clock gate disable. */ 1628c2ecf20Sopenharmony_ci#define USB_CONF_CLK2OFFEN BIT(18) 1638c2ecf20Sopenharmony_ci/* USB 2.0 clock gate enable. */ 1648c2ecf20Sopenharmony_ci#define USB_CONF_CLK2OFFDS BIT(19) 1658c2ecf20Sopenharmony_ci/* L0 LPM state entry request (used in HS/FS mode). */ 1668c2ecf20Sopenharmony_ci#define USB_CONF_LGO_L0 BIT(20) 1678c2ecf20Sopenharmony_ci/* USB 3.0 clock gate disable. */ 1688c2ecf20Sopenharmony_ci#define USB_CONF_CLK3OFFEN BIT(21) 1698c2ecf20Sopenharmony_ci/* USB 3.0 clock gate enable. */ 1708c2ecf20Sopenharmony_ci#define USB_CONF_CLK3OFFDS BIT(22) 1718c2ecf20Sopenharmony_ci/* Bit 23 is reserved*/ 1728c2ecf20Sopenharmony_ci/* U1 state entry enable (used in SS mode). */ 1738c2ecf20Sopenharmony_ci#define USB_CONF_U1EN BIT(24) 1748c2ecf20Sopenharmony_ci/* U1 state entry disable (used in SS mode). */ 1758c2ecf20Sopenharmony_ci#define USB_CONF_U1DS BIT(25) 1768c2ecf20Sopenharmony_ci/* U2 state entry enable (used in SS mode). */ 1778c2ecf20Sopenharmony_ci#define USB_CONF_U2EN BIT(26) 1788c2ecf20Sopenharmony_ci/* U2 state entry disable (used in SS mode). */ 1798c2ecf20Sopenharmony_ci#define USB_CONF_U2DS BIT(27) 1808c2ecf20Sopenharmony_ci/* U0 state entry request (used in SS mode). */ 1818c2ecf20Sopenharmony_ci#define USB_CONF_LGO_U0 BIT(28) 1828c2ecf20Sopenharmony_ci/* U1 state entry request (used in SS mode). */ 1838c2ecf20Sopenharmony_ci#define USB_CONF_LGO_U1 BIT(29) 1848c2ecf20Sopenharmony_ci/* U2 state entry request (used in SS mode). */ 1858c2ecf20Sopenharmony_ci#define USB_CONF_LGO_U2 BIT(30) 1868c2ecf20Sopenharmony_ci/* SS.Inactive state entry request (used in SS mode) */ 1878c2ecf20Sopenharmony_ci#define USB_CONF_LGO_SSINACT BIT(31) 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* USB_STS - bitmasks */ 1908c2ecf20Sopenharmony_ci/* 1918c2ecf20Sopenharmony_ci * Configuration status. 1928c2ecf20Sopenharmony_ci * 1 - device is in the configured state. 1938c2ecf20Sopenharmony_ci * 0 - device is not configured. 1948c2ecf20Sopenharmony_ci */ 1958c2ecf20Sopenharmony_ci#define USB_STS_CFGSTS_MASK BIT(0) 1968c2ecf20Sopenharmony_ci#define USB_STS_CFGSTS(p) ((p) & USB_STS_CFGSTS_MASK) 1978c2ecf20Sopenharmony_ci/* 1988c2ecf20Sopenharmony_ci * On-chip memory overflow. 1998c2ecf20Sopenharmony_ci * 0 - On-chip memory status OK. 2008c2ecf20Sopenharmony_ci * 1 - On-chip memory overflow. 2018c2ecf20Sopenharmony_ci */ 2028c2ecf20Sopenharmony_ci#define USB_STS_OV_MASK BIT(1) 2038c2ecf20Sopenharmony_ci#define USB_STS_OV(p) ((p) & USB_STS_OV_MASK) 2048c2ecf20Sopenharmony_ci/* 2058c2ecf20Sopenharmony_ci * SuperSpeed connection status. 2068c2ecf20Sopenharmony_ci * 0 - USB in SuperSpeed mode disconnected. 2078c2ecf20Sopenharmony_ci * 1 - USB in SuperSpeed mode connected. 2088c2ecf20Sopenharmony_ci */ 2098c2ecf20Sopenharmony_ci#define USB_STS_USB3CONS_MASK BIT(2) 2108c2ecf20Sopenharmony_ci#define USB_STS_USB3CONS(p) ((p) & USB_STS_USB3CONS_MASK) 2118c2ecf20Sopenharmony_ci/* 2128c2ecf20Sopenharmony_ci * DMA transfer configuration status. 2138c2ecf20Sopenharmony_ci * 0 - single request. 2148c2ecf20Sopenharmony_ci * 1 - multiple TRB chain 2158c2ecf20Sopenharmony_ci * Supported only for controller version < DEV_VER_V3 2168c2ecf20Sopenharmony_ci */ 2178c2ecf20Sopenharmony_ci#define USB_STS_DTRANS_MASK BIT(3) 2188c2ecf20Sopenharmony_ci#define USB_STS_DTRANS(p) ((p) & USB_STS_DTRANS_MASK) 2198c2ecf20Sopenharmony_ci/* 2208c2ecf20Sopenharmony_ci * Device speed. 2218c2ecf20Sopenharmony_ci * 0 - Undefined (value after reset). 2228c2ecf20Sopenharmony_ci * 1 - Low speed 2238c2ecf20Sopenharmony_ci * 2 - Full speed 2248c2ecf20Sopenharmony_ci * 3 - High speed 2258c2ecf20Sopenharmony_ci * 4 - Super speed 2268c2ecf20Sopenharmony_ci */ 2278c2ecf20Sopenharmony_ci#define USB_STS_USBSPEED_MASK GENMASK(6, 4) 2288c2ecf20Sopenharmony_ci#define USB_STS_USBSPEED(p) (((p) & USB_STS_USBSPEED_MASK) >> 4) 2298c2ecf20Sopenharmony_ci#define USB_STS_LS (0x1 << 4) 2308c2ecf20Sopenharmony_ci#define USB_STS_FS (0x2 << 4) 2318c2ecf20Sopenharmony_ci#define USB_STS_HS (0x3 << 4) 2328c2ecf20Sopenharmony_ci#define USB_STS_SS (0x4 << 4) 2338c2ecf20Sopenharmony_ci#define DEV_UNDEFSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == (0x0 << 4)) 2348c2ecf20Sopenharmony_ci#define DEV_LOWSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_LS) 2358c2ecf20Sopenharmony_ci#define DEV_FULLSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_FS) 2368c2ecf20Sopenharmony_ci#define DEV_HIGHSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_HS) 2378c2ecf20Sopenharmony_ci#define DEV_SUPERSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_SS) 2388c2ecf20Sopenharmony_ci/* 2398c2ecf20Sopenharmony_ci * Endianness for SFR access. 2408c2ecf20Sopenharmony_ci * 0 - Little Endian order (default after hardware reset). 2418c2ecf20Sopenharmony_ci * 1 - Big Endian order 2428c2ecf20Sopenharmony_ci */ 2438c2ecf20Sopenharmony_ci#define USB_STS_ENDIAN_MASK BIT(7) 2448c2ecf20Sopenharmony_ci#define USB_STS_ENDIAN(p) ((p) & USB_STS_ENDIAN_MASK) 2458c2ecf20Sopenharmony_ci/* 2468c2ecf20Sopenharmony_ci * HS/FS clock turn-off status. 2478c2ecf20Sopenharmony_ci * 0 - hsfs clock is always on. 2488c2ecf20Sopenharmony_ci * 1 - hsfs clock turn-off in L2 (HS/FS mode) is enabled 2498c2ecf20Sopenharmony_ci * (default after hardware reset). 2508c2ecf20Sopenharmony_ci */ 2518c2ecf20Sopenharmony_ci#define USB_STS_CLK2OFF_MASK BIT(8) 2528c2ecf20Sopenharmony_ci#define USB_STS_CLK2OFF(p) ((p) & USB_STS_CLK2OFF_MASK) 2538c2ecf20Sopenharmony_ci/* 2548c2ecf20Sopenharmony_ci * PCLK clock turn-off status. 2558c2ecf20Sopenharmony_ci * 0 - pclk clock is always on. 2568c2ecf20Sopenharmony_ci * 1 - pclk clock turn-off in U3 (SS mode) is enabled 2578c2ecf20Sopenharmony_ci * (default after hardware reset). 2588c2ecf20Sopenharmony_ci */ 2598c2ecf20Sopenharmony_ci#define USB_STS_CLK3OFF_MASK BIT(9) 2608c2ecf20Sopenharmony_ci#define USB_STS_CLK3OFF(p) ((p) & USB_STS_CLK3OFF_MASK) 2618c2ecf20Sopenharmony_ci/* 2628c2ecf20Sopenharmony_ci * Controller in reset state. 2638c2ecf20Sopenharmony_ci * 0 - Internal reset is active. 2648c2ecf20Sopenharmony_ci * 1 - Internal reset is not active and controller is fully operational. 2658c2ecf20Sopenharmony_ci */ 2668c2ecf20Sopenharmony_ci#define USB_STS_IN_RST_MASK BIT(10) 2678c2ecf20Sopenharmony_ci#define USB_STS_IN_RST(p) ((p) & USB_STS_IN_RST_MASK) 2688c2ecf20Sopenharmony_ci/* 2698c2ecf20Sopenharmony_ci * Status of the "TDL calculation basing on TRB" feature. 2708c2ecf20Sopenharmony_ci * 0 - disabled 2718c2ecf20Sopenharmony_ci * 1 - enabled 2728c2ecf20Sopenharmony_ci * Supported only for DEV_VER_V2 controller version. 2738c2ecf20Sopenharmony_ci */ 2748c2ecf20Sopenharmony_ci#define USB_STS_TDL_TRB_ENABLED BIT(11) 2758c2ecf20Sopenharmony_ci/* 2768c2ecf20Sopenharmony_ci * Device enable Status. 2778c2ecf20Sopenharmony_ci * 0 - USB device is disabled (VBUS input is disconnected from internal logic). 2788c2ecf20Sopenharmony_ci * 1 - USB device is enabled (VBUS input is connected to the internal logic). 2798c2ecf20Sopenharmony_ci */ 2808c2ecf20Sopenharmony_ci#define USB_STS_DEVS_MASK BIT(14) 2818c2ecf20Sopenharmony_ci#define USB_STS_DEVS(p) ((p) & USB_STS_DEVS_MASK) 2828c2ecf20Sopenharmony_ci/* 2838c2ecf20Sopenharmony_ci * Address status. 2848c2ecf20Sopenharmony_ci * 0 - USB device is default state. 2858c2ecf20Sopenharmony_ci * 1 - USB device is at least in address state. 2868c2ecf20Sopenharmony_ci */ 2878c2ecf20Sopenharmony_ci#define USB_STS_ADDRESSED_MASK BIT(15) 2888c2ecf20Sopenharmony_ci#define USB_STS_ADDRESSED(p) ((p) & USB_STS_ADDRESSED_MASK) 2898c2ecf20Sopenharmony_ci/* 2908c2ecf20Sopenharmony_ci * L1 LPM state enable status (used in HS/FS mode). 2918c2ecf20Sopenharmony_ci * 0 - Entering to L1 LPM state disabled. 2928c2ecf20Sopenharmony_ci * 1 - Entering to L1 LPM state enabled. 2938c2ecf20Sopenharmony_ci */ 2948c2ecf20Sopenharmony_ci#define USB_STS_L1ENS_MASK BIT(16) 2958c2ecf20Sopenharmony_ci#define USB_STS_L1ENS(p) ((p) & USB_STS_L1ENS_MASK) 2968c2ecf20Sopenharmony_ci/* 2978c2ecf20Sopenharmony_ci * Internal VBUS connection status (used both in HS/FS and SS mode). 2988c2ecf20Sopenharmony_ci * 0 - internal VBUS is not detected. 2998c2ecf20Sopenharmony_ci * 1 - internal VBUS is detected. 3008c2ecf20Sopenharmony_ci */ 3018c2ecf20Sopenharmony_ci#define USB_STS_VBUSS_MASK BIT(17) 3028c2ecf20Sopenharmony_ci#define USB_STS_VBUSS(p) ((p) & USB_STS_VBUSS_MASK) 3038c2ecf20Sopenharmony_ci/* 3048c2ecf20Sopenharmony_ci * HS/FS LPM state (used in FS/HS mode). 3058c2ecf20Sopenharmony_ci * 0 - L0 State 3068c2ecf20Sopenharmony_ci * 1 - L1 State 3078c2ecf20Sopenharmony_ci * 2 - L2 State 3088c2ecf20Sopenharmony_ci * 3 - L3 State 3098c2ecf20Sopenharmony_ci */ 3108c2ecf20Sopenharmony_ci#define USB_STS_LPMST_MASK GENMASK(19, 18) 3118c2ecf20Sopenharmony_ci#define DEV_L0_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x0 << 18)) 3128c2ecf20Sopenharmony_ci#define DEV_L1_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x1 << 18)) 3138c2ecf20Sopenharmony_ci#define DEV_L2_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x2 << 18)) 3148c2ecf20Sopenharmony_ci#define DEV_L3_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x3 << 18)) 3158c2ecf20Sopenharmony_ci/* 3168c2ecf20Sopenharmony_ci * Disable HS status (used in FS/HS mode). 3178c2ecf20Sopenharmony_ci * 0 - the disconnect bit for HS/FS mode is set . 3188c2ecf20Sopenharmony_ci * 1 - the disconnect bit for HS/FS mode is not set. 3198c2ecf20Sopenharmony_ci */ 3208c2ecf20Sopenharmony_ci#define USB_STS_USB2CONS_MASK BIT(20) 3218c2ecf20Sopenharmony_ci#define USB_STS_USB2CONS(p) ((p) & USB_STS_USB2CONS_MASK) 3228c2ecf20Sopenharmony_ci/* 3238c2ecf20Sopenharmony_ci * HS/FS mode connection status (used in FS/HS mode). 3248c2ecf20Sopenharmony_ci * 0 - High Speed operations in USB2.0 (FS/HS) mode not disabled. 3258c2ecf20Sopenharmony_ci * 1 - High Speed operations in USB2.0 (FS/HS). 3268c2ecf20Sopenharmony_ci */ 3278c2ecf20Sopenharmony_ci#define USB_STS_DISABLE_HS_MASK BIT(21) 3288c2ecf20Sopenharmony_ci#define USB_STS_DISABLE_HS(p) ((p) & USB_STS_DISABLE_HS_MASK) 3298c2ecf20Sopenharmony_ci/* 3308c2ecf20Sopenharmony_ci * U1 state enable status (used in SS mode). 3318c2ecf20Sopenharmony_ci * 0 - Entering to U1 state disabled. 3328c2ecf20Sopenharmony_ci * 1 - Entering to U1 state enabled. 3338c2ecf20Sopenharmony_ci */ 3348c2ecf20Sopenharmony_ci#define USB_STS_U1ENS_MASK BIT(24) 3358c2ecf20Sopenharmony_ci#define USB_STS_U1ENS(p) ((p) & USB_STS_U1ENS_MASK) 3368c2ecf20Sopenharmony_ci/* 3378c2ecf20Sopenharmony_ci * U2 state enable status (used in SS mode). 3388c2ecf20Sopenharmony_ci * 0 - Entering to U2 state disabled. 3398c2ecf20Sopenharmony_ci * 1 - Entering to U2 state enabled. 3408c2ecf20Sopenharmony_ci */ 3418c2ecf20Sopenharmony_ci#define USB_STS_U2ENS_MASK BIT(25) 3428c2ecf20Sopenharmony_ci#define USB_STS_U2ENS(p) ((p) & USB_STS_U2ENS_MASK) 3438c2ecf20Sopenharmony_ci/* 3448c2ecf20Sopenharmony_ci * SuperSpeed Link LTSSM state. This field reflects USBSS-DEV current 3458c2ecf20Sopenharmony_ci * SuperSpeed link state 3468c2ecf20Sopenharmony_ci */ 3478c2ecf20Sopenharmony_ci#define USB_STS_LST_MASK GENMASK(29, 26) 3488c2ecf20Sopenharmony_ci#define DEV_LST_U0 (((p) & USB_STS_LST_MASK) == (0x0 << 26)) 3498c2ecf20Sopenharmony_ci#define DEV_LST_U1 (((p) & USB_STS_LST_MASK) == (0x1 << 26)) 3508c2ecf20Sopenharmony_ci#define DEV_LST_U2 (((p) & USB_STS_LST_MASK) == (0x2 << 26)) 3518c2ecf20Sopenharmony_ci#define DEV_LST_U3 (((p) & USB_STS_LST_MASK) == (0x3 << 26)) 3528c2ecf20Sopenharmony_ci#define DEV_LST_DISABLED (((p) & USB_STS_LST_MASK) == (0x4 << 26)) 3538c2ecf20Sopenharmony_ci#define DEV_LST_RXDETECT (((p) & USB_STS_LST_MASK) == (0x5 << 26)) 3548c2ecf20Sopenharmony_ci#define DEV_LST_INACTIVE (((p) & USB_STS_LST_MASK) == (0x6 << 26)) 3558c2ecf20Sopenharmony_ci#define DEV_LST_POLLING (((p) & USB_STS_LST_MASK) == (0x7 << 26)) 3568c2ecf20Sopenharmony_ci#define DEV_LST_RECOVERY (((p) & USB_STS_LST_MASK) == (0x8 << 26)) 3578c2ecf20Sopenharmony_ci#define DEV_LST_HOT_RESET (((p) & USB_STS_LST_MASK) == (0x9 << 26)) 3588c2ecf20Sopenharmony_ci#define DEV_LST_COMP_MODE (((p) & USB_STS_LST_MASK) == (0xa << 26)) 3598c2ecf20Sopenharmony_ci#define DEV_LST_LB_STATE (((p) & USB_STS_LST_MASK) == (0xb << 26)) 3608c2ecf20Sopenharmony_ci/* 3618c2ecf20Sopenharmony_ci * DMA clock turn-off status. 3628c2ecf20Sopenharmony_ci * 0 - DMA clock is always on (default after hardware reset). 3638c2ecf20Sopenharmony_ci * 1 - DMA clock turn-off in U1, U2 and U3 (SS mode) is enabled. 3648c2ecf20Sopenharmony_ci */ 3658c2ecf20Sopenharmony_ci#define USB_STS_DMAOFF_MASK BIT(30) 3668c2ecf20Sopenharmony_ci#define USB_STS_DMAOFF(p) ((p) & USB_STS_DMAOFF_MASK) 3678c2ecf20Sopenharmony_ci/* 3688c2ecf20Sopenharmony_ci * SFR Endian status. 3698c2ecf20Sopenharmony_ci * 0 - Little Endian order (default after hardware reset). 3708c2ecf20Sopenharmony_ci * 1 - Big Endian order. 3718c2ecf20Sopenharmony_ci */ 3728c2ecf20Sopenharmony_ci#define USB_STS_ENDIAN2_MASK BIT(31) 3738c2ecf20Sopenharmony_ci#define USB_STS_ENDIAN2(p) ((p) & USB_STS_ENDIAN2_MASK) 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci/* USB_CMD - bitmasks */ 3768c2ecf20Sopenharmony_ci/* Set Function Address */ 3778c2ecf20Sopenharmony_ci#define USB_CMD_SET_ADDR BIT(0) 3788c2ecf20Sopenharmony_ci/* 3798c2ecf20Sopenharmony_ci * Function Address This field is saved to the device only when the field 3808c2ecf20Sopenharmony_ci * SET_ADDR is set '1 ' during write to USB_CMD register. 3818c2ecf20Sopenharmony_ci * Software is responsible for entering the address of the device during 3828c2ecf20Sopenharmony_ci * SET_ADDRESS request service. This field should be set immediately after 3838c2ecf20Sopenharmony_ci * the SETUP packet is decoded, and prior to confirmation of the status phase 3848c2ecf20Sopenharmony_ci */ 3858c2ecf20Sopenharmony_ci#define USB_CMD_FADDR_MASK GENMASK(7, 1) 3868c2ecf20Sopenharmony_ci#define USB_CMD_FADDR(p) (((p) << 1) & USB_CMD_FADDR_MASK) 3878c2ecf20Sopenharmony_ci/* Send Function Wake Device Notification TP (used only in SS mode). */ 3888c2ecf20Sopenharmony_ci#define USB_CMD_SDNFW BIT(8) 3898c2ecf20Sopenharmony_ci/* Set Test Mode (used only in HS/FS mode). */ 3908c2ecf20Sopenharmony_ci#define USB_CMD_STMODE BIT(9) 3918c2ecf20Sopenharmony_ci/* Test mode selector (used only in HS/FS mode) */ 3928c2ecf20Sopenharmony_ci#define USB_STS_TMODE_SEL_MASK GENMASK(11, 10) 3938c2ecf20Sopenharmony_ci#define USB_STS_TMODE_SEL(p) (((p) << 10) & USB_STS_TMODE_SEL_MASK) 3948c2ecf20Sopenharmony_ci/* 3958c2ecf20Sopenharmony_ci * Send Latency Tolerance Message Device Notification TP (used only 3968c2ecf20Sopenharmony_ci * in SS mode). 3978c2ecf20Sopenharmony_ci */ 3988c2ecf20Sopenharmony_ci#define USB_CMD_SDNLTM BIT(12) 3998c2ecf20Sopenharmony_ci/* Send Custom Transaction Packet (used only in SS mode) */ 4008c2ecf20Sopenharmony_ci#define USB_CMD_SPKT BIT(13) 4018c2ecf20Sopenharmony_ci/*Device Notification 'Function Wake' - Interface value (only in SS mode. */ 4028c2ecf20Sopenharmony_ci#define USB_CMD_DNFW_INT_MASK GENMASK(23, 16) 4038c2ecf20Sopenharmony_ci#define USB_STS_DNFW_INT(p) (((p) << 16) & USB_CMD_DNFW_INT_MASK) 4048c2ecf20Sopenharmony_ci/* 4058c2ecf20Sopenharmony_ci * Device Notification 'Latency Tolerance Message' -373 BELT value [7:0] 4068c2ecf20Sopenharmony_ci * (used only in SS mode). 4078c2ecf20Sopenharmony_ci */ 4088c2ecf20Sopenharmony_ci#define USB_CMD_DNLTM_BELT_MASK GENMASK(27, 16) 4098c2ecf20Sopenharmony_ci#define USB_STS_DNLTM_BELT(p) (((p) << 16) & USB_CMD_DNLTM_BELT_MASK) 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci/* USB_ITPN - bitmasks */ 4128c2ecf20Sopenharmony_ci/* 4138c2ecf20Sopenharmony_ci * ITP(SS) / SOF (HS/FS) number 4148c2ecf20Sopenharmony_ci * In SS mode this field represent number of last ITP received from host. 4158c2ecf20Sopenharmony_ci * In HS/FS mode this field represent number of last SOF received from host. 4168c2ecf20Sopenharmony_ci */ 4178c2ecf20Sopenharmony_ci#define USB_ITPN_MASK GENMASK(13, 0) 4188c2ecf20Sopenharmony_ci#define USB_ITPN(p) ((p) & USB_ITPN_MASK) 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci/* USB_LPM - bitmasks */ 4218c2ecf20Sopenharmony_ci/* Host Initiated Resume Duration. */ 4228c2ecf20Sopenharmony_ci#define USB_LPM_HIRD_MASK GENMASK(3, 0) 4238c2ecf20Sopenharmony_ci#define USB_LPM_HIRD(p) ((p) & USB_LPM_HIRD_MASK) 4248c2ecf20Sopenharmony_ci/* Remote Wakeup Enable (bRemoteWake). */ 4258c2ecf20Sopenharmony_ci#define USB_LPM_BRW BIT(4) 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci/* USB_IEN - bitmasks */ 4288c2ecf20Sopenharmony_ci/* SS connection interrupt enable */ 4298c2ecf20Sopenharmony_ci#define USB_IEN_CONIEN BIT(0) 4308c2ecf20Sopenharmony_ci/* SS disconnection interrupt enable. */ 4318c2ecf20Sopenharmony_ci#define USB_IEN_DISIEN BIT(1) 4328c2ecf20Sopenharmony_ci/* USB SS warm reset interrupt enable. */ 4338c2ecf20Sopenharmony_ci#define USB_IEN_UWRESIEN BIT(2) 4348c2ecf20Sopenharmony_ci/* USB SS hot reset interrupt enable */ 4358c2ecf20Sopenharmony_ci#define USB_IEN_UHRESIEN BIT(3) 4368c2ecf20Sopenharmony_ci/* SS link U3 state enter interrupt enable (suspend).*/ 4378c2ecf20Sopenharmony_ci#define USB_IEN_U3ENTIEN BIT(4) 4388c2ecf20Sopenharmony_ci/* SS link U3 state exit interrupt enable (wakeup). */ 4398c2ecf20Sopenharmony_ci#define USB_IEN_U3EXTIEN BIT(5) 4408c2ecf20Sopenharmony_ci/* SS link U2 state enter interrupt enable.*/ 4418c2ecf20Sopenharmony_ci#define USB_IEN_U2ENTIEN BIT(6) 4428c2ecf20Sopenharmony_ci/* SS link U2 state exit interrupt enable.*/ 4438c2ecf20Sopenharmony_ci#define USB_IEN_U2EXTIEN BIT(7) 4448c2ecf20Sopenharmony_ci/* SS link U1 state enter interrupt enable.*/ 4458c2ecf20Sopenharmony_ci#define USB_IEN_U1ENTIEN BIT(8) 4468c2ecf20Sopenharmony_ci/* SS link U1 state exit interrupt enable.*/ 4478c2ecf20Sopenharmony_ci#define USB_IEN_U1EXTIEN BIT(9) 4488c2ecf20Sopenharmony_ci/* ITP/SOF packet detected interrupt enable.*/ 4498c2ecf20Sopenharmony_ci#define USB_IEN_ITPIEN BIT(10) 4508c2ecf20Sopenharmony_ci/* Wakeup interrupt enable.*/ 4518c2ecf20Sopenharmony_ci#define USB_IEN_WAKEIEN BIT(11) 4528c2ecf20Sopenharmony_ci/* Send Custom Packet interrupt enable.*/ 4538c2ecf20Sopenharmony_ci#define USB_IEN_SPKTIEN BIT(12) 4548c2ecf20Sopenharmony_ci/* HS/FS mode connection interrupt enable.*/ 4558c2ecf20Sopenharmony_ci#define USB_IEN_CON2IEN BIT(16) 4568c2ecf20Sopenharmony_ci/* HS/FS mode disconnection interrupt enable.*/ 4578c2ecf20Sopenharmony_ci#define USB_IEN_DIS2IEN BIT(17) 4588c2ecf20Sopenharmony_ci/* USB reset (HS/FS mode) interrupt enable.*/ 4598c2ecf20Sopenharmony_ci#define USB_IEN_U2RESIEN BIT(18) 4608c2ecf20Sopenharmony_ci/* LPM L2 state enter interrupt enable.*/ 4618c2ecf20Sopenharmony_ci#define USB_IEN_L2ENTIEN BIT(20) 4628c2ecf20Sopenharmony_ci/* LPM L2 state exit interrupt enable.*/ 4638c2ecf20Sopenharmony_ci#define USB_IEN_L2EXTIEN BIT(21) 4648c2ecf20Sopenharmony_ci/* LPM L1 state enter interrupt enable.*/ 4658c2ecf20Sopenharmony_ci#define USB_IEN_L1ENTIEN BIT(24) 4668c2ecf20Sopenharmony_ci/* LPM L1 state exit interrupt enable.*/ 4678c2ecf20Sopenharmony_ci#define USB_IEN_L1EXTIEN BIT(25) 4688c2ecf20Sopenharmony_ci/* Configuration reset interrupt enable.*/ 4698c2ecf20Sopenharmony_ci#define USB_IEN_CFGRESIEN BIT(26) 4708c2ecf20Sopenharmony_ci/* Start of the USB SS warm reset interrupt enable.*/ 4718c2ecf20Sopenharmony_ci#define USB_IEN_UWRESSIEN BIT(28) 4728c2ecf20Sopenharmony_ci/* End of the USB SS warm reset interrupt enable.*/ 4738c2ecf20Sopenharmony_ci#define USB_IEN_UWRESEIEN BIT(29) 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci#define USB_IEN_INIT (USB_IEN_U2RESIEN | USB_ISTS_DIS2I | USB_IEN_CON2IEN \ 4768c2ecf20Sopenharmony_ci | USB_IEN_UHRESIEN | USB_IEN_UWRESIEN | USB_IEN_DISIEN \ 4778c2ecf20Sopenharmony_ci | USB_IEN_CONIEN | USB_IEN_U3EXTIEN | USB_IEN_L2ENTIEN \ 4788c2ecf20Sopenharmony_ci | USB_IEN_L2EXTIEN | USB_IEN_L1ENTIEN | USB_IEN_U3ENTIEN) 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci/* USB_ISTS - bitmasks */ 4818c2ecf20Sopenharmony_ci/* SS Connection detected. */ 4828c2ecf20Sopenharmony_ci#define USB_ISTS_CONI BIT(0) 4838c2ecf20Sopenharmony_ci/* SS Disconnection detected. */ 4848c2ecf20Sopenharmony_ci#define USB_ISTS_DISI BIT(1) 4858c2ecf20Sopenharmony_ci/* UUSB warm reset detectede. */ 4868c2ecf20Sopenharmony_ci#define USB_ISTS_UWRESI BIT(2) 4878c2ecf20Sopenharmony_ci/* USB hot reset detected. */ 4888c2ecf20Sopenharmony_ci#define USB_ISTS_UHRESI BIT(3) 4898c2ecf20Sopenharmony_ci/* U3 link state enter detected (suspend).*/ 4908c2ecf20Sopenharmony_ci#define USB_ISTS_U3ENTI BIT(4) 4918c2ecf20Sopenharmony_ci/* U3 link state exit detected (wakeup). */ 4928c2ecf20Sopenharmony_ci#define USB_ISTS_U3EXTI BIT(5) 4938c2ecf20Sopenharmony_ci/* U2 link state enter detected.*/ 4948c2ecf20Sopenharmony_ci#define USB_ISTS_U2ENTI BIT(6) 4958c2ecf20Sopenharmony_ci/* U2 link state exit detected.*/ 4968c2ecf20Sopenharmony_ci#define USB_ISTS_U2EXTI BIT(7) 4978c2ecf20Sopenharmony_ci/* U1 link state enter detected.*/ 4988c2ecf20Sopenharmony_ci#define USB_ISTS_U1ENTI BIT(8) 4998c2ecf20Sopenharmony_ci/* U1 link state exit detected.*/ 5008c2ecf20Sopenharmony_ci#define USB_ISTS_U1EXTI BIT(9) 5018c2ecf20Sopenharmony_ci/* ITP/SOF packet detected.*/ 5028c2ecf20Sopenharmony_ci#define USB_ISTS_ITPI BIT(10) 5038c2ecf20Sopenharmony_ci/* Wakeup detected.*/ 5048c2ecf20Sopenharmony_ci#define USB_ISTS_WAKEI BIT(11) 5058c2ecf20Sopenharmony_ci/* Send Custom Packet detected.*/ 5068c2ecf20Sopenharmony_ci#define USB_ISTS_SPKTI BIT(12) 5078c2ecf20Sopenharmony_ci/* HS/FS mode connection detected.*/ 5088c2ecf20Sopenharmony_ci#define USB_ISTS_CON2I BIT(16) 5098c2ecf20Sopenharmony_ci/* HS/FS mode disconnection detected.*/ 5108c2ecf20Sopenharmony_ci#define USB_ISTS_DIS2I BIT(17) 5118c2ecf20Sopenharmony_ci/* USB reset (HS/FS mode) detected.*/ 5128c2ecf20Sopenharmony_ci#define USB_ISTS_U2RESI BIT(18) 5138c2ecf20Sopenharmony_ci/* LPM L2 state enter detected.*/ 5148c2ecf20Sopenharmony_ci#define USB_ISTS_L2ENTI BIT(20) 5158c2ecf20Sopenharmony_ci/* LPM L2 state exit detected.*/ 5168c2ecf20Sopenharmony_ci#define USB_ISTS_L2EXTI BIT(21) 5178c2ecf20Sopenharmony_ci/* LPM L1 state enter detected.*/ 5188c2ecf20Sopenharmony_ci#define USB_ISTS_L1ENTI BIT(24) 5198c2ecf20Sopenharmony_ci/* LPM L1 state exit detected.*/ 5208c2ecf20Sopenharmony_ci#define USB_ISTS_L1EXTI BIT(25) 5218c2ecf20Sopenharmony_ci/* USB configuration reset detected.*/ 5228c2ecf20Sopenharmony_ci#define USB_ISTS_CFGRESI BIT(26) 5238c2ecf20Sopenharmony_ci/* Start of the USB warm reset detected.*/ 5248c2ecf20Sopenharmony_ci#define USB_ISTS_UWRESSI BIT(28) 5258c2ecf20Sopenharmony_ci/* End of the USB warm reset detected.*/ 5268c2ecf20Sopenharmony_ci#define USB_ISTS_UWRESEI BIT(29) 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci/* USB_SEL - bitmasks */ 5298c2ecf20Sopenharmony_ci#define EP_SEL_EPNO_MASK GENMASK(3, 0) 5308c2ecf20Sopenharmony_ci/* Endpoint number. */ 5318c2ecf20Sopenharmony_ci#define EP_SEL_EPNO(p) ((p) & EP_SEL_EPNO_MASK) 5328c2ecf20Sopenharmony_ci/* Endpoint direction bit - 0 - OUT, 1 - IN. */ 5338c2ecf20Sopenharmony_ci#define EP_SEL_DIR BIT(7) 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci#define select_ep_in(nr) (EP_SEL_EPNO(p) | EP_SEL_DIR) 5368c2ecf20Sopenharmony_ci#define select_ep_out (EP_SEL_EPNO(p)) 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci/* EP_TRADDR - bitmasks */ 5398c2ecf20Sopenharmony_ci/* Transfer Ring address. */ 5408c2ecf20Sopenharmony_ci#define EP_TRADDR_TRADDR(p) ((p)) 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci/* EP_CFG - bitmasks */ 5438c2ecf20Sopenharmony_ci/* Endpoint enable */ 5448c2ecf20Sopenharmony_ci#define EP_CFG_ENABLE BIT(0) 5458c2ecf20Sopenharmony_ci/* 5468c2ecf20Sopenharmony_ci * Endpoint type. 5478c2ecf20Sopenharmony_ci * 1 - isochronous 5488c2ecf20Sopenharmony_ci * 2 - bulk 5498c2ecf20Sopenharmony_ci * 3 - interrupt 5508c2ecf20Sopenharmony_ci */ 5518c2ecf20Sopenharmony_ci#define EP_CFG_EPTYPE_MASK GENMASK(2, 1) 5528c2ecf20Sopenharmony_ci#define EP_CFG_EPTYPE(p) (((p) << 1) & EP_CFG_EPTYPE_MASK) 5538c2ecf20Sopenharmony_ci/* Stream support enable (only in SS mode). */ 5548c2ecf20Sopenharmony_ci#define EP_CFG_STREAM_EN BIT(3) 5558c2ecf20Sopenharmony_ci/* TDL check (only in SS mode for BULK EP). */ 5568c2ecf20Sopenharmony_ci#define EP_CFG_TDL_CHK BIT(4) 5578c2ecf20Sopenharmony_ci/* SID check (only in SS mode for BULK OUT EP). */ 5588c2ecf20Sopenharmony_ci#define EP_CFG_SID_CHK BIT(5) 5598c2ecf20Sopenharmony_ci/* DMA transfer endianness. */ 5608c2ecf20Sopenharmony_ci#define EP_CFG_EPENDIAN BIT(7) 5618c2ecf20Sopenharmony_ci/* Max burst size (used only in SS mode). */ 5628c2ecf20Sopenharmony_ci#define EP_CFG_MAXBURST_MASK GENMASK(11, 8) 5638c2ecf20Sopenharmony_ci#define EP_CFG_MAXBURST(p) (((p) << 8) & EP_CFG_MAXBURST_MASK) 5648c2ecf20Sopenharmony_ci#define EP_CFG_MAXBURST_MAX 15 5658c2ecf20Sopenharmony_ci/* ISO max burst. */ 5668c2ecf20Sopenharmony_ci#define EP_CFG_MULT_MASK GENMASK(15, 14) 5678c2ecf20Sopenharmony_ci#define EP_CFG_MULT(p) (((p) << 14) & EP_CFG_MULT_MASK) 5688c2ecf20Sopenharmony_ci#define EP_CFG_MULT_MAX 2 5698c2ecf20Sopenharmony_ci/* ISO max burst. */ 5708c2ecf20Sopenharmony_ci#define EP_CFG_MAXPKTSIZE_MASK GENMASK(26, 16) 5718c2ecf20Sopenharmony_ci#define EP_CFG_MAXPKTSIZE(p) (((p) << 16) & EP_CFG_MAXPKTSIZE_MASK) 5728c2ecf20Sopenharmony_ci/* Max number of buffered packets. */ 5738c2ecf20Sopenharmony_ci#define EP_CFG_BUFFERING_MASK GENMASK(31, 27) 5748c2ecf20Sopenharmony_ci#define EP_CFG_BUFFERING(p) (((p) << 27) & EP_CFG_BUFFERING_MASK) 5758c2ecf20Sopenharmony_ci#define EP_CFG_BUFFERING_MAX 15 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci/* EP_CMD - bitmasks */ 5788c2ecf20Sopenharmony_ci/* Endpoint reset. */ 5798c2ecf20Sopenharmony_ci#define EP_CMD_EPRST BIT(0) 5808c2ecf20Sopenharmony_ci/* Endpoint STALL set. */ 5818c2ecf20Sopenharmony_ci#define EP_CMD_SSTALL BIT(1) 5828c2ecf20Sopenharmony_ci/* Endpoint STALL clear. */ 5838c2ecf20Sopenharmony_ci#define EP_CMD_CSTALL BIT(2) 5848c2ecf20Sopenharmony_ci/* Send ERDY TP. */ 5858c2ecf20Sopenharmony_ci#define EP_CMD_ERDY BIT(3) 5868c2ecf20Sopenharmony_ci/* Request complete. */ 5878c2ecf20Sopenharmony_ci#define EP_CMD_REQ_CMPL BIT(5) 5888c2ecf20Sopenharmony_ci/* Transfer descriptor ready. */ 5898c2ecf20Sopenharmony_ci#define EP_CMD_DRDY BIT(6) 5908c2ecf20Sopenharmony_ci/* Data flush. */ 5918c2ecf20Sopenharmony_ci#define EP_CMD_DFLUSH BIT(7) 5928c2ecf20Sopenharmony_ci/* 5938c2ecf20Sopenharmony_ci * Transfer Descriptor Length write (used only for Bulk Stream capable 5948c2ecf20Sopenharmony_ci * endpoints in SS mode). 5958c2ecf20Sopenharmony_ci * Bit Removed from DEV_VER_V3 controller version. 5968c2ecf20Sopenharmony_ci */ 5978c2ecf20Sopenharmony_ci#define EP_CMD_STDL BIT(8) 5988c2ecf20Sopenharmony_ci/* 5998c2ecf20Sopenharmony_ci * Transfer Descriptor Length (used only in SS mode for bulk endpoints). 6008c2ecf20Sopenharmony_ci * Bits Removed from DEV_VER_V3 controller version. 6018c2ecf20Sopenharmony_ci */ 6028c2ecf20Sopenharmony_ci#define EP_CMD_TDL_MASK GENMASK(15, 9) 6038c2ecf20Sopenharmony_ci#define EP_CMD_TDL_SET(p) (((p) << 9) & EP_CMD_TDL_MASK) 6048c2ecf20Sopenharmony_ci#define EP_CMD_TDL_GET(p) (((p) & EP_CMD_TDL_MASK) >> 9) 6058c2ecf20Sopenharmony_ci#define EP_CMD_TDL_MAX (EP_CMD_TDL_MASK >> 9) 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci/* ERDY Stream ID value (used in SS mode). */ 6088c2ecf20Sopenharmony_ci#define EP_CMD_ERDY_SID_MASK GENMASK(31, 16) 6098c2ecf20Sopenharmony_ci#define EP_CMD_ERDY_SID(p) (((p) << 16) & EP_CMD_ERDY_SID_MASK) 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci/* EP_STS - bitmasks */ 6128c2ecf20Sopenharmony_ci/* Setup transfer complete. */ 6138c2ecf20Sopenharmony_ci#define EP_STS_SETUP BIT(0) 6148c2ecf20Sopenharmony_ci/* Endpoint STALL status. */ 6158c2ecf20Sopenharmony_ci#define EP_STS_STALL(p) ((p) & BIT(1)) 6168c2ecf20Sopenharmony_ci/* Interrupt On Complete. */ 6178c2ecf20Sopenharmony_ci#define EP_STS_IOC BIT(2) 6188c2ecf20Sopenharmony_ci/* Interrupt on Short Packet. */ 6198c2ecf20Sopenharmony_ci#define EP_STS_ISP BIT(3) 6208c2ecf20Sopenharmony_ci/* Transfer descriptor missing. */ 6218c2ecf20Sopenharmony_ci#define EP_STS_DESCMIS BIT(4) 6228c2ecf20Sopenharmony_ci/* Stream Rejected (used only in SS mode) */ 6238c2ecf20Sopenharmony_ci#define EP_STS_STREAMR BIT(5) 6248c2ecf20Sopenharmony_ci/* EXIT from MOVE DATA State (used only for stream transfers in SS mode). */ 6258c2ecf20Sopenharmony_ci#define EP_STS_MD_EXIT BIT(6) 6268c2ecf20Sopenharmony_ci/* TRB error. */ 6278c2ecf20Sopenharmony_ci#define EP_STS_TRBERR BIT(7) 6288c2ecf20Sopenharmony_ci/* Not ready (used only in SS mode). */ 6298c2ecf20Sopenharmony_ci#define EP_STS_NRDY BIT(8) 6308c2ecf20Sopenharmony_ci/* DMA busy bit. */ 6318c2ecf20Sopenharmony_ci#define EP_STS_DBUSY BIT(9) 6328c2ecf20Sopenharmony_ci/* Endpoint Buffer Empty */ 6338c2ecf20Sopenharmony_ci#define EP_STS_BUFFEMPTY(p) ((p) & BIT(10)) 6348c2ecf20Sopenharmony_ci/* Current Cycle Status */ 6358c2ecf20Sopenharmony_ci#define EP_STS_CCS(p) ((p) & BIT(11)) 6368c2ecf20Sopenharmony_ci/* Prime (used only in SS mode. */ 6378c2ecf20Sopenharmony_ci#define EP_STS_PRIME BIT(12) 6388c2ecf20Sopenharmony_ci/* Stream error (used only in SS mode). */ 6398c2ecf20Sopenharmony_ci#define EP_STS_SIDERR BIT(13) 6408c2ecf20Sopenharmony_ci/* OUT size mismatch. */ 6418c2ecf20Sopenharmony_ci#define EP_STS_OUTSMM BIT(14) 6428c2ecf20Sopenharmony_ci/* ISO transmission error. */ 6438c2ecf20Sopenharmony_ci#define EP_STS_ISOERR BIT(15) 6448c2ecf20Sopenharmony_ci/* Host Packet Pending (only for SS mode). */ 6458c2ecf20Sopenharmony_ci#define EP_STS_HOSTPP(p) ((p) & BIT(16)) 6468c2ecf20Sopenharmony_ci/* Stream Protocol State Machine State (only for Bulk stream endpoints). */ 6478c2ecf20Sopenharmony_ci#define EP_STS_SPSMST_MASK GENMASK(18, 17) 6488c2ecf20Sopenharmony_ci#define EP_STS_SPSMST_DISABLED(p) (((p) & EP_STS_SPSMST_MASK) >> 17) 6498c2ecf20Sopenharmony_ci#define EP_STS_SPSMST_IDLE(p) (((p) & EP_STS_SPSMST_MASK) >> 17) 6508c2ecf20Sopenharmony_ci#define EP_STS_SPSMST_START_STREAM(p) (((p) & EP_STS_SPSMST_MASK) >> 17) 6518c2ecf20Sopenharmony_ci#define EP_STS_SPSMST_MOVE_DATA(p) (((p) & EP_STS_SPSMST_MASK) >> 17) 6528c2ecf20Sopenharmony_ci/* Interrupt On Transfer complete. */ 6538c2ecf20Sopenharmony_ci#define EP_STS_IOT BIT(19) 6548c2ecf20Sopenharmony_ci/* OUT queue endpoint number. */ 6558c2ecf20Sopenharmony_ci#define EP_STS_OUTQ_NO_MASK GENMASK(27, 24) 6568c2ecf20Sopenharmony_ci#define EP_STS_OUTQ_NO(p) (((p) & EP_STS_OUTQ_NO_MASK) >> 24) 6578c2ecf20Sopenharmony_ci/* OUT queue valid flag. */ 6588c2ecf20Sopenharmony_ci#define EP_STS_OUTQ_VAL_MASK BIT(28) 6598c2ecf20Sopenharmony_ci#define EP_STS_OUTQ_VAL(p) ((p) & EP_STS_OUTQ_VAL_MASK) 6608c2ecf20Sopenharmony_ci/* SETUP WAIT. */ 6618c2ecf20Sopenharmony_ci#define EP_STS_STPWAIT BIT(31) 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci/* EP_STS_SID - bitmasks */ 6648c2ecf20Sopenharmony_ci/* Stream ID (used only in SS mode). */ 6658c2ecf20Sopenharmony_ci#define EP_STS_SID_MASK GENMASK(15, 0) 6668c2ecf20Sopenharmony_ci#define EP_STS_SID(p) ((p) & EP_STS_SID_MASK) 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci/* EP_STS_EN - bitmasks */ 6698c2ecf20Sopenharmony_ci/* SETUP interrupt enable. */ 6708c2ecf20Sopenharmony_ci#define EP_STS_EN_SETUPEN BIT(0) 6718c2ecf20Sopenharmony_ci/* OUT transfer missing descriptor enable. */ 6728c2ecf20Sopenharmony_ci#define EP_STS_EN_DESCMISEN BIT(4) 6738c2ecf20Sopenharmony_ci/* Stream Rejected enable. */ 6748c2ecf20Sopenharmony_ci#define EP_STS_EN_STREAMREN BIT(5) 6758c2ecf20Sopenharmony_ci/* Move Data Exit enable.*/ 6768c2ecf20Sopenharmony_ci#define EP_STS_EN_MD_EXITEN BIT(6) 6778c2ecf20Sopenharmony_ci/* TRB enable. */ 6788c2ecf20Sopenharmony_ci#define EP_STS_EN_TRBERREN BIT(7) 6798c2ecf20Sopenharmony_ci/* NRDY enable. */ 6808c2ecf20Sopenharmony_ci#define EP_STS_EN_NRDYEN BIT(8) 6818c2ecf20Sopenharmony_ci/* Prime enable. */ 6828c2ecf20Sopenharmony_ci#define EP_STS_EN_PRIMEEEN BIT(12) 6838c2ecf20Sopenharmony_ci/* Stream error enable. */ 6848c2ecf20Sopenharmony_ci#define EP_STS_EN_SIDERREN BIT(13) 6858c2ecf20Sopenharmony_ci/* OUT size mismatch enable. */ 6868c2ecf20Sopenharmony_ci#define EP_STS_EN_OUTSMMEN BIT(14) 6878c2ecf20Sopenharmony_ci/* ISO transmission error enable. */ 6888c2ecf20Sopenharmony_ci#define EP_STS_EN_ISOERREN BIT(15) 6898c2ecf20Sopenharmony_ci/* Interrupt on Transmission complete enable. */ 6908c2ecf20Sopenharmony_ci#define EP_STS_EN_IOTEN BIT(19) 6918c2ecf20Sopenharmony_ci/* Setup Wait interrupt enable. */ 6928c2ecf20Sopenharmony_ci#define EP_STS_EN_STPWAITEN BIT(31) 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci/* DRBL- bitmasks */ 6958c2ecf20Sopenharmony_ci#define DB_VALUE_BY_INDEX(index) (1 << (index)) 6968c2ecf20Sopenharmony_ci#define DB_VALUE_EP0_OUT BIT(0) 6978c2ecf20Sopenharmony_ci#define DB_VALUE_EP0_IN BIT(16) 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci/* EP_IEN - bitmasks */ 7008c2ecf20Sopenharmony_ci#define EP_IEN(index) (1 << (index)) 7018c2ecf20Sopenharmony_ci#define EP_IEN_EP_OUT0 BIT(0) 7028c2ecf20Sopenharmony_ci#define EP_IEN_EP_IN0 BIT(16) 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci/* EP_ISTS - bitmasks */ 7058c2ecf20Sopenharmony_ci#define EP_ISTS(index) (1 << (index)) 7068c2ecf20Sopenharmony_ci#define EP_ISTS_EP_OUT0 BIT(0) 7078c2ecf20Sopenharmony_ci#define EP_ISTS_EP_IN0 BIT(16) 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci/* USB_PWR- bitmasks */ 7108c2ecf20Sopenharmony_ci/*Power Shut Off capability enable*/ 7118c2ecf20Sopenharmony_ci#define PUSB_PWR_PSO_EN BIT(0) 7128c2ecf20Sopenharmony_ci/*Power Shut Off capability disable*/ 7138c2ecf20Sopenharmony_ci#define PUSB_PWR_PSO_DS BIT(1) 7148c2ecf20Sopenharmony_ci/* 7158c2ecf20Sopenharmony_ci * Enables turning-off Reference Clock. 7168c2ecf20Sopenharmony_ci * This bit is optional and implemented only when support for OTG is 7178c2ecf20Sopenharmony_ci * implemented (indicated by OTG_READY bit set to '1'). 7188c2ecf20Sopenharmony_ci */ 7198c2ecf20Sopenharmony_ci#define PUSB_PWR_STB_CLK_SWITCH_EN BIT(8) 7208c2ecf20Sopenharmony_ci/* 7218c2ecf20Sopenharmony_ci * Status bit indicating that operation required by STB_CLK_SWITCH_EN write 7228c2ecf20Sopenharmony_ci * is completed 7238c2ecf20Sopenharmony_ci */ 7248c2ecf20Sopenharmony_ci#define PUSB_PWR_STB_CLK_SWITCH_DONE BIT(9) 7258c2ecf20Sopenharmony_ci/* This bit informs if Fast Registers Access is enabled. */ 7268c2ecf20Sopenharmony_ci#define PUSB_PWR_FST_REG_ACCESS_STAT BIT(30) 7278c2ecf20Sopenharmony_ci/* Fast Registers Access Enable. */ 7288c2ecf20Sopenharmony_ci#define PUSB_PWR_FST_REG_ACCESS BIT(31) 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci/* USB_CONF2- bitmasks */ 7318c2ecf20Sopenharmony_ci/* 7328c2ecf20Sopenharmony_ci * Writing 1 disables TDL calculation basing on TRB feature in controller 7338c2ecf20Sopenharmony_ci * for DMULT mode. 7348c2ecf20Sopenharmony_ci * Bit supported only for DEV_VER_V2 version. 7358c2ecf20Sopenharmony_ci */ 7368c2ecf20Sopenharmony_ci#define USB_CONF2_DIS_TDL_TRB BIT(1) 7378c2ecf20Sopenharmony_ci/* 7388c2ecf20Sopenharmony_ci * Writing 1 enables TDL calculation basing on TRB feature in controller 7398c2ecf20Sopenharmony_ci * for DMULT mode. 7408c2ecf20Sopenharmony_ci * Bit supported only for DEV_VER_V2 version. 7418c2ecf20Sopenharmony_ci */ 7428c2ecf20Sopenharmony_ci#define USB_CONF2_EN_TDL_TRB BIT(2) 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_ci/* USB_CAP1- bitmasks */ 7458c2ecf20Sopenharmony_ci/* 7468c2ecf20Sopenharmony_ci * SFR Interface type 7478c2ecf20Sopenharmony_ci * These field reflects type of SFR interface implemented: 7488c2ecf20Sopenharmony_ci * 0x0 - OCP 7498c2ecf20Sopenharmony_ci * 0x1 - AHB, 7508c2ecf20Sopenharmony_ci * 0x2 - PLB 7518c2ecf20Sopenharmony_ci * 0x3 - AXI 7528c2ecf20Sopenharmony_ci * 0x4-0xF - reserved 7538c2ecf20Sopenharmony_ci */ 7548c2ecf20Sopenharmony_ci#define USB_CAP1_SFR_TYPE_MASK GENMASK(3, 0) 7558c2ecf20Sopenharmony_ci#define DEV_SFR_TYPE_OCP(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x0) 7568c2ecf20Sopenharmony_ci#define DEV_SFR_TYPE_AHB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x1) 7578c2ecf20Sopenharmony_ci#define DEV_SFR_TYPE_PLB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x2) 7588c2ecf20Sopenharmony_ci#define DEV_SFR_TYPE_AXI(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x3) 7598c2ecf20Sopenharmony_ci/* 7608c2ecf20Sopenharmony_ci * SFR Interface width 7618c2ecf20Sopenharmony_ci * These field reflects width of SFR interface implemented: 7628c2ecf20Sopenharmony_ci * 0x0 - 8 bit interface, 7638c2ecf20Sopenharmony_ci * 0x1 - 16 bit interface, 7648c2ecf20Sopenharmony_ci * 0x2 - 32 bit interface 7658c2ecf20Sopenharmony_ci * 0x3 - 64 bit interface 7668c2ecf20Sopenharmony_ci * 0x4-0xF - reserved 7678c2ecf20Sopenharmony_ci */ 7688c2ecf20Sopenharmony_ci#define USB_CAP1_SFR_WIDTH_MASK GENMASK(7, 4) 7698c2ecf20Sopenharmony_ci#define DEV_SFR_WIDTH_8(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x0 << 4)) 7708c2ecf20Sopenharmony_ci#define DEV_SFR_WIDTH_16(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x1 << 4)) 7718c2ecf20Sopenharmony_ci#define DEV_SFR_WIDTH_32(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x2 << 4)) 7728c2ecf20Sopenharmony_ci#define DEV_SFR_WIDTH_64(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x3 << 4)) 7738c2ecf20Sopenharmony_ci/* 7748c2ecf20Sopenharmony_ci * DMA Interface type 7758c2ecf20Sopenharmony_ci * These field reflects type of DMA interface implemented: 7768c2ecf20Sopenharmony_ci * 0x0 - OCP 7778c2ecf20Sopenharmony_ci * 0x1 - AHB, 7788c2ecf20Sopenharmony_ci * 0x2 - PLB 7798c2ecf20Sopenharmony_ci * 0x3 - AXI 7808c2ecf20Sopenharmony_ci * 0x4-0xF - reserved 7818c2ecf20Sopenharmony_ci */ 7828c2ecf20Sopenharmony_ci#define USB_CAP1_DMA_TYPE_MASK GENMASK(11, 8) 7838c2ecf20Sopenharmony_ci#define DEV_DMA_TYPE_OCP(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x0 << 8)) 7848c2ecf20Sopenharmony_ci#define DEV_DMA_TYPE_AHB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x1 << 8)) 7858c2ecf20Sopenharmony_ci#define DEV_DMA_TYPE_PLB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x2 << 8)) 7868c2ecf20Sopenharmony_ci#define DEV_DMA_TYPE_AXI(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x3 << 8)) 7878c2ecf20Sopenharmony_ci/* 7888c2ecf20Sopenharmony_ci * DMA Interface width 7898c2ecf20Sopenharmony_ci * These field reflects width of DMA interface implemented: 7908c2ecf20Sopenharmony_ci * 0x0 - reserved, 7918c2ecf20Sopenharmony_ci * 0x1 - reserved, 7928c2ecf20Sopenharmony_ci * 0x2 - 32 bit interface 7938c2ecf20Sopenharmony_ci * 0x3 - 64 bit interface 7948c2ecf20Sopenharmony_ci * 0x4-0xF - reserved 7958c2ecf20Sopenharmony_ci */ 7968c2ecf20Sopenharmony_ci#define USB_CAP1_DMA_WIDTH_MASK GENMASK(15, 12) 7978c2ecf20Sopenharmony_ci#define DEV_DMA_WIDTH_32(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x2 << 12)) 7988c2ecf20Sopenharmony_ci#define DEV_DMA_WIDTH_64(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x3 << 12)) 7998c2ecf20Sopenharmony_ci/* 8008c2ecf20Sopenharmony_ci * USB3 PHY Interface type 8018c2ecf20Sopenharmony_ci * These field reflects type of USB3 PHY interface implemented: 8028c2ecf20Sopenharmony_ci * 0x0 - USB PIPE, 8038c2ecf20Sopenharmony_ci * 0x1 - RMMI, 8048c2ecf20Sopenharmony_ci * 0x2-0xF - reserved 8058c2ecf20Sopenharmony_ci */ 8068c2ecf20Sopenharmony_ci#define USB_CAP1_U3PHY_TYPE_MASK GENMASK(19, 16) 8078c2ecf20Sopenharmony_ci#define DEV_U3PHY_PIPE(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x0 << 16)) 8088c2ecf20Sopenharmony_ci#define DEV_U3PHY_RMMI(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x1 << 16)) 8098c2ecf20Sopenharmony_ci/* 8108c2ecf20Sopenharmony_ci * USB3 PHY Interface width 8118c2ecf20Sopenharmony_ci * These field reflects width of USB3 PHY interface implemented: 8128c2ecf20Sopenharmony_ci * 0x0 - 8 bit PIPE interface, 8138c2ecf20Sopenharmony_ci * 0x1 - 16 bit PIPE interface, 8148c2ecf20Sopenharmony_ci * 0x2 - 32 bit PIPE interface, 8158c2ecf20Sopenharmony_ci * 0x3 - 64 bit PIPE interface 8168c2ecf20Sopenharmony_ci * 0x4-0xF - reserved 8178c2ecf20Sopenharmony_ci * Note: When SSIC interface is implemented this field shows the width of 8188c2ecf20Sopenharmony_ci * internal PIPE interface. The RMMI interface is always 20bit wide. 8198c2ecf20Sopenharmony_ci */ 8208c2ecf20Sopenharmony_ci#define USB_CAP1_U3PHY_WIDTH_MASK GENMASK(23, 20) 8218c2ecf20Sopenharmony_ci#define DEV_U3PHY_WIDTH_8(p) \ 8228c2ecf20Sopenharmony_ci (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x0 << 20)) 8238c2ecf20Sopenharmony_ci#define DEV_U3PHY_WIDTH_16(p) \ 8248c2ecf20Sopenharmony_ci (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x1 << 16)) 8258c2ecf20Sopenharmony_ci#define DEV_U3PHY_WIDTH_32(p) \ 8268c2ecf20Sopenharmony_ci (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x2 << 20)) 8278c2ecf20Sopenharmony_ci#define DEV_U3PHY_WIDTH_64(p) \ 8288c2ecf20Sopenharmony_ci (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x3 << 16)) 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci/* 8318c2ecf20Sopenharmony_ci * USB2 PHY Interface enable 8328c2ecf20Sopenharmony_ci * These field informs if USB2 PHY interface is implemented: 8338c2ecf20Sopenharmony_ci * 0x0 - interface NOT implemented, 8348c2ecf20Sopenharmony_ci * 0x1 - interface implemented 8358c2ecf20Sopenharmony_ci */ 8368c2ecf20Sopenharmony_ci#define USB_CAP1_U2PHY_EN(p) ((p) & BIT(24)) 8378c2ecf20Sopenharmony_ci/* 8388c2ecf20Sopenharmony_ci * USB2 PHY Interface type 8398c2ecf20Sopenharmony_ci * These field reflects type of USB2 PHY interface implemented: 8408c2ecf20Sopenharmony_ci * 0x0 - UTMI, 8418c2ecf20Sopenharmony_ci * 0x1 - ULPI 8428c2ecf20Sopenharmony_ci */ 8438c2ecf20Sopenharmony_ci#define DEV_U2PHY_ULPI(p) ((p) & BIT(25)) 8448c2ecf20Sopenharmony_ci/* 8458c2ecf20Sopenharmony_ci * USB2 PHY Interface width 8468c2ecf20Sopenharmony_ci * These field reflects width of USB2 PHY interface implemented: 8478c2ecf20Sopenharmony_ci * 0x0 - 8 bit interface, 8488c2ecf20Sopenharmony_ci * 0x1 - 16 bit interface, 8498c2ecf20Sopenharmony_ci * Note: The ULPI interface is always 8bit wide. 8508c2ecf20Sopenharmony_ci */ 8518c2ecf20Sopenharmony_ci#define DEV_U2PHY_WIDTH_16(p) ((p) & BIT(26)) 8528c2ecf20Sopenharmony_ci/* 8538c2ecf20Sopenharmony_ci * OTG Ready 8548c2ecf20Sopenharmony_ci * 0x0 - pure device mode 8558c2ecf20Sopenharmony_ci * 0x1 - some features and ports for CDNS USB OTG controller are implemented. 8568c2ecf20Sopenharmony_ci */ 8578c2ecf20Sopenharmony_ci#define USB_CAP1_OTG_READY(p) ((p) & BIT(27)) 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_ci/* 8608c2ecf20Sopenharmony_ci * When set, indicates that controller supports automatic internal TDL 8618c2ecf20Sopenharmony_ci * calculation basing on the size provided in TRB (TRB[22:17]) for DMULT mode 8628c2ecf20Sopenharmony_ci * Supported only for DEV_VER_V2 controller version. 8638c2ecf20Sopenharmony_ci */ 8648c2ecf20Sopenharmony_ci#define USB_CAP1_TDL_FROM_TRB(p) ((p) & BIT(28)) 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci/* USB_CAP2- bitmasks */ 8678c2ecf20Sopenharmony_ci/* 8688c2ecf20Sopenharmony_ci * The actual size of the connected On-chip RAM memory in kB: 8698c2ecf20Sopenharmony_ci * - 0 means 256 kB (max supported mem size) 8708c2ecf20Sopenharmony_ci * - value other than 0 reflects the mem size in kB 8718c2ecf20Sopenharmony_ci */ 8728c2ecf20Sopenharmony_ci#define USB_CAP2_ACTUAL_MEM_SIZE(p) ((p) & GENMASK(7, 0)) 8738c2ecf20Sopenharmony_ci/* 8748c2ecf20Sopenharmony_ci * Max supported mem size 8758c2ecf20Sopenharmony_ci * These field reflects width of on-chip RAM address bus width, 8768c2ecf20Sopenharmony_ci * which determines max supported mem size: 8778c2ecf20Sopenharmony_ci * 0x0-0x7 - reserved, 8788c2ecf20Sopenharmony_ci * 0x8 - support for 4kB mem, 8798c2ecf20Sopenharmony_ci * 0x9 - support for 8kB mem, 8808c2ecf20Sopenharmony_ci * 0xA - support for 16kB mem, 8818c2ecf20Sopenharmony_ci * 0xB - support for 32kB mem, 8828c2ecf20Sopenharmony_ci * 0xC - support for 64kB mem, 8838c2ecf20Sopenharmony_ci * 0xD - support for 128kB mem, 8848c2ecf20Sopenharmony_ci * 0xE - support for 256kB mem, 8858c2ecf20Sopenharmony_ci * 0xF - reserved 8868c2ecf20Sopenharmony_ci */ 8878c2ecf20Sopenharmony_ci#define USB_CAP2_MAX_MEM_SIZE(p) ((p) & GENMASK(11, 8)) 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci/* USB_CAP3- bitmasks */ 8908c2ecf20Sopenharmony_ci#define EP_IS_IMPLEMENTED(reg, index) ((reg) & (1 << (index))) 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci/* USB_CAP4- bitmasks */ 8938c2ecf20Sopenharmony_ci#define EP_SUPPORT_ISO(reg, index) ((reg) & (1 << (index))) 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci/* USB_CAP5- bitmasks */ 8968c2ecf20Sopenharmony_ci#define EP_SUPPORT_STREAM(reg, index) ((reg) & (1 << (index))) 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci/* USB_CAP6- bitmasks */ 8998c2ecf20Sopenharmony_ci/* The USBSS-DEV Controller Internal build number. */ 9008c2ecf20Sopenharmony_ci#define GET_DEV_BASE_VERSION(p) ((p) & GENMASK(23, 0)) 9018c2ecf20Sopenharmony_ci/* The USBSS-DEV Controller version number. */ 9028c2ecf20Sopenharmony_ci#define GET_DEV_CUSTOM_VERSION(p) ((p) & GENMASK(31, 24)) 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci#define DEV_VER_NXP_V1 0x00024502 9058c2ecf20Sopenharmony_ci#define DEV_VER_TI_V1 0x00024509 9068c2ecf20Sopenharmony_ci#define DEV_VER_V2 0x0002450C 9078c2ecf20Sopenharmony_ci#define DEV_VER_V3 0x0002450d 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci/* DBG_LINK1- bitmasks */ 9108c2ecf20Sopenharmony_ci/* 9118c2ecf20Sopenharmony_ci * LFPS_MIN_DET_U1_EXIT value This parameter configures the minimum 9128c2ecf20Sopenharmony_ci * time required for decoding the received LFPS as an LFPS.U1_Exit. 9138c2ecf20Sopenharmony_ci */ 9148c2ecf20Sopenharmony_ci#define DBG_LINK1_LFPS_MIN_DET_U1_EXIT(p) ((p) & GENMASK(7, 0)) 9158c2ecf20Sopenharmony_ci/* 9168c2ecf20Sopenharmony_ci * LFPS_MIN_GEN_U1_EXIT value This parameter configures the minimum time for 9178c2ecf20Sopenharmony_ci * phytxelecidle deassertion when LFPS.U1_Exit 9188c2ecf20Sopenharmony_ci */ 9198c2ecf20Sopenharmony_ci#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_MASK GENMASK(15, 8) 9208c2ecf20Sopenharmony_ci#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT(p) (((p) << 8) & GENMASK(15, 8)) 9218c2ecf20Sopenharmony_ci/* 9228c2ecf20Sopenharmony_ci * RXDET_BREAK_DIS value This parameter configures terminating the Far-end 9238c2ecf20Sopenharmony_ci * Receiver termination detection sequence: 9248c2ecf20Sopenharmony_ci * 0: it is possible that USBSS_DEV will terminate Farend receiver 9258c2ecf20Sopenharmony_ci * termination detection sequence 9268c2ecf20Sopenharmony_ci * 1: USBSS_DEV will not terminate Far-end receiver termination 9278c2ecf20Sopenharmony_ci * detection sequence 9288c2ecf20Sopenharmony_ci */ 9298c2ecf20Sopenharmony_ci#define DBG_LINK1_RXDET_BREAK_DIS BIT(16) 9308c2ecf20Sopenharmony_ci/* LFPS_GEN_PING value This parameter configures the LFPS.Ping generation */ 9318c2ecf20Sopenharmony_ci#define DBG_LINK1_LFPS_GEN_PING(p) (((p) << 17) & GENMASK(21, 17)) 9328c2ecf20Sopenharmony_ci/* 9338c2ecf20Sopenharmony_ci * Set the LFPS_MIN_DET_U1_EXIT value Writing '1' to this bit writes the 9348c2ecf20Sopenharmony_ci * LFPS_MIN_DET_U1_EXIT field value to the device. This bit is automatically 9358c2ecf20Sopenharmony_ci * cleared. Writing '0' has no effect 9368c2ecf20Sopenharmony_ci */ 9378c2ecf20Sopenharmony_ci#define DBG_LINK1_LFPS_MIN_DET_U1_EXIT_SET BIT(24) 9388c2ecf20Sopenharmony_ci/* 9398c2ecf20Sopenharmony_ci * Set the LFPS_MIN_GEN_U1_EXIT value. Writing '1' to this bit writes the 9408c2ecf20Sopenharmony_ci * LFPS_MIN_GEN_U1_EXIT field value to the device. This bit is automatically 9418c2ecf20Sopenharmony_ci * cleared. Writing '0' has no effect 9428c2ecf20Sopenharmony_ci */ 9438c2ecf20Sopenharmony_ci#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_SET BIT(25) 9448c2ecf20Sopenharmony_ci/* 9458c2ecf20Sopenharmony_ci * Set the RXDET_BREAK_DIS value Writing '1' to this bit writes 9468c2ecf20Sopenharmony_ci * the RXDET_BREAK_DIS field value to the device. This bit is automatically 9478c2ecf20Sopenharmony_ci * cleared. Writing '0' has no effect 9488c2ecf20Sopenharmony_ci */ 9498c2ecf20Sopenharmony_ci#define DBG_LINK1_RXDET_BREAK_DIS_SET BIT(26) 9508c2ecf20Sopenharmony_ci/* 9518c2ecf20Sopenharmony_ci * Set the LFPS_GEN_PING_SET value Writing '1' to this bit writes 9528c2ecf20Sopenharmony_ci * the LFPS_GEN_PING field value to the device. This bit is automatically 9538c2ecf20Sopenharmony_ci * cleared. Writing '0' has no effect." 9548c2ecf20Sopenharmony_ci */ 9558c2ecf20Sopenharmony_ci#define DBG_LINK1_LFPS_GEN_PING_SET BIT(27) 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_ci/* DMA_AXI_CTRL- bitmasks */ 9588c2ecf20Sopenharmony_ci/* The mawprot pin configuration. */ 9598c2ecf20Sopenharmony_ci#define DMA_AXI_CTRL_MARPROT(p) ((p) & GENMASK(2, 0)) 9608c2ecf20Sopenharmony_ci/* The marprot pin configuration. */ 9618c2ecf20Sopenharmony_ci#define DMA_AXI_CTRL_MAWPROT(p) (((p) & GENMASK(2, 0)) << 16) 9628c2ecf20Sopenharmony_ci#define DMA_AXI_CTRL_NON_SECURE 0x02 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci#define gadget_to_cdns3_device(g) (container_of(g, struct cdns3_device, gadget)) 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci#define ep_to_cdns3_ep(ep) (container_of(ep, struct cdns3_endpoint, endpoint)) 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 9698c2ecf20Sopenharmony_ci/* 9708c2ecf20Sopenharmony_ci * USBSS-DEV DMA interface. 9718c2ecf20Sopenharmony_ci */ 9728c2ecf20Sopenharmony_ci#define TRBS_PER_SEGMENT 600 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_ci#define ISO_MAX_INTERVAL 10 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci#define MAX_TRB_LENGTH BIT(16) 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_ci#if TRBS_PER_SEGMENT < 2 9798c2ecf20Sopenharmony_ci#error "Incorrect TRBS_PER_SEGMENT. Minimal Transfer Ring size is 2." 9808c2ecf20Sopenharmony_ci#endif 9818c2ecf20Sopenharmony_ci 9828c2ecf20Sopenharmony_ci#define TRBS_PER_STREAM_SEGMENT 2 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci#if TRBS_PER_STREAM_SEGMENT < 2 9858c2ecf20Sopenharmony_ci#error "Incorrect TRBS_PER_STREAMS_SEGMENT. Minimal Transfer Ring size is 2." 9868c2ecf20Sopenharmony_ci#endif 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci/* 9898c2ecf20Sopenharmony_ci *Only for ISOC endpoints - maximum number of TRBs is calculated as 9908c2ecf20Sopenharmony_ci * pow(2, bInterval-1) * number of usb requests. It is limitation made by 9918c2ecf20Sopenharmony_ci * driver to save memory. Controller must prepare TRB for each ITP even 9928c2ecf20Sopenharmony_ci * if bInterval > 1. It's the reason why driver needs so many TRBs for 9938c2ecf20Sopenharmony_ci * isochronous endpoints. 9948c2ecf20Sopenharmony_ci */ 9958c2ecf20Sopenharmony_ci#define TRBS_PER_ISOC_SEGMENT (ISO_MAX_INTERVAL * 8) 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci#define GET_TRBS_PER_SEGMENT(ep_type) ((ep_type) == USB_ENDPOINT_XFER_ISOC ? \ 9988c2ecf20Sopenharmony_ci TRBS_PER_ISOC_SEGMENT : TRBS_PER_SEGMENT) 9998c2ecf20Sopenharmony_ci/** 10008c2ecf20Sopenharmony_ci * struct cdns3_trb - represent Transfer Descriptor block. 10018c2ecf20Sopenharmony_ci * @buffer: pointer to buffer data 10028c2ecf20Sopenharmony_ci * @length: length of data 10038c2ecf20Sopenharmony_ci * @control: control flags. 10048c2ecf20Sopenharmony_ci * 10058c2ecf20Sopenharmony_ci * This structure describes transfer block serviced by DMA module. 10068c2ecf20Sopenharmony_ci */ 10078c2ecf20Sopenharmony_cistruct cdns3_trb { 10088c2ecf20Sopenharmony_ci __le32 buffer; 10098c2ecf20Sopenharmony_ci __le32 length; 10108c2ecf20Sopenharmony_ci __le32 control; 10118c2ecf20Sopenharmony_ci}; 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci#define TRB_SIZE (sizeof(struct cdns3_trb)) 10148c2ecf20Sopenharmony_ci#define TRB_RING_SIZE (TRB_SIZE * TRBS_PER_SEGMENT) 10158c2ecf20Sopenharmony_ci#define TRB_STREAM_RING_SIZE (TRB_SIZE * TRBS_PER_STREAM_SEGMENT) 10168c2ecf20Sopenharmony_ci#define TRB_ISO_RING_SIZE (TRB_SIZE * TRBS_PER_ISOC_SEGMENT) 10178c2ecf20Sopenharmony_ci#define TRB_CTRL_RING_SIZE (TRB_SIZE * 2) 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci/* TRB bit mask */ 10208c2ecf20Sopenharmony_ci#define TRB_TYPE_BITMASK GENMASK(15, 10) 10218c2ecf20Sopenharmony_ci#define TRB_TYPE(p) ((p) << 10) 10228c2ecf20Sopenharmony_ci#define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10) 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci/* TRB type IDs */ 10258c2ecf20Sopenharmony_ci/* bulk, interrupt, isoc , and control data stage */ 10268c2ecf20Sopenharmony_ci#define TRB_NORMAL 1 10278c2ecf20Sopenharmony_ci/* TRB for linking ring segments */ 10288c2ecf20Sopenharmony_ci#define TRB_LINK 6 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci/* Cycle bit - indicates TRB ownership by driver or hw*/ 10318c2ecf20Sopenharmony_ci#define TRB_CYCLE BIT(0) 10328c2ecf20Sopenharmony_ci/* 10338c2ecf20Sopenharmony_ci * When set to '1', the device will toggle its interpretation of the Cycle bit 10348c2ecf20Sopenharmony_ci */ 10358c2ecf20Sopenharmony_ci#define TRB_TOGGLE BIT(1) 10368c2ecf20Sopenharmony_ci/* 10378c2ecf20Sopenharmony_ci * The controller will set it if OUTSMM (OUT size mismatch) is detected, 10388c2ecf20Sopenharmony_ci * this bit is for normal TRB 10398c2ecf20Sopenharmony_ci */ 10408c2ecf20Sopenharmony_ci#define TRB_SMM BIT(1) 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci/* 10438c2ecf20Sopenharmony_ci * Short Packet (SP). OUT EPs at DMULT=1 only. Indicates if the TRB was 10448c2ecf20Sopenharmony_ci * processed while USB short packet was received. No more buffers defined by 10458c2ecf20Sopenharmony_ci * the TD will be used. DMA will automatically advance to next TD. 10468c2ecf20Sopenharmony_ci * - Shall be set to 0 by Software when putting TRB on the Transfer Ring 10478c2ecf20Sopenharmony_ci * - Shall be set to 1 by Controller when Short Packet condition for this TRB 10488c2ecf20Sopenharmony_ci * is detected independent if ISP is set or not. 10498c2ecf20Sopenharmony_ci */ 10508c2ecf20Sopenharmony_ci#define TRB_SP BIT(1) 10518c2ecf20Sopenharmony_ci 10528c2ecf20Sopenharmony_ci/* Interrupt on short packet*/ 10538c2ecf20Sopenharmony_ci#define TRB_ISP BIT(2) 10548c2ecf20Sopenharmony_ci/*Setting this bit enables FIFO DMA operation mode*/ 10558c2ecf20Sopenharmony_ci#define TRB_FIFO_MODE BIT(3) 10568c2ecf20Sopenharmony_ci/* Set PCIe no snoop attribute */ 10578c2ecf20Sopenharmony_ci#define TRB_CHAIN BIT(4) 10588c2ecf20Sopenharmony_ci/* Interrupt on completion */ 10598c2ecf20Sopenharmony_ci#define TRB_IOC BIT(5) 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci/* stream ID bitmasks. */ 10628c2ecf20Sopenharmony_ci#define TRB_STREAM_ID_BITMASK GENMASK(31, 16) 10638c2ecf20Sopenharmony_ci#define TRB_STREAM_ID(p) ((p) << 16) 10648c2ecf20Sopenharmony_ci#define TRB_FIELD_TO_STREAMID(p) (((p) & TRB_STREAM_ID_BITMASK) >> 16) 10658c2ecf20Sopenharmony_ci 10668c2ecf20Sopenharmony_ci/* Size of TD expressed in USB packets for HS/FS mode. */ 10678c2ecf20Sopenharmony_ci#define TRB_TDL_HS_SIZE(p) (((p) << 16) & GENMASK(31, 16)) 10688c2ecf20Sopenharmony_ci#define TRB_TDL_HS_SIZE_GET(p) (((p) & GENMASK(31, 16)) >> 16) 10698c2ecf20Sopenharmony_ci 10708c2ecf20Sopenharmony_ci/* transfer_len bitmasks. */ 10718c2ecf20Sopenharmony_ci#define TRB_LEN(p) ((p) & GENMASK(16, 0)) 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci/* Size of TD expressed in USB packets for SS mode. */ 10748c2ecf20Sopenharmony_ci#define TRB_TDL_SS_SIZE(p) (((p) << 17) & GENMASK(23, 17)) 10758c2ecf20Sopenharmony_ci#define TRB_TDL_SS_SIZE_GET(p) (((p) & GENMASK(23, 17)) >> 17) 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci/* transfer_len bitmasks - bits 31:24 */ 10788c2ecf20Sopenharmony_ci#define TRB_BURST_LEN(p) ((unsigned int)((p) << 24) & GENMASK(31, 24)) 10798c2ecf20Sopenharmony_ci#define TRB_BURST_LEN_GET(p) (((p) & GENMASK(31, 24)) >> 24) 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_ci/* Data buffer pointer bitmasks*/ 10828c2ecf20Sopenharmony_ci#define TRB_BUFFER(p) ((p) & GENMASK(31, 0)) 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 10858c2ecf20Sopenharmony_ci/* Driver numeric constants */ 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci/* Such declaration should be added to ch9.h */ 10888c2ecf20Sopenharmony_ci#define USB_DEVICE_MAX_ADDRESS 127 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci/* Endpoint init values */ 10918c2ecf20Sopenharmony_ci#define CDNS3_EP_MAX_PACKET_LIMIT 1024 10928c2ecf20Sopenharmony_ci#define CDNS3_EP_MAX_STREAMS 15 10938c2ecf20Sopenharmony_ci#define CDNS3_EP0_MAX_PACKET_LIMIT 512 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci/* All endpoints including EP0 */ 10968c2ecf20Sopenharmony_ci#define CDNS3_ENDPOINTS_MAX_COUNT 32 10978c2ecf20Sopenharmony_ci#define CDNS3_EP_ZLP_BUF_SIZE 1024 10988c2ecf20Sopenharmony_ci 10998c2ecf20Sopenharmony_ci#define CDNS3_MAX_NUM_DESCMISS_BUF 32 11008c2ecf20Sopenharmony_ci#define CDNS3_DESCMIS_BUF_SIZE 2048 /* Bytes */ 11018c2ecf20Sopenharmony_ci#define CDNS3_WA2_NUM_BUFFERS 128 11028c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/ 11038c2ecf20Sopenharmony_ci/* Used structs */ 11048c2ecf20Sopenharmony_ci 11058c2ecf20Sopenharmony_cistruct cdns3_device; 11068c2ecf20Sopenharmony_ci 11078c2ecf20Sopenharmony_ci/** 11088c2ecf20Sopenharmony_ci * struct cdns3_endpoint - extended device side representation of USB endpoint. 11098c2ecf20Sopenharmony_ci * @endpoint: usb endpoint 11108c2ecf20Sopenharmony_ci * @pending_req_list: list of requests queuing on transfer ring. 11118c2ecf20Sopenharmony_ci * @deferred_req_list: list of requests waiting for queuing on transfer ring. 11128c2ecf20Sopenharmony_ci * @wa2_descmiss_req_list: list of requests internally allocated by driver. 11138c2ecf20Sopenharmony_ci * @trb_pool: transfer ring - array of transaction buffers 11148c2ecf20Sopenharmony_ci * @trb_pool_dma: dma address of transfer ring 11158c2ecf20Sopenharmony_ci * @cdns3_dev: device associated with this endpoint 11168c2ecf20Sopenharmony_ci * @name: a human readable name e.g. ep1out 11178c2ecf20Sopenharmony_ci * @flags: specify the current state of endpoint 11188c2ecf20Sopenharmony_ci * @descmis_req: internal transfer object used for getting data from on-chip 11198c2ecf20Sopenharmony_ci * buffer. It can happen only if function driver doesn't send usb_request 11208c2ecf20Sopenharmony_ci * object on time. 11218c2ecf20Sopenharmony_ci * @dir: endpoint direction 11228c2ecf20Sopenharmony_ci * @num: endpoint number (1 - 15) 11238c2ecf20Sopenharmony_ci * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK 11248c2ecf20Sopenharmony_ci * @interval: interval between packets used for ISOC endpoint. 11258c2ecf20Sopenharmony_ci * @free_trbs: number of free TRBs in transfer ring 11268c2ecf20Sopenharmony_ci * @num_trbs: number of all TRBs in transfer ring 11278c2ecf20Sopenharmony_ci * @alloc_ring_size: size of the allocated TRB ring 11288c2ecf20Sopenharmony_ci * @pcs: producer cycle state 11298c2ecf20Sopenharmony_ci * @ccs: consumer cycle state 11308c2ecf20Sopenharmony_ci * @enqueue: enqueue index in transfer ring 11318c2ecf20Sopenharmony_ci * @dequeue: dequeue index in transfer ring 11328c2ecf20Sopenharmony_ci * @trb_burst_size: number of burst used in trb. 11338c2ecf20Sopenharmony_ci */ 11348c2ecf20Sopenharmony_cistruct cdns3_endpoint { 11358c2ecf20Sopenharmony_ci struct usb_ep endpoint; 11368c2ecf20Sopenharmony_ci struct list_head pending_req_list; 11378c2ecf20Sopenharmony_ci struct list_head deferred_req_list; 11388c2ecf20Sopenharmony_ci struct list_head wa2_descmiss_req_list; 11398c2ecf20Sopenharmony_ci int wa2_counter; 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_ci struct cdns3_trb *trb_pool; 11428c2ecf20Sopenharmony_ci dma_addr_t trb_pool_dma; 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci struct cdns3_device *cdns3_dev; 11458c2ecf20Sopenharmony_ci char name[20]; 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_ci#define EP_ENABLED BIT(0) 11488c2ecf20Sopenharmony_ci#define EP_STALLED BIT(1) 11498c2ecf20Sopenharmony_ci#define EP_STALL_PENDING BIT(2) 11508c2ecf20Sopenharmony_ci#define EP_WEDGE BIT(3) 11518c2ecf20Sopenharmony_ci#define EP_TRANSFER_STARTED BIT(4) 11528c2ecf20Sopenharmony_ci#define EP_UPDATE_EP_TRBADDR BIT(5) 11538c2ecf20Sopenharmony_ci#define EP_PENDING_REQUEST BIT(6) 11548c2ecf20Sopenharmony_ci#define EP_RING_FULL BIT(7) 11558c2ecf20Sopenharmony_ci#define EP_CLAIMED BIT(8) 11568c2ecf20Sopenharmony_ci#define EP_DEFERRED_DRDY BIT(9) 11578c2ecf20Sopenharmony_ci#define EP_QUIRK_ISO_OUT_EN BIT(10) 11588c2ecf20Sopenharmony_ci#define EP_QUIRK_END_TRANSFER BIT(11) 11598c2ecf20Sopenharmony_ci#define EP_QUIRK_EXTRA_BUF_DET BIT(12) 11608c2ecf20Sopenharmony_ci#define EP_QUIRK_EXTRA_BUF_EN BIT(13) 11618c2ecf20Sopenharmony_ci#define EP_TDLCHK_EN BIT(15) 11628c2ecf20Sopenharmony_ci#define EP_CONFIGURED BIT(16) 11638c2ecf20Sopenharmony_ci u32 flags; 11648c2ecf20Sopenharmony_ci 11658c2ecf20Sopenharmony_ci struct cdns3_request *descmis_req; 11668c2ecf20Sopenharmony_ci 11678c2ecf20Sopenharmony_ci u8 dir; 11688c2ecf20Sopenharmony_ci u8 num; 11698c2ecf20Sopenharmony_ci u8 type; 11708c2ecf20Sopenharmony_ci u8 mult; 11718c2ecf20Sopenharmony_ci u8 bMaxBurst; 11728c2ecf20Sopenharmony_ci u16 wMaxPacketSize; 11738c2ecf20Sopenharmony_ci int interval; 11748c2ecf20Sopenharmony_ci 11758c2ecf20Sopenharmony_ci int free_trbs; 11768c2ecf20Sopenharmony_ci int num_trbs; 11778c2ecf20Sopenharmony_ci int alloc_ring_size; 11788c2ecf20Sopenharmony_ci u8 pcs; 11798c2ecf20Sopenharmony_ci u8 ccs; 11808c2ecf20Sopenharmony_ci int enqueue; 11818c2ecf20Sopenharmony_ci int dequeue; 11828c2ecf20Sopenharmony_ci u8 trb_burst_size; 11838c2ecf20Sopenharmony_ci 11848c2ecf20Sopenharmony_ci unsigned int wa1_set:1; 11858c2ecf20Sopenharmony_ci struct cdns3_trb *wa1_trb; 11868c2ecf20Sopenharmony_ci unsigned int wa1_trb_index; 11878c2ecf20Sopenharmony_ci unsigned int wa1_cycle_bit:1; 11888c2ecf20Sopenharmony_ci 11898c2ecf20Sopenharmony_ci /* Stream related */ 11908c2ecf20Sopenharmony_ci unsigned int use_streams:1; 11918c2ecf20Sopenharmony_ci unsigned int prime_flag:1; 11928c2ecf20Sopenharmony_ci u32 ep_sts_pending; 11938c2ecf20Sopenharmony_ci u16 last_stream_id; 11948c2ecf20Sopenharmony_ci u16 pending_tdl; 11958c2ecf20Sopenharmony_ci unsigned int stream_sg_idx; 11968c2ecf20Sopenharmony_ci}; 11978c2ecf20Sopenharmony_ci 11988c2ecf20Sopenharmony_ci/** 11998c2ecf20Sopenharmony_ci * struct cdns3_aligned_buf - represent aligned buffer used for DMA transfer 12008c2ecf20Sopenharmony_ci * @buf: aligned to 8 bytes data buffer. Buffer address used in 12018c2ecf20Sopenharmony_ci * TRB shall be aligned to 8. 12028c2ecf20Sopenharmony_ci * @dma: dma address 12038c2ecf20Sopenharmony_ci * @size: size of buffer 12048c2ecf20Sopenharmony_ci * @in_use: inform if this buffer is associated with usb_request 12058c2ecf20Sopenharmony_ci * @list: used to adding instance of this object to list 12068c2ecf20Sopenharmony_ci */ 12078c2ecf20Sopenharmony_cistruct cdns3_aligned_buf { 12088c2ecf20Sopenharmony_ci void *buf; 12098c2ecf20Sopenharmony_ci dma_addr_t dma; 12108c2ecf20Sopenharmony_ci u32 size; 12118c2ecf20Sopenharmony_ci unsigned in_use:1; 12128c2ecf20Sopenharmony_ci struct list_head list; 12138c2ecf20Sopenharmony_ci}; 12148c2ecf20Sopenharmony_ci 12158c2ecf20Sopenharmony_ci/** 12168c2ecf20Sopenharmony_ci * struct cdns3_request - extended device side representation of usb_request 12178c2ecf20Sopenharmony_ci * object . 12188c2ecf20Sopenharmony_ci * @request: generic usb_request object describing single I/O request. 12198c2ecf20Sopenharmony_ci * @priv_ep: extended representation of usb_ep object 12208c2ecf20Sopenharmony_ci * @trb: the first TRB association with this request 12218c2ecf20Sopenharmony_ci * @start_trb: number of the first TRB in transfer ring 12228c2ecf20Sopenharmony_ci * @end_trb: number of the last TRB in transfer ring 12238c2ecf20Sopenharmony_ci * @aligned_buf: object holds information about aligned buffer associated whit 12248c2ecf20Sopenharmony_ci * this endpoint 12258c2ecf20Sopenharmony_ci * @flags: flag specifying special usage of request 12268c2ecf20Sopenharmony_ci * @list: used by internally allocated request to add to wa2_descmiss_req_list. 12278c2ecf20Sopenharmony_ci * @finished_trb: number of trb has already finished per request 12288c2ecf20Sopenharmony_ci * @num_of_trb: how many trbs in this request 12298c2ecf20Sopenharmony_ci */ 12308c2ecf20Sopenharmony_cistruct cdns3_request { 12318c2ecf20Sopenharmony_ci struct usb_request request; 12328c2ecf20Sopenharmony_ci struct cdns3_endpoint *priv_ep; 12338c2ecf20Sopenharmony_ci struct cdns3_trb *trb; 12348c2ecf20Sopenharmony_ci int start_trb; 12358c2ecf20Sopenharmony_ci int end_trb; 12368c2ecf20Sopenharmony_ci struct cdns3_aligned_buf *aligned_buf; 12378c2ecf20Sopenharmony_ci#define REQUEST_PENDING BIT(0) 12388c2ecf20Sopenharmony_ci#define REQUEST_INTERNAL BIT(1) 12398c2ecf20Sopenharmony_ci#define REQUEST_INTERNAL_CH BIT(2) 12408c2ecf20Sopenharmony_ci#define REQUEST_ZLP BIT(3) 12418c2ecf20Sopenharmony_ci#define REQUEST_UNALIGNED BIT(4) 12428c2ecf20Sopenharmony_ci u32 flags; 12438c2ecf20Sopenharmony_ci struct list_head list; 12448c2ecf20Sopenharmony_ci int finished_trb; 12458c2ecf20Sopenharmony_ci int num_of_trb; 12468c2ecf20Sopenharmony_ci}; 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci#define to_cdns3_request(r) (container_of(r, struct cdns3_request, request)) 12498c2ecf20Sopenharmony_ci 12508c2ecf20Sopenharmony_ci/*Stages used during enumeration process.*/ 12518c2ecf20Sopenharmony_ci#define CDNS3_SETUP_STAGE 0x0 12528c2ecf20Sopenharmony_ci#define CDNS3_DATA_STAGE 0x1 12538c2ecf20Sopenharmony_ci#define CDNS3_STATUS_STAGE 0x2 12548c2ecf20Sopenharmony_ci 12558c2ecf20Sopenharmony_ci/** 12568c2ecf20Sopenharmony_ci * struct cdns3_device - represent USB device. 12578c2ecf20Sopenharmony_ci * @dev: pointer to device structure associated whit this controller 12588c2ecf20Sopenharmony_ci * @sysdev: pointer to the DMA capable device 12598c2ecf20Sopenharmony_ci * @gadget: device side representation of the peripheral controller 12608c2ecf20Sopenharmony_ci * @gadget_driver: pointer to the gadget driver 12618c2ecf20Sopenharmony_ci * @dev_ver: device controller version. 12628c2ecf20Sopenharmony_ci * @lock: for synchronizing 12638c2ecf20Sopenharmony_ci * @regs: base address for device side registers 12648c2ecf20Sopenharmony_ci * @setup_buf: used while processing usb control requests 12658c2ecf20Sopenharmony_ci * @setup_dma: dma address for setup_buf 12668c2ecf20Sopenharmony_ci * @zlp_buf - zlp buffer 12678c2ecf20Sopenharmony_ci * @ep0_stage: ep0 stage during enumeration process. 12688c2ecf20Sopenharmony_ci * @ep0_data_dir: direction for control transfer 12698c2ecf20Sopenharmony_ci * @eps: array of pointers to all endpoints with exclusion ep0 12708c2ecf20Sopenharmony_ci * @aligned_buf_list: list of aligned buffers internally allocated by driver 12718c2ecf20Sopenharmony_ci * @aligned_buf_wq: workqueue freeing no longer used aligned buf. 12728c2ecf20Sopenharmony_ci * @selected_ep: actually selected endpoint. It's used only to improve 12738c2ecf20Sopenharmony_ci * performance. 12748c2ecf20Sopenharmony_ci * @isoch_delay: value from Set Isoch Delay request. Only valid on SS/SSP. 12758c2ecf20Sopenharmony_ci * @u1_allowed: allow device transition to u1 state 12768c2ecf20Sopenharmony_ci * @u2_allowed: allow device transition to u2 state 12778c2ecf20Sopenharmony_ci * @is_selfpowered: device is self powered 12788c2ecf20Sopenharmony_ci * @setup_pending: setup packet is processing by gadget driver 12798c2ecf20Sopenharmony_ci * @hw_configured_flag: hardware endpoint configuration was set. 12808c2ecf20Sopenharmony_ci * @wake_up_flag: allow device to remote up the host 12818c2ecf20Sopenharmony_ci * @status_completion_no_call: indicate that driver is waiting for status s 12828c2ecf20Sopenharmony_ci * stage completion. It's used in deferred SET_CONFIGURATION request. 12838c2ecf20Sopenharmony_ci * @onchip_buffers: number of available on-chip buffers. 12848c2ecf20Sopenharmony_ci * @onchip_used_size: actual size of on-chip memory assigned to endpoints. 12858c2ecf20Sopenharmony_ci * @pending_status_wq: workqueue handling status stage for deferred requests. 12868c2ecf20Sopenharmony_ci * @pending_status_request: request for which status stage was deferred 12878c2ecf20Sopenharmony_ci */ 12888c2ecf20Sopenharmony_cistruct cdns3_device { 12898c2ecf20Sopenharmony_ci struct device *dev; 12908c2ecf20Sopenharmony_ci struct device *sysdev; 12918c2ecf20Sopenharmony_ci 12928c2ecf20Sopenharmony_ci struct usb_gadget gadget; 12938c2ecf20Sopenharmony_ci struct usb_gadget_driver *gadget_driver; 12948c2ecf20Sopenharmony_ci 12958c2ecf20Sopenharmony_ci#define CDNS_REVISION_V0 0x00024501 12968c2ecf20Sopenharmony_ci#define CDNS_REVISION_V1 0x00024509 12978c2ecf20Sopenharmony_ci u32 dev_ver; 12988c2ecf20Sopenharmony_ci 12998c2ecf20Sopenharmony_ci /* generic spin-lock for drivers */ 13008c2ecf20Sopenharmony_ci spinlock_t lock; 13018c2ecf20Sopenharmony_ci 13028c2ecf20Sopenharmony_ci struct cdns3_usb_regs __iomem *regs; 13038c2ecf20Sopenharmony_ci 13048c2ecf20Sopenharmony_ci struct usb_ctrlrequest *setup_buf; 13058c2ecf20Sopenharmony_ci dma_addr_t setup_dma; 13068c2ecf20Sopenharmony_ci void *zlp_buf; 13078c2ecf20Sopenharmony_ci 13088c2ecf20Sopenharmony_ci u8 ep0_stage; 13098c2ecf20Sopenharmony_ci int ep0_data_dir; 13108c2ecf20Sopenharmony_ci 13118c2ecf20Sopenharmony_ci struct cdns3_endpoint *eps[CDNS3_ENDPOINTS_MAX_COUNT]; 13128c2ecf20Sopenharmony_ci 13138c2ecf20Sopenharmony_ci struct list_head aligned_buf_list; 13148c2ecf20Sopenharmony_ci struct work_struct aligned_buf_wq; 13158c2ecf20Sopenharmony_ci 13168c2ecf20Sopenharmony_ci u32 selected_ep; 13178c2ecf20Sopenharmony_ci u16 isoch_delay; 13188c2ecf20Sopenharmony_ci 13198c2ecf20Sopenharmony_ci unsigned wait_for_setup:1; 13208c2ecf20Sopenharmony_ci unsigned u1_allowed:1; 13218c2ecf20Sopenharmony_ci unsigned u2_allowed:1; 13228c2ecf20Sopenharmony_ci unsigned is_selfpowered:1; 13238c2ecf20Sopenharmony_ci unsigned setup_pending:1; 13248c2ecf20Sopenharmony_ci unsigned hw_configured_flag:1; 13258c2ecf20Sopenharmony_ci unsigned wake_up_flag:1; 13268c2ecf20Sopenharmony_ci unsigned status_completion_no_call:1; 13278c2ecf20Sopenharmony_ci unsigned using_streams:1; 13288c2ecf20Sopenharmony_ci int out_mem_is_allocated; 13298c2ecf20Sopenharmony_ci 13308c2ecf20Sopenharmony_ci struct work_struct pending_status_wq; 13318c2ecf20Sopenharmony_ci struct usb_request *pending_status_request; 13328c2ecf20Sopenharmony_ci 13338c2ecf20Sopenharmony_ci /*in KB */ 13348c2ecf20Sopenharmony_ci u16 onchip_buffers; 13358c2ecf20Sopenharmony_ci u16 onchip_used_size; 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci u16 ep_buf_size; 13388c2ecf20Sopenharmony_ci u16 ep_iso_burst; 13398c2ecf20Sopenharmony_ci}; 13408c2ecf20Sopenharmony_ci 13418c2ecf20Sopenharmony_civoid cdns3_set_register_bit(void __iomem *ptr, u32 mask); 13428c2ecf20Sopenharmony_cidma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep, 13438c2ecf20Sopenharmony_ci struct cdns3_trb *trb); 13448c2ecf20Sopenharmony_cienum usb_device_speed cdns3_get_speed(struct cdns3_device *priv_dev); 13458c2ecf20Sopenharmony_civoid cdns3_pending_setup_status_handler(struct work_struct *work); 13468c2ecf20Sopenharmony_civoid cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev); 13478c2ecf20Sopenharmony_civoid cdns3_set_hw_configuration(struct cdns3_device *priv_dev); 13488c2ecf20Sopenharmony_civoid cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); 13498c2ecf20Sopenharmony_civoid cdns3_allow_enable_l1(struct cdns3_device *priv_dev, int enable); 13508c2ecf20Sopenharmony_cistruct usb_request *cdns3_next_request(struct list_head *list); 13518c2ecf20Sopenharmony_civoid cdns3_rearm_transfer(struct cdns3_endpoint *priv_ep, u8 rearm); 13528c2ecf20Sopenharmony_ciint cdns3_allocate_trb_pool(struct cdns3_endpoint *priv_ep); 13538c2ecf20Sopenharmony_ciu8 cdns3_ep_addr_to_index(u8 ep_addr); 13548c2ecf20Sopenharmony_ciint cdns3_gadget_ep_set_wedge(struct usb_ep *ep); 13558c2ecf20Sopenharmony_ciint cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value); 13568c2ecf20Sopenharmony_civoid __cdns3_gadget_ep_set_halt(struct cdns3_endpoint *priv_ep); 13578c2ecf20Sopenharmony_ciint __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep); 13588c2ecf20Sopenharmony_cistruct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, 13598c2ecf20Sopenharmony_ci gfp_t gfp_flags); 13608c2ecf20Sopenharmony_civoid cdns3_gadget_ep_free_request(struct usb_ep *ep, 13618c2ecf20Sopenharmony_ci struct usb_request *request); 13628c2ecf20Sopenharmony_ciint cdns3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request); 13638c2ecf20Sopenharmony_civoid cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, 13648c2ecf20Sopenharmony_ci struct cdns3_request *priv_req, 13658c2ecf20Sopenharmony_ci int status); 13668c2ecf20Sopenharmony_ci 13678c2ecf20Sopenharmony_ciint cdns3_init_ep0(struct cdns3_device *priv_dev, 13688c2ecf20Sopenharmony_ci struct cdns3_endpoint *priv_ep); 13698c2ecf20Sopenharmony_civoid cdns3_ep0_config(struct cdns3_device *priv_dev); 13708c2ecf20Sopenharmony_ciint cdns3_ep_config(struct cdns3_endpoint *priv_ep, bool enable); 13718c2ecf20Sopenharmony_civoid cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir); 13728c2ecf20Sopenharmony_ciint __cdns3_gadget_wakeup(struct cdns3_device *priv_dev); 13738c2ecf20Sopenharmony_ci 13748c2ecf20Sopenharmony_ci#endif /* __LINUX_CDNS3_GADGET */ 1375