linux/drivers/usb/gadget/udc/amd5536udc.h

// SPDX-License-Identifier: GPL-2.0+
/*
 * amd5536.h -- header for AMD 5536 UDC high/full speed USB device controller
 *
 * Copyright (C) 2007 AMD (https://www.amd.com)
 * Author: Thomas Dahlmann
 */

#ifndef AMD5536UDC_H
#define AMD5536UDC_H

/* debug control */
/* #define UDC_VERBOSE */

#include <linux/extcon.h>
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>

/* various constants */
#define UDC_RDE_TIMER_SECONDS
#define UDC_RDE_TIMER_DIV
#define UDC_POLLSTALL_TIMER_USECONDS

/* Hs AMD5536 chip rev. */
#define UDC_HSA0_REV
#define UDC_HSB1_REV

/* Broadcom chip rev. */
#define UDC_BCM_REV

/*
 * SETUP usb commands
 * needed, because some SETUP's are handled in hw, but must be passed to
 * gadget driver above
 * SET_CONFIG
 */
#define UDC_SETCONFIG_DWORD0
#define UDC_SETCONFIG_DWORD0_VALUE_MASK
#define UDC_SETCONFIG_DWORD0_VALUE_OFS

#define UDC_SETCONFIG_DWORD1

/* SET_INTERFACE */
#define UDC_SETINTF_DWORD0
#define UDC_SETINTF_DWORD0_ALT_MASK
#define UDC_SETINTF_DWORD0_ALT_OFS

#define UDC_SETINTF_DWORD1
#define UDC_SETINTF_DWORD1_INTF_MASK
#define UDC_SETINTF_DWORD1_INTF_OFS

/* Mass storage reset */
#define UDC_MSCRES_DWORD0
#define UDC_MSCRES_DWORD1

/* Global CSR's -------------------------------------------------------------*/
#define UDC_CSR_ADDR

/* EP NE bits */
/* EP number */
#define UDC_CSR_NE_NUM_MASK
#define UDC_CSR_NE_NUM_OFS
/* EP direction */
#define UDC_CSR_NE_DIR_MASK
#define UDC_CSR_NE_DIR_OFS
/* EP type */
#define UDC_CSR_NE_TYPE_MASK
#define UDC_CSR_NE_TYPE_OFS
/* EP config number */
#define UDC_CSR_NE_CFG_MASK
#define UDC_CSR_NE_CFG_OFS
/* EP interface number */
#define UDC_CSR_NE_INTF_MASK
#define UDC_CSR_NE_INTF_OFS
/* EP alt setting */
#define UDC_CSR_NE_ALT_MASK
#define UDC_CSR_NE_ALT_OFS

/* max pkt */
#define UDC_CSR_NE_MAX_PKT_MASK
#define UDC_CSR_NE_MAX_PKT_OFS

/* Device Config Register ---------------------------------------------------*/
#define UDC_DEVCFG_ADDR

#define UDC_DEVCFG_SOFTRESET
#define UDC_DEVCFG_HNPSFEN
#define UDC_DEVCFG_DMARST
#define UDC_DEVCFG_SET_DESC
#define UDC_DEVCFG_CSR_PRG
#define UDC_DEVCFG_STATUS
#define UDC_DEVCFG_DIR
#define UDC_DEVCFG_PI
#define UDC_DEVCFG_SS
#define UDC_DEVCFG_SP
#define UDC_DEVCFG_RWKP

#define UDC_DEVCFG_SPD_MASK
#define UDC_DEVCFG_SPD_OFS
#define UDC_DEVCFG_SPD_HS
#define UDC_DEVCFG_SPD_FS
#define UDC_DEVCFG_SPD_LS
/*#define UDC_DEVCFG_SPD_FS			0x3*/


/* Device Control Register --------------------------------------------------*/
#define UDC_DEVCTL_ADDR

#define UDC_DEVCTL_THLEN_MASK
#define UDC_DEVCTL_THLEN_OFS

#define UDC_DEVCTL_BRLEN_MASK
#define UDC_DEVCTL_BRLEN_OFS

#define UDC_DEVCTL_SRX_FLUSH
#define UDC_DEVCTL_CSR_DONE
#define UDC_DEVCTL_DEVNAK
#define UDC_DEVCTL_SD
#define UDC_DEVCTL_MODE
#define UDC_DEVCTL_BREN
#define UDC_DEVCTL_THE
#define UDC_DEVCTL_BF
#define UDC_DEVCTL_BE
#define UDC_DEVCTL_DU
#define UDC_DEVCTL_TDE
#define UDC_DEVCTL_RDE
#define UDC_DEVCTL_RES


/* Device Status Register ---------------------------------------------------*/
#define UDC_DEVSTS_ADDR

