1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * (c) 2005 Hartmut Hackmann
5 * (c) 2007 Michael Krufky
8 #include <linux/module.h>
9 #include <linux/slab.h>
10 #include <asm/types.h>
11 #include <linux/dvb/frontend.h>
12 #include <linux/videodev2.h>
17 module_param(debug
, int, 0644);
18 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
20 #define dprintk(args...) \
22 if (debug) printk(KERN_DEBUG "tda827x: " args); \
27 struct i2c_adapter
*i2c_adap
;
28 struct tda827x_config
*cfg
;
37 static void tda827x_set_std(struct dvb_frontend
*fe
,
38 struct analog_parameters
*params
)
40 struct tda827x_priv
*priv
= fe
->tuner_priv
;
44 if (params
->std
& V4L2_STD_MN
) {
48 } else if (params
->std
& V4L2_STD_B
) {
51 } else if (params
->std
& V4L2_STD_GH
) {
54 } else if (params
->std
& V4L2_STD_PAL_I
) {
57 } else if (params
->std
& V4L2_STD_DK
) {
60 } else if (params
->std
& V4L2_STD_SECAM_L
) {
63 } else if (params
->std
& V4L2_STD_SECAM_LC
) {
71 if (params
->mode
== V4L2_TUNER_RADIO
) {
72 priv
->sgIF
= 88; /* if frequency is 5.5 MHz */
73 dprintk("setting tda827x to radio FM\n");
75 dprintk("setting tda827x to system %s\n", mode
);
79 /* ------------------------------------------------------------------ */
91 static const struct tda827x_data tda827x_table
[] = {
92 { .lomax
= 62000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1},
93 { .lomax
= 66000000, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1},
94 { .lomax
= 76000000, .spd
= 3, .bs
= 1, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0},
95 { .lomax
= 84000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0},
96 { .lomax
= 93000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0},
97 { .lomax
= 98000000, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0},
98 { .lomax
= 109000000, .spd
= 3, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
99 { .lomax
= 123000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1},
100 { .lomax
= 133000000, .spd
= 2, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1},
101 { .lomax
= 151000000, .spd
= 2, .bs
= 1, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
102 { .lomax
= 154000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
103 { .lomax
= 181000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 0, .div1p5
= 0},
104 { .lomax
= 185000000, .spd
= 2, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
105 { .lomax
= 217000000, .spd
= 2, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
106 { .lomax
= 244000000, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1},
107 { .lomax
= 265000000, .spd
= 1, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1},
108 { .lomax
= 302000000, .spd
= 1, .bs
= 1, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
109 { .lomax
= 324000000, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
110 { .lomax
= 370000000, .spd
= 1, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
111 { .lomax
= 454000000, .spd
= 1, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
112 { .lomax
= 493000000, .spd
= 0, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1},
113 { .lomax
= 530000000, .spd
= 0, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1},
114 { .lomax
= 554000000, .spd
= 0, .bs
= 1, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
115 { .lomax
= 604000000, .spd
= 0, .bs
= 1, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
116 { .lomax
= 696000000, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
117 { .lomax
= 740000000, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0},
118 { .lomax
= 820000000, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
119 { .lomax
= 865000000, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0},
120 { .lomax
= 0, .spd
= 0, .bs
= 0, .bp
= 0, .cp
= 0, .gc3
= 0, .div1p5
= 0}
123 static int tuner_transfer(struct dvb_frontend
*fe
,
128 struct tda827x_priv
*priv
= fe
->tuner_priv
;
130 if (fe
->ops
.i2c_gate_ctrl
)
131 fe
->ops
.i2c_gate_ctrl(fe
, 1);
132 rc
= i2c_transfer(priv
->i2c_adap
, msg
, size
);
133 if (fe
->ops
.i2c_gate_ctrl
)
134 fe
->ops
.i2c_gate_ctrl(fe
, 0);
136 if (rc
>= 0 && rc
!= size
)
142 static int tda827xo_set_params(struct dvb_frontend
*fe
)
144 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
145 struct tda827x_priv
*priv
= fe
->tuner_priv
;
149 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
150 .buf
= buf
, .len
= sizeof(buf
) };
151 int i
, tuner_freq
, if_freq
;
154 dprintk("%s:\n", __func__
);
155 if (c
->bandwidth_hz
== 0) {
157 } else if (c
->bandwidth_hz
<= 6000000) {
159 } else if (c
->bandwidth_hz
<= 7000000) {
164 tuner_freq
= c
->frequency
;
167 while (tda827x_table
[i
].lomax
< tuner_freq
) {
168 if (tda827x_table
[i
+ 1].lomax
== 0)
173 tuner_freq
+= if_freq
;
175 N
= ((tuner_freq
+ 125000) / 250000) << (tda827x_table
[i
].spd
+ 2);
177 buf
[1] = (N
>>8) | 0x40;
181 buf
[5] = (tda827x_table
[i
].spd
<< 6) + (tda827x_table
[i
].div1p5
<< 5) +
182 (tda827x_table
[i
].bs
<< 3) +
184 buf
[6] = (tda827x_table
[i
].gc3
<< 4) + 0x8f;
194 rc
= tuner_transfer(fe
, &msg
, 1);
199 /* correct CP value */
201 buf
[1] = 0x50 + tda827x_table
[i
].cp
;
204 rc
= tuner_transfer(fe
, &msg
, 1);
208 priv
->frequency
= c
->frequency
;
209 priv
->bandwidth
= c
->bandwidth_hz
;
214 printk(KERN_ERR
"%s: could not write to tuner at addr: 0x%02x\n",
215 __func__
, priv
->i2c_addr
<< 1);
219 static int tda827xo_sleep(struct dvb_frontend
*fe
)
221 struct tda827x_priv
*priv
= fe
->tuner_priv
;
222 static u8 buf
[] = { 0x30, 0xd0 };
223 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
224 .buf
= buf
, .len
= sizeof(buf
) };
226 dprintk("%s:\n", __func__
);
227 tuner_transfer(fe
, &msg
, 1);
229 if (priv
->cfg
&& priv
->cfg
->sleep
)
230 priv
->cfg
->sleep(fe
);
235 /* ------------------------------------------------------------------ */
237 static int tda827xo_set_analog_params(struct dvb_frontend
*fe
,
238 struct analog_parameters
*params
)
240 unsigned char tuner_reg
[8];
241 unsigned char reg2
[2];
244 struct tda827x_priv
*priv
= fe
->tuner_priv
;
245 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0 };
246 unsigned int freq
= params
->frequency
;
248 tda827x_set_std(fe
, params
);
250 if (params
->mode
== V4L2_TUNER_RADIO
)
253 N
= freq
+ priv
->sgIF
;
256 while (tda827x_table
[i
].lomax
< N
* 62500) {
257 if (tda827x_table
[i
+ 1].lomax
== 0)
262 N
= N
<< tda827x_table
[i
].spd
;
265 tuner_reg
[1] = (unsigned char)(N
>>8);
266 tuner_reg
[2] = (unsigned char) N
;
268 tuner_reg
[4] = 0x52 + (priv
->lpsel
<< 5);
269 tuner_reg
[5] = (tda827x_table
[i
].spd
<< 6) +
270 (tda827x_table
[i
].div1p5
<< 5) +
271 (tda827x_table
[i
].bs
<< 3) + tda827x_table
[i
].bp
;
272 tuner_reg
[6] = 0x8f + (tda827x_table
[i
].gc3
<< 4);
277 tuner_transfer(fe
, &msg
, 1);
283 tuner_transfer(fe
, &msg
, 1);
287 tuner_transfer(fe
, &msg
, 1);
290 reg2
[1] = tuner_reg
[4] + 0x80;
291 tuner_transfer(fe
, &msg
, 1);
295 reg2
[1] = tuner_reg
[4] + 4;
296 tuner_transfer(fe
, &msg
, 1);
300 reg2
[1] = tuner_reg
[4];
301 tuner_transfer(fe
, &msg
, 1);
305 reg2
[1] = (tuner_reg
[4] & 0xfc) + tda827x_table
[i
].cp
;
306 tuner_transfer(fe
, &msg
, 1);
310 tuner_transfer(fe
, &msg
, 1);
313 reg2
[1] = 0x08; /* Vsync en */
314 tuner_transfer(fe
, &msg
, 1);
316 priv
->frequency
= params
->frequency
;
321 static void tda827xo_agcf(struct dvb_frontend
*fe
)
323 struct tda827x_priv
*priv
= fe
->tuner_priv
;
324 unsigned char data
[] = { 0x80, 0x0c };
325 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
326 .buf
= data
, .len
= 2};
328 tuner_transfer(fe
, &msg
, 1);
331 /* ------------------------------------------------------------------ */
333 struct tda827xa_data
{
342 static struct tda827xa_data tda827xa_dvbt
[] = {
343 { .lomax
= 56875000, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 1},
344 { .lomax
= 67250000, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
345 { .lomax
= 81250000, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
346 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
347 { .lomax
= 113750000, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1},
348 { .lomax
= 134500000, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
349 { .lomax
= 154000000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
350 { .lomax
= 162500000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
351 { .lomax
= 183000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
352 { .lomax
= 195000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
353 { .lomax
= 227500000, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
354 { .lomax
= 269000000, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
355 { .lomax
= 290000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
356 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
357 { .lomax
= 390000000, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
358 { .lomax
= 455000000, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
359 { .lomax
= 520000000, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
360 { .lomax
= 538000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
361 { .lomax
= 550000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
362 { .lomax
= 620000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
363 { .lomax
= 650000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
364 { .lomax
= 700000000, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
365 { .lomax
= 780000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
366 { .lomax
= 820000000, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
367 { .lomax
= 870000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
368 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0},
369 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
372 static struct tda827xa_data tda827xa_dvbc
[] = {
373 { .lomax
= 50125000, .svco
= 2, .spd
= 4, .scr
= 2, .sbs
= 0, .gc3
= 3},
374 { .lomax
= 58500000, .svco
= 3, .spd
= 4, .scr
= 2, .sbs
= 0, .gc3
= 3},
375 { .lomax
= 69250000, .svco
= 0, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
376 { .lomax
= 83625000, .svco
= 1, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
377 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
378 { .lomax
= 100250000, .svco
= 2, .spd
= 3, .scr
= 2, .sbs
= 1, .gc3
= 1},
379 { .lomax
= 117000000, .svco
= 3, .spd
= 3, .scr
= 2, .sbs
= 1, .gc3
= 1},
380 { .lomax
= 138500000, .svco
= 0, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
381 { .lomax
= 167250000, .svco
= 1, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
382 { .lomax
= 187000000, .svco
= 2, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
383 { .lomax
= 200500000, .svco
= 2, .spd
= 2, .scr
= 2, .sbs
= 2, .gc3
= 1},
384 { .lomax
= 234000000, .svco
= 3, .spd
= 2, .scr
= 2, .sbs
= 2, .gc3
= 3},
385 { .lomax
= 277000000, .svco
= 0, .spd
= 1, .scr
= 2, .sbs
= 2, .gc3
= 3},
386 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 2, .sbs
= 2, .gc3
= 1},
387 { .lomax
= 334500000, .svco
= 1, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 3},
388 { .lomax
= 401000000, .svco
= 2, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 3},
389 { .lomax
= 468000000, .svco
= 3, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 1},
390 { .lomax
= 535000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
391 { .lomax
= 554000000, .svco
= 0, .spd
= 0, .scr
= 2, .sbs
= 3, .gc3
= 1},
392 { .lomax
= 638000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
393 { .lomax
= 669000000, .svco
= 1, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
394 { .lomax
= 720000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
395 { .lomax
= 802000000, .svco
= 2, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
396 { .lomax
= 835000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
397 { .lomax
= 885000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
398 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
399 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
402 static struct tda827xa_data tda827xa_analog
[] = {
403 { .lomax
= 56875000, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 3},
404 { .lomax
= 67250000, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
405 { .lomax
= 81250000, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
406 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
407 { .lomax
= 113750000, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1},
408 { .lomax
= 134500000, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
409 { .lomax
= 154000000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
410 { .lomax
= 162500000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
411 { .lomax
= 183000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
412 { .lomax
= 195000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
413 { .lomax
= 227500000, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 3},
414 { .lomax
= 269000000, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 3},
415 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
416 { .lomax
= 390000000, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3},
417 { .lomax
= 455000000, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3},
418 { .lomax
= 520000000, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
419 { .lomax
= 538000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
420 { .lomax
= 554000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
421 { .lomax
= 620000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
422 { .lomax
= 650000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
423 { .lomax
= 700000000, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
424 { .lomax
= 780000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
425 { .lomax
= 820000000, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
426 { .lomax
= 870000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
427 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0},
428 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
431 static int tda827xa_sleep(struct dvb_frontend
*fe
)
433 struct tda827x_priv
*priv
= fe
->tuner_priv
;
434 static u8 buf
[] = { 0x30, 0x90 };
435 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
436 .buf
= buf
, .len
= sizeof(buf
) };
438 dprintk("%s:\n", __func__
);
440 tuner_transfer(fe
, &msg
, 1);
442 if (priv
->cfg
&& priv
->cfg
->sleep
)
443 priv
->cfg
->sleep(fe
);
448 static void tda827xa_lna_gain(struct dvb_frontend
*fe
, int high
,
449 struct analog_parameters
*params
)
451 struct tda827x_priv
*priv
= fe
->tuner_priv
;
452 unsigned char buf
[] = {0x22, 0x01};
455 struct i2c_msg msg
= { .flags
= 0, .buf
= buf
, .len
= sizeof(buf
) };
457 if (NULL
== priv
->cfg
) {
458 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
461 msg
.addr
= priv
->cfg
->switch_addr
;
462 if (priv
->cfg
->config
) {
464 dprintk("setting LNA to high gain\n");
466 dprintk("setting LNA to low gain\n");
468 switch (priv
->cfg
->config
) {
469 case TDA8290_LNA_OFF
: /* no LNA */
471 case TDA8290_LNA_GP0_HIGH_ON
: /* switch is GPIO 0 of tda8290 */
472 case TDA8290_LNA_GP0_HIGH_OFF
:
473 if (params
== NULL
) {
479 if (params
->std
& V4L2_STD_MN
)
485 fe
->callback(priv
->i2c_adap
->algo_data
,
486 DVB_FRONTEND_COMPONENT_TUNER
,
488 buf
[1] = high
? 0 : 1;
489 if (priv
->cfg
->config
== TDA8290_LNA_GP0_HIGH_OFF
)
490 buf
[1] = high
? 1 : 0;
491 tuner_transfer(fe
, &msg
, 1);
493 case TDA8290_LNA_ON_BRIDGE
: /* switch with GPIO of saa713x */
495 fe
->callback(priv
->i2c_adap
->algo_data
,
496 DVB_FRONTEND_COMPONENT_TUNER
, 0, high
);
501 static int tda827xa_set_params(struct dvb_frontend
*fe
)
503 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
504 struct tda827x_priv
*priv
= fe
->tuner_priv
;
505 struct tda827xa_data
*frequency_map
= tda827xa_dvbt
;
508 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
509 .buf
= buf
, .len
= sizeof(buf
) };
511 int i
, tuner_freq
, if_freq
, rc
;
514 dprintk("%s:\n", __func__
);
516 tda827xa_lna_gain(fe
, 1, NULL
);
519 if (c
->bandwidth_hz
== 0) {
521 } else if (c
->bandwidth_hz
<= 6000000) {
523 } else if (c
->bandwidth_hz
<= 7000000) {
528 tuner_freq
= c
->frequency
;
530 switch (c
->delivery_system
) {
531 case SYS_DVBC_ANNEX_A
:
532 case SYS_DVBC_ANNEX_C
:
533 dprintk("%s select tda827xa_dvbc\n", __func__
);
534 frequency_map
= tda827xa_dvbc
;
541 while (frequency_map
[i
].lomax
< tuner_freq
) {
542 if (frequency_map
[i
+ 1].lomax
== 0)
547 tuner_freq
+= if_freq
;
549 N
= ((tuner_freq
+ 31250) / 62500) << frequency_map
[i
].spd
;
550 buf
[0] = 0; // subaddress
555 buf
[5] = (frequency_map
[i
].spd
<< 5) + (frequency_map
[i
].svco
<< 3) +
556 frequency_map
[i
].sbs
;
557 buf
[6] = 0x4b + (frequency_map
[i
].gc3
<< 4);
563 rc
= tuner_transfer(fe
, &msg
, 1);
571 buf
[4] = 0x59; // lpsel, for 6MHz + 2
573 rc
= tuner_transfer(fe
, &msg
, 1);
580 rc
= tuner_transfer(fe
, &msg
, 1);
585 msg
.flags
= I2C_M_RD
;
586 rc
= tuner_transfer(fe
, &msg
, 1);
592 dprintk("tda8275a AGC2 gain is: %d\n", buf
[1]);
594 tda827xa_lna_gain(fe
, 0, NULL
);
597 rc
= tuner_transfer(fe
, &msg
, 1);
603 buf
[1] = 0x99; // lpsel, for 6MHz + 2
604 rc
= tuner_transfer(fe
, &msg
, 1);
610 rc
= tuner_transfer(fe
, &msg
, 1);
614 /* correct CP value */
616 buf
[1] = 0x10 + frequency_map
[i
].scr
;
617 rc
= tuner_transfer(fe
, &msg
, 1);
623 buf
[1] = 0x39; // lpsel, for 6MHz + 2
624 rc
= tuner_transfer(fe
, &msg
, 1);
631 buf
[1] = 0x4f + (frequency_map
[i
].gc3
<< 4);
632 rc
= tuner_transfer(fe
, &msg
, 1);
636 priv
->frequency
= c
->frequency
;
637 priv
->bandwidth
= c
->bandwidth_hz
;
642 printk(KERN_ERR
"%s: could not write to tuner at addr: 0x%02x\n",
643 __func__
, priv
->i2c_addr
<< 1);
648 static int tda827xa_set_analog_params(struct dvb_frontend
*fe
,
649 struct analog_parameters
*params
)
651 unsigned char tuner_reg
[11];
654 struct tda827x_priv
*priv
= fe
->tuner_priv
;
655 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
656 .buf
= tuner_reg
, .len
= sizeof(tuner_reg
) };
657 unsigned int freq
= params
->frequency
;
659 tda827x_set_std(fe
, params
);
661 tda827xa_lna_gain(fe
, 1, params
);
664 if (params
->mode
== V4L2_TUNER_RADIO
)
667 N
= freq
+ priv
->sgIF
;
670 while (tda827xa_analog
[i
].lomax
< N
* 62500) {
671 if (tda827xa_analog
[i
+ 1].lomax
== 0)
676 N
= N
<< tda827xa_analog
[i
].spd
;
679 tuner_reg
[1] = (unsigned char)(N
>>8);
680 tuner_reg
[2] = (unsigned char) N
;
683 tuner_reg
[5] = (tda827xa_analog
[i
].spd
<< 5) +
684 (tda827xa_analog
[i
].svco
<< 3) +
685 tda827xa_analog
[i
].sbs
;
686 tuner_reg
[6] = 0x8b + (tda827xa_analog
[i
].gc3
<< 4);
690 tuner_reg
[10] = 0x00;
692 tuner_transfer(fe
, &msg
, 1);
698 tuner_reg
[4] = 0x99 + (priv
->lpsel
<< 1);
700 tuner_transfer(fe
, &msg
, 1);
705 tuner_transfer(fe
, &msg
, 1);
708 tuner_reg
[1] = 0x10 + tda827xa_analog
[i
].scr
;
709 tuner_transfer(fe
, &msg
, 1);
711 msg
.flags
= I2C_M_RD
;
712 tuner_transfer(fe
, &msg
, 1);
715 dprintk("AGC2 gain is: %d\n", tuner_reg
[1]);
716 if (tuner_reg
[1] < 1)
717 tda827xa_lna_gain(fe
, 0, params
);
722 tuner_transfer(fe
, &msg
, 1);
726 tuner_reg
[1] = 0x8f + (tda827xa_analog
[i
].gc3
<< 4);
727 tuner_transfer(fe
, &msg
, 1);
731 tuner_transfer(fe
, &msg
, 1);
735 tuner_transfer(fe
, &msg
, 1);
738 tuner_reg
[1] = 0x19 + (priv
->lpsel
<< 1);
739 tuner_transfer(fe
, &msg
, 1);
741 priv
->frequency
= params
->frequency
;
746 static void tda827xa_agcf(struct dvb_frontend
*fe
)
748 struct tda827x_priv
*priv
= fe
->tuner_priv
;
749 unsigned char data
[] = {0x80, 0x2c};
750 struct i2c_msg msg
= {.addr
= priv
->i2c_addr
, .flags
= 0,
751 .buf
= data
, .len
= 2};
752 tuner_transfer(fe
, &msg
, 1);
755 /* ------------------------------------------------------------------ */
757 static void tda827x_release(struct dvb_frontend
*fe
)
759 kfree(fe
->tuner_priv
);
760 fe
->tuner_priv
= NULL
;
763 static int tda827x_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
765 struct tda827x_priv
*priv
= fe
->tuner_priv
;
766 *frequency
= priv
->frequency
;
770 static int tda827x_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
772 struct tda827x_priv
*priv
= fe
->tuner_priv
;
773 *bandwidth
= priv
->bandwidth
;
777 static int tda827x_init(struct dvb_frontend
*fe
)
779 struct tda827x_priv
*priv
= fe
->tuner_priv
;
780 dprintk("%s:\n", __func__
);
781 if (priv
->cfg
&& priv
->cfg
->init
)
787 static int tda827x_probe_version(struct dvb_frontend
*fe
);
789 static int tda827x_initial_init(struct dvb_frontend
*fe
)
792 ret
= tda827x_probe_version(fe
);
795 return fe
->ops
.tuner_ops
.init(fe
);
798 static int tda827x_initial_sleep(struct dvb_frontend
*fe
)
801 ret
= tda827x_probe_version(fe
);
804 return fe
->ops
.tuner_ops
.sleep(fe
);
807 static const struct dvb_tuner_ops tda827xo_tuner_ops
= {
809 .name
= "Philips TDA827X",
810 .frequency_min_hz
= 55 * MHz
,
811 .frequency_max_hz
= 860 * MHz
,
812 .frequency_step_hz
= 250 * kHz
814 .release
= tda827x_release
,
815 .init
= tda827x_initial_init
,
816 .sleep
= tda827x_initial_sleep
,
817 .set_params
= tda827xo_set_params
,
818 .set_analog_params
= tda827xo_set_analog_params
,
819 .get_frequency
= tda827x_get_frequency
,
820 .get_bandwidth
= tda827x_get_bandwidth
,
823 static const struct dvb_tuner_ops tda827xa_tuner_ops
= {
825 .name
= "Philips TDA827XA",
826 .frequency_min_hz
= 44 * MHz
,
827 .frequency_max_hz
= 906 * MHz
,
828 .frequency_step_hz
= 62500
830 .release
= tda827x_release
,
831 .init
= tda827x_init
,
832 .sleep
= tda827xa_sleep
,
833 .set_params
= tda827xa_set_params
,
834 .set_analog_params
= tda827xa_set_analog_params
,
835 .get_frequency
= tda827x_get_frequency
,
836 .get_bandwidth
= tda827x_get_bandwidth
,
839 static int tda827x_probe_version(struct dvb_frontend
*fe
)
843 struct tda827x_priv
*priv
= fe
->tuner_priv
;
844 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= I2C_M_RD
,
845 .buf
= &data
, .len
= 1 };
847 rc
= tuner_transfer(fe
, &msg
, 1);
850 printk("%s: could not read from tuner at addr: 0x%02x\n",
851 __func__
, msg
.addr
<< 1);
854 if ((data
& 0x3c) == 0) {
855 dprintk("tda827x tuner found\n");
856 fe
->ops
.tuner_ops
.init
= tda827x_init
;
857 fe
->ops
.tuner_ops
.sleep
= tda827xo_sleep
;
859 priv
->cfg
->agcf
= tda827xo_agcf
;
861 dprintk("tda827xa tuner found\n");
862 memcpy(&fe
->ops
.tuner_ops
, &tda827xa_tuner_ops
, sizeof(struct dvb_tuner_ops
));
864 priv
->cfg
->agcf
= tda827xa_agcf
;
869 struct dvb_frontend
*tda827x_attach(struct dvb_frontend
*fe
, int addr
,
870 struct i2c_adapter
*i2c
,
871 struct tda827x_config
*cfg
)
873 struct tda827x_priv
*priv
= NULL
;
875 dprintk("%s:\n", __func__
);
876 priv
= kzalloc(sizeof(struct tda827x_priv
), GFP_KERNEL
);
880 priv
->i2c_addr
= addr
;
881 priv
->i2c_adap
= i2c
;
883 memcpy(&fe
->ops
.tuner_ops
, &tda827xo_tuner_ops
, sizeof(struct dvb_tuner_ops
));
884 fe
->tuner_priv
= priv
;
886 dprintk("type set to %s\n", fe
->ops
.tuner_ops
.info
.name
);
890 EXPORT_SYMBOL_GPL(tda827x_attach
);
892 MODULE_DESCRIPTION("DVB TDA827x driver");
893 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
894 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
895 MODULE_LICENSE("GPL");