tvafe_adc.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  1. /*
  2. * TVAFE adc device driver.
  3. *
  4. * Copyright (c) 2010 Frank zhao <frank.zhao@amlogic.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the smems of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. */
  10. /******************************Includes************************************/
  11. #include <linux/errno.h>
  12. #include <linux/kernel.h>
  13. #include <mach/am_regs.h>
  14. #include "tvafe.h"
  15. #include "tvafe_regs.h"
  16. #include "tvafe_general.h"
  17. #include "tvafe_adc.h"
  18. /***************************Local defines**********************************/
  19. #define AUTO_CLK_VS_CNT 15//10 // get stable BD readings after n+1 frames
  20. #define AUTO_PHASE_VS_CNT 1 // get stable AP readings after n+1 frames
  21. #define ADC_WINDOW_H_OFFSET 32 // auto phase window h offset
  22. #define ADC_WINDOW_V_OFFSET 2 // auto phase window v offset
  23. #define MAX_AUTO_CLOCK_ORDER 4 // 1/16 headroom
  24. #define VGA_AUTO_TRY_COUNTER 300 // vga max adjust counter, 3 seconds
  25. // divide window into 7*7 sub-windows & make phase detection on 9 sub-windows
  26. // -------
  27. // -*-*-*-
  28. // -------
  29. // -*-*-*-
  30. // -------
  31. // -*-*-*-
  32. // -------
  33. #define VGA_AUTO_PHASE_H_WIN 7
  34. #define VGA_AUTO_PHASE_V_WIN 7
  35. #define TVIN_FMT_CHG_VGA_H_CNT_WOBBLE 5
  36. #define TVIN_FMT_CHG_VGA_V_CNT_WOBBLE 1
  37. #define TVIN_FMT_CHG_VGA_HS_CNT_WOBBLE 5
  38. #define TVIN_FMT_CHG_VGA_VS_CNT_WOBBLE 1
  39. #define TVIN_FMT_CHG_COMP_H_CNT_WOBBLE 7//5
  40. #define TVIN_FMT_CHG_COMP_V_CNT_WOBBLE 3// 1
  41. #define TVIN_FMT_CHG_COMP_HS_CNT_WOBBLE 0xffffffff // not to trust
  42. #define TVIN_FMT_CHG_COMP_VS_CNT_WOBBLE 0xffffffff // not to trust
  43. #define TVIN_FMT_CHK_VGA_VS_CNT_WOBBLE 1
  44. #define TVAFE_H_MAX 0xfff
  45. #define TVAFE_H_MIN 0x000
  46. #define TVAFE_V_MAX 0xfff
  47. #define TVAFE_V_MIN 0x000
  48. #define TVAFE_VGA_VS_CNT_MAX 200
  49. #define TVAFE_VGA_BD_EN_DELAY 4 //4//4 field delay
  50. #define TVAFE_ADC_CONFIGURE_INIT 1
  51. #define TVAFE_ADC_CONFIGURE_NORMAL 1|(1<<POWERDOWNZ_BIT)|(1<<RSTDIGZ_BIT) // 7
  52. #define TVAFE_ADC_CONFIGURE_RESET_ON 1|(1<<POWERDOWNZ_BIT) // 5
  53. #define TVAFE_VGA_CLK_TUNE_RANGE_ORDER 4 // 1/16 h_total
  54. #define TVAFE_VGA_HPOS_TUNE_RANGE_ORDER 6 // 1/64 h_active
  55. #define TVAFE_VGA_VPOS_TUNE_RANGE_ORDER 6 // 1/64 v_active
  56. /***************************Local Structures**********************************/
  57. static struct tvin_format_s adc_timing_info =
  58. {
  59. //H_Active V_Active H_cnt Hcnt_offset Vcnt_offset Hs_cnt Hscnt_offset
  60. 0, 0, 0, 0, 0, 0, 0,
  61. //H_Total V_Total Hs_Front Hs_Width Hs_bp Vs_Front Vs_Width Vs_bp Hs_Polarity
  62. 0, 0, 0, 0, 0, 0, 0, 0, TVIN_SYNC_POL_NULL,
  63. //Vs_Polarity Scan_Mode Pixel_Clk(Khz/10) VBIs vbie
  64. TVIN_SYNC_POL_NULL, TVIN_SCAN_MODE_NULL, 0, 0, 0
  65. };
  66. static struct tvafe_vga_auto_state_s vga_auto = {
  67. VGA_CLK_IDLE,
  68. VGA_PHASE_IDLE,
  69. 0,
  70. 0,
  71. 0,
  72. 0,
  73. 0,
  74. 0,
  75. 0,
  76. 0,
  77. {0, 0, 0, 0}
  78. };
  79. // *****************************************************************************
  80. // Function:get ADC DVSS signal status
  81. //
  82. // Params: none
  83. //
  84. // Return: none
  85. //
  86. // *****************************************************************************
  87. bool tvafe_adc_get_pll_status(void)
  88. {
  89. return (bool)READ_APB_REG_BITS(ADC_REG_35, PLLLOCKED_BIT, PLLLOCKED_WID);
  90. }
  91. /*
  92. const static int unsigned short charge_pump_tbl[] = {0};
  93. // *****************************************************************************
  94. // Function:set adc clock
  95. //
  96. // Params: format index
  97. //
  98. // Return: success/error
  99. //
  100. // *****************************************************************************
  101. static void tvafe_adc_set_clock(enum tvin_sig_fmt_e fmt)
  102. {
  103. unsigned char div_ratio,vco_range_sel,i;
  104. unsigned short vco_gain;
  105. unsigned long k_vco,hs_freq,tmp;
  106. unsigned char charge_pump_table[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7};
  107. //select vco range and gain by pixel clock
  108. if (tvin_fmt_tbl[fmt].pixel_clk < 2500) //25Mhz
  109. vco_range_sel |= 0x00;
  110. else if (tvin_fmt_tbl[fmt].pixel_clk < 4000) //40MHz
  111. vco_range_sel |= 0x01;
  112. else if (tvin_fmt_tbl[fmt].pixel_clk < 10000) //100MHz
  113. vco_range_sel |= 0x02;
  114. else
  115. vco_range_sel |= 0x03;
  116. //set vco sel reg
  117. WRITE_APB_REG_BITS(ADC_REG_68, vco_range_sel, VCORANGESEL_BIT, VCORANGESEL_WID);
  118. //set charge pump current value
  119. WRITE_APB_REG_BITS(ADC_REG_69, charge_pump_tbl[fmt], CHARGEPUMPCURR_BIT, CHARGEPUMPCURR_WID);
  120. // PLL divider programming
  121. div_ratio = (unsigned char)((tvin_fmt_tbl[fmt].h_total - 1) & 0x0FF0) >> 4;
  122. WRITE_APB_REG_BITS(ADC_REG_01, div_ratio, PLLDIVRATIO_MSB_BIT, PLLDIVRATIO_MSB_WID);
  123. div_ratio = (unsigned char)((tvin_fmt_tbl[fmt].h_total - 1) & 0x000F) << 4;
  124. WRITE_APB_REG_BITS(ADC_REG_02, div_ratio, PLLDIVRATIO_LSB_BIT, PLLDIVRATIO_LSB_WID);
  125. return;
  126. }
  127. // *****************************************************************************
  128. // Function:set adc analog buffer bandwidth
  129. //
  130. // Params: format index, adc channel
  131. //
  132. // Return: none
  133. //
  134. // *****************************************************************************
  135. static void tvafe_adc_set_bw_lpf(enum tvin_sig_fmt_e fmt)
  136. {
  137. unsigned char i;
  138. unsigned int freq[] = {
  139. 5, 7, 9, 13, 16, 20, 25, 28,
  140. 33, 37, 40, 47, 54, 67, 74, 81,
  141. 90, 150, 230, 320, 450, 600, 750
  142. };
  143. unsigned char lpf_ctl_tbl[] = {
  144. 0x0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  145. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  147. };
  148. unsigned char bw_tbl[] = {
  149. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  150. 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
  151. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  152. };
  153. for (i = 0; i <= 22; i++) {
  154. if (((tvin_fmt_tbl[fmt].pixel_clk/100)/2) <= (unsigned long)freq[i]) //Mhz
  155. break;
  156. }
  157. if (i > 15) { //if pixel clk > 2*81Mhz should close lpf
  158. WRITE_APB_REG_BITS(ADC_REG_19, 0, ENLPFA_BIT, ENLPFA_WID);
  159. WRITE_APB_REG_BITS(ADC_REG_1A, 0, ENLPFB_BIT, ENLPFB_WID);
  160. WRITE_APB_REG_BITS(ADC_REG_1B, 0, ENLPFC_BIT, ENLPFC_WID);
  161. } else {
  162. WRITE_APB_REG_BITS(ADC_REG_19, 1, ENLPFA_BIT, ENLPFA_WID);
  163. WRITE_APB_REG_BITS(ADC_REG_1A, 1, ENLPFB_BIT, ENLPFB_WID);
  164. WRITE_APB_REG_BITS(ADC_REG_1B, 1, ENLPFC_BIT, ENLPFC_WID);
  165. WRITE_APB_REG_BITS(ADC_REG_19, lpf_ctl_tbl[i], LPFBWCTRA_BIT, LPFBWCTRA_WID);
  166. WRITE_APB_REG_BITS(ADC_REG_1A, lpf_ctl_tbl[i], LPFBWCTRB_BIT, LPFBWCTRB_WID);
  167. WRITE_APB_REG_BITS(ADC_REG_1B, lpf_ctl_tbl[i], LPFBWCTRC_BIT, LPFBWCTRC_WID);
  168. }
  169. WRITE_APB_REG_BITS(ADC_REG_19, bw_tbl[i], ANABWCTRLA_BIT, ANABWCTRLA_WID);
  170. WRITE_APB_REG_BITS(ADC_REG_1A, bw_tbl[i], ANABWCTRLB_BIT, ANABWCTRLB_WID);
  171. WRITE_APB_REG_BITS(ADC_REG_1B, bw_tbl[i], ANABWCTRLB_BIT, ANABWCTRLC_WID);
  172. return;
  173. }
  174. // *****************************************************************************
  175. // Function:set adc clamp parameter
  176. //
  177. // Params: format index
  178. //
  179. // Return: success/error
  180. //
  181. // *****************************************************************************
  182. void tvafe_adc_set_clamp_para(enum tvin_sig_fmt_e fmt)
  183. {
  184. WRITE_APB_REG_BITS(ADC_REG_03, (tvin_fmt_tbl[fmt].hs_width + 10),
  185. CLAMPPLACEM_BIT, CLAMPPLACEM_WID);
  186. WRITE_APB_REG_BITS(ADC_REG_04, (tvin_fmt_tbl[fmt].hs_bp - 10), CLAMPDURATION_BIT, CLAMPDURATION_WID);
  187. return;
  188. }
  189. */
  190. // *****************************************************************************
  191. // Function:get ADC signal info(hcnt,vcnt,hpol,vpol)
  192. //
  193. // Params: none
  194. //
  195. // Return: none
  196. //
  197. // *****************************************************************************
  198. bool tvafe_adc_no_sig(void)
  199. {
  200. return (READ_APB_REG_BITS(TVFE_DVSS_INDICATOR1, NOSIG_BIT, NOSIG_WID) ? true : false);
  201. }
  202. // *****************************************************************************
  203. // Function:get ADC signal info(hcnt,vcnt,hpol,vpol)
  204. //
  205. // Params: none
  206. //
  207. // Return: none
  208. //
  209. // *****************************************************************************
  210. bool tvafe_adc_fmt_chg(struct tvafe_info_s *info) //(enum tvafe_src_type_e src_type, struct tvin_parm_s *parm)
  211. {
  212. unsigned short tmp0 = 0, tmp1 = 0;
  213. unsigned int h_cnt_offset = 0, v_cnt_offset = 0;
  214. unsigned int hs_cnt_offset = 0, vs_cnt_offset = 0;
  215. unsigned int h_cnt_wobble = 0, v_cnt_wobble = 0;
  216. unsigned int hs_cnt_wobble = 0, vs_cnt_wobble = 0;
  217. bool h_pol_chg = false, v_pol_chg = false;
  218. bool flag = (bool)READ_APB_REG_BITS(TVFE_DVSS_INDICATOR1,
  219. NOSIG_BIT, NOSIG_WID);
  220. if (flag)
  221. {
  222. pr_info("tvafe fmt check no signal \n");
  223. return flag;
  224. }
  225. if (info->src_type == TVAFE_SRC_TYPE_VGA)
  226. {
  227. h_cnt_wobble = TVIN_FMT_CHG_VGA_H_CNT_WOBBLE;
  228. v_cnt_wobble = TVIN_FMT_CHG_VGA_V_CNT_WOBBLE;
  229. hs_cnt_wobble = TVIN_FMT_CHG_VGA_HS_CNT_WOBBLE;
  230. vs_cnt_wobble = TVIN_FMT_CHG_VGA_VS_CNT_WOBBLE;
  231. //h_pol
  232. flag = (bool)READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR3,
  233. SPOL_H_POL_BIT, SPOL_H_POL_WID);
  234. if (flag)
  235. {
  236. if (adc_timing_info.hs_pol == TVIN_SYNC_POL_POSITIVE)
  237. h_pol_chg = true;
  238. adc_timing_info.hs_pol = TVIN_SYNC_POL_NEGATIVE;
  239. }
  240. else
  241. {
  242. if (adc_timing_info.hs_pol == TVIN_SYNC_POL_NEGATIVE)
  243. h_pol_chg = true;
  244. adc_timing_info.hs_pol = TVIN_SYNC_POL_POSITIVE;
  245. }
  246. //v_pol
  247. flag = (bool)READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR3,
  248. SPOL_V_POL_BIT, SPOL_V_POL_WID);
  249. if (flag)
  250. {
  251. if (adc_timing_info.vs_pol == TVIN_SYNC_POL_POSITIVE)
  252. v_pol_chg = true;
  253. adc_timing_info.vs_pol = TVIN_SYNC_POL_NEGATIVE;
  254. }
  255. else
  256. {
  257. if (adc_timing_info.vs_pol == TVIN_SYNC_POL_NEGATIVE)
  258. v_pol_chg = true;
  259. adc_timing_info.vs_pol = TVIN_SYNC_POL_POSITIVE;
  260. }
  261. }
  262. else if (info->src_type == TVAFE_SRC_TYPE_COMP)
  263. {
  264. h_cnt_wobble = TVIN_FMT_CHG_COMP_H_CNT_WOBBLE;
  265. v_cnt_wobble = TVIN_FMT_CHG_COMP_V_CNT_WOBBLE;
  266. hs_cnt_wobble = TVIN_FMT_CHG_COMP_HS_CNT_WOBBLE;
  267. vs_cnt_wobble = TVIN_FMT_CHG_COMP_VS_CNT_WOBBLE;
  268. }
  269. else
  270. {
  271. pr_info("tvafe fmt check no signal \n");
  272. return flag;
  273. }
  274. // hs_cnt
  275. tmp0 = (unsigned short)READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR1_HCNT,
  276. SPOL_HCNT_NEG_BIT, SPOL_HCNT_NEG_WID);
  277. tmp1 = (unsigned short)READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR1_HCNT,
  278. SPOL_HCNT_POS_BIT, SPOL_HCNT_POS_WID);
  279. tmp0 = (tmp0 < tmp1) ? tmp0 : tmp1;
  280. hs_cnt_offset = ABS((signed int)adc_timing_info.hs_cnt - (signed int)tmp0);
  281. adc_timing_info.hs_cnt = tmp0;
  282. // vs_cnt
  283. tmp0 = (unsigned short)READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR2_VCNT,
  284. SPOL_VCNT_NEG_BIT, SPOL_VCNT_NEG_WID);
  285. tmp1 = (unsigned short)READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR2_VCNT,
  286. SPOL_VCNT_POS_BIT, SPOL_VCNT_POS_WID);
  287. tmp0 = (tmp0 < tmp1) ? tmp0 : tmp1;
  288. vs_cnt_offset = ABS((signed int)adc_timing_info.vs_width - (signed int)tmp0);
  289. adc_timing_info.vs_width = tmp0;
  290. // h_cnt
  291. tmp0 = READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR4,
  292. SAM_HCNT_BIT, SAM_HCNT_WID);
  293. if ((info->param.status == TVIN_SIG_STATUS_STABLE) &&
  294. (info->src_type == TVAFE_SRC_TYPE_COMP))
  295. adc_timing_info.h_cnt = tvin_fmt_tbl[info->param.fmt].h_cnt;
  296. h_cnt_offset = ABS((signed int)adc_timing_info.h_cnt - (signed int)tmp0);
  297. //h_cnt_offset = ABS((signed int)tvin_fmt_tbl[fmt].h_cnt - (signed int)tmp0);
  298. adc_timing_info.h_cnt = tmp0;
  299. // v_cnt
  300. tmp0 = READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR4,
  301. SAM_VCNT_BIT, SAM_VCNT_WID);
  302. if ((info->param.status == TVIN_SIG_STATUS_STABLE) &&
  303. (info->src_type == TVAFE_SRC_TYPE_COMP))
  304. adc_timing_info.v_total = tvin_fmt_tbl[info->param.fmt].v_total;
  305. v_cnt_offset = ABS((signed int)adc_timing_info.v_total - (signed int)tmp0);
  306. //v_cnt_offset = ABS((signed int)tvin_fmt_tbl[fmt].v_total- (signed int)tmp0);
  307. adc_timing_info.v_total = tmp0;
  308. if ((h_cnt_offset > h_cnt_wobble) ||
  309. (v_cnt_offset > v_cnt_wobble) ||
  310. (hs_cnt_offset > hs_cnt_wobble) ||
  311. (vs_cnt_offset > vs_cnt_wobble) ||
  312. h_pol_chg ||
  313. v_pol_chg
  314. )
  315. flag = true;
  316. else
  317. flag = false;
  318. return flag;
  319. }
  320. // *****************************************************************************
  321. // Function:set ADC sync mux setting
  322. //
  323. // Params: none
  324. //
  325. // Return: sucess/error
  326. //
  327. // *****************************************************************************
  328. //static int tvafe_adc_sync_select(enum adc_sync_type_e sync_type)
  329. //{
  330. // int ret = 0;
  331. //
  332. // switch (sync_type) {
  333. // case ADC_SYNC_AUTO:
  334. // tvafe_reg_set_bits(ADC_REG_39, ADC_REG_SYNCMUXCTRLBYPASS, ADC_REG_SYNCMUXCTRLBYPASS_MASK, 1);
  335. // tvafe_reg_set_bits(ADC_REG_39, ADC_REG_SYNCMUXCTRL, ADC_REG_SYNCMUXCTRL_MASK, 1);
  336. // tvafe_reg_set_bits(ADC_REG_2E, ADC_REG_HSYNCACTVOVRD, ADC_REG_HSYNCACTVOVRD_MASK, 1);
  337. // tvafe_reg_set_bits(ADC_REG_2E, ADC_REG_VSYNCACTVSEL, ADC_REG_VSYNCACTVSEL_MASK, 1);
  338. // break;
  339. // case ADC_SYNC_SEPARATE:
  340. // //...
  341. // break;
  342. // case ADC_SYNC_SOG:
  343. // //...
  344. // break;
  345. // }
  346. //
  347. // return ret;
  348. //}
  349. void tvafe_adc_digital_reset(void)
  350. {
  351. WRITE_APB_REG(((ADC_BASE_ADD+0x21)<<2), 1);
  352. WRITE_APB_REG(((ADC_BASE_ADD+0x21)<<2), 5);
  353. WRITE_APB_REG(((ADC_BASE_ADD+0x21)<<2), 7);
  354. }
  355. // *****************************************************************************
  356. // Function: search input format by the info table
  357. //
  358. // Params: none
  359. //
  360. // Return: format index
  361. //
  362. // *****************************************************************************
  363. enum tvin_sig_fmt_e tvafe_adc_search_mode(enum tvafe_src_type_e src_type)
  364. {
  365. enum tvin_sig_fmt_e index = TVIN_SIG_FMT_NULL;
  366. enum tvin_sig_fmt_e index_min = TVIN_SIG_FMT_NULL;
  367. enum tvin_sig_fmt_e index_max = TVIN_SIG_FMT_NULL;
  368. //unsigned int hcnt = 0;
  369. switch (src_type)
  370. {
  371. case TVAFE_SRC_TYPE_VGA:
  372. index_min = TVIN_SIG_FMT_NULL;
  373. index_max = TVIN_SIG_FMT_VGA_MAX;
  374. break;
  375. case TVAFE_SRC_TYPE_COMP:
  376. index_min = TVIN_SIG_FMT_VGA_MAX;
  377. index_max = TVIN_SIG_FMT_COMP_MAX;
  378. break;
  379. default:
  380. break;
  381. }
  382. if (index_max)
  383. {
  384. for (index=index_min+1; index<index_max; index++)
  385. {
  386. if ((src_type == TVAFE_SRC_TYPE_COMP) ||
  387. (
  388. // VGA h_pol
  389. (adc_timing_info.hs_pol == tvin_fmt_tbl[index].hs_pol) &&
  390. // VGA v_pol
  391. (adc_timing_info.vs_pol == tvin_fmt_tbl[index].vs_pol) &&
  392. // VGA hs_cnt
  393. (ABS((signed int)adc_timing_info.hs_cnt - (signed int)tvin_fmt_tbl[index].hs_cnt) <= tvin_fmt_tbl[index].hs_cnt_offset) &&
  394. // VGA vs_cnt
  395. (ABS((signed int)adc_timing_info.vs_width - (signed int)tvin_fmt_tbl[index].vs_width) <= TVIN_FMT_CHK_VGA_VS_CNT_WOBBLE)
  396. )
  397. )
  398. {
  399. if (// h_cnt
  400. (ABS((signed int)adc_timing_info.h_cnt- (signed int)tvin_fmt_tbl[index].h_cnt) <= tvin_fmt_tbl[index].h_cnt_offset) &&
  401. // v_cnt
  402. (ABS((signed int)adc_timing_info.v_total- (signed int)tvin_fmt_tbl[index].v_total) <= tvin_fmt_tbl[index].v_cnt_offset)
  403. )
  404. break;
  405. }
  406. }
  407. if (index >= index_max)
  408. index = TVIN_SIG_FMT_NULL;
  409. }
  410. return index;
  411. }
  412. // *****************************************************************************
  413. // Function:set auto phase window
  414. //
  415. // Params: format index
  416. //
  417. // Return: success/error
  418. //
  419. // *****************************************************************************
  420. static void tvafe_adc_set_bd_window(enum tvin_sig_fmt_e fmt)
  421. {
  422. unsigned int tmp = 0;
  423. tmp = tvin_fmt_tbl[fmt].hs_width + tvin_fmt_tbl[fmt].hs_bp - ADC_WINDOW_H_OFFSET;
  424. WRITE_APB_REG_BITS(TVFE_BD_MUXCTRL1, tmp, BD_HSTART_BIT, BD_HSTART_WID);
  425. tmp += tvin_fmt_tbl[fmt].h_active + ADC_WINDOW_H_OFFSET + ADC_WINDOW_H_OFFSET;
  426. WRITE_APB_REG_BITS(TVFE_BD_MUXCTRL1, tmp, BD_HEND_BIT, BD_HEND_WID);
  427. tmp = tvin_fmt_tbl[fmt].vs_width + tvin_fmt_tbl[fmt].vs_bp - ADC_WINDOW_V_OFFSET;
  428. WRITE_APB_REG_BITS(TVFE_BD_MUXCTRL2, tmp, BD_VSTART_BIT, BD_VSTART_WID);
  429. tmp += tvin_fmt_tbl[fmt].v_active + ADC_WINDOW_V_OFFSET + ADC_WINDOW_V_OFFSET;
  430. WRITE_APB_REG_BITS(TVFE_BD_MUXCTRL2, tmp, BD_VEND_BIT, BD_VEND_WID);
  431. }
  432. static void tvafe_adc_set_ap_window(enum tvin_sig_fmt_e fmt, unsigned char idx)
  433. {
  434. unsigned int hh = tvin_fmt_tbl[fmt].h_active / VGA_AUTO_PHASE_H_WIN;
  435. unsigned int vv = tvin_fmt_tbl[fmt].v_active / VGA_AUTO_PHASE_V_WIN;
  436. unsigned int hs = tvin_fmt_tbl[fmt].h_active + (((idx%3) << 1) + 1)*hh;
  437. unsigned int he = hs + hh - 1;
  438. unsigned int vs = tvin_fmt_tbl[fmt].v_active + (((idx/3) << 1) + 1)*vv;
  439. unsigned int ve = vs + vv - 1;
  440. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, hs, AP_HSTART_BIT, AP_HSTART_WID);
  441. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, he, AP_HEND_BIT, AP_HEND_WID );
  442. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL2, vs, AP_VSTART_BIT, AP_VSTART_WID);
  443. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL2, ve, AP_VEND_BIT, AP_VEND_WID );
  444. }
  445. // *****************************************************************************
  446. // Function:set afe clamp function
  447. //
  448. // Params: format index
  449. //
  450. // Return: none
  451. //
  452. // *****************************************************************************
  453. /*
  454. static void tvafe_adc_set_clamp(enum tvin_sig_fmt_e fmt)
  455. {
  456. //set clamp starting edge and duration
  457. tvafe_adc_set_clamp_para(fmt);
  458. //set clamp starting edge and duration
  459. //if (clamp_type <= CLAMP_BOTTOM_REGULATED)
  460. // tvafe_adc_set_clamp_reference(ch, ref_val);
  461. //enable clamp type
  462. //tvafe_adc_clamp_select(ch, clamp_type);
  463. }
  464. */
  465. // *****************************************************************************
  466. // Function:set & get clock
  467. //
  468. // Params: clock value
  469. //
  470. // Return: success/error
  471. //
  472. // *****************************************************************************
  473. static void tvafe_vga_set_clock(unsigned int clock)
  474. {
  475. unsigned int tmp;
  476. tmp = (clock >> 4) & 0x000000FF;
  477. WRITE_APB_REG_BITS(ADC_REG_01, tmp, PLLDIVRATIO_MSB_BIT, PLLDIVRATIO_MSB_WID);
  478. tmp = clock & 0x0000000F;
  479. WRITE_APB_REG_BITS(ADC_REG_02, tmp, PLLDIVRATIO_LSB_BIT, PLLDIVRATIO_LSB_WID);
  480. //reset adc digital pll
  481. tvafe_adc_digital_reset();
  482. return;
  483. }
  484. static unsigned int tvafe_vga_get_clock(void)
  485. {
  486. unsigned int data;
  487. data = READ_APB_REG_BITS(ADC_REG_01, PLLDIVRATIO_MSB_BIT, PLLDIVRATIO_MSB_WID) << 4;
  488. data |= READ_APB_REG_BITS(ADC_REG_02, PLLDIVRATIO_LSB_BIT, PLLDIVRATIO_LSB_WID);
  489. return data;
  490. }
  491. // *****************************************************************************
  492. // Function:set & get phase
  493. //
  494. // Params: phase value
  495. //
  496. // Return: none
  497. //
  498. // *****************************************************************************
  499. static void tvafe_vga_set_phase(unsigned int phase)
  500. {
  501. WRITE_APB_REG_BITS(ADC_REG_56, phase, CLKPHASEADJ_BIT, CLKPHASEADJ_WID);
  502. //reset adc digital pll
  503. tvafe_adc_digital_reset();
  504. return;
  505. }
  506. static unsigned int tvafe_vga_get_phase(void)
  507. {
  508. return READ_APB_REG_BITS(ADC_REG_56, CLKPHASEADJ_BIT, CLKPHASEADJ_WID);
  509. }
  510. // *****************************************************************************
  511. // Function:set & get h position
  512. //
  513. // Params: position value
  514. //
  515. // Return: none
  516. //
  517. // *****************************************************************************
  518. static void tvafe_vga_set_h_pos(unsigned int hs, unsigned int he)
  519. {
  520. WRITE_APB_REG_BITS(TVFE_DEG_H, hs, DEG_HSTART_BIT, DEG_HSTART_WID);
  521. WRITE_APB_REG_BITS(TVFE_DEG_H, he, DEG_HEND_BIT, DEG_HEND_WID );
  522. return;
  523. }
  524. static unsigned int tvafe_vga_get_h_pos(void)
  525. {
  526. return READ_APB_REG_BITS(TVFE_DEG_H, DEG_HSTART_BIT, DEG_HSTART_WID);
  527. }
  528. // *****************************************************************************
  529. // Function:set & get v position
  530. //
  531. // Params: v position value
  532. //
  533. // Return: none
  534. //
  535. // *****************************************************************************
  536. static void tvafe_vga_set_v_pos(unsigned int vs, unsigned int ve, enum tvin_scan_mode_e scan_mode)
  537. {
  538. unsigned int offset = (scan_mode == TVIN_SCAN_MODE_PROGRESSIVE) ? 0 : 1;
  539. WRITE_APB_REG_BITS(TVFE_DEG_VODD, vs, DEG_VSTART_ODD_BIT, DEG_VSTART_ODD_WID );
  540. WRITE_APB_REG_BITS(TVFE_DEG_VODD, ve, DEG_VEND_ODD_BIT, DEG_VEND_ODD_WID );
  541. WRITE_APB_REG_BITS(TVFE_DEG_VEVEN, vs + offset, DEG_VSTART_EVEN_BIT, DEG_VSTART_EVEN_WID);
  542. WRITE_APB_REG_BITS(TVFE_DEG_VEVEN, ve + offset, DEG_VEND_EVEN_BIT, DEG_VEND_EVEN_WID );
  543. }
  544. static unsigned int tvafe_vga_get_v_pos(void)
  545. {
  546. return READ_APB_REG_BITS(TVFE_DEG_VODD, DEG_VSTART_ODD_BIT, DEG_VSTART_ODD_WID);
  547. }
  548. static void tvafe_vga_border_detect_enable(void)
  549. {
  550. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, 1, BD_DET_EN_BIT, BD_DET_EN_WID);
  551. }
  552. static void tvafe_vga_border_detect_disable(void)
  553. {
  554. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, 0, BD_DET_EN_BIT, BD_DET_EN_WID);
  555. }
  556. static void tvafe_vga_auto_phase_enable(void)
  557. {
  558. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, 1, AUTOPHASE_EN_BIT, AUTOPHASE_EN_WID);
  559. }
  560. static void tvafe_vga_auto_phase_disable(void)
  561. {
  562. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, 0, AUTOPHASE_EN_BIT, AUTOPHASE_EN_WID);
  563. }
  564. // *****************************************************************************
  565. // Function: border detect init
  566. //
  567. // Params: format index
  568. //
  569. // Return: success/error
  570. //
  571. // *****************************************************************************
  572. static void tvafe_vga_border_detect_init(enum tvin_sig_fmt_e fmt)
  573. {
  574. //diable border detect
  575. tvafe_vga_border_detect_disable();
  576. // pix_thr = 4 (pix-val > pix_thr => valid pixel)
  577. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL3, 0x100/*0x10*/,
  578. BD_R_TH_BIT, BD_R_TH_WID);
  579. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL5, 0x100/*0x10*/,
  580. BD_G_TH_BIT, BD_G_TH_WID);
  581. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL5, 0x100/*0x10*/,
  582. BD_B_TH_BIT, BD_B_TH_WID);
  583. // pix_val > pix_thr => valid pixel
  584. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, 1,
  585. BD_DET_METHOD_BIT, BD_DET_METHOD_WID);
  586. // line_thr = 1/16 of h_active (valid pixels > line_thr => valid line)
  587. WRITE_APB_REG_BITS(TVFE_BD_MUXCTRL3, (tvin_fmt_tbl[fmt].h_active)>>5/*(tvin_fmt_tbl[fmt].h_active)>>4*/,
  588. BD_VLD_LN_TH_BIT, BD_VLD_LN_TH_WID);
  589. // line_thr enable
  590. WRITE_APB_REG_BITS(TVFE_BD_MUXCTRL3, 1,
  591. BD_VALID_LN_EN_BIT, BD_VALID_LN_EN_WID);
  592. // continuous border detection mode
  593. WRITE_APB_REG_BITS(TVFE_BD_MUXCTRL4, 0,
  594. BD_LIMITED_FLD_RECORD_BIT, BD_LIMITED_FLD_RECORD_WID);
  595. WRITE_APB_REG_BITS(TVFE_BD_MUXCTRL4, 0,
  596. BD_FLD_CD_NUM_BIT, BD_FLD_CD_NUM_WID);
  597. // set a large window
  598. tvafe_adc_set_bd_window(fmt);
  599. //enable border detect
  600. tvafe_vga_border_detect_enable();
  601. }
  602. // *****************************************************************************
  603. // Function: auto phase init
  604. //
  605. // Params: format index
  606. //
  607. // Return: success/error
  608. //
  609. // *****************************************************************************
  610. static void tvafe_vga_auto_phase_init(enum tvin_sig_fmt_e fmt, unsigned char idx)
  611. {
  612. //disable auto phase
  613. tvafe_vga_auto_phase_disable();
  614. // use diff value
  615. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, 1,
  616. AP_DIFF_SEL_BIT, AP_DIFF_SEL_WID);
  617. // use window
  618. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL1, 0,
  619. AP_SPECIFIC_POINT_OUT_BIT, AP_SPECIFIC_POINT_OUT_WID);
  620. // coring_thr = 4 (diff > coring_thr => valid diff)
  621. WRITE_APB_REG_BITS(TVFE_AP_MUXCTRL3, 0x10,
  622. AP_CORING_TH_BIT, AP_CORING_TH_WID);
  623. // set auto phase window
  624. tvafe_adc_set_ap_window(fmt, idx);
  625. //enable auto phase
  626. tvafe_vga_auto_phase_enable();
  627. }
  628. static unsigned int tvafe_vga_get_ap_diff(void)
  629. {
  630. unsigned int sum_r = READ_APB_REG(TVFE_AP_INDICATOR1);
  631. unsigned int sum_g = READ_APB_REG(TVFE_AP_INDICATOR2);
  632. unsigned int sum_b = READ_APB_REG(TVFE_AP_INDICATOR3);
  633. unsigned int sum = 0;
  634. if (sum < sum_r)
  635. sum = sum_r;
  636. if (sum < sum_g)
  637. sum = sum_g;
  638. if (sum < sum_b)
  639. sum = sum_b;
  640. return sum;
  641. }
  642. // *****************************************************************************
  643. // Function:get the result of H border detection
  644. //
  645. // Params: format index
  646. //
  647. // Return: success/error
  648. //
  649. // *****************************************************************************
  650. static void tvafe_vga_get_h_border(void)
  651. {
  652. unsigned int r_left_hcnt = 0, r_right_hcnt = 0;
  653. unsigned int g_left_hcnt = 0, g_right_hcnt = 0;
  654. unsigned int b_left_hcnt = 0, b_right_hcnt = 0;
  655. r_right_hcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR14, BD_R_RIGHT_HCNT_BIT, BD_R_RIGHT_HCNT_WID);
  656. r_left_hcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR14, BD_R_LEFT_HCNT_BIT, BD_R_LEFT_HCNT_WID );
  657. g_right_hcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR16, BD_G_RIGHT_HCNT_BIT, BD_G_RIGHT_HCNT_WID);
  658. g_left_hcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR16, BD_G_LEFT_HCNT_BIT, BD_G_LEFT_HCNT_WID );
  659. b_right_hcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR18, BD_B_RIGHT_HCNT_BIT, BD_B_RIGHT_HCNT_WID);
  660. b_left_hcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR18, BD_B_LEFT_HCNT_BIT, BD_B_LEFT_HCNT_WID );
  661. vga_auto.win.hstart = TVAFE_H_MAX;
  662. if (vga_auto.win.hstart > r_left_hcnt)
  663. vga_auto.win.hstart = r_left_hcnt;
  664. if (vga_auto.win.hstart > g_left_hcnt)
  665. vga_auto.win.hstart = g_left_hcnt;
  666. if (vga_auto.win.hstart > b_left_hcnt)
  667. vga_auto.win.hstart = b_left_hcnt;
  668. vga_auto.win.hend = TVAFE_H_MIN;
  669. if (vga_auto.win.hend < r_right_hcnt)
  670. vga_auto.win.hend = r_right_hcnt;
  671. if (vga_auto.win.hend < g_right_hcnt)
  672. vga_auto.win.hend = g_right_hcnt;
  673. if (vga_auto.win.hend < b_right_hcnt)
  674. vga_auto.win.hend = b_right_hcnt;
  675. }
  676. // *****************************************************************************
  677. // Function:get the result of V border detection
  678. //
  679. // Params: format index
  680. //
  681. // Return: success/error
  682. //
  683. // *****************************************************************************
  684. static void tvafe_vga_get_v_border(void)
  685. {
  686. unsigned int r_top_vcnt = 0, r_bot_vcnt = 0;
  687. unsigned int g_top_vcnt = 0, g_bot_vcnt = 0;
  688. unsigned int b_top_vcnt = 0, b_bot_vcnt = 0;
  689. r_top_vcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR13, BD_R_TOP_VCNT_BIT, BD_R_TOP_VCNT_WID);
  690. r_bot_vcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR13, BD_R_BOT_VCNT_BIT, BD_R_BOT_VCNT_WID);
  691. g_top_vcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR15, BD_G_TOP_VCNT_BIT, BD_G_TOP_VCNT_WID);
  692. g_bot_vcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR15, BD_G_BOT_VCNT_BIT, BD_G_BOT_VCNT_WID);
  693. b_top_vcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR17, BD_B_TOP_VCNT_BIT, BD_B_TOP_VCNT_WID);
  694. b_bot_vcnt = READ_APB_REG_BITS(TVFE_AP_INDICATOR17, BD_B_BOT_VCNT_BIT, BD_B_BOT_VCNT_WID);
  695. vga_auto.win.vstart = TVAFE_V_MAX;
  696. if (vga_auto.win.vstart > r_top_vcnt)
  697. vga_auto.win.vstart = r_top_vcnt;
  698. if (vga_auto.win.vstart > g_top_vcnt)
  699. vga_auto.win.vstart = g_top_vcnt;
  700. if (vga_auto.win.vstart > b_top_vcnt)
  701. vga_auto.win.vstart = b_top_vcnt;
  702. vga_auto.win.vend = TVAFE_V_MIN;
  703. if (vga_auto.win.vend < r_bot_vcnt)
  704. vga_auto.win.vend = r_bot_vcnt;
  705. if (vga_auto.win.vend < g_bot_vcnt)
  706. vga_auto.win.vend = g_bot_vcnt;
  707. if (vga_auto.win.vend < b_bot_vcnt)
  708. vga_auto.win.vend = b_bot_vcnt;
  709. }
  710. void tvafe_vga_vs_cnt(void)
  711. {
  712. if (++vga_auto.vs_cnt > TVAFE_VGA_VS_CNT_MAX)
  713. vga_auto.vs_cnt = TVAFE_VGA_VS_CNT_MAX;
  714. }
  715. // *****************************************************************************
  716. // Function:VGA auto clock handler
  717. //
  718. // Params: none
  719. //
  720. // Return: sucess/error
  721. //
  722. // *****************************************************************************
  723. static void tvafe_vga_auto_clock_adj(unsigned int clk, signed int diff)
  724. {
  725. if (diff > 0)
  726. clk -= (ABS(diff) + 1) >> 1;
  727. if (diff < 0)
  728. clk += (ABS(diff) + 1) >> 1;
  729. tvafe_vga_set_clock(clk);
  730. // disable border detect
  731. tvafe_vga_border_detect_disable();
  732. // enable border detect
  733. //tvafe_vga_border_detect_enable();
  734. }
  735. static void tvafe_vga_auto_clock_handler(struct tvafe_info_s *info)
  736. {
  737. unsigned int clk = 0;
  738. signed int diff = 0;
  739. //signal stable
  740. if (info->param.status != TVIN_SIG_STATUS_STABLE)
  741. {
  742. info->cmd_status = TVAFE_CMD_STATUS_FAILED;
  743. return;
  744. }
  745. switch (vga_auto.clk_state)
  746. {
  747. case VGA_CLK_IDLE:
  748. break;
  749. case VGA_CLK_INIT:
  750. tvafe_vga_set_phase(VGA_ADC_PHASE_MID);
  751. tvafe_vga_border_detect_init(info->param.fmt);
  752. tvafe_vga_set_clock(tvin_fmt_tbl[info->param.fmt].h_total); //set spec clock value
  753. vga_auto.adj_cnt = 0;
  754. vga_auto.adj_dir = 0;
  755. vga_auto.clk_state = VGA_CLK_ROUGH_ADJ;
  756. vga_auto.vs_cnt = 0;
  757. break;
  758. case VGA_CLK_ROUGH_ADJ:
  759. diff = 0;
  760. if (vga_auto.vs_cnt > AUTO_CLK_VS_CNT)
  761. {
  762. // get H border
  763. tvafe_vga_get_h_border();
  764. // get current clk
  765. clk = tvafe_vga_get_clock();
  766. // calculate new clk
  767. clk = (((clk * (unsigned int)tvin_fmt_tbl[info->param.fmt].h_active) << 8) / (vga_auto.win.hend - vga_auto.win.hstart + 1) + 128) >> 8;
  768. // if clk is too far from spec, then return error
  769. if ((clk > (tvin_fmt_tbl[info->param.fmt].h_total + (tvin_fmt_tbl[info->param.fmt].h_total >> MAX_AUTO_CLOCK_ORDER))) ||
  770. (clk < (tvin_fmt_tbl[info->param.fmt].h_total - (tvin_fmt_tbl[info->param.fmt].h_total >> MAX_AUTO_CLOCK_ORDER)))
  771. )
  772. {
  773. vga_auto.clk_state = VGA_CLK_EXCEPTION;
  774. }
  775. else
  776. {
  777. tvafe_vga_auto_clock_adj(clk, diff);
  778. //tvafe_vga_border_detect_disable();
  779. vga_auto.clk_state = VGA_CLK_FINE_ADJ;
  780. }
  781. vga_auto.vs_cnt = 0;
  782. }
  783. break;
  784. case VGA_CLK_FINE_ADJ:
  785. if (++vga_auto.adj_cnt > VGA_AUTO_TRY_COUNTER)
  786. {
  787. vga_auto.clk_state = VGA_CLK_EXCEPTION;
  788. }
  789. else
  790. {
  791. //delay about 4 field for border detection
  792. if (vga_auto.vs_cnt == TVAFE_VGA_BD_EN_DELAY)
  793. {
  794. // disable border detect
  795. tvafe_vga_border_detect_enable();
  796. }
  797. if (vga_auto.vs_cnt > AUTO_CLK_VS_CNT)
  798. {
  799. //vga_auto.vs_cnt = 0;
  800. // get H border
  801. tvafe_vga_get_h_border();
  802. // get diff
  803. diff = (signed int)vga_auto.win.hend - (signed int)vga_auto.win.hstart + (signed int)1 - (signed int)tvin_fmt_tbl[info->param.fmt].h_active;
  804. // get clk
  805. clk = tvafe_vga_get_clock();
  806. if (!diff)
  807. {
  808. vga_auto.clk_state = VGA_CLK_END;
  809. }
  810. if (diff > 0)
  811. {
  812. if (vga_auto.adj_dir == 1)
  813. {
  814. if (clk > tvin_fmt_tbl[info->param.fmt].h_total)
  815. {
  816. tvafe_vga_auto_clock_adj(clk, diff);
  817. }
  818. vga_auto.clk_state = VGA_CLK_END;
  819. }
  820. else
  821. {
  822. tvafe_vga_auto_clock_adj(clk, diff);
  823. vga_auto.adj_dir = -1;
  824. }
  825. }
  826. if (diff < 0)
  827. {
  828. if (vga_auto.adj_dir == -1)
  829. {
  830. if (clk < tvin_fmt_tbl[info->param.fmt].h_total)
  831. {
  832. tvafe_vga_auto_clock_adj(clk, diff);
  833. }
  834. vga_auto.clk_state = VGA_CLK_END;
  835. }
  836. else
  837. {
  838. tvafe_vga_auto_clock_adj(clk, diff);
  839. vga_auto.adj_dir = 1;
  840. }
  841. }
  842. vga_auto.vs_cnt = 0;
  843. }
  844. }
  845. break;
  846. case VGA_CLK_EXCEPTION: //stop auto
  847. // disable border detect
  848. tvafe_vga_border_detect_disable();
  849. info->cmd_status = TVAFE_CMD_STATUS_FAILED;
  850. vga_auto.clk_state = VGA_CLK_IDLE;
  851. break;
  852. case VGA_CLK_END: //start auto phase
  853. // disable border detect
  854. tvafe_vga_border_detect_disable();
  855. vga_auto.phase_state = VGA_PHASE_INIT;
  856. vga_auto.clk_state = VGA_CLK_IDLE;
  857. break;
  858. default:
  859. break;
  860. }
  861. return;
  862. }
  863. // *****************************************************************************
  864. // Function:VGA auto phase handler
  865. //
  866. // Params: none
  867. //
  868. // Return: sucess/error
  869. //
  870. // *****************************************************************************
  871. static void tvafe_vga_auto_phase_handler(struct tvafe_info_s *info)
  872. {
  873. unsigned int sum = 0, hs = 0, he = 0, vs = 0, ve = 0;
  874. //signal stable
  875. if (info->param.status != TVIN_SIG_STATUS_STABLE)
  876. {
  877. info->cmd_status = TVAFE_CMD_STATUS_FAILED;
  878. return;
  879. }
  880. switch (vga_auto.phase_state) {
  881. case VGA_PHASE_IDLE:
  882. break;
  883. case VGA_PHASE_INIT:
  884. vga_auto.adj_cnt = 0;
  885. vga_auto.ap_max_diff = 0;
  886. vga_auto.ap_pha_index = VGA_ADC_PHASE_0;
  887. vga_auto.ap_phamax_index = VGA_ADC_PHASE_0;
  888. vga_auto.ap_win_index = VGA_PHASE_WIN_INDEX_0;
  889. vga_auto.ap_winmax_index = VGA_PHASE_WIN_INDEX_0;
  890. tvafe_vga_set_phase(vga_auto.ap_pha_index);
  891. tvafe_vga_auto_phase_init(info->param.fmt, vga_auto.ap_win_index);
  892. vga_auto.phase_state = VGA_PHASE_SEARCH_WIN;
  893. vga_auto.vs_cnt = 0;
  894. break;
  895. case VGA_PHASE_SEARCH_WIN:
  896. if (++vga_auto.adj_cnt > VGA_AUTO_TRY_COUNTER)
  897. {
  898. vga_auto.phase_state = VGA_PHASE_EXCEPTION;
  899. }
  900. else
  901. {
  902. if (vga_auto.vs_cnt > AUTO_PHASE_VS_CNT)
  903. {
  904. //vga_auto.vs_cnt = 0;
  905. sum = tvafe_vga_get_ap_diff();
  906. if (vga_auto.ap_max_diff < sum)
  907. {
  908. vga_auto.ap_max_diff = sum;
  909. vga_auto.ap_winmax_index = vga_auto.ap_win_index;
  910. }
  911. if (++vga_auto.ap_win_index > VGA_PHASE_WIN_INDEX_MAX)
  912. {
  913. tvafe_adc_set_ap_window(info->param.fmt, vga_auto.ap_winmax_index);
  914. vga_auto.ap_max_diff = 0;
  915. vga_auto.phase_state = VGA_PHASE_ADJ;
  916. }
  917. else
  918. tvafe_adc_set_ap_window(info->param.fmt, vga_auto.ap_win_index);
  919. vga_auto.vs_cnt = 0;
  920. }
  921. }
  922. break;
  923. case VGA_PHASE_ADJ:
  924. if (++vga_auto.adj_cnt > VGA_AUTO_TRY_COUNTER)
  925. {
  926. vga_auto.phase_state = VGA_PHASE_EXCEPTION;
  927. }
  928. else
  929. {
  930. if (vga_auto.vs_cnt > AUTO_PHASE_VS_CNT)
  931. {
  932. vga_auto.vs_cnt = 0;
  933. sum = tvafe_vga_get_ap_diff();
  934. if (vga_auto.ap_max_diff < sum)
  935. {
  936. vga_auto.ap_max_diff = sum;
  937. vga_auto.ap_phamax_index = vga_auto.ap_pha_index;
  938. }
  939. if (++vga_auto.ap_pha_index > VGA_ADC_PHASE_MAX)
  940. {
  941. tvafe_vga_set_phase(vga_auto.ap_phamax_index);
  942. //enable border detect
  943. tvafe_vga_border_detect_enable();
  944. //tvafe_vga_auto_phase_disable();
  945. //tvafe_vga_border_detect_init(info->param.fmt);
  946. vga_auto.phase_state = VGA_PHASE_END;
  947. }
  948. else
  949. tvafe_vga_set_phase(vga_auto.ap_pha_index);
  950. vga_auto.vs_cnt = 0;
  951. }
  952. }
  953. break;
  954. case VGA_PHASE_EXCEPTION: //stop auto
  955. // disable auto phase
  956. tvafe_vga_auto_phase_disable();
  957. info->cmd_status = TVAFE_CMD_STATUS_FAILED;
  958. vga_auto.phase_state = VGA_PHASE_IDLE;
  959. case VGA_PHASE_END: //auto position
  960. if (vga_auto.vs_cnt > AUTO_CLK_VS_CNT)
  961. {
  962. //vga_auto.vs_cnt = 0;
  963. tvafe_vga_get_h_border();
  964. tvafe_vga_get_v_border();
  965. if (((vga_auto.win.hend - vga_auto.win.hstart + 1) >= tvin_fmt_tbl[info->param.fmt].h_active) ||
  966. (vga_auto.win.hend > (tvin_fmt_tbl[info->param.fmt].hs_width + tvin_fmt_tbl[info->param.fmt].hs_bp + tvin_fmt_tbl[info->param.fmt].h_active - 1))
  967. )
  968. {
  969. he = vga_auto.win.hend;
  970. hs = he - tvin_fmt_tbl[info->param.fmt].h_active + 1;
  971. }
  972. else if (vga_auto.win.hstart < (tvin_fmt_tbl[info->param.fmt].hs_width + tvin_fmt_tbl[info->param.fmt].hs_bp))
  973. {
  974. hs = vga_auto.win.hstart;
  975. he = hs + tvin_fmt_tbl[info->param.fmt].h_active - 1;
  976. }
  977. else
  978. {
  979. hs = tvin_fmt_tbl[info->param.fmt].hs_width + tvin_fmt_tbl[info->param.fmt].hs_bp;
  980. he = hs + tvin_fmt_tbl[info->param.fmt].h_active - 1;
  981. }
  982. if (((vga_auto.win.vend - vga_auto.win.vstart + 1) >= tvin_fmt_tbl[info->param.fmt].v_active) ||
  983. (vga_auto.win.vend > (tvin_fmt_tbl[info->param.fmt].vs_width + tvin_fmt_tbl[info->param.fmt].vs_bp + tvin_fmt_tbl[info->param.fmt].v_active - 1))
  984. )
  985. {
  986. ve = vga_auto.win.vend;
  987. vs = ve - tvin_fmt_tbl[info->param.fmt].v_active + 1;
  988. }
  989. else if (vga_auto.win.vstart < (tvin_fmt_tbl[info->param.fmt].vs_width + tvin_fmt_tbl[info->param.fmt].vs_bp))
  990. {
  991. vs = vga_auto.win.vstart;
  992. ve = vs + tvin_fmt_tbl[info->param.fmt].v_active - 1;
  993. }
  994. else
  995. {
  996. vs = tvin_fmt_tbl[info->param.fmt].vs_width + tvin_fmt_tbl[info->param.fmt].vs_bp;
  997. ve = vs + tvin_fmt_tbl[info->param.fmt].v_active - 1;
  998. }
  999. tvafe_vga_set_h_pos(hs, he);
  1000. tvafe_vga_set_v_pos(vs, ve, tvafe_top_get_scan_mode());
  1001. // disable border detect
  1002. tvafe_vga_border_detect_disable();
  1003. // disable auto phase
  1004. tvafe_vga_auto_phase_disable();
  1005. info->cmd_status = TVAFE_CMD_STATUS_SUCCESSFUL;
  1006. vga_auto.phase_state = VGA_PHASE_IDLE;
  1007. vga_auto.vs_cnt = 0;
  1008. }
  1009. break;
  1010. default:
  1011. break;
  1012. }
  1013. return;
  1014. }
  1015. // *****************************************************************************
  1016. // Function:VGA auto adjust enable
  1017. //
  1018. // Params: none
  1019. //
  1020. // Return: sucess/error
  1021. //
  1022. // *****************************************************************************
  1023. int tvafe_vga_auto_adjust_enable(struct tvafe_info_s *info)
  1024. {
  1025. int ret = 0;
  1026. if ((info->src_type == TVAFE_SRC_TYPE_VGA) &&
  1027. (info->param.status == TVIN_SIG_STATUS_STABLE) &&
  1028. (info->cmd_status == TVAFE_CMD_STATUS_IDLE)
  1029. )
  1030. {
  1031. info->cmd_status = TVAFE_CMD_STATUS_PROCESSING;
  1032. vga_auto.clk_state = VGA_CLK_INIT;
  1033. vga_auto.phase_state = VGA_PHASE_IDLE;
  1034. info->vga_auto_flag = 1;
  1035. }
  1036. else
  1037. {
  1038. info->cmd_status = TVAFE_CMD_STATUS_FAILED;
  1039. vga_auto.clk_state = VGA_CLK_IDLE;
  1040. vga_auto.phase_state = VGA_PHASE_IDLE;
  1041. info->vga_auto_flag = 0;
  1042. ret = -EFAULT;
  1043. }
  1044. return ret;
  1045. }
  1046. void tvafe_vga_auto_adjust_disable(struct tvafe_info_s *info)
  1047. {
  1048. if (info->cmd_status == TVAFE_CMD_STATUS_PROCESSING)
  1049. {
  1050. info->cmd_status = TVAFE_CMD_STATUS_TERMINATED;
  1051. vga_auto.clk_state = VGA_CLK_IDLE;
  1052. vga_auto.phase_state = VGA_PHASE_IDLE;
  1053. info->vga_auto_flag = 0;
  1054. }
  1055. }
  1056. // *****************************************************************************
  1057. // Function: VGA auto adjust handler
  1058. //
  1059. // Params: system info
  1060. //
  1061. // Return: success/error
  1062. //
  1063. // *****************************************************************************
  1064. void tvafe_vga_auto_adjust_handler(struct tvafe_info_s *info)
  1065. {
  1066. //auto clock handler
  1067. tvafe_vga_auto_clock_handler(info);
  1068. // auto phase handler after auto clock
  1069. tvafe_vga_auto_phase_handler(info);
  1070. return;
  1071. }
  1072. // *****************************************************************************
  1073. // Function:configure the format setting
  1074. //
  1075. // Params: format index
  1076. //
  1077. // Return: none
  1078. //
  1079. // *****************************************************************************
  1080. void tvafe_adc_clear(unsigned int val, unsigned int clear)
  1081. {
  1082. unsigned int i=0;
  1083. for (i=0; i<ADC_REG_NUM; i++)
  1084. {
  1085. if (clear)
  1086. {
  1087. WRITE_APB_REG((ADC_BASE_ADD+i)<<2, ((i == 0x21) ? val : 0));
  1088. }
  1089. else
  1090. {
  1091. WRITE_APB_REG(ADC_REG_21, val);
  1092. }
  1093. }
  1094. }
  1095. void tvafe_adc_configure(enum tvin_sig_fmt_e fmt)
  1096. {
  1097. int i;
  1098. const unsigned char *buff_t = NULL;
  1099. //set adc clock by standard
  1100. //tvafe_adc_set_clock(fmt);
  1101. //set adc clamp by standard
  1102. //tvafe_adc_set_clamp(fmt);
  1103. //set channel bandwidth
  1104. //tvafe_adc_set_bw_lpf(fmt);
  1105. //load vga reg hardcode
  1106. //tvafe_adc_load_hardcode();
  1107. #if 1
  1108. tvafe_adc_clear(TVAFE_ADC_CONFIGURE_INIT, 1);
  1109. tvafe_adc_clear(TVAFE_ADC_CONFIGURE_NORMAL, 1);
  1110. tvafe_adc_clear(TVAFE_ADC_CONFIGURE_RESET_ON, 1);
  1111. if (fmt < TVIN_SIG_FMT_VGA_MAX) // VGA formats
  1112. {
  1113. buff_t = adc_vga_table[fmt-TVIN_SIG_FMT_NULL-1];
  1114. }
  1115. else if (fmt < TVIN_SIG_FMT_COMP_MAX) // Component formats
  1116. {
  1117. buff_t = adc_component_table[fmt-TVIN_SIG_FMT_VGA_MAX-1];
  1118. }
  1119. else // CVBS formats
  1120. {
  1121. //pr_info("tvafe: tvafe_adc_configure(CVBS)\n");
  1122. buff_t = adc_cvbs_table;
  1123. }
  1124. for (i=0; i<ADC_REG_NUM; i++)
  1125. {
  1126. WRITE_APB_REG((ADC_BASE_ADD+i)<<2, ((i == 0x21) ? TVAFE_ADC_CONFIGURE_RESET_ON : (unsigned int)(buff_t[i])));
  1127. }
  1128. tvafe_adc_clear(TVAFE_ADC_CONFIGURE_NORMAL, 0);
  1129. #if 0
  1130. //debug setting
  1131. // diable other mux on test pins 0~27 & 30
  1132. WRITE_CBUS_REG(PERIPHS_PIN_MUX_0 , READ_CBUS_REG(PERIPHS_PIN_MUX_0 )&0xcff0ffdf);
  1133. WRITE_CBUS_REG(PERIPHS_PIN_MUX_1 , READ_CBUS_REG(PERIPHS_PIN_MUX_1 )&0xfc017fff);
  1134. WRITE_CBUS_REG(PERIPHS_PIN_MUX_2 , READ_CBUS_REG(PERIPHS_PIN_MUX_2 )&0xe001ffff);
  1135. WRITE_CBUS_REG(PERIPHS_PIN_MUX_3 , READ_CBUS_REG(PERIPHS_PIN_MUX_3 )&0xfc000000);
  1136. WRITE_CBUS_REG(PERIPHS_PIN_MUX_4 , READ_CBUS_REG(PERIPHS_PIN_MUX_4 )&0xff8007ff);
  1137. WRITE_CBUS_REG(PERIPHS_PIN_MUX_6 , READ_CBUS_REG(PERIPHS_PIN_MUX_6 )&0xffffffbf);
  1138. WRITE_CBUS_REG(PERIPHS_PIN_MUX_7 , READ_CBUS_REG(PERIPHS_PIN_MUX_7 )&0xff00003f);
  1139. WRITE_CBUS_REG(PERIPHS_PIN_MUX_10, READ_CBUS_REG(PERIPHS_PIN_MUX_10)&0xffffffb3);
  1140. // enable TVFE_TEST mux on test pins 0~27 & 30
  1141. WRITE_CBUS_REG(PERIPHS_PIN_MUX_9 , 0x4fffffff);//
  1142. #endif
  1143. #else
  1144. for (i=0; i<ADC_REG_NUM; i++)
  1145. {
  1146. if (fmt < TVIN_SIG_FMT_VGA_MAX) // VGA formats
  1147. {
  1148. //pr_info("tvafe: tvafe_adc_configure(VGA)\n");
  1149. WRITE_APB_REG((ADC_BASE_ADD+i)<<2, (unsigned int)(adc_vga_table[fmt-TVIN_SIG_FMT_NULL-1][i]));
  1150. }
  1151. else if (fmt < TVIN_SIG_FMT_COMP_MAX) // Component formats
  1152. {
  1153. //pr_info("tvafe: tvafe_adc_configure(COMP)\n");
  1154. WRITE_APB_REG((ADC_BASE_ADD+i)<<2, (unsigned int)(adc_component_table[fmt-TVIN_SIG_FMT_VGA_MAX-1][i]));
  1155. }
  1156. else // CVBS formats
  1157. {
  1158. //pr_info("tvafe: tvafe_adc_configure(CVBS)\n");
  1159. WRITE_APB_REG((ADC_BASE_ADD+i)<<2, (unsigned int)(adc_cvbs_table[i]));
  1160. }
  1161. }
  1162. #endif
  1163. }
  1164. void tvafe_adc_set_param(struct tvafe_vga_parm_s *adc_parm, struct tvafe_info_s *info)
  1165. {
  1166. signed int data = 0;
  1167. unsigned int tmp = 0;
  1168. enum tvin_scan_mode_e scan_mode = tvafe_top_get_scan_mode();
  1169. // clk
  1170. data = tvin_fmt_tbl[info->param.fmt].h_total >> TVAFE_VGA_CLK_TUNE_RANGE_ORDER;
  1171. if (ABS(adc_parm->clk_step) > data)
  1172. {
  1173. adc_parm->clk_step = (adc_parm->clk_step > 0) ? data : (0 - data);
  1174. }
  1175. tmp = (unsigned int)((signed int)tvin_fmt_tbl[info->param.fmt].h_total + adc_parm->clk_step);
  1176. tvafe_vga_set_clock(tmp);
  1177. // phase
  1178. if (adc_parm->phase > VGA_ADC_PHASE_MAX)
  1179. adc_parm->phase = VGA_ADC_PHASE_MAX;
  1180. tmp = adc_parm->phase;
  1181. tvafe_vga_set_phase(tmp);
  1182. // hpos
  1183. data = tvin_fmt_tbl[info->param.fmt].h_active >> TVAFE_VGA_HPOS_TUNE_RANGE_ORDER;
  1184. if (ABS(adc_parm->hpos_step) > data)
  1185. {
  1186. adc_parm->hpos_step = (adc_parm->hpos_step > 0) ? data : (0 - data);
  1187. }
  1188. tmp = (unsigned int)((signed int)tvin_fmt_tbl[info->param.fmt].hs_width + (signed int)tvin_fmt_tbl[info->param.fmt].hs_bp + adc_parm->hpos_step);
  1189. tvafe_vga_set_h_pos(tmp, tmp + tvin_fmt_tbl[info->param.fmt].h_active - 1);
  1190. // vpos
  1191. data = tvin_fmt_tbl[info->param.fmt].v_active >> ((scan_mode == TVIN_SCAN_MODE_PROGRESSIVE) ? TVAFE_VGA_VPOS_TUNE_RANGE_ORDER : TVAFE_VGA_VPOS_TUNE_RANGE_ORDER - 1);
  1192. if (ABS(adc_parm->vpos_step) > data)
  1193. {
  1194. adc_parm->vpos_step = (adc_parm->vpos_step > 0) ? data : (0 - data);
  1195. }
  1196. tmp = (unsigned int)((signed int)tvin_fmt_tbl[info->param.fmt].vs_width + (signed int)tvin_fmt_tbl[info->param.fmt].vs_bp + adc_parm->vpos_step);
  1197. tvafe_vga_set_v_pos(tmp, tmp + tvin_fmt_tbl[info->param.fmt].v_active - 1, scan_mode);
  1198. }
  1199. void tvafe_adc_get_param(struct tvafe_vga_parm_s *adc_parm, struct tvafe_info_s *info)
  1200. {
  1201. //signed int tmp = 0;
  1202. adc_parm->clk_step = (signed int)tvafe_vga_get_clock() - (signed int)tvin_fmt_tbl[info->param.fmt].h_total;
  1203. adc_parm->phase = tvafe_vga_get_phase();
  1204. adc_parm->hpos_step = (signed int)tvin_fmt_tbl[info->param.fmt].hs_width + (signed int)tvin_fmt_tbl[info->param.fmt].hs_bp - (signed int)tvafe_vga_get_h_pos();
  1205. adc_parm->vpos_step = (signed int)tvin_fmt_tbl[info->param.fmt].vs_width + (signed int)tvin_fmt_tbl[info->param.fmt].vs_bp - (signed int)tvafe_vga_get_v_pos();
  1206. }
  1207. /* TOP */ //TVIN_SIG_FMT_VGA_800X600P_60D317
  1208. const static int vga_top_reg_default[][2] = {
  1209. {TVFE_DVSS_MUXCTRL , 0x07000008,} ,// TVFE_DVSS_MUXCTRL
  1210. {TVFE_DVSS_MUXVS_REF , 0x00000000,} ,// TVFE_DVSS_MUXVS_REF
  1211. {TVFE_DVSS_MUXCOAST_V , 0x0200000c,} ,// TVFE_DVSS_MUXCOAST_V
  1212. {TVFE_DVSS_SEP_HVWIDTH , 0x000a0073,} ,// TVFE_DVSS_SEP_HVWIDTH
  1213. {TVFE_DVSS_SEP_HPARA , 0x026b0343,} ,// TVFE_DVSS_SEP_HPARA
  1214. {TVFE_DVSS_SEP_VINTEG , 0x0fff0100,} ,// TVFE_DVSS_SEP_VINTEG
  1215. {TVFE_DVSS_SEP_H_THR , 0x00005002,} ,// TVFE_DVSS_SEP_H_THR
  1216. {TVFE_DVSS_SEP_CTRL , 0x40000008,} ,// TVFE_DVSS_SEP_CTRL
  1217. {TVFE_DVSS_GEN_WIDTH , 0x000a0073,} ,// TVFE_DVSS_GEN_WIDTH
  1218. {TVFE_DVSS_GEN_PRD , 0x020d0359,} ,// TVFE_DVSS_GEN_PRD
  1219. {TVFE_DVSS_GEN_COAST , 0x01cc001c,} ,// TVFE_DVSS_GEN_COAST
  1220. {TVFE_DVSS_NOSIG_PARA , 0x00000009,} ,// TVFE_DVSS_NOSIG_PARA
  1221. {TVFE_DVSS_NOSIG_PLS_TH , 0x05000010,} ,// TVFE_DVSS_NOSIG_PLS_TH
  1222. {TVFE_DVSS_GATE_H , 0x00270016,} ,// TVFE_DVSS_GATE_H
  1223. {TVFE_DVSS_GATE_V , 0x020a0009,} ,// TVFE_DVSS_GATE_V
  1224. {TVFE_DVSS_INDICATOR1 , 0x00000000,} ,// TVFE_DVSS_INDICATOR1
  1225. {TVFE_DVSS_INDICATOR2 , 0x00000000,} ,// TVFE_DVSS_INDICATOR2
  1226. {TVFE_DVSS_MVDET_CTRL1 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL1
  1227. {TVFE_DVSS_MVDET_CTRL2 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL2
  1228. {TVFE_DVSS_MVDET_CTRL3 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL3
  1229. {TVFE_DVSS_MVDET_CTRL4 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL4
  1230. {TVFE_DVSS_MVDET_CTRL5 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL5
  1231. {TVFE_DVSS_MVDET_CTRL6 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL6
  1232. {TVFE_DVSS_MVDET_CTRL7 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL7
  1233. {TVFE_SYNCTOP_SPOL_MUXCTRL , 0x00000009,} ,// TVFE_SYNCTOP_SPOL_MUXCTRL
  1234. {TVFE_SYNCTOP_INDICATOR1_HCNT , 0x00000000,} ,// TVFE_SYNCTOP_INDICATOR1_HCNT
  1235. {TVFE_SYNCTOP_INDICATOR2_VCNT , 0x00000000,} ,// TVFE_SYNCTOP_INDICATOR2_VCNT
  1236. {TVFE_SYNCTOP_INDICATOR3 , 0x00000000,} ,// TVFE_SYNCTOP_INDICATOR3
  1237. {TVFE_SYNCTOP_SFG_MUXCTRL1 , 0x81315107,} ,// TVFE_SYNCTOP_SFG_MUXCTRL1
  1238. {TVFE_SYNCTOP_SFG_MUXCTRL2 , 0x01330000,} ,// TVFE_SYNCTOP_SFG_MUXCTRL2
  1239. {TVFE_SYNCTOP_INDICATOR4 , 0x00000000,} ,// TVFE_SYNCTOP_INDICATOR4
  1240. {TVFE_SYNCTOP_SAM_MUXCTRL , 0x00082001,} ,// TVFE_SYNCTOP_SAM_MUXCTRL
  1241. {TVFE_MISC_WSS1_MUXCTRL1 , 0x00000000,} ,// TVFE_MISC_WSS1_MUXCTRL1
  1242. {TVFE_MISC_WSS1_MUXCTRL2 , 0x00000000,} ,// TVFE_MISC_WSS1_MUXCTRL2
  1243. {TVFE_MISC_WSS2_MUXCTRL1 , 0x00000000,} ,// TVFE_MISC_WSS2_MUXCTRL1
  1244. {TVFE_MISC_WSS2_MUXCTRL2 , 0x00000000,} ,// TVFE_MISC_WSS2_MUXCTRL2
  1245. {TVFE_MISC_WSS1_INDICATOR1 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR1
  1246. {TVFE_MISC_WSS1_INDICATOR2 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR2
  1247. {TVFE_MISC_WSS1_INDICATOR3 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR3
  1248. {TVFE_MISC_WSS1_INDICATOR4 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR4
  1249. {TVFE_MISC_WSS1_INDICATOR5 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR5
  1250. {TVFE_MISC_WSS2_INDICATOR1 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR1
  1251. {TVFE_MISC_WSS2_INDICATOR2 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR2
  1252. {TVFE_MISC_WSS2_INDICATOR3 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR3
  1253. {TVFE_MISC_WSS2_INDICATOR4 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR4
  1254. {TVFE_MISC_WSS2_INDICATOR5 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR5
  1255. {TVFE_AP_MUXCTRL1 , 0x19310010,} ,// TVFE_AP_MUXCTRL1
  1256. {TVFE_AP_MUXCTRL2 , 0x00200010,} ,// TVFE_AP_MUXCTRL2
  1257. {TVFE_AP_MUXCTRL3 , 0x10000030,} ,// TVFE_AP_MUXCTRL3
  1258. {TVFE_AP_MUXCTRL4 , 0x00000000,} ,// TVFE_AP_MUXCTRL4
  1259. {TVFE_AP_MUXCTRL5 , 0x10040000,} ,// TVFE_AP_MUXCTRL5
  1260. {TVFE_AP_INDICATOR1 , 0x00000000,} ,// TVFE_AP_INDICATOR1
  1261. {TVFE_AP_INDICATOR2 , 0x00000000,} ,// TVFE_AP_INDICATOR2
  1262. {TVFE_AP_INDICATOR3 , 0x00000000,} ,// TVFE_AP_INDICATOR3
  1263. {TVFE_AP_INDICATOR4 , 0x00000000,} ,// TVFE_AP_INDICATOR4
  1264. {TVFE_AP_INDICATOR5 , 0x00000000,} ,// TVFE_AP_INDICATOR5
  1265. {TVFE_AP_INDICATOR6 , 0x00000000,} ,// TVFE_AP_INDICATOR6
  1266. {TVFE_AP_INDICATOR7 , 0x00000000,} ,// TVFE_AP_INDICATOR7
  1267. {TVFE_AP_INDICATOR8 , 0x00000000,} ,// TVFE_AP_INDICATOR8
  1268. {TVFE_AP_INDICATOR9 , 0x00000000,} ,// TVFE_AP_INDICATOR9
  1269. {TVFE_AP_INDICATOR10 , 0x00000000,} ,// TVFE_AP_INDICATOR10
  1270. {TVFE_AP_INDICATOR11 , 0x00000000,} ,// TVFE_AP_INDICATOR11
  1271. {TVFE_AP_INDICATOR12 , 0x00000000,} ,// TVFE_AP_INDICATOR12
  1272. {TVFE_AP_INDICATOR13 , 0x00000000,} ,// TVFE_AP_INDICATOR13
  1273. {TVFE_AP_INDICATOR14 , 0x00000000,} ,// TVFE_AP_INDICATOR14
  1274. {TVFE_AP_INDICATOR15 , 0x00000000,} ,// TVFE_AP_INDICATOR15
  1275. {TVFE_AP_INDICATOR16 , 0x00000000,} ,// TVFE_AP_INDICATOR16
  1276. {TVFE_AP_INDICATOR17 , 0x00000000,} ,// TVFE_AP_INDICATOR17
  1277. {TVFE_AP_INDICATOR18 , 0x00000000,} ,// TVFE_AP_INDICATOR18
  1278. {TVFE_AP_INDICATOR19 , 0x00000000,} ,// TVFE_AP_INDICATOR19
  1279. {TVFE_BD_MUXCTRL1 , 0x01320000,} ,// TVFE_BD_MUXCTRL1
  1280. {TVFE_BD_MUXCTRL2 , 0x0020d000,} ,// TVFE_BD_MUXCTRL2
  1281. {TVFE_BD_MUXCTRL3 , 0x00000000,} ,// TVFE_BD_MUXCTRL3
  1282. {TVFE_BD_MUXCTRL4 , 0x00000000,} ,// TVFE_BD_MUXCTRL4
  1283. {TVFE_CLP_MUXCTRL1 , 0x00000000,} ,// TVFE_CLP_MUXCTRL1
  1284. {TVFE_CLP_MUXCTRL2 , 0x00000000,} ,// TVFE_CLP_MUXCTRL2
  1285. {TVFE_CLP_MUXCTRL3 , 0x00000000,} ,// TVFE_CLP_MUXCTRL3
  1286. {TVFE_CLP_MUXCTRL4 , 0x00000000,} ,// TVFE_CLP_MUXCTRL4
  1287. {TVFE_CLP_INDICATOR1 , 0x00000000,} ,// TVFE_CLP_INDICATOR1
  1288. {TVFE_BPG_BACKP_H , 0x00000000,} ,// TVFE_BPG_BACKP_H
  1289. {TVFE_BPG_BACKP_V , 0x00000000,} ,// TVFE_BPG_BACKP_V
  1290. {TVFE_DEG_H , 0x003f80d8,} ,// TVFE_DEG_H
  1291. {TVFE_DEG_VODD , 0x0027301b,} ,// TVFE_DEG_VODD
  1292. {TVFE_DEG_VEVEN , 0x0027301b,} ,// TVFE_DEG_VEVEN
  1293. {TVFE_OGO_OFFSET1 , 0x00000000,} ,// TVFE_OGO_OFFSET1
  1294. {TVFE_OGO_GAIN1 , 0x00000000,} ,// TVFE_OGO_GAIN1
  1295. {TVFE_OGO_GAIN2 , 0x00000000,} ,// TVFE_OGO_GAIN2
  1296. {TVFE_OGO_OFFSET2 , 0x00000000,} ,// TVFE_OGO_OFFSET2
  1297. {TVFE_OGO_OFFSET3 , 0x00000000,} ,// TVFE_OGO_OFFSET3
  1298. {TVFE_VAFE_CTRL , 0x00000001,} ,// TVFE_VAFE_CTRL
  1299. {TVFE_VAFE_STATUS , 0x00000000,} ,// TVFE_VAFE_STATUS
  1300. {TVFE_TOP_CTRL , 0x00008750,} ,// TVFE_TOP_CTRL
  1301. {TVFE_CLAMP_INTF , 0x00000000,} ,// TVFE_CLAMP_INTF
  1302. {TVFE_RST_CTRL , 0x00000000,} ,// TVFE_RST_CTRL
  1303. {TVFE_EXT_VIDEO_AFE_CTRL_MUX1 , 0x00000000,} ,// TVFE_EXT_VIDEO_AFE_CTRL_MUX1
  1304. {TVFE_AAFILTER_CTRL1 , 0x00082222,} ,// TVFE_AAFILTER_CTRL1
  1305. {TVFE_AAFILTER_CTRL2 , 0x252b39c6,} ,// TVFE_AAFILTER_CTRL2
  1306. {TVFE_EDID_CONFIG , 0x01800050,} ,// TVFE_EDID_CONFIG
  1307. {TVFE_EDID_RAM_ADDR , 0x00000100,} ,// TVFE_EDID_RAM_ADDR
  1308. {TVFE_EDID_RAM_WDATA , 0x00000000,} ,// TVFE_EDID_RAM_WDATA
  1309. {TVFE_EDID_RAM_RDATA , 0x00000000,} ,// TVFE_EDID_RAM_RDATA
  1310. {TVFE_APB_ERR_CTRL_MUX1 , 0x00000000,} ,// TVFE_APB_ERR_CTRL_MUX1
  1311. {TVFE_APB_ERR_CTRL_MUX2 , 0x00000000,} ,// TVFE_APB_ERR_CTRL_MUX2
  1312. {TVFE_APB_INDICATOR1 , 0x00000000,} ,// TVFE_APB_INDICATOR1
  1313. {TVFE_APB_INDICATOR2 , 0x00000000,} ,// TVFE_APB_INDICATOR2
  1314. {TVFE_ADC_READBACK_CTRL , 0xa0142003,} ,// TVFE_ADC_READBACK_CTRL
  1315. {TVFE_ADC_READBACK_INDICATOR , 0x00000000,} ,// TVFE_ADC_READBACK_INDICATOR
  1316. {TVFE_INT_CLR , 0x00000000,} ,// TVFE_INT_CLR
  1317. {TVFE_INT_MSKN , 0x00000000,} ,// TVFE_INT_MASKN
  1318. {TVFE_INT_INDICATOR1 , 0x00000000,} ,// TVFE_INT_INDICATOR1
  1319. {TVFE_INT_SET , 0x00000000,} ,// TVFE_INT_SET
  1320. {TVFE_CHIP_VERSION , 0x00000000,} ,// TVFE_CHIP_VERSION
  1321. {0xFFFFFFFF , 0x00000000,} // TVFE_CHIP_VERSION
  1322. }; //TVIN_SIG_FMT_VGA_800X600P_60D317
  1323. void tvafe_set_vga_default(enum tvin_sig_fmt_e fmt)
  1324. {
  1325. unsigned int i = 0;
  1326. /** write top register **/
  1327. while (vga_top_reg_default[i][0] != 0xFFFFFFFF) {
  1328. WRITE_APB_REG(vga_top_reg_default[i][0], vga_top_reg_default[i][1]);
  1329. i++;
  1330. }
  1331. pr_info("tvafe_set_vga_default fmt=%d\n", (int)fmt);
  1332. /** write 7740 register **/
  1333. tvafe_adc_configure(fmt);
  1334. }
  1335. /* TOP */
  1336. ///zhuang wei
  1337. const static int comp_top_reg_default[][2] = {
  1338. {TVFE_DVSS_MUXCTRL , 0x072a1480,} ,// TVFE_DVSS_MUXCTRL //zhuang
  1339. {TVFE_DVSS_MUXVS_REF , 0x00000000,} ,// TVFE_DVSS_MUXVS_REF
  1340. {TVFE_DVSS_MUXCOAST_V , 0x00000000,} ,// TVFE_DVSS_MUXCOAST_V
  1341. {TVFE_DVSS_SEP_HVWIDTH , 0x00000000,} ,// TVFE_DVSS_SEP_HVWIDTH
  1342. {TVFE_DVSS_SEP_HPARA , 0x00000000,} ,// TVFE_DVSS_SEP_HPARA
  1343. {TVFE_DVSS_SEP_VINTEG , 0x00000000,} ,// TVFE_DVSS_SEP_VINTEG
  1344. {TVFE_DVSS_SEP_H_THR , 0x00000000,} ,// TVFE_DVSS_SEP_H_THR
  1345. {TVFE_DVSS_SEP_CTRL , 0x00000000,} ,// TVFE_DVSS_SEP_CTRL
  1346. {TVFE_DVSS_GEN_WIDTH , 0x00000000,} ,// TVFE_DVSS_GEN_WIDTH
  1347. {TVFE_DVSS_GEN_PRD , 0x00000000,} ,// TVFE_DVSS_GEN_PRD
  1348. {TVFE_DVSS_GEN_COAST , 0x00000000,} ,// TVFE_DVSS_GEN_COAST
  1349. {TVFE_DVSS_NOSIG_PARA , 0x00000000,} ,// TVFE_DVSS_NOSIG_PARA
  1350. {TVFE_DVSS_NOSIG_PLS_TH , 0x00000000,} ,// TVFE_DVSS_NOSIG_PLS_TH
  1351. {TVFE_DVSS_GATE_H , 0x00000000,} ,// TVFE_DVSS_GATE_H
  1352. {TVFE_DVSS_GATE_V , 0x00000000,} ,// TVFE_DVSS_GATE_V
  1353. {TVFE_DVSS_INDICATOR1 , 0x00000000,} ,// TVFE_DVSS_INDICATOR1
  1354. {TVFE_DVSS_INDICATOR2 , 0x00000000,} ,// TVFE_DVSS_INDICATOR2
  1355. {TVFE_DVSS_MVDET_CTRL1 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL1
  1356. {TVFE_DVSS_MVDET_CTRL2 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL2
  1357. {TVFE_DVSS_MVDET_CTRL3 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL3
  1358. {TVFE_DVSS_MVDET_CTRL4 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL4
  1359. {TVFE_DVSS_MVDET_CTRL5 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL5
  1360. {TVFE_DVSS_MVDET_CTRL6 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL6
  1361. {TVFE_DVSS_MVDET_CTRL7 , 0x00000000,} ,// TVFE_DVSS_MVDET_CTRL7
  1362. {TVFE_SYNCTOP_SPOL_MUXCTRL , 0x00000009,} ,// TVFE_SYNCTOP_SPOL_MUXCTRL
  1363. {TVFE_SYNCTOP_INDICATOR1_HCNT , 0x00000000,} ,// TVFE_SYNCTOP_INDICATOR1_HCNT
  1364. {TVFE_SYNCTOP_INDICATOR2_VCNT , 0x00000000,} ,// TVFE_SYNCTOP_INDICATOR2_VCNT
  1365. {TVFE_SYNCTOP_INDICATOR3 , 0x00000000,} ,// TVFE_SYNCTOP_INDICATOR3
  1366. {TVFE_SYNCTOP_SFG_MUXCTRL1 , 0x812880d8,} ,// TVFE_SYNCTOP_SFG_MUXCTRL1
  1367. {TVFE_SYNCTOP_SFG_MUXCTRL2 , 0x00334400,} ,// TVFE_SYNCTOP_SFG_MUXCTRL2
  1368. {TVFE_SYNCTOP_INDICATOR4 , 0x00000000,} ,// TVFE_SYNCTOP_INDICATOR4
  1369. {TVFE_SYNCTOP_SAM_MUXCTRL , 0x00082001,} ,// TVFE_SYNCTOP_SAM_MUXCTRL
  1370. {TVFE_MISC_WSS1_MUXCTRL1 , 0x00000000,} ,// TVFE_MISC_WSS1_MUXCTRL1
  1371. {TVFE_MISC_WSS1_MUXCTRL2 , 0x00000000,} ,// TVFE_MISC_WSS1_MUXCTRL2
  1372. {TVFE_MISC_WSS2_MUXCTRL1 , 0x00000000,} ,// TVFE_MISC_WSS2_MUXCTRL1
  1373. {TVFE_MISC_WSS2_MUXCTRL2 , 0x00000000,} ,// TVFE_MISC_WSS2_MUXCTRL2
  1374. {TVFE_MISC_WSS1_INDICATOR1 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR1
  1375. {TVFE_MISC_WSS1_INDICATOR2 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR2
  1376. {TVFE_MISC_WSS1_INDICATOR3 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR3
  1377. {TVFE_MISC_WSS1_INDICATOR4 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR4
  1378. {TVFE_MISC_WSS1_INDICATOR5 , 0x00000000,} ,// TVFE_MISC_WSS1_INDICATOR5
  1379. {TVFE_MISC_WSS2_INDICATOR1 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR1
  1380. {TVFE_MISC_WSS2_INDICATOR2 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR2
  1381. {TVFE_MISC_WSS2_INDICATOR3 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR3
  1382. {TVFE_MISC_WSS2_INDICATOR4 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR4
  1383. {TVFE_MISC_WSS2_INDICATOR5 , 0x00000000,} ,// TVFE_MISC_WSS2_INDICATOR5
  1384. {TVFE_AP_MUXCTRL1 , 0x00000000,} ,// TVFE_AP_MUXCTRL1
  1385. {TVFE_AP_MUXCTRL2 , 0x00000000,} ,// TVFE_AP_MUXCTRL2
  1386. {TVFE_AP_MUXCTRL3 , 0x00000000,} ,// TVFE_AP_MUXCTRL3
  1387. {TVFE_AP_MUXCTRL4 , 0x00000000,} ,// TVFE_AP_MUXCTRL4
  1388. {TVFE_AP_MUXCTRL5 , 0x00000000,} ,// TVFE_AP_MUXCTRL5
  1389. {TVFE_AP_INDICATOR1 , 0x00000000,} ,// TVFE_AP_INDICATOR1
  1390. {TVFE_AP_INDICATOR2 , 0x00000000,} ,// TVFE_AP_INDICATOR2
  1391. {TVFE_AP_INDICATOR3 , 0x00000000,} ,// TVFE_AP_INDICATOR3
  1392. {TVFE_AP_INDICATOR4 , 0x00000000,} ,// TVFE_AP_INDICATOR4
  1393. {TVFE_AP_INDICATOR5 , 0x00000000,} ,// TVFE_AP_INDICATOR5
  1394. {TVFE_AP_INDICATOR6 , 0x00000000,} ,// TVFE_AP_INDICATOR6
  1395. {TVFE_AP_INDICATOR7 , 0x00000000,} ,// TVFE_AP_INDICATOR7
  1396. {TVFE_AP_INDICATOR8 , 0x00000000,} ,// TVFE_AP_INDICATOR8
  1397. {TVFE_AP_INDICATOR9 , 0x00000000,} ,// TVFE_AP_INDICATOR9
  1398. {TVFE_AP_INDICATOR10 , 0x00000000,} ,// TVFE_AP_INDICATOR10
  1399. {TVFE_AP_INDICATOR11 , 0x00000000,} ,// TVFE_AP_INDICATOR11
  1400. {TVFE_AP_INDICATOR12 , 0x00000000,} ,// TVFE_AP_INDICATOR12
  1401. {TVFE_AP_INDICATOR13 , 0x00000000,} ,// TVFE_AP_INDICATOR13
  1402. {TVFE_AP_INDICATOR14 , 0x00000000,} ,// TVFE_AP_INDICATOR14
  1403. {TVFE_AP_INDICATOR15 , 0x00000000,} ,// TVFE_AP_INDICATOR15
  1404. {TVFE_AP_INDICATOR16 , 0x00000000,} ,// TVFE_AP_INDICATOR16
  1405. {TVFE_AP_INDICATOR17 , 0x00000000,} ,// TVFE_AP_INDICATOR17
  1406. {TVFE_AP_INDICATOR18 , 0x00000000,} ,// TVFE_AP_INDICATOR18
  1407. {TVFE_AP_INDICATOR19 , 0x00000000,} ,// TVFE_AP_INDICATOR19
  1408. {TVFE_BD_MUXCTRL1 , 0x00000000,} ,// TVFE_BD_MUXCTRL1
  1409. {TVFE_BD_MUXCTRL2 , 0x00000000,} ,// TVFE_BD_MUXCTRL2
  1410. {TVFE_BD_MUXCTRL3 , 0x00000000,} ,// TVFE_BD_MUXCTRL3
  1411. {TVFE_BD_MUXCTRL4 , 0x00000000,} ,// TVFE_BD_MUXCTRL4
  1412. {TVFE_CLP_MUXCTRL1 , 0x00000000,} ,// TVFE_CLP_MUXCTRL1
  1413. {TVFE_CLP_MUXCTRL2 , 0x00000000,} ,// TVFE_CLP_MUXCTRL2
  1414. {TVFE_CLP_MUXCTRL3 , 0x00000000,} ,// TVFE_CLP_MUXCTRL3
  1415. {TVFE_CLP_MUXCTRL4 , 0x00000000,} ,// TVFE_CLP_MUXCTRL4
  1416. {TVFE_CLP_INDICATOR1 , 0x00000000,} ,// TVFE_CLP_INDICATOR1
  1417. {TVFE_BPG_BACKP_H , 0x00000000,} ,// TVFE_BPG_BACKP_H
  1418. {TVFE_BPG_BACKP_V , 0x00000000,} ,// TVFE_BPG_BACKP_V
  1419. {TVFE_DEG_H , 0x00621121,} ,// TVFE_DEG_H
  1420. {TVFE_DEG_VODD , 0x002e8018,} ,// TVFE_DEG_VODD //zhuang
  1421. {TVFE_DEG_VEVEN , 0x002e8018,} ,// TVFE_DEG_VEVEN //zhuang
  1422. {TVFE_OGO_OFFSET1 , 0x00000000,} ,// TVFE_OGO_OFFSET1
  1423. {TVFE_OGO_GAIN1 , 0x00000000,} ,// TVFE_OGO_GAIN1
  1424. {TVFE_OGO_GAIN2 , 0x00000000,} ,// TVFE_OGO_GAIN2
  1425. {TVFE_OGO_OFFSET2 , 0x00000000,} ,// TVFE_OGO_OFFSET2
  1426. {TVFE_OGO_OFFSET3 , 0x00000000,} ,// TVFE_OGO_OFFSET3
  1427. {TVFE_VAFE_CTRL , 0x00000201,} ,// TVFE_VAFE_CTRL //zhuang
  1428. {TVFE_VAFE_STATUS , 0x00000000,} ,// TVFE_VAFE_STATUS
  1429. {TVFE_TOP_CTRL , 0x00008750,} ,// TVFE_TOP_CTRL
  1430. {TVFE_CLAMP_INTF , 0x00000000,} ,// TVFE_CLAMP_INTF
  1431. {TVFE_RST_CTRL , 0x00000000,} ,// TVFE_RST_CTRL
  1432. {TVFE_EXT_VIDEO_AFE_CTRL_MUX1 , 0x00000000,} ,// TVFE_EXT_VIDEO_AFE_CTRL_MUX1
  1433. {TVFE_AAFILTER_CTRL1 , 0x00082222,} ,// TVFE_AAFILTER_CTRL1
  1434. {TVFE_AAFILTER_CTRL2 , 0x252b39c6,} ,// TVFE_AAFILTER_CTRL2
  1435. {TVFE_EDID_CONFIG , 0x01800050,} ,// TVFE_EDID_CONFIG
  1436. {TVFE_EDID_RAM_ADDR , 0x00000100,} ,// TVFE_EDID_RAM_ADDR
  1437. {TVFE_EDID_RAM_WDATA , 0x00000000,} ,// TVFE_EDID_RAM_WDATA
  1438. {TVFE_EDID_RAM_RDATA , 0x00000000,} ,// TVFE_EDID_RAM_RDATA
  1439. {TVFE_APB_ERR_CTRL_MUX1 , 0x00000000,} ,// TVFE_APB_ERR_CTRL_MUX1
  1440. {TVFE_APB_ERR_CTRL_MUX2 , 0x00000000,} ,// TVFE_APB_ERR_CTRL_MUX2
  1441. {TVFE_APB_INDICATOR1 , 0x00000000,} ,// TVFE_APB_INDICATOR1
  1442. {TVFE_APB_INDICATOR2 , 0x00000000,} ,// TVFE_APB_INDICATOR2
  1443. {TVFE_ADC_READBACK_CTRL , 0x00000000,} ,// TVFE_ADC_READBACK_CTRL
  1444. {TVFE_ADC_READBACK_INDICATOR , 0x00000000,} ,// TVFE_ADC_READBACK_INDICATOR
  1445. {TVFE_INT_CLR , 0x00000000,} ,// TVFE_INT_CLR
  1446. {TVFE_INT_MSKN , 0x00000000,} ,// TVFE_INT_MASKN
  1447. {TVFE_INT_INDICATOR1 , 0x00000000,} ,// TVFE_INT_INDICATOR1
  1448. {TVFE_INT_SET , 0x00000000,} ,// TVFE_INT_SET
  1449. {TVFE_CHIP_VERSION , 0x00000000,} ,// TVFE_CHIP_VERSION
  1450. {0xFFFFFFFF , 0x00000000,}
  1451. };
  1452. /* TVAFE_SIG_FORMAT_576I_50 */
  1453. void tvafe_set_comp_default(enum tvin_sig_fmt_e fmt)
  1454. {
  1455. unsigned int i = 0;
  1456. /** write top register **/
  1457. while (comp_top_reg_default[i][0] != 0xFFFFFFFF) {
  1458. WRITE_APB_REG(comp_top_reg_default[i][0], comp_top_reg_default[i][1]);
  1459. i++;
  1460. }
  1461. pr_info("tvafe_set_comp_default fmt=%d\n", (int)fmt);
  1462. /** write 7740 register **/
  1463. tvafe_adc_configure(fmt);
  1464. #if 0
  1465. for (i=0 ; i < 112; i++)
  1466. {
  1467. //WRITE_APB_REG((TOP_BASE_ADD+i)<<2,(vafe_default[i]));
  1468. pr_info("%x ", READ_APB_REG((ADC_BASE_ADD+i)<<2));
  1469. if ((i%15 == 0)&&(i != 0))
  1470. pr_info("\n");
  1471. };
  1472. pr_info("\n............below for top contrl.................\n");
  1473. for (i=0 ; i <= 0x90; i++)
  1474. {
  1475. //WRITE_APB_REG((TOP_BASE_ADD+i)<<2,(vafe_default[i]));
  1476. pr_info("%x ", READ_APB_REG((TOP_BASE_ADD+i)<<2));
  1477. if ((i%15 == 0)&&(i != 0))
  1478. pr_info("\n");
  1479. };
  1480. #endif
  1481. pr_info("tvafe_set_comp_default END\n");
  1482. }