fd24c87bc326e6c99b3d530ff221f6edce481deb
[openwrt/staging/wigyori.git] /
1 From 7ec008222fcb4682fa2cfdbb62e657bf98950ec5 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Tue, 19 May 2020 15:56:47 +0100
4 Subject: [PATCH] staging: vc04_services: isp: Fixup g/s_selection
5 implementation
6
7 Add V4L2_SEL_TGT_CROP_DEFAULT and V4L2_SEL_TGT_CROP_BOUND targets.
8 Disable the appropriate ioctls for the meta capture nodes - this now
9 passes v4l2-compliance tests.
10
11 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
12 ---
13 .../bcm2835-isp/bcm2835-v4l2-isp.c | 84 ++++++++++++-------
14 1 file changed, 55 insertions(+), 29 deletions(-)
15
16 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
17 +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
18 @@ -1006,15 +1006,32 @@ static int bcm2835_isp_node_s_selection(
19 if (!s->r.width || !s->r.height)
20 return -EINVAL;
21
22 - /* Adjust the crop window if goes outside the frame dimensions. */
23 - s->r.left = min((unsigned int)max(s->r.left, 0),
24 - node->q_data.width - MIN_DIM);
25 - s->r.top = min((unsigned int)max(s->r.top, 0),
26 - node->q_data.height - MIN_DIM);
27 - s->r.width = max(min(s->r.width, node->q_data.width - s->r.left),
28 - MIN_DIM);
29 - s->r.height = max(min(s->r.height, node->q_data.height - s->r.top),
30 - MIN_DIM);
31 + /* We can only set crop on the input. */
32 + switch (s->target) {
33 + case V4L2_SEL_TGT_CROP:
34 + /*
35 + * Adjust the crop window if it goes outside of the frame
36 + * dimensions.
37 + */
38 + s->r.left = min((unsigned int)max(s->r.left, 0),
39 + node->q_data.width - MIN_DIM);
40 + s->r.top = min((unsigned int)max(s->r.top, 0),
41 + node->q_data.height - MIN_DIM);
42 + s->r.width = max(min(s->r.width,
43 + node->q_data.width - s->r.left), MIN_DIM);
44 + s->r.height = max(min(s->r.height,
45 + node->q_data.height - s->r.top), MIN_DIM);
46 + break;
47 + case V4L2_SEL_TGT_CROP_DEFAULT:
48 + /* Default (i.e. no) crop window. */
49 + s->r.left = 0;
50 + s->r.top = 0;
51 + s->r.width = node->q_data.width;
52 + s->r.height = node->q_data.height;
53 + break;
54 + default:
55 + return -EINVAL;
56 + }
57
58 crop.rect.x = s->r.left;
59 crop.rect.y = s->r.top;
60 @@ -1029,33 +1046,40 @@ static int bcm2835_isp_node_s_selection(
61 static int bcm2835_isp_node_g_selection(struct file *file, void *fh,
62 struct v4l2_selection *s)
63 {
64 + struct mmal_parameter_crop crop;
65 struct bcm2835_isp_node *node = video_drvdata(file);
66 - struct bcm2835_isp_dev *dev = node_get_dev(node);
67 struct vchiq_mmal_port *port = get_port_data(node);
68 - struct mmal_parameter_crop crop;
69 + struct bcm2835_isp_dev *dev = node_get_dev(node);
70 u32 crop_size = sizeof(crop);
71 int ret;
72
73 - /* This return value is required for V4L2 compliance. */
74 - if (node_is_stats(node))
75 - return -ENOTTY;
76 -
77 /* We can only return out an input crop. */
78 - if (s->target != V4L2_SEL_TGT_CROP)
79 - return -EINVAL;
80 -
81 - ret = vchiq_mmal_port_parameter_get(dev->mmal_instance, port,
82 - MMAL_PARAMETER_CROP,
83 - &crop, &crop_size);
84 - if (!ret)
85 - return -EINVAL;
86 -
87 - s->r.left = crop.rect.x;
88 - s->r.top = crop.rect.y;
89 - s->r.width = crop.rect.width;
90 - s->r.height = crop.rect.height;
91 + switch (s->target) {
92 + case V4L2_SEL_TGT_CROP:
93 + ret = vchiq_mmal_port_parameter_get(dev->mmal_instance, port,
94 + MMAL_PARAMETER_CROP,
95 + &crop, &crop_size);
96 + if (!ret) {
97 + s->r.left = crop.rect.x;
98 + s->r.top = crop.rect.y;
99 + s->r.width = crop.rect.width;
100 + s->r.height = crop.rect.height;
101 + }
102 + break;
103 + case V4L2_SEL_TGT_CROP_DEFAULT:
104 + case V4L2_SEL_TGT_CROP_BOUNDS:
105 + /* Default (i.e. no) crop window. */
106 + s->r.left = 0;
107 + s->r.top = 0;
108 + s->r.width = node->q_data.width;
109 + s->r.height = node->q_data.height;
110 + ret = 0;
111 + break;
112 + default:
113 + ret = -EINVAL;
114 + }
115
116 - return 0;
117 + return ret;
118 }
119
120 static int bcm3285_isp_subscribe_event(struct v4l2_fh *fh,
121 @@ -1218,6 +1242,8 @@ static int register_node(struct bcm2835_
122 node->vfl_dir = VFL_DIR_RX;
123 node->name = "stats";
124 v4l2_disable_ioctl(&node->vfd, VIDIOC_S_CTRL);
125 + v4l2_disable_ioctl(&node->vfd, VIDIOC_S_SELECTION);
126 + v4l2_disable_ioctl(&node->vfd, VIDIOC_G_SELECTION);
127 break;
128 }
129