4 * Driver for ST STV0900 satellite demodulator IC.
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/string.h>
29 #include <linux/slab.h>
30 #include <linux/i2c.h>
33 #include "stv0900_reg.h"
34 #include "stv0900_priv.h"
35 #include "stv0900_init.h"
37 static int stvdebug
= 1;
38 module_param_named(debug
, stvdebug
, int, 0644);
40 /* internal params node */
41 struct stv0900_inode
{
42 /* pointer for internal params, one for each pair of demods */
43 struct stv0900_internal
*internal
;
44 struct stv0900_inode
*next_inode
;
47 /* first internal params */
48 static struct stv0900_inode
*stv0900_first_inode
;
50 /* find chip by i2c adapter and i2c address */
51 static struct stv0900_inode
*find_inode(struct i2c_adapter
*i2c_adap
,
54 struct stv0900_inode
*temp_chip
= stv0900_first_inode
;
56 if (temp_chip
!= NULL
) {
58 Search of the last stv0900 chip or
59 find it by i2c adapter and i2c address */
60 while ((temp_chip
!= NULL
) &&
61 ((temp_chip
->internal
->i2c_adap
!= i2c_adap
) ||
62 (temp_chip
->internal
->i2c_addr
!= i2c_addr
)))
64 temp_chip
= temp_chip
->next_inode
;
71 /* deallocating chip */
72 static void remove_inode(struct stv0900_internal
*internal
)
74 struct stv0900_inode
*prev_node
= stv0900_first_inode
;
75 struct stv0900_inode
*del_node
= find_inode(internal
->i2c_adap
,
78 if (del_node
!= NULL
) {
79 if (del_node
== stv0900_first_inode
) {
80 stv0900_first_inode
= del_node
->next_inode
;
82 while (prev_node
->next_inode
!= del_node
)
83 prev_node
= prev_node
->next_inode
;
85 if (del_node
->next_inode
== NULL
)
86 prev_node
->next_inode
= NULL
;
88 prev_node
->next_inode
=
89 prev_node
->next_inode
->next_inode
;
96 /* allocating new chip */
97 static struct stv0900_inode
*append_internal(struct stv0900_internal
*internal
)
99 struct stv0900_inode
*new_node
= stv0900_first_inode
;
101 if (new_node
== NULL
) {
102 new_node
= kmalloc(sizeof(struct stv0900_inode
), GFP_KERNEL
);
103 stv0900_first_inode
= new_node
;
105 while (new_node
->next_inode
!= NULL
)
106 new_node
= new_node
->next_inode
;
108 new_node
->next_inode
= kmalloc(sizeof(struct stv0900_inode
), GFP_KERNEL
);
109 if (new_node
->next_inode
!= NULL
)
110 new_node
= new_node
->next_inode
;
115 if (new_node
!= NULL
) {
116 new_node
->internal
= internal
;
117 new_node
->next_inode
= NULL
;
123 s32
ge2comp(s32 a
, s32 width
)
128 return (a
>= (1 << (width
- 1))) ? (a
- (1 << width
)) : a
;
131 void stv0900_write_reg(struct stv0900_internal
*i_params
, u16 reg_addr
,
136 struct i2c_msg i2cmsg
= {
137 .addr
= i_params
->i2c_addr
,
143 data
[0] = MSB(reg_addr
);
144 data
[1] = LSB(reg_addr
);
147 ret
= i2c_transfer(i_params
->i2c_adap
, &i2cmsg
, 1);
149 dprintk(KERN_ERR
"%s: i2c error %d\n", __func__
, ret
);
152 u8
stv0900_read_reg(struct stv0900_internal
*i_params
, u16 reg
)
155 u8 b0
[] = { MSB(reg
), LSB(reg
) };
157 struct i2c_msg msg
[] = {
159 .addr
= i_params
->i2c_addr
,
164 .addr
= i_params
->i2c_addr
,
171 ret
= i2c_transfer(i_params
->i2c_adap
, msg
, 2);
173 dprintk(KERN_ERR
"%s: i2c error %d, reg[0x%02x]\n",
179 void extract_mask_pos(u32 label
, u8
*mask
, u8
*pos
)
181 u8 position
= 0, i
= 0;
183 (*mask
) = label
& 0xff;
185 while ((position
== 0) && (i
< 8)) {
186 position
= ((*mask
) >> i
) & 0x01;
193 void stv0900_write_bits(struct stv0900_internal
*i_params
, u32 label
, u8 val
)
197 reg
= stv0900_read_reg(i_params
, (label
>> 16) & 0xffff);
198 extract_mask_pos(label
, &mask
, &pos
);
200 val
= mask
& (val
<< pos
);
202 reg
= (reg
& (~mask
)) | val
;
203 stv0900_write_reg(i_params
, (label
>> 16) & 0xffff, reg
);
207 u8
stv0900_get_bits(struct stv0900_internal
*i_params
, u32 label
)
212 extract_mask_pos(label
, &mask
, &pos
);
214 val
= stv0900_read_reg(i_params
, label
>> 16);
215 val
= (val
& mask
) >> pos
;
220 enum fe_stv0900_error
stv0900_initialize(struct stv0900_internal
*i_params
)
223 enum fe_stv0900_error error
;
225 if (i_params
!= NULL
) {
226 i_params
->chip_id
= stv0900_read_reg(i_params
, R0900_MID
);
227 if (i_params
->errs
== STV0900_NO_ERROR
) {
229 stv0900_write_reg(i_params
, R0900_P1_DMDISTATE
, 0x5c);
230 stv0900_write_reg(i_params
, R0900_P2_DMDISTATE
, 0x5c);
231 stv0900_write_reg(i_params
, R0900_P1_TNRCFG
, 0x6c);
232 stv0900_write_reg(i_params
, R0900_P2_TNRCFG
, 0x6f);
233 stv0900_write_reg(i_params
, R0900_P1_I2CRPT
, 0x20);
234 stv0900_write_reg(i_params
, R0900_P2_I2CRPT
, 0x20);
235 stv0900_write_reg(i_params
, R0900_NCOARSE
, 0x13);
237 stv0900_write_reg(i_params
, R0900_I2CCFG
, 0x08);
239 switch (i_params
->clkmode
) {
242 stv0900_write_reg(i_params
, R0900_SYNTCTRL
, 0x20
243 | i_params
->clkmode
);
246 /* preserve SELOSCI bit */
247 i
= 0x02 & stv0900_read_reg(i_params
, R0900_SYNTCTRL
);
248 stv0900_write_reg(i_params
, R0900_SYNTCTRL
, 0x20 | i
);
253 for (i
= 0; i
< 182; i
++)
254 stv0900_write_reg(i_params
, STV0900_InitVal
[i
][0], STV0900_InitVal
[i
][1]);
256 if (stv0900_read_reg(i_params
, R0900_MID
) >= 0x20) {
257 stv0900_write_reg(i_params
, R0900_TSGENERAL
, 0x0c);
258 for (i
= 0; i
< 32; i
++)
259 stv0900_write_reg(i_params
, STV0900_Cut20_AddOnVal
[i
][0], STV0900_Cut20_AddOnVal
[i
][1]);
262 stv0900_write_reg(i_params
, R0900_P1_FSPYCFG
, 0x6c);
263 stv0900_write_reg(i_params
, R0900_P2_FSPYCFG
, 0x6c);
264 stv0900_write_reg(i_params
, R0900_TSTRES0
, 0x80);
265 stv0900_write_reg(i_params
, R0900_TSTRES0
, 0x00);
267 error
= i_params
->errs
;
269 error
= STV0900_INVALID_HANDLE
;
275 u32
stv0900_get_mclk_freq(struct stv0900_internal
*i_params
, u32 ext_clk
)
277 u32 mclk
= 90000000, div
= 0, ad_div
= 0;
279 div
= stv0900_get_bits(i_params
, F0900_M_DIV
);
280 ad_div
= ((stv0900_get_bits(i_params
, F0900_SELX1RATIO
) == 1) ? 4 : 6);
282 mclk
= (div
+ 1) * ext_clk
/ ad_div
;
284 dprintk(KERN_INFO
"%s: Calculated Mclk = %d\n", __func__
, mclk
);
289 enum fe_stv0900_error
stv0900_set_mclk(struct stv0900_internal
*i_params
, u32 mclk
)
291 enum fe_stv0900_error error
= STV0900_NO_ERROR
;
294 dprintk(KERN_INFO
"%s: Mclk set to %d, Quartz = %d\n", __func__
, mclk
,
297 if (i_params
== NULL
)
298 error
= STV0900_INVALID_HANDLE
;
301 error
= STV0900_I2C_ERROR
;
303 clk_sel
= ((stv0900_get_bits(i_params
, F0900_SELX1RATIO
) == 1) ? 4 : 6);
304 m_div
= ((clk_sel
* mclk
) / i_params
->quartz
) - 1;
305 stv0900_write_bits(i_params
, F0900_M_DIV
, m_div
);
306 i_params
->mclk
= stv0900_get_mclk_freq(i_params
,
309 /*Set the DiseqC frequency to 22KHz */
312 DiseqC_TX_Freq= MasterClock/(32*F22TX_Reg)
313 DiseqC_RX_Freq= MasterClock/(32*F22RX_Reg)
315 m_div
= i_params
->mclk
/ 704000;
316 stv0900_write_reg(i_params
, R0900_P1_F22TX
, m_div
);
317 stv0900_write_reg(i_params
, R0900_P1_F22RX
, m_div
);
319 stv0900_write_reg(i_params
, R0900_P2_F22TX
, m_div
);
320 stv0900_write_reg(i_params
, R0900_P2_F22RX
, m_div
);
322 if ((i_params
->errs
))
323 error
= STV0900_I2C_ERROR
;
330 u32
stv0900_get_err_count(struct stv0900_internal
*i_params
, int cntr
,
331 enum fe_stv0900_demod_num demod
)
333 u32 lsb
, msb
, hsb
, err_val
;
334 s32 err1field_hsb
, err1field_msb
, err1field_lsb
;
335 s32 err2field_hsb
, err2field_msb
, err2field_lsb
;
337 dmd_reg(err1field_hsb
, F0900_P1_ERR_CNT12
, F0900_P2_ERR_CNT12
);
338 dmd_reg(err1field_msb
, F0900_P1_ERR_CNT11
, F0900_P2_ERR_CNT11
);
339 dmd_reg(err1field_lsb
, F0900_P1_ERR_CNT10
, F0900_P2_ERR_CNT10
);
341 dmd_reg(err2field_hsb
, F0900_P1_ERR_CNT22
, F0900_P2_ERR_CNT22
);
342 dmd_reg(err2field_msb
, F0900_P1_ERR_CNT21
, F0900_P2_ERR_CNT21
);
343 dmd_reg(err2field_lsb
, F0900_P1_ERR_CNT20
, F0900_P2_ERR_CNT20
);
348 hsb
= stv0900_get_bits(i_params
, err1field_hsb
);
349 msb
= stv0900_get_bits(i_params
, err1field_msb
);
350 lsb
= stv0900_get_bits(i_params
, err1field_lsb
);
353 hsb
= stv0900_get_bits(i_params
, err2field_hsb
);
354 msb
= stv0900_get_bits(i_params
, err2field_msb
);
355 lsb
= stv0900_get_bits(i_params
, err2field_lsb
);
359 err_val
= (hsb
<< 16) + (msb
<< 8) + (lsb
);
364 static int stv0900_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
366 struct stv0900_state
*state
= fe
->demodulator_priv
;
367 struct stv0900_internal
*i_params
= state
->internal
;
368 enum fe_stv0900_demod_num demod
= state
->demod
;
372 dmd_reg(fi2c
, F0900_P1_I2CT_ON
, F0900_P2_I2CT_ON
);
374 stv0900_write_bits(i_params
, fi2c
, enable
);
379 static void stv0900_set_ts_parallel_serial(struct stv0900_internal
*i_params
,
380 enum fe_stv0900_clock_type path1_ts
,
381 enum fe_stv0900_clock_type path2_ts
)
384 dprintk(KERN_INFO
"%s\n", __func__
);
386 if (i_params
->chip_id
>= 0x20) {
388 case STV0900_PARALLEL_PUNCT_CLOCK
:
389 case STV0900_DVBCI_CLOCK
:
391 case STV0900_SERIAL_PUNCT_CLOCK
:
392 case STV0900_SERIAL_CONT_CLOCK
:
394 stv0900_write_reg(i_params
, R0900_TSGENERAL
,
397 case STV0900_PARALLEL_PUNCT_CLOCK
:
398 case STV0900_DVBCI_CLOCK
:
399 stv0900_write_reg(i_params
, R0900_TSGENERAL
,
401 stv0900_write_bits(i_params
,
402 F0900_P1_TSFIFO_MANSPEED
, 3);
403 stv0900_write_bits(i_params
,
404 F0900_P2_TSFIFO_MANSPEED
, 0);
405 stv0900_write_reg(i_params
,
406 R0900_P1_TSSPEED
, 0x14);
407 stv0900_write_reg(i_params
,
408 R0900_P2_TSSPEED
, 0x28);
412 case STV0900_SERIAL_PUNCT_CLOCK
:
413 case STV0900_SERIAL_CONT_CLOCK
:
416 case STV0900_SERIAL_PUNCT_CLOCK
:
417 case STV0900_SERIAL_CONT_CLOCK
:
419 stv0900_write_reg(i_params
,
420 R0900_TSGENERAL
, 0x0C);
422 case STV0900_PARALLEL_PUNCT_CLOCK
:
423 case STV0900_DVBCI_CLOCK
:
424 stv0900_write_reg(i_params
,
425 R0900_TSGENERAL
, 0x0A);
426 dprintk(KERN_INFO
"%s: 0x0a\n", __func__
);
433 case STV0900_PARALLEL_PUNCT_CLOCK
:
434 case STV0900_DVBCI_CLOCK
:
436 case STV0900_SERIAL_PUNCT_CLOCK
:
437 case STV0900_SERIAL_CONT_CLOCK
:
439 stv0900_write_reg(i_params
, R0900_TSGENERAL1X
,
442 case STV0900_PARALLEL_PUNCT_CLOCK
:
443 case STV0900_DVBCI_CLOCK
:
444 stv0900_write_reg(i_params
, R0900_TSGENERAL1X
,
446 stv0900_write_bits(i_params
,
447 F0900_P1_TSFIFO_MANSPEED
, 3);
448 stv0900_write_bits(i_params
,
449 F0900_P2_TSFIFO_MANSPEED
, 0);
450 stv0900_write_reg(i_params
, R0900_P1_TSSPEED
,
452 stv0900_write_reg(i_params
, R0900_P2_TSSPEED
,
458 case STV0900_SERIAL_PUNCT_CLOCK
:
459 case STV0900_SERIAL_CONT_CLOCK
:
462 case STV0900_SERIAL_PUNCT_CLOCK
:
463 case STV0900_SERIAL_CONT_CLOCK
:
465 stv0900_write_reg(i_params
, R0900_TSGENERAL1X
,
468 case STV0900_PARALLEL_PUNCT_CLOCK
:
469 case STV0900_DVBCI_CLOCK
:
470 stv0900_write_reg(i_params
, R0900_TSGENERAL1X
,
472 dprintk(KERN_INFO
"%s: 0x12\n", __func__
);
481 case STV0900_PARALLEL_PUNCT_CLOCK
:
482 stv0900_write_bits(i_params
, F0900_P1_TSFIFO_SERIAL
, 0x00);
483 stv0900_write_bits(i_params
, F0900_P1_TSFIFO_DVBCI
, 0x00);
485 case STV0900_DVBCI_CLOCK
:
486 stv0900_write_bits(i_params
, F0900_P1_TSFIFO_SERIAL
, 0x00);
487 stv0900_write_bits(i_params
, F0900_P1_TSFIFO_DVBCI
, 0x01);
489 case STV0900_SERIAL_PUNCT_CLOCK
:
490 stv0900_write_bits(i_params
, F0900_P1_TSFIFO_SERIAL
, 0x01);
491 stv0900_write_bits(i_params
, F0900_P1_TSFIFO_DVBCI
, 0x00);
493 case STV0900_SERIAL_CONT_CLOCK
:
494 stv0900_write_bits(i_params
, F0900_P1_TSFIFO_SERIAL
, 0x01);
495 stv0900_write_bits(i_params
, F0900_P1_TSFIFO_DVBCI
, 0x01);
502 case STV0900_PARALLEL_PUNCT_CLOCK
:
503 stv0900_write_bits(i_params
, F0900_P2_TSFIFO_SERIAL
, 0x00);
504 stv0900_write_bits(i_params
, F0900_P2_TSFIFO_DVBCI
, 0x00);
506 case STV0900_DVBCI_CLOCK
:
507 stv0900_write_bits(i_params
, F0900_P2_TSFIFO_SERIAL
, 0x00);
508 stv0900_write_bits(i_params
, F0900_P2_TSFIFO_DVBCI
, 0x01);
510 case STV0900_SERIAL_PUNCT_CLOCK
:
511 stv0900_write_bits(i_params
, F0900_P2_TSFIFO_SERIAL
, 0x01);
512 stv0900_write_bits(i_params
, F0900_P2_TSFIFO_DVBCI
, 0x00);
514 case STV0900_SERIAL_CONT_CLOCK
:
515 stv0900_write_bits(i_params
, F0900_P2_TSFIFO_SERIAL
, 0x01);
516 stv0900_write_bits(i_params
, F0900_P2_TSFIFO_DVBCI
, 0x01);
522 stv0900_write_bits(i_params
, F0900_P2_RST_HWARE
, 1);
523 stv0900_write_bits(i_params
, F0900_P2_RST_HWARE
, 0);
524 stv0900_write_bits(i_params
, F0900_P1_RST_HWARE
, 1);
525 stv0900_write_bits(i_params
, F0900_P1_RST_HWARE
, 0);
528 void stv0900_set_tuner(struct dvb_frontend
*fe
, u32 frequency
,
531 struct dvb_frontend_ops
*frontend_ops
= NULL
;
532 struct dvb_tuner_ops
*tuner_ops
= NULL
;
535 frontend_ops
= &fe
->ops
;
537 if (&frontend_ops
->tuner_ops
)
538 tuner_ops
= &frontend_ops
->tuner_ops
;
540 if (tuner_ops
->set_frequency
) {
541 if ((tuner_ops
->set_frequency(fe
, frequency
)) < 0)
542 dprintk("%s: Invalid parameter\n", __func__
);
544 dprintk("%s: Frequency=%d\n", __func__
, frequency
);
548 if (tuner_ops
->set_bandwidth
) {
549 if ((tuner_ops
->set_bandwidth(fe
, bandwidth
)) < 0)
550 dprintk("%s: Invalid parameter\n", __func__
);
552 dprintk("%s: Bandwidth=%d\n", __func__
, bandwidth
);
557 void stv0900_set_bandwidth(struct dvb_frontend
*fe
, u32 bandwidth
)
559 struct dvb_frontend_ops
*frontend_ops
= NULL
;
560 struct dvb_tuner_ops
*tuner_ops
= NULL
;
563 frontend_ops
= &fe
->ops
;
565 if (&frontend_ops
->tuner_ops
)
566 tuner_ops
= &frontend_ops
->tuner_ops
;
568 if (tuner_ops
->set_bandwidth
) {
569 if ((tuner_ops
->set_bandwidth(fe
, bandwidth
)) < 0)
570 dprintk("%s: Invalid parameter\n", __func__
);
572 dprintk("%s: Bandwidth=%d\n", __func__
, bandwidth
);
577 static s32
stv0900_get_rf_level(struct stv0900_internal
*i_params
,
578 const struct stv0900_table
*lookup
,
579 enum fe_stv0900_demod_num demod
)
587 dprintk(KERN_INFO
"%s\n", __func__
);
589 if ((lookup
!= NULL
) && lookup
->size
) {
591 case STV0900_DEMOD_1
:
593 agc_gain
= MAKEWORD(stv0900_get_bits(i_params
, F0900_P1_AGCIQ_VALUE1
),
594 stv0900_get_bits(i_params
, F0900_P1_AGCIQ_VALUE0
));
596 case STV0900_DEMOD_2
:
597 agc_gain
= MAKEWORD(stv0900_get_bits(i_params
, F0900_P2_AGCIQ_VALUE1
),
598 stv0900_get_bits(i_params
, F0900_P2_AGCIQ_VALUE0
));
603 imax
= lookup
->size
- 1;
604 if (INRANGE(lookup
->table
[imin
].regval
, agc_gain
, lookup
->table
[imax
].regval
)) {
605 while ((imax
- imin
) > 1) {
606 i
= (imax
+ imin
) >> 1;
608 if (INRANGE(lookup
->table
[imin
].regval
, agc_gain
, lookup
->table
[i
].regval
))
614 rf_lvl
= (((s32
)agc_gain
- lookup
->table
[imin
].regval
)
615 * (lookup
->table
[imax
].realval
- lookup
->table
[imin
].realval
)
616 / (lookup
->table
[imax
].regval
- lookup
->table
[imin
].regval
))
617 + lookup
->table
[imin
].realval
;
618 } else if (agc_gain
> lookup
->table
[0].regval
)
620 else if (agc_gain
< lookup
->table
[lookup
->size
-1].regval
)
625 dprintk(KERN_INFO
"%s: RFLevel = %d\n", __func__
, rf_lvl
);
630 static int stv0900_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
632 struct stv0900_state
*state
= fe
->demodulator_priv
;
633 struct stv0900_internal
*internal
= state
->internal
;
634 s32 rflevel
= stv0900_get_rf_level(internal
, &stv0900_rf
,
637 *strength
= (rflevel
+ 100) * (16383 / 105);
643 static s32
stv0900_carr_get_quality(struct dvb_frontend
*fe
,
644 const struct stv0900_table
*lookup
)
646 struct stv0900_state
*state
= fe
->demodulator_priv
;
647 struct stv0900_internal
*i_params
= state
->internal
;
648 enum fe_stv0900_demod_num demod
= state
->demod
;
657 dprintk(KERN_INFO
"%s\n", __func__
);
659 dmd_reg(lock_flag_field
, F0900_P1_LOCK_DEFINITIF
,
660 F0900_P2_LOCK_DEFINITIF
);
661 if (stv0900_get_standard(fe
, demod
) == STV0900_DVBS2_STANDARD
) {
662 dmd_reg(noise_field1
, F0900_P1_NOSPLHT_NORMED1
,
663 F0900_P2_NOSPLHT_NORMED1
);
664 dmd_reg(noise_field0
, F0900_P1_NOSPLHT_NORMED0
,
665 F0900_P2_NOSPLHT_NORMED0
);
667 dmd_reg(noise_field1
, F0900_P1_NOSDATAT_NORMED1
,
668 F0900_P2_NOSDATAT_NORMED1
);
669 dmd_reg(noise_field0
, F0900_P1_NOSDATAT_NORMED0
,
670 F0900_P2_NOSDATAT_NORMED0
);
673 if (stv0900_get_bits(i_params
, lock_flag_field
)) {
674 if ((lookup
!= NULL
) && lookup
->size
) {
677 for (i
= 0; i
< 16; i
++) {
678 regval
+= MAKEWORD(stv0900_get_bits(i_params
,
680 stv0900_get_bits(i_params
,
687 imax
= lookup
->size
- 1;
688 if (INRANGE(lookup
->table
[imin
].regval
,
690 lookup
->table
[imax
].regval
)) {
691 while ((imax
- imin
) > 1) {
692 i
= (imax
+ imin
) >> 1;
693 if (INRANGE(lookup
->table
[imin
].regval
,
695 lookup
->table
[i
].regval
))
701 c_n
= ((regval
- lookup
->table
[imin
].regval
)
702 * (lookup
->table
[imax
].realval
703 - lookup
->table
[imin
].realval
)
704 / (lookup
->table
[imax
].regval
705 - lookup
->table
[imin
].regval
))
706 + lookup
->table
[imin
].realval
;
707 } else if (regval
< lookup
->table
[imin
].regval
)
715 static int stv0900_read_ucblocks(struct dvb_frontend
*fe
, u32
* ucblocks
)
717 struct stv0900_state
*state
= fe
->demodulator_priv
;
718 struct stv0900_internal
*i_params
= state
->internal
;
719 enum fe_stv0900_demod_num demod
= state
->demod
;
720 u8 err_val1
, err_val0
;
721 s32 err_field1
, err_field0
;
722 u32 header_err_val
= 0;
725 if (stv0900_get_standard(fe
, demod
) == STV0900_DVBS2_STANDARD
) {
726 /* DVB-S2 delineator errors count */
728 /* retreiving number for errnous headers */
729 dmd_reg(err_field0
, R0900_P1_BBFCRCKO0
,
731 dmd_reg(err_field1
, R0900_P1_BBFCRCKO1
,
734 err_val1
= stv0900_read_reg(i_params
, err_field1
);
735 err_val0
= stv0900_read_reg(i_params
, err_field0
);
736 header_err_val
= (err_val1
<<8) | err_val0
;
738 /* retreiving number for errnous packets */
739 dmd_reg(err_field0
, R0900_P1_UPCRCKO0
,
741 dmd_reg(err_field1
, R0900_P1_UPCRCKO1
,
744 err_val1
= stv0900_read_reg(i_params
, err_field1
);
745 err_val0
= stv0900_read_reg(i_params
, err_field0
);
746 *ucblocks
= (err_val1
<<8) | err_val0
;
747 *ucblocks
+= header_err_val
;
753 static int stv0900_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
755 *snr
= stv0900_carr_get_quality(fe
,
756 (const struct stv0900_table
*)&stv0900_s2_cn
);
758 *snr
*= (16383 / 1030);
763 static u32
stv0900_get_ber(struct stv0900_internal
*i_params
,
764 enum fe_stv0900_demod_num demod
)
766 u32 ber
= 10000000, i
;
774 dmd_reg(dmd_state_reg
, F0900_P1_HEADER_MODE
, F0900_P2_HEADER_MODE
);
775 dmd_reg(vstatus_reg
, R0900_P1_VSTATUSVIT
, R0900_P2_VSTATUSVIT
);
776 dmd_reg(prvit_field
, F0900_P1_PRFVIT
, F0900_P2_PRFVIT
);
777 dmd_reg(pdel_status_reg
, R0900_P1_PDELSTATUS1
, R0900_P2_PDELSTATUS1
);
778 dmd_reg(pdel_lock_field
, F0900_P1_PKTDELIN_LOCK
,
779 F0900_P2_PKTDELIN_LOCK
);
781 demod_state
= stv0900_get_bits(i_params
, dmd_state_reg
);
783 switch (demod_state
) {
785 case STV0900_PLH_DETECTED
:
789 case STV0900_DVBS_FOUND
:
791 for (i
= 0; i
< 5; i
++) {
793 ber
+= stv0900_get_err_count(i_params
, 0, demod
);
797 if (stv0900_get_bits(i_params
, prvit_field
)) {
803 case STV0900_DVBS2_FOUND
:
805 for (i
= 0; i
< 5; i
++) {
807 ber
+= stv0900_get_err_count(i_params
, 0, demod
);
811 if (stv0900_get_bits(i_params
, pdel_lock_field
)) {
822 static int stv0900_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
824 struct stv0900_state
*state
= fe
->demodulator_priv
;
825 struct stv0900_internal
*internal
= state
->internal
;
827 *ber
= stv0900_get_ber(internal
, state
->demod
);
832 int stv0900_get_demod_lock(struct stv0900_internal
*i_params
,
833 enum fe_stv0900_demod_num demod
, s32 time_out
)
840 enum fe_stv0900_search_state dmd_state
;
842 dmd_reg(header_field
, F0900_P1_HEADER_MODE
, F0900_P2_HEADER_MODE
);
843 dmd_reg(lock_field
, F0900_P1_LOCK_DEFINITIF
, F0900_P2_LOCK_DEFINITIF
);
844 while ((timer
< time_out
) && (lock
== 0)) {
845 dmd_state
= stv0900_get_bits(i_params
, header_field
);
846 dprintk("Demod State = %d\n", dmd_state
);
849 case STV0900_PLH_DETECTED
:
853 case STV0900_DVBS2_FOUND
:
854 case STV0900_DVBS_FOUND
:
855 lock
= stv0900_get_bits(i_params
, lock_field
);
866 dprintk("DEMOD LOCK OK\n");
868 dprintk("DEMOD LOCK FAIL\n");
873 void stv0900_stop_all_s2_modcod(struct stv0900_internal
*i_params
,
874 enum fe_stv0900_demod_num demod
)
879 dprintk(KERN_INFO
"%s\n", __func__
);
881 dmd_reg(regflist
, R0900_P1_MODCODLST0
, R0900_P2_MODCODLST0
);
883 for (i
= 0; i
< 16; i
++)
884 stv0900_write_reg(i_params
, regflist
+ i
, 0xff);
887 void stv0900_activate_s2_modcode(struct stv0900_internal
*i_params
,
888 enum fe_stv0900_demod_num demod
)
896 dprintk(KERN_INFO
"%s\n", __func__
);
898 if (i_params
->chip_id
<= 0x11) {
902 case STV0900_DEMOD_1
:
904 mod_code
= stv0900_read_reg(i_params
,
906 matype
= mod_code
& 0x3;
907 mod_code
= (mod_code
& 0x7f) >> 2;
909 reg_index
= R0900_P1_MODCODLSTF
- mod_code
/ 2;
910 field_index
= mod_code
% 2;
912 case STV0900_DEMOD_2
:
913 mod_code
= stv0900_read_reg(i_params
,
915 matype
= mod_code
& 0x3;
916 mod_code
= (mod_code
& 0x7f) >> 2;
918 reg_index
= R0900_P2_MODCODLSTF
- mod_code
/ 2;
919 field_index
= mod_code
% 2;
940 if ((INRANGE(STV0900_QPSK_12
, mod_code
, STV0900_8PSK_910
))
942 if (field_index
== 0)
943 stv0900_write_reg(i_params
, reg_index
,
946 stv0900_write_reg(i_params
, reg_index
,
949 } else if (i_params
->chip_id
>= 0x12) {
951 case STV0900_DEMOD_1
:
953 for (reg_index
= 0; reg_index
< 7; reg_index
++)
954 stv0900_write_reg(i_params
, R0900_P1_MODCODLST0
+ reg_index
, 0xff);
956 stv0900_write_reg(i_params
, R0900_P1_MODCODLSTE
, 0xff);
957 stv0900_write_reg(i_params
, R0900_P1_MODCODLSTF
, 0xcf);
958 for (reg_index
= 0; reg_index
< 8; reg_index
++)
959 stv0900_write_reg(i_params
, R0900_P1_MODCODLST7
+ reg_index
, 0xcc);
962 case STV0900_DEMOD_2
:
963 for (reg_index
= 0; reg_index
< 7; reg_index
++)
964 stv0900_write_reg(i_params
, R0900_P2_MODCODLST0
+ reg_index
, 0xff);
966 stv0900_write_reg(i_params
, R0900_P2_MODCODLSTE
, 0xff);
967 stv0900_write_reg(i_params
, R0900_P2_MODCODLSTF
, 0xcf);
968 for (reg_index
= 0; reg_index
< 8; reg_index
++)
969 stv0900_write_reg(i_params
, R0900_P2_MODCODLST7
+ reg_index
, 0xcc);
977 void stv0900_activate_s2_modcode_single(struct stv0900_internal
*i_params
,
978 enum fe_stv0900_demod_num demod
)
982 dprintk(KERN_INFO
"%s\n", __func__
);
985 case STV0900_DEMOD_1
:
987 stv0900_write_reg(i_params
, R0900_P1_MODCODLST0
, 0xff);
988 stv0900_write_reg(i_params
, R0900_P1_MODCODLST1
, 0xf0);
989 stv0900_write_reg(i_params
, R0900_P1_MODCODLSTF
, 0x0f);
990 for (reg_index
= 0; reg_index
< 13; reg_index
++)
991 stv0900_write_reg(i_params
,
992 R0900_P1_MODCODLST2
+ reg_index
, 0);
995 case STV0900_DEMOD_2
:
996 stv0900_write_reg(i_params
, R0900_P2_MODCODLST0
, 0xff);
997 stv0900_write_reg(i_params
, R0900_P2_MODCODLST1
, 0xf0);
998 stv0900_write_reg(i_params
, R0900_P2_MODCODLSTF
, 0x0f);
999 for (reg_index
= 0; reg_index
< 13; reg_index
++)
1000 stv0900_write_reg(i_params
,
1001 R0900_P2_MODCODLST2
+ reg_index
, 0);
1007 static enum dvbfe_algo
stv0900_frontend_algo(struct dvb_frontend
*fe
)
1009 return DVBFE_ALGO_CUSTOM
;
1012 static int stb0900_set_property(struct dvb_frontend
*fe
,
1013 struct dtv_property
*tvp
)
1015 dprintk(KERN_INFO
"%s(..)\n", __func__
);
1020 static int stb0900_get_property(struct dvb_frontend
*fe
,
1021 struct dtv_property
*tvp
)
1023 dprintk(KERN_INFO
"%s(..)\n", __func__
);
1028 void stv0900_start_search(struct stv0900_internal
*i_params
,
1029 enum fe_stv0900_demod_num demod
)
1033 case STV0900_DEMOD_1
:
1035 stv0900_write_bits(i_params
, F0900_P1_I2C_DEMOD_MODE
, 0x1f);
1037 if (i_params
->chip_id
== 0x10)
1038 stv0900_write_reg(i_params
, R0900_P1_CORRELEXP
, 0xaa);
1040 if (i_params
->chip_id
< 0x20)
1041 stv0900_write_reg(i_params
, R0900_P1_CARHDR
, 0x55);
1043 if (i_params
->dmd1_symbol_rate
<= 5000000) {
1044 stv0900_write_reg(i_params
, R0900_P1_CARCFG
, 0x44);
1045 stv0900_write_reg(i_params
, R0900_P1_CFRUP1
, 0x0f);
1046 stv0900_write_reg(i_params
, R0900_P1_CFRUP0
, 0xff);
1047 stv0900_write_reg(i_params
, R0900_P1_CFRLOW1
, 0xf0);
1048 stv0900_write_reg(i_params
, R0900_P1_CFRLOW0
, 0x00);
1049 stv0900_write_reg(i_params
, R0900_P1_RTCS2
, 0x68);
1051 stv0900_write_reg(i_params
, R0900_P1_CARCFG
, 0xc4);
1052 stv0900_write_reg(i_params
, R0900_P1_RTCS2
, 0x44);
1055 stv0900_write_reg(i_params
, R0900_P1_CFRINIT1
, 0);
1056 stv0900_write_reg(i_params
, R0900_P1_CFRINIT0
, 0);
1058 if (i_params
->chip_id
>= 0x20) {
1059 stv0900_write_reg(i_params
, R0900_P1_EQUALCFG
, 0x41);
1060 stv0900_write_reg(i_params
, R0900_P1_FFECFG
, 0x41);
1062 if ((i_params
->dmd1_srch_standard
== STV0900_SEARCH_DVBS1
) || (i_params
->dmd1_srch_standard
== STV0900_SEARCH_DSS
) || (i_params
->dmd1_srch_standard
== STV0900_AUTO_SEARCH
)) {
1063 stv0900_write_reg(i_params
, R0900_P1_VITSCALE
, 0x82);
1064 stv0900_write_reg(i_params
, R0900_P1_VAVSRVIT
, 0x0);
1068 stv0900_write_reg(i_params
, R0900_P1_SFRSTEP
, 0x00);
1069 stv0900_write_reg(i_params
, R0900_P1_TMGTHRISE
, 0xe0);
1070 stv0900_write_reg(i_params
, R0900_P1_TMGTHFALL
, 0xc0);
1071 stv0900_write_bits(i_params
, F0900_P1_SCAN_ENABLE
, 0);
1072 stv0900_write_bits(i_params
, F0900_P1_CFR_AUTOSCAN
, 0);
1073 stv0900_write_bits(i_params
, F0900_P1_S1S2_SEQUENTIAL
, 0);
1074 stv0900_write_reg(i_params
, R0900_P1_RTC
, 0x88);
1075 if (i_params
->chip_id
>= 0x20) {
1076 if (i_params
->dmd1_symbol_rate
< 2000000) {
1077 stv0900_write_reg(i_params
, R0900_P1_CARFREQ
, 0x39);
1078 stv0900_write_reg(i_params
, R0900_P1_CARHDR
, 0x40);
1081 if (i_params
->dmd1_symbol_rate
< 10000000) {
1082 stv0900_write_reg(i_params
, R0900_P1_CARFREQ
, 0x4c);
1083 stv0900_write_reg(i_params
, R0900_P1_CARHDR
, 0x20);
1085 stv0900_write_reg(i_params
, R0900_P1_CARFREQ
, 0x4b);
1086 stv0900_write_reg(i_params
, R0900_P1_CARHDR
, 0x20);
1090 if (i_params
->dmd1_symbol_rate
< 10000000)
1091 stv0900_write_reg(i_params
, R0900_P1_CARFREQ
, 0xef);
1093 stv0900_write_reg(i_params
, R0900_P1_CARFREQ
, 0xed);
1096 switch (i_params
->dmd1_srch_algo
) {
1097 case STV0900_WARM_START
:
1098 stv0900_write_reg(i_params
, R0900_P1_DMDISTATE
, 0x1f);
1099 stv0900_write_reg(i_params
, R0900_P1_DMDISTATE
, 0x18);
1101 case STV0900_COLD_START
:
1102 stv0900_write_reg(i_params
, R0900_P1_DMDISTATE
, 0x1f);
1103 stv0900_write_reg(i_params
, R0900_P1_DMDISTATE
, 0x15);
1110 case STV0900_DEMOD_2
:
1111 stv0900_write_bits(i_params
, F0900_P2_I2C_DEMOD_MODE
, 0x1f);
1112 if (i_params
->chip_id
== 0x10)
1113 stv0900_write_reg(i_params
, R0900_P2_CORRELEXP
, 0xaa);
1115 if (i_params
->chip_id
< 0x20)
1116 stv0900_write_reg(i_params
, R0900_P2_CARHDR
, 0x55);
1118 if (i_params
->dmd2_symbol_rate
<= 5000000) {
1119 stv0900_write_reg(i_params
, R0900_P2_CARCFG
, 0x44);
1120 stv0900_write_reg(i_params
, R0900_P2_CFRUP1
, 0x0f);
1121 stv0900_write_reg(i_params
, R0900_P2_CFRUP0
, 0xff);
1122 stv0900_write_reg(i_params
, R0900_P2_CFRLOW1
, 0xf0);
1123 stv0900_write_reg(i_params
, R0900_P2_CFRLOW0
, 0x00);
1124 stv0900_write_reg(i_params
, R0900_P2_RTCS2
, 0x68);
1126 stv0900_write_reg(i_params
, R0900_P2_CARCFG
, 0xc4);
1127 stv0900_write_reg(i_params
, R0900_P2_RTCS2
, 0x44);
1130 stv0900_write_reg(i_params
, R0900_P2_CFRINIT1
, 0);
1131 stv0900_write_reg(i_params
, R0900_P2_CFRINIT0
, 0);
1133 if (i_params
->chip_id
>= 0x20) {
1134 stv0900_write_reg(i_params
, R0900_P2_EQUALCFG
, 0x41);
1135 stv0900_write_reg(i_params
, R0900_P2_FFECFG
, 0x41);
1136 if ((i_params
->dmd2_srch_stndrd
== STV0900_SEARCH_DVBS1
) || (i_params
->dmd2_srch_stndrd
== STV0900_SEARCH_DSS
) || (i_params
->dmd2_srch_stndrd
== STV0900_AUTO_SEARCH
)) {
1137 stv0900_write_reg(i_params
, R0900_P2_VITSCALE
, 0x82);
1138 stv0900_write_reg(i_params
, R0900_P2_VAVSRVIT
, 0x0);
1142 stv0900_write_reg(i_params
, R0900_P2_SFRSTEP
, 0x00);
1143 stv0900_write_reg(i_params
, R0900_P2_TMGTHRISE
, 0xe0);
1144 stv0900_write_reg(i_params
, R0900_P2_TMGTHFALL
, 0xc0);
1145 stv0900_write_bits(i_params
, F0900_P2_SCAN_ENABLE
, 0);
1146 stv0900_write_bits(i_params
, F0900_P2_CFR_AUTOSCAN
, 0);
1147 stv0900_write_bits(i_params
, F0900_P2_S1S2_SEQUENTIAL
, 0);
1148 stv0900_write_reg(i_params
, R0900_P2_RTC
, 0x88);
1149 if (i_params
->chip_id
>= 0x20) {
1150 if (i_params
->dmd2_symbol_rate
< 2000000) {
1151 stv0900_write_reg(i_params
, R0900_P2_CARFREQ
, 0x39);
1152 stv0900_write_reg(i_params
, R0900_P2_CARHDR
, 0x40);
1155 if (i_params
->dmd2_symbol_rate
< 10000000) {
1156 stv0900_write_reg(i_params
, R0900_P2_CARFREQ
, 0x4c);
1157 stv0900_write_reg(i_params
, R0900_P2_CARHDR
, 0x20);
1159 stv0900_write_reg(i_params
, R0900_P2_CARFREQ
, 0x4b);
1160 stv0900_write_reg(i_params
, R0900_P2_CARHDR
, 0x20);
1164 if (i_params
->dmd2_symbol_rate
< 10000000)
1165 stv0900_write_reg(i_params
, R0900_P2_CARFREQ
, 0xef);
1167 stv0900_write_reg(i_params
, R0900_P2_CARFREQ
, 0xed);
1170 switch (i_params
->dmd2_srch_algo
) {
1171 case STV0900_WARM_START
:
1172 stv0900_write_reg(i_params
, R0900_P2_DMDISTATE
, 0x1f);
1173 stv0900_write_reg(i_params
, R0900_P2_DMDISTATE
, 0x18);
1175 case STV0900_COLD_START
:
1176 stv0900_write_reg(i_params
, R0900_P2_DMDISTATE
, 0x1f);
1177 stv0900_write_reg(i_params
, R0900_P2_DMDISTATE
, 0x15);
1187 u8
stv0900_get_optim_carr_loop(s32 srate
, enum fe_stv0900_modcode modcode
,
1188 s32 pilot
, u8 chip_id
)
1190 u8 aclc_value
= 0x29;
1192 const struct stv0900_car_loop_optim
*car_loop_s2
;
1194 dprintk(KERN_INFO
"%s\n", __func__
);
1196 if (chip_id
<= 0x12)
1197 car_loop_s2
= FE_STV0900_S2CarLoop
;
1198 else if (chip_id
== 0x20)
1199 car_loop_s2
= FE_STV0900_S2CarLoopCut20
;
1201 car_loop_s2
= FE_STV0900_S2CarLoop
;
1203 if (modcode
< STV0900_QPSK_12
) {
1205 while ((i
< 3) && (modcode
!= FE_STV0900_S2LowQPCarLoopCut20
[i
].modcode
))
1212 while ((i
< 14) && (modcode
!= car_loop_s2
[i
].modcode
))
1217 while ((i
< 11) && (modcode
!= FE_STV0900_S2APSKCarLoopCut20
[i
].modcode
))
1225 if (modcode
<= STV0900_QPSK_25
) {
1227 if (srate
<= 3000000)
1228 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_on_2
;
1229 else if (srate
<= 7000000)
1230 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_on_5
;
1231 else if (srate
<= 15000000)
1232 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_on_10
;
1233 else if (srate
<= 25000000)
1234 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_on_20
;
1236 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_on_30
;
1238 if (srate
<= 3000000)
1239 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_off_2
;
1240 else if (srate
<= 7000000)
1241 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_off_5
;
1242 else if (srate
<= 15000000)
1243 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_off_10
;
1244 else if (srate
<= 25000000)
1245 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_off_20
;
1247 aclc_value
= FE_STV0900_S2LowQPCarLoopCut20
[i
].car_loop_pilots_off_30
;
1250 } else if (modcode
<= STV0900_8PSK_910
) {
1252 if (srate
<= 3000000)
1253 aclc_value
= car_loop_s2
[i
].car_loop_pilots_on_2
;
1254 else if (srate
<= 7000000)
1255 aclc_value
= car_loop_s2
[i
].car_loop_pilots_on_5
;
1256 else if (srate
<= 15000000)
1257 aclc_value
= car_loop_s2
[i
].car_loop_pilots_on_10
;
1258 else if (srate
<= 25000000)
1259 aclc_value
= car_loop_s2
[i
].car_loop_pilots_on_20
;
1261 aclc_value
= car_loop_s2
[i
].car_loop_pilots_on_30
;
1263 if (srate
<= 3000000)
1264 aclc_value
= car_loop_s2
[i
].car_loop_pilots_off_2
;
1265 else if (srate
<= 7000000)
1266 aclc_value
= car_loop_s2
[i
].car_loop_pilots_off_5
;
1267 else if (srate
<= 15000000)
1268 aclc_value
= car_loop_s2
[i
].car_loop_pilots_off_10
;
1269 else if (srate
<= 25000000)
1270 aclc_value
= car_loop_s2
[i
].car_loop_pilots_off_20
;
1272 aclc_value
= car_loop_s2
[i
].car_loop_pilots_off_30
;
1276 if (srate
<= 3000000)
1277 aclc_value
= FE_STV0900_S2APSKCarLoopCut20
[i
].car_loop_pilots_on_2
;
1278 else if (srate
<= 7000000)
1279 aclc_value
= FE_STV0900_S2APSKCarLoopCut20
[i
].car_loop_pilots_on_5
;
1280 else if (srate
<= 15000000)
1281 aclc_value
= FE_STV0900_S2APSKCarLoopCut20
[i
].car_loop_pilots_on_10
;
1282 else if (srate
<= 25000000)
1283 aclc_value
= FE_STV0900_S2APSKCarLoopCut20
[i
].car_loop_pilots_on_20
;
1285 aclc_value
= FE_STV0900_S2APSKCarLoopCut20
[i
].car_loop_pilots_on_30
;
1291 u8
stv0900_get_optim_short_carr_loop(s32 srate
, enum fe_stv0900_modulation modulation
, u8 chip_id
)
1295 u8 aclc_value
= 0x0b;
1297 dprintk(KERN_INFO
"%s\n", __func__
);
1299 switch (modulation
) {
1307 case STV0900_16APSK
:
1310 case STV0900_32APSK
:
1317 if (srate
<= 3000000)
1318 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut20_2
;
1319 else if (srate
<= 7000000)
1320 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut20_5
;
1321 else if (srate
<= 15000000)
1322 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut20_10
;
1323 else if (srate
<= 25000000)
1324 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut20_20
;
1326 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut20_30
;
1331 if (srate
<= 3000000)
1332 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut12_2
;
1333 else if (srate
<= 7000000)
1334 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut12_5
;
1335 else if (srate
<= 15000000)
1336 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut12_10
;
1337 else if (srate
<= 25000000)
1338 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut12_20
;
1340 aclc_value
= FE_STV0900_S2ShortCarLoop
[mod_index
].car_loop_cut12_30
;
1348 static enum fe_stv0900_error
stv0900_st_dvbs2_single(struct stv0900_internal
*i_params
,
1349 enum fe_stv0900_demod_mode LDPC_Mode
,
1350 enum fe_stv0900_demod_num demod
)
1352 enum fe_stv0900_error error
= STV0900_NO_ERROR
;
1354 dprintk(KERN_INFO
"%s\n", __func__
);
1356 switch (LDPC_Mode
) {
1359 if ((i_params
->demod_mode
!= STV0900_DUAL
)
1360 || (stv0900_get_bits(i_params
, F0900_DDEMOD
) != 1)) {
1361 stv0900_write_reg(i_params
, R0900_GENCFG
, 0x1d);
1363 i_params
->demod_mode
= STV0900_DUAL
;
1365 stv0900_write_bits(i_params
, F0900_FRESFEC
, 1);
1366 stv0900_write_bits(i_params
, F0900_FRESFEC
, 0);
1370 case STV0900_SINGLE
:
1371 if (demod
== STV0900_DEMOD_2
)
1372 stv0900_write_reg(i_params
, R0900_GENCFG
, 0x06);
1374 stv0900_write_reg(i_params
, R0900_GENCFG
, 0x04);
1376 i_params
->demod_mode
= STV0900_SINGLE
;
1378 stv0900_write_bits(i_params
, F0900_FRESFEC
, 1);
1379 stv0900_write_bits(i_params
, F0900_FRESFEC
, 0);
1380 stv0900_write_bits(i_params
, F0900_P1_ALGOSWRST
, 1);
1381 stv0900_write_bits(i_params
, F0900_P1_ALGOSWRST
, 0);
1382 stv0900_write_bits(i_params
, F0900_P2_ALGOSWRST
, 1);
1383 stv0900_write_bits(i_params
, F0900_P2_ALGOSWRST
, 0);
1390 static enum fe_stv0900_error
stv0900_init_internal(struct dvb_frontend
*fe
,
1391 struct stv0900_init_params
*p_init
)
1393 struct stv0900_state
*state
= fe
->demodulator_priv
;
1394 enum fe_stv0900_error error
= STV0900_NO_ERROR
;
1395 enum fe_stv0900_error demodError
= STV0900_NO_ERROR
;
1398 struct stv0900_inode
*temp_int
= find_inode(state
->i2c_adap
,
1399 state
->config
->demod_address
);
1401 dprintk(KERN_INFO
"%s\n", __func__
);
1403 if (temp_int
!= NULL
) {
1404 state
->internal
= temp_int
->internal
;
1405 (state
->internal
->dmds_used
)++;
1406 dprintk(KERN_INFO
"%s: Find Internal Structure!\n", __func__
);
1407 return STV0900_NO_ERROR
;
1409 state
->internal
= kmalloc(sizeof(struct stv0900_internal
), GFP_KERNEL
);
1410 temp_int
= append_internal(state
->internal
);
1411 state
->internal
->dmds_used
= 1;
1412 state
->internal
->i2c_adap
= state
->i2c_adap
;
1413 state
->internal
->i2c_addr
= state
->config
->demod_address
;
1414 state
->internal
->clkmode
= state
->config
->clkmode
;
1415 state
->internal
->errs
= STV0900_NO_ERROR
;
1416 dprintk(KERN_INFO
"%s: Create New Internal Structure!\n", __func__
);
1419 if (state
->internal
!= NULL
) {
1420 demodError
= stv0900_initialize(state
->internal
);
1421 if (demodError
== STV0900_NO_ERROR
) {
1422 error
= STV0900_NO_ERROR
;
1424 if (demodError
== STV0900_INVALID_HANDLE
)
1425 error
= STV0900_INVALID_HANDLE
;
1427 error
= STV0900_I2C_ERROR
;
1430 if (state
->internal
!= NULL
) {
1431 if (error
== STV0900_NO_ERROR
) {
1432 state
->internal
->demod_mode
= p_init
->demod_mode
;
1434 stv0900_st_dvbs2_single(state
->internal
, state
->internal
->demod_mode
, STV0900_DEMOD_1
);
1436 state
->internal
->chip_id
= stv0900_read_reg(state
->internal
, R0900_MID
);
1437 state
->internal
->rolloff
= p_init
->rolloff
;
1438 state
->internal
->quartz
= p_init
->dmd_ref_clk
;
1440 stv0900_write_bits(state
->internal
, F0900_P1_ROLLOFF_CONTROL
, p_init
->rolloff
);
1441 stv0900_write_bits(state
->internal
, F0900_P2_ROLLOFF_CONTROL
, p_init
->rolloff
);
1443 state
->internal
->ts_config
= p_init
->ts_config
;
1444 if (state
->internal
->ts_config
== NULL
)
1445 stv0900_set_ts_parallel_serial(state
->internal
,
1446 p_init
->path1_ts_clock
,
1447 p_init
->path2_ts_clock
);
1449 for (i
= 0; state
->internal
->ts_config
[i
].addr
!= 0xffff; i
++)
1450 stv0900_write_reg(state
->internal
,
1451 state
->internal
->ts_config
[i
].addr
,
1452 state
->internal
->ts_config
[i
].val
);
1454 stv0900_write_bits(state
->internal
, F0900_P2_RST_HWARE
, 1);
1455 stv0900_write_bits(state
->internal
, F0900_P2_RST_HWARE
, 0);
1456 stv0900_write_bits(state
->internal
, F0900_P1_RST_HWARE
, 1);
1457 stv0900_write_bits(state
->internal
, F0900_P1_RST_HWARE
, 0);
1460 stv0900_write_bits(state
->internal
, F0900_P1_TUN_MADDRESS
, p_init
->tun1_maddress
);
1461 switch (p_init
->tuner1_adc
) {
1463 stv0900_write_reg(state
->internal
, R0900_TSTTNR1
, 0x26);
1469 stv0900_write_bits(state
->internal
, F0900_P2_TUN_MADDRESS
, p_init
->tun2_maddress
);
1470 switch (p_init
->tuner2_adc
) {
1472 stv0900_write_reg(state
->internal
, R0900_TSTTNR3
, 0x26);
1478 stv0900_write_bits(state
->internal
, F0900_P1_TUN_IQSWAP
, p_init
->tun1_iq_inversion
);
1479 stv0900_write_bits(state
->internal
, F0900_P2_TUN_IQSWAP
, p_init
->tun2_iq_inversion
);
1480 stv0900_set_mclk(state
->internal
, 135000000);
1483 switch (state
->internal
->clkmode
) {
1486 stv0900_write_reg(state
->internal
, R0900_SYNTCTRL
, 0x20 | state
->internal
->clkmode
);
1489 selosci
= 0x02 & stv0900_read_reg(state
->internal
, R0900_SYNTCTRL
);
1490 stv0900_write_reg(state
->internal
, R0900_SYNTCTRL
, 0x20 | selosci
);
1495 state
->internal
->mclk
= stv0900_get_mclk_freq(state
->internal
, state
->internal
->quartz
);
1496 if (state
->internal
->errs
)
1497 error
= STV0900_I2C_ERROR
;
1500 error
= STV0900_INVALID_HANDLE
;
1507 static int stv0900_status(struct stv0900_internal
*i_params
,
1508 enum fe_stv0900_demod_num demod
)
1510 enum fe_stv0900_search_state demod_state
;
1511 s32 mode_field
, delin_field
, lock_field
, fifo_field
, lockedvit_field
;
1514 dmd_reg(mode_field
, F0900_P1_HEADER_MODE
, F0900_P2_HEADER_MODE
);
1515 dmd_reg(lock_field
, F0900_P1_LOCK_DEFINITIF
, F0900_P2_LOCK_DEFINITIF
);
1516 dmd_reg(delin_field
, F0900_P1_PKTDELIN_LOCK
, F0900_P2_PKTDELIN_LOCK
);
1517 dmd_reg(fifo_field
, F0900_P1_TSFIFO_LINEOK
, F0900_P2_TSFIFO_LINEOK
);
1518 dmd_reg(lockedvit_field
, F0900_P1_LOCKEDVIT
, F0900_P2_LOCKEDVIT
);
1520 demod_state
= stv0900_get_bits(i_params
, mode_field
);
1521 switch (demod_state
) {
1522 case STV0900_SEARCH
:
1523 case STV0900_PLH_DETECTED
:
1527 case STV0900_DVBS2_FOUND
:
1528 locked
= stv0900_get_bits(i_params
, lock_field
) &&
1529 stv0900_get_bits(i_params
, delin_field
) &&
1530 stv0900_get_bits(i_params
, fifo_field
);
1532 case STV0900_DVBS_FOUND
:
1533 locked
= stv0900_get_bits(i_params
, lock_field
) &&
1534 stv0900_get_bits(i_params
, lockedvit_field
) &&
1535 stv0900_get_bits(i_params
, fifo_field
);
1542 static enum dvbfe_search
stv0900_search(struct dvb_frontend
*fe
,
1543 struct dvb_frontend_parameters
*params
)
1545 struct stv0900_state
*state
= fe
->demodulator_priv
;
1546 struct stv0900_internal
*i_params
= state
->internal
;
1547 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1549 struct stv0900_search_params p_search
;
1550 struct stv0900_signal_info p_result
;
1552 enum fe_stv0900_error error
= STV0900_NO_ERROR
;
1554 dprintk(KERN_INFO
"%s: ", __func__
);
1556 p_result
.locked
= FALSE
;
1557 p_search
.path
= state
->demod
;
1558 p_search
.frequency
= c
->frequency
;
1559 p_search
.symbol_rate
= c
->symbol_rate
;
1560 p_search
.search_range
= 10000000;
1561 p_search
.fec
= STV0900_FEC_UNKNOWN
;
1562 p_search
.standard
= STV0900_AUTO_SEARCH
;
1563 p_search
.iq_inversion
= STV0900_IQ_AUTO
;
1564 p_search
.search_algo
= STV0900_BLIND_SEARCH
;
1566 if ((INRANGE(100000, p_search
.symbol_rate
, 70000000)) &&
1567 (INRANGE(100000, p_search
.search_range
, 50000000))) {
1568 switch (p_search
.path
) {
1569 case STV0900_DEMOD_1
:
1571 i_params
->dmd1_srch_standard
= p_search
.standard
;
1572 i_params
->dmd1_symbol_rate
= p_search
.symbol_rate
;
1573 i_params
->dmd1_srch_range
= p_search
.search_range
;
1574 i_params
->tuner1_freq
= p_search
.frequency
;
1575 i_params
->dmd1_srch_algo
= p_search
.search_algo
;
1576 i_params
->dmd1_srch_iq_inv
= p_search
.iq_inversion
;
1577 i_params
->dmd1_fec
= p_search
.fec
;
1580 case STV0900_DEMOD_2
:
1581 i_params
->dmd2_srch_stndrd
= p_search
.standard
;
1582 i_params
->dmd2_symbol_rate
= p_search
.symbol_rate
;
1583 i_params
->dmd2_srch_range
= p_search
.search_range
;
1584 i_params
->tuner2_freq
= p_search
.frequency
;
1585 i_params
->dmd2_srch_algo
= p_search
.search_algo
;
1586 i_params
->dmd2_srch_iq_inv
= p_search
.iq_inversion
;
1587 i_params
->dmd2_fec
= p_search
.fec
;
1591 if ((stv0900_algo(fe
) == STV0900_RANGEOK
) &&
1592 (i_params
->errs
== STV0900_NO_ERROR
)) {
1593 switch (p_search
.path
) {
1594 case STV0900_DEMOD_1
:
1596 p_result
.locked
= i_params
->dmd1_rslts
.locked
;
1597 p_result
.standard
= i_params
->dmd1_rslts
.standard
;
1598 p_result
.frequency
= i_params
->dmd1_rslts
.frequency
;
1599 p_result
.symbol_rate
= i_params
->dmd1_rslts
.symbol_rate
;
1600 p_result
.fec
= i_params
->dmd1_rslts
.fec
;
1601 p_result
.modcode
= i_params
->dmd1_rslts
.modcode
;
1602 p_result
.pilot
= i_params
->dmd1_rslts
.pilot
;
1603 p_result
.frame_length
= i_params
->dmd1_rslts
.frame_length
;
1604 p_result
.spectrum
= i_params
->dmd1_rslts
.spectrum
;
1605 p_result
.rolloff
= i_params
->dmd1_rslts
.rolloff
;
1606 p_result
.modulation
= i_params
->dmd1_rslts
.modulation
;
1608 case STV0900_DEMOD_2
:
1609 p_result
.locked
= i_params
->dmd2_rslts
.locked
;
1610 p_result
.standard
= i_params
->dmd2_rslts
.standard
;
1611 p_result
.frequency
= i_params
->dmd2_rslts
.frequency
;
1612 p_result
.symbol_rate
= i_params
->dmd2_rslts
.symbol_rate
;
1613 p_result
.fec
= i_params
->dmd2_rslts
.fec
;
1614 p_result
.modcode
= i_params
->dmd2_rslts
.modcode
;
1615 p_result
.pilot
= i_params
->dmd2_rslts
.pilot
;
1616 p_result
.frame_length
= i_params
->dmd2_rslts
.frame_length
;
1617 p_result
.spectrum
= i_params
->dmd2_rslts
.spectrum
;
1618 p_result
.rolloff
= i_params
->dmd2_rslts
.rolloff
;
1619 p_result
.modulation
= i_params
->dmd2_rslts
.modulation
;
1624 p_result
.locked
= FALSE
;
1625 switch (p_search
.path
) {
1626 case STV0900_DEMOD_1
:
1627 switch (i_params
->dmd1_err
) {
1628 case STV0900_I2C_ERROR
:
1629 error
= STV0900_I2C_ERROR
;
1631 case STV0900_NO_ERROR
:
1633 error
= STV0900_SEARCH_FAILED
;
1637 case STV0900_DEMOD_2
:
1638 switch (i_params
->dmd2_err
) {
1639 case STV0900_I2C_ERROR
:
1640 error
= STV0900_I2C_ERROR
;
1642 case STV0900_NO_ERROR
:
1644 error
= STV0900_SEARCH_FAILED
;
1652 error
= STV0900_BAD_PARAMETER
;
1654 if ((p_result
.locked
== TRUE
) && (error
== STV0900_NO_ERROR
)) {
1655 dprintk(KERN_INFO
"Search Success\n");
1656 return DVBFE_ALGO_SEARCH_SUCCESS
;
1658 dprintk(KERN_INFO
"Search Fail\n");
1659 return DVBFE_ALGO_SEARCH_FAILED
;
1662 return DVBFE_ALGO_SEARCH_ERROR
;
1665 static int stv0900_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
1667 struct stv0900_state
*state
= fe
->demodulator_priv
;
1669 dprintk("%s: ", __func__
);
1671 if ((stv0900_status(state
->internal
, state
->demod
)) == TRUE
) {
1672 dprintk("DEMOD LOCK OK\n");
1673 *status
= FE_HAS_CARRIER
1678 dprintk("DEMOD LOCK FAIL\n");
1683 static int stv0900_track(struct dvb_frontend
*fe
,
1684 struct dvb_frontend_parameters
*p
)
1689 static int stv0900_stop_ts(struct dvb_frontend
*fe
, int stop_ts
)
1692 struct stv0900_state
*state
= fe
->demodulator_priv
;
1693 struct stv0900_internal
*i_params
= state
->internal
;
1694 enum fe_stv0900_demod_num demod
= state
->demod
;
1697 dmd_reg(rst_field
, F0900_P1_RST_HWARE
, F0900_P2_RST_HWARE
);
1699 if (stop_ts
== TRUE
)
1700 stv0900_write_bits(i_params
, rst_field
, 1);
1702 stv0900_write_bits(i_params
, rst_field
, 0);
1707 static int stv0900_diseqc_init(struct dvb_frontend
*fe
)
1709 struct stv0900_state
*state
= fe
->demodulator_priv
;
1710 struct stv0900_internal
*i_params
= state
->internal
;
1711 enum fe_stv0900_demod_num demod
= state
->demod
;
1712 s32 mode_field
, reset_field
;
1714 dmd_reg(mode_field
, F0900_P1_DISTX_MODE
, F0900_P2_DISTX_MODE
);
1715 dmd_reg(reset_field
, F0900_P1_DISEQC_RESET
, F0900_P2_DISEQC_RESET
);
1717 stv0900_write_bits(i_params
, mode_field
, state
->config
->diseqc_mode
);
1718 stv0900_write_bits(i_params
, reset_field
, 1);
1719 stv0900_write_bits(i_params
, reset_field
, 0);
1724 static int stv0900_init(struct dvb_frontend
*fe
)
1726 dprintk(KERN_INFO
"%s\n", __func__
);
1728 stv0900_stop_ts(fe
, 1);
1729 stv0900_diseqc_init(fe
);
1734 static int stv0900_diseqc_send(struct stv0900_internal
*i_params
, u8
*Data
,
1735 u32 NbData
, enum fe_stv0900_demod_num demod
)
1740 case STV0900_DEMOD_1
:
1742 stv0900_write_bits(i_params
, F0900_P1_DIS_PRECHARGE
, 1);
1743 while (i
< NbData
) {
1744 while (stv0900_get_bits(i_params
, F0900_P1_FIFO_FULL
))
1745 ;/* checkpatch complains */
1746 stv0900_write_reg(i_params
, R0900_P1_DISTXDATA
, Data
[i
]);
1750 stv0900_write_bits(i_params
, F0900_P1_DIS_PRECHARGE
, 0);
1752 while ((stv0900_get_bits(i_params
, F0900_P1_TX_IDLE
) != 1) && (i
< 10)) {
1758 case STV0900_DEMOD_2
:
1759 stv0900_write_bits(i_params
, F0900_P2_DIS_PRECHARGE
, 1);
1761 while (i
< NbData
) {
1762 while (stv0900_get_bits(i_params
, F0900_P2_FIFO_FULL
))
1763 ;/* checkpatch complains */
1764 stv0900_write_reg(i_params
, R0900_P2_DISTXDATA
, Data
[i
]);
1768 stv0900_write_bits(i_params
, F0900_P2_DIS_PRECHARGE
, 0);
1770 while ((stv0900_get_bits(i_params
, F0900_P2_TX_IDLE
) != 1) && (i
< 10)) {
1781 static int stv0900_send_master_cmd(struct dvb_frontend
*fe
,
1782 struct dvb_diseqc_master_cmd
*cmd
)
1784 struct stv0900_state
*state
= fe
->demodulator_priv
;
1786 return stv0900_diseqc_send(state
->internal
,
1792 static int stv0900_send_burst(struct dvb_frontend
*fe
, fe_sec_mini_cmd_t burst
)
1794 struct stv0900_state
*state
= fe
->demodulator_priv
;
1795 struct stv0900_internal
*i_params
= state
->internal
;
1796 enum fe_stv0900_demod_num demod
= state
->demod
;
1800 dmd_reg(mode_field
, F0900_P1_DISTX_MODE
, F0900_P2_DISTX_MODE
);
1801 dmd_reg(diseqc_fifo
, R0900_P1_DISTXDATA
, R0900_P2_DISTXDATA
);
1805 stv0900_write_bits(i_params
, mode_field
, 3);/* Unmodulated */
1806 stv0900_write_reg(i_params
, diseqc_fifo
, 0x00);
1809 stv0900_write_bits(i_params
, mode_field
, 2);/* Modulated */
1810 stv0900_write_reg(i_params
, diseqc_fifo
, 0xff);
1817 static int stv0900_recv_slave_reply(struct dvb_frontend
*fe
,
1818 struct dvb_diseqc_slave_reply
*reply
)
1820 struct stv0900_state
*state
= fe
->demodulator_priv
;
1821 struct stv0900_internal
*i_params
= state
->internal
;
1824 switch (state
->demod
) {
1825 case STV0900_DEMOD_1
:
1829 while ((stv0900_get_bits(i_params
, F0900_P1_RX_END
) != 1) && (i
< 10)) {
1834 if (stv0900_get_bits(i_params
, F0900_P1_RX_END
)) {
1835 reply
->msg_len
= stv0900_get_bits(i_params
, F0900_P1_FIFO_BYTENBR
);
1837 for (i
= 0; i
< reply
->msg_len
; i
++)
1838 reply
->msg
[i
] = stv0900_read_reg(i_params
, R0900_P1_DISRXDATA
);
1841 case STV0900_DEMOD_2
:
1844 while ((stv0900_get_bits(i_params
, F0900_P2_RX_END
) != 1) && (i
< 10)) {
1849 if (stv0900_get_bits(i_params
, F0900_P2_RX_END
)) {
1850 reply
->msg_len
= stv0900_get_bits(i_params
, F0900_P2_FIFO_BYTENBR
);
1852 for (i
= 0; i
< reply
->msg_len
; i
++)
1853 reply
->msg
[i
] = stv0900_read_reg(i_params
, R0900_P2_DISRXDATA
);
1861 static int stv0900_set_tone(struct dvb_frontend
*fe
, fe_sec_tone_mode_t tone
)
1863 struct stv0900_state
*state
= fe
->demodulator_priv
;
1864 struct stv0900_internal
*i_params
= state
->internal
;
1865 enum fe_stv0900_demod_num demod
= state
->demod
;
1866 s32 mode_field
, reset_field
;
1868 dprintk(KERN_INFO
"%s: %s\n", __func__
, ((tone
== 0) ? "Off" : "On"));
1870 dmd_reg(mode_field
, F0900_P1_DISTX_MODE
, F0900_P2_DISTX_MODE
);
1871 dmd_reg(reset_field
, F0900_P1_DISEQC_RESET
, F0900_P2_DISEQC_RESET
);
1874 /*Set the DiseqC mode to 22Khz continues tone*/
1875 stv0900_write_bits(i_params
, mode_field
, 0);
1876 stv0900_write_bits(i_params
, reset_field
, 1);
1877 /*release DiseqC reset to enable the 22KHz tone*/
1878 stv0900_write_bits(i_params
, reset_field
, 0);
1880 stv0900_write_bits(i_params
, mode_field
, 0);
1881 /*maintain the DiseqC reset to disable the 22KHz tone*/
1882 stv0900_write_bits(i_params
, reset_field
, 1);
1888 static void stv0900_release(struct dvb_frontend
*fe
)
1890 struct stv0900_state
*state
= fe
->demodulator_priv
;
1892 dprintk(KERN_INFO
"%s\n", __func__
);
1894 if ((--(state
->internal
->dmds_used
)) <= 0) {
1896 dprintk(KERN_INFO
"%s: Actually removing\n", __func__
);
1898 remove_inode(state
->internal
);
1899 kfree(state
->internal
);
1905 static struct dvb_frontend_ops stv0900_ops
= {
1908 .name
= "STV0900 frontend",
1910 .frequency_min
= 950000,
1911 .frequency_max
= 2150000,
1912 .frequency_stepsize
= 125,
1913 .frequency_tolerance
= 0,
1914 .symbol_rate_min
= 1000000,
1915 .symbol_rate_max
= 45000000,
1916 .symbol_rate_tolerance
= 500,
1917 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
|
1918 FE_CAN_FEC_3_4
| FE_CAN_FEC_5_6
|
1919 FE_CAN_FEC_7_8
| FE_CAN_QPSK
|
1920 FE_CAN_2G_MODULATION
|
1923 .release
= stv0900_release
,
1924 .init
= stv0900_init
,
1925 .get_frontend_algo
= stv0900_frontend_algo
,
1926 .i2c_gate_ctrl
= stv0900_i2c_gate_ctrl
,
1927 .diseqc_send_master_cmd
= stv0900_send_master_cmd
,
1928 .diseqc_send_burst
= stv0900_send_burst
,
1929 .diseqc_recv_slave_reply
= stv0900_recv_slave_reply
,
1930 .set_tone
= stv0900_set_tone
,
1931 .set_property
= stb0900_set_property
,
1932 .get_property
= stb0900_get_property
,
1933 .search
= stv0900_search
,
1934 .track
= stv0900_track
,
1935 .read_status
= stv0900_read_status
,
1936 .read_ber
= stv0900_read_ber
,
1937 .read_signal_strength
= stv0900_read_signal_strength
,
1938 .read_snr
= stv0900_read_snr
,
1939 .read_ucblocks
= stv0900_read_ucblocks
,
1942 struct dvb_frontend
*stv0900_attach(const struct stv0900_config
*config
,
1943 struct i2c_adapter
*i2c
,
1946 struct stv0900_state
*state
= NULL
;
1947 struct stv0900_init_params init_params
;
1948 enum fe_stv0900_error err_stv0900
;
1950 state
= kzalloc(sizeof(struct stv0900_state
), GFP_KERNEL
);
1954 state
->demod
= demod
;
1955 state
->config
= config
;
1956 state
->i2c_adap
= i2c
;
1958 memcpy(&state
->frontend
.ops
, &stv0900_ops
,
1959 sizeof(struct dvb_frontend_ops
));
1960 state
->frontend
.demodulator_priv
= state
;
1965 init_params
.dmd_ref_clk
= config
->xtal
;
1966 init_params
.demod_mode
= STV0900_DUAL
;
1967 init_params
.rolloff
= STV0900_35
;
1968 init_params
.path1_ts_clock
= config
->path1_mode
;
1969 init_params
.tun1_maddress
= config
->tun1_maddress
;
1970 init_params
.tun1_iq_inversion
= STV0900_IQ_NORMAL
;
1971 init_params
.tuner1_adc
= config
->tun1_adc
;
1972 init_params
.path2_ts_clock
= config
->path2_mode
;
1973 init_params
.ts_config
= config
->ts_config_regs
;
1974 init_params
.tun2_maddress
= config
->tun2_maddress
;
1975 init_params
.tuner2_adc
= config
->tun2_adc
;
1976 init_params
.tun2_iq_inversion
= STV0900_IQ_SWAPPED
;
1978 err_stv0900
= stv0900_init_internal(&state
->frontend
,
1990 dprintk("%s: Attaching STV0900 demodulator(%d) \n", __func__
, demod
);
1991 return &state
->frontend
;
1994 dprintk("%s: Failed to attach STV0900 demodulator(%d) \n",
1999 EXPORT_SYMBOL(stv0900_attach
);
2001 MODULE_PARM_DESC(debug
, "Set debug");
2003 MODULE_AUTHOR("Igor M. Liplianin");
2004 MODULE_DESCRIPTION("ST STV0900 frontend");
2005 MODULE_LICENSE("GPL");