2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
4 * flexcop-fe-tuner.c - methods for attaching a frontend and controlling DiSEqC.
6 * see flexcop.c for copyright information.
8 #include <media/tuner.h>
20 #include "tuner-simple.h"
32 static int flexcop_set_voltage(struct dvb_frontend
*fe
, fe_sec_voltage_t voltage
)
34 struct flexcop_device
*fc
= fe
->dvb
->priv
;
36 deb_tuner("polarity/voltage = %u\n", voltage
);
38 v
= fc
->read_ibi_reg(fc
, misc_204
);
41 v
.misc_204
.ACPI1_sig
= 1;
44 v
.misc_204
.ACPI1_sig
= 0;
45 v
.misc_204
.LNB_L_H_sig
= 0;
48 v
.misc_204
.ACPI1_sig
= 0;
49 v
.misc_204
.LNB_L_H_sig
= 1;
52 err("unknown SEC_VOLTAGE value");
55 return fc
->write_ibi_reg(fc
, misc_204
, v
);
58 static int flexcop_sleep(struct dvb_frontend
* fe
)
60 struct flexcop_device
*fc
= fe
->dvb
->priv
;
61 /* flexcop_ibi_value v = fc->read_ibi_reg(fc,misc_204); */
64 return fc
->fe_sleep(fe
);
66 /* v.misc_204.ACPI3_sig = 1;
67 fc->write_ibi_reg(fc,misc_204,v);*/
72 static int flexcop_set_tone(struct dvb_frontend
*fe
, fe_sec_tone_mode_t tone
)
74 /* u16 wz_half_period_for_45_mhz[] = { 0x01ff, 0x0154, 0x00ff, 0x00cc }; */
75 struct flexcop_device
*fc
= fe
->dvb
->priv
;
80 deb_tuner("tone = %u\n",tone
);
90 err("unknown SEC_TONE value");
94 v
.lnb_switch_freq_200
.LNB_CTLPrescaler_sig
= 1; /* divide by 2 */
96 v
.lnb_switch_freq_200
.LNB_CTLHighCount_sig
= ax
;
97 v
.lnb_switch_freq_200
.LNB_CTLLowCount_sig
= ax
== 0 ? 0x1ff : ax
;
99 return fc
->write_ibi_reg(fc
,lnb_switch_freq_200
,v
);
102 static void flexcop_diseqc_send_bit(struct dvb_frontend
* fe
, int data
)
104 flexcop_set_tone(fe
, SEC_TONE_ON
);
105 udelay(data
? 500 : 1000);
106 flexcop_set_tone(fe
, SEC_TONE_OFF
);
107 udelay(data
? 1000 : 500);
110 static void flexcop_diseqc_send_byte(struct dvb_frontend
* fe
, int data
)
114 for (i
= 7; i
>= 0; i
--) {
117 flexcop_diseqc_send_bit(fe
, d
);
120 flexcop_diseqc_send_bit(fe
, par
);
123 static int flexcop_send_diseqc_msg(struct dvb_frontend
* fe
, int len
, u8
*msg
, unsigned long burst
)
127 flexcop_set_tone(fe
, SEC_TONE_OFF
);
130 for (i
= 0; i
< len
; i
++)
131 flexcop_diseqc_send_byte(fe
,msg
[i
]);
137 flexcop_diseqc_send_byte(fe
, 0xff);
139 flexcop_set_tone(fe
, SEC_TONE_ON
);
142 flexcop_set_tone(fe
, SEC_TONE_OFF
);
149 static int flexcop_diseqc_send_master_cmd(struct dvb_frontend
* fe
, struct dvb_diseqc_master_cmd
* cmd
)
151 return flexcop_send_diseqc_msg(fe
, cmd
->msg_len
, cmd
->msg
, 0);
154 static int flexcop_diseqc_send_burst(struct dvb_frontend
* fe
, fe_sec_mini_cmd_t minicmd
)
156 return flexcop_send_diseqc_msg(fe
, 0, NULL
, minicmd
);
160 static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend
* fe
, u32 srate
, u32 ratio
)
165 if (srate
< 1500000) { aclk
= 0xb7; bclk
= 0x47; }
166 else if (srate
< 3000000) { aclk
= 0xb7; bclk
= 0x4b; }
167 else if (srate
< 7000000) { aclk
= 0xb7; bclk
= 0x4f; }
168 else if (srate
< 14000000) { aclk
= 0xb7; bclk
= 0x53; }
169 else if (srate
< 30000000) { aclk
= 0xb6; bclk
= 0x53; }
170 else if (srate
< 45000000) { aclk
= 0xb4; bclk
= 0x51; }
172 stv0299_writereg (fe
, 0x13, aclk
);
173 stv0299_writereg (fe
, 0x14, bclk
);
174 stv0299_writereg (fe
, 0x1f, (ratio
>> 16) & 0xff);
175 stv0299_writereg (fe
, 0x20, (ratio
>> 8) & 0xff);
176 stv0299_writereg (fe
, 0x21, (ratio
) & 0xf0);
181 static int samsung_tbmu24112_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*params
)
185 struct i2c_msg msg
= { .addr
= 0x61, .flags
= 0, .buf
= buf
, .len
= sizeof(buf
) };
186 struct flexcop_device
*fc
= fe
->dvb
->priv
;
188 div
= params
->frequency
/ 125;
190 buf
[0] = (div
>> 8) & 0x7f;
192 buf
[2] = 0x84; /* 0xC4 */
195 if (params
->frequency
< 1500000)
198 if (fe
->ops
.i2c_gate_ctrl
)
199 fe
->ops
.i2c_gate_ctrl(fe
, 1);
200 if (i2c_transfer(&fc
->fc_i2c_adap
[0].i2c_adap
, &msg
, 1) != 1)
205 static u8 samsung_tbmu24112_inittab
[] = {
250 static struct stv0299_config samsung_tbmu24112_config
= {
251 .demod_address
= 0x68,
252 .inittab
= samsung_tbmu24112_inittab
,
256 .lock_output
= STV0299_LOCKOUTPUT_LK
,
257 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
259 .set_symbol_rate
= samsung_tbmu24112_set_symbol_rate
,
263 static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend
* fe
)
265 static u8 mt352_clock_config
[] = { 0x89, 0x18, 0x2d };
266 static u8 mt352_reset
[] = { 0x50, 0x80 };
267 static u8 mt352_adc_ctl_1_cfg
[] = { 0x8E, 0x40 };
268 static u8 mt352_agc_cfg
[] = { 0x67, 0x28, 0xa1 };
269 static u8 mt352_capt_range_cfg
[] = { 0x75, 0x32 };
271 mt352_write(fe
, mt352_clock_config
, sizeof(mt352_clock_config
));
273 mt352_write(fe
, mt352_reset
, sizeof(mt352_reset
));
274 mt352_write(fe
, mt352_adc_ctl_1_cfg
, sizeof(mt352_adc_ctl_1_cfg
));
276 mt352_write(fe
, mt352_agc_cfg
, sizeof(mt352_agc_cfg
));
277 mt352_write(fe
, mt352_capt_range_cfg
, sizeof(mt352_capt_range_cfg
));
282 static int samsung_tdtc9251dh0_calc_regs(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*params
, u8
* pllbuf
, int buf_len
)
285 unsigned char bs
= 0;
290 #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
291 div
= (((params
->frequency
+ 83333) * 3) / 500000) + IF_FREQUENCYx6
;
293 if (params
->frequency
>= 48000000 && params
->frequency
<= 154000000) bs
= 0x09;
294 if (params
->frequency
>= 161000000 && params
->frequency
<= 439000000) bs
= 0x0a;
295 if (params
->frequency
>= 447000000 && params
->frequency
<= 863000000) bs
= 0x08;
298 pllbuf
[1] = div
>> 8;
299 pllbuf
[2] = div
& 0xff;
306 static struct mt352_config samsung_tdtc9251dh0_config
= {
307 .demod_address
= 0x0f,
308 .demod_init
= samsung_tdtc9251dh0_demod_init
,
311 static int flexcop_fe_request_firmware(struct dvb_frontend
* fe
, const struct firmware
**fw
, char* name
)
313 struct flexcop_device
*fc
= fe
->dvb
->priv
;
314 return request_firmware(fw
, name
, fc
->dev
);
317 static struct lgdt330x_config air2pc_atsc_hd5000_config
= {
318 .demod_address
= 0x59,
319 .demod_chip
= LGDT3303
,
321 .clock_polarity_flip
= 1,
324 static struct nxt200x_config samsung_tbmv_config
= {
325 .demod_address
= 0x0a,
328 static struct bcm3510_config air2pc_atsc_first_gen_config
= {
329 .demod_address
= 0x0f,
330 .request_firmware
= flexcop_fe_request_firmware
,
333 static int skystar23_samsung_tbdu18132_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*params
)
337 struct i2c_msg msg
= { .addr
= 0x61, .flags
= 0, .buf
= buf
, .len
= sizeof(buf
) };
338 struct flexcop_device
*fc
= fe
->dvb
->priv
;
340 div
= (params
->frequency
+ (125/2)) / 125;
342 buf
[0] = (div
>> 8) & 0x7f;
343 buf
[1] = (div
>> 0) & 0xff;
344 buf
[2] = 0x84 | ((div
>> 10) & 0x60);
347 if (params
->frequency
< 1550000)
350 if (fe
->ops
.i2c_gate_ctrl
)
351 fe
->ops
.i2c_gate_ctrl(fe
, 1);
352 if (i2c_transfer(&fc
->fc_i2c_adap
[0].i2c_adap
, &msg
, 1) != 1)
357 static struct mt312_config skystar23_samsung_tbdu18132_config
= {
359 .demod_address
= 0x0e,
362 static int alps_tdee4_stv0297_tuner_set_params(struct dvb_frontend
* fe
,
363 struct dvb_frontend_parameters
*fep
)
365 struct flexcop_device
*fc
= fe
->dvb
->priv
;
372 #define FREQ_OFFSET 36125
374 div
= ((fep
->frequency
/1000 + FREQ_OFFSET
) * 10) / REF_FREQ
; // 4 MHz = 4000 KHz
376 buf
[0] = (u8
)( div
>> 8) & 0x7f;
377 buf
[1] = (u8
) div
& 0xff;
379 /* F(osc) = N * Reference Freq. (62.5 kHz)
380 * byte 2 : 0 N14 N13 N12 N11 N10 N9 N8
381 * byte 3 : N7 N6 N5 N4 N3 N2 N1 N0
382 * byte 4 : 1 * * AGD R3 R2 R1 R0
383 * byte 5 : C1 * RE RTS BS4 BS3 BS2 BS1
384 * AGD = 1, R3 R2 R1 R0 = 0 1 0 1 => byte 4 = 1**10101 = 0x95 */
387 // Range(MHz) C1 * RE RTS BS4 BS3 BS2 BS1 Byte 5
388 // 47 - 153 0 * 0 0 0 0 0 1 0x01
389 // 153 - 430 0 * 0 0 0 0 1 0 0x02
390 // 430 - 822 0 * 0 0 1 0 0 0 0x08
391 // 822 - 862 1 * 0 0 1 0 0 0 0x88
393 if (fep
->frequency
<= 153000000) buf
[3] = 0x01;
394 else if (fep
->frequency
<= 430000000) buf
[3] = 0x02;
395 else if (fep
->frequency
<= 822000000) buf
[3] = 0x08;
398 if (fe
->ops
.i2c_gate_ctrl
)
399 fe
->ops
.i2c_gate_ctrl(fe
, 0);
400 deb_tuner("tuner buffer for %d Hz: %x %x %x %x\n",fep
->frequency
, buf
[0],buf
[1],buf
[2],buf
[3]);
401 ret
= fc
->i2c_request(&fc
->fc_i2c_adap
[2],
402 FC_WRITE
, 0x61, buf
[0], &buf
[1], 3);
403 deb_tuner("tuner write returned: %d\n",ret
);
408 static u8 alps_tdee4_stv0297_inittab
[] = {
481 static struct stv0297_config alps_tdee4_stv0297_config
= {
482 .demod_address
= 0x1c,
483 .inittab
= alps_tdee4_stv0297_inittab
,
485 // .pll_set = alps_tdee4_stv0297_pll_set,
489 /* SkyStar2 rev2.7 (a/u) */
490 static struct s5h1420_config skystar2_rev2_7_s5h1420_config
= {
491 .demod_address
= 0x53,
493 .repeated_start_workaround
= 1,
497 static struct itd1000_config skystar2_rev2_7_itd1000_config
= {
501 /* SkyStar2 rev2.8 */
502 static struct cx24123_config skystar2_rev2_8_cx24123_config
= {
503 .demod_address
= 0x55,
505 .agc_callback
= cx24113_agc_callback
,
508 static const struct cx24113_config skystar2_rev2_8_cx24113_config
= {
513 /* try to figure out the frontend, each card/box can have on of the following list */
514 int flexcop_frontend_init(struct flexcop_device
*fc
)
516 struct dvb_frontend_ops
*ops
;
517 struct i2c_adapter
*i2c
= &fc
->fc_i2c_adap
[0].i2c_adap
;
518 struct i2c_adapter
*i2c_tuner
;
520 /* enable no_base_addr - no repeated start when reading */
521 fc
->fc_i2c_adap
[0].no_base_addr
= 1;
522 fc
->fe
= dvb_attach(s5h1420_attach
, &skystar2_rev2_7_s5h1420_config
, i2c
);
523 if (fc
->fe
!= NULL
) {
524 flexcop_ibi_value r108
;
525 i2c_tuner
= s5h1420_get_tuner_i2c_adapter(fc
->fe
);
528 fc
->fe_sleep
= ops
->sleep
;
529 ops
->sleep
= flexcop_sleep
;
531 fc
->dev_type
= FC_SKY_REV27
;
533 /* enable no_base_addr - no repeated start when reading */
534 fc
->fc_i2c_adap
[2].no_base_addr
= 1;
535 if (dvb_attach(isl6421_attach
, fc
->fe
, &fc
->fc_i2c_adap
[2].i2c_adap
, 0x08, 1, 1) == NULL
)
536 err("ISL6421 could NOT be attached");
538 info("ISL6421 successfully attached");
540 /* the ITD1000 requires a lower i2c clock - it slows down the stuff for everyone - but is it a problem ? */
541 r108
.raw
= 0x00000506;
542 fc
->write_ibi_reg(fc
, tw_sm_c_108
, r108
);
544 if (dvb_attach(itd1000_attach
, fc
->fe
, i2c_tuner
, &skystar2_rev2_7_itd1000_config
) == NULL
)
545 err("ITD1000 could NOT be attached");
547 info("ITD1000 successfully attached");
551 fc
->fc_i2c_adap
[0].no_base_addr
= 0; /* for the next devices we need it again */
553 /* try the sky v2.8 (cx24123, isl6421) */
554 fc
->fe
= dvb_attach(cx24123_attach
,
555 &skystar2_rev2_8_cx24123_config
, i2c
);
556 if (fc
->fe
!= NULL
) {
557 i2c_tuner
= cx24123_get_tuner_i2c_adapter(fc
->fe
);
558 if (i2c_tuner
!= NULL
) {
559 if (dvb_attach(cx24113_attach
, fc
->fe
,
560 &skystar2_rev2_8_cx24113_config
,
562 err("CX24113 could NOT be attached");
564 info("CX24113 successfully attached");
567 fc
->dev_type
= FC_SKY_REV28
;
569 fc
->fc_i2c_adap
[2].no_base_addr
= 1;
570 if (dvb_attach(isl6421_attach
, fc
->fe
,
571 &fc
->fc_i2c_adap
[2].i2c_adap
, 0x08, 0, 0) == NULL
)
572 err("ISL6421 could NOT be attached");
574 info("ISL6421 successfully attached");
576 /* TODO on i2c_adap[1] addr 0x11 (EEPROM) there seems to be an
577 * IR-receiver (PIC16F818) - but the card has no input for
583 /* try the sky v2.6 (stv0299/Samsung tbmu24112(sl1935)) */
584 fc
->fe
= dvb_attach(stv0299_attach
, &samsung_tbmu24112_config
, i2c
);
585 if (fc
->fe
!= NULL
) {
588 ops
->tuner_ops
.set_params
= samsung_tbmu24112_tuner_set_params
;
590 ops
->set_voltage
= flexcop_set_voltage
;
592 fc
->fe_sleep
= ops
->sleep
;
593 ops
->sleep
= flexcop_sleep
;
595 fc
->dev_type
= FC_SKY_REV26
;
599 /* try the air dvb-t (mt352/Samsung tdtc9251dh0(??)) */
600 fc
->fe
= dvb_attach(mt352_attach
, &samsung_tdtc9251dh0_config
, i2c
);
601 if (fc
->fe
!= NULL
) {
602 fc
->dev_type
= FC_AIR_DVBT
;
603 fc
->fe
->ops
.tuner_ops
.calc_regs
= samsung_tdtc9251dh0_calc_regs
;
607 /* try the air atsc 2nd generation (nxt2002) */
608 fc
->fe
= dvb_attach(nxt200x_attach
, &samsung_tbmv_config
, i2c
);
609 if (fc
->fe
!= NULL
) {
610 fc
->dev_type
= FC_AIR_ATSC2
;
611 dvb_attach(dvb_pll_attach
, fc
->fe
, 0x61, NULL
, DVB_PLL_SAMSUNG_TBMV
);
615 fc
->fe
= dvb_attach(lgdt330x_attach
, &air2pc_atsc_hd5000_config
, i2c
);
616 if (fc
->fe
!= NULL
) {
617 fc
->dev_type
= FC_AIR_ATSC3
;
618 dvb_attach(simple_tuner_attach
, fc
->fe
, i2c
, 0x61,
619 TUNER_LG_TDVS_H06XF
);
623 /* try the air atsc 1nd generation (bcm3510)/panasonic ct10s */
624 fc
->fe
= dvb_attach(bcm3510_attach
, &air2pc_atsc_first_gen_config
, i2c
);
625 if (fc
->fe
!= NULL
) {
626 fc
->dev_type
= FC_AIR_ATSC1
;
630 /* try the cable dvb (stv0297) */
631 fc
->fc_i2c_adap
[0].no_base_addr
= 1;
632 fc
->fe
= dvb_attach(stv0297_attach
, &alps_tdee4_stv0297_config
, i2c
);
633 if (fc
->fe
!= NULL
) {
634 fc
->dev_type
= FC_CABLE
;
635 fc
->fe
->ops
.tuner_ops
.set_params
= alps_tdee4_stv0297_tuner_set_params
;
638 fc
->fc_i2c_adap
[0].no_base_addr
= 0;
640 /* try the sky v2.3 (vp310/Samsung tbdu18132(tsa5059)) */
641 fc
->fe
= dvb_attach(mt312_attach
,
642 &skystar23_samsung_tbdu18132_config
, i2c
);
643 if (fc
->fe
!= NULL
) {
646 ops
->tuner_ops
.set_params
= skystar23_samsung_tbdu18132_tuner_set_params
;
648 ops
->diseqc_send_master_cmd
= flexcop_diseqc_send_master_cmd
;
649 ops
->diseqc_send_burst
= flexcop_diseqc_send_burst
;
650 ops
->set_tone
= flexcop_set_tone
;
651 ops
->set_voltage
= flexcop_set_voltage
;
653 fc
->fe_sleep
= ops
->sleep
;
654 ops
->sleep
= flexcop_sleep
;
656 fc
->dev_type
= FC_SKY_REV23
;
660 err("no frontend driver found for this B2C2/FlexCop adapter");
664 info("found '%s' .", fc
->fe
->ops
.info
.name
);
665 if (dvb_register_frontend(&fc
->dvb_adapter
, fc
->fe
)) {
666 err("frontend registration failed!");
668 if (ops
->release
!= NULL
)
669 ops
->release(fc
->fe
);
673 fc
->init_state
|= FC_STATE_FE_INIT
;
677 void flexcop_frontend_exit(struct flexcop_device
*fc
)
679 if (fc
->init_state
& FC_STATE_FE_INIT
) {
680 dvb_unregister_frontend(fc
->fe
);
681 dvb_frontend_detach(fc
->fe
);
684 fc
->init_state
&= ~FC_STATE_FE_INIT
;