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 dmd_reg(a, b, c) \
53 case STV0900_DEMOD_1: \
57 case STV0900_DEMOD_2: \
63 #define dmd_choose(a, b) (demod = STV0900_DEMOD_2 ? b : a))
67 #define dprintk(args...) \
70 printk(KERN_DEBUG args); \
73 #define STV0900_MAXLOOKUPSIZE 500
74 #define STV0900_BLIND_SEARCH_AGC2_TH 700
76 /* One point of the lookup table */
77 struct stv000_lookpoint {
78 s32 realval;/* real value */
79 s32 regval;/* binary value */
82 /* Lookup table definition */
84 s32 size;/* Size of the lookup table */
85 struct stv000_lookpoint table[STV0900_MAXLOOKUPSIZE];/* Lookup table */
88 enum fe_stv0900_error {
90 STV0900_INVALID_HANDLE,
91 STV0900_BAD_PARAMETER,
93 STV0900_SEARCH_FAILED,
96 enum fe_stv0900_clock_type {
97 STV0900_USE_REGISTERS_DEFAULT,
98 STV0900_SERIAL_PUNCT_CLOCK,/*Serial punctured clock */
99 STV0900_SERIAL_CONT_CLOCK,/*Serial continues clock */
100 STV0900_PARALLEL_PUNCT_CLOCK,/*Parallel punctured clock */
101 STV0900_DVBCI_CLOCK/*Parallel continues clock : DVBCI */
104 enum fe_stv0900_search_state {
106 STV0900_PLH_DETECTED,
112 enum fe_stv0900_ldpc_state {
113 STV0900_PATH1_OFF_PATH2_OFF = 0,
114 STV0900_PATH1_ON_PATH2_OFF = 1,
115 STV0900_PATH1_OFF_PATH2_ON = 2,
116 STV0900_PATH1_ON_PATH2_ON = 3
119 enum fe_stv0900_signal_type {
123 STV0900_ANALOGCARRIER,
135 enum fe_stv0900_demod_num {
140 enum fe_stv0900_tracking_standard {
141 STV0900_DVBS1_STANDARD,/* Found Standard*/
142 STV0900_DVBS2_STANDARD,
143 STV0900_DSS_STANDARD,
144 STV0900_TURBOCODE_STANDARD,
145 STV0900_UNKNOWN_STANDARD
148 enum fe_stv0900_search_standard {
150 STV0900_SEARCH_DVBS1,/* Search Standard*/
151 STV0900_SEARCH_DVBS2,
153 STV0900_SEARCH_TURBOCODE
156 enum fe_stv0900_search_algo {
157 STV0900_BLIND_SEARCH,/* offset freq and SR are Unknown */
158 STV0900_COLD_START,/* only the SR is known */
159 STV0900_WARM_START/* offset freq and SR are known */
162 enum fe_stv0900_modulation {
170 enum fe_stv0900_modcode {
200 STV0900_MODCODE_UNKNOWN
203 enum fe_stv0900_fec {/*DVBS1, DSS and turbo code puncture rate*/
207 STV0900_FEC_4_5,/*for turbo code only*/
209 STV0900_FEC_6_7,/*for DSS only */
211 STV0900_FEC_8_9,/*for turbo code only*/
215 enum fe_stv0900_frame_length {
220 enum fe_stv0900_pilot {
225 enum fe_stv0900_rolloff {
231 enum fe_stv0900_search_iq {
233 STV0900_IQ_AUTO_NORMAL_FIRST,
234 STV0900_IQ_FORCE_NORMAL,
235 STV0900_IQ_FORCE_SWAPPED
238 enum stv0900_iq_inversion {
243 enum fe_stv0900_diseqc_mode {
244 STV0900_22KHZ_Continues = 0,
245 STV0900_DISEQC_2_3_PWM = 2,
246 STV0900_DISEQC_3_3_PWM = 3,
247 STV0900_DISEQC_2_3_ENVELOP = 4,
248 STV0900_DISEQC_3_3_ENVELOP = 5
251 enum fe_stv0900_demod_mode {
256 struct stv0900_init_params{
257 u32 dmd_ref_clk;/* Refrence,Input clock for the demod in Hz */
259 /* Demodulator Type (single demod or dual demod) */
260 enum fe_stv0900_demod_mode demod_mode;
261 enum fe_stv0900_rolloff rolloff;
262 enum fe_stv0900_clock_type path1_ts_clock;
267 /* IQ from the tuner1 to the demod */
268 enum stv0900_iq_inversion tun1_iq_inversion;
269 enum fe_stv0900_clock_type path2_ts_clock;
274 /* IQ from the tuner2 to the demod */
275 enum stv0900_iq_inversion tun2_iq_inversion;
278 struct stv0900_search_params {
279 enum fe_stv0900_demod_num path;/* Path Used demod1 or 2 */
281 u32 frequency;/* Transponder frequency (in KHz) */
282 u32 symbol_rate;/* Transponder symbol rate (in bds)*/
283 u32 search_range;/* Range of the search (in Hz) */
285 enum fe_stv0900_search_standard standard;
286 enum fe_stv0900_modulation modulation;
287 enum fe_stv0900_fec fec;
288 enum fe_stv0900_modcode modcode;
289 enum fe_stv0900_search_iq iq_inversion;
290 enum fe_stv0900_search_algo search_algo;
294 struct stv0900_signal_info {
295 int locked;/* Transponder locked */
296 u32 frequency;/* Transponder frequency (in KHz) */
297 u32 symbol_rate;/* Transponder symbol rate (in Mbds) */
299 enum fe_stv0900_tracking_standard standard;
300 enum fe_stv0900_fec fec;
301 enum fe_stv0900_modcode modcode;
302 enum fe_stv0900_modulation modulation;
303 enum fe_stv0900_pilot pilot;
304 enum fe_stv0900_frame_length frame_length;
305 enum stv0900_iq_inversion spectrum;
306 enum fe_stv0900_rolloff rolloff;
308 s32 Power;/* Power of the RF signal (dBm) */
309 s32 C_N;/* Carrier to noise ratio (dB x10)*/
310 u32 BER;/* Bit error rate (x10^7) */
314 struct stv0900_internal{
317 /* manual RollOff for DVBS1/DSS only */
318 enum fe_stv0900_rolloff rolloff;
319 /* Demodulator use for single demod or for dual demod) */
320 enum fe_stv0900_demod_mode demod_mode;
325 s32 dmd1_symbol_rate;
328 /* algorithm for search Blind, Cold or Warm*/
329 enum fe_stv0900_search_algo dmd1_srch_algo;
330 /* search standard: Auto, DVBS1/DSS only or DVBS2 only*/
331 enum fe_stv0900_search_standard dmd1_srch_standard;
332 /* inversion search : auto, auto norma first, normal or inverted */
333 enum fe_stv0900_search_iq dmd1_srch_iq_inv;
334 enum fe_stv0900_modcode dmd1_modcode;
335 enum fe_stv0900_modulation dmd1_modulation;
336 enum fe_stv0900_fec dmd1_fec;
338 struct stv0900_signal_info dmd1_rslts;
339 enum fe_stv0900_signal_type dmd1_state;
341 enum fe_stv0900_error dmd1_err;
346 s32 dmd2_symbol_rate;
349 enum fe_stv0900_search_algo dmd2_srch_algo;
350 enum fe_stv0900_search_standard dmd2_srch_stndrd;
351 /* inversion search : auto, auto normal first, normal or inverted */
352 enum fe_stv0900_search_iq dmd2_srch_iq_inv;
353 enum fe_stv0900_modcode dmd2_modcode;
354 enum fe_stv0900_modulation dmd2_modulation;
355 enum fe_stv0900_fec dmd2_fec;
357 /* results of the search*/
358 struct stv0900_signal_info dmd2_rslts;
359 /* current state of the search algorithm */
360 enum fe_stv0900_signal_type dmd2_state;
362 enum fe_stv0900_error dmd2_err;
364 struct i2c_adapter *i2c_adap;
366 u8 clkmode;/* 0 for CLKI, 2 for XTALI */
368 enum fe_stv0900_error errs;
372 /* state for each demod */
373 struct stv0900_state {
374 /* pointer for internal params, one for each pair of demods */
375 struct stv0900_internal *internal;
376 struct i2c_adapter *i2c_adap;
377 const struct stv0900_config *config;
378 struct dvb_frontend frontend;
382 extern s32 ge2comp(s32 a, s32 width);
384 extern void stv0900_write_reg(struct stv0900_internal *i_params,
385 u16 reg_addr, u8 reg_data);
387 extern u8 stv0900_read_reg(struct stv0900_internal *i_params,
390 extern void stv0900_write_bits(struct stv0900_internal *i_params,
393 extern u8 stv0900_get_bits(struct stv0900_internal *i_params,
396 extern int stv0900_get_demod_lock(struct stv0900_internal *i_params,
397 enum fe_stv0900_demod_num demod, s32 time_out);
398 extern int stv0900_check_signal_presence(struct stv0900_internal *i_params,
399 enum fe_stv0900_demod_num demod);
401 extern enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe);
403 extern void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency,
405 extern void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth);
407 extern void stv0900_start_search(struct stv0900_internal *i_params,
408 enum fe_stv0900_demod_num demod);
410 extern u8 stv0900_get_optim_carr_loop(s32 srate,
411 enum fe_stv0900_modcode modcode,
412 s32 pilot, u8 chip_id);
414 extern u8 stv0900_get_optim_short_carr_loop(s32 srate,
415 enum fe_stv0900_modulation modulation,
418 extern void stv0900_stop_all_s2_modcod(struct stv0900_internal *i_params,
419 enum fe_stv0900_demod_num demod);
421 extern void stv0900_activate_s2_modcode(struct stv0900_internal *i_params,
422 enum fe_stv0900_demod_num demod);
424 extern void stv0900_activate_s2_modcode_single(struct stv0900_internal *i_params,
425 enum fe_stv0900_demod_num demod);
427 extern enum fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe,
428 enum fe_stv0900_demod_num demod);