diff options
Diffstat (limited to 'drivers/media/dvb/frontends/dvb-pll.c')
-rw-r--r-- | drivers/media/dvb/frontends/dvb-pll.c | 181 |
1 files changed, 176 insertions, 5 deletions
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c index 791706ec1da3..a189683454b7 100644 --- a/drivers/media/dvb/frontends/dvb-pll.c +++ b/drivers/media/dvb/frontends/dvb-pll.c | |||
@@ -227,10 +227,10 @@ struct dvb_pll_desc dvb_pll_tua6034 = { | |||
227 | EXPORT_SYMBOL(dvb_pll_tua6034); | 227 | EXPORT_SYMBOL(dvb_pll_tua6034); |
228 | 228 | ||
229 | /* Infineon TUA6034 | 229 | /* Infineon TUA6034 |
230 | * used in LG TDVS H061F and LG TDVS H062F | 230 | * used in LG TDVS-H061F, LG TDVS-H062F and LG TDVS-H064F |
231 | */ | 231 | */ |
232 | struct dvb_pll_desc dvb_pll_tdvs_tua6034 = { | 232 | struct dvb_pll_desc dvb_pll_lg_tdvs_h06xf = { |
233 | .name = "LG/Infineon TUA6034", | 233 | .name = "LG TDVS-H06xF", |
234 | .min = 54000000, | 234 | .min = 54000000, |
235 | .max = 863000000, | 235 | .max = 863000000, |
236 | .count = 3, | 236 | .count = 3, |
@@ -240,7 +240,7 @@ struct dvb_pll_desc dvb_pll_tdvs_tua6034 = { | |||
240 | { 999999999, 44000000, 62500, 0xce, 0x04 }, | 240 | { 999999999, 44000000, 62500, 0xce, 0x04 }, |
241 | }, | 241 | }, |
242 | }; | 242 | }; |
243 | EXPORT_SYMBOL(dvb_pll_tdvs_tua6034); | 243 | EXPORT_SYMBOL(dvb_pll_lg_tdvs_h06xf); |
244 | 244 | ||
245 | /* Philips FMD1216ME | 245 | /* Philips FMD1216ME |
246 | * used in Medion Hybrid PCMCIA card and USB Box | 246 | * used in Medion Hybrid PCMCIA card and USB Box |
@@ -419,6 +419,19 @@ struct dvb_pll_desc dvb_pll_thomson_fe6600 = { | |||
419 | }; | 419 | }; |
420 | EXPORT_SYMBOL(dvb_pll_thomson_fe6600); | 420 | EXPORT_SYMBOL(dvb_pll_thomson_fe6600); |
421 | 421 | ||
422 | struct dvb_pll_priv { | ||
423 | /* i2c details */ | ||
424 | int pll_i2c_address; | ||
425 | struct i2c_adapter *i2c; | ||
426 | |||
427 | /* the PLL descriptor */ | ||
428 | struct dvb_pll_desc *pll_desc; | ||
429 | |||
430 | /* cached frequency/bandwidth */ | ||
431 | u32 frequency; | ||
432 | u32 bandwidth; | ||
433 | }; | ||
434 | |||
422 | /* ----------------------------------------------------------- */ | 435 | /* ----------------------------------------------------------- */ |
423 | /* code */ | 436 | /* code */ |
424 | 437 | ||
@@ -443,7 +456,8 @@ int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, | |||
443 | if (debug) | 456 | if (debug) |
444 | printk("pll: %s: freq=%d bw=%d | i=%d/%d\n", | 457 | printk("pll: %s: freq=%d bw=%d | i=%d/%d\n", |
445 | desc->name, freq, bandwidth, i, desc->count); | 458 | desc->name, freq, bandwidth, i, desc->count); |
446 | BUG_ON(i == desc->count); | 459 | if (i == desc->count) |
460 | return -EINVAL; | ||
447 | 461 | ||
448 | div = (freq + desc->entries[i].offset) / desc->entries[i].stepsize; | 462 | div = (freq + desc->entries[i].offset) / desc->entries[i].stepsize; |
449 | buf[0] = div >> 8; | 463 | buf[0] = div >> 8; |
@@ -462,6 +476,163 @@ int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, | |||
462 | } | 476 | } |
463 | EXPORT_SYMBOL(dvb_pll_configure); | 477 | EXPORT_SYMBOL(dvb_pll_configure); |
464 | 478 | ||
479 | static int dvb_pll_release(struct dvb_frontend *fe) | ||
480 | { | ||
481 | if (fe->tuner_priv) | ||
482 | kfree(fe->tuner_priv); | ||
483 | fe->tuner_priv = NULL; | ||
484 | return 0; | ||
485 | } | ||
486 | |||
487 | static int dvb_pll_sleep(struct dvb_frontend *fe) | ||
488 | { | ||
489 | struct dvb_pll_priv *priv = fe->tuner_priv; | ||
490 | u8 buf[4]; | ||
491 | struct i2c_msg msg = | ||
492 | { .addr = priv->pll_i2c_address, .flags = 0, .buf = buf, .len = sizeof(buf) }; | ||
493 | int i; | ||
494 | int result; | ||
495 | |||
496 | for (i = 0; i < priv->pll_desc->count; i++) { | ||
497 | if (priv->pll_desc->entries[i].limit == 0) | ||
498 | break; | ||
499 | } | ||
500 | if (i == priv->pll_desc->count) | ||
501 | return 0; | ||
502 | |||
503 | buf[0] = 0; | ||
504 | buf[1] = 0; | ||
505 | buf[2] = priv->pll_desc->entries[i].config; | ||
506 | buf[3] = priv->pll_desc->entries[i].cb; | ||
507 | |||
508 | if (fe->ops.i2c_gate_ctrl) | ||
509 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
510 | if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) { | ||
511 | return result; | ||
512 | } | ||
513 | |||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | static int dvb_pll_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) | ||
518 | { | ||
519 | struct dvb_pll_priv *priv = fe->tuner_priv; | ||
520 | u8 buf[4]; | ||
521 | struct i2c_msg msg = | ||
522 | { .addr = priv->pll_i2c_address, .flags = 0, .buf = buf, .len = sizeof(buf) }; | ||
523 | int result; | ||
524 | u32 div; | ||
525 | int i; | ||
526 | u32 bandwidth = 0; | ||
527 | |||
528 | if (priv->i2c == NULL) | ||
529 | return -EINVAL; | ||
530 | |||
531 | // DVBT bandwidth only just now | ||
532 | if (fe->ops.info.type == FE_OFDM) { | ||
533 | bandwidth = params->u.ofdm.bandwidth; | ||
534 | } | ||
535 | |||
536 | if ((result = dvb_pll_configure(priv->pll_desc, buf, params->frequency, bandwidth)) != 0) | ||
537 | return result; | ||
538 | |||
539 | if (fe->ops.i2c_gate_ctrl) | ||
540 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
541 | if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) { | ||
542 | return result; | ||
543 | } | ||
544 | |||
545 | // calculate the frequency we set it to | ||
546 | for (i = 0; i < priv->pll_desc->count; i++) { | ||
547 | if (params->frequency > priv->pll_desc->entries[i].limit) | ||
548 | continue; | ||
549 | break; | ||
550 | } | ||
551 | div = (params->frequency + priv->pll_desc->entries[i].offset) / priv->pll_desc->entries[i].stepsize; | ||
552 | priv->frequency = (div * priv->pll_desc->entries[i].stepsize) - priv->pll_desc->entries[i].offset; | ||
553 | priv->bandwidth = bandwidth; | ||
554 | |||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | static int dvb_pll_calc_regs(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8 *buf, int buf_len) | ||
559 | { | ||
560 | struct dvb_pll_priv *priv = fe->tuner_priv; | ||
561 | int result; | ||
562 | u32 div; | ||
563 | int i; | ||
564 | u32 bandwidth = 0; | ||
565 | |||
566 | if (buf_len < 5) | ||
567 | return -EINVAL; | ||
568 | |||
569 | // DVBT bandwidth only just now | ||
570 | if (fe->ops.info.type == FE_OFDM) { | ||
571 | bandwidth = params->u.ofdm.bandwidth; | ||
572 | } | ||
573 | |||
574 | if ((result = dvb_pll_configure(priv->pll_desc, buf+1, params->frequency, bandwidth)) != 0) | ||
575 | return result; | ||
576 | buf[0] = priv->pll_i2c_address; | ||
577 | |||
578 | // calculate the frequency we set it to | ||
579 | for (i = 0; i < priv->pll_desc->count; i++) { | ||
580 | if (params->frequency > priv->pll_desc->entries[i].limit) | ||
581 | continue; | ||
582 | break; | ||
583 | } | ||
584 | div = (params->frequency + priv->pll_desc->entries[i].offset) / priv->pll_desc->entries[i].stepsize; | ||
585 | priv->frequency = (div * priv->pll_desc->entries[i].stepsize) - priv->pll_desc->entries[i].offset; | ||
586 | priv->bandwidth = bandwidth; | ||
587 | |||
588 | return 5; | ||
589 | } | ||
590 | |||
591 | static int dvb_pll_get_frequency(struct dvb_frontend *fe, u32 *frequency) | ||
592 | { | ||
593 | struct dvb_pll_priv *priv = fe->tuner_priv; | ||
594 | *frequency = priv->frequency; | ||
595 | return 0; | ||
596 | } | ||
597 | |||
598 | static int dvb_pll_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) | ||
599 | { | ||
600 | struct dvb_pll_priv *priv = fe->tuner_priv; | ||
601 | *bandwidth = priv->bandwidth; | ||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | static struct dvb_tuner_ops dvb_pll_tuner_ops = { | ||
606 | .release = dvb_pll_release, | ||
607 | .sleep = dvb_pll_sleep, | ||
608 | .set_params = dvb_pll_set_params, | ||
609 | .calc_regs = dvb_pll_calc_regs, | ||
610 | .get_frequency = dvb_pll_get_frequency, | ||
611 | .get_bandwidth = dvb_pll_get_bandwidth, | ||
612 | }; | ||
613 | |||
614 | int dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc) | ||
615 | { | ||
616 | struct dvb_pll_priv *priv = NULL; | ||
617 | |||
618 | priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL); | ||
619 | if (priv == NULL) | ||
620 | return -ENOMEM; | ||
621 | |||
622 | priv->pll_i2c_address = pll_addr; | ||
623 | priv->i2c = i2c; | ||
624 | priv->pll_desc = desc; | ||
625 | |||
626 | memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops, sizeof(struct dvb_tuner_ops)); | ||
627 | strncpy(fe->ops.tuner_ops.info.name, desc->name, 128); | ||
628 | fe->ops.tuner_ops.info.frequency_min = desc->min; | ||
629 | fe->ops.tuner_ops.info.frequency_min = desc->max; | ||
630 | |||
631 | fe->tuner_priv = priv; | ||
632 | return 0; | ||
633 | } | ||
634 | EXPORT_SYMBOL(dvb_pll_attach); | ||
635 | |||
465 | MODULE_DESCRIPTION("dvb pll library"); | 636 | MODULE_DESCRIPTION("dvb pll library"); |
466 | MODULE_AUTHOR("Gerd Knorr"); | 637 | MODULE_AUTHOR("Gerd Knorr"); |
467 | MODULE_LICENSE("GPL"); | 638 | MODULE_LICENSE("GPL"); |