]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/video/au0828/au0828.h
V4L/DVB (11069): au8522: add mutex protecting use of hybrid state
[mirror_ubuntu-artful-kernel.git] / drivers / media / video / au0828 / au0828.h
CommitLineData
265a6510
ST
1/*
2 * Driver for the Auvitek AU0828 USB bridge
3 *
6d897616 4 * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
265a6510
ST
5 *
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.
10 *
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
14 *
15 * GNU General Public License for more details.
16 *
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.
20 */
21
22#include <linux/usb.h>
23#include <linux/i2c.h>
24#include <linux/i2c-algo-bit.h>
28930fa9 25#include <media/tveeprom.h>
265a6510 26
8b2f0795
DH
27/* Analog */
28#include <linux/videodev2.h>
29#include <media/videobuf-vmalloc.h>
30
265a6510
ST
31/* DVB */
32#include "demux.h"
33#include "dmxdev.h"
34#include "dvb_demux.h"
35#include "dvb_frontend.h"
36#include "dvb_net.h"
37#include "dvbdev.h"
38
39#include "au0828-reg.h"
40#include "au0828-cards.h"
41
42#define DRIVER_NAME "au0828"
43#define URB_COUNT 16
265a6510
ST
44#define URB_BUFSIZE (0xe522)
45
8b2f0795
DH
46/* Analog constants */
47#define NTSC_STD_W 720
48#define NTSC_STD_H 480
49
50#define AU0828_INTERLACED_DEFAULT 1
51#define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)
52
53/* Defination for AU0828 USB transfer */
54#define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */
55#define AU0828_ISO_PACKETS_PER_URB 10
56#define AU0828_ISO_MAX_FRAME_SIZE (3 * 1024)
57#define AU0828_ISO_BUFFER_SIZE (AU0828_ISO_PACKETS_PER_URB * AU0828_ISO_MAX_FRAME_SIZE)
58
59#define AU0828_MIN_BUF 4
60#define AU0828_DEF_BUF 8
61
62#define AU0828_MAX_IMAGES 10
63#define AU0828_FRAME_SIZE (1028 * 1024 * 4)
64#define AU0828_URB_TIMEOUT msecs_to_jiffies(AU0828_MAX_ISO_BUFS * AU0828_ISO_PACKETS_PER_URB)
65
66#define AU0828_MAX_INPUT 4
67
68enum au0828_itype {
69 AU0828_VMUX_COMPOSITE = 1,
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
265a6510
ST
84struct au0828_board {
85 char *name;
8b2f0795
DH
86 struct au0828_input input[AU0828_MAX_INPUT];
87
265a6510
ST
88};
89
90struct au0828_dvb {
91 struct mutex lock;
92 struct dvb_adapter adapter;
93 struct dvb_frontend *frontend;
94 struct dvb_demux demux;
95 struct dmxdev dmxdev;
96 struct dmx_frontend fe_hw;
97 struct dmx_frontend fe_mem;
98 struct dvb_net net;
99 int feeding;
100};
101
8b2f0795
DH
102enum au0828_stream_state {
103 STREAM_OFF,
104 STREAM_INTERRUPT,
105 STREAM_ON
106};
107
108#define AUVI_INPUT(nr) (&au0828_boards[dev->board].input[nr])
109
110/* device state */
111enum au0828_dev_state {
112 DEV_INITIALIZED = 0x01,
113 DEV_DISCONNECTED = 0x02,
114 DEV_MISCONFIGURED = 0x04
115};
116
117struct au0828_fh {
118 struct au0828_dev *dev;
119 unsigned int stream_on:1; /* Locks streams */
120 struct videobuf_queue vb_vidq;
121 enum v4l2_buf_type type;
122};
123
124struct au0828_usb_isoc_ctl {
125 /* max packet size of isoc transaction */
126 int max_pkt_size;
127
128 /* number of allocated urbs */
129 int num_bufs;
130
131 /* urb for isoc transfers */
132 struct urb **urb;
133
134 /* transfer buffers for isoc transfer */
135 char **transfer_buffer;
136
137 /* Last buffer command and region */
138 u8 cmd;
139 int pos, size, pktsize;
140
141 /* Last field: ODD or EVEN? */
142 int field;
143
144 /* Stores incomplete commands */
145 u32 tmp_buf;
146 int tmp_buf_len;
147
148 /* Stores already requested buffers */
149 struct au0828_buffer *buf;
150
151 /* Stores the number of received fields */
152 int nfields;
153
154 /* isoc urb callback */
155 int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
156
157};
158
159/* buffer for one video frame */
160struct au0828_buffer {
161 /* common v4l buffer stuff -- must be first */
162 struct videobuf_buffer vb;
163
164 struct list_head frame;
165 int top_field;
166 int receiving;
167};
168
169struct au0828_dmaqueue {
170 struct list_head active;
171 struct list_head queued;
172
173 wait_queue_head_t wq;
174
175 /* Counters to control buffer fill */
176 int pos;
177};
178
265a6510
ST
179struct au0828_dev {
180 struct mutex mutex;
181 struct usb_device *usbdev;
182 int board;
183 u8 ctrlmsg[64];
184
185 /* I2C */
186 struct i2c_adapter i2c_adap;
187 struct i2c_algo_bit_data i2c_algo;
188 struct i2c_client i2c_client;
189 u32 i2c_rc;
190
191 /* Digital */
192 struct au0828_dvb dvb;
193
8b2f0795
DH
194 /* Analog */
195 struct list_head au0828list;
196 int users;
197 unsigned int stream_on:1; /* Locks streams */
198 struct video_device *vdev;
199 struct video_device *vbi_dev;
200 int width;
201 int height;
202 u32 field_size;
203 u32 frame_size;
204 u32 bytesperline;
205 int type;
206 u8 ctrl_ainput;
207 __u8 isoc_in_endpointaddr;
208 u8 isoc_init_ok;
209 int greenscreen_detected;
210 unsigned int frame_count;
211 int ctrl_freq;
212 int input_type;
213 unsigned int ctrl_input;
214 enum au0828_dev_state dev_state;
215 enum au0828_stream_state stream_state;
216 wait_queue_head_t open;
217
218 struct mutex lock;
219
220 /* Isoc control struct */
221 struct au0828_dmaqueue vidq;
222 struct au0828_usb_isoc_ctl isoc_ctl;
223 spinlock_t slock;
224
225 /* usb transfer */
226 int alt; /* alternate */
227 int max_pkt_size; /* max packet size of isoc transaction */
228 int num_alt; /* Number of alternative settings */
229 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
230 struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */
231 char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc
232 transfer */
233
265a6510
ST
234 /* USB / URB Related */
235 int urb_streaming;
236 struct urb *urbs[URB_COUNT];
265a6510
ST
237};
238
239/* ----------------------------------------------------------- */
18d73c58
MCC
240#define au0828_read(dev, reg) au0828_readreg(dev, reg)
241#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
242#define au0828_andor(dev, reg, mask, value) \
243 au0828_writereg(dev, reg, \
244 (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
245
246#define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
247#define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
265a6510
ST
248
249/* ----------------------------------------------------------- */
250/* au0828-core.c */
251extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
252extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
b33d24c4 253extern int au0828_debug;
265a6510
ST
254
255/* ----------------------------------------------------------- */
256/* au0828-cards.c */
257extern struct au0828_board au0828_boards[];
258extern struct usb_device_id au0828_usb_id_table[];
265a6510 259extern void au0828_gpio_setup(struct au0828_dev *dev);
d7cba043
MK
260extern int au0828_tuner_callback(void *priv, int component,
261 int command, int arg);
28930fa9 262extern void au0828_card_setup(struct au0828_dev *dev);
265a6510
ST
263
264/* ----------------------------------------------------------- */
265/* au0828-i2c.c */
266extern int au0828_i2c_register(struct au0828_dev *dev);
267extern int au0828_i2c_unregister(struct au0828_dev *dev);
268extern void au0828_call_i2c_clients(struct au0828_dev *dev,
269 unsigned int cmd, void *arg);
270
8b2f0795
DH
271/* ----------------------------------------------------------- */
272/* au0828-video.c */
273int au0828_analog_register(struct au0828_dev *dev);
274int au0828_analog_stream_disable(struct au0828_dev *d);
275void au0828_analog_unregister(struct au0828_dev *dev);
276
265a6510
ST
277/* ----------------------------------------------------------- */
278/* au0828-dvb.c */
279extern int au0828_dvb_register(struct au0828_dev *dev);
280extern void au0828_dvb_unregister(struct au0828_dev *dev);
bc3c613c
ST
281
282#define dprintk(level, fmt, arg...)\
b33d24c4 283 do { if (au0828_debug & level)\
bc3c613c
ST
284 printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
285 } while (0)