aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tvp5150.c
diff options
context:
space:
mode:
authorakpm@osdl.org <akpm@osdl.org>2005-11-09 00:37:07 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-09 10:56:15 -0500
commita6c2ba283565dbc9f055dcb2ecba1971460bb535 (patch)
treefd262f8af5bffc99753ff861be85574616113467 /drivers/media/video/tvp5150.c
parent4b017415fc9ab63f7c0e49aced5e403c18d55659 (diff)
[PATCH] v4l: 716: support for em28xx board family
- Added support for em28xx board family Signed-off-by: Ludovico Cavedon <cavedon@sssup.it> Signed-off-by: Markus Rechberger <mrechberger@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/media/video/tvp5150.c')
-rw-r--r--drivers/media/video/tvp5150.c337
1 files changed, 226 insertions, 111 deletions
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index 6e3ba23104d2..03f360b45fdf 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -35,6 +35,47 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
35 printk(format , ##args); \ 35 printk(format , ##args); \
36 } while (0) 36 } while (0)
37 37
38/* supported controls */
39static struct v4l2_queryctrl tvp5150_qctrl[] = {
40 {
41 .id = V4L2_CID_BRIGHTNESS,
42 .type = V4L2_CTRL_TYPE_INTEGER,
43 .name = "Brightness",
44 .minimum = 0,
45 .maximum = 255,
46 .step = 1,
47 .default_value = 0,
48 .flags = 0,
49 }, {
50 .id = V4L2_CID_CONTRAST,
51 .type = V4L2_CTRL_TYPE_INTEGER,
52 .name = "Contrast",
53 .minimum = 0,
54 .maximum = 255,
55 .step = 0x1,
56 .default_value = 0x10,
57 .flags = 0,
58 }, {
59 .id = V4L2_CID_SATURATION,
60 .type = V4L2_CTRL_TYPE_INTEGER,
61 .name = "Saturation",
62 .minimum = 0,
63 .maximum = 255,
64 .step = 0x1,
65 .default_value = 0x10,
66 .flags = 0,
67 }, {
68 .id = V4L2_CID_HUE,
69 .type = V4L2_CTRL_TYPE_INTEGER,
70 .name = "Hue",
71 .minimum = -128,
72 .maximum = 127,
73 .step = 0x1,
74 .default_value = 0x10,
75 .flags = 0,
76 }
77};
78
38struct tvp5150 { 79struct tvp5150 {
39 struct i2c_client *client; 80 struct i2c_client *client;
40 81
@@ -73,7 +114,7 @@ static inline void tvp5150_write(struct i2c_client *c, unsigned char addr,
73 114
74 buffer[0] = addr; 115 buffer[0] = addr;
75 buffer[1] = value; 116 buffer[1] = value;
76 dprintk(1,"tvp5150: writing 0x%02x 0x%02x\n",buffer[0],buffer[1]); 117 dprintk(1, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
77 if (2 != (rc = i2c_master_send(c, buffer, 2))) 118 if (2 != (rc = i2c_master_send(c, buffer, 2)))
78 dprintk(0, "i2c i/o error: rc == %d (should be 2)\n", rc); 119 dprintk(0, "i2c i/o error: rc == %d (should be 2)\n", rc);
79} 120}
@@ -398,28 +439,11 @@ static inline void tvp5150_selmux(struct i2c_client *c,
398 enum tvp5150_input input) 439 enum tvp5150_input input)
399{ 440{
400 struct tvp5150 *decoder = i2c_get_clientdata(c); 441 struct tvp5150 *decoder = i2c_get_clientdata(c);
401 int tvp_input;
402
403 /* FIXME: It is dependent of basic driver */
404 switch (input)
405 {
406 case 2:
407 tvp_input=TVP5150_ANALOG_CH0;
408 break;
409 case 0:
410 tvp_input=TVP5150_ANALOG_CH1;
411 break;
412 case 1:
413 tvp_input=TVP5150_SVIDEO;
414 break;
415 default:
416 tvp_input=TVP5150_BLACK_SCREEN;
417 }
418 442
419 if (!decoder->enable) 443 if (!decoder->enable)
420 tvp_input|=TVP5150_BLACK_SCREEN; 444 input |= TVP5150_BLACK_SCREEN;
421 445
422 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, tvp_input); 446 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
423}; 447};
424 448
425static inline void tvp5150_reset(struct i2c_client *c) 449static inline void tvp5150_reset(struct i2c_client *c)
@@ -432,7 +456,7 @@ static inline void tvp5150_reset(struct i2c_client *c)
432 tvp5150_write(c, TVP5150_ANAL_CHL_CTL, 0x15); 456 tvp5150_write(c, TVP5150_ANAL_CHL_CTL, 0x15);
433 457
434 /* Normal Operation */ 458 /* Normal Operation */
435// tvp5150_write(c, TVP5150_OP_MODE_CTL, 0x00); 459// tvp5150_write(c, TVP5150_OP_MODE_CTL, 0x00);
436 460
437 /* Activate YCrCb output 0x9 or 0xd ? */ 461 /* Activate YCrCb output 0x9 or 0xd ? */
438 tvp5150_write(c, TVP5150_MISC_CTL, 0x6f); 462 tvp5150_write(c, TVP5150_MISC_CTL, 0x6f);
@@ -458,6 +482,50 @@ static inline void tvp5150_reset(struct i2c_client *c)
458 tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8); 482 tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8);
459}; 483};
460 484
485static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
486{
487/* struct tvp5150 *decoder = i2c_get_clientdata(c); */
488
489 switch (ctrl->id) {
490 case V4L2_CID_BRIGHTNESS:
491 ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL);
492 return 0;
493 case V4L2_CID_CONTRAST:
494 ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL);
495 return 0;
496 case V4L2_CID_SATURATION:
497 ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL);
498 return 0;
499 case V4L2_CID_HUE:
500 ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL);
501 return 0;
502 default:
503 return -EINVAL;
504 }
505}
506
507static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
508{
509/* struct tvp5150 *decoder = i2c_get_clientdata(c); */
510
511 switch (ctrl->id) {
512 case V4L2_CID_BRIGHTNESS:
513 tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value);
514 return 0;
515 case V4L2_CID_CONTRAST:
516 tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value);
517 return 0;
518 case V4L2_CID_SATURATION:
519 tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value);
520 return 0;
521 case V4L2_CID_HUE:
522 tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value);
523 return 0;
524 default:
525 return -EINVAL;
526 }
527}
528
461/**************************************************************************** 529/****************************************************************************
462 I2C Command 530 I2C Command
463 ****************************************************************************/ 531 ****************************************************************************/
@@ -478,21 +546,21 @@ static int tvp5150_command(struct i2c_client *client,
478 break; 546 break;
479 547
480 case DECODER_GET_CAPABILITIES: 548 case DECODER_GET_CAPABILITIES:
481 { 549 {
482 struct video_decoder_capability *cap = arg; 550 struct video_decoder_capability *cap = arg;
483 551
484 cap->flags = VIDEO_DECODER_PAL | 552 cap->flags = VIDEO_DECODER_PAL |
485 VIDEO_DECODER_NTSC | 553 VIDEO_DECODER_NTSC |
486 VIDEO_DECODER_SECAM | 554 VIDEO_DECODER_SECAM |
487 VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR; 555 VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR;
488 cap->inputs = 3; 556 cap->inputs = 3;
489 cap->outputs = 1; 557 cap->outputs = 1;
490 break; 558 break;
491 } 559 }
492 case DECODER_GET_STATUS: 560 case DECODER_GET_STATUS:
493 { 561 {
494 break; 562 break;
495 } 563 }
496 564
497 case DECODER_SET_GPIO: 565 case DECODER_SET_GPIO:
498 break; 566 break;
@@ -501,87 +569,138 @@ static int tvp5150_command(struct i2c_client *client,
501 break; 569 break;
502 570
503 case DECODER_SET_NORM: 571 case DECODER_SET_NORM:
504 { 572 {
505 int *iarg = arg; 573 int *iarg = arg;
506 574
507 switch (*iarg) { 575 switch (*iarg) {
508 576
509 case VIDEO_MODE_NTSC: 577 case VIDEO_MODE_NTSC:
510 break; 578 break;
511 579
512 case VIDEO_MODE_PAL: 580 case VIDEO_MODE_PAL:
513 break; 581 break;
514 582
515 case VIDEO_MODE_SECAM: 583 case VIDEO_MODE_SECAM:
516 break; 584 break;
517 585
518 case VIDEO_MODE_AUTO: 586 case VIDEO_MODE_AUTO:
519 break; 587 break;
520 588
521 default: 589 default:
522 return -EINVAL; 590 return -EINVAL;
523 591
592 }
593 decoder->norm = *iarg;
594 break;
524 } 595 }
525 decoder->norm = *iarg;
526 break;
527 }
528 case DECODER_SET_INPUT: 596 case DECODER_SET_INPUT:
529 { 597 {
530 int *iarg = arg; 598 int *iarg = arg;
531 if (*iarg < 0 || *iarg > 3) { 599 if (*iarg < 0 || *iarg > 3) {
532 return -EINVAL; 600 return -EINVAL;
533 } 601 }
534 602
535 decoder->input=*iarg; 603 decoder->input = *iarg;
536 tvp5150_selmux(client, decoder->input); 604 tvp5150_selmux(client, decoder->input);
537 605
538 break; 606 break;
539 } 607 }
540 case DECODER_SET_OUTPUT: 608 case DECODER_SET_OUTPUT:
541 { 609 {
542 int *iarg = arg; 610 int *iarg = arg;
543 611
544 /* not much choice of outputs */ 612 /* not much choice of outputs */
545 if (*iarg != 0) { 613 if (*iarg != 0) {
546 return -EINVAL; 614 return -EINVAL;
615 }
616 break;
547 } 617 }
548 break;
549 }
550 case DECODER_ENABLE_OUTPUT: 618 case DECODER_ENABLE_OUTPUT:
551 { 619 {
552 int *iarg = arg; 620 int *iarg = arg;
553 621
554 decoder->enable = (*iarg != 0); 622 decoder->enable = (*iarg != 0);
555 623
556 tvp5150_selmux(client, decoder->input); 624 tvp5150_selmux(client, decoder->input);
557 625
558 break; 626 break;
559 }
560 case DECODER_SET_PICTURE:
561 {
562 struct video_picture *pic = arg;
563 if (decoder->bright != pic->brightness) {
564 /* We want 0 to 255 we get 0-65535 */
565 decoder->bright = pic->brightness;
566 tvp5150_write(client, TVP5150_BRIGHT_CTL, decoder->bright >> 8);
567 } 627 }
568 if (decoder->contrast != pic->contrast) { 628 case VIDIOC_QUERYCTRL:
569 /* We want 0 to 255 we get 0-65535 */ 629 {
570 decoder->contrast = pic->contrast; 630 struct v4l2_queryctrl *qc = arg;
571 tvp5150_write(client, TVP5150_CONTRAST_CTL, decoder->contrast >> 8); 631 u8 i, n;
632
633 dprintk(1, KERN_DEBUG "VIDIOC_QUERYCTRL");
634
635 n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
636 for (i = 0; i < n; i++)
637 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
638 memcpy(qc, &(tvp5150_qctrl[i]),
639 sizeof(*qc));
640 return 0;
641 }
642
643 return -EINVAL;
572 } 644 }
573 if (decoder->sat != pic->colour) { 645 case VIDIOC_G_CTRL:
574 /* We want 0 to 255 we get 0-65535 */ 646 {
575 decoder->sat = pic->colour; 647 struct v4l2_control *ctrl = arg;
576 tvp5150_write(client, TVP5150_SATURATION_CTL, decoder->contrast >> 8); 648 dprintk(1, KERN_DEBUG "VIDIOC_G_CTRL");
649
650 return tvp5150_get_ctrl(client, ctrl);
577 } 651 }
578 if (decoder->hue != pic->hue) { 652 case VIDIOC_S_CTRL_OLD: /* ??? */
579 /* We want -128 to 127 we get 0-65535 */ 653 case VIDIOC_S_CTRL:
580 decoder->hue = pic->hue; 654 {
581 tvp5150_write(client, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8); 655 struct v4l2_control *ctrl = arg;
656 u8 i, n;
657 dprintk(1, KERN_DEBUG "VIDIOC_S_CTRL");
658 n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
659 for (i = 0; i < n; i++)
660 if (ctrl->id == tvp5150_qctrl[i].id) {
661 if (ctrl->value <
662 tvp5150_qctrl[i].minimum
663 || ctrl->value >
664 tvp5150_qctrl[i].maximum)
665 return -ERANGE;
666 dprintk(1,
667 KERN_DEBUG
668 "VIDIOC_S_CTRL: id=%d, value=%d",
669 ctrl->id, ctrl->value);
670 return tvp5150_set_ctrl(client, ctrl);
671 }
672 return -EINVAL;
673 }
674
675 case DECODER_SET_PICTURE:
676 {
677 struct video_picture *pic = arg;
678 if (decoder->bright != pic->brightness) {
679 /* We want 0 to 255 we get 0-65535 */
680 decoder->bright = pic->brightness;
681 tvp5150_write(client, TVP5150_BRIGHT_CTL,
682 decoder->bright >> 8);
683 }
684 if (decoder->contrast != pic->contrast) {
685 /* We want 0 to 255 we get 0-65535 */
686 decoder->contrast = pic->contrast;
687 tvp5150_write(client, TVP5150_CONTRAST_CTL,
688 decoder->contrast >> 8);
689 }
690 if (decoder->sat != pic->colour) {
691 /* We want 0 to 255 we get 0-65535 */
692 decoder->sat = pic->colour;
693 tvp5150_write(client, TVP5150_SATURATION_CTL,
694 decoder->contrast >> 8);
695 }
696 if (decoder->hue != pic->hue) {
697 /* We want -128 to 127 we get 0-65535 */
698 decoder->hue = pic->hue;
699 tvp5150_write(client, TVP5150_HUE_CTL,
700 (decoder->hue - 32768) >> 8);
701 }
702 break;
582 } 703 }
583 break;
584 }
585 default: 704 default:
586 return -EINVAL; 705 return -EINVAL;
587 } 706 }
@@ -594,15 +713,14 @@ static int tvp5150_command(struct i2c_client *client,
594 ****************************************************************************/ 713 ****************************************************************************/
595static struct i2c_driver driver; 714static struct i2c_driver driver;
596 715
597static struct i2c_client client_template = 716static struct i2c_client client_template = {
598{ 717 .name = "(unset)",
599 .name = "(unset)", 718 .flags = I2C_CLIENT_ALLOW_USE,
600 .flags = I2C_CLIENT_ALLOW_USE, 719 .driver = &driver,
601 .driver = &driver,
602}; 720};
603 721
604static int tvp5150_detect_client (struct i2c_adapter *adapter, 722static int tvp5150_detect_client(struct i2c_adapter *adapter,
605 int address, int kind) 723 int address, int kind)
606{ 724{
607 struct i2c_client *client; 725 struct i2c_client *client;
608 struct tvp5150 *core; 726 struct tvp5150 *core;
@@ -625,7 +743,7 @@ static int tvp5150_detect_client (struct i2c_adapter *adapter,
625 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 743 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
626 if (client == 0) 744 if (client == 0)
627 return -ENOMEM; 745 return -ENOMEM;
628 memcpy(client,&client_template,sizeof(struct i2c_client)); 746 memcpy(client, &client_template, sizeof(struct i2c_client));
629 747
630 core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL); 748 core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL);
631 if (core == 0) { 749 if (core == 0) {
@@ -651,13 +769,13 @@ static int tvp5150_detect_client (struct i2c_adapter *adapter,
651 return rv; 769 return rv;
652 } 770 }
653 771
654 dump_reg (client); 772 if (debug > 1)
773 dump_reg(client);
655 774
656 return 0; 775 return 0;
657} 776}
658 777
659static int 778static int tvp5150_attach_adapter(struct i2c_adapter *adapter)
660tvp5150_attach_adapter (struct i2c_adapter *adapter)
661{ 779{
662 dprintk(1, 780 dprintk(1,
663 KERN_INFO 781 KERN_INFO
@@ -666,8 +784,7 @@ tvp5150_attach_adapter (struct i2c_adapter *adapter)
666 return i2c_probe(adapter, &addr_data, &tvp5150_detect_client); 784 return i2c_probe(adapter, &addr_data, &tvp5150_detect_client);
667} 785}
668 786
669static int 787static int tvp5150_detach_client(struct i2c_client *client)
670tvp5150_detach_client (struct i2c_client *client)
671{ 788{
672 struct tvp5150 *decoder = i2c_get_clientdata(client); 789 struct tvp5150 *decoder = i2c_get_clientdata(client);
673 int err; 790 int err;
@@ -699,14 +816,12 @@ static struct i2c_driver driver = {
699 .command = tvp5150_command, 816 .command = tvp5150_command,
700}; 817};
701 818
702static int __init 819static int __init tvp5150_init(void)
703tvp5150_init (void)
704{ 820{
705 return i2c_add_driver(&driver); 821 return i2c_add_driver(&driver);
706} 822}
707 823
708static void __exit 824static void __exit tvp5150_exit(void)
709tvp5150_exit (void)
710{ 825{
711 i2c_del_driver(&driver); 826 i2c_del_driver(&driver);
712} 827}