Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] tvp514x: use the control framework

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
cf6832af e3d5ef04

+57 -179
+57 -179
drivers/media/video/tvp514x.c
··· 37 37 #include <media/v4l2-common.h> 38 38 #include <media/v4l2-mediabus.h> 39 39 #include <media/v4l2-chip-ident.h> 40 + #include <media/v4l2-ctrls.h> 40 41 #include <media/tvp514x.h> 41 42 42 43 #include "tvp514x_regs.h" ··· 98 97 */ 99 98 struct tvp514x_decoder { 100 99 struct v4l2_subdev sd; 100 + struct v4l2_ctrl_handler hdl; 101 101 struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)]; 102 102 const struct tvp514x_platform_data *pdata; 103 103 ··· 238 236 static inline struct tvp514x_decoder *to_decoder(struct v4l2_subdev *sd) 239 237 { 240 238 return container_of(sd, struct tvp514x_decoder, sd); 239 + } 240 + 241 + static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) 242 + { 243 + return &container_of(ctrl->handler, struct tvp514x_decoder, hdl)->sd; 241 244 } 242 245 243 246 ··· 726 719 } 727 720 728 721 /** 729 - * tvp514x_queryctrl() - V4L2 decoder interface handler for queryctrl 730 - * @sd: pointer to standard V4L2 sub-device structure 731 - * @qctrl: standard V4L2 v4l2_queryctrl structure 732 - * 733 - * If the requested control is supported, returns the control information. 734 - * Otherwise, returns -EINVAL if the control is not supported. 735 - */ 736 - static int 737 - tvp514x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qctrl) 738 - { 739 - int err = -EINVAL; 740 - 741 - if (qctrl == NULL) 742 - return err; 743 - 744 - switch (qctrl->id) { 745 - case V4L2_CID_BRIGHTNESS: 746 - /* Brightness supported is (0-255), */ 747 - err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128); 748 - break; 749 - case V4L2_CID_CONTRAST: 750 - case V4L2_CID_SATURATION: 751 - /** 752 - * Saturation and Contrast supported is - 753 - * Contrast: 0 - 255 (Default - 128) 754 - * Saturation: 0 - 255 (Default - 128) 755 - */ 756 - err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128); 757 - break; 758 - case V4L2_CID_HUE: 759 - /* Hue Supported is - 760 - * Hue - -180 - +180 (Default - 0, Step - +180) 761 - */ 762 - err = v4l2_ctrl_query_fill(qctrl, -180, 180, 180, 0); 763 - break; 764 - case V4L2_CID_AUTOGAIN: 765 - /** 766 - * Auto Gain supported is - 767 - * 0 - 1 (Default - 1) 768 - */ 769 - err = v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1); 770 - break; 771 - default: 772 - v4l2_err(sd, "invalid control id %d\n", qctrl->id); 773 - return err; 774 - } 775 - 776 - v4l2_dbg(1, debug, sd, "Query Control:%s: Min - %d, Max - %d, Def - %d\n", 777 - qctrl->name, qctrl->minimum, qctrl->maximum, 778 - qctrl->default_value); 779 - 780 - return err; 781 - } 782 - 783 - /** 784 - * tvp514x_g_ctrl() - V4L2 decoder interface handler for g_ctrl 785 - * @sd: pointer to standard V4L2 sub-device structure 786 - * @ctrl: pointer to v4l2_control structure 787 - * 788 - * If the requested control is supported, returns the control's current 789 - * value from the decoder. Otherwise, returns -EINVAL if the control is not 790 - * supported. 791 - */ 792 - static int 793 - tvp514x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 794 - { 795 - struct tvp514x_decoder *decoder = to_decoder(sd); 796 - 797 - if (ctrl == NULL) 798 - return -EINVAL; 799 - 800 - switch (ctrl->id) { 801 - case V4L2_CID_BRIGHTNESS: 802 - ctrl->value = decoder->tvp514x_regs[REG_BRIGHTNESS].val; 803 - break; 804 - case V4L2_CID_CONTRAST: 805 - ctrl->value = decoder->tvp514x_regs[REG_CONTRAST].val; 806 - break; 807 - case V4L2_CID_SATURATION: 808 - ctrl->value = decoder->tvp514x_regs[REG_SATURATION].val; 809 - break; 810 - case V4L2_CID_HUE: 811 - ctrl->value = decoder->tvp514x_regs[REG_HUE].val; 812 - if (ctrl->value == 0x7F) 813 - ctrl->value = 180; 814 - else if (ctrl->value == 0x80) 815 - ctrl->value = -180; 816 - else 817 - ctrl->value = 0; 818 - 819 - break; 820 - case V4L2_CID_AUTOGAIN: 821 - ctrl->value = decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val; 822 - if ((ctrl->value & 0x3) == 3) 823 - ctrl->value = 1; 824 - else 825 - ctrl->value = 0; 826 - 827 - break; 828 - default: 829 - v4l2_err(sd, "invalid control id %d\n", ctrl->id); 830 - return -EINVAL; 831 - } 832 - 833 - v4l2_dbg(1, debug, sd, "Get Control: ID - %d - %d\n", 834 - ctrl->id, ctrl->value); 835 - return 0; 836 - } 837 - 838 - /** 839 722 * tvp514x_s_ctrl() - V4L2 decoder interface handler for s_ctrl 840 - * @sd: pointer to standard V4L2 sub-device structure 841 - * @ctrl: pointer to v4l2_control structure 723 + * @ctrl: pointer to v4l2_ctrl structure 842 724 * 843 725 * If the requested control is supported, sets the control's current 844 726 * value in HW. Otherwise, returns -EINVAL if the control is not supported. 845 727 */ 846 - static int 847 - tvp514x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 728 + static int tvp514x_s_ctrl(struct v4l2_ctrl *ctrl) 848 729 { 730 + struct v4l2_subdev *sd = to_sd(ctrl); 849 731 struct tvp514x_decoder *decoder = to_decoder(sd); 850 732 int err = -EINVAL, value; 851 733 852 - if (ctrl == NULL) 853 - return err; 854 - 855 - value = ctrl->value; 734 + value = ctrl->val; 856 735 857 736 switch (ctrl->id) { 858 737 case V4L2_CID_BRIGHTNESS: 859 - if (ctrl->value < 0 || ctrl->value > 255) { 860 - v4l2_err(sd, "invalid brightness setting %d\n", 861 - ctrl->value); 862 - return -ERANGE; 863 - } 864 - err = tvp514x_write_reg(sd, REG_BRIGHTNESS, 865 - value); 866 - if (err) 867 - return err; 868 - 869 - decoder->tvp514x_regs[REG_BRIGHTNESS].val = value; 738 + err = tvp514x_write_reg(sd, REG_BRIGHTNESS, value); 739 + if (!err) 740 + decoder->tvp514x_regs[REG_BRIGHTNESS].val = value; 870 741 break; 871 742 case V4L2_CID_CONTRAST: 872 - if (ctrl->value < 0 || ctrl->value > 255) { 873 - v4l2_err(sd, "invalid contrast setting %d\n", 874 - ctrl->value); 875 - return -ERANGE; 876 - } 877 743 err = tvp514x_write_reg(sd, REG_CONTRAST, value); 878 - if (err) 879 - return err; 880 - 881 - decoder->tvp514x_regs[REG_CONTRAST].val = value; 744 + if (!err) 745 + decoder->tvp514x_regs[REG_CONTRAST].val = value; 882 746 break; 883 747 case V4L2_CID_SATURATION: 884 - if (ctrl->value < 0 || ctrl->value > 255) { 885 - v4l2_err(sd, "invalid saturation setting %d\n", 886 - ctrl->value); 887 - return -ERANGE; 888 - } 889 748 err = tvp514x_write_reg(sd, REG_SATURATION, value); 890 - if (err) 891 - return err; 892 - 893 - decoder->tvp514x_regs[REG_SATURATION].val = value; 749 + if (!err) 750 + decoder->tvp514x_regs[REG_SATURATION].val = value; 894 751 break; 895 752 case V4L2_CID_HUE: 896 753 if (value == 180) 897 754 value = 0x7F; 898 755 else if (value == -180) 899 756 value = 0x80; 900 - else if (value == 0) 901 - value = 0; 902 - else { 903 - v4l2_err(sd, "invalid hue setting %d\n", ctrl->value); 904 - return -ERANGE; 905 - } 906 757 err = tvp514x_write_reg(sd, REG_HUE, value); 907 - if (err) 908 - return err; 909 - 910 - decoder->tvp514x_regs[REG_HUE].val = value; 758 + if (!err) 759 + decoder->tvp514x_regs[REG_HUE].val = value; 911 760 break; 912 761 case V4L2_CID_AUTOGAIN: 913 - if (value == 1) 914 - value = 0x0F; 915 - else if (value == 0) 916 - value = 0x0C; 917 - else { 918 - v4l2_err(sd, "invalid auto gain setting %d\n", 919 - ctrl->value); 920 - return -ERANGE; 921 - } 922 - err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value); 923 - if (err) 924 - return err; 925 - 926 - decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value; 762 + err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value ? 0x0f : 0x0c); 763 + if (!err) 764 + decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value; 927 765 break; 928 - default: 929 - v4l2_err(sd, "invalid control id %d\n", ctrl->id); 930 - return err; 931 766 } 932 767 933 768 v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d\n", 934 - ctrl->id, ctrl->value); 935 - 769 + ctrl->id, ctrl->val); 936 770 return err; 937 771 } 938 772 ··· 952 1104 return err; 953 1105 } 954 1106 955 - static const struct v4l2_subdev_core_ops tvp514x_core_ops = { 956 - .queryctrl = tvp514x_queryctrl, 957 - .g_ctrl = tvp514x_g_ctrl, 1107 + static const struct v4l2_ctrl_ops tvp514x_ctrl_ops = { 958 1108 .s_ctrl = tvp514x_s_ctrl, 1109 + }; 1110 + 1111 + static const struct v4l2_subdev_core_ops tvp514x_core_ops = { 1112 + .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 1113 + .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 1114 + .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 1115 + .g_ctrl = v4l2_subdev_g_ctrl, 1116 + .s_ctrl = v4l2_subdev_s_ctrl, 1117 + .queryctrl = v4l2_subdev_queryctrl, 1118 + .querymenu = v4l2_subdev_querymenu, 959 1119 .s_std = tvp514x_s_std, 960 1120 }; 961 1121 ··· 1046 1190 sd = &decoder->sd; 1047 1191 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops); 1048 1192 1193 + v4l2_ctrl_handler_init(&decoder->hdl, 5); 1194 + v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, 1195 + V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); 1196 + v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, 1197 + V4L2_CID_CONTRAST, 0, 255, 1, 128); 1198 + v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, 1199 + V4L2_CID_SATURATION, 0, 255, 1, 128); 1200 + v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, 1201 + V4L2_CID_HUE, -180, 180, 180, 0); 1202 + v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, 1203 + V4L2_CID_AUTOGAIN, 0, 1, 1, 1); 1204 + sd->ctrl_handler = &decoder->hdl; 1205 + if (decoder->hdl.error) { 1206 + int err = decoder->hdl.error; 1207 + 1208 + v4l2_ctrl_handler_free(&decoder->hdl); 1209 + kfree(decoder); 1210 + return err; 1211 + } 1212 + v4l2_ctrl_handler_setup(&decoder->hdl); 1213 + 1049 1214 v4l2_info(sd, "%s decoder driver registered !!\n", sd->name); 1050 1215 1051 1216 return 0; ··· 1086 1209 struct tvp514x_decoder *decoder = to_decoder(sd); 1087 1210 1088 1211 v4l2_device_unregister_subdev(sd); 1212 + v4l2_ctrl_handler_free(&decoder->hdl); 1089 1213 kfree(decoder); 1090 1214 return 0; 1091 1215 }