#define UDC_DEVSTS_TS_MASK
#define UDC_DEVSTS_TS_OFS

#define UDC_DEVSTS_SESSVLD
#define UDC_DEVSTS_PHY_ERROR
#define UDC_DEVSTS_RXFIFO_EMPTY

#define UDC_DEVSTS_ENUM_SPEED_MASK
#define UDC_DEVSTS_ENUM_SPEED_OFS
#define UDC_DEVSTS_ENUM_SPEED_FULL
#define UDC_DEVSTS_ENUM_SPEED_HIGH

#define UDC_DEVSTS_SUSP

#define UDC_DEVSTS_ALT_MASK
#define UDC_DEVSTS_ALT_OFS

#define UDC_DEVSTS_INTF_MASK
#define UDC_DEVSTS_INTF_OFS

#define UDC_DEVSTS_CFG_MASK
#define UDC_DEVSTS_CFG_OFS


/* Device Interrupt Register ------------------------------------------------*/
#define UDC_DEVINT_ADDR

#define UDC_DEVINT_SVC
#define UDC_DEVINT_ENUM
#define UDC_DEVINT_SOF
#define UDC_DEVINT_US
#define UDC_DEVINT_UR
#define UDC_DEVINT_ES
#define UDC_DEVINT_SI
#define UDC_DEVINT_SC

/* Device Interrupt Mask Register -------------------------------------------*/
#define UDC_DEVINT_MSK_ADDR

#define UDC_DEVINT_MSK

/* Endpoint Interrupt Register ----------------------------------------------*/
#define UDC_EPINT_ADDR

#define UDC_EPINT_OUT_MASK
#define UDC_EPINT_OUT_OFS
#define UDC_EPINT_IN_MASK
#define UDC_EPINT_IN_OFS

#define UDC_EPINT_IN_EP0
#define UDC_EPINT_IN_EP1
#define UDC_EPINT_IN_EP2
#define UDC_EPINT_IN_EP3
#define UDC_EPINT_OUT_EP0
#define UDC_EPINT_OUT_EP1
#define UDC_EPINT_OUT_EP2
#define UDC_EPINT_OUT_EP3

#define UDC_EPINT_EP0_ENABLE_MSK

/* Endpoint Interrupt Mask Register -----------------------------------------*/
#define UDC_EPINT_MSK_ADDR

#define UDC_EPINT_OUT_MSK_MASK
#define UDC_EPINT_OUT_MSK_OFS
#define UDC_EPINT_IN_MSK_MASK
#define UDC_EPINT_IN_MSK_OFS

#define UDC_EPINT_MSK_DISABLE_ALL
/* mask non-EP0 endpoints */
#define UDC_EPDATAINT_MSK_DISABLE
/* mask all dev interrupts */
#define UDC_DEV_MSK_DISABLE

/* Endpoint-specific CSR's --------------------------------------------------*/
#define UDC_EPREGS_ADDR
#define UDC_EPIN_REGS_ADDR
#define UDC_EPOUT_REGS_ADDR

#define UDC_EPCTL_ADDR

#define UDC_EPCTL_RRDY
#define UDC_EPCTL_CNAK
#define UDC_EPCTL_SNAK
#define UDC_EPCTL_NAK

#define UDC_EPCTL_ET_MASK
#define UDC_EPCTL_ET_OFS
#define UDC_EPCTL_ET_CONTROL
#define UDC_EPCTL_ET_ISO
#define UDC_EPCTL_ET_BULK
#define UDC_EPCTL_ET_INTERRUPT

#define UDC_EPCTL_P
#define UDC_EPCTL_SN
#define UDC_EPCTL_F
#define UDC_EPCTL_S

/* Endpoint Status Registers ------------------------------------------------*/
#define UDC_EPSTS_ADDR

#define UDC_EPSTS_RX_PKT_SIZE_MASK
#define UDC_EPSTS_RX_PKT_SIZE_OFS

#define UDC_EPSTS_TDC
#define UDC_EPSTS_HE
#define UDC_EPSTS_BNA
#define UDC_EPSTS_IN

#define UDC_EPSTS_OUT_MASK
#define UDC_EPSTS_OUT_OFS
#define UDC_EPSTS_OUT_DATA
#define UDC_EPSTS_OUT_DATA_CLEAR
#define UDC_EPSTS_OUT_SETUP
#define UDC_EPSTS_OUT_SETUP_CLEAR
#define UDC_EPSTS_OUT_CLEAR

/* Endpoint Buffer Size IN/ Receive Packet Frame Number OUT Registers ------*/
#define UDC_EPIN_BUFF_SIZE_ADDR
#define UDC_EPOUT_FRAME_NUMBER_ADDR

