diff options
author | Andrew de Quincey <adq_dvb@lidskialf.net> | 2006-04-18 16:47:12 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-06-25 00:59:15 -0400 |
commit | 272bc4db791bc49d50d5f77f24c688be6d1907f8 (patch) | |
tree | d617d3868f282e85674e34ddac1e380e173b3bab /drivers/media | |
parent | a263394b4866a89860d7b5dbcacf33a32f00d206 (diff) |
V4L/DVB (3885): Convert dvb-pll to be a refactored tuner
Rename pll calls to appropriate tuner calls.
Remove pll functions from demod structures.
Hook tuner call into tuner_ops.
Remove BUG_ON() and convert to a soft error.
Signed-off-by: Andrew de Quincey <adq_dvb@lidskialf.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/dvb/frontends/dvb-pll.c | 173 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/dvb-pll.h | 16 |
2 files changed, 187 insertions, 2 deletions
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c index 50a79eea892a..87fd8861a411 100644 --- a/drivers/media/dvb/frontends/dvb-pll.c +++ b/drivers/media/dvb/frontends/dvb-pll.c | |||
@@ -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_pllbuf(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 | .pllbuf = dvb_pll_pllbuf, | ||
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"); |
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h index 2b8461784989..3908ae1d446a 100644 --- a/drivers/media/dvb/frontends/dvb-pll.h +++ b/drivers/media/dvb/frontends/dvb-pll.h | |||
@@ -5,6 +5,9 @@ | |||
5 | #ifndef __DVB_PLL_H__ | 5 | #ifndef __DVB_PLL_H__ |
6 | #define __DVB_PLL_H__ | 6 | #define __DVB_PLL_H__ |
7 | 7 | ||
8 | #include <linux/i2c.h> | ||
9 | #include "dvb_frontend.h" | ||
10 | |||
8 | struct dvb_pll_desc { | 11 | struct dvb_pll_desc { |
9 | char *name; | 12 | char *name; |
10 | u32 min; | 13 | u32 min; |
@@ -44,7 +47,18 @@ extern struct dvb_pll_desc dvb_pll_philips_td1316; | |||
44 | 47 | ||
45 | extern struct dvb_pll_desc dvb_pll_thomson_fe6600; | 48 | extern struct dvb_pll_desc dvb_pll_thomson_fe6600; |
46 | 49 | ||
47 | int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, | 50 | extern int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, |
48 | u32 freq, int bandwidth); | 51 | u32 freq, int bandwidth); |
49 | 52 | ||
53 | /** | ||
54 | * Attach a dvb-pll to the supplied frontend structure. | ||
55 | * | ||
56 | * @param fe Frontend to attach to. | ||
57 | * @param pll_addr i2c address of the PLL (if used). | ||
58 | * @param i2c i2c adapter to use (set to NULL if not used). | ||
59 | * @param desc dvb_pll_desc to use. | ||
60 | * @return 0 on success, nonzero on failure. | ||
61 | */ | ||
62 | extern int dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc); | ||
63 | |||
50 | #endif | 64 | #endif |