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",
46 .sleepdata
= (u8
[]){ 2, 0xb4, 0x03 },
49 { 443250000, 166667, 0xb4, 0x02 },
50 { 542000000, 166667, 0xb4, 0x08 },
51 { 771000000, 166667, 0xbc, 0x08 },
52 { 999999999, 166667, 0xf4, 0x08 },
55 EXPORT_SYMBOL(dvb_pll_thomson_dtt7579
);
57 struct dvb_pll_desc dvb_pll_thomson_dtt7610
= {
58 .name
= "Thomson dtt7610",
64 { 157250000, 62500, 0x8e, 0x39 },
65 { 454000000, 62500, 0x8e, 0x3a },
66 { 999999999, 62500, 0x8e, 0x3c },
69 EXPORT_SYMBOL(dvb_pll_thomson_dtt7610
);
71 static void thomson_dtt759x_bw(u8
*buf
, u32 freq
, int bandwidth
)
73 if (BANDWIDTH_7_MHZ
== bandwidth
)
77 struct dvb_pll_desc dvb_pll_thomson_dtt759x
= {
78 .name
= "Thomson dtt759x",
81 .setbw
= thomson_dtt759x_bw
,
83 .sleepdata
= (u8
[]){ 2, 0x84, 0x03 },
86 { 264000000, 166667, 0xb4, 0x02 },
87 { 470000000, 166667, 0xbc, 0x02 },
88 { 735000000, 166667, 0xbc, 0x08 },
89 { 835000000, 166667, 0xf4, 0x08 },
90 { 999999999, 166667, 0xfc, 0x08 },
93 EXPORT_SYMBOL(dvb_pll_thomson_dtt759x
);
95 struct dvb_pll_desc dvb_pll_lg_z201
= {
100 .sleepdata
= (u8
[]){ 2, 0xbc, 0x03 },
103 { 157500000, 166667, 0xbc, 0x01 },
104 { 443250000, 166667, 0xbc, 0x02 },
105 { 542000000, 166667, 0xbc, 0x04 },
106 { 830000000, 166667, 0xf4, 0x04 },
107 { 999999999, 166667, 0xfc, 0x04 },
110 EXPORT_SYMBOL(dvb_pll_lg_z201
);
112 struct dvb_pll_desc dvb_pll_microtune_4042
= {
113 .name
= "Microtune 4042 FI5",
119 { 162000000, 62500, 0x8e, 0xa1 },
120 { 457000000, 62500, 0x8e, 0x91 },
121 { 999999999, 62500, 0x8e, 0x31 },
124 EXPORT_SYMBOL(dvb_pll_microtune_4042
);
126 struct dvb_pll_desc dvb_pll_thomson_dtt761x
= {
127 /* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */
128 .name
= "Thomson dtt761x",
133 .initdata
= tua603x_agc103
,
135 { 147000000, 62500, 0x8e, 0x39 },
136 { 417000000, 62500, 0x8e, 0x3a },
137 { 999999999, 62500, 0x8e, 0x3c },
140 EXPORT_SYMBOL(dvb_pll_thomson_dtt761x
);
142 struct dvb_pll_desc dvb_pll_unknown_1
= {
143 .name
= "unknown 1", /* used by dntv live dvb-t */
149 { 150000000, 166667, 0xb4, 0x01 },
150 { 173000000, 166667, 0xbc, 0x01 },
151 { 250000000, 166667, 0xb4, 0x02 },
152 { 400000000, 166667, 0xbc, 0x02 },
153 { 420000000, 166667, 0xf4, 0x02 },
154 { 470000000, 166667, 0xfc, 0x02 },
155 { 600000000, 166667, 0xbc, 0x08 },
156 { 730000000, 166667, 0xf4, 0x08 },
157 { 999999999, 166667, 0xfc, 0x08 },
160 EXPORT_SYMBOL(dvb_pll_unknown_1
);
162 /* Infineon TUA6010XS
163 * used in Thomson Cable Tuner
165 struct dvb_pll_desc dvb_pll_tua6010xs
= {
166 .name
= "Infineon TUA6010XS",
172 { 115750000, 62500, 0x8e, 0x03 },
173 { 403250000, 62500, 0x8e, 0x06 },
174 { 999999999, 62500, 0x8e, 0x85 },
177 EXPORT_SYMBOL(dvb_pll_tua6010xs
);
179 /* Panasonic env57h1xd5 (some Philips PLL ?) */
180 struct dvb_pll_desc dvb_pll_env57h1xd5
= {
181 .name
= "Panasonic ENV57H1XD5",
187 { 153000000, 166667, 0xc2, 0x41 },
188 { 470000000, 166667, 0xc2, 0x42 },
189 { 526000000, 166667, 0xc2, 0x84 },
190 { 999999999, 166667, 0xc2, 0xa4 },
193 EXPORT_SYMBOL(dvb_pll_env57h1xd5
);
195 /* Philips TDA6650/TDA6651
196 * used in Panasonic ENV77H11D5
198 static void tda665x_bw(u8
*buf
, u32 freq
, int bandwidth
)
200 if (bandwidth
== BANDWIDTH_8_MHZ
)
204 struct dvb_pll_desc dvb_pll_tda665x
= {
205 .name
= "Philips TDA6650/TDA6651",
212 { 93834000, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
213 { 123834000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
214 { 161000000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
215 { 163834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
216 { 253834000, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
217 { 383834000, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
218 { 443834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
219 { 444000000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
220 { 583834000, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ },
221 { 793834000, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ },
222 { 444834000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
223 { 861000000, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ },
226 EXPORT_SYMBOL(dvb_pll_tda665x
);
229 * used in LG TDTP E102P
231 static void tua6034_bw(u8
*buf
, u32 freq
, int bandwidth
)
233 if (BANDWIDTH_7_MHZ
!= bandwidth
)
237 struct dvb_pll_desc dvb_pll_tua6034
= {
238 .name
= "Infineon TUA6034",
245 { 174500000, 62500, 0xce, 0x01 },
246 { 230000000, 62500, 0xce, 0x02 },
247 { 999999999, 62500, 0xce, 0x04 },
250 EXPORT_SYMBOL(dvb_pll_tua6034
);
253 * used in LG TDVS-H061F, LG TDVS-H062F and LG TDVS-H064F
255 struct dvb_pll_desc dvb_pll_lg_tdvs_h06xf
= {
256 .name
= "LG TDVS-H06xF",
260 .initdata
= tua603x_agc103
,
263 { 165000000, 62500, 0xce, 0x01 },
264 { 450000000, 62500, 0xce, 0x02 },
265 { 999999999, 62500, 0xce, 0x04 },
268 EXPORT_SYMBOL(dvb_pll_lg_tdvs_h06xf
);
271 * used in Medion Hybrid PCMCIA card and USB Box
273 static void fmd1216me_bw(u8
*buf
, u32 freq
, int bandwidth
)
275 if (bandwidth
== BANDWIDTH_8_MHZ
&& freq
>= 158870000)
279 struct dvb_pll_desc dvb_pll_fmd1216me
= {
280 .name
= "Philips FMD1216ME",
284 .setbw
= fmd1216me_bw
,
287 { 143870000, 166667, 0xbc, 0x41 },
288 { 158870000, 166667, 0xf4, 0x41 },
289 { 329870000, 166667, 0xbc, 0x42 },
290 { 441870000, 166667, 0xf4, 0x42 },
291 { 625870000, 166667, 0xbc, 0x44 },
292 { 803870000, 166667, 0xf4, 0x44 },
293 { 999999999, 166667, 0xfc, 0x44 },
296 EXPORT_SYMBOL(dvb_pll_fmd1216me
);
299 * used in Nebula-Cards and USB boxes
301 static void tded4_bw(u8
*buf
, u32 freq
, int bandwidth
)
303 if (bandwidth
== BANDWIDTH_8_MHZ
)
307 struct dvb_pll_desc dvb_pll_tded4
= {
308 .name
= "ALPS TDED4",
315 { 153000000, 166667, 0x85, 0x01 },
316 { 470000000, 166667, 0x85, 0x02 },
317 { 823000000, 166667, 0x85, 0x08 },
318 { 999999999, 166667, 0x85, 0x88 },
321 EXPORT_SYMBOL(dvb_pll_tded4
);
324 * used in AverTVHD MCE A180
326 struct dvb_pll_desc dvb_pll_tdhu2
= {
327 .name
= "ALPS TDHU2",
333 { 162000000, 62500, 0x85, 0x01 },
334 { 426000000, 62500, 0x85, 0x02 },
335 { 782000000, 62500, 0x85, 0x08 },
336 { 999999999, 62500, 0x85, 0x88 },
339 EXPORT_SYMBOL(dvb_pll_tdhu2
);
342 * used in ATI HDTV Wonder
344 struct dvb_pll_desc dvb_pll_tuv1236d
= {
345 .name
= "Philips TUV1236D",
351 { 157250000, 62500, 0xc6, 0x41 },
352 { 454000000, 62500, 0xc6, 0x42 },
353 { 999999999, 62500, 0xc6, 0x44 },
356 EXPORT_SYMBOL(dvb_pll_tuv1236d
);
358 /* Samsung TBMV30111IN / TBMV30712IN1
359 * used in Air2PC ATSC - 2nd generation (nxt2002)
361 struct dvb_pll_desc dvb_pll_samsung_tbmv
= {
362 .name
= "Samsung TBMV30111IN / TBMV30712IN1",
368 { 172000000, 166667, 0xb4, 0x01 },
369 { 214000000, 166667, 0xb4, 0x02 },
370 { 467000000, 166667, 0xbc, 0x02 },
371 { 721000000, 166667, 0xbc, 0x08 },
372 { 841000000, 166667, 0xf4, 0x08 },
373 { 999999999, 166667, 0xfc, 0x02 },
376 EXPORT_SYMBOL(dvb_pll_samsung_tbmv
);
379 * Philips SD1878 Tuner.
381 struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261
= {
382 .name
= "Philips SD1878",
385 .iffreq
= 249, /* zero-IF, offset 249 is to round up */
388 { 1250000, 500, 0xc4, 0x00},
389 { 1550000, 500, 0xc4, 0x40},
390 { 2050000, 500, 0xc4, 0x80},
391 { 2150000, 500, 0xc4, 0xc0},
394 EXPORT_SYMBOL(dvb_pll_philips_sd1878_tda8261
);
397 * Philips TD1316 Tuner.
399 static void td1316_bw(u8
*buf
, u32 freq
, int bandwidth
)
404 if (freq
< 161000000)
406 else if (freq
< 444000000)
413 /* setup PLL filter */
414 if (bandwidth
== BANDWIDTH_8_MHZ
)
418 struct dvb_pll_desc dvb_pll_philips_td1316
= {
419 .name
= "Philips TD1316",
426 { 93834000, 166667, 0xca, 0x60},
427 { 123834000, 166667, 0xca, 0xa0},
428 { 163834000, 166667, 0xca, 0xc0},
429 { 253834000, 166667, 0xca, 0x60},
430 { 383834000, 166667, 0xca, 0xa0},
431 { 443834000, 166667, 0xca, 0xc0},
432 { 583834000, 166667, 0xca, 0x60},
433 { 793834000, 166667, 0xca, 0xa0},
434 { 858834000, 166667, 0xca, 0xe0},
437 EXPORT_SYMBOL(dvb_pll_philips_td1316
);
439 /* FE6600 used on DViCO Hybrid */
440 struct dvb_pll_desc dvb_pll_thomson_fe6600
= {
441 .name
= "Thomson FE6600",
447 { 250000000, 166667, 0xb4, 0x12 },
448 { 455000000, 166667, 0xfe, 0x11 },
449 { 775500000, 166667, 0xbc, 0x18 },
450 { 999999999, 166667, 0xf4, 0x18 },
453 EXPORT_SYMBOL(dvb_pll_thomson_fe6600
);
454 static void opera1_bw(u8
*buf
, u32 freq
, int bandwidth
)
456 if (bandwidth
== BANDWIDTH_8_MHZ
)
460 struct dvb_pll_desc dvb_pll_opera1
= {
461 .name
= "Opera Tuner",
468 { 1064000, 500, 0xe5, 0xc6 },
469 { 1169000, 500, 0xe5, 0xe6 },
470 { 1299000, 500, 0xe5, 0x24 },
471 { 1444000, 500, 0xe5, 0x44 },
472 { 1606000, 500, 0xe5, 0x64 },
473 { 1777000, 500, 0xe5, 0x84 },
474 { 1941000, 500, 0xe5, 0xa4 },
475 { 2250000, 500, 0xe5, 0xc4 },
478 EXPORT_SYMBOL(dvb_pll_opera1
);
480 struct dvb_pll_priv
{
483 struct i2c_adapter
*i2c
;
485 /* the PLL descriptor */
486 struct dvb_pll_desc
*pll_desc
;
488 /* cached frequency/bandwidth */
493 /* ----------------------------------------------------------- */
496 static int debug
= 0;
497 module_param(debug
, int, 0644);
498 MODULE_PARM_DESC(debug
, "enable verbose debug messages");
500 int dvb_pll_configure(struct dvb_pll_desc
*desc
, u8
*buf
,
501 u32 freq
, int bandwidth
)
506 if (freq
!= 0 && (freq
< desc
->min
|| freq
> desc
->max
))
509 for (i
= 0; i
< desc
->count
; i
++) {
510 if (freq
> desc
->entries
[i
].limit
)
515 printk("pll: %s: freq=%d bw=%d | i=%d/%d\n",
516 desc
->name
, freq
, bandwidth
, i
, desc
->count
);
517 if (i
== desc
->count
)
520 div
= (freq
+ desc
->iffreq
+ desc
->entries
[i
].stepsize
/2) /
521 desc
->entries
[i
].stepsize
;
524 buf
[2] = desc
->entries
[i
].config
;
525 buf
[3] = desc
->entries
[i
].cb
;
528 desc
->setbw(buf
, freq
, bandwidth
);
531 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
532 desc
->name
, div
, buf
[0], buf
[1], buf
[2], buf
[3]);
534 // calculate the frequency we set it to
535 return (div
* desc
->entries
[i
].stepsize
) - desc
->iffreq
;
537 EXPORT_SYMBOL(dvb_pll_configure
);
539 static int dvb_pll_release(struct dvb_frontend
*fe
)
541 kfree(fe
->tuner_priv
);
542 fe
->tuner_priv
= NULL
;
546 static int dvb_pll_sleep(struct dvb_frontend
*fe
)
548 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
550 if (priv
->i2c
== NULL
)
553 if (priv
->pll_desc
->sleepdata
) {
554 struct i2c_msg msg
= { .flags
= 0,
555 .addr
= priv
->pll_i2c_address
,
556 .buf
= priv
->pll_desc
->sleepdata
+ 1,
557 .len
= priv
->pll_desc
->sleepdata
[0] };
561 if (fe
->ops
.i2c_gate_ctrl
)
562 fe
->ops
.i2c_gate_ctrl(fe
, 1);
563 if ((result
= i2c_transfer(priv
->i2c
, &msg
, 1)) != 1) {
568 /* Shouldn't be called when initdata is NULL, maybe BUG()? */
572 static int dvb_pll_set_params(struct dvb_frontend
*fe
,
573 struct dvb_frontend_parameters
*params
)
575 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
578 { .addr
= priv
->pll_i2c_address
, .flags
= 0,
579 .buf
= buf
, .len
= sizeof(buf
) };
581 u32 bandwidth
= 0, frequency
= 0;
583 if (priv
->i2c
== NULL
)
586 // DVBT bandwidth only just now
587 if (fe
->ops
.info
.type
== FE_OFDM
) {
588 bandwidth
= params
->u
.ofdm
.bandwidth
;
591 if ((result
= dvb_pll_configure(priv
->pll_desc
, buf
,
592 params
->frequency
, bandwidth
)) < 0)
597 if (fe
->ops
.i2c_gate_ctrl
)
598 fe
->ops
.i2c_gate_ctrl(fe
, 1);
599 if ((result
= i2c_transfer(priv
->i2c
, &msg
, 1)) != 1) {
603 priv
->frequency
= frequency
;
604 priv
->bandwidth
= bandwidth
;
609 static int dvb_pll_calc_regs(struct dvb_frontend
*fe
,
610 struct dvb_frontend_parameters
*params
,
611 u8
*buf
, int buf_len
)
613 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
615 u32 bandwidth
= 0, frequency
= 0;
620 // DVBT bandwidth only just now
621 if (fe
->ops
.info
.type
== FE_OFDM
) {
622 bandwidth
= params
->u
.ofdm
.bandwidth
;
625 if ((result
= dvb_pll_configure(priv
->pll_desc
, buf
+1,
626 params
->frequency
, bandwidth
)) < 0)
631 buf
[0] = priv
->pll_i2c_address
;
633 priv
->frequency
= frequency
;
634 priv
->bandwidth
= bandwidth
;
639 static int dvb_pll_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
641 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
642 *frequency
= priv
->frequency
;
646 static int dvb_pll_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
648 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
649 *bandwidth
= priv
->bandwidth
;
653 static int dvb_pll_init(struct dvb_frontend
*fe
)
655 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
657 if (priv
->i2c
== NULL
)
660 if (priv
->pll_desc
->initdata
) {
661 struct i2c_msg msg
= { .flags
= 0,
662 .addr
= priv
->pll_i2c_address
,
663 .buf
= priv
->pll_desc
->initdata
+ 1,
664 .len
= priv
->pll_desc
->initdata
[0] };
667 if (fe
->ops
.i2c_gate_ctrl
)
668 fe
->ops
.i2c_gate_ctrl(fe
, 1);
669 if ((result
= i2c_transfer(priv
->i2c
, &msg
, 1)) != 1) {
674 /* Shouldn't be called when initdata is NULL, maybe BUG()? */
678 static struct dvb_tuner_ops dvb_pll_tuner_ops
= {
679 .release
= dvb_pll_release
,
680 .sleep
= dvb_pll_sleep
,
681 .init
= dvb_pll_init
,
682 .set_params
= dvb_pll_set_params
,
683 .calc_regs
= dvb_pll_calc_regs
,
684 .get_frequency
= dvb_pll_get_frequency
,
685 .get_bandwidth
= dvb_pll_get_bandwidth
,
688 struct dvb_frontend
*dvb_pll_attach(struct dvb_frontend
*fe
, int pll_addr
,
689 struct i2c_adapter
*i2c
,
690 struct dvb_pll_desc
*desc
)
693 struct i2c_msg msg
= { .addr
= pll_addr
, .flags
= I2C_M_RD
,
694 .buf
= b1
, .len
= 1 };
695 struct dvb_pll_priv
*priv
= NULL
;
699 if (fe
->ops
.i2c_gate_ctrl
)
700 fe
->ops
.i2c_gate_ctrl(fe
, 1);
702 ret
= i2c_transfer (i2c
, &msg
, 1);
705 if (fe
->ops
.i2c_gate_ctrl
)
706 fe
->ops
.i2c_gate_ctrl(fe
, 0);
709 priv
= kzalloc(sizeof(struct dvb_pll_priv
), GFP_KERNEL
);
713 priv
->pll_i2c_address
= pll_addr
;
715 priv
->pll_desc
= desc
;
717 memcpy(&fe
->ops
.tuner_ops
, &dvb_pll_tuner_ops
,
718 sizeof(struct dvb_tuner_ops
));
720 strncpy(fe
->ops
.tuner_ops
.info
.name
, desc
->name
,
721 sizeof(fe
->ops
.tuner_ops
.info
.name
));
722 fe
->ops
.tuner_ops
.info
.frequency_min
= desc
->min
;
723 fe
->ops
.tuner_ops
.info
.frequency_min
= desc
->max
;
725 fe
->ops
.tuner_ops
.init
= NULL
;
726 if (!desc
->sleepdata
)
727 fe
->ops
.tuner_ops
.sleep
= NULL
;
729 fe
->tuner_priv
= priv
;
732 EXPORT_SYMBOL(dvb_pll_attach
);
734 MODULE_DESCRIPTION("dvb pll library");
735 MODULE_AUTHOR("Gerd Knorr");
736 MODULE_LICENSE("GPL");