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 #define MAX_CI_SLOTS	2
92 
93 /* place to store all the necessary device information */
94 struct av7110 {
95 	/* devices */
96 
97 	struct dvb_device	dvb_dev;
98 	struct dvb_net		dvb_net;
99 
100 	struct video_device	v4l_dev;
101 	struct video_device	vbi_dev;
102 
103 	struct saa7146_dev	*dev;
104 
105 	struct i2c_adapter	i2c_adap;
106 
107 	char			*card_name;
108 
109 	/* support for analog module of dvb-c */
110 	int			analog_tuner_flags;
111 	int			current_input;
112 	u32			current_freq;
113 
114 	struct tasklet_struct	debi_tasklet;
115 	struct tasklet_struct	gpio_tasklet;
116 
117 	int adac_type;	       /* audio DAC type */
118 #define DVB_ADAC_TI	  0
119 #define DVB_ADAC_CRYSTAL  1
120 #define DVB_ADAC_MSP34x0  2
121 #define DVB_ADAC_MSP34x5  3
122 #define DVB_ADAC_NONE	 -1
123 
124 	/* buffers */
125 
126 	void		       *iobuf;	 /* memory for all buffers */
127 	struct dvb_ringbuffer	avout;   /* buffer for video or A/V mux */
128 #define AVOUTLEN (128 * 1024)
129 	struct dvb_ringbuffer	aout;    /* buffer for audio */
130 #define AOUTLEN (64 * 1024)
131 	void		       *bmpbuf;
132 #define BMPLEN (8 * 32768 + 1024)
133 
134 	/* bitmap buffers and states */
135 
136 	int			bmpp;
137 	int			bmplen;
138 	volatile int		bmp_state;
139 #define BMP_NONE     0
140 #define BMP_LOADING  1
141 #define BMP_LOADED   2
142 	wait_queue_head_t	bmpq;
143 
144 	/* DEBI and polled command interface */
145 
146 	spinlock_t		debilock;
147 	struct mutex		dcomlock;
148 	volatile int		debitype;
149 	volatile int		debilen;
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 	/* OSD */
161 
162 	int			osdwin;      /* currently active window */
163 	u16			osdbpp[8];
164 	struct mutex		osd_mutex;
165 
166 	/* CA */
167 
168 	struct ca_slot_info	ci_slot[MAX_CI_SLOTS];
169 
170 	enum av7110_video_mode	vidmode;
171 	struct dmxdev		dmxdev;
172 	struct dvb_demux	demux;
173 
174 	struct dmx_frontend	hw_frontend;
175 	struct dmx_frontend	mem_frontend;
176 
177 	/* for budget mode demux1 */
178 	struct dmxdev		dmxdev1;
179 	struct dvb_demux	demux1;
180 	struct dvb_net		dvb_net1;
181 	spinlock_t		feedlock1;
182 	int			feeding1;
183 	u32			ttbp;
184 	unsigned char           *grabbing;
185 	struct saa7146_pgtable  pt;
186 	struct tasklet_struct   vpe_tasklet;
187 	bool			full_ts;
188 
189 	int			fe_synced;
190 	struct mutex		pid_mutex;
191 
192 	int			video_blank;
193 	struct video_status	videostate;
194 	u16			display_panscan;
195 	int			display_ar;
196 	int			trickmode;
197 #define TRICK_NONE   0
198 #define TRICK_FAST   1
199 #define TRICK_SLOW   2
200 #define TRICK_FREEZE 3
201 	struct audio_status	audiostate;
202 
203 	struct dvb_demux_filter *handle2filter[32];
204 	struct av7110_p2t	 p2t_filter[MAXFILT];
205 	struct dvb_filter_pes2ts p2t[2];
206 	struct ipack		 ipack[2];
207 	u8			*kbuf[2];
208 
209 	int sinfo;
210 	int feeding;
211 
212 	int arm_errors;
213 	int registered;
214 
215 	/* AV711X */
216 
217 	u32		    arm_fw;
218 	u32		    arm_rtsl;
219 	u32		    arm_vid;
220 	u32		    arm_app;
221 	u32		    avtype;
222 	int		    arm_ready;
223 	struct task_struct *arm_thread;
224 	wait_queue_head_t   arm_wait;
225 	u16		    arm_loops;
226 
227 	void		   *debi_virt;
228 	dma_addr_t	    debi_bus;
229 
230 	u16		    pids[DMX_PES_OTHER];
231 
232 	struct dvb_ringbuffer	 ci_rbuffer;
233 	struct dvb_ringbuffer	 ci_wbuffer;
234 
235 	struct audio_mixer	mixer;
236 
237 	struct dvb_adapter	 dvb_adapter;
238 	struct dvb_device	 *video_dev;
239 	struct dvb_device	 *audio_dev;
240 	struct dvb_device	 *ca_dev;
241 	struct dvb_device	 *osd_dev;
242 
243 	struct dvb_video_events  video_events;
244 	video_size_t		 video_size;
245 
246 	u16			wssMode;
247 	u16			wssData;
248 
249 	struct infrared		ir;
250 
251 	/* firmware stuff */
252 	unsigned char *bin_fw;
253 	unsigned long size_fw;
254 
255 	unsigned char *bin_dpram;
256 	unsigned long size_dpram;
257 
258 	unsigned char *bin_root;
259 	unsigned long size_root;
260 
261 	struct dvb_frontend *fe;
262 	enum fe_status fe_status;
263 
264 	struct mutex ioctl_mutex;
265 
266 	/* crash recovery */
267 	void				(*recover)(struct av7110 *av7110);
268 	enum fe_sec_voltage		saved_voltage;
269 	enum fe_sec_tone_mode		saved_tone;
270 	struct dvb_diseqc_master_cmd	saved_master_cmd;
271 	enum fe_sec_mini_cmd		saved_minicmd;
272 
273 	int (*fe_init)(struct dvb_frontend *fe);
274 	int (*fe_read_status)(struct dvb_frontend *fe, enum fe_status *status);
275 	int (*fe_diseqc_reset_overload)(struct dvb_frontend *fe);
276 	int (*fe_diseqc_send_master_cmd)(struct dvb_frontend *fe,
277 					 struct dvb_diseqc_master_cmd *cmd);
278 	int (*fe_diseqc_send_burst)(struct dvb_frontend *fe,
279 				    enum fe_sec_mini_cmd minicmd);
280 	int (*fe_set_tone)(struct dvb_frontend *fe,
281 			   enum fe_sec_tone_mode tone);
282 	int (*fe_set_voltage)(struct dvb_frontend *fe,
283 			      enum fe_sec_voltage voltage);
284 	int (*fe_dishnetwork_send_legacy_command)(struct dvb_frontend *fe,
285 						  unsigned long cmd);
286 	int (*fe_set_frontend)(struct dvb_frontend *fe);
287 };
288 
289 int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
290 	       u16 subpid, u16 pcrpid);
291 
292 void av7110_ir_handler(struct av7110 *av7110, u32 ircom);
293 int av7110_set_ir_config(struct av7110 *av7110);
294 int av7110_ir_init(struct av7110 *av7110);
295 void av7110_ir_exit(struct av7110 *av7110);
296 
297 /* msp3400 i2c subaddresses */
298 #define MSP_WR_DEM 0x10
299 #define MSP_RD_DEM 0x11
300 #define MSP_WR_DSP 0x12
301 #define MSP_RD_DSP 0x13
302 
303 int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val);
304 u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg);
305 int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val);
306 
307 int av7110_init_analog_module(struct av7110 *av7110);
308 int av7110_init_v4l(struct av7110 *av7110);
309 int av7110_exit_v4l(struct av7110 *av7110);
310 
311 #endif /* _AV7110_H_ */
312