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/delay.h>
25 #include <linux/videodev2.h>
26 #include "tuner-i2c.h"
32 module_param(debug, int, 0644);
33 MODULE_PARM_DESC(debug, "enable verbose debug messages");
35 static int deemphasis_50;
36 module_param(deemphasis_50, int, 0644);
37 MODULE_PARM_DESC(deemphasis_50, "0 - 75us deemphasis; 1 - 50us deemphasis");
39 /* ---------------------------------------------------------------------- */
42 struct tuner_i2c_props i2c_props;
44 unsigned char tda8290_easy_mode;
46 unsigned char tda827x_addr;
55 struct tda827x_config cfg;
58 /*---------------------------------------------------------------------*/
60 static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
62 struct tda8290_priv *priv = fe->analog_demod_priv;
64 unsigned char enable[2] = { 0x21, 0xC0 };
65 unsigned char disable[2] = { 0x21, 0x00 };
70 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
71 /* let the bridge stabilize */
75 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
81 static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
83 struct tda8290_priv *priv = fe->analog_demod_priv;
85 unsigned char enable[2] = { 0x45, 0xc1 };
86 unsigned char disable[2] = { 0x46, 0x00 };
87 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
92 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
93 /* let the bridge stabilize */
97 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
98 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
102 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
106 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
112 /*---------------------------------------------------------------------*/
114 static void set_audio(struct dvb_frontend *fe,
115 struct analog_parameters *params)
117 struct tda8290_priv *priv = fe->analog_demod_priv;
120 if (params->std & V4L2_STD_MN) {
121 priv->tda8290_easy_mode = 0x01;
123 } else if (params->std & V4L2_STD_B) {
124 priv->tda8290_easy_mode = 0x02;
126 } else if (params->std & V4L2_STD_GH) {
127 priv->tda8290_easy_mode = 0x04;
129 } else if (params->std & V4L2_STD_PAL_I) {
130 priv->tda8290_easy_mode = 0x08;
132 } else if (params->std & V4L2_STD_DK) {
133 priv->tda8290_easy_mode = 0x10;
135 } else if (params->std & V4L2_STD_SECAM_L) {
136 priv->tda8290_easy_mode = 0x20;
138 } else if (params->std & V4L2_STD_SECAM_LC) {
139 priv->tda8290_easy_mode = 0x40;
142 priv->tda8290_easy_mode = 0x10;
146 if (params->mode == V4L2_TUNER_RADIO) {
147 /* Set TDA8295 to FM radio; Start TDA8290 with MN values */
148 priv->tda8290_easy_mode = (priv->ver & TDA8295) ? 0x80 : 0x01;
149 tuner_dbg("setting to radio FM\n");
151 tuner_dbg("setting tda829x to system %s\n", mode);
156 unsigned char seq[2];
158 { { 0x01, 0x81} }, /* Put device into expert mode */
159 { { 0x03, 0x48} }, /* Disable NOTCH and VIDEO filters */
160 { { 0x04, 0x04} }, /* Disable color carrier filter (SSIF) */
161 { { 0x05, 0x04} }, /* ADC headroom */
162 { { 0x06, 0x10} }, /* group delay flat */
164 { { 0x07, 0x00} }, /* use the same radio DTO values as a tda8295 */
171 { { 0x0d, 0x00} }, /* PLL off, no video carrier detect */
172 { { 0x14, 0x00} }, /* disable auto mute if no video */
175 static void tda8290_set_params(struct dvb_frontend *fe,
176 struct analog_parameters *params)
178 struct tda8290_priv *priv = fe->analog_demod_priv;
180 unsigned char soft_reset[] = { 0x00, 0x00 };
181 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_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);
211 if (params->mode == V4L2_TUNER_RADIO) {
212 unsigned char deemphasis[] = { 0x13, 1 };
214 /* FIXME: allow using a different deemphasis */
219 for (i = 0; i < ARRAY_SIZE(fm_mode); i++)
220 tuner_i2c_xfer_send(&priv->i2c_props, fm_mode[i].seq, 2);
222 tuner_i2c_xfer_send(&priv->i2c_props, deemphasis, 2);
224 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
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);
228 if (priv->tda8290_easy_mode & 0x60)
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);
235 tda8290_i2c_bridge(fe, 1);
237 if (fe->ops.tuner_ops.set_analog_params)
238 fe->ops.tuner_ops.set_analog_params(fe, params);
240 for (i = 0; i < 3; i++) {
241 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
242 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
243 if (pll_stat & 0x80) {
244 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
245 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
246 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
247 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
248 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
251 tuner_dbg("tda8290 not locked, no signal?\n");
255 /* adjust headroom resp. gain */
256 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
257 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
258 agc_stat, adc_sat, pll_stat & 0x80);
259 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
261 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
262 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
263 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
264 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
265 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
266 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
267 agc_stat, pll_stat & 0x80);
271 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
272 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
273 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
274 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
275 if((agc_stat > 115) || !(pll_stat & 0x80)) {
276 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
277 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
278 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
284 /* l/ l' deadlock? */
285 if(priv->tda8290_easy_mode & 0x60) {
286 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
287 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
288 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
289 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
290 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
291 tuner_dbg("trying to resolve SECAM L deadlock\n");
292 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
294 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
298 tda8290_i2c_bridge(fe, 0);
299 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
302 /*---------------------------------------------------------------------*/
304 static void tda8295_power(struct dvb_frontend *fe, int enable)
306 struct tda8290_priv *priv = fe->analog_demod_priv;
307 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
309 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
310 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
317 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
320 static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
322 struct tda8290_priv *priv = fe->analog_demod_priv;
323 unsigned char buf[] = { 0x01, 0x00 };
325 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
326 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
329 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
331 buf[1] = 0x00; /* reset active bit */
333 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
336 static void tda8295_set_video_std(struct dvb_frontend *fe)
338 struct tda8290_priv *priv = fe->analog_demod_priv;
339 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
341 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
343 tda8295_set_easy_mode(fe, 1);
345 tda8295_set_easy_mode(fe, 0);
348 /*---------------------------------------------------------------------*/
350 static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
352 struct tda8290_priv *priv = fe->analog_demod_priv;
353 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
355 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
356 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
363 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
366 static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
368 struct tda8290_priv *priv = fe->analog_demod_priv;
369 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
370 unsigned char set_gpio_val[] = { 0x46, 0x00 };
372 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
373 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
374 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
375 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
377 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
380 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
381 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
383 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
384 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
387 static int tda8295_has_signal(struct dvb_frontend *fe)
389 struct tda8290_priv *priv = fe->analog_demod_priv;
391 unsigned char hvpll_stat = 0x26;
394 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
395 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
396 return (ret & 0x01) ? 65535 : 0;
399 /*---------------------------------------------------------------------*/
401 static void tda8295_set_params(struct dvb_frontend *fe,
402 struct analog_parameters *params)
404 struct tda8290_priv *priv = fe->analog_demod_priv;
406 unsigned char blanking_mode[] = { 0x1d, 0x00 };
408 set_audio(fe, params);
410 tuner_dbg("%s: freq = %d\n", __func__, params->frequency);
412 tda8295_power(fe, 1);
413 tda8295_agc1_out(fe, 1);
415 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
416 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
418 tda8295_set_video_std(fe);
420 blanking_mode[1] = 0x03;
421 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
424 tda8295_i2c_bridge(fe, 1);
426 if (fe->ops.tuner_ops.set_analog_params)
427 fe->ops.tuner_ops.set_analog_params(fe, params);
432 if (tda8295_has_signal(fe))
433 tuner_dbg("tda8295 is locked\n");
435 tuner_dbg("tda8295 not locked, no signal?\n");
437 tda8295_i2c_bridge(fe, 0);
440 /*---------------------------------------------------------------------*/
442 static int tda8290_has_signal(struct dvb_frontend *fe)
444 struct tda8290_priv *priv = fe->analog_demod_priv;
446 unsigned char i2c_get_afc[1] = { 0x1B };
447 unsigned char afc = 0;
449 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
450 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
451 return (afc & 0x80)? 65535:0;
454 /*---------------------------------------------------------------------*/
456 static void tda8290_standby(struct dvb_frontend *fe)
458 struct tda8290_priv *priv = fe->analog_demod_priv;
460 unsigned char cb1[] = { 0x30, 0xD0 };
461 unsigned char tda8290_standby[] = { 0x00, 0x02 };
462 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
463 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
465 tda8290_i2c_bridge(fe, 1);
466 if (priv->ver & TDA8275A)
468 i2c_transfer(priv->i2c_props.adap, &msg, 1);
469 tda8290_i2c_bridge(fe, 0);
470 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
471 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
474 static void tda8295_standby(struct dvb_frontend *fe)
476 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
478 tda8295_power(fe, 0);
481 static void tda8290_init_if(struct dvb_frontend *fe)
483 struct tda8290_priv *priv = fe->analog_demod_priv;
485 unsigned char set_VS[] = { 0x30, 0x6F };
486 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
487 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
489 if ((priv->cfg.config == 1) || (priv->cfg.config == 2))
490 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
492 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
493 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
496 static void tda8295_init_if(struct dvb_frontend *fe)
498 struct tda8290_priv *priv = fe->analog_demod_priv;
500 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
501 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
502 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
503 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
504 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
505 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
506 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
508 tda8295_power(fe, 1);
510 tda8295_set_easy_mode(fe, 0);
511 tda8295_set_video_std(fe);
513 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
514 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
515 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
516 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
517 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
518 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
519 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
521 tda8295_agc1_out(fe, 0);
522 tda8295_agc2_out(fe, 0);
525 static void tda8290_init_tuner(struct dvb_frontend *fe)
527 struct tda8290_priv *priv = fe->analog_demod_priv;
528 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
529 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
530 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
531 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
532 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
533 .buf=tda8275_init, .len = 14};
534 if (priv->ver & TDA8275A)
535 msg.buf = tda8275a_init;
537 tda8290_i2c_bridge(fe, 1);
538 i2c_transfer(priv->i2c_props.adap, &msg, 1);
539 tda8290_i2c_bridge(fe, 0);
542 /*---------------------------------------------------------------------*/
544 static void tda829x_release(struct dvb_frontend *fe)
546 struct tda8290_priv *priv = fe->analog_demod_priv;
548 /* only try to release the tuner if we've
549 * attached it from within this module */
550 if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))
551 if (fe->ops.tuner_ops.release)
552 fe->ops.tuner_ops.release(fe);
554 kfree(fe->analog_demod_priv);
555 fe->analog_demod_priv = NULL;
558 static struct tda18271_config tda829x_tda18271_config = {
559 .gate = TDA18271_GATE_ANALOG,
562 static int tda829x_find_tuner(struct dvb_frontend *fe)
564 struct tda8290_priv *priv = fe->analog_demod_priv;
565 struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
566 int i, ret, tuners_found;
569 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
571 if (!analog_ops->i2c_gate_ctrl) {
572 printk(KERN_ERR "tda8290: no gate control were provided!\n");
577 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 analog_ops->i2c_gate_ctrl(fe, 0);
597 if (tuners_found > 1)
598 for (i = 0; i < tuners_found; i++) {
599 msg.addr = tuner_addrs & 0xff;
600 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
602 tuner_addrs = tuner_addrs >> 8;
607 if (tuner_addrs == 0) {
609 tuner_info("could not clearly identify tuner address, "
610 "defaulting to %x\n", tuner_addrs);
612 tuner_addrs = tuner_addrs & 0xff;
613 tuner_info("setting tuner address to %x\n", tuner_addrs);
615 priv->tda827x_addr = tuner_addrs;
616 msg.addr = tuner_addrs;
618 analog_ops->i2c_gate_ctrl(fe, 1);
619 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
622 tuner_warn("tuner access failed!\n");
623 analog_ops->i2c_gate_ctrl(fe, 0);
627 if ((data == 0x83) || (data == 0x84)) {
628 priv->ver |= TDA18271;
629 tda829x_tda18271_config.config = priv->cfg.config;
630 dvb_attach(tda18271_attach, fe, priv->tda827x_addr,
631 priv->i2c_props.adap, &tda829x_tda18271_config);
633 if ((data & 0x3c) == 0)
634 priv->ver |= TDA8275;
636 priv->ver |= TDA8275A;
638 dvb_attach(tda827x_attach, fe, priv->tda827x_addr,
639 priv->i2c_props.adap, &priv->cfg);
640 priv->cfg.switch_addr = priv->i2c_props.addr;
642 if (fe->ops.tuner_ops.init)
643 fe->ops.tuner_ops.init(fe);
645 if (fe->ops.tuner_ops.sleep)
646 fe->ops.tuner_ops.sleep(fe);
648 analog_ops->i2c_gate_ctrl(fe, 0);
653 static int tda8290_probe(struct tuner_i2c_props *i2c_props)
655 #define TDA8290_ID 0x89
656 unsigned char tda8290_id[] = { 0x1f, 0x00 };
659 tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
660 tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
662 if (tda8290_id[1] == TDA8290_ID) {
664 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
665 __func__, i2c_adapter_id(i2c_props->adap),
673 static int tda8295_probe(struct tuner_i2c_props *i2c_props)
675 #define TDA8295_ID 0x8a
676 #define TDA8295C2_ID 0x8b
677 unsigned char tda8295_id[] = { 0x2f, 0x00 };
680 tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
681 tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
683 if ((tda8295_id[1] & 0xfe) == TDA8295_ID) {
685 printk(KERN_DEBUG "%s: %s detected @ %d-%04x\n",
686 __func__, (tda8295_id[1] == TDA8295_ID) ?
687 "tda8295c1" : "tda8295c2",
688 i2c_adapter_id(i2c_props->adap),
696 static struct analog_demod_ops tda8290_ops = {
697 .set_params = tda8290_set_params,
698 .has_signal = tda8290_has_signal,
699 .standby = tda8290_standby,
700 .release = tda829x_release,
701 .i2c_gate_ctrl = tda8290_i2c_bridge,
704 static struct analog_demod_ops tda8295_ops = {
705 .set_params = tda8295_set_params,
706 .has_signal = tda8295_has_signal,
707 .standby = tda8295_standby,
708 .release = tda829x_release,
709 .i2c_gate_ctrl = tda8295_i2c_bridge,
712 struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
713 struct i2c_adapter *i2c_adap, u8 i2c_addr,
714 struct tda829x_config *cfg)
716 struct tda8290_priv *priv = NULL;
719 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
722 fe->analog_demod_priv = priv;
724 priv->i2c_props.addr = i2c_addr;
725 priv->i2c_props.adap = i2c_adap;
726 priv->i2c_props.name = "tda829x";
728 priv->cfg.config = cfg->lna_cfg;
730 if (tda8290_probe(&priv->i2c_props) == 0) {
732 memcpy(&fe->ops.analog_ops, &tda8290_ops,
733 sizeof(struct analog_demod_ops));
736 if (tda8295_probe(&priv->i2c_props) == 0) {
738 memcpy(&fe->ops.analog_ops, &tda8295_ops,
739 sizeof(struct analog_demod_ops));
742 if ((!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) &&
743 (tda829x_find_tuner(fe) < 0))
753 case TDA8290 | TDA8275:
756 case TDA8295 | TDA8275:
759 case TDA8290 | TDA8275A:
760 name = "tda8290+75a";
762 case TDA8295 | TDA8275A:
763 name = "tda8295+75a";
765 case TDA8290 | TDA18271:
766 name = "tda8290+18271";
768 case TDA8295 | TDA18271:
769 name = "tda8295+18271";
774 tuner_info("type set to %s\n", name);
776 fe->ops.analog_ops.info.name = name;
778 if (priv->ver & TDA8290) {
779 if (priv->ver & (TDA8275 | TDA8275A))
780 tda8290_init_tuner(fe);
782 } else if (priv->ver & TDA8295)
791 EXPORT_SYMBOL_GPL(tda829x_attach);
793 int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
795 struct tuner_i2c_props i2c_props = {
800 unsigned char soft_reset[] = { 0x00, 0x00 };
801 unsigned char easy_mode_b[] = { 0x01, 0x02 };
802 unsigned char easy_mode_g[] = { 0x01, 0x04 };
803 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
804 unsigned char addr_dto_lsb = 0x07;
806 #define PROBE_BUFFER_SIZE 8
807 unsigned char buf[PROBE_BUFFER_SIZE];
810 /* rule out tda9887, which would return the same byte repeatedly */
811 tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
812 tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
813 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
814 if (buf[i] != buf[0])
818 /* all bytes are equal, not a tda829x - probably a tda9887 */
819 if (i == PROBE_BUFFER_SIZE)
822 if ((tda8290_probe(&i2c_props) == 0) ||
823 (tda8295_probe(&i2c_props) == 0))
826 /* fall back to old probing method */
827 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
828 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
829 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
830 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
832 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
833 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
834 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
835 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
840 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
843 EXPORT_SYMBOL_GPL(tda829x_probe);
845 MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
846 MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
847 MODULE_LICENSE("GPL");
850 * Overrides for Emacs so that we follow Linus's tabbing style.
851 * ---------------------------------------------------------------------------