1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/usb.h>
23#include <linux/i2c.h>
24#include <linux/i2c-algo-bit.h>
25#include <media/tveeprom.h>
26
27
28#include <linux/videodev2.h>
29#include <media/videobuf-vmalloc.h>
30#include <media/v4l2-device.h>
31
32
33#include "demux.h"
34#include "dmxdev.h"
35#include "dvb_demux.h"
36#include "dvb_frontend.h"
37#include "dvb_net.h"
38#include "dvbdev.h"
39
40#include "au0828-reg.h"
41#include "au0828-cards.h"
42
43#define DRIVER_NAME "au0828"
44#define URB_COUNT 16
45#define URB_BUFSIZE (0xe522)
46
47
48#define NTSC_STD_W 720
49#define NTSC_STD_H 480
50
51#define AU0828_INTERLACED_DEFAULT 1
52#define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)
53
54
55#define AU0828_MAX_ISO_BUFS 12
56#define AU0828_ISO_PACKETS_PER_URB 128
57
58#define AU0828_MIN_BUF 4
59#define AU0828_DEF_BUF 8
60
61#define AU0828_MAX_INPUT 4
62
63
64#define AU0828_RESOURCE_VIDEO 0x01
65#define AU0828_RESOURCE_VBI 0x02
66
67enum au0828_itype {
68 AU0828_VMUX_UNDEFINED = 0,
69 AU0828_VMUX_COMPOSITE,
70 AU0828_VMUX_SVIDEO,
71 AU0828_VMUX_CABLE,
72 AU0828_VMUX_TELEVISION,
73 AU0828_VMUX_DVB,
74 AU0828_VMUX_DEBUG
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 struct au0828_input input[AU0828_MAX_INPUT];
90
91};
92
93struct au0828_dvb {
94 struct mutex lock;
95 struct dvb_adapter adapter;
96 struct dvb_frontend *frontend;
97 struct dvb_demux demux;
98 struct dmxdev dmxdev;
99 struct dmx_frontend fe_hw;
100 struct dmx_frontend fe_mem;
101 struct dvb_net net;
102 int feeding;
103};
104
105enum au0828_stream_state {
106 STREAM_OFF,
107 STREAM_INTERRUPT,
108 STREAM_ON
109};
110
111#define AUVI_INPUT(nr) (dev->board.input[nr])
112
113
114enum au0828_dev_state {
115 DEV_INITIALIZED = 0x01,
116 DEV_DISCONNECTED = 0x02,
117 DEV_MISCONFIGURED = 0x04
118};
119
120struct au0828_fh {
121 struct au0828_dev *dev;
122 unsigned int resources;
123
124 struct videobuf_queue vb_vidq;
125 struct videobuf_queue vb_vbiq;
126 enum v4l2_buf_type type;
127};
128
129struct au0828_usb_isoc_ctl {
130
131 int max_pkt_size;
132
133
134 int num_bufs;
135
136
137 struct urb **urb;
138
139
140 char **transfer_buffer;
141
142
143 u8 cmd;
144 int pos, size, pktsize;
145
146
147 int field;
148
149
150 u32 tmp_buf;
151 int tmp_buf_len;
152
153
154 struct au0828_buffer *buf;
155 struct au0828_buffer *vbi_buf;
156
157
158 int nfields;
159
160
161 int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
162
163};
164
165
166struct au0828_buffer {
167
168 struct videobuf_buffer vb;
169
170 struct list_head frame;
171 int top_field;
172 int receiving;
173};
174
175struct au0828_dmaqueue {
176 struct list_head active;
177 struct list_head queued;
178
179 wait_queue_head_t wq;
180
181
182 int pos;
183};
184
185struct au0828_dev {
186 struct mutex mutex;
187 struct usb_device *usbdev;
188 int boardnr;
189 struct au0828_board board;
190 u8 ctrlmsg[64];
191
192
193 struct i2c_adapter i2c_adap;
194 struct i2c_algorithm i2c_algo;
195 struct i2c_client i2c_client;
196 u32 i2c_rc;
197
198
199 struct au0828_dvb dvb;
200
201
202 struct v4l2_device v4l2_dev;
203 int users;
204 unsigned int resources;
205 struct video_device *vdev;
206 struct video_device *vbi_dev;
207 struct timer_list vid_timeout;
208 int vid_timeout_running;
209 struct timer_list vbi_timeout;
210 int vbi_timeout_running;
211 int width;
212 int height;
213 int vbi_width;
214 int vbi_height;
215 u32 vbi_read;
216 u32 field_size;
217 u32 frame_size;
218 u32 bytesperline;
219 int type;
220 u8 ctrl_ainput;
221 __u8 isoc_in_endpointaddr;
222 u8 isoc_init_ok;
223 int greenscreen_detected;
224 unsigned int frame_count;
225 int ctrl_freq;
226 int input_type;
227 unsigned int ctrl_input;
228 enum au0828_dev_state dev_state;
229 enum au0828_stream_state stream_state;
230 wait_queue_head_t open;
231
232 struct mutex lock;
233
234
235 struct au0828_dmaqueue vidq;
236 struct au0828_dmaqueue vbiq;
237 struct au0828_usb_isoc_ctl isoc_ctl;
238 spinlock_t slock;
239
240
241 int alt;
242 int max_pkt_size;
243 int num_alt;
244 unsigned int *alt_max_pkt_size;
245 struct urb *urb[AU0828_MAX_ISO_BUFS];
246 char *transfer_buffer[AU0828_MAX_ISO_BUFS];
247
248
249
250 int urb_streaming;
251 struct urb *urbs[URB_COUNT];
252};
253
254
255#define au0828_read(dev, reg) au0828_readreg(dev, reg)
256#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
257#define au0828_andor(dev, reg, mask, value) \
258 au0828_writereg(dev, reg, \
259 (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
260
261#define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
262#define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
263
264
265
266extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
267extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
268extern int au0828_debug;
269
270
271
272extern struct au0828_board au0828_boards[];
273extern struct usb_device_id au0828_usb_id_table[];
274extern void au0828_gpio_setup(struct au0828_dev *dev);
275extern int au0828_tuner_callback(void *priv, int component,
276 int command, int arg);
277extern void au0828_card_setup(struct au0828_dev *dev);
278
279
280
281extern int au0828_i2c_register(struct au0828_dev *dev);
282extern int au0828_i2c_unregister(struct au0828_dev *dev);
283
284
285
286int au0828_analog_register(struct au0828_dev *dev,
287 struct usb_interface *interface);
288int au0828_analog_stream_disable(struct au0828_dev *d);
289void au0828_analog_unregister(struct au0828_dev *dev);
290
291
292
293extern int au0828_dvb_register(struct au0828_dev *dev);
294extern void au0828_dvb_unregister(struct au0828_dev *dev);
295
296
297extern struct videobuf_queue_ops au0828_vbi_qops;
298
299#define dprintk(level, fmt, arg...)\
300 do { if (au0828_debug & level)\
301 printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
302 } while (0)
303