2 Universal driver for STV0299/TDA5059/SL1935 based
5 Alps BSRU6, LG TDQB-S00x
7 Copyright (C) 2001-2002 Convergence Integrated Media GmbH
8 <ralph@convergence.de>,
9 <holger@convergence.de>,
15 Copyright (C) 2002 by Peter Schildmann <peter.schildmann@web.de>
20 Copyright (C) 2002 Felix Domke <tmbinc@elitedvb.net>
21 & Andreas Oberritter <obi@linuxtv.org>
24 Support for Samsung TBMU24112IMB used on Technisat SkyStar2 rev. 2.6B
26 Copyright (C) 2003 Vadim Catana <skystar@moldova.cc>:
28 Support for Philips SU1278 on Technotrend hardware
30 Copyright (C) 2004 Andrew de Quincey <adq_dvb@lidskialf.net>
32 This program is free software; you can redistribute it and/or modify
33 it under the terms of the GNU General Public License as published by
34 the Free Software Foundation; either version 2 of the License, or
35 (at your option) any later version.
37 This program is distributed in the hope that it will be useful,
38 but WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 GNU General Public License for more details.
42 You should have received a copy of the GNU General Public License
43 along with this program; if not, write to the Free Software
44 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
48 #include <linux/init.h>
49 #include <linux/kernel.h>
50 #include <linux/module.h>
51 #include <linux/moduleparam.h>
52 #include <linux/string.h>
53 #include <linux/slab.h>
54 #include <asm/div64.h>
56 #include "dvb_frontend.h"
58 #define FRONTEND_NAME "dvbfe_stv0299"
60 #define dprintk(args...) \
62 if (debug) printk(KERN_DEBUG FRONTEND_NAME ": " args); \
66 static int stv0299_status
;
68 module_param(debug
, int, 0644);
69 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
70 module_param(stv0299_status
, int, 0444);
71 MODULE_PARM_DESC(stv0299_status
, "Which status value to support "
72 "(0 == BER (default), 1 == UCBLOCKS)");
75 #define STATUS_UCBLOCKS 1
79 #define UNKNOWN_FRONTEND -1
80 #define PHILIPS_SU1278_TSA 0 // SU1278 with TSA5059 synth and datasheet recommended settings
82 #define LG_TDQF_S001F 2
83 #define PHILIPS_SU1278_TUA 3 // SU1278 with TUA6100 synth
84 #define SAMSUNG_TBMU24112IMB 4
85 #define PHILIPS_SU1278_TSA_TT 5 // SU1278 with TSA5059 synth and TechnoTrend settings
86 #define PHILIPS_SU1278_TSA_TY 6 // SU1278 with TUA5059 synth and Typhoon wiring
87 #define PHILIPS_SU1278_TSA_CI 7 // SU1278 with TUA5059 synth and TerraTec Cinergy wiring
89 /* Master Clock = 88 MHz */
90 #define M_CLK (88000000UL)
92 /* Master Clock for TT cards = 64 MHz */
93 #define M_CLK_SU1278_TSA_TT (64000000UL)
95 static struct dvb_frontend_info uni0299_info
= {
96 .name
= "STV0299/TSA5059/SL1935 based",
98 .frequency_min
= 950000,
99 .frequency_max
= 2150000,
100 .frequency_stepsize
= 125, /* kHz for QPSK frontends */
101 .frequency_tolerance
= M_CLK
/2000,
102 .symbol_rate_min
= 1000000,
103 .symbol_rate_max
= 45000000,
104 .symbol_rate_tolerance
= 500, /* ppm */
106 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
107 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
|
113 struct stv0299_state
{
118 fe_code_rate_t fec_inner
;
119 struct i2c_adapter
*i2c
;
120 struct dvb_adapter
*dvb
;
124 static u8 init_tab
[] = {
125 0x04, 0x7d, /* F22FR = 0x7d */
126 /* F22 = f_VCO / 128 / 0x7d = 22 kHz */
128 /* I2C bus repeater */
129 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
131 /* general purpose DAC registers */
132 0x06, 0x40, /* DAC not used, set to high impendance mode */
133 0x07, 0x00, /* DAC LSB */
135 /* DiSEqC registers */
136 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
137 0x09, 0x00, /* FIFO */
139 /* Input/Output configuration register */
140 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
141 /* OP0 ctl = Normal, OP0 val = 1 (18 V) */
142 /* Nyquist filter = 00, QPSK reverse = 0 */
144 /* AGC1 control register */
145 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
147 /* Timing loop register */
148 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
150 0x10, 0x3f, // AGC2 0x3d
153 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on
155 0x15, 0xc9, // lock detector threshold
170 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
172 0x29, 0x1e, // 1/2 threshold
173 0x2a, 0x14, // 2/3 threshold
174 0x2b, 0x0f, // 3/4 threshold
175 0x2c, 0x09, // 5/6 threshold
176 0x2d, 0x05, // 7/8 threshold
179 0x31, 0x1f, // test all FECs
181 0x32, 0x19, // viterbi and synchro search
182 0x33, 0xfc, // rs control
183 0x34, 0x93, // error control
187 static u8 init_tab_samsung
[] = {
232 static u8 init_tab_su1278_tsa_tt
[] = {
277 static int stv0299_set_FEC (struct i2c_adapter
*i2c
, fe_code_rate_t fec
);
278 static int stv0299_set_symbolrate (struct i2c_adapter
*i2c
, u32 srate
, int tuner_type
);
280 static int stv0299_writereg (struct i2c_adapter
*i2c
, u8 reg
, u8 data
)
283 u8 buf
[] = { reg
, data
};
284 struct i2c_msg msg
= { .addr
= 0x68, .flags
= 0, .buf
= buf
, .len
= 2 };
286 ret
= i2c_transfer (i2c
, &msg
, 1);
289 dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, "
290 "ret == %i)\n", __FUNCTION__
, reg
, data
, ret
);
292 return (ret
!= 1) ? -EREMOTEIO
: 0;
296 static u8
stv0299_readreg (struct i2c_adapter
*i2c
, u8 reg
)
301 struct i2c_msg msg
[] = { { .addr
= 0x68, .flags
= 0, .buf
= b0
, .len
= 1 },
302 { .addr
= 0x68, .flags
= I2C_M_RD
, .buf
= b1
, .len
= 1 } };
304 ret
= i2c_transfer (i2c
, msg
, 2);
307 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n",
308 __FUNCTION__
, reg
, ret
);
314 static int stv0299_readregs (struct i2c_adapter
*i2c
, u8 reg1
, u8
*b
, u8 len
)
317 struct i2c_msg msg
[] = { { .addr
= 0x68, .flags
= 0, .buf
= ®1
, .len
= 1 },
318 { .addr
= 0x68, .flags
= I2C_M_RD
, .buf
= b
, .len
= len
} };
320 ret
= i2c_transfer (i2c
, msg
, 2);
323 dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__
, ret
);
325 return ret
== 2 ? 0 : ret
;
329 static int pll_write (struct i2c_adapter
*i2c
, u8 addr
, u8
*data
, int len
)
332 struct i2c_msg msg
= { .addr
= addr
, .buf
= data
, .len
= len
};
335 stv0299_writereg(i2c
, 0x05, 0xb5); /* enable i2c repeater on stv0299 */
337 ret
= i2c_transfer (i2c
, &msg
, 1);
339 stv0299_writereg(i2c
, 0x05, 0x35); /* disable i2c repeater on stv0299 */
342 dprintk("%s: i/o error (ret == %i)\n", __FUNCTION__
, ret
);
344 return (ret
!= 1) ? -1 : 0;
348 static int sl1935_set_tv_freq (struct i2c_adapter
*i2c
, u32 freq
, int ftype
)
355 dprintk("%s : freq = %i, div = %i\n", __FUNCTION__
, freq
, div
);
357 buf
[0] = (div
>> 8) & 0x7f;
359 buf
[2] = 0x84; // 0xC4
362 if (freq
< 1500000) buf
[3] |= 0x10;
364 return pll_write (i2c
, 0x61, buf
, sizeof(buf
));
368 * set up the downconverter frequency divisor for a
369 * reference clock comparision frequency of 125 kHz.
371 static int tsa5059_set_tv_freq (struct i2c_adapter
*i2c
, u32 freq
, int ftype
, int srate
)
376 int divisor
, regcode
;
378 dprintk ("%s: freq %i, ftype %i\n", __FUNCTION__
, freq
, ftype
);
380 if ((freq
< 950000) || (freq
> 2150000)) return -EINVAL
;
382 if (ftype
== PHILIPS_SU1278_TSA_TT
) {
390 // setup frequency divisor
391 div
= (freq
+ (divisor
- 1)) / divisor
; // round correctly
392 buf
[0] = (div
>> 8) & 0x7f;
394 buf
[2] = 0x80 | ((div
& 0x18000) >> 10) | regcode
;
397 // tuner-specific settings
399 case PHILIPS_SU1278_TSA
:
400 case PHILIPS_SU1278_TSA_TT
:
401 case PHILIPS_SU1278_TSA_TY
:
402 case PHILIPS_SU1278_TSA_CI
:
403 if (ftype
== PHILIPS_SU1278_TSA_TY
|| ftype
== PHILIPS_SU1278_TSA_CI
)
410 if (srate
< 4000000) buf
[3] |= 1;
412 if (freq
< 1250000) buf
[3] |= 0;
413 else if (freq
< 1550000) buf
[3] |= 0x40;
414 else if (freq
< 2050000) buf
[3] |= 0x80;
415 else if (freq
< 2150000) buf
[3] |= 0xC0;
421 if (freq
> 1530000) buf
[3] = 0xc0;
428 return pll_write (i2c
, addr
, buf
, sizeof(buf
));
432 #define MIN2(a,b) ((a) < (b) ? (a) : (b))
433 #define MIN3(a,b,c) MIN2(MIN2(a,b),c)
435 static int tua6100_set_tv_freq (struct i2c_adapter
*i2c
, u32 freq
,
436 int ftype
, int srate
)
438 u8 reg0
[2] = { 0x00, 0x00 };
439 u8 reg1
[4] = { 0x01, 0x00, 0x00, 0x00 };
440 u8 reg2
[3] = { 0x02, 0x00, 0x00 };
446 first_ZF
= (freq
) / 1000;
448 if (abs(MIN2(abs(first_ZF
-1190),abs(first_ZF
-1790))) <
449 abs(MIN3(abs(first_ZF
-1202),abs(first_ZF
-1542),abs(first_ZF
-1890))))
455 if (((first_ZF
>= 950) && (first_ZF
< 1350)) ||
456 ((first_ZF
>= 1430) && (first_ZF
< 1950)))
458 else if (((first_ZF
>= 1350) && (first_ZF
< 1430)) ||
459 ((first_ZF
>= 1950) && (first_ZF
< 2150)))
464 if (((first_ZF
>= 950) && (first_ZF
< 1350)) ||
465 ((first_ZF
>= 1455) && (first_ZF
< 1950)))
467 else if (((first_ZF
>= 1350) && (first_ZF
< 1420)) ||
468 ((first_ZF
>= 1950) && (first_ZF
< 2150)))
470 else if ((first_ZF
>= 1420) && (first_ZF
< 1455))
480 if (first_ZF
> 1430) { /* 1430MHZ */
481 reg1
[1] &= 0xCF; /* N2 */
482 reg2
[1] &= 0xCF; /* R2 */
485 reg1
[1] &= 0xCF; /* N2 */
487 reg2
[1] &= 0xCF; /* R2 */
493 if ((first_ZF
>= 1455) &&
495 reg1
[1] &= 0xCF; /* N2 */
497 reg2
[1] &= 0xCF; /* R2 */
499 if (first_ZF
< 1455) {
500 reg1
[1] &= 0xCF; /* N2 */
502 reg2
[1] &= 0xCF; /* R2 */
505 if (first_ZF
>= 1630) {
506 reg1
[1] &= 0xCF; /* N2 */
507 reg2
[1] &= 0xCF; /* R2 */
514 /* set ports, enable P0 for symbol rates > 4Ms/s */
515 if (srate
>= 4000000)
526 M
= (freq
* R
) / 4; /* in Mhz */
527 N
= (M
- A
* 1000) / (P
* 1000);
529 reg1
[1] |= (N
>> 9) & 0x03;
530 reg1
[2] = (N
>> 1) & 0xff;
531 reg1
[3] = (N
<< 7) & 0x80;
533 reg2
[1] |= (R
>> 8) & 0x03;
534 reg2
[2] = R
& 0xFF; /* R */
536 reg1
[3] |= A
& 0x7f; /* A */
539 reg1
[1] |= 0x40; /* Prescaler 64/65 */
543 if ((err
= pll_write(i2c
, 0x60, reg0
, sizeof(reg0
))))
546 if ((err
= pll_write(i2c
, 0x60, reg1
, sizeof(reg1
))))
549 if ((err
= pll_write(i2c
, 0x60, reg2
, sizeof(reg2
))))
556 static int pll_set_tv_freq (struct i2c_adapter
*i2c
, u32 freq
, int ftype
, int srate
)
559 case SAMSUNG_TBMU24112IMB
:
560 return sl1935_set_tv_freq(i2c
, freq
, ftype
);
563 return sl1935_set_tv_freq(i2c
, freq
, ftype
);
565 case PHILIPS_SU1278_TUA
:
566 return tua6100_set_tv_freq(i2c
, freq
, ftype
, srate
);
569 return tsa5059_set_tv_freq(i2c
, freq
, ftype
, srate
);
574 static int tsa5059_read_status (struct i2c_adapter
*i2c
)
577 u8 rpt1
[] = { 0x05, 0xb5 };
580 struct i2c_msg msg
[] = {{ .addr
= 0x68, .flags
= 0, .buf
= rpt1
, .len
= 2 },
581 { .addr
= 0x60, .flags
= I2C_M_RD
, .buf
= stat
, .len
= 1 }};
583 dprintk ("%s\n", __FUNCTION__
);
585 ret
= i2c_transfer (i2c
, msg
, 2);
588 dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__
, ret
);
595 static int stv0299_init (struct i2c_adapter
*i2c
, int ftype
)
599 dprintk("stv0299: init chip\n");
602 case SAMSUNG_TBMU24112IMB
:
603 dprintk("%s: init stv0299 chip for Samsung TBMU24112IMB\n", __FUNCTION__
);
605 for (i
=0; i
<sizeof(init_tab_samsung
); i
+=2)
607 dprintk("%s: reg == 0x%02x, val == 0x%02x\n", __FUNCTION__
, init_tab_samsung
[i
], init_tab_samsung
[i
+1]);
609 stv0299_writereg (i2c
, init_tab_samsung
[i
], init_tab_samsung
[i
+1]);
613 case PHILIPS_SU1278_TSA_TT
:
614 for (i
=0; i
<sizeof(init_tab_su1278_tsa_tt
); i
+=2) {
615 stv0299_writereg (i2c
, init_tab_su1278_tsa_tt
[i
], init_tab_su1278_tsa_tt
[i
+1]);
620 stv0299_writereg (i2c
, 0x01, 0x15);
621 stv0299_writereg (i2c
, 0x02, ftype
== PHILIPS_SU1278_TUA
? 0x00 : 0x30);
622 stv0299_writereg (i2c
, 0x03, 0x00);
624 for (i
=0; i
<sizeof(init_tab
); i
+=2)
625 stv0299_writereg (i2c
, init_tab
[i
], init_tab
[i
+1]);
627 /* AGC1 reference register setup */
628 if (ftype
== PHILIPS_SU1278_TSA
|| ftype
== PHILIPS_SU1278_TSA_TY
|| ftype
== PHILIPS_SU1278_TSA_CI
)
629 stv0299_writereg (i2c
, 0x0f, 0x92); /* Iagc = Inverse, m1 = 18 */
630 else if (ftype
== PHILIPS_SU1278_TUA
)
631 stv0299_writereg (i2c
, 0x0f, 0x94); /* Iagc = Inverse, m1 = 20 */
633 stv0299_writereg (i2c
, 0x0f, 0x52); /* Iagc = Normal, m1 = 18 */
637 switch(stv0299_status
) {
639 stv0299_writereg(i2c
, 0x34, 0x93);
642 case STATUS_UCBLOCKS
:
643 stv0299_writereg(i2c
, 0x34, 0xB3);
651 static int stv0299_set_FEC (struct i2c_adapter
*i2c
, fe_code_rate_t fec
)
653 dprintk ("%s\n", __FUNCTION__
);
658 dprintk ("%s : FEC_AUTO\n", __FUNCTION__
);
659 return stv0299_writereg (i2c
, 0x31, 0x1f);
663 dprintk ("%s : FEC_1_2\n", __FUNCTION__
);
664 return stv0299_writereg (i2c
, 0x31, 0x01);
668 dprintk ("%s : FEC_2_3\n", __FUNCTION__
);
669 return stv0299_writereg (i2c
, 0x31, 0x02);
673 dprintk ("%s : FEC_3_4\n", __FUNCTION__
);
674 return stv0299_writereg (i2c
, 0x31, 0x04);
678 dprintk ("%s : FEC_5_6\n", __FUNCTION__
);
679 return stv0299_writereg (i2c
, 0x31, 0x08);
683 dprintk ("%s : FEC_7_8\n", __FUNCTION__
);
684 return stv0299_writereg (i2c
, 0x31, 0x10);
688 dprintk ("%s : FEC invalid\n", __FUNCTION__
);
695 static fe_code_rate_t
stv0299_get_fec (struct i2c_adapter
*i2c
)
697 static fe_code_rate_t fec_tab
[] = { FEC_2_3
, FEC_3_4
, FEC_5_6
,
701 dprintk ("%s\n", __FUNCTION__
);
703 index
= stv0299_readreg (i2c
, 0x1b);
709 return fec_tab
[index
];
713 static int stv0299_wait_diseqc_fifo (struct i2c_adapter
*i2c
, int timeout
)
715 unsigned long start
= jiffies
;
717 dprintk ("%s\n", __FUNCTION__
);
719 while (stv0299_readreg(i2c
, 0x0a) & 1) {
720 if (jiffies
- start
> timeout
) {
721 dprintk ("%s: timeout!!\n", __FUNCTION__
);
731 static int stv0299_wait_diseqc_idle (struct i2c_adapter
*i2c
, int timeout
)
733 unsigned long start
= jiffies
;
735 dprintk ("%s\n", __FUNCTION__
);
737 while ((stv0299_readreg(i2c
, 0x0a) & 3) != 2 ) {
738 if (jiffies
- start
> timeout
) {
739 dprintk ("%s: timeout!!\n", __FUNCTION__
);
749 static int stv0299_send_diseqc_msg (struct i2c_adapter
*i2c
,
750 struct dvb_diseqc_master_cmd
*m
)
755 dprintk ("%s\n", __FUNCTION__
);
757 if (stv0299_wait_diseqc_idle (i2c
, 100) < 0)
760 val
= stv0299_readreg (i2c
, 0x08);
762 if (stv0299_writereg (i2c
, 0x08, (val
& ~0x7) | 0x6)) /* DiSEqC mode */
765 for (i
=0; i
<m
->msg_len
; i
++) {
766 if (stv0299_wait_diseqc_fifo (i2c
, 100) < 0)
769 if (stv0299_writereg (i2c
, 0x09, m
->msg
[i
]))
773 if (stv0299_wait_diseqc_idle (i2c
, 100) < 0)
780 static int stv0299_send_diseqc_burst (struct i2c_adapter
*i2c
, fe_sec_mini_cmd_t burst
)
784 dprintk ("%s\n", __FUNCTION__
);
786 if (stv0299_wait_diseqc_idle (i2c
, 100) < 0)
789 val
= stv0299_readreg (i2c
, 0x08);
791 if (stv0299_writereg (i2c
, 0x08, (val
& ~0x7) | 0x2)) /* burst mode */
794 if (stv0299_writereg (i2c
, 0x09, burst
== SEC_MINI_A
? 0x00 : 0xff))
797 if (stv0299_wait_diseqc_idle (i2c
, 100) < 0)
800 if (stv0299_writereg (i2c
, 0x08, val
))
807 static int stv0299_set_tone (struct i2c_adapter
*i2c
, fe_sec_tone_mode_t tone
)
811 dprintk("%s: %s\n", __FUNCTION__
,
812 tone
== SEC_TONE_ON
? "SEC_TONE_ON" :
813 tone
== SEC_TONE_OFF
? "SEC_TONE_OFF" : "??");
815 if (stv0299_wait_diseqc_idle (i2c
, 100) < 0)
818 val
= stv0299_readreg (i2c
, 0x08);
823 dprintk("%s: TONE_ON\n", __FUNCTION__
);
824 return stv0299_writereg (i2c
, 0x08, val
| 0x3);
828 dprintk("%s: TONE_OFF\n", __FUNCTION__
);
829 return stv0299_writereg (i2c
, 0x08, (val
& ~0x3) | 0x02);
833 dprintk("%s: TONE INVALID\n", __FUNCTION__
);
840 static int stv0299_set_voltage (struct i2c_adapter
*i2c
, fe_sec_voltage_t voltage
,
846 dprintk("%s: %s\n", __FUNCTION__
,
847 voltage
== SEC_VOLTAGE_13
? "SEC_VOLTAGE_13" :
848 voltage
== SEC_VOLTAGE_18
? "SEC_VOLTAGE_18" : "??");
850 reg0x08
= stv0299_readreg (i2c
, 0x08);
851 reg0x0c
= stv0299_readreg (i2c
, 0x0c);
854 * H/V switching over OP0, OP1 and OP2 are LNB power enable bits
858 if (voltage
== SEC_VOLTAGE_OFF
) {
859 stv0299_writereg (i2c
, 0x0c, 0x00); /* LNB power off! */
860 return stv0299_writereg (i2c
, 0x08, 0x00); /* LNB power off! */
863 if (tuner_type
== PHILIPS_SU1278_TSA_CI
)
865 stv0299_writereg (i2c
, 0x08, reg0x08
& 0xBF); // switch LNB power on OP2/LOCK pin off
869 stv0299_writereg (i2c
, 0x08, reg0x08
| 0x40);
874 if (tuner_type
== PHILIPS_SU1278_TSA_TY
|| tuner_type
== PHILIPS_SU1278_TSA_CI
)
875 return stv0299_writereg (i2c
, 0x0c, reg0x0c
| 0x10);
877 return stv0299_writereg (i2c
, 0x0c, reg0x0c
| 0x40);
880 return stv0299_writereg (i2c
, 0x0c, reg0x0c
| 0x50);
888 static int stv0299_send_legacy_dish_cmd(struct i2c_adapter
*i2c
, u32 cmd
,
894 /* reset voltage at the end
895 if((0x50 & stv0299_readreg (i2c, 0x0c)) == 0x50)
902 dprintk("%s switch command: 0x%04x\n",__FUNCTION__
, cmd
);
904 stv0299_set_voltage(i2c
,SEC_VOLTAGE_18
,tuner_type
);
907 for (i
=0; i
<9; i
++) {
908 if((cmd
& 0x01) != last
) {
909 stv0299_set_voltage(i2c
,
910 last
? SEC_VOLTAGE_13
:
913 last
= (last
) ? 0 : 1;
925 static int stv0299_set_symbolrate (struct i2c_adapter
*i2c
, u32 srate
, int tuner_type
)
934 // check rate is within limits
935 if ((srate
< 1000000) || (srate
> 45000000)) return -EINVAL
;
937 // calculate value to program
938 if (tuner_type
== PHILIPS_SU1278_TSA_TT
) Mclk
= M_CLK_SU1278_TSA_TT
;
940 big
+= (Mclk
-1); // round correctly
946 case PHILIPS_SU1278_TSA_TT
:
947 stv0299_writereg (i2c
, 0x0e, 0x44);
948 if (srate
>= 10000000) {
949 stv0299_writereg (i2c
, 0x13, 0x97);
950 stv0299_writereg (i2c
, 0x14, 0x95);
951 stv0299_writereg (i2c
, 0x15, 0xc9);
952 stv0299_writereg (i2c
, 0x17, 0x8c);
953 stv0299_writereg (i2c
, 0x1a, 0xfe);
954 stv0299_writereg (i2c
, 0x1c, 0x7f);
955 stv0299_writereg (i2c
, 0x2d, 0x09);
957 stv0299_writereg (i2c
, 0x13, 0x99);
958 stv0299_writereg (i2c
, 0x14, 0x8d);
959 stv0299_writereg (i2c
, 0x15, 0xce);
960 stv0299_writereg (i2c
, 0x17, 0x43);
961 stv0299_writereg (i2c
, 0x1a, 0x1d);
962 stv0299_writereg (i2c
, 0x1c, 0x12);
963 stv0299_writereg (i2c
, 0x2d, 0x05);
965 stv0299_writereg (i2c
, 0x0e, 0x23);
966 stv0299_writereg (i2c
, 0x0f, 0x94);
967 stv0299_writereg (i2c
, 0x10, 0x39);
968 stv0299_writereg (i2c
, 0x15, 0xc9);
970 stv0299_writereg (i2c
, 0x1f, (ratio
>> 16) & 0xff);
971 stv0299_writereg (i2c
, 0x20, (ratio
>> 8) & 0xff);
972 stv0299_writereg (i2c
, 0x21, (ratio
) & 0xf0);
975 case PHILIPS_SU1278_TSA_TY
:
976 case PHILIPS_SU1278_TSA_CI
:
977 case PHILIPS_SU1278_TSA
:
979 if (srate
< 2000000) bclk
= 0x86;
980 else if (srate
< 5000000) bclk
= 0x89;
981 else if (srate
< 15000000) bclk
= 0x8f;
982 else if (srate
< 45000000) bclk
= 0x95;
985 if (srate
< 4000000) m1
= 0x10;
987 stv0299_writereg (i2c
, 0x13, aclk
);
988 stv0299_writereg (i2c
, 0x14, bclk
);
989 stv0299_writereg (i2c
, 0x1f, (ratio
>> 16) & 0xff);
990 stv0299_writereg (i2c
, 0x20, (ratio
>> 8) & 0xff);
991 stv0299_writereg (i2c
, 0x21, (ratio
) & 0xf0);
992 stv0299_writereg (i2c
, 0x0f, (stv0299_readreg(i2c
, 0x0f) & 0xc0) | m1
);
997 if (srate
< 1500000) { aclk
= 0xb7; bclk
= 0x47; }
998 else if (srate
< 3000000) { aclk
= 0xb7; bclk
= 0x4b; }
999 else if (srate
< 7000000) { aclk
= 0xb7; bclk
= 0x4f; }
1000 else if (srate
< 14000000) { aclk
= 0xb7; bclk
= 0x53; }
1001 else if (srate
< 30000000) { aclk
= 0xb6; bclk
= 0x53; }
1002 else if (srate
< 45000000) { aclk
= 0xb4; bclk
= 0x51; }
1004 stv0299_writereg (i2c
, 0x13, aclk
);
1005 stv0299_writereg (i2c
, 0x14, bclk
);
1006 stv0299_writereg (i2c
, 0x1f, (ratio
>> 16) & 0xff);
1007 stv0299_writereg (i2c
, 0x20, (ratio
>> 8) & 0xff);
1008 stv0299_writereg (i2c
, 0x21, (ratio
) & 0xf0);
1017 static int stv0299_get_symbolrate (struct i2c_adapter
*i2c
, int tuner_type
)
1019 u32 Mclk
= M_CLK
/ 4096L;
1025 dprintk ("%s\n", __FUNCTION__
);
1027 if (tuner_type
== PHILIPS_SU1278_TSA_TT
) Mclk
= M_CLK_SU1278_TSA_TT
/ 4096L;
1029 stv0299_readregs (i2c
, 0x1f, sfr
, 3);
1030 stv0299_readregs (i2c
, 0x1a, &rtf
, 1);
1032 srate
= (sfr
[0] << 8) | sfr
[1];
1035 srate
+= (sfr
[2] >> 4) * Mclk
/ 256;
1037 offset
= (s32
) rtf
* (srate
/ 4096L);
1040 dprintk ("%s : srate = %i\n", __FUNCTION__
, srate
);
1041 dprintk ("%s : ofset = %i\n", __FUNCTION__
, offset
);
1052 static int uni0299_ioctl (struct dvb_frontend
*fe
, unsigned int cmd
, void *arg
)
1054 struct stv0299_state
*state
= (struct stv0299_state
*) fe
->data
;
1055 struct i2c_adapter
*i2c
= state
->i2c
;
1057 dprintk ("%s\n", __FUNCTION__
);
1062 struct dvb_frontend_info
* tmp
= (struct dvb_frontend_info
*) arg
;
1063 memcpy (arg
, &uni0299_info
, sizeof(struct dvb_frontend_info
));
1065 if (state
->tuner_type
== PHILIPS_SU1278_TSA_TT
) {
1066 tmp
->frequency_tolerance
= M_CLK_SU1278_TSA_TT
/ 2000;
1071 case FE_READ_STATUS
:
1073 fe_status_t
*status
= (fe_status_t
*) arg
;
1074 u8 signal
= 0xff - stv0299_readreg (i2c
, 0x18);
1075 u8 sync
= stv0299_readreg (i2c
, 0x1b);
1077 dprintk ("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __FUNCTION__
, sync
);
1082 *status
|= FE_HAS_SIGNAL
;
1085 *status
|= FE_HAS_CARRIER
;
1088 *status
|= FE_HAS_VITERBI
;
1091 *status
|= FE_HAS_SYNC
;
1093 if ((sync
& 0x98) == 0x98)
1094 *status
|= FE_HAS_LOCK
;
1100 if (stv0299_status
== STATUS_BER
) {
1101 *((u32
*) arg
) = (stv0299_readreg (i2c
, 0x1d) << 8)
1102 | stv0299_readreg (i2c
, 0x1e);
1108 case FE_READ_SIGNAL_STRENGTH
:
1110 s32 signal
= 0xffff - ((stv0299_readreg (i2c
, 0x18) << 8)
1111 | stv0299_readreg (i2c
, 0x19));
1113 dprintk ("%s : FE_READ_SIGNAL_STRENGTH : AGC2I: 0x%02x%02x, signal=0x%04x\n", __FUNCTION__
,
1114 stv0299_readreg (i2c
, 0x18),
1115 stv0299_readreg (i2c
, 0x19), (int) signal
);
1117 signal
= signal
* 5 / 4;
1118 *((u16
*) arg
) = (signal
> 0xffff) ? 0xffff :
1119 (signal
< 0) ? 0 : signal
;
1124 s32 snr
= 0xffff - ((stv0299_readreg (i2c
, 0x24) << 8)
1125 | stv0299_readreg (i2c
, 0x25));
1126 snr
= 3 * (snr
- 0xa100);
1127 *((u16
*) arg
) = (snr
> 0xffff) ? 0xffff :
1128 (snr
< 0) ? 0 : snr
;
1131 case FE_READ_UNCORRECTED_BLOCKS
:
1132 if (stv0299_status
== STATUS_UCBLOCKS
) {
1133 *((u32
*) arg
) = (stv0299_readreg (i2c
, 0x1d) << 8)
1134 | stv0299_readreg (i2c
, 0x1e);
1140 case FE_SET_FRONTEND
:
1142 struct dvb_frontend_parameters
*p
= arg
;
1145 dprintk ("%s : FE_SET_FRONTEND\n", __FUNCTION__
);
1147 // set the inversion
1148 if (p
->inversion
== INVERSION_OFF
) invval
= 0;
1149 else if (p
->inversion
== INVERSION_ON
) invval
= 1;
1151 printk("stv0299 does not support auto-inversion\n");
1154 if (state
->tuner_type
== ALPS_BSRU6
) invval
= (~invval
) & 1;
1155 stv0299_writereg(i2c
, 0x0c, (stv0299_readreg(i2c
, 0x0c) & 0xfe) | invval
);
1157 switch(state
->tuner_type
) {
1158 case PHILIPS_SU1278_TSA_TT
:
1160 /* check if we should do a finetune */
1161 int frequency_delta
= p
->frequency
- state
->tuner_frequency
;
1162 int minmax
= p
->u
.qpsk
.symbol_rate
/ 2000;
1163 if (minmax
< 5000) minmax
= 5000;
1165 if ((frequency_delta
> -minmax
) && (frequency_delta
< minmax
) && (frequency_delta
!= 0) &&
1166 (state
->fec_inner
== p
->u
.qpsk
.fec_inner
) &&
1167 (state
->symbol_rate
== p
->u
.qpsk
.symbol_rate
)) {
1168 int Drot_freq
= (frequency_delta
<< 16) / (M_CLK_SU1278_TSA_TT
/ 1000);
1170 // zap the derotator registers first
1171 stv0299_writereg (i2c
, 0x22, 0x00);
1172 stv0299_writereg (i2c
, 0x23, 0x00);
1174 // now set them as we want
1175 stv0299_writereg (i2c
, 0x22, Drot_freq
>> 8);
1176 stv0299_writereg (i2c
, 0x23, Drot_freq
);
1178 /* A "normal" tune is requested */
1179 pll_set_tv_freq (i2c
, p
->frequency
, state
->tuner_type
, p
->u
.qpsk
.symbol_rate
);
1180 stv0299_writereg (i2c
, 0x32, 0x80);
1181 stv0299_writereg (i2c
, 0x22, 0x00);
1182 stv0299_writereg (i2c
, 0x23, 0x00);
1183 stv0299_writereg (i2c
, 0x32, 0x19);
1184 stv0299_set_symbolrate (i2c
, p
->u
.qpsk
.symbol_rate
, state
->tuner_type
);
1185 stv0299_set_FEC (i2c
, p
->u
.qpsk
.fec_inner
);
1191 pll_set_tv_freq (i2c
, p
->frequency
, state
->tuner_type
, p
->u
.qpsk
.symbol_rate
);
1192 stv0299_set_FEC (i2c
, p
->u
.qpsk
.fec_inner
);
1193 stv0299_set_symbolrate (i2c
, p
->u
.qpsk
.symbol_rate
, state
->tuner_type
);
1194 stv0299_writereg (i2c
, 0x22, 0x00);
1195 stv0299_writereg (i2c
, 0x23, 0x00);
1196 stv0299_readreg (i2c
, 0x23);
1197 stv0299_writereg (i2c
, 0x12, 0xb9);
1201 state
->tuner_frequency
= p
->frequency
;
1202 state
->fec_inner
= p
->u
.qpsk
.fec_inner
;
1203 state
->symbol_rate
= p
->u
.qpsk
.symbol_rate
;
1207 case FE_GET_FRONTEND
:
1209 struct dvb_frontend_parameters
*p
= arg
;
1214 if (state
->tuner_type
== PHILIPS_SU1278_TSA_TT
) Mclk
= M_CLK_SU1278_TSA_TT
;
1216 derot_freq
= (s32
)(s16
) ((stv0299_readreg (i2c
, 0x22) << 8)
1217 | stv0299_readreg (i2c
, 0x23));
1219 derot_freq
*= (Mclk
>> 16);
1223 p
->frequency
+= derot_freq
;
1225 invval
= stv0299_readreg (i2c
, 0x0c) & 1;
1226 if (state
->tuner_type
== ALPS_BSRU6
) invval
= (~invval
) & 1;
1227 p
->inversion
= invval
? INVERSION_ON
: INVERSION_OFF
;
1229 p
->u
.qpsk
.fec_inner
= stv0299_get_fec (i2c
);
1230 p
->u
.qpsk
.symbol_rate
= stv0299_get_symbolrate (i2c
, state
->tuner_type
);
1235 stv0299_writereg (i2c
, 0x0c, 0x00); /* LNB power off! */
1236 stv0299_writereg (i2c
, 0x08, 0x00); /* LNB power off! */
1237 stv0299_writereg (i2c
, 0x02, 0x80);
1238 state
->initialised
= 0;
1242 switch(state
->tuner_type
) {
1243 case PHILIPS_SU1278_TSA_TT
:
1244 state
->tuner_frequency
= 0;
1245 if (!state
->initialised
) {
1246 state
->initialised
= 1;
1247 return stv0299_init (i2c
, state
->tuner_type
);
1252 return stv0299_init (i2c
, state
->tuner_type
);
1256 case FE_DISEQC_SEND_MASTER_CMD
:
1257 return stv0299_send_diseqc_msg (i2c
, arg
);
1259 case FE_DISEQC_SEND_BURST
:
1260 return stv0299_send_diseqc_burst (i2c
, (fe_sec_mini_cmd_t
) arg
);
1263 return stv0299_set_tone (i2c
, (fe_sec_tone_mode_t
) arg
);
1265 case FE_SET_VOLTAGE
:
1266 return stv0299_set_voltage (i2c
, (fe_sec_voltage_t
) arg
,
1269 case FE_DISHNETWORK_SEND_LEGACY_CMD
:
1270 return stv0299_send_legacy_dish_cmd (i2c
, (u32
) arg
,
1273 case FE_GET_TUNE_SETTINGS
:
1275 struct dvb_frontend_tune_settings
* fesettings
= (struct dvb_frontend_tune_settings
*) arg
;
1277 switch(state
->tuner_type
) {
1278 case PHILIPS_SU1278_TSA_TT
:
1279 fesettings
->min_delay_ms
= 50;
1280 if (fesettings
->parameters
.u
.qpsk
.symbol_rate
< 10000000) {
1281 fesettings
->step_size
= fesettings
->parameters
.u
.qpsk
.symbol_rate
/ 32000;
1282 fesettings
->max_drift
= 5000;
1284 fesettings
->step_size
= fesettings
->parameters
.u
.qpsk
.symbol_rate
/ 16000;
1285 fesettings
->max_drift
= fesettings
->parameters
.u
.qpsk
.symbol_rate
/ 2000;
1290 fesettings
->min_delay_ms
= 100;
1291 if (fesettings
->parameters
.u
.qpsk
.symbol_rate
< 10000000) {
1292 fesettings
->step_size
= fesettings
->parameters
.u
.qpsk
.symbol_rate
/ 32000;
1293 fesettings
->max_drift
= 5000;
1295 fesettings
->step_size
= fesettings
->parameters
.u
.qpsk
.symbol_rate
/ 16000;
1296 fesettings
->max_drift
= fesettings
->parameters
.u
.qpsk
.symbol_rate
/ 2000;
1311 static long probe_tuner (struct i2c_adapter
*adapter
)
1313 struct i2c_adapter
*i2c
= adapter
; /* superfluous */
1315 /* read the status register of TSA5059 */
1316 u8 rpt
[] = { 0x05, 0xb5 };
1318 u8 tda6100_buf
[] = { 0, 0 };
1320 struct i2c_msg msg1
[] = {{ .addr
= 0x68, .flags
= 0, .buf
= rpt
, len
: 2 },
1321 { .addr
= 0x60, .flags
= I2C_M_RD
, .buf
= stat
, .len
= 1 }};
1322 struct i2c_msg msg2
[] = {{ .addr
= 0x68, .flags
= 0, .buf
= rpt
, len
: 2 },
1323 { .addr
= 0x61, .flags
= I2C_M_RD
, .buf
= stat
, .len
= 1 }};
1324 struct i2c_msg msg3
[] = {{ .addr
= 0x68, .flags
= 0, .buf
= rpt
, len
: 2 },
1325 { .addr
= 0x60, .flags
= 0, .buf
= tda6100_buf
, .len
= 2 }};
1327 stv0299_writereg (i2c
, 0x01, 0x15);
1328 stv0299_writereg (i2c
, 0x02, 0x30);
1329 stv0299_writereg (i2c
, 0x03, 0x00);
1332 printk("stv0299: try to attach to %s\n", adapter
->name
);
1334 if (!strcmp(adapter
->name
, "SkyStar2")) {
1335 printk ("stv0299: setup for tuner Samsung TBMU24112IMB\n");
1336 return SAMSUNG_TBMU24112IMB
;
1339 if ((ret
= i2c_transfer(i2c
, msg1
, 2)) == 2) {
1340 if ( strcmp(adapter
->name
, "TT-Budget/WinTV-NOVA-CI PCI") == 0 ) {
1341 // technotrend cards require non-datasheet settings
1342 printk ("stv0299: setup for tuner SU1278 (TSA5059 synth) on TechnoTrend hardware\n");
1343 return PHILIPS_SU1278_TSA_TT
;
1345 // fall back to datasheet-recommended settings
1346 printk ("stv0299: setup for tuner SU1278 (TSA5059 synth)\n");
1347 return PHILIPS_SU1278_TSA
;
1351 if ((ret
= i2c_transfer(i2c
, msg2
, 2)) == 2) {
1352 if ( strcmp(adapter
->name
, "KNC1 DVB-S") == 0 )
1354 // Typhoon cards have unusual wiring.
1355 printk ("stv0299: setup for tuner SU1278 (TSA5059 synth) on Typhoon hardware\n");
1356 return PHILIPS_SU1278_TSA_TY
;
1358 else if ( strcmp(adapter
->name
, "TerraTec Cinergy 1200 DVB-S") == 0 )
1360 // Cinergy cards have unusual wiring.
1361 printk ("%s: setup for tuner SU1278 (TSA5059 synth) on"
1362 " TerraTec hardware\n", __FILE__
);
1363 return PHILIPS_SU1278_TSA_CI
;
1365 //else if ((stat[0] & 0x3f) == 0) {
1367 printk ("stv0299: setup for tuner TDQF-S001F\n");
1368 return LG_TDQF_S001F
;
1370 printk ("stv0299: setup for tuner BSRU6, TDQB-S00x\n");
1376 * setup i2c timing for SU1278...
1378 stv0299_writereg (i2c
, 0x02, 0x00);
1380 if ((ret
= i2c_transfer(i2c
, msg3
, 2)) == 2) {
1381 printk ("stv0299: setup for tuner Philips SU1278 (TUA6100 synth)\n");
1382 return PHILIPS_SU1278_TUA
;
1385 printk ("stv0299: unknown PLL synthesizer (ret == %i), please report to <linuxdvb@linuxtv.org>!!\n", ret
);
1387 return UNKNOWN_FRONTEND
;
1390 static struct i2c_client client_template
;
1392 static int attach_adapter(struct i2c_adapter
*adapter
)
1394 struct i2c_client
*client
;
1395 struct stv0299_state
* state
;
1400 stv0299_writereg(adapter
, 0x02, 0x34); /* standby off */
1402 id
= stv0299_readreg(adapter
, 0x00);
1404 dprintk ("%s: id == 0x%02x\n", __FUNCTION__
, id
);
1406 /* register 0x00 contains 0xa1 for STV0299 and STV0299B */
1407 /* register 0x00 might contain 0x80 when returning from standby */
1408 if (id
!= 0xa1 && id
!= 0x80)
1411 if ((tuner_type
= probe_tuner(adapter
)) < 0)
1414 if ((state
= kmalloc(sizeof(struct stv0299_state
), GFP_KERNEL
)) == NULL
) {
1418 if (NULL
== (client
= kmalloc(sizeof(struct i2c_client
), GFP_KERNEL
))) {
1423 state
->tuner_type
= tuner_type
;
1424 state
->tuner_frequency
= 0;
1425 state
->initialised
= 0;
1426 state
->i2c
= adapter
;
1428 memcpy(client
, &client_template
, sizeof(struct i2c_client
));
1429 client
->adapter
= adapter
;
1430 client
->addr
= (0x68>>1);
1431 i2c_set_clientdata(client
, (void*)state
);
1433 ret
= i2c_attach_client(client
);
1440 BUG_ON(!state
->dvb
);
1442 ret
= dvb_register_frontend(uni0299_ioctl
, state
->dvb
, state
,
1443 &uni0299_info
, THIS_MODULE
);
1445 i2c_detach_client(client
);
1454 static int detach_client(struct i2c_client
*client
)
1456 struct stv0299_state
*state
= (struct stv0299_state
*)i2c_get_clientdata(client
);
1458 dvb_unregister_frontend (uni0299_ioctl
, state
->dvb
);
1459 i2c_detach_client(client
);
1465 static int command (struct i2c_client
*client
, unsigned int cmd
, void *arg
)
1467 struct stv0299_state
*data
= (struct stv0299_state
*)i2c_get_clientdata(client
);
1468 dprintk ("%s\n", __FUNCTION__
);
1472 data
->dvb
= (struct dvb_adapter
*)arg
;
1475 case FE_UNREGISTER
: {
1485 static struct i2c_driver driver
= {
1486 .owner
= THIS_MODULE
,
1487 .name
= FRONTEND_NAME
,
1488 .id
= I2C_DRIVERID_DVBFE_STV0299
,
1489 .flags
= I2C_DF_NOTIFY
,
1490 .attach_adapter
= attach_adapter
,
1491 .detach_client
= detach_client
,
1495 static struct i2c_client client_template
= {
1496 .name
= FRONTEND_NAME
,
1497 .flags
= I2C_CLIENT_ALLOW_USE
,
1501 static int __init
init_uni0299 (void)
1503 return i2c_add_driver(&driver
);
1506 static void __exit
exit_uni0299 (void)
1508 if (i2c_del_driver(&driver
))
1509 printk("stv0299: driver deregistration failed\n");
1512 module_init (init_uni0299
);
1513 module_exit (exit_uni0299
);
1515 MODULE_DESCRIPTION("Universal STV0299/TSA5059/SL1935 DVB Frontend driver");
1516 MODULE_AUTHOR("Ralph Metzler, Holger Waechtler, Peter Schildmann, Felix Domke, "
1517 "Andreas Oberritter, Andrew de Quincey, Kenneth Aafløy");
1518 MODULE_LICENSE("GPL");