/drivers/media/video/tlg2300/pd-common.h

https://bitbucket.org/ndreys/linux-sunxi · C++ Header · 282 lines · 203 code · 53 blank · 26 comment · 10 complexity · 8d30752a378429bea829b0e9619a3aad MD5 · raw file

  1. #ifndef PD_COMMON_H
  2. #define PD_COMMON_H
  3. #include <linux/version.h>
  4. #include <linux/fs.h>
  5. #include <linux/wait.h>
  6. #include <linux/list.h>
  7. #include <linux/videodev2.h>
  8. #include <linux/semaphore.h>
  9. #include <linux/usb.h>
  10. #include <linux/poll.h>
  11. #include <media/videobuf-vmalloc.h>
  12. #include <media/v4l2-device.h>
  13. #include "dvb_frontend.h"
  14. #include "dvbdev.h"
  15. #include "dvb_demux.h"
  16. #include "dmxdev.h"
  17. #define SBUF_NUM 8
  18. #define MAX_BUFFER_NUM 6
  19. #define PK_PER_URB 32
  20. #define ISO_PKT_SIZE 3072
  21. #define POSEIDON_STATE_NONE (0x0000)
  22. #define POSEIDON_STATE_ANALOG (0x0001)
  23. #define POSEIDON_STATE_FM (0x0002)
  24. #define POSEIDON_STATE_DVBT (0x0004)
  25. #define POSEIDON_STATE_VBI (0x0008)
  26. #define POSEIDON_STATE_DISCONNECT (0x0080)
  27. #define PM_SUSPEND_DELAY 3
  28. #define V4L_PAL_VBI_LINES 18
  29. #define V4L_NTSC_VBI_LINES 12
  30. #define V4L_PAL_VBI_FRAMESIZE (V4L_PAL_VBI_LINES * 1440 * 2)
  31. #define V4L_NTSC_VBI_FRAMESIZE (V4L_NTSC_VBI_LINES * 1440 * 2)
  32. #define TUNER_FREQ_MIN (45000000)
  33. #define TUNER_FREQ_MAX (862000000)
  34. struct vbi_data {
  35. struct video_device *v_dev;
  36. struct video_data *video;
  37. struct front_face *front;
  38. unsigned int copied;
  39. unsigned int vbi_size; /* the whole size of two fields */
  40. int users;
  41. };
  42. /*
  43. * This is the running context of the video, it is useful for
  44. * resume()
  45. */
  46. struct running_context {
  47. u32 freq; /* VIDIOC_S_FREQUENCY */
  48. int audio_idx; /* VIDIOC_S_TUNER */
  49. v4l2_std_id tvnormid; /* VIDIOC_S_STD */
  50. int sig_index; /* VIDIOC_S_INPUT */
  51. struct v4l2_pix_format pix; /* VIDIOC_S_FMT */
  52. };
  53. struct video_data {
  54. /* v4l2 video device */
  55. struct video_device *v_dev;
  56. /* the working context */
  57. struct running_context context;
  58. /* for data copy */
  59. int field_count;
  60. char *dst;
  61. int lines_copied;
  62. int prev_left;
  63. int lines_per_field;
  64. int lines_size;
  65. /* for communication */
  66. u8 endpoint_addr;
  67. struct urb *urb_array[SBUF_NUM];
  68. struct vbi_data *vbi;
  69. struct poseidon *pd;
  70. struct front_face *front;
  71. int is_streaming;
  72. int users;
  73. /* for bubble handler */
  74. struct work_struct bubble_work;
  75. };
  76. enum pcm_stream_state {
  77. STREAM_OFF,
  78. STREAM_ON,
  79. STREAM_SUSPEND,
  80. };
  81. #define AUDIO_BUFS (3)
  82. #define CAPTURE_STREAM_EN 1
  83. struct poseidon_audio {
  84. struct urb *urb_array[AUDIO_BUFS];
  85. unsigned int copied_position;
  86. struct snd_pcm_substream *capture_pcm_substream;
  87. unsigned int rcv_position;
  88. struct snd_card *card;
  89. int card_close;
  90. int users;
  91. int pm_state;
  92. enum pcm_stream_state capture_stream;
  93. };
  94. struct radio_data {
  95. __u32 fm_freq;
  96. int users;
  97. unsigned int is_radio_streaming;
  98. int pre_emphasis;
  99. struct video_device *fm_dev;
  100. };
  101. #define DVB_SBUF_NUM 4
  102. #define DVB_URB_BUF_SIZE 0x2000
  103. struct pd_dvb_adapter {
  104. struct dvb_adapter dvb_adap;
  105. struct dvb_frontend dvb_fe;
  106. struct dmxdev dmxdev;
  107. struct dvb_demux demux;
  108. atomic_t users;
  109. atomic_t active_feed;
  110. /* data transfer */
  111. s32 is_streaming;
  112. struct urb *urb_array[DVB_SBUF_NUM];
  113. struct poseidon *pd_device;
  114. u8 ep_addr;
  115. u8 reserved[3];
  116. /* data for power resume*/
  117. struct dvb_frontend_parameters fe_param;
  118. /* for channel scanning */
  119. int prev_freq;
  120. int bandwidth;
  121. unsigned long last_jiffies;
  122. };
  123. struct front_face {
  124. /* use this field to distinguish VIDEO and VBI */
  125. enum v4l2_buf_type type;
  126. /* for host */
  127. struct videobuf_queue q;
  128. /* the bridge for host and device */
  129. struct videobuf_buffer *curr_frame;
  130. /* for device */
  131. spinlock_t queue_lock;
  132. struct list_head active;
  133. struct poseidon *pd;
  134. };
  135. struct poseidon {
  136. struct list_head device_list;
  137. struct mutex lock;
  138. struct kref kref;
  139. /* for V4L2 */
  140. struct v4l2_device v4l2_dev;
  141. /* hardware info */
  142. struct usb_device *udev;
  143. struct usb_interface *interface;
  144. int cur_transfer_mode;
  145. struct video_data video_data; /* video */
  146. struct vbi_data vbi_data; /* vbi */
  147. struct poseidon_audio audio; /* audio (alsa) */
  148. struct radio_data radio_data; /* FM */
  149. struct pd_dvb_adapter dvb_data; /* DVB */
  150. u32 state;
  151. struct file *file_for_stream; /* the active stream*/
  152. #ifdef CONFIG_PM
  153. int (*pm_suspend)(struct poseidon *);
  154. int (*pm_resume)(struct poseidon *);
  155. pm_message_t msg;
  156. struct work_struct pm_work;
  157. u8 portnum;
  158. #endif
  159. };
  160. struct poseidon_format {
  161. char *name;
  162. int fourcc; /* video4linux 2 */
  163. int depth; /* bit/pixel */
  164. int flags;
  165. };
  166. struct poseidon_tvnorm {
  167. v4l2_std_id v4l2_id;
  168. char name[12];
  169. u32 tlg_tvnorm;
  170. };
  171. /* video */
  172. int pd_video_init(struct poseidon *);
  173. void pd_video_exit(struct poseidon *);
  174. int stop_all_video_stream(struct poseidon *);
  175. /* alsa audio */
  176. int poseidon_audio_init(struct poseidon *);
  177. int poseidon_audio_free(struct poseidon *);
  178. #ifdef CONFIG_PM
  179. int pm_alsa_suspend(struct poseidon *);
  180. int pm_alsa_resume(struct poseidon *);
  181. #endif
  182. /* dvb */
  183. int pd_dvb_usb_device_init(struct poseidon *);
  184. void pd_dvb_usb_device_exit(struct poseidon *);
  185. void pd_dvb_usb_device_cleanup(struct poseidon *);
  186. int pd_dvb_get_adapter_num(struct pd_dvb_adapter *);
  187. void dvb_stop_streaming(struct pd_dvb_adapter *);
  188. /* FM */
  189. int poseidon_fm_init(struct poseidon *);
  190. int poseidon_fm_exit(struct poseidon *);
  191. struct video_device *vdev_init(struct poseidon *, struct video_device *);
  192. /* vendor command ops */
  193. int send_set_req(struct poseidon*, u8, s32, s32*);
  194. int send_get_req(struct poseidon*, u8, s32, void*, s32*, s32);
  195. s32 set_tuner_mode(struct poseidon*, unsigned char);
  196. /* bulk urb alloc/free */
  197. int alloc_bulk_urbs_generic(struct urb **urb_array, int num,
  198. struct usb_device *udev, u8 ep_addr,
  199. int buf_size, gfp_t gfp_flags,
  200. usb_complete_t complete_fn, void *context);
  201. void free_all_urb_generic(struct urb **urb_array, int num);
  202. /* misc */
  203. void poseidon_delete(struct kref *kref);
  204. void destroy_video_device(struct video_device **v_dev);
  205. extern int debug_mode;
  206. void set_debug_mode(struct video_device *vfd, int debug_mode);
  207. #ifdef CONFIG_PM
  208. #define in_hibernation(pd) (pd->msg.event == PM_EVENT_FREEZE)
  209. #else
  210. #define in_hibernation(pd) (0)
  211. #endif
  212. #define get_pm_count(p) (atomic_read(&(p)->interface->pm_usage_cnt))
  213. #define log(a, ...) printk(KERN_DEBUG "\t[ %s : %.3d ] "a"\n", \
  214. __func__, __LINE__, ## __VA_ARGS__)
  215. /* for power management */
  216. #define logpm(pd) do {\
  217. if (debug_mode & 0x10)\
  218. log();\
  219. } while (0)
  220. #define logs(f) do { \
  221. if ((debug_mode & 0x4) && \
  222. (f)->type == V4L2_BUF_TYPE_VBI_CAPTURE) \
  223. log("type : VBI");\
  224. \
  225. if ((debug_mode & 0x8) && \
  226. (f)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) \
  227. log("type : VIDEO");\
  228. } while (0)
  229. #endif