Full support for Ginger Console
[linux-ginger.git] / drivers / media / video / au0828 / au0828.h
blobb977915efbd0a0eaa52636c7e8cfb1c2a79d8a55
1 /*
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>
27 /* Analog */
28 #include <linux/videodev2.h>
29 #include <media/videobuf-vmalloc.h>
30 #include <media/v4l2-device.h>
32 /* DVB */
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"
40 #include "au0828-reg.h"
41 #include "au0828-cards.h"
43 #define DRIVER_NAME "au0828"
44 #define URB_COUNT 16
45 #define URB_BUFSIZE (0xe522)
47 /* Analog constants */
48 #define NTSC_STD_W 720
49 #define NTSC_STD_H 480
51 #define AU0828_INTERLACED_DEFAULT 1
52 #define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)
54 /* Defination for AU0828 USB transfer */
55 #define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */
56 #define AU0828_ISO_PACKETS_PER_URB 10
58 #define AU0828_MIN_BUF 4
59 #define AU0828_DEF_BUF 8
61 #define AU0828_MAX_INPUT 4
63 enum au0828_itype {
64 AU0828_VMUX_UNDEFINED = 0,
65 AU0828_VMUX_COMPOSITE,
66 AU0828_VMUX_SVIDEO,
67 AU0828_VMUX_CABLE,
68 AU0828_VMUX_TELEVISION,
69 AU0828_VMUX_DVB,
70 AU0828_VMUX_DEBUG
73 struct au0828_input {
74 enum au0828_itype type;
75 unsigned int vmux;
76 unsigned int amux;
77 void (*audio_setup) (void *priv, int enable);
80 struct au0828_board {
81 char *name;
82 unsigned int tuner_type;
83 unsigned char tuner_addr;
84 unsigned char i2c_clk_divider;
85 struct au0828_input input[AU0828_MAX_INPUT];
89 struct au0828_dvb {
90 struct mutex lock;
91 struct dvb_adapter adapter;
92 struct dvb_frontend *frontend;
93 struct dvb_demux demux;
94 struct dmxdev dmxdev;
95 struct dmx_frontend fe_hw;
96 struct dmx_frontend fe_mem;
97 struct dvb_net net;
98 int feeding;
101 enum au0828_stream_state {
102 STREAM_OFF,
103 STREAM_INTERRUPT,
104 STREAM_ON
107 #define AUVI_INPUT(nr) (dev->board.input[nr])
109 /* device state */
110 enum au0828_dev_state {
111 DEV_INITIALIZED = 0x01,
112 DEV_DISCONNECTED = 0x02,
113 DEV_MISCONFIGURED = 0x04
116 struct au0828_fh {
117 struct au0828_dev *dev;
118 unsigned int stream_on:1; /* Locks streams */
119 struct videobuf_queue vb_vidq;
120 enum v4l2_buf_type type;
123 struct au0828_usb_isoc_ctl {
124 /* max packet size of isoc transaction */
125 int max_pkt_size;
127 /* number of allocated urbs */
128 int num_bufs;
130 /* urb for isoc transfers */
131 struct urb **urb;
133 /* transfer buffers for isoc transfer */
134 char **transfer_buffer;
136 /* Last buffer command and region */
137 u8 cmd;
138 int pos, size, pktsize;
140 /* Last field: ODD or EVEN? */
141 int field;
143 /* Stores incomplete commands */
144 u32 tmp_buf;
145 int tmp_buf_len;
147 /* Stores already requested buffers */
148 struct au0828_buffer *buf;
150 /* Stores the number of received fields */
151 int nfields;
153 /* isoc urb callback */
154 int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
158 /* buffer for one video frame */
159 struct au0828_buffer {
160 /* common v4l buffer stuff -- must be first */
161 struct videobuf_buffer vb;
163 struct list_head frame;
164 int top_field;
165 int receiving;
168 struct au0828_dmaqueue {
169 struct list_head active;
170 struct list_head queued;
172 wait_queue_head_t wq;
174 /* Counters to control buffer fill */
175 int pos;
178 struct au0828_dev {
179 struct mutex mutex;
180 struct usb_device *usbdev;
181 int boardnr;
182 struct au0828_board board;
183 u8 ctrlmsg[64];
185 /* I2C */
186 struct i2c_adapter i2c_adap;
187 struct i2c_algorithm i2c_algo;
188 struct i2c_client i2c_client;
189 u32 i2c_rc;
191 /* Digital */
192 struct au0828_dvb dvb;
194 /* Analog */
195 struct list_head au0828list;
196 struct v4l2_device v4l2_dev;
197 int users;
198 unsigned int stream_on:1; /* Locks streams */
199 struct video_device *vdev;
200 struct video_device *vbi_dev;
201 int width;
202 int height;
203 u32 field_size;
204 u32 frame_size;
205 u32 bytesperline;
206 int type;
207 u8 ctrl_ainput;
208 __u8 isoc_in_endpointaddr;
209 u8 isoc_init_ok;
210 int greenscreen_detected;
211 unsigned int frame_count;
212 int ctrl_freq;
213 int input_type;
214 unsigned int ctrl_input;
215 enum au0828_dev_state dev_state;
216 enum au0828_stream_state stream_state;
217 wait_queue_head_t open;
219 struct mutex lock;
221 /* Isoc control struct */
222 struct au0828_dmaqueue vidq;
223 struct au0828_usb_isoc_ctl isoc_ctl;
224 spinlock_t slock;
226 /* usb transfer */
227 int alt; /* alternate */
228 int max_pkt_size; /* max packet size of isoc transaction */
229 int num_alt; /* Number of alternative settings */
230 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
231 struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */
232 char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc
233 transfer */
235 /* USB / URB Related */
236 int urb_streaming;
237 struct urb *urbs[URB_COUNT];
240 /* ----------------------------------------------------------- */
241 #define au0828_read(dev, reg) au0828_readreg(dev, reg)
242 #define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
243 #define au0828_andor(dev, reg, mask, value) \
244 au0828_writereg(dev, reg, \
245 (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
247 #define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
248 #define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
250 /* ----------------------------------------------------------- */
251 /* au0828-core.c */
252 extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
253 extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
254 extern int au0828_debug;
256 /* ----------------------------------------------------------- */
257 /* au0828-cards.c */
258 extern struct au0828_board au0828_boards[];
259 extern struct usb_device_id au0828_usb_id_table[];
260 extern void au0828_gpio_setup(struct au0828_dev *dev);
261 extern int au0828_tuner_callback(void *priv, int component,
262 int command, int arg);
263 extern void au0828_card_setup(struct au0828_dev *dev);
265 /* ----------------------------------------------------------- */
266 /* au0828-i2c.c */
267 extern int au0828_i2c_register(struct au0828_dev *dev);
268 extern int au0828_i2c_unregister(struct au0828_dev *dev);
270 /* ----------------------------------------------------------- */
271 /* au0828-video.c */
272 int au0828_analog_register(struct au0828_dev *dev,
273 struct usb_interface *interface);
274 int au0828_analog_stream_disable(struct au0828_dev *d);
275 void au0828_analog_unregister(struct au0828_dev *dev);
277 /* ----------------------------------------------------------- */
278 /* au0828-dvb.c */
279 extern int au0828_dvb_register(struct au0828_dev *dev);
280 extern void au0828_dvb_unregister(struct au0828_dev *dev);
282 #define dprintk(level, fmt, arg...)\
283 do { if (au0828_debug & level)\
284 printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
285 } while (0)