]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/usb/em28xx/em28xx.h
[media] em28xx: check if a device has audio earlier
[mirror_ubuntu-artful-kernel.git] / drivers / media / usb / em28xx / em28xx.h
CommitLineData
a6c2ba28 1/*
0e7072ef 2 em28xx.h - driver for Empia EM2800/EM2820/2840 USB video capture devices
a6c2ba28 3
4 Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
4ac97914 5 Ludovico Cavedon <cavedon@sssup.it>
2e7c6dc3 6 Mauro Carvalho Chehab <mchehab@infradead.org>
0cf544a6 7 Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
a6c2ba28 8
9 Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
3acf2809
MCC
26#ifndef _EM28XX_H
27#define _EM28XX_H
a6c2ba28 28
01c28193 29#define EM28XX_VERSION "0.2.1"
ce67943e 30
39a96b4c
MCC
31#include <linux/workqueue.h>
32#include <linux/i2c.h>
33#include <linux/mutex.h>
cb77d010 34#include <linux/videodev2.h>
39a96b4c 35
d3829fad 36#include <media/videobuf2-vmalloc.h>
f2cf250a 37#include <media/v4l2-device.h>
081b945e 38#include <media/v4l2-ctrls.h>
69a61642 39#include <media/v4l2-fh.h>
d5e52653 40#include <media/ir-kbd-i2c.h>
6bda9644 41#include <media/rc-core.h>
3ca9c093 42#include "tuner-xc2028.h"
82e7dbbd 43#include "xc5000.h"
2ba890ec 44#include "em28xx-reg.h"
3aefb79a
MCC
45
46/* Boards supported by driver */
d5b6a746
FS
47#define EM2800_BOARD_UNKNOWN 0
48#define EM2820_BOARD_UNKNOWN 1
49#define EM2820_BOARD_TERRATEC_CINERGY_250 2
50#define EM2820_BOARD_PINNACLE_USB_2 3
51#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
52#define EM2820_BOARD_MSI_VOX_USB_2 5
53#define EM2800_BOARD_TERRATEC_CINERGY_200 6
54#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
55#define EM2800_BOARD_KWORLD_USB2800 8
56#define EM2820_BOARD_PINNACLE_DVC_90 9
57#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
58#define EM2880_BOARD_TERRATEC_HYBRID_XS 11
59#define EM2820_BOARD_KWORLD_PVRTV2800RF 12
60#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
61#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
62#define EM2800_BOARD_VGEAR_POCKETTV 15
63#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 16
64#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17
65#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18
66#define EM2860_BOARD_SAA711X_REFERENCE_DESIGN 19
67#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 20
68#define EM2800_BOARD_GRABBEEX_USB2800 21
95b86a9a
DSL
69#define EM2750_BOARD_UNKNOWN 22
70#define EM2750_BOARD_DLCW_130 23
71#define EM2820_BOARD_DLINK_USB_TV 24
72#define EM2820_BOARD_GADMEI_UTV310 25
73#define EM2820_BOARD_HERCULES_SMART_TV_USB2 26
74#define EM2820_BOARD_PINNACLE_USB_2_FM1216ME 27
75#define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28
443fed9f 76#define EM2860_BOARD_TVP5150_REFERENCE_DESIGN 29
95b86a9a
DSL
77#define EM2820_BOARD_VIDEOLOGY_20K14XUSB 30
78#define EM2821_BOARD_USBGEAR_VD204 31
79#define EM2821_BOARD_SUPERCOMP_USB_2 32
8298f2f8 80#define EM2860_BOARD_ELGATO_VIDEO_CAPTURE 33
95b86a9a
DSL
81#define EM2860_BOARD_TERRATEC_HYBRID_XS 34
82#define EM2860_BOARD_TYPHOON_DVD_MAKER 35
83#define EM2860_BOARD_NETGMBH_CAM 36
84#define EM2860_BOARD_GADMEI_UTV330 37
85#define EM2861_BOARD_YAKUMO_MOVIE_MIXER 38
86#define EM2861_BOARD_KWORLD_PVRTV_300U 39
87#define EM2861_BOARD_PLEXTOR_PX_TV100U 40
88#define EM2870_BOARD_KWORLD_350U 41
89#define EM2870_BOARD_KWORLD_355U 42
90#define EM2870_BOARD_TERRATEC_XS 43
91#define EM2870_BOARD_TERRATEC_XS_MT2060 44
92#define EM2870_BOARD_PINNACLE_PCTV_DVB 45
93#define EM2870_BOARD_COMPRO_VIDEOMATE 46
94#define EM2880_BOARD_KWORLD_DVB_305U 47
95#define EM2880_BOARD_KWORLD_DVB_310U 48
96#define EM2880_BOARD_MSI_DIGIVOX_AD 49
97#define EM2880_BOARD_MSI_DIGIVOX_AD_II 50
98#define EM2880_BOARD_TERRATEC_HYBRID_XS_FR 51
99#define EM2881_BOARD_DNT_DA2_HYBRID 52
100#define EM2881_BOARD_PINNACLE_HYBRID_PRO 53
101#define EM2882_BOARD_KWORLD_VS_DVBT 54
102#define EM2882_BOARD_TERRATEC_HYBRID_XS 55
09bc1942 103#define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E 56
d5b6a746 104#define EM2883_BOARD_KWORLD_HYBRID_330U 57
ee281b85 105#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58
f89bc329 106#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60
1e1addd5 107#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61
f7fe3e6f 108#define EM2820_BOARD_GADMEI_TVR200 62
d5b6a746
FS
109#define EM2860_BOARD_KAIOMY_TVNPC_U2 63
110#define EM2860_BOARD_EASYCAP 64
f74a61e3 111#define EM2820_BOARD_IODATA_GVMVP_SZ 65
e5db5d44 112#define EM2880_BOARD_EMPIRE_DUAL_TV 66
4557af9c 113#define EM2860_BOARD_TERRATEC_GRABBY 67
766ed64d 114#define EM2860_BOARD_TERRATEC_AV350 68
d7de5d8f 115#define EM2882_BOARD_KWORLD_ATSC_315U 69
19859229 116#define EM2882_BOARD_EVGA_INDTUBE 70
d5b6a746
FS
117#define EM2820_BOARD_SILVERCREST_WEBCAM 71
118#define EM2861_BOARD_GADMEI_UTV330PLUS 72
119#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73
694a101e 120#define EM2800_BOARD_VC211A 74
7ca7ef60 121#define EM2882_BOARD_DIKOM_DK300 75
7e48b30a 122#define EM2870_BOARD_KWORLD_A340 76
fec528b7 123#define EM2874_BOARD_LEADERSHIP_ISDBT 77
d5b6a746 124#define EM28174_BOARD_PCTV_290E 78
fec528b7 125#define EM2884_BOARD_TERRATEC_H5 79
d5b6a746 126#define EM28174_BOARD_PCTV_460E 80
82e7dbbd 127#define EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C 81
a1ed02e9 128#define EM2884_BOARD_CINERGY_HTC_STICK 82
d5b6a746
FS
129#define EM2860_BOARD_HT_VIDBOX_NW03 83
130#define EM2874_BOARD_MAXMEDIA_UB425_TC 84
131#define EM2884_BOARD_PCTV_510E 85
132#define EM2884_BOARD_PCTV_520E 86
89040136 133#define EM2884_BOARD_TERRATEC_HTC_USB_XS 87
4159d01b 134#define EM2884_BOARD_C3TECH_DIGITAL_DUO 88
7c1dfdb0 135#define EM2874_BOARD_DELOCK_61959 89
6dbea9f0 136#define EM2874_BOARD_KWORLD_UB435Q_V2 90
0c37e736 137#define EM2765_BOARD_SPEEDLINK_VAD_LAPLACE 91
ec573362 138#define EM28178_BOARD_PCTV_461E 92
3aefb79a
MCC
139
140/* Limits minimum and default number of buffers */
141#define EM28XX_MIN_BUF 4
142#define EM28XX_DEF_BUF 8
a6c2ba28 143
c4a98793
MCC
144/*Limits the max URB message size */
145#define URB_MAX_CTRL_SIZE 80
146
95b86a9a
DSL
147/* Params for validated field */
148#define EM28XX_BOARD_NOT_VALIDATED 1
149#define EM28XX_BOARD_VALIDATED 0
150
22cff7b3
DSL
151/* Params for em28xx_cmd() audio */
152#define EM28XX_START_AUDIO 1
153#define EM28XX_STOP_AUDIO 0
154
596d92d5 155/* maximum number of em28xx boards */
3687e1e6 156#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */
596d92d5 157
a6c2ba28 158/* maximum number of frames that can be queued */
3acf2809 159#define EM28XX_NUM_FRAMES 5
a6c2ba28 160/* number of frames that get used for v4l2_read() */
3acf2809 161#define EM28XX_NUM_READ_FRAMES 2
a6c2ba28 162
163/* number of buffers for isoc transfers */
3acf2809 164#define EM28XX_NUM_BUFS 5
86d38d1e 165#define EM28XX_DVB_NUM_BUFS 5
a6c2ba28 166
c7a45e5b
MCC
167/* max number of I2C buses on em28xx devices */
168#define NUM_I2C_BUSES 2
169
515688a8 170/* isoc transfers: number of packets for each buffer
33c02fac 171 windows requests only 64 packets .. so we better do the same
d5e52653
MCC
172 this is what I found out for all alternate numbers there!
173 */
515688a8
FS
174#define EM28XX_NUM_ISOC_PACKETS 64
175#define EM28XX_DVB_NUM_ISOC_PACKETS 64
a6c2ba28 176
c647a91a
FS
177/* bulk transfers: transfer buffer size = packet size * packet multiplier
178 USB 2.0 spec says bulk packet size is always 512 bytes
179 */
180#define EM28XX_BULK_PACKET_MULTIPLIER 384
181#define EM28XX_DVB_BULK_PACKET_MULTIPLIER 384
182
3acf2809 183#define EM28XX_INTERLACED_DEFAULT 1
a6c2ba28 184
596d92d5 185/* time in msecs to wait for i2c writes to finish */
2fcc82d8 186#define EM2800_I2C_XFER_TIMEOUT 20
596d92d5 187
f5222609
FS
188/* max. number of button state polling addresses */
189#define EM28XX_NUM_BUTTON_ADDRESSES_MAX 5
190
3aefb79a 191enum em28xx_mode {
2fe3e2ee 192 EM28XX_SUSPEND,
3aefb79a
MCC
193 EM28XX_ANALOG_MODE,
194 EM28XX_DIGITAL_MODE,
195};
196
a6c2ba28 197
579f72e4
AT
198struct em28xx;
199
f0fa9936 200struct em28xx_usb_bufs {
ad0ebb96
MCC
201 /* max packet size of isoc transaction */
202 int max_pkt_size;
203
86d38d1e
GG
204 /* number of packets in each buffer */
205 int num_packets;
206
ad0ebb96
MCC
207 /* number of allocated urbs */
208 int num_bufs;
209
f0fa9936 210 /* urb for isoc/bulk transfers */
ad0ebb96
MCC
211 struct urb **urb;
212
f0fa9936 213 /* transfer buffers for isoc/bulk transfer */
ad0ebb96 214 char **transfer_buffer;
86d38d1e
GG
215};
216
74209dc0
FS
217struct em28xx_usb_ctl {
218 /* isoc/bulk transfer buffers for analog mode */
f0fa9936 219 struct em28xx_usb_bufs analog_bufs;
86d38d1e 220
74209dc0 221 /* isoc/bulk transfer buffers for digital mode */
f0fa9936 222 struct em28xx_usb_bufs digital_bufs;
ad0ebb96 223
ad0ebb96 224 /* Stores already requested buffers */
28abf083
DH
225 struct em28xx_buffer *vid_buf;
226 struct em28xx_buffer *vbi_buf;
ad0ebb96 227
74209dc0
FS
228 /* copy data from URB */
229 int (*urb_data_copy) (struct em28xx *dev, struct urb *urb);
579f72e4 230
ad0ebb96
MCC
231};
232
bddcf633 233/* Struct to enumberate video formats */
ad0ebb96
MCC
234struct em28xx_fmt {
235 char *name;
236 u32 fourcc; /* v4l2 format id */
bddcf633
MCC
237 int depth;
238 int reg;
ad0ebb96
MCC
239};
240
241/* buffer for one video frame */
242struct em28xx_buffer {
243 /* common v4l buffer stuff -- must be first */
d3829fad
DH
244 struct vb2_buffer vb;
245 struct list_head list;
ad0ebb96 246
d3829fad
DH
247 void *mem;
248 unsigned int length;
a6c2ba28 249 int top_field;
8732533b
FS
250
251 /* counter to control buffer fill */
252 unsigned int pos;
253 /* NOTE; in interlaced mode, this value is reset to zero at
254 * the start of each new field (not frame !) */
4078d625
FS
255
256 /* pointer to vmalloc memory address in vb */
257 char *vb_buf;
ad0ebb96
MCC
258};
259
260struct em28xx_dmaqueue {
261 struct list_head active;
ad0ebb96
MCC
262
263 wait_queue_head_t wq;
a6c2ba28 264};
265
a6c2ba28 266/* inputs */
267
3acf2809
MCC
268#define MAX_EM28XX_INPUT 4
269enum enum28xx_itype {
270 EM28XX_VMUX_COMPOSITE1 = 1,
271 EM28XX_VMUX_COMPOSITE2,
272 EM28XX_VMUX_COMPOSITE3,
273 EM28XX_VMUX_COMPOSITE4,
274 EM28XX_VMUX_SVIDEO,
275 EM28XX_VMUX_TELEVISION,
276 EM28XX_VMUX_CABLE,
277 EM28XX_VMUX_DVB,
278 EM28XX_VMUX_DEBUG,
279 EM28XX_RADIO,
a6c2ba28 280};
281
35643943
MCC
282enum em28xx_ac97_mode {
283 EM28XX_NO_AC97 = 0,
284 EM28XX_AC97_EM202,
209acc02 285 EM28XX_AC97_SIGMATEL,
35643943
MCC
286 EM28XX_AC97_OTHER,
287};
288
289struct em28xx_audio_mode {
290 enum em28xx_ac97_mode ac97;
291
292 u16 ac97_feat;
16c7bcad 293 u32 ac97_vendor_id;
35643943
MCC
294
295 unsigned int has_audio:1;
296
297 unsigned int i2s_3rates:1;
298 unsigned int i2s_5rates:1;
5c2231c8
DH
299};
300
5faff789
MCC
301/* em28xx has two audio inputs: tuner and line in.
302 However, on most devices, an auxiliary AC97 codec device is used.
303 The AC97 device may have several different inputs and outputs,
304 depending on their model. So, it is possible to use AC97 mixer to
305 address more than two different entries.
306 */
539c96d0 307enum em28xx_amux {
5faff789
MCC
308 /* This is the only entry for em28xx tuner input */
309 EM28XX_AMUX_VIDEO, /* em28xx tuner, AC97 mixer Video */
310
311 EM28XX_AMUX_LINE_IN, /* AC97 mixer Line In */
312
313 /* Some less-common mixer setups */
314 EM28XX_AMUX_VIDEO2, /* em28xx Line in, AC97 mixer Video */
315 EM28XX_AMUX_PHONE,
316 EM28XX_AMUX_MIC,
317 EM28XX_AMUX_CD,
318 EM28XX_AMUX_AUX,
319 EM28XX_AMUX_PCM_OUT,
539c96d0
MCC
320};
321
35ae6f04 322enum em28xx_aout {
8866f9cf 323 /* AC97 outputs */
e879b8eb
MCC
324 EM28XX_AOUT_MASTER = 1 << 0,
325 EM28XX_AOUT_LINE = 1 << 1,
326 EM28XX_AOUT_MONO = 1 << 2,
327 EM28XX_AOUT_LFE = 1 << 3,
328 EM28XX_AOUT_SURR = 1 << 4,
8866f9cf
MCC
329
330 /* PCM IN Mixer - used by AC97_RECORD_SELECT register */
331 EM28XX_AOUT_PCM_IN = 1 << 7,
332
333 /* Bits 10-8 are used to indicate the PCM IN record select */
334 EM28XX_AOUT_PCM_MIC_PCM = 0 << 8,
335 EM28XX_AOUT_PCM_CD = 1 << 8,
336 EM28XX_AOUT_PCM_VIDEO = 2 << 8,
337 EM28XX_AOUT_PCM_AUX = 3 << 8,
338 EM28XX_AOUT_PCM_LINE = 4 << 8,
339 EM28XX_AOUT_PCM_STEREO = 5 << 8,
340 EM28XX_AOUT_PCM_MONO = 6 << 8,
341 EM28XX_AOUT_PCM_PHONE = 7 << 8,
35ae6f04
MCC
342};
343
32929fb4 344static inline int ac97_return_record_select(int a_out)
8866f9cf
MCC
345{
346 return (a_out & 0x700) >> 8;
347}
348
122b77e5
MCC
349struct em28xx_reg_seq {
350 int reg;
351 unsigned char val, mask;
352 int sleep;
353};
354
3acf2809
MCC
355struct em28xx_input {
356 enum enum28xx_itype type;
a6c2ba28 357 unsigned int vmux;
539c96d0 358 enum em28xx_amux amux;
35ae6f04 359 enum em28xx_aout aout;
122b77e5 360 struct em28xx_reg_seq *gpio;
a6c2ba28 361};
362
3acf2809 363#define INPUT(nr) (&em28xx_boards[dev->model].input[nr])
a6c2ba28 364
3acf2809 365enum em28xx_decoder {
527f09a9 366 EM28XX_NODECODER = 0,
3acf2809 367 EM28XX_TVP5150,
ec5de990 368 EM28XX_SAA711X,
527f09a9
MCC
369};
370
371enum em28xx_sensor {
372 EM28XX_NOSENSOR = 0,
02e7804b 373 EM28XX_MT9V011,
b80fd2d8 374 EM28XX_MT9M001,
f2e26ae7 375 EM28XX_MT9M111,
e4b7131d 376 EM28XX_OV2640,
a6c2ba28 377};
378
df7fa09c
MCC
379enum em28xx_adecoder {
380 EM28XX_NOADECODER = 0,
381 EM28XX_TVAUDIO,
382};
383
6b8a3170
FS
384enum em28xx_led_role {
385 EM28XX_LED_ANALOG_CAPTURING = 0,
6063d077 386 EM28XX_LED_ILLUMINATION,
6b8a3170
FS
387 EM28XX_NUM_LED_ROLES, /* must be the last */
388};
389
07e4de30 390struct em28xx_led {
6b8a3170 391 enum em28xx_led_role role;
07e4de30
FS
392 u8 gpio_reg;
393 u8 gpio_mask;
394 bool inverted;
395};
396
f5222609
FS
397enum em28xx_button_role {
398 EM28XX_BUTTON_SNAPSHOT = 0,
6063d077 399 EM28XX_BUTTON_ILLUMINATION,
f5222609
FS
400 EM28XX_NUM_BUTTON_ROLES, /* must be the last */
401};
402
403struct em28xx_button {
404 enum em28xx_button_role role;
405 u8 reg_r;
406 u8 reg_clearing;
407 u8 mask;
408 bool inverted;
409};
410
3acf2809 411struct em28xx_board {
a6c2ba28 412 char *name;
505b6d0b 413 int vchannels;
a6c2ba28 414 int tuner_type;
66767920 415 int tuner_addr;
aab3125c 416 unsigned def_i2c_bus; /* Default I2C bus */
a6c2ba28 417
418 /* i2c flags */
419 unsigned int tda9887_conf;
420
017ab4b1 421 /* GPIO sequences */
122b77e5 422 struct em28xx_reg_seq *dvb_gpio;
2fe3e2ee 423 struct em28xx_reg_seq *suspend_gpio;
017ab4b1 424 struct em28xx_reg_seq *tuner_gpio;
2bd1d9eb 425 struct em28xx_reg_seq *mute_gpio;
122b77e5 426
74f38a82 427 unsigned int is_em2800:1;
a6c2ba28 428 unsigned int has_msp34xx:1;
5add9a6f 429 unsigned int mts_firmware:1;
c8793b03 430 unsigned int max_range_640_480:1;
3aefb79a 431 unsigned int has_dvb:1;
c43221df 432 unsigned int is_webcam:1;
95b86a9a 433 unsigned int valid:1;
ac07bb73 434 unsigned int has_ir_i2c:1;
3abee53e 435
a2070c66 436 unsigned char xclk, i2c_speed;
f2cf250a
DSL
437 unsigned char radio_addr;
438 unsigned short tvaudio_addr;
a2070c66 439
3acf2809 440 enum em28xx_decoder decoder;
df7fa09c 441 enum em28xx_adecoder adecoder;
a6c2ba28 442
3acf2809 443 struct em28xx_input input[MAX_EM28XX_INPUT];
0be43754 444 struct em28xx_input radio;
02858eed 445 char *ir_codes;
07e4de30
FS
446
447 /* LEDs that need to be controlled explicitly */
6b8a3170 448 struct em28xx_led *leds;
f5222609
FS
449
450 /* Buttons */
451 struct em28xx_button *buttons;
a6c2ba28 452};
453
3acf2809 454struct em28xx_eeprom {
0c28dcc0
FS
455 u8 id[4]; /* 1a eb 67 95 */
456 __le16 vendor_ID;
457 __le16 product_ID;
a6c2ba28 458
0c28dcc0 459 __le16 chip_conf;
a6c2ba28 460
0c28dcc0 461 __le16 board_conf;
a6c2ba28 462
0c28dcc0 463 __le16 string1, string2, string3;
a6c2ba28 464
465 u8 string_idx_table;
466};
467
6d79468d
MCC
468#define EM28XX_AUDIO_BUFS 5
469#define EM28XX_NUM_AUDIO_PACKETS 64
470#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */
471#define EM28XX_CAPTURE_STREAM_EN 1
3aefb79a
MCC
472
473/* em28xx extensions */
6d79468d 474#define EM28XX_AUDIO 0x10
3aefb79a 475#define EM28XX_DVB 0x20
f4d4e765 476#define EM28XX_RC 0x30
01c28193 477#define EM28XX_V4L2 0x40
6d79468d 478
8c873d31
DH
479/* em28xx resource types (used for res_get/res_lock etc */
480#define EM28XX_RESOURCE_VIDEO 0x01
481#define EM28XX_RESOURCE_VBI 0x02
482
6d79468d
MCC
483struct em28xx_audio {
484 char name[50];
485 char *transfer_buffer[EM28XX_AUDIO_BUFS];
486 struct urb *urb[EM28XX_AUDIO_BUFS];
487 struct usb_device *udev;
488 unsigned int capture_transfer_done;
489 struct snd_pcm_substream *capture_pcm_substream;
490
491 unsigned int hwptr_done_capture;
492 struct snd_card *sndcard;
493
c744dff2 494 int users;
6d79468d
MCC
495 spinlock_t slock;
496};
497
52284c3e
MCC
498struct em28xx;
499
500struct em28xx_fh {
69a61642 501 struct v4l2_fh fh;
52284c3e 502 struct em28xx *dev;
52284c3e
MCC
503
504 enum v4l2_buf_type type;
505};
506
a3ea4bf9
FS
507enum em28xx_i2c_algo_type {
508 EM28XX_I2C_ALGO_EM28XX = 0,
509 EM28XX_I2C_ALGO_EM2800,
510 EM28XX_I2C_ALGO_EM25XX_BUS_B,
511};
512
aab3125c
MCC
513struct em28xx_i2c_bus {
514 struct em28xx *dev;
515
516 unsigned bus;
a3ea4bf9 517 enum em28xx_i2c_algo_type algo_type;
aab3125c
MCC
518};
519
520
a6c2ba28 521/* main device struct */
3acf2809 522struct em28xx {
a6c2ba28 523 /* generic device properties */
524 char name[30]; /* name (including minor) of the device */
525 int model; /* index in the device_data struct */
e5589bef 526 int devno; /* marks the number of this device */
600bd7f0 527 enum em28xx_chip_id chip_id;
505b6d0b 528
ce67943e 529 unsigned int is_em25xx:1; /* em25xx/em276x/7x/8x family bridge */
2665c299 530 unsigned char disconnected:1; /* device has been diconnected */
01c28193 531 unsigned int has_video:1;
ce67943e
MCC
532 unsigned int has_audio_class:1;
533 unsigned int has_alsa_audio:1;
534 unsigned int is_audio_only:1;
2665c299 535
4f83e7b3
MCC
536 int audio_ifnum;
537
f2cf250a 538 struct v4l2_device v4l2_dev;
081b945e 539 struct v4l2_ctrl_handler ctrl_handler;
fc5d0f8a 540 struct v4l2_clk *clk;
505b6d0b
MCC
541 struct em28xx_board board;
542
d36bb4e7 543 /* Webcam specific fields */
527f09a9 544 enum em28xx_sensor em28xx_sensor;
55699964 545 int sensor_xres, sensor_yres;
d36bb4e7 546 int sensor_xtal;
527f09a9 547
8c301567 548 /* Progressive (non-interlaced) mode */
c2a6b54a
MCC
549 int progressive;
550
579d3152
MCC
551 /* Vinmode/Vinctl used at the driver */
552 int vinmode, vinctl;
553
39a96b4c 554 /* Controls audio streaming */
d5b6a746
FS
555 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
556 atomic_t stream_started; /* stream should be running if true */
39a96b4c 557
bddcf633
MCC
558 struct em28xx_fmt *format;
559
a924a499
MCC
560 struct em28xx_IR *ir;
561
89b329ef
MCC
562 /* Some older em28xx chips needs a waiting time after writing */
563 unsigned int wait_after_write;
564
74f38a82
MCC
565 struct list_head devlist;
566
9bb13a6d
MCC
567 u32 i2s_speed; /* I2S speed for audio digital stream */
568
35643943 569 struct em28xx_audio_mode audio_mode;
a6c2ba28 570
571 int tuner_type; /* type of the tuner */
572 int tuner_addr; /* tuner address */
573 int tda9887_conf;
c7a45e5b 574
a6c2ba28 575 /* i2c i/o */
c7a45e5b
MCC
576 struct i2c_adapter i2c_adap[NUM_I2C_BUSES];
577 struct i2c_client i2c_client[NUM_I2C_BUSES];
aab3125c
MCC
578 struct em28xx_i2c_bus i2c_bus[NUM_I2C_BUSES];
579
87b52439 580 unsigned char eeprom_addrwidth_16bit:1;
aab3125c
MCC
581 unsigned def_i2c_bus; /* Default I2C bus */
582 unsigned cur_i2c_bus; /* Current I2C bus */
583 struct rt_mutex i2c_bus_lock;
c7a45e5b 584
a6c2ba28 585 /* video for linux */
586 int users; /* user count for exclusive use */
d3829fad 587 int streaming_users; /* Number of actively streaming users */
a6c2ba28 588 struct video_device *vdev; /* video for linux device struct */
7d497f8a 589 v4l2_std_id norm; /* selected tv norm */
a6c2ba28 590 int ctl_freq; /* selected frequency */
591 unsigned int ctl_input; /* selected input */
95b86a9a 592 unsigned int ctl_ainput;/* selected audio input */
35ae6f04 593 unsigned int ctl_aoutput;/* selected audio output */
a6c2ba28 594 int mute;
595 int volume;
596 /* frame properties */
a6c2ba28 597 int width; /* current frame width */
598 int height; /* current frame height */
d45b9b8a
HV
599 unsigned hscale; /* horizontal scale factor (see datasheet) */
600 unsigned vscale; /* vertical scale factor (see datasheet) */
a6c2ba28 601 int interlaced; /* 1=interlace fileds, 0=just top fileds */
9e31ced8 602 unsigned int video_bytesread; /* Number of bytes read */
a6c2ba28 603
03910cc3 604 unsigned long hash; /* eeprom hash - for boards with generic ID */
6ea54d93
DSL
605 unsigned long i2c_hash; /* i2c devicelist hash -
606 for boards with generic ID */
03910cc3 607
9baed99e 608 struct em28xx_audio adev;
6d79468d 609
960da93b 610 /* capture state tracking */
da52a55c 611 int capture_type;
0455eebf 612 unsigned char top_field:1;
960da93b 613 int vbi_read;
66d9cbad
DH
614 unsigned int vbi_width;
615 unsigned int vbi_height; /* lines per field */
da52a55c 616
d7448a8d
MCC
617 struct work_struct request_module_wk;
618
a6c2ba28 619 /* locks */
5a80415b 620 struct mutex lock;
f2a2e491 621 struct mutex ctrl_urb_lock; /* protects urb_buf */
d7aa8020 622 /* spinlock_t queue_lock; */
a6c2ba28 623 struct list_head inqueue, outqueue;
a6c2ba28 624 struct video_device *vbi_dev;
0be43754 625 struct video_device *radio_dev;
a6c2ba28 626
d3829fad
DH
627 /* Videobuf2 */
628 struct vb2_queue vb_vidq;
629 struct vb2_queue vb_vbiq;
630 struct mutex vb_queue_lock;
631 struct mutex vb_vbi_queue_lock;
632
8c873d31
DH
633 /* resources in use */
634 unsigned int resources;
635
510e884c
FS
636 /* eeprom content */
637 u8 *eedata;
638 u16 eedata_len;
a6c2ba28 639
ad0ebb96
MCC
640 /* Isoc control struct */
641 struct em28xx_dmaqueue vidq;
28abf083 642 struct em28xx_dmaqueue vbiq;
74209dc0 643 struct em28xx_usb_ctl usb_ctl;
ad0ebb96
MCC
644 spinlock_t slock;
645
d3829fad
DH
646 unsigned int field_count;
647 unsigned int vbi_field_count;
648
a6c2ba28 649 /* usb transfer */
650 struct usb_device *udev; /* the usb device */
c647a91a
FS
651 u8 analog_ep_isoc; /* address of isoc endpoint for analog */
652 u8 analog_ep_bulk; /* address of bulk endpoint for analog */
653 u8 dvb_ep_isoc; /* address of isoc endpoint for DVB */
d5b6a746 654 u8 dvb_ep_bulk; /* address of bulk endpoint for DVB */
0cf544a6
FS
655 int alt; /* alternate setting */
656 int max_pkt_size; /* max packet size of the selected ep at alt */
c647a91a
FS
657 int packet_multiplier; /* multiplier for wMaxPacketSize, used for
658 URB buffer size definition */
0cf544a6
FS
659 int num_alt; /* number of alternative settings */
660 unsigned int *alt_max_pkt_size_isoc; /* array of isoc wMaxPacketSize */
7312f2c9
FS
661 unsigned int analog_xfer_bulk:1; /* use bulk instead of isoc
662 transfers for analog */
0cf544a6
FS
663 int dvb_alt_isoc; /* alternate setting for DVB isoc transfers */
664 unsigned int dvb_max_pkt_size_isoc; /* isoc max packet size of the
665 selected DVB ep at dvb_alt */
7312f2c9
FS
666 unsigned int dvb_xfer_bulk:1; /* use bulk instead of isoc
667 transfers for DVB */
c4a98793
MCC
668 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
669
a6c2ba28 670 /* helper funcs that call usb_control_msg */
6ea54d93 671 int (*em28xx_write_regs) (struct em28xx *dev, u16 reg,
a6c2ba28 672 char *buf, int len);
6ea54d93
DSL
673 int (*em28xx_read_reg) (struct em28xx *dev, u16 reg);
674 int (*em28xx_read_reg_req_len) (struct em28xx *dev, u8 req, u16 reg,
675 char *buf, int len);
676 int (*em28xx_write_regs_req) (struct em28xx *dev, u8 req, u16 reg,
a6c2ba28 677 char *buf, int len);
6ea54d93 678 int (*em28xx_read_reg_req) (struct em28xx *dev, u8 req, u16 reg);
3aefb79a
MCC
679
680 enum em28xx_mode mode;
681
f5222609
FS
682 /* Button state polling */
683 struct delayed_work buttons_query_work;
684 u8 button_polling_addresses[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
7763481a 685 u8 button_polling_last_values[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
f5222609 686 u8 num_button_polling_addresses;
0ff950a7 687 u16 button_polling_interval; /* [ms] */
f5222609 688 /* Snapshot button input device */
a9fc52bc
DH
689 char snapshot_button_path[30]; /* path of the input dev */
690 struct input_dev *sbutton_input_dev;
a9fc52bc 691
3421b778 692 struct em28xx_dvb *dvb;
a6c2ba28 693};
694
6d79468d
MCC
695struct em28xx_ops {
696 struct list_head next;
697 char *name;
698 int id;
699 int (*init)(struct em28xx *);
700 int (*fini)(struct em28xx *);
a3a048ce
MCC
701};
702
3acf2809 703/* Provided by em28xx-i2c.c */
aab3125c 704void em28xx_do_i2c_scan(struct em28xx *dev, unsigned bus);
a3ea4bf9
FS
705int em28xx_i2c_register(struct em28xx *dev, unsigned bus,
706 enum em28xx_i2c_algo_type algo_type);
aab3125c 707int em28xx_i2c_unregister(struct em28xx *dev, unsigned bus);
a6c2ba28 708
3acf2809 709/* Provided by em28xx-core.c */
3acf2809 710int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
a6c2ba28 711 char *buf, int len);
3acf2809
MCC
712int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);
713int em28xx_read_reg(struct em28xx *dev, u16 reg);
714int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
a6c2ba28 715 int len);
3acf2809 716int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);
b6972489 717int em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val);
1bad429e
MCC
718int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
719 u8 bitmask);
6063d077 720int em28xx_toggle_reg_bits(struct em28xx *dev, u16 reg, u8 bitmask);
b6972489 721
531c98e7
MCC
722int em28xx_read_ac97(struct em28xx *dev, u8 reg);
723int em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val);
724
3acf2809 725int em28xx_audio_analog_set(struct em28xx *dev);
35643943 726int em28xx_audio_setup(struct em28xx *dev);
539c96d0 727
6b8a3170
FS
728const struct em28xx_led *em28xx_find_led(struct em28xx *dev,
729 enum em28xx_led_role role);
3acf2809 730int em28xx_capture_start(struct em28xx *dev, int start);
6ddd89d0
FS
731int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
732 int num_bufs, int max_pkt_size, int packet_multiplier);
057ca0da
FS
733int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
734 int xfer_bulk,
735 int num_bufs, int max_pkt_size, int packet_multiplier,
736 int (*urb_data_copy)
737 (struct em28xx *dev, struct urb *urb));
afb177e0 738void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
5f5f147f 739void em28xx_stop_urbs(struct em28xx *dev);
c67ec53f
MCC
740int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
741int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio);
6d79468d
MCC
742int em28xx_register_extension(struct em28xx_ops *dev);
743void em28xx_unregister_extension(struct em28xx_ops *dev);
1a23f81b
MCC
744void em28xx_init_extension(struct em28xx *dev);
745void em28xx_close_extension(struct em28xx *dev);
746
3acf2809 747/* Provided by em28xx-cards.c */
3acf2809
MCC
748extern struct em28xx_board em28xx_boards[];
749extern struct usb_device_id em28xx_id_table[];
d7cba043 750int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
1a23f81b 751void em28xx_release_resources(struct em28xx *dev);
c8793b03 752
855ff38e
FS
753/* Provided by em28xx-camera.c */
754int em28xx_detect_sensor(struct em28xx *dev);
755int em28xx_init_camera(struct em28xx *dev);
756
a6c2ba28 757/* printk macros */
758
3acf2809 759#define em28xx_err(fmt, arg...) do {\
f85c657f 760 printk(KERN_ERR fmt , ##arg); } while (0)
a6c2ba28 761
3acf2809 762#define em28xx_errdev(fmt, arg...) do {\
4ac97914 763 printk(KERN_ERR "%s: "fmt,\
f85c657f 764 dev->name , ##arg); } while (0)
a6c2ba28 765
3acf2809 766#define em28xx_info(fmt, arg...) do {\
4ac97914 767 printk(KERN_INFO "%s: "fmt,\
f85c657f 768 dev->name , ##arg); } while (0)
3acf2809 769#define em28xx_warn(fmt, arg...) do {\
4ac97914 770 printk(KERN_WARNING "%s: "fmt,\
f85c657f 771 dev->name , ##arg); } while (0)
a6c2ba28 772
6ea54d93 773static inline int em28xx_compression_disable(struct em28xx *dev)
a6c2ba28 774{
775 /* side effect of disabling scaler and mixer */
2a29a0d7 776 return em28xx_write_reg(dev, EM28XX_R26_COMPR, 0x00);
a6c2ba28 777}
778
a6c2ba28 779/*FIXME: maxw should be dependent of alt mode */
6ea54d93 780static inline unsigned int norm_maxw(struct em28xx *dev)
30556b23 781{
55699964
MCC
782 if (dev->board.is_webcam)
783 return dev->sensor_xres;
784
1020d13d 785 if (dev->board.max_range_640_480)
7d497f8a 786 return 640;
55699964
MCC
787
788 return 720;
30556b23
MR
789}
790
6ea54d93 791static inline unsigned int norm_maxh(struct em28xx *dev)
a6c2ba28 792{
55699964
MCC
793 if (dev->board.is_webcam)
794 return dev->sensor_yres;
795
505b6d0b 796 if (dev->board.max_range_640_480)
7d497f8a 797 return 480;
55699964
MCC
798
799 return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
a6c2ba28 800}
a6c2ba28 801#endif