18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Realtek RTL28xxU DVB USB driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
68c2ecf20Sopenharmony_ci * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef RTL28XXU_H
108c2ecf20Sopenharmony_ci#define RTL28XXU_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include "dvb_usb.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "rtl2830.h"
178c2ecf20Sopenharmony_ci#include "rtl2832.h"
188c2ecf20Sopenharmony_ci#include "rtl2832_sdr.h"
198c2ecf20Sopenharmony_ci#include "mn88472.h"
208c2ecf20Sopenharmony_ci#include "mn88473.h"
218c2ecf20Sopenharmony_ci#include "cxd2841er.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include "qt1010.h"
248c2ecf20Sopenharmony_ci#include "mt2060.h"
258c2ecf20Sopenharmony_ci#include "mxl5005s.h"
268c2ecf20Sopenharmony_ci#include "fc0012.h"
278c2ecf20Sopenharmony_ci#include "fc0013.h"
288c2ecf20Sopenharmony_ci#include "e4000.h"
298c2ecf20Sopenharmony_ci#include "fc2580.h"
308c2ecf20Sopenharmony_ci#include "tua9001.h"
318c2ecf20Sopenharmony_ci#include "r820t.h"
328c2ecf20Sopenharmony_ci#include "si2168.h"
338c2ecf20Sopenharmony_ci#include "si2157.h"
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/*
368c2ecf20Sopenharmony_ci * USB commands
378c2ecf20Sopenharmony_ci * (usb_control_msg() index parameter)
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define DEMOD            0x0000
418c2ecf20Sopenharmony_ci#define USB              0x0100
428c2ecf20Sopenharmony_ci#define SYS              0x0200
438c2ecf20Sopenharmony_ci#define I2C              0x0300
448c2ecf20Sopenharmony_ci#define I2C_DA           0x0600
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define CMD_WR_FLAG      0x0010
478c2ecf20Sopenharmony_ci#define CMD_DEMOD_RD     0x0000
488c2ecf20Sopenharmony_ci#define CMD_DEMOD_WR     0x0010
498c2ecf20Sopenharmony_ci#define CMD_USB_RD       0x0100
508c2ecf20Sopenharmony_ci#define CMD_USB_WR       0x0110
518c2ecf20Sopenharmony_ci#define CMD_SYS_RD       0x0200
528c2ecf20Sopenharmony_ci#define CMD_IR_RD        0x0201
538c2ecf20Sopenharmony_ci#define CMD_IR_WR        0x0211
548c2ecf20Sopenharmony_ci#define CMD_SYS_WR       0x0210
558c2ecf20Sopenharmony_ci#define CMD_I2C_RD       0x0300
568c2ecf20Sopenharmony_ci#define CMD_I2C_WR       0x0310
578c2ecf20Sopenharmony_ci#define CMD_I2C_DA_RD    0x0600
588c2ecf20Sopenharmony_ci#define CMD_I2C_DA_WR    0x0610
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistruct rtl28xxu_dev {
628c2ecf20Sopenharmony_ci	u8 buf[128];
638c2ecf20Sopenharmony_ci	u8 chip_id;
648c2ecf20Sopenharmony_ci	u8 tuner;
658c2ecf20Sopenharmony_ci	char *tuner_name;
668c2ecf20Sopenharmony_ci	u8 page; /* integrated demod active register page */
678c2ecf20Sopenharmony_ci	struct i2c_adapter *demod_i2c_adapter;
688c2ecf20Sopenharmony_ci	bool rc_active;
698c2ecf20Sopenharmony_ci	bool new_i2c_write;
708c2ecf20Sopenharmony_ci	struct i2c_client *i2c_client_demod;
718c2ecf20Sopenharmony_ci	struct i2c_client *i2c_client_tuner;
728c2ecf20Sopenharmony_ci	struct i2c_client *i2c_client_slave_demod;
738c2ecf20Sopenharmony_ci	struct platform_device *platform_device_sdr;
748c2ecf20Sopenharmony_ci	#define SLAVE_DEMOD_NONE           0
758c2ecf20Sopenharmony_ci	#define SLAVE_DEMOD_MN88472        1
768c2ecf20Sopenharmony_ci	#define SLAVE_DEMOD_MN88473        2
778c2ecf20Sopenharmony_ci	#define SLAVE_DEMOD_SI2168         3
788c2ecf20Sopenharmony_ci	#define SLAVE_DEMOD_CXD2837ER      4
798c2ecf20Sopenharmony_ci	unsigned int slave_demod:3;
808c2ecf20Sopenharmony_ci	union {
818c2ecf20Sopenharmony_ci		struct rtl2830_platform_data rtl2830_platform_data;
828c2ecf20Sopenharmony_ci		struct rtl2832_platform_data rtl2832_platform_data;
838c2ecf20Sopenharmony_ci	};
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cienum rtl28xxu_chip_id {
878c2ecf20Sopenharmony_ci	CHIP_ID_NONE,
888c2ecf20Sopenharmony_ci	CHIP_ID_RTL2831U,
898c2ecf20Sopenharmony_ci	CHIP_ID_RTL2832U,
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* XXX: Hack. This must be keep sync with rtl2832 demod driver. */
938c2ecf20Sopenharmony_cienum rtl28xxu_tuner {
948c2ecf20Sopenharmony_ci	TUNER_NONE,
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	TUNER_RTL2830_QT1010          = 0x10,
978c2ecf20Sopenharmony_ci	TUNER_RTL2830_MT2060,
988c2ecf20Sopenharmony_ci	TUNER_RTL2830_MXL5005S,
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	TUNER_RTL2832_MT2266          = 0x20,
1018c2ecf20Sopenharmony_ci	TUNER_RTL2832_FC2580,
1028c2ecf20Sopenharmony_ci	TUNER_RTL2832_MT2063,
1038c2ecf20Sopenharmony_ci	TUNER_RTL2832_MAX3543,
1048c2ecf20Sopenharmony_ci	TUNER_RTL2832_TUA9001,
1058c2ecf20Sopenharmony_ci	TUNER_RTL2832_MXL5007T,
1068c2ecf20Sopenharmony_ci	TUNER_RTL2832_FC0012,
1078c2ecf20Sopenharmony_ci	TUNER_RTL2832_E4000,
1088c2ecf20Sopenharmony_ci	TUNER_RTL2832_TDA18272,
1098c2ecf20Sopenharmony_ci	TUNER_RTL2832_FC0013,
1108c2ecf20Sopenharmony_ci	TUNER_RTL2832_R820T,
1118c2ecf20Sopenharmony_ci	TUNER_RTL2832_R828D,
1128c2ecf20Sopenharmony_ci	TUNER_RTL2832_SI2157,
1138c2ecf20Sopenharmony_ci};
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistruct rtl28xxu_req {
1168c2ecf20Sopenharmony_ci	u16 value;
1178c2ecf20Sopenharmony_ci	u16 index;
1188c2ecf20Sopenharmony_ci	u16 size;
1198c2ecf20Sopenharmony_ci	u8 *data;
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistruct rtl28xxu_reg_val {
1238c2ecf20Sopenharmony_ci	u16 reg;
1248c2ecf20Sopenharmony_ci	u8 val;
1258c2ecf20Sopenharmony_ci};
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistruct rtl28xxu_reg_val_mask {
1288c2ecf20Sopenharmony_ci	u16 reg;
1298c2ecf20Sopenharmony_ci	u8 val;
1308c2ecf20Sopenharmony_ci	u8 mask;
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/*
1348c2ecf20Sopenharmony_ci * memory map
1358c2ecf20Sopenharmony_ci *
1368c2ecf20Sopenharmony_ci * 0x0000 DEMOD : demodulator
1378c2ecf20Sopenharmony_ci * 0x2000 USB   : SIE, USB endpoint, debug, DMA
1388c2ecf20Sopenharmony_ci * 0x3000 SYS   : system
1398c2ecf20Sopenharmony_ci * 0xfc00 RC    : remote controller (not RTL2831U)
1408c2ecf20Sopenharmony_ci */
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/*
1438c2ecf20Sopenharmony_ci * USB registers
1448c2ecf20Sopenharmony_ci */
1458c2ecf20Sopenharmony_ci/* SIE Control Registers */
1468c2ecf20Sopenharmony_ci#define USB_SYSCTL         0x2000 /* USB system control */
1478c2ecf20Sopenharmony_ci#define USB_SYSCTL_0       0x2000 /* USB system control */
1488c2ecf20Sopenharmony_ci#define USB_SYSCTL_1       0x2001 /* USB system control */
1498c2ecf20Sopenharmony_ci#define USB_SYSCTL_2       0x2002 /* USB system control */
1508c2ecf20Sopenharmony_ci#define USB_SYSCTL_3       0x2003 /* USB system control */
1518c2ecf20Sopenharmony_ci#define USB_IRQSTAT        0x2008 /* SIE interrupt status */
1528c2ecf20Sopenharmony_ci#define USB_IRQEN          0x200C /* SIE interrupt enable */
1538c2ecf20Sopenharmony_ci#define USB_CTRL           0x2010 /* USB control */
1548c2ecf20Sopenharmony_ci#define USB_STAT           0x2014 /* USB status */
1558c2ecf20Sopenharmony_ci#define USB_DEVADDR        0x2018 /* USB device address */
1568c2ecf20Sopenharmony_ci#define USB_TEST           0x201C /* USB test mode */
1578c2ecf20Sopenharmony_ci#define USB_FRAME_NUMBER   0x2020 /* frame number */
1588c2ecf20Sopenharmony_ci#define USB_FIFO_ADDR      0x2028 /* address of SIE FIFO RAM */
1598c2ecf20Sopenharmony_ci#define USB_FIFO_CMD       0x202A /* SIE FIFO RAM access command */
1608c2ecf20Sopenharmony_ci#define USB_FIFO_DATA      0x2030 /* SIE FIFO RAM data */
1618c2ecf20Sopenharmony_ci/* Endpoint Registers */
1628c2ecf20Sopenharmony_ci#define EP0_SETUPA         0x20F8 /* EP 0 setup packet lower byte */
1638c2ecf20Sopenharmony_ci#define EP0_SETUPB         0x20FC /* EP 0 setup packet higher byte */
1648c2ecf20Sopenharmony_ci#define USB_EP0_CFG        0x2104 /* EP 0 configure */
1658c2ecf20Sopenharmony_ci#define USB_EP0_CTL        0x2108 /* EP 0 control */
1668c2ecf20Sopenharmony_ci#define USB_EP0_STAT       0x210C /* EP 0 status */
1678c2ecf20Sopenharmony_ci#define USB_EP0_IRQSTAT    0x2110 /* EP 0 interrupt status */
1688c2ecf20Sopenharmony_ci#define USB_EP0_IRQEN      0x2114 /* EP 0 interrupt enable */
1698c2ecf20Sopenharmony_ci#define USB_EP0_MAXPKT     0x2118 /* EP 0 max packet size */
1708c2ecf20Sopenharmony_ci#define USB_EP0_BC         0x2120 /* EP 0 FIFO byte counter */
1718c2ecf20Sopenharmony_ci#define USB_EPA_CFG        0x2144 /* EP A configure */
1728c2ecf20Sopenharmony_ci#define USB_EPA_CFG_0      0x2144 /* EP A configure */
1738c2ecf20Sopenharmony_ci#define USB_EPA_CFG_1      0x2145 /* EP A configure */
1748c2ecf20Sopenharmony_ci#define USB_EPA_CFG_2      0x2146 /* EP A configure */
1758c2ecf20Sopenharmony_ci#define USB_EPA_CFG_3      0x2147 /* EP A configure */
1768c2ecf20Sopenharmony_ci#define USB_EPA_CTL        0x2148 /* EP A control */
1778c2ecf20Sopenharmony_ci#define USB_EPA_CTL_0      0x2148 /* EP A control */
1788c2ecf20Sopenharmony_ci#define USB_EPA_CTL_1      0x2149 /* EP A control */
1798c2ecf20Sopenharmony_ci#define USB_EPA_CTL_2      0x214A /* EP A control */
1808c2ecf20Sopenharmony_ci#define USB_EPA_CTL_3      0x214B /* EP A control */
1818c2ecf20Sopenharmony_ci#define USB_EPA_STAT       0x214C /* EP A status */
1828c2ecf20Sopenharmony_ci#define USB_EPA_IRQSTAT    0x2150 /* EP A interrupt status */
1838c2ecf20Sopenharmony_ci#define USB_EPA_IRQEN      0x2154 /* EP A interrupt enable */
1848c2ecf20Sopenharmony_ci#define USB_EPA_MAXPKT     0x2158 /* EP A max packet size */
1858c2ecf20Sopenharmony_ci#define USB_EPA_MAXPKT_0   0x2158 /* EP A max packet size */
1868c2ecf20Sopenharmony_ci#define USB_EPA_MAXPKT_1   0x2159 /* EP A max packet size */
1878c2ecf20Sopenharmony_ci#define USB_EPA_MAXPKT_2   0x215A /* EP A max packet size */
1888c2ecf20Sopenharmony_ci#define USB_EPA_MAXPKT_3   0x215B /* EP A max packet size */
1898c2ecf20Sopenharmony_ci#define USB_EPA_FIFO_CFG   0x2160 /* EP A FIFO configure */
1908c2ecf20Sopenharmony_ci#define USB_EPA_FIFO_CFG_0 0x2160 /* EP A FIFO configure */
1918c2ecf20Sopenharmony_ci#define USB_EPA_FIFO_CFG_1 0x2161 /* EP A FIFO configure */
1928c2ecf20Sopenharmony_ci#define USB_EPA_FIFO_CFG_2 0x2162 /* EP A FIFO configure */
1938c2ecf20Sopenharmony_ci#define USB_EPA_FIFO_CFG_3 0x2163 /* EP A FIFO configure */
1948c2ecf20Sopenharmony_ci/* Debug Registers */
1958c2ecf20Sopenharmony_ci#define USB_PHYTSTDIS      0x2F04 /* PHY test disable */
1968c2ecf20Sopenharmony_ci#define USB_TOUT_VAL       0x2F08 /* USB time-out time */
1978c2ecf20Sopenharmony_ci#define USB_VDRCTRL        0x2F10 /* UTMI vendor signal control */
1988c2ecf20Sopenharmony_ci#define USB_VSTAIN         0x2F14 /* UTMI vendor signal status in */
1998c2ecf20Sopenharmony_ci#define USB_VLOADM         0x2F18 /* UTMI load vendor signal status in */
2008c2ecf20Sopenharmony_ci#define USB_VSTAOUT        0x2F1C /* UTMI vendor signal status out */
2018c2ecf20Sopenharmony_ci#define USB_UTMI_TST       0x2F80 /* UTMI test */
2028c2ecf20Sopenharmony_ci#define USB_UTMI_STATUS    0x2F84 /* UTMI status */
2038c2ecf20Sopenharmony_ci#define USB_TSTCTL         0x2F88 /* test control */
2048c2ecf20Sopenharmony_ci#define USB_TSTCTL2        0x2F8C /* test control 2 */
2058c2ecf20Sopenharmony_ci#define USB_PID_FORCE      0x2F90 /* force PID */
2068c2ecf20Sopenharmony_ci#define USB_PKTERR_CNT     0x2F94 /* packet error counter */
2078c2ecf20Sopenharmony_ci#define USB_RXERR_CNT      0x2F98 /* RX error counter */
2088c2ecf20Sopenharmony_ci#define USB_MEM_BIST       0x2F9C /* MEM BIST test */
2098c2ecf20Sopenharmony_ci#define USB_SLBBIST        0x2FA0 /* self-loop-back BIST */
2108c2ecf20Sopenharmony_ci#define USB_CNTTEST        0x2FA4 /* counter test */
2118c2ecf20Sopenharmony_ci#define USB_PHYTST         0x2FC0 /* USB PHY test */
2128c2ecf20Sopenharmony_ci#define USB_DBGIDX         0x2FF0 /* select individual block debug signal */
2138c2ecf20Sopenharmony_ci#define USB_DBGMUX         0x2FF4 /* debug signal module mux */
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci/*
2168c2ecf20Sopenharmony_ci * SYS registers
2178c2ecf20Sopenharmony_ci */
2188c2ecf20Sopenharmony_ci/* demod control registers */
2198c2ecf20Sopenharmony_ci#define SYS_SYS0           0x3000 /* include DEMOD_CTL, GPO, GPI, GPOE */
2208c2ecf20Sopenharmony_ci#define SYS_DEMOD_CTL      0x3000 /* control register for DVB-T demodulator */
2218c2ecf20Sopenharmony_ci/* GPIO registers */
2228c2ecf20Sopenharmony_ci#define SYS_GPIO_OUT_VAL   0x3001 /* output value of GPIO */
2238c2ecf20Sopenharmony_ci#define SYS_GPIO_IN_VAL    0x3002 /* input value of GPIO */
2248c2ecf20Sopenharmony_ci#define SYS_GPIO_OUT_EN    0x3003 /* output enable of GPIO */
2258c2ecf20Sopenharmony_ci#define SYS_SYS1           0x3004 /* include GPD, SYSINTE, SYSINTS, GP_CFG0 */
2268c2ecf20Sopenharmony_ci#define SYS_GPIO_DIR       0x3004 /* direction control for GPIO */
2278c2ecf20Sopenharmony_ci#define SYS_SYSINTE        0x3005 /* system interrupt enable */
2288c2ecf20Sopenharmony_ci#define SYS_SYSINTS        0x3006 /* system interrupt status */
2298c2ecf20Sopenharmony_ci#define SYS_GPIO_CFG0      0x3007 /* PAD configuration for GPIO0-GPIO3 */
2308c2ecf20Sopenharmony_ci#define SYS_SYS2           0x3008 /* include GP_CFG1 and 3 reserved bytes */
2318c2ecf20Sopenharmony_ci#define SYS_GPIO_CFG1      0x3008 /* PAD configuration for GPIO4 */
2328c2ecf20Sopenharmony_ci#define SYS_DEMOD_CTL1     0x300B
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci/* IrDA registers */
2358c2ecf20Sopenharmony_ci#define SYS_IRRC_PSR       0x3020 /* IR protocol selection */
2368c2ecf20Sopenharmony_ci#define SYS_IRRC_PER       0x3024 /* IR protocol extension */
2378c2ecf20Sopenharmony_ci#define SYS_IRRC_SF        0x3028 /* IR sampling frequency */
2388c2ecf20Sopenharmony_ci#define SYS_IRRC_DPIR      0x302C /* IR data package interval */
2398c2ecf20Sopenharmony_ci#define SYS_IRRC_CR        0x3030 /* IR control */
2408c2ecf20Sopenharmony_ci#define SYS_IRRC_RP        0x3034 /* IR read port */
2418c2ecf20Sopenharmony_ci#define SYS_IRRC_SR        0x3038 /* IR status */
2428c2ecf20Sopenharmony_ci/* I2C master registers */
2438c2ecf20Sopenharmony_ci#define SYS_I2CCR          0x3040 /* I2C clock */
2448c2ecf20Sopenharmony_ci#define SYS_I2CMCR         0x3044 /* I2C master control */
2458c2ecf20Sopenharmony_ci#define SYS_I2CMSTR        0x3048 /* I2C master SCL timing */
2468c2ecf20Sopenharmony_ci#define SYS_I2CMSR         0x304C /* I2C master status */
2478c2ecf20Sopenharmony_ci#define SYS_I2CMFR         0x3050 /* I2C master FIFO */
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci/*
2508c2ecf20Sopenharmony_ci * IR registers
2518c2ecf20Sopenharmony_ci */
2528c2ecf20Sopenharmony_ci#define IR_RX_BUF          0xFC00
2538c2ecf20Sopenharmony_ci#define IR_RX_IE           0xFD00
2548c2ecf20Sopenharmony_ci#define IR_RX_IF           0xFD01
2558c2ecf20Sopenharmony_ci#define IR_RX_CTRL         0xFD02
2568c2ecf20Sopenharmony_ci#define IR_RX_CFG          0xFD03
2578c2ecf20Sopenharmony_ci#define IR_MAX_DURATION0   0xFD04
2588c2ecf20Sopenharmony_ci#define IR_MAX_DURATION1   0xFD05
2598c2ecf20Sopenharmony_ci#define IR_IDLE_LEN0       0xFD06
2608c2ecf20Sopenharmony_ci#define IR_IDLE_LEN1       0xFD07
2618c2ecf20Sopenharmony_ci#define IR_GLITCH_LEN      0xFD08
2628c2ecf20Sopenharmony_ci#define IR_RX_BUF_CTRL     0xFD09
2638c2ecf20Sopenharmony_ci#define IR_RX_BUF_DATA     0xFD0A
2648c2ecf20Sopenharmony_ci#define IR_RX_BC           0xFD0B
2658c2ecf20Sopenharmony_ci#define IR_RX_CLK          0xFD0C
2668c2ecf20Sopenharmony_ci#define IR_RX_C_COUNT_L    0xFD0D
2678c2ecf20Sopenharmony_ci#define IR_RX_C_COUNT_H    0xFD0E
2688c2ecf20Sopenharmony_ci#define IR_SUSPEND_CTRL    0xFD10
2698c2ecf20Sopenharmony_ci#define IR_ERR_TOL_CTRL    0xFD11
2708c2ecf20Sopenharmony_ci#define IR_UNIT_LEN        0xFD12
2718c2ecf20Sopenharmony_ci#define IR_ERR_TOL_LEN     0xFD13
2728c2ecf20Sopenharmony_ci#define IR_MAX_H_TOL_LEN   0xFD14
2738c2ecf20Sopenharmony_ci#define IR_MAX_L_TOL_LEN   0xFD15
2748c2ecf20Sopenharmony_ci#define IR_MASK_CTRL       0xFD16
2758c2ecf20Sopenharmony_ci#define IR_MASK_DATA       0xFD17
2768c2ecf20Sopenharmony_ci#define IR_RES_MASK_ADDR   0xFD18
2778c2ecf20Sopenharmony_ci#define IR_RES_MASK_T_LEN  0xFD19
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci#endif
280