ngene.h 23 KB

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