adc_hw.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. #include "adc_global.h"
  2. #include "adc_hw.h"
  3. void ADC_Clear_Interrupt(UINT16 usValue)
  4. {
  5. //printk(KERN_EMERG" ## Clear Interrupt 0x%x ##\n", usValue);
  6. ADC_Write(ADC_REG_int_clear_byte, usValue);
  7. }
  8. void ADC_Interrupt(BOOL bStatus, UINT16 usValue)
  9. {
  10. //printk(KERN_EMERG" ## Set Interrupt [%s] = 0x%x ##\n", bStatus?"TRUE":"FALSE", usValue);
  11. if(gAdcAp.bDisableInterrupt)
  12. bStatus = DISABLE;
  13. if(bStatus == ENABLE)
  14. ADC_Write(ADC_REG_int_mask_byte, ~usValue);
  15. else
  16. ADC_Write(ADC_REG_int_mask_byte, 0xffff);
  17. }
  18. #ifdef CONFIG_DDC_CI_SUPPORT
  19. void DRV_ADC_Get_DDCCI_OSDPhase(UINT8 *Phase)
  20. {
  21. *Phase = sAdcInfo.DDCCI_OSDPhase;
  22. }
  23. EXPORT_SYMBOL(DRV_ADC_GetPhase);
  24. void DRV_ADC_Get_DDCCI_OSDClock(UINT8 *Clock)
  25. {
  26. *Clock = sAdcInfo.DDCCI_OSDClock;
  27. }
  28. EXPORT_SYMBOL(DRV_ADC_GetPhase);
  29. #endif
  30. void ADC_SetPhaseDirdect (UINT8 ucPhaseValue)
  31. {
  32. ADC_Write(ADC_REG_pll_phase_r_sel, ucPhaseValue);
  33. ADC_Write(ADC_REG_pll_phase_g_sel, ucPhaseValue);
  34. ADC_Write(ADC_REG_pll_phase_b_sel, ucPhaseValue);
  35. }
  36. void DRV_ADC_GetPhase(UINT8 *bPhase)
  37. {
  38. *bPhase=ADC_Read(ADC_REG_pll_phase_r_sel);
  39. }
  40. EXPORT_SYMBOL(DRV_ADC_GetPhase);
  41. void DRV_ADC_SetPhase(INT8 scPhaseValue)
  42. {
  43. UINT8 ucDelay;
  44. UINT16 usInterruptStatus;
  45. //when inputmode is nosignal, ADC_DetectTiming.ucVFrequency=0 will get the Kernel Panic
  46. if((sAdcInfo.ucInputMode == UNSUPPORT_MODE) || (sAdcInfo.ucInputMode == NOSIGNAL_MODE))
  47. return;
  48. ucDelay = 500*3/(ADC_DetectTiming.ucVFrequency+1);
  49. sAdcInfo.ucUserPhase = scPhaseValue;//(((scPhaseValue - scOsdMin)* 100000) /((( scOsdMax - scOsdMin)+1) * 100000 /32 ));
  50. usInterruptStatus = ADC_Read(ADC_REG_int_mask_byte);
  51. if( (sAdcInfo.ucSource != Adc_kSourceVGA) && ((usInterruptStatus & 0x80) == 0x80) )
  52. {
  53. printk(KERN_EMERG"#### Interrupt Disabled!! Skip @ [%s] ####\n", __FUNCTION__);
  54. return;
  55. }
  56. ADC_Write(ADC_REG_int_mask_byte, usInterruptStatus|0x80);
  57. ADC_Interrupt(DISABLE, 0);
  58. ADC_SetPhaseDirdect(sAdcInfo.ucUserPhase);
  59. ADC_DelayMS(ucDelay);
  60. ADC_Clear_Interrupt(0x80);
  61. ADC_Write(ADC_REG_int_mask_byte, usInterruptStatus);
  62. }
  63. EXPORT_SYMBOL(DRV_ADC_SetPhase);
  64. void ADC_SetGainDirdect(UINT8 ucColor, UINT32 uwValue) //0~511
  65. {
  66. if(uwValue > 511)
  67. uwValue = 511;
  68. switch(ucColor)
  69. {
  70. case RED:
  71. ADC_Write(ADC_REG_lcg_rmp1, (uwValue>>6)&0x7);
  72. ADC_Write(ADC_REG_lcg_rmp2, uwValue&0x3f);
  73. break;
  74. case GREEN:
  75. ADC_Write(ADC_REG_lcg_gmp1, (uwValue>>6)&0x7);
  76. ADC_Write(ADC_REG_lcg_gmp2, uwValue&0x3f);
  77. break;
  78. case BLUE:
  79. ADC_Write(ADC_REG_lcg_bmp1, (uwValue>>6)&0x7);
  80. ADC_Write(ADC_REG_lcg_bmp2, uwValue&0x3f);
  81. break;
  82. }
  83. }
  84. void DRV_ADC_SetGain(UINT8 ucColor, UINT32 scColorGain) //0~511
  85. {
  86. switch(ucColor)
  87. {
  88. case RED:
  89. ADC_SetGainDirdect(RED, scColorGain);
  90. break;
  91. case GREEN:
  92. ADC_SetGainDirdect(GREEN, scColorGain);
  93. break;
  94. case BLUE:
  95. ADC_SetGainDirdect(BLUE, scColorGain);
  96. break;
  97. }
  98. }
  99. EXPORT_SYMBOL(DRV_ADC_SetGain);
  100. UINT16 ADC_GetGain(UINT8 ucColor)
  101. {
  102. UINT16 ulColorGain=0;
  103. switch(ucColor)
  104. {
  105. case RED:
  106. ulColorGain |= (ADC_Read(ADC_REG_lcg_rmp1)&0x7)<<6;
  107. ulColorGain |= ADC_Read(ADC_REG_lcg_rmp2)&0x3f;
  108. break;
  109. case GREEN:
  110. ulColorGain |= (ADC_Read(ADC_REG_lcg_gmp1)&0x7)<<6;
  111. ulColorGain |= ADC_Read(ADC_REG_lcg_gmp2)&0x3f;
  112. break;
  113. case BLUE:
  114. ulColorGain |= (ADC_Read(ADC_REG_lcg_bmp1)&0x7)<<6;
  115. ulColorGain |= ADC_Read(ADC_REG_lcg_bmp2)&0x3f;
  116. break;
  117. default:
  118. ulColorGain = 256;
  119. }
  120. return ulColorGain;
  121. }
  122. void ADC_SetOffsetDirdect(UINT8 ucColor, UINT32 uwValue)// -255 ~ 255
  123. {
  124. if(uwValue > 255)
  125. uwValue = 255;
  126. switch(ucColor)
  127. {
  128. case RED:
  129. ADC_Write(ADC_REG_dofst_r_7to0, uwValue&0xff);
  130. break;
  131. case GREEN:
  132. ADC_Write(ADC_REG_dofst_g_7to6, ((uwValue>>6)&0x3));
  133. ADC_Write(ADC_REG_dofst_g_5to0, uwValue&0x3f);
  134. break;
  135. case BLUE:
  136. ADC_Write(ADC_REG_dofst_b_7to4, ((uwValue>>4)&0xf));
  137. ADC_Write(ADC_REG_dofst_b_3to0, uwValue&0xf);
  138. break;
  139. }
  140. }
  141. void DRV_ADC_SetOffset(UINT8 ucColor, INT16 scColorOffset) // 0 ~ 511
  142. {
  143. UINT32 ulOffsetValue = 0;
  144. switch(ucColor)
  145. {
  146. case RED:
  147. if(scColorOffset > 255)
  148. {
  149. ADC_Write(ADC_REG_dofst_r, 1);
  150. ulOffsetValue = scColorOffset - 255;
  151. }
  152. else
  153. {
  154. ADC_Write(ADC_REG_dofst_r, 0);
  155. ulOffsetValue = abs(scColorOffset- 255);
  156. }
  157. break;
  158. case GREEN:
  159. if(scColorOffset > 255)
  160. {
  161. ADC_Write(ADC_REG_dofst_g, 1);
  162. ulOffsetValue = scColorOffset - 255;
  163. }
  164. else
  165. {
  166. ADC_Write(ADC_REG_dofst_g, 0);
  167. ulOffsetValue = abs(scColorOffset- 255);
  168. }
  169. break;
  170. case BLUE:
  171. if(scColorOffset > 255)
  172. {
  173. ADC_Write(ADC_REG_dofst_b, 1);
  174. ulOffsetValue = scColorOffset - 255;
  175. }
  176. else
  177. {
  178. ADC_Write(ADC_REG_dofst_b, 0);
  179. ulOffsetValue = abs(scColorOffset- 255);
  180. }
  181. break;
  182. }
  183. switch(ucColor)
  184. {
  185. case RED:
  186. ADC_SetOffsetDirdect(RED, ulOffsetValue);
  187. break;
  188. case GREEN:
  189. ADC_SetOffsetDirdect(GREEN, ulOffsetValue);
  190. break;
  191. case BLUE:
  192. ADC_SetOffsetDirdect(BLUE, ulOffsetValue);
  193. break;
  194. }
  195. }
  196. EXPORT_SYMBOL(DRV_ADC_SetOffset);
  197. UINT16 ADC_GetOffset(UINT8 ucColor)
  198. {
  199. UINT32 ulColorOffset=0;
  200. switch(ucColor)
  201. {
  202. case RED:
  203. ulColorOffset |= ADC_Read(ADC_REG_dofst_r_7to0)&0xff;
  204. break;
  205. case GREEN:
  206. ulColorOffset |= (ADC_Read(ADC_REG_dofst_g_7to6)&0x3)<<6;
  207. ulColorOffset |= ADC_Read(ADC_REG_dofst_g_5to0)&0x3f;
  208. break;
  209. case BLUE:
  210. ulColorOffset |= (ADC_Read(ADC_REG_dofst_b_7to4)&0xf) <<4;
  211. ulColorOffset |= ADC_Read(ADC_REG_dofst_b_3to0)&0xf;
  212. break;
  213. default:
  214. ulColorOffset = 256;
  215. }
  216. return ulColorOffset;
  217. }
  218. void DRV_ADC_SetHTotal(UINT16 usHTotal)
  219. {
  220. BOOL bHsOutEnable=FALSE;
  221. UINT16 usRegPllMul;
  222. ADC_DebugMsg("%s %d\n", __FUNCTION__,__LINE__);
  223. ADC_DebugMsg("HTotal = %d\n", usHTotal);
  224. if( sAdcInfo.ucSource!=Adc_kSourceVGA )
  225. {
  226. if( (ADC_Read(ADC_REG_int_mask_byte)&0x80)==0 )
  227. {
  228. bHsOutEnable = TRUE;
  229. ADC_Write(ADC_REG_int_mask_byte, ADC_Read(ADC_REG_int_mask_byte)|0x0080);
  230. }
  231. }
  232. usRegPllMul = usHTotal-1;
  233. ADC_Write(ADC_REG_pll_febdiv_7to0, (usRegPllMul&0xff));
  234. ADC_Write(ADC_REG_pll_febdiv_11to8, (usRegPllMul&0xf00)>>8);
  235. //ADC_DelayMS(24);
  236. if( bHsOutEnable )
  237. {
  238. ADC_Write(ADC_REG_int_mask_byte, ADC_Read(ADC_REG_int_mask_byte)&(~0x0080));
  239. }
  240. }
  241. EXPORT_SYMBOL(DRV_ADC_SetHTotal);
  242. void ADC_PllSetting(UINT8 ucPixelClock, UINT16 usHTotal)
  243. {
  244. UINT8 ucRegPllDiv, ucRegPllGb=0, ucRegPlli2ctrl, ucRegPllictrl, ucRegPllDivb=0, ucPllDiva[]={1, 2, 4,8}, ucPllDivb[]={2, 3, 4, 5};
  245. UINT16 usVCO, usFebDiv=0, usPxDiv=0;
  246. // pixel clock < 40MHz, the 0xbe150058 is setting to 0x22
  247. // pixel 40MHz <= clock < 80MHz, the 0xbe150058 is setting to 0x55
  248. // pixel clock >= 80MHz, the 0xbe150058 is setting to 0x99
  249. if( ucPixelClock < 40 )
  250. {
  251. ADC_Write(ADC_REG_sch_pbw_ctrl, 2);
  252. ADC_Write(ADC_REG_sch_ref_pbw_ctrl, 2);
  253. }
  254. else if( ucPixelClock >= 40 && ucPixelClock < 80 )
  255. {
  256. ADC_Write(ADC_REG_sch_pbw_ctrl, 5);
  257. ADC_Write(ADC_REG_sch_ref_pbw_ctrl, 5);
  258. }
  259. else if( ucPixelClock >= 80 )
  260. {
  261. ADC_Write(ADC_REG_sch_pbw_ctrl, 9);
  262. ADC_Write(ADC_REG_sch_ref_pbw_ctrl, 9);
  263. }
  264. //Keep VCO range 900~1330M Hz by 20120822
  265. if(ucPixelClock < 19)
  266. ucRegPllDiv = 3;
  267. else if(ucPixelClock < 38)
  268. ucRegPllDiv = 2;
  269. else if(ucPixelClock < 76)
  270. ucRegPllDiv = 1;
  271. else
  272. ucRegPllDiv = 0;
  273. if(ucPixelClock < 28)
  274. ucRegPllDivb = 1;
  275. else if(ucPixelClock < 38)
  276. ucRegPllDivb = 0;
  277. else if(ucPixelClock < 56)
  278. ucRegPllDivb = 1;
  279. else if(ucPixelClock < 76)
  280. ucRegPllDivb = 0;
  281. else if(ucPixelClock < 112)
  282. ucRegPllDivb = 1;
  283. else
  284. ucRegPllDivb = 0;
  285. usPxDiv = ucPllDiva[ucRegPllDiv]*ucPllDivb[ucRegPllDivb]*4 - 1;
  286. usVCO = ucPixelClock*(usPxDiv+1);
  287. if(ADC_Read(GLB_REG_VADC_REF_SEL_24M))
  288. usFebDiv = (usVCO*1000)/CRYSTAL_CLK -1;
  289. else
  290. usFebDiv = (usVCO*1000)/System_CLK -1;
  291. //PLL charge pump, set PLL band width
  292. if( ucPixelClock<60 )
  293. {
  294. ucRegPlli2ctrl=3;
  295. ucRegPllictrl=3;
  296. }
  297. else
  298. {
  299. ucRegPlli2ctrl=0xb;
  300. ucRegPllictrl=0xb;
  301. }
  302. if ( ( usVCO >= 900) && (usVCO < 1100) )
  303. {
  304. ADC_Write(ADC_REG_dco_gb, 0x4);
  305. ADC_Write(ADC_REG_dco_ictrl, 0x5);
  306. }
  307. else if ( ( usVCO >= 1100 ) && ( usVCO < 1400) )
  308. {
  309. ADC_Write(ADC_REG_dco_gb, 0x4);
  310. ADC_Write(ADC_REG_dco_ictrl, 0x5);
  311. }
  312. else
  313. {
  314. ADC_Write(ADC_REG_dco_gb, 0x4);
  315. ADC_Write(ADC_REG_dco_ictrl, 0x5);
  316. }
  317. //ADC_Write(ADC_REG_cs2_pll_sw_rst, 0x1);
  318. //ADC_Write(ADC_REG_pll_pwdn, 0);
  319. ADC_Write(ADC_REG_pdiv_rstn, 0);
  320. ADC_Write(ADC_REG_pll_gb_vb, (ucRegPllGb&0x7));
  321. ADC_Write(ADC_REG_pll_gb_MSBs, (ucRegPllGb&0x18)>>3);
  322. ADC_Write(ADC_REG_pll_i2ctrl, (ucRegPlli2ctrl&0x7));
  323. ADC_Write(ADC_REG_pll_i2ctrl_MSBs, (ucRegPlli2ctrl&0x018)>>3);
  324. ADC_Write(ADC_REG_pll_ictrl, (ucRegPllictrl&0x7));
  325. ADC_Write(ADC_REG_pll_ictrl_MSBs, (ucRegPllictrl&0x18)>>3);
  326. DRV_ADC_SetHTotal(usHTotal);
  327. ADC_Write(ADC_REG_pll_div_sel, ucRegPllDiv);
  328. ADC_Write(ADC_REG_pll_hsync_pw, 0xf);
  329. ADC_Write(ADC_REG_pll_12v, 2);
  330. ADC_Write(ADC_REG_PLL12V, 0xa);
  331. ADC_Write(ADC_REG_dco_refdiv, 0x08); // 0x147[4:0]
  332. //ADC_Write(ADC_REG_pll_pwdn, 1);
  333. //ADC_Write(ADC_REG_cs2_pll_sw_rst, 0x0);
  334. ADC_Write(ADC_REG_pdiv_rstn, 1);
  335. ADC_Write(ADC_REG_pll_pdiv_en, 0);
  336. ADC_Write(ADC_REG_pll_divb_sel, ucRegPllDivb);
  337. ADC_Write(ADC_REG_dco_febdiv, usFebDiv);
  338. ADC_Write(ADC_REG_dlpll_pxdiv, usPxDiv);
  339. }
  340. void ADC_CheckPllResetSequence(UINT8 ucPixelClock, UINT16 usHTotal)
  341. {
  342. ADC_DebugMsg("%s %d\n", __FUNCTION__,__LINE__);
  343. /// Analog PLL
  344. // Reset all PLL functions
  345. ADC_Write(ADC_REG_ldo_pwde, 1); // 0x14a[1]
  346. ADC_Write(ADC_REG_ldo_pwd, 1); // 0x14a[0]
  347. ADC_Write(ADC_REG_cs2_pll_sw_rst, 0x1); // 0x1a[0]
  348. ADC_Write(ADC_REG_pll_pwdn, 0); // 0x32[1]
  349. ADC_Write(ADC_REG_dco_pdiv_rstj , 0x0); // 0x144[6]
  350. ADC_PllSetting(ucPixelClock, usHTotal);
  351. // Enable all PLL functions
  352. ADC_Write(ADC_REG_ldo_pwde, 0); // 0x14a[1]
  353. ADC_Write(ADC_REG_ldo_pwd, 0); // 0x14a[0]
  354. udelay(10);
  355. ADC_Write(ADC_REG_cs2_pll_sw_rst, 0x0); // 0x1a[0]
  356. ADC_Write(ADC_REG_pll_pwdn, 1); // 0x32[1]
  357. udelay(20);
  358. ADC_Write(ADC_REG_dco_pdiv_rstj , 0x1); // 0x144[6]
  359. /// Digital PLL
  360. //PLL SDM reset
  361. ADC_Write(ADC_REG_sdmresetj, 0);
  362. ADC_Write(ADC_REG_sdmresetj, 1);
  363. udelay(100);
  364. //PLL Line_div & Pixel_div reset
  365. ADC_Write(ADC_REG_dlpll_pdiv_rstj, 0);
  366. ADC_Write(ADC_REG_dlpll_pdiv_rstj, 1);
  367. // PLL 3-channel phase divider reset
  368. ADC_Write(ADC_REG_cs2_pdiv_sw_rst_ctrl, 0);
  369. ADC_Write(ADC_REG_pdiv_rstn, 0);
  370. ADC_Write(ADC_REG_pdiv_rstn, 1);
  371. ADC_DelayMS(1);
  372. }
  373. void ADC_SOG_Slicer_Backup(void)
  374. {
  375. ADC_Write(ADC_REG_cs2_sog_sw_rst, 0x1);
  376. ADC_Write(ADC_REG_cs2_sog_sw_rst, 0x0);
  377. }
  378. void ADC_Coast_Gen_Backup(void)
  379. {
  380. // 2010/12/30 modify by patrick
  381. ADC_Write(ADC_REG_adi_reset, 1);
  382. ADC_Write(ADC_REG_adi_reset, 0);
  383. }
  384. UINT32 ADC_InputSrcPinYvalue(UINT32 iPin)
  385. {
  386. switch (iPin)
  387. {
  388. case INPUT_PIN_AV_Y1:
  389. case INPUT_PIN_AV_Y_ON_G1:
  390. return 0x1;
  391. case INPUT_PIN_AV_Y2:
  392. case INPUT_PIN_AV_Y_ON_G2:
  393. return 0x2;
  394. case INPUT_PIN_AV_Y3:
  395. case INPUT_PIN_AV_Y_ON_G3:
  396. return 0x3;
  397. default:
  398. return 0;
  399. }
  400. }
  401. void DRV_ADC_YCInitSetting(int iInputSource)
  402. {
  403. ADC_DebugMsg("%s %d\n", __FUNCTION__,__LINE__);
  404. ADC_Write(GLB_REG_VCLK_DIV_RSTN, 1 ); // Set ADC_PLL reference divider reset as normal mode
  405. ADC_Write(GLB_REG_global_reset, 0);
  406. udelay(1000);
  407. ADC_Write(GLB_REG_global_reset, 1);
  408. DRV_ADC_YppShareBandGap_Power(TRUE); // power on MVADC's BGP (default value is 0 after global reset)
  409. switch(iInputSource)
  410. {
  411. case ADC_SV_INPUT_CHANNEL:
  412. if (iInputSource == ADC_SV_INPUT_CHANNEL)
  413. {
  414. ADC_DebugMsg("Source SV: pin on Y%d_CHANNEL...\n", ADC_InputSrcPinYvalue(adc_InputSrcPin.svideo.y_pin));
  415. if (adc_InputSrcPin.svideo.c_pin == INPUT_PIN_AV_Y0_C0)
  416. {
  417. ADC_DebugMsg("Source SV: C on G3_CHANNEL...\n");
  418. //C on G chel
  419. ADC_Write(ADC_REG_lcg_gch_sel, 0x3);
  420. //off R B chel
  421. ADC_Write(ADC_REG_sch_pwdn_r, 0x1);
  422. ADC_Write(ADC_REG_sch_pwdn_b, 0x1);
  423. }
  424. else
  425. {
  426. ADC_DebugMsg("Source SV: C on R3_CHANNEL...\n");
  427. //C on R chel
  428. ADC_Write(ADC_REG_lcg_rch_sel, 0x3);
  429. //off G B chel
  430. ADC_Write(ADC_REG_sch_pwdn_g, 0x1);
  431. ADC_Write(ADC_REG_sch_pwdn_b, 0x1);
  432. }
  433. ADC_Write(ADC_REG_y_chsel, ADC_InputSrcPinYvalue(adc_InputSrcPin.svideo.y_pin));
  434. }
  435. ADC_Write(ADC_REG_g_sb2, 0x8);
  436. ADC_Write(ADC_REG_sch_pbw_ctrl, 0xf);
  437. ADC_Write(ADC_REG_sch_ref_pbw_ctrl, 0xf);
  438. ADC_Write(ADC_REG_R_SYPP120, 1);
  439. ADC_Write(ADC_REG_R_SYPP121, 0);
  440. ADC_Write(ADC_REG_R_SCVBS12, 0);
  441. ADC_Write(ADC_REG_G_SCVBS12, 0x1);
  442. ADC_Write(ADC_REG_av_r_pg12v1, 0);
  443. ADC_Write(ADC_REG_av_g_pg12v1, 0);
  444. ADC_Write(ADC_REG_av_g_pg12v2, 1);
  445. break;
  446. case ADC_AV1_INPUT_CHANNEL:
  447. case ADC_AV2_INPUT_CHANNEL:
  448. case ADC_AV_ON_G_CHANNEL:
  449. if ( ( adc_InputSrcPin.cvbs.pin == INPUT_PIN_AV_Y1) || ( adc_InputSrcPin.cvbs.pin == INPUT_PIN_AV_Y2) || ( adc_InputSrcPin.cvbs.pin == INPUT_PIN_AV_Y3) || ( adc_InputSrcPin.cvbs.pin == INPUT_PIN_AV_Y4))
  450. {
  451. ADC_DebugMsg("Source AV: pin on Y%d_CHANNEL...\n", ADC_InputSrcPinYvalue(adc_InputSrcPin.cvbs.pin));
  452. if (iInputSource == ADC_AV1_INPUT_CHANNEL)
  453. {
  454. ADC_DebugMsg("Input AV1 Init Setting...\n");
  455. ADC_Write(ADC_REG_lcg_rch_sel, 1);
  456. ADC_Write(ADC_REG_lcg_gch_sel, 1);
  457. ADC_Write(ADC_REG_lcg_bch_sel, 1);
  458. }
  459. else if (iInputSource == ADC_AV2_INPUT_CHANNEL)
  460. {
  461. ADC_DebugMsg("Input AV2 Init Setting...\n");
  462. ADC_Write(ADC_REG_lcg_rch_sel, 2);
  463. ADC_Write(ADC_REG_lcg_gch_sel, 2);
  464. ADC_Write(ADC_REG_lcg_bch_sel, 2);
  465. }
  466. else
  467. {
  468. ADC_DebugMsg("Input AV3 Init Setting...\n");
  469. ADC_Write(ADC_REG_lcg_rch_sel, 3);
  470. ADC_Write(ADC_REG_lcg_gch_sel, 3);
  471. ADC_Write(ADC_REG_lcg_bch_sel, 3);
  472. }
  473. //Y chel select
  474. ADC_Write(ADC_REG_y_chsel, ADC_InputSrcPinYvalue(adc_InputSrcPin.cvbs.pin) );
  475. //off R G B chel
  476. ADC_Write(ADC_REG_sch_pwdn_r, 0x1);
  477. ADC_Write(ADC_REG_sch_pwdn_g, 0x1);
  478. ADC_Write(ADC_REG_sch_pwdn_b, 0x1);
  479. ADC_Write(ADC_REG_av_g_pg12v1, 0); // ADC MDAC OP current (0: Large current / 1: Small current)
  480. ADC_Write(ADC_REG_av_g_pg12v2, 1);
  481. }
  482. else
  483. {
  484. ADC_DebugMsg("Source AV: pin on G%d_CHANNEL...\n", ADC_InputSrcPinYvalue(adc_InputSrcPin.cvbs.pin));
  485. ADC_Write(ADC_REG_lcg_rch_sel, 0);
  486. ADC_Write(ADC_REG_lcg_gch_sel, ADC_InputSrcPinYvalue(adc_InputSrcPin.cvbs.pin));
  487. ADC_Write(ADC_REG_lcg_bch_sel, 0);
  488. ADC_Write(ADC_REG_sch_pbw_ctrl, 0xf);
  489. ADC_Write(ADC_REG_sch_ref_pbw_ctrl, 0xf);
  490. // Power on RGB channel
  491. ADC_Write(ADC_REG_sch_pwdn_r, 0x1);
  492. ADC_Write(ADC_REG_sch_pwdn_g, 0x0);
  493. ADC_Write(ADC_REG_sch_pwdn_b, 0x1);
  494. ADC_Write(ADC_REG_pwdny, 1);
  495. // Setup RGN channel ADC common mode
  496. ADC_Write(ADC_REG_lcg_r33vcm_sel, 0x7);
  497. ADC_Write(ADC_REG_lcg_g33vcm_sel, 0x7);
  498. ADC_Write(ADC_REG_lcg_b33vcm_sel, 0x7);
  499. ADC_Write(ADC_REG_g_12vcm_sel, 0x4);
  500. ADC_Write(ADC_REG_R_SYPP120, 0);
  501. ADC_Write(ADC_REG_R_SYPP121, 0);
  502. ADC_Write(ADC_REG_R_SCVBS12, 0);
  503. ADC_Write(ADC_REG_G_SYPP120, 0);
  504. ADC_Write(ADC_REG_G_SYPP121, 0);
  505. ADC_Write(ADC_REG_G_SCVBS12, 1);
  506. ADC_Write(ADC_REG_B_SYPP120, 0);
  507. ADC_Write(ADC_REG_B_SYPP121, 0);
  508. ADC_Write(ADC_REG_b_scvbs12, 0);
  509. ADC_Write(ADC_REG_CHR_SIFCLK_SEL, 0);
  510. ADC_Write(ADC_REG_av_g_pg12v1, 0); // ADC MDAC OP current (0: Large current / 1: Small current)
  511. ADC_Write(ADC_REG_av_g_pg12v2, 0);
  512. ADC_Write(ADC_REG_gcvbsen, 1);
  513. ADC_Write(ADC_REG_pll_div_sel, 0);
  514. ADC_Write(ADC_REG_pll_divb_sel, 0);//ADC_Write(ADC_REG_pll_divb_sel, 1);
  515. ADC_Write(ADC_REG_pll_ref_sel, 2);
  516. }
  517. break;
  518. default:
  519. ADC_DebugMsg("Do Not Need ADC Init Setting...\n");
  520. break;
  521. }
  522. ADC_Write(ADC_REG_ext_clk_muxsel, 0x1);// 0xa7[5:4] ADC_Write(ADC_REG_ext_clk_muxsel, 0x1);
  523. ADC_Write(ADC_REG_pll_extpclk_sel, 0); // 0x39[4]
  524. ADC_Write(GLB_REG_VADC_REF_SEL_24M, 0); // 0xbe000149[6] 24 MHz reference selector. 0: CPLL, 1: Crystal 24M
  525. // Y chel setting
  526. ADC_Write(ADC_REG_y_ffadj12v, 0x1);
  527. ADC_Write(ADC_REG_clamp_mode_y, 0x1);
  528. ADC_Write(ADC_REG_y_mp10y, 0);
  529. ADC_Write(ADC_REG_y_pga12v1, 0);
  530. // Pull down unused RGB
  531. ADC_Write(ADC_REG_r_pden12v, 1);
  532. ADC_Write(ADC_REG_g_pden12v, 1);
  533. ADC_Write(ADC_REG_b_pden12v, 1);
  534. ADC_Write(ADC_REG_r_tswmiden12v, 1);
  535. ADC_Write(ADC_REG_g_tswmiden12v, 1);
  536. ADC_Write(ADC_REG_b_tswmiden12v, 1);
  537. ADC_Write(ADC_REG_y_pga12v2_bit4, 0);
  538. ADC_Write(ADC_REG_y_pga12v3, 0);
  539. ADC_Write(ADC_REG_y_sb2, 0);
  540. ADC_Write(ADC_REG_y_sb1, 0xc);
  541. ADC_Write(ADC_REG_y_sypp12, 0);
  542. ADC_Write(ADC_REG_y_clamp_en, 0x1);
  543. ADC_Write(ADC_REG_y_scvbs12, 1);
  544. ADC_Write(ADC_REG_sog_ch1_sel, 1);
  545. ADC_Write(ADC_REG_rwclampeco, 1);
  546. //Differential mode setting
  547. ADC_Write(ADC_REG_y_pden12v, 0);
  548. ADC_Write(ADC_REG_y_refch12v, 3);
  549. ADC_Write(ADC_REG_y_tswmiden12v, 1);
  550. ADC_Write(ADC_REG_y_refclampsel12v, 0);
  551. ADC_Write(ADC_REG_y_intrefen12v, 1);
  552. ADC_Write(ADC_REG_av_r_pg12v2, 1);
  553. ADC_Write(ADC_REG_av_b_pg12v2, 1);
  554. ADC_Write(ADC_REG_r_refch12v, 2);
  555. ADC_Write(ADC_REG_g_refch12v, 2);
  556. ADC_Write(ADC_REG_b_refch12v, 2);
  557. ADC_Write(ADC_REG_r_lpfmod12v, 0);
  558. ADC_Write(ADC_REG_g_lpfmod12v, 0);
  559. ADC_Write(ADC_REG_b_lpfmod12v, 0);
  560. ADC_Write(ADC_REG_r_refclampsel12v, 1);
  561. ADC_Write(ADC_REG_g_refclampsel12v, 0);
  562. ADC_Write(ADC_REG_b_refclampsel12v, 1);
  563. ADC_Write(ADC_REG_r_intrefen12v, 1);
  564. ADC_Write(ADC_REG_g_intrefen12v, 1);
  565. ADC_Write(ADC_REG_b_intrefen12v, 1);
  566. ADC_Write(ADC_REG_epdy_12v, 0);
  567. //enable VBG from Audio
  568. ADC_Write(ADC_REG_cal_manual_en, 0);
  569. ADC_Write(ADC_REG_cal_manual_th, 0x00);
  570. ADC_Write(ADC_REG_cal_sw_ctrl_en, 1);
  571. ADC_Write(ADC_REG_cal_sw_ctrl_th, 0x0b);
  572. //disable auto source select
  573. ADC_Write(ADC_REG_ss_mode, 0x1);
  574. #ifdef CONFIG_BOE_HV430FHB_N40
  575. // Cannot pull down due to Tcon_7 and VGA_R are bonded on N40 panel
  576. ADC_Write(ADC_REG_r_epd12v, 0x0);
  577. #else
  578. //Enalbe YPP F switch function
  579. ADC_Write(ADC_REG_r_epd12v, 0x1);
  580. #endif
  581. //SOG comparator power down
  582. ADC_Write(ADC_REG_sog_pwdn,1);
  583. //Enable LPF
  584. ADC_Write(ADC_REG_y_scvbs12, 0x2);
  585. ADC_Write(ADC_REG_lpfmod12v, 0x1);
  586. //clamp
  587. ADC_Write(ADC_REG_adc_mode, 0x1);
  588. ADC_Write(ADC_REG_clamp_mode, 1);
  589. ADC_Write(ADC_REG_y_pga12v2_bit0to3, 0);
  590. }
  591. void DRV_ADC_PLL100MHzToCVD2(void)
  592. {
  593. ADC_DebugMsg("%s %d\n", __FUNCTION__,__LINE__);
  594. //set PLL power
  595. ADC_Write(ADC_REG_vbg_sel, 0x3);
  596. //pll hardware reset disable
  597. ADC_Write(ADC_REG_cs2_pll_rst_sel, 0x1);
  598. // Reset all PLL functions
  599. ADC_Write(ADC_REG_cs2_pll_sw_rst, 1); // 0x1a[0]
  600. ADC_Write(ADC_REG_dco_pdiv_rstj , 0x0); // 0x144[6]
  601. ADC_Write(ADC_REG_ldo_pwd, 1); // 0x14a[0]
  602. ADC_Write(ADC_REG_ldo_pwde, 1); // 0x14a[1]
  603. //ADC_Write(ADC_REG_pll_rstn, 0); // 0x32[0]
  604. ADC_Write(ADC_REG_pll_pwdn, 0); // 0x32[1]
  605. ADC_Write(ADC_REG_ext_clk_muxsel, 0x1); // ADC_Write(ADC_REG_ext_clk_muxsel, 0x2);
  606. ADC_Write(ADC_REG_dco_en_fdiv, 0x0);
  607. ADC_Write(ADC_REG_dco_febdiv, 0x2f); // 0x143[7:0]
  608. ADC_Write(ADC_REG_dco_gb, 0x04); // 0x144[5:0]
  609. ADC_Write(ADC_REG_dco_ictrl, 0x05); // 0x145[7:0]
  610. ADC_Write(ADC_REG_dlpll_pxdiv, 0xb);
  611. ADC_Write(ADC_REG_dco_refdiv, 0x08); // 0x147[4:0]
  612. //R-channel clock divider setting
  613. ADC_Write(ADC_REG_pll_div_sel, 0);
  614. ADC_Write(ADC_REG_pll_divb_sel, 1);
  615. //LN_div msb
  616. ADC_Write(ADC_REG_r_pll_opi, 0);
  617. // Enable all PLL functions
  618. //ADC_Write(ADC_REG_ldo_pwd, 0); // 0x14a[0]
  619. //ADC_Write(ADC_REG_pll_rstn, 1); // 0x32[0]
  620. //ADC_Write(ADC_REG_pll_pwdn, 1); // 0x32[1]
  621. // For preventing Vcpt floating, PFD reset should be triggered before toggling DCO LPF
  622. ADC_Write(ADC_REG_cs2_pll_sw_rst, 0x1); // 0x1a[0]
  623. ADC_Write(ADC_REG_cs2_pll_sw_rst, 0x0); // 0x1a[0]
  624. //ADC_Write(ADC_REG_dco_pdiv_rstj , 0x1); // 0x144[6]
  625. // Enable all PLL functions
  626. ADC_Write(ADC_REG_ldo_pwde, 0); // 0x14a[1]
  627. ADC_Write(ADC_REG_ldo_pwd, 0); // 0x14a[0]
  628. udelay(10);
  629. ADC_Write(ADC_REG_cs2_pll_sw_rst, 0x0); // 0x1a[0]
  630. ADC_Write(ADC_REG_pll_pwdn, 1); // 0x32[1]
  631. udelay(20);
  632. ADC_Write(ADC_REG_dco_pdiv_rstj , 0x1); // 0x144[6]
  633. // DCO LPF
  634. ADC_Write(ADC_REG_dco_en_fdiv, 0x1);
  635. ADC_Write(ADC_REG_pdiv_rstn, 0x1);
  636. ADC_Write(ADC_REG_pll_pdiv_en, 0);
  637. ADC_Write(ADC_REG_pll_ref_sel, 0x2);
  638. ADC_DelayMS(1);
  639. ADC_Write(ADC_REG_dlpll_pdiv_rstj, 0x0);
  640. //ADC_Write(ADC_REG_dlpll_pdiv_rstj, 0x1);
  641. //ADC_Write(ADC_REG_dco_bx2, 0);
  642. //ADC_Write(ADC_REG_dco_bx2, 0x1);
  643. ADC_Write(ADC_REG_pll_phase_r_sel, 0x8);
  644. ADC_Write(ADC_REG_pll_phase_g_sel, 0xc);
  645. ADC_Write(ADC_REG_pll_phase_b_sel, 0x10);
  646. // Preventing PLL lock failed, additional DCO LPF power down and then trigger again.
  647. //ADC_Write(ADC_REG_ldo_pwde, 1); // 0x14a[1]
  648. // udelay(10);
  649. //ADC_Write(ADC_REG_ldo_pwde, 0); // 0x14a[1]
  650. }
  651. void DRV_ADC_Pll_Divider_Power(BOOL Enable)
  652. {
  653. // Provide for the stability of 100MHz on AV source when power on.
  654. ADC_Write(ADC_REG_dlpll_pdiv_rstj, Enable);
  655. // Set ADC_PLL reference divider reset as normal mode
  656. ADC_Write(GLB_REG_VCLK_DIV_RSTN, Enable);
  657. ADC_DebugMsg("Turn %s ADC PLL divider.\n", Enable?"On":"Off");
  658. }
  659. void DRV_ADC_YppShareBandGap_Power(BOOL Enable)
  660. {
  661. if(Enable) // turn on MVADC's bandgap
  662. ADC_Write(ADC_REG_vbg_pwdn,0);
  663. else // turn off MVADC's bandgap
  664. ADC_Write(ADC_REG_vbg_pwdn,1);
  665. }