V4L/DVB: Add driver for Telegent tlg2300
[linux-2.6-block.git] / drivers / media / video / tlg2300 / pd-common.h
CommitLineData
5b3f03f0
HS
1#ifndef PD_COMMON_H
2#define PD_COMMON_H
3
4#include <linux/version.h>
5#include <linux/fs.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>
14
15#include "dvb_frontend.h"
16#include "dvbdev.h"
17#include "dvb_demux.h"
18#include "dmxdev.h"
19
20#define SBUF_NUM 8
21#define MAX_BUFFER_NUM 6
22#define PK_PER_URB 32
23#define ISO_PKT_SIZE 3072
24
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)
31
32#define PM_SUSPEND_DELAY 3
33
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)
38
39#define TUNER_FREQ_MIN (45000000)
40#define TUNER_FREQ_MAX (862000000)
41
42struct vbi_data {
43 struct video_device *v_dev;
44 struct video_data *video;
45 struct front_face *front;
46
47 unsigned int copied;
48 unsigned int vbi_size; /* the whole size of two fields */
49 int users;
50};
51
52/*
53 * This is the running context of the video, it is useful for
54 * resume()
55 */
56struct 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 */
62};
63
64struct video_data {
65 /* v4l2 video device */
66 struct video_device *v_dev;
67
68 /* the working context */
69 struct running_context context;
70
71 /* for data copy */
72 int field_count;
73
74 char *dst;
75 int lines_copied;
76 int prev_left;
77
78 int lines_per_field;
79 int lines_size;
80
81 /* for communication */
82 u8 endpoint_addr;
83 struct urb *urb_array[SBUF_NUM];
84 struct vbi_data *vbi;
85 struct poseidon *pd;
86 struct front_face *front;
87
88 int is_streaming;
89 int users;
90
91 /* for bubble handler */
92 struct work_struct bubble_work;
93};
94
95enum pcm_stream_state {
96 STREAM_OFF,
97 STREAM_ON,
98 STREAM_SUSPEND,
99};
100
101#define AUDIO_BUFS (3)
102#define CAPTURE_STREAM_EN 1
103struct poseidon_audio {
104 struct urb *urb_array[AUDIO_BUFS];
105 unsigned int copied_position;
106 struct snd_pcm_substream *capture_pcm_substream;
107
108 unsigned int rcv_position;
109 struct snd_card *card;
110 int card_close;
111
112 int users;
113 int pm_state;
114 enum pcm_stream_state capture_stream;
115};
116
117struct radio_data {
118 __u32 fm_freq;
119 int users;
120 unsigned int is_radio_streaming;
121 struct video_device *fm_dev;
122};
123
124#define DVB_SBUF_NUM 4
125#define DVB_URB_BUF_SIZE 0x2000
126struct pd_dvb_adapter {
127 struct dvb_adapter dvb_adap;
128 struct dvb_frontend dvb_fe;
129 struct dmxdev dmxdev;
130 struct dvb_demux demux;
131
132 atomic_t users;
133 atomic_t active_feed;
134
135 /* data transfer */
136 s32 is_streaming;
137 struct urb *urb_array[DVB_SBUF_NUM];
138 struct poseidon *pd_device;
139 u8 ep_addr;
140 u8 reserved[3];
141
142 /* data for power resume*/
143 struct dvb_frontend_parameters fe_param;
144
145 /* for channel scanning */
146 int prev_freq;
147 int bandwidth;
148 unsigned long last_jiffies;
149};
150
151struct front_face {
152 /* use this field to distinguish VIDEO and VBI */
153 enum v4l2_buf_type type;
154
155 /* for host */
156 struct videobuf_queue q;
157
158 /* the bridge for host and device */
159 struct videobuf_buffer *curr_frame;
160
161 /* for device */
162 spinlock_t queue_lock;
163 struct list_head active;
164 struct poseidon *pd;
165};
166
167struct poseidon {
168 struct list_head device_list;
169
170 struct mutex lock;
171 struct kref kref;
172
173 /* for V4L2 */
174 struct v4l2_device v4l2_dev;
175
176 /* hardware info */
177 struct usb_device *udev;
178 struct usb_interface *interface;
179 int cur_transfer_mode;
180
181 struct video_data video_data; /* video */
182 struct vbi_data vbi_data; /* vbi */
183 struct poseidon_audio audio; /* audio (alsa) */
184 struct radio_data radio_data; /* FM */
185 struct pd_dvb_adapter dvb_data; /* DVB */
186
187 u32 state;
188 int country_code;
189 struct file *file_for_stream; /* the active stream*/
190
191#ifdef CONFIG_PM
192 int (*pm_suspend)(struct poseidon *);
193 int (*pm_resume)(struct poseidon *);
194 pm_message_t msg;
195
196 struct work_struct pm_work;
197 u8 portnum;
198#endif
199};
200
201struct poseidon_format {
202 char *name;
203 int fourcc; /* video4linux 2 */
204 int depth; /* bit/pixel */
205 int flags;
206};
207
208struct poseidon_tvnorm {
209 v4l2_std_id v4l2_id;
210 char name[12];
211 u32 tlg_tvnorm;
212};
213
214/* video */
215int pd_video_init(struct poseidon *);
216void pd_video_exit(struct poseidon *);
217int stop_all_video_stream(struct poseidon *);
218
219/* alsa audio */
220int poseidon_audio_init(struct poseidon *);
221int poseidon_audio_free(struct poseidon *);
222#ifdef CONFIG_PM
223int pm_alsa_suspend(struct poseidon *);
224int pm_alsa_resume(struct poseidon *);
225#endif
226
227/* dvb */
228int pd_dvb_usb_device_init(struct poseidon *);
229void pd_dvb_usb_device_exit(struct poseidon *);
230void pd_dvb_usb_device_cleanup(struct poseidon *);
231int pd_dvb_get_adapter_num(struct pd_dvb_adapter *);
232void dvb_stop_streaming(struct pd_dvb_adapter *);
233
234/* FM */
235int poseidon_fm_init(struct poseidon *);
236int poseidon_fm_exit(struct poseidon *);
237struct video_device *vdev_init(struct poseidon *, struct video_device *);
238
239/* vendor command ops */
240int send_set_req(struct poseidon*, u8, s32, s32*);
241int send_get_req(struct poseidon*, u8, s32, void*, s32*, s32);
242s32 set_tuner_mode(struct poseidon*, unsigned char);
243enum tlg__analog_audio_standard get_audio_std(s32, s32);
244
245/* bulk urb alloc/free */
246int alloc_bulk_urbs_generic(struct urb **urb_array, int num,
247 struct usb_device *udev, u8 ep_addr,
248 int buf_size, gfp_t gfp_flags,
249 usb_complete_t complete_fn, void *context);
250void free_all_urb_generic(struct urb **urb_array, int num);
251
252/* misc */
253void poseidon_delete(struct kref *kref);
254void destroy_video_device(struct video_device **v_dev);
255extern int country_code;
256extern int debug_mode;
257void set_debug_mode(struct video_device *vfd, int debug_mode);
258
259#define in_hibernation(pd) (pd->msg.event == PM_EVENT_FREEZE)
260#define get_pm_count(p) (atomic_read(&(p)->interface->pm_usage_cnt))
261
262#define log(a, ...) printk(KERN_DEBUG "\t[ %s : %.3d ] "a"\n", \
263 __func__, __LINE__, ## __VA_ARGS__)
264
265/* for power management */
266#define logpm(pd) do {\
267 if (debug_mode & 0x10)\
268 log();\
269 } while (0)
270
271#define logs(f) do { \
272 if ((debug_mode & 0x4) && \
273 (f)->type == V4L2_BUF_TYPE_VBI_CAPTURE) \
274 log("type : VBI");\
275 \
276 if ((debug_mode & 0x8) && \
277 (f)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) \
278 log("type : VIDEO");\
279 } while (0)
280#endif