3 i2c tv tuner chip device driver
4 controls the philips tda8290+75 tuner chip combo.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 This "tda8290" module was split apart from the original "tuner" module.
23 #include <linux/i2c.h>
24 #include <linux/slab.h>
25 #include <linux/delay.h>
26 #include <linux/videodev2.h>
27 #include "tuner-i2c.h"
33 module_param(debug, int, 0644);
34 MODULE_PARM_DESC(debug, "enable verbose debug messages");
36 static int deemphasis_50;
37 module_param(deemphasis_50, int, 0644);
38 MODULE_PARM_DESC(deemphasis_50, "0 - 75us deemphasis; 1 - 50us deemphasis");
40 /* ---------------------------------------------------------------------- */
43 struct tuner_i2c_props i2c_props;
45 unsigned char tda8290_easy_mode;
47 unsigned char tda827x_addr;
56 struct tda827x_config cfg;
57 struct tda18271_std_map *tda18271_std_map;
60 /*---------------------------------------------------------------------*/
62 static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
64 struct tda8290_priv *priv = fe->analog_demod_priv;
66 unsigned char enable[2] = { 0x21, 0xC0 };
67 unsigned char disable[2] = { 0x21, 0x00 };
72 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
73 /* let the bridge stabilize */
77 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
83 static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
85 struct tda8290_priv *priv = fe->analog_demod_priv;
87 unsigned char enable[2] = { 0x45, 0xc1 };
88 unsigned char disable[2] = { 0x46, 0x00 };
89 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
94 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
95 /* let the bridge stabilize */
99 tuner_i2c_xfer_send_recv(&priv->i2c_props, msg, 1, &msg[1], 1);
103 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
107 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
113 /*---------------------------------------------------------------------*/
115 static void set_audio(struct dvb_frontend *fe,
116 struct analog_parameters *params)
118 struct tda8290_priv *priv = fe->analog_demod_priv;
121 if (params->std & V4L2_STD_MN) {
122 priv->tda8290_easy_mode = 0x01;
124 } else if (params->std & V4L2_STD_B) {
125 priv->tda8290_easy_mode = 0x02;
127 } else if (params->std & V4L2_STD_GH) {
128 priv->tda8290_easy_mode = 0x04;
130 } else if (params->std & V4L2_STD_PAL_I) {
131 priv->tda8290_easy_mode = 0x08;
133 } else if (params->std & V4L2_STD_DK) {
134 priv->tda8290_easy_mode = 0x10;
136 } else if (params->std & V4L2_STD_SECAM_L) {
137 priv->tda8290_easy_mode = 0x20;
139 } else if (params->std & V4L2_STD_SECAM_LC) {
140 priv->tda8290_easy_mode = 0x40;
143 priv->tda8290_easy_mode = 0x10;
147 if (params->mode == V4L2_TUNER_RADIO) {
148 /* Set TDA8295 to FM radio; Start TDA8290 with MN values */
149 priv->tda8290_easy_mode = (priv->ver & TDA8295) ? 0x80 : 0x01;
150 tuner_dbg("setting to radio FM\n");
152 tuner_dbg("setting tda829x to system %s\n", mode);
157 unsigned char seq[2];
159 { { 0x01, 0x81} }, /* Put device into expert mode */
160 { { 0x03, 0x48} }, /* Disable NOTCH and VIDEO filters */
161 { { 0x04, 0x04} }, /* Disable color carrier filter (SSIF) */
162 { { 0x05, 0x04} }, /* ADC headroom */
163 { { 0x06, 0x10} }, /* group delay flat */
165 { { 0x07, 0x00} }, /* use the same radio DTO values as a tda8295 */
172 { { 0x0d, 0x00} }, /* PLL off, no video carrier detect */
173 { { 0x14, 0x00} }, /* disable auto mute if no video */
176 static void tda8290_set_params(struct dvb_frontend *fe,
177 struct analog_parameters *params)
179 struct tda8290_priv *priv = fe->analog_demod_priv;
181 unsigned char soft_reset[] = { 0x00, 0x00 };
182 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
183 unsigned char expert_mode[] = { 0x01, 0x80 };
184 unsigned char agc_out_on[] = { 0x02, 0x00 };
185 unsigned char gainset_off[] = { 0x28, 0x14 };
186 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
187 unsigned char adc_head_6[] = { 0x05, 0x04 };
188 unsigned char adc_head_9[] = { 0x05, 0x02 };
189 unsigned char adc_head_12[] = { 0x05, 0x01 };
190 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
191 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
192 unsigned char gainset_2[] = { 0x28, 0x64 };
193 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
194 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
195 unsigned char if_agc_set[] = { 0x0f, 0x81 };
196 unsigned char addr_adc_sat = 0x1a;
197 unsigned char addr_agc_stat = 0x1d;
198 unsigned char addr_pll_stat = 0x1b;
199 unsigned char adc_sat, agc_stat,
203 set_audio(fe, params);
205 if (priv->cfg.config)
206 tuner_dbg("tda827xa config is 0x%02x\n", priv->cfg.config);
207 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
208 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
209 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
212 if (params->mode == V4L2_TUNER_RADIO) {
213 unsigned char deemphasis[] = { 0x13, 1 };
215 /* FIXME: allow using a different deemphasis */
220 for (i = 0; i < ARRAY_SIZE(fm_mode); i++)
221 tuner_i2c_xfer_send(&priv->i2c_props, fm_mode[i].seq, 2);
223 tuner_i2c_xfer_send(&priv->i2c_props, deemphasis, 2);
225 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
226 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
227 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
228 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
229 if (priv->tda8290_easy_mode & 0x60)
230 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
232 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
233 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
237 if (fe->ops.analog_ops.i2c_gate_ctrl)
238 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
240 if (fe->ops.tuner_ops.set_analog_params)
241 fe->ops.tuner_ops.set_analog_params(fe, params);
243 for (i = 0; i < 3; i++) {
244 tuner_i2c_xfer_send_recv(&priv->i2c_props,
245 &addr_pll_stat, 1, &pll_stat, 1);
246 if (pll_stat & 0x80) {
247 tuner_i2c_xfer_send_recv(&priv->i2c_props,
250 tuner_i2c_xfer_send_recv(&priv->i2c_props,
253 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
256 tuner_dbg("tda8290 not locked, no signal?\n");
260 /* adjust headroom resp. gain */
261 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
262 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
263 agc_stat, adc_sat, pll_stat & 0x80);
264 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
266 tuner_i2c_xfer_send_recv(&priv->i2c_props,
267 &addr_agc_stat, 1, &agc_stat, 1);
268 tuner_i2c_xfer_send_recv(&priv->i2c_props,
269 &addr_pll_stat, 1, &pll_stat, 1);
270 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
271 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
272 agc_stat, pll_stat & 0x80);
276 tuner_i2c_xfer_send_recv(&priv->i2c_props,
279 tuner_i2c_xfer_send_recv(&priv->i2c_props,
282 if((agc_stat > 115) || !(pll_stat & 0x80)) {
283 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
284 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
285 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
291 /* l/ l' deadlock? */
292 if(priv->tda8290_easy_mode & 0x60) {
293 tuner_i2c_xfer_send_recv(&priv->i2c_props,
296 tuner_i2c_xfer_send_recv(&priv->i2c_props,
299 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
300 tuner_dbg("trying to resolve SECAM L deadlock\n");
301 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
303 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
307 if (fe->ops.analog_ops.i2c_gate_ctrl)
308 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
309 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
312 /*---------------------------------------------------------------------*/
314 static void tda8295_power(struct dvb_frontend *fe, int enable)
316 struct tda8290_priv *priv = fe->analog_demod_priv;
317 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
319 tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);
326 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
329 static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
331 struct tda8290_priv *priv = fe->analog_demod_priv;
332 unsigned char buf[] = { 0x01, 0x00 };
334 tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);
337 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
339 buf[1] = 0x00; /* reset active bit */
341 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
344 static void tda8295_set_video_std(struct dvb_frontend *fe)
346 struct tda8290_priv *priv = fe->analog_demod_priv;
347 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
349 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
351 tda8295_set_easy_mode(fe, 1);
353 tda8295_set_easy_mode(fe, 0);
356 /*---------------------------------------------------------------------*/
358 static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
360 struct tda8290_priv *priv = fe->analog_demod_priv;
361 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
363 tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);
370 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
373 static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
375 struct tda8290_priv *priv = fe->analog_demod_priv;
376 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
377 unsigned char set_gpio_val[] = { 0x46, 0x00 };
379 tuner_i2c_xfer_send_recv(&priv->i2c_props,
380 &set_gpio_cf[0], 1, &set_gpio_cf[1], 1);
381 tuner_i2c_xfer_send_recv(&priv->i2c_props,
382 &set_gpio_val[0], 1, &set_gpio_val[1], 1);
384 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
387 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
388 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
390 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
391 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
394 static int tda8295_has_signal(struct dvb_frontend *fe)
396 struct tda8290_priv *priv = fe->analog_demod_priv;
398 unsigned char hvpll_stat = 0x26;
401 tuner_i2c_xfer_send_recv(&priv->i2c_props, &hvpll_stat, 1, &ret, 1);
402 return (ret & 0x01) ? 65535 : 0;
405 /*---------------------------------------------------------------------*/
407 static void tda8295_set_params(struct dvb_frontend *fe,
408 struct analog_parameters *params)
410 struct tda8290_priv *priv = fe->analog_demod_priv;
412 unsigned char blanking_mode[] = { 0x1d, 0x00 };
414 set_audio(fe, params);
416 tuner_dbg("%s: freq = %d\n", __func__, params->frequency);
418 tda8295_power(fe, 1);
419 tda8295_agc1_out(fe, 1);
421 tuner_i2c_xfer_send_recv(&priv->i2c_props,
422 &blanking_mode[0], 1, &blanking_mode[1], 1);
424 tda8295_set_video_std(fe);
426 blanking_mode[1] = 0x03;
427 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
430 if (fe->ops.analog_ops.i2c_gate_ctrl)
431 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
433 if (fe->ops.tuner_ops.set_analog_params)
434 fe->ops.tuner_ops.set_analog_params(fe, params);
439 if (tda8295_has_signal(fe))
440 tuner_dbg("tda8295 is locked\n");
442 tuner_dbg("tda8295 not locked, no signal?\n");
444 if (fe->ops.analog_ops.i2c_gate_ctrl)
445 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
448 /*---------------------------------------------------------------------*/
450 static int tda8290_has_signal(struct dvb_frontend *fe)
452 struct tda8290_priv *priv = fe->analog_demod_priv;
454 unsigned char i2c_get_afc[1] = { 0x1B };
455 unsigned char afc = 0;
457 tuner_i2c_xfer_send_recv(&priv->i2c_props,
458 i2c_get_afc, ARRAY_SIZE(i2c_get_afc), &afc, 1);
459 return (afc & 0x80)? 65535:0;
462 /*---------------------------------------------------------------------*/
464 static void tda8290_standby(struct dvb_frontend *fe)
466 struct tda8290_priv *priv = fe->analog_demod_priv;
468 unsigned char cb1[] = { 0x30, 0xD0 };
469 unsigned char tda8290_standby[] = { 0x00, 0x02 };
470 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
471 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
473 if (fe->ops.analog_ops.i2c_gate_ctrl)
474 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
475 if (priv->ver & TDA8275A)
477 i2c_transfer(priv->i2c_props.adap, &msg, 1);
478 if (fe->ops.analog_ops.i2c_gate_ctrl)
479 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
480 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
481 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
484 static void tda8295_standby(struct dvb_frontend *fe)
486 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
488 tda8295_power(fe, 0);
491 static void tda8290_init_if(struct dvb_frontend *fe)
493 struct tda8290_priv *priv = fe->analog_demod_priv;
495 unsigned char set_VS[] = { 0x30, 0x6F };
496 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
497 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
499 if ((priv->cfg.config == TDA8290_LNA_GP0_HIGH_ON) ||
500 (priv->cfg.config == TDA8290_LNA_GP0_HIGH_OFF))
501 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
503 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
504 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
507 static void tda8295_init_if(struct dvb_frontend *fe)
509 struct tda8290_priv *priv = fe->analog_demod_priv;
511 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
512 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
513 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
514 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
515 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
516 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
517 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
519 tda8295_power(fe, 1);
521 tda8295_set_easy_mode(fe, 0);
522 tda8295_set_video_std(fe);
524 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
525 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
526 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
527 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
528 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
529 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
530 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
532 tda8295_agc1_out(fe, 0);
533 tda8295_agc2_out(fe, 0);
536 static void tda8290_init_tuner(struct dvb_frontend *fe)
538 struct tda8290_priv *priv = fe->analog_demod_priv;
539 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
540 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
541 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
542 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
543 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
544 .buf=tda8275_init, .len = 14};
545 if (priv->ver & TDA8275A)
546 msg.buf = tda8275a_init;
548 if (fe->ops.analog_ops.i2c_gate_ctrl)
549 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
550 i2c_transfer(priv->i2c_props.adap, &msg, 1);
551 if (fe->ops.analog_ops.i2c_gate_ctrl)
552 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
555 /*---------------------------------------------------------------------*/
557 static void tda829x_release(struct dvb_frontend *fe)
559 struct tda8290_priv *priv = fe->analog_demod_priv;
561 /* only try to release the tuner if we've
562 * attached it from within this module */
563 if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))
564 if (fe->ops.tuner_ops.release)
565 fe->ops.tuner_ops.release(fe);
567 kfree(fe->analog_demod_priv);
568 fe->analog_demod_priv = NULL;
571 static struct tda18271_config tda829x_tda18271_config = {
572 .gate = TDA18271_GATE_ANALOG,
575 static int tda829x_find_tuner(struct dvb_frontend *fe)
577 struct tda8290_priv *priv = fe->analog_demod_priv;
578 int i, ret, tuners_found;
581 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
583 if (fe->ops.analog_ops.i2c_gate_ctrl)
584 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
586 /* probe for tuner chip */
589 for (i = 0x60; i <= 0x63; i++) {
591 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
594 tuner_addrs = (tuner_addrs << 8) + i;
597 /* if there is more than one tuner, we expect the right one is
598 behind the bridge and we choose the highest address that doesn't
602 if (fe->ops.analog_ops.i2c_gate_ctrl)
603 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
605 if (tuners_found > 1)
606 for (i = 0; i < tuners_found; i++) {
607 msg.addr = tuner_addrs & 0xff;
608 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
610 tuner_addrs = tuner_addrs >> 8;
615 if (tuner_addrs == 0) {
617 tuner_info("could not clearly identify tuner address, "
618 "defaulting to %x\n", tuner_addrs);
620 tuner_addrs = tuner_addrs & 0xff;
621 tuner_info("setting tuner address to %x\n", tuner_addrs);
623 priv->tda827x_addr = tuner_addrs;
624 msg.addr = tuner_addrs;
626 if (fe->ops.analog_ops.i2c_gate_ctrl)
627 fe->ops.analog_ops.i2c_gate_ctrl(fe, 1);
628 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
631 tuner_warn("tuner access failed!\n");
632 if (fe->ops.analog_ops.i2c_gate_ctrl)
633 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
637 if ((data == 0x83) || (data == 0x84)) {
638 priv->ver |= TDA18271;
639 tda829x_tda18271_config.config = priv->cfg.config;
640 tda829x_tda18271_config.std_map = priv->tda18271_std_map;
641 dvb_attach(tda18271_attach, fe, priv->tda827x_addr,
642 priv->i2c_props.adap, &tda829x_tda18271_config);
644 if ((data & 0x3c) == 0)
645 priv->ver |= TDA8275;
647 priv->ver |= TDA8275A;
649 dvb_attach(tda827x_attach, fe, priv->tda827x_addr,
650 priv->i2c_props.adap, &priv->cfg);
651 priv->cfg.switch_addr = priv->i2c_props.addr;
653 if (fe->ops.tuner_ops.init)
654 fe->ops.tuner_ops.init(fe);
656 if (fe->ops.tuner_ops.sleep)
657 fe->ops.tuner_ops.sleep(fe);
659 if (fe->ops.analog_ops.i2c_gate_ctrl)
660 fe->ops.analog_ops.i2c_gate_ctrl(fe, 0);
665 static int tda8290_probe(struct tuner_i2c_props *i2c_props)
667 #define TDA8290_ID 0x89
669 struct i2c_msg msg_read[] = {
670 { .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = ® },
671 { .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id },
675 if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) {
676 printk(KERN_WARNING "%s: couldn't read register 0x%02x\n",
681 if (id == TDA8290_ID) {
683 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
684 __func__, i2c_adapter_id(i2c_props->adap),
691 static int tda8295_probe(struct tuner_i2c_props *i2c_props)
693 #define TDA8295_ID 0x8a
694 #define TDA8295C2_ID 0x8b
696 struct i2c_msg msg_read[] = {
697 { .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = ® },
698 { .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id },
702 if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) {
703 printk(KERN_WARNING "%s: couldn't read register 0x%02x\n",
708 if ((id & 0xfe) == TDA8295_ID) {
710 printk(KERN_DEBUG "%s: %s detected @ %d-%04x\n",
711 __func__, (id == TDA8295_ID) ?
712 "tda8295c1" : "tda8295c2",
713 i2c_adapter_id(i2c_props->adap),
721 static struct analog_demod_ops tda8290_ops = {
722 .set_params = tda8290_set_params,
723 .has_signal = tda8290_has_signal,
724 .standby = tda8290_standby,
725 .release = tda829x_release,
726 .i2c_gate_ctrl = tda8290_i2c_bridge,
729 static struct analog_demod_ops tda8295_ops = {
730 .set_params = tda8295_set_params,
731 .has_signal = tda8295_has_signal,
732 .standby = tda8295_standby,
733 .release = tda829x_release,
734 .i2c_gate_ctrl = tda8295_i2c_bridge,
737 struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
738 struct i2c_adapter *i2c_adap, u8 i2c_addr,
739 struct tda829x_config *cfg)
741 struct tda8290_priv *priv = NULL;
744 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
747 fe->analog_demod_priv = priv;
749 priv->i2c_props.addr = i2c_addr;
750 priv->i2c_props.adap = i2c_adap;
751 priv->i2c_props.name = "tda829x";
753 priv->cfg.config = cfg->lna_cfg;
754 priv->tda18271_std_map = cfg->tda18271_std_map;
757 if (tda8290_probe(&priv->i2c_props) == 0) {
759 memcpy(&fe->ops.analog_ops, &tda8290_ops,
760 sizeof(struct analog_demod_ops));
763 if (tda8295_probe(&priv->i2c_props) == 0) {
765 memcpy(&fe->ops.analog_ops, &tda8295_ops,
766 sizeof(struct analog_demod_ops));
769 if (cfg && cfg->no_i2c_gate)
770 fe->ops.analog_ops.i2c_gate_ctrl = NULL;
772 if (!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) {
773 tda8295_power(fe, 1);
774 if (tda829x_find_tuner(fe) < 0)
785 case TDA8290 | TDA8275:
788 case TDA8295 | TDA8275:
791 case TDA8290 | TDA8275A:
792 name = "tda8290+75a";
794 case TDA8295 | TDA8275A:
795 name = "tda8295+75a";
797 case TDA8290 | TDA18271:
798 name = "tda8290+18271";
800 case TDA8295 | TDA18271:
801 name = "tda8295+18271";
806 tuner_info("type set to %s\n", name);
808 fe->ops.analog_ops.info.name = name;
810 if (priv->ver & TDA8290) {
811 if (priv->ver & (TDA8275 | TDA8275A))
812 tda8290_init_tuner(fe);
814 } else if (priv->ver & TDA8295)
820 memset(&fe->ops.analog_ops, 0, sizeof(struct analog_demod_ops));
825 EXPORT_SYMBOL_GPL(tda829x_attach);
827 int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
829 struct tuner_i2c_props i2c_props = {
834 unsigned char soft_reset[] = { 0x00, 0x00 };
835 unsigned char easy_mode_b[] = { 0x01, 0x02 };
836 unsigned char easy_mode_g[] = { 0x01, 0x04 };
837 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
838 unsigned char addr_dto_lsb = 0x07;
840 #define PROBE_BUFFER_SIZE 8
841 unsigned char buf[PROBE_BUFFER_SIZE];
844 /* rule out tda9887, which would return the same byte repeatedly */
845 tuner_i2c_xfer_send_recv(&i2c_props,
846 soft_reset, 1, buf, PROBE_BUFFER_SIZE);
847 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
848 if (buf[i] != buf[0])
852 /* all bytes are equal, not a tda829x - probably a tda9887 */
853 if (i == PROBE_BUFFER_SIZE)
856 if ((tda8290_probe(&i2c_props) == 0) ||
857 (tda8295_probe(&i2c_props) == 0))
860 /* fall back to old probing method */
861 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
862 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
863 tuner_i2c_xfer_send_recv(&i2c_props, &addr_dto_lsb, 1, &data, 1);
865 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
866 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
867 tuner_i2c_xfer_send_recv(&i2c_props,
868 &addr_dto_lsb, 1, &data, 1);
873 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
876 EXPORT_SYMBOL_GPL(tda829x_probe);
878 MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
879 MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
880 MODULE_LICENSE("GPL");
883 * Overrides for Emacs so that we follow Linus's tabbing style.
884 * ---------------------------------------------------------------------------