4 #include <linux/version.h>
6 #include <linux/wait.h>
7 #include <linux/list.h>
8 #include <linux/videodev2.h>
9 #include <linux/semaphore.h>
10 #include <linux/usb.h>
11 #include <linux/poll.h>
12 #include <media/videobuf-vmalloc.h>
13 #include <media/v4l2-device.h>
15 #include "dvb_frontend.h"
17 #include "dvb_demux.h"
21 #define MAX_BUFFER_NUM 6
23 #define ISO_PKT_SIZE 3072
25 #define POSEIDON_STATE_NONE (0x0000)
26 #define POSEIDON_STATE_ANALOG (0x0001)
27 #define POSEIDON_STATE_FM (0x0002)
28 #define POSEIDON_STATE_DVBT (0x0004)
29 #define POSEIDON_STATE_VBI (0x0008)
30 #define POSEIDON_STATE_DISCONNECT (0x0080)
32 #define PM_SUSPEND_DELAY 3
34 #define V4L_PAL_VBI_LINES 18
35 #define V4L_NTSC_VBI_LINES 12
36 #define V4L_PAL_VBI_FRAMESIZE (V4L_PAL_VBI_LINES * 1440 * 2)
37 #define V4L_NTSC_VBI_FRAMESIZE (V4L_NTSC_VBI_LINES * 1440 * 2)
39 #define TUNER_FREQ_MIN (45000000)
40 #define TUNER_FREQ_MAX (862000000)
43 struct video_device
*v_dev
;
44 struct video_data
*video
;
45 struct front_face
*front
;
48 unsigned int vbi_size
; /* the whole size of two fields */
53 * This is the running context of the video, it is useful for
56 struct running_context
{
57 u32 freq
; /* VIDIOC_S_FREQUENCY */
58 int audio_idx
; /* VIDIOC_S_TUNER */
59 v4l2_std_id tvnormid
; /* VIDIOC_S_STD */
60 int sig_index
; /* VIDIOC_S_INPUT */
61 struct v4l2_pix_format pix
; /* VIDIOC_S_FMT */
65 /* v4l2 video device */
66 struct video_device
*v_dev
;
68 /* the working context */
69 struct running_context context
;
81 /* for communication */
83 struct urb
*urb_array
[SBUF_NUM
];
86 struct front_face
*front
;
91 /* for bubble handler */
92 struct work_struct bubble_work
;
95 enum pcm_stream_state
{
101 #define AUDIO_BUFS (3)
102 #define CAPTURE_STREAM_EN 1
103 struct poseidon_audio
{
104 struct urb
*urb_array
[AUDIO_BUFS
];
105 unsigned int copied_position
;
106 struct snd_pcm_substream
*capture_pcm_substream
;
108 unsigned int rcv_position
;
109 struct snd_card
*card
;
114 enum pcm_stream_state capture_stream
;
120 unsigned int is_radio_streaming
;
122 struct video_device
*fm_dev
;
125 #define DVB_SBUF_NUM 4
126 #define DVB_URB_BUF_SIZE 0x2000
127 struct pd_dvb_adapter
{
128 struct dvb_adapter dvb_adap
;
129 struct dvb_frontend dvb_fe
;
130 struct dmxdev dmxdev
;
131 struct dvb_demux demux
;
134 atomic_t active_feed
;
138 struct urb
*urb_array
[DVB_SBUF_NUM
];
139 struct poseidon
*pd_device
;
143 /* data for power resume*/
144 struct dvb_frontend_parameters fe_param
;
146 /* for channel scanning */
149 unsigned long last_jiffies
;
153 /* use this field to distinguish VIDEO and VBI */
154 enum v4l2_buf_type type
;
157 struct videobuf_queue q
;
159 /* the bridge for host and device */
160 struct videobuf_buffer
*curr_frame
;
163 spinlock_t queue_lock
;
164 struct list_head active
;
169 struct list_head device_list
;
175 struct v4l2_device v4l2_dev
;
178 struct usb_device
*udev
;
179 struct usb_interface
*interface
;
180 int cur_transfer_mode
;
182 struct video_data video_data
; /* video */
183 struct vbi_data vbi_data
; /* vbi */
184 struct poseidon_audio audio
; /* audio (alsa) */
185 struct radio_data radio_data
; /* FM */
186 struct pd_dvb_adapter dvb_data
; /* DVB */
189 struct file
*file_for_stream
; /* the active stream*/
192 int (*pm_suspend
)(struct poseidon
*);
193 int (*pm_resume
)(struct poseidon
*);
196 struct work_struct pm_work
;
201 struct poseidon_format
{
203 int fourcc
; /* video4linux 2 */
204 int depth
; /* bit/pixel */
208 struct poseidon_tvnorm
{
215 int pd_video_init(struct poseidon
*);
216 void pd_video_exit(struct poseidon
*);
217 int stop_all_video_stream(struct poseidon
*);
220 int poseidon_audio_init(struct poseidon
*);
221 int poseidon_audio_free(struct poseidon
*);
223 int pm_alsa_suspend(struct poseidon
*);
224 int pm_alsa_resume(struct poseidon
*);
228 int pd_dvb_usb_device_init(struct poseidon
*);
229 void pd_dvb_usb_device_exit(struct poseidon
*);
230 void pd_dvb_usb_device_cleanup(struct poseidon
*);
231 int pd_dvb_get_adapter_num(struct pd_dvb_adapter
*);
232 void dvb_stop_streaming(struct pd_dvb_adapter
*);
235 int poseidon_fm_init(struct poseidon
*);
236 int poseidon_fm_exit(struct poseidon
*);
237 struct video_device
*vdev_init(struct poseidon
*, struct video_device
*);
239 /* vendor command ops */
240 int send_set_req(struct poseidon
*, u8
, s32
, s32
*);
241 int send_get_req(struct poseidon
*, u8
, s32
, void*, s32
*, s32
);
242 s32
set_tuner_mode(struct poseidon
*, unsigned char);
244 /* bulk urb alloc/free */
245 int alloc_bulk_urbs_generic(struct urb
**urb_array
, int num
,
246 struct usb_device
*udev
, u8 ep_addr
,
247 int buf_size
, gfp_t gfp_flags
,
248 usb_complete_t complete_fn
, void *context
);
249 void free_all_urb_generic(struct urb
**urb_array
, int num
);
252 void poseidon_delete(struct kref
*kref
);
253 void destroy_video_device(struct video_device
**v_dev
);
254 extern int debug_mode
;
255 void set_debug_mode(struct video_device
*vfd
, int debug_mode
);
258 #define in_hibernation(pd) (pd->msg.event == PM_EVENT_FREEZE)
260 #define in_hibernation(pd) (0)
262 #define get_pm_count(p) (atomic_read(&(p)->interface->pm_usage_cnt))
264 #define log(a, ...) printk(KERN_DEBUG "\t[ %s : %.3d ] "a"\n", \
265 __func__, __LINE__, ## __VA_ARGS__)
267 /* for power management */
268 #define logpm(pd) do {\
269 if (debug_mode & 0x10)\
273 #define logs(f) do { \
274 if ((debug_mode & 0x4) && \
275 (f)->type == V4L2_BUF_TYPE_VBI_CAPTURE) \
278 if ((debug_mode & 0x8) && \
279 (f)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) \
280 log("type : VIDEO");\