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)
57 int v4l2_subdev_get_format(struct media_entity *entity,
58 struct v4l2_mbus_framefmt *format, unsigned int pad,
59 enum v4l2_subdev_format_whence which)
61 struct v4l2_subdev_format fmt;
64 ret = v4l2_subdev_open(entity);
68 memset(&fmt, 0, sizeof(fmt));
72 ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_FMT, &fmt);
80 int v4l2_subdev_set_format(struct media_entity *entity,
81 struct v4l2_mbus_framefmt *format, unsigned int pad,
82 enum v4l2_subdev_format_whence which)
84 struct v4l2_subdev_format fmt;
87 ret = v4l2_subdev_open(entity);
91 memset(&fmt, 0, sizeof(fmt));
96 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FMT, &fmt);
100 *format = fmt.format;
104 int v4l2_subdev_get_crop(struct media_entity *entity, struct v4l2_rect *rect,
105 unsigned int pad, enum v4l2_subdev_format_whence which)
107 struct v4l2_subdev_crop crop;
110 ret = v4l2_subdev_open(entity);
114 memset(&crop, 0, sizeof(crop));
118 ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_CROP, &crop);
126 int v4l2_subdev_set_crop(struct media_entity *entity, struct v4l2_rect *rect,
127 unsigned int pad, enum v4l2_subdev_format_whence which)
129 struct v4l2_subdev_crop crop;
132 ret = v4l2_subdev_open(entity);
136 memset(&crop, 0, sizeof(crop));
141 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_CROP, &crop);
149 int v4l2_subdev_get_frame_interval(struct media_entity *entity,
150 struct v4l2_fract *interval)
152 struct v4l2_subdev_frame_interval ival;
155 ret = v4l2_subdev_open(entity);
159 memset(&ival, 0, sizeof(ival));
161 ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_FRAME_INTERVAL, &ival);
165 *interval = ival.interval;
169 int v4l2_subdev_set_frame_interval(struct media_entity *entity,
170 struct v4l2_fract *interval)
172 struct v4l2_subdev_frame_interval ival;
175 ret = v4l2_subdev_open(entity);
179 memset(&ival, 0, sizeof(ival));
180 ival.interval = *interval;
182 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FRAME_INTERVAL, &ival);
186 *interval = ival.interval;