+ if (ret < 0)
+ return ret;
+
+ if (entity->sd->fd != -1)
return 0;
- entity->fd = open(entity->devname, O_RDWR);
- if (entity->fd == -1) {
+ entity->sd->fd = open(entity->devname, O_RDWR);
+ if (entity->sd->fd == -1) {
int ret = -errno;
media_dbg(entity->media,
"%s: Failed to open subdev device node %s\n", __func__,
@@ -58,8 +106,8 @@ int v4l2_subdev_open(struct media_entity *entity)
void v4l2_subdev_close(struct media_entity *entity)
{
- close(entity->fd);
- entity->fd = -1;
+ close(entity->sd->fd);
+ entity->sd->fd = -1;
}
int v4l2_subdev_get_format(struct media_entity *entity,
@@ -77,7 +125,7 @@ int v4l2_subdev_get_format(struct media_entity *entity,
fmt.pad = pad;
fmt.which = which;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_FMT, &fmt);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_G_FMT, &fmt);
if (ret < 0)
return -errno;
@@ -101,7 +149,7 @@ int v4l2_subdev_set_format(struct media_entity *entity,
fmt.which = which;
fmt.format = *format;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FMT, &fmt);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_S_FMT, &fmt);
if (ret < 0)
return -errno;
@@ -128,7 +176,7 @@ int v4l2_subdev_get_selection(struct media_entity *entity,
u.sel.target = target;
u.sel.which = which;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_SELECTION, &u.sel);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_G_SELECTION, &u.sel);
if (ret >= 0) {
*rect = u.sel.r;
return 0;
@@ -140,7 +188,7 @@ int v4l2_subdev_get_selection(struct media_entity *entity,
u.crop.pad = pad;
u.crop.which = which;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_CROP, &u.crop);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_G_CROP, &u.crop);
if (ret < 0)
return -errno;
@@ -168,7 +216,7 @@ int v4l2_subdev_set_selection(struct media_entity *entity,
u.sel.which = which;
u.sel.r = *rect;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_SELECTION, &u.sel);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_S_SELECTION, &u.sel);
if (ret >= 0) {
*rect = u.sel.r;
return 0;
@@ -181,7 +229,7 @@ int v4l2_subdev_set_selection(struct media_entity *entity,
u.crop.which = which;
u.crop.rect = *rect;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_CROP, &u.crop);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_S_CROP, &u.crop);
if (ret < 0)
return -errno;
@@ -202,7 +250,7 @@ int v4l2_subdev_get_dv_timings_caps(struct media_entity *entity,
memset(caps, 0, sizeof(*caps));
caps->pad = pad;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_DV_TIMINGS_CAP, caps);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_DV_TIMINGS_CAP, caps);
if (ret < 0)
return -errno;
@@ -220,7 +268,7 @@ int v4l2_subdev_query_dv_timings(struct media_entity *entity,
memset(timings, 0, sizeof(*timings));
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_QUERY_DV_TIMINGS, timings);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_QUERY_DV_TIMINGS, timings);
if (ret < 0)
return -errno;
@@ -238,7 +286,7 @@ int v4l2_subdev_get_dv_timings(struct media_entity *entity,
memset(timings, 0, sizeof(*timings));
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_DV_TIMINGS, timings);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_G_DV_TIMINGS, timings);
if (ret < 0)
return -errno;
@@ -254,7 +302,7 @@ int v4l2_subdev_set_dv_timings(struct media_entity *entity,
if (ret < 0)
return ret;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_DV_TIMINGS, timings);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_S_DV_TIMINGS, timings);
if (ret < 0)
return -errno;
@@ -273,7 +321,7 @@ int v4l2_subdev_get_frame_interval(struct media_entity *entity,
memset(&ival, 0, sizeof(ival));
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_FRAME_INTERVAL, &ival);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_G_FRAME_INTERVAL, &ival);
if (ret < 0)
return -errno;
@@ -294,7 +342,7 @@ int v4l2_subdev_set_frame_interval(struct media_entity *entity,
memset(&ival, 0, sizeof(ival));
ival.interval = *interval;
- ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FRAME_INTERVAL, &ival);
+ ret = ioctl(entity->sd->fd, VIDIOC_SUBDEV_S_FRAME_INTERVAL, &ival);
if (ret < 0)
return -errno;
diff --git a/utils/media-ctl/mediactl-priv.h b/utils/media-ctl/mediactl-priv.h
index a0d3a55..f531c52 100644
--- a/utils/media-ctl/mediactl-priv.h
+++ b/utils/media-ctl/mediactl-priv.h
@@ -26,6 +26,8 @@
#include "mediactl.h"
+struct v4l2_subdev;
+
struct media_entity {
struct media_device *media;
struct media_entity_desc info;
@@ -34,8 +36,9 @@ struct media_entity {
unsigned int max_links;
unsigned int num_links;
+ struct v4l2_subdev *sd;
+
char devname[32];
- int fd;
};
struct media_device {
diff --git a/utils/media-ctl/v4l2subdev.h b/utils/media-ctl/v4l2subdev.h
index 104e420..ba9b8c4 100644
--- a/utils/media-ctl/v4l2subdev.h
+++ b/utils/media-ctl/v4l2subdev.h
@@ -27,6 +27,44 @@
struct media_device;
struct media_entity;
+struct v4l2_subdev {
+ int fd;
+};
+
+/**
+ * @brief Create a v4l2-subdev
+ * @param entity - sub-device media entity.
+ *
+ * Create the representation of the entity sub-device.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_create(struct media_entity *entity);
+
+/**
+ * @brief Create a representation of the already opened v4l2-subdev
+ * @param entity - sub-device media entity.
+ * @param fd - sub-device file descriptor.
+ *
+ * Create the representation of the sub-device that had been opened
+ * before the parent media device was created, and associate it
+ * with the media entity.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_create_with_fd(struct media_entity *entity, int fd);
+
+/**
+ * @brief Release a v4l2-subdev
+ * @param entity - sub-device media entity.
+ * @param close_fd - indicates whether subdev fd should be closed.
+ *
+ * Release the representation of the entity sub-device.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+void v4l2_subdev_release(struct media_entity *entity, bool close_fd);
+