diff options
Diffstat (limited to 'drivers/media/video/tvp5150.c')
-rw-r--r-- | drivers/media/video/tvp5150.c | 535 |
1 files changed, 434 insertions, 101 deletions
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c index a60442ea4f94..c35b8042eee5 100644 --- a/drivers/media/video/tvp5150.c +++ b/drivers/media/video/tvp5150.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/videodev.h> | 9 | #include <linux/videodev.h> |
10 | #include <linux/delay.h> | 10 | #include <linux/delay.h> |
11 | #include <linux/video_decoder.h> | 11 | #include <linux/video_decoder.h> |
12 | #include <media/v4l2-common.h> | ||
12 | 13 | ||
13 | #include "tvp5150_reg.h" | 14 | #include "tvp5150_reg.h" |
14 | 15 | ||
@@ -28,33 +29,38 @@ static int debug = 0; | |||
28 | module_param(debug, int, 0); | 29 | module_param(debug, int, 0); |
29 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); | 30 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
30 | 31 | ||
31 | #define dprintk(num, format, args...) \ | 32 | #define tvp5150_info(fmt, arg...) do { \ |
33 | printk(KERN_INFO "%s %d-%04x: " fmt, c->driver->driver.name, \ | ||
34 | i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0) | ||
35 | #define tvp5150_dbg(num, fmt, arg...) \ | ||
32 | do { \ | 36 | do { \ |
33 | if (debug >= num) \ | 37 | if (debug >= num) \ |
34 | printk(format, ##args); \ | 38 | printk(KERN_DEBUG "%s debug %d-%04x: " fmt,\ |
35 | } while (0) | 39 | c->driver->driver.name, \ |
40 | i2c_adapter_id(c->adapter), \ | ||
41 | c->addr , ## arg); } while (0) | ||
36 | 42 | ||
37 | /* supported controls */ | 43 | /* supported controls */ |
38 | static struct v4l2_queryctrl tvp5150_qctrl[] = { | 44 | static struct v4l2_queryctrl tvp5150_qctrl[] = { |
39 | { | 45 | { |
40 | .id = V4L2_CID_BRIGHTNESS, | 46 | .id = V4L2_CID_BRIGHTNESS, |
41 | .type = V4L2_CTRL_TYPE_INTEGER, | 47 | .type = V4L2_CTRL_TYPE_INTEGER, |
42 | .name = "Brightness", | 48 | .name = "Brightness", |
43 | .minimum = 0, | 49 | .minimum = 0, |
44 | .maximum = 255, | 50 | .maximum = 255, |
45 | .step = 1, | 51 | .step = 1, |
46 | .default_value = 0, | 52 | .default_value = 0, |
47 | .flags = 0, | 53 | .flags = 0, |
48 | }, { | 54 | }, { |
49 | .id = V4L2_CID_CONTRAST, | 55 | .id = V4L2_CID_CONTRAST, |
50 | .type = V4L2_CTRL_TYPE_INTEGER, | 56 | .type = V4L2_CTRL_TYPE_INTEGER, |
51 | .name = "Contrast", | 57 | .name = "Contrast", |
52 | .minimum = 0, | 58 | .minimum = 0, |
53 | .maximum = 255, | 59 | .maximum = 255, |
54 | .step = 0x1, | 60 | .step = 0x1, |
55 | .default_value = 0x10, | 61 | .default_value = 0x10, |
56 | .flags = 0, | 62 | .flags = 0, |
57 | }, { | 63 | }, { |
58 | .id = V4L2_CID_SATURATION, | 64 | .id = V4L2_CID_SATURATION, |
59 | .type = V4L2_CTRL_TYPE_INTEGER, | 65 | .type = V4L2_CTRL_TYPE_INTEGER, |
60 | .name = "Saturation", | 66 | .name = "Saturation", |
@@ -63,16 +69,16 @@ static struct v4l2_queryctrl tvp5150_qctrl[] = { | |||
63 | .step = 0x1, | 69 | .step = 0x1, |
64 | .default_value = 0x10, | 70 | .default_value = 0x10, |
65 | .flags = 0, | 71 | .flags = 0, |
66 | }, { | 72 | }, { |
67 | .id = V4L2_CID_HUE, | 73 | .id = V4L2_CID_HUE, |
68 | .type = V4L2_CTRL_TYPE_INTEGER, | 74 | .type = V4L2_CTRL_TYPE_INTEGER, |
69 | .name = "Hue", | 75 | .name = "Hue", |
70 | .minimum = -128, | 76 | .minimum = -128, |
71 | .maximum = 127, | 77 | .maximum = 127, |
72 | .step = 0x1, | 78 | .step = 0x1, |
73 | .default_value = 0x10, | 79 | .default_value = 0x10, |
74 | .flags = 0, | 80 | .flags = 0, |
75 | } | 81 | } |
76 | }; | 82 | }; |
77 | 83 | ||
78 | struct tvp5150 { | 84 | struct tvp5150 { |
@@ -94,12 +100,14 @@ static inline int tvp5150_read(struct i2c_client *c, unsigned char addr) | |||
94 | 100 | ||
95 | buffer[0] = addr; | 101 | buffer[0] = addr; |
96 | if (1 != (rc = i2c_master_send(c, buffer, 1))) | 102 | if (1 != (rc = i2c_master_send(c, buffer, 1))) |
97 | dprintk(0, "i2c i/o error: rc == %d (should be 1)\n", rc); | 103 | tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc); |
98 | 104 | ||
99 | msleep(10); | 105 | msleep(10); |
100 | 106 | ||
101 | if (1 != (rc = i2c_master_recv(c, buffer, 1))) | 107 | if (1 != (rc = i2c_master_recv(c, buffer, 1))) |
102 | dprintk(0, "i2c i/o error: rc == %d (should be 1)\n", rc); | 108 | tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc); |
109 | |||
110 | tvp5150_dbg(2, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]); | ||
103 | 111 | ||
104 | return (buffer[0]); | 112 | return (buffer[0]); |
105 | } | 113 | } |
@@ -109,13 +117,12 @@ static inline void tvp5150_write(struct i2c_client *c, unsigned char addr, | |||
109 | { | 117 | { |
110 | unsigned char buffer[2]; | 118 | unsigned char buffer[2]; |
111 | int rc; | 119 | int rc; |
112 | /* struct tvp5150 *core = i2c_get_clientdata(c); */ | ||
113 | 120 | ||
114 | buffer[0] = addr; | 121 | buffer[0] = addr; |
115 | buffer[1] = value; | 122 | buffer[1] = value; |
116 | dprintk(1, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]); | 123 | tvp5150_dbg(2, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]); |
117 | if (2 != (rc = i2c_master_send(c, buffer, 2))) | 124 | if (2 != (rc = i2c_master_send(c, buffer, 2))) |
118 | dprintk(0, "i2c i/o error: rc == %d (should be 2)\n", rc); | 125 | tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 2)\n", rc); |
119 | } | 126 | } |
120 | 127 | ||
121 | static void dump_reg(struct i2c_client *c) | 128 | static void dump_reg(struct i2c_client *c) |
@@ -437,48 +444,346 @@ enum tvp5150_input { | |||
437 | static inline void tvp5150_selmux(struct i2c_client *c, | 444 | static inline void tvp5150_selmux(struct i2c_client *c, |
438 | enum tvp5150_input input) | 445 | enum tvp5150_input input) |
439 | { | 446 | { |
447 | int opmode=0; | ||
448 | |||
440 | struct tvp5150 *decoder = i2c_get_clientdata(c); | 449 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
441 | 450 | ||
442 | if (!decoder->enable) | 451 | if (!decoder->enable) |
443 | input |= TVP5150_BLACK_SCREEN; | 452 | input |= TVP5150_BLACK_SCREEN; |
444 | 453 | ||
454 | switch (input) { | ||
455 | case TVP5150_ANALOG_CH0: | ||
456 | case TVP5150_ANALOG_CH1: | ||
457 | opmode=0x30; /* TV Mode */ | ||
458 | break; | ||
459 | default: | ||
460 | opmode=0; /* Auto Mode */ | ||
461 | break; | ||
462 | } | ||
463 | |||
464 | tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode); | ||
445 | tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input); | 465 | tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input); |
446 | }; | 466 | }; |
447 | 467 | ||
448 | static inline void tvp5150_reset(struct i2c_client *c) | 468 | struct i2c_reg_value { |
469 | unsigned char reg; | ||
470 | unsigned char value; | ||
471 | }; | ||
472 | |||
473 | /* Default values as sugested at TVP5150AM1 datasheet */ | ||
474 | static const struct i2c_reg_value tvp5150_init_default[] = { | ||
475 | { /* 0x00 */ | ||
476 | TVP5150_VD_IN_SRC_SEL_1,0x00 | ||
477 | }, | ||
478 | { /* 0x01 */ | ||
479 | TVP5150_ANAL_CHL_CTL,0x15 | ||
480 | }, | ||
481 | { /* 0x02 */ | ||
482 | TVP5150_OP_MODE_CTL,0x00 | ||
483 | }, | ||
484 | { /* 0x03 */ | ||
485 | TVP5150_MISC_CTL,0x01 | ||
486 | }, | ||
487 | { /* 0x06 */ | ||
488 | TVP5150_COLOR_KIL_THSH_CTL,0x10 | ||
489 | }, | ||
490 | { /* 0x07 */ | ||
491 | TVP5150_LUMA_PROC_CTL_1,0x60 | ||
492 | }, | ||
493 | { /* 0x08 */ | ||
494 | TVP5150_LUMA_PROC_CTL_2,0x00 | ||
495 | }, | ||
496 | { /* 0x09 */ | ||
497 | TVP5150_BRIGHT_CTL,0x80 | ||
498 | }, | ||
499 | { /* 0x0a */ | ||
500 | TVP5150_SATURATION_CTL,0x80 | ||
501 | }, | ||
502 | { /* 0x0b */ | ||
503 | TVP5150_HUE_CTL,0x00 | ||
504 | }, | ||
505 | { /* 0x0c */ | ||
506 | TVP5150_CONTRAST_CTL,0x80 | ||
507 | }, | ||
508 | { /* 0x0d */ | ||
509 | TVP5150_DATA_RATE_SEL,0x47 | ||
510 | }, | ||
511 | { /* 0x0e */ | ||
512 | TVP5150_LUMA_PROC_CTL_3,0x00 | ||
513 | }, | ||
514 | { /* 0x0f */ | ||
515 | TVP5150_CONF_SHARED_PIN,0x08 | ||
516 | }, | ||
517 | { /* 0x11 */ | ||
518 | TVP5150_ACT_VD_CROP_ST_MSB,0x00 | ||
519 | }, | ||
520 | { /* 0x12 */ | ||
521 | TVP5150_ACT_VD_CROP_ST_LSB,0x00 | ||
522 | }, | ||
523 | { /* 0x13 */ | ||
524 | TVP5150_ACT_VD_CROP_STP_MSB,0x00 | ||
525 | }, | ||
526 | { /* 0x14 */ | ||
527 | TVP5150_ACT_VD_CROP_STP_LSB,0x00 | ||
528 | }, | ||
529 | { /* 0x15 */ | ||
530 | TVP5150_GENLOCK,0x01 | ||
531 | }, | ||
532 | { /* 0x16 */ | ||
533 | TVP5150_HORIZ_SYNC_START,0x80 | ||
534 | }, | ||
535 | { /* 0x18 */ | ||
536 | TVP5150_VERT_BLANKING_START,0x00 | ||
537 | }, | ||
538 | { /* 0x19 */ | ||
539 | TVP5150_VERT_BLANKING_STOP,0x00 | ||
540 | }, | ||
541 | { /* 0x1a */ | ||
542 | TVP5150_CHROMA_PROC_CTL_1,0x0c | ||
543 | }, | ||
544 | { /* 0x1b */ | ||
545 | TVP5150_CHROMA_PROC_CTL_2,0x14 | ||
546 | }, | ||
547 | { /* 0x1c */ | ||
548 | TVP5150_INT_RESET_REG_B,0x00 | ||
549 | }, | ||
550 | { /* 0x1d */ | ||
551 | TVP5150_INT_ENABLE_REG_B,0x00 | ||
552 | }, | ||
553 | { /* 0x1e */ | ||
554 | TVP5150_INTT_CONFIG_REG_B,0x00 | ||
555 | }, | ||
556 | { /* 0x28 */ | ||
557 | TVP5150_VIDEO_STD,0x00 | ||
558 | }, | ||
559 | { /* 0x2e */ | ||
560 | TVP5150_MACROVISION_ON_CTR,0x0f | ||
561 | }, | ||
562 | { /* 0x2f */ | ||
563 | TVP5150_MACROVISION_OFF_CTR,0x01 | ||
564 | }, | ||
565 | { /* 0xbb */ | ||
566 | TVP5150_TELETEXT_FIL_ENA,0x00 | ||
567 | }, | ||
568 | { /* 0xc0 */ | ||
569 | TVP5150_INT_STATUS_REG_A,0x00 | ||
570 | }, | ||
571 | { /* 0xc1 */ | ||
572 | TVP5150_INT_ENABLE_REG_A,0x00 | ||
573 | }, | ||
574 | { /* 0xc2 */ | ||
575 | TVP5150_INT_CONF,0x04 | ||
576 | }, | ||
577 | { /* 0xc8 */ | ||
578 | TVP5150_FIFO_INT_THRESHOLD,0x80 | ||
579 | }, | ||
580 | { /* 0xc9 */ | ||
581 | TVP5150_FIFO_RESET,0x00 | ||
582 | }, | ||
583 | { /* 0xca */ | ||
584 | TVP5150_LINE_NUMBER_INT,0x00 | ||
585 | }, | ||
586 | { /* 0xcb */ | ||
587 | TVP5150_PIX_ALIGN_REG_LOW,0x4e | ||
588 | }, | ||
589 | { /* 0xcc */ | ||
590 | TVP5150_PIX_ALIGN_REG_HIGH,0x00 | ||
591 | }, | ||
592 | { /* 0xcd */ | ||
593 | TVP5150_FIFO_OUT_CTRL,0x01 | ||
594 | }, | ||
595 | { /* 0xcf */ | ||
596 | TVP5150_FULL_FIELD_ENA_1,0x00 | ||
597 | }, | ||
598 | { /* 0xd0 */ | ||
599 | TVP5150_FULL_FIELD_ENA_2,0x00 | ||
600 | }, | ||
601 | { /* 0xfc */ | ||
602 | TVP5150_FULL_FIELD_MODE_REG,0x7f | ||
603 | }, | ||
604 | { /* end of data */ | ||
605 | 0xff,0xff | ||
606 | } | ||
607 | }; | ||
608 | |||
609 | /* Default values as sugested at TVP5150AM1 datasheet */ | ||
610 | static const struct i2c_reg_value tvp5150_init_enable[] = { | ||
611 | { | ||
612 | TVP5150_CONF_SHARED_PIN, 2 | ||
613 | },{ /* Automatic offset and AGC enabled */ | ||
614 | TVP5150_ANAL_CHL_CTL, 0x15 | ||
615 | },{ /* Activate YCrCb output 0x9 or 0xd ? */ | ||
616 | TVP5150_MISC_CTL, 0x6f | ||
617 | },{ /* Activates video std autodetection for all standards */ | ||
618 | TVP5150_AUTOSW_MSK, 0x0 | ||
619 | },{ /* Default format: 0x47. For 4:2:2: 0x40 */ | ||
620 | TVP5150_DATA_RATE_SEL, 0x47 | ||
621 | },{ | ||
622 | TVP5150_CHROMA_PROC_CTL_1, 0x0c | ||
623 | },{ | ||
624 | TVP5150_CHROMA_PROC_CTL_2, 0x54 | ||
625 | },{ /* Non documented, but initialized on WinTV USB2 */ | ||
626 | 0x27, 0x20 | ||
627 | },{ | ||
628 | 0xff,0xff | ||
629 | } | ||
630 | }; | ||
631 | |||
632 | struct i2c_vbi_ram_value { | ||
633 | u16 reg; | ||
634 | unsigned char values[26]; | ||
635 | }; | ||
636 | |||
637 | struct i2c_vbi_ram_value vbi_ram_default[] = | ||
449 | { | 638 | { |
450 | struct tvp5150 *decoder = i2c_get_clientdata(c); | 639 | {0x010, /* WST SECAM 6 */ |
640 | { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x26, 0xe6, 0xb4, 0x0e, 0x0, 0x0, 0x0, 0x10, 0x0 } | ||
641 | }, | ||
642 | {0x030, /* WST PAL B 6 */ | ||
643 | { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x2b, 0xa6, 0x72, 0x10, 0x0, 0x0, 0x0, 0x10, 0x0 } | ||
644 | }, | ||
645 | {0x050, /* WST PAL C 6 */ | ||
646 | { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0xa6, 0x98, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } | ||
647 | }, | ||
648 | {0x070, /* WST NTSC 6 */ | ||
649 | { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } | ||
650 | }, | ||
651 | {0x090, /* NABTS, NTSC 6 */ | ||
652 | { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x15, 0x0 } | ||
653 | }, | ||
654 | {0x0b0, /* NABTS, NTSC-J 6 */ | ||
655 | { 0xaa, 0xaa, 0xff, 0xff , 0xa7, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } | ||
656 | }, | ||
657 | {0x0d0, /* CC, PAL/SECAM 6 */ | ||
658 | { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0xa6, 0x7b, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 } | ||
659 | }, | ||
660 | {0x0f0, /* CC, NTSC 6 */ | ||
661 | { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0x69, 0x8c, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 } | ||
662 | }, | ||
663 | {0x110, /* WSS, PAL/SECAM 6 */ | ||
664 | { 0x5b, 0x55, 0xc5, 0xff , 0x0, 0x71, 0x6e, 0x42, 0xa6, 0xcd, 0x0f, 0x0, 0x0, 0x0, 0x3a, 0x0 } | ||
665 | }, | ||
666 | {0x130, /* WSS, NTSC C */ | ||
667 | { 0x38, 0x00, 0x3f, 0x00 , 0x0, 0x71, 0x6e, 0x43, 0x69, 0x7c, 0x08, 0x0, 0x0, 0x0, 0x39, 0x0 } | ||
668 | }, | ||
669 | {0x150, /* VITC, PAL/SECAM 6 */ | ||
670 | { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0xa6, 0x85, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 } | ||
671 | }, | ||
672 | {0x170, /* VITC, NTSC 6 */ | ||
673 | { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0x69, 0x94, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 } | ||
674 | }, | ||
675 | { (u16)-1 } | ||
676 | }; | ||
451 | 677 | ||
452 | tvp5150_write(c, TVP5150_CONF_SHARED_PIN, 2); | 678 | static int tvp5150_write_inittab(struct i2c_client *c, |
679 | const struct i2c_reg_value *regs) | ||
680 | { | ||
681 | while (regs->reg != 0xff) { | ||
682 | tvp5150_write(c, regs->reg, regs->value); | ||
683 | regs++; | ||
684 | } | ||
685 | return 0; | ||
686 | } | ||
453 | 687 | ||
454 | /* Automatic offset and AGC enabled */ | 688 | static int tvp5150_vdp_init(struct i2c_client *c, |
455 | tvp5150_write(c, TVP5150_ANAL_CHL_CTL, 0x15); | 689 | const struct i2c_vbi_ram_value *regs) |
690 | { | ||
691 | unsigned int i; | ||
456 | 692 | ||
457 | /* Normal Operation */ | 693 | /* Disable Full Field */ |
458 | // tvp5150_write(c, TVP5150_OP_MODE_CTL, 0x00); | 694 | tvp5150_write(c, TVP5150_FULL_FIELD_ENA_1, 0); |
459 | 695 | ||
460 | /* Activate YCrCb output 0x9 or 0xd ? */ | 696 | /* Before programming, Line mode should be at 0xff */ |
461 | tvp5150_write(c, TVP5150_MISC_CTL, 0x6f); | 697 | for (i=TVP5150_FULL_FIELD_ENA_2; i<=TVP5150_LINE_MODE_REG_44; i++) |
698 | tvp5150_write(c, i, 0xff); | ||
462 | 699 | ||
463 | /* Activates video std autodetection for all standards */ | 700 | /* Load Ram Table */ |
464 | tvp5150_write(c, TVP5150_AUTOSW_MSK, 0x0); | 701 | while (regs->reg != (u16)-1 ) { |
702 | tvp5150_write(c, TVP5150_CONF_RAM_ADDR_HIGH,regs->reg>>8); | ||
703 | tvp5150_write(c, TVP5150_CONF_RAM_ADDR_LOW,regs->reg); | ||
465 | 704 | ||
466 | /* Default format: 0x47, 4:2:2: 0x40 */ | 705 | for (i=0;i<16;i++) |
467 | tvp5150_write(c, TVP5150_DATA_RATE_SEL, 0x47); | 706 | tvp5150_write(c, TVP5150_VDP_CONF_RAM_DATA,regs->values[i]); |
468 | 707 | ||
469 | tvp5150_selmux(c, decoder->input); | 708 | regs++; |
709 | } | ||
710 | return 0; | ||
711 | } | ||
712 | |||
713 | static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std) | ||
714 | { | ||
715 | struct tvp5150 *decoder = i2c_get_clientdata(c); | ||
716 | int fmt=0; | ||
717 | |||
718 | decoder->norm=std; | ||
719 | |||
720 | /* First tests should be against specific std */ | ||
721 | |||
722 | if (std == V4L2_STD_ALL) { | ||
723 | fmt=0; /* Autodetect mode */ | ||
724 | } else if (std & V4L2_STD_NTSC_443) { | ||
725 | fmt=0xa; | ||
726 | } else if (std & V4L2_STD_PAL_M) { | ||
727 | fmt=0x6; | ||
728 | } else if (std & (V4L2_STD_PAL_N| V4L2_STD_PAL_Nc)) { | ||
729 | fmt=0x8; | ||
730 | } else { | ||
731 | /* Then, test against generic ones */ | ||
732 | if (std & V4L2_STD_NTSC) { | ||
733 | fmt=0x2; | ||
734 | } else if (std & V4L2_STD_PAL) { | ||
735 | fmt=0x4; | ||
736 | } else if (std & V4L2_STD_SECAM) { | ||
737 | fmt=0xc; | ||
738 | } | ||
739 | } | ||
740 | |||
741 | tvp5150_dbg(1,"Set video std register to %d.\n",fmt); | ||
742 | tvp5150_write(c, TVP5150_VIDEO_STD, fmt); | ||
470 | 743 | ||
471 | tvp5150_write(c, TVP5150_CHROMA_PROC_CTL_1, 0x0c); | 744 | return 0; |
472 | tvp5150_write(c, TVP5150_CHROMA_PROC_CTL_2, 0x54); | 745 | } |
473 | 746 | ||
474 | tvp5150_write(c, 0x27, 0x20); /* ?????????? */ | 747 | static inline void tvp5150_reset(struct i2c_client *c) |
748 | { | ||
749 | u8 type, ver_656, msb_id, lsb_id, msb_rom, lsb_rom; | ||
750 | struct tvp5150 *decoder = i2c_get_clientdata(c); | ||
475 | 751 | ||
476 | tvp5150_write(c, TVP5150_VIDEO_STD, 0x0); /* Auto switch */ | 752 | type=tvp5150_read(c,TVP5150_AUTOSW_MSK); |
753 | msb_id=tvp5150_read(c,TVP5150_MSB_DEV_ID); | ||
754 | lsb_id=tvp5150_read(c,TVP5150_LSB_DEV_ID); | ||
755 | msb_rom=tvp5150_read(c,TVP5150_ROM_MAJOR_VER); | ||
756 | lsb_rom=tvp5150_read(c,TVP5150_ROM_MINOR_VER); | ||
757 | |||
758 | if (type==0xdc) { | ||
759 | ver_656=tvp5150_read(c,TVP5150_REV_SELECT); | ||
760 | tvp5150_info("tvp%02x%02xam1 detected 656 version is %d.\n",msb_id, lsb_id,ver_656); | ||
761 | } else if (type==0xfc) { | ||
762 | tvp5150_info("tvp%02x%02xa detected.\n",msb_id, lsb_id); | ||
763 | } else { | ||
764 | tvp5150_info("unknown tvp%02x%02x chip detected(%d).\n",msb_id,lsb_id,type); | ||
765 | } | ||
766 | tvp5150_info("Rom ver is %d.%d\n",msb_rom,lsb_rom); | ||
477 | 767 | ||
768 | /* Initializes TVP5150 to its default values */ | ||
769 | tvp5150_write_inittab(c, tvp5150_init_default); | ||
770 | |||
771 | /* Initializes VDP registers */ | ||
772 | tvp5150_vdp_init(c, vbi_ram_default); | ||
773 | |||
774 | /* Selects decoder input */ | ||
775 | tvp5150_selmux(c, decoder->input); | ||
776 | |||
777 | /* Initializes TVP5150 to stream enabled values */ | ||
778 | tvp5150_write_inittab(c, tvp5150_init_enable); | ||
779 | |||
780 | /* Initialize image preferences */ | ||
478 | tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8); | 781 | tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8); |
479 | tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8); | 782 | tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8); |
480 | tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8); | 783 | tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8); |
481 | tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8); | 784 | tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8); |
785 | |||
786 | tvp5150_set_std(c, decoder->norm); | ||
482 | }; | 787 | }; |
483 | 788 | ||
484 | static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) | 789 | static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) |
@@ -498,9 +803,8 @@ static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) | |||
498 | case V4L2_CID_HUE: | 803 | case V4L2_CID_HUE: |
499 | ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL); | 804 | ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL); |
500 | return 0; | 805 | return 0; |
501 | default: | ||
502 | return -EINVAL; | ||
503 | } | 806 | } |
807 | return -EINVAL; | ||
504 | } | 808 | } |
505 | 809 | ||
506 | static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) | 810 | static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) |
@@ -520,28 +824,59 @@ static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) | |||
520 | case V4L2_CID_HUE: | 824 | case V4L2_CID_HUE: |
521 | tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value); | 825 | tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value); |
522 | return 0; | 826 | return 0; |
523 | default: | ||
524 | return -EINVAL; | ||
525 | } | 827 | } |
828 | return -EINVAL; | ||
526 | } | 829 | } |
527 | 830 | ||
528 | /**************************************************************************** | 831 | /**************************************************************************** |
529 | I2C Command | 832 | I2C Command |
530 | ****************************************************************************/ | 833 | ****************************************************************************/ |
531 | static int tvp5150_command(struct i2c_client *client, | 834 | static int tvp5150_command(struct i2c_client *c, |
532 | unsigned int cmd, void *arg) | 835 | unsigned int cmd, void *arg) |
533 | { | 836 | { |
534 | struct tvp5150 *decoder = i2c_get_clientdata(client); | 837 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
535 | 838 | ||
536 | switch (cmd) { | 839 | switch (cmd) { |
537 | 840 | ||
538 | case 0: | 841 | case 0: |
842 | case VIDIOC_INT_RESET: | ||
539 | case DECODER_INIT: | 843 | case DECODER_INIT: |
540 | tvp5150_reset(client); | 844 | tvp5150_reset(c); |
845 | break; | ||
846 | case VIDIOC_S_STD: | ||
847 | if (decoder->norm == *(v4l2_std_id *)arg) | ||
848 | break; | ||
849 | return tvp5150_set_std(c, *(v4l2_std_id *)arg); | ||
850 | case VIDIOC_G_STD: | ||
851 | *(v4l2_std_id *)arg = decoder->norm; | ||
852 | break; | ||
853 | |||
854 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
855 | case VIDIOC_INT_G_REGISTER: | ||
856 | { | ||
857 | struct v4l2_register *reg = arg; | ||
858 | |||
859 | if (reg->i2c_id != I2C_DRIVERID_TVP5150) | ||
860 | return -EINVAL; | ||
861 | reg->val = tvp5150_read(c, reg->reg & 0xff); | ||
862 | break; | ||
863 | } | ||
864 | |||
865 | case VIDIOC_INT_S_REGISTER: | ||
866 | { | ||
867 | struct v4l2_register *reg = arg; | ||
868 | |||
869 | if (reg->i2c_id != I2C_DRIVERID_TVP5150) | ||
870 | return -EINVAL; | ||
871 | if (!capable(CAP_SYS_ADMIN)) | ||
872 | return -EPERM; | ||
873 | tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff); | ||
541 | break; | 874 | break; |
875 | } | ||
876 | #endif | ||
542 | 877 | ||
543 | case DECODER_DUMP: | 878 | case DECODER_DUMP: |
544 | dump_reg(client); | 879 | dump_reg(c); |
545 | break; | 880 | break; |
546 | 881 | ||
547 | case DECODER_GET_CAPABILITIES: | 882 | case DECODER_GET_CAPABILITIES: |
@@ -600,7 +935,7 @@ static int tvp5150_command(struct i2c_client *client, | |||
600 | } | 935 | } |
601 | 936 | ||
602 | decoder->input = *iarg; | 937 | decoder->input = *iarg; |
603 | tvp5150_selmux(client, decoder->input); | 938 | tvp5150_selmux(c, decoder->input); |
604 | 939 | ||
605 | break; | 940 | break; |
606 | } | 941 | } |
@@ -620,19 +955,18 @@ static int tvp5150_command(struct i2c_client *client, | |||
620 | 955 | ||
621 | decoder->enable = (*iarg != 0); | 956 | decoder->enable = (*iarg != 0); |
622 | 957 | ||
623 | tvp5150_selmux(client, decoder->input); | 958 | tvp5150_selmux(c, decoder->input); |
624 | 959 | ||
625 | break; | 960 | break; |
626 | } | 961 | } |
627 | case VIDIOC_QUERYCTRL: | 962 | case VIDIOC_QUERYCTRL: |
628 | { | 963 | { |
629 | struct v4l2_queryctrl *qc = arg; | 964 | struct v4l2_queryctrl *qc = arg; |
630 | u8 i, n; | 965 | int i; |
631 | 966 | ||
632 | dprintk(1, KERN_DEBUG "VIDIOC_QUERYCTRL"); | 967 | tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n"); |
633 | 968 | ||
634 | n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]); | 969 | for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++) |
635 | for (i = 0; i < n; i++) | ||
636 | if (qc->id && qc->id == tvp5150_qctrl[i].id) { | 970 | if (qc->id && qc->id == tvp5150_qctrl[i].id) { |
637 | memcpy(qc, &(tvp5150_qctrl[i]), | 971 | memcpy(qc, &(tvp5150_qctrl[i]), |
638 | sizeof(*qc)); | 972 | sizeof(*qc)); |
@@ -644,16 +978,14 @@ static int tvp5150_command(struct i2c_client *client, | |||
644 | case VIDIOC_G_CTRL: | 978 | case VIDIOC_G_CTRL: |
645 | { | 979 | { |
646 | struct v4l2_control *ctrl = arg; | 980 | struct v4l2_control *ctrl = arg; |
647 | dprintk(1, KERN_DEBUG "VIDIOC_G_CTRL"); | 981 | tvp5150_dbg(1, "VIDIOC_G_CTRL called\n"); |
648 | 982 | ||
649 | return tvp5150_get_ctrl(client, ctrl); | 983 | return tvp5150_get_ctrl(c, ctrl); |
650 | } | 984 | } |
651 | case VIDIOC_S_CTRL_OLD: /* ??? */ | ||
652 | case VIDIOC_S_CTRL: | 985 | case VIDIOC_S_CTRL: |
653 | { | 986 | { |
654 | struct v4l2_control *ctrl = arg; | 987 | struct v4l2_control *ctrl = arg; |
655 | u8 i, n; | 988 | u8 i, n; |
656 | dprintk(1, KERN_DEBUG "VIDIOC_S_CTRL"); | ||
657 | n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]); | 989 | n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]); |
658 | for (i = 0; i < n; i++) | 990 | for (i = 0; i < n; i++) |
659 | if (ctrl->id == tvp5150_qctrl[i].id) { | 991 | if (ctrl->id == tvp5150_qctrl[i].id) { |
@@ -662,11 +994,10 @@ static int tvp5150_command(struct i2c_client *client, | |||
662 | || ctrl->value > | 994 | || ctrl->value > |
663 | tvp5150_qctrl[i].maximum) | 995 | tvp5150_qctrl[i].maximum) |
664 | return -ERANGE; | 996 | return -ERANGE; |
665 | dprintk(1, | 997 | tvp5150_dbg(1, |
666 | KERN_DEBUG | 998 | "VIDIOC_S_CTRL: id=%d, value=%d\n", |
667 | "VIDIOC_S_CTRL: id=%d, value=%d", | ||
668 | ctrl->id, ctrl->value); | 999 | ctrl->id, ctrl->value); |
669 | return tvp5150_set_ctrl(client, ctrl); | 1000 | return tvp5150_set_ctrl(c, ctrl); |
670 | } | 1001 | } |
671 | return -EINVAL; | 1002 | return -EINVAL; |
672 | } | 1003 | } |
@@ -677,25 +1008,25 @@ static int tvp5150_command(struct i2c_client *client, | |||
677 | if (decoder->bright != pic->brightness) { | 1008 | if (decoder->bright != pic->brightness) { |
678 | /* We want 0 to 255 we get 0-65535 */ | 1009 | /* We want 0 to 255 we get 0-65535 */ |
679 | decoder->bright = pic->brightness; | 1010 | decoder->bright = pic->brightness; |
680 | tvp5150_write(client, TVP5150_BRIGHT_CTL, | 1011 | tvp5150_write(c, TVP5150_BRIGHT_CTL, |
681 | decoder->bright >> 8); | 1012 | decoder->bright >> 8); |
682 | } | 1013 | } |
683 | if (decoder->contrast != pic->contrast) { | 1014 | if (decoder->contrast != pic->contrast) { |
684 | /* We want 0 to 255 we get 0-65535 */ | 1015 | /* We want 0 to 255 we get 0-65535 */ |
685 | decoder->contrast = pic->contrast; | 1016 | decoder->contrast = pic->contrast; |
686 | tvp5150_write(client, TVP5150_CONTRAST_CTL, | 1017 | tvp5150_write(c, TVP5150_CONTRAST_CTL, |
687 | decoder->contrast >> 8); | 1018 | decoder->contrast >> 8); |
688 | } | 1019 | } |
689 | if (decoder->sat != pic->colour) { | 1020 | if (decoder->sat != pic->colour) { |
690 | /* We want 0 to 255 we get 0-65535 */ | 1021 | /* We want 0 to 255 we get 0-65535 */ |
691 | decoder->sat = pic->colour; | 1022 | decoder->sat = pic->colour; |
692 | tvp5150_write(client, TVP5150_SATURATION_CTL, | 1023 | tvp5150_write(c, TVP5150_SATURATION_CTL, |
693 | decoder->contrast >> 8); | 1024 | decoder->contrast >> 8); |
694 | } | 1025 | } |
695 | if (decoder->hue != pic->hue) { | 1026 | if (decoder->hue != pic->hue) { |
696 | /* We want -128 to 127 we get 0-65535 */ | 1027 | /* We want -128 to 127 we get 0-65535 */ |
697 | decoder->hue = pic->hue; | 1028 | decoder->hue = pic->hue; |
698 | tvp5150_write(client, TVP5150_HUE_CTL, | 1029 | tvp5150_write(c, TVP5150_HUE_CTL, |
699 | (decoder->hue - 32768) >> 8); | 1030 | (decoder->hue - 32768) >> 8); |
700 | } | 1031 | } |
701 | break; | 1032 | break; |
@@ -720,12 +1051,12 @@ static struct i2c_client client_template = { | |||
720 | static int tvp5150_detect_client(struct i2c_adapter *adapter, | 1051 | static int tvp5150_detect_client(struct i2c_adapter *adapter, |
721 | int address, int kind) | 1052 | int address, int kind) |
722 | { | 1053 | { |
723 | struct i2c_client *client; | 1054 | struct i2c_client *c; |
724 | struct tvp5150 *core; | 1055 | struct tvp5150 *core; |
725 | int rv; | 1056 | int rv; |
726 | 1057 | ||
727 | dprintk(1, | 1058 | if (debug) |
728 | KERN_INFO | 1059 | printk( KERN_INFO |
729 | "tvp5150.c: detecting tvp5150 client on address 0x%x\n", | 1060 | "tvp5150.c: detecting tvp5150 client on address 0x%x\n", |
730 | address << 1); | 1061 | address << 1); |
731 | 1062 | ||
@@ -738,22 +1069,22 @@ static int tvp5150_detect_client(struct i2c_adapter *adapter, | |||
738 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) | 1069 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
739 | return 0; | 1070 | return 0; |
740 | 1071 | ||
741 | client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); | 1072 | c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); |
742 | if (client == 0) | 1073 | if (c == 0) |
743 | return -ENOMEM; | 1074 | return -ENOMEM; |
744 | memcpy(client, &client_template, sizeof(struct i2c_client)); | 1075 | memcpy(c, &client_template, sizeof(struct i2c_client)); |
745 | 1076 | ||
746 | core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL); | 1077 | core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL); |
747 | if (core == 0) { | 1078 | if (core == 0) { |
748 | kfree(client); | 1079 | kfree(c); |
749 | return -ENOMEM; | 1080 | return -ENOMEM; |
750 | } | 1081 | } |
751 | memset(core, 0, sizeof(struct tvp5150)); | 1082 | memset(core, 0, sizeof(struct tvp5150)); |
752 | i2c_set_clientdata(client, core); | 1083 | i2c_set_clientdata(c, core); |
753 | 1084 | ||
754 | rv = i2c_attach_client(client); | 1085 | rv = i2c_attach_client(c); |
755 | 1086 | ||
756 | core->norm = VIDEO_MODE_AUTO; | 1087 | core->norm = V4L2_STD_ALL; |
757 | core->input = 2; | 1088 | core->input = 2; |
758 | core->enable = 1; | 1089 | core->enable = 1; |
759 | core->bright = 32768; | 1090 | core->bright = 32768; |
@@ -762,37 +1093,41 @@ static int tvp5150_detect_client(struct i2c_adapter *adapter, | |||
762 | core->sat = 32768; | 1093 | core->sat = 32768; |
763 | 1094 | ||
764 | if (rv) { | 1095 | if (rv) { |
765 | kfree(client); | 1096 | kfree(c); |
766 | kfree(core); | 1097 | kfree(core); |
767 | return rv; | 1098 | return rv; |
768 | } | 1099 | } |
769 | 1100 | ||
770 | if (debug > 1) | 1101 | if (debug > 1) |
771 | dump_reg(client); | 1102 | dump_reg(c); |
772 | return 0; | 1103 | return 0; |
773 | } | 1104 | } |
774 | 1105 | ||
775 | static int tvp5150_attach_adapter(struct i2c_adapter *adapter) | 1106 | static int tvp5150_attach_adapter(struct i2c_adapter *adapter) |
776 | { | 1107 | { |
777 | dprintk(1, | 1108 | if (debug) |
778 | KERN_INFO | 1109 | printk( KERN_INFO |
779 | "tvp5150.c: starting probe for adapter %s (0x%x)\n", | 1110 | "tvp5150.c: starting probe for adapter %s (0x%x)\n", |
780 | adapter->name, adapter->id); | 1111 | adapter->name, adapter->id); |
781 | return i2c_probe(adapter, &addr_data, &tvp5150_detect_client); | 1112 | return i2c_probe(adapter, &addr_data, &tvp5150_detect_client); |
782 | } | 1113 | } |
783 | 1114 | ||
784 | static int tvp5150_detach_client(struct i2c_client *client) | 1115 | static int tvp5150_detach_client(struct i2c_client *c) |
785 | { | 1116 | { |
786 | struct tvp5150 *decoder = i2c_get_clientdata(client); | 1117 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
787 | int err; | 1118 | int err; |
788 | 1119 | ||
789 | err = i2c_detach_client(client); | 1120 | tvp5150_dbg(1, |
1121 | "tvp5150.c: removing tvp5150 adapter on address 0x%x\n", | ||
1122 | c->addr << 1); | ||
1123 | |||
1124 | err = i2c_detach_client(c); | ||
790 | if (err) { | 1125 | if (err) { |
791 | return err; | 1126 | return err; |
792 | } | 1127 | } |
793 | 1128 | ||
794 | kfree(decoder); | 1129 | kfree(decoder); |
795 | kfree(client); | 1130 | kfree(c); |
796 | 1131 | ||
797 | return 0; | 1132 | return 0; |
798 | } | 1133 | } |
@@ -803,9 +1138,7 @@ static struct i2c_driver driver = { | |||
803 | .driver = { | 1138 | .driver = { |
804 | .name = "tvp5150", | 1139 | .name = "tvp5150", |
805 | }, | 1140 | }, |
806 | 1141 | .id = I2C_DRIVERID_TVP5150, | |
807 | /* FIXME */ | ||
808 | .id = I2C_DRIVERID_SAA7110, | ||
809 | 1142 | ||
810 | .attach_adapter = tvp5150_attach_adapter, | 1143 | .attach_adapter = tvp5150_attach_adapter, |
811 | .detach_client = tvp5150_detach_client, | 1144 | .detach_client = tvp5150_detach_client, |