pd-common.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #ifndef PD_COMMON_H
  2. #define PD_COMMON_H
  3. #include <linux/fs.h>
  4. #include <linux/wait.h>
  5. #include <linux/list.h>
  6. #include <linux/videodev2.h>
  7. #include <linux/semaphore.h>
  8. #include <linux/usb.h>
  9. #include <linux/poll.h>
  10. #include <media/videobuf-vmalloc.h>
  11. #include <media/v4l2-device.h>
  12. #include <media/v4l2-ctrls.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 (45000000U)
  33. #define TUNER_FREQ_MAX (862000000U)
  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. struct v4l2_ctrl_handler ctrl_handler;
  57. /* the working context */
  58. struct running_context context;
  59. /* for data copy */
  60. int field_count;
  61. char *dst;
  62. int lines_copied;
  63. int prev_left;
  64. int lines_per_field;
  65. int lines_size;
  66. /* for communication */
  67. u8 endpoint_addr;
  68. struct urb *urb_array[SBUF_NUM];
  69. struct vbi_data *vbi;
  70. struct poseidon *pd;
  71. struct front_face *front;
  72. int is_streaming;
  73. int users;
  74. /* for bubble handler */
  75. struct work_struct bubble_work;
  76. };
  77. enum pcm_stream_state {
  78. STREAM_OFF,
  79. STREAM_ON,
  80. STREAM_SUSPEND,
  81. };
  82. #define AUDIO_BUFS (3)
  83. #define CAPTURE_STREAM_EN 1
  84. struct poseidon_audio {
  85. struct urb *urb_array[AUDIO_BUFS];
  86. unsigned int copied_position;
  87. struct snd_pcm_substream *capture_pcm_substream;
  88. unsigned int rcv_position;
  89. struct snd_card *card;
  90. int card_close;
  91. int users;
  92. int pm_state;
  93. enum pcm_stream_state capture_stream;
  94. };
  95. struct radio_data {
  96. __u32 fm_freq;
  97. unsigned int is_radio_streaming;
  98. int pre_emphasis;
  99. struct video_device fm_dev;
  100. struct v4l2_ctrl_handler ctrl_handler;
  101. };
  102. #define DVB_SBUF_NUM 4
  103. #define DVB_URB_BUF_SIZE 0x2000
  104. struct pd_dvb_adapter {
  105. struct dvb_adapter dvb_adap;
  106. struct dvb_frontend dvb_fe;
  107. struct dmxdev dmxdev;
  108. struct dvb_demux demux;
  109. atomic_t users;
  110. atomic_t active_feed;
  111. /* data transfer */
  112. s32 is_streaming;
  113. struct urb *urb_array[DVB_SBUF_NUM];
  114. struct poseidon *pd_device;
  115. u8 ep_addr;
  116. u8 reserved[3];
  117. /* data for power resume*/
  118. struct dtv_frontend_properties fe_param;
  119. /* for channel scanning */
  120. int prev_freq;
  121. int bandwidth;
  122. unsigned long last_jiffies;
  123. };
  124. struct front_face {
  125. /* use this field to distinguish VIDEO and VBI */
  126. enum v4l2_buf_type type;
  127. /* for host */
  128. struct videobuf_queue q;
  129. /* the bridge for host and device */
  130. struct videobuf_buffer *curr_frame;
  131. /* for device */
  132. spinlock_t queue_lock;
  133. struct list_head active;
  134. struct poseidon *pd;
  135. };
  136. struct poseidon {
  137. struct list_head device_list;
  138. struct mutex lock;
  139. struct kref kref;
  140. /* for V4L2 */
  141. struct v4l2_device v4l2_dev;
  142. /* hardware info */
  143. struct usb_device *udev;
  144. struct usb_interface *interface;
  145. int cur_transfer_mode;
  146. struct video_data video_data; /* video */
  147. struct vbi_data vbi_data; /* vbi */
  148. struct poseidon_audio audio; /* audio (alsa) */
  149. struct radio_data radio_data; /* FM */
  150. struct pd_dvb_adapter dvb_data; /* DVB */
  151. u32 state;
  152. struct file *file_for_stream; /* the active stream*/
  153. #ifdef CONFIG_PM
  154. int (*pm_suspend)(struct poseidon *);
  155. int (*pm_resume)(struct poseidon *);
  156. pm_message_t msg;
  157. struct work_struct pm_work;
  158. u8 portnum;
  159. #endif
  160. };
  161. struct poseidon_format {
  162. char *name;
  163. int fourcc; /* video4linux 2 */
  164. int depth; /* bit/pixel */
  165. int flags;
  166. };
  167. struct poseidon_tvnorm {
  168. v4l2_std_id v4l2_id;
  169. char name[12];
  170. u32 tlg_tvnorm;
  171. };
  172. /* video */
  173. int pd_video_init(struct poseidon *);
  174. void pd_video_exit(struct poseidon *);
  175. int stop_all_video_stream(struct poseidon *);
  176. /* alsa audio */
  177. int poseidon_audio_init(struct poseidon *);
  178. int poseidon_audio_free(struct poseidon *);
  179. #ifdef CONFIG_PM
  180. int pm_alsa_suspend(struct poseidon *);
  181. int pm_alsa_resume(struct poseidon *);
  182. #endif
  183. /* dvb */
  184. int pd_dvb_usb_device_init(struct poseidon *);
  185. void pd_dvb_usb_device_exit(struct poseidon *);
  186. void pd_dvb_usb_device_cleanup(struct poseidon *);
  187. int pd_dvb_get_adapter_num(struct pd_dvb_adapter *);
  188. void dvb_stop_streaming(struct pd_dvb_adapter *);
  189. /* FM */
  190. int poseidon_fm_init(struct poseidon *);
  191. int poseidon_fm_exit(struct poseidon *);
  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. extern int debug_mode;
  205. void set_debug_mode(struct video_device *vfd, int debug_mode);
  206. #ifdef CONFIG_PM
  207. #define in_hibernation(pd) (pd->msg.event == PM_EVENT_FREEZE)
  208. #else
  209. #define in_hibernation(pd) (0)
  210. #endif
  211. #define get_pm_count(p) (atomic_read(&(p)->interface->pm_usage_cnt))
  212. #define log(a, ...) printk(KERN_DEBUG "\t[ %s : %.3d ] "a"\n", \
  213. __func__, __LINE__, ## __VA_ARGS__)
  214. /* for power management */
  215. #define logpm(pd) do {\
  216. if (debug_mode & 0x10)\
  217. log();\
  218. } while (0)
  219. #define logs(f) do { \
  220. if ((debug_mode & 0x4) && \
  221. (f)->type == V4L2_BUF_TYPE_VBI_CAPTURE) \
  222. log("type : VBI");\
  223. \
  224. if ((debug_mode & 0x8) && \
  225. (f)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) \
  226. log("type : VIDEO");\
  227. } while (0)
  228. #endif