deinterlace.c 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795
  1. #include <linux/string.h>
  2. #include <linux/timer.h>
  3. #include <linux/workqueue.h>
  4. #include <linux/platform_device.h>
  5. #include <mach/am_regs.h>
  6. #include <linux/amports/canvas.h>
  7. #include <linux/amports/vframe.h>
  8. #include <linux/amports/vframe_provider.h>
  9. #include "deinterlace.h"
  10. #ifdef DEBUG
  11. unsigned di_pre_underflow = 0, di_pre_overflow = 0;
  12. unsigned long debug_array[4 * 1024];
  13. #endif
  14. #if 1
  15. #define RECEIVER_NAME "amvideo"
  16. #else
  17. #define RECEIVER_NAME "deinterlace"
  18. #endif
  19. #define PATTERN32_NUM 2
  20. #define PATTERN22_NUM 32
  21. #if (PATTERN22_NUM < 32)
  22. #define PATTERN22_MARK ((1LL<<PATTERN22_NUM)-1)
  23. #elif (PATTERN22_NUM < 64)
  24. #define PATTERN22_MARK ((0x100000000LL<<(PATTERN22_NUM-32))-1)
  25. #else
  26. #define PATTERN22_MARK 0xffffffffffffffffLL
  27. #endif
  28. #define PRE_HOLD_LINE 4
  29. #define DI_PRE_INTERVAL (HZ/100)
  30. // 0 - off
  31. // 1 - pre-post link
  32. // 2 - pre-post separate, only post in vsync
  33. static int deinterlace_mode = 0;
  34. #if defined(CONFIG_ARCH_MESON2)
  35. static int noise_reduction_level = 2;
  36. #endif
  37. static struct timer_list di_pre_timer;
  38. static struct work_struct di_pre_work;
  39. int di_pre_recycle_buf = -1;
  40. int prev_struct = 0;
  41. int prog_field_count = 0;
  42. int buf_recycle_done = 1;
  43. int di_pre_post_done = 1;
  44. int field_counter = 0, pre_field_counter = 0, di_checked_field = 0;
  45. int pattern_len = 0;
  46. int di_p32_counter = 0;
  47. unsigned int last_big_data = 0, last_big_num = 0;
  48. unsigned long blend_mode, pattern_22, di_info[4][83];
  49. unsigned long long di_p32_info, di_p22_info, di_p32_info_2, di_p22_info_2;
  50. vframe_t *cur_buf;
  51. vframe_t di_buf_pool[DI_BUF_NUM];
  52. DI_MIF_t di_inp_top_mif;
  53. DI_MIF_t di_inp_bot_mif;
  54. DI_MIF_t di_mem_mif;
  55. DI_MIF_t di_buf0_mif;
  56. DI_MIF_t di_buf1_mif;
  57. DI_MIF_t di_chan2_mif;
  58. DI_SIM_MIF_t di_nrwr_mif;
  59. DI_SIM_MIF_t di_mtnwr_mif;
  60. DI_SIM_MIF_t di_mtncrd_mif;
  61. DI_SIM_MIF_t di_mtnprd_mif;
  62. unsigned di_mem_start;
  63. int vdin_en = 0;
  64. vframe_t dummy_buf;
  65. int get_deinterlace_mode(void)
  66. {
  67. return deinterlace_mode;
  68. }
  69. void set_deinterlace_mode(int mode)
  70. {
  71. deinterlace_mode = mode;
  72. }
  73. #if defined(CONFIG_ARCH_MESON2)
  74. int get_noise_reduction_level(void)
  75. {
  76. return noise_reduction_level;
  77. }
  78. void set_noise_reduction_level(int level)
  79. {
  80. noise_reduction_level = level;
  81. }
  82. #endif
  83. int get_di_pre_recycle_buf(void)
  84. {
  85. return di_pre_recycle_buf;
  86. }
  87. vframe_t *peek_di_out_buf(void)
  88. {
  89. if (field_counter <= pre_field_counter - 2) {
  90. return &(di_buf_pool[field_counter % DI_BUF_NUM]);
  91. } else {
  92. return NULL;
  93. }
  94. }
  95. void inc_field_counter(void)
  96. {
  97. field_counter++;
  98. }
  99. void set_post_di_mem(int mode)
  100. {
  101. unsigned temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((field_counter + di_checked_field) % DI_BUF_NUM);
  102. canvas_config(di_buf0_mif.canvas0_addr0, temp, MAX_CANVAS_WIDTH * 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  103. if (mode == 1) {
  104. temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((field_counter + di_checked_field + 1) % DI_BUF_NUM);
  105. } else {
  106. temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((field_counter + di_checked_field - 1) % DI_BUF_NUM);
  107. }
  108. canvas_config(di_buf1_mif.canvas0_addr0, temp, MAX_CANVAS_WIDTH * 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  109. temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((field_counter + di_checked_field) % DI_BUF_NUM) + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT);
  110. canvas_config(di_mtncrd_mif.canvas_num, temp, MAX_CANVAS_WIDTH / 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  111. temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((field_counter + di_checked_field + 1) % DI_BUF_NUM) + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT);
  112. canvas_config(di_mtnprd_mif.canvas_num, temp, MAX_CANVAS_WIDTH / 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  113. }
  114. void disable_deinterlace(void)
  115. {
  116. WRITE_MPEG_REG(DI_PRE_CTRL, 0x3 << 30);
  117. WRITE_MPEG_REG(DI_POST_CTRL, 0x3 << 30);
  118. WRITE_MPEG_REG(DI_PRE_SIZE, (32 - 1) | ((64 - 1) << 16));
  119. WRITE_MPEG_REG(DI_POST_SIZE, (32 - 1) | ((128 - 1) << 16));
  120. WRITE_MPEG_REG(DI_INP_GEN_REG, READ_MPEG_REG(DI_INP_GEN_REG) & 0xfffffffe);
  121. WRITE_MPEG_REG(DI_MEM_GEN_REG, READ_MPEG_REG(DI_MEM_GEN_REG) & 0xfffffffe);
  122. WRITE_MPEG_REG(DI_CHAN2_GEN_REG, READ_MPEG_REG(DI_CHAN2_GEN_REG) & 0xfffffffe);
  123. WRITE_MPEG_REG(DI_IF1_GEN_REG, READ_MPEG_REG(DI_IF1_GEN_REG) & 0xfffffffe);
  124. }
  125. void disable_pre_deinterlace(void)
  126. {
  127. unsigned status = READ_MPEG_REG(DI_PRE_CTRL) & 0x2;
  128. if (prev_struct > 0) {
  129. unsigned temp = READ_MPEG_REG(DI_PRE_SIZE);
  130. unsigned total = (temp & 0xffff) * ((temp >> 16) & 0xffff);
  131. unsigned count = 0;
  132. while ((READ_MPEG_REG(DI_INTR_CTRL) & 0xf) != (status | 0x9)) {
  133. if (count++ >= total) {
  134. break;
  135. }
  136. }
  137. WRITE_MPEG_REG(DI_INTR_CTRL, READ_MPEG_REG(DI_INTR_CTRL));
  138. }
  139. WRITE_MPEG_REG(DI_INP_GEN_REG, READ_MPEG_REG(DI_INP_GEN_REG) & 0xfffffffe);
  140. WRITE_MPEG_REG(DI_MEM_GEN_REG, READ_MPEG_REG(DI_MEM_GEN_REG) & 0xfffffffe);
  141. WRITE_MPEG_REG(DI_CHAN2_GEN_REG, READ_MPEG_REG(DI_CHAN2_GEN_REG) & 0xfffffffe);
  142. #ifdef DEBUG
  143. di_pre_underflow = 0;
  144. di_pre_overflow = 0;
  145. #endif
  146. prev_struct = 0;
  147. prog_field_count = 0;
  148. buf_recycle_done = 1;
  149. di_pre_post_done = 1;
  150. pre_field_counter = field_counter;
  151. di_pre_recycle_buf = -1;
  152. WRITE_MPEG_REG(DI_PRE_CTRL, 0x3 << 30);
  153. WRITE_MPEG_REG(DI_PRE_SIZE, (32 - 1) | ((64 - 1) << 16));
  154. }
  155. void disable_post_deinterlace(void)
  156. {
  157. WRITE_MPEG_REG(DI_POST_CTRL, 0x3 << 30);
  158. WRITE_MPEG_REG(DI_POST_SIZE, (32 - 1) | ((128 - 1) << 16));
  159. WRITE_MPEG_REG(DI_IF1_GEN_REG, READ_MPEG_REG(DI_IF1_GEN_REG) & 0xfffffffe);
  160. }
  161. void set_vd1_fmt_more(
  162. int hfmt_en,
  163. int hz_yc_ratio, //2bit
  164. int hz_ini_phase, //4bit
  165. int vfmt_en,
  166. int vt_yc_ratio, //2bit
  167. int vt_ini_phase, //4bit
  168. int y_length,
  169. int c_length,
  170. int hz_rpt //1bit
  171. )
  172. {
  173. int vt_phase_step = (16 >> vt_yc_ratio);
  174. WRITE_MPEG_REG(VIU_VD1_FMT_CTRL, (hz_rpt << 28) | // hz rpt pixel
  175. (hz_ini_phase << 24) | // hz ini phase
  176. (0 << 23) | // repeat p0 enable
  177. (hz_yc_ratio << 21) | // hz yc ratio
  178. (hfmt_en << 20) | // hz enable
  179. (1 << 17) | // nrpt_phase0 enable
  180. (0 << 16) | // repeat l0 enable
  181. (0 << 12) | // skip line num
  182. (vt_ini_phase << 8) | // vt ini phase
  183. (vt_phase_step << 1) | // vt phase step (3.4)
  184. (vfmt_en << 0) // vt enable
  185. );
  186. WRITE_MPEG_REG(VIU_VD1_FMT_W, (y_length << 16) | // hz format width
  187. (c_length << 0) // vt format width
  188. );
  189. }
  190. void initial_di_prepost(int hsize_pre, int vsize_pre, int hsize_post, int vsize_post, int hold_line)
  191. {
  192. WRITE_MPEG_REG(DI_PRE_SIZE, (hsize_pre - 1) | ((vsize_pre - 1) << 16));
  193. WRITE_MPEG_REG(DI_POST_SIZE, (hsize_post - 1) | ((vsize_post - 1) << 16));
  194. WRITE_MPEG_REG(DI_BLEND_CTRL,
  195. (0x2 << 20) | // top mode. EI only
  196. 25); // KDEINT
  197. WRITE_MPEG_REG(DI_EI_CTRL0, (255 << 16) | // ei_filter.
  198. (5 << 8) | // ei_threshold.
  199. (1 << 2) | // ei bypass cf2.
  200. (1 << 1)); // ei bypass far1
  201. WRITE_MPEG_REG(DI_EI_CTRL1, (180 << 24) | // ei diff
  202. (10 << 16) | // ei ang45
  203. (15 << 8) | // ei peak.
  204. 45); // ei cross.
  205. WRITE_MPEG_REG(DI_EI_CTRL2, (10 << 23) | // close2
  206. (10 << 16) | // close1
  207. (10 << 8) | // far2
  208. 10); // far1
  209. WRITE_MPEG_REG(DI_PRE_CTRL, 0 | // NR enable
  210. (0 << 1) | // MTN_EN
  211. (0 << 2) | // check 3:2 pulldown
  212. (0 << 3) | // check 2:2 pulldown
  213. (0 << 4) | // 2:2 check mid pixel come from next field after MTN.
  214. (0 << 5) | // hist check enable
  215. (0 << 6) | // hist check not use chan2.
  216. (0 << 7) | // hist check use data before noise reduction.
  217. (0 << 8) | // chan 2 enable for 2:2 pull down check.
  218. (0 << 9) | // line buffer 2 enable
  219. (0 << 10) | // pre drop first.
  220. (0 << 11) | // pre repeat.
  221. (1 << 12) | // pre viu link
  222. (hold_line << 16) | // pre hold line number
  223. (0 << 29) | // pre field number.
  224. (0x3 << 30) // pre soft rst, pre frame rst.
  225. );
  226. WRITE_MPEG_REG(DI_POST_CTRL, (0 << 0) | // line buffer 0 enable
  227. (0 << 1) | // line buffer 1 enable
  228. (0 << 2) | // ei enable
  229. (0 << 3) | // mtn line buffer enable
  230. (0 << 4) | // mtnp read mif enable
  231. (0 << 5) | // di blend enble.
  232. (0 << 6) | // di mux output enable
  233. (0 << 7) | // di write to SDRAM enable.
  234. (1 << 8) | // di to VPP enable.
  235. (0 << 9) | // mif0 to VPP enable.
  236. (0 << 10) | // post drop first.
  237. (0 << 11) | // post repeat.
  238. (1 << 12) | // post viu link
  239. (1 << 13) | // prepost_link
  240. (hold_line << 16) | // post hold line number
  241. (0 << 29) | // post field number.
  242. (0x3 << 30) // post soft rst post frame rst.
  243. );
  244. WRITE_MPEG_REG(DI_MC_22LVL0, (READ_MPEG_REG(DI_MC_22LVL0) & 0xffff0000) | 256); // field 22 level
  245. WRITE_MPEG_REG(DI_MC_32LVL0, (READ_MPEG_REG(DI_MC_32LVL0) & 0xffffff00) | 16); // field 32 level
  246. // set hold line for all ddr req interface.
  247. WRITE_MPEG_REG(DI_INP_GEN_REG, (hold_line << 19));
  248. WRITE_MPEG_REG(DI_MEM_GEN_REG, (hold_line << 19));
  249. WRITE_MPEG_REG(VD1_IF0_GEN_REG, (hold_line << 19));
  250. WRITE_MPEG_REG(DI_IF1_GEN_REG, (hold_line << 19));
  251. WRITE_MPEG_REG(DI_CHAN2_GEN_REG, (hold_line << 19));
  252. }
  253. void initial_di_pre(int hsize_pre, int vsize_pre, int hold_line)
  254. {
  255. WRITE_MPEG_REG(DI_PRE_SIZE, (hsize_pre - 1) | ((vsize_pre - 1) << 16));
  256. WRITE_MPEG_REG(DI_PRE_CTRL, 0 | // NR enable
  257. (0 << 1) | // MTN_EN
  258. (0 << 2) | // check 3:2 pulldown
  259. (0 << 3) | // check 2:2 pulldown
  260. (0 << 4) | // 2:2 check mid pixel come from next field after MTN.
  261. (0 << 5) | // hist check enable
  262. (0 << 6) | // hist check not use chan2.
  263. (0 << 7) | // hist check use data before noise reduction.
  264. (0 << 8) | // chan 2 enable for 2:2 pull down check.
  265. (0 << 9) | // line buffer 2 enable
  266. (0 << 10) | // pre drop first.
  267. (0 << 11) | // pre repeat.
  268. (0 << 12) | // pre viu link
  269. (hold_line << 16) | // pre hold line number
  270. (0 << 29) | // pre field number.
  271. (0x3 << 30) // pre soft rst, pre frame rst.
  272. );
  273. WRITE_MPEG_REG(DI_MC_22LVL0, (READ_MPEG_REG(DI_MC_22LVL0) & 0xffff0000) | 256); // field 22 level
  274. WRITE_MPEG_REG(DI_MC_32LVL0, (READ_MPEG_REG(DI_MC_32LVL0) & 0xffffff00) | 16); // field 32 level
  275. }
  276. void initial_di_post(int hsize_post, int vsize_post, int hold_line)
  277. {
  278. WRITE_MPEG_REG(DI_POST_SIZE, (hsize_post - 1) | ((vsize_post - 1) << 16));
  279. WRITE_MPEG_REG(DI_BLEND_CTRL,
  280. (0x2 << 20) | // top mode. EI only
  281. 25); // KDEINT
  282. WRITE_MPEG_REG(DI_EI_CTRL0, (255 << 16) | // ei_filter.
  283. (5 << 8) | // ei_threshold.
  284. (1 << 2) | // ei bypass cf2.
  285. (1 << 1)); // ei bypass far1
  286. WRITE_MPEG_REG(DI_EI_CTRL1, (180 << 24) | // ei diff
  287. (10 << 16) | // ei ang45
  288. (15 << 8) | // ei peak.
  289. 45); // ei cross.
  290. WRITE_MPEG_REG(DI_EI_CTRL2, (10 << 23) | // close2
  291. (10 << 16) | // close1
  292. (10 << 8) | // far2
  293. 10); // far1
  294. WRITE_MPEG_REG(DI_POST_CTRL, (0 << 0) | // line buffer 0 enable
  295. (0 << 1) | // line buffer 1 enable
  296. (0 << 2) | // ei enable
  297. (0 << 3) | // mtn line buffer enable
  298. (0 << 4) | // mtnp read mif enable
  299. (0 << 5) | // di blend enble.
  300. (0 << 6) | // di mux output enable
  301. (0 << 7) | // di write to SDRAM enable.
  302. (1 << 8) | // di to VPP enable.
  303. (0 << 9) | // mif0 to VPP enable.
  304. (0 << 10) | // post drop first.
  305. (0 << 11) | // post repeat.
  306. (1 << 12) | // post viu link
  307. (hold_line << 16) | // post hold line number
  308. (0 << 29) | // post field number.
  309. (0x3 << 30) // post soft rst post frame rst.
  310. );
  311. }
  312. void enable_di_mode_check(int win0_start_x, int win0_end_x, int win0_start_y, int win0_end_y,
  313. int win1_start_x, int win1_end_x, int win1_start_y, int win1_end_y,
  314. int win2_start_x, int win2_end_x, int win2_start_y, int win2_end_y,
  315. int win3_start_x, int win3_end_x, int win3_start_y, int win3_end_y,
  316. int win4_start_x, int win4_end_x, int win4_start_y, int win4_end_y,
  317. int win0_32lvl, int win1_32lvl, int win2_32lvl, int win3_32lvl, int win4_32lvl,
  318. int win0_22lvl, int win1_22lvl, int win2_22lvl, int win3_22lvl, int win4_22lvl,
  319. int field_32lvl, int field_22lvl)
  320. {
  321. WRITE_MPEG_REG(DI_MC_REG0_X, (win0_start_x << 16) | // start_x
  322. win0_end_x); // end_x
  323. WRITE_MPEG_REG(DI_MC_REG0_Y, (win0_start_y << 16) | // start_y
  324. win0_end_y); // end_x
  325. WRITE_MPEG_REG(DI_MC_REG1_X, (win1_start_x << 16) | // start_x
  326. win1_end_x); // end_x
  327. WRITE_MPEG_REG(DI_MC_REG1_Y, (win1_start_y << 16) | // start_y
  328. win1_end_y); // end_x
  329. WRITE_MPEG_REG(DI_MC_REG2_X, (win2_start_x << 16) | // start_x
  330. win2_end_x); // end_x
  331. WRITE_MPEG_REG(DI_MC_REG2_Y, (win2_start_y << 16) | // start_y
  332. win2_end_y); // end_x
  333. WRITE_MPEG_REG(DI_MC_REG3_X, (win3_start_x << 16) | // start_x
  334. win3_end_x); // end_x
  335. WRITE_MPEG_REG(DI_MC_REG3_Y, (win3_start_y << 16) | // start_y
  336. win3_end_y); // end_x
  337. WRITE_MPEG_REG(DI_MC_REG4_X, (win4_start_x << 16) | // start_x
  338. win4_end_x); // end_x
  339. WRITE_MPEG_REG(DI_MC_REG4_Y, (win4_start_y << 16) | // start_y
  340. win4_end_y); // end_x
  341. WRITE_MPEG_REG(DI_MC_32LVL1, win3_32lvl | //region 3
  342. (win4_32lvl << 8)); //region 4
  343. WRITE_MPEG_REG(DI_MC_32LVL0, field_32lvl | //field 32 level
  344. (win0_32lvl << 8) | //region 0
  345. (win1_32lvl << 16) | //region 1
  346. (win2_32lvl << 24)); //region 2.
  347. WRITE_MPEG_REG(DI_MC_22LVL0, field_22lvl | // field 22 level
  348. (win0_22lvl << 16)); // region 0.
  349. WRITE_MPEG_REG(DI_MC_22LVL1, win1_22lvl | // region 1
  350. (win2_22lvl << 16)); // region 2.
  351. WRITE_MPEG_REG(DI_MC_22LVL2, win3_22lvl | // region 3
  352. (win4_22lvl << 16)); // region 4.
  353. WRITE_MPEG_REG(DI_MC_CTRL, 0x1f); // enable region level
  354. }
  355. // handle all case of prepost link.
  356. void enable_di_prepost_full(
  357. DI_MIF_t *di_inp_mif,
  358. DI_MIF_t *di_mem_mif,
  359. DI_MIF_t *di_buf0_mif,
  360. DI_MIF_t *di_buf1_mif,
  361. DI_MIF_t *di_chan2_mif,
  362. DI_SIM_MIF_t *di_nrwr_mif,
  363. DI_SIM_MIF_t *di_diwr_mif,
  364. DI_SIM_MIF_t *di_mtnwr_mif,
  365. DI_SIM_MIF_t *di_mtncrd_mif,
  366. DI_SIM_MIF_t *di_mtnprd_mif,
  367. int nr_en, int mtn_en, int pd32_check_en, int pd22_check_en, int hist_check_en,
  368. int ei_en, int blend_en, int blend_mtn_en, int blend_mode, int di_vpp_en, int di_ddr_en,
  369. #if defined(CONFIG_ARCH_MESON)
  370. #elif defined(CONFIG_ARCH_MESON2)
  371. int nr_hfilt_en, int nr_hfilt_mb_en, int mtn_modify_en,
  372. int blend_mtn_filt_en, int blend_data_filt_en, int post_mb_en,
  373. #endif
  374. int post_field_num, int pre_field_num, int prepost_link, int hold_line)
  375. {
  376. int hist_check_only;
  377. int ei_only;
  378. int buf1_en;
  379. #if defined(CONFIG_ARCH_MESON2)
  380. int nr_zone_0, nr_zone_1, nr_zone_2;
  381. if (noise_reduction_level == 0) {
  382. nr_zone_0 = 1;
  383. nr_zone_1 = 3;
  384. nr_zone_2 = 5;
  385. } else {
  386. nr_zone_0 = 3;
  387. nr_zone_1 = 6;
  388. nr_zone_2 = 10;
  389. }
  390. #endif
  391. hist_check_only = hist_check_en && !nr_en && !mtn_en && !pd22_check_en && !pd32_check_en;
  392. ei_only = ei_en && !blend_en && (di_vpp_en || di_ddr_en);
  393. #if defined(CONFIG_ARCH_MESON)
  394. buf1_en = (!prepost_link && !ei_only && (di_ddr_en || di_vpp_en));
  395. #elif defined(CONFIG_ARCH_MESON2)
  396. if (ei_only) {
  397. buf1_en = 0;
  398. } else {
  399. buf1_en = 1;
  400. }
  401. #endif
  402. if (nr_en | mtn_en | pd22_check_en || pd32_check_en) {
  403. set_di_inp_mif(di_inp_mif, di_vpp_en && prepost_link , hold_line);
  404. set_di_mem_mif(di_mem_mif, di_vpp_en && prepost_link, hold_line);
  405. }
  406. if (pd22_check_en || hist_check_only) {
  407. set_di_chan2_mif(di_chan2_mif, di_vpp_en && prepost_link, hold_line);
  408. }
  409. #if defined(CONFIG_ARCH_MESON)
  410. if (ei_en || di_vpp_en || di_ddr_en) {
  411. set_di_if0_mif(di_buf0_mif, di_vpp_en, hold_line);
  412. }
  413. if (!prepost_link && !ei_only && (di_ddr_en || di_vpp_en)) {
  414. set_di_if1_mif(di_buf1_mif, di_vpp_en, hold_line);
  415. }
  416. #elif defined(CONFIG_ARCH_MESON2)
  417. if (prepost_link && !ei_only && (di_ddr_en || di_vpp_en)) {
  418. set_di_if1_mif(di_buf1_mif, di_vpp_en, hold_line);
  419. } else if (!prepost_link && (ei_en || di_vpp_en || di_ddr_en)) {
  420. set_di_if0_mif(di_buf0_mif, di_vpp_en, hold_line);
  421. set_di_if1_mif(di_buf1_mif, di_vpp_en, hold_line);
  422. }
  423. #endif
  424. // set nr wr mif interface.
  425. if (nr_en) {
  426. WRITE_MPEG_REG(DI_NRWR_X, (di_nrwr_mif->start_x << 16) | (di_nrwr_mif->end_x)); // start_x 0 end_x 719.
  427. WRITE_MPEG_REG(DI_NRWR_Y, (di_nrwr_mif->start_y << 16) | (di_nrwr_mif->end_y)); // start_y 0 end_y 239.
  428. WRITE_MPEG_REG(DI_NRWR_CTRL, di_nrwr_mif->canvas_num | // canvas index.
  429. ((prepost_link && di_vpp_en) << 8)); // urgent.
  430. #if defined(CONFIG_ARCH_MESON)
  431. #elif defined(CONFIG_ARCH_MESON2)
  432. WRITE_MPEG_REG(DI_NR_CTRL0, (1 << 31) | // nr yuv enable.
  433. (1 << 30) | // nr range. 3 point
  434. (0 << 29) | // max of 3 point.
  435. (nr_hfilt_en << 28) | // nr hfilter enable.
  436. (nr_hfilt_mb_en << 27) | // nr hfilter motion_blur enable.
  437. (nr_zone_2 << 16) | // zone 2
  438. (nr_zone_1 << 8) | // zone 1
  439. (nr_zone_0 << 0)); // zone 0
  440. WRITE_MPEG_REG(DI_NR_CTRL2, (10 << 24) | //intra noise level
  441. (1 << 16) | // intra no noise level.
  442. (10 << 8) | // inter noise level.
  443. (1 << 0)); // inter no noise level.
  444. WRITE_MPEG_REG(DI_NR_CTRL3, (16 << 16) | // if any one of 3 point mtn larger than 16 don't use 3 point.
  445. 720); // if one line eq cnt is larger than this number, this line is not conunted.
  446. #endif
  447. }
  448. // motion wr mif.
  449. if (mtn_en) {
  450. WRITE_MPEG_REG(DI_MTNWR_X, (di_mtnwr_mif->start_x << 16) | (di_mtnwr_mif->end_x)); // start_x 0 end_x 719.
  451. WRITE_MPEG_REG(DI_MTNWR_Y, (di_mtnwr_mif->start_y << 16) | (di_mtnwr_mif->end_y)); // start_y 0 end_y 239.
  452. WRITE_MPEG_REG(DI_MTNWR_CTRL, di_mtnwr_mif->canvas_num | // canvas index.
  453. ((prepost_link && di_vpp_en) << 8)); // urgent.
  454. #if defined(CONFIG_ARCH_MESON)
  455. #elif defined(CONFIG_ARCH_MESON2)
  456. WRITE_MPEG_REG(DI_MTN_CTRL, (1 << 31) | // lpf enable.
  457. (1 << 30) | // mtn uv enable.
  458. (mtn_modify_en << 29) | // no mtn modify.
  459. (2 << 24) | // char diff count.
  460. (40 << 16) | // black level.
  461. (196 << 8) | // white level.
  462. (64 << 0)); // char diff level.
  463. WRITE_MPEG_REG(DI_MTN_CTRL1, (3 << 8) | // mtn shift if mtn modifty_en
  464. 0); // mtn reduce before shift.
  465. #endif
  466. }
  467. // motion for current display field.
  468. #if defined(CONFIG_ARCH_MESON)
  469. if (blend_mtn_en) {
  470. WRITE_MPEG_REG(DI_MTNCRD_X, (di_mtncrd_mif->start_x << 16) | (di_mtncrd_mif->end_x)); // start_x 0 end_x 719.
  471. WRITE_MPEG_REG(DI_MTNCRD_Y, (di_mtncrd_mif->start_y << 16) | (di_mtncrd_mif->end_y)); // start_y 0 end_y 239.
  472. if (!prepost_link) {
  473. WRITE_MPEG_REG(DI_MTNRD_CTRL, (di_mtnprd_mif->canvas_num << 8) | //mtnp canvas index.
  474. (0 << 16) | // urgent
  475. di_mtncrd_mif->canvas_num); // current field mtn canvas index.
  476. } else {
  477. WRITE_MPEG_REG(DI_MTNRD_CTRL, (0 << 8) | //mtnp canvas index.
  478. ((prepost_link && di_vpp_en) << 16) | // urgent
  479. di_mtncrd_mif->canvas_num); // current field mtn canvas index.
  480. }
  481. }
  482. if (blend_mtn_en && !prepost_link) {
  483. WRITE_MPEG_REG(DI_MTNPRD_X, (di_mtnprd_mif->start_x << 16) | (di_mtnprd_mif->end_x)); // start_x 0 end_x 719.
  484. WRITE_MPEG_REG(DI_MTNPRD_Y, (di_mtnprd_mif->start_y << 16) | (di_mtnprd_mif->end_y)); // start_y 0 end_y 239.
  485. }
  486. #elif defined(CONFIG_ARCH_MESON2)
  487. if (blend_mtn_en) {
  488. WRITE_MPEG_REG(DI_MTNCRD_X, (di_mtncrd_mif->start_x << 16) | (di_mtncrd_mif->end_x)); // start_x 0 end_x 719.
  489. WRITE_MPEG_REG(DI_MTNCRD_Y, (di_mtncrd_mif->start_y << 16) | (di_mtncrd_mif->end_y)); // start_y 0 end_y 239.
  490. WRITE_MPEG_REG(DI_MTNPRD_X, (di_mtnprd_mif->start_x << 16) | (di_mtnprd_mif->end_x)); // start_x 0 end_x 719.
  491. WRITE_MPEG_REG(DI_MTNPRD_Y, (di_mtnprd_mif->start_y << 16) | (di_mtnprd_mif->end_y)); // start_y 0 end_y 239.
  492. WRITE_MPEG_REG(DI_MTNRD_CTRL, (di_mtnprd_mif->canvas_num << 8) | //mtnp canvas index.
  493. ((prepost_link && di_vpp_en) << 16) | // urgent
  494. di_mtncrd_mif->canvas_num); // current field mtn canvas index.
  495. }
  496. #endif
  497. if (di_ddr_en) {
  498. WRITE_MPEG_REG(DI_DIWR_X, (di_diwr_mif->start_x << 16) | (di_diwr_mif->end_x)); // start_x 0 end_x 719.
  499. WRITE_MPEG_REG(DI_DIWR_Y, (di_diwr_mif->start_y << 16) | (di_diwr_mif->end_y * 2 + 1)); // start_y 0 end_y 479.
  500. WRITE_MPEG_REG(DI_DIWR_CTRL, di_diwr_mif->canvas_num | // canvas index.
  501. (di_vpp_en << 8)); // urgent.
  502. }
  503. #if defined(CONFIG_ARCH_MESON)
  504. WRITE_MPEG_REG(DI_PRE_CTRL, nr_en | // NR enable
  505. (mtn_en << 1) | // MTN_EN
  506. (pd32_check_en << 2) | // check 3:2 pulldown
  507. (pd22_check_en << 3) | // check 2:2 pulldown
  508. (1 << 4) | // 2:2 check mid pixel come from next field after MTN.
  509. (hist_check_en << 5) | // hist check enable
  510. (0 << 6) | // hist check not use chan2.
  511. ((!nr_en) << 7) | // hist check use data before noise reduction.
  512. (pd22_check_en << 8) | // chan 2 enable for 2:2 pull down check.
  513. (pd22_check_en << 9) | // line buffer 2 enable
  514. (0 << 10) | // pre drop first.
  515. (0 << 11) | // pre repeat.
  516. (di_vpp_en << 12) | // pre viu link
  517. (hold_line << 16) | // pre hold line number
  518. (pre_field_num << 29) | // pre field number.
  519. (0x1 << 30) // pre soft rst, pre frame rst.
  520. );
  521. WRITE_MPEG_REG(DI_POST_CTRL, ((ei_en || di_vpp_en || di_ddr_en) << 0) | // line buffer 0 enable
  522. (buf1_en << 1) | // line buffer 1 enable
  523. (ei_en << 2) | // ei enable
  524. (blend_mtn_en << 3) | // mtn line buffer enable
  525. ((blend_mtn_en && !prepost_link) << 4) | // mtnp read mif enable
  526. (blend_en << 5) | // di blend enble.
  527. (1 << 6) | // di mux output enable
  528. (di_ddr_en << 7) | // di write to SDRAM enable.
  529. (di_vpp_en << 8) | // di to VPP enable.
  530. (0 << 9) | // mif0 to VPP enable.
  531. (0 << 10) | // post drop first.
  532. (0 << 11) | // post repeat.
  533. (1 << 12) | // post viu link
  534. (prepost_link << 13) |
  535. (hold_line << 16) | // post hold line number
  536. (post_field_num << 29) | // post field number.
  537. (0x1 << 30) // post soft rst post frame rst.
  538. );
  539. #elif defined(CONFIG_ARCH_MESON2)
  540. WRITE_MPEG_REG(DI_PRE_CTRL, nr_en | // NR enable
  541. (mtn_en << 1) | // MTN_EN
  542. (pd32_check_en << 2) | // check 3:2 pulldown
  543. (pd22_check_en << 3) | // check 2:2 pulldown
  544. (nr_en << 4) | // 2:2 check mid pixel come from next field after MTN.
  545. (hist_check_en << 5) | // hist check enable
  546. (1 << 6) | // hist check not use chan2.
  547. ((!nr_en) << 7) | // hist check use data before noise reduction.
  548. (pd22_check_en << 8) | // chan 2 enable for 2:2 pull down check.
  549. (pd22_check_en << 9) | // line buffer 2 enable
  550. (0 << 10) | // pre drop first.
  551. (0 << 11) | // pre repeat.
  552. (di_vpp_en << 12) | // pre viu link
  553. (hold_line << 16) | // pre hold line number
  554. (nr_en << 22) | // MTN after NR.
  555. (pre_field_num << 29) | // pre field number.
  556. (0x1 << 30) // pre soft rst, pre frame rst.
  557. );
  558. WRITE_MPEG_REG(DI_POST_CTRL, ((ei_en || blend_en) << 0) | // line buffer 0 enable
  559. (buf1_en << 1) | // line buffer 1 enable
  560. (ei_en << 2) | // ei enable
  561. (blend_mtn_en << 3) | // mtn line buffer enable
  562. (blend_mtn_en << 4) | // mtnp read mif enable
  563. (blend_en << 5) | // di blend enble.
  564. (1 << 6) | // di mux output enable
  565. (di_ddr_en << 7) | // di write to SDRAM enable.
  566. (di_vpp_en << 8) | // di to VPP enable.
  567. (0 << 9) | // mif0 to VPP enable.
  568. (0 << 10) | // post drop first.
  569. (0 << 11) | // post repeat.
  570. (di_vpp_en << 12) | // post viu link
  571. (prepost_link << 13) |
  572. (hold_line << 16) | // post hold line number
  573. (post_field_num << 29) | // post field number.
  574. (0x1 << 30) // post soft rst post frame rst.
  575. );
  576. #endif
  577. if (ei_only == 0) {
  578. #if defined(CONFIG_ARCH_MESON)
  579. WRITE_MPEG_REG(DI_BLEND_CTRL, (READ_MPEG_REG(DI_BLEND_CTRL) & (~((1 << 25) | (3 << 20)))) | // clean some bit we need to set.
  580. (blend_mtn_en << 26) | // blend mtn enable.
  581. (0 << 25) | // blend with the mtn of the pre display field and next display field.
  582. (1 << 24) | // blend with pre display field.
  583. (blend_mode << 20) // motion adaptive blend.
  584. );
  585. #elif defined(CONFIG_ARCH_MESON2)
  586. WRITE_MPEG_REG(DI_BLEND_CTRL, (post_mb_en << 28) | // post motion blur enable.
  587. (0 << 27) | // mtn3p(l, c, r) max.
  588. (0 << 26) | // mtn3p(l, c, r) min.
  589. (0 << 25) | // mtn3p(l, c, r) ave.
  590. (1 << 24) | // mtntopbot max
  591. (blend_mtn_filt_en << 23) | // blend mtn filter enable.
  592. (blend_data_filt_en << 22) | // blend data filter enable.
  593. (blend_mode << 20) | // motion adaptive blend.
  594. 25 // kdeint.
  595. );
  596. WRITE_MPEG_REG(DI_BLEND_CTRL1, (196 << 24) | // char level
  597. (64 << 16) | // angle thredhold.
  598. (40 << 8) | // all_af filt thd.
  599. (64)); // all 4 equal
  600. WRITE_MPEG_REG(DI_BLEND_CTRL2, (4 << 8) | // mtn no mov level.
  601. (48)); //black level.
  602. #endif
  603. }
  604. }
  605. int di_mode_check(int cur_field)
  606. {
  607. int i;
  608. WRITE_MPEG_REG(DI_INFO_ADDR, 0);
  609. #if defined(CONFIG_ARCH_MESON)
  610. for (i = 0; i <= 76; i++)
  611. #elif defined(CONFIG_ARCH_MESON2)
  612. for (i = 0; i <= 82; i++)
  613. #endif
  614. {
  615. di_info[cur_field][i] = READ_MPEG_REG(DI_INFO_DATA);
  616. }
  617. WRITE_MPEG_REG(DI_PRE_CTRL, READ_MPEG_REG(DI_PRE_CTRL) | (0x1 << 30)); // pre soft rst
  618. WRITE_MPEG_REG(DI_POST_CTRL, READ_MPEG_REG(DI_POST_CTRL) | (0x1 << 30)); // post soft rst
  619. return (0);
  620. }
  621. void set_di_inp_fmt_more(int hfmt_en,
  622. int hz_yc_ratio, //2bit
  623. int hz_ini_phase, //4bit
  624. int vfmt_en,
  625. int vt_yc_ratio, //2bit
  626. int vt_ini_phase, //4bit
  627. int y_length,
  628. int c_length,
  629. int hz_rpt //1bit
  630. )
  631. {
  632. int repeat_l0_en = 1, nrpt_phase0_en = 0;
  633. int vt_phase_step = (16 >> vt_yc_ratio);
  634. WRITE_MPEG_REG(DI_INP_FMT_CTRL,
  635. (hz_rpt << 28) | //hz rpt pixel
  636. (hz_ini_phase << 24) | //hz ini phase
  637. (0 << 23) | //repeat p0 enable
  638. (hz_yc_ratio << 21) | //hz yc ratio
  639. (hfmt_en << 20) | //hz enable
  640. (nrpt_phase0_en << 17) | //nrpt_phase0 enable
  641. (repeat_l0_en << 16) | //repeat l0 enable
  642. (0 << 12) | //skip line num
  643. (vt_ini_phase << 8) | //vt ini phase
  644. (vt_phase_step << 1) | //vt phase step (3.4)
  645. (vfmt_en << 0) //vt enable
  646. );
  647. WRITE_MPEG_REG(DI_INP_FMT_W, (y_length << 16) | //hz format width
  648. (c_length << 0) //vt format width
  649. );
  650. }
  651. void set_di_inp_mif(DI_MIF_t *mif, int urgent, int hold_line)
  652. {
  653. unsigned long bytes_per_pixel;
  654. unsigned long demux_mode;
  655. unsigned long chro_rpt_lastl_ctrl;
  656. unsigned long luma0_rpt_loop_start;
  657. unsigned long luma0_rpt_loop_end;
  658. unsigned long luma0_rpt_loop_pat;
  659. unsigned long chroma0_rpt_loop_start;
  660. unsigned long chroma0_rpt_loop_end;
  661. unsigned long chroma0_rpt_loop_pat;
  662. unsigned long vt_ini_phase = 0;
  663. if (mif->set_separate_en == 1 && mif->src_field_mode == 1) {
  664. chro_rpt_lastl_ctrl = 1;
  665. luma0_rpt_loop_start = 1;
  666. luma0_rpt_loop_end = 1;
  667. chroma0_rpt_loop_start = 1;
  668. chroma0_rpt_loop_end = 1;
  669. luma0_rpt_loop_pat = 0x80;
  670. chroma0_rpt_loop_pat = 0x80;
  671. if (mif->output_field_num == 0) {
  672. vt_ini_phase = 0xe;
  673. } else {
  674. vt_ini_phase = 0xa;
  675. }
  676. } else if (mif->set_separate_en == 1 && mif->src_field_mode == 0) {
  677. chro_rpt_lastl_ctrl = 1;
  678. luma0_rpt_loop_start = 0;
  679. luma0_rpt_loop_end = 0;
  680. chroma0_rpt_loop_start = 0;
  681. chroma0_rpt_loop_end = 0;
  682. luma0_rpt_loop_pat = 0x0;
  683. chroma0_rpt_loop_pat = 0x0;
  684. } else if (mif->set_separate_en == 0 && mif->src_field_mode == 1) {
  685. chro_rpt_lastl_ctrl = 1;
  686. luma0_rpt_loop_start = 1;
  687. luma0_rpt_loop_end = 1;
  688. chroma0_rpt_loop_start = 0;
  689. chroma0_rpt_loop_end = 0;
  690. luma0_rpt_loop_pat = 0x80;
  691. chroma0_rpt_loop_pat = 0x00;
  692. } else {
  693. chro_rpt_lastl_ctrl = 0;
  694. luma0_rpt_loop_start = 0;
  695. luma0_rpt_loop_end = 0;
  696. chroma0_rpt_loop_start = 0;
  697. chroma0_rpt_loop_end = 0;
  698. luma0_rpt_loop_pat = 0x00;
  699. chroma0_rpt_loop_pat = 0x00;
  700. }
  701. bytes_per_pixel = mif->set_separate_en ? 0 : (mif->video_mode ? 2 : 1);
  702. demux_mode = mif->video_mode;
  703. // ----------------------
  704. // General register
  705. // ----------------------
  706. WRITE_MPEG_REG(DI_INP_GEN_REG, (urgent << 28) | // chroma urgent bit
  707. (urgent << 27) | // luma urgent bit.
  708. (1 << 25) | // no dummy data.
  709. (hold_line << 19) | // hold lines
  710. (1 << 18) | // push dummy pixel
  711. (demux_mode << 16) | // demux_mode
  712. (bytes_per_pixel << 14) |
  713. (mif->burst_size_cr << 12) |
  714. (mif->burst_size_cb << 10) |
  715. (mif->burst_size_y << 8) |
  716. (chro_rpt_lastl_ctrl << 6) |
  717. (mif->set_separate_en << 1) |
  718. (1 << 0) // cntl_enable
  719. );
  720. // ----------------------
  721. // Canvas
  722. // ----------------------
  723. WRITE_MPEG_REG(DI_INP_CANVAS0, (mif->canvas0_addr2 << 16) | // cntl_canvas0_addr2
  724. (mif->canvas0_addr1 << 8) | // cntl_canvas0_addr1
  725. (mif->canvas0_addr0 << 0) // cntl_canvas0_addr0
  726. );
  727. // ----------------------
  728. // Picture 0 X/Y start,end
  729. // ----------------------
  730. WRITE_MPEG_REG(DI_INP_LUMA_X0, (mif->luma_x_end0 << 16) | // cntl_luma_x_end0
  731. (mif->luma_x_start0 << 0) // cntl_luma_x_start0
  732. );
  733. WRITE_MPEG_REG(DI_INP_LUMA_Y0, (mif->luma_y_end0 << 16) | // cntl_luma_y_end0
  734. (mif->luma_y_start0 << 0) // cntl_luma_y_start0
  735. );
  736. WRITE_MPEG_REG(DI_INP_CHROMA_X0, (mif->chroma_x_end0 << 16) |
  737. (mif->chroma_x_start0 << 0)
  738. );
  739. WRITE_MPEG_REG(DI_INP_CHROMA_Y0, (mif->chroma_y_end0 << 16) |
  740. (mif->chroma_y_start0 << 0)
  741. );
  742. // ----------------------
  743. // Repeat or skip
  744. // ----------------------
  745. WRITE_MPEG_REG(DI_INP_RPT_LOOP, (0 << 28) |
  746. (0 << 24) |
  747. (0 << 20) |
  748. (0 << 16) |
  749. (chroma0_rpt_loop_start << 12) |
  750. (chroma0_rpt_loop_end << 8) |
  751. (luma0_rpt_loop_start << 4) |
  752. (luma0_rpt_loop_end << 0)
  753. ) ;
  754. WRITE_MPEG_REG(DI_INP_LUMA0_RPT_PAT, luma0_rpt_loop_pat);
  755. WRITE_MPEG_REG(DI_INP_CHROMA0_RPT_PAT, chroma0_rpt_loop_pat);
  756. // Dummy pixel value
  757. WRITE_MPEG_REG(DI_INP_DUMMY_PIXEL, 0x00808000);
  758. if ((mif->set_separate_en == 1)) { // 4:2:0 block mode.
  759. set_di_inp_fmt_more(
  760. 1, // hfmt_en
  761. 1, // hz_yc_ratio
  762. 0, // hz_ini_phase
  763. 1, // vfmt_en
  764. 1, // vt_yc_ratio
  765. vt_ini_phase, // vt_ini_phase
  766. mif->luma_x_end0 - mif->luma_x_start0 + 1, // y_length
  767. mif->chroma_x_end0 - mif->chroma_x_start0 + 1 , // c length
  768. 0); // hz repeat.
  769. } else {
  770. set_di_inp_fmt_more(
  771. 1, // hfmt_en
  772. 1, // hz_yc_ratio
  773. 0, // hz_ini_phase
  774. 0, // vfmt_en
  775. 0, // vt_yc_ratio
  776. 0, // vt_ini_phase
  777. mif->luma_x_end0 - mif->luma_x_start0 + 1, // y_length
  778. ((mif->luma_x_end0 >> 1) - (mif->luma_x_start0 >> 1) + 1), // c length
  779. 0); // hz repeat.
  780. }
  781. }
  782. void set_di_mem_fmt_more(int hfmt_en,
  783. int hz_yc_ratio, //2bit
  784. int hz_ini_phase, //4bit
  785. int vfmt_en,
  786. int vt_yc_ratio, //2bit
  787. int vt_ini_phase, //4bit
  788. int y_length,
  789. int c_length,
  790. int hz_rpt //1bit
  791. )
  792. {
  793. int vt_phase_step = (16 >> vt_yc_ratio);
  794. WRITE_MPEG_REG(DI_MEM_FMT_CTRL,
  795. (hz_rpt << 28) | //hz rpt pixel
  796. (hz_ini_phase << 24) | //hz ini phase
  797. (0 << 23) | //repeat p0 enable
  798. (hz_yc_ratio << 21) | //hz yc ratio
  799. (hfmt_en << 20) | //hz enable
  800. (1 << 17) | //nrpt_phase0 enable
  801. (0 << 16) | //repeat l0 enable
  802. (0 << 12) | //skip line num
  803. (vt_ini_phase << 8) | //vt ini phase
  804. (vt_phase_step << 1) | //vt phase step (3.4)
  805. (vfmt_en << 0) //vt enable
  806. );
  807. WRITE_MPEG_REG(DI_MEM_FMT_W, (y_length << 16) | //hz format width
  808. (c_length << 0) //vt format width
  809. );
  810. }
  811. void set_di_mem_mif(DI_MIF_t *mif, int urgent, int hold_line)
  812. {
  813. unsigned long bytes_per_pixel;
  814. unsigned long demux_mode;
  815. unsigned long chro_rpt_lastl_ctrl;
  816. unsigned long luma0_rpt_loop_start;
  817. unsigned long luma0_rpt_loop_end;
  818. unsigned long luma0_rpt_loop_pat;
  819. unsigned long chroma0_rpt_loop_start;
  820. unsigned long chroma0_rpt_loop_end;
  821. unsigned long chroma0_rpt_loop_pat;
  822. if (mif->set_separate_en == 1 && mif->src_field_mode == 1) {
  823. chro_rpt_lastl_ctrl = 1;
  824. luma0_rpt_loop_start = 1;
  825. luma0_rpt_loop_end = 1;
  826. chroma0_rpt_loop_start = 1;
  827. chroma0_rpt_loop_end = 1;
  828. luma0_rpt_loop_pat = 0x80;
  829. chroma0_rpt_loop_pat = 0x80;
  830. } else if (mif->set_separate_en == 1 && mif->src_field_mode == 0) {
  831. chro_rpt_lastl_ctrl = 1;
  832. luma0_rpt_loop_start = 0;
  833. luma0_rpt_loop_end = 0;
  834. chroma0_rpt_loop_start = 0;
  835. chroma0_rpt_loop_end = 0;
  836. luma0_rpt_loop_pat = 0x0;
  837. chroma0_rpt_loop_pat = 0x0;
  838. } else if (mif->set_separate_en == 0 && mif->src_field_mode == 1) {
  839. chro_rpt_lastl_ctrl = 1;
  840. luma0_rpt_loop_start = 1;
  841. luma0_rpt_loop_end = 1;
  842. chroma0_rpt_loop_start = 0;
  843. chroma0_rpt_loop_end = 0;
  844. luma0_rpt_loop_pat = 0x80;
  845. chroma0_rpt_loop_pat = 0x00;
  846. } else {
  847. chro_rpt_lastl_ctrl = 0;
  848. luma0_rpt_loop_start = 0;
  849. luma0_rpt_loop_end = 0;
  850. chroma0_rpt_loop_start = 0;
  851. chroma0_rpt_loop_end = 0;
  852. luma0_rpt_loop_pat = 0x00;
  853. chroma0_rpt_loop_pat = 0x00;
  854. }
  855. bytes_per_pixel = mif->set_separate_en ? 0 : (mif->video_mode ? 2 : 1);
  856. demux_mode = mif->video_mode;
  857. // ----------------------
  858. // General register
  859. // ----------------------
  860. WRITE_MPEG_REG(DI_MEM_GEN_REG,
  861. (urgent << 28) | // urgent bit.
  862. (urgent << 27) | // urgent bit.
  863. (1 << 25) | // no dummy data.
  864. (hold_line << 19) | // hold lines
  865. (1 << 18) | // push dummy pixel
  866. (demux_mode << 16) | // demux_mode
  867. (bytes_per_pixel << 14) |
  868. (mif->burst_size_cr << 12) |
  869. (mif->burst_size_cb << 10) |
  870. (mif->burst_size_y << 8) |
  871. (chro_rpt_lastl_ctrl << 6) |
  872. (mif->set_separate_en << 1) |
  873. (1 << 0) // cntl_enable
  874. );
  875. // ----------------------
  876. // Canvas
  877. // ----------------------
  878. WRITE_MPEG_REG(DI_MEM_CANVAS0, (mif->canvas0_addr2 << 16) | // cntl_canvas0_addr2
  879. (mif->canvas0_addr1 << 8) | // cntl_canvas0_addr1
  880. (mif->canvas0_addr0 << 0) // cntl_canvas0_addr0
  881. );
  882. // ----------------------
  883. // Picture 0 X/Y start,end
  884. // ----------------------
  885. WRITE_MPEG_REG(DI_MEM_LUMA_X0, (mif->luma_x_end0 << 16) | // cntl_luma_x_end0
  886. (mif->luma_x_start0 << 0) // cntl_luma_x_start0
  887. );
  888. WRITE_MPEG_REG(DI_MEM_LUMA_Y0, (mif->luma_y_end0 << 16) | // cntl_luma_y_end0
  889. (mif->luma_y_start0 << 0) // cntl_luma_y_start0
  890. );
  891. WRITE_MPEG_REG(DI_MEM_CHROMA_X0, (mif->chroma_x_end0 << 16) |
  892. (mif->chroma_x_start0 << 0)
  893. );
  894. WRITE_MPEG_REG(DI_MEM_CHROMA_Y0, (mif->chroma_y_end0 << 16) |
  895. (mif->chroma_y_start0 << 0)
  896. );
  897. // ----------------------
  898. // Repeat or skip
  899. // ----------------------
  900. WRITE_MPEG_REG(DI_MEM_RPT_LOOP, (0 << 28) |
  901. (0 << 24) |
  902. (0 << 20) |
  903. (0 << 16) |
  904. (chroma0_rpt_loop_start << 12) |
  905. (chroma0_rpt_loop_end << 8) |
  906. (luma0_rpt_loop_start << 4) |
  907. (luma0_rpt_loop_end << 0)
  908. ) ;
  909. WRITE_MPEG_REG(DI_MEM_LUMA0_RPT_PAT, luma0_rpt_loop_pat);
  910. WRITE_MPEG_REG(DI_MEM_CHROMA0_RPT_PAT, chroma0_rpt_loop_pat);
  911. // Dummy pixel value
  912. WRITE_MPEG_REG(DI_MEM_DUMMY_PIXEL, 0x00808000);
  913. if ((mif->set_separate_en == 1)) { // 4:2:0 block mode.
  914. set_di_mem_fmt_more(
  915. 1, // hfmt_en
  916. 1, // hz_yc_ratio
  917. 0, // hz_ini_phase
  918. 1, // vfmt_en
  919. 1, // vt_yc_ratio
  920. 0, // vt_ini_phase
  921. mif->luma_x_end0 - mif->luma_x_start0 + 1, // y_length
  922. mif->chroma_x_end0 - mif->chroma_x_start0 + 1, // c length
  923. 0); // hz repeat.
  924. } else {
  925. set_di_mem_fmt_more(
  926. 1, // hfmt_en
  927. 1, // hz_yc_ratio
  928. 0, // hz_ini_phase
  929. 0, // vfmt_en
  930. 0, // vt_yc_ratio
  931. 0, // vt_ini_phase
  932. mif->luma_x_end0 - mif->luma_x_start0 + 1, // y_length
  933. ((mif->luma_x_end0 >> 1) - (mif->luma_x_start0 >> 1) + 1), // c length
  934. 0); // hz repeat.
  935. }
  936. }
  937. void set_di_if1_fmt_more(int hfmt_en,
  938. int hz_yc_ratio, //2bit
  939. int hz_ini_phase, //4bit
  940. int vfmt_en,
  941. int vt_yc_ratio, //2bit
  942. int vt_ini_phase, //4bit
  943. int y_length,
  944. int c_length,
  945. int hz_rpt //1bit
  946. )
  947. {
  948. int vt_phase_step = (16 >> vt_yc_ratio);
  949. WRITE_MPEG_REG(DI_IF1_FMT_CTRL,
  950. (hz_rpt << 28) | //hz rpt pixel
  951. (hz_ini_phase << 24) | //hz ini phase
  952. (0 << 23) | //repeat p0 enable
  953. (hz_yc_ratio << 21) | //hz yc ratio
  954. (hfmt_en << 20) | //hz enable
  955. (1 << 17) | //nrpt_phase0 enable
  956. (0 << 16) | //repeat l0 enable
  957. (0 << 12) | //skip line num
  958. (vt_ini_phase << 8) | //vt ini phase
  959. (vt_phase_step << 1) | //vt phase step (3.4)
  960. (vfmt_en << 0) //vt enable
  961. );
  962. WRITE_MPEG_REG(DI_IF1_FMT_W, (y_length << 16) | //hz format width
  963. (c_length << 0) //vt format width
  964. );
  965. }
  966. void set_di_if1_mif(DI_MIF_t *mif, int urgent, int hold_line)
  967. {
  968. unsigned long bytes_per_pixel;
  969. unsigned long demux_mode;
  970. unsigned long chro_rpt_lastl_ctrl;
  971. unsigned long luma0_rpt_loop_start;
  972. unsigned long luma0_rpt_loop_end;
  973. unsigned long luma0_rpt_loop_pat;
  974. unsigned long chroma0_rpt_loop_start;
  975. unsigned long chroma0_rpt_loop_end;
  976. unsigned long chroma0_rpt_loop_pat;
  977. if (mif->set_separate_en == 1 && mif->src_field_mode == 1) {
  978. chro_rpt_lastl_ctrl = 1;
  979. luma0_rpt_loop_start = 1;
  980. luma0_rpt_loop_end = 1;
  981. chroma0_rpt_loop_start = 1;
  982. chroma0_rpt_loop_end = 1;
  983. luma0_rpt_loop_pat = 0x80;
  984. chroma0_rpt_loop_pat = 0x80;
  985. } else if (mif->set_separate_en == 1 && mif->src_field_mode == 0) {
  986. chro_rpt_lastl_ctrl = 1;
  987. luma0_rpt_loop_start = 0;
  988. luma0_rpt_loop_end = 0;
  989. chroma0_rpt_loop_start = 0;
  990. chroma0_rpt_loop_end = 0;
  991. luma0_rpt_loop_pat = 0x0;
  992. chroma0_rpt_loop_pat = 0x0;
  993. } else if (mif->set_separate_en == 0 && mif->src_field_mode == 1) {
  994. chro_rpt_lastl_ctrl = 1;
  995. luma0_rpt_loop_start = 1;
  996. luma0_rpt_loop_end = 1;
  997. chroma0_rpt_loop_start = 0;
  998. chroma0_rpt_loop_end = 0;
  999. luma0_rpt_loop_pat = 0x80;
  1000. chroma0_rpt_loop_pat = 0x00;
  1001. } else {
  1002. chro_rpt_lastl_ctrl = 0;
  1003. luma0_rpt_loop_start = 0;
  1004. luma0_rpt_loop_end = 0;
  1005. chroma0_rpt_loop_start = 0;
  1006. chroma0_rpt_loop_end = 0;
  1007. luma0_rpt_loop_pat = 0x00;
  1008. chroma0_rpt_loop_pat = 0x00;
  1009. }
  1010. bytes_per_pixel = mif->set_separate_en ? 0 : (mif->video_mode ? 2 : 1);
  1011. demux_mode = mif->video_mode;
  1012. // ----------------------
  1013. // General register
  1014. // ----------------------
  1015. WRITE_MPEG_REG(DI_IF1_GEN_REG, (urgent << 28) | // urgent
  1016. (urgent << 27) | // luma urgent
  1017. (1 << 25) | // no dummy data.
  1018. (hold_line << 19) | // hold lines
  1019. (1 << 18) | // push dummy pixel
  1020. (demux_mode << 16) | // demux_mode
  1021. (bytes_per_pixel << 14) |
  1022. (mif->burst_size_cr << 12) |
  1023. (mif->burst_size_cb << 10) |
  1024. (mif->burst_size_y << 8) |
  1025. (chro_rpt_lastl_ctrl << 6) |
  1026. (mif->set_separate_en << 1) |
  1027. (1 << 0) // cntl_enable
  1028. );
  1029. // ----------------------
  1030. // Canvas
  1031. // ----------------------
  1032. WRITE_MPEG_REG(DI_IF1_CANVAS0, (mif->canvas0_addr2 << 16) | // cntl_canvas0_addr2
  1033. (mif->canvas0_addr1 << 8) | // cntl_canvas0_addr1
  1034. (mif->canvas0_addr0 << 0) // cntl_canvas0_addr0
  1035. );
  1036. // ----------------------
  1037. // Picture 0 X/Y start,end
  1038. // ----------------------
  1039. WRITE_MPEG_REG(DI_IF1_LUMA_X0, (mif->luma_x_end0 << 16) | // cntl_luma_x_end0
  1040. (mif->luma_x_start0 << 0) // cntl_luma_x_start0
  1041. );
  1042. WRITE_MPEG_REG(DI_IF1_LUMA_Y0, (mif->luma_y_end0 << 16) | // cntl_luma_y_end0
  1043. (mif->luma_y_start0 << 0) // cntl_luma_y_start0
  1044. );
  1045. WRITE_MPEG_REG(DI_IF1_CHROMA_X0, (mif->chroma_x_end0 << 16) |
  1046. (mif->chroma_x_start0 << 0)
  1047. );
  1048. WRITE_MPEG_REG(DI_IF1_CHROMA_Y0, (mif->chroma_y_end0 << 16) |
  1049. (mif->chroma_y_start0 << 0)
  1050. );
  1051. // ----------------------
  1052. // Repeat or skip
  1053. // ----------------------
  1054. WRITE_MPEG_REG(DI_IF1_RPT_LOOP, (0 << 28) |
  1055. (0 << 24) |
  1056. (0 << 20) |
  1057. (0 << 16) |
  1058. (chroma0_rpt_loop_start << 12) |
  1059. (chroma0_rpt_loop_end << 8) |
  1060. (luma0_rpt_loop_start << 4) |
  1061. (luma0_rpt_loop_end << 0)
  1062. ) ;
  1063. WRITE_MPEG_REG(DI_IF1_LUMA0_RPT_PAT, luma0_rpt_loop_pat);
  1064. WRITE_MPEG_REG(DI_IF1_CHROMA0_RPT_PAT, chroma0_rpt_loop_pat);
  1065. // Dummy pixel value
  1066. WRITE_MPEG_REG(DI_IF1_DUMMY_PIXEL, 0x00808000);
  1067. if ((mif->set_separate_en == 1)) { // 4:2:0 block mode.
  1068. set_di_if1_fmt_more(
  1069. 1, // hfmt_en
  1070. 1, // hz_yc_ratio
  1071. 0, // hz_ini_phase
  1072. 1, // vfmt_en
  1073. 1, // vt_yc_ratio
  1074. 0, // vt_ini_phase
  1075. mif->luma_x_end0 - mif->luma_x_start0 + 1, // y_length
  1076. mif->chroma_x_end0 - mif->chroma_x_start0 + 1 , // c length
  1077. 0); // hz repeat.
  1078. } else {
  1079. set_di_if1_fmt_more(
  1080. 1, // hfmt_en
  1081. 1, // hz_yc_ratio
  1082. 0, // hz_ini_phase
  1083. 0, // vfmt_en
  1084. 0, // vt_yc_ratio
  1085. 0, // vt_ini_phase
  1086. mif->luma_x_end0 - mif->luma_x_start0 + 1, // y_length
  1087. ((mif->luma_x_end0 >> 1) - (mif->luma_x_start0 >> 1) + 1), // c length
  1088. 0); // hz repeat.
  1089. }
  1090. }
  1091. void set_di_chan2_mif(DI_MIF_t *mif, int urgent, int hold_line)
  1092. {
  1093. unsigned long bytes_per_pixel;
  1094. unsigned long demux_mode;
  1095. unsigned long luma0_rpt_loop_start;
  1096. unsigned long luma0_rpt_loop_end;
  1097. unsigned long luma0_rpt_loop_pat;
  1098. bytes_per_pixel = mif->set_separate_en ? 0 : ((mif->video_mode == 1) ? 2 : 1);
  1099. demux_mode = mif->video_mode & 1;
  1100. if (mif->src_field_mode == 1) {
  1101. luma0_rpt_loop_start = 1;
  1102. luma0_rpt_loop_end = 1;
  1103. luma0_rpt_loop_pat = 0x80;
  1104. } else {
  1105. luma0_rpt_loop_start = 0;
  1106. luma0_rpt_loop_end = 0;
  1107. luma0_rpt_loop_pat = 0;
  1108. }
  1109. // ----------------------
  1110. // General register
  1111. // ----------------------
  1112. WRITE_MPEG_REG(DI_CHAN2_GEN_REG, (urgent << 28) | // urgent
  1113. (urgent << 27) | // luma urgent
  1114. (1 << 25) | // no dummy data.
  1115. (hold_line << 19) | // hold lines
  1116. (1 << 18) | // push dummy pixel
  1117. (demux_mode << 16) | // demux_mode
  1118. (bytes_per_pixel << 14) |
  1119. (0 << 12) |
  1120. (0 << 10) |
  1121. (mif->burst_size_y << 8) |
  1122. ((hold_line == 0 ? 1 : 0) << 7) | //manual start.
  1123. (0 << 6) |
  1124. (0 << 1) |
  1125. (1 << 0) // cntl_enable
  1126. );
  1127. // ----------------------
  1128. // Canvas
  1129. // ----------------------
  1130. WRITE_MPEG_REG(DI_CHAN2_CANVAS, (0 << 16) | // cntl_canvas0_addr2
  1131. (0 << 8) | // cntl_canvas0_addr1
  1132. (mif->canvas0_addr0 << 0) // cntl_canvas0_addr0
  1133. );
  1134. // ----------------------
  1135. // Picture 0 X/Y start,end
  1136. // ----------------------
  1137. WRITE_MPEG_REG(DI_CHAN2_LUMA_X, (mif->luma_x_end0 << 16) | // cntl_luma_x_end0
  1138. (mif->luma_x_start0 << 0) // cntl_luma_x_start0
  1139. );
  1140. WRITE_MPEG_REG(DI_CHAN2_LUMA_Y, (mif->luma_y_end0 << 16) | // cntl_luma_y_end0
  1141. (mif->luma_y_start0 << 0) // cntl_luma_y_start0
  1142. );
  1143. // ----------------------
  1144. // Repeat or skip
  1145. // ----------------------
  1146. WRITE_MPEG_REG(DI_CHAN2_RPT_LOOP, (0 << 28) |
  1147. (0 << 24) |
  1148. (0 << 20) |
  1149. (0 << 16) |
  1150. (0 << 12) |
  1151. (0 << 8) |
  1152. (luma0_rpt_loop_start << 4) |
  1153. (luma0_rpt_loop_end << 0)
  1154. );
  1155. WRITE_MPEG_REG(DI_CHAN2_LUMA_RPT_PAT, luma0_rpt_loop_pat);
  1156. // Dummy pixel value
  1157. WRITE_MPEG_REG(DI_CHAN2_DUMMY_PIXEL, 0x00808000);
  1158. }
  1159. void set_di_if0_mif(DI_MIF_t *mif, int urgent, int hold_line)
  1160. {
  1161. unsigned long bytes_per_pixel;
  1162. unsigned long demux_mode;
  1163. unsigned long chro_rpt_lastl_ctrl;
  1164. unsigned long luma0_rpt_loop_start;
  1165. unsigned long luma0_rpt_loop_end;
  1166. unsigned long luma0_rpt_loop_pat;
  1167. unsigned long chroma0_rpt_loop_start;
  1168. unsigned long chroma0_rpt_loop_end;
  1169. unsigned long chroma0_rpt_loop_pat;
  1170. if (mif->set_separate_en == 1 && mif->src_field_mode == 1) {
  1171. chro_rpt_lastl_ctrl = 1;
  1172. luma0_rpt_loop_start = 1;
  1173. luma0_rpt_loop_end = 1;
  1174. chroma0_rpt_loop_start = 1;
  1175. chroma0_rpt_loop_end = 1;
  1176. luma0_rpt_loop_pat = 0x80;
  1177. chroma0_rpt_loop_pat = 0x80;
  1178. } else if (mif->set_separate_en == 1 && mif->src_field_mode == 0) {
  1179. chro_rpt_lastl_ctrl = 1;
  1180. luma0_rpt_loop_start = 0;
  1181. luma0_rpt_loop_end = 0;
  1182. chroma0_rpt_loop_start = 0;
  1183. chroma0_rpt_loop_end = 0;
  1184. luma0_rpt_loop_pat = 0x0;
  1185. chroma0_rpt_loop_pat = 0x0;
  1186. } else if (mif->set_separate_en == 0 && mif->src_field_mode == 1) {
  1187. chro_rpt_lastl_ctrl = 1;
  1188. luma0_rpt_loop_start = 1;
  1189. luma0_rpt_loop_end = 1;
  1190. chroma0_rpt_loop_start = 0;
  1191. chroma0_rpt_loop_end = 0;
  1192. luma0_rpt_loop_pat = 0x80;
  1193. chroma0_rpt_loop_pat = 0x00;
  1194. } else {
  1195. chro_rpt_lastl_ctrl = 0;
  1196. luma0_rpt_loop_start = 0;
  1197. luma0_rpt_loop_end = 0;
  1198. chroma0_rpt_loop_start = 0;
  1199. chroma0_rpt_loop_end = 0;
  1200. luma0_rpt_loop_pat = 0x00;
  1201. chroma0_rpt_loop_pat = 0x00;
  1202. }
  1203. bytes_per_pixel = mif->set_separate_en ? 0 : (mif->video_mode ? 2 : 1);
  1204. demux_mode = mif->video_mode;
  1205. // ----------------------
  1206. // General register
  1207. // ----------------------
  1208. WRITE_MPEG_REG(VD1_IF0_GEN_REG, (urgent << 28) | // urgent
  1209. (urgent << 27) | // luma urgent
  1210. (1 << 25) | // no dummy data.
  1211. (hold_line << 19) | // hold lines
  1212. (1 << 18) | // push dummy pixel
  1213. (demux_mode << 16) | // demux_mode
  1214. (bytes_per_pixel << 14) |
  1215. (mif->burst_size_cr << 12) |
  1216. (mif->burst_size_cb << 10) |
  1217. (mif->burst_size_y << 8) |
  1218. (chro_rpt_lastl_ctrl << 6) |
  1219. (mif->set_separate_en << 1) |
  1220. (1 << 0) // cntl_enable
  1221. );
  1222. // ----------------------
  1223. // Canvas
  1224. // ----------------------
  1225. WRITE_MPEG_REG(VD1_IF0_CANVAS0, (mif->canvas0_addr2 << 16) | // cntl_canvas0_addr2
  1226. (mif->canvas0_addr1 << 8) | // cntl_canvas0_addr1
  1227. (mif->canvas0_addr0 << 0) // cntl_canvas0_addr0
  1228. );
  1229. // ----------------------
  1230. // Picture 0 X/Y start,end
  1231. // ----------------------
  1232. WRITE_MPEG_REG(VD1_IF0_LUMA_X0, (mif->luma_x_end0 << 16) | // cntl_luma_x_end0
  1233. (mif->luma_x_start0 << 0) // cntl_luma_x_start0
  1234. );
  1235. WRITE_MPEG_REG(VD1_IF0_LUMA_Y0, (mif->luma_y_end0 << 16) | // cntl_luma_y_end0
  1236. (mif->luma_y_start0 << 0) // cntl_luma_y_start0
  1237. );
  1238. WRITE_MPEG_REG(VD1_IF0_CHROMA_X0, (mif->chroma_x_end0 << 16) |
  1239. (mif->chroma_x_start0 << 0)
  1240. );
  1241. WRITE_MPEG_REG(VD1_IF0_CHROMA_Y0, (mif->chroma_y_end0 << 16) |
  1242. (mif->chroma_y_start0 << 0)
  1243. );
  1244. // ----------------------
  1245. // Repeat or skip
  1246. // ----------------------
  1247. WRITE_MPEG_REG(VD1_IF0_RPT_LOOP, (0 << 28) |
  1248. (0 << 24) |
  1249. (0 << 20) |
  1250. (0 << 16) |
  1251. (chroma0_rpt_loop_start << 12) |
  1252. (chroma0_rpt_loop_end << 8) |
  1253. (luma0_rpt_loop_start << 4) |
  1254. (luma0_rpt_loop_end << 0)
  1255. ) ;
  1256. WRITE_MPEG_REG(VD1_IF0_LUMA0_RPT_PAT, luma0_rpt_loop_pat);
  1257. WRITE_MPEG_REG(VD1_IF0_CHROMA0_RPT_PAT, chroma0_rpt_loop_pat);
  1258. // Dummy pixel value
  1259. WRITE_MPEG_REG(VD1_IF0_DUMMY_PIXEL, 0x00808000);
  1260. // ----------------------
  1261. // Picture 1 unused
  1262. // ----------------------
  1263. WRITE_MPEG_REG(VD1_IF0_LUMA_X1, 0); // unused
  1264. WRITE_MPEG_REG(VD1_IF0_LUMA_Y1, 0); // unused
  1265. WRITE_MPEG_REG(VD1_IF0_CHROMA_X1, 0); // unused
  1266. WRITE_MPEG_REG(VD1_IF0_CHROMA_Y1, 0); // unused
  1267. WRITE_MPEG_REG(VD1_IF0_LUMA_PSEL, 0); // unused only one picture
  1268. WRITE_MPEG_REG(VD1_IF0_CHROMA_PSEL, 0); // unused only one picture
  1269. if ((mif->set_separate_en == 1)) { // 4:2:0 block mode.
  1270. set_vd1_fmt_more(
  1271. 1, // hfmt_en
  1272. 1, // hz_yc_ratio
  1273. 0, // hz_ini_phase
  1274. 1, // vfmt_en
  1275. 1, // vt_yc_ratio
  1276. 0, // vt_ini_phase
  1277. mif->luma_x_end0 - mif->luma_x_start0 + 1, // y_length
  1278. mif->chroma_x_end0 - mif->chroma_x_start0 + 1 , // c length
  1279. 0); // hz repeat.
  1280. } else {
  1281. set_vd1_fmt_more(
  1282. 1, // hfmt_en
  1283. 1, // hz_yc_ratio
  1284. 0, // hz_ini_phase
  1285. 0, // vfmt_en
  1286. 0, // vt_yc_ratio
  1287. 0, // vt_ini_phase
  1288. mif->luma_x_end0 - mif->luma_x_start0 + 1, // y_length
  1289. ((mif->luma_x_end0 >> 1) - (mif->luma_x_start0 >> 1) + 1) , //c length
  1290. 0); // hz repeat.
  1291. }
  1292. }
  1293. //enable deinterlace pre module separated for pre post separate tests.
  1294. void enable_di_pre(
  1295. DI_MIF_t *di_inp_mif,
  1296. DI_MIF_t *di_mem_mif,
  1297. DI_MIF_t *di_chan2_mif,
  1298. DI_SIM_MIF_t *di_nrwr_mif,
  1299. DI_SIM_MIF_t *di_mtnwr_mif,
  1300. int nr_en, int mtn_en, int pd32_check_en, int pd22_check_en, int hist_check_en,
  1301. #if defined(CONFIG_ARCH_MESON)
  1302. #elif defined(CONFIG_ARCH_MESON2)
  1303. int nr_hfilt_en, int nr_hfilt_mb_en, int mtn_modify_en,
  1304. #endif
  1305. int pre_field_num, int pre_viu_link, int hold_line)
  1306. {
  1307. int hist_check_only;
  1308. #if defined(CONFIG_ARCH_MESON2)
  1309. int nr_zone_0, nr_zone_1, nr_zone_2;
  1310. if (noise_reduction_level == 0) {
  1311. nr_zone_0 = 1;
  1312. nr_zone_1 = 3;
  1313. nr_zone_2 = 5;
  1314. } else {
  1315. nr_zone_0 = 3;
  1316. nr_zone_1 = 6;
  1317. nr_zone_2 = 10;
  1318. }
  1319. #endif
  1320. hist_check_only = hist_check_en && !nr_en && !mtn_en && !pd22_check_en && !pd32_check_en ;
  1321. if (nr_en | mtn_en | pd22_check_en || pd32_check_en) {
  1322. set_di_mem_mif(di_mem_mif, 0, hold_line); // set urgent 0
  1323. if (!vdin_en) {
  1324. set_di_inp_mif(di_inp_mif, 0, hold_line); // set urgent 0
  1325. }
  1326. }
  1327. if (pd22_check_en || hist_check_only) {
  1328. set_di_chan2_mif(di_chan2_mif, 0, hold_line); // set urgent 0.
  1329. }
  1330. // set nr wr mif interface.
  1331. if (nr_en) {
  1332. WRITE_MPEG_REG(DI_NRWR_X, (di_nrwr_mif->start_x << 16) | (di_nrwr_mif->end_x)); // start_x 0 end_x 719.
  1333. WRITE_MPEG_REG(DI_NRWR_Y, (di_nrwr_mif->start_y << 16) | (di_nrwr_mif->end_y)); // start_y 0 end_y 239.
  1334. WRITE_MPEG_REG(DI_NRWR_CTRL, di_nrwr_mif->canvas_num); // canvas index.
  1335. #if defined(CONFIG_ARCH_MESON)
  1336. #elif defined(CONFIG_ARCH_MESON2)
  1337. WRITE_MPEG_REG(DI_NR_CTRL0, (1 << 31) | // nr yuv enable.
  1338. (1 << 30) | // nr range. 3 point
  1339. (0 << 29) | // max of 3 point.
  1340. (nr_hfilt_en << 28) | // nr hfilter enable.
  1341. (nr_hfilt_mb_en << 27) | // nr hfilter motion_blur enable.
  1342. (nr_zone_2 << 16) | // zone 2
  1343. (nr_zone_1 << 8) | // zone 1
  1344. (nr_zone_0 << 0)); // zone 0
  1345. WRITE_MPEG_REG(DI_NR_CTRL2, (10 << 24) | //intra noise level
  1346. (1 << 16) | // intra no noise level.
  1347. (10 << 8) | // inter noise level.
  1348. (1 << 0)); // inter no noise level.
  1349. WRITE_MPEG_REG(DI_NR_CTRL3, (16 << 16) | // if any one of 3 point mtn larger than 16 don't use 3 point.
  1350. 720); // if one line eq cnt is larger than this number, this line is not conunted.
  1351. #endif
  1352. }
  1353. // motion wr mif.
  1354. if (mtn_en) {
  1355. WRITE_MPEG_REG(DI_MTNWR_X, (di_mtnwr_mif->start_x << 16) | (di_mtnwr_mif->end_x)); // start_x 0 end_x 719.
  1356. WRITE_MPEG_REG(DI_MTNWR_Y, (di_mtnwr_mif->start_y << 16) | (di_mtnwr_mif->end_y)); // start_y 0 end_y 239.
  1357. WRITE_MPEG_REG(DI_MTNWR_CTRL, di_mtnwr_mif->canvas_num | // canvas index.
  1358. (0 << 8)); // urgent.
  1359. #if defined(CONFIG_ARCH_MESON)
  1360. #elif defined(CONFIG_ARCH_MESON2)
  1361. WRITE_MPEG_REG(DI_MTN_CTRL, (1 << 31) | // lpf enable.
  1362. (1 << 30) | // mtn uv enable.
  1363. (mtn_modify_en << 29) | // no mtn modify.
  1364. (2 << 24) | // char diff count.
  1365. (40 << 16) | // black level.
  1366. (196 << 8) | // white level.
  1367. (64 << 0)); // char diff level.
  1368. WRITE_MPEG_REG(DI_MTN_CTRL1, (3 << 8) | // mtn shift if mtn modifty_en
  1369. 0); // mtn reduce before shift.
  1370. #endif
  1371. }
  1372. // reset pre
  1373. WRITE_MPEG_REG(DI_PRE_CTRL, READ_MPEG_REG(DI_PRE_CTRL) |
  1374. 1 << 31); // frame reset for the pre modules.
  1375. #if defined(CONFIG_ARCH_MESON)
  1376. WRITE_MPEG_REG(DI_PRE_CTRL, nr_en | // NR enable
  1377. (mtn_en << 1) | // MTN_EN
  1378. (pd32_check_en << 2) | // check 3:2 pulldown
  1379. (pd22_check_en << 3) | // check 2:2 pulldown
  1380. (1 << 4) | // 2:2 check mid pixel come from next field after MTN.
  1381. (hist_check_en << 5) | // hist check enable
  1382. (hist_check_only << 6) | // hist check use chan2.
  1383. ((!nr_en) << 7) | // hist check use data before noise reduction.
  1384. ((pd22_check_en || hist_check_only) << 8) | // chan 2 enable for 2:2 pull down check.
  1385. (pd22_check_en << 9) | // line buffer 2 enable
  1386. (0 << 10) | // pre drop first.
  1387. (0 << 11) | // pre repeat.
  1388. (0 << 12) | // pre viu link
  1389. (hold_line << 16) | // pre hold line number
  1390. (pre_field_num << 29) | // pre field number.
  1391. (0x1 << 30) // pre soft rst, pre frame rst.
  1392. );
  1393. #elif defined(CONFIG_ARCH_MESON2)
  1394. WRITE_MPEG_REG(DI_PRE_CTRL, nr_en | // NR enable
  1395. (mtn_en << 1) | // MTN_EN
  1396. (pd32_check_en << 2) | // check 3:2 pulldown
  1397. (pd22_check_en << 3) | // check 2:2 pulldown
  1398. (1 << 4) | // 2:2 check mid pixel come from next field after MTN.
  1399. (hist_check_en << 5) | // hist check enable
  1400. (1 << 6) | // hist check use chan2.
  1401. ((!nr_en) << 7) | // hist check use data before noise reduction.
  1402. ((pd22_check_en || hist_check_only) << 8) | // chan 2 enable for 2:2 pull down check.
  1403. (pd22_check_en << 9) | // line buffer 2 enable
  1404. (0 << 10) | // pre drop first.
  1405. (0 << 11) | // pre repeat.
  1406. (0 << 12) | // pre viu link
  1407. (hold_line << 16) | // pre hold line number
  1408. (1 << 22) | // MTN after NR.
  1409. (pre_field_num << 29) | // pre field number.
  1410. (0x1 << 30) // pre soft rst, pre frame rst.
  1411. );
  1412. #endif
  1413. }
  1414. // enable di post module for separate test.
  1415. void enable_di_post(
  1416. DI_MIF_t *di_buf0_mif,
  1417. DI_MIF_t *di_buf1_mif,
  1418. DI_SIM_MIF_t *di_diwr_mif,
  1419. DI_SIM_MIF_t *di_mtncrd_mif,
  1420. DI_SIM_MIF_t *di_mtnprd_mif,
  1421. int ei_en, int blend_en, int blend_mtn_en, int blend_mode, int di_vpp_en, int di_ddr_en,
  1422. #if defined(CONFIG_ARCH_MESON)
  1423. #elif defined(CONFIG_ARCH_MESON2)
  1424. int blend_mtn_filt_en, int blend_data_filt_en, int post_mb_en,
  1425. #endif
  1426. int post_field_num, int hold_line)
  1427. {
  1428. int ei_only;
  1429. int buf1_en;
  1430. ei_only = ei_en && !blend_en && (di_vpp_en || di_ddr_en);
  1431. buf1_en = (!ei_only && (di_ddr_en || di_vpp_en));
  1432. if (ei_en || di_vpp_en || di_ddr_en) {
  1433. set_di_if0_mif(di_buf0_mif, di_vpp_en, hold_line);
  1434. }
  1435. if (!ei_only && (di_ddr_en || di_vpp_en)) {
  1436. set_di_if1_mif(di_buf1_mif, di_vpp_en, hold_line);
  1437. }
  1438. // motion for current display field.
  1439. if (blend_mtn_en) {
  1440. WRITE_MPEG_REG(DI_MTNPRD_X, (di_mtnprd_mif->start_x << 16) | (di_mtnprd_mif->end_x)); // start_x 0 end_x 719.
  1441. WRITE_MPEG_REG(DI_MTNPRD_Y, (di_mtnprd_mif->start_y << 16) | (di_mtnprd_mif->end_y)); // start_y 0 end_y 239.
  1442. WRITE_MPEG_REG(DI_MTNCRD_X, (di_mtncrd_mif->start_x << 16) | (di_mtncrd_mif->end_x)); // start_x 0 end_x 719.
  1443. WRITE_MPEG_REG(DI_MTNCRD_Y, (di_mtncrd_mif->start_y << 16) | (di_mtncrd_mif->end_y)); // start_y 0 end_y 239.
  1444. WRITE_MPEG_REG(DI_MTNRD_CTRL, (di_mtnprd_mif->canvas_num << 8) | //mtnp canvas index.
  1445. (1 << 16) | // urgent
  1446. di_mtncrd_mif->canvas_num); // current field mtn canvas index.
  1447. }
  1448. if (di_ddr_en) {
  1449. WRITE_MPEG_REG(DI_DIWR_X, (di_diwr_mif->start_x << 16) | (di_diwr_mif->end_x)); // start_x 0 end_x 719.
  1450. WRITE_MPEG_REG(DI_DIWR_Y, (di_diwr_mif->start_y << 16) | (di_diwr_mif->end_y * 2 + 1)); // start_y 0 end_y 479.
  1451. WRITE_MPEG_REG(DI_DIWR_CTRL, di_diwr_mif->canvas_num | // canvas index.
  1452. (di_vpp_en << 8)); // urgent.
  1453. }
  1454. if (ei_only == 0) {
  1455. #if defined(CONFIG_ARCH_MESON)
  1456. WRITE_MPEG_REG(DI_BLEND_CTRL, (READ_MPEG_REG(DI_BLEND_CTRL) & (~((1 << 25) | (3 << 20)))) | // clean some bit we need to set.
  1457. (blend_mtn_en << 26) | // blend mtn enable.
  1458. (0 << 25) | // blend with the mtn of the pre display field and next display field.
  1459. (1 << 24) | // blend with pre display field.
  1460. (blend_mode << 20) // motion adaptive blend.
  1461. );
  1462. #elif defined(CONFIG_ARCH_MESON2)
  1463. WRITE_MPEG_REG(DI_BLEND_CTRL, (post_mb_en << 28) | // post motion blur enable.
  1464. (0 << 27) | // mtn3p(l, c, r) max.
  1465. (0 << 26) | // mtn3p(l, c, r) min.
  1466. (0 << 25) | // mtn3p(l, c, r) ave.
  1467. (1 << 24) | // mtntopbot max
  1468. (blend_mtn_filt_en << 23) | // blend mtn filter enable.
  1469. (blend_data_filt_en << 22) | // blend data filter enable.
  1470. (blend_mode << 20) | // motion adaptive blend.
  1471. 25 // kdeint.
  1472. );
  1473. WRITE_MPEG_REG(DI_BLEND_CTRL1, (196 << 24) | // char level
  1474. (64 << 16) | // angle thredhold.
  1475. (40 << 8) | // all_af filt thd.
  1476. (64)); // all 4 equal
  1477. WRITE_MPEG_REG(DI_BLEND_CTRL2, (4 << 8) | // mtn no mov level.
  1478. (48)); //black level.
  1479. #endif
  1480. }
  1481. #if defined(CONFIG_ARCH_MESON)
  1482. WRITE_MPEG_REG(DI_POST_CTRL, ((ei_en | blend_en) << 0) | // line buffer 0 enable
  1483. (0 << 1) | // line buffer 1 enable
  1484. (ei_en << 2) | // ei enable
  1485. (blend_mtn_en << 3) | // mtn line buffer enable
  1486. (blend_mtn_en << 4) | // mtnp read mif enable
  1487. (blend_en << 5) | // di blend enble.
  1488. (1 << 6) | // di mux output enable
  1489. (di_ddr_en << 7) | // di write to SDRAM enable.
  1490. (di_vpp_en << 8) | // di to VPP enable.
  1491. (0 << 9) | // mif0 to VPP enable.
  1492. (0 << 10) | // post drop first.
  1493. (0 << 11) | // post repeat.
  1494. (1 << 12) | // post viu link
  1495. (hold_line << 16) | // post hold line number
  1496. (post_field_num << 29) | // post field number.
  1497. (0x1 << 30) // post soft rst post frame rst.
  1498. );
  1499. #elif defined(CONFIG_ARCH_MESON2)
  1500. WRITE_MPEG_REG(DI_POST_CTRL, ((ei_en | blend_en) << 0) | // line buffer 0 enable
  1501. (0 << 1) | // line buffer 1 enable
  1502. (ei_en << 2) | // ei enable
  1503. (blend_mtn_en << 3) | // mtn line buffer enable
  1504. (blend_mtn_en << 4) | // mtnp read mif enable
  1505. (blend_en << 5) | // di blend enble.
  1506. (1 << 6) | // di mux output enable
  1507. (di_ddr_en << 7) | // di write to SDRAM enable.
  1508. (di_vpp_en << 8) | // di to VPP enable.
  1509. (0 << 9) | // mif0 to VPP enable.
  1510. (0 << 10) | // post drop first.
  1511. (0 << 11) | // post repeat.
  1512. (di_vpp_en << 12) | // post viu link
  1513. (hold_line << 16) | // post hold line number
  1514. (post_field_num << 29) | // post field number.
  1515. (0x1 << 30) // post soft rst post frame rst.
  1516. );
  1517. #endif
  1518. }
  1519. int di_pre_mode_check(int cur_field)
  1520. {
  1521. int i;
  1522. WRITE_MPEG_REG(DI_INFO_ADDR, 0);
  1523. for (i = 0; i <= 68; i++) {
  1524. di_info[cur_field][i] = READ_MPEG_REG(DI_INFO_DATA);
  1525. }
  1526. #if defined(CONFIG_ARCH_MESON)
  1527. #elif defined(CONFIG_ARCH_MESON2)
  1528. WRITE_MPEG_REG(DI_INFO_ADDR, 77);
  1529. for (i = 77; i <= 82; i++) {
  1530. di_info[cur_field][i] = READ_MPEG_REG(DI_INFO_DATA);
  1531. }
  1532. #endif
  1533. return (0);
  1534. }
  1535. int di_post_mode_check(int cur_field)
  1536. {
  1537. int i;
  1538. WRITE_MPEG_REG(DI_INFO_ADDR, 69);
  1539. for (i = 69; i <= 76; i++) {
  1540. di_info[cur_field][i] = READ_MPEG_REG(DI_INFO_DATA);
  1541. }
  1542. return (0);
  1543. }
  1544. void enable_region_blend(
  1545. int reg0_en, int reg0_start_x, int reg0_end_x, int reg0_start_y, int reg0_end_y, int reg0_mode,
  1546. int reg1_en, int reg1_start_x, int reg1_end_x, int reg1_start_y, int reg1_end_y, int reg1_mode,
  1547. int reg2_en, int reg2_start_x, int reg2_end_x, int reg2_start_y, int reg2_end_y, int reg2_mode,
  1548. int reg3_en, int reg3_start_x, int reg3_end_x, int reg3_start_y, int reg3_end_y, int reg3_mode)
  1549. {
  1550. WRITE_MPEG_REG(DI_BLEND_REG0_X, (reg0_start_x << 16) |
  1551. reg0_end_x);
  1552. WRITE_MPEG_REG(DI_BLEND_REG0_Y, (reg0_start_y << 16) |
  1553. reg0_end_y);
  1554. WRITE_MPEG_REG(DI_BLEND_REG1_X, (reg1_start_x << 16) |
  1555. reg1_end_x);
  1556. WRITE_MPEG_REG(DI_BLEND_REG1_Y, (reg1_start_y << 16) |
  1557. reg1_end_y);
  1558. WRITE_MPEG_REG(DI_BLEND_REG2_X, (reg2_start_x << 16) |
  1559. reg2_end_x);
  1560. WRITE_MPEG_REG(DI_BLEND_REG2_Y, (reg2_start_y << 16) |
  1561. reg2_end_y);
  1562. WRITE_MPEG_REG(DI_BLEND_REG3_X, (reg3_start_x << 16) |
  1563. reg3_end_x);
  1564. WRITE_MPEG_REG(DI_BLEND_REG3_Y, (reg3_start_y << 16) |
  1565. reg3_end_y);
  1566. WRITE_MPEG_REG(DI_BLEND_CTRL, (READ_MPEG_REG(DI_BLEND_CTRL) & (~(0xfff << 8))) |
  1567. (reg0_mode << 8) |
  1568. (reg1_mode << 10) |
  1569. (reg2_mode << 12) |
  1570. (reg3_mode << 14) |
  1571. (reg0_en << 16) |
  1572. (reg1_en << 17) |
  1573. (reg2_en << 18) |
  1574. (reg3_en << 19));
  1575. }
  1576. int check_p32_p22(int cur_field, int pre_field, int pre2_field)
  1577. {
  1578. unsigned int cur_data, pre_data, pre2_data;
  1579. unsigned int cur_num, pre_num, pre2_num;
  1580. unsigned int data_diff, num_diff;
  1581. di_p22_info = di_p22_info << 1;
  1582. cur_data = di_info[cur_field][2];
  1583. pre_data = di_info[pre_field][2];
  1584. pre2_data = di_info[pre2_field][2];
  1585. cur_num = di_info[cur_field][4] & 0xffffff;
  1586. pre_num = di_info[pre_field][4] & 0xffffff;
  1587. pre2_num = di_info[pre2_field][4] & 0xffffff;
  1588. if (cur_data * 2 <= pre_data && pre2_data * 2 <= pre_data && cur_num * 2 <= pre_num && pre2_num * 2 <= pre_num) {
  1589. di_p22_info |= 1;
  1590. }
  1591. di_p32_info = di_p32_info << 1;
  1592. di_p32_info_2 = di_p32_info_2 << 1;
  1593. di_p22_info_2 = di_p22_info_2 << 1;
  1594. cur_data = di_info[cur_field][0];
  1595. cur_num = di_info[cur_field][1] & 0xffffff;
  1596. pre_data = di_info[pre_field][0];
  1597. pre_num = di_info[pre_field][1] & 0xffffff;
  1598. data_diff = cur_data > pre_data ? cur_data - pre_data : pre_data - cur_data;
  1599. num_diff = cur_num > pre_num ? cur_num - pre_num : pre_num - cur_num;
  1600. if ((di_p22_info & 0x1) && data_diff * 10 <= cur_data && num_diff * 10 <= cur_num) {
  1601. di_p22_info_2 |= 1;
  1602. }
  1603. if (di_p32_counter > 0 || di_p32_info == 0) {
  1604. if (cur_data * 2 <= pre_data && cur_num * 50 <= pre_num) {
  1605. di_p32_info |= 1;
  1606. last_big_data = pre_data;
  1607. last_big_num = pre_num;
  1608. di_p32_counter = -1;
  1609. } else {
  1610. last_big_data = 0;
  1611. last_big_num = 0;
  1612. if ((di_p32_counter & 0x1) && data_diff * 5 <= cur_data && num_diff * 5 <= cur_num) {
  1613. di_p32_info_2 |= 1;
  1614. }
  1615. }
  1616. } else {
  1617. if (cur_data * 2 <= last_big_data && cur_num * 50 <= last_big_num) {
  1618. di_p32_info |= 1;
  1619. di_p32_counter = -1;
  1620. }
  1621. }
  1622. di_p32_counter++;
  1623. return 0;
  1624. }
  1625. void pattern_check_prepost(void)
  1626. {
  1627. if (pre_field_counter != di_checked_field) {
  1628. di_checked_field = pre_field_counter;
  1629. di_mode_check(pre_field_counter % 4);
  1630. #ifdef DEBUG
  1631. debug_array[(pre_field_counter & 0x3ff) * 4] = di_info[pre_field_counter % 4][0];
  1632. debug_array[(pre_field_counter & 0x3ff) * 4 + 1] = di_info[pre_field_counter % 4][1] & 0xffffff;
  1633. debug_array[(pre_field_counter & 0x3ff) * 4 + 2] = di_info[pre_field_counter % 4][2];
  1634. debug_array[(pre_field_counter & 0x3ff) * 4 + 3] = di_info[pre_field_counter % 4][4];
  1635. #endif
  1636. if (pre_field_counter >= 3) {
  1637. check_p32_p22(pre_field_counter % 4, (pre_field_counter + 3) % 4, (pre_field_counter + 2) % 4);
  1638. #if defined(CONFIG_ARCH_MESON)
  1639. pattern_22 = pattern_22 << 1;
  1640. if (di_info[pre_field_counter % 4][4] < di_info[(pre_field_counter + 3) % 4][4]) {
  1641. pattern_22 |= 1;
  1642. }
  1643. #endif
  1644. }
  1645. }
  1646. di_chan2_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 3) % 4;
  1647. di_mem_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 2) % 4;
  1648. blend_mode = 3;
  1649. #if defined(CONFIG_ARCH_MESON)
  1650. di_buf0_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 3) % 4;
  1651. // 2:2 check
  1652. if (((di_p22_info & PATTERN22_MARK) == (0xaaaaaaaaaaaaaaaaLL & PATTERN22_MARK))
  1653. && ((di_p22_info_2 & PATTERN22_MARK) == (0xaaaaaaaaaaaaaaaaLL & PATTERN22_MARK))) {
  1654. blend_mode = 1;
  1655. } else if (((di_p22_info & PATTERN22_MARK) == (0x5555555555555555LL & PATTERN22_MARK))
  1656. && ((di_p22_info_2 & PATTERN22_MARK) == (0x5555555555555555LL & PATTERN22_MARK))) {
  1657. blend_mode = 0;
  1658. }
  1659. #elif defined(CONFIG_ARCH_MESON2)
  1660. di_buf1_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 1) % 4;
  1661. if (((di_p22_info & PATTERN22_MARK) == (0x5555555555555555LL & PATTERN22_MARK))
  1662. && ((di_p22_info_2 & PATTERN22_MARK) == (0x5555555555555555LL & PATTERN22_MARK))) {
  1663. di_buf1_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 3) % 4;
  1664. blend_mode = 1;
  1665. } else if (((di_p22_info & PATTERN22_MARK) == (0xaaaaaaaaaaaaaaaaLL & PATTERN22_MARK))
  1666. && ((di_p22_info_2 & PATTERN22_MARK) == (0xaaaaaaaaaaaaaaaaLL & PATTERN22_MARK))) {
  1667. di_buf1_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 1) % 4;
  1668. blend_mode = 0;
  1669. }
  1670. #endif
  1671. // pull down pattern check
  1672. if (pattern_len == 0) {
  1673. int i, j, pattern, pattern_2, mask;
  1674. for (j = 5 ; j < 22 ; j++) {
  1675. mask = (1 << j) - 1;
  1676. pattern = di_p32_info & mask;
  1677. pattern_2 = di_p32_info_2 & mask;
  1678. if (pattern != 0 && pattern_2 != 0 && pattern != mask) {
  1679. for (i = j ; i < j * 3 ; i += j)
  1680. if (((di_p32_info >> i) & mask) != pattern || ((di_p32_info_2 >> i) & mask) != pattern_2) {
  1681. break;
  1682. }
  1683. if (i == j * 3) {
  1684. #if defined(CONFIG_ARCH_MESON)
  1685. if (pattern_22 & (1 << (j - 1))) {
  1686. blend_mode = 1;
  1687. } else {
  1688. blend_mode = 0;
  1689. }
  1690. #elif defined(CONFIG_ARCH_MESON2)
  1691. if (di_info[(field_counter + 3) % 4][4] < di_info[(field_counter + 2) % 4][4]) {
  1692. di_buf1_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 3) % 4;
  1693. blend_mode = 1;
  1694. } else {
  1695. di_buf1_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 1) % 4;
  1696. blend_mode = 0;
  1697. }
  1698. #endif
  1699. pattern_len = j;
  1700. break;
  1701. }
  1702. }
  1703. }
  1704. } else {
  1705. int i, pattern, pattern_2, mask;
  1706. mask = (1 << pattern_len) - 1;
  1707. pattern = di_p32_info & mask;
  1708. pattern_2 = di_p32_info_2 & mask;
  1709. for (i = pattern_len ; i < pattern_len * 3 ; i += pattern_len)
  1710. if (((di_p32_info >> i) & mask) != pattern || ((di_p32_info_2 >> i) & mask) != pattern_2) {
  1711. break;
  1712. }
  1713. if (i == pattern_len * 3) {
  1714. #if defined(CONFIG_ARCH_MESON)
  1715. if (pattern_22 & (1 << (pattern_len - 1))) {
  1716. blend_mode = 1;
  1717. } else {
  1718. blend_mode = 0;
  1719. }
  1720. #elif defined(CONFIG_ARCH_MESON2)
  1721. if (di_info[(field_counter + 3) % 4][4] < di_info[(field_counter + 2) % 4][4]) {
  1722. di_buf1_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 3) % 4;
  1723. blend_mode = 1;
  1724. } else {
  1725. di_buf1_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + (field_counter + 1) % 4;
  1726. blend_mode = 0;
  1727. }
  1728. #endif
  1729. } else {
  1730. pattern_len = 0;
  1731. }
  1732. }
  1733. di_nrwr_mif.canvas_num = DEINTERLACE_CANVAS_BASE_INDEX + field_counter % 4;
  1734. di_mtnwr_mif.canvas_num = DEINTERLACE_CANVAS_BASE_INDEX + 4 + field_counter % 4;
  1735. di_mtncrd_mif.canvas_num = DEINTERLACE_CANVAS_BASE_INDEX + 4 + (field_counter + 2) % 4;
  1736. di_mtnprd_mif.canvas_num = DEINTERLACE_CANVAS_BASE_INDEX + 4 + (field_counter + 3) % 4;
  1737. }
  1738. void pattern_check_pre(void)
  1739. {
  1740. di_pre_mode_check(pre_field_counter % 4);
  1741. #ifdef DEBUG
  1742. debug_array[(pre_field_counter & 0x3ff) * 4] = di_info[pre_field_counter % 4][0];
  1743. debug_array[(pre_field_counter & 0x3ff) * 4 + 1] = di_info[pre_field_counter % 4][1] & 0xffffff;
  1744. debug_array[(pre_field_counter & 0x3ff) * 4 + 2] = di_info[pre_field_counter % 4][2];
  1745. debug_array[(pre_field_counter & 0x3ff) * 4 + 3] = di_info[pre_field_counter % 4][4];
  1746. #endif
  1747. if (pre_field_counter >= 3) {
  1748. check_p32_p22(pre_field_counter % 4, (pre_field_counter - 1) % 4, (pre_field_counter - 2) % 4);
  1749. if (di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode == 3) {
  1750. if (((di_p22_info & PATTERN22_MARK) == (0x5555555555555555LL & PATTERN22_MARK))
  1751. && ((di_p22_info_2 & PATTERN22_MARK) == (0x5555555555555555LL & PATTERN22_MARK))) {
  1752. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 1;
  1753. } else if (((di_p22_info & PATTERN22_MARK) == (0xaaaaaaaaaaaaaaaaLL & PATTERN22_MARK))
  1754. && ((di_p22_info_2 & PATTERN22_MARK) == (0xaaaaaaaaaaaaaaaaLL & PATTERN22_MARK))) {
  1755. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 0;
  1756. } else if (pattern_len == 0) {
  1757. di_buf_pool[(pre_field_counter - 2) % DI_BUF_NUM].blend_mode = 3;
  1758. }
  1759. if (pattern_len == 0) {
  1760. int i, j, pattern, pattern_2, mask;
  1761. for (j = 5 ; j < 22 ; j++) {
  1762. mask = (1 << j) - 1;
  1763. pattern = di_p32_info & mask;
  1764. pattern_2 = di_p32_info_2 & mask;
  1765. if (pattern != 0 && pattern_2 != 0 && pattern != mask) {
  1766. for (i = j ; i < j * PATTERN32_NUM ; i += j)
  1767. if (((di_p32_info >> i) & mask) != pattern || ((di_p32_info_2 >> i) & mask) != pattern_2) {
  1768. break;
  1769. }
  1770. if (i == j * PATTERN32_NUM) {
  1771. if ((pattern_len == 5) && ((pattern & (pattern - 1)) == 0)) {
  1772. if ((di_p32_info & 0x1) || (di_p32_info & 0x2) || (di_p32_info & 0x8)) {
  1773. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 0;
  1774. } else {
  1775. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 1;
  1776. }
  1777. } else {
  1778. if ((pattern & (pattern - 1)) != 0) {
  1779. if (di_info[pre_field_counter % 4][4] < di_info[(pre_field_counter - 1) % 4][4]) {
  1780. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 1;
  1781. } else {
  1782. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 0;
  1783. }
  1784. }
  1785. }
  1786. pattern_len = j;
  1787. break;
  1788. }
  1789. }
  1790. }
  1791. } else {
  1792. int i, pattern, pattern_2, mask;
  1793. mask = (1 << pattern_len) - 1;
  1794. pattern = di_p32_info & mask;
  1795. pattern_2 = di_p32_info_2 & mask;
  1796. for (i = pattern_len ; i < pattern_len * PATTERN32_NUM ; i += pattern_len)
  1797. if (((di_p32_info >> i) & mask) != pattern || ((di_p32_info_2 >> i) & mask) != pattern_2) {
  1798. break;
  1799. }
  1800. if (i == pattern_len * PATTERN32_NUM) {
  1801. if ((pattern_len == 5) && ((pattern & (pattern - 1)) == 0)) {
  1802. if ((di_p32_info & 0x1) || (di_p32_info & 0x2) || (di_p32_info & 0x8)) {
  1803. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 0;
  1804. } else {
  1805. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 1;
  1806. }
  1807. } else {
  1808. if ((pattern & (pattern - 1)) != 0) {
  1809. if (di_info[pre_field_counter % 4][4] < di_info[(pre_field_counter - 1) % 4][4]) {
  1810. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 1;
  1811. } else {
  1812. di_buf_pool[(pre_field_counter - 1) % DI_BUF_NUM].blend_mode = 0;
  1813. }
  1814. }
  1815. }
  1816. } else {
  1817. pattern_len = 0;
  1818. di_buf_pool[(pre_field_counter - 2) % DI_BUF_NUM].blend_mode = 3;
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. void set_vdin_par(int flag, vframe_t *buf)
  1825. {
  1826. vdin_en = flag;
  1827. memcpy(&dummy_buf, buf, sizeof(vframe_t));
  1828. }
  1829. void di_pre_process(void)
  1830. {
  1831. unsigned temp = READ_MPEG_REG(DI_INTR_CTRL);
  1832. unsigned status = READ_MPEG_REG(DI_PRE_CTRL) & 0x2;
  1833. #if defined(CONFIG_ARCH_MESON2)
  1834. int nr_hfilt_en, nr_hfilt_mb_en;
  1835. if (noise_reduction_level == 2) {
  1836. nr_hfilt_en = 1;
  1837. nr_hfilt_mb_en = 1;
  1838. } else {
  1839. nr_hfilt_en = 0;
  1840. nr_hfilt_mb_en = 0;
  1841. }
  1842. #endif
  1843. if (deinterlace_mode != 2) {
  1844. return;
  1845. }
  1846. if ((prev_struct == 0) && (READ_MPEG_REG(DI_PRE_SIZE) != ((32 - 1) | ((64 - 1) << 16)))) {
  1847. disable_pre_deinterlace();
  1848. }
  1849. if (prev_struct > 0) {
  1850. #if defined(CONFIG_ARCH_MESON)
  1851. if ((temp & 0xf) != (status | 0x9))
  1852. #elif defined(CONFIG_ARCH_MESON2)
  1853. if ((temp & 0xf) != (status | 0x1))
  1854. #endif
  1855. return;
  1856. if (!vdin_en && (prog_field_count == 0) && (buf_recycle_done == 0)) {
  1857. buf_recycle_done = 1;
  1858. vf_put(cur_buf, RECEIVER_NAME);
  1859. }
  1860. if (di_pre_post_done == 0) {
  1861. di_pre_post_done = 1;
  1862. pattern_check_pre();
  1863. memcpy((&di_buf_pool[pre_field_counter % DI_BUF_NUM]), cur_buf, sizeof(vframe_t));
  1864. di_buf_pool[pre_field_counter % DI_BUF_NUM].blend_mode = blend_mode;
  1865. di_buf_pool[pre_field_counter % DI_BUF_NUM].canvas0Addr = DEINTERLACE_CANVAS_BASE_INDEX + 4;
  1866. di_buf_pool[pre_field_counter % DI_BUF_NUM].canvas1Addr = DEINTERLACE_CANVAS_BASE_INDEX + 4;
  1867. if (prev_struct == 1) {
  1868. di_buf_pool[pre_field_counter % DI_BUF_NUM].type = VIDTYPE_INTERLACE_TOP | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  1869. } else {
  1870. di_buf_pool[pre_field_counter % DI_BUF_NUM].type = VIDTYPE_INTERLACE_BOTTOM | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  1871. }
  1872. pre_field_counter++;
  1873. }
  1874. if ((pre_field_counter >= field_counter + DI_BUF_NUM - 3) && ((pre_field_counter >= field_counter + DI_BUF_NUM - 2) || (field_counter == 0))) {
  1875. #ifdef DEBUG
  1876. di_pre_overflow++;
  1877. #endif
  1878. return;
  1879. }
  1880. if (!vdin_en && (prog_field_count == 0) && (!vf_peek(RECEIVER_NAME))) {
  1881. #ifdef DEBUG
  1882. di_pre_underflow++;
  1883. #endif
  1884. return;
  1885. }
  1886. }
  1887. if (prog_field_count > 0) {
  1888. blend_mode = 0;
  1889. prog_field_count--;
  1890. prev_struct = 3 - prev_struct;
  1891. } else {
  1892. if (vdin_en) {
  1893. di_pre_recycle_buf = 1;
  1894. cur_buf = &dummy_buf;
  1895. } else {
  1896. cur_buf = vf_peek(RECEIVER_NAME);
  1897. if (!cur_buf) {
  1898. return;
  1899. }
  1900. if ((cur_buf->duration == 0)
  1901. #if defined(CONFIG_AM_DEINTERLACE_SD_ONLY)
  1902. || (cur_buf->width > 720)
  1903. #endif
  1904. ) {
  1905. di_pre_recycle_buf = 0;
  1906. return;
  1907. }
  1908. di_pre_recycle_buf = 1;
  1909. cur_buf = vf_get(RECEIVER_NAME);
  1910. }
  1911. if (((cur_buf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP && prev_struct == 1)
  1912. || ((cur_buf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_BOTTOM && prev_struct == 2)) {
  1913. if (!vdin_en) {
  1914. vf_put(cur_buf, RECEIVER_NAME);
  1915. }
  1916. return;
  1917. }
  1918. di_inp_top_mif.canvas0_addr0 = di_inp_bot_mif.canvas0_addr0 = cur_buf->canvas0Addr & 0xff;
  1919. di_inp_top_mif.canvas0_addr1 = di_inp_bot_mif.canvas0_addr1 = (cur_buf->canvas0Addr >> 8) & 0xff;
  1920. di_inp_top_mif.canvas0_addr2 = di_inp_bot_mif.canvas0_addr2 = (cur_buf->canvas0Addr >> 16) & 0xff;
  1921. blend_mode = 3;
  1922. if ((cur_buf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP) {
  1923. prev_struct = 1;
  1924. prog_field_count = 0;
  1925. } else if ((cur_buf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_BOTTOM) {
  1926. prev_struct = 2;
  1927. prog_field_count = 0;
  1928. } else {
  1929. if (prev_struct == 0) {
  1930. prev_struct = 1;
  1931. } else {
  1932. prev_struct = 3 - prev_struct;
  1933. }
  1934. if (cur_buf->duration_pulldown > 0) {
  1935. prog_field_count = 2;
  1936. } else {
  1937. prog_field_count = 1;
  1938. }
  1939. blend_mode = 1;
  1940. cur_buf->duration >>= 1;
  1941. cur_buf->duration_pulldown = 0;
  1942. }
  1943. }
  1944. buf_recycle_done = 0;
  1945. di_pre_post_done = 0;
  1946. WRITE_MPEG_REG(DI_INTR_CTRL, temp);
  1947. if ((READ_MPEG_REG(DI_PRE_SIZE) != ((cur_buf->width - 1) | ((cur_buf->height / 2 - 1) << 16)))) {
  1948. WRITE_MPEG_REG(DI_INTR_CTRL, 0x000f000f);
  1949. initial_di_pre(cur_buf->width, cur_buf->height / 2, PRE_HOLD_LINE);
  1950. di_checked_field = (field_counter + di_checked_field + 1) % DI_BUF_NUM;
  1951. pre_field_counter = field_counter = 0;
  1952. di_p32_info = di_p22_info = di_p32_info_2 = di_p22_info_2 = 0;
  1953. pattern_len = 0;
  1954. di_mem_mif.luma_x_start0 = 0;
  1955. di_mem_mif.luma_x_end0 = cur_buf->width - 1;
  1956. di_mem_mif.luma_y_start0 = 0;
  1957. di_mem_mif.luma_y_end0 = cur_buf->height / 2 - 1;
  1958. di_chan2_mif.luma_x_start0 = 0;
  1959. di_chan2_mif.luma_x_end0 = cur_buf->width - 1;
  1960. di_chan2_mif.luma_y_start0 = 0;
  1961. di_chan2_mif.luma_y_end0 = cur_buf->height / 2 - 1;
  1962. di_nrwr_mif.start_x = 0;
  1963. di_nrwr_mif.end_x = cur_buf->width - 1;
  1964. di_nrwr_mif.start_y = 0;
  1965. di_nrwr_mif.end_y = cur_buf->height / 2 - 1;
  1966. di_mtnwr_mif.start_x = 0;
  1967. di_mtnwr_mif.end_x = cur_buf->width - 1;
  1968. di_mtnwr_mif.start_y = 0;
  1969. di_mtnwr_mif.end_y = cur_buf->height / 2 - 1;
  1970. if (cur_buf->type & VIDTYPE_VIU_422) {
  1971. di_inp_top_mif.video_mode = 0;
  1972. di_inp_top_mif.set_separate_en = 0;
  1973. di_inp_top_mif.src_field_mode = 0;
  1974. di_inp_top_mif.output_field_num = 0;
  1975. di_inp_top_mif.burst_size_y = 3;
  1976. di_inp_top_mif.burst_size_cb = 0;
  1977. di_inp_top_mif.burst_size_cr = 0;
  1978. memcpy(&di_inp_bot_mif, &di_inp_top_mif, sizeof(DI_MIF_t));
  1979. di_inp_top_mif.luma_x_start0 = 0;
  1980. di_inp_top_mif.luma_x_end0 = cur_buf->width - 1;
  1981. di_inp_top_mif.luma_y_start0 = 0;
  1982. di_inp_top_mif.luma_y_end0 = cur_buf->height / 2 - 1;
  1983. di_inp_top_mif.chroma_x_start0 = 0;
  1984. di_inp_top_mif.chroma_x_end0 = 0;
  1985. di_inp_top_mif.chroma_y_start0 = 0;
  1986. di_inp_top_mif.chroma_y_end0 = 0;
  1987. di_inp_bot_mif.luma_x_start0 = 0;
  1988. di_inp_bot_mif.luma_x_end0 = cur_buf->width - 1;
  1989. di_inp_bot_mif.luma_y_start0 = 0;
  1990. di_inp_bot_mif.luma_y_end0 = cur_buf->height / 2 - 1;
  1991. di_inp_bot_mif.chroma_x_start0 = 0;
  1992. di_inp_bot_mif.chroma_x_end0 = 0;
  1993. di_inp_bot_mif.chroma_y_start0 = 0;
  1994. di_inp_bot_mif.chroma_y_end0 = 0;
  1995. } else {
  1996. di_inp_top_mif.video_mode = 0;
  1997. di_inp_top_mif.set_separate_en = 1;
  1998. di_inp_top_mif.src_field_mode = 1;
  1999. di_inp_top_mif.burst_size_y = 3;
  2000. di_inp_top_mif.burst_size_cb = 1;
  2001. di_inp_top_mif.burst_size_cr = 1;
  2002. memcpy(&di_inp_bot_mif, &di_inp_top_mif, sizeof(DI_MIF_t));
  2003. di_inp_top_mif.output_field_num = 0; // top
  2004. di_inp_bot_mif.output_field_num = 1; // bottom
  2005. di_inp_top_mif.luma_x_start0 = 0;
  2006. di_inp_top_mif.luma_x_end0 = cur_buf->width - 1;
  2007. di_inp_top_mif.luma_y_start0 = 0;
  2008. di_inp_top_mif.luma_y_end0 = cur_buf->height - 2;
  2009. di_inp_top_mif.chroma_x_start0 = 0;
  2010. di_inp_top_mif.chroma_x_end0 = cur_buf->width / 2 - 1;
  2011. di_inp_top_mif.chroma_y_start0 = 0;
  2012. di_inp_top_mif.chroma_y_end0 = cur_buf->height / 2 - 2;
  2013. di_inp_bot_mif.luma_x_start0 = 0;
  2014. di_inp_bot_mif.luma_x_end0 = cur_buf->width - 1;
  2015. di_inp_bot_mif.luma_y_start0 = 1;
  2016. di_inp_bot_mif.luma_y_end0 = cur_buf->height - 1;
  2017. di_inp_bot_mif.chroma_x_start0 = 0;
  2018. di_inp_bot_mif.chroma_x_end0 = cur_buf->width / 2 - 1;
  2019. di_inp_bot_mif.chroma_y_start0 = 1;
  2020. di_inp_bot_mif.chroma_y_end0 = cur_buf->height / 2 - 1;
  2021. }
  2022. di_nrwr_mif.canvas_num = DEINTERLACE_CANVAS_BASE_INDEX;
  2023. di_mtnwr_mif.canvas_num = DEINTERLACE_CANVAS_BASE_INDEX + 1;
  2024. di_chan2_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + 2;
  2025. di_mem_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + 3;
  2026. di_buf0_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + 4;
  2027. di_buf1_mif.canvas0_addr0 = DEINTERLACE_CANVAS_BASE_INDEX + 5;
  2028. di_mtncrd_mif.canvas_num = DEINTERLACE_CANVAS_BASE_INDEX + 6;
  2029. di_mtnprd_mif.canvas_num = DEINTERLACE_CANVAS_BASE_INDEX + 7;
  2030. enable_di_mode_check(
  2031. 0, cur_buf->width - 1, 0, cur_buf->height / 2 - 1, // window 0 ( start_x, end_x, start_y, end_y)
  2032. 0, cur_buf->width - 1, 0, cur_buf->height / 2 - 1, // window 1 ( start_x, end_x, start_y, end_y)
  2033. 0, cur_buf->width - 1, 0, cur_buf->height / 2 - 1, // window 2 ( start_x, end_x, start_y, end_y)
  2034. 0, cur_buf->width - 1, 0, cur_buf->height / 2 - 1, // window 3 ( start_x, end_x, start_y, end_y)
  2035. 0, cur_buf->width - 1, 0, cur_buf->height / 2 - 1, // window 4 ( start_x, end_x, start_y, end_y)
  2036. 16, 16, 16, 16, 16, // windows 32 level
  2037. 256, 256, 256, 256, 256, // windows 22 level
  2038. 16, 256); // field 32 level; field 22 level
  2039. }
  2040. temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((pre_field_counter + di_checked_field) % DI_BUF_NUM);
  2041. canvas_config(di_nrwr_mif.canvas_num, temp, MAX_CANVAS_WIDTH * 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  2042. temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((pre_field_counter + di_checked_field) % DI_BUF_NUM) + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT);
  2043. canvas_config(di_mtnwr_mif.canvas_num, temp, MAX_CANVAS_WIDTH / 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  2044. temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((pre_field_counter + di_checked_field + DI_BUF_NUM - 1) % DI_BUF_NUM);
  2045. canvas_config(di_chan2_mif.canvas0_addr0, temp, MAX_CANVAS_WIDTH * 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  2046. temp = di_mem_start + (MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT * 5 / 4) * ((pre_field_counter + di_checked_field + DI_BUF_NUM - 2) % DI_BUF_NUM);
  2047. canvas_config(di_mem_mif.canvas0_addr0, temp, MAX_CANVAS_WIDTH * 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  2048. WRITE_MPEG_REG(DI_PRE_CTRL, 0x3 << 30);
  2049. enable_di_pre(
  2050. (prev_struct == 1) ? &di_inp_top_mif : &di_inp_bot_mif,
  2051. (pre_field_counter < 2) ? ((prev_struct == 1) ? &di_inp_top_mif : &di_inp_bot_mif) : &di_mem_mif,
  2052. &di_chan2_mif,
  2053. &di_nrwr_mif,
  2054. &di_mtnwr_mif,
  2055. 1, // nr enable
  2056. (pre_field_counter >= 2), // mtn enable
  2057. (pre_field_counter >= 2), // 3:2 pulldown check enable
  2058. (pre_field_counter >= 1), // 2:2 pulldown check enable
  2059. #if defined(CONFIG_ARCH_MESON)
  2060. 1, // hist check_en
  2061. #elif defined(CONFIG_ARCH_MESON2)
  2062. 0, // hist check_en
  2063. nr_hfilt_en, // nr_hfilt_en
  2064. nr_hfilt_mb_en, // nr_hfilt_mb_en
  2065. 1, // mtn_modify_en,
  2066. #endif
  2067. (prev_struct == 1) ? 1 : 0, // field num for chan2. 1 bottom, 0 top.
  2068. 0, // pre viu link.
  2069. PRE_HOLD_LINE
  2070. );
  2071. }
  2072. void di_pre_isr(struct work_struct *work)
  2073. {
  2074. if (!vf_get_provider(RECEIVER_NAME)) {
  2075. return;
  2076. }
  2077. di_pre_process();
  2078. }
  2079. void run_deinterlace(unsigned zoom_start_x_lines, unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines,
  2080. unsigned type, int mode, int hold_line)
  2081. {
  2082. int di_width, di_height, di_start_x, di_end_x, di_start_y, di_end_y, size_change, position_change;
  2083. #if defined(CONFIG_ARCH_MESON2)
  2084. int nr_hfilt_en, nr_hfilt_mb_en, post_mb_en;
  2085. if (noise_reduction_level == 2) {
  2086. nr_hfilt_en = 1;
  2087. nr_hfilt_mb_en = 1;
  2088. post_mb_en = 1;
  2089. } else {
  2090. nr_hfilt_en = 0;
  2091. nr_hfilt_mb_en = 0;
  2092. post_mb_en = 0;
  2093. }
  2094. #endif
  2095. di_start_x = zoom_start_x_lines;
  2096. di_end_x = zoom_end_x_lines;
  2097. di_width = di_end_x - di_start_x + 1;
  2098. di_start_y = (zoom_start_y_lines + 1) & 0xfffffffe;
  2099. di_end_y = (zoom_end_y_lines - 1) | 0x1;
  2100. di_height = di_end_y - di_start_y + 1;
  2101. if (deinterlace_mode == 1) {
  2102. int i;
  2103. unsigned long addr = di_mem_start;
  2104. size_change = (READ_MPEG_REG(DI_POST_SIZE) != ((di_width - 1) | ((di_height - 1) << 16)));
  2105. position_change = ((di_inp_top_mif.luma_x_start0 != di_start_x) || (di_inp_top_mif.luma_y_start0 != di_start_y));
  2106. if (size_change || position_change) {
  2107. if (size_change) {
  2108. initial_di_prepost(di_width, di_height / 2, di_width, di_height, hold_line);
  2109. pattern_22 = 0;
  2110. di_p32_info = di_p22_info = di_p32_info_2 = di_p22_info_2 = 0;
  2111. pattern_len = 0;
  2112. }
  2113. di_mem_mif.luma_x_start0 = di_start_x;
  2114. di_mem_mif.luma_x_end0 = di_end_x;
  2115. di_mem_mif.luma_y_start0 = di_start_y / 2;
  2116. di_mem_mif.luma_y_end0 = (di_end_y + 1) / 2 - 1;
  2117. di_buf0_mif.luma_x_start0 = di_start_x;
  2118. di_buf0_mif.luma_x_end0 = di_end_x;
  2119. di_buf0_mif.luma_y_start0 = di_start_y / 2;
  2120. di_buf0_mif.luma_y_end0 = (di_end_y + 1) / 2 - 1;
  2121. di_chan2_mif.luma_x_start0 = di_start_x;
  2122. di_chan2_mif.luma_x_end0 = di_end_x;
  2123. di_chan2_mif.luma_y_start0 = di_start_y / 2;
  2124. di_chan2_mif.luma_y_end0 = (di_end_y + 1) / 2 - 1;
  2125. di_nrwr_mif.start_x = di_start_x;
  2126. di_nrwr_mif.end_x = di_end_x;
  2127. di_nrwr_mif.start_y = di_start_y / 2;
  2128. di_nrwr_mif.end_y = (di_end_y + 1) / 2 - 1;
  2129. di_mtnwr_mif.start_x = di_start_x;
  2130. di_mtnwr_mif.end_x = di_end_x;
  2131. di_mtnwr_mif.start_y = di_start_y / 2;
  2132. di_mtnwr_mif.end_y = (di_end_y + 1) / 2 - 1;
  2133. di_mtncrd_mif.start_x = di_start_x;
  2134. di_mtncrd_mif.end_x = di_end_x;
  2135. di_mtncrd_mif.start_y = di_start_y / 2;
  2136. di_mtncrd_mif.end_y = (di_end_y + 1) / 2 - 1;
  2137. enable_di_mode_check(
  2138. di_start_x, di_end_x, di_start_y, (di_end_y + 1) / 2 - 1, // window 0 ( start_x, end_x, start_y, end_y)
  2139. di_start_x, di_end_x, di_start_y, (di_end_y + 1) / 2 - 1, // window 1 ( start_x, end_x, start_y, end_y)
  2140. di_start_x, di_end_x, di_start_y, (di_end_y + 1) / 2 - 1, // window 2 ( start_x, end_x, start_y, end_y)
  2141. di_start_x, di_end_x, di_start_y, (di_end_y + 1) / 2 - 1, // window 3 ( start_x, end_x, start_y, end_y)
  2142. di_start_x, di_end_x, di_start_y, (di_end_y + 1) / 2 - 1, // window 4 ( start_x, end_x, start_y, end_y)
  2143. 16, 16, 16, 16, 16, // windows 32 level
  2144. 256, 256, 256, 256, 256, // windows 22 level
  2145. 16, 256); // field 32 level; field 22 level
  2146. pre_field_counter = field_counter = di_checked_field = 0;
  2147. if (type & VIDTYPE_VIU_422) {
  2148. di_inp_top_mif.video_mode = 0;
  2149. di_inp_top_mif.set_separate_en = 0;
  2150. di_inp_top_mif.src_field_mode = 0;
  2151. di_inp_top_mif.output_field_num = 0;
  2152. di_inp_top_mif.burst_size_y = 3;
  2153. di_inp_top_mif.burst_size_cb = 0;
  2154. di_inp_top_mif.burst_size_cr = 0;
  2155. memcpy(&di_inp_bot_mif, &di_inp_top_mif, sizeof(DI_MIF_t));
  2156. di_inp_top_mif.luma_x_start0 = di_start_x;
  2157. di_inp_top_mif.luma_x_end0 = di_end_x;
  2158. di_inp_top_mif.luma_y_start0 = di_start_y;
  2159. di_inp_top_mif.luma_y_end0 = (di_end_y + 1) / 2 - 1;
  2160. di_inp_top_mif.chroma_x_start0 = 0;
  2161. di_inp_top_mif.chroma_x_end0 = 0;
  2162. di_inp_top_mif.chroma_y_start0 = 0;
  2163. di_inp_top_mif.chroma_y_end0 = 0;
  2164. di_inp_bot_mif.luma_x_start0 = di_start_x;
  2165. di_inp_bot_mif.luma_x_end0 = di_end_x;
  2166. di_inp_bot_mif.luma_y_start0 = di_start_y;
  2167. di_inp_bot_mif.luma_y_end0 = (di_end_y + 1) / 2 - 1;
  2168. di_inp_bot_mif.chroma_x_start0 = 0;
  2169. di_inp_bot_mif.chroma_x_end0 = 0;
  2170. di_inp_bot_mif.chroma_y_start0 = 0;
  2171. di_inp_bot_mif.chroma_y_end0 = 0;
  2172. } else {
  2173. di_inp_top_mif.video_mode = 0;
  2174. di_inp_top_mif.set_separate_en = 1;
  2175. di_inp_top_mif.src_field_mode = 1;
  2176. di_inp_top_mif.burst_size_y = 3;
  2177. di_inp_top_mif.burst_size_cb = 1;
  2178. di_inp_top_mif.burst_size_cr = 1;
  2179. memcpy(&di_inp_bot_mif, &di_inp_top_mif, sizeof(DI_MIF_t));
  2180. di_inp_top_mif.output_field_num = 0; // top
  2181. di_inp_bot_mif.output_field_num = 1; // bottom
  2182. di_inp_top_mif.luma_x_start0 = di_start_x;
  2183. di_inp_top_mif.luma_x_end0 = di_end_x;
  2184. di_inp_top_mif.luma_y_start0 = di_start_y;
  2185. di_inp_top_mif.luma_y_end0 = di_end_y - 1;
  2186. di_inp_top_mif.chroma_x_start0 = di_start_x / 2;
  2187. di_inp_top_mif.chroma_x_end0 = (di_end_x + 1) / 2 - 1;
  2188. di_inp_top_mif.chroma_y_start0 = di_start_y / 2;
  2189. di_inp_top_mif.chroma_y_end0 = (di_end_y + 1) / 2 - 2;
  2190. di_inp_bot_mif.luma_x_start0 = di_start_x;
  2191. di_inp_bot_mif.luma_x_end0 = di_end_x;
  2192. di_inp_bot_mif.luma_y_start0 = di_start_y + 1;
  2193. di_inp_bot_mif.luma_y_end0 = di_end_y;
  2194. di_inp_bot_mif.chroma_x_start0 = di_start_x / 2;
  2195. di_inp_bot_mif.chroma_x_end0 = (di_end_x + 1) / 2 - 1;
  2196. di_inp_bot_mif.chroma_y_start0 = di_start_y / 2 + 1;
  2197. di_inp_bot_mif.chroma_y_end0 = (di_end_y + 1) / 2 - 1;
  2198. }
  2199. for (i = 0 ; i < 4 ; i++) {
  2200. canvas_config(DEINTERLACE_CANVAS_BASE_INDEX + i, addr, MAX_CANVAS_WIDTH * 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  2201. addr += MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT;
  2202. }
  2203. for (i = 4 ; i < 8 ; i++) {
  2204. canvas_config(DEINTERLACE_CANVAS_BASE_INDEX + i, addr, MAX_CANVAS_WIDTH / 2, MAX_CANVAS_HEIGHT / 2, 0, 0);
  2205. addr += MAX_CANVAS_WIDTH * MAX_CANVAS_HEIGHT / 4;
  2206. }
  2207. di_inp_top_mif.canvas0_addr0 = di_inp_bot_mif.canvas0_addr0 = DISPLAY_CANVAS_BASE_INDEX;
  2208. di_inp_top_mif.canvas0_addr1 = di_inp_bot_mif.canvas0_addr1 = DISPLAY_CANVAS_BASE_INDEX + 1;
  2209. di_inp_top_mif.canvas0_addr2 = di_inp_bot_mif.canvas0_addr2 = DISPLAY_CANVAS_BASE_INDEX + 2;
  2210. }
  2211. pattern_check_prepost();
  2212. #if defined(CONFIG_ARCH_MESON)
  2213. if ((type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP) {
  2214. enable_di_prepost_full(
  2215. &di_inp_top_mif,
  2216. &di_mem_mif,
  2217. (field_counter < 1 ? &di_inp_top_mif : &di_buf0_mif),
  2218. NULL,
  2219. &di_chan2_mif,
  2220. &di_nrwr_mif,
  2221. NULL,
  2222. &di_mtnwr_mif,
  2223. &di_mtncrd_mif,
  2224. NULL,
  2225. (pre_field_counter != field_counter || field_counter == 0), // noise reduction enable
  2226. (field_counter >= 2), // motion check enable
  2227. (pre_field_counter != field_counter && field_counter >= 2), // 3:2 pulldown check enable
  2228. (pre_field_counter != field_counter && field_counter >= 1), // 2:2 pulldown check enable
  2229. (pre_field_counter != field_counter || field_counter == 0), // video luma histogram check enable
  2230. 1, // edge interpolation module enable.
  2231. (field_counter >= 2), // blend enable.
  2232. (field_counter >= 2), // blend with mtn.
  2233. (field_counter < 2 ? 2 : blend_mode), // blend mode
  2234. 1, // deinterlace output to VPP.
  2235. 0, // deinterlace output to DDR SDRAM at same time.
  2236. (field_counter >= 1), // 1 = current display field is bottom field, we need generated top field.
  2237. (field_counter >= 1), // pre field num: 1 = current chan2 input field is bottom field.
  2238. (field_counter >= 1), // prepost link. for the first field it look no need to be propost_link.
  2239. hold_line
  2240. );
  2241. } else {
  2242. enable_di_prepost_full(
  2243. &di_inp_bot_mif,
  2244. &di_mem_mif,
  2245. (field_counter < 1 ? &di_inp_bot_mif : &di_buf0_mif),
  2246. NULL,
  2247. &di_chan2_mif,
  2248. &di_nrwr_mif,
  2249. NULL,
  2250. &di_mtnwr_mif,
  2251. &di_mtncrd_mif,
  2252. NULL,
  2253. (pre_field_counter != field_counter || field_counter == 0), // noise reduction enable
  2254. (field_counter >= 2), // motion check enable
  2255. (pre_field_counter != field_counter && field_counter >= 2), // 3:2 pulldown check enable
  2256. (pre_field_counter != field_counter && field_counter >= 1), // 2:2 pulldown check enable
  2257. (pre_field_counter != field_counter || field_counter == 0), // video luma histogram check enable
  2258. 1, // edge interpolation module enable.
  2259. (field_counter >= 2), // blend enable.
  2260. (field_counter >= 2), // blend with mtn.
  2261. (field_counter < 2 ? 2 : blend_mode), // blend mode: 3 motion adapative blend.
  2262. 1, // deinterlace output to VPP.
  2263. 0, // deinterlace output to DDR SDRAM at same time.
  2264. (field_counter < 1), // 1 = current display field is bottom field, we need generated top field.
  2265. (field_counter < 1), // pre field num. 1 = current chan2 input field is bottom field.
  2266. (field_counter >= 1), // prepost link. for the first field it look no need to be propost_link.
  2267. hold_line
  2268. );
  2269. }
  2270. #elif defined(CONFIG_ARCH_MESON2)
  2271. if ((type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP) {
  2272. enable_di_prepost_full(
  2273. &di_inp_top_mif,
  2274. (field_counter < 2 ? &di_inp_top_mif : &di_mem_mif),
  2275. NULL,
  2276. &di_buf1_mif,
  2277. &di_chan2_mif,
  2278. &di_nrwr_mif,
  2279. NULL,
  2280. &di_mtnwr_mif,
  2281. &di_mtncrd_mif,
  2282. &di_mtnprd_mif,
  2283. (pre_field_counter != field_counter || field_counter == 0), // noise reduction enable
  2284. (field_counter >= 2), // motion check enable
  2285. (pre_field_counter != field_counter && field_counter >= 2), // 3:2 pulldown check enable
  2286. (pre_field_counter != field_counter && field_counter >= 1), // 2:2 pulldown check enable
  2287. (pre_field_counter != field_counter || field_counter == 0), // video luma histogram check enable
  2288. 1, // edge interpolation module enable.
  2289. (field_counter >= 3), // blend enable.
  2290. (field_counter >= 3), // blend with mtn.
  2291. (field_counter < 3 ? 2 : blend_mode), // blend mode
  2292. 1, // deinterlace output to VPP.
  2293. 0, // deinterlace output to DDR SDRAM at same time.
  2294. nr_hfilt_en, // nr_hfilt_en
  2295. nr_hfilt_mb_en, // nr_hfilt_mb_en
  2296. 1, // mtn_modify_en,
  2297. 1, // blend_mtn_filt_en
  2298. 1, // blend_data_filt_en
  2299. post_mb_en, // post_mb_en
  2300. 0, // 1 = current display field is bottom field, we need generated top field.
  2301. 1, // pre field num: 1 = current chan2 input field is bottom field.
  2302. (field_counter >= 2), // prepost link. for the first field it look no need to be propost_link.
  2303. hold_line
  2304. );
  2305. } else {
  2306. enable_di_prepost_full(
  2307. &di_inp_bot_mif,
  2308. (field_counter < 2 ? &di_inp_top_mif : &di_mem_mif),
  2309. NULL,
  2310. &di_buf1_mif,
  2311. &di_chan2_mif,
  2312. &di_nrwr_mif,
  2313. NULL,
  2314. &di_mtnwr_mif,
  2315. &di_mtncrd_mif,
  2316. &di_mtnprd_mif,
  2317. (pre_field_counter != field_counter || field_counter == 0), // noise reduction enable
  2318. (field_counter >= 2), // motion check enable
  2319. (pre_field_counter != field_counter && field_counter >= 2), // 3:2 pulldown check enable
  2320. (pre_field_counter != field_counter && field_counter >= 1), // 2:2 pulldown check enable
  2321. (pre_field_counter != field_counter || field_counter == 0), // video luma histogram check enable
  2322. 1, // edge interpolation module enable.
  2323. (field_counter >= 3), // blend enable.
  2324. (field_counter >= 3), // blend with mtn.
  2325. (field_counter < 3 ? 2 : blend_mode), // blend mode: 3 motion adapative blend.
  2326. 1, // deinterlace output to VPP.
  2327. 0, // deinterlace output to DDR SDRAM at same time.
  2328. nr_hfilt_en, // nr_hfilt_en
  2329. nr_hfilt_mb_en, // nr_hfilt_mb_en
  2330. 1, // mtn_modify_en,
  2331. 1, // blend_mtn_filt_en
  2332. 1, // blend_data_filt_en
  2333. post_mb_en, // post_mb_en
  2334. 1, // 1 = current display field is bottom field, we need generated top field.
  2335. 0, // pre field num. 1 = current chan2 input field is bottom field.
  2336. (field_counter >= 2), // prepost link. for the first field it look no need to be propost_link.
  2337. hold_line
  2338. );
  2339. }
  2340. #endif
  2341. pre_field_counter = field_counter;
  2342. } else {
  2343. int post_blend_en, post_blend_mode;
  2344. if (READ_MPEG_REG(DI_POST_SIZE) != ((di_width - 1) | ((di_height - 1) << 16))
  2345. || (di_buf0_mif.luma_x_start0 != di_start_x) || (di_buf0_mif.luma_y_start0 != di_start_y / 2)) {
  2346. initial_di_post(di_width, di_height, hold_line);
  2347. di_buf0_mif.luma_x_start0 = di_start_x;
  2348. di_buf0_mif.luma_x_end0 = di_end_x;
  2349. di_buf0_mif.luma_y_start0 = di_start_y / 2;
  2350. di_buf0_mif.luma_y_end0 = (di_end_y + 1) / 2 - 1;
  2351. di_buf1_mif.luma_x_start0 = di_start_x;
  2352. di_buf1_mif.luma_x_end0 = di_end_x;
  2353. di_buf1_mif.luma_y_start0 = di_start_y / 2;
  2354. di_buf1_mif.luma_y_end0 = (di_end_y + 1) / 2 - 1;
  2355. di_mtncrd_mif.start_x = di_start_x;
  2356. di_mtncrd_mif.end_x = di_end_x;
  2357. di_mtncrd_mif.start_y = di_start_y / 2;
  2358. di_mtncrd_mif.end_y = (di_end_y + 1) / 2 - 1;
  2359. di_mtnprd_mif.start_x = di_start_x;
  2360. di_mtnprd_mif.end_x = di_end_x;
  2361. di_mtnprd_mif.start_y = di_start_y / 2;
  2362. di_mtnprd_mif.end_y = (di_end_y + 1) / 2 - 1;
  2363. }
  2364. post_blend_en = 1;
  2365. post_blend_mode = mode;
  2366. if ((post_blend_mode == 3) && (field_counter <= 2)) {
  2367. post_blend_en = 0;
  2368. post_blend_mode = 2;
  2369. }
  2370. enable_di_post(
  2371. &di_buf0_mif,
  2372. &di_buf1_mif,
  2373. NULL,
  2374. &di_mtncrd_mif,
  2375. &di_mtnprd_mif,
  2376. 1, // ei enable
  2377. post_blend_en, // blend enable
  2378. post_blend_en, // blend mtn enable
  2379. post_blend_mode, // blend mode.
  2380. 1, // di_vpp_en.
  2381. 0, // di_ddr_en.
  2382. #if defined(CONFIG_ARCH_MESON)
  2383. #elif defined(CONFIG_ARCH_MESON2)
  2384. 1, // blend_mtn_filt_en
  2385. 1, // blend_data_filt_en
  2386. post_mb_en, // post_mb_en
  2387. #endif
  2388. (type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP ? 0 : 1, // 1 bottom generate top
  2389. hold_line
  2390. );
  2391. }
  2392. }
  2393. void di_pre_timer_func(unsigned long arg)
  2394. {
  2395. struct timer_list *timer = (struct timer_list *)arg;
  2396. schedule_work(&di_pre_work);
  2397. timer->expires = jiffies + DI_PRE_INTERVAL;
  2398. add_timer(timer);
  2399. }
  2400. void deinterlace_init(void)
  2401. {
  2402. di_mem_mif.chroma_x_start0 = 0;
  2403. di_mem_mif.chroma_x_end0 = 0;
  2404. di_mem_mif.chroma_y_start0 = 0;
  2405. di_mem_mif.chroma_y_end0 = 0;
  2406. di_mem_mif.video_mode = 0;
  2407. di_mem_mif.set_separate_en = 0;
  2408. di_mem_mif.src_field_mode = 0;
  2409. di_mem_mif.output_field_num = 0;
  2410. di_mem_mif.burst_size_y = 3;
  2411. di_mem_mif.burst_size_cb = 0;
  2412. di_mem_mif.burst_size_cr = 0;
  2413. di_mem_mif.canvas0_addr1 = 0;
  2414. di_mem_mif.canvas0_addr2 = 0;
  2415. memcpy(&di_buf0_mif, &di_mem_mif, sizeof(DI_MIF_t));
  2416. memcpy(&di_buf1_mif, &di_mem_mif, sizeof(DI_MIF_t));
  2417. memcpy(&di_chan2_mif, &di_buf1_mif, sizeof(DI_MIF_t));
  2418. WRITE_MPEG_REG(DI_PRE_HOLD, (1 << 31) | (31 << 16) | 31);
  2419. #if defined(CONFIG_ARCH_MESON)
  2420. WRITE_MPEG_REG(DI_NRMTN_CTRL0, 0xb00a0603);
  2421. #endif
  2422. INIT_WORK(&di_pre_work, di_pre_isr);
  2423. init_timer(&di_pre_timer);
  2424. di_pre_timer.data = (ulong) & di_pre_timer;
  2425. di_pre_timer.function = di_pre_timer_func;
  2426. di_pre_timer.expires = jiffies + DI_PRE_INTERVAL;
  2427. add_timer(&di_pre_timer);
  2428. }
  2429. static int deinterlace_probe(struct platform_device *pdev)
  2430. {
  2431. struct resource *mem;
  2432. printk("Amlogic deinterlace init\n");
  2433. if (!(mem = platform_get_resource(pdev, IORESOURCE_MEM, 0))) {
  2434. printk("\ndeinterlace memory resource undefined.\n");
  2435. return -EFAULT;
  2436. }
  2437. // declare deinterlace memory
  2438. di_mem_start = mem->start;
  2439. printk("Deinterlace memory: start = 0x%x, end = 0x%x\n", di_mem_start, mem->end);
  2440. deinterlace_init();
  2441. return 0;
  2442. }
  2443. static int deinterlace_remove(struct platform_device *pdev)
  2444. {
  2445. printk("Amlogic deinterlace release\n");
  2446. del_timer_sync(&di_pre_timer);
  2447. return 0;
  2448. }
  2449. static struct platform_driver
  2450. deinterlace_driver = {
  2451. .probe = deinterlace_probe,
  2452. .remove = deinterlace_remove,
  2453. .driver = {
  2454. .name = "deinterlace",
  2455. }
  2456. };
  2457. static int __init deinterlace_module_init(void)
  2458. {
  2459. if (platform_driver_register(&deinterlace_driver)) {
  2460. printk("failed to register deinterlace module\n");
  2461. return -ENODEV;
  2462. }
  2463. return 0;
  2464. }
  2465. static void __exit deinterlace_module_exit(void)
  2466. {
  2467. platform_driver_unregister(&deinterlace_driver);
  2468. return;
  2469. }
  2470. MODULE_PARM_DESC(deinterlace_mode, "\n deinterlace mode \n");
  2471. module_param(deinterlace_mode, int, 0664);
  2472. #if defined(CONFIG_ARCH_MESON2)
  2473. MODULE_PARM_DESC(noise_reduction_level, "\n noise reduction level \n");
  2474. module_param(noise_reduction_level, int, 0664);
  2475. #endif
  2476. module_init(deinterlace_module_init);
  2477. module_exit(deinterlace_module_exit);
  2478. MODULE_DESCRIPTION("AMLOGIC deinterlace driver");
  2479. MODULE_LICENSE("GPL");
  2480. MODULE_AUTHOR("Qi Wang <qi.wang@amlogic.com>");