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 tda827xo_set_params(struct dvb_frontend *fe,
136 struct dvb_frontend_parameters *params)
138 struct tda827x_priv *priv = fe->tuner_priv;
141 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
142 .buf = buf, .len = sizeof(buf) };
143 int i, tuner_freq, if_freq;
146 dprintk("%s:\n", __func__);
147 switch (params->u.ofdm.bandwidth) {
148 case BANDWIDTH_6_MHZ:
151 case BANDWIDTH_7_MHZ:
154 default: /* 8 MHz or Auto */
158 tuner_freq = params->frequency + if_freq;
161 while (tda827x_table[i].lomax < tuner_freq) {
162 if (tda827x_table[i + 1].lomax == 0)
167 N = ((tuner_freq + 125000) / 250000) << (tda827x_table[i].spd + 2);
169 buf[1] = (N>>8) | 0x40;
173 buf[5] = (tda827x_table[i].spd << 6) + (tda827x_table[i].div1p5 << 5) +
174 (tda827x_table[i].bs << 3) +
176 buf[6] = (tda827x_table[i].gc3 << 4) + 0x8f;
186 if (fe->ops.i2c_gate_ctrl)
187 fe->ops.i2c_gate_ctrl(fe, 1);
188 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
189 printk("%s: could not write to tuner at addr: 0x%02x\n",
190 __func__, priv->i2c_addr << 1);
194 /* correct CP value */
196 buf[1] = 0x50 + tda827x_table[i].cp;
199 if (fe->ops.i2c_gate_ctrl)
200 fe->ops.i2c_gate_ctrl(fe, 1);
201 i2c_transfer(priv->i2c_adap, &msg, 1);
203 priv->frequency = params->frequency;
204 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
209 static int tda827xo_sleep(struct dvb_frontend *fe)
211 struct tda827x_priv *priv = fe->tuner_priv;
212 static u8 buf[] = { 0x30, 0xd0 };
213 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
214 .buf = buf, .len = sizeof(buf) };
216 dprintk("%s:\n", __func__);
217 if (fe->ops.i2c_gate_ctrl)
218 fe->ops.i2c_gate_ctrl(fe, 1);
219 i2c_transfer(priv->i2c_adap, &msg, 1);
221 if (priv->cfg && priv->cfg->sleep)
222 priv->cfg->sleep(fe);
227 /* ------------------------------------------------------------------ */
229 static int tda827xo_set_analog_params(struct dvb_frontend *fe,
230 struct analog_parameters *params)
232 unsigned char tuner_reg[8];
233 unsigned char reg2[2];
236 struct tda827x_priv *priv = fe->tuner_priv;
237 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0 };
238 unsigned int freq = params->frequency;
240 tda827x_set_std(fe, params);
242 if (params->mode == V4L2_TUNER_RADIO)
245 N = freq + priv->sgIF;
248 while (tda827x_table[i].lomax < N * 62500) {
249 if (tda827x_table[i + 1].lomax == 0)
254 N = N << tda827x_table[i].spd;
257 tuner_reg[1] = (unsigned char)(N>>8);
258 tuner_reg[2] = (unsigned char) N;
260 tuner_reg[4] = 0x52 + (priv->lpsel << 5);
261 tuner_reg[5] = (tda827x_table[i].spd << 6) +
262 (tda827x_table[i].div1p5 << 5) +
263 (tda827x_table[i].bs << 3) + tda827x_table[i].bp;
264 tuner_reg[6] = 0x8f + (tda827x_table[i].gc3 << 4);
269 i2c_transfer(priv->i2c_adap, &msg, 1);
275 i2c_transfer(priv->i2c_adap, &msg, 1);
279 i2c_transfer(priv->i2c_adap, &msg, 1);
282 reg2[1] = tuner_reg[4] + 0x80;
283 i2c_transfer(priv->i2c_adap, &msg, 1);
287 reg2[1] = tuner_reg[4] + 4;
288 i2c_transfer(priv->i2c_adap, &msg, 1);
292 reg2[1] = tuner_reg[4];
293 i2c_transfer(priv->i2c_adap, &msg, 1);
297 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_table[i].cp;
298 i2c_transfer(priv->i2c_adap, &msg, 1);
302 i2c_transfer(priv->i2c_adap, &msg, 1);
305 reg2[1] = 0x08; /* Vsync en */
306 i2c_transfer(priv->i2c_adap, &msg, 1);
308 priv->frequency = params->frequency;
313 static void tda827xo_agcf(struct dvb_frontend *fe)
315 struct tda827x_priv *priv = fe->tuner_priv;
316 unsigned char data[] = { 0x80, 0x0c };
317 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
318 .buf = data, .len = 2};
320 i2c_transfer(priv->i2c_adap, &msg, 1);
323 /* ------------------------------------------------------------------ */
325 struct tda827xa_data {
334 static const struct tda827xa_data tda827xa_dvbt[] = {
335 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
336 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
337 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
338 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
339 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
340 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
341 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
342 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
343 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
344 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
345 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
346 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
347 { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
348 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
349 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
350 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
351 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
352 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
353 { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
354 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
355 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
356 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
357 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
358 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
359 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
360 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
361 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
364 static struct tda827xa_data tda827xa_analog[] = {
365 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3},
366 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
367 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
368 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
369 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
370 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
371 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
372 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
373 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
374 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
375 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3},
376 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3},
377 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
378 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
379 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
380 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
381 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
382 { .lomax = 554000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
383 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
384 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
385 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
386 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
387 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
388 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
389 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
390 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
393 static int tda827xa_sleep(struct dvb_frontend *fe)
395 struct tda827x_priv *priv = fe->tuner_priv;
396 static u8 buf[] = { 0x30, 0x90 };
397 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
398 .buf = buf, .len = sizeof(buf) };
400 dprintk("%s:\n", __func__);
401 if (fe->ops.i2c_gate_ctrl)
402 fe->ops.i2c_gate_ctrl(fe, 1);
404 i2c_transfer(priv->i2c_adap, &msg, 1);
406 if (fe->ops.i2c_gate_ctrl)
407 fe->ops.i2c_gate_ctrl(fe, 0);
409 if (priv->cfg && priv->cfg->sleep)
410 priv->cfg->sleep(fe);
415 static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
416 struct analog_parameters *params)
418 struct tda827x_priv *priv = fe->tuner_priv;
419 unsigned char buf[] = {0x22, 0x01};
422 struct i2c_msg msg = { .flags = 0, .buf = buf, .len = sizeof(buf) };
424 if (NULL == priv->cfg) {
425 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
428 msg.addr = priv->cfg->switch_addr;
429 if (priv->cfg->config) {
431 dprintk("setting LNA to high gain\n");
433 dprintk("setting LNA to low gain\n");
435 switch (priv->cfg->config) {
438 case 1: /* switch is GPIO 0 of tda8290 */
440 if (params == NULL) {
446 if (params->std & V4L2_STD_MN)
452 fe->callback(priv->i2c_adap->algo_data,
453 DVB_FRONTEND_COMPONENT_TUNER,
455 buf[1] = high ? 0 : 1;
456 if (priv->cfg->config == 2)
457 buf[1] = high ? 1 : 0;
458 i2c_transfer(priv->i2c_adap, &msg, 1);
460 case 3: /* switch with GPIO of saa713x */
462 fe->callback(priv->i2c_adap->algo_data,
463 DVB_FRONTEND_COMPONENT_TUNER, 0, high);
468 static int tda827xa_set_params(struct dvb_frontend *fe,
469 struct dvb_frontend_parameters *params)
471 struct tda827x_priv *priv = fe->tuner_priv;
474 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
475 .buf = buf, .len = sizeof(buf) };
477 int i, tuner_freq, if_freq;
480 dprintk("%s:\n", __func__);
482 tda827xa_lna_gain(fe, 1, NULL);
485 switch (params->u.ofdm.bandwidth) {
486 case BANDWIDTH_6_MHZ:
489 case BANDWIDTH_7_MHZ:
492 default: /* 8 MHz or Auto */
496 tuner_freq = params->frequency + if_freq;
499 while (tda827xa_dvbt[i].lomax < tuner_freq) {
500 if(tda827xa_dvbt[i + 1].lomax == 0)
505 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
506 buf[0] = 0; // subaddress
511 buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
512 tda827xa_dvbt[i].sbs;
513 buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
519 if (fe->ops.i2c_gate_ctrl)
520 fe->ops.i2c_gate_ctrl(fe, 1);
521 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
522 printk("%s: could not write to tuner at addr: 0x%02x\n",
523 __func__, priv->i2c_addr << 1);
530 buf[4] = 0x59; // lpsel, for 6MHz + 2
532 if (fe->ops.i2c_gate_ctrl)
533 fe->ops.i2c_gate_ctrl(fe, 1);
534 i2c_transfer(priv->i2c_adap, &msg, 1);
539 if (fe->ops.i2c_gate_ctrl)
540 fe->ops.i2c_gate_ctrl(fe, 1);
541 i2c_transfer(priv->i2c_adap, &msg, 1);
544 msg.flags = I2C_M_RD;
545 if (fe->ops.i2c_gate_ctrl)
546 fe->ops.i2c_gate_ctrl(fe, 1);
547 i2c_transfer(priv->i2c_adap, &msg, 1);
551 dprintk("tda8275a AGC2 gain is: %d\n", buf[1]);
553 tda827xa_lna_gain(fe, 0, NULL);
556 if (fe->ops.i2c_gate_ctrl)
557 fe->ops.i2c_gate_ctrl(fe, 1);
558 i2c_transfer(priv->i2c_adap, &msg, 1);
562 buf[1] = 0x99; // lpsel, for 6MHz + 2
563 if (fe->ops.i2c_gate_ctrl)
564 fe->ops.i2c_gate_ctrl(fe, 1);
565 i2c_transfer(priv->i2c_adap, &msg, 1);
569 if (fe->ops.i2c_gate_ctrl)
570 fe->ops.i2c_gate_ctrl(fe, 1);
571 i2c_transfer(priv->i2c_adap, &msg, 1);
573 /* correct CP value */
575 buf[1] = 0x10 + tda827xa_dvbt[i].scr;
576 if (fe->ops.i2c_gate_ctrl)
577 fe->ops.i2c_gate_ctrl(fe, 1);
578 i2c_transfer(priv->i2c_adap, &msg, 1);
582 buf[1] = 0x39; // lpsel, for 6MHz + 2
583 if (fe->ops.i2c_gate_ctrl)
584 fe->ops.i2c_gate_ctrl(fe, 1);
585 i2c_transfer(priv->i2c_adap, &msg, 1);
590 buf[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
591 if (fe->ops.i2c_gate_ctrl)
592 fe->ops.i2c_gate_ctrl(fe, 1);
593 i2c_transfer(priv->i2c_adap, &msg, 1);
595 priv->frequency = params->frequency;
596 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
602 static int tda827xa_set_analog_params(struct dvb_frontend *fe,
603 struct analog_parameters *params)
605 unsigned char tuner_reg[11];
608 struct tda827x_priv *priv = fe->tuner_priv;
609 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
610 .buf = tuner_reg, .len = sizeof(tuner_reg) };
611 unsigned int freq = params->frequency;
613 tda827x_set_std(fe, params);
615 tda827xa_lna_gain(fe, 1, params);
618 if (params->mode == V4L2_TUNER_RADIO)
621 N = freq + priv->sgIF;
624 while (tda827xa_analog[i].lomax < N * 62500) {
625 if (tda827xa_analog[i + 1].lomax == 0)
630 N = N << tda827xa_analog[i].spd;
633 tuner_reg[1] = (unsigned char)(N>>8);
634 tuner_reg[2] = (unsigned char) N;
637 tuner_reg[5] = (tda827xa_analog[i].spd << 5) +
638 (tda827xa_analog[i].svco << 3) +
639 tda827xa_analog[i].sbs;
640 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
644 tuner_reg[10] = 0x00;
646 i2c_transfer(priv->i2c_adap, &msg, 1);
652 tuner_reg[4] = 0x99 + (priv->lpsel << 1);
654 i2c_transfer(priv->i2c_adap, &msg, 1);
659 i2c_transfer(priv->i2c_adap, &msg, 1);
662 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
663 i2c_transfer(priv->i2c_adap, &msg, 1);
665 msg.flags = I2C_M_RD;
666 i2c_transfer(priv->i2c_adap, &msg, 1);
669 dprintk("AGC2 gain is: %d\n", tuner_reg[1]);
670 if (tuner_reg[1] < 1)
671 tda827xa_lna_gain(fe, 0, params);
676 i2c_transfer(priv->i2c_adap, &msg, 1);
680 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
681 i2c_transfer(priv->i2c_adap, &msg, 1);
685 i2c_transfer(priv->i2c_adap, &msg, 1);
689 i2c_transfer(priv->i2c_adap, &msg, 1);
692 tuner_reg[1] = 0x19 + (priv->lpsel << 1);
693 i2c_transfer(priv->i2c_adap, &msg, 1);
695 priv->frequency = params->frequency;
700 static void tda827xa_agcf(struct dvb_frontend *fe)
702 struct tda827x_priv *priv = fe->tuner_priv;
703 unsigned char data[] = {0x80, 0x2c};
704 struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,
705 .buf = data, .len = 2};
706 i2c_transfer(priv->i2c_adap, &msg, 1);
709 /* ------------------------------------------------------------------ */
711 static int tda827x_release(struct dvb_frontend *fe)
713 kfree(fe->tuner_priv);
714 fe->tuner_priv = NULL;
718 static int tda827x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
720 struct tda827x_priv *priv = fe->tuner_priv;
721 *frequency = priv->frequency;
725 static int tda827x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
727 struct tda827x_priv *priv = fe->tuner_priv;
728 *bandwidth = priv->bandwidth;
732 static int tda827x_init(struct dvb_frontend *fe)
734 struct tda827x_priv *priv = fe->tuner_priv;
735 dprintk("%s:\n", __func__);
736 if (priv->cfg && priv->cfg->init)
742 static int tda827x_probe_version(struct dvb_frontend *fe);
744 static int tda827x_initial_init(struct dvb_frontend *fe)
747 ret = tda827x_probe_version(fe);
750 return fe->ops.tuner_ops.init(fe);
753 static int tda827x_initial_sleep(struct dvb_frontend *fe)
756 ret = tda827x_probe_version(fe);
759 return fe->ops.tuner_ops.sleep(fe);
762 static struct dvb_tuner_ops tda827xo_tuner_ops = {
764 .name = "Philips TDA827X",
765 .frequency_min = 55000000,
766 .frequency_max = 860000000,
767 .frequency_step = 250000
769 .release = tda827x_release,
770 .init = tda827x_initial_init,
771 .sleep = tda827x_initial_sleep,
772 .set_params = tda827xo_set_params,
773 .set_analog_params = tda827xo_set_analog_params,
774 .get_frequency = tda827x_get_frequency,
775 .get_bandwidth = tda827x_get_bandwidth,
778 static struct dvb_tuner_ops tda827xa_tuner_ops = {
780 .name = "Philips TDA827XA",
781 .frequency_min = 44000000,
782 .frequency_max = 906000000,
783 .frequency_step = 62500
785 .release = tda827x_release,
786 .init = tda827x_init,
787 .sleep = tda827xa_sleep,
788 .set_params = tda827xa_set_params,
789 .set_analog_params = tda827xa_set_analog_params,
790 .get_frequency = tda827x_get_frequency,
791 .get_bandwidth = tda827x_get_bandwidth,
794 static int tda827x_probe_version(struct dvb_frontend *fe)
796 struct tda827x_priv *priv = fe->tuner_priv;
797 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD,
798 .buf = &data, .len = 1 };
799 if (fe->ops.i2c_gate_ctrl)
800 fe->ops.i2c_gate_ctrl(fe, 1);
801 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
802 printk("%s: could not read from tuner at addr: 0x%02x\n",
803 __func__, msg.addr << 1);
806 if ((data & 0x3c) == 0) {
807 dprintk("tda827x tuner found\n");
808 fe->ops.tuner_ops.init = tda827x_init;
809 fe->ops.tuner_ops.sleep = tda827xo_sleep;
811 priv->cfg->agcf = tda827xo_agcf;
813 dprintk("tda827xa tuner found\n");
814 memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops));
816 priv->cfg->agcf = tda827xa_agcf;
821 struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,
822 struct i2c_adapter *i2c,
823 struct tda827x_config *cfg)
825 struct tda827x_priv *priv = NULL;
827 dprintk("%s:\n", __func__);
828 priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL);
832 priv->i2c_addr = addr;
833 priv->i2c_adap = i2c;
835 memcpy(&fe->ops.tuner_ops, &tda827xo_tuner_ops, sizeof(struct dvb_tuner_ops));
836 fe->tuner_priv = priv;
838 dprintk("type set to %s\n", fe->ops.tuner_ops.info.name);
842 EXPORT_SYMBOL_GPL(tda827x_attach);
844 MODULE_DESCRIPTION("DVB TDA827x driver");
845 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
846 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
847 MODULE_LICENSE("GPL");
850 * Overrides for Emacs so that we follow Linus's tabbing style.
851 * ---------------------------------------------------------------------------