1 // SPDX-License-Identifier: GPL-2.0-or-later
3 STV0900/0903 Multistandard Broadcast Frontend driver
4 Copyright (C) Manu Abraham <abraham.manu@gmail.com>
6 Copyright (C) ST Microelectronics
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/string.h>
14 #include <linux/slab.h>
15 #include <linux/mutex.h>
17 #include <linux/dvb/frontend.h>
18 #include <media/dvb_frontend.h>
20 #include "stv6110x.h" /* for demodulator internal modes */
22 #include "stv090x_reg.h"
24 #include "stv090x_priv.h"
26 /* Max transfer size done by I2C transfer functions */
27 #define MAX_XFER_SIZE 64
29 static unsigned int verbose
;
30 module_param(verbose
, int, 0644);
32 /* internal params node */
34 /* pointer for internal params, one for each pair of demods */
35 struct stv090x_internal
*internal
;
36 struct stv090x_dev
*next_dev
;
39 /* first internal params */
40 static struct stv090x_dev
*stv090x_first_dev
;
42 /* find chip by i2c adapter and i2c address */
43 static struct stv090x_dev
*find_dev(struct i2c_adapter
*i2c_adap
,
46 struct stv090x_dev
*temp_dev
= stv090x_first_dev
;
49 Search of the last stv0900 chip or
50 find it by i2c adapter and i2c address */
51 while ((temp_dev
!= NULL
) &&
52 ((temp_dev
->internal
->i2c_adap
!= i2c_adap
) ||
53 (temp_dev
->internal
->i2c_addr
!= i2c_addr
))) {
55 temp_dev
= temp_dev
->next_dev
;
61 /* deallocating chip */
62 static void remove_dev(struct stv090x_internal
*internal
)
64 struct stv090x_dev
*prev_dev
= stv090x_first_dev
;
65 struct stv090x_dev
*del_dev
= find_dev(internal
->i2c_adap
,
68 if (del_dev
!= NULL
) {
69 if (del_dev
== stv090x_first_dev
) {
70 stv090x_first_dev
= del_dev
->next_dev
;
72 while (prev_dev
->next_dev
!= del_dev
)
73 prev_dev
= prev_dev
->next_dev
;
75 prev_dev
->next_dev
= del_dev
->next_dev
;
82 /* allocating new chip */
83 static struct stv090x_dev
*append_internal(struct stv090x_internal
*internal
)
85 struct stv090x_dev
*new_dev
;
86 struct stv090x_dev
*temp_dev
;
88 new_dev
= kmalloc(sizeof(struct stv090x_dev
), GFP_KERNEL
);
89 if (new_dev
!= NULL
) {
90 new_dev
->internal
= internal
;
91 new_dev
->next_dev
= NULL
;
94 if (stv090x_first_dev
== NULL
) {
95 stv090x_first_dev
= new_dev
;
97 temp_dev
= stv090x_first_dev
;
98 while (temp_dev
->next_dev
!= NULL
)
99 temp_dev
= temp_dev
->next_dev
;
101 temp_dev
->next_dev
= new_dev
;
109 /* DVBS1 and DSS C/N Lookup table */
110 static const struct stv090x_tab stv090x_s1cn_tab
[] = {
111 { 0, 8917 }, /* 0.0dB */
112 { 5, 8801 }, /* 0.5dB */
113 { 10, 8667 }, /* 1.0dB */
114 { 15, 8522 }, /* 1.5dB */
115 { 20, 8355 }, /* 2.0dB */
116 { 25, 8175 }, /* 2.5dB */
117 { 30, 7979 }, /* 3.0dB */
118 { 35, 7763 }, /* 3.5dB */
119 { 40, 7530 }, /* 4.0dB */
120 { 45, 7282 }, /* 4.5dB */
121 { 50, 7026 }, /* 5.0dB */
122 { 55, 6781 }, /* 5.5dB */
123 { 60, 6514 }, /* 6.0dB */
124 { 65, 6241 }, /* 6.5dB */
125 { 70, 5965 }, /* 7.0dB */
126 { 75, 5690 }, /* 7.5dB */
127 { 80, 5424 }, /* 8.0dB */
128 { 85, 5161 }, /* 8.5dB */
129 { 90, 4902 }, /* 9.0dB */
130 { 95, 4654 }, /* 9.5dB */
131 { 100, 4417 }, /* 10.0dB */
132 { 105, 4186 }, /* 10.5dB */
133 { 110, 3968 }, /* 11.0dB */
134 { 115, 3757 }, /* 11.5dB */
135 { 120, 3558 }, /* 12.0dB */
136 { 125, 3366 }, /* 12.5dB */
137 { 130, 3185 }, /* 13.0dB */
138 { 135, 3012 }, /* 13.5dB */
139 { 140, 2850 }, /* 14.0dB */
140 { 145, 2698 }, /* 14.5dB */
141 { 150, 2550 }, /* 15.0dB */
142 { 160, 2283 }, /* 16.0dB */
143 { 170, 2042 }, /* 17.0dB */
144 { 180, 1827 }, /* 18.0dB */
145 { 190, 1636 }, /* 19.0dB */
146 { 200, 1466 }, /* 20.0dB */
147 { 210, 1315 }, /* 21.0dB */
148 { 220, 1181 }, /* 22.0dB */
149 { 230, 1064 }, /* 23.0dB */
150 { 240, 960 }, /* 24.0dB */
151 { 250, 869 }, /* 25.0dB */
152 { 260, 792 }, /* 26.0dB */
153 { 270, 724 }, /* 27.0dB */
154 { 280, 665 }, /* 28.0dB */
155 { 290, 616 }, /* 29.0dB */
156 { 300, 573 }, /* 30.0dB */
157 { 310, 537 }, /* 31.0dB */
158 { 320, 507 }, /* 32.0dB */
159 { 330, 483 }, /* 33.0dB */
160 { 400, 398 }, /* 40.0dB */
161 { 450, 381 }, /* 45.0dB */
162 { 500, 377 } /* 50.0dB */
165 /* DVBS2 C/N Lookup table */
166 static const struct stv090x_tab stv090x_s2cn_tab
[] = {
167 { -30, 13348 }, /* -3.0dB */
168 { -20, 12640 }, /* -2d.0B */
169 { -10, 11883 }, /* -1.0dB */
170 { 0, 11101 }, /* -0.0dB */
171 { 5, 10718 }, /* 0.5dB */
172 { 10, 10339 }, /* 1.0dB */
173 { 15, 9947 }, /* 1.5dB */
174 { 20, 9552 }, /* 2.0dB */
175 { 25, 9183 }, /* 2.5dB */
176 { 30, 8799 }, /* 3.0dB */
177 { 35, 8422 }, /* 3.5dB */
178 { 40, 8062 }, /* 4.0dB */
179 { 45, 7707 }, /* 4.5dB */
180 { 50, 7353 }, /* 5.0dB */
181 { 55, 7025 }, /* 5.5dB */
182 { 60, 6684 }, /* 6.0dB */
183 { 65, 6331 }, /* 6.5dB */
184 { 70, 6036 }, /* 7.0dB */
185 { 75, 5727 }, /* 7.5dB */
186 { 80, 5437 }, /* 8.0dB */
187 { 85, 5164 }, /* 8.5dB */
188 { 90, 4902 }, /* 9.0dB */
189 { 95, 4653 }, /* 9.5dB */
190 { 100, 4408 }, /* 10.0dB */
191 { 105, 4187 }, /* 10.5dB */
192 { 110, 3961 }, /* 11.0dB */
193 { 115, 3751 }, /* 11.5dB */
194 { 120, 3558 }, /* 12.0dB */
195 { 125, 3368 }, /* 12.5dB */
196 { 130, 3191 }, /* 13.0dB */
197 { 135, 3017 }, /* 13.5dB */
198 { 140, 2862 }, /* 14.0dB */
199 { 145, 2710 }, /* 14.5dB */
200 { 150, 2565 }, /* 15.0dB */
201 { 160, 2300 }, /* 16.0dB */
202 { 170, 2058 }, /* 17.0dB */
203 { 180, 1849 }, /* 18.0dB */
204 { 190, 1663 }, /* 19.0dB */
205 { 200, 1495 }, /* 20.0dB */
206 { 210, 1349 }, /* 21.0dB */
207 { 220, 1222 }, /* 22.0dB */
208 { 230, 1110 }, /* 23.0dB */
209 { 240, 1011 }, /* 24.0dB */
210 { 250, 925 }, /* 25.0dB */
211 { 260, 853 }, /* 26.0dB */
212 { 270, 789 }, /* 27.0dB */
213 { 280, 734 }, /* 28.0dB */
214 { 290, 690 }, /* 29.0dB */
215 { 300, 650 }, /* 30.0dB */
216 { 310, 619 }, /* 31.0dB */
217 { 320, 593 }, /* 32.0dB */
218 { 330, 571 }, /* 33.0dB */
219 { 400, 498 }, /* 40.0dB */
220 { 450, 484 }, /* 45.0dB */
221 { 500, 481 } /* 50.0dB */
224 /* RF level C/N lookup table */
225 static const struct stv090x_tab stv090x_rf_tab
[] = {
226 { -5, 0xcaa1 }, /* -5dBm */
227 { -10, 0xc229 }, /* -10dBm */
228 { -15, 0xbb08 }, /* -15dBm */
229 { -20, 0xb4bc }, /* -20dBm */
230 { -25, 0xad5a }, /* -25dBm */
231 { -30, 0xa298 }, /* -30dBm */
232 { -35, 0x98a8 }, /* -35dBm */
233 { -40, 0x8389 }, /* -40dBm */
234 { -45, 0x59be }, /* -45dBm */
235 { -50, 0x3a14 }, /* -50dBm */
236 { -55, 0x2d11 }, /* -55dBm */
237 { -60, 0x210d }, /* -60dBm */
238 { -65, 0xa14f }, /* -65dBm */
239 { -70, 0x07aa } /* -70dBm */
243 static struct stv090x_reg stv0900_initval
[] = {
245 { STV090x_OUTCFG
, 0x00 },
246 { STV090x_MODECFG
, 0xff },
247 { STV090x_AGCRF1CFG
, 0x11 },
248 { STV090x_AGCRF2CFG
, 0x13 },
249 { STV090x_TSGENERAL1X
, 0x14 },
250 { STV090x_TSTTNR2
, 0x21 },
251 { STV090x_TSTTNR4
, 0x21 },
252 { STV090x_P2_DISTXCTL
, 0x22 },
253 { STV090x_P2_F22TX
, 0xc0 },
254 { STV090x_P2_F22RX
, 0xc0 },
255 { STV090x_P2_DISRXCTL
, 0x00 },
256 { STV090x_P2_DMDCFGMD
, 0xF9 },
257 { STV090x_P2_DEMOD
, 0x08 },
258 { STV090x_P2_DMDCFG3
, 0xc4 },
259 { STV090x_P2_CARFREQ
, 0xed },
260 { STV090x_P2_LDT
, 0xd0 },
261 { STV090x_P2_LDT2
, 0xb8 },
262 { STV090x_P2_TMGCFG
, 0xd2 },
263 { STV090x_P2_TMGTHRISE
, 0x20 },
264 { STV090x_P1_TMGCFG
, 0xd2 },
266 { STV090x_P2_TMGTHFALL
, 0x00 },
267 { STV090x_P2_FECSPY
, 0x88 },
268 { STV090x_P2_FSPYDATA
, 0x3a },
269 { STV090x_P2_FBERCPT4
, 0x00 },
270 { STV090x_P2_FSPYBER
, 0x10 },
271 { STV090x_P2_ERRCTRL1
, 0x35 },
272 { STV090x_P2_ERRCTRL2
, 0xc1 },
273 { STV090x_P2_CFRICFG
, 0xf8 },
274 { STV090x_P2_NOSCFG
, 0x1c },
275 { STV090x_P2_DMDTOM
, 0x20 },
276 { STV090x_P2_CORRELMANT
, 0x70 },
277 { STV090x_P2_CORRELABS
, 0x88 },
278 { STV090x_P2_AGC2O
, 0x5b },
279 { STV090x_P2_AGC2REF
, 0x38 },
280 { STV090x_P2_CARCFG
, 0xe4 },
281 { STV090x_P2_ACLC
, 0x1A },
282 { STV090x_P2_BCLC
, 0x09 },
283 { STV090x_P2_CARHDR
, 0x08 },
284 { STV090x_P2_KREFTMG
, 0xc1 },
285 { STV090x_P2_SFRUPRATIO
, 0xf0 },
286 { STV090x_P2_SFRLOWRATIO
, 0x70 },
287 { STV090x_P2_SFRSTEP
, 0x58 },
288 { STV090x_P2_TMGCFG2
, 0x01 },
289 { STV090x_P2_CAR2CFG
, 0x26 },
290 { STV090x_P2_BCLC2S2Q
, 0x86 },
291 { STV090x_P2_BCLC2S28
, 0x86 },
292 { STV090x_P2_SMAPCOEF7
, 0x77 },
293 { STV090x_P2_SMAPCOEF6
, 0x85 },
294 { STV090x_P2_SMAPCOEF5
, 0x77 },
295 { STV090x_P2_TSCFGL
, 0x20 },
296 { STV090x_P2_DMDCFG2
, 0x3b },
297 { STV090x_P2_MODCODLST0
, 0xff },
298 { STV090x_P2_MODCODLST1
, 0xff },
299 { STV090x_P2_MODCODLST2
, 0xff },
300 { STV090x_P2_MODCODLST3
, 0xff },
301 { STV090x_P2_MODCODLST4
, 0xff },
302 { STV090x_P2_MODCODLST5
, 0xff },
303 { STV090x_P2_MODCODLST6
, 0xff },
304 { STV090x_P2_MODCODLST7
, 0xcc },
305 { STV090x_P2_MODCODLST8
, 0xcc },
306 { STV090x_P2_MODCODLST9
, 0xcc },
307 { STV090x_P2_MODCODLSTA
, 0xcc },
308 { STV090x_P2_MODCODLSTB
, 0xcc },
309 { STV090x_P2_MODCODLSTC
, 0xcc },
310 { STV090x_P2_MODCODLSTD
, 0xcc },
311 { STV090x_P2_MODCODLSTE
, 0xcc },
312 { STV090x_P2_MODCODLSTF
, 0xcf },
313 { STV090x_P1_DISTXCTL
, 0x22 },
314 { STV090x_P1_F22TX
, 0xc0 },
315 { STV090x_P1_F22RX
, 0xc0 },
316 { STV090x_P1_DISRXCTL
, 0x00 },
317 { STV090x_P1_DMDCFGMD
, 0xf9 },
318 { STV090x_P1_DEMOD
, 0x08 },
319 { STV090x_P1_DMDCFG3
, 0xc4 },
320 { STV090x_P1_DMDTOM
, 0x20 },
321 { STV090x_P1_CARFREQ
, 0xed },
322 { STV090x_P1_LDT
, 0xd0 },
323 { STV090x_P1_LDT2
, 0xb8 },
324 { STV090x_P1_TMGCFG
, 0xd2 },
325 { STV090x_P1_TMGTHRISE
, 0x20 },
326 { STV090x_P1_TMGTHFALL
, 0x00 },
327 { STV090x_P1_SFRUPRATIO
, 0xf0 },
328 { STV090x_P1_SFRLOWRATIO
, 0x70 },
329 { STV090x_P1_TSCFGL
, 0x20 },
330 { STV090x_P1_FECSPY
, 0x88 },
331 { STV090x_P1_FSPYDATA
, 0x3a },
332 { STV090x_P1_FBERCPT4
, 0x00 },
333 { STV090x_P1_FSPYBER
, 0x10 },
334 { STV090x_P1_ERRCTRL1
, 0x35 },
335 { STV090x_P1_ERRCTRL2
, 0xc1 },
336 { STV090x_P1_CFRICFG
, 0xf8 },
337 { STV090x_P1_NOSCFG
, 0x1c },
338 { STV090x_P1_CORRELMANT
, 0x70 },
339 { STV090x_P1_CORRELABS
, 0x88 },
340 { STV090x_P1_AGC2O
, 0x5b },
341 { STV090x_P1_AGC2REF
, 0x38 },
342 { STV090x_P1_CARCFG
, 0xe4 },
343 { STV090x_P1_ACLC
, 0x1A },
344 { STV090x_P1_BCLC
, 0x09 },
345 { STV090x_P1_CARHDR
, 0x08 },
346 { STV090x_P1_KREFTMG
, 0xc1 },
347 { STV090x_P1_SFRSTEP
, 0x58 },
348 { STV090x_P1_TMGCFG2
, 0x01 },
349 { STV090x_P1_CAR2CFG
, 0x26 },
350 { STV090x_P1_BCLC2S2Q
, 0x86 },
351 { STV090x_P1_BCLC2S28
, 0x86 },
352 { STV090x_P1_SMAPCOEF7
, 0x77 },
353 { STV090x_P1_SMAPCOEF6
, 0x85 },
354 { STV090x_P1_SMAPCOEF5
, 0x77 },
355 { STV090x_P1_DMDCFG2
, 0x3b },
356 { STV090x_P1_MODCODLST0
, 0xff },
357 { STV090x_P1_MODCODLST1
, 0xff },
358 { STV090x_P1_MODCODLST2
, 0xff },
359 { STV090x_P1_MODCODLST3
, 0xff },
360 { STV090x_P1_MODCODLST4
, 0xff },
361 { STV090x_P1_MODCODLST5
, 0xff },
362 { STV090x_P1_MODCODLST6
, 0xff },
363 { STV090x_P1_MODCODLST7
, 0xcc },
364 { STV090x_P1_MODCODLST8
, 0xcc },
365 { STV090x_P1_MODCODLST9
, 0xcc },
366 { STV090x_P1_MODCODLSTA
, 0xcc },
367 { STV090x_P1_MODCODLSTB
, 0xcc },
368 { STV090x_P1_MODCODLSTC
, 0xcc },
369 { STV090x_P1_MODCODLSTD
, 0xcc },
370 { STV090x_P1_MODCODLSTE
, 0xcc },
371 { STV090x_P1_MODCODLSTF
, 0xcf },
372 { STV090x_GENCFG
, 0x1d },
373 { STV090x_NBITER_NF4
, 0x37 },
374 { STV090x_NBITER_NF5
, 0x29 },
375 { STV090x_NBITER_NF6
, 0x37 },
376 { STV090x_NBITER_NF7
, 0x33 },
377 { STV090x_NBITER_NF8
, 0x31 },
378 { STV090x_NBITER_NF9
, 0x2f },
379 { STV090x_NBITER_NF10
, 0x39 },
380 { STV090x_NBITER_NF11
, 0x3a },
381 { STV090x_NBITER_NF12
, 0x29 },
382 { STV090x_NBITER_NF13
, 0x37 },
383 { STV090x_NBITER_NF14
, 0x33 },
384 { STV090x_NBITER_NF15
, 0x2f },
385 { STV090x_NBITER_NF16
, 0x39 },
386 { STV090x_NBITER_NF17
, 0x3a },
387 { STV090x_NBITERNOERR
, 0x04 },
388 { STV090x_GAINLLR_NF4
, 0x0C },
389 { STV090x_GAINLLR_NF5
, 0x0F },
390 { STV090x_GAINLLR_NF6
, 0x11 },
391 { STV090x_GAINLLR_NF7
, 0x14 },
392 { STV090x_GAINLLR_NF8
, 0x17 },
393 { STV090x_GAINLLR_NF9
, 0x19 },
394 { STV090x_GAINLLR_NF10
, 0x20 },
395 { STV090x_GAINLLR_NF11
, 0x21 },
396 { STV090x_GAINLLR_NF12
, 0x0D },
397 { STV090x_GAINLLR_NF13
, 0x0F },
398 { STV090x_GAINLLR_NF14
, 0x13 },
399 { STV090x_GAINLLR_NF15
, 0x1A },
400 { STV090x_GAINLLR_NF16
, 0x1F },
401 { STV090x_GAINLLR_NF17
, 0x21 },
402 { STV090x_RCCFGH
, 0x20 },
403 { STV090x_P1_FECM
, 0x01 }, /* disable DSS modes */
404 { STV090x_P2_FECM
, 0x01 }, /* disable DSS modes */
405 { STV090x_P1_PRVIT
, 0x2F }, /* disable PR 6/7 */
406 { STV090x_P2_PRVIT
, 0x2F }, /* disable PR 6/7 */
409 static struct stv090x_reg stv0903_initval
[] = {
410 { STV090x_OUTCFG
, 0x00 },
411 { STV090x_AGCRF1CFG
, 0x11 },
412 { STV090x_STOPCLK1
, 0x48 },
413 { STV090x_STOPCLK2
, 0x14 },
414 { STV090x_TSTTNR1
, 0x27 },
415 { STV090x_TSTTNR2
, 0x21 },
416 { STV090x_P1_DISTXCTL
, 0x22 },
417 { STV090x_P1_F22TX
, 0xc0 },
418 { STV090x_P1_F22RX
, 0xc0 },
419 { STV090x_P1_DISRXCTL
, 0x00 },
420 { STV090x_P1_DMDCFGMD
, 0xF9 },
421 { STV090x_P1_DEMOD
, 0x08 },
422 { STV090x_P1_DMDCFG3
, 0xc4 },
423 { STV090x_P1_CARFREQ
, 0xed },
424 { STV090x_P1_TNRCFG2
, 0x82 },
425 { STV090x_P1_LDT
, 0xd0 },
426 { STV090x_P1_LDT2
, 0xb8 },
427 { STV090x_P1_TMGCFG
, 0xd2 },
428 { STV090x_P1_TMGTHRISE
, 0x20 },
429 { STV090x_P1_TMGTHFALL
, 0x00 },
430 { STV090x_P1_SFRUPRATIO
, 0xf0 },
431 { STV090x_P1_SFRLOWRATIO
, 0x70 },
432 { STV090x_P1_TSCFGL
, 0x20 },
433 { STV090x_P1_FECSPY
, 0x88 },
434 { STV090x_P1_FSPYDATA
, 0x3a },
435 { STV090x_P1_FBERCPT4
, 0x00 },
436 { STV090x_P1_FSPYBER
, 0x10 },
437 { STV090x_P1_ERRCTRL1
, 0x35 },
438 { STV090x_P1_ERRCTRL2
, 0xc1 },
439 { STV090x_P1_CFRICFG
, 0xf8 },
440 { STV090x_P1_NOSCFG
, 0x1c },
441 { STV090x_P1_DMDTOM
, 0x20 },
442 { STV090x_P1_CORRELMANT
, 0x70 },
443 { STV090x_P1_CORRELABS
, 0x88 },
444 { STV090x_P1_AGC2O
, 0x5b },
445 { STV090x_P1_AGC2REF
, 0x38 },
446 { STV090x_P1_CARCFG
, 0xe4 },
447 { STV090x_P1_ACLC
, 0x1A },
448 { STV090x_P1_BCLC
, 0x09 },
449 { STV090x_P1_CARHDR
, 0x08 },
450 { STV090x_P1_KREFTMG
, 0xc1 },
451 { STV090x_P1_SFRSTEP
, 0x58 },
452 { STV090x_P1_TMGCFG2
, 0x01 },
453 { STV090x_P1_CAR2CFG
, 0x26 },
454 { STV090x_P1_BCLC2S2Q
, 0x86 },
455 { STV090x_P1_BCLC2S28
, 0x86 },
456 { STV090x_P1_SMAPCOEF7
, 0x77 },
457 { STV090x_P1_SMAPCOEF6
, 0x85 },
458 { STV090x_P1_SMAPCOEF5
, 0x77 },
459 { STV090x_P1_DMDCFG2
, 0x3b },
460 { STV090x_P1_MODCODLST0
, 0xff },
461 { STV090x_P1_MODCODLST1
, 0xff },
462 { STV090x_P1_MODCODLST2
, 0xff },
463 { STV090x_P1_MODCODLST3
, 0xff },
464 { STV090x_P1_MODCODLST4
, 0xff },
465 { STV090x_P1_MODCODLST5
, 0xff },
466 { STV090x_P1_MODCODLST6
, 0xff },
467 { STV090x_P1_MODCODLST7
, 0xcc },
468 { STV090x_P1_MODCODLST8
, 0xcc },
469 { STV090x_P1_MODCODLST9
, 0xcc },
470 { STV090x_P1_MODCODLSTA
, 0xcc },
471 { STV090x_P1_MODCODLSTB
, 0xcc },
472 { STV090x_P1_MODCODLSTC
, 0xcc },
473 { STV090x_P1_MODCODLSTD
, 0xcc },
474 { STV090x_P1_MODCODLSTE
, 0xcc },
475 { STV090x_P1_MODCODLSTF
, 0xcf },
476 { STV090x_GENCFG
, 0x1c },
477 { STV090x_NBITER_NF4
, 0x37 },
478 { STV090x_NBITER_NF5
, 0x29 },
479 { STV090x_NBITER_NF6
, 0x37 },
480 { STV090x_NBITER_NF7
, 0x33 },
481 { STV090x_NBITER_NF8
, 0x31 },
482 { STV090x_NBITER_NF9
, 0x2f },
483 { STV090x_NBITER_NF10
, 0x39 },
484 { STV090x_NBITER_NF11
, 0x3a },
485 { STV090x_NBITER_NF12
, 0x29 },
486 { STV090x_NBITER_NF13
, 0x37 },
487 { STV090x_NBITER_NF14
, 0x33 },
488 { STV090x_NBITER_NF15
, 0x2f },
489 { STV090x_NBITER_NF16
, 0x39 },
490 { STV090x_NBITER_NF17
, 0x3a },
491 { STV090x_NBITERNOERR
, 0x04 },
492 { STV090x_GAINLLR_NF4
, 0x0C },
493 { STV090x_GAINLLR_NF5
, 0x0F },
494 { STV090x_GAINLLR_NF6
, 0x11 },
495 { STV090x_GAINLLR_NF7
, 0x14 },
496 { STV090x_GAINLLR_NF8
, 0x17 },
497 { STV090x_GAINLLR_NF9
, 0x19 },
498 { STV090x_GAINLLR_NF10
, 0x20 },
499 { STV090x_GAINLLR_NF11
, 0x21 },
500 { STV090x_GAINLLR_NF12
, 0x0D },
501 { STV090x_GAINLLR_NF13
, 0x0F },
502 { STV090x_GAINLLR_NF14
, 0x13 },
503 { STV090x_GAINLLR_NF15
, 0x1A },
504 { STV090x_GAINLLR_NF16
, 0x1F },
505 { STV090x_GAINLLR_NF17
, 0x21 },
506 { STV090x_RCCFGH
, 0x20 },
507 { STV090x_P1_FECM
, 0x01 }, /*disable the DSS mode */
508 { STV090x_P1_PRVIT
, 0x2f } /*disable puncture rate 6/7*/
511 static struct stv090x_reg stv0900_cut20_val
[] = {
513 { STV090x_P2_DMDCFG3
, 0xe8 },
514 { STV090x_P2_DMDCFG4
, 0x10 },
515 { STV090x_P2_CARFREQ
, 0x38 },
516 { STV090x_P2_CARHDR
, 0x20 },
517 { STV090x_P2_KREFTMG
, 0x5a },
518 { STV090x_P2_SMAPCOEF7
, 0x06 },
519 { STV090x_P2_SMAPCOEF6
, 0x00 },
520 { STV090x_P2_SMAPCOEF5
, 0x04 },
521 { STV090x_P2_NOSCFG
, 0x0c },
522 { STV090x_P1_DMDCFG3
, 0xe8 },
523 { STV090x_P1_DMDCFG4
, 0x10 },
524 { STV090x_P1_CARFREQ
, 0x38 },
525 { STV090x_P1_CARHDR
, 0x20 },
526 { STV090x_P1_KREFTMG
, 0x5a },
527 { STV090x_P1_SMAPCOEF7
, 0x06 },
528 { STV090x_P1_SMAPCOEF6
, 0x00 },
529 { STV090x_P1_SMAPCOEF5
, 0x04 },
530 { STV090x_P1_NOSCFG
, 0x0c },
531 { STV090x_GAINLLR_NF4
, 0x21 },
532 { STV090x_GAINLLR_NF5
, 0x21 },
533 { STV090x_GAINLLR_NF6
, 0x20 },
534 { STV090x_GAINLLR_NF7
, 0x1F },
535 { STV090x_GAINLLR_NF8
, 0x1E },
536 { STV090x_GAINLLR_NF9
, 0x1E },
537 { STV090x_GAINLLR_NF10
, 0x1D },
538 { STV090x_GAINLLR_NF11
, 0x1B },
539 { STV090x_GAINLLR_NF12
, 0x20 },
540 { STV090x_GAINLLR_NF13
, 0x20 },
541 { STV090x_GAINLLR_NF14
, 0x20 },
542 { STV090x_GAINLLR_NF15
, 0x20 },
543 { STV090x_GAINLLR_NF16
, 0x20 },
544 { STV090x_GAINLLR_NF17
, 0x21 },
547 static struct stv090x_reg stv0903_cut20_val
[] = {
548 { STV090x_P1_DMDCFG3
, 0xe8 },
549 { STV090x_P1_DMDCFG4
, 0x10 },
550 { STV090x_P1_CARFREQ
, 0x38 },
551 { STV090x_P1_CARHDR
, 0x20 },
552 { STV090x_P1_KREFTMG
, 0x5a },
553 { STV090x_P1_SMAPCOEF7
, 0x06 },
554 { STV090x_P1_SMAPCOEF6
, 0x00 },
555 { STV090x_P1_SMAPCOEF5
, 0x04 },
556 { STV090x_P1_NOSCFG
, 0x0c },
557 { STV090x_GAINLLR_NF4
, 0x21 },
558 { STV090x_GAINLLR_NF5
, 0x21 },
559 { STV090x_GAINLLR_NF6
, 0x20 },
560 { STV090x_GAINLLR_NF7
, 0x1F },
561 { STV090x_GAINLLR_NF8
, 0x1E },
562 { STV090x_GAINLLR_NF9
, 0x1E },
563 { STV090x_GAINLLR_NF10
, 0x1D },
564 { STV090x_GAINLLR_NF11
, 0x1B },
565 { STV090x_GAINLLR_NF12
, 0x20 },
566 { STV090x_GAINLLR_NF13
, 0x20 },
567 { STV090x_GAINLLR_NF14
, 0x20 },
568 { STV090x_GAINLLR_NF15
, 0x20 },
569 { STV090x_GAINLLR_NF16
, 0x20 },
570 { STV090x_GAINLLR_NF17
, 0x21 }
573 /* Cut 2.0 Long Frame Tracking CR loop */
574 static struct stv090x_long_frame_crloop stv090x_s2_crl_cut20
[] = {
575 /* MODCOD 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
576 { STV090x_QPSK_12
, 0x1f, 0x3f, 0x1e, 0x3f, 0x3d, 0x1f, 0x3d, 0x3e, 0x3d, 0x1e },
577 { STV090x_QPSK_35
, 0x2f, 0x3f, 0x2e, 0x2f, 0x3d, 0x0f, 0x0e, 0x2e, 0x3d, 0x0e },
578 { STV090x_QPSK_23
, 0x2f, 0x3f, 0x2e, 0x2f, 0x0e, 0x0f, 0x0e, 0x1e, 0x3d, 0x3d },
579 { STV090x_QPSK_34
, 0x3f, 0x3f, 0x3e, 0x1f, 0x0e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
580 { STV090x_QPSK_45
, 0x3f, 0x3f, 0x3e, 0x1f, 0x0e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
581 { STV090x_QPSK_56
, 0x3f, 0x3f, 0x3e, 0x1f, 0x0e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
582 { STV090x_QPSK_89
, 0x3f, 0x3f, 0x3e, 0x1f, 0x1e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
583 { STV090x_QPSK_910
, 0x3f, 0x3f, 0x3e, 0x1f, 0x1e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
584 { STV090x_8PSK_35
, 0x3c, 0x3e, 0x1c, 0x2e, 0x0c, 0x1e, 0x2b, 0x2d, 0x1b, 0x1d },
585 { STV090x_8PSK_23
, 0x1d, 0x3e, 0x3c, 0x2e, 0x2c, 0x1e, 0x0c, 0x2d, 0x2b, 0x1d },
586 { STV090x_8PSK_34
, 0x0e, 0x3e, 0x3d, 0x2e, 0x0d, 0x1e, 0x2c, 0x2d, 0x0c, 0x1d },
587 { STV090x_8PSK_56
, 0x2e, 0x3e, 0x1e, 0x2e, 0x2d, 0x1e, 0x3c, 0x2d, 0x2c, 0x1d },
588 { STV090x_8PSK_89
, 0x3e, 0x3e, 0x1e, 0x2e, 0x3d, 0x1e, 0x0d, 0x2d, 0x3c, 0x1d },
589 { STV090x_8PSK_910
, 0x3e, 0x3e, 0x1e, 0x2e, 0x3d, 0x1e, 0x1d, 0x2d, 0x0d, 0x1d }
592 /* Cut 3.0 Long Frame Tracking CR loop */
593 static struct stv090x_long_frame_crloop stv090x_s2_crl_cut30
[] = {
594 /* MODCOD 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
595 { STV090x_QPSK_12
, 0x3c, 0x2c, 0x0c, 0x2c, 0x1b, 0x2c, 0x1b, 0x1c, 0x0b, 0x3b },
596 { STV090x_QPSK_35
, 0x0d, 0x0d, 0x0c, 0x0d, 0x1b, 0x3c, 0x1b, 0x1c, 0x0b, 0x3b },
597 { STV090x_QPSK_23
, 0x1d, 0x0d, 0x0c, 0x1d, 0x2b, 0x3c, 0x1b, 0x1c, 0x0b, 0x3b },
598 { STV090x_QPSK_34
, 0x1d, 0x1d, 0x0c, 0x1d, 0x2b, 0x3c, 0x1b, 0x1c, 0x0b, 0x3b },
599 { STV090x_QPSK_45
, 0x2d, 0x1d, 0x1c, 0x1d, 0x2b, 0x3c, 0x2b, 0x0c, 0x1b, 0x3b },
600 { STV090x_QPSK_56
, 0x2d, 0x1d, 0x1c, 0x1d, 0x2b, 0x3c, 0x2b, 0x0c, 0x1b, 0x3b },
601 { STV090x_QPSK_89
, 0x3d, 0x2d, 0x1c, 0x1d, 0x3b, 0x3c, 0x2b, 0x0c, 0x1b, 0x3b },
602 { STV090x_QPSK_910
, 0x3d, 0x2d, 0x1c, 0x1d, 0x3b, 0x3c, 0x2b, 0x0c, 0x1b, 0x3b },
603 { STV090x_8PSK_35
, 0x39, 0x29, 0x39, 0x19, 0x19, 0x19, 0x19, 0x19, 0x09, 0x19 },
604 { STV090x_8PSK_23
, 0x2a, 0x39, 0x1a, 0x0a, 0x39, 0x0a, 0x29, 0x39, 0x29, 0x0a },
605 { STV090x_8PSK_34
, 0x2b, 0x3a, 0x1b, 0x1b, 0x3a, 0x1b, 0x1a, 0x0b, 0x1a, 0x3a },
606 { STV090x_8PSK_56
, 0x0c, 0x1b, 0x3b, 0x3b, 0x1b, 0x3b, 0x3a, 0x3b, 0x3a, 0x1b },
607 { STV090x_8PSK_89
, 0x0d, 0x3c, 0x2c, 0x2c, 0x2b, 0x0c, 0x0b, 0x3b, 0x0b, 0x1b },
608 { STV090x_8PSK_910
, 0x0d, 0x0d, 0x2c, 0x3c, 0x3b, 0x1c, 0x0b, 0x3b, 0x0b, 0x1b }
611 /* Cut 2.0 Long Frame Tracking CR Loop */
612 static struct stv090x_long_frame_crloop stv090x_s2_apsk_crl_cut20
[] = {
613 /* MODCOD 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
614 { STV090x_16APSK_23
, 0x0c, 0x0c, 0x0c, 0x0c, 0x1d, 0x0c, 0x3c, 0x0c, 0x2c, 0x0c },
615 { STV090x_16APSK_34
, 0x0c, 0x0c, 0x0c, 0x0c, 0x0e, 0x0c, 0x2d, 0x0c, 0x1d, 0x0c },
616 { STV090x_16APSK_45
, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x0c, 0x3d, 0x0c, 0x2d, 0x0c },
617 { STV090x_16APSK_56
, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x0c, 0x3d, 0x0c, 0x2d, 0x0c },
618 { STV090x_16APSK_89
, 0x0c, 0x0c, 0x0c, 0x0c, 0x2e, 0x0c, 0x0e, 0x0c, 0x3d, 0x0c },
619 { STV090x_16APSK_910
, 0x0c, 0x0c, 0x0c, 0x0c, 0x2e, 0x0c, 0x0e, 0x0c, 0x3d, 0x0c },
620 { STV090x_32APSK_34
, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c },
621 { STV090x_32APSK_45
, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c },
622 { STV090x_32APSK_56
, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c },
623 { STV090x_32APSK_89
, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c },
624 { STV090x_32APSK_910
, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c }
627 /* Cut 3.0 Long Frame Tracking CR Loop */
628 static struct stv090x_long_frame_crloop stv090x_s2_apsk_crl_cut30
[] = {
629 /* MODCOD 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
630 { STV090x_16APSK_23
, 0x0a, 0x0a, 0x0a, 0x0a, 0x1a, 0x0a, 0x3a, 0x0a, 0x2a, 0x0a },
631 { STV090x_16APSK_34
, 0x0a, 0x0a, 0x0a, 0x0a, 0x0b, 0x0a, 0x3b, 0x0a, 0x1b, 0x0a },
632 { STV090x_16APSK_45
, 0x0a, 0x0a, 0x0a, 0x0a, 0x1b, 0x0a, 0x3b, 0x0a, 0x2b, 0x0a },
633 { STV090x_16APSK_56
, 0x0a, 0x0a, 0x0a, 0x0a, 0x1b, 0x0a, 0x3b, 0x0a, 0x2b, 0x0a },
634 { STV090x_16APSK_89
, 0x0a, 0x0a, 0x0a, 0x0a, 0x2b, 0x0a, 0x0c, 0x0a, 0x3b, 0x0a },
635 { STV090x_16APSK_910
, 0x0a, 0x0a, 0x0a, 0x0a, 0x2b, 0x0a, 0x0c, 0x0a, 0x3b, 0x0a },
636 { STV090x_32APSK_34
, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },
637 { STV090x_32APSK_45
, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },
638 { STV090x_32APSK_56
, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },
639 { STV090x_32APSK_89
, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },
640 { STV090x_32APSK_910
, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a }
643 static struct stv090x_long_frame_crloop stv090x_s2_lowqpsk_crl_cut20
[] = {
644 /* MODCOD 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
645 { STV090x_QPSK_14
, 0x0f, 0x3f, 0x0e, 0x3f, 0x2d, 0x2f, 0x2d, 0x1f, 0x3d, 0x3e },
646 { STV090x_QPSK_13
, 0x0f, 0x3f, 0x0e, 0x3f, 0x2d, 0x2f, 0x3d, 0x0f, 0x3d, 0x2e },
647 { STV090x_QPSK_25
, 0x1f, 0x3f, 0x1e, 0x3f, 0x3d, 0x1f, 0x3d, 0x3e, 0x3d, 0x2e }
650 static struct stv090x_long_frame_crloop stv090x_s2_lowqpsk_crl_cut30
[] = {
651 /* MODCOD 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
652 { STV090x_QPSK_14
, 0x0c, 0x3c, 0x0b, 0x3c, 0x2a, 0x2c, 0x2a, 0x1c, 0x3a, 0x3b },
653 { STV090x_QPSK_13
, 0x0c, 0x3c, 0x0b, 0x3c, 0x2a, 0x2c, 0x3a, 0x0c, 0x3a, 0x2b },
654 { STV090x_QPSK_25
, 0x1c, 0x3c, 0x1b, 0x3c, 0x3a, 0x1c, 0x3a, 0x3b, 0x3a, 0x2b }
657 /* Cut 2.0 Short Frame Tracking CR Loop */
658 static struct stv090x_short_frame_crloop stv090x_s2_short_crl_cut20
[] = {
659 /* MODCOD 2M 5M 10M 20M 30M */
660 { STV090x_QPSK
, 0x2f, 0x2e, 0x0e, 0x0e, 0x3d },
661 { STV090x_8PSK
, 0x3e, 0x0e, 0x2d, 0x0d, 0x3c },
662 { STV090x_16APSK
, 0x1e, 0x1e, 0x1e, 0x3d, 0x2d },
663 { STV090x_32APSK
, 0x1e, 0x1e, 0x1e, 0x3d, 0x2d }
666 /* Cut 3.0 Short Frame Tracking CR Loop */
667 static struct stv090x_short_frame_crloop stv090x_s2_short_crl_cut30
[] = {
668 /* MODCOD 2M 5M 10M 20M 30M */
669 { STV090x_QPSK
, 0x2C, 0x2B, 0x0B, 0x0B, 0x3A },
670 { STV090x_8PSK
, 0x3B, 0x0B, 0x2A, 0x0A, 0x39 },
671 { STV090x_16APSK
, 0x1B, 0x1B, 0x1B, 0x3A, 0x2A },
672 { STV090x_32APSK
, 0x1B, 0x1B, 0x1B, 0x3A, 0x2A }
675 static inline s32
comp2(s32 __x
, s32 __width
)
680 return (__x
>= (1 << (__width
- 1))) ? (__x
- (1 << __width
)) : __x
;
683 static int stv090x_read_reg(struct stv090x_state
*state
, unsigned int reg
)
685 const struct stv090x_config
*config
= state
->config
;
688 u8 b0
[] = { reg
>> 8, reg
& 0xff };
691 struct i2c_msg msg
[] = {
692 { .addr
= config
->address
, .flags
= 0, .buf
= b0
, .len
= 2 },
693 { .addr
= config
->address
, .flags
= I2C_M_RD
, .buf
= &buf
, .len
= 1 }
696 ret
= i2c_transfer(state
->i2c
, msg
, 2);
698 if (ret
!= -ERESTARTSYS
)
700 "Read error, Reg=[0x%02x], Status=%d",
703 return ret
< 0 ? ret
: -EREMOTEIO
;
705 if (unlikely(*state
->verbose
>= FE_DEBUGREG
))
706 dprintk(FE_ERROR
, 1, "Reg=[0x%02x], data=%02x",
709 return (unsigned int) buf
;
712 static int stv090x_write_regs(struct stv090x_state
*state
, unsigned int reg
, u8
*data
, u32 count
)
714 const struct stv090x_config
*config
= state
->config
;
716 u8 buf
[MAX_XFER_SIZE
];
717 struct i2c_msg i2c_msg
= { .addr
= config
->address
, .flags
= 0, .buf
= buf
, .len
= 2 + count
};
719 if (2 + count
> sizeof(buf
)) {
721 "%s: i2c wr reg=%04x: len=%d is too big!\n",
722 KBUILD_MODNAME
, reg
, count
);
728 memcpy(&buf
[2], data
, count
);
730 dprintk(FE_DEBUGREG
, 1, "%s [0x%04x]: %*ph",
731 __func__
, reg
, count
, data
);
733 ret
= i2c_transfer(state
->i2c
, &i2c_msg
, 1);
735 if (ret
!= -ERESTARTSYS
)
736 dprintk(FE_ERROR
, 1, "Reg=[0x%04x], Data=[0x%02x ...], Count=%u, Status=%d",
737 reg
, data
[0], count
, ret
);
738 return ret
< 0 ? ret
: -EREMOTEIO
;
744 static int stv090x_write_reg(struct stv090x_state
*state
, unsigned int reg
, u8 data
)
746 u8 tmp
= data
; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
748 return stv090x_write_regs(state
, reg
, &tmp
, 1);
751 static inline void stv090x_tuner_i2c_lock(struct stv090x_state
*state
)
753 if (state
->config
->tuner_i2c_lock
)
754 state
->config
->tuner_i2c_lock(&state
->frontend
, 1);
756 mutex_lock(&state
->internal
->tuner_lock
);
759 static inline void stv090x_tuner_i2c_unlock(struct stv090x_state
*state
)
761 if (state
->config
->tuner_i2c_lock
)
762 state
->config
->tuner_i2c_lock(&state
->frontend
, 0);
764 mutex_unlock(&state
->internal
->tuner_lock
);
767 static int stv090x_i2c_gate_ctrl(struct stv090x_state
*state
, int enable
)
772 * NOTE! A lock is used as a FSM to control the state in which
773 * access is serialized between two tuners on the same demod.
774 * This has nothing to do with a lock to protect a critical section
775 * which may in some other cases be confused with protecting I/O
776 * access to the demodulator gate.
777 * In case of any error, the lock is unlocked and exit within the
778 * relevant operations themselves.
781 stv090x_tuner_i2c_lock(state
);
783 reg
= STV090x_READ_DEMOD(state
, I2CRPT
);
785 dprintk(FE_DEBUG
, 1, "Enable Gate");
786 STV090x_SETFIELD_Px(reg
, I2CT_ON_FIELD
, 1);
787 if (STV090x_WRITE_DEMOD(state
, I2CRPT
, reg
) < 0)
791 dprintk(FE_DEBUG
, 1, "Disable Gate");
792 STV090x_SETFIELD_Px(reg
, I2CT_ON_FIELD
, 0);
793 if ((STV090x_WRITE_DEMOD(state
, I2CRPT
, reg
)) < 0)
798 stv090x_tuner_i2c_unlock(state
);
802 dprintk(FE_ERROR
, 1, "I/O error");
803 stv090x_tuner_i2c_unlock(state
);
807 static void stv090x_get_lock_tmg(struct stv090x_state
*state
)
809 switch (state
->algo
) {
810 case STV090x_BLIND_SEARCH
:
811 dprintk(FE_DEBUG
, 1, "Blind Search");
812 if (state
->srate
<= 1500000) { /*10Msps< SR <=15Msps*/
813 state
->DemodTimeout
= 1500;
814 state
->FecTimeout
= 400;
815 } else if (state
->srate
<= 5000000) { /*10Msps< SR <=15Msps*/
816 state
->DemodTimeout
= 1000;
817 state
->FecTimeout
= 300;
818 } else { /*SR >20Msps*/
819 state
->DemodTimeout
= 700;
820 state
->FecTimeout
= 100;
824 case STV090x_COLD_SEARCH
:
825 case STV090x_WARM_SEARCH
:
827 dprintk(FE_DEBUG
, 1, "Normal Search");
828 if (state
->srate
<= 1000000) { /*SR <=1Msps*/
829 state
->DemodTimeout
= 4500;
830 state
->FecTimeout
= 1700;
831 } else if (state
->srate
<= 2000000) { /*1Msps < SR <= 2Msps */
832 state
->DemodTimeout
= 2500;
833 state
->FecTimeout
= 1100;
834 } else if (state
->srate
<= 5000000) { /*2Msps < SR <= 5Msps */
835 state
->DemodTimeout
= 1000;
836 state
->FecTimeout
= 550;
837 } else if (state
->srate
<= 10000000) { /*5Msps < SR <= 10Msps */
838 state
->DemodTimeout
= 700;
839 state
->FecTimeout
= 250;
840 } else if (state
->srate
<= 20000000) { /*10Msps < SR <= 20Msps */
841 state
->DemodTimeout
= 400;
842 state
->FecTimeout
= 130;
843 } else { /*SR >20Msps*/
844 state
->DemodTimeout
= 300;
845 state
->FecTimeout
= 100;
850 if (state
->algo
== STV090x_WARM_SEARCH
)
851 state
->DemodTimeout
/= 2;
854 static int stv090x_set_srate(struct stv090x_state
*state
, u32 srate
)
858 if (srate
> 60000000) {
859 sym
= (srate
<< 4); /* SR * 2^16 / master_clk */
860 sym
/= (state
->internal
->mclk
>> 12);
861 } else if (srate
> 6000000) {
863 sym
/= (state
->internal
->mclk
>> 10);
866 sym
/= (state
->internal
->mclk
>> 7);
869 if (STV090x_WRITE_DEMOD(state
, SFRINIT1
, (sym
>> 8) & 0x7f) < 0) /* MSB */
871 if (STV090x_WRITE_DEMOD(state
, SFRINIT0
, (sym
& 0xff)) < 0) /* LSB */
876 dprintk(FE_ERROR
, 1, "I/O error");
880 static int stv090x_set_max_srate(struct stv090x_state
*state
, u32 clk
, u32 srate
)
884 srate
= 105 * (srate
/ 100);
885 if (srate
> 60000000) {
886 sym
= (srate
<< 4); /* SR * 2^16 / master_clk */
887 sym
/= (state
->internal
->mclk
>> 12);
888 } else if (srate
> 6000000) {
890 sym
/= (state
->internal
->mclk
>> 10);
893 sym
/= (state
->internal
->mclk
>> 7);
897 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, (sym
>> 8) & 0x7f) < 0) /* MSB */
899 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, sym
& 0xff) < 0) /* LSB */
902 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, 0x7f) < 0) /* MSB */
904 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, 0xff) < 0) /* LSB */
910 dprintk(FE_ERROR
, 1, "I/O error");
914 static int stv090x_set_min_srate(struct stv090x_state
*state
, u32 clk
, u32 srate
)
918 srate
= 95 * (srate
/ 100);
919 if (srate
> 60000000) {
920 sym
= (srate
<< 4); /* SR * 2^16 / master_clk */
921 sym
/= (state
->internal
->mclk
>> 12);
922 } else if (srate
> 6000000) {
924 sym
/= (state
->internal
->mclk
>> 10);
927 sym
/= (state
->internal
->mclk
>> 7);
930 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, ((sym
>> 8) & 0x7f)) < 0) /* MSB */
932 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, (sym
& 0xff)) < 0) /* LSB */
936 dprintk(FE_ERROR
, 1, "I/O error");
940 static u32
stv090x_car_width(u32 srate
, enum stv090x_rolloff rolloff
)
957 return srate
+ (srate
* ro
) / 100;
960 static int stv090x_set_vit_thacq(struct stv090x_state
*state
)
962 if (STV090x_WRITE_DEMOD(state
, VTH12
, 0x96) < 0)
964 if (STV090x_WRITE_DEMOD(state
, VTH23
, 0x64) < 0)
966 if (STV090x_WRITE_DEMOD(state
, VTH34
, 0x36) < 0)
968 if (STV090x_WRITE_DEMOD(state
, VTH56
, 0x23) < 0)
970 if (STV090x_WRITE_DEMOD(state
, VTH67
, 0x1e) < 0)
972 if (STV090x_WRITE_DEMOD(state
, VTH78
, 0x19) < 0)
976 dprintk(FE_ERROR
, 1, "I/O error");
980 static int stv090x_set_vit_thtracq(struct stv090x_state
*state
)
982 if (STV090x_WRITE_DEMOD(state
, VTH12
, 0xd0) < 0)
984 if (STV090x_WRITE_DEMOD(state
, VTH23
, 0x7d) < 0)
986 if (STV090x_WRITE_DEMOD(state
, VTH34
, 0x53) < 0)
988 if (STV090x_WRITE_DEMOD(state
, VTH56
, 0x2f) < 0)
990 if (STV090x_WRITE_DEMOD(state
, VTH67
, 0x24) < 0)
992 if (STV090x_WRITE_DEMOD(state
, VTH78
, 0x1f) < 0)
996 dprintk(FE_ERROR
, 1, "I/O error");
1000 static int stv090x_set_viterbi(struct stv090x_state
*state
)
1002 switch (state
->search_mode
) {
1003 case STV090x_SEARCH_AUTO
:
1004 if (STV090x_WRITE_DEMOD(state
, FECM
, 0x10) < 0) /* DVB-S and DVB-S2 */
1006 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x3f) < 0) /* all puncture rate */
1009 case STV090x_SEARCH_DVBS1
:
1010 if (STV090x_WRITE_DEMOD(state
, FECM
, 0x00) < 0) /* disable DSS */
1012 switch (state
->fec
) {
1014 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x01) < 0)
1019 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x02) < 0)
1024 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x04) < 0)
1029 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x08) < 0)
1034 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x20) < 0)
1039 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x2f) < 0) /* all */
1044 case STV090x_SEARCH_DSS
:
1045 if (STV090x_WRITE_DEMOD(state
, FECM
, 0x80) < 0)
1047 switch (state
->fec
) {
1049 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x01) < 0)
1054 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x02) < 0)
1059 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x10) < 0)
1064 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x13) < 0) /* 1/2, 2/3, 6/7 */
1074 dprintk(FE_ERROR
, 1, "I/O error");
1078 static int stv090x_stop_modcod(struct stv090x_state
*state
)
1080 if (STV090x_WRITE_DEMOD(state
, MODCODLST0
, 0xff) < 0)
1082 if (STV090x_WRITE_DEMOD(state
, MODCODLST1
, 0xff) < 0)
1084 if (STV090x_WRITE_DEMOD(state
, MODCODLST2
, 0xff) < 0)
1086 if (STV090x_WRITE_DEMOD(state
, MODCODLST3
, 0xff) < 0)
1088 if (STV090x_WRITE_DEMOD(state
, MODCODLST4
, 0xff) < 0)
1090 if (STV090x_WRITE_DEMOD(state
, MODCODLST5
, 0xff) < 0)
1092 if (STV090x_WRITE_DEMOD(state
, MODCODLST6
, 0xff) < 0)
1094 if (STV090x_WRITE_DEMOD(state
, MODCODLST7
, 0xff) < 0)
1096 if (STV090x_WRITE_DEMOD(state
, MODCODLST8
, 0xff) < 0)
1098 if (STV090x_WRITE_DEMOD(state
, MODCODLST9
, 0xff) < 0)
1100 if (STV090x_WRITE_DEMOD(state
, MODCODLSTA
, 0xff) < 0)
1102 if (STV090x_WRITE_DEMOD(state
, MODCODLSTB
, 0xff) < 0)
1104 if (STV090x_WRITE_DEMOD(state
, MODCODLSTC
, 0xff) < 0)
1106 if (STV090x_WRITE_DEMOD(state
, MODCODLSTD
, 0xff) < 0)
1108 if (STV090x_WRITE_DEMOD(state
, MODCODLSTE
, 0xff) < 0)
1110 if (STV090x_WRITE_DEMOD(state
, MODCODLSTF
, 0xff) < 0)
1114 dprintk(FE_ERROR
, 1, "I/O error");
1118 static int stv090x_activate_modcod(struct stv090x_state
*state
)
1120 if (STV090x_WRITE_DEMOD(state
, MODCODLST0
, 0xff) < 0)
1122 if (STV090x_WRITE_DEMOD(state
, MODCODLST1
, 0xfc) < 0)
1124 if (STV090x_WRITE_DEMOD(state
, MODCODLST2
, 0xcc) < 0)
1126 if (STV090x_WRITE_DEMOD(state
, MODCODLST3
, 0xcc) < 0)
1128 if (STV090x_WRITE_DEMOD(state
, MODCODLST4
, 0xcc) < 0)
1130 if (STV090x_WRITE_DEMOD(state
, MODCODLST5
, 0xcc) < 0)
1132 if (STV090x_WRITE_DEMOD(state
, MODCODLST6
, 0xcc) < 0)
1134 if (STV090x_WRITE_DEMOD(state
, MODCODLST7
, 0xcc) < 0)
1136 if (STV090x_WRITE_DEMOD(state
, MODCODLST8
, 0xcc) < 0)
1138 if (STV090x_WRITE_DEMOD(state
, MODCODLST9
, 0xcc) < 0)
1140 if (STV090x_WRITE_DEMOD(state
, MODCODLSTA
, 0xcc) < 0)
1142 if (STV090x_WRITE_DEMOD(state
, MODCODLSTB
, 0xcc) < 0)
1144 if (STV090x_WRITE_DEMOD(state
, MODCODLSTC
, 0xcc) < 0)
1146 if (STV090x_WRITE_DEMOD(state
, MODCODLSTD
, 0xcc) < 0)
1148 if (STV090x_WRITE_DEMOD(state
, MODCODLSTE
, 0xcc) < 0)
1150 if (STV090x_WRITE_DEMOD(state
, MODCODLSTF
, 0xcf) < 0)
1155 dprintk(FE_ERROR
, 1, "I/O error");
1159 static int stv090x_activate_modcod_single(struct stv090x_state
*state
)
1162 if (STV090x_WRITE_DEMOD(state
, MODCODLST0
, 0xff) < 0)
1164 if (STV090x_WRITE_DEMOD(state
, MODCODLST1
, 0xf0) < 0)
1166 if (STV090x_WRITE_DEMOD(state
, MODCODLST2
, 0x00) < 0)
1168 if (STV090x_WRITE_DEMOD(state
, MODCODLST3
, 0x00) < 0)
1170 if (STV090x_WRITE_DEMOD(state
, MODCODLST4
, 0x00) < 0)
1172 if (STV090x_WRITE_DEMOD(state
, MODCODLST5
, 0x00) < 0)
1174 if (STV090x_WRITE_DEMOD(state
, MODCODLST6
, 0x00) < 0)
1176 if (STV090x_WRITE_DEMOD(state
, MODCODLST7
, 0x00) < 0)
1178 if (STV090x_WRITE_DEMOD(state
, MODCODLST8
, 0x00) < 0)
1180 if (STV090x_WRITE_DEMOD(state
, MODCODLST9
, 0x00) < 0)
1182 if (STV090x_WRITE_DEMOD(state
, MODCODLSTA
, 0x00) < 0)
1184 if (STV090x_WRITE_DEMOD(state
, MODCODLSTB
, 0x00) < 0)
1186 if (STV090x_WRITE_DEMOD(state
, MODCODLSTC
, 0x00) < 0)
1188 if (STV090x_WRITE_DEMOD(state
, MODCODLSTD
, 0x00) < 0)
1190 if (STV090x_WRITE_DEMOD(state
, MODCODLSTE
, 0x00) < 0)
1192 if (STV090x_WRITE_DEMOD(state
, MODCODLSTF
, 0x0f) < 0)
1198 dprintk(FE_ERROR
, 1, "I/O error");
1202 static int stv090x_vitclk_ctl(struct stv090x_state
*state
, int enable
)
1206 switch (state
->demod
) {
1207 case STV090x_DEMODULATOR_0
:
1208 mutex_lock(&state
->internal
->demod_lock
);
1209 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
1210 STV090x_SETFIELD(reg
, STOP_CLKVIT1_FIELD
, enable
);
1211 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
1213 mutex_unlock(&state
->internal
->demod_lock
);
1216 case STV090x_DEMODULATOR_1
:
1217 mutex_lock(&state
->internal
->demod_lock
);
1218 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
1219 STV090x_SETFIELD(reg
, STOP_CLKVIT2_FIELD
, enable
);
1220 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
1222 mutex_unlock(&state
->internal
->demod_lock
);
1226 dprintk(FE_ERROR
, 1, "Wrong demodulator!");
1231 mutex_unlock(&state
->internal
->demod_lock
);
1232 dprintk(FE_ERROR
, 1, "I/O error");
1236 static int stv090x_dvbs_track_crl(struct stv090x_state
*state
)
1238 if (state
->internal
->dev_ver
>= 0x30) {
1239 /* Set ACLC BCLC optimised value vs SR */
1240 if (state
->srate
>= 15000000) {
1241 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x2b) < 0)
1243 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x1a) < 0)
1245 } else if ((state
->srate
>= 7000000) && (15000000 > state
->srate
)) {
1246 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x0c) < 0)
1248 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x1b) < 0)
1250 } else if (state
->srate
< 7000000) {
1251 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x2c) < 0)
1253 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x1c) < 0)
1259 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x1a) < 0)
1261 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x09) < 0)
1266 dprintk(FE_ERROR
, 1, "I/O error");
1270 static int stv090x_delivery_search(struct stv090x_state
*state
)
1274 switch (state
->search_mode
) {
1275 case STV090x_SEARCH_DVBS1
:
1276 case STV090x_SEARCH_DSS
:
1277 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1278 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
1279 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 0);
1280 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1283 /* Activate Viterbi decoder in legacy search,
1284 * do not use FRESVIT1, might impact VITERBI2
1286 if (stv090x_vitclk_ctl(state
, 0) < 0)
1289 if (stv090x_dvbs_track_crl(state
) < 0)
1292 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x22) < 0) /* disable DVB-S2 */
1295 if (stv090x_set_vit_thacq(state
) < 0)
1297 if (stv090x_set_viterbi(state
) < 0)
1301 case STV090x_SEARCH_DVBS2
:
1302 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1303 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 0);
1304 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 0);
1305 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1307 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
1308 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 1);
1309 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1312 if (stv090x_vitclk_ctl(state
, 1) < 0)
1315 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x1a) < 0) /* stop DVB-S CR loop */
1317 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x09) < 0)
1320 if (state
->internal
->dev_ver
<= 0x20) {
1321 /* enable S2 carrier loop */
1322 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x26) < 0)
1325 /* > Cut 3: Stop carrier 3 */
1326 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x66) < 0)
1330 if (state
->demod_mode
!= STV090x_SINGLE
) {
1331 /* Cut 2: enable link during search */
1332 if (stv090x_activate_modcod(state
) < 0)
1335 /* Single demodulator
1336 * Authorize SHORT and LONG frames,
1337 * QPSK, 8PSK, 16APSK and 32APSK
1339 if (stv090x_activate_modcod_single(state
) < 0)
1343 if (stv090x_set_vit_thtracq(state
) < 0)
1347 case STV090x_SEARCH_AUTO
:
1349 /* enable DVB-S2 and DVB-S2 in Auto MODE */
1350 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1351 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 0);
1352 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 0);
1353 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1355 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
1356 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 1);
1357 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1360 if (stv090x_vitclk_ctl(state
, 0) < 0)
1363 if (stv090x_dvbs_track_crl(state
) < 0)
1366 if (state
->internal
->dev_ver
<= 0x20) {
1367 /* enable S2 carrier loop */
1368 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x26) < 0)
1371 /* > Cut 3: Stop carrier 3 */
1372 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x66) < 0)
1376 if (state
->demod_mode
!= STV090x_SINGLE
) {
1377 /* Cut 2: enable link during search */
1378 if (stv090x_activate_modcod(state
) < 0)
1381 /* Single demodulator
1382 * Authorize SHORT and LONG frames,
1383 * QPSK, 8PSK, 16APSK and 32APSK
1385 if (stv090x_activate_modcod_single(state
) < 0)
1389 if (stv090x_set_vit_thacq(state
) < 0)
1392 if (stv090x_set_viterbi(state
) < 0)
1398 dprintk(FE_ERROR
, 1, "I/O error");
1402 static int stv090x_start_search(struct stv090x_state
*state
)
1407 /* Reset demodulator */
1408 reg
= STV090x_READ_DEMOD(state
, DMDISTATE
);
1409 STV090x_SETFIELD_Px(reg
, I2C_DEMOD_MODE_FIELD
, 0x1f);
1410 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, reg
) < 0)
1413 if (state
->internal
->dev_ver
<= 0x20) {
1414 if (state
->srate
<= 5000000) {
1415 if (STV090x_WRITE_DEMOD(state
, CARCFG
, 0x44) < 0)
1417 if (STV090x_WRITE_DEMOD(state
, CFRUP1
, 0x0f) < 0)
1419 if (STV090x_WRITE_DEMOD(state
, CFRUP0
, 0xff) < 0)
1421 if (STV090x_WRITE_DEMOD(state
, CFRLOW1
, 0xf0) < 0)
1423 if (STV090x_WRITE_DEMOD(state
, CFRLOW0
, 0x00) < 0)
1426 /*enlarge the timing bandwidth for Low SR*/
1427 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x68) < 0)
1430 /* If the symbol rate is >5 Msps
1431 Set The carrier search up and low to auto mode */
1432 if (STV090x_WRITE_DEMOD(state
, CARCFG
, 0xc4) < 0)
1434 /*reduce the timing bandwidth for high SR*/
1435 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x44) < 0)
1440 if (state
->srate
<= 5000000) {
1441 /* enlarge the timing bandwidth for Low SR */
1442 STV090x_WRITE_DEMOD(state
, RTCS2
, 0x68);
1444 /* reduce timing bandwidth for high SR */
1445 STV090x_WRITE_DEMOD(state
, RTCS2
, 0x44);
1448 /* Set CFR min and max to manual mode */
1449 STV090x_WRITE_DEMOD(state
, CARCFG
, 0x46);
1451 if (state
->algo
== STV090x_WARM_SEARCH
) {
1456 freq_abs
= 1000 << 16;
1457 freq_abs
/= (state
->internal
->mclk
/ 1000);
1458 freq
= (s16
) freq_abs
;
1461 * CFR min =- (SearchRange / 2 + 600KHz)
1462 * CFR max = +(SearchRange / 2 + 600KHz)
1463 * (600KHz for the tuner step size)
1465 freq_abs
= (state
->search_range
/ 2000) + 600;
1466 freq_abs
= freq_abs
<< 16;
1467 freq_abs
/= (state
->internal
->mclk
/ 1000);
1468 freq
= (s16
) freq_abs
;
1471 if (STV090x_WRITE_DEMOD(state
, CFRUP1
, MSB(freq
)) < 0)
1473 if (STV090x_WRITE_DEMOD(state
, CFRUP0
, LSB(freq
)) < 0)
1478 if (STV090x_WRITE_DEMOD(state
, CFRLOW1
, MSB(freq
)) < 0)
1480 if (STV090x_WRITE_DEMOD(state
, CFRLOW0
, LSB(freq
)) < 0)
1485 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, 0) < 0)
1487 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, 0) < 0)
1490 if (state
->internal
->dev_ver
>= 0x20) {
1491 if (STV090x_WRITE_DEMOD(state
, EQUALCFG
, 0x41) < 0)
1493 if (STV090x_WRITE_DEMOD(state
, FFECFG
, 0x41) < 0)
1496 if ((state
->search_mode
== STV090x_SEARCH_DVBS1
) ||
1497 (state
->search_mode
== STV090x_SEARCH_DSS
) ||
1498 (state
->search_mode
== STV090x_SEARCH_AUTO
)) {
1500 if (STV090x_WRITE_DEMOD(state
, VITSCALE
, 0x82) < 0)
1502 if (STV090x_WRITE_DEMOD(state
, VAVSRVIT
, 0x00) < 0)
1507 if (STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x00) < 0)
1509 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, 0xe0) < 0)
1511 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, 0xc0) < 0)
1514 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1515 STV090x_SETFIELD_Px(reg
, SCAN_ENABLE_FIELD
, 0);
1516 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0);
1517 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1519 reg
= STV090x_READ_DEMOD(state
, DMDCFG2
);
1520 STV090x_SETFIELD_Px(reg
, S1S2_SEQUENTIAL_FIELD
, 0x0);
1521 if (STV090x_WRITE_DEMOD(state
, DMDCFG2
, reg
) < 0)
1524 if (STV090x_WRITE_DEMOD(state
, RTC
, 0x88) < 0)
1527 if (state
->internal
->dev_ver
>= 0x20) {
1528 /*Frequency offset detector setting*/
1529 if (state
->srate
< 2000000) {
1530 if (state
->internal
->dev_ver
<= 0x20) {
1532 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x39) < 0)
1536 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x89) < 0)
1539 if (STV090x_WRITE_DEMOD(state
, CARHDR
, 0x40) < 0)
1541 } else if (state
->srate
< 10000000) {
1542 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x4c) < 0)
1544 if (STV090x_WRITE_DEMOD(state
, CARHDR
, 0x20) < 0)
1547 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x4b) < 0)
1549 if (STV090x_WRITE_DEMOD(state
, CARHDR
, 0x20) < 0)
1553 if (state
->srate
< 10000000) {
1554 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0xef) < 0)
1557 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0xed) < 0)
1562 switch (state
->algo
) {
1563 case STV090x_WARM_SEARCH
:
1564 /* The symbol rate and the exact
1565 * carrier Frequency are known
1567 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
1569 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0)
1573 case STV090x_COLD_SEARCH
:
1574 /* The symbol rate is known */
1575 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
1577 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x15) < 0)
1586 dprintk(FE_ERROR
, 1, "I/O error");
1590 static int stv090x_get_agc2_min_level(struct stv090x_state
*state
)
1592 u32 agc2_min
= 0xffff, agc2
= 0, freq_init
, freq_step
, reg
;
1593 s32 i
, j
, steps
, dir
;
1595 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
1597 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1598 STV090x_SETFIELD_Px(reg
, SCAN_ENABLE_FIELD
, 0);
1599 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0);
1600 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1603 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, 0x83) < 0) /* SR = 65 Msps Max */
1605 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, 0xc0) < 0)
1607 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, 0x82) < 0) /* SR= 400 ksps Min */
1609 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, 0xa0) < 0)
1611 if (STV090x_WRITE_DEMOD(state
, DMDTOM
, 0x00) < 0) /* stop acq @ coarse carrier state */
1613 if (stv090x_set_srate(state
, 1000000) < 0)
1616 steps
= state
->search_range
/ 1000000;
1621 freq_step
= (1000000 * 256) / (state
->internal
->mclk
/ 256);
1624 for (i
= 0; i
< steps
; i
++) {
1626 freq_init
= freq_init
+ (freq_step
* i
);
1628 freq_init
= freq_init
- (freq_step
* i
);
1632 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x5c) < 0) /* Demod RESET */
1634 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, (freq_init
>> 8) & 0xff) < 0)
1636 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, freq_init
& 0xff) < 0)
1638 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x58) < 0) /* Demod RESET */
1643 for (j
= 0; j
< 10; j
++) {
1644 agc2
+= (STV090x_READ_DEMOD(state
, AGC2I1
) << 8) |
1645 STV090x_READ_DEMOD(state
, AGC2I0
);
1648 if (agc2
< agc2_min
)
1654 dprintk(FE_ERROR
, 1, "I/O error");
1658 static u32
stv090x_get_srate(struct stv090x_state
*state
, u32 clk
)
1661 s32 srate
, int_1
, int_2
, tmp_1
, tmp_2
;
1663 r3
= STV090x_READ_DEMOD(state
, SFR3
);
1664 r2
= STV090x_READ_DEMOD(state
, SFR2
);
1665 r1
= STV090x_READ_DEMOD(state
, SFR1
);
1666 r0
= STV090x_READ_DEMOD(state
, SFR0
);
1668 srate
= ((r3
<< 24) | (r2
<< 16) | (r1
<< 8) | r0
);
1671 int_2
= srate
>> 16;
1673 tmp_1
= clk
% 0x10000;
1674 tmp_2
= srate
% 0x10000;
1676 srate
= (int_1
* int_2
) +
1677 ((int_1
* tmp_2
) >> 16) +
1678 ((int_2
* tmp_1
) >> 16);
1683 static u32
stv090x_srate_srch_coarse(struct stv090x_state
*state
)
1685 struct dvb_frontend
*fe
= &state
->frontend
;
1687 int tmg_lock
= 0, i
;
1688 s32 tmg_cpt
= 0, dir
= 1, steps
, cur_step
= 0, freq
;
1689 u32 srate_coarse
= 0, agc2
= 0, car_step
= 1200, reg
;
1692 if (state
->internal
->dev_ver
>= 0x30)
1697 reg
= STV090x_READ_DEMOD(state
, DMDISTATE
);
1698 STV090x_SETFIELD_Px(reg
, I2C_DEMOD_MODE_FIELD
, 0x1f); /* Demod RESET */
1699 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, reg
) < 0)
1701 if (STV090x_WRITE_DEMOD(state
, TMGCFG
, 0x12) < 0)
1703 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc0) < 0)
1705 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, 0xf0) < 0)
1707 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, 0xe0) < 0)
1709 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1710 STV090x_SETFIELD_Px(reg
, SCAN_ENABLE_FIELD
, 1);
1711 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0);
1712 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1715 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, 0x83) < 0)
1717 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, 0xc0) < 0)
1719 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, 0x82) < 0)
1721 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, 0xa0) < 0)
1723 if (STV090x_WRITE_DEMOD(state
, DMDTOM
, 0x00) < 0)
1725 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x50) < 0)
1728 if (state
->internal
->dev_ver
>= 0x30) {
1729 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x99) < 0)
1731 if (STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x98) < 0)
1734 } else if (state
->internal
->dev_ver
>= 0x20) {
1735 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x6a) < 0)
1737 if (STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x95) < 0)
1741 if (state
->srate
<= 2000000)
1743 else if (state
->srate
<= 5000000)
1745 else if (state
->srate
<= 12000000)
1750 steps
= -1 + ((state
->search_range
/ 1000) / car_step
);
1752 steps
= (2 * steps
) + 1;
1755 else if (steps
> 10) {
1757 car_step
= (state
->search_range
/ 1000) / 10;
1761 freq
= state
->frequency
;
1763 while ((!tmg_lock
) && (cur_step
< steps
)) {
1764 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x5f) < 0) /* Demod RESET */
1766 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, 0x00) < 0)
1768 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, 0x00) < 0)
1770 if (STV090x_WRITE_DEMOD(state
, SFRINIT1
, 0x00) < 0)
1772 if (STV090x_WRITE_DEMOD(state
, SFRINIT0
, 0x00) < 0)
1774 /* trigger acquisition */
1775 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x40) < 0)
1778 for (i
= 0; i
< 10; i
++) {
1779 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
1780 if (STV090x_GETFIELD_Px(reg
, TMGLOCK_QUALITY_FIELD
) >= 2)
1782 agc2
+= (STV090x_READ_DEMOD(state
, AGC2I1
) << 8) |
1783 STV090x_READ_DEMOD(state
, AGC2I0
);
1786 srate_coarse
= stv090x_get_srate(state
, state
->internal
->mclk
);
1789 if ((tmg_cpt
>= 5) && (agc2
< agc2th
) &&
1790 (srate_coarse
< 50000000) && (srate_coarse
> 850000))
1792 else if (cur_step
< steps
) {
1794 freq
+= cur_step
* car_step
;
1796 freq
-= cur_step
* car_step
;
1799 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
1802 if (state
->config
->tuner_set_frequency
) {
1803 if (state
->config
->tuner_set_frequency(fe
, freq
) < 0)
1807 if (state
->config
->tuner_set_bandwidth
) {
1808 if (state
->config
->tuner_set_bandwidth(fe
, state
->tuner_bw
) < 0)
1812 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
1817 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
1820 if (state
->config
->tuner_get_status
) {
1821 if (state
->config
->tuner_get_status(fe
, ®
) < 0)
1826 dprintk(FE_DEBUG
, 1, "Tuner phase locked");
1828 dprintk(FE_DEBUG
, 1, "Tuner unlocked");
1830 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
1838 srate_coarse
= stv090x_get_srate(state
, state
->internal
->mclk
);
1840 return srate_coarse
;
1843 stv090x_i2c_gate_ctrl(state
, 0);
1845 dprintk(FE_ERROR
, 1, "I/O error");
1849 static u32
stv090x_srate_srch_fine(struct stv090x_state
*state
)
1851 u32 srate_coarse
, freq_coarse
, sym
, reg
;
1853 srate_coarse
= stv090x_get_srate(state
, state
->internal
->mclk
);
1854 freq_coarse
= STV090x_READ_DEMOD(state
, CFR2
) << 8;
1855 freq_coarse
|= STV090x_READ_DEMOD(state
, CFR1
);
1856 sym
= 13 * (srate_coarse
/ 10); /* SFRUP = SFR + 30% */
1858 if (sym
< state
->srate
)
1861 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0) /* Demod RESET */
1863 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc1) < 0)
1865 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, 0x20) < 0)
1867 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, 0x00) < 0)
1869 if (STV090x_WRITE_DEMOD(state
, TMGCFG
, 0xd2) < 0)
1871 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1872 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0x00);
1873 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1876 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
1879 if (state
->internal
->dev_ver
>= 0x30) {
1880 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x79) < 0)
1882 } else if (state
->internal
->dev_ver
>= 0x20) {
1883 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x49) < 0)
1887 if (srate_coarse
> 3000000) {
1888 sym
= 13 * (srate_coarse
/ 10); /* SFRUP = SFR + 30% */
1889 sym
= (sym
/ 1000) * 65536;
1890 sym
/= (state
->internal
->mclk
/ 1000);
1891 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, (sym
>> 8) & 0x7f) < 0)
1893 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, sym
& 0xff) < 0)
1895 sym
= 10 * (srate_coarse
/ 13); /* SFRLOW = SFR - 30% */
1896 sym
= (sym
/ 1000) * 65536;
1897 sym
/= (state
->internal
->mclk
/ 1000);
1898 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, (sym
>> 8) & 0x7f) < 0)
1900 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, sym
& 0xff) < 0)
1902 sym
= (srate_coarse
/ 1000) * 65536;
1903 sym
/= (state
->internal
->mclk
/ 1000);
1904 if (STV090x_WRITE_DEMOD(state
, SFRINIT1
, (sym
>> 8) & 0xff) < 0)
1906 if (STV090x_WRITE_DEMOD(state
, SFRINIT0
, sym
& 0xff) < 0)
1909 sym
= 13 * (srate_coarse
/ 10); /* SFRUP = SFR + 30% */
1910 sym
= (sym
/ 100) * 65536;
1911 sym
/= (state
->internal
->mclk
/ 100);
1912 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, (sym
>> 8) & 0x7f) < 0)
1914 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, sym
& 0xff) < 0)
1916 sym
= 10 * (srate_coarse
/ 14); /* SFRLOW = SFR - 30% */
1917 sym
= (sym
/ 100) * 65536;
1918 sym
/= (state
->internal
->mclk
/ 100);
1919 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, (sym
>> 8) & 0x7f) < 0)
1921 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, sym
& 0xff) < 0)
1923 sym
= (srate_coarse
/ 100) * 65536;
1924 sym
/= (state
->internal
->mclk
/ 100);
1925 if (STV090x_WRITE_DEMOD(state
, SFRINIT1
, (sym
>> 8) & 0xff) < 0)
1927 if (STV090x_WRITE_DEMOD(state
, SFRINIT0
, sym
& 0xff) < 0)
1930 if (STV090x_WRITE_DEMOD(state
, DMDTOM
, 0x20) < 0)
1932 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, (freq_coarse
>> 8) & 0xff) < 0)
1934 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, freq_coarse
& 0xff) < 0)
1936 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x15) < 0) /* trigger acquisition */
1940 return srate_coarse
;
1943 dprintk(FE_ERROR
, 1, "I/O error");
1947 static int stv090x_get_dmdlock(struct stv090x_state
*state
, s32 timeout
)
1949 s32 timer
= 0, lock
= 0;
1953 while ((timer
< timeout
) && (!lock
)) {
1954 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
1955 stat
= STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
);
1958 case 0: /* searching */
1959 case 1: /* first PLH detected */
1961 dprintk(FE_DEBUG
, 1, "Demodulator searching ..");
1964 case 2: /* DVB-S2 mode */
1965 case 3: /* DVB-S1/legacy mode */
1966 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
1967 lock
= STV090x_GETFIELD_Px(reg
, LOCK_DEFINITIF_FIELD
);
1974 dprintk(FE_DEBUG
, 1, "Demodulator acquired LOCK");
1981 static int stv090x_blind_search(struct stv090x_state
*state
)
1983 u32 agc2
, reg
, srate_coarse
;
1984 s32 cpt_fail
, agc2_ovflw
, i
;
1985 u8 k_ref
, k_max
, k_min
;
1986 int coarse_fail
= 0;
1992 agc2
= stv090x_get_agc2_min_level(state
);
1994 if (agc2
> STV090x_SEARCH_AGC2_TH(state
->internal
->dev_ver
)) {
1998 if (state
->internal
->dev_ver
<= 0x20) {
1999 if (STV090x_WRITE_DEMOD(state
, CARCFG
, 0xc4) < 0)
2003 if (STV090x_WRITE_DEMOD(state
, CARCFG
, 0x06) < 0)
2007 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x44) < 0)
2010 if (state
->internal
->dev_ver
>= 0x20) {
2011 if (STV090x_WRITE_DEMOD(state
, EQUALCFG
, 0x41) < 0)
2013 if (STV090x_WRITE_DEMOD(state
, FFECFG
, 0x41) < 0)
2015 if (STV090x_WRITE_DEMOD(state
, VITSCALE
, 0x82) < 0)
2017 if (STV090x_WRITE_DEMOD(state
, VAVSRVIT
, 0x00) < 0) /* set viterbi hysteresis */
2023 if (STV090x_WRITE_DEMOD(state
, KREFTMG
, k_ref
) < 0)
2025 if (stv090x_srate_srch_coarse(state
) != 0) {
2026 srate_coarse
= stv090x_srate_srch_fine(state
);
2027 if (srate_coarse
!= 0) {
2028 stv090x_get_lock_tmg(state
);
2029 lock
= stv090x_get_dmdlock(state
,
2030 state
->DemodTimeout
);
2037 for (i
= 0; i
< 10; i
++) {
2038 agc2
+= (STV090x_READ_DEMOD(state
, AGC2I1
) << 8) |
2039 STV090x_READ_DEMOD(state
, AGC2I0
);
2042 reg
= STV090x_READ_DEMOD(state
, DSTATUS2
);
2043 if ((STV090x_GETFIELD_Px(reg
, CFR_OVERFLOW_FIELD
) == 0x01) &&
2044 (STV090x_GETFIELD_Px(reg
, DEMOD_DELOCK_FIELD
) == 0x01))
2048 if ((cpt_fail
> 7) || (agc2_ovflw
> 7))
2054 } while ((k_ref
>= k_min
) && (!lock
) && (!coarse_fail
));
2060 dprintk(FE_ERROR
, 1, "I/O error");
2064 static int stv090x_chk_tmg(struct stv090x_state
*state
)
2068 u8 freq
, tmg_thh
, tmg_thl
;
2071 freq
= STV090x_READ_DEMOD(state
, CARFREQ
);
2072 tmg_thh
= STV090x_READ_DEMOD(state
, TMGTHRISE
);
2073 tmg_thl
= STV090x_READ_DEMOD(state
, TMGTHFALL
);
2074 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, 0x20) < 0)
2076 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, 0x00) < 0)
2079 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2080 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0x00); /* stop carrier offset search */
2081 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2083 if (STV090x_WRITE_DEMOD(state
, RTC
, 0x80) < 0)
2086 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x40) < 0)
2088 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x00) < 0)
2091 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, 0x00) < 0) /* set car ofset to 0 */
2093 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, 0x00) < 0)
2095 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x65) < 0)
2098 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0) /* trigger acquisition */
2102 for (i
= 0; i
< 10; i
++) {
2103 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
2104 if (STV090x_GETFIELD_Px(reg
, TMGLOCK_QUALITY_FIELD
) >= 2)
2111 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
2113 if (STV090x_WRITE_DEMOD(state
, RTC
, 0x88) < 0) /* DVB-S1 timing */
2115 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x68) < 0) /* DVB-S2 timing */
2118 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, freq
) < 0)
2120 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, tmg_thh
) < 0)
2122 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, tmg_thl
) < 0)
2128 dprintk(FE_ERROR
, 1, "I/O error");
2132 static int stv090x_get_coldlock(struct stv090x_state
*state
, s32 timeout_dmd
)
2134 struct dvb_frontend
*fe
= &state
->frontend
;
2137 s32 car_step
, steps
, cur_step
, dir
, freq
, timeout_lock
;
2140 if (state
->srate
>= 10000000)
2141 timeout_lock
= timeout_dmd
/ 3;
2143 timeout_lock
= timeout_dmd
/ 2;
2145 lock
= stv090x_get_dmdlock(state
, timeout_lock
); /* cold start wait */
2149 if (state
->srate
>= 10000000) {
2150 if (stv090x_chk_tmg(state
)) {
2151 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
2153 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x15) < 0)
2155 return stv090x_get_dmdlock(state
, timeout_dmd
);
2160 if (state
->srate
<= 4000000)
2162 else if (state
->srate
<= 7000000)
2164 else if (state
->srate
<= 10000000)
2169 steps
= (state
->search_range
/ 1000) / car_step
;
2171 steps
= 2 * (steps
+ 1);
2174 else if (steps
> 12)
2180 freq
= state
->frequency
;
2181 state
->tuner_bw
= stv090x_car_width(state
->srate
, state
->rolloff
) + state
->srate
;
2182 while ((cur_step
<= steps
) && (!lock
)) {
2184 freq
+= cur_step
* car_step
;
2186 freq
-= cur_step
* car_step
;
2189 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
2192 if (state
->config
->tuner_set_frequency
) {
2193 if (state
->config
->tuner_set_frequency(fe
, freq
) < 0)
2197 if (state
->config
->tuner_set_bandwidth
) {
2198 if (state
->config
->tuner_set_bandwidth(fe
, state
->tuner_bw
) < 0)
2202 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
2207 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
2210 if (state
->config
->tuner_get_status
) {
2211 if (state
->config
->tuner_get_status(fe
, ®
) < 0)
2214 dprintk(FE_DEBUG
, 1, "Tuner phase locked");
2216 dprintk(FE_DEBUG
, 1, "Tuner unlocked");
2219 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
2222 STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1c);
2223 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, 0x00) < 0)
2225 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, 0x00) < 0)
2227 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
2229 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x15) < 0)
2231 lock
= stv090x_get_dmdlock(state
, (timeout_dmd
/ 3));
2240 stv090x_i2c_gate_ctrl(state
, 0);
2242 dprintk(FE_ERROR
, 1, "I/O error");
2246 static int stv090x_get_loop_params(struct stv090x_state
*state
, s32
*freq_inc
, s32
*timeout_sw
, s32
*steps
)
2248 s32 timeout
, inc
, steps_max
, srate
, car_max
;
2250 srate
= state
->srate
;
2251 car_max
= state
->search_range
/ 1000;
2252 car_max
+= car_max
/ 10;
2253 car_max
= 65536 * (car_max
/ 2);
2254 car_max
/= (state
->internal
->mclk
/ 1000);
2256 if (car_max
> 0x4000)
2257 car_max
= 0x4000 ; /* maxcarrier should be<= +-1/4 Mclk */
2260 inc
/= state
->internal
->mclk
/ 1000;
2265 switch (state
->search_mode
) {
2266 case STV090x_SEARCH_DVBS1
:
2267 case STV090x_SEARCH_DSS
:
2268 inc
*= 3; /* freq step = 3% of srate */
2272 case STV090x_SEARCH_DVBS2
:
2277 case STV090x_SEARCH_AUTO
:
2284 if ((inc
> car_max
) || (inc
< 0))
2285 inc
= car_max
/ 2; /* increment <= 1/8 Mclk */
2287 timeout
*= 27500; /* 27.5 Msps reference */
2289 timeout
/= (srate
/ 1000);
2291 if ((timeout
> 100) || (timeout
< 0))
2294 steps_max
= (car_max
/ inc
) + 1; /* min steps = 3 */
2295 if ((steps_max
> 100) || (steps_max
< 0)) {
2296 steps_max
= 100; /* max steps <= 100 */
2297 inc
= car_max
/ steps_max
;
2300 *timeout_sw
= timeout
;
2306 static int stv090x_chk_signal(struct stv090x_state
*state
)
2308 s32 offst_car
, agc2
, car_max
;
2311 offst_car
= STV090x_READ_DEMOD(state
, CFR2
) << 8;
2312 offst_car
|= STV090x_READ_DEMOD(state
, CFR1
);
2313 offst_car
= comp2(offst_car
, 16);
2315 agc2
= STV090x_READ_DEMOD(state
, AGC2I1
) << 8;
2316 agc2
|= STV090x_READ_DEMOD(state
, AGC2I0
);
2317 car_max
= state
->search_range
/ 1000;
2319 car_max
+= (car_max
/ 10); /* 10% margin */
2320 car_max
= (65536 * car_max
/ 2);
2321 car_max
/= state
->internal
->mclk
/ 1000;
2323 if (car_max
> 0x4000)
2326 if ((agc2
> 0x2000) || (offst_car
> 2 * car_max
) || (offst_car
< -2 * car_max
)) {
2328 dprintk(FE_DEBUG
, 1, "No Signal");
2331 dprintk(FE_DEBUG
, 1, "Found Signal");
2337 static int stv090x_search_car_loop(struct stv090x_state
*state
, s32 inc
, s32 timeout
, int zigzag
, s32 steps_max
)
2339 int no_signal
, lock
= 0;
2340 s32 cpt_step
= 0, offst_freq
, car_max
;
2343 car_max
= state
->search_range
/ 1000;
2344 car_max
+= (car_max
/ 10);
2345 car_max
= (65536 * car_max
/ 2);
2346 car_max
/= (state
->internal
->mclk
/ 1000);
2347 if (car_max
> 0x4000)
2353 offst_freq
= -car_max
+ inc
;
2356 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1c) < 0)
2358 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, ((offst_freq
/ 256) & 0xff)) < 0)
2360 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, offst_freq
& 0xff) < 0)
2362 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0)
2365 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
2366 STV090x_SETFIELD_Px(reg
, ALGOSWRST_FIELD
, 0x1); /* stop DVB-S2 packet delin */
2367 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
2371 if (offst_freq
>= 0)
2372 offst_freq
= -offst_freq
- 2 * inc
;
2374 offst_freq
= -offst_freq
;
2376 offst_freq
+= 2 * inc
;
2381 lock
= stv090x_get_dmdlock(state
, timeout
);
2382 no_signal
= stv090x_chk_signal(state
);
2386 ((offst_freq
- inc
) < car_max
) &&
2387 ((offst_freq
+ inc
) > -car_max
) &&
2388 (cpt_step
< steps_max
));
2390 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
2391 STV090x_SETFIELD_Px(reg
, ALGOSWRST_FIELD
, 0);
2392 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
2397 dprintk(FE_ERROR
, 1, "I/O error");
2401 static int stv090x_sw_algo(struct stv090x_state
*state
)
2403 int no_signal
, zigzag
, lock
= 0;
2406 s32 dvbs2_fly_wheel
;
2407 s32 inc
, timeout_step
, trials
, steps_max
;
2410 stv090x_get_loop_params(state
, &inc
, &timeout_step
, &steps_max
);
2412 switch (state
->search_mode
) {
2413 case STV090x_SEARCH_DVBS1
:
2414 case STV090x_SEARCH_DSS
:
2415 /* accelerate the frequency detector */
2416 if (state
->internal
->dev_ver
>= 0x20) {
2417 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x3B) < 0)
2421 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, 0x49) < 0)
2426 case STV090x_SEARCH_DVBS2
:
2427 if (state
->internal
->dev_ver
>= 0x20) {
2428 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x79) < 0)
2432 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, 0x89) < 0)
2437 case STV090x_SEARCH_AUTO
:
2439 /* accelerate the frequency detector */
2440 if (state
->internal
->dev_ver
>= 0x20) {
2441 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x3b) < 0)
2443 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x79) < 0)
2447 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, 0xc9) < 0)
2455 lock
= stv090x_search_car_loop(state
, inc
, timeout_step
, zigzag
, steps_max
);
2456 no_signal
= stv090x_chk_signal(state
);
2459 /*run the SW search 2 times maximum*/
2460 if (lock
|| no_signal
|| (trials
== 2)) {
2461 /*Check if the demod is not losing lock in DVBS2*/
2462 if (state
->internal
->dev_ver
>= 0x20) {
2463 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x49) < 0)
2465 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x9e) < 0)
2469 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
2470 if ((lock
) && (STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
) == STV090x_DVBS2
)) {
2471 /*Check if the demod is not losing lock in DVBS2*/
2472 msleep(timeout_step
);
2473 reg
= STV090x_READ_DEMOD(state
, DMDFLYW
);
2474 dvbs2_fly_wheel
= STV090x_GETFIELD_Px(reg
, FLYWHEEL_CPT_FIELD
);
2475 if (dvbs2_fly_wheel
< 0xd) { /*if correct frames is decrementing */
2476 msleep(timeout_step
);
2477 reg
= STV090x_READ_DEMOD(state
, DMDFLYW
);
2478 dvbs2_fly_wheel
= STV090x_GETFIELD_Px(reg
, FLYWHEEL_CPT_FIELD
);
2480 if (dvbs2_fly_wheel
< 0xd) {
2481 /*FALSE lock, The demod is losing lock */
2484 if (state
->internal
->dev_ver
>= 0x20) {
2485 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x79) < 0)
2489 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, 0x89) < 0)
2495 } while ((!lock
) && (trials
< 2) && (!no_signal
));
2499 dprintk(FE_ERROR
, 1, "I/O error");
2503 static enum stv090x_delsys
stv090x_get_std(struct stv090x_state
*state
)
2506 enum stv090x_delsys delsys
;
2508 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
2509 if (STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
) == 2)
2510 delsys
= STV090x_DVBS2
;
2511 else if (STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
) == 3) {
2512 reg
= STV090x_READ_DEMOD(state
, FECM
);
2513 if (STV090x_GETFIELD_Px(reg
, DSS_DVB_FIELD
) == 1)
2514 delsys
= STV090x_DSS
;
2516 delsys
= STV090x_DVBS1
;
2518 delsys
= STV090x_ERROR
;
2525 static s32
stv090x_get_car_freq(struct stv090x_state
*state
, u32 mclk
)
2527 s32 derot
, int_1
, int_2
, tmp_1
, tmp_2
;
2529 derot
= STV090x_READ_DEMOD(state
, CFR2
) << 16;
2530 derot
|= STV090x_READ_DEMOD(state
, CFR1
) << 8;
2531 derot
|= STV090x_READ_DEMOD(state
, CFR0
);
2533 derot
= comp2(derot
, 24);
2535 int_2
= derot
>> 12;
2537 /* carrier_frequency = MasterClock * Reg / 2^24 */
2538 tmp_1
= mclk
% 0x1000;
2539 tmp_2
= derot
% 0x1000;
2541 derot
= (int_1
* int_2
) +
2542 ((int_1
* tmp_2
) >> 12) +
2543 ((int_2
* tmp_1
) >> 12);
2548 static int stv090x_get_viterbi(struct stv090x_state
*state
)
2552 reg
= STV090x_READ_DEMOD(state
, VITCURPUN
);
2553 rate
= STV090x_GETFIELD_Px(reg
, VIT_CURPUN_FIELD
);
2557 state
->fec
= STV090x_PR12
;
2561 state
->fec
= STV090x_PR23
;
2565 state
->fec
= STV090x_PR34
;
2569 state
->fec
= STV090x_PR56
;
2573 state
->fec
= STV090x_PR67
;
2577 state
->fec
= STV090x_PR78
;
2581 state
->fec
= STV090x_PRERR
;
2588 static enum stv090x_signal_state
stv090x_get_sig_params(struct stv090x_state
*state
)
2590 struct dvb_frontend
*fe
= &state
->frontend
;
2594 s32 i
= 0, offst_freq
;
2598 if (state
->algo
== STV090x_BLIND_SEARCH
) {
2599 tmg
= STV090x_READ_DEMOD(state
, TMGREG2
);
2600 STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x5c);
2601 while ((i
<= 50) && (tmg
!= 0) && (tmg
!= 0xff)) {
2602 tmg
= STV090x_READ_DEMOD(state
, TMGREG2
);
2607 state
->delsys
= stv090x_get_std(state
);
2609 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
2612 if (state
->config
->tuner_get_frequency
) {
2613 if (state
->config
->tuner_get_frequency(fe
, &state
->frequency
) < 0)
2617 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
2620 offst_freq
= stv090x_get_car_freq(state
, state
->internal
->mclk
) / 1000;
2621 state
->frequency
+= offst_freq
;
2623 if (stv090x_get_viterbi(state
) < 0)
2626 reg
= STV090x_READ_DEMOD(state
, DMDMODCOD
);
2627 state
->modcod
= STV090x_GETFIELD_Px(reg
, DEMOD_MODCOD_FIELD
);
2628 state
->pilots
= STV090x_GETFIELD_Px(reg
, DEMOD_TYPE_FIELD
) & 0x01;
2629 state
->frame_len
= STV090x_GETFIELD_Px(reg
, DEMOD_TYPE_FIELD
) >> 1;
2630 reg
= STV090x_READ_DEMOD(state
, TMGOBS
);
2631 state
->rolloff
= STV090x_GETFIELD_Px(reg
, ROLLOFF_STATUS_FIELD
);
2632 reg
= STV090x_READ_DEMOD(state
, FECM
);
2633 state
->inversion
= STV090x_GETFIELD_Px(reg
, IQINV_FIELD
);
2635 if ((state
->algo
== STV090x_BLIND_SEARCH
) || (state
->srate
< 10000000)) {
2637 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
2640 if (state
->config
->tuner_get_frequency
) {
2641 if (state
->config
->tuner_get_frequency(fe
, &state
->frequency
) < 0)
2645 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
2648 if (abs(offst_freq
) <= ((state
->search_range
/ 2000) + 500))
2649 return STV090x_RANGEOK
;
2650 else if (abs(offst_freq
) <= (stv090x_car_width(state
->srate
, state
->rolloff
) / 2000))
2651 return STV090x_RANGEOK
;
2653 if (abs(offst_freq
) <= ((state
->search_range
/ 2000) + 500))
2654 return STV090x_RANGEOK
;
2657 return STV090x_OUTOFRANGE
;
2660 stv090x_i2c_gate_ctrl(state
, 0);
2662 dprintk(FE_ERROR
, 1, "I/O error");
2666 static u32
stv090x_get_tmgoffst(struct stv090x_state
*state
, u32 srate
)
2670 offst_tmg
= STV090x_READ_DEMOD(state
, TMGREG2
) << 16;
2671 offst_tmg
|= STV090x_READ_DEMOD(state
, TMGREG1
) << 8;
2672 offst_tmg
|= STV090x_READ_DEMOD(state
, TMGREG0
);
2674 offst_tmg
= comp2(offst_tmg
, 24); /* 2's complement */
2678 offst_tmg
= ((s32
) srate
* 10) / ((s32
) 0x1000000 / offst_tmg
);
2684 static u8
stv090x_optimize_carloop(struct stv090x_state
*state
, enum stv090x_modcod modcod
, s32 pilots
)
2688 struct stv090x_long_frame_crloop
*car_loop
, *car_loop_qpsk_low
, *car_loop_apsk_low
;
2690 if (state
->internal
->dev_ver
== 0x20) {
2691 car_loop
= stv090x_s2_crl_cut20
;
2692 car_loop_qpsk_low
= stv090x_s2_lowqpsk_crl_cut20
;
2693 car_loop_apsk_low
= stv090x_s2_apsk_crl_cut20
;
2696 car_loop
= stv090x_s2_crl_cut30
;
2697 car_loop_qpsk_low
= stv090x_s2_lowqpsk_crl_cut30
;
2698 car_loop_apsk_low
= stv090x_s2_apsk_crl_cut30
;
2701 if (modcod
< STV090x_QPSK_12
) {
2703 while ((i
< 3) && (modcod
!= car_loop_qpsk_low
[i
].modcod
))
2711 while ((i
< 14) && (modcod
!= car_loop
[i
].modcod
))
2716 while ((i
< 11) && (modcod
!= car_loop_apsk_low
[i
].modcod
))
2724 if (modcod
<= STV090x_QPSK_25
) {
2726 if (state
->srate
<= 3000000)
2727 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_2
;
2728 else if (state
->srate
<= 7000000)
2729 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_5
;
2730 else if (state
->srate
<= 15000000)
2731 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_10
;
2732 else if (state
->srate
<= 25000000)
2733 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_20
;
2735 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_30
;
2737 if (state
->srate
<= 3000000)
2738 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_2
;
2739 else if (state
->srate
<= 7000000)
2740 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_5
;
2741 else if (state
->srate
<= 15000000)
2742 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_10
;
2743 else if (state
->srate
<= 25000000)
2744 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_20
;
2746 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_30
;
2749 } else if (modcod
<= STV090x_8PSK_910
) {
2751 if (state
->srate
<= 3000000)
2752 aclc
= car_loop
[i
].crl_pilots_on_2
;
2753 else if (state
->srate
<= 7000000)
2754 aclc
= car_loop
[i
].crl_pilots_on_5
;
2755 else if (state
->srate
<= 15000000)
2756 aclc
= car_loop
[i
].crl_pilots_on_10
;
2757 else if (state
->srate
<= 25000000)
2758 aclc
= car_loop
[i
].crl_pilots_on_20
;
2760 aclc
= car_loop
[i
].crl_pilots_on_30
;
2762 if (state
->srate
<= 3000000)
2763 aclc
= car_loop
[i
].crl_pilots_off_2
;
2764 else if (state
->srate
<= 7000000)
2765 aclc
= car_loop
[i
].crl_pilots_off_5
;
2766 else if (state
->srate
<= 15000000)
2767 aclc
= car_loop
[i
].crl_pilots_off_10
;
2768 else if (state
->srate
<= 25000000)
2769 aclc
= car_loop
[i
].crl_pilots_off_20
;
2771 aclc
= car_loop
[i
].crl_pilots_off_30
;
2773 } else { /* 16APSK and 32APSK */
2775 * This should never happen in practice, except if
2776 * something is really wrong at the car_loop table.
2780 if (state
->srate
<= 3000000)
2781 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_2
;
2782 else if (state
->srate
<= 7000000)
2783 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_5
;
2784 else if (state
->srate
<= 15000000)
2785 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_10
;
2786 else if (state
->srate
<= 25000000)
2787 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_20
;
2789 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_30
;
2795 static u8
stv090x_optimize_carloop_short(struct stv090x_state
*state
)
2797 struct stv090x_short_frame_crloop
*short_crl
= NULL
;
2801 switch (state
->modulation
) {
2809 case STV090x_16APSK
:
2812 case STV090x_32APSK
:
2817 if (state
->internal
->dev_ver
>= 0x30) {
2818 /* Cut 3.0 and up */
2819 short_crl
= stv090x_s2_short_crl_cut30
;
2821 /* Cut 2.0 and up: we don't support cuts older than 2.0 */
2822 short_crl
= stv090x_s2_short_crl_cut20
;
2825 if (state
->srate
<= 3000000)
2826 aclc
= short_crl
[index
].crl_2
;
2827 else if (state
->srate
<= 7000000)
2828 aclc
= short_crl
[index
].crl_5
;
2829 else if (state
->srate
<= 15000000)
2830 aclc
= short_crl
[index
].crl_10
;
2831 else if (state
->srate
<= 25000000)
2832 aclc
= short_crl
[index
].crl_20
;
2834 aclc
= short_crl
[index
].crl_30
;
2839 static int stv090x_optimize_track(struct stv090x_state
*state
)
2841 struct dvb_frontend
*fe
= &state
->frontend
;
2843 enum stv090x_modcod modcod
;
2845 s32 srate
, pilots
, aclc
, f_1
, f_0
, i
= 0, blind_tune
= 0;
2848 srate
= stv090x_get_srate(state
, state
->internal
->mclk
);
2849 srate
+= stv090x_get_tmgoffst(state
, srate
);
2851 switch (state
->delsys
) {
2854 if (state
->search_mode
== STV090x_SEARCH_AUTO
) {
2855 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2856 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
2857 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 0);
2858 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2861 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
2862 STV090x_SETFIELD_Px(reg
, ROLLOFF_CONTROL_FIELD
, state
->rolloff
);
2863 STV090x_SETFIELD_Px(reg
, MANUAL_SXROLLOFF_FIELD
, 0x01);
2864 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
2867 if (state
->internal
->dev_ver
>= 0x30) {
2868 if (stv090x_get_viterbi(state
) < 0)
2871 if (state
->fec
== STV090x_PR12
) {
2872 if (STV090x_WRITE_DEMOD(state
, GAUSSR0
, 0x98) < 0)
2874 if (STV090x_WRITE_DEMOD(state
, CCIR0
, 0x18) < 0)
2877 if (STV090x_WRITE_DEMOD(state
, GAUSSR0
, 0x18) < 0)
2879 if (STV090x_WRITE_DEMOD(state
, CCIR0
, 0x18) < 0)
2884 if (STV090x_WRITE_DEMOD(state
, ERRCTRL1
, 0x75) < 0)
2889 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2890 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 0);
2891 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 1);
2892 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2894 if (state
->internal
->dev_ver
>= 0x30) {
2895 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0) < 0)
2897 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0) < 0)
2900 if (state
->frame_len
== STV090x_LONG_FRAME
) {
2901 reg
= STV090x_READ_DEMOD(state
, DMDMODCOD
);
2902 modcod
= STV090x_GETFIELD_Px(reg
, DEMOD_MODCOD_FIELD
);
2903 pilots
= STV090x_GETFIELD_Px(reg
, DEMOD_TYPE_FIELD
) & 0x01;
2904 aclc
= stv090x_optimize_carloop(state
, modcod
, pilots
);
2905 if (modcod
<= STV090x_QPSK_910
) {
2906 STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, aclc
);
2907 } else if (modcod
<= STV090x_8PSK_910
) {
2908 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2910 if (STV090x_WRITE_DEMOD(state
, ACLC2S28
, aclc
) < 0)
2913 if ((state
->demod_mode
== STV090x_SINGLE
) && (modcod
> STV090x_8PSK_910
)) {
2914 if (modcod
<= STV090x_16APSK_910
) {
2915 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2917 if (STV090x_WRITE_DEMOD(state
, ACLC2S216A
, aclc
) < 0)
2920 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2922 if (STV090x_WRITE_DEMOD(state
, ACLC2S232A
, aclc
) < 0)
2927 /*Carrier loop setting for short frame*/
2928 aclc
= stv090x_optimize_carloop_short(state
);
2929 if (state
->modulation
== STV090x_QPSK
) {
2930 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, aclc
) < 0)
2932 } else if (state
->modulation
== STV090x_8PSK
) {
2933 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2935 if (STV090x_WRITE_DEMOD(state
, ACLC2S28
, aclc
) < 0)
2937 } else if (state
->modulation
== STV090x_16APSK
) {
2938 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2940 if (STV090x_WRITE_DEMOD(state
, ACLC2S216A
, aclc
) < 0)
2942 } else if (state
->modulation
== STV090x_32APSK
) {
2943 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2945 if (STV090x_WRITE_DEMOD(state
, ACLC2S232A
, aclc
) < 0)
2950 STV090x_WRITE_DEMOD(state
, ERRCTRL1
, 0x67); /* PER */
2955 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2956 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
2957 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 1);
2958 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2963 f_1
= STV090x_READ_DEMOD(state
, CFR2
);
2964 f_0
= STV090x_READ_DEMOD(state
, CFR1
);
2965 reg
= STV090x_READ_DEMOD(state
, TMGOBS
);
2967 if (state
->algo
== STV090x_BLIND_SEARCH
) {
2968 STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x00);
2969 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2970 STV090x_SETFIELD_Px(reg
, SCAN_ENABLE_FIELD
, 0x00);
2971 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0x00);
2972 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2974 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc1) < 0)
2977 if (stv090x_set_srate(state
, srate
) < 0)
2981 if (stv090x_dvbs_track_crl(state
) < 0)
2985 if (state
->internal
->dev_ver
>= 0x20) {
2986 if ((state
->search_mode
== STV090x_SEARCH_DVBS1
) ||
2987 (state
->search_mode
== STV090x_SEARCH_DSS
) ||
2988 (state
->search_mode
== STV090x_SEARCH_AUTO
)) {
2990 if (STV090x_WRITE_DEMOD(state
, VAVSRVIT
, 0x0a) < 0)
2992 if (STV090x_WRITE_DEMOD(state
, VITSCALE
, 0x00) < 0)
2997 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
3000 /* AUTO tracking MODE */
3001 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, 0x80) < 0)
3003 /* AUTO tracking MODE */
3004 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, 0x80) < 0)
3007 if ((state
->internal
->dev_ver
>= 0x20) || (blind_tune
== 1) ||
3008 (state
->srate
< 10000000)) {
3009 /* update initial carrier freq with the found freq offset */
3010 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, f_1
) < 0)
3012 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, f_0
) < 0)
3014 state
->tuner_bw
= stv090x_car_width(srate
, state
->rolloff
) + 10000000;
3016 if ((state
->internal
->dev_ver
>= 0x20) || (blind_tune
== 1)) {
3018 if (state
->algo
!= STV090x_WARM_SEARCH
) {
3020 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
3023 if (state
->config
->tuner_set_bandwidth
) {
3024 if (state
->config
->tuner_set_bandwidth(fe
, state
->tuner_bw
) < 0)
3028 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
3033 if ((state
->algo
== STV090x_BLIND_SEARCH
) || (state
->srate
< 10000000))
3034 msleep(50); /* blind search: wait 50ms for SR stabilization */
3038 stv090x_get_lock_tmg(state
);
3040 if (!(stv090x_get_dmdlock(state
, (state
->DemodTimeout
/ 2)))) {
3041 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
3043 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, f_1
) < 0)
3045 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, f_0
) < 0)
3047 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0)
3052 while ((!(stv090x_get_dmdlock(state
, (state
->DemodTimeout
/ 2)))) && (i
<= 2)) {
3054 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
3056 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, f_1
) < 0)
3058 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, f_0
) < 0)
3060 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0)
3068 if (state
->internal
->dev_ver
>= 0x20) {
3069 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x49) < 0)
3073 if ((state
->delsys
== STV090x_DVBS1
) || (state
->delsys
== STV090x_DSS
))
3074 stv090x_set_vit_thtracq(state
);
3079 stv090x_i2c_gate_ctrl(state
, 0);
3081 dprintk(FE_ERROR
, 1, "I/O error");
3085 static int stv090x_get_feclock(struct stv090x_state
*state
, s32 timeout
)
3087 s32 timer
= 0, lock
= 0, stat
;
3090 while ((timer
< timeout
) && (!lock
)) {
3091 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
3092 stat
= STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
);
3095 case 0: /* searching */
3096 case 1: /* first PLH detected */
3101 case 2: /* DVB-S2 mode */
3102 reg
= STV090x_READ_DEMOD(state
, PDELSTATUS1
);
3103 lock
= STV090x_GETFIELD_Px(reg
, PKTDELIN_LOCK_FIELD
);
3106 case 3: /* DVB-S1/legacy mode */
3107 reg
= STV090x_READ_DEMOD(state
, VSTATUSVIT
);
3108 lock
= STV090x_GETFIELD_Px(reg
, LOCKEDVIT_FIELD
);
3119 static int stv090x_get_lock(struct stv090x_state
*state
, s32 timeout_dmd
, s32 timeout_fec
)
3125 lock
= stv090x_get_dmdlock(state
, timeout_dmd
);
3127 lock
= stv090x_get_feclock(state
, timeout_fec
);
3132 while ((timer
< timeout_fec
) && (!lock
)) {
3133 reg
= STV090x_READ_DEMOD(state
, TSSTATUS
);
3134 lock
= STV090x_GETFIELD_Px(reg
, TSFIFO_LINEOK_FIELD
);
3143 static int stv090x_set_s2rolloff(struct stv090x_state
*state
)
3147 if (state
->internal
->dev_ver
<= 0x20) {
3148 /* rolloff to auto mode if DVBS2 */
3149 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
3150 STV090x_SETFIELD_Px(reg
, MANUAL_SXROLLOFF_FIELD
, 0x00);
3151 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
3154 /* DVB-S2 rolloff to auto mode if DVBS2 */
3155 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
3156 STV090x_SETFIELD_Px(reg
, MANUAL_S2ROLLOFF_FIELD
, 0x00);
3157 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
3162 dprintk(FE_ERROR
, 1, "I/O error");
3167 static enum stv090x_signal_state
stv090x_algo(struct stv090x_state
*state
)
3169 struct dvb_frontend
*fe
= &state
->frontend
;
3170 enum stv090x_signal_state signal_state
= STV090x_NOCARRIER
;
3172 s32 agc1_power
, power_iq
= 0, i
;
3173 int lock
= 0, low_sr
= 0;
3175 reg
= STV090x_READ_DEMOD(state
, TSCFGH
);
3176 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 1); /* Stop path 1 stream merger */
3177 if (STV090x_WRITE_DEMOD(state
, TSCFGH
, reg
) < 0)
3180 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x5c) < 0) /* Demod stop */
3183 if (state
->internal
->dev_ver
>= 0x20) {
3184 if (state
->srate
> 5000000) {
3185 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x9e) < 0)
3188 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x82) < 0)
3193 stv090x_get_lock_tmg(state
);
3195 if (state
->algo
== STV090x_BLIND_SEARCH
) {
3196 state
->tuner_bw
= 2 * 36000000; /* wide bw for unknown srate */
3197 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc0) < 0) /* wider srate scan */
3199 if (STV090x_WRITE_DEMOD(state
, CORRELMANT
, 0x70) < 0)
3201 if (stv090x_set_srate(state
, 1000000) < 0) /* initial srate = 1Msps */
3205 if (STV090x_WRITE_DEMOD(state
, DMDTOM
, 0x20) < 0)
3207 if (STV090x_WRITE_DEMOD(state
, TMGCFG
, 0xd2) < 0)
3210 if (state
->srate
< 2000000) {
3212 if (STV090x_WRITE_DEMOD(state
, CORRELMANT
, 0x63) < 0)
3216 if (STV090x_WRITE_DEMOD(state
, CORRELMANT
, 0x70) < 0)
3220 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
3223 if (state
->internal
->dev_ver
>= 0x20) {
3224 if (STV090x_WRITE_DEMOD(state
, KREFTMG
, 0x5a) < 0)
3226 if (state
->algo
== STV090x_COLD_SEARCH
)
3227 state
->tuner_bw
= (15 * (stv090x_car_width(state
->srate
, state
->rolloff
) + 10000000)) / 10;
3228 else if (state
->algo
== STV090x_WARM_SEARCH
)
3229 state
->tuner_bw
= stv090x_car_width(state
->srate
, state
->rolloff
) + 10000000;
3232 /* if cold start or warm (Symbolrate is known)
3233 * use a Narrow symbol rate scan range
3235 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc1) < 0) /* narrow srate scan */
3238 if (stv090x_set_srate(state
, state
->srate
) < 0)
3241 if (stv090x_set_max_srate(state
, state
->internal
->mclk
,
3244 if (stv090x_set_min_srate(state
, state
->internal
->mclk
,
3248 if (state
->srate
>= 10000000)
3255 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
3258 if (state
->config
->tuner_set_bbgain
) {
3259 reg
= state
->config
->tuner_bbgain
;
3261 reg
= 10; /* default: 10dB */
3262 if (state
->config
->tuner_set_bbgain(fe
, reg
) < 0)
3266 if (state
->config
->tuner_set_frequency
) {
3267 if (state
->config
->tuner_set_frequency(fe
, state
->frequency
) < 0)
3271 if (state
->config
->tuner_set_bandwidth
) {
3272 if (state
->config
->tuner_set_bandwidth(fe
, state
->tuner_bw
) < 0)
3276 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
3281 if (state
->config
->tuner_get_status
) {
3282 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
3284 if (state
->config
->tuner_get_status(fe
, ®
) < 0)
3286 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
3290 dprintk(FE_DEBUG
, 1, "Tuner phase locked");
3292 dprintk(FE_DEBUG
, 1, "Tuner unlocked");
3293 return STV090x_NOCARRIER
;
3298 agc1_power
= MAKEWORD16(STV090x_READ_DEMOD(state
, AGCIQIN1
),
3299 STV090x_READ_DEMOD(state
, AGCIQIN0
));
3301 if (agc1_power
== 0) {
3302 /* If AGC1 integrator value is 0
3303 * then read POWERI, POWERQ
3305 for (i
= 0; i
< 5; i
++) {
3306 power_iq
+= (STV090x_READ_DEMOD(state
, POWERI
) +
3307 STV090x_READ_DEMOD(state
, POWERQ
)) >> 1;
3312 if ((agc1_power
== 0) && (power_iq
< STV090x_IQPOWER_THRESHOLD
)) {
3313 dprintk(FE_ERROR
, 1, "No Signal: POWER_IQ=0x%02x", power_iq
);
3315 signal_state
= STV090x_NOAGC1
;
3317 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
3318 STV090x_SETFIELD_Px(reg
, SPECINV_CONTROL_FIELD
, state
->inversion
);
3320 if (state
->internal
->dev_ver
<= 0x20) {
3321 /* rolloff to auto mode if DVBS2 */
3322 STV090x_SETFIELD_Px(reg
, MANUAL_SXROLLOFF_FIELD
, 1);
3324 /* DVB-S2 rolloff to auto mode if DVBS2 */
3325 STV090x_SETFIELD_Px(reg
, MANUAL_S2ROLLOFF_FIELD
, 1);
3327 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
3330 if (stv090x_delivery_search(state
) < 0)
3333 if (state
->algo
!= STV090x_BLIND_SEARCH
) {
3334 if (stv090x_start_search(state
) < 0)
3339 if (signal_state
== STV090x_NOAGC1
)
3340 return signal_state
;
3342 if (state
->algo
== STV090x_BLIND_SEARCH
)
3343 lock
= stv090x_blind_search(state
);
3345 else if (state
->algo
== STV090x_COLD_SEARCH
)
3346 lock
= stv090x_get_coldlock(state
, state
->DemodTimeout
);
3348 else if (state
->algo
== STV090x_WARM_SEARCH
)
3349 lock
= stv090x_get_dmdlock(state
, state
->DemodTimeout
);
3351 if ((!lock
) && (state
->algo
== STV090x_COLD_SEARCH
)) {
3353 if (stv090x_chk_tmg(state
))
3354 lock
= stv090x_sw_algo(state
);
3359 signal_state
= stv090x_get_sig_params(state
);
3361 if ((lock
) && (signal_state
== STV090x_RANGEOK
)) { /* signal within Range */
3362 stv090x_optimize_track(state
);
3364 if (state
->internal
->dev_ver
>= 0x20) {
3365 /* >= Cut 2.0 :release TS reset after
3366 * demod lock and optimized Tracking
3368 reg
= STV090x_READ_DEMOD(state
, TSCFGH
);
3369 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0); /* release merger reset */
3370 if (STV090x_WRITE_DEMOD(state
, TSCFGH
, reg
) < 0)
3375 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 1); /* merger reset */
3376 if (STV090x_WRITE_DEMOD(state
, TSCFGH
, reg
) < 0)
3379 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0); /* release merger reset */
3380 if (STV090x_WRITE_DEMOD(state
, TSCFGH
, reg
) < 0)
3384 lock
= stv090x_get_lock(state
, state
->FecTimeout
,
3387 if (state
->delsys
== STV090x_DVBS2
) {
3388 stv090x_set_s2rolloff(state
);
3390 reg
= STV090x_READ_DEMOD(state
, PDELCTRL2
);
3391 STV090x_SETFIELD_Px(reg
, RESET_UPKO_COUNT
, 1);
3392 if (STV090x_WRITE_DEMOD(state
, PDELCTRL2
, reg
) < 0)
3394 /* Reset DVBS2 packet delinator error counter */
3395 reg
= STV090x_READ_DEMOD(state
, PDELCTRL2
);
3396 STV090x_SETFIELD_Px(reg
, RESET_UPKO_COUNT
, 0);
3397 if (STV090x_WRITE_DEMOD(state
, PDELCTRL2
, reg
) < 0)
3400 if (STV090x_WRITE_DEMOD(state
, ERRCTRL1
, 0x67) < 0) /* PER */
3403 if (STV090x_WRITE_DEMOD(state
, ERRCTRL1
, 0x75) < 0)
3406 /* Reset the Total packet counter */
3407 if (STV090x_WRITE_DEMOD(state
, FBERCPT4
, 0x00) < 0)
3409 /* Reset the packet Error counter2 */
3410 if (STV090x_WRITE_DEMOD(state
, ERRCTRL2
, 0xc1) < 0)
3413 signal_state
= STV090x_NODATA
;
3414 stv090x_chk_signal(state
);
3417 return signal_state
;
3420 stv090x_i2c_gate_ctrl(state
, 0);
3422 dprintk(FE_ERROR
, 1, "I/O error");
3426 static int stv090x_set_pls(struct stv090x_state
*state
, u32 pls_code
)
3428 dprintk(FE_DEBUG
, 1, "Set Gold PLS code %d", pls_code
);
3429 if (STV090x_WRITE_DEMOD(state
, PLROOT0
, pls_code
& 0xff) < 0)
3431 if (STV090x_WRITE_DEMOD(state
, PLROOT1
, (pls_code
>> 8) & 0xff) < 0)
3433 if (STV090x_WRITE_DEMOD(state
, PLROOT2
, 0x04 | (pls_code
>> 16)) < 0)
3437 dprintk(FE_ERROR
, 1, "I/O error");
3441 static int stv090x_set_mis(struct stv090x_state
*state
, int mis
)
3445 if (mis
< 0 || mis
> 255) {
3446 dprintk(FE_DEBUG
, 1, "Disable MIS filtering");
3447 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
3448 STV090x_SETFIELD_Px(reg
, FILTER_EN_FIELD
, 0x00);
3449 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
3452 dprintk(FE_DEBUG
, 1, "Enable MIS filtering - %d", mis
);
3453 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
3454 STV090x_SETFIELD_Px(reg
, FILTER_EN_FIELD
, 0x01);
3455 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
3457 if (STV090x_WRITE_DEMOD(state
, ISIENTRY
, mis
) < 0)
3459 if (STV090x_WRITE_DEMOD(state
, ISIBITENA
, 0xff) < 0)
3464 dprintk(FE_ERROR
, 1, "I/O error");
3468 static enum dvbfe_search
stv090x_search(struct dvb_frontend
*fe
)
3470 struct stv090x_state
*state
= fe
->demodulator_priv
;
3471 struct dtv_frontend_properties
*props
= &fe
->dtv_property_cache
;
3473 if (props
->frequency
== 0)
3474 return DVBFE_ALGO_SEARCH_INVALID
;
3476 switch (props
->delivery_system
) {
3478 state
->delsys
= STV090x_DSS
;
3481 state
->delsys
= STV090x_DVBS1
;
3484 state
->delsys
= STV090x_DVBS2
;
3487 return DVBFE_ALGO_SEARCH_INVALID
;
3490 state
->frequency
= props
->frequency
;
3491 state
->srate
= props
->symbol_rate
;
3492 state
->search_mode
= STV090x_SEARCH_AUTO
;
3493 state
->algo
= STV090x_COLD_SEARCH
;
3494 state
->fec
= STV090x_PRERR
;
3495 if (state
->srate
> 10000000) {
3496 dprintk(FE_DEBUG
, 1, "Search range: 10 MHz");
3497 state
->search_range
= 10000000;
3499 dprintk(FE_DEBUG
, 1, "Search range: 5 MHz");
3500 state
->search_range
= 5000000;
3503 stv090x_set_pls(state
, props
->scrambling_sequence_index
);
3504 stv090x_set_mis(state
, props
->stream_id
);
3506 if (stv090x_algo(state
) == STV090x_RANGEOK
) {
3507 dprintk(FE_DEBUG
, 1, "Search success!");
3508 return DVBFE_ALGO_SEARCH_SUCCESS
;
3510 dprintk(FE_DEBUG
, 1, "Search failed!");
3511 return DVBFE_ALGO_SEARCH_FAILED
;
3514 return DVBFE_ALGO_SEARCH_ERROR
;
3517 static int stv090x_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
3519 struct stv090x_state
*state
= fe
->demodulator_priv
;
3525 dstatus
= STV090x_READ_DEMOD(state
, DSTATUS
);
3526 if (STV090x_GETFIELD_Px(dstatus
, CAR_LOCK_FIELD
))
3527 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
;
3529 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
3530 search_state
= STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
);
3532 switch (search_state
) {
3533 case 0: /* searching */
3534 case 1: /* first PLH detected */
3536 dprintk(FE_DEBUG
, 1, "Status: Unlocked (Searching ..)");
3539 case 2: /* DVB-S2 mode */
3540 dprintk(FE_DEBUG
, 1, "Delivery system: DVB-S2");
3541 if (STV090x_GETFIELD_Px(dstatus
, LOCK_DEFINITIF_FIELD
)) {
3542 reg
= STV090x_READ_DEMOD(state
, PDELSTATUS1
);
3543 if (STV090x_GETFIELD_Px(reg
, PKTDELIN_LOCK_FIELD
)) {
3544 *status
|= FE_HAS_VITERBI
;
3545 reg
= STV090x_READ_DEMOD(state
, TSSTATUS
);
3546 if (STV090x_GETFIELD_Px(reg
, TSFIFO_LINEOK_FIELD
))
3547 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
3552 case 3: /* DVB-S1/legacy mode */
3553 dprintk(FE_DEBUG
, 1, "Delivery system: DVB-S");
3554 if (STV090x_GETFIELD_Px(dstatus
, LOCK_DEFINITIF_FIELD
)) {
3555 reg
= STV090x_READ_DEMOD(state
, VSTATUSVIT
);
3556 if (STV090x_GETFIELD_Px(reg
, LOCKEDVIT_FIELD
)) {
3557 *status
|= FE_HAS_VITERBI
;
3558 reg
= STV090x_READ_DEMOD(state
, TSSTATUS
);
3559 if (STV090x_GETFIELD_Px(reg
, TSFIFO_LINEOK_FIELD
))
3560 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
3569 static int stv090x_read_per(struct dvb_frontend
*fe
, u32
*per
)
3571 struct stv090x_state
*state
= fe
->demodulator_priv
;
3573 s32 count_4
, count_3
, count_2
, count_1
, count_0
, count
;
3575 enum fe_status status
;
3577 stv090x_read_status(fe
, &status
);
3578 if (!(status
& FE_HAS_LOCK
)) {
3579 *per
= 1 << 23; /* Max PER */
3582 reg
= STV090x_READ_DEMOD(state
, ERRCNT22
);
3583 h
= STV090x_GETFIELD_Px(reg
, ERR_CNT2_FIELD
);
3585 reg
= STV090x_READ_DEMOD(state
, ERRCNT21
);
3586 m
= STV090x_GETFIELD_Px(reg
, ERR_CNT21_FIELD
);
3588 reg
= STV090x_READ_DEMOD(state
, ERRCNT20
);
3589 l
= STV090x_GETFIELD_Px(reg
, ERR_CNT20_FIELD
);
3591 *per
= ((h
<< 16) | (m
<< 8) | l
);
3593 count_4
= STV090x_READ_DEMOD(state
, FBERCPT4
);
3594 count_3
= STV090x_READ_DEMOD(state
, FBERCPT3
);
3595 count_2
= STV090x_READ_DEMOD(state
, FBERCPT2
);
3596 count_1
= STV090x_READ_DEMOD(state
, FBERCPT1
);
3597 count_0
= STV090x_READ_DEMOD(state
, FBERCPT0
);
3599 if ((!count_4
) && (!count_3
)) {
3600 count
= (count_2
& 0xff) << 16;
3601 count
|= (count_1
& 0xff) << 8;
3602 count
|= count_0
& 0xff;
3609 if (STV090x_WRITE_DEMOD(state
, FBERCPT4
, 0) < 0)
3611 if (STV090x_WRITE_DEMOD(state
, ERRCTRL2
, 0xc1) < 0)
3616 dprintk(FE_ERROR
, 1, "I/O error");
3620 static int stv090x_table_lookup(const struct stv090x_tab
*tab
, int max
, int val
)
3625 if ((val
>= tab
[min
].read
&& val
< tab
[max
].read
) ||
3626 (val
>= tab
[max
].read
&& val
< tab
[min
].read
)) {
3627 while ((max
- min
) > 1) {
3628 med
= (max
+ min
) / 2;
3629 if ((val
>= tab
[min
].read
&& val
< tab
[med
].read
) ||
3630 (val
>= tab
[med
].read
&& val
< tab
[min
].read
))
3635 res
= ((val
- tab
[min
].read
) *
3636 (tab
[max
].real
- tab
[min
].real
) /
3637 (tab
[max
].read
- tab
[min
].read
)) +
3640 if (tab
[min
].read
< tab
[max
].read
) {
3641 if (val
< tab
[min
].read
)
3642 res
= tab
[min
].real
;
3643 else if (val
>= tab
[max
].read
)
3644 res
= tab
[max
].real
;
3646 if (val
>= tab
[min
].read
)
3647 res
= tab
[min
].real
;
3648 else if (val
< tab
[max
].read
)
3649 res
= tab
[max
].real
;
3656 static int stv090x_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
3658 struct stv090x_state
*state
= fe
->demodulator_priv
;
3660 s32 agc_0
, agc_1
, agc
;
3663 reg
= STV090x_READ_DEMOD(state
, AGCIQIN1
);
3664 agc_1
= STV090x_GETFIELD_Px(reg
, AGCIQ_VALUE_FIELD
);
3665 reg
= STV090x_READ_DEMOD(state
, AGCIQIN0
);
3666 agc_0
= STV090x_GETFIELD_Px(reg
, AGCIQ_VALUE_FIELD
);
3667 agc
= MAKEWORD16(agc_1
, agc_0
);
3669 str
= stv090x_table_lookup(stv090x_rf_tab
,
3670 ARRAY_SIZE(stv090x_rf_tab
) - 1, agc
);
3671 if (agc
> stv090x_rf_tab
[0].read
)
3673 else if (agc
< stv090x_rf_tab
[ARRAY_SIZE(stv090x_rf_tab
) - 1].read
)
3675 *strength
= (str
+ 100) * 0xFFFF / 100;
3680 static int stv090x_read_cnr(struct dvb_frontend
*fe
, u16
*cnr
)
3682 struct stv090x_state
*state
= fe
->demodulator_priv
;
3683 u32 reg_0
, reg_1
, reg
, i
;
3684 s32 val_0
, val_1
, val
= 0;
3689 switch (state
->delsys
) {
3691 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
3692 lock_f
= STV090x_GETFIELD_Px(reg
, LOCK_DEFINITIF_FIELD
);
3695 for (i
= 0; i
< 16; i
++) {
3696 reg_1
= STV090x_READ_DEMOD(state
, NNOSPLHT1
);
3697 val_1
= STV090x_GETFIELD_Px(reg_1
, NOSPLHT_NORMED_FIELD
);
3698 reg_0
= STV090x_READ_DEMOD(state
, NNOSPLHT0
);
3699 val_0
= STV090x_GETFIELD_Px(reg_0
, NOSPLHT_NORMED_FIELD
);
3700 val
+= MAKEWORD16(val_1
, val_0
);
3704 last
= ARRAY_SIZE(stv090x_s2cn_tab
) - 1;
3705 div
= stv090x_s2cn_tab
[last
].real
-
3706 stv090x_s2cn_tab
[3].real
;
3707 val
= stv090x_table_lookup(stv090x_s2cn_tab
, last
, val
);
3710 *cnr
= val
* 0xFFFF / div
;
3716 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
3717 lock_f
= STV090x_GETFIELD_Px(reg
, LOCK_DEFINITIF_FIELD
);
3720 for (i
= 0; i
< 16; i
++) {
3721 reg_1
= STV090x_READ_DEMOD(state
, NOSDATAT1
);
3722 val_1
= STV090x_GETFIELD_Px(reg_1
, NOSDATAT_UNNORMED_FIELD
);
3723 reg_0
= STV090x_READ_DEMOD(state
, NOSDATAT0
);
3724 val_0
= STV090x_GETFIELD_Px(reg_0
, NOSDATAT_UNNORMED_FIELD
);
3725 val
+= MAKEWORD16(val_1
, val_0
);
3729 last
= ARRAY_SIZE(stv090x_s1cn_tab
) - 1;
3730 div
= stv090x_s1cn_tab
[last
].real
-
3731 stv090x_s1cn_tab
[0].real
;
3732 val
= stv090x_table_lookup(stv090x_s1cn_tab
, last
, val
);
3733 *cnr
= val
* 0xFFFF / div
;
3743 static int stv090x_set_tone(struct dvb_frontend
*fe
, enum fe_sec_tone_mode tone
)
3745 struct stv090x_state
*state
= fe
->demodulator_priv
;
3748 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3751 STV090x_SETFIELD_Px(reg
, DISTX_MODE_FIELD
, 0);
3752 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 1);
3753 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3755 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 0);
3756 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3761 STV090x_SETFIELD_Px(reg
, DISTX_MODE_FIELD
, 0);
3762 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 1);
3763 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3772 dprintk(FE_ERROR
, 1, "I/O error");
3777 static enum dvbfe_algo
stv090x_frontend_algo(struct dvb_frontend
*fe
)
3779 return DVBFE_ALGO_CUSTOM
;
3782 static int stv090x_send_diseqc_msg(struct dvb_frontend
*fe
, struct dvb_diseqc_master_cmd
*cmd
)
3784 struct stv090x_state
*state
= fe
->demodulator_priv
;
3785 u32 reg
, idle
= 0, fifo_full
= 1;
3788 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3790 STV090x_SETFIELD_Px(reg
, DISTX_MODE_FIELD
,
3791 (state
->config
->diseqc_envelope_mode
) ? 4 : 2);
3792 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 1);
3793 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3795 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 0);
3796 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3799 STV090x_SETFIELD_Px(reg
, DIS_PRECHARGE_FIELD
, 1);
3800 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3803 for (i
= 0; i
< cmd
->msg_len
; i
++) {
3806 reg
= STV090x_READ_DEMOD(state
, DISTXSTATUS
);
3807 fifo_full
= STV090x_GETFIELD_Px(reg
, FIFO_FULL_FIELD
);
3810 if (STV090x_WRITE_DEMOD(state
, DISTXDATA
, cmd
->msg
[i
]) < 0)
3813 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3814 STV090x_SETFIELD_Px(reg
, DIS_PRECHARGE_FIELD
, 0);
3815 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3820 while ((!idle
) && (i
< 10)) {
3821 reg
= STV090x_READ_DEMOD(state
, DISTXSTATUS
);
3822 idle
= STV090x_GETFIELD_Px(reg
, TX_IDLE_FIELD
);
3829 dprintk(FE_ERROR
, 1, "I/O error");
3833 static int stv090x_send_diseqc_burst(struct dvb_frontend
*fe
,
3834 enum fe_sec_mini_cmd burst
)
3836 struct stv090x_state
*state
= fe
->demodulator_priv
;
3837 u32 reg
, idle
= 0, fifo_full
= 1;
3841 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3843 if (burst
== SEC_MINI_A
) {
3844 mode
= (state
->config
->diseqc_envelope_mode
) ? 5 : 3;
3847 mode
= (state
->config
->diseqc_envelope_mode
) ? 4 : 2;
3851 STV090x_SETFIELD_Px(reg
, DISTX_MODE_FIELD
, mode
);
3852 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 1);
3853 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3855 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 0);
3856 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3859 STV090x_SETFIELD_Px(reg
, DIS_PRECHARGE_FIELD
, 1);
3860 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3864 reg
= STV090x_READ_DEMOD(state
, DISTXSTATUS
);
3865 fifo_full
= STV090x_GETFIELD_Px(reg
, FIFO_FULL_FIELD
);
3868 if (STV090x_WRITE_DEMOD(state
, DISTXDATA
, value
) < 0)
3871 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3872 STV090x_SETFIELD_Px(reg
, DIS_PRECHARGE_FIELD
, 0);
3873 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3878 while ((!idle
) && (i
< 10)) {
3879 reg
= STV090x_READ_DEMOD(state
, DISTXSTATUS
);
3880 idle
= STV090x_GETFIELD_Px(reg
, TX_IDLE_FIELD
);
3887 dprintk(FE_ERROR
, 1, "I/O error");
3891 static int stv090x_recv_slave_reply(struct dvb_frontend
*fe
, struct dvb_diseqc_slave_reply
*reply
)
3893 struct stv090x_state
*state
= fe
->demodulator_priv
;
3894 u32 reg
= 0, i
= 0, rx_end
= 0;
3896 while ((rx_end
!= 1) && (i
< 10)) {
3899 reg
= STV090x_READ_DEMOD(state
, DISRX_ST0
);
3900 rx_end
= STV090x_GETFIELD_Px(reg
, RX_END_FIELD
);
3904 reply
->msg_len
= STV090x_GETFIELD_Px(reg
, FIFO_BYTENBR_FIELD
);
3905 for (i
= 0; i
< reply
->msg_len
; i
++)
3906 reply
->msg
[i
] = STV090x_READ_DEMOD(state
, DISRXDATA
);
3912 static int stv090x_sleep(struct dvb_frontend
*fe
)
3914 struct stv090x_state
*state
= fe
->demodulator_priv
;
3916 u8 full_standby
= 0;
3918 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
3921 if (state
->config
->tuner_sleep
) {
3922 if (state
->config
->tuner_sleep(fe
) < 0)
3926 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
3929 dprintk(FE_DEBUG
, 1, "Set %s(%d) to sleep",
3930 state
->device
== STV0900
? "STV0900" : "STV0903",
3933 mutex_lock(&state
->internal
->demod_lock
);
3935 switch (state
->demod
) {
3936 case STV090x_DEMODULATOR_0
:
3937 /* power off ADC 1 */
3938 reg
= stv090x_read_reg(state
, STV090x_TSTTNR1
);
3939 STV090x_SETFIELD(reg
, ADC1_PON_FIELD
, 0);
3940 if (stv090x_write_reg(state
, STV090x_TSTTNR1
, reg
) < 0)
3942 /* power off DiSEqC 1 */
3943 reg
= stv090x_read_reg(state
, STV090x_TSTTNR2
);
3944 STV090x_SETFIELD(reg
, DISEQC1_PON_FIELD
, 0);
3945 if (stv090x_write_reg(state
, STV090x_TSTTNR2
, reg
) < 0)
3948 /* check whether path 2 is already sleeping, that is when
3950 reg
= stv090x_read_reg(state
, STV090x_TSTTNR3
);
3951 if (STV090x_GETFIELD(reg
, ADC2_PON_FIELD
) == 0)
3955 reg
= stv090x_read_reg(state
, STV090x_STOPCLK1
);
3956 /* packet delineator 1 clock */
3957 STV090x_SETFIELD(reg
, STOP_CLKPKDT1_FIELD
, 1);
3959 STV090x_SETFIELD(reg
, STOP_CLKADCI1_FIELD
, 1);
3960 /* FEC clock is shared between the two paths, only stop it
3961 when full standby is possible */
3963 STV090x_SETFIELD(reg
, STOP_CLKFEC_FIELD
, 1);
3964 if (stv090x_write_reg(state
, STV090x_STOPCLK1
, reg
) < 0)
3966 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
3967 /* sampling 1 clock */
3968 STV090x_SETFIELD(reg
, STOP_CLKSAMP1_FIELD
, 1);
3969 /* viterbi 1 clock */
3970 STV090x_SETFIELD(reg
, STOP_CLKVIT1_FIELD
, 1);
3971 /* TS clock is shared between the two paths, only stop it
3972 when full standby is possible */
3974 STV090x_SETFIELD(reg
, STOP_CLKTS_FIELD
, 1);
3975 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
3979 case STV090x_DEMODULATOR_1
:
3980 /* power off ADC 2 */
3981 reg
= stv090x_read_reg(state
, STV090x_TSTTNR3
);
3982 STV090x_SETFIELD(reg
, ADC2_PON_FIELD
, 0);
3983 if (stv090x_write_reg(state
, STV090x_TSTTNR3
, reg
) < 0)
3985 /* power off DiSEqC 2 */
3986 reg
= stv090x_read_reg(state
, STV090x_TSTTNR4
);
3987 STV090x_SETFIELD(reg
, DISEQC2_PON_FIELD
, 0);
3988 if (stv090x_write_reg(state
, STV090x_TSTTNR4
, reg
) < 0)
3991 /* check whether path 1 is already sleeping, that is when
3993 reg
= stv090x_read_reg(state
, STV090x_TSTTNR1
);
3994 if (STV090x_GETFIELD(reg
, ADC1_PON_FIELD
) == 0)
3998 reg
= stv090x_read_reg(state
, STV090x_STOPCLK1
);
3999 /* packet delineator 2 clock */
4000 STV090x_SETFIELD(reg
, STOP_CLKPKDT2_FIELD
, 1);
4002 STV090x_SETFIELD(reg
, STOP_CLKADCI2_FIELD
, 1);
4003 /* FEC clock is shared between the two paths, only stop it
4004 when full standby is possible */
4006 STV090x_SETFIELD(reg
, STOP_CLKFEC_FIELD
, 1);
4007 if (stv090x_write_reg(state
, STV090x_STOPCLK1
, reg
) < 0)
4009 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
4010 /* sampling 2 clock */
4011 STV090x_SETFIELD(reg
, STOP_CLKSAMP2_FIELD
, 1);
4012 /* viterbi 2 clock */
4013 STV090x_SETFIELD(reg
, STOP_CLKVIT2_FIELD
, 1);
4014 /* TS clock is shared between the two paths, only stop it
4015 when full standby is possible */
4017 STV090x_SETFIELD(reg
, STOP_CLKTS_FIELD
, 1);
4018 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
4023 dprintk(FE_ERROR
, 1, "Wrong demodulator!");
4028 /* general power off */
4029 reg
= stv090x_read_reg(state
, STV090x_SYNTCTRL
);
4030 STV090x_SETFIELD(reg
, STANDBY_FIELD
, 0x01);
4031 if (stv090x_write_reg(state
, STV090x_SYNTCTRL
, reg
) < 0)
4035 mutex_unlock(&state
->internal
->demod_lock
);
4039 stv090x_i2c_gate_ctrl(state
, 0);
4042 mutex_unlock(&state
->internal
->demod_lock
);
4044 dprintk(FE_ERROR
, 1, "I/O error");
4048 static int stv090x_wakeup(struct dvb_frontend
*fe
)
4050 struct stv090x_state
*state
= fe
->demodulator_priv
;
4053 dprintk(FE_DEBUG
, 1, "Wake %s(%d) from standby",
4054 state
->device
== STV0900
? "STV0900" : "STV0903",
4057 mutex_lock(&state
->internal
->demod_lock
);
4059 /* general power on */
4060 reg
= stv090x_read_reg(state
, STV090x_SYNTCTRL
);
4061 STV090x_SETFIELD(reg
, STANDBY_FIELD
, 0x00);
4062 if (stv090x_write_reg(state
, STV090x_SYNTCTRL
, reg
) < 0)
4065 switch (state
->demod
) {
4066 case STV090x_DEMODULATOR_0
:
4067 /* power on ADC 1 */
4068 reg
= stv090x_read_reg(state
, STV090x_TSTTNR1
);
4069 STV090x_SETFIELD(reg
, ADC1_PON_FIELD
, 1);
4070 if (stv090x_write_reg(state
, STV090x_TSTTNR1
, reg
) < 0)
4072 /* power on DiSEqC 1 */
4073 reg
= stv090x_read_reg(state
, STV090x_TSTTNR2
);
4074 STV090x_SETFIELD(reg
, DISEQC1_PON_FIELD
, 1);
4075 if (stv090x_write_reg(state
, STV090x_TSTTNR2
, reg
) < 0)
4078 /* activate clocks */
4079 reg
= stv090x_read_reg(state
, STV090x_STOPCLK1
);
4080 /* packet delineator 1 clock */
4081 STV090x_SETFIELD(reg
, STOP_CLKPKDT1_FIELD
, 0);
4083 STV090x_SETFIELD(reg
, STOP_CLKADCI1_FIELD
, 0);
4085 STV090x_SETFIELD(reg
, STOP_CLKFEC_FIELD
, 0);
4086 if (stv090x_write_reg(state
, STV090x_STOPCLK1
, reg
) < 0)
4088 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
4089 /* sampling 1 clock */
4090 STV090x_SETFIELD(reg
, STOP_CLKSAMP1_FIELD
, 0);
4091 /* viterbi 1 clock */
4092 STV090x_SETFIELD(reg
, STOP_CLKVIT1_FIELD
, 0);
4094 STV090x_SETFIELD(reg
, STOP_CLKTS_FIELD
, 0);
4095 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
4099 case STV090x_DEMODULATOR_1
:
4100 /* power on ADC 2 */
4101 reg
= stv090x_read_reg(state
, STV090x_TSTTNR3
);
4102 STV090x_SETFIELD(reg
, ADC2_PON_FIELD
, 1);
4103 if (stv090x_write_reg(state
, STV090x_TSTTNR3
, reg
) < 0)
4105 /* power on DiSEqC 2 */
4106 reg
= stv090x_read_reg(state
, STV090x_TSTTNR4
);
4107 STV090x_SETFIELD(reg
, DISEQC2_PON_FIELD
, 1);
4108 if (stv090x_write_reg(state
, STV090x_TSTTNR4
, reg
) < 0)
4111 /* activate clocks */
4112 reg
= stv090x_read_reg(state
, STV090x_STOPCLK1
);
4113 /* packet delineator 2 clock */
4114 STV090x_SETFIELD(reg
, STOP_CLKPKDT2_FIELD
, 0);
4116 STV090x_SETFIELD(reg
, STOP_CLKADCI2_FIELD
, 0);
4118 STV090x_SETFIELD(reg
, STOP_CLKFEC_FIELD
, 0);
4119 if (stv090x_write_reg(state
, STV090x_STOPCLK1
, reg
) < 0)
4121 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
4122 /* sampling 2 clock */
4123 STV090x_SETFIELD(reg
, STOP_CLKSAMP2_FIELD
, 0);
4124 /* viterbi 2 clock */
4125 STV090x_SETFIELD(reg
, STOP_CLKVIT2_FIELD
, 0);
4127 STV090x_SETFIELD(reg
, STOP_CLKTS_FIELD
, 0);
4128 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
4133 dprintk(FE_ERROR
, 1, "Wrong demodulator!");
4137 mutex_unlock(&state
->internal
->demod_lock
);
4140 mutex_unlock(&state
->internal
->demod_lock
);
4141 dprintk(FE_ERROR
, 1, "I/O error");
4145 static void stv090x_release(struct dvb_frontend
*fe
)
4147 struct stv090x_state
*state
= fe
->demodulator_priv
;
4149 state
->internal
->num_used
--;
4150 if (state
->internal
->num_used
<= 0) {
4152 dprintk(FE_ERROR
, 1, "Actually removing");
4154 remove_dev(state
->internal
);
4155 kfree(state
->internal
);
4161 static int stv090x_ldpc_mode(struct stv090x_state
*state
, enum stv090x_mode ldpc_mode
)
4165 reg
= stv090x_read_reg(state
, STV090x_GENCFG
);
4167 switch (ldpc_mode
) {
4170 if ((state
->demod_mode
!= STV090x_DUAL
) || (STV090x_GETFIELD(reg
, DDEMOD_FIELD
) != 1)) {
4171 /* set LDPC to dual mode */
4172 if (stv090x_write_reg(state
, STV090x_GENCFG
, 0x1d) < 0)
4175 state
->demod_mode
= STV090x_DUAL
;
4177 reg
= stv090x_read_reg(state
, STV090x_TSTRES0
);
4178 STV090x_SETFIELD(reg
, FRESFEC_FIELD
, 0x1);
4179 if (stv090x_write_reg(state
, STV090x_TSTRES0
, reg
) < 0)
4181 STV090x_SETFIELD(reg
, FRESFEC_FIELD
, 0x0);
4182 if (stv090x_write_reg(state
, STV090x_TSTRES0
, reg
) < 0)
4185 if (STV090x_WRITE_DEMOD(state
, MODCODLST0
, 0xff) < 0)
4187 if (STV090x_WRITE_DEMOD(state
, MODCODLST1
, 0xff) < 0)
4189 if (STV090x_WRITE_DEMOD(state
, MODCODLST2
, 0xff) < 0)
4191 if (STV090x_WRITE_DEMOD(state
, MODCODLST3
, 0xff) < 0)
4193 if (STV090x_WRITE_DEMOD(state
, MODCODLST4
, 0xff) < 0)
4195 if (STV090x_WRITE_DEMOD(state
, MODCODLST5
, 0xff) < 0)
4197 if (STV090x_WRITE_DEMOD(state
, MODCODLST6
, 0xff) < 0)
4200 if (STV090x_WRITE_DEMOD(state
, MODCODLST7
, 0xcc) < 0)
4202 if (STV090x_WRITE_DEMOD(state
, MODCODLST8
, 0xcc) < 0)
4204 if (STV090x_WRITE_DEMOD(state
, MODCODLST9
, 0xcc) < 0)
4206 if (STV090x_WRITE_DEMOD(state
, MODCODLSTA
, 0xcc) < 0)
4208 if (STV090x_WRITE_DEMOD(state
, MODCODLSTB
, 0xcc) < 0)
4210 if (STV090x_WRITE_DEMOD(state
, MODCODLSTC
, 0xcc) < 0)
4212 if (STV090x_WRITE_DEMOD(state
, MODCODLSTD
, 0xcc) < 0)
4215 if (STV090x_WRITE_DEMOD(state
, MODCODLSTE
, 0xff) < 0)
4217 if (STV090x_WRITE_DEMOD(state
, MODCODLSTF
, 0xcf) < 0)
4222 case STV090x_SINGLE
:
4223 if (stv090x_stop_modcod(state
) < 0)
4225 if (stv090x_activate_modcod_single(state
) < 0)
4228 if (state
->demod
== STV090x_DEMODULATOR_1
) {
4229 if (stv090x_write_reg(state
, STV090x_GENCFG
, 0x06) < 0) /* path 2 */
4232 if (stv090x_write_reg(state
, STV090x_GENCFG
, 0x04) < 0) /* path 1 */
4236 reg
= stv090x_read_reg(state
, STV090x_TSTRES0
);
4237 STV090x_SETFIELD(reg
, FRESFEC_FIELD
, 0x1);
4238 if (stv090x_write_reg(state
, STV090x_TSTRES0
, reg
) < 0)
4240 STV090x_SETFIELD(reg
, FRESFEC_FIELD
, 0x0);
4241 if (stv090x_write_reg(state
, STV090x_TSTRES0
, reg
) < 0)
4244 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
4245 STV090x_SETFIELD_Px(reg
, ALGOSWRST_FIELD
, 0x01);
4246 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
4248 STV090x_SETFIELD_Px(reg
, ALGOSWRST_FIELD
, 0x00);
4249 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
4256 dprintk(FE_ERROR
, 1, "I/O error");
4260 /* return (Hz), clk in Hz*/
4261 static u32
stv090x_get_mclk(struct stv090x_state
*state
)
4263 const struct stv090x_config
*config
= state
->config
;
4267 div
= stv090x_read_reg(state
, STV090x_NCOARSE
);
4268 reg
= stv090x_read_reg(state
, STV090x_SYNTCTRL
);
4269 ratio
= STV090x_GETFIELD(reg
, SELX1RATIO_FIELD
) ? 4 : 6;
4271 return (div
+ 1) * config
->xtal
/ ratio
; /* kHz */
4274 static int stv090x_set_mclk(struct stv090x_state
*state
, u32 mclk
, u32 clk
)
4276 const struct stv090x_config
*config
= state
->config
;
4277 u32 reg
, div
, clk_sel
;
4279 reg
= stv090x_read_reg(state
, STV090x_SYNTCTRL
);
4280 clk_sel
= ((STV090x_GETFIELD(reg
, SELX1RATIO_FIELD
) == 1) ? 4 : 6);
4282 div
= ((clk_sel
* mclk
) / config
->xtal
) - 1;
4284 reg
= stv090x_read_reg(state
, STV090x_NCOARSE
);
4285 STV090x_SETFIELD(reg
, M_DIV_FIELD
, div
);
4286 if (stv090x_write_reg(state
, STV090x_NCOARSE
, reg
) < 0)
4289 state
->internal
->mclk
= stv090x_get_mclk(state
);
4291 /*Set the DiseqC frequency to 22KHz */
4292 div
= state
->internal
->mclk
/ 704000;
4293 if (STV090x_WRITE_DEMOD(state
, F22TX
, div
) < 0)
4295 if (STV090x_WRITE_DEMOD(state
, F22RX
, div
) < 0)
4300 dprintk(FE_ERROR
, 1, "I/O error");
4304 static int stv0900_set_tspath(struct stv090x_state
*state
)
4308 if (state
->internal
->dev_ver
>= 0x20) {
4309 switch (state
->config
->ts1_mode
) {
4310 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4311 case STV090x_TSMODE_DVBCI
:
4312 switch (state
->config
->ts2_mode
) {
4313 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4314 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4316 stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x00);
4319 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4320 case STV090x_TSMODE_DVBCI
:
4321 if (stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x06) < 0) /* Mux'd stream mode */
4323 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4324 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4325 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4327 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGM
);
4328 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4329 if (stv090x_write_reg(state
, STV090x_P2_TSCFGM
, reg
) < 0)
4331 if (stv090x_write_reg(state
, STV090x_P1_TSSPEED
, 0x14) < 0)
4333 if (stv090x_write_reg(state
, STV090x_P2_TSSPEED
, 0x28) < 0)
4339 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4340 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4342 switch (state
->config
->ts2_mode
) {
4343 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4344 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4346 if (stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x0c) < 0)
4350 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4351 case STV090x_TSMODE_DVBCI
:
4352 if (stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x0a) < 0)
4359 switch (state
->config
->ts1_mode
) {
4360 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4361 case STV090x_TSMODE_DVBCI
:
4362 switch (state
->config
->ts2_mode
) {
4363 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4364 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4366 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x10);
4369 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4370 case STV090x_TSMODE_DVBCI
:
4371 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x16);
4372 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4373 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4374 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4376 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4377 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 0);
4378 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4380 if (stv090x_write_reg(state
, STV090x_P1_TSSPEED
, 0x14) < 0)
4382 if (stv090x_write_reg(state
, STV090x_P2_TSSPEED
, 0x28) < 0)
4388 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4389 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4391 switch (state
->config
->ts2_mode
) {
4392 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4393 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4395 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x14);
4398 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4399 case STV090x_TSMODE_DVBCI
:
4400 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x12);
4407 switch (state
->config
->ts1_mode
) {
4408 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4409 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4410 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts1_tei
);
4411 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4412 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4413 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4417 case STV090x_TSMODE_DVBCI
:
4418 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4419 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts1_tei
);
4420 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4421 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4422 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4426 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4427 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4428 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts1_tei
);
4429 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4430 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4431 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4435 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4436 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4437 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts1_tei
);
4438 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4439 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4440 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4448 switch (state
->config
->ts2_mode
) {
4449 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4450 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4451 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts2_tei
);
4452 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4453 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4454 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4458 case STV090x_TSMODE_DVBCI
:
4459 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4460 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts2_tei
);
4461 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4462 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4463 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4467 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4468 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4469 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts2_tei
);
4470 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4471 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4472 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4476 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4477 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4478 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts2_tei
);
4479 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4480 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4481 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4489 if (state
->config
->ts1_clk
> 0) {
4492 switch (state
->config
->ts1_mode
) {
4493 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4494 case STV090x_TSMODE_DVBCI
:
4496 speed
= state
->internal
->mclk
/
4497 (state
->config
->ts1_clk
/ 4);
4503 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4504 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4505 speed
= state
->internal
->mclk
/
4506 (state
->config
->ts1_clk
/ 32);
4513 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4514 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4515 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4517 if (stv090x_write_reg(state
, STV090x_P1_TSSPEED
, speed
) < 0)
4521 if (state
->config
->ts2_clk
> 0) {
4524 switch (state
->config
->ts2_mode
) {
4525 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4526 case STV090x_TSMODE_DVBCI
:
4528 speed
= state
->internal
->mclk
/
4529 (state
->config
->ts2_clk
/ 4);
4535 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4536 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4537 speed
= state
->internal
->mclk
/
4538 (state
->config
->ts2_clk
/ 32);
4545 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGM
);
4546 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4547 if (stv090x_write_reg(state
, STV090x_P2_TSCFGM
, reg
) < 0)
4549 if (stv090x_write_reg(state
, STV090x_P2_TSSPEED
, speed
) < 0)
4553 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4554 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x01);
4555 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4557 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x00);
4558 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4561 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4562 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x01);
4563 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4565 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x00);
4566 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4571 dprintk(FE_ERROR
, 1, "I/O error");
4575 static int stv0903_set_tspath(struct stv090x_state
*state
)
4579 if (state
->internal
->dev_ver
>= 0x20) {
4580 switch (state
->config
->ts1_mode
) {
4581 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4582 case STV090x_TSMODE_DVBCI
:
4583 stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x00);
4586 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4587 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4589 stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x0c);
4593 switch (state
->config
->ts1_mode
) {
4594 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4595 case STV090x_TSMODE_DVBCI
:
4596 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x10);
4599 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4600 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4602 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x14);
4607 switch (state
->config
->ts1_mode
) {
4608 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4609 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4610 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4611 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4612 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4616 case STV090x_TSMODE_DVBCI
:
4617 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4618 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4619 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4620 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4624 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4625 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4626 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4627 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4628 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4632 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4633 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4634 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4635 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4636 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4644 if (state
->config
->ts1_clk
> 0) {
4647 switch (state
->config
->ts1_mode
) {
4648 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4649 case STV090x_TSMODE_DVBCI
:
4651 speed
= state
->internal
->mclk
/
4652 (state
->config
->ts1_clk
/ 4);
4658 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4659 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4660 speed
= state
->internal
->mclk
/
4661 (state
->config
->ts1_clk
/ 32);
4668 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4669 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4670 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4672 if (stv090x_write_reg(state
, STV090x_P1_TSSPEED
, speed
) < 0)
4676 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4677 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x01);
4678 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4680 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x00);
4681 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4686 dprintk(FE_ERROR
, 1, "I/O error");
4690 static int stv090x_init(struct dvb_frontend
*fe
)
4692 struct stv090x_state
*state
= fe
->demodulator_priv
;
4693 const struct stv090x_config
*config
= state
->config
;
4696 if (state
->internal
->mclk
== 0) {
4697 /* call tuner init to configure the tuner's clock output
4698 divider directly before setting up the master clock of
4700 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
4703 if (config
->tuner_init
) {
4704 if (config
->tuner_init(fe
) < 0)
4708 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
4711 stv090x_set_mclk(state
, 135000000, config
->xtal
); /* 135 Mhz */
4713 if (stv090x_write_reg(state
, STV090x_SYNTCTRL
,
4714 0x20 | config
->clk_mode
) < 0)
4716 stv090x_get_mclk(state
);
4719 if (stv090x_wakeup(fe
) < 0) {
4720 dprintk(FE_ERROR
, 1, "Error waking device");
4724 if (stv090x_ldpc_mode(state
, state
->demod_mode
) < 0)
4727 reg
= STV090x_READ_DEMOD(state
, TNRCFG2
);
4728 STV090x_SETFIELD_Px(reg
, TUN_IQSWAP_FIELD
, state
->inversion
);
4729 if (STV090x_WRITE_DEMOD(state
, TNRCFG2
, reg
) < 0)
4731 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
4732 STV090x_SETFIELD_Px(reg
, ROLLOFF_CONTROL_FIELD
, state
->rolloff
);
4733 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
4736 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
4739 if (config
->tuner_set_mode
) {
4740 if (config
->tuner_set_mode(fe
, TUNER_WAKE
) < 0)
4744 if (config
->tuner_init
) {
4745 if (config
->tuner_init(fe
) < 0)
4749 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
4752 if (state
->device
== STV0900
) {
4753 if (stv0900_set_tspath(state
) < 0)
4756 if (stv0903_set_tspath(state
) < 0)
4763 stv090x_i2c_gate_ctrl(state
, 0);
4765 dprintk(FE_ERROR
, 1, "I/O error");
4769 static int stv090x_setup(struct dvb_frontend
*fe
)
4771 struct stv090x_state
*state
= fe
->demodulator_priv
;
4772 const struct stv090x_config
*config
= state
->config
;
4773 const struct stv090x_reg
*stv090x_initval
= NULL
;
4774 const struct stv090x_reg
*stv090x_cut20_val
= NULL
;
4775 unsigned long t1_size
= 0, t2_size
= 0;
4780 if (state
->device
== STV0900
) {
4781 dprintk(FE_DEBUG
, 1, "Initializing STV0900");
4782 stv090x_initval
= stv0900_initval
;
4783 t1_size
= ARRAY_SIZE(stv0900_initval
);
4784 stv090x_cut20_val
= stv0900_cut20_val
;
4785 t2_size
= ARRAY_SIZE(stv0900_cut20_val
);
4786 } else if (state
->device
== STV0903
) {
4787 dprintk(FE_DEBUG
, 1, "Initializing STV0903");
4788 stv090x_initval
= stv0903_initval
;
4789 t1_size
= ARRAY_SIZE(stv0903_initval
);
4790 stv090x_cut20_val
= stv0903_cut20_val
;
4791 t2_size
= ARRAY_SIZE(stv0903_cut20_val
);
4797 if (stv090x_write_reg(state
, STV090x_P1_DMDISTATE
, 0x5c) < 0)
4799 if (state
->device
== STV0900
)
4800 if (stv090x_write_reg(state
, STV090x_P2_DMDISTATE
, 0x5c) < 0)
4805 /* Set No Tuner Mode */
4806 if (stv090x_write_reg(state
, STV090x_P1_TNRCFG
, 0x6c) < 0)
4808 if (state
->device
== STV0900
)
4809 if (stv090x_write_reg(state
, STV090x_P2_TNRCFG
, 0x6c) < 0)
4812 /* I2C repeater OFF */
4813 STV090x_SETFIELD_Px(reg
, ENARPT_LEVEL_FIELD
, config
->repeater_level
);
4814 if (stv090x_write_reg(state
, STV090x_P1_I2CRPT
, reg
) < 0)
4816 if (state
->device
== STV0900
)
4817 if (stv090x_write_reg(state
, STV090x_P2_I2CRPT
, reg
) < 0)
4820 if (stv090x_write_reg(state
, STV090x_NCOARSE
, 0x13) < 0) /* set PLL divider */
4823 if (stv090x_write_reg(state
, STV090x_I2CCFG
, 0x08) < 0) /* 1/41 oversampling */
4825 if (stv090x_write_reg(state
, STV090x_SYNTCTRL
, 0x20 | config
->clk_mode
) < 0) /* enable PLL */
4830 dprintk(FE_DEBUG
, 1, "Setting up initial values");
4831 for (i
= 0; i
< t1_size
; i
++) {
4832 if (stv090x_write_reg(state
, stv090x_initval
[i
].addr
, stv090x_initval
[i
].data
) < 0)
4836 state
->internal
->dev_ver
= stv090x_read_reg(state
, STV090x_MID
);
4837 if (state
->internal
->dev_ver
>= 0x20) {
4838 if (stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x0c) < 0)
4841 /* write cut20_val*/
4842 dprintk(FE_DEBUG
, 1, "Setting up Cut 2.0 initial values");
4843 for (i
= 0; i
< t2_size
; i
++) {
4844 if (stv090x_write_reg(state
, stv090x_cut20_val
[i
].addr
, stv090x_cut20_val
[i
].data
) < 0)
4848 } else if (state
->internal
->dev_ver
< 0x20) {
4849 dprintk(FE_ERROR
, 1, "ERROR: Unsupported Cut: 0x%02x!",
4850 state
->internal
->dev_ver
);
4853 } else if (state
->internal
->dev_ver
> 0x30) {
4854 /* we shouldn't bail out from here */
4855 dprintk(FE_ERROR
, 1, "INFO: Cut: 0x%02x probably incomplete support!",
4856 state
->internal
->dev_ver
);
4860 reg
= stv090x_read_reg(state
, STV090x_TSTTNR1
);
4861 STV090x_SETFIELD(reg
, ADC1_INMODE_FIELD
,
4862 (config
->adc1_range
== STV090x_ADC_1Vpp
) ? 0 : 1);
4863 if (stv090x_write_reg(state
, STV090x_TSTTNR1
, reg
) < 0)
4867 reg
= stv090x_read_reg(state
, STV090x_TSTTNR3
);
4868 STV090x_SETFIELD(reg
, ADC2_INMODE_FIELD
,
4869 (config
->adc2_range
== STV090x_ADC_1Vpp
) ? 0 : 1);
4870 if (stv090x_write_reg(state
, STV090x_TSTTNR3
, reg
) < 0)
4873 if (stv090x_write_reg(state
, STV090x_TSTRES0
, 0x80) < 0)
4875 if (stv090x_write_reg(state
, STV090x_TSTRES0
, 0x00) < 0)
4880 dprintk(FE_ERROR
, 1, "I/O error");
4884 static int stv090x_set_gpio(struct dvb_frontend
*fe
, u8 gpio
, u8 dir
,
4885 u8 value
, u8 xor_value
)
4887 struct stv090x_state
*state
= fe
->demodulator_priv
;
4890 STV090x_SETFIELD(reg
, GPIOx_OPD_FIELD
, dir
);
4891 STV090x_SETFIELD(reg
, GPIOx_CONFIG_FIELD
, value
);
4892 STV090x_SETFIELD(reg
, GPIOx_XOR_FIELD
, xor_value
);
4894 return stv090x_write_reg(state
, STV090x_GPIOxCFG(gpio
), reg
);
4897 static int stv090x_setup_compound(struct stv090x_state
*state
)
4899 struct stv090x_dev
*temp_int
;
4901 temp_int
= find_dev(state
->i2c
,
4902 state
->config
->address
);
4904 if (temp_int
&& state
->demod_mode
== STV090x_DUAL
) {
4905 state
->internal
= temp_int
->internal
;
4906 state
->internal
->num_used
++;
4907 dprintk(FE_INFO
, 1, "Found Internal Structure!");
4909 state
->internal
= kmalloc(sizeof(*state
->internal
), GFP_KERNEL
);
4910 if (!state
->internal
)
4912 temp_int
= append_internal(state
->internal
);
4914 kfree(state
->internal
);
4917 state
->internal
->num_used
= 1;
4918 state
->internal
->mclk
= 0;
4919 state
->internal
->dev_ver
= 0;
4920 state
->internal
->i2c_adap
= state
->i2c
;
4921 state
->internal
->i2c_addr
= state
->config
->address
;
4922 dprintk(FE_INFO
, 1, "Create New Internal Structure!");
4924 mutex_init(&state
->internal
->demod_lock
);
4925 mutex_init(&state
->internal
->tuner_lock
);
4927 if (stv090x_setup(&state
->frontend
) < 0) {
4928 dprintk(FE_ERROR
, 1, "Error setting up device");
4933 if (state
->internal
->dev_ver
>= 0x30)
4934 state
->frontend
.ops
.info
.caps
|= FE_CAN_MULTISTREAM
;
4936 /* workaround for stuck DiSEqC output */
4937 if (state
->config
->diseqc_envelope_mode
)
4938 stv090x_send_diseqc_burst(&state
->frontend
, SEC_MINI_A
);
4940 state
->config
->set_gpio
= stv090x_set_gpio
;
4942 dprintk(FE_ERROR
, 1, "Probing %s demodulator(%d) Cut=0x%02x",
4943 state
->device
== STV0900
? "STV0900" : "STV0903",
4944 state
->config
->demod
,
4945 state
->internal
->dev_ver
);
4952 remove_dev(state
->internal
);
4953 kfree(state
->internal
);
4957 static const struct dvb_frontend_ops stv090x_ops
= {
4958 .delsys
= { SYS_DVBS
, SYS_DVBS2
, SYS_DSS
},
4960 .name
= "STV090x Multistandard",
4961 .frequency_min_hz
= 950 * MHz
,
4962 .frequency_max_hz
= 2150 * MHz
,
4963 .symbol_rate_min
= 1000000,
4964 .symbol_rate_max
= 45000000,
4965 .caps
= FE_CAN_INVERSION_AUTO
|
4968 FE_CAN_2G_MODULATION
4971 .release
= stv090x_release
,
4972 .init
= stv090x_init
,
4974 .sleep
= stv090x_sleep
,
4975 .get_frontend_algo
= stv090x_frontend_algo
,
4977 .diseqc_send_master_cmd
= stv090x_send_diseqc_msg
,
4978 .diseqc_send_burst
= stv090x_send_diseqc_burst
,
4979 .diseqc_recv_slave_reply
= stv090x_recv_slave_reply
,
4980 .set_tone
= stv090x_set_tone
,
4982 .search
= stv090x_search
,
4983 .read_status
= stv090x_read_status
,
4984 .read_ber
= stv090x_read_per
,
4985 .read_signal_strength
= stv090x_read_signal_strength
,
4986 .read_snr
= stv090x_read_cnr
,
4989 static struct dvb_frontend
*stv090x_get_dvb_frontend(struct i2c_client
*client
)
4991 struct stv090x_state
*state
= i2c_get_clientdata(client
);
4993 dev_dbg(&client
->dev
, "\n");
4995 return &state
->frontend
;
4998 static int stv090x_probe(struct i2c_client
*client
)
5001 struct stv090x_config
*config
= client
->dev
.platform_data
;
5003 struct stv090x_state
*state
= NULL
;
5005 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
5011 state
->verbose
= &verbose
;
5012 state
->config
= config
;
5013 state
->i2c
= client
->adapter
;
5014 state
->frontend
.ops
= stv090x_ops
;
5015 state
->frontend
.demodulator_priv
= state
;
5016 state
->demod
= config
->demod
;
5017 /* Single or Dual mode */
5018 state
->demod_mode
= config
->demod_mode
;
5019 state
->device
= config
->device
;
5021 state
->rolloff
= STV090x_RO_35
;
5023 ret
= stv090x_setup_compound(state
);
5027 i2c_set_clientdata(client
, state
);
5029 /* setup callbacks */
5030 config
->get_dvb_frontend
= stv090x_get_dvb_frontend
;
5039 static void stv090x_remove(struct i2c_client
*client
)
5041 struct stv090x_state
*state
= i2c_get_clientdata(client
);
5043 stv090x_release(&state
->frontend
);
5046 struct dvb_frontend
*stv090x_attach(struct stv090x_config
*config
,
5047 struct i2c_adapter
*i2c
,
5048 enum stv090x_demodulator demod
)
5051 struct stv090x_state
*state
= NULL
;
5053 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
5057 state
->verbose
= &verbose
;
5058 state
->config
= config
;
5060 state
->frontend
.ops
= stv090x_ops
;
5061 state
->frontend
.demodulator_priv
= state
;
5062 state
->demod
= demod
;
5063 /* Single or Dual mode */
5064 state
->demod_mode
= config
->demod_mode
;
5065 state
->device
= config
->device
;
5067 state
->rolloff
= STV090x_RO_35
;
5069 ret
= stv090x_setup_compound(state
);
5073 return &state
->frontend
;
5079 EXPORT_SYMBOL_GPL(stv090x_attach
);
5081 static const struct i2c_device_id stv090x_id_table
[] = {
5085 MODULE_DEVICE_TABLE(i2c
, stv090x_id_table
);
5087 static struct i2c_driver stv090x_driver
= {
5090 .suppress_bind_attrs
= true,
5092 .probe
= stv090x_probe
,
5093 .remove
= stv090x_remove
,
5094 .id_table
= stv090x_id_table
,
5097 module_i2c_driver(stv090x_driver
);
5099 MODULE_PARM_DESC(verbose
, "Set Verbosity level");
5100 MODULE_AUTHOR("Manu Abraham");
5101 MODULE_DESCRIPTION("STV090x Multi-Std Broadcast frontend");
5102 MODULE_LICENSE("GPL");