blob: da10430051c08af7f7d560c687a6a5ae12c4d7b8 [file] [log] [blame]
Laurent Pinchart2096a5d2009-12-09 08:38:49 -03001/*
Laurent Pinchart3dd5ee02009-12-09 08:38:52 -03002 * V4L2 sub-device
Laurent Pinchart2096a5d2009-12-09 08:38:49 -03003 *
Laurent Pinchart3dd5ee02009-12-09 08:38:52 -03004 * Copyright (C) 2010 Nokia Corporation
Laurent Pinchart2096a5d2009-12-09 08:38:49 -03005 *
Laurent Pinchart3dd5ee02009-12-09 08:38:52 -03006 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
Laurent Pinchart2096a5d2009-12-09 08:38:49 -03008 *
Laurent Pinchart3dd5ee02009-12-09 08:38:52 -03009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
Laurent Pinchart2096a5d2009-12-09 08:38:49 -030012 *
Laurent Pinchart3dd5ee02009-12-09 08:38:52 -030013 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Laurent Pinchart2096a5d2009-12-09 08:38:49 -030017 *
Laurent Pinchart3dd5ee02009-12-09 08:38:52 -030018 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Laurent Pinchart2096a5d2009-12-09 08:38:49 -030021 */
22
23#include <linux/types.h>
24#include <linux/ioctl.h>
25#include <linux/videodev2.h>
26
Laurent Pinchartea8aa432009-12-09 08:39:54 -030027#include <media/v4l2-ctrls.h>
Laurent Pinchart2096a5d2009-12-09 08:38:49 -030028#include <media/v4l2-device.h>
29#include <media/v4l2-ioctl.h>
30
31static int subdev_open(struct file *file)
32{
33 return 0;
34}
35
36static int subdev_close(struct file *file)
37{
38 return 0;
39}
40
41static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
42{
Laurent Pinchartea8aa432009-12-09 08:39:54 -030043 struct video_device *vdev = video_devdata(file);
44 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
45
Laurent Pinchart2096a5d2009-12-09 08:38:49 -030046 switch (cmd) {
Laurent Pinchartea8aa432009-12-09 08:39:54 -030047 case VIDIOC_QUERYCTRL:
48 return v4l2_subdev_queryctrl(sd, arg);
49
50 case VIDIOC_QUERYMENU:
51 return v4l2_subdev_querymenu(sd, arg);
52
53 case VIDIOC_G_CTRL:
54 return v4l2_subdev_g_ctrl(sd, arg);
55
56 case VIDIOC_S_CTRL:
57 return v4l2_subdev_s_ctrl(sd, arg);
58
59 case VIDIOC_G_EXT_CTRLS:
60 return v4l2_subdev_g_ext_ctrls(sd, arg);
61
62 case VIDIOC_S_EXT_CTRLS:
63 return v4l2_subdev_s_ext_ctrls(sd, arg);
64
65 case VIDIOC_TRY_EXT_CTRLS:
66 return v4l2_subdev_try_ext_ctrls(sd, arg);
67
Laurent Pinchart2096a5d2009-12-09 08:38:49 -030068 default:
69 return -ENOIOCTLCMD;
70 }
71
72 return 0;
73}
74
75static long subdev_ioctl(struct file *file, unsigned int cmd,
76 unsigned long arg)
77{
78 return video_usercopy(file, cmd, arg, subdev_do_ioctl);
79}
80
81const struct v4l2_file_operations v4l2_subdev_fops = {
82 .owner = THIS_MODULE,
83 .open = subdev_open,
84 .unlocked_ioctl = subdev_ioctl,
85 .release = subdev_close,
86};
Laurent Pinchart3dd5ee02009-12-09 08:38:52 -030087
88void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
89{
90 INIT_LIST_HEAD(&sd->list);
91 BUG_ON(!ops);
92 sd->ops = ops;
93 sd->v4l2_dev = NULL;
94 sd->flags = 0;
95 sd->name[0] = '\0';
96 sd->grp_id = 0;
97 sd->dev_priv = NULL;
98 sd->host_priv = NULL;
99}
100EXPORT_SYMBOL(v4l2_subdev_init);