linux/drivers/usb/gadget/udc/aspeed-vhub/vhub.h

/* SPDX-License-Identifier: GPL-2.0+ */
#ifndef __ASPEED_VHUB_H
#define __ASPEED_VHUB_H

#include <linux/usb.h>
#include <linux/usb/ch11.h>

/*****************************
 *                           *
 * VHUB register definitions *
 *                           *
 *****************************/

#define AST_VHUB_CTRL
#define AST_VHUB_CONF
#define AST_VHUB_IER
#define AST_VHUB_ISR
#define AST_VHUB_EP_ACK_IER
#define AST_VHUB_EP_NACK_IER
#define AST_VHUB_EP_ACK_ISR
#define AST_VHUB_EP_NACK_ISR
#define AST_VHUB_SW_RESET
#define AST_VHUB_USBSTS
#define AST_VHUB_EP_TOGGLE
#define AST_VHUB_ISO_FAIL_ACC
#define AST_VHUB_EP0_CTRL
#define AST_VHUB_EP0_DATA
#define AST_VHUB_EP1_CTRL
#define AST_VHUB_EP1_STS_CHG
#define AST_VHUB_SETUP0
#define AST_VHUB_SETUP1

/* Main control reg */
#define VHUB_CTRL_PHY_CLK
#define VHUB_CTRL_PHY_LOOP_TEST
#define VHUB_CTRL_DN_PWN
#define VHUB_CTRL_DP_PWN
#define VHUB_CTRL_LONG_DESC
#define VHUB_CTRL_ISO_RSP_CTRL
#define VHUB_CTRL_SPLIT_IN
#define VHUB_CTRL_LOOP_T_RESULT
#define VHUB_CTRL_LOOP_T_STS
#define VHUB_CTRL_PHY_BIST_RESULT
#define VHUB_CTRL_PHY_BIST_CTRL
#define VHUB_CTRL_PHY_RESET_DIS
#define VHUB_CTRL_SET_TEST_MODE(x)
#define VHUB_CTRL_MANUAL_REMOTE_WAKEUP
#define VHUB_CTRL_AUTO_REMOTE_WAKEUP
#define VHUB_CTRL_CLK_STOP_SUSPEND
#define VHUB_CTRL_FULL_SPEED_ONLY
#define VHUB_CTRL_UPSTREAM_CONNECT

/* IER & ISR */
#define VHUB_IRQ_DEV1_BIT
#define VHUB_IRQ_USB_CMD_DEADLOCK
#define VHUB_IRQ_EP_POOL_NAK
#define VHUB_IRQ_EP_POOL_ACK_STALL
#define VHUB_IRQ_DEVICE1
#define VHUB_IRQ_BUS_RESUME
#define VHUB_IRQ_BUS_SUSPEND
#define VHUB_IRQ_BUS_RESET
#define VHUB_IRQ_HUB_EP1_IN_DATA_ACK
#define VHUB_IRQ_HUB_EP0_IN_DATA_NAK
#define VHUB_IRQ_HUB_EP0_IN_ACK_STALL
#define VHUB_IRQ_HUB_EP0_OUT_NAK
#define VHUB_IRQ_HUB_EP0_OUT_ACK_STALL
#define VHUB_IRQ_HUB_EP0_SETUP
#define VHUB_IRQ_ACK_ALL

/* Downstream device IRQ mask. */
#define VHUB_DEV_IRQ(n)

/* SW reset reg */
#define VHUB_SW_RESET_EP_POOL
#define VHUB_SW_RESET_DMA_CONTROLLER
#define VHUB_SW_RESET_DEVICE5
#define VHUB_SW_RESET_DEVICE4
#define VHUB_SW_RESET_DEVICE3
#define VHUB_SW_RESET_DEVICE2
#define VHUB_SW_RESET_DEVICE1
#define VHUB_SW_RESET_ROOT_HUB

/* EP ACK/NACK IRQ masks */
#define VHUB_EP_IRQ(n)

/* USB status reg */
#define VHUB_USBSTS_HISPEED

/* EP toggle */
#define VHUB_EP_TOGGLE_VALUE
#define VHUB_EP_TOGGLE_SET_EPNUM(x)

/* HUB EP0 control */
#define VHUB_EP0_CTRL_STALL
#define VHUB_EP0_TX_BUFF_RDY
#define VHUB_EP0_RX_BUFF_RDY
#define VHUB_EP0_RX_LEN(x)
#define VHUB_EP0_SET_TX_LEN(x)

