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