18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Thanks to Afatech who kindly provided information.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef AF9015_H
118c2ecf20Sopenharmony_ci#define AF9015_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/hash.h>
148c2ecf20Sopenharmony_ci#include <linux/regmap.h>
158c2ecf20Sopenharmony_ci#include "dvb_usb.h"
168c2ecf20Sopenharmony_ci#include "af9013.h"
178c2ecf20Sopenharmony_ci#include "dvb-pll.h"
188c2ecf20Sopenharmony_ci#include "mt2060.h"
198c2ecf20Sopenharmony_ci#include "qt1010.h"
208c2ecf20Sopenharmony_ci#include "tda18271.h"
218c2ecf20Sopenharmony_ci#include "mxl5005s.h"
228c2ecf20Sopenharmony_ci#include "mc44s803.h"
238c2ecf20Sopenharmony_ci#include "tda18218.h"
248c2ecf20Sopenharmony_ci#include "mxl5007t.h"
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define AF9015_FIRMWARE "dvb-usb-af9015.fw"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define AF9015_I2C_EEPROM  0x50
298c2ecf20Sopenharmony_ci#define AF9015_I2C_DEMOD   0x1c
308c2ecf20Sopenharmony_ci#define AF9015_USB_TIMEOUT 2000
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* EEPROM locations */
338c2ecf20Sopenharmony_ci#define AF9015_EEPROM_IR_MODE        0x18
348c2ecf20Sopenharmony_ci#define AF9015_EEPROM_IR_REMOTE_TYPE 0x34
358c2ecf20Sopenharmony_ci#define AF9015_EEPROM_TS_MODE        0x31
368c2ecf20Sopenharmony_ci#define AF9015_EEPROM_DEMOD2_I2C     0x32
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define AF9015_EEPROM_SAW_BW1        0x35
398c2ecf20Sopenharmony_ci#define AF9015_EEPROM_XTAL_TYPE1     0x36
408c2ecf20Sopenharmony_ci#define AF9015_EEPROM_SPEC_INV1      0x37
418c2ecf20Sopenharmony_ci#define AF9015_EEPROM_IF1L           0x38
428c2ecf20Sopenharmony_ci#define AF9015_EEPROM_IF1H           0x39
438c2ecf20Sopenharmony_ci#define AF9015_EEPROM_MT2060_IF1L    0x3a
448c2ecf20Sopenharmony_ci#define AF9015_EEPROM_MT2060_IF1H    0x3b
458c2ecf20Sopenharmony_ci#define AF9015_EEPROM_TUNER_ID1      0x3c
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define AF9015_EEPROM_SAW_BW2        0x45
488c2ecf20Sopenharmony_ci#define AF9015_EEPROM_XTAL_TYPE2     0x46
498c2ecf20Sopenharmony_ci#define AF9015_EEPROM_SPEC_INV2      0x47
508c2ecf20Sopenharmony_ci#define AF9015_EEPROM_IF2L           0x48
518c2ecf20Sopenharmony_ci#define AF9015_EEPROM_IF2H           0x49
528c2ecf20Sopenharmony_ci#define AF9015_EEPROM_MT2060_IF2L    0x4a
538c2ecf20Sopenharmony_ci#define AF9015_EEPROM_MT2060_IF2H    0x4b
548c2ecf20Sopenharmony_ci#define AF9015_EEPROM_TUNER_ID2      0x4c
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define AF9015_EEPROM_OFFSET (AF9015_EEPROM_SAW_BW2 - AF9015_EEPROM_SAW_BW1)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct req_t {
598c2ecf20Sopenharmony_ci	u8  cmd;       /* [0] */
608c2ecf20Sopenharmony_ci	/*  seq */     /* [1] */
618c2ecf20Sopenharmony_ci	u8  i2c_addr;  /* [2] */
628c2ecf20Sopenharmony_ci	u16 addr;      /* [3|4] */
638c2ecf20Sopenharmony_ci	u8  mbox;      /* [5] */
648c2ecf20Sopenharmony_ci	u8  addr_len;  /* [6] */
658c2ecf20Sopenharmony_ci	u8  data_len;  /* [7] */
668c2ecf20Sopenharmony_ci	u8  *data;
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cienum af9015_cmd {
708c2ecf20Sopenharmony_ci	GET_CONFIG           = 0x10,
718c2ecf20Sopenharmony_ci	DOWNLOAD_FIRMWARE    = 0x11,
728c2ecf20Sopenharmony_ci	BOOT                 = 0x13,
738c2ecf20Sopenharmony_ci	READ_MEMORY          = 0x20,
748c2ecf20Sopenharmony_ci	WRITE_MEMORY         = 0x21,
758c2ecf20Sopenharmony_ci	READ_WRITE_I2C       = 0x22,
768c2ecf20Sopenharmony_ci	COPY_FIRMWARE        = 0x23,
778c2ecf20Sopenharmony_ci	RECONNECT_USB        = 0x5a,
788c2ecf20Sopenharmony_ci	WRITE_VIRTUAL_MEMORY = 0x26,
798c2ecf20Sopenharmony_ci	GET_IR_CODE          = 0x27,
808c2ecf20Sopenharmony_ci	READ_I2C,
818c2ecf20Sopenharmony_ci	WRITE_I2C,
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cienum af9015_ir_mode {
858c2ecf20Sopenharmony_ci	AF9015_IR_MODE_DISABLED = 0,
868c2ecf20Sopenharmony_ci	AF9015_IR_MODE_HID,
878c2ecf20Sopenharmony_ci	AF9015_IR_MODE_RLC,
888c2ecf20Sopenharmony_ci	AF9015_IR_MODE_RC6,
898c2ecf20Sopenharmony_ci	AF9015_IR_MODE_POLLING, /* just guess */
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define BUF_LEN 63
938c2ecf20Sopenharmony_cistruct af9015_state {
948c2ecf20Sopenharmony_ci	struct regmap *regmap;
958c2ecf20Sopenharmony_ci	u8 buf[BUF_LEN]; /* bulk USB control message */
968c2ecf20Sopenharmony_ci	u8 ir_mode;
978c2ecf20Sopenharmony_ci	u8 rc_repeat;
988c2ecf20Sopenharmony_ci	u32 rc_keycode;
998c2ecf20Sopenharmony_ci	u8 rc_last[4];
1008c2ecf20Sopenharmony_ci	bool rc_failed;
1018c2ecf20Sopenharmony_ci	u8 dual_mode;
1028c2ecf20Sopenharmony_ci	u8 seq; /* packet sequence number */
1038c2ecf20Sopenharmony_ci	u16 mt2060_if1[2];
1048c2ecf20Sopenharmony_ci	u16 firmware_size;
1058c2ecf20Sopenharmony_ci	u16 firmware_checksum;
1068c2ecf20Sopenharmony_ci	u32 eeprom_sum;
1078c2ecf20Sopenharmony_ci	struct af9013_platform_data af9013_pdata[2];
1088c2ecf20Sopenharmony_ci	struct i2c_client *demod_i2c_client[2];
1098c2ecf20Sopenharmony_ci	u8 af9013_i2c_addr[2];
1108c2ecf20Sopenharmony_ci	bool usb_ts_if_configured[2];
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	/* for demod callback override */
1138c2ecf20Sopenharmony_ci	int (*set_frontend[2]) (struct dvb_frontend *fe);
1148c2ecf20Sopenharmony_ci	int (*read_status[2]) (struct dvb_frontend *fe, enum fe_status *status);
1158c2ecf20Sopenharmony_ci	int (*init[2]) (struct dvb_frontend *fe);
1168c2ecf20Sopenharmony_ci	int (*sleep[2]) (struct dvb_frontend *fe);
1178c2ecf20Sopenharmony_ci	int (*tuner_init[2]) (struct dvb_frontend *fe);
1188c2ecf20Sopenharmony_ci	int (*tuner_sleep[2]) (struct dvb_frontend *fe);
1198c2ecf20Sopenharmony_ci	struct mutex fe_mutex;
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cienum af9015_remote {
1238c2ecf20Sopenharmony_ci	AF9015_REMOTE_NONE                    = 0,
1248c2ecf20Sopenharmony_ci/* 1 */	AF9015_REMOTE_A_LINK_DTU_M,
1258c2ecf20Sopenharmony_ci	AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
1268c2ecf20Sopenharmony_ci	AF9015_REMOTE_MYGICTV_U718,
1278c2ecf20Sopenharmony_ci	AF9015_REMOTE_DIGITTRADE_DVB_T,
1288c2ecf20Sopenharmony_ci/* 5 */	AF9015_REMOTE_AVERMEDIA_KS,
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci#endif
132