Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 1 | /* |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 2 | * V4L2 sub-device |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 3 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 4 | * Copyright (C) 2010 Nokia Corporation |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 5 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 6 | * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
| 7 | * Sakari Ailus <sakari.ailus@iki.fi> |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 8 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 9 | * 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 Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 12 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 13 | * 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 Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 17 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 18 | * 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 Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/ioctl.h> |
| 25 | #include <linux/videodev2.h> |
| 26 | |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame^] | 27 | #include <media/v4l2-ctrls.h> |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 28 | #include <media/v4l2-device.h> |
| 29 | #include <media/v4l2-ioctl.h> |
| 30 | |
| 31 | static int subdev_open(struct file *file) |
| 32 | { |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static int subdev_close(struct file *file) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) |
| 42 | { |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame^] | 43 | struct video_device *vdev = video_devdata(file); |
| 44 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
| 45 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 46 | switch (cmd) { |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame^] | 47 | 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 Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 68 | default: |
| 69 | return -ENOIOCTLCMD; |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static 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 | |
| 81 | const 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 Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 87 | |
| 88 | void 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 | } |
| 100 | EXPORT_SYMBOL(v4l2_subdev_init); |