162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * em28xx.h - driver for Empia EM2800/EM2820/2840 USB video capture devices
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
662306a36Sopenharmony_ci *		      Ludovico Cavedon <cavedon@sssup.it>
762306a36Sopenharmony_ci *		      Mauro Carvalho Chehab <mchehab@kernel.org>
862306a36Sopenharmony_ci * Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifndef _EM28XX_H
1462306a36Sopenharmony_ci#define _EM28XX_H
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <linux/bitfield.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#define EM28XX_VERSION "0.2.2"
1962306a36Sopenharmony_ci#define DRIVER_DESC    "Empia em28xx device driver"
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#include <linux/workqueue.h>
2262306a36Sopenharmony_ci#include <linux/i2c.h>
2362306a36Sopenharmony_ci#include <linux/mutex.h>
2462306a36Sopenharmony_ci#include <linux/kref.h>
2562306a36Sopenharmony_ci#include <linux/videodev2.h>
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#include <media/videobuf2-v4l2.h>
2862306a36Sopenharmony_ci#include <media/videobuf2-vmalloc.h>
2962306a36Sopenharmony_ci#include <media/v4l2-device.h>
3062306a36Sopenharmony_ci#include <media/v4l2-ctrls.h>
3162306a36Sopenharmony_ci#include <media/v4l2-fh.h>
3262306a36Sopenharmony_ci#include <media/i2c/ir-kbd-i2c.h>
3362306a36Sopenharmony_ci#include <media/rc-core.h>
3462306a36Sopenharmony_ci#include "xc2028.h"
3562306a36Sopenharmony_ci#include "xc5000.h"
3662306a36Sopenharmony_ci#include "em28xx-reg.h"
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* Boards supported by driver */
3962306a36Sopenharmony_ci#define EM2800_BOARD_UNKNOWN			  0
4062306a36Sopenharmony_ci#define EM2820_BOARD_UNKNOWN			  1
4162306a36Sopenharmony_ci#define EM2820_BOARD_TERRATEC_CINERGY_250	  2
4262306a36Sopenharmony_ci#define EM2820_BOARD_PINNACLE_USB_2		  3
4362306a36Sopenharmony_ci#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2	  4
4462306a36Sopenharmony_ci#define EM2820_BOARD_MSI_VOX_USB_2		  5
4562306a36Sopenharmony_ci#define EM2800_BOARD_TERRATEC_CINERGY_200	  6
4662306a36Sopenharmony_ci#define EM2800_BOARD_LEADTEK_WINFAST_USBII	  7
4762306a36Sopenharmony_ci#define EM2800_BOARD_KWORLD_USB2800		  8
4862306a36Sopenharmony_ci#define EM2820_BOARD_PINNACLE_DVC_90		  9
4962306a36Sopenharmony_ci#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900	  10
5062306a36Sopenharmony_ci#define EM2880_BOARD_TERRATEC_HYBRID_XS		  11
5162306a36Sopenharmony_ci#define EM2820_BOARD_KWORLD_PVRTV2800RF		  12
5262306a36Sopenharmony_ci#define EM2880_BOARD_TERRATEC_PRODIGY_XS	  13
5362306a36Sopenharmony_ci#define EM2820_BOARD_PROLINK_PLAYTV_USB2	  14
5462306a36Sopenharmony_ci#define EM2800_BOARD_VGEAR_POCKETTV		  15
5562306a36Sopenharmony_ci#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950	  16
5662306a36Sopenharmony_ci#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO	  17
5762306a36Sopenharmony_ci#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2	  18
5862306a36Sopenharmony_ci#define EM2860_BOARD_SAA711X_REFERENCE_DESIGN	  19
5962306a36Sopenharmony_ci#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600	  20
6062306a36Sopenharmony_ci#define EM2800_BOARD_GRABBEEX_USB2800		  21
6162306a36Sopenharmony_ci#define EM2750_BOARD_UNKNOWN			  22
6262306a36Sopenharmony_ci#define EM2750_BOARD_DLCW_130			  23
6362306a36Sopenharmony_ci#define EM2820_BOARD_DLINK_USB_TV		  24
6462306a36Sopenharmony_ci#define EM2820_BOARD_GADMEI_UTV310		  25
6562306a36Sopenharmony_ci#define EM2820_BOARD_HERCULES_SMART_TV_USB2	  26
6662306a36Sopenharmony_ci#define EM2820_BOARD_PINNACLE_USB_2_FM1216ME	  27
6762306a36Sopenharmony_ci#define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28
6862306a36Sopenharmony_ci#define EM2860_BOARD_TVP5150_REFERENCE_DESIGN	  29
6962306a36Sopenharmony_ci#define EM2820_BOARD_VIDEOLOGY_20K14XUSB	  30
7062306a36Sopenharmony_ci#define EM2821_BOARD_USBGEAR_VD204		  31
7162306a36Sopenharmony_ci#define EM2821_BOARD_SUPERCOMP_USB_2		  32
7262306a36Sopenharmony_ci#define EM2860_BOARD_ELGATO_VIDEO_CAPTURE	  33
7362306a36Sopenharmony_ci#define EM2860_BOARD_TERRATEC_HYBRID_XS		  34
7462306a36Sopenharmony_ci#define EM2860_BOARD_TYPHOON_DVD_MAKER		  35
7562306a36Sopenharmony_ci#define EM2860_BOARD_NETGMBH_CAM		  36
7662306a36Sopenharmony_ci#define EM2860_BOARD_GADMEI_UTV330		  37
7762306a36Sopenharmony_ci#define EM2861_BOARD_YAKUMO_MOVIE_MIXER		  38
7862306a36Sopenharmony_ci#define EM2861_BOARD_KWORLD_PVRTV_300U		  39
7962306a36Sopenharmony_ci#define EM2861_BOARD_PLEXTOR_PX_TV100U		  40
8062306a36Sopenharmony_ci#define EM2870_BOARD_KWORLD_350U		  41
8162306a36Sopenharmony_ci#define EM2870_BOARD_KWORLD_355U		  42
8262306a36Sopenharmony_ci#define EM2870_BOARD_TERRATEC_XS		  43
8362306a36Sopenharmony_ci#define EM2870_BOARD_TERRATEC_XS_MT2060		  44
8462306a36Sopenharmony_ci#define EM2870_BOARD_PINNACLE_PCTV_DVB		  45
8562306a36Sopenharmony_ci#define EM2870_BOARD_COMPRO_VIDEOMATE		  46
8662306a36Sopenharmony_ci#define EM2880_BOARD_KWORLD_DVB_305U		  47
8762306a36Sopenharmony_ci#define EM2880_BOARD_KWORLD_DVB_310U		  48
8862306a36Sopenharmony_ci#define EM2880_BOARD_MSI_DIGIVOX_AD		  49
8962306a36Sopenharmony_ci#define EM2880_BOARD_MSI_DIGIVOX_AD_II		  50
9062306a36Sopenharmony_ci#define EM2880_BOARD_TERRATEC_HYBRID_XS_FR	  51
9162306a36Sopenharmony_ci#define EM2881_BOARD_DNT_DA2_HYBRID		  52
9262306a36Sopenharmony_ci#define EM2881_BOARD_PINNACLE_HYBRID_PRO	  53
9362306a36Sopenharmony_ci#define EM2882_BOARD_KWORLD_VS_DVBT		  54
9462306a36Sopenharmony_ci#define EM2882_BOARD_TERRATEC_HYBRID_XS		  55
9562306a36Sopenharmony_ci#define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E	  56
9662306a36Sopenharmony_ci#define EM2883_BOARD_KWORLD_HYBRID_330U		  57
9762306a36Sopenharmony_ci#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU	  58
9862306a36Sopenharmony_ci#define EM2874_BOARD_PCTV_HD_MINI_80E		  59
9962306a36Sopenharmony_ci#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850	  60
10062306a36Sopenharmony_ci#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2	  61
10162306a36Sopenharmony_ci#define EM2820_BOARD_GADMEI_TVR200		  62
10262306a36Sopenharmony_ci#define EM2860_BOARD_KAIOMY_TVNPC_U2		  63
10362306a36Sopenharmony_ci#define EM2860_BOARD_EASYCAP			  64
10462306a36Sopenharmony_ci#define EM2820_BOARD_IODATA_GVMVP_SZ		  65
10562306a36Sopenharmony_ci#define EM2880_BOARD_EMPIRE_DUAL_TV		  66
10662306a36Sopenharmony_ci#define EM2860_BOARD_TERRATEC_GRABBY		  67
10762306a36Sopenharmony_ci#define EM2860_BOARD_TERRATEC_AV350		  68
10862306a36Sopenharmony_ci#define EM2882_BOARD_KWORLD_ATSC_315U		  69
10962306a36Sopenharmony_ci#define EM2882_BOARD_EVGA_INDTUBE		  70
11062306a36Sopenharmony_ci#define EM2820_BOARD_SILVERCREST_WEBCAM		  71
11162306a36Sopenharmony_ci#define EM2861_BOARD_GADMEI_UTV330PLUS		  72
11262306a36Sopenharmony_ci#define EM2870_BOARD_REDDO_DVB_C_USB_BOX	  73
11362306a36Sopenharmony_ci#define EM2800_BOARD_VC211A			  74
11462306a36Sopenharmony_ci#define EM2882_BOARD_DIKOM_DK300		  75
11562306a36Sopenharmony_ci#define EM2870_BOARD_KWORLD_A340		  76
11662306a36Sopenharmony_ci#define EM2874_BOARD_LEADERSHIP_ISDBT		  77
11762306a36Sopenharmony_ci#define EM28174_BOARD_PCTV_290E			  78
11862306a36Sopenharmony_ci#define EM2884_BOARD_TERRATEC_H5		  79
11962306a36Sopenharmony_ci#define EM28174_BOARD_PCTV_460E			  80
12062306a36Sopenharmony_ci#define EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C	  81
12162306a36Sopenharmony_ci#define EM2884_BOARD_CINERGY_HTC_STICK		  82
12262306a36Sopenharmony_ci#define EM2860_BOARD_HT_VIDBOX_NW03		  83
12362306a36Sopenharmony_ci#define EM2874_BOARD_MAXMEDIA_UB425_TC		  84
12462306a36Sopenharmony_ci#define EM2884_BOARD_PCTV_510E			  85
12562306a36Sopenharmony_ci#define EM2884_BOARD_PCTV_520E			  86
12662306a36Sopenharmony_ci#define EM2884_BOARD_TERRATEC_HTC_USB_XS	  87
12762306a36Sopenharmony_ci#define EM2884_BOARD_C3TECH_DIGITAL_DUO		  88
12862306a36Sopenharmony_ci#define EM2874_BOARD_DELOCK_61959		  89
12962306a36Sopenharmony_ci#define EM2874_BOARD_KWORLD_UB435Q_V2		  90
13062306a36Sopenharmony_ci#define EM2765_BOARD_SPEEDLINK_VAD_LAPLACE	  91
13162306a36Sopenharmony_ci#define EM28178_BOARD_PCTV_461E                   92
13262306a36Sopenharmony_ci#define EM2874_BOARD_KWORLD_UB435Q_V3		  93
13362306a36Sopenharmony_ci#define EM28178_BOARD_PCTV_292E                   94
13462306a36Sopenharmony_ci#define EM2861_BOARD_LEADTEK_VC100                95
13562306a36Sopenharmony_ci#define EM28178_BOARD_TERRATEC_T2_STICK_HD        96
13662306a36Sopenharmony_ci#define EM2884_BOARD_ELGATO_EYETV_HYBRID_2008     97
13762306a36Sopenharmony_ci#define EM28178_BOARD_PLEX_PX_BCUD                98
13862306a36Sopenharmony_ci#define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB  99
13962306a36Sopenharmony_ci#define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595 100
14062306a36Sopenharmony_ci#define EM2884_BOARD_TERRATEC_H6		  101
14162306a36Sopenharmony_ci#define EM2882_BOARD_ZOLID_HYBRID_TV_STICK		102
14262306a36Sopenharmony_ci#define EM2861_BOARD_MAGIX_VIDEOWANDLER2          103
14362306a36Sopenharmony_ci#define EM28178_BOARD_PCTV_461E_V2                104
14462306a36Sopenharmony_ci#define EM2860_BOARD_MYGICA_IGRABBER              105
14562306a36Sopenharmony_ci#define EM2874_BOARD_HAUPPAUGE_USB_QUADHD         106
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci/* Limits minimum and default number of buffers */
14862306a36Sopenharmony_ci#define EM28XX_MIN_BUF 4
14962306a36Sopenharmony_ci#define EM28XX_DEF_BUF 8
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci/*Limits the max URB message size */
15262306a36Sopenharmony_ci#define URB_MAX_CTRL_SIZE 80
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci/* Params for validated field */
15562306a36Sopenharmony_ci#define EM28XX_BOARD_NOT_VALIDATED 1
15662306a36Sopenharmony_ci#define EM28XX_BOARD_VALIDATED	   0
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci/* Params for em28xx_cmd() audio */
15962306a36Sopenharmony_ci#define EM28XX_START_AUDIO      1
16062306a36Sopenharmony_ci#define EM28XX_STOP_AUDIO       0
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci/* maximum number of em28xx boards */
16362306a36Sopenharmony_ci#define EM28XX_MAXBOARDS DVB_MAX_ADAPTERS /* All adapters could be em28xx */
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/* maximum number of frames that can be queued */
16662306a36Sopenharmony_ci#define EM28XX_NUM_FRAMES 5
16762306a36Sopenharmony_ci/* number of frames that get used for v4l2_read() */
16862306a36Sopenharmony_ci#define EM28XX_NUM_READ_FRAMES 2
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci/* number of buffers for isoc transfers */
17162306a36Sopenharmony_ci#define EM28XX_NUM_BUFS 5
17262306a36Sopenharmony_ci#define EM28XX_DVB_NUM_BUFS 5
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci/* max number of I2C buses on em28xx devices */
17562306a36Sopenharmony_ci#define NUM_I2C_BUSES	2
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci/*
17862306a36Sopenharmony_ci * isoc transfers: number of packets for each buffer
17962306a36Sopenharmony_ci * windows requests only 64 packets .. so we better do the same
18062306a36Sopenharmony_ci * this is what I found out for all alternate numbers there!
18162306a36Sopenharmony_ci */
18262306a36Sopenharmony_ci#define EM28XX_NUM_ISOC_PACKETS 64
18362306a36Sopenharmony_ci#define EM28XX_DVB_NUM_ISOC_PACKETS 64
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci/*
18662306a36Sopenharmony_ci * bulk transfers: transfer buffer size = packet size * packet multiplier
18762306a36Sopenharmony_ci * USB 2.0 spec says bulk packet size is always 512 bytes
18862306a36Sopenharmony_ci */
18962306a36Sopenharmony_ci#define EM28XX_BULK_PACKET_MULTIPLIER 384
19062306a36Sopenharmony_ci#define EM28XX_DVB_BULK_PACKET_MULTIPLIER 94
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#define EM28XX_INTERLACED_DEFAULT 1
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci/* time in msecs to wait for AC97 xfers to finish */
19562306a36Sopenharmony_ci#define EM28XX_AC97_XFER_TIMEOUT	100
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci/* max. number of button state polling addresses */
19862306a36Sopenharmony_ci#define EM28XX_NUM_BUTTON_ADDRESSES_MAX		5
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci#define PRIMARY_TS	0
20162306a36Sopenharmony_ci#define SECONDARY_TS	1
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_cienum em28xx_mode {
20462306a36Sopenharmony_ci	EM28XX_SUSPEND,
20562306a36Sopenharmony_ci	EM28XX_ANALOG_MODE,
20662306a36Sopenharmony_ci	EM28XX_DIGITAL_MODE,
20762306a36Sopenharmony_ci};
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_cistruct em28xx;
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci/**
21262306a36Sopenharmony_ci * struct em28xx_usb_bufs - Contains URB-related buffer data
21362306a36Sopenharmony_ci *
21462306a36Sopenharmony_ci * @max_pkt_size:	max packet size of isoc transaction
21562306a36Sopenharmony_ci * @num_packets:	number of packets in each buffer
21662306a36Sopenharmony_ci * @num_bufs:		number of allocated urb
21762306a36Sopenharmony_ci * @urb:		urb for isoc/bulk transfers
21862306a36Sopenharmony_ci * @buf:		transfer buffers for isoc/bulk transfer
21962306a36Sopenharmony_ci */
22062306a36Sopenharmony_cistruct em28xx_usb_bufs {
22162306a36Sopenharmony_ci	int				max_pkt_size;
22262306a36Sopenharmony_ci	int				num_packets;
22362306a36Sopenharmony_ci	int				num_bufs;
22462306a36Sopenharmony_ci	struct urb			**urb;
22562306a36Sopenharmony_ci	char				**buf;
22662306a36Sopenharmony_ci};
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ci/**
22962306a36Sopenharmony_ci * struct em28xx_usb_ctl - Contains URB-related buffer data
23062306a36Sopenharmony_ci *
23162306a36Sopenharmony_ci * @analog_bufs:	isoc/bulk transfer buffers for analog mode
23262306a36Sopenharmony_ci * @digital_bufs:	isoc/bulk transfer buffers for digital mode
23362306a36Sopenharmony_ci * @vid_buf:		Stores already requested video buffers
23462306a36Sopenharmony_ci * @vbi_buf:		Stores already requested VBI buffers
23562306a36Sopenharmony_ci * @urb_data_copy:	copy data from URB
23662306a36Sopenharmony_ci */
23762306a36Sopenharmony_cistruct em28xx_usb_ctl {
23862306a36Sopenharmony_ci	struct em28xx_usb_bufs		analog_bufs;
23962306a36Sopenharmony_ci	struct em28xx_usb_bufs		digital_bufs;
24062306a36Sopenharmony_ci	struct em28xx_buffer	*vid_buf;
24162306a36Sopenharmony_ci	struct em28xx_buffer	*vbi_buf;
24262306a36Sopenharmony_ci	int (*urb_data_copy)(struct em28xx *dev, struct urb *urb);
24362306a36Sopenharmony_ci};
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci/**
24662306a36Sopenharmony_ci * struct em28xx_fmt - Struct to enumberate video formats
24762306a36Sopenharmony_ci *
24862306a36Sopenharmony_ci * @fourcc:	v4l2 format id
24962306a36Sopenharmony_ci * @depth:	mean number of bits to represent a pixel
25062306a36Sopenharmony_ci * @reg:	em28xx register value to set it
25162306a36Sopenharmony_ci */
25262306a36Sopenharmony_cistruct em28xx_fmt {
25362306a36Sopenharmony_ci	u32	fourcc;
25462306a36Sopenharmony_ci	int	depth;
25562306a36Sopenharmony_ci	int	reg;
25662306a36Sopenharmony_ci};
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci/**
25962306a36Sopenharmony_ci * struct em28xx_buffer- buffer for storing one video frame
26062306a36Sopenharmony_ci *
26162306a36Sopenharmony_ci * @vb:		common v4l buffer stuff
26262306a36Sopenharmony_ci * @list:	List to associate it with the other buffers
26362306a36Sopenharmony_ci * @mem:	pointer to the buffer, as returned by vb2_plane_vaddr()
26462306a36Sopenharmony_ci * @length:	length of the buffer, as returned by vb2_plane_size()
26562306a36Sopenharmony_ci * @top_field:	If non-zero, indicate that the buffer is the top field
26662306a36Sopenharmony_ci * @pos:	Indicate the next position of the buffer to be filled.
26762306a36Sopenharmony_ci * @vb_buf:	pointer to vmalloc memory address in vb
26862306a36Sopenharmony_ci *
26962306a36Sopenharmony_ci * .. note::
27062306a36Sopenharmony_ci *
27162306a36Sopenharmony_ci *    in interlaced mode, @pos is reset to zero at the start of each new
27262306a36Sopenharmony_ci *    field (not frame !)
27362306a36Sopenharmony_ci */
27462306a36Sopenharmony_cistruct em28xx_buffer {
27562306a36Sopenharmony_ci	struct vb2_v4l2_buffer	vb;		/* must be first */
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci	struct list_head	list;
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci	void			*mem;
28062306a36Sopenharmony_ci	unsigned int		length;
28162306a36Sopenharmony_ci	int			top_field;
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci	unsigned int		pos;
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_ci	char			*vb_buf;
28662306a36Sopenharmony_ci};
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_cistruct em28xx_dmaqueue {
28962306a36Sopenharmony_ci	struct list_head       active;
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci	wait_queue_head_t          wq;
29262306a36Sopenharmony_ci};
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ci/* inputs */
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci#define MAX_EM28XX_INPUT 4
29762306a36Sopenharmony_cienum enum28xx_itype {
29862306a36Sopenharmony_ci	EM28XX_VMUX_COMPOSITE = 1,
29962306a36Sopenharmony_ci	EM28XX_VMUX_SVIDEO,
30062306a36Sopenharmony_ci	EM28XX_VMUX_TELEVISION,
30162306a36Sopenharmony_ci	EM28XX_RADIO,
30262306a36Sopenharmony_ci};
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_cienum em28xx_ac97_mode {
30562306a36Sopenharmony_ci	EM28XX_NO_AC97 = 0,
30662306a36Sopenharmony_ci	EM28XX_AC97_EM202,
30762306a36Sopenharmony_ci	EM28XX_AC97_SIGMATEL,
30862306a36Sopenharmony_ci	EM28XX_AC97_OTHER,
30962306a36Sopenharmony_ci};
31062306a36Sopenharmony_ci
31162306a36Sopenharmony_cistruct em28xx_audio_mode {
31262306a36Sopenharmony_ci	enum em28xx_ac97_mode ac97;
31362306a36Sopenharmony_ci};
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_cienum em28xx_int_audio_type {
31662306a36Sopenharmony_ci	EM28XX_INT_AUDIO_NONE = 0,
31762306a36Sopenharmony_ci	EM28XX_INT_AUDIO_AC97,
31862306a36Sopenharmony_ci	EM28XX_INT_AUDIO_I2S,
31962306a36Sopenharmony_ci};
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_cienum em28xx_usb_audio_type {
32262306a36Sopenharmony_ci	EM28XX_USB_AUDIO_NONE = 0,
32362306a36Sopenharmony_ci	EM28XX_USB_AUDIO_CLASS,
32462306a36Sopenharmony_ci	EM28XX_USB_AUDIO_VENDOR,
32562306a36Sopenharmony_ci};
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci/**
32862306a36Sopenharmony_ci * enum em28xx_amux - describes the type of audio input used by em28xx
32962306a36Sopenharmony_ci *
33062306a36Sopenharmony_ci * @EM28XX_AMUX_UNUSED:
33162306a36Sopenharmony_ci *	Used only on em28xx dev->map field, in order to mark an entry
33262306a36Sopenharmony_ci *	as unused.
33362306a36Sopenharmony_ci * @EM28XX_AMUX_VIDEO:
33462306a36Sopenharmony_ci *	On devices without AC97, this is the only value that it is currently
33562306a36Sopenharmony_ci *	allowed.
33662306a36Sopenharmony_ci *	On devices with AC97, it corresponds to the AC97 mixer "Video" control.
33762306a36Sopenharmony_ci * @EM28XX_AMUX_LINE_IN:
33862306a36Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "Line In".
33962306a36Sopenharmony_ci * @EM28XX_AMUX_VIDEO2:
34062306a36Sopenharmony_ci *	Only for devices with AC97. It means that em28xx should use "Line In"
34162306a36Sopenharmony_ci *	And AC97 should use the "Video" mixer control.
34262306a36Sopenharmony_ci * @EM28XX_AMUX_PHONE:
34362306a36Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "Phone".
34462306a36Sopenharmony_ci * @EM28XX_AMUX_MIC:
34562306a36Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "Mic".
34662306a36Sopenharmony_ci * @EM28XX_AMUX_CD:
34762306a36Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "CD".
34862306a36Sopenharmony_ci * @EM28XX_AMUX_AUX:
34962306a36Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "Aux".
35062306a36Sopenharmony_ci * @EM28XX_AMUX_PCM_OUT:
35162306a36Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "PCM out".
35262306a36Sopenharmony_ci *
35362306a36Sopenharmony_ci * The em28xx chip itself has only two audio inputs: tuner and line in.
35462306a36Sopenharmony_ci * On almost all devices, only the tuner input is used.
35562306a36Sopenharmony_ci *
35662306a36Sopenharmony_ci * However, on most devices, an auxiliary AC97 codec device is used,
35762306a36Sopenharmony_ci * usually connected to the em28xx tuner input (except for
35862306a36Sopenharmony_ci * @EM28XX_AMUX_LINE_IN).
35962306a36Sopenharmony_ci *
36062306a36Sopenharmony_ci * The AC97 device typically have several different inputs and outputs.
36162306a36Sopenharmony_ci * The exact number and description depends on their model.
36262306a36Sopenharmony_ci *
36362306a36Sopenharmony_ci * It is possible to AC97 to mixer more than one different entries at the
36462306a36Sopenharmony_ci * same time, via the alsa mux.
36562306a36Sopenharmony_ci */
36662306a36Sopenharmony_cienum em28xx_amux {
36762306a36Sopenharmony_ci	EM28XX_AMUX_UNUSED = -1,
36862306a36Sopenharmony_ci	EM28XX_AMUX_VIDEO = 0,
36962306a36Sopenharmony_ci	EM28XX_AMUX_LINE_IN,
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci	/* Some less-common mixer setups */
37262306a36Sopenharmony_ci	EM28XX_AMUX_VIDEO2,
37362306a36Sopenharmony_ci	EM28XX_AMUX_PHONE,
37462306a36Sopenharmony_ci	EM28XX_AMUX_MIC,
37562306a36Sopenharmony_ci	EM28XX_AMUX_CD,
37662306a36Sopenharmony_ci	EM28XX_AMUX_AUX,
37762306a36Sopenharmony_ci	EM28XX_AMUX_PCM_OUT,
37862306a36Sopenharmony_ci};
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_cienum em28xx_aout {
38162306a36Sopenharmony_ci	/* AC97 outputs */
38262306a36Sopenharmony_ci	EM28XX_AOUT_MASTER = BIT(0),
38362306a36Sopenharmony_ci	EM28XX_AOUT_LINE   = BIT(1),
38462306a36Sopenharmony_ci	EM28XX_AOUT_MONO   = BIT(2),
38562306a36Sopenharmony_ci	EM28XX_AOUT_LFE    = BIT(3),
38662306a36Sopenharmony_ci	EM28XX_AOUT_SURR   = BIT(4),
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_ci	/* PCM IN Mixer - used by AC97_RECORD_SELECT register */
38962306a36Sopenharmony_ci	EM28XX_AOUT_PCM_IN = BIT(7),
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci	/* Bits 10-8 are used to indicate the PCM IN record select */
39262306a36Sopenharmony_ci	EM28XX_AOUT_PCM_MIC_PCM = 0 << 8,
39362306a36Sopenharmony_ci	EM28XX_AOUT_PCM_CD	= 1 << 8,
39462306a36Sopenharmony_ci	EM28XX_AOUT_PCM_VIDEO	= 2 << 8,
39562306a36Sopenharmony_ci	EM28XX_AOUT_PCM_AUX	= 3 << 8,
39662306a36Sopenharmony_ci	EM28XX_AOUT_PCM_LINE	= 4 << 8,
39762306a36Sopenharmony_ci	EM28XX_AOUT_PCM_STEREO	= 5 << 8,
39862306a36Sopenharmony_ci	EM28XX_AOUT_PCM_MONO	= 6 << 8,
39962306a36Sopenharmony_ci	EM28XX_AOUT_PCM_PHONE	= 7 << 8,
40062306a36Sopenharmony_ci};
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_cistatic inline int ac97_return_record_select(int a_out)
40362306a36Sopenharmony_ci{
40462306a36Sopenharmony_ci	return (a_out & 0x700) >> 8;
40562306a36Sopenharmony_ci}
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_cistruct em28xx_reg_seq {
40862306a36Sopenharmony_ci	int reg;
40962306a36Sopenharmony_ci	unsigned char val, mask;
41062306a36Sopenharmony_ci	int sleep;
41162306a36Sopenharmony_ci};
41262306a36Sopenharmony_ci
41362306a36Sopenharmony_cistruct em28xx_input {
41462306a36Sopenharmony_ci	enum enum28xx_itype type;
41562306a36Sopenharmony_ci	unsigned int vmux;
41662306a36Sopenharmony_ci	enum em28xx_amux amux;
41762306a36Sopenharmony_ci	enum em28xx_aout aout;
41862306a36Sopenharmony_ci	const struct em28xx_reg_seq *gpio;
41962306a36Sopenharmony_ci};
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_ci#define INPUT(nr) (&em28xx_boards[dev->model].input[nr])
42262306a36Sopenharmony_ci
42362306a36Sopenharmony_cienum em28xx_decoder {
42462306a36Sopenharmony_ci	EM28XX_NODECODER = 0,
42562306a36Sopenharmony_ci	EM28XX_TVP5150,
42662306a36Sopenharmony_ci	EM28XX_SAA711X,
42762306a36Sopenharmony_ci};
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_cienum em28xx_sensor {
43062306a36Sopenharmony_ci	EM28XX_NOSENSOR = 0,
43162306a36Sopenharmony_ci	EM28XX_MT9V011,
43262306a36Sopenharmony_ci	EM28XX_MT9M001,
43362306a36Sopenharmony_ci	EM28XX_MT9M111,
43462306a36Sopenharmony_ci	EM28XX_OV2640,
43562306a36Sopenharmony_ci};
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_cienum em28xx_adecoder {
43862306a36Sopenharmony_ci	EM28XX_NOADECODER = 0,
43962306a36Sopenharmony_ci	EM28XX_TVAUDIO,
44062306a36Sopenharmony_ci};
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_cienum em28xx_led_role {
44362306a36Sopenharmony_ci	EM28XX_LED_ANALOG_CAPTURING = 0,
44462306a36Sopenharmony_ci	EM28XX_LED_DIGITAL_CAPTURING,
44562306a36Sopenharmony_ci	EM28XX_LED_DIGITAL_CAPTURING_TS2,
44662306a36Sopenharmony_ci	EM28XX_LED_ILLUMINATION,
44762306a36Sopenharmony_ci	EM28XX_NUM_LED_ROLES, /* must be the last */
44862306a36Sopenharmony_ci};
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_cistruct em28xx_led {
45162306a36Sopenharmony_ci	enum em28xx_led_role role;
45262306a36Sopenharmony_ci	u8 gpio_reg;
45362306a36Sopenharmony_ci	u8 gpio_mask;
45462306a36Sopenharmony_ci	bool inverted;
45562306a36Sopenharmony_ci};
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_cienum em28xx_button_role {
45862306a36Sopenharmony_ci	EM28XX_BUTTON_SNAPSHOT = 0,
45962306a36Sopenharmony_ci	EM28XX_BUTTON_ILLUMINATION,
46062306a36Sopenharmony_ci	EM28XX_NUM_BUTTON_ROLES, /* must be the last */
46162306a36Sopenharmony_ci};
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_cistruct em28xx_button {
46462306a36Sopenharmony_ci	enum em28xx_button_role role;
46562306a36Sopenharmony_ci	u8 reg_r;
46662306a36Sopenharmony_ci	u8 reg_clearing;
46762306a36Sopenharmony_ci	u8 mask;
46862306a36Sopenharmony_ci	bool inverted;
46962306a36Sopenharmony_ci};
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_cistruct em28xx_board {
47262306a36Sopenharmony_ci	char *name;
47362306a36Sopenharmony_ci	int vchannels;
47462306a36Sopenharmony_ci	int tuner_type;
47562306a36Sopenharmony_ci	int tuner_addr;
47662306a36Sopenharmony_ci	unsigned int def_i2c_bus;	/* Default I2C bus */
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci	/* i2c flags */
47962306a36Sopenharmony_ci	unsigned int tda9887_conf;
48062306a36Sopenharmony_ci
48162306a36Sopenharmony_ci	/* GPIO sequences */
48262306a36Sopenharmony_ci	const struct em28xx_reg_seq *dvb_gpio;
48362306a36Sopenharmony_ci	const struct em28xx_reg_seq *suspend_gpio;
48462306a36Sopenharmony_ci	const struct em28xx_reg_seq *tuner_gpio;
48562306a36Sopenharmony_ci	const struct em28xx_reg_seq *mute_gpio;
48662306a36Sopenharmony_ci
48762306a36Sopenharmony_ci	unsigned int is_em2800:1;
48862306a36Sopenharmony_ci	unsigned int has_msp34xx:1;
48962306a36Sopenharmony_ci	unsigned int mts_firmware:1;
49062306a36Sopenharmony_ci	unsigned int max_range_640_480:1;
49162306a36Sopenharmony_ci	unsigned int has_dvb:1;
49262306a36Sopenharmony_ci	unsigned int has_dual_ts:1;
49362306a36Sopenharmony_ci	unsigned int is_webcam:1;
49462306a36Sopenharmony_ci	unsigned int valid:1;
49562306a36Sopenharmony_ci	unsigned int has_ir_i2c:1;
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_ci	unsigned char xclk, i2c_speed;
49862306a36Sopenharmony_ci	unsigned char radio_addr;
49962306a36Sopenharmony_ci	unsigned short tvaudio_addr;
50062306a36Sopenharmony_ci
50162306a36Sopenharmony_ci	enum em28xx_decoder decoder;
50262306a36Sopenharmony_ci	enum em28xx_adecoder adecoder;
50362306a36Sopenharmony_ci
50462306a36Sopenharmony_ci	struct em28xx_input       input[MAX_EM28XX_INPUT];
50562306a36Sopenharmony_ci	struct em28xx_input	  radio;
50662306a36Sopenharmony_ci	char			  *ir_codes;
50762306a36Sopenharmony_ci
50862306a36Sopenharmony_ci	/* LEDs that need to be controlled explicitly */
50962306a36Sopenharmony_ci	struct em28xx_led	  *leds;
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci	/* Buttons */
51262306a36Sopenharmony_ci	const struct em28xx_button *buttons;
51362306a36Sopenharmony_ci};
51462306a36Sopenharmony_ci
51562306a36Sopenharmony_cistruct em28xx_eeprom {
51662306a36Sopenharmony_ci	u8 id[4];			/* 1a eb 67 95 */
51762306a36Sopenharmony_ci	__le16 vendor_ID;
51862306a36Sopenharmony_ci	__le16 product_ID;
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_ci	__le16 chip_conf;
52162306a36Sopenharmony_ci
52262306a36Sopenharmony_ci	__le16 board_conf;
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_ci	__le16 string1, string2, string3;
52562306a36Sopenharmony_ci
52662306a36Sopenharmony_ci	u8 string_idx_table;
52762306a36Sopenharmony_ci};
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_ci#define EM28XX_CAPTURE_STREAM_EN 1
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci/* em28xx extensions */
53262306a36Sopenharmony_ci#define EM28XX_AUDIO   0x10
53362306a36Sopenharmony_ci#define EM28XX_DVB     0x20
53462306a36Sopenharmony_ci#define EM28XX_RC      0x30
53562306a36Sopenharmony_ci#define EM28XX_V4L2    0x40
53662306a36Sopenharmony_ci
53762306a36Sopenharmony_ci/* em28xx resource types (used for res_get/res_lock etc */
53862306a36Sopenharmony_ci#define EM28XX_RESOURCE_VIDEO 0x01
53962306a36Sopenharmony_ci#define EM28XX_RESOURCE_VBI   0x02
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_cistruct em28xx_v4l2 {
54262306a36Sopenharmony_ci	struct kref ref;
54362306a36Sopenharmony_ci	struct em28xx *dev;
54462306a36Sopenharmony_ci
54562306a36Sopenharmony_ci	struct v4l2_device v4l2_dev;
54662306a36Sopenharmony_ci	struct v4l2_ctrl_handler ctrl_handler;
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_ci	struct video_device vdev;
54962306a36Sopenharmony_ci	struct video_device vbi_dev;
55062306a36Sopenharmony_ci	struct video_device radio_dev;
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_ci	/* Videobuf2 */
55362306a36Sopenharmony_ci	struct vb2_queue vb_vidq;
55462306a36Sopenharmony_ci	struct vb2_queue vb_vbiq;
55562306a36Sopenharmony_ci	struct mutex vb_queue_lock;	/* Protects vb_vidq */
55662306a36Sopenharmony_ci	struct mutex vb_vbi_queue_lock;	/* Protects vb_vbiq */
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci	u8 vinmode;
55962306a36Sopenharmony_ci	u8 vinctl;
56062306a36Sopenharmony_ci
56162306a36Sopenharmony_ci	/* Camera specific fields */
56262306a36Sopenharmony_ci	int sensor_xres;
56362306a36Sopenharmony_ci	int sensor_yres;
56462306a36Sopenharmony_ci	int sensor_xtal;
56562306a36Sopenharmony_ci
56662306a36Sopenharmony_ci	int users;		/* user count for exclusive use */
56762306a36Sopenharmony_ci	int streaming_users;    /* number of actively streaming users */
56862306a36Sopenharmony_ci
56962306a36Sopenharmony_ci	u32 frequency;		/* selected tuner frequency */
57062306a36Sopenharmony_ci
57162306a36Sopenharmony_ci	struct em28xx_fmt *format;
57262306a36Sopenharmony_ci	v4l2_std_id norm;	/* selected tv norm */
57362306a36Sopenharmony_ci
57462306a36Sopenharmony_ci	/* Progressive/interlaced mode */
57562306a36Sopenharmony_ci	bool progressive;
57662306a36Sopenharmony_ci	int interlaced_fieldmode; /* 1=interlaced fields, 0=just top fields */
57762306a36Sopenharmony_ci	/* FIXME: everything else than interlaced_fieldmode=1 doesn't work */
57862306a36Sopenharmony_ci
57962306a36Sopenharmony_ci	/* Frame properties */
58062306a36Sopenharmony_ci	int width;		/* current frame width */
58162306a36Sopenharmony_ci	int height;		/* current frame height */
58262306a36Sopenharmony_ci	unsigned int hscale;	/* horizontal scale factor (see datasheet) */
58362306a36Sopenharmony_ci	unsigned int vscale;	/* vertical scale factor (see datasheet) */
58462306a36Sopenharmony_ci	unsigned int vbi_width;
58562306a36Sopenharmony_ci	unsigned int vbi_height; /* lines per field */
58662306a36Sopenharmony_ci
58762306a36Sopenharmony_ci	/* Capture state tracking */
58862306a36Sopenharmony_ci	int capture_type;
58962306a36Sopenharmony_ci	bool top_field;
59062306a36Sopenharmony_ci	int vbi_read;
59162306a36Sopenharmony_ci	unsigned int field_count;
59262306a36Sopenharmony_ci
59362306a36Sopenharmony_ci#ifdef CONFIG_MEDIA_CONTROLLER
59462306a36Sopenharmony_ci	struct media_pad video_pad, vbi_pad;
59562306a36Sopenharmony_ci	struct media_entity *decoder;
59662306a36Sopenharmony_ci#endif
59762306a36Sopenharmony_ci};
59862306a36Sopenharmony_ci
59962306a36Sopenharmony_cistruct em28xx_audio {
60062306a36Sopenharmony_ci	char name[50];
60162306a36Sopenharmony_ci	unsigned int num_urb;
60262306a36Sopenharmony_ci	char **transfer_buffer;
60362306a36Sopenharmony_ci	struct urb **urb;
60462306a36Sopenharmony_ci	struct usb_device *udev;
60562306a36Sopenharmony_ci	unsigned int capture_transfer_done;
60662306a36Sopenharmony_ci	struct snd_pcm_substream   *capture_pcm_substream;
60762306a36Sopenharmony_ci
60862306a36Sopenharmony_ci	unsigned int hwptr_done_capture;
60962306a36Sopenharmony_ci	struct snd_card            *sndcard;
61062306a36Sopenharmony_ci
61162306a36Sopenharmony_ci	size_t period;
61262306a36Sopenharmony_ci
61362306a36Sopenharmony_ci	int users;
61462306a36Sopenharmony_ci	spinlock_t slock;		/* Protects struct em28xx_audio */
61562306a36Sopenharmony_ci
61662306a36Sopenharmony_ci	/* Controls streaming */
61762306a36Sopenharmony_ci	struct work_struct wq_trigger;	/* trigger to start/stop audio */
61862306a36Sopenharmony_ci	atomic_t       stream_started;	/* stream should be running if true */
61962306a36Sopenharmony_ci};
62062306a36Sopenharmony_ci
62162306a36Sopenharmony_cienum em28xx_i2c_algo_type {
62262306a36Sopenharmony_ci	EM28XX_I2C_ALGO_EM28XX = 0,
62362306a36Sopenharmony_ci	EM28XX_I2C_ALGO_EM2800,
62462306a36Sopenharmony_ci	EM28XX_I2C_ALGO_EM25XX_BUS_B,
62562306a36Sopenharmony_ci};
62662306a36Sopenharmony_ci
62762306a36Sopenharmony_cistruct em28xx_i2c_bus {
62862306a36Sopenharmony_ci	struct em28xx *dev;
62962306a36Sopenharmony_ci
63062306a36Sopenharmony_ci	unsigned int bus;
63162306a36Sopenharmony_ci	enum em28xx_i2c_algo_type algo_type;
63262306a36Sopenharmony_ci};
63362306a36Sopenharmony_ci
63462306a36Sopenharmony_ci/* main device struct */
63562306a36Sopenharmony_cistruct em28xx {
63662306a36Sopenharmony_ci	struct kref ref;
63762306a36Sopenharmony_ci
63862306a36Sopenharmony_ci	// Sub-module data
63962306a36Sopenharmony_ci	struct em28xx_v4l2 *v4l2;
64062306a36Sopenharmony_ci	struct em28xx_dvb *dvb;
64162306a36Sopenharmony_ci	struct em28xx_audio adev;
64262306a36Sopenharmony_ci	struct em28xx_IR *ir;
64362306a36Sopenharmony_ci
64462306a36Sopenharmony_ci	// generic device properties
64562306a36Sopenharmony_ci	int model;		// index in the device_data struct
64662306a36Sopenharmony_ci	int devno;		// marks the number of this device
64762306a36Sopenharmony_ci	enum em28xx_chip_id chip_id;
64862306a36Sopenharmony_ci
64962306a36Sopenharmony_ci	unsigned int is_em25xx:1;	// em25xx/em276x/7x/8x family bridge
65062306a36Sopenharmony_ci	unsigned int disconnected:1;	// device has been disconnected
65162306a36Sopenharmony_ci	unsigned int has_video:1;
65262306a36Sopenharmony_ci	unsigned int is_audio_only:1;
65362306a36Sopenharmony_ci	unsigned int is_webcam:1;
65462306a36Sopenharmony_ci	unsigned int has_msp34xx:1;
65562306a36Sopenharmony_ci	unsigned int i2c_speed:2;
65662306a36Sopenharmony_ci	enum em28xx_int_audio_type int_audio_type;
65762306a36Sopenharmony_ci	enum em28xx_usb_audio_type usb_audio_type;
65862306a36Sopenharmony_ci	unsigned char name[32];
65962306a36Sopenharmony_ci
66062306a36Sopenharmony_ci	struct em28xx_board board;
66162306a36Sopenharmony_ci
66262306a36Sopenharmony_ci	enum em28xx_sensor em28xx_sensor;	// camera specific
66362306a36Sopenharmony_ci
66462306a36Sopenharmony_ci	// Some older em28xx chips needs a waiting time after writing
66562306a36Sopenharmony_ci	unsigned int wait_after_write;
66662306a36Sopenharmony_ci
66762306a36Sopenharmony_ci	struct list_head	devlist;
66862306a36Sopenharmony_ci
66962306a36Sopenharmony_ci	u32 i2s_speed;		// I2S speed for audio digital stream
67062306a36Sopenharmony_ci
67162306a36Sopenharmony_ci	struct em28xx_audio_mode audio_mode;
67262306a36Sopenharmony_ci
67362306a36Sopenharmony_ci	int tuner_type;		// type of the tuner
67462306a36Sopenharmony_ci
67562306a36Sopenharmony_ci	// i2c i/o
67662306a36Sopenharmony_ci	struct i2c_adapter i2c_adap[NUM_I2C_BUSES];
67762306a36Sopenharmony_ci	struct i2c_client i2c_client[NUM_I2C_BUSES];
67862306a36Sopenharmony_ci	struct em28xx_i2c_bus i2c_bus[NUM_I2C_BUSES];
67962306a36Sopenharmony_ci
68062306a36Sopenharmony_ci	unsigned char eeprom_addrwidth_16bit:1;
68162306a36Sopenharmony_ci	unsigned int def_i2c_bus;	// Default I2C bus
68262306a36Sopenharmony_ci	unsigned int cur_i2c_bus;	// Current I2C bus
68362306a36Sopenharmony_ci	struct rt_mutex i2c_bus_lock;
68462306a36Sopenharmony_ci
68562306a36Sopenharmony_ci	// video for linux
68662306a36Sopenharmony_ci	unsigned int ctl_input;	// selected input
68762306a36Sopenharmony_ci	unsigned int ctl_ainput;// selected audio input
68862306a36Sopenharmony_ci	unsigned int ctl_aoutput;// selected audio output
68962306a36Sopenharmony_ci	enum em28xx_amux amux_map[MAX_EM28XX_INPUT];
69062306a36Sopenharmony_ci
69162306a36Sopenharmony_ci	int mute;
69262306a36Sopenharmony_ci	int volume;
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_ci	unsigned long hash;	// eeprom hash - for boards with generic ID
69562306a36Sopenharmony_ci	unsigned long i2c_hash;	// i2c devicelist hash -
69662306a36Sopenharmony_ci				// for boards with generic ID
69762306a36Sopenharmony_ci
69862306a36Sopenharmony_ci	struct work_struct         request_module_wk;
69962306a36Sopenharmony_ci
70062306a36Sopenharmony_ci	// locks
70162306a36Sopenharmony_ci	struct mutex lock;		/* protects em28xx struct */
70262306a36Sopenharmony_ci	struct mutex ctrl_urb_lock;	/* protects urb_buf */
70362306a36Sopenharmony_ci
70462306a36Sopenharmony_ci	// resources in use
70562306a36Sopenharmony_ci	unsigned int resources;
70662306a36Sopenharmony_ci
70762306a36Sopenharmony_ci	// eeprom content
70862306a36Sopenharmony_ci	u8 *eedata;
70962306a36Sopenharmony_ci	u16 eedata_len;
71062306a36Sopenharmony_ci
71162306a36Sopenharmony_ci	// Isoc control struct
71262306a36Sopenharmony_ci	struct em28xx_dmaqueue vidq;
71362306a36Sopenharmony_ci	struct em28xx_dmaqueue vbiq;
71462306a36Sopenharmony_ci	struct em28xx_usb_ctl usb_ctl;
71562306a36Sopenharmony_ci
71662306a36Sopenharmony_ci	spinlock_t slock; /* Protects em28xx video/vbi/dvb IRQ stream data */
71762306a36Sopenharmony_ci
71862306a36Sopenharmony_ci	// usb transfer
71962306a36Sopenharmony_ci	struct usb_interface *intf;	// the usb interface
72062306a36Sopenharmony_ci	u8 ifnum;		// number of the assigned usb interface
72162306a36Sopenharmony_ci	u8 analog_ep_isoc;	// address of isoc endpoint for analog
72262306a36Sopenharmony_ci	u8 analog_ep_bulk;	// address of bulk endpoint for analog
72362306a36Sopenharmony_ci	u8 dvb_ep_isoc_ts2;	// address of isoc endpoint for DVB TS2
72462306a36Sopenharmony_ci	u8 dvb_ep_bulk_ts2;	// address of bulk endpoint for DVB TS2
72562306a36Sopenharmony_ci	u8 dvb_ep_isoc;		// address of isoc endpoint for DVB
72662306a36Sopenharmony_ci	u8 dvb_ep_bulk;		// address of bulk endpoint for DVB
72762306a36Sopenharmony_ci	int alt;		// alternate setting
72862306a36Sopenharmony_ci	int max_pkt_size;	// max packet size of the selected ep at alt
72962306a36Sopenharmony_ci	int packet_multiplier;	// multiplier for wMaxPacketSize, used for
73062306a36Sopenharmony_ci				// URB buffer size definition
73162306a36Sopenharmony_ci	int num_alt;		// number of alternative settings
73262306a36Sopenharmony_ci	unsigned int *alt_max_pkt_size_isoc; // array of isoc wMaxPacketSize
73362306a36Sopenharmony_ci	unsigned int analog_xfer_bulk:1;	// use bulk instead of isoc
73462306a36Sopenharmony_ci						// transfers for analog
73562306a36Sopenharmony_ci	int dvb_alt_isoc;	// alternate setting for DVB isoc transfers
73662306a36Sopenharmony_ci	unsigned int dvb_max_pkt_size_isoc;	// isoc max packet size of the
73762306a36Sopenharmony_ci						// selected DVB ep at dvb_alt
73862306a36Sopenharmony_ci	unsigned int dvb_max_pkt_size_isoc_ts2;	// isoc max packet size of the
73962306a36Sopenharmony_ci						// selected DVB ep at dvb_alt
74062306a36Sopenharmony_ci	unsigned int dvb_xfer_bulk:1;		// use bulk instead of isoc
74162306a36Sopenharmony_ci						// transfers for DVB
74262306a36Sopenharmony_ci	char urb_buf[URB_MAX_CTRL_SIZE];	// urb control msg buffer
74362306a36Sopenharmony_ci
74462306a36Sopenharmony_ci	// helper funcs that call usb_control_msg
74562306a36Sopenharmony_ci	int (*em28xx_write_regs)(struct em28xx *dev, u16 reg,
74662306a36Sopenharmony_ci				 char *buf, int len);
74762306a36Sopenharmony_ci	int (*em28xx_read_reg)(struct em28xx *dev, u16 reg);
74862306a36Sopenharmony_ci	int (*em28xx_read_reg_req_len)(struct em28xx *dev, u8 req, u16 reg,
74962306a36Sopenharmony_ci				       char *buf, int len);
75062306a36Sopenharmony_ci	int (*em28xx_write_regs_req)(struct em28xx *dev, u8 req, u16 reg,
75162306a36Sopenharmony_ci				     char *buf, int len);
75262306a36Sopenharmony_ci	int (*em28xx_read_reg_req)(struct em28xx *dev, u8 req, u16 reg);
75362306a36Sopenharmony_ci
75462306a36Sopenharmony_ci	enum em28xx_mode mode;
75562306a36Sopenharmony_ci
75662306a36Sopenharmony_ci	// Button state polling
75762306a36Sopenharmony_ci	struct delayed_work buttons_query_work;
75862306a36Sopenharmony_ci	u8 button_polling_addresses[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
75962306a36Sopenharmony_ci	u8 button_polling_last_values[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
76062306a36Sopenharmony_ci	u8 num_button_polling_addresses;
76162306a36Sopenharmony_ci	u16 button_polling_interval; // [ms]
76262306a36Sopenharmony_ci	// Snapshot button input device
76362306a36Sopenharmony_ci	char snapshot_button_path[30];	// path of the input dev
76462306a36Sopenharmony_ci	struct input_dev *sbutton_input_dev;
76562306a36Sopenharmony_ci
76662306a36Sopenharmony_ci#ifdef CONFIG_MEDIA_CONTROLLER
76762306a36Sopenharmony_ci	struct media_device *media_dev;
76862306a36Sopenharmony_ci	struct media_entity input_ent[MAX_EM28XX_INPUT];
76962306a36Sopenharmony_ci	struct media_pad input_pad[MAX_EM28XX_INPUT];
77062306a36Sopenharmony_ci#endif
77162306a36Sopenharmony_ci
77262306a36Sopenharmony_ci	struct em28xx	*dev_next;
77362306a36Sopenharmony_ci	int ts;
77462306a36Sopenharmony_ci};
77562306a36Sopenharmony_ci
77662306a36Sopenharmony_ci#define kref_to_dev(d) container_of(d, struct em28xx, ref)
77762306a36Sopenharmony_ci
77862306a36Sopenharmony_cistruct em28xx_ops {
77962306a36Sopenharmony_ci	struct list_head next;
78062306a36Sopenharmony_ci	char *name;
78162306a36Sopenharmony_ci	int id;
78262306a36Sopenharmony_ci	int (*init)(struct em28xx *dev);
78362306a36Sopenharmony_ci	int (*fini)(struct em28xx *dev);
78462306a36Sopenharmony_ci	int (*suspend)(struct em28xx *dev);
78562306a36Sopenharmony_ci	int (*resume)(struct em28xx *dev);
78662306a36Sopenharmony_ci};
78762306a36Sopenharmony_ci
78862306a36Sopenharmony_ci/* Provided by em28xx-i2c.c */
78962306a36Sopenharmony_civoid em28xx_do_i2c_scan(struct em28xx *dev, unsigned int bus);
79062306a36Sopenharmony_ciint  em28xx_i2c_register(struct em28xx *dev, unsigned int bus,
79162306a36Sopenharmony_ci			 enum em28xx_i2c_algo_type algo_type);
79262306a36Sopenharmony_ciint  em28xx_i2c_unregister(struct em28xx *dev, unsigned int bus);
79362306a36Sopenharmony_ci
79462306a36Sopenharmony_ci/* Provided by em28xx-core.c */
79562306a36Sopenharmony_ciint em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
79662306a36Sopenharmony_ci			    char *buf, int len);
79762306a36Sopenharmony_ciint em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);
79862306a36Sopenharmony_ciint em28xx_read_reg(struct em28xx *dev, u16 reg);
79962306a36Sopenharmony_ciint em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
80062306a36Sopenharmony_ci			  int len);
80162306a36Sopenharmony_ciint em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);
80262306a36Sopenharmony_ciint em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val);
80362306a36Sopenharmony_ciint em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
80462306a36Sopenharmony_ci			  u8 bitmask);
80562306a36Sopenharmony_ciint em28xx_toggle_reg_bits(struct em28xx *dev, u16 reg, u8 bitmask);
80662306a36Sopenharmony_ci
80762306a36Sopenharmony_ciint em28xx_read_ac97(struct em28xx *dev, u8 reg);
80862306a36Sopenharmony_ciint em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val);
80962306a36Sopenharmony_ci
81062306a36Sopenharmony_ciint em28xx_audio_analog_set(struct em28xx *dev);
81162306a36Sopenharmony_ciint em28xx_audio_setup(struct em28xx *dev);
81262306a36Sopenharmony_ci
81362306a36Sopenharmony_ciconst struct em28xx_led *em28xx_find_led(struct em28xx *dev,
81462306a36Sopenharmony_ci					 enum em28xx_led_role role);
81562306a36Sopenharmony_ciint em28xx_capture_start(struct em28xx *dev, int start);
81662306a36Sopenharmony_ciint em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
81762306a36Sopenharmony_ci		      int num_bufs, int max_pkt_size, int packet_multiplier);
81862306a36Sopenharmony_ciint em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
81962306a36Sopenharmony_ci			 int xfer_bulk,
82062306a36Sopenharmony_ci			 int num_bufs, int max_pkt_size, int packet_multiplier,
82162306a36Sopenharmony_ci			 int (*urb_data_copy)
82262306a36Sopenharmony_ci					(struct em28xx *dev, struct urb *urb));
82362306a36Sopenharmony_civoid em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
82462306a36Sopenharmony_civoid em28xx_stop_urbs(struct em28xx *dev);
82562306a36Sopenharmony_ciint em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
82662306a36Sopenharmony_ciint em28xx_gpio_set(struct em28xx *dev, const struct em28xx_reg_seq *gpio);
82762306a36Sopenharmony_ciint em28xx_register_extension(struct em28xx_ops *dev);
82862306a36Sopenharmony_civoid em28xx_unregister_extension(struct em28xx_ops *dev);
82962306a36Sopenharmony_civoid em28xx_init_extension(struct em28xx *dev);
83062306a36Sopenharmony_civoid em28xx_close_extension(struct em28xx *dev);
83162306a36Sopenharmony_ciint em28xx_suspend_extension(struct em28xx *dev);
83262306a36Sopenharmony_ciint em28xx_resume_extension(struct em28xx *dev);
83362306a36Sopenharmony_ci
83462306a36Sopenharmony_ci/* Provided by em28xx-cards.c */
83562306a36Sopenharmony_ciextern const struct em28xx_board em28xx_boards[];
83662306a36Sopenharmony_ciextern struct usb_device_id em28xx_id_table[];
83762306a36Sopenharmony_ciint em28xx_tuner_callback(void *ptr, int component, int command, int arg);
83862306a36Sopenharmony_civoid em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl);
83962306a36Sopenharmony_civoid em28xx_free_device(struct kref *ref);
84062306a36Sopenharmony_ci
84162306a36Sopenharmony_ci/* Provided by em28xx-camera.c */
84262306a36Sopenharmony_ciint em28xx_detect_sensor(struct em28xx *dev);
84362306a36Sopenharmony_ciint em28xx_init_camera(struct em28xx *dev);
84462306a36Sopenharmony_ci
84562306a36Sopenharmony_ci#endif
846