1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * descriptions + helper functions for simple dvb plls.
5 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/slab.h>
11 #include <linux/module.h>
12 #include <linux/idr.h>
13 #include <linux/dvb/frontend.h>
14 #include <asm/types.h>
18 #define dprintk(fmt, arg...) \
19 printk(KERN_DEBUG pr_fmt("%s: " fmt), __func__, ##arg)
27 struct i2c_adapter *i2c;
29 /* the PLL descriptor */
30 const struct dvb_pll_desc *pll_desc;
32 /* cached frequency/bandwidth */
37 #define DVB_PLL_MAX 64
38 static DEFINE_IDA(pll_ida);
41 module_param(debug, int, 0644);
42 MODULE_PARM_DESC(debug, "enable verbose debug messages");
44 static unsigned int id[DVB_PLL_MAX] =
45 { [ 0 ... (DVB_PLL_MAX-1) ] = DVB_PLL_UNDEFINED };
46 module_param_array(id, int, NULL, 0644);
47 MODULE_PARM_DESC(id, "force pll id to use (DEBUG ONLY)");
49 /* ----------------------------------------------------------- */
56 void (*set)(struct dvb_frontend *fe, u8 *buf);
69 /* ----------------------------------------------------------- */
72 static const struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
73 .name = "Thomson dtt7579",
77 .sleepdata = (u8[]){ 2, 0xb4, 0x03 },
80 { 443250000, 166667, 0xb4, 0x02 },
81 { 542000000, 166667, 0xb4, 0x08 },
82 { 771000000, 166667, 0xbc, 0x08 },
83 { 999999999, 166667, 0xf4, 0x08 },
87 static void thomson_dtt759x_bw(struct dvb_frontend *fe, u8 *buf)
89 u32 bw = fe->dtv_property_cache.bandwidth_hz;
94 static const struct dvb_pll_desc dvb_pll_thomson_dtt759x = {
95 .name = "Thomson dtt759x",
98 .set = thomson_dtt759x_bw,
100 .sleepdata = (u8[]){ 2, 0x84, 0x03 },
103 { 264000000, 166667, 0xb4, 0x02 },
104 { 470000000, 166667, 0xbc, 0x02 },
105 { 735000000, 166667, 0xbc, 0x08 },
106 { 835000000, 166667, 0xf4, 0x08 },
107 { 999999999, 166667, 0xfc, 0x08 },
111 static void thomson_dtt7520x_bw(struct dvb_frontend *fe, u8 *buf)
113 u32 bw = fe->dtv_property_cache.bandwidth_hz;
118 static const struct dvb_pll_desc dvb_pll_thomson_dtt7520x = {
119 .name = "Thomson dtt7520x",
122 .set = thomson_dtt7520x_bw,
126 { 305000000, 166667, 0xb4, 0x12 },
127 { 405000000, 166667, 0xbc, 0x12 },
128 { 445000000, 166667, 0xbc, 0x12 },
129 { 465000000, 166667, 0xf4, 0x18 },
130 { 735000000, 166667, 0xfc, 0x18 },
131 { 835000000, 166667, 0xbc, 0x18 },
132 { 999999999, 166667, 0xfc, 0x18 },
136 static const struct dvb_pll_desc dvb_pll_lg_z201 = {
141 .sleepdata = (u8[]){ 2, 0xbc, 0x03 },
144 { 157500000, 166667, 0xbc, 0x01 },
145 { 443250000, 166667, 0xbc, 0x02 },
146 { 542000000, 166667, 0xbc, 0x04 },
147 { 830000000, 166667, 0xf4, 0x04 },
148 { 999999999, 166667, 0xfc, 0x04 },
152 static const struct dvb_pll_desc dvb_pll_unknown_1 = {
153 .name = "unknown 1", /* used by dntv live dvb-t */
159 { 150000000, 166667, 0xb4, 0x01 },
160 { 173000000, 166667, 0xbc, 0x01 },
161 { 250000000, 166667, 0xb4, 0x02 },
162 { 400000000, 166667, 0xbc, 0x02 },
163 { 420000000, 166667, 0xf4, 0x02 },
164 { 470000000, 166667, 0xfc, 0x02 },
165 { 600000000, 166667, 0xbc, 0x08 },
166 { 730000000, 166667, 0xf4, 0x08 },
167 { 999999999, 166667, 0xfc, 0x08 },
171 /* Infineon TUA6010XS
172 * used in Thomson Cable Tuner
174 static const struct dvb_pll_desc dvb_pll_tua6010xs = {
175 .name = "Infineon TUA6010XS",
181 { 115750000, 62500, 0x8e, 0x03 },
182 { 403250000, 62500, 0x8e, 0x06 },
183 { 999999999, 62500, 0x8e, 0x85 },
187 /* Panasonic env57h1xd5 (some Philips PLL ?) */
188 static const struct dvb_pll_desc dvb_pll_env57h1xd5 = {
189 .name = "Panasonic ENV57H1XD5",
195 { 153000000, 166667, 0xc2, 0x41 },
196 { 470000000, 166667, 0xc2, 0x42 },
197 { 526000000, 166667, 0xc2, 0x84 },
198 { 999999999, 166667, 0xc2, 0xa4 },
202 /* Philips TDA6650/TDA6651
203 * used in Panasonic ENV77H11D5
205 static void tda665x_bw(struct dvb_frontend *fe, u8 *buf)
207 u32 bw = fe->dtv_property_cache.bandwidth_hz;
212 static const struct dvb_pll_desc dvb_pll_tda665x = {
213 .name = "Philips TDA6650/TDA6651",
218 .initdata = (u8[]){ 4, 0x0b, 0xf5, 0x85, 0xab },
221 { 93834000, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
222 { 123834000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
223 { 161000000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
224 { 163834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
225 { 253834000, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
226 { 383834000, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
227 { 443834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
228 { 444000000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
229 { 583834000, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ },
230 { 793834000, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ },
231 { 444834000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
232 { 861000000, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ },
237 * used in LG TDTP E102P
239 static void tua6034_bw(struct dvb_frontend *fe, u8 *buf)
241 u32 bw = fe->dtv_property_cache.bandwidth_hz;
246 static const struct dvb_pll_desc dvb_pll_tua6034 = {
247 .name = "Infineon TUA6034",
254 { 174500000, 62500, 0xce, 0x01 },
255 { 230000000, 62500, 0xce, 0x02 },
256 { 999999999, 62500, 0xce, 0x04 },
261 * used in Nebula-Cards and USB boxes
263 static void tded4_bw(struct dvb_frontend *fe, u8 *buf)
265 u32 bw = fe->dtv_property_cache.bandwidth_hz;
270 static const struct dvb_pll_desc dvb_pll_tded4 = {
271 .name = "ALPS TDED4",
278 { 153000000, 166667, 0x85, 0x01 },
279 { 470000000, 166667, 0x85, 0x02 },
280 { 823000000, 166667, 0x85, 0x08 },
281 { 999999999, 166667, 0x85, 0x88 },
286 * used in AverTVHD MCE A180
288 static const struct dvb_pll_desc dvb_pll_tdhu2 = {
289 .name = "ALPS TDHU2",
295 { 162000000, 62500, 0x85, 0x01 },
296 { 426000000, 62500, 0x85, 0x02 },
297 { 782000000, 62500, 0x85, 0x08 },
298 { 999999999, 62500, 0x85, 0x88 },
302 /* Samsung TBMV30111IN / TBMV30712IN1
303 * used in Air2PC ATSC - 2nd generation (nxt2002)
305 static const struct dvb_pll_desc dvb_pll_samsung_tbmv = {
306 .name = "Samsung TBMV30111IN / TBMV30712IN1",
312 { 172000000, 166667, 0xb4, 0x01 },
313 { 214000000, 166667, 0xb4, 0x02 },
314 { 467000000, 166667, 0xbc, 0x02 },
315 { 721000000, 166667, 0xbc, 0x08 },
316 { 841000000, 166667, 0xf4, 0x08 },
317 { 999999999, 166667, 0xfc, 0x02 },
322 * Philips SD1878 Tuner.
324 static const struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
325 .name = "Philips SD1878",
328 .iffreq= 249, /* zero-IF, offset 249 is to round up */
331 { 1250000, 500, 0xc4, 0x00},
332 { 1450000, 500, 0xc4, 0x40},
333 { 2050000, 500, 0xc4, 0x80},
334 { 2150000, 500, 0xc4, 0xc0},
338 static void opera1_bw(struct dvb_frontend *fe, u8 *buf)
340 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
341 struct dvb_pll_priv *priv = fe->tuner_priv;
342 u32 b_w = (c->symbol_rate * 27) / 32000;
343 struct i2c_msg msg = {
344 .addr = priv->pll_i2c_address,
352 if (fe->ops.i2c_gate_ctrl)
353 fe->ops.i2c_gate_ctrl(fe, 1);
355 result = i2c_transfer(priv->i2c, &msg, 1);
357 pr_err("%s: i2c_transfer failed:%d",
362 else if (b_w <= 12000)
364 else if (b_w <= 14000)
366 else if (b_w <= 16000)
368 else if (b_w <= 18000)
370 else if (b_w <= 20000)
372 else if (b_w <= 22000)
374 else if (b_w <= 24000)
376 else if (b_w <= 26000)
378 else if (b_w <= 28000)
382 buf[2] ^= 0x1c; /* Flip bits 3-5 */
384 buf[2] |= ((lpf >> 2) & 0x3) << 3;
385 buf[3] |= (lpf & 0x3) << 2;
390 static const struct dvb_pll_desc dvb_pll_opera1 = {
391 .name = "Opera Tuner",
394 .initdata = (u8[]){ 4, 0x08, 0xe5, 0xe1, 0x00 },
395 .initdata2 = (u8[]){ 4, 0x08, 0xe5, 0xe5, 0x00 },
400 { 1064000, 500, 0xf9, 0xc2 },
401 { 1169000, 500, 0xf9, 0xe2 },
402 { 1299000, 500, 0xf9, 0x20 },
403 { 1444000, 500, 0xf9, 0x40 },
404 { 1606000, 500, 0xf9, 0x60 },
405 { 1777000, 500, 0xf9, 0x80 },
406 { 1941000, 500, 0xf9, 0xa0 },
407 { 2250000, 500, 0xf9, 0xc0 },
411 static void samsung_dtos403ih102a_set(struct dvb_frontend *fe, u8 *buf)
413 struct dvb_pll_priv *priv = fe->tuner_priv;
414 struct i2c_msg msg = {
415 .addr = priv->pll_i2c_address,
422 if (fe->ops.i2c_gate_ctrl)
423 fe->ops.i2c_gate_ctrl(fe, 1);
425 result = i2c_transfer(priv->i2c, &msg, 1);
427 pr_err("%s: i2c_transfer failed:%d",
436 /* unknown pll used in Samsung DTOS403IH102A DVB-C tuner */
437 static const struct dvb_pll_desc dvb_pll_samsung_dtos403ih102a = {
438 .name = "Samsung DTOS403IH102A",
443 .set = samsung_dtos403ih102a_set,
445 { 135000000, 62500, 0xbe, 0x01 },
446 { 177000000, 62500, 0xf6, 0x01 },
447 { 370000000, 62500, 0xbe, 0x02 },
448 { 450000000, 62500, 0xf6, 0x02 },
449 { 466000000, 62500, 0xfe, 0x02 },
450 { 538000000, 62500, 0xbe, 0x08 },
451 { 826000000, 62500, 0xf6, 0x08 },
452 { 999999999, 62500, 0xfe, 0x08 },
456 /* Samsung TDTC9251DH0 DVB-T NIM, as used on AirStar 2 */
457 static const struct dvb_pll_desc dvb_pll_samsung_tdtc9251dh0 = {
458 .name = "Samsung TDTC9251DH0",
464 { 157500000, 166667, 0xcc, 0x09 },
465 { 443000000, 166667, 0xcc, 0x0a },
466 { 863000000, 166667, 0xcc, 0x08 },
470 /* Samsung TBDU18132 DVB-S NIM with TSA5059 PLL, used in SkyStar2 DVB-S 2.3 */
471 static const struct dvb_pll_desc dvb_pll_samsung_tbdu18132 = {
472 .name = "Samsung TBDU18132",
474 .max = 2150 * MHz, /* guesses */
478 { 1550000, 125, 0x84, 0x82 },
479 { 4095937, 125, 0x84, 0x80 },
481 /* TSA5059 PLL has a 17 bit divisor rather than the 15 bits supported
482 * by this driver. The two extra bits are 0x60 in the third byte. 15
483 * bits is enough for over 4 GHz, which is enough to cover the range
484 * of this tuner. We could use the additional divisor bits by adding
486 { 0x0ffff * 125 + 125/2, 125, 0x84 | 0x20, },
487 { 0x17fff * 125 + 125/2, 125, 0x84 | 0x40, },
488 { 0x1ffff * 125 + 125/2, 125, 0x84 | 0x60, }, */
491 /* Samsung TBMU24112 DVB-S NIM with SL1935 zero-IF tuner */
492 static const struct dvb_pll_desc dvb_pll_samsung_tbmu24112 = {
493 .name = "Samsung TBMU24112",
495 .max = 2150 * MHz, /* guesses */
499 { 1500000, 125, 0x84, 0x18 },
500 { 9999999, 125, 0x84, 0x08 },
504 /* Alps TDEE4 DVB-C NIM, used on Cablestar 2 */
505 /* byte 4 : 1 * * AGD R3 R2 R1 R0
506 * byte 5 : C1 * RE RTS BS4 BS3 BS2 BS1
507 * AGD = 1, R3 R2 R1 R0 = 0 1 0 1 => byte 4 = 1**10101 = 0x95
508 * Range(MHz) C1 * RE RTS BS4 BS3 BS2 BS1 Byte 5
509 * 47 - 153 0 * 0 0 0 0 0 1 0x01
510 * 153 - 430 0 * 0 0 0 0 1 0 0x02
511 * 430 - 822 0 * 0 0 1 0 0 0 0x08
512 * 822 - 862 1 * 0 0 1 0 0 0 0x88 */
513 static const struct dvb_pll_desc dvb_pll_alps_tdee4 = {
514 .name = "ALPS TDEE4",
520 { 153000000, 62500, 0x95, 0x01 },
521 { 430000000, 62500, 0x95, 0x02 },
522 { 822000000, 62500, 0x95, 0x08 },
523 { 999999999, 62500, 0x95, 0x88 },
527 /* Infineon TUA6034 ISDB-T, used in Friio */
528 /* CP cur. 50uA, AGC takeover: 103dBuV, PORT3 on */
529 static const struct dvb_pll_desc dvb_pll_tua6034_friio = {
530 .name = "Infineon TUA6034 ISDB-T (Friio)",
534 .initdata = (u8[]){ 4, 0x9a, 0x50, 0xb2, 0x08 },
535 .sleepdata = (u8[]){ 4, 0x9a, 0x70, 0xb3, 0x0b },
538 { 170000000, 142857, 0xba, 0x09 },
539 { 470000000, 142857, 0xba, 0x0a },
540 { 770000000, 142857, 0xb2, 0x08 },
544 /* Philips TDA6651 ISDB-T, used in Earthsoft PT1 */
545 static const struct dvb_pll_desc dvb_pll_tda665x_earth_pt1 = {
546 .name = "Philips TDA6651 ISDB-T (EarthSoft PT1)",
550 .initdata = (u8[]){ 5, 0x0e, 0x7f, 0xc1, 0x80, 0x80 },
553 { 140000000, 142857, 0xc1, 0x81 },
554 { 170000000, 142857, 0xc1, 0xa1 },
555 { 220000000, 142857, 0xc1, 0x62 },
556 { 330000000, 142857, 0xc1, 0xa2 },
557 { 402000000, 142857, 0xc1, 0xe2 },
558 { 450000000, 142857, 0xc1, 0x64 },
559 { 550000000, 142857, 0xc1, 0x84 },
560 { 600000000, 142857, 0xc1, 0xa4 },
561 { 700000000, 142857, 0xc1, 0xc4 },
562 { 770000000, 142857, 0xc1, 0xe4 },
566 /* ----------------------------------------------------------- */
568 static const struct dvb_pll_desc *pll_list[] = {
569 [DVB_PLL_UNDEFINED] = NULL,
570 [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579,
571 [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x,
572 [DVB_PLL_THOMSON_DTT7520X] = &dvb_pll_thomson_dtt7520x,
573 [DVB_PLL_LG_Z201] = &dvb_pll_lg_z201,
574 [DVB_PLL_UNKNOWN_1] = &dvb_pll_unknown_1,
575 [DVB_PLL_TUA6010XS] = &dvb_pll_tua6010xs,
576 [DVB_PLL_ENV57H1XD5] = &dvb_pll_env57h1xd5,
577 [DVB_PLL_TUA6034] = &dvb_pll_tua6034,
578 [DVB_PLL_TDA665X] = &dvb_pll_tda665x,
579 [DVB_PLL_TDED4] = &dvb_pll_tded4,
580 [DVB_PLL_TDEE4] = &dvb_pll_alps_tdee4,
581 [DVB_PLL_TDHU2] = &dvb_pll_tdhu2,
582 [DVB_PLL_SAMSUNG_TBMV] = &dvb_pll_samsung_tbmv,
583 [DVB_PLL_PHILIPS_SD1878_TDA8261] = &dvb_pll_philips_sd1878_tda8261,
584 [DVB_PLL_OPERA1] = &dvb_pll_opera1,
585 [DVB_PLL_SAMSUNG_DTOS403IH102A] = &dvb_pll_samsung_dtos403ih102a,
586 [DVB_PLL_SAMSUNG_TDTC9251DH0] = &dvb_pll_samsung_tdtc9251dh0,
587 [DVB_PLL_SAMSUNG_TBDU18132] = &dvb_pll_samsung_tbdu18132,
588 [DVB_PLL_SAMSUNG_TBMU24112] = &dvb_pll_samsung_tbmu24112,
589 [DVB_PLL_TUA6034_FRIIO] = &dvb_pll_tua6034_friio,
590 [DVB_PLL_TDA665X_EARTH_PT1] = &dvb_pll_tda665x_earth_pt1,
593 /* ----------------------------------------------------------- */
596 static int dvb_pll_configure(struct dvb_frontend *fe, u8 *buf,
599 struct dvb_pll_priv *priv = fe->tuner_priv;
600 const struct dvb_pll_desc *desc = priv->pll_desc;
604 for (i = 0; i < desc->count; i++) {
605 if (frequency > desc->entries[i].limit)
611 dprintk("pll: %s: freq=%d | i=%d/%d\n", desc->name,
612 frequency, i, desc->count);
613 if (i == desc->count)
616 div = (frequency + desc->iffreq +
617 desc->entries[i].stepsize/2) / desc->entries[i].stepsize;
620 buf[2] = desc->entries[i].config;
621 buf[3] = desc->entries[i].cb;
627 dprintk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
628 desc->name, div, buf[0], buf[1], buf[2], buf[3]);
630 // calculate the frequency we set it to
631 return (div * desc->entries[i].stepsize) - desc->iffreq;
634 static void dvb_pll_release(struct dvb_frontend *fe)
636 kfree(fe->tuner_priv);
637 fe->tuner_priv = NULL;
640 static int dvb_pll_sleep(struct dvb_frontend *fe)
642 struct dvb_pll_priv *priv = fe->tuner_priv;
644 if (priv->i2c == NULL)
647 if (priv->pll_desc->sleepdata) {
648 struct i2c_msg msg = { .flags = 0,
649 .addr = priv->pll_i2c_address,
650 .buf = priv->pll_desc->sleepdata + 1,
651 .len = priv->pll_desc->sleepdata[0] };
655 if (fe->ops.i2c_gate_ctrl)
656 fe->ops.i2c_gate_ctrl(fe, 1);
657 if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
662 /* Shouldn't be called when initdata is NULL, maybe BUG()? */
666 static int dvb_pll_set_params(struct dvb_frontend *fe)
668 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
669 struct dvb_pll_priv *priv = fe->tuner_priv;
672 { .addr = priv->pll_i2c_address, .flags = 0,
673 .buf = buf, .len = sizeof(buf) };
677 if (priv->i2c == NULL)
680 result = dvb_pll_configure(fe, buf, c->frequency);
686 if (fe->ops.i2c_gate_ctrl)
687 fe->ops.i2c_gate_ctrl(fe, 1);
688 if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
692 priv->frequency = frequency;
693 priv->bandwidth = c->bandwidth_hz;
698 static int dvb_pll_calc_regs(struct dvb_frontend *fe,
699 u8 *buf, int buf_len)
701 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
702 struct dvb_pll_priv *priv = fe->tuner_priv;
709 result = dvb_pll_configure(fe, buf + 1, c->frequency);
715 buf[0] = priv->pll_i2c_address;
717 priv->frequency = frequency;
718 priv->bandwidth = c->bandwidth_hz;
723 static int dvb_pll_get_frequency(struct dvb_frontend *fe, u32 *frequency)
725 struct dvb_pll_priv *priv = fe->tuner_priv;
726 *frequency = priv->frequency;
730 static int dvb_pll_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
732 struct dvb_pll_priv *priv = fe->tuner_priv;
733 *bandwidth = priv->bandwidth;
737 static int dvb_pll_init(struct dvb_frontend *fe)
739 struct dvb_pll_priv *priv = fe->tuner_priv;
741 if (priv->i2c == NULL)
744 if (priv->pll_desc->initdata) {
745 struct i2c_msg msg = { .flags = 0,
746 .addr = priv->pll_i2c_address,
747 .buf = priv->pll_desc->initdata + 1,
748 .len = priv->pll_desc->initdata[0] };
751 if (fe->ops.i2c_gate_ctrl)
752 fe->ops.i2c_gate_ctrl(fe, 1);
753 result = i2c_transfer(priv->i2c, &msg, 1);
756 if (priv->pll_desc->initdata2) {
757 msg.buf = priv->pll_desc->initdata2 + 1;
758 msg.len = priv->pll_desc->initdata2[0];
759 if (fe->ops.i2c_gate_ctrl)
760 fe->ops.i2c_gate_ctrl(fe, 1);
761 result = i2c_transfer(priv->i2c, &msg, 1);
767 /* Shouldn't be called when initdata is NULL, maybe BUG()? */
771 static const struct dvb_tuner_ops dvb_pll_tuner_ops = {
772 .release = dvb_pll_release,
773 .sleep = dvb_pll_sleep,
774 .init = dvb_pll_init,
775 .set_params = dvb_pll_set_params,
776 .calc_regs = dvb_pll_calc_regs,
777 .get_frequency = dvb_pll_get_frequency,
778 .get_bandwidth = dvb_pll_get_bandwidth,
781 struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
782 struct i2c_adapter *i2c,
783 unsigned int pll_desc_id)
786 struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD, .len = 1 };
787 struct dvb_pll_priv *priv = NULL;
789 const struct dvb_pll_desc *desc;
792 b1 = kmalloc(1, GFP_KERNEL);
799 nr = ida_simple_get(&pll_ida, 0, DVB_PLL_MAX, GFP_KERNEL);
805 if (id[nr] > DVB_PLL_UNDEFINED && id[nr] < ARRAY_SIZE(pll_list))
806 pll_desc_id = id[nr];
808 BUG_ON(pll_desc_id < 1 || pll_desc_id >= ARRAY_SIZE(pll_list));
810 desc = pll_list[pll_desc_id];
813 if (fe->ops.i2c_gate_ctrl)
814 fe->ops.i2c_gate_ctrl(fe, 1);
816 ret = i2c_transfer (i2c, &msg, 1);
819 if (fe->ops.i2c_gate_ctrl)
820 fe->ops.i2c_gate_ctrl(fe, 0);
823 priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL);
827 priv->pll_i2c_address = pll_addr;
829 priv->pll_desc = desc;
832 memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops,
833 sizeof(struct dvb_tuner_ops));
835 strscpy(fe->ops.tuner_ops.info.name, desc->name,
836 sizeof(fe->ops.tuner_ops.info.name));
838 fe->ops.tuner_ops.info.frequency_min_hz = desc->min;
839 fe->ops.tuner_ops.info.frequency_max_hz = desc->max;
841 dprintk("%s tuner, frequency range: %u...%u\n",
842 desc->name, desc->min, desc->max);
845 fe->ops.tuner_ops.init = NULL;
846 if (!desc->sleepdata)
847 fe->ops.tuner_ops.sleep = NULL;
849 fe->tuner_priv = priv;
851 if ((debug) || (id[priv->nr] == pll_desc_id)) {
852 dprintk("dvb-pll[%d]", priv->nr);
854 pr_cont(" %d-%04x", i2c_adapter_id(i2c), pll_addr);
855 pr_cont(": id# %d (%s) attached, %s\n", pll_desc_id, desc->name,
856 id[priv->nr] == pll_desc_id ?
857 "insmod option" : "autodetected");
865 ida_simple_remove(&pll_ida, nr);
869 EXPORT_SYMBOL(dvb_pll_attach);
873 dvb_pll_probe(struct i2c_client *client, const struct i2c_device_id *id)
875 struct dvb_pll_config *cfg;
876 struct dvb_frontend *fe;
877 unsigned int desc_id;
879 cfg = client->dev.platform_data;
881 i2c_set_clientdata(client, fe);
882 desc_id = (unsigned int) id->driver_data;
884 if (!dvb_pll_attach(fe, client->addr, client->adapter, desc_id))
888 * Unset tuner_ops.release (== dvb_pll_release)
889 * which has been just set in the above dvb_pll_attach(),
890 * because if tuner_ops.release was left defined,
891 * this module would be 'put' twice on exit:
892 * once by dvb_frontend_detach() and another by dvb_module_release().
894 * dvb_pll_release is instead executed in the i2c driver's .remove(),
895 * keeping dvb_pll_attach untouched for legacy (dvb_attach) drivers.
897 fe->ops.tuner_ops.release = NULL;
898 dev_info(&client->dev, "DVB Simple Tuner attached.\n");
902 static int dvb_pll_remove(struct i2c_client *client)
904 struct dvb_frontend *fe = i2c_get_clientdata(client);
905 struct dvb_pll_priv *priv = fe->tuner_priv;
907 ida_simple_remove(&pll_ida, priv->nr);
913 static const struct i2c_device_id dvb_pll_id[] = {
914 {"dtt7579", DVB_PLL_THOMSON_DTT7579},
915 {"dtt759x", DVB_PLL_THOMSON_DTT759X},
916 {"z201", DVB_PLL_LG_Z201},
917 {"unknown_1", DVB_PLL_UNKNOWN_1},
918 {"tua6010xs", DVB_PLL_TUA6010XS},
919 {"env57h1xd5", DVB_PLL_ENV57H1XD5},
920 {"tua6034", DVB_PLL_TUA6034},
921 {"tda665x", DVB_PLL_TDA665X},
922 {"tded4", DVB_PLL_TDED4},
923 {"tdhu2", DVB_PLL_TDHU2},
924 {"tbmv", DVB_PLL_SAMSUNG_TBMV},
925 {"sd1878_tda8261", DVB_PLL_PHILIPS_SD1878_TDA8261},
926 {"opera1", DVB_PLL_OPERA1},
927 {"dtos403ih102a", DVB_PLL_SAMSUNG_DTOS403IH102A},
928 {"tdtc9251dh0", DVB_PLL_SAMSUNG_TDTC9251DH0},
929 {"tbdu18132", DVB_PLL_SAMSUNG_TBDU18132},
930 {"tbmu24112", DVB_PLL_SAMSUNG_TBMU24112},
931 {"tdee4", DVB_PLL_TDEE4},
932 {"dtt7520x", DVB_PLL_THOMSON_DTT7520X},
933 {"tua6034_friio", DVB_PLL_TUA6034_FRIIO},
934 {"tda665x_earthpt1", DVB_PLL_TDA665X_EARTH_PT1},
939 MODULE_DEVICE_TABLE(i2c, dvb_pll_id);
941 static struct i2c_driver dvb_pll_driver = {
945 .probe = dvb_pll_probe,
946 .remove = dvb_pll_remove,
947 .id_table = dvb_pll_id,
950 module_i2c_driver(dvb_pll_driver);
952 MODULE_DESCRIPTION("dvb pll library");
953 MODULE_AUTHOR("Gerd Knorr");
954 MODULE_LICENSE("GPL");