v4l2-subdev.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * V4L2 sub-device
  3. *
  4. * Copyright (C) 2010 Nokia Corporation
  5. *
  6. * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  7. * Sakari Ailus <sakari.ailus@iki.fi>
  8. *
  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.
  12. *
  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.
  17. *
  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
  21. */
  22. #include <linux/types.h>
  23. #include <linux/ioctl.h>
  24. #include <linux/videodev2.h>
  25. #include <media/v4l2-ctrls.h>
  26. #include <media/v4l2-device.h>
  27. #include <media/v4l2-ioctl.h>
  28. static int subdev_open(struct file *file)
  29. {
  30. return 0;
  31. }
  32. static int subdev_close(struct file *file)
  33. {
  34. return 0;
  35. }
  36. static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
  37. {
  38. struct video_device *vdev = video_devdata(file);
  39. struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
  40. switch (cmd) {
  41. case VIDIOC_QUERYCTRL:
  42. return v4l2_subdev_queryctrl(sd, arg);
  43. case VIDIOC_QUERYMENU:
  44. return v4l2_subdev_querymenu(sd, arg);
  45. case VIDIOC_G_CTRL:
  46. return v4l2_subdev_g_ctrl(sd, arg);
  47. case VIDIOC_S_CTRL:
  48. return v4l2_subdev_s_ctrl(sd, arg);
  49. case VIDIOC_G_EXT_CTRLS:
  50. return v4l2_subdev_g_ext_ctrls(sd, arg);
  51. case VIDIOC_S_EXT_CTRLS:
  52. return v4l2_subdev_s_ext_ctrls(sd, arg);
  53. case VIDIOC_TRY_EXT_CTRLS:
  54. return v4l2_subdev_try_ext_ctrls(sd, arg);
  55. default:
  56. return -ENOIOCTLCMD;
  57. }
  58. return 0;
  59. }
  60. static long subdev_ioctl(struct file *file, unsigned int cmd,
  61. unsigned long arg)
  62. {
  63. return video_usercopy(file, cmd, arg, subdev_do_ioctl);
  64. }
  65. const struct v4l2_file_operations v4l2_subdev_fops = {
  66. .owner = THIS_MODULE,
  67. .open = subdev_open,
  68. .unlocked_ioctl = subdev_ioctl,
  69. .release = subdev_close,
  70. };
  71. void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
  72. {
  73. INIT_LIST_HEAD(&sd->list);
  74. BUG_ON(!ops);
  75. sd->ops = ops;
  76. sd->v4l2_dev = NULL;
  77. sd->flags = 0;
  78. sd->name[0] = '\0';
  79. sd->grp_id = 0;
  80. sd->dev_priv = NULL;
  81. sd->host_priv = NULL;
  82. }
  83. EXPORT_SYMBOL(v4l2_subdev_init);