Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ngene.h
Go to the documentation of this file.
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  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA
21  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22  */
23 
24 #ifndef _NGENE_H_
25 #define _NGENE_H_
26 
27 #include <linux/types.h>
28 #include <linux/sched.h>
29 #include <linux/interrupt.h>
30 #include <linux/i2c.h>
31 #include <asm/dma.h>
32 #include <linux/scatterlist.h>
33 
34 #include <linux/dvb/frontend.h>
35 
36 #include "dmxdev.h"
37 #include "dvbdev.h"
38 #include "dvb_demux.h"
39 #include "dvb_ca_en50221.h"
40 #include "dvb_frontend.h"
41 #include "dvb_ringbuffer.h"
42 #include "dvb_net.h"
43 #include "cxd2099.h"
44 
45 #define DEVICE_NAME "ngene"
46 
47 #define NGENE_VID 0x18c3
48 #define NGENE_PID 0x0720
49 
50 #ifndef VIDEO_CAP_VC1
51 #define VIDEO_CAP_AVC 128
52 #define VIDEO_CAP_H264 128
53 #define VIDEO_CAP_VC1 256
54 #define VIDEO_CAP_WMV9 256
55 #define VIDEO_CAP_MPEG4 512
56 #endif
57 
58 enum STREAM {
59  STREAM_VIDEOIN1 = 0, /* ITU656 or TS Input */
61  STREAM_AUDIOIN1, /* I2S or SPI Input */
65 };
66 
67 enum SMODE_BITS {
69  SMODE_AVSYNC = 0x10,
74 };
75 
77  SFLAG_CHROMA_FORMAT_2COMP = 0x01, /* Chroma Format : 2's complement */
78  SFLAG_CHROMA_FORMAT_OFFSET = 0x00, /* Chroma Format : Binary offset */
79  SFLAG_ORDER_LUMA_CHROMA = 0x02, /* Byte order: Y,Cb,Y,Cr */
80  SFLAG_ORDER_CHROMA_LUMA = 0x00, /* Byte order: Cb,Y,Cr,Y */
81  SFLAG_COLORBAR = 0x04, /* Select colorbar */
82 };
83 
84 #define PROGRAM_ROM 0x0000
85 #define PROGRAM_SRAM 0x1000
86 #define PERIPHERALS0 0x8000
87 #define PERIPHERALS1 0x9000
88 #define SHARED_BUFFER 0xC000
89 
90 #define HOST_TO_NGENE (SHARED_BUFFER+0x0000)
91 #define NGENE_TO_HOST (SHARED_BUFFER+0x0100)
92 #define NGENE_COMMAND (SHARED_BUFFER+0x0200)
93 #define NGENE_COMMAND_HI (SHARED_BUFFER+0x0204)
94 #define NGENE_STATUS (SHARED_BUFFER+0x0208)
95 #define NGENE_STATUS_HI (SHARED_BUFFER+0x020C)
96 #define NGENE_EVENT (SHARED_BUFFER+0x0210)
97 #define NGENE_EVENT_HI (SHARED_BUFFER+0x0214)
98 #define VARIABLES (SHARED_BUFFER+0x0210)
99 
100 #define NGENE_INT_COUNTS (SHARED_BUFFER+0x0260)
101 #define NGENE_INT_ENABLE (SHARED_BUFFER+0x0264)
102 #define NGENE_VBI_LINE_COUNT (SHARED_BUFFER+0x0268)
103 
104 #define BUFFER_GP_XMIT (SHARED_BUFFER+0x0800)
105 #define BUFFER_GP_RECV (SHARED_BUFFER+0x0900)
106 #define EEPROM_AREA (SHARED_BUFFER+0x0A00)
107 
108 #define SG_V_IN_1 (SHARED_BUFFER+0x0A80)
109 #define SG_VBI_1 (SHARED_BUFFER+0x0B00)
110 #define SG_A_IN_1 (SHARED_BUFFER+0x0B80)
111 #define SG_V_IN_2 (SHARED_BUFFER+0x0C00)
112 #define SG_VBI_2 (SHARED_BUFFER+0x0C80)
113 #define SG_A_IN_2 (SHARED_BUFFER+0x0D00)
114 #define SG_V_OUT (SHARED_BUFFER+0x0D80)
115 #define SG_A_OUT2 (SHARED_BUFFER+0x0E00)
116 
117 #define DATA_A_IN_1 (SHARED_BUFFER+0x0E80)
118 #define DATA_A_IN_2 (SHARED_BUFFER+0x0F00)
119 #define DATA_A_OUT (SHARED_BUFFER+0x0F80)
120 #define DATA_V_IN_1 (SHARED_BUFFER+0x1000)
121 #define DATA_V_IN_2 (SHARED_BUFFER+0x2000)
122 #define DATA_V_OUT (SHARED_BUFFER+0x3000)
123 
124 #define DATA_FIFO_AREA (SHARED_BUFFER+0x1000)
125 
126 #define TIMESTAMPS 0xA000
127 #define SCRATCHPAD 0xA080
128 #define FORCE_INT 0xA088
129 #define FORCE_NMI 0xA090
130 #define INT_STATUS 0xA0A0
131 
132 #define DEV_VER 0x9004
133 
134 #define FW_DEBUG_DEFAULT (PROGRAM_SRAM+0x00FF)
135 
136 struct SG_ADDR {
141  u32 pad[3];
142 } __attribute__ ((__packed__));
145  /* C000 */
148  /* C100 */
150 
151  /* C200 */
155 
156  /* C210 */
157  u8 pad1[0xc260 - 0xc218];
158 
159  /* C260 */
162 
163  /* C268 */
164  u8 pad2[0xd000 - 0xc268];
165 
166 } __attribute__ ((__packed__));
167 
169  u32 Clock; /* Stream time in 100ns units */
170  u16 RemainingLines; /* Remaining lines in this field.
171  0 for complete field */
172  u8 FieldCount; /* Video field number */
173  u8 Flags; /* Bit 7 = Done, Bit 6 = seen, Bit 5 = overflow,
174  Bit 0 = FieldID */
175  u16 BlockCount; /* Audio block count (unused) */
178 } __attribute__ ((__packed__));
184 } __attribute__ ((__packed__));
189 
193 
197 } __attribute__ ((__packed__));
199 struct EVENT_BUFFER {
206 } __attribute__ ((__packed__));
208 /* Firmware commands. */
210 enum OPCODES {
211  CMD_NOP = 0,
214  CMD_I2C_READ = 0x03,
216 
220 
222 
223  CMD_CONTROL = 0x10,
226 
227  CMD_SPI_READ = 0x13,
229 
230  CMD_MEM_READ = 0x20,
232  CMD_SFR_READ = 0x22,
241 };
242 
243 enum RESPONSES {
244  OK = 0,
245  ERROR = 1
246 };
247 
248 struct FW_HEADER {
251 } __attribute__ ((__packed__));
253 struct FW_I2C_WRITE {
254  struct FW_HEADER hdr;
256  u8 Data[250];
257 } __attribute__ ((__packed__));
260  struct FW_HEADER hdr;
261  u8 Data[250];
262 } __attribute__ ((__packed__));
263 
264 struct FW_I2C_READ {
265  struct FW_HEADER hdr;
267  u8 Data[252]; /* followed by two bytes of read data count */
268 } __attribute__ ((__packed__));
269 
270 struct FW_SPI_WRITE {
271  struct FW_HEADER hdr;
273  u8 Data[250];
274 } __attribute__ ((__packed__));
275 
276 struct FW_SPI_READ {
277  struct FW_HEADER hdr;
279  u8 Data[252]; /* followed by two bytes of read data count */
280 } __attribute__ ((__packed__));
281 
283  struct FW_HEADER hdr;
284 } __attribute__ ((__packed__));
285 
287  struct FW_HEADER hdr;
288  u16 Address; /* address of final block */
290 } __attribute__ ((__packed__));
291 
292 /*
293  * Meaning of FW_STREAM_CONTROL::Mode bits:
294  * Bit 7: Loopback PEXin to PEXout using TVOut channel
295  * Bit 6: AVLOOP
296  * Bit 5: Audio select; 0=I2S, 1=SPDIF
297  * Bit 4: AVSYNC
298  * Bit 3: Enable transport stream
299  * Bit 2: Enable audio capture
300  * Bit 1: Enable ITU-Video VBI capture
301  * Bit 0: Enable ITU-Video capture
302  *
303  * Meaning of FW_STREAM_CONTROL::Control bits (see UVI1_CTL)
304  * Bit 7: continuous capture
305  * Bit 6: capture one field
306  * Bit 5: capture one frame
307  * Bit 4: unused
308  * Bit 3: starting field; 0=odd, 1=even
309  * Bit 2: sample size; 0=8-bit, 1=10-bit
310  * Bit 1: data format; 0=UYVY, 1=YUY2
311  * Bit 0: resets buffer pointers
312 */
313 
316  SMODE_AVLOOP = 0x40,
323 };
324 
325 
326 /* Meaning of FW_STREAM_CONTROL::Stream bits:
327  * Bit 3: Audio sample count: 0 = relative, 1 = absolute
328  * Bit 2: color bar select; 1=color bars, 0=CV3 decoder
329  * Bits 1-0: stream select, UVI1, UVI2, TVOUT
330  */
331 
333  struct FW_HEADER hdr;
334  u8 Stream; /* Stream number (UVI1, UVI2, TVOUT) */
335  u8 Control; /* Value written to UVI1_CTL */
336  u8 Mode; /* Controls clock source */
337  u8 SetupDataLen; /* Length of setup data, MSB=1 write
338  backwards */
339  u16 CaptureBlockCount; /* Blocks (a 256 Bytes) to capture per buffer
340  for TS and Audio */
341  u64 Buffer_Address; /* Address of first buffer header */
349  u16 SetupDataAddr; /* ngene relative address of setup data */
350  u8 SetupData[32]; /* setup data */
351 } __attribute__((__packed__));
352 
353 #define AUDIO_BLOCK_SIZE 256
354 #define TS_BLOCK_SIZE 256
356 struct FW_MEM_READ {
357  struct FW_HEADER hdr;
359 } __attribute__ ((__packed__));
361 struct FW_MEM_WRITE {
362  struct FW_HEADER hdr;
365 } __attribute__ ((__packed__));
368  struct FW_HEADER hdr;
370 } __attribute__ ((__packed__));
371 
373  struct FW_HEADER hdr;
376 } __attribute__ ((__packed__));
377 
379  struct FW_HEADER hdr;
381 } __attribute__ ((__packed__));
382 
384  struct FW_HEADER hdr;
386 } __attribute__ ((__packed__));
387 
389  struct FW_HEADER hdr;
391 } __attribute__ ((__packed__));
392 
394  struct FW_HEADER hdr;
396 } __attribute__ ((__packed__));
397 
399  /* 4k UVI1, 4k UVI2, 2k AUD1, 2k AUD2 (standard usage) */
401  /* 3k UVI1, 3k UVI2, 3k AUD1, 3k AUD2 (4x TS input usage) */
403  /* 8k UVI1, 0k UVI2, 2k AUD1, 2k I2SOut (HDTV decoder usage) */
405  BUFFER_CONFIG_FW17 = 255, /* Use new FW 17 command */
406 };
407 
409  struct FW_HEADER hdr;
416 } __attribute__ ((__packed__));
417 
419  struct FW_HEADER hdr;
421 } __attribute__ ((__packed__));
430 };
431 
433  struct FW_HEADER hdr;
434  u8 Data[252];
435 } __attribute__ ((__packed__));
436 
437 
441  union {
442  u32 raw[64];
443  u8 raw8[256];
444  struct FW_HEADER hdr;
464  } cmd;
465 } __attribute__ ((__packed__));
467 #define NGENE_INTERFACE_VERSION 0x103
468 #define MAX_VIDEO_BUFFER_SIZE (417792) /* 288*1440 rounded up to next page */
469 #define MAX_AUDIO_BUFFER_SIZE (8192) /* Gives room for about 23msec@48KHz */
470 #define MAX_VBI_BUFFER_SIZE (28672) /* 1144*18 rounded up to next page */
471 #define MAX_TS_BUFFER_SIZE (98304) /* 512*188 rounded up to next page */
472 #define MAX_HDTV_BUFFER_SIZE (2080768) /* 541*1920*2 rounded up to next page
473  Max: (1920x1080i60) */
475 #define OVERFLOW_BUFFER_SIZE (8192)
477 #define RING_SIZE_VIDEO 4
478 #define RING_SIZE_AUDIO 8
479 #define RING_SIZE_TS 8
481 #define NUM_SCATTER_GATHER_ENTRIES 8
483 #define MAX_DMA_LENGTH (((MAX_VIDEO_BUFFER_SIZE + MAX_VBI_BUFFER_SIZE) * \
484  RING_SIZE_VIDEO * 2) + \
485  (MAX_AUDIO_BUFFER_SIZE * RING_SIZE_AUDIO * 2) + \
486  (MAX_TS_BUFFER_SIZE * RING_SIZE_TS * 4) + \
487  (RING_SIZE_VIDEO * PAGE_SIZE * 2) + \
488  (RING_SIZE_AUDIO * PAGE_SIZE * 2) + \
489  (RING_SIZE_TS * PAGE_SIZE * 4) + \
490  8 * PAGE_SIZE + OVERFLOW_BUFFER_SIZE + PAGE_SIZE)
492 #define EVENT_QUEUE_SIZE 16
493 
494 /* Gathers the current state of a single channel. */
497  struct BUFFER_HEADER ngeneBuffer; /* Physical descriptor */
499  void *Buffer1;
501  void *Buffer2;
503 };
504 
505 /* Sizeof SBufferHeader aligned to next 64 Bit boundary (hw restriction) */
506 #define SIZEOF_SBufferHeader ((sizeof(struct SBufferHeader) + 63) & ~63)
508 enum HWSTATE {
513 };
515 enum KSSTATE {
519  KSSTATE_RUN,
520 };
523  struct SBufferHeader *Head; /* Points to first buffer in ring buffer
524  structure*/
525  u64 PAHead; /* Physical address of first buffer */
526  u32 MemSize; /* Memory size of allocated ring buffers
527  (needed for freeing) */
528  u32 NumBuffers; /* Number of buffers in the ring */
529  u32 Buffer1Length; /* Allocated length of Buffer 1 */
530  u32 Buffer2Length; /* Allocated length of Buffer 2 */
531  void *SCListMem; /* Memory to hold scatter gather lists for this
532  ring */
533  u64 PASCListMem; /* Physical address .. */
534  u32 SCListMemSize; /* Size of this memory */
535 };
538  StreamMode_NONE = 0, /* Stream not used */
539  StreamMode_ANALOG = 1, /* Analog: Stream 0,1 = Video, 2,3 = Audio */
540  StreamMode_TSIN = 2, /* Transport stream input (all) */
541  StreamMode_HDTV = 4, /* HDTV: Maximum 1920x1080p30,1920x1080i60
542  (only stream 0) */
543  StreamMode_TSOUT = 8, /* Transport stream output (only stream 3) */
544 };
545 
548  BEF_EVEN_FIELD = 0x00000001,
549  BEF_CONTINUATION = 0x00000002,
550  BEF_MORE_DATA = 0x00000004,
551  BEF_OVERFLOW = 0x00000008,
552  DF_SWAP32 = 0x00010000,
553 };
555 typedef void *(IBufferExchange)(void *, void *, u32, u32, u32);
559  IBufferExchange *pExchangeVBI; /* Secondary (VBI, ancillary) */
568  u32 CaptureLength; /* Used for audio and transport stream */
569 };
570 
571 /****************************************************************************/
572 /* STRUCTS ******************************************************************/
573 /****************************************************************************/
574 
575 /* sound hardware definition */
576 #define MIXER_ADDR_TVTUNER 0
577 #define MIXER_ADDR_LAST 0
578 
579 struct ngene_channel;
580 
581 /*struct sound chip*/
583 struct mychip {
585  struct snd_card *card;
586  struct pci_dev *pci;
588  struct snd_pcm *pcm;
589  unsigned long port;
590  int irq;
594  int capture_source[MIXER_ADDR_LAST + 1][2];
595 };
596 
597 #ifdef NGENE_V4L
598 struct ngene_overlay {
599  int tvnorm;
600  struct v4l2_rect w;
601  enum v4l2_field field;
602  struct v4l2_clip *clips;
603  int nclips;
604  int setup_ok;
605 };
606 
607 struct ngene_tvnorm {
608  int v4l2_id;
609  char *name;
610  u16 swidth, sheight; /* scaled standard width, height */
611  int tuner_norm;
612  int soundstd;
613 };
614 
615 struct ngene_vopen {
616  struct ngene_channel *ch;
617  enum v4l2_priority prio;
618  int width;
619  int height;
620  int depth;
621  struct videobuf_queue vbuf_q;
622  struct videobuf_queue vbi;
623  int fourcc;
624  int picxcount;
625  int resources;
626  enum v4l2_buf_type type;
627  const struct ngene_format *fmt;
628 
629  const struct ngene_format *ovfmt;
630  struct ngene_overlay ov;
631 };
632 #endif
635  struct device device;
636  struct i2c_adapter i2c_adapter;
638  struct ngene *dev;
639  int number;
640  int type;
641  int mode;
643  bool has_demux;
645  int (*gate_ctrl)(struct dvb_frontend *, int);
647  struct dvb_frontend *fe;
648  struct dvb_frontend *fe2;
649  struct dmxdev dmxdev;
650  struct dvb_demux demux;
651  struct dvb_net dvbnet;
654  int users;
686  u8 lnbh;
687 
688  /* stuff from analog driver */
690  int minor;
691  struct mychip *mychip;
699  int tun_rdy;
700  int dec_rdy;
702  int lastbufferflag;
704  struct ngene_tvnorm *tvnorms;
706  int tvnorm;
707 
708 #ifdef NGENE_V4L
709  int videousers;
710  struct v4l2_prio_state prio;
711  struct ngene_vopen init;
712  int resources;
713  struct v4l2_framebuffer fbuf;
714  struct ngene_buffer *screen; /* overlay */
715  struct list_head capture; /* video capture queue */
716  spinlock_t s_lock;
717  struct semaphore reslock;
718 #endif
720  int running;
721 };
722 
724 struct ngene_ci {
725  struct device device;
726  struct i2c_adapter i2c_adapter;
728  struct ngene *dev;
729  struct dvb_ca_en50221 *en;
730 };
731 
732 struct ngene;
734 typedef void (rx_cb_t)(struct ngene *, u32, u8);
735 typedef void (tx_cb_t)(struct ngene *, u32);
737 struct ngene {
738  int nr;
739  struct pci_dev *pci_dev;
740  unsigned char *iomem;
741 
742  /*struct i2c_adapter i2c_adapter;*/
746  u32 icounts;
757  u8 *hosttongene;
768  int cmd_done;
778  struct dvb_adapter *first_adapter; /* "one_adapter" modprobe opt */
781  struct ngene_info *card_info;
785  int tx_busy;
788 #define UART_RBUF_LEN 4096
790  int uart_rp, uart_wp;
792 #define TS_FILLER 0x6f
795 #define TSOUT_BUF_SIZE (512*188*8)
796  struct dvb_ringbuffer tsout_rbuf;
799 #define TSIN_BUF_SIZE (512*188*8)
800  struct dvb_ringbuffer tsin_rbuf;
803 #define AIN_BUF_SIZE (128*1024)
804  struct dvb_ringbuffer ain_rbuf;
805 
808 #define VIN_BUF_SIZE (4*1920*1080)
809  struct dvb_ringbuffer vin_rbuf;
811  unsigned long exp_val;
812  int prev_cmd;
814  struct ngene_ci ci;
815 };
817 struct ngene_info {
818  int type;
819 #define NGENE_APP 0
820 #define NGENE_TERRATEC 1
821 #define NGENE_SIDEWINDER 2
822 #define NGENE_RACER 3
823 #define NGENE_VIPER 4
824 #define NGENE_PYTHON 5
825 #define NGENE_VBOX_V1 6
826 #define NGENE_VBOX_V2 7
830  char *name;
833 #define NGENE_IO_NONE 0
834 #define NGENE_IO_TV 1
835 #define NGENE_IO_HDTV 2
836 #define NGENE_IO_TSIN 4
837 #define NGENE_IO_TSOUT 8
838 #define NGENE_IO_AIN 16
840  void *fe_config[4];
841  void *tuner_config[4];
843  int (*demod_attach[4])(struct ngene_channel *);
844  int (*tuner_attach[4])(struct ngene_channel *);
846  u8 avf[4];
847  u8 msp[4];
848  u8 demoda[4];
849  u8 lnb[4];
852  u8 tsf[4];
853  u8 i2s[4];
855  int (*gate_ctrl)(struct dvb_frontend *, int);
856  int (*switch_ctrl)(struct ngene_channel *, int, int);
857 };
858 
859 #ifdef NGENE_V4L
860 struct ngene_format {
861  char *name;
862  int fourcc; /* video4linux 2 */
863  int btformat; /* BT848_COLOR_FMT_* */
864  int format;
865  int btswap; /* BT848_COLOR_CTL_* */
866  int depth; /* bit/pixel */
867  int flags;
868  int hshift, vshift; /* for planar modes */
869  int palette;
870 };
871 
872 #define RESOURCE_OVERLAY 1
873 #define RESOURCE_VIDEO 2
874 #define RESOURCE_VBI 4
875 
876 struct ngene_buffer {
877  /* common v4l buffer stuff -- must be first */
878  struct videobuf_buffer vb;
879 
880  /* ngene specific */
881  const struct ngene_format *fmt;
882  int tvnorm;
883  int btformat;
884  int btswap;
885 };
886 #endif
887 
888 
889 /* Provided by ngene-core.c */
891  const struct pci_device_id *id);
892 void __devexit ngene_remove(struct pci_dev *pdev);
893 void ngene_shutdown(struct pci_dev *pdev);
894 int ngene_command(struct ngene *dev, struct ngene_command *com);
896 void set_transfer(struct ngene_channel *chan, int state);
897 void FillTSBuffer(void *Buffer, int Length, u32 Flags);
898 
899 /* Provided by ngene-i2c.c */
900 int ngene_i2c_init(struct ngene *dev, int dev_nr);
901 
902 /* Provided by ngene-dvb.c */
903 extern struct dvb_device ngene_dvbdev_ci;
904 void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
905 void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
906 int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed);
907 int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
908 int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
909  int (*start_feed)(struct dvb_demux_feed *),
910  int (*stop_feed)(struct dvb_demux_feed *),
911  void *priv);
913  struct dvb_demux *dvbdemux,
914  struct dmx_frontend *hw_frontend,
915  struct dmx_frontend *mem_frontend,
916  struct dvb_adapter *dvb_adapter);
917 
918 #endif
919 
920 /* LocalWords: Endif
921  */