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

[media] tvp7002: use 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
0eb73de0 9a775323

+43 -74
+43 -74
drivers/media/video/tvp7002.c
··· 32 32 #include <media/v4l2-device.h> 33 33 #include <media/v4l2-chip-ident.h> 34 34 #include <media/v4l2-common.h> 35 + #include <media/v4l2-ctrls.h> 35 36 #include "tvp7002_reg.h" 36 37 37 38 MODULE_DESCRIPTION("TI TVP7002 Video and Graphics Digitizer driver"); ··· 422 421 /* Device definition */ 423 422 struct tvp7002 { 424 423 struct v4l2_subdev sd; 424 + struct v4l2_ctrl_handler hdl; 425 425 const struct tvp7002_config *pdata; 426 426 427 427 int ver; 428 428 int streaming; 429 429 430 430 const struct tvp7002_preset_definition *current_preset; 431 - u8 gain; 432 431 }; 433 432 434 433 /* ··· 440 439 static inline struct tvp7002 *to_tvp7002(struct v4l2_subdev *sd) 441 440 { 442 441 return container_of(sd, struct tvp7002, sd); 442 + } 443 + 444 + static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) 445 + { 446 + return &container_of(ctrl->handler, struct tvp7002, hdl)->sd; 443 447 } 444 448 445 449 /* ··· 612 606 } 613 607 614 608 /* 615 - * tvp7002_g_ctrl() - Get a control 616 - * @sd: ptr to v4l2_subdev struct 617 - * @ctrl: ptr to v4l2_control struct 618 - * 619 - * Get a control for a TVP7002 decoder device. 620 - * Returns zero when successful or -EINVAL if register access fails. 621 - */ 622 - static int tvp7002_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 623 - { 624 - struct tvp7002 *device = to_tvp7002(sd); 625 - 626 - switch (ctrl->id) { 627 - case V4L2_CID_GAIN: 628 - ctrl->value = device->gain; 629 - return 0; 630 - default: 631 - return -EINVAL; 632 - } 633 - } 634 - 635 - /* 636 609 * tvp7002_s_ctrl() - Set a control 637 - * @sd: ptr to v4l2_subdev struct 638 - * @ctrl: ptr to v4l2_control struct 610 + * @ctrl: ptr to v4l2_ctrl struct 639 611 * 640 612 * Set a control in TVP7002 decoder device. 641 613 * Returns zero when successful or -EINVAL if register access fails. 642 614 */ 643 - static int tvp7002_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 615 + static int tvp7002_s_ctrl(struct v4l2_ctrl *ctrl) 644 616 { 645 - struct tvp7002 *device = to_tvp7002(sd); 617 + struct v4l2_subdev *sd = to_sd(ctrl); 646 618 int error = 0; 647 619 648 620 switch (ctrl->id) { 649 621 case V4L2_CID_GAIN: 650 - tvp7002_write_err(sd, TVP7002_R_FINE_GAIN, 651 - ctrl->value & 0xff, &error); 652 - tvp7002_write_err(sd, TVP7002_G_FINE_GAIN, 653 - ctrl->value & 0xff, &error); 654 - tvp7002_write_err(sd, TVP7002_B_FINE_GAIN, 655 - ctrl->value & 0xff, &error); 656 - 657 - if (error < 0) 658 - return error; 659 - 660 - /* Set only after knowing there is no error */ 661 - device->gain = ctrl->value & 0xff; 662 - return 0; 663 - default: 664 - return -EINVAL; 622 + tvp7002_write_err(sd, TVP7002_R_FINE_GAIN, ctrl->val, &error); 623 + tvp7002_write_err(sd, TVP7002_G_FINE_GAIN, ctrl->val, &error); 624 + tvp7002_write_err(sd, TVP7002_B_FINE_GAIN, ctrl->val, &error); 625 + return error; 665 626 } 666 - } 667 - 668 - /* 669 - * tvp7002_queryctrl() - Query a control 670 - * @sd: ptr to v4l2_subdev struct 671 - * @qc: ptr to v4l2_queryctrl struct 672 - * 673 - * Query a control of a TVP7002 decoder device. 674 - * Returns zero when successful or -EINVAL if register read fails. 675 - */ 676 - static int tvp7002_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) 677 - { 678 - switch (qc->id) { 679 - case V4L2_CID_GAIN: 680 - /* 681 - * Gain is supported [0-255, default=0, step=1] 682 - */ 683 - return v4l2_ctrl_query_fill(qc, 0, 255, 1, 0); 684 - default: 685 - return -EINVAL; 686 - } 627 + return -EINVAL; 687 628 } 688 629 689 630 /* ··· 877 924 device->streaming ? "yes" : "no"); 878 925 879 926 /* Print the current value of the gain control */ 880 - v4l2_info(sd, "Gain: %u\n", device->gain); 927 + v4l2_ctrl_handler_log_status(&device->hdl, sd->name); 881 928 882 929 return 0; 883 930 } ··· 899 946 return v4l_fill_dv_preset_info(tvp7002_presets[preset->index].preset, preset); 900 947 } 901 948 949 + static const struct v4l2_ctrl_ops tvp7002_ctrl_ops = { 950 + .s_ctrl = tvp7002_s_ctrl, 951 + }; 952 + 902 953 /* V4L2 core operation handlers */ 903 954 static const struct v4l2_subdev_core_ops tvp7002_core_ops = { 904 955 .g_chip_ident = tvp7002_g_chip_ident, 905 956 .log_status = tvp7002_log_status, 906 - .g_ctrl = tvp7002_g_ctrl, 907 - .s_ctrl = tvp7002_s_ctrl, 908 - .queryctrl = tvp7002_queryctrl, 957 + .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 958 + .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 959 + .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 960 + .g_ctrl = v4l2_subdev_g_ctrl, 961 + .s_ctrl = v4l2_subdev_s_ctrl, 962 + .queryctrl = v4l2_subdev_queryctrl, 963 + .querymenu = v4l2_subdev_querymenu, 909 964 #ifdef CONFIG_VIDEO_ADV_DEBUG 910 965 .g_register = tvp7002_g_register, 911 966 .s_register = tvp7002_s_register, ··· 936 975 static const struct v4l2_subdev_ops tvp7002_ops = { 937 976 .core = &tvp7002_core_ops, 938 977 .video = &tvp7002_video_ops, 939 - }; 940 - 941 - static struct tvp7002 tvp7002_dev = { 942 - .streaming = 0, 943 - .current_preset = tvp7002_presets, 944 - .gain = 0, 945 978 }; 946 979 947 980 /* ··· 968 1013 return -ENODEV; 969 1014 } 970 1015 971 - device = kmalloc(sizeof(struct tvp7002), GFP_KERNEL); 1016 + device = kzalloc(sizeof(struct tvp7002), GFP_KERNEL); 972 1017 973 1018 if (!device) 974 1019 return -ENOMEM; 975 1020 976 - *device = tvp7002_dev; 977 1021 sd = &device->sd; 978 1022 device->pdata = c->dev.platform_data; 1023 + device->current_preset = tvp7002_presets; 979 1024 980 1025 /* Tell v4l2 the device is ready */ 981 1026 v4l2_i2c_subdev_init(sd, c, &tvp7002_ops); ··· 1015 1060 preset.preset = device->current_preset->preset; 1016 1061 error = tvp7002_s_dv_preset(sd, &preset); 1017 1062 1063 + v4l2_ctrl_handler_init(&device->hdl, 1); 1064 + v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops, 1065 + V4L2_CID_GAIN, 0, 255, 1, 0); 1066 + sd->ctrl_handler = &device->hdl; 1067 + if (device->hdl.error) { 1068 + int err = device->hdl.error; 1069 + 1070 + v4l2_ctrl_handler_free(&device->hdl); 1071 + kfree(device); 1072 + return err; 1073 + } 1074 + v4l2_ctrl_handler_setup(&device->hdl); 1075 + 1018 1076 found_error: 1019 1077 if (error < 0) 1020 1078 kfree(device); ··· 1051 1083 "on address 0x%x\n", c->addr); 1052 1084 1053 1085 v4l2_device_unregister_subdev(sd); 1086 + v4l2_ctrl_handler_free(&device->hdl); 1054 1087 kfree(device); 1055 1088 return 0; 1056 1089 }