adc_333.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. #ifndef _ADC_H_
  2. #define _ADC_H_
  3. /**
  4. * @brief Update gain and offset values on RGB channels.
  5. *
  6. * This function gets current gain and offset values on RGB channels separately,
  7. * and then updates the input structure.
  8. *
  9. * @param pstConfig structure for saving gain and offset values.
  10. *
  11. */
  12. extern void DRV_ADC_GetAutoColorValue(ADCCalibrate_OSDGainOffset_t* pstConfig);
  13. /**
  14. * @brief Initialize requested input source, and enable/disable power, timer and workqueue.
  15. *
  16. * This function would initialize or clear selected input source, including ADC module power,
  17. * timer function execution and workqueue procedure.
  18. *
  19. * @param ucSubInputSource Requested input source type.
  20. * @param bEnable Enable selected source.
  21. *
  22. */
  23. extern void ADC_SourceSelect(UINT8 ucSubInputSource, BOOL bEnable);
  24. /**
  25. * @brief Execute auto adjust for current signal.
  26. *
  27. * This function processes phase detection and image centering for input signals.
  28. * Phase would be set as recorded info directly if bEnable is FALSE. There are several
  29. * types of centering mode,
  30. * ucMode = 0, indicate only Hstart and Vstart could be tuned for PC source.
  31. * ucMode = 1, indicate Hstart, Vstart, Hactive and Vactive could be tuned for PC source.
  32. * ucMode = 2, indicate Hstart, Vstart, Hactive and Vactive could be tuned for PC, Ypp and Scart_RGB.
  33. *
  34. * @param ucPath Not mention in the function.
  35. * @param bEnable Enable for running phase detection.
  36. * @param ucMode Image centering mode type.
  37. *
  38. */
  39. extern BOOL ADC_DoAuto(UINT8 ucPath, BOOL bEnable, UINT8 ucMode);
  40. /**
  41. * @brief Return -1.
  42. *
  43. * This function always retunrs -1.
  44. *
  45. * @param ucFunID Not mention in the function
  46. * @return Always return -1
  47. *
  48. */
  49. extern INT32 ADC_InfoGet(UINT8 ucFunID);
  50. /**
  51. * @brief Empty function.
  52. *
  53. * This function is empty now.
  54. *
  55. * @param ucFunID Not mention in the function
  56. * @param iValue Not mention in the function
  57. *
  58. */
  59. extern void ADC_InfoSet(UINT8 ucFunID, INT32 iValue);
  60. //kernel 2.6.35.9 update
  61. //void __exit DRV_ADC_Linuxexit(void);
  62. //INT32 __init DRV_ADC_Linuxinit(void);
  63. //INT32 ADC_Resume(void);
  64. //INT32 ADC_Suspend(pm_message_t state);
  65. //ssize_t adc_ioctl(struct inode *inode,struct file *file,UINT32 cmd,ULONG arg);
  66. /**
  67. * @brief Notify ADC standby.
  68. *
  69. * This function sets ADC flag to indicate the state is standby mode, which should ignore debounce mechanism of VGA plug ISR.
  70. *
  71. */
  72. void ADC_Standby(void);
  73. void ADC_WakeUp(void);
  74. /**
  75. * @brief Enable ADI reset on VIP module.
  76. *
  77. * This function requests VIP module to enable ADI reset.
  78. *
  79. */
  80. void ADC_ResetADI_Unlock(void);
  81. /**
  82. * @brief Process interrupt status.
  83. *
  84. * This function deals with several types of interrupt situations.
  85. *
  86. */
  87. void ADC_InterruptHandler (void);
  88. /**
  89. * @brief Search the best gain values for RGB channels.
  90. *
  91. * This function sets gains several times, and select one having the least delta
  92. * value after comparing with specific target.
  93. *
  94. * @param bAutoGainMode Whether to reload original lcg settings after gain searching.
  95. *
  96. */
  97. void ADC_SearchGain(BOOL bAutoGainMode);
  98. /**
  99. * @brief Disable interrupt and timer before exit ADC module.
  100. *
  101. * This function is one of module exit step. It disables interrupt, stops timer
  102. * and turns off related power.
  103. *
  104. */
  105. void ADC_Close(void);
  106. /**
  107. * @brief Setup flags for the first time search gains when initialize ADC module.
  108. *
  109. * This function is one of module initialization step. It enables flags related
  110. * to the first time gain search.
  111. *
  112. */
  113. void ADC_Open(void);
  114. /**
  115. * @brief Reset SOG for timer signal off.
  116. *
  117. * This function resets SOG when timer signal status is off.
  118. *
  119. */
  120. void ADC_TimerWork(void *unuse);
  121. /**
  122. * @brief Find one best phase with the least difference of frame comparison.
  123. *
  124. * This function requests VIP module to do frame comparison for each phase, and
  125. * records these pixel difference values. After collecting all results of frame
  126. * comparisons, the phase having the least difference value would be chosen as the
  127. * best phase.
  128. *
  129. * @return The best phase number.
  130. *
  131. */
  132. UINT8 ADC_FullPhaseDetected(void);
  133. /**
  134. * @brief Process image display centering.
  135. *
  136. * This function decides whether to trigger VIP centering function.
  137. *
  138. * @param bDoCentering Whether to triger VIP centering or not.
  139. *
  140. */
  141. void ADC_Centering(BOOL bDoCentering);
  142. /**
  143. * @brief Set VIP flags and send to VIP.
  144. *
  145. * This function sets VIP flags and then calls VIP function to send these information.
  146. */
  147. void ADC_SendInfo( void );
  148. /**
  149. * @brief Initialize setting according to current source type.
  150. *
  151. * This function sets basic settings for initializing current source type.
  152. *
  153. */
  154. void ADC_SourceInit(void);
  155. /**
  156. * @brief Timing mode setup.
  157. *
  158. * This function setup timing mode in sequential peocedures, including SOG status,
  159. * timing support and PLL setting.
  160. *
  161. * @return Setup timing mode result.
  162. * @retval VIP_No_Signal indicate SOG is not stable
  163. * @retval Unsupported_Timing indicate there is no matching timing in table list.
  164. * @retval Mode_Change_Again indicate HV sync status is unstable.
  165. * @retval Mode_Change_Stable indicate timing mode is found and signal is stable.
  166. *
  167. */
  168. UINT8 ADC_Mode_Setup( void );
  169. /**
  170. * @brief Check SOG stable status.
  171. *
  172. * This function checks SOG status for several loops.
  173. *
  174. * @return Status of SOG stability.
  175. *
  176. */
  177. BOOL ADC_Signal_Status(void);
  178. /**
  179. * @brief Setup timing mode according to referenced timing table.
  180. *
  181. * This function loads related timing table settings and adjust SOG or
  182. * clamping in specific condition.
  183. *
  184. */
  185. void ADC_ModeSetting(void);
  186. /**
  187. * @brief Check mode stable status.
  188. *
  189. * This function checks mode stable status for several times.
  190. *
  191. * @return Whether current mode is stable or not.
  192. *
  193. */
  194. BOOL ADC_ModeStable(void);
  195. /**
  196. * @brief Get timing information about HV frequency, vertical count and HV width.
  197. *
  198. * This function gets Horizontal/Vertical frequency, vertical count and horizontal/vertical
  199. * width according to current signals. It cannot execute succesfully until there are specific
  200. * number of stability count within constrain loops.
  201. *
  202. * @param ucStableCnt Continuous stability times for confirming.
  203. * @param ucTimeOut Total times for checking stability loop.
  204. * @param ucMdelay Not mention in the function.
  205. * @return Indicate whther the exts information is got or not.
  206. *
  207. */
  208. BOOL ADC_GetExtsInfo(UINT8 ucStableCnt, UINT8 ucTimeOut, UINT8 ucMdelay);
  209. /**
  210. * @brief Check HV sync stable status.
  211. *
  212. * This function gets Horizontal/Vertical sync stable status according to requesting VIP.
  213. *
  214. * @param ucTimeOut Polling times for requesting VIP in the first round.
  215. * @return Sync stable status.
  216. *
  217. */
  218. BOOL ADC_CheckSyncStable(UINT8 ucTimeOut);
  219. /**
  220. * @brief Print message about loaded timing table.
  221. *
  222. * This function prints debugging message related to loaded timing table,
  223. * and always returns FALSE.
  224. *
  225. * @return Timing table loading status.
  226. *
  227. */
  228. BOOL ADC_CheckLoadTableValueRange(void);
  229. /**
  230. * @brief Load information of Vesa timing structure for YPP.
  231. *
  232. * This function update Vesa timing structure of YPP according to computation result of
  233. * related horizontal and vertical factors.
  234. *
  235. * @param ucTablePtr Index of table.
  236. *
  237. */
  238. void ADC_LoadYPPTable(UINT8 ucTablePtr);
  239. /**
  240. * @brief Load information of Vesa timing structure for VGA.
  241. *
  242. * This function update Vesa timing structure of VGA according to computation result of
  243. * related horizontal and vertical factors.
  244. *
  245. * @param ucTablePtr Index of table.
  246. *
  247. */
  248. void ADC_LoadVesaTable(UINT8 ucTablePtr);
  249. /**
  250. * @brief Determine whether to further check Vsync width if there are conflict timing modes.
  251. *
  252. * This function checks whether there is ambiguous timing according to comparing contents of
  253. * timing table. Furthermore, additional Vsync width comparison should be checked in the next step.
  254. *
  255. * @return Confirm result.
  256. *
  257. */
  258. BOOL ADC_NeedCheckVsyncWidth(void);
  259. /**
  260. * @brief Determine whether to further check Hsync width if there are conflict timing modes.
  261. *
  262. * This function checks whether there is ambiguous timing according to comparing contents of
  263. * timing table. Furthermore, additional Hsync width comparison should be checked in the next step.
  264. *
  265. * @return Confirm result.
  266. *
  267. */
  268. BOOL ADC_NeedCheckHsyncWidth(void);
  269. /**
  270. * @brief Determine whether to further check Polarity if there are conflict timing modes.
  271. *
  272. * This function checks whether there is ambiguous timing according to comparing contents of
  273. * timing table. Furthermore, additional polarity comparison should be checked in the next step.
  274. *
  275. * @return Confirm result.
  276. *
  277. */
  278. BOOL ADC_NeedToCheckPolarity(void);
  279. /**
  280. * @brief Check whether vertical frequency is proper or not.
  281. *
  282. * This function checks the range of vertical frequency, and report not support if the frequency
  283. * is out of specific range on reference source.
  284. *
  285. * @return Confirm result.
  286. *
  287. */
  288. BOOL ADC_Frequency_Filter(void);
  289. /**
  290. * @brief Update HV polarity and interlace information.
  291. *
  292. * This function updates flags related to Horizontal/Vertical polarity and interlace.
  293. *
  294. * @param ucFlag Status for write back into flags.
  295. *
  296. */
  297. void ADC_UpdateFlag(UINT8 ucFlag);
  298. /**
  299. * @brief Update current Horizontal count and Vertical count.
  300. *
  301. * This function updates current ADC information about horizontal and vertical counts.
  302. *
  303. */
  304. void ADC_StatusUpdate(void);
  305. /**
  306. * @brief Display screen according to screen mode.
  307. *
  308. * This function sends information to VIP according to input screen type.
  309. *
  310. * @param ucScreenMode Screen mode type (NormalScreen, BlackScreen)
  311. *
  312. */
  313. void ADC_ScreenMode(UINT8 ucScreenMode);
  314. /**
  315. * @brief Create work for mode detection.
  316. *
  317. * This function adds work thread into sync detection workqueue for mode detection.
  318. * If the detection procedure is done, revise flag to force doing mode detection again.
  319. *
  320. */
  321. void ADC_SyncDetectCreate(void);
  322. /**
  323. * @brief Print memory information when executing memory test procedure.
  324. *
  325. * This function print debugging message about the status of total memory
  326. * and free memory if memory test configuration is enabled.
  327. *
  328. * @param msg message for print in the end of memory status.
  329. *
  330. */
  331. void print_meminfo(INT8 *msg);
  332. /**
  333. * @brief Clock of ADC module.
  334. *
  335. * This function calculates system clock for ADC usage. The formula is
  336. * system_clk x [R_CPLL_MUL(0xbe0001b8[7:0]) + 1]
  337. * ¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w
  338. * [R_CPLL_DIV(0xbe0001b8[12:8]) + 1] x [R_YPP200M_DIV(0xbe000158[6:0]) + 1]
  339. *
  340. * @return Clock value for ADC module.
  341. *
  342. */
  343. UINT32 ADC_MClk(void);
  344. /**
  345. * @brief Send event to KMF according to detecting status.
  346. *
  347. * This function notifies KMF by sending event ID accompany with information.
  348. * Two kind of messages are available in ADC moodule,
  349. * - ADCMSG_INPUTPATHSTATUS => notify KMF current signals status of ADC module.
  350. * - NOTICEMSG_ADC_TURNOFFSOUND => request KMF to turn off sound on ADC source.
  351. *
  352. * @param msgType Message type for sending.
  353. * @param bActive Whether currect signals is stable or not
  354. * @param bNotSupport Whther current signal is supported or not.
  355. *
  356. */
  357. void ADC_NoticeKmf(INT32 msgType, BOOL bActive, BOOL bNotSupport);
  358. /**
  359. * @brief Reset ADC flags to default status.
  360. *
  361. * This function resets several flags relating to ADC detecting flow.
  362. * These flags should be reset before timing mode detection,.
  363. *
  364. */
  365. void ADC_ResetAdcInfoSetting(void);
  366. /**
  367. * @brief Find matching timing mode in VGA table.
  368. *
  369. * This function checks specific rules and looks up matching VGA timing mode.
  370. *
  371. */
  372. void ADC_CheckVGATable(void);
  373. /**
  374. * @brief Find matching timing mode in YPP table.
  375. *
  376. * This function checks specific rules and looks up matching YPP timing mode.
  377. *
  378. */
  379. void ADC_CheckYPPTable(void);
  380. /**
  381. * @brief Check timing mode depending on request table type.
  382. *
  383. * This function looks up matching timing mode according to requested type.
  384. *
  385. */
  386. void ADC_CheckInputMatch(UINT8 ucTable);
  387. /**
  388. * @brief Find timing mode depending on source type.
  389. *
  390. * This function looks up timing mode tables according to input source type, and
  391. * reports unsupport if the timing cannot be found in table list.
  392. *
  393. * @return Supporting source mode or unsupport.
  394. *
  395. */
  396. UINT8 ADC_FindTimingModeTable(void);
  397. /**
  398. * @brief Check whether input signal can be supported or not.
  399. *
  400. * This function checks frequency filter and timing tables, and then updates the status
  401. * after checking.
  402. *
  403. * @return Whether input signal is supported.
  404. *
  405. */
  406. BOOL ADC_Detect_Mode(void);
  407. /**
  408. * @brief Reset flags for ADC AP.
  409. *
  410. * This function resets flags which are used by ADC AP.
  411. *
  412. */
  413. void ADC_ResetApSetting(void);
  414. /**
  415. * @brief Record chip information to flag.
  416. *
  417. * This function saves chip information to flag ulChipID by reading global register.
  418. * The bits[23:8] of ulChipID indicates the device chip ID(e.g. 0x331 -> 331 chip, 0x533 -> 533 chip.),
  419. * and the bits[7:0] indicates the revision ID(e.g. 0x10 -> A0 revision, 0x31 -> C1 revision).
  420. *
  421. */
  422. void ADC_SystemChipID(void);
  423. /**
  424. * @brief Check horizontal total and pixel clock range to decide enlarge width rate.
  425. *
  426. * This function gets horizontal total and pixel clock value from referenced timing table,
  427. * and then check its range for determining the rate of enlarge width iEnlargeWidthRate.
  428. * The iEnlargeWidthRate would be used to calculate horizontal related information.
  429. *
  430. */
  431. void ADC_OverSample(void);
  432. /**
  433. * @brief Update white balance related parameters for OSD updating usage.
  434. *
  435. * This function saves R,G and B gain control and digital offset values, which are used to
  436. * update OSD gain and offset status of RGB separately.
  437. *
  438. */
  439. void ADC_UpdateWBOSDvalue(void);
  440. /**
  441. * @brief Execute phase detection for the second round.
  442. *
  443. * This function sets different phases for frame comparison, and then select one best phase which
  444. * has the least difference summation.
  445. *
  446. */
  447. void ADC_PhaseDetectedSecond(void);
  448. /**
  449. * @brief Check whether detected signal is interlace mode or not.
  450. *
  451. * This function checks the difference of Vcount to distinguish current signal is
  452. * interlace type or progress type.
  453. *
  454. */
  455. BOOL ADC_CheckInterlaceMode(void);
  456. /**
  457. * @brief Search gain value for the first time processing white balance.
  458. *
  459. * This function checks whether it is the first time to execute white balance or not.
  460. * If it is not the first time white balance procedure, the gain value would be set
  461. * according to current status.
  462. *
  463. */
  464. void ADC_FirstTimeSearchGain(void);
  465. /**
  466. * @brief Check whether gain value is located in specific range.
  467. *
  468. * This function checks input gain value, and returns TRUE if the value is not a proper value.
  469. *
  470. * @param scValue Gain value for checking.
  471. *
  472. */
  473. BOOL ADC_CheckGainValue(UINT16 scValue);
  474. /**
  475. * @brief Read data according to address.
  476. *
  477. * This function gets value of requested register, the format of requesting register includes
  478. * start/end bits and its address.
  479. *
  480. * @param uiAdr Request address format using 32 bits data
  481. * [28] => 1: Global BASE registers (0xbe000000~);
  482. * 0: ADC BASE registers (0xbe150000~);
  483. * [25:21] => Starting bit position
  484. * [20:16] => Ending bit position
  485. * [15:0] => Offset value from BASE address
  486. * @return Data read from referenced address
  487. *
  488. */
  489. UINT32 ADC_Read(UINT32 uiAdr);
  490. /**
  491. * @brief Write data according to address.
  492. *
  493. * This function writes value into requested register, the format of register includes
  494. * start/end bits and its address.
  495. *
  496. * @param uiAdr Request address format using 32 bits data
  497. * [28] => 1: Global BASE registers (0xbe000000~);
  498. * 0: ADC BASE registers (0xbe150000~);
  499. * [25:21] => Starting bit position
  500. * [20:16] => Ending bit position
  501. * [15:0] => Offset value from BASE address
  502. * @param uiDat Data for writing.
  503. *
  504. */
  505. void ADC_Write(UINT32 uiAdr, UINT32 uiDat);
  506. /**
  507. * @brief Find the most close gain value for RGB.
  508. *
  509. * This function searches gain value which has the least difference comparing with target value.
  510. * It would process iterately setting gain and checking delta on RGB channels.
  511. *
  512. */
  513. void ADC_SearchDigitalOffset(void);
  514. /**
  515. * @brief Enable/Disable ADC related power and clock.
  516. *
  517. * This function setups power down bits and related clock for enable/disable ADC module.
  518. *
  519. * @param bPowerOn Switch for power on or power off.
  520. *
  521. */
  522. INT32 DRV_ADC_power(INT32 bPowerOn);
  523. /**
  524. * @brief Provide current dg status for CVD2 closed caption decoding.
  525. *
  526. * This function provides dg status for video decoder. Decoder would set vbi line select
  527. * depending on dg status.
  528. *
  529. * @return Current dg status.
  530. *
  531. */
  532. UINT8 DRV_ADC_DgSourceStatus(void);
  533. /**
  534. * @brief Adjust function for app layer.
  535. *
  536. * This function contains several commands for app layer usage.
  537. *
  538. * @param ucFunID Request Funciton ID .
  539. * @param iValue Request value for function.
  540. *
  541. */
  542. INT32 adc_AdjustFunction(UINT8 ucFunID, INT32 iValue);
  543. /**
  544. * @brief Auto white balance.
  545. *
  546. * This function processes white balance by searching best gain and offset for RGB channels separately.
  547. *
  548. */
  549. void ADC_AutoColorCalibration(void);
  550. /**
  551. * @brief Fetch customer table data for VGA, YPP and Scart.
  552. *
  553. * This function gets VGA, YPP and Scart timing tables from customized default setting.
  554. *
  555. */
  556. void ADC_GetVideoTimingTable(void);
  557. /**
  558. * @brief Sets input pin according to source.
  559. *
  560. * This function setups related input pins, including R/G/B, Y/C, YCbCr, SOG and CVBS
  561. * according to input source type.
  562. *
  563. */
  564. void DRV_ADC_SetAdcPinConfig(UINT32 itype, InputVideoConf_st InputSrcPin);
  565. #endif