main.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #pragma once
  2. #include <media/videobuf2-vmalloc.h>
  3. #include <linux/timekeeping.h>
  4. int webcamTryFormat( struct driverInstance*, struct v4l2_pix_format*, char setFlag );
  5. struct webcam_control* usbcam_ctrl_find( struct driverInstance*, u32 );
  6. int webcamCaptureStart( struct driverInstance* );
  7. int webcamInit( struct driverInstance*, const struct usb_device_id* );
  8. void webcamRelease( struct driverInstance* );
  9. /****************************
  10. * Videobuf2 *
  11. ****************************/
  12. static int queue_setup_callback( struct vb2_queue* videobufQueue, unsigned int* numBuffers, unsigned int* numPlanes, unsigned int sizes[], struct device* alloc_ctxs[] );
  13. static int buf_prepare_callback( struct vb2_buffer* videoBuffer );
  14. static void buf_queue_callback( struct vb2_buffer* videoBuffer );
  15. static int start_streaming_callback( struct vb2_queue* videobufQueue, unsigned int count );
  16. static void stop_streaming_callback( struct vb2_queue* videobufQueue );
  17. //Note that since videobuf2Queue->lock is set we can use the standard vb2_ops_wait_prepare/finish helper functions.
  18. //If videobuf2Queue->lock would be NULL, then this driver would have to provide these ops.
  19. static const struct vb2_ops videobuf2QueueOps = {
  20. .queue_setup = queue_setup_callback,
  21. .buf_prepare = buf_prepare_callback,
  22. .buf_queue = buf_queue_callback,
  23. .start_streaming = start_streaming_callback,
  24. .stop_streaming = stop_streaming_callback,
  25. .wait_prepare = vb2_ops_wait_prepare,
  26. .wait_finish = vb2_ops_wait_finish,
  27. };
  28. //The set of file operations. Note that all these ops are standard core helper functions.
  29. static const struct v4l2_file_operations v4l2FileOperations = {
  30. .owner = THIS_MODULE,
  31. .open = v4l2_fh_open,
  32. .release = vb2_fop_release,
  33. .unlocked_ioctl = video_ioctl2,
  34. .read = vb2_fop_read,
  35. .mmap = vb2_fop_mmap,
  36. .poll = vb2_fop_poll,
  37. };
  38. /****************************
  39. * videoDevice ioctl ops *
  40. ****************************/
  41. static int vidioc_querycap_callback( struct file* file, void* fh, struct v4l2_capability* cap );
  42. static int vidioc_enum_fmt_vid_cap_callback( struct file* file, void* fh, struct v4l2_fmtdesc* f );
  43. static int vidioc_g_fmt_vid_cap_callback( struct file* file, void* fh, struct v4l2_format* f );
  44. static int vidioc_s_fmt_vid_cap_callback( struct file* file, void* fh, struct v4l2_format* f );
  45. static int vidioc_try_fmt_vid_cap_callback( struct file* file, void* fh, struct v4l2_format* f );
  46. static int vidioc_enum_input_callback( struct file* file, void* fh, struct v4l2_input* inp );
  47. static int vidioc_g_input_callback( struct file* file, void* fh, unsigned int* i );
  48. static int vidioc_s_input_callback( struct file* file, void* fh, unsigned int i );
  49. static int vidioc_querystd_callback( struct file* file, void* fh, v4l2_std_id* argp );
  50. static int vidioc_g_std_callback( struct file* file, void* fh, v4l2_std_id* argp );
  51. static int vidioc_s_std_callback( struct file* file, void* fh, v4l2_std_id argp );
  52. static int vidioc_enum_framesizes_callback( struct file* file, void* fh, struct v4l2_frmsizeenum* fsize );
  53. static int vidioc_enum_frameintervals_callback( struct file* file, void* fh, struct v4l2_frmivalenum* fival );
  54. //full list in include/media/v4l2-ioctl.h
  55. static const struct v4l2_ioctl_ops videoDeviceIoctlOps = {
  56. .vidioc_querycap = vidioc_querycap_callback,
  57. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap_callback,
  58. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap_callback,
  59. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap_callback,
  60. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap_callback,
  61. .vidioc_enum_input = vidioc_enum_input_callback,
  62. .vidioc_g_input = vidioc_g_input_callback,
  63. .vidioc_s_input = vidioc_s_input_callback,
  64. .vidioc_querystd = vidioc_querystd_callback,
  65. .vidioc_g_std = vidioc_g_std_callback,
  66. .vidioc_s_std = vidioc_s_std_callback,
  67. .vidioc_enum_framesizes = vidioc_enum_framesizes_callback,
  68. .vidioc_enum_frameintervals = vidioc_enum_frameintervals_callback,
  69. //standart helpers
  70. .vidioc_reqbufs = vb2_ioctl_reqbufs,
  71. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  72. .vidioc_querybuf = vb2_ioctl_querybuf,
  73. .vidioc_qbuf = vb2_ioctl_qbuf,
  74. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  75. .vidioc_expbuf = vb2_ioctl_expbuf,
  76. .vidioc_streamon = vb2_ioctl_streamon,
  77. .vidioc_streamoff = vb2_ioctl_streamoff,
  78. };
  79. /****************************
  80. * USB *
  81. ****************************/
  82. #define R5U870_DEVICE_UVC(VID, PID, DINFO) \
  83. .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, \
  84. .idVendor = (VID), \
  85. .idProduct = (PID), \
  86. .bInterfaceClass = USB_CLASS_VIDEO, \
  87. .bInterfaceSubClass = 1, \
  88. .bInterfaceProtocol = 0, \
  89. .driver_info = (DINFO)
  90. static const struct usb_device_id id_table[] = {
  91. { USB_DEVICE(0x05CA, 0x1830), .driver_info = R5U870_DI_VGP_VCC2_SZ },
  92. { USB_DEVICE(0x05CA, 0x1832), .driver_info = R5U870_DI_VGP_VCC3 },
  93. { USB_DEVICE(0x05CA, 0x1833), .driver_info = R5U870_DI_VGP_VCC2_AR1 },
  94. { USB_DEVICE(0x05CA, 0x1834), .driver_info = R5U870_DI_VGP_VCC2_AR2 },
  95. { USB_DEVICE(0x05CA, 0x1870), .driver_info = R5U870_DI_HP_PAVWC_WDM },
  96. { R5U870_DEVICE_UVC(0x05CA, 0x1810, R5U870_DI_HP_PAVWC_UVC) },
  97. { R5U870_DEVICE_UVC(0x05CA, 0x1812, R5U870_DI_HP_PAVWC_UVC_NOFW) },
  98. { R5U870_DEVICE_UVC(0x05CA, 0x1835, R5U870_DI_VGP_VCC5) },
  99. { R5U870_DEVICE_UVC(0x05CA, 0x1836, R5U870_DI_VGP_VCC4) },
  100. { R5U870_DEVICE_UVC(0x05CA, 0x1837, R5U870_DI_VGP_VCC4_VFLIP) },
  101. /* 0x1838 does not appear to have ever been released */
  102. { R5U870_DEVICE_UVC(0x05CA, 0x1839, R5U870_DI_VGP_VCC6) },
  103. { R5U870_DEVICE_UVC(0x05CA, 0x183a, R5U870_DI_VGP_VCC7) },
  104. { R5U870_DEVICE_UVC(0x05CA, 0x183b, R5U870_DI_VGP_VCC8) },
  105. { R5U870_DEVICE_UVC(0x05CA, 0x183e, R5U870_DI_VGP_VCC9) },
  106. { R5U870_DEVICE_UVC(0x05CA, 0x1841, R5U870_DI_FUJITSU) },
  107. { },
  108. };
  109. static int usbDeviceProbe_callback( struct usb_interface* usbInterface, const struct usb_device_id* usbDeviceId );
  110. static void usbDeviceDisconnect_callback( struct usb_interface* usbInterface );
  111. static struct usb_driver usbDriver_s = {
  112. .name = KBUILD_MODNAME,
  113. .id_table = id_table,
  114. .probe = usbDeviceProbe_callback,
  115. .disconnect = usbDeviceDisconnect_callback,
  116. };