9c9a0bf6bbc6e34674164b00945827ec5b8af881
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-4.19 / 950-0742-staging-bcm2835-codec-Add-support-for-ENUM_FRAMESIZE.patch
1 From 9894906ad424f266853b61a6996b2da8b119c6e6 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Fri, 13 Sep 2019 17:19:33 +0100
4 Subject: [PATCH] staging:bcm2835-codec: Add support for
5 ENUM_FRAMESIZES
6
7 Required for compliance testing for the encoder.
8
9 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
10 ---
11 .../bcm2835-codec/bcm2835-v4l2-codec.c | 48 +++++++++++++++++--
12 1 file changed, 44 insertions(+), 4 deletions(-)
13
14 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
15 +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
16 @@ -496,9 +496,10 @@ struct bcm2835_codec_fmt *get_default_fo
17 return &dev->supported_fmts[capture ? 1 : 0].list[0];
18 }
19
20 -static struct bcm2835_codec_fmt *find_format(struct v4l2_format *f,
21 - struct bcm2835_codec_dev *dev,
22 - bool capture)
23 +static
24 +struct bcm2835_codec_fmt *find_format_pix_fmt(u32 pix_fmt,
25 + struct bcm2835_codec_dev *dev,
26 + bool capture)
27 {
28 struct bcm2835_codec_fmt *fmt;
29 unsigned int k;
30 @@ -507,7 +508,7 @@ static struct bcm2835_codec_fmt *find_fo
31
32 for (k = 0; k < fmts->num_entries; k++) {
33 fmt = &fmts->list[k];
34 - if (fmt->fourcc == f->fmt.pix_mp.pixelformat)
35 + if (fmt->fourcc == pix_fmt)
36 break;
37 }
38 if (k == fmts->num_entries)
39 @@ -516,6 +517,14 @@ static struct bcm2835_codec_fmt *find_fo
40 return &fmts->list[k];
41 }
42
43 +static inline
44 +struct bcm2835_codec_fmt *find_format(struct v4l2_format *f,
45 + struct bcm2835_codec_dev *dev,
46 + bool capture)
47 +{
48 + return find_format_pix_fmt(f->fmt.pix_mp.pixelformat, dev, capture);
49 +}
50 +
51 static inline struct bcm2835_codec_ctx *file2ctx(struct file *file)
52 {
53 return container_of(file->private_data, struct bcm2835_codec_ctx, fh);
54 @@ -1792,6 +1801,36 @@ static int vidioc_encoder_cmd(struct fil
55 return 0;
56 }
57
58 +static int vidioc_enum_framesizes(struct file *file, void *fh,
59 + struct v4l2_frmsizeenum *fsize)
60 +{
61 + struct bcm2835_codec_fmt *fmt;
62 +
63 + fmt = find_format_pix_fmt(fsize->pixel_format, file2ctx(file)->dev,
64 + true);
65 + if (!fmt)
66 + fmt = find_format_pix_fmt(fsize->pixel_format,
67 + file2ctx(file)->dev,
68 + false);
69 +
70 + if (!fmt)
71 + return -EINVAL;
72 +
73 + if (fsize->index)
74 + return -EINVAL;
75 +
76 + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
77 +
78 + fsize->stepwise.min_width = MIN_W;
79 + fsize->stepwise.max_width = MAX_W;
80 + fsize->stepwise.step_width = 1;
81 + fsize->stepwise.min_height = MIN_H;
82 + fsize->stepwise.max_height = MAX_H;
83 + fsize->stepwise.step_height = 1;
84 +
85 + return 0;
86 +}
87 +
88 static const struct v4l2_ioctl_ops bcm2835_codec_ioctl_ops = {
89 .vidioc_querycap = vidioc_querycap,
90
91 @@ -1829,6 +1868,7 @@ static const struct v4l2_ioctl_ops bcm28
92 .vidioc_try_decoder_cmd = vidioc_try_decoder_cmd,
93 .vidioc_encoder_cmd = vidioc_encoder_cmd,
94 .vidioc_try_encoder_cmd = vidioc_try_encoder_cmd,
95 + .vidioc_enum_framesizes = vidioc_enum_framesizes,
96 };
97
98 static int bcm2835_codec_set_ctrls(struct bcm2835_codec_ctx *ctx)