Skip to content

Commit ee02da6

Browse files
Hans VerkuilMauro Carvalho Chehab
authored andcommitted
[media] soc_camera: add control handler support
The soc_camera framework is switched over to use the control framework. After this patch none of the controls in subdevs or host drivers are available, until those drivers are also converted to the control framework. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> [g.liakhovetski@gmx.de: moved code around, fixed problems] Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent 1d3564d commit ee02da6

2 files changed

Lines changed: 21 additions & 75 deletions

File tree

‎drivers/media/video/soc_camera.c‎

Lines changed: 19 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ static int soc_camera_open(struct file *file)
512512
if (ret < 0)
513513
goto einitvb;
514514
}
515+
v4l2_ctrl_handler_setup(&icd->ctrl_handler);
515516
}
516517

517518
file->private_data = icd;
@@ -781,78 +782,6 @@ static int soc_camera_streamoff(struct file *file, void *priv,
781782
return 0;
782783
}
783784

784-
static int soc_camera_queryctrl(struct file *file, void *priv,
785-
struct v4l2_queryctrl *qc)
786-
{
787-
struct soc_camera_device *icd = file->private_data;
788-
struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
789-
int i;
790-
791-
WARN_ON(priv != file->private_data);
792-
793-
if (!qc->id)
794-
return -EINVAL;
795-
796-
/* First check host controls */
797-
for (i = 0; i < ici->ops->num_controls; i++)
798-
if (qc->id == ici->ops->controls[i].id) {
799-
memcpy(qc, &(ici->ops->controls[i]),
800-
sizeof(*qc));
801-
return 0;
802-
}
803-
804-
if (!icd->ops)
805-
return -EINVAL;
806-
807-
/* Then device controls */
808-
for (i = 0; i < icd->ops->num_controls; i++)
809-
if (qc->id == icd->ops->controls[i].id) {
810-
memcpy(qc, &(icd->ops->controls[i]),
811-
sizeof(*qc));
812-
return 0;
813-
}
814-
815-
return -EINVAL;
816-
}
817-
818-
static int soc_camera_g_ctrl(struct file *file, void *priv,
819-
struct v4l2_control *ctrl)
820-
{
821-
struct soc_camera_device *icd = file->private_data;
822-
struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
823-
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
824-
int ret;
825-
826-
WARN_ON(priv != file->private_data);
827-
828-
if (ici->ops->get_ctrl) {
829-
ret = ici->ops->get_ctrl(icd, ctrl);
830-
if (ret != -ENOIOCTLCMD)
831-
return ret;
832-
}
833-
834-
return v4l2_subdev_call(sd, core, g_ctrl, ctrl);
835-
}
836-
837-
static int soc_camera_s_ctrl(struct file *file, void *priv,
838-
struct v4l2_control *ctrl)
839-
{
840-
struct soc_camera_device *icd = file->private_data;
841-
struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
842-
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
843-
int ret;
844-
845-
WARN_ON(priv != file->private_data);
846-
847-
if (ici->ops->set_ctrl) {
848-
ret = ici->ops->set_ctrl(icd, ctrl);
849-
if (ret != -ENOIOCTLCMD)
850-
return ret;
851-
}
852-
853-
return v4l2_subdev_call(sd, core, s_ctrl, ctrl);
854-
}
855-
856785
static int soc_camera_cropcap(struct file *file, void *fh,
857786
struct v4l2_cropcap *a)
858787
{
@@ -1055,6 +984,17 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1055984

1056985
dev_info(icd->pdev, "Probing %s\n", dev_name(icd->pdev));
1057986

987+
/*
988+
* Currently the subdev with the largest number of controls (13) is
989+
* ov6550. So let's pick 16 as a hint for the control handler. Note
990+
* that this is a hint only: too large and you waste some memory, too
991+
* small and there is a (very) small performance hit when looking up
992+
* controls in the internal hash.
993+
*/
994+
ret = v4l2_ctrl_handler_init(&icd->ctrl_handler, 16);
995+
if (ret < 0)
996+
return ret;
997+
1058998
ret = regulator_bulk_get(icd->pdev, icl->num_regulators,
1059999
icl->regulators);
10601000
if (ret < 0)
@@ -1108,6 +1048,9 @@ static int soc_camera_probe(struct soc_camera_device *icd)
11081048
sd = soc_camera_to_subdev(icd);
11091049
sd->grp_id = (long)icd;
11101050

1051+
if (v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler))
1052+
goto ectrl;
1053+
11111054
/* At this point client .probe() should have run already */
11121055
ret = soc_camera_init_user_formats(icd);
11131056
if (ret < 0)
@@ -1146,6 +1089,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
11461089
mutex_unlock(&icd->video_lock);
11471090
soc_camera_free_user_formats(icd);
11481091
eiufmt:
1092+
ectrl:
11491093
if (icl->board_info) {
11501094
soc_camera_free_i2c(icd);
11511095
} else {
@@ -1162,6 +1106,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
11621106
epower:
11631107
regulator_bulk_free(icl->num_regulators, icl->regulators);
11641108
ereg:
1109+
v4l2_ctrl_handler_free(&icd->ctrl_handler);
11651110
return ret;
11661111
}
11671112

@@ -1176,6 +1121,7 @@ static int soc_camera_remove(struct soc_camera_device *icd)
11761121

11771122
BUG_ON(!icd->parent);
11781123

1124+
v4l2_ctrl_handler_free(&icd->ctrl_handler);
11791125
if (vdev) {
11801126
video_unregister_device(vdev);
11811127
icd->vdev = NULL;
@@ -1381,9 +1327,6 @@ static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
13811327
.vidioc_dqbuf = soc_camera_dqbuf,
13821328
.vidioc_streamon = soc_camera_streamon,
13831329
.vidioc_streamoff = soc_camera_streamoff,
1384-
.vidioc_queryctrl = soc_camera_queryctrl,
1385-
.vidioc_g_ctrl = soc_camera_g_ctrl,
1386-
.vidioc_s_ctrl = soc_camera_s_ctrl,
13871330
.vidioc_cropcap = soc_camera_cropcap,
13881331
.vidioc_g_crop = soc_camera_g_crop,
13891332
.vidioc_s_crop = soc_camera_s_crop,
@@ -1412,6 +1355,7 @@ static int video_dev_create(struct soc_camera_device *icd)
14121355
vdev->ioctl_ops = &soc_camera_ioctl_ops;
14131356
vdev->release = video_device_release;
14141357
vdev->tvnorms = V4L2_STD_UNKNOWN;
1358+
vdev->ctrl_handler = &icd->ctrl_handler;
14151359
vdev->lock = &icd->video_lock;
14161360

14171361
icd->vdev = vdev;

‎include/media/soc_camera.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/videodev2.h>
2020
#include <media/videobuf-core.h>
2121
#include <media/videobuf2-core.h>
22+
#include <media/v4l2-ctrls.h>
2223
#include <media/v4l2-device.h>
2324

2425
struct file;
@@ -40,6 +41,7 @@ struct soc_camera_device {
4041
struct soc_camera_sense *sense; /* See comment in struct definition */
4142
struct soc_camera_ops *ops;
4243
struct video_device *vdev;
44+
struct v4l2_ctrl_handler ctrl_handler;
4345
const struct soc_camera_format_xlate *current_fmt;
4446
struct soc_camera_format_xlate *user_formats;
4547
int num_user_formats;

0 commit comments

Comments
 (0)