162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * USBHS-DEV device controller driver header file
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2023 Cadence.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Author: Pawel Laszczak <pawell@cadence.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef __LINUX_CDNS2_GADGET
1162306a36Sopenharmony_ci#define __LINUX_CDNS2_GADGET
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <linux/usb/gadget.h>
1462306a36Sopenharmony_ci#include <linux/dma-direction.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/*
1762306a36Sopenharmony_ci * USBHS register interface.
1862306a36Sopenharmony_ci * This corresponds to the USBHS Device Controller Interface.
1962306a36Sopenharmony_ci */
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/**
2262306a36Sopenharmony_ci * struct cdns2_ep0_regs - endpoint 0 related registers.
2362306a36Sopenharmony_ci * @rxbc: receive (OUT) 0 endpoint byte count register.
2462306a36Sopenharmony_ci * @txbc: transmit (IN) 0 endpoint byte count register.
2562306a36Sopenharmony_ci * @cs: 0 endpoint control and status register.
2662306a36Sopenharmony_ci * @reserved1: reserved.
2762306a36Sopenharmony_ci * @fifo: 0 endpoint fifo register.
2862306a36Sopenharmony_ci * @reserved2: reserved.
2962306a36Sopenharmony_ci * @setupdat: SETUP data register.
3062306a36Sopenharmony_ci * @reserved4: reserved.
3162306a36Sopenharmony_ci * @maxpack: 0 endpoint max packet size.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_cistruct cdns2_ep0_regs {
3462306a36Sopenharmony_ci	__u8 rxbc;
3562306a36Sopenharmony_ci	__u8 txbc;
3662306a36Sopenharmony_ci	__u8 cs;
3762306a36Sopenharmony_ci	__u8 reserved1[4];
3862306a36Sopenharmony_ci	__u8 fifo;
3962306a36Sopenharmony_ci	__le32 reserved2[94];
4062306a36Sopenharmony_ci	__u8 setupdat[8];
4162306a36Sopenharmony_ci	__u8 reserved4[88];
4262306a36Sopenharmony_ci	__u8 maxpack;
4362306a36Sopenharmony_ci} __packed __aligned(4);
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/* EP0CS - bitmasks. */
4662306a36Sopenharmony_ci/* Endpoint 0 stall bit for status stage. */
4762306a36Sopenharmony_ci#define EP0CS_STALL	BIT(0)
4862306a36Sopenharmony_ci/* HSNAK bit. */
4962306a36Sopenharmony_ci#define EP0CS_HSNAK	BIT(1)
5062306a36Sopenharmony_ci/* IN 0 endpoint busy bit. */
5162306a36Sopenharmony_ci#define EP0CS_TXBSY_MSK	BIT(2)
5262306a36Sopenharmony_ci/* OUT 0 endpoint busy bit. */
5362306a36Sopenharmony_ci#define EP0CS_RXBSY_MSK	BIT(3)
5462306a36Sopenharmony_ci/* Send STALL in the data stage phase. */
5562306a36Sopenharmony_ci#define EP0CS_DSTALL	BIT(4)
5662306a36Sopenharmony_ci/* SETUP buffer content was changed. */
5762306a36Sopenharmony_ci#define EP0CS_CHGSET	BIT(7)
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci/* EP0FIFO - bitmasks. */
6062306a36Sopenharmony_ci/* Direction. */
6162306a36Sopenharmony_ci#define EP0_FIFO_IO_TX	BIT(4)
6262306a36Sopenharmony_ci/* FIFO auto bit. */
6362306a36Sopenharmony_ci#define EP0_FIFO_AUTO	BIT(5)
6462306a36Sopenharmony_ci/* FIFO commit bit. */
6562306a36Sopenharmony_ci#define EP0_FIFO_COMMIT	BIT(6)
6662306a36Sopenharmony_ci/* FIFO access bit. */
6762306a36Sopenharmony_ci#define EP0_FIFO_ACCES	BIT(7)
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/**
7062306a36Sopenharmony_ci * struct cdns2_epx_base - base endpoint registers.
7162306a36Sopenharmony_ci * @rxbc: OUT endpoint byte count register.
7262306a36Sopenharmony_ci * @rxcon: OUT endpoint control register.
7362306a36Sopenharmony_ci * @rxcs: OUT endpoint control and status register.
7462306a36Sopenharmony_ci * @txbc: IN endpoint byte count register.
7562306a36Sopenharmony_ci * @txcon: IN endpoint control register.
7662306a36Sopenharmony_ci * @txcs: IN endpoint control and status register.
7762306a36Sopenharmony_ci */
7862306a36Sopenharmony_cistruct cdns2_epx_base {
7962306a36Sopenharmony_ci	__le16 rxbc;
8062306a36Sopenharmony_ci	__u8 rxcon;
8162306a36Sopenharmony_ci	__u8 rxcs;
8262306a36Sopenharmony_ci	__le16 txbc;
8362306a36Sopenharmony_ci	__u8 txcon;
8462306a36Sopenharmony_ci	__u8 txcs;
8562306a36Sopenharmony_ci} __packed __aligned(4);
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/* rxcon/txcon - endpoint control register bitmasks. */
8862306a36Sopenharmony_ci/* Endpoint buffering: 0 - single buffering ... 3 - quad buffering. */
8962306a36Sopenharmony_ci#define EPX_CON_BUF		GENMASK(1, 0)
9062306a36Sopenharmony_ci/* Endpoint type. */
9162306a36Sopenharmony_ci#define EPX_CON_TYPE		GENMASK(3, 2)
9262306a36Sopenharmony_ci/* Endpoint type: isochronous. */
9362306a36Sopenharmony_ci#define EPX_CON_TYPE_ISOC	0x4
9462306a36Sopenharmony_ci/* Endpoint type: bulk. */
9562306a36Sopenharmony_ci#define EPX_CON_TYPE_BULK	0x8
9662306a36Sopenharmony_ci/* Endpoint type: interrupt. */
9762306a36Sopenharmony_ci#define EPX_CON_TYPE_INT	0xC
9862306a36Sopenharmony_ci/* Number of packets per microframe. */
9962306a36Sopenharmony_ci#define EPX_CON_ISOD		GENMASK(5, 4)
10062306a36Sopenharmony_ci#define EPX_CON_ISOD_SHIFT	0x4
10162306a36Sopenharmony_ci/* Endpoint stall bit. */
10262306a36Sopenharmony_ci#define EPX_CON_STALL		BIT(6)
10362306a36Sopenharmony_ci/* Endpoint enable bit.*/
10462306a36Sopenharmony_ci#define EPX_CON_VAL		BIT(7)
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/* rxcs/txcs - endpoint control and status bitmasks. */
10762306a36Sopenharmony_ci/* Data sequence error for the ISO endpoint. */
10862306a36Sopenharmony_ci#define EPX_CS_ERR(p)		((p) & BIT(0))
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci/**
11162306a36Sopenharmony_ci * struct cdns2_epx_regs - endpoint 1..15 related registers.
11262306a36Sopenharmony_ci * @reserved: reserved.
11362306a36Sopenharmony_ci * @ep: none control endpoints array.
11462306a36Sopenharmony_ci * @reserved2: reserved.
11562306a36Sopenharmony_ci * @endprst: endpoint reset register.
11662306a36Sopenharmony_ci * @reserved3: reserved.
11762306a36Sopenharmony_ci * @isoautoarm: ISO auto-arm register.
11862306a36Sopenharmony_ci * @reserved4: reserved.
11962306a36Sopenharmony_ci * @isodctrl: ISO control register.
12062306a36Sopenharmony_ci * @reserved5: reserved.
12162306a36Sopenharmony_ci * @isoautodump: ISO auto dump enable register.
12262306a36Sopenharmony_ci * @reserved6: reserved.
12362306a36Sopenharmony_ci * @rxmaxpack: receive (OUT) Max packet size register.
12462306a36Sopenharmony_ci * @reserved7: reserved.
12562306a36Sopenharmony_ci * @rxstaddr: receive (OUT) start address endpoint buffer register.
12662306a36Sopenharmony_ci * @reserved8: reserved.
12762306a36Sopenharmony_ci * @txstaddr: transmit (IN) start address endpoint buffer register.
12862306a36Sopenharmony_ci * @reserved9: reserved.
12962306a36Sopenharmony_ci * @txmaxpack: transmit (IN) Max packet size register.
13062306a36Sopenharmony_ci */
13162306a36Sopenharmony_cistruct cdns2_epx_regs {
13262306a36Sopenharmony_ci	__le32 reserved[2];
13362306a36Sopenharmony_ci	struct cdns2_epx_base ep[15];
13462306a36Sopenharmony_ci	__u8 reserved2[290];
13562306a36Sopenharmony_ci	__u8 endprst;
13662306a36Sopenharmony_ci	__u8 reserved3[41];
13762306a36Sopenharmony_ci	__le16 isoautoarm;
13862306a36Sopenharmony_ci	__u8 reserved4[10];
13962306a36Sopenharmony_ci	__le16 isodctrl;
14062306a36Sopenharmony_ci	__le16 reserved5;
14162306a36Sopenharmony_ci	__le16 isoautodump;
14262306a36Sopenharmony_ci	__le32 reserved6;
14362306a36Sopenharmony_ci	__le16 rxmaxpack[15];
14462306a36Sopenharmony_ci	__le32 reserved7[65];
14562306a36Sopenharmony_ci	__le32 rxstaddr[15];
14662306a36Sopenharmony_ci	__u8 reserved8[4];
14762306a36Sopenharmony_ci	__le32 txstaddr[15];
14862306a36Sopenharmony_ci	__u8 reserved9[98];
14962306a36Sopenharmony_ci	__le16 txmaxpack[15];
15062306a36Sopenharmony_ci} __packed __aligned(4);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/* ENDPRST - bitmasks. */
15362306a36Sopenharmony_ci/* Endpoint number. */
15462306a36Sopenharmony_ci#define ENDPRST_EP	GENMASK(3, 0)
15562306a36Sopenharmony_ci/* IN direction bit. */
15662306a36Sopenharmony_ci#define ENDPRST_IO_TX	BIT(4)
15762306a36Sopenharmony_ci/* Toggle reset bit. */
15862306a36Sopenharmony_ci#define ENDPRST_TOGRST	BIT(5)
15962306a36Sopenharmony_ci/* FIFO reset bit. */
16062306a36Sopenharmony_ci#define ENDPRST_FIFORST	BIT(6)
16162306a36Sopenharmony_ci/* Toggle status and reset bit. */
16262306a36Sopenharmony_ci#define ENDPRST_TOGSETQ	BIT(7)
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci/**
16562306a36Sopenharmony_ci * struct cdns2_interrupt_regs - USB interrupt related registers.
16662306a36Sopenharmony_ci * @reserved: reserved.
16762306a36Sopenharmony_ci * @usbirq: USB interrupt request register.
16862306a36Sopenharmony_ci * @extirq: external interrupt request register.
16962306a36Sopenharmony_ci * @rxpngirq: external interrupt request register.
17062306a36Sopenharmony_ci * @reserved1: reserved.
17162306a36Sopenharmony_ci * @usbien: USB interrupt enable register.
17262306a36Sopenharmony_ci * @extien: external interrupt enable register.
17362306a36Sopenharmony_ci * @reserved2: reserved.
17462306a36Sopenharmony_ci * @usbivect: USB interrupt vector register.
17562306a36Sopenharmony_ci */
17662306a36Sopenharmony_cistruct cdns2_interrupt_regs {
17762306a36Sopenharmony_ci	__u8 reserved[396];
17862306a36Sopenharmony_ci	__u8 usbirq;
17962306a36Sopenharmony_ci	__u8 extirq;
18062306a36Sopenharmony_ci	__le16 rxpngirq;
18162306a36Sopenharmony_ci	__le16 reserved1[4];
18262306a36Sopenharmony_ci	__u8 usbien;
18362306a36Sopenharmony_ci	__u8 extien;
18462306a36Sopenharmony_ci	__le16 reserved2[3];
18562306a36Sopenharmony_ci	__u8 usbivect;
18662306a36Sopenharmony_ci} __packed __aligned(4);
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci/* EXTIRQ and EXTIEN - bitmasks. */
18962306a36Sopenharmony_ci/* VBUS fault fall interrupt. */
19062306a36Sopenharmony_ci#define EXTIRQ_VBUSFAULT_FALL BIT(0)
19162306a36Sopenharmony_ci/* VBUS fault fall interrupt. */
19262306a36Sopenharmony_ci#define EXTIRQ_VBUSFAULT_RISE BIT(1)
19362306a36Sopenharmony_ci/* Wake up interrupt bit. */
19462306a36Sopenharmony_ci#define EXTIRQ_WAKEUP	BIT(7)
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci/* USBIEN and USBIRQ - bitmasks. */
19762306a36Sopenharmony_ci/* SETUP data valid interrupt bit.*/
19862306a36Sopenharmony_ci#define USBIRQ_SUDAV	BIT(0)
19962306a36Sopenharmony_ci/* Start-of-frame interrupt bit. */
20062306a36Sopenharmony_ci#define USBIRQ_SOF	BIT(1)
20162306a36Sopenharmony_ci/* SETUP token interrupt bit. */
20262306a36Sopenharmony_ci#define USBIRQ_SUTOK	BIT(2)
20362306a36Sopenharmony_ci/* USB suspend interrupt bit. */
20462306a36Sopenharmony_ci#define USBIRQ_SUSPEND	BIT(3)
20562306a36Sopenharmony_ci/* USB reset interrupt bit. */
20662306a36Sopenharmony_ci#define USBIRQ_URESET	BIT(4)
20762306a36Sopenharmony_ci/* USB high-speed mode interrupt bit. */
20862306a36Sopenharmony_ci#define USBIRQ_HSPEED	BIT(5)
20962306a36Sopenharmony_ci/* Link Power Management interrupt bit. */
21062306a36Sopenharmony_ci#define USBIRQ_LPM	BIT(7)
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci#define USB_IEN_INIT (USBIRQ_SUDAV | USBIRQ_SUSPEND | USBIRQ_URESET \
21362306a36Sopenharmony_ci		      | USBIRQ_HSPEED | USBIRQ_LPM)
21462306a36Sopenharmony_ci/**
21562306a36Sopenharmony_ci * struct cdns2_usb_regs - USB controller registers.
21662306a36Sopenharmony_ci * @reserved: reserved.
21762306a36Sopenharmony_ci * @lpmctrl: LPM control register.
21862306a36Sopenharmony_ci * @lpmclock: LPM clock register.
21962306a36Sopenharmony_ci * @reserved2: reserved.
22062306a36Sopenharmony_ci * @endprst: endpoint reset register.
22162306a36Sopenharmony_ci * @usbcs: USB control and status register.
22262306a36Sopenharmony_ci * @frmnr: USB frame counter register.
22362306a36Sopenharmony_ci * @fnaddr: function Address register.
22462306a36Sopenharmony_ci * @clkgate: clock gate register.
22562306a36Sopenharmony_ci * @fifoctrl: FIFO control register.
22662306a36Sopenharmony_ci * @speedctrl: speed Control register.
22762306a36Sopenharmony_ci * @sleep_clkgate: sleep Clock Gate register.
22862306a36Sopenharmony_ci * @reserved3: reserved.
22962306a36Sopenharmony_ci * @cpuctrl: microprocessor control register.
23062306a36Sopenharmony_ci */
23162306a36Sopenharmony_cistruct cdns2_usb_regs {
23262306a36Sopenharmony_ci	__u8 reserved[4];
23362306a36Sopenharmony_ci	__u16 lpmctrl;
23462306a36Sopenharmony_ci	__u8 lpmclock;
23562306a36Sopenharmony_ci	__u8 reserved2[411];
23662306a36Sopenharmony_ci	__u8 endprst;
23762306a36Sopenharmony_ci	__u8 usbcs;
23862306a36Sopenharmony_ci	__le16 frmnr;
23962306a36Sopenharmony_ci	__u8 fnaddr;
24062306a36Sopenharmony_ci	__u8 clkgate;
24162306a36Sopenharmony_ci	__u8 fifoctrl;
24262306a36Sopenharmony_ci	__u8 speedctrl;
24362306a36Sopenharmony_ci	__u8 sleep_clkgate;
24462306a36Sopenharmony_ci	__u8 reserved3[533];
24562306a36Sopenharmony_ci	__u8 cpuctrl;
24662306a36Sopenharmony_ci} __packed __aligned(4);
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci/* LPMCTRL - bitmasks. */
24962306a36Sopenharmony_ci/* BESL (Best Effort Service Latency). */
25062306a36Sopenharmony_ci#define LPMCTRLLL_HIRD		GENMASK(7, 4)
25162306a36Sopenharmony_ci/* Last received Remote Wakeup field from LPM Extended Token packet. */
25262306a36Sopenharmony_ci#define LPMCTRLLH_BREMOTEWAKEUP	BIT(8)
25362306a36Sopenharmony_ci/* Reflects value of the lpmnyet bit located in the usbcs[1] register. */
25462306a36Sopenharmony_ci#define LPMCTRLLH_LPMNYET	BIT(16)
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci/* LPMCLOCK - bitmasks. */
25762306a36Sopenharmony_ci/*
25862306a36Sopenharmony_ci * If bit is 1 the controller automatically turns off clock
25962306a36Sopenharmony_ci * (utmisleepm goes to low), else the microprocessor should use
26062306a36Sopenharmony_ci * sleep clock gate register to turn off clock.
26162306a36Sopenharmony_ci */
26262306a36Sopenharmony_ci#define LPMCLOCK_SLEEP_ENTRY	BIT(7)
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci/* USBCS - bitmasks. */
26562306a36Sopenharmony_ci/* Send NYET handshake for the LPM transaction. */
26662306a36Sopenharmony_ci#define USBCS_LPMNYET		BIT(2)
26762306a36Sopenharmony_ci/* Remote wake-up bit. */
26862306a36Sopenharmony_ci#define USBCS_SIGRSUME		BIT(5)
26962306a36Sopenharmony_ci/* Software disconnect bit. */
27062306a36Sopenharmony_ci#define USBCS_DISCON		BIT(6)
27162306a36Sopenharmony_ci/* Indicates that a wakeup pin resumed the controller. */
27262306a36Sopenharmony_ci#define USBCS_WAKESRC		BIT(7)
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci/* FIFOCTRL - bitmasks. */
27562306a36Sopenharmony_ci/* Endpoint number. */
27662306a36Sopenharmony_ci#define FIFOCTRL_EP		GENMASK(3, 0)
27762306a36Sopenharmony_ci/* Direction bit. */
27862306a36Sopenharmony_ci#define FIFOCTRL_IO_TX		BIT(4)
27962306a36Sopenharmony_ci/* FIFO auto bit. */
28062306a36Sopenharmony_ci#define FIFOCTRL_FIFOAUTO	BIT(5)
28162306a36Sopenharmony_ci/* FIFO commit bit. */
28262306a36Sopenharmony_ci#define FIFOCTRL_FIFOCMIT	BIT(6)
28362306a36Sopenharmony_ci/* FIFO access bit. */
28462306a36Sopenharmony_ci#define FIFOCTRL_FIFOACC	BIT(7)
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ci/* SPEEDCTRL - bitmasks. */
28762306a36Sopenharmony_ci/* Device works in Full Speed. */
28862306a36Sopenharmony_ci#define SPEEDCTRL_FS		BIT(1)
28962306a36Sopenharmony_ci/* Device works in High Speed. */
29062306a36Sopenharmony_ci#define SPEEDCTRL_HS		BIT(2)
29162306a36Sopenharmony_ci/* Force FS mode. */
29262306a36Sopenharmony_ci#define SPEEDCTRL_HSDISABLE	BIT(7)
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ci/* CPUCTRL- bitmasks. */
29562306a36Sopenharmony_ci/* Controller reset bit. */
29662306a36Sopenharmony_ci#define CPUCTRL_SW_RST		BIT(1)
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci/**
29962306a36Sopenharmony_ci * struct cdns2_adma_regs - ADMA controller registers.
30062306a36Sopenharmony_ci * @conf: DMA global configuration register.
30162306a36Sopenharmony_ci * @sts: DMA global Status register.
30262306a36Sopenharmony_ci * @reserved1: reserved.
30362306a36Sopenharmony_ci * @ep_sel: DMA endpoint select register.
30462306a36Sopenharmony_ci * @ep_traddr: DMA endpoint transfer ring address register.
30562306a36Sopenharmony_ci * @ep_cfg: DMA endpoint configuration register.
30662306a36Sopenharmony_ci * @ep_cmd: DMA endpoint command register.
30762306a36Sopenharmony_ci * @ep_sts: DMA endpoint status register.
30862306a36Sopenharmony_ci * @reserved2: reserved.
30962306a36Sopenharmony_ci * @ep_sts_en: DMA endpoint status enable register.
31062306a36Sopenharmony_ci * @drbl: DMA doorbell register.
31162306a36Sopenharmony_ci * @ep_ien: DMA endpoint interrupt enable register.
31262306a36Sopenharmony_ci * @ep_ists: DMA endpoint interrupt status register.
31362306a36Sopenharmony_ci * @axim_ctrl: AXI Master Control register.
31462306a36Sopenharmony_ci * @axim_id: AXI Master ID register.
31562306a36Sopenharmony_ci * @reserved3: reserved.
31662306a36Sopenharmony_ci * @axim_cap: AXI Master Wrapper Extended Capability.
31762306a36Sopenharmony_ci * @reserved4: reserved.
31862306a36Sopenharmony_ci * @axim_ctrl0: AXI Master Wrapper Extended Capability Control Register 0.
31962306a36Sopenharmony_ci * @axim_ctrl1: AXI Master Wrapper Extended Capability Control Register 1.
32062306a36Sopenharmony_ci */
32162306a36Sopenharmony_cistruct cdns2_adma_regs {
32262306a36Sopenharmony_ci	__le32 conf;
32362306a36Sopenharmony_ci	__le32 sts;
32462306a36Sopenharmony_ci	__le32 reserved1[5];
32562306a36Sopenharmony_ci	__le32 ep_sel;
32662306a36Sopenharmony_ci	__le32 ep_traddr;
32762306a36Sopenharmony_ci	__le32 ep_cfg;
32862306a36Sopenharmony_ci	__le32 ep_cmd;
32962306a36Sopenharmony_ci	__le32 ep_sts;
33062306a36Sopenharmony_ci	__le32 reserved2;
33162306a36Sopenharmony_ci	__le32 ep_sts_en;
33262306a36Sopenharmony_ci	__le32 drbl;
33362306a36Sopenharmony_ci	__le32 ep_ien;
33462306a36Sopenharmony_ci	__le32 ep_ists;
33562306a36Sopenharmony_ci	__le32 axim_ctrl;
33662306a36Sopenharmony_ci	__le32 axim_id;
33762306a36Sopenharmony_ci	__le32 reserved3;
33862306a36Sopenharmony_ci	__le32 axim_cap;
33962306a36Sopenharmony_ci	__le32 reserved4;
34062306a36Sopenharmony_ci	__le32 axim_ctrl0;
34162306a36Sopenharmony_ci	__le32 axim_ctrl1;
34262306a36Sopenharmony_ci};
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ci#define CDNS2_ADMA_REGS_OFFSET	0x400
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ci/* DMA_CONF - bitmasks. */
34762306a36Sopenharmony_ci/* Reset USB device configuration. */
34862306a36Sopenharmony_ci#define DMA_CONF_CFGRST		BIT(0)
34962306a36Sopenharmony_ci/* Singular DMA transfer mode.*/
35062306a36Sopenharmony_ci#define DMA_CONF_DSING		BIT(8)
35162306a36Sopenharmony_ci/* Multiple DMA transfers mode.*/
35262306a36Sopenharmony_ci#define DMA_CONF_DMULT		BIT(9)
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci/* DMA_EP_CFG - bitmasks. */
35562306a36Sopenharmony_ci/* Endpoint enable. */
35662306a36Sopenharmony_ci#define DMA_EP_CFG_ENABLE	BIT(0)
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_ci/* DMA_EP_CMD - bitmasks. */
35962306a36Sopenharmony_ci/* Endpoint reset. */
36062306a36Sopenharmony_ci#define DMA_EP_CMD_EPRST	BIT(0)
36162306a36Sopenharmony_ci/* Transfer descriptor ready. */
36262306a36Sopenharmony_ci#define DMA_EP_CMD_DRDY		BIT(6)
36362306a36Sopenharmony_ci/* Data flush. */
36462306a36Sopenharmony_ci#define DMA_EP_CMD_DFLUSH	BIT(7)
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_ci/* DMA_EP_STS - bitmasks. */
36762306a36Sopenharmony_ci/* Interrupt On Complete. */
36862306a36Sopenharmony_ci#define DMA_EP_STS_IOC		BIT(2)
36962306a36Sopenharmony_ci/* Interrupt on Short Packet. */
37062306a36Sopenharmony_ci#define DMA_EP_STS_ISP		BIT(3)
37162306a36Sopenharmony_ci/* Transfer descriptor missing. */
37262306a36Sopenharmony_ci#define DMA_EP_STS_DESCMIS	BIT(4)
37362306a36Sopenharmony_ci/* TRB error. */
37462306a36Sopenharmony_ci#define DMA_EP_STS_TRBERR	BIT(7)
37562306a36Sopenharmony_ci/* DMA busy bit. */
37662306a36Sopenharmony_ci#define DMA_EP_STS_DBUSY	BIT(9)
37762306a36Sopenharmony_ci/* Current Cycle Status. */
37862306a36Sopenharmony_ci#define DMA_EP_STS_CCS(p)	((p) & BIT(11))
37962306a36Sopenharmony_ci/* OUT size mismatch. */
38062306a36Sopenharmony_ci#define DMA_EP_STS_OUTSMM	BIT(14)
38162306a36Sopenharmony_ci/* ISO transmission error. */
38262306a36Sopenharmony_ci#define DMA_EP_STS_ISOERR	BIT(15)
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_ci/* DMA_EP_STS_EN - bitmasks. */
38562306a36Sopenharmony_ci/* OUT transfer missing descriptor enable. */
38662306a36Sopenharmony_ci#define DMA_EP_STS_EN_DESCMISEN	BIT(4)
38762306a36Sopenharmony_ci/* TRB enable. */
38862306a36Sopenharmony_ci#define DMA_EP_STS_EN_TRBERREN	BIT(7)
38962306a36Sopenharmony_ci/* OUT size mismatch enable. */
39062306a36Sopenharmony_ci#define DMA_EP_STS_EN_OUTSMMEN	BIT(14)
39162306a36Sopenharmony_ci/* ISO transmission error enable. */
39262306a36Sopenharmony_ci#define DMA_EP_STS_EN_ISOERREN	BIT(15)
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci/* DMA_EP_IEN - bitmasks. */
39562306a36Sopenharmony_ci#define DMA_EP_IEN(index)	(1 << (index))
39662306a36Sopenharmony_ci#define DMA_EP_IEN_EP_OUT0	BIT(0)
39762306a36Sopenharmony_ci#define DMA_EP_IEN_EP_IN0	BIT(16)
39862306a36Sopenharmony_ci
39962306a36Sopenharmony_ci/* DMA_EP_ISTS - bitmasks. */
40062306a36Sopenharmony_ci#define DMA_EP_ISTS(index)	(1 << (index))
40162306a36Sopenharmony_ci#define DMA_EP_ISTS_EP_OUT0	BIT(0)
40262306a36Sopenharmony_ci#define DMA_EP_ISTS_EP_IN0	BIT(16)
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_ci#define gadget_to_cdns2_device(g) (container_of(g, struct cdns2_device, gadget))
40562306a36Sopenharmony_ci#define ep_to_cdns2_ep(ep) (container_of(ep, struct cdns2_endpoint, endpoint))
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/
40862306a36Sopenharmony_ci#define TRBS_PER_SEGMENT	600
40962306a36Sopenharmony_ci#define ISO_MAX_INTERVAL	8
41062306a36Sopenharmony_ci#define MAX_TRB_LENGTH		BIT(16)
41162306a36Sopenharmony_ci#define MAX_ISO_SIZE		3076
41262306a36Sopenharmony_ci/*
41362306a36Sopenharmony_ci * To improve performance the TRB buffer pointers can't cross
41462306a36Sopenharmony_ci * 4KB boundaries.
41562306a36Sopenharmony_ci */
41662306a36Sopenharmony_ci#define TRB_MAX_ISO_BUFF_SHIFT	12
41762306a36Sopenharmony_ci#define TRB_MAX_ISO_BUFF_SIZE	BIT(TRB_MAX_ISO_BUFF_SHIFT)
41862306a36Sopenharmony_ci/* How much data is left before the 4KB boundary? */
41962306a36Sopenharmony_ci#define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_ISO_BUFF_SIZE - \
42062306a36Sopenharmony_ci					((addr) & (TRB_MAX_ISO_BUFF_SIZE - 1)))
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci#if TRBS_PER_SEGMENT < 2
42362306a36Sopenharmony_ci#error "Incorrect TRBS_PER_SEGMENT. Minimal Transfer Ring size is 2."
42462306a36Sopenharmony_ci#endif
42562306a36Sopenharmony_ci
42662306a36Sopenharmony_ci/**
42762306a36Sopenharmony_ci * struct cdns2_trb - represent Transfer Descriptor block.
42862306a36Sopenharmony_ci * @buffer: pointer to buffer data.
42962306a36Sopenharmony_ci * @length: length of data.
43062306a36Sopenharmony_ci * @control: control flags.
43162306a36Sopenharmony_ci *
43262306a36Sopenharmony_ci * This structure describes transfer block handled by DMA module.
43362306a36Sopenharmony_ci */
43462306a36Sopenharmony_cistruct cdns2_trb {
43562306a36Sopenharmony_ci	__le32 buffer;
43662306a36Sopenharmony_ci	__le32 length;
43762306a36Sopenharmony_ci	__le32 control;
43862306a36Sopenharmony_ci};
43962306a36Sopenharmony_ci
44062306a36Sopenharmony_ci#define TRB_SIZE		(sizeof(struct cdns2_trb))
44162306a36Sopenharmony_ci/*
44262306a36Sopenharmony_ci * These two extra TRBs are reserved for isochronous transfer
44362306a36Sopenharmony_ci * to inject 0 length packet and extra LINK TRB to synchronize the ISO transfer.
44462306a36Sopenharmony_ci */
44562306a36Sopenharmony_ci#define TRB_ISO_RESERVED	2
44662306a36Sopenharmony_ci#define TR_SEG_SIZE		(TRB_SIZE * (TRBS_PER_SEGMENT + TRB_ISO_RESERVED))
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci/* TRB bit mask. */
44962306a36Sopenharmony_ci#define TRB_TYPE_BITMASK	GENMASK(15, 10)
45062306a36Sopenharmony_ci#define TRB_TYPE(p)		((p) << 10)
45162306a36Sopenharmony_ci#define TRB_FIELD_TO_TYPE(p)	(((p) & TRB_TYPE_BITMASK) >> 10)
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci/* TRB type IDs. */
45462306a36Sopenharmony_ci/* Used for Bulk, Interrupt, ISOC, and control data stage. */
45562306a36Sopenharmony_ci#define TRB_NORMAL		1
45662306a36Sopenharmony_ci/* TRB for linking ring segments. */
45762306a36Sopenharmony_ci#define TRB_LINK		6
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ci/* Cycle bit - indicates TRB ownership by driver or hw. */
46062306a36Sopenharmony_ci#define TRB_CYCLE		BIT(0)
46162306a36Sopenharmony_ci/*
46262306a36Sopenharmony_ci * When set to '1', the device will toggle its interpretation of the Cycle bit.
46362306a36Sopenharmony_ci */
46462306a36Sopenharmony_ci#define TRB_TOGGLE		BIT(1)
46562306a36Sopenharmony_ci/* Interrupt on short packet. */
46662306a36Sopenharmony_ci#define TRB_ISP			BIT(2)
46762306a36Sopenharmony_ci/* Chain bit associate this TRB with next one TRB. */
46862306a36Sopenharmony_ci#define TRB_CHAIN		BIT(4)
46962306a36Sopenharmony_ci/* Interrupt on completion. */
47062306a36Sopenharmony_ci#define TRB_IOC			BIT(5)
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_ci/* Transfer_len bitmasks. */
47362306a36Sopenharmony_ci#define TRB_LEN(p)		((p) & GENMASK(16, 0))
47462306a36Sopenharmony_ci#define TRB_BURST(p)		(((p) << 24) & GENMASK(31, 24))
47562306a36Sopenharmony_ci#define TRB_FIELD_TO_BURST(p)	(((p) & GENMASK(31, 24)) >> 24)
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_ci/* Data buffer pointer bitmasks. */
47862306a36Sopenharmony_ci#define TRB_BUFFER(p)		((p) & GENMASK(31, 0))
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/
48162306a36Sopenharmony_ci/* Driver numeric constants. */
48262306a36Sopenharmony_ci
48362306a36Sopenharmony_ci/* Maximum address that can be assigned to device. */
48462306a36Sopenharmony_ci#define USB_DEVICE_MAX_ADDRESS	127
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci/* One control and 15 IN and 15 OUT endpoints. */
48762306a36Sopenharmony_ci#define CDNS2_ENDPOINTS_NUM	31
48862306a36Sopenharmony_ci
48962306a36Sopenharmony_ci#define CDNS2_EP_ZLP_BUF_SIZE	512
49062306a36Sopenharmony_ci
49162306a36Sopenharmony_ci/*-------------------------------------------------------------------------*/
49262306a36Sopenharmony_ci/* Used structures. */
49362306a36Sopenharmony_ci
49462306a36Sopenharmony_cistruct cdns2_device;
49562306a36Sopenharmony_ci
49662306a36Sopenharmony_ci/**
49762306a36Sopenharmony_ci * struct cdns2_ring - transfer ring representation.
49862306a36Sopenharmony_ci * @trbs: pointer to transfer ring.
49962306a36Sopenharmony_ci * @dma: dma address of transfer ring.
50062306a36Sopenharmony_ci * @free_trbs: number of free TRBs in transfer ring.
50162306a36Sopenharmony_ci * @pcs: producer cycle state.
50262306a36Sopenharmony_ci * @ccs: consumer cycle state.
50362306a36Sopenharmony_ci * @enqueue: enqueue index in transfer ring.
50462306a36Sopenharmony_ci * @dequeue: dequeue index in transfer ring.
50562306a36Sopenharmony_ci */
50662306a36Sopenharmony_cistruct cdns2_ring {
50762306a36Sopenharmony_ci	struct cdns2_trb *trbs;
50862306a36Sopenharmony_ci	dma_addr_t dma;
50962306a36Sopenharmony_ci	int free_trbs;
51062306a36Sopenharmony_ci	u8 pcs;
51162306a36Sopenharmony_ci	u8 ccs;
51262306a36Sopenharmony_ci	int enqueue;
51362306a36Sopenharmony_ci	int dequeue;
51462306a36Sopenharmony_ci};
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_ci/**
51762306a36Sopenharmony_ci * struct cdns2_endpoint - extended device side representation of USB endpoint.
51862306a36Sopenharmony_ci * @endpoint: usb endpoint.
51962306a36Sopenharmony_ci * @pending_list: list of requests queuing on transfer ring.
52062306a36Sopenharmony_ci * @deferred_list: list of requests waiting for queuing on transfer ring.
52162306a36Sopenharmony_ci * @pdev: device associated with endpoint.
52262306a36Sopenharmony_ci * @name: a human readable name e.g. ep1out.
52362306a36Sopenharmony_ci * @ring: transfer ring associated with endpoint.
52462306a36Sopenharmony_ci * @ep_state: state of endpoint.
52562306a36Sopenharmony_ci * @idx: index of endpoint in pdev->eps table.
52662306a36Sopenharmony_ci * @dir: endpoint direction.
52762306a36Sopenharmony_ci * @num: endpoint number (1 - 15).
52862306a36Sopenharmony_ci * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK.
52962306a36Sopenharmony_ci * @interval: interval between packets used for ISOC and Interrupt endpoint.
53062306a36Sopenharmony_ci * @buffering: on-chip buffers assigned to endpoint.
53162306a36Sopenharmony_ci * @trb_burst_size: number of burst used in TRB.
53262306a36Sopenharmony_ci * @skip: Sometimes the controller cannot process isochronous endpoint ring
53362306a36Sopenharmony_ci *        quickly enough and it will miss some isoc tds on the ring and
53462306a36Sopenharmony_ci *        generate ISO transmition error.
53562306a36Sopenharmony_ci *        Driver sets skip flag when receive a ISO transmition error and
53662306a36Sopenharmony_ci *        process the missed TDs on the endpoint ring.
53762306a36Sopenharmony_ci * @wa1_set: use WA1.
53862306a36Sopenharmony_ci * @wa1_trb: TRB assigned to WA1.
53962306a36Sopenharmony_ci * @wa1_trb_index: TRB index for WA1.
54062306a36Sopenharmony_ci * @wa1_cycle_bit: correct cycle bit for WA1.
54162306a36Sopenharmony_ci */
54262306a36Sopenharmony_cistruct cdns2_endpoint {
54362306a36Sopenharmony_ci	struct usb_ep endpoint;
54462306a36Sopenharmony_ci	struct list_head pending_list;
54562306a36Sopenharmony_ci	struct list_head deferred_list;
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ci	struct cdns2_device	*pdev;
54862306a36Sopenharmony_ci	char name[20];
54962306a36Sopenharmony_ci
55062306a36Sopenharmony_ci	struct cdns2_ring ring;
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_ci#define EP_ENABLED		BIT(0)
55362306a36Sopenharmony_ci#define EP_STALLED		BIT(1)
55462306a36Sopenharmony_ci#define EP_STALL_PENDING	BIT(2)
55562306a36Sopenharmony_ci#define EP_WEDGE		BIT(3)
55662306a36Sopenharmony_ci#define	EP_CLAIMED		BIT(4)
55762306a36Sopenharmony_ci#define EP_RING_FULL		BIT(5)
55862306a36Sopenharmony_ci#define EP_DEFERRED_DRDY	BIT(6)
55962306a36Sopenharmony_ci
56062306a36Sopenharmony_ci	u32 ep_state;
56162306a36Sopenharmony_ci
56262306a36Sopenharmony_ci	u8 idx;
56362306a36Sopenharmony_ci	u8 dir;
56462306a36Sopenharmony_ci	u8 num;
56562306a36Sopenharmony_ci	u8 type;
56662306a36Sopenharmony_ci	int interval;
56762306a36Sopenharmony_ci	u8 buffering;
56862306a36Sopenharmony_ci	u8 trb_burst_size;
56962306a36Sopenharmony_ci	bool skip;
57062306a36Sopenharmony_ci
57162306a36Sopenharmony_ci	unsigned int wa1_set:1;
57262306a36Sopenharmony_ci	struct cdns2_trb *wa1_trb;
57362306a36Sopenharmony_ci	unsigned int wa1_trb_index;
57462306a36Sopenharmony_ci	unsigned int wa1_cycle_bit:1;
57562306a36Sopenharmony_ci};
57662306a36Sopenharmony_ci
57762306a36Sopenharmony_ci/**
57862306a36Sopenharmony_ci * struct cdns2_request - extended device side representation of usb_request
57962306a36Sopenharmony_ci *                        object.
58062306a36Sopenharmony_ci * @request: generic usb_request object describing single I/O request.
58162306a36Sopenharmony_ci * @pep: extended representation of usb_ep object.
58262306a36Sopenharmony_ci * @trb: the first TRB association with this request.
58362306a36Sopenharmony_ci * @start_trb: number of the first TRB in transfer ring.
58462306a36Sopenharmony_ci * @end_trb: number of the last TRB in transfer ring.
58562306a36Sopenharmony_ci * @list: used for queuing request in lists.
58662306a36Sopenharmony_ci * @finished_trb: number of trb has already finished per request.
58762306a36Sopenharmony_ci * @num_of_trb: how many trbs are associated with request.
58862306a36Sopenharmony_ci */
58962306a36Sopenharmony_cistruct cdns2_request {
59062306a36Sopenharmony_ci	struct usb_request request;
59162306a36Sopenharmony_ci	struct cdns2_endpoint *pep;
59262306a36Sopenharmony_ci	struct cdns2_trb *trb;
59362306a36Sopenharmony_ci	int start_trb;
59462306a36Sopenharmony_ci	int end_trb;
59562306a36Sopenharmony_ci	struct list_head list;
59662306a36Sopenharmony_ci	int finished_trb;
59762306a36Sopenharmony_ci	int num_of_trb;
59862306a36Sopenharmony_ci};
59962306a36Sopenharmony_ci
60062306a36Sopenharmony_ci#define to_cdns2_request(r) (container_of(r, struct cdns2_request, request))
60162306a36Sopenharmony_ci
60262306a36Sopenharmony_ci/* Stages used during enumeration process.*/
60362306a36Sopenharmony_ci#define CDNS2_SETUP_STAGE		0x0
60462306a36Sopenharmony_ci#define CDNS2_DATA_STAGE		0x1
60562306a36Sopenharmony_ci#define CDNS2_STATUS_STAGE		0x2
60662306a36Sopenharmony_ci
60762306a36Sopenharmony_ci/**
60862306a36Sopenharmony_ci * struct cdns2_device - represent USB device.
60962306a36Sopenharmony_ci * @dev: pointer to device structure associated whit this controller.
61062306a36Sopenharmony_ci * @gadget: device side representation of the peripheral controller.
61162306a36Sopenharmony_ci * @gadget_driver: pointer to the gadget driver.
61262306a36Sopenharmony_ci * @lock: for synchronizing.
61362306a36Sopenharmony_ci * @irq: interrupt line number.
61462306a36Sopenharmony_ci * @regs: base address for registers
61562306a36Sopenharmony_ci * @usb_regs: base address for common USB registers.
61662306a36Sopenharmony_ci * @ep0_regs: base address for endpoint 0 related registers.
61762306a36Sopenharmony_ci * @epx_regs: base address for all none control endpoint registers.
61862306a36Sopenharmony_ci * @interrupt_regs: base address for interrupt handling related registers.
61962306a36Sopenharmony_ci * @adma_regs: base address for ADMA registers.
62062306a36Sopenharmony_ci * @eps_dma_pool: endpoint Transfer Ring pool.
62162306a36Sopenharmony_ci * @setup: used while processing usb control requests.
62262306a36Sopenharmony_ci * @ep0_preq: private request used while handling EP0.
62362306a36Sopenharmony_ci * @ep0_stage: ep0 stage during enumeration process.
62462306a36Sopenharmony_ci * @zlp_buf: zlp buffer.
62562306a36Sopenharmony_ci * @dev_address: device address assigned by host.
62662306a36Sopenharmony_ci * @eps: array of objects describing endpoints.
62762306a36Sopenharmony_ci * @selected_ep: actually selected endpoint. It's used only to improve
62862306a36Sopenharmony_ci *      performance by limiting access to dma_ep_sel register.
62962306a36Sopenharmony_ci * @is_selfpowered: device is self powered.
63062306a36Sopenharmony_ci * @may_wakeup: allows device to remote wakeup the host.
63162306a36Sopenharmony_ci * @status_completion_no_call: indicate that driver is waiting for status
63262306a36Sopenharmony_ci *      stage completion. It's used in deferred SET_CONFIGURATION request.
63362306a36Sopenharmony_ci * @in_lpm: indicate the controller is in low power mode.
63462306a36Sopenharmony_ci * @pending_status_wq: workqueue handling status stage for deferred requests.
63562306a36Sopenharmony_ci * @pending_status_request: request for which status stage was deferred.
63662306a36Sopenharmony_ci * @eps_supported: endpoints supported by controller in form:
63762306a36Sopenharmony_ci *      bit: 0 - ep0, 1 - epOut1, 2 - epIn1, 3 - epOut2 ...
63862306a36Sopenharmony_ci * @burst_opt: array with the best burst size value for different TRB size.
63962306a36Sopenharmony_ci * @onchip_tx_buf: size of transmit on-chip buffer in KB.
64062306a36Sopenharmony_ci * @onchip_rx_buf: size of receive on-chip buffer in KB.
64162306a36Sopenharmony_ci */
64262306a36Sopenharmony_cistruct cdns2_device {
64362306a36Sopenharmony_ci	struct device *dev;
64462306a36Sopenharmony_ci	struct usb_gadget gadget;
64562306a36Sopenharmony_ci	struct usb_gadget_driver *gadget_driver;
64662306a36Sopenharmony_ci
64762306a36Sopenharmony_ci	/* generic spin-lock for drivers */
64862306a36Sopenharmony_ci	spinlock_t lock;
64962306a36Sopenharmony_ci	int irq;
65062306a36Sopenharmony_ci	void __iomem *regs;
65162306a36Sopenharmony_ci	struct cdns2_usb_regs __iomem *usb_regs;
65262306a36Sopenharmony_ci	struct cdns2_ep0_regs __iomem *ep0_regs;
65362306a36Sopenharmony_ci	struct cdns2_epx_regs __iomem *epx_regs;
65462306a36Sopenharmony_ci	struct cdns2_interrupt_regs __iomem *interrupt_regs;
65562306a36Sopenharmony_ci	struct cdns2_adma_regs __iomem *adma_regs;
65662306a36Sopenharmony_ci	struct dma_pool *eps_dma_pool;
65762306a36Sopenharmony_ci	struct usb_ctrlrequest setup;
65862306a36Sopenharmony_ci	struct cdns2_request ep0_preq;
65962306a36Sopenharmony_ci	u8 ep0_stage;
66062306a36Sopenharmony_ci	void *zlp_buf;
66162306a36Sopenharmony_ci	u8 dev_address;
66262306a36Sopenharmony_ci	struct cdns2_endpoint eps[CDNS2_ENDPOINTS_NUM];
66362306a36Sopenharmony_ci	u32 selected_ep;
66462306a36Sopenharmony_ci	bool is_selfpowered;
66562306a36Sopenharmony_ci	bool may_wakeup;
66662306a36Sopenharmony_ci	bool status_completion_no_call;
66762306a36Sopenharmony_ci	bool in_lpm;
66862306a36Sopenharmony_ci	struct work_struct pending_status_wq;
66962306a36Sopenharmony_ci	struct usb_request *pending_status_request;
67062306a36Sopenharmony_ci	u32 eps_supported;
67162306a36Sopenharmony_ci	u8 burst_opt[MAX_ISO_SIZE + 1];
67262306a36Sopenharmony_ci
67362306a36Sopenharmony_ci	/*in KB */
67462306a36Sopenharmony_ci	u16 onchip_tx_buf;
67562306a36Sopenharmony_ci	u16 onchip_rx_buf;
67662306a36Sopenharmony_ci};
67762306a36Sopenharmony_ci
67862306a36Sopenharmony_ci#define CDNS2_IF_EP_EXIST(pdev, ep_num, dir) \
67962306a36Sopenharmony_ci			 ((pdev)->eps_supported & \
68062306a36Sopenharmony_ci			 (BIT(ep_num) << ((dir) ? 0 : 16)))
68162306a36Sopenharmony_ci
68262306a36Sopenharmony_cidma_addr_t cdns2_trb_virt_to_dma(struct cdns2_endpoint *pep,
68362306a36Sopenharmony_ci				 struct cdns2_trb *trb);
68462306a36Sopenharmony_civoid cdns2_pending_setup_status_handler(struct work_struct *work);
68562306a36Sopenharmony_civoid cdns2_select_ep(struct cdns2_device *pdev, u32 ep);
68662306a36Sopenharmony_cistruct cdns2_request *cdns2_next_preq(struct list_head *list);
68762306a36Sopenharmony_cistruct usb_request *cdns2_gadget_ep_alloc_request(struct usb_ep *ep,
68862306a36Sopenharmony_ci						  gfp_t gfp_flags);
68962306a36Sopenharmony_civoid cdns2_gadget_ep_free_request(struct usb_ep *ep,
69062306a36Sopenharmony_ci				  struct usb_request *request);
69162306a36Sopenharmony_ciint cdns2_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request);
69262306a36Sopenharmony_civoid cdns2_gadget_giveback(struct cdns2_endpoint *pep,
69362306a36Sopenharmony_ci			   struct cdns2_request *priv_req,
69462306a36Sopenharmony_ci			   int status);
69562306a36Sopenharmony_civoid cdns2_init_ep0(struct cdns2_device *pdev, struct cdns2_endpoint *pep);
69662306a36Sopenharmony_civoid cdns2_ep0_config(struct cdns2_device *pdev);
69762306a36Sopenharmony_civoid cdns2_handle_ep0_interrupt(struct cdns2_device *pdev, int dir);
69862306a36Sopenharmony_civoid cdns2_handle_setup_packet(struct cdns2_device *pdev);
69962306a36Sopenharmony_ciint cdns2_gadget_resume(struct cdns2_device *pdev, bool hibernated);
70062306a36Sopenharmony_ciint cdns2_gadget_suspend(struct cdns2_device *pdev);
70162306a36Sopenharmony_civoid cdns2_gadget_remove(struct cdns2_device *pdev);
70262306a36Sopenharmony_ciint cdns2_gadget_init(struct cdns2_device *pdev);
70362306a36Sopenharmony_civoid set_reg_bit_8(void __iomem *ptr, u8 mask);
70462306a36Sopenharmony_ciint cdns2_halt_endpoint(struct cdns2_device *pdev, struct cdns2_endpoint *pep,
70562306a36Sopenharmony_ci			int value);
70662306a36Sopenharmony_ci
70762306a36Sopenharmony_ci#endif /* __LINUX_CDNS2_GADGET */
708