23 #include <linux/i2c.h>
24 #include <linux/slab.h>
26 #include <linux/videodev2.h>
36 static int deemphasis_50;
61 static int tda8290_i2c_bridge(
struct dvb_frontend *fe,
int close)
65 unsigned char enable[2] = { 0x21, 0xC0 };
66 unsigned char disable[2] = { 0x21, 0x00 };
71 tuner_i2c_xfer_send(&priv->
i2c_props, msg, 2);
76 tuner_i2c_xfer_send(&priv->
i2c_props, msg, 2);
82 static int tda8295_i2c_bridge(
struct dvb_frontend *fe,
int close)
86 unsigned char enable[2] = { 0x45, 0xc1 };
87 unsigned char disable[2] = { 0x46, 0x00 };
88 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
93 tuner_i2c_xfer_send(&priv->
i2c_props, msg, 2);
98 tuner_i2c_xfer_send_recv(&priv->
i2c_props, msg, 1, &msg[1], 1);
102 tuner_i2c_xfer_send(&priv->
i2c_props, buf, 3);
106 tuner_i2c_xfer_send(&priv->
i2c_props, msg, 2);
151 tuner_dbg(
"setting tda829x to system %s\n", mode);
182 unsigned char expert_mode[] = { 0x01, 0x80 };
183 unsigned char agc_out_on[] = { 0x02, 0x00 };
184 unsigned char gainset_off[] = { 0x28, 0x14 };
185 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
186 unsigned char adc_head_6[] = { 0x05, 0x04 };
187 unsigned char adc_head_9[] = { 0x05, 0x02 };
188 unsigned char adc_head_12[] = { 0x05, 0x01 };
189 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
190 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
191 unsigned char gainset_2[] = { 0x28, 0x64 };
192 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
193 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
194 unsigned char if_agc_set[] = { 0x0f, 0x81 };
195 unsigned char addr_adc_sat = 0x1a;
196 unsigned char addr_agc_stat = 0x1d;
197 unsigned char addr_pll_stat = 0x1b;
198 unsigned char adc_sat, agc_stat,
202 set_audio(fe, params);
204 if (priv->
cfg.config)
205 tuner_dbg(
"tda827xa config is 0x%02x\n", priv->
cfg.config);
206 tuner_i2c_xfer_send(&priv->
i2c_props, easy_mode, 2);
207 tuner_i2c_xfer_send(&priv->
i2c_props, agc_out_on, 2);
208 tuner_i2c_xfer_send(&priv->
i2c_props, soft_reset, 2);
212 unsigned char deemphasis[] = { 0x13, 1 };
220 tuner_i2c_xfer_send(&priv->
i2c_props, fm_mode[i].seq, 2);
222 tuner_i2c_xfer_send(&priv->
i2c_props, deemphasis, 2);
225 tuner_i2c_xfer_send(&priv->
i2c_props, expert_mode, 2);
226 tuner_i2c_xfer_send(&priv->
i2c_props, gainset_off, 2);
227 tuner_i2c_xfer_send(&priv->
i2c_props, if_agc_spd, 2);
229 tuner_i2c_xfer_send(&priv->
i2c_props, adc_head_9, 2);
231 tuner_i2c_xfer_send(&priv->
i2c_props, adc_head_6, 2);
232 tuner_i2c_xfer_send(&priv->
i2c_props, pll_bw_nom, 2);
236 tda8290_i2c_bridge(fe, 1);
238 if (fe->
ops.tuner_ops.set_analog_params)
239 fe->
ops.tuner_ops.set_analog_params(fe, params);
241 for (i = 0; i < 3; i++) {
242 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
243 &addr_pll_stat, 1, &pll_stat, 1);
244 if (pll_stat & 0x80) {
245 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
248 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
251 tuner_dbg(
"tda8290 is locked, AGC: %d\n", agc_stat);
254 tuner_dbg(
"tda8290 not locked, no signal?\n");
259 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
260 tuner_dbg(
"adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
261 agc_stat, adc_sat, pll_stat & 0x80);
262 tuner_i2c_xfer_send(&priv->
i2c_props, gainset_2, 2);
264 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
265 &addr_agc_stat, 1, &agc_stat, 1);
266 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
267 &addr_pll_stat, 1, &pll_stat, 1);
268 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
269 tuner_dbg(
"adjust gain, step 2. Agc: %d, lock: %d\n",
270 agc_stat, pll_stat & 0x80);
274 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
277 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
280 if((agc_stat > 115) || !(pll_stat & 0x80)) {
281 tuner_dbg(
"adjust gain, step 3. Agc: %d\n", agc_stat);
282 tuner_i2c_xfer_send(&priv->
i2c_props, adc_head_12, 2);
283 tuner_i2c_xfer_send(&priv->
i2c_props, pll_bw_low, 2);
291 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
294 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
297 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
298 tuner_dbg(
"trying to resolve SECAM L deadlock\n");
299 tuner_i2c_xfer_send(&priv->
i2c_props, agc_rst_on, 2);
301 tuner_i2c_xfer_send(&priv->
i2c_props, agc_rst_off, 2);
305 tda8290_i2c_bridge(fe, 0);
306 tuner_i2c_xfer_send(&priv->
i2c_props, if_agc_set, 2);
311 static void tda8295_power(
struct dvb_frontend *fe,
int enable)
314 unsigned char buf[] = { 0x30, 0x00 };
316 tuner_i2c_xfer_send_recv(&priv->
i2c_props, &buf[0], 1, &buf[1], 1);
323 tuner_i2c_xfer_send(&priv->
i2c_props, buf, 2);
326 static void tda8295_set_easy_mode(
struct dvb_frontend *fe,
int enable)
329 unsigned char buf[] = { 0x01, 0x00 };
331 tuner_i2c_xfer_send_recv(&priv->
i2c_props, &buf[0], 1, &buf[1], 1);
338 tuner_i2c_xfer_send(&priv->
i2c_props, buf, 2);
341 static void tda8295_set_video_std(
struct dvb_frontend *fe)
346 tuner_i2c_xfer_send(&priv->
i2c_props, buf, 2);
348 tda8295_set_easy_mode(fe, 1);
350 tda8295_set_easy_mode(fe, 0);
355 static void tda8295_agc1_out(
struct dvb_frontend *fe,
int enable)
358 unsigned char buf[] = { 0x02, 0x00 };
360 tuner_i2c_xfer_send_recv(&priv->
i2c_props, &buf[0], 1, &buf[1], 1);
367 tuner_i2c_xfer_send(&priv->
i2c_props, buf, 2);
370 static void tda8295_agc2_out(
struct dvb_frontend *fe,
int enable)
373 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
374 unsigned char set_gpio_val[] = { 0x46, 0x00 };
376 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
377 &set_gpio_cf[0], 1, &set_gpio_cf[1], 1);
378 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
379 &set_gpio_val[0], 1, &set_gpio_val[1], 1);
381 set_gpio_cf[1] &= 0xf0;
384 set_gpio_cf[1] |= 0x01;
385 set_gpio_val[1] &= 0xfe;
387 tuner_i2c_xfer_send(&priv->
i2c_props, set_gpio_cf, 2);
388 tuner_i2c_xfer_send(&priv->
i2c_props, set_gpio_val, 2);
395 unsigned char hvpll_stat = 0x26;
398 tuner_i2c_xfer_send_recv(&priv->
i2c_props, &hvpll_stat, 1, &ret, 1);
399 return (ret & 0x01) ? 65535 : 0;
409 unsigned char blanking_mode[] = { 0x1d, 0x00 };
411 set_audio(fe, params);
415 tda8295_power(fe, 1);
416 tda8295_agc1_out(fe, 1);
418 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
419 &blanking_mode[0], 1, &blanking_mode[1], 1);
421 tda8295_set_video_std(fe);
423 blanking_mode[1] = 0x03;
424 tuner_i2c_xfer_send(&priv->
i2c_props, blanking_mode, 2);
427 tda8295_i2c_bridge(fe, 1);
429 if (fe->
ops.tuner_ops.set_analog_params)
430 fe->
ops.tuner_ops.set_analog_params(fe, params);
435 if (tda8295_has_signal(fe))
438 tuner_dbg(
"tda8295 not locked, no signal?\n");
440 tda8295_i2c_bridge(fe, 0);
449 unsigned char i2c_get_afc[1] = { 0x1B };
450 unsigned char afc = 0;
452 tuner_i2c_xfer_send_recv(&priv->
i2c_props,
453 i2c_get_afc,
ARRAY_SIZE(i2c_get_afc), &afc, 1);
454 return (afc & 0x80)? 65535:0;
463 unsigned char cb1[] = { 0x30, 0xD0 };
464 unsigned char tda8290_standby[] = { 0x00, 0x02 };
465 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
468 tda8290_i2c_bridge(fe, 1);
472 tda8290_i2c_bridge(fe, 0);
473 tuner_i2c_xfer_send(&priv->
i2c_props, tda8290_agc_tri, 2);
474 tuner_i2c_xfer_send(&priv->
i2c_props, tda8290_standby, 2);
479 tda8295_agc1_out(fe, 0);
481 tda8295_power(fe, 0);
488 unsigned char set_VS[] = { 0x30, 0x6F };
489 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
490 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
492 if ((priv->
cfg.config == 1) || (priv->
cfg.config == 2))
493 tuner_i2c_xfer_send(&priv->
i2c_props, set_GP00_CF, 2);
495 tuner_i2c_xfer_send(&priv->
i2c_props, set_GP01_CF, 2);
496 tuner_i2c_xfer_send(&priv->
i2c_props, set_VS, 2);
503 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
504 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
505 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
506 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
507 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
508 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
509 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
511 tda8295_power(fe, 1);
513 tda8295_set_easy_mode(fe, 0);
514 tda8295_set_video_std(fe);
516 tuner_i2c_xfer_send(&priv->
i2c_props, set_adc_ctl, 2);
517 tuner_i2c_xfer_send(&priv->
i2c_props, set_adc_ctl2, 2);
518 tuner_i2c_xfer_send(&priv->
i2c_props, set_pll_reg6, 2);
519 tuner_i2c_xfer_send(&priv->
i2c_props, set_pll_reg0, 2);
520 tuner_i2c_xfer_send(&priv->
i2c_props, set_pll_reg7, 2);
521 tuner_i2c_xfer_send(&priv->
i2c_props, set_pll_reg10, 2);
522 tuner_i2c_xfer_send(&priv->
i2c_props, set_gpio_reg0, 2);
524 tda8295_agc1_out(fe, 0);
525 tda8295_agc2_out(fe, 0);
531 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
532 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
533 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
534 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
536 .buf=tda8275_init, .len = 14};
538 msg.
buf = tda8275a_init;
540 tda8290_i2c_bridge(fe, 1);
542 tda8290_i2c_bridge(fe, 0);
554 if (fe->
ops.tuner_ops.release)
555 fe->
ops.tuner_ops.release(fe);
569 int i,
ret, tuners_found;
585 for (i = 0x60; i <= 0x63; i++) {
590 tuner_addrs = (tuner_addrs << 8) + i;
600 if (tuners_found > 1)
601 for (i = 0; i < tuners_found; i++) {
602 msg.
addr = tuner_addrs & 0xff;
605 tuner_addrs = tuner_addrs >> 8;
610 if (tuner_addrs == 0) {
612 tuner_info(
"could not clearly identify tuner address, "
613 "defaulting to %x\n", tuner_addrs);
615 tuner_addrs = tuner_addrs & 0xff;
616 tuner_info(
"setting tuner address to %x\n", tuner_addrs);
619 msg.
addr = tuner_addrs;
630 if ((data == 0x83) || (data == 0x84)) {
632 tda829x_tda18271_config.
config = priv->
cfg.config;
634 priv->
i2c_props.adap, &tda829x_tda18271_config);
636 if ((data & 0x3c) == 0)
645 if (fe->
ops.tuner_ops.init)
646 fe->
ops.tuner_ops.init(fe);
648 if (fe->
ops.tuner_ops.sleep)
649 fe->
ops.tuner_ops.sleep(fe);
658 #define TDA8290_ID 0x89
661 { .
addr = i2c_props->
addr, .flags = 0, .len = 1, .buf = ® },
662 { .addr = i2c_props->
addr, .flags =
I2C_M_RD, .len = 1, .buf = &
id },
672 if (
id == TDA8290_ID) {
675 __func__, i2c_adapter_id(i2c_props->
adap),
684 #define TDA8295_ID 0x8a
685 #define TDA8295C2_ID 0x8b
688 { .
addr = i2c_props->
addr, .flags = 0, .len = 1, .buf = ® },
689 { .addr = i2c_props->
addr, .flags =
I2C_M_RD, .len = 1, .buf = &
id },
699 if ((
id & 0xfe) == TDA8295_ID) {
702 __func__, (
id == TDA8295_ID) ?
703 "tda8295c1" :
"tda8295c2",
704 i2c_adapter_id(i2c_props->
adap),
713 .set_params = tda8290_set_params,
714 .has_signal = tda8290_has_signal,
715 .standby = tda8290_standby,
716 .release = tda829x_release,
717 .i2c_gate_ctrl = tda8290_i2c_bridge,
721 .set_params = tda8295_set_params,
722 .has_signal = tda8295_has_signal,
723 .standby = tda8295_standby,
724 .release = tda829x_release,
725 .i2c_gate_ctrl = tda8295_i2c_bridge,
746 if (tda8290_probe(&priv->
i2c_props) == 0) {
748 memcpy(&fe->
ops.analog_ops, &tda8290_ops,
752 if (tda8295_probe(&priv->
i2c_props) == 0) {
754 memcpy(&fe->
ops.analog_ops, &tda8295_ops,
759 tda8295_power(fe, 1);
760 if (tda829x_find_tuner(fe) < 0)
778 name =
"tda8290+75a";
781 name =
"tda8295+75a";
784 name =
"tda8290+18271";
787 name =
"tda8295+18271";
794 fe->
ops.analog_ops.info.name =
name;
798 tda8290_init_tuner(fe);
820 unsigned char soft_reset[] = { 0x00, 0x00 };
821 unsigned char easy_mode_b[] = { 0x01, 0x02 };
822 unsigned char easy_mode_g[] = { 0x01, 0x04 };
823 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
824 unsigned char addr_dto_lsb = 0x07;
826 #define PROBE_BUFFER_SIZE 8
831 tuner_i2c_xfer_send_recv(&i2c_props,
834 if (buf[i] != buf[0])
839 if (i == PROBE_BUFFER_SIZE)
842 if ((tda8290_probe(&i2c_props) == 0) ||
843 (tda8295_probe(&i2c_props) == 0))
847 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
848 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
849 tuner_i2c_xfer_send_recv(&i2c_props, &addr_dto_lsb, 1, &data, 1);
851 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
852 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
853 tuner_i2c_xfer_send_recv(&i2c_props,
854 &addr_dto_lsb, 1, &data, 1);
859 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
865 MODULE_AUTHOR(
"Gerd Knorr, Hartmut Hackmann, Michael Krufky");