1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Abilis Systems Single DVB-T Receiver
4 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
5 */
6#ifndef _AS10X_CMD_H_
7#define _AS10X_CMD_H_
8
9#include <linux/kernel.h>
10
11#include "as102_fe_types.h"
12
13/*********************************/
14/* MACRO DEFINITIONS */
15/*********************************/
16#define AS10X_CMD_ERROR -1
17
18#define SERVICE_PROG_ID 0x0002
19#define SERVICE_PROG_VERSION 0x0001
20
21#define HIER_NONE 0x00
22#define HIER_LOW_PRIORITY 0x01
23
24#define HEADER_SIZE (sizeof(struct as10x_cmd_header_t))
25
26/* context request types */
27#define GET_CONTEXT_DATA 1
28#define SET_CONTEXT_DATA 2
29
30/* ODSP suspend modes */
31#define CFG_MODE_ODSP_RESUME 0
32#define CFG_MODE_ODSP_SUSPEND 1
33
34/* Dump memory size */
35#define DUMP_BLOCK_SIZE_MAX 0x20
36
37/*********************************/
38/* TYPE DEFINITION */
39/*********************************/
40enum control_proc {
41 CONTROL_PROC_TURNON = 0x0001,
42 CONTROL_PROC_TURNON_RSP = 0x0100,
43 CONTROL_PROC_SET_REGISTER = 0x0002,
44 CONTROL_PROC_SET_REGISTER_RSP = 0x0200,
45 CONTROL_PROC_GET_REGISTER = 0x0003,
46 CONTROL_PROC_GET_REGISTER_RSP = 0x0300,
47 CONTROL_PROC_SETTUNE = 0x000A,
48 CONTROL_PROC_SETTUNE_RSP = 0x0A00,
49 CONTROL_PROC_GETTUNESTAT = 0x000B,
50 CONTROL_PROC_GETTUNESTAT_RSP = 0x0B00,
51 CONTROL_PROC_GETTPS = 0x000D,
52 CONTROL_PROC_GETTPS_RSP = 0x0D00,
53 CONTROL_PROC_SETFILTER = 0x000E,
54 CONTROL_PROC_SETFILTER_RSP = 0x0E00,
55 CONTROL_PROC_REMOVEFILTER = 0x000F,
56 CONTROL_PROC_REMOVEFILTER_RSP = 0x0F00,
57 CONTROL_PROC_GET_IMPULSE_RESP = 0x0012,
58 CONTROL_PROC_GET_IMPULSE_RESP_RSP = 0x1200,
59 CONTROL_PROC_START_STREAMING = 0x0013,
60 CONTROL_PROC_START_STREAMING_RSP = 0x1300,
61 CONTROL_PROC_STOP_STREAMING = 0x0014,
62 CONTROL_PROC_STOP_STREAMING_RSP = 0x1400,
63 CONTROL_PROC_GET_DEMOD_STATS = 0x0015,
64 CONTROL_PROC_GET_DEMOD_STATS_RSP = 0x1500,
65 CONTROL_PROC_ELNA_CHANGE_MODE = 0x0016,
66 CONTROL_PROC_ELNA_CHANGE_MODE_RSP = 0x1600,
67 CONTROL_PROC_ODSP_CHANGE_MODE = 0x0017,
68 CONTROL_PROC_ODSP_CHANGE_MODE_RSP = 0x1700,
69 CONTROL_PROC_AGC_CHANGE_MODE = 0x0018,
70 CONTROL_PROC_AGC_CHANGE_MODE_RSP = 0x1800,
71
72 CONTROL_PROC_CONTEXT = 0x00FC,
73 CONTROL_PROC_CONTEXT_RSP = 0xFC00,
74 CONTROL_PROC_DUMP_MEMORY = 0x00FD,
75 CONTROL_PROC_DUMP_MEMORY_RSP = 0xFD00,
76 CONTROL_PROC_DUMPLOG_MEMORY = 0x00FE,
77 CONTROL_PROC_DUMPLOG_MEMORY_RSP = 0xFE00,
78 CONTROL_PROC_TURNOFF = 0x00FF,
79 CONTROL_PROC_TURNOFF_RSP = 0xFF00
80};
81
82union as10x_turn_on {
83 /* request */
84 struct {
85 /* request identifier */
86 __le16 proc_id;
87 } __packed req;
88 /* response */
89 struct {
90 /* response identifier */
91 __le16 proc_id;
92 /* error */
93 uint8_t error;
94 } __packed rsp;
95} __packed;
96
97union as10x_turn_off {
98 /* request */
99 struct {
100 /* request identifier */
101 __le16 proc_id;
102 } __packed req;
103 /* response */
104 struct {
105 /* response identifier */
106 __le16 proc_id;
107 /* error */
108 uint8_t err;
109 } __packed rsp;
110} __packed;
111
112union as10x_set_tune {
113 /* request */
114 struct {
115 /* request identifier */
116 __le16 proc_id;
117 /* tune params */
118 struct as10x_tune_args args;
119 } __packed req;
120 /* response */
121 struct {
122 /* response identifier */
123 __le16 proc_id;
124 /* response error */
125 uint8_t error;
126 } __packed rsp;
127} __packed;
128
129union as10x_get_tune_status {
130 /* request */
131 struct {
132 /* request identifier */
133 __le16 proc_id;
134 } __packed req;
135 /* response */
136 struct {
137 /* response identifier */
138 __le16 proc_id;
139 /* response error */
140 uint8_t error;
141 /* tune status */
142 struct as10x_tune_status sts;
143 } __packed rsp;
144} __packed;
145
146union as10x_get_tps {
147 /* request */
148 struct {
149 /* request identifier */
150 __le16 proc_id;
151 } __packed req;
152 /* response */
153 struct {
154 /* response identifier */
155 __le16 proc_id;
156 /* response error */
157 uint8_t error;
158 /* tps details */
159 struct as10x_tps tps;
160 } __packed rsp;
161} __packed;
162
163union as10x_common {
164 /* request */
165 struct {
166 /* request identifier */
167 __le16 proc_id;
168 } __packed req;
169 /* response */
170 struct {
171 /* response identifier */
172 __le16 proc_id;
173 /* response error */
174 uint8_t error;
175 } __packed rsp;
176} __packed;
177
178union as10x_add_pid_filter {
179 /* request */
180 struct {
181 /* request identifier */
182 __le16 proc_id;
183 /* PID to filter */
184 __le16 pid;
185 /* stream type (MPE, PSI/SI or PES )*/
186 uint8_t stream_type;
187 /* PID index in filter table */
188 uint8_t idx;
189 } __packed req;
190 /* response */
191 struct {
192 /* response identifier */
193 __le16 proc_id;
194 /* response error */
195 uint8_t error;
196 /* Filter id */
197 uint8_t filter_id;
198 } __packed rsp;
199} __packed;
200
201union as10x_del_pid_filter {
202 /* request */
203 struct {
204 /* request identifier */
205 __le16 proc_id;
206 /* PID to remove */
207 __le16 pid;
208 } __packed req;
209 /* response */
210 struct {
211 /* response identifier */
212 __le16 proc_id;
213 /* response error */
214 uint8_t error;
215 } __packed rsp;
216} __packed;
217
218union as10x_start_streaming {
219 /* request */
220 struct {
221 /* request identifier */
222 __le16 proc_id;
223 } __packed req;
224 /* response */
225 struct {
226 /* response identifier */
227 __le16 proc_id;
228 /* error */
229 uint8_t error;
230 } __packed rsp;
231} __packed;
232
233union as10x_stop_streaming {
234 /* request */
235 struct {
236 /* request identifier */
237 __le16 proc_id;
238 } __packed req;
239 /* response */
240 struct {
241 /* response identifier */
242 __le16 proc_id;
243 /* error */
244 uint8_t error;
245 } __packed rsp;
246} __packed;
247
248union as10x_get_demod_stats {
249 /* request */
250 struct {
251 /* request identifier */
252 __le16 proc_id;
253 } __packed req;
254 /* response */
255 struct {
256 /* response identifier */
257 __le16 proc_id;
258 /* error */
259 uint8_t error;
260 /* demod stats */
261 struct as10x_demod_stats stats;
262 } __packed rsp;
263} __packed;
264
265union as10x_get_impulse_resp {
266 /* request */
267 struct {
268 /* request identifier */
269 __le16 proc_id;
270 } __packed req;
271 /* response */
272 struct {
273 /* response identifier */
274 __le16 proc_id;
275 /* error */
276 uint8_t error;
277 /* impulse response ready */
278 uint8_t is_ready;
279 } __packed rsp;
280} __packed;
281
282union as10x_fw_context {
283 /* request */
284 struct {
285 /* request identifier */
286 __le16 proc_id;
287 /* value to write (for set context)*/
288 struct as10x_register_value reg_val;
289 /* context tag */
290 __le16 tag;
291 /* context request type */
292 __le16 type;
293 } __packed req;
294 /* response */
295 struct {
296 /* response identifier */
297 __le16 proc_id;
298 /* value read (for get context) */
299 struct as10x_register_value reg_val;
300 /* context request type */
301 __le16 type;
302 /* error */
303 uint8_t error;
304 } __packed rsp;
305} __packed;
306
307union as10x_set_register {
308 /* request */
309 struct {
310 /* response identifier */
311 __le16 proc_id;
312 /* register description */
313 struct as10x_register_addr reg_addr;
314 /* register content */
315 struct as10x_register_value reg_val;
316 } __packed req;
317 /* response */
318 struct {
319 /* response identifier */
320 __le16 proc_id;
321 /* error */
322 uint8_t error;
323 } __packed rsp;
324} __packed;
325
326union as10x_get_register {
327 /* request */
328 struct {
329 /* response identifier */
330 __le16 proc_id;
331 /* register description */
332 struct as10x_register_addr reg_addr;
333 } __packed req;
334 /* response */
335 struct {
336 /* response identifier */
337 __le16 proc_id;
338 /* error */
339 uint8_t error;
340 /* register content */
341 struct as10x_register_value reg_val;
342 } __packed rsp;
343} __packed;
344
345union as10x_cfg_change_mode {
346 /* request */
347 struct {
348 /* request identifier */
349 __le16 proc_id;
350 /* mode */
351 uint8_t mode;
352 } __packed req;
353 /* response */
354 struct {
355 /* response identifier */
356 __le16 proc_id;
357 /* error */
358 uint8_t error;
359 } __packed rsp;
360} __packed;
361
362struct as10x_cmd_header_t {
363 __le16 req_id;
364 __le16 prog;
365 __le16 version;
366 __le16 data_len;
367} __packed;
368
369#define DUMP_BLOCK_SIZE 16
370
371union as10x_dump_memory {
372 /* request */
373 struct {
374 /* request identifier */
375 __le16 proc_id;
376 /* dump memory type request */
377 uint8_t dump_req;
378 /* register description */
379 struct as10x_register_addr reg_addr;
380 /* nb blocks to read */
381 __le16 num_blocks;
382 } __packed req;
383 /* response */
384 struct {
385 /* response identifier */
386 __le16 proc_id;
387 /* error */
388 uint8_t error;
389 /* dump response */
390 uint8_t dump_rsp;
391 /* data */
392 union {
393 uint8_t data8[DUMP_BLOCK_SIZE];
394 __le16 data16[DUMP_BLOCK_SIZE / sizeof(__le16)];
395 __le32 data32[DUMP_BLOCK_SIZE / sizeof(__le32)];
396 } __packed u;
397 } __packed rsp;
398} __packed;
399
400union as10x_dumplog_memory {
401 struct {
402 /* request identifier */
403 __le16 proc_id;
404 /* dump memory type request */
405 uint8_t dump_req;
406 } __packed req;
407 struct {
408 /* request identifier */
409 __le16 proc_id;
410 /* error */
411 uint8_t error;
412 /* dump response */
413 uint8_t dump_rsp;
414 /* dump data */
415 uint8_t data[DUMP_BLOCK_SIZE];
416 } __packed rsp;
417} __packed;
418
419union as10x_raw_data {
420 /* request */
421 struct {
422 __le16 proc_id;
423 uint8_t data[64 - sizeof(struct as10x_cmd_header_t)
424 - 2 /* proc_id */];
425 } __packed req;
426 /* response */
427 struct {
428 __le16 proc_id;
429 uint8_t error;
430 uint8_t data[64 - sizeof(struct as10x_cmd_header_t)
431 - 2 /* proc_id */ - 1 /* rc */];
432 } __packed rsp;
433} __packed;
434
435struct as10x_cmd_t {
436 struct as10x_cmd_header_t header;
437 union {
438 union as10x_turn_on turn_on;
439 union as10x_turn_off turn_off;
440 union as10x_set_tune set_tune;
441 union as10x_get_tune_status get_tune_status;
442 union as10x_get_tps get_tps;
443 union as10x_common common;
444 union as10x_add_pid_filter add_pid_filter;
445 union as10x_del_pid_filter del_pid_filter;
446 union as10x_start_streaming start_streaming;
447 union as10x_stop_streaming stop_streaming;
448 union as10x_get_demod_stats get_demod_stats;
449 union as10x_get_impulse_resp get_impulse_rsp;
450 union as10x_fw_context context;
451 union as10x_set_register set_register;
452 union as10x_get_register get_register;
453 union as10x_cfg_change_mode cfg_change_mode;
454 union as10x_dump_memory dump_memory;
455 union as10x_dumplog_memory dumplog_memory;
456 union as10x_raw_data raw_data;
457 } __packed body;
458} __packed;
459
460struct as10x_token_cmd_t {
461 /* token cmd */
462 struct as10x_cmd_t c;
463 /* token response */
464 struct as10x_cmd_t r;
465} __packed;
466
467
468/**************************/
469/* FUNCTION DECLARATION */
470/**************************/
471
472void as10x_cmd_build(struct as10x_cmd_t *pcmd, uint16_t proc_id,
473 uint16_t cmd_len);
474int as10x_rsp_parse(struct as10x_cmd_t *r, uint16_t proc_id);
475
476/* as10x cmd */
477int as10x_cmd_turn_on(struct as10x_bus_adapter_t *adap);
478int as10x_cmd_turn_off(struct as10x_bus_adapter_t *adap);
479
480int as10x_cmd_set_tune(struct as10x_bus_adapter_t *adap,
481 struct as10x_tune_args *ptune);
482
483int as10x_cmd_get_tune_status(struct as10x_bus_adapter_t *adap,
484 struct as10x_tune_status *pstatus);
485
486int as10x_cmd_get_tps(struct as10x_bus_adapter_t *adap,
487 struct as10x_tps *ptps);
488
489int as10x_cmd_get_demod_stats(struct as10x_bus_adapter_t *adap,
490 struct as10x_demod_stats *pdemod_stats);
491
492int as10x_cmd_get_impulse_resp(struct as10x_bus_adapter_t *adap,
493 uint8_t *is_ready);
494
495/* as10x cmd stream */
496int as10x_cmd_add_PID_filter(struct as10x_bus_adapter_t *adap,
497 struct as10x_ts_filter *filter);
498int as10x_cmd_del_PID_filter(struct as10x_bus_adapter_t *adap,
499 uint16_t pid_value);
500
501int as10x_cmd_start_streaming(struct as10x_bus_adapter_t *adap);
502int as10x_cmd_stop_streaming(struct as10x_bus_adapter_t *adap);
503
504/* as10x cmd cfg */
505int as10x_cmd_set_context(struct as10x_bus_adapter_t *adap,
506 uint16_t tag,
507 uint32_t value);
508int as10x_cmd_get_context(struct as10x_bus_adapter_t *adap,
509 uint16_t tag,
510 uint32_t *pvalue);
511
512int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t mode);
513int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id);
514#endif
515

source code of linux/drivers/media/usb/as102/as10x_cmd.h