#define UDC_EPIN_BUFF_SIZE_MASK
#define UDC_EPIN_BUFF_SIZE_OFS
/* EP0in txfifo = 128 bytes*/
#define UDC_EPIN0_BUFF_SIZE
/* EP0in fullspeed txfifo = 128 bytes*/
#define UDC_FS_EPIN0_BUFF_SIZE

/* fifo size mult = fifo size / max packet */
#define UDC_EPIN_BUFF_SIZE_MULT

/* EPin data fifo size = 1024 bytes DOUBLE BUFFERING */
#define UDC_EPIN_BUFF_SIZE
/* EPin small INT data fifo size = 128 bytes */
#define UDC_EPIN_SMALLINT_BUFF_SIZE

/* EPin fullspeed data fifo size = 128 bytes DOUBLE BUFFERING */
#define UDC_FS_EPIN_BUFF_SIZE

#define UDC_EPOUT_FRAME_NUMBER_MASK
#define UDC_EPOUT_FRAME_NUMBER_OFS

/* Endpoint Buffer Size OUT/Max Packet Size Registers -----------------------*/
#define UDC_EPOUT_BUFF_SIZE_ADDR
#define UDC_EP_MAX_PKT_SIZE_ADDR

#define UDC_EPOUT_BUFF_SIZE_MASK
#define UDC_EPOUT_BUFF_SIZE_OFS
#define UDC_EP_MAX_PKT_SIZE_MASK
#define UDC_EP_MAX_PKT_SIZE_OFS
/* EP0in max packet size = 64 bytes */
#define UDC_EP0IN_MAX_PKT_SIZE
/* EP0out max packet size = 64 bytes */
#define UDC_EP0OUT_MAX_PKT_SIZE
/* EP0in fullspeed max packet size = 64 bytes */
#define UDC_FS_EP0IN_MAX_PKT_SIZE
/* EP0out fullspeed max packet size = 64 bytes */
#define UDC_FS_EP0OUT_MAX_PKT_SIZE

/*
 * Endpoint dma descriptors ------------------------------------------------
 *
 * Setup data, Status dword
 */
#define UDC_DMA_STP_STS_CFG_MASK
#define UDC_DMA_STP_STS_CFG_OFS
#define UDC_DMA_STP_STS_CFG_ALT_MASK
#define UDC_DMA_STP_STS_CFG_ALT_OFS
#define UDC_DMA_STP_STS_CFG_INTF_MASK
#define UDC_DMA_STP_STS_CFG_INTF_OFS
#define UDC_DMA_STP_STS_CFG_NUM_MASK
#define UDC_DMA_STP_STS_CFG_NUM_OFS
#define UDC_DMA_STP_STS_RX_MASK
#define UDC_DMA_STP_STS_RX_OFS
#define UDC_DMA_STP_STS_BS_MASK
#define UDC_DMA_STP_STS_BS_OFS
#define UDC_DMA_STP_STS_BS_HOST_READY
#define UDC_DMA_STP_STS_BS_DMA_BUSY
#define UDC_DMA_STP_STS_BS_DMA_DONE
#define UDC_DMA_STP_STS_BS_HOST_BUSY
/* IN data, Status dword */
#define UDC_DMA_IN_STS_TXBYTES_MASK
#define UDC_DMA_IN_STS_TXBYTES_OFS
#define UDC_DMA_IN_STS_FRAMENUM_MASK
#define UDC_DMA_IN_STS_FRAMENUM_OFS
#define UDC_DMA_IN_STS_L
#define UDC_DMA_IN_STS_TX_MASK
#define UDC_DMA_IN_STS_TX_OFS
#define UDC_DMA_IN_STS_BS_MASK
#define UDC_DMA_IN_STS_BS_OFS
#define UDC_DMA_IN_STS_BS_HOST_READY
#define UDC_DMA_IN_STS_BS_DMA_BUSY
#define UDC_DMA_IN_STS_BS_DMA_DONE
#define UDC_DMA_IN_STS_BS_HOST_BUSY
/* OUT data, Status dword */
#define UDC_DMA_OUT_STS_RXBYTES_MASK
#define UDC_DMA_OUT_STS_RXBYTES_OFS
#define UDC_DMA_OUT_STS_FRAMENUM_MASK
#define UDC_DMA_OUT_STS_FRAMENUM_OFS
#define UDC_DMA_OUT_STS_L
#define UDC_DMA_OUT_STS_RX_MASK
#define UDC_DMA_OUT_STS_RX_OFS
#define UDC_DMA_OUT_STS_BS_MASK
#define UDC_DMA_OUT_STS_BS_OFS
#define UDC_DMA_OUT_STS_BS_HOST_READY
#define UDC_DMA_OUT_STS_BS_DMA_BUSY
#define UDC_DMA_OUT_STS_BS_DMA_DONE
#define UDC_DMA_OUT_STS_BS_HOST_BUSY
/* max ep0in packet */
#define UDC_EP0IN_MAXPACKET
/* max dma packet */
#define UDC_DMA_MAXPACKET

