tvafe_general.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031
  1. /******************************Includes************************************/
  2. #include <linux/errno.h>
  3. #include <mach/am_regs.h>
  4. #include "tvin_global.h"
  5. #include "tvafe.h"
  6. #include "tvafe_regs.h"
  7. #include "tvafe_adc.h"
  8. #include "tvafe_cvd.h"
  9. #include "tvafe_general.h"
  10. /***************************Global Variables**********************************/
  11. enum tvafe_adc_pin_e tvafe_default_cvbs_out;
  12. enum tvafe_state_e tvafe_state;
  13. unsigned int tvafe_state_counter; // used in TVAFE_STATE_NOSIG & TVAFE_STATE_UNSTABLE
  14. unsigned int tvafe_exit_nosig_counter; // used in TVAFE_STATE_NOSIG
  15. unsigned int tvafe_back_nosig_counter; // used in TVAFE_STATE_UNSTABLE
  16. unsigned int tvafe_exit_stable_counter; // used in TVAFE_STATE_STABLE
  17. unsigned int tvafe_back_stable_counter; // used in TVAFE_STATE_UNSTABLE
  18. // *****************************************************************************
  19. // Function:
  20. //
  21. // Params:
  22. //
  23. // Return:
  24. //
  25. // *****************************************************************************
  26. enum tvafe_adc_pin_e tvafe_get_free_pga_pin(struct tvafe_pin_mux_s *pinmux)
  27. {
  28. unsigned int i = 0;
  29. unsigned int flag = 0;
  30. enum tvafe_adc_pin_e ret = TVAFE_ADC_PIN_NULL;
  31. for (i=0; i<TVAFE_SRC_SIG_MAX_NUM; i++)
  32. {
  33. if (pinmux->pin[i] == TVAFE_ADC_PIN_A_PGA_0)
  34. flag |= 0x00000001;
  35. if (pinmux->pin[i] == TVAFE_ADC_PIN_A_PGA_1)
  36. flag |= 0x00000002;
  37. if (pinmux->pin[i] == TVAFE_ADC_PIN_A_PGA_2)
  38. flag |= 0x00000004;
  39. if (pinmux->pin[i] == TVAFE_ADC_PIN_A_PGA_3)
  40. flag |= 0x00000008;
  41. }
  42. if (!(flag&0x00000001))
  43. {
  44. ret = TVAFE_ADC_PIN_A_PGA_0;
  45. }
  46. else if (!(flag&0x00000002))
  47. {
  48. ret = TVAFE_ADC_PIN_A_PGA_1;
  49. }
  50. else if (!(flag&0x00000004))
  51. {
  52. ret = TVAFE_ADC_PIN_A_PGA_2;
  53. }
  54. else if (!(flag&0x00000008))
  55. {
  56. ret = TVAFE_ADC_PIN_A_PGA_3;
  57. }
  58. else // In the worst case, CVBS_OUT links to TV
  59. {
  60. ret = pinmux->pin[CVBS0_Y];
  61. }
  62. return ret;
  63. }
  64. #include <linux/kernel.h>
  65. static inline enum tvafe_adc_ch_e tvafe_pin_adc_muxing(enum tvafe_adc_pin_e pin)
  66. {
  67. enum tvafe_adc_ch_e ret = TVAFE_ADC_CH_NULL;
  68. if ((pin >= TVAFE_ADC_PIN_A_PGA_0) && (pin <= TVAFE_ADC_PIN_A_PGA_3))
  69. {
  70. WRITE_APB_REG_BITS(ADC_REG_06, 1, ENPGA_BIT, ENPGA_WID);
  71. WRITE_APB_REG_BITS(ADC_REG_17, pin-TVAFE_ADC_PIN_A_PGA_0, INMUXA_BIT, INMUXA_WID);
  72. ret = TVAFE_ADC_CH_PGA;
  73. }
  74. else if ((pin >= TVAFE_ADC_PIN_A_0) && (pin <= TVAFE_ADC_PIN_A_3))
  75. {
  76. WRITE_APB_REG_BITS(ADC_REG_06, 0, ENPGA_BIT, ENPGA_WID);
  77. WRITE_APB_REG_BITS(ADC_REG_17, pin-TVAFE_ADC_PIN_A_0, INMUXA_BIT, INMUXA_WID);
  78. ret = TVAFE_ADC_CH_A;
  79. }
  80. else if ((pin >= TVAFE_ADC_PIN_B_0) && (pin <= TVAFE_ADC_PIN_B_4))
  81. {
  82. WRITE_APB_REG_BITS(ADC_REG_17, pin-TVAFE_ADC_PIN_B_0, INMUXB_BIT, INMUXB_WID);
  83. ret = TVAFE_ADC_CH_B;
  84. }
  85. else if ((pin >= TVAFE_ADC_PIN_C_0) && (pin <= TVAFE_ADC_PIN_C_4))
  86. {
  87. WRITE_APB_REG_BITS(ADC_REG_18, pin-TVAFE_ADC_PIN_C_0, INMUXC_BIT, INMUXC_WID);
  88. ret = TVAFE_ADC_CH_C;
  89. }
  90. return ret;
  91. }
  92. /*
  93. 000: abc
  94. 001: acb
  95. 010: bac
  96. 011: bca
  97. 100: cab
  98. 101: cba
  99. */
  100. static inline int tvafe_adc_top_muxing(enum tvafe_adc_ch_e gy,
  101. enum tvafe_adc_ch_e bpb,
  102. enum tvafe_adc_ch_e rpr,
  103. unsigned int s_video_flag)
  104. {
  105. int ret = 0;
  106. switch (gy)
  107. {
  108. case TVAFE_ADC_CH_PGA:
  109. case TVAFE_ADC_CH_A:
  110. switch (bpb)
  111. {
  112. case TVAFE_ADC_CH_B:
  113. // abc => abc
  114. if (s_video_flag || (rpr == TVAFE_ADC_CH_C))
  115. {
  116. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 0, SWT_GY_BCB_RCR_IN_BIT,
  117. SWT_GY_BCB_RCR_IN_WID);
  118. }
  119. else
  120. {
  121. ret = -EFAULT;
  122. }
  123. break;
  124. case TVAFE_ADC_CH_C:
  125. // acb => abc
  126. if (s_video_flag || (rpr == TVAFE_ADC_CH_B))
  127. {
  128. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 1, SWT_GY_BCB_RCR_IN_BIT,
  129. SWT_GY_BCB_RCR_IN_WID);
  130. }
  131. else
  132. {
  133. ret = -EFAULT;
  134. }
  135. break;
  136. default:
  137. ret = -EFAULT;
  138. break;
  139. }
  140. break;
  141. case TVAFE_ADC_CH_B:
  142. switch (bpb)
  143. {
  144. case TVAFE_ADC_CH_PGA:
  145. case TVAFE_ADC_CH_A:
  146. // bac => abc
  147. if (s_video_flag || (rpr == TVAFE_ADC_CH_C))
  148. {
  149. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 2, SWT_GY_BCB_RCR_IN_BIT,
  150. SWT_GY_BCB_RCR_IN_WID);
  151. }
  152. else
  153. {
  154. ret = -EFAULT;
  155. }
  156. break;
  157. case TVAFE_ADC_CH_C:
  158. // bca => abc
  159. if (s_video_flag || (rpr == TVAFE_ADC_CH_PGA)
  160. || (rpr == TVAFE_ADC_CH_A))
  161. {
  162. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 3, SWT_GY_BCB_RCR_IN_BIT,
  163. SWT_GY_BCB_RCR_IN_WID);
  164. }
  165. else
  166. {
  167. ret = -EFAULT;
  168. }
  169. break;
  170. default:
  171. ret = -EFAULT;
  172. break;
  173. }
  174. break;
  175. case TVAFE_ADC_CH_C:
  176. switch (bpb)
  177. {
  178. case TVAFE_ADC_CH_PGA:
  179. case TVAFE_ADC_CH_A:
  180. // cab => abc
  181. if (s_video_flag || (rpr == TVAFE_ADC_CH_B))
  182. {
  183. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 4, SWT_GY_BCB_RCR_IN_BIT,
  184. SWT_GY_BCB_RCR_IN_WID);
  185. }
  186. else
  187. {
  188. ret = -EFAULT;
  189. }
  190. break;
  191. case TVAFE_ADC_CH_B:
  192. // cba => abc
  193. if (s_video_flag || (rpr == TVAFE_ADC_CH_PGA)
  194. || (rpr == TVAFE_ADC_CH_A))
  195. {
  196. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 5, SWT_GY_BCB_RCR_IN_BIT,
  197. SWT_GY_BCB_RCR_IN_WID);
  198. }
  199. else
  200. {
  201. ret = -EFAULT;
  202. }
  203. break;
  204. default:
  205. ret = -EFAULT;
  206. break;
  207. }
  208. break;
  209. default:
  210. ret = -EFAULT;
  211. break;
  212. }
  213. return ret;
  214. }
  215. int tvafe_source_muxing(struct tvafe_info_s *info)
  216. {
  217. int ret = 0;
  218. switch (info->param.port)
  219. {
  220. case TVIN_PORT_CVBS0:
  221. if (tvafe_pin_adc_muxing(info->pinmux->pin[CVBS0_Y]) == TVAFE_ADC_CH_PGA)
  222. {
  223. if (info->pinmux->pin[CVBS0_SOG] >= TVAFE_ADC_PIN_SOG_0)
  224. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[CVBS0_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  225. info->src_type = TVAFE_SRC_TYPE_CVBS;
  226. }
  227. else
  228. {
  229. ret = -EFAULT;
  230. }
  231. break;
  232. case TVIN_PORT_CVBS1:
  233. if (tvafe_pin_adc_muxing(info->pinmux->pin[CVBS1_Y]) == TVAFE_ADC_CH_PGA)
  234. {
  235. if (info->pinmux->pin[CVBS1_SOG] >= TVAFE_ADC_PIN_SOG_0)
  236. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[CVBS1_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  237. info->src_type = TVAFE_SRC_TYPE_CVBS;
  238. }
  239. else
  240. {
  241. ret = -EFAULT;
  242. }
  243. break;
  244. case TVIN_PORT_CVBS2:
  245. if (tvafe_pin_adc_muxing(info->pinmux->pin[CVBS2_Y]) == TVAFE_ADC_CH_PGA)
  246. {
  247. WRITE_APB_REG_BITS(ADC_REG_20, info->pinmux->pin[CVBS2_Y]-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  248. if (info->pinmux->pin[CVBS2_SOG] >= TVAFE_ADC_PIN_SOG_0)
  249. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[CVBS2_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  250. info->src_type = TVAFE_SRC_TYPE_CVBS;
  251. }
  252. else
  253. {
  254. ret = -EFAULT;
  255. }
  256. break;
  257. case TVIN_PORT_CVBS3:
  258. if (tvafe_pin_adc_muxing(info->pinmux->pin[CVBS3_Y]) == TVAFE_ADC_CH_PGA)
  259. {
  260. WRITE_APB_REG_BITS(ADC_REG_20, info->pinmux->pin[CVBS3_Y]-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  261. if (info->pinmux->pin[CVBS3_SOG] >= TVAFE_ADC_PIN_SOG_0)
  262. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[CVBS3_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  263. info->src_type = TVAFE_SRC_TYPE_CVBS;
  264. }
  265. else
  266. {
  267. ret = -EFAULT;
  268. }
  269. break;
  270. case TVIN_PORT_CVBS4:
  271. if (tvafe_pin_adc_muxing(info->pinmux->pin[CVBS4_Y]) == TVAFE_ADC_CH_PGA)
  272. {
  273. WRITE_APB_REG_BITS(ADC_REG_20, info->pinmux->pin[CVBS4_Y]-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  274. if (info->pinmux->pin[CVBS4_SOG] >= TVAFE_ADC_PIN_SOG_0)
  275. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[CVBS5_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  276. info->src_type = TVAFE_SRC_TYPE_CVBS;
  277. }
  278. else
  279. {
  280. ret = -EFAULT;
  281. }
  282. break;
  283. case TVIN_PORT_CVBS5:
  284. if (tvafe_pin_adc_muxing(info->pinmux->pin[CVBS5_Y]) == TVAFE_ADC_CH_PGA)
  285. {
  286. WRITE_APB_REG_BITS(ADC_REG_20, info->pinmux->pin[CVBS5_Y]-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  287. if (info->pinmux->pin[CVBS5_SOG] >= TVAFE_ADC_PIN_SOG_0)
  288. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[CVBS5_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  289. info->src_type = TVAFE_SRC_TYPE_CVBS;
  290. }
  291. else
  292. {
  293. ret = -EFAULT;
  294. }
  295. break;
  296. case TVIN_PORT_CVBS6:
  297. if (tvafe_pin_adc_muxing(info->pinmux->pin[CVBS6_Y]) == TVAFE_ADC_CH_PGA)
  298. {
  299. WRITE_APB_REG_BITS(ADC_REG_20, info->pinmux->pin[CVBS6_Y]-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  300. if (info->pinmux->pin[CVBS6_SOG] >= TVAFE_ADC_PIN_SOG_0)
  301. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[CVBS6_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  302. info->src_type = TVAFE_SRC_TYPE_CVBS;
  303. }
  304. else
  305. {
  306. ret = -EFAULT;
  307. }
  308. break;
  309. case TVIN_PORT_CVBS7:
  310. if (tvafe_pin_adc_muxing(info->pinmux->pin[CVBS7_Y]) == TVAFE_ADC_CH_PGA)
  311. {
  312. WRITE_APB_REG_BITS(ADC_REG_20, info->pinmux->pin[CVBS7_Y]-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  313. if (info->pinmux->pin[CVBS7_SOG] >= TVAFE_ADC_PIN_SOG_0)
  314. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[CVBS7_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  315. info->src_type = TVAFE_SRC_TYPE_CVBS;
  316. }
  317. else
  318. {
  319. ret = -EFAULT;
  320. }
  321. break;
  322. case TVIN_PORT_SVIDEO0:
  323. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO0_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO0_C]), TVAFE_ADC_CH_NULL, 1) == 0)
  324. {
  325. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  326. if (info->pinmux->pin[S_VIDEO0_SOG] >= TVAFE_ADC_PIN_SOG_0)
  327. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[S_VIDEO0_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  328. info->src_type = TVAFE_SRC_TYPE_SVIDEO;
  329. }
  330. else
  331. {
  332. ret = -EFAULT;
  333. }
  334. break;
  335. case TVIN_PORT_SVIDEO1:
  336. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO1_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO1_C]), TVAFE_ADC_CH_NULL, 1) == 0)
  337. {
  338. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  339. if (info->pinmux->pin[S_VIDEO1_SOG] >= TVAFE_ADC_PIN_SOG_0)
  340. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[S_VIDEO1_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  341. info->src_type = TVAFE_SRC_TYPE_SVIDEO;
  342. }
  343. else
  344. {
  345. ret = -EFAULT;
  346. }
  347. break;
  348. case TVIN_PORT_SVIDEO2:
  349. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO2_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO2_C]), TVAFE_ADC_CH_NULL, 1) == 0)
  350. {
  351. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  352. if (info->pinmux->pin[S_VIDEO2_SOG] >= TVAFE_ADC_PIN_SOG_0)
  353. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[S_VIDEO2_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  354. info->src_type = TVAFE_SRC_TYPE_SVIDEO;
  355. }
  356. else
  357. {
  358. ret = -EFAULT;
  359. }
  360. break;
  361. case TVIN_PORT_SVIDEO3:
  362. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO3_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO3_C]), TVAFE_ADC_CH_NULL, 1) == 0)
  363. {
  364. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  365. if (info->pinmux->pin[S_VIDEO3_SOG] >= TVAFE_ADC_PIN_SOG_0)
  366. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[S_VIDEO3_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  367. info->src_type = TVAFE_SRC_TYPE_SVIDEO;
  368. }
  369. else
  370. {
  371. ret = -EFAULT;
  372. }
  373. break;
  374. case TVIN_PORT_SVIDEO4:
  375. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO4_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO4_C]), TVAFE_ADC_CH_NULL, 1) == 0)
  376. {
  377. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  378. if (info->pinmux->pin[S_VIDEO4_SOG] >= TVAFE_ADC_PIN_SOG_0)
  379. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[S_VIDEO4_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  380. info->src_type = TVAFE_SRC_TYPE_SVIDEO;
  381. }
  382. else
  383. {
  384. ret = -EFAULT;
  385. }
  386. break;
  387. case TVIN_PORT_SVIDEO5:
  388. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO5_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO5_C]), TVAFE_ADC_CH_NULL, 1) == 0)
  389. {
  390. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  391. if (info->pinmux->pin[S_VIDEO5_SOG] >= TVAFE_ADC_PIN_SOG_0)
  392. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[S_VIDEO5_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  393. info->src_type = TVAFE_SRC_TYPE_SVIDEO;
  394. }
  395. else
  396. {
  397. ret = -EFAULT;
  398. }
  399. break;
  400. case TVIN_PORT_SVIDEO6:
  401. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO6_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO6_C]), TVAFE_ADC_CH_NULL, 1) == 0)
  402. {
  403. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  404. if (info->pinmux->pin[S_VIDEO6_SOG] >= TVAFE_ADC_PIN_SOG_0)
  405. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[S_VIDEO6_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  406. info->src_type = TVAFE_SRC_TYPE_SVIDEO;
  407. }
  408. else
  409. {
  410. ret = -EFAULT;
  411. }
  412. break;
  413. case TVIN_PORT_SVIDEO7:
  414. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO7_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[S_VIDEO7_C]), TVAFE_ADC_CH_NULL, 1) == 0)
  415. {
  416. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  417. if (info->pinmux->pin[S_VIDEO7_SOG] >= TVAFE_ADC_PIN_SOG_0)
  418. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[S_VIDEO7_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  419. info->src_type = TVAFE_SRC_TYPE_SVIDEO;
  420. }
  421. else
  422. {
  423. ret = -EFAULT;
  424. }
  425. break;
  426. case TVIN_PORT_VGA0:
  427. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[VGA0_G]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA0_B]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA0_R]), 0) == 0)
  428. {
  429. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  430. if (info->pinmux->pin[VGA0_SOG] >= TVAFE_ADC_PIN_SOG_0)
  431. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[VGA0_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  432. WRITE_APB_REG_BITS(ADC_REG_39, 0, INSYNCMUXCTRL_BIT, INSYNCMUXCTRL_WID);
  433. info->src_type = TVAFE_SRC_TYPE_VGA;
  434. }
  435. else
  436. {
  437. ret = -EFAULT;
  438. }
  439. break;
  440. case TVIN_PORT_VGA1:
  441. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[VGA1_G]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA1_B]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA1_R]), 0) == 0)
  442. {
  443. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  444. if (info->pinmux->pin[VGA1_SOG] >= TVAFE_ADC_PIN_SOG_0)
  445. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[VGA1_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  446. WRITE_APB_REG_BITS(ADC_REG_39, 1, INSYNCMUXCTRL_BIT, INSYNCMUXCTRL_WID);
  447. info->src_type = TVAFE_SRC_TYPE_VGA;
  448. }
  449. else
  450. {
  451. ret = -EFAULT;
  452. }
  453. break;
  454. case TVIN_PORT_VGA2:
  455. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[VGA2_G]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA2_B]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA2_R]), 0) == 0)
  456. {
  457. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  458. if (info->pinmux->pin[VGA2_SOG] >= TVAFE_ADC_PIN_SOG_0)
  459. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[VGA2_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  460. info->src_type = TVAFE_SRC_TYPE_VGA;
  461. }
  462. else
  463. {
  464. ret = -EFAULT;
  465. }
  466. break;
  467. case TVIN_PORT_VGA3:
  468. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[VGA3_G]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA3_B]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA3_R]), 0) == 0)
  469. {
  470. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  471. if (info->pinmux->pin[VGA3_SOG] >= TVAFE_ADC_PIN_SOG_0)
  472. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[VGA3_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  473. info->src_type = TVAFE_SRC_TYPE_VGA;
  474. }
  475. else
  476. {
  477. ret = -EFAULT;
  478. }
  479. break;
  480. case TVIN_PORT_VGA4:
  481. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[VGA4_G]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA4_B]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA4_R]), 0) == 0)
  482. {
  483. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  484. if (info->pinmux->pin[VGA4_SOG] >= TVAFE_ADC_PIN_SOG_0)
  485. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[VGA4_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  486. info->src_type = TVAFE_SRC_TYPE_VGA;
  487. }
  488. else
  489. {
  490. ret = -EFAULT;
  491. }
  492. break;
  493. case TVIN_PORT_VGA5:
  494. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[VGA5_G]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA5_B]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA5_R]), 0) == 0)
  495. {
  496. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  497. if (info->pinmux->pin[VGA5_SOG] >= TVAFE_ADC_PIN_SOG_0)
  498. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[VGA5_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  499. info->src_type = TVAFE_SRC_TYPE_VGA;
  500. }
  501. else
  502. {
  503. ret = -EFAULT;
  504. }
  505. break;
  506. case TVIN_PORT_VGA6:
  507. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[VGA6_G]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA6_B]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA6_R]), 0) == 0)
  508. {
  509. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  510. if (info->pinmux->pin[VGA6_SOG] >= TVAFE_ADC_PIN_SOG_0)
  511. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[VGA6_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  512. info->src_type = TVAFE_SRC_TYPE_VGA;
  513. }
  514. else
  515. {
  516. ret = -EFAULT;
  517. }
  518. break;
  519. case TVIN_PORT_VGA7:
  520. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[VGA7_G]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA7_B]), tvafe_pin_adc_muxing(info->pinmux->pin[VGA7_R]), 0) == 0)
  521. {
  522. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  523. if (info->pinmux->pin[VGA7_SOG] >= TVAFE_ADC_PIN_SOG_0)
  524. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[VGA7_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  525. info->src_type = TVAFE_SRC_TYPE_VGA;
  526. }
  527. else
  528. {
  529. ret = -EFAULT;
  530. }
  531. break;
  532. case TVIN_PORT_COMP0:
  533. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[COMP0_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP0_PB]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP0_PR]), 0) == 0)
  534. {
  535. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  536. if (info->pinmux->pin[COMP0_SOG] >= TVAFE_ADC_PIN_SOG_0)
  537. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[COMP0_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  538. info->src_type = TVAFE_SRC_TYPE_COMP;
  539. }
  540. else
  541. {
  542. ret = -EFAULT;
  543. }
  544. break;
  545. case TVIN_PORT_COMP1:
  546. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[COMP1_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP1_PB]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP1_PR]), 0) == 0)
  547. {
  548. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  549. if (info->pinmux->pin[COMP1_SOG] >= TVAFE_ADC_PIN_SOG_0)
  550. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[COMP1_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  551. info->src_type = TVAFE_SRC_TYPE_COMP;
  552. }
  553. else
  554. {
  555. ret = -EFAULT;
  556. }
  557. break;
  558. case TVIN_PORT_COMP2:
  559. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[COMP2_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP2_PB]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP2_PR]), 0) == 0)
  560. {
  561. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  562. if (info->pinmux->pin[COMP2_SOG] >= TVAFE_ADC_PIN_SOG_0)
  563. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[COMP2_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  564. info->src_type = TVAFE_SRC_TYPE_COMP;
  565. }
  566. else
  567. {
  568. ret = -EFAULT;
  569. }
  570. break;
  571. case TVIN_PORT_COMP3:
  572. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[COMP3_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP3_PB]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP3_PR]), 0) == 0)
  573. {
  574. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  575. if (info->pinmux->pin[COMP3_SOG] >= TVAFE_ADC_PIN_SOG_0)
  576. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[COMP3_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  577. info->src_type = TVAFE_SRC_TYPE_COMP;
  578. }
  579. else
  580. {
  581. ret = -EFAULT;
  582. }
  583. break;
  584. case TVIN_PORT_COMP4:
  585. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[COMP4_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP4_PB]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP4_PR]), 0) == 0)
  586. {
  587. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  588. if (info->pinmux->pin[COMP4_SOG] >= TVAFE_ADC_PIN_SOG_0)
  589. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[COMP4_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  590. info->src_type = TVAFE_SRC_TYPE_COMP;
  591. }
  592. else
  593. {
  594. ret = -EFAULT;
  595. }
  596. break;
  597. case TVIN_PORT_COMP5:
  598. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[COMP5_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP5_PB]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP5_PR]), 0) == 0)
  599. {
  600. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  601. if (info->pinmux->pin[COMP5_SOG] >= TVAFE_ADC_PIN_SOG_0)
  602. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[COMP5_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  603. info->src_type = TVAFE_SRC_TYPE_COMP;
  604. }
  605. else
  606. {
  607. ret = -EFAULT;
  608. }
  609. break;
  610. case TVIN_PORT_COMP6:
  611. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[COMP6_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP6_PB]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP6_PR]), 0) == 0)
  612. {
  613. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  614. if (info->pinmux->pin[COMP6_SOG] >= TVAFE_ADC_PIN_SOG_0)
  615. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[COMP6_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  616. info->src_type = TVAFE_SRC_TYPE_COMP;
  617. }
  618. else
  619. {
  620. ret = -EFAULT;
  621. }
  622. break;
  623. case TVIN_PORT_COMP7:
  624. if (tvafe_adc_top_muxing(tvafe_pin_adc_muxing(info->pinmux->pin[COMP7_Y]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP7_PB]), tvafe_pin_adc_muxing(info->pinmux->pin[COMP7_PR]), 0) == 0)
  625. {
  626. WRITE_APB_REG_BITS(ADC_REG_20, tvafe_default_cvbs_out-TVAFE_ADC_PIN_A_PGA_0, INMUXBUF_BIT, INMUXBUF_WID);
  627. if (info->pinmux->pin[COMP7_SOG] >= TVAFE_ADC_PIN_SOG_0)
  628. WRITE_APB_REG_BITS(ADC_REG_24, (info->pinmux->pin[COMP7_SOG] - TVAFE_ADC_PIN_SOG_0), INMUXSOG_BIT, INMUXSOG_WID);
  629. info->src_type = TVAFE_SRC_TYPE_COMP;
  630. }
  631. else
  632. {
  633. ret = -EFAULT;
  634. }
  635. break;
  636. default:
  637. ret = -EFAULT;
  638. break;
  639. }
  640. if (!ret)
  641. info->sig_status_cnt = 0;
  642. return ret;
  643. }
  644. void tvafe_vga_set_edid(struct tvafe_vga_edid_s *edid)
  645. {
  646. unsigned int i = 0;
  647. // diable TCON
  648. WRITE_CBUS_REG_BITS(PERIPHS_PIN_MUX_7, 0, 1, 1);
  649. // diable DVIN
  650. WRITE_CBUS_REG_BITS(PERIPHS_PIN_MUX_6, 0, 27, 1);
  651. // DDC_SDA0
  652. WRITE_CBUS_REG_BITS(PERIPHS_PIN_MUX_6, 1, 13, 1);
  653. // DDC_SCL0
  654. WRITE_CBUS_REG_BITS(PERIPHS_PIN_MUX_6, 1, 12, 1);
  655. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 1, EDID_CLK_EN_BIT,EDID_CLK_EN_WID); // VGA_CLK_EN
  656. // APB Bus accessing mode
  657. WRITE_APB_REG(TVFE_EDID_CONFIG, 0x00000000);
  658. WRITE_APB_REG(TVFE_EDID_RAM_ADDR, 0x00000000);
  659. for (i=0; i<256; i++)
  660. WRITE_APB_REG(TVFE_EDID_RAM_WDATA, (unsigned int)edid->value[i]);
  661. // Slave IIC acessing mode, 8-bit standard IIC protocol
  662. WRITE_APB_REG(TVFE_EDID_CONFIG, 0x01800050);
  663. }
  664. void tvafe_vga_get_edid(struct tvafe_vga_edid_s *edid)
  665. {
  666. unsigned int i = 0;
  667. // diable TCON
  668. WRITE_CBUS_REG_BITS(PERIPHS_PIN_MUX_7, 0, 1, 1);
  669. // diable DVIN
  670. WRITE_CBUS_REG_BITS(PERIPHS_PIN_MUX_6, 0, 27, 1);
  671. // DDC_SDA0
  672. WRITE_CBUS_REG_BITS(PERIPHS_PIN_MUX_6, 1, 13, 1);
  673. // DDC_SCL0
  674. WRITE_CBUS_REG_BITS(PERIPHS_PIN_MUX_6, 1, 12, 1);
  675. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 1, EDID_CLK_EN_BIT,EDID_CLK_EN_WID); // VGA_CLK_EN
  676. // APB Bus accessing mode
  677. WRITE_APB_REG(TVFE_EDID_CONFIG, 0x00000000);
  678. WRITE_APB_REG(TVFE_EDID_RAM_ADDR, 0x00000100);
  679. for (i=0; i<256; i++)
  680. edid->value[i] = (unsigned char)(READ_APB_REG_BITS(TVFE_EDID_RAM_RDATA, EDID_RAM_RDATA_BIT, EDID_RAM_RDATA_WID));
  681. // Slave IIC acessing mode, 8-bit standard IIC protocol
  682. WRITE_APB_REG(TVFE_EDID_CONFIG, 0x01800050);
  683. return;
  684. }
  685. ///////////////////TVFE top control////////////////////
  686. const static unsigned int aafilter_ctl[][2] = {
  687. //TVIN_SIG_FMT_NULL = 0,
  688. {0,0},
  689. //VDIN_SIG_FORMAT_VGA_512X384P_60D147,
  690. {
  691. 0x00082222, // TVFE_AAFILTER_CTRL1
  692. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  693. },
  694. //VDIN_SIG_FORMAT_VGA_560X384P_60D147,
  695. {
  696. 0x00082222, // TVFE_AAFILTER_CTRL1
  697. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  698. },
  699. //VDIN_SIG_FORMAT_VGA_640X200P_59D924,
  700. {
  701. 0x00082222, // TVFE_AAFILTER_CTRL1
  702. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  703. },
  704. //VDIN_SIG_FORMAT_VGA_640X350P_85D080,
  705. {
  706. 0x00082222, // TVFE_AAFILTER_CTRL1
  707. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  708. },
  709. //VDIN_SIG_FORMAT_VGA_640X400P_59D940,
  710. {
  711. 0x00082222, // TVFE_AAFILTER_CTRL1
  712. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  713. },
  714. //VDIN_SIG_FORMAT_VGA_640X400P_85D080,
  715. {
  716. 0x00082222, // TVFE_AAFILTER_CTRL1
  717. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  718. },
  719. //VDIN_SIG_FORMAT_VGA_640X400P_59D638,
  720. {
  721. 0x00082222, // TVFE_AAFILTER_CTRL1
  722. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  723. },
  724. //VDIN_SIG_FORMAT_VGA_640X400P_56D416,
  725. {
  726. 0x00082222, // TVFE_AAFILTER_CTRL1
  727. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  728. },
  729. //VDIN_SIG_FORMAT_VGA_640X480I_29D970,
  730. {
  731. 0x00082222, // TVFE_AAFILTER_CTRL1
  732. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  733. },
  734. //VDIN_SIG_FORMAT_VGA_640X480P_66D619,
  735. {
  736. 0x00082222, // TVFE_AAFILTER_CTRL1
  737. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  738. },
  739. //VDIN_SIG_FORMAT_VGA_640X480P_66D667,
  740. {
  741. 0x00082222, // TVFE_AAFILTER_CTRL1
  742. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  743. },
  744. //VDIN_SIG_FORMAT_VGA_640X480P_59D940,
  745. {
  746. 0x00082222, // TVFE_AAFILTER_CTRL1
  747. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  748. },
  749. //VDIN_SIG_FORMAT_VGA_640X480P_60D000,
  750. {
  751. 0x00082222, // TVFE_AAFILTER_CTRL1
  752. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  753. },
  754. //VDIN_SIG_FORMAT_VGA_640X480P_72D809,
  755. {
  756. 0x00082222, // TVFE_AAFILTER_CTRL1
  757. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  758. },
  759. //VDIN_SIG_FORMAT_VGA_640X480P_75D000_A,
  760. {
  761. 0x00082222, // TVFE_AAFILTER_CTRL1
  762. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  763. },
  764. //VDIN_SIG_FORMAT_VGA_640X480P_85D008,
  765. {
  766. 0x00082222, // TVFE_AAFILTER_CTRL1
  767. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  768. },
  769. //VDIN_SIG_FORMAT_VGA_640X480P_59D638,
  770. {
  771. 0x00082222, // TVFE_AAFILTER_CTRL1
  772. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  773. },
  774. //VDIN_SIG_FORMAT_VGA_640X480P_75D000_B,
  775. {
  776. 0x00082222, // TVFE_AAFILTER_CTRL1
  777. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  778. },
  779. //VDIN_SIG_FORMAT_VGA_640X870P_75D000,
  780. {
  781. 0x00082222, // TVFE_AAFILTER_CTRL1
  782. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  783. },
  784. //VDIN_SIG_FORMAT_VGA_720X350P_70D086,
  785. {
  786. 0x00082222, // TVFE_AAFILTER_CTRL1
  787. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  788. },
  789. //VDIN_SIG_FORMAT_VGA_720X400P_85D039,
  790. {
  791. 0x00082222, // TVFE_AAFILTER_CTRL1
  792. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  793. },
  794. //VDIN_SIG_FORMAT_VGA_720X400P_70D086,
  795. {
  796. 0x00082222, // TVFE_AAFILTER_CTRL1
  797. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  798. },
  799. //VDIN_SIG_FORMAT_VGA_720X400P_87D849,
  800. {
  801. 0x00082222, // TVFE_AAFILTER_CTRL1
  802. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  803. },
  804. //VDIN_SIG_FORMAT_VGA_720X400P_59D940,
  805. {
  806. 0x00082222, // TVFE_AAFILTER_CTRL1
  807. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  808. },
  809. //VDIN_SIG_FORMAT_VGA_720X480P_59D940,
  810. {
  811. 0x00082222, // TVFE_AAFILTER_CTRL1
  812. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  813. },
  814. //VDIN_SIG_FORMAT_VGA_752X484I_29D970,
  815. {
  816. 0x00082222, // TVFE_AAFILTER_CTRL1
  817. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  818. },
  819. //VDIN_SIG_FORMAT_VGA_768X574I_25D000,
  820. {
  821. 0x00082222, // TVFE_AAFILTER_CTRL1
  822. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  823. },
  824. //VDIN_SIG_FORMAT_VGA_800X600P_56D250,
  825. {
  826. 0x00082222, // TVFE_AAFILTER_CTRL1
  827. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  828. },
  829. //VDIN_SIG_FORMAT_VGA_800X600P_60D317,
  830. {
  831. 0x00082222, // TVFE_AAFILTER_CTRL1
  832. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  833. },
  834. //VDIN_SIG_FORMAT_VGA_800X600P_72D188,
  835. {
  836. 0x00082222, // TVFE_AAFILTER_CTRL1
  837. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  838. },
  839. //VDIN_SIG_FORMAT_VGA_800X600P_75D000,
  840. {
  841. 0x00082222, // TVFE_AAFILTER_CTRL1
  842. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  843. },
  844. //VDIN_SIG_FORMAT_VGA_800X600P_85D061,
  845. {
  846. 0x00082222, // TVFE_AAFILTER_CTRL1
  847. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  848. },
  849. //VDIN_SIG_FORMAT_VGA_832X624P_75D087,
  850. {
  851. 0x00082222, // TVFE_AAFILTER_CTRL1
  852. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  853. },
  854. //VDIN_SIG_FORMAT_VGA_848X480P_84D751,
  855. {
  856. 0x00082222, // TVFE_AAFILTER_CTRL1
  857. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  858. },
  859. //VDIN_SIG_FORMAT_VGA_1024X768P_59D278,
  860. {
  861. 0x00082222, // TVFE_AAFILTER_CTRL1
  862. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  863. },
  864. //VDIN_SIG_FORMAT_VGA_1024X768P_74D927,
  865. {
  866. 0x00082222, // TVFE_AAFILTER_CTRL1
  867. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  868. },
  869. //VDIN_SIG_FORMAT_VGA_1024X768I_43D479,
  870. {
  871. 0x00082222, // TVFE_AAFILTER_CTRL1
  872. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  873. },
  874. //VDIN_SIG_FORMAT_VGA_1024X768P_60D004,
  875. {
  876. 0x00082222, // TVFE_AAFILTER_CTRL1
  877. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  878. },
  879. //VDIN_SIG_FORMAT_VGA_1024X768P_70D069,
  880. {
  881. 0x00082222, // TVFE_AAFILTER_CTRL1
  882. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  883. },
  884. //VDIN_SIG_FORMAT_VGA_1024X768P_75D029,
  885. {
  886. 0x00082222, // TVFE_AAFILTER_CTRL1
  887. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  888. },
  889. //VDIN_SIG_FORMAT_VGA_1024X768P_84D997,
  890. {
  891. 0x00082222, // TVFE_AAFILTER_CTRL1
  892. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  893. },
  894. //VDIN_SIG_FORMAT_VGA_1024X768P_60D000,
  895. {
  896. 0x00082222, // TVFE_AAFILTER_CTRL1
  897. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  898. },
  899. //VDIN_SIG_FORMAT_VGA_1024X768P_74D925,
  900. {
  901. 0x00082222, // TVFE_AAFILTER_CTRL1
  902. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  903. },
  904. //VDIN_SIG_FORMAT_VGA_1024X768P_75D020,
  905. {
  906. 0x00082222, // TVFE_AAFILTER_CTRL1
  907. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  908. },
  909. //VDIN_SIG_FORMAT_VGA_1024X768P_70D008,
  910. {
  911. 0x00082222, // TVFE_AAFILTER_CTRL1
  912. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  913. },
  914. //VDIN_SIG_FORMAT_VGA_1024X768P_75D782,
  915. {
  916. 0x00082222, // TVFE_AAFILTER_CTRL1
  917. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  918. },
  919. //VDIN_SIG_FORMAT_VGA_1024X768P_77D069,
  920. {
  921. 0x00082222, // TVFE_AAFILTER_CTRL1
  922. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  923. },
  924. //VDIN_SIG_FORMAT_VGA_1024X768P_71D799,
  925. {
  926. 0x00082222, // TVFE_AAFILTER_CTRL1
  927. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  928. },
  929. //VDIN_SIG_FORMAT_VGA_1024X1024P_60D000,
  930. {
  931. 0x00082222, // TVFE_AAFILTER_CTRL1
  932. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  933. },
  934. //VDIN_SIG_FORMAT_VGA_1053X754I_43D453,
  935. {
  936. 0x00082222, // TVFE_AAFILTER_CTRL1
  937. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  938. },
  939. //VDIN_SIG_FORMAT_VGA_1056X768I_43D470,
  940. {
  941. 0x00082222, // TVFE_AAFILTER_CTRL1
  942. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  943. },
  944. //VDIN_SIG_FORMAT_VGA_1120X750I_40D021,
  945. {
  946. 0x00082222, // TVFE_AAFILTER_CTRL1
  947. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  948. },
  949. //VDIN_SIG_FORMAT_VGA_1152X864P_70D012,
  950. {
  951. 0x00082222, // TVFE_AAFILTER_CTRL1
  952. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  953. },
  954. //VDIN_SIG_FORMAT_VGA_1152X864P_75D000,
  955. {
  956. 0x00082222, // TVFE_AAFILTER_CTRL1
  957. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  958. },
  959. //VDIN_SIG_FORMAT_VGA_1152X864P_84D999,
  960. {
  961. 0x00082222, // TVFE_AAFILTER_CTRL1
  962. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  963. },
  964. //VDIN_SIG_FORMAT_VGA_1152X870P_75D062,
  965. {
  966. 0x00082222, // TVFE_AAFILTER_CTRL1
  967. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  968. },
  969. //VDIN_SIG_FORMAT_VGA_1152X900P_65D950,
  970. {
  971. 0x00082222, // TVFE_AAFILTER_CTRL1
  972. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  973. },
  974. //VDIN_SIG_FORMAT_VGA_1152X900P_66D004,
  975. {
  976. 0x00082222, // TVFE_AAFILTER_CTRL1
  977. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  978. },
  979. //VDIN_SIG_FORMAT_VGA_1152X900P_76D047,
  980. {
  981. 0x00082222, // TVFE_AAFILTER_CTRL1
  982. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  983. },
  984. //VDIN_SIG_FORMAT_VGA_1152X900P_76D149,
  985. {
  986. 0x00082222, // TVFE_AAFILTER_CTRL1
  987. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  988. },
  989. //VDIN_SIG_FORMAT_VGA_1244X842I_30D000,
  990. {
  991. 0x00082222, // TVFE_AAFILTER_CTRL1
  992. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  993. },
  994. //VDIN_SIG_FORMAT_VGA_1280X768P_59D995,
  995. {
  996. 0x00082222, // TVFE_AAFILTER_CTRL1
  997. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  998. },
  999. //VDIN_SIG_FORMAT_VGA_1280X768P_74D893,
  1000. {
  1001. 0x00082222, // TVFE_AAFILTER_CTRL1
  1002. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1003. },
  1004. //VDIN_SIG_FORMAT_VGA_1280X768P_84D837,
  1005. {
  1006. 0x00082222, // TVFE_AAFILTER_CTRL1
  1007. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1008. },
  1009. //VDIN_SIG_FORMAT_VGA_1280X960P_60D000,
  1010. {
  1011. 0x00082222, // TVFE_AAFILTER_CTRL1
  1012. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1013. },
  1014. //VDIN_SIG_FORMAT_VGA_1280X960P_75D000,
  1015. {
  1016. 0x00082222, // TVFE_AAFILTER_CTRL1
  1017. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1018. },
  1019. //VDIN_SIG_FORMAT_VGA_1280X960P_85D002,
  1020. {
  1021. 0x00082222, // TVFE_AAFILTER_CTRL1
  1022. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1023. },
  1024. //VDIN_SIG_FORMAT_VGA_1280X1024I_43D436,
  1025. {
  1026. 0x00082222, // TVFE_AAFILTER_CTRL1
  1027. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1028. },
  1029. //VDIN_SIG_FORMAT_VGA_1280X1024P_60D020,
  1030. {
  1031. 0x00082222, // TVFE_AAFILTER_CTRL1
  1032. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1033. },
  1034. //VDIN_SIG_FORMAT_VGA_1280X1024P_75D025,
  1035. {
  1036. 0x00082222, // TVFE_AAFILTER_CTRL1
  1037. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1038. },
  1039. //VDIN_SIG_FORMAT_VGA_1280X1024P_85D024,
  1040. {
  1041. 0x00082222, // TVFE_AAFILTER_CTRL1
  1042. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1043. },
  1044. //VDIN_SIG_FORMAT_VGA_1280X1024P_59D979,
  1045. {
  1046. 0x00082222, // TVFE_AAFILTER_CTRL1
  1047. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1048. },
  1049. //VDIN_SIG_FORMAT_VGA_1280X1024P_72D005,
  1050. {
  1051. 0x00082222, // TVFE_AAFILTER_CTRL1
  1052. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1053. },
  1054. //VDIN_SIG_FORMAT_VGA_1280X1024P_60D002,
  1055. {
  1056. 0x00082222, // TVFE_AAFILTER_CTRL1
  1057. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1058. },
  1059. //VDIN_SIG_FORMAT_VGA_1280X1024P_67D003,
  1060. {
  1061. 0x00082222, // TVFE_AAFILTER_CTRL1
  1062. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1063. },
  1064. //VDIN_SIG_FORMAT_VGA_1280X1024P_74D112,
  1065. {
  1066. 0x00082222, // TVFE_AAFILTER_CTRL1
  1067. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1068. },
  1069. //VDIN_SIG_FORMAT_VGA_1280X1024P_76D179,
  1070. {
  1071. 0x00082222, // TVFE_AAFILTER_CTRL1
  1072. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1073. },
  1074. //VDIN_SIG_FORMAT_VGA_1280X1024P_66D718,
  1075. {
  1076. 0x00082222, // TVFE_AAFILTER_CTRL1
  1077. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1078. },
  1079. //VDIN_SIG_FORMAT_VGA_1280X1024P_66D677,
  1080. {
  1081. 0x00082222, // TVFE_AAFILTER_CTRL1
  1082. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1083. },
  1084. //VDIN_SIG_FORMAT_VGA_1280X1024P_76D107,
  1085. {
  1086. 0x00082222, // TVFE_AAFILTER_CTRL1
  1087. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1088. },
  1089. //VDIN_SIG_FORMAT_VGA_1280X1024P_59D996,
  1090. {
  1091. 0x00082222, // TVFE_AAFILTER_CTRL1
  1092. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1093. },
  1094. //VDIN_SIG_FORMAT_VGA_1360X768P_59D799,
  1095. {
  1096. 0x00082222, // TVFE_AAFILTER_CTRL1
  1097. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1098. },
  1099. //VDIN_SIG_FORMAT_VGA_1360X1024I_51D476,
  1100. {
  1101. 0x00082222, // TVFE_AAFILTER_CTRL1
  1102. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1103. },
  1104. //VDIN_SIG_FORMAT_VGA_1440X1080P_60D000,
  1105. {
  1106. 0x00082222, // TVFE_AAFILTER_CTRL1
  1107. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1108. },
  1109. //VDIN_SIG_FORMAT_VGA_1600X1200I_48D040,
  1110. {
  1111. 0x00082222, // TVFE_AAFILTER_CTRL1
  1112. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1113. },
  1114. //VDIN_SIG_FORMAT_VGA_1600X1200P_60D000,
  1115. {
  1116. 0x00082222, // TVFE_AAFILTER_CTRL1
  1117. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1118. },
  1119. //VDIN_SIG_FORMAT_VGA_1600X1200P_65D000,
  1120. {
  1121. 0x00082222, // TVFE_AAFILTER_CTRL1
  1122. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1123. },
  1124. //VDIN_SIG_FORMAT_VGA_1600X1200P_70D000,
  1125. {
  1126. 0x00082222, // TVFE_AAFILTER_CTRL1
  1127. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1128. },
  1129. //VDIN_SIG_FORMAT_VGA_1600X1200P_75D000,
  1130. {
  1131. 0x00082222, // TVFE_AAFILTER_CTRL1
  1132. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1133. },
  1134. //VDIN_SIG_FORMAT_VGA_1600X1200P_80D000,
  1135. {
  1136. 0x00082222, // TVFE_AAFILTER_CTRL1
  1137. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1138. },
  1139. //VDIN_SIG_FORMAT_VGA_1600X1200P_85D000,
  1140. {
  1141. 0x00082222, // TVFE_AAFILTER_CTRL1
  1142. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1143. },
  1144. //VDIN_SIG_FORMAT_VGA_1600X1280P_66D931,
  1145. {
  1146. 0x00082222, // TVFE_AAFILTER_CTRL1
  1147. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1148. },
  1149. //VDIN_SIG_FORMAT_VGA_1680X1080P_60D000,
  1150. {
  1151. 0x00082222, // TVFE_AAFILTER_CTRL1
  1152. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1153. },
  1154. //VDIN_SIG_FORMAT_VGA_1792X1344P_60D000,
  1155. {
  1156. 0x00082222, // TVFE_AAFILTER_CTRL1
  1157. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1158. },
  1159. //VDIN_SIG_FORMAT_VGA_1792X1344P_74D997,
  1160. {
  1161. 0x00082222, // TVFE_AAFILTER_CTRL1
  1162. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1163. },
  1164. //VDIN_SIG_FORMAT_VGA_1856X1392P_59D995,
  1165. {
  1166. 0x00082222, // TVFE_AAFILTER_CTRL1
  1167. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1168. },
  1169. //VDIN_SIG_FORMAT_VGA_1856X1392P_75D000,
  1170. {
  1171. 0x00082222, // TVFE_AAFILTER_CTRL1
  1172. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1173. },
  1174. //VDIN_SIG_FORMAT_VGA_1868X1200P_75D000,
  1175. //VDIN_SIG_FORMAT_VGA_1920X1080P_60D000,
  1176. {
  1177. 0x00082222, // TVFE_AAFILTER_CTRL1
  1178. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1179. },
  1180. //VDIN_SIG_FORMAT_VGA_1920X1080P_75D000,
  1181. {
  1182. 0x00082222, // TVFE_AAFILTER_CTRL1
  1183. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1184. },
  1185. //VDIN_SIG_FORMAT_VGA_1920X1080P_85D000,
  1186. {
  1187. 0x00082222, // TVFE_AAFILTER_CTRL1
  1188. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1189. },
  1190. //VDIN_SIG_FORMAT_VGA_1920X1200P_84D932,
  1191. {
  1192. 0x00082222, // TVFE_AAFILTER_CTRL1
  1193. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1194. },
  1195. //VDIN_SIG_FORMAT_VGA_1920X1200P_75D000,
  1196. {
  1197. 0x00082222, // TVFE_AAFILTER_CTRL1
  1198. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1199. },
  1200. //VDIN_SIG_FORMAT_VGA_1920X1200P_85D000,
  1201. {
  1202. 0x00082222, // TVFE_AAFILTER_CTRL1
  1203. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1204. },
  1205. //VDIN_SIG_FORMAT_VGA_1920X1234P_75D000,
  1206. {
  1207. 0x00082222, // TVFE_AAFILTER_CTRL1
  1208. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1209. },
  1210. //VDIN_SIG_FORMAT_VGA_1920X1234P_85D000,
  1211. {
  1212. 0x00082222, // TVFE_AAFILTER_CTRL1
  1213. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1214. },
  1215. //VDIN_SIG_FORMAT_VGA_1920X1440P_60D000,
  1216. {
  1217. 0x00082222, // TVFE_AAFILTER_CTRL1
  1218. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1219. },
  1220. //VDIN_SIG_FORMAT_VGA_1920X1440P_75D000,
  1221. {
  1222. 0x00082222, // TVFE_AAFILTER_CTRL1
  1223. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1224. },
  1225. //VDIN_SIG_FORMAT_VGA_2048X1536P_60D000_A,
  1226. {
  1227. 0x00082222, //
  1228. 0x252b39c6, //
  1229. },
  1230. //VDIN_SIG_FORMAT_VGA_2048X1536P_75D000,
  1231. {0,0},
  1232. //VDIN_SIG_FORMAT_VGA_2048X1536P_60D000_B,
  1233. {0,0},
  1234. //VDIN_SIG_FORMAT_VGA_2048X2048P_60D008,
  1235. {0,0},
  1236. //TVIN_SIG_FMT_VGA_MAX,
  1237. {0,0},
  1238. ///////////////////////////////////////////////////////////////
  1239. //VDIN_SIG_FORMAT_COMPONENT_480P_60D000,
  1240. {
  1241. 0x00082222, // TVFE_AAFILTER_CTRL1
  1242. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1243. },
  1244. //VDIN_SIG_FORMAT_COMPONENT_480I_59D940,
  1245. {
  1246. 0x00082222, // TVFE_AAFILTER_CTRL1
  1247. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1248. },
  1249. //VDIN_SIG_FORMAT_COMPONENT_576P_50D000,
  1250. {
  1251. 0x00082222, // TVFE_AAFILTER_CTRL1
  1252. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1253. },
  1254. //VDIN_SIG_FORMAT_COMPONENT_576I_50D000,
  1255. {
  1256. 0x00082222, // TVFE_AAFILTER_CTRL1
  1257. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1258. },
  1259. //VDIN_SIG_FORMAT_COMPONENT_720P_59D940,
  1260. {
  1261. 0x00082222, // TVFE_AAFILTER_CTRL1
  1262. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1263. },
  1264. //VDIN_SIG_FORMAT_COMPONENT_720P_50D000,
  1265. {
  1266. 0x00082222, // TVFE_AAFILTER_CTRL1
  1267. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1268. },
  1269. //VDIN_SIG_FORMAT_COMPONENT_1080P_23D976,
  1270. {
  1271. 0x00082222, // TVFE_AAFILTER_CTRL1
  1272. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1273. },
  1274. //VDIN_SIG_FORMAT_COMPONENT_1080P_24D000,
  1275. {
  1276. 0x00082222, // TVFE_AAFILTER_CTRL1
  1277. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1278. },
  1279. //VDIN_SIG_FORMAT_COMPONENT_1080P_25D000,
  1280. {
  1281. 0x00082222, // TVFE_AAFILTER_CTRL1
  1282. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1283. },
  1284. //VDIN_SIG_FORMAT_COMPONENT_1080P_30D000,
  1285. {
  1286. 0x00082222, // TVFE_AAFILTER_CTRL1
  1287. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1288. },
  1289. //VDIN_SIG_FORMAT_COMPONENT_1080P_50D000,
  1290. {
  1291. 0x00082222, // TVFE_AAFILTER_CTRL1
  1292. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1293. },
  1294. //VDIN_SIG_FORMAT_COMPONENT_1080P_60D000,
  1295. {
  1296. 0x00082222, // TVFE_AAFILTER_CTRL1
  1297. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1298. },
  1299. //VDIN_SIG_FORMAT_COMPONENT_1080I_29D970,
  1300. {
  1301. 0x00082222, // TVFE_AAFILTER_CTRL1
  1302. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1303. },
  1304. //VDIN_SIG_FORMAT_COMPONENT_1080I_47D952,
  1305. {
  1306. 0x00082222, // TVFE_AAFILTER_CTRL1
  1307. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1308. },
  1309. //VDIN_SIG_FORMAT_COMPONENT_1080I_48D000,
  1310. {
  1311. 0x00082222, // TVFE_AAFILTER_CTRL1
  1312. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1313. },
  1314. //VDIN_SIG_FORMAT_COMPONENT_1080I_50D000_A,
  1315. {
  1316. 0x00082222, // TVFE_AAFILTER_CTRL1
  1317. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1318. },
  1319. //VDIN_SIG_FORMAT_COMPONENT_1080I_50D000_B,
  1320. {
  1321. 0x00082222, // TVFE_AAFILTER_CTRL1
  1322. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1323. },
  1324. //VDIN_SIG_FORMAT_COMPONENT_1080I_50D000_C,
  1325. {
  1326. 0x00082222, // TVFE_AAFILTER_CTRL1
  1327. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1328. },
  1329. //VDIN_SIG_FORMAT_COMPONENT_1080I_60D000,
  1330. {
  1331. 0x00082222, // TVFE_AAFILTER_CTRL1
  1332. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1333. },
  1334. //TVIN_SIG_FMT_COMP_MAX,
  1335. {0,0},
  1336. //VDIN_SIG_FORMAT_CVBS_NTSC_M,
  1337. { 0x00082222, // TVFE_AAFILTER_CTRL1
  1338. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1339. },
  1340. //VDIN_SIG_FORMAT_CVBS_NTSC_443,
  1341. { 0x00082222, // TVFE_AAFILTER_CTRL1
  1342. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1343. },
  1344. //VDIN_SIG_FORMAT_CVBS_PAL_I,
  1345. { 0x00082222, // TVFE_AAFILTER_CTRL1
  1346. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1347. },
  1348. //VDIN_SIG_FORMAT_CVBS_PAL_M,
  1349. { 0x00082222, // TVFE_AAFILTER_CTRL1
  1350. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1351. },
  1352. //VDIN_SIG_FORMAT_CVBS_PAL_60,
  1353. { 0x00082222, // TVFE_AAFILTER_CTRL1
  1354. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1355. },
  1356. //VDIN_SIG_FORMAT_CVBS_PAL_CN,
  1357. { 0x00082222, // TVFE_AAFILTER_CTRL1
  1358. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1359. },
  1360. //VDIN_SIG_FORMAT_CVBS_SECAM,
  1361. { 0x00082222, // TVFE_AAFILTER_CTRL1
  1362. 0x252b39c6, // TVFE_AAFILTER_CTRL2
  1363. },
  1364. //VDIN_SIG_FORMAT_MAX,
  1365. {0,0 }
  1366. };
  1367. // *****************************************************************************
  1368. // Function:set aafilter control
  1369. //
  1370. // Params: format index
  1371. //
  1372. // Return: none
  1373. //
  1374. // *****************************************************************************
  1375. void tvafe_top_set_aafilter_control(enum tvin_sig_fmt_e fmt)
  1376. {
  1377. WRITE_APB_REG(TVFE_AAFILTER_CTRL1, aafilter_ctl[fmt][0]);
  1378. WRITE_APB_REG(TVFE_AAFILTER_CTRL2, aafilter_ctl[fmt][1]);
  1379. return;
  1380. }
  1381. void tvafe_top_set_cpump_para(enum tvin_sig_fmt_e fmt)
  1382. {
  1383. unsigned char clamp_type = 0;
  1384. unsigned int clamping_delay;
  1385. //check top charge pump clamping bit
  1386. clamp_type = READ_APB_REG_BITS(TVFE_CLAMP_INTF, CLAMP_EN_BIT, CLAMP_EN_WID);
  1387. if (clamp_type == 1) {
  1388. clamping_delay = tvin_fmt_tbl[fmt].hs_front + tvin_fmt_tbl[fmt].hs_width
  1389. + tvin_fmt_tbl[fmt].h_active;
  1390. WRITE_APB_REG_BITS(TVFE_CLP_MUXCTRL1, clamping_delay, CLAMPING_DLY_BIT,
  1391. CLAMPING_DLY_WID);
  1392. }
  1393. }
  1394. // *****************************************************************************
  1395. // Function:set bp gate of tvfe top module
  1396. //
  1397. // Params: format index
  1398. //
  1399. // Return: none
  1400. //
  1401. // *****************************************************************************
  1402. void tvafe_top_set_bp_gate(enum tvin_sig_fmt_e fmt)
  1403. {
  1404. unsigned int h_bp_end,h_bp_start;
  1405. unsigned int v_bp_end,v_bp_start;
  1406. h_bp_start = tvin_fmt_tbl[fmt].hs_width + 1;
  1407. WRITE_APB_REG_BITS(TVFE_BPG_BACKP_H, h_bp_start, BACKP_H_ST_BIT, BACKP_H_ST_WID);
  1408. h_bp_end = tvin_fmt_tbl[fmt].h_total
  1409. - tvin_fmt_tbl[fmt].hs_front + 1;
  1410. WRITE_APB_REG_BITS(TVFE_BPG_BACKP_H, h_bp_end, BACKP_H_ED_BIT, BACKP_H_ED_WID);
  1411. v_bp_start = tvin_fmt_tbl[fmt].vs_width + 1;
  1412. WRITE_APB_REG_BITS(TVFE_BPG_BACKP_V, v_bp_start, BACKP_V_ST_BIT, BACKP_V_ST_WID);
  1413. v_bp_end = tvin_fmt_tbl[fmt].v_total
  1414. - tvin_fmt_tbl[fmt].vs_front + 1;
  1415. WRITE_APB_REG_BITS(TVFE_BPG_BACKP_V, v_bp_end, BACKP_V_ED_BIT, BACKP_V_ED_WID);
  1416. return;
  1417. }
  1418. // *****************************************************************************
  1419. // Function:set mvdet control of tvfe module
  1420. //
  1421. // Params: format index
  1422. //
  1423. // Return: none
  1424. //
  1425. // *****************************************************************************
  1426. void tvafe_top_set_mvdet_control(enum tvin_sig_fmt_e fmt)
  1427. {
  1428. unsigned int sd_mvd_reg_15_1b[] = {0, 0, 0, 0, 0, 0, 0,};
  1429. if ((fmt > TVIN_SIG_FMT_COMP_480P_60D000)
  1430. && (fmt < TVIN_SIG_FMT_COMP_576I_50D000)) {
  1431. WRITE_APB_REG(TVFE_DVSS_MVDET_CTRL1, sd_mvd_reg_15_1b[0]);
  1432. WRITE_APB_REG(TVFE_DVSS_MVDET_CTRL2, sd_mvd_reg_15_1b[1]);
  1433. WRITE_APB_REG(TVFE_DVSS_MVDET_CTRL3, sd_mvd_reg_15_1b[2]);
  1434. WRITE_APB_REG(TVFE_DVSS_MVDET_CTRL4, sd_mvd_reg_15_1b[3]);
  1435. WRITE_APB_REG(TVFE_DVSS_MVDET_CTRL5, sd_mvd_reg_15_1b[4]);
  1436. WRITE_APB_REG(TVFE_DVSS_MVDET_CTRL6, sd_mvd_reg_15_1b[5]);
  1437. WRITE_APB_REG(TVFE_DVSS_MVDET_CTRL7, sd_mvd_reg_15_1b[6]);
  1438. }
  1439. return;
  1440. }
  1441. // *****************************************************************************
  1442. // Function:set wss of tvfe top module
  1443. //
  1444. // Params: format index
  1445. //
  1446. // Return: none
  1447. //
  1448. // *****************************************************************************
  1449. void tvafe_top_set_wss_control(enum tvin_sig_fmt_e fmt)
  1450. {
  1451. unsigned int hd_mvd_reg_2a_2d[] = {0, 0, 0, 0};
  1452. if (fmt > TVIN_SIG_FMT_COMP_720P_59D940
  1453. && fmt < TVIN_SIG_FMT_COMP_1080I_60D000) {
  1454. WRITE_APB_REG(TVFE_MISC_WSS1_MUXCTRL1, hd_mvd_reg_2a_2d[0]);
  1455. WRITE_APB_REG(TVFE_MISC_WSS1_MUXCTRL2, hd_mvd_reg_2a_2d[1]);
  1456. WRITE_APB_REG(TVFE_MISC_WSS2_MUXCTRL1, hd_mvd_reg_2a_2d[2]);
  1457. WRITE_APB_REG(TVFE_MISC_WSS2_MUXCTRL2, hd_mvd_reg_2a_2d[3]);
  1458. }
  1459. return;
  1460. }
  1461. // *****************************************************************************
  1462. // Function:set sfg control of tvfe top module
  1463. //
  1464. // Params: format index
  1465. //
  1466. // Return: none
  1467. //
  1468. // *****************************************************************************
  1469. void tvafe_top_set_sfg_mux_control(enum tvin_sig_fmt_e fmt)
  1470. {
  1471. unsigned int tmp;
  1472. tmp = tvin_fmt_tbl[fmt].h_total/4;
  1473. WRITE_APB_REG_BITS(TVFE_SYNCTOP_SFG_MUXCTRL1, tmp, SFG_DET_HSTART_BIT, SFG_DET_HSTART_WID);
  1474. tmp = tvin_fmt_tbl[fmt].h_total*3/4;
  1475. WRITE_APB_REG_BITS(TVFE_SYNCTOP_SFG_MUXCTRL1, tmp, SFG_DET_HEND_BIT, SFG_DET_HEND_WID);
  1476. return;
  1477. }
  1478. enum tvin_scan_mode_e tvafe_top_get_scan_mode(void)
  1479. {
  1480. unsigned int scan_mode;
  1481. scan_mode = READ_APB_REG_BITS(TVFE_SYNCTOP_INDICATOR3,
  1482. SFG_PROGRESSIVE_BIT, SFG_PROGRESSIVE_WID);
  1483. if (scan_mode == 0)
  1484. return TVIN_SCAN_MODE_INTERLACED;
  1485. else
  1486. return TVIN_SCAN_MODE_PROGRESSIVE;
  1487. }
  1488. // *****************************************************************************
  1489. // Function: get & set cal result
  1490. //
  1491. // Params: system info
  1492. //
  1493. // Return: none
  1494. //
  1495. // *****************************************************************************
  1496. void tvafe_set_cal_value(struct tvafe_adc_cal_s *para)
  1497. {
  1498. WRITE_APB_REG_BITS(TVFE_OGO_OFFSET1, 1, OGO_EN_BIT, OGO_EN_WID);
  1499. WRITE_APB_REG_BITS(ADC_REG_07, para->a_analog_gain, ADCGAINA_BIT, ADCGAINA_WID);
  1500. WRITE_APB_REG_BITS(ADC_REG_08, para->b_analog_gain, ADCGAINB_BIT, ADCGAINB_WID);
  1501. WRITE_APB_REG_BITS(ADC_REG_09, para->c_analog_gain, ADCGAINC_BIT, ADCGAINC_WID);
  1502. WRITE_APB_REG_BITS(TVFE_OGO_OFFSET1, para->a_digital_offset1,
  1503. OGO_YG_OFFSET1_BIT, OGO_YG_OFFSET1_WID);
  1504. WRITE_APB_REG_BITS(TVFE_OGO_OFFSET1, para->b_digital_offset1,
  1505. OGO_UB_OFFSET1_BIT, OGO_UB_OFFSET1_WID);
  1506. WRITE_APB_REG_BITS(TVFE_OGO_OFFSET3, para->c_digital_offset1,
  1507. OGO_VR_OFFSET1_BIT, OGO_VR_OFFSET1_WID);
  1508. WRITE_APB_REG_BITS(TVFE_OGO_GAIN1, para->a_digital_gain,
  1509. OGO_YG_GAIN_BIT, OGO_YG_GAIN_WID);
  1510. WRITE_APB_REG_BITS(TVFE_OGO_GAIN1, para->b_digital_gain,
  1511. OGO_UB_GAIN_BIT, OGO_UB_GAIN_WID);
  1512. WRITE_APB_REG_BITS(TVFE_OGO_GAIN2, para->c_digital_gain,
  1513. OGO_VR_GAIN_BIT, OGO_VR_GAIN_WID);
  1514. WRITE_APB_REG_BITS(TVFE_OGO_OFFSET2, para->a_digital_offset2,
  1515. OGO_YG_OFFSET2_BIT, OGO_YG_OFFSET2_WID);
  1516. WRITE_APB_REG_BITS(TVFE_OGO_OFFSET2, para->b_digital_offset2,
  1517. OGO_UB_OFFSET2_BIT, OGO_UB_OFFSET2_WID);
  1518. WRITE_APB_REG_BITS(TVFE_OGO_OFFSET3, para->c_digital_offset2,
  1519. OGO_VR_OFFSET2_BIT, OGO_VR_OFFSET2_WID);
  1520. }
  1521. void tvafe_get_cal_value(struct tvafe_adc_cal_s *para)
  1522. {
  1523. para->a_analog_gain = READ_APB_REG_BITS(ADC_REG_07, ADCGAINA_BIT, ADCGAINA_WID);
  1524. para->b_analog_gain = READ_APB_REG_BITS(ADC_REG_08, ADCGAINB_BIT, ADCGAINB_WID);
  1525. para->c_analog_gain = READ_APB_REG_BITS(ADC_REG_09, ADCGAINC_BIT, ADCGAINC_WID);
  1526. para->a_digital_offset1 = READ_APB_REG_BITS(TVFE_OGO_OFFSET1, OGO_YG_OFFSET1_BIT, OGO_YG_OFFSET1_WID);
  1527. para->b_digital_offset1 = READ_APB_REG_BITS(TVFE_OGO_OFFSET1, OGO_UB_OFFSET1_BIT, OGO_UB_OFFSET1_WID);
  1528. para->c_digital_offset1 = READ_APB_REG_BITS(TVFE_OGO_OFFSET3, OGO_VR_OFFSET1_BIT, OGO_VR_OFFSET1_WID);
  1529. para->a_digital_gain = READ_APB_REG_BITS(TVFE_OGO_GAIN1, OGO_YG_GAIN_BIT, OGO_YG_GAIN_WID);
  1530. para->b_digital_gain = READ_APB_REG_BITS(TVFE_OGO_GAIN1, OGO_UB_GAIN_BIT, OGO_UB_GAIN_WID);
  1531. para->c_digital_gain = READ_APB_REG_BITS(TVFE_OGO_GAIN2, OGO_VR_GAIN_BIT, OGO_VR_GAIN_WID);
  1532. para->a_digital_offset2 = READ_APB_REG_BITS(TVFE_OGO_OFFSET2, OGO_YG_OFFSET2_BIT, OGO_YG_OFFSET2_WID);
  1533. para->b_digital_offset2 = READ_APB_REG_BITS(TVFE_OGO_OFFSET2, OGO_UB_OFFSET2_BIT, OGO_UB_OFFSET2_WID);
  1534. para->c_digital_offset2 = READ_APB_REG_BITS(TVFE_OGO_OFFSET3, OGO_VR_OFFSET2_BIT, OGO_VR_OFFSET2_WID);
  1535. }
  1536. // *****************************************************************************
  1537. // Function: fetch WSS data
  1538. //
  1539. // Params: system info
  1540. //
  1541. // Return: none
  1542. //
  1543. // *****************************************************************************
  1544. void tvafe_get_wss_data(struct tvafe_comp_wss_s *para)
  1545. {
  1546. para->wss1[0] = READ_APB_REG(TVFE_MISC_WSS1_INDICATOR1);
  1547. para->wss1[1] = READ_APB_REG(TVFE_MISC_WSS1_INDICATOR2);
  1548. para->wss1[2] = READ_APB_REG(TVFE_MISC_WSS1_INDICATOR3);
  1549. para->wss1[3] = READ_APB_REG(TVFE_MISC_WSS1_INDICATOR4);
  1550. para->wss1[4] = READ_APB_REG_BITS(TVFE_MISC_WSS1_INDICATOR5, WSS1_DATA_143_128_BIT, WSS1_DATA_143_128_WID);
  1551. para->wss2[0] = READ_APB_REG(TVFE_MISC_WSS2_INDICATOR1);
  1552. para->wss2[1] = READ_APB_REG(TVFE_MISC_WSS2_INDICATOR2);
  1553. para->wss2[2] = READ_APB_REG(TVFE_MISC_WSS2_INDICATOR3);
  1554. para->wss2[3] = READ_APB_REG(TVFE_MISC_WSS2_INDICATOR4);
  1555. para->wss2[4] = READ_APB_REG_BITS(TVFE_MISC_WSS2_INDICATOR5, WSS2_DATA_143_128_BIT, WSS2_DATA_143_128_WID);
  1556. }
  1557. // *****************************************************************************
  1558. // Function: set hardcode of tvfe top module
  1559. //
  1560. // Params: none
  1561. //
  1562. // Return: none
  1563. //
  1564. // *****************************************************************************
  1565. void tvafe_check_cvbs_3d_comb(void)
  1566. {
  1567. #if 0
  1568. unsigned int interrupt_status = READ_APB_REG(TVFE_INT_INDICATOR1);
  1569. if ((interrupt_status>>WARNING_3D_BIT) & 0x01) {
  1570. WRITE_APB_REG_BITS(TVFE_INT_INDICATOR1, 0, WARNING_3D_BIT, WARNING_3D_WID);
  1571. WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 1, SOFT_RST_BIT, SOFT_RST_WID);
  1572. WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 0, SOFT_RST_BIT, SOFT_RST_WID);
  1573. }
  1574. #else
  1575. unsigned int cvd2_3d_status = READ_APB_REG(CVD2_REG_95);
  1576. if(cvd2_3d_status & 0x1ffff) {
  1577. //pr_info("%s: cvd2_3d_status = %x \n",__FUNCTION__, cvd2_3d_status);
  1578. WRITE_APB_REG_BITS(CVD2_REG_B2, 1, COMB2D_ONLY_BIT, COMB2D_ONLY_WID);
  1579. WRITE_APB_REG_BITS(CVD2_REG_B2, 0, COMB2D_ONLY_BIT, COMB2D_ONLY_WID);
  1580. }
  1581. #endif
  1582. }
  1583. void tvafe_top_set_de(enum tvin_sig_fmt_e fmt)
  1584. {
  1585. unsigned int hs = 0, he = 0, vs = 0, ve = 0;
  1586. hs = tvin_fmt_tbl[fmt].hs_width + tvin_fmt_tbl[fmt].hs_bp;
  1587. vs = tvin_fmt_tbl[fmt].vs_width + tvin_fmt_tbl[fmt].vs_bp;
  1588. he = hs + tvin_fmt_tbl[fmt].h_active - 1;
  1589. ve = vs + tvin_fmt_tbl[fmt].v_active - 1;
  1590. WRITE_APB_REG_BITS(TVFE_DEG_H, hs,
  1591. DEG_HSTART_BIT, DEG_HSTART_WID);
  1592. WRITE_APB_REG_BITS(TVFE_DEG_H, he,
  1593. DEG_HEND_BIT, DEG_HEND_WID);
  1594. WRITE_APB_REG_BITS(TVFE_DEG_VODD, vs,
  1595. DEG_VSTART_ODD_BIT, DEG_VSTART_ODD_WID);
  1596. WRITE_APB_REG_BITS(TVFE_DEG_VODD, ve,
  1597. DEG_VEND_ODD_BIT, DEG_VEND_ODD_WID);
  1598. WRITE_APB_REG_BITS(TVFE_DEG_VEVEN, vs + 1,
  1599. DEG_VSTART_EVEN_BIT, DEG_VSTART_EVEN_WID);
  1600. WRITE_APB_REG_BITS(TVFE_DEG_VEVEN, ve + 1,
  1601. DEG_VEND_EVEN_BIT, DEG_VEND_EVEN_WID);
  1602. }
  1603. void tvafe_top_set_field_gen(enum tvin_sig_fmt_e fmt)
  1604. {
  1605. unsigned int hs = 0, he = 0, vs = 0, ve = 0;
  1606. hs = tvin_fmt_tbl[fmt].hs_width + tvin_fmt_tbl[fmt].hs_bp;
  1607. vs = tvin_fmt_tbl[fmt].vs_width + tvin_fmt_tbl[fmt].vs_bp;
  1608. he = hs + tvin_fmt_tbl[fmt].h_active - 1;
  1609. ve = vs + tvin_fmt_tbl[fmt].v_active - 1;
  1610. WRITE_APB_REG_BITS(TVFE_SYNCTOP_SFG_MUXCTRL1, hs,
  1611. DEG_HSTART_BIT, DEG_HSTART_WID);
  1612. WRITE_APB_REG_BITS(TVFE_SYNCTOP_SFG_MUXCTRL1, he,
  1613. DEG_HEND_BIT, DEG_HEND_WID);
  1614. WRITE_APB_REG_BITS(TVFE_SYNCTOP_SFG_MUXCTRL1, vs,
  1615. DEG_VSTART_ODD_BIT, DEG_VSTART_ODD_WID);
  1616. WRITE_APB_REG_BITS(TVFE_SYNCTOP_SFG_MUXCTRL1, ve,
  1617. DEG_VEND_ODD_BIT, DEG_VEND_ODD_WID);
  1618. WRITE_APB_REG_BITS(TVFE_SYNCTOP_SFG_MUXCTRL1, vs + 1,
  1619. DEG_VSTART_EVEN_BIT, DEG_VSTART_EVEN_WID);
  1620. WRITE_APB_REG_BITS(TVFE_SYNCTOP_SFG_MUXCTRL1, ve + 1,
  1621. DEG_VEND_EVEN_BIT, DEG_VEND_EVEN_WID);
  1622. }
  1623. static void tvafe_top_config(enum tvin_sig_fmt_e fmt)
  1624. {
  1625. //tvafe_top_set_aafilter_control(fmt);
  1626. //tvafe_top_set_bp_gate(fmt);
  1627. //tvafe_top_set_mvdet_control(fmt);
  1628. //tvafe_top_set_sfg_mux_control(fmt);
  1629. tvafe_top_set_wss_control(fmt);
  1630. tvafe_top_set_de(fmt);
  1631. }
  1632. static void tvafe_stop_vga(void)
  1633. {
  1634. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 0, COMP_CLK_ENABLE_BIT, COMP_CLK_ENABLE_WID);
  1635. //WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 0, EDID_CLK_EN_BIT, EDID_CLK_EN_WID);
  1636. //WRITE_CBUS_REG_BITS(HHI_TVFE_AUTOMODE_CLK_CNTL, 0, 7, 1); //?
  1637. //...
  1638. }
  1639. #include <linux/kernel.h>
  1640. static void tvafe_reset_vga(void)
  1641. {
  1642. // pr_info("tvafe: tvafe_reset_vga.CVD2_RESET_REGISTER %x 1\n", CVD2_RESET_REGISTER);
  1643. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 0, SOFT_RST_BIT, SOFT_RST_WID);
  1644. //pr_info("tvafe: tvafe_reset_vga. 2\n");
  1645. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 1, SOFT_RST_BIT, SOFT_RST_WID); //SOFT RESET memory
  1646. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 0, SOFT_RST_BIT, SOFT_RST_WID);
  1647. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 1, COMP_CLK_ENABLE_BIT, COMP_CLK_ENABLE_WID);
  1648. //WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 1, EDID_CLK_EN_BIT, EDID_CLK_EN_WID);
  1649. //pr_info("tvafe: tvafe_reset_vga. 3\n");
  1650. //WRITE_CBUS_REG_BITS(HHI_TVFE_AUTOMODE_CLK_CNTL, 1, 7, 1); //enable auto mode clock
  1651. //...
  1652. //pr_info("tvafe: tvafe_reset_vga. 4\n");
  1653. WRITE_APB_REG_BITS(TVFE_RST_CTRL, 1, ADC_CLK_RST_BIT, ADC_CLK_RST_WID);
  1654. WRITE_APB_REG_BITS(TVFE_RST_CTRL, 1, EDID_RST_BIT, EDID_RST_WID);
  1655. WRITE_APB_REG_BITS(TVFE_RST_CTRL, 1, VAFE_RST_BIT, VAFE_RST_WID);
  1656. }
  1657. static void tvafe_stop_comp(void)
  1658. {
  1659. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 0, COMP_CLK_ENABLE_BIT, COMP_CLK_ENABLE_WID);
  1660. //WRITE_CBUS_REG_BITS(HHI_TVFE_AUTOMODE_CLK_CNTL, 0, 7, 1); //
  1661. }
  1662. static void tvafe_reset_comp(void)
  1663. {
  1664. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 0, SOFT_RST_BIT, SOFT_RST_WID);
  1665. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 1, SOFT_RST_BIT, SOFT_RST_WID); //SOFT RESET memory
  1666. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 0, SOFT_RST_BIT, SOFT_RST_WID);
  1667. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 0, DCLK_ENABLE_BIT, DCLK_ENABLE_WID);
  1668. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 0, VAFE_MCLK_EN_BIT, VAFE_MCLK_EN_WID);
  1669. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 1, COMP_CLK_ENABLE_BIT, COMP_CLK_ENABLE_WID);
  1670. //WRITE_CBUS_REG_BITS(HHI_TVFE_AUTOMODE_CLK_CNTL, 1, 7, 1); //enable auto mode clock
  1671. WRITE_APB_REG_BITS(TVFE_RST_CTRL, 1, ADC_CLK_RST_BIT, ADC_CLK_RST_WID);
  1672. WRITE_APB_REG_BITS(TVFE_RST_CTRL, 1, VAFE_RST_BIT, VAFE_RST_WID);
  1673. }
  1674. static void tvafe_stop_cvbs(void)
  1675. {
  1676. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 0, DCLK_ENABLE_BIT, DCLK_ENABLE_WID);
  1677. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 0, VAFE_MCLK_EN_BIT, VAFE_MCLK_EN_WID);
  1678. }
  1679. static void tvafe_reset_cvbs(void)
  1680. {
  1681. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 0, SOFT_RST_BIT, SOFT_RST_WID);
  1682. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 1, SOFT_RST_BIT, SOFT_RST_WID); //SOFT RESET memory
  1683. //WRITE_APB_REG_BITS(CVD2_RESET_REGISTER, 0, SOFT_RST_BIT, SOFT_RST_WID);
  1684. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 1, DCLK_ENABLE_BIT, DCLK_ENABLE_WID);
  1685. WRITE_APB_REG_BITS(TVFE_TOP_CTRL, 1, VAFE_MCLK_EN_BIT, VAFE_MCLK_EN_WID);
  1686. WRITE_APB_REG_BITS(TVFE_RST_CTRL, 1, DCLK_RST_BIT, DCLK_RST_WID);
  1687. WRITE_APB_REG_BITS(TVFE_RST_CTRL, 1, MCLK_RST_BIT, MCLK_RST_WID);
  1688. }
  1689. void tvafe_stop_module(struct tvafe_info_s *info)
  1690. {
  1691. if ((info->param.port > TVIN_PORT_VGA0) && (info->param.port < TVIN_PORT_VGA7))
  1692. tvafe_stop_vga();
  1693. else if ((info->param.port > TVIN_PORT_COMP0) && (info->param.port < TVIN_PORT_COMP7))
  1694. tvafe_stop_comp();
  1695. else
  1696. tvafe_stop_cvbs();
  1697. }
  1698. void tvafe_reset_module(enum tvin_port_e port)
  1699. {
  1700. if ((port >= TVIN_PORT_VGA0) && (port <= TVIN_PORT_VGA7))
  1701. tvafe_reset_vga();
  1702. else if ((port >= TVIN_PORT_COMP0) && (port <= TVIN_PORT_COMP7))
  1703. tvafe_reset_comp();
  1704. else
  1705. tvafe_reset_cvbs();
  1706. }
  1707. void tvafe_set_fmt(struct tvafe_info_s *info)
  1708. {
  1709. //check decoder signal status
  1710. if((info->param.status != TVIN_SIG_STATUS_STABLE) || (info->param.fmt == TVIN_SIG_FMT_NULL))
  1711. {
  1712. //pr_info("TVAFE tvafe_set_fmt format abnormal \n");
  1713. return;
  1714. }
  1715. pr_info("TVAFE tvafe_set_fmt:%d\n", info->param.fmt);
  1716. if ((info->param.port >= TVIN_PORT_CVBS0) &&
  1717. (info->param.port <= TVIN_PORT_SVIDEO7)
  1718. )
  1719. {
  1720. #ifndef VDIN_FIXED_FMT_TEST
  1721. tvafe_cvd2_video_mode_confiure(info->param.fmt, info->param.port);
  1722. #endif
  1723. }
  1724. else
  1725. {
  1726. tvafe_adc_configure(info->param.fmt);
  1727. tvafe_top_config(info->param.fmt);
  1728. }
  1729. //pin mux, must load pin mux again after load reg table
  1730. tvafe_source_muxing(info);
  1731. //cvd2 set fmt ...
  1732. }
  1733. static inline bool tvafe_is_nosig(struct tvafe_info_s *info)
  1734. {
  1735. bool ret = 0;
  1736. if ((info->src_type == TVAFE_SRC_TYPE_VGA) ||
  1737. (info->src_type == TVAFE_SRC_TYPE_COMP))
  1738. ret = tvafe_adc_no_sig();
  1739. else if ((info->src_type == TVAFE_SRC_TYPE_CVBS) ||
  1740. (info->src_type == TVAFE_SRC_TYPE_SVIDEO))
  1741. ret = tvafe_cvd_no_sig();
  1742. return ret;
  1743. }
  1744. static inline bool tvafe_fmt_chg(struct tvafe_info_s *info)
  1745. {
  1746. bool ret = false;
  1747. if ((info->src_type == TVAFE_SRC_TYPE_VGA) ||
  1748. (info->src_type == TVAFE_SRC_TYPE_COMP))
  1749. ret = tvafe_adc_fmt_chg(info);//(info->src_type, &info->param);
  1750. else if ((info->src_type == TVAFE_SRC_TYPE_CVBS) ||
  1751. (info->src_type == TVAFE_SRC_TYPE_SVIDEO))
  1752. ret = tvafe_cvd_fmt_chg();
  1753. return ret;
  1754. }
  1755. static inline bool tvafe_pll_bad(struct tvafe_info_s *info)
  1756. {
  1757. bool ret = true;
  1758. if ((info->src_type == TVAFE_SRC_TYPE_VGA) ||
  1759. (info->src_type == TVAFE_SRC_TYPE_COMP)
  1760. )
  1761. ret = tvafe_adc_get_pll_status();
  1762. if (ret)
  1763. return false;
  1764. else
  1765. return true;
  1766. }
  1767. static inline enum tvin_sig_fmt_e tvafe_get_fmt(struct tvafe_info_s *info)
  1768. {
  1769. enum tvin_sig_fmt_e fmt = TVIN_SIG_FMT_NULL;
  1770. if ((info->src_type == TVAFE_SRC_TYPE_VGA) ||
  1771. (info->src_type == TVAFE_SRC_TYPE_COMP))
  1772. fmt = tvafe_adc_search_mode(info->src_type);
  1773. else if ((info->src_type == TVAFE_SRC_TYPE_CVBS) ||
  1774. (info->src_type == TVAFE_SRC_TYPE_SVIDEO))
  1775. fmt = tvafe_cvd2_get_format();
  1776. return fmt;
  1777. }
  1778. inline void tvafe_init_state_handler(void)
  1779. {
  1780. tvafe_state = TVAFE_STATE_NOSIG;
  1781. tvafe_state_counter = 0;
  1782. tvafe_exit_nosig_counter = 0;
  1783. tvafe_back_nosig_counter = 0;
  1784. tvafe_exit_stable_counter = 0;
  1785. tvafe_back_stable_counter = 0;
  1786. tvafe_cvd2_state_init();
  1787. }
  1788. static unsigned int wait_fmt_set_cnt = 0;
  1789. static bool rst_fg = 0;
  1790. inline void tvafe_run_state_handler(struct tvafe_info_s *info)
  1791. {
  1792. enum tvin_sig_fmt_e fmt = 0;
  1793. //wait format stable after set format table
  1794. if (info->src_type == TVAFE_SRC_TYPE_COMP)
  1795. {
  1796. if (wait_fmt_set_cnt++ <= 10)
  1797. return;
  1798. else
  1799. wait_fmt_set_cnt = 10;
  1800. }
  1801. switch (tvafe_state)
  1802. {
  1803. case TVAFE_STATE_NOSIG:
  1804. ++tvafe_state_counter;
  1805. if (tvafe_is_nosig(info))
  1806. {
  1807. tvafe_exit_nosig_counter = 0;
  1808. if (tvafe_state_counter >= TVAFE_SURE_NOSIG)
  1809. {
  1810. tvafe_state_counter = TVAFE_SURE_NOSIG;
  1811. info->param.status = TVIN_SIG_STATUS_NOSIG;
  1812. info->param.fmt = TVIN_SIG_FMT_NULL;
  1813. //pr_info("TVAFE state: nosig\n");
  1814. }
  1815. }
  1816. else
  1817. {
  1818. ++tvafe_exit_nosig_counter;
  1819. if (tvafe_exit_nosig_counter >= TVAFE_EXIT_NOSIG)
  1820. {
  1821. tvafe_exit_nosig_counter = 0;
  1822. tvafe_state_counter = 0;
  1823. tvafe_state = TVAFE_STATE_UNSTABLE;
  1824. rst_fg = 0;
  1825. pr_info("TVAFE state: nosig-->unstable\n");
  1826. }
  1827. }
  1828. break;
  1829. case TVAFE_STATE_UNSTABLE:
  1830. ++tvafe_state_counter;
  1831. if (tvafe_is_nosig(info))
  1832. {
  1833. tvafe_back_stable_counter = 0;
  1834. ++tvafe_back_nosig_counter;
  1835. if (tvafe_back_nosig_counter >= TVAFE_BACK_NOSIG)
  1836. {
  1837. tvafe_back_nosig_counter = 0;
  1838. tvafe_state_counter = 0;
  1839. tvafe_state = TVAFE_STATE_NOSIG;
  1840. info->param.status = TVIN_SIG_STATUS_NOSIG;
  1841. info->param.fmt = TVIN_SIG_FMT_NULL;
  1842. pr_info("TVAFE state: unstable-->nosig\n");
  1843. }
  1844. }
  1845. else
  1846. {
  1847. tvafe_back_nosig_counter = 0;
  1848. // if (tvafe_fmt_chg(info) || tvafe_pll_bad(info))
  1849. if (tvafe_fmt_chg(info))
  1850. {
  1851. tvafe_back_stable_counter = 0;
  1852. if (tvafe_state_counter >= TVAFE_SURE_UNSTABLE)
  1853. {
  1854. tvafe_state_counter = TVAFE_SURE_UNSTABLE;
  1855. info->param.status = TVIN_SIG_STATUS_UNSTABLE;
  1856. info->param.fmt = TVIN_SIG_FMT_NULL;
  1857. if ((rst_fg == 0) &&
  1858. (info->src_type == TVAFE_SRC_TYPE_COMP))
  1859. {
  1860. rst_fg = 1;
  1861. tvafe_adc_digital_reset();
  1862. wait_fmt_set_cnt = 0;
  1863. pr_info("TVAFE: unstable, reset ADC\n");
  1864. }
  1865. pr_info("TVAFE state: unstable\n");
  1866. }
  1867. }
  1868. else
  1869. {
  1870. ++tvafe_back_stable_counter;
  1871. if (tvafe_back_stable_counter >= TVAFE_BACK_STABLE*9)
  1872. { //must wait enough time for cvd signal lock
  1873. tvafe_back_stable_counter = 0;
  1874. tvafe_state_counter = 0;
  1875. tvafe_state = TVAFE_STATE_STABLE;
  1876. info->param.status = TVIN_SIG_STATUS_STABLE;
  1877. //info->param.fmt = tvafe_get_fmt(info);
  1878. fmt = tvafe_get_fmt(info);
  1879. #if 1
  1880. if (info->src_type == TVAFE_SRC_TYPE_COMP)
  1881. {
  1882. if ((info->param.fmt == TVIN_SIG_FMT_NULL) &&
  1883. (rst_fg == 0))
  1884. {
  1885. rst_fg = 1;
  1886. tvafe_adc_digital_reset();
  1887. wait_fmt_set_cnt = 0;
  1888. pr_info("TVAFE: NULL fmt, reset ADC\n");
  1889. }
  1890. else if (info->param.fmt != fmt)
  1891. wait_fmt_set_cnt = 0;
  1892. }
  1893. info->param.fmt = fmt;
  1894. #else
  1895. info->param.fmt = tvafe_get_fmt(info);
  1896. #endif
  1897. pr_info("TVAFE state: unstable-->stable fmt:%d\n", info->param.fmt);
  1898. }
  1899. }
  1900. }
  1901. break;
  1902. case TVAFE_STATE_STABLE:
  1903. // if (tvafe_is_nosig(info) || tvafe_fmt_chg(info) || tvafe_pll_bad(info))
  1904. if (tvafe_is_nosig(info) || tvafe_fmt_chg(info))
  1905. {
  1906. ++tvafe_exit_stable_counter;
  1907. if (tvafe_exit_stable_counter >= TVAFE_EXIT_STABLE)
  1908. {
  1909. tvafe_exit_stable_counter = 0;
  1910. tvafe_state = TVAFE_STATE_UNSTABLE;
  1911. rst_fg = 0;
  1912. pr_info("TVAFE state: stable-->unstable\n");
  1913. }
  1914. }
  1915. else
  1916. {
  1917. tvafe_exit_stable_counter = 0;
  1918. }
  1919. break;
  1920. default:
  1921. break;
  1922. }
  1923. }