1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
20#include <linux/bitops.h>
21#include <linux/usb.h>
22#include <linux/i2c.h>
23#include <linux/i2c-algo-bit.h>
24#include <media/tveeprom.h>
25
26
27#include <linux/videodev2.h>
28#include <media/videobuf2-v4l2.h>
29#include <media/videobuf2-vmalloc.h>
30#include <media/v4l2-device.h>
31#include <media/v4l2-ctrls.h>
32#include <media/v4l2-fh.h>
33#include <media/media-device.h>
34
35
36#include <media/demux.h>
37#include <media/dmxdev.h>
38#include <media/dvb_demux.h>
39#include <media/dvb_frontend.h>
40#include <media/dvb_net.h>
41#include <media/dvbdev.h>
42
43#include "au0828-reg.h"
44#include "au0828-cards.h"
45
46#define URB_COUNT 16
47#define URB_BUFSIZE (0xe522)
48
49
50#define NTSC_STD_W 720
51#define NTSC_STD_H 480
52
53#define AU0828_INTERLACED_DEFAULT 1
54
55
56#define AU0828_MAX_ISO_BUFS 12
57#define AU0828_ISO_PACKETS_PER_URB 128
58
59#define AU0828_MIN_BUF 4
60#define AU0828_DEF_BUF 8
61
62#define AU0828_MAX_INPUT 4
63
64
65#define AU0828_RESOURCE_VIDEO 0x01
66#define AU0828_RESOURCE_VBI 0x02
67
68enum au0828_itype {
69 AU0828_VMUX_UNDEFINED = 0,
70 AU0828_VMUX_COMPOSITE,
71 AU0828_VMUX_SVIDEO,
72 AU0828_VMUX_CABLE,
73 AU0828_VMUX_TELEVISION,
74 AU0828_VMUX_DVB,
75};
76
77struct au0828_input {
78 enum au0828_itype type;
79 unsigned int vmux;
80 unsigned int amux;
81 void (*audio_setup) (void *priv, int enable);
82};
83
84struct au0828_board {
85 char *name;
86 unsigned int tuner_type;
87 unsigned char tuner_addr;
88 unsigned char i2c_clk_divider;
89 unsigned char has_ir_i2c:1;
90 unsigned char has_analog:1;
91 struct au0828_input input[AU0828_MAX_INPUT];
92};
93
94struct au0828_dvb {
95 struct mutex lock;
96 struct dvb_adapter adapter;
97 struct dvb_frontend *frontend;
98 struct dvb_demux demux;
99 struct dmxdev dmxdev;
100 struct dmx_frontend fe_hw;
101 struct dmx_frontend fe_mem;
102 struct dvb_net net;
103 int feeding;
104 int start_count;
105 int stop_count;
106
107 int (*set_frontend)(struct dvb_frontend *fe);
108};
109
110enum au0828_stream_state {
111 STREAM_OFF,
112 STREAM_INTERRUPT,
113 STREAM_ON
114};
115
116#define AUVI_INPUT(nr) (dev->board.input[nr])
117
118
119enum au0828_dev_state {
120 DEV_INITIALIZED = 0,
121 DEV_DISCONNECTED = 1,
122 DEV_MISCONFIGURED = 2
123};
124
125struct au0828_dev;
126
127struct au0828_usb_isoc_ctl {
128
129 int max_pkt_size;
130
131
132 int num_bufs;
133
134
135 struct urb **urb;
136
137
138 char **transfer_buffer;
139
140
141 u8 cmd;
142 int pos, size, pktsize;
143
144
145 int field;
146
147
148 u32 tmp_buf;
149 int tmp_buf_len;
150
151
152 struct au0828_buffer *buf;
153 struct au0828_buffer *vbi_buf;
154
155
156 int nfields;
157
158
159 int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
160
161};
162
163
164struct au0828_buffer {
165
166 struct vb2_v4l2_buffer vb;
167 struct list_head list;
168
169 void *mem;
170 unsigned long length;
171 int top_field;
172
173 char *vb_buf;
174};
175
176struct au0828_dmaqueue {
177 struct list_head active;
178
179 int pos;
180};
181
182struct au0828_dev {
183 struct mutex mutex;
184 struct usb_device *usbdev;
185 int boardnr;
186 struct au0828_board board;
187 u8 ctrlmsg[64];
188
189
190 struct i2c_adapter i2c_adap;
191 struct i2c_algorithm i2c_algo;
192 struct i2c_client i2c_client;
193 u32 i2c_rc;
194
195
196 struct au0828_dvb dvb;
197 struct work_struct restart_streaming;
198 struct timer_list bulk_timeout;
199 int bulk_timeout_running;
200
201#ifdef CONFIG_VIDEO_AU0828_V4L2
202
203 struct v4l2_device v4l2_dev;
204 struct v4l2_ctrl_handler v4l2_ctrl_hdl;
205#endif
206#ifdef CONFIG_VIDEO_AU0828_RC
207 struct au0828_rc *ir;
208#endif
209
210 struct video_device vdev;
211 struct video_device vbi_dev;
212
213
214 struct vb2_queue vb_vidq;
215 struct vb2_queue vb_vbiq;
216 struct mutex vb_queue_lock;
217 struct mutex vb_vbi_queue_lock;
218
219 unsigned int frame_count;
220 unsigned int vbi_frame_count;
221
222 struct timer_list vid_timeout;
223 int vid_timeout_running;
224 struct timer_list vbi_timeout;
225 int vbi_timeout_running;
226
227 int users;
228 int streaming_users;
229
230 int width;
231 int height;
232 int vbi_width;
233 int vbi_height;
234 u32 vbi_read;
235 v4l2_std_id std;
236 u32 field_size;
237 u32 frame_size;
238 u32 bytesperline;
239 int type;
240 u8 ctrl_ainput;
241 __u8 isoc_in_endpointaddr;
242 u8 isoc_init_ok;
243 int greenscreen_detected;
244 int ctrl_freq;
245 int input_type;
246 int std_set_in_tuner_core;
247 unsigned int ctrl_input;
248 long unsigned int dev_state; ;
249 enum au0828_stream_state stream_state;
250 wait_queue_head_t open;
251
252 struct mutex lock;
253
254
255 struct au0828_dmaqueue vidq;
256 struct au0828_dmaqueue vbiq;
257 struct au0828_usb_isoc_ctl isoc_ctl;
258 spinlock_t slock;
259
260
261 int alt;
262 int max_pkt_size;
263 int num_alt;
264 unsigned int *alt_max_pkt_size;
265 struct urb *urb[AU0828_MAX_ISO_BUFS];
266 char *transfer_buffer[AU0828_MAX_ISO_BUFS];
267
268
269
270 bool urb_streaming, need_urb_start;
271 struct urb *urbs[URB_COUNT];
272
273
274
275 char *dig_transfer_buffer[URB_COUNT];
276
277#ifdef CONFIG_MEDIA_CONTROLLER
278 struct media_device *media_dev;
279 struct media_pad video_pad, vbi_pad;
280 struct media_entity *decoder;
281 struct media_entity input_ent[AU0828_MAX_INPUT];
282 struct media_pad input_pad[AU0828_MAX_INPUT];
283 struct media_entity_notify entity_notify;
284 struct media_entity *tuner;
285 struct media_link *active_link;
286 struct media_entity *active_link_owner;
287 struct media_entity *active_source;
288 struct media_entity *active_sink;
289#endif
290};
291
292
293
294#define au0828_read(dev, reg) au0828_readreg(dev, reg)
295#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
296#define au0828_andor(dev, reg, mask, value) \
297 au0828_writereg(dev, reg, \
298 (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
299
300#define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
301#define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
302
303
304
305extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
306extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
307extern void au0828_usb_release(struct au0828_dev *dev);
308extern int au0828_debug;
309
310
311
312extern struct au0828_board au0828_boards[];
313extern struct usb_device_id au0828_usb_id_table[];
314extern void au0828_gpio_setup(struct au0828_dev *dev);
315extern int au0828_tuner_callback(void *priv, int component,
316 int command, int arg);
317extern void au0828_card_setup(struct au0828_dev *dev);
318
319
320
321extern int au0828_i2c_register(struct au0828_dev *dev);
322extern int au0828_i2c_unregister(struct au0828_dev *dev);
323
324
325
326extern int au0828_start_analog_streaming(struct vb2_queue *vq,
327 unsigned int count);
328extern void au0828_stop_vbi_streaming(struct vb2_queue *vq);
329#ifdef CONFIG_VIDEO_AU0828_V4L2
330extern int au0828_v4l2_device_register(struct usb_interface *interface,
331 struct au0828_dev *dev);
332
333extern int au0828_analog_register(struct au0828_dev *dev,
334 struct usb_interface *interface);
335extern int au0828_analog_unregister(struct au0828_dev *dev);
336extern void au0828_usb_v4l2_media_release(struct au0828_dev *dev);
337extern void au0828_v4l2_suspend(struct au0828_dev *dev);
338extern void au0828_v4l2_resume(struct au0828_dev *dev);
339#else
340static inline int au0828_v4l2_device_register(struct usb_interface *interface,
341 struct au0828_dev *dev)
342{ return 0; };
343static inline int au0828_analog_register(struct au0828_dev *dev,
344 struct usb_interface *interface)
345{ return 0; };
346static inline int au0828_analog_unregister(struct au0828_dev *dev)
347{ return 0; };
348static inline void au0828_usb_v4l2_media_release(struct au0828_dev *dev) { };
349static inline void au0828_v4l2_suspend(struct au0828_dev *dev) { };
350static inline void au0828_v4l2_resume(struct au0828_dev *dev) { };
351#endif
352
353
354
355extern int au0828_dvb_register(struct au0828_dev *dev);
356extern void au0828_dvb_unregister(struct au0828_dev *dev);
357void au0828_dvb_suspend(struct au0828_dev *dev);
358void au0828_dvb_resume(struct au0828_dev *dev);
359
360
361extern const struct vb2_ops au0828_vbi_qops;
362
363#define dprintk(level, fmt, arg...)\
364 do { if (au0828_debug & level)\
365 printk(KERN_DEBUG pr_fmt(fmt), ## arg);\
366 } while (0)
367
368
369#ifdef CONFIG_VIDEO_AU0828_RC
370extern int au0828_rc_register(struct au0828_dev *dev);
371extern void au0828_rc_unregister(struct au0828_dev *dev);
372extern int au0828_rc_suspend(struct au0828_dev *dev);
373extern int au0828_rc_resume(struct au0828_dev *dev);
374#else
375static inline int au0828_rc_register(struct au0828_dev *dev) { return 0; }
376static inline void au0828_rc_unregister(struct au0828_dev *dev) { }
377static inline int au0828_rc_suspend(struct au0828_dev *dev) { return 0; }
378static inline int au0828_rc_resume(struct au0828_dev *dev) { return 0; }
379#endif
380