linux/include/linux/rtsx_usb.h

/* SPDX-License-Identifier: GPL-2.0-only */
/* Driver for Realtek RTS5139 USB card reader
 *
 * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
 *
 * Author:
 *   Roger Tseng <[email protected]>
 */

#ifndef __RTSX_USB_H
#define __RTSX_USB_H

#include <linux/usb.h>

/* related module names */
#define RTSX_USB_SD_CARD
#define RTSX_USB_MS_CARD

/* endpoint numbers */
#define EP_BULK_OUT
#define EP_BULK_IN
#define EP_INTR_IN

/* USB vendor requests */
#define RTSX_USB_REQ_REG_OP
#define RTSX_USB_REQ_POLL

/* miscellaneous parameters */
#define MIN_DIV_N
#define MAX_DIV_N

#define MAX_PHASE
#define RX_TUNING_CNT

#define QFN24
#define LQFP48
#define CHECK_PKG(ucr, pkg)

/* data structures */
struct rtsx_ucr {};

/* buffer size */
#define IOBUF_SIZE

/* prototypes of exported functions */
extern int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status);

extern int rtsx_usb_read_register(struct rtsx_ucr *ucr, u16 addr, u8 *data);
extern int rtsx_usb_write_register(struct rtsx_ucr *ucr, u16 addr, u8 mask,
		u8 data);

extern int rtsx_usb_ep0_write_register(struct rtsx_ucr *ucr, u16 addr, u8 mask,
		u8 data);
extern int rtsx_usb_ep0_read_register(struct rtsx_ucr *ucr, u16 addr,
		u8 *data);

extern void rtsx_usb_add_cmd(struct rtsx_ucr *ucr, u8 cmd_type,
		u16 reg_addr, u8 mask, u8 data);
extern int rtsx_usb_send_cmd(struct rtsx_ucr *ucr, u8 flag, int timeout);
extern int rtsx_usb_get_rsp(struct rtsx_ucr *ucr, int rsp_len, int timeout);
extern int rtsx_usb_transfer_data(struct rtsx_ucr *ucr, unsigned int pipe,
			      void *buf, unsigned int len, int use_sg,
			      unsigned int *act_len, int timeout);

