deinterlace.c 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348
  1. /*
  2. * Amlogic M2
  3. * frame buffer driver-----------Deinterlace
  4. * Copyright (C) 2010 Amlogic, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the named License,
  9. * or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/version.h>
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/kernel.h>
  21. #include <linux/kthread.h>
  22. #include <linux/semaphore.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/fs.h>
  28. #include <linux/init.h>
  29. #include <linux/device.h>
  30. #include <linux/mm.h>
  31. #include <linux/major.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/mutex.h>
  34. #include <linux/cdev.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/list.h>
  37. //#include <linux/aml_common.h>
  38. #include <asm/uaccess.h>
  39. #include <mach/am_regs.h>
  40. #include <linux/osd/osd_dev.h>
  41. #include <linux/amports/vframe.h>
  42. #include <linux/amports/vframe_provider.h>
  43. #include <linux/amports/vframe_receiver.h>
  44. #include <linux/amports/canvas.h>
  45. //#include <linux/fiq_bridge.h>
  46. #include "deinterlace.h"
  47. #include "deinterlace_module.h"
  48. #if defined(CONFIG_ARCH_MESON2)
  49. #define FORCE_BOB_SUPPORT
  50. #endif
  51. //#define RUN_DI_PROCESS_IN_IRQ
  52. //#define RUN_DI_PROCESS_IN_TIMER
  53. //#define GET_VFRAME_DIRECTLY
  54. #undef USE_LIST
  55. #ifdef GET_VFRAME_DIRECTLY
  56. #define raw_local_save_flags(fiq_flag)
  57. #define local_fiq_disable()
  58. #define raw_local_irq_restore(fiq_flag)
  59. static struct vframe_provider_s * prov = NULL;
  60. #endif
  61. #if defined(CONFIG_ARCH_MESON6)
  62. #undef FIQ_VSYNC
  63. #define raw_local_save_flags(fiq_flag)
  64. #define local_fiq_disable()
  65. #define raw_local_irq_restore(fiq_flag)
  66. #else
  67. #define FIQ_VSYNC
  68. #endif
  69. #define CHECK_VDIN_BUF_ERROR
  70. #define DEVICE_NAME "deinterlace"
  71. #ifdef DEBUG
  72. #define pr_dbg(fmt, args...) printk(KERN_DEBUG "DI: " fmt, ## args)
  73. #else
  74. #define pr_dbg(fmt, args...)
  75. #endif
  76. #define pr_error(fmt, args...) printk(KERN_ERR "DI: " fmt, ## args)
  77. #define Wr(adr, val) WRITE_MPEG_REG(adr, val)
  78. #define Rd(adr) READ_MPEG_REG(adr)
  79. extern void timestamp_pcrscr_enable(u32 enable);
  80. static DEFINE_SPINLOCK(plist_lock);
  81. static di_dev_t di_device;
  82. static dev_t di_id;
  83. static struct class *di_class;
  84. #define INIT_FLAG_NOT_LOAD 0x80
  85. static int version = 5;
  86. static unsigned char boot_init_flag=0;
  87. static int receiver_is_amvideo = 1;
  88. static int buf_mgr_mode = 0;
  89. static int buf_mgr_mode_mask = 0xf;
  90. static int bypass_state = 0;
  91. static int bypass_prog = 0;
  92. static int bypass_hd = 0;
  93. static int bypass_all = 0;
  94. static int bypass_vscale_skip = 0;
  95. static int bypass_get_buf_threshold = 4;
  96. /* prog_proc_config,
  97. bit[0]: only valid when real_buf_mgr_mode[bit0]==0, when real_buf_mgr_mode[bit0]==1, two field buffers are used for "prog vdin"
  98. 0 "prog vdin" use two field buffers, 1 "prog vdin" use single frame buffer
  99. bit[2:1]: when two field buffers are used, 0 use vpp for blending ,
  100. 1 use post_di module for blending
  101. 2 debug mode, bob with top field
  102. 3 debug mode, bot with bot field
  103. */
  104. static int prog_proc_config = (1<<1)|1; /*
  105. for source include both progressive and interlace pictures,
  106. always use post_di module for blending
  107. */
  108. static int pulldown_detect = 0x10;
  109. static int skip_wrong_field = 1;
  110. static int frame_count = 0;
  111. static int provider_vframe_level = 0;
  112. static int frame_packing_mode = 1;
  113. static int disp_frame_count = 0;
  114. static int start_frame_drop_count = 0;
  115. static int start_frame_hold_count = 0;
  116. static int pre_de_irq_check = 0;
  117. static int force_bob_flag = 0;
  118. int di_vscale_skip_count = 0;
  119. static uint init_flag=0;
  120. static unsigned char active_flag=0;
  121. static unsigned char recovery_flag=0;
  122. #define VFM_NAME "deinterlace"
  123. static long same_field_top_count = 0;
  124. static long same_field_bot_count = 0;
  125. static long same_w_r_canvas_count = 0;
  126. static long pulldown_count = 0;
  127. static long pulldown_buffer_mode = 1; /* bit 0:
  128. 0, keep 3 buffers in pre_ready_list for checking;
  129. 1, keep 4 buffers in pre_ready_list for checking;
  130. */
  131. static long pulldown_win_mode = 0x11111;
  132. static int same_field_source_flag_th = 60;
  133. int nr_hfilt_en = 0;
  134. #define real_buf_mgr_mode (((buf_mgr_mode|(get_blackout_policy()==0))&buf_mgr_mode_mask)|(buf_mgr_mode_mask>>16))
  135. #define DisableVideoLayer() \
  136. do { CLEAR_MPEG_REG_MASK(VPP_MISC, \
  137. VPP_VD1_PREBLEND|VPP_VD2_PREBLEND|VPP_VD2_POSTBLEND|VPP_VD1_POSTBLEND ); \
  138. } while (0)
  139. static int di_receiver_event_fun(int type, void* data, void* arg);
  140. static void di_uninit_buf(void);
  141. static unsigned char is_bypass(void);
  142. static void log_buffer_state(unsigned char* tag);
  143. u32 get_blackout_policy(void);
  144. static void put_get_disp_buf(void);
  145. static const struct vframe_receiver_op_s di_vf_receiver =
  146. {
  147. .event_cb = di_receiver_event_fun
  148. };
  149. static struct vframe_receiver_s di_vf_recv;
  150. static vframe_t *di_vf_peek(void* arg);
  151. static vframe_t *di_vf_get(void* arg);
  152. static void di_vf_put(vframe_t *vf, void* arg);
  153. static int di_event_cb(int type, void *data, void *private_data);
  154. static void di_process(void);
  155. static int get_current_vscale_skip_count(void);
  156. static const struct vframe_operations_s deinterlace_vf_provider =
  157. {
  158. .peek = di_vf_peek,
  159. .get = di_vf_get,
  160. .put = di_vf_put,
  161. .event_cb = di_event_cb,
  162. };
  163. static struct vframe_provider_s di_vf_prov;
  164. int di_sema_init_flag = 0;
  165. static struct semaphore di_sema;
  166. #ifdef FIQ_VSYNC
  167. static bridge_item_t fiq_handle_item;
  168. static irqreturn_t di_vf_put_isr(int irq, void *dev_id)
  169. {
  170. #ifdef RUN_DI_PROCESS_IN_IRQ
  171. int i;
  172. for(i=0; i<2; i++){
  173. if(active_flag){
  174. di_process();
  175. }
  176. }
  177. #else
  178. up(&di_sema);
  179. #endif
  180. return IRQ_HANDLED;
  181. }
  182. #endif
  183. void trigger_pre_di_process(char idx)
  184. {
  185. if(di_sema_init_flag == 0)
  186. return ;
  187. if(idx!='p')
  188. {
  189. log_buffer_state((idx=='i')?"irq":((idx=='p')?"put":((idx=='r')?"rdy":"oth")));
  190. }
  191. #ifndef RUN_DI_PROCESS_IN_TIMER
  192. #ifdef RUN_DI_PROCESS_IN_IRQ
  193. fiq_bridge_pulse_trigger(&fiq_handle_item);
  194. #else
  195. #ifdef FIQ_VSYNC
  196. if(idx == 'p'){
  197. fiq_bridge_pulse_trigger(&fiq_handle_item);
  198. }
  199. else
  200. #endif
  201. {
  202. up(&di_sema);
  203. }
  204. #endif
  205. #endif
  206. }
  207. #define DI_PRE_INTERVAL (HZ/100)
  208. static struct timer_list di_pre_timer;
  209. static struct work_struct di_pre_work;
  210. static void di_pre_timer_cb(unsigned long arg)
  211. {
  212. struct timer_list *timer = (struct timer_list *)arg;
  213. schedule_work(&di_pre_work);
  214. timer->expires = jiffies + DI_PRE_INTERVAL;
  215. add_timer(timer);
  216. }
  217. /*****************************
  218. * di attr management :
  219. * enable
  220. * mode
  221. * reg
  222. ******************************/
  223. /*config attr*/
  224. static ssize_t show_config(struct device * dev, struct device_attribute *attr, char * buf)
  225. {
  226. int pos=0;
  227. return pos;
  228. }
  229. static ssize_t store_config(struct device * dev, struct device_attribute *attr, const char * buf, size_t count);
  230. static void dump_state(void);
  231. static void force_source_change(void);
  232. #define DI_RUN_FLAG_RUN 0
  233. #define DI_RUN_FLAG_PAUSE 1
  234. #define DI_RUN_FLAG_STEP 2
  235. #define DI_RUN_FLAG_STEP_DONE 3
  236. static int run_flag = DI_RUN_FLAG_RUN;
  237. static ssize_t store_dbg(struct device * dev, struct device_attribute *attr, const char * buf, size_t count)
  238. {
  239. if(strncmp(buf, "state", 4)==0){
  240. dump_state();
  241. }
  242. else if(strncmp(buf,"bypass_prog", 11)==0){
  243. force_source_change();
  244. if(buf[11]=='1'){
  245. bypass_prog = 1;
  246. }
  247. else{
  248. bypass_prog = 0;
  249. }
  250. }
  251. else if(strncmp(buf, "prog_proc_config", 16)==0){
  252. if(buf[16]=='1'){
  253. prog_proc_config = 1;
  254. }
  255. else{
  256. prog_proc_config = 0;
  257. }
  258. }
  259. else if(strncmp(buf, "time_div", 8)==0){
  260. }
  261. else if(strncmp(buf, "show_osd", 8)==0){
  262. Wr(VIU_OSD1_CTRL_STAT, Rd(VIU_OSD1_CTRL_STAT)|(0xff<<12));
  263. }
  264. else if(strncmp(buf, "run", 3)==0){
  265. //timestamp_pcrscr_enable(1);
  266. run_flag = DI_RUN_FLAG_RUN;
  267. }
  268. else if(strncmp(buf, "pause", 5)==0){
  269. //timestamp_pcrscr_enable(0);
  270. run_flag = DI_RUN_FLAG_PAUSE;
  271. }
  272. else if(strncmp(buf, "step", 4)==0){
  273. run_flag = DI_RUN_FLAG_STEP;
  274. }
  275. else if(strncmp(buf, "dumptsync", 9) == 0){
  276. }
  277. else if(strncmp(buf, "robust_test", 11) == 0){
  278. }
  279. return count;
  280. }
  281. static unsigned char* di_log_buf=NULL;
  282. static unsigned int di_log_wr_pos=0;
  283. static unsigned int di_log_rd_pos=0;
  284. static unsigned int di_log_buf_size=0;
  285. static unsigned int di_printk_flag=0;
  286. unsigned int di_log_flag=0;
  287. unsigned int buf_state_log_threshold = 16;
  288. unsigned int buf_state_log_start = 0; /* set to 1 by condition of "post_ready count < buf_state_log_threshold",
  289. reset to 0 by set buf_state_log_threshold as 0 */
  290. static DEFINE_SPINLOCK(di_print_lock);
  291. #define PRINT_TEMP_BUF_SIZE 128
  292. int di_print_buf(char* buf, int len)
  293. {
  294. unsigned long flags;
  295. int pos;
  296. int di_log_rd_pos_;
  297. if(di_log_buf_size==0)
  298. return 0;
  299. spin_lock_irqsave(&di_print_lock, flags);
  300. di_log_rd_pos_=di_log_rd_pos;
  301. if(di_log_wr_pos>=di_log_rd_pos)
  302. di_log_rd_pos_+=di_log_buf_size;
  303. for(pos=0;pos<len && di_log_wr_pos<(di_log_rd_pos_-1);pos++,di_log_wr_pos++){
  304. if(di_log_wr_pos>=di_log_buf_size)
  305. di_log_buf[di_log_wr_pos-di_log_buf_size]=buf[pos];
  306. else
  307. di_log_buf[di_log_wr_pos]=buf[pos];
  308. }
  309. if(di_log_wr_pos>=di_log_buf_size)
  310. di_log_wr_pos-=di_log_buf_size;
  311. spin_unlock_irqrestore(&di_print_lock, flags);
  312. return pos;
  313. }
  314. //static int log_seq = 0;
  315. #if 0
  316. #define di_print printk
  317. #else
  318. int di_print(const char *fmt, ...)
  319. {
  320. va_list args;
  321. int avail = PRINT_TEMP_BUF_SIZE;
  322. char buf[PRINT_TEMP_BUF_SIZE];
  323. int pos,len=0;
  324. if(di_printk_flag&1){
  325. va_start(args, fmt);
  326. vprintk(fmt, args);
  327. va_end(args);
  328. return 0;
  329. }
  330. if(di_log_buf_size==0)
  331. return 0;
  332. //len += snprintf(buf+len, avail-len, "%d:",log_seq++);
  333. if(di_log_flag&DI_LOG_TIMESTAMP){
  334. len += snprintf(buf+len, avail-len, "%u:", (unsigned int)jiffies);
  335. }
  336. else if(di_log_flag&DI_LOG_PRECISE_TIMESTAMP){
  337. #ifndef CONFIG_ARCH_MESON6
  338. if(READ_MPEG_REG(ISA_TIMERB)==0){
  339. WRITE_MPEG_REG(ISA_TIMER_MUX, (READ_MPEG_REG(ISA_TIMER_MUX)&(~(3<<TIMER_B_INPUT_BIT)))
  340. |(TIMER_UNIT_100us<<TIMER_B_INPUT_BIT)|(1<<13)|(1<<17));
  341. WRITE_MPEG_REG(ISA_TIMERB, 0xffff);
  342. printk("Deinterlace: Init 100us TimerB\n");
  343. }
  344. len += snprintf(buf+len, avail-len, "%u:", (unsigned int)(0x10000-READ_MPEG_REG(ISA_TIMERB)));
  345. #endif
  346. }
  347. va_start(args, fmt);
  348. len += vsnprintf(buf+len, avail-len, fmt, args);
  349. va_end(args);
  350. if ((avail-len) <= 0) {
  351. buf[PRINT_TEMP_BUF_SIZE - 1] = '\0';
  352. }
  353. pos = di_print_buf(buf, len);
  354. //printk("di_print:%d %d\n", di_log_wr_pos, di_log_rd_pos);
  355. return pos;
  356. }
  357. #endif
  358. static ssize_t read_log(char * buf)
  359. {
  360. unsigned long flags;
  361. ssize_t read_size=0;
  362. if(di_log_buf_size==0)
  363. return 0;
  364. //printk("show_log:%d %d\n", di_log_wr_pos, di_log_rd_pos);
  365. spin_lock_irqsave(&di_print_lock, flags);
  366. if(di_log_rd_pos<di_log_wr_pos){
  367. read_size = di_log_wr_pos-di_log_rd_pos;
  368. }
  369. else if(di_log_rd_pos>di_log_wr_pos){
  370. read_size = di_log_buf_size-di_log_rd_pos;
  371. }
  372. if(read_size>PAGE_SIZE)
  373. read_size=PAGE_SIZE;
  374. if(read_size>0)
  375. memcpy(buf, di_log_buf+di_log_rd_pos, read_size);
  376. di_log_rd_pos += read_size;
  377. if(di_log_rd_pos>=di_log_buf_size)
  378. di_log_rd_pos = 0;
  379. spin_unlock_irqrestore(&di_print_lock, flags);
  380. return read_size;
  381. }
  382. static ssize_t show_log(struct device * dev, struct device_attribute *attr, char * buf)
  383. {
  384. return read_log(buf);
  385. }
  386. #ifdef DI_DEBUG
  387. char log_tmp_buf[PAGE_SIZE];
  388. static void dump_log(void)
  389. {
  390. while(read_log(log_tmp_buf)>0){
  391. printk("%s", log_tmp_buf);
  392. }
  393. }
  394. #endif
  395. static ssize_t store_log(struct device * dev, struct device_attribute *attr, const char * buf, size_t count)
  396. {
  397. int tmp;
  398. unsigned long flags;
  399. if(strncmp(buf, "bufsize", 7)==0){
  400. tmp = simple_strtoul(buf+7,NULL,10);
  401. spin_lock_irqsave(&di_print_lock, flags);
  402. if(di_log_buf){
  403. kfree(di_log_buf);
  404. di_log_buf=NULL;
  405. di_log_buf_size=0;
  406. di_log_rd_pos=0;
  407. di_log_wr_pos=0;
  408. }
  409. if(tmp>=1024){
  410. di_log_buf_size=0;
  411. di_log_rd_pos=0;
  412. di_log_wr_pos=0;
  413. di_log_buf=kmalloc(tmp, GFP_KERNEL);
  414. if(di_log_buf){
  415. di_log_buf_size=tmp;
  416. }
  417. }
  418. spin_unlock_irqrestore(&di_print_lock, flags);
  419. printk("di_store:set bufsize tmp %d %d\n",tmp, di_log_buf_size);
  420. }
  421. else if(strncmp(buf, "printk", 6)==0){
  422. di_printk_flag = simple_strtoul(buf+6, NULL, 10);
  423. }
  424. else{
  425. di_print(0, "%s", buf);
  426. }
  427. return 16;
  428. }
  429. static int set_noise_reduction_level(void)
  430. {
  431. int nr_zone_0 = 4, nr_zone_1 = 8, nr_zone_2 = 12;
  432. //int nr_hfilt_en = 0;
  433. int nr_hfilt_mb_en = 0;
  434. /* int post_mb_en = 0;
  435. int blend_mtn_filt_en = 1;
  436. int blend_data_filt_en = 1;
  437. */
  438. unsigned int nr_strength = 0, nr_gain2 = 0, nr_gain1 = 0, nr_gain0 = 0;
  439. nr_strength = noise_reduction_level;
  440. if (nr_strength > 64)
  441. nr_strength = 64;
  442. nr_gain2 = 64 - nr_strength;
  443. nr_gain1 = nr_gain2 - ((nr_gain2 * nr_strength + 32) >> 6);
  444. nr_gain0 = nr_gain1 - ((nr_gain1 * nr_strength + 32) >> 6);
  445. nr_ctrl1 = (64 << 24) | (nr_gain2 << 16) | (nr_gain1 << 8) | (nr_gain0 << 0);
  446. nr_ctrl0 = (1 << 31 ) | // nr yuv enable.
  447. (1 << 30 ) | // nr range. 3 point
  448. (0 << 29 ) | // max of 3 point.
  449. (nr_hfilt_en << 28 ) | // nr hfilter enable.
  450. (nr_hfilt_mb_en << 27 ) | // nr hfilter motion_blur enable.
  451. (nr_zone_2 <<16 ) | // zone 2
  452. (nr_zone_1 << 8 ) | // zone 1
  453. (nr_zone_0 << 0 ) ; // zone 0
  454. // blend_ctrl = ( post_mb_en << 28 ) | // post motion blur enable.
  455. // ( 0 << 27 ) | // mtn3p(l, c, r) max.
  456. // ( 0 << 26 ) | // mtn3p(l, c, r) min.
  457. // ( 0 << 25 ) | // mtn3p(l, c, r) ave.
  458. // ( 1 << 24 ) | // mtntopbot max
  459. // ( blend_mtn_filt_en << 23 ) | // blend mtn filter enable.
  460. // ( blend_data_filt_en << 22 ) | // blend data filter enable.
  461. // kdeint0; // kdeint.
  462. return 0;
  463. }
  464. typedef struct{
  465. char* name;
  466. uint* param;
  467. int (*proc_fun)(void);
  468. }di_param_t;
  469. unsigned long reg_mtn_info[7];
  470. di_param_t di_params[]=
  471. {
  472. {"ei_ctrl0", &ei_ctrl0, NULL },
  473. {"ei_ctrl1", &ei_ctrl1, NULL },
  474. {"ei_ctrl2", &ei_ctrl2, NULL },
  475. {"nr_ctrl0", &nr_ctrl0, NULL },
  476. {"nr_ctrl1", &nr_ctrl1, NULL },
  477. {"nr_ctrl2", &nr_ctrl2, NULL },
  478. {"nr_ctrl3", &nr_ctrl3, NULL },
  479. {"mtn_ctrl_char_diff_cnt", &mtn_ctrl_char_diff_cnt, NULL },
  480. {"mtn_ctrl_low_level", &mtn_ctrl_low_level, NULL },
  481. {"mtn_ctrl_high_level", &mtn_ctrl_high_level, NULL },
  482. {"mtn_ctrl", &mtn_ctrl, NULL},
  483. {"mtn_ctrl_diff_level", &mtn_ctrl_diff_level, NULL },
  484. {"mtn_ctrl1_reduce", &mtn_ctrl1_reduce, NULL },
  485. {"mtn_ctrl1_shift", &mtn_ctrl1_shift, NULL },
  486. {"mtn_ctrl1", &mtn_ctrl1, NULL},
  487. {"blend_ctrl", &blend_ctrl, NULL },
  488. {"kdeint0", &kdeint0, NULL },
  489. {"kdeint1", &kdeint1, NULL },
  490. {"kdeint2", &kdeint2, NULL },
  491. {"blend_ctrl1", &blend_ctrl1, NULL },
  492. {"blend_ctrl1_char_level", &blend_ctrl1_char_level, NULL},
  493. {"blend_ctrl1_angle_thd", &blend_ctrl1_angle_thd, NULL},
  494. {"blend_ctrl1_filt_thd", &blend_ctrl1_filt_thd, NULL},
  495. {"blend_ctrl1_diff_thd", &blend_ctrl1_diff_thd, NULL},
  496. {"blend_ctrl2", &blend_ctrl2, NULL },
  497. {"blend_ctrl2_black_level", &blend_ctrl2_black_level, NULL},
  498. {"blend_ctrl2_mtn_no_mov", &blend_ctrl2_mtn_no_mov, NULL},
  499. {"mtn_thre_1_low",&mtn_thre_1_low,NULL},
  500. {"mtn_thre_1_high",&mtn_thre_1_high,NULL},
  501. {"mtn_thre_2_low",&mtn_thre_2_low,NULL},
  502. {"mtn_thre_2_high",&mtn_thre_2_high,NULL},
  503. {"mtn_info0",((uint*)&reg_mtn_info[0]) ,NULL},
  504. {"mtn_info1",((uint*)&reg_mtn_info[1]) ,NULL},
  505. {"mtn_info2",((uint*)&reg_mtn_info[2]) ,NULL},
  506. {"mtn_info3",((uint*)&reg_mtn_info[3]) ,NULL},
  507. {"mtn_info4",((uint*)&reg_mtn_info[4]) ,NULL},
  508. {"mtn_info5",((uint*)&reg_mtn_info[5]) ,NULL},
  509. {"mtn_info6",((uint*)&reg_mtn_info[6]) ,NULL},
  510. {"post_ctrl__di_blend_en", &post_ctrl__di_blend_en, NULL},
  511. {"post_ctrl__di_post_repeat", &post_ctrl__di_post_repeat, NULL},
  512. {"di_pre_ctrl__di_pre_repeat", &di_pre_ctrl__di_pre_repeat, NULL},
  513. {"noise_reduction_level", &noise_reduction_level, set_noise_reduction_level},
  514. {"field_32lvl", &field_32lvl, NULL},
  515. {"field_22lvl", &field_22lvl, NULL},
  516. {"field_pd_frame_diff_chg_th", &(field_pd_th.frame_diff_chg_th), NULL},
  517. {"field_pd_frame_diff_num_chg_th", &(field_pd_th.frame_diff_num_chg_th), NULL},
  518. {"field_pd_field_diff_chg_th", &(field_pd_th.field_diff_chg_th), NULL},
  519. {"field_pd_field_diff_num_chg_th", &(field_pd_th.field_diff_num_chg_th), NULL},
  520. {"field_pd_frame_diff_skew_th", &(field_pd_th.frame_diff_skew_th), NULL},
  521. {"field_pd_frame_diff_num_skew_th", &(field_pd_th.frame_diff_num_skew_th), NULL},
  522. {"win0_start_x_r", &pd_win_prop[0].win_start_x_r, NULL},
  523. {"win0_end_x_r", &pd_win_prop[0].win_end_x_r, NULL},
  524. {"win0_start_y_r", &pd_win_prop[0].win_start_y_r, NULL},
  525. {"win0_end_y_r", &pd_win_prop[0].win_end_y_r, NULL},
  526. {"win0_32lvl", &pd_win_prop[0].win_32lvl, NULL},
  527. {"win0_22lvl", &pd_win_prop[0].win_22lvl, NULL},
  528. {"win0_pd_frame_diff_chg_th", &(win_pd_th[0].frame_diff_chg_th), NULL},
  529. {"win0_pd_frame_diff_num_chg_th", &(win_pd_th[0].frame_diff_num_chg_th), NULL},
  530. {"win0_pd_field_diff_chg_th", &(win_pd_th[0].field_diff_chg_th), NULL},
  531. {"win0_pd_field_diff_num_chg_th", &(win_pd_th[0].field_diff_num_chg_th), NULL},
  532. {"win0_pd_frame_diff_skew_th", &(win_pd_th[0].frame_diff_skew_th), NULL},
  533. {"win0_pd_frame_diff_num_skew_th", &(win_pd_th[0].frame_diff_num_skew_th), NULL},
  534. {"win0_pd_field_diff_num_th", &(win_pd_th[0].field_diff_num_th), NULL},
  535. {"win1_start_x_r", &pd_win_prop[1].win_start_x_r, NULL},
  536. {"win1_end_x_r", &pd_win_prop[1].win_end_x_r, NULL},
  537. {"win1_start_y_r", &pd_win_prop[1].win_start_y_r, NULL},
  538. {"win1_end_y_r", &pd_win_prop[1].win_end_y_r, NULL},
  539. {"win1_32lvl", &pd_win_prop[1].win_32lvl, NULL},
  540. {"win1_22lvl", &pd_win_prop[1].win_22lvl, NULL},
  541. {"win1_pd_frame_diff_chg_th", &(win_pd_th[1].frame_diff_chg_th), NULL},
  542. {"win1_pd_frame_diff_num_chg_th", &(win_pd_th[1].frame_diff_num_chg_th), NULL},
  543. {"win1_pd_field_diff_chg_th", &(win_pd_th[1].field_diff_chg_th), NULL},
  544. {"win1_pd_field_diff_num_chg_th", &(win_pd_th[1].field_diff_num_chg_th), NULL},
  545. {"win1_pd_frame_diff_skew_th", &(win_pd_th[1].frame_diff_skew_th), NULL},
  546. {"win1_pd_frame_diff_num_skew_th", &(win_pd_th[1].frame_diff_num_skew_th), NULL},
  547. {"win1_pd_field_diff_num_th", &(win_pd_th[1].field_diff_num_th), NULL},
  548. {"win2_start_x_r", &pd_win_prop[2].win_start_x_r, NULL},
  549. {"win2_end_x_r", &pd_win_prop[2].win_end_x_r, NULL},
  550. {"win2_start_y_r", &pd_win_prop[2].win_start_y_r, NULL},
  551. {"win2_end_y_r", &pd_win_prop[2].win_end_y_r, NULL},
  552. {"win2_32lvl", &pd_win_prop[2].win_32lvl, NULL},
  553. {"win2_22lvl", &pd_win_prop[2].win_22lvl, NULL},
  554. {"win2_pd_frame_diff_chg_th", &(win_pd_th[2].frame_diff_chg_th), NULL},
  555. {"win2_pd_frame_diff_num_chg_th", &(win_pd_th[2].frame_diff_num_chg_th), NULL},
  556. {"win2_pd_field_diff_chg_th", &(win_pd_th[2].field_diff_chg_th), NULL},
  557. {"win2_pd_field_diff_num_chg_th", &(win_pd_th[2].field_diff_num_chg_th), NULL},
  558. {"win2_pd_frame_diff_skew_th", &(win_pd_th[2].frame_diff_skew_th), NULL},
  559. {"win2_pd_frame_diff_num_skew_th", &(win_pd_th[2].frame_diff_num_skew_th), NULL},
  560. {"win2_pd_field_diff_num_th", &(win_pd_th[2].field_diff_num_th), NULL},
  561. {"win3_start_x_r", &pd_win_prop[3].win_start_x_r, NULL},
  562. {"win3_end_x_r", &pd_win_prop[3].win_end_x_r, NULL},
  563. {"win3_start_y_r", &pd_win_prop[3].win_start_y_r, NULL},
  564. {"win3_end_y_r", &pd_win_prop[3].win_end_y_r, NULL},
  565. {"win3_32lvl", &pd_win_prop[3].win_32lvl, NULL},
  566. {"win3_22lvl", &pd_win_prop[3].win_22lvl, NULL},
  567. {"win3_pd_frame_diff_chg_th", &(win_pd_th[3].frame_diff_chg_th), NULL},
  568. {"win3_pd_frame_diff_num_chg_th", &(win_pd_th[3].frame_diff_num_chg_th), NULL},
  569. {"win3_pd_field_diff_chg_th", &(win_pd_th[3].field_diff_chg_th), NULL},
  570. {"win3_pd_field_diff_num_chg_th", &(win_pd_th[3].field_diff_num_chg_th), NULL},
  571. {"win3_pd_frame_diff_skew_th", &(win_pd_th[3].frame_diff_skew_th), NULL},
  572. {"win3_pd_frame_diff_num_skew_th", &(win_pd_th[3].frame_diff_num_skew_th), NULL},
  573. {"win3_pd_field_diff_num_th", &(win_pd_th[3].field_diff_num_th), NULL},
  574. {"win4_start_x_r", &pd_win_prop[4].win_start_x_r, NULL},
  575. {"win4_end_x_r", &pd_win_prop[4].win_end_x_r, NULL},
  576. {"win4_start_y_r", &pd_win_prop[4].win_start_y_r, NULL},
  577. {"win4_end_y_r", &pd_win_prop[4].win_end_y_r, NULL},
  578. {"win4_32lvl", &pd_win_prop[4].win_32lvl, NULL},
  579. {"win4_22lvl", &pd_win_prop[4].win_22lvl, NULL},
  580. {"win4_pd_frame_diff_chg_th", &(win_pd_th[4].frame_diff_chg_th), NULL},
  581. {"win4_pd_frame_diff_num_chg_th", &(win_pd_th[4].frame_diff_num_chg_th), NULL},
  582. {"win4_pd_field_diff_chg_th", &(win_pd_th[4].field_diff_chg_th), NULL},
  583. {"win4_pd_field_diff_num_chg_th", &(win_pd_th[4].field_diff_num_chg_th), NULL},
  584. {"win4_pd_frame_diff_skew_th", &(win_pd_th[4].frame_diff_skew_th), NULL},
  585. {"win4_pd_frame_diff_num_skew_th", &(win_pd_th[4].frame_diff_num_skew_th), NULL},
  586. {"win4_pd_field_diff_num_th", &(win_pd_th[4].field_diff_num_th), NULL},
  587. {"pd32_match_num", &pd32_match_num, NULL},
  588. {"pd32_diff_num_0_th", &pd32_diff_num_0_th, NULL},
  589. {"pd32_debug_th", &pd32_debug_th, NULL},
  590. {"pd22_th", &pd22_th, NULL},
  591. {"pd22_num_th", &pd22_num_th, NULL},
  592. {"", NULL}
  593. };
  594. static ssize_t show_parameters(struct device * dev, struct device_attribute *attr, char * buf)
  595. {
  596. int i = 0;
  597. int len = 0;
  598. for(i=0; di_params[i].param; i++){
  599. len += sprintf(buf+len, "%s=%08x\n", di_params[i].name, *(di_params[i].param));
  600. }
  601. return len;
  602. }
  603. static char tmpbuf[128];
  604. static ssize_t store_parameters(struct device * dev, struct device_attribute *attr, const char * buf, size_t count)
  605. {
  606. int i = 0;
  607. int j;
  608. while((buf[i])&&(buf[i]!='=')&&(buf[i]!=' ')){
  609. tmpbuf[i]=buf[i];
  610. i++;
  611. }
  612. tmpbuf[i]=0;
  613. //printk("%s\n", tmpbuf);
  614. if(strcmp("reset", tmpbuf)==0){
  615. reset_di_para();
  616. di_print("reset param\n");
  617. }
  618. else{
  619. for(j=0; di_params[j].param; j++){
  620. if(strcmp(di_params[j].name, tmpbuf)==0){
  621. int value=simple_strtoul(buf+i+1, NULL, 16);
  622. *(di_params[j].param) = value;
  623. if(di_params[j].proc_fun){
  624. di_params[j].proc_fun();
  625. }
  626. di_print("set %s=%x\n", di_params[j].name, value);
  627. break;
  628. }
  629. }
  630. }
  631. return count;
  632. }
  633. typedef struct{
  634. char* name;
  635. uint* status;
  636. }di_status_t;
  637. di_status_t di_status[]=
  638. {
  639. {"active", &init_flag },
  640. {"", NULL}
  641. };
  642. static ssize_t show_status(struct device * dev, struct device_attribute *attr, char * buf)
  643. {
  644. int i = 0;
  645. int len = 0;
  646. di_print("%s\n", __func__);
  647. for(i=0; di_status[i].status; i++){
  648. len += sprintf(buf+len, "%s=%08x\n", di_status[i].name, *(di_status[i].status));
  649. }
  650. return len;
  651. }
  652. static DEVICE_ATTR(config, S_IWUGO | S_IRUGO, show_config, store_config);
  653. static DEVICE_ATTR(parameters, S_IWUGO | S_IRUGO, show_parameters, store_parameters);
  654. static DEVICE_ATTR(debug, S_IWUGO | S_IRUGO, NULL, store_dbg);
  655. static DEVICE_ATTR(log, S_IWUGO | S_IRUGO, show_log, store_log);
  656. static DEVICE_ATTR(status, S_IWUGO | S_IRUGO, show_status, NULL);
  657. /***************************
  658. * di buffer management
  659. ***************************/
  660. #if defined(CONFIG_ARCH_MESON2)
  661. #define MAX_IN_BUF_NUM 16
  662. #define MAX_LOCAL_BUF_NUM 12
  663. #define MAX_POST_BUF_NUM 16
  664. #else
  665. #define MAX_IN_BUF_NUM 8
  666. #define MAX_LOCAL_BUF_NUM 6
  667. #define MAX_POST_BUF_NUM 6
  668. #endif
  669. #define VFRAME_TYPE_IN 1
  670. #define VFRAME_TYPE_LOCAL 2
  671. #define VFRAME_TYPE_POST 3
  672. #define VFRAME_TYPE_NUM 3
  673. #ifdef DI_DEBUG
  674. static char* vframe_type_name[] = {"", "di_buf_in", "di_buf_loc", "di_buf_post"};
  675. #endif
  676. typedef struct di_buf_s{
  677. #ifdef USE_LIST
  678. struct list_head list;
  679. #endif
  680. vframe_t* vframe;
  681. int index; /* index in vframe_in_dup[] or vframe_in[], only for type of VFRAME_TYPE_IN */
  682. int post_proc_flag; /* 0,no post di; 1, normal post di; 2, edge only; 3, dummy */
  683. int new_format_flag;
  684. int type;
  685. int seq;
  686. int pre_ref_count; /* none zero, is used by mem_mif, chan2_mif, or wr_buf*/
  687. int post_ref_count; /* none zero, is used by post process */
  688. int queue_index;
  689. /*below for type of VFRAME_TYPE_LOCAL */
  690. unsigned int nr_adr;
  691. int nr_canvas_idx;
  692. unsigned int mtn_adr;
  693. int mtn_canvas_idx;
  694. /* pull down information */
  695. pulldown_detect_info_t field_pd_info;
  696. pulldown_detect_info_t win_pd_info[MAX_WIN_NUM];
  697. unsigned long mtn_info[5];
  698. int pulldown_mode;
  699. int win_pd_mode[5];
  700. /*below for type of VFRAME_TYPE_POST*/
  701. struct di_buf_s* di_buf[2];
  702. struct di_buf_s* di_buf_dup_p[5]; /* 0~4: n-2, n-1, n, n+1, n+2 ; n is the field to display*/
  703. }di_buf_t;
  704. static unsigned long di_mem_start;
  705. static unsigned long di_mem_size;
  706. static unsigned int default_width = 1920;
  707. static unsigned int default_height = 1080;
  708. static int local_buf_num;
  709. /*
  710. progressive frame process type config:
  711. 0, process by field;
  712. 1, process by frame (only valid for vdin source whose width/height does not change)
  713. */
  714. static vframe_t* vframe_in[MAX_IN_BUF_NUM];
  715. static vframe_t vframe_in_dup[MAX_IN_BUF_NUM];
  716. static vframe_t vframe_local[MAX_LOCAL_BUF_NUM*2];
  717. static vframe_t vframe_post[MAX_POST_BUF_NUM];
  718. static di_buf_t* cur_post_ready_di_buf = NULL;
  719. static di_buf_t di_buf_local[MAX_LOCAL_BUF_NUM*2];
  720. static di_buf_t di_buf_in[MAX_IN_BUF_NUM];
  721. static di_buf_t di_buf_post[MAX_POST_BUF_NUM];
  722. /*
  723. all buffers are in
  724. 1) list of local_free_list,in_free_list,pre_ready_list,recycle_list
  725. 2) di_pre_stru.di_inp_buf
  726. 3) di_pre_stru.di_wr_buf
  727. 4) cur_post_ready_di_buf
  728. 5) (di_buf_t*)(vframe->private_data)->di_buf[]
  729. 6) post_free_list_head
  730. 8) (di_buf_t*)(vframe->private_data)
  731. */
  732. #define QUEUE_LOCAL_FREE 0
  733. #define QUEUE_IN_FREE 1
  734. #define QUEUE_PRE_READY 2
  735. #define QUEUE_POST_FREE 3
  736. #define QUEUE_POST_READY 4
  737. #define QUEUE_RECYCLE 5
  738. #define QUEUE_DISPLAY 6
  739. #define QUEUE_TMP 7
  740. #define QUEUE_NUM 8
  741. #ifdef USE_LIST
  742. static struct list_head local_free_list_head = LIST_HEAD_INIT(local_free_list_head); // vframe is local_vframe
  743. static struct list_head in_free_list_head = LIST_HEAD_INIT(in_free_list_head); //vframe is NULL
  744. static struct list_head pre_ready_list_head = LIST_HEAD_INIT(pre_ready_list_head); //vframe is either local_vframe or in_vframe
  745. static struct list_head recycle_list_head = LIST_HEAD_INIT(recycle_list_head); //vframe is either local_vframe or in_vframe
  746. static struct list_head post_free_list_head = LIST_HEAD_INIT(post_free_list_head); //vframe is post_vframe
  747. static struct list_head post_ready_list_head = LIST_HEAD_INIT(post_ready_list_head); //vframe is post_vframe
  748. static struct list_head display_list_head = LIST_HEAD_INIT(display_list_head); //vframe sent out for displaying
  749. static struct list_head* list_head_array[QUEUE_NUM];
  750. #define get_di_buf_head(queue_idx) \
  751. list_first_entry(list_head_array[queue_idx], struct di_buf_s, list)
  752. static void queue_init(int local_buffer_num)
  753. {
  754. list_head_array[QUEUE_LOCAL_FREE] = &local_free_list_head;
  755. list_head_array[QUEUE_IN_FREE] = &in_free_list_head;
  756. list_head_array[QUEUE_PRE_READY] = &pre_ready_list_head;
  757. list_head_array[QUEUE_POST_FREE] = &post_free_list_head;
  758. list_head_array[QUEUE_POST_READY] = &post_ready_list_head;
  759. list_head_array[QUEUE_RECYCLE] = &recycle_list_head;
  760. list_head_array[QUEUE_DISPLAY] = &display_list_head;
  761. list_head_array[QUEUE_TMP] = &post_ready_list_head;
  762. }
  763. static bool queue_empty(queue_idx)
  764. {
  765. return list_empty(list_head_array[queue_idx]);
  766. }
  767. static void queue_out(di_buf_t* di_buf)
  768. {
  769. list_del(&(di_buf->list));
  770. }
  771. static void queue_in(di_buf_t* di_buf, int queue_idx)
  772. {
  773. list_add_tail(&(di_buf->list), list_head_array[queue_idx]);
  774. }
  775. static int list_count(int queue_idx)
  776. {
  777. int count = 0;
  778. di_buf_t *p = NULL, *ptmp;
  779. list_for_each_entry_safe(p, ptmp, list_head_array[queue_idx], list) {
  780. count++;
  781. }
  782. return count;
  783. }
  784. #define queue_for_each_entry(di_buf, ptm, queue_idx, list) \
  785. list_for_each_entry_safe(di_buf, ptmp, list_head_array[queue_idx], list)
  786. #else
  787. #define MAX_QUEUE_POOL_SIZE 256
  788. typedef struct queue_s{
  789. int num;
  790. int in_idx;
  791. int out_idx;
  792. int type; /* 0, first in first out; 1, general */
  793. unsigned int pool[MAX_QUEUE_POOL_SIZE];
  794. }queue_t;
  795. static queue_t queue[QUEUE_NUM];
  796. struct di_buf_pool_s{
  797. di_buf_t* di_buf_ptr;
  798. unsigned int size;
  799. }di_buf_pool[VFRAME_TYPE_NUM];
  800. #define queue_for_each_entry(di_buf, ptm, queue_idx, list) \
  801. for(itmp=0; ((di_buf = get_di_buf(queue_idx, &itmp))!=NULL); )
  802. static void queue_init(int local_buffer_num)
  803. {
  804. int i, j;
  805. for(i=0; i<QUEUE_NUM; i++){
  806. queue_t* q = &queue[i];
  807. for(j=0; j<MAX_QUEUE_POOL_SIZE; j++){
  808. q->pool[j] = 0;
  809. }
  810. q->in_idx = 0;
  811. q->out_idx = 0;
  812. q->num = 0;
  813. q->type = 0;
  814. if((i==QUEUE_RECYCLE)||(i==QUEUE_DISPLAY)||(i==QUEUE_TMP)){
  815. q->type = 1;
  816. }
  817. }
  818. if(local_buffer_num > 0){
  819. di_buf_pool[VFRAME_TYPE_IN-1].di_buf_ptr = &di_buf_in[0];
  820. di_buf_pool[VFRAME_TYPE_IN-1].size = MAX_IN_BUF_NUM;
  821. di_buf_pool[VFRAME_TYPE_LOCAL-1].di_buf_ptr = &di_buf_local[0];
  822. di_buf_pool[VFRAME_TYPE_LOCAL-1].size = local_buffer_num;
  823. di_buf_pool[VFRAME_TYPE_POST-1].di_buf_ptr = &di_buf_post[0];
  824. di_buf_pool[VFRAME_TYPE_POST-1].size = MAX_POST_BUF_NUM;
  825. }
  826. }
  827. static di_buf_t* get_di_buf(int queue_idx, int* start_pos)
  828. {
  829. queue_t* q = &(queue[queue_idx]);
  830. int idx;
  831. unsigned int pool_idx, di_buf_idx;
  832. di_buf_t* di_buf = NULL;
  833. #ifdef DI_DEBUG
  834. if(di_log_flag&DI_LOG_QUEUE){
  835. di_print("%s:<%d:%d,%d,%d> %d\n", __func__, queue_idx, q->num, q->in_idx, q->out_idx, *start_pos);
  836. }
  837. #endif
  838. if(q->type==0){
  839. if((*start_pos) < q->num){
  840. idx = q->out_idx + (*start_pos);
  841. if(idx >= MAX_QUEUE_POOL_SIZE){
  842. idx-=MAX_QUEUE_POOL_SIZE;
  843. }
  844. (*start_pos)++;
  845. }
  846. else{
  847. idx = MAX_QUEUE_POOL_SIZE;
  848. }
  849. }
  850. else{
  851. for(idx=(*start_pos); idx<MAX_QUEUE_POOL_SIZE; idx++){
  852. if(q->pool[idx]!=0){
  853. *start_pos = idx+1;
  854. break;
  855. }
  856. }
  857. }
  858. if(idx<MAX_QUEUE_POOL_SIZE){
  859. pool_idx = ((q->pool[idx]>>8)&0xff)-1;
  860. di_buf_idx = q->pool[idx]&0xff;
  861. if(pool_idx < VFRAME_TYPE_NUM){
  862. if(di_buf_idx < di_buf_pool[pool_idx].size){
  863. di_buf = &(di_buf_pool[pool_idx].di_buf_ptr[di_buf_idx]);
  864. }
  865. }
  866. }
  867. if((di_buf)&&( (((pool_idx+1)<<8)|di_buf_idx) != ((di_buf->type<<8)|(di_buf->index)))){
  868. #ifdef DI_DEBUG
  869. printk("%s: Error (%x,%x)\n", __func__, (((pool_idx+1)<<8)|di_buf_idx), ((di_buf->type<<8)|(di_buf->index)) );
  870. #endif
  871. recovery_flag = 1;
  872. di_buf = NULL;
  873. }
  874. #ifdef DI_DEBUG
  875. if(di_log_flag&DI_LOG_QUEUE){
  876. if(di_buf){
  877. di_print("%s: %x(%d,%d)\n", __func__, di_buf, pool_idx, di_buf_idx);
  878. }
  879. else{
  880. di_print("%s: %x\n", __func__, di_buf);
  881. }
  882. }
  883. #endif
  884. return di_buf;
  885. }
  886. static di_buf_t* get_di_buf_head(int queue_idx)
  887. {
  888. queue_t* q = &(queue[queue_idx]);
  889. int idx;
  890. unsigned int pool_idx, di_buf_idx;
  891. di_buf_t* di_buf = NULL;
  892. #ifdef DI_DEBUG
  893. if(di_log_flag&DI_LOG_QUEUE){
  894. di_print("%s:<%d:%d,%d,%d>\n", __func__,queue_idx,q->num, q->in_idx, q->out_idx);
  895. }
  896. #endif
  897. if(q->num > 0){
  898. if(q->type==0){
  899. idx = q->out_idx;
  900. }
  901. else{
  902. for(idx=0; idx<MAX_QUEUE_POOL_SIZE; idx++){
  903. if(q->pool[idx]!=0){
  904. break;
  905. }
  906. }
  907. }
  908. if(idx<MAX_QUEUE_POOL_SIZE){
  909. pool_idx = ((q->pool[idx]>>8)&0xff)-1;
  910. di_buf_idx = q->pool[idx]&0xff;
  911. if(pool_idx < VFRAME_TYPE_NUM){
  912. if(di_buf_idx < di_buf_pool[pool_idx].size){
  913. di_buf = &(di_buf_pool[pool_idx].di_buf_ptr[di_buf_idx]);
  914. }
  915. }
  916. }
  917. }
  918. if((di_buf)&&( (((pool_idx+1)<<8)|di_buf_idx) != ((di_buf->type<<8)|(di_buf->index)))){
  919. #ifdef DI_DEBUG
  920. printk("%s: Error (%x,%x)\n", __func__, (((pool_idx+1)<<8)|di_buf_idx), ((di_buf->type<<8)|(di_buf->index)) );
  921. #endif
  922. recovery_flag = 1;
  923. di_buf = NULL;
  924. }
  925. #ifdef DI_DEBUG
  926. if(di_log_flag&DI_LOG_QUEUE){
  927. if(di_buf){
  928. di_print("%s: %x(%d,%d)\n", __func__, di_buf, pool_idx, di_buf_idx);
  929. }
  930. else{
  931. di_print("%s: %x\n", __func__, di_buf);
  932. }
  933. }
  934. #endif
  935. return di_buf;
  936. }
  937. static void queue_out(di_buf_t* di_buf)
  938. {
  939. int i;
  940. if(di_buf == NULL){
  941. #ifdef DI_DEBUG
  942. printk("%s:Error\n", __func__);
  943. #endif
  944. recovery_flag = 1;
  945. return;
  946. }
  947. if(di_buf->queue_index>=0 && di_buf->queue_index<QUEUE_NUM){
  948. queue_t* q = &(queue[di_buf->queue_index]);
  949. #ifdef DI_DEBUG
  950. if(di_log_flag&DI_LOG_QUEUE){
  951. di_print("%s:<%d:%d,%d,%d> %x\n", __func__, di_buf->queue_index, q->num, q->in_idx, q->out_idx, di_buf);
  952. }
  953. #endif
  954. if(q->num > 0){
  955. if(q->type==0){
  956. if(q->pool[q->out_idx] == ((di_buf->type<<8)|(di_buf->index))){
  957. q->num--;
  958. q->pool[q->out_idx] = 0;
  959. q->out_idx++;
  960. if(q->out_idx>=MAX_QUEUE_POOL_SIZE){
  961. q->out_idx = 0;
  962. }
  963. di_buf->queue_index = -1;
  964. }
  965. else{
  966. #ifdef DI_DEBUG
  967. printk("%s: Error (%d, %x,%x)\n", __func__, di_buf->queue_index, q->pool[q->out_idx], ((di_buf->type<<8)|(di_buf->index)) );
  968. #endif
  969. recovery_flag = 1;
  970. }
  971. }
  972. else{
  973. int pool_val = (di_buf->type<<8)|(di_buf->index);
  974. for(i=0; i<MAX_QUEUE_POOL_SIZE; i++){
  975. if(q->pool[i]==pool_val){
  976. q->num--;
  977. q->pool[i]=0;
  978. di_buf->queue_index = -1;
  979. break;
  980. }
  981. }
  982. if(i==MAX_QUEUE_POOL_SIZE){
  983. #ifdef DI_DEBUG
  984. printk("%s: Error\n", __func__);
  985. #endif
  986. recovery_flag = 1;
  987. }
  988. }
  989. }
  990. }
  991. else{
  992. #ifdef DI_DEBUG
  993. printk("%s: Error, queue_index %d is not right\n", __func__, di_buf->queue_index);
  994. #endif
  995. recovery_flag = 1;
  996. }
  997. #ifdef DI_DEBUG
  998. if(di_log_flag&DI_LOG_QUEUE){
  999. di_print("%s done\n",__func__);
  1000. }
  1001. #endif
  1002. }
  1003. static void queue_in(di_buf_t* di_buf, int queue_idx)
  1004. {
  1005. if(di_buf == NULL){
  1006. #ifdef DI_DEBUG
  1007. printk("%s:Error\n", __func__);
  1008. #endif
  1009. recovery_flag = 1;
  1010. return;
  1011. }
  1012. if(di_buf->queue_index != -1){
  1013. #ifdef DI_DEBUG
  1014. printk("%s:Error, queue_index(%d) is not -1\n", __func__, di_buf->queue_index);
  1015. #endif
  1016. recovery_flag = 1;
  1017. return;
  1018. }
  1019. queue_t* q = &(queue[queue_idx]);
  1020. #ifdef DI_DEBUG
  1021. if(di_log_flag&DI_LOG_QUEUE){
  1022. di_print("%s:<%d:%d,%d,%d> %x\n", __func__,queue_idx, q->num, q->in_idx, q->out_idx,di_buf);
  1023. }
  1024. #endif
  1025. if(q->type==0){
  1026. q->pool[q->in_idx] = (di_buf->type<<8)|(di_buf->index);
  1027. di_buf->queue_index = queue_idx;
  1028. q->in_idx++;
  1029. if(q->in_idx>=MAX_QUEUE_POOL_SIZE){
  1030. q->in_idx = 0;
  1031. }
  1032. q->num++;
  1033. }
  1034. else{
  1035. int i;
  1036. for(i=0; i<MAX_QUEUE_POOL_SIZE; i++){
  1037. if(q->pool[i]==0){
  1038. q->pool[i] = (di_buf->type<<8)|(di_buf->index);
  1039. di_buf->queue_index = queue_idx;
  1040. q->num++;
  1041. break;
  1042. }
  1043. }
  1044. if(i==MAX_QUEUE_POOL_SIZE){
  1045. #ifdef DI_DEBUG
  1046. printk("%s: Error\n", __func__);
  1047. #endif
  1048. recovery_flag = 1;
  1049. }
  1050. }
  1051. #ifdef DI_DEBUG
  1052. if(di_log_flag&DI_LOG_QUEUE){
  1053. di_print("%s done\n",__func__);
  1054. }
  1055. #endif
  1056. }
  1057. static int list_count(int queue_idx)
  1058. {
  1059. return queue[queue_idx].num;
  1060. }
  1061. static bool queue_empty(queue_idx)
  1062. {
  1063. return (queue[queue_idx].num == 0);
  1064. }
  1065. #endif
  1066. static bool is_in_queue(di_buf_t* di_buf, int queue_idx)
  1067. {
  1068. bool ret = 0;
  1069. di_buf_t *p = NULL, *ptmp;
  1070. int itmp;
  1071. queue_for_each_entry(p, ptmp, queue_idx, list) {
  1072. if(p==di_buf){
  1073. ret = 1;
  1074. break;
  1075. }
  1076. }
  1077. return ret;
  1078. }
  1079. typedef struct{
  1080. /* pre input */
  1081. DI_MIF_t di_inp_mif;
  1082. DI_MIF_t di_mem_mif;
  1083. DI_MIF_t di_chan2_mif;
  1084. di_buf_t* di_inp_buf;
  1085. di_buf_t* di_mem_buf_dup_p;
  1086. di_buf_t* di_chan2_buf_dup_p;
  1087. /* pre output */
  1088. DI_SIM_MIF_t di_nrwr_mif;
  1089. DI_SIM_MIF_t di_mtnwr_mif;
  1090. di_buf_t* di_wr_buf;
  1091. /* pre state */
  1092. int in_seq;
  1093. int recycle_seq;
  1094. int pre_ready_seq;
  1095. int pre_de_busy; /* 1 if pre_de is not done */
  1096. int pre_de_busy_timer_count;
  1097. int pre_de_process_done; /* flag when irq done */
  1098. int unreg_req_flag; /* flag is set when VFRAME_EVENT_PROVIDER_UNREG*/
  1099. int force_unreg_req_flag;
  1100. int disable_req_flag;
  1101. /* current source info */
  1102. int cur_width;
  1103. int cur_height;
  1104. int cur_inp_type;
  1105. int cur_prog_flag; /* 1 for progressive source */
  1106. int process_count; /* valid only when prog_proc_type is 0, for progressive source: top field 1, bot field 0 */
  1107. int source_change_flag;
  1108. unsigned char prog_proc_type; /* set by prog_proc_config when source is vdin*/
  1109. unsigned char enable_mtnwr;
  1110. unsigned char enable_pulldown_check;
  1111. int same_field_source_flag;
  1112. }di_pre_stru_t;
  1113. static di_pre_stru_t di_pre_stru;
  1114. static void dump_di_pre_stru(void)
  1115. {
  1116. printk("di_pre_stru:\n");
  1117. printk("di_mem_buf_dup_p = 0x%p\n", di_pre_stru.di_mem_buf_dup_p);
  1118. printk("di_chan2_buf_dup_p = 0x%p\n", di_pre_stru.di_chan2_buf_dup_p);
  1119. printk("in_seq = %d\n", di_pre_stru.in_seq);
  1120. printk("recycle_seq = %d\n", di_pre_stru.recycle_seq);
  1121. printk("pre_ready_seq = %d\n", di_pre_stru.pre_ready_seq);
  1122. printk("pre_de_busy = %d\n", di_pre_stru.pre_de_busy);
  1123. printk("pre_de_busy_timer_count= %d\n", di_pre_stru.pre_de_busy_timer_count);
  1124. printk("pre_de_process_done = %d\n", di_pre_stru.pre_de_process_done);
  1125. printk("unreg_req_flag = %d\n", di_pre_stru.unreg_req_flag);
  1126. printk("cur_width = %d\n", di_pre_stru.cur_width);
  1127. printk("cur_height = %d\n", di_pre_stru.cur_height);
  1128. printk("cur_inp_type = 0x%x\n", di_pre_stru.cur_inp_type);
  1129. printk("cur_prog_flag = %d\n", di_pre_stru.cur_prog_flag);
  1130. printk("process_count = %d\n", di_pre_stru.process_count);
  1131. printk("source_change_flag = %d\n", di_pre_stru.source_change_flag);
  1132. printk("prog_proc_type = %d\n", di_pre_stru.prog_proc_type);
  1133. printk("enable_mtnwr = %d\n", di_pre_stru.enable_mtnwr);
  1134. printk("enable_pulldown_check = %d\n", di_pre_stru.enable_pulldown_check);
  1135. printk("same_field_source_flag = %d\n", di_pre_stru.same_field_source_flag);
  1136. }
  1137. typedef struct{
  1138. DI_MIF_t di_buf0_mif;
  1139. DI_MIF_t di_buf1_mif;
  1140. DI_SIM_MIF_t di_mtncrd_mif;
  1141. DI_SIM_MIF_t di_mtnprd_mif;
  1142. }di_post_stru_t;
  1143. static di_post_stru_t di_post_stru;
  1144. #define is_from_vdin(vframe) (vframe->type & VIDTYPE_VIU_422)
  1145. static void recycle_vframe_type_post(di_buf_t* di_buf);
  1146. #ifdef DI_DEBUG
  1147. static void recycle_vframe_type_post_print(di_buf_t* di_buf, const char* func);
  1148. #endif
  1149. static ssize_t store_config(struct device * dev, struct device_attribute *attr, const char * buf, size_t count)
  1150. {
  1151. if(strncmp(buf, "disable", 7)==0){
  1152. #ifdef DI_DEBUG
  1153. di_print("%s: disable\n", __func__);
  1154. #endif
  1155. if(init_flag){
  1156. di_pre_stru.disable_req_flag = 1;
  1157. provider_vframe_level = 0;
  1158. trigger_pre_di_process('d');
  1159. while(di_pre_stru.disable_req_flag){
  1160. msleep(1);
  1161. }
  1162. }
  1163. }
  1164. return count;
  1165. }
  1166. static unsigned char is_progressive(vframe_t* vframe)
  1167. {
  1168. return ((vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_PROGRESSIVE);
  1169. }
  1170. static void force_source_change(void)
  1171. {
  1172. di_pre_stru.cur_inp_type = 0;
  1173. }
  1174. static unsigned char is_source_change(vframe_t* vframe)
  1175. {
  1176. #define VFRAME_FORMAT_MASK (VIDTYPE_VIU_422|VIDTYPE_VIU_FIELD|VIDTYPE_VIU_SINGLE_PLANE|VIDTYPE_VIU_444|VIDTYPE_MVC)
  1177. if(
  1178. (di_pre_stru.cur_width!=vframe->width)||
  1179. (di_pre_stru.cur_height!=vframe->height)||
  1180. (di_pre_stru.cur_prog_flag!=is_progressive(vframe))||
  1181. ((di_pre_stru.cur_inp_type&VFRAME_FORMAT_MASK)!=(vframe->type&VFRAME_FORMAT_MASK))
  1182. ){
  1183. return 1;
  1184. }
  1185. return 0;
  1186. }
  1187. static unsigned char is_bypass(void)
  1188. {
  1189. if(bypass_vscale_skip && (get_current_vscale_skip_count()>0))
  1190. return 1;
  1191. if(bypass_all)
  1192. return 1;
  1193. if(di_pre_stru.cur_prog_flag&&
  1194. ((bypass_prog)||
  1195. (di_pre_stru.cur_width>1920)||(di_pre_stru.cur_height>1080)
  1196. ||(di_pre_stru.cur_inp_type&VIDTYPE_VIU_444))
  1197. )
  1198. return 1;
  1199. if(bypass_hd&&
  1200. ((di_pre_stru.cur_width>720)||(di_pre_stru.cur_height>576))
  1201. )
  1202. return 1;
  1203. if(di_pre_stru.cur_inp_type&VIDTYPE_MVC)
  1204. return 1;
  1205. return 0;
  1206. }
  1207. #if defined(CONFIG_ARCH_MESON2)
  1208. #if ((DEINTERLACE_CANVAS_BASE_INDEX!=0x68)||(DEINTERLACE_CANVAS_MAX_INDEX!=0x7f))
  1209. #error "DEINTERLACE_CANVAS_BASE_INDEX is not 0x68 or DEINTERLACE_CANVAS_MAX_INDEX is not 0x7f, update canvas.h"
  1210. #endif
  1211. #endif
  1212. static int di_init_buf(int width, int height, unsigned char prog_flag)
  1213. {
  1214. int i, local_buf_num_available;
  1215. int canvas_height = height + 8;
  1216. frame_count = 0;
  1217. disp_frame_count = 0;
  1218. cur_post_ready_di_buf = NULL;
  1219. for(i=0; i<MAX_IN_BUF_NUM; i++){
  1220. vframe_in[i]=NULL;
  1221. }
  1222. memset(&di_pre_stru, 0, sizeof(di_pre_stru));
  1223. memset(&di_post_stru, 0, sizeof(di_post_stru));
  1224. if(prog_flag){
  1225. di_pre_stru.prog_proc_type = 1;
  1226. local_buf_num = di_mem_size/(width*canvas_height*2);
  1227. local_buf_num_available = local_buf_num;
  1228. if(local_buf_num > (2*MAX_LOCAL_BUF_NUM)){
  1229. local_buf_num = 2*MAX_LOCAL_BUF_NUM;
  1230. }
  1231. }
  1232. else{
  1233. di_pre_stru.prog_proc_type = 0;
  1234. local_buf_num = di_mem_size/(width*canvas_height*5/4);
  1235. local_buf_num_available = local_buf_num;
  1236. if(local_buf_num > MAX_LOCAL_BUF_NUM){
  1237. local_buf_num = MAX_LOCAL_BUF_NUM;
  1238. }
  1239. }
  1240. printk("%s: version %d, prog_proc_type %d, buf start %x, size %x, buf(w%d,h%d) num %d (available %d) \n",
  1241. __func__, version, di_pre_stru.prog_proc_type, (unsigned int)di_mem_start,
  1242. (unsigned int)di_mem_size, width, canvas_height, local_buf_num, local_buf_num_available);
  1243. same_w_r_canvas_count = 0;
  1244. same_field_top_count = 0;
  1245. same_field_bot_count = 0;
  1246. queue_init(local_buf_num);
  1247. for(i=0; i<local_buf_num; i++){
  1248. di_buf_t* di_buf = &(di_buf_local[i]);
  1249. if(di_buf){
  1250. memset(di_buf, sizeof(di_buf_t), 0);
  1251. di_buf->type = VFRAME_TYPE_LOCAL;
  1252. di_buf->pre_ref_count = 0;
  1253. di_buf->post_ref_count = 0;
  1254. if(prog_flag){
  1255. di_buf->nr_adr = di_mem_start + (width*canvas_height*2)*i;
  1256. di_buf->nr_canvas_idx = DEINTERLACE_CANVAS_BASE_INDEX+i;
  1257. canvas_config(di_buf->nr_canvas_idx, di_buf->nr_adr, width*2, canvas_height, 0, 0);
  1258. }
  1259. else{
  1260. di_buf->nr_adr = di_mem_start + (width*canvas_height*5/4)*i;
  1261. di_buf->nr_canvas_idx = DEINTERLACE_CANVAS_BASE_INDEX+i*2;
  1262. canvas_config(di_buf->nr_canvas_idx, di_buf->nr_adr, width*2, canvas_height/2, 0, 0);
  1263. di_buf->mtn_adr = di_mem_start + (width*canvas_height*5/4)*i + (width*canvas_height);
  1264. di_buf->mtn_canvas_idx = DEINTERLACE_CANVAS_BASE_INDEX+i*2+1;
  1265. canvas_config(di_buf->mtn_canvas_idx, di_buf->mtn_adr, width/2, canvas_height/2, 0, 0);
  1266. }
  1267. di_buf->index = i;
  1268. di_buf->vframe = &(vframe_local[i]);
  1269. di_buf->vframe->private_data = di_buf;
  1270. di_buf->vframe->canvas0Addr = di_buf->nr_canvas_idx;
  1271. di_buf->vframe->canvas1Addr = di_buf->nr_canvas_idx;
  1272. di_buf->queue_index = -1;
  1273. queue_in(di_buf, QUEUE_LOCAL_FREE);
  1274. }
  1275. }
  1276. for(i=0; i<MAX_IN_BUF_NUM; i++){
  1277. di_buf_t* di_buf = &(di_buf_in[i]);
  1278. if(di_buf){
  1279. memset(di_buf, sizeof(di_buf_t), 0);
  1280. di_buf->type = VFRAME_TYPE_IN;
  1281. di_buf->pre_ref_count = 0;
  1282. di_buf->post_ref_count = 0;
  1283. di_buf->vframe = &(vframe_in_dup[i]);
  1284. di_buf->vframe->private_data = di_buf;
  1285. di_buf->index = i;
  1286. di_buf->queue_index = -1;
  1287. queue_in(di_buf, QUEUE_IN_FREE);
  1288. }
  1289. }
  1290. for(i=0; i<MAX_POST_BUF_NUM; i++){
  1291. di_buf_t* di_buf = &(di_buf_post[i]);
  1292. if(di_buf){
  1293. memset(di_buf, sizeof(di_buf_t), 0);
  1294. di_buf->type = VFRAME_TYPE_POST;
  1295. di_buf->index = i;
  1296. di_buf->vframe = &(vframe_post[i]);
  1297. di_buf->vframe->private_data = di_buf;
  1298. di_buf->queue_index = -1;
  1299. queue_in(di_buf, QUEUE_POST_FREE);
  1300. }
  1301. }
  1302. return 0;
  1303. }
  1304. static void di_uninit_buf(void)
  1305. {
  1306. di_buf_t *p = NULL, *ptmp;
  1307. int i;
  1308. #ifdef USE_LIST
  1309. list_for_each_entry_safe(p, ptmp, &local_free_list_head, list) {
  1310. list_del(&p->list);
  1311. }
  1312. list_for_each_entry_safe(p, ptmp, &in_free_list_head, list) {
  1313. list_del(&p->list);
  1314. }
  1315. list_for_each_entry_safe(p, ptmp, &pre_ready_list_head, list) {
  1316. list_del(&p->list);
  1317. }
  1318. list_for_each_entry_safe(p, ptmp, &recycle_list_head, list) {
  1319. list_del(&p->list);
  1320. }
  1321. list_for_each_entry_safe(p, ptmp, &post_free_list_head, list) {
  1322. list_del(&p->list);
  1323. }
  1324. list_for_each_entry_safe(p, ptmp, &post_ready_list_head, list) {
  1325. list_del(&p->list);
  1326. }
  1327. list_for_each_entry_safe(p, ptmp, &display_list_head, list) {
  1328. list_del(&p->list);
  1329. }
  1330. #else
  1331. queue_init(0);
  1332. #endif
  1333. for(i=0; i<MAX_IN_BUF_NUM; i++){
  1334. vframe_in[i]=NULL;
  1335. }
  1336. }
  1337. static void di_clean_in_buf(void)
  1338. {
  1339. di_buf_t *di_buf = NULL, *ptmp;
  1340. int itmp;
  1341. int i;
  1342. //di_printk_flag = 1;
  1343. frame_count = 0;
  1344. //disp_frame_count = 0; //do not set it to 0 here to make start_frame_hold_count not work when "keep last frame" is enabled
  1345. if(real_buf_mgr_mode&0x100){
  1346. while(!queue_empty(QUEUE_POST_READY)){
  1347. di_buf = get_di_buf_head(QUEUE_POST_READY);
  1348. recycle_vframe_type_post(di_buf);
  1349. #ifdef DI_DEBUG
  1350. recycle_vframe_type_post_print(di_buf, __func__);
  1351. #endif
  1352. }
  1353. }
  1354. if(di_pre_stru.di_mem_buf_dup_p){
  1355. di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
  1356. di_pre_stru.di_mem_buf_dup_p = NULL;
  1357. }
  1358. if(di_pre_stru.di_chan2_buf_dup_p){
  1359. di_pre_stru.di_chan2_buf_dup_p->pre_ref_count = 0;
  1360. di_pre_stru.di_chan2_buf_dup_p = NULL;
  1361. }
  1362. di_pre_stru.process_count = 0;
  1363. if(di_pre_stru.di_inp_buf){
  1364. if(vframe_in[di_pre_stru.di_inp_buf->index]){
  1365. vframe_in[di_pre_stru.di_inp_buf->index] = NULL;
  1366. }
  1367. queue_in(di_pre_stru.di_inp_buf, QUEUE_IN_FREE);
  1368. di_pre_stru.di_inp_buf = NULL;
  1369. }
  1370. if(di_pre_stru.di_wr_buf){
  1371. di_pre_stru.di_wr_buf->pre_ref_count = 0;
  1372. queue_in(di_pre_stru.di_wr_buf, QUEUE_RECYCLE);
  1373. di_pre_stru.di_wr_buf = NULL;
  1374. }
  1375. queue_for_each_entry(di_buf, ptmp, QUEUE_PRE_READY, list) {
  1376. queue_out(di_buf);
  1377. queue_in(di_buf, QUEUE_RECYCLE);
  1378. }
  1379. queue_for_each_entry(di_buf, ptmp, QUEUE_RECYCLE, list) {
  1380. if(di_buf->type == VFRAME_TYPE_IN){
  1381. di_buf->pre_ref_count = 0;
  1382. queue_out(di_buf);
  1383. if(vframe_in[di_buf->index]){
  1384. vframe_in[di_buf->index] = NULL;
  1385. }
  1386. queue_in(di_buf, QUEUE_IN_FREE);
  1387. }
  1388. else{
  1389. if((di_buf->pre_ref_count == 0)&&(di_buf->post_ref_count == 0)){
  1390. queue_out(di_buf);
  1391. queue_in(di_buf, QUEUE_LOCAL_FREE);
  1392. }
  1393. }
  1394. }
  1395. di_pre_stru.cur_width = 0;
  1396. di_pre_stru.cur_height= 0;
  1397. di_pre_stru.cur_prog_flag = 0;
  1398. di_pre_stru.cur_inp_type = 0;
  1399. di_pre_stru.pre_de_process_done = 0;
  1400. di_pre_stru.pre_de_busy = 0;
  1401. for(i=0; i<MAX_IN_BUF_NUM; i++){
  1402. vframe_in[i]=NULL;
  1403. }
  1404. }
  1405. static void log_buffer_state(unsigned char* tag)
  1406. {
  1407. if(di_log_flag&DI_LOG_BUFFER_STATE){
  1408. di_buf_t *p = NULL, *ptmp;
  1409. int itmp;
  1410. int in_free = 0;
  1411. int local_free = 0;
  1412. int pre_ready = 0;
  1413. int post_free = 0;
  1414. int post_ready = 0;
  1415. int post_ready_ext = 0;
  1416. int display = 0;
  1417. int display_ext = 0;
  1418. int recycle = 0;
  1419. int di_inp = 0;
  1420. int di_wr = 0;
  1421. ulong fiq_flag;
  1422. raw_local_save_flags(fiq_flag);
  1423. local_fiq_disable();
  1424. in_free = list_count(QUEUE_IN_FREE);
  1425. local_free = list_count(QUEUE_LOCAL_FREE);
  1426. pre_ready = list_count(QUEUE_PRE_READY);
  1427. post_free = list_count(QUEUE_POST_FREE);
  1428. post_ready = list_count(QUEUE_POST_READY);
  1429. queue_for_each_entry(p, ptmp, QUEUE_POST_READY, list) {
  1430. if(p->di_buf[0]){
  1431. post_ready_ext++;
  1432. }
  1433. if(p->di_buf[1]){
  1434. post_ready_ext++;
  1435. }
  1436. }
  1437. queue_for_each_entry(p, ptmp, QUEUE_DISPLAY, list) {
  1438. display++;
  1439. if(p->di_buf[0]){
  1440. display_ext++;
  1441. }
  1442. if(p->di_buf[1]){
  1443. display_ext++;
  1444. }
  1445. }
  1446. recycle = list_count(QUEUE_RECYCLE);
  1447. if(di_pre_stru.di_inp_buf)
  1448. di_inp++;
  1449. if(di_pre_stru.di_wr_buf)
  1450. di_wr++;
  1451. if(buf_state_log_threshold == 0){
  1452. buf_state_log_start = 0;
  1453. }
  1454. else if(post_ready < buf_state_log_threshold){
  1455. buf_state_log_start = 1;
  1456. }
  1457. if(buf_state_log_start){
  1458. di_print("[%s]i %d, i_f %d/%d, l_f %d/%d, pre_r %d, post_f %d/%d, post_r (%d:%d), disp (%d:%d),rec %d, di_i %d, di_w %d\r\n",
  1459. tag,
  1460. provider_vframe_level,
  1461. in_free,MAX_IN_BUF_NUM,
  1462. local_free, local_buf_num,
  1463. pre_ready,
  1464. post_free, MAX_POST_BUF_NUM,
  1465. post_ready, post_ready_ext,
  1466. display, display_ext,
  1467. recycle,
  1468. di_inp, di_wr
  1469. );
  1470. }
  1471. raw_local_irq_restore(fiq_flag);
  1472. }
  1473. }
  1474. static void dump_state(void)
  1475. {
  1476. di_buf_t *p = NULL, *ptmp;
  1477. int itmp;
  1478. printk("provider vframe level %d\n", provider_vframe_level);
  1479. printk("in_free_list (max %d):\n", MAX_IN_BUF_NUM);
  1480. queue_for_each_entry(p, ptmp, QUEUE_IN_FREE, list) {
  1481. printk("index %d, %x, type %d\n", p->index, (unsigned int)p, p->type);
  1482. }
  1483. printk("local_free_list (max %d):\n", local_buf_num);
  1484. queue_for_each_entry(p, ptmp, QUEUE_LOCAL_FREE, list) {
  1485. printk("index %d, %x, type %d\n", p->index, (unsigned int)p, p->type);
  1486. }
  1487. printk("pre_ready_list:\n");
  1488. queue_for_each_entry(p, ptmp, QUEUE_PRE_READY, list) {
  1489. printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type, p->vframe->type);
  1490. }
  1491. printk("post_free_list (max %d):\n", MAX_POST_BUF_NUM);
  1492. queue_for_each_entry(p, ptmp, QUEUE_POST_FREE, list) {
  1493. printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type ,p->vframe->type);
  1494. }
  1495. printk("post_ready_list:\n");
  1496. queue_for_each_entry(p, ptmp, QUEUE_POST_READY, list) {
  1497. printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type, p->vframe->type);
  1498. if(p->di_buf[0]){
  1499. printk(" +index %d, %x, type %d, vframetype%x\n", p->di_buf[0]->index, (unsigned int)p->di_buf[0], p->di_buf[0]->type, p->di_buf[0]->vframe->type);
  1500. }
  1501. if(p->di_buf[1]){
  1502. printk(" +index %d, %x, type %d, vframetype%x\n", p->di_buf[1]->index, (unsigned int)p->di_buf[1], p->di_buf[1]->type, p->di_buf[1]->vframe->type);
  1503. }
  1504. }
  1505. printk("display_list:\n");
  1506. queue_for_each_entry(p, ptmp, QUEUE_DISPLAY, list) {
  1507. printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type, p->vframe->type);
  1508. if(p->di_buf[0]){
  1509. printk(" +index %d, %x, type %d, vframetype%x\n", p->di_buf[0]->index, (unsigned int)p->di_buf[0], p->di_buf[0]->type, p->di_buf[0]->vframe->type);
  1510. }
  1511. if(p->di_buf[1]){
  1512. printk(" +index %d, %x, type %d, vframetype%x\n", p->di_buf[1]->index, (unsigned int)p->di_buf[1], p->di_buf[1]->type, p->di_buf[1]->vframe->type);
  1513. }
  1514. }
  1515. printk("recycle_list:\n");
  1516. queue_for_each_entry(p, ptmp, QUEUE_RECYCLE, list) {
  1517. printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type, p->vframe->type);
  1518. }
  1519. if(di_pre_stru.di_inp_buf)
  1520. printk("di_inp_buf:index %d, %x, type %d\n", di_pre_stru.di_inp_buf->index, (unsigned int)di_pre_stru.di_inp_buf, di_pre_stru.di_inp_buf->type);
  1521. if(di_pre_stru.di_wr_buf)
  1522. printk("di_wr_buf:index %d, %x, type %d\n", di_pre_stru.di_wr_buf->index, (unsigned int)di_pre_stru.di_wr_buf, di_pre_stru.di_wr_buf->type);
  1523. dump_di_pre_stru();
  1524. }
  1525. /*
  1526. * di pre process
  1527. */
  1528. static void config_di_wr_mif(DI_SIM_MIF_t* di_nrwr_mif, DI_SIM_MIF_t* di_mtnwr_mif, di_buf_t* di_buf, vframe_t* in_vframe)
  1529. {
  1530. di_nrwr_mif->canvas_num = di_buf->nr_canvas_idx;
  1531. di_nrwr_mif->start_x = 0;
  1532. di_nrwr_mif->end_x = in_vframe->width - 1;
  1533. di_nrwr_mif->start_y = 0;
  1534. if(di_pre_stru.prog_proc_type == 0){
  1535. di_nrwr_mif->end_y = in_vframe->height/2 - 1;
  1536. }
  1537. else{
  1538. di_nrwr_mif->end_y = in_vframe->height - 1;
  1539. }
  1540. if(di_pre_stru.prog_proc_type == 0){
  1541. di_mtnwr_mif->start_x = 0;
  1542. di_mtnwr_mif->end_x = in_vframe->width - 1;
  1543. di_mtnwr_mif->start_y = 0;
  1544. di_mtnwr_mif->end_y = in_vframe->height/2 - 1;
  1545. di_mtnwr_mif->canvas_num = di_buf->mtn_canvas_idx;
  1546. }
  1547. }
  1548. static void config_di_mif(DI_MIF_t* di_mif, di_buf_t*di_buf)
  1549. {
  1550. if(di_buf == NULL)
  1551. return;
  1552. di_mif->canvas0_addr0 = di_buf->vframe->canvas0Addr & 0xff;
  1553. di_mif->canvas0_addr1 = (di_buf->vframe->canvas0Addr>>8) & 0xff;
  1554. di_mif->canvas0_addr2 = (di_buf->vframe->canvas0Addr>>16) & 0xff;
  1555. if ( di_buf->vframe->type & VIDTYPE_VIU_422 )
  1556. { //from vdin or local vframe
  1557. if((!is_progressive(di_buf->vframe)) //interlace, from vdin or local vframe
  1558. ||(di_pre_stru.prog_proc_type) //progressive(by frame), from vdin or local frame
  1559. ){
  1560. di_mif->video_mode = 0;
  1561. di_mif->set_separate_en = 0;
  1562. di_mif->src_field_mode = 0;
  1563. di_mif->output_field_num = 0;
  1564. di_mif->burst_size_y = 3;
  1565. di_mif->burst_size_cb = 0;
  1566. di_mif->burst_size_cr = 0;
  1567. di_mif->luma_x_start0 = 0;
  1568. di_mif->luma_x_end0 = di_buf->vframe->width - 1;
  1569. di_mif->luma_y_start0 = 0;
  1570. if(di_pre_stru.prog_proc_type){
  1571. di_mif->luma_y_end0 = di_buf->vframe->height - 1;
  1572. }
  1573. else{
  1574. di_mif->luma_y_end0 = di_buf->vframe->height/2 - 1;
  1575. }
  1576. di_mif->chroma_x_start0 = 0;
  1577. di_mif->chroma_x_end0 = 0;
  1578. di_mif->chroma_y_start0 = 0;
  1579. di_mif->chroma_y_end0 = 0;
  1580. di_mif->canvas0_addr0 = di_buf->vframe->canvas0Addr & 0xff;
  1581. di_mif->canvas0_addr1 = (di_buf->vframe->canvas0Addr>>8) & 0xff;
  1582. di_mif->canvas0_addr2 = (di_buf->vframe->canvas0Addr>>16) & 0xff;
  1583. }
  1584. else{
  1585. //progressive (by field), from vdin only
  1586. di_mif->video_mode = 0;
  1587. di_mif->set_separate_en = 0;
  1588. di_mif->src_field_mode = 1;
  1589. di_mif->burst_size_y = 3;
  1590. di_mif->burst_size_cb = 0;
  1591. di_mif->burst_size_cr = 0;
  1592. if(di_pre_stru.process_count>0){ //process top
  1593. di_mif->output_field_num = 0; // top
  1594. di_mif->luma_x_start0 = 0;
  1595. di_mif->luma_x_end0 = di_buf->vframe->width - 1;
  1596. di_mif->luma_y_start0 = 0;
  1597. di_mif->luma_y_end0 = di_buf->vframe->height - 2;
  1598. di_mif->chroma_x_start0 = 0;
  1599. di_mif->chroma_x_end0 = di_buf->vframe->width/2 - 1;
  1600. di_mif->chroma_y_start0 = 0;
  1601. di_mif->chroma_y_end0 = di_buf->vframe->height/2 - 2;
  1602. }
  1603. else{ //process bot
  1604. di_mif->output_field_num = 1; // bottom
  1605. di_mif->luma_x_start0 = 0;
  1606. di_mif->luma_x_end0 = di_buf->vframe->width - 1;
  1607. di_mif->luma_y_start0 = 1;
  1608. di_mif->luma_y_end0 = di_buf->vframe->height - 1;
  1609. di_mif->chroma_x_start0 = 0;
  1610. di_mif->chroma_x_end0 = di_buf->vframe->width/2 - 1;
  1611. di_mif->chroma_y_start0 = 1;
  1612. di_mif->chroma_y_end0 = di_buf->vframe->height/2 - 1;
  1613. }
  1614. }
  1615. }
  1616. else{
  1617. //from decoder
  1618. di_mif->video_mode = 0;
  1619. di_mif->set_separate_en = 1;
  1620. di_mif->src_field_mode = 1;
  1621. di_mif->burst_size_y = 3;
  1622. di_mif->burst_size_cb = 1;
  1623. di_mif->burst_size_cr = 1;
  1624. if(((di_buf->vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)
  1625. ||(di_pre_stru.process_count>0)){
  1626. di_mif->output_field_num = 0; // top
  1627. di_mif->luma_x_start0 = 0;
  1628. di_mif->luma_x_end0 = di_buf->vframe->width - 1;
  1629. di_mif->luma_y_start0 = 0;
  1630. di_mif->luma_y_end0 = di_buf->vframe->height - 2;
  1631. di_mif->chroma_x_start0 = 0;
  1632. di_mif->chroma_x_end0 = di_buf->vframe->width/2 - 1;
  1633. di_mif->chroma_y_start0 = 0;
  1634. di_mif->chroma_y_end0 = di_buf->vframe->height/2 - 2;
  1635. }
  1636. else{
  1637. di_mif->output_field_num = 1; // bottom
  1638. di_mif->luma_x_start0 = 0;
  1639. di_mif->luma_x_end0 = di_buf->vframe->width - 1;
  1640. di_mif->luma_y_start0 = 1;
  1641. di_mif->luma_y_end0 = di_buf->vframe->height - 1;
  1642. di_mif->chroma_x_start0 = 0;
  1643. di_mif->chroma_x_end0 = di_buf->vframe->width/2 - 1;
  1644. di_mif->chroma_y_start0 = 1;
  1645. di_mif->chroma_y_end0 = di_buf->vframe->height/2 - 1;
  1646. }
  1647. }
  1648. }
  1649. static void pre_de_process(void)
  1650. {
  1651. int chan2_field_num = 1;
  1652. #ifdef DI_DEBUG
  1653. di_print("%s: start\n", __func__);
  1654. #endif
  1655. di_pre_stru.pre_de_busy = 1;
  1656. di_pre_stru.pre_de_busy_timer_count = 0;
  1657. config_di_mif(&di_pre_stru.di_inp_mif, di_pre_stru.di_inp_buf);
  1658. config_di_mif(&di_pre_stru.di_mem_mif, di_pre_stru.di_mem_buf_dup_p);
  1659. config_di_mif(&di_pre_stru.di_chan2_mif, di_pre_stru.di_chan2_buf_dup_p);
  1660. config_di_wr_mif(&di_pre_stru.di_nrwr_mif, &di_pre_stru.di_mtnwr_mif,
  1661. di_pre_stru.di_wr_buf, di_pre_stru.di_inp_buf->vframe);
  1662. if((di_pre_stru.di_chan2_buf_dup_p)&&
  1663. ((di_pre_stru.di_chan2_buf_dup_p->vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)){
  1664. chan2_field_num = 0;
  1665. }
  1666. Wr(DI_PRE_SIZE, di_pre_stru.di_nrwr_mif.end_x|(di_pre_stru.di_nrwr_mif.end_y << 16) );
  1667. // set interrupt mask for pre module.
  1668. Wr(DI_INTR_CTRL, (0 << 16) | // nrwr interrupt.
  1669. ((di_pre_stru.enable_mtnwr?0:1) << 17) | // mtnwr interrupt.
  1670. (1 << 18) | // diwr interrupt.
  1671. (1 << 19) | // hist check interrupt.
  1672. 0xf ); // clean all pending interrupt bits.
  1673. #if 1
  1674. enable_di_mode_check_2(
  1675. (pd_win_prop[0].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
  1676. (pd_win_prop[0].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
  1677. (pd_win_prop[0].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
  1678. (pd_win_prop[0].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1,
  1679. (pd_win_prop[1].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
  1680. (pd_win_prop[1].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
  1681. (pd_win_prop[1].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
  1682. (pd_win_prop[1].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1,
  1683. (pd_win_prop[2].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
  1684. (pd_win_prop[2].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
  1685. (pd_win_prop[2].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
  1686. (pd_win_prop[2].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1,
  1687. (pd_win_prop[3].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
  1688. (pd_win_prop[3].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
  1689. (pd_win_prop[3].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
  1690. (pd_win_prop[3].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1,
  1691. (pd_win_prop[4].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
  1692. (pd_win_prop[4].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
  1693. (pd_win_prop[4].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
  1694. (pd_win_prop[4].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1
  1695. );
  1696. #else
  1697. enable_di_mode_check_2(
  1698. 0, di_pre_stru.di_inp_buf->vframe->width-1, 0, di_pre_stru.di_inp_buf->vframe->height/2-1, // window 0 ( start_x, end_x, start_y, end_y)
  1699. 0, di_pre_stru.di_inp_buf->vframe->width-1, 0, di_pre_stru.di_inp_buf->vframe->height/2-1, // window 1 ( start_x, end_x, start_y, end_y)
  1700. 0, di_pre_stru.di_inp_buf->vframe->width-1, 0, di_pre_stru.di_inp_buf->vframe->height/2-1, // window 2 ( start_x, end_x, start_y, end_y)
  1701. 0, di_pre_stru.di_inp_buf->vframe->width-1, 0, di_pre_stru.di_inp_buf->vframe->height/2-1, // window 3 ( start_x, end_x, start_y, end_y)
  1702. 0, di_pre_stru.di_inp_buf->vframe->width-1, 0, di_pre_stru.di_inp_buf->vframe->height/2-1 // window 4 ( start_x, end_x, start_y, end_y)
  1703. );
  1704. #endif
  1705. WRITE_MPEG_REG(DI_PRE_CTRL, 0x3 << 30); //reset
  1706. enable_di_pre_aml ( &di_pre_stru.di_inp_mif, // di_inp
  1707. &di_pre_stru.di_mem_mif, // di_mem
  1708. &di_pre_stru.di_chan2_mif, // chan2
  1709. &di_pre_stru.di_nrwr_mif, // nrwrite
  1710. &di_pre_stru.di_mtnwr_mif, // mtn write
  1711. 1, // nr enable
  1712. di_pre_stru.enable_mtnwr, // mtn enable
  1713. di_pre_stru.enable_pulldown_check, // pd32 check_en
  1714. di_pre_stru.enable_pulldown_check, // pd22 check_en
  1715. #if defined(CONFIG_ARCH_MESON)
  1716. 1, // hist check_en
  1717. #else
  1718. 0, // hist check_en
  1719. #endif
  1720. chan2_field_num, // field num for chan2. 1 bottom, 0 top.
  1721. 0, // pre viu link.
  1722. 10 //hold line.
  1723. );
  1724. }
  1725. static void pre_de_done_buf_config(void)
  1726. {
  1727. ulong fiq_flag;
  1728. if(di_pre_stru.di_wr_buf){
  1729. read_pulldown_info(&(di_pre_stru.di_wr_buf->field_pd_info),
  1730. &(di_pre_stru.di_wr_buf->win_pd_info[0])
  1731. );
  1732. read_mtn_info(di_pre_stru.di_wr_buf->mtn_info,reg_mtn_info);
  1733. if(di_pre_stru.cur_prog_flag){
  1734. if(di_pre_stru.prog_proc_type == 0){
  1735. if((di_pre_stru.process_count>0)
  1736. &&(is_progressive(di_pre_stru.di_mem_buf_dup_p->vframe))){
  1737. // di_mem_buf_dup_p->vframe is from in_list, and it is top field
  1738. di_pre_stru.di_chan2_buf_dup_p = di_pre_stru.di_wr_buf;
  1739. #ifdef DI_DEBUG
  1740. di_print("%s: set di_chan2_buf_dup_p to di_wr_buf\n", __func__);
  1741. #endif
  1742. }
  1743. else{ // di_mem_buf_dup->vfrme is either local vframe, or bot field of vframe from in_list
  1744. di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
  1745. di_pre_stru.di_mem_buf_dup_p = di_pre_stru.di_chan2_buf_dup_p;
  1746. di_pre_stru.di_chan2_buf_dup_p = di_pre_stru.di_wr_buf;
  1747. #ifdef DI_DEBUG
  1748. di_print("%s: set di_mem_buf_dup_p to di_chan2_buf_dup_p; set di_chan2_buf_dup_p to di_wr_buf\n", __func__);
  1749. #endif
  1750. }
  1751. }
  1752. else{
  1753. di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
  1754. di_pre_stru.di_mem_buf_dup_p = di_pre_stru.di_wr_buf;
  1755. #ifdef DI_DEBUG
  1756. di_print("%s: set di_mem_buf_dup_p to di_wr_buf\n", __func__);
  1757. #endif
  1758. }
  1759. di_pre_stru.di_wr_buf->seq = di_pre_stru.pre_ready_seq++;
  1760. di_pre_stru.di_wr_buf->post_ref_count = 0;
  1761. if(di_pre_stru.source_change_flag){
  1762. di_pre_stru.di_wr_buf->new_format_flag = 1;
  1763. di_pre_stru.source_change_flag = 0;
  1764. }
  1765. else{
  1766. di_pre_stru.di_wr_buf->new_format_flag = 0;
  1767. }
  1768. if(bypass_state == 1){
  1769. di_pre_stru.di_wr_buf->new_format_flag = 1;
  1770. bypass_state = 0;
  1771. }
  1772. queue_in(di_pre_stru.di_wr_buf, QUEUE_PRE_READY);
  1773. #ifdef DI_DEBUG
  1774. di_print("%s: process_count %d, %s[%d] => pre_ready_list\n",
  1775. __func__, di_pre_stru.process_count, vframe_type_name[di_pre_stru.di_wr_buf->type], di_pre_stru.di_wr_buf->index);
  1776. #endif
  1777. di_pre_stru.di_wr_buf = NULL;
  1778. }
  1779. else{
  1780. di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
  1781. di_pre_stru.di_mem_buf_dup_p = NULL;
  1782. if(di_pre_stru.di_chan2_buf_dup_p){
  1783. di_pre_stru.di_mem_buf_dup_p = di_pre_stru.di_chan2_buf_dup_p;
  1784. #ifdef DI_DEBUG
  1785. di_print("%s: set di_mem_buf_dup_p to di_chan2_buf_dup_p\n", __func__);
  1786. #endif
  1787. }
  1788. di_pre_stru.di_chan2_buf_dup_p = di_pre_stru.di_wr_buf;
  1789. if(di_pre_stru.di_wr_buf->post_proc_flag == 2){
  1790. //add dummy buf, will not be displayed
  1791. if(!queue_empty(QUEUE_LOCAL_FREE)){
  1792. di_buf_t* di_buf_tmp;
  1793. di_buf_tmp = get_di_buf_head(QUEUE_LOCAL_FREE);
  1794. if(di_buf_tmp){
  1795. queue_out(di_buf_tmp);
  1796. di_buf_tmp->pre_ref_count = 0;
  1797. di_buf_tmp->post_ref_count = 0;
  1798. di_buf_tmp->post_proc_flag = 3;
  1799. di_buf_tmp->new_format_flag = 0;
  1800. queue_in(di_buf_tmp, QUEUE_PRE_READY);
  1801. }
  1802. #ifdef DI_DEBUG
  1803. di_print("%s: dummy %s[%d] => pre_ready_list\n",
  1804. __func__, vframe_type_name[di_buf_tmp->type], di_buf_tmp->index);
  1805. #endif
  1806. }
  1807. }
  1808. di_pre_stru.di_wr_buf->seq = di_pre_stru.pre_ready_seq++;
  1809. di_pre_stru.di_wr_buf->post_ref_count = 0;
  1810. if(di_pre_stru.source_change_flag){
  1811. di_pre_stru.di_wr_buf->new_format_flag = 1;
  1812. di_pre_stru.source_change_flag = 0;
  1813. }
  1814. else{
  1815. di_pre_stru.di_wr_buf->new_format_flag = 0;
  1816. }
  1817. if(bypass_state == 1){
  1818. di_pre_stru.di_wr_buf->new_format_flag = 1;
  1819. bypass_state = 0;
  1820. }
  1821. queue_in(di_pre_stru.di_wr_buf, QUEUE_PRE_READY);
  1822. #ifdef DI_DEBUG
  1823. di_print("%s: %s[%d] => pre_ready_list\n",
  1824. __func__, vframe_type_name[di_pre_stru.di_wr_buf->type], di_pre_stru.di_wr_buf->index);
  1825. #endif
  1826. di_pre_stru.di_wr_buf = NULL;
  1827. }
  1828. }
  1829. if((di_pre_stru.process_count==0)&&(di_pre_stru.di_inp_buf)){
  1830. #ifdef DI_DEBUG
  1831. di_print("%s: %s[%d] => recycle_list\n",
  1832. __func__, vframe_type_name[di_pre_stru.di_inp_buf->type], di_pre_stru.di_inp_buf->index);
  1833. #endif
  1834. raw_local_save_flags(fiq_flag);
  1835. local_fiq_disable();
  1836. queue_in(di_pre_stru.di_inp_buf, QUEUE_RECYCLE);
  1837. di_pre_stru.di_inp_buf = NULL;
  1838. raw_local_irq_restore(fiq_flag);
  1839. }
  1840. }
  1841. #if defined(CONFIG_ARCH_MESON2)
  1842. /* add for di Reg re-init */
  1843. static enum vframe_source_type_e vframe_source_type = VFRAME_SOURCE_TYPE_OTHERS;
  1844. static void di_set_para_by_tvinfo(vframe_t* vframe)
  1845. {
  1846. if (vframe->source_type == vframe_source_type)
  1847. return;
  1848. pr_info("%s: tvinfo change, reset di Reg \n", __FUNCTION__);
  1849. vframe_source_type = vframe->source_type;
  1850. /* add for smooth skin */
  1851. if (vframe_source_type != VFRAME_SOURCE_TYPE_OTHERS)
  1852. nr_hfilt_en = 1;
  1853. else
  1854. nr_hfilt_en = 0;
  1855. //if input is pal and ntsc
  1856. if (vframe_source_type != VFRAME_SOURCE_TYPE_TUNER)
  1857. {
  1858. ei_ctrl0 = (255 << 16) | // ei_filter.
  1859. (1 << 8) | // ei_threshold.
  1860. (0 << 2) | // ei bypass cf2.
  1861. (0 << 1); // ei bypass far1
  1862. ei_ctrl1 = (90 << 24) | // ei diff
  1863. (10 << 16) | // ei ang45
  1864. (15 << 8 ) | // ei peak.
  1865. 45; // ei cross.
  1866. ei_ctrl2 = (10 << 24) | // close2
  1867. (10 << 16) | // close1
  1868. (10 << 8 ) | // far2
  1869. 93; // far1
  1870. kdeint2 = 25;
  1871. mtn_ctrl= 0xe228c440;
  1872. #ifdef CONFIG_MACH_MESON2_7366M_REFE03
  1873. if (vframe_source_type == VFRAME_SOURCE_TYPE_COMP)
  1874. blend_ctrl = 0x15f00019;
  1875. else
  1876. #endif
  1877. blend_ctrl=0x1f00019;
  1878. pr_info("%s: tvinfo change, reset di Reg \n", __FUNCTION__);
  1879. }
  1880. else //input is tuner
  1881. {
  1882. ei_ctrl0 = (255 << 16) | // ei_filter.
  1883. (1 << 8) | // ei_threshold.
  1884. (0 << 2) | // ei bypass cf2.
  1885. (0 << 1); // ei bypass far1
  1886. ei_ctrl1 = ( 90 << 24) | // ei diff
  1887. (192 << 16) | // ei ang45
  1888. (15 << 8 ) | // ei peak.
  1889. 128; // ei cross.
  1890. ei_ctrl2 = (10 << 24) | // close2
  1891. (255 << 16) | // close1
  1892. (10 << 8 ) | // far2
  1893. 255; // far1
  1894. if(kdeint1==0x10){
  1895. kdeint2 = 25;
  1896. mtn_ctrl= 0xe228c440 ;
  1897. blend_ctrl=0x1f00019;
  1898. }
  1899. else{
  1900. kdeint2 = 25;
  1901. #ifdef CONFIG_MESON2_CHIP_C
  1902. mtn_ctrl = 0xe228c440;
  1903. blend_ctrl = 0x15f00019;
  1904. mtn_ctrl1_shift = 0x00000055;
  1905. #else
  1906. mtn_ctrl= 0x0 ;
  1907. blend_ctrl=0x19f00019;
  1908. #endif
  1909. pr_info("%s: tvinfo change, reset di Reg in tuner source \n", __FUNCTION__);
  1910. }
  1911. }
  1912. //WRITE_MPEG_REG(DI_EI_CTRL0, ei_ctrl0);
  1913. //WRITE_MPEG_REG(DI_EI_CTRL1, ei_ctrl1);
  1914. //WRITE_MPEG_REG(DI_EI_CTRL2, ei_ctrl2);
  1915. }
  1916. #endif
  1917. static unsigned char pre_de_buf_config(void)
  1918. {
  1919. di_buf_t* di_buf = NULL;
  1920. vframe_t* vframe;
  1921. int i;
  1922. if((queue_empty(QUEUE_IN_FREE)&&(di_pre_stru.process_count==0))||
  1923. queue_empty(QUEUE_LOCAL_FREE)){
  1924. return 0;
  1925. }
  1926. #if 1
  1927. if(is_bypass()){ //some provider has problem if receiver get all buffers of provider
  1928. int in_buf_num = 0;
  1929. for(i=0; i<MAX_IN_BUF_NUM; i++){
  1930. if(vframe_in[i]!=NULL){
  1931. in_buf_num++;
  1932. }
  1933. }
  1934. if(in_buf_num>bypass_get_buf_threshold){
  1935. return 0;
  1936. }
  1937. }
  1938. #endif
  1939. if(di_pre_stru.process_count>0){
  1940. /* previous is progressive top */
  1941. di_pre_stru.process_count = 0;
  1942. }
  1943. else{
  1944. //check if source change
  1945. #ifdef CHECK_VDIN_BUF_ERROR
  1946. #define WR_CANVAS_BIT 0
  1947. #define WR_CANVAS_WID 8
  1948. #ifdef GET_VFRAME_DIRECTLY
  1949. if (prov && prov->ops && prov->ops->peek)
  1950. vframe = prov->ops->peek(prov->op_arg);
  1951. else
  1952. vframe = NULL;
  1953. #else
  1954. vframe = vf_peek(VFM_NAME);
  1955. #endif
  1956. if(vframe&&is_from_vdin(vframe)){
  1957. if(vframe->canvas0Addr == READ_CBUS_REG_BITS((VDIN_WR_CTRL + 0), WR_CANVAS_BIT, WR_CANVAS_WID)){
  1958. same_w_r_canvas_count++;
  1959. }
  1960. }
  1961. #endif
  1962. #ifdef GET_VFRAME_DIRECTLY
  1963. if (prov && prov->ops && prov->ops->get)
  1964. vframe = prov->ops->get(prov->op_arg);
  1965. else
  1966. vframe = NULL;
  1967. #else
  1968. vframe = vf_get(VFM_NAME);
  1969. #endif
  1970. if(vframe == NULL){
  1971. return 0;
  1972. }
  1973. #ifdef DI_DEBUG
  1974. di_print("%s: vf_get => %x\n", __func__, vframe);
  1975. #endif
  1976. provider_vframe_level--;
  1977. di_buf = get_di_buf_head(QUEUE_IN_FREE);
  1978. if((di_buf == NULL)||(di_buf->vframe == NULL)){
  1979. #ifdef DI_DEBUG
  1980. printk("%s: Error\n", __func__);
  1981. #endif
  1982. recovery_flag = 1;
  1983. return 0;
  1984. }
  1985. memcpy(di_buf->vframe, vframe, sizeof(vframe_t));
  1986. di_buf->vframe->private_data = di_buf;
  1987. vframe_in[di_buf->index] = vframe;
  1988. di_buf->seq = di_pre_stru.in_seq;
  1989. di_pre_stru.in_seq++;
  1990. queue_out(di_buf);
  1991. if(is_source_change(vframe)){ /* source change*/
  1992. if(di_pre_stru.di_mem_buf_dup_p){
  1993. di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
  1994. di_pre_stru.di_mem_buf_dup_p = NULL;
  1995. }
  1996. if(di_pre_stru.di_chan2_buf_dup_p){
  1997. di_pre_stru.di_chan2_buf_dup_p->pre_ref_count = 0;
  1998. di_pre_stru.di_chan2_buf_dup_p = NULL;
  1999. }
  2000. #ifdef DI_DEBUG
  2001. di_print("%s: source change: %d/%d/%d=>%d/%d/%d\n", __func__,
  2002. di_pre_stru.cur_inp_type, di_pre_stru.cur_width, di_pre_stru.cur_height,
  2003. di_buf->vframe->type, di_buf->vframe->width, di_buf->vframe->height);
  2004. #endif
  2005. di_pre_stru.cur_width = di_buf->vframe->width;
  2006. di_pre_stru.cur_height= di_buf->vframe->height;
  2007. di_pre_stru.cur_prog_flag = is_progressive(di_buf->vframe);
  2008. di_pre_stru.cur_inp_type = di_buf->vframe->type;
  2009. di_pre_stru.source_change_flag = 1;
  2010. di_pre_stru.same_field_source_flag = 0;
  2011. #if defined(CONFIG_ARCH_MESON2)
  2012. di_set_para_by_tvinfo(vframe);
  2013. #endif
  2014. }
  2015. else{
  2016. /* check if top/bot interleaved */
  2017. if(di_pre_stru.cur_prog_flag == 0){
  2018. if((di_pre_stru.cur_inp_type & VIDTYPE_TYPEMASK) ==
  2019. (di_buf->vframe->type & VIDTYPE_TYPEMASK)){
  2020. #ifdef CHECK_VDIN_BUF_ERROR
  2021. if ((di_buf->vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)
  2022. same_field_top_count++;
  2023. else
  2024. same_field_bot_count++;
  2025. #endif
  2026. if(di_pre_stru.same_field_source_flag<same_field_source_flag_th){
  2027. /*some source's filed is top or bot always*/
  2028. di_pre_stru.same_field_source_flag++;
  2029. if(skip_wrong_field && is_from_vdin(di_buf->vframe)){
  2030. ulong fiq_flag;
  2031. raw_local_save_flags(fiq_flag);
  2032. local_fiq_disable();
  2033. queue_in(di_buf, QUEUE_RECYCLE);
  2034. raw_local_irq_restore(fiq_flag);
  2035. return 0;
  2036. }
  2037. }
  2038. }
  2039. else{
  2040. di_pre_stru.same_field_source_flag=0;
  2041. }
  2042. }
  2043. di_pre_stru.cur_inp_type = di_buf->vframe->type;
  2044. }
  2045. if(is_bypass()){
  2046. // bypass progressive
  2047. di_buf->seq = di_pre_stru.pre_ready_seq++;
  2048. di_buf->post_ref_count = 0;
  2049. if(di_pre_stru.source_change_flag){
  2050. di_buf->new_format_flag = 1;
  2051. di_pre_stru.source_change_flag = 0;
  2052. }
  2053. else{
  2054. di_buf->new_format_flag = 0;
  2055. }
  2056. if(bypass_state == 0){
  2057. di_buf->new_format_flag = 1;
  2058. bypass_state = 1;
  2059. }
  2060. queue_in(di_buf, QUEUE_PRE_READY);
  2061. di_buf->post_proc_flag = 0;
  2062. #ifdef DI_DEBUG
  2063. di_print("%s: %s[%d] => pre_ready_list\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
  2064. #endif
  2065. return 0;
  2066. }
  2067. else if(is_progressive(vframe)){
  2068. //n
  2069. di_pre_stru.di_inp_buf = di_buf;
  2070. if(di_pre_stru.prog_proc_type == 0){
  2071. di_pre_stru.process_count = 1;
  2072. }
  2073. else{
  2074. di_pre_stru.process_count = 0;
  2075. }
  2076. #ifdef DI_DEBUG
  2077. di_print("%s: %s[%d] => di_inp_buf, process_count %d\n",
  2078. __func__, vframe_type_name[di_buf->type], di_buf->index, di_pre_stru.process_count);
  2079. #endif
  2080. if(di_pre_stru.di_mem_buf_dup_p == NULL){//use n
  2081. di_pre_stru.di_mem_buf_dup_p = di_buf;
  2082. #ifdef DI_DEBUG
  2083. di_print("%s: set di_mem_buf_dup_p to be di_inp_buf\n", __func__);
  2084. #endif
  2085. }
  2086. }
  2087. else{
  2088. //n
  2089. di_pre_stru.di_inp_buf = di_buf;
  2090. #ifdef DI_DEBUG
  2091. di_print("%s: %s[%d] => di_inp_buf\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
  2092. #endif
  2093. if(di_pre_stru.di_mem_buf_dup_p == NULL){// use n
  2094. di_pre_stru.di_mem_buf_dup_p = di_buf;
  2095. #ifdef DI_DEBUG
  2096. di_print("%s: set di_mem_buf_dup_p to be di_inp_buf\n", __func__);
  2097. #endif
  2098. }
  2099. }
  2100. }
  2101. /* di_wr_buf */
  2102. di_buf= get_di_buf_head(QUEUE_LOCAL_FREE);
  2103. if((di_buf == NULL)||(di_buf->vframe == NULL)){
  2104. #ifdef DI_DEBUG
  2105. printk("%s:Error\n", __func__);
  2106. #endif
  2107. recovery_flag = 1;
  2108. return 0;
  2109. }
  2110. queue_out(di_buf);
  2111. di_pre_stru.di_wr_buf = di_buf;
  2112. di_pre_stru.di_wr_buf->pre_ref_count = 1;
  2113. #ifdef DI_DEBUG
  2114. di_print("%s: %s[%d] => di_wr_buf\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
  2115. #endif
  2116. memcpy(di_buf->vframe, di_pre_stru.di_inp_buf->vframe, sizeof(vframe_t));
  2117. di_buf->vframe->private_data = di_buf;
  2118. di_buf->vframe->canvas0Addr = di_buf->nr_canvas_idx;
  2119. di_buf->vframe->canvas1Addr = di_buf->nr_canvas_idx;
  2120. if(di_pre_stru.prog_proc_type){
  2121. di_buf->vframe->type = VIDTYPE_PROGRESSIVE | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  2122. }
  2123. else{
  2124. if(((di_pre_stru.di_inp_buf->vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)
  2125. ||(di_pre_stru.process_count>0)){
  2126. di_buf->vframe->type = VIDTYPE_INTERLACE_TOP | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  2127. }
  2128. else{
  2129. di_buf->vframe->type = VIDTYPE_INTERLACE_BOTTOM | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  2130. }
  2131. }
  2132. /* */
  2133. if(is_progressive(di_pre_stru.di_inp_buf->vframe)){
  2134. di_pre_stru.enable_mtnwr = 0;
  2135. di_pre_stru.enable_pulldown_check = 0;
  2136. di_buf->post_proc_flag = 0;
  2137. }
  2138. else{
  2139. if(di_pre_stru.di_chan2_buf_dup_p == NULL){
  2140. di_pre_stru.enable_mtnwr = 0;
  2141. di_pre_stru.enable_pulldown_check = 0;
  2142. di_buf->post_proc_flag = 2;
  2143. }
  2144. else{
  2145. di_pre_stru.enable_mtnwr = 1;
  2146. di_pre_stru.enable_pulldown_check = 1;
  2147. di_buf->post_proc_flag = 1;
  2148. }
  2149. }
  2150. #ifndef USE_LIST
  2151. if((di_pre_stru.di_mem_buf_dup_p == di_pre_stru.di_wr_buf)||
  2152. (di_pre_stru.di_chan2_buf_dup_p == di_pre_stru.di_wr_buf)){
  2153. printk("+++++++++++++++++++++++\n");
  2154. recovery_flag = 1;
  2155. return 0;
  2156. }
  2157. #endif
  2158. return 1;
  2159. }
  2160. static int check_recycle_buf(void)
  2161. {
  2162. di_buf_t *di_buf = NULL, *ptmp;
  2163. int itmp;
  2164. int ret = 0;
  2165. queue_for_each_entry(di_buf, ptmp, QUEUE_RECYCLE, list) {
  2166. if((di_buf->pre_ref_count == 0)&&(di_buf->post_ref_count == 0)){
  2167. if(di_buf->type == VFRAME_TYPE_IN){
  2168. queue_out(di_buf);
  2169. if(vframe_in[di_buf->index]){
  2170. #ifdef GET_VFRAME_DIRECTLY
  2171. if (prov && prov->ops && prov->ops->put)
  2172. prov->ops->put(vframe_in[di_buf->index], prov->op_arg);
  2173. #else
  2174. vf_put(vframe_in[di_buf->index], VFM_NAME);
  2175. #endif
  2176. #ifdef DI_DEBUG
  2177. di_print("%s: vf_put(%d) %x\n", __func__, di_pre_stru.recycle_seq, vframe_in[di_buf->index]);
  2178. #endif
  2179. vframe_in[di_buf->index] = NULL;
  2180. }
  2181. queue_in(di_buf, QUEUE_IN_FREE);
  2182. di_pre_stru.recycle_seq++;
  2183. ret |= 1;
  2184. }
  2185. else{
  2186. queue_out(di_buf);
  2187. queue_in(di_buf, QUEUE_LOCAL_FREE);
  2188. ret |= 2;
  2189. }
  2190. #ifdef DI_DEBUG
  2191. di_print("%s: recycle %s[%d]\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
  2192. #endif
  2193. }
  2194. }
  2195. return ret;
  2196. }
  2197. static irqreturn_t de_irq(int irq, void *dev_instance)
  2198. {
  2199. unsigned int data32;
  2200. data32 = Rd(DI_INTR_CTRL);
  2201. //if ( (data32 & 0xf) != 0x1 ) {
  2202. // printk("%s: error %x\n", __func__, data32);
  2203. //} else {
  2204. Wr(DI_INTR_CTRL, data32);
  2205. //}
  2206. //Wr(A9_0_IRQ_IN1_INTR_STAT_CLR, 1 << 14);
  2207. //Rd(A9_0_IRQ_IN1_INTR_STAT_CLR);
  2208. if(di_pre_stru.pre_de_busy==0){
  2209. di_print("%s: wrong enter %x\n", __func__, Rd(DI_INTR_CTRL));
  2210. return IRQ_HANDLED;
  2211. }
  2212. #ifdef DI_DEBUG
  2213. di_print("%s: start\n", __func__);
  2214. #endif
  2215. di_pre_stru.pre_de_process_done = 1;
  2216. di_pre_stru.pre_de_busy = 0;
  2217. if(init_flag){
  2218. //printk("%s:up di sema\n", __func__);
  2219. trigger_pre_di_process('i');
  2220. }
  2221. #ifdef DI_DEBUG
  2222. di_print("%s: end\n", __func__);
  2223. #endif
  2224. return IRQ_HANDLED;
  2225. }
  2226. /*
  2227. di post process
  2228. */
  2229. static void inc_post_ref_count(di_buf_t* di_buf)
  2230. {
  2231. int post_blend_mode;
  2232. if(di_buf == NULL){
  2233. #ifdef DI_DEBUG
  2234. printk("%s: Error\n", __func__);
  2235. #endif
  2236. recovery_flag = 1;
  2237. }
  2238. if(di_buf->pulldown_mode == 0)
  2239. post_blend_mode = 0;
  2240. else if(di_buf->pulldown_mode == 1)
  2241. post_blend_mode =1;
  2242. else
  2243. post_blend_mode = 3;
  2244. if(di_buf->di_buf_dup_p[1]){
  2245. di_buf->di_buf_dup_p[1]->post_ref_count++;
  2246. }
  2247. if ( post_blend_mode != 1 ){
  2248. if(di_buf->di_buf_dup_p[0]){
  2249. di_buf->di_buf_dup_p[0]->post_ref_count++;
  2250. }
  2251. }
  2252. if(di_buf->di_buf_dup_p[2]){
  2253. di_buf->di_buf_dup_p[2]->post_ref_count++;
  2254. }
  2255. }
  2256. static void dec_post_ref_count(di_buf_t* di_buf)
  2257. {
  2258. int post_blend_mode;
  2259. if(di_buf == NULL){
  2260. #ifdef DI_DEBUG
  2261. printk("%s: Error\n", __func__);
  2262. #endif
  2263. recovery_flag = 1;
  2264. }
  2265. if(di_buf->pulldown_mode == 0)
  2266. post_blend_mode = 0;
  2267. else if(di_buf->pulldown_mode == 1)
  2268. post_blend_mode =1;
  2269. else
  2270. post_blend_mode = 3;
  2271. if(di_buf->di_buf_dup_p[1]){
  2272. di_buf->di_buf_dup_p[1]->post_ref_count--;
  2273. }
  2274. if ( post_blend_mode != 1 ){
  2275. if(di_buf->di_buf_dup_p[0]){
  2276. di_buf->di_buf_dup_p[0]->post_ref_count--;
  2277. }
  2278. }
  2279. if(di_buf->di_buf_dup_p[2]){
  2280. di_buf->di_buf_dup_p[2]->post_ref_count--;
  2281. }
  2282. }
  2283. static int de_post_disable_fun(void* arg)
  2284. {
  2285. disable_post_deinterlace_2();
  2286. return 1; //called for new_format_flag, make video set video_property_changed
  2287. }
  2288. static int do_nothing_fun(void* arg)
  2289. {
  2290. return 0;
  2291. }
  2292. static int get_vscale_skip_count(unsigned par)
  2293. {
  2294. di_vscale_skip_count = (par >> 24)&0xff;
  2295. }
  2296. static int de_post_process(void* arg, unsigned zoom_start_x_lines,
  2297. unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines)
  2298. {
  2299. di_buf_t* di_buf = (di_buf_t*)arg;
  2300. int di_width, di_height, di_start_x, di_end_x, di_start_y, di_end_y;
  2301. int hold_line = 10;
  2302. int post_blend_en, post_blend_mode;
  2303. get_vscale_skip_count(zoom_start_x_lines);
  2304. zoom_start_x_lines = zoom_start_x_lines&0xffff;
  2305. zoom_end_x_lines = zoom_end_x_lines&0xffff;
  2306. zoom_start_y_lines = zoom_start_y_lines&0xffff;
  2307. zoom_end_y_lines = zoom_end_y_lines&0xffff;
  2308. if(di_buf->pulldown_mode == 0)
  2309. post_blend_mode = 0;
  2310. else if(di_buf->pulldown_mode == 1)
  2311. post_blend_mode =1;
  2312. else
  2313. post_blend_mode = 3;
  2314. //printk("post_blend_mode %d\n", post_blend_mode);
  2315. if(init_flag == 0){
  2316. return 0;
  2317. }
  2318. di_start_x = zoom_start_x_lines;
  2319. di_end_x = zoom_end_x_lines;
  2320. di_width = di_end_x - di_start_x + 1;
  2321. di_start_y = (zoom_start_y_lines+1) & 0xfffffffe;
  2322. di_end_y = (zoom_end_y_lines-1) | 0x1;
  2323. di_height = di_end_y - di_start_y + 1;
  2324. //printk("height = (%d %d %d %d %d)\n", di_buf->vframe->height, zoom_start_x_lines, zoom_end_x_lines, zoom_start_y_lines, zoom_end_y_lines);
  2325. if ( READ_MPEG_REG(DI_POST_SIZE) != ((di_width-1) | ((di_height-1)<<16))
  2326. || (di_post_stru.di_buf0_mif.luma_x_start0 != di_start_x) || (di_post_stru.di_buf0_mif.luma_y_start0 != di_start_y/2) )
  2327. {
  2328. initial_di_post_2(di_width, di_height, hold_line);
  2329. di_post_stru.di_buf0_mif.luma_x_start0 = di_start_x;
  2330. di_post_stru.di_buf0_mif.luma_x_end0 = di_end_x;
  2331. di_post_stru.di_buf0_mif.luma_y_start0 = di_start_y/2;
  2332. di_post_stru.di_buf0_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
  2333. di_post_stru.di_buf1_mif.luma_x_start0 = di_start_x;
  2334. di_post_stru.di_buf1_mif.luma_x_end0 = di_end_x;
  2335. di_post_stru.di_buf1_mif.luma_y_start0 = di_start_y/2;
  2336. di_post_stru.di_buf1_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
  2337. di_post_stru.di_mtncrd_mif.start_x = di_start_x;
  2338. di_post_stru.di_mtncrd_mif.end_x = di_end_x;
  2339. di_post_stru.di_mtncrd_mif.start_y = di_start_y/2;
  2340. di_post_stru.di_mtncrd_mif.end_y = (di_end_y + 1)/2 - 1;
  2341. di_post_stru.di_mtnprd_mif.start_x = di_start_x;
  2342. di_post_stru.di_mtnprd_mif.end_x = di_end_x;
  2343. di_post_stru.di_mtnprd_mif.start_y = di_start_y/2;
  2344. di_post_stru.di_mtnprd_mif.end_y = (di_end_y + 1)/2 - 1;
  2345. }
  2346. di_post_stru.di_buf0_mif.canvas0_addr0 = di_buf->di_buf_dup_p[1]->nr_canvas_idx;
  2347. if ( post_blend_mode == 1 )
  2348. di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[2]->nr_canvas_idx;
  2349. else
  2350. di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[0]->nr_canvas_idx;
  2351. di_post_stru.di_mtncrd_mif.canvas_num = di_buf->di_buf_dup_p[1]->mtn_canvas_idx;
  2352. di_post_stru.di_mtnprd_mif.canvas_num = di_buf->di_buf_dup_p[2]->mtn_canvas_idx;
  2353. post_blend_en = 1;
  2354. enable_di_post_2 (
  2355. &di_post_stru.di_buf0_mif,
  2356. &di_post_stru.di_buf1_mif,
  2357. NULL,
  2358. &di_post_stru.di_mtncrd_mif,
  2359. &di_post_stru.di_mtnprd_mif,
  2360. 1, // ei enable
  2361. post_blend_en, // blend enable
  2362. post_blend_en, // blend mtn enable
  2363. post_blend_mode, // blend mode.
  2364. 1, // di_vpp_en.
  2365. 0, // di_ddr_en.
  2366. (di_buf->di_buf_dup_p[1]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_TOP ? 0 : 1, // 1 bottom generate top
  2367. hold_line,
  2368. reg_mtn_info
  2369. );
  2370. return 0;
  2371. }
  2372. static int de_post_process_pd(void* arg, unsigned zoom_start_x_lines,
  2373. unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines)
  2374. {
  2375. di_buf_t* di_buf = (di_buf_t*)arg;
  2376. int di_width, di_height, di_start_x, di_end_x, di_start_y, di_end_y;
  2377. int hold_line = 10;
  2378. int post_blend_mode;
  2379. get_vscale_skip_count(zoom_start_x_lines);
  2380. zoom_start_x_lines = zoom_start_x_lines&0xffff;
  2381. zoom_end_x_lines = zoom_end_x_lines&0xffff;
  2382. zoom_start_y_lines = zoom_start_y_lines&0xffff;
  2383. zoom_end_y_lines = zoom_end_y_lines&0xffff;
  2384. if(di_buf->pulldown_mode == 0)
  2385. post_blend_mode = 0;
  2386. else
  2387. post_blend_mode =1;
  2388. if(init_flag == 0){
  2389. return 0;
  2390. }
  2391. di_start_x = zoom_start_x_lines;
  2392. di_end_x = zoom_end_x_lines;
  2393. di_width = di_end_x - di_start_x + 1;
  2394. di_start_y = (zoom_start_y_lines+1) & 0xfffffffe;
  2395. di_end_y = (zoom_end_y_lines-1) | 0x1;
  2396. di_height = di_end_y - di_start_y + 1;
  2397. //printk("height = (%d %d %d %d %d)\n", di_buf->vframe->height, zoom_start_x_lines, zoom_end_x_lines, zoom_start_y_lines, zoom_end_y_lines);
  2398. if ( READ_MPEG_REG(DI_POST_SIZE) != ((di_width-1) | ((di_height-1)<<16))
  2399. || (di_post_stru.di_buf0_mif.luma_x_start0 != di_start_x) || (di_post_stru.di_buf0_mif.luma_y_start0 != di_start_y/2) )
  2400. {
  2401. initial_di_post_2(di_width, di_height, hold_line);
  2402. di_post_stru.di_buf0_mif.luma_x_start0 = di_start_x;
  2403. di_post_stru.di_buf0_mif.luma_x_end0 = di_end_x;
  2404. di_post_stru.di_buf0_mif.luma_y_start0 = di_start_y/2;
  2405. di_post_stru.di_buf0_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
  2406. di_post_stru.di_buf1_mif.luma_x_start0 = di_start_x;
  2407. di_post_stru.di_buf1_mif.luma_x_end0 = di_end_x;
  2408. di_post_stru.di_buf1_mif.luma_y_start0 = di_start_y/2;
  2409. di_post_stru.di_buf1_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
  2410. di_post_stru.di_mtncrd_mif.start_x = di_start_x;
  2411. di_post_stru.di_mtncrd_mif.end_x = di_end_x;
  2412. di_post_stru.di_mtncrd_mif.start_y = di_start_y/2;
  2413. di_post_stru.di_mtncrd_mif.end_y = (di_end_y + 1)/2 - 1;
  2414. di_post_stru.di_mtnprd_mif.start_x = di_start_x;
  2415. di_post_stru.di_mtnprd_mif.end_x = di_end_x;
  2416. di_post_stru.di_mtnprd_mif.start_y = di_start_y/2;
  2417. di_post_stru.di_mtnprd_mif.end_y = (di_end_y + 1)/2 - 1;
  2418. }
  2419. di_post_stru.di_buf0_mif.canvas0_addr0 = di_buf->di_buf_dup_p[1]->nr_canvas_idx;
  2420. if ( post_blend_mode == 1 )
  2421. di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[2]->nr_canvas_idx;
  2422. else
  2423. di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[0]->nr_canvas_idx;
  2424. di_post_stru.di_mtncrd_mif.canvas_num = di_buf->di_buf_dup_p[1]->mtn_canvas_idx;
  2425. di_post_stru.di_mtnprd_mif.canvas_num = di_buf->di_buf_dup_p[2]->mtn_canvas_idx;
  2426. enable_di_post_pd (
  2427. &di_post_stru.di_buf0_mif,
  2428. &di_post_stru.di_buf1_mif,
  2429. NULL,
  2430. &di_post_stru.di_mtncrd_mif,
  2431. &di_post_stru.di_mtnprd_mif,
  2432. 1, // ei enable
  2433. 1, // blend enable
  2434. 1, // blend mtn enable
  2435. post_blend_mode, // blend mode.
  2436. 1, // di_vpp_en.
  2437. 0, // di_ddr_en.
  2438. (di_buf->di_buf_dup_p[1]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_TOP ? 0 : 1, // 1 bottom generate top
  2439. hold_line
  2440. );
  2441. return 0;
  2442. }
  2443. static int de_post_process_prog(void* arg, unsigned zoom_start_x_lines,
  2444. unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines)
  2445. {
  2446. di_buf_t* di_buf = (di_buf_t*)arg;
  2447. int di_width, di_height, di_start_x, di_end_x, di_start_y, di_end_y;
  2448. int hold_line = 10;
  2449. int post_blend_mode;
  2450. get_vscale_skip_count(zoom_start_x_lines);
  2451. zoom_start_x_lines = zoom_start_x_lines&0xffff;
  2452. zoom_end_x_lines = zoom_end_x_lines&0xffff;
  2453. zoom_start_y_lines = zoom_start_y_lines&0xffff;
  2454. zoom_end_y_lines = zoom_end_y_lines&0xffff;
  2455. post_blend_mode =1;
  2456. if(init_flag == 0){
  2457. return 0;
  2458. }
  2459. di_start_x = zoom_start_x_lines;
  2460. di_end_x = zoom_end_x_lines;
  2461. di_width = di_end_x - di_start_x + 1;
  2462. di_start_y = (zoom_start_y_lines+1) & 0xfffffffe;
  2463. di_end_y = (zoom_end_y_lines-1) | 0x1;
  2464. di_height = di_end_y - di_start_y + 1;
  2465. //printk("height = (%d %d %d %d %d)\n", di_buf->vframe->height, zoom_start_x_lines, zoom_end_x_lines, zoom_start_y_lines, zoom_end_y_lines);
  2466. if ( READ_MPEG_REG(DI_POST_SIZE) != ((di_width-1) | ((di_height-1)<<16))
  2467. || (di_post_stru.di_buf0_mif.luma_x_start0 != di_start_x) || (di_post_stru.di_buf0_mif.luma_y_start0 != di_start_y/2) )
  2468. {
  2469. initial_di_post_2(di_width, di_height, hold_line);
  2470. di_post_stru.di_buf0_mif.luma_x_start0 = di_start_x;
  2471. di_post_stru.di_buf0_mif.luma_x_end0 = di_end_x;
  2472. di_post_stru.di_buf0_mif.luma_y_start0 = di_start_y/2;
  2473. di_post_stru.di_buf0_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
  2474. di_post_stru.di_buf1_mif.luma_x_start0 = di_start_x;
  2475. di_post_stru.di_buf1_mif.luma_x_end0 = di_end_x;
  2476. di_post_stru.di_buf1_mif.luma_y_start0 = di_start_y/2;
  2477. di_post_stru.di_buf1_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
  2478. di_post_stru.di_mtncrd_mif.start_x = di_start_x;
  2479. di_post_stru.di_mtncrd_mif.end_x = di_end_x;
  2480. di_post_stru.di_mtncrd_mif.start_y = di_start_y/2;
  2481. di_post_stru.di_mtncrd_mif.end_y = (di_end_y + 1)/2 - 1;
  2482. di_post_stru.di_mtnprd_mif.start_x = di_start_x;
  2483. di_post_stru.di_mtnprd_mif.end_x = di_end_x;
  2484. di_post_stru.di_mtnprd_mif.start_y = di_start_y/2;
  2485. di_post_stru.di_mtnprd_mif.end_y = (di_end_y + 1)/2 - 1;
  2486. }
  2487. di_post_stru.di_buf0_mif.canvas0_addr0 = di_buf->di_buf_dup_p[0]->nr_canvas_idx;
  2488. di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[1]->nr_canvas_idx;
  2489. di_post_stru.di_mtncrd_mif.canvas_num = di_buf->di_buf_dup_p[0]->mtn_canvas_idx;
  2490. di_post_stru.di_mtnprd_mif.canvas_num = di_buf->di_buf_dup_p[1]->mtn_canvas_idx;
  2491. enable_di_post_pd (
  2492. &di_post_stru.di_buf0_mif,
  2493. &di_post_stru.di_buf1_mif,
  2494. NULL,
  2495. &di_post_stru.di_mtncrd_mif,
  2496. &di_post_stru.di_mtnprd_mif,
  2497. 1, // ei enable
  2498. 1, // blend enable
  2499. 1, // blend mtn enable
  2500. post_blend_mode, // blend mode.
  2501. 1, // di_vpp_en.
  2502. 0, // di_ddr_en.
  2503. (di_buf->di_buf_dup_p[0]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_TOP ? 0 : 1, // 1 bottom generate top
  2504. hold_line
  2505. );
  2506. return 0;
  2507. }
  2508. #ifdef FORCE_BOB_SUPPORT
  2509. static int de_post_process_force_bob(void* arg, unsigned zoom_start_x_lines,
  2510. unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines)
  2511. {
  2512. de_post_process(arg, zoom_start_x_lines, zoom_end_x_lines, zoom_start_y_lines, zoom_end_y_lines);
  2513. WRITE_MPEG_REG(DI_BLEND_CTRL, READ_MPEG_REG(DI_BLEND_CTRL)&0xffefffff);
  2514. return 0;
  2515. }
  2516. #endif
  2517. int pd_detect_rst ;
  2518. static void recycle_vframe_type_post(di_buf_t* di_buf)
  2519. {
  2520. int i;
  2521. if(di_buf == NULL){
  2522. #ifdef DI_DEBUG
  2523. printk("%s:Error\n", __func__);
  2524. #endif
  2525. recovery_flag = 1;
  2526. return;
  2527. }
  2528. if( di_buf->vframe->process_fun == de_post_process_pd
  2529. || di_buf->vframe->process_fun == de_post_process
  2530. #ifdef FORCE_BOB_SUPPORT
  2531. || di_buf->vframe->process_fun == de_post_process_force_bob
  2532. #endif
  2533. ){
  2534. dec_post_ref_count(di_buf);
  2535. }
  2536. for(i=0;i<2;i++){
  2537. if(di_buf->di_buf[i])
  2538. queue_in(di_buf->di_buf[i], QUEUE_RECYCLE);
  2539. }
  2540. queue_out(di_buf); //remove it from display_list_head
  2541. queue_in(di_buf, QUEUE_POST_FREE);
  2542. }
  2543. #ifdef DI_DEBUG
  2544. static void recycle_vframe_type_post_print(di_buf_t* di_buf, const char* func)
  2545. {
  2546. int i;
  2547. di_print("%s:", func);
  2548. for(i=0;i<2;i++){
  2549. if(di_buf->di_buf[i]){
  2550. di_print("%s[%d]<%d>=>recycle_list; ", vframe_type_name[di_buf->di_buf[i]->type], di_buf->di_buf[i]->index, i);
  2551. }
  2552. }
  2553. di_print("%s[%d] =>post_free_list\n", vframe_type_name[di_buf->type], di_buf->index);
  2554. }
  2555. #endif
  2556. static int process_post_vframe(void)
  2557. {
  2558. /*
  2559. 1) get buf from post_free_list, config it according to buf in pre_ready_list, send it to post_ready_list
  2560. (it will be send to post_free_list in di_vf_put())
  2561. 2) get buf from pre_ready_list, attach it to buf from post_free_list
  2562. (it will be send to recycle_list in di_vf_put() )
  2563. */
  2564. ulong fiq_flag;
  2565. int i,pulldown_mode_hise;
  2566. int ret = 0;
  2567. int buffer_keep_count = 3;
  2568. di_buf_t* di_buf = NULL;
  2569. di_buf_t *ready_di_buf;
  2570. di_buf_t *p = NULL, *ptmp;
  2571. int itmp;
  2572. int ready_count = list_count(QUEUE_PRE_READY);
  2573. if(queue_empty(QUEUE_POST_FREE)){
  2574. return 0;
  2575. }
  2576. if(ready_count>0){
  2577. ready_di_buf = get_di_buf_head(QUEUE_PRE_READY);
  2578. if((ready_di_buf == NULL)||(ready_di_buf->vframe == NULL)){
  2579. #ifdef DI_DEBUG
  2580. printk("%s:Error1\n", __func__);
  2581. #endif
  2582. recovery_flag = 1;
  2583. return 0;
  2584. }
  2585. if(ready_di_buf->post_proc_flag){
  2586. /*if((pulldown_buffer_mode&1)
  2587. &&(real_buf_mgr_mode==0)){
  2588. buffer_keep_count = 4;
  2589. }
  2590. else{
  2591. buffer_keep_count = 3;
  2592. }*/
  2593. if(ready_count>=buffer_keep_count){
  2594. raw_local_save_flags(fiq_flag);
  2595. local_fiq_disable();
  2596. di_buf = get_di_buf_head(QUEUE_POST_FREE);
  2597. if((di_buf == NULL)||(di_buf->vframe == NULL)){
  2598. #ifdef DI_DEBUG
  2599. printk("%s:Error2\n", __func__);
  2600. #endif
  2601. raw_local_irq_restore(fiq_flag);
  2602. recovery_flag = 1;
  2603. return 0;
  2604. }
  2605. queue_out(di_buf);
  2606. raw_local_irq_restore(fiq_flag);
  2607. i = 0;
  2608. queue_for_each_entry(p, ptmp, QUEUE_PRE_READY, list) {
  2609. di_buf->di_buf_dup_p[i++] = p;
  2610. if(i>=buffer_keep_count)
  2611. break;
  2612. }
  2613. if(i<buffer_keep_count){
  2614. #ifdef DI_DEBUG
  2615. printk("%s:Error3\n", __func__);
  2616. #endif
  2617. recovery_flag = 1;
  2618. return 0;
  2619. }
  2620. memcpy(di_buf->vframe, di_buf->di_buf_dup_p[1]->vframe, sizeof(vframe_t));
  2621. di_buf->vframe->private_data = di_buf;
  2622. if(di_buf->di_buf_dup_p[1]->post_proc_flag == 3){//dummy, not for display
  2623. di_buf->di_buf[0] = di_buf->di_buf_dup_p[0];
  2624. di_buf->di_buf[1] = NULL;
  2625. queue_out(di_buf->di_buf[0]);
  2626. raw_local_save_flags(fiq_flag);
  2627. local_fiq_disable();
  2628. queue_in(di_buf, QUEUE_TMP);
  2629. recycle_vframe_type_post(di_buf);
  2630. raw_local_irq_restore(fiq_flag);
  2631. #ifdef DI_DEBUG
  2632. di_print("%s <dummy>: ", __func__);
  2633. #endif
  2634. }
  2635. else{
  2636. if(di_buf->di_buf_dup_p[1]->post_proc_flag == 2){
  2637. reset_pulldown_state();
  2638. di_buf->pulldown_mode = 1; /* blend with di_buf->di_buf_dup_p[2] */
  2639. }
  2640. else{
  2641. int pulldown_type=-1; /* 0, 2:2; 1, m:n */
  2642. int win_pd_type[5] = {-1,-1,-1,-1,-1};
  2643. int ii;
  2644. int pulldown_mode2;
  2645. insert_pd_his(&di_buf->di_buf_dup_p[1]->field_pd_info);
  2646. if(buffer_keep_count==4){
  2647. //4 buffers
  2648. cal_pd_parameters(&di_buf->di_buf_dup_p[2]->field_pd_info, &di_buf->di_buf_dup_p[1]->field_pd_info, &di_buf->di_buf_dup_p[3]->field_pd_info, &field_pd_th); //cal parameters of di_buf_dup_p[2]
  2649. pattern_check_pre_2(0, &di_buf->di_buf_dup_p[3]->field_pd_info,
  2650. &di_buf->di_buf_dup_p[2]->field_pd_info,
  2651. &di_buf->di_buf_dup_p[1]->field_pd_info,
  2652. &di_buf->di_buf_dup_p[2]->pulldown_mode,
  2653. &di_buf->di_buf_dup_p[1]->pulldown_mode,
  2654. &pulldown_type, &field_pd_th
  2655. );
  2656. for(ii=0;ii<MAX_WIN_NUM; ii++){
  2657. cal_pd_parameters(&di_buf->di_buf_dup_p[2]->win_pd_info[ii], &di_buf->di_buf_dup_p[1]->win_pd_info[ii], &di_buf->di_buf_dup_p[3]->win_pd_info[ii], &field_pd_th); //cal parameters of di_buf_dup_p[2]
  2658. pattern_check_pre_2(ii+1, &di_buf->di_buf_dup_p[3]->win_pd_info[ii],
  2659. &di_buf->di_buf_dup_p[2]->win_pd_info[ii],
  2660. &di_buf->di_buf_dup_p[1]->win_pd_info[ii],
  2661. &(di_buf->di_buf_dup_p[2]->win_pd_mode[ii]),
  2662. &(di_buf->di_buf_dup_p[1]->win_pd_mode[ii]),
  2663. &(win_pd_type[ii]), &win_pd_th[ii]
  2664. );
  2665. }
  2666. }
  2667. else{
  2668. //3 buffers
  2669. cal_pd_parameters(&di_buf->di_buf_dup_p[1]->field_pd_info, &di_buf->di_buf_dup_p[0]->field_pd_info, &di_buf->di_buf_dup_p[2]->field_pd_info, &field_pd_th); //cal parameters of di_buf_dup_p[1]
  2670. pattern_check_pre_2(0, &di_buf->di_buf_dup_p[2]->field_pd_info,
  2671. &di_buf->di_buf_dup_p[1]->field_pd_info,
  2672. &di_buf->di_buf_dup_p[0]->field_pd_info,
  2673. &di_buf->di_buf_dup_p[1]->pulldown_mode,
  2674. NULL, &pulldown_type, &field_pd_th);
  2675. for(ii=0;ii<MAX_WIN_NUM; ii++){
  2676. cal_pd_parameters(&di_buf->di_buf_dup_p[1]->win_pd_info[ii], &di_buf->di_buf_dup_p[0]->win_pd_info[ii], &di_buf->di_buf_dup_p[2]->win_pd_info[ii], &field_pd_th); //cal parameters of di_buf_dup_p[1]
  2677. pattern_check_pre_2(ii+1, &di_buf->di_buf_dup_p[2]->win_pd_info[ii],
  2678. &di_buf->di_buf_dup_p[1]->win_pd_info[ii],
  2679. &di_buf->di_buf_dup_p[0]->win_pd_info[ii],
  2680. &(di_buf->di_buf_dup_p[1]->win_pd_mode[ii]),
  2681. NULL,&(win_pd_type[ii]), &win_pd_th[ii]
  2682. );
  2683. }
  2684. }
  2685. pulldown_mode_hise = pulldown_mode2 = detect_pd32();
  2686. if(di_log_flag&DI_LOG_PULLDOWN)
  2687. {
  2688. di_buf_t* dp = di_buf->di_buf_dup_p[1];
  2689. di_print("%02d (%x%x%x) %08x %06x %08x %06x %02x %02x %02x %02x %02x %02x %02x %02x ", dp->seq%100,
  2690. dp->pulldown_mode<0?0xf:dp->pulldown_mode, pulldown_type<0?0xf:pulldown_type,
  2691. pulldown_mode2<0?0xf:pulldown_mode2,
  2692. dp->field_pd_info.frame_diff, dp->field_pd_info.frame_diff_num,
  2693. dp->field_pd_info.field_diff, dp->field_pd_info.field_diff_num,
  2694. dp->field_pd_info.frame_diff_by_pre, dp->field_pd_info.frame_diff_num_by_pre,
  2695. dp->field_pd_info.field_diff_by_pre, dp->field_pd_info.field_diff_num_by_pre,
  2696. dp->field_pd_info.field_diff_by_next, dp->field_pd_info.field_diff_num_by_next,
  2697. dp->field_pd_info.frame_diff_skew_ratio, dp->field_pd_info.frame_diff_num_skew_ratio);
  2698. for(ii=0; ii<MAX_WIN_NUM; ii++){
  2699. di_print("(%x,%x) %08x %06x %08x %06x %02x %02x %02x %02x %02x %02x %02x %02x ", dp->win_pd_mode[ii]<0?0xf:dp->win_pd_mode[ii],
  2700. win_pd_type[ii]<0?0xf:win_pd_type[ii],
  2701. dp->win_pd_info[ii].frame_diff, dp->win_pd_info[ii].frame_diff_num,
  2702. dp->win_pd_info[ii].field_diff, dp->win_pd_info[ii].field_diff_num,
  2703. dp->win_pd_info[ii].frame_diff_by_pre, dp->win_pd_info[ii].frame_diff_num_by_pre,
  2704. dp->win_pd_info[ii].field_diff_by_pre, dp->win_pd_info[ii].field_diff_num_by_pre,
  2705. dp->win_pd_info[ii].field_diff_by_next, dp->win_pd_info[ii].field_diff_num_by_next,
  2706. dp->win_pd_info[ii].frame_diff_skew_ratio, dp->win_pd_info[ii].frame_diff_num_skew_ratio);
  2707. }
  2708. di_print("\n");
  2709. }
  2710. di_buf->pulldown_mode = -1;
  2711. if(pulldown_detect){
  2712. if(pulldown_detect&0x1){
  2713. di_buf->pulldown_mode = di_buf->di_buf_dup_p[1]->pulldown_mode; //used by de_post_process
  2714. }
  2715. if(pulldown_detect&0x10){
  2716. if((pulldown_mode2 >=0) && (pd_detect_rst > 15)){
  2717. di_buf->pulldown_mode = pulldown_mode2;
  2718. }
  2719. }
  2720. if(pd_detect_rst <= 32)
  2721. pd_detect_rst ++;
  2722. if((pulldown_win_mode&0xfffff)!=0){
  2723. int ii;
  2724. unsigned mode;
  2725. for(ii=0; ii<5; ii++){
  2726. mode = (pulldown_win_mode>>(ii*4))&0xf;
  2727. if(mode==1){
  2728. if(di_buf->di_buf_dup_p[1]->pulldown_mode == 0){
  2729. if((di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num*win_pd_th[ii].field_diff_num_th) >=
  2730. pd_win_prop[ii].pixels_num){
  2731. break;
  2732. }
  2733. }
  2734. else{
  2735. if((di_buf->di_buf_dup_p[2]->win_pd_info[ii].field_diff_num*win_pd_th[ii].field_diff_num_th) >=
  2736. pd_win_prop[ii].pixels_num){
  2737. break;
  2738. }
  2739. }
  2740. if ((ii!= 0) &&
  2741. (ii!= 5) &&
  2742. (ii!= 4) &&
  2743. (pulldown_mode2 == 1) &&
  2744. (((di_buf->di_buf_dup_p[2]->win_pd_info[ii+1].field_diff_num*100) < di_buf->di_buf_dup_p[1]->win_pd_info[ii+1].field_diff_num) &&
  2745. ((di_buf->di_buf_dup_p[2]->win_pd_info[ii-1].field_diff_num*100) < di_buf->di_buf_dup_p[1]->win_pd_info[ii-1].field_diff_num) &&
  2746. ((di_buf->di_buf_dup_p[2]->win_pd_info[ii ].field_diff_num*100) >= di_buf->di_buf_dup_p[1]->win_pd_info[ii ].field_diff_num)
  2747. )
  2748. )
  2749. {
  2750. di_print("out %x %06x %06x \n",
  2751. ii,
  2752. di_buf->di_buf_dup_p[2]->win_pd_info[ii].field_diff_num,
  2753. di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num);
  2754. pd_detect_rst =0;
  2755. break;
  2756. }
  2757. if ((ii!= 0) &&
  2758. (ii!= 5) &&
  2759. (ii!= 4) &&
  2760. (pulldown_mode2 == 0) &&
  2761. ((di_buf->di_buf_dup_p[1]->win_pd_info[ii+1].field_diff_num*100)<di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num) &&
  2762. ((di_buf->di_buf_dup_p[1]->win_pd_info[ii-1].field_diff_num*100)<di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num)
  2763. )
  2764. {
  2765. pd_detect_rst =0;
  2766. break;
  2767. }
  2768. }
  2769. else if(mode==2){
  2770. if( (pulldown_type == 0) &&
  2771. (di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num_pattern
  2772. != di_buf->di_buf_dup_p[1]->field_pd_info.field_diff_num_pattern )
  2773. ){
  2774. break;
  2775. }
  2776. if( (pulldown_type == 1) &&
  2777. (di_buf->di_buf_dup_p[1]->win_pd_info[ii].frame_diff_num_pattern
  2778. != di_buf->di_buf_dup_p[1]->field_pd_info.frame_diff_num_pattern )
  2779. ){
  2780. break;
  2781. }
  2782. }
  2783. else if(mode==3){
  2784. if((di_buf->di_buf_dup_p[1]->win_pd_mode[ii]!= di_buf->di_buf_dup_p[1]->pulldown_mode)
  2785. ||(pulldown_type!=win_pd_type[ii])){
  2786. break;
  2787. }
  2788. }
  2789. }
  2790. if(ii<5){
  2791. di_buf->pulldown_mode = -1;
  2792. if(mode==1){
  2793. // printk("Deinterlace pulldown %s, win%d pd field_diff_num %08x/%08x is too big\n",
  2794. // (pulldown_type==0)?"2:2":"3:2", ii, pd_win_prop[ii].pixels_num,
  2795. // (di_buf->di_buf_dup_p[1]->pulldown_mode==0)? di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num:di_buf->di_buf_dup_p[2]->win_pd_info[ii].field_diff_num
  2796. // );
  2797. }
  2798. else if(mode==2){
  2799. // printk("Deinterlace pulldown %s, win%d pd pattern %08x is different from field pd pattern %08x\n",
  2800. // (pulldown_type==0)?"2:2":"3:2", ii,
  2801. // (pulldown_type==0)? di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num_pattern:di_buf->di_buf_dup_p[1]->win_pd_info[ii].frame_diff_num_pattern,
  2802. // (pulldown_type==0)? di_buf->di_buf_dup_p[1]->field_pd_info.field_diff_num_pattern:di_buf->di_buf_dup_p[1]->field_pd_info.frame_diff_num_pattern
  2803. // );
  2804. }
  2805. else{
  2806. // printk("Deinterlace pulldown, win%d pd type (%d, %d) is different from field pd type (%d, %d)\n",
  2807. // ii, di_buf->di_buf_dup_p[1]->win_pd_mode[ii], win_pd_type[ii],
  2808. // di_buf->di_buf_dup_p[1]->pulldown_mode, pulldown_type);
  2809. }
  2810. }
  2811. }
  2812. /*
  2813. if(di_buf->pulldown_mode>=0)
  2814. printk("%s pulldown\n", (pulldown_type==0)?"2:2":"m:n");
  2815. if((di_buf->vframe->tvin_sig_fmt == TVIN_SIG_FMT_CVBS_PAL_I)
  2816. && (pulldown_type == 1)){
  2817. //m:n not do
  2818. di_buf->pulldown_mode = -1;
  2819. printk("m:n ignore\n");
  2820. }
  2821. if((di_buf->vframe->tvin_sig_fmt == TVIN_SIG_FMT_CVBS_NTSC_M)
  2822. && (pulldown_type == 0)){
  2823. //2:2 not do
  2824. di_buf->pulldown_mode = -1;
  2825. printk("2:2 ignore\n");
  2826. }
  2827. */
  2828. if(di_buf->pulldown_mode != -1){
  2829. pulldown_count++;
  2830. }
  2831. #if defined(CONFIG_ARCH_MESON2)
  2832. if(di_buf->vframe->source_type == VFRAME_SOURCE_TYPE_TUNER) {
  2833. di_buf->pulldown_mode = -1;
  2834. //printk("2:2 ignore\n");
  2835. }
  2836. #endif
  2837. }
  2838. }
  2839. #ifdef FORCE_BOB_SUPPORT
  2840. /*added for hisense*/
  2841. if(pd_enable){
  2842. if(pulldown_mode_hise == 2)
  2843. force_bob_flag = 1;
  2844. else
  2845. force_bob_flag = 0;
  2846. }
  2847. if(force_bob_flag!=0){
  2848. di_buf->vframe->type = VIDTYPE_PROGRESSIVE| VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  2849. if((force_bob_flag==1)||(force_bob_flag==2)){
  2850. di_buf->vframe->duration<<=1;
  2851. }
  2852. di_buf->vframe->private_data = di_buf;
  2853. if(di_buf->di_buf_dup_p[1]->new_format_flag){ //if(di_buf->di_buf_dup_p[1]->post_proc_flag == 2){
  2854. di_buf->vframe->early_process_fun = de_post_disable_fun;
  2855. }
  2856. else{
  2857. di_buf->vframe->early_process_fun = do_nothing_fun;
  2858. }
  2859. di_buf->vframe->process_fun = de_post_process_force_bob;
  2860. inc_post_ref_count(di_buf);
  2861. di_buf->di_buf[0] = di_buf->di_buf_dup_p[0];
  2862. di_buf->di_buf[1] = NULL;
  2863. queue_out(di_buf->di_buf[0]);
  2864. raw_local_save_flags(fiq_flag);
  2865. local_fiq_disable();
  2866. if((frame_count<start_frame_drop_count)||
  2867. (((di_buf->di_buf_dup_p[1]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_TOP)
  2868. && ((force_bob_flag&1)==0))||
  2869. (((di_buf->di_buf_dup_p[1]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_BOTTOM)
  2870. && ((force_bob_flag&2)==0))){
  2871. queue_in(di_buf, QUEUE_TMP);
  2872. recycle_vframe_type_post(di_buf);
  2873. #ifdef DI_DEBUG
  2874. recycle_vframe_type_post_print(di_buf, __func__);
  2875. #endif
  2876. }
  2877. else{
  2878. queue_in(di_buf, QUEUE_POST_READY);
  2879. }
  2880. frame_count++;
  2881. raw_local_irq_restore(fiq_flag);
  2882. }
  2883. else{
  2884. #endif
  2885. di_buf->vframe->type = VIDTYPE_PROGRESSIVE| VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  2886. if(di_buf->di_buf_dup_p[1]->new_format_flag){ //if(di_buf->di_buf_dup_p[1]->post_proc_flag == 2){
  2887. di_buf->vframe->early_process_fun = de_post_disable_fun;
  2888. }
  2889. else{
  2890. di_buf->vframe->early_process_fun = do_nothing_fun;
  2891. }
  2892. if(di_buf->pulldown_mode >= 0){
  2893. di_buf->vframe->process_fun = de_post_process_pd;
  2894. inc_post_ref_count(di_buf);
  2895. }
  2896. else{
  2897. di_buf->vframe->process_fun = de_post_process;
  2898. inc_post_ref_count(di_buf);
  2899. }
  2900. di_buf->di_buf[0] = di_buf->di_buf_dup_p[0];
  2901. di_buf->di_buf[1] = NULL;
  2902. queue_out(di_buf->di_buf[0]);
  2903. raw_local_save_flags(fiq_flag);
  2904. local_fiq_disable();
  2905. if(frame_count<start_frame_drop_count){
  2906. queue_in(di_buf, QUEUE_TMP);
  2907. recycle_vframe_type_post(di_buf);
  2908. #ifdef DI_DEBUG
  2909. recycle_vframe_type_post_print(di_buf, __func__);
  2910. #endif
  2911. }
  2912. else{
  2913. queue_in(di_buf, QUEUE_POST_READY);
  2914. }
  2915. frame_count++;
  2916. raw_local_irq_restore(fiq_flag);
  2917. #ifdef FORCE_BOB_SUPPORT
  2918. }
  2919. #endif
  2920. #ifdef DI_DEBUG
  2921. di_print("%s <interlace>: ", __func__);
  2922. #endif
  2923. }
  2924. ret = 1;
  2925. }
  2926. }
  2927. else{
  2928. if(is_progressive(ready_di_buf->vframe)||
  2929. ready_di_buf->type == VFRAME_TYPE_IN){
  2930. raw_local_save_flags(fiq_flag);
  2931. local_fiq_disable();
  2932. di_buf = get_di_buf_head(QUEUE_POST_FREE);
  2933. if((di_buf == NULL)||(di_buf->vframe == NULL)){
  2934. #ifdef DI_DEBUG
  2935. printk("%s:Error4\n", __func__);
  2936. #endif
  2937. raw_local_irq_restore(fiq_flag);
  2938. recovery_flag = 1;
  2939. return 0;
  2940. }
  2941. queue_out(di_buf);
  2942. raw_local_irq_restore(fiq_flag);
  2943. memcpy(di_buf->vframe, ready_di_buf->vframe, sizeof(vframe_t));
  2944. di_buf->vframe->private_data = di_buf;
  2945. if(frame_packing_mode == 1){
  2946. #if defined(CONFIG_ARCH_MESON2)
  2947. if(di_buf->vframe->trans_fmt == TVIN_TFMT_3D_FP){
  2948. if(di_buf->vframe->height == 2205){
  2949. di_buf->vframe->height = 1080;
  2950. }
  2951. if(di_buf->vframe->height == 1470){
  2952. di_buf->vframe->height = 720;
  2953. }
  2954. }
  2955. #endif
  2956. }
  2957. else{
  2958. if(di_buf->vframe->height > 2000){ //work around hw problem
  2959. di_buf->vframe->height = 2000;
  2960. }
  2961. }
  2962. if(ready_di_buf->new_format_flag){
  2963. di_buf->vframe->early_process_fun = de_post_disable_fun;
  2964. }
  2965. else{
  2966. di_buf->vframe->early_process_fun = do_nothing_fun;
  2967. }
  2968. di_buf->vframe->process_fun = NULL;
  2969. di_buf->di_buf[0] = ready_di_buf;
  2970. di_buf->di_buf[1] = NULL;
  2971. queue_out(ready_di_buf);
  2972. raw_local_save_flags(fiq_flag);
  2973. local_fiq_disable();
  2974. if(frame_count<start_frame_drop_count){
  2975. queue_in(di_buf, QUEUE_TMP);
  2976. recycle_vframe_type_post(di_buf);
  2977. #ifdef DI_DEBUG
  2978. recycle_vframe_type_post_print(di_buf, __func__);
  2979. #endif
  2980. }
  2981. else{
  2982. queue_in(di_buf, QUEUE_POST_READY);
  2983. }
  2984. frame_count++;
  2985. raw_local_irq_restore(fiq_flag);
  2986. #ifdef DI_DEBUG
  2987. di_print("%s <prog by frame>: ", __func__);
  2988. #endif
  2989. ret = 1;
  2990. }
  2991. else if(ready_count>=2){
  2992. unsigned char prog_tb_field_proc_type = (prog_proc_config>>1)&0x3;
  2993. raw_local_save_flags(fiq_flag);
  2994. local_fiq_disable();
  2995. di_buf = get_di_buf_head(QUEUE_POST_FREE);
  2996. if((di_buf == NULL)||(di_buf->vframe==NULL)){
  2997. #ifdef DI_DEBUG
  2998. printk("%s:Error5\n", __func__);
  2999. #endif
  3000. raw_local_irq_restore(fiq_flag);
  3001. recovery_flag = 1;
  3002. return 0;
  3003. }
  3004. queue_out(di_buf);
  3005. raw_local_irq_restore(fiq_flag);
  3006. i = 0;
  3007. queue_for_each_entry(p, ptmp, QUEUE_PRE_READY, list) {
  3008. di_buf->di_buf_dup_p[i++] = p;
  3009. if(i>=2)
  3010. break;
  3011. }
  3012. if(i<2){
  3013. #ifdef DI_DEBUG
  3014. printk("%s:Error6\n", __func__);
  3015. #endif
  3016. recovery_flag = 1;
  3017. return 0;
  3018. }
  3019. memcpy(di_buf->vframe, di_buf->di_buf_dup_p[0]->vframe, sizeof(vframe_t));
  3020. di_buf->vframe->private_data = di_buf;
  3021. if((prog_tb_field_proc_type == 1)||((real_buf_mgr_mode&1)==1)){
  3022. di_buf->vframe->type = VIDTYPE_PROGRESSIVE| VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  3023. if(di_buf->di_buf_dup_p[0]->new_format_flag){
  3024. di_buf->vframe->early_process_fun = de_post_disable_fun;
  3025. }
  3026. else{
  3027. di_buf->vframe->early_process_fun = do_nothing_fun;
  3028. }
  3029. di_buf->vframe->process_fun = de_post_process_prog;
  3030. }
  3031. else if(prog_tb_field_proc_type == 0){
  3032. //do weave by vpp
  3033. di_buf->vframe->type = VIDTYPE_PROGRESSIVE| VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE; // top and bot are in separate buffer, do not set VIDTYPE_VIU_FIELD
  3034. if((di_buf->di_buf_dup_p[0]->new_format_flag)
  3035. ||(READ_MPEG_REG(DI_IF1_GEN_REG)&1)){
  3036. di_buf->vframe->early_process_fun = de_post_disable_fun;
  3037. }
  3038. else{
  3039. di_buf->vframe->early_process_fun = do_nothing_fun;
  3040. }
  3041. di_buf->vframe->process_fun = NULL;
  3042. di_buf->vframe->canvas0Addr = di_buf->di_buf_dup_p[0]->nr_canvas_idx; //top
  3043. di_buf->vframe->canvas1Addr = di_buf->di_buf_dup_p[1]->nr_canvas_idx; //bot
  3044. }
  3045. else{
  3046. di_buf->vframe->type = VIDTYPE_PROGRESSIVE | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
  3047. di_buf->vframe->height >>= 1;
  3048. if((di_buf->di_buf_dup_p[0]->new_format_flag)
  3049. ||(READ_MPEG_REG(DI_IF1_GEN_REG)&1)){
  3050. di_buf->vframe->early_process_fun = de_post_disable_fun;
  3051. }
  3052. else{
  3053. di_buf->vframe->early_process_fun = do_nothing_fun;
  3054. }
  3055. if(prog_tb_field_proc_type == 2){
  3056. di_buf->vframe->canvas0Addr = di_buf->di_buf_dup_p[0]->nr_canvas_idx; //top
  3057. di_buf->vframe->canvas1Addr = di_buf->di_buf_dup_p[0]->nr_canvas_idx;
  3058. }
  3059. else{
  3060. di_buf->vframe->canvas0Addr = di_buf->di_buf_dup_p[1]->nr_canvas_idx; //top
  3061. di_buf->vframe->canvas1Addr = di_buf->di_buf_dup_p[1]->nr_canvas_idx;
  3062. }
  3063. }
  3064. di_buf->di_buf[0] = di_buf->di_buf_dup_p[0];
  3065. di_buf->di_buf[1] = di_buf->di_buf_dup_p[1];
  3066. queue_out(di_buf->di_buf[0]);
  3067. queue_out(di_buf->di_buf[1]);
  3068. raw_local_save_flags(fiq_flag);
  3069. local_fiq_disable();
  3070. if(frame_count<start_frame_drop_count){
  3071. queue_in(di_buf, QUEUE_TMP);
  3072. recycle_vframe_type_post(di_buf);
  3073. #ifdef DI_DEBUG
  3074. recycle_vframe_type_post_print(di_buf, __func__);
  3075. #endif
  3076. }
  3077. else{
  3078. queue_in(di_buf, QUEUE_POST_READY);
  3079. }
  3080. frame_count++;
  3081. raw_local_irq_restore(fiq_flag);
  3082. #ifdef DI_DEBUG
  3083. di_print("%s <prog by field>: ", __func__);
  3084. #endif
  3085. ret = 1;
  3086. }
  3087. }
  3088. #ifdef DI_DEBUG
  3089. if(di_buf){
  3090. di_print("%s[%d](", vframe_type_name[di_buf->type], di_buf->index);
  3091. for(i=0; i< 2; i++){
  3092. if(di_buf->di_buf[i])
  3093. di_print("%s[%d],",vframe_type_name[di_buf->di_buf[i]->type], di_buf->di_buf[i]->index);
  3094. }
  3095. di_print(")(vframe type %x dur %d)", di_buf->vframe->type, di_buf->vframe->duration);
  3096. if(di_buf->di_buf_dup_p[1]&&(di_buf->di_buf_dup_p[1]->post_proc_flag == 3)){
  3097. di_print("=> recycle_list\n");
  3098. }
  3099. else{
  3100. di_print("=> post_ready_list\n");
  3101. }
  3102. }
  3103. #endif
  3104. }
  3105. return ret;
  3106. }
  3107. /*
  3108. di task
  3109. */
  3110. static void di_process(void)
  3111. {
  3112. ulong flags;
  3113. ulong fiq_flag;
  3114. vframe_t * vframe;
  3115. /* add for di Reg re-init */
  3116. //di_set_para_by_tvinfo(vframe);
  3117. if((di_pre_stru.unreg_req_flag||di_pre_stru.force_unreg_req_flag||di_pre_stru.disable_req_flag)&&
  3118. (di_pre_stru.pre_de_busy==0)){
  3119. //printk("===unreg_req_flag\n");
  3120. if(di_pre_stru.force_unreg_req_flag||di_pre_stru.disable_req_flag){
  3121. #ifdef DI_DEBUG
  3122. di_print("%s: force_unreg\n", __func__);
  3123. #endif
  3124. printk("%s: force_unreg\n", __func__);
  3125. if(bypass_state == 0){
  3126. vf_notify_receiver(VFM_NAME,VFRAME_EVENT_PROVIDER_FORCE_BLACKOUT,NULL);
  3127. }
  3128. goto unreg;
  3129. }
  3130. else if(((real_buf_mgr_mode&1)==1)&&(is_bypass()==0)&&(recovery_flag==0)){
  3131. if(init_flag){
  3132. #ifdef DI_DEBUG
  3133. di_print("%s: di_clean_in_buf\n", __func__);
  3134. #endif
  3135. spin_lock_irqsave(&plist_lock, flags);
  3136. raw_local_save_flags(fiq_flag);
  3137. local_fiq_disable();
  3138. di_clean_in_buf();
  3139. raw_local_irq_restore(fiq_flag);
  3140. spin_unlock_irqrestore(&plist_lock, flags);
  3141. }
  3142. }
  3143. else{
  3144. unreg:
  3145. init_flag = 0;
  3146. raw_local_save_flags(fiq_flag);
  3147. local_fiq_disable();
  3148. if(bypass_state == 0){
  3149. DisableVideoLayer();
  3150. }
  3151. vf_unreg_provider(&di_vf_prov);
  3152. raw_local_irq_restore(fiq_flag);
  3153. spin_lock_irqsave(&plist_lock, flags);
  3154. raw_local_save_flags(fiq_flag);
  3155. local_fiq_disable();
  3156. #ifdef DI_DEBUG
  3157. di_print("%s: di_uninit_buf\n", __func__);
  3158. #endif
  3159. di_uninit_buf();
  3160. raw_local_irq_restore(fiq_flag);
  3161. spin_unlock_irqrestore(&plist_lock, flags);
  3162. di_pre_stru.force_unreg_req_flag = 0;
  3163. di_pre_stru.disable_req_flag = 0;
  3164. recovery_flag = 0;
  3165. }
  3166. di_pre_stru.unreg_req_flag = 0;
  3167. }
  3168. if(init_flag == 0){
  3169. #ifdef GET_VFRAME_DIRECTLY
  3170. if (prov && prov->ops && prov->ops->peek)
  3171. vframe = prov->ops->peek(prov->op_arg);
  3172. else
  3173. vframe = NULL;
  3174. #else
  3175. vframe = vf_peek(VFM_NAME);
  3176. #endif
  3177. if(vframe){
  3178. /* add for di Reg re-init */
  3179. #if defined(CONFIG_ARCH_MESON2)
  3180. di_set_para_by_tvinfo(vframe);
  3181. #endif
  3182. if(di_printk_flag&2){
  3183. di_printk_flag=1;
  3184. }
  3185. #ifdef DI_DEBUG
  3186. di_print("%s: vframe come => di_init_buf\n", __func__);
  3187. #endif
  3188. if(is_progressive(vframe)&&is_from_vdin(vframe)&&(prog_proc_config&0x1)&&((real_buf_mgr_mode&1)==0)){
  3189. spin_lock_irqsave(&plist_lock, flags);
  3190. raw_local_save_flags(fiq_flag);
  3191. local_fiq_disable();
  3192. di_init_buf(vframe->width, vframe->height, 1);
  3193. raw_local_irq_restore(fiq_flag);
  3194. spin_unlock_irqrestore(&plist_lock, flags);
  3195. }
  3196. else{
  3197. spin_lock_irqsave(&plist_lock, flags);
  3198. raw_local_save_flags(fiq_flag);
  3199. local_fiq_disable();
  3200. di_init_buf(default_width, default_height, 0);
  3201. raw_local_irq_restore(fiq_flag);
  3202. spin_unlock_irqrestore(&plist_lock, flags);
  3203. }
  3204. vf_provider_init(&di_vf_prov, VFM_NAME, &deinterlace_vf_provider, NULL);
  3205. vf_reg_provider(&di_vf_prov);
  3206. reset_pulldown_state();
  3207. init_flag = 1;
  3208. }
  3209. }
  3210. else{
  3211. #if 1
  3212. //for vdin, need re-init buffers
  3213. if(((real_buf_mgr_mode&1)==1)&&(is_bypass()==0)){
  3214. }
  3215. else{
  3216. #ifdef GET_VFRAME_DIRECTLY
  3217. if (prov && prov->ops && prov->ops->peek)
  3218. vframe = prov->ops->peek(prov->op_arg);
  3219. else
  3220. vframe = NULL;
  3221. #else
  3222. vframe = vf_peek(VFM_NAME);
  3223. #endif
  3224. if(vframe &&
  3225. is_source_change(vframe)
  3226. &&is_from_vdin(vframe)){
  3227. printk("===source_change\n");
  3228. spin_lock_irqsave(&plist_lock, flags);
  3229. raw_local_save_flags(fiq_flag);
  3230. local_fiq_disable();
  3231. vf_unreg_provider(&di_vf_prov);
  3232. #ifdef DI_DEBUG
  3233. di_print("%s: di_uninit_buf 2\n", __func__);
  3234. #endif
  3235. di_uninit_buf();
  3236. if(is_progressive(vframe)&&is_from_vdin(vframe)&&(prog_proc_config&0x1)&&((real_buf_mgr_mode&1)==0)){
  3237. di_init_buf(vframe->width, vframe->height, 1);
  3238. }
  3239. else{
  3240. di_init_buf(default_width, default_height, 0);
  3241. }
  3242. /* add for di Reg re-init */
  3243. //di_set_para_by_tvinfo(vframe);
  3244. vf_reg_provider(&di_vf_prov);
  3245. raw_local_irq_restore(fiq_flag);
  3246. spin_unlock_irqrestore(&plist_lock, flags);
  3247. }
  3248. }
  3249. #endif
  3250. }
  3251. if((init_flag)&&(recovery_flag == 0)){
  3252. spin_lock_irqsave(&plist_lock, flags);
  3253. if(di_pre_stru.pre_de_process_done){
  3254. pre_de_done_buf_config();
  3255. WRITE_MPEG_REG(DI_PRE_CTRL, 0x3 << 30); //disable, and reset
  3256. di_pre_stru.pre_de_process_done = 0;
  3257. #if 1
  3258. //for debug
  3259. if(di_pre_stru.process_count==0){
  3260. if(prog_proc_config&0x10){
  3261. if(prog_proc_config&0x1){
  3262. di_pre_stru.prog_proc_type = 1;
  3263. }
  3264. else{
  3265. di_pre_stru.prog_proc_type = 0;
  3266. }
  3267. prog_proc_config &= (~0x10);
  3268. }
  3269. }
  3270. #endif
  3271. }
  3272. raw_local_save_flags(fiq_flag);
  3273. local_fiq_disable();
  3274. while(check_recycle_buf()&1){};
  3275. raw_local_irq_restore(fiq_flag);
  3276. if((di_pre_stru.pre_de_busy==0) && pre_de_buf_config()){
  3277. pre_de_process();
  3278. }
  3279. while(process_post_vframe()){};
  3280. #ifdef GET_VFRAME_DIRECTLY
  3281. put_get_disp_buf();
  3282. #endif
  3283. spin_unlock_irqrestore(&plist_lock, flags);
  3284. }
  3285. }
  3286. void di_timer_handle(struct work_struct *work)
  3287. {
  3288. if(di_pre_stru.pre_de_busy){
  3289. di_pre_stru.pre_de_busy_timer_count++;
  3290. if(di_pre_stru.pre_de_busy_timer_count>=100){
  3291. di_pre_stru.pre_de_busy_timer_count = 0;
  3292. di_pre_stru.pre_de_busy = 0;
  3293. pr_info("******* DI ********** wait pre_de_irq timeout\n");
  3294. #if defined(CONFIG_ARCH_MESON2)
  3295. set_foreign_affairs(FOREIGN_AFFAIRS_01);
  3296. if(pre_de_irq_check){
  3297. pr_info("DI: Force RESET\n");
  3298. WRITE_MPEG_REG(WATCHDOG_RESET, 0);
  3299. WRITE_MPEG_REG(WATCHDOG_TC,(1<<WATCHDOG_ENABLE_BIT)|(50));
  3300. }
  3301. #endif
  3302. }
  3303. }
  3304. #ifdef RUN_DI_PROCESS_IN_TIMER
  3305. {
  3306. int i;
  3307. for(i=0; i<10; i++){
  3308. if(active_flag){
  3309. di_process();
  3310. }
  3311. }
  3312. }
  3313. #endif
  3314. if(init_flag){
  3315. trigger_pre_di_process('t');
  3316. }
  3317. }
  3318. static int di_task_handle(void *data)
  3319. {
  3320. while (1)
  3321. {
  3322. down_interruptible(&di_sema);
  3323. if(active_flag){
  3324. di_process();
  3325. }
  3326. }
  3327. return 0;
  3328. }
  3329. /*
  3330. provider/receiver interface
  3331. */
  3332. static int di_receiver_event_fun(int type, void* data, void* arg)
  3333. {
  3334. int i;
  3335. ulong flags;
  3336. if(type == VFRAME_EVENT_PROVIDER_UNREG){
  3337. #ifdef DI_DEBUG
  3338. di_print("%s: vf_notify_receiver unreg\n", __func__);
  3339. #endif
  3340. #ifdef GET_VFRAME_DIRECTLY
  3341. spin_lock_irqsave(&plist_lock, flags);
  3342. prov = NULL;
  3343. spin_unlock_irqrestore(&plist_lock, flags);
  3344. #endif
  3345. di_pre_stru.unreg_req_flag = 1;
  3346. provider_vframe_level = 0;
  3347. trigger_pre_di_process('n');
  3348. }
  3349. else if(type == VFRAME_EVENT_PROVIDER_LIGHT_UNREG){
  3350. #ifdef DI_DEBUG
  3351. di_print("%s: vf_notify_receiver ligth unreg\n", __func__);
  3352. #endif
  3353. provider_vframe_level = 0;
  3354. spin_lock_irqsave(&plist_lock, flags);
  3355. for(i=0; i<MAX_IN_BUF_NUM; i++){
  3356. #ifdef DI_DEBUG
  3357. if(vframe_in[i]){
  3358. printk("DI:clear vframe_in[%d]\n", i);
  3359. }
  3360. #endif
  3361. vframe_in[i] = NULL;
  3362. }
  3363. spin_unlock_irqrestore(&plist_lock, flags);
  3364. }
  3365. else if(type == VFRAME_EVENT_PROVIDER_VFRAME_READY){
  3366. #ifdef DI_DEBUG
  3367. di_print("%s: vframe ready\n", __func__);
  3368. #endif
  3369. provider_vframe_level++;
  3370. trigger_pre_di_process('r');
  3371. }
  3372. else if(type == VFRAME_EVENT_PROVIDER_QUREY_STATE){
  3373. int in_buf_num = 0;
  3374. if(recovery_flag){
  3375. return RECEIVER_INACTIVE;
  3376. }
  3377. for(i=0; i<MAX_IN_BUF_NUM; i++){
  3378. if(vframe_in[i]!=NULL){
  3379. in_buf_num++;
  3380. }
  3381. }
  3382. if(bypass_state==1){
  3383. if(in_buf_num>1){
  3384. return RECEIVER_ACTIVE ;
  3385. }else{
  3386. return RECEIVER_INACTIVE;
  3387. }
  3388. }
  3389. else{
  3390. if(in_buf_num>0){
  3391. return RECEIVER_ACTIVE ;
  3392. }else{
  3393. return RECEIVER_INACTIVE;
  3394. }
  3395. }
  3396. }
  3397. else if(type == VFRAME_EVENT_PROVIDER_REG){
  3398. #ifdef GET_VFRAME_DIRECTLY
  3399. prov = vf_get_provider(VFM_NAME);
  3400. #endif
  3401. }
  3402. return 0;
  3403. }
  3404. static vframe_t *di_vf_peek(void* arg)
  3405. {
  3406. vframe_t* vframe_ret = NULL;
  3407. di_buf_t* di_buf = NULL;
  3408. #ifdef GET_VFRAME_DIRECTLY
  3409. return NULL;
  3410. #endif
  3411. if((init_flag == 0)||recovery_flag)
  3412. return NULL;
  3413. if((run_flag == DI_RUN_FLAG_PAUSE)||
  3414. (run_flag == DI_RUN_FLAG_STEP_DONE))
  3415. return NULL;
  3416. if((disp_frame_count==0)&&(is_bypass()==0)){
  3417. int ready_count = list_count(QUEUE_POST_READY);
  3418. if(ready_count>start_frame_hold_count){
  3419. di_buf = get_di_buf_head(QUEUE_POST_READY);
  3420. if(di_buf){
  3421. vframe_ret = di_buf->vframe;
  3422. }
  3423. }
  3424. }
  3425. else{
  3426. if(!queue_empty(QUEUE_POST_READY)){
  3427. di_buf = get_di_buf_head(QUEUE_POST_READY);
  3428. if(di_buf){
  3429. vframe_ret = di_buf->vframe;
  3430. }
  3431. }
  3432. }
  3433. #ifdef DI_DEBUG
  3434. if(vframe_ret){
  3435. di_print("%s: %s[%d]:%x\n", __func__, vframe_type_name[di_buf->type], di_buf->index, vframe_ret);
  3436. }
  3437. #endif
  3438. return vframe_ret;
  3439. }
  3440. static vframe_t *di_vf_get(void* arg)
  3441. {
  3442. vframe_t* vframe_ret = NULL;
  3443. di_buf_t* di_buf = NULL;
  3444. ulong flags;
  3445. #ifdef GET_VFRAME_DIRECTLY
  3446. return NULL;
  3447. #endif
  3448. if((init_flag == 0)||recovery_flag)
  3449. return NULL;
  3450. if((run_flag == DI_RUN_FLAG_PAUSE)||
  3451. (run_flag == DI_RUN_FLAG_STEP_DONE))
  3452. return NULL;
  3453. if((disp_frame_count==0)&&(is_bypass()==0)){
  3454. int ready_count = list_count(QUEUE_POST_READY);
  3455. if(ready_count>start_frame_hold_count){
  3456. goto get_vframe;
  3457. }
  3458. }
  3459. else if (!queue_empty(QUEUE_POST_READY)){
  3460. get_vframe:
  3461. log_buffer_state("get");
  3462. if(receiver_is_amvideo == 0){
  3463. spin_lock_irqsave(&plist_lock, flags);
  3464. }
  3465. di_buf = get_di_buf_head(QUEUE_POST_READY);
  3466. queue_out(di_buf);
  3467. queue_in(di_buf, QUEUE_DISPLAY); //add it into display_list
  3468. if(receiver_is_amvideo == 0){
  3469. spin_unlock_irqrestore(&plist_lock, flags);
  3470. }
  3471. if(di_buf){
  3472. vframe_ret = di_buf->vframe;
  3473. }
  3474. disp_frame_count++;
  3475. if(run_flag == DI_RUN_FLAG_STEP){
  3476. run_flag = DI_RUN_FLAG_STEP_DONE;
  3477. }
  3478. }
  3479. #ifdef DI_DEBUG
  3480. if(vframe_ret){
  3481. di_print("%s: %s[%d]:%x\n", __func__, vframe_type_name[di_buf->type], di_buf->index, vframe_ret);
  3482. }
  3483. #endif
  3484. return vframe_ret;
  3485. }
  3486. static void di_vf_put(vframe_t *vf, void* arg)
  3487. {
  3488. di_buf_t* di_buf = (di_buf_t*)vf->private_data;
  3489. ulong flags;
  3490. #ifdef GET_VFRAME_DIRECTLY
  3491. return;
  3492. #endif
  3493. if((init_flag == 0)||recovery_flag){
  3494. #ifdef DI_DEBUG
  3495. di_print("%s: %x\n", __func__, vf);
  3496. #endif
  3497. return;
  3498. }
  3499. log_buffer_state("put");
  3500. if(di_buf->type == VFRAME_TYPE_POST){
  3501. if(receiver_is_amvideo == 0){
  3502. spin_lock_irqsave(&plist_lock, flags);
  3503. }
  3504. if(is_in_queue(di_buf, QUEUE_DISPLAY)){
  3505. recycle_vframe_type_post(di_buf);
  3506. }
  3507. if(receiver_is_amvideo == 0){
  3508. spin_unlock_irqrestore(&plist_lock, flags);
  3509. }
  3510. #ifdef DI_DEBUG
  3511. recycle_vframe_type_post_print(di_buf, __func__);
  3512. #endif
  3513. }
  3514. else{
  3515. if(receiver_is_amvideo == 0){
  3516. spin_lock_irqsave(&plist_lock, flags);
  3517. }
  3518. queue_in(di_buf, QUEUE_RECYCLE);
  3519. if(receiver_is_amvideo == 0){
  3520. spin_unlock_irqrestore(&plist_lock, flags);
  3521. }
  3522. #ifdef DI_DEBUG
  3523. di_print("%s: %s[%d] =>recycle_list\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
  3524. #endif
  3525. }
  3526. trigger_pre_di_process('p');
  3527. }
  3528. static int di_event_cb(int type, void *data, void *private_data)
  3529. {
  3530. int i;
  3531. if(type == VFRAME_EVENT_RECEIVER_FORCE_UNREG){
  3532. #ifdef DI_DEBUG
  3533. di_print("%s: VFRAME_EVENT_RECEIVER_FORCE_UNREG\n", __func__);
  3534. #endif
  3535. di_pre_stru.force_unreg_req_flag = 1;
  3536. provider_vframe_level = 0;
  3537. trigger_pre_di_process('f');
  3538. while(di_pre_stru.force_unreg_req_flag){
  3539. msleep(1);
  3540. }
  3541. }
  3542. return 0;
  3543. }
  3544. #ifdef GET_VFRAME_DIRECTLY
  3545. extern vframe_t* di_recycle_buffer;
  3546. extern vframe_t* di_vframe_buffer;
  3547. static void put_get_disp_buf(void)
  3548. {
  3549. di_buf_t* di_buf;
  3550. if(di_vframe_buffer == NULL ){
  3551. if (!queue_empty(QUEUE_POST_READY)){
  3552. di_buf = get_di_buf_head(QUEUE_POST_READY);
  3553. if(di_buf){
  3554. queue_out(di_buf);
  3555. queue_in(di_buf, QUEUE_DISPLAY); //add it into display_list
  3556. di_vframe_buffer = di_buf->vframe;
  3557. }
  3558. }
  3559. }
  3560. if(di_recycle_buffer){
  3561. di_buf = (di_buf_t*)(di_recycle_buffer->private_data);
  3562. di_recycle_buffer = NULL;
  3563. if(is_in_queue(di_buf, QUEUE_DISPLAY)){
  3564. recycle_vframe_type_post(di_buf);
  3565. }
  3566. #ifdef DI_DEBUG
  3567. recycle_vframe_type_post_print(di_buf, __func__);
  3568. #endif
  3569. }
  3570. }
  3571. #endif
  3572. /*****************************
  3573. * di driver file_operations
  3574. *
  3575. ******************************/
  3576. static int di_open(struct inode *node, struct file *file)
  3577. {
  3578. di_dev_t *di_in_devp;
  3579. /* Get the per-device structure that contains this cdev */
  3580. di_in_devp = container_of(node->i_cdev, di_dev_t, cdev);
  3581. file->private_data = di_in_devp;
  3582. return 0;
  3583. }
  3584. static int di_release(struct inode *node, struct file *file)
  3585. {
  3586. //di_dev_t *di_in_devp = file->private_data;
  3587. /* Reset file pointer */
  3588. /* Release some other fields */
  3589. /* ... */
  3590. return 0;
  3591. }
  3592. #ifndef CONFIG_ARCH_MESON6
  3593. static int di_ioctl(struct inode *node, struct file *file, unsigned int cmd, unsigned long args)
  3594. {
  3595. int r = 0;
  3596. switch (cmd) {
  3597. default:
  3598. break;
  3599. }
  3600. return r;
  3601. }
  3602. #endif
  3603. const static struct file_operations di_fops = {
  3604. .owner = THIS_MODULE,
  3605. .open = di_open,
  3606. .release = di_release,
  3607. #ifndef CONFIG_ARCH_MESON6
  3608. .ioctl = di_ioctl,
  3609. #endif
  3610. };
  3611. static int di_probe(struct platform_device *pdev)
  3612. {
  3613. int r;
  3614. struct resource *mem;
  3615. int buf_num_avail;
  3616. pr_dbg("di_probe\n");
  3617. r = alloc_chrdev_region(&di_id, 0, DI_COUNT, DEVICE_NAME);
  3618. if (r < 0) {
  3619. pr_error("Can't register major for di device\n");
  3620. return r;
  3621. }
  3622. di_class = class_create(THIS_MODULE, DEVICE_NAME);
  3623. if (IS_ERR(di_class))
  3624. {
  3625. unregister_chrdev_region(di_id, DI_COUNT);
  3626. return -1;
  3627. }
  3628. memset(&di_device, 0, sizeof(di_dev_t));
  3629. cdev_init(&(di_device.cdev), &di_fops);
  3630. di_device.cdev.owner = THIS_MODULE;
  3631. cdev_add(&(di_device.cdev), di_id, DI_COUNT);
  3632. di_device.devt = MKDEV(MAJOR(di_id), 0);
  3633. di_device.dev = device_create(di_class, &pdev->dev, di_device.devt, &di_device, "di%d", 0); //kernel>=2.6.27
  3634. if (di_device.dev == NULL) {
  3635. pr_error("device_create create error\n");
  3636. class_destroy(di_class);
  3637. r = -EEXIST;
  3638. return r;
  3639. }
  3640. device_create_file(di_device.dev, &dev_attr_config);
  3641. device_create_file(di_device.dev, &dev_attr_debug);
  3642. device_create_file(di_device.dev, &dev_attr_log);
  3643. device_create_file(di_device.dev, &dev_attr_parameters);
  3644. device_create_file(di_device.dev, &dev_attr_status);
  3645. if (!(mem = platform_get_resource(pdev, IORESOURCE_MEM, 0)))
  3646. {
  3647. pr_error("\ndeinterlace memory resource undefined.\n");
  3648. return -EFAULT;
  3649. }
  3650. // declare deinterlace memory
  3651. di_print("Deinterlace memory: start = 0x%x, end = 0x%x, size=0x%x\n", mem->start, mem->end, mem->end-mem->start);
  3652. di_mem_start = mem->start;
  3653. di_mem_size = mem->end - mem->start + 1;
  3654. init_flag = 0;
  3655. /* set start_frame_hold_count base on buffer size */
  3656. buf_num_avail = di_mem_size/(default_width*(default_height+8)*5/4);
  3657. if(buf_num_avail > MAX_LOCAL_BUF_NUM){
  3658. buf_num_avail = MAX_LOCAL_BUF_NUM;
  3659. }
  3660. if(buf_num_avail > 6){
  3661. start_frame_hold_count = buf_num_avail-6;
  3662. }
  3663. if(start_frame_hold_count > 4){
  3664. start_frame_hold_count = 4;
  3665. }
  3666. /**/
  3667. vf_receiver_init(&di_vf_recv, VFM_NAME, &di_vf_receiver, NULL);
  3668. vf_reg_receiver(&di_vf_recv);
  3669. active_flag = 1;
  3670. //data32 = (*P_A9_0_IRQ_IN1_INTR_STAT_CLR);
  3671. r = request_irq(INT_DEINTERLACE, &de_irq,
  3672. IRQF_SHARED, "deinterlace",
  3673. (void *)"deinterlace");
  3674. #if defined(CONFIG_ARCH_MESON6)
  3675. Wr(SYS_CPU_0_IRQ_IN1_INTR_MASK, Rd(SYS_CPU_0_IRQ_IN1_INTR_MASK)|(1<<14));
  3676. #else
  3677. Wr(A9_0_IRQ_IN1_INTR_MASK, Rd(A9_0_IRQ_IN1_INTR_MASK)|(1<<14));
  3678. #endif
  3679. #if defined(CONFIG_ARCH_MESON6)
  3680. sema_init(&di_sema,1);
  3681. #else
  3682. init_MUTEX(&di_sema);
  3683. #endif
  3684. di_sema_init_flag=1;
  3685. #ifdef FIQ_VSYNC
  3686. fiq_handle_item.handle=di_vf_put_isr;
  3687. fiq_handle_item.key=(u32)di_vf_put_isr;
  3688. fiq_handle_item.name="di_vf_put_isr";
  3689. if(register_fiq_bridge_handle(&fiq_handle_item)){
  3690. pr_dbg("%s: register_fiq_bridge_handle fail\n", __func__);
  3691. }
  3692. #endif
  3693. reset_di_para();
  3694. di_hw_init();
  3695. /* timer */
  3696. INIT_WORK(&di_pre_work, di_timer_handle);
  3697. init_timer(&di_pre_timer);
  3698. di_pre_timer.data = (ulong) & di_pre_timer;
  3699. di_pre_timer.function = di_pre_timer_cb;
  3700. di_pre_timer.expires = jiffies + DI_PRE_INTERVAL;
  3701. add_timer(&di_pre_timer);
  3702. /**/
  3703. #if (!(defined RUN_DI_PROCESS_IN_IRQ))&&(!(defined RUN_DI_PROCESS_IN_TIMER))
  3704. di_device.task = kthread_run(di_task_handle, &di_device, "kthread_di");
  3705. #endif
  3706. return r;
  3707. }
  3708. static int di_remove(struct platform_device *pdev)
  3709. {
  3710. di_hw_uninit();
  3711. di_device.di_event = 0xff;
  3712. kthread_stop(di_device.task);
  3713. #ifdef FIQ_VSYNC
  3714. unregister_fiq_bridge_handle(&fiq_handle_item);
  3715. #endif
  3716. vf_unreg_provider(&di_vf_prov);
  3717. vf_unreg_receiver(&di_vf_recv);
  3718. di_uninit_buf();
  3719. /* Remove the cdev */
  3720. device_remove_file(di_device.dev, &dev_attr_config);
  3721. device_remove_file(di_device.dev, &dev_attr_debug);
  3722. device_remove_file(di_device.dev, &dev_attr_log);
  3723. device_remove_file(di_device.dev, &dev_attr_parameters);
  3724. device_remove_file(di_device.dev, &dev_attr_status);
  3725. cdev_del(&di_device.cdev);
  3726. device_destroy(di_class, di_id);
  3727. class_destroy(di_class);
  3728. unregister_chrdev_region(di_id, DI_COUNT);
  3729. return 0;
  3730. }
  3731. static struct platform_driver di_driver = {
  3732. .probe = di_probe,
  3733. .remove = di_remove,
  3734. .driver = {
  3735. .name = DEVICE_NAME,
  3736. .owner = THIS_MODULE,
  3737. }
  3738. };
  3739. static struct platform_device* deinterlace_device = NULL;
  3740. static int __init di_init(void)
  3741. {
  3742. if(boot_init_flag&INIT_FLAG_NOT_LOAD)
  3743. return 0;
  3744. pr_dbg("di_init\n");
  3745. #if 0
  3746. deinterlace_device = platform_device_alloc(DEVICE_NAME,0);
  3747. if (!deinterlace_device) {
  3748. pr_error("failed to alloc deinterlace_device\n");
  3749. return -ENOMEM;
  3750. }
  3751. if(platform_device_add(deinterlace_device)){
  3752. platform_device_put(deinterlace_device);
  3753. pr_error("failed to add deinterlace_device\n");
  3754. return -ENODEV;
  3755. }
  3756. if (platform_driver_register(&di_driver)) {
  3757. pr_error("failed to register di module\n");
  3758. platform_device_del(deinterlace_device);
  3759. platform_device_put(deinterlace_device);
  3760. return -ENODEV;
  3761. }
  3762. #else
  3763. if (platform_driver_register(&di_driver)) {
  3764. di_print("failed to register di module\n");
  3765. return -ENODEV;
  3766. }
  3767. #endif
  3768. return 0;
  3769. }
  3770. static void __exit di_exit(void)
  3771. {
  3772. pr_dbg("di_exit\n");
  3773. platform_driver_unregister(&di_driver);
  3774. platform_device_unregister(deinterlace_device);
  3775. deinterlace_device = NULL;
  3776. return ;
  3777. }
  3778. MODULE_PARM_DESC(bypass_hd, "\n bypass_hd \n");
  3779. module_param(bypass_hd, int, 0664);
  3780. MODULE_PARM_DESC(bypass_prog, "\n bypass_prog \n");
  3781. module_param(bypass_prog, int, 0664);
  3782. MODULE_PARM_DESC(bypass_all, "\n bypass_all \n");
  3783. module_param(bypass_all, int, 0664);
  3784. MODULE_PARM_DESC(bypass_vscale_skip, "\n bypass_vscale_skip \n");
  3785. module_param(bypass_vscale_skip, int, 0664);
  3786. MODULE_PARM_DESC(bypass_get_buf_threshold, "\n bypass_get_buf_threshold\n");
  3787. module_param(bypass_get_buf_threshold, uint, 0664);
  3788. MODULE_PARM_DESC(pulldown_detect, "\n pulldown_detect \n");
  3789. module_param(pulldown_detect, int, 0664);
  3790. MODULE_PARM_DESC(prog_proc_config, "\n prog_proc_config \n");
  3791. module_param(prog_proc_config, int, 0664);
  3792. MODULE_PARM_DESC(skip_wrong_field, "\n skip_wrong_field \n");
  3793. module_param(skip_wrong_field, int, 0664);
  3794. MODULE_PARM_DESC(frame_count, "\n frame_count \n");
  3795. module_param(frame_count, int, 0664);
  3796. MODULE_PARM_DESC(start_frame_drop_count, "\n start_frame_drop_count \n");
  3797. module_param(start_frame_drop_count, int, 0664);
  3798. MODULE_PARM_DESC(start_frame_hold_count, "\n start_frame_hold_count \n");
  3799. module_param(start_frame_hold_count, int, 0664);
  3800. module_init(di_init);
  3801. module_exit(di_exit);
  3802. MODULE_PARM_DESC(same_w_r_canvas_count, "\n canvas of write and read are same \n");
  3803. module_param(same_w_r_canvas_count, long, 0664);
  3804. MODULE_PARM_DESC(same_field_top_count, "\n same top field \n");
  3805. module_param(same_field_top_count, long, 0664);
  3806. MODULE_PARM_DESC(same_field_bot_count, "\n same bottom field \n");
  3807. module_param(same_field_bot_count, long, 0664);
  3808. MODULE_PARM_DESC(same_field_source_flag_th, "\n same_field_source_flag_th \n");
  3809. module_param(same_field_source_flag_th, int, 0664);
  3810. MODULE_PARM_DESC(pulldown_count, "\n pulldown_count \n");
  3811. module_param(pulldown_count, long, 0664);
  3812. MODULE_PARM_DESC(pulldown_buffer_mode, "\n pulldown_buffer_mode \n");
  3813. module_param(pulldown_buffer_mode, long, 0664);
  3814. MODULE_PARM_DESC(pulldown_win_mode, "\n pulldown_win_mode \n");
  3815. module_param(pulldown_win_mode, long, 0664);
  3816. MODULE_PARM_DESC(frame_packing_mode, "\n frame_packing_mode \n");
  3817. module_param(frame_packing_mode, int, 0664);
  3818. MODULE_PARM_DESC(di_log_flag, "\n di log flag \n");
  3819. module_param(di_log_flag, int, 0664);
  3820. MODULE_PARM_DESC(buf_state_log_threshold, "\n buf_state_log_threshold \n");
  3821. module_param(buf_state_log_threshold, int, 0664);
  3822. MODULE_PARM_DESC(buf_mgr_mode, "\n buf_mgr_mode\n");
  3823. module_param(buf_mgr_mode, uint, 0664);
  3824. MODULE_PARM_DESC(buf_mgr_mode_mask, "\n buf_mgr_mode_mask\n");
  3825. module_param(buf_mgr_mode_mask, uint, 0664);
  3826. MODULE_PARM_DESC(pre_de_irq_check, "\n pre_de_irq_check\n");
  3827. module_param(pre_de_irq_check, uint, 0664);
  3828. MODULE_PARM_DESC(bypass_state, "\n bypass_state\n");
  3829. module_param(bypass_state, uint, 0664);
  3830. MODULE_PARM_DESC(force_bob_flag, "\n force_bob_flag\n");
  3831. module_param(force_bob_flag, uint, 0664);
  3832. MODULE_PARM_DESC(di_vscale_skip_count, "\n di_vscale_skip_count\n");
  3833. module_param(di_vscale_skip_count, uint, 0664);
  3834. MODULE_PARM_DESC(version, "\n version\n");
  3835. module_param(version, uint, 0664);
  3836. MODULE_DESCRIPTION("AMLOGIC HDMI TX driver");
  3837. MODULE_LICENSE("GPL");
  3838. MODULE_VERSION("1.0.0");
  3839. static char* next_token_ex(char* seperator, char *buf, unsigned size, unsigned offset, unsigned *token_len, unsigned *token_offset)
  3840. { /* besides characters defined in seperator, '\"' are used as seperator; and any characters in '\"' will not act as seperator */
  3841. char *pToken = NULL;
  3842. char last_seperator = 0;
  3843. char trans_char_flag = 0;
  3844. if(buf){
  3845. for (;offset<size;offset++){
  3846. int ii=0;
  3847. char ch;
  3848. if (buf[offset] == '\\'){
  3849. trans_char_flag = 1;
  3850. continue;
  3851. }
  3852. while(((ch=seperator[ii++])!=buf[offset])&&(ch)){
  3853. }
  3854. if (ch){
  3855. if (!pToken){
  3856. continue;
  3857. }
  3858. else {
  3859. if (last_seperator != '"'){
  3860. *token_len = (unsigned)(buf + offset - pToken);
  3861. *token_offset = offset;
  3862. return pToken;
  3863. }
  3864. }
  3865. }
  3866. else if (!pToken)
  3867. {
  3868. if (trans_char_flag&&(buf[offset] == '"'))
  3869. last_seperator = buf[offset];
  3870. pToken = &buf[offset];
  3871. }
  3872. else if ((trans_char_flag&&(buf[offset] == '"'))&&(last_seperator == '"')){
  3873. *token_len = (unsigned)(buf + offset - pToken - 2);
  3874. *token_offset = offset + 1;
  3875. return pToken + 1;
  3876. }
  3877. trans_char_flag = 0;
  3878. }
  3879. if (pToken) {
  3880. *token_len = (unsigned)(buf + offset - pToken);
  3881. *token_offset = offset;
  3882. }
  3883. }
  3884. return pToken;
  3885. }
  3886. static int __init di_boot_para_setup(char *s)
  3887. {
  3888. char separator[]={' ',',',';',0x0};
  3889. char *token;
  3890. unsigned token_len, token_offset, offset=0;
  3891. int size=strlen(s);
  3892. do{
  3893. token=next_token_ex(separator, s, size, offset, &token_len, &token_offset);
  3894. if(token){
  3895. if((token_len==3) && (strncmp(token, "off", token_len)==0)){
  3896. boot_init_flag|=INIT_FLAG_NOT_LOAD;
  3897. }
  3898. }
  3899. offset=token_offset;
  3900. }while(token);
  3901. return 0;
  3902. }
  3903. __setup("di=",di_boot_para_setup);
  3904. vframe_t* get_di_inp_vframe(void)
  3905. {
  3906. vframe_t* vframe = NULL;
  3907. if(di_pre_stru.di_inp_buf){
  3908. vframe = di_pre_stru.di_inp_buf->vframe;
  3909. }
  3910. return vframe;
  3911. }