1 // SPDX-License-Identifier: GPL-2.0-or-later
4 i2c tv tuner chip device driver
5 controls the philips tda8290+75 tuner chip combo.
8 This "tda8290" module was split apart from the original "tuner" module.
11 #include <linux/i2c.h>
12 #include <linux/slab.h>
13 #include <linux/delay.h>
14 #include <linux/videodev2.h>
15 #include "tuner-i2c.h"
21 module_param(debug, int, 0644);
22 MODULE_PARM_DESC(debug, "enable verbose debug messages");
24 static int deemphasis_50;
25 module_param(deemphasis_50, int, 0644);
26 MODULE_PARM_DESC(deemphasis_50, "0 - 75us deemphasis; 1 - 50us deemphasis");
28 /* ---------------------------------------------------------------------- */
31 struct tuner_i2c_props i2c_props;
33 unsigned char tda8290_easy_mode;
35 unsigned char tda827x_addr;
44 struct tda827x_config cfg;
45 struct tda18271_std_map *tda18271_std_map;
48 /*---------------------------------------------------------------------*/
50 static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
52 struct tda8290_priv *priv = fe->analog_demod_priv;
54 static unsigned char enable[2] = { 0x21, 0xC0 };
55 static unsigned char disable[2] = { 0x21, 0x00 };
60 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
61 /* let the bridge stabilize */
65 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
71 static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
73 struct tda8290_priv *priv = fe->analog_demod_priv;
75 static unsigned char enable[2] = { 0x45, 0xc1 };
76 static unsigned char disable[2] = { 0x46, 0x00 };
77 static unsigned char buf[3] = { 0x45, 0x01, 0x00 };
82 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
83 /* let the bridge stabilize */
87 tuner_i2c_xfer_send_recv(&priv->i2c_props, msg, 1, &msg[1], 1);
91 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
95 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
101 /*---------------------------------------------------------------------*/
103 static void set_audio(struct dvb_frontend *fe,
104 struct analog_parameters *params)
106 struct tda8290_priv *priv = fe->analog_demod_priv;
109 if (params->std & V4L2_STD_MN) {
110 priv->tda8290_easy_mode = 0x01;
112 } else if (params->std & V4L2_STD_B) {
113 priv->tda8290_easy_mode = 0x02;
115 } else if (params->std & V4L2_STD_GH) {
116 priv->tda8290_easy_mode = 0x04;
118 } else if (params->std & V4L2_STD_PAL_I) {
119 priv->tda8290_easy_mode = 0x08;
121 } else if (params->std & V4L2_STD_DK) {
122 priv->tda8290_easy_mode = 0x10;
124 } else if (params->std & V4L2_STD_SECAM_L) {
125 priv->tda8290_easy_mode = 0x20;
127 } else if (params->std & V4L2_STD_SECAM_LC) {
128 priv->tda8290_easy_mode = 0x40;
131 priv->tda8290_easy_mode = 0x10;
135 if (params->mode == V4L2_TUNER_RADIO) {
136 /* Set TDA8295 to FM radio; Start TDA8290 with MN values */
137 priv->tda8290_easy_mode = (priv->ver & TDA8295) ? 0x80 : 0x01;
138 tuner_dbg("setting to radio FM\n");
140 tuner_dbg("setting tda829x to system %s\n", mode);
145 unsigned char seq[2];
147 { { 0x01, 0x81} }, /* Put device into expert mode */
148 { { 0x03, 0x48} }, /* Disable NOTCH and VIDEO filters */
149 { { 0x04, 0x04} }, /* Disable color carrier filter (SSIF) */
150 { { 0x05, 0x04} }, /* ADC headroom */
151 { { 0x06, 0x10} }, /* group delay flat */
153 { { 0x07, 0x00} }, /* use the same radio DTO values as a tda8295 */
160 { { 0x0d, 0x00} }, /* PLL off, no video carrier detect */
161 { { 0x14, 0x00} }, /* disable auto mute if no video */
164 static void tda8290_set_params(struct dvb_frontend *fe,
165 struct analog_parameters *params)
167 struct tda8290_priv *priv = fe->analog_demod_priv;
169 static unsigned char soft_reset[] = { 0x00, 0x00 };
170 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
171 static unsigned char expert_mode[] = { 0x01, 0x80 };
172 static unsigned char agc_out_on[] = { 0x02, 0x00 };
173 static unsigned char gainset_off[] = { 0x28, 0x14 };
174 static unsigned char if_agc_spd[] = { 0x0f, 0x88 };
175 static unsigned char adc_head_6[] = { 0x05, 0x04 };
176 static unsigned char adc_head_9[] = { 0x05, 0x02 };
177 static unsigned char adc_head_12[] = { 0x05, 0x01 };
178 static unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
179 static unsigned char pll_bw_low[] = { 0x0d, 0x27 };
180 static unsigned char gainset_2[] = { 0x28, 0x64 };
181 static unsigned char agc_rst_on[] = { 0x0e, 0x0b };
182 static unsigned char agc_rst_off[] = { 0x0e, 0x09 };
183 static unsigned char if_agc_set[] = { 0x0f, 0x81 };
184 static unsigned char addr_adc_sat = 0x1a;
185 static unsigned char addr_agc_stat = 0x1d;
186 static unsigned char addr_pll_stat = 0x1b;
187 static unsigned char adc_sat = 0, agc_stat = 0,
191 set_audio(fe, params);
193 if (priv->cfg.config)
194 tuner_dbg("tda827xa config is 0x%02x\n", priv->cfg.config);
195 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
196 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
197 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
200 if (params->mode == V4L2_TUNER_RADIO) {
201 unsigned char deemphasis[] = { 0x13, 1 };
203 /* FIXME: allow using a different deemphasis */
208 for (i = 0; i < ARRAY_SIZE(fm_mode); i++)
209 tuner_i2c_xfer_send(&priv->i2c_props, fm_mode[i].seq, 2);
211 tuner_i2c_xfer_send(&priv->i2c_props, deemphasis, 2);
213 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
214 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
215 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
216 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
217 if (priv->tda8290_easy_mode & 0x60)
218 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
220 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
221 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
225 if (fe->ops.analog_ops.i2c_gate_ctrl)
226 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
228 if (fe->ops.tuner_ops.set_analog_params)
229 fe->ops.tuner_ops.set_analog_params(fe, params);
231 for (i = 0; i < 3; i++) {
232 tuner_i2c_xfer_send_recv(&priv->i2c_props,
233 &addr_pll_stat, 1, &pll_stat, 1);
234 if (pll_stat & 0x80) {
235 tuner_i2c_xfer_send_recv(&priv->i2c_props,
238 tuner_i2c_xfer_send_recv(&priv->i2c_props,
241 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
244 tuner_dbg("tda8290 not locked, no signal?\n");
248 /* adjust headroom resp. gain */
249 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
250 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
251 agc_stat, adc_sat, pll_stat & 0x80);
252 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
254 tuner_i2c_xfer_send_recv(&priv->i2c_props,
255 &addr_agc_stat, 1, &agc_stat, 1);
256 tuner_i2c_xfer_send_recv(&priv->i2c_props,
257 &addr_pll_stat, 1, &pll_stat, 1);
258 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
259 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
260 agc_stat, pll_stat & 0x80);
264 tuner_i2c_xfer_send_recv(&priv->i2c_props,
267 tuner_i2c_xfer_send_recv(&priv->i2c_props,
270 if((agc_stat > 115) || !(pll_stat & 0x80)) {
271 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
272 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
273 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
279 /* l/ l' deadlock? */
280 if(priv->tda8290_easy_mode & 0x60) {
281 tuner_i2c_xfer_send_recv(&priv->i2c_props,
284 tuner_i2c_xfer_send_recv(&priv->i2c_props,
287 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
288 tuner_dbg("trying to resolve SECAM L deadlock\n");
289 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
291 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
295 if (fe->ops.analog_ops.i2c_gate_ctrl)
296 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
297 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
300 /*---------------------------------------------------------------------*/
302 static void tda8295_power(struct dvb_frontend *fe, int enable)
304 struct tda8290_priv *priv = fe->analog_demod_priv;
305 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
307 tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);
314 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
317 static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
319 struct tda8290_priv *priv = fe->analog_demod_priv;
320 unsigned char buf[] = { 0x01, 0x00 };
322 tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);
325 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
327 buf[1] = 0x00; /* reset active bit */
329 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
332 static void tda8295_set_video_std(struct dvb_frontend *fe)
334 struct tda8290_priv *priv = fe->analog_demod_priv;
335 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
337 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
339 tda8295_set_easy_mode(fe, 1);
341 tda8295_set_easy_mode(fe, 0);
344 /*---------------------------------------------------------------------*/
346 static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
348 struct tda8290_priv *priv = fe->analog_demod_priv;
349 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
351 tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);
358 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
361 static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
363 struct tda8290_priv *priv = fe->analog_demod_priv;
364 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
365 unsigned char set_gpio_val[] = { 0x46, 0x00 };
367 tuner_i2c_xfer_send_recv(&priv->i2c_props,
368 &set_gpio_cf[0], 1, &set_gpio_cf[1], 1);
369 tuner_i2c_xfer_send_recv(&priv->i2c_props,
370 &set_gpio_val[0], 1, &set_gpio_val[1], 1);
372 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
375 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
376 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
378 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
379 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
382 static int tda8295_has_signal(struct dvb_frontend *fe, u16 *signal)
384 struct tda8290_priv *priv = fe->analog_demod_priv;
386 unsigned char hvpll_stat = 0x26;
389 tuner_i2c_xfer_send_recv(&priv->i2c_props, &hvpll_stat, 1, &ret, 1);
390 *signal = (ret & 0x01) ? 65535 : 0;
394 /*---------------------------------------------------------------------*/
396 static void tda8295_set_params(struct dvb_frontend *fe,
397 struct analog_parameters *params)
399 struct tda8290_priv *priv = fe->analog_demod_priv;
401 unsigned char blanking_mode[] = { 0x1d, 0x00 };
403 set_audio(fe, params);
405 tuner_dbg("%s: freq = %d\n", __func__, params->frequency);
407 tda8295_power(fe, 1);
408 tda8295_agc1_out(fe, 1);
410 tuner_i2c_xfer_send_recv(&priv->i2c_props,
411 &blanking_mode[0], 1, &blanking_mode[1], 1);
413 tda8295_set_video_std(fe);
415 blanking_mode[1] = 0x03;
416 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
419 if (fe->ops.analog_ops.i2c_gate_ctrl)
420 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
422 if (fe->ops.tuner_ops.set_analog_params)
423 fe->ops.tuner_ops.set_analog_params(fe, params);
428 tda8295_has_signal(fe, &signal);
430 tuner_dbg("tda8295 is locked\n");
432 tuner_dbg("tda8295 not locked, no signal?\n");
434 if (fe->ops.analog_ops.i2c_gate_ctrl)
435 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
438 /*---------------------------------------------------------------------*/
440 static int tda8290_has_signal(struct dvb_frontend *fe, u16 *signal)
442 struct tda8290_priv *priv = fe->analog_demod_priv;
444 unsigned char i2c_get_afc[1] = { 0x1B };
445 unsigned char afc = 0;
447 tuner_i2c_xfer_send_recv(&priv->i2c_props,
448 i2c_get_afc, ARRAY_SIZE(i2c_get_afc), &afc, 1);
449 *signal = (afc & 0x80) ? 65535 : 0;
453 /*---------------------------------------------------------------------*/
455 static void tda8290_standby(struct dvb_frontend *fe)
457 struct tda8290_priv *priv = fe->analog_demod_priv;
459 static unsigned char cb1[] = { 0x30, 0xD0 };
460 static unsigned char tda8290_standby[] = { 0x00, 0x02 };
461 static unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
462 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
464 if (fe->ops.analog_ops.i2c_gate_ctrl)
465 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
466 if (priv->ver & TDA8275A)
468 i2c_transfer(priv->i2c_props.adap, &msg, 1);
469 if (fe->ops.analog_ops.i2c_gate_ctrl)
470 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
471 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
472 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
475 static void tda8295_standby(struct dvb_frontend *fe)
477 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
479 tda8295_power(fe, 0);
482 static void tda8290_init_if(struct dvb_frontend *fe)
484 struct tda8290_priv *priv = fe->analog_demod_priv;
486 static unsigned char set_VS[] = { 0x30, 0x6F };
487 static unsigned char set_GP00_CF[] = { 0x20, 0x01 };
488 static unsigned char set_GP01_CF[] = { 0x20, 0x0B };
490 if ((priv->cfg.config == TDA8290_LNA_GP0_HIGH_ON) ||
491 (priv->cfg.config == TDA8290_LNA_GP0_HIGH_OFF))
492 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
494 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
495 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
498 static void tda8295_init_if(struct dvb_frontend *fe)
500 struct tda8290_priv *priv = fe->analog_demod_priv;
502 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
503 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
504 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
505 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
506 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
507 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
508 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
510 tda8295_power(fe, 1);
512 tda8295_set_easy_mode(fe, 0);
513 tda8295_set_video_std(fe);
515 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
516 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
517 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
518 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
519 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
520 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
521 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
523 tda8295_agc1_out(fe, 0);
524 tda8295_agc2_out(fe, 0);
527 static void tda8290_init_tuner(struct dvb_frontend *fe)
529 struct tda8290_priv *priv = fe->analog_demod_priv;
530 static unsigned char tda8275_init[] =
531 { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
532 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
533 static unsigned char tda8275a_init[] =
534 { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
535 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
536 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
537 .buf=tda8275_init, .len = 14};
538 if (priv->ver & TDA8275A)
539 msg.buf = tda8275a_init;
541 if (fe->ops.analog_ops.i2c_gate_ctrl)
542 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
543 i2c_transfer(priv->i2c_props.adap, &msg, 1);
544 if (fe->ops.analog_ops.i2c_gate_ctrl)
545 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
548 /*---------------------------------------------------------------------*/
550 static void tda829x_release(struct dvb_frontend *fe)
552 struct tda8290_priv *priv = fe->analog_demod_priv;
554 /* only try to release the tuner if we've
555 * attached it from within this module */
556 if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))
557 if (fe->ops.tuner_ops.release)
558 fe->ops.tuner_ops.release(fe);
560 kfree(fe->analog_demod_priv);
561 fe->analog_demod_priv = NULL;
564 static struct tda18271_config tda829x_tda18271_config = {
565 .gate = TDA18271_GATE_ANALOG,
568 static int tda829x_find_tuner(struct dvb_frontend *fe)
570 struct tda8290_priv *priv = fe->analog_demod_priv;
571 int i, ret, tuners_found;
574 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
576 if (fe->ops.analog_ops.i2c_gate_ctrl)
577 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
579 /* probe for tuner chip */
582 for (i = 0x60; i <= 0x63; i++) {
584 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
587 tuner_addrs = (tuner_addrs << 8) + i;
590 /* if there is more than one tuner, we expect the right one is
591 behind the bridge and we choose the highest address that doesn't
595 if (fe->ops.analog_ops.i2c_gate_ctrl)
596 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
598 if (tuners_found > 1)
599 for (i = 0; i < tuners_found; i++) {
600 msg.addr = tuner_addrs & 0xff;
601 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
603 tuner_addrs = tuner_addrs >> 8;
608 if (tuner_addrs == 0) {
610 tuner_info("could not clearly identify tuner address, defaulting to %x\n",
613 tuner_addrs = tuner_addrs & 0xff;
614 tuner_info("setting tuner address to %x\n", tuner_addrs);
616 priv->tda827x_addr = tuner_addrs;
617 msg.addr = tuner_addrs;
619 if (fe->ops.analog_ops.i2c_gate_ctrl)
620 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
621 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
624 tuner_warn("tuner access failed!\n");
625 if (fe->ops.analog_ops.i2c_gate_ctrl)
626 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
630 if ((data == 0x83) || (data == 0x84)) {
631 priv->ver |= TDA18271;
632 tda829x_tda18271_config.config = priv->cfg.config;
633 tda829x_tda18271_config.std_map = priv->tda18271_std_map;
634 dvb_attach(tda18271_attach, fe, priv->tda827x_addr,
635 priv->i2c_props.adap, &tda829x_tda18271_config);
637 if ((data & 0x3c) == 0)
638 priv->ver |= TDA8275;
640 priv->ver |= TDA8275A;
642 dvb_attach(tda827x_attach, fe, priv->tda827x_addr,
643 priv->i2c_props.adap, &priv->cfg);
644 priv->cfg.switch_addr = priv->i2c_props.addr;
646 if (fe->ops.tuner_ops.init)
647 fe->ops.tuner_ops.init(fe);
649 if (fe->ops.tuner_ops.sleep)
650 fe->ops.tuner_ops.sleep(fe);
652 if (fe->ops.analog_ops.i2c_gate_ctrl)
653 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
658 static int tda8290_probe(struct tuner_i2c_props *i2c_props)
660 #define TDA8290_ID 0x89
662 struct i2c_msg msg_read[] = {
663 { .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = ® },
664 { .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id },
668 if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) {
669 printk(KERN_WARNING "%s: couldn't read register 0x%02x\n",
674 if (id == TDA8290_ID) {
676 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
677 __func__, i2c_adapter_id(i2c_props->adap),
684 static int tda8295_probe(struct tuner_i2c_props *i2c_props)
686 #define TDA8295_ID 0x8a
687 #define TDA8295C2_ID 0x8b
689 struct i2c_msg msg_read[] = {
690 { .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = ® },
691 { .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id },
695 if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) {
696 printk(KERN_WARNING "%s: couldn't read register 0x%02x\n",
701 if ((id & 0xfe) == TDA8295_ID) {
703 printk(KERN_DEBUG "%s: %s detected @ %d-%04x\n",
704 __func__, (id == TDA8295_ID) ?
705 "tda8295c1" : "tda8295c2",
706 i2c_adapter_id(i2c_props->adap),
714 static const struct analog_demod_ops tda8290_ops = {
715 .set_params = tda8290_set_params,
716 .has_signal = tda8290_has_signal,
717 .standby = tda8290_standby,
718 .release = tda829x_release,
719 .i2c_gate_ctrl = tda8290_i2c_bridge,
722 static const struct analog_demod_ops tda8295_ops = {
723 .set_params = tda8295_set_params,
724 .has_signal = tda8295_has_signal,
725 .standby = tda8295_standby,
726 .release = tda829x_release,
727 .i2c_gate_ctrl = tda8295_i2c_bridge,
730 struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
731 struct i2c_adapter *i2c_adap, u8 i2c_addr,
732 struct tda829x_config *cfg)
734 struct tda8290_priv *priv = NULL;
737 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
740 fe->analog_demod_priv = priv;
742 priv->i2c_props.addr = i2c_addr;
743 priv->i2c_props.adap = i2c_adap;
744 priv->i2c_props.name = "tda829x";
746 priv->cfg.config = cfg->lna_cfg;
747 priv->tda18271_std_map = cfg->tda18271_std_map;
750 if (tda8290_probe(&priv->i2c_props) == 0) {
752 memcpy(&fe->ops.analog_ops, &tda8290_ops,
753 sizeof(struct analog_demod_ops));
756 if (tda8295_probe(&priv->i2c_props) == 0) {
758 memcpy(&fe->ops.analog_ops, &tda8295_ops,
759 sizeof(struct analog_demod_ops));
762 if (cfg && cfg->no_i2c_gate)
763 fe->ops.analog_ops.i2c_gate_ctrl = NULL;
765 if (!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) {
766 tda8295_power(fe, 1);
767 if (tda829x_find_tuner(fe) < 0)
778 case TDA8290 | TDA8275:
781 case TDA8295 | TDA8275:
784 case TDA8290 | TDA8275A:
785 name = "tda8290+75a";
787 case TDA8295 | TDA8275A:
788 name = "tda8295+75a";
790 case TDA8290 | TDA18271:
791 name = "tda8290+18271";
793 case TDA8295 | TDA18271:
794 name = "tda8295+18271";
799 tuner_info("type set to %s\n", name);
801 fe->ops.analog_ops.info.name = name;
803 if (priv->ver & TDA8290) {
804 if (priv->ver & (TDA8275 | TDA8275A))
805 tda8290_init_tuner(fe);
807 } else if (priv->ver & TDA8295)
813 memset(&fe->ops.analog_ops, 0, sizeof(struct analog_demod_ops));
818 EXPORT_SYMBOL_GPL(tda829x_attach);
820 int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
822 struct tuner_i2c_props i2c_props = {
827 static unsigned char soft_reset[] = { 0x00, 0x00 };
828 static unsigned char easy_mode_b[] = { 0x01, 0x02 };
829 static unsigned char easy_mode_g[] = { 0x01, 0x04 };
830 static unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
831 static unsigned char addr_dto_lsb = 0x07;
833 #define PROBE_BUFFER_SIZE 8
834 unsigned char buf[PROBE_BUFFER_SIZE];
837 /* rule out tda9887, which would return the same byte repeatedly */
838 tuner_i2c_xfer_send_recv(&i2c_props,
839 soft_reset, 1, buf, PROBE_BUFFER_SIZE);
840 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
841 if (buf[i] != buf[0])
845 /* all bytes are equal, not a tda829x - probably a tda9887 */
846 if (i == PROBE_BUFFER_SIZE)
849 if ((tda8290_probe(&i2c_props) == 0) ||
850 (tda8295_probe(&i2c_props) == 0))
853 /* fall back to old probing method */
854 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
855 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
856 tuner_i2c_xfer_send_recv(&i2c_props, &addr_dto_lsb, 1, &data, 1);
858 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
859 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
860 tuner_i2c_xfer_send_recv(&i2c_props,
861 &addr_dto_lsb, 1, &data, 1);
866 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
869 EXPORT_SYMBOL_GPL(tda829x_probe);
871 MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
872 MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
873 MODULE_LICENSE("GPL");