Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * ngene.h: nGene PCIe bridge driver
0004  *
0005  * Copyright (C) 2005-2007 Micronas
0006  */
0007 
0008 #ifndef _NGENE_H_
0009 #define _NGENE_H_
0010 
0011 #include <linux/types.h>
0012 #include <linux/sched.h>
0013 #include <linux/interrupt.h>
0014 #include <linux/i2c.h>
0015 #include <asm/dma.h>
0016 #include <linux/scatterlist.h>
0017 
0018 #include <linux/dvb/frontend.h>
0019 
0020 #include <media/dmxdev.h>
0021 #include <media/dvbdev.h>
0022 #include <media/dvb_demux.h>
0023 #include <media/dvb_ca_en50221.h>
0024 #include <media/dvb_frontend.h>
0025 #include <media/dvb_ringbuffer.h>
0026 #include <media/dvb_net.h>
0027 #include "cxd2099.h"
0028 
0029 #define DEVICE_NAME "ngene"
0030 
0031 #define NGENE_VID       0x18c3
0032 #define NGENE_PID       0x0720
0033 
0034 #ifndef VIDEO_CAP_VC1
0035 #define VIDEO_CAP_AVC   128
0036 #define VIDEO_CAP_H264  128
0037 #define VIDEO_CAP_VC1   256
0038 #define VIDEO_CAP_WMV9  256
0039 #define VIDEO_CAP_MPEG4 512
0040 #endif
0041 
0042 #define DEMOD_TYPE_STV090X  0
0043 #define DEMOD_TYPE_DRXK     1
0044 #define DEMOD_TYPE_STV0367  2
0045 
0046 #define DEMOD_TYPE_XO2      32
0047 #define DEMOD_TYPE_STV0910  (DEMOD_TYPE_XO2 + 0)
0048 #define DEMOD_TYPE_SONY_CT2 (DEMOD_TYPE_XO2 + 1)
0049 #define DEMOD_TYPE_SONY_ISDBT   (DEMOD_TYPE_XO2 + 2)
0050 #define DEMOD_TYPE_SONY_C2T2    (DEMOD_TYPE_XO2 + 3)
0051 #define DEMOD_TYPE_ST_ATSC  (DEMOD_TYPE_XO2 + 4)
0052 #define DEMOD_TYPE_SONY_C2T2I   (DEMOD_TYPE_XO2 + 5)
0053 
0054 #define NGENE_XO2_TYPE_NONE 0
0055 #define NGENE_XO2_TYPE_DUOFLEX  1
0056 #define NGENE_XO2_TYPE_CI   2
0057 
0058 enum STREAM {
0059     STREAM_VIDEOIN1 = 0,        /* ITU656 or TS Input */
0060     STREAM_VIDEOIN2,
0061     STREAM_AUDIOIN1,            /* I2S or SPI Input */
0062     STREAM_AUDIOIN2,
0063     STREAM_AUDIOOUT,
0064     MAX_STREAM
0065 };
0066 
0067 enum SMODE_BITS {
0068     SMODE_AUDIO_SPDIF = 0x20,
0069     SMODE_AVSYNC = 0x10,
0070     SMODE_TRANSPORT_STREAM = 0x08,
0071     SMODE_AUDIO_CAPTURE = 0x04,
0072     SMODE_VBI_CAPTURE = 0x02,
0073     SMODE_VIDEO_CAPTURE = 0x01
0074 };
0075 
0076 enum STREAM_FLAG_BITS {
0077     SFLAG_CHROMA_FORMAT_2COMP  = 0x01, /* Chroma Format : 2's complement */
0078     SFLAG_CHROMA_FORMAT_OFFSET = 0x00, /* Chroma Format : Binary offset */
0079     SFLAG_ORDER_LUMA_CHROMA    = 0x02, /* Byte order: Y,Cb,Y,Cr */
0080     SFLAG_ORDER_CHROMA_LUMA    = 0x00, /* Byte order: Cb,Y,Cr,Y */
0081     SFLAG_COLORBAR             = 0x04, /* Select colorbar */
0082 };
0083 
0084 #define PROGRAM_ROM     0x0000
0085 #define PROGRAM_SRAM    0x1000
0086 #define PERIPHERALS0    0x8000
0087 #define PERIPHERALS1    0x9000
0088 #define SHARED_BUFFER   0xC000
0089 
0090 #define HOST_TO_NGENE    (SHARED_BUFFER+0x0000)
0091 #define NGENE_TO_HOST    (SHARED_BUFFER+0x0100)
0092 #define NGENE_COMMAND    (SHARED_BUFFER+0x0200)
0093 #define NGENE_COMMAND_HI (SHARED_BUFFER+0x0204)
0094 #define NGENE_STATUS     (SHARED_BUFFER+0x0208)
0095 #define NGENE_STATUS_HI  (SHARED_BUFFER+0x020C)
0096 #define NGENE_EVENT      (SHARED_BUFFER+0x0210)
0097 #define NGENE_EVENT_HI   (SHARED_BUFFER+0x0214)
0098 #define VARIABLES        (SHARED_BUFFER+0x0210)
0099 
0100 #define NGENE_INT_COUNTS       (SHARED_BUFFER+0x0260)
0101 #define NGENE_INT_ENABLE       (SHARED_BUFFER+0x0264)
0102 #define NGENE_VBI_LINE_COUNT   (SHARED_BUFFER+0x0268)
0103 
0104 #define BUFFER_GP_XMIT  (SHARED_BUFFER+0x0800)
0105 #define BUFFER_GP_RECV  (SHARED_BUFFER+0x0900)
0106 #define EEPROM_AREA     (SHARED_BUFFER+0x0A00)
0107 
0108 #define SG_V_IN_1       (SHARED_BUFFER+0x0A80)
0109 #define SG_VBI_1        (SHARED_BUFFER+0x0B00)
0110 #define SG_A_IN_1       (SHARED_BUFFER+0x0B80)
0111 #define SG_V_IN_2       (SHARED_BUFFER+0x0C00)
0112 #define SG_VBI_2        (SHARED_BUFFER+0x0C80)
0113 #define SG_A_IN_2       (SHARED_BUFFER+0x0D00)
0114 #define SG_V_OUT        (SHARED_BUFFER+0x0D80)
0115 #define SG_A_OUT2       (SHARED_BUFFER+0x0E00)
0116 
0117 #define DATA_A_IN_1     (SHARED_BUFFER+0x0E80)
0118 #define DATA_A_IN_2     (SHARED_BUFFER+0x0F00)
0119 #define DATA_A_OUT      (SHARED_BUFFER+0x0F80)
0120 #define DATA_V_IN_1     (SHARED_BUFFER+0x1000)
0121 #define DATA_V_IN_2     (SHARED_BUFFER+0x2000)
0122 #define DATA_V_OUT      (SHARED_BUFFER+0x3000)
0123 
0124 #define DATA_FIFO_AREA  (SHARED_BUFFER+0x1000)
0125 
0126 #define TIMESTAMPS      0xA000
0127 #define SCRATCHPAD      0xA080
0128 #define FORCE_INT       0xA088
0129 #define FORCE_NMI       0xA090
0130 #define INT_STATUS      0xA0A0
0131 
0132 #define DEV_VER         0x9004
0133 
0134 #define FW_DEBUG_DEFAULT (PROGRAM_SRAM+0x00FF)
0135 
0136 struct SG_ADDR {
0137     u64 start;
0138     u64 curr;
0139     u16 curr_ptr;
0140     u16 elements;
0141     u32 pad[3];
0142 } __attribute__ ((__packed__));
0143 
0144 struct SHARED_MEMORY {
0145     /* C000 */
0146     u32 HostToNgene[64];
0147 
0148     /* C100 */
0149     u32 NgeneToHost[64];
0150 
0151     /* C200 */
0152     u64 NgeneCommand;
0153     u64 NgeneStatus;
0154     u64 NgeneEvent;
0155 
0156     /* C210 */
0157     u8 pad1[0xc260 - 0xc218];
0158 
0159     /* C260 */
0160     u32 IntCounts;
0161     u32 IntEnable;
0162 
0163     /* C268 */
0164     u8 pad2[0xd000 - 0xc268];
0165 
0166 } __attribute__ ((__packed__));
0167 
0168 struct BUFFER_STREAM_RESULTS {
0169     u32 Clock;           /* Stream time in 100ns units */
0170     u16 RemainingLines;  /* Remaining lines in this field.
0171                 0 for complete field */
0172     u8  FieldCount;      /* Video field number */
0173     u8  Flags;           /* Bit 7 = Done, Bit 6 = seen, Bit 5 = overflow,
0174                 Bit 0 = FieldID */
0175     u16 BlockCount;      /* Audio block count (unused) */
0176     u8  Reserved[2];
0177     u32 DTOUpdate;
0178 } __attribute__ ((__packed__));
0179 
0180 struct HW_SCATTER_GATHER_ELEMENT {
0181     u64 Address;
0182     u32 Length;
0183     u32 Reserved;
0184 } __attribute__ ((__packed__));
0185 
0186 struct BUFFER_HEADER {
0187     u64    Next;
0188     struct BUFFER_STREAM_RESULTS SR;
0189 
0190     u32    Number_of_entries_1;
0191     u32    Reserved5;
0192     u64    Address_of_first_entry_1;
0193 
0194     u32    Number_of_entries_2;
0195     u32    Reserved7;
0196     u64    Address_of_first_entry_2;
0197 } __attribute__ ((__packed__));
0198 
0199 struct EVENT_BUFFER {
0200     u32    TimeStamp;
0201     u8     GPIOStatus;
0202     u8     UARTStatus;
0203     u8     RXCharacter;
0204     u8     EventStatus;
0205     u32    Reserved[2];
0206 } __attribute__ ((__packed__));
0207 
0208 /* Firmware commands. */
0209 
0210 enum OPCODES {
0211     CMD_NOP = 0,
0212     CMD_FWLOAD_PREPARE  = 0x01,
0213     CMD_FWLOAD_FINISH   = 0x02,
0214     CMD_I2C_READ        = 0x03,
0215     CMD_I2C_WRITE       = 0x04,
0216 
0217     CMD_I2C_WRITE_NOSTOP = 0x05,
0218     CMD_I2C_CONTINUE_WRITE = 0x06,
0219     CMD_I2C_CONTINUE_WRITE_NOSTOP = 0x07,
0220 
0221     CMD_DEBUG_OUTPUT    = 0x09,
0222 
0223     CMD_CONTROL         = 0x10,
0224     CMD_CONFIGURE_BUFFER = 0x11,
0225     CMD_CONFIGURE_FREE_BUFFER = 0x12,
0226 
0227     CMD_SPI_READ        = 0x13,
0228     CMD_SPI_WRITE       = 0x14,
0229 
0230     CMD_MEM_READ        = 0x20,
0231     CMD_MEM_WRITE       = 0x21,
0232     CMD_SFR_READ        = 0x22,
0233     CMD_SFR_WRITE       = 0x23,
0234     CMD_IRAM_READ       = 0x24,
0235     CMD_IRAM_WRITE      = 0x25,
0236     CMD_SET_GPIO_PIN    = 0x26,
0237     CMD_SET_GPIO_INT    = 0x27,
0238     CMD_CONFIGURE_UART  = 0x28,
0239     CMD_WRITE_UART      = 0x29,
0240     MAX_CMD
0241 };
0242 
0243 enum RESPONSES {
0244     OK = 0,
0245     ERROR = 1
0246 };
0247 
0248 struct FW_HEADER {
0249     u8 Opcode;
0250     u8 Length;
0251 } __attribute__ ((__packed__));
0252 
0253 struct FW_I2C_WRITE {
0254     struct FW_HEADER hdr;
0255     u8 Device;
0256     u8 Data[250];
0257 } __attribute__ ((__packed__));
0258 
0259 struct FW_I2C_CONTINUE_WRITE {
0260     struct FW_HEADER hdr;
0261     u8 Data[250];
0262 } __attribute__ ((__packed__));
0263 
0264 struct FW_I2C_READ {
0265     struct FW_HEADER hdr;
0266     u8 Device;
0267     u8 Data[252];    /* followed by two bytes of read data count */
0268 } __attribute__ ((__packed__));
0269 
0270 struct FW_SPI_WRITE {
0271     struct FW_HEADER hdr;
0272     u8 ModeSelect;
0273     u8 Data[250];
0274 } __attribute__ ((__packed__));
0275 
0276 struct FW_SPI_READ {
0277     struct FW_HEADER hdr;
0278     u8 ModeSelect;
0279     u8 Data[252];    /* followed by two bytes of read data count */
0280 } __attribute__ ((__packed__));
0281 
0282 struct FW_FWLOAD_PREPARE {
0283     struct FW_HEADER hdr;
0284 } __attribute__ ((__packed__));
0285 
0286 struct FW_FWLOAD_FINISH {
0287     struct FW_HEADER hdr;
0288     u16 Address;     /* address of final block */
0289     u16 Length;
0290 } __attribute__ ((__packed__));
0291 
0292 /*
0293  * Meaning of FW_STREAM_CONTROL::Mode bits:
0294  *  Bit 7: Loopback PEXin to PEXout using TVOut channel
0295  *  Bit 6: AVLOOP
0296  *  Bit 5: Audio select; 0=I2S, 1=SPDIF
0297  *  Bit 4: AVSYNC
0298  *  Bit 3: Enable transport stream
0299  *  Bit 2: Enable audio capture
0300  *  Bit 1: Enable ITU-Video VBI capture
0301  *  Bit 0: Enable ITU-Video capture
0302  *
0303  * Meaning of FW_STREAM_CONTROL::Control bits (see UVI1_CTL)
0304  *  Bit 7: continuous capture
0305  *  Bit 6: capture one field
0306  *  Bit 5: capture one frame
0307  *  Bit 4: unused
0308  *  Bit 3: starting field; 0=odd, 1=even
0309  *  Bit 2: sample size; 0=8-bit, 1=10-bit
0310  *  Bit 1: data format; 0=UYVY, 1=YUY2
0311  *  Bit 0: resets buffer pointers
0312 */
0313 
0314 enum FSC_MODE_BITS {
0315     SMODE_LOOPBACK          = 0x80,
0316     SMODE_AVLOOP            = 0x40,
0317     _SMODE_AUDIO_SPDIF      = 0x20,
0318     _SMODE_AVSYNC           = 0x10,
0319     _SMODE_TRANSPORT_STREAM = 0x08,
0320     _SMODE_AUDIO_CAPTURE    = 0x04,
0321     _SMODE_VBI_CAPTURE      = 0x02,
0322     _SMODE_VIDEO_CAPTURE    = 0x01
0323 };
0324 
0325 
0326 /* Meaning of FW_STREAM_CONTROL::Stream bits:
0327  * Bit 3: Audio sample count:  0 = relative, 1 = absolute
0328  * Bit 2: color bar select; 1=color bars, 0=CV3 decoder
0329  * Bits 1-0: stream select, UVI1, UVI2, TVOUT
0330  */
0331 
0332 struct FW_STREAM_CONTROL {
0333     struct FW_HEADER hdr;
0334     u8     Stream;             /* Stream number (UVI1, UVI2, TVOUT) */
0335     u8     Control;            /* Value written to UVI1_CTL */
0336     u8     Mode;               /* Controls clock source */
0337     u8     SetupDataLen;       /* Length of setup data, MSB=1 write
0338                       backwards */
0339     u16    CaptureBlockCount;  /* Blocks (a 256 Bytes) to capture per buffer
0340                       for TS and Audio */
0341     u64    Buffer_Address;     /* Address of first buffer header */
0342     u16    BytesPerVideoLine;
0343     u16    MaxLinesPerField;
0344     u16    MinLinesPerField;
0345     u16    Reserved_1;
0346     u16    BytesPerVBILine;
0347     u16    MaxVBILinesPerField;
0348     u16    MinVBILinesPerField;
0349     u16    SetupDataAddr;      /* ngene relative address of setup data */
0350     u8     SetupData[32];      /* setup data */
0351 } __attribute__((__packed__));
0352 
0353 #define AUDIO_BLOCK_SIZE    256
0354 #define TS_BLOCK_SIZE       256
0355 
0356 struct FW_MEM_READ {
0357     struct FW_HEADER hdr;
0358     u16   address;
0359 } __attribute__ ((__packed__));
0360 
0361 struct FW_MEM_WRITE {
0362     struct FW_HEADER hdr;
0363     u16   address;
0364     u8    data;
0365 } __attribute__ ((__packed__));
0366 
0367 struct FW_SFR_IRAM_READ {
0368     struct FW_HEADER hdr;
0369     u8    address;
0370 } __attribute__ ((__packed__));
0371 
0372 struct FW_SFR_IRAM_WRITE {
0373     struct FW_HEADER hdr;
0374     u8    address;
0375     u8    data;
0376 } __attribute__ ((__packed__));
0377 
0378 struct FW_SET_GPIO_PIN {
0379     struct FW_HEADER hdr;
0380     u8    select;
0381 } __attribute__ ((__packed__));
0382 
0383 struct FW_SET_GPIO_INT {
0384     struct FW_HEADER hdr;
0385     u8    select;
0386 } __attribute__ ((__packed__));
0387 
0388 struct FW_SET_DEBUGMODE {
0389     struct FW_HEADER hdr;
0390     u8   debug_flags;
0391 } __attribute__ ((__packed__));
0392 
0393 struct FW_CONFIGURE_BUFFERS {
0394     struct FW_HEADER hdr;
0395     u8   config;
0396 } __attribute__ ((__packed__));
0397 
0398 enum _BUFFER_CONFIGS {
0399     /* 4k UVI1, 4k UVI2, 2k AUD1, 2k AUD2  (standard usage) */
0400     BUFFER_CONFIG_4422 = 0,
0401     /* 3k UVI1, 3k UVI2, 3k AUD1, 3k AUD2  (4x TS input usage) */
0402     BUFFER_CONFIG_3333 = 1,
0403     /* 8k UVI1, 0k UVI2, 2k AUD1, 2k I2SOut  (HDTV decoder usage) */
0404     BUFFER_CONFIG_8022 = 2,
0405     BUFFER_CONFIG_FW17 = 255, /* Use new FW 17 command */
0406 };
0407 
0408 struct FW_CONFIGURE_FREE_BUFFERS {
0409     struct FW_HEADER hdr;
0410     struct {
0411         u8   UVI1_BufferLength;
0412         u8   UVI2_BufferLength;
0413         u8   TVO_BufferLength;
0414         u8   AUD1_BufferLength;
0415         u8   AUD2_BufferLength;
0416         u8   TVA_BufferLength;
0417     } __packed config;
0418 } __attribute__ ((__packed__));
0419 
0420 struct FW_CONFIGURE_UART {
0421     struct FW_HEADER hdr;
0422     u8 UartControl;
0423 } __attribute__ ((__packed__));
0424 
0425 enum _UART_CONFIG {
0426     _UART_BAUDRATE_19200 = 0,
0427     _UART_BAUDRATE_9600  = 1,
0428     _UART_BAUDRATE_4800  = 2,
0429     _UART_BAUDRATE_2400  = 3,
0430     _UART_RX_ENABLE      = 0x40,
0431     _UART_TX_ENABLE      = 0x80,
0432 };
0433 
0434 struct FW_WRITE_UART {
0435     struct FW_HEADER hdr;
0436     u8 Data[252];
0437 } __attribute__ ((__packed__));
0438 
0439 
0440 struct ngene_command {
0441     u32 in_len;
0442     u32 out_len;
0443     union {
0444         u32                              raw[64];
0445         u8                               raw8[256];
0446         struct FW_HEADER                 hdr;
0447         struct FW_I2C_WRITE              I2CWrite;
0448         struct FW_I2C_CONTINUE_WRITE     I2CContinueWrite;
0449         struct FW_I2C_READ               I2CRead;
0450         struct FW_STREAM_CONTROL         StreamControl;
0451         struct FW_FWLOAD_PREPARE         FWLoadPrepare;
0452         struct FW_FWLOAD_FINISH          FWLoadFinish;
0453         struct FW_MEM_READ       MemoryRead;
0454         struct FW_MEM_WRITE      MemoryWrite;
0455         struct FW_SFR_IRAM_READ      SfrIramRead;
0456         struct FW_SFR_IRAM_WRITE         SfrIramWrite;
0457         struct FW_SPI_WRITE              SPIWrite;
0458         struct FW_SPI_READ               SPIRead;
0459         struct FW_SET_GPIO_PIN           SetGpioPin;
0460         struct FW_SET_GPIO_INT           SetGpioInt;
0461         struct FW_SET_DEBUGMODE          SetDebugMode;
0462         struct FW_CONFIGURE_BUFFERS      ConfigureBuffers;
0463         struct FW_CONFIGURE_FREE_BUFFERS ConfigureFreeBuffers;
0464         struct FW_CONFIGURE_UART         ConfigureUart;
0465         struct FW_WRITE_UART             WriteUart;
0466     } cmd;
0467 } __attribute__ ((__packed__));
0468 
0469 #define NGENE_INTERFACE_VERSION 0x103
0470 #define MAX_VIDEO_BUFFER_SIZE   (417792) /* 288*1440 rounded up to next page */
0471 #define MAX_AUDIO_BUFFER_SIZE     (8192) /* Gives room for about 23msec@48KHz */
0472 #define MAX_VBI_BUFFER_SIZE      (28672) /* 1144*18 rounded up to next page */
0473 #define MAX_TS_BUFFER_SIZE       (98304) /* 512*188 rounded up to next page */
0474 #define MAX_HDTV_BUFFER_SIZE   (2080768) /* 541*1920*2 rounded up to next page
0475                         Max: (1920x1080i60) */
0476 
0477 #define OVERFLOW_BUFFER_SIZE    (8192)
0478 
0479 #define RING_SIZE_VIDEO     4
0480 #define RING_SIZE_AUDIO     8
0481 #define RING_SIZE_TS        8
0482 
0483 #define NUM_SCATTER_GATHER_ENTRIES  8
0484 
0485 #define MAX_DMA_LENGTH (((MAX_VIDEO_BUFFER_SIZE + MAX_VBI_BUFFER_SIZE) * \
0486             RING_SIZE_VIDEO * 2) + \
0487             (MAX_AUDIO_BUFFER_SIZE * RING_SIZE_AUDIO * 2) + \
0488             (MAX_TS_BUFFER_SIZE * RING_SIZE_TS * 4) + \
0489             (RING_SIZE_VIDEO * PAGE_SIZE * 2) + \
0490             (RING_SIZE_AUDIO * PAGE_SIZE * 2) + \
0491             (RING_SIZE_TS    * PAGE_SIZE * 4) + \
0492              8 * PAGE_SIZE + OVERFLOW_BUFFER_SIZE + PAGE_SIZE)
0493 
0494 #define EVENT_QUEUE_SIZE    16
0495 
0496 /* Gathers the current state of a single channel. */
0497 
0498 struct SBufferHeader {
0499     struct BUFFER_HEADER   ngeneBuffer; /* Physical descriptor */
0500     struct SBufferHeader  *Next;
0501     void                  *Buffer1;
0502     struct HW_SCATTER_GATHER_ELEMENT *scList1;
0503     void                  *Buffer2;
0504     struct HW_SCATTER_GATHER_ELEMENT *scList2;
0505 };
0506 
0507 /* Sizeof SBufferHeader aligned to next 64 Bit boundary (hw restriction) */
0508 #define SIZEOF_SBufferHeader ((sizeof(struct SBufferHeader) + 63) & ~63)
0509 
0510 enum HWSTATE {
0511     HWSTATE_STOP,
0512     HWSTATE_STARTUP,
0513     HWSTATE_RUN,
0514     HWSTATE_PAUSE,
0515 };
0516 
0517 enum KSSTATE {
0518     KSSTATE_STOP,
0519     KSSTATE_ACQUIRE,
0520     KSSTATE_PAUSE,
0521     KSSTATE_RUN,
0522 };
0523 
0524 struct SRingBufferDescriptor {
0525     struct SBufferHeader *Head; /* Points to first buffer in ring buffer
0526                        structure*/
0527     u64   PAHead;         /* Physical address of first buffer */
0528     u32   MemSize;        /* Memory size of allocated ring buffers
0529                  (needed for freeing) */
0530     u32   NumBuffers;     /* Number of buffers in the ring */
0531     u32   Buffer1Length;  /* Allocated length of Buffer 1 */
0532     u32   Buffer2Length;  /* Allocated length of Buffer 2 */
0533     void *SCListMem;      /* Memory to hold scatter gather lists for this
0534                  ring */
0535     u64   PASCListMem;    /* Physical address  .. */
0536     u32   SCListMemSize;  /* Size of this memory */
0537 };
0538 
0539 enum STREAMMODEFLAGS {
0540     StreamMode_NONE   = 0, /* Stream not used */
0541     StreamMode_ANALOG = 1, /* Analog: Stream 0,1 = Video, 2,3 = Audio */
0542     StreamMode_TSIN   = 2, /* Transport stream input (all) */
0543     StreamMode_HDTV   = 4, /* HDTV: Maximum 1920x1080p30,1920x1080i60
0544                   (only stream 0) */
0545     StreamMode_TSOUT  = 8, /* Transport stream output (only stream 3) */
0546 };
0547 
0548 
0549 enum BufferExchangeFlags {
0550     BEF_EVEN_FIELD   = 0x00000001,
0551     BEF_CONTINUATION = 0x00000002,
0552     BEF_MORE_DATA    = 0x00000004,
0553     BEF_OVERFLOW     = 0x00000008,
0554     DF_SWAP32        = 0x00010000,
0555 };
0556 
0557 typedef void *(IBufferExchange)(void *, void *, u32, u32, u32);
0558 
0559 struct MICI_STREAMINFO {
0560     IBufferExchange    *pExchange;
0561     IBufferExchange    *pExchangeVBI;     /* Secondary (VBI, ancillary) */
0562     u8  Stream;
0563     u8  Flags;
0564     u8  Mode;
0565     u8  Reserved;
0566     u16 nLinesVideo;
0567     u16 nBytesPerLineVideo;
0568     u16 nLinesVBI;
0569     u16 nBytesPerLineVBI;
0570     u32 CaptureLength;    /* Used for audio and transport stream */
0571 };
0572 
0573 /****************************************************************************/
0574 /* STRUCTS ******************************************************************/
0575 /****************************************************************************/
0576 
0577 /* sound hardware definition */
0578 #define MIXER_ADDR_TVTUNER      0
0579 #define MIXER_ADDR_LAST         0
0580 
0581 struct ngene_channel;
0582 
0583 /*struct sound chip*/
0584 
0585 struct mychip {
0586     struct ngene_channel *chan;
0587     struct snd_card *card;
0588     struct pci_dev *pci;
0589     struct snd_pcm_substream *substream;
0590     struct snd_pcm *pcm;
0591     unsigned long port;
0592     int irq;
0593     spinlock_t mixer_lock;
0594     spinlock_t lock;
0595     int mixer_volume[MIXER_ADDR_LAST + 1][2];
0596     int capture_source[MIXER_ADDR_LAST + 1][2];
0597 };
0598 
0599 #ifdef NGENE_V4L
0600 struct ngene_overlay {
0601     int                    tvnorm;
0602     struct v4l2_rect       w;
0603     enum v4l2_field        field;
0604     struct v4l2_clip       *clips;
0605     int                    nclips;
0606     int                    setup_ok;
0607 };
0608 
0609 struct ngene_tvnorm {
0610     int   v4l2_id;
0611     char  *name;
0612     u16   swidth, sheight; /* scaled standard width, height */
0613     int   tuner_norm;
0614     int   soundstd;
0615 };
0616 
0617 struct ngene_vopen {
0618     struct ngene_channel      *ch;
0619     enum v4l2_priority         prio;
0620     int                        width;
0621     int                        height;
0622     int                        depth;
0623     struct videobuf_queue      vbuf_q;
0624     struct videobuf_queue      vbi;
0625     int                        fourcc;
0626     int                        picxcount;
0627     int                        resources;
0628     enum v4l2_buf_type         type;
0629     const struct ngene_format *fmt;
0630 
0631     const struct ngene_format *ovfmt;
0632     struct ngene_overlay       ov;
0633 };
0634 #endif
0635 
0636 struct ngene_channel {
0637     struct device         device;
0638     struct i2c_adapter    i2c_adapter;
0639     struct i2c_client    *i2c_client[1];
0640     int                   i2c_client_fe;
0641 
0642     struct ngene         *dev;
0643     int                   number;
0644     int                   type;
0645     int                   mode;
0646     bool                  has_adapter;
0647     bool                  has_demux;
0648     int                   demod_type;
0649     int (*gate_ctrl)(struct dvb_frontend *, int);
0650 
0651     struct dvb_frontend  *fe;
0652     struct dvb_frontend  *fe2;
0653     struct dmxdev         dmxdev;
0654     struct dvb_demux      demux;
0655     struct dvb_net        dvbnet;
0656     struct dmx_frontend   hw_frontend;
0657     struct dmx_frontend   mem_frontend;
0658     int                   users;
0659     struct video_device  *v4l_dev;
0660     struct dvb_device    *ci_dev;
0661     struct tasklet_struct demux_tasklet;
0662 
0663     struct SBufferHeader *nextBuffer;
0664     enum KSSTATE          State;
0665     enum HWSTATE          HWState;
0666     u8                    Stream;
0667     u8                    Flags;
0668     u8                    Mode;
0669     IBufferExchange      *pBufferExchange;
0670     IBufferExchange      *pBufferExchange2;
0671 
0672     spinlock_t            state_lock;
0673     u16                   nLines;
0674     u16                   nBytesPerLine;
0675     u16                   nVBILines;
0676     u16                   nBytesPerVBILine;
0677     u16                   itumode;
0678     u32                   Capture1Length;
0679     u32                   Capture2Length;
0680     struct SRingBufferDescriptor RingBuffer;
0681     struct SRingBufferDescriptor TSRingBuffer;
0682     struct SRingBufferDescriptor TSIdleBuffer;
0683 
0684     u32                   DataFormatFlags;
0685 
0686     int                   AudioDTOUpdated;
0687     u32                   AudioDTOValue;
0688 
0689     int (*set_tone)(struct dvb_frontend *, enum fe_sec_tone_mode);
0690     u8 lnbh;
0691 
0692     /* stuff from analog driver */
0693 
0694     int minor;
0695     struct mychip        *mychip;
0696     struct snd_card      *soundcard;
0697     u8                   *evenbuffer;
0698     u8                    dma_on;
0699     int                   soundstreamon;
0700     int                   audiomute;
0701     int                   soundbuffisallocated;
0702     int                   sndbuffflag;
0703     int                   tun_rdy;
0704     int                   dec_rdy;
0705     int                   tun_dec_rdy;
0706     int                   lastbufferflag;
0707 
0708     struct ngene_tvnorm  *tvnorms;
0709     int                   tvnorm_num;
0710     int                   tvnorm;
0711 
0712 #ifdef NGENE_V4L
0713     int                   videousers;
0714     struct v4l2_prio_state prio;
0715     struct ngene_vopen    init;
0716     int                   resources;
0717     struct v4l2_framebuffer fbuf;
0718     struct ngene_buffer  *screen;     /* overlay             */
0719     struct list_head      capture;    /* video capture queue */
0720     spinlock_t s_lock;
0721     struct semaphore reslock;
0722 #endif
0723 
0724     int running;
0725 
0726     int tsin_offset;
0727     u8  tsin_buffer[188];
0728 };
0729 
0730 
0731 struct ngene_ci {
0732     struct device         device;
0733     struct i2c_adapter    i2c_adapter;
0734 
0735     struct ngene         *dev;
0736     struct dvb_ca_en50221 *en;
0737 };
0738 
0739 struct ngene;
0740 
0741 typedef void (rx_cb_t)(struct ngene *, u32, u8);
0742 typedef void (tx_cb_t)(struct ngene *, u32);
0743 
0744 struct ngene {
0745     int                   nr;
0746     struct pci_dev       *pci_dev;
0747     unsigned char __iomem *iomem;
0748 
0749     /*struct i2c_adapter  i2c_adapter;*/
0750 
0751     u32                   device_version;
0752     u32                   fw_interface_version;
0753     u32                   icounts;
0754     bool                  msi_enabled;
0755     bool                  cmd_timeout_workaround;
0756 
0757     u8                   *CmdDoneByte;
0758     int                   BootFirmware;
0759     void                 *OverflowBuffer;
0760     dma_addr_t            PAOverflowBuffer;
0761     void                 *FWInterfaceBuffer;
0762     dma_addr_t            PAFWInterfaceBuffer;
0763     u8                   *ngenetohost;
0764     u8                   *hosttongene;
0765 
0766     struct EVENT_BUFFER   EventQueue[EVENT_QUEUE_SIZE];
0767     int                   EventQueueOverflowCount;
0768     int                   EventQueueOverflowFlag;
0769     struct tasklet_struct event_tasklet;
0770     struct EVENT_BUFFER  *EventBuffer;
0771     int                   EventQueueWriteIndex;
0772     int                   EventQueueReadIndex;
0773 
0774     wait_queue_head_t     cmd_wq;
0775     int                   cmd_done;
0776     struct mutex          cmd_mutex;
0777     struct mutex          stream_mutex;
0778     struct semaphore      pll_mutex;
0779     struct mutex          i2c_switch_mutex;
0780     int                   i2c_current_channel;
0781     int                   i2c_current_bus;
0782     spinlock_t            cmd_lock;
0783 
0784     struct dvb_adapter    adapter[MAX_STREAM];
0785     struct dvb_adapter    *first_adapter; /* "one_adapter" modprobe opt */
0786     struct ngene_channel  channel[MAX_STREAM];
0787 
0788     struct ngene_info    *card_info;
0789 
0790     tx_cb_t              *TxEventNotify;
0791     rx_cb_t              *RxEventNotify;
0792     int                   tx_busy;
0793     wait_queue_head_t     tx_wq;
0794     wait_queue_head_t     rx_wq;
0795 #define UART_RBUF_LEN 4096
0796     u8                    uart_rbuf[UART_RBUF_LEN];
0797     int                   uart_rp, uart_wp;
0798 
0799 #define TS_FILLER  0x6f
0800 
0801     u8                   *tsout_buf;
0802 #define TSOUT_BUF_SIZE (512*188*8)
0803     struct dvb_ringbuffer tsout_rbuf;
0804 
0805     u8                   *tsin_buf;
0806 #define TSIN_BUF_SIZE (512*188*8)
0807     struct dvb_ringbuffer tsin_rbuf;
0808 
0809     u8                   *ain_buf;
0810 #define AIN_BUF_SIZE (128*1024)
0811     struct dvb_ringbuffer ain_rbuf;
0812 
0813 
0814     u8                   *vin_buf;
0815 #define VIN_BUF_SIZE (4*1920*1080)
0816     struct dvb_ringbuffer vin_rbuf;
0817 
0818     unsigned long         exp_val;
0819     int prev_cmd;
0820 
0821     struct ngene_ci       ci;
0822 };
0823 
0824 struct ngene_info {
0825     int   type;
0826 #define NGENE_APP        0
0827 #define NGENE_TERRATEC   1
0828 #define NGENE_SIDEWINDER 2
0829 #define NGENE_RACER      3
0830 #define NGENE_VIPER      4
0831 #define NGENE_PYTHON     5
0832 #define NGENE_VBOX_V1    6
0833 #define NGENE_VBOX_V2    7
0834 
0835     int   fw_version;
0836     bool  msi_supported;
0837     char *name;
0838 
0839     int   io_type[MAX_STREAM];
0840 #define NGENE_IO_NONE    0
0841 #define NGENE_IO_TV      1
0842 #define NGENE_IO_HDTV    2
0843 #define NGENE_IO_TSIN    4
0844 #define NGENE_IO_TSOUT   8
0845 #define NGENE_IO_AIN     16
0846 
0847     void *fe_config[4];
0848     void *tuner_config[4];
0849 
0850     int (*demod_attach[4])(struct ngene_channel *);
0851     int (*tuner_attach[4])(struct ngene_channel *);
0852 
0853     u8    avf[4];
0854     u8    msp[4];
0855     u8    demoda[4];
0856     u8    lnb[4];
0857     int   i2c_access;
0858     u8    ntsc;
0859     u8    tsf[4];
0860     u8    i2s[4];
0861 
0862     int (*gate_ctrl)(struct dvb_frontend *, int);
0863     int (*switch_ctrl)(struct ngene_channel *, int, int);
0864 };
0865 
0866 #ifdef NGENE_V4L
0867 struct ngene_format {
0868     char *name;
0869     int   fourcc;          /* video4linux 2      */
0870     int   btformat;        /* BT848_COLOR_FMT_*  */
0871     int   format;
0872     int   btswap;          /* BT848_COLOR_CTL_*  */
0873     int   depth;           /* bit/pixel          */
0874     int   flags;
0875     int   hshift, vshift;  /* for planar modes   */
0876     int   palette;
0877 };
0878 
0879 #define RESOURCE_OVERLAY       1
0880 #define RESOURCE_VIDEO         2
0881 #define RESOURCE_VBI           4
0882 
0883 struct ngene_buffer {
0884     /* common v4l buffer stuff -- must be first */
0885     struct videobuf_buffer     vb;
0886 
0887     /* ngene specific */
0888     const struct ngene_format *fmt;
0889     int                        tvnorm;
0890     int                        btformat;
0891     int                        btswap;
0892 };
0893 #endif
0894 
0895 
0896 /* Provided by ngene-core.c */
0897 int ngene_probe(struct pci_dev *pci_dev, const struct pci_device_id *id);
0898 void ngene_remove(struct pci_dev *pdev);
0899 void ngene_shutdown(struct pci_dev *pdev);
0900 int ngene_command(struct ngene *dev, struct ngene_command *com);
0901 int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level);
0902 void set_transfer(struct ngene_channel *chan, int state);
0903 void FillTSBuffer(void *Buffer, int Length, u32 Flags);
0904 
0905 /* Provided by ngene-cards.c */
0906 int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type);
0907 
0908 /* Provided by ngene-i2c.c */
0909 int ngene_i2c_init(struct ngene *dev, int dev_nr);
0910 
0911 /* Provided by ngene-dvb.c */
0912 extern struct dvb_device ngene_dvbdev_ci;
0913 void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
0914 void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
0915 int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed);
0916 int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
0917 int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
0918                 int (*start_feed)(struct dvb_demux_feed *),
0919                 int (*stop_feed)(struct dvb_demux_feed *),
0920                 void *priv);
0921 int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
0922                    struct dvb_demux *dvbdemux,
0923                    struct dmx_frontend *hw_frontend,
0924                    struct dmx_frontend *mem_frontend,
0925                    struct dvb_adapter *dvb_adapter);
0926 
0927 #endif
0928 
0929 /*  LocalWords:  Endif
0930  */