ngene.h 23 KB

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