/* HUB EP1 control */
#define VHUB_EP1_CTRL_RESET_TOGGLE
#define VHUB_EP1_CTRL_STALL
#define VHUB_EP1_CTRL_ENABLE

/***********************************
 *                                 *
 * per-device register definitions *
 *                                 *
 ***********************************/
#define AST_VHUB_DEV_EN_CTRL
#define AST_VHUB_DEV_ISR
#define AST_VHUB_DEV_EP0_CTRL
#define AST_VHUB_DEV_EP0_DATA

/* Device enable control */
#define VHUB_DEV_EN_SET_ADDR(x)
#define VHUB_DEV_EN_ADDR_MASK
#define VHUB_DEV_EN_EP0_NAK_IRQEN
#define VHUB_DEV_EN_EP0_IN_ACK_IRQEN
#define VHUB_DEV_EN_EP0_OUT_NAK_IRQEN
#define VHUB_DEV_EN_EP0_OUT_ACK_IRQEN
#define VHUB_DEV_EN_EP0_SETUP_IRQEN
#define VHUB_DEV_EN_SPEED_SEL_HIGH
#define VHUB_DEV_EN_ENABLE_PORT

/* Interrupt status */
#define VHUV_DEV_IRQ_EP0_IN_DATA_NACK
#define VHUV_DEV_IRQ_EP0_IN_ACK_STALL
#define VHUV_DEV_IRQ_EP0_OUT_DATA_NACK
#define VHUV_DEV_IRQ_EP0_OUT_ACK_STALL
#define VHUV_DEV_IRQ_EP0_SETUP

/* Control bits.
 *
 * Note: The driver relies on the bulk of those bits
 *       matching corresponding vHub EP0 control bits
 */
#define VHUB_DEV_EP0_CTRL_STALL
#define VHUB_DEV_EP0_TX_BUFF_RDY
#define VHUB_DEV_EP0_RX_BUFF_RDY
#define VHUB_DEV_EP0_RX_LEN(x)
#define VHUB_DEV_EP0_SET_TX_LEN(x)

/*************************************
 *                                   *
 * per-endpoint register definitions *
 *                                   *
 *************************************/

#define AST_VHUB_EP_CONFIG
#define AST_VHUB_EP_DMA_CTLSTAT
#define AST_VHUB_EP_DESC_BASE
#define AST_VHUB_EP_DESC_STATUS

/* EP config reg */
#define VHUB_EP_CFG_SET_MAX_PKT(x)
#define VHUB_EP_CFG_AUTO_DATA_DISABLE
#define VHUB_EP_CFG_STALL_CTRL
#define VHUB_EP_CFG_SET_EP_NUM(x)
#define VHUB_EP_CFG_SET_TYPE(x)
#define EP_TYPE_OFF
#define EP_TYPE_BULK
#define EP_TYPE_INT
#define EP_TYPE_ISO
#define VHUB_EP_CFG_DIR_OUT
#define VHUB_EP_CFG_SET_DEV(x)
#define VHUB_EP_CFG_ENABLE

/* EP DMA control */
#define VHUB_EP_DMA_PROC_STATUS(x)
#define EP_DMA_PROC_RX_IDLE
#define EP_DMA_PROC_TX_IDLE
#define VHUB_EP_DMA_IN_LONG_MODE
#define VHUB_EP_DMA_OUT_CONTIG_MODE
#define VHUB_EP_DMA_CTRL_RESET
#define VHUB_EP_DMA_SINGLE_STAGE
#define VHUB_EP_DMA_DESC_MODE

/* EP DMA status */
#define VHUB_EP_DMA_SET_TX_SIZE(x)
#define VHUB_EP_DMA_TX_SIZE(x)
#define VHUB_EP_DMA_RPTR(x)
#define VHUB_EP_DMA_SET_RPTR(x)
#define VHUB_EP_DMA_SET_CPU_WPTR(x)
#define VHUB_EP_DMA_SINGLE_KICK

/*******************************
 *                             *
 * DMA descriptors definitions *
 *                             *
 *******************************/

/* Desc W1 IN */
#define VHUB_DSC1_IN_INTERRUPT
#define VHUB_DSC1_IN_SPID_DATA0
#define VHUB_DSC1_IN_SPID_DATA2
#define VHUB_DSC1_IN_SPID_DATA1
#define VHUB_DSC1_IN_SPID_MDATA
#define VHUB_DSC1_IN_SET_LEN(x)
#define VHUB_DSC1_IN_LEN(x)

/****************************************
 *                                      *
 * Data structures and misc definitions *
 *                                      *
 ****************************************/

