18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * ngene.h: nGene PCIe bridge driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2005-2007 Micronas
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _NGENE_H_
98c2ecf20Sopenharmony_ci#define _NGENE_H_
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/types.h>
128c2ecf20Sopenharmony_ci#include <linux/sched.h>
138c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
148c2ecf20Sopenharmony_ci#include <linux/i2c.h>
158c2ecf20Sopenharmony_ci#include <asm/dma.h>
168c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/dvb/frontend.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <media/dmxdev.h>
218c2ecf20Sopenharmony_ci#include <media/dvbdev.h>
228c2ecf20Sopenharmony_ci#include <media/dvb_demux.h>
238c2ecf20Sopenharmony_ci#include <media/dvb_ca_en50221.h>
248c2ecf20Sopenharmony_ci#include <media/dvb_frontend.h>
258c2ecf20Sopenharmony_ci#include <media/dvb_ringbuffer.h>
268c2ecf20Sopenharmony_ci#include <media/dvb_net.h>
278c2ecf20Sopenharmony_ci#include "cxd2099.h"
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define DEVICE_NAME "ngene"
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define NGENE_VID       0x18c3
328c2ecf20Sopenharmony_ci#define NGENE_PID       0x0720
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#ifndef VIDEO_CAP_VC1
358c2ecf20Sopenharmony_ci#define VIDEO_CAP_AVC   128
368c2ecf20Sopenharmony_ci#define VIDEO_CAP_H264  128
378c2ecf20Sopenharmony_ci#define VIDEO_CAP_VC1   256
388c2ecf20Sopenharmony_ci#define VIDEO_CAP_WMV9  256
398c2ecf20Sopenharmony_ci#define VIDEO_CAP_MPEG4 512
408c2ecf20Sopenharmony_ci#endif
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define DEMOD_TYPE_STV090X	0
438c2ecf20Sopenharmony_ci#define DEMOD_TYPE_DRXK		1
448c2ecf20Sopenharmony_ci#define DEMOD_TYPE_STV0367	2
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define DEMOD_TYPE_XO2		32
478c2ecf20Sopenharmony_ci#define DEMOD_TYPE_STV0910	(DEMOD_TYPE_XO2 + 0)
488c2ecf20Sopenharmony_ci#define DEMOD_TYPE_SONY_CT2	(DEMOD_TYPE_XO2 + 1)
498c2ecf20Sopenharmony_ci#define DEMOD_TYPE_SONY_ISDBT	(DEMOD_TYPE_XO2 + 2)
508c2ecf20Sopenharmony_ci#define DEMOD_TYPE_SONY_C2T2	(DEMOD_TYPE_XO2 + 3)
518c2ecf20Sopenharmony_ci#define DEMOD_TYPE_ST_ATSC	(DEMOD_TYPE_XO2 + 4)
528c2ecf20Sopenharmony_ci#define DEMOD_TYPE_SONY_C2T2I	(DEMOD_TYPE_XO2 + 5)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define NGENE_XO2_TYPE_NONE	0
558c2ecf20Sopenharmony_ci#define NGENE_XO2_TYPE_DUOFLEX	1
568c2ecf20Sopenharmony_ci#define NGENE_XO2_TYPE_CI	2
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cienum STREAM {
598c2ecf20Sopenharmony_ci	STREAM_VIDEOIN1 = 0,        /* ITU656 or TS Input */
608c2ecf20Sopenharmony_ci	STREAM_VIDEOIN2,
618c2ecf20Sopenharmony_ci	STREAM_AUDIOIN1,            /* I2S or SPI Input */
628c2ecf20Sopenharmony_ci	STREAM_AUDIOIN2,
638c2ecf20Sopenharmony_ci	STREAM_AUDIOOUT,
648c2ecf20Sopenharmony_ci	MAX_STREAM
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cienum SMODE_BITS {
688c2ecf20Sopenharmony_ci	SMODE_AUDIO_SPDIF = 0x20,
698c2ecf20Sopenharmony_ci	SMODE_AVSYNC = 0x10,
708c2ecf20Sopenharmony_ci	SMODE_TRANSPORT_STREAM = 0x08,
718c2ecf20Sopenharmony_ci	SMODE_AUDIO_CAPTURE = 0x04,
728c2ecf20Sopenharmony_ci	SMODE_VBI_CAPTURE = 0x02,
738c2ecf20Sopenharmony_ci	SMODE_VIDEO_CAPTURE = 0x01
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cienum STREAM_FLAG_BITS {
778c2ecf20Sopenharmony_ci	SFLAG_CHROMA_FORMAT_2COMP  = 0x01, /* Chroma Format : 2's complement */
788c2ecf20Sopenharmony_ci	SFLAG_CHROMA_FORMAT_OFFSET = 0x00, /* Chroma Format : Binary offset */
798c2ecf20Sopenharmony_ci	SFLAG_ORDER_LUMA_CHROMA    = 0x02, /* Byte order: Y,Cb,Y,Cr */
808c2ecf20Sopenharmony_ci	SFLAG_ORDER_CHROMA_LUMA    = 0x00, /* Byte order: Cb,Y,Cr,Y */
818c2ecf20Sopenharmony_ci	SFLAG_COLORBAR             = 0x04, /* Select colorbar */
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define PROGRAM_ROM     0x0000
858c2ecf20Sopenharmony_ci#define PROGRAM_SRAM    0x1000
868c2ecf20Sopenharmony_ci#define PERIPHERALS0    0x8000
878c2ecf20Sopenharmony_ci#define PERIPHERALS1    0x9000
888c2ecf20Sopenharmony_ci#define SHARED_BUFFER   0xC000
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define HOST_TO_NGENE    (SHARED_BUFFER+0x0000)
918c2ecf20Sopenharmony_ci#define NGENE_TO_HOST    (SHARED_BUFFER+0x0100)
928c2ecf20Sopenharmony_ci#define NGENE_COMMAND    (SHARED_BUFFER+0x0200)
938c2ecf20Sopenharmony_ci#define NGENE_COMMAND_HI (SHARED_BUFFER+0x0204)
948c2ecf20Sopenharmony_ci#define NGENE_STATUS     (SHARED_BUFFER+0x0208)
958c2ecf20Sopenharmony_ci#define NGENE_STATUS_HI  (SHARED_BUFFER+0x020C)
968c2ecf20Sopenharmony_ci#define NGENE_EVENT      (SHARED_BUFFER+0x0210)
978c2ecf20Sopenharmony_ci#define NGENE_EVENT_HI   (SHARED_BUFFER+0x0214)
988c2ecf20Sopenharmony_ci#define VARIABLES        (SHARED_BUFFER+0x0210)
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define NGENE_INT_COUNTS       (SHARED_BUFFER+0x0260)
1018c2ecf20Sopenharmony_ci#define NGENE_INT_ENABLE       (SHARED_BUFFER+0x0264)
1028c2ecf20Sopenharmony_ci#define NGENE_VBI_LINE_COUNT   (SHARED_BUFFER+0x0268)
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define BUFFER_GP_XMIT  (SHARED_BUFFER+0x0800)
1058c2ecf20Sopenharmony_ci#define BUFFER_GP_RECV  (SHARED_BUFFER+0x0900)
1068c2ecf20Sopenharmony_ci#define EEPROM_AREA     (SHARED_BUFFER+0x0A00)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define SG_V_IN_1       (SHARED_BUFFER+0x0A80)
1098c2ecf20Sopenharmony_ci#define SG_VBI_1        (SHARED_BUFFER+0x0B00)
1108c2ecf20Sopenharmony_ci#define SG_A_IN_1       (SHARED_BUFFER+0x0B80)
1118c2ecf20Sopenharmony_ci#define SG_V_IN_2       (SHARED_BUFFER+0x0C00)
1128c2ecf20Sopenharmony_ci#define SG_VBI_2        (SHARED_BUFFER+0x0C80)
1138c2ecf20Sopenharmony_ci#define SG_A_IN_2       (SHARED_BUFFER+0x0D00)
1148c2ecf20Sopenharmony_ci#define SG_V_OUT        (SHARED_BUFFER+0x0D80)
1158c2ecf20Sopenharmony_ci#define SG_A_OUT2       (SHARED_BUFFER+0x0E00)
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define DATA_A_IN_1     (SHARED_BUFFER+0x0E80)
1188c2ecf20Sopenharmony_ci#define DATA_A_IN_2     (SHARED_BUFFER+0x0F00)
1198c2ecf20Sopenharmony_ci#define DATA_A_OUT      (SHARED_BUFFER+0x0F80)
1208c2ecf20Sopenharmony_ci#define DATA_V_IN_1     (SHARED_BUFFER+0x1000)
1218c2ecf20Sopenharmony_ci#define DATA_V_IN_2     (SHARED_BUFFER+0x2000)
1228c2ecf20Sopenharmony_ci#define DATA_V_OUT      (SHARED_BUFFER+0x3000)
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci#define DATA_FIFO_AREA  (SHARED_BUFFER+0x1000)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define TIMESTAMPS      0xA000
1278c2ecf20Sopenharmony_ci#define SCRATCHPAD      0xA080
1288c2ecf20Sopenharmony_ci#define FORCE_INT       0xA088
1298c2ecf20Sopenharmony_ci#define FORCE_NMI       0xA090
1308c2ecf20Sopenharmony_ci#define INT_STATUS      0xA0A0
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci#define DEV_VER         0x9004
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#define FW_DEBUG_DEFAULT (PROGRAM_SRAM+0x00FF)
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistruct SG_ADDR {
1378c2ecf20Sopenharmony_ci	u64 start;
1388c2ecf20Sopenharmony_ci	u64 curr;
1398c2ecf20Sopenharmony_ci	u16 curr_ptr;
1408c2ecf20Sopenharmony_ci	u16 elements;
1418c2ecf20Sopenharmony_ci	u32 pad[3];
1428c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistruct SHARED_MEMORY {
1458c2ecf20Sopenharmony_ci	/* C000 */
1468c2ecf20Sopenharmony_ci	u32 HostToNgene[64];
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	/* C100 */
1498c2ecf20Sopenharmony_ci	u32 NgeneToHost[64];
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	/* C200 */
1528c2ecf20Sopenharmony_ci	u64 NgeneCommand;
1538c2ecf20Sopenharmony_ci	u64 NgeneStatus;
1548c2ecf20Sopenharmony_ci	u64 NgeneEvent;
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	/* C210 */
1578c2ecf20Sopenharmony_ci	u8 pad1[0xc260 - 0xc218];
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	/* C260 */
1608c2ecf20Sopenharmony_ci	u32 IntCounts;
1618c2ecf20Sopenharmony_ci	u32 IntEnable;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	/* C268 */
1648c2ecf20Sopenharmony_ci	u8 pad2[0xd000 - 0xc268];
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cistruct BUFFER_STREAM_RESULTS {
1698c2ecf20Sopenharmony_ci	u32 Clock;           /* Stream time in 100ns units */
1708c2ecf20Sopenharmony_ci	u16 RemainingLines;  /* Remaining lines in this field.
1718c2ecf20Sopenharmony_ci				0 for complete field */
1728c2ecf20Sopenharmony_ci	u8  FieldCount;      /* Video field number */
1738c2ecf20Sopenharmony_ci	u8  Flags;           /* Bit 7 = Done, Bit 6 = seen, Bit 5 = overflow,
1748c2ecf20Sopenharmony_ci				Bit 0 = FieldID */
1758c2ecf20Sopenharmony_ci	u16 BlockCount;      /* Audio block count (unused) */
1768c2ecf20Sopenharmony_ci	u8  Reserved[2];
1778c2ecf20Sopenharmony_ci	u32 DTOUpdate;
1788c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistruct HW_SCATTER_GATHER_ELEMENT {
1818c2ecf20Sopenharmony_ci	u64 Address;
1828c2ecf20Sopenharmony_ci	u32 Length;
1838c2ecf20Sopenharmony_ci	u32 Reserved;
1848c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistruct BUFFER_HEADER {
1878c2ecf20Sopenharmony_ci	u64    Next;
1888c2ecf20Sopenharmony_ci	struct BUFFER_STREAM_RESULTS SR;
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	u32    Number_of_entries_1;
1918c2ecf20Sopenharmony_ci	u32    Reserved5;
1928c2ecf20Sopenharmony_ci	u64    Address_of_first_entry_1;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	u32    Number_of_entries_2;
1958c2ecf20Sopenharmony_ci	u32    Reserved7;
1968c2ecf20Sopenharmony_ci	u64    Address_of_first_entry_2;
1978c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistruct EVENT_BUFFER {
2008c2ecf20Sopenharmony_ci	u32    TimeStamp;
2018c2ecf20Sopenharmony_ci	u8     GPIOStatus;
2028c2ecf20Sopenharmony_ci	u8     UARTStatus;
2038c2ecf20Sopenharmony_ci	u8     RXCharacter;
2048c2ecf20Sopenharmony_ci	u8     EventStatus;
2058c2ecf20Sopenharmony_ci	u32    Reserved[2];
2068c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/* Firmware commands. */
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_cienum OPCODES {
2118c2ecf20Sopenharmony_ci	CMD_NOP = 0,
2128c2ecf20Sopenharmony_ci	CMD_FWLOAD_PREPARE  = 0x01,
2138c2ecf20Sopenharmony_ci	CMD_FWLOAD_FINISH   = 0x02,
2148c2ecf20Sopenharmony_ci	CMD_I2C_READ        = 0x03,
2158c2ecf20Sopenharmony_ci	CMD_I2C_WRITE       = 0x04,
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	CMD_I2C_WRITE_NOSTOP = 0x05,
2188c2ecf20Sopenharmony_ci	CMD_I2C_CONTINUE_WRITE = 0x06,
2198c2ecf20Sopenharmony_ci	CMD_I2C_CONTINUE_WRITE_NOSTOP = 0x07,
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	CMD_DEBUG_OUTPUT    = 0x09,
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	CMD_CONTROL         = 0x10,
2248c2ecf20Sopenharmony_ci	CMD_CONFIGURE_BUFFER = 0x11,
2258c2ecf20Sopenharmony_ci	CMD_CONFIGURE_FREE_BUFFER = 0x12,
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	CMD_SPI_READ        = 0x13,
2288c2ecf20Sopenharmony_ci	CMD_SPI_WRITE       = 0x14,
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	CMD_MEM_READ        = 0x20,
2318c2ecf20Sopenharmony_ci	CMD_MEM_WRITE	    = 0x21,
2328c2ecf20Sopenharmony_ci	CMD_SFR_READ	    = 0x22,
2338c2ecf20Sopenharmony_ci	CMD_SFR_WRITE	    = 0x23,
2348c2ecf20Sopenharmony_ci	CMD_IRAM_READ	    = 0x24,
2358c2ecf20Sopenharmony_ci	CMD_IRAM_WRITE	    = 0x25,
2368c2ecf20Sopenharmony_ci	CMD_SET_GPIO_PIN    = 0x26,
2378c2ecf20Sopenharmony_ci	CMD_SET_GPIO_INT    = 0x27,
2388c2ecf20Sopenharmony_ci	CMD_CONFIGURE_UART  = 0x28,
2398c2ecf20Sopenharmony_ci	CMD_WRITE_UART      = 0x29,
2408c2ecf20Sopenharmony_ci	MAX_CMD
2418c2ecf20Sopenharmony_ci};
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cienum RESPONSES {
2448c2ecf20Sopenharmony_ci	OK = 0,
2458c2ecf20Sopenharmony_ci	ERROR = 1
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistruct FW_HEADER {
2498c2ecf20Sopenharmony_ci	u8 Opcode;
2508c2ecf20Sopenharmony_ci	u8 Length;
2518c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_cistruct FW_I2C_WRITE {
2548c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
2558c2ecf20Sopenharmony_ci	u8 Device;
2568c2ecf20Sopenharmony_ci	u8 Data[250];
2578c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistruct FW_I2C_CONTINUE_WRITE {
2608c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
2618c2ecf20Sopenharmony_ci	u8 Data[250];
2628c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_cistruct FW_I2C_READ {
2658c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
2668c2ecf20Sopenharmony_ci	u8 Device;
2678c2ecf20Sopenharmony_ci	u8 Data[252];    /* followed by two bytes of read data count */
2688c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistruct FW_SPI_WRITE {
2718c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
2728c2ecf20Sopenharmony_ci	u8 ModeSelect;
2738c2ecf20Sopenharmony_ci	u8 Data[250];
2748c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_cistruct FW_SPI_READ {
2778c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
2788c2ecf20Sopenharmony_ci	u8 ModeSelect;
2798c2ecf20Sopenharmony_ci	u8 Data[252];    /* followed by two bytes of read data count */
2808c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_cistruct FW_FWLOAD_PREPARE {
2838c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
2848c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_cistruct FW_FWLOAD_FINISH {
2878c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
2888c2ecf20Sopenharmony_ci	u16 Address;     /* address of final block */
2898c2ecf20Sopenharmony_ci	u16 Length;
2908c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci/*
2938c2ecf20Sopenharmony_ci * Meaning of FW_STREAM_CONTROL::Mode bits:
2948c2ecf20Sopenharmony_ci *  Bit 7: Loopback PEXin to PEXout using TVOut channel
2958c2ecf20Sopenharmony_ci *  Bit 6: AVLOOP
2968c2ecf20Sopenharmony_ci *  Bit 5: Audio select; 0=I2S, 1=SPDIF
2978c2ecf20Sopenharmony_ci *  Bit 4: AVSYNC
2988c2ecf20Sopenharmony_ci *  Bit 3: Enable transport stream
2998c2ecf20Sopenharmony_ci *  Bit 2: Enable audio capture
3008c2ecf20Sopenharmony_ci *  Bit 1: Enable ITU-Video VBI capture
3018c2ecf20Sopenharmony_ci *  Bit 0: Enable ITU-Video capture
3028c2ecf20Sopenharmony_ci *
3038c2ecf20Sopenharmony_ci * Meaning of FW_STREAM_CONTROL::Control bits (see UVI1_CTL)
3048c2ecf20Sopenharmony_ci *  Bit 7: continuous capture
3058c2ecf20Sopenharmony_ci *  Bit 6: capture one field
3068c2ecf20Sopenharmony_ci *  Bit 5: capture one frame
3078c2ecf20Sopenharmony_ci *  Bit 4: unused
3088c2ecf20Sopenharmony_ci *  Bit 3: starting field; 0=odd, 1=even
3098c2ecf20Sopenharmony_ci *  Bit 2: sample size; 0=8-bit, 1=10-bit
3108c2ecf20Sopenharmony_ci *  Bit 1: data format; 0=UYVY, 1=YUY2
3118c2ecf20Sopenharmony_ci *  Bit 0: resets buffer pointers
3128c2ecf20Sopenharmony_ci*/
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cienum FSC_MODE_BITS {
3158c2ecf20Sopenharmony_ci	SMODE_LOOPBACK          = 0x80,
3168c2ecf20Sopenharmony_ci	SMODE_AVLOOP            = 0x40,
3178c2ecf20Sopenharmony_ci	_SMODE_AUDIO_SPDIF      = 0x20,
3188c2ecf20Sopenharmony_ci	_SMODE_AVSYNC           = 0x10,
3198c2ecf20Sopenharmony_ci	_SMODE_TRANSPORT_STREAM = 0x08,
3208c2ecf20Sopenharmony_ci	_SMODE_AUDIO_CAPTURE    = 0x04,
3218c2ecf20Sopenharmony_ci	_SMODE_VBI_CAPTURE      = 0x02,
3228c2ecf20Sopenharmony_ci	_SMODE_VIDEO_CAPTURE    = 0x01
3238c2ecf20Sopenharmony_ci};
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci/* Meaning of FW_STREAM_CONTROL::Stream bits:
3278c2ecf20Sopenharmony_ci * Bit 3: Audio sample count:  0 = relative, 1 = absolute
3288c2ecf20Sopenharmony_ci * Bit 2: color bar select; 1=color bars, 0=CV3 decoder
3298c2ecf20Sopenharmony_ci * Bits 1-0: stream select, UVI1, UVI2, TVOUT
3308c2ecf20Sopenharmony_ci */
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_cistruct FW_STREAM_CONTROL {
3338c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3348c2ecf20Sopenharmony_ci	u8     Stream;             /* Stream number (UVI1, UVI2, TVOUT) */
3358c2ecf20Sopenharmony_ci	u8     Control;            /* Value written to UVI1_CTL */
3368c2ecf20Sopenharmony_ci	u8     Mode;               /* Controls clock source */
3378c2ecf20Sopenharmony_ci	u8     SetupDataLen;	   /* Length of setup data, MSB=1 write
3388c2ecf20Sopenharmony_ci				      backwards */
3398c2ecf20Sopenharmony_ci	u16    CaptureBlockCount;  /* Blocks (a 256 Bytes) to capture per buffer
3408c2ecf20Sopenharmony_ci				      for TS and Audio */
3418c2ecf20Sopenharmony_ci	u64    Buffer_Address;	   /* Address of first buffer header */
3428c2ecf20Sopenharmony_ci	u16    BytesPerVideoLine;
3438c2ecf20Sopenharmony_ci	u16    MaxLinesPerField;
3448c2ecf20Sopenharmony_ci	u16    MinLinesPerField;
3458c2ecf20Sopenharmony_ci	u16    Reserved_1;
3468c2ecf20Sopenharmony_ci	u16    BytesPerVBILine;
3478c2ecf20Sopenharmony_ci	u16    MaxVBILinesPerField;
3488c2ecf20Sopenharmony_ci	u16    MinVBILinesPerField;
3498c2ecf20Sopenharmony_ci	u16    SetupDataAddr;      /* ngene relative address of setup data */
3508c2ecf20Sopenharmony_ci	u8     SetupData[32];      /* setup data */
3518c2ecf20Sopenharmony_ci} __attribute__((__packed__));
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci#define AUDIO_BLOCK_SIZE    256
3548c2ecf20Sopenharmony_ci#define TS_BLOCK_SIZE       256
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_cistruct FW_MEM_READ {
3578c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3588c2ecf20Sopenharmony_ci	u16   address;
3598c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_cistruct FW_MEM_WRITE {
3628c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3638c2ecf20Sopenharmony_ci	u16   address;
3648c2ecf20Sopenharmony_ci	u8    data;
3658c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_cistruct FW_SFR_IRAM_READ {
3688c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3698c2ecf20Sopenharmony_ci	u8    address;
3708c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_cistruct FW_SFR_IRAM_WRITE {
3738c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3748c2ecf20Sopenharmony_ci	u8    address;
3758c2ecf20Sopenharmony_ci	u8    data;
3768c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_cistruct FW_SET_GPIO_PIN {
3798c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3808c2ecf20Sopenharmony_ci	u8    select;
3818c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_cistruct FW_SET_GPIO_INT {
3848c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3858c2ecf20Sopenharmony_ci	u8    select;
3868c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_cistruct FW_SET_DEBUGMODE {
3898c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3908c2ecf20Sopenharmony_ci	u8   debug_flags;
3918c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_cistruct FW_CONFIGURE_BUFFERS {
3948c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
3958c2ecf20Sopenharmony_ci	u8   config;
3968c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_cienum _BUFFER_CONFIGS {
3998c2ecf20Sopenharmony_ci	/* 4k UVI1, 4k UVI2, 2k AUD1, 2k AUD2  (standard usage) */
4008c2ecf20Sopenharmony_ci	BUFFER_CONFIG_4422 = 0,
4018c2ecf20Sopenharmony_ci	/* 3k UVI1, 3k UVI2, 3k AUD1, 3k AUD2  (4x TS input usage) */
4028c2ecf20Sopenharmony_ci	BUFFER_CONFIG_3333 = 1,
4038c2ecf20Sopenharmony_ci	/* 8k UVI1, 0k UVI2, 2k AUD1, 2k I2SOut  (HDTV decoder usage) */
4048c2ecf20Sopenharmony_ci	BUFFER_CONFIG_8022 = 2,
4058c2ecf20Sopenharmony_ci	BUFFER_CONFIG_FW17 = 255, /* Use new FW 17 command */
4068c2ecf20Sopenharmony_ci};
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistruct FW_CONFIGURE_FREE_BUFFERS {
4098c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
4108c2ecf20Sopenharmony_ci	struct {
4118c2ecf20Sopenharmony_ci		u8   UVI1_BufferLength;
4128c2ecf20Sopenharmony_ci		u8   UVI2_BufferLength;
4138c2ecf20Sopenharmony_ci		u8   TVO_BufferLength;
4148c2ecf20Sopenharmony_ci		u8   AUD1_BufferLength;
4158c2ecf20Sopenharmony_ci		u8   AUD2_BufferLength;
4168c2ecf20Sopenharmony_ci		u8   TVA_BufferLength;
4178c2ecf20Sopenharmony_ci	} __packed config;
4188c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_cistruct FW_CONFIGURE_UART {
4218c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
4228c2ecf20Sopenharmony_ci	u8 UartControl;
4238c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cienum _UART_CONFIG {
4268c2ecf20Sopenharmony_ci	_UART_BAUDRATE_19200 = 0,
4278c2ecf20Sopenharmony_ci	_UART_BAUDRATE_9600  = 1,
4288c2ecf20Sopenharmony_ci	_UART_BAUDRATE_4800  = 2,
4298c2ecf20Sopenharmony_ci	_UART_BAUDRATE_2400  = 3,
4308c2ecf20Sopenharmony_ci	_UART_RX_ENABLE      = 0x40,
4318c2ecf20Sopenharmony_ci	_UART_TX_ENABLE      = 0x80,
4328c2ecf20Sopenharmony_ci};
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_cistruct FW_WRITE_UART {
4358c2ecf20Sopenharmony_ci	struct FW_HEADER hdr;
4368c2ecf20Sopenharmony_ci	u8 Data[252];
4378c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_cistruct ngene_command {
4418c2ecf20Sopenharmony_ci	u32 in_len;
4428c2ecf20Sopenharmony_ci	u32 out_len;
4438c2ecf20Sopenharmony_ci	union {
4448c2ecf20Sopenharmony_ci		u32                              raw[64];
4458c2ecf20Sopenharmony_ci		u8                               raw8[256];
4468c2ecf20Sopenharmony_ci		struct FW_HEADER                 hdr;
4478c2ecf20Sopenharmony_ci		struct FW_I2C_WRITE              I2CWrite;
4488c2ecf20Sopenharmony_ci		struct FW_I2C_CONTINUE_WRITE     I2CContinueWrite;
4498c2ecf20Sopenharmony_ci		struct FW_I2C_READ               I2CRead;
4508c2ecf20Sopenharmony_ci		struct FW_STREAM_CONTROL         StreamControl;
4518c2ecf20Sopenharmony_ci		struct FW_FWLOAD_PREPARE         FWLoadPrepare;
4528c2ecf20Sopenharmony_ci		struct FW_FWLOAD_FINISH          FWLoadFinish;
4538c2ecf20Sopenharmony_ci		struct FW_MEM_READ		 MemoryRead;
4548c2ecf20Sopenharmony_ci		struct FW_MEM_WRITE		 MemoryWrite;
4558c2ecf20Sopenharmony_ci		struct FW_SFR_IRAM_READ		 SfrIramRead;
4568c2ecf20Sopenharmony_ci		struct FW_SFR_IRAM_WRITE         SfrIramWrite;
4578c2ecf20Sopenharmony_ci		struct FW_SPI_WRITE              SPIWrite;
4588c2ecf20Sopenharmony_ci		struct FW_SPI_READ               SPIRead;
4598c2ecf20Sopenharmony_ci		struct FW_SET_GPIO_PIN           SetGpioPin;
4608c2ecf20Sopenharmony_ci		struct FW_SET_GPIO_INT           SetGpioInt;
4618c2ecf20Sopenharmony_ci		struct FW_SET_DEBUGMODE          SetDebugMode;
4628c2ecf20Sopenharmony_ci		struct FW_CONFIGURE_BUFFERS      ConfigureBuffers;
4638c2ecf20Sopenharmony_ci		struct FW_CONFIGURE_FREE_BUFFERS ConfigureFreeBuffers;
4648c2ecf20Sopenharmony_ci		struct FW_CONFIGURE_UART         ConfigureUart;
4658c2ecf20Sopenharmony_ci		struct FW_WRITE_UART             WriteUart;
4668c2ecf20Sopenharmony_ci	} cmd;
4678c2ecf20Sopenharmony_ci} __attribute__ ((__packed__));
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci#define NGENE_INTERFACE_VERSION 0x103
4708c2ecf20Sopenharmony_ci#define MAX_VIDEO_BUFFER_SIZE   (417792) /* 288*1440 rounded up to next page */
4718c2ecf20Sopenharmony_ci#define MAX_AUDIO_BUFFER_SIZE     (8192) /* Gives room for about 23msec@48KHz */
4728c2ecf20Sopenharmony_ci#define MAX_VBI_BUFFER_SIZE      (28672) /* 1144*18 rounded up to next page */
4738c2ecf20Sopenharmony_ci#define MAX_TS_BUFFER_SIZE       (98304) /* 512*188 rounded up to next page */
4748c2ecf20Sopenharmony_ci#define MAX_HDTV_BUFFER_SIZE   (2080768) /* 541*1920*2 rounded up to next page
4758c2ecf20Sopenharmony_ci					    Max: (1920x1080i60) */
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci#define OVERFLOW_BUFFER_SIZE    (8192)
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci#define RING_SIZE_VIDEO     4
4808c2ecf20Sopenharmony_ci#define RING_SIZE_AUDIO     8
4818c2ecf20Sopenharmony_ci#define RING_SIZE_TS        8
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci#define NUM_SCATTER_GATHER_ENTRIES  8
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci#define MAX_DMA_LENGTH (((MAX_VIDEO_BUFFER_SIZE + MAX_VBI_BUFFER_SIZE) * \
4868c2ecf20Sopenharmony_ci			RING_SIZE_VIDEO * 2) + \
4878c2ecf20Sopenharmony_ci			(MAX_AUDIO_BUFFER_SIZE * RING_SIZE_AUDIO * 2) + \
4888c2ecf20Sopenharmony_ci			(MAX_TS_BUFFER_SIZE * RING_SIZE_TS * 4) + \
4898c2ecf20Sopenharmony_ci			(RING_SIZE_VIDEO * PAGE_SIZE * 2) + \
4908c2ecf20Sopenharmony_ci			(RING_SIZE_AUDIO * PAGE_SIZE * 2) + \
4918c2ecf20Sopenharmony_ci			(RING_SIZE_TS    * PAGE_SIZE * 4) + \
4928c2ecf20Sopenharmony_ci			 8 * PAGE_SIZE + OVERFLOW_BUFFER_SIZE + PAGE_SIZE)
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci#define EVENT_QUEUE_SIZE    16
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci/* Gathers the current state of a single channel. */
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_cistruct SBufferHeader {
4998c2ecf20Sopenharmony_ci	struct BUFFER_HEADER   ngeneBuffer; /* Physical descriptor */
5008c2ecf20Sopenharmony_ci	struct SBufferHeader  *Next;
5018c2ecf20Sopenharmony_ci	void                  *Buffer1;
5028c2ecf20Sopenharmony_ci	struct HW_SCATTER_GATHER_ELEMENT *scList1;
5038c2ecf20Sopenharmony_ci	void                  *Buffer2;
5048c2ecf20Sopenharmony_ci	struct HW_SCATTER_GATHER_ELEMENT *scList2;
5058c2ecf20Sopenharmony_ci};
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci/* Sizeof SBufferHeader aligned to next 64 Bit boundary (hw restriction) */
5088c2ecf20Sopenharmony_ci#define SIZEOF_SBufferHeader ((sizeof(struct SBufferHeader) + 63) & ~63)
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_cienum HWSTATE {
5118c2ecf20Sopenharmony_ci	HWSTATE_STOP,
5128c2ecf20Sopenharmony_ci	HWSTATE_STARTUP,
5138c2ecf20Sopenharmony_ci	HWSTATE_RUN,
5148c2ecf20Sopenharmony_ci	HWSTATE_PAUSE,
5158c2ecf20Sopenharmony_ci};
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_cienum KSSTATE {
5188c2ecf20Sopenharmony_ci	KSSTATE_STOP,
5198c2ecf20Sopenharmony_ci	KSSTATE_ACQUIRE,
5208c2ecf20Sopenharmony_ci	KSSTATE_PAUSE,
5218c2ecf20Sopenharmony_ci	KSSTATE_RUN,
5228c2ecf20Sopenharmony_ci};
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_cistruct SRingBufferDescriptor {
5258c2ecf20Sopenharmony_ci	struct SBufferHeader *Head; /* Points to first buffer in ring buffer
5268c2ecf20Sopenharmony_ci				       structure*/
5278c2ecf20Sopenharmony_ci	u64   PAHead;         /* Physical address of first buffer */
5288c2ecf20Sopenharmony_ci	u32   MemSize;        /* Memory size of allocated ring buffers
5298c2ecf20Sopenharmony_ci				 (needed for freeing) */
5308c2ecf20Sopenharmony_ci	u32   NumBuffers;     /* Number of buffers in the ring */
5318c2ecf20Sopenharmony_ci	u32   Buffer1Length;  /* Allocated length of Buffer 1 */
5328c2ecf20Sopenharmony_ci	u32   Buffer2Length;  /* Allocated length of Buffer 2 */
5338c2ecf20Sopenharmony_ci	void *SCListMem;      /* Memory to hold scatter gather lists for this
5348c2ecf20Sopenharmony_ci				 ring */
5358c2ecf20Sopenharmony_ci	u64   PASCListMem;    /* Physical address  .. */
5368c2ecf20Sopenharmony_ci	u32   SCListMemSize;  /* Size of this memory */
5378c2ecf20Sopenharmony_ci};
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_cienum STREAMMODEFLAGS {
5408c2ecf20Sopenharmony_ci	StreamMode_NONE   = 0, /* Stream not used */
5418c2ecf20Sopenharmony_ci	StreamMode_ANALOG = 1, /* Analog: Stream 0,1 = Video, 2,3 = Audio */
5428c2ecf20Sopenharmony_ci	StreamMode_TSIN   = 2, /* Transport stream input (all) */
5438c2ecf20Sopenharmony_ci	StreamMode_HDTV   = 4, /* HDTV: Maximum 1920x1080p30,1920x1080i60
5448c2ecf20Sopenharmony_ci				  (only stream 0) */
5458c2ecf20Sopenharmony_ci	StreamMode_TSOUT  = 8, /* Transport stream output (only stream 3) */
5468c2ecf20Sopenharmony_ci};
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cienum BufferExchangeFlags {
5508c2ecf20Sopenharmony_ci	BEF_EVEN_FIELD   = 0x00000001,
5518c2ecf20Sopenharmony_ci	BEF_CONTINUATION = 0x00000002,
5528c2ecf20Sopenharmony_ci	BEF_MORE_DATA    = 0x00000004,
5538c2ecf20Sopenharmony_ci	BEF_OVERFLOW     = 0x00000008,
5548c2ecf20Sopenharmony_ci	DF_SWAP32        = 0x00010000,
5558c2ecf20Sopenharmony_ci};
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_citypedef void *(IBufferExchange)(void *, void *, u32, u32, u32);
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_cistruct MICI_STREAMINFO {
5608c2ecf20Sopenharmony_ci	IBufferExchange    *pExchange;
5618c2ecf20Sopenharmony_ci	IBufferExchange    *pExchangeVBI;     /* Secondary (VBI, ancillary) */
5628c2ecf20Sopenharmony_ci	u8  Stream;
5638c2ecf20Sopenharmony_ci	u8  Flags;
5648c2ecf20Sopenharmony_ci	u8  Mode;
5658c2ecf20Sopenharmony_ci	u8  Reserved;
5668c2ecf20Sopenharmony_ci	u16 nLinesVideo;
5678c2ecf20Sopenharmony_ci	u16 nBytesPerLineVideo;
5688c2ecf20Sopenharmony_ci	u16 nLinesVBI;
5698c2ecf20Sopenharmony_ci	u16 nBytesPerLineVBI;
5708c2ecf20Sopenharmony_ci	u32 CaptureLength;    /* Used for audio and transport stream */
5718c2ecf20Sopenharmony_ci};
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci/****************************************************************************/
5748c2ecf20Sopenharmony_ci/* STRUCTS ******************************************************************/
5758c2ecf20Sopenharmony_ci/****************************************************************************/
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci/* sound hardware definition */
5788c2ecf20Sopenharmony_ci#define MIXER_ADDR_TVTUNER      0
5798c2ecf20Sopenharmony_ci#define MIXER_ADDR_LAST         0
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_cistruct ngene_channel;
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci/*struct sound chip*/
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_cistruct mychip {
5868c2ecf20Sopenharmony_ci	struct ngene_channel *chan;
5878c2ecf20Sopenharmony_ci	struct snd_card *card;
5888c2ecf20Sopenharmony_ci	struct pci_dev *pci;
5898c2ecf20Sopenharmony_ci	struct snd_pcm_substream *substream;
5908c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;
5918c2ecf20Sopenharmony_ci	unsigned long port;
5928c2ecf20Sopenharmony_ci	int irq;
5938c2ecf20Sopenharmony_ci	spinlock_t mixer_lock;
5948c2ecf20Sopenharmony_ci	spinlock_t lock;
5958c2ecf20Sopenharmony_ci	int mixer_volume[MIXER_ADDR_LAST + 1][2];
5968c2ecf20Sopenharmony_ci	int capture_source[MIXER_ADDR_LAST + 1][2];
5978c2ecf20Sopenharmony_ci};
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci#ifdef NGENE_V4L
6008c2ecf20Sopenharmony_cistruct ngene_overlay {
6018c2ecf20Sopenharmony_ci	int                    tvnorm;
6028c2ecf20Sopenharmony_ci	struct v4l2_rect       w;
6038c2ecf20Sopenharmony_ci	enum v4l2_field        field;
6048c2ecf20Sopenharmony_ci	struct v4l2_clip       *clips;
6058c2ecf20Sopenharmony_ci	int                    nclips;
6068c2ecf20Sopenharmony_ci	int                    setup_ok;
6078c2ecf20Sopenharmony_ci};
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_cistruct ngene_tvnorm {
6108c2ecf20Sopenharmony_ci	int   v4l2_id;
6118c2ecf20Sopenharmony_ci	char  *name;
6128c2ecf20Sopenharmony_ci	u16   swidth, sheight; /* scaled standard width, height */
6138c2ecf20Sopenharmony_ci	int   tuner_norm;
6148c2ecf20Sopenharmony_ci	int   soundstd;
6158c2ecf20Sopenharmony_ci};
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_cistruct ngene_vopen {
6188c2ecf20Sopenharmony_ci	struct ngene_channel      *ch;
6198c2ecf20Sopenharmony_ci	enum v4l2_priority         prio;
6208c2ecf20Sopenharmony_ci	int                        width;
6218c2ecf20Sopenharmony_ci	int                        height;
6228c2ecf20Sopenharmony_ci	int                        depth;
6238c2ecf20Sopenharmony_ci	struct videobuf_queue      vbuf_q;
6248c2ecf20Sopenharmony_ci	struct videobuf_queue      vbi;
6258c2ecf20Sopenharmony_ci	int                        fourcc;
6268c2ecf20Sopenharmony_ci	int                        picxcount;
6278c2ecf20Sopenharmony_ci	int                        resources;
6288c2ecf20Sopenharmony_ci	enum v4l2_buf_type         type;
6298c2ecf20Sopenharmony_ci	const struct ngene_format *fmt;
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	const struct ngene_format *ovfmt;
6328c2ecf20Sopenharmony_ci	struct ngene_overlay       ov;
6338c2ecf20Sopenharmony_ci};
6348c2ecf20Sopenharmony_ci#endif
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_cistruct ngene_channel {
6378c2ecf20Sopenharmony_ci	struct device         device;
6388c2ecf20Sopenharmony_ci	struct i2c_adapter    i2c_adapter;
6398c2ecf20Sopenharmony_ci	struct i2c_client    *i2c_client[1];
6408c2ecf20Sopenharmony_ci	int                   i2c_client_fe;
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci	struct ngene         *dev;
6438c2ecf20Sopenharmony_ci	int                   number;
6448c2ecf20Sopenharmony_ci	int                   type;
6458c2ecf20Sopenharmony_ci	int                   mode;
6468c2ecf20Sopenharmony_ci	bool                  has_adapter;
6478c2ecf20Sopenharmony_ci	bool                  has_demux;
6488c2ecf20Sopenharmony_ci	int                   demod_type;
6498c2ecf20Sopenharmony_ci	int (*gate_ctrl)(struct dvb_frontend *, int);
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ci	struct dvb_frontend  *fe;
6528c2ecf20Sopenharmony_ci	struct dvb_frontend  *fe2;
6538c2ecf20Sopenharmony_ci	struct dmxdev         dmxdev;
6548c2ecf20Sopenharmony_ci	struct dvb_demux      demux;
6558c2ecf20Sopenharmony_ci	struct dvb_net        dvbnet;
6568c2ecf20Sopenharmony_ci	struct dmx_frontend   hw_frontend;
6578c2ecf20Sopenharmony_ci	struct dmx_frontend   mem_frontend;
6588c2ecf20Sopenharmony_ci	int                   users;
6598c2ecf20Sopenharmony_ci	struct video_device  *v4l_dev;
6608c2ecf20Sopenharmony_ci	struct dvb_device    *ci_dev;
6618c2ecf20Sopenharmony_ci	struct tasklet_struct demux_tasklet;
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci	struct SBufferHeader *nextBuffer;
6648c2ecf20Sopenharmony_ci	enum KSSTATE          State;
6658c2ecf20Sopenharmony_ci	enum HWSTATE          HWState;
6668c2ecf20Sopenharmony_ci	u8                    Stream;
6678c2ecf20Sopenharmony_ci	u8                    Flags;
6688c2ecf20Sopenharmony_ci	u8                    Mode;
6698c2ecf20Sopenharmony_ci	IBufferExchange      *pBufferExchange;
6708c2ecf20Sopenharmony_ci	IBufferExchange      *pBufferExchange2;
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_ci	spinlock_t            state_lock;
6738c2ecf20Sopenharmony_ci	u16                   nLines;
6748c2ecf20Sopenharmony_ci	u16                   nBytesPerLine;
6758c2ecf20Sopenharmony_ci	u16                   nVBILines;
6768c2ecf20Sopenharmony_ci	u16                   nBytesPerVBILine;
6778c2ecf20Sopenharmony_ci	u16                   itumode;
6788c2ecf20Sopenharmony_ci	u32                   Capture1Length;
6798c2ecf20Sopenharmony_ci	u32                   Capture2Length;
6808c2ecf20Sopenharmony_ci	struct SRingBufferDescriptor RingBuffer;
6818c2ecf20Sopenharmony_ci	struct SRingBufferDescriptor TSRingBuffer;
6828c2ecf20Sopenharmony_ci	struct SRingBufferDescriptor TSIdleBuffer;
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	u32                   DataFormatFlags;
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci	int                   AudioDTOUpdated;
6878c2ecf20Sopenharmony_ci	u32                   AudioDTOValue;
6888c2ecf20Sopenharmony_ci
6898c2ecf20Sopenharmony_ci	int (*set_tone)(struct dvb_frontend *, enum fe_sec_tone_mode);
6908c2ecf20Sopenharmony_ci	u8 lnbh;
6918c2ecf20Sopenharmony_ci
6928c2ecf20Sopenharmony_ci	/* stuff from analog driver */
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	int minor;
6958c2ecf20Sopenharmony_ci	struct mychip        *mychip;
6968c2ecf20Sopenharmony_ci	struct snd_card      *soundcard;
6978c2ecf20Sopenharmony_ci	u8                   *evenbuffer;
6988c2ecf20Sopenharmony_ci	u8                    dma_on;
6998c2ecf20Sopenharmony_ci	int                   soundstreamon;
7008c2ecf20Sopenharmony_ci	int                   audiomute;
7018c2ecf20Sopenharmony_ci	int                   soundbuffisallocated;
7028c2ecf20Sopenharmony_ci	int                   sndbuffflag;
7038c2ecf20Sopenharmony_ci	int                   tun_rdy;
7048c2ecf20Sopenharmony_ci	int                   dec_rdy;
7058c2ecf20Sopenharmony_ci	int                   tun_dec_rdy;
7068c2ecf20Sopenharmony_ci	int                   lastbufferflag;
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	struct ngene_tvnorm  *tvnorms;
7098c2ecf20Sopenharmony_ci	int                   tvnorm_num;
7108c2ecf20Sopenharmony_ci	int                   tvnorm;
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci#ifdef NGENE_V4L
7138c2ecf20Sopenharmony_ci	int                   videousers;
7148c2ecf20Sopenharmony_ci	struct v4l2_prio_state prio;
7158c2ecf20Sopenharmony_ci	struct ngene_vopen    init;
7168c2ecf20Sopenharmony_ci	int                   resources;
7178c2ecf20Sopenharmony_ci	struct v4l2_framebuffer fbuf;
7188c2ecf20Sopenharmony_ci	struct ngene_buffer  *screen;     /* overlay             */
7198c2ecf20Sopenharmony_ci	struct list_head      capture;    /* video capture queue */
7208c2ecf20Sopenharmony_ci	spinlock_t s_lock;
7218c2ecf20Sopenharmony_ci	struct semaphore reslock;
7228c2ecf20Sopenharmony_ci#endif
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci	int running;
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci	int tsin_offset;
7278c2ecf20Sopenharmony_ci	u8  tsin_buffer[188];
7288c2ecf20Sopenharmony_ci};
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_cistruct ngene_ci {
7328c2ecf20Sopenharmony_ci	struct device         device;
7338c2ecf20Sopenharmony_ci	struct i2c_adapter    i2c_adapter;
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci	struct ngene         *dev;
7368c2ecf20Sopenharmony_ci	struct dvb_ca_en50221 *en;
7378c2ecf20Sopenharmony_ci};
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_cistruct ngene;
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_citypedef void (rx_cb_t)(struct ngene *, u32, u8);
7428c2ecf20Sopenharmony_citypedef void (tx_cb_t)(struct ngene *, u32);
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_cistruct ngene {
7458c2ecf20Sopenharmony_ci	int                   nr;
7468c2ecf20Sopenharmony_ci	struct pci_dev       *pci_dev;
7478c2ecf20Sopenharmony_ci	unsigned char __iomem *iomem;
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci	/*struct i2c_adapter  i2c_adapter;*/
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ci	u32                   device_version;
7528c2ecf20Sopenharmony_ci	u32                   fw_interface_version;
7538c2ecf20Sopenharmony_ci	u32                   icounts;
7548c2ecf20Sopenharmony_ci	bool                  msi_enabled;
7558c2ecf20Sopenharmony_ci	bool                  cmd_timeout_workaround;
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci	u8                   *CmdDoneByte;
7588c2ecf20Sopenharmony_ci	int                   BootFirmware;
7598c2ecf20Sopenharmony_ci	void                 *OverflowBuffer;
7608c2ecf20Sopenharmony_ci	dma_addr_t            PAOverflowBuffer;
7618c2ecf20Sopenharmony_ci	void                 *FWInterfaceBuffer;
7628c2ecf20Sopenharmony_ci	dma_addr_t            PAFWInterfaceBuffer;
7638c2ecf20Sopenharmony_ci	u8                   *ngenetohost;
7648c2ecf20Sopenharmony_ci	u8                   *hosttongene;
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci	struct EVENT_BUFFER   EventQueue[EVENT_QUEUE_SIZE];
7678c2ecf20Sopenharmony_ci	int                   EventQueueOverflowCount;
7688c2ecf20Sopenharmony_ci	int                   EventQueueOverflowFlag;
7698c2ecf20Sopenharmony_ci	struct tasklet_struct event_tasklet;
7708c2ecf20Sopenharmony_ci	struct EVENT_BUFFER  *EventBuffer;
7718c2ecf20Sopenharmony_ci	int                   EventQueueWriteIndex;
7728c2ecf20Sopenharmony_ci	int                   EventQueueReadIndex;
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci	wait_queue_head_t     cmd_wq;
7758c2ecf20Sopenharmony_ci	int                   cmd_done;
7768c2ecf20Sopenharmony_ci	struct mutex          cmd_mutex;
7778c2ecf20Sopenharmony_ci	struct mutex          stream_mutex;
7788c2ecf20Sopenharmony_ci	struct semaphore      pll_mutex;
7798c2ecf20Sopenharmony_ci	struct mutex          i2c_switch_mutex;
7808c2ecf20Sopenharmony_ci	int                   i2c_current_channel;
7818c2ecf20Sopenharmony_ci	int                   i2c_current_bus;
7828c2ecf20Sopenharmony_ci	spinlock_t            cmd_lock;
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci	struct dvb_adapter    adapter[MAX_STREAM];
7858c2ecf20Sopenharmony_ci	struct dvb_adapter    *first_adapter; /* "one_adapter" modprobe opt */
7868c2ecf20Sopenharmony_ci	struct ngene_channel  channel[MAX_STREAM];
7878c2ecf20Sopenharmony_ci
7888c2ecf20Sopenharmony_ci	struct ngene_info    *card_info;
7898c2ecf20Sopenharmony_ci
7908c2ecf20Sopenharmony_ci	tx_cb_t              *TxEventNotify;
7918c2ecf20Sopenharmony_ci	rx_cb_t              *RxEventNotify;
7928c2ecf20Sopenharmony_ci	int                   tx_busy;
7938c2ecf20Sopenharmony_ci	wait_queue_head_t     tx_wq;
7948c2ecf20Sopenharmony_ci	wait_queue_head_t     rx_wq;
7958c2ecf20Sopenharmony_ci#define UART_RBUF_LEN 4096
7968c2ecf20Sopenharmony_ci	u8                    uart_rbuf[UART_RBUF_LEN];
7978c2ecf20Sopenharmony_ci	int                   uart_rp, uart_wp;
7988c2ecf20Sopenharmony_ci
7998c2ecf20Sopenharmony_ci#define TS_FILLER  0x6f
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci	u8                   *tsout_buf;
8028c2ecf20Sopenharmony_ci#define TSOUT_BUF_SIZE (512*188*8)
8038c2ecf20Sopenharmony_ci	struct dvb_ringbuffer tsout_rbuf;
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	u8                   *tsin_buf;
8068c2ecf20Sopenharmony_ci#define TSIN_BUF_SIZE (512*188*8)
8078c2ecf20Sopenharmony_ci	struct dvb_ringbuffer tsin_rbuf;
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci	u8                   *ain_buf;
8108c2ecf20Sopenharmony_ci#define AIN_BUF_SIZE (128*1024)
8118c2ecf20Sopenharmony_ci	struct dvb_ringbuffer ain_rbuf;
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	u8                   *vin_buf;
8158c2ecf20Sopenharmony_ci#define VIN_BUF_SIZE (4*1920*1080)
8168c2ecf20Sopenharmony_ci	struct dvb_ringbuffer vin_rbuf;
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci	unsigned long         exp_val;
8198c2ecf20Sopenharmony_ci	int prev_cmd;
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci	struct ngene_ci       ci;
8228c2ecf20Sopenharmony_ci};
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_cistruct ngene_info {
8258c2ecf20Sopenharmony_ci	int   type;
8268c2ecf20Sopenharmony_ci#define NGENE_APP        0
8278c2ecf20Sopenharmony_ci#define NGENE_TERRATEC   1
8288c2ecf20Sopenharmony_ci#define NGENE_SIDEWINDER 2
8298c2ecf20Sopenharmony_ci#define NGENE_RACER      3
8308c2ecf20Sopenharmony_ci#define NGENE_VIPER      4
8318c2ecf20Sopenharmony_ci#define NGENE_PYTHON     5
8328c2ecf20Sopenharmony_ci#define NGENE_VBOX_V1	 6
8338c2ecf20Sopenharmony_ci#define NGENE_VBOX_V2	 7
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_ci	int   fw_version;
8368c2ecf20Sopenharmony_ci	bool  msi_supported;
8378c2ecf20Sopenharmony_ci	char *name;
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	int   io_type[MAX_STREAM];
8408c2ecf20Sopenharmony_ci#define NGENE_IO_NONE    0
8418c2ecf20Sopenharmony_ci#define NGENE_IO_TV      1
8428c2ecf20Sopenharmony_ci#define NGENE_IO_HDTV    2
8438c2ecf20Sopenharmony_ci#define NGENE_IO_TSIN    4
8448c2ecf20Sopenharmony_ci#define NGENE_IO_TSOUT   8
8458c2ecf20Sopenharmony_ci#define NGENE_IO_AIN     16
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci	void *fe_config[4];
8488c2ecf20Sopenharmony_ci	void *tuner_config[4];
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci	int (*demod_attach[4])(struct ngene_channel *);
8518c2ecf20Sopenharmony_ci	int (*tuner_attach[4])(struct ngene_channel *);
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_ci	u8    avf[4];
8548c2ecf20Sopenharmony_ci	u8    msp[4];
8558c2ecf20Sopenharmony_ci	u8    demoda[4];
8568c2ecf20Sopenharmony_ci	u8    lnb[4];
8578c2ecf20Sopenharmony_ci	int   i2c_access;
8588c2ecf20Sopenharmony_ci	u8    ntsc;
8598c2ecf20Sopenharmony_ci	u8    tsf[4];
8608c2ecf20Sopenharmony_ci	u8    i2s[4];
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_ci	int (*gate_ctrl)(struct dvb_frontend *, int);
8638c2ecf20Sopenharmony_ci	int (*switch_ctrl)(struct ngene_channel *, int, int);
8648c2ecf20Sopenharmony_ci};
8658c2ecf20Sopenharmony_ci
8668c2ecf20Sopenharmony_ci#ifdef NGENE_V4L
8678c2ecf20Sopenharmony_cistruct ngene_format {
8688c2ecf20Sopenharmony_ci	char *name;
8698c2ecf20Sopenharmony_ci	int   fourcc;          /* video4linux 2      */
8708c2ecf20Sopenharmony_ci	int   btformat;        /* BT848_COLOR_FMT_*  */
8718c2ecf20Sopenharmony_ci	int   format;
8728c2ecf20Sopenharmony_ci	int   btswap;          /* BT848_COLOR_CTL_*  */
8738c2ecf20Sopenharmony_ci	int   depth;           /* bit/pixel          */
8748c2ecf20Sopenharmony_ci	int   flags;
8758c2ecf20Sopenharmony_ci	int   hshift, vshift;  /* for planar modes   */
8768c2ecf20Sopenharmony_ci	int   palette;
8778c2ecf20Sopenharmony_ci};
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_ci#define RESOURCE_OVERLAY       1
8808c2ecf20Sopenharmony_ci#define RESOURCE_VIDEO         2
8818c2ecf20Sopenharmony_ci#define RESOURCE_VBI           4
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_cistruct ngene_buffer {
8848c2ecf20Sopenharmony_ci	/* common v4l buffer stuff -- must be first */
8858c2ecf20Sopenharmony_ci	struct videobuf_buffer     vb;
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_ci	/* ngene specific */
8888c2ecf20Sopenharmony_ci	const struct ngene_format *fmt;
8898c2ecf20Sopenharmony_ci	int                        tvnorm;
8908c2ecf20Sopenharmony_ci	int                        btformat;
8918c2ecf20Sopenharmony_ci	int                        btswap;
8928c2ecf20Sopenharmony_ci};
8938c2ecf20Sopenharmony_ci#endif
8948c2ecf20Sopenharmony_ci
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_ci/* Provided by ngene-core.c */
8978c2ecf20Sopenharmony_ciint ngene_probe(struct pci_dev *pci_dev, const struct pci_device_id *id);
8988c2ecf20Sopenharmony_civoid ngene_remove(struct pci_dev *pdev);
8998c2ecf20Sopenharmony_civoid ngene_shutdown(struct pci_dev *pdev);
9008c2ecf20Sopenharmony_ciint ngene_command(struct ngene *dev, struct ngene_command *com);
9018c2ecf20Sopenharmony_ciint ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level);
9028c2ecf20Sopenharmony_civoid set_transfer(struct ngene_channel *chan, int state);
9038c2ecf20Sopenharmony_civoid FillTSBuffer(void *Buffer, int Length, u32 Flags);
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_ci/* Provided by ngene-cards.c */
9068c2ecf20Sopenharmony_ciint ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type);
9078c2ecf20Sopenharmony_ci
9088c2ecf20Sopenharmony_ci/* Provided by ngene-i2c.c */
9098c2ecf20Sopenharmony_ciint ngene_i2c_init(struct ngene *dev, int dev_nr);
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_ci/* Provided by ngene-dvb.c */
9128c2ecf20Sopenharmony_ciextern struct dvb_device ngene_dvbdev_ci;
9138c2ecf20Sopenharmony_civoid *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
9148c2ecf20Sopenharmony_civoid *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
9158c2ecf20Sopenharmony_ciint ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed);
9168c2ecf20Sopenharmony_ciint ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
9178c2ecf20Sopenharmony_ciint my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
9188c2ecf20Sopenharmony_ci			    int (*start_feed)(struct dvb_demux_feed *),
9198c2ecf20Sopenharmony_ci			    int (*stop_feed)(struct dvb_demux_feed *),
9208c2ecf20Sopenharmony_ci			    void *priv);
9218c2ecf20Sopenharmony_ciint my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
9228c2ecf20Sopenharmony_ci			       struct dvb_demux *dvbdemux,
9238c2ecf20Sopenharmony_ci			       struct dmx_frontend *hw_frontend,
9248c2ecf20Sopenharmony_ci			       struct dmx_frontend *mem_frontend,
9258c2ecf20Sopenharmony_ci			       struct dvb_adapter *dvb_adapter);
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_ci#endif
9288c2ecf20Sopenharmony_ci
9298c2ecf20Sopenharmony_ci/*  LocalWords:  Endif
9308c2ecf20Sopenharmony_ci */
931