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>
38 enum v4l2_mbus_pixelcode code;
40 { "YUYV", V4L2_MBUS_FMT_YUYV16_1X16 },
41 { "UYVY", V4L2_MBUS_FMT_UYVY16_1X16 },
42 { "SGRBG10", V4L2_MBUS_FMT_SGRBG10_1X10 },
43 { "SGRBG10_DPCM8", V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 },
46 const char *pixelcode_to_string(enum v4l2_mbus_pixelcode code)
50 for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) {
51 if (mbus_formats[i].code == code)
52 return mbus_formats[i].name;
58 enum v4l2_mbus_pixelcode string_to_pixelcode(const char *string,
63 for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) {
64 if (strncmp(mbus_formats[i].name, string, length) == 0)
68 if (i == ARRAY_SIZE(mbus_formats))
69 return (enum v4l2_mbus_pixelcode)-1;
71 return mbus_formats[i].code;
74 static int v4l2_subdev_open(struct media_entity *entity)
79 entity->fd = open(entity->devname, O_RDWR);
80 if (entity->fd == -1) {
81 printf("%s: Failed to open subdev device node %s\n", __func__,
89 int v4l2_subdev_get_format(struct media_entity *entity,
90 struct v4l2_mbus_framefmt *format, unsigned int pad,
91 enum v4l2_subdev_format which)
93 struct v4l2_subdev_pad_format fmt;
96 ret = v4l2_subdev_open(entity);
100 memset(&fmt, 0, sizeof(fmt));
104 ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_FMT, &fmt);
108 *format = fmt.format;
112 int v4l2_subdev_set_format(struct media_entity *entity,
113 struct v4l2_mbus_framefmt *format, unsigned int pad,
114 enum v4l2_subdev_format which)
116 struct v4l2_subdev_pad_format fmt;
119 ret = v4l2_subdev_open(entity);
123 memset(&fmt, 0, sizeof(fmt));
126 fmt.format = *format;
128 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FMT, &fmt);
132 *format = fmt.format;
136 int v4l2_subdev_get_crop(struct media_entity *entity, struct v4l2_rect *rect,
137 unsigned int pad, enum v4l2_subdev_format which)
139 struct v4l2_subdev_pad_crop crop;
142 ret = v4l2_subdev_open(entity);
146 memset(&crop, 0, sizeof(crop));
150 ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_CROP, &crop);
158 int v4l2_subdev_set_crop(struct media_entity *entity, struct v4l2_rect *rect,
159 unsigned int pad, enum v4l2_subdev_format which)
161 struct v4l2_subdev_pad_crop crop;
164 ret = v4l2_subdev_open(entity);
168 memset(&crop, 0, sizeof(crop));
173 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_CROP, &crop);
181 int v4l2_subdev_set_frame_interval(struct media_entity *entity,
182 struct v4l2_fract *interval)
184 struct v4l2_subdev_frame_interval ival;
187 ret = v4l2_subdev_open(entity);
191 memset(&ival, 0, sizeof(ival));
192 ival.interval = *interval;
194 ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FRAME_INTERVAL, &ival);
198 *interval = ival.interval;