Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / media / dvb / ttpci / av7110.h
1 #ifndef _AV7110_H_
2 #define _AV7110_H_
3
4 #include <linux/interrupt.h>
5 #include <linux/socket.h>
6 #include <linux/netdevice.h>
7 #include <linux/i2c.h>
8
9 #ifdef CONFIG_DEVFS_FS
10 #include <linux/devfs_fs_kernel.h>
11 #endif
12
13 #include <linux/dvb/video.h>
14 #include <linux/dvb/audio.h>
15 #include <linux/dvb/dmx.h>
16 #include <linux/dvb/ca.h>
17 #include <linux/dvb/osd.h>
18 #include <linux/dvb/net.h>
19 #include <linux/mutex.h>
20
21 #include "dvbdev.h"
22 #include "demux.h"
23 #include "dvb_demux.h"
24 #include "dmxdev.h"
25 #include "dvb_filter.h"
26 #include "dvb_net.h"
27 #include "dvb_ringbuffer.h"
28 #include "dvb_frontend.h"
29 #include "ves1820.h"
30 #include "ves1x93.h"
31 #include "stv0299.h"
32 #include "tda8083.h"
33 #include "sp8870.h"
34 #include "stv0297.h"
35 #include "l64781.h"
36
37 #include <media/saa7146_vv.h>
38
39
40 #define ANALOG_TUNER_VES1820 1
41 #define ANALOG_TUNER_STV0297 2
42 #define ANALOG_TUNER_VBI     0x100
43
44 extern int av7110_debug;
45
46 #define dprintk(level,args...) \
47             do { if ((av7110_debug & level)) { printk("dvb-ttpci: %s(): ", __FUNCTION__); printk(args); } } while (0)
48
49 #define MAXFILT 32
50
51 enum {AV_PES_STREAM, PS_STREAM, TS_STREAM, PES_STREAM};
52
53 struct av7110_p2t {
54         u8                pes[TS_SIZE];
55         u8                counter;
56         long int          pos;
57         int               frags;
58         struct dvb_demux_feed *feed;
59 };
60
61 /* video MPEG decoder events: */
62 /* (code copied from dvb_frontend.c, should maybe be factored out...) */
63 #define MAX_VIDEO_EVENT 8
64 struct dvb_video_events {
65         struct video_event        events[MAX_VIDEO_EVENT];
66         int                       eventw;
67         int                       eventr;
68         int                       overflow;
69         wait_queue_head_t         wait_queue;
70         spinlock_t                lock;
71 };
72
73
74 /* place to store all the necessary device information */
75 struct av7110 {
76
77         /* devices */
78
79         struct dvb_device       dvb_dev;
80         struct dvb_net          dvb_net;
81
82         struct video_device     *v4l_dev;
83         struct video_device     *vbi_dev;
84
85         struct saa7146_dev      *dev;
86
87         struct i2c_adapter      i2c_adap;
88
89         char                    *card_name;
90
91         /* support for analog module of dvb-c */
92         int                     analog_tuner_flags;
93         int                     current_input;
94         u32                     current_freq;
95
96         struct tasklet_struct   debi_tasklet;
97         struct tasklet_struct   gpio_tasklet;
98
99         int adac_type;         /* audio DAC type */
100 #define DVB_ADAC_TI       0
101 #define DVB_ADAC_CRYSTAL  1
102 #define DVB_ADAC_MSP34x0  2
103 #define DVB_ADAC_MSP34x5  3
104 #define DVB_ADAC_NONE    -1
105
106
107         /* buffers */
108
109         void                   *iobuf;   /* memory for all buffers */
110         struct dvb_ringbuffer   avout;   /* buffer for video or A/V mux */
111 #define AVOUTLEN (128*1024)
112         struct dvb_ringbuffer   aout;    /* buffer for audio */
113 #define AOUTLEN (64*1024)
114         void                   *bmpbuf;
115 #define BMPLEN (8*32768+1024)
116
117         /* bitmap buffers and states */
118
119         int                     bmpp;
120         int                     bmplen;
121         volatile int            bmp_state;
122 #define BMP_NONE     0
123 #define BMP_LOADING  1
124 #define BMP_LOADED   2
125         wait_queue_head_t       bmpq;
126
127
128         /* DEBI and polled command interface */
129
130         spinlock_t              debilock;
131         struct mutex            dcomlock;
132         volatile int            debitype;
133         volatile int            debilen;
134
135
136         /* Recording and playback flags */
137
138         int                     rec_mode;
139         int                     playing;
140 #define RP_NONE  0
141 #define RP_VIDEO 1
142 #define RP_AUDIO 2
143 #define RP_AV    3
144
145
146         /* OSD */
147
148         int                     osdwin;      /* currently active window */
149         u16                     osdbpp[8];
150         struct mutex            osd_mutex;
151
152         /* CA */
153
154         ca_slot_info_t          ci_slot[2];
155
156         int                     vidmode;
157         struct dmxdev           dmxdev;
158         struct dvb_demux        demux;
159
160         struct dmx_frontend     hw_frontend;
161         struct dmx_frontend     mem_frontend;
162
163         /* for budget mode demux1 */
164         struct dmxdev           dmxdev1;
165         struct dvb_demux        demux1;
166         struct dvb_net          dvb_net1;
167         spinlock_t              feedlock1;
168         int                     feeding1;
169         u8                      tsf;
170         u32                     ttbp;
171         unsigned char           *grabbing;
172         struct saa7146_pgtable  pt;
173         struct tasklet_struct   vpe_tasklet;
174
175         int                     fe_synced;
176         struct mutex            pid_mutex;
177
178         int                     video_blank;
179         struct video_status     videostate;
180         int                     display_ar;
181         int                     trickmode;
182 #define TRICK_NONE   0
183 #define TRICK_FAST   1
184 #define TRICK_SLOW   2
185 #define TRICK_FREEZE 3
186         struct audio_status     audiostate;
187
188         struct dvb_demux_filter *handle2filter[32];
189         struct av7110_p2t        p2t_filter[MAXFILT];
190         struct dvb_filter_pes2ts p2t[2];
191         struct ipack             ipack[2];
192         u8                      *kbuf[2];
193
194         int sinfo;
195         int feeding;
196
197         int arm_errors;
198         int registered;
199
200
201         /* AV711X */
202
203         u32                 arm_fw;
204         u32                 arm_rtsl;
205         u32                 arm_vid;
206         u32                 arm_app;
207         u32                 avtype;
208         int                 arm_ready;
209         struct task_struct *arm_thread;
210         wait_queue_head_t   arm_wait;
211         u16                 arm_loops;
212         int                 arm_rmmod;
213
214         void               *debi_virt;
215         dma_addr_t          debi_bus;
216
217         u16                 pids[DMX_PES_OTHER];
218
219         struct dvb_ringbuffer    ci_rbuffer;
220         struct dvb_ringbuffer    ci_wbuffer;
221
222         struct audio_mixer      mixer;
223
224         struct dvb_adapter       dvb_adapter;
225         struct dvb_device        *video_dev;
226         struct dvb_device        *audio_dev;
227         struct dvb_device        *ca_dev;
228         struct dvb_device        *osd_dev;
229
230         struct dvb_video_events  video_events;
231         video_size_t             video_size;
232
233         u16                     wssMode;
234         u16                     wssData;
235
236         u32                     ir_config;
237         u32                     ir_command;
238         void                    (*ir_handler)(struct av7110 *av7110, u32 ircom);
239         struct tasklet_struct   ir_tasklet;
240
241         /* firmware stuff */
242         unsigned char *bin_fw;
243         unsigned long size_fw;
244
245         unsigned char *bin_dpram;
246         unsigned long size_dpram;
247
248         unsigned char *bin_root;
249         unsigned long size_root;
250
251         struct dvb_frontend* fe;
252         fe_status_t fe_status;
253
254         /* crash recovery */
255         void                            (*recover)(struct av7110* av7110);
256         struct dvb_frontend_parameters  saved_fe_params;
257         fe_sec_voltage_t                saved_voltage;
258         fe_sec_tone_mode_t              saved_tone;
259         struct dvb_diseqc_master_cmd    saved_master_cmd;
260         fe_sec_mini_cmd_t               saved_minicmd;
261
262         int (*fe_init)(struct dvb_frontend* fe);
263         int (*fe_read_status)(struct dvb_frontend* fe, fe_status_t* status);
264         int (*fe_diseqc_reset_overload)(struct dvb_frontend* fe);
265         int (*fe_diseqc_send_master_cmd)(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd);
266         int (*fe_diseqc_send_burst)(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd);
267         int (*fe_set_tone)(struct dvb_frontend* fe, fe_sec_tone_mode_t tone);
268         int (*fe_set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
269         int (*fe_dishnetwork_send_legacy_command)(struct dvb_frontend* fe, unsigned long cmd);
270         int (*fe_set_frontend)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params);
271 };
272
273
274 extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
275                        u16 subpid, u16 pcrpid);
276
277 extern int av7110_ir_init(struct av7110 *av7110);
278 extern void av7110_ir_exit(struct av7110 *av7110);
279
280 /* msp3400 i2c subaddresses */
281 #define MSP_WR_DEM 0x10
282 #define MSP_RD_DEM 0x11
283 #define MSP_WR_DSP 0x12
284 #define MSP_RD_DSP 0x13
285
286 extern int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val);
287 extern u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg);
288 extern int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val);
289
290
291 extern int av7110_init_analog_module(struct av7110 *av7110);
292 extern int av7110_init_v4l(struct av7110 *av7110);
293 extern int av7110_exit_v4l(struct av7110 *av7110);
294
295 #endif /* _AV7110_H_ */