1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
4  *
5  * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
6  *
7  * Thanks to Afatech who kindly provided information.
8  */
9 
10 #ifndef AF9015_H
11 #define AF9015_H
12 
13 #include <linux/hash.h>
14 #include <linux/regmap.h>
15 #include "dvb_usb.h"
16 #include "af9013.h"
17 #include "dvb-pll.h"
18 #include "mt2060.h"
19 #include "qt1010.h"
20 #include "tda18271.h"
21 #include "mxl5005s.h"
22 #include "mc44s803.h"
23 #include "tda18218.h"
24 #include "mxl5007t.h"
25 
26 #define AF9015_FIRMWARE "dvb-usb-af9015.fw"
27 
28 #define AF9015_I2C_EEPROM  0x50
29 #define AF9015_I2C_DEMOD   0x1c
30 #define AF9015_USB_TIMEOUT 2000
31 
32 /* EEPROM locations */
33 #define AF9015_EEPROM_IR_MODE        0x18
34 #define AF9015_EEPROM_IR_REMOTE_TYPE 0x34
35 #define AF9015_EEPROM_TS_MODE        0x31
36 #define AF9015_EEPROM_DEMOD2_I2C     0x32
37 
38 #define AF9015_EEPROM_SAW_BW1        0x35
39 #define AF9015_EEPROM_XTAL_TYPE1     0x36
40 #define AF9015_EEPROM_SPEC_INV1      0x37
41 #define AF9015_EEPROM_IF1L           0x38
42 #define AF9015_EEPROM_IF1H           0x39
43 #define AF9015_EEPROM_MT2060_IF1L    0x3a
44 #define AF9015_EEPROM_MT2060_IF1H    0x3b
45 #define AF9015_EEPROM_TUNER_ID1      0x3c
46 
47 #define AF9015_EEPROM_SAW_BW2        0x45
48 #define AF9015_EEPROM_XTAL_TYPE2     0x46
49 #define AF9015_EEPROM_SPEC_INV2      0x47
50 #define AF9015_EEPROM_IF2L           0x48
51 #define AF9015_EEPROM_IF2H           0x49
52 #define AF9015_EEPROM_MT2060_IF2L    0x4a
53 #define AF9015_EEPROM_MT2060_IF2H    0x4b
54 #define AF9015_EEPROM_TUNER_ID2      0x4c
55 
56 #define AF9015_EEPROM_OFFSET (AF9015_EEPROM_SAW_BW2 - AF9015_EEPROM_SAW_BW1)
57 
58 struct req_t {
59 	u8  cmd;       /* [0] */
60 	/*  seq */     /* [1] */
61 	u8  i2c_addr;  /* [2] */
62 	u16 addr;      /* [3|4] */
63 	u8  mbox;      /* [5] */
64 	u8  addr_len;  /* [6] */
65 	u8  data_len;  /* [7] */
66 	u8  *data;
67 };
68 
69 enum af9015_cmd {
70 	GET_CONFIG           = 0x10,
71 	DOWNLOAD_FIRMWARE    = 0x11,
72 	BOOT                 = 0x13,
73 	READ_MEMORY          = 0x20,
74 	WRITE_MEMORY         = 0x21,
75 	READ_WRITE_I2C       = 0x22,
76 	COPY_FIRMWARE        = 0x23,
77 	RECONNECT_USB        = 0x5a,
78 	WRITE_VIRTUAL_MEMORY = 0x26,
79 	GET_IR_CODE          = 0x27,
80 	READ_I2C,
81 	WRITE_I2C,
82 };
83 
84 enum af9015_ir_mode {
85 	AF9015_IR_MODE_DISABLED = 0,
86 	AF9015_IR_MODE_HID,
87 	AF9015_IR_MODE_RLC,
88 	AF9015_IR_MODE_RC6,
89 	AF9015_IR_MODE_POLLING, /* just guess */
90 };
91 
92 #define BUF_LEN 63
93 struct af9015_state {
94 	struct regmap *regmap;
95 	u8 buf[BUF_LEN]; /* bulk USB control message */
96 	u8 ir_mode;
97 	u8 rc_repeat;
98 	u32 rc_keycode;
99 	u8 rc_last[4];
100 	bool rc_failed;
101 	u8 dual_mode;
102 	u8 seq; /* packet sequence number */
103 	u16 mt2060_if1[2];
104 	u16 firmware_size;
105 	u16 firmware_checksum;
106 	u32 eeprom_sum;
107 	struct af9013_platform_data af9013_pdata[2];
108 	struct i2c_client *demod_i2c_client[2];
109 	u8 af9013_i2c_addr[2];
110 	bool usb_ts_if_configured[2];
111 
112 	/* for demod callback override */
113 	int (*set_frontend[2]) (struct dvb_frontend *fe);
114 	int (*read_status[2]) (struct dvb_frontend *fe, enum fe_status *status);
115 	int (*init[2]) (struct dvb_frontend *fe);
116 	int (*sleep[2]) (struct dvb_frontend *fe);
117 	int (*tuner_init[2]) (struct dvb_frontend *fe);
118 	int (*tuner_sleep[2]) (struct dvb_frontend *fe);
119 	struct mutex fe_mutex;
120 };
121 
122 enum af9015_remote {
123 	AF9015_REMOTE_NONE                    = 0,
124 /* 1 */	AF9015_REMOTE_A_LINK_DTU_M,
125 	AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
126 	AF9015_REMOTE_MYGICTV_U718,
127 	AF9015_REMOTE_DIGITTRADE_DVB_T,
128 /* 5 */	AF9015_REMOTE_AVERMEDIA_KS,
129 };
130 
131 #endif
132