1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef STV0900_PRIV_H
27#define STV0900_PRIV_H
28
29#include <linux/i2c.h>
30
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)
34
35#ifndef MAKEWORD
36#define MAKEWORD(X, Y) (((X) << 8) + (Y))
37#endif
38
39#define LSB(X) (((X) & 0xFF))
40#define MSB(Y) (((Y) >> 8) & 0xFF)
41
42#ifndef TRUE
43#define TRUE (1 == 1)
44#endif
45#ifndef FALSE
46#define FALSE (!TRUE)
47#endif
48
49#define dprintk(args...) \
50 do { \
51 if (stvdebug) \
52 printk(KERN_DEBUG args); \
53 } while (0)
54
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
59
60
61struct stv000_lookpoint {
62 s32 realval;
63 s32 regval;
64};
65
66
67struct stv0900_table{
68 s32 size;
69 struct stv000_lookpoint table[STV0900_MAXLOOKUPSIZE];
70};
71
72enum fe_stv0900_error {
73 STV0900_NO_ERROR = 0,
74 STV0900_INVALID_HANDLE,
75 STV0900_BAD_PARAMETER,
76 STV0900_I2C_ERROR,
77 STV0900_SEARCH_FAILED,
78};
79
80enum fe_stv0900_clock_type {
81 STV0900_USE_REGISTERS_DEFAULT,
82 STV0900_SERIAL_PUNCT_CLOCK,
83 STV0900_SERIAL_CONT_CLOCK,
84 STV0900_PARALLEL_PUNCT_CLOCK,
85 STV0900_DVBCI_CLOCK
86};
87
88enum fe_stv0900_search_state {
89 STV0900_SEARCH = 0,
90 STV0900_PLH_DETECTED,
91 STV0900_DVBS2_FOUND,
92 STV0900_DVBS_FOUND
93
94};
95
96enum 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
101};
102
103enum fe_stv0900_signal_type {
104 STV0900_NOAGC1 = 0,
105 STV0900_AGC1OK,
106 STV0900_NOTIMING,
107 STV0900_ANALOGCARRIER,
108 STV0900_TIMINGOK,
109 STV0900_NOAGC2,
110 STV0900_AGC2OK,
111 STV0900_NOCARRIER,
112 STV0900_CARRIEROK,
113 STV0900_NODATA,
114 STV0900_DATAOK,
115 STV0900_OUTOFRANGE,
116 STV0900_RANGEOK
117};
118
119enum fe_stv0900_demod_num {
120 STV0900_DEMOD_1,
121 STV0900_DEMOD_2
122};
123
124enum fe_stv0900_tracking_standard {
125 STV0900_DVBS1_STANDARD,
126 STV0900_DVBS2_STANDARD,
127 STV0900_DSS_STANDARD,
128 STV0900_TURBOCODE_STANDARD,
129 STV0900_UNKNOWN_STANDARD
130};
131
132enum fe_stv0900_search_standard {
133 STV0900_AUTO_SEARCH,
134 STV0900_SEARCH_DVBS1,
135 STV0900_SEARCH_DVBS2,
136 STV0900_SEARCH_DSS,
137 STV0900_SEARCH_TURBOCODE
138};
139
140enum fe_stv0900_search_algo {
141 STV0900_BLIND_SEARCH,
142 STV0900_COLD_START,
143 STV0900_WARM_START
144};
145
146enum fe_stv0900_modulation {
147 STV0900_QPSK,
148 STV0900_8PSK,
149 STV0900_16APSK,
150 STV0900_32APSK,
151 STV0900_UNKNOWN
152};
153
154enum fe_stv0900_modcode {
155 STV0900_DUMMY_PLF,
156 STV0900_QPSK_14,
157 STV0900_QPSK_13,
158 STV0900_QPSK_25,
159 STV0900_QPSK_12,
160 STV0900_QPSK_35,
161 STV0900_QPSK_23,
162 STV0900_QPSK_34,
163 STV0900_QPSK_45,
164 STV0900_QPSK_56,
165 STV0900_QPSK_89,
166 STV0900_QPSK_910,
167 STV0900_8PSK_35,
168 STV0900_8PSK_23,
169 STV0900_8PSK_34,
170 STV0900_8PSK_56,
171 STV0900_8PSK_89,
172 STV0900_8PSK_910,
173 STV0900_16APSK_23,
174 STV0900_16APSK_34,
175 STV0900_16APSK_45,
176 STV0900_16APSK_56,
177 STV0900_16APSK_89,
178 STV0900_16APSK_910,
179 STV0900_32APSK_34,
180 STV0900_32APSK_45,
181 STV0900_32APSK_56,
182 STV0900_32APSK_89,
183 STV0900_32APSK_910,
184 STV0900_MODCODE_UNKNOWN
185};
186
187enum fe_stv0900_fec {
188 STV0900_FEC_1_2 = 0,
189 STV0900_FEC_2_3,
190 STV0900_FEC_3_4,
191 STV0900_FEC_4_5,
192 STV0900_FEC_5_6,
193 STV0900_FEC_6_7,
194 STV0900_FEC_7_8,
195 STV0900_FEC_8_9,
196 STV0900_FEC_UNKNOWN
197};
198
199enum fe_stv0900_frame_length {
200 STV0900_LONG_FRAME,
201 STV0900_SHORT_FRAME
202};
203
204enum fe_stv0900_pilot {
205 STV0900_PILOTS_OFF,
206 STV0900_PILOTS_ON
207};
208
209enum fe_stv0900_rolloff {
210 STV0900_35,
211 STV0900_25,
212 STV0900_20
213};
214
215enum fe_stv0900_search_iq {
216 STV0900_IQ_AUTO,
217 STV0900_IQ_AUTO_NORMAL_FIRST,
218 STV0900_IQ_FORCE_NORMAL,
219 STV0900_IQ_FORCE_SWAPPED
220};
221
222enum stv0900_iq_inversion {
223 STV0900_IQ_NORMAL,
224 STV0900_IQ_SWAPPED
225};
226
227enum 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
233};
234
235enum fe_stv0900_demod_mode {
236 STV0900_SINGLE = 0,
237 STV0900_DUAL
238};
239
240struct stv0900_init_params{
241 u32 dmd_ref_clk;
242
243
244 enum fe_stv0900_demod_mode demod_mode;
245 enum fe_stv0900_rolloff rolloff;
246 enum fe_stv0900_clock_type path1_ts_clock;
247
248 u8 tun1_maddress;
249 int tuner1_adc;
250 int tuner1_type;
251
252
253 enum stv0900_iq_inversion tun1_iq_inv;
254 enum fe_stv0900_clock_type path2_ts_clock;
255
256 u8 tun2_maddress;
257 int tuner2_adc;
258 int tuner2_type;
259
260
261 enum stv0900_iq_inversion tun2_iq_inv;
262 struct stv0900_reg *ts_config;
263};
264
265struct stv0900_search_params {
266 enum fe_stv0900_demod_num path;
267
268 u32 frequency;
269 u32 symbol_rate;
270 u32 search_range;
271
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;
278
279};
280
281struct stv0900_signal_info {
282 int locked;
283 u32 frequency;
284 u32 symbol_rate;
285
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;
294
295 s32 Power;
296 s32 C_N;
297 u32 BER;
298
299};
300
301struct stv0900_internal{
302 s32 quartz;
303 s32 mclk;
304
305 enum fe_stv0900_rolloff rolloff;
306
307 enum fe_stv0900_demod_mode demod_mode;
308
309
310 s32 freq[2];
311 s32 bw[2];
312 s32 symbol_rate[2];
313 s32 srch_range[2];
314
315 int tuner_type[2];
316
317
318 enum fe_stv0900_search_algo srch_algo[2];
319
320 enum fe_stv0900_search_standard srch_standard[2];
321
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];
326
327 struct stv0900_signal_info result[2];
328 enum fe_stv0900_error err[2];
329
330
331 struct i2c_adapter *i2c_adap;
332 u8 i2c_addr;
333 u8 clkmode;
334 u8 chip_id;
335 struct stv0900_reg *ts_config;
336 enum fe_stv0900_error errs;
337 int dmds_used;
338};
339
340
341struct stv0900_state {
342
343 struct stv0900_internal *internal;
344 struct i2c_adapter *i2c_adap;
345 const struct stv0900_config *config;
346 struct dvb_frontend frontend;
347 int demod;
348};
349
350extern int stvdebug;
351
352extern s32 ge2comp(s32 a, s32 width);
353
354extern void stv0900_write_reg(struct stv0900_internal *i_params,
355 u16 reg_addr, u8 reg_data);
356
357extern u8 stv0900_read_reg(struct stv0900_internal *i_params,
358 u16 reg_addr);
359
360extern void stv0900_write_bits(struct stv0900_internal *i_params,
361 u32 label, u8 val);
362
363extern u8 stv0900_get_bits(struct stv0900_internal *i_params,
364 u32 label);
365
366extern int stv0900_get_demod_lock(struct stv0900_internal *i_params,
367 enum fe_stv0900_demod_num demod, s32 time_out);
368extern int stv0900_check_signal_presence(struct stv0900_internal *i_params,
369 enum fe_stv0900_demod_num demod);
370
371extern enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe);
372
373extern void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency,
374 u32 bandwidth);
375extern void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth);
376
377extern void stv0900_start_search(struct stv0900_internal *i_params,
378 enum fe_stv0900_demod_num demod);
379
380extern u8 stv0900_get_optim_carr_loop(s32 srate,
381 enum fe_stv0900_modcode modcode,
382 s32 pilot, u8 chip_id);
383
384extern u8 stv0900_get_optim_short_carr_loop(s32 srate,
385 enum fe_stv0900_modulation modulation,
386 u8 chip_id);
387
388extern void stv0900_stop_all_s2_modcod(struct stv0900_internal *i_params,
389 enum fe_stv0900_demod_num demod);
390
391extern void stv0900_activate_s2_modcod(struct stv0900_internal *i_params,
392 enum fe_stv0900_demod_num demod);
393
394extern void stv0900_activate_s2_modcod_single(struct stv0900_internal *i_params,
395 enum fe_stv0900_demod_num demod);
396
397extern enum
398fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe,
399 enum fe_stv0900_demod_num demod);
400
401extern u32
402stv0900_get_freq_auto(struct stv0900_internal *intp, int demod);
403
404extern void
405stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency,
406 u32 Bandwidth, int demod);
407
408#endif
409