extern int rtsx_usb_read_ppbuf(struct rtsx_ucr *ucr, u8 *buf, int buf_len);
extern int rtsx_usb_write_ppbuf(struct rtsx_ucr *ucr, u8 *buf, int buf_len);
extern int rtsx_usb_switch_clock(struct rtsx_ucr *ucr, unsigned int card_clock,
		u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
extern int rtsx_usb_card_exclusive_check(struct rtsx_ucr *ucr, int card);

/* card status */
#define SD_CD
#define MS_CD
#define XD_CD
#define CD_MASK
#define SD_WP

/* reader command field offset & parameters */
#define READ_REG_CMD
#define WRITE_REG_CMD
#define CHECK_REG_CMD

#define PACKET_TYPE
#define CNT_H
#define CNT_L
#define STAGE_FLAG
#define CMD_OFFSET
#define SEQ_WRITE_DATA_OFFSET

#define BATCH_CMD
#define SEQ_READ
#define SEQ_WRITE

#define STAGE_R
#define STAGE_DI
#define STAGE_DO
#define STAGE_MS_STATUS
#define STAGE_XD_STATUS
#define MODE_C
#define MODE_CR
#define MODE_CDIR
#define MODE_CDOR

#define EP0_OP_SHIFT
#define EP0_READ_REG_CMD
#define EP0_WRITE_REG_CMD

#define rtsx_usb_cmd_hdr_tag(ucr)

static inline void rtsx_usb_init_cmd(struct rtsx_ucr *ucr)
{}

/* internal register address */
#define FPDCTL
#define SSC_DIV_N_0
#define SSC_CTL1
#define SSC_CTL2
#define CFG_MODE
#define CFG_MODE_1
#define RCCTL
#define SOF_WDOG
#define SYS_DUMMY0

#define MS_BLKEND
#define MS_READ_START
#define MS_READ_COUNT
#define MS_WRITE_START
#define MS_WRITE_COUNT
#define MS_COMMAND
#define MS_OLD_BLOCK_0
#define MS_OLD_BLOCK_1
#define MS_NEW_BLOCK_0
#define MS_NEW_BLOCK_1
#define MS_LOG_BLOCK_0
#define MS_LOG_BLOCK_1
#define MS_BUS_WIDTH
#define MS_PAGE_START
#define MS_PAGE_LENGTH
#define MS_CFG
#define MS_TPC
#define MS_TRANS_CFG
#define MS_TRANSFER
#define MS_INT_REG
#define MS_BYTE_CNT
#define MS_SECTOR_CNT_L
#define MS_SECTOR_CNT_H
#define MS_DBUS_H

#define CARD_DMA1_CTL
#define CARD_PULL_CTL1
#define CARD_PULL_CTL2
#define CARD_PULL_CTL3
#define CARD_PULL_CTL4
#define CARD_PULL_CTL5
#define CARD_PULL_CTL6
#define CARD_EXIST
#define CARD_INT_PEND

#define LDO_POWER_CFG

#define SD_CFG1
#define SD_CFG2
#define SD_CFG3
#define SD_STAT1
#define SD_STAT2
#define SD_BUS_STAT
#define SD_PAD_CTL
#define SD_SAMPLE_POINT_CTL
#define SD_PUSH_POINT_CTL
#define SD_CMD0
#define SD_CMD1
#define SD_CMD2
#define SD_CMD3
#define SD_CMD4
#define SD_CMD5
#define SD_BYTE_CNT_L
#define SD_BYTE_CNT_H
#define SD_BLOCK_CNT_L
#define SD_BLOCK_CNT_H
#define SD_TRANSFER
#define SD_CMD_STATE
#define SD_DATA_STATE
#define SD_VPCLK0_CTL
#define SD_VPCLK1_CTL
#define SD_DCMPS0_CTL
#define SD_DCMPS1_CTL

#define CARD_DMA1_CTL

#define HW_VERSION

#define SSC_CLK_FPGA_SEL
#define CLK_DIV
#define SFSM_ED

#define CD_DEGLITCH_WIDTH
#define CD_DEGLITCH_EN
#define AUTO_DELINK_EN

#define FPGA_PULL_CTL
#define CARD_CLK_SOURCE

#define CARD_SHARE_MODE
#define CARD_DRIVE_SEL
#define CARD_STOP
#define CARD_OE
#define CARD_AUTO_BLINK
#define CARD_GPIO
#define SD30_DRIVE_SEL

#define CARD_DATA_SOURCE
#define CARD_SELECT

#define CARD_CLK_EN
#define CARD_PWR_CTL

#define OCPCTL
#define OCPPARA1
#define OCPPARA2
#define OCPSTAT

#define HS_USB_STAT
#define HS_VCONTROL
#define HS_VSTAIN
#define HS_VLOADM
#define HS_VSTAOUT

#define MC_IRQ
#define MC_IRQEN
#define MC_FIFO_CTL
#define MC_FIFO_BC0
#define MC_FIFO_BC1
#define MC_FIFO_STAT
#define MC_FIFO_MODE
#define MC_FIFO_RD_PTR0
#define MC_FIFO_RD_PTR1
#define MC_DMA_CTL
#define MC_DMA_TC0
#define MC_DMA_TC1
#define MC_DMA_TC2
#define MC_DMA_TC3
#define MC_DMA_RST

#define RBUF_SIZE_MASK
#define RBUF_BASE
#define PPBUF_BASE1
#define PPBUF_BASE2

/* internal register value macros */
#define POWER_OFF
#define PARTIAL_POWER_ON
#define POWER_ON
#define POWER_MASK
#define LDO3318_PWR_MASK
#define LDO_ON
#define LDO_SUSPEND
#define LDO_OFF
#define DV3318_AUTO_PWR_OFF
#define FORCE_LDO_POWERB

/* LDO_POWER_CFG */
#define TUNE_SD18_MASK
#define TUNE_SD18_1V7
#define TUNE_SD18_1V8
#define TUNE_SD18_1V9
#define TUNE_SD18_2V0
#define TUNE_SD18_2V7
#define TUNE_SD18_2V8
#define TUNE_SD18_2V9
#define TUNE_SD18_3V3

/* CLK_DIV */
#define CLK_CHANGE
#define CLK_DIV_1
#define CLK_DIV_2
#define CLK_DIV_4
#define CLK_DIV_8

#define SSC_POWER_MASK
#define SSC_POWER_DOWN
#define SSC_POWER_ON

#define FPGA_VER
#define HW_VER_MASK

#define EXTEND_DMA1_ASYNC_SIGNAL

/* CFG_MODE*/
#define XTAL_FREE
#define CLK_MODE_MASK
#define CLK_MODE_12M_XTAL
#define CLK_MODE_NON_XTAL
#define CLK_MODE_24M_OSC
#define CLK_MODE_48M_OSC

/* CFG_MODE_1*/
#define RTS5179

#define NYET_EN
#define NYET_MSAK

#define SD30_DRIVE_MASK
#define SD20_DRIVE_MASK

#define DISABLE_SD_CD
#define DISABLE_MS_CD
#define DISABLE_XD_CD
#define SD_CD_DEGLITCH_EN
#define MS_CD_DEGLITCH_EN
#define XD_CD_DEGLITCH_EN

#define CARD_SHARE_LQFP48
#define CARD_SHARE_QFN24
#define CARD_SHARE_LQFP_SEL
#define CARD_SHARE_XD
#define CARD_SHARE_SD
#define CARD_SHARE_MS
#define CARD_SHARE_MASK


/* SD30_DRIVE_SEL */
#define DRIVER_TYPE_A
#define DRIVER_TYPE_B
#define DRIVER_TYPE_C
#define DRIVER_TYPE_D

/* SD_BUS_STAT */
#define SD_CLK_TOGGLE_EN
#define SD_CLK_FORCE_STOP
#define SD_DAT3_STATUS
#define SD_DAT2_STATUS
#define SD_DAT1_STATUS
#define SD_DAT0_STATUS
#define SD_CMD_STATUS

/* SD_PAD_CTL */
#define SD_IO_USING_1V8
#define SD_IO_USING_3V3
#define TYPE_A_DRIVING
#define TYPE_B_DRIVING
#define TYPE_C_DRIVING
#define TYPE_D_DRIVING

/* CARD_CLK_EN */
#define SD_CLK_EN
#define MS_CLK_EN

/* CARD_SELECT */
#define SD_MOD_SEL
#define MS_MOD_SEL

/* CARD_SHARE_MODE */
#define CARD_SHARE_LQFP48
#define CARD_SHARE_QFN24
#define CARD_SHARE_LQFP_SEL
#define CARD_SHARE_XD
#define CARD_SHARE_SD
#define CARD_SHARE_MS
#define CARD_SHARE_MASK

/* SSC_CTL1 */
#define SSC_RSTB
#define SSC_8X_EN
#define SSC_FIX_FRAC
#define SSC_SEL_1M
#define SSC_SEL_2M
#define SSC_SEL_4M
#define SSC_SEL_8M

/* SSC_CTL2 */
#define SSC_DEPTH_MASK
#define SSC_DEPTH_DISALBE
#define SSC_DEPTH_2M
#define SSC_DEPTH_1M
#define SSC_DEPTH_512K

/* SD_VPCLK0_CTL */
#define PHASE_CHANGE
#define PHASE_NOT_RESET

/* SD_TRANSFER */
#define SD_TRANSFER_START
#define SD_TRANSFER_END
#define SD_STAT_IDLE
#define SD_TRANSFER_ERR
#define SD_TM_NORMAL_WRITE
#define SD_TM_AUTO_WRITE_3
#define SD_TM_AUTO_WRITE_4
#define SD_TM_AUTO_READ_3
#define SD_TM_AUTO_READ_4
#define SD_TM_CMD_RSP
#define SD_TM_AUTO_WRITE_1
#define SD_TM_AUTO_WRITE_2
#define SD_TM_NORMAL_READ
#define SD_TM_AUTO_READ_1
#define SD_TM_AUTO_READ_2
#define SD_TM_AUTO_TUNING

/* SD_CFG1 */
#define SD_CLK_DIVIDE_0
#define SD_CLK_DIVIDE_256
#define SD_CLK_DIVIDE_128
#define SD_CLK_DIVIDE_MASK
#define SD_BUS_WIDTH_1BIT
#define SD_BUS_WIDTH_4BIT
#define SD_BUS_WIDTH_8BIT
#define SD_ASYNC_FIFO_RST
#define SD_20_MODE
#define SD_DDR_MODE
#define SD_30_MODE

/* SD_CFG2 */
#define SD_CALCULATE_CRC7
#define SD_NO_CALCULATE_CRC7
#define SD_CHECK_CRC16
#define SD_NO_CHECK_CRC16
#define SD_WAIT_CRC_TO_EN
#define SD_WAIT_BUSY_END
#define SD_NO_WAIT_BUSY_END
#define SD_CHECK_CRC7
#define SD_NO_CHECK_CRC7
#define SD_RSP_LEN_0
#define SD_RSP_LEN_6
#define SD_RSP_LEN_17
#define SD_RSP_TYPE_R0
#define SD_RSP_TYPE_R1
#define SD_RSP_TYPE_R1b
#define SD_RSP_TYPE_R2
#define SD_RSP_TYPE_R3
#define SD_RSP_TYPE_R4
#define SD_RSP_TYPE_R5
#define SD_RSP_TYPE_R6
#define SD_RSP_TYPE_R7

/* SD_STAT1 */
#define SD_CRC7_ERR
#define SD_CRC16_ERR
#define SD_CRC_WRITE_ERR
#define SD_CRC_WRITE_ERR_MASK
#define GET_CRC_TIME_OUT
#define SD_TUNING_COMPARE_ERR

/* SD_DATA_STATE */
#define SD_DATA_IDLE

/* CARD_DATA_SOURCE */
#define PINGPONG_BUFFER
#define RING_BUFFER

/* CARD_OE */
#define SD_OUTPUT_EN
#define MS_OUTPUT_EN

/* CARD_STOP */
#define SD_STOP
#define MS_STOP
#define SD_CLR_ERR
#define MS_CLR_ERR

/* CARD_CLK_SOURCE */
#define CRC_FIX_CLK
#define CRC_VAR_CLK0
#define CRC_VAR_CLK1
#define SD30_FIX_CLK
#define SD30_VAR_CLK0
#define SD30_VAR_CLK1
#define SAMPLE_FIX_CLK
#define SAMPLE_VAR_CLK0
#define SAMPLE_VAR_CLK1

/* SD_SAMPLE_POINT_CTL */
#define DDR_FIX_RX_DAT
#define DDR_VAR_RX_DAT
#define DDR_FIX_RX_DAT_EDGE
#define DDR_FIX_RX_DAT_14_DELAY
#define DDR_FIX_RX_CMD
#define DDR_VAR_RX_CMD
#define DDR_FIX_RX_CMD_POS_EDGE
#define DDR_FIX_RX_CMD_14_DELAY
#define SD20_RX_POS_EDGE
#define SD20_RX_14_DELAY
#define SD20_RX_SEL_MASK

/* SD_PUSH_POINT_CTL */
#define DDR_FIX_TX_CMD_DAT
#define DDR_VAR_TX_CMD_DAT
#define DDR_FIX_TX_DAT_14_TSU
#define DDR_FIX_TX_DAT_12_TSU
#define DDR_FIX_TX_CMD_NEG_EDGE
#define DDR_FIX_TX_CMD_14_AHEAD
#define SD20_TX_NEG_EDGE
#define SD20_TX_14_AHEAD
#define SD20_TX_SEL_MASK
#define DDR_VAR_SDCLK_POL_SWAP

/* MS_CFG */
#define SAMPLE_TIME_RISING
#define SAMPLE_TIME_FALLING
#define PUSH_TIME_DEFAULT
#define PUSH_TIME_ODD
#define NO_EXTEND_TOGGLE
#define EXTEND_TOGGLE_CHK
#define MS_BUS_WIDTH_1
#define MS_BUS_WIDTH_4
#define MS_BUS_WIDTH_8
#define MS_2K_SECTOR_MODE
#define MS_512_SECTOR_MODE
#define MS_TOGGLE_TIMEOUT_EN
#define MS_TOGGLE_TIMEOUT_DISEN
#define MS_NO_CHECK_INT

/* MS_TRANS_CFG */
#define WAIT_INT
#define NO_WAIT_INT
#define NO_AUTO_READ_INT_REG
#define AUTO_READ_INT_REG
#define MS_CRC16_ERR
#define MS_RDY_TIMEOUT
#define MS_INT_CMDNK
#define MS_INT_BREQ
#define MS_INT_ERR
#define MS_INT_CED

/* MS_TRANSFER */
#define MS_TRANSFER_START
#define MS_TRANSFER_END
#define MS_TRANSFER_ERR
#define MS_BS_STATE
#define MS_TM_READ_BYTES
#define MS_TM_NORMAL_READ
#define MS_TM_WRITE_BYTES
#define MS_TM_NORMAL_WRITE
#define MS_TM_AUTO_READ
#define MS_TM_AUTO_WRITE
#define MS_TM_SET_CMD
#define MS_TM_COPY_PAGE
#define MS_TM_MULTI_READ
#define MS_TM_MULTI_WRITE

/* MC_FIFO_CTL */
#define FIFO_FLUSH

/* MC_DMA_RST */
#define DMA_RESET

/* MC_DMA_CTL */
#define DMA_TC_EQ_0
#define DMA_DIR_TO_CARD
#define DMA_DIR_FROM_CARD
#define DMA_EN
#define DMA_128
#define DMA_256
#define DMA_512
#define DMA_1024
#define DMA_PACK_SIZE_MASK

/* CARD_INT_PEND */
#define XD_INT
#define MS_INT
#define SD_INT

/* LED operations*/
static inline int rtsx_usb_turn_on_led(struct rtsx_ucr *ucr)
{}

static inline int rtsx_usb_turn_off_led(struct rtsx_ucr *ucr)
{}

/* HW error clearing */
static inline void rtsx_usb_clear_fsm_err(struct rtsx_ucr *ucr)
{}

static inline void rtsx_usb_clear_dma_err(struct rtsx_ucr *ucr)
{}
#endif /* __RTS51139_H */