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