1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver
4  *
5  * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
6  *
7  * TODO:
8  * - add smart card reader support for Conditional Access (CA)
9  *
10  * Card reader in Anysee is nothing more than ISO 7816 card reader.
11  * There is no hardware CAM in any Anysee device sold.
12  * In my understanding it should be implemented by making own module
13  * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
14  * module registers serial interface that can be used to communicate
15  * with any ISO 7816 smart card.
16  *
17  * Any help according to implement serial smart card reader support
18  * is highly welcome!
19  */
20 
21 #ifndef _DVB_USB_ANYSEE_H_
22 #define _DVB_USB_ANYSEE_H_
23 
24 #define DVB_USB_LOG_PREFIX "anysee"
25 #include "dvb_usb.h"
26 #include <media/dvb_ca_en50221.h>
27 
28 enum cmd {
29 	CMD_I2C_READ            = 0x33,
30 	CMD_I2C_WRITE           = 0x31,
31 	CMD_REG_READ            = 0xb0,
32 	CMD_REG_WRITE           = 0xb1,
33 	CMD_STREAMING_CTRL      = 0x12,
34 	CMD_LED_AND_IR_CTRL     = 0x16,
35 	CMD_GET_IR_CODE         = 0x41,
36 	CMD_GET_HW_INFO         = 0x19,
37 	CMD_SMARTCARD           = 0x34,
38 	CMD_CI                  = 0x37,
39 };
40 
41 struct anysee_state {
42 	u8 buf[64];
43 	u8 seq;
44 	u8 hw; /* PCB ID */
45 	#define ANYSEE_I2C_CLIENT_MAX 1
46 	struct i2c_client *i2c_client[ANYSEE_I2C_CLIENT_MAX];
47 	u8 fe_id:1; /* frondend ID */
48 	u8 has_ci:1;
49 	u8 has_tda18212:1;
50 	u8 ci_attached:1;
51 	struct dvb_ca_en50221 ci;
52 	unsigned long ci_cam_ready; /* jiffies */
53 };
54 
55 #define ANYSEE_HW_507T    2 /* E30 */
56 #define ANYSEE_HW_507CD   6 /* E30 Plus */
57 #define ANYSEE_HW_507DC  10 /* E30 C Plus */
58 #define ANYSEE_HW_507SI  11 /* E30 S2 Plus */
59 #define ANYSEE_HW_507FA  15 /* E30 Combo Plus / E30 C Plus */
60 #define ANYSEE_HW_508TC  18 /* E7 TC */
61 #define ANYSEE_HW_508S2  19 /* E7 S2 */
62 #define ANYSEE_HW_508T2C 20 /* E7 T2C */
63 #define ANYSEE_HW_508PTC 21 /* E7 PTC Plus */
64 #define ANYSEE_HW_508PS2 22 /* E7 PS2 Plus */
65 
66 #define REG_IOA       0x80 /* Port A (bit addressable) */
67 #define REG_IOB       0x90 /* Port B (bit addressable) */
68 #define REG_IOC       0xa0 /* Port C (bit addressable) */
69 #define REG_IOD       0xb0 /* Port D (bit addressable) */
70 #define REG_IOE       0xb1 /* Port E (NOT bit addressable) */
71 #define REG_OEA       0xb2 /* Port A Output Enable */
72 #define REG_OEB       0xb3 /* Port B Output Enable */
73 #define REG_OEC       0xb4 /* Port C Output Enable */
74 #define REG_OED       0xb5 /* Port D Output Enable */
75 #define REG_OEE       0xb6 /* Port E Output Enable */
76 
77 #endif
78 
79 /***************************************************************************
80  * USB API description (reverse engineered)
81  ***************************************************************************
82 
83 Transaction flow:
84 =================
85 BULK[00001] >>> REQUEST PACKET 64 bytes
86 BULK[00081] <<< REPLY PACKET #1 64 bytes (PREVIOUS TRANSACTION REPLY)
87 BULK[00081] <<< REPLY PACKET #2 64 bytes (CURRENT TRANSACTION REPLY)
88 
89 General reply packet(s) are always used if not own reply defined.
90 
91 ============================================================================
92 | 00-63 | GENERAL REPLY PACKET #1 (PREVIOUS REPLY)
93 ============================================================================
94 |    00 | reply data (if any) from previous transaction
95 |       | Just same reply packet as returned during previous transaction.
96 |       | Needed only if reply is missed in previous transaction.
97 |       | Just skip normally.
98 ----------------------------------------------------------------------------
99 | 01-59 | don't care
100 ----------------------------------------------------------------------------
101 |    60 | packet sequence number
102 ----------------------------------------------------------------------------
103 | 61-63 | don't care
104 ----------------------------------------------------------------------------
105 
106 ============================================================================
107 | 00-63 | GENERAL REPLY PACKET #2 (CURRENT REPLY)
108 ============================================================================
109 |    00 | reply data (if any)
110 ----------------------------------------------------------------------------
111 | 01-59 | don't care
112 ----------------------------------------------------------------------------
113 |    60 | packet sequence number
114 ----------------------------------------------------------------------------
115 | 61-63 | don't care
116 ----------------------------------------------------------------------------
117 
118 ============================================================================
119 | 00-63 | I2C WRITE REQUEST PACKET
120 ============================================================================
121 |    00 | 0x31 I2C write command
122 ----------------------------------------------------------------------------
123 |    01 | i2c address
124 ----------------------------------------------------------------------------
125 |    02 | data length
126 |       | 0x02 (for typical I2C reg / val pair)
127 ----------------------------------------------------------------------------
128 |    03 | 0x01
129 ----------------------------------------------------------------------------
130 | 04-   | data
131 ----------------------------------------------------------------------------
132 |   -59 | don't care
133 ----------------------------------------------------------------------------
134 |    60 | packet sequence number
135 ----------------------------------------------------------------------------
136 | 61-63 | don't care
137 ----------------------------------------------------------------------------
138 
139 ============================================================================
140 | 00-63 | I2C READ REQUEST PACKET
141 ============================================================================
142 |    00 | 0x33 I2C read command
143 ----------------------------------------------------------------------------
144 |    01 | i2c address + 1
145 ----------------------------------------------------------------------------
146 |    02 | register
147 ----------------------------------------------------------------------------
148 |    03 | 0x00
149 ----------------------------------------------------------------------------
150 |    04 | 0x00
151 ----------------------------------------------------------------------------
152 |    05 | data length
153 ----------------------------------------------------------------------------
154 | 06-59 | don't care
155 ----------------------------------------------------------------------------
156 |    60 | packet sequence number
157 ----------------------------------------------------------------------------
158 | 61-63 | don't care
159 ----------------------------------------------------------------------------
160 
161 ============================================================================
162 | 00-63 | USB CONTROLLER REGISTER WRITE REQUEST PACKET
163 ============================================================================
164 |    00 | 0xb1 register write command
165 ----------------------------------------------------------------------------
166 | 01-02 | register
167 ----------------------------------------------------------------------------
168 |    03 | 0x01
169 ----------------------------------------------------------------------------
170 |    04 | value
171 ----------------------------------------------------------------------------
172 | 05-59 | don't care
173 ----------------------------------------------------------------------------
174 |    60 | packet sequence number
175 ----------------------------------------------------------------------------
176 | 61-63 | don't care
177 ----------------------------------------------------------------------------
178 
179 ============================================================================
180 | 00-63 | USB CONTROLLER REGISTER READ REQUEST PACKET
181 ============================================================================
182 |    00 | 0xb0 register read command
183 ----------------------------------------------------------------------------
184 | 01-02 | register
185 ----------------------------------------------------------------------------
186 |    03 | 0x01
187 ----------------------------------------------------------------------------
188 | 04-59 | don't care
189 ----------------------------------------------------------------------------
190 |    60 | packet sequence number
191 ----------------------------------------------------------------------------
192 | 61-63 | don't care
193 ----------------------------------------------------------------------------
194 
195 ============================================================================
196 | 00-63 | LED CONTROL REQUEST PACKET
197 ============================================================================
198 |    00 | 0x16 LED and IR control command
199 ----------------------------------------------------------------------------
200 |    01 | 0x01 (LED)
201 ----------------------------------------------------------------------------
202 |    03 | 0x00 blink
203 |       | 0x01 lights continuously
204 ----------------------------------------------------------------------------
205 |    04 | blink interval
206 |       | 0x00 fastest (looks like LED lights continuously)
207 |       | 0xff slowest
208 ----------------------------------------------------------------------------
209 | 05-59 | don't care
210 ----------------------------------------------------------------------------
211 |    60 | packet sequence number
212 ----------------------------------------------------------------------------
213 | 61-63 | don't care
214 ----------------------------------------------------------------------------
215 
216 ============================================================================
217 | 00-63 | IR CONTROL REQUEST PACKET
218 ============================================================================
219 |    00 | 0x16 LED and IR control command
220 ----------------------------------------------------------------------------
221 |    01 | 0x02 (IR)
222 ----------------------------------------------------------------------------
223 |    03 | 0x00 IR disabled
224 |       | 0x01 IR enabled
225 ----------------------------------------------------------------------------
226 | 04-59 | don't care
227 ----------------------------------------------------------------------------
228 |    60 | packet sequence number
229 ----------------------------------------------------------------------------
230 | 61-63 | don't care
231 ----------------------------------------------------------------------------
232 
233 ============================================================================
234 | 00-63 | STREAMING CONTROL REQUEST PACKET
235 ============================================================================
236 |    00 | 0x12 streaming control command
237 ----------------------------------------------------------------------------
238 |    01 | 0x00 streaming disabled
239 |       | 0x01 streaming enabled
240 ----------------------------------------------------------------------------
241 |    02 | 0x00
242 ----------------------------------------------------------------------------
243 | 03-59 | don't care
244 ----------------------------------------------------------------------------
245 |    60 | packet sequence number
246 ----------------------------------------------------------------------------
247 | 61-63 | don't care
248 ----------------------------------------------------------------------------
249 
250 ============================================================================
251 | 00-63 | REMOTE CONTROL REQUEST PACKET
252 ============================================================================
253 |    00 | 0x41 remote control command
254 ----------------------------------------------------------------------------
255 | 01-59 | don't care
256 ----------------------------------------------------------------------------
257 |    60 | packet sequence number
258 ----------------------------------------------------------------------------
259 | 61-63 | don't care
260 ----------------------------------------------------------------------------
261 
262 ============================================================================
263 | 00-63 | REMOTE CONTROL REPLY PACKET
264 ============================================================================
265 |    00 | 0x00 code not received
266 |       | 0x01 code received
267 ----------------------------------------------------------------------------
268 |    01 | remote control code
269 ----------------------------------------------------------------------------
270 | 02-59 | don't care
271 ----------------------------------------------------------------------------
272 |    60 | packet sequence number
273 ----------------------------------------------------------------------------
274 | 61-63 | don't care
275 ----------------------------------------------------------------------------
276 
277 ============================================================================
278 | 00-63 | GET HARDWARE INFO REQUEST PACKET
279 ============================================================================
280 |    00 | 0x19 get hardware info command
281 ----------------------------------------------------------------------------
282 | 01-59 | don't care
283 ----------------------------------------------------------------------------
284 |    60 | packet sequence number
285 ----------------------------------------------------------------------------
286 | 61-63 | don't care
287 ----------------------------------------------------------------------------
288 
289 ============================================================================
290 | 00-63 | GET HARDWARE INFO REPLY PACKET
291 ============================================================================
292 |    00 | hardware id
293 ----------------------------------------------------------------------------
294 | 01-02 | firmware version
295 ----------------------------------------------------------------------------
296 | 03-59 | don't care
297 ----------------------------------------------------------------------------
298 |    60 | packet sequence number
299 ----------------------------------------------------------------------------
300 | 61-63 | don't care
301 ----------------------------------------------------------------------------
302 
303 ============================================================================
304 | 00-63 | SMART CARD READER PACKET
305 ============================================================================
306 |    00 | 0x34 smart card reader command
307 ----------------------------------------------------------------------------
308 |    xx |
309 ----------------------------------------------------------------------------
310 | xx-59 | don't care
311 ----------------------------------------------------------------------------
312 |    60 | packet sequence number
313 ----------------------------------------------------------------------------
314 | 61-63 | don't care
315 ----------------------------------------------------------------------------
316 
317 */
318