2 * descriptions + helper functions for simple dvb plls.
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
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 <linux/dvb/frontend.h>
23 #include <asm/types.h>
27 /* ----------------------------------------------------------- */
30 /* Set AGC TOP value to 103 dBuV:
32 0x40 = 250 uA charge pump (irrelevant)
33 0x18 = Aux Byte to follow
34 0x06 = 64.5 kHz divider (irrelevant)
35 0x01 = Disable Vt (aka sleep)
37 0x00 = AGC Time constant 2s Iagc = 300 nA (vs 0x80 = 9 nA)
38 0x50 = AGC Take over point = 103 dBuV */
39 static u8 tua603x_agc103
[] = { 2, 0x80|0x40|0x18|0x06|0x01, 0x00|0x50 };
41 struct dvb_pll_desc dvb_pll_thomson_dtt7579
= {
42 .name
= "Thomson dtt7579",
47 { 0, 36166667, 166666, 0xb4, 0x03 }, /* go sleep */
48 { 443250000, 36166667, 166666, 0xb4, 0x02 },
49 { 542000000, 36166667, 166666, 0xb4, 0x08 },
50 { 771000000, 36166667, 166666, 0xbc, 0x08 },
51 { 999999999, 36166667, 166666, 0xf4, 0x08 },
54 EXPORT_SYMBOL(dvb_pll_thomson_dtt7579
);
56 struct dvb_pll_desc dvb_pll_thomson_dtt7610
= {
57 .name
= "Thomson dtt7610",
62 { 157250000, 44000000, 62500, 0x8e, 0x39 },
63 { 454000000, 44000000, 62500, 0x8e, 0x3a },
64 { 999999999, 44000000, 62500, 0x8e, 0x3c },
67 EXPORT_SYMBOL(dvb_pll_thomson_dtt7610
);
69 static void thomson_dtt759x_bw(u8
*buf
, u32 freq
, int bandwidth
)
71 if (BANDWIDTH_7_MHZ
== bandwidth
)
75 struct dvb_pll_desc dvb_pll_thomson_dtt759x
= {
76 .name
= "Thomson dtt759x",
79 .setbw
= thomson_dtt759x_bw
,
82 { 0, 36166667, 166666, 0x84, 0x03 },
83 { 264000000, 36166667, 166666, 0xb4, 0x02 },
84 { 470000000, 36166667, 166666, 0xbc, 0x02 },
85 { 735000000, 36166667, 166666, 0xbc, 0x08 },
86 { 835000000, 36166667, 166666, 0xf4, 0x08 },
87 { 999999999, 36166667, 166666, 0xfc, 0x08 },
90 EXPORT_SYMBOL(dvb_pll_thomson_dtt759x
);
92 struct dvb_pll_desc dvb_pll_lg_z201
= {
98 { 0, 36166667, 166666, 0xbc, 0x03 },
99 { 157500000, 36166667, 166666, 0xbc, 0x01 },
100 { 443250000, 36166667, 166666, 0xbc, 0x02 },
101 { 542000000, 36166667, 166666, 0xbc, 0x04 },
102 { 830000000, 36166667, 166666, 0xf4, 0x04 },
103 { 999999999, 36166667, 166666, 0xfc, 0x04 },
106 EXPORT_SYMBOL(dvb_pll_lg_z201
);
108 struct dvb_pll_desc dvb_pll_microtune_4042
= {
109 .name
= "Microtune 4042 FI5",
114 { 162000000, 44000000, 62500, 0x8e, 0xa1 },
115 { 457000000, 44000000, 62500, 0x8e, 0x91 },
116 { 999999999, 44000000, 62500, 0x8e, 0x31 },
119 EXPORT_SYMBOL(dvb_pll_microtune_4042
);
121 struct dvb_pll_desc dvb_pll_thomson_dtt761x
= {
122 /* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */
123 .name
= "Thomson dtt761x",
127 .initdata
= tua603x_agc103
,
129 { 147000000, 44000000, 62500, 0x8e, 0x39 },
130 { 417000000, 44000000, 62500, 0x8e, 0x3a },
131 { 999999999, 44000000, 62500, 0x8e, 0x3c },
134 EXPORT_SYMBOL(dvb_pll_thomson_dtt761x
);
136 struct dvb_pll_desc dvb_pll_unknown_1
= {
137 .name
= "unknown 1", /* used by dntv live dvb-t */
142 { 150000000, 36166667, 166666, 0xb4, 0x01 },
143 { 173000000, 36166667, 166666, 0xbc, 0x01 },
144 { 250000000, 36166667, 166666, 0xb4, 0x02 },
145 { 400000000, 36166667, 166666, 0xbc, 0x02 },
146 { 420000000, 36166667, 166666, 0xf4, 0x02 },
147 { 470000000, 36166667, 166666, 0xfc, 0x02 },
148 { 600000000, 36166667, 166666, 0xbc, 0x08 },
149 { 730000000, 36166667, 166666, 0xf4, 0x08 },
150 { 999999999, 36166667, 166666, 0xfc, 0x08 },
153 EXPORT_SYMBOL(dvb_pll_unknown_1
);
155 /* Infineon TUA6010XS
156 * used in Thomson Cable Tuner
158 struct dvb_pll_desc dvb_pll_tua6010xs
= {
159 .name
= "Infineon TUA6010XS",
164 { 115750000, 36125000, 62500, 0x8e, 0x03 },
165 { 403250000, 36125000, 62500, 0x8e, 0x06 },
166 { 999999999, 36125000, 62500, 0x8e, 0x85 },
169 EXPORT_SYMBOL(dvb_pll_tua6010xs
);
171 /* Panasonic env57h1xd5 (some Philips PLL ?) */
172 struct dvb_pll_desc dvb_pll_env57h1xd5
= {
173 .name
= "Panasonic ENV57H1XD5",
178 { 153000000, 36291666, 166666, 0xc2, 0x41 },
179 { 470000000, 36291666, 166666, 0xc2, 0x42 },
180 { 526000000, 36291666, 166666, 0xc2, 0x84 },
181 { 999999999, 36291666, 166666, 0xc2, 0xa4 },
184 EXPORT_SYMBOL(dvb_pll_env57h1xd5
);
186 /* Philips TDA6650/TDA6651
187 * used in Panasonic ENV77H11D5
189 static void tda665x_bw(u8
*buf
, u32 freq
, int bandwidth
)
191 if (bandwidth
== BANDWIDTH_8_MHZ
)
195 struct dvb_pll_desc dvb_pll_tda665x
= {
196 .name
= "Philips TDA6650/TDA6651",
202 { 93834000, 36249333, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
203 { 123834000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
204 { 161000000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
205 { 163834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
206 { 253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
207 { 383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
208 { 443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
209 { 444000000, 36249333, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
210 { 583834000, 36249333, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ },
211 { 793834000, 36249333, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ },
212 { 444834000, 36249333, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
213 { 861000000, 36249333, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ },
216 EXPORT_SYMBOL(dvb_pll_tda665x
);
219 * used in LG TDTP E102P
221 static void tua6034_bw(u8
*buf
, u32 freq
, int bandwidth
)
223 if (BANDWIDTH_7_MHZ
!= bandwidth
)
227 struct dvb_pll_desc dvb_pll_tua6034
= {
228 .name
= "Infineon TUA6034",
234 { 174500000, 36166667, 62500, 0xce, 0x01 },
235 { 230000000, 36166667, 62500, 0xce, 0x02 },
236 { 999999999, 36166667, 62500, 0xce, 0x04 },
239 EXPORT_SYMBOL(dvb_pll_tua6034
);
242 * used in LG TDVS-H061F, LG TDVS-H062F and LG TDVS-H064F
244 struct dvb_pll_desc dvb_pll_lg_tdvs_h06xf
= {
245 .name
= "LG TDVS-H06xF",
248 .initdata
= tua603x_agc103
,
251 { 165000000, 44000000, 62500, 0xce, 0x01 },
252 { 450000000, 44000000, 62500, 0xce, 0x02 },
253 { 999999999, 44000000, 62500, 0xce, 0x04 },
256 EXPORT_SYMBOL(dvb_pll_lg_tdvs_h06xf
);
259 * used in Medion Hybrid PCMCIA card and USB Box
261 static void fmd1216me_bw(u8
*buf
, u32 freq
, int bandwidth
)
263 if (bandwidth
== BANDWIDTH_8_MHZ
&& freq
>= 158870000)
267 struct dvb_pll_desc dvb_pll_fmd1216me
= {
268 .name
= "Philips FMD1216ME",
271 .setbw
= fmd1216me_bw
,
274 { 143870000, 36213333, 166667, 0xbc, 0x41 },
275 { 158870000, 36213333, 166667, 0xf4, 0x41 },
276 { 329870000, 36213333, 166667, 0xbc, 0x42 },
277 { 441870000, 36213333, 166667, 0xf4, 0x42 },
278 { 625870000, 36213333, 166667, 0xbc, 0x44 },
279 { 803870000, 36213333, 166667, 0xf4, 0x44 },
280 { 999999999, 36213333, 166667, 0xfc, 0x44 },
283 EXPORT_SYMBOL(dvb_pll_fmd1216me
);
286 * used in Nebula-Cards and USB boxes
288 static void tded4_bw(u8
*buf
, u32 freq
, int bandwidth
)
290 if (bandwidth
== BANDWIDTH_8_MHZ
)
294 struct dvb_pll_desc dvb_pll_tded4
= {
295 .name
= "ALPS TDED4",
301 { 153000000, 36166667, 166667, 0x85, 0x01 },
302 { 470000000, 36166667, 166667, 0x85, 0x02 },
303 { 823000000, 36166667, 166667, 0x85, 0x08 },
304 { 999999999, 36166667, 166667, 0x85, 0x88 },
307 EXPORT_SYMBOL(dvb_pll_tded4
);
310 * used in AverTVHD MCE A180
312 struct dvb_pll_desc dvb_pll_tdhu2
= {
313 .name
= "ALPS TDHU2",
318 { 162000000, 44000000, 62500, 0x85, 0x01 },
319 { 426000000, 44000000, 62500, 0x85, 0x02 },
320 { 782000000, 44000000, 62500, 0x85, 0x08 },
321 { 999999999, 44000000, 62500, 0x85, 0x88 },
324 EXPORT_SYMBOL(dvb_pll_tdhu2
);
327 * used in ATI HDTV Wonder
329 struct dvb_pll_desc dvb_pll_tuv1236d
= {
330 .name
= "Philips TUV1236D",
335 { 157250000, 44000000, 62500, 0xc6, 0x41 },
336 { 454000000, 44000000, 62500, 0xc6, 0x42 },
337 { 999999999, 44000000, 62500, 0xc6, 0x44 },
340 EXPORT_SYMBOL(dvb_pll_tuv1236d
);
342 /* Samsung TBMV30111IN / TBMV30712IN1
343 * used in Air2PC ATSC - 2nd generation (nxt2002)
345 struct dvb_pll_desc dvb_pll_samsung_tbmv
= {
346 .name
= "Samsung TBMV30111IN / TBMV30712IN1",
351 { 172000000, 44000000, 166666, 0xb4, 0x01 },
352 { 214000000, 44000000, 166666, 0xb4, 0x02 },
353 { 467000000, 44000000, 166666, 0xbc, 0x02 },
354 { 721000000, 44000000, 166666, 0xbc, 0x08 },
355 { 841000000, 44000000, 166666, 0xf4, 0x08 },
356 { 999999999, 44000000, 166666, 0xfc, 0x02 },
359 EXPORT_SYMBOL(dvb_pll_samsung_tbmv
);
362 * Philips SD1878 Tuner.
364 struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261
= {
365 .name
= "Philips SD1878",
370 { 1250000, 499, 500, 0xc4, 0x00},
371 { 1550000, 499, 500, 0xc4, 0x40},
372 { 2050000, 499, 500, 0xc4, 0x80},
373 { 2150000, 499, 500, 0xc4, 0xc0},
376 EXPORT_SYMBOL(dvb_pll_philips_sd1878_tda8261
);
379 * Philips TD1316 Tuner.
381 static void td1316_bw(u8
*buf
, u32 freq
, int bandwidth
)
386 if (freq
< 161000000)
388 else if (freq
< 444000000)
395 /* setup PLL filter */
396 if (bandwidth
== BANDWIDTH_8_MHZ
)
400 struct dvb_pll_desc dvb_pll_philips_td1316
= {
401 .name
= "Philips TD1316",
407 { 93834000, 36166000, 166666, 0xca, 0x60},
408 { 123834000, 36166000, 166666, 0xca, 0xa0},
409 { 163834000, 36166000, 166666, 0xca, 0xc0},
410 { 253834000, 36166000, 166666, 0xca, 0x60},
411 { 383834000, 36166000, 166666, 0xca, 0xa0},
412 { 443834000, 36166000, 166666, 0xca, 0xc0},
413 { 583834000, 36166000, 166666, 0xca, 0x60},
414 { 793834000, 36166000, 166666, 0xca, 0xa0},
415 { 858834000, 36166000, 166666, 0xca, 0xe0},
418 EXPORT_SYMBOL(dvb_pll_philips_td1316
);
420 /* FE6600 used on DViCO Hybrid */
421 struct dvb_pll_desc dvb_pll_thomson_fe6600
= {
422 .name
= "Thomson FE6600",
427 { 250000000, 36213333, 166667, 0xb4, 0x12 },
428 { 455000000, 36213333, 166667, 0xfe, 0x11 },
429 { 775500000, 36213333, 166667, 0xbc, 0x18 },
430 { 999999999, 36213333, 166667, 0xf4, 0x18 },
433 EXPORT_SYMBOL(dvb_pll_thomson_fe6600
);
435 struct dvb_pll_priv
{
438 struct i2c_adapter
*i2c
;
440 /* the PLL descriptor */
441 struct dvb_pll_desc
*pll_desc
;
443 /* cached frequency/bandwidth */
448 /* ----------------------------------------------------------- */
451 static int debug
= 0;
452 module_param(debug
, int, 0644);
453 MODULE_PARM_DESC(debug
, "enable verbose debug messages");
455 int dvb_pll_configure(struct dvb_pll_desc
*desc
, u8
*buf
,
456 u32 freq
, int bandwidth
)
461 if (freq
!= 0 && (freq
< desc
->min
|| freq
> desc
->max
))
464 for (i
= 0; i
< desc
->count
; i
++) {
465 if (freq
> desc
->entries
[i
].limit
)
470 printk("pll: %s: freq=%d bw=%d | i=%d/%d\n",
471 desc
->name
, freq
, bandwidth
, i
, desc
->count
);
472 if (i
== desc
->count
)
475 div
= (freq
+ desc
->entries
[i
].offset
) / desc
->entries
[i
].stepsize
;
478 buf
[2] = desc
->entries
[i
].config
;
479 buf
[3] = desc
->entries
[i
].cb
;
482 desc
->setbw(buf
, freq
, bandwidth
);
485 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
486 desc
->name
, div
, buf
[0], buf
[1], buf
[2], buf
[3]);
488 // calculate the frequency we set it to
489 return (div
* desc
->entries
[i
].stepsize
) - desc
->entries
[i
].offset
;
491 EXPORT_SYMBOL(dvb_pll_configure
);
493 static int dvb_pll_release(struct dvb_frontend
*fe
)
495 kfree(fe
->tuner_priv
);
496 fe
->tuner_priv
= NULL
;
500 static int dvb_pll_sleep(struct dvb_frontend
*fe
)
502 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
505 { .addr
= priv
->pll_i2c_address
, .flags
= 0,
506 .buf
= buf
, .len
= sizeof(buf
) };
510 if (priv
->i2c
== NULL
)
513 for (i
= 0; i
< priv
->pll_desc
->count
; i
++) {
514 if (priv
->pll_desc
->entries
[i
].limit
== 0)
517 if (i
== priv
->pll_desc
->count
)
522 buf
[2] = priv
->pll_desc
->entries
[i
].config
;
523 buf
[3] = priv
->pll_desc
->entries
[i
].cb
;
525 if (fe
->ops
.i2c_gate_ctrl
)
526 fe
->ops
.i2c_gate_ctrl(fe
, 1);
527 if ((result
= i2c_transfer(priv
->i2c
, &msg
, 1)) != 1) {
534 static int dvb_pll_set_params(struct dvb_frontend
*fe
,
535 struct dvb_frontend_parameters
*params
)
537 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
540 { .addr
= priv
->pll_i2c_address
, .flags
= 0,
541 .buf
= buf
, .len
= sizeof(buf
) };
543 u32 bandwidth
= 0, frequency
= 0;
545 if (priv
->i2c
== NULL
)
548 // DVBT bandwidth only just now
549 if (fe
->ops
.info
.type
== FE_OFDM
) {
550 bandwidth
= params
->u
.ofdm
.bandwidth
;
553 if ((result
= dvb_pll_configure(priv
->pll_desc
, buf
,
554 params
->frequency
, bandwidth
)) < 0)
559 if (fe
->ops
.i2c_gate_ctrl
)
560 fe
->ops
.i2c_gate_ctrl(fe
, 1);
561 if ((result
= i2c_transfer(priv
->i2c
, &msg
, 1)) != 1) {
565 priv
->frequency
= frequency
;
566 priv
->bandwidth
= bandwidth
;
571 static int dvb_pll_calc_regs(struct dvb_frontend
*fe
,
572 struct dvb_frontend_parameters
*params
,
573 u8
*buf
, int buf_len
)
575 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
577 u32 bandwidth
= 0, frequency
= 0;
582 // DVBT bandwidth only just now
583 if (fe
->ops
.info
.type
== FE_OFDM
) {
584 bandwidth
= params
->u
.ofdm
.bandwidth
;
587 if ((result
= dvb_pll_configure(priv
->pll_desc
, buf
+1,
588 params
->frequency
, bandwidth
)) < 0)
593 buf
[0] = priv
->pll_i2c_address
;
595 priv
->frequency
= frequency
;
596 priv
->bandwidth
= bandwidth
;
601 static int dvb_pll_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
603 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
604 *frequency
= priv
->frequency
;
608 static int dvb_pll_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
610 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
611 *bandwidth
= priv
->bandwidth
;
615 static int dvb_pll_init(struct dvb_frontend
*fe
)
617 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
619 if (priv
->i2c
== NULL
)
622 if (priv
->pll_desc
->initdata
) {
623 struct i2c_msg msg
= { .flags
= 0,
624 .addr
= priv
->pll_i2c_address
,
625 .buf
= priv
->pll_desc
->initdata
+ 1,
626 .len
= priv
->pll_desc
->initdata
[0] };
629 if (fe
->ops
.i2c_gate_ctrl
)
630 fe
->ops
.i2c_gate_ctrl(fe
, 1);
631 if ((result
= i2c_transfer(priv
->i2c
, &msg
, 1)) != 1) {
636 /* Shouldn't be called when initdata is NULL, maybe BUG()? */
640 static struct dvb_tuner_ops dvb_pll_tuner_ops
= {
641 .release
= dvb_pll_release
,
642 .sleep
= dvb_pll_sleep
,
643 .set_params
= dvb_pll_set_params
,
644 .calc_regs
= dvb_pll_calc_regs
,
645 .get_frequency
= dvb_pll_get_frequency
,
646 .get_bandwidth
= dvb_pll_get_bandwidth
,
649 struct dvb_frontend
*dvb_pll_attach(struct dvb_frontend
*fe
, int pll_addr
,
650 struct i2c_adapter
*i2c
,
651 struct dvb_pll_desc
*desc
)
654 struct i2c_msg msg
= { .addr
= pll_addr
, .flags
= I2C_M_RD
,
655 .buf
= b1
, .len
= 1 };
656 struct dvb_pll_priv
*priv
= NULL
;
660 if (fe
->ops
.i2c_gate_ctrl
)
661 fe
->ops
.i2c_gate_ctrl(fe
, 1);
663 ret
= i2c_transfer (i2c
, &msg
, 1);
666 if (fe
->ops
.i2c_gate_ctrl
)
667 fe
->ops
.i2c_gate_ctrl(fe
, 0);
670 priv
= kzalloc(sizeof(struct dvb_pll_priv
), GFP_KERNEL
);
674 priv
->pll_i2c_address
= pll_addr
;
676 priv
->pll_desc
= desc
;
678 memcpy(&fe
->ops
.tuner_ops
, &dvb_pll_tuner_ops
,
679 sizeof(struct dvb_tuner_ops
));
681 strncpy(fe
->ops
.tuner_ops
.info
.name
, desc
->name
,
682 sizeof(fe
->ops
.tuner_ops
.info
.name
));
683 fe
->ops
.tuner_ops
.info
.frequency_min
= desc
->min
;
684 fe
->ops
.tuner_ops
.info
.frequency_min
= desc
->max
;
686 fe
->ops
.tuner_ops
.init
= dvb_pll_init
;
688 fe
->tuner_priv
= priv
;
691 EXPORT_SYMBOL(dvb_pll_attach
);
693 MODULE_DESCRIPTION("dvb pll library");
694 MODULE_AUTHOR("Gerd Knorr");
695 MODULE_LICENSE("GPL");