Commit | Line | Data |
---|---|---|
db7a4843 IL |
1 | /* |
2 | * stv0900_priv.h | |
3 | * | |
4 | * Driver for ST STV0900 satellite demodulator IC. | |
5 | * | |
6 | * Copyright (C) ST Microelectronics. | |
7 | * Copyright (C) 2009 NetUP Inc. | |
8 | * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru> | |
9 | * | |
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. | |
14 | * | |
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 | |
18 | * | |
19 | * GNU General Public License for more details. | |
20 | * | |
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. | |
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 dmd_reg(a, b, c) \ | |
50 | do { \ | |
51 | a = 0; \ | |
52 | switch (demod) { \ | |
53 | case STV0900_DEMOD_1: \ | |
54 | default: \ | |
55 | a = b; \ | |
56 | break; \ | |
57 | case STV0900_DEMOD_2: \ | |
58 | a = c; \ | |
59 | break; \ | |
60 | } \ | |
61 | } while (0) | |
62 | ||
5a771cb1 | 63 | static int stvdebug; |
db7a4843 IL |
64 | |
65 | #define dprintk(args...) \ | |
66 | do { \ | |
5a771cb1 | 67 | if (stvdebug) \ |
db7a4843 IL |
68 | printk(KERN_DEBUG args); \ |
69 | } while (0) | |
70 | ||
71 | #define STV0900_MAXLOOKUPSIZE 500 | |
72 | #define STV0900_BLIND_SEARCH_AGC2_TH 700 | |
73 | ||
74 | /* One point of the lookup table */ | |
75 | struct stv000_lookpoint { | |
76 | s32 realval;/* real value */ | |
77 | s32 regval;/* binary value */ | |
78 | }; | |
79 | ||
80 | /* Lookup table definition */ | |
81 | struct stv0900_table{ | |
82 | s32 size;/* Size of the lookup table */ | |
83 | struct stv000_lookpoint table[STV0900_MAXLOOKUPSIZE];/* Lookup table */ | |
84 | }; | |
85 | ||
86 | enum fe_stv0900_error { | |
87 | STV0900_NO_ERROR = 0, | |
88 | STV0900_INVALID_HANDLE, | |
89 | STV0900_BAD_PARAMETER, | |
90 | STV0900_I2C_ERROR, | |
91 | STV0900_SEARCH_FAILED, | |
92 | }; | |
93 | ||
94 | enum fe_stv0900_clock_type { | |
95 | STV0900_USE_REGISTERS_DEFAULT, | |
96 | STV0900_SERIAL_PUNCT_CLOCK,/*Serial punctured clock */ | |
97 | STV0900_SERIAL_CONT_CLOCK,/*Serial continues clock */ | |
98 | STV0900_PARALLEL_PUNCT_CLOCK,/*Parallel punctured clock */ | |
99 | STV0900_DVBCI_CLOCK/*Parallel continues clock : DVBCI */ | |
100 | }; | |
101 | ||
102 | enum fe_stv0900_search_state { | |
103 | STV0900_SEARCH = 0, | |
104 | STV0900_PLH_DETECTED, | |
105 | STV0900_DVBS2_FOUND, | |
106 | STV0900_DVBS_FOUND | |
107 | ||
108 | }; | |
109 | ||
110 | enum fe_stv0900_ldpc_state { | |
111 | STV0900_PATH1_OFF_PATH2_OFF = 0, | |
112 | STV0900_PATH1_ON_PATH2_OFF = 1, | |
113 | STV0900_PATH1_OFF_PATH2_ON = 2, | |
114 | STV0900_PATH1_ON_PATH2_ON = 3 | |
115 | }; | |
116 | ||
117 | enum fe_stv0900_signal_type { | |
118 | STV0900_NOAGC1 = 0, | |
119 | STV0900_AGC1OK, | |
120 | STV0900_NOTIMING, | |
121 | STV0900_ANALOGCARRIER, | |
122 | STV0900_TIMINGOK, | |
123 | STV0900_NOAGC2, | |
124 | STV0900_AGC2OK, | |
125 | STV0900_NOCARRIER, | |
126 | STV0900_CARRIEROK, | |
127 | STV0900_NODATA, | |
128 | STV0900_DATAOK, | |
129 | STV0900_OUTOFRANGE, | |
130 | STV0900_RANGEOK | |
131 | }; | |
132 | ||
133 | enum fe_stv0900_demod_num { | |
134 | STV0900_DEMOD_1, | |
135 | STV0900_DEMOD_2 | |
136 | }; | |
137 | ||
138 | enum fe_stv0900_tracking_standard { | |
139 | STV0900_DVBS1_STANDARD,/* Found Standard*/ | |
140 | STV0900_DVBS2_STANDARD, | |
141 | STV0900_DSS_STANDARD, | |
142 | STV0900_TURBOCODE_STANDARD, | |
143 | STV0900_UNKNOWN_STANDARD | |
144 | }; | |
145 | ||
146 | enum fe_stv0900_search_standard { | |
147 | STV0900_AUTO_SEARCH, | |
148 | STV0900_SEARCH_DVBS1,/* Search Standard*/ | |
149 | STV0900_SEARCH_DVBS2, | |
150 | STV0900_SEARCH_DSS, | |
151 | STV0900_SEARCH_TURBOCODE | |
152 | }; | |
153 | ||
154 | enum fe_stv0900_search_algo { | |
155 | STV0900_BLIND_SEARCH,/* offset freq and SR are Unknown */ | |
156 | STV0900_COLD_START,/* only the SR is known */ | |
157 | STV0900_WARM_START/* offset freq and SR are known */ | |
158 | }; | |
159 | ||
160 | enum fe_stv0900_modulation { | |
161 | STV0900_QPSK, | |
162 | STV0900_8PSK, | |
163 | STV0900_16APSK, | |
164 | STV0900_32APSK, | |
165 | STV0900_UNKNOWN | |
166 | }; | |
167 | ||
168 | enum fe_stv0900_modcode { | |
169 | STV0900_DUMMY_PLF, | |
170 | STV0900_QPSK_14, | |
171 | STV0900_QPSK_13, | |
172 | STV0900_QPSK_25, | |
173 | STV0900_QPSK_12, | |
174 | STV0900_QPSK_35, | |
175 | STV0900_QPSK_23, | |
176 | STV0900_QPSK_34, | |
177 | STV0900_QPSK_45, | |
178 | STV0900_QPSK_56, | |
179 | STV0900_QPSK_89, | |
180 | STV0900_QPSK_910, | |
181 | STV0900_8PSK_35, | |
182 | STV0900_8PSK_23, | |
183 | STV0900_8PSK_34, | |
184 | STV0900_8PSK_56, | |
185 | STV0900_8PSK_89, | |
186 | STV0900_8PSK_910, | |
187 | STV0900_16APSK_23, | |
188 | STV0900_16APSK_34, | |
189 | STV0900_16APSK_45, | |
190 | STV0900_16APSK_56, | |
191 | STV0900_16APSK_89, | |
192 | STV0900_16APSK_910, | |
193 | STV0900_32APSK_34, | |
194 | STV0900_32APSK_45, | |
195 | STV0900_32APSK_56, | |
196 | STV0900_32APSK_89, | |
197 | STV0900_32APSK_910, | |
198 | STV0900_MODCODE_UNKNOWN | |
199 | }; | |
200 | ||
201 | enum fe_stv0900_fec {/*DVBS1, DSS and turbo code puncture rate*/ | |
202 | STV0900_FEC_1_2 = 0, | |
203 | STV0900_FEC_2_3, | |
204 | STV0900_FEC_3_4, | |
205 | STV0900_FEC_4_5,/*for turbo code only*/ | |
206 | STV0900_FEC_5_6, | |
207 | STV0900_FEC_6_7,/*for DSS only */ | |
208 | STV0900_FEC_7_8, | |
209 | STV0900_FEC_8_9,/*for turbo code only*/ | |
210 | STV0900_FEC_UNKNOWN | |
211 | }; | |
212 | ||
213 | enum fe_stv0900_frame_length { | |
214 | STV0900_LONG_FRAME, | |
215 | STV0900_SHORT_FRAME | |
216 | }; | |
217 | ||
218 | enum fe_stv0900_pilot { | |
219 | STV0900_PILOTS_OFF, | |
220 | STV0900_PILOTS_ON | |
221 | }; | |
222 | ||
223 | enum fe_stv0900_rolloff { | |
224 | STV0900_35, | |
225 | STV0900_25, | |
226 | STV0900_20 | |
227 | }; | |
228 | ||
229 | enum fe_stv0900_search_iq { | |
230 | STV0900_IQ_AUTO, | |
231 | STV0900_IQ_AUTO_NORMAL_FIRST, | |
232 | STV0900_IQ_FORCE_NORMAL, | |
233 | STV0900_IQ_FORCE_SWAPPED | |
234 | }; | |
235 | ||
236 | enum stv0900_iq_inversion { | |
237 | STV0900_IQ_NORMAL, | |
238 | STV0900_IQ_SWAPPED | |
239 | }; | |
240 | ||
241 | enum fe_stv0900_diseqc_mode { | |
242 | STV0900_22KHZ_Continues = 0, | |
243 | STV0900_DISEQC_2_3_PWM = 2, | |
244 | STV0900_DISEQC_3_3_PWM = 3, | |
245 | STV0900_DISEQC_2_3_ENVELOP = 4, | |
246 | STV0900_DISEQC_3_3_ENVELOP = 5 | |
247 | }; | |
248 | ||
249 | enum fe_stv0900_demod_mode { | |
250 | STV0900_SINGLE = 0, | |
251 | STV0900_DUAL | |
252 | }; | |
253 | ||
254 | struct stv0900_init_params{ | |
255 | u32 dmd_ref_clk;/* Refrence,Input clock for the demod in Hz */ | |
256 | ||
257 | /* Demodulator Type (single demod or dual demod) */ | |
258 | enum fe_stv0900_demod_mode demod_mode; | |
259 | enum fe_stv0900_rolloff rolloff; | |
260 | enum fe_stv0900_clock_type path1_ts_clock; | |
261 | ||
262 | u8 tun1_maddress; | |
263 | int tuner1_adc; | |
264 | ||
265 | /* IQ from the tuner1 to the demod */ | |
266 | enum stv0900_iq_inversion tun1_iq_inversion; | |
267 | enum fe_stv0900_clock_type path2_ts_clock; | |
268 | ||
269 | u8 tun2_maddress; | |
270 | int tuner2_adc; | |
271 | ||
272 | /* IQ from the tuner2 to the demod */ | |
273 | enum stv0900_iq_inversion tun2_iq_inversion; | |
f867c3f4 | 274 | struct stv0900_reg *ts_config; |
db7a4843 IL |
275 | }; |
276 | ||
277 | struct stv0900_search_params { | |
278 | enum fe_stv0900_demod_num path;/* Path Used demod1 or 2 */ | |
279 | ||
280 | u32 frequency;/* Transponder frequency (in KHz) */ | |
281 | u32 symbol_rate;/* Transponder symbol rate (in bds)*/ | |
282 | u32 search_range;/* Range of the search (in Hz) */ | |
283 | ||
284 | enum fe_stv0900_search_standard standard; | |
285 | enum fe_stv0900_modulation modulation; | |
286 | enum fe_stv0900_fec fec; | |
287 | enum fe_stv0900_modcode modcode; | |
288 | enum fe_stv0900_search_iq iq_inversion; | |
289 | enum fe_stv0900_search_algo search_algo; | |
290 | ||
291 | }; | |
292 | ||
293 | struct stv0900_signal_info { | |
294 | int locked;/* Transponder locked */ | |
295 | u32 frequency;/* Transponder frequency (in KHz) */ | |
296 | u32 symbol_rate;/* Transponder symbol rate (in Mbds) */ | |
297 | ||
298 | enum fe_stv0900_tracking_standard standard; | |
299 | enum fe_stv0900_fec fec; | |
300 | enum fe_stv0900_modcode modcode; | |
301 | enum fe_stv0900_modulation modulation; | |
302 | enum fe_stv0900_pilot pilot; | |
303 | enum fe_stv0900_frame_length frame_length; | |
304 | enum stv0900_iq_inversion spectrum; | |
305 | enum fe_stv0900_rolloff rolloff; | |
306 | ||
307 | s32 Power;/* Power of the RF signal (dBm) */ | |
308 | s32 C_N;/* Carrier to noise ratio (dB x10)*/ | |
309 | u32 BER;/* Bit error rate (x10^7) */ | |
310 | ||
311 | }; | |
312 | ||
313 | struct stv0900_internal{ | |
314 | s32 quartz; | |
315 | s32 mclk; | |
316 | /* manual RollOff for DVBS1/DSS only */ | |
317 | enum fe_stv0900_rolloff rolloff; | |
318 | /* Demodulator use for single demod or for dual demod) */ | |
319 | enum fe_stv0900_demod_mode demod_mode; | |
320 | ||
321 | /*Demod 1*/ | |
322 | s32 tuner1_freq; | |
323 | s32 tuner1_bw; | |
324 | s32 dmd1_symbol_rate; | |
325 | s32 dmd1_srch_range; | |
326 | ||
327 | /* algorithm for search Blind, Cold or Warm*/ | |
328 | enum fe_stv0900_search_algo dmd1_srch_algo; | |
329 | /* search standard: Auto, DVBS1/DSS only or DVBS2 only*/ | |
330 | enum fe_stv0900_search_standard dmd1_srch_standard; | |
331 | /* inversion search : auto, auto norma first, normal or inverted */ | |
332 | enum fe_stv0900_search_iq dmd1_srch_iq_inv; | |
333 | enum fe_stv0900_modcode dmd1_modcode; | |
334 | enum fe_stv0900_modulation dmd1_modulation; | |
335 | enum fe_stv0900_fec dmd1_fec; | |
336 | ||
337 | struct stv0900_signal_info dmd1_rslts; | |
338 | enum fe_stv0900_signal_type dmd1_state; | |
339 | ||
340 | enum fe_stv0900_error dmd1_err; | |
341 | ||
342 | /*Demod 2*/ | |
343 | s32 tuner2_freq; | |
344 | s32 tuner2_bw; | |
345 | s32 dmd2_symbol_rate; | |
346 | s32 dmd2_srch_range; | |
347 | ||
348 | enum fe_stv0900_search_algo dmd2_srch_algo; | |
349 | enum fe_stv0900_search_standard dmd2_srch_stndrd; | |
350 | /* inversion search : auto, auto normal first, normal or inverted */ | |
351 | enum fe_stv0900_search_iq dmd2_srch_iq_inv; | |
352 | enum fe_stv0900_modcode dmd2_modcode; | |
353 | enum fe_stv0900_modulation dmd2_modulation; | |
354 | enum fe_stv0900_fec dmd2_fec; | |
355 | ||
356 | /* results of the search*/ | |
357 | struct stv0900_signal_info dmd2_rslts; | |
358 | /* current state of the search algorithm */ | |
359 | enum fe_stv0900_signal_type dmd2_state; | |
360 | ||
361 | enum fe_stv0900_error dmd2_err; | |
362 | ||
363 | struct i2c_adapter *i2c_adap; | |
364 | u8 i2c_addr; | |
365 | u8 clkmode;/* 0 for CLKI, 2 for XTALI */ | |
366 | u8 chip_id; | |
f867c3f4 | 367 | struct stv0900_reg *ts_config; |
db7a4843 IL |
368 | enum fe_stv0900_error errs; |
369 | int dmds_used; | |
370 | }; | |
371 | ||
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; | |
379 | int demod; | |
380 | }; | |
381 | ||
382 | extern s32 ge2comp(s32 a, s32 width); | |
383 | ||
384 | extern void stv0900_write_reg(struct stv0900_internal *i_params, | |
385 | u16 reg_addr, u8 reg_data); | |
386 | ||
387 | extern u8 stv0900_read_reg(struct stv0900_internal *i_params, | |
388 | u16 reg_addr); | |
389 | ||
390 | extern void stv0900_write_bits(struct stv0900_internal *i_params, | |
391 | u32 label, u8 val); | |
392 | ||
393 | extern u8 stv0900_get_bits(struct stv0900_internal *i_params, | |
394 | u32 label); | |
395 | ||
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); | |
400 | ||
401 | extern enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe); | |
402 | ||
403 | extern void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency, | |
404 | u32 bandwidth); | |
405 | extern void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth); | |
406 | ||
407 | extern void stv0900_start_search(struct stv0900_internal *i_params, | |
408 | enum fe_stv0900_demod_num demod); | |
409 | ||
410 | extern u8 stv0900_get_optim_carr_loop(s32 srate, | |
411 | enum fe_stv0900_modcode modcode, | |
412 | s32 pilot, u8 chip_id); | |
413 | ||
414 | extern u8 stv0900_get_optim_short_carr_loop(s32 srate, | |
415 | enum fe_stv0900_modulation modulation, | |
416 | u8 chip_id); | |
417 | ||
418 | extern void stv0900_stop_all_s2_modcod(struct stv0900_internal *i_params, | |
419 | enum fe_stv0900_demod_num demod); | |
420 | ||
421 | extern void stv0900_activate_s2_modcode(struct stv0900_internal *i_params, | |
422 | enum fe_stv0900_demod_num demod); | |
423 | ||
424 | extern void stv0900_activate_s2_modcode_single(struct stv0900_internal *i_params, | |
425 | enum fe_stv0900_demod_num demod); | |
426 | ||
427 | extern enum fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe, | |
428 | enum fe_stv0900_demod_num demod); | |
429 | ||
430 | #endif |