aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tvp5150.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/tvp5150.c')
-rw-r--r--drivers/media/video/tvp5150.c199
1 files changed, 67 insertions, 132 deletions
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index 58927664d3ea..e927d25e0d35 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -12,6 +12,7 @@
12#include <media/v4l2-device.h> 12#include <media/v4l2-device.h>
13#include <media/tvp5150.h> 13#include <media/tvp5150.h>
14#include <media/v4l2-chip-ident.h> 14#include <media/v4l2-chip-ident.h>
15#include <media/v4l2-ctrls.h>
15 16
16#include "tvp5150_reg.h" 17#include "tvp5150_reg.h"
17 18
@@ -24,58 +25,14 @@ static int debug;
24module_param(debug, int, 0); 25module_param(debug, int, 0);
25MODULE_PARM_DESC(debug, "Debug level (0-2)"); 26MODULE_PARM_DESC(debug, "Debug level (0-2)");
26 27
27/* supported controls */
28static struct v4l2_queryctrl tvp5150_qctrl[] = {
29 {
30 .id = V4L2_CID_BRIGHTNESS,
31 .type = V4L2_CTRL_TYPE_INTEGER,
32 .name = "Brightness",
33 .minimum = 0,
34 .maximum = 255,
35 .step = 1,
36 .default_value = 128,
37 .flags = 0,
38 }, {
39 .id = V4L2_CID_CONTRAST,
40 .type = V4L2_CTRL_TYPE_INTEGER,
41 .name = "Contrast",
42 .minimum = 0,
43 .maximum = 255,
44 .step = 0x1,
45 .default_value = 128,
46 .flags = 0,
47 }, {
48 .id = V4L2_CID_SATURATION,
49 .type = V4L2_CTRL_TYPE_INTEGER,
50 .name = "Saturation",
51 .minimum = 0,
52 .maximum = 255,
53 .step = 0x1,
54 .default_value = 128,
55 .flags = 0,
56 }, {
57 .id = V4L2_CID_HUE,
58 .type = V4L2_CTRL_TYPE_INTEGER,
59 .name = "Hue",
60 .minimum = -128,
61 .maximum = 127,
62 .step = 0x1,
63 .default_value = 0,
64 .flags = 0,
65 }
66};
67
68struct tvp5150 { 28struct tvp5150 {
69 struct v4l2_subdev sd; 29 struct v4l2_subdev sd;
30 struct v4l2_ctrl_handler hdl;
70 31
71 v4l2_std_id norm; /* Current set standard */ 32 v4l2_std_id norm; /* Current set standard */
72 u32 input; 33 u32 input;
73 u32 output; 34 u32 output;
74 int enable; 35 int enable;
75 int bright;
76 int contrast;
77 int hue;
78 int sat;
79}; 36};
80 37
81static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd) 38static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd)
@@ -83,6 +40,11 @@ static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd)
83 return container_of(sd, struct tvp5150, sd); 40 return container_of(sd, struct tvp5150, sd);
84} 41}
85 42
43static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
44{
45 return &container_of(ctrl->handler, struct tvp5150, hdl)->sd;
46}
47
86static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr) 48static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
87{ 49{
88 struct i2c_client *c = v4l2_get_subdevdata(sd); 50 struct i2c_client *c = v4l2_get_subdevdata(sd);
@@ -775,27 +737,6 @@ static int tvp5150_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
775static int tvp5150_reset(struct v4l2_subdev *sd, u32 val) 737static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
776{ 738{
777 struct tvp5150 *decoder = to_tvp5150(sd); 739 struct tvp5150 *decoder = to_tvp5150(sd);
778 u8 msb_id, lsb_id, msb_rom, lsb_rom;
779
780 msb_id = tvp5150_read(sd, TVP5150_MSB_DEV_ID);
781 lsb_id = tvp5150_read(sd, TVP5150_LSB_DEV_ID);
782 msb_rom = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER);
783 lsb_rom = tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
784
785 if (msb_rom == 4 && lsb_rom == 0) { /* Is TVP5150AM1 */
786 v4l2_info(sd, "tvp%02x%02xam1 detected.\n", msb_id, lsb_id);
787
788 /* ITU-T BT.656.4 timing */
789 tvp5150_write(sd, TVP5150_REV_SELECT, 0);
790 } else {
791 if (msb_rom == 3 || lsb_rom == 0x21) { /* Is TVP5150A */
792 v4l2_info(sd, "tvp%02x%02xa detected.\n", msb_id, lsb_id);
793 } else {
794 v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
795 msb_id, lsb_id);
796 v4l2_info(sd, "*** Rom ver is %d.%d\n", msb_rom, lsb_rom);
797 }
798 }
799 740
800 /* Initializes TVP5150 to its default values */ 741 /* Initializes TVP5150 to its default values */
801 tvp5150_write_inittab(sd, tvp5150_init_default); 742 tvp5150_write_inittab(sd, tvp5150_init_default);
@@ -810,64 +751,28 @@ static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
810 tvp5150_write_inittab(sd, tvp5150_init_enable); 751 tvp5150_write_inittab(sd, tvp5150_init_enable);
811 752
812 /* Initialize image preferences */ 753 /* Initialize image preferences */
813 tvp5150_write(sd, TVP5150_BRIGHT_CTL, decoder->bright); 754 v4l2_ctrl_handler_setup(&decoder->hdl);
814 tvp5150_write(sd, TVP5150_CONTRAST_CTL, decoder->contrast);
815 tvp5150_write(sd, TVP5150_SATURATION_CTL, decoder->contrast);
816 tvp5150_write(sd, TVP5150_HUE_CTL, decoder->hue);
817 755
818 tvp5150_set_std(sd, decoder->norm); 756 tvp5150_set_std(sd, decoder->norm);
819 return 0; 757 return 0;
820}; 758};
821 759
822static int tvp5150_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 760static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl)
823{
824 v4l2_dbg(1, debug, sd, "g_ctrl called\n");
825
826 switch (ctrl->id) {
827 case V4L2_CID_BRIGHTNESS:
828 ctrl->value = tvp5150_read(sd, TVP5150_BRIGHT_CTL);
829 return 0;
830 case V4L2_CID_CONTRAST:
831 ctrl->value = tvp5150_read(sd, TVP5150_CONTRAST_CTL);
832 return 0;
833 case V4L2_CID_SATURATION:
834 ctrl->value = tvp5150_read(sd, TVP5150_SATURATION_CTL);
835 return 0;
836 case V4L2_CID_HUE:
837 ctrl->value = tvp5150_read(sd, TVP5150_HUE_CTL);
838 return 0;
839 }
840 return -EINVAL;
841}
842
843static int tvp5150_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
844{ 761{
845 u8 i, n; 762 struct v4l2_subdev *sd = to_sd(ctrl);
846 n = ARRAY_SIZE(tvp5150_qctrl);
847
848 for (i = 0; i < n; i++) {
849 if (ctrl->id != tvp5150_qctrl[i].id)
850 continue;
851 if (ctrl->value < tvp5150_qctrl[i].minimum ||
852 ctrl->value > tvp5150_qctrl[i].maximum)
853 return -ERANGE;
854 v4l2_dbg(1, debug, sd, "s_ctrl: id=%d, value=%d\n",
855 ctrl->id, ctrl->value);
856 break;
857 }
858 763
859 switch (ctrl->id) { 764 switch (ctrl->id) {
860 case V4L2_CID_BRIGHTNESS: 765 case V4L2_CID_BRIGHTNESS:
861 tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->value); 766 tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->val);
862 return 0; 767 return 0;
863 case V4L2_CID_CONTRAST: 768 case V4L2_CID_CONTRAST:
864 tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->value); 769 tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->val);
865 return 0; 770 return 0;
866 case V4L2_CID_SATURATION: 771 case V4L2_CID_SATURATION:
867 tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->value); 772 tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->val);
868 return 0; 773 return 0;
869 case V4L2_CID_HUE: 774 case V4L2_CID_HUE:
870 tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->value); 775 tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->val);
871 return 0; 776 return 0;
872 } 777 }
873 return -EINVAL; 778 return -EINVAL;
@@ -995,29 +900,21 @@ static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
995 return 0; 900 return 0;
996} 901}
997 902
998static int tvp5150_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
999{
1000 int i;
1001
1002 v4l2_dbg(1, debug, sd, "queryctrl called\n");
1003
1004 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
1005 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
1006 memcpy(qc, &(tvp5150_qctrl[i]),
1007 sizeof(*qc));
1008 return 0;
1009 }
1010
1011 return -EINVAL;
1012}
1013
1014/* ----------------------------------------------------------------------- */ 903/* ----------------------------------------------------------------------- */
1015 904
905static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
906 .s_ctrl = tvp5150_s_ctrl,
907};
908
1016static const struct v4l2_subdev_core_ops tvp5150_core_ops = { 909static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
1017 .log_status = tvp5150_log_status, 910 .log_status = tvp5150_log_status,
1018 .g_ctrl = tvp5150_g_ctrl, 911 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1019 .s_ctrl = tvp5150_s_ctrl, 912 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1020 .queryctrl = tvp5150_queryctrl, 913 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
914 .g_ctrl = v4l2_subdev_g_ctrl,
915 .s_ctrl = v4l2_subdev_s_ctrl,
916 .queryctrl = v4l2_subdev_queryctrl,
917 .querymenu = v4l2_subdev_querymenu,
1021 .s_std = tvp5150_s_std, 918 .s_std = tvp5150_s_std,
1022 .reset = tvp5150_reset, 919 .reset = tvp5150_reset,
1023 .g_chip_ident = tvp5150_g_chip_ident, 920 .g_chip_ident = tvp5150_g_chip_ident,
@@ -1059,6 +956,7 @@ static int tvp5150_probe(struct i2c_client *c,
1059{ 956{
1060 struct tvp5150 *core; 957 struct tvp5150 *core;
1061 struct v4l2_subdev *sd; 958 struct v4l2_subdev *sd;
959 u8 msb_id, lsb_id, msb_rom, lsb_rom;
1062 960
1063 /* Check if the adapter supports the needed features */ 961 /* Check if the adapter supports the needed features */
1064 if (!i2c_check_functionality(c->adapter, 962 if (!i2c_check_functionality(c->adapter,
@@ -1074,13 +972,48 @@ static int tvp5150_probe(struct i2c_client *c,
1074 v4l_info(c, "chip found @ 0x%02x (%s)\n", 972 v4l_info(c, "chip found @ 0x%02x (%s)\n",
1075 c->addr << 1, c->adapter->name); 973 c->addr << 1, c->adapter->name);
1076 974
975 msb_id = tvp5150_read(sd, TVP5150_MSB_DEV_ID);
976 lsb_id = tvp5150_read(sd, TVP5150_LSB_DEV_ID);
977 msb_rom = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER);
978 lsb_rom = tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
979
980 if (msb_rom == 4 && lsb_rom == 0) { /* Is TVP5150AM1 */
981 v4l2_info(sd, "tvp%02x%02xam1 detected.\n", msb_id, lsb_id);
982
983 /* ITU-T BT.656.4 timing */
984 tvp5150_write(sd, TVP5150_REV_SELECT, 0);
985 } else {
986 if (msb_rom == 3 || lsb_rom == 0x21) { /* Is TVP5150A */
987 v4l2_info(sd, "tvp%02x%02xa detected.\n", msb_id, lsb_id);
988 } else {
989 v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
990 msb_id, lsb_id);
991 v4l2_info(sd, "*** Rom ver is %d.%d\n", msb_rom, lsb_rom);
992 }
993 }
994
1077 core->norm = V4L2_STD_ALL; /* Default is autodetect */ 995 core->norm = V4L2_STD_ALL; /* Default is autodetect */
1078 core->input = TVP5150_COMPOSITE1; 996 core->input = TVP5150_COMPOSITE1;
1079 core->enable = 1; 997 core->enable = 1;
1080 core->bright = 128; 998
1081 core->contrast = 128; 999 v4l2_ctrl_handler_init(&core->hdl, 4);
1082 core->hue = 0; 1000 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1083 core->sat = 128; 1001 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1002 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1003 V4L2_CID_CONTRAST, 0, 255, 1, 128);
1004 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1005 V4L2_CID_SATURATION, 0, 255, 1, 128);
1006 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1007 V4L2_CID_HUE, -128, 127, 1, 0);
1008 sd->ctrl_handler = &core->hdl;
1009 if (core->hdl.error) {
1010 int err = core->hdl.error;
1011
1012 v4l2_ctrl_handler_free(&core->hdl);
1013 kfree(core);
1014 return err;
1015 }
1016 v4l2_ctrl_handler_setup(&core->hdl);
1084 1017
1085 if (debug > 1) 1018 if (debug > 1)
1086 tvp5150_log_status(sd); 1019 tvp5150_log_status(sd);
@@ -1090,12 +1023,14 @@ static int tvp5150_probe(struct i2c_client *c,
1090static int tvp5150_remove(struct i2c_client *c) 1023static int tvp5150_remove(struct i2c_client *c)
1091{ 1024{
1092 struct v4l2_subdev *sd = i2c_get_clientdata(c); 1025 struct v4l2_subdev *sd = i2c_get_clientdata(c);
1026 struct tvp5150 *decoder = to_tvp5150(sd);
1093 1027
1094 v4l2_dbg(1, debug, sd, 1028 v4l2_dbg(1, debug, sd,
1095 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n", 1029 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1096 c->addr << 1); 1030 c->addr << 1);
1097 1031
1098 v4l2_device_unregister_subdev(sd); 1032 v4l2_device_unregister_subdev(sd);
1033 v4l2_ctrl_handler_free(&decoder->hdl);
1099 kfree(to_tvp5150(sd)); 1034 kfree(to_tvp5150(sd));
1100 return 0; 1035 return 0;
1101} 1036}