/*
 * AST_VHUB_NUM_GEN_EPs and AST_VHUB_NUM_PORTS are kept to avoid breaking
 * existing AST2400/AST2500 platforms. AST2600 and future vhub revisions
 * should define number of downstream ports and endpoints in device tree.
 */
#define AST_VHUB_NUM_GEN_EPs
#define AST_VHUB_NUM_PORTS
#define AST_VHUB_EP0_MAX_PACKET
#define AST_VHUB_EPn_MAX_PACKET
#define AST_VHUB_DESCS_COUNT

struct ast_vhub;
struct ast_vhub_dev;

/*
 * DMA descriptor (generic EPs only, currently only used
 * for IN endpoints
 */
struct ast_vhub_desc {};

/* A transfer request, either core-originated or internal */
struct ast_vhub_req {};
#define to_ast_req(__ureq)

/* Current state of an EP0 */
enum ep0_state {};

/*
 * An endpoint, either generic, ep0, actual gadget EP
 * or internal use vhub EP0. vhub EP1 doesn't have an
 * associated structure as it's mostly HW managed.
 */
struct ast_vhub_ep {};
#define to_ast_ep(__uep)

/* A device attached to a vHub port */
struct ast_vhub_dev {};
#define to_ast_dev(__g)

/* Per vhub port stateinfo structure */
struct ast_vhub_port {};

struct ast_vhub_full_cdesc {} __packed;

/* Global vhub structure */
struct ast_vhub {};

/* Standard request handlers result codes */
enum std_req_rc {};

#ifdef CONFIG_USB_GADGET_VERBOSE
#define UDCVDBG(u, fmt...)

#define EPVDBG(ep, fmt, ...)

#define DVDBG(d, fmt, ...)

#else
#define UDCVDBG
#define EPVDBG
#define DVDBG
#endif

#ifdef CONFIG_USB_GADGET_DEBUG
#define UDCDBG(u, fmt...)

#define EPDBG(ep, fmt, ...)

#define DDBG(d, fmt, ...)
#else
#define UDCDBG
#define EPDBG
#define DDBG
#endif

static inline void vhub_dma_workaround(void *addr)
{}

/* core.c */
void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req,
		   int status);
void ast_vhub_nuke(struct ast_vhub_ep *ep, int status);
struct usb_request *ast_vhub_alloc_request(struct usb_ep *u_ep,
					   gfp_t gfp_flags);
void ast_vhub_free_request(struct usb_ep *u_ep, struct usb_request *u_req);
void ast_vhub_init_hw(struct ast_vhub *vhub);

/* ep0.c */
void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack);
void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep);
void ast_vhub_reset_ep0(struct ast_vhub_dev *dev);
void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep *ep,
		       struct ast_vhub_dev *dev);
int ast_vhub_reply(struct ast_vhub_ep *ep, char *ptr, int len);
int __ast_vhub_simple_reply(struct ast_vhub_ep *ep, int len, ...);
#define ast_vhub_simple_reply(udc, ...)

/* hub.c */
int ast_vhub_init_hub(struct ast_vhub *vhub);
enum std_req_rc ast_vhub_std_hub_request(struct ast_vhub_ep *ep,
					 struct usb_ctrlrequest *crq);
enum std_req_rc ast_vhub_class_hub_request(struct ast_vhub_ep *ep,
					   struct usb_ctrlrequest *crq);
void ast_vhub_device_connect(struct ast_vhub *vhub, unsigned int port,
			     bool on);
void ast_vhub_hub_suspend(struct ast_vhub *vhub);
void ast_vhub_hub_resume(struct ast_vhub *vhub);
void ast_vhub_hub_reset(struct ast_vhub *vhub);
void ast_vhub_hub_wake_all(struct ast_vhub *vhub);

/* dev.c */
int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx);
void ast_vhub_del_dev(struct ast_vhub_dev *d);
void ast_vhub_dev_irq(struct ast_vhub_dev *d);
int ast_vhub_std_dev_request(struct ast_vhub_ep *ep,
			     struct usb_ctrlrequest *crq);

/* epn.c */
void ast_vhub_epn_ack_irq(struct ast_vhub_ep *ep);
void ast_vhub_update_epn_stall(struct ast_vhub_ep *ep);
struct ast_vhub_ep *ast_vhub_alloc_epn(struct ast_vhub_dev *d, u8 addr);
void ast_vhub_dev_suspend(struct ast_vhub_dev *d);
void ast_vhub_dev_resume(struct ast_vhub_dev *d);
void ast_vhub_dev_reset(struct ast_vhub_dev *d);

#endif /* __ASPEED_VHUB_H */