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.
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <asm/types.h>
20 #include <linux/dvb/frontend.h>
21 #include <linux/videodev2.h>
26 module_param(debug
, int, 0644);
27 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
29 #define dprintk(args...) \
31 if (debug) printk(KERN_DEBUG "tda827x: " args); \
36 struct i2c_adapter
*i2c_adap
;
37 struct tda827x_config
*cfg
;
46 static void tda827x_set_std(struct dvb_frontend
*fe
,
47 struct analog_parameters
*params
)
49 struct tda827x_priv
*priv
= fe
->tuner_priv
;
53 if (params
->std
& V4L2_STD_MN
) {
57 } else if (params
->std
& V4L2_STD_B
) {
60 } else if (params
->std
& V4L2_STD_GH
) {
63 } else if (params
->std
& V4L2_STD_PAL_I
) {
66 } else if (params
->std
& V4L2_STD_DK
) {
69 } else if (params
->std
& V4L2_STD_SECAM_L
) {
72 } else if (params
->std
& V4L2_STD_SECAM_LC
) {
80 if (params
->mode
== V4L2_TUNER_RADIO
) {
81 priv
->sgIF
= 88; /* if frequency is 5.5 MHz */
82 dprintk("setting tda827x to radio FM\n");
84 dprintk("setting tda827x to system %s\n", mode
);
88 /* ------------------------------------------------------------------ */
100 static const struct tda827x_data tda827x_table
[] = {
101 { .lomax
= 62000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1},
102 { .lomax
= 66000000, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1},
103 { .lomax
= 76000000, .spd
= 3, .bs
= 1, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0},
104 { .lomax
= 84000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0},
105 { .lomax
= 93000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0},
106 { .lomax
= 98000000, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0},
107 { .lomax
= 109000000, .spd
= 3, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
108 { .lomax
= 123000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1},
109 { .lomax
= 133000000, .spd
= 2, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1},
110 { .lomax
= 151000000, .spd
= 2, .bs
= 1, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
111 { .lomax
= 154000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
112 { .lomax
= 181000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 0, .div1p5
= 0},
113 { .lomax
= 185000000, .spd
= 2, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
114 { .lomax
= 217000000, .spd
= 2, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
115 { .lomax
= 244000000, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1},
116 { .lomax
= 265000000, .spd
= 1, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1},
117 { .lomax
= 302000000, .spd
= 1, .bs
= 1, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
118 { .lomax
= 324000000, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
119 { .lomax
= 370000000, .spd
= 1, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
120 { .lomax
= 454000000, .spd
= 1, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
121 { .lomax
= 493000000, .spd
= 0, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1},
122 { .lomax
= 530000000, .spd
= 0, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1},
123 { .lomax
= 554000000, .spd
= 0, .bs
= 1, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
124 { .lomax
= 604000000, .spd
= 0, .bs
= 1, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
125 { .lomax
= 696000000, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
126 { .lomax
= 740000000, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0},
127 { .lomax
= 820000000, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
128 { .lomax
= 865000000, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0},
129 { .lomax
= 0, .spd
= 0, .bs
= 0, .bp
= 0, .cp
= 0, .gc3
= 0, .div1p5
= 0}
132 static int tuner_transfer(struct dvb_frontend
*fe
,
137 struct tda827x_priv
*priv
= fe
->tuner_priv
;
139 if (fe
->ops
.i2c_gate_ctrl
)
140 fe
->ops
.i2c_gate_ctrl(fe
, 1);
141 rc
= i2c_transfer(priv
->i2c_adap
, msg
, size
);
142 if (fe
->ops
.i2c_gate_ctrl
)
143 fe
->ops
.i2c_gate_ctrl(fe
, 0);
145 if (rc
>= 0 && rc
!= size
)
151 static int tda827xo_set_params(struct dvb_frontend
*fe
)
153 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
154 struct tda827x_priv
*priv
= fe
->tuner_priv
;
158 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
159 .buf
= buf
, .len
= sizeof(buf
) };
160 int i
, tuner_freq
, if_freq
;
163 dprintk("%s:\n", __func__
);
164 if (c
->bandwidth_hz
== 0) {
166 } else if (c
->bandwidth_hz
<= 6000000) {
168 } else if (c
->bandwidth_hz
<= 7000000) {
173 tuner_freq
= c
->frequency
;
176 while (tda827x_table
[i
].lomax
< tuner_freq
) {
177 if (tda827x_table
[i
+ 1].lomax
== 0)
182 tuner_freq
+= if_freq
;
184 N
= ((tuner_freq
+ 125000) / 250000) << (tda827x_table
[i
].spd
+ 2);
186 buf
[1] = (N
>>8) | 0x40;
190 buf
[5] = (tda827x_table
[i
].spd
<< 6) + (tda827x_table
[i
].div1p5
<< 5) +
191 (tda827x_table
[i
].bs
<< 3) +
193 buf
[6] = (tda827x_table
[i
].gc3
<< 4) + 0x8f;
203 rc
= tuner_transfer(fe
, &msg
, 1);
208 /* correct CP value */
210 buf
[1] = 0x50 + tda827x_table
[i
].cp
;
213 rc
= tuner_transfer(fe
, &msg
, 1);
217 priv
->frequency
= c
->frequency
;
218 priv
->bandwidth
= c
->bandwidth_hz
;
223 printk(KERN_ERR
"%s: could not write to tuner at addr: 0x%02x\n",
224 __func__
, priv
->i2c_addr
<< 1);
228 static int tda827xo_sleep(struct dvb_frontend
*fe
)
230 struct tda827x_priv
*priv
= fe
->tuner_priv
;
231 static u8 buf
[] = { 0x30, 0xd0 };
232 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
233 .buf
= buf
, .len
= sizeof(buf
) };
235 dprintk("%s:\n", __func__
);
236 tuner_transfer(fe
, &msg
, 1);
238 if (priv
->cfg
&& priv
->cfg
->sleep
)
239 priv
->cfg
->sleep(fe
);
244 /* ------------------------------------------------------------------ */
246 static int tda827xo_set_analog_params(struct dvb_frontend
*fe
,
247 struct analog_parameters
*params
)
249 unsigned char tuner_reg
[8];
250 unsigned char reg2
[2];
253 struct tda827x_priv
*priv
= fe
->tuner_priv
;
254 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0 };
255 unsigned int freq
= params
->frequency
;
257 tda827x_set_std(fe
, params
);
259 if (params
->mode
== V4L2_TUNER_RADIO
)
262 N
= freq
+ priv
->sgIF
;
265 while (tda827x_table
[i
].lomax
< N
* 62500) {
266 if (tda827x_table
[i
+ 1].lomax
== 0)
271 N
= N
<< tda827x_table
[i
].spd
;
274 tuner_reg
[1] = (unsigned char)(N
>>8);
275 tuner_reg
[2] = (unsigned char) N
;
277 tuner_reg
[4] = 0x52 + (priv
->lpsel
<< 5);
278 tuner_reg
[5] = (tda827x_table
[i
].spd
<< 6) +
279 (tda827x_table
[i
].div1p5
<< 5) +
280 (tda827x_table
[i
].bs
<< 3) + tda827x_table
[i
].bp
;
281 tuner_reg
[6] = 0x8f + (tda827x_table
[i
].gc3
<< 4);
286 tuner_transfer(fe
, &msg
, 1);
292 tuner_transfer(fe
, &msg
, 1);
296 tuner_transfer(fe
, &msg
, 1);
299 reg2
[1] = tuner_reg
[4] + 0x80;
300 tuner_transfer(fe
, &msg
, 1);
304 reg2
[1] = tuner_reg
[4] + 4;
305 tuner_transfer(fe
, &msg
, 1);
309 reg2
[1] = tuner_reg
[4];
310 tuner_transfer(fe
, &msg
, 1);
314 reg2
[1] = (tuner_reg
[4] & 0xfc) + tda827x_table
[i
].cp
;
315 tuner_transfer(fe
, &msg
, 1);
319 tuner_transfer(fe
, &msg
, 1);
322 reg2
[1] = 0x08; /* Vsync en */
323 tuner_transfer(fe
, &msg
, 1);
325 priv
->frequency
= params
->frequency
;
330 static void tda827xo_agcf(struct dvb_frontend
*fe
)
332 struct tda827x_priv
*priv
= fe
->tuner_priv
;
333 unsigned char data
[] = { 0x80, 0x0c };
334 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
335 .buf
= data
, .len
= 2};
337 tuner_transfer(fe
, &msg
, 1);
340 /* ------------------------------------------------------------------ */
342 struct tda827xa_data
{
351 static struct tda827xa_data tda827xa_dvbt
[] = {
352 { .lomax
= 56875000, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 1},
353 { .lomax
= 67250000, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
354 { .lomax
= 81250000, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
355 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
356 { .lomax
= 113750000, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1},
357 { .lomax
= 134500000, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
358 { .lomax
= 154000000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
359 { .lomax
= 162500000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
360 { .lomax
= 183000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
361 { .lomax
= 195000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
362 { .lomax
= 227500000, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
363 { .lomax
= 269000000, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
364 { .lomax
= 290000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
365 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
366 { .lomax
= 390000000, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
367 { .lomax
= 455000000, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
368 { .lomax
= 520000000, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
369 { .lomax
= 538000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
370 { .lomax
= 550000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
371 { .lomax
= 620000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
372 { .lomax
= 650000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
373 { .lomax
= 700000000, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
374 { .lomax
= 780000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
375 { .lomax
= 820000000, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
376 { .lomax
= 870000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
377 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0},
378 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
381 static struct tda827xa_data tda827xa_dvbc
[] = {
382 { .lomax
= 50125000, .svco
= 2, .spd
= 4, .scr
= 2, .sbs
= 0, .gc3
= 3},
383 { .lomax
= 58500000, .svco
= 3, .spd
= 4, .scr
= 2, .sbs
= 0, .gc3
= 3},
384 { .lomax
= 69250000, .svco
= 0, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
385 { .lomax
= 83625000, .svco
= 1, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
386 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
387 { .lomax
= 100250000, .svco
= 2, .spd
= 3, .scr
= 2, .sbs
= 1, .gc3
= 1},
388 { .lomax
= 117000000, .svco
= 3, .spd
= 3, .scr
= 2, .sbs
= 1, .gc3
= 1},
389 { .lomax
= 138500000, .svco
= 0, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
390 { .lomax
= 167250000, .svco
= 1, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
391 { .lomax
= 187000000, .svco
= 2, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
392 { .lomax
= 200500000, .svco
= 2, .spd
= 2, .scr
= 2, .sbs
= 2, .gc3
= 1},
393 { .lomax
= 234000000, .svco
= 3, .spd
= 2, .scr
= 2, .sbs
= 2, .gc3
= 3},
394 { .lomax
= 277000000, .svco
= 0, .spd
= 1, .scr
= 2, .sbs
= 2, .gc3
= 3},
395 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 2, .sbs
= 2, .gc3
= 1},
396 { .lomax
= 334500000, .svco
= 1, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 3},
397 { .lomax
= 401000000, .svco
= 2, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 3},
398 { .lomax
= 468000000, .svco
= 3, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 1},
399 { .lomax
= 535000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
400 { .lomax
= 554000000, .svco
= 0, .spd
= 0, .scr
= 2, .sbs
= 3, .gc3
= 1},
401 { .lomax
= 638000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
402 { .lomax
= 669000000, .svco
= 1, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
403 { .lomax
= 720000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
404 { .lomax
= 802000000, .svco
= 2, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
405 { .lomax
= 835000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
406 { .lomax
= 885000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
407 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
408 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
411 static struct tda827xa_data tda827xa_analog
[] = {
412 { .lomax
= 56875000, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 3},
413 { .lomax
= 67250000, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
414 { .lomax
= 81250000, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
415 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
416 { .lomax
= 113750000, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1},
417 { .lomax
= 134500000, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
418 { .lomax
= 154000000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
419 { .lomax
= 162500000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
420 { .lomax
= 183000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
421 { .lomax
= 195000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
422 { .lomax
= 227500000, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 3},
423 { .lomax
= 269000000, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 3},
424 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
425 { .lomax
= 390000000, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3},
426 { .lomax
= 455000000, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3},
427 { .lomax
= 520000000, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
428 { .lomax
= 538000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
429 { .lomax
= 554000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
430 { .lomax
= 620000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
431 { .lomax
= 650000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
432 { .lomax
= 700000000, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
433 { .lomax
= 780000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
434 { .lomax
= 820000000, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
435 { .lomax
= 870000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
436 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0},
437 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
440 static int tda827xa_sleep(struct dvb_frontend
*fe
)
442 struct tda827x_priv
*priv
= fe
->tuner_priv
;
443 static u8 buf
[] = { 0x30, 0x90 };
444 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
445 .buf
= buf
, .len
= sizeof(buf
) };
447 dprintk("%s:\n", __func__
);
449 tuner_transfer(fe
, &msg
, 1);
451 if (priv
->cfg
&& priv
->cfg
->sleep
)
452 priv
->cfg
->sleep(fe
);
457 static void tda827xa_lna_gain(struct dvb_frontend
*fe
, int high
,
458 struct analog_parameters
*params
)
460 struct tda827x_priv
*priv
= fe
->tuner_priv
;
461 unsigned char buf
[] = {0x22, 0x01};
464 struct i2c_msg msg
= { .flags
= 0, .buf
= buf
, .len
= sizeof(buf
) };
466 if (NULL
== priv
->cfg
) {
467 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
470 msg
.addr
= priv
->cfg
->switch_addr
;
471 if (priv
->cfg
->config
) {
473 dprintk("setting LNA to high gain\n");
475 dprintk("setting LNA to low gain\n");
477 switch (priv
->cfg
->config
) {
478 case TDA8290_LNA_OFF
: /* no LNA */
480 case TDA8290_LNA_GP0_HIGH_ON
: /* switch is GPIO 0 of tda8290 */
481 case TDA8290_LNA_GP0_HIGH_OFF
:
482 if (params
== NULL
) {
488 if (params
->std
& V4L2_STD_MN
)
494 fe
->callback(priv
->i2c_adap
->algo_data
,
495 DVB_FRONTEND_COMPONENT_TUNER
,
497 buf
[1] = high
? 0 : 1;
498 if (priv
->cfg
->config
== TDA8290_LNA_GP0_HIGH_OFF
)
499 buf
[1] = high
? 1 : 0;
500 tuner_transfer(fe
, &msg
, 1);
502 case TDA8290_LNA_ON_BRIDGE
: /* switch with GPIO of saa713x */
504 fe
->callback(priv
->i2c_adap
->algo_data
,
505 DVB_FRONTEND_COMPONENT_TUNER
, 0, high
);
510 static int tda827xa_set_params(struct dvb_frontend
*fe
)
512 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
513 struct tda827x_priv
*priv
= fe
->tuner_priv
;
514 struct tda827xa_data
*frequency_map
= tda827xa_dvbt
;
517 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
518 .buf
= buf
, .len
= sizeof(buf
) };
520 int i
, tuner_freq
, if_freq
, rc
;
523 dprintk("%s:\n", __func__
);
525 tda827xa_lna_gain(fe
, 1, NULL
);
528 if (c
->bandwidth_hz
== 0) {
530 } else if (c
->bandwidth_hz
<= 6000000) {
532 } else if (c
->bandwidth_hz
<= 7000000) {
537 tuner_freq
= c
->frequency
;
539 switch (c
->delivery_system
) {
540 case SYS_DVBC_ANNEX_A
:
541 case SYS_DVBC_ANNEX_C
:
542 dprintk("%s select tda827xa_dvbc\n", __func__
);
543 frequency_map
= tda827xa_dvbc
;
550 while (frequency_map
[i
].lomax
< tuner_freq
) {
551 if (frequency_map
[i
+ 1].lomax
== 0)
556 tuner_freq
+= if_freq
;
558 N
= ((tuner_freq
+ 31250) / 62500) << frequency_map
[i
].spd
;
559 buf
[0] = 0; // subaddress
564 buf
[5] = (frequency_map
[i
].spd
<< 5) + (frequency_map
[i
].svco
<< 3) +
565 frequency_map
[i
].sbs
;
566 buf
[6] = 0x4b + (frequency_map
[i
].gc3
<< 4);
572 rc
= tuner_transfer(fe
, &msg
, 1);
580 buf
[4] = 0x59; // lpsel, for 6MHz + 2
582 rc
= tuner_transfer(fe
, &msg
, 1);
589 rc
= tuner_transfer(fe
, &msg
, 1);
594 msg
.flags
= I2C_M_RD
;
595 rc
= tuner_transfer(fe
, &msg
, 1);
601 dprintk("tda8275a AGC2 gain is: %d\n", buf
[1]);
603 tda827xa_lna_gain(fe
, 0, NULL
);
606 rc
= tuner_transfer(fe
, &msg
, 1);
612 buf
[1] = 0x99; // lpsel, for 6MHz + 2
613 rc
= tuner_transfer(fe
, &msg
, 1);
619 rc
= tuner_transfer(fe
, &msg
, 1);
623 /* correct CP value */
625 buf
[1] = 0x10 + frequency_map
[i
].scr
;
626 rc
= tuner_transfer(fe
, &msg
, 1);
632 buf
[1] = 0x39; // lpsel, for 6MHz + 2
633 rc
= tuner_transfer(fe
, &msg
, 1);
640 buf
[1] = 0x4f + (frequency_map
[i
].gc3
<< 4);
641 rc
= tuner_transfer(fe
, &msg
, 1);
645 priv
->frequency
= c
->frequency
;
646 priv
->bandwidth
= c
->bandwidth_hz
;
651 printk(KERN_ERR
"%s: could not write to tuner at addr: 0x%02x\n",
652 __func__
, priv
->i2c_addr
<< 1);
657 static int tda827xa_set_analog_params(struct dvb_frontend
*fe
,
658 struct analog_parameters
*params
)
660 unsigned char tuner_reg
[11];
663 struct tda827x_priv
*priv
= fe
->tuner_priv
;
664 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
665 .buf
= tuner_reg
, .len
= sizeof(tuner_reg
) };
666 unsigned int freq
= params
->frequency
;
668 tda827x_set_std(fe
, params
);
670 tda827xa_lna_gain(fe
, 1, params
);
673 if (params
->mode
== V4L2_TUNER_RADIO
)
676 N
= freq
+ priv
->sgIF
;
679 while (tda827xa_analog
[i
].lomax
< N
* 62500) {
680 if (tda827xa_analog
[i
+ 1].lomax
== 0)
685 N
= N
<< tda827xa_analog
[i
].spd
;
688 tuner_reg
[1] = (unsigned char)(N
>>8);
689 tuner_reg
[2] = (unsigned char) N
;
692 tuner_reg
[5] = (tda827xa_analog
[i
].spd
<< 5) +
693 (tda827xa_analog
[i
].svco
<< 3) +
694 tda827xa_analog
[i
].sbs
;
695 tuner_reg
[6] = 0x8b + (tda827xa_analog
[i
].gc3
<< 4);
699 tuner_reg
[10] = 0x00;
701 tuner_transfer(fe
, &msg
, 1);
707 tuner_reg
[4] = 0x99 + (priv
->lpsel
<< 1);
709 tuner_transfer(fe
, &msg
, 1);
714 tuner_transfer(fe
, &msg
, 1);
717 tuner_reg
[1] = 0x10 + tda827xa_analog
[i
].scr
;
718 tuner_transfer(fe
, &msg
, 1);
720 msg
.flags
= I2C_M_RD
;
721 tuner_transfer(fe
, &msg
, 1);
724 dprintk("AGC2 gain is: %d\n", tuner_reg
[1]);
725 if (tuner_reg
[1] < 1)
726 tda827xa_lna_gain(fe
, 0, params
);
731 tuner_transfer(fe
, &msg
, 1);
735 tuner_reg
[1] = 0x8f + (tda827xa_analog
[i
].gc3
<< 4);
736 tuner_transfer(fe
, &msg
, 1);
740 tuner_transfer(fe
, &msg
, 1);
744 tuner_transfer(fe
, &msg
, 1);
747 tuner_reg
[1] = 0x19 + (priv
->lpsel
<< 1);
748 tuner_transfer(fe
, &msg
, 1);
750 priv
->frequency
= params
->frequency
;
755 static void tda827xa_agcf(struct dvb_frontend
*fe
)
757 struct tda827x_priv
*priv
= fe
->tuner_priv
;
758 unsigned char data
[] = {0x80, 0x2c};
759 struct i2c_msg msg
= {.addr
= priv
->i2c_addr
, .flags
= 0,
760 .buf
= data
, .len
= 2};
761 tuner_transfer(fe
, &msg
, 1);
764 /* ------------------------------------------------------------------ */
766 static void tda827x_release(struct dvb_frontend
*fe
)
768 kfree(fe
->tuner_priv
);
769 fe
->tuner_priv
= NULL
;
772 static int tda827x_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
774 struct tda827x_priv
*priv
= fe
->tuner_priv
;
775 *frequency
= priv
->frequency
;
779 static int tda827x_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
781 struct tda827x_priv
*priv
= fe
->tuner_priv
;
782 *bandwidth
= priv
->bandwidth
;
786 static int tda827x_init(struct dvb_frontend
*fe
)
788 struct tda827x_priv
*priv
= fe
->tuner_priv
;
789 dprintk("%s:\n", __func__
);
790 if (priv
->cfg
&& priv
->cfg
->init
)
796 static int tda827x_probe_version(struct dvb_frontend
*fe
);
798 static int tda827x_initial_init(struct dvb_frontend
*fe
)
801 ret
= tda827x_probe_version(fe
);
804 return fe
->ops
.tuner_ops
.init(fe
);
807 static int tda827x_initial_sleep(struct dvb_frontend
*fe
)
810 ret
= tda827x_probe_version(fe
);
813 return fe
->ops
.tuner_ops
.sleep(fe
);
816 static const struct dvb_tuner_ops tda827xo_tuner_ops
= {
818 .name
= "Philips TDA827X",
819 .frequency_min
= 55000000,
820 .frequency_max
= 860000000,
821 .frequency_step
= 250000
823 .release
= tda827x_release
,
824 .init
= tda827x_initial_init
,
825 .sleep
= tda827x_initial_sleep
,
826 .set_params
= tda827xo_set_params
,
827 .set_analog_params
= tda827xo_set_analog_params
,
828 .get_frequency
= tda827x_get_frequency
,
829 .get_bandwidth
= tda827x_get_bandwidth
,
832 static const struct dvb_tuner_ops tda827xa_tuner_ops
= {
834 .name
= "Philips TDA827XA",
835 .frequency_min
= 44000000,
836 .frequency_max
= 906000000,
837 .frequency_step
= 62500
839 .release
= tda827x_release
,
840 .init
= tda827x_init
,
841 .sleep
= tda827xa_sleep
,
842 .set_params
= tda827xa_set_params
,
843 .set_analog_params
= tda827xa_set_analog_params
,
844 .get_frequency
= tda827x_get_frequency
,
845 .get_bandwidth
= tda827x_get_bandwidth
,
848 static int tda827x_probe_version(struct dvb_frontend
*fe
)
852 struct tda827x_priv
*priv
= fe
->tuner_priv
;
853 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= I2C_M_RD
,
854 .buf
= &data
, .len
= 1 };
856 rc
= tuner_transfer(fe
, &msg
, 1);
859 printk("%s: could not read from tuner at addr: 0x%02x\n",
860 __func__
, msg
.addr
<< 1);
863 if ((data
& 0x3c) == 0) {
864 dprintk("tda827x tuner found\n");
865 fe
->ops
.tuner_ops
.init
= tda827x_init
;
866 fe
->ops
.tuner_ops
.sleep
= tda827xo_sleep
;
868 priv
->cfg
->agcf
= tda827xo_agcf
;
870 dprintk("tda827xa tuner found\n");
871 memcpy(&fe
->ops
.tuner_ops
, &tda827xa_tuner_ops
, sizeof(struct dvb_tuner_ops
));
873 priv
->cfg
->agcf
= tda827xa_agcf
;
878 struct dvb_frontend
*tda827x_attach(struct dvb_frontend
*fe
, int addr
,
879 struct i2c_adapter
*i2c
,
880 struct tda827x_config
*cfg
)
882 struct tda827x_priv
*priv
= NULL
;
884 dprintk("%s:\n", __func__
);
885 priv
= kzalloc(sizeof(struct tda827x_priv
), GFP_KERNEL
);
889 priv
->i2c_addr
= addr
;
890 priv
->i2c_adap
= i2c
;
892 memcpy(&fe
->ops
.tuner_ops
, &tda827xo_tuner_ops
, sizeof(struct dvb_tuner_ops
));
893 fe
->tuner_priv
= priv
;
895 dprintk("type set to %s\n", fe
->ops
.tuner_ops
.info
.name
);
899 EXPORT_SYMBOL_GPL(tda827x_attach
);
901 MODULE_DESCRIPTION("DVB TDA827x driver");
902 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
903 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
904 MODULE_LICENSE("GPL");