forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/media/usb/gspca/gspca.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Main USB camera driver
34 *
....@@ -5,16 +6,6 @@
56 *
67 * Camera button input handling by Márton Németh
78 * Copyright (C) 2009-2010 Márton Németh <nm127@freemail.hu>
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License as published by the
11
- * Free Software Foundation; either version 2 of the License, or (at your
12
- * option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful, but
15
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17
- * for more details.
189 */
1910
2011 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -916,23 +907,30 @@
916907 }
917908
918909 static int wxh_to_mode(struct gspca_dev *gspca_dev,
919
- int width, int height)
910
+ int width, int height, u32 pixelformat)
920911 {
921912 int i;
922913
923914 for (i = 0; i < gspca_dev->cam.nmodes; i++) {
924915 if (width == gspca_dev->cam.cam_mode[i].width
925
- && height == gspca_dev->cam.cam_mode[i].height)
916
+ && height == gspca_dev->cam.cam_mode[i].height
917
+ && pixelformat == gspca_dev->cam.cam_mode[i].pixelformat)
926918 return i;
927919 }
928920 return -EINVAL;
929921 }
930922
931923 static int wxh_to_nearest_mode(struct gspca_dev *gspca_dev,
932
- int width, int height)
924
+ int width, int height, u32 pixelformat)
933925 {
934926 int i;
935927
928
+ for (i = gspca_dev->cam.nmodes; --i >= 0; ) {
929
+ if (width >= gspca_dev->cam.cam_mode[i].width
930
+ && height >= gspca_dev->cam.cam_mode[i].height
931
+ && pixelformat == gspca_dev->cam.cam_mode[i].pixelformat)
932
+ return i;
933
+ }
936934 for (i = gspca_dev->cam.nmodes; --i > 0; ) {
937935 if (width >= gspca_dev->cam.cam_mode[i].width
938936 && height >= gspca_dev->cam.cam_mode[i].height)
....@@ -1026,27 +1024,18 @@
10261024 return -EINVAL; /* no more format */
10271025
10281026 fmtdesc->pixelformat = fmt_tb[index];
1029
- if (gspca_dev->cam.cam_mode[i].sizeimage <
1030
- gspca_dev->cam.cam_mode[i].width *
1031
- gspca_dev->cam.cam_mode[i].height)
1032
- fmtdesc->flags = V4L2_FMT_FLAG_COMPRESSED;
1033
- fmtdesc->description[0] = fmtdesc->pixelformat & 0xff;
1034
- fmtdesc->description[1] = (fmtdesc->pixelformat >> 8) & 0xff;
1035
- fmtdesc->description[2] = (fmtdesc->pixelformat >> 16) & 0xff;
1036
- fmtdesc->description[3] = fmtdesc->pixelformat >> 24;
1037
- fmtdesc->description[4] = '\0';
10381027 return 0;
10391028 }
10401029
1041
-static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1042
- struct v4l2_format *fmt)
1030
+static int vidioc_g_fmt_vid_cap(struct file *file, void *_priv,
1031
+ struct v4l2_format *fmt)
10431032 {
10441033 struct gspca_dev *gspca_dev = video_drvdata(file);
1034
+ u32 priv = fmt->fmt.pix.priv;
10451035
10461036 fmt->fmt.pix = gspca_dev->pixfmt;
1047
- /* some drivers use priv internally, zero it before giving it back to
1048
- the core */
1049
- fmt->fmt.pix.priv = 0;
1037
+ /* some drivers use priv internally, so keep the original value */
1038
+ fmt->fmt.pix.priv = priv;
10501039 return 0;
10511040 }
10521041
....@@ -1062,7 +1051,7 @@
10621051 fmt->fmt.pix.pixelformat, w, h);
10631052
10641053 /* search the nearest mode for width and height */
1065
- mode = wxh_to_nearest_mode(gspca_dev, w, h);
1054
+ mode = wxh_to_nearest_mode(gspca_dev, w, h, fmt->fmt.pix.pixelformat);
10661055
10671056 /* OK if right palette */
10681057 if (gspca_dev->cam.cam_mode[mode].pixelformat
....@@ -1081,27 +1070,27 @@
10811070 fmt->fmt.pix.height = h;
10821071 gspca_dev->sd_desc->try_fmt(gspca_dev, fmt);
10831072 }
1084
- /* some drivers use priv internally, zero it before giving it back to
1085
- the core */
1086
- fmt->fmt.pix.priv = 0;
10871073 return mode; /* used when s_fmt */
10881074 }
10891075
1090
-static int vidioc_try_fmt_vid_cap(struct file *file,
1091
- void *priv,
1092
- struct v4l2_format *fmt)
1076
+static int vidioc_try_fmt_vid_cap(struct file *file, void *_priv,
1077
+ struct v4l2_format *fmt)
10931078 {
10941079 struct gspca_dev *gspca_dev = video_drvdata(file);
1080
+ u32 priv = fmt->fmt.pix.priv;
10951081
10961082 if (try_fmt_vid_cap(gspca_dev, fmt) < 0)
10971083 return -EINVAL;
1084
+ /* some drivers use priv internally, so keep the original value */
1085
+ fmt->fmt.pix.priv = priv;
10981086 return 0;
10991087 }
11001088
1101
-static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1102
- struct v4l2_format *fmt)
1089
+static int vidioc_s_fmt_vid_cap(struct file *file, void *_priv,
1090
+ struct v4l2_format *fmt)
11031091 {
11041092 struct gspca_dev *gspca_dev = video_drvdata(file);
1093
+ u32 priv = fmt->fmt.pix.priv;
11051094 int mode;
11061095
11071096 if (vb2_is_busy(&gspca_dev->queue))
....@@ -1117,6 +1106,8 @@
11171106 gspca_dev->pixfmt = fmt->fmt.pix;
11181107 else
11191108 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[mode];
1109
+ /* some drivers use priv internally, so keep the original value */
1110
+ fmt->fmt.pix.priv = priv;
11201111 return 0;
11211112 }
11221113
....@@ -1156,7 +1147,8 @@
11561147 int mode;
11571148 __u32 i;
11581149
1159
- mode = wxh_to_mode(gspca_dev, fival->width, fival->height);
1150
+ mode = wxh_to_mode(gspca_dev, fival->width, fival->height,
1151
+ fival->pixel_format);
11601152 if (mode < 0)
11611153 return -EINVAL;
11621154
....@@ -1197,11 +1189,11 @@
11971189 {
11981190 struct gspca_dev *gspca_dev = video_drvdata(file);
11991191
1200
- strlcpy((char *) cap->driver, gspca_dev->sd_desc->name,
1201
- sizeof cap->driver);
1192
+ strscpy((char *)cap->driver, gspca_dev->sd_desc->name,
1193
+ sizeof(cap->driver));
12021194 if (gspca_dev->dev->product != NULL) {
1203
- strlcpy((char *) cap->card, gspca_dev->dev->product,
1204
- sizeof cap->card);
1195
+ strscpy((char *)cap->card, gspca_dev->dev->product,
1196
+ sizeof(cap->card));
12051197 } else {
12061198 snprintf((char *) cap->card, sizeof cap->card,
12071199 "USB Camera (%04x:%04x)",
....@@ -1210,10 +1202,6 @@
12101202 }
12111203 usb_make_path(gspca_dev->dev, (char *) cap->bus_info,
12121204 sizeof(cap->bus_info));
1213
- cap->device_caps = V4L2_CAP_VIDEO_CAPTURE
1214
- | V4L2_CAP_STREAMING
1215
- | V4L2_CAP_READWRITE;
1216
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
12171205 return 0;
12181206 }
12191207
....@@ -1226,7 +1214,7 @@
12261214 return -EINVAL;
12271215 input->type = V4L2_INPUT_TYPE_CAMERA;
12281216 input->status = gspca_dev->cam.input_flags;
1229
- strlcpy(input->name, gspca_dev->sd_desc->name,
1217
+ strscpy(input->name, gspca_dev->sd_desc->name,
12301218 sizeof input->name);
12311219 return 0;
12321220 }
....@@ -1509,6 +1497,8 @@
15091497 gspca_dev->empty_packet = -1; /* don't check the empty packets */
15101498 gspca_dev->vdev = gspca_template;
15111499 gspca_dev->vdev.v4l2_dev = &gspca_dev->v4l2_dev;
1500
+ gspca_dev->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE |
1501
+ V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
15121502 video_set_drvdata(&gspca_dev->vdev, gspca_dev);
15131503 gspca_dev->module = module;
15141504
....@@ -1565,7 +1555,7 @@
15651555
15661556 /* init video stuff */
15671557 ret = video_register_device(&gspca_dev->vdev,
1568
- VFL_TYPE_GRABBER,
1558
+ VFL_TYPE_VIDEO,
15691559 -1);
15701560 if (ret < 0) {
15711561 pr_err("video_register_device err %d\n", ret);