hdpvr.h 6.9 KB

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