usb: uvc: move uvc_fmts and uvc_format_by_guid to own compile unit
The media driver USB_VIDEO_CLASS and USB_F_UVC are using the same function uvc_format_by_guid. Since the function is inline, every user will get a copy of the used uvc_fmts array and the function. This patch moves the code to an own compile unit and add this dependency as UVC_COMMON to both users. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com> Tested-by: Daniel Scally <dan.scally@ideasonboard.com> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Link: https://lore.kernel.org/r/20230126231456.3402323-4-m.grzeschik@pengutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Родитель
e1d5d71d18
Коммит
466be4c9a6
|
@ -14,6 +14,9 @@ config TTPCI_EEPROM
|
|||
tristate
|
||||
depends on I2C
|
||||
|
||||
config UVC_COMMON
|
||||
tristate
|
||||
|
||||
config VIDEO_CX2341X
|
||||
tristate
|
||||
|
||||
|
|
|
@ -5,5 +5,6 @@ obj-y += b2c2/ siano/ v4l2-tpg/ videobuf2/
|
|||
# (e. g. LC_ALL=C sort Makefile)
|
||||
obj-$(CONFIG_CYPRESS_FIRMWARE) += cypress_firmware.o
|
||||
obj-$(CONFIG_TTPCI_EEPROM) += ttpci-eeprom.o
|
||||
obj-$(CONFIG_UVC_COMMON) += uvc.o
|
||||
obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
|
||||
obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
|
||||
|
|
|
@ -0,0 +1,221 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/usb/uvc.h>
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Video formats
|
||||
*/
|
||||
|
||||
static struct uvc_format_desc uvc_fmts[] = {
|
||||
{
|
||||
.name = "YUV 4:2:2 (YUYV)",
|
||||
.guid = UVC_GUID_FORMAT_YUY2,
|
||||
.fcc = V4L2_PIX_FMT_YUYV,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:2 (YUYV)",
|
||||
.guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
|
||||
.fcc = V4L2_PIX_FMT_YUYV,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:0 (NV12)",
|
||||
.guid = UVC_GUID_FORMAT_NV12,
|
||||
.fcc = V4L2_PIX_FMT_NV12,
|
||||
},
|
||||
{
|
||||
.name = "MJPEG",
|
||||
.guid = UVC_GUID_FORMAT_MJPEG,
|
||||
.fcc = V4L2_PIX_FMT_MJPEG,
|
||||
},
|
||||
{
|
||||
.name = "YVU 4:2:0 (YV12)",
|
||||
.guid = UVC_GUID_FORMAT_YV12,
|
||||
.fcc = V4L2_PIX_FMT_YVU420,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:0 (I420)",
|
||||
.guid = UVC_GUID_FORMAT_I420,
|
||||
.fcc = V4L2_PIX_FMT_YUV420,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:0 (M420)",
|
||||
.guid = UVC_GUID_FORMAT_M420,
|
||||
.fcc = V4L2_PIX_FMT_M420,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:2 (UYVY)",
|
||||
.guid = UVC_GUID_FORMAT_UYVY,
|
||||
.fcc = V4L2_PIX_FMT_UYVY,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 8-bit (Y800)",
|
||||
.guid = UVC_GUID_FORMAT_Y800,
|
||||
.fcc = V4L2_PIX_FMT_GREY,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 8-bit (Y8 )",
|
||||
.guid = UVC_GUID_FORMAT_Y8,
|
||||
.fcc = V4L2_PIX_FMT_GREY,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 8-bit (D3DFMT_L8)",
|
||||
.guid = UVC_GUID_FORMAT_D3DFMT_L8,
|
||||
.fcc = V4L2_PIX_FMT_GREY,
|
||||
},
|
||||
{
|
||||
.name = "IR 8-bit (L8_IR)",
|
||||
.guid = UVC_GUID_FORMAT_KSMEDIA_L8_IR,
|
||||
.fcc = V4L2_PIX_FMT_GREY,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 10-bit (Y10 )",
|
||||
.guid = UVC_GUID_FORMAT_Y10,
|
||||
.fcc = V4L2_PIX_FMT_Y10,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 12-bit (Y12 )",
|
||||
.guid = UVC_GUID_FORMAT_Y12,
|
||||
.fcc = V4L2_PIX_FMT_Y12,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 16-bit (Y16 )",
|
||||
.guid = UVC_GUID_FORMAT_Y16,
|
||||
.fcc = V4L2_PIX_FMT_Y16,
|
||||
},
|
||||
{
|
||||
.name = "BGGR Bayer (BY8 )",
|
||||
.guid = UVC_GUID_FORMAT_BY8,
|
||||
.fcc = V4L2_PIX_FMT_SBGGR8,
|
||||
},
|
||||
{
|
||||
.name = "BGGR Bayer (BA81)",
|
||||
.guid = UVC_GUID_FORMAT_BA81,
|
||||
.fcc = V4L2_PIX_FMT_SBGGR8,
|
||||
},
|
||||
{
|
||||
.name = "GBRG Bayer (GBRG)",
|
||||
.guid = UVC_GUID_FORMAT_GBRG,
|
||||
.fcc = V4L2_PIX_FMT_SGBRG8,
|
||||
},
|
||||
{
|
||||
.name = "GRBG Bayer (GRBG)",
|
||||
.guid = UVC_GUID_FORMAT_GRBG,
|
||||
.fcc = V4L2_PIX_FMT_SGRBG8,
|
||||
},
|
||||
{
|
||||
.name = "RGGB Bayer (RGGB)",
|
||||
.guid = UVC_GUID_FORMAT_RGGB,
|
||||
.fcc = V4L2_PIX_FMT_SRGGB8,
|
||||
},
|
||||
{
|
||||
.name = "RGB565",
|
||||
.guid = UVC_GUID_FORMAT_RGBP,
|
||||
.fcc = V4L2_PIX_FMT_RGB565,
|
||||
},
|
||||
{
|
||||
.name = "BGR 8:8:8 (BGR3)",
|
||||
.guid = UVC_GUID_FORMAT_BGR3,
|
||||
.fcc = V4L2_PIX_FMT_BGR24,
|
||||
},
|
||||
{
|
||||
.name = "BGRA/X 8:8:8:8 (BGR4)",
|
||||
.guid = UVC_GUID_FORMAT_BGR4,
|
||||
.fcc = V4L2_PIX_FMT_XBGR32,
|
||||
},
|
||||
{
|
||||
.name = "H.264",
|
||||
.guid = UVC_GUID_FORMAT_H264,
|
||||
.fcc = V4L2_PIX_FMT_H264,
|
||||
},
|
||||
{
|
||||
.name = "H.265",
|
||||
.guid = UVC_GUID_FORMAT_H265,
|
||||
.fcc = V4L2_PIX_FMT_HEVC,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 8 L/R (Y8I)",
|
||||
.guid = UVC_GUID_FORMAT_Y8I,
|
||||
.fcc = V4L2_PIX_FMT_Y8I,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 12 L/R (Y12I)",
|
||||
.guid = UVC_GUID_FORMAT_Y12I,
|
||||
.fcc = V4L2_PIX_FMT_Y12I,
|
||||
},
|
||||
{
|
||||
.name = "Depth data 16-bit (Z16)",
|
||||
.guid = UVC_GUID_FORMAT_Z16,
|
||||
.fcc = V4L2_PIX_FMT_Z16,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 10-bit (SRGGB10P)",
|
||||
.guid = UVC_GUID_FORMAT_RW10,
|
||||
.fcc = V4L2_PIX_FMT_SRGGB10P,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 16-bit (SBGGR16)",
|
||||
.guid = UVC_GUID_FORMAT_BG16,
|
||||
.fcc = V4L2_PIX_FMT_SBGGR16,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 16-bit (SGBRG16)",
|
||||
.guid = UVC_GUID_FORMAT_GB16,
|
||||
.fcc = V4L2_PIX_FMT_SGBRG16,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 16-bit (SRGGB16)",
|
||||
.guid = UVC_GUID_FORMAT_RG16,
|
||||
.fcc = V4L2_PIX_FMT_SRGGB16,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 16-bit (SGRBG16)",
|
||||
.guid = UVC_GUID_FORMAT_GR16,
|
||||
.fcc = V4L2_PIX_FMT_SGRBG16,
|
||||
},
|
||||
{
|
||||
.name = "Depth data 16-bit (Z16)",
|
||||
.guid = UVC_GUID_FORMAT_INVZ,
|
||||
.fcc = V4L2_PIX_FMT_Z16,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 10-bit (Y10 )",
|
||||
.guid = UVC_GUID_FORMAT_INVI,
|
||||
.fcc = V4L2_PIX_FMT_Y10,
|
||||
},
|
||||
{
|
||||
.name = "IR:Depth 26-bit (INZI)",
|
||||
.guid = UVC_GUID_FORMAT_INZI,
|
||||
.fcc = V4L2_PIX_FMT_INZI,
|
||||
},
|
||||
{
|
||||
.name = "4-bit Depth Confidence (Packed)",
|
||||
.guid = UVC_GUID_FORMAT_CNF4,
|
||||
.fcc = V4L2_PIX_FMT_CNF4,
|
||||
},
|
||||
{
|
||||
.name = "HEVC",
|
||||
.guid = UVC_GUID_FORMAT_HEVC,
|
||||
.fcc = V4L2_PIX_FMT_HEVC,
|
||||
},
|
||||
};
|
||||
|
||||
struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16])
|
||||
{
|
||||
unsigned int len = ARRAY_SIZE(uvc_fmts);
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
|
||||
return &uvc_fmts[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(uvc_format_by_guid);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
|
@ -3,6 +3,7 @@ config USB_VIDEO_CLASS
|
|||
tristate "USB Video Class (UVC)"
|
||||
depends on VIDEO_DEV
|
||||
select VIDEOBUF2_VMALLOC
|
||||
select UVC_COMMON
|
||||
help
|
||||
Support for the USB Video Class (UVC). Currently only video
|
||||
input devices, such as webcams, are supported.
|
||||
|
|
|
@ -203,6 +203,7 @@ config USB_F_UAC2
|
|||
|
||||
config USB_F_UVC
|
||||
tristate
|
||||
select UVC_COMMON
|
||||
|
||||
config USB_F_MIDI
|
||||
tristate
|
||||
|
|
|
@ -148,220 +148,12 @@
|
|||
{ 'H', 'E', 'V', 'C', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Video formats
|
||||
*/
|
||||
|
||||
struct uvc_format_desc {
|
||||
char *name;
|
||||
u8 guid[16];
|
||||
u32 fcc;
|
||||
};
|
||||
|
||||
static struct uvc_format_desc uvc_fmts[] = {
|
||||
{
|
||||
.name = "YUV 4:2:2 (YUYV)",
|
||||
.guid = UVC_GUID_FORMAT_YUY2,
|
||||
.fcc = V4L2_PIX_FMT_YUYV,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:2 (YUYV)",
|
||||
.guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
|
||||
.fcc = V4L2_PIX_FMT_YUYV,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:0 (NV12)",
|
||||
.guid = UVC_GUID_FORMAT_NV12,
|
||||
.fcc = V4L2_PIX_FMT_NV12,
|
||||
},
|
||||
{
|
||||
.name = "MJPEG",
|
||||
.guid = UVC_GUID_FORMAT_MJPEG,
|
||||
.fcc = V4L2_PIX_FMT_MJPEG,
|
||||
},
|
||||
{
|
||||
.name = "YVU 4:2:0 (YV12)",
|
||||
.guid = UVC_GUID_FORMAT_YV12,
|
||||
.fcc = V4L2_PIX_FMT_YVU420,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:0 (I420)",
|
||||
.guid = UVC_GUID_FORMAT_I420,
|
||||
.fcc = V4L2_PIX_FMT_YUV420,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:0 (M420)",
|
||||
.guid = UVC_GUID_FORMAT_M420,
|
||||
.fcc = V4L2_PIX_FMT_M420,
|
||||
},
|
||||
{
|
||||
.name = "YUV 4:2:2 (UYVY)",
|
||||
.guid = UVC_GUID_FORMAT_UYVY,
|
||||
.fcc = V4L2_PIX_FMT_UYVY,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 8-bit (Y800)",
|
||||
.guid = UVC_GUID_FORMAT_Y800,
|
||||
.fcc = V4L2_PIX_FMT_GREY,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 8-bit (Y8 )",
|
||||
.guid = UVC_GUID_FORMAT_Y8,
|
||||
.fcc = V4L2_PIX_FMT_GREY,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 8-bit (D3DFMT_L8)",
|
||||
.guid = UVC_GUID_FORMAT_D3DFMT_L8,
|
||||
.fcc = V4L2_PIX_FMT_GREY,
|
||||
},
|
||||
{
|
||||
.name = "IR 8-bit (L8_IR)",
|
||||
.guid = UVC_GUID_FORMAT_KSMEDIA_L8_IR,
|
||||
.fcc = V4L2_PIX_FMT_GREY,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 10-bit (Y10 )",
|
||||
.guid = UVC_GUID_FORMAT_Y10,
|
||||
.fcc = V4L2_PIX_FMT_Y10,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 12-bit (Y12 )",
|
||||
.guid = UVC_GUID_FORMAT_Y12,
|
||||
.fcc = V4L2_PIX_FMT_Y12,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 16-bit (Y16 )",
|
||||
.guid = UVC_GUID_FORMAT_Y16,
|
||||
.fcc = V4L2_PIX_FMT_Y16,
|
||||
},
|
||||
{
|
||||
.name = "BGGR Bayer (BY8 )",
|
||||
.guid = UVC_GUID_FORMAT_BY8,
|
||||
.fcc = V4L2_PIX_FMT_SBGGR8,
|
||||
},
|
||||
{
|
||||
.name = "BGGR Bayer (BA81)",
|
||||
.guid = UVC_GUID_FORMAT_BA81,
|
||||
.fcc = V4L2_PIX_FMT_SBGGR8,
|
||||
},
|
||||
{
|
||||
.name = "GBRG Bayer (GBRG)",
|
||||
.guid = UVC_GUID_FORMAT_GBRG,
|
||||
.fcc = V4L2_PIX_FMT_SGBRG8,
|
||||
},
|
||||
{
|
||||
.name = "GRBG Bayer (GRBG)",
|
||||
.guid = UVC_GUID_FORMAT_GRBG,
|
||||
.fcc = V4L2_PIX_FMT_SGRBG8,
|
||||
},
|
||||
{
|
||||
.name = "RGGB Bayer (RGGB)",
|
||||
.guid = UVC_GUID_FORMAT_RGGB,
|
||||
.fcc = V4L2_PIX_FMT_SRGGB8,
|
||||
},
|
||||
{
|
||||
.name = "RGB565",
|
||||
.guid = UVC_GUID_FORMAT_RGBP,
|
||||
.fcc = V4L2_PIX_FMT_RGB565,
|
||||
},
|
||||
{
|
||||
.name = "BGR 8:8:8 (BGR3)",
|
||||
.guid = UVC_GUID_FORMAT_BGR3,
|
||||
.fcc = V4L2_PIX_FMT_BGR24,
|
||||
},
|
||||
{
|
||||
.name = "BGRA/X 8:8:8:8 (BGR4)",
|
||||
.guid = UVC_GUID_FORMAT_BGR4,
|
||||
.fcc = V4L2_PIX_FMT_XBGR32,
|
||||
},
|
||||
{
|
||||
.name = "H.264",
|
||||
.guid = UVC_GUID_FORMAT_H264,
|
||||
.fcc = V4L2_PIX_FMT_H264,
|
||||
},
|
||||
{
|
||||
.name = "H.265",
|
||||
.guid = UVC_GUID_FORMAT_H265,
|
||||
.fcc = V4L2_PIX_FMT_HEVC,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 8 L/R (Y8I)",
|
||||
.guid = UVC_GUID_FORMAT_Y8I,
|
||||
.fcc = V4L2_PIX_FMT_Y8I,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 12 L/R (Y12I)",
|
||||
.guid = UVC_GUID_FORMAT_Y12I,
|
||||
.fcc = V4L2_PIX_FMT_Y12I,
|
||||
},
|
||||
{
|
||||
.name = "Depth data 16-bit (Z16)",
|
||||
.guid = UVC_GUID_FORMAT_Z16,
|
||||
.fcc = V4L2_PIX_FMT_Z16,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 10-bit (SRGGB10P)",
|
||||
.guid = UVC_GUID_FORMAT_RW10,
|
||||
.fcc = V4L2_PIX_FMT_SRGGB10P,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 16-bit (SBGGR16)",
|
||||
.guid = UVC_GUID_FORMAT_BG16,
|
||||
.fcc = V4L2_PIX_FMT_SBGGR16,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 16-bit (SGBRG16)",
|
||||
.guid = UVC_GUID_FORMAT_GB16,
|
||||
.fcc = V4L2_PIX_FMT_SGBRG16,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 16-bit (SRGGB16)",
|
||||
.guid = UVC_GUID_FORMAT_RG16,
|
||||
.fcc = V4L2_PIX_FMT_SRGGB16,
|
||||
},
|
||||
{
|
||||
.name = "Bayer 16-bit (SGRBG16)",
|
||||
.guid = UVC_GUID_FORMAT_GR16,
|
||||
.fcc = V4L2_PIX_FMT_SGRBG16,
|
||||
},
|
||||
{
|
||||
.name = "Depth data 16-bit (Z16)",
|
||||
.guid = UVC_GUID_FORMAT_INVZ,
|
||||
.fcc = V4L2_PIX_FMT_Z16,
|
||||
},
|
||||
{
|
||||
.name = "Greyscale 10-bit (Y10 )",
|
||||
.guid = UVC_GUID_FORMAT_INVI,
|
||||
.fcc = V4L2_PIX_FMT_Y10,
|
||||
},
|
||||
{
|
||||
.name = "IR:Depth 26-bit (INZI)",
|
||||
.guid = UVC_GUID_FORMAT_INZI,
|
||||
.fcc = V4L2_PIX_FMT_INZI,
|
||||
},
|
||||
{
|
||||
.name = "4-bit Depth Confidence (Packed)",
|
||||
.guid = UVC_GUID_FORMAT_CNF4,
|
||||
.fcc = V4L2_PIX_FMT_CNF4,
|
||||
},
|
||||
{
|
||||
.name = "HEVC",
|
||||
.guid = UVC_GUID_FORMAT_HEVC,
|
||||
.fcc = V4L2_PIX_FMT_HEVC,
|
||||
},
|
||||
};
|
||||
|
||||
static inline struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16])
|
||||
{
|
||||
unsigned int len = ARRAY_SIZE(uvc_fmts);
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
|
||||
return &uvc_fmts[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16]);
|
||||
|
||||
#endif /* __LINUX_V4L2_UVC_H */
|
||||
|
|
Загрузка…
Ссылка в новой задаче