18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * em28xx.h - driver for Empia EM2800/EM2820/2840 USB video capture devices
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
68c2ecf20Sopenharmony_ci *		      Ludovico Cavedon <cavedon@sssup.it>
78c2ecf20Sopenharmony_ci *		      Mauro Carvalho Chehab <mchehab@kernel.org>
88c2ecf20Sopenharmony_ci * Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
138c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
148c2ecf20Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
158c2ecf20Sopenharmony_ci * (at your option) any later version.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
188c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
198c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
208c2ecf20Sopenharmony_ci * GNU General Public License for more details.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#ifndef _EM28XX_H
248c2ecf20Sopenharmony_ci#define _EM28XX_H
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include <linux/bitfield.h>
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define EM28XX_VERSION "0.2.2"
298c2ecf20Sopenharmony_ci#define DRIVER_DESC    "Empia em28xx device driver"
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
328c2ecf20Sopenharmony_ci#include <linux/i2c.h>
338c2ecf20Sopenharmony_ci#include <linux/mutex.h>
348c2ecf20Sopenharmony_ci#include <linux/kref.h>
358c2ecf20Sopenharmony_ci#include <linux/videodev2.h>
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#include <media/videobuf2-v4l2.h>
388c2ecf20Sopenharmony_ci#include <media/videobuf2-vmalloc.h>
398c2ecf20Sopenharmony_ci#include <media/v4l2-device.h>
408c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h>
418c2ecf20Sopenharmony_ci#include <media/v4l2-fh.h>
428c2ecf20Sopenharmony_ci#include <media/i2c/ir-kbd-i2c.h>
438c2ecf20Sopenharmony_ci#include <media/rc-core.h>
448c2ecf20Sopenharmony_ci#include "tuner-xc2028.h"
458c2ecf20Sopenharmony_ci#include "xc5000.h"
468c2ecf20Sopenharmony_ci#include "em28xx-reg.h"
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* Boards supported by driver */
498c2ecf20Sopenharmony_ci#define EM2800_BOARD_UNKNOWN			  0
508c2ecf20Sopenharmony_ci#define EM2820_BOARD_UNKNOWN			  1
518c2ecf20Sopenharmony_ci#define EM2820_BOARD_TERRATEC_CINERGY_250	  2
528c2ecf20Sopenharmony_ci#define EM2820_BOARD_PINNACLE_USB_2		  3
538c2ecf20Sopenharmony_ci#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2	  4
548c2ecf20Sopenharmony_ci#define EM2820_BOARD_MSI_VOX_USB_2		  5
558c2ecf20Sopenharmony_ci#define EM2800_BOARD_TERRATEC_CINERGY_200	  6
568c2ecf20Sopenharmony_ci#define EM2800_BOARD_LEADTEK_WINFAST_USBII	  7
578c2ecf20Sopenharmony_ci#define EM2800_BOARD_KWORLD_USB2800		  8
588c2ecf20Sopenharmony_ci#define EM2820_BOARD_PINNACLE_DVC_90		  9
598c2ecf20Sopenharmony_ci#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900	  10
608c2ecf20Sopenharmony_ci#define EM2880_BOARD_TERRATEC_HYBRID_XS		  11
618c2ecf20Sopenharmony_ci#define EM2820_BOARD_KWORLD_PVRTV2800RF		  12
628c2ecf20Sopenharmony_ci#define EM2880_BOARD_TERRATEC_PRODIGY_XS	  13
638c2ecf20Sopenharmony_ci#define EM2820_BOARD_PROLINK_PLAYTV_USB2	  14
648c2ecf20Sopenharmony_ci#define EM2800_BOARD_VGEAR_POCKETTV		  15
658c2ecf20Sopenharmony_ci#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950	  16
668c2ecf20Sopenharmony_ci#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO	  17
678c2ecf20Sopenharmony_ci#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2	  18
688c2ecf20Sopenharmony_ci#define EM2860_BOARD_SAA711X_REFERENCE_DESIGN	  19
698c2ecf20Sopenharmony_ci#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600	  20
708c2ecf20Sopenharmony_ci#define EM2800_BOARD_GRABBEEX_USB2800		  21
718c2ecf20Sopenharmony_ci#define EM2750_BOARD_UNKNOWN			  22
728c2ecf20Sopenharmony_ci#define EM2750_BOARD_DLCW_130			  23
738c2ecf20Sopenharmony_ci#define EM2820_BOARD_DLINK_USB_TV		  24
748c2ecf20Sopenharmony_ci#define EM2820_BOARD_GADMEI_UTV310		  25
758c2ecf20Sopenharmony_ci#define EM2820_BOARD_HERCULES_SMART_TV_USB2	  26
768c2ecf20Sopenharmony_ci#define EM2820_BOARD_PINNACLE_USB_2_FM1216ME	  27
778c2ecf20Sopenharmony_ci#define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28
788c2ecf20Sopenharmony_ci#define EM2860_BOARD_TVP5150_REFERENCE_DESIGN	  29
798c2ecf20Sopenharmony_ci#define EM2820_BOARD_VIDEOLOGY_20K14XUSB	  30
808c2ecf20Sopenharmony_ci#define EM2821_BOARD_USBGEAR_VD204		  31
818c2ecf20Sopenharmony_ci#define EM2821_BOARD_SUPERCOMP_USB_2		  32
828c2ecf20Sopenharmony_ci#define EM2860_BOARD_ELGATO_VIDEO_CAPTURE	  33
838c2ecf20Sopenharmony_ci#define EM2860_BOARD_TERRATEC_HYBRID_XS		  34
848c2ecf20Sopenharmony_ci#define EM2860_BOARD_TYPHOON_DVD_MAKER		  35
858c2ecf20Sopenharmony_ci#define EM2860_BOARD_NETGMBH_CAM		  36
868c2ecf20Sopenharmony_ci#define EM2860_BOARD_GADMEI_UTV330		  37
878c2ecf20Sopenharmony_ci#define EM2861_BOARD_YAKUMO_MOVIE_MIXER		  38
888c2ecf20Sopenharmony_ci#define EM2861_BOARD_KWORLD_PVRTV_300U		  39
898c2ecf20Sopenharmony_ci#define EM2861_BOARD_PLEXTOR_PX_TV100U		  40
908c2ecf20Sopenharmony_ci#define EM2870_BOARD_KWORLD_350U		  41
918c2ecf20Sopenharmony_ci#define EM2870_BOARD_KWORLD_355U		  42
928c2ecf20Sopenharmony_ci#define EM2870_BOARD_TERRATEC_XS		  43
938c2ecf20Sopenharmony_ci#define EM2870_BOARD_TERRATEC_XS_MT2060		  44
948c2ecf20Sopenharmony_ci#define EM2870_BOARD_PINNACLE_PCTV_DVB		  45
958c2ecf20Sopenharmony_ci#define EM2870_BOARD_COMPRO_VIDEOMATE		  46
968c2ecf20Sopenharmony_ci#define EM2880_BOARD_KWORLD_DVB_305U		  47
978c2ecf20Sopenharmony_ci#define EM2880_BOARD_KWORLD_DVB_310U		  48
988c2ecf20Sopenharmony_ci#define EM2880_BOARD_MSI_DIGIVOX_AD		  49
998c2ecf20Sopenharmony_ci#define EM2880_BOARD_MSI_DIGIVOX_AD_II		  50
1008c2ecf20Sopenharmony_ci#define EM2880_BOARD_TERRATEC_HYBRID_XS_FR	  51
1018c2ecf20Sopenharmony_ci#define EM2881_BOARD_DNT_DA2_HYBRID		  52
1028c2ecf20Sopenharmony_ci#define EM2881_BOARD_PINNACLE_HYBRID_PRO	  53
1038c2ecf20Sopenharmony_ci#define EM2882_BOARD_KWORLD_VS_DVBT		  54
1048c2ecf20Sopenharmony_ci#define EM2882_BOARD_TERRATEC_HYBRID_XS		  55
1058c2ecf20Sopenharmony_ci#define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E	  56
1068c2ecf20Sopenharmony_ci#define EM2883_BOARD_KWORLD_HYBRID_330U		  57
1078c2ecf20Sopenharmony_ci#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU	  58
1088c2ecf20Sopenharmony_ci#define EM2874_BOARD_PCTV_HD_MINI_80E		  59
1098c2ecf20Sopenharmony_ci#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850	  60
1108c2ecf20Sopenharmony_ci#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2	  61
1118c2ecf20Sopenharmony_ci#define EM2820_BOARD_GADMEI_TVR200		  62
1128c2ecf20Sopenharmony_ci#define EM2860_BOARD_KAIOMY_TVNPC_U2		  63
1138c2ecf20Sopenharmony_ci#define EM2860_BOARD_EASYCAP			  64
1148c2ecf20Sopenharmony_ci#define EM2820_BOARD_IODATA_GVMVP_SZ		  65
1158c2ecf20Sopenharmony_ci#define EM2880_BOARD_EMPIRE_DUAL_TV		  66
1168c2ecf20Sopenharmony_ci#define EM2860_BOARD_TERRATEC_GRABBY		  67
1178c2ecf20Sopenharmony_ci#define EM2860_BOARD_TERRATEC_AV350		  68
1188c2ecf20Sopenharmony_ci#define EM2882_BOARD_KWORLD_ATSC_315U		  69
1198c2ecf20Sopenharmony_ci#define EM2882_BOARD_EVGA_INDTUBE		  70
1208c2ecf20Sopenharmony_ci#define EM2820_BOARD_SILVERCREST_WEBCAM		  71
1218c2ecf20Sopenharmony_ci#define EM2861_BOARD_GADMEI_UTV330PLUS		  72
1228c2ecf20Sopenharmony_ci#define EM2870_BOARD_REDDO_DVB_C_USB_BOX	  73
1238c2ecf20Sopenharmony_ci#define EM2800_BOARD_VC211A			  74
1248c2ecf20Sopenharmony_ci#define EM2882_BOARD_DIKOM_DK300		  75
1258c2ecf20Sopenharmony_ci#define EM2870_BOARD_KWORLD_A340		  76
1268c2ecf20Sopenharmony_ci#define EM2874_BOARD_LEADERSHIP_ISDBT		  77
1278c2ecf20Sopenharmony_ci#define EM28174_BOARD_PCTV_290E			  78
1288c2ecf20Sopenharmony_ci#define EM2884_BOARD_TERRATEC_H5		  79
1298c2ecf20Sopenharmony_ci#define EM28174_BOARD_PCTV_460E			  80
1308c2ecf20Sopenharmony_ci#define EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C	  81
1318c2ecf20Sopenharmony_ci#define EM2884_BOARD_CINERGY_HTC_STICK		  82
1328c2ecf20Sopenharmony_ci#define EM2860_BOARD_HT_VIDBOX_NW03		  83
1338c2ecf20Sopenharmony_ci#define EM2874_BOARD_MAXMEDIA_UB425_TC		  84
1348c2ecf20Sopenharmony_ci#define EM2884_BOARD_PCTV_510E			  85
1358c2ecf20Sopenharmony_ci#define EM2884_BOARD_PCTV_520E			  86
1368c2ecf20Sopenharmony_ci#define EM2884_BOARD_TERRATEC_HTC_USB_XS	  87
1378c2ecf20Sopenharmony_ci#define EM2884_BOARD_C3TECH_DIGITAL_DUO		  88
1388c2ecf20Sopenharmony_ci#define EM2874_BOARD_DELOCK_61959		  89
1398c2ecf20Sopenharmony_ci#define EM2874_BOARD_KWORLD_UB435Q_V2		  90
1408c2ecf20Sopenharmony_ci#define EM2765_BOARD_SPEEDLINK_VAD_LAPLACE	  91
1418c2ecf20Sopenharmony_ci#define EM28178_BOARD_PCTV_461E                   92
1428c2ecf20Sopenharmony_ci#define EM2874_BOARD_KWORLD_UB435Q_V3		  93
1438c2ecf20Sopenharmony_ci#define EM28178_BOARD_PCTV_292E                   94
1448c2ecf20Sopenharmony_ci#define EM2861_BOARD_LEADTEK_VC100                95
1458c2ecf20Sopenharmony_ci#define EM28178_BOARD_TERRATEC_T2_STICK_HD        96
1468c2ecf20Sopenharmony_ci#define EM2884_BOARD_ELGATO_EYETV_HYBRID_2008     97
1478c2ecf20Sopenharmony_ci#define EM28178_BOARD_PLEX_PX_BCUD                98
1488c2ecf20Sopenharmony_ci#define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB  99
1498c2ecf20Sopenharmony_ci#define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595 100
1508c2ecf20Sopenharmony_ci#define EM2884_BOARD_TERRATEC_H6		  101
1518c2ecf20Sopenharmony_ci#define EM2882_BOARD_ZOLID_HYBRID_TV_STICK		102
1528c2ecf20Sopenharmony_ci#define EM2861_BOARD_MAGIX_VIDEOWANDLER2          103
1538c2ecf20Sopenharmony_ci#define EM28178_BOARD_PCTV_461E_V2                104
1548c2ecf20Sopenharmony_ci#define EM2860_BOARD_MYGICA_IGRABBER              105
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* Limits minimum and default number of buffers */
1578c2ecf20Sopenharmony_ci#define EM28XX_MIN_BUF 4
1588c2ecf20Sopenharmony_ci#define EM28XX_DEF_BUF 8
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/*Limits the max URB message size */
1618c2ecf20Sopenharmony_ci#define URB_MAX_CTRL_SIZE 80
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci/* Params for validated field */
1648c2ecf20Sopenharmony_ci#define EM28XX_BOARD_NOT_VALIDATED 1
1658c2ecf20Sopenharmony_ci#define EM28XX_BOARD_VALIDATED	   0
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci/* Params for em28xx_cmd() audio */
1688c2ecf20Sopenharmony_ci#define EM28XX_START_AUDIO      1
1698c2ecf20Sopenharmony_ci#define EM28XX_STOP_AUDIO       0
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* maximum number of em28xx boards */
1728c2ecf20Sopenharmony_ci#define EM28XX_MAXBOARDS DVB_MAX_ADAPTERS /* All adapters could be em28xx */
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/* maximum number of frames that can be queued */
1758c2ecf20Sopenharmony_ci#define EM28XX_NUM_FRAMES 5
1768c2ecf20Sopenharmony_ci/* number of frames that get used for v4l2_read() */
1778c2ecf20Sopenharmony_ci#define EM28XX_NUM_READ_FRAMES 2
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/* number of buffers for isoc transfers */
1808c2ecf20Sopenharmony_ci#define EM28XX_NUM_BUFS 5
1818c2ecf20Sopenharmony_ci#define EM28XX_DVB_NUM_BUFS 5
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* max number of I2C buses on em28xx devices */
1848c2ecf20Sopenharmony_ci#define NUM_I2C_BUSES	2
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci/*
1878c2ecf20Sopenharmony_ci * isoc transfers: number of packets for each buffer
1888c2ecf20Sopenharmony_ci * windows requests only 64 packets .. so we better do the same
1898c2ecf20Sopenharmony_ci * this is what I found out for all alternate numbers there!
1908c2ecf20Sopenharmony_ci */
1918c2ecf20Sopenharmony_ci#define EM28XX_NUM_ISOC_PACKETS 64
1928c2ecf20Sopenharmony_ci#define EM28XX_DVB_NUM_ISOC_PACKETS 64
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci/*
1958c2ecf20Sopenharmony_ci * bulk transfers: transfer buffer size = packet size * packet multiplier
1968c2ecf20Sopenharmony_ci * USB 2.0 spec says bulk packet size is always 512 bytes
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_ci#define EM28XX_BULK_PACKET_MULTIPLIER 384
1998c2ecf20Sopenharmony_ci#define EM28XX_DVB_BULK_PACKET_MULTIPLIER 94
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#define EM28XX_INTERLACED_DEFAULT 1
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci/* time in msecs to wait for AC97 xfers to finish */
2048c2ecf20Sopenharmony_ci#define EM28XX_AC97_XFER_TIMEOUT	100
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/* max. number of button state polling addresses */
2078c2ecf20Sopenharmony_ci#define EM28XX_NUM_BUTTON_ADDRESSES_MAX		5
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#define PRIMARY_TS	0
2108c2ecf20Sopenharmony_ci#define SECONDARY_TS	1
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_cienum em28xx_mode {
2138c2ecf20Sopenharmony_ci	EM28XX_SUSPEND,
2148c2ecf20Sopenharmony_ci	EM28XX_ANALOG_MODE,
2158c2ecf20Sopenharmony_ci	EM28XX_DIGITAL_MODE,
2168c2ecf20Sopenharmony_ci};
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_cistruct em28xx;
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci/**
2218c2ecf20Sopenharmony_ci * struct em28xx_usb_bufs - Contains URB-related buffer data
2228c2ecf20Sopenharmony_ci *
2238c2ecf20Sopenharmony_ci * @max_pkt_size:	max packet size of isoc transaction
2248c2ecf20Sopenharmony_ci * @num_packets:	number of packets in each buffer
2258c2ecf20Sopenharmony_ci * @num_bufs:		number of allocated urb
2268c2ecf20Sopenharmony_ci * @urb:		urb for isoc/bulk transfers
2278c2ecf20Sopenharmony_ci * @buf:		transfer buffers for isoc/bulk transfer
2288c2ecf20Sopenharmony_ci */
2298c2ecf20Sopenharmony_cistruct em28xx_usb_bufs {
2308c2ecf20Sopenharmony_ci	int				max_pkt_size;
2318c2ecf20Sopenharmony_ci	int				num_packets;
2328c2ecf20Sopenharmony_ci	int				num_bufs;
2338c2ecf20Sopenharmony_ci	struct urb			**urb;
2348c2ecf20Sopenharmony_ci	char				**buf;
2358c2ecf20Sopenharmony_ci};
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci/**
2388c2ecf20Sopenharmony_ci * struct em28xx_usb_ctl - Contains URB-related buffer data
2398c2ecf20Sopenharmony_ci *
2408c2ecf20Sopenharmony_ci * @analog_bufs:	isoc/bulk transfer buffers for analog mode
2418c2ecf20Sopenharmony_ci * @digital_bufs:	isoc/bulk transfer buffers for digital mode
2428c2ecf20Sopenharmony_ci * @vid_buf:		Stores already requested video buffers
2438c2ecf20Sopenharmony_ci * @vbi_buf:		Stores already requested VBI buffers
2448c2ecf20Sopenharmony_ci * @urb_data_copy:	copy data from URB
2458c2ecf20Sopenharmony_ci */
2468c2ecf20Sopenharmony_cistruct em28xx_usb_ctl {
2478c2ecf20Sopenharmony_ci	struct em28xx_usb_bufs		analog_bufs;
2488c2ecf20Sopenharmony_ci	struct em28xx_usb_bufs		digital_bufs;
2498c2ecf20Sopenharmony_ci	struct em28xx_buffer	*vid_buf;
2508c2ecf20Sopenharmony_ci	struct em28xx_buffer	*vbi_buf;
2518c2ecf20Sopenharmony_ci	int (*urb_data_copy)(struct em28xx *dev, struct urb *urb);
2528c2ecf20Sopenharmony_ci};
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/**
2558c2ecf20Sopenharmony_ci * struct em28xx_fmt - Struct to enumberate video formats
2568c2ecf20Sopenharmony_ci *
2578c2ecf20Sopenharmony_ci * @fourcc:	v4l2 format id
2588c2ecf20Sopenharmony_ci * @depth:	mean number of bits to represent a pixel
2598c2ecf20Sopenharmony_ci * @reg:	em28xx register value to set it
2608c2ecf20Sopenharmony_ci */
2618c2ecf20Sopenharmony_cistruct em28xx_fmt {
2628c2ecf20Sopenharmony_ci	u32	fourcc;
2638c2ecf20Sopenharmony_ci	int	depth;
2648c2ecf20Sopenharmony_ci	int	reg;
2658c2ecf20Sopenharmony_ci};
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci/**
2688c2ecf20Sopenharmony_ci * struct em28xx_buffer- buffer for storing one video frame
2698c2ecf20Sopenharmony_ci *
2708c2ecf20Sopenharmony_ci * @vb:		common v4l buffer stuff
2718c2ecf20Sopenharmony_ci * @list:	List to associate it with the other buffers
2728c2ecf20Sopenharmony_ci * @mem:	pointer to the buffer, as returned by vb2_plane_vaddr()
2738c2ecf20Sopenharmony_ci * @length:	length of the buffer, as returned by vb2_plane_size()
2748c2ecf20Sopenharmony_ci * @top_field:	If non-zero, indicate that the buffer is the top field
2758c2ecf20Sopenharmony_ci * @pos:	Indicate the next position of the buffer to be filled.
2768c2ecf20Sopenharmony_ci * @vb_buf:	pointer to vmalloc memory address in vb
2778c2ecf20Sopenharmony_ci *
2788c2ecf20Sopenharmony_ci * .. note::
2798c2ecf20Sopenharmony_ci *
2808c2ecf20Sopenharmony_ci *    in interlaced mode, @pos is reset to zero at the start of each new
2818c2ecf20Sopenharmony_ci *    field (not frame !)
2828c2ecf20Sopenharmony_ci */
2838c2ecf20Sopenharmony_cistruct em28xx_buffer {
2848c2ecf20Sopenharmony_ci	struct vb2_v4l2_buffer	vb;		/* must be first */
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	struct list_head	list;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	void			*mem;
2898c2ecf20Sopenharmony_ci	unsigned int		length;
2908c2ecf20Sopenharmony_ci	int			top_field;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	unsigned int		pos;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	char			*vb_buf;
2958c2ecf20Sopenharmony_ci};
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_cistruct em28xx_dmaqueue {
2988c2ecf20Sopenharmony_ci	struct list_head       active;
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci	wait_queue_head_t          wq;
3018c2ecf20Sopenharmony_ci};
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci/* inputs */
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci#define MAX_EM28XX_INPUT 4
3068c2ecf20Sopenharmony_cienum enum28xx_itype {
3078c2ecf20Sopenharmony_ci	EM28XX_VMUX_COMPOSITE = 1,
3088c2ecf20Sopenharmony_ci	EM28XX_VMUX_SVIDEO,
3098c2ecf20Sopenharmony_ci	EM28XX_VMUX_TELEVISION,
3108c2ecf20Sopenharmony_ci	EM28XX_RADIO,
3118c2ecf20Sopenharmony_ci};
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cienum em28xx_ac97_mode {
3148c2ecf20Sopenharmony_ci	EM28XX_NO_AC97 = 0,
3158c2ecf20Sopenharmony_ci	EM28XX_AC97_EM202,
3168c2ecf20Sopenharmony_ci	EM28XX_AC97_SIGMATEL,
3178c2ecf20Sopenharmony_ci	EM28XX_AC97_OTHER,
3188c2ecf20Sopenharmony_ci};
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistruct em28xx_audio_mode {
3218c2ecf20Sopenharmony_ci	enum em28xx_ac97_mode ac97;
3228c2ecf20Sopenharmony_ci};
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cienum em28xx_int_audio_type {
3258c2ecf20Sopenharmony_ci	EM28XX_INT_AUDIO_NONE = 0,
3268c2ecf20Sopenharmony_ci	EM28XX_INT_AUDIO_AC97,
3278c2ecf20Sopenharmony_ci	EM28XX_INT_AUDIO_I2S,
3288c2ecf20Sopenharmony_ci};
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_cienum em28xx_usb_audio_type {
3318c2ecf20Sopenharmony_ci	EM28XX_USB_AUDIO_NONE = 0,
3328c2ecf20Sopenharmony_ci	EM28XX_USB_AUDIO_CLASS,
3338c2ecf20Sopenharmony_ci	EM28XX_USB_AUDIO_VENDOR,
3348c2ecf20Sopenharmony_ci};
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci/**
3378c2ecf20Sopenharmony_ci * em28xx_amux - describes the type of audio input used by em28xx
3388c2ecf20Sopenharmony_ci *
3398c2ecf20Sopenharmony_ci * @EM28XX_AMUX_UNUSED:
3408c2ecf20Sopenharmony_ci *	Used only on em28xx dev->map field, in order to mark an entry
3418c2ecf20Sopenharmony_ci *	as unused.
3428c2ecf20Sopenharmony_ci * @EM28XX_AMUX_VIDEO:
3438c2ecf20Sopenharmony_ci *	On devices without AC97, this is the only value that it is currently
3448c2ecf20Sopenharmony_ci *	allowed.
3458c2ecf20Sopenharmony_ci *	On devices with AC97, it corresponds to the AC97 mixer "Video" control.
3468c2ecf20Sopenharmony_ci * @EM28XX_AMUX_LINE_IN:
3478c2ecf20Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "Line In".
3488c2ecf20Sopenharmony_ci * @EM28XX_AMUX_VIDEO2:
3498c2ecf20Sopenharmony_ci *	Only for devices with AC97. It means that em28xx should use "Line In"
3508c2ecf20Sopenharmony_ci *	And AC97 should use the "Video" mixer control.
3518c2ecf20Sopenharmony_ci * @EM28XX_AMUX_PHONE:
3528c2ecf20Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "Phone".
3538c2ecf20Sopenharmony_ci * @EM28XX_AMUX_MIC:
3548c2ecf20Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "Mic".
3558c2ecf20Sopenharmony_ci * @EM28XX_AMUX_CD:
3568c2ecf20Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "CD".
3578c2ecf20Sopenharmony_ci * @EM28XX_AMUX_AUX:
3588c2ecf20Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "Aux".
3598c2ecf20Sopenharmony_ci * @EM28XX_AMUX_PCM_OUT:
3608c2ecf20Sopenharmony_ci *	Only for devices with AC97. Corresponds to AC97 mixer "PCM out".
3618c2ecf20Sopenharmony_ci *
3628c2ecf20Sopenharmony_ci * The em28xx chip itself has only two audio inputs: tuner and line in.
3638c2ecf20Sopenharmony_ci * On almost all devices, only the tuner input is used.
3648c2ecf20Sopenharmony_ci *
3658c2ecf20Sopenharmony_ci * However, on most devices, an auxiliary AC97 codec device is used,
3668c2ecf20Sopenharmony_ci * usually connected to the em28xx tuner input (except for
3678c2ecf20Sopenharmony_ci * @EM28XX_AMUX_LINE_IN).
3688c2ecf20Sopenharmony_ci *
3698c2ecf20Sopenharmony_ci * The AC97 device typically have several different inputs and outputs.
3708c2ecf20Sopenharmony_ci * The exact number and description depends on their model.
3718c2ecf20Sopenharmony_ci *
3728c2ecf20Sopenharmony_ci * It is possible to AC97 to mixer more than one different entries at the
3738c2ecf20Sopenharmony_ci * same time, via the alsa mux.
3748c2ecf20Sopenharmony_ci */
3758c2ecf20Sopenharmony_cienum em28xx_amux {
3768c2ecf20Sopenharmony_ci	EM28XX_AMUX_UNUSED = -1,
3778c2ecf20Sopenharmony_ci	EM28XX_AMUX_VIDEO = 0,
3788c2ecf20Sopenharmony_ci	EM28XX_AMUX_LINE_IN,
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	/* Some less-common mixer setups */
3818c2ecf20Sopenharmony_ci	EM28XX_AMUX_VIDEO2,
3828c2ecf20Sopenharmony_ci	EM28XX_AMUX_PHONE,
3838c2ecf20Sopenharmony_ci	EM28XX_AMUX_MIC,
3848c2ecf20Sopenharmony_ci	EM28XX_AMUX_CD,
3858c2ecf20Sopenharmony_ci	EM28XX_AMUX_AUX,
3868c2ecf20Sopenharmony_ci	EM28XX_AMUX_PCM_OUT,
3878c2ecf20Sopenharmony_ci};
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_cienum em28xx_aout {
3908c2ecf20Sopenharmony_ci	/* AC97 outputs */
3918c2ecf20Sopenharmony_ci	EM28XX_AOUT_MASTER = BIT(0),
3928c2ecf20Sopenharmony_ci	EM28XX_AOUT_LINE   = BIT(1),
3938c2ecf20Sopenharmony_ci	EM28XX_AOUT_MONO   = BIT(2),
3948c2ecf20Sopenharmony_ci	EM28XX_AOUT_LFE    = BIT(3),
3958c2ecf20Sopenharmony_ci	EM28XX_AOUT_SURR   = BIT(4),
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	/* PCM IN Mixer - used by AC97_RECORD_SELECT register */
3988c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_IN = BIT(7),
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	/* Bits 10-8 are used to indicate the PCM IN record select */
4018c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_MIC_PCM = 0 << 8,
4028c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_CD	= 1 << 8,
4038c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_VIDEO	= 2 << 8,
4048c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_AUX	= 3 << 8,
4058c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_LINE	= 4 << 8,
4068c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_STEREO	= 5 << 8,
4078c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_MONO	= 6 << 8,
4088c2ecf20Sopenharmony_ci	EM28XX_AOUT_PCM_PHONE	= 7 << 8,
4098c2ecf20Sopenharmony_ci};
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_cistatic inline int ac97_return_record_select(int a_out)
4128c2ecf20Sopenharmony_ci{
4138c2ecf20Sopenharmony_ci	return (a_out & 0x700) >> 8;
4148c2ecf20Sopenharmony_ci}
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_cistruct em28xx_reg_seq {
4178c2ecf20Sopenharmony_ci	int reg;
4188c2ecf20Sopenharmony_ci	unsigned char val, mask;
4198c2ecf20Sopenharmony_ci	int sleep;
4208c2ecf20Sopenharmony_ci};
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_cistruct em28xx_input {
4238c2ecf20Sopenharmony_ci	enum enum28xx_itype type;
4248c2ecf20Sopenharmony_ci	unsigned int vmux;
4258c2ecf20Sopenharmony_ci	enum em28xx_amux amux;
4268c2ecf20Sopenharmony_ci	enum em28xx_aout aout;
4278c2ecf20Sopenharmony_ci	const struct em28xx_reg_seq *gpio;
4288c2ecf20Sopenharmony_ci};
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci#define INPUT(nr) (&em28xx_boards[dev->model].input[nr])
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_cienum em28xx_decoder {
4338c2ecf20Sopenharmony_ci	EM28XX_NODECODER = 0,
4348c2ecf20Sopenharmony_ci	EM28XX_TVP5150,
4358c2ecf20Sopenharmony_ci	EM28XX_SAA711X,
4368c2ecf20Sopenharmony_ci};
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_cienum em28xx_sensor {
4398c2ecf20Sopenharmony_ci	EM28XX_NOSENSOR = 0,
4408c2ecf20Sopenharmony_ci	EM28XX_MT9V011,
4418c2ecf20Sopenharmony_ci	EM28XX_MT9M001,
4428c2ecf20Sopenharmony_ci	EM28XX_MT9M111,
4438c2ecf20Sopenharmony_ci	EM28XX_OV2640,
4448c2ecf20Sopenharmony_ci};
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_cienum em28xx_adecoder {
4478c2ecf20Sopenharmony_ci	EM28XX_NOADECODER = 0,
4488c2ecf20Sopenharmony_ci	EM28XX_TVAUDIO,
4498c2ecf20Sopenharmony_ci};
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_cienum em28xx_led_role {
4528c2ecf20Sopenharmony_ci	EM28XX_LED_ANALOG_CAPTURING = 0,
4538c2ecf20Sopenharmony_ci	EM28XX_LED_DIGITAL_CAPTURING,
4548c2ecf20Sopenharmony_ci	EM28XX_LED_DIGITAL_CAPTURING_TS2,
4558c2ecf20Sopenharmony_ci	EM28XX_LED_ILLUMINATION,
4568c2ecf20Sopenharmony_ci	EM28XX_NUM_LED_ROLES, /* must be the last */
4578c2ecf20Sopenharmony_ci};
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_cistruct em28xx_led {
4608c2ecf20Sopenharmony_ci	enum em28xx_led_role role;
4618c2ecf20Sopenharmony_ci	u8 gpio_reg;
4628c2ecf20Sopenharmony_ci	u8 gpio_mask;
4638c2ecf20Sopenharmony_ci	bool inverted;
4648c2ecf20Sopenharmony_ci};
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_cienum em28xx_button_role {
4678c2ecf20Sopenharmony_ci	EM28XX_BUTTON_SNAPSHOT = 0,
4688c2ecf20Sopenharmony_ci	EM28XX_BUTTON_ILLUMINATION,
4698c2ecf20Sopenharmony_ci	EM28XX_NUM_BUTTON_ROLES, /* must be the last */
4708c2ecf20Sopenharmony_ci};
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_cistruct em28xx_button {
4738c2ecf20Sopenharmony_ci	enum em28xx_button_role role;
4748c2ecf20Sopenharmony_ci	u8 reg_r;
4758c2ecf20Sopenharmony_ci	u8 reg_clearing;
4768c2ecf20Sopenharmony_ci	u8 mask;
4778c2ecf20Sopenharmony_ci	bool inverted;
4788c2ecf20Sopenharmony_ci};
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_cistruct em28xx_board {
4818c2ecf20Sopenharmony_ci	char *name;
4828c2ecf20Sopenharmony_ci	int vchannels;
4838c2ecf20Sopenharmony_ci	int tuner_type;
4848c2ecf20Sopenharmony_ci	int tuner_addr;
4858c2ecf20Sopenharmony_ci	unsigned int def_i2c_bus;	/* Default I2C bus */
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci	/* i2c flags */
4888c2ecf20Sopenharmony_ci	unsigned int tda9887_conf;
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci	/* GPIO sequences */
4918c2ecf20Sopenharmony_ci	const struct em28xx_reg_seq *dvb_gpio;
4928c2ecf20Sopenharmony_ci	const struct em28xx_reg_seq *suspend_gpio;
4938c2ecf20Sopenharmony_ci	const struct em28xx_reg_seq *tuner_gpio;
4948c2ecf20Sopenharmony_ci	const struct em28xx_reg_seq *mute_gpio;
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	unsigned int is_em2800:1;
4978c2ecf20Sopenharmony_ci	unsigned int has_msp34xx:1;
4988c2ecf20Sopenharmony_ci	unsigned int mts_firmware:1;
4998c2ecf20Sopenharmony_ci	unsigned int max_range_640_480:1;
5008c2ecf20Sopenharmony_ci	unsigned int has_dvb:1;
5018c2ecf20Sopenharmony_ci	unsigned int has_dual_ts:1;
5028c2ecf20Sopenharmony_ci	unsigned int is_webcam:1;
5038c2ecf20Sopenharmony_ci	unsigned int valid:1;
5048c2ecf20Sopenharmony_ci	unsigned int has_ir_i2c:1;
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci	unsigned char xclk, i2c_speed;
5078c2ecf20Sopenharmony_ci	unsigned char radio_addr;
5088c2ecf20Sopenharmony_ci	unsigned short tvaudio_addr;
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	enum em28xx_decoder decoder;
5118c2ecf20Sopenharmony_ci	enum em28xx_adecoder adecoder;
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ci	struct em28xx_input       input[MAX_EM28XX_INPUT];
5148c2ecf20Sopenharmony_ci	struct em28xx_input	  radio;
5158c2ecf20Sopenharmony_ci	char			  *ir_codes;
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci	/* LEDs that need to be controlled explicitly */
5188c2ecf20Sopenharmony_ci	struct em28xx_led	  *leds;
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ci	/* Buttons */
5218c2ecf20Sopenharmony_ci	const struct em28xx_button *buttons;
5228c2ecf20Sopenharmony_ci};
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_cistruct em28xx_eeprom {
5258c2ecf20Sopenharmony_ci	u8 id[4];			/* 1a eb 67 95 */
5268c2ecf20Sopenharmony_ci	__le16 vendor_ID;
5278c2ecf20Sopenharmony_ci	__le16 product_ID;
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci	__le16 chip_conf;
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci	__le16 board_conf;
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci	__le16 string1, string2, string3;
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci	u8 string_idx_table;
5368c2ecf20Sopenharmony_ci};
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_ci#define EM28XX_CAPTURE_STREAM_EN 1
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci/* em28xx extensions */
5418c2ecf20Sopenharmony_ci#define EM28XX_AUDIO   0x10
5428c2ecf20Sopenharmony_ci#define EM28XX_DVB     0x20
5438c2ecf20Sopenharmony_ci#define EM28XX_RC      0x30
5448c2ecf20Sopenharmony_ci#define EM28XX_V4L2    0x40
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci/* em28xx resource types (used for res_get/res_lock etc */
5478c2ecf20Sopenharmony_ci#define EM28XX_RESOURCE_VIDEO 0x01
5488c2ecf20Sopenharmony_ci#define EM28XX_RESOURCE_VBI   0x02
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_cistruct em28xx_v4l2 {
5518c2ecf20Sopenharmony_ci	struct kref ref;
5528c2ecf20Sopenharmony_ci	struct em28xx *dev;
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	struct v4l2_device v4l2_dev;
5558c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler ctrl_handler;
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	struct video_device vdev;
5588c2ecf20Sopenharmony_ci	struct video_device vbi_dev;
5598c2ecf20Sopenharmony_ci	struct video_device radio_dev;
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci	/* Videobuf2 */
5628c2ecf20Sopenharmony_ci	struct vb2_queue vb_vidq;
5638c2ecf20Sopenharmony_ci	struct vb2_queue vb_vbiq;
5648c2ecf20Sopenharmony_ci	struct mutex vb_queue_lock;	/* Protects vb_vidq */
5658c2ecf20Sopenharmony_ci	struct mutex vb_vbi_queue_lock;	/* Protects vb_vbiq */
5668c2ecf20Sopenharmony_ci
5678c2ecf20Sopenharmony_ci	u8 vinmode;
5688c2ecf20Sopenharmony_ci	u8 vinctl;
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci	/* Camera specific fields */
5718c2ecf20Sopenharmony_ci	int sensor_xres;
5728c2ecf20Sopenharmony_ci	int sensor_yres;
5738c2ecf20Sopenharmony_ci	int sensor_xtal;
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci	int users;		/* user count for exclusive use */
5768c2ecf20Sopenharmony_ci	int streaming_users;    /* number of actively streaming users */
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_ci	u32 frequency;		/* selected tuner frequency */
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci	struct em28xx_fmt *format;
5818c2ecf20Sopenharmony_ci	v4l2_std_id norm;	/* selected tv norm */
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	/* Progressive/interlaced mode */
5848c2ecf20Sopenharmony_ci	bool progressive;
5858c2ecf20Sopenharmony_ci	int interlaced_fieldmode; /* 1=interlaced fields, 0=just top fields */
5868c2ecf20Sopenharmony_ci	/* FIXME: everything else than interlaced_fieldmode=1 doesn't work */
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ci	/* Frame properties */
5898c2ecf20Sopenharmony_ci	int width;		/* current frame width */
5908c2ecf20Sopenharmony_ci	int height;		/* current frame height */
5918c2ecf20Sopenharmony_ci	unsigned int hscale;	/* horizontal scale factor (see datasheet) */
5928c2ecf20Sopenharmony_ci	unsigned int vscale;	/* vertical scale factor (see datasheet) */
5938c2ecf20Sopenharmony_ci	unsigned int vbi_width;
5948c2ecf20Sopenharmony_ci	unsigned int vbi_height; /* lines per field */
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci	/* Capture state tracking */
5978c2ecf20Sopenharmony_ci	int capture_type;
5988c2ecf20Sopenharmony_ci	bool top_field;
5998c2ecf20Sopenharmony_ci	int vbi_read;
6008c2ecf20Sopenharmony_ci	unsigned int field_count;
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci#ifdef CONFIG_MEDIA_CONTROLLER
6038c2ecf20Sopenharmony_ci	struct media_pad video_pad, vbi_pad;
6048c2ecf20Sopenharmony_ci	struct media_entity *decoder;
6058c2ecf20Sopenharmony_ci#endif
6068c2ecf20Sopenharmony_ci};
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_cistruct em28xx_audio {
6098c2ecf20Sopenharmony_ci	char name[50];
6108c2ecf20Sopenharmony_ci	unsigned int num_urb;
6118c2ecf20Sopenharmony_ci	char **transfer_buffer;
6128c2ecf20Sopenharmony_ci	struct urb **urb;
6138c2ecf20Sopenharmony_ci	struct usb_device *udev;
6148c2ecf20Sopenharmony_ci	unsigned int capture_transfer_done;
6158c2ecf20Sopenharmony_ci	struct snd_pcm_substream   *capture_pcm_substream;
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	unsigned int hwptr_done_capture;
6188c2ecf20Sopenharmony_ci	struct snd_card            *sndcard;
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci	size_t period;
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_ci	int users;
6238c2ecf20Sopenharmony_ci	spinlock_t slock;		/* Protects struct em28xx_audio */
6248c2ecf20Sopenharmony_ci
6258c2ecf20Sopenharmony_ci	/* Controls streaming */
6268c2ecf20Sopenharmony_ci	struct work_struct wq_trigger;	/* trigger to start/stop audio */
6278c2ecf20Sopenharmony_ci	atomic_t       stream_started;	/* stream should be running if true */
6288c2ecf20Sopenharmony_ci};
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_cistruct em28xx;
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_cienum em28xx_i2c_algo_type {
6338c2ecf20Sopenharmony_ci	EM28XX_I2C_ALGO_EM28XX = 0,
6348c2ecf20Sopenharmony_ci	EM28XX_I2C_ALGO_EM2800,
6358c2ecf20Sopenharmony_ci	EM28XX_I2C_ALGO_EM25XX_BUS_B,
6368c2ecf20Sopenharmony_ci};
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_cistruct em28xx_i2c_bus {
6398c2ecf20Sopenharmony_ci	struct em28xx *dev;
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci	unsigned int bus;
6428c2ecf20Sopenharmony_ci	enum em28xx_i2c_algo_type algo_type;
6438c2ecf20Sopenharmony_ci};
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci/* main device struct */
6468c2ecf20Sopenharmony_cistruct em28xx {
6478c2ecf20Sopenharmony_ci	struct kref ref;
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	// Sub-module data
6508c2ecf20Sopenharmony_ci	struct em28xx_v4l2 *v4l2;
6518c2ecf20Sopenharmony_ci	struct em28xx_dvb *dvb;
6528c2ecf20Sopenharmony_ci	struct em28xx_audio adev;
6538c2ecf20Sopenharmony_ci	struct em28xx_IR *ir;
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci	// generic device properties
6568c2ecf20Sopenharmony_ci	int model;		// index in the device_data struct
6578c2ecf20Sopenharmony_ci	int devno;		// marks the number of this device
6588c2ecf20Sopenharmony_ci	enum em28xx_chip_id chip_id;
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci	unsigned int is_em25xx:1;	// em25xx/em276x/7x/8x family bridge
6618c2ecf20Sopenharmony_ci	unsigned int disconnected:1;	// device has been disconnected
6628c2ecf20Sopenharmony_ci	unsigned int has_video:1;
6638c2ecf20Sopenharmony_ci	unsigned int is_audio_only:1;
6648c2ecf20Sopenharmony_ci	unsigned int is_webcam:1;
6658c2ecf20Sopenharmony_ci	unsigned int has_msp34xx:1;
6668c2ecf20Sopenharmony_ci	unsigned int i2c_speed:2;
6678c2ecf20Sopenharmony_ci	enum em28xx_int_audio_type int_audio_type;
6688c2ecf20Sopenharmony_ci	enum em28xx_usb_audio_type usb_audio_type;
6698c2ecf20Sopenharmony_ci	unsigned char name[32];
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci	struct em28xx_board board;
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci	enum em28xx_sensor em28xx_sensor;	// camera specific
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci	// Some older em28xx chips needs a waiting time after writing
6768c2ecf20Sopenharmony_ci	unsigned int wait_after_write;
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	struct list_head	devlist;
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci	u32 i2s_speed;		// I2S speed for audio digital stream
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci	struct em28xx_audio_mode audio_mode;
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	int tuner_type;		// type of the tuner
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci	// i2c i/o
6878c2ecf20Sopenharmony_ci	struct i2c_adapter i2c_adap[NUM_I2C_BUSES];
6888c2ecf20Sopenharmony_ci	struct i2c_client i2c_client[NUM_I2C_BUSES];
6898c2ecf20Sopenharmony_ci	struct em28xx_i2c_bus i2c_bus[NUM_I2C_BUSES];
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	unsigned char eeprom_addrwidth_16bit:1;
6928c2ecf20Sopenharmony_ci	unsigned int def_i2c_bus;	// Default I2C bus
6938c2ecf20Sopenharmony_ci	unsigned int cur_i2c_bus;	// Current I2C bus
6948c2ecf20Sopenharmony_ci	struct rt_mutex i2c_bus_lock;
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	// video for linux
6978c2ecf20Sopenharmony_ci	unsigned int ctl_input;	// selected input
6988c2ecf20Sopenharmony_ci	unsigned int ctl_ainput;// selected audio input
6998c2ecf20Sopenharmony_ci	unsigned int ctl_aoutput;// selected audio output
7008c2ecf20Sopenharmony_ci	enum em28xx_amux amux_map[MAX_EM28XX_INPUT];
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci	int mute;
7038c2ecf20Sopenharmony_ci	int volume;
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_ci	unsigned long hash;	// eeprom hash - for boards with generic ID
7068c2ecf20Sopenharmony_ci	unsigned long i2c_hash;	// i2c devicelist hash -
7078c2ecf20Sopenharmony_ci				// for boards with generic ID
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci	struct work_struct         request_module_wk;
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci	// locks
7128c2ecf20Sopenharmony_ci	struct mutex lock;		/* protects em28xx struct */
7138c2ecf20Sopenharmony_ci	struct mutex ctrl_urb_lock;	/* protects urb_buf */
7148c2ecf20Sopenharmony_ci
7158c2ecf20Sopenharmony_ci	// resources in use
7168c2ecf20Sopenharmony_ci	unsigned int resources;
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci	// eeprom content
7198c2ecf20Sopenharmony_ci	u8 *eedata;
7208c2ecf20Sopenharmony_ci	u16 eedata_len;
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	// Isoc control struct
7238c2ecf20Sopenharmony_ci	struct em28xx_dmaqueue vidq;
7248c2ecf20Sopenharmony_ci	struct em28xx_dmaqueue vbiq;
7258c2ecf20Sopenharmony_ci	struct em28xx_usb_ctl usb_ctl;
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci	spinlock_t slock; /* Protects em28xx video/vbi/dvb IRQ stream data */
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci	// usb transfer
7308c2ecf20Sopenharmony_ci	struct usb_interface *intf;	// the usb interface
7318c2ecf20Sopenharmony_ci	u8 ifnum;		// number of the assigned usb interface
7328c2ecf20Sopenharmony_ci	u8 analog_ep_isoc;	// address of isoc endpoint for analog
7338c2ecf20Sopenharmony_ci	u8 analog_ep_bulk;	// address of bulk endpoint for analog
7348c2ecf20Sopenharmony_ci	u8 dvb_ep_isoc_ts2;	// address of isoc endpoint for DVB TS2
7358c2ecf20Sopenharmony_ci	u8 dvb_ep_bulk_ts2;	// address of bulk endpoint for DVB TS2
7368c2ecf20Sopenharmony_ci	u8 dvb_ep_isoc;		// address of isoc endpoint for DVB
7378c2ecf20Sopenharmony_ci	u8 dvb_ep_bulk;		// address of bulk endpoint for DVB
7388c2ecf20Sopenharmony_ci	int alt;		// alternate setting
7398c2ecf20Sopenharmony_ci	int max_pkt_size;	// max packet size of the selected ep at alt
7408c2ecf20Sopenharmony_ci	int packet_multiplier;	// multiplier for wMaxPacketSize, used for
7418c2ecf20Sopenharmony_ci				// URB buffer size definition
7428c2ecf20Sopenharmony_ci	int num_alt;		// number of alternative settings
7438c2ecf20Sopenharmony_ci	unsigned int *alt_max_pkt_size_isoc; // array of isoc wMaxPacketSize
7448c2ecf20Sopenharmony_ci	unsigned int analog_xfer_bulk:1;	// use bulk instead of isoc
7458c2ecf20Sopenharmony_ci						// transfers for analog
7468c2ecf20Sopenharmony_ci	int dvb_alt_isoc;	// alternate setting for DVB isoc transfers
7478c2ecf20Sopenharmony_ci	unsigned int dvb_max_pkt_size_isoc;	// isoc max packet size of the
7488c2ecf20Sopenharmony_ci						// selected DVB ep at dvb_alt
7498c2ecf20Sopenharmony_ci	unsigned int dvb_max_pkt_size_isoc_ts2;	// isoc max packet size of the
7508c2ecf20Sopenharmony_ci						// selected DVB ep at dvb_alt
7518c2ecf20Sopenharmony_ci	unsigned int dvb_xfer_bulk:1;		// use bulk instead of isoc
7528c2ecf20Sopenharmony_ci						// transfers for DVB
7538c2ecf20Sopenharmony_ci	char urb_buf[URB_MAX_CTRL_SIZE];	// urb control msg buffer
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci	// helper funcs that call usb_control_msg
7568c2ecf20Sopenharmony_ci	int (*em28xx_write_regs)(struct em28xx *dev, u16 reg,
7578c2ecf20Sopenharmony_ci				 char *buf, int len);
7588c2ecf20Sopenharmony_ci	int (*em28xx_read_reg)(struct em28xx *dev, u16 reg);
7598c2ecf20Sopenharmony_ci	int (*em28xx_read_reg_req_len)(struct em28xx *dev, u8 req, u16 reg,
7608c2ecf20Sopenharmony_ci				       char *buf, int len);
7618c2ecf20Sopenharmony_ci	int (*em28xx_write_regs_req)(struct em28xx *dev, u8 req, u16 reg,
7628c2ecf20Sopenharmony_ci				     char *buf, int len);
7638c2ecf20Sopenharmony_ci	int (*em28xx_read_reg_req)(struct em28xx *dev, u8 req, u16 reg);
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_ci	enum em28xx_mode mode;
7668c2ecf20Sopenharmony_ci
7678c2ecf20Sopenharmony_ci	// Button state polling
7688c2ecf20Sopenharmony_ci	struct delayed_work buttons_query_work;
7698c2ecf20Sopenharmony_ci	u8 button_polling_addresses[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
7708c2ecf20Sopenharmony_ci	u8 button_polling_last_values[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
7718c2ecf20Sopenharmony_ci	u8 num_button_polling_addresses;
7728c2ecf20Sopenharmony_ci	u16 button_polling_interval; // [ms]
7738c2ecf20Sopenharmony_ci	// Snapshot button input device
7748c2ecf20Sopenharmony_ci	char snapshot_button_path[30];	// path of the input dev
7758c2ecf20Sopenharmony_ci	struct input_dev *sbutton_input_dev;
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci#ifdef CONFIG_MEDIA_CONTROLLER
7788c2ecf20Sopenharmony_ci	struct media_device *media_dev;
7798c2ecf20Sopenharmony_ci	struct media_entity input_ent[MAX_EM28XX_INPUT];
7808c2ecf20Sopenharmony_ci	struct media_pad input_pad[MAX_EM28XX_INPUT];
7818c2ecf20Sopenharmony_ci#endif
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	struct em28xx	*dev_next;
7848c2ecf20Sopenharmony_ci	int ts;
7858c2ecf20Sopenharmony_ci};
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci#define kref_to_dev(d) container_of(d, struct em28xx, ref)
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_cistruct em28xx_ops {
7908c2ecf20Sopenharmony_ci	struct list_head next;
7918c2ecf20Sopenharmony_ci	char *name;
7928c2ecf20Sopenharmony_ci	int id;
7938c2ecf20Sopenharmony_ci	int (*init)(struct em28xx *dev);
7948c2ecf20Sopenharmony_ci	int (*fini)(struct em28xx *dev);
7958c2ecf20Sopenharmony_ci	int (*suspend)(struct em28xx *dev);
7968c2ecf20Sopenharmony_ci	int (*resume)(struct em28xx *dev);
7978c2ecf20Sopenharmony_ci};
7988c2ecf20Sopenharmony_ci
7998c2ecf20Sopenharmony_ci/* Provided by em28xx-i2c.c */
8008c2ecf20Sopenharmony_civoid em28xx_do_i2c_scan(struct em28xx *dev, unsigned int bus);
8018c2ecf20Sopenharmony_ciint  em28xx_i2c_register(struct em28xx *dev, unsigned int bus,
8028c2ecf20Sopenharmony_ci			 enum em28xx_i2c_algo_type algo_type);
8038c2ecf20Sopenharmony_ciint  em28xx_i2c_unregister(struct em28xx *dev, unsigned int bus);
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci/* Provided by em28xx-core.c */
8068c2ecf20Sopenharmony_ciint em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
8078c2ecf20Sopenharmony_ci			    char *buf, int len);
8088c2ecf20Sopenharmony_ciint em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);
8098c2ecf20Sopenharmony_ciint em28xx_read_reg(struct em28xx *dev, u16 reg);
8108c2ecf20Sopenharmony_ciint em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
8118c2ecf20Sopenharmony_ci			  int len);
8128c2ecf20Sopenharmony_ciint em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);
8138c2ecf20Sopenharmony_ciint em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val);
8148c2ecf20Sopenharmony_ciint em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
8158c2ecf20Sopenharmony_ci			  u8 bitmask);
8168c2ecf20Sopenharmony_ciint em28xx_toggle_reg_bits(struct em28xx *dev, u16 reg, u8 bitmask);
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ciint em28xx_read_ac97(struct em28xx *dev, u8 reg);
8198c2ecf20Sopenharmony_ciint em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val);
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ciint em28xx_audio_analog_set(struct em28xx *dev);
8228c2ecf20Sopenharmony_ciint em28xx_audio_setup(struct em28xx *dev);
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ciconst struct em28xx_led *em28xx_find_led(struct em28xx *dev,
8258c2ecf20Sopenharmony_ci					 enum em28xx_led_role role);
8268c2ecf20Sopenharmony_ciint em28xx_capture_start(struct em28xx *dev, int start);
8278c2ecf20Sopenharmony_ciint em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
8288c2ecf20Sopenharmony_ci		      int num_bufs, int max_pkt_size, int packet_multiplier);
8298c2ecf20Sopenharmony_ciint em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
8308c2ecf20Sopenharmony_ci			 int xfer_bulk,
8318c2ecf20Sopenharmony_ci			 int num_bufs, int max_pkt_size, int packet_multiplier,
8328c2ecf20Sopenharmony_ci			 int (*urb_data_copy)
8338c2ecf20Sopenharmony_ci					(struct em28xx *dev, struct urb *urb));
8348c2ecf20Sopenharmony_civoid em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
8358c2ecf20Sopenharmony_civoid em28xx_stop_urbs(struct em28xx *dev);
8368c2ecf20Sopenharmony_ciint em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
8378c2ecf20Sopenharmony_ciint em28xx_gpio_set(struct em28xx *dev, const struct em28xx_reg_seq *gpio);
8388c2ecf20Sopenharmony_ciint em28xx_register_extension(struct em28xx_ops *dev);
8398c2ecf20Sopenharmony_civoid em28xx_unregister_extension(struct em28xx_ops *dev);
8408c2ecf20Sopenharmony_civoid em28xx_init_extension(struct em28xx *dev);
8418c2ecf20Sopenharmony_civoid em28xx_close_extension(struct em28xx *dev);
8428c2ecf20Sopenharmony_ciint em28xx_suspend_extension(struct em28xx *dev);
8438c2ecf20Sopenharmony_ciint em28xx_resume_extension(struct em28xx *dev);
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci/* Provided by em28xx-cards.c */
8468c2ecf20Sopenharmony_ciextern const struct em28xx_board em28xx_boards[];
8478c2ecf20Sopenharmony_ciextern struct usb_device_id em28xx_id_table[];
8488c2ecf20Sopenharmony_ciint em28xx_tuner_callback(void *ptr, int component, int command, int arg);
8498c2ecf20Sopenharmony_civoid em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl);
8508c2ecf20Sopenharmony_civoid em28xx_free_device(struct kref *ref);
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci/* Provided by em28xx-camera.c */
8538c2ecf20Sopenharmony_ciint em28xx_detect_sensor(struct em28xx *dev);
8548c2ecf20Sopenharmony_ciint em28xx_init_camera(struct em28xx *dev);
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_ci#endif
857