xref: /linux/drivers/media/dvb-frontends/stv0900_priv.h (revision 547f574fd9d5e3925d47fd44decbf6ab6df94b0e)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * stv0900_priv.h
4  *
5  * Driver for ST STV0900 satellite demodulator IC.
6  *
7  * Copyright (C) ST Microelectronics.
8  * Copyright (C) 2009 NetUP Inc.
9  * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
10  */
11 
12 #ifndef STV0900_PRIV_H
13 #define STV0900_PRIV_H
14 
15 #include <linux/i2c.h>
16 
17 #define INRANGE(X, Y, Z) ((((X) <= (Y)) && ((Y) <= (Z))) \
18 		|| (((Z) <= (Y)) && ((Y) <= (X))) ? 1 : 0)
19 
20 #ifndef MAKEWORD
21 #define MAKEWORD(X, Y) (((X) << 8) + (Y))
22 #endif
23 
24 #define LSB(X) (((X) & 0xFF))
25 #define MSB(Y) (((Y) >> 8) & 0xFF)
26 
27 #ifndef TRUE
28 #define TRUE (1 == 1)
29 #endif
30 #ifndef FALSE
31 #define FALSE (!TRUE)
32 #endif
33 
34 #define dprintk(args...) \
35 	do { \
36 		if (stvdebug) \
37 			printk(KERN_DEBUG args); \
38 	} while (0)
39 
40 #define STV0900_MAXLOOKUPSIZE 500
41 #define STV0900_BLIND_SEARCH_AGC2_TH 700
42 #define STV0900_BLIND_SEARCH_AGC2_TH_CUT30 1400
43 #define IQPOWER_THRESHOLD  30
44 
45 /* One point of the lookup table */
46 struct stv000_lookpoint {
47 	s32 realval;/* real value */
48 	s32 regval;/* binary value */
49 };
50 
51 /* Lookup table definition */
52 struct stv0900_table{
53 	s32 size;/* Size of the lookup table */
54 	struct stv000_lookpoint table[STV0900_MAXLOOKUPSIZE];/* Lookup table */
55 };
56 
57 enum fe_stv0900_error {
58 	STV0900_NO_ERROR = 0,
59 	STV0900_INVALID_HANDLE,
60 	STV0900_BAD_PARAMETER,
61 	STV0900_I2C_ERROR,
62 	STV0900_SEARCH_FAILED,
63 };
64 
65 enum fe_stv0900_clock_type {
66 	STV0900_USE_REGISTERS_DEFAULT,
67 	STV0900_SERIAL_PUNCT_CLOCK,/*Serial punctured clock */
68 	STV0900_SERIAL_CONT_CLOCK,/*Serial continues clock */
69 	STV0900_PARALLEL_PUNCT_CLOCK,/*Parallel punctured clock */
70 	STV0900_DVBCI_CLOCK/*Parallel continues clock : DVBCI */
71 };
72 
73 enum fe_stv0900_search_state {
74 	STV0900_SEARCH = 0,
75 	STV0900_PLH_DETECTED,
76 	STV0900_DVBS2_FOUND,
77 	STV0900_DVBS_FOUND
78 
79 };
80 
81 enum fe_stv0900_ldpc_state {
82 	STV0900_PATH1_OFF_PATH2_OFF = 0,
83 	STV0900_PATH1_ON_PATH2_OFF = 1,
84 	STV0900_PATH1_OFF_PATH2_ON = 2,
85 	STV0900_PATH1_ON_PATH2_ON = 3
86 };
87 
88 enum fe_stv0900_signal_type {
89 	STV0900_NOAGC1 = 0,
90 	STV0900_AGC1OK,
91 	STV0900_NOTIMING,
92 	STV0900_ANALOGCARRIER,
93 	STV0900_TIMINGOK,
94 	STV0900_NOAGC2,
95 	STV0900_AGC2OK,
96 	STV0900_NOCARRIER,
97 	STV0900_CARRIEROK,
98 	STV0900_NODATA,
99 	STV0900_DATAOK,
100 	STV0900_OUTOFRANGE,
101 	STV0900_RANGEOK
102 };
103 
104 enum fe_stv0900_demod_num {
105 	STV0900_DEMOD_1,
106 	STV0900_DEMOD_2
107 };
108 
109 enum fe_stv0900_tracking_standard {
110 	STV0900_DVBS1_STANDARD,/* Found Standard*/
111 	STV0900_DVBS2_STANDARD,
112 	STV0900_DSS_STANDARD,
113 	STV0900_TURBOCODE_STANDARD,
114 	STV0900_UNKNOWN_STANDARD
115 };
116 
117 enum fe_stv0900_search_standard {
118 	STV0900_AUTO_SEARCH,
119 	STV0900_SEARCH_DVBS1,/* Search Standard*/
120 	STV0900_SEARCH_DVBS2,
121 	STV0900_SEARCH_DSS,
122 	STV0900_SEARCH_TURBOCODE
123 };
124 
125 enum fe_stv0900_search_algo {
126 	STV0900_BLIND_SEARCH,/* offset freq and SR are Unknown */
127 	STV0900_COLD_START,/* only the SR is known */
128 	STV0900_WARM_START/* offset freq and SR are known */
129 };
130 
131 enum fe_stv0900_modulation {
132 	STV0900_QPSK,
133 	STV0900_8PSK,
134 	STV0900_16APSK,
135 	STV0900_32APSK,
136 	STV0900_UNKNOWN
137 };
138 
139 enum fe_stv0900_modcode {
140 	STV0900_DUMMY_PLF,
141 	STV0900_QPSK_14,
142 	STV0900_QPSK_13,
143 	STV0900_QPSK_25,
144 	STV0900_QPSK_12,
145 	STV0900_QPSK_35,
146 	STV0900_QPSK_23,
147 	STV0900_QPSK_34,
148 	STV0900_QPSK_45,
149 	STV0900_QPSK_56,
150 	STV0900_QPSK_89,
151 	STV0900_QPSK_910,
152 	STV0900_8PSK_35,
153 	STV0900_8PSK_23,
154 	STV0900_8PSK_34,
155 	STV0900_8PSK_56,
156 	STV0900_8PSK_89,
157 	STV0900_8PSK_910,
158 	STV0900_16APSK_23,
159 	STV0900_16APSK_34,
160 	STV0900_16APSK_45,
161 	STV0900_16APSK_56,
162 	STV0900_16APSK_89,
163 	STV0900_16APSK_910,
164 	STV0900_32APSK_34,
165 	STV0900_32APSK_45,
166 	STV0900_32APSK_56,
167 	STV0900_32APSK_89,
168 	STV0900_32APSK_910,
169 	STV0900_MODCODE_UNKNOWN
170 };
171 
172 enum fe_stv0900_fec {/*DVBS1, DSS and turbo code puncture rate*/
173 	STV0900_FEC_1_2 = 0,
174 	STV0900_FEC_2_3,
175 	STV0900_FEC_3_4,
176 	STV0900_FEC_4_5,/*for turbo code only*/
177 	STV0900_FEC_5_6,
178 	STV0900_FEC_6_7,/*for DSS only */
179 	STV0900_FEC_7_8,
180 	STV0900_FEC_8_9,/*for turbo code only*/
181 	STV0900_FEC_UNKNOWN
182 };
183 
184 enum fe_stv0900_frame_length {
185 	STV0900_LONG_FRAME,
186 	STV0900_SHORT_FRAME
187 };
188 
189 enum fe_stv0900_pilot {
190 	STV0900_PILOTS_OFF,
191 	STV0900_PILOTS_ON
192 };
193 
194 enum fe_stv0900_rolloff {
195 	STV0900_35,
196 	STV0900_25,
197 	STV0900_20
198 };
199 
200 enum fe_stv0900_search_iq {
201 	STV0900_IQ_AUTO,
202 	STV0900_IQ_AUTO_NORMAL_FIRST,
203 	STV0900_IQ_FORCE_NORMAL,
204 	STV0900_IQ_FORCE_SWAPPED
205 };
206 
207 enum stv0900_iq_inversion {
208 	STV0900_IQ_NORMAL,
209 	STV0900_IQ_SWAPPED
210 };
211 
212 enum fe_stv0900_diseqc_mode {
213 	STV0900_22KHZ_Continues = 0,
214 	STV0900_DISEQC_2_3_PWM = 2,
215 	STV0900_DISEQC_3_3_PWM = 3,
216 	STV0900_DISEQC_2_3_ENVELOP = 4,
217 	STV0900_DISEQC_3_3_ENVELOP = 5
218 };
219 
220 enum fe_stv0900_demod_mode {
221 	STV0900_SINGLE = 0,
222 	STV0900_DUAL
223 };
224 
225 struct stv0900_init_params{
226 	u32	dmd_ref_clk;/* Reference,Input clock for the demod in Hz */
227 
228 	/* Demodulator Type (single demod or dual demod) */
229 	enum fe_stv0900_demod_mode	demod_mode;
230 	enum fe_stv0900_rolloff		rolloff;
231 	enum fe_stv0900_clock_type	path1_ts_clock;
232 
233 	u8	tun1_maddress;
234 	int	tuner1_adc;
235 	int	tuner1_type;
236 
237 	/* IQ from the tuner1 to the demod */
238 	enum stv0900_iq_inversion	tun1_iq_inv;
239 	enum fe_stv0900_clock_type	path2_ts_clock;
240 
241 	u8	tun2_maddress;
242 	int	tuner2_adc;
243 	int	tuner2_type;
244 
245 	/* IQ from the tuner2 to the demod */
246 	enum stv0900_iq_inversion	tun2_iq_inv;
247 	struct stv0900_reg		*ts_config;
248 };
249 
250 struct stv0900_search_params {
251 	enum fe_stv0900_demod_num	path;/* Path Used demod1 or 2 */
252 
253 	u32	frequency;/* Transponder frequency (in KHz) */
254 	u32	symbol_rate;/* Transponder symbol rate  (in bds)*/
255 	u32	search_range;/* Range of the search (in Hz) */
256 
257 	enum fe_stv0900_search_standard	standard;
258 	enum fe_stv0900_modulation	modulation;
259 	enum fe_stv0900_fec		fec;
260 	enum fe_stv0900_modcode		modcode;
261 	enum fe_stv0900_search_iq	iq_inversion;
262 	enum fe_stv0900_search_algo	search_algo;
263 
264 };
265 
266 struct stv0900_signal_info {
267 	int	locked;/* Transponder locked */
268 	u32	frequency;/* Transponder frequency (in KHz) */
269 	u32	symbol_rate;/* Transponder symbol rate  (in Mbds) */
270 
271 	enum fe_stv0900_tracking_standard	standard;
272 	enum fe_stv0900_fec			fec;
273 	enum fe_stv0900_modcode			modcode;
274 	enum fe_stv0900_modulation		modulation;
275 	enum fe_stv0900_pilot			pilot;
276 	enum fe_stv0900_frame_length		frame_len;
277 	enum stv0900_iq_inversion		spectrum;
278 	enum fe_stv0900_rolloff			rolloff;
279 
280 	s32 Power;/* Power of the RF signal (dBm) */
281 	s32 C_N;/* Carrier to noise ratio (dB x10)*/
282 	u32 BER;/* Bit error rate (x10^7) */
283 
284 };
285 
286 struct stv0900_internal{
287 	s32	quartz;
288 	s32	mclk;
289 	/* manual RollOff for DVBS1/DSS only */
290 	enum fe_stv0900_rolloff		rolloff;
291 	/* Demodulator use for single demod or for dual demod) */
292 	enum fe_stv0900_demod_mode	demod_mode;
293 
294 	/*Demods */
295 	s32	freq[2];
296 	s32	bw[2];
297 	s32	symbol_rate[2];
298 	s32	srch_range[2];
299 	/* for software/auto tuner */
300 	int	tuner_type[2];
301 
302 	/* algorithm for search Blind, Cold or Warm*/
303 	enum fe_stv0900_search_algo	srch_algo[2];
304 	/* search standard: Auto, DVBS1/DSS only or DVBS2 only*/
305 	enum fe_stv0900_search_standard	srch_standard[2];
306 	/* inversion search : auto, auto norma first, normal or inverted */
307 	enum fe_stv0900_search_iq	srch_iq_inv[2];
308 	enum fe_stv0900_modcode		modcode[2];
309 	enum fe_stv0900_modulation	modulation[2];
310 	enum fe_stv0900_fec		fec[2];
311 
312 	struct stv0900_signal_info	result[2];
313 	enum fe_stv0900_error		err[2];
314 
315 
316 	struct i2c_adapter	*i2c_adap;
317 	u8			i2c_addr;
318 	u8			clkmode;/* 0 for CLKI, 2 for XTALI */
319 	u8			chip_id;
320 	struct stv0900_reg	*ts_config;
321 	enum fe_stv0900_error	errs;
322 	int dmds_used;
323 };
324 
325 /* state for each demod */
326 struct stv0900_state {
327 	/* pointer for internal params, one for each pair of demods */
328 	struct stv0900_internal		*internal;
329 	struct i2c_adapter		*i2c_adap;
330 	const struct stv0900_config	*config;
331 	struct dvb_frontend		frontend;
332 	int demod;
333 };
334 
335 extern int stvdebug;
336 
337 extern s32 ge2comp(s32 a, s32 width);
338 
339 extern void stv0900_write_reg(struct stv0900_internal *i_params,
340 				u16 reg_addr, u8 reg_data);
341 
342 extern u8 stv0900_read_reg(struct stv0900_internal *i_params,
343 				u16 reg_addr);
344 
345 extern void stv0900_write_bits(struct stv0900_internal *i_params,
346 				u32 label, u8 val);
347 
348 extern u8 stv0900_get_bits(struct stv0900_internal *i_params,
349 				u32 label);
350 
351 extern int stv0900_get_demod_lock(struct stv0900_internal *i_params,
352 				enum fe_stv0900_demod_num demod, s32 time_out);
353 extern int stv0900_check_signal_presence(struct stv0900_internal *i_params,
354 				enum fe_stv0900_demod_num demod);
355 
356 extern enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe);
357 
358 extern void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency,
359 				u32 bandwidth);
360 extern void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth);
361 
362 extern void stv0900_start_search(struct stv0900_internal *i_params,
363 				enum fe_stv0900_demod_num demod);
364 
365 extern u8 stv0900_get_optim_carr_loop(s32 srate,
366 				enum fe_stv0900_modcode modcode,
367 				s32 pilot, u8 chip_id);
368 
369 extern u8 stv0900_get_optim_short_carr_loop(s32 srate,
370 				enum fe_stv0900_modulation modulation,
371 				u8 chip_id);
372 
373 extern void stv0900_stop_all_s2_modcod(struct stv0900_internal *i_params,
374 				enum fe_stv0900_demod_num demod);
375 
376 extern void stv0900_activate_s2_modcod(struct stv0900_internal *i_params,
377 				enum fe_stv0900_demod_num demod);
378 
379 extern void stv0900_activate_s2_modcod_single(struct stv0900_internal *i_params,
380 				enum fe_stv0900_demod_num demod);
381 
382 extern enum
383 fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe,
384 				enum fe_stv0900_demod_num demod);
385 
386 extern u32
387 stv0900_get_freq_auto(struct stv0900_internal *intp, int demod);
388 
389 extern void
390 stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency,
391 						u32 Bandwidth, int demod);
392 
393 #endif
394