4 * Driver for ST STV0900 satellite demodulator IC.
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
22 #ifndef STV0900_PRIV_H
23 #define STV0900_PRIV_H
25 #include <linux/i2c.h>
27 #define ABS(X) ((X) < 0 ? (-1 * (X)) : (X))
28 #define INRANGE(X, Y, Z) ((((X) <= (Y)) && ((Y) <= (Z))) \
29 || (((Z) <= (Y)) && ((Y) <= (X))) ? 1 : 0)
32 #define MAKEWORD(X, Y) (((X) << 8) + (Y))
35 #define LSB(X) (((X) & 0xFF))
36 #define MSB(Y) (((Y) >> 8) & 0xFF)
45 #define dprintk(args...) \
48 printk(KERN_DEBUG args); \
51 #define STV0900_MAXLOOKUPSIZE 500
52 #define STV0900_BLIND_SEARCH_AGC2_TH 700
53 #define STV0900_BLIND_SEARCH_AGC2_TH_CUT30 1400
54 #define IQPOWER_THRESHOLD 30
56 /* One point of the lookup table */
57 struct stv000_lookpoint
{
58 s32 realval
;/* real value */
59 s32 regval
;/* binary value */
62 /* Lookup table definition */
64 s32 size
;/* Size of the lookup table */
65 struct stv000_lookpoint table
[STV0900_MAXLOOKUPSIZE
];/* Lookup table */
68 enum fe_stv0900_error
{
70 STV0900_INVALID_HANDLE
,
71 STV0900_BAD_PARAMETER
,
73 STV0900_SEARCH_FAILED
,
76 enum fe_stv0900_clock_type
{
77 STV0900_USE_REGISTERS_DEFAULT
,
78 STV0900_SERIAL_PUNCT_CLOCK
,/*Serial punctured clock */
79 STV0900_SERIAL_CONT_CLOCK
,/*Serial continues clock */
80 STV0900_PARALLEL_PUNCT_CLOCK
,/*Parallel punctured clock */
81 STV0900_DVBCI_CLOCK
/*Parallel continues clock : DVBCI */
84 enum fe_stv0900_search_state
{
92 enum fe_stv0900_ldpc_state
{
93 STV0900_PATH1_OFF_PATH2_OFF
= 0,
94 STV0900_PATH1_ON_PATH2_OFF
= 1,
95 STV0900_PATH1_OFF_PATH2_ON
= 2,
96 STV0900_PATH1_ON_PATH2_ON
= 3
99 enum fe_stv0900_signal_type
{
103 STV0900_ANALOGCARRIER
,
115 enum fe_stv0900_demod_num
{
120 enum fe_stv0900_tracking_standard
{
121 STV0900_DVBS1_STANDARD
,/* Found Standard*/
122 STV0900_DVBS2_STANDARD
,
123 STV0900_DSS_STANDARD
,
124 STV0900_TURBOCODE_STANDARD
,
125 STV0900_UNKNOWN_STANDARD
128 enum fe_stv0900_search_standard
{
130 STV0900_SEARCH_DVBS1
,/* Search Standard*/
131 STV0900_SEARCH_DVBS2
,
133 STV0900_SEARCH_TURBOCODE
136 enum fe_stv0900_search_algo
{
137 STV0900_BLIND_SEARCH
,/* offset freq and SR are Unknown */
138 STV0900_COLD_START
,/* only the SR is known */
139 STV0900_WARM_START
/* offset freq and SR are known */
142 enum fe_stv0900_modulation
{
150 enum fe_stv0900_modcode
{
180 STV0900_MODCODE_UNKNOWN
183 enum fe_stv0900_fec
{/*DVBS1, DSS and turbo code puncture rate*/
187 STV0900_FEC_4_5
,/*for turbo code only*/
189 STV0900_FEC_6_7
,/*for DSS only */
191 STV0900_FEC_8_9
,/*for turbo code only*/
195 enum fe_stv0900_frame_length
{
200 enum fe_stv0900_pilot
{
205 enum fe_stv0900_rolloff
{
211 enum fe_stv0900_search_iq
{
213 STV0900_IQ_AUTO_NORMAL_FIRST
,
214 STV0900_IQ_FORCE_NORMAL
,
215 STV0900_IQ_FORCE_SWAPPED
218 enum stv0900_iq_inversion
{
223 enum fe_stv0900_diseqc_mode
{
224 STV0900_22KHZ_Continues
= 0,
225 STV0900_DISEQC_2_3_PWM
= 2,
226 STV0900_DISEQC_3_3_PWM
= 3,
227 STV0900_DISEQC_2_3_ENVELOP
= 4,
228 STV0900_DISEQC_3_3_ENVELOP
= 5
231 enum fe_stv0900_demod_mode
{
236 struct stv0900_init_params
{
237 u32 dmd_ref_clk
;/* Reference,Input clock for the demod in Hz */
239 /* Demodulator Type (single demod or dual demod) */
240 enum fe_stv0900_demod_mode demod_mode
;
241 enum fe_stv0900_rolloff rolloff
;
242 enum fe_stv0900_clock_type path1_ts_clock
;
248 /* IQ from the tuner1 to the demod */
249 enum stv0900_iq_inversion tun1_iq_inv
;
250 enum fe_stv0900_clock_type path2_ts_clock
;
256 /* IQ from the tuner2 to the demod */
257 enum stv0900_iq_inversion tun2_iq_inv
;
258 struct stv0900_reg
*ts_config
;
261 struct stv0900_search_params
{
262 enum fe_stv0900_demod_num path
;/* Path Used demod1 or 2 */
264 u32 frequency
;/* Transponder frequency (in KHz) */
265 u32 symbol_rate
;/* Transponder symbol rate (in bds)*/
266 u32 search_range
;/* Range of the search (in Hz) */
268 enum fe_stv0900_search_standard standard
;
269 enum fe_stv0900_modulation modulation
;
270 enum fe_stv0900_fec fec
;
271 enum fe_stv0900_modcode modcode
;
272 enum fe_stv0900_search_iq iq_inversion
;
273 enum fe_stv0900_search_algo search_algo
;
277 struct stv0900_signal_info
{
278 int locked
;/* Transponder locked */
279 u32 frequency
;/* Transponder frequency (in KHz) */
280 u32 symbol_rate
;/* Transponder symbol rate (in Mbds) */
282 enum fe_stv0900_tracking_standard standard
;
283 enum fe_stv0900_fec fec
;
284 enum fe_stv0900_modcode modcode
;
285 enum fe_stv0900_modulation modulation
;
286 enum fe_stv0900_pilot pilot
;
287 enum fe_stv0900_frame_length frame_len
;
288 enum stv0900_iq_inversion spectrum
;
289 enum fe_stv0900_rolloff rolloff
;
291 s32 Power
;/* Power of the RF signal (dBm) */
292 s32 C_N
;/* Carrier to noise ratio (dB x10)*/
293 u32 BER
;/* Bit error rate (x10^7) */
297 struct stv0900_internal
{
300 /* manual RollOff for DVBS1/DSS only */
301 enum fe_stv0900_rolloff rolloff
;
302 /* Demodulator use for single demod or for dual demod) */
303 enum fe_stv0900_demod_mode demod_mode
;
310 /* for software/auto tuner */
313 /* algorithm for search Blind, Cold or Warm*/
314 enum fe_stv0900_search_algo srch_algo
[2];
315 /* search standard: Auto, DVBS1/DSS only or DVBS2 only*/
316 enum fe_stv0900_search_standard srch_standard
[2];
317 /* inversion search : auto, auto norma first, normal or inverted */
318 enum fe_stv0900_search_iq srch_iq_inv
[2];
319 enum fe_stv0900_modcode modcode
[2];
320 enum fe_stv0900_modulation modulation
[2];
321 enum fe_stv0900_fec fec
[2];
323 struct stv0900_signal_info result
[2];
324 enum fe_stv0900_error err
[2];
327 struct i2c_adapter
*i2c_adap
;
329 u8 clkmode
;/* 0 for CLKI, 2 for XTALI */
331 struct stv0900_reg
*ts_config
;
332 enum fe_stv0900_error errs
;
336 /* state for each demod */
337 struct stv0900_state
{
338 /* pointer for internal params, one for each pair of demods */
339 struct stv0900_internal
*internal
;
340 struct i2c_adapter
*i2c_adap
;
341 const struct stv0900_config
*config
;
342 struct dvb_frontend frontend
;
348 extern s32
ge2comp(s32 a
, s32 width
);
350 extern void stv0900_write_reg(struct stv0900_internal
*i_params
,
351 u16 reg_addr
, u8 reg_data
);
353 extern u8
stv0900_read_reg(struct stv0900_internal
*i_params
,
356 extern void stv0900_write_bits(struct stv0900_internal
*i_params
,
359 extern u8
stv0900_get_bits(struct stv0900_internal
*i_params
,
362 extern int stv0900_get_demod_lock(struct stv0900_internal
*i_params
,
363 enum fe_stv0900_demod_num demod
, s32 time_out
);
364 extern int stv0900_check_signal_presence(struct stv0900_internal
*i_params
,
365 enum fe_stv0900_demod_num demod
);
367 extern enum fe_stv0900_signal_type
stv0900_algo(struct dvb_frontend
*fe
);
369 extern void stv0900_set_tuner(struct dvb_frontend
*fe
, u32 frequency
,
371 extern void stv0900_set_bandwidth(struct dvb_frontend
*fe
, u32 bandwidth
);
373 extern void stv0900_start_search(struct stv0900_internal
*i_params
,
374 enum fe_stv0900_demod_num demod
);
376 extern u8
stv0900_get_optim_carr_loop(s32 srate
,
377 enum fe_stv0900_modcode modcode
,
378 s32 pilot
, u8 chip_id
);
380 extern u8
stv0900_get_optim_short_carr_loop(s32 srate
,
381 enum fe_stv0900_modulation modulation
,
384 extern void stv0900_stop_all_s2_modcod(struct stv0900_internal
*i_params
,
385 enum fe_stv0900_demod_num demod
);
387 extern void stv0900_activate_s2_modcod(struct stv0900_internal
*i_params
,
388 enum fe_stv0900_demod_num demod
);
390 extern void stv0900_activate_s2_modcod_single(struct stv0900_internal
*i_params
,
391 enum fe_stv0900_demod_num demod
);
394 fe_stv0900_tracking_standard
stv0900_get_standard(struct dvb_frontend
*fe
,
395 enum fe_stv0900_demod_num demod
);
398 stv0900_get_freq_auto(struct stv0900_internal
*intp
, int demod
);
401 stv0900_set_tuner_auto(struct stv0900_internal
*intp
, u32 Frequency
,
402 u32 Bandwidth
, int demod
);