adc_global.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #ifndef _ADC_GLOBAL_H_
  2. #define _ADC_GLOBAL_H_
  3. //=================================================================================================
  4. // Header files area
  5. //=================================================================================================
  6. #include <linux/init.h>
  7. #include <linux/module.h>
  8. #include <linux/device.h>
  9. #include <linux/kernel.h>
  10. #include <linux/slab.h>
  11. #include <linux/fs.h>
  12. #include <linux/cdev.h>
  13. #include <asm/uaccess.h>
  14. #include <asm/irq.h>
  15. #include <linux/delay.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/version.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/sched.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/wait.h>
  22. #include <project.h>
  23. #include <Customization.h>
  24. #include <drv_spi.h>
  25. #include <drv_gpio.h>
  26. #include <drv_i2c.h>
  27. #include <drv_debug.h>
  28. #include <drv_platform.h>
  29. #include "drv_types.h"
  30. #include <drv_gated_clk.h>
  31. #include <drv_adc_internal.h>
  32. #include <drv_adc_external.h>
  33. #include <drv_vip_internal.h>
  34. //#include <pthread.h>
  35. #include <drv_cvd2_internal.h>
  36. #ifdef DRV_ENABLE_TUNER
  37. #include "drv_tuner_internal.h"
  38. #endif
  39. #include "drv_event.h"
  40. #include "drv2kmf.h"
  41. #include "drv_kmf_interface.h"
  42. #include "adc_reg.h"
  43. #include "adc_device.h"
  44. #include "adc_hw.h"
  45. //=================================================================================================
  46. // Macro definition area
  47. //=================================================================================================
  48. #define I2CWriteADCFun(DeviceID,Address,Data,pStatus) DRV_I2C_M0_WRITE_BYTE_100K(DeviceID,Address,Data,pStatus)
  49. #define I2CReadADCFun(DeviceID,Address,pStatus) DRV_I2C_M0_READ_BYTE_100K(DeviceID,Address,pStatus)
  50. #ifdef CONFIG_CRYSTAL_USE_24MHZ
  51. #define System_CLK 24000
  52. // ADC adopts Crystal clock
  53. #define CRYSTAL_CLK 24000
  54. // (System_CLK/CRYSTAL_CLK)*1000
  55. #define SYS_CRYS_CLK_RATIO_PRECISE_3 1000
  56. #else
  57. #define System_CLK 24576
  58. // ADC adopts Crystal clock which is not the same as System clock since 131 chip
  59. #define CRYSTAL_CLK 24000 // CPU PLL
  60. #define SYS_CRYS_CLK_RATIO_PRECISE_3 1024 // CPU PLL // (System_CLK/CRYSTAL_CLK)*1000
  61. //#define CRYSTAL_CLK 24576 // Pre PLL
  62. //#define SYS_CRYS_CLK_RATIO_PRECISE_3 1000 // Pre PLL // (System_CLK/CRYSTAL_CLK)*1000
  63. #endif
  64. #ifdef CONFIG_SUPPORT_DEBUG_MESSAGE
  65. #define ADC_DebugMsg(fmt, args...) DBG_MSG1(DBGCFG_ADC, "ADC] "fmt,## args)
  66. //#define ADC_ReleaseMsg(fmt, args...) RELEASE_MSG1(" [ADC] "fmt, ## args)
  67. #define COLOR_PRINT(color, fmt, args...) { if(color == RED) DBG_MSG1(DBGCFG_ADC, "\e[1;31mADC] "fmt "\e[0m",## args); \
  68. if(color == GREEN) DBG_MSG1(DBGCFG_ADC, "\e[1;32mADC] "fmt "\e[0m",## args); \
  69. if(color == BLUE) DBG_MSG1(DBGCFG_ADC, "\e[1;34mADC] "fmt "\e[0m",## args); }
  70. #else
  71. #define ADC_DebugMsg(fmt, args...)
  72. #define ADC_ReleaseMsg(fmt, args...)
  73. #endif
  74. //Watch dog
  75. #define ADC_WATCHDOG
  76. #define WATCH_DOG_ADR 0xbe0f0300
  77. #ifdef ADC_WATCHDOG
  78. #define ADC_ClearWatchDog set_bit(28, (void *)(WATCH_DOG_ADR));
  79. #else
  80. #define ADC_ClearWatchDog
  81. #endif
  82. //IRQ
  83. #define ADC_SYNC_IRQ 12
  84. #define ADC_VGA_WAKEUP_IRQ 19
  85. #define ADC_VIP_SYNC_IRQ 33
  86. #define GainYCodeDiff 6110 // G and Sog share pin target = [Diff of 533] * [High-Low ratio] = 6110
  87. //#define GainYCodeDiff 6008 // (235.75-16)/1.045 * ((1.05V-0.55V)/0.700) *4*10*
  88. #define GainCbCrCodeDiff 6124 // (240-16)/1.045 * ((1.05V-0.55V)/0.700) *4*10
  89. #define GainRGBCodeDiff 6950 // 0~255
  90. //#define GainRGBCodeDiff 6562 // (250-5) * ((1.05V-0.55V)/0.700) *4*10 modify by patrick
  91. //#define GainRGBCodeDiff 6699 // (250-5)/1.045 * ((1.05V-0.55V)/0.700) *4*10
  92. #define GainScartCodeDiff 6699 //(250-5)/1.045 * ((1.05V-0.55V)/0.700) *4*10
  93. //#define OffsetRGBTarget 10*4*10
  94. #define OffsetRGBTarget 20 // 0~255
  95. //#define OffsetRGBTarget 5*4*10
  96. #define OffsetYTarget 17*4*10
  97. //#define OffsetCbCrTarget 5140 //(128+0.5)*4*10
  98. #define OffsetCbCrTarget 128*4*10 //5120
  99. #define ADI_CENTERING_HOR_DELAY 10 // HW horizontal active starting position delay for image centering procedure
  100. //=================================================================================================
  101. // Data structure type definition
  102. //=================================================================================================
  103. enum{
  104. RED=0,
  105. GREEN,
  106. BLUE,
  107. MaxColor
  108. };
  109. enum ADC_TimerType{
  110. TimerVsyncloss,
  111. TimerSignaloff,
  112. TimerModeChange,
  113. TimerTunerStrength,
  114. };
  115. #ifndef BIT0
  116. enum {
  117. BIT0 = 0x01,
  118. BIT1 = 0x02,
  119. BIT2 = 0x04,
  120. BIT3 = 0x08,
  121. BIT4 = 0x10,
  122. BIT5 = 0x20,
  123. BIT6 = 0x40,
  124. BIT7 = 0x80
  125. };
  126. #endif
  127. enum {
  128. Current_state_Failed=0,
  129. Csync_stable_i2_failed,
  130. VIP_No_Signal,
  131. Unsupported_Timing,
  132. Unstable_Timing_Setting,
  133. Mode_Change_Again,
  134. Mode_Change_Stable,
  135. };
  136. enum ADC_InterruptEvent
  137. {
  138. CheckSogWidth,
  139. ResearchSogThreshold,
  140. ResetCoast,
  141. HandlerHSOut,
  142. CheckSyncStable,
  143. TotalInterruptEvent,
  144. };
  145. enum {
  146. ADCMSG_INPUTPATHSTATUS,
  147. NOTICEMSG_ADC_TURNOFFSOUND,
  148. };
  149. enum{
  150. SOURCE_VGA=0,
  151. SOURCE_COMPONENT1,
  152. SOURCE_COMPONENT2
  153. };
  154. typedef enum {
  155. ReturntoIdleEvent,
  156. MaxEvent
  157. }ADC_EVENT;
  158. typedef enum {
  159. HSYNC_POLARITY=0,
  160. VSYNC_POLARITY
  161. }ADC_SyncPolarity_t;
  162. typedef struct
  163. {
  164. UINT8 ucSel1Gpio;
  165. UINT8 ucSel1GpioStatus;
  166. UINT8 ucSel2Gpio;
  167. UINT8 ucSel2GpioStatus;
  168. } ADC_MuxGpio_t;
  169. typedef struct _ADC_CONTEXT_ {
  170. UINT32 BaseAddress;
  171. UINT8 IrqNumber;
  172. void (*ADCStateFun)(struct _ADC_CONTEXT_ *,ADC_EVENT);
  173. }ADC_CONTEXT,*PADC_CONTEXT;
  174. typedef struct _adc_ioctl_data
  175. {
  176. BOOL bChangeFlow;
  177. UINT32 ucMatchTablePtr;
  178. UINT32 ucPhase;
  179. UINT32 ucColor;
  180. UINT32 ulPosition;
  181. UINT32 ulData;
  182. UINT32 ulTimes;
  183. UINT32 ulTargetValue[3];
  184. UINT32 ulClock;
  185. }adc_ioctl_data, *pAdc_ioctl_data;
  186. typedef struct _adc_ap_data
  187. {
  188. BOOL bAutoFlow;
  189. BOOL bApUse;
  190. BOOL bDisableInterrupt;
  191. UINT8 ucMatchTable;
  192. UINT8 ucColor;
  193. UINT8 ucPhase;
  194. UINT32 ulApPosition;
  195. UINT32 ulData;
  196. UINT32 ulTimes;
  197. UINT32 ulTargetValue[3];
  198. }adc_ap_data;
  199. typedef struct _WhiteBalanceDebugMessage
  200. {
  201. UINT32 ulCurrentSearch;
  202. UINT32 ulCurrentSearchValue;
  203. UINT32 ulDelta;
  204. UINT32 ulLowValue;
  205. UINT32 ulHighValue;
  206. }WBDbgMsg;
  207. typedef struct
  208. {
  209. VesaTiming* pYppVideoTimingTable;
  210. UINT32 YppVideoTimingTblSize;
  211. VesaTiming* pVgaVideoTimingTable;
  212. UINT32 VgaVideoTimingTblSize;
  213. VesaTiming* pScartVideoTimingTable;
  214. UINT32 ScartVideoTimingTblSize;
  215. }stADCTimingTable;
  216. #endif // End of #ifndef _ADC_GLOBAL_H_
  217. //=================================================================================================
  218. // External function list
  219. //=================================================================================================
  220. extern UINT32 ADC_Read(UINT32 uiAdr);
  221. extern void ADC_Write(UINT32 uiAdr, UINT32 uiDat);
  222. extern void ADC_DelayMS(UINT32 ulDelayMS );
  223. //=================================================================================================
  224. // External variable list
  225. //=================================================================================================
  226. extern AdcInfo sAdcInfo;
  227. extern adc_ap_data gAdcAp;
  228. extern INT32 iEnlargeWidthRate;
  229. extern VesaTiming ADC_DetectTiming;
  230. extern InputVideoConf_st adc_InputSrcPin;