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>
30 static int tuner_debug;
31 module_param_named(debug, tuner_debug, int, 0644);
32 MODULE_PARM_DESC(debug, "enable verbose debug messages");
34 #define PREFIX "tda8290"
36 /* ---------------------------------------------------------------------- */
39 struct tuner_i2c_props i2c_props;
41 unsigned char tda8290_easy_mode;
43 unsigned char tda827x_addr;
52 struct tda827x_config cfg;
57 /*---------------------------------------------------------------------*/
59 static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
61 struct tda8290_priv *priv = fe->analog_demod_priv;
63 unsigned char enable[2] = { 0x21, 0xC0 };
64 unsigned char disable[2] = { 0x21, 0x00 };
69 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
70 /* let the bridge stabilize */
74 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
80 static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
82 struct tda8290_priv *priv = fe->analog_demod_priv;
84 unsigned char enable[2] = { 0x45, 0xc1 };
85 unsigned char disable[2] = { 0x46, 0x00 };
86 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
91 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
92 /* let the bridge stabilize */
96 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
97 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
101 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
105 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
111 /*---------------------------------------------------------------------*/
113 static void set_audio(struct dvb_frontend *fe,
114 struct analog_parameters *params)
116 struct tda8290_priv *priv = fe->analog_demod_priv;
117 struct tuner *t = priv->t;
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 tuner_dbg("setting tda829x to system %s\n", mode);
149 static void tda8290_set_params(struct dvb_frontend *fe,
150 struct analog_parameters *params)
152 struct tda8290_priv *priv = fe->analog_demod_priv;
153 struct tuner *t = priv->t;
155 unsigned char soft_reset[] = { 0x00, 0x00 };
156 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
157 unsigned char expert_mode[] = { 0x01, 0x80 };
158 unsigned char agc_out_on[] = { 0x02, 0x00 };
159 unsigned char gainset_off[] = { 0x28, 0x14 };
160 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
161 unsigned char adc_head_6[] = { 0x05, 0x04 };
162 unsigned char adc_head_9[] = { 0x05, 0x02 };
163 unsigned char adc_head_12[] = { 0x05, 0x01 };
164 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
165 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
166 unsigned char gainset_2[] = { 0x28, 0x64 };
167 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
168 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
169 unsigned char if_agc_set[] = { 0x0f, 0x81 };
170 unsigned char addr_adc_sat = 0x1a;
171 unsigned char addr_agc_stat = 0x1d;
172 unsigned char addr_pll_stat = 0x1b;
173 unsigned char adc_sat, agc_stat,
177 set_audio(fe, params);
179 tuner_dbg("tda827xa config is 0x%02x\n", t->config);
180 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
181 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
182 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
185 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
186 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
187 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
188 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
189 if (priv->tda8290_easy_mode & 0x60)
190 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
192 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
193 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
195 tda8290_i2c_bridge(fe, 1);
197 if (fe->ops.tuner_ops.set_analog_params)
198 fe->ops.tuner_ops.set_analog_params(fe, params);
200 for (i = 0; i < 3; i++) {
201 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
202 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
203 if (pll_stat & 0x80) {
204 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
205 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
206 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
207 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
208 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
211 tuner_dbg("tda8290 not locked, no signal?\n");
215 /* adjust headroom resp. gain */
216 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
217 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
218 agc_stat, adc_sat, pll_stat & 0x80);
219 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
221 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
222 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
223 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
224 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
225 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
226 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
227 agc_stat, pll_stat & 0x80);
231 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
232 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
233 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
234 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
235 if((agc_stat > 115) || !(pll_stat & 0x80)) {
236 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
237 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
238 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
244 /* l/ l' deadlock? */
245 if(priv->tda8290_easy_mode & 0x60) {
246 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
247 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
248 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
249 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
250 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
251 tuner_dbg("trying to resolve SECAM L deadlock\n");
252 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
254 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
258 tda8290_i2c_bridge(fe, 0);
259 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
262 /*---------------------------------------------------------------------*/
264 static void tda8295_power(struct dvb_frontend *fe, int enable)
266 struct tda8290_priv *priv = fe->analog_demod_priv;
267 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
269 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
270 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
277 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
280 static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
282 struct tda8290_priv *priv = fe->analog_demod_priv;
283 unsigned char buf[] = { 0x01, 0x00 };
285 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
286 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
289 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
291 buf[1] = 0x00; /* reset active bit */
293 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
296 static void tda8295_set_video_std(struct dvb_frontend *fe)
298 struct tda8290_priv *priv = fe->analog_demod_priv;
299 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
301 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
303 tda8295_set_easy_mode(fe, 1);
305 tda8295_set_easy_mode(fe, 0);
308 /*---------------------------------------------------------------------*/
310 static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
312 struct tda8290_priv *priv = fe->analog_demod_priv;
313 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
315 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
316 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
323 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
326 static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
328 struct tda8290_priv *priv = fe->analog_demod_priv;
329 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
330 unsigned char set_gpio_val[] = { 0x46, 0x00 };
332 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
333 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
334 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
335 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
337 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
340 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
341 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
343 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
344 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
347 static int tda8295_has_signal(struct dvb_frontend *fe)
349 struct tda8290_priv *priv = fe->analog_demod_priv;
351 unsigned char hvpll_stat = 0x26;
354 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
355 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
356 return (ret & 0x01) ? 65535 : 0;
359 /*---------------------------------------------------------------------*/
361 static void tda8295_set_params(struct dvb_frontend *fe,
362 struct analog_parameters *params)
364 struct tda8290_priv *priv = fe->analog_demod_priv;
365 struct tuner *t = priv->t;
367 unsigned char blanking_mode[] = { 0x1d, 0x00 };
369 set_audio(fe, params);
371 tuner_dbg("%s: freq = %d\n", __FUNCTION__, params->frequency);
373 tda8295_power(fe, 1);
374 tda8295_agc1_out(fe, 1);
376 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
377 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
379 tda8295_set_video_std(fe);
381 blanking_mode[1] = 0x03;
382 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
385 tda8295_i2c_bridge(fe, 1);
387 if (fe->ops.tuner_ops.set_analog_params)
388 fe->ops.tuner_ops.set_analog_params(fe, params);
393 if (tda8295_has_signal(fe))
394 tuner_dbg("tda8295 is locked\n");
396 tuner_dbg("tda8295 not locked, no signal?\n");
398 tda8295_i2c_bridge(fe, 0);
401 /*---------------------------------------------------------------------*/
403 static int tda8290_has_signal(struct dvb_frontend *fe)
405 struct tda8290_priv *priv = fe->analog_demod_priv;
407 unsigned char i2c_get_afc[1] = { 0x1B };
408 unsigned char afc = 0;
410 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
411 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
412 return (afc & 0x80)? 65535:0;
415 /*---------------------------------------------------------------------*/
417 static void tda8290_standby(struct dvb_frontend *fe)
419 struct tda8290_priv *priv = fe->analog_demod_priv;
421 unsigned char cb1[] = { 0x30, 0xD0 };
422 unsigned char tda8290_standby[] = { 0x00, 0x02 };
423 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
424 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
426 tda8290_i2c_bridge(fe, 1);
427 if (priv->ver & TDA8275A)
429 i2c_transfer(priv->i2c_props.adap, &msg, 1);
430 tda8290_i2c_bridge(fe, 0);
431 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
432 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
435 static void tda8295_standby(struct dvb_frontend *fe)
437 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
439 tda8295_power(fe, 0);
442 static void tda8290_init_if(struct dvb_frontend *fe)
444 struct tda8290_priv *priv = fe->analog_demod_priv;
445 struct tuner *t = priv->t;
447 unsigned char set_VS[] = { 0x30, 0x6F };
448 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
449 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
451 if ((t->config == 1) || (t->config == 2))
452 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
454 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
455 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
458 static void tda8295_init_if(struct dvb_frontend *fe)
460 struct tda8290_priv *priv = fe->analog_demod_priv;
462 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
463 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
464 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
465 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
466 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
467 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
468 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
470 tda8295_power(fe, 1);
472 tda8295_set_easy_mode(fe, 0);
473 tda8295_set_video_std(fe);
475 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
476 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
477 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
478 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
479 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
480 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
481 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
483 tda8295_agc1_out(fe, 0);
484 tda8295_agc2_out(fe, 0);
487 static void tda8290_init_tuner(struct dvb_frontend *fe)
489 struct tda8290_priv *priv = fe->analog_demod_priv;
490 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
491 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
492 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
493 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
494 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
495 .buf=tda8275_init, .len = 14};
496 if (priv->ver & TDA8275A)
497 msg.buf = tda8275a_init;
499 tda8290_i2c_bridge(fe, 1);
500 i2c_transfer(priv->i2c_props.adap, &msg, 1);
501 tda8290_i2c_bridge(fe, 0);
504 /*---------------------------------------------------------------------*/
506 static void tda829x_release(struct dvb_frontend *fe)
508 if (fe->ops.tuner_ops.release)
509 fe->ops.tuner_ops.release(fe);
511 kfree(fe->analog_demod_priv);
512 fe->analog_demod_priv = NULL;
515 static int tda829x_find_tuner(struct dvb_frontend *fe)
517 struct tda8290_priv *priv = fe->analog_demod_priv;
518 struct analog_tuner_ops *ops = fe->ops.analog_demod_ops;
519 struct tuner *t = priv->t;
520 int i, ret, tuners_found;
523 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
528 ops->i2c_gate_ctrl(fe, 1);
530 /* probe for tuner chip */
533 for (i = 0x60; i <= 0x63; i++) {
535 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
538 tuner_addrs = (tuner_addrs << 8) + i;
541 /* if there is more than one tuner, we expect the right one is
542 behind the bridge and we choose the highest address that doesn't
546 ops->i2c_gate_ctrl(fe, 0);
548 if (tuners_found > 1)
549 for (i = 0; i < tuners_found; i++) {
550 msg.addr = tuner_addrs & 0xff;
551 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
553 tuner_addrs = tuner_addrs >> 8;
558 if (tuner_addrs == 0) {
560 tuner_info("could not clearly identify tuner address, "
561 "defaulting to %x\n", tuner_addrs);
563 tuner_addrs = tuner_addrs & 0xff;
564 tuner_info("setting tuner address to %x\n", tuner_addrs);
566 priv->tda827x_addr = tuner_addrs;
567 msg.addr = tuner_addrs;
569 ops->i2c_gate_ctrl(fe, 1);
570 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
573 tuner_warn("tuner access failed!\n");
578 priv->ver |= TDA18271;
579 tda18271_attach(fe, priv->tda827x_addr,
580 priv->i2c_props.adap);
582 if ((data & 0x3c) == 0)
583 priv->ver |= TDA8275;
585 priv->ver |= TDA8275A;
587 tda827x_attach(fe, priv->tda827x_addr,
588 priv->i2c_props.adap, &priv->cfg);
590 if (fe->ops.tuner_ops.init)
591 fe->ops.tuner_ops.init(fe);
593 if (fe->ops.tuner_ops.sleep)
594 fe->ops.tuner_ops.sleep(fe);
596 ops->i2c_gate_ctrl(fe, 0);
599 case TDA8290 | TDA8275:
600 strlcpy(t->i2c->name, "tda8290+75", sizeof(t->i2c->name));
602 case TDA8295 | TDA8275:
603 strlcpy(t->i2c->name, "tda8295+75", sizeof(t->i2c->name));
605 case TDA8290 | TDA8275A:
606 strlcpy(t->i2c->name, "tda8290+75a", sizeof(t->i2c->name));
608 case TDA8295 | TDA8275A:
609 strlcpy(t->i2c->name, "tda8295+75a", sizeof(t->i2c->name));
611 case TDA8290 | TDA18271:
612 strlcpy(t->i2c->name, "tda8290+18271", sizeof(t->i2c->name));
614 case TDA8295 | TDA18271:
615 strlcpy(t->i2c->name, "tda8295+18271", sizeof(t->i2c->name));
624 static int tda8290_probe(struct tuner_i2c_props *i2c_props)
626 #define TDA8290_ID 0x89
627 unsigned char tda8290_id[] = { 0x1f, 0x00 };
630 tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
631 tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
633 if (tda8290_id[1] == TDA8290_ID) {
635 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
636 __FUNCTION__, i2c_adapter_id(i2c_props->adap),
644 static int tda8295_probe(struct tuner_i2c_props *i2c_props)
646 #define TDA8295_ID 0x8a
647 unsigned char tda8295_id[] = { 0x2f, 0x00 };
650 tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
651 tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
653 if (tda8295_id[1] == TDA8295_ID) {
655 printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n",
656 __FUNCTION__, i2c_adapter_id(i2c_props->adap),
664 static struct analog_tuner_ops tda8290_tuner_ops = {
665 .set_params = tda8290_set_params,
666 .has_signal = tda8290_has_signal,
667 .standby = tda8290_standby,
668 .release = tda829x_release,
669 .i2c_gate_ctrl = tda8290_i2c_bridge,
672 static struct analog_tuner_ops tda8295_tuner_ops = {
673 .set_params = tda8295_set_params,
674 .has_signal = tda8295_has_signal,
675 .standby = tda8295_standby,
676 .release = tda829x_release,
677 .i2c_gate_ctrl = tda8295_i2c_bridge,
680 int tda829x_attach(struct tuner *t)
682 struct dvb_frontend *fe = &t->fe;
683 struct tda8290_priv *priv = NULL;
685 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
688 fe->analog_demod_priv = priv;
690 priv->i2c_props.addr = t->i2c->addr;
691 priv->i2c_props.adap = t->i2c->adapter;
692 priv->cfg.config = &t->config;
693 priv->cfg.tuner_callback = t->tuner_callback;
696 if (tda8290_probe(&priv->i2c_props) == 0) {
698 fe->ops.analog_demod_ops = &tda8290_tuner_ops;
701 if (tda8295_probe(&priv->i2c_props) == 0) {
703 fe->ops.analog_demod_ops = &tda8295_tuner_ops;
706 if (tda829x_find_tuner(fe) < 0)
709 if (priv->ver & TDA8290) {
710 tda8290_init_tuner(fe);
712 } else if (priv->ver & TDA8295)
715 tuner_info("type set to %s\n", t->i2c->name);
717 t->mode = V4L2_TUNER_ANALOG_TV;
721 EXPORT_SYMBOL_GPL(tda829x_attach);
723 int tda829x_probe(struct tuner *t)
725 struct tuner_i2c_props i2c_props = {
726 .adap = t->i2c->adapter,
730 unsigned char soft_reset[] = { 0x00, 0x00 };
731 unsigned char easy_mode_b[] = { 0x01, 0x02 };
732 unsigned char easy_mode_g[] = { 0x01, 0x04 };
733 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
734 unsigned char addr_dto_lsb = 0x07;
736 #define PROBE_BUFFER_SIZE 8
737 unsigned char buf[PROBE_BUFFER_SIZE];
740 /* rule out tda9887, which would return the same byte repeatedly */
741 tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
742 tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
743 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
744 if (buf[i] != buf[0])
748 /* all bytes are equal, not a tda829x - probably a tda9887 */
749 if (i == PROBE_BUFFER_SIZE)
752 if ((tda8290_probe(&i2c_props) == 0) ||
753 (tda8295_probe(&i2c_props) == 0))
756 /* fall back to old probing method */
757 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
758 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
759 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
760 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
762 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
763 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
764 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
765 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
770 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
773 EXPORT_SYMBOL_GPL(tda829x_probe);
775 MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
776 MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
777 MODULE_LICENSE("GPL");
780 * Overrides for Emacs so that we follow Linus's tabbing style.
781 * ---------------------------------------------------------------------------