mtv23x_port.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /******************************************************************************
  2. * (c) COPYRIGHT 2013 RAONTECH, Inc. ALL RIGHTS RESERVED.
  3. *
  4. * TITLE : MTV23x configuration header file.
  5. *
  6. * FILENAME : mtv23x_port.h
  7. *
  8. * DESCRIPTION :
  9. * Configuration for RAONTECH MTV23x Services.
  10. *
  11. ******************************************************************************/
  12. /******************************************************************************
  13. * REVISION HISTORY
  14. *
  15. * DATE NAME REMARKS
  16. * ---------- ------------- ------------------------------------------------
  17. * 03/03/2013 Yang, Maverick Created.
  18. ******************************************************************************/
  19. #ifndef __MTV23X_PORT_H__
  20. #define __MTV23X_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. #include <linux/jiffies.h>
  33. #elif defined(WINCE) || defined(WINDOWS) || defined(WIN32)
  34. #include <stdio.h>
  35. #include <windows.h>
  36. #include <winbase.h>
  37. #include <string.h>
  38. #ifdef WINCE
  39. #include <drvmsg.h>
  40. #endif
  41. #else
  42. #include <stdio.h>
  43. #include <string.h>
  44. #endif
  45. #ifdef __cplusplus
  46. extern "C"{
  47. #endif
  48. /*############################################################################
  49. #
  50. # COMMON configurations
  51. #
  52. ############################################################################*/
  53. /*============================================================================
  54. * The slave address for I2C and SPI.
  55. *===========================================================================*/
  56. #define RTV_CHIP_ADDR 0x43 //7bit I2C Address ID
  57. /*============================================================================
  58. * Modifies the basic data types if necessary.
  59. *===========================================================================*/
  60. typedef int BOOL;
  61. typedef signed char S8;
  62. typedef unsigned char U8;
  63. typedef signed short S16;
  64. typedef unsigned short U16;
  65. typedef signed int S32;
  66. typedef unsigned int U32;
  67. typedef int INT;
  68. typedef unsigned int UINT;
  69. typedef long LONG;
  70. typedef unsigned long ULONG;
  71. typedef volatile U8 VU8;
  72. typedef volatile U16 VU16;
  73. typedef volatile U32 VU32;
  74. #if defined(__GNUC__)
  75. #define INLINE inline
  76. #elif defined(WINCE) || defined(WINDOWS) || defined(WIN32)
  77. #define INLINE __inline
  78. #elif defined(__ARMCC_VERSION)
  79. #define INLINE __inline
  80. #else
  81. /* Need to modified */
  82. #define INLINE inline
  83. #endif
  84. /*==============================================================================
  85. * Selects the TV mode(s) to target product.
  86. *============================================================================*/
  87. #define RTV_ISDBT_ENABLE
  88. //#define RTV_DVBT_ENABLE
  89. #if defined(RTV_ISDBT_ENABLE)
  90. // #define RTV_ISDBT_1SEG_LPMODE_ENABLE
  91. #endif
  92. /*============================================================================
  93. * Defines the Dual Diversity Enable
  94. *===========================================================================*/
  95. //#define RTV_DUAL_DIVERISTY_ENABLE
  96. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  97. extern U8 g_div_i2c_chip_id;
  98. #define RTV_CHIP_ADDR_SLAVE 0x44
  99. // #defined RTV_DIVER_TWO_XTAL_USED //define for two X-TAL using both M,S
  100. #endif
  101. /*============================================================================
  102. * Defines the power Mode
  103. *===========================================================================*/
  104. //#define RTV_EXT_POWER_MODE
  105. /*============================================================================
  106. * Defines the package type of chip to target product.
  107. *===========================================================================*/
  108. //#define RTV_CHIP_PKG_CSP
  109. #define RTV_CHIP_PKG_QFN
  110. /*============================================================================
  111. * Defines the external source frequency in KHz.
  112. * Ex> #define RTV_SRC_CLK_FREQ_KHz 32000 // 32MHz
  113. *===========================================================================*/
  114. #define RTV_SRC_CLK_FREQ_KHz 32000//32MHz
  115. //#define RTV_SRC_CLK_FREQ_KHz 19200//19.MHz
  116. /*============================================================================
  117. * Defines the Host interface.
  118. *===========================================================================*/
  119. #define RTV_IF_SPI /* AP: SPI Master Mode */
  120. //#define RTV_IF_TSIF_0 /* I2C + TSIF0<GPDx pinout> for Serial Out Master Mode*/
  121. //#define RTV_IF_TSIF_1 /* I2C + TSIF1<GDDx pinout> For Serial/Parallel Out Master Mode*/
  122. //#define RTV_IF_SPI_SLAVE /* AP: SPI Slave Mode: control: I2C, data: SPI */
  123. //#define RTV_IF_SPI_TSIFx /* AP: SPI Master Mode for Control and please */
  124. /* define RTV_IF_TSIF_0 or RTV_IF_TSIF_1 for TSIF */
  125. #if defined(RTV_IF_SPI_TSIFx)
  126. #if defined(RTV_IF_TSIF_0)
  127. #error "TSIF0 can't use in case of SPI used for Register Control"
  128. #endif
  129. #endif
  130. #if defined(RTV_IF_TSIF_0) || defined(RTV_IF_TSIF_1) || defined(RTV_IF_SPI_SLAVE)
  131. //#define RTV_IF_CSI656_RAW_8BIT_ENABLE /*Sync signal pre-move(4clock) + 1 clock add Mode*/
  132. #endif
  133. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  134. #if defined(RTV_IF_TSIF_1) || defined(RTV_IF_SPI) || defined(RTV_IF_SPI_SLAVE)
  135. #error "Diversity function is not supported for defined interface"
  136. #endif
  137. #endif
  138. /*============================================================================
  139. * Defines the feature of SPI speed(> 30MHz) for SPI interface.
  140. *===========================================================================*/
  141. #if defined(RTV_IF_SPI)
  142. //#define RTV_SPI_HIGH_SPEED_ENABLE
  143. #endif
  144. /* Determine if the output of error-tsp is disable. */
  145. #define RTV_ERROR_TSP_OUTPUT_DISABLE
  146. #define RTV_NULL_PID_TSP_OUTPUT_DISABLE
  147. #ifndef RTV_ERROR_TSP_OUTPUT_DISABLE
  148. /* Determine if the NULL PID will generated for error-tsp. */
  149. //#define RTV_NULL_PID_GENERATE
  150. #endif /* RTV_ERROR_TSP_OUTPUT_DISABLE */
  151. #if defined(RTV_IF_TSIF_0) && defined(RTV_IF_TSIF_1)
  152. /*If TSIF0 & TSIF1 is Enabled, TS0= LayerA, TS1 = LayerB out..*/
  153. // #define DUAL_PORT_TSOUT_ENABLE
  154. #endif
  155. /*============================================================================
  156. * Defines the polarity of interrupt if necessary.
  157. *===========================================================================*/
  158. #define RTV_INTR_POLARITY_LOW_ACTIVE
  159. //#define RTV_INTR_POLARITY_HIGH_ACTIVE
  160. /*============================================================================
  161. * Defines the delay macro in milliseconds.
  162. *===========================================================================*/
  163. #if defined(__KERNEL__) /* Linux kernel */
  164. static INLINE void RTV_DELAY_MS(UINT ms)
  165. {
  166. unsigned long start_jiffies, end_jiffies;
  167. UINT diff_time;
  168. UINT _1ms_cnt = ms;
  169. start_jiffies = get_jiffies_64();
  170. do {
  171. end_jiffies = get_jiffies_64();
  172. diff_time = jiffies_to_msecs(end_jiffies - start_jiffies);
  173. if (diff_time >= ms)
  174. break;
  175. mdelay(1);
  176. } while (--_1ms_cnt);
  177. }
  178. #elif defined(WINCE)
  179. #define RTV_DELAY_MS(ms) Sleep(ms)
  180. #else
  181. void mtv_delay_ms(int ms);
  182. #define RTV_DELAY_MS(ms) mtv_delay_ms(ms) /* TODO */
  183. #endif
  184. /*============================================================================
  185. * Defines the debug message macro.
  186. *===========================================================================*/
  187. #if 1
  188. #define RTV_DBGMSG0(fmt) printk(fmt)
  189. #define RTV_DBGMSG1(fmt, arg1) printk(fmt, arg1)
  190. #define RTV_DBGMSG2(fmt, arg1, arg2) printk(fmt, arg1, arg2)
  191. #define RTV_DBGMSG3(fmt, arg1, arg2, arg3) printk(fmt, arg1, arg2, arg3)
  192. #else
  193. /* To eliminates the debug messages. */
  194. #define RTV_DBGMSG0(fmt) do {} while (0)
  195. #define RTV_DBGMSG1(fmt, arg1) do {} while (0)
  196. #define RTV_DBGMSG2(fmt, arg1, arg2) do {} while (0)
  197. #define RTV_DBGMSG3(fmt, arg1, arg2, arg3) do {} while (0)
  198. #endif
  199. /*#### End of Common ###########*/
  200. /*############################################################################
  201. #
  202. # ISDB-T specific configurations
  203. #
  204. ############################################################################*/
  205. /*############################################################################
  206. #
  207. # Host Interface specific configurations
  208. #
  209. ############################################################################*/
  210. #if defined(RTV_IF_SPI) || defined(RTV_IF_SPI_TSIFx)
  211. /*=================================================================
  212. * Defines the register I/O macros.
  213. *================================================================*/
  214. U8 mtv23x_spi_read(U8 page, U8 reg);
  215. void mtv23x_spi_read_burst(U8 page, U8 reg, U8 *buf, int size);
  216. void mtv23x_spi_write(U8 page, U8 reg, U8 val);
  217. extern U8 g_bRtvPage;
  218. static INLINE U8 RTV_REG_GET(U8 reg)
  219. {
  220. return (U8)mtv23x_spi_read(g_bRtvPage, (U8)(reg));
  221. }
  222. #define RTV_REG_BURST_GET(reg, buf, size)\
  223. mtv23x_spi_read_burst(g_bRtvPage, (U8)(reg), buf, (size))
  224. #define RTV_REG_SET(reg, val)\
  225. mtv23x_spi_write(g_bRtvPage, (U8)(reg), (U8)(val))
  226. #define RTV_REG_MASK_SET(reg, mask, val)\
  227. do { \
  228. U8 tmp; \
  229. tmp = (RTV_REG_GET(reg)|(U8)(mask))\
  230. & (U8)((~(mask))|(val));\
  231. RTV_REG_SET(reg, tmp); \
  232. } while (0)
  233. #define RTV_TSP_XFER_SIZE 188
  234. #endif
  235. #if defined(RTV_IF_TSIF_0) || defined(RTV_IF_TSIF_1) || defined(RTV_IF_SPI_SLAVE)
  236. /*=================================================================
  237. * Defines the TS format.
  238. *================================================================*/
  239. //#define RTV_TSIF_FORMAT_0 /* Serial: EN_high, CLK_rising */
  240. #define RTV_TSIF_FORMAT_1 /* Serial: EN_high, CLK_falling */ //
  241. //#define RTV_TSIF_FORMAT_2 /* Serial: EN_low, CLK_rising */
  242. //#define RTV_TSIF_FORMAT_3 /* Serial: EN_low, CLK_falling */
  243. //#define RTV_TSIF_FORMAT_4 /* Serial: EN_high, CLK_rising + 1CLK add */
  244. //#define RTV_TSIF_FORMAT_5 /* Serial: EN_high, CLK_falling + 1CLK add */
  245. //#define RTV_TSIF_FORMAT_6 /* Parallel: EN_high, CLK_rising */
  246. //#define RTV_TSIF_FORMAT_7 /* Parallel: EN_high, CLK_falling */
  247. /*=================================================================
  248. * Defines the TSIF speed.
  249. *================================================================*/
  250. //#define RTV_TSIF_SPEED_500_kbps
  251. //#define RTV_TSIF_SPEED_1_Mbps
  252. //#define RTV_TSIF_SPEED_2_Mbps
  253. //#define RTV_TSIF_SPEED_4_Mbps
  254. //#define RTV_TSIF_SPEED_7_Mbps
  255. //#define RTV_TSIF_SPEED_15_Mbps
  256. #define RTV_TSIF_SPEED_30_Mbps
  257. //#define RTV_TSIF_SPEED_60_Mbps
  258. /*=================================================================
  259. * Defines the TSP size. 188 or 204
  260. *================================================================*/
  261. #define RTV_TSP_XFER_SIZE 188
  262. #ifndef RTV_IF_SPI_TSIFx
  263. /*=================================================================
  264. * Defines the register I/O macros.
  265. *================================================================*/
  266. U8 isdbt_i2c_read(U8 i2c_chip_addr, U8 reg);
  267. void isdbt_i2c_write(U8 i2c_chip_addr, U8 reg, U8 val);
  268. void isdbt_i2c_read_burst(U8 i2c_chip_addr, U8 reg, U8 *buf, int size);
  269. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  270. #define RTV_REG_GET(reg) isdbt_i2c_read((U8)g_div_i2c_chip_id,(U8)reg)
  271. #define RTV_REG_SET(reg, val) isdbt_i2c_write((U8)g_div_i2c_chip_id,(U8)reg, (U8)val)
  272. #define RTV_REG_BURST_GET(reg, buf, size)\
  273. isdbt_i2c_read_burst(g_div_i2c_chip_id, (U8)(reg), buf, (size))
  274. #else
  275. #define RTV_REG_GET(reg) isdbt_i2c_read(RTV_CHIP_ADDR, (U8)reg)
  276. #define RTV_REG_SET(reg, val) isdbt_i2c_write(RTV_CHIP_ADDR, (U8)reg, (U8)val)
  277. #define RTV_REG_BURST_GET(reg, buf, size)\
  278. isdbt_i2c_read_burst(RTV_CHIP_ADDR, (U8)(reg), buf, size)
  279. #endif
  280. #define RTV_REG_MASK_SET(reg, mask, val) \
  281. do { \
  282. U8 tmp; \
  283. tmp = (RTV_REG_GET(reg)|(U8)(mask)) & (U8)((~(mask))|(val)); \
  284. RTV_REG_SET(reg, tmp); \
  285. } while(0)
  286. #endif
  287. #endif
  288. #if defined(RTV_IF_EBI2)
  289. #define RTV_EBI2_BUS_WITDH_16 //
  290. //#define RTV_EBI2_BUS_WITDH_32 //
  291. /*=================================================================
  292. * Defines the register I/O macros.
  293. *================================================================*/
  294. U8 isdbt_ebi2_read(U8 page, U8 reg);
  295. void isdbt_ebi2_read_burst(U8 page, U8 reg, U8 *buf, int size);
  296. void isdbt_ebi2_write(U8 page, U8 reg, U8 val);
  297. extern U8 g_bRtvPage;
  298. static INLINE U8 RTV_REG_GET(U8 reg)
  299. {
  300. return (U8)isdbt_ebi2_read(g_bRtvPage, (U8)(reg));
  301. }
  302. #define RTV_REG_BURST_GET(reg, buf, size)\
  303. isdbt_ebi2_read_burst(g_bRtvPage, (U8)(reg), buf, (size))
  304. #define RTV_REG_SET(reg, val)\
  305. isdbt_ebi2_write(g_bRtvPage, (U8)(reg), (U8)(val))
  306. #define RTV_REG_MASK_SET(reg, mask, val)\
  307. do { \
  308. U8 tmp; \
  309. tmp = (RTV_REG_GET(reg)|(U8)(mask))\
  310. & (U8)((~(mask))|(val));\
  311. RTV_REG_SET(reg, tmp); \
  312. } while (0)
  313. #define RTV_TSP_XFER_SIZE 188
  314. #endif
  315. /*############################################################################
  316. #
  317. # Pre-definintion by RAONTECH.
  318. #
  319. ############################################################################*/
  320. /*############################################################################
  321. #
  322. # Defines the critical object and macros.
  323. #
  324. ############################################################################*/
  325. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
  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_0) || defined(RTV_IF_TSIF_1) || 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_TSP_XFER_SIZE
  369. #error "Must define the RTV_TSP_XFER_SIZE definition !"
  370. #endif
  371. #if (RTV_TSP_XFER_SIZE != 188) && (RTV_TSP_XFER_SIZE != 204)
  372. #error "Must 188 or 204 for TS size"
  373. #endif
  374. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
  375. extern BOOL g_bRtvSpiHighSpeed;
  376. #endif
  377. void rtvOEM_PowerOn(int on);
  378. #ifdef __cplusplus
  379. }
  380. #endif
  381. #endif /* __MTV23X_PORT_H__ */