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/videodev.h>
26 #include "tuner-i2c.h"
32 module_param(debug, int, 0644);
33 MODULE_PARM_DESC(debug, "enable verbose debug messages");
35 /* ---------------------------------------------------------------------- */
38 struct tuner_i2c_props i2c_props;
40 unsigned char tda8290_easy_mode;
42 unsigned char tda827x_addr;
51 struct tda827x_config cfg;
54 /*---------------------------------------------------------------------*/
56 static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
58 struct tda8290_priv *priv = fe->analog_demod_priv;
60 unsigned char enable[2] = { 0x21, 0xC0 };
61 unsigned char disable[2] = { 0x21, 0x00 };
66 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
67 /* let the bridge stabilize */
71 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
77 static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
79 struct tda8290_priv *priv = fe->analog_demod_priv;
81 unsigned char enable[2] = { 0x45, 0xc1 };
82 unsigned char disable[2] = { 0x46, 0x00 };
83 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
88 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
89 /* let the bridge stabilize */
93 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
94 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
98 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
102 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
108 /*---------------------------------------------------------------------*/
110 static void set_audio(struct dvb_frontend *fe,
111 struct analog_parameters *params)
113 struct tda8290_priv *priv = fe->analog_demod_priv;
116 if (params->std & V4L2_STD_MN) {
117 priv->tda8290_easy_mode = 0x01;
119 } else if (params->std & V4L2_STD_B) {
120 priv->tda8290_easy_mode = 0x02;
122 } else if (params->std & V4L2_STD_GH) {
123 priv->tda8290_easy_mode = 0x04;
125 } else if (params->std & V4L2_STD_PAL_I) {
126 priv->tda8290_easy_mode = 0x08;
128 } else if (params->std & V4L2_STD_DK) {
129 priv->tda8290_easy_mode = 0x10;
131 } else if (params->std & V4L2_STD_SECAM_L) {
132 priv->tda8290_easy_mode = 0x20;
134 } else if (params->std & V4L2_STD_SECAM_LC) {
135 priv->tda8290_easy_mode = 0x40;
138 priv->tda8290_easy_mode = 0x10;
142 tuner_dbg("setting tda829x to system %s\n", mode);
145 static void tda8290_set_params(struct dvb_frontend *fe,
146 struct analog_parameters *params)
148 struct tda8290_priv *priv = fe->analog_demod_priv;
150 unsigned char soft_reset[] = { 0x00, 0x00 };
151 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
152 unsigned char expert_mode[] = { 0x01, 0x80 };
153 unsigned char agc_out_on[] = { 0x02, 0x00 };
154 unsigned char gainset_off[] = { 0x28, 0x14 };
155 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
156 unsigned char adc_head_6[] = { 0x05, 0x04 };
157 unsigned char adc_head_9[] = { 0x05, 0x02 };
158 unsigned char adc_head_12[] = { 0x05, 0x01 };
159 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
160 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
161 unsigned char gainset_2[] = { 0x28, 0x64 };
162 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
163 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
164 unsigned char if_agc_set[] = { 0x0f, 0x81 };
165 unsigned char addr_adc_sat = 0x1a;
166 unsigned char addr_agc_stat = 0x1d;
167 unsigned char addr_pll_stat = 0x1b;
168 unsigned char adc_sat, agc_stat,
172 set_audio(fe, params);
174 if (priv->cfg.config)
175 tuner_dbg("tda827xa config is 0x%02x\n", priv->cfg.config);
176 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
177 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
178 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
181 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
182 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
183 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
184 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
185 if (priv->tda8290_easy_mode & 0x60)
186 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
188 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
189 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
191 tda8290_i2c_bridge(fe, 1);
193 if (fe->ops.tuner_ops.set_analog_params)
194 fe->ops.tuner_ops.set_analog_params(fe, params);
196 for (i = 0; i < 3; i++) {
197 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
198 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
199 if (pll_stat & 0x80) {
200 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
201 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
202 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
203 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
204 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
207 tuner_dbg("tda8290 not locked, no signal?\n");
211 /* adjust headroom resp. gain */
212 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
213 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
214 agc_stat, adc_sat, pll_stat & 0x80);
215 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
217 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
218 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
219 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
220 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
221 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
222 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
223 agc_stat, pll_stat & 0x80);
227 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
228 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
229 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
230 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
231 if((agc_stat > 115) || !(pll_stat & 0x80)) {
232 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
233 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
234 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
240 /* l/ l' deadlock? */
241 if(priv->tda8290_easy_mode & 0x60) {
242 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
243 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
244 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
245 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
246 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
247 tuner_dbg("trying to resolve SECAM L deadlock\n");
248 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
250 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
254 tda8290_i2c_bridge(fe, 0);
255 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
258 /*---------------------------------------------------------------------*/
260 static void tda8295_power(struct dvb_frontend *fe, int enable)
262 struct tda8290_priv *priv = fe->analog_demod_priv;
263 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
265 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
266 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
273 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
276 static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
278 struct tda8290_priv *priv = fe->analog_demod_priv;
279 unsigned char buf[] = { 0x01, 0x00 };
281 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
282 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
285 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
287 buf[1] = 0x00; /* reset active bit */
289 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
292 static void tda8295_set_video_std(struct dvb_frontend *fe)
294 struct tda8290_priv *priv = fe->analog_demod_priv;
295 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
297 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
299 tda8295_set_easy_mode(fe, 1);
301 tda8295_set_easy_mode(fe, 0);
304 /*---------------------------------------------------------------------*/
306 static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
308 struct tda8290_priv *priv = fe->analog_demod_priv;
309 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
311 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
312 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
319 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
322 static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
324 struct tda8290_priv *priv = fe->analog_demod_priv;
325 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
326 unsigned char set_gpio_val[] = { 0x46, 0x00 };
328 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
329 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
330 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
331 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
333 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
336 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
337 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
339 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
340 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
343 static int tda8295_has_signal(struct dvb_frontend *fe)
345 struct tda8290_priv *priv = fe->analog_demod_priv;
347 unsigned char hvpll_stat = 0x26;
350 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
351 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
352 return (ret & 0x01) ? 65535 : 0;
355 /*---------------------------------------------------------------------*/
357 static void tda8295_set_params(struct dvb_frontend *fe,
358 struct analog_parameters *params)
360 struct tda8290_priv *priv = fe->analog_demod_priv;
362 unsigned char blanking_mode[] = { 0x1d, 0x00 };
364 set_audio(fe, params);
366 tuner_dbg("%s: freq = %d\n", __func__, params->frequency);
368 tda8295_power(fe, 1);
369 tda8295_agc1_out(fe, 1);
371 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
372 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
374 tda8295_set_video_std(fe);
376 blanking_mode[1] = 0x03;
377 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
380 tda8295_i2c_bridge(fe, 1);
382 if (fe->ops.tuner_ops.set_analog_params)
383 fe->ops.tuner_ops.set_analog_params(fe, params);
388 if (tda8295_has_signal(fe))
389 tuner_dbg("tda8295 is locked\n");
391 tuner_dbg("tda8295 not locked, no signal?\n");
393 tda8295_i2c_bridge(fe, 0);
396 /*---------------------------------------------------------------------*/
398 static int tda8290_has_signal(struct dvb_frontend *fe)
400 struct tda8290_priv *priv = fe->analog_demod_priv;
402 unsigned char i2c_get_afc[1] = { 0x1B };
403 unsigned char afc = 0;
405 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
406 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
407 return (afc & 0x80)? 65535:0;
410 /*---------------------------------------------------------------------*/
412 static void tda8290_standby(struct dvb_frontend *fe)
414 struct tda8290_priv *priv = fe->analog_demod_priv;
416 unsigned char cb1[] = { 0x30, 0xD0 };
417 unsigned char tda8290_standby[] = { 0x00, 0x02 };
418 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
419 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
421 tda8290_i2c_bridge(fe, 1);
422 if (priv->ver & TDA8275A)
424 i2c_transfer(priv->i2c_props.adap, &msg, 1);
425 tda8290_i2c_bridge(fe, 0);
426 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
427 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
430 static void tda8295_standby(struct dvb_frontend *fe)
432 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
434 tda8295_power(fe, 0);
437 static void tda8290_init_if(struct dvb_frontend *fe)
439 struct tda8290_priv *priv = fe->analog_demod_priv;
441 unsigned char set_VS[] = { 0x30, 0x6F };
442 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
443 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
445 if ((priv->cfg.config == 1) || (priv->cfg.config == 2))
446 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
448 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
449 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
452 static void tda8295_init_if(struct dvb_frontend *fe)
454 struct tda8290_priv *priv = fe->analog_demod_priv;
456 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
457 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
458 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
459 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
460 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
461 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
462 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
464 tda8295_power(fe, 1);
466 tda8295_set_easy_mode(fe, 0);
467 tda8295_set_video_std(fe);
469 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
470 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
471 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
472 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
473 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
474 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
475 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
477 tda8295_agc1_out(fe, 0);
478 tda8295_agc2_out(fe, 0);
481 static void tda8290_init_tuner(struct dvb_frontend *fe)
483 struct tda8290_priv *priv = fe->analog_demod_priv;
484 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
485 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
486 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
487 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
488 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
489 .buf=tda8275_init, .len = 14};
490 if (priv->ver & TDA8275A)
491 msg.buf = tda8275a_init;
493 tda8290_i2c_bridge(fe, 1);
494 i2c_transfer(priv->i2c_props.adap, &msg, 1);
495 tda8290_i2c_bridge(fe, 0);
498 /*---------------------------------------------------------------------*/
500 static void tda829x_release(struct dvb_frontend *fe)
502 struct tda8290_priv *priv = fe->analog_demod_priv;
504 /* only try to release the tuner if we've
505 * attached it from within this module */
506 if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))
507 if (fe->ops.tuner_ops.release)
508 fe->ops.tuner_ops.release(fe);
510 kfree(fe->analog_demod_priv);
511 fe->analog_demod_priv = NULL;
514 static struct tda18271_config tda829x_tda18271_config = {
515 .gate = TDA18271_GATE_ANALOG,
518 static int tda829x_find_tuner(struct dvb_frontend *fe)
520 struct tda8290_priv *priv = fe->analog_demod_priv;
521 struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
522 int i, ret, tuners_found;
525 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
527 if (NULL == analog_ops->i2c_gate_ctrl)
530 analog_ops->i2c_gate_ctrl(fe, 1);
532 /* probe for tuner chip */
535 for (i = 0x60; i <= 0x63; i++) {
537 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
540 tuner_addrs = (tuner_addrs << 8) + i;
543 /* if there is more than one tuner, we expect the right one is
544 behind the bridge and we choose the highest address that doesn't
548 analog_ops->i2c_gate_ctrl(fe, 0);
550 if (tuners_found > 1)
551 for (i = 0; i < tuners_found; i++) {
552 msg.addr = tuner_addrs & 0xff;
553 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
555 tuner_addrs = tuner_addrs >> 8;
560 if (tuner_addrs == 0) {
562 tuner_info("could not clearly identify tuner address, "
563 "defaulting to %x\n", tuner_addrs);
565 tuner_addrs = tuner_addrs & 0xff;
566 tuner_info("setting tuner address to %x\n", tuner_addrs);
568 priv->tda827x_addr = tuner_addrs;
569 msg.addr = tuner_addrs;
571 analog_ops->i2c_gate_ctrl(fe, 1);
572 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
575 tuner_warn("tuner access failed!\n");
579 if ((data == 0x83) || (data == 0x84)) {
580 priv->ver |= TDA18271;
581 dvb_attach(tda18271_attach, fe, priv->tda827x_addr,
582 priv->i2c_props.adap, &tda829x_tda18271_config);
584 if ((data & 0x3c) == 0)
585 priv->ver |= TDA8275;
587 priv->ver |= TDA8275A;
589 dvb_attach(tda827x_attach, fe, priv->tda827x_addr,
590 priv->i2c_props.adap, &priv->cfg);
591 priv->cfg.switch_addr = priv->i2c_props.addr;
593 if (fe->ops.tuner_ops.init)
594 fe->ops.tuner_ops.init(fe);
596 if (fe->ops.tuner_ops.sleep)
597 fe->ops.tuner_ops.sleep(fe);
599 analog_ops->i2c_gate_ctrl(fe, 0);
604 static int tda8290_probe(struct tuner_i2c_props *i2c_props)
606 #define TDA8290_ID 0x89
607 unsigned char tda8290_id[] = { 0x1f, 0x00 };
610 tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
611 tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
613 if (tda8290_id[1] == TDA8290_ID) {
615 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
616 __func__, i2c_adapter_id(i2c_props->adap),
624 static int tda8295_probe(struct tuner_i2c_props *i2c_props)
626 #define TDA8295_ID 0x8a
627 unsigned char tda8295_id[] = { 0x2f, 0x00 };
630 tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
631 tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
633 if (tda8295_id[1] == TDA8295_ID) {
635 printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n",
636 __func__, i2c_adapter_id(i2c_props->adap),
644 static struct analog_demod_ops tda8290_ops = {
645 .set_params = tda8290_set_params,
646 .has_signal = tda8290_has_signal,
647 .standby = tda8290_standby,
648 .release = tda829x_release,
649 .i2c_gate_ctrl = tda8290_i2c_bridge,
652 static struct analog_demod_ops tda8295_ops = {
653 .set_params = tda8295_set_params,
654 .has_signal = tda8295_has_signal,
655 .standby = tda8295_standby,
656 .release = tda829x_release,
657 .i2c_gate_ctrl = tda8295_i2c_bridge,
660 struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
661 struct i2c_adapter *i2c_adap, u8 i2c_addr,
662 struct tda829x_config *cfg)
664 struct tda8290_priv *priv = NULL;
667 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
670 fe->analog_demod_priv = priv;
672 priv->i2c_props.addr = i2c_addr;
673 priv->i2c_props.adap = i2c_adap;
674 priv->i2c_props.name = "tda829x";
676 priv->cfg.config = cfg->lna_cfg;
677 priv->cfg.tuner_callback = cfg->tuner_callback;
680 if (tda8290_probe(&priv->i2c_props) == 0) {
682 memcpy(&fe->ops.analog_ops, &tda8290_ops,
683 sizeof(struct analog_demod_ops));
686 if (tda8295_probe(&priv->i2c_props) == 0) {
688 memcpy(&fe->ops.analog_ops, &tda8295_ops,
689 sizeof(struct analog_demod_ops));
692 if ((!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) &&
693 (tda829x_find_tuner(fe) < 0))
703 case TDA8290 | TDA8275:
706 case TDA8295 | TDA8275:
709 case TDA8290 | TDA8275A:
710 name = "tda8290+75a";
712 case TDA8295 | TDA8275A:
713 name = "tda8295+75a";
715 case TDA8290 | TDA18271:
716 name = "tda8290+18271";
718 case TDA8295 | TDA18271:
719 name = "tda8295+18271";
724 tuner_info("type set to %s\n", name);
726 fe->ops.analog_ops.info.name = name;
728 if (priv->ver & TDA8290) {
729 tda8290_init_tuner(fe);
731 } else if (priv->ver & TDA8295)
740 EXPORT_SYMBOL_GPL(tda829x_attach);
742 int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
744 struct tuner_i2c_props i2c_props = {
749 unsigned char soft_reset[] = { 0x00, 0x00 };
750 unsigned char easy_mode_b[] = { 0x01, 0x02 };
751 unsigned char easy_mode_g[] = { 0x01, 0x04 };
752 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
753 unsigned char addr_dto_lsb = 0x07;
755 #define PROBE_BUFFER_SIZE 8
756 unsigned char buf[PROBE_BUFFER_SIZE];
759 /* rule out tda9887, which would return the same byte repeatedly */
760 tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
761 tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
762 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
763 if (buf[i] != buf[0])
767 /* all bytes are equal, not a tda829x - probably a tda9887 */
768 if (i == PROBE_BUFFER_SIZE)
771 if ((tda8290_probe(&i2c_props) == 0) ||
772 (tda8295_probe(&i2c_props) == 0))
775 /* fall back to old probing method */
776 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
777 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
778 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
779 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
781 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
782 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
783 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
784 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
789 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
792 EXPORT_SYMBOL_GPL(tda829x_probe);
794 MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
795 MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
796 MODULE_LICENSE("GPL");
799 * Overrides for Emacs so that we follow Linus's tabbing style.
800 * ---------------------------------------------------------------------------