ngene.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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 <linux/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 DEVICE_NAME "ngene"
  38. #define NGENE_VID 0x18c3
  39. #define NGENE_PID 0x0720
  40. #ifndef VIDEO_CAP_VC1
  41. #define VIDEO_CAP_AVC 128
  42. #define VIDEO_CAP_H264 128
  43. #define VIDEO_CAP_VC1 256
  44. #define VIDEO_CAP_WMV9 256
  45. #define VIDEO_CAP_MPEG4 512
  46. #endif
  47. enum STREAM {
  48. STREAM_VIDEOIN1 = 0, /* ITU656 or TS Input */
  49. STREAM_VIDEOIN2,
  50. STREAM_AUDIOIN1, /* I2S or SPI Input */
  51. STREAM_AUDIOIN2,
  52. STREAM_AUDIOOUT,
  53. MAX_STREAM
  54. };
  55. enum SMODE_BITS {
  56. SMODE_AUDIO_SPDIF = 0x20,
  57. SMODE_AVSYNC = 0x10,
  58. SMODE_TRANSPORT_STREAM = 0x08,
  59. SMODE_AUDIO_CAPTURE = 0x04,
  60. SMODE_VBI_CAPTURE = 0x02,
  61. SMODE_VIDEO_CAPTURE = 0x01
  62. };
  63. enum STREAM_FLAG_BITS {
  64. SFLAG_CHROMA_FORMAT_2COMP = 0x01, /* Chroma Format : 2's complement */
  65. SFLAG_CHROMA_FORMAT_OFFSET = 0x00, /* Chroma Format : Binary offset */
  66. SFLAG_ORDER_LUMA_CHROMA = 0x02, /* Byte order: Y,Cb,Y,Cr */
  67. SFLAG_ORDER_CHROMA_LUMA = 0x00, /* Byte order: Cb,Y,Cr,Y */
  68. SFLAG_COLORBAR = 0x04, /* Select colorbar */
  69. };
  70. #define PROGRAM_ROM 0x0000
  71. #define PROGRAM_SRAM 0x1000
  72. #define PERIPHERALS0 0x8000
  73. #define PERIPHERALS1 0x9000
  74. #define SHARED_BUFFER 0xC000
  75. #define HOST_TO_NGENE (SHARED_BUFFER+0x0000)
  76. #define NGENE_TO_HOST (SHARED_BUFFER+0x0100)
  77. #define NGENE_COMMAND (SHARED_BUFFER+0x0200)
  78. #define NGENE_COMMAND_HI (SHARED_BUFFER+0x0204)
  79. #define NGENE_STATUS (SHARED_BUFFER+0x0208)
  80. #define NGENE_STATUS_HI (SHARED_BUFFER+0x020C)
  81. #define NGENE_EVENT (SHARED_BUFFER+0x0210)
  82. #define NGENE_EVENT_HI (SHARED_BUFFER+0x0214)
  83. #define VARIABLES (SHARED_BUFFER+0x0210)
  84. #define NGENE_INT_COUNTS (SHARED_BUFFER+0x0260)
  85. #define NGENE_INT_ENABLE (SHARED_BUFFER+0x0264)
  86. #define NGENE_VBI_LINE_COUNT (SHARED_BUFFER+0x0268)
  87. #define BUFFER_GP_XMIT (SHARED_BUFFER+0x0800)
  88. #define BUFFER_GP_RECV (SHARED_BUFFER+0x0900)
  89. #define EEPROM_AREA (SHARED_BUFFER+0x0A00)
  90. #define SG_V_IN_1 (SHARED_BUFFER+0x0A80)
  91. #define SG_VBI_1 (SHARED_BUFFER+0x0B00)
  92. #define SG_A_IN_1 (SHARED_BUFFER+0x0B80)
  93. #define SG_V_IN_2 (SHARED_BUFFER+0x0C00)
  94. #define SG_VBI_2 (SHARED_BUFFER+0x0C80)
  95. #define SG_A_IN_2 (SHARED_BUFFER+0x0D00)
  96. #define SG_V_OUT (SHARED_BUFFER+0x0D80)
  97. #define SG_A_OUT2 (SHARED_BUFFER+0x0E00)
  98. #define DATA_A_IN_1 (SHARED_BUFFER+0x0E80)
  99. #define DATA_A_IN_2 (SHARED_BUFFER+0x0F00)
  100. #define DATA_A_OUT (SHARED_BUFFER+0x0F80)
  101. #define DATA_V_IN_1 (SHARED_BUFFER+0x1000)
  102. #define DATA_V_IN_2 (SHARED_BUFFER+0x2000)
  103. #define DATA_V_OUT (SHARED_BUFFER+0x3000)
  104. #define DATA_FIFO_AREA (SHARED_BUFFER+0x1000)
  105. #define TIMESTAMPS 0xA000
  106. #define SCRATCHPAD 0xA080
  107. #define FORCE_INT 0xA088
  108. #define FORCE_NMI 0xA090
  109. #define INT_STATUS 0xA0A0
  110. #define DEV_VER 0x9004
  111. #define FW_DEBUG_DEFAULT (PROGRAM_SRAM+0x00FF)
  112. struct SG_ADDR {
  113. u64 start;
  114. u64 curr;
  115. u16 curr_ptr;
  116. u16 elements;
  117. u32 pad[3];
  118. } __attribute__ ((__packed__));
  119. struct SHARED_MEMORY {
  120. /* C000 */
  121. u32 HostToNgene[64];
  122. /* C100 */
  123. u32 NgeneToHost[64];
  124. /* C200 */
  125. u64 NgeneCommand;
  126. u64 NgeneStatus;
  127. u64 NgeneEvent;
  128. /* C210 */
  129. u8 pad1[0xc260 - 0xc218];
  130. /* C260 */
  131. u32 IntCounts;
  132. u32 IntEnable;
  133. /* C268 */
  134. u8 pad2[0xd000 - 0xc268];
  135. } __attribute__ ((__packed__));
  136. struct BUFFER_STREAM_RESULTS {
  137. u32 Clock; /* Stream time in 100ns units */
  138. u16 RemainingLines; /* Remaining lines in this field.
  139. 0 for complete field */
  140. u8 FieldCount; /* Video field number */
  141. u8 Flags; /* Bit 7 = Done, Bit 6 = seen, Bit 5 = overflow,
  142. Bit 0 = FieldID */
  143. u16 BlockCount; /* Audio block count (unused) */
  144. u8 Reserved[2];
  145. u32 DTOUpdate;
  146. } __attribute__ ((__packed__));
  147. struct HW_SCATTER_GATHER_ELEMENT {
  148. u64 Address;
  149. u32 Length;
  150. u32 Reserved;
  151. } __attribute__ ((__packed__));
  152. struct BUFFER_HEADER {
  153. u64 Next;
  154. struct BUFFER_STREAM_RESULTS SR;
  155. u32 Number_of_entries_1;
  156. u32 Reserved5;
  157. u64 Address_of_first_entry_1;
  158. u32 Number_of_entries_2;
  159. u32 Reserved7;
  160. u64 Address_of_first_entry_2;
  161. } __attribute__ ((__packed__));
  162. struct EVENT_BUFFER {
  163. u32 TimeStamp;
  164. u8 GPIOStatus;
  165. u8 UARTStatus;
  166. u8 RXCharacter;
  167. u8 EventStatus;
  168. u32 Reserved[2];
  169. } __attribute__ ((__packed__));
  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. /* Gathers the current state of a single channel. */
  414. struct SBufferHeader {
  415. struct BUFFER_HEADER ngeneBuffer; /* Physical descriptor */
  416. struct SBufferHeader *Next;
  417. void *Buffer1;
  418. struct HW_SCATTER_GATHER_ELEMENT *scList1;
  419. void *Buffer2;
  420. struct HW_SCATTER_GATHER_ELEMENT *scList2;
  421. };
  422. /* Sizeof SBufferHeader aligned to next 64 Bit boundary (hw restriction) */
  423. #define SIZEOF_SBufferHeader ((sizeof(struct SBufferHeader) + 63) & ~63)
  424. enum HWSTATE {
  425. HWSTATE_STOP,
  426. HWSTATE_STARTUP,
  427. HWSTATE_RUN,
  428. HWSTATE_PAUSE,
  429. };
  430. enum KSSTATE {
  431. KSSTATE_STOP,
  432. KSSTATE_ACQUIRE,
  433. KSSTATE_PAUSE,
  434. KSSTATE_RUN,
  435. };
  436. struct SRingBufferDescriptor {
  437. struct SBufferHeader *Head; /* Points to first buffer in ring buffer
  438. structure*/
  439. u64 PAHead; /* Physical address of first buffer */
  440. u32 MemSize; /* Memory size of allocated ring buffers
  441. (needed for freeing) */
  442. u32 NumBuffers; /* Number of buffers in the ring */
  443. u32 Buffer1Length; /* Allocated length of Buffer 1 */
  444. u32 Buffer2Length; /* Allocated length of Buffer 2 */
  445. void *SCListMem; /* Memory to hold scatter gather lists for this
  446. ring */
  447. u64 PASCListMem; /* Physical address .. */
  448. u32 SCListMemSize; /* Size of this memory */
  449. };
  450. enum STREAMMODEFLAGS {
  451. StreamMode_NONE = 0, /* Stream not used */
  452. StreamMode_ANALOG = 1, /* Analog: Stream 0,1 = Video, 2,3 = Audio */
  453. StreamMode_TSIN = 2, /* Transport stream input (all) */
  454. StreamMode_HDTV = 4, /* HDTV: Maximum 1920x1080p30,1920x1080i60
  455. (only stream 0) */
  456. StreamMode_TSOUT = 8, /* Transport stream output (only stream 3) */
  457. };
  458. enum BufferExchangeFlags {
  459. BEF_EVEN_FIELD = 0x00000001,
  460. BEF_CONTINUATION = 0x00000002,
  461. BEF_MORE_DATA = 0x00000004,
  462. BEF_OVERFLOW = 0x00000008,
  463. DF_SWAP32 = 0x00010000,
  464. };
  465. typedef void *(IBufferExchange)(void *, void *, u32, u32, u32);
  466. struct MICI_STREAMINFO {
  467. IBufferExchange *pExchange;
  468. IBufferExchange *pExchangeVBI; /* Secondary (VBI, ancillary) */
  469. u8 Stream;
  470. u8 Flags;
  471. u8 Mode;
  472. u8 Reserved;
  473. u16 nLinesVideo;
  474. u16 nBytesPerLineVideo;
  475. u16 nLinesVBI;
  476. u16 nBytesPerLineVBI;
  477. u32 CaptureLength; /* Used for audio and transport stream */
  478. };
  479. /****************************************************************************/
  480. /* STRUCTS ******************************************************************/
  481. /****************************************************************************/
  482. /* sound hardware definition */
  483. #define MIXER_ADDR_TVTUNER 0
  484. #define MIXER_ADDR_LAST 0
  485. struct ngene_channel;
  486. /*struct sound chip*/
  487. struct mychip {
  488. struct ngene_channel *chan;
  489. struct snd_card *card;
  490. struct pci_dev *pci;
  491. struct snd_pcm_substream *substream;
  492. struct snd_pcm *pcm;
  493. unsigned long port;
  494. int irq;
  495. spinlock_t mixer_lock;
  496. spinlock_t lock;
  497. int mixer_volume[MIXER_ADDR_LAST + 1][2];
  498. int capture_source[MIXER_ADDR_LAST + 1][2];
  499. };
  500. #ifdef NGENE_V4L
  501. struct ngene_overlay {
  502. int tvnorm;
  503. struct v4l2_rect w;
  504. enum v4l2_field field;
  505. struct v4l2_clip *clips;
  506. int nclips;
  507. int setup_ok;
  508. };
  509. struct ngene_tvnorm {
  510. int v4l2_id;
  511. char *name;
  512. u16 swidth, sheight; /* scaled standard width, height */
  513. int tuner_norm;
  514. int soundstd;
  515. };
  516. struct ngene_vopen {
  517. struct ngene_channel *ch;
  518. enum v4l2_priority prio;
  519. int width;
  520. int height;
  521. int depth;
  522. struct videobuf_queue vbuf_q;
  523. struct videobuf_queue vbi;
  524. int fourcc;
  525. int picxcount;
  526. int resources;
  527. enum v4l2_buf_type type;
  528. const struct ngene_format *fmt;
  529. const struct ngene_format *ovfmt;
  530. struct ngene_overlay ov;
  531. };
  532. #endif
  533. struct ngene_channel {
  534. struct device device;
  535. struct i2c_adapter i2c_adapter;
  536. struct ngene *dev;
  537. int number;
  538. int type;
  539. int mode;
  540. struct dvb_frontend *fe;
  541. struct dmxdev dmxdev;
  542. struct dvb_demux demux;
  543. struct dmx_frontend hw_frontend;
  544. struct dmx_frontend mem_frontend;
  545. int users;
  546. struct video_device *v4l_dev;
  547. struct tasklet_struct demux_tasklet;
  548. struct SBufferHeader *nextBuffer;
  549. enum KSSTATE State;
  550. enum HWSTATE HWState;
  551. u8 Stream;
  552. u8 Flags;
  553. u8 Mode;
  554. IBufferExchange *pBufferExchange;
  555. IBufferExchange *pBufferExchange2;
  556. spinlock_t state_lock;
  557. u16 nLines;
  558. u16 nBytesPerLine;
  559. u16 nVBILines;
  560. u16 nBytesPerVBILine;
  561. u16 itumode;
  562. u32 Capture1Length;
  563. u32 Capture2Length;
  564. struct SRingBufferDescriptor RingBuffer;
  565. struct SRingBufferDescriptor TSRingBuffer;
  566. struct SRingBufferDescriptor TSIdleBuffer;
  567. u32 DataFormatFlags;
  568. int AudioDTOUpdated;
  569. u32 AudioDTOValue;
  570. int (*set_tone)(struct dvb_frontend *, fe_sec_tone_mode_t);
  571. u8 lnbh;
  572. /* stuff from analog driver */
  573. int minor;
  574. struct mychip *mychip;
  575. struct snd_card *soundcard;
  576. u8 *evenbuffer;
  577. u8 dma_on;
  578. int soundstreamon;
  579. int audiomute;
  580. int soundbuffisallocated;
  581. int sndbuffflag;
  582. int tun_rdy;
  583. int dec_rdy;
  584. int tun_dec_rdy;
  585. int lastbufferflag;
  586. struct ngene_tvnorm *tvnorms;
  587. int tvnorm_num;
  588. int tvnorm;
  589. #ifdef NGENE_V4L
  590. int videousers;
  591. struct v4l2_prio_state prio;
  592. struct ngene_vopen init;
  593. int resources;
  594. struct v4l2_framebuffer fbuf;
  595. struct ngene_buffer *screen; /* overlay */
  596. struct list_head capture; /* video capture queue */
  597. spinlock_t s_lock;
  598. struct semaphore reslock;
  599. #endif
  600. int running;
  601. };
  602. struct ngene;
  603. typedef void (rx_cb_t)(struct ngene *, u32, u8);
  604. typedef void (tx_cb_t)(struct ngene *, u32);
  605. struct ngene {
  606. int nr;
  607. struct pci_dev *pci_dev;
  608. unsigned char *iomem;
  609. /*struct i2c_adapter i2c_adapter;*/
  610. u32 device_version;
  611. u32 fw_interface_version;
  612. u32 icounts;
  613. bool msi_enabled;
  614. bool cmd_timeout_workaround;
  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 dvb_adapter *first_adapter; /* "one_adapter" modprobe opt */
  641. struct ngene_channel channel[MAX_STREAM];
  642. struct ngene_info *card_info;
  643. tx_cb_t *TxEventNotify;
  644. rx_cb_t *RxEventNotify;
  645. int tx_busy;
  646. wait_queue_head_t tx_wq;
  647. wait_queue_head_t rx_wq;
  648. #define UART_RBUF_LEN 4096
  649. u8 uart_rbuf[UART_RBUF_LEN];
  650. int uart_rp, uart_wp;
  651. u8 *tsout_buf;
  652. #define TSOUT_BUF_SIZE (512*188*8)
  653. struct dvb_ringbuffer tsout_rbuf;
  654. u8 *ain_buf;
  655. #define AIN_BUF_SIZE (128*1024)
  656. struct dvb_ringbuffer ain_rbuf;
  657. u8 *vin_buf;
  658. #define VIN_BUF_SIZE (4*1920*1080)
  659. struct dvb_ringbuffer vin_rbuf;
  660. unsigned long exp_val;
  661. int prev_cmd;
  662. };
  663. struct ngene_info {
  664. int type;
  665. #define NGENE_APP 0
  666. #define NGENE_TERRATEC 1
  667. #define NGENE_SIDEWINDER 2
  668. #define NGENE_RACER 3
  669. #define NGENE_VIPER 4
  670. #define NGENE_PYTHON 5
  671. #define NGENE_VBOX_V1 6
  672. #define NGENE_VBOX_V2 7
  673. int fw_version;
  674. bool msi_supported;
  675. char *name;
  676. int io_type[MAX_STREAM];
  677. #define NGENE_IO_NONE 0
  678. #define NGENE_IO_TV 1
  679. #define NGENE_IO_HDTV 2
  680. #define NGENE_IO_TSIN 4
  681. #define NGENE_IO_TSOUT 8
  682. #define NGENE_IO_AIN 16
  683. void *fe_config[4];
  684. void *tuner_config[4];
  685. int (*demod_attach[4])(struct ngene_channel *);
  686. int (*tuner_attach[4])(struct ngene_channel *);
  687. u8 avf[4];
  688. u8 msp[4];
  689. u8 demoda[4];
  690. u8 lnb[4];
  691. int i2c_access;
  692. u8 ntsc;
  693. u8 tsf[4];
  694. u8 i2s[4];
  695. int (*gate_ctrl)(struct dvb_frontend *, int);
  696. int (*switch_ctrl)(struct ngene_channel *, int, int);
  697. };
  698. #ifdef NGENE_V4L
  699. struct ngene_format{
  700. char *name;
  701. int fourcc; /* video4linux 2 */
  702. int btformat; /* BT848_COLOR_FMT_* */
  703. int format;
  704. int btswap; /* BT848_COLOR_CTL_* */
  705. int depth; /* bit/pixel */
  706. int flags;
  707. int hshift, vshift; /* for planar modes */
  708. int palette;
  709. };
  710. #define RESOURCE_OVERLAY 1
  711. #define RESOURCE_VIDEO 2
  712. #define RESOURCE_VBI 4
  713. struct ngene_buffer {
  714. /* common v4l buffer stuff -- must be first */
  715. struct videobuf_buffer vb;
  716. /* ngene specific */
  717. const struct ngene_format *fmt;
  718. int tvnorm;
  719. int btformat;
  720. int btswap;
  721. };
  722. #endif
  723. /* Provided by ngene-core.c */
  724. int __devinit ngene_probe(struct pci_dev *pci_dev,
  725. const struct pci_device_id *id);
  726. void __devexit ngene_remove(struct pci_dev *pdev);
  727. int ngene_command(struct ngene *dev, struct ngene_command *com);
  728. int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level);
  729. void set_transfer(struct ngene_channel *chan, int state);
  730. void FillTSBuffer(void *Buffer, int Length, u32 Flags);
  731. /* Provided by ngene-i2c.c */
  732. int ngene_i2c_init(struct ngene *dev, int dev_nr);
  733. /* Provided by ngene-dvb.c */
  734. void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
  735. void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
  736. int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed);
  737. int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
  738. int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
  739. int (*start_feed)(struct dvb_demux_feed *),
  740. int (*stop_feed)(struct dvb_demux_feed *),
  741. void *priv);
  742. int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
  743. struct dvb_demux *dvbdemux,
  744. struct dmx_frontend *hw_frontend,
  745. struct dmx_frontend *mem_frontend,
  746. struct dvb_adapter *dvb_adapter);
  747. #endif
  748. /* LocalWords: Endif
  749. */