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