ngene.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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_ca_en50221.h"
  36. #include "dvb_frontend.h"
  37. #include "dvb_ringbuffer.h"
  38. #include "dvb_net.h"
  39. #include "cxd2099.h"
  40. #define DEVICE_NAME "ngene"
  41. #define NGENE_VID 0x18c3
  42. #define NGENE_PID 0x0720
  43. #ifndef VIDEO_CAP_VC1
  44. #define VIDEO_CAP_AVC 128
  45. #define VIDEO_CAP_H264 128
  46. #define VIDEO_CAP_VC1 256
  47. #define VIDEO_CAP_WMV9 256
  48. #define VIDEO_CAP_MPEG4 512
  49. #endif
  50. enum STREAM {
  51. STREAM_VIDEOIN1 = 0, /* ITU656 or TS Input */
  52. STREAM_VIDEOIN2,
  53. STREAM_AUDIOIN1, /* I2S or SPI Input */
  54. STREAM_AUDIOIN2,
  55. STREAM_AUDIOOUT,
  56. MAX_STREAM
  57. };
  58. enum SMODE_BITS {
  59. SMODE_AUDIO_SPDIF = 0x20,
  60. SMODE_AVSYNC = 0x10,
  61. SMODE_TRANSPORT_STREAM = 0x08,
  62. SMODE_AUDIO_CAPTURE = 0x04,
  63. SMODE_VBI_CAPTURE = 0x02,
  64. SMODE_VIDEO_CAPTURE = 0x01
  65. };
  66. enum STREAM_FLAG_BITS {
  67. SFLAG_CHROMA_FORMAT_2COMP = 0x01, /* Chroma Format : 2's complement */
  68. SFLAG_CHROMA_FORMAT_OFFSET = 0x00, /* Chroma Format : Binary offset */
  69. SFLAG_ORDER_LUMA_CHROMA = 0x02, /* Byte order: Y,Cb,Y,Cr */
  70. SFLAG_ORDER_CHROMA_LUMA = 0x00, /* Byte order: Cb,Y,Cr,Y */
  71. SFLAG_COLORBAR = 0x04, /* Select colorbar */
  72. };
  73. #define PROGRAM_ROM 0x0000
  74. #define PROGRAM_SRAM 0x1000
  75. #define PERIPHERALS0 0x8000
  76. #define PERIPHERALS1 0x9000
  77. #define SHARED_BUFFER 0xC000
  78. #define HOST_TO_NGENE (SHARED_BUFFER+0x0000)
  79. #define NGENE_TO_HOST (SHARED_BUFFER+0x0100)
  80. #define NGENE_COMMAND (SHARED_BUFFER+0x0200)
  81. #define NGENE_COMMAND_HI (SHARED_BUFFER+0x0204)
  82. #define NGENE_STATUS (SHARED_BUFFER+0x0208)
  83. #define NGENE_STATUS_HI (SHARED_BUFFER+0x020C)
  84. #define NGENE_EVENT (SHARED_BUFFER+0x0210)
  85. #define NGENE_EVENT_HI (SHARED_BUFFER+0x0214)
  86. #define VARIABLES (SHARED_BUFFER+0x0210)
  87. #define NGENE_INT_COUNTS (SHARED_BUFFER+0x0260)
  88. #define NGENE_INT_ENABLE (SHARED_BUFFER+0x0264)
  89. #define NGENE_VBI_LINE_COUNT (SHARED_BUFFER+0x0268)
  90. #define BUFFER_GP_XMIT (SHARED_BUFFER+0x0800)
  91. #define BUFFER_GP_RECV (SHARED_BUFFER+0x0900)
  92. #define EEPROM_AREA (SHARED_BUFFER+0x0A00)
  93. #define SG_V_IN_1 (SHARED_BUFFER+0x0A80)
  94. #define SG_VBI_1 (SHARED_BUFFER+0x0B00)
  95. #define SG_A_IN_1 (SHARED_BUFFER+0x0B80)
  96. #define SG_V_IN_2 (SHARED_BUFFER+0x0C00)
  97. #define SG_VBI_2 (SHARED_BUFFER+0x0C80)
  98. #define SG_A_IN_2 (SHARED_BUFFER+0x0D00)
  99. #define SG_V_OUT (SHARED_BUFFER+0x0D80)
  100. #define SG_A_OUT2 (SHARED_BUFFER+0x0E00)
  101. #define DATA_A_IN_1 (SHARED_BUFFER+0x0E80)
  102. #define DATA_A_IN_2 (SHARED_BUFFER+0x0F00)
  103. #define DATA_A_OUT (SHARED_BUFFER+0x0F80)
  104. #define DATA_V_IN_1 (SHARED_BUFFER+0x1000)
  105. #define DATA_V_IN_2 (SHARED_BUFFER+0x2000)
  106. #define DATA_V_OUT (SHARED_BUFFER+0x3000)
  107. #define DATA_FIFO_AREA (SHARED_BUFFER+0x1000)
  108. #define TIMESTAMPS 0xA000
  109. #define SCRATCHPAD 0xA080
  110. #define FORCE_INT 0xA088
  111. #define FORCE_NMI 0xA090
  112. #define INT_STATUS 0xA0A0
  113. #define DEV_VER 0x9004
  114. #define FW_DEBUG_DEFAULT (PROGRAM_SRAM+0x00FF)
  115. struct SG_ADDR {
  116. u64 start;
  117. u64 curr;
  118. u16 curr_ptr;
  119. u16 elements;
  120. u32 pad[3];
  121. } __attribute__ ((__packed__));
  122. struct SHARED_MEMORY {
  123. /* C000 */
  124. u32 HostToNgene[64];
  125. /* C100 */
  126. u32 NgeneToHost[64];
  127. /* C200 */
  128. u64 NgeneCommand;
  129. u64 NgeneStatus;
  130. u64 NgeneEvent;
  131. /* C210 */
  132. u8 pad1[0xc260 - 0xc218];
  133. /* C260 */
  134. u32 IntCounts;
  135. u32 IntEnable;
  136. /* C268 */
  137. u8 pad2[0xd000 - 0xc268];
  138. } __attribute__ ((__packed__));
  139. struct BUFFER_STREAM_RESULTS {
  140. u32 Clock; /* Stream time in 100ns units */
  141. u16 RemainingLines; /* Remaining lines in this field.
  142. 0 for complete field */
  143. u8 FieldCount; /* Video field number */
  144. u8 Flags; /* Bit 7 = Done, Bit 6 = seen, Bit 5 = overflow,
  145. Bit 0 = FieldID */
  146. u16 BlockCount; /* Audio block count (unused) */
  147. u8 Reserved[2];
  148. u32 DTOUpdate;
  149. } __attribute__ ((__packed__));
  150. struct HW_SCATTER_GATHER_ELEMENT {
  151. u64 Address;
  152. u32 Length;
  153. u32 Reserved;
  154. } __attribute__ ((__packed__));
  155. struct BUFFER_HEADER {
  156. u64 Next;
  157. struct BUFFER_STREAM_RESULTS SR;
  158. u32 Number_of_entries_1;
  159. u32 Reserved5;
  160. u64 Address_of_first_entry_1;
  161. u32 Number_of_entries_2;
  162. u32 Reserved7;
  163. u64 Address_of_first_entry_2;
  164. } __attribute__ ((__packed__));
  165. struct EVENT_BUFFER {
  166. u32 TimeStamp;
  167. u8 GPIOStatus;
  168. u8 UARTStatus;
  169. u8 RXCharacter;
  170. u8 EventStatus;
  171. u32 Reserved[2];
  172. } __attribute__ ((__packed__));
  173. /* Firmware commands. */
  174. enum OPCODES {
  175. CMD_NOP = 0,
  176. CMD_FWLOAD_PREPARE = 0x01,
  177. CMD_FWLOAD_FINISH = 0x02,
  178. CMD_I2C_READ = 0x03,
  179. CMD_I2C_WRITE = 0x04,
  180. CMD_I2C_WRITE_NOSTOP = 0x05,
  181. CMD_I2C_CONTINUE_WRITE = 0x06,
  182. CMD_I2C_CONTINUE_WRITE_NOSTOP = 0x07,
  183. CMD_DEBUG_OUTPUT = 0x09,
  184. CMD_CONTROL = 0x10,
  185. CMD_CONFIGURE_BUFFER = 0x11,
  186. CMD_CONFIGURE_FREE_BUFFER = 0x12,
  187. CMD_SPI_READ = 0x13,
  188. CMD_SPI_WRITE = 0x14,
  189. CMD_MEM_READ = 0x20,
  190. CMD_MEM_WRITE = 0x21,
  191. CMD_SFR_READ = 0x22,
  192. CMD_SFR_WRITE = 0x23,
  193. CMD_IRAM_READ = 0x24,
  194. CMD_IRAM_WRITE = 0x25,
  195. CMD_SET_GPIO_PIN = 0x26,
  196. CMD_SET_GPIO_INT = 0x27,
  197. CMD_CONFIGURE_UART = 0x28,
  198. CMD_WRITE_UART = 0x29,
  199. MAX_CMD
  200. };
  201. enum RESPONSES {
  202. OK = 0,
  203. ERROR = 1
  204. };
  205. struct FW_HEADER {
  206. u8 Opcode;
  207. u8 Length;
  208. } __attribute__ ((__packed__));
  209. struct FW_I2C_WRITE {
  210. struct FW_HEADER hdr;
  211. u8 Device;
  212. u8 Data[250];
  213. } __attribute__ ((__packed__));
  214. struct FW_I2C_CONTINUE_WRITE {
  215. struct FW_HEADER hdr;
  216. u8 Data[250];
  217. } __attribute__ ((__packed__));
  218. struct FW_I2C_READ {
  219. struct FW_HEADER hdr;
  220. u8 Device;
  221. u8 Data[252]; /* followed by two bytes of read data count */
  222. } __attribute__ ((__packed__));
  223. struct FW_SPI_WRITE {
  224. struct FW_HEADER hdr;
  225. u8 ModeSelect;
  226. u8 Data[250];
  227. } __attribute__ ((__packed__));
  228. struct FW_SPI_READ {
  229. struct FW_HEADER hdr;
  230. u8 ModeSelect;
  231. u8 Data[252]; /* followed by two bytes of read data count */
  232. } __attribute__ ((__packed__));
  233. struct FW_FWLOAD_PREPARE {
  234. struct FW_HEADER hdr;
  235. } __attribute__ ((__packed__));
  236. struct FW_FWLOAD_FINISH {
  237. struct FW_HEADER hdr;
  238. u16 Address; /* address of final block */
  239. u16 Length;
  240. } __attribute__ ((__packed__));
  241. /*
  242. * Meaning of FW_STREAM_CONTROL::Mode bits:
  243. * Bit 7: Loopback PEXin to PEXout using TVOut channel
  244. * Bit 6: AVLOOP
  245. * Bit 5: Audio select; 0=I2S, 1=SPDIF
  246. * Bit 4: AVSYNC
  247. * Bit 3: Enable transport stream
  248. * Bit 2: Enable audio capture
  249. * Bit 1: Enable ITU-Video VBI capture
  250. * Bit 0: Enable ITU-Video capture
  251. *
  252. * Meaning of FW_STREAM_CONTROL::Control bits (see UVI1_CTL)
  253. * Bit 7: continuous capture
  254. * Bit 6: capture one field
  255. * Bit 5: capture one frame
  256. * Bit 4: unused
  257. * Bit 3: starting field; 0=odd, 1=even
  258. * Bit 2: sample size; 0=8-bit, 1=10-bit
  259. * Bit 1: data format; 0=UYVY, 1=YUY2
  260. * Bit 0: resets buffer pointers
  261. */
  262. enum FSC_MODE_BITS {
  263. SMODE_LOOPBACK = 0x80,
  264. SMODE_AVLOOP = 0x40,
  265. _SMODE_AUDIO_SPDIF = 0x20,
  266. _SMODE_AVSYNC = 0x10,
  267. _SMODE_TRANSPORT_STREAM = 0x08,
  268. _SMODE_AUDIO_CAPTURE = 0x04,
  269. _SMODE_VBI_CAPTURE = 0x02,
  270. _SMODE_VIDEO_CAPTURE = 0x01
  271. };
  272. /* Meaning of FW_STREAM_CONTROL::Stream bits:
  273. * Bit 3: Audio sample count: 0 = relative, 1 = absolute
  274. * Bit 2: color bar select; 1=color bars, 0=CV3 decoder
  275. * Bits 1-0: stream select, UVI1, UVI2, TVOUT
  276. */
  277. struct FW_STREAM_CONTROL {
  278. struct FW_HEADER hdr;
  279. u8 Stream; /* Stream number (UVI1, UVI2, TVOUT) */
  280. u8 Control; /* Value written to UVI1_CTL */
  281. u8 Mode; /* Controls clock source */
  282. u8 SetupDataLen; /* Length of setup data, MSB=1 write
  283. backwards */
  284. u16 CaptureBlockCount; /* Blocks (a 256 Bytes) to capture per buffer
  285. for TS and Audio */
  286. u64 Buffer_Address; /* Address of first buffer header */
  287. u16 BytesPerVideoLine;
  288. u16 MaxLinesPerField;
  289. u16 MinLinesPerField;
  290. u16 Reserved_1;
  291. u16 BytesPerVBILine;
  292. u16 MaxVBILinesPerField;
  293. u16 MinVBILinesPerField;
  294. u16 SetupDataAddr; /* ngene relative address of setup data */
  295. u8 SetupData[32]; /* setup data */
  296. } __attribute__((__packed__));
  297. #define AUDIO_BLOCK_SIZE 256
  298. #define TS_BLOCK_SIZE 256
  299. struct FW_MEM_READ {
  300. struct FW_HEADER hdr;
  301. u16 address;
  302. } __attribute__ ((__packed__));
  303. struct FW_MEM_WRITE {
  304. struct FW_HEADER hdr;
  305. u16 address;
  306. u8 data;
  307. } __attribute__ ((__packed__));
  308. struct FW_SFR_IRAM_READ {
  309. struct FW_HEADER hdr;
  310. u8 address;
  311. } __attribute__ ((__packed__));
  312. struct FW_SFR_IRAM_WRITE {
  313. struct FW_HEADER hdr;
  314. u8 address;
  315. u8 data;
  316. } __attribute__ ((__packed__));
  317. struct FW_SET_GPIO_PIN {
  318. struct FW_HEADER hdr;
  319. u8 select;
  320. } __attribute__ ((__packed__));
  321. struct FW_SET_GPIO_INT {
  322. struct FW_HEADER hdr;
  323. u8 select;
  324. } __attribute__ ((__packed__));
  325. struct FW_SET_DEBUGMODE {
  326. struct FW_HEADER hdr;
  327. u8 debug_flags;
  328. } __attribute__ ((__packed__));
  329. struct FW_CONFIGURE_BUFFERS {
  330. struct FW_HEADER hdr;
  331. u8 config;
  332. } __attribute__ ((__packed__));
  333. enum _BUFFER_CONFIGS {
  334. /* 4k UVI1, 4k UVI2, 2k AUD1, 2k AUD2 (standard usage) */
  335. BUFFER_CONFIG_4422 = 0,
  336. /* 3k UVI1, 3k UVI2, 3k AUD1, 3k AUD2 (4x TS input usage) */
  337. BUFFER_CONFIG_3333 = 1,
  338. /* 8k UVI1, 0k UVI2, 2k AUD1, 2k I2SOut (HDTV decoder usage) */
  339. BUFFER_CONFIG_8022 = 2,
  340. BUFFER_CONFIG_FW17 = 255, /* Use new FW 17 command */
  341. };
  342. struct FW_CONFIGURE_FREE_BUFFERS {
  343. struct FW_HEADER hdr;
  344. u8 UVI1_BufferLength;
  345. u8 UVI2_BufferLength;
  346. u8 TVO_BufferLength;
  347. u8 AUD1_BufferLength;
  348. u8 AUD2_BufferLength;
  349. u8 TVA_BufferLength;
  350. } __attribute__ ((__packed__));
  351. struct FW_CONFIGURE_UART {
  352. struct FW_HEADER hdr;
  353. u8 UartControl;
  354. } __attribute__ ((__packed__));
  355. enum _UART_CONFIG {
  356. _UART_BAUDRATE_19200 = 0,
  357. _UART_BAUDRATE_9600 = 1,
  358. _UART_BAUDRATE_4800 = 2,
  359. _UART_BAUDRATE_2400 = 3,
  360. _UART_RX_ENABLE = 0x40,
  361. _UART_TX_ENABLE = 0x80,
  362. };
  363. struct FW_WRITE_UART {
  364. struct FW_HEADER hdr;
  365. u8 Data[252];
  366. } __attribute__ ((__packed__));
  367. struct ngene_command {
  368. u32 in_len;
  369. u32 out_len;
  370. union {
  371. u32 raw[64];
  372. u8 raw8[256];
  373. struct FW_HEADER hdr;
  374. struct FW_I2C_WRITE I2CWrite;
  375. struct FW_I2C_CONTINUE_WRITE I2CContinueWrite;
  376. struct FW_I2C_READ I2CRead;
  377. struct FW_STREAM_CONTROL StreamControl;
  378. struct FW_FWLOAD_PREPARE FWLoadPrepare;
  379. struct FW_FWLOAD_FINISH FWLoadFinish;
  380. struct FW_MEM_READ MemoryRead;
  381. struct FW_MEM_WRITE MemoryWrite;
  382. struct FW_SFR_IRAM_READ SfrIramRead;
  383. struct FW_SFR_IRAM_WRITE SfrIramWrite;
  384. struct FW_SPI_WRITE SPIWrite;
  385. struct FW_SPI_READ SPIRead;
  386. struct FW_SET_GPIO_PIN SetGpioPin;
  387. struct FW_SET_GPIO_INT SetGpioInt;
  388. struct FW_SET_DEBUGMODE SetDebugMode;
  389. struct FW_CONFIGURE_BUFFERS ConfigureBuffers;
  390. struct FW_CONFIGURE_FREE_BUFFERS ConfigureFreeBuffers;
  391. struct FW_CONFIGURE_UART ConfigureUart;
  392. struct FW_WRITE_UART WriteUart;
  393. } cmd;
  394. } __attribute__ ((__packed__));
  395. #define NGENE_INTERFACE_VERSION 0x103
  396. #define MAX_VIDEO_BUFFER_SIZE (417792) /* 288*1440 rounded up to next page */
  397. #define MAX_AUDIO_BUFFER_SIZE (8192) /* Gives room for about 23msec@48KHz */
  398. #define MAX_VBI_BUFFER_SIZE (28672) /* 1144*18 rounded up to next page */
  399. #define MAX_TS_BUFFER_SIZE (98304) /* 512*188 rounded up to next page */
  400. #define MAX_HDTV_BUFFER_SIZE (2080768) /* 541*1920*2 rounded up to next page
  401. Max: (1920x1080i60) */
  402. #define OVERFLOW_BUFFER_SIZE (8192)
  403. #define RING_SIZE_VIDEO 4
  404. #define RING_SIZE_AUDIO 8
  405. #define RING_SIZE_TS 8
  406. #define NUM_SCATTER_GATHER_ENTRIES 8
  407. #define MAX_DMA_LENGTH (((MAX_VIDEO_BUFFER_SIZE + MAX_VBI_BUFFER_SIZE) * \
  408. RING_SIZE_VIDEO * 2) + \
  409. (MAX_AUDIO_BUFFER_SIZE * RING_SIZE_AUDIO * 2) + \
  410. (MAX_TS_BUFFER_SIZE * RING_SIZE_TS * 4) + \
  411. (RING_SIZE_VIDEO * PAGE_SIZE * 2) + \
  412. (RING_SIZE_AUDIO * PAGE_SIZE * 2) + \
  413. (RING_SIZE_TS * PAGE_SIZE * 4) + \
  414. 8 * PAGE_SIZE + OVERFLOW_BUFFER_SIZE + PAGE_SIZE)
  415. #define EVENT_QUEUE_SIZE 16
  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. struct HW_SCATTER_GATHER_ELEMENT *scList1;
  422. void *Buffer2;
  423. struct HW_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. struct MICI_STREAMINFO {
  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. };
  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. bool has_adapter;
  544. bool has_demux;
  545. int demod_type;
  546. int (*gate_ctrl)(struct dvb_frontend *, int);
  547. struct dvb_frontend *fe;
  548. struct dvb_frontend *fe2;
  549. struct dmxdev dmxdev;
  550. struct dvb_demux demux;
  551. struct dvb_net dvbnet;
  552. struct dmx_frontend hw_frontend;
  553. struct dmx_frontend mem_frontend;
  554. int users;
  555. struct video_device *v4l_dev;
  556. struct dvb_device *ci_dev;
  557. struct tasklet_struct demux_tasklet;
  558. struct SBufferHeader *nextBuffer;
  559. enum KSSTATE State;
  560. enum HWSTATE HWState;
  561. u8 Stream;
  562. u8 Flags;
  563. u8 Mode;
  564. IBufferExchange *pBufferExchange;
  565. IBufferExchange *pBufferExchange2;
  566. spinlock_t state_lock;
  567. u16 nLines;
  568. u16 nBytesPerLine;
  569. u16 nVBILines;
  570. u16 nBytesPerVBILine;
  571. u16 itumode;
  572. u32 Capture1Length;
  573. u32 Capture2Length;
  574. struct SRingBufferDescriptor RingBuffer;
  575. struct SRingBufferDescriptor TSRingBuffer;
  576. struct SRingBufferDescriptor TSIdleBuffer;
  577. u32 DataFormatFlags;
  578. int AudioDTOUpdated;
  579. u32 AudioDTOValue;
  580. int (*set_tone)(struct dvb_frontend *, enum fe_sec_tone_mode);
  581. u8 lnbh;
  582. /* stuff from analog driver */
  583. int minor;
  584. struct mychip *mychip;
  585. struct snd_card *soundcard;
  586. u8 *evenbuffer;
  587. u8 dma_on;
  588. int soundstreamon;
  589. int audiomute;
  590. int soundbuffisallocated;
  591. int sndbuffflag;
  592. int tun_rdy;
  593. int dec_rdy;
  594. int tun_dec_rdy;
  595. int lastbufferflag;
  596. struct ngene_tvnorm *tvnorms;
  597. int tvnorm_num;
  598. int tvnorm;
  599. #ifdef NGENE_V4L
  600. int videousers;
  601. struct v4l2_prio_state prio;
  602. struct ngene_vopen init;
  603. int resources;
  604. struct v4l2_framebuffer fbuf;
  605. struct ngene_buffer *screen; /* overlay */
  606. struct list_head capture; /* video capture queue */
  607. spinlock_t s_lock;
  608. struct semaphore reslock;
  609. #endif
  610. int running;
  611. };
  612. struct ngene_ci {
  613. struct device device;
  614. struct i2c_adapter i2c_adapter;
  615. struct ngene *dev;
  616. struct dvb_ca_en50221 *en;
  617. };
  618. struct ngene;
  619. typedef void (rx_cb_t)(struct ngene *, u32, u8);
  620. typedef void (tx_cb_t)(struct ngene *, u32);
  621. struct ngene {
  622. int nr;
  623. struct pci_dev *pci_dev;
  624. unsigned char __iomem *iomem;
  625. /*struct i2c_adapter i2c_adapter;*/
  626. u32 device_version;
  627. u32 fw_interface_version;
  628. u32 icounts;
  629. bool msi_enabled;
  630. bool cmd_timeout_workaround;
  631. u8 *CmdDoneByte;
  632. int BootFirmware;
  633. void *OverflowBuffer;
  634. dma_addr_t PAOverflowBuffer;
  635. void *FWInterfaceBuffer;
  636. dma_addr_t PAFWInterfaceBuffer;
  637. u8 *ngenetohost;
  638. u8 *hosttongene;
  639. struct EVENT_BUFFER EventQueue[EVENT_QUEUE_SIZE];
  640. int EventQueueOverflowCount;
  641. int EventQueueOverflowFlag;
  642. struct tasklet_struct event_tasklet;
  643. struct EVENT_BUFFER *EventBuffer;
  644. int EventQueueWriteIndex;
  645. int EventQueueReadIndex;
  646. wait_queue_head_t cmd_wq;
  647. int cmd_done;
  648. struct semaphore cmd_mutex;
  649. struct semaphore stream_mutex;
  650. struct semaphore pll_mutex;
  651. struct semaphore i2c_switch_mutex;
  652. int i2c_current_channel;
  653. int i2c_current_bus;
  654. spinlock_t cmd_lock;
  655. struct dvb_adapter adapter[MAX_STREAM];
  656. struct dvb_adapter *first_adapter; /* "one_adapter" modprobe opt */
  657. struct ngene_channel channel[MAX_STREAM];
  658. struct ngene_info *card_info;
  659. tx_cb_t *TxEventNotify;
  660. rx_cb_t *RxEventNotify;
  661. int tx_busy;
  662. wait_queue_head_t tx_wq;
  663. wait_queue_head_t rx_wq;
  664. #define UART_RBUF_LEN 4096
  665. u8 uart_rbuf[UART_RBUF_LEN];
  666. int uart_rp, uart_wp;
  667. #define TS_FILLER 0x6f
  668. u8 *tsout_buf;
  669. #define TSOUT_BUF_SIZE (512*188*8)
  670. struct dvb_ringbuffer tsout_rbuf;
  671. u8 *tsin_buf;
  672. #define TSIN_BUF_SIZE (512*188*8)
  673. struct dvb_ringbuffer tsin_rbuf;
  674. u8 *ain_buf;
  675. #define AIN_BUF_SIZE (128*1024)
  676. struct dvb_ringbuffer ain_rbuf;
  677. u8 *vin_buf;
  678. #define VIN_BUF_SIZE (4*1920*1080)
  679. struct dvb_ringbuffer vin_rbuf;
  680. unsigned long exp_val;
  681. int prev_cmd;
  682. struct ngene_ci ci;
  683. };
  684. struct ngene_info {
  685. int type;
  686. #define NGENE_APP 0
  687. #define NGENE_TERRATEC 1
  688. #define NGENE_SIDEWINDER 2
  689. #define NGENE_RACER 3
  690. #define NGENE_VIPER 4
  691. #define NGENE_PYTHON 5
  692. #define NGENE_VBOX_V1 6
  693. #define NGENE_VBOX_V2 7
  694. int fw_version;
  695. bool msi_supported;
  696. char *name;
  697. int io_type[MAX_STREAM];
  698. #define NGENE_IO_NONE 0
  699. #define NGENE_IO_TV 1
  700. #define NGENE_IO_HDTV 2
  701. #define NGENE_IO_TSIN 4
  702. #define NGENE_IO_TSOUT 8
  703. #define NGENE_IO_AIN 16
  704. void *fe_config[4];
  705. void *tuner_config[4];
  706. int (*demod_attach[4])(struct ngene_channel *);
  707. int (*tuner_attach[4])(struct ngene_channel *);
  708. u8 avf[4];
  709. u8 msp[4];
  710. u8 demoda[4];
  711. u8 lnb[4];
  712. int i2c_access;
  713. u8 ntsc;
  714. u8 tsf[4];
  715. u8 i2s[4];
  716. int (*gate_ctrl)(struct dvb_frontend *, int);
  717. int (*switch_ctrl)(struct ngene_channel *, int, int);
  718. };
  719. #ifdef NGENE_V4L
  720. struct ngene_format {
  721. char *name;
  722. int fourcc; /* video4linux 2 */
  723. int btformat; /* BT848_COLOR_FMT_* */
  724. int format;
  725. int btswap; /* BT848_COLOR_CTL_* */
  726. int depth; /* bit/pixel */
  727. int flags;
  728. int hshift, vshift; /* for planar modes */
  729. int palette;
  730. };
  731. #define RESOURCE_OVERLAY 1
  732. #define RESOURCE_VIDEO 2
  733. #define RESOURCE_VBI 4
  734. struct ngene_buffer {
  735. /* common v4l buffer stuff -- must be first */
  736. struct videobuf_buffer vb;
  737. /* ngene specific */
  738. const struct ngene_format *fmt;
  739. int tvnorm;
  740. int btformat;
  741. int btswap;
  742. };
  743. #endif
  744. /* Provided by ngene-core.c */
  745. int ngene_probe(struct pci_dev *pci_dev, const struct pci_device_id *id);
  746. void ngene_remove(struct pci_dev *pdev);
  747. void ngene_shutdown(struct pci_dev *pdev);
  748. int ngene_command(struct ngene *dev, struct ngene_command *com);
  749. int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level);
  750. void set_transfer(struct ngene_channel *chan, int state);
  751. void FillTSBuffer(void *Buffer, int Length, u32 Flags);
  752. /* Provided by ngene-i2c.c */
  753. int ngene_i2c_init(struct ngene *dev, int dev_nr);
  754. /* Provided by ngene-dvb.c */
  755. extern struct dvb_device ngene_dvbdev_ci;
  756. void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
  757. void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
  758. int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed);
  759. int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
  760. int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
  761. int (*start_feed)(struct dvb_demux_feed *),
  762. int (*stop_feed)(struct dvb_demux_feed *),
  763. void *priv);
  764. int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
  765. struct dvb_demux *dvbdemux,
  766. struct dmx_frontend *hw_frontend,
  767. struct dmx_frontend *mem_frontend,
  768. struct dvb_adapter *dvb_adapter);
  769. #endif
  770. /* LocalWords: Endif
  771. */