]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/media/usb/au0828/au0828.h
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[mirror_ubuntu-hirsute-kernel.git] / drivers / media / usb / 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
83afb32a
MCC
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
e8e3039f 24#include <linux/bitops.h>
265a6510
ST
25#include <linux/usb.h>
26#include <linux/i2c.h>
27#include <linux/i2c-algo-bit.h>
28930fa9 28#include <media/tveeprom.h>
265a6510 29
8b2f0795
DH
30/* Analog */
31#include <linux/videodev2.h>
2d700715 32#include <media/videobuf2-v4l2.h>
05439b1a 33#include <media/videobuf2-vmalloc.h>
b14667f3 34#include <media/v4l2-device.h>
e8c26f45 35#include <media/v4l2-ctrls.h>
83b09422 36#include <media/v4l2-fh.h>
bed69196 37#include <media/media-device.h>
8b2f0795 38
265a6510
ST
39/* DVB */
40#include "demux.h"
41#include "dmxdev.h"
42#include "dvb_demux.h"
43#include "dvb_frontend.h"
44#include "dvb_net.h"
45#include "dvbdev.h"
46
47#include "au0828-reg.h"
48#include "au0828-cards.h"
49
265a6510 50#define URB_COUNT 16
265a6510
ST
51#define URB_BUFSIZE (0xe522)
52
8b2f0795
DH
53/* Analog constants */
54#define NTSC_STD_W 720
55#define NTSC_STD_H 480
56
57#define AU0828_INTERLACED_DEFAULT 1
58#define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)
59
60/* Defination for AU0828 USB transfer */
61#define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */
83f859c5 62#define AU0828_ISO_PACKETS_PER_URB 128
8b2f0795
DH
63
64#define AU0828_MIN_BUF 4
65#define AU0828_DEF_BUF 8
66
8b2f0795
DH
67#define AU0828_MAX_INPUT 4
68
7f8eacd2
DH
69/* au0828 resource types (used for res_get/res_lock etc */
70#define AU0828_RESOURCE_VIDEO 0x01
71#define AU0828_RESOURCE_VBI 0x02
72
8b2f0795 73enum au0828_itype {
220be77c
DH
74 AU0828_VMUX_UNDEFINED = 0,
75 AU0828_VMUX_COMPOSITE,
8b2f0795
DH
76 AU0828_VMUX_SVIDEO,
77 AU0828_VMUX_CABLE,
78 AU0828_VMUX_TELEVISION,
79 AU0828_VMUX_DVB,
8b2f0795
DH
80};
81
82struct au0828_input {
83 enum au0828_itype type;
84 unsigned int vmux;
85 unsigned int amux;
86 void (*audio_setup) (void *priv, int enable);
87};
88
265a6510
ST
89struct au0828_board {
90 char *name;
f1add5b5
DH
91 unsigned int tuner_type;
92 unsigned char tuner_addr;
16af6f5a 93 unsigned char i2c_clk_divider;
2fcfd317 94 unsigned char has_ir_i2c:1;
b13b47e0 95 unsigned char has_analog:1;
8b2f0795 96 struct au0828_input input[AU0828_MAX_INPUT];
265a6510
ST
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;
4609981f
TM
109 int start_count;
110 int stop_count;
f6fef863
MCC
111
112 int (*set_frontend)(struct dvb_frontend *fe);
265a6510
ST
113};
114
8b2f0795
DH
115enum au0828_stream_state {
116 STREAM_OFF,
117 STREAM_INTERRUPT,
118 STREAM_ON
119};
120
f1add5b5 121#define AUVI_INPUT(nr) (dev->board.input[nr])
8b2f0795
DH
122
123/* device state */
124enum au0828_dev_state {
e8e3039f
MCC
125 DEV_INITIALIZED = 0,
126 DEV_DISCONNECTED = 1,
127 DEV_MISCONFIGURED = 2
8b2f0795
DH
128};
129
05439b1a 130struct au0828_dev;
8b2f0795
DH
131
132struct au0828_usb_isoc_ctl {
133 /* max packet size of isoc transaction */
134 int max_pkt_size;
135
136 /* number of allocated urbs */
137 int num_bufs;
138
139 /* urb for isoc transfers */
140 struct urb **urb;
141
142 /* transfer buffers for isoc transfer */
143 char **transfer_buffer;
144
145 /* Last buffer command and region */
146 u8 cmd;
147 int pos, size, pktsize;
148
149 /* Last field: ODD or EVEN? */
150 int field;
151
152 /* Stores incomplete commands */
153 u32 tmp_buf;
154 int tmp_buf_len;
155
156 /* Stores already requested buffers */
7f8eacd2
DH
157 struct au0828_buffer *buf;
158 struct au0828_buffer *vbi_buf;
8b2f0795
DH
159
160 /* Stores the number of received fields */
161 int nfields;
162
163 /* isoc urb callback */
164 int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
165
166};
167
168/* buffer for one video frame */
169struct au0828_buffer {
170 /* common v4l buffer stuff -- must be first */
2d700715 171 struct vb2_v4l2_buffer vb;
05439b1a 172 struct list_head list;
8b2f0795 173
05439b1a
SK
174 void *mem;
175 unsigned long length;
8b2f0795 176 int top_field;
05439b1a
SK
177 /* pointer to vmalloc memory address in vb */
178 char *vb_buf;
8b2f0795
DH
179};
180
181struct au0828_dmaqueue {
182 struct list_head active;
8b2f0795 183 /* Counters to control buffer fill */
05439b1a 184 int pos;
8b2f0795
DH
185};
186
265a6510
ST
187struct au0828_dev {
188 struct mutex mutex;
189 struct usb_device *usbdev;
f1add5b5
DH
190 int boardnr;
191 struct au0828_board board;
265a6510
ST
192 u8 ctrlmsg[64];
193
194 /* I2C */
195 struct i2c_adapter i2c_adap;
b14667f3 196 struct i2c_algorithm i2c_algo;
265a6510
ST
197 struct i2c_client i2c_client;
198 u32 i2c_rc;
199
200 /* Digital */
201 struct au0828_dvb dvb;
43f2cccf 202 struct work_struct restart_streaming;
265a6510 203
8a4e7866 204#ifdef CONFIG_VIDEO_AU0828_V4L2
8b2f0795 205 /* Analog */
b14667f3 206 struct v4l2_device v4l2_dev;
e8c26f45 207 struct v4l2_ctrl_handler v4l2_ctrl_hdl;
8a4e7866 208#endif
2fcfd317
MCC
209#ifdef CONFIG_VIDEO_AU0828_RC
210 struct au0828_rc *ir;
211#endif
212
41071bb8
SK
213 struct video_device vdev;
214 struct video_device vbi_dev;
05439b1a
SK
215
216 /* Videobuf2 */
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
6e04b7b9 225 struct timer_list vid_timeout;
78ca5005 226 int vid_timeout_running;
6e04b7b9 227 struct timer_list vbi_timeout;
78ca5005 228 int vbi_timeout_running;
05439b1a
SK
229
230 int users;
231 int streaming_users;
232
8b2f0795
DH
233 int width;
234 int height;
7f8eacd2
DH
235 int vbi_width;
236 int vbi_height;
237 u32 vbi_read;
33b6b89b 238 v4l2_std_id std;
8b2f0795
DH
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;
8b2f0795
DH
247 int ctrl_freq;
248 int input_type;
c98bc032 249 int std_set_in_tuner_core;
8b2f0795 250 unsigned int ctrl_input;
e8e3039f 251 long unsigned int dev_state; /* defined at enum au0828_dev_state */;
8b2f0795
DH
252 enum au0828_stream_state stream_state;
253 wait_queue_head_t open;
254
255 struct mutex lock;
256
257 /* Isoc control struct */
258 struct au0828_dmaqueue vidq;
7f8eacd2 259 struct au0828_dmaqueue vbiq;
8b2f0795
DH
260 struct au0828_usb_isoc_ctl isoc_ctl;
261 spinlock_t slock;
262
263 /* usb transfer */
264 int alt; /* alternate */
265 int max_pkt_size; /* max packet size of isoc transaction */
266 int num_alt; /* Number of alternative settings */
267 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
268 struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */
269 char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc
270 transfer */
271
2930977a
MCC
272 /* DVB USB / URB Related */
273 bool urb_streaming, need_urb_start;
265a6510 274 struct urb *urbs[URB_COUNT];
f251b3e7
TM
275
276 /* Preallocated transfer digital transfer buffers */
277
278 char *dig_transfer_buffer[URB_COUNT];
bed69196
RLLC
279
280#ifdef CONFIG_MEDIA_CONTROLLER
281 struct media_device *media_dev;
282 struct media_pad video_pad, vbi_pad;
0158e7b6 283 struct media_entity *decoder;
d1f33737
MCC
284 struct media_entity input_ent[AU0828_MAX_INPUT];
285 struct media_pad input_pad[AU0828_MAX_INPUT];
f90c5d79 286 struct media_entity_notify entity_notify;
c94903f1
SK
287 struct media_entity *tuner;
288 struct media_link *active_link;
289 struct media_entity *active_link_owner;
290 struct media_entity *active_source;
291 struct media_entity *active_sink;
bed69196 292#endif
265a6510
ST
293};
294
05439b1a 295
265a6510 296/* ----------------------------------------------------------- */
18d73c58
MCC
297#define au0828_read(dev, reg) au0828_readreg(dev, reg)
298#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
299#define au0828_andor(dev, reg, mask, value) \
300 au0828_writereg(dev, reg, \
301 (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
302
303#define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
304#define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
265a6510
ST
305
306/* ----------------------------------------------------------- */
307/* au0828-core.c */
308extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
309extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
7b606ffd 310extern void au0828_usb_release(struct au0828_dev *dev);
b33d24c4 311extern int au0828_debug;
265a6510
ST
312
313/* ----------------------------------------------------------- */
314/* au0828-cards.c */
315extern struct au0828_board au0828_boards[];
316extern struct usb_device_id au0828_usb_id_table[];
265a6510 317extern void au0828_gpio_setup(struct au0828_dev *dev);
d7cba043
MK
318extern int au0828_tuner_callback(void *priv, int component,
319 int command, int arg);
28930fa9 320extern void au0828_card_setup(struct au0828_dev *dev);
265a6510
ST
321
322/* ----------------------------------------------------------- */
323/* au0828-i2c.c */
324extern int au0828_i2c_register(struct au0828_dev *dev);
325extern int au0828_i2c_unregister(struct au0828_dev *dev);
265a6510 326
8b2f0795
DH
327/* ----------------------------------------------------------- */
328/* au0828-video.c */
05439b1a
SK
329extern int au0828_start_analog_streaming(struct vb2_queue *vq,
330 unsigned int count);
331extern void au0828_stop_vbi_streaming(struct vb2_queue *vq);
1a1ba95e 332#ifdef CONFIG_VIDEO_AU0828_V4L2
7b606ffd
MCC
333extern int au0828_v4l2_device_register(struct usb_interface *interface,
334 struct au0828_dev *dev);
335
336extern int au0828_analog_register(struct au0828_dev *dev,
337 struct usb_interface *interface);
338extern int au0828_analog_unregister(struct au0828_dev *dev);
339extern void au0828_usb_v4l2_media_release(struct au0828_dev *dev);
05439b1a
SK
340extern void au0828_v4l2_suspend(struct au0828_dev *dev);
341extern void au0828_v4l2_resume(struct au0828_dev *dev);
1a1ba95e 342#else
7b606ffd
MCC
343static inline int au0828_v4l2_device_register(struct usb_interface *interface,
344 struct au0828_dev *dev)
345{ return 0; };
346static inline int au0828_analog_register(struct au0828_dev *dev,
347 struct usb_interface *interface)
348{ return 0; };
349static inline int au0828_analog_unregister(struct au0828_dev *dev)
350{ return 0; };
351static inline void au0828_usb_v4l2_media_release(struct au0828_dev *dev) { };
1a1ba95e
MCC
352static inline void au0828_v4l2_suspend(struct au0828_dev *dev) { };
353static inline void au0828_v4l2_resume(struct au0828_dev *dev) { };
354#endif
8b2f0795 355
265a6510
ST
356/* ----------------------------------------------------------- */
357/* au0828-dvb.c */
358extern int au0828_dvb_register(struct au0828_dev *dev);
359extern void au0828_dvb_unregister(struct au0828_dev *dev);
b799de75
MCC
360void au0828_dvb_suspend(struct au0828_dev *dev);
361void au0828_dvb_resume(struct au0828_dev *dev);
bc3c613c 362
7f8eacd2 363/* au0828-vbi.c */
05439b1a 364extern struct vb2_ops au0828_vbi_qops;
7f8eacd2 365
bc3c613c 366#define dprintk(level, fmt, arg...)\
b33d24c4 367 do { if (au0828_debug & level)\
83afb32a 368 printk(KERN_DEBUG pr_fmt(fmt), ## arg);\
bc3c613c 369 } while (0)
2fcfd317
MCC
370
371/* au0828-input.c */
917cbcde
SK
372#ifdef CONFIG_VIDEO_AU0828_RC
373extern int au0828_rc_register(struct au0828_dev *dev);
374extern void au0828_rc_unregister(struct au0828_dev *dev);
375extern int au0828_rc_suspend(struct au0828_dev *dev);
376extern int au0828_rc_resume(struct au0828_dev *dev);
377#else
378static inline int au0828_rc_register(struct au0828_dev *dev) { return 0; }
379static inline void au0828_rc_unregister(struct au0828_dev *dev) { }
380static inline int au0828_rc_suspend(struct au0828_dev *dev) { return 0; }
381static inline int au0828_rc_resume(struct au0828_dev *dev) { return 0; }
382#endif