1 /* SPDX-License-Identifier: GPL-2.0-or-later */
5 * Driver for ST STV0900 satellite demodulator IC.
7 * Copyright (C) ST Microelectronics.
8 * Copyright (C) 2009 NetUP Inc.
9 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
12 #ifndef STV0900_PRIV_H
13 #define STV0900_PRIV_H
15 #include <linux/i2c.h>
17 #define INRANGE(X, Y, Z) ((((X) <= (Y)) && ((Y) <= (Z))) \
18 || (((Z) <= (Y)) && ((Y) <= (X))) ? 1 : 0)
21 #define MAKEWORD(X, Y) (((X) << 8) + (Y))
24 #define LSB(X) (((X) & 0xFF))
25 #define MSB(Y) (((Y) >> 8) & 0xFF)
34 #define dprintk(args...) \
37 printk(KERN_DEBUG args); \
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
45 /* One point of the lookup table */
46 struct stv000_lookpoint {
47 s32 realval;/* real value */
48 s32 regval;/* binary value */
51 /* Lookup table definition */
53 s32 size;/* Size of the lookup table */
54 struct stv000_lookpoint table[STV0900_MAXLOOKUPSIZE];/* Lookup table */
57 enum fe_stv0900_error {
59 STV0900_INVALID_HANDLE,
60 STV0900_BAD_PARAMETER,
62 STV0900_SEARCH_FAILED,
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 */
73 enum fe_stv0900_search_state {
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
88 enum fe_stv0900_signal_type {
92 STV0900_ANALOGCARRIER,
104 enum fe_stv0900_demod_num {
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
117 enum fe_stv0900_search_standard {
119 STV0900_SEARCH_DVBS1,/* Search Standard*/
120 STV0900_SEARCH_DVBS2,
122 STV0900_SEARCH_TURBOCODE
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 */
131 enum fe_stv0900_modulation {
139 enum fe_stv0900_modcode {
169 STV0900_MODCODE_UNKNOWN
172 enum fe_stv0900_fec {/*DVBS1, DSS and turbo code puncture rate*/
176 STV0900_FEC_4_5,/*for turbo code only*/
178 STV0900_FEC_6_7,/*for DSS only */
180 STV0900_FEC_8_9,/*for turbo code only*/
184 enum fe_stv0900_frame_length {
189 enum fe_stv0900_pilot {
194 enum fe_stv0900_rolloff {
200 enum fe_stv0900_search_iq {
202 STV0900_IQ_AUTO_NORMAL_FIRST,
203 STV0900_IQ_FORCE_NORMAL,
204 STV0900_IQ_FORCE_SWAPPED
207 enum stv0900_iq_inversion {
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
220 enum fe_stv0900_demod_mode {
225 struct stv0900_init_params{
226 u32 dmd_ref_clk;/* Reference,Input clock for the demod in Hz */
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;
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;
245 /* IQ from the tuner2 to the demod */
246 enum stv0900_iq_inversion tun2_iq_inv;
247 struct stv0900_reg *ts_config;
250 struct stv0900_search_params {
251 enum fe_stv0900_demod_num path;/* Path Used demod1 or 2 */
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) */
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;
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) */
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;
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) */
286 struct stv0900_internal{
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;
299 /* for software/auto tuner */
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];
312 struct stv0900_signal_info result[2];
313 enum fe_stv0900_error err[2];
316 struct i2c_adapter *i2c_adap;
318 u8 clkmode;/* 0 for CLKI, 2 for XTALI */
320 struct stv0900_reg *ts_config;
321 enum fe_stv0900_error errs;
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;
337 extern s32 ge2comp(s32 a, s32 width);
339 extern void stv0900_write_reg(struct stv0900_internal *i_params,
340 u16 reg_addr, u8 reg_data);
342 extern u8 stv0900_read_reg(struct stv0900_internal *i_params,
345 extern void stv0900_write_bits(struct stv0900_internal *i_params,
348 extern u8 stv0900_get_bits(struct stv0900_internal *i_params,
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);
356 extern enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe);
358 extern void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency,
360 extern void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth);
362 extern void stv0900_start_search(struct stv0900_internal *i_params,
363 enum fe_stv0900_demod_num demod);
365 extern u8 stv0900_get_optim_carr_loop(s32 srate,
366 enum fe_stv0900_modcode modcode,
367 s32 pilot, u8 chip_id);
369 extern u8 stv0900_get_optim_short_carr_loop(s32 srate,
370 enum fe_stv0900_modulation modulation,
373 extern void stv0900_stop_all_s2_modcod(struct stv0900_internal *i_params,
374 enum fe_stv0900_demod_num demod);
376 extern void stv0900_activate_s2_modcod(struct stv0900_internal *i_params,
377 enum fe_stv0900_demod_num demod);
379 extern void stv0900_activate_s2_modcod_single(struct stv0900_internal *i_params,
380 enum fe_stv0900_demod_num demod);
383 fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe,
384 enum fe_stv0900_demod_num demod);
387 stv0900_get_freq_auto(struct stv0900_internal *intp, int demod);
390 stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency,
391 u32 Bandwidth, int demod);