v4l2-dev.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. *
  3. * V 4 L 2 D R I V E R H E L P E R A P I
  4. *
  5. * Moved from videodev2.h
  6. *
  7. * Some commonly needed functions for drivers (v4l2-common.o module)
  8. */
  9. #ifndef _V4L2_DEV_H
  10. #define _V4L2_DEV_H
  11. #define OBSOLETE_OWNER 1 /* to be removed soon */
  12. #define OBSOLETE_DEVDATA 1 /* to be removed soon */
  13. #include <linux/poll.h>
  14. #include <linux/fs.h>
  15. #include <linux/device.h>
  16. #include <linux/mutex.h>
  17. #include <linux/compiler.h> /* need __user */
  18. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  19. #include <linux/videodev.h>
  20. #else
  21. #include <linux/videodev2.h>
  22. #endif
  23. #define VIDEO_MAJOR 81
  24. /* Minor device allocation */
  25. #define MINOR_VFL_TYPE_GRABBER_MIN 0
  26. #define MINOR_VFL_TYPE_GRABBER_MAX 63
  27. #define MINOR_VFL_TYPE_RADIO_MIN 64
  28. #define MINOR_VFL_TYPE_RADIO_MAX 127
  29. #define MINOR_VFL_TYPE_VTX_MIN 192
  30. #define MINOR_VFL_TYPE_VTX_MAX 223
  31. #define MINOR_VFL_TYPE_VBI_MIN 224
  32. #define MINOR_VFL_TYPE_VBI_MAX 255
  33. #define VFL_TYPE_GRABBER 0
  34. #define VFL_TYPE_VBI 1
  35. #define VFL_TYPE_RADIO 2
  36. #define VFL_TYPE_VTX 3
  37. struct v4l2_ioctl_callbacks;
  38. /*
  39. * Newer version of video_device, handled by videodev2.c
  40. * This version moves redundant code from video device code to
  41. * the common handler
  42. */
  43. struct video_device
  44. {
  45. /* device ops */
  46. const struct file_operations *fops;
  47. /* sysfs */
  48. struct device dev; /* v4l device */
  49. struct device *parent; /* device parent */
  50. /* device info */
  51. char name[32];
  52. int type; /* v4l1 */
  53. int type2; /* v4l2 */
  54. int minor;
  55. /* attribute to diferentiate multiple indexs on one physical device */
  56. int index;
  57. int debug; /* Activates debug level*/
  58. /* Video standard vars */
  59. v4l2_std_id tvnorms; /* Supported tv norms */
  60. v4l2_std_id current_norm; /* Current tvnorm */
  61. /* callbacks */
  62. void (*release)(struct video_device *vfd);
  63. /* ioctl callbacks */
  64. const struct v4l2_ioctl_ops *ioctl_ops;
  65. #ifdef OBSOLETE_OWNER /* to be removed soon */
  66. /* obsolete -- fops->owner is used instead */
  67. struct module *owner;
  68. /* dev->driver_data will be used instead some day.
  69. * Use the video_{get|set}_drvdata() helper functions,
  70. * so the switch over will be transparent for you.
  71. * Or use {pci|usb}_{get|set}_drvdata() directly. */
  72. void *priv;
  73. #endif
  74. /* for videodev.c intenal usage -- please don't touch */
  75. int users; /* video_exclusive_{open|close} ... */
  76. struct mutex lock; /* ... helper function uses these */
  77. };
  78. /* Class-dev to video-device */
  79. #define to_video_device(cd) container_of(cd, struct video_device, dev)
  80. /* Version 2 functions */
  81. extern int video_register_device(struct video_device *vfd, int type, int nr);
  82. int video_register_device_index(struct video_device *vfd, int type, int nr,
  83. int index);
  84. void video_unregister_device(struct video_device *);
  85. /* helper functions to alloc / release struct video_device, the
  86. later can be used for video_device->release() */
  87. struct video_device *video_device_alloc(void);
  88. void video_device_release(struct video_device *vfd);
  89. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  90. #include <linux/mm.h>
  91. static inline int __must_check
  92. video_device_create_file(struct video_device *vfd,
  93. struct device_attribute *attr)
  94. {
  95. int ret = device_create_file(&vfd->dev, attr);
  96. if (ret < 0)
  97. printk(KERN_WARNING "%s error: %d\n", __func__, ret);
  98. return ret;
  99. }
  100. static inline void
  101. video_device_remove_file(struct video_device *vfd,
  102. struct device_attribute *attr)
  103. {
  104. device_remove_file(&vfd->dev, attr);
  105. }
  106. #endif /* CONFIG_VIDEO_V4L1_COMPAT */
  107. #ifdef OBSOLETE_OWNER /* to be removed soon */
  108. /* helper functions to access driver private data. */
  109. static inline void *video_get_drvdata(struct video_device *dev)
  110. {
  111. return dev->priv;
  112. }
  113. static inline void video_set_drvdata(struct video_device *dev, void *data)
  114. {
  115. dev->priv = data;
  116. }
  117. #endif
  118. #ifdef OBSOLETE_DEVDATA /* to be removed soon */
  119. /* Obsolete stuff - Still needed for radio devices and obsolete drivers */
  120. extern struct video_device* video_devdata(struct file*);
  121. extern int video_exclusive_open(struct inode *inode, struct file *file);
  122. extern int video_exclusive_release(struct inode *inode, struct file *file);
  123. #endif
  124. #endif /* _V4L2_DEV_H */