ngene.h 25 KB

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