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 int stv090x_i2c_gate_ctrl(struct stv090x_state
*state
, int enable
)
756 * NOTE! A lock is used as a FSM to control the state in which
757 * access is serialized between two tuners on the same demod.
758 * This has nothing to do with a lock to protect a critical section
759 * which may in some other cases be confused with protecting I/O
760 * access to the demodulator gate.
761 * In case of any error, the lock is unlocked and exit within the
762 * relevant operations themselves.
765 if (state
->config
->tuner_i2c_lock
)
766 state
->config
->tuner_i2c_lock(&state
->frontend
, 1);
768 mutex_lock(&state
->internal
->tuner_lock
);
771 reg
= STV090x_READ_DEMOD(state
, I2CRPT
);
773 dprintk(FE_DEBUG
, 1, "Enable Gate");
774 STV090x_SETFIELD_Px(reg
, I2CT_ON_FIELD
, 1);
775 if (STV090x_WRITE_DEMOD(state
, I2CRPT
, reg
) < 0)
779 dprintk(FE_DEBUG
, 1, "Disable Gate");
780 STV090x_SETFIELD_Px(reg
, I2CT_ON_FIELD
, 0);
781 if ((STV090x_WRITE_DEMOD(state
, I2CRPT
, reg
)) < 0)
786 if (state
->config
->tuner_i2c_lock
)
787 state
->config
->tuner_i2c_lock(&state
->frontend
, 0);
789 mutex_unlock(&state
->internal
->tuner_lock
);
794 dprintk(FE_ERROR
, 1, "I/O error");
795 if (state
->config
->tuner_i2c_lock
)
796 state
->config
->tuner_i2c_lock(&state
->frontend
, 0);
798 mutex_unlock(&state
->internal
->tuner_lock
);
802 static void stv090x_get_lock_tmg(struct stv090x_state
*state
)
804 switch (state
->algo
) {
805 case STV090x_BLIND_SEARCH
:
806 dprintk(FE_DEBUG
, 1, "Blind Search");
807 if (state
->srate
<= 1500000) { /*10Msps< SR <=15Msps*/
808 state
->DemodTimeout
= 1500;
809 state
->FecTimeout
= 400;
810 } else if (state
->srate
<= 5000000) { /*10Msps< SR <=15Msps*/
811 state
->DemodTimeout
= 1000;
812 state
->FecTimeout
= 300;
813 } else { /*SR >20Msps*/
814 state
->DemodTimeout
= 700;
815 state
->FecTimeout
= 100;
819 case STV090x_COLD_SEARCH
:
820 case STV090x_WARM_SEARCH
:
822 dprintk(FE_DEBUG
, 1, "Normal Search");
823 if (state
->srate
<= 1000000) { /*SR <=1Msps*/
824 state
->DemodTimeout
= 4500;
825 state
->FecTimeout
= 1700;
826 } else if (state
->srate
<= 2000000) { /*1Msps < SR <= 2Msps */
827 state
->DemodTimeout
= 2500;
828 state
->FecTimeout
= 1100;
829 } else if (state
->srate
<= 5000000) { /*2Msps < SR <= 5Msps */
830 state
->DemodTimeout
= 1000;
831 state
->FecTimeout
= 550;
832 } else if (state
->srate
<= 10000000) { /*5Msps < SR <= 10Msps */
833 state
->DemodTimeout
= 700;
834 state
->FecTimeout
= 250;
835 } else if (state
->srate
<= 20000000) { /*10Msps < SR <= 20Msps */
836 state
->DemodTimeout
= 400;
837 state
->FecTimeout
= 130;
838 } else { /*SR >20Msps*/
839 state
->DemodTimeout
= 300;
840 state
->FecTimeout
= 100;
845 if (state
->algo
== STV090x_WARM_SEARCH
)
846 state
->DemodTimeout
/= 2;
849 static int stv090x_set_srate(struct stv090x_state
*state
, u32 srate
)
853 if (srate
> 60000000) {
854 sym
= (srate
<< 4); /* SR * 2^16 / master_clk */
855 sym
/= (state
->internal
->mclk
>> 12);
856 } else if (srate
> 6000000) {
858 sym
/= (state
->internal
->mclk
>> 10);
861 sym
/= (state
->internal
->mclk
>> 7);
864 if (STV090x_WRITE_DEMOD(state
, SFRINIT1
, (sym
>> 8) & 0x7f) < 0) /* MSB */
866 if (STV090x_WRITE_DEMOD(state
, SFRINIT0
, (sym
& 0xff)) < 0) /* LSB */
871 dprintk(FE_ERROR
, 1, "I/O error");
875 static int stv090x_set_max_srate(struct stv090x_state
*state
, u32 clk
, u32 srate
)
879 srate
= 105 * (srate
/ 100);
880 if (srate
> 60000000) {
881 sym
= (srate
<< 4); /* SR * 2^16 / master_clk */
882 sym
/= (state
->internal
->mclk
>> 12);
883 } else if (srate
> 6000000) {
885 sym
/= (state
->internal
->mclk
>> 10);
888 sym
/= (state
->internal
->mclk
>> 7);
892 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, (sym
>> 8) & 0x7f) < 0) /* MSB */
894 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, sym
& 0xff) < 0) /* LSB */
897 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, 0x7f) < 0) /* MSB */
899 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, 0xff) < 0) /* LSB */
905 dprintk(FE_ERROR
, 1, "I/O error");
909 static int stv090x_set_min_srate(struct stv090x_state
*state
, u32 clk
, u32 srate
)
913 srate
= 95 * (srate
/ 100);
914 if (srate
> 60000000) {
915 sym
= (srate
<< 4); /* SR * 2^16 / master_clk */
916 sym
/= (state
->internal
->mclk
>> 12);
917 } else if (srate
> 6000000) {
919 sym
/= (state
->internal
->mclk
>> 10);
922 sym
/= (state
->internal
->mclk
>> 7);
925 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, ((sym
>> 8) & 0x7f)) < 0) /* MSB */
927 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, (sym
& 0xff)) < 0) /* LSB */
931 dprintk(FE_ERROR
, 1, "I/O error");
935 static u32
stv090x_car_width(u32 srate
, enum stv090x_rolloff rolloff
)
952 return srate
+ (srate
* ro
) / 100;
955 static int stv090x_set_vit_thacq(struct stv090x_state
*state
)
957 if (STV090x_WRITE_DEMOD(state
, VTH12
, 0x96) < 0)
959 if (STV090x_WRITE_DEMOD(state
, VTH23
, 0x64) < 0)
961 if (STV090x_WRITE_DEMOD(state
, VTH34
, 0x36) < 0)
963 if (STV090x_WRITE_DEMOD(state
, VTH56
, 0x23) < 0)
965 if (STV090x_WRITE_DEMOD(state
, VTH67
, 0x1e) < 0)
967 if (STV090x_WRITE_DEMOD(state
, VTH78
, 0x19) < 0)
971 dprintk(FE_ERROR
, 1, "I/O error");
975 static int stv090x_set_vit_thtracq(struct stv090x_state
*state
)
977 if (STV090x_WRITE_DEMOD(state
, VTH12
, 0xd0) < 0)
979 if (STV090x_WRITE_DEMOD(state
, VTH23
, 0x7d) < 0)
981 if (STV090x_WRITE_DEMOD(state
, VTH34
, 0x53) < 0)
983 if (STV090x_WRITE_DEMOD(state
, VTH56
, 0x2f) < 0)
985 if (STV090x_WRITE_DEMOD(state
, VTH67
, 0x24) < 0)
987 if (STV090x_WRITE_DEMOD(state
, VTH78
, 0x1f) < 0)
991 dprintk(FE_ERROR
, 1, "I/O error");
995 static int stv090x_set_viterbi(struct stv090x_state
*state
)
997 switch (state
->search_mode
) {
998 case STV090x_SEARCH_AUTO
:
999 if (STV090x_WRITE_DEMOD(state
, FECM
, 0x10) < 0) /* DVB-S and DVB-S2 */
1001 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x3f) < 0) /* all puncture rate */
1004 case STV090x_SEARCH_DVBS1
:
1005 if (STV090x_WRITE_DEMOD(state
, FECM
, 0x00) < 0) /* disable DSS */
1007 switch (state
->fec
) {
1009 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x01) < 0)
1014 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x02) < 0)
1019 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x04) < 0)
1024 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x08) < 0)
1029 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x20) < 0)
1034 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x2f) < 0) /* all */
1039 case STV090x_SEARCH_DSS
:
1040 if (STV090x_WRITE_DEMOD(state
, FECM
, 0x80) < 0)
1042 switch (state
->fec
) {
1044 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x01) < 0)
1049 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x02) < 0)
1054 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x10) < 0)
1059 if (STV090x_WRITE_DEMOD(state
, PRVIT
, 0x13) < 0) /* 1/2, 2/3, 6/7 */
1069 dprintk(FE_ERROR
, 1, "I/O error");
1073 static int stv090x_stop_modcod(struct stv090x_state
*state
)
1075 if (STV090x_WRITE_DEMOD(state
, MODCODLST0
, 0xff) < 0)
1077 if (STV090x_WRITE_DEMOD(state
, MODCODLST1
, 0xff) < 0)
1079 if (STV090x_WRITE_DEMOD(state
, MODCODLST2
, 0xff) < 0)
1081 if (STV090x_WRITE_DEMOD(state
, MODCODLST3
, 0xff) < 0)
1083 if (STV090x_WRITE_DEMOD(state
, MODCODLST4
, 0xff) < 0)
1085 if (STV090x_WRITE_DEMOD(state
, MODCODLST5
, 0xff) < 0)
1087 if (STV090x_WRITE_DEMOD(state
, MODCODLST6
, 0xff) < 0)
1089 if (STV090x_WRITE_DEMOD(state
, MODCODLST7
, 0xff) < 0)
1091 if (STV090x_WRITE_DEMOD(state
, MODCODLST8
, 0xff) < 0)
1093 if (STV090x_WRITE_DEMOD(state
, MODCODLST9
, 0xff) < 0)
1095 if (STV090x_WRITE_DEMOD(state
, MODCODLSTA
, 0xff) < 0)
1097 if (STV090x_WRITE_DEMOD(state
, MODCODLSTB
, 0xff) < 0)
1099 if (STV090x_WRITE_DEMOD(state
, MODCODLSTC
, 0xff) < 0)
1101 if (STV090x_WRITE_DEMOD(state
, MODCODLSTD
, 0xff) < 0)
1103 if (STV090x_WRITE_DEMOD(state
, MODCODLSTE
, 0xff) < 0)
1105 if (STV090x_WRITE_DEMOD(state
, MODCODLSTF
, 0xff) < 0)
1109 dprintk(FE_ERROR
, 1, "I/O error");
1113 static int stv090x_activate_modcod(struct stv090x_state
*state
)
1115 if (STV090x_WRITE_DEMOD(state
, MODCODLST0
, 0xff) < 0)
1117 if (STV090x_WRITE_DEMOD(state
, MODCODLST1
, 0xfc) < 0)
1119 if (STV090x_WRITE_DEMOD(state
, MODCODLST2
, 0xcc) < 0)
1121 if (STV090x_WRITE_DEMOD(state
, MODCODLST3
, 0xcc) < 0)
1123 if (STV090x_WRITE_DEMOD(state
, MODCODLST4
, 0xcc) < 0)
1125 if (STV090x_WRITE_DEMOD(state
, MODCODLST5
, 0xcc) < 0)
1127 if (STV090x_WRITE_DEMOD(state
, MODCODLST6
, 0xcc) < 0)
1129 if (STV090x_WRITE_DEMOD(state
, MODCODLST7
, 0xcc) < 0)
1131 if (STV090x_WRITE_DEMOD(state
, MODCODLST8
, 0xcc) < 0)
1133 if (STV090x_WRITE_DEMOD(state
, MODCODLST9
, 0xcc) < 0)
1135 if (STV090x_WRITE_DEMOD(state
, MODCODLSTA
, 0xcc) < 0)
1137 if (STV090x_WRITE_DEMOD(state
, MODCODLSTB
, 0xcc) < 0)
1139 if (STV090x_WRITE_DEMOD(state
, MODCODLSTC
, 0xcc) < 0)
1141 if (STV090x_WRITE_DEMOD(state
, MODCODLSTD
, 0xcc) < 0)
1143 if (STV090x_WRITE_DEMOD(state
, MODCODLSTE
, 0xcc) < 0)
1145 if (STV090x_WRITE_DEMOD(state
, MODCODLSTF
, 0xcf) < 0)
1150 dprintk(FE_ERROR
, 1, "I/O error");
1154 static int stv090x_activate_modcod_single(struct stv090x_state
*state
)
1157 if (STV090x_WRITE_DEMOD(state
, MODCODLST0
, 0xff) < 0)
1159 if (STV090x_WRITE_DEMOD(state
, MODCODLST1
, 0xf0) < 0)
1161 if (STV090x_WRITE_DEMOD(state
, MODCODLST2
, 0x00) < 0)
1163 if (STV090x_WRITE_DEMOD(state
, MODCODLST3
, 0x00) < 0)
1165 if (STV090x_WRITE_DEMOD(state
, MODCODLST4
, 0x00) < 0)
1167 if (STV090x_WRITE_DEMOD(state
, MODCODLST5
, 0x00) < 0)
1169 if (STV090x_WRITE_DEMOD(state
, MODCODLST6
, 0x00) < 0)
1171 if (STV090x_WRITE_DEMOD(state
, MODCODLST7
, 0x00) < 0)
1173 if (STV090x_WRITE_DEMOD(state
, MODCODLST8
, 0x00) < 0)
1175 if (STV090x_WRITE_DEMOD(state
, MODCODLST9
, 0x00) < 0)
1177 if (STV090x_WRITE_DEMOD(state
, MODCODLSTA
, 0x00) < 0)
1179 if (STV090x_WRITE_DEMOD(state
, MODCODLSTB
, 0x00) < 0)
1181 if (STV090x_WRITE_DEMOD(state
, MODCODLSTC
, 0x00) < 0)
1183 if (STV090x_WRITE_DEMOD(state
, MODCODLSTD
, 0x00) < 0)
1185 if (STV090x_WRITE_DEMOD(state
, MODCODLSTE
, 0x00) < 0)
1187 if (STV090x_WRITE_DEMOD(state
, MODCODLSTF
, 0x0f) < 0)
1193 dprintk(FE_ERROR
, 1, "I/O error");
1197 static int stv090x_vitclk_ctl(struct stv090x_state
*state
, int enable
)
1201 switch (state
->demod
) {
1202 case STV090x_DEMODULATOR_0
:
1203 mutex_lock(&state
->internal
->demod_lock
);
1204 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
1205 STV090x_SETFIELD(reg
, STOP_CLKVIT1_FIELD
, enable
);
1206 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
1208 mutex_unlock(&state
->internal
->demod_lock
);
1211 case STV090x_DEMODULATOR_1
:
1212 mutex_lock(&state
->internal
->demod_lock
);
1213 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
1214 STV090x_SETFIELD(reg
, STOP_CLKVIT2_FIELD
, enable
);
1215 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
1217 mutex_unlock(&state
->internal
->demod_lock
);
1221 dprintk(FE_ERROR
, 1, "Wrong demodulator!");
1226 mutex_unlock(&state
->internal
->demod_lock
);
1227 dprintk(FE_ERROR
, 1, "I/O error");
1231 static int stv090x_dvbs_track_crl(struct stv090x_state
*state
)
1233 if (state
->internal
->dev_ver
>= 0x30) {
1234 /* Set ACLC BCLC optimised value vs SR */
1235 if (state
->srate
>= 15000000) {
1236 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x2b) < 0)
1238 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x1a) < 0)
1240 } else if ((state
->srate
>= 7000000) && (15000000 > state
->srate
)) {
1241 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x0c) < 0)
1243 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x1b) < 0)
1245 } else if (state
->srate
< 7000000) {
1246 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x2c) < 0)
1248 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x1c) < 0)
1254 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x1a) < 0)
1256 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x09) < 0)
1261 dprintk(FE_ERROR
, 1, "I/O error");
1265 static int stv090x_delivery_search(struct stv090x_state
*state
)
1269 switch (state
->search_mode
) {
1270 case STV090x_SEARCH_DVBS1
:
1271 case STV090x_SEARCH_DSS
:
1272 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1273 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
1274 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 0);
1275 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1278 /* Activate Viterbi decoder in legacy search,
1279 * do not use FRESVIT1, might impact VITERBI2
1281 if (stv090x_vitclk_ctl(state
, 0) < 0)
1284 if (stv090x_dvbs_track_crl(state
) < 0)
1287 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x22) < 0) /* disable DVB-S2 */
1290 if (stv090x_set_vit_thacq(state
) < 0)
1292 if (stv090x_set_viterbi(state
) < 0)
1296 case STV090x_SEARCH_DVBS2
:
1297 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1298 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 0);
1299 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 0);
1300 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1302 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
1303 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 1);
1304 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1307 if (stv090x_vitclk_ctl(state
, 1) < 0)
1310 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0x1a) < 0) /* stop DVB-S CR loop */
1312 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0x09) < 0)
1315 if (state
->internal
->dev_ver
<= 0x20) {
1316 /* enable S2 carrier loop */
1317 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x26) < 0)
1320 /* > Cut 3: Stop carrier 3 */
1321 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x66) < 0)
1325 if (state
->demod_mode
!= STV090x_SINGLE
) {
1326 /* Cut 2: enable link during search */
1327 if (stv090x_activate_modcod(state
) < 0)
1330 /* Single demodulator
1331 * Authorize SHORT and LONG frames,
1332 * QPSK, 8PSK, 16APSK and 32APSK
1334 if (stv090x_activate_modcod_single(state
) < 0)
1338 if (stv090x_set_vit_thtracq(state
) < 0)
1342 case STV090x_SEARCH_AUTO
:
1344 /* enable DVB-S2 and DVB-S2 in Auto MODE */
1345 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1346 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 0);
1347 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 0);
1348 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1350 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
1351 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 1);
1352 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1355 if (stv090x_vitclk_ctl(state
, 0) < 0)
1358 if (stv090x_dvbs_track_crl(state
) < 0)
1361 if (state
->internal
->dev_ver
<= 0x20) {
1362 /* enable S2 carrier loop */
1363 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x26) < 0)
1366 /* > Cut 3: Stop carrier 3 */
1367 if (STV090x_WRITE_DEMOD(state
, CAR2CFG
, 0x66) < 0)
1371 if (state
->demod_mode
!= STV090x_SINGLE
) {
1372 /* Cut 2: enable link during search */
1373 if (stv090x_activate_modcod(state
) < 0)
1376 /* Single demodulator
1377 * Authorize SHORT and LONG frames,
1378 * QPSK, 8PSK, 16APSK and 32APSK
1380 if (stv090x_activate_modcod_single(state
) < 0)
1384 if (stv090x_set_vit_thacq(state
) < 0)
1387 if (stv090x_set_viterbi(state
) < 0)
1393 dprintk(FE_ERROR
, 1, "I/O error");
1397 static int stv090x_start_search(struct stv090x_state
*state
)
1402 /* Reset demodulator */
1403 reg
= STV090x_READ_DEMOD(state
, DMDISTATE
);
1404 STV090x_SETFIELD_Px(reg
, I2C_DEMOD_MODE_FIELD
, 0x1f);
1405 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, reg
) < 0)
1408 if (state
->internal
->dev_ver
<= 0x20) {
1409 if (state
->srate
<= 5000000) {
1410 if (STV090x_WRITE_DEMOD(state
, CARCFG
, 0x44) < 0)
1412 if (STV090x_WRITE_DEMOD(state
, CFRUP1
, 0x0f) < 0)
1414 if (STV090x_WRITE_DEMOD(state
, CFRUP0
, 0xff) < 0)
1416 if (STV090x_WRITE_DEMOD(state
, CFRLOW1
, 0xf0) < 0)
1418 if (STV090x_WRITE_DEMOD(state
, CFRLOW0
, 0x00) < 0)
1421 /*enlarge the timing bandwidth for Low SR*/
1422 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x68) < 0)
1425 /* If the symbol rate is >5 Msps
1426 Set The carrier search up and low to auto mode */
1427 if (STV090x_WRITE_DEMOD(state
, CARCFG
, 0xc4) < 0)
1429 /*reduce the timing bandwidth for high SR*/
1430 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x44) < 0)
1435 if (state
->srate
<= 5000000) {
1436 /* enlarge the timing bandwidth for Low SR */
1437 STV090x_WRITE_DEMOD(state
, RTCS2
, 0x68);
1439 /* reduce timing bandwidth for high SR */
1440 STV090x_WRITE_DEMOD(state
, RTCS2
, 0x44);
1443 /* Set CFR min and max to manual mode */
1444 STV090x_WRITE_DEMOD(state
, CARCFG
, 0x46);
1446 if (state
->algo
== STV090x_WARM_SEARCH
) {
1451 freq_abs
= 1000 << 16;
1452 freq_abs
/= (state
->internal
->mclk
/ 1000);
1453 freq
= (s16
) freq_abs
;
1456 * CFR min =- (SearchRange / 2 + 600KHz)
1457 * CFR max = +(SearchRange / 2 + 600KHz)
1458 * (600KHz for the tuner step size)
1460 freq_abs
= (state
->search_range
/ 2000) + 600;
1461 freq_abs
= freq_abs
<< 16;
1462 freq_abs
/= (state
->internal
->mclk
/ 1000);
1463 freq
= (s16
) freq_abs
;
1466 if (STV090x_WRITE_DEMOD(state
, CFRUP1
, MSB(freq
)) < 0)
1468 if (STV090x_WRITE_DEMOD(state
, CFRUP0
, LSB(freq
)) < 0)
1473 if (STV090x_WRITE_DEMOD(state
, CFRLOW1
, MSB(freq
)) < 0)
1475 if (STV090x_WRITE_DEMOD(state
, CFRLOW0
, LSB(freq
)) < 0)
1480 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, 0) < 0)
1482 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, 0) < 0)
1485 if (state
->internal
->dev_ver
>= 0x20) {
1486 if (STV090x_WRITE_DEMOD(state
, EQUALCFG
, 0x41) < 0)
1488 if (STV090x_WRITE_DEMOD(state
, FFECFG
, 0x41) < 0)
1491 if ((state
->search_mode
== STV090x_SEARCH_DVBS1
) ||
1492 (state
->search_mode
== STV090x_SEARCH_DSS
) ||
1493 (state
->search_mode
== STV090x_SEARCH_AUTO
)) {
1495 if (STV090x_WRITE_DEMOD(state
, VITSCALE
, 0x82) < 0)
1497 if (STV090x_WRITE_DEMOD(state
, VAVSRVIT
, 0x00) < 0)
1502 if (STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x00) < 0)
1504 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, 0xe0) < 0)
1506 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, 0xc0) < 0)
1509 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1510 STV090x_SETFIELD_Px(reg
, SCAN_ENABLE_FIELD
, 0);
1511 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0);
1512 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1514 reg
= STV090x_READ_DEMOD(state
, DMDCFG2
);
1515 STV090x_SETFIELD_Px(reg
, S1S2_SEQUENTIAL_FIELD
, 0x0);
1516 if (STV090x_WRITE_DEMOD(state
, DMDCFG2
, reg
) < 0)
1519 if (STV090x_WRITE_DEMOD(state
, RTC
, 0x88) < 0)
1522 if (state
->internal
->dev_ver
>= 0x20) {
1523 /*Frequency offset detector setting*/
1524 if (state
->srate
< 2000000) {
1525 if (state
->internal
->dev_ver
<= 0x20) {
1527 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x39) < 0)
1531 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x89) < 0)
1534 if (STV090x_WRITE_DEMOD(state
, CARHDR
, 0x40) < 0)
1536 } else if (state
->srate
< 10000000) {
1537 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x4c) < 0)
1539 if (STV090x_WRITE_DEMOD(state
, CARHDR
, 0x20) < 0)
1542 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x4b) < 0)
1544 if (STV090x_WRITE_DEMOD(state
, CARHDR
, 0x20) < 0)
1548 if (state
->srate
< 10000000) {
1549 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0xef) < 0)
1552 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0xed) < 0)
1557 switch (state
->algo
) {
1558 case STV090x_WARM_SEARCH
:
1559 /* The symbol rate and the exact
1560 * carrier Frequency are known
1562 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
1564 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0)
1568 case STV090x_COLD_SEARCH
:
1569 /* The symbol rate is known */
1570 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
1572 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x15) < 0)
1581 dprintk(FE_ERROR
, 1, "I/O error");
1585 static int stv090x_get_agc2_min_level(struct stv090x_state
*state
)
1587 u32 agc2_min
= 0xffff, agc2
= 0, freq_init
, freq_step
, reg
;
1588 s32 i
, j
, steps
, dir
;
1590 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
1592 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1593 STV090x_SETFIELD_Px(reg
, SCAN_ENABLE_FIELD
, 0);
1594 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0);
1595 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1598 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, 0x83) < 0) /* SR = 65 Msps Max */
1600 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, 0xc0) < 0)
1602 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, 0x82) < 0) /* SR= 400 ksps Min */
1604 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, 0xa0) < 0)
1606 if (STV090x_WRITE_DEMOD(state
, DMDTOM
, 0x00) < 0) /* stop acq @ coarse carrier state */
1608 if (stv090x_set_srate(state
, 1000000) < 0)
1611 steps
= state
->search_range
/ 1000000;
1616 freq_step
= (1000000 * 256) / (state
->internal
->mclk
/ 256);
1619 for (i
= 0; i
< steps
; i
++) {
1621 freq_init
= freq_init
+ (freq_step
* i
);
1623 freq_init
= freq_init
- (freq_step
* i
);
1627 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x5c) < 0) /* Demod RESET */
1629 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, (freq_init
>> 8) & 0xff) < 0)
1631 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, freq_init
& 0xff) < 0)
1633 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x58) < 0) /* Demod RESET */
1638 for (j
= 0; j
< 10; j
++) {
1639 agc2
+= (STV090x_READ_DEMOD(state
, AGC2I1
) << 8) |
1640 STV090x_READ_DEMOD(state
, AGC2I0
);
1643 if (agc2
< agc2_min
)
1649 dprintk(FE_ERROR
, 1, "I/O error");
1653 static u32
stv090x_get_srate(struct stv090x_state
*state
, u32 clk
)
1656 s32 srate
, int_1
, int_2
, tmp_1
, tmp_2
;
1658 r3
= STV090x_READ_DEMOD(state
, SFR3
);
1659 r2
= STV090x_READ_DEMOD(state
, SFR2
);
1660 r1
= STV090x_READ_DEMOD(state
, SFR1
);
1661 r0
= STV090x_READ_DEMOD(state
, SFR0
);
1663 srate
= ((r3
<< 24) | (r2
<< 16) | (r1
<< 8) | r0
);
1666 int_2
= srate
>> 16;
1668 tmp_1
= clk
% 0x10000;
1669 tmp_2
= srate
% 0x10000;
1671 srate
= (int_1
* int_2
) +
1672 ((int_1
* tmp_2
) >> 16) +
1673 ((int_2
* tmp_1
) >> 16);
1678 static u32
stv090x_srate_srch_coarse(struct stv090x_state
*state
)
1680 struct dvb_frontend
*fe
= &state
->frontend
;
1682 int tmg_lock
= 0, i
;
1683 s32 tmg_cpt
= 0, dir
= 1, steps
, cur_step
= 0, freq
;
1684 u32 srate_coarse
= 0, agc2
= 0, car_step
= 1200, reg
;
1687 if (state
->internal
->dev_ver
>= 0x30)
1692 reg
= STV090x_READ_DEMOD(state
, DMDISTATE
);
1693 STV090x_SETFIELD_Px(reg
, I2C_DEMOD_MODE_FIELD
, 0x1f); /* Demod RESET */
1694 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, reg
) < 0)
1696 if (STV090x_WRITE_DEMOD(state
, TMGCFG
, 0x12) < 0)
1698 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc0) < 0)
1700 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, 0xf0) < 0)
1702 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, 0xe0) < 0)
1704 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1705 STV090x_SETFIELD_Px(reg
, SCAN_ENABLE_FIELD
, 1);
1706 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0);
1707 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1710 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, 0x83) < 0)
1712 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, 0xc0) < 0)
1714 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, 0x82) < 0)
1716 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, 0xa0) < 0)
1718 if (STV090x_WRITE_DEMOD(state
, DMDTOM
, 0x00) < 0)
1720 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x50) < 0)
1723 if (state
->internal
->dev_ver
>= 0x30) {
1724 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x99) < 0)
1726 if (STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x98) < 0)
1729 } else if (state
->internal
->dev_ver
>= 0x20) {
1730 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x6a) < 0)
1732 if (STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x95) < 0)
1736 if (state
->srate
<= 2000000)
1738 else if (state
->srate
<= 5000000)
1740 else if (state
->srate
<= 12000000)
1745 steps
= -1 + ((state
->search_range
/ 1000) / car_step
);
1747 steps
= (2 * steps
) + 1;
1750 else if (steps
> 10) {
1752 car_step
= (state
->search_range
/ 1000) / 10;
1756 freq
= state
->frequency
;
1758 while ((!tmg_lock
) && (cur_step
< steps
)) {
1759 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x5f) < 0) /* Demod RESET */
1761 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, 0x00) < 0)
1763 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, 0x00) < 0)
1765 if (STV090x_WRITE_DEMOD(state
, SFRINIT1
, 0x00) < 0)
1767 if (STV090x_WRITE_DEMOD(state
, SFRINIT0
, 0x00) < 0)
1769 /* trigger acquisition */
1770 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x40) < 0)
1773 for (i
= 0; i
< 10; i
++) {
1774 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
1775 if (STV090x_GETFIELD_Px(reg
, TMGLOCK_QUALITY_FIELD
) >= 2)
1777 agc2
+= (STV090x_READ_DEMOD(state
, AGC2I1
) << 8) |
1778 STV090x_READ_DEMOD(state
, AGC2I0
);
1781 srate_coarse
= stv090x_get_srate(state
, state
->internal
->mclk
);
1784 if ((tmg_cpt
>= 5) && (agc2
< agc2th
) &&
1785 (srate_coarse
< 50000000) && (srate_coarse
> 850000))
1787 else if (cur_step
< steps
) {
1789 freq
+= cur_step
* car_step
;
1791 freq
-= cur_step
* car_step
;
1794 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
1797 if (state
->config
->tuner_set_frequency
) {
1798 if (state
->config
->tuner_set_frequency(fe
, freq
) < 0)
1802 if (state
->config
->tuner_set_bandwidth
) {
1803 if (state
->config
->tuner_set_bandwidth(fe
, state
->tuner_bw
) < 0)
1807 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
1812 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
1815 if (state
->config
->tuner_get_status
) {
1816 if (state
->config
->tuner_get_status(fe
, ®
) < 0)
1821 dprintk(FE_DEBUG
, 1, "Tuner phase locked");
1823 dprintk(FE_DEBUG
, 1, "Tuner unlocked");
1825 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
1833 srate_coarse
= stv090x_get_srate(state
, state
->internal
->mclk
);
1835 return srate_coarse
;
1838 stv090x_i2c_gate_ctrl(state
, 0);
1840 dprintk(FE_ERROR
, 1, "I/O error");
1844 static u32
stv090x_srate_srch_fine(struct stv090x_state
*state
)
1846 u32 srate_coarse
, freq_coarse
, sym
, reg
;
1848 srate_coarse
= stv090x_get_srate(state
, state
->internal
->mclk
);
1849 freq_coarse
= STV090x_READ_DEMOD(state
, CFR2
) << 8;
1850 freq_coarse
|= STV090x_READ_DEMOD(state
, CFR1
);
1851 sym
= 13 * (srate_coarse
/ 10); /* SFRUP = SFR + 30% */
1853 if (sym
< state
->srate
)
1856 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0) /* Demod RESET */
1858 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc1) < 0)
1860 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, 0x20) < 0)
1862 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, 0x00) < 0)
1864 if (STV090x_WRITE_DEMOD(state
, TMGCFG
, 0xd2) < 0)
1866 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
1867 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0x00);
1868 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
1871 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
1874 if (state
->internal
->dev_ver
>= 0x30) {
1875 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x79) < 0)
1877 } else if (state
->internal
->dev_ver
>= 0x20) {
1878 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x49) < 0)
1882 if (srate_coarse
> 3000000) {
1883 sym
= 13 * (srate_coarse
/ 10); /* SFRUP = SFR + 30% */
1884 sym
= (sym
/ 1000) * 65536;
1885 sym
/= (state
->internal
->mclk
/ 1000);
1886 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, (sym
>> 8) & 0x7f) < 0)
1888 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, sym
& 0xff) < 0)
1890 sym
= 10 * (srate_coarse
/ 13); /* SFRLOW = SFR - 30% */
1891 sym
= (sym
/ 1000) * 65536;
1892 sym
/= (state
->internal
->mclk
/ 1000);
1893 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, (sym
>> 8) & 0x7f) < 0)
1895 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, sym
& 0xff) < 0)
1897 sym
= (srate_coarse
/ 1000) * 65536;
1898 sym
/= (state
->internal
->mclk
/ 1000);
1899 if (STV090x_WRITE_DEMOD(state
, SFRINIT1
, (sym
>> 8) & 0xff) < 0)
1901 if (STV090x_WRITE_DEMOD(state
, SFRINIT0
, sym
& 0xff) < 0)
1904 sym
= 13 * (srate_coarse
/ 10); /* SFRUP = SFR + 30% */
1905 sym
= (sym
/ 100) * 65536;
1906 sym
/= (state
->internal
->mclk
/ 100);
1907 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, (sym
>> 8) & 0x7f) < 0)
1909 if (STV090x_WRITE_DEMOD(state
, SFRUP0
, sym
& 0xff) < 0)
1911 sym
= 10 * (srate_coarse
/ 14); /* SFRLOW = SFR - 30% */
1912 sym
= (sym
/ 100) * 65536;
1913 sym
/= (state
->internal
->mclk
/ 100);
1914 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, (sym
>> 8) & 0x7f) < 0)
1916 if (STV090x_WRITE_DEMOD(state
, SFRLOW0
, sym
& 0xff) < 0)
1918 sym
= (srate_coarse
/ 100) * 65536;
1919 sym
/= (state
->internal
->mclk
/ 100);
1920 if (STV090x_WRITE_DEMOD(state
, SFRINIT1
, (sym
>> 8) & 0xff) < 0)
1922 if (STV090x_WRITE_DEMOD(state
, SFRINIT0
, sym
& 0xff) < 0)
1925 if (STV090x_WRITE_DEMOD(state
, DMDTOM
, 0x20) < 0)
1927 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, (freq_coarse
>> 8) & 0xff) < 0)
1929 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, freq_coarse
& 0xff) < 0)
1931 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x15) < 0) /* trigger acquisition */
1935 return srate_coarse
;
1938 dprintk(FE_ERROR
, 1, "I/O error");
1942 static int stv090x_get_dmdlock(struct stv090x_state
*state
, s32 timeout
)
1944 s32 timer
= 0, lock
= 0;
1948 while ((timer
< timeout
) && (!lock
)) {
1949 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
1950 stat
= STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
);
1953 case 0: /* searching */
1954 case 1: /* first PLH detected */
1956 dprintk(FE_DEBUG
, 1, "Demodulator searching ..");
1959 case 2: /* DVB-S2 mode */
1960 case 3: /* DVB-S1/legacy mode */
1961 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
1962 lock
= STV090x_GETFIELD_Px(reg
, LOCK_DEFINITIF_FIELD
);
1969 dprintk(FE_DEBUG
, 1, "Demodulator acquired LOCK");
1976 static int stv090x_blind_search(struct stv090x_state
*state
)
1978 u32 agc2
, reg
, srate_coarse
;
1979 s32 cpt_fail
, agc2_ovflw
, i
;
1980 u8 k_ref
, k_max
, k_min
;
1981 int coarse_fail
= 0;
1987 agc2
= stv090x_get_agc2_min_level(state
);
1989 if (agc2
> STV090x_SEARCH_AGC2_TH(state
->internal
->dev_ver
)) {
1993 if (state
->internal
->dev_ver
<= 0x20) {
1994 if (STV090x_WRITE_DEMOD(state
, CARCFG
, 0xc4) < 0)
1998 if (STV090x_WRITE_DEMOD(state
, CARCFG
, 0x06) < 0)
2002 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x44) < 0)
2005 if (state
->internal
->dev_ver
>= 0x20) {
2006 if (STV090x_WRITE_DEMOD(state
, EQUALCFG
, 0x41) < 0)
2008 if (STV090x_WRITE_DEMOD(state
, FFECFG
, 0x41) < 0)
2010 if (STV090x_WRITE_DEMOD(state
, VITSCALE
, 0x82) < 0)
2012 if (STV090x_WRITE_DEMOD(state
, VAVSRVIT
, 0x00) < 0) /* set viterbi hysteresis */
2018 if (STV090x_WRITE_DEMOD(state
, KREFTMG
, k_ref
) < 0)
2020 if (stv090x_srate_srch_coarse(state
) != 0) {
2021 srate_coarse
= stv090x_srate_srch_fine(state
);
2022 if (srate_coarse
!= 0) {
2023 stv090x_get_lock_tmg(state
);
2024 lock
= stv090x_get_dmdlock(state
,
2025 state
->DemodTimeout
);
2032 for (i
= 0; i
< 10; i
++) {
2033 agc2
+= (STV090x_READ_DEMOD(state
, AGC2I1
) << 8) |
2034 STV090x_READ_DEMOD(state
, AGC2I0
);
2037 reg
= STV090x_READ_DEMOD(state
, DSTATUS2
);
2038 if ((STV090x_GETFIELD_Px(reg
, CFR_OVERFLOW_FIELD
) == 0x01) &&
2039 (STV090x_GETFIELD_Px(reg
, DEMOD_DELOCK_FIELD
) == 0x01))
2043 if ((cpt_fail
> 7) || (agc2_ovflw
> 7))
2049 } while ((k_ref
>= k_min
) && (!lock
) && (!coarse_fail
));
2055 dprintk(FE_ERROR
, 1, "I/O error");
2059 static int stv090x_chk_tmg(struct stv090x_state
*state
)
2063 u8 freq
, tmg_thh
, tmg_thl
;
2066 freq
= STV090x_READ_DEMOD(state
, CARFREQ
);
2067 tmg_thh
= STV090x_READ_DEMOD(state
, TMGTHRISE
);
2068 tmg_thl
= STV090x_READ_DEMOD(state
, TMGTHFALL
);
2069 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, 0x20) < 0)
2071 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, 0x00) < 0)
2074 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2075 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0x00); /* stop carrier offset search */
2076 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2078 if (STV090x_WRITE_DEMOD(state
, RTC
, 0x80) < 0)
2081 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x40) < 0)
2083 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x00) < 0)
2086 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, 0x00) < 0) /* set car ofset to 0 */
2088 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, 0x00) < 0)
2090 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x65) < 0)
2093 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0) /* trigger acquisition */
2097 for (i
= 0; i
< 10; i
++) {
2098 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
2099 if (STV090x_GETFIELD_Px(reg
, TMGLOCK_QUALITY_FIELD
) >= 2)
2106 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
2108 if (STV090x_WRITE_DEMOD(state
, RTC
, 0x88) < 0) /* DVB-S1 timing */
2110 if (STV090x_WRITE_DEMOD(state
, RTCS2
, 0x68) < 0) /* DVB-S2 timing */
2113 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, freq
) < 0)
2115 if (STV090x_WRITE_DEMOD(state
, TMGTHRISE
, tmg_thh
) < 0)
2117 if (STV090x_WRITE_DEMOD(state
, TMGTHFALL
, tmg_thl
) < 0)
2123 dprintk(FE_ERROR
, 1, "I/O error");
2127 static int stv090x_get_coldlock(struct stv090x_state
*state
, s32 timeout_dmd
)
2129 struct dvb_frontend
*fe
= &state
->frontend
;
2132 s32 car_step
, steps
, cur_step
, dir
, freq
, timeout_lock
;
2135 if (state
->srate
>= 10000000)
2136 timeout_lock
= timeout_dmd
/ 3;
2138 timeout_lock
= timeout_dmd
/ 2;
2140 lock
= stv090x_get_dmdlock(state
, timeout_lock
); /* cold start wait */
2144 if (state
->srate
>= 10000000) {
2145 if (stv090x_chk_tmg(state
)) {
2146 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
2148 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x15) < 0)
2150 return stv090x_get_dmdlock(state
, timeout_dmd
);
2155 if (state
->srate
<= 4000000)
2157 else if (state
->srate
<= 7000000)
2159 else if (state
->srate
<= 10000000)
2164 steps
= (state
->search_range
/ 1000) / car_step
;
2166 steps
= 2 * (steps
+ 1);
2169 else if (steps
> 12)
2175 freq
= state
->frequency
;
2176 state
->tuner_bw
= stv090x_car_width(state
->srate
, state
->rolloff
) + state
->srate
;
2177 while ((cur_step
<= steps
) && (!lock
)) {
2179 freq
+= cur_step
* car_step
;
2181 freq
-= cur_step
* car_step
;
2184 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
2187 if (state
->config
->tuner_set_frequency
) {
2188 if (state
->config
->tuner_set_frequency(fe
, freq
) < 0)
2192 if (state
->config
->tuner_set_bandwidth
) {
2193 if (state
->config
->tuner_set_bandwidth(fe
, state
->tuner_bw
) < 0)
2197 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
2202 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
2205 if (state
->config
->tuner_get_status
) {
2206 if (state
->config
->tuner_get_status(fe
, ®
) < 0)
2209 dprintk(FE_DEBUG
, 1, "Tuner phase locked");
2211 dprintk(FE_DEBUG
, 1, "Tuner unlocked");
2214 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
2217 STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1c);
2218 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, 0x00) < 0)
2220 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, 0x00) < 0)
2222 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
2224 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x15) < 0)
2226 lock
= stv090x_get_dmdlock(state
, (timeout_dmd
/ 3));
2235 stv090x_i2c_gate_ctrl(state
, 0);
2237 dprintk(FE_ERROR
, 1, "I/O error");
2241 static int stv090x_get_loop_params(struct stv090x_state
*state
, s32
*freq_inc
, s32
*timeout_sw
, s32
*steps
)
2243 s32 timeout
, inc
, steps_max
, srate
, car_max
;
2245 srate
= state
->srate
;
2246 car_max
= state
->search_range
/ 1000;
2247 car_max
+= car_max
/ 10;
2248 car_max
= 65536 * (car_max
/ 2);
2249 car_max
/= (state
->internal
->mclk
/ 1000);
2251 if (car_max
> 0x4000)
2252 car_max
= 0x4000 ; /* maxcarrier should be<= +-1/4 Mclk */
2255 inc
/= state
->internal
->mclk
/ 1000;
2260 switch (state
->search_mode
) {
2261 case STV090x_SEARCH_DVBS1
:
2262 case STV090x_SEARCH_DSS
:
2263 inc
*= 3; /* freq step = 3% of srate */
2267 case STV090x_SEARCH_DVBS2
:
2272 case STV090x_SEARCH_AUTO
:
2279 if ((inc
> car_max
) || (inc
< 0))
2280 inc
= car_max
/ 2; /* increment <= 1/8 Mclk */
2282 timeout
*= 27500; /* 27.5 Msps reference */
2284 timeout
/= (srate
/ 1000);
2286 if ((timeout
> 100) || (timeout
< 0))
2289 steps_max
= (car_max
/ inc
) + 1; /* min steps = 3 */
2290 if ((steps_max
> 100) || (steps_max
< 0)) {
2291 steps_max
= 100; /* max steps <= 100 */
2292 inc
= car_max
/ steps_max
;
2295 *timeout_sw
= timeout
;
2301 static int stv090x_chk_signal(struct stv090x_state
*state
)
2303 s32 offst_car
, agc2
, car_max
;
2306 offst_car
= STV090x_READ_DEMOD(state
, CFR2
) << 8;
2307 offst_car
|= STV090x_READ_DEMOD(state
, CFR1
);
2308 offst_car
= comp2(offst_car
, 16);
2310 agc2
= STV090x_READ_DEMOD(state
, AGC2I1
) << 8;
2311 agc2
|= STV090x_READ_DEMOD(state
, AGC2I0
);
2312 car_max
= state
->search_range
/ 1000;
2314 car_max
+= (car_max
/ 10); /* 10% margin */
2315 car_max
= (65536 * car_max
/ 2);
2316 car_max
/= state
->internal
->mclk
/ 1000;
2318 if (car_max
> 0x4000)
2321 if ((agc2
> 0x2000) || (offst_car
> 2 * car_max
) || (offst_car
< -2 * car_max
)) {
2323 dprintk(FE_DEBUG
, 1, "No Signal");
2326 dprintk(FE_DEBUG
, 1, "Found Signal");
2332 static int stv090x_search_car_loop(struct stv090x_state
*state
, s32 inc
, s32 timeout
, int zigzag
, s32 steps_max
)
2334 int no_signal
, lock
= 0;
2335 s32 cpt_step
= 0, offst_freq
, car_max
;
2338 car_max
= state
->search_range
/ 1000;
2339 car_max
+= (car_max
/ 10);
2340 car_max
= (65536 * car_max
/ 2);
2341 car_max
/= (state
->internal
->mclk
/ 1000);
2342 if (car_max
> 0x4000)
2348 offst_freq
= -car_max
+ inc
;
2351 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1c) < 0)
2353 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, ((offst_freq
/ 256) & 0xff)) < 0)
2355 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, offst_freq
& 0xff) < 0)
2357 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0)
2360 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
2361 STV090x_SETFIELD_Px(reg
, ALGOSWRST_FIELD
, 0x1); /* stop DVB-S2 packet delin */
2362 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
2366 if (offst_freq
>= 0)
2367 offst_freq
= -offst_freq
- 2 * inc
;
2369 offst_freq
= -offst_freq
;
2371 offst_freq
+= 2 * inc
;
2376 lock
= stv090x_get_dmdlock(state
, timeout
);
2377 no_signal
= stv090x_chk_signal(state
);
2381 ((offst_freq
- inc
) < car_max
) &&
2382 ((offst_freq
+ inc
) > -car_max
) &&
2383 (cpt_step
< steps_max
));
2385 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
2386 STV090x_SETFIELD_Px(reg
, ALGOSWRST_FIELD
, 0);
2387 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
2392 dprintk(FE_ERROR
, 1, "I/O error");
2396 static int stv090x_sw_algo(struct stv090x_state
*state
)
2398 int no_signal
, zigzag
, lock
= 0;
2401 s32 dvbs2_fly_wheel
;
2402 s32 inc
, timeout_step
, trials
, steps_max
;
2405 stv090x_get_loop_params(state
, &inc
, &timeout_step
, &steps_max
);
2407 switch (state
->search_mode
) {
2408 case STV090x_SEARCH_DVBS1
:
2409 case STV090x_SEARCH_DSS
:
2410 /* accelerate the frequency detector */
2411 if (state
->internal
->dev_ver
>= 0x20) {
2412 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x3B) < 0)
2416 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, 0x49) < 0)
2421 case STV090x_SEARCH_DVBS2
:
2422 if (state
->internal
->dev_ver
>= 0x20) {
2423 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x79) < 0)
2427 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, 0x89) < 0)
2432 case STV090x_SEARCH_AUTO
:
2434 /* accelerate the frequency detector */
2435 if (state
->internal
->dev_ver
>= 0x20) {
2436 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x3b) < 0)
2438 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x79) < 0)
2442 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, 0xc9) < 0)
2450 lock
= stv090x_search_car_loop(state
, inc
, timeout_step
, zigzag
, steps_max
);
2451 no_signal
= stv090x_chk_signal(state
);
2454 /*run the SW search 2 times maximum*/
2455 if (lock
|| no_signal
|| (trials
== 2)) {
2456 /*Check if the demod is not losing lock in DVBS2*/
2457 if (state
->internal
->dev_ver
>= 0x20) {
2458 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x49) < 0)
2460 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x9e) < 0)
2464 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
2465 if ((lock
) && (STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
) == STV090x_DVBS2
)) {
2466 /*Check if the demod is not losing lock in DVBS2*/
2467 msleep(timeout_step
);
2468 reg
= STV090x_READ_DEMOD(state
, DMDFLYW
);
2469 dvbs2_fly_wheel
= STV090x_GETFIELD_Px(reg
, FLYWHEEL_CPT_FIELD
);
2470 if (dvbs2_fly_wheel
< 0xd) { /*if correct frames is decrementing */
2471 msleep(timeout_step
);
2472 reg
= STV090x_READ_DEMOD(state
, DMDFLYW
);
2473 dvbs2_fly_wheel
= STV090x_GETFIELD_Px(reg
, FLYWHEEL_CPT_FIELD
);
2475 if (dvbs2_fly_wheel
< 0xd) {
2476 /*FALSE lock, The demod is losing lock */
2479 if (state
->internal
->dev_ver
>= 0x20) {
2480 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x79) < 0)
2484 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, 0x89) < 0)
2490 } while ((!lock
) && (trials
< 2) && (!no_signal
));
2494 dprintk(FE_ERROR
, 1, "I/O error");
2498 static enum stv090x_delsys
stv090x_get_std(struct stv090x_state
*state
)
2501 enum stv090x_delsys delsys
;
2503 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
2504 if (STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
) == 2)
2505 delsys
= STV090x_DVBS2
;
2506 else if (STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
) == 3) {
2507 reg
= STV090x_READ_DEMOD(state
, FECM
);
2508 if (STV090x_GETFIELD_Px(reg
, DSS_DVB_FIELD
) == 1)
2509 delsys
= STV090x_DSS
;
2511 delsys
= STV090x_DVBS1
;
2513 delsys
= STV090x_ERROR
;
2520 static s32
stv090x_get_car_freq(struct stv090x_state
*state
, u32 mclk
)
2522 s32 derot
, int_1
, int_2
, tmp_1
, tmp_2
;
2524 derot
= STV090x_READ_DEMOD(state
, CFR2
) << 16;
2525 derot
|= STV090x_READ_DEMOD(state
, CFR1
) << 8;
2526 derot
|= STV090x_READ_DEMOD(state
, CFR0
);
2528 derot
= comp2(derot
, 24);
2530 int_2
= derot
>> 12;
2532 /* carrier_frequency = MasterClock * Reg / 2^24 */
2533 tmp_1
= mclk
% 0x1000;
2534 tmp_2
= derot
% 0x1000;
2536 derot
= (int_1
* int_2
) +
2537 ((int_1
* tmp_2
) >> 12) +
2538 ((int_2
* tmp_1
) >> 12);
2543 static int stv090x_get_viterbi(struct stv090x_state
*state
)
2547 reg
= STV090x_READ_DEMOD(state
, VITCURPUN
);
2548 rate
= STV090x_GETFIELD_Px(reg
, VIT_CURPUN_FIELD
);
2552 state
->fec
= STV090x_PR12
;
2556 state
->fec
= STV090x_PR23
;
2560 state
->fec
= STV090x_PR34
;
2564 state
->fec
= STV090x_PR56
;
2568 state
->fec
= STV090x_PR67
;
2572 state
->fec
= STV090x_PR78
;
2576 state
->fec
= STV090x_PRERR
;
2583 static enum stv090x_signal_state
stv090x_get_sig_params(struct stv090x_state
*state
)
2585 struct dvb_frontend
*fe
= &state
->frontend
;
2589 s32 i
= 0, offst_freq
;
2593 if (state
->algo
== STV090x_BLIND_SEARCH
) {
2594 tmg
= STV090x_READ_DEMOD(state
, TMGREG2
);
2595 STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x5c);
2596 while ((i
<= 50) && (tmg
!= 0) && (tmg
!= 0xff)) {
2597 tmg
= STV090x_READ_DEMOD(state
, TMGREG2
);
2602 state
->delsys
= stv090x_get_std(state
);
2604 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
2607 if (state
->config
->tuner_get_frequency
) {
2608 if (state
->config
->tuner_get_frequency(fe
, &state
->frequency
) < 0)
2612 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
2615 offst_freq
= stv090x_get_car_freq(state
, state
->internal
->mclk
) / 1000;
2616 state
->frequency
+= offst_freq
;
2618 if (stv090x_get_viterbi(state
) < 0)
2621 reg
= STV090x_READ_DEMOD(state
, DMDMODCOD
);
2622 state
->modcod
= STV090x_GETFIELD_Px(reg
, DEMOD_MODCOD_FIELD
);
2623 state
->pilots
= STV090x_GETFIELD_Px(reg
, DEMOD_TYPE_FIELD
) & 0x01;
2624 state
->frame_len
= STV090x_GETFIELD_Px(reg
, DEMOD_TYPE_FIELD
) >> 1;
2625 reg
= STV090x_READ_DEMOD(state
, TMGOBS
);
2626 state
->rolloff
= STV090x_GETFIELD_Px(reg
, ROLLOFF_STATUS_FIELD
);
2627 reg
= STV090x_READ_DEMOD(state
, FECM
);
2628 state
->inversion
= STV090x_GETFIELD_Px(reg
, IQINV_FIELD
);
2630 if ((state
->algo
== STV090x_BLIND_SEARCH
) || (state
->srate
< 10000000)) {
2632 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
2635 if (state
->config
->tuner_get_frequency
) {
2636 if (state
->config
->tuner_get_frequency(fe
, &state
->frequency
) < 0)
2640 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
2643 if (abs(offst_freq
) <= ((state
->search_range
/ 2000) + 500))
2644 return STV090x_RANGEOK
;
2645 else if (abs(offst_freq
) <= (stv090x_car_width(state
->srate
, state
->rolloff
) / 2000))
2646 return STV090x_RANGEOK
;
2648 if (abs(offst_freq
) <= ((state
->search_range
/ 2000) + 500))
2649 return STV090x_RANGEOK
;
2652 return STV090x_OUTOFRANGE
;
2655 stv090x_i2c_gate_ctrl(state
, 0);
2657 dprintk(FE_ERROR
, 1, "I/O error");
2661 static u32
stv090x_get_tmgoffst(struct stv090x_state
*state
, u32 srate
)
2665 offst_tmg
= STV090x_READ_DEMOD(state
, TMGREG2
) << 16;
2666 offst_tmg
|= STV090x_READ_DEMOD(state
, TMGREG1
) << 8;
2667 offst_tmg
|= STV090x_READ_DEMOD(state
, TMGREG0
);
2669 offst_tmg
= comp2(offst_tmg
, 24); /* 2's complement */
2673 offst_tmg
= ((s32
) srate
* 10) / ((s32
) 0x1000000 / offst_tmg
);
2679 static u8
stv090x_optimize_carloop(struct stv090x_state
*state
, enum stv090x_modcod modcod
, s32 pilots
)
2683 struct stv090x_long_frame_crloop
*car_loop
, *car_loop_qpsk_low
, *car_loop_apsk_low
;
2685 if (state
->internal
->dev_ver
== 0x20) {
2686 car_loop
= stv090x_s2_crl_cut20
;
2687 car_loop_qpsk_low
= stv090x_s2_lowqpsk_crl_cut20
;
2688 car_loop_apsk_low
= stv090x_s2_apsk_crl_cut20
;
2691 car_loop
= stv090x_s2_crl_cut30
;
2692 car_loop_qpsk_low
= stv090x_s2_lowqpsk_crl_cut30
;
2693 car_loop_apsk_low
= stv090x_s2_apsk_crl_cut30
;
2696 if (modcod
< STV090x_QPSK_12
) {
2698 while ((i
< 3) && (modcod
!= car_loop_qpsk_low
[i
].modcod
))
2706 while ((i
< 14) && (modcod
!= car_loop
[i
].modcod
))
2711 while ((i
< 11) && (modcod
!= car_loop_apsk_low
[i
].modcod
))
2719 if (modcod
<= STV090x_QPSK_25
) {
2721 if (state
->srate
<= 3000000)
2722 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_2
;
2723 else if (state
->srate
<= 7000000)
2724 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_5
;
2725 else if (state
->srate
<= 15000000)
2726 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_10
;
2727 else if (state
->srate
<= 25000000)
2728 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_20
;
2730 aclc
= car_loop_qpsk_low
[i
].crl_pilots_on_30
;
2732 if (state
->srate
<= 3000000)
2733 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_2
;
2734 else if (state
->srate
<= 7000000)
2735 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_5
;
2736 else if (state
->srate
<= 15000000)
2737 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_10
;
2738 else if (state
->srate
<= 25000000)
2739 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_20
;
2741 aclc
= car_loop_qpsk_low
[i
].crl_pilots_off_30
;
2744 } else if (modcod
<= STV090x_8PSK_910
) {
2746 if (state
->srate
<= 3000000)
2747 aclc
= car_loop
[i
].crl_pilots_on_2
;
2748 else if (state
->srate
<= 7000000)
2749 aclc
= car_loop
[i
].crl_pilots_on_5
;
2750 else if (state
->srate
<= 15000000)
2751 aclc
= car_loop
[i
].crl_pilots_on_10
;
2752 else if (state
->srate
<= 25000000)
2753 aclc
= car_loop
[i
].crl_pilots_on_20
;
2755 aclc
= car_loop
[i
].crl_pilots_on_30
;
2757 if (state
->srate
<= 3000000)
2758 aclc
= car_loop
[i
].crl_pilots_off_2
;
2759 else if (state
->srate
<= 7000000)
2760 aclc
= car_loop
[i
].crl_pilots_off_5
;
2761 else if (state
->srate
<= 15000000)
2762 aclc
= car_loop
[i
].crl_pilots_off_10
;
2763 else if (state
->srate
<= 25000000)
2764 aclc
= car_loop
[i
].crl_pilots_off_20
;
2766 aclc
= car_loop
[i
].crl_pilots_off_30
;
2768 } else { /* 16APSK and 32APSK */
2770 * This should never happen in practice, except if
2771 * something is really wrong at the car_loop table.
2775 if (state
->srate
<= 3000000)
2776 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_2
;
2777 else if (state
->srate
<= 7000000)
2778 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_5
;
2779 else if (state
->srate
<= 15000000)
2780 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_10
;
2781 else if (state
->srate
<= 25000000)
2782 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_20
;
2784 aclc
= car_loop_apsk_low
[i
].crl_pilots_on_30
;
2790 static u8
stv090x_optimize_carloop_short(struct stv090x_state
*state
)
2792 struct stv090x_short_frame_crloop
*short_crl
= NULL
;
2796 switch (state
->modulation
) {
2804 case STV090x_16APSK
:
2807 case STV090x_32APSK
:
2812 if (state
->internal
->dev_ver
>= 0x30) {
2813 /* Cut 3.0 and up */
2814 short_crl
= stv090x_s2_short_crl_cut30
;
2816 /* Cut 2.0 and up: we don't support cuts older than 2.0 */
2817 short_crl
= stv090x_s2_short_crl_cut20
;
2820 if (state
->srate
<= 3000000)
2821 aclc
= short_crl
[index
].crl_2
;
2822 else if (state
->srate
<= 7000000)
2823 aclc
= short_crl
[index
].crl_5
;
2824 else if (state
->srate
<= 15000000)
2825 aclc
= short_crl
[index
].crl_10
;
2826 else if (state
->srate
<= 25000000)
2827 aclc
= short_crl
[index
].crl_20
;
2829 aclc
= short_crl
[index
].crl_30
;
2834 static int stv090x_optimize_track(struct stv090x_state
*state
)
2836 struct dvb_frontend
*fe
= &state
->frontend
;
2838 enum stv090x_modcod modcod
;
2840 s32 srate
, pilots
, aclc
, f_1
, f_0
, i
= 0, blind_tune
= 0;
2843 srate
= stv090x_get_srate(state
, state
->internal
->mclk
);
2844 srate
+= stv090x_get_tmgoffst(state
, srate
);
2846 switch (state
->delsys
) {
2849 if (state
->search_mode
== STV090x_SEARCH_AUTO
) {
2850 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2851 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
2852 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 0);
2853 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2856 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
2857 STV090x_SETFIELD_Px(reg
, ROLLOFF_CONTROL_FIELD
, state
->rolloff
);
2858 STV090x_SETFIELD_Px(reg
, MANUAL_SXROLLOFF_FIELD
, 0x01);
2859 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
2862 if (state
->internal
->dev_ver
>= 0x30) {
2863 if (stv090x_get_viterbi(state
) < 0)
2866 if (state
->fec
== STV090x_PR12
) {
2867 if (STV090x_WRITE_DEMOD(state
, GAUSSR0
, 0x98) < 0)
2869 if (STV090x_WRITE_DEMOD(state
, CCIR0
, 0x18) < 0)
2872 if (STV090x_WRITE_DEMOD(state
, GAUSSR0
, 0x18) < 0)
2874 if (STV090x_WRITE_DEMOD(state
, CCIR0
, 0x18) < 0)
2879 if (STV090x_WRITE_DEMOD(state
, ERRCTRL1
, 0x75) < 0)
2884 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2885 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 0);
2886 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 1);
2887 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2889 if (state
->internal
->dev_ver
>= 0x30) {
2890 if (STV090x_WRITE_DEMOD(state
, ACLC
, 0) < 0)
2892 if (STV090x_WRITE_DEMOD(state
, BCLC
, 0) < 0)
2895 if (state
->frame_len
== STV090x_LONG_FRAME
) {
2896 reg
= STV090x_READ_DEMOD(state
, DMDMODCOD
);
2897 modcod
= STV090x_GETFIELD_Px(reg
, DEMOD_MODCOD_FIELD
);
2898 pilots
= STV090x_GETFIELD_Px(reg
, DEMOD_TYPE_FIELD
) & 0x01;
2899 aclc
= stv090x_optimize_carloop(state
, modcod
, pilots
);
2900 if (modcod
<= STV090x_QPSK_910
) {
2901 STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, aclc
);
2902 } else if (modcod
<= STV090x_8PSK_910
) {
2903 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2905 if (STV090x_WRITE_DEMOD(state
, ACLC2S28
, aclc
) < 0)
2908 if ((state
->demod_mode
== STV090x_SINGLE
) && (modcod
> STV090x_8PSK_910
)) {
2909 if (modcod
<= STV090x_16APSK_910
) {
2910 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2912 if (STV090x_WRITE_DEMOD(state
, ACLC2S216A
, aclc
) < 0)
2915 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2917 if (STV090x_WRITE_DEMOD(state
, ACLC2S232A
, aclc
) < 0)
2922 /*Carrier loop setting for short frame*/
2923 aclc
= stv090x_optimize_carloop_short(state
);
2924 if (state
->modulation
== STV090x_QPSK
) {
2925 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, aclc
) < 0)
2927 } else if (state
->modulation
== STV090x_8PSK
) {
2928 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2930 if (STV090x_WRITE_DEMOD(state
, ACLC2S28
, aclc
) < 0)
2932 } else if (state
->modulation
== STV090x_16APSK
) {
2933 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2935 if (STV090x_WRITE_DEMOD(state
, ACLC2S216A
, aclc
) < 0)
2937 } else if (state
->modulation
== STV090x_32APSK
) {
2938 if (STV090x_WRITE_DEMOD(state
, ACLC2S2Q
, 0x2a) < 0)
2940 if (STV090x_WRITE_DEMOD(state
, ACLC2S232A
, aclc
) < 0)
2945 STV090x_WRITE_DEMOD(state
, ERRCTRL1
, 0x67); /* PER */
2950 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2951 STV090x_SETFIELD_Px(reg
, DVBS1_ENABLE_FIELD
, 1);
2952 STV090x_SETFIELD_Px(reg
, DVBS2_ENABLE_FIELD
, 1);
2953 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2958 f_1
= STV090x_READ_DEMOD(state
, CFR2
);
2959 f_0
= STV090x_READ_DEMOD(state
, CFR1
);
2960 reg
= STV090x_READ_DEMOD(state
, TMGOBS
);
2962 if (state
->algo
== STV090x_BLIND_SEARCH
) {
2963 STV090x_WRITE_DEMOD(state
, SFRSTEP
, 0x00);
2964 reg
= STV090x_READ_DEMOD(state
, DMDCFGMD
);
2965 STV090x_SETFIELD_Px(reg
, SCAN_ENABLE_FIELD
, 0x00);
2966 STV090x_SETFIELD_Px(reg
, CFR_AUTOSCAN_FIELD
, 0x00);
2967 if (STV090x_WRITE_DEMOD(state
, DMDCFGMD
, reg
) < 0)
2969 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc1) < 0)
2972 if (stv090x_set_srate(state
, srate
) < 0)
2976 if (stv090x_dvbs_track_crl(state
) < 0)
2980 if (state
->internal
->dev_ver
>= 0x20) {
2981 if ((state
->search_mode
== STV090x_SEARCH_DVBS1
) ||
2982 (state
->search_mode
== STV090x_SEARCH_DSS
) ||
2983 (state
->search_mode
== STV090x_SEARCH_AUTO
)) {
2985 if (STV090x_WRITE_DEMOD(state
, VAVSRVIT
, 0x0a) < 0)
2987 if (STV090x_WRITE_DEMOD(state
, VITSCALE
, 0x00) < 0)
2992 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
2995 /* AUTO tracking MODE */
2996 if (STV090x_WRITE_DEMOD(state
, SFRUP1
, 0x80) < 0)
2998 /* AUTO tracking MODE */
2999 if (STV090x_WRITE_DEMOD(state
, SFRLOW1
, 0x80) < 0)
3002 if ((state
->internal
->dev_ver
>= 0x20) || (blind_tune
== 1) ||
3003 (state
->srate
< 10000000)) {
3004 /* update initial carrier freq with the found freq offset */
3005 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, f_1
) < 0)
3007 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, f_0
) < 0)
3009 state
->tuner_bw
= stv090x_car_width(srate
, state
->rolloff
) + 10000000;
3011 if ((state
->internal
->dev_ver
>= 0x20) || (blind_tune
== 1)) {
3013 if (state
->algo
!= STV090x_WARM_SEARCH
) {
3015 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
3018 if (state
->config
->tuner_set_bandwidth
) {
3019 if (state
->config
->tuner_set_bandwidth(fe
, state
->tuner_bw
) < 0)
3023 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
3028 if ((state
->algo
== STV090x_BLIND_SEARCH
) || (state
->srate
< 10000000))
3029 msleep(50); /* blind search: wait 50ms for SR stabilization */
3033 stv090x_get_lock_tmg(state
);
3035 if (!(stv090x_get_dmdlock(state
, (state
->DemodTimeout
/ 2)))) {
3036 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
3038 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, f_1
) < 0)
3040 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, f_0
) < 0)
3042 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0)
3047 while ((!(stv090x_get_dmdlock(state
, (state
->DemodTimeout
/ 2)))) && (i
<= 2)) {
3049 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x1f) < 0)
3051 if (STV090x_WRITE_DEMOD(state
, CFRINIT1
, f_1
) < 0)
3053 if (STV090x_WRITE_DEMOD(state
, CFRINIT0
, f_0
) < 0)
3055 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x18) < 0)
3063 if (state
->internal
->dev_ver
>= 0x20) {
3064 if (STV090x_WRITE_DEMOD(state
, CARFREQ
, 0x49) < 0)
3068 if ((state
->delsys
== STV090x_DVBS1
) || (state
->delsys
== STV090x_DSS
))
3069 stv090x_set_vit_thtracq(state
);
3074 stv090x_i2c_gate_ctrl(state
, 0);
3076 dprintk(FE_ERROR
, 1, "I/O error");
3080 static int stv090x_get_feclock(struct stv090x_state
*state
, s32 timeout
)
3082 s32 timer
= 0, lock
= 0, stat
;
3085 while ((timer
< timeout
) && (!lock
)) {
3086 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
3087 stat
= STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
);
3090 case 0: /* searching */
3091 case 1: /* first PLH detected */
3096 case 2: /* DVB-S2 mode */
3097 reg
= STV090x_READ_DEMOD(state
, PDELSTATUS1
);
3098 lock
= STV090x_GETFIELD_Px(reg
, PKTDELIN_LOCK_FIELD
);
3101 case 3: /* DVB-S1/legacy mode */
3102 reg
= STV090x_READ_DEMOD(state
, VSTATUSVIT
);
3103 lock
= STV090x_GETFIELD_Px(reg
, LOCKEDVIT_FIELD
);
3114 static int stv090x_get_lock(struct stv090x_state
*state
, s32 timeout_dmd
, s32 timeout_fec
)
3120 lock
= stv090x_get_dmdlock(state
, timeout_dmd
);
3122 lock
= stv090x_get_feclock(state
, timeout_fec
);
3127 while ((timer
< timeout_fec
) && (!lock
)) {
3128 reg
= STV090x_READ_DEMOD(state
, TSSTATUS
);
3129 lock
= STV090x_GETFIELD_Px(reg
, TSFIFO_LINEOK_FIELD
);
3138 static int stv090x_set_s2rolloff(struct stv090x_state
*state
)
3142 if (state
->internal
->dev_ver
<= 0x20) {
3143 /* rolloff to auto mode if DVBS2 */
3144 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
3145 STV090x_SETFIELD_Px(reg
, MANUAL_SXROLLOFF_FIELD
, 0x00);
3146 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
3149 /* DVB-S2 rolloff to auto mode if DVBS2 */
3150 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
3151 STV090x_SETFIELD_Px(reg
, MANUAL_S2ROLLOFF_FIELD
, 0x00);
3152 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
3157 dprintk(FE_ERROR
, 1, "I/O error");
3162 static enum stv090x_signal_state
stv090x_algo(struct stv090x_state
*state
)
3164 struct dvb_frontend
*fe
= &state
->frontend
;
3165 enum stv090x_signal_state signal_state
= STV090x_NOCARRIER
;
3167 s32 agc1_power
, power_iq
= 0, i
;
3168 int lock
= 0, low_sr
= 0;
3170 reg
= STV090x_READ_DEMOD(state
, TSCFGH
);
3171 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 1); /* Stop path 1 stream merger */
3172 if (STV090x_WRITE_DEMOD(state
, TSCFGH
, reg
) < 0)
3175 if (STV090x_WRITE_DEMOD(state
, DMDISTATE
, 0x5c) < 0) /* Demod stop */
3178 if (state
->internal
->dev_ver
>= 0x20) {
3179 if (state
->srate
> 5000000) {
3180 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x9e) < 0)
3183 if (STV090x_WRITE_DEMOD(state
, CORRELABS
, 0x82) < 0)
3188 stv090x_get_lock_tmg(state
);
3190 if (state
->algo
== STV090x_BLIND_SEARCH
) {
3191 state
->tuner_bw
= 2 * 36000000; /* wide bw for unknown srate */
3192 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc0) < 0) /* wider srate scan */
3194 if (STV090x_WRITE_DEMOD(state
, CORRELMANT
, 0x70) < 0)
3196 if (stv090x_set_srate(state
, 1000000) < 0) /* initial srate = 1Msps */
3200 if (STV090x_WRITE_DEMOD(state
, DMDTOM
, 0x20) < 0)
3202 if (STV090x_WRITE_DEMOD(state
, TMGCFG
, 0xd2) < 0)
3205 if (state
->srate
< 2000000) {
3207 if (STV090x_WRITE_DEMOD(state
, CORRELMANT
, 0x63) < 0)
3211 if (STV090x_WRITE_DEMOD(state
, CORRELMANT
, 0x70) < 0)
3215 if (STV090x_WRITE_DEMOD(state
, AGC2REF
, 0x38) < 0)
3218 if (state
->internal
->dev_ver
>= 0x20) {
3219 if (STV090x_WRITE_DEMOD(state
, KREFTMG
, 0x5a) < 0)
3221 if (state
->algo
== STV090x_COLD_SEARCH
)
3222 state
->tuner_bw
= (15 * (stv090x_car_width(state
->srate
, state
->rolloff
) + 10000000)) / 10;
3223 else if (state
->algo
== STV090x_WARM_SEARCH
)
3224 state
->tuner_bw
= stv090x_car_width(state
->srate
, state
->rolloff
) + 10000000;
3227 /* if cold start or warm (Symbolrate is known)
3228 * use a Narrow symbol rate scan range
3230 if (STV090x_WRITE_DEMOD(state
, TMGCFG2
, 0xc1) < 0) /* narrow srate scan */
3233 if (stv090x_set_srate(state
, state
->srate
) < 0)
3236 if (stv090x_set_max_srate(state
, state
->internal
->mclk
,
3239 if (stv090x_set_min_srate(state
, state
->internal
->mclk
,
3243 if (state
->srate
>= 10000000)
3250 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
3253 if (state
->config
->tuner_set_bbgain
) {
3254 reg
= state
->config
->tuner_bbgain
;
3256 reg
= 10; /* default: 10dB */
3257 if (state
->config
->tuner_set_bbgain(fe
, reg
) < 0)
3261 if (state
->config
->tuner_set_frequency
) {
3262 if (state
->config
->tuner_set_frequency(fe
, state
->frequency
) < 0)
3266 if (state
->config
->tuner_set_bandwidth
) {
3267 if (state
->config
->tuner_set_bandwidth(fe
, state
->tuner_bw
) < 0)
3271 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
3276 if (state
->config
->tuner_get_status
) {
3277 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
3279 if (state
->config
->tuner_get_status(fe
, ®
) < 0)
3281 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
3285 dprintk(FE_DEBUG
, 1, "Tuner phase locked");
3287 dprintk(FE_DEBUG
, 1, "Tuner unlocked");
3288 return STV090x_NOCARRIER
;
3293 agc1_power
= MAKEWORD16(STV090x_READ_DEMOD(state
, AGCIQIN1
),
3294 STV090x_READ_DEMOD(state
, AGCIQIN0
));
3296 if (agc1_power
== 0) {
3297 /* If AGC1 integrator value is 0
3298 * then read POWERI, POWERQ
3300 for (i
= 0; i
< 5; i
++) {
3301 power_iq
+= (STV090x_READ_DEMOD(state
, POWERI
) +
3302 STV090x_READ_DEMOD(state
, POWERQ
)) >> 1;
3307 if ((agc1_power
== 0) && (power_iq
< STV090x_IQPOWER_THRESHOLD
)) {
3308 dprintk(FE_ERROR
, 1, "No Signal: POWER_IQ=0x%02x", power_iq
);
3310 signal_state
= STV090x_NOAGC1
;
3312 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
3313 STV090x_SETFIELD_Px(reg
, SPECINV_CONTROL_FIELD
, state
->inversion
);
3315 if (state
->internal
->dev_ver
<= 0x20) {
3316 /* rolloff to auto mode if DVBS2 */
3317 STV090x_SETFIELD_Px(reg
, MANUAL_SXROLLOFF_FIELD
, 1);
3319 /* DVB-S2 rolloff to auto mode if DVBS2 */
3320 STV090x_SETFIELD_Px(reg
, MANUAL_S2ROLLOFF_FIELD
, 1);
3322 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
3325 if (stv090x_delivery_search(state
) < 0)
3328 if (state
->algo
!= STV090x_BLIND_SEARCH
) {
3329 if (stv090x_start_search(state
) < 0)
3334 if (signal_state
== STV090x_NOAGC1
)
3335 return signal_state
;
3337 if (state
->algo
== STV090x_BLIND_SEARCH
)
3338 lock
= stv090x_blind_search(state
);
3340 else if (state
->algo
== STV090x_COLD_SEARCH
)
3341 lock
= stv090x_get_coldlock(state
, state
->DemodTimeout
);
3343 else if (state
->algo
== STV090x_WARM_SEARCH
)
3344 lock
= stv090x_get_dmdlock(state
, state
->DemodTimeout
);
3346 if ((!lock
) && (state
->algo
== STV090x_COLD_SEARCH
)) {
3348 if (stv090x_chk_tmg(state
))
3349 lock
= stv090x_sw_algo(state
);
3354 signal_state
= stv090x_get_sig_params(state
);
3356 if ((lock
) && (signal_state
== STV090x_RANGEOK
)) { /* signal within Range */
3357 stv090x_optimize_track(state
);
3359 if (state
->internal
->dev_ver
>= 0x20) {
3360 /* >= Cut 2.0 :release TS reset after
3361 * demod lock and optimized Tracking
3363 reg
= STV090x_READ_DEMOD(state
, TSCFGH
);
3364 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0); /* release merger reset */
3365 if (STV090x_WRITE_DEMOD(state
, TSCFGH
, reg
) < 0)
3370 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 1); /* merger reset */
3371 if (STV090x_WRITE_DEMOD(state
, TSCFGH
, reg
) < 0)
3374 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0); /* release merger reset */
3375 if (STV090x_WRITE_DEMOD(state
, TSCFGH
, reg
) < 0)
3379 lock
= stv090x_get_lock(state
, state
->FecTimeout
,
3382 if (state
->delsys
== STV090x_DVBS2
) {
3383 stv090x_set_s2rolloff(state
);
3385 reg
= STV090x_READ_DEMOD(state
, PDELCTRL2
);
3386 STV090x_SETFIELD_Px(reg
, RESET_UPKO_COUNT
, 1);
3387 if (STV090x_WRITE_DEMOD(state
, PDELCTRL2
, reg
) < 0)
3389 /* Reset DVBS2 packet delinator error counter */
3390 reg
= STV090x_READ_DEMOD(state
, PDELCTRL2
);
3391 STV090x_SETFIELD_Px(reg
, RESET_UPKO_COUNT
, 0);
3392 if (STV090x_WRITE_DEMOD(state
, PDELCTRL2
, reg
) < 0)
3395 if (STV090x_WRITE_DEMOD(state
, ERRCTRL1
, 0x67) < 0) /* PER */
3398 if (STV090x_WRITE_DEMOD(state
, ERRCTRL1
, 0x75) < 0)
3401 /* Reset the Total packet counter */
3402 if (STV090x_WRITE_DEMOD(state
, FBERCPT4
, 0x00) < 0)
3404 /* Reset the packet Error counter2 */
3405 if (STV090x_WRITE_DEMOD(state
, ERRCTRL2
, 0xc1) < 0)
3408 signal_state
= STV090x_NODATA
;
3409 stv090x_chk_signal(state
);
3412 return signal_state
;
3415 stv090x_i2c_gate_ctrl(state
, 0);
3417 dprintk(FE_ERROR
, 1, "I/O error");
3421 static int stv090x_set_pls(struct stv090x_state
*state
, u32 pls_code
)
3423 dprintk(FE_DEBUG
, 1, "Set Gold PLS code %d", pls_code
);
3424 if (STV090x_WRITE_DEMOD(state
, PLROOT0
, pls_code
& 0xff) < 0)
3426 if (STV090x_WRITE_DEMOD(state
, PLROOT1
, (pls_code
>> 8) & 0xff) < 0)
3428 if (STV090x_WRITE_DEMOD(state
, PLROOT2
, 0x04 | (pls_code
>> 16)) < 0)
3432 dprintk(FE_ERROR
, 1, "I/O error");
3436 static int stv090x_set_mis(struct stv090x_state
*state
, int mis
)
3440 if (mis
< 0 || mis
> 255) {
3441 dprintk(FE_DEBUG
, 1, "Disable MIS filtering");
3442 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
3443 STV090x_SETFIELD_Px(reg
, FILTER_EN_FIELD
, 0x00);
3444 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
3447 dprintk(FE_DEBUG
, 1, "Enable MIS filtering - %d", mis
);
3448 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
3449 STV090x_SETFIELD_Px(reg
, FILTER_EN_FIELD
, 0x01);
3450 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
3452 if (STV090x_WRITE_DEMOD(state
, ISIENTRY
, mis
) < 0)
3454 if (STV090x_WRITE_DEMOD(state
, ISIBITENA
, 0xff) < 0)
3459 dprintk(FE_ERROR
, 1, "I/O error");
3463 static enum dvbfe_search
stv090x_search(struct dvb_frontend
*fe
)
3465 struct stv090x_state
*state
= fe
->demodulator_priv
;
3466 struct dtv_frontend_properties
*props
= &fe
->dtv_property_cache
;
3468 if (props
->frequency
== 0)
3469 return DVBFE_ALGO_SEARCH_INVALID
;
3471 switch (props
->delivery_system
) {
3473 state
->delsys
= STV090x_DSS
;
3476 state
->delsys
= STV090x_DVBS1
;
3479 state
->delsys
= STV090x_DVBS2
;
3482 return DVBFE_ALGO_SEARCH_INVALID
;
3485 state
->frequency
= props
->frequency
;
3486 state
->srate
= props
->symbol_rate
;
3487 state
->search_mode
= STV090x_SEARCH_AUTO
;
3488 state
->algo
= STV090x_COLD_SEARCH
;
3489 state
->fec
= STV090x_PRERR
;
3490 if (state
->srate
> 10000000) {
3491 dprintk(FE_DEBUG
, 1, "Search range: 10 MHz");
3492 state
->search_range
= 10000000;
3494 dprintk(FE_DEBUG
, 1, "Search range: 5 MHz");
3495 state
->search_range
= 5000000;
3498 stv090x_set_pls(state
, props
->scrambling_sequence_index
);
3499 stv090x_set_mis(state
, props
->stream_id
);
3501 if (stv090x_algo(state
) == STV090x_RANGEOK
) {
3502 dprintk(FE_DEBUG
, 1, "Search success!");
3503 return DVBFE_ALGO_SEARCH_SUCCESS
;
3505 dprintk(FE_DEBUG
, 1, "Search failed!");
3506 return DVBFE_ALGO_SEARCH_FAILED
;
3509 return DVBFE_ALGO_SEARCH_ERROR
;
3512 static int stv090x_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
3514 struct stv090x_state
*state
= fe
->demodulator_priv
;
3520 dstatus
= STV090x_READ_DEMOD(state
, DSTATUS
);
3521 if (STV090x_GETFIELD_Px(dstatus
, CAR_LOCK_FIELD
))
3522 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
;
3524 reg
= STV090x_READ_DEMOD(state
, DMDSTATE
);
3525 search_state
= STV090x_GETFIELD_Px(reg
, HEADER_MODE_FIELD
);
3527 switch (search_state
) {
3528 case 0: /* searching */
3529 case 1: /* first PLH detected */
3531 dprintk(FE_DEBUG
, 1, "Status: Unlocked (Searching ..)");
3534 case 2: /* DVB-S2 mode */
3535 dprintk(FE_DEBUG
, 1, "Delivery system: DVB-S2");
3536 if (STV090x_GETFIELD_Px(dstatus
, LOCK_DEFINITIF_FIELD
)) {
3537 reg
= STV090x_READ_DEMOD(state
, PDELSTATUS1
);
3538 if (STV090x_GETFIELD_Px(reg
, PKTDELIN_LOCK_FIELD
)) {
3539 *status
|= FE_HAS_VITERBI
;
3540 reg
= STV090x_READ_DEMOD(state
, TSSTATUS
);
3541 if (STV090x_GETFIELD_Px(reg
, TSFIFO_LINEOK_FIELD
))
3542 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
3547 case 3: /* DVB-S1/legacy mode */
3548 dprintk(FE_DEBUG
, 1, "Delivery system: DVB-S");
3549 if (STV090x_GETFIELD_Px(dstatus
, LOCK_DEFINITIF_FIELD
)) {
3550 reg
= STV090x_READ_DEMOD(state
, VSTATUSVIT
);
3551 if (STV090x_GETFIELD_Px(reg
, LOCKEDVIT_FIELD
)) {
3552 *status
|= FE_HAS_VITERBI
;
3553 reg
= STV090x_READ_DEMOD(state
, TSSTATUS
);
3554 if (STV090x_GETFIELD_Px(reg
, TSFIFO_LINEOK_FIELD
))
3555 *status
|= FE_HAS_SYNC
| FE_HAS_LOCK
;
3564 static int stv090x_read_per(struct dvb_frontend
*fe
, u32
*per
)
3566 struct stv090x_state
*state
= fe
->demodulator_priv
;
3568 s32 count_4
, count_3
, count_2
, count_1
, count_0
, count
;
3570 enum fe_status status
;
3572 stv090x_read_status(fe
, &status
);
3573 if (!(status
& FE_HAS_LOCK
)) {
3574 *per
= 1 << 23; /* Max PER */
3577 reg
= STV090x_READ_DEMOD(state
, ERRCNT22
);
3578 h
= STV090x_GETFIELD_Px(reg
, ERR_CNT2_FIELD
);
3580 reg
= STV090x_READ_DEMOD(state
, ERRCNT21
);
3581 m
= STV090x_GETFIELD_Px(reg
, ERR_CNT21_FIELD
);
3583 reg
= STV090x_READ_DEMOD(state
, ERRCNT20
);
3584 l
= STV090x_GETFIELD_Px(reg
, ERR_CNT20_FIELD
);
3586 *per
= ((h
<< 16) | (m
<< 8) | l
);
3588 count_4
= STV090x_READ_DEMOD(state
, FBERCPT4
);
3589 count_3
= STV090x_READ_DEMOD(state
, FBERCPT3
);
3590 count_2
= STV090x_READ_DEMOD(state
, FBERCPT2
);
3591 count_1
= STV090x_READ_DEMOD(state
, FBERCPT1
);
3592 count_0
= STV090x_READ_DEMOD(state
, FBERCPT0
);
3594 if ((!count_4
) && (!count_3
)) {
3595 count
= (count_2
& 0xff) << 16;
3596 count
|= (count_1
& 0xff) << 8;
3597 count
|= count_0
& 0xff;
3604 if (STV090x_WRITE_DEMOD(state
, FBERCPT4
, 0) < 0)
3606 if (STV090x_WRITE_DEMOD(state
, ERRCTRL2
, 0xc1) < 0)
3611 dprintk(FE_ERROR
, 1, "I/O error");
3615 static int stv090x_table_lookup(const struct stv090x_tab
*tab
, int max
, int val
)
3620 if ((val
>= tab
[min
].read
&& val
< tab
[max
].read
) ||
3621 (val
>= tab
[max
].read
&& val
< tab
[min
].read
)) {
3622 while ((max
- min
) > 1) {
3623 med
= (max
+ min
) / 2;
3624 if ((val
>= tab
[min
].read
&& val
< tab
[med
].read
) ||
3625 (val
>= tab
[med
].read
&& val
< tab
[min
].read
))
3630 res
= ((val
- tab
[min
].read
) *
3631 (tab
[max
].real
- tab
[min
].real
) /
3632 (tab
[max
].read
- tab
[min
].read
)) +
3635 if (tab
[min
].read
< tab
[max
].read
) {
3636 if (val
< tab
[min
].read
)
3637 res
= tab
[min
].real
;
3638 else if (val
>= tab
[max
].read
)
3639 res
= tab
[max
].real
;
3641 if (val
>= tab
[min
].read
)
3642 res
= tab
[min
].real
;
3643 else if (val
< tab
[max
].read
)
3644 res
= tab
[max
].real
;
3651 static int stv090x_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
3653 struct stv090x_state
*state
= fe
->demodulator_priv
;
3655 s32 agc_0
, agc_1
, agc
;
3658 reg
= STV090x_READ_DEMOD(state
, AGCIQIN1
);
3659 agc_1
= STV090x_GETFIELD_Px(reg
, AGCIQ_VALUE_FIELD
);
3660 reg
= STV090x_READ_DEMOD(state
, AGCIQIN0
);
3661 agc_0
= STV090x_GETFIELD_Px(reg
, AGCIQ_VALUE_FIELD
);
3662 agc
= MAKEWORD16(agc_1
, agc_0
);
3664 str
= stv090x_table_lookup(stv090x_rf_tab
,
3665 ARRAY_SIZE(stv090x_rf_tab
) - 1, agc
);
3666 if (agc
> stv090x_rf_tab
[0].read
)
3668 else if (agc
< stv090x_rf_tab
[ARRAY_SIZE(stv090x_rf_tab
) - 1].read
)
3670 *strength
= (str
+ 100) * 0xFFFF / 100;
3675 static int stv090x_read_cnr(struct dvb_frontend
*fe
, u16
*cnr
)
3677 struct stv090x_state
*state
= fe
->demodulator_priv
;
3678 u32 reg_0
, reg_1
, reg
, i
;
3679 s32 val_0
, val_1
, val
= 0;
3684 switch (state
->delsys
) {
3686 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
3687 lock_f
= STV090x_GETFIELD_Px(reg
, LOCK_DEFINITIF_FIELD
);
3690 for (i
= 0; i
< 16; i
++) {
3691 reg_1
= STV090x_READ_DEMOD(state
, NNOSPLHT1
);
3692 val_1
= STV090x_GETFIELD_Px(reg_1
, NOSPLHT_NORMED_FIELD
);
3693 reg_0
= STV090x_READ_DEMOD(state
, NNOSPLHT0
);
3694 val_0
= STV090x_GETFIELD_Px(reg_0
, NOSPLHT_NORMED_FIELD
);
3695 val
+= MAKEWORD16(val_1
, val_0
);
3699 last
= ARRAY_SIZE(stv090x_s2cn_tab
) - 1;
3700 div
= stv090x_s2cn_tab
[last
].real
-
3701 stv090x_s2cn_tab
[3].real
;
3702 val
= stv090x_table_lookup(stv090x_s2cn_tab
, last
, val
);
3705 *cnr
= val
* 0xFFFF / div
;
3711 reg
= STV090x_READ_DEMOD(state
, DSTATUS
);
3712 lock_f
= STV090x_GETFIELD_Px(reg
, LOCK_DEFINITIF_FIELD
);
3715 for (i
= 0; i
< 16; i
++) {
3716 reg_1
= STV090x_READ_DEMOD(state
, NOSDATAT1
);
3717 val_1
= STV090x_GETFIELD_Px(reg_1
, NOSDATAT_UNNORMED_FIELD
);
3718 reg_0
= STV090x_READ_DEMOD(state
, NOSDATAT0
);
3719 val_0
= STV090x_GETFIELD_Px(reg_0
, NOSDATAT_UNNORMED_FIELD
);
3720 val
+= MAKEWORD16(val_1
, val_0
);
3724 last
= ARRAY_SIZE(stv090x_s1cn_tab
) - 1;
3725 div
= stv090x_s1cn_tab
[last
].real
-
3726 stv090x_s1cn_tab
[0].real
;
3727 val
= stv090x_table_lookup(stv090x_s1cn_tab
, last
, val
);
3728 *cnr
= val
* 0xFFFF / div
;
3738 static int stv090x_set_tone(struct dvb_frontend
*fe
, enum fe_sec_tone_mode tone
)
3740 struct stv090x_state
*state
= fe
->demodulator_priv
;
3743 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3746 STV090x_SETFIELD_Px(reg
, DISTX_MODE_FIELD
, 0);
3747 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 1);
3748 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3750 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 0);
3751 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3756 STV090x_SETFIELD_Px(reg
, DISTX_MODE_FIELD
, 0);
3757 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 1);
3758 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3767 dprintk(FE_ERROR
, 1, "I/O error");
3772 static enum dvbfe_algo
stv090x_frontend_algo(struct dvb_frontend
*fe
)
3774 return DVBFE_ALGO_CUSTOM
;
3777 static int stv090x_send_diseqc_msg(struct dvb_frontend
*fe
, struct dvb_diseqc_master_cmd
*cmd
)
3779 struct stv090x_state
*state
= fe
->demodulator_priv
;
3780 u32 reg
, idle
= 0, fifo_full
= 1;
3783 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3785 STV090x_SETFIELD_Px(reg
, DISTX_MODE_FIELD
,
3786 (state
->config
->diseqc_envelope_mode
) ? 4 : 2);
3787 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 1);
3788 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3790 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 0);
3791 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3794 STV090x_SETFIELD_Px(reg
, DIS_PRECHARGE_FIELD
, 1);
3795 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3798 for (i
= 0; i
< cmd
->msg_len
; i
++) {
3801 reg
= STV090x_READ_DEMOD(state
, DISTXSTATUS
);
3802 fifo_full
= STV090x_GETFIELD_Px(reg
, FIFO_FULL_FIELD
);
3805 if (STV090x_WRITE_DEMOD(state
, DISTXDATA
, cmd
->msg
[i
]) < 0)
3808 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3809 STV090x_SETFIELD_Px(reg
, DIS_PRECHARGE_FIELD
, 0);
3810 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3815 while ((!idle
) && (i
< 10)) {
3816 reg
= STV090x_READ_DEMOD(state
, DISTXSTATUS
);
3817 idle
= STV090x_GETFIELD_Px(reg
, TX_IDLE_FIELD
);
3824 dprintk(FE_ERROR
, 1, "I/O error");
3828 static int stv090x_send_diseqc_burst(struct dvb_frontend
*fe
,
3829 enum fe_sec_mini_cmd burst
)
3831 struct stv090x_state
*state
= fe
->demodulator_priv
;
3832 u32 reg
, idle
= 0, fifo_full
= 1;
3836 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3838 if (burst
== SEC_MINI_A
) {
3839 mode
= (state
->config
->diseqc_envelope_mode
) ? 5 : 3;
3842 mode
= (state
->config
->diseqc_envelope_mode
) ? 4 : 2;
3846 STV090x_SETFIELD_Px(reg
, DISTX_MODE_FIELD
, mode
);
3847 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 1);
3848 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3850 STV090x_SETFIELD_Px(reg
, DISEQC_RESET_FIELD
, 0);
3851 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3854 STV090x_SETFIELD_Px(reg
, DIS_PRECHARGE_FIELD
, 1);
3855 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3859 reg
= STV090x_READ_DEMOD(state
, DISTXSTATUS
);
3860 fifo_full
= STV090x_GETFIELD_Px(reg
, FIFO_FULL_FIELD
);
3863 if (STV090x_WRITE_DEMOD(state
, DISTXDATA
, value
) < 0)
3866 reg
= STV090x_READ_DEMOD(state
, DISTXCTL
);
3867 STV090x_SETFIELD_Px(reg
, DIS_PRECHARGE_FIELD
, 0);
3868 if (STV090x_WRITE_DEMOD(state
, DISTXCTL
, reg
) < 0)
3873 while ((!idle
) && (i
< 10)) {
3874 reg
= STV090x_READ_DEMOD(state
, DISTXSTATUS
);
3875 idle
= STV090x_GETFIELD_Px(reg
, TX_IDLE_FIELD
);
3882 dprintk(FE_ERROR
, 1, "I/O error");
3886 static int stv090x_recv_slave_reply(struct dvb_frontend
*fe
, struct dvb_diseqc_slave_reply
*reply
)
3888 struct stv090x_state
*state
= fe
->demodulator_priv
;
3889 u32 reg
= 0, i
= 0, rx_end
= 0;
3891 while ((rx_end
!= 1) && (i
< 10)) {
3894 reg
= STV090x_READ_DEMOD(state
, DISRX_ST0
);
3895 rx_end
= STV090x_GETFIELD_Px(reg
, RX_END_FIELD
);
3899 reply
->msg_len
= STV090x_GETFIELD_Px(reg
, FIFO_BYTENBR_FIELD
);
3900 for (i
= 0; i
< reply
->msg_len
; i
++)
3901 reply
->msg
[i
] = STV090x_READ_DEMOD(state
, DISRXDATA
);
3907 static int stv090x_sleep(struct dvb_frontend
*fe
)
3909 struct stv090x_state
*state
= fe
->demodulator_priv
;
3911 u8 full_standby
= 0;
3913 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
3916 if (state
->config
->tuner_sleep
) {
3917 if (state
->config
->tuner_sleep(fe
) < 0)
3921 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
3924 dprintk(FE_DEBUG
, 1, "Set %s(%d) to sleep",
3925 state
->device
== STV0900
? "STV0900" : "STV0903",
3928 mutex_lock(&state
->internal
->demod_lock
);
3930 switch (state
->demod
) {
3931 case STV090x_DEMODULATOR_0
:
3932 /* power off ADC 1 */
3933 reg
= stv090x_read_reg(state
, STV090x_TSTTNR1
);
3934 STV090x_SETFIELD(reg
, ADC1_PON_FIELD
, 0);
3935 if (stv090x_write_reg(state
, STV090x_TSTTNR1
, reg
) < 0)
3937 /* power off DiSEqC 1 */
3938 reg
= stv090x_read_reg(state
, STV090x_TSTTNR2
);
3939 STV090x_SETFIELD(reg
, DISEQC1_PON_FIELD
, 0);
3940 if (stv090x_write_reg(state
, STV090x_TSTTNR2
, reg
) < 0)
3943 /* check whether path 2 is already sleeping, that is when
3945 reg
= stv090x_read_reg(state
, STV090x_TSTTNR3
);
3946 if (STV090x_GETFIELD(reg
, ADC2_PON_FIELD
) == 0)
3950 reg
= stv090x_read_reg(state
, STV090x_STOPCLK1
);
3951 /* packet delineator 1 clock */
3952 STV090x_SETFIELD(reg
, STOP_CLKPKDT1_FIELD
, 1);
3954 STV090x_SETFIELD(reg
, STOP_CLKADCI1_FIELD
, 1);
3955 /* FEC clock is shared between the two paths, only stop it
3956 when full standby is possible */
3958 STV090x_SETFIELD(reg
, STOP_CLKFEC_FIELD
, 1);
3959 if (stv090x_write_reg(state
, STV090x_STOPCLK1
, reg
) < 0)
3961 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
3962 /* sampling 1 clock */
3963 STV090x_SETFIELD(reg
, STOP_CLKSAMP1_FIELD
, 1);
3964 /* viterbi 1 clock */
3965 STV090x_SETFIELD(reg
, STOP_CLKVIT1_FIELD
, 1);
3966 /* TS clock is shared between the two paths, only stop it
3967 when full standby is possible */
3969 STV090x_SETFIELD(reg
, STOP_CLKTS_FIELD
, 1);
3970 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
3974 case STV090x_DEMODULATOR_1
:
3975 /* power off ADC 2 */
3976 reg
= stv090x_read_reg(state
, STV090x_TSTTNR3
);
3977 STV090x_SETFIELD(reg
, ADC2_PON_FIELD
, 0);
3978 if (stv090x_write_reg(state
, STV090x_TSTTNR3
, reg
) < 0)
3980 /* power off DiSEqC 2 */
3981 reg
= stv090x_read_reg(state
, STV090x_TSTTNR4
);
3982 STV090x_SETFIELD(reg
, DISEQC2_PON_FIELD
, 0);
3983 if (stv090x_write_reg(state
, STV090x_TSTTNR4
, reg
) < 0)
3986 /* check whether path 1 is already sleeping, that is when
3988 reg
= stv090x_read_reg(state
, STV090x_TSTTNR1
);
3989 if (STV090x_GETFIELD(reg
, ADC1_PON_FIELD
) == 0)
3993 reg
= stv090x_read_reg(state
, STV090x_STOPCLK1
);
3994 /* packet delineator 2 clock */
3995 STV090x_SETFIELD(reg
, STOP_CLKPKDT2_FIELD
, 1);
3997 STV090x_SETFIELD(reg
, STOP_CLKADCI2_FIELD
, 1);
3998 /* FEC clock is shared between the two paths, only stop it
3999 when full standby is possible */
4001 STV090x_SETFIELD(reg
, STOP_CLKFEC_FIELD
, 1);
4002 if (stv090x_write_reg(state
, STV090x_STOPCLK1
, reg
) < 0)
4004 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
4005 /* sampling 2 clock */
4006 STV090x_SETFIELD(reg
, STOP_CLKSAMP2_FIELD
, 1);
4007 /* viterbi 2 clock */
4008 STV090x_SETFIELD(reg
, STOP_CLKVIT2_FIELD
, 1);
4009 /* TS clock is shared between the two paths, only stop it
4010 when full standby is possible */
4012 STV090x_SETFIELD(reg
, STOP_CLKTS_FIELD
, 1);
4013 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
4018 dprintk(FE_ERROR
, 1, "Wrong demodulator!");
4023 /* general power off */
4024 reg
= stv090x_read_reg(state
, STV090x_SYNTCTRL
);
4025 STV090x_SETFIELD(reg
, STANDBY_FIELD
, 0x01);
4026 if (stv090x_write_reg(state
, STV090x_SYNTCTRL
, reg
) < 0)
4030 mutex_unlock(&state
->internal
->demod_lock
);
4034 stv090x_i2c_gate_ctrl(state
, 0);
4037 mutex_unlock(&state
->internal
->demod_lock
);
4039 dprintk(FE_ERROR
, 1, "I/O error");
4043 static int stv090x_wakeup(struct dvb_frontend
*fe
)
4045 struct stv090x_state
*state
= fe
->demodulator_priv
;
4048 dprintk(FE_DEBUG
, 1, "Wake %s(%d) from standby",
4049 state
->device
== STV0900
? "STV0900" : "STV0903",
4052 mutex_lock(&state
->internal
->demod_lock
);
4054 /* general power on */
4055 reg
= stv090x_read_reg(state
, STV090x_SYNTCTRL
);
4056 STV090x_SETFIELD(reg
, STANDBY_FIELD
, 0x00);
4057 if (stv090x_write_reg(state
, STV090x_SYNTCTRL
, reg
) < 0)
4060 switch (state
->demod
) {
4061 case STV090x_DEMODULATOR_0
:
4062 /* power on ADC 1 */
4063 reg
= stv090x_read_reg(state
, STV090x_TSTTNR1
);
4064 STV090x_SETFIELD(reg
, ADC1_PON_FIELD
, 1);
4065 if (stv090x_write_reg(state
, STV090x_TSTTNR1
, reg
) < 0)
4067 /* power on DiSEqC 1 */
4068 reg
= stv090x_read_reg(state
, STV090x_TSTTNR2
);
4069 STV090x_SETFIELD(reg
, DISEQC1_PON_FIELD
, 1);
4070 if (stv090x_write_reg(state
, STV090x_TSTTNR2
, reg
) < 0)
4073 /* activate clocks */
4074 reg
= stv090x_read_reg(state
, STV090x_STOPCLK1
);
4075 /* packet delineator 1 clock */
4076 STV090x_SETFIELD(reg
, STOP_CLKPKDT1_FIELD
, 0);
4078 STV090x_SETFIELD(reg
, STOP_CLKADCI1_FIELD
, 0);
4080 STV090x_SETFIELD(reg
, STOP_CLKFEC_FIELD
, 0);
4081 if (stv090x_write_reg(state
, STV090x_STOPCLK1
, reg
) < 0)
4083 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
4084 /* sampling 1 clock */
4085 STV090x_SETFIELD(reg
, STOP_CLKSAMP1_FIELD
, 0);
4086 /* viterbi 1 clock */
4087 STV090x_SETFIELD(reg
, STOP_CLKVIT1_FIELD
, 0);
4089 STV090x_SETFIELD(reg
, STOP_CLKTS_FIELD
, 0);
4090 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
4094 case STV090x_DEMODULATOR_1
:
4095 /* power on ADC 2 */
4096 reg
= stv090x_read_reg(state
, STV090x_TSTTNR3
);
4097 STV090x_SETFIELD(reg
, ADC2_PON_FIELD
, 1);
4098 if (stv090x_write_reg(state
, STV090x_TSTTNR3
, reg
) < 0)
4100 /* power on DiSEqC 2 */
4101 reg
= stv090x_read_reg(state
, STV090x_TSTTNR4
);
4102 STV090x_SETFIELD(reg
, DISEQC2_PON_FIELD
, 1);
4103 if (stv090x_write_reg(state
, STV090x_TSTTNR4
, reg
) < 0)
4106 /* activate clocks */
4107 reg
= stv090x_read_reg(state
, STV090x_STOPCLK1
);
4108 /* packet delineator 2 clock */
4109 STV090x_SETFIELD(reg
, STOP_CLKPKDT2_FIELD
, 0);
4111 STV090x_SETFIELD(reg
, STOP_CLKADCI2_FIELD
, 0);
4113 STV090x_SETFIELD(reg
, STOP_CLKFEC_FIELD
, 0);
4114 if (stv090x_write_reg(state
, STV090x_STOPCLK1
, reg
) < 0)
4116 reg
= stv090x_read_reg(state
, STV090x_STOPCLK2
);
4117 /* sampling 2 clock */
4118 STV090x_SETFIELD(reg
, STOP_CLKSAMP2_FIELD
, 0);
4119 /* viterbi 2 clock */
4120 STV090x_SETFIELD(reg
, STOP_CLKVIT2_FIELD
, 0);
4122 STV090x_SETFIELD(reg
, STOP_CLKTS_FIELD
, 0);
4123 if (stv090x_write_reg(state
, STV090x_STOPCLK2
, reg
) < 0)
4128 dprintk(FE_ERROR
, 1, "Wrong demodulator!");
4132 mutex_unlock(&state
->internal
->demod_lock
);
4135 mutex_unlock(&state
->internal
->demod_lock
);
4136 dprintk(FE_ERROR
, 1, "I/O error");
4140 static void stv090x_release(struct dvb_frontend
*fe
)
4142 struct stv090x_state
*state
= fe
->demodulator_priv
;
4144 state
->internal
->num_used
--;
4145 if (state
->internal
->num_used
<= 0) {
4147 dprintk(FE_ERROR
, 1, "Actually removing");
4149 remove_dev(state
->internal
);
4150 kfree(state
->internal
);
4156 static int stv090x_ldpc_mode(struct stv090x_state
*state
, enum stv090x_mode ldpc_mode
)
4160 reg
= stv090x_read_reg(state
, STV090x_GENCFG
);
4162 switch (ldpc_mode
) {
4165 if ((state
->demod_mode
!= STV090x_DUAL
) || (STV090x_GETFIELD(reg
, DDEMOD_FIELD
) != 1)) {
4166 /* set LDPC to dual mode */
4167 if (stv090x_write_reg(state
, STV090x_GENCFG
, 0x1d) < 0)
4170 state
->demod_mode
= STV090x_DUAL
;
4172 reg
= stv090x_read_reg(state
, STV090x_TSTRES0
);
4173 STV090x_SETFIELD(reg
, FRESFEC_FIELD
, 0x1);
4174 if (stv090x_write_reg(state
, STV090x_TSTRES0
, reg
) < 0)
4176 STV090x_SETFIELD(reg
, FRESFEC_FIELD
, 0x0);
4177 if (stv090x_write_reg(state
, STV090x_TSTRES0
, reg
) < 0)
4180 if (STV090x_WRITE_DEMOD(state
, MODCODLST0
, 0xff) < 0)
4182 if (STV090x_WRITE_DEMOD(state
, MODCODLST1
, 0xff) < 0)
4184 if (STV090x_WRITE_DEMOD(state
, MODCODLST2
, 0xff) < 0)
4186 if (STV090x_WRITE_DEMOD(state
, MODCODLST3
, 0xff) < 0)
4188 if (STV090x_WRITE_DEMOD(state
, MODCODLST4
, 0xff) < 0)
4190 if (STV090x_WRITE_DEMOD(state
, MODCODLST5
, 0xff) < 0)
4192 if (STV090x_WRITE_DEMOD(state
, MODCODLST6
, 0xff) < 0)
4195 if (STV090x_WRITE_DEMOD(state
, MODCODLST7
, 0xcc) < 0)
4197 if (STV090x_WRITE_DEMOD(state
, MODCODLST8
, 0xcc) < 0)
4199 if (STV090x_WRITE_DEMOD(state
, MODCODLST9
, 0xcc) < 0)
4201 if (STV090x_WRITE_DEMOD(state
, MODCODLSTA
, 0xcc) < 0)
4203 if (STV090x_WRITE_DEMOD(state
, MODCODLSTB
, 0xcc) < 0)
4205 if (STV090x_WRITE_DEMOD(state
, MODCODLSTC
, 0xcc) < 0)
4207 if (STV090x_WRITE_DEMOD(state
, MODCODLSTD
, 0xcc) < 0)
4210 if (STV090x_WRITE_DEMOD(state
, MODCODLSTE
, 0xff) < 0)
4212 if (STV090x_WRITE_DEMOD(state
, MODCODLSTF
, 0xcf) < 0)
4217 case STV090x_SINGLE
:
4218 if (stv090x_stop_modcod(state
) < 0)
4220 if (stv090x_activate_modcod_single(state
) < 0)
4223 if (state
->demod
== STV090x_DEMODULATOR_1
) {
4224 if (stv090x_write_reg(state
, STV090x_GENCFG
, 0x06) < 0) /* path 2 */
4227 if (stv090x_write_reg(state
, STV090x_GENCFG
, 0x04) < 0) /* path 1 */
4231 reg
= stv090x_read_reg(state
, STV090x_TSTRES0
);
4232 STV090x_SETFIELD(reg
, FRESFEC_FIELD
, 0x1);
4233 if (stv090x_write_reg(state
, STV090x_TSTRES0
, reg
) < 0)
4235 STV090x_SETFIELD(reg
, FRESFEC_FIELD
, 0x0);
4236 if (stv090x_write_reg(state
, STV090x_TSTRES0
, reg
) < 0)
4239 reg
= STV090x_READ_DEMOD(state
, PDELCTRL1
);
4240 STV090x_SETFIELD_Px(reg
, ALGOSWRST_FIELD
, 0x01);
4241 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
4243 STV090x_SETFIELD_Px(reg
, ALGOSWRST_FIELD
, 0x00);
4244 if (STV090x_WRITE_DEMOD(state
, PDELCTRL1
, reg
) < 0)
4251 dprintk(FE_ERROR
, 1, "I/O error");
4255 /* return (Hz), clk in Hz*/
4256 static u32
stv090x_get_mclk(struct stv090x_state
*state
)
4258 const struct stv090x_config
*config
= state
->config
;
4262 div
= stv090x_read_reg(state
, STV090x_NCOARSE
);
4263 reg
= stv090x_read_reg(state
, STV090x_SYNTCTRL
);
4264 ratio
= STV090x_GETFIELD(reg
, SELX1RATIO_FIELD
) ? 4 : 6;
4266 return (div
+ 1) * config
->xtal
/ ratio
; /* kHz */
4269 static int stv090x_set_mclk(struct stv090x_state
*state
, u32 mclk
, u32 clk
)
4271 const struct stv090x_config
*config
= state
->config
;
4272 u32 reg
, div
, clk_sel
;
4274 reg
= stv090x_read_reg(state
, STV090x_SYNTCTRL
);
4275 clk_sel
= ((STV090x_GETFIELD(reg
, SELX1RATIO_FIELD
) == 1) ? 4 : 6);
4277 div
= ((clk_sel
* mclk
) / config
->xtal
) - 1;
4279 reg
= stv090x_read_reg(state
, STV090x_NCOARSE
);
4280 STV090x_SETFIELD(reg
, M_DIV_FIELD
, div
);
4281 if (stv090x_write_reg(state
, STV090x_NCOARSE
, reg
) < 0)
4284 state
->internal
->mclk
= stv090x_get_mclk(state
);
4286 /*Set the DiseqC frequency to 22KHz */
4287 div
= state
->internal
->mclk
/ 704000;
4288 if (STV090x_WRITE_DEMOD(state
, F22TX
, div
) < 0)
4290 if (STV090x_WRITE_DEMOD(state
, F22RX
, div
) < 0)
4295 dprintk(FE_ERROR
, 1, "I/O error");
4299 static int stv0900_set_tspath(struct stv090x_state
*state
)
4303 if (state
->internal
->dev_ver
>= 0x20) {
4304 switch (state
->config
->ts1_mode
) {
4305 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4306 case STV090x_TSMODE_DVBCI
:
4307 switch (state
->config
->ts2_mode
) {
4308 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4309 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4311 stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x00);
4314 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4315 case STV090x_TSMODE_DVBCI
:
4316 if (stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x06) < 0) /* Mux'd stream mode */
4318 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4319 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4320 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4322 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGM
);
4323 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4324 if (stv090x_write_reg(state
, STV090x_P2_TSCFGM
, reg
) < 0)
4326 if (stv090x_write_reg(state
, STV090x_P1_TSSPEED
, 0x14) < 0)
4328 if (stv090x_write_reg(state
, STV090x_P2_TSSPEED
, 0x28) < 0)
4334 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4335 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4337 switch (state
->config
->ts2_mode
) {
4338 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4339 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4341 if (stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x0c) < 0)
4345 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4346 case STV090x_TSMODE_DVBCI
:
4347 if (stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x0a) < 0)
4354 switch (state
->config
->ts1_mode
) {
4355 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4356 case STV090x_TSMODE_DVBCI
:
4357 switch (state
->config
->ts2_mode
) {
4358 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4359 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4361 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x10);
4364 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4365 case STV090x_TSMODE_DVBCI
:
4366 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x16);
4367 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4368 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4369 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4371 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4372 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 0);
4373 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4375 if (stv090x_write_reg(state
, STV090x_P1_TSSPEED
, 0x14) < 0)
4377 if (stv090x_write_reg(state
, STV090x_P2_TSSPEED
, 0x28) < 0)
4383 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4384 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4386 switch (state
->config
->ts2_mode
) {
4387 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4388 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4390 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x14);
4393 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4394 case STV090x_TSMODE_DVBCI
:
4395 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x12);
4402 switch (state
->config
->ts1_mode
) {
4403 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4404 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4405 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts1_tei
);
4406 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4407 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4408 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4412 case STV090x_TSMODE_DVBCI
:
4413 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4414 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts1_tei
);
4415 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4416 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4417 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4421 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4422 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4423 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts1_tei
);
4424 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4425 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4426 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4430 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4431 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4432 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts1_tei
);
4433 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4434 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4435 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4443 switch (state
->config
->ts2_mode
) {
4444 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4445 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4446 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts2_tei
);
4447 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4448 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4449 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4453 case STV090x_TSMODE_DVBCI
:
4454 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4455 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts2_tei
);
4456 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4457 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4458 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4462 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4463 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4464 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts2_tei
);
4465 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4466 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4467 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4471 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4472 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4473 STV090x_SETFIELD_Px(reg
, TSFIFO_TEIUPDATE_FIELD
, state
->config
->ts2_tei
);
4474 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4475 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4476 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4484 if (state
->config
->ts1_clk
> 0) {
4487 switch (state
->config
->ts1_mode
) {
4488 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4489 case STV090x_TSMODE_DVBCI
:
4491 speed
= state
->internal
->mclk
/
4492 (state
->config
->ts1_clk
/ 4);
4498 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4499 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4500 speed
= state
->internal
->mclk
/
4501 (state
->config
->ts1_clk
/ 32);
4508 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4509 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4510 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4512 if (stv090x_write_reg(state
, STV090x_P1_TSSPEED
, speed
) < 0)
4516 if (state
->config
->ts2_clk
> 0) {
4519 switch (state
->config
->ts2_mode
) {
4520 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4521 case STV090x_TSMODE_DVBCI
:
4523 speed
= state
->internal
->mclk
/
4524 (state
->config
->ts2_clk
/ 4);
4530 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4531 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4532 speed
= state
->internal
->mclk
/
4533 (state
->config
->ts2_clk
/ 32);
4540 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGM
);
4541 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4542 if (stv090x_write_reg(state
, STV090x_P2_TSCFGM
, reg
) < 0)
4544 if (stv090x_write_reg(state
, STV090x_P2_TSSPEED
, speed
) < 0)
4548 reg
= stv090x_read_reg(state
, STV090x_P2_TSCFGH
);
4549 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x01);
4550 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4552 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x00);
4553 if (stv090x_write_reg(state
, STV090x_P2_TSCFGH
, reg
) < 0)
4556 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4557 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x01);
4558 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4560 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x00);
4561 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4566 dprintk(FE_ERROR
, 1, "I/O error");
4570 static int stv0903_set_tspath(struct stv090x_state
*state
)
4574 if (state
->internal
->dev_ver
>= 0x20) {
4575 switch (state
->config
->ts1_mode
) {
4576 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4577 case STV090x_TSMODE_DVBCI
:
4578 stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x00);
4581 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4582 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4584 stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x0c);
4588 switch (state
->config
->ts1_mode
) {
4589 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4590 case STV090x_TSMODE_DVBCI
:
4591 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x10);
4594 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4595 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4597 stv090x_write_reg(state
, STV090x_TSGENERAL1X
, 0x14);
4602 switch (state
->config
->ts1_mode
) {
4603 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4604 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4605 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4606 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4607 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4611 case STV090x_TSMODE_DVBCI
:
4612 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4613 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x00);
4614 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4615 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4619 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4620 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4621 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4622 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x00);
4623 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4627 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4628 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4629 STV090x_SETFIELD_Px(reg
, TSFIFO_SERIAL_FIELD
, 0x01);
4630 STV090x_SETFIELD_Px(reg
, TSFIFO_DVBCI_FIELD
, 0x01);
4631 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4639 if (state
->config
->ts1_clk
> 0) {
4642 switch (state
->config
->ts1_mode
) {
4643 case STV090x_TSMODE_PARALLEL_PUNCTURED
:
4644 case STV090x_TSMODE_DVBCI
:
4646 speed
= state
->internal
->mclk
/
4647 (state
->config
->ts1_clk
/ 4);
4653 case STV090x_TSMODE_SERIAL_PUNCTURED
:
4654 case STV090x_TSMODE_SERIAL_CONTINUOUS
:
4655 speed
= state
->internal
->mclk
/
4656 (state
->config
->ts1_clk
/ 32);
4663 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGM
);
4664 STV090x_SETFIELD_Px(reg
, TSFIFO_MANSPEED_FIELD
, 3);
4665 if (stv090x_write_reg(state
, STV090x_P1_TSCFGM
, reg
) < 0)
4667 if (stv090x_write_reg(state
, STV090x_P1_TSSPEED
, speed
) < 0)
4671 reg
= stv090x_read_reg(state
, STV090x_P1_TSCFGH
);
4672 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x01);
4673 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4675 STV090x_SETFIELD_Px(reg
, RST_HWARE_FIELD
, 0x00);
4676 if (stv090x_write_reg(state
, STV090x_P1_TSCFGH
, reg
) < 0)
4681 dprintk(FE_ERROR
, 1, "I/O error");
4685 static int stv090x_init(struct dvb_frontend
*fe
)
4687 struct stv090x_state
*state
= fe
->demodulator_priv
;
4688 const struct stv090x_config
*config
= state
->config
;
4691 if (state
->internal
->mclk
== 0) {
4692 /* call tuner init to configure the tuner's clock output
4693 divider directly before setting up the master clock of
4695 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
4698 if (config
->tuner_init
) {
4699 if (config
->tuner_init(fe
) < 0)
4703 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
4706 stv090x_set_mclk(state
, 135000000, config
->xtal
); /* 135 Mhz */
4708 if (stv090x_write_reg(state
, STV090x_SYNTCTRL
,
4709 0x20 | config
->clk_mode
) < 0)
4711 stv090x_get_mclk(state
);
4714 if (stv090x_wakeup(fe
) < 0) {
4715 dprintk(FE_ERROR
, 1, "Error waking device");
4719 if (stv090x_ldpc_mode(state
, state
->demod_mode
) < 0)
4722 reg
= STV090x_READ_DEMOD(state
, TNRCFG2
);
4723 STV090x_SETFIELD_Px(reg
, TUN_IQSWAP_FIELD
, state
->inversion
);
4724 if (STV090x_WRITE_DEMOD(state
, TNRCFG2
, reg
) < 0)
4726 reg
= STV090x_READ_DEMOD(state
, DEMOD
);
4727 STV090x_SETFIELD_Px(reg
, ROLLOFF_CONTROL_FIELD
, state
->rolloff
);
4728 if (STV090x_WRITE_DEMOD(state
, DEMOD
, reg
) < 0)
4731 if (stv090x_i2c_gate_ctrl(state
, 1) < 0)
4734 if (config
->tuner_set_mode
) {
4735 if (config
->tuner_set_mode(fe
, TUNER_WAKE
) < 0)
4739 if (config
->tuner_init
) {
4740 if (config
->tuner_init(fe
) < 0)
4744 if (stv090x_i2c_gate_ctrl(state
, 0) < 0)
4747 if (state
->device
== STV0900
) {
4748 if (stv0900_set_tspath(state
) < 0)
4751 if (stv0903_set_tspath(state
) < 0)
4758 stv090x_i2c_gate_ctrl(state
, 0);
4760 dprintk(FE_ERROR
, 1, "I/O error");
4764 static int stv090x_setup(struct dvb_frontend
*fe
)
4766 struct stv090x_state
*state
= fe
->demodulator_priv
;
4767 const struct stv090x_config
*config
= state
->config
;
4768 const struct stv090x_reg
*stv090x_initval
= NULL
;
4769 const struct stv090x_reg
*stv090x_cut20_val
= NULL
;
4770 unsigned long t1_size
= 0, t2_size
= 0;
4775 if (state
->device
== STV0900
) {
4776 dprintk(FE_DEBUG
, 1, "Initializing STV0900");
4777 stv090x_initval
= stv0900_initval
;
4778 t1_size
= ARRAY_SIZE(stv0900_initval
);
4779 stv090x_cut20_val
= stv0900_cut20_val
;
4780 t2_size
= ARRAY_SIZE(stv0900_cut20_val
);
4781 } else if (state
->device
== STV0903
) {
4782 dprintk(FE_DEBUG
, 1, "Initializing STV0903");
4783 stv090x_initval
= stv0903_initval
;
4784 t1_size
= ARRAY_SIZE(stv0903_initval
);
4785 stv090x_cut20_val
= stv0903_cut20_val
;
4786 t2_size
= ARRAY_SIZE(stv0903_cut20_val
);
4792 if (stv090x_write_reg(state
, STV090x_P1_DMDISTATE
, 0x5c) < 0)
4794 if (state
->device
== STV0900
)
4795 if (stv090x_write_reg(state
, STV090x_P2_DMDISTATE
, 0x5c) < 0)
4800 /* Set No Tuner Mode */
4801 if (stv090x_write_reg(state
, STV090x_P1_TNRCFG
, 0x6c) < 0)
4803 if (state
->device
== STV0900
)
4804 if (stv090x_write_reg(state
, STV090x_P2_TNRCFG
, 0x6c) < 0)
4807 /* I2C repeater OFF */
4808 STV090x_SETFIELD_Px(reg
, ENARPT_LEVEL_FIELD
, config
->repeater_level
);
4809 if (stv090x_write_reg(state
, STV090x_P1_I2CRPT
, reg
) < 0)
4811 if (state
->device
== STV0900
)
4812 if (stv090x_write_reg(state
, STV090x_P2_I2CRPT
, reg
) < 0)
4815 if (stv090x_write_reg(state
, STV090x_NCOARSE
, 0x13) < 0) /* set PLL divider */
4818 if (stv090x_write_reg(state
, STV090x_I2CCFG
, 0x08) < 0) /* 1/41 oversampling */
4820 if (stv090x_write_reg(state
, STV090x_SYNTCTRL
, 0x20 | config
->clk_mode
) < 0) /* enable PLL */
4825 dprintk(FE_DEBUG
, 1, "Setting up initial values");
4826 for (i
= 0; i
< t1_size
; i
++) {
4827 if (stv090x_write_reg(state
, stv090x_initval
[i
].addr
, stv090x_initval
[i
].data
) < 0)
4831 state
->internal
->dev_ver
= stv090x_read_reg(state
, STV090x_MID
);
4832 if (state
->internal
->dev_ver
>= 0x20) {
4833 if (stv090x_write_reg(state
, STV090x_TSGENERAL
, 0x0c) < 0)
4836 /* write cut20_val*/
4837 dprintk(FE_DEBUG
, 1, "Setting up Cut 2.0 initial values");
4838 for (i
= 0; i
< t2_size
; i
++) {
4839 if (stv090x_write_reg(state
, stv090x_cut20_val
[i
].addr
, stv090x_cut20_val
[i
].data
) < 0)
4843 } else if (state
->internal
->dev_ver
< 0x20) {
4844 dprintk(FE_ERROR
, 1, "ERROR: Unsupported Cut: 0x%02x!",
4845 state
->internal
->dev_ver
);
4848 } else if (state
->internal
->dev_ver
> 0x30) {
4849 /* we shouldn't bail out from here */
4850 dprintk(FE_ERROR
, 1, "INFO: Cut: 0x%02x probably incomplete support!",
4851 state
->internal
->dev_ver
);
4855 reg
= stv090x_read_reg(state
, STV090x_TSTTNR1
);
4856 STV090x_SETFIELD(reg
, ADC1_INMODE_FIELD
,
4857 (config
->adc1_range
== STV090x_ADC_1Vpp
) ? 0 : 1);
4858 if (stv090x_write_reg(state
, STV090x_TSTTNR1
, reg
) < 0)
4862 reg
= stv090x_read_reg(state
, STV090x_TSTTNR3
);
4863 STV090x_SETFIELD(reg
, ADC2_INMODE_FIELD
,
4864 (config
->adc2_range
== STV090x_ADC_1Vpp
) ? 0 : 1);
4865 if (stv090x_write_reg(state
, STV090x_TSTTNR3
, reg
) < 0)
4868 if (stv090x_write_reg(state
, STV090x_TSTRES0
, 0x80) < 0)
4870 if (stv090x_write_reg(state
, STV090x_TSTRES0
, 0x00) < 0)
4875 dprintk(FE_ERROR
, 1, "I/O error");
4879 static int stv090x_set_gpio(struct dvb_frontend
*fe
, u8 gpio
, u8 dir
,
4880 u8 value
, u8 xor_value
)
4882 struct stv090x_state
*state
= fe
->demodulator_priv
;
4885 STV090x_SETFIELD(reg
, GPIOx_OPD_FIELD
, dir
);
4886 STV090x_SETFIELD(reg
, GPIOx_CONFIG_FIELD
, value
);
4887 STV090x_SETFIELD(reg
, GPIOx_XOR_FIELD
, xor_value
);
4889 return stv090x_write_reg(state
, STV090x_GPIOxCFG(gpio
), reg
);
4892 static int stv090x_setup_compound(struct stv090x_state
*state
)
4894 struct stv090x_dev
*temp_int
;
4896 temp_int
= find_dev(state
->i2c
,
4897 state
->config
->address
);
4899 if (temp_int
&& state
->demod_mode
== STV090x_DUAL
) {
4900 state
->internal
= temp_int
->internal
;
4901 state
->internal
->num_used
++;
4902 dprintk(FE_INFO
, 1, "Found Internal Structure!");
4904 state
->internal
= kmalloc(sizeof(*state
->internal
), GFP_KERNEL
);
4905 if (!state
->internal
)
4907 temp_int
= append_internal(state
->internal
);
4909 kfree(state
->internal
);
4912 state
->internal
->num_used
= 1;
4913 state
->internal
->mclk
= 0;
4914 state
->internal
->dev_ver
= 0;
4915 state
->internal
->i2c_adap
= state
->i2c
;
4916 state
->internal
->i2c_addr
= state
->config
->address
;
4917 dprintk(FE_INFO
, 1, "Create New Internal Structure!");
4919 mutex_init(&state
->internal
->demod_lock
);
4920 mutex_init(&state
->internal
->tuner_lock
);
4922 if (stv090x_setup(&state
->frontend
) < 0) {
4923 dprintk(FE_ERROR
, 1, "Error setting up device");
4928 if (state
->internal
->dev_ver
>= 0x30)
4929 state
->frontend
.ops
.info
.caps
|= FE_CAN_MULTISTREAM
;
4931 /* workaround for stuck DiSEqC output */
4932 if (state
->config
->diseqc_envelope_mode
)
4933 stv090x_send_diseqc_burst(&state
->frontend
, SEC_MINI_A
);
4935 state
->config
->set_gpio
= stv090x_set_gpio
;
4937 dprintk(FE_ERROR
, 1, "Probing %s demodulator(%d) Cut=0x%02x",
4938 state
->device
== STV0900
? "STV0900" : "STV0903",
4939 state
->config
->demod
,
4940 state
->internal
->dev_ver
);
4947 remove_dev(state
->internal
);
4948 kfree(state
->internal
);
4952 static const struct dvb_frontend_ops stv090x_ops
= {
4953 .delsys
= { SYS_DVBS
, SYS_DVBS2
, SYS_DSS
},
4955 .name
= "STV090x Multistandard",
4956 .frequency_min_hz
= 950 * MHz
,
4957 .frequency_max_hz
= 2150 * MHz
,
4958 .symbol_rate_min
= 1000000,
4959 .symbol_rate_max
= 45000000,
4960 .caps
= FE_CAN_INVERSION_AUTO
|
4963 FE_CAN_2G_MODULATION
4966 .release
= stv090x_release
,
4967 .init
= stv090x_init
,
4969 .sleep
= stv090x_sleep
,
4970 .get_frontend_algo
= stv090x_frontend_algo
,
4972 .diseqc_send_master_cmd
= stv090x_send_diseqc_msg
,
4973 .diseqc_send_burst
= stv090x_send_diseqc_burst
,
4974 .diseqc_recv_slave_reply
= stv090x_recv_slave_reply
,
4975 .set_tone
= stv090x_set_tone
,
4977 .search
= stv090x_search
,
4978 .read_status
= stv090x_read_status
,
4979 .read_ber
= stv090x_read_per
,
4980 .read_signal_strength
= stv090x_read_signal_strength
,
4981 .read_snr
= stv090x_read_cnr
,
4984 static struct dvb_frontend
*stv090x_get_dvb_frontend(struct i2c_client
*client
)
4986 struct stv090x_state
*state
= i2c_get_clientdata(client
);
4988 dev_dbg(&client
->dev
, "\n");
4990 return &state
->frontend
;
4993 static int stv090x_probe(struct i2c_client
*client
,
4994 const struct i2c_device_id
*id
)
4997 struct stv090x_config
*config
= client
->dev
.platform_data
;
4999 struct stv090x_state
*state
= NULL
;
5001 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
5007 state
->verbose
= &verbose
;
5008 state
->config
= config
;
5009 state
->i2c
= client
->adapter
;
5010 state
->frontend
.ops
= stv090x_ops
;
5011 state
->frontend
.demodulator_priv
= state
;
5012 state
->demod
= config
->demod
;
5013 /* Single or Dual mode */
5014 state
->demod_mode
= config
->demod_mode
;
5015 state
->device
= config
->device
;
5017 state
->rolloff
= STV090x_RO_35
;
5019 ret
= stv090x_setup_compound(state
);
5023 i2c_set_clientdata(client
, state
);
5025 /* setup callbacks */
5026 config
->get_dvb_frontend
= stv090x_get_dvb_frontend
;
5035 static int stv090x_remove(struct i2c_client
*client
)
5037 struct stv090x_state
*state
= i2c_get_clientdata(client
);
5039 stv090x_release(&state
->frontend
);
5043 struct dvb_frontend
*stv090x_attach(struct stv090x_config
*config
,
5044 struct i2c_adapter
*i2c
,
5045 enum stv090x_demodulator demod
)
5048 struct stv090x_state
*state
= NULL
;
5050 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
5054 state
->verbose
= &verbose
;
5055 state
->config
= config
;
5057 state
->frontend
.ops
= stv090x_ops
;
5058 state
->frontend
.demodulator_priv
= state
;
5059 state
->demod
= demod
;
5060 /* Single or Dual mode */
5061 state
->demod_mode
= config
->demod_mode
;
5062 state
->device
= config
->device
;
5064 state
->rolloff
= STV090x_RO_35
;
5066 ret
= stv090x_setup_compound(state
);
5070 return &state
->frontend
;
5076 EXPORT_SYMBOL(stv090x_attach
);
5078 static const struct i2c_device_id stv090x_id_table
[] = {
5082 MODULE_DEVICE_TABLE(i2c
, stv090x_id_table
);
5084 static struct i2c_driver stv090x_driver
= {
5087 .suppress_bind_attrs
= true,
5089 .probe
= stv090x_probe
,
5090 .remove
= stv090x_remove
,
5091 .id_table
= stv090x_id_table
,
5094 module_i2c_driver(stv090x_driver
);
5096 MODULE_PARM_DESC(verbose
, "Set Verbosity level");
5097 MODULE_AUTHOR("Manu Abraham");
5098 MODULE_DESCRIPTION("STV090x Multi-Std Broadcast frontend");
5099 MODULE_LICENSE("GPL");