2 * Driver for the Auvitek AU0828 USB bridge
4 * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/usb.h>
23 #include <linux/i2c.h>
24 #include <linux/i2c-algo-bit.h>
25 #include <media/tveeprom.h>
28 #include <linux/videodev2.h>
29 #include <media/videobuf-vmalloc.h>
30 #include <media/v4l2-device.h>
31 #include <media/v4l2-ctrls.h>
32 #include <media/v4l2-fh.h>
37 #include "dvb_demux.h"
38 #include "dvb_frontend.h"
42 #include "au0828-reg.h"
43 #include "au0828-cards.h"
45 #define DRIVER_NAME "au0828"
47 #define URB_BUFSIZE (0xe522)
49 /* Analog constants */
50 #define NTSC_STD_W 720
51 #define NTSC_STD_H 480
53 #define AU0828_INTERLACED_DEFAULT 1
54 #define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)
56 /* Defination for AU0828 USB transfer */
57 #define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */
58 #define AU0828_ISO_PACKETS_PER_URB 128
60 #define AU0828_MIN_BUF 4
61 #define AU0828_DEF_BUF 8
63 #define AU0828_MAX_INPUT 4
65 /* au0828 resource types (used for res_get/res_lock etc */
66 #define AU0828_RESOURCE_VIDEO 0x01
67 #define AU0828_RESOURCE_VBI 0x02
70 AU0828_VMUX_UNDEFINED
= 0,
71 AU0828_VMUX_COMPOSITE
,
74 AU0828_VMUX_TELEVISION
,
80 enum au0828_itype type
;
83 void (*audio_setup
) (void *priv
, int enable
);
88 unsigned int tuner_type
;
89 unsigned char tuner_addr
;
90 unsigned char i2c_clk_divider
;
91 struct au0828_input input
[AU0828_MAX_INPUT
];
97 struct dvb_adapter adapter
;
98 struct dvb_frontend
*frontend
;
99 struct dvb_demux demux
;
100 struct dmxdev dmxdev
;
101 struct dmx_frontend fe_hw
;
102 struct dmx_frontend fe_mem
;
107 enum au0828_stream_state
{
113 #define AUVI_INPUT(nr) (dev->board.input[nr])
116 enum au0828_dev_state
{
117 DEV_INITIALIZED
= 0x01,
118 DEV_DISCONNECTED
= 0x02,
119 DEV_MISCONFIGURED
= 0x04
123 /* must be the first field of this struct! */
126 struct au0828_dev
*dev
;
127 unsigned int resources
;
129 struct videobuf_queue vb_vidq
;
130 struct videobuf_queue vb_vbiq
;
131 enum v4l2_buf_type type
;
134 struct au0828_usb_isoc_ctl
{
135 /* max packet size of isoc transaction */
138 /* number of allocated urbs */
141 /* urb for isoc transfers */
144 /* transfer buffers for isoc transfer */
145 char **transfer_buffer
;
147 /* Last buffer command and region */
149 int pos
, size
, pktsize
;
151 /* Last field: ODD or EVEN? */
154 /* Stores incomplete commands */
158 /* Stores already requested buffers */
159 struct au0828_buffer
*buf
;
160 struct au0828_buffer
*vbi_buf
;
162 /* Stores the number of received fields */
165 /* isoc urb callback */
166 int (*isoc_copy
) (struct au0828_dev
*dev
, struct urb
*urb
);
170 /* buffer for one video frame */
171 struct au0828_buffer
{
172 /* common v4l buffer stuff -- must be first */
173 struct videobuf_buffer vb
;
175 struct list_head frame
;
180 struct au0828_dmaqueue
{
181 struct list_head active
;
182 struct list_head queued
;
184 wait_queue_head_t wq
;
186 /* Counters to control buffer fill */
192 struct usb_device
*usbdev
;
194 struct au0828_board board
;
198 struct i2c_adapter i2c_adap
;
199 struct i2c_algorithm i2c_algo
;
200 struct i2c_client i2c_client
;
204 struct au0828_dvb dvb
;
205 struct work_struct restart_streaming
;
207 #ifdef CONFIG_VIDEO_AU0828_V4L2
209 struct v4l2_device v4l2_dev
;
210 struct v4l2_ctrl_handler v4l2_ctrl_hdl
;
213 unsigned int resources
; /* resources in use */
214 struct video_device
*vdev
;
215 struct video_device
*vbi_dev
;
216 struct timer_list vid_timeout
;
217 int vid_timeout_running
;
218 struct timer_list vbi_timeout
;
219 int vbi_timeout_running
;
231 __u8 isoc_in_endpointaddr
;
233 int greenscreen_detected
;
234 unsigned int frame_count
;
237 int std_set_in_tuner_core
;
238 unsigned int ctrl_input
;
239 enum au0828_dev_state dev_state
;
240 enum au0828_stream_state stream_state
;
241 wait_queue_head_t open
;
245 /* Isoc control struct */
246 struct au0828_dmaqueue vidq
;
247 struct au0828_dmaqueue vbiq
;
248 struct au0828_usb_isoc_ctl isoc_ctl
;
252 int alt
; /* alternate */
253 int max_pkt_size
; /* max packet size of isoc transaction */
254 int num_alt
; /* Number of alternative settings */
255 unsigned int *alt_max_pkt_size
; /* array of wMaxPacketSize */
256 struct urb
*urb
[AU0828_MAX_ISO_BUFS
]; /* urb for isoc transfers */
257 char *transfer_buffer
[AU0828_MAX_ISO_BUFS
];/* transfer buffers for isoc
260 /* USB / URB Related */
262 struct urb
*urbs
[URB_COUNT
];
265 /* ----------------------------------------------------------- */
266 #define au0828_read(dev, reg) au0828_readreg(dev, reg)
267 #define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
268 #define au0828_andor(dev, reg, mask, value) \
269 au0828_writereg(dev, reg, \
270 (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
272 #define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
273 #define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
275 /* ----------------------------------------------------------- */
277 extern u32
au0828_read(struct au0828_dev
*dev
, u16 reg
);
278 extern u32
au0828_write(struct au0828_dev
*dev
, u16 reg
, u32 val
);
279 extern int au0828_debug
;
281 /* ----------------------------------------------------------- */
283 extern struct au0828_board au0828_boards
[];
284 extern struct usb_device_id au0828_usb_id_table
[];
285 extern void au0828_gpio_setup(struct au0828_dev
*dev
);
286 extern int au0828_tuner_callback(void *priv
, int component
,
287 int command
, int arg
);
288 extern void au0828_card_setup(struct au0828_dev
*dev
);
290 /* ----------------------------------------------------------- */
292 extern int au0828_i2c_register(struct au0828_dev
*dev
);
293 extern int au0828_i2c_unregister(struct au0828_dev
*dev
);
295 /* ----------------------------------------------------------- */
297 int au0828_analog_register(struct au0828_dev
*dev
,
298 struct usb_interface
*interface
);
299 int au0828_analog_stream_disable(struct au0828_dev
*d
);
300 void au0828_analog_unregister(struct au0828_dev
*dev
);
302 /* ----------------------------------------------------------- */
304 extern int au0828_dvb_register(struct au0828_dev
*dev
);
305 extern void au0828_dvb_unregister(struct au0828_dev
*dev
);
308 extern struct videobuf_queue_ops au0828_vbi_qops
;
310 #define dprintk(level, fmt, arg...)\
311 do { if (au0828_debug & level)\
312 printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\