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.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #ifndef STV0900_PRIV_H
27 #define STV0900_PRIV_H
29 #include <linux/i2c.h>
31 #define ABS(X) ((X) < 0 ? (-1 * (X)) : (X))
32 #define INRANGE(X, Y, Z) ((((X) <= (Y)) && ((Y) <= (Z))) \
33 || (((Z) <= (Y)) && ((Y) <= (X))) ? 1 : 0)
36 #define MAKEWORD(X, Y) (((X) << 8) + (Y))
39 #define LSB(X) (((X) & 0xFF))
40 #define MSB(Y) (((Y) >> 8) & 0xFF)
49 #define dprintk(args...) \
52 printk(KERN_DEBUG args); \
55 #define STV0900_MAXLOOKUPSIZE 500
56 #define STV0900_BLIND_SEARCH_AGC2_TH 700
57 #define STV0900_BLIND_SEARCH_AGC2_TH_CUT30 1400
58 #define IQPOWER_THRESHOLD 30
60 /* One point of the lookup table */
61 struct stv000_lookpoint
{
62 s32 realval
;/* real value */
63 s32 regval
;/* binary value */
66 /* Lookup table definition */
68 s32 size
;/* Size of the lookup table */
69 struct stv000_lookpoint table
[STV0900_MAXLOOKUPSIZE
];/* Lookup table */
72 enum fe_stv0900_error
{
74 STV0900_INVALID_HANDLE
,
75 STV0900_BAD_PARAMETER
,
77 STV0900_SEARCH_FAILED
,
80 enum fe_stv0900_clock_type
{
81 STV0900_USE_REGISTERS_DEFAULT
,
82 STV0900_SERIAL_PUNCT_CLOCK
,/*Serial punctured clock */
83 STV0900_SERIAL_CONT_CLOCK
,/*Serial continues clock */
84 STV0900_PARALLEL_PUNCT_CLOCK
,/*Parallel punctured clock */
85 STV0900_DVBCI_CLOCK
/*Parallel continues clock : DVBCI */
88 enum fe_stv0900_search_state
{
96 enum fe_stv0900_ldpc_state
{
97 STV0900_PATH1_OFF_PATH2_OFF
= 0,
98 STV0900_PATH1_ON_PATH2_OFF
= 1,
99 STV0900_PATH1_OFF_PATH2_ON
= 2,
100 STV0900_PATH1_ON_PATH2_ON
= 3
103 enum fe_stv0900_signal_type
{
107 STV0900_ANALOGCARRIER
,
119 enum fe_stv0900_demod_num
{
124 enum fe_stv0900_tracking_standard
{
125 STV0900_DVBS1_STANDARD
,/* Found Standard*/
126 STV0900_DVBS2_STANDARD
,
127 STV0900_DSS_STANDARD
,
128 STV0900_TURBOCODE_STANDARD
,
129 STV0900_UNKNOWN_STANDARD
132 enum fe_stv0900_search_standard
{
134 STV0900_SEARCH_DVBS1
,/* Search Standard*/
135 STV0900_SEARCH_DVBS2
,
137 STV0900_SEARCH_TURBOCODE
140 enum fe_stv0900_search_algo
{
141 STV0900_BLIND_SEARCH
,/* offset freq and SR are Unknown */
142 STV0900_COLD_START
,/* only the SR is known */
143 STV0900_WARM_START
/* offset freq and SR are known */
146 enum fe_stv0900_modulation
{
154 enum fe_stv0900_modcode
{
184 STV0900_MODCODE_UNKNOWN
187 enum fe_stv0900_fec
{/*DVBS1, DSS and turbo code puncture rate*/
191 STV0900_FEC_4_5
,/*for turbo code only*/
193 STV0900_FEC_6_7
,/*for DSS only */
195 STV0900_FEC_8_9
,/*for turbo code only*/
199 enum fe_stv0900_frame_length
{
204 enum fe_stv0900_pilot
{
209 enum fe_stv0900_rolloff
{
215 enum fe_stv0900_search_iq
{
217 STV0900_IQ_AUTO_NORMAL_FIRST
,
218 STV0900_IQ_FORCE_NORMAL
,
219 STV0900_IQ_FORCE_SWAPPED
222 enum stv0900_iq_inversion
{
227 enum fe_stv0900_diseqc_mode
{
228 STV0900_22KHZ_Continues
= 0,
229 STV0900_DISEQC_2_3_PWM
= 2,
230 STV0900_DISEQC_3_3_PWM
= 3,
231 STV0900_DISEQC_2_3_ENVELOP
= 4,
232 STV0900_DISEQC_3_3_ENVELOP
= 5
235 enum fe_stv0900_demod_mode
{
240 struct stv0900_init_params
{
241 u32 dmd_ref_clk
;/* Refrence,Input clock for the demod in Hz */
243 /* Demodulator Type (single demod or dual demod) */
244 enum fe_stv0900_demod_mode demod_mode
;
245 enum fe_stv0900_rolloff rolloff
;
246 enum fe_stv0900_clock_type path1_ts_clock
;
252 /* IQ from the tuner1 to the demod */
253 enum stv0900_iq_inversion tun1_iq_inv
;
254 enum fe_stv0900_clock_type path2_ts_clock
;
260 /* IQ from the tuner2 to the demod */
261 enum stv0900_iq_inversion tun2_iq_inv
;
262 struct stv0900_reg
*ts_config
;
265 struct stv0900_search_params
{
266 enum fe_stv0900_demod_num path
;/* Path Used demod1 or 2 */
268 u32 frequency
;/* Transponder frequency (in KHz) */
269 u32 symbol_rate
;/* Transponder symbol rate (in bds)*/
270 u32 search_range
;/* Range of the search (in Hz) */
272 enum fe_stv0900_search_standard standard
;
273 enum fe_stv0900_modulation modulation
;
274 enum fe_stv0900_fec fec
;
275 enum fe_stv0900_modcode modcode
;
276 enum fe_stv0900_search_iq iq_inversion
;
277 enum fe_stv0900_search_algo search_algo
;
281 struct stv0900_signal_info
{
282 int locked
;/* Transponder locked */
283 u32 frequency
;/* Transponder frequency (in KHz) */
284 u32 symbol_rate
;/* Transponder symbol rate (in Mbds) */
286 enum fe_stv0900_tracking_standard standard
;
287 enum fe_stv0900_fec fec
;
288 enum fe_stv0900_modcode modcode
;
289 enum fe_stv0900_modulation modulation
;
290 enum fe_stv0900_pilot pilot
;
291 enum fe_stv0900_frame_length frame_len
;
292 enum stv0900_iq_inversion spectrum
;
293 enum fe_stv0900_rolloff rolloff
;
295 s32 Power
;/* Power of the RF signal (dBm) */
296 s32 C_N
;/* Carrier to noise ratio (dB x10)*/
297 u32 BER
;/* Bit error rate (x10^7) */
301 struct stv0900_internal
{
304 /* manual RollOff for DVBS1/DSS only */
305 enum fe_stv0900_rolloff rolloff
;
306 /* Demodulator use for single demod or for dual demod) */
307 enum fe_stv0900_demod_mode demod_mode
;
314 /* for software/auto tuner */
317 /* algorithm for search Blind, Cold or Warm*/
318 enum fe_stv0900_search_algo srch_algo
[2];
319 /* search standard: Auto, DVBS1/DSS only or DVBS2 only*/
320 enum fe_stv0900_search_standard srch_standard
[2];
321 /* inversion search : auto, auto norma first, normal or inverted */
322 enum fe_stv0900_search_iq srch_iq_inv
[2];
323 enum fe_stv0900_modcode modcode
[2];
324 enum fe_stv0900_modulation modulation
[2];
325 enum fe_stv0900_fec fec
[2];
327 struct stv0900_signal_info result
[2];
328 enum fe_stv0900_error err
[2];
331 struct i2c_adapter
*i2c_adap
;
333 u8 clkmode
;/* 0 for CLKI, 2 for XTALI */
335 struct stv0900_reg
*ts_config
;
336 enum fe_stv0900_error errs
;
340 /* state for each demod */
341 struct stv0900_state
{
342 /* pointer for internal params, one for each pair of demods */
343 struct stv0900_internal
*internal
;
344 struct i2c_adapter
*i2c_adap
;
345 const struct stv0900_config
*config
;
346 struct dvb_frontend frontend
;
352 extern s32
ge2comp(s32 a
, s32 width
);
354 extern void stv0900_write_reg(struct stv0900_internal
*i_params
,
355 u16 reg_addr
, u8 reg_data
);
357 extern u8
stv0900_read_reg(struct stv0900_internal
*i_params
,
360 extern void stv0900_write_bits(struct stv0900_internal
*i_params
,
363 extern u8
stv0900_get_bits(struct stv0900_internal
*i_params
,
366 extern int stv0900_get_demod_lock(struct stv0900_internal
*i_params
,
367 enum fe_stv0900_demod_num demod
, s32 time_out
);
368 extern int stv0900_check_signal_presence(struct stv0900_internal
*i_params
,
369 enum fe_stv0900_demod_num demod
);
371 extern enum fe_stv0900_signal_type
stv0900_algo(struct dvb_frontend
*fe
);
373 extern void stv0900_set_tuner(struct dvb_frontend
*fe
, u32 frequency
,
375 extern void stv0900_set_bandwidth(struct dvb_frontend
*fe
, u32 bandwidth
);
377 extern void stv0900_start_search(struct stv0900_internal
*i_params
,
378 enum fe_stv0900_demod_num demod
);
380 extern u8
stv0900_get_optim_carr_loop(s32 srate
,
381 enum fe_stv0900_modcode modcode
,
382 s32 pilot
, u8 chip_id
);
384 extern u8
stv0900_get_optim_short_carr_loop(s32 srate
,
385 enum fe_stv0900_modulation modulation
,
388 extern void stv0900_stop_all_s2_modcod(struct stv0900_internal
*i_params
,
389 enum fe_stv0900_demod_num demod
);
391 extern void stv0900_activate_s2_modcod(struct stv0900_internal
*i_params
,
392 enum fe_stv0900_demod_num demod
);
394 extern void stv0900_activate_s2_modcod_single(struct stv0900_internal
*i_params
,
395 enum fe_stv0900_demod_num demod
);
398 fe_stv0900_tracking_standard
stv0900_get_standard(struct dvb_frontend
*fe
,
399 enum fe_stv0900_demod_num demod
);
402 stv0900_get_freq_auto(struct stv0900_internal
*intp
, int demod
);
405 stv0900_set_tuner_auto(struct stv0900_internal
*intp
, u32 Frequency
,
406 u32 Bandwidth
, int demod
);