forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/media/platform/s5p-jpeg/jpeg-core.c
....@@ -1,14 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* linux/drivers/media/platform/s5p-jpeg/jpeg-core.c
23 *
34 * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
45 * http://www.samsung.com
56 *
6
- * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
7
+ * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
78 * Author: Jacek Anaszewski <j.anaszewski@samsung.com>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License version 2 as
11
- * published by the Free Software Foundation.
129 */
1310
1411 #include <linux/clk.h>
....@@ -27,6 +24,7 @@
2724 #include <media/v4l2-event.h>
2825 #include <media/v4l2-mem2mem.h>
2926 #include <media/v4l2-ioctl.h>
27
+#include <media/v4l2-rect.h>
3028 #include <media/videobuf2-v4l2.h>
3129 #include <media/videobuf2-dma-contig.h>
3230
....@@ -38,7 +36,6 @@
3836
3937 static struct s5p_jpeg_fmt sjpeg_formats[] = {
4038 {
41
- .name = "JPEG JFIF",
4239 .fourcc = V4L2_PIX_FMT_JPEG,
4340 .flags = SJPEG_FMT_FLAG_ENC_CAPTURE |
4441 SJPEG_FMT_FLAG_DEC_OUTPUT |
....@@ -47,7 +44,6 @@
4744 SJPEG_FMT_FLAG_EXYNOS4,
4845 },
4946 {
50
- .name = "YUV 4:2:2 packed, YCbYCr",
5147 .fourcc = V4L2_PIX_FMT_YUYV,
5248 .depth = 16,
5349 .colplanes = 1,
....@@ -60,7 +56,6 @@
6056 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
6157 },
6258 {
63
- .name = "YUV 4:2:2 packed, YCbYCr",
6459 .fourcc = V4L2_PIX_FMT_YUYV,
6560 .depth = 16,
6661 .colplanes = 1,
....@@ -73,7 +68,6 @@
7368 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
7469 },
7570 {
76
- .name = "YUV 4:2:2 packed, YCbYCr",
7771 .fourcc = V4L2_PIX_FMT_YUYV,
7872 .depth = 16,
7973 .colplanes = 1,
....@@ -86,7 +80,6 @@
8680 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
8781 },
8882 {
89
- .name = "YUV 4:2:2 packed, YCrYCb",
9083 .fourcc = V4L2_PIX_FMT_YVYU,
9184 .depth = 16,
9285 .colplanes = 1,
....@@ -99,7 +92,6 @@
9992 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
10093 },
10194 {
102
- .name = "YUV 4:2:2 packed, YCrYCb",
10395 .fourcc = V4L2_PIX_FMT_YVYU,
10496 .depth = 16,
10597 .colplanes = 1,
....@@ -112,7 +104,6 @@
112104 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
113105 },
114106 {
115
- .name = "YUV 4:2:2 packed, YCrYCb",
116107 .fourcc = V4L2_PIX_FMT_UYVY,
117108 .depth = 16,
118109 .colplanes = 1,
....@@ -125,7 +116,6 @@
125116 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
126117 },
127118 {
128
- .name = "YUV 4:2:2 packed, YCrYCb",
129119 .fourcc = V4L2_PIX_FMT_VYUY,
130120 .depth = 16,
131121 .colplanes = 1,
....@@ -138,7 +128,6 @@
138128 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
139129 },
140130 {
141
- .name = "RGB565",
142131 .fourcc = V4L2_PIX_FMT_RGB565,
143132 .depth = 16,
144133 .colplanes = 1,
....@@ -151,7 +140,6 @@
151140 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
152141 },
153142 {
154
- .name = "RGB565",
155143 .fourcc = V4L2_PIX_FMT_RGB565,
156144 .depth = 16,
157145 .colplanes = 1,
....@@ -164,7 +152,6 @@
164152 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
165153 },
166154 {
167
- .name = "RGB565X",
168155 .fourcc = V4L2_PIX_FMT_RGB565X,
169156 .depth = 16,
170157 .colplanes = 1,
....@@ -177,7 +164,6 @@
177164 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
178165 },
179166 {
180
- .name = "RGB565",
181167 .fourcc = V4L2_PIX_FMT_RGB565,
182168 .depth = 16,
183169 .colplanes = 1,
....@@ -189,7 +175,6 @@
189175 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
190176 },
191177 {
192
- .name = "ARGB8888, 32 bpp",
193178 .fourcc = V4L2_PIX_FMT_RGB32,
194179 .depth = 32,
195180 .colplanes = 1,
....@@ -202,7 +187,6 @@
202187 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
203188 },
204189 {
205
- .name = "ARGB8888, 32 bpp",
206190 .fourcc = V4L2_PIX_FMT_RGB32,
207191 .depth = 32,
208192 .colplanes = 1,
....@@ -215,7 +199,6 @@
215199 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
216200 },
217201 {
218
- .name = "YUV 4:4:4 planar, Y/CbCr",
219202 .fourcc = V4L2_PIX_FMT_NV24,
220203 .depth = 24,
221204 .colplanes = 2,
....@@ -228,7 +211,6 @@
228211 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
229212 },
230213 {
231
- .name = "YUV 4:4:4 planar, Y/CrCb",
232214 .fourcc = V4L2_PIX_FMT_NV42,
233215 .depth = 24,
234216 .colplanes = 2,
....@@ -241,7 +223,6 @@
241223 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
242224 },
243225 {
244
- .name = "YUV 4:2:2 planar, Y/CrCb",
245226 .fourcc = V4L2_PIX_FMT_NV61,
246227 .depth = 16,
247228 .colplanes = 2,
....@@ -254,7 +235,6 @@
254235 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
255236 },
256237 {
257
- .name = "YUV 4:2:2 planar, Y/CbCr",
258238 .fourcc = V4L2_PIX_FMT_NV16,
259239 .depth = 16,
260240 .colplanes = 2,
....@@ -267,7 +247,6 @@
267247 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422,
268248 },
269249 {
270
- .name = "YUV 4:2:0 planar, Y/CbCr",
271250 .fourcc = V4L2_PIX_FMT_NV12,
272251 .depth = 12,
273252 .colplanes = 2,
....@@ -280,7 +259,6 @@
280259 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420,
281260 },
282261 {
283
- .name = "YUV 4:2:0 planar, Y/CbCr",
284262 .fourcc = V4L2_PIX_FMT_NV12,
285263 .depth = 12,
286264 .colplanes = 2,
....@@ -293,7 +271,6 @@
293271 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420,
294272 },
295273 {
296
- .name = "YUV 4:2:0 planar, Y/CbCr",
297274 .fourcc = V4L2_PIX_FMT_NV12,
298275 .depth = 12,
299276 .colplanes = 2,
....@@ -306,7 +283,6 @@
306283 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420,
307284 },
308285 {
309
- .name = "YUV 4:2:0 planar, Y/CrCb",
310286 .fourcc = V4L2_PIX_FMT_NV21,
311287 .depth = 12,
312288 .colplanes = 2,
....@@ -319,7 +295,6 @@
319295 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420,
320296 },
321297 {
322
- .name = "YUV 4:2:0 planar, Y/CrCb",
323298 .fourcc = V4L2_PIX_FMT_NV21,
324299 .depth = 12,
325300 .colplanes = 2,
....@@ -333,7 +308,6 @@
333308 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420,
334309 },
335310 {
336
- .name = "YUV 4:2:0 contiguous 3-planar, Y/Cb/Cr",
337311 .fourcc = V4L2_PIX_FMT_YUV420,
338312 .depth = 12,
339313 .colplanes = 3,
....@@ -346,7 +320,6 @@
346320 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420,
347321 },
348322 {
349
- .name = "YUV 4:2:0 contiguous 3-planar, Y/Cb/Cr",
350323 .fourcc = V4L2_PIX_FMT_YUV420,
351324 .depth = 12,
352325 .colplanes = 3,
....@@ -359,7 +332,6 @@
359332 .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420,
360333 },
361334 {
362
- .name = "Gray",
363335 .fourcc = V4L2_PIX_FMT_GREY,
364336 .depth = 8,
365337 .colplanes = 1,
....@@ -1265,7 +1237,6 @@
12651237 }
12661238 result->sof = sof;
12671239 result->sof_len = sof_len;
1268
- result->components = components;
12691240
12701241 return true;
12711242 }
....@@ -1276,20 +1247,18 @@
12761247 struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
12771248
12781249 if (ctx->mode == S5P_JPEG_ENCODE) {
1279
- strlcpy(cap->driver, S5P_JPEG_M2M_NAME,
1250
+ strscpy(cap->driver, S5P_JPEG_M2M_NAME,
12801251 sizeof(cap->driver));
1281
- strlcpy(cap->card, S5P_JPEG_M2M_NAME " encoder",
1252
+ strscpy(cap->card, S5P_JPEG_M2M_NAME " encoder",
12821253 sizeof(cap->card));
12831254 } else {
1284
- strlcpy(cap->driver, S5P_JPEG_M2M_NAME,
1255
+ strscpy(cap->driver, S5P_JPEG_M2M_NAME,
12851256 sizeof(cap->driver));
1286
- strlcpy(cap->card, S5P_JPEG_M2M_NAME " decoder",
1257
+ strscpy(cap->card, S5P_JPEG_M2M_NAME " decoder",
12871258 sizeof(cap->card));
12881259 }
12891260 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
12901261 dev_name(ctx->jpeg->dev));
1291
- cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M;
1292
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
12931262 return 0;
12941263 }
12951264
....@@ -1317,7 +1286,6 @@
13171286 if (i >= n)
13181287 return -EINVAL;
13191288
1320
- strlcpy(f->description, sjpeg_formats[i].name, sizeof(f->description));
13211289 f->pixelformat = sjpeg_formats[i].fourcc;
13221290
13231291 return 0;
....@@ -1768,19 +1736,6 @@
17681736 return 0;
17691737 }
17701738
1771
-/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
1772
-static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
1773
-{
1774
- if (a->left < b->left || a->top < b->top)
1775
- return 0;
1776
- if (a->left + a->width > b->left + b->width)
1777
- return 0;
1778
- if (a->top + a->height > b->top + b->height)
1779
- return 0;
1780
-
1781
- return 1;
1782
-}
1783
-
17841739 static int exynos3250_jpeg_try_crop(struct s5p_jpeg_ctx *ctx,
17851740 struct v4l2_rect *r)
17861741 {
....@@ -1813,7 +1768,7 @@
18131768 r->left = round_down(r->left, 2);
18141769 r->top = round_down(r->top, 2);
18151770
1816
- if (!enclosed_rectangle(r, &base_rect))
1771
+ if (!v4l2_rect_enclosed(r, &base_rect))
18171772 return -EINVAL;
18181773
18191774 ctx->crop_rect.left = r->left;
....@@ -2611,11 +2566,8 @@
26112566 static int s5p_jpeg_start_streaming(struct vb2_queue *q, unsigned int count)
26122567 {
26132568 struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(q);
2614
- int ret;
26152569
2616
- ret = pm_runtime_get_sync(ctx->jpeg->dev);
2617
-
2618
- return ret > 0 ? 0 : ret;
2570
+ return pm_runtime_resume_and_get(ctx->jpeg->dev);
26192571 }
26202572
26212573 static void s5p_jpeg_stop_streaming(struct vb2_queue *q)
....@@ -2977,8 +2929,9 @@
29772929 jpeg->vfd_encoder->lock = &jpeg->lock;
29782930 jpeg->vfd_encoder->v4l2_dev = &jpeg->v4l2_dev;
29792931 jpeg->vfd_encoder->vfl_dir = VFL_DIR_M2M;
2932
+ jpeg->vfd_encoder->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M;
29802933
2981
- ret = video_register_device(jpeg->vfd_encoder, VFL_TYPE_GRABBER, -1);
2934
+ ret = video_register_device(jpeg->vfd_encoder, VFL_TYPE_VIDEO, -1);
29822935 if (ret) {
29832936 v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n");
29842937 video_device_release(jpeg->vfd_encoder);
....@@ -3006,8 +2959,9 @@
30062959 jpeg->vfd_decoder->lock = &jpeg->lock;
30072960 jpeg->vfd_decoder->v4l2_dev = &jpeg->v4l2_dev;
30082961 jpeg->vfd_decoder->vfl_dir = VFL_DIR_M2M;
2962
+ jpeg->vfd_decoder->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M;
30092963
3010
- ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_GRABBER, -1);
2964
+ ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_VIDEO, -1);
30112965 if (ret) {
30122966 v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n");
30132967 video_device_release(jpeg->vfd_decoder);
....@@ -3223,7 +3177,7 @@
32233177
32243178 module_platform_driver(s5p_jpeg_driver);
32253179
3226
-MODULE_AUTHOR("Andrzej Pietrasiewicz <andrzej.p@samsung.com>");
3180
+MODULE_AUTHOR("Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>");
32273181 MODULE_AUTHOR("Jacek Anaszewski <j.anaszewski@samsung.com>");
32283182 MODULE_DESCRIPTION("Samsung JPEG codec driver");
32293183 MODULE_LICENSE("GPL");