| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* linux/drivers/media/platform/s5p-jpeg/jpeg-core.c |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd. |
|---|
| 4 | 5 | * http://www.samsung.com |
|---|
| 5 | 6 | * |
|---|
| 6 | | - * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> |
|---|
| 7 | + * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com> |
|---|
| 7 | 8 | * 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. |
|---|
| 12 | 9 | */ |
|---|
| 13 | 10 | |
|---|
| 14 | 11 | #include <linux/clk.h> |
|---|
| .. | .. |
|---|
| 27 | 24 | #include <media/v4l2-event.h> |
|---|
| 28 | 25 | #include <media/v4l2-mem2mem.h> |
|---|
| 29 | 26 | #include <media/v4l2-ioctl.h> |
|---|
| 27 | +#include <media/v4l2-rect.h> |
|---|
| 30 | 28 | #include <media/videobuf2-v4l2.h> |
|---|
| 31 | 29 | #include <media/videobuf2-dma-contig.h> |
|---|
| 32 | 30 | |
|---|
| .. | .. |
|---|
| 38 | 36 | |
|---|
| 39 | 37 | static struct s5p_jpeg_fmt sjpeg_formats[] = { |
|---|
| 40 | 38 | { |
|---|
| 41 | | - .name = "JPEG JFIF", |
|---|
| 42 | 39 | .fourcc = V4L2_PIX_FMT_JPEG, |
|---|
| 43 | 40 | .flags = SJPEG_FMT_FLAG_ENC_CAPTURE | |
|---|
| 44 | 41 | SJPEG_FMT_FLAG_DEC_OUTPUT | |
|---|
| .. | .. |
|---|
| 47 | 44 | SJPEG_FMT_FLAG_EXYNOS4, |
|---|
| 48 | 45 | }, |
|---|
| 49 | 46 | { |
|---|
| 50 | | - .name = "YUV 4:2:2 packed, YCbYCr", |
|---|
| 51 | 47 | .fourcc = V4L2_PIX_FMT_YUYV, |
|---|
| 52 | 48 | .depth = 16, |
|---|
| 53 | 49 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 60 | 56 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 61 | 57 | }, |
|---|
| 62 | 58 | { |
|---|
| 63 | | - .name = "YUV 4:2:2 packed, YCbYCr", |
|---|
| 64 | 59 | .fourcc = V4L2_PIX_FMT_YUYV, |
|---|
| 65 | 60 | .depth = 16, |
|---|
| 66 | 61 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 73 | 68 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 74 | 69 | }, |
|---|
| 75 | 70 | { |
|---|
| 76 | | - .name = "YUV 4:2:2 packed, YCbYCr", |
|---|
| 77 | 71 | .fourcc = V4L2_PIX_FMT_YUYV, |
|---|
| 78 | 72 | .depth = 16, |
|---|
| 79 | 73 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 86 | 80 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 87 | 81 | }, |
|---|
| 88 | 82 | { |
|---|
| 89 | | - .name = "YUV 4:2:2 packed, YCrYCb", |
|---|
| 90 | 83 | .fourcc = V4L2_PIX_FMT_YVYU, |
|---|
| 91 | 84 | .depth = 16, |
|---|
| 92 | 85 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 99 | 92 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 100 | 93 | }, |
|---|
| 101 | 94 | { |
|---|
| 102 | | - .name = "YUV 4:2:2 packed, YCrYCb", |
|---|
| 103 | 95 | .fourcc = V4L2_PIX_FMT_YVYU, |
|---|
| 104 | 96 | .depth = 16, |
|---|
| 105 | 97 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 112 | 104 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 113 | 105 | }, |
|---|
| 114 | 106 | { |
|---|
| 115 | | - .name = "YUV 4:2:2 packed, YCrYCb", |
|---|
| 116 | 107 | .fourcc = V4L2_PIX_FMT_UYVY, |
|---|
| 117 | 108 | .depth = 16, |
|---|
| 118 | 109 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 125 | 116 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 126 | 117 | }, |
|---|
| 127 | 118 | { |
|---|
| 128 | | - .name = "YUV 4:2:2 packed, YCrYCb", |
|---|
| 129 | 119 | .fourcc = V4L2_PIX_FMT_VYUY, |
|---|
| 130 | 120 | .depth = 16, |
|---|
| 131 | 121 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 138 | 128 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 139 | 129 | }, |
|---|
| 140 | 130 | { |
|---|
| 141 | | - .name = "RGB565", |
|---|
| 142 | 131 | .fourcc = V4L2_PIX_FMT_RGB565, |
|---|
| 143 | 132 | .depth = 16, |
|---|
| 144 | 133 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 151 | 140 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444, |
|---|
| 152 | 141 | }, |
|---|
| 153 | 142 | { |
|---|
| 154 | | - .name = "RGB565", |
|---|
| 155 | 143 | .fourcc = V4L2_PIX_FMT_RGB565, |
|---|
| 156 | 144 | .depth = 16, |
|---|
| 157 | 145 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 164 | 152 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444, |
|---|
| 165 | 153 | }, |
|---|
| 166 | 154 | { |
|---|
| 167 | | - .name = "RGB565X", |
|---|
| 168 | 155 | .fourcc = V4L2_PIX_FMT_RGB565X, |
|---|
| 169 | 156 | .depth = 16, |
|---|
| 170 | 157 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 177 | 164 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444, |
|---|
| 178 | 165 | }, |
|---|
| 179 | 166 | { |
|---|
| 180 | | - .name = "RGB565", |
|---|
| 181 | 167 | .fourcc = V4L2_PIX_FMT_RGB565, |
|---|
| 182 | 168 | .depth = 16, |
|---|
| 183 | 169 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 189 | 175 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444, |
|---|
| 190 | 176 | }, |
|---|
| 191 | 177 | { |
|---|
| 192 | | - .name = "ARGB8888, 32 bpp", |
|---|
| 193 | 178 | .fourcc = V4L2_PIX_FMT_RGB32, |
|---|
| 194 | 179 | .depth = 32, |
|---|
| 195 | 180 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 202 | 187 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444, |
|---|
| 203 | 188 | }, |
|---|
| 204 | 189 | { |
|---|
| 205 | | - .name = "ARGB8888, 32 bpp", |
|---|
| 206 | 190 | .fourcc = V4L2_PIX_FMT_RGB32, |
|---|
| 207 | 191 | .depth = 32, |
|---|
| 208 | 192 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 215 | 199 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444, |
|---|
| 216 | 200 | }, |
|---|
| 217 | 201 | { |
|---|
| 218 | | - .name = "YUV 4:4:4 planar, Y/CbCr", |
|---|
| 219 | 202 | .fourcc = V4L2_PIX_FMT_NV24, |
|---|
| 220 | 203 | .depth = 24, |
|---|
| 221 | 204 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 228 | 211 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444, |
|---|
| 229 | 212 | }, |
|---|
| 230 | 213 | { |
|---|
| 231 | | - .name = "YUV 4:4:4 planar, Y/CrCb", |
|---|
| 232 | 214 | .fourcc = V4L2_PIX_FMT_NV42, |
|---|
| 233 | 215 | .depth = 24, |
|---|
| 234 | 216 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 241 | 223 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444, |
|---|
| 242 | 224 | }, |
|---|
| 243 | 225 | { |
|---|
| 244 | | - .name = "YUV 4:2:2 planar, Y/CrCb", |
|---|
| 245 | 226 | .fourcc = V4L2_PIX_FMT_NV61, |
|---|
| 246 | 227 | .depth = 16, |
|---|
| 247 | 228 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 254 | 235 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 255 | 236 | }, |
|---|
| 256 | 237 | { |
|---|
| 257 | | - .name = "YUV 4:2:2 planar, Y/CbCr", |
|---|
| 258 | 238 | .fourcc = V4L2_PIX_FMT_NV16, |
|---|
| 259 | 239 | .depth = 16, |
|---|
| 260 | 240 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 267 | 247 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422, |
|---|
| 268 | 248 | }, |
|---|
| 269 | 249 | { |
|---|
| 270 | | - .name = "YUV 4:2:0 planar, Y/CbCr", |
|---|
| 271 | 250 | .fourcc = V4L2_PIX_FMT_NV12, |
|---|
| 272 | 251 | .depth = 12, |
|---|
| 273 | 252 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 280 | 259 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420, |
|---|
| 281 | 260 | }, |
|---|
| 282 | 261 | { |
|---|
| 283 | | - .name = "YUV 4:2:0 planar, Y/CbCr", |
|---|
| 284 | 262 | .fourcc = V4L2_PIX_FMT_NV12, |
|---|
| 285 | 263 | .depth = 12, |
|---|
| 286 | 264 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 293 | 271 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420, |
|---|
| 294 | 272 | }, |
|---|
| 295 | 273 | { |
|---|
| 296 | | - .name = "YUV 4:2:0 planar, Y/CbCr", |
|---|
| 297 | 274 | .fourcc = V4L2_PIX_FMT_NV12, |
|---|
| 298 | 275 | .depth = 12, |
|---|
| 299 | 276 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 306 | 283 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420, |
|---|
| 307 | 284 | }, |
|---|
| 308 | 285 | { |
|---|
| 309 | | - .name = "YUV 4:2:0 planar, Y/CrCb", |
|---|
| 310 | 286 | .fourcc = V4L2_PIX_FMT_NV21, |
|---|
| 311 | 287 | .depth = 12, |
|---|
| 312 | 288 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 319 | 295 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420, |
|---|
| 320 | 296 | }, |
|---|
| 321 | 297 | { |
|---|
| 322 | | - .name = "YUV 4:2:0 planar, Y/CrCb", |
|---|
| 323 | 298 | .fourcc = V4L2_PIX_FMT_NV21, |
|---|
| 324 | 299 | .depth = 12, |
|---|
| 325 | 300 | .colplanes = 2, |
|---|
| .. | .. |
|---|
| 333 | 308 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420, |
|---|
| 334 | 309 | }, |
|---|
| 335 | 310 | { |
|---|
| 336 | | - .name = "YUV 4:2:0 contiguous 3-planar, Y/Cb/Cr", |
|---|
| 337 | 311 | .fourcc = V4L2_PIX_FMT_YUV420, |
|---|
| 338 | 312 | .depth = 12, |
|---|
| 339 | 313 | .colplanes = 3, |
|---|
| .. | .. |
|---|
| 346 | 320 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420, |
|---|
| 347 | 321 | }, |
|---|
| 348 | 322 | { |
|---|
| 349 | | - .name = "YUV 4:2:0 contiguous 3-planar, Y/Cb/Cr", |
|---|
| 350 | 323 | .fourcc = V4L2_PIX_FMT_YUV420, |
|---|
| 351 | 324 | .depth = 12, |
|---|
| 352 | 325 | .colplanes = 3, |
|---|
| .. | .. |
|---|
| 359 | 332 | .subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420, |
|---|
| 360 | 333 | }, |
|---|
| 361 | 334 | { |
|---|
| 362 | | - .name = "Gray", |
|---|
| 363 | 335 | .fourcc = V4L2_PIX_FMT_GREY, |
|---|
| 364 | 336 | .depth = 8, |
|---|
| 365 | 337 | .colplanes = 1, |
|---|
| .. | .. |
|---|
| 1265 | 1237 | } |
|---|
| 1266 | 1238 | result->sof = sof; |
|---|
| 1267 | 1239 | result->sof_len = sof_len; |
|---|
| 1268 | | - result->components = components; |
|---|
| 1269 | 1240 | |
|---|
| 1270 | 1241 | return true; |
|---|
| 1271 | 1242 | } |
|---|
| .. | .. |
|---|
| 1276 | 1247 | struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv); |
|---|
| 1277 | 1248 | |
|---|
| 1278 | 1249 | if (ctx->mode == S5P_JPEG_ENCODE) { |
|---|
| 1279 | | - strlcpy(cap->driver, S5P_JPEG_M2M_NAME, |
|---|
| 1250 | + strscpy(cap->driver, S5P_JPEG_M2M_NAME, |
|---|
| 1280 | 1251 | sizeof(cap->driver)); |
|---|
| 1281 | | - strlcpy(cap->card, S5P_JPEG_M2M_NAME " encoder", |
|---|
| 1252 | + strscpy(cap->card, S5P_JPEG_M2M_NAME " encoder", |
|---|
| 1282 | 1253 | sizeof(cap->card)); |
|---|
| 1283 | 1254 | } else { |
|---|
| 1284 | | - strlcpy(cap->driver, S5P_JPEG_M2M_NAME, |
|---|
| 1255 | + strscpy(cap->driver, S5P_JPEG_M2M_NAME, |
|---|
| 1285 | 1256 | sizeof(cap->driver)); |
|---|
| 1286 | | - strlcpy(cap->card, S5P_JPEG_M2M_NAME " decoder", |
|---|
| 1257 | + strscpy(cap->card, S5P_JPEG_M2M_NAME " decoder", |
|---|
| 1287 | 1258 | sizeof(cap->card)); |
|---|
| 1288 | 1259 | } |
|---|
| 1289 | 1260 | snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", |
|---|
| 1290 | 1261 | 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; |
|---|
| 1293 | 1262 | return 0; |
|---|
| 1294 | 1263 | } |
|---|
| 1295 | 1264 | |
|---|
| .. | .. |
|---|
| 1317 | 1286 | if (i >= n) |
|---|
| 1318 | 1287 | return -EINVAL; |
|---|
| 1319 | 1288 | |
|---|
| 1320 | | - strlcpy(f->description, sjpeg_formats[i].name, sizeof(f->description)); |
|---|
| 1321 | 1289 | f->pixelformat = sjpeg_formats[i].fourcc; |
|---|
| 1322 | 1290 | |
|---|
| 1323 | 1291 | return 0; |
|---|
| .. | .. |
|---|
| 1768 | 1736 | return 0; |
|---|
| 1769 | 1737 | } |
|---|
| 1770 | 1738 | |
|---|
| 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 | | - |
|---|
| 1784 | 1739 | static int exynos3250_jpeg_try_crop(struct s5p_jpeg_ctx *ctx, |
|---|
| 1785 | 1740 | struct v4l2_rect *r) |
|---|
| 1786 | 1741 | { |
|---|
| .. | .. |
|---|
| 1813 | 1768 | r->left = round_down(r->left, 2); |
|---|
| 1814 | 1769 | r->top = round_down(r->top, 2); |
|---|
| 1815 | 1770 | |
|---|
| 1816 | | - if (!enclosed_rectangle(r, &base_rect)) |
|---|
| 1771 | + if (!v4l2_rect_enclosed(r, &base_rect)) |
|---|
| 1817 | 1772 | return -EINVAL; |
|---|
| 1818 | 1773 | |
|---|
| 1819 | 1774 | ctx->crop_rect.left = r->left; |
|---|
| .. | .. |
|---|
| 2611 | 2566 | static int s5p_jpeg_start_streaming(struct vb2_queue *q, unsigned int count) |
|---|
| 2612 | 2567 | { |
|---|
| 2613 | 2568 | struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(q); |
|---|
| 2614 | | - int ret; |
|---|
| 2615 | 2569 | |
|---|
| 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); |
|---|
| 2619 | 2571 | } |
|---|
| 2620 | 2572 | |
|---|
| 2621 | 2573 | static void s5p_jpeg_stop_streaming(struct vb2_queue *q) |
|---|
| .. | .. |
|---|
| 2977 | 2929 | jpeg->vfd_encoder->lock = &jpeg->lock; |
|---|
| 2978 | 2930 | jpeg->vfd_encoder->v4l2_dev = &jpeg->v4l2_dev; |
|---|
| 2979 | 2931 | jpeg->vfd_encoder->vfl_dir = VFL_DIR_M2M; |
|---|
| 2932 | + jpeg->vfd_encoder->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M; |
|---|
| 2980 | 2933 | |
|---|
| 2981 | | - ret = video_register_device(jpeg->vfd_encoder, VFL_TYPE_GRABBER, -1); |
|---|
| 2934 | + ret = video_register_device(jpeg->vfd_encoder, VFL_TYPE_VIDEO, -1); |
|---|
| 2982 | 2935 | if (ret) { |
|---|
| 2983 | 2936 | v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n"); |
|---|
| 2984 | 2937 | video_device_release(jpeg->vfd_encoder); |
|---|
| .. | .. |
|---|
| 3006 | 2959 | jpeg->vfd_decoder->lock = &jpeg->lock; |
|---|
| 3007 | 2960 | jpeg->vfd_decoder->v4l2_dev = &jpeg->v4l2_dev; |
|---|
| 3008 | 2961 | jpeg->vfd_decoder->vfl_dir = VFL_DIR_M2M; |
|---|
| 2962 | + jpeg->vfd_decoder->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M; |
|---|
| 3009 | 2963 | |
|---|
| 3010 | | - ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_GRABBER, -1); |
|---|
| 2964 | + ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_VIDEO, -1); |
|---|
| 3011 | 2965 | if (ret) { |
|---|
| 3012 | 2966 | v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n"); |
|---|
| 3013 | 2967 | video_device_release(jpeg->vfd_decoder); |
|---|
| .. | .. |
|---|
| 3223 | 3177 | |
|---|
| 3224 | 3178 | module_platform_driver(s5p_jpeg_driver); |
|---|
| 3225 | 3179 | |
|---|
| 3226 | | -MODULE_AUTHOR("Andrzej Pietrasiewicz <andrzej.p@samsung.com>"); |
|---|
| 3180 | +MODULE_AUTHOR("Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>"); |
|---|
| 3227 | 3181 | MODULE_AUTHOR("Jacek Anaszewski <j.anaszewski@samsung.com>"); |
|---|
| 3228 | 3182 | MODULE_DESCRIPTION("Samsung JPEG codec driver"); |
|---|
| 3229 | 3183 | MODULE_LICENSE("GPL"); |
|---|