1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * ddbridge-mci.h: Digital Devices micro code interface
4  *
5  * Copyright (C) 2017 Digital Devices GmbH
6  *                    Marcus Metzler <mocm@metzlerbros.de>
7  *                    Ralph Metzler <rjkm@metzlerbros.de>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * version 2 only, as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */
18 
19 #ifndef _DDBRIDGE_MCI_H_
20 #define _DDBRIDGE_MCI_H_
21 
22 #define MCI_CONTROL                         (0x500)
23 #define MCI_COMMAND                         (0x600)
24 #define MCI_RESULT                          (0x680)
25 
26 #define MCI_COMMAND_SIZE                    (0x80)
27 #define MCI_RESULT_SIZE                     (0x80)
28 
29 #define MCI_CONTROL_START_COMMAND           (0x00000001)
30 #define MCI_CONTROL_ENABLE_DONE_INTERRUPT   (0x00000002)
31 #define MCI_CONTROL_RESET                   (0x00008000)
32 #define MCI_CONTROL_READY                   (0x00010000)
33 
34 #define SX8_TSCONFIG                        (0x280)
35 
36 #define SX8_TSCONFIG_MODE_MASK              (0x00000003)
37 #define SX8_TSCONFIG_MODE_OFF               (0x00000000)
38 #define SX8_TSCONFIG_MODE_NORMAL            (0x00000001)
39 #define SX8_TSCONFIG_MODE_IQ                (0x00000003)
40 
41 #define SX8_TSCONFIG_TSHEADER               (0x00000004)
42 #define SX8_TSCONFIG_BURST                  (0x00000008)
43 
44 #define SX8_TSCONFIG_BURSTSIZE_MASK         (0x00000030)
45 #define SX8_TSCONFIG_BURSTSIZE_2K           (0x00000000)
46 #define SX8_TSCONFIG_BURSTSIZE_4K           (0x00000010)
47 #define SX8_TSCONFIG_BURSTSIZE_8K           (0x00000020)
48 #define SX8_TSCONFIG_BURSTSIZE_16K          (0x00000030)
49 
50 #define SX8_DEMOD_STOPPED       (0)
51 #define SX8_DEMOD_IQ_MODE       (1)
52 #define SX8_DEMOD_WAIT_SIGNAL   (2)
53 #define SX8_DEMOD_WAIT_MATYPE   (3)
54 #define SX8_DEMOD_TIMEOUT       (14)
55 #define SX8_DEMOD_LOCKED        (15)
56 
57 #define MCI_CMD_STOP            (0x01)
58 #define MCI_CMD_GETSTATUS       (0x02)
59 #define MCI_CMD_GETSIGNALINFO   (0x03)
60 #define MCI_CMD_RFPOWER         (0x04)
61 
62 #define MCI_CMD_SEARCH_DVBS     (0x10)
63 
64 #define MCI_CMD_GET_IQSYMBOL    (0x30)
65 
66 #define SX8_CMD_INPUT_ENABLE    (0x40)
67 #define SX8_CMD_INPUT_DISABLE   (0x41)
68 #define SX8_CMD_START_IQ        (0x42)
69 #define SX8_CMD_STOP_IQ         (0x43)
70 #define SX8_CMD_SELECT_IQOUT    (0x44)
71 #define SX8_CMD_SELECT_TSOUT    (0x45)
72 
73 #define SX8_ERROR_UNSUPPORTED   (0x80)
74 
75 #define SX8_SUCCESS(status)     (status < SX8_ERROR_UNSUPPORTED)
76 
77 #define SX8_CMD_DIAG_READ8      (0xE0)
78 #define SX8_CMD_DIAG_READ32     (0xE1)
79 #define SX8_CMD_DIAG_WRITE8     (0xE2)
80 #define SX8_CMD_DIAG_WRITE32    (0xE3)
81 
82 #define SX8_CMD_DIAG_READRF     (0xE8)
83 #define SX8_CMD_DIAG_WRITERF    (0xE9)
84 
85 struct mci_command {
86 	union {
87 		u32 command_word;
88 		struct {
89 			u8 command;
90 			u8 tuner;
91 			u8 demod;
92 			u8 output;
93 		};
94 	};
95 	union {
96 		u32 params[31];
97 		struct {
98 			u8  flags;
99 			u8  s2_modulation_mask;
100 			u8  rsvd1;
101 			u8  retry;
102 			u32 frequency;
103 			u32 symbol_rate;
104 			u8  input_stream_id;
105 			u8  rsvd2[3];
106 			u32 scrambling_sequence_index;
107 		} dvbs2_search;
108 	};
109 };
110 
111 struct mci_result {
112 	union {
113 		u32 status_word;
114 		struct {
115 			u8 status;
116 			u8 rsvd;
117 			u16 time;
118 		};
119 	};
120 	union {
121 		u32 result[27];
122 		struct {
123 			u8  standard;
124 			/* puncture rate for DVB-S */
125 			u8  pls_code;
126 			/* 7-6: rolloff, 5-2: rsrvd, 1:short, 0:pilots */
127 			u8  roll_off;
128 			u8  rsvd;
129 			u32 frequency;
130 			u32 symbol_rate;
131 			s16 channel_power;
132 			s16 band_power;
133 			s16 signal_to_noise;
134 			s16 rsvd2;
135 			u32 packet_errors;
136 			u32 ber_numerator;
137 			u32 ber_denominator;
138 		} dvbs2_signal_info;
139 		struct {
140 			u8 i_symbol;
141 			u8 q_symbol;
142 		} dvbs2_signal_iq;
143 	};
144 	u32 version[4];
145 };
146 
147 struct dvb_frontend
148 *ddb_mci_attach(struct ddb_input *input,
149 		int mci_type, int nr,
150 		int (**fn_set_input)(struct dvb_frontend *, int));
151 
152 #endif /* _DDBRIDGE_MCI_H_ */
153