/* un-usable DMA address */
#define DMA_DONT_USE

/* other Endpoint register addresses and values-----------------------------*/
#define UDC_EP_SUBPTR_ADDR
#define UDC_EP_DESPTR_ADDR
#define UDC_EP_WRITE_CONFIRM_ADDR

/* EP number as layouted in AHB space */
#define UDC_EP_NUM
#define UDC_EPIN_NUM
#define UDC_EPIN_NUM_USED
#define UDC_EPOUT_NUM
/* EP number of EP's really used = EP0 + 8 data EP's */
#define UDC_USED_EP_NUM
/* UDC CSR regs are aligned but AHB regs not - offset for OUT EP's */
#define UDC_CSR_EP_OUT_IX_OFS

#define UDC_EP0OUT_IX
#define UDC_EP0IN_IX

/* Rx fifo address and size = 1k -------------------------------------------*/
#define UDC_RXFIFO_ADDR
#define UDC_RXFIFO_SIZE

/* Tx fifo address and size = 1.5k -----------------------------------------*/
#define UDC_TXFIFO_ADDR
#define UDC_TXFIFO_SIZE

/* default data endpoints --------------------------------------------------*/
#define UDC_EPIN_STATUS_IX
#define UDC_EPIN_IX
#define UDC_EPOUT_IX

/* general constants -------------------------------------------------------*/
#define UDC_DWORD_BYTES
#define UDC_BITS_PER_BYTE_SHIFT
#define UDC_BYTE_MASK
#define UDC_BITS_PER_BYTE

/*---------------------------------------------------------------------------*/
/* UDC CSR's */
struct udc_csrs {} __attribute__ ((packed));

/* AHB subsystem CSR registers */
struct udc_regs {} __attribute__ ((packed));

/* endpoint specific registers */
struct udc_ep_regs {} __attribute__ ((packed));

/* control data DMA desc */
struct udc_stp_dma {} __attribute__ ((aligned));

/* normal data DMA desc */
struct udc_data_dma {} __attribute__ ((aligned));

/* request packet */
struct udc_request {};

/* UDC specific endpoint parameters */
struct udc_ep {};

/* device struct */
struct udc {};

#define to_amd5536_udc(g)

/* setup request data */
udc_setup_data;

/* Function declarations */
int udc_enable_dev_setup_interrupts(struct udc *dev);
int udc_mask_unused_interrupts(struct udc *dev);
irqreturn_t udc_irq(int irq, void *pdev);
void gadget_release(struct device *pdev);
void empty_req_queue(struct udc_ep *ep);
void udc_basic_init(struct udc *dev);
void free_dma_pools(struct udc *dev);
int init_dma_pools(struct udc *dev);
void udc_remove(struct udc *dev);
int udc_probe(struct udc *dev);

/* DMA usage flag */
static bool use_dma =;
/* packet per buffer dma */
static bool use_dma_ppb =;
/* with per descr. update */
static bool use_dma_ppb_du;
/* full speed only mode */
static bool use_fullspeed;

/* module parameters */
module_param(use_dma, bool, S_IRUGO);
MODULE_PARM_DESC();
module_param(use_dma_ppb, bool, S_IRUGO);
MODULE_PARM_DESC();
module_param(use_dma_ppb_du, bool, S_IRUGO);
MODULE_PARM_DESC();
module_param(use_fullspeed, bool, S_IRUGO);
MODULE_PARM_DESC();
/*
 *---------------------------------------------------------------------------
 * SET and GET bitfields in u32 values
 * via constants for mask/offset:
 * <bit_field_stub_name> is the text between
 * UDC_ and _MASK|_OFS of appropriate
 * constant
 *
 * set bitfield value in u32 u32Val
 */
#define AMD_ADDBITS(u32Val, bitfield_val, bitfield_stub_name)

/*
 * set bitfield value in zero-initialized u32 u32Val
 * => bitfield bits in u32Val are all zero
 */
#define AMD_INIT_SETBITS(u32Val, bitfield_val, bitfield_stub_name)

/* get bitfield value from u32 u32Val */
#define AMD_GETBITS(u32Val, bitfield_stub_name)

/* SET and GET bits in u32 values ------------------------------------------*/
#define AMD_BIT(bit_stub_name)
#define AMD_UNMASK_BIT(bit_stub_name)
#define AMD_CLEAR_BIT(bit_stub_name)

/* debug macros ------------------------------------------------------------*/

#define DBG(udc , args...)

#ifdef UDC_VERBOSE
#define VDBG
#else
#define VDBG(udc , args...)
#endif

#endif /* #ifdef AMD5536UDC_H */