18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * bdc.h - header for the BRCM BDC USB3.0 device controller
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2014 Broadcom Corporation
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Ashwini Pahuja
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef	__LINUX_BDC_H__
118c2ecf20Sopenharmony_ci#define	__LINUX_BDC_H__
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/usb.h>
158c2ecf20Sopenharmony_ci#include <linux/device.h>
168c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
178c2ecf20Sopenharmony_ci#include <linux/list.h>
188c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
198c2ecf20Sopenharmony_ci#include <linux/mm.h>
208c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
218c2ecf20Sopenharmony_ci#include <linux/usb/ch9.h>
228c2ecf20Sopenharmony_ci#include <linux/usb/gadget.h>
238c2ecf20Sopenharmony_ci#include <asm/unaligned.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define BRCM_BDC_NAME "bdc"
268c2ecf20Sopenharmony_ci#define BRCM_BDC_DESC "Broadcom USB Device Controller driver"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define DMA_ADDR_INVALID        (~(dma_addr_t)0)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* BDC command operation timeout in usec*/
318c2ecf20Sopenharmony_ci#define BDC_CMD_TIMEOUT	1000
328c2ecf20Sopenharmony_ci/* BDC controller operation timeout in usec*/
338c2ecf20Sopenharmony_ci#define BDC_COP_TIMEOUT	500
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/*
368c2ecf20Sopenharmony_ci * Maximum size of ep0 response buffer for ch9 requests,
378c2ecf20Sopenharmony_ci * the set_sel request uses 6 so far, the max.
388c2ecf20Sopenharmony_ci*/
398c2ecf20Sopenharmony_ci#define EP0_RESPONSE_BUFF  6
408c2ecf20Sopenharmony_ci/* Start with SS as default */
418c2ecf20Sopenharmony_ci#define EP0_MAX_PKT_SIZE 512
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/* 64 entries in a SRR */
448c2ecf20Sopenharmony_ci#define NUM_SR_ENTRIES	64
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/* Num of bds per table */
478c2ecf20Sopenharmony_ci#define NUM_BDS_PER_TABLE	64
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* Num of tables in bd list for control,bulk and Int ep */
508c2ecf20Sopenharmony_ci#define NUM_TABLES	2
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* Num of tables in bd list for Isoch ep */
538c2ecf20Sopenharmony_ci#define NUM_TABLES_ISOCH	6
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* U1 Timeout default: 248usec */
568c2ecf20Sopenharmony_ci#define U1_TIMEOUT	0xf8
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* Interrupt coalescence in usec */
598c2ecf20Sopenharmony_ci#define	INT_CLS	500
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/* Register offsets */
628c2ecf20Sopenharmony_ci/* Configuration and Capability registers */
638c2ecf20Sopenharmony_ci#define BDC_BDCCFG0	0x00
648c2ecf20Sopenharmony_ci#define BDC_BDCCFG1	0x04
658c2ecf20Sopenharmony_ci#define BDC_BDCCAP0	0x08
668c2ecf20Sopenharmony_ci#define BDC_BDCCAP1	0x0c
678c2ecf20Sopenharmony_ci#define BDC_CMDPAR0	0x10
688c2ecf20Sopenharmony_ci#define BDC_CMDPAR1	0x14
698c2ecf20Sopenharmony_ci#define BDC_CMDPAR2	0x18
708c2ecf20Sopenharmony_ci#define BDC_CMDSC	0x1c
718c2ecf20Sopenharmony_ci#define BDC_USPC	0x20
728c2ecf20Sopenharmony_ci#define BDC_USPPMS	0x28
738c2ecf20Sopenharmony_ci#define BDC_USPPM2	0x2c
748c2ecf20Sopenharmony_ci#define BDC_SPBBAL	0x38
758c2ecf20Sopenharmony_ci#define BDC_SPBBAH	0x3c
768c2ecf20Sopenharmony_ci#define BDC_BDCSC	0x40
778c2ecf20Sopenharmony_ci#define BDC_XSFNTF	0x4c
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define BDC_DVCSA	0x50
808c2ecf20Sopenharmony_ci#define BDC_DVCSB	0x54
818c2ecf20Sopenharmony_ci#define BDC_EPSTS0	0x60
828c2ecf20Sopenharmony_ci#define BDC_EPSTS1	0x64
838c2ecf20Sopenharmony_ci#define BDC_EPSTS2	0x68
848c2ecf20Sopenharmony_ci#define BDC_EPSTS3	0x6c
858c2ecf20Sopenharmony_ci#define BDC_EPSTS4	0x70
868c2ecf20Sopenharmony_ci#define BDC_EPSTS5	0x74
878c2ecf20Sopenharmony_ci#define BDC_EPSTS6	0x78
888c2ecf20Sopenharmony_ci#define BDC_EPSTS7	0x7c
898c2ecf20Sopenharmony_ci#define BDC_SRRBAL(n)	(0x200 + (n * 0x10))
908c2ecf20Sopenharmony_ci#define BDC_SRRBAH(n)	(0x204 + (n * 0x10))
918c2ecf20Sopenharmony_ci#define BDC_SRRINT(n)	(0x208 + (n * 0x10))
928c2ecf20Sopenharmony_ci#define BDC_INTCTLS(n)	(0x20c + (n * 0x10))
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* Extended capability regs */
958c2ecf20Sopenharmony_ci#define BDC_FSCNOC	0xcd4
968c2ecf20Sopenharmony_ci#define BDC_FSCNIC	0xce4
978c2ecf20Sopenharmony_ci#define NUM_NCS(p)	(p >> 28)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/* Register bit fields and Masks */
1008c2ecf20Sopenharmony_ci/* BDC Configuration 0 */
1018c2ecf20Sopenharmony_ci#define BDC_PGS(p)	(((p) & (0x7 << 8)) >> 8)
1028c2ecf20Sopenharmony_ci#define BDC_SPB(p)	(p & 0x7)
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* BDC Capability1 */
1058c2ecf20Sopenharmony_ci#define BDC_P64		(1 << 0)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/* BDC Command register */
1088c2ecf20Sopenharmony_ci#define BDC_CMD_FH	0xe
1098c2ecf20Sopenharmony_ci#define BDC_CMD_DNC	0x6
1108c2ecf20Sopenharmony_ci#define BDC_CMD_EPO	0x4
1118c2ecf20Sopenharmony_ci#define BDC_CMD_BLA	0x3
1128c2ecf20Sopenharmony_ci#define BDC_CMD_EPC	0x2
1138c2ecf20Sopenharmony_ci#define BDC_CMD_DVC	0x1
1148c2ecf20Sopenharmony_ci#define BDC_CMD_CWS		(0x1 << 5)
1158c2ecf20Sopenharmony_ci#define BDC_CMD_CST(p)		(((p) & (0xf << 6))>>6)
1168c2ecf20Sopenharmony_ci#define BDC_CMD_EPN(p)		((p & 0x1f) << 10)
1178c2ecf20Sopenharmony_ci#define BDC_SUB_CMD_ADD		(0x1 << 17)
1188c2ecf20Sopenharmony_ci#define BDC_SUB_CMD_FWK		(0x4 << 17)
1198c2ecf20Sopenharmony_ci/* Reset sequence number */
1208c2ecf20Sopenharmony_ci#define BDC_CMD_EPO_RST_SN	(0x1 << 16)
1218c2ecf20Sopenharmony_ci#define BDC_CMD_EP0_XSD		(0x1 << 16)
1228c2ecf20Sopenharmony_ci#define BDC_SUB_CMD_ADD_EP	(0x1 << 17)
1238c2ecf20Sopenharmony_ci#define BDC_SUB_CMD_DRP_EP	(0x2 << 17)
1248c2ecf20Sopenharmony_ci#define BDC_SUB_CMD_EP_STP	(0x2 << 17)
1258c2ecf20Sopenharmony_ci#define BDC_SUB_CMD_EP_STL	(0x4 << 17)
1268c2ecf20Sopenharmony_ci#define BDC_SUB_CMD_EP_RST	(0x1 << 17)
1278c2ecf20Sopenharmony_ci#define BDC_CMD_SRD		(1 << 27)
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/* CMD completion status */
1308c2ecf20Sopenharmony_ci#define BDC_CMDS_SUCC	0x1
1318c2ecf20Sopenharmony_ci#define BDC_CMDS_PARA	0x3
1328c2ecf20Sopenharmony_ci#define BDC_CMDS_STAT	0x4
1338c2ecf20Sopenharmony_ci#define BDC_CMDS_FAIL	0x5
1348c2ecf20Sopenharmony_ci#define BDC_CMDS_INTL	0x6
1358c2ecf20Sopenharmony_ci#define BDC_CMDS_BUSY	0xf
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/* CMDSC Param 2 shifts */
1388c2ecf20Sopenharmony_ci#define EPT_SHIFT	22
1398c2ecf20Sopenharmony_ci#define MP_SHIFT	10
1408c2ecf20Sopenharmony_ci#define MB_SHIFT	6
1418c2ecf20Sopenharmony_ci#define EPM_SHIFT	4
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci/* BDC USPSC */
1448c2ecf20Sopenharmony_ci#define BDC_VBC		(1 << 31)
1458c2ecf20Sopenharmony_ci#define BDC_PRC		(1 << 30)
1468c2ecf20Sopenharmony_ci#define BDC_PCE		(1 << 29)
1478c2ecf20Sopenharmony_ci#define BDC_CFC		(1 << 28)
1488c2ecf20Sopenharmony_ci#define BDC_PCC		(1 << 27)
1498c2ecf20Sopenharmony_ci#define BDC_PSC		(1 << 26)
1508c2ecf20Sopenharmony_ci#define BDC_VBS		(1 << 25)
1518c2ecf20Sopenharmony_ci#define BDC_PRS		(1 << 24)
1528c2ecf20Sopenharmony_ci#define BDC_PCS		(1 << 23)
1538c2ecf20Sopenharmony_ci#define BDC_PSP(p)	(((p) & (0x7 << 20))>>20)
1548c2ecf20Sopenharmony_ci#define BDC_SCN		(1 << 8)
1558c2ecf20Sopenharmony_ci#define BDC_SDC		(1 << 7)
1568c2ecf20Sopenharmony_ci#define BDC_SWS		(1 << 4)
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define BDC_USPSC_RW	(BDC_SCN|BDC_SDC|BDC_SWS|0xf)
1598c2ecf20Sopenharmony_ci#define BDC_PSP(p)	(((p) & (0x7 << 20))>>20)
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#define BDC_SPEED_FS	0x1
1628c2ecf20Sopenharmony_ci#define BDC_SPEED_LS	0x2
1638c2ecf20Sopenharmony_ci#define BDC_SPEED_HS	0x3
1648c2ecf20Sopenharmony_ci#define BDC_SPEED_SS	0x4
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#define BDC_PST(p)	(p & 0xf)
1678c2ecf20Sopenharmony_ci#define BDC_PST_MASK	0xf
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/* USPPMS */
1708c2ecf20Sopenharmony_ci#define BDC_U2E		(0x1 << 31)
1718c2ecf20Sopenharmony_ci#define BDC_U1E		(0x1 << 30)
1728c2ecf20Sopenharmony_ci#define BDC_U2A		(0x1 << 29)
1738c2ecf20Sopenharmony_ci#define BDC_PORT_W1S	(0x1 << 17)
1748c2ecf20Sopenharmony_ci#define BDC_U1T(p)	((p) & 0xff)
1758c2ecf20Sopenharmony_ci#define BDC_U2T(p)	(((p) & 0xff) << 8)
1768c2ecf20Sopenharmony_ci#define BDC_U1T_MASK	0xff
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci/* USBPM2 */
1798c2ecf20Sopenharmony_ci/* Hardware LPM Enable */
1808c2ecf20Sopenharmony_ci#define BDC_HLE		(1 << 16)
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* BDC Status and Control */
1838c2ecf20Sopenharmony_ci#define BDC_COP_RST	(1 << 29)
1848c2ecf20Sopenharmony_ci#define BDC_COP_RUN	(2 << 29)
1858c2ecf20Sopenharmony_ci#define BDC_COP_STP	(4 << 29)
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci#define BDC_COP_MASK (BDC_COP_RST|BDC_COP_RUN|BDC_COP_STP)
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci#define BDC_COS		(1 << 28)
1908c2ecf20Sopenharmony_ci#define BDC_CSTS(p)	(((p) & (0x7 << 20)) >> 20)
1918c2ecf20Sopenharmony_ci#define BDC_MASK_MCW	(1 << 7)
1928c2ecf20Sopenharmony_ci#define BDC_GIE		(1 << 1)
1938c2ecf20Sopenharmony_ci#define BDC_GIP		(1 << 0)
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#define BDC_HLT	1
1968c2ecf20Sopenharmony_ci#define BDC_NOR	2
1978c2ecf20Sopenharmony_ci#define BDC_OIP	7
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* Buffer descriptor and Status report bit fields and masks */
2008c2ecf20Sopenharmony_ci#define BD_TYPE_BITMASK	(0xf)
2018c2ecf20Sopenharmony_ci#define BD_CHAIN	0xf
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci#define BD_TFS_SHIFT	4
2048c2ecf20Sopenharmony_ci#define BD_SOT		(1 << 26)
2058c2ecf20Sopenharmony_ci#define BD_EOT		(1 << 27)
2068c2ecf20Sopenharmony_ci#define BD_ISP		(1 << 29)
2078c2ecf20Sopenharmony_ci#define BD_IOC		(1 << 30)
2088c2ecf20Sopenharmony_ci#define BD_SBF		(1 << 31)
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci#define BD_INTR_TARGET(p)	(((p) & 0x1f) << 27)
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci#define BDC_SRR_RWS		(1 << 4)
2138c2ecf20Sopenharmony_ci#define BDC_SRR_RST		(1 << 3)
2148c2ecf20Sopenharmony_ci#define BDC_SRR_ISR		(1 << 2)
2158c2ecf20Sopenharmony_ci#define BDC_SRR_IE		(1 << 1)
2168c2ecf20Sopenharmony_ci#define BDC_SRR_IP		(1 << 0)
2178c2ecf20Sopenharmony_ci#define BDC_SRR_EPI(p)	(((p) & (0xff << 24)) >> 24)
2188c2ecf20Sopenharmony_ci#define BDC_SRR_DPI(p) (((p) & (0xff << 16)) >> 16)
2198c2ecf20Sopenharmony_ci#define BDC_SRR_DPI_MASK	0x00ff0000
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci#define MARK_CHAIN_BD	(BD_CHAIN|BD_EOT|BD_SOT)
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci/* Control transfer BD specific fields */
2248c2ecf20Sopenharmony_ci#define BD_DIR_IN		(1 << 25)
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci#define BDC_PTC_MASK	0xf0000000
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/* status report defines */
2298c2ecf20Sopenharmony_ci#define SR_XSF		0
2308c2ecf20Sopenharmony_ci#define SR_USPC		4
2318c2ecf20Sopenharmony_ci#define SR_BD_LEN(p)    (p & 0xffffff)
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci#define XSF_SUCC	0x1
2348c2ecf20Sopenharmony_ci#define XSF_SHORT	0x3
2358c2ecf20Sopenharmony_ci#define XSF_BABB	0x4
2368c2ecf20Sopenharmony_ci#define XSF_SETUP_RECV	0x6
2378c2ecf20Sopenharmony_ci#define XSF_DATA_START	0x7
2388c2ecf20Sopenharmony_ci#define XSF_STATUS_START 0x8
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci#define XSF_STS(p) (((p) >> 28) & 0xf)
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci/* Transfer BD fields */
2438c2ecf20Sopenharmony_ci#define BD_LEN(p) ((p) & 0x1ffff)
2448c2ecf20Sopenharmony_ci#define BD_LTF		(1 << 25)
2458c2ecf20Sopenharmony_ci#define BD_TYPE_DS	0x1
2468c2ecf20Sopenharmony_ci#define BD_TYPE_SS	0x2
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci#define BDC_EP_ENABLED     (1 << 0)
2498c2ecf20Sopenharmony_ci#define BDC_EP_STALL       (1 << 1)
2508c2ecf20Sopenharmony_ci#define BDC_EP_STOP        (1 << 2)
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci/* One BD can transfer max 65536 bytes */
2538c2ecf20Sopenharmony_ci#define BD_MAX_BUFF_SIZE	(1 << 16)
2548c2ecf20Sopenharmony_ci/* Maximum bytes in one XFR, Refer to BDC spec */
2558c2ecf20Sopenharmony_ci#define MAX_XFR_LEN		16777215
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci/* defines for Force Header command */
2588c2ecf20Sopenharmony_ci#define DEV_NOTF_TYPE 6
2598c2ecf20Sopenharmony_ci#define FWK_SUBTYPE  1
2608c2ecf20Sopenharmony_ci#define TRA_PACKET   4
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci#define to_bdc_ep(e)		container_of(e, struct bdc_ep, usb_ep)
2638c2ecf20Sopenharmony_ci#define to_bdc_req(r)		container_of(r, struct bdc_req, usb_req)
2648c2ecf20Sopenharmony_ci#define gadget_to_bdc(g)	container_of(g, struct bdc, gadget)
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci/* FUNCTION WAKE DEV NOTIFICATION interval, USB3 spec table 8.13 */
2678c2ecf20Sopenharmony_ci#define BDC_TNOTIFY 2500 /*in ms*/
2688c2ecf20Sopenharmony_ci/* Devstatus bitfields */
2698c2ecf20Sopenharmony_ci#define REMOTE_WAKEUP_ISSUED	(1 << 16)
2708c2ecf20Sopenharmony_ci#define DEVICE_SUSPENDED	(1 << 17)
2718c2ecf20Sopenharmony_ci#define FUNC_WAKE_ISSUED	(1 << 18)
2728c2ecf20Sopenharmony_ci#define REMOTE_WAKE_ENABLE	(1 << USB_DEVICE_REMOTE_WAKEUP)
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci/* On disconnect, preserve these bits and clear rest */
2758c2ecf20Sopenharmony_ci#define DEVSTATUS_CLEAR		(1 << USB_DEVICE_SELF_POWERED)
2768c2ecf20Sopenharmony_ci/* Hardware and software Data structures */
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci/* Endpoint bd: buffer descriptor */
2798c2ecf20Sopenharmony_cistruct bdc_bd {
2808c2ecf20Sopenharmony_ci	__le32 offset[4];
2818c2ecf20Sopenharmony_ci};
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci/* Status report in Status report ring(srr) */
2848c2ecf20Sopenharmony_cistruct bdc_sr {
2858c2ecf20Sopenharmony_ci	__le32 offset[4];
2868c2ecf20Sopenharmony_ci};
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci/* bd_table: contiguous bd's in a table */
2898c2ecf20Sopenharmony_cistruct bd_table {
2908c2ecf20Sopenharmony_ci	struct bdc_bd *start_bd;
2918c2ecf20Sopenharmony_ci	/* dma address of start bd of table*/
2928c2ecf20Sopenharmony_ci	dma_addr_t dma;
2938c2ecf20Sopenharmony_ci};
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci/*
2968c2ecf20Sopenharmony_ci * Each endpoint has a bdl(buffer descriptor list), bdl consists of 1 or more bd
2978c2ecf20Sopenharmony_ci * table's chained to each other through a chain bd, every table has equal
2988c2ecf20Sopenharmony_ci * number of bds. the software uses bdi(bd index) to refer to particular bd in
2998c2ecf20Sopenharmony_ci * the list.
3008c2ecf20Sopenharmony_ci */
3018c2ecf20Sopenharmony_cistruct bd_list {
3028c2ecf20Sopenharmony_ci	/* Array of bd table pointers*/
3038c2ecf20Sopenharmony_ci	struct bd_table **bd_table_array;
3048c2ecf20Sopenharmony_ci	/* How many tables chained to each other */
3058c2ecf20Sopenharmony_ci	int num_tabs;
3068c2ecf20Sopenharmony_ci	/* Max_bdi = num_tabs * num_bds_table - 1 */
3078c2ecf20Sopenharmony_ci	int max_bdi;
3088c2ecf20Sopenharmony_ci	/* current enq bdi from sw point of view */
3098c2ecf20Sopenharmony_ci	int eqp_bdi;
3108c2ecf20Sopenharmony_ci	/* current deq bdi from sw point of view */
3118c2ecf20Sopenharmony_ci	int hwd_bdi;
3128c2ecf20Sopenharmony_ci	/* numbers of bds per table */
3138c2ecf20Sopenharmony_ci	int num_bds_table;
3148c2ecf20Sopenharmony_ci};
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_cistruct bdc_req;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/* Representation of a transfer, one transfer can have multiple bd's */
3198c2ecf20Sopenharmony_cistruct bd_transfer {
3208c2ecf20Sopenharmony_ci	struct bdc_req *req;
3218c2ecf20Sopenharmony_ci	/* start bd index */
3228c2ecf20Sopenharmony_ci	int start_bdi;
3238c2ecf20Sopenharmony_ci	/* this will be the next hw dqp when this transfer completes */
3248c2ecf20Sopenharmony_ci	int next_hwd_bdi;
3258c2ecf20Sopenharmony_ci	/* number of bds in this transfer */
3268c2ecf20Sopenharmony_ci	int num_bds;
3278c2ecf20Sopenharmony_ci};
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci/*
3308c2ecf20Sopenharmony_ci * Representation of a gadget request, every gadget request is contained
3318c2ecf20Sopenharmony_ci * by 1 bd_transfer.
3328c2ecf20Sopenharmony_ci */
3338c2ecf20Sopenharmony_cistruct bdc_req {
3348c2ecf20Sopenharmony_ci	struct usb_request	usb_req;
3358c2ecf20Sopenharmony_ci	struct list_head	queue;
3368c2ecf20Sopenharmony_ci	struct bdc_ep		*ep;
3378c2ecf20Sopenharmony_ci	/* only one Transfer per request */
3388c2ecf20Sopenharmony_ci	struct bd_transfer bd_xfr;
3398c2ecf20Sopenharmony_ci	int	epnum;
3408c2ecf20Sopenharmony_ci};
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci/* scratchpad buffer needed by bdc hardware */
3438c2ecf20Sopenharmony_cistruct bdc_scratchpad {
3448c2ecf20Sopenharmony_ci	dma_addr_t sp_dma;
3458c2ecf20Sopenharmony_ci	void *buff;
3468c2ecf20Sopenharmony_ci	u32 size;
3478c2ecf20Sopenharmony_ci};
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci/* endpoint representation */
3508c2ecf20Sopenharmony_cistruct bdc_ep {
3518c2ecf20Sopenharmony_ci	struct usb_ep	usb_ep;
3528c2ecf20Sopenharmony_ci	struct list_head queue;
3538c2ecf20Sopenharmony_ci	struct bdc *bdc;
3548c2ecf20Sopenharmony_ci	u8  ep_type;
3558c2ecf20Sopenharmony_ci	u8  dir;
3568c2ecf20Sopenharmony_ci	u8  ep_num;
3578c2ecf20Sopenharmony_ci	const struct usb_ss_ep_comp_descriptor	*comp_desc;
3588c2ecf20Sopenharmony_ci	const struct usb_endpoint_descriptor	*desc;
3598c2ecf20Sopenharmony_ci	unsigned int flags;
3608c2ecf20Sopenharmony_ci	char name[20];
3618c2ecf20Sopenharmony_ci	/* endpoint bd list*/
3628c2ecf20Sopenharmony_ci	struct bd_list bd_list;
3638c2ecf20Sopenharmony_ci	/*
3648c2ecf20Sopenharmony_ci	 * HW generates extra event for multi bd tranfers, this flag helps in
3658c2ecf20Sopenharmony_ci	 * ignoring the extra event
3668c2ecf20Sopenharmony_ci	 */
3678c2ecf20Sopenharmony_ci	bool ignore_next_sr;
3688c2ecf20Sopenharmony_ci};
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci/* bdc cmmand parameter structure */
3718c2ecf20Sopenharmony_cistruct bdc_cmd_params {
3728c2ecf20Sopenharmony_ci	u32	param2;
3738c2ecf20Sopenharmony_ci	u32	param1;
3748c2ecf20Sopenharmony_ci	u32	param0;
3758c2ecf20Sopenharmony_ci};
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci/* status report ring(srr), currently one srr is supported for entire system */
3788c2ecf20Sopenharmony_cistruct srr {
3798c2ecf20Sopenharmony_ci	struct bdc_sr *sr_bds;
3808c2ecf20Sopenharmony_ci	u16	eqp_index;
3818c2ecf20Sopenharmony_ci	u16	dqp_index;
3828c2ecf20Sopenharmony_ci	dma_addr_t	dma_addr;
3838c2ecf20Sopenharmony_ci};
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci/* EP0 states */
3868c2ecf20Sopenharmony_cienum bdc_ep0_state {
3878c2ecf20Sopenharmony_ci	WAIT_FOR_SETUP = 0,
3888c2ecf20Sopenharmony_ci	WAIT_FOR_DATA_START,
3898c2ecf20Sopenharmony_ci	WAIT_FOR_DATA_XMIT,
3908c2ecf20Sopenharmony_ci	WAIT_FOR_STATUS_START,
3918c2ecf20Sopenharmony_ci	WAIT_FOR_STATUS_XMIT,
3928c2ecf20Sopenharmony_ci	STATUS_PENDING
3938c2ecf20Sopenharmony_ci};
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci/* Link states */
3968c2ecf20Sopenharmony_cienum bdc_link_state {
3978c2ecf20Sopenharmony_ci	BDC_LINK_STATE_U0	= 0x00,
3988c2ecf20Sopenharmony_ci	BDC_LINK_STATE_U3	= 0x03,
3998c2ecf20Sopenharmony_ci	BDC_LINK_STATE_RX_DET	= 0x05,
4008c2ecf20Sopenharmony_ci	BDC_LINK_STATE_RESUME	= 0x0f
4018c2ecf20Sopenharmony_ci};
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci/* representation of bdc */
4048c2ecf20Sopenharmony_cistruct bdc {
4058c2ecf20Sopenharmony_ci	struct usb_gadget	gadget;
4068c2ecf20Sopenharmony_ci	struct usb_gadget_driver	*gadget_driver;
4078c2ecf20Sopenharmony_ci	struct device	*dev;
4088c2ecf20Sopenharmony_ci	/* device lock */
4098c2ecf20Sopenharmony_ci	spinlock_t	lock;
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	/* generic phy */
4128c2ecf20Sopenharmony_ci	struct phy      **phys;
4138c2ecf20Sopenharmony_ci	int num_phys;
4148c2ecf20Sopenharmony_ci	/* num of endpoints for a particular instantiation of IP */
4158c2ecf20Sopenharmony_ci	unsigned int num_eps;
4168c2ecf20Sopenharmony_ci	/*
4178c2ecf20Sopenharmony_ci	 * Array of ep's, it uses the same index covention as bdc hw i.e.
4188c2ecf20Sopenharmony_ci	 * 1 for ep0, 2 for 1out,3 for 1in ....
4198c2ecf20Sopenharmony_ci	 */
4208c2ecf20Sopenharmony_ci	struct bdc_ep		**bdc_ep_array;
4218c2ecf20Sopenharmony_ci	void __iomem		*regs;
4228c2ecf20Sopenharmony_ci	struct bdc_scratchpad	scratchpad;
4238c2ecf20Sopenharmony_ci	u32	sp_buff_size;
4248c2ecf20Sopenharmony_ci	/* current driver supports 1 status ring */
4258c2ecf20Sopenharmony_ci	struct srr	srr;
4268c2ecf20Sopenharmony_ci	/* Last received setup packet */
4278c2ecf20Sopenharmony_ci	struct	usb_ctrlrequest setup_pkt;
4288c2ecf20Sopenharmony_ci	struct	bdc_req ep0_req;
4298c2ecf20Sopenharmony_ci	struct	bdc_req status_req;
4308c2ecf20Sopenharmony_ci	enum	bdc_ep0_state ep0_state;
4318c2ecf20Sopenharmony_ci	bool	delayed_status;
4328c2ecf20Sopenharmony_ci	bool	zlp_needed;
4338c2ecf20Sopenharmony_ci	bool	reinit;
4348c2ecf20Sopenharmony_ci	bool	pullup;
4358c2ecf20Sopenharmony_ci	/* Bits 0-15 are standard and 16-31 for proprietary information */
4368c2ecf20Sopenharmony_ci	u32	devstatus;
4378c2ecf20Sopenharmony_ci	int	irq;
4388c2ecf20Sopenharmony_ci	void	*mem;
4398c2ecf20Sopenharmony_ci	u32	dev_addr;
4408c2ecf20Sopenharmony_ci	/* DMA pools */
4418c2ecf20Sopenharmony_ci	struct dma_pool	*bd_table_pool;
4428c2ecf20Sopenharmony_ci	u8		test_mode;
4438c2ecf20Sopenharmony_ci	/* array of callbacks for various status report handlers */
4448c2ecf20Sopenharmony_ci	void (*sr_handler[2])(struct bdc *, struct bdc_sr *);
4458c2ecf20Sopenharmony_ci	/* ep0 callback handlers */
4468c2ecf20Sopenharmony_ci	void (*sr_xsf_ep0[3])(struct bdc *, struct bdc_sr *);
4478c2ecf20Sopenharmony_ci	/* ep0 response buffer for ch9 requests like GET_STATUS and SET_SEL */
4488c2ecf20Sopenharmony_ci	unsigned char		ep0_response_buff[EP0_RESPONSE_BUFF];
4498c2ecf20Sopenharmony_ci	/*
4508c2ecf20Sopenharmony_ci	 * Timer to check if host resumed transfer after bdc sent Func wake
4518c2ecf20Sopenharmony_ci	 * notification  packet after a remote wakeup. if not, then resend the
4528c2ecf20Sopenharmony_ci	 * Func Wake packet every 2.5 secs. Refer to USB3 spec section 8.5.6.4
4538c2ecf20Sopenharmony_ci	 */
4548c2ecf20Sopenharmony_ci	struct delayed_work	func_wake_notify;
4558c2ecf20Sopenharmony_ci	struct clk		*clk;
4568c2ecf20Sopenharmony_ci};
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_cistatic inline u32 bdc_readl(void __iomem *base, u32 offset)
4598c2ecf20Sopenharmony_ci{
4608c2ecf20Sopenharmony_ci	return readl(base + offset);
4618c2ecf20Sopenharmony_ci}
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_cistatic inline void bdc_writel(void __iomem *base, u32 offset, u32 value)
4648c2ecf20Sopenharmony_ci{
4658c2ecf20Sopenharmony_ci	writel(value, base + offset);
4668c2ecf20Sopenharmony_ci}
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci/* Buffer descriptor list operations */
4698c2ecf20Sopenharmony_civoid bdc_notify_xfr(struct bdc *, u32);
4708c2ecf20Sopenharmony_civoid bdc_softconn(struct bdc *);
4718c2ecf20Sopenharmony_civoid bdc_softdisconn(struct bdc *);
4728c2ecf20Sopenharmony_ciint bdc_run(struct bdc *);
4738c2ecf20Sopenharmony_ciint bdc_stop(struct bdc *);
4748c2ecf20Sopenharmony_ciint bdc_reset(struct bdc *);
4758c2ecf20Sopenharmony_ciint bdc_udc_init(struct bdc *);
4768c2ecf20Sopenharmony_civoid bdc_udc_exit(struct bdc *);
4778c2ecf20Sopenharmony_ciint bdc_reinit(struct bdc *);
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci/* Status report handlers */
4808c2ecf20Sopenharmony_ci/* Upstream port status change sr */
4818c2ecf20Sopenharmony_civoid bdc_sr_uspc(struct bdc *, struct bdc_sr *);
4828c2ecf20Sopenharmony_ci/* transfer sr */
4838c2ecf20Sopenharmony_civoid bdc_sr_xsf(struct bdc *, struct bdc_sr *);
4848c2ecf20Sopenharmony_ci/* EP0 XSF handlers */
4858c2ecf20Sopenharmony_civoid bdc_xsf_ep0_setup_recv(struct bdc *, struct bdc_sr *);
4868c2ecf20Sopenharmony_civoid bdc_xsf_ep0_data_start(struct bdc *, struct bdc_sr *);
4878c2ecf20Sopenharmony_civoid bdc_xsf_ep0_status_start(struct bdc *, struct bdc_sr *);
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci#endif /* __LINUX_BDC_H__ */
490