mtv319_port.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*
  2. *
  3. * File name: mtv319_port.h
  4. *
  5. * Description : Configuration for RAONTECH MTV319 Services.
  6. *
  7. * Copyright (C) (2013, RAONTECH)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #ifndef __MTV319_PORT_H__
  20. #define __MTV319_PORT_H__
  21. /*=============================================================================
  22. * Includes the user header files if neccessry.
  23. *===========================================================================*/
  24. #if defined(__KERNEL__) /* Linux kernel */
  25. #include <linux/io.h>
  26. #include <linux/kernel.h>
  27. #include <linux/delay.h>
  28. #include <linux/mm.h>
  29. #include <linux/mutex.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/string.h>
  32. #elif defined(WINCE) || defined(WINDOWS) || defined(WIN32)
  33. #include <windows.h>
  34. #include <winbase.h>
  35. #include <string.h>
  36. #ifdef WINCE
  37. #include <drvmsg.h>
  38. #endif
  39. #else
  40. #include <stdio.h>
  41. #include <string.h>
  42. #endif
  43. #ifdef __cplusplus
  44. extern "C"{
  45. #endif
  46. /*############################################################################
  47. #
  48. # COMMON configurations
  49. #
  50. ############################################################################*/
  51. /*============================================================================
  52. * The slave address for I2C and SPI.
  53. *===========================================================================*/
  54. #define RTV_CHIP_ADDR 0x86
  55. /*============================================================================
  56. * Modifies the basic data types if neccessry.
  57. *===========================================================================*/
  58. #define BOOL int
  59. #define S8 s8
  60. #define U8 u8
  61. #define S16 s16
  62. #define U16 u16
  63. #define S32 s32
  64. #define U32 u32
  65. #define INT int
  66. #define UINT unsigned int
  67. #define LONG long
  68. #define ULONG unsigned long
  69. #define INLINE inline
  70. /*============================================================================
  71. * Defines the package type of chip to target product.
  72. *===========================================================================*/
  73. #define RTV_CHIP_PKG_CSP
  74. /* #define RTV_CHIP_PKG_QFN */
  75. /*============================================================================
  76. * Defines the external source freqenecy in KHz.
  77. * Ex> #define RTV_SRC_CLK_FREQ_KHz 36000 // 36MHz
  78. *===========================================================================*/
  79. #define RTV_SRC_CLK_FREQ_KHz 24576
  80. /*============================================================================
  81. * Defines the Host interface.
  82. *===========================================================================*/
  83. #define RTV_IF_SPI /* AP: SPI Master Mode */
  84. /* #define RTV_IF_TSIF */ /* I2C + TSIF Master Mode*/
  85. /* #define RTV_IF_SPI_SLAVE */ /* AP: SPI Slave Mode*/
  86. /*============================================================================
  87. * Defines the polarity of interrupt if necessary.
  88. *===========================================================================*/
  89. #define RTV_INTR_POLARITY_LOW_ACTIVE
  90. /* #define RTV_INTR_POLARITY_HIGH_ACTIVE */
  91. /*============================================================================
  92. * Defines the delay macro in milliseconds.
  93. *===========================================================================*/
  94. #if defined(__KERNEL__) /* Linux kernel */
  95. #define RTV_DELAY_MS(ms) mdelay(ms)
  96. #elif defined(WINCE)
  97. #define RTV_DELAY_MS(ms) Sleep(ms)
  98. #else
  99. void mtv_delay_ms(int ms);
  100. #define RTV_DELAY_MS(ms) mtv_delay_ms(ms) /* TODO */
  101. #endif
  102. /*============================================================================
  103. * Defines the debug message macro.
  104. *===========================================================================*/
  105. #if 1
  106. #define RTV_DBGMSG0(fmt) printk(fmt)
  107. #define RTV_DBGMSG1(fmt, arg1) printk(fmt, arg1)
  108. #define RTV_DBGMSG2(fmt, arg1, arg2) printk(fmt, arg1, arg2)
  109. #define RTV_DBGMSG3(fmt, arg1, arg2, arg3) printk(fmt, arg1, arg2, arg3)
  110. #else
  111. /* To eliminates the debug messages. */
  112. #define RTV_DBGMSG0(fmt) do {} while (0)
  113. #define RTV_DBGMSG1(fmt, arg1) do {} while (0)
  114. #define RTV_DBGMSG2(fmt, arg1, arg2) do {} while (0)
  115. #define RTV_DBGMSG3(fmt, arg1, arg2, arg3) do {} while (0)
  116. #endif
  117. /*#### End of Common ###########*/
  118. /*#############################################################################
  119. #
  120. # T-DMB specific configurations
  121. #
  122. #############################################################################*/
  123. /* Determine if the FIC is not handled by interrupt. */
  124. #define RTV_FIC_POLLING_MODE
  125. /* Defines the number of sub channel to be open simultaneously. (AV + DATA) */
  126. #define RTV_MAX_NUM_USE_SUBCHANNEL 1
  127. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
  128. /* #define RTV_SPI_FIC_DECODE_IN_PLAY */
  129. /* The size of interrupt level for CIF mode of SPI interface. */
  130. #define RTV_SPI_CIF_MODE_INTERRUPT_SIZE (16 * 188)
  131. #elif defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
  132. /*========================================================*/
  133. /* Selects FIC transmission path when SCAN and PLAY state */
  134. /* NA: Not Applicable */
  135. /*========================================================*/
  136. /* #define RTV_FIC__SCAN_I2C__PLAY_NA */ /* Polling or Intrrupt. */
  137. /* #define RTV_FIC__SCAN_I2C__PLAY_I2C */ /* Polling or Intrrupt */
  138. #define RTV_FIC__SCAN_I2C__PLAY_TSIF /* Polling or Intrrupt */
  139. /* #define RTV_FIC__SCAN_TSIF__PLAY_NA */ /* Polling meaningless */
  140. /* #define RTV_FIC__SCAN_TSIF__PLAY_I2C */ /* Polling or Intrrupt */
  141. /* #define RTV_FIC__SCAN_TSIF__PLAY_TSIF */ /* Polling meaningless */
  142. #endif
  143. /* Determine if the output of error-tsp is disable. */
  144. /*#define RTV_ERROR_TSP_OUTPUT_DISABLE */
  145. #ifndef RTV_ERROR_TSP_OUTPUT_DISABLE
  146. /* Determine if the NULL PID will generated for error-tsp. */
  147. /*#define RTV_NULL_PID_GENERATE*/
  148. /* Determine if the sync-byte was insert for error-tsp forcely. */
  149. #define RTV_FORCE_INSERT_SYNC_BYTE
  150. #endif /* RTV_ERROR_TSP_OUTPUT_DISABLE */
  151. /* Determine if the CIF decoder is compiled with RAONTECH driver. */
  152. #define RTV_CIFDEC_IN_DRIVER
  153. #ifdef RTV_CIFDEC_IN_DRIVER
  154. /* Select the copying method of CIF decoded data(FIC and MSC).
  155. CIF decoder copy the decoded data into user space buffer direcly
  156. to fast operation.
  157. NOTE: Only applicable in RTV_CIF_MODE_ENABLED defined. */
  158. /* #define RTV_CIFDEC_DIRECT_COPY_USER_SPACE */
  159. #endif
  160. /*############################################################################
  161. #
  162. # Host Interface specific configurations
  163. #
  164. ############################################################################*/
  165. #if defined(RTV_IF_SPI)
  166. /*=================================================================
  167. * Defines the register I/O macros.
  168. *================================================================*/
  169. void mtv319_set_port_if(unsigned long interface);
  170. U8 mtv319_spi_read(U8 page, U8 reg);
  171. void mtv319_spi_read_burst(U8 page, U8 reg, U8 *buf, int size);
  172. void mtv319_spi_write(U8 page, U8 reg, U8 val);
  173. void mtv319_spi_recover(unsigned char *buf, unsigned int intr_size);
  174. extern U8 g_bRtvPage;
  175. static INLINE U8 RTV_REG_GET(U8 reg)
  176. {
  177. if (g_bRtvPage == 0xF)
  178. reg ^= 0x10;
  179. return (U8)mtv319_spi_read(g_bRtvPage, (U8)(reg));
  180. }
  181. #define RTV_REG_BURST_GET(reg, buf, size)\
  182. mtv319_spi_read_burst(g_bRtvPage, (U8)(reg), buf, (size))
  183. static INLINE void RTV_REG_SET(U8 reg, U8 val)
  184. {
  185. if (g_bRtvPage == 0xF)
  186. reg ^= 0x10;
  187. mtv319_spi_write(g_bRtvPage, (U8)(reg), (U8)(val));
  188. }
  189. #define RTV_REG_MASK_SET(reg, mask, val)\
  190. do { \
  191. U8 tmp; \
  192. tmp = (RTV_REG_GET(reg)|(U8)(mask))\
  193. & (U8)((~(mask))|(val));\
  194. RTV_REG_SET(reg, tmp); \
  195. } while (0)
  196. #define RTV_TSP_XFER_SIZE 188
  197. #elif defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
  198. /*=================================================================
  199. * Defines the TS format.
  200. *================================================================*/
  201. /* #define RTV_TSIF_FORMAT_0 */ /* EN_high, CLK_rising */
  202. #define RTV_TSIF_FORMAT_1 /* EN_high, CLK_falling */
  203. /* #define RTV_TSIF_FORMAT_2 */ /* EN_low, CLK_rising */
  204. /* #define RTV_TSIF_FORMAT_3 */ /* EN_low, CLK_falling */
  205. /* #define RTV_TSIF_FORMAT_4 */ /* EN_high, CLK_rising + 1CLK add */
  206. /* #define RTV_TSIF_FORMAT_5 */ /* EN_high, CLK_falling + 1CLK add */
  207. /* #define RTV_TSIF_FORMAT_6 */ /* Parallel: EN_high, CLK_falling */
  208. /*=================================================================
  209. * Defines the TSIF speed.
  210. *================================================================*/
  211. /* #define RTV_TSIF_SPEED_3_Mbps */ /* 2.41MHz */
  212. #define RTV_TSIF_SPEED_4_Mbps /* 3.62MHz */
  213. /* #define RTV_TSIF_SPEED_5_Mbps */ /* 4.8MHz */
  214. /* #define RTV_TSIF_SPEED_6_Mbps */ /* 5.8MHz */
  215. /* #define RTV_TSIF_SPEED_8_Mbps */ /* 7.2MHz */
  216. /* #define RTV_TSIF_SPEED_10_Mbps */ /* 9.6MHz */
  217. /* #define RTV_TSIF_SPEED_15_Mbps */ /* 14.5MHz */
  218. /* #define RTV_TSIF_SPEED_30_Mbps */ /* 28.8MHz */
  219. /* #define RTV_TSIF_SPEED_60_Mbps */ /* 58.5MHz */
  220. /*=================================================================
  221. * Defines the TSP size. 188 or 204
  222. *================================================================*/
  223. #define RTV_TSP_XFER_SIZE 188
  224. /*=================================================================
  225. * Defines the register I/O macros.
  226. *================================================================*/
  227. U8 tdmb_i2c_read(U8 chipid, U8 reg);
  228. void tdmb_i2c_read_burst(U8 reg, U8 *buf, int size);
  229. void tdmb_i2c_write(U8 chipid, U8 reg, U8 val);
  230. extern U8 g_bRtvPage;
  231. static INLINE U8 RTV_REG_GET(U8 reg)
  232. {
  233. if (g_bRtvPage != 0xF)
  234. return (U8)tdmb_i2c_read((U8)RTV_CHIP_ADDR, (U8)(reg));
  235. else {
  236. tdmb_i2c_write(RTV_CHIP_ADDR, 0x02, (0x62|0x80));
  237. return (U8)tdmb_i2c_read((U8)(0x62), (U8)(reg));
  238. }
  239. }
  240. #define RTV_REG_BURST_GET(reg, buf, size)\
  241. tdmb_i2c_read_burst((U8)(reg), buf, size)
  242. static INLINE void RTV_REG_SET(U8 reg, U8 val)
  243. {
  244. if (g_bRtvPage != 0xF)
  245. tdmb_i2c_write(RTV_CHIP_ADDR, (U8)(reg), (U8)(val));
  246. else {
  247. tdmb_i2c_write(RTV_CHIP_ADDR, 0x02, (0x62|0x80));
  248. tdmb_i2c_write(0x62, (U8)(reg), (U8)(val));
  249. }
  250. }
  251. #define RTV_REG_MASK_SET(reg, mask, val)\
  252. do { \
  253. U8 tmp; \
  254. tmp = (RTV_REG_GET(reg)|(U8)(mask))\
  255. & (U8)((~(mask))|(val));\
  256. RTV_REG_SET(reg, tmp); \
  257. } while (0)
  258. #elif defined(RTV_IF_EBI2)
  259. /*=================================================================
  260. * Defines the register I/O macros.
  261. *================================================================*/
  262. U8 tdmb_ebi2_read(U8 page, U8 reg);
  263. void tdmb_ebi2_read_burst(U8 page, U8 reg, U8 *buf, int size);
  264. void tdmb_ebi2_write(U8 page, U8 reg, U8 val);
  265. extern U8 g_bRtvPage;
  266. static INLINE U8 RTV_REG_GET(U8 reg)
  267. {
  268. if (g_bRtvPage == 0xF)
  269. reg ^= 0x10;
  270. return (U8)tdmb_ebi2_read(g_bRtvPage, (U8)(reg));
  271. }
  272. #define RTV_REG_BURST_GET(reg, buf, size)\
  273. tdmb_ebi2_read_burst(g_bRtvPage, (U8)(reg), buf, (size))
  274. static INLINE void RTV_REG_SET(U8 reg, U8 val)
  275. {
  276. if (g_bRtvPage == 0xF)
  277. reg ^= 0x10;
  278. tdmb_ebi2_write(g_bRtvPage, (U8)(reg), (U8)(val));
  279. }
  280. #define RTV_REG_MASK_SET(reg, mask, val)\
  281. do { \
  282. U8 tmp; \
  283. tmp = (RTV_REG_GET(reg)|(U8)(mask))\
  284. & (U8)((~(mask))|(val));\
  285. RTV_REG_SET(reg, tmp); \
  286. } while (0)
  287. #define RTV_TSP_XFER_SIZE 188
  288. #else
  289. #error "Must define the interface definition !"
  290. #endif
  291. /*############################################################################
  292. #
  293. # Pre-definintion by RAONTECH.
  294. #
  295. ############################################################################*/
  296. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
  297. #ifndef RTV_FIC_POLLING_MODE
  298. #define RTV_FIC_SPI_INTR_ENABLED /* FIC SPI Interrupt use. */
  299. #endif
  300. #else
  301. #if !defined(RTV_FIC_POLLING_MODE)\
  302. && !defined(RTV_FIC__SCAN_TSIF__PLAY_NA)\
  303. && !defined(RTV_FIC__SCAN_TSIF__PLAY_TSIF)
  304. #define RTV_FIC_I2C_INTR_ENABLED /* FIC I2C Interrupt use. */
  305. #endif
  306. #endif
  307. /* Defines the FIC recevied in play state or not. */
  308. #if defined(RTV_SPI_FIC_DECODE_IN_PLAY)\
  309. || defined(RTV_FIC__SCAN_I2C__PLAY_TSIF)\
  310. || defined(RTV_FIC__SCAN_TSIF__PLAY_TSIF)
  311. #define RTV_FIC_CIFMODE_ENABLED
  312. #endif
  313. #if (RTV_MAX_NUM_USE_SUBCHANNEL >= 2)
  314. #define RTV_MSC_CIFMODE_ENABLED
  315. #endif
  316. #if defined(RTV_MSC_CIFMODE_ENABLED) || defined(RTV_FIC_CIFMODE_ENABLED)
  317. #define RTV_CIF_MODE_ENABLED /* CIF decoder enabled */
  318. #endif
  319. /*############################################################################
  320. #
  321. # Defines the critical object and macros.
  322. #
  323. ############################################################################*/
  324. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)\
  325. || defined(RTV_FIC_I2C_INTR_ENABLED)
  326. #if defined(__KERNEL__)
  327. extern struct mutex raontv_guard;
  328. #define RTV_GUARD_INIT mutex_init(&raontv_guard)
  329. #define RTV_GUARD_LOCK mutex_lock(&raontv_guard)
  330. #define RTV_GUARD_FREE mutex_unlock(&raontv_guard)
  331. #define RTV_GUARD_DEINIT ((void)0)
  332. #elif defined(WINCE) || defined(WINDOWS) || defined(WIN32)
  333. extern CRITICAL_SECTION raontv_guard;
  334. #define RTV_GUARD_INIT InitializeCriticalSection(&raontv_guard)
  335. #define RTV_GUARD_LOCK EnterCriticalSection(&raontv_guard)
  336. #define RTV_GUARD_FREE LeaveCriticalSection(&raontv_guard)
  337. #define RTV_GUARD_DEINIT DeleteCriticalSection(&raontv_guard)
  338. #else
  339. /* temp: TODO */
  340. #define RTV_GUARD_INIT ((void)0)
  341. #define RTV_GUARD_LOCK ((void)0)
  342. #define RTV_GUARD_FREE ((void)0)
  343. #define RTV_GUARD_DEINIT ((void)0)
  344. #endif
  345. #else
  346. #define RTV_GUARD_INIT ((void)0)
  347. #define RTV_GUARD_LOCK ((void)0)
  348. #define RTV_GUARD_FREE ((void)0)
  349. #define RTV_GUARD_DEINIT ((void)0)
  350. #endif
  351. /*############################################################################
  352. #
  353. # Check erros by user-configurations.
  354. #
  355. ############################################################################*/
  356. #if !defined(RTV_CHIP_PKG_CSP) && !defined(RTV_CHIP_PKG_QFN)
  357. #error "Must define the package type !"
  358. #endif
  359. #if defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)\
  360. || defined(RTV_IF_SPI)
  361. #if (RTV_CHIP_ADDR >= 0xFF)
  362. #error "Invalid chip address"
  363. #endif
  364. #elif defined(RTV_IF_EBI2)
  365. #else
  366. #error "Must define the interface definition !"
  367. #endif
  368. #ifndef RTV_MAX_NUM_USE_SUBCHANNEL
  369. #error "Should be define number of subchannel!"
  370. #endif
  371. #if (RTV_MAX_NUM_USE_SUBCHANNEL < 0) || (RTV_MAX_NUM_USE_SUBCHANNEL > 4)
  372. #error "Must 0 or 4 for subchannel. TDMB(1ea), DAB(2ea), DABP(1ea)"
  373. #endif
  374. #if defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
  375. #if !defined(RTV_FIC__SCAN_I2C__PLAY_NA)\
  376. && !defined(RTV_FIC__SCAN_I2C__PLAY_I2C)\
  377. && !defined(RTV_FIC__SCAN_I2C__PLAY_TSIF)\
  378. && !defined(RTV_FIC__SCAN_TSIF__PLAY_NA)\
  379. && !defined(RTV_FIC__SCAN_TSIF__PLAY_I2C)\
  380. && !defined(RTV_FIC__SCAN_TSIF__PLAY_TSIF)
  381. #error "No FIC path was defined for TSIF!"
  382. #endif
  383. #if defined(RTV_FIC__SCAN_I2C__PLAY_NA)\
  384. && defined(RTV_FIC__SCAN_I2C__PLAY_I2C)\
  385. && defined(RTV_FIC__SCAN_I2C__PLAY_TSIF)\
  386. && defined(RTV_FIC__SCAN_TSIF__PLAY_NA)\
  387. && defined(RTV_FIC__SCAN_TSIF__PLAY_I2C)\
  388. && defined(RTV_FIC__SCAN_TSIF__PLAY_TSIF)
  389. #error "Should select only one FIC path for TSIF!"
  390. #endif
  391. #endif
  392. #ifndef RTV_TSP_XFER_SIZE
  393. #error "Must define the RTV_TSP_XFER_SIZE definition !"
  394. #endif
  395. #if (RTV_TSP_XFER_SIZE != 188) && (RTV_TSP_XFER_SIZE != 204)
  396. #error "Must 188 or 204 for TS size"
  397. #endif
  398. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
  399. #ifdef RTV_CIF_MODE_ENABLED
  400. #ifdef RTV_SPI_CIF_MODE_INTERRUPT_SIZE
  401. #if ((RTV_SPI_CIF_MODE_INTERRUPT_SIZE % 188) != 0)
  402. #error "Must multiple of 188"
  403. #endif
  404. #else
  405. #error "Should defined"
  406. #endif
  407. #endif
  408. #if defined(RTV_FIC_POLLING_MODE) && defined(RTV_SPI_FIC_DECODE_IN_PLAY)
  409. #error "Not support!"
  410. #endif
  411. #endif
  412. #if defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
  413. #endif
  414. void rtvOEM_PowerOn(int on);
  415. #ifdef __cplusplus
  416. }
  417. #endif
  418. #endif /* __MTV319_PORT_H__ */