md-cluster: Fix potential error pointer dereference in resize_bitmaps()
[linux/fpc-iii.git] / drivers / media / dvb-frontends / stv0900_priv.h
blob370d5fc1c22759a23d762d5022b0e39d43808a01
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * stv0900_priv.h
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)
20 #ifndef MAKEWORD
21 #define MAKEWORD(X, Y) (((X) << 8) + (Y))
22 #endif
24 #define LSB(X) (((X) & 0xFF))
25 #define MSB(Y) (((Y) >> 8) & 0xFF)
27 #ifndef TRUE
28 #define TRUE (1 == 1)
29 #endif
30 #ifndef FALSE
31 #define FALSE (!TRUE)
32 #endif
34 #define dprintk(args...) \
35 do { \
36 if (stvdebug) \
37 printk(KERN_DEBUG args); \
38 } while (0)
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 */
52 struct stv0900_table{
53 s32 size;/* Size of the lookup table */
54 struct stv000_lookpoint table[STV0900_MAXLOOKUPSIZE];/* Lookup table */
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,
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 {
74 STV0900_SEARCH = 0,
75 STV0900_PLH_DETECTED,
76 STV0900_DVBS2_FOUND,
77 STV0900_DVBS_FOUND
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 {
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
104 enum fe_stv0900_demod_num {
105 STV0900_DEMOD_1,
106 STV0900_DEMOD_2
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 {
118 STV0900_AUTO_SEARCH,
119 STV0900_SEARCH_DVBS1,/* Search Standard*/
120 STV0900_SEARCH_DVBS2,
121 STV0900_SEARCH_DSS,
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 {
132 STV0900_QPSK,
133 STV0900_8PSK,
134 STV0900_16APSK,
135 STV0900_32APSK,
136 STV0900_UNKNOWN
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
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
184 enum fe_stv0900_frame_length {
185 STV0900_LONG_FRAME,
186 STV0900_SHORT_FRAME
189 enum fe_stv0900_pilot {
190 STV0900_PILOTS_OFF,
191 STV0900_PILOTS_ON
194 enum fe_stv0900_rolloff {
195 STV0900_35,
196 STV0900_25,
197 STV0900_20
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
207 enum stv0900_iq_inversion {
208 STV0900_IQ_NORMAL,
209 STV0900_IQ_SWAPPED
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 {
221 STV0900_SINGLE = 0,
222 STV0900_DUAL
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;
233 u8 tun1_maddress;
234 int tuner1_adc;
235 int tuner1_type;
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;
241 u8 tun2_maddress;
242 int tuner2_adc;
243 int tuner2_type;
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{
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;
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];
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;
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;
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;
335 extern int stvdebug;
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,
343 u16 reg_addr);
345 extern void stv0900_write_bits(struct stv0900_internal *i_params,
346 u32 label, u8 val);
348 extern u8 stv0900_get_bits(struct stv0900_internal *i_params,
349 u32 label);
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,
359 u32 bandwidth);
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,
371 u8 chip_id);
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);
382 extern enum
383 fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe,
384 enum fe_stv0900_demod_num demod);
386 extern u32
387 stv0900_get_freq_auto(struct stv0900_internal *intp, int demod);
389 extern void
390 stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency,
391 u32 Bandwidth, int demod);
393 #endif