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