v4l2-fh.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * v4l2-fh.c
  3. *
  4. * V4L2 file handles.
  5. *
  6. * Copyright (C) 2009--2010 Nokia Corporation.
  7. *
  8. * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * version 2 as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  22. * 02110-1301 USA
  23. */
  24. #include <linux/bitops.h>
  25. #include <media/v4l2-dev.h>
  26. #include <media/v4l2-fh.h>
  27. #include <media/v4l2-event.h>
  28. #include <media/v4l2-ioctl.h>
  29. int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
  30. {
  31. fh->vdev = vdev;
  32. INIT_LIST_HEAD(&fh->list);
  33. set_bit(V4L2_FL_USES_V4L2_FH, &fh->vdev->flags);
  34. fh->prio = V4L2_PRIORITY_UNSET;
  35. BUG_ON(vdev->prio == NULL);
  36. /*
  37. * fh->events only needs to be initialized if the driver
  38. * supports the VIDIOC_SUBSCRIBE_EVENT ioctl.
  39. */
  40. if (vdev->ioctl_ops && vdev->ioctl_ops->vidioc_subscribe_event)
  41. return v4l2_event_init(fh);
  42. fh->events = NULL;
  43. return 0;
  44. }
  45. EXPORT_SYMBOL_GPL(v4l2_fh_init);
  46. void v4l2_fh_add(struct v4l2_fh *fh)
  47. {
  48. unsigned long flags;
  49. v4l2_prio_open(fh->vdev->prio, &fh->prio);
  50. spin_lock_irqsave(&fh->vdev->fh_lock, flags);
  51. list_add(&fh->list, &fh->vdev->fh_list);
  52. spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
  53. }
  54. EXPORT_SYMBOL_GPL(v4l2_fh_add);
  55. void v4l2_fh_del(struct v4l2_fh *fh)
  56. {
  57. unsigned long flags;
  58. spin_lock_irqsave(&fh->vdev->fh_lock, flags);
  59. list_del_init(&fh->list);
  60. spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
  61. v4l2_prio_close(fh->vdev->prio, fh->prio);
  62. }
  63. EXPORT_SYMBOL_GPL(v4l2_fh_del);
  64. void v4l2_fh_exit(struct v4l2_fh *fh)
  65. {
  66. if (fh->vdev == NULL)
  67. return;
  68. fh->vdev = NULL;
  69. v4l2_event_free(fh);
  70. }
  71. EXPORT_SYMBOL_GPL(v4l2_fh_exit);