GNU Linux-libre 4.14.257-gnu1
[releases.git] / drivers / media / pci / ngene / ngene.h
1 /*
2  * ngene.h: nGene PCIe bridge driver
3  *
4  * Copyright (C) 2005-2007 Micronas
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 only, as published by the Free Software Foundation.
9  *
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * To obtain the license, point your browser to
17  * http://www.gnu.org/copyleft/gpl.html
18  */
19
20 #ifndef _NGENE_H_
21 #define _NGENE_H_
22
23 #include <linux/types.h>
24 #include <linux/sched.h>
25 #include <linux/interrupt.h>
26 #include <linux/i2c.h>
27 #include <asm/dma.h>
28 #include <linux/scatterlist.h>
29
30 #include <linux/dvb/frontend.h>
31
32 #include "dmxdev.h"
33 #include "dvbdev.h"
34 #include "dvb_demux.h"
35 #include "dvb_ca_en50221.h"
36 #include "dvb_frontend.h"
37 #include "dvb_ringbuffer.h"
38 #include "dvb_net.h"
39 #include "cxd2099.h"
40
41 #define DEVICE_NAME "ngene"
42
43 #define NGENE_VID       0x18c3
44 #define NGENE_PID       0x0720
45
46 #ifndef VIDEO_CAP_VC1
47 #define VIDEO_CAP_AVC   128
48 #define VIDEO_CAP_H264  128
49 #define VIDEO_CAP_VC1   256
50 #define VIDEO_CAP_WMV9  256
51 #define VIDEO_CAP_MPEG4 512
52 #endif
53
54 enum STREAM {
55         STREAM_VIDEOIN1 = 0,        /* ITU656 or TS Input */
56         STREAM_VIDEOIN2,
57         STREAM_AUDIOIN1,            /* I2S or SPI Input */
58         STREAM_AUDIOIN2,
59         STREAM_AUDIOOUT,
60         MAX_STREAM
61 };
62
63 enum SMODE_BITS {
64         SMODE_AUDIO_SPDIF = 0x20,
65         SMODE_AVSYNC = 0x10,
66         SMODE_TRANSPORT_STREAM = 0x08,
67         SMODE_AUDIO_CAPTURE = 0x04,
68         SMODE_VBI_CAPTURE = 0x02,
69         SMODE_VIDEO_CAPTURE = 0x01
70 };
71
72 enum STREAM_FLAG_BITS {
73         SFLAG_CHROMA_FORMAT_2COMP  = 0x01, /* Chroma Format : 2's complement */
74         SFLAG_CHROMA_FORMAT_OFFSET = 0x00, /* Chroma Format : Binary offset */
75         SFLAG_ORDER_LUMA_CHROMA    = 0x02, /* Byte order: Y,Cb,Y,Cr */
76         SFLAG_ORDER_CHROMA_LUMA    = 0x00, /* Byte order: Cb,Y,Cr,Y */
77         SFLAG_COLORBAR             = 0x04, /* Select colorbar */
78 };
79
80 #define PROGRAM_ROM     0x0000
81 #define PROGRAM_SRAM    0x1000
82 #define PERIPHERALS0    0x8000
83 #define PERIPHERALS1    0x9000
84 #define SHARED_BUFFER   0xC000
85
86 #define HOST_TO_NGENE    (SHARED_BUFFER+0x0000)
87 #define NGENE_TO_HOST    (SHARED_BUFFER+0x0100)
88 #define NGENE_COMMAND    (SHARED_BUFFER+0x0200)
89 #define NGENE_COMMAND_HI (SHARED_BUFFER+0x0204)
90 #define NGENE_STATUS     (SHARED_BUFFER+0x0208)
91 #define NGENE_STATUS_HI  (SHARED_BUFFER+0x020C)
92 #define NGENE_EVENT      (SHARED_BUFFER+0x0210)
93 #define NGENE_EVENT_HI   (SHARED_BUFFER+0x0214)
94 #define VARIABLES        (SHARED_BUFFER+0x0210)
95
96 #define NGENE_INT_COUNTS       (SHARED_BUFFER+0x0260)
97 #define NGENE_INT_ENABLE       (SHARED_BUFFER+0x0264)
98 #define NGENE_VBI_LINE_COUNT   (SHARED_BUFFER+0x0268)
99
100 #define BUFFER_GP_XMIT  (SHARED_BUFFER+0x0800)
101 #define BUFFER_GP_RECV  (SHARED_BUFFER+0x0900)
102 #define EEPROM_AREA     (SHARED_BUFFER+0x0A00)
103
104 #define SG_V_IN_1       (SHARED_BUFFER+0x0A80)
105 #define SG_VBI_1        (SHARED_BUFFER+0x0B00)
106 #define SG_A_IN_1       (SHARED_BUFFER+0x0B80)
107 #define SG_V_IN_2       (SHARED_BUFFER+0x0C00)
108 #define SG_VBI_2        (SHARED_BUFFER+0x0C80)
109 #define SG_A_IN_2       (SHARED_BUFFER+0x0D00)
110 #define SG_V_OUT        (SHARED_BUFFER+0x0D80)
111 #define SG_A_OUT2       (SHARED_BUFFER+0x0E00)
112
113 #define DATA_A_IN_1     (SHARED_BUFFER+0x0E80)
114 #define DATA_A_IN_2     (SHARED_BUFFER+0x0F00)
115 #define DATA_A_OUT      (SHARED_BUFFER+0x0F80)
116 #define DATA_V_IN_1     (SHARED_BUFFER+0x1000)
117 #define DATA_V_IN_2     (SHARED_BUFFER+0x2000)
118 #define DATA_V_OUT      (SHARED_BUFFER+0x3000)
119
120 #define DATA_FIFO_AREA  (SHARED_BUFFER+0x1000)
121
122 #define TIMESTAMPS      0xA000
123 #define SCRATCHPAD      0xA080
124 #define FORCE_INT       0xA088
125 #define FORCE_NMI       0xA090
126 #define INT_STATUS      0xA0A0
127
128 #define DEV_VER         0x9004
129
130 #define FW_DEBUG_DEFAULT (PROGRAM_SRAM+0x00FF)
131
132 struct SG_ADDR {
133         u64 start;
134         u64 curr;
135         u16 curr_ptr;
136         u16 elements;
137         u32 pad[3];
138 } __attribute__ ((__packed__));
139
140 struct SHARED_MEMORY {
141         /* C000 */
142         u32 HostToNgene[64];
143
144         /* C100 */
145         u32 NgeneToHost[64];
146
147         /* C200 */
148         u64 NgeneCommand;
149         u64 NgeneStatus;
150         u64 NgeneEvent;
151
152         /* C210 */
153         u8 pad1[0xc260 - 0xc218];
154
155         /* C260 */
156         u32 IntCounts;
157         u32 IntEnable;
158
159         /* C268 */
160         u8 pad2[0xd000 - 0xc268];
161
162 } __attribute__ ((__packed__));
163
164 struct BUFFER_STREAM_RESULTS {
165         u32 Clock;           /* Stream time in 100ns units */
166         u16 RemainingLines;  /* Remaining lines in this field.
167                                 0 for complete field */
168         u8  FieldCount;      /* Video field number */
169         u8  Flags;           /* Bit 7 = Done, Bit 6 = seen, Bit 5 = overflow,
170                                 Bit 0 = FieldID */
171         u16 BlockCount;      /* Audio block count (unused) */
172         u8  Reserved[2];
173         u32 DTOUpdate;
174 } __attribute__ ((__packed__));
175
176 struct HW_SCATTER_GATHER_ELEMENT {
177         u64 Address;
178         u32 Length;
179         u32 Reserved;
180 } __attribute__ ((__packed__));
181
182 struct BUFFER_HEADER {
183         u64    Next;
184         struct BUFFER_STREAM_RESULTS SR;
185
186         u32    Number_of_entries_1;
187         u32    Reserved5;
188         u64    Address_of_first_entry_1;
189
190         u32    Number_of_entries_2;
191         u32    Reserved7;
192         u64    Address_of_first_entry_2;
193 } __attribute__ ((__packed__));
194
195 struct EVENT_BUFFER {
196         u32    TimeStamp;
197         u8     GPIOStatus;
198         u8     UARTStatus;
199         u8     RXCharacter;
200         u8     EventStatus;
201         u32    Reserved[2];
202 } __attribute__ ((__packed__));
203
204 /* Firmware commands. */
205
206 enum OPCODES {
207         CMD_NOP = 0,
208         CMD_FWLOAD_PREPARE  = 0x01,
209         CMD_FWLOAD_FINISH   = 0x02,
210         CMD_I2C_READ        = 0x03,
211         CMD_I2C_WRITE       = 0x04,
212
213         CMD_I2C_WRITE_NOSTOP = 0x05,
214         CMD_I2C_CONTINUE_WRITE = 0x06,
215         CMD_I2C_CONTINUE_WRITE_NOSTOP = 0x07,
216
217         CMD_DEBUG_OUTPUT    = 0x09,
218
219         CMD_CONTROL         = 0x10,
220         CMD_CONFIGURE_BUFFER = 0x11,
221         CMD_CONFIGURE_FREE_BUFFER = 0x12,
222
223         CMD_SPI_READ        = 0x13,
224         CMD_SPI_WRITE       = 0x14,
225
226         CMD_MEM_READ        = 0x20,
227         CMD_MEM_WRITE       = 0x21,
228         CMD_SFR_READ        = 0x22,
229         CMD_SFR_WRITE       = 0x23,
230         CMD_IRAM_READ       = 0x24,
231         CMD_IRAM_WRITE      = 0x25,
232         CMD_SET_GPIO_PIN    = 0x26,
233         CMD_SET_GPIO_INT    = 0x27,
234         CMD_CONFIGURE_UART  = 0x28,
235         CMD_WRITE_UART      = 0x29,
236         MAX_CMD
237 };
238
239 enum RESPONSES {
240         OK = 0,
241         ERROR = 1
242 };
243
244 struct FW_HEADER {
245         u8 Opcode;
246         u8 Length;
247 } __attribute__ ((__packed__));
248
249 struct FW_I2C_WRITE {
250         struct FW_HEADER hdr;
251         u8 Device;
252         u8 Data[250];
253 } __attribute__ ((__packed__));
254
255 struct FW_I2C_CONTINUE_WRITE {
256         struct FW_HEADER hdr;
257         u8 Data[250];
258 } __attribute__ ((__packed__));
259
260 struct FW_I2C_READ {
261         struct FW_HEADER hdr;
262         u8 Device;
263         u8 Data[252];    /* followed by two bytes of read data count */
264 } __attribute__ ((__packed__));
265
266 struct FW_SPI_WRITE {
267         struct FW_HEADER hdr;
268         u8 ModeSelect;
269         u8 Data[250];
270 } __attribute__ ((__packed__));
271
272 struct FW_SPI_READ {
273         struct FW_HEADER hdr;
274         u8 ModeSelect;
275         u8 Data[252];    /* followed by two bytes of read data count */
276 } __attribute__ ((__packed__));
277
278 struct FW_FWLOAD_PREPARE {
279         struct FW_HEADER hdr;
280 } __attribute__ ((__packed__));
281
282 struct FW_FWLOAD_FINISH {
283         struct FW_HEADER hdr;
284         u16 Address;     /* address of final block */
285         u16 Length;
286 } __attribute__ ((__packed__));
287
288 /*
289  * Meaning of FW_STREAM_CONTROL::Mode bits:
290  *  Bit 7: Loopback PEXin to PEXout using TVOut channel
291  *  Bit 6: AVLOOP
292  *  Bit 5: Audio select; 0=I2S, 1=SPDIF
293  *  Bit 4: AVSYNC
294  *  Bit 3: Enable transport stream
295  *  Bit 2: Enable audio capture
296  *  Bit 1: Enable ITU-Video VBI capture
297  *  Bit 0: Enable ITU-Video capture
298  *
299  * Meaning of FW_STREAM_CONTROL::Control bits (see UVI1_CTL)
300  *  Bit 7: continuous capture
301  *  Bit 6: capture one field
302  *  Bit 5: capture one frame
303  *  Bit 4: unused
304  *  Bit 3: starting field; 0=odd, 1=even
305  *  Bit 2: sample size; 0=8-bit, 1=10-bit
306  *  Bit 1: data format; 0=UYVY, 1=YUY2
307  *  Bit 0: resets buffer pointers
308 */
309
310 enum FSC_MODE_BITS {
311         SMODE_LOOPBACK          = 0x80,
312         SMODE_AVLOOP            = 0x40,
313         _SMODE_AUDIO_SPDIF      = 0x20,
314         _SMODE_AVSYNC           = 0x10,
315         _SMODE_TRANSPORT_STREAM = 0x08,
316         _SMODE_AUDIO_CAPTURE    = 0x04,
317         _SMODE_VBI_CAPTURE      = 0x02,
318         _SMODE_VIDEO_CAPTURE    = 0x01
319 };
320
321
322 /* Meaning of FW_STREAM_CONTROL::Stream bits:
323  * Bit 3: Audio sample count:  0 = relative, 1 = absolute
324  * Bit 2: color bar select; 1=color bars, 0=CV3 decoder
325  * Bits 1-0: stream select, UVI1, UVI2, TVOUT
326  */
327
328 struct FW_STREAM_CONTROL {
329         struct FW_HEADER hdr;
330         u8     Stream;             /* Stream number (UVI1, UVI2, TVOUT) */
331         u8     Control;            /* Value written to UVI1_CTL */
332         u8     Mode;               /* Controls clock source */
333         u8     SetupDataLen;       /* Length of setup data, MSB=1 write
334                                       backwards */
335         u16    CaptureBlockCount;  /* Blocks (a 256 Bytes) to capture per buffer
336                                       for TS and Audio */
337         u64    Buffer_Address;     /* Address of first buffer header */
338         u16    BytesPerVideoLine;
339         u16    MaxLinesPerField;
340         u16    MinLinesPerField;
341         u16    Reserved_1;
342         u16    BytesPerVBILine;
343         u16    MaxVBILinesPerField;
344         u16    MinVBILinesPerField;
345         u16    SetupDataAddr;      /* ngene relative address of setup data */
346         u8     SetupData[32];      /* setup data */
347 } __attribute__((__packed__));
348
349 #define AUDIO_BLOCK_SIZE    256
350 #define TS_BLOCK_SIZE       256
351
352 struct FW_MEM_READ {
353         struct FW_HEADER hdr;
354         u16   address;
355 } __attribute__ ((__packed__));
356
357 struct FW_MEM_WRITE {
358         struct FW_HEADER hdr;
359         u16   address;
360         u8    data;
361 } __attribute__ ((__packed__));
362
363 struct FW_SFR_IRAM_READ {
364         struct FW_HEADER hdr;
365         u8    address;
366 } __attribute__ ((__packed__));
367
368 struct FW_SFR_IRAM_WRITE {
369         struct FW_HEADER hdr;
370         u8    address;
371         u8    data;
372 } __attribute__ ((__packed__));
373
374 struct FW_SET_GPIO_PIN {
375         struct FW_HEADER hdr;
376         u8    select;
377 } __attribute__ ((__packed__));
378
379 struct FW_SET_GPIO_INT {
380         struct FW_HEADER hdr;
381         u8    select;
382 } __attribute__ ((__packed__));
383
384 struct FW_SET_DEBUGMODE {
385         struct FW_HEADER hdr;
386         u8   debug_flags;
387 } __attribute__ ((__packed__));
388
389 struct FW_CONFIGURE_BUFFERS {
390         struct FW_HEADER hdr;
391         u8   config;
392 } __attribute__ ((__packed__));
393
394 enum _BUFFER_CONFIGS {
395         /* 4k UVI1, 4k UVI2, 2k AUD1, 2k AUD2  (standard usage) */
396         BUFFER_CONFIG_4422 = 0,
397         /* 3k UVI1, 3k UVI2, 3k AUD1, 3k AUD2  (4x TS input usage) */
398         BUFFER_CONFIG_3333 = 1,
399         /* 8k UVI1, 0k UVI2, 2k AUD1, 2k I2SOut  (HDTV decoder usage) */
400         BUFFER_CONFIG_8022 = 2,
401         BUFFER_CONFIG_FW17 = 255, /* Use new FW 17 command */
402 };
403
404 struct FW_CONFIGURE_FREE_BUFFERS {
405         struct FW_HEADER hdr;
406         struct {
407                 u8   UVI1_BufferLength;
408                 u8   UVI2_BufferLength;
409                 u8   TVO_BufferLength;
410                 u8   AUD1_BufferLength;
411                 u8   AUD2_BufferLength;
412                 u8   TVA_BufferLength;
413         } __packed config;
414 } __attribute__ ((__packed__));
415
416 struct FW_CONFIGURE_UART {
417         struct FW_HEADER hdr;
418         u8 UartControl;
419 } __attribute__ ((__packed__));
420
421 enum _UART_CONFIG {
422         _UART_BAUDRATE_19200 = 0,
423         _UART_BAUDRATE_9600  = 1,
424         _UART_BAUDRATE_4800  = 2,
425         _UART_BAUDRATE_2400  = 3,
426         _UART_RX_ENABLE      = 0x40,
427         _UART_TX_ENABLE      = 0x80,
428 };
429
430 struct FW_WRITE_UART {
431         struct FW_HEADER hdr;
432         u8 Data[252];
433 } __attribute__ ((__packed__));
434
435
436 struct ngene_command {
437         u32 in_len;
438         u32 out_len;
439         union {
440                 u32                              raw[64];
441                 u8                               raw8[256];
442                 struct FW_HEADER                 hdr;
443                 struct FW_I2C_WRITE              I2CWrite;
444                 struct FW_I2C_CONTINUE_WRITE     I2CContinueWrite;
445                 struct FW_I2C_READ               I2CRead;
446                 struct FW_STREAM_CONTROL         StreamControl;
447                 struct FW_FWLOAD_PREPARE         FWLoadPrepare;
448                 struct FW_FWLOAD_FINISH          FWLoadFinish;
449                 struct FW_MEM_READ               MemoryRead;
450                 struct FW_MEM_WRITE              MemoryWrite;
451                 struct FW_SFR_IRAM_READ          SfrIramRead;
452                 struct FW_SFR_IRAM_WRITE         SfrIramWrite;
453                 struct FW_SPI_WRITE              SPIWrite;
454                 struct FW_SPI_READ               SPIRead;
455                 struct FW_SET_GPIO_PIN           SetGpioPin;
456                 struct FW_SET_GPIO_INT           SetGpioInt;
457                 struct FW_SET_DEBUGMODE          SetDebugMode;
458                 struct FW_CONFIGURE_BUFFERS      ConfigureBuffers;
459                 struct FW_CONFIGURE_FREE_BUFFERS ConfigureFreeBuffers;
460                 struct FW_CONFIGURE_UART         ConfigureUart;
461                 struct FW_WRITE_UART             WriteUart;
462         } cmd;
463 } __attribute__ ((__packed__));
464
465 #define NGENE_INTERFACE_VERSION 0x103
466 #define MAX_VIDEO_BUFFER_SIZE   (417792) /* 288*1440 rounded up to next page */
467 #define MAX_AUDIO_BUFFER_SIZE     (8192) /* Gives room for about 23msec@48KHz */
468 #define MAX_VBI_BUFFER_SIZE      (28672) /* 1144*18 rounded up to next page */
469 #define MAX_TS_BUFFER_SIZE       (98304) /* 512*188 rounded up to next page */
470 #define MAX_HDTV_BUFFER_SIZE   (2080768) /* 541*1920*2 rounded up to next page
471                                             Max: (1920x1080i60) */
472
473 #define OVERFLOW_BUFFER_SIZE    (8192)
474
475 #define RING_SIZE_VIDEO     4
476 #define RING_SIZE_AUDIO     8
477 #define RING_SIZE_TS        8
478
479 #define NUM_SCATTER_GATHER_ENTRIES  8
480
481 #define MAX_DMA_LENGTH (((MAX_VIDEO_BUFFER_SIZE + MAX_VBI_BUFFER_SIZE) * \
482                         RING_SIZE_VIDEO * 2) + \
483                         (MAX_AUDIO_BUFFER_SIZE * RING_SIZE_AUDIO * 2) + \
484                         (MAX_TS_BUFFER_SIZE * RING_SIZE_TS * 4) + \
485                         (RING_SIZE_VIDEO * PAGE_SIZE * 2) + \
486                         (RING_SIZE_AUDIO * PAGE_SIZE * 2) + \
487                         (RING_SIZE_TS    * PAGE_SIZE * 4) + \
488                          8 * PAGE_SIZE + OVERFLOW_BUFFER_SIZE + PAGE_SIZE)
489
490 #define EVENT_QUEUE_SIZE    16
491
492 /* Gathers the current state of a single channel. */
493
494 struct SBufferHeader {
495         struct BUFFER_HEADER   ngeneBuffer; /* Physical descriptor */
496         struct SBufferHeader  *Next;
497         void                  *Buffer1;
498         struct HW_SCATTER_GATHER_ELEMENT *scList1;
499         void                  *Buffer2;
500         struct HW_SCATTER_GATHER_ELEMENT *scList2;
501 };
502
503 /* Sizeof SBufferHeader aligned to next 64 Bit boundary (hw restriction) */
504 #define SIZEOF_SBufferHeader ((sizeof(struct SBufferHeader) + 63) & ~63)
505
506 enum HWSTATE {
507         HWSTATE_STOP,
508         HWSTATE_STARTUP,
509         HWSTATE_RUN,
510         HWSTATE_PAUSE,
511 };
512
513 enum KSSTATE {
514         KSSTATE_STOP,
515         KSSTATE_ACQUIRE,
516         KSSTATE_PAUSE,
517         KSSTATE_RUN,
518 };
519
520 struct SRingBufferDescriptor {
521         struct SBufferHeader *Head; /* Points to first buffer in ring buffer
522                                        structure*/
523         u64   PAHead;         /* Physical address of first buffer */
524         u32   MemSize;        /* Memory size of allocated ring buffers
525                                  (needed for freeing) */
526         u32   NumBuffers;     /* Number of buffers in the ring */
527         u32   Buffer1Length;  /* Allocated length of Buffer 1 */
528         u32   Buffer2Length;  /* Allocated length of Buffer 2 */
529         void *SCListMem;      /* Memory to hold scatter gather lists for this
530                                  ring */
531         u64   PASCListMem;    /* Physical address  .. */
532         u32   SCListMemSize;  /* Size of this memory */
533 };
534
535 enum STREAMMODEFLAGS {
536         StreamMode_NONE   = 0, /* Stream not used */
537         StreamMode_ANALOG = 1, /* Analog: Stream 0,1 = Video, 2,3 = Audio */
538         StreamMode_TSIN   = 2, /* Transport stream input (all) */
539         StreamMode_HDTV   = 4, /* HDTV: Maximum 1920x1080p30,1920x1080i60
540                                   (only stream 0) */
541         StreamMode_TSOUT  = 8, /* Transport stream output (only stream 3) */
542 };
543
544
545 enum BufferExchangeFlags {
546         BEF_EVEN_FIELD   = 0x00000001,
547         BEF_CONTINUATION = 0x00000002,
548         BEF_MORE_DATA    = 0x00000004,
549         BEF_OVERFLOW     = 0x00000008,
550         DF_SWAP32        = 0x00010000,
551 };
552
553 typedef void *(IBufferExchange)(void *, void *, u32, u32, u32);
554
555 struct MICI_STREAMINFO {
556         IBufferExchange    *pExchange;
557         IBufferExchange    *pExchangeVBI;     /* Secondary (VBI, ancillary) */
558         u8  Stream;
559         u8  Flags;
560         u8  Mode;
561         u8  Reserved;
562         u16 nLinesVideo;
563         u16 nBytesPerLineVideo;
564         u16 nLinesVBI;
565         u16 nBytesPerLineVBI;
566         u32 CaptureLength;    /* Used for audio and transport stream */
567 };
568
569 /****************************************************************************/
570 /* STRUCTS ******************************************************************/
571 /****************************************************************************/
572
573 /* sound hardware definition */
574 #define MIXER_ADDR_TVTUNER      0
575 #define MIXER_ADDR_LAST         0
576
577 struct ngene_channel;
578
579 /*struct sound chip*/
580
581 struct mychip {
582         struct ngene_channel *chan;
583         struct snd_card *card;
584         struct pci_dev *pci;
585         struct snd_pcm_substream *substream;
586         struct snd_pcm *pcm;
587         unsigned long port;
588         int irq;
589         spinlock_t mixer_lock;
590         spinlock_t lock;
591         int mixer_volume[MIXER_ADDR_LAST + 1][2];
592         int capture_source[MIXER_ADDR_LAST + 1][2];
593 };
594
595 #ifdef NGENE_V4L
596 struct ngene_overlay {
597         int                    tvnorm;
598         struct v4l2_rect       w;
599         enum v4l2_field        field;
600         struct v4l2_clip       *clips;
601         int                    nclips;
602         int                    setup_ok;
603 };
604
605 struct ngene_tvnorm {
606         int   v4l2_id;
607         char  *name;
608         u16   swidth, sheight; /* scaled standard width, height */
609         int   tuner_norm;
610         int   soundstd;
611 };
612
613 struct ngene_vopen {
614         struct ngene_channel      *ch;
615         enum v4l2_priority         prio;
616         int                        width;
617         int                        height;
618         int                        depth;
619         struct videobuf_queue      vbuf_q;
620         struct videobuf_queue      vbi;
621         int                        fourcc;
622         int                        picxcount;
623         int                        resources;
624         enum v4l2_buf_type         type;
625         const struct ngene_format *fmt;
626
627         const struct ngene_format *ovfmt;
628         struct ngene_overlay       ov;
629 };
630 #endif
631
632 struct ngene_channel {
633         struct device         device;
634         struct i2c_adapter    i2c_adapter;
635
636         struct ngene         *dev;
637         int                   number;
638         int                   type;
639         int                   mode;
640         bool                  has_adapter;
641         bool                  has_demux;
642         int                   demod_type;
643         int (*gate_ctrl)(struct dvb_frontend *, int);
644
645         struct dvb_frontend  *fe;
646         struct dvb_frontend  *fe2;
647         struct dmxdev         dmxdev;
648         struct dvb_demux      demux;
649         struct dvb_net        dvbnet;
650         struct dmx_frontend   hw_frontend;
651         struct dmx_frontend   mem_frontend;
652         int                   users;
653         struct video_device  *v4l_dev;
654         struct dvb_device    *ci_dev;
655         struct tasklet_struct demux_tasklet;
656
657         struct SBufferHeader *nextBuffer;
658         enum KSSTATE          State;
659         enum HWSTATE          HWState;
660         u8                    Stream;
661         u8                    Flags;
662         u8                    Mode;
663         IBufferExchange      *pBufferExchange;
664         IBufferExchange      *pBufferExchange2;
665
666         spinlock_t            state_lock;
667         u16                   nLines;
668         u16                   nBytesPerLine;
669         u16                   nVBILines;
670         u16                   nBytesPerVBILine;
671         u16                   itumode;
672         u32                   Capture1Length;
673         u32                   Capture2Length;
674         struct SRingBufferDescriptor RingBuffer;
675         struct SRingBufferDescriptor TSRingBuffer;
676         struct SRingBufferDescriptor TSIdleBuffer;
677
678         u32                   DataFormatFlags;
679
680         int                   AudioDTOUpdated;
681         u32                   AudioDTOValue;
682
683         int (*set_tone)(struct dvb_frontend *, enum fe_sec_tone_mode);
684         u8 lnbh;
685
686         /* stuff from analog driver */
687
688         int minor;
689         struct mychip        *mychip;
690         struct snd_card      *soundcard;
691         u8                   *evenbuffer;
692         u8                    dma_on;
693         int                   soundstreamon;
694         int                   audiomute;
695         int                   soundbuffisallocated;
696         int                   sndbuffflag;
697         int                   tun_rdy;
698         int                   dec_rdy;
699         int                   tun_dec_rdy;
700         int                   lastbufferflag;
701
702         struct ngene_tvnorm  *tvnorms;
703         int                   tvnorm_num;
704         int                   tvnorm;
705
706 #ifdef NGENE_V4L
707         int                   videousers;
708         struct v4l2_prio_state prio;
709         struct ngene_vopen    init;
710         int                   resources;
711         struct v4l2_framebuffer fbuf;
712         struct ngene_buffer  *screen;     /* overlay             */
713         struct list_head      capture;    /* video capture queue */
714         spinlock_t s_lock;
715         struct semaphore reslock;
716 #endif
717
718         int running;
719 };
720
721
722 struct ngene_ci {
723         struct device         device;
724         struct i2c_adapter    i2c_adapter;
725
726         struct ngene         *dev;
727         struct dvb_ca_en50221 *en;
728 };
729
730 struct ngene;
731
732 typedef void (rx_cb_t)(struct ngene *, u32, u8);
733 typedef void (tx_cb_t)(struct ngene *, u32);
734
735 struct ngene {
736         int                   nr;
737         struct pci_dev       *pci_dev;
738         unsigned char __iomem *iomem;
739
740         /*struct i2c_adapter  i2c_adapter;*/
741
742         u32                   device_version;
743         u32                   fw_interface_version;
744         u32                   icounts;
745         bool                  msi_enabled;
746         bool                  cmd_timeout_workaround;
747
748         u8                   *CmdDoneByte;
749         int                   BootFirmware;
750         void                 *OverflowBuffer;
751         dma_addr_t            PAOverflowBuffer;
752         void                 *FWInterfaceBuffer;
753         dma_addr_t            PAFWInterfaceBuffer;
754         u8                   *ngenetohost;
755         u8                   *hosttongene;
756
757         struct EVENT_BUFFER   EventQueue[EVENT_QUEUE_SIZE];
758         int                   EventQueueOverflowCount;
759         int                   EventQueueOverflowFlag;
760         struct tasklet_struct event_tasklet;
761         struct EVENT_BUFFER  *EventBuffer;
762         int                   EventQueueWriteIndex;
763         int                   EventQueueReadIndex;
764
765         wait_queue_head_t     cmd_wq;
766         int                   cmd_done;
767         struct mutex          cmd_mutex;
768         struct mutex          stream_mutex;
769         struct semaphore      pll_mutex;
770         struct mutex          i2c_switch_mutex;
771         int                   i2c_current_channel;
772         int                   i2c_current_bus;
773         spinlock_t            cmd_lock;
774
775         struct dvb_adapter    adapter[MAX_STREAM];
776         struct dvb_adapter    *first_adapter; /* "one_adapter" modprobe opt */
777         struct ngene_channel  channel[MAX_STREAM];
778
779         struct ngene_info    *card_info;
780
781         tx_cb_t              *TxEventNotify;
782         rx_cb_t              *RxEventNotify;
783         int                   tx_busy;
784         wait_queue_head_t     tx_wq;
785         wait_queue_head_t     rx_wq;
786 #define UART_RBUF_LEN 4096
787         u8                    uart_rbuf[UART_RBUF_LEN];
788         int                   uart_rp, uart_wp;
789
790 #define TS_FILLER  0x6f
791
792         u8                   *tsout_buf;
793 #define TSOUT_BUF_SIZE (512*188*8)
794         struct dvb_ringbuffer tsout_rbuf;
795
796         u8                   *tsin_buf;
797 #define TSIN_BUF_SIZE (512*188*8)
798         struct dvb_ringbuffer tsin_rbuf;
799
800         u8                   *ain_buf;
801 #define AIN_BUF_SIZE (128*1024)
802         struct dvb_ringbuffer ain_rbuf;
803
804
805         u8                   *vin_buf;
806 #define VIN_BUF_SIZE (4*1920*1080)
807         struct dvb_ringbuffer vin_rbuf;
808
809         unsigned long         exp_val;
810         int prev_cmd;
811
812         struct ngene_ci       ci;
813 };
814
815 struct ngene_info {
816         int   type;
817 #define NGENE_APP        0
818 #define NGENE_TERRATEC   1
819 #define NGENE_SIDEWINDER 2
820 #define NGENE_RACER      3
821 #define NGENE_VIPER      4
822 #define NGENE_PYTHON     5
823 #define NGENE_VBOX_V1    6
824 #define NGENE_VBOX_V2    7
825
826         int   fw_version;
827         bool  msi_supported;
828         char *name;
829
830         int   io_type[MAX_STREAM];
831 #define NGENE_IO_NONE    0
832 #define NGENE_IO_TV      1
833 #define NGENE_IO_HDTV    2
834 #define NGENE_IO_TSIN    4
835 #define NGENE_IO_TSOUT   8
836 #define NGENE_IO_AIN     16
837
838         void *fe_config[4];
839         void *tuner_config[4];
840
841         int (*demod_attach[4])(struct ngene_channel *);
842         int (*tuner_attach[4])(struct ngene_channel *);
843
844         u8    avf[4];
845         u8    msp[4];
846         u8    demoda[4];
847         u8    lnb[4];
848         int   i2c_access;
849         u8    ntsc;
850         u8    tsf[4];
851         u8    i2s[4];
852
853         int (*gate_ctrl)(struct dvb_frontend *, int);
854         int (*switch_ctrl)(struct ngene_channel *, int, int);
855 };
856
857 #ifdef NGENE_V4L
858 struct ngene_format {
859         char *name;
860         int   fourcc;          /* video4linux 2      */
861         int   btformat;        /* BT848_COLOR_FMT_*  */
862         int   format;
863         int   btswap;          /* BT848_COLOR_CTL_*  */
864         int   depth;           /* bit/pixel          */
865         int   flags;
866         int   hshift, vshift;  /* for planar modes   */
867         int   palette;
868 };
869
870 #define RESOURCE_OVERLAY       1
871 #define RESOURCE_VIDEO         2
872 #define RESOURCE_VBI           4
873
874 struct ngene_buffer {
875         /* common v4l buffer stuff -- must be first */
876         struct videobuf_buffer     vb;
877
878         /* ngene specific */
879         const struct ngene_format *fmt;
880         int                        tvnorm;
881         int                        btformat;
882         int                        btswap;
883 };
884 #endif
885
886
887 /* Provided by ngene-core.c */
888 int ngene_probe(struct pci_dev *pci_dev, const struct pci_device_id *id);
889 void ngene_remove(struct pci_dev *pdev);
890 void ngene_shutdown(struct pci_dev *pdev);
891 int ngene_command(struct ngene *dev, struct ngene_command *com);
892 int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level);
893 void set_transfer(struct ngene_channel *chan, int state);
894 void FillTSBuffer(void *Buffer, int Length, u32 Flags);
895
896 /* Provided by ngene-i2c.c */
897 int ngene_i2c_init(struct ngene *dev, int dev_nr);
898
899 /* Provided by ngene-dvb.c */
900 extern struct dvb_device ngene_dvbdev_ci;
901 void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
902 void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
903 int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed);
904 int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
905 int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
906                             int (*start_feed)(struct dvb_demux_feed *),
907                             int (*stop_feed)(struct dvb_demux_feed *),
908                             void *priv);
909 int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
910                                struct dvb_demux *dvbdemux,
911                                struct dmx_frontend *hw_frontend,
912                                struct dmx_frontend *mem_frontend,
913                                struct dvb_adapter *dvb_adapter);
914
915 #endif
916
917 /*  LocalWords:  Endif
918  */