2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-01-21 16:39:52 +08:00
|
|
|
/*
|
|
|
|
* uvc_entity.c -- USB Video Class driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2011
|
|
|
|
* Laurent Pinchart (laurent.pinchart@ideasonboard.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
|
|
|
|
#include <media/v4l2-common.h>
|
|
|
|
|
|
|
|
#include "uvcvideo.h"
|
|
|
|
|
2015-12-12 01:16:34 +08:00
|
|
|
static int uvc_mc_create_links(struct uvc_video_chain *chain,
|
2015-09-03 19:46:06 +08:00
|
|
|
struct uvc_entity *entity)
|
2010-01-21 16:39:52 +08:00
|
|
|
{
|
|
|
|
const u32 flags = MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE;
|
2011-06-29 05:17:48 +08:00
|
|
|
struct media_entity *sink;
|
2010-01-21 16:39:52 +08:00
|
|
|
unsigned int i;
|
2011-06-29 05:17:48 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
sink = (UVC_ENTITY_TYPE(entity) == UVC_TT_STREAMING)
|
|
|
|
? (entity->vdev ? &entity->vdev->entity : NULL)
|
|
|
|
: &entity->subdev.entity;
|
|
|
|
if (sink == NULL)
|
|
|
|
return 0;
|
2010-01-21 16:39:52 +08:00
|
|
|
|
|
|
|
for (i = 0; i < entity->num_pads; ++i) {
|
2010-01-21 19:56:19 +08:00
|
|
|
struct media_entity *source;
|
2011-06-29 05:17:48 +08:00
|
|
|
struct uvc_entity *remote;
|
|
|
|
u8 remote_pad;
|
2010-01-21 19:56:19 +08:00
|
|
|
|
2010-01-21 16:39:52 +08:00
|
|
|
if (!(entity->pads[i].flags & MEDIA_PAD_FL_SINK))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
|
|
|
|
if (remote == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-09-07 06:16:18 +08:00
|
|
|
source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
|
2011-06-29 05:17:48 +08:00
|
|
|
? (remote->vdev ? &remote->vdev->entity : NULL)
|
|
|
|
: &remote->subdev.entity;
|
|
|
|
if (source == NULL)
|
|
|
|
continue;
|
2010-01-21 19:56:19 +08:00
|
|
|
|
2010-01-21 16:39:52 +08:00
|
|
|
remote_pad = remote->num_pads - 1;
|
2015-08-07 19:14:38 +08:00
|
|
|
ret = media_create_pad_link(source, remote_pad,
|
2010-01-21 19:56:19 +08:00
|
|
|
sink, i, flags);
|
2010-01-21 16:39:52 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-03 19:46:06 +08:00
|
|
|
return 0;
|
2010-01-21 16:39:52 +08:00
|
|
|
}
|
|
|
|
|
2017-08-08 20:56:24 +08:00
|
|
|
static const struct v4l2_subdev_ops uvc_subdev_ops = {
|
2010-01-21 16:39:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void uvc_mc_cleanup_entity(struct uvc_entity *entity)
|
|
|
|
{
|
2010-01-21 19:56:19 +08:00
|
|
|
if (UVC_ENTITY_TYPE(entity) != UVC_TT_STREAMING)
|
|
|
|
media_entity_cleanup(&entity->subdev.entity);
|
|
|
|
else if (entity->vdev != NULL)
|
|
|
|
media_entity_cleanup(&entity->vdev->entity);
|
2010-01-21 16:39:52 +08:00
|
|
|
}
|
|
|
|
|
2015-12-12 01:16:35 +08:00
|
|
|
static int uvc_mc_init_entity(struct uvc_video_chain *chain,
|
|
|
|
struct uvc_entity *entity)
|
2010-01-21 16:39:52 +08:00
|
|
|
{
|
2010-01-21 19:56:19 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (UVC_ENTITY_TYPE(entity) != UVC_TT_STREAMING) {
|
2020-06-07 10:05:49 +08:00
|
|
|
u32 function;
|
|
|
|
|
2010-01-21 19:56:19 +08:00
|
|
|
v4l2_subdev_init(&entity->subdev, &uvc_subdev_ops);
|
2018-09-10 20:19:14 +08:00
|
|
|
strscpy(entity->subdev.name, entity->name,
|
2010-01-21 19:56:19 +08:00
|
|
|
sizeof(entity->subdev.name));
|
|
|
|
|
2020-06-07 10:05:49 +08:00
|
|
|
switch (UVC_ENTITY_TYPE(entity)) {
|
|
|
|
case UVC_VC_SELECTOR_UNIT:
|
|
|
|
function = MEDIA_ENT_F_VID_MUX;
|
|
|
|
break;
|
|
|
|
case UVC_VC_PROCESSING_UNIT:
|
|
|
|
case UVC_VC_EXTENSION_UNIT:
|
|
|
|
/* For lack of a better option. */
|
|
|
|
function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
|
|
|
|
break;
|
|
|
|
case UVC_COMPOSITE_CONNECTOR:
|
|
|
|
case UVC_COMPONENT_CONNECTOR:
|
|
|
|
function = MEDIA_ENT_F_CONN_COMPOSITE;
|
|
|
|
break;
|
|
|
|
case UVC_SVIDEO_CONNECTOR:
|
|
|
|
function = MEDIA_ENT_F_CONN_SVIDEO;
|
|
|
|
break;
|
|
|
|
case UVC_ITT_CAMERA:
|
|
|
|
function = MEDIA_ENT_F_CAM_SENSOR;
|
|
|
|
break;
|
|
|
|
case UVC_TT_VENDOR_SPECIFIC:
|
|
|
|
case UVC_ITT_VENDOR_SPECIFIC:
|
|
|
|
case UVC_ITT_MEDIA_TRANSPORT_INPUT:
|
|
|
|
case UVC_OTT_VENDOR_SPECIFIC:
|
|
|
|
case UVC_OTT_DISPLAY:
|
|
|
|
case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
|
|
|
|
case UVC_EXTERNAL_VENDOR_SPECIFIC:
|
media: uvcvideo: Implement UVC_EXT_GPIO_UNIT
Some devices can implement a physical switch to disable the input of the
camera on demand. Think of it like an elegant privacy sticker.
The system can read the status of the privacy switch via a GPIO.
It is important to know the status of the switch, e.g. to notify the
user when the camera will produce black frames and a videochat
application is used.
In some systems, the GPIO is connected to the main SoC instead of the
camera controller, with the connection reported by the system firmware
(ACPI or DT). In that case, the UVC device isn't aware of the GPIO. We
need to implement a virtual entity to handle the GPIO fully on the
driver side.
For example, for ACPI-based systems, the GPIO is reported in the USB
device object:
Scope (\_SB.PCI0.XHCI.RHUB.HS07)
{
/.../
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x0064
}
})
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x01)
{
Package (0x02)
{
"privacy-gpio",
Package (0x04)
{
\_SB.PCI0.XHCI.RHUB.HS07,
Zero,
Zero,
One
}
}
}
})
}
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-12-23 21:35:22 +08:00
|
|
|
case UVC_EXT_GPIO_UNIT:
|
2020-06-07 10:05:49 +08:00
|
|
|
default:
|
|
|
|
function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
entity->subdev.entity.function = function;
|
|
|
|
|
2015-12-11 17:44:40 +08:00
|
|
|
ret = media_entity_pads_init(&entity->subdev.entity,
|
2015-08-06 20:25:57 +08:00
|
|
|
entity->num_pads, entity->pads);
|
2015-12-12 01:16:35 +08:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = v4l2_device_register_subdev(&chain->dev->vdev,
|
|
|
|
&entity->subdev);
|
2011-06-29 05:17:48 +08:00
|
|
|
} else if (entity->vdev != NULL) {
|
2015-12-11 17:44:40 +08:00
|
|
|
ret = media_entity_pads_init(&entity->vdev->entity,
|
2015-08-06 20:25:57 +08:00
|
|
|
entity->num_pads, entity->pads);
|
2012-08-03 15:35:10 +08:00
|
|
|
if (entity->flags & UVC_ENTITY_FLAG_DEFAULT)
|
|
|
|
entity->vdev->entity.flags |= MEDIA_ENT_FL_DEFAULT;
|
2011-06-29 05:17:48 +08:00
|
|
|
} else
|
|
|
|
ret = 0;
|
2010-01-21 16:39:52 +08:00
|
|
|
|
2010-01-21 19:56:19 +08:00
|
|
|
return ret;
|
2010-01-21 16:39:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int uvc_mc_register_entities(struct uvc_video_chain *chain)
|
|
|
|
{
|
|
|
|
struct uvc_entity *entity;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
list_for_each_entry(entity, &chain->entities, chain) {
|
2015-12-12 01:16:35 +08:00
|
|
|
ret = uvc_mc_init_entity(chain, entity);
|
2010-01-21 16:39:52 +08:00
|
|
|
if (ret < 0) {
|
2020-12-23 21:35:24 +08:00
|
|
|
dev_info(&chain->dev->udev->dev,
|
|
|
|
"Failed to initialize entity for entity %u\n",
|
|
|
|
entity->id);
|
2010-01-21 16:39:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 19:46:06 +08:00
|
|
|
list_for_each_entry(entity, &chain->entities, chain) {
|
2015-12-12 01:16:34 +08:00
|
|
|
ret = uvc_mc_create_links(chain, entity);
|
2015-09-03 19:46:06 +08:00
|
|
|
if (ret < 0) {
|
2020-12-23 21:35:24 +08:00
|
|
|
dev_info(&chain->dev->udev->dev,
|
|
|
|
"Failed to create links for entity %u\n",
|
|
|
|
entity->id);
|
2015-09-03 19:46:06 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-21 16:39:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|