Summary
I'm currently trying to add custom V4L2 controls to a V4L2 device after v4l2_ctrl_handler_setup
is called in a Linux Kernel driver. However the control does not seem to be added (does not show up when running v4l2-ctl --list-ctrls
). Below is generally the approach I am trying to take.
static int add_custom_v4l2_ctrls(struct tegracam_device *tc_dev)
{
struct camera_common_data *s_data = tc_dev->s_data;
struct v4l2_ctrl_handler *ctrl_handler = s_data->ctrl_handler;
struct v4l2_ctrl *ctrl;
int err = 0;
static struct v4l2_ctrl_config my_control = {
.ops = &my_custom_ctrl_ops,
.id = TEGRA_CAMERA_CID_BASE+150,
.name = "My control",
.type = V4L2_CTRL_TYPE_INTEGER,
.flags = V4L2_CTRL_FLAG_SLIDER,
.min = 0,
.max = 1,
.def = 0,
.step = 1,
};
// Increment number of controls
tc_dev->numctrls++;
s_data->numctrls++;
ctrl = v4l2_ctrl_new_custom(ctrl_handler, &my_control, NULL);
if(ctrl == NULL) {
dev_err(tc_dev->dev, "Failed to init ctrl");
return -EIO;
}
// err = v4l2_ctrl_handler_setup(ctrl_handler);
if(err) {
printk("FAILED");
}
return 0;
}
This code snippet is run after an effective call to v4l2_ctrl_handler_setup
and v4l2_async_register_subdev
.
Question
Is it possible to add custom V4L2 controls after the device has been registered? If so, what is wrong with my approach which is causing the control to not show up?
More Info
This driver is implemented using NVIDIA's Tegracam V2 framework which abstracts V4L2 setup code including the addition of controls, at the moment it does not expose the ability for adding custom V4L2 controls which is the reasoning behind this approach.
After following down the call stack I found this order (arrows represent calls, links are to the Linux source code).
v4l2_async_register_subdev -> v4l2_async_match_notify -> v4l2_device_register_subdev -> v4l2_ctrl_add_handler
The last function (v4l2_ctrl_add_handler) goes through and copies V4L2 controls from one handler to another.
Therefore, if the V4L2 control is not added before
v4l2_async_register_subdev
is called, then the control will not be copied to the different devices and will therefore not be a valid option available.So in summation from what I found, no it is not possible to add V4L2 controls after the device has been registered.