raontv_port.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /******************************************************************************
  2. * (c) COPYRIGHT 2010 RAONTECH, Inc. ALL RIGHTS RESERVED.
  3. *
  4. * TITLE : RAONTECH TV configuration header file.
  5. *
  6. * FILENAME : raontv_port.h
  7. *
  8. * DESCRIPTION :
  9. * Configuration for RAONTECH TV Services.
  10. *
  11. ******************************************************************************/
  12. /******************************************************************************
  13. * REVISION HISTORY
  14. *
  15. * DATE NAME REMARKS
  16. * ---------- ------------- ------------------------------------------------
  17. * 07/26/2013 Yang, Maverick Created.
  18. ******************************************************************************/
  19. #ifndef __RAONTV_PORT_H__
  20. #define __RAONTV_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/jiffies.h>
  32. #elif defined(WINCE)
  33. #include <windows.h>
  34. #include <drvmsg.h>
  35. #else
  36. #include <stdio.h>
  37. #endif
  38. #ifdef __cplusplus
  39. extern "C"{
  40. #endif
  41. /*############################################################################
  42. #
  43. # COMMON configurations
  44. #
  45. ############################################################################*/
  46. /*============================================================================
  47. * The slave address for I2C and SPI, the base address for EBI2.
  48. *===========================================================================*/
  49. #define RAONTV_CHIP_ADDR 0x86
  50. /*============================================================================
  51. * Modifies the basic data types if neccessry.
  52. *===========================================================================*/
  53. typedef int BOOL;
  54. typedef signed char S8;
  55. typedef unsigned char U8;
  56. typedef signed short S16;
  57. typedef unsigned short U16;
  58. typedef signed int S32;
  59. typedef unsigned int U32;
  60. typedef int INT;
  61. typedef unsigned int UINT;
  62. typedef long LONG;
  63. typedef unsigned long ULONG;
  64. typedef volatile U8 VU8;
  65. typedef volatile U16 VU16;
  66. typedef volatile U32 VU32;
  67. #if defined(__GNUC__)
  68. #define INLINE inline
  69. #elif defined(_WIN32)
  70. #define INLINE __inline
  71. #elif defined(__ARMCC_VERSION)
  72. #define INLINE __inline
  73. #else
  74. /* Need to modified */
  75. #define INLINE inline
  76. #endif
  77. /*============================================================================
  78. * Selects the TV mode(s) to target product.
  79. *===========================================================================*/
  80. #define RTV_ISDBT_ENABLE
  81. /*============================================================================
  82. * Defines the package type of chip to target product.
  83. *===========================================================================*/
  84. #define RAONTV_CHIP_PKG_WLCSP // MTV222
  85. //#define RAONTV_CHIP_PKG_QFN // MTV818A
  86. /*============================================================================
  87. * Defines the external source freqenecy in KHz.
  88. * Ex> #define RTV_SRC_CLK_FREQ_KHz 36000 // 36MHz
  89. *=============================================================================
  90. * MTV250 : #define RTV_SRC_CLK_FREQ_KHz 32000 //must be defined
  91. * MTV350 : #define RTV_SRC_CLK_FREQ_KHz 19200 //must be defined
  92. *===========================================================================*/
  93. //#define RTV_SRC_CLK_FREQ_KHz 36000
  94. //#define RTV_SRC_CLK_FREQ_KHz 32000
  95. #define RTV_SRC_CLK_FREQ_KHz 19200
  96. /*============================================================================
  97. * Define the power type.
  98. *============================================================================*/
  99. //#define RTV_PWR_EXTERNAL
  100. #define RTV_PWR_LDO
  101. /*============================================================================
  102. * Defines the Host interface.
  103. *===========================================================================*/
  104. //#define RTV_IF_MPEG2_SERIAL_TSIF // I2C + TSIF Master Mode.
  105. //#define RTV_IF_QUALCOMM_TSIF // I2C + TSIF Master Mode
  106. #define RTV_IF_SPI // AP: SPI Master Mode
  107. //#define RTV_IF_SPI_SLAVE // AP: SPI Slave Mode
  108. //#define RTV_IF_EBI2 // External Bus Interface Slave Mode
  109. /*#################################
  110. # Pre-definintion by RAONTECH.
  111. ###################################*/
  112. #if defined(RTV_IF_MPEG2_SERIAL_TSIF) || defined(RTV_IF_QUALCOMM_TSIF)\
  113. || defined(RTV_IF_MPEG2_PARALLEL_TSIF)
  114. #define RTV_IF_TSIF /* All TSIF */
  115. #endif
  116. #if defined(RTV_IF_MPEG2_SERIAL_TSIF) || defined(RTV_IF_QUALCOMM_TSIF)
  117. #define RTV_IF_SERIAL_TSIF /* Serial TSIF */
  118. #endif
  119. /*============================================================================
  120. * Defines the delay macro in milliseconds.
  121. *===========================================================================*/
  122. #if defined(__KERNEL__) /* Linux kernel */
  123. static INLINE void RTV_DELAY_MS(UINT ms)
  124. {
  125. unsigned long start_jiffies, end_jiffies;
  126. UINT diff_time;
  127. UINT _1ms_cnt = ms;
  128. start_jiffies = get_jiffies_64();
  129. do {
  130. end_jiffies = get_jiffies_64();
  131. diff_time = jiffies_to_msecs(end_jiffies - start_jiffies);
  132. if (diff_time >= ms)
  133. break;
  134. mdelay(1);
  135. } while (--_1ms_cnt);
  136. }
  137. #elif defined(WINCE)
  138. #define RTV_DELAY_MS(ms) Sleep(ms)
  139. #else
  140. extern void mtv_delay_ms(int ms);
  141. #define RTV_DELAY_MS(ms) mtv_delay_ms(ms) // TODO
  142. #endif
  143. /*============================================================================
  144. * Defines the debug message macro.
  145. *===========================================================================*/
  146. #if 1
  147. #define RTV_DBGMSG0(fmt) printk(fmt)
  148. #define RTV_DBGMSG1(fmt, arg1) printk(fmt, arg1)
  149. #define RTV_DBGMSG2(fmt, arg1, arg2) printk(fmt, arg1, arg2)
  150. #define RTV_DBGMSG3(fmt, arg1, arg2, arg3) printk(fmt, arg1, arg2, arg3)
  151. #else
  152. /* To eliminates the debug messages. */
  153. #define RTV_DBGMSG0(fmt) ((void)0)
  154. #define RTV_DBGMSG1(fmt, arg1) ((void)0)
  155. #define RTV_DBGMSG2(fmt, arg1, arg2) ((void)0)
  156. #define RTV_DBGMSG3(fmt, arg1, arg2, arg3) ((void)0)
  157. #endif
  158. /*#### End of Common ###########*/
  159. /*############################################################################
  160. #
  161. # ISDB-T specific configurations
  162. #
  163. ############################################################################*/
  164. /* Determine if the output of error-tsp is disable. */
  165. #define RTV_ERROR_TSP_OUTPUT_DISABLE
  166. #ifndef RTV_ERROR_TSP_OUTPUT_DISABLE
  167. /* Determine if the NULL PID will generated for error-tsp. */
  168. //#define RTV_NULL_PID_GENERATE
  169. #endif /* RTV_ERROR_TSP_OUTPUT_DISABLE */
  170. /*============================================================================
  171. * Defines the HRM ON setting Enable.
  172. * In order to reject GSM/CDMA blocker, HRM ON must be defined.
  173. *===========================================================================*/
  174. #if defined(RTV_ISDBT_ENABLE)
  175. #ifdef RAONTV_CHIP_PKG_WLCSP
  176. #define RAONTV_CHIP_PKG_WLCSP_HRM_ON
  177. #endif
  178. #endif
  179. /*============================================================================
  180. * Defines the polarity of interrupt if necessary.
  181. *===========================================================================*/
  182. #define RTV_INTR_POLARITY_LOW_ACTIVE
  183. /* #define RTV_INTR_POLARITY_HIGH_ACTIVE */
  184. /*############################################################################
  185. #
  186. # Host Interface specific configurations
  187. #
  188. ############################################################################*/
  189. extern U8 g_bRtvPage;
  190. #if defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
  191. /*=================================================================
  192. * Defines the TSIF interface for MPEG2 or QUALCOMM TSIF.
  193. *================================================================*/
  194. //#define RTV_TSIF_FORMAT_1
  195. //#define RTV_TSIF_FORMAT_2
  196. #define RTV_TSIF_FORMAT_3
  197. //#define RTV_TSIF_FORMAT_4
  198. //#define RTV_TSIF_FORMAT_5
  199. //#define RTV_TSIF_CLK_SPEED_DIV_2 // 12MHz
  200. //#define RTV_TSIF_CLK_SPEED_DIV_4 // 6MHz
  201. #define RTV_TSIF_CLK_SPEED_DIV_6 // 3MHz
  202. //#define RTV_TSIF_CLK_SPEED_DIV_8 // 1.5MHz
  203. /*=================================================================
  204. * Defines the register I/O macros.
  205. *================================================================*/
  206. unsigned char mtv_i2c_read(U8 reg);
  207. void mtv_i2c_read_burst(U8 reg, U8 *buf, int size);
  208. void mtv_i2c_write(U8 reg, U8 val);
  209. #define RTV_REG_GET(reg) mtv_i2c_read((U8)(reg))
  210. #define RTV_REG_BURST_GET(reg, buf, size) mtv_i2c_read_burst((U8)(reg), buf, size)
  211. #define RTV_REG_SET(reg, val) mtv_i2c_write((U8)(reg), (U8)(val))
  212. #define RTV_REG_MASK_SET(reg, mask, val)\
  213. do { \
  214. U8 tmp; \
  215. tmp = (RTV_REG_GET(reg)|(U8)(mask)) & (U8)((~(mask))|(val));\
  216. RTV_REG_SET(reg, tmp); \
  217. } while(0)
  218. #define RTV_TSP_XFER_SIZE 188
  219. #elif defined(RTV_IF_SPI)
  220. /*=================================================================
  221. * Defines the register I/O macros.
  222. *================================================================*/
  223. unsigned char mtv222_spi_read(U8 page, U8 reg);
  224. void mtv222_spi_read_burst(U8 page, U8 reg, U8 *buf, int size);
  225. void mtv222_spi_write(U8 page, U8 reg, U8 val);
  226. #define RTV_REG_GET(reg) (U8)mtv222_spi_read(g_bRtvPage, (U8)(reg))
  227. #define RTV_REG_BURST_GET(reg, buf, size) mtv222_spi_read_burst(g_bRtvPage, (U8)(reg), buf, (size))
  228. #define RTV_REG_SET(reg, val) mtv222_spi_write(g_bRtvPage, (U8)(reg), (U8)(val))
  229. #define RTV_REG_MASK_SET(reg, mask, val)\
  230. do { \
  231. U8 tmp; \
  232. tmp = (RTV_REG_GET(reg)|(U8)(mask)) & (U8)((~(mask))|(val));\
  233. RTV_REG_SET(reg, tmp); \
  234. } while(0)
  235. #define RTV_TSP_XFER_SIZE 188
  236. #elif defined(RTV_IF_EBI2)
  237. unsigned char mtv_ebi2_read(unsigned char reg);
  238. void mtv_ebi2_read_burst(unsigned char reg, unsigned char *buf, int size);
  239. void mtv_ebi2_write(unsigned char reg, unsigned char val);
  240. #define RTV_REG_GET(reg) (U8)mtv_ebi2_read((U8)(reg))
  241. #define RTV_REG_BURST_GET(reg, buf, size) mtv_ebi2_read_burst((U8)(reg), buf, size)
  242. #define RTV_REG_SET(reg, val) mtv_ebi2_write((U8)(reg), (U8)(val))
  243. #define RTV_REG_MASK_SET(reg, mask, val) \
  244. do { \
  245. U8 tmp; \
  246. tmp = (RTV_REG_GET(reg)|(U8)(mask)) & (U8)((~(mask))|(val)); \
  247. RTV_REG_SET(reg, tmp); \
  248. } while (0)
  249. #define RTV_TSP_XFER_SIZE 188
  250. #else
  251. #error "Must define the interface definition !"
  252. #endif
  253. /*############################################################################
  254. #
  255. # Pre-definintion by RAONTECH.
  256. # Assume that FM only project was not exist.
  257. #
  258. ############################################################################*/
  259. #define RTV_SPI_MSC1_ENABLED /* to backward */
  260. #if (defined(RTV_TDMB_ENABLE)||defined(RTV_DAB_ENABLE))\
  261. && !(defined(RTV_ISDBT_ENABLE)||defined(RTV_FM_ENABLE))
  262. /* Only TDMB or DAB enabled. */
  263. #define RTV_TDMBorDAB_ONLY_ENABLED
  264. #elif !(defined(RTV_TDMB_ENABLE)||defined(RTV_DAB_ENABLE) || defined(RTV_FM_ENABLE))\
  265. && defined(RTV_ISDBT_ENABLE)
  266. /* Only 1SEG enabled. */
  267. #define RTV_ISDBT_ONLY_ENABLED
  268. #elif (defined(RTV_TDMB_ENABLE)||defined(RTV_DAB_ENABLE)) && defined(RTV_FM_ENABLE)\
  269. && !defined(RTV_ISDBT_ENABLE)
  270. /* Only TDMB/DAB and FM enabled. */
  271. #define RTV_TDMBorDAB_FM_ENABLED
  272. #endif
  273. /*############################################################################
  274. # Define the critical object.
  275. ############################################################################*/
  276. #if defined(RTV_IF_SPI) || defined(RTV_FIC_I2C_INTR_ENABLED)
  277. #if defined(__KERNEL__)
  278. extern struct mutex raontv_guard;
  279. #define RTV_GUARD_INIT mutex_init(&raontv_guard)
  280. #define RTV_GUARD_LOCK mutex_lock(&raontv_guard)
  281. #define RTV_GUARD_FREE mutex_unlock(&raontv_guard)
  282. #define RTV_GUARD_DEINIT ((void)0)
  283. #elif defined(WINCE)
  284. extern CRITICAL_SECTION raontv_guard;
  285. #define RTV_GUARD_INIT InitializeCriticalSection(&raontv_guard)
  286. #define RTV_GUARD_LOCK EnterCriticalSection(&raontv_guard)
  287. #define RTV_GUARD_FREE LeaveCriticalSection(&raontv_guard)
  288. #define RTV_GUARD_DEINIT DeleteCriticalSection(&raontv_guard)
  289. #else
  290. // temp: TODO
  291. #define RTV_GUARD_INIT ((void)0)
  292. #define RTV_GUARD_LOCK ((void)0)
  293. #define RTV_GUARD_FREE ((void)0)
  294. #define RTV_GUARD_DEINIT ((void)0)
  295. #endif
  296. #else
  297. #define RTV_GUARD_INIT ((void)0)
  298. #define RTV_GUARD_LOCK ((void)0)
  299. #define RTV_GUARD_FREE ((void)0)
  300. #define RTV_GUARD_DEINIT ((void)0)
  301. #endif
  302. /*############################################################################
  303. #
  304. # Check erros by user-configurations.
  305. #
  306. ############################################################################*/
  307. #if !defined(RAONTV_CHIP_PKG_WLCSP) && !defined(RAONTV_CHIP_PKG_QFN)
  308. #error "Must define the package type !"
  309. #endif
  310. #if !defined(RTV_PWR_EXTERNAL) && !defined(RTV_PWR_LDO)
  311. #error "Must define the power type !"
  312. #endif
  313. #if defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)\
  314. || defined(RTV_IF_SPI)
  315. #if (RAONTV_CHIP_ADDR >= 0xFF)
  316. #error "Invalid chip address"
  317. #endif
  318. #elif defined(RTV_IF_EBI2)
  319. #else
  320. #error "Must define the interface definition !"
  321. #endif
  322. void rtvOEM_ConfigureInterrupt(void);
  323. void rtvOEM_PowerOn(int on);
  324. #ifdef __cplusplus
  325. }
  326. #endif
  327. #endif /* __RAONTV_PORT_H__ */