pd-common.h 6.3 KB

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