hdpvr.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Hauppauge HD PVR USB driver
  4. *
  5. * Copyright (C) 2008 Janne Grunau ([email protected])
  6. */
  7. #include <linux/usb.h>
  8. #include <linux/i2c.h>
  9. #include <linux/mutex.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/videodev2.h>
  12. #include <media/v4l2-device.h>
  13. #include <media/v4l2-ctrls.h>
  14. #include <media/i2c/ir-kbd-i2c.h>
  15. #define HDPVR_MAX 8
  16. #define HDPVR_I2C_MAX_SIZE 128
  17. /* Define these values to match your devices */
  18. #define HD_PVR_VENDOR_ID 0x2040
  19. #define HD_PVR_PRODUCT_ID 0x4900
  20. #define HD_PVR_PRODUCT_ID1 0x4901
  21. #define HD_PVR_PRODUCT_ID2 0x4902
  22. #define HD_PVR_PRODUCT_ID4 0x4903
  23. #define HD_PVR_PRODUCT_ID3 0x4982
  24. #define UNSET (-1U)
  25. #define NUM_BUFFERS 64
  26. #define HDPVR_FIRMWARE_VERSION 0x08
  27. #define HDPVR_FIRMWARE_VERSION_AC3 0x0d
  28. #define HDPVR_FIRMWARE_VERSION_0X12 0x12
  29. #define HDPVR_FIRMWARE_VERSION_0X15 0x15
  30. #define HDPVR_FIRMWARE_VERSION_0X1E 0x1e
  31. /* #define HDPVR_DEBUG */
  32. extern int hdpvr_debug;
  33. #define MSG_INFO 1
  34. #define MSG_BUFFER 2
  35. struct hdpvr_options {
  36. u8 video_std;
  37. u8 video_input;
  38. u8 audio_input;
  39. u8 bitrate; /* in 100kbps */
  40. u8 peak_bitrate; /* in 100kbps */
  41. u8 bitrate_mode;
  42. u8 gop_mode;
  43. enum v4l2_mpeg_audio_encoding audio_codec;
  44. u8 brightness;
  45. u8 contrast;
  46. u8 hue;
  47. u8 saturation;
  48. u8 sharpness;
  49. };
  50. /* Structure to hold all of our device specific stuff */
  51. struct hdpvr_device {
  52. /* the v4l device for this device */
  53. struct video_device video_dev;
  54. /* the control handler for this device */
  55. struct v4l2_ctrl_handler hdl;
  56. /* the usb device for this device */
  57. struct usb_device *udev;
  58. /* v4l2-device unused */
  59. struct v4l2_device v4l2_dev;
  60. struct { /* video mode/bitrate control cluster */
  61. struct v4l2_ctrl *video_mode;
  62. struct v4l2_ctrl *video_bitrate;
  63. struct v4l2_ctrl *video_bitrate_peak;
  64. };
  65. /* v4l2 format */
  66. uint width, height;
  67. /* the max packet size of the bulk endpoint */
  68. size_t bulk_in_size;
  69. /* the address of the bulk in endpoint */
  70. __u8 bulk_in_endpointAddr;
  71. /* holds the current device status */
  72. __u8 status;
  73. /* holds the current set options */
  74. struct hdpvr_options options;
  75. v4l2_std_id cur_std;
  76. struct v4l2_dv_timings cur_dv_timings;
  77. uint flags;
  78. /* synchronize I/O */
  79. struct mutex io_mutex;
  80. /* available buffers */
  81. struct list_head free_buff_list;
  82. /* in progress buffers */
  83. struct list_head rec_buff_list;
  84. /* waitqueue for buffers */
  85. wait_queue_head_t wait_buffer;
  86. /* waitqueue for data */
  87. wait_queue_head_t wait_data;
  88. /**/
  89. struct work_struct worker;
  90. /* current stream owner */
  91. struct v4l2_fh *owner;
  92. /* I2C adapter */
  93. struct i2c_adapter i2c_adapter;
  94. /* I2C lock */
  95. struct mutex i2c_mutex;
  96. /* I2C message buffer space */
  97. char i2c_buf[HDPVR_I2C_MAX_SIZE];
  98. /* For passing data to ir-kbd-i2c */
  99. struct IR_i2c_init_data ir_i2c_init_data;
  100. /* usb control transfer buffer and lock */
  101. struct mutex usbc_mutex;
  102. u8 *usbc_buf;
  103. u8 fw_ver;
  104. };
  105. static inline struct hdpvr_device *to_hdpvr_dev(struct v4l2_device *v4l2_dev)
  106. {
  107. return container_of(v4l2_dev, struct hdpvr_device, v4l2_dev);
  108. }
  109. /* buffer one bulk urb of data */
  110. struct hdpvr_buffer {
  111. struct list_head buff_list;
  112. struct urb *urb;
  113. struct hdpvr_device *dev;
  114. uint pos;
  115. __u8 status;
  116. };
  117. /* */
  118. struct hdpvr_video_info {
  119. u16 width;
  120. u16 height;
  121. u8 fps;
  122. bool valid;
  123. };
  124. enum {
  125. STATUS_UNINITIALIZED = 0,
  126. STATUS_IDLE,
  127. STATUS_STARTING,
  128. STATUS_SHUTTING_DOWN,
  129. STATUS_STREAMING,
  130. STATUS_ERROR,
  131. STATUS_DISCONNECTED,
  132. };
  133. enum {
  134. HDPVR_FLAG_AC3_CAP = 1,
  135. };
  136. enum {
  137. BUFSTAT_UNINITIALIZED = 0,
  138. BUFSTAT_AVAILABLE,
  139. BUFSTAT_INPROGRESS,
  140. BUFSTAT_READY,
  141. };
  142. #define CTRL_START_STREAMING_VALUE 0x0700
  143. #define CTRL_STOP_STREAMING_VALUE 0x0800
  144. #define CTRL_BITRATE_VALUE 0x1000
  145. #define CTRL_BITRATE_MODE_VALUE 0x1200
  146. #define CTRL_GOP_MODE_VALUE 0x1300
  147. #define CTRL_VIDEO_INPUT_VALUE 0x1500
  148. #define CTRL_VIDEO_STD_TYPE 0x1700
  149. #define CTRL_AUDIO_INPUT_VALUE 0x2500
  150. #define CTRL_BRIGHTNESS 0x2900
  151. #define CTRL_CONTRAST 0x2a00
  152. #define CTRL_HUE 0x2b00
  153. #define CTRL_SATURATION 0x2c00
  154. #define CTRL_SHARPNESS 0x2d00
  155. #define CTRL_LOW_PASS_FILTER_VALUE 0x3100
  156. #define CTRL_DEFAULT_INDEX 0x0003
  157. /* :0 s 38 01 1000 0003 0004 4 = 0a00ca00
  158. * BITRATE SETTING
  159. * 1st and 2nd byte (little endian): average bitrate in 100 000 bit/s
  160. * min: 1 mbit/s, max: 13.5 mbit/s
  161. * 3rd and 4th byte (little endian): peak bitrate in 100 000 bit/s
  162. * min: average + 100kbit/s,
  163. * max: 20.2 mbit/s
  164. */
  165. /* :0 s 38 01 1200 0003 0001 1 = 02
  166. * BIT RATE MODE
  167. * constant = 1, variable (peak) = 2, variable (average) = 3
  168. */
  169. /* :0 s 38 01 1300 0003 0001 1 = 03
  170. * GOP MODE (2 bit)
  171. * low bit 0/1: advanced/simple GOP
  172. * high bit 0/1: IDR(4/32/128) / no IDR (4/32/0)
  173. */
  174. /* :0 s 38 01 1700 0003 0001 1 = 00
  175. * VIDEO STANDARD or FREQUENCY 0 = 60hz, 1 = 50hz
  176. */
  177. /* :0 s 38 01 3100 0003 0004 4 = 03030000
  178. * FILTER CONTROL
  179. * 1st byte luma low pass filter strength,
  180. * 2nd byte chroma low pass filter strength,
  181. * 3rd byte MF enable chroma, min=0, max=1
  182. * 4th byte n
  183. */
  184. /* :0 s 38 b9 0001 0000 0000 0 */
  185. /* :0 s 38 d3 0000 0000 0001 1 = 00 */
  186. /* ret = usb_control_msg(dev->udev, */
  187. /* usb_sndctrlpipe(dev->udev, 0), */
  188. /* 0xd3, 0x38, */
  189. /* 0, 0, */
  190. /* "\0", 1, */
  191. /* 1000); */
  192. /* info("control request returned %d", ret); */
  193. /* msleep(5000); */
  194. /* :0 s b8 81 1400 0003 0005 5 <
  195. * :0 0 5 = d0024002 19
  196. * QUERY FRAME SIZE AND RATE
  197. * 1st and 2nd byte (little endian): horizontal resolution
  198. * 3rd and 4th byte (little endian): vertical resolution
  199. * 5th byte: frame rate
  200. */
  201. /* :0 s b8 81 1800 0003 0003 3 <
  202. * :0 0 3 = 030104
  203. * QUERY SIGNAL AND DETECTED LINES, maybe INPUT
  204. */
  205. enum hdpvr_video_std {
  206. HDPVR_60HZ = 0,
  207. HDPVR_50HZ,
  208. };
  209. enum hdpvr_video_input {
  210. HDPVR_COMPONENT = 0,
  211. HDPVR_SVIDEO,
  212. HDPVR_COMPOSITE,
  213. HDPVR_VIDEO_INPUTS
  214. };
  215. enum hdpvr_audio_inputs {
  216. HDPVR_RCA_BACK = 0,
  217. HDPVR_RCA_FRONT,
  218. HDPVR_SPDIF,
  219. HDPVR_AUDIO_INPUTS
  220. };
  221. enum hdpvr_bitrate_mode {
  222. HDPVR_CONSTANT = 1,
  223. HDPVR_VARIABLE_PEAK,
  224. HDPVR_VARIABLE_AVERAGE,
  225. };
  226. enum hdpvr_gop_mode {
  227. HDPVR_ADVANCED_IDR_GOP = 0,
  228. HDPVR_SIMPLE_IDR_GOP,
  229. HDPVR_ADVANCED_NOIDR_GOP,
  230. HDPVR_SIMPLE_NOIDR_GOP,
  231. };
  232. void hdpvr_delete(struct hdpvr_device *dev);
  233. /*========================================================================*/
  234. /* hardware control functions */
  235. int hdpvr_set_options(struct hdpvr_device *dev);
  236. int hdpvr_set_bitrate(struct hdpvr_device *dev);
  237. int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
  238. enum v4l2_mpeg_audio_encoding codec);
  239. int hdpvr_config_call(struct hdpvr_device *dev, uint value,
  240. unsigned char valbuf);
  241. int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vid_info);
  242. /* :0 s b8 81 1800 0003 0003 3 < */
  243. /* :0 0 3 = 0301ff */
  244. int get_input_lines_info(struct hdpvr_device *dev);
  245. /*========================================================================*/
  246. /* v4l2 registration */
  247. int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
  248. int devnumber);
  249. int hdpvr_cancel_queue(struct hdpvr_device *dev);
  250. /*========================================================================*/
  251. /* i2c adapter registration */
  252. int hdpvr_register_i2c_adapter(struct hdpvr_device *dev);
  253. struct i2c_client *hdpvr_register_ir_i2c(struct hdpvr_device *dev);
  254. /*========================================================================*/
  255. /* buffer management */
  256. int hdpvr_free_buffers(struct hdpvr_device *dev);
  257. int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count);