2 * Media controller test application
4 * Copyright (C) 2010 Ideas on board SPRL <laurent.pinchart@ideasonboard.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
20 #include <sys/ioctl.h>
22 #include <sys/types.h>
30 #include <linux/v4l2-subdev.h>
36 int v4l2_subdev_open(struct media_entity *entity)
41 entity->fd = open(entity->devname, O_RDWR);
42 if (entity->fd == -1) {
43 printf("%s: Failed to open subdev device node %s\n", __func__,
51 void v4l2_subdev_close(struct media_entity *entity)
56 int v4l2_subdev_get_format(struct media_entity *entity,
57 struct v4l2_mbus_framefmt *format, unsigned int pad,
58 enum v4l2_subdev_format_whence which)
60 struct v4l2_subdev_format fmt;
63 ret = v4l2_subdev_open(entity);
67 memset(&fmt, 0, sizeof(fmt));
71 ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_FMT, &fmt);
79 int v4l2_subdev_set_format(struct media_entity *entity,
80 struct v4l2_mbus_framefmt *format, unsigned int pad,
81 enum v4l2_subdev_format_whence which)
83 struct v4l2_subdev_format fmt;
86 ret = v4l2_subdev_open(entity);
90 memset(&fmt, 0, sizeof(fmt));
95 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FMT, &fmt);
103 int v4l2_subdev_get_crop(struct media_entity *entity, struct v4l2_rect *rect,
104 unsigned int pad, enum v4l2_subdev_format_whence which)
106 struct v4l2_subdev_crop crop;
109 ret = v4l2_subdev_open(entity);
113 memset(&crop, 0, sizeof(crop));
117 ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_CROP, &crop);
125 int v4l2_subdev_set_crop(struct media_entity *entity, struct v4l2_rect *rect,
126 unsigned int pad, enum v4l2_subdev_format_whence which)
128 struct v4l2_subdev_crop crop;
131 ret = v4l2_subdev_open(entity);
135 memset(&crop, 0, sizeof(crop));
140 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_CROP, &crop);
148 int v4l2_subdev_get_frame_interval(struct media_entity *entity,
149 struct v4l2_fract *interval)
151 struct v4l2_subdev_frame_interval ival;
154 ret = v4l2_subdev_open(entity);
158 memset(&ival, 0, sizeof(ival));
160 ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_FRAME_INTERVAL, &ival);
164 *interval = ival.interval;
168 int v4l2_subdev_set_frame_interval(struct media_entity *entity,
169 struct v4l2_fract *interval)
171 struct v4l2_subdev_frame_interval ival;
174 ret = v4l2_subdev_open(entity);
178 memset(&ival, 0, sizeof(ival));
179 ival.interval = *interval;
181 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FRAME_INTERVAL, &ival);
185 *interval = ival.interval;