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