3 * (c) 2005 Hartmut Hackmann
4 * (c) 2007 Michael Krufky
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.
21 #include <linux/module.h>
22 #include <asm/types.h>
23 #include <linux/dvb/frontend.h>
24 #include <linux/videodev2.h>
29 module_param(debug, int, 0644);
30 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
32 #define dprintk(args...) \
34 if (debug) printk(KERN_DEBUG "tda827x: " args); \
39 struct i2c_adapter *i2c_adap;
40 struct tda827x_config *cfg;
49 static void tda827x_set_std(struct dvb_frontend *fe,
50 struct analog_parameters *params)
52 struct tda827x_priv *priv = fe->tuner_priv;
56 if (params->std & V4L2_STD_MN) {
60 } else if (params->std & V4L2_STD_B) {
63 } else if (params->std & V4L2_STD_GH) {
66 } else if (params->std & V4L2_STD_PAL_I) {
69 } else if (params->std & V4L2_STD_DK) {
72 } else if (params->std & V4L2_STD_SECAM_L) {
75 } else if (params->std & V4L2_STD_SECAM_LC) {
83 if (params->mode == V4L2_TUNER_RADIO) {
84 priv->sgIF = 88; /* if frequency is 5.5 MHz */
85 dprintk("setting tda827x to radio FM\n");
87 dprintk("setting tda827x to system %s\n", mode);
91 /* ------------------------------------------------------------------ */
103 static const struct tda827x_data tda827x_table[] = {
104 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
105 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
106 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
107 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
108 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
109 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
110 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
111 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
112 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
113 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
114 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
115 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
116 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
117 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
118 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
119 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
120 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
121 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
122 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
123 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
124 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
125 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
126 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
127 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
128 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
129 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
130 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
131 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
132 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
135 static int tuner_transfer(struct dvb_frontend *fe,
140 struct tda827x_priv *priv = fe->tuner_priv;
142 if (fe->ops.i2c_gate_ctrl)
143 fe->ops.i2c_gate_ctrl(fe, 1);
144 rc = i2c_transfer(priv->i2c_adap, msg, size);
145 if (fe->ops.i2c_gate_ctrl)
146 fe->ops.i2c_gate_ctrl(fe, 0);
148 if (rc >= 0 && rc != size)
154 static int tda827xo_set_params(struct dvb_frontend *fe,
155 struct dvb_frontend_parameters *params)
157 struct tda827x_priv *priv = fe->tuner_priv;
161 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
162 .buf = buf, .len = sizeof(buf) };
163 int i, tuner_freq, if_freq;
166 dprintk("%s:\n", __func__);
167 switch (params->u.ofdm.bandwidth) {
168 case BANDWIDTH_6_MHZ:
171 case BANDWIDTH_7_MHZ:
174 default: /* 8 MHz or Auto */
178 tuner_freq = params->frequency + if_freq;
181 while (tda827x_table[i].lomax < tuner_freq) {
182 if (tda827x_table[i + 1].lomax == 0)
187 N = ((tuner_freq + 125000) / 250000) << (tda827x_table[i].spd + 2);
189 buf[1] = (N>>8) | 0x40;
193 buf[5] = (tda827x_table[i].spd << 6) + (tda827x_table[i].div1p5 << 5) +
194 (tda827x_table[i].bs << 3) +
196 buf[6] = (tda827x_table[i].gc3 << 4) + 0x8f;
206 rc = tuner_transfer(fe, &msg, 1);
211 /* correct CP value */
213 buf[1] = 0x50 + tda827x_table[i].cp;
216 rc = tuner_transfer(fe, &msg, 1);
220 priv->frequency = params->frequency;
221 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
226 printk(KERN_ERR "%s: could not write to tuner at addr: 0x%02x\n",
227 __func__, priv->i2c_addr << 1);
231 static int tda827xo_sleep(struct dvb_frontend *fe)
233 struct tda827x_priv *priv = fe->tuner_priv;
234 static u8 buf[] = { 0x30, 0xd0 };
235 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
236 .buf = buf, .len = sizeof(buf) };
238 dprintk("%s:\n", __func__);
239 tuner_transfer(fe, &msg, 1);
241 if (priv->cfg && priv->cfg->sleep)
242 priv->cfg->sleep(fe);
247 /* ------------------------------------------------------------------ */
249 static int tda827xo_set_analog_params(struct dvb_frontend *fe,
250 struct analog_parameters *params)
252 unsigned char tuner_reg[8];
253 unsigned char reg2[2];
256 struct tda827x_priv *priv = fe->tuner_priv;
257 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0 };
258 unsigned int freq = params->frequency;
260 tda827x_set_std(fe, params);
262 if (params->mode == V4L2_TUNER_RADIO)
265 N = freq + priv->sgIF;
268 while (tda827x_table[i].lomax < N * 62500) {
269 if (tda827x_table[i + 1].lomax == 0)
274 N = N << tda827x_table[i].spd;
277 tuner_reg[1] = (unsigned char)(N>>8);
278 tuner_reg[2] = (unsigned char) N;
280 tuner_reg[4] = 0x52 + (priv->lpsel << 5);
281 tuner_reg[5] = (tda827x_table[i].spd << 6) +
282 (tda827x_table[i].div1p5 << 5) +
283 (tda827x_table[i].bs << 3) + tda827x_table[i].bp;
284 tuner_reg[6] = 0x8f + (tda827x_table[i].gc3 << 4);
289 tuner_transfer(fe, &msg, 1);
295 tuner_transfer(fe, &msg, 1);
299 tuner_transfer(fe, &msg, 1);
302 reg2[1] = tuner_reg[4] + 0x80;
303 tuner_transfer(fe, &msg, 1);
307 reg2[1] = tuner_reg[4] + 4;
308 tuner_transfer(fe, &msg, 1);
312 reg2[1] = tuner_reg[4];
313 tuner_transfer(fe, &msg, 1);
317 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_table[i].cp;
318 tuner_transfer(fe, &msg, 1);
322 tuner_transfer(fe, &msg, 1);
325 reg2[1] = 0x08; /* Vsync en */
326 tuner_transfer(fe, &msg, 1);
328 priv->frequency = params->frequency;
333 static void tda827xo_agcf(struct dvb_frontend *fe)
335 struct tda827x_priv *priv = fe->tuner_priv;
336 unsigned char data[] = { 0x80, 0x0c };
337 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
338 .buf = data, .len = 2};
340 tuner_transfer(fe, &msg, 1);
343 /* ------------------------------------------------------------------ */
345 struct tda827xa_data {
354 static const struct tda827xa_data tda827xa_dvbt[] = {
355 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
356 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
357 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
358 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
359 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
360 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
361 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
362 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
363 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
364 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
365 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
366 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
367 { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
368 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
369 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
370 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
371 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
372 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
373 { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
374 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
375 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
376 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
377 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
378 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
379 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
380 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
381 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
384 static struct tda827xa_data tda827xa_analog[] = {
385 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3},
386 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
387 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
388 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
389 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
390 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
391 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
392 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
393 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
394 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
395 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3},
396 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3},
397 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
398 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
399 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
400 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
401 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
402 { .lomax = 554000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
403 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
404 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
405 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
406 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
407 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
408 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
409 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
410 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
413 static int tda827xa_sleep(struct dvb_frontend *fe)
415 struct tda827x_priv *priv = fe->tuner_priv;
416 static u8 buf[] = { 0x30, 0x90 };
417 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
418 .buf = buf, .len = sizeof(buf) };
420 dprintk("%s:\n", __func__);
422 tuner_transfer(fe, &msg, 1);
424 if (priv->cfg && priv->cfg->sleep)
425 priv->cfg->sleep(fe);
430 static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
431 struct analog_parameters *params)
433 struct tda827x_priv *priv = fe->tuner_priv;
434 unsigned char buf[] = {0x22, 0x01};
437 struct i2c_msg msg = { .flags = 0, .buf = buf, .len = sizeof(buf) };
439 if (NULL == priv->cfg) {
440 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
443 msg.addr = priv->cfg->switch_addr;
444 if (priv->cfg->config) {
446 dprintk("setting LNA to high gain\n");
448 dprintk("setting LNA to low gain\n");
450 switch (priv->cfg->config) {
453 case 1: /* switch is GPIO 0 of tda8290 */
455 if (params == NULL) {
461 if (params->std & V4L2_STD_MN)
467 fe->callback(priv->i2c_adap->algo_data,
468 DVB_FRONTEND_COMPONENT_TUNER,
470 buf[1] = high ? 0 : 1;
471 if (priv->cfg->config == 2)
472 buf[1] = high ? 1 : 0;
473 tuner_transfer(fe, &msg, 1);
475 case 3: /* switch with GPIO of saa713x */
477 fe->callback(priv->i2c_adap->algo_data,
478 DVB_FRONTEND_COMPONENT_TUNER, 0, high);
483 static int tda827xa_set_params(struct dvb_frontend *fe,
484 struct dvb_frontend_parameters *params)
486 struct tda827x_priv *priv = fe->tuner_priv;
489 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
490 .buf = buf, .len = sizeof(buf) };
492 int i, tuner_freq, if_freq, rc;
495 dprintk("%s:\n", __func__);
497 tda827xa_lna_gain(fe, 1, NULL);
500 switch (params->u.ofdm.bandwidth) {
501 case BANDWIDTH_6_MHZ:
504 case BANDWIDTH_7_MHZ:
507 default: /* 8 MHz or Auto */
511 tuner_freq = params->frequency + if_freq;
514 while (tda827xa_dvbt[i].lomax < tuner_freq) {
515 if(tda827xa_dvbt[i + 1].lomax == 0)
520 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
521 buf[0] = 0; // subaddress
526 buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
527 tda827xa_dvbt[i].sbs;
528 buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
534 rc = tuner_transfer(fe, &msg, 1);
542 buf[4] = 0x59; // lpsel, for 6MHz + 2
544 rc = tuner_transfer(fe, &msg, 1);
551 rc = tuner_transfer(fe, &msg, 1);
556 msg.flags = I2C_M_RD;
557 rc = tuner_transfer(fe, &msg, 1);
563 dprintk("tda8275a AGC2 gain is: %d\n", buf[1]);
565 tda827xa_lna_gain(fe, 0, NULL);
568 rc = tuner_transfer(fe, &msg, 1);
574 buf[1] = 0x99; // lpsel, for 6MHz + 2
575 rc = tuner_transfer(fe, &msg, 1);
581 rc = tuner_transfer(fe, &msg, 1);
585 /* correct CP value */
587 buf[1] = 0x10 + tda827xa_dvbt[i].scr;
588 rc = tuner_transfer(fe, &msg, 1);
594 buf[1] = 0x39; // lpsel, for 6MHz + 2
595 rc = tuner_transfer(fe, &msg, 1);
602 buf[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
603 rc = tuner_transfer(fe, &msg, 1);
607 priv->frequency = params->frequency;
608 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
614 printk(KERN_ERR "%s: could not write to tuner at addr: 0x%02x\n",
615 __func__, priv->i2c_addr << 1);
620 static int tda827xa_set_analog_params(struct dvb_frontend *fe,
621 struct analog_parameters *params)
623 unsigned char tuner_reg[11];
626 struct tda827x_priv *priv = fe->tuner_priv;
627 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
628 .buf = tuner_reg, .len = sizeof(tuner_reg) };
629 unsigned int freq = params->frequency;
631 tda827x_set_std(fe, params);
633 tda827xa_lna_gain(fe, 1, params);
636 if (params->mode == V4L2_TUNER_RADIO)
639 N = freq + priv->sgIF;
642 while (tda827xa_analog[i].lomax < N * 62500) {
643 if (tda827xa_analog[i + 1].lomax == 0)
648 N = N << tda827xa_analog[i].spd;
651 tuner_reg[1] = (unsigned char)(N>>8);
652 tuner_reg[2] = (unsigned char) N;
655 tuner_reg[5] = (tda827xa_analog[i].spd << 5) +
656 (tda827xa_analog[i].svco << 3) +
657 tda827xa_analog[i].sbs;
658 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
662 tuner_reg[10] = 0x00;
664 tuner_transfer(fe, &msg, 1);
670 tuner_reg[4] = 0x99 + (priv->lpsel << 1);
672 tuner_transfer(fe, &msg, 1);
677 tuner_transfer(fe, &msg, 1);
680 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
681 tuner_transfer(fe, &msg, 1);
683 msg.flags = I2C_M_RD;
684 tuner_transfer(fe, &msg, 1);
687 dprintk("AGC2 gain is: %d\n", tuner_reg[1]);
688 if (tuner_reg[1] < 1)
689 tda827xa_lna_gain(fe, 0, params);
694 tuner_transfer(fe, &msg, 1);
698 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
699 tuner_transfer(fe, &msg, 1);
703 tuner_transfer(fe, &msg, 1);
707 tuner_transfer(fe, &msg, 1);
710 tuner_reg[1] = 0x19 + (priv->lpsel << 1);
711 tuner_transfer(fe, &msg, 1);
713 priv->frequency = params->frequency;
718 static void tda827xa_agcf(struct dvb_frontend *fe)
720 struct tda827x_priv *priv = fe->tuner_priv;
721 unsigned char data[] = {0x80, 0x2c};
722 struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,
723 .buf = data, .len = 2};
724 tuner_transfer(fe, &msg, 1);
727 /* ------------------------------------------------------------------ */
729 static int tda827x_release(struct dvb_frontend *fe)
731 kfree(fe->tuner_priv);
732 fe->tuner_priv = NULL;
736 static int tda827x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
738 struct tda827x_priv *priv = fe->tuner_priv;
739 *frequency = priv->frequency;
743 static int tda827x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
745 struct tda827x_priv *priv = fe->tuner_priv;
746 *bandwidth = priv->bandwidth;
750 static int tda827x_init(struct dvb_frontend *fe)
752 struct tda827x_priv *priv = fe->tuner_priv;
753 dprintk("%s:\n", __func__);
754 if (priv->cfg && priv->cfg->init)
760 static int tda827x_probe_version(struct dvb_frontend *fe);
762 static int tda827x_initial_init(struct dvb_frontend *fe)
765 ret = tda827x_probe_version(fe);
768 return fe->ops.tuner_ops.init(fe);
771 static int tda827x_initial_sleep(struct dvb_frontend *fe)
774 ret = tda827x_probe_version(fe);
777 return fe->ops.tuner_ops.sleep(fe);
780 static struct dvb_tuner_ops tda827xo_tuner_ops = {
782 .name = "Philips TDA827X",
783 .frequency_min = 55000000,
784 .frequency_max = 860000000,
785 .frequency_step = 250000
787 .release = tda827x_release,
788 .init = tda827x_initial_init,
789 .sleep = tda827x_initial_sleep,
790 .set_params = tda827xo_set_params,
791 .set_analog_params = tda827xo_set_analog_params,
792 .get_frequency = tda827x_get_frequency,
793 .get_bandwidth = tda827x_get_bandwidth,
796 static struct dvb_tuner_ops tda827xa_tuner_ops = {
798 .name = "Philips TDA827XA",
799 .frequency_min = 44000000,
800 .frequency_max = 906000000,
801 .frequency_step = 62500
803 .release = tda827x_release,
804 .init = tda827x_init,
805 .sleep = tda827xa_sleep,
806 .set_params = tda827xa_set_params,
807 .set_analog_params = tda827xa_set_analog_params,
808 .get_frequency = tda827x_get_frequency,
809 .get_bandwidth = tda827x_get_bandwidth,
812 static int tda827x_probe_version(struct dvb_frontend *fe)
816 struct tda827x_priv *priv = fe->tuner_priv;
817 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD,
818 .buf = &data, .len = 1 };
820 rc = tuner_transfer(fe, &msg, 1);
823 printk("%s: could not read from tuner at addr: 0x%02x\n",
824 __func__, msg.addr << 1);
827 if ((data & 0x3c) == 0) {
828 dprintk("tda827x tuner found\n");
829 fe->ops.tuner_ops.init = tda827x_init;
830 fe->ops.tuner_ops.sleep = tda827xo_sleep;
832 priv->cfg->agcf = tda827xo_agcf;
834 dprintk("tda827xa tuner found\n");
835 memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops));
837 priv->cfg->agcf = tda827xa_agcf;
842 struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,
843 struct i2c_adapter *i2c,
844 struct tda827x_config *cfg)
846 struct tda827x_priv *priv = NULL;
848 dprintk("%s:\n", __func__);
849 priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL);
853 priv->i2c_addr = addr;
854 priv->i2c_adap = i2c;
856 memcpy(&fe->ops.tuner_ops, &tda827xo_tuner_ops, sizeof(struct dvb_tuner_ops));
857 fe->tuner_priv = priv;
859 dprintk("type set to %s\n", fe->ops.tuner_ops.info.name);
863 EXPORT_SYMBOL_GPL(tda827x_attach);
865 MODULE_DESCRIPTION("DVB TDA827x driver");
866 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
867 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
868 MODULE_LICENSE("GPL");
871 * Overrides for Emacs so that we follow Linus's tabbing style.
872 * ---------------------------------------------------------------------------