forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/media/platform/exynos4-is/fimc-lite.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Samsung EXYNOS FIMC-LITE (camera host interface) driver
34 *
45 * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
56 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118 #define pr_fmt(fmt) "%s:%d " fmt, __func__, __LINE__
129
....@@ -28,6 +25,7 @@
2825 #include <media/v4l2-device.h>
2926 #include <media/v4l2-ioctl.h>
3027 #include <media/v4l2-mem2mem.h>
28
+#include <media/v4l2-rect.h>
3129 #include <media/videobuf2-v4l2.h>
3230 #include <media/videobuf2-dma-contig.h>
3331 #include <media/drv-intf/exynos-fimc.h>
....@@ -42,7 +40,6 @@
4240
4341 static const struct fimc_fmt fimc_lite_formats[] = {
4442 {
45
- .name = "YUV 4:2:2 packed, YCbYCr",
4643 .fourcc = V4L2_PIX_FMT_YUYV,
4744 .colorspace = V4L2_COLORSPACE_JPEG,
4845 .depth = { 16 },
....@@ -51,7 +48,6 @@
5148 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
5249 .flags = FMT_FLAGS_YUV,
5350 }, {
54
- .name = "YUV 4:2:2 packed, CbYCrY",
5551 .fourcc = V4L2_PIX_FMT_UYVY,
5652 .colorspace = V4L2_COLORSPACE_JPEG,
5753 .depth = { 16 },
....@@ -60,7 +56,6 @@
6056 .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
6157 .flags = FMT_FLAGS_YUV,
6258 }, {
63
- .name = "YUV 4:2:2 packed, CrYCbY",
6459 .fourcc = V4L2_PIX_FMT_VYUY,
6560 .colorspace = V4L2_COLORSPACE_JPEG,
6661 .depth = { 16 },
....@@ -69,7 +64,6 @@
6964 .mbus_code = MEDIA_BUS_FMT_VYUY8_2X8,
7065 .flags = FMT_FLAGS_YUV,
7166 }, {
72
- .name = "YUV 4:2:2 packed, YCrYCb",
7367 .fourcc = V4L2_PIX_FMT_YVYU,
7468 .colorspace = V4L2_COLORSPACE_JPEG,
7569 .depth = { 16 },
....@@ -78,7 +72,6 @@
7872 .mbus_code = MEDIA_BUS_FMT_YVYU8_2X8,
7973 .flags = FMT_FLAGS_YUV,
8074 }, {
81
- .name = "RAW8 (GRBG)",
8275 .fourcc = V4L2_PIX_FMT_SGRBG8,
8376 .colorspace = V4L2_COLORSPACE_SRGB,
8477 .depth = { 8 },
....@@ -87,7 +80,6 @@
8780 .mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8,
8881 .flags = FMT_FLAGS_RAW_BAYER,
8982 }, {
90
- .name = "RAW10 (GRBG)",
9183 .fourcc = V4L2_PIX_FMT_SGRBG10,
9284 .colorspace = V4L2_COLORSPACE_SRGB,
9385 .depth = { 16 },
....@@ -96,7 +88,6 @@
9688 .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10,
9789 .flags = FMT_FLAGS_RAW_BAYER,
9890 }, {
99
- .name = "RAW12 (GRBG)",
10091 .fourcc = V4L2_PIX_FMT_SGRBG12,
10192 .colorspace = V4L2_COLORSPACE_SRGB,
10293 .depth = { 16 },
....@@ -478,9 +469,9 @@
478469 }
479470
480471 set_bit(ST_FLITE_IN_USE, &fimc->state);
481
- ret = pm_runtime_get_sync(&fimc->pdev->dev);
472
+ ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
482473 if (ret < 0)
483
- goto err_pm;
474
+ goto err_in_use;
484475
485476 ret = v4l2_fh_open(file);
486477 if (ret < 0)
....@@ -508,6 +499,7 @@
508499 v4l2_fh_release(file);
509500 err_pm:
510501 pm_runtime_put_sync(&fimc->pdev->dev);
502
+err_in_use:
511503 clear_bit(ST_FLITE_IN_USE, &fimc->state);
512504 unlock:
513505 mutex_unlock(&fimc->lock);
....@@ -654,18 +646,15 @@
654646 {
655647 struct fimc_lite *fimc = video_drvdata(file);
656648
657
- strlcpy(cap->driver, FIMC_LITE_DRV_NAME, sizeof(cap->driver));
658
- strlcpy(cap->card, FIMC_LITE_DRV_NAME, sizeof(cap->card));
649
+ strscpy(cap->driver, FIMC_LITE_DRV_NAME, sizeof(cap->driver));
650
+ strscpy(cap->card, FIMC_LITE_DRV_NAME, sizeof(cap->card));
659651 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
660652 dev_name(&fimc->pdev->dev));
661
-
662
- cap->device_caps = V4L2_CAP_STREAMING;
663
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
664653 return 0;
665654 }
666655
667
-static int fimc_lite_enum_fmt_mplane(struct file *file, void *priv,
668
- struct v4l2_fmtdesc *f)
656
+static int fimc_lite_enum_fmt(struct file *file, void *priv,
657
+ struct v4l2_fmtdesc *f)
669658 {
670659 const struct fimc_fmt *fmt;
671660
....@@ -673,7 +662,6 @@
673662 return -EINVAL;
674663
675664 fmt = &fimc_lite_formats[f->index];
676
- strlcpy(f->description, fmt->name, sizeof(f->description));
677665 f->pixelformat = fmt->fourcc;
678666
679667 return 0;
....@@ -882,19 +870,6 @@
882870 return ret;
883871 }
884872
885
-/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
886
-static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
887
-{
888
- if (a->left < b->left || a->top < b->top)
889
- return 0;
890
- if (a->left + a->width > b->left + b->width)
891
- return 0;
892
- if (a->top + a->height > b->top + b->height)
893
- return 0;
894
-
895
- return 1;
896
-}
897
-
898873 static int fimc_lite_g_selection(struct file *file, void *fh,
899874 struct v4l2_selection *sel)
900875 {
....@@ -936,11 +911,11 @@
936911 fimc_lite_try_compose(fimc, &rect);
937912
938913 if ((sel->flags & V4L2_SEL_FLAG_LE) &&
939
- !enclosed_rectangle(&rect, &sel->r))
914
+ !v4l2_rect_enclosed(&rect, &sel->r))
940915 return -ERANGE;
941916
942917 if ((sel->flags & V4L2_SEL_FLAG_GE) &&
943
- !enclosed_rectangle(&sel->r, &rect))
918
+ !v4l2_rect_enclosed(&sel->r, &rect))
944919 return -ERANGE;
945920
946921 sel->r = rect;
....@@ -954,7 +929,7 @@
954929
955930 static const struct v4l2_ioctl_ops fimc_lite_ioctl_ops = {
956931 .vidioc_querycap = fimc_lite_querycap,
957
- .vidioc_enum_fmt_vid_cap_mplane = fimc_lite_enum_fmt_mplane,
932
+ .vidioc_enum_fmt_vid_cap = fimc_lite_enum_fmt,
958933 .vidioc_try_fmt_vid_cap_mplane = fimc_lite_try_fmt_mplane,
959934 .vidioc_s_fmt_vid_cap_mplane = fimc_lite_s_fmt_mplane,
960935 .vidioc_g_fmt_vid_cap_mplane = fimc_lite_g_fmt_mplane,
....@@ -1282,6 +1257,7 @@
12821257 vfd->minor = -1;
12831258 vfd->release = video_device_release_empty;
12841259 vfd->queue = q;
1260
+ vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_STREAMING;
12851261 fimc->reqbufs_count = 0;
12861262
12871263 INIT_LIST_HEAD(&fimc->pending_buf_q);
....@@ -1310,7 +1286,7 @@
13101286 video_set_drvdata(vfd, fimc);
13111287 fimc->ve.pipe = v4l2_get_subdev_hostdata(sd);
13121288
1313
- ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
1289
+ ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
13141290 if (ret < 0) {
13151291 media_entity_cleanup(&vfd->entity);
13161292 fimc->ve.pipe = NULL;
....@@ -1627,6 +1603,9 @@
16271603 struct fimc_lite *fimc = platform_get_drvdata(pdev);
16281604 struct device *dev = &pdev->dev;
16291605
1606
+ if (!pm_runtime_enabled(dev))
1607
+ clk_disable_unprepare(fimc->clock);
1608
+
16301609 pm_runtime_disable(dev);
16311610 pm_runtime_set_suspended(dev);
16321611 fimc_lite_unregister_capture_subdev(fimc);