1 /**************************************************************************
3 xserver-xorg-video-emulfb
5 Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: Boram Park <boram1288.park@samsung.com>
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 #include <sys/ioctl.h>
38 #include "fbdev_v4l2.h"
39 #include "fbdev_util.h"
41 typedef struct _CapInfo
47 static CapInfo cap_infos [] =
49 {V4L2_CAP_VIDEO_CAPTURE, "VIDEO_CAPTURE"},
50 {V4L2_CAP_VIDEO_OUTPUT, "VIDEO_OUTPUT"},
51 {V4L2_CAP_VIDEO_OVERLAY, "VIDEO_OVERLAY"},
52 {V4L2_CAP_VBI_CAPTURE, "VBI_CAPTURE"},
53 {V4L2_CAP_VBI_OUTPUT, "VBI_OUTPUT"},
54 {V4L2_CAP_SLICED_VBI_CAPTURE, "SLICED_VBI_CAPTURE"},
55 {V4L2_CAP_SLICED_VBI_OUTPUT, "SLICED_VBI_OUTPUT"},
56 {V4L2_CAP_RDS_CAPTURE, "RDS_CAPTURE"},
57 {V4L2_CAP_VIDEO_OUTPUT_OVERLAY, "VIDEO_OUTPUT_OVERLAY"},
58 {V4L2_CAP_HW_FREQ_SEEK, "HW_FREQ_SEEK"},
59 {V4L2_CAP_RDS_OUTPUT, "RDS_OUTPUT"},
60 {V4L2_CAP_TUNER, "TUNER"},
61 {V4L2_CAP_AUDIO, "AUDIO"},
62 {V4L2_CAP_RADIO, "RADIO"},
63 {V4L2_CAP_MODULATOR, "MODULATOR"},
64 {V4L2_CAP_READWRITE, "READWRITE"},
65 {V4L2_CAP_ASYNCIO, "ASYNCIO"},
66 {V4L2_CAP_STREAMING, "STREAMING"}
69 static Bool _fbdev_v4l2_ioctl (int fd, int cmd, void *data, char *debug)
75 ret = ioctl (fd, cmd, data);
78 if (errno == EINTR || errno == EAGAIN)
93 Bool fbdev_v4l2_querycap (int fd, int capabilities)
95 struct v4l2_capability cap;
99 ret = ioctl (fd, VIDIOC_QUERYCAP, &cap);
102 xf86DrvMsg (0, X_ERROR, "[QUERYCAP] failed. (%s)\n", strerror(errno));
106 if (~(cap.capabilities) & capabilities)
108 int unsupport = ~(cap.capabilities) & capabilities;
111 for (i = 0; i < sizeof (cap_infos) / sizeof (CapInfo); i++)
112 if (unsupport & cap_infos[i].value)
113 xf86DrvMsg (0, X_ERROR, "[QUERYCAP] %s not support.\n", cap_infos[i].name);
121 Bool fbdev_v4l2_cropcap (int fd, FBDevV4l2BufType type, struct v4l2_rect *crop)
123 struct v4l2_cropcap cropcap;
128 ret = ioctl (fd, VIDIOC_CROPCAP, &cropcap);
131 xf86DrvMsg (0, X_ERROR, "[CROPCAP] failed. (%s)\n", strerror(errno));
135 /* check if crop_rect si valid */
136 if ((crop->left < cropcap.bounds.left) &&
137 (crop->top < cropcap.bounds.top) &&
138 (crop->width > cropcap.bounds.width) &&
139 (crop->height > cropcap.bounds.height))
141 xf86DrvMsg (0, X_ERROR, "(%d,%d %dx%d) is out of bound(%d,%d %dx%d)\n",
142 crop->left, crop->top, crop->width, crop->height,
143 cropcap.bounds.left, cropcap.bounds.top,
144 cropcap.bounds.width, cropcap.bounds.height);
151 Bool fbdev_v4l2_enum_std (int fd, struct v4l2_standard *std, v4l2_std_id std_id)
155 while (0 == ioctl (fd, VIDIOC_ENUMSTD, std))
157 /* return TRUE if std_id found */
158 if (std->id & std_id)
160 xf86DrvMsg (0, X_ERROR, "[ENUMSTD] name(%s). (%s)\n", std->name, strerror(errno));
170 Bool fbdev_v4l2_enum_output (int fd, struct v4l2_output *output, FBDevV4l2BufType type)
174 while (0 == ioctl (fd, VIDIOC_ENUMOUTPUT, output))
176 /* return TRUE if type found */
177 if (output->type & type)
179 xf86DrvMsg (0, X_ERROR, "[ENUMOUTPUT] index(%d) type(0x%08x) name(%s). (%s)\n",
180 output->index,output->type,output->name, strerror(errno));
190 Bool fbdev_v4l2_enum_fmt (int fd, struct v4l2_fmtdesc *desc, FBDevV4l2BufType type)
194 while (0 == ioctl (fd, VIDIOC_ENUM_FMT, desc))
196 /* return TRUE if type found */
197 if (desc->type & type)
199 xf86DrvMsg (0, X_ERROR, "[ENUM_FMT] index(%d) type(0x%08x) desc(%s) pxlfmt(0x%08x). (%s)\n",
200 desc->index, desc->type, desc->description, desc->pixelformat, strerror(errno));
210 Bool fbdev_v4l2_g_std (int fd, v4l2_std_id *std_id)
214 ret = ioctl (fd, VIDIOC_G_STD, std_id);
217 xf86DrvMsg (0, X_ERROR, "[G_STD] failed. (%s)\n", strerror(errno));
224 Bool fbdev_v4l2_s_std (int fd, v4l2_std_id std_id)
228 ret = ioctl (fd, VIDIOC_S_STD, &std_id);
231 xf86DrvMsg (0, X_ERROR, "[S_STD] failed. (%s)\n", strerror(errno));
238 Bool fbdev_v4l2_g_output (int fd, int *index)
242 ret = ioctl (fd, VIDIOC_G_OUTPUT, index);
245 xf86DrvMsg (0, X_ERROR, "[G_OUTPUT] failed. (%s)\n", strerror(errno));
252 Bool fbdev_v4l2_s_output (int fd, int index)
256 ret = ioctl (fd, VIDIOC_S_OUTPUT, &index);
259 xf86DrvMsg (0, X_ERROR, "[S_OUTPUT] failed. (%s)\n", strerror(errno));
266 Bool fbdev_v4l2_try_fmt (int fd, struct v4l2_format *format)
270 ret = ioctl (fd, VIDIOC_TRY_FMT, format);
277 Bool fbdev_v4l2_g_fmt (int fd, struct v4l2_format *format)
281 ret = ioctl (fd, VIDIOC_G_FMT, format);
284 xf86DrvMsg (0, X_ERROR, "[G_FMT] failed. (%s)\n", strerror(errno));
291 Bool fbdev_v4l2_s_fmt (int fd, struct v4l2_format *format)
295 ret = ioctl (fd, VIDIOC_S_FMT, format);
298 xf86DrvMsg (0, X_ERROR, "[S_FMT] failed. (%s)\n", strerror(errno));
305 Bool fbdev_v4l2_g_parm (int fd, struct v4l2_streamparm *parm)
309 ret = ioctl (fd, VIDIOC_G_PARM, parm);
312 xf86DrvMsg (0, X_ERROR, "[G_PARM] failed. (%s)\n", strerror(errno));
319 Bool fbdev_v4l2_s_parm (int fd, struct v4l2_streamparm *parm)
323 ret = ioctl (fd, VIDIOC_S_PARM, parm);
326 xf86DrvMsg (0, X_ERROR, "[S_PARM] failed. (%s)\n", strerror(errno));
333 Bool fbdev_v4l2_g_fbuf (int fd, struct v4l2_framebuffer *frame)
337 ret = ioctl (fd, VIDIOC_G_FBUF, frame);
340 xf86DrvMsg (0, X_ERROR, "[G_FBUF] failed. (%s)\n", strerror(errno));
347 Bool fbdev_v4l2_s_fbuf (int fd, struct v4l2_framebuffer *frame)
351 ret = ioctl (fd, VIDIOC_S_FBUF, frame);
354 xf86DrvMsg (0, X_ERROR, "[S_FBUF] failed. (%s)\n", strerror(errno));
361 Bool fbdev_v4l2_g_crop (int fd, struct v4l2_crop *crop)
365 ret = ioctl (fd, VIDIOC_G_CROP, crop);
368 xf86DrvMsg (0, X_ERROR, "[G_CROP] failed. (%s)\n", strerror(errno));
375 Bool fbdev_v4l2_s_crop (int fd, struct v4l2_crop *crop)
379 ret = ioctl (fd, VIDIOC_S_CROP, crop);
382 xf86DrvMsg (0, X_ERROR, "[S_CROP] failed. (%s)\n", strerror(errno));
389 Bool fbdev_v4l2_g_ctrl (int fd, struct v4l2_control *ctrl)
393 ret = ioctl (fd, VIDIOC_G_CTRL, ctrl);
396 xf86DrvMsg (0, X_ERROR, "[G_CTRL] failed. (%s)\n", strerror(errno));
403 Bool fbdev_v4l2_s_ctrl (int fd, struct v4l2_control *ctrl)
407 ret = ioctl (fd, VIDIOC_S_CTRL, ctrl);
410 xf86DrvMsg (0, X_ERROR, "[S_CTRL] failed. (%s)\n", strerror(errno));
417 Bool fbdev_v4l2_streamon (int fd, FBDevV4l2BufType type)
419 if (!_fbdev_v4l2_ioctl (fd, VIDIOC_STREAMON, (void*)&type, "STREAMON"))
421 xf86DrvMsg (0, X_ERROR, "[STREAMON] failed. (%s)\n", strerror(errno));
428 Bool fbdev_v4l2_streamoff (int fd, FBDevV4l2BufType type)
430 if (!_fbdev_v4l2_ioctl (fd, VIDIOC_STREAMOFF, (void*)&type, "STREAMOFF"))
432 xf86DrvMsg (0, X_ERROR, "[STREAMOFF] failed. (%s)\n", strerror(errno));
440 Bool fbdev_v4l2_start_overlay (int fd)
444 if (!_fbdev_v4l2_ioctl (fd, VIDIOC_OVERLAY, (void*)&start, "OVERLAY (start)"))
446 xf86DrvMsg (0, X_ERROR, "[OVERLAY] (start) failed. (%s)\n", strerror(errno));
453 Bool fbdev_v4l2_stop_overlay (int fd)
457 if (!_fbdev_v4l2_ioctl (fd, VIDIOC_OVERLAY, (void*)&stop, "OVERLAY (stop)"))
459 xf86DrvMsg (0, X_ERROR, "[OVERLAY] (stop) failed. (%s)\n", strerror(errno));
466 Bool fbdev_v4l2_reqbuf (int fd, struct v4l2_requestbuffers *req)
468 if (!_fbdev_v4l2_ioctl (fd, VIDIOC_REQBUFS, (void*)req, "REQBUFS"))
470 xf86DrvMsg (0, X_ERROR, "[REQBUFS] failed. (%s)\n", strerror(errno));
477 Bool fbdev_v4l2_querybuf (int fd, struct v4l2_buffer *set_buf)
479 if (!_fbdev_v4l2_ioctl (fd, VIDIOC_QUERYBUF, (void*)set_buf, "QUERYBUF"))
481 xf86DrvMsg (0, X_ERROR, "[QUERYBUF] failed. (%s)\n", strerror(errno));
489 Bool fbdev_v4l2_queue (int fd, struct v4l2_buffer *buf)
491 if (!_fbdev_v4l2_ioctl (fd, VIDIOC_QBUF, (void*)buf, "QBUF"))
493 xf86DrvMsg (0, X_ERROR, "[QBUF] failed. (%s)\n", strerror(errno));
501 Bool fbdev_v4l2_dequeue (int fd, struct v4l2_buffer *buf)
503 if (!_fbdev_v4l2_ioctl (fd, VIDIOC_DQBUF, (void*)buf, "DQBUF"))
505 xf86DrvMsg (0, X_ERROR, "[DQBUF] failed. (%s)\n", strerror(errno));