shared.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #pragma once
  2. #include <linux/ctype.h>
  3. #include <linux/device.h>
  4. #include <linux/dmi.h>
  5. #include <linux/module.h>
  6. #include <linux/mutex.h>
  7. #include <linux/usb.h>
  8. #include <linux/slab.h>
  9. #include <linux/version.h>
  10. #include <linux/workqueue.h>
  11. #include <media/v4l2-common.h>
  12. #include <media/v4l2-ctrls.h>
  13. #include <media/v4l2-device.h>
  14. #include <media/v4l2-ioctl.h>
  15. #include <media/videobuf2-v4l2.h>
  16. /****************************
  17. * COMPAT *
  18. ****************************/
  19. #if LINUX_VERSION_CODE < KERNEL_VERSION( 5, 7, 0 )
  20. #define VFL_TYPE_VIDEO VFL_TYPE_GRABBER
  21. #endif
  22. /****************************
  23. * DEFINE *
  24. ****************************/
  25. #define VIDEOBUF_QUEUE_MIN_BUF_NEED 2
  26. #define URBSTREAM_URB_COUNT 8
  27. #define URBSTREAM_URB_PACKETS_COUNT 32
  28. /****************************
  29. * ENUM *
  30. ****************************/
  31. enum {
  32. R5U870_DI_INVALID,
  33. R5U870_DI_VGP_VCC2_SZ,
  34. R5U870_DI_VGP_VCC3,
  35. R5U870_DI_VGP_VCC2_AR1,
  36. R5U870_DI_VGP_VCC2_AR2,
  37. R5U870_DI_VGP_VCC5,
  38. R5U870_DI_VGP_VCC4,
  39. R5U870_DI_VGP_VCC4_VFLIP,
  40. R5U870_DI_VGP_VCC6,
  41. R5U870_DI_VGP_VCC7,
  42. R5U870_DI_VGP_VCC8,
  43. R5U870_DI_VGP_VCC9,
  44. R5U870_DI_HP_WEBCAM1K,
  45. R5U870_DI_HP_PAVWC_WDM,
  46. R5U870_DI_HP_PAVWC_UVC,
  47. R5U870_DI_HP_PAVWC_UVC_NOFW,
  48. R5U870_DI_GENERIC_UVC,
  49. R5U870_DI_FUJITSU,
  50. };
  51. /****************************
  52. * STRUCT *
  53. ****************************/
  54. struct urb_capsule {
  55. struct work_struct workitem;
  56. struct urb* urbp;
  57. void* driverInstanceThis;
  58. };
  59. //struct vb2_buffer must be first in struct
  60. struct videobuffer_capsule {
  61. struct vb2_buffer videobuffer;
  62. struct list_head listItem;
  63. };
  64. struct r5u870_resolution {
  65. int width; //rw_width
  66. int height; //rw_height
  67. int requiredBandwidth; //rw_reqbw;
  68. int rw_interval;
  69. int resolutionId; //rw_frameidx;
  70. };
  71. struct r5u870_pixelformat {
  72. char description[32];
  73. unsigned int pixelformat;
  74. unsigned int flags;
  75. int formatId; //rp_formatidx
  76. const struct r5u870_resolution* resolutionTable; //rp_restbl
  77. int resolutionTableAlloc; //rp_restbl_alloc;
  78. };
  79. struct r5u870_model {
  80. char* modelName; //rm_name;
  81. const char* ucodeFile; //rm_ucode_file;
  82. u16 ucodeVersion; //rm_ucode_version;
  83. const int* controls_wdm; //rm_wdm_ctrlids
  84. const struct r5u870_pixelformat* pixelformats; //rm_pixfmts;
  85. int pixelformatsCount; //rm_npixfmts
  86. unsigned int isUvc : 1; //rm_uvc : 1;
  87. unsigned int rm_no_ctrl_reload : 1;
  88. unsigned int rm_no_first_auto_suppress : 1;
  89. };
  90. struct driverInstance{
  91. struct usb_interface* usbInterface; //ud_intf
  92. struct usb_device* usbDevice; //ud_dev
  93. struct usb_driver* usbDeviceDriver; //um_usbdrv ?
  94. struct device* dev;
  95. struct video_device videoDevice;
  96. struct v4l2_device v4l2Device;
  97. struct vb2_queue videobuf2Queue;
  98. struct v4l2_ctrl_handler webcamControlHandler;
  99. //this mutex used in videobuf2Queue and videoDevice
  100. struct mutex lock;
  101. struct list_head buflist;
  102. spinlock_t buflistSpinlock;
  103. atomic_t buflistIsDisabled;
  104. const struct r5u870_model* webcamModel; //vh_model
  105. const struct r5u870_pixelformat* webcamFormats; //ud_fmt_array; vh_pixfmts;
  106. int webcamFormatsCount; //ud_fmt_array_len; vh_npixfmts;
  107. struct v4l2_pix_format webcamCurrentPixelformat; //ud_format
  108. const struct r5u870_pixelformat* webcamCurrentFormat; //vh_fmt;
  109. const struct r5u870_resolution* webcamCurrentResolution; //vh_res;
  110. atomic_t webcamControlRegisterIsEnabled; //vh_ctrl_reg_enable : 1;
  111. atomic_t webcamIsCaptuing; //ud_capturing : 1,
  112. atomic_t usbDeviceIsDisconnected; //ud_disconnected : 1,
  113. unsigned char vh_ctrl_sync : 1;
  114. unsigned char vh_configured : 1;
  115. int vh_firstframe;
  116. int vh_emptypkts;
  117. int vh_frame_accum;
  118. int vh_framebuf_offset;
  119. int vh_ctrl_ifnum;
  120. int urbstreamEndpoint; //vh_iso_ep, us_endpoint
  121. int urbstreamInterfaceNumber; //vh_iso_ifnum
  122. atomic_t urbstreamIsStreaming; //us_streaming;
  123. int urbstreamMinPacketSize; //vh_iso_minpacket;
  124. int usbCurrentAltsetting; //vh_act_altsetting
  125. struct workqueue_struct* urbstreamWorkqueue;
  126. struct urb_capsule urbstreamUrbs[URBSTREAM_URB_COUNT];
  127. int ( *webcamApplyFormat )( struct driverInstance* );//vh_set_fmt
  128. int ( *vh_cap_stop )( struct driverInstance* );
  129. int ( *vh_decide_pkt )( struct driverInstance*, int st, int len, const u8* pktdata, int* start );
  130. struct list_head claimedInterfacesList;//ud_interface_list;
  131. /*
  132. //Auto settings
  133. int vh_auto_wb;
  134. int vh_aec;
  135. int vh_agc;
  136. */
  137. };
  138. /****************************
  139. * FUNCTIONS *
  140. ****************************/
  141. void webcamCaptureStop( struct driverInstance* );