1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348 |
- /*
- * Amlogic M2
- * frame buffer driver-----------Deinterlace
- * Copyright (C) 2010 Amlogic, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the named License,
- * or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
- #include <linux/version.h>
- #include <linux/module.h>
- #include <linux/types.h>
- #include <linux/kernel.h>
- #include <linux/kthread.h>
- #include <linux/semaphore.h>
- #include <linux/workqueue.h>
- #include <linux/spinlock.h>
- #include <linux/delay.h>
- #include <linux/interrupt.h>
- #include <linux/fs.h>
- #include <linux/init.h>
- #include <linux/device.h>
- #include <linux/mm.h>
- #include <linux/major.h>
- #include <linux/platform_device.h>
- #include <linux/mutex.h>
- #include <linux/cdev.h>
- #include <linux/proc_fs.h>
- #include <linux/list.h>
- //#include <linux/aml_common.h>
- #include <asm/uaccess.h>
- #include <mach/am_regs.h>
- #include <linux/osd/osd_dev.h>
- #include <linux/amports/vframe.h>
- #include <linux/amports/vframe_provider.h>
- #include <linux/amports/vframe_receiver.h>
- #include <linux/amports/canvas.h>
- //#include <linux/fiq_bridge.h>
- #include "deinterlace.h"
- #include "deinterlace_module.h"
- #if defined(CONFIG_ARCH_MESON2)
- #define FORCE_BOB_SUPPORT
- #endif
- //#define RUN_DI_PROCESS_IN_IRQ
- //#define RUN_DI_PROCESS_IN_TIMER
- //#define GET_VFRAME_DIRECTLY
- #undef USE_LIST
- #ifdef GET_VFRAME_DIRECTLY
- #define raw_local_save_flags(fiq_flag)
- #define local_fiq_disable()
- #define raw_local_irq_restore(fiq_flag)
- static struct vframe_provider_s * prov = NULL;
- #endif
- #if defined(CONFIG_ARCH_MESON6)
- #undef FIQ_VSYNC
- #define raw_local_save_flags(fiq_flag)
- #define local_fiq_disable()
- #define raw_local_irq_restore(fiq_flag)
- #else
- #define FIQ_VSYNC
- #endif
- #define CHECK_VDIN_BUF_ERROR
- #define DEVICE_NAME "deinterlace"
- #ifdef DEBUG
- #define pr_dbg(fmt, args...) printk(KERN_DEBUG "DI: " fmt, ## args)
- #else
- #define pr_dbg(fmt, args...)
- #endif
- #define pr_error(fmt, args...) printk(KERN_ERR "DI: " fmt, ## args)
- #define Wr(adr, val) WRITE_MPEG_REG(adr, val)
- #define Rd(adr) READ_MPEG_REG(adr)
- extern void timestamp_pcrscr_enable(u32 enable);
- static DEFINE_SPINLOCK(plist_lock);
- static di_dev_t di_device;
- static dev_t di_id;
- static struct class *di_class;
- #define INIT_FLAG_NOT_LOAD 0x80
- static int version = 5;
- static unsigned char boot_init_flag=0;
- static int receiver_is_amvideo = 1;
- static int buf_mgr_mode = 0;
- static int buf_mgr_mode_mask = 0xf;
- static int bypass_state = 0;
- static int bypass_prog = 0;
- static int bypass_hd = 0;
- static int bypass_all = 0;
- static int bypass_vscale_skip = 0;
- static int bypass_get_buf_threshold = 4;
- /* prog_proc_config,
- 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"
- 0 "prog vdin" use two field buffers, 1 "prog vdin" use single frame buffer
- bit[2:1]: when two field buffers are used, 0 use vpp for blending ,
- 1 use post_di module for blending
- 2 debug mode, bob with top field
- 3 debug mode, bot with bot field
- */
- static int prog_proc_config = (1<<1)|1; /*
- for source include both progressive and interlace pictures,
- always use post_di module for blending
- */
- static int pulldown_detect = 0x10;
- static int skip_wrong_field = 1;
- static int frame_count = 0;
- static int provider_vframe_level = 0;
- static int frame_packing_mode = 1;
- static int disp_frame_count = 0;
- static int start_frame_drop_count = 0;
- static int start_frame_hold_count = 0;
- static int pre_de_irq_check = 0;
- static int force_bob_flag = 0;
- int di_vscale_skip_count = 0;
- static uint init_flag=0;
- static unsigned char active_flag=0;
- static unsigned char recovery_flag=0;
- #define VFM_NAME "deinterlace"
- static long same_field_top_count = 0;
- static long same_field_bot_count = 0;
- static long same_w_r_canvas_count = 0;
- static long pulldown_count = 0;
- static long pulldown_buffer_mode = 1; /* bit 0:
- 0, keep 3 buffers in pre_ready_list for checking;
- 1, keep 4 buffers in pre_ready_list for checking;
- */
- static long pulldown_win_mode = 0x11111;
- static int same_field_source_flag_th = 60;
- int nr_hfilt_en = 0;
- #define real_buf_mgr_mode (((buf_mgr_mode|(get_blackout_policy()==0))&buf_mgr_mode_mask)|(buf_mgr_mode_mask>>16))
- #define DisableVideoLayer() \
- do { CLEAR_MPEG_REG_MASK(VPP_MISC, \
- VPP_VD1_PREBLEND|VPP_VD2_PREBLEND|VPP_VD2_POSTBLEND|VPP_VD1_POSTBLEND ); \
- } while (0)
- static int di_receiver_event_fun(int type, void* data, void* arg);
- static void di_uninit_buf(void);
- static unsigned char is_bypass(void);
- static void log_buffer_state(unsigned char* tag);
- u32 get_blackout_policy(void);
- static void put_get_disp_buf(void);
- static const struct vframe_receiver_op_s di_vf_receiver =
- {
- .event_cb = di_receiver_event_fun
- };
- static struct vframe_receiver_s di_vf_recv;
- static vframe_t *di_vf_peek(void* arg);
- static vframe_t *di_vf_get(void* arg);
- static void di_vf_put(vframe_t *vf, void* arg);
- static int di_event_cb(int type, void *data, void *private_data);
- static void di_process(void);
- static int get_current_vscale_skip_count(void);
- static const struct vframe_operations_s deinterlace_vf_provider =
- {
- .peek = di_vf_peek,
- .get = di_vf_get,
- .put = di_vf_put,
- .event_cb = di_event_cb,
- };
- static struct vframe_provider_s di_vf_prov;
- int di_sema_init_flag = 0;
- static struct semaphore di_sema;
- #ifdef FIQ_VSYNC
- static bridge_item_t fiq_handle_item;
- static irqreturn_t di_vf_put_isr(int irq, void *dev_id)
- {
- #ifdef RUN_DI_PROCESS_IN_IRQ
- int i;
- for(i=0; i<2; i++){
- if(active_flag){
- di_process();
- }
- }
- #else
- up(&di_sema);
- #endif
- return IRQ_HANDLED;
- }
- #endif
- void trigger_pre_di_process(char idx)
- {
- if(di_sema_init_flag == 0)
- return ;
- if(idx!='p')
- {
- log_buffer_state((idx=='i')?"irq":((idx=='p')?"put":((idx=='r')?"rdy":"oth")));
- }
- #ifndef RUN_DI_PROCESS_IN_TIMER
- #ifdef RUN_DI_PROCESS_IN_IRQ
- fiq_bridge_pulse_trigger(&fiq_handle_item);
- #else
- #ifdef FIQ_VSYNC
- if(idx == 'p'){
- fiq_bridge_pulse_trigger(&fiq_handle_item);
- }
- else
- #endif
- {
- up(&di_sema);
- }
- #endif
- #endif
- }
- #define DI_PRE_INTERVAL (HZ/100)
- static struct timer_list di_pre_timer;
- static struct work_struct di_pre_work;
- static void di_pre_timer_cb(unsigned long arg)
- {
- struct timer_list *timer = (struct timer_list *)arg;
- schedule_work(&di_pre_work);
- timer->expires = jiffies + DI_PRE_INTERVAL;
- add_timer(timer);
- }
- /*****************************
- * di attr management :
- * enable
- * mode
- * reg
- ******************************/
- /*config attr*/
- static ssize_t show_config(struct device * dev, struct device_attribute *attr, char * buf)
- {
- int pos=0;
- return pos;
- }
- static ssize_t store_config(struct device * dev, struct device_attribute *attr, const char * buf, size_t count);
- static void dump_state(void);
- static void force_source_change(void);
- #define DI_RUN_FLAG_RUN 0
- #define DI_RUN_FLAG_PAUSE 1
- #define DI_RUN_FLAG_STEP 2
- #define DI_RUN_FLAG_STEP_DONE 3
- static int run_flag = DI_RUN_FLAG_RUN;
- static ssize_t store_dbg(struct device * dev, struct device_attribute *attr, const char * buf, size_t count)
- {
- if(strncmp(buf, "state", 4)==0){
- dump_state();
- }
- else if(strncmp(buf,"bypass_prog", 11)==0){
- force_source_change();
- if(buf[11]=='1'){
- bypass_prog = 1;
- }
- else{
- bypass_prog = 0;
- }
- }
- else if(strncmp(buf, "prog_proc_config", 16)==0){
- if(buf[16]=='1'){
- prog_proc_config = 1;
- }
- else{
- prog_proc_config = 0;
- }
- }
- else if(strncmp(buf, "time_div", 8)==0){
- }
- else if(strncmp(buf, "show_osd", 8)==0){
- Wr(VIU_OSD1_CTRL_STAT, Rd(VIU_OSD1_CTRL_STAT)|(0xff<<12));
- }
- else if(strncmp(buf, "run", 3)==0){
- //timestamp_pcrscr_enable(1);
- run_flag = DI_RUN_FLAG_RUN;
- }
- else if(strncmp(buf, "pause", 5)==0){
- //timestamp_pcrscr_enable(0);
- run_flag = DI_RUN_FLAG_PAUSE;
- }
- else if(strncmp(buf, "step", 4)==0){
- run_flag = DI_RUN_FLAG_STEP;
- }
- else if(strncmp(buf, "dumptsync", 9) == 0){
- }
- else if(strncmp(buf, "robust_test", 11) == 0){
-
- }
- return count;
- }
- static unsigned char* di_log_buf=NULL;
- static unsigned int di_log_wr_pos=0;
- static unsigned int di_log_rd_pos=0;
- static unsigned int di_log_buf_size=0;
- static unsigned int di_printk_flag=0;
- unsigned int di_log_flag=0;
- unsigned int buf_state_log_threshold = 16;
- unsigned int buf_state_log_start = 0; /* set to 1 by condition of "post_ready count < buf_state_log_threshold",
- reset to 0 by set buf_state_log_threshold as 0 */
- static DEFINE_SPINLOCK(di_print_lock);
- #define PRINT_TEMP_BUF_SIZE 128
- int di_print_buf(char* buf, int len)
- {
- unsigned long flags;
- int pos;
- int di_log_rd_pos_;
- if(di_log_buf_size==0)
- return 0;
- spin_lock_irqsave(&di_print_lock, flags);
- di_log_rd_pos_=di_log_rd_pos;
- if(di_log_wr_pos>=di_log_rd_pos)
- di_log_rd_pos_+=di_log_buf_size;
- for(pos=0;pos<len && di_log_wr_pos<(di_log_rd_pos_-1);pos++,di_log_wr_pos++){
- if(di_log_wr_pos>=di_log_buf_size)
- di_log_buf[di_log_wr_pos-di_log_buf_size]=buf[pos];
- else
- di_log_buf[di_log_wr_pos]=buf[pos];
- }
- if(di_log_wr_pos>=di_log_buf_size)
- di_log_wr_pos-=di_log_buf_size;
- spin_unlock_irqrestore(&di_print_lock, flags);
- return pos;
- }
- //static int log_seq = 0;
- #if 0
- #define di_print printk
- #else
- int di_print(const char *fmt, ...)
- {
- va_list args;
- int avail = PRINT_TEMP_BUF_SIZE;
- char buf[PRINT_TEMP_BUF_SIZE];
- int pos,len=0;
- if(di_printk_flag&1){
- va_start(args, fmt);
- vprintk(fmt, args);
- va_end(args);
- return 0;
- }
- if(di_log_buf_size==0)
- return 0;
- //len += snprintf(buf+len, avail-len, "%d:",log_seq++);
- if(di_log_flag&DI_LOG_TIMESTAMP){
- len += snprintf(buf+len, avail-len, "%u:", (unsigned int)jiffies);
- }
- else if(di_log_flag&DI_LOG_PRECISE_TIMESTAMP){
- #ifndef CONFIG_ARCH_MESON6
- if(READ_MPEG_REG(ISA_TIMERB)==0){
- WRITE_MPEG_REG(ISA_TIMER_MUX, (READ_MPEG_REG(ISA_TIMER_MUX)&(~(3<<TIMER_B_INPUT_BIT)))
- |(TIMER_UNIT_100us<<TIMER_B_INPUT_BIT)|(1<<13)|(1<<17));
- WRITE_MPEG_REG(ISA_TIMERB, 0xffff);
- printk("Deinterlace: Init 100us TimerB\n");
- }
- len += snprintf(buf+len, avail-len, "%u:", (unsigned int)(0x10000-READ_MPEG_REG(ISA_TIMERB)));
- #endif
- }
- va_start(args, fmt);
- len += vsnprintf(buf+len, avail-len, fmt, args);
- va_end(args);
- if ((avail-len) <= 0) {
- buf[PRINT_TEMP_BUF_SIZE - 1] = '\0';
- }
- pos = di_print_buf(buf, len);
- //printk("di_print:%d %d\n", di_log_wr_pos, di_log_rd_pos);
- return pos;
- }
- #endif
- static ssize_t read_log(char * buf)
- {
- unsigned long flags;
- ssize_t read_size=0;
- if(di_log_buf_size==0)
- return 0;
- //printk("show_log:%d %d\n", di_log_wr_pos, di_log_rd_pos);
- spin_lock_irqsave(&di_print_lock, flags);
- if(di_log_rd_pos<di_log_wr_pos){
- read_size = di_log_wr_pos-di_log_rd_pos;
- }
- else if(di_log_rd_pos>di_log_wr_pos){
- read_size = di_log_buf_size-di_log_rd_pos;
- }
- if(read_size>PAGE_SIZE)
- read_size=PAGE_SIZE;
- if(read_size>0)
- memcpy(buf, di_log_buf+di_log_rd_pos, read_size);
- di_log_rd_pos += read_size;
- if(di_log_rd_pos>=di_log_buf_size)
- di_log_rd_pos = 0;
- spin_unlock_irqrestore(&di_print_lock, flags);
- return read_size;
- }
- static ssize_t show_log(struct device * dev, struct device_attribute *attr, char * buf)
- {
- return read_log(buf);
- }
- #ifdef DI_DEBUG
- char log_tmp_buf[PAGE_SIZE];
- static void dump_log(void)
- {
- while(read_log(log_tmp_buf)>0){
- printk("%s", log_tmp_buf);
- }
- }
- #endif
- static ssize_t store_log(struct device * dev, struct device_attribute *attr, const char * buf, size_t count)
- {
- int tmp;
- unsigned long flags;
- if(strncmp(buf, "bufsize", 7)==0){
- tmp = simple_strtoul(buf+7,NULL,10);
- spin_lock_irqsave(&di_print_lock, flags);
- if(di_log_buf){
- kfree(di_log_buf);
- di_log_buf=NULL;
- di_log_buf_size=0;
- di_log_rd_pos=0;
- di_log_wr_pos=0;
- }
- if(tmp>=1024){
- di_log_buf_size=0;
- di_log_rd_pos=0;
- di_log_wr_pos=0;
- di_log_buf=kmalloc(tmp, GFP_KERNEL);
- if(di_log_buf){
- di_log_buf_size=tmp;
- }
- }
- spin_unlock_irqrestore(&di_print_lock, flags);
- printk("di_store:set bufsize tmp %d %d\n",tmp, di_log_buf_size);
- }
- else if(strncmp(buf, "printk", 6)==0){
- di_printk_flag = simple_strtoul(buf+6, NULL, 10);
- }
- else{
- di_print(0, "%s", buf);
- }
- return 16;
- }
- static int set_noise_reduction_level(void)
- {
- int nr_zone_0 = 4, nr_zone_1 = 8, nr_zone_2 = 12;
- //int nr_hfilt_en = 0;
- int nr_hfilt_mb_en = 0;
- /* int post_mb_en = 0;
- int blend_mtn_filt_en = 1;
- int blend_data_filt_en = 1;
- */
- unsigned int nr_strength = 0, nr_gain2 = 0, nr_gain1 = 0, nr_gain0 = 0;
- nr_strength = noise_reduction_level;
- if (nr_strength > 64)
- nr_strength = 64;
- nr_gain2 = 64 - nr_strength;
- nr_gain1 = nr_gain2 - ((nr_gain2 * nr_strength + 32) >> 6);
- nr_gain0 = nr_gain1 - ((nr_gain1 * nr_strength + 32) >> 6);
- nr_ctrl1 = (64 << 24) | (nr_gain2 << 16) | (nr_gain1 << 8) | (nr_gain0 << 0);
- nr_ctrl0 = (1 << 31 ) | // nr yuv enable.
- (1 << 30 ) | // nr range. 3 point
- (0 << 29 ) | // max of 3 point.
- (nr_hfilt_en << 28 ) | // nr hfilter enable.
- (nr_hfilt_mb_en << 27 ) | // nr hfilter motion_blur enable.
- (nr_zone_2 <<16 ) | // zone 2
- (nr_zone_1 << 8 ) | // zone 1
- (nr_zone_0 << 0 ) ; // zone 0
- // blend_ctrl = ( post_mb_en << 28 ) | // post motion blur enable.
- // ( 0 << 27 ) | // mtn3p(l, c, r) max.
- // ( 0 << 26 ) | // mtn3p(l, c, r) min.
- // ( 0 << 25 ) | // mtn3p(l, c, r) ave.
- // ( 1 << 24 ) | // mtntopbot max
- // ( blend_mtn_filt_en << 23 ) | // blend mtn filter enable.
- // ( blend_data_filt_en << 22 ) | // blend data filter enable.
- // kdeint0; // kdeint.
- return 0;
- }
- typedef struct{
- char* name;
- uint* param;
- int (*proc_fun)(void);
- }di_param_t;
- unsigned long reg_mtn_info[7];
- di_param_t di_params[]=
- {
- {"ei_ctrl0", &ei_ctrl0, NULL },
- {"ei_ctrl1", &ei_ctrl1, NULL },
- {"ei_ctrl2", &ei_ctrl2, NULL },
- {"nr_ctrl0", &nr_ctrl0, NULL },
- {"nr_ctrl1", &nr_ctrl1, NULL },
- {"nr_ctrl2", &nr_ctrl2, NULL },
- {"nr_ctrl3", &nr_ctrl3, NULL },
- {"mtn_ctrl_char_diff_cnt", &mtn_ctrl_char_diff_cnt, NULL },
- {"mtn_ctrl_low_level", &mtn_ctrl_low_level, NULL },
- {"mtn_ctrl_high_level", &mtn_ctrl_high_level, NULL },
- {"mtn_ctrl", &mtn_ctrl, NULL},
- {"mtn_ctrl_diff_level", &mtn_ctrl_diff_level, NULL },
- {"mtn_ctrl1_reduce", &mtn_ctrl1_reduce, NULL },
- {"mtn_ctrl1_shift", &mtn_ctrl1_shift, NULL },
- {"mtn_ctrl1", &mtn_ctrl1, NULL},
- {"blend_ctrl", &blend_ctrl, NULL },
- {"kdeint0", &kdeint0, NULL },
- {"kdeint1", &kdeint1, NULL },
- {"kdeint2", &kdeint2, NULL },
- {"blend_ctrl1", &blend_ctrl1, NULL },
- {"blend_ctrl1_char_level", &blend_ctrl1_char_level, NULL},
- {"blend_ctrl1_angle_thd", &blend_ctrl1_angle_thd, NULL},
- {"blend_ctrl1_filt_thd", &blend_ctrl1_filt_thd, NULL},
- {"blend_ctrl1_diff_thd", &blend_ctrl1_diff_thd, NULL},
- {"blend_ctrl2", &blend_ctrl2, NULL },
- {"blend_ctrl2_black_level", &blend_ctrl2_black_level, NULL},
- {"blend_ctrl2_mtn_no_mov", &blend_ctrl2_mtn_no_mov, NULL},
- {"mtn_thre_1_low",&mtn_thre_1_low,NULL},
- {"mtn_thre_1_high",&mtn_thre_1_high,NULL},
- {"mtn_thre_2_low",&mtn_thre_2_low,NULL},
- {"mtn_thre_2_high",&mtn_thre_2_high,NULL},
- {"mtn_info0",((uint*)®_mtn_info[0]) ,NULL},
- {"mtn_info1",((uint*)®_mtn_info[1]) ,NULL},
- {"mtn_info2",((uint*)®_mtn_info[2]) ,NULL},
- {"mtn_info3",((uint*)®_mtn_info[3]) ,NULL},
- {"mtn_info4",((uint*)®_mtn_info[4]) ,NULL},
- {"mtn_info5",((uint*)®_mtn_info[5]) ,NULL},
- {"mtn_info6",((uint*)®_mtn_info[6]) ,NULL},
- {"post_ctrl__di_blend_en", &post_ctrl__di_blend_en, NULL},
- {"post_ctrl__di_post_repeat", &post_ctrl__di_post_repeat, NULL},
- {"di_pre_ctrl__di_pre_repeat", &di_pre_ctrl__di_pre_repeat, NULL},
- {"noise_reduction_level", &noise_reduction_level, set_noise_reduction_level},
- {"field_32lvl", &field_32lvl, NULL},
- {"field_22lvl", &field_22lvl, NULL},
- {"field_pd_frame_diff_chg_th", &(field_pd_th.frame_diff_chg_th), NULL},
- {"field_pd_frame_diff_num_chg_th", &(field_pd_th.frame_diff_num_chg_th), NULL},
- {"field_pd_field_diff_chg_th", &(field_pd_th.field_diff_chg_th), NULL},
- {"field_pd_field_diff_num_chg_th", &(field_pd_th.field_diff_num_chg_th), NULL},
- {"field_pd_frame_diff_skew_th", &(field_pd_th.frame_diff_skew_th), NULL},
- {"field_pd_frame_diff_num_skew_th", &(field_pd_th.frame_diff_num_skew_th), NULL},
- {"win0_start_x_r", &pd_win_prop[0].win_start_x_r, NULL},
- {"win0_end_x_r", &pd_win_prop[0].win_end_x_r, NULL},
- {"win0_start_y_r", &pd_win_prop[0].win_start_y_r, NULL},
- {"win0_end_y_r", &pd_win_prop[0].win_end_y_r, NULL},
- {"win0_32lvl", &pd_win_prop[0].win_32lvl, NULL},
- {"win0_22lvl", &pd_win_prop[0].win_22lvl, NULL},
- {"win0_pd_frame_diff_chg_th", &(win_pd_th[0].frame_diff_chg_th), NULL},
- {"win0_pd_frame_diff_num_chg_th", &(win_pd_th[0].frame_diff_num_chg_th), NULL},
- {"win0_pd_field_diff_chg_th", &(win_pd_th[0].field_diff_chg_th), NULL},
- {"win0_pd_field_diff_num_chg_th", &(win_pd_th[0].field_diff_num_chg_th), NULL},
- {"win0_pd_frame_diff_skew_th", &(win_pd_th[0].frame_diff_skew_th), NULL},
- {"win0_pd_frame_diff_num_skew_th", &(win_pd_th[0].frame_diff_num_skew_th), NULL},
- {"win0_pd_field_diff_num_th", &(win_pd_th[0].field_diff_num_th), NULL},
- {"win1_start_x_r", &pd_win_prop[1].win_start_x_r, NULL},
- {"win1_end_x_r", &pd_win_prop[1].win_end_x_r, NULL},
- {"win1_start_y_r", &pd_win_prop[1].win_start_y_r, NULL},
- {"win1_end_y_r", &pd_win_prop[1].win_end_y_r, NULL},
- {"win1_32lvl", &pd_win_prop[1].win_32lvl, NULL},
- {"win1_22lvl", &pd_win_prop[1].win_22lvl, NULL},
- {"win1_pd_frame_diff_chg_th", &(win_pd_th[1].frame_diff_chg_th), NULL},
- {"win1_pd_frame_diff_num_chg_th", &(win_pd_th[1].frame_diff_num_chg_th), NULL},
- {"win1_pd_field_diff_chg_th", &(win_pd_th[1].field_diff_chg_th), NULL},
- {"win1_pd_field_diff_num_chg_th", &(win_pd_th[1].field_diff_num_chg_th), NULL},
- {"win1_pd_frame_diff_skew_th", &(win_pd_th[1].frame_diff_skew_th), NULL},
- {"win1_pd_frame_diff_num_skew_th", &(win_pd_th[1].frame_diff_num_skew_th), NULL},
- {"win1_pd_field_diff_num_th", &(win_pd_th[1].field_diff_num_th), NULL},
- {"win2_start_x_r", &pd_win_prop[2].win_start_x_r, NULL},
- {"win2_end_x_r", &pd_win_prop[2].win_end_x_r, NULL},
- {"win2_start_y_r", &pd_win_prop[2].win_start_y_r, NULL},
- {"win2_end_y_r", &pd_win_prop[2].win_end_y_r, NULL},
- {"win2_32lvl", &pd_win_prop[2].win_32lvl, NULL},
- {"win2_22lvl", &pd_win_prop[2].win_22lvl, NULL},
- {"win2_pd_frame_diff_chg_th", &(win_pd_th[2].frame_diff_chg_th), NULL},
- {"win2_pd_frame_diff_num_chg_th", &(win_pd_th[2].frame_diff_num_chg_th), NULL},
- {"win2_pd_field_diff_chg_th", &(win_pd_th[2].field_diff_chg_th), NULL},
- {"win2_pd_field_diff_num_chg_th", &(win_pd_th[2].field_diff_num_chg_th), NULL},
- {"win2_pd_frame_diff_skew_th", &(win_pd_th[2].frame_diff_skew_th), NULL},
- {"win2_pd_frame_diff_num_skew_th", &(win_pd_th[2].frame_diff_num_skew_th), NULL},
- {"win2_pd_field_diff_num_th", &(win_pd_th[2].field_diff_num_th), NULL},
- {"win3_start_x_r", &pd_win_prop[3].win_start_x_r, NULL},
- {"win3_end_x_r", &pd_win_prop[3].win_end_x_r, NULL},
- {"win3_start_y_r", &pd_win_prop[3].win_start_y_r, NULL},
- {"win3_end_y_r", &pd_win_prop[3].win_end_y_r, NULL},
- {"win3_32lvl", &pd_win_prop[3].win_32lvl, NULL},
- {"win3_22lvl", &pd_win_prop[3].win_22lvl, NULL},
- {"win3_pd_frame_diff_chg_th", &(win_pd_th[3].frame_diff_chg_th), NULL},
- {"win3_pd_frame_diff_num_chg_th", &(win_pd_th[3].frame_diff_num_chg_th), NULL},
- {"win3_pd_field_diff_chg_th", &(win_pd_th[3].field_diff_chg_th), NULL},
- {"win3_pd_field_diff_num_chg_th", &(win_pd_th[3].field_diff_num_chg_th), NULL},
- {"win3_pd_frame_diff_skew_th", &(win_pd_th[3].frame_diff_skew_th), NULL},
- {"win3_pd_frame_diff_num_skew_th", &(win_pd_th[3].frame_diff_num_skew_th), NULL},
- {"win3_pd_field_diff_num_th", &(win_pd_th[3].field_diff_num_th), NULL},
- {"win4_start_x_r", &pd_win_prop[4].win_start_x_r, NULL},
- {"win4_end_x_r", &pd_win_prop[4].win_end_x_r, NULL},
- {"win4_start_y_r", &pd_win_prop[4].win_start_y_r, NULL},
- {"win4_end_y_r", &pd_win_prop[4].win_end_y_r, NULL},
- {"win4_32lvl", &pd_win_prop[4].win_32lvl, NULL},
- {"win4_22lvl", &pd_win_prop[4].win_22lvl, NULL},
- {"win4_pd_frame_diff_chg_th", &(win_pd_th[4].frame_diff_chg_th), NULL},
- {"win4_pd_frame_diff_num_chg_th", &(win_pd_th[4].frame_diff_num_chg_th), NULL},
- {"win4_pd_field_diff_chg_th", &(win_pd_th[4].field_diff_chg_th), NULL},
- {"win4_pd_field_diff_num_chg_th", &(win_pd_th[4].field_diff_num_chg_th), NULL},
- {"win4_pd_frame_diff_skew_th", &(win_pd_th[4].frame_diff_skew_th), NULL},
- {"win4_pd_frame_diff_num_skew_th", &(win_pd_th[4].frame_diff_num_skew_th), NULL},
- {"win4_pd_field_diff_num_th", &(win_pd_th[4].field_diff_num_th), NULL},
- {"pd32_match_num", &pd32_match_num, NULL},
- {"pd32_diff_num_0_th", &pd32_diff_num_0_th, NULL},
- {"pd32_debug_th", &pd32_debug_th, NULL},
- {"pd22_th", &pd22_th, NULL},
- {"pd22_num_th", &pd22_num_th, NULL},
- {"", NULL}
- };
- static ssize_t show_parameters(struct device * dev, struct device_attribute *attr, char * buf)
- {
- int i = 0;
- int len = 0;
- for(i=0; di_params[i].param; i++){
- len += sprintf(buf+len, "%s=%08x\n", di_params[i].name, *(di_params[i].param));
- }
- return len;
- }
- static char tmpbuf[128];
- static ssize_t store_parameters(struct device * dev, struct device_attribute *attr, const char * buf, size_t count)
- {
- int i = 0;
- int j;
- while((buf[i])&&(buf[i]!='=')&&(buf[i]!=' ')){
- tmpbuf[i]=buf[i];
- i++;
- }
- tmpbuf[i]=0;
- //printk("%s\n", tmpbuf);
- if(strcmp("reset", tmpbuf)==0){
- reset_di_para();
- di_print("reset param\n");
- }
- else{
- for(j=0; di_params[j].param; j++){
- if(strcmp(di_params[j].name, tmpbuf)==0){
- int value=simple_strtoul(buf+i+1, NULL, 16);
- *(di_params[j].param) = value;
- if(di_params[j].proc_fun){
- di_params[j].proc_fun();
- }
- di_print("set %s=%x\n", di_params[j].name, value);
- break;
- }
- }
- }
- return count;
- }
- typedef struct{
- char* name;
- uint* status;
- }di_status_t;
- di_status_t di_status[]=
- {
- {"active", &init_flag },
- {"", NULL}
- };
- static ssize_t show_status(struct device * dev, struct device_attribute *attr, char * buf)
- {
- int i = 0;
- int len = 0;
- di_print("%s\n", __func__);
- for(i=0; di_status[i].status; i++){
- len += sprintf(buf+len, "%s=%08x\n", di_status[i].name, *(di_status[i].status));
- }
- return len;
- }
- static DEVICE_ATTR(config, S_IWUGO | S_IRUGO, show_config, store_config);
- static DEVICE_ATTR(parameters, S_IWUGO | S_IRUGO, show_parameters, store_parameters);
- static DEVICE_ATTR(debug, S_IWUGO | S_IRUGO, NULL, store_dbg);
- static DEVICE_ATTR(log, S_IWUGO | S_IRUGO, show_log, store_log);
- static DEVICE_ATTR(status, S_IWUGO | S_IRUGO, show_status, NULL);
- /***************************
- * di buffer management
- ***************************/
- #if defined(CONFIG_ARCH_MESON2)
- #define MAX_IN_BUF_NUM 16
- #define MAX_LOCAL_BUF_NUM 12
- #define MAX_POST_BUF_NUM 16
- #else
- #define MAX_IN_BUF_NUM 8
- #define MAX_LOCAL_BUF_NUM 6
- #define MAX_POST_BUF_NUM 6
- #endif
- #define VFRAME_TYPE_IN 1
- #define VFRAME_TYPE_LOCAL 2
- #define VFRAME_TYPE_POST 3
- #define VFRAME_TYPE_NUM 3
- #ifdef DI_DEBUG
- static char* vframe_type_name[] = {"", "di_buf_in", "di_buf_loc", "di_buf_post"};
- #endif
- typedef struct di_buf_s{
- #ifdef USE_LIST
- struct list_head list;
- #endif
- vframe_t* vframe;
- int index; /* index in vframe_in_dup[] or vframe_in[], only for type of VFRAME_TYPE_IN */
- int post_proc_flag; /* 0,no post di; 1, normal post di; 2, edge only; 3, dummy */
- int new_format_flag;
- int type;
- int seq;
- int pre_ref_count; /* none zero, is used by mem_mif, chan2_mif, or wr_buf*/
- int post_ref_count; /* none zero, is used by post process */
- int queue_index;
- /*below for type of VFRAME_TYPE_LOCAL */
- unsigned int nr_adr;
- int nr_canvas_idx;
- unsigned int mtn_adr;
- int mtn_canvas_idx;
- /* pull down information */
- pulldown_detect_info_t field_pd_info;
- pulldown_detect_info_t win_pd_info[MAX_WIN_NUM];
- unsigned long mtn_info[5];
- int pulldown_mode;
- int win_pd_mode[5];
- /*below for type of VFRAME_TYPE_POST*/
- struct di_buf_s* di_buf[2];
- 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*/
- }di_buf_t;
- static unsigned long di_mem_start;
- static unsigned long di_mem_size;
- static unsigned int default_width = 1920;
- static unsigned int default_height = 1080;
- static int local_buf_num;
- /*
- progressive frame process type config:
- 0, process by field;
- 1, process by frame (only valid for vdin source whose width/height does not change)
- */
- static vframe_t* vframe_in[MAX_IN_BUF_NUM];
- static vframe_t vframe_in_dup[MAX_IN_BUF_NUM];
- static vframe_t vframe_local[MAX_LOCAL_BUF_NUM*2];
- static vframe_t vframe_post[MAX_POST_BUF_NUM];
- static di_buf_t* cur_post_ready_di_buf = NULL;
- static di_buf_t di_buf_local[MAX_LOCAL_BUF_NUM*2];
- static di_buf_t di_buf_in[MAX_IN_BUF_NUM];
- static di_buf_t di_buf_post[MAX_POST_BUF_NUM];
- /*
- all buffers are in
- 1) list of local_free_list,in_free_list,pre_ready_list,recycle_list
- 2) di_pre_stru.di_inp_buf
- 3) di_pre_stru.di_wr_buf
- 4) cur_post_ready_di_buf
- 5) (di_buf_t*)(vframe->private_data)->di_buf[]
- 6) post_free_list_head
- 8) (di_buf_t*)(vframe->private_data)
- */
- #define QUEUE_LOCAL_FREE 0
- #define QUEUE_IN_FREE 1
- #define QUEUE_PRE_READY 2
- #define QUEUE_POST_FREE 3
- #define QUEUE_POST_READY 4
- #define QUEUE_RECYCLE 5
- #define QUEUE_DISPLAY 6
- #define QUEUE_TMP 7
- #define QUEUE_NUM 8
- #ifdef USE_LIST
- static struct list_head local_free_list_head = LIST_HEAD_INIT(local_free_list_head); // vframe is local_vframe
- static struct list_head in_free_list_head = LIST_HEAD_INIT(in_free_list_head); //vframe is NULL
- static struct list_head pre_ready_list_head = LIST_HEAD_INIT(pre_ready_list_head); //vframe is either local_vframe or in_vframe
- static struct list_head recycle_list_head = LIST_HEAD_INIT(recycle_list_head); //vframe is either local_vframe or in_vframe
- static struct list_head post_free_list_head = LIST_HEAD_INIT(post_free_list_head); //vframe is post_vframe
- static struct list_head post_ready_list_head = LIST_HEAD_INIT(post_ready_list_head); //vframe is post_vframe
- static struct list_head display_list_head = LIST_HEAD_INIT(display_list_head); //vframe sent out for displaying
- static struct list_head* list_head_array[QUEUE_NUM];
- #define get_di_buf_head(queue_idx) \
- list_first_entry(list_head_array[queue_idx], struct di_buf_s, list)
- static void queue_init(int local_buffer_num)
- {
- list_head_array[QUEUE_LOCAL_FREE] = &local_free_list_head;
- list_head_array[QUEUE_IN_FREE] = &in_free_list_head;
- list_head_array[QUEUE_PRE_READY] = &pre_ready_list_head;
- list_head_array[QUEUE_POST_FREE] = &post_free_list_head;
- list_head_array[QUEUE_POST_READY] = &post_ready_list_head;
- list_head_array[QUEUE_RECYCLE] = &recycle_list_head;
- list_head_array[QUEUE_DISPLAY] = &display_list_head;
- list_head_array[QUEUE_TMP] = &post_ready_list_head;
-
- }
- static bool queue_empty(queue_idx)
- {
- return list_empty(list_head_array[queue_idx]);
- }
- static void queue_out(di_buf_t* di_buf)
- {
- list_del(&(di_buf->list));
- }
- static void queue_in(di_buf_t* di_buf, int queue_idx)
- {
- list_add_tail(&(di_buf->list), list_head_array[queue_idx]);
- }
- static int list_count(int queue_idx)
- {
- int count = 0;
- di_buf_t *p = NULL, *ptmp;
- list_for_each_entry_safe(p, ptmp, list_head_array[queue_idx], list) {
- count++;
- }
- return count;
- }
- #define queue_for_each_entry(di_buf, ptm, queue_idx, list) \
- list_for_each_entry_safe(di_buf, ptmp, list_head_array[queue_idx], list)
- #else
- #define MAX_QUEUE_POOL_SIZE 256
- typedef struct queue_s{
- int num;
- int in_idx;
- int out_idx;
- int type; /* 0, first in first out; 1, general */
- unsigned int pool[MAX_QUEUE_POOL_SIZE];
- }queue_t;
- static queue_t queue[QUEUE_NUM];
- struct di_buf_pool_s{
- di_buf_t* di_buf_ptr;
- unsigned int size;
- }di_buf_pool[VFRAME_TYPE_NUM];
- #define queue_for_each_entry(di_buf, ptm, queue_idx, list) \
- for(itmp=0; ((di_buf = get_di_buf(queue_idx, &itmp))!=NULL); )
-
- static void queue_init(int local_buffer_num)
- {
- int i, j;
- for(i=0; i<QUEUE_NUM; i++){
- queue_t* q = &queue[i];
- for(j=0; j<MAX_QUEUE_POOL_SIZE; j++){
- q->pool[j] = 0;
- }
- q->in_idx = 0;
- q->out_idx = 0;
- q->num = 0;
- q->type = 0;
- if((i==QUEUE_RECYCLE)||(i==QUEUE_DISPLAY)||(i==QUEUE_TMP)){
- q->type = 1;
- }
- }
- if(local_buffer_num > 0){
- di_buf_pool[VFRAME_TYPE_IN-1].di_buf_ptr = &di_buf_in[0];
- di_buf_pool[VFRAME_TYPE_IN-1].size = MAX_IN_BUF_NUM;
-
- di_buf_pool[VFRAME_TYPE_LOCAL-1].di_buf_ptr = &di_buf_local[0];
- di_buf_pool[VFRAME_TYPE_LOCAL-1].size = local_buffer_num;
-
- di_buf_pool[VFRAME_TYPE_POST-1].di_buf_ptr = &di_buf_post[0];
- di_buf_pool[VFRAME_TYPE_POST-1].size = MAX_POST_BUF_NUM;
- }
-
- }
- static di_buf_t* get_di_buf(int queue_idx, int* start_pos)
- {
- queue_t* q = &(queue[queue_idx]);
- int idx;
- unsigned int pool_idx, di_buf_idx;
- di_buf_t* di_buf = NULL;
-
- #ifdef DI_DEBUG
- if(di_log_flag&DI_LOG_QUEUE){
- di_print("%s:<%d:%d,%d,%d> %d\n", __func__, queue_idx, q->num, q->in_idx, q->out_idx, *start_pos);
- }
- #endif
- if(q->type==0){
- if((*start_pos) < q->num){
- idx = q->out_idx + (*start_pos);
- if(idx >= MAX_QUEUE_POOL_SIZE){
- idx-=MAX_QUEUE_POOL_SIZE;
- }
- (*start_pos)++;
- }
- else{
- idx = MAX_QUEUE_POOL_SIZE;
- }
- }
- else{
- for(idx=(*start_pos); idx<MAX_QUEUE_POOL_SIZE; idx++){
- if(q->pool[idx]!=0){
- *start_pos = idx+1;
- break;
- }
- }
- }
- if(idx<MAX_QUEUE_POOL_SIZE){
- pool_idx = ((q->pool[idx]>>8)&0xff)-1;
- di_buf_idx = q->pool[idx]&0xff;
- if(pool_idx < VFRAME_TYPE_NUM){
- if(di_buf_idx < di_buf_pool[pool_idx].size){
- di_buf = &(di_buf_pool[pool_idx].di_buf_ptr[di_buf_idx]);
- }
- }
- }
- if((di_buf)&&( (((pool_idx+1)<<8)|di_buf_idx) != ((di_buf->type<<8)|(di_buf->index)))){
- #ifdef DI_DEBUG
- printk("%s: Error (%x,%x)\n", __func__, (((pool_idx+1)<<8)|di_buf_idx), ((di_buf->type<<8)|(di_buf->index)) );
- #endif
- recovery_flag = 1;
- di_buf = NULL;
- }
-
- #ifdef DI_DEBUG
- if(di_log_flag&DI_LOG_QUEUE){
- if(di_buf){
- di_print("%s: %x(%d,%d)\n", __func__, di_buf, pool_idx, di_buf_idx);
- }
- else{
- di_print("%s: %x\n", __func__, di_buf);
- }
- }
- #endif
- return di_buf;
- }
- static di_buf_t* get_di_buf_head(int queue_idx)
- {
- queue_t* q = &(queue[queue_idx]);
- int idx;
- unsigned int pool_idx, di_buf_idx;
- di_buf_t* di_buf = NULL;
- #ifdef DI_DEBUG
- if(di_log_flag&DI_LOG_QUEUE){
- di_print("%s:<%d:%d,%d,%d>\n", __func__,queue_idx,q->num, q->in_idx, q->out_idx);
- }
- #endif
- if(q->num > 0){
- if(q->type==0){
- idx = q->out_idx;
- }
- else{
- for(idx=0; idx<MAX_QUEUE_POOL_SIZE; idx++){
- if(q->pool[idx]!=0){
- break;
- }
- }
- }
- if(idx<MAX_QUEUE_POOL_SIZE){
- pool_idx = ((q->pool[idx]>>8)&0xff)-1;
- di_buf_idx = q->pool[idx]&0xff;
- if(pool_idx < VFRAME_TYPE_NUM){
- if(di_buf_idx < di_buf_pool[pool_idx].size){
- di_buf = &(di_buf_pool[pool_idx].di_buf_ptr[di_buf_idx]);
- }
- }
- }
- }
- if((di_buf)&&( (((pool_idx+1)<<8)|di_buf_idx) != ((di_buf->type<<8)|(di_buf->index)))){
- #ifdef DI_DEBUG
- printk("%s: Error (%x,%x)\n", __func__, (((pool_idx+1)<<8)|di_buf_idx), ((di_buf->type<<8)|(di_buf->index)) );
- #endif
- recovery_flag = 1;
- di_buf = NULL;
- }
-
- #ifdef DI_DEBUG
- if(di_log_flag&DI_LOG_QUEUE){
- if(di_buf){
- di_print("%s: %x(%d,%d)\n", __func__, di_buf, pool_idx, di_buf_idx);
- }
- else{
- di_print("%s: %x\n", __func__, di_buf);
- }
- }
- #endif
- return di_buf;
-
- }
- static void queue_out(di_buf_t* di_buf)
- {
- int i;
- if(di_buf == NULL){
- #ifdef DI_DEBUG
- printk("%s:Error\n", __func__);
- #endif
- recovery_flag = 1;
- return;
- }
- if(di_buf->queue_index>=0 && di_buf->queue_index<QUEUE_NUM){
- queue_t* q = &(queue[di_buf->queue_index]);
- #ifdef DI_DEBUG
- if(di_log_flag&DI_LOG_QUEUE){
- di_print("%s:<%d:%d,%d,%d> %x\n", __func__, di_buf->queue_index, q->num, q->in_idx, q->out_idx, di_buf);
- }
- #endif
- if(q->num > 0){
- if(q->type==0){
- if(q->pool[q->out_idx] == ((di_buf->type<<8)|(di_buf->index))){
- q->num--;
- q->pool[q->out_idx] = 0;
- q->out_idx++;
- if(q->out_idx>=MAX_QUEUE_POOL_SIZE){
- q->out_idx = 0;
- }
- di_buf->queue_index = -1;
- }
- else{
- #ifdef DI_DEBUG
- printk("%s: Error (%d, %x,%x)\n", __func__, di_buf->queue_index, q->pool[q->out_idx], ((di_buf->type<<8)|(di_buf->index)) );
- #endif
- recovery_flag = 1;
- }
- }
- else{
- int pool_val = (di_buf->type<<8)|(di_buf->index);
- for(i=0; i<MAX_QUEUE_POOL_SIZE; i++){
- if(q->pool[i]==pool_val){
- q->num--;
- q->pool[i]=0;
- di_buf->queue_index = -1;
- break;
- }
- }
- if(i==MAX_QUEUE_POOL_SIZE){
- #ifdef DI_DEBUG
- printk("%s: Error\n", __func__);
- #endif
- recovery_flag = 1;
- }
- }
- }
- }
- else{
- #ifdef DI_DEBUG
- printk("%s: Error, queue_index %d is not right\n", __func__, di_buf->queue_index);
- #endif
- recovery_flag = 1;
- }
- #ifdef DI_DEBUG
- if(di_log_flag&DI_LOG_QUEUE){
- di_print("%s done\n",__func__);
- }
- #endif
- }
- static void queue_in(di_buf_t* di_buf, int queue_idx)
- {
- if(di_buf == NULL){
- #ifdef DI_DEBUG
- printk("%s:Error\n", __func__);
- #endif
- recovery_flag = 1;
- return;
- }
- if(di_buf->queue_index != -1){
- #ifdef DI_DEBUG
- printk("%s:Error, queue_index(%d) is not -1\n", __func__, di_buf->queue_index);
- #endif
- recovery_flag = 1;
- return;
- }
- queue_t* q = &(queue[queue_idx]);
- #ifdef DI_DEBUG
- if(di_log_flag&DI_LOG_QUEUE){
- di_print("%s:<%d:%d,%d,%d> %x\n", __func__,queue_idx, q->num, q->in_idx, q->out_idx,di_buf);
- }
- #endif
- if(q->type==0){
- q->pool[q->in_idx] = (di_buf->type<<8)|(di_buf->index);
- di_buf->queue_index = queue_idx;
- q->in_idx++;
- if(q->in_idx>=MAX_QUEUE_POOL_SIZE){
- q->in_idx = 0;
- }
- q->num++;
- }
- else{
- int i;
- for(i=0; i<MAX_QUEUE_POOL_SIZE; i++){
- if(q->pool[i]==0){
- q->pool[i] = (di_buf->type<<8)|(di_buf->index);
- di_buf->queue_index = queue_idx;
- q->num++;
- break;
- }
- }
- if(i==MAX_QUEUE_POOL_SIZE){
- #ifdef DI_DEBUG
- printk("%s: Error\n", __func__);
- #endif
- recovery_flag = 1;
- }
- }
- #ifdef DI_DEBUG
- if(di_log_flag&DI_LOG_QUEUE){
- di_print("%s done\n",__func__);
- }
- #endif
- }
- static int list_count(int queue_idx)
- {
- return queue[queue_idx].num;
- }
- static bool queue_empty(queue_idx)
- {
- return (queue[queue_idx].num == 0);
- }
- #endif
- static bool is_in_queue(di_buf_t* di_buf, int queue_idx)
- {
- bool ret = 0;
- di_buf_t *p = NULL, *ptmp;
- int itmp;
- queue_for_each_entry(p, ptmp, queue_idx, list) {
- if(p==di_buf){
- ret = 1;
- break;
- }
- }
- return ret;
- }
- typedef struct{
- /* pre input */
- DI_MIF_t di_inp_mif;
- DI_MIF_t di_mem_mif;
- DI_MIF_t di_chan2_mif;
- di_buf_t* di_inp_buf;
- di_buf_t* di_mem_buf_dup_p;
- di_buf_t* di_chan2_buf_dup_p;
- /* pre output */
- DI_SIM_MIF_t di_nrwr_mif;
- DI_SIM_MIF_t di_mtnwr_mif;
- di_buf_t* di_wr_buf;
- /* pre state */
- int in_seq;
- int recycle_seq;
- int pre_ready_seq;
- int pre_de_busy; /* 1 if pre_de is not done */
- int pre_de_busy_timer_count;
- int pre_de_process_done; /* flag when irq done */
- int unreg_req_flag; /* flag is set when VFRAME_EVENT_PROVIDER_UNREG*/
- int force_unreg_req_flag;
- int disable_req_flag;
- /* current source info */
- int cur_width;
- int cur_height;
- int cur_inp_type;
- int cur_prog_flag; /* 1 for progressive source */
- int process_count; /* valid only when prog_proc_type is 0, for progressive source: top field 1, bot field 0 */
- int source_change_flag;
- unsigned char prog_proc_type; /* set by prog_proc_config when source is vdin*/
- unsigned char enable_mtnwr;
- unsigned char enable_pulldown_check;
- int same_field_source_flag;
- }di_pre_stru_t;
- static di_pre_stru_t di_pre_stru;
- static void dump_di_pre_stru(void)
- {
- printk("di_pre_stru:\n");
- printk("di_mem_buf_dup_p = 0x%p\n", di_pre_stru.di_mem_buf_dup_p);
- printk("di_chan2_buf_dup_p = 0x%p\n", di_pre_stru.di_chan2_buf_dup_p);
- printk("in_seq = %d\n", di_pre_stru.in_seq);
- printk("recycle_seq = %d\n", di_pre_stru.recycle_seq);
- printk("pre_ready_seq = %d\n", di_pre_stru.pre_ready_seq);
- printk("pre_de_busy = %d\n", di_pre_stru.pre_de_busy);
- printk("pre_de_busy_timer_count= %d\n", di_pre_stru.pre_de_busy_timer_count);
- printk("pre_de_process_done = %d\n", di_pre_stru.pre_de_process_done);
- printk("unreg_req_flag = %d\n", di_pre_stru.unreg_req_flag);
- printk("cur_width = %d\n", di_pre_stru.cur_width);
- printk("cur_height = %d\n", di_pre_stru.cur_height);
- printk("cur_inp_type = 0x%x\n", di_pre_stru.cur_inp_type);
- printk("cur_prog_flag = %d\n", di_pre_stru.cur_prog_flag);
- printk("process_count = %d\n", di_pre_stru.process_count);
- printk("source_change_flag = %d\n", di_pre_stru.source_change_flag);
- printk("prog_proc_type = %d\n", di_pre_stru.prog_proc_type);
- printk("enable_mtnwr = %d\n", di_pre_stru.enable_mtnwr);
- printk("enable_pulldown_check = %d\n", di_pre_stru.enable_pulldown_check);
- printk("same_field_source_flag = %d\n", di_pre_stru.same_field_source_flag);
- }
- typedef struct{
- DI_MIF_t di_buf0_mif;
- DI_MIF_t di_buf1_mif;
- DI_SIM_MIF_t di_mtncrd_mif;
- DI_SIM_MIF_t di_mtnprd_mif;
- }di_post_stru_t;
- static di_post_stru_t di_post_stru;
- #define is_from_vdin(vframe) (vframe->type & VIDTYPE_VIU_422)
- static void recycle_vframe_type_post(di_buf_t* di_buf);
- #ifdef DI_DEBUG
- static void recycle_vframe_type_post_print(di_buf_t* di_buf, const char* func);
- #endif
- static ssize_t store_config(struct device * dev, struct device_attribute *attr, const char * buf, size_t count)
- {
- if(strncmp(buf, "disable", 7)==0){
- #ifdef DI_DEBUG
- di_print("%s: disable\n", __func__);
- #endif
- if(init_flag){
- di_pre_stru.disable_req_flag = 1;
- provider_vframe_level = 0;
- trigger_pre_di_process('d');
- while(di_pre_stru.disable_req_flag){
- msleep(1);
- }
- }
- }
- return count;
- }
- static unsigned char is_progressive(vframe_t* vframe)
- {
- return ((vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_PROGRESSIVE);
- }
- static void force_source_change(void)
- {
- di_pre_stru.cur_inp_type = 0;
- }
- static unsigned char is_source_change(vframe_t* vframe)
- {
- #define VFRAME_FORMAT_MASK (VIDTYPE_VIU_422|VIDTYPE_VIU_FIELD|VIDTYPE_VIU_SINGLE_PLANE|VIDTYPE_VIU_444|VIDTYPE_MVC)
- if(
- (di_pre_stru.cur_width!=vframe->width)||
- (di_pre_stru.cur_height!=vframe->height)||
- (di_pre_stru.cur_prog_flag!=is_progressive(vframe))||
- ((di_pre_stru.cur_inp_type&VFRAME_FORMAT_MASK)!=(vframe->type&VFRAME_FORMAT_MASK))
- ){
- return 1;
- }
- return 0;
- }
- static unsigned char is_bypass(void)
- {
- if(bypass_vscale_skip && (get_current_vscale_skip_count()>0))
- return 1;
-
- if(bypass_all)
- return 1;
- if(di_pre_stru.cur_prog_flag&&
- ((bypass_prog)||
- (di_pre_stru.cur_width>1920)||(di_pre_stru.cur_height>1080)
- ||(di_pre_stru.cur_inp_type&VIDTYPE_VIU_444))
- )
- return 1;
- if(bypass_hd&&
- ((di_pre_stru.cur_width>720)||(di_pre_stru.cur_height>576))
- )
- return 1;
- if(di_pre_stru.cur_inp_type&VIDTYPE_MVC)
- return 1;
- return 0;
- }
- #if defined(CONFIG_ARCH_MESON2)
- #if ((DEINTERLACE_CANVAS_BASE_INDEX!=0x68)||(DEINTERLACE_CANVAS_MAX_INDEX!=0x7f))
- #error "DEINTERLACE_CANVAS_BASE_INDEX is not 0x68 or DEINTERLACE_CANVAS_MAX_INDEX is not 0x7f, update canvas.h"
- #endif
- #endif
- static int di_init_buf(int width, int height, unsigned char prog_flag)
- {
- int i, local_buf_num_available;
- int canvas_height = height + 8;
- frame_count = 0;
- disp_frame_count = 0;
- cur_post_ready_di_buf = NULL;
- for(i=0; i<MAX_IN_BUF_NUM; i++){
- vframe_in[i]=NULL;
- }
- memset(&di_pre_stru, 0, sizeof(di_pre_stru));
- memset(&di_post_stru, 0, sizeof(di_post_stru));
- if(prog_flag){
- di_pre_stru.prog_proc_type = 1;
- local_buf_num = di_mem_size/(width*canvas_height*2);
- local_buf_num_available = local_buf_num;
- if(local_buf_num > (2*MAX_LOCAL_BUF_NUM)){
- local_buf_num = 2*MAX_LOCAL_BUF_NUM;
- }
- }
- else{
- di_pre_stru.prog_proc_type = 0;
- local_buf_num = di_mem_size/(width*canvas_height*5/4);
- local_buf_num_available = local_buf_num;
- if(local_buf_num > MAX_LOCAL_BUF_NUM){
- local_buf_num = MAX_LOCAL_BUF_NUM;
- }
- }
- printk("%s: version %d, prog_proc_type %d, buf start %x, size %x, buf(w%d,h%d) num %d (available %d) \n",
- __func__, version, di_pre_stru.prog_proc_type, (unsigned int)di_mem_start,
- (unsigned int)di_mem_size, width, canvas_height, local_buf_num, local_buf_num_available);
- same_w_r_canvas_count = 0;
- same_field_top_count = 0;
- same_field_bot_count = 0;
- queue_init(local_buf_num);
- for(i=0; i<local_buf_num; i++){
- di_buf_t* di_buf = &(di_buf_local[i]);
- if(di_buf){
- memset(di_buf, sizeof(di_buf_t), 0);
- di_buf->type = VFRAME_TYPE_LOCAL;
- di_buf->pre_ref_count = 0;
- di_buf->post_ref_count = 0;
- if(prog_flag){
- di_buf->nr_adr = di_mem_start + (width*canvas_height*2)*i;
- di_buf->nr_canvas_idx = DEINTERLACE_CANVAS_BASE_INDEX+i;
- canvas_config(di_buf->nr_canvas_idx, di_buf->nr_adr, width*2, canvas_height, 0, 0);
- }
- else{
- di_buf->nr_adr = di_mem_start + (width*canvas_height*5/4)*i;
- di_buf->nr_canvas_idx = DEINTERLACE_CANVAS_BASE_INDEX+i*2;
- canvas_config(di_buf->nr_canvas_idx, di_buf->nr_adr, width*2, canvas_height/2, 0, 0);
- di_buf->mtn_adr = di_mem_start + (width*canvas_height*5/4)*i + (width*canvas_height);
- di_buf->mtn_canvas_idx = DEINTERLACE_CANVAS_BASE_INDEX+i*2+1;
- canvas_config(di_buf->mtn_canvas_idx, di_buf->mtn_adr, width/2, canvas_height/2, 0, 0);
- }
- di_buf->index = i;
- di_buf->vframe = &(vframe_local[i]);
- di_buf->vframe->private_data = di_buf;
- di_buf->vframe->canvas0Addr = di_buf->nr_canvas_idx;
- di_buf->vframe->canvas1Addr = di_buf->nr_canvas_idx;
- di_buf->queue_index = -1;
- queue_in(di_buf, QUEUE_LOCAL_FREE);
- }
- }
- for(i=0; i<MAX_IN_BUF_NUM; i++){
- di_buf_t* di_buf = &(di_buf_in[i]);
- if(di_buf){
- memset(di_buf, sizeof(di_buf_t), 0);
- di_buf->type = VFRAME_TYPE_IN;
- di_buf->pre_ref_count = 0;
- di_buf->post_ref_count = 0;
- di_buf->vframe = &(vframe_in_dup[i]);
- di_buf->vframe->private_data = di_buf;
- di_buf->index = i;
- di_buf->queue_index = -1;
- queue_in(di_buf, QUEUE_IN_FREE);
- }
- }
- for(i=0; i<MAX_POST_BUF_NUM; i++){
- di_buf_t* di_buf = &(di_buf_post[i]);
- if(di_buf){
- memset(di_buf, sizeof(di_buf_t), 0);
- di_buf->type = VFRAME_TYPE_POST;
- di_buf->index = i;
- di_buf->vframe = &(vframe_post[i]);
- di_buf->vframe->private_data = di_buf;
- di_buf->queue_index = -1;
- queue_in(di_buf, QUEUE_POST_FREE);
- }
- }
- return 0;
- }
- static void di_uninit_buf(void)
- {
- di_buf_t *p = NULL, *ptmp;
- int i;
- #ifdef USE_LIST
- list_for_each_entry_safe(p, ptmp, &local_free_list_head, list) {
- list_del(&p->list);
- }
- list_for_each_entry_safe(p, ptmp, &in_free_list_head, list) {
- list_del(&p->list);
- }
- list_for_each_entry_safe(p, ptmp, &pre_ready_list_head, list) {
- list_del(&p->list);
- }
- list_for_each_entry_safe(p, ptmp, &recycle_list_head, list) {
- list_del(&p->list);
- }
- list_for_each_entry_safe(p, ptmp, &post_free_list_head, list) {
- list_del(&p->list);
- }
- list_for_each_entry_safe(p, ptmp, &post_ready_list_head, list) {
- list_del(&p->list);
- }
- list_for_each_entry_safe(p, ptmp, &display_list_head, list) {
- list_del(&p->list);
- }
- #else
- queue_init(0);
- #endif
- for(i=0; i<MAX_IN_BUF_NUM; i++){
- vframe_in[i]=NULL;
- }
- }
- static void di_clean_in_buf(void)
- {
- di_buf_t *di_buf = NULL, *ptmp;
- int itmp;
- int i;
- //di_printk_flag = 1;
- frame_count = 0;
- //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
- if(real_buf_mgr_mode&0x100){
- while(!queue_empty(QUEUE_POST_READY)){
- di_buf = get_di_buf_head(QUEUE_POST_READY);
- recycle_vframe_type_post(di_buf);
- #ifdef DI_DEBUG
- recycle_vframe_type_post_print(di_buf, __func__);
- #endif
- }
- }
-
- if(di_pre_stru.di_mem_buf_dup_p){
- di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
- di_pre_stru.di_mem_buf_dup_p = NULL;
- }
- if(di_pre_stru.di_chan2_buf_dup_p){
- di_pre_stru.di_chan2_buf_dup_p->pre_ref_count = 0;
- di_pre_stru.di_chan2_buf_dup_p = NULL;
- }
- di_pre_stru.process_count = 0;
- if(di_pre_stru.di_inp_buf){
- if(vframe_in[di_pre_stru.di_inp_buf->index]){
- vframe_in[di_pre_stru.di_inp_buf->index] = NULL;
- }
- queue_in(di_pre_stru.di_inp_buf, QUEUE_IN_FREE);
- di_pre_stru.di_inp_buf = NULL;
- }
- if(di_pre_stru.di_wr_buf){
- di_pre_stru.di_wr_buf->pre_ref_count = 0;
- queue_in(di_pre_stru.di_wr_buf, QUEUE_RECYCLE);
- di_pre_stru.di_wr_buf = NULL;
- }
- queue_for_each_entry(di_buf, ptmp, QUEUE_PRE_READY, list) {
- queue_out(di_buf);
- queue_in(di_buf, QUEUE_RECYCLE);
- }
- queue_for_each_entry(di_buf, ptmp, QUEUE_RECYCLE, list) {
- if(di_buf->type == VFRAME_TYPE_IN){
- di_buf->pre_ref_count = 0;
- queue_out(di_buf);
- if(vframe_in[di_buf->index]){
- vframe_in[di_buf->index] = NULL;
- }
- queue_in(di_buf, QUEUE_IN_FREE);
- }
- else{
- if((di_buf->pre_ref_count == 0)&&(di_buf->post_ref_count == 0)){
- queue_out(di_buf);
- queue_in(di_buf, QUEUE_LOCAL_FREE);
- }
- }
- }
- di_pre_stru.cur_width = 0;
- di_pre_stru.cur_height= 0;
- di_pre_stru.cur_prog_flag = 0;
- di_pre_stru.cur_inp_type = 0;
- di_pre_stru.pre_de_process_done = 0;
- di_pre_stru.pre_de_busy = 0;
- for(i=0; i<MAX_IN_BUF_NUM; i++){
- vframe_in[i]=NULL;
- }
-
- }
- static void log_buffer_state(unsigned char* tag)
- {
- if(di_log_flag&DI_LOG_BUFFER_STATE){
- di_buf_t *p = NULL, *ptmp;
- int itmp;
- int in_free = 0;
- int local_free = 0;
- int pre_ready = 0;
- int post_free = 0;
- int post_ready = 0;
- int post_ready_ext = 0;
- int display = 0;
- int display_ext = 0;
- int recycle = 0;
- int di_inp = 0;
- int di_wr = 0;
- ulong fiq_flag;
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- in_free = list_count(QUEUE_IN_FREE);
- local_free = list_count(QUEUE_LOCAL_FREE);
- pre_ready = list_count(QUEUE_PRE_READY);
- post_free = list_count(QUEUE_POST_FREE);
- post_ready = list_count(QUEUE_POST_READY);
- queue_for_each_entry(p, ptmp, QUEUE_POST_READY, list) {
- if(p->di_buf[0]){
- post_ready_ext++;
- }
- if(p->di_buf[1]){
- post_ready_ext++;
- }
- }
- queue_for_each_entry(p, ptmp, QUEUE_DISPLAY, list) {
- display++;
- if(p->di_buf[0]){
- display_ext++;
- }
- if(p->di_buf[1]){
- display_ext++;
- }
- }
- recycle = list_count(QUEUE_RECYCLE);
- if(di_pre_stru.di_inp_buf)
- di_inp++;
- if(di_pre_stru.di_wr_buf)
- di_wr++;
-
- if(buf_state_log_threshold == 0){
- buf_state_log_start = 0;
- }
- else if(post_ready < buf_state_log_threshold){
- buf_state_log_start = 1;
- }
- if(buf_state_log_start){
- 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",
- tag,
- provider_vframe_level,
- in_free,MAX_IN_BUF_NUM,
- local_free, local_buf_num,
- pre_ready,
- post_free, MAX_POST_BUF_NUM,
- post_ready, post_ready_ext,
- display, display_ext,
- recycle,
- di_inp, di_wr
- );
- }
- raw_local_irq_restore(fiq_flag);
- }
- }
- static void dump_state(void)
- {
- di_buf_t *p = NULL, *ptmp;
- int itmp;
- printk("provider vframe level %d\n", provider_vframe_level);
- printk("in_free_list (max %d):\n", MAX_IN_BUF_NUM);
- queue_for_each_entry(p, ptmp, QUEUE_IN_FREE, list) {
- printk("index %d, %x, type %d\n", p->index, (unsigned int)p, p->type);
- }
- printk("local_free_list (max %d):\n", local_buf_num);
- queue_for_each_entry(p, ptmp, QUEUE_LOCAL_FREE, list) {
- printk("index %d, %x, type %d\n", p->index, (unsigned int)p, p->type);
- }
- printk("pre_ready_list:\n");
- queue_for_each_entry(p, ptmp, QUEUE_PRE_READY, list) {
- printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type, p->vframe->type);
- }
- printk("post_free_list (max %d):\n", MAX_POST_BUF_NUM);
- queue_for_each_entry(p, ptmp, QUEUE_POST_FREE, list) {
- printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type ,p->vframe->type);
- }
- printk("post_ready_list:\n");
- queue_for_each_entry(p, ptmp, QUEUE_POST_READY, list) {
- printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type, p->vframe->type);
- if(p->di_buf[0]){
- 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);
- }
- if(p->di_buf[1]){
- 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);
- }
- }
- printk("display_list:\n");
- queue_for_each_entry(p, ptmp, QUEUE_DISPLAY, list) {
- printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type, p->vframe->type);
- if(p->di_buf[0]){
- 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);
- }
- if(p->di_buf[1]){
- 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);
- }
- }
- printk("recycle_list:\n");
- queue_for_each_entry(p, ptmp, QUEUE_RECYCLE, list) {
- printk("index %d, %x, type %d, vframetype%x\n", p->index, (unsigned int)p, p->type, p->vframe->type);
- }
- if(di_pre_stru.di_inp_buf)
- 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);
- if(di_pre_stru.di_wr_buf)
- 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);
- dump_di_pre_stru();
- }
- /*
- * di pre process
- */
- 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)
- {
- di_nrwr_mif->canvas_num = di_buf->nr_canvas_idx;
- di_nrwr_mif->start_x = 0;
- di_nrwr_mif->end_x = in_vframe->width - 1;
- di_nrwr_mif->start_y = 0;
- if(di_pre_stru.prog_proc_type == 0){
- di_nrwr_mif->end_y = in_vframe->height/2 - 1;
- }
- else{
- di_nrwr_mif->end_y = in_vframe->height - 1;
- }
- if(di_pre_stru.prog_proc_type == 0){
- di_mtnwr_mif->start_x = 0;
- di_mtnwr_mif->end_x = in_vframe->width - 1;
- di_mtnwr_mif->start_y = 0;
- di_mtnwr_mif->end_y = in_vframe->height/2 - 1;
- di_mtnwr_mif->canvas_num = di_buf->mtn_canvas_idx;
- }
- }
- static void config_di_mif(DI_MIF_t* di_mif, di_buf_t*di_buf)
- {
- if(di_buf == NULL)
- return;
- di_mif->canvas0_addr0 = di_buf->vframe->canvas0Addr & 0xff;
- di_mif->canvas0_addr1 = (di_buf->vframe->canvas0Addr>>8) & 0xff;
- di_mif->canvas0_addr2 = (di_buf->vframe->canvas0Addr>>16) & 0xff;
- if ( di_buf->vframe->type & VIDTYPE_VIU_422 )
- { //from vdin or local vframe
- if((!is_progressive(di_buf->vframe)) //interlace, from vdin or local vframe
- ||(di_pre_stru.prog_proc_type) //progressive(by frame), from vdin or local frame
- ){
- di_mif->video_mode = 0;
- di_mif->set_separate_en = 0;
- di_mif->src_field_mode = 0;
- di_mif->output_field_num = 0;
- di_mif->burst_size_y = 3;
- di_mif->burst_size_cb = 0;
- di_mif->burst_size_cr = 0;
- di_mif->luma_x_start0 = 0;
- di_mif->luma_x_end0 = di_buf->vframe->width - 1;
- di_mif->luma_y_start0 = 0;
- if(di_pre_stru.prog_proc_type){
- di_mif->luma_y_end0 = di_buf->vframe->height - 1;
- }
- else{
- di_mif->luma_y_end0 = di_buf->vframe->height/2 - 1;
- }
- di_mif->chroma_x_start0 = 0;
- di_mif->chroma_x_end0 = 0;
- di_mif->chroma_y_start0 = 0;
- di_mif->chroma_y_end0 = 0;
- di_mif->canvas0_addr0 = di_buf->vframe->canvas0Addr & 0xff;
- di_mif->canvas0_addr1 = (di_buf->vframe->canvas0Addr>>8) & 0xff;
- di_mif->canvas0_addr2 = (di_buf->vframe->canvas0Addr>>16) & 0xff;
- }
- else{
- //progressive (by field), from vdin only
- di_mif->video_mode = 0;
- di_mif->set_separate_en = 0;
- di_mif->src_field_mode = 1;
- di_mif->burst_size_y = 3;
- di_mif->burst_size_cb = 0;
- di_mif->burst_size_cr = 0;
- if(di_pre_stru.process_count>0){ //process top
- di_mif->output_field_num = 0; // top
- di_mif->luma_x_start0 = 0;
- di_mif->luma_x_end0 = di_buf->vframe->width - 1;
- di_mif->luma_y_start0 = 0;
- di_mif->luma_y_end0 = di_buf->vframe->height - 2;
- di_mif->chroma_x_start0 = 0;
- di_mif->chroma_x_end0 = di_buf->vframe->width/2 - 1;
- di_mif->chroma_y_start0 = 0;
- di_mif->chroma_y_end0 = di_buf->vframe->height/2 - 2;
- }
- else{ //process bot
- di_mif->output_field_num = 1; // bottom
- di_mif->luma_x_start0 = 0;
- di_mif->luma_x_end0 = di_buf->vframe->width - 1;
- di_mif->luma_y_start0 = 1;
- di_mif->luma_y_end0 = di_buf->vframe->height - 1;
- di_mif->chroma_x_start0 = 0;
- di_mif->chroma_x_end0 = di_buf->vframe->width/2 - 1;
- di_mif->chroma_y_start0 = 1;
- di_mif->chroma_y_end0 = di_buf->vframe->height/2 - 1;
- }
- }
- }
- else{
- //from decoder
- di_mif->video_mode = 0;
- di_mif->set_separate_en = 1;
- di_mif->src_field_mode = 1;
- di_mif->burst_size_y = 3;
- di_mif->burst_size_cb = 1;
- di_mif->burst_size_cr = 1;
- if(((di_buf->vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)
- ||(di_pre_stru.process_count>0)){
- di_mif->output_field_num = 0; // top
- di_mif->luma_x_start0 = 0;
- di_mif->luma_x_end0 = di_buf->vframe->width - 1;
- di_mif->luma_y_start0 = 0;
- di_mif->luma_y_end0 = di_buf->vframe->height - 2;
- di_mif->chroma_x_start0 = 0;
- di_mif->chroma_x_end0 = di_buf->vframe->width/2 - 1;
- di_mif->chroma_y_start0 = 0;
- di_mif->chroma_y_end0 = di_buf->vframe->height/2 - 2;
- }
- else{
- di_mif->output_field_num = 1; // bottom
- di_mif->luma_x_start0 = 0;
- di_mif->luma_x_end0 = di_buf->vframe->width - 1;
- di_mif->luma_y_start0 = 1;
- di_mif->luma_y_end0 = di_buf->vframe->height - 1;
- di_mif->chroma_x_start0 = 0;
- di_mif->chroma_x_end0 = di_buf->vframe->width/2 - 1;
- di_mif->chroma_y_start0 = 1;
- di_mif->chroma_y_end0 = di_buf->vframe->height/2 - 1;
- }
- }
- }
- static void pre_de_process(void)
- {
- int chan2_field_num = 1;
- #ifdef DI_DEBUG
- di_print("%s: start\n", __func__);
- #endif
- di_pre_stru.pre_de_busy = 1;
- di_pre_stru.pre_de_busy_timer_count = 0;
- config_di_mif(&di_pre_stru.di_inp_mif, di_pre_stru.di_inp_buf);
- config_di_mif(&di_pre_stru.di_mem_mif, di_pre_stru.di_mem_buf_dup_p);
- config_di_mif(&di_pre_stru.di_chan2_mif, di_pre_stru.di_chan2_buf_dup_p);
- config_di_wr_mif(&di_pre_stru.di_nrwr_mif, &di_pre_stru.di_mtnwr_mif,
- di_pre_stru.di_wr_buf, di_pre_stru.di_inp_buf->vframe);
- if((di_pre_stru.di_chan2_buf_dup_p)&&
- ((di_pre_stru.di_chan2_buf_dup_p->vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)){
- chan2_field_num = 0;
- }
- Wr(DI_PRE_SIZE, di_pre_stru.di_nrwr_mif.end_x|(di_pre_stru.di_nrwr_mif.end_y << 16) );
- // set interrupt mask for pre module.
- Wr(DI_INTR_CTRL, (0 << 16) | // nrwr interrupt.
- ((di_pre_stru.enable_mtnwr?0:1) << 17) | // mtnwr interrupt.
- (1 << 18) | // diwr interrupt.
- (1 << 19) | // hist check interrupt.
- 0xf ); // clean all pending interrupt bits.
- #if 1
- enable_di_mode_check_2(
- (pd_win_prop[0].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
- (pd_win_prop[0].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[0].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
- (pd_win_prop[0].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[1].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
- (pd_win_prop[1].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[1].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
- (pd_win_prop[1].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[2].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
- (pd_win_prop[2].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[2].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
- (pd_win_prop[2].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[3].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
- (pd_win_prop[3].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[3].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
- (pd_win_prop[3].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[4].win_start_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR),
- (pd_win_prop[4].win_end_x_r*di_pre_stru.di_inp_buf->vframe->width/WIN_SIZE_FACTOR)-1,
- (pd_win_prop[4].win_start_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR),
- (pd_win_prop[4].win_end_y_r*(di_pre_stru.di_inp_buf->vframe->height/2)/WIN_SIZE_FACTOR)-1
- );
- #else
- enable_di_mode_check_2(
- 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)
- 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)
- 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)
- 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)
- 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)
- );
- #endif
- WRITE_MPEG_REG(DI_PRE_CTRL, 0x3 << 30); //reset
- enable_di_pre_aml ( &di_pre_stru.di_inp_mif, // di_inp
- &di_pre_stru.di_mem_mif, // di_mem
- &di_pre_stru.di_chan2_mif, // chan2
- &di_pre_stru.di_nrwr_mif, // nrwrite
- &di_pre_stru.di_mtnwr_mif, // mtn write
- 1, // nr enable
- di_pre_stru.enable_mtnwr, // mtn enable
- di_pre_stru.enable_pulldown_check, // pd32 check_en
- di_pre_stru.enable_pulldown_check, // pd22 check_en
- #if defined(CONFIG_ARCH_MESON)
- 1, // hist check_en
- #else
- 0, // hist check_en
- #endif
- chan2_field_num, // field num for chan2. 1 bottom, 0 top.
- 0, // pre viu link.
- 10 //hold line.
- );
- }
- static void pre_de_done_buf_config(void)
- {
- ulong fiq_flag;
- if(di_pre_stru.di_wr_buf){
- read_pulldown_info(&(di_pre_stru.di_wr_buf->field_pd_info),
- &(di_pre_stru.di_wr_buf->win_pd_info[0])
- );
- read_mtn_info(di_pre_stru.di_wr_buf->mtn_info,reg_mtn_info);
- if(di_pre_stru.cur_prog_flag){
- if(di_pre_stru.prog_proc_type == 0){
- if((di_pre_stru.process_count>0)
- &&(is_progressive(di_pre_stru.di_mem_buf_dup_p->vframe))){
- // di_mem_buf_dup_p->vframe is from in_list, and it is top field
- di_pre_stru.di_chan2_buf_dup_p = di_pre_stru.di_wr_buf;
- #ifdef DI_DEBUG
- di_print("%s: set di_chan2_buf_dup_p to di_wr_buf\n", __func__);
- #endif
- }
- else{ // di_mem_buf_dup->vfrme is either local vframe, or bot field of vframe from in_list
- di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
- di_pre_stru.di_mem_buf_dup_p = di_pre_stru.di_chan2_buf_dup_p;
- di_pre_stru.di_chan2_buf_dup_p = di_pre_stru.di_wr_buf;
- #ifdef DI_DEBUG
- 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__);
- #endif
- }
- }
- else{
- di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
- di_pre_stru.di_mem_buf_dup_p = di_pre_stru.di_wr_buf;
- #ifdef DI_DEBUG
- di_print("%s: set di_mem_buf_dup_p to di_wr_buf\n", __func__);
- #endif
- }
- di_pre_stru.di_wr_buf->seq = di_pre_stru.pre_ready_seq++;
- di_pre_stru.di_wr_buf->post_ref_count = 0;
- if(di_pre_stru.source_change_flag){
- di_pre_stru.di_wr_buf->new_format_flag = 1;
- di_pre_stru.source_change_flag = 0;
- }
- else{
- di_pre_stru.di_wr_buf->new_format_flag = 0;
- }
- if(bypass_state == 1){
- di_pre_stru.di_wr_buf->new_format_flag = 1;
- bypass_state = 0;
- }
-
- queue_in(di_pre_stru.di_wr_buf, QUEUE_PRE_READY);
- #ifdef DI_DEBUG
- di_print("%s: process_count %d, %s[%d] => pre_ready_list\n",
- __func__, di_pre_stru.process_count, vframe_type_name[di_pre_stru.di_wr_buf->type], di_pre_stru.di_wr_buf->index);
- #endif
- di_pre_stru.di_wr_buf = NULL;
- }
- else{
- di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
- di_pre_stru.di_mem_buf_dup_p = NULL;
- if(di_pre_stru.di_chan2_buf_dup_p){
- di_pre_stru.di_mem_buf_dup_p = di_pre_stru.di_chan2_buf_dup_p;
- #ifdef DI_DEBUG
- di_print("%s: set di_mem_buf_dup_p to di_chan2_buf_dup_p\n", __func__);
- #endif
- }
- di_pre_stru.di_chan2_buf_dup_p = di_pre_stru.di_wr_buf;
- if(di_pre_stru.di_wr_buf->post_proc_flag == 2){
- //add dummy buf, will not be displayed
- if(!queue_empty(QUEUE_LOCAL_FREE)){
- di_buf_t* di_buf_tmp;
- di_buf_tmp = get_di_buf_head(QUEUE_LOCAL_FREE);
- if(di_buf_tmp){
- queue_out(di_buf_tmp);
- di_buf_tmp->pre_ref_count = 0;
- di_buf_tmp->post_ref_count = 0;
- di_buf_tmp->post_proc_flag = 3;
- di_buf_tmp->new_format_flag = 0;
- queue_in(di_buf_tmp, QUEUE_PRE_READY);
- }
- #ifdef DI_DEBUG
- di_print("%s: dummy %s[%d] => pre_ready_list\n",
- __func__, vframe_type_name[di_buf_tmp->type], di_buf_tmp->index);
- #endif
- }
- }
- di_pre_stru.di_wr_buf->seq = di_pre_stru.pre_ready_seq++;
- di_pre_stru.di_wr_buf->post_ref_count = 0;
- if(di_pre_stru.source_change_flag){
- di_pre_stru.di_wr_buf->new_format_flag = 1;
- di_pre_stru.source_change_flag = 0;
- }
- else{
- di_pre_stru.di_wr_buf->new_format_flag = 0;
- }
- if(bypass_state == 1){
- di_pre_stru.di_wr_buf->new_format_flag = 1;
- bypass_state = 0;
- }
-
- queue_in(di_pre_stru.di_wr_buf, QUEUE_PRE_READY);
- #ifdef DI_DEBUG
- di_print("%s: %s[%d] => pre_ready_list\n",
- __func__, vframe_type_name[di_pre_stru.di_wr_buf->type], di_pre_stru.di_wr_buf->index);
- #endif
- di_pre_stru.di_wr_buf = NULL;
- }
- }
- if((di_pre_stru.process_count==0)&&(di_pre_stru.di_inp_buf)){
- #ifdef DI_DEBUG
- di_print("%s: %s[%d] => recycle_list\n",
- __func__, vframe_type_name[di_pre_stru.di_inp_buf->type], di_pre_stru.di_inp_buf->index);
- #endif
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- queue_in(di_pre_stru.di_inp_buf, QUEUE_RECYCLE);
- di_pre_stru.di_inp_buf = NULL;
- raw_local_irq_restore(fiq_flag);
- }
- }
- #if defined(CONFIG_ARCH_MESON2)
- /* add for di Reg re-init */
- static enum vframe_source_type_e vframe_source_type = VFRAME_SOURCE_TYPE_OTHERS;
- static void di_set_para_by_tvinfo(vframe_t* vframe)
- {
- if (vframe->source_type == vframe_source_type)
- return;
- pr_info("%s: tvinfo change, reset di Reg \n", __FUNCTION__);
- vframe_source_type = vframe->source_type;
- /* add for smooth skin */
- if (vframe_source_type != VFRAME_SOURCE_TYPE_OTHERS)
- nr_hfilt_en = 1;
- else
- nr_hfilt_en = 0;
- //if input is pal and ntsc
- if (vframe_source_type != VFRAME_SOURCE_TYPE_TUNER)
- {
- ei_ctrl0 = (255 << 16) | // ei_filter.
- (1 << 8) | // ei_threshold.
- (0 << 2) | // ei bypass cf2.
- (0 << 1); // ei bypass far1
- ei_ctrl1 = (90 << 24) | // ei diff
- (10 << 16) | // ei ang45
- (15 << 8 ) | // ei peak.
- 45; // ei cross.
- ei_ctrl2 = (10 << 24) | // close2
- (10 << 16) | // close1
- (10 << 8 ) | // far2
- 93; // far1
- kdeint2 = 25;
- mtn_ctrl= 0xe228c440;
- #ifdef CONFIG_MACH_MESON2_7366M_REFE03
- if (vframe_source_type == VFRAME_SOURCE_TYPE_COMP)
- blend_ctrl = 0x15f00019;
- else
- #endif
- blend_ctrl=0x1f00019;
- pr_info("%s: tvinfo change, reset di Reg \n", __FUNCTION__);
- }
- else //input is tuner
- {
- ei_ctrl0 = (255 << 16) | // ei_filter.
- (1 << 8) | // ei_threshold.
- (0 << 2) | // ei bypass cf2.
- (0 << 1); // ei bypass far1
- ei_ctrl1 = ( 90 << 24) | // ei diff
- (192 << 16) | // ei ang45
- (15 << 8 ) | // ei peak.
- 128; // ei cross.
- ei_ctrl2 = (10 << 24) | // close2
- (255 << 16) | // close1
- (10 << 8 ) | // far2
- 255; // far1
- if(kdeint1==0x10){
- kdeint2 = 25;
- mtn_ctrl= 0xe228c440 ;
- blend_ctrl=0x1f00019;
- }
- else{
- kdeint2 = 25;
- #ifdef CONFIG_MESON2_CHIP_C
- mtn_ctrl = 0xe228c440;
- blend_ctrl = 0x15f00019;
- mtn_ctrl1_shift = 0x00000055;
- #else
- mtn_ctrl= 0x0 ;
- blend_ctrl=0x19f00019;
- #endif
- pr_info("%s: tvinfo change, reset di Reg in tuner source \n", __FUNCTION__);
- }
- }
- //WRITE_MPEG_REG(DI_EI_CTRL0, ei_ctrl0);
- //WRITE_MPEG_REG(DI_EI_CTRL1, ei_ctrl1);
- //WRITE_MPEG_REG(DI_EI_CTRL2, ei_ctrl2);
- }
- #endif
- static unsigned char pre_de_buf_config(void)
- {
- di_buf_t* di_buf = NULL;
- vframe_t* vframe;
- int i;
- if((queue_empty(QUEUE_IN_FREE)&&(di_pre_stru.process_count==0))||
- queue_empty(QUEUE_LOCAL_FREE)){
- return 0;
- }
- #if 1
- if(is_bypass()){ //some provider has problem if receiver get all buffers of provider
- int in_buf_num = 0;
- for(i=0; i<MAX_IN_BUF_NUM; i++){
- if(vframe_in[i]!=NULL){
- in_buf_num++;
- }
- }
- if(in_buf_num>bypass_get_buf_threshold){
- return 0;
- }
- }
- #endif
- if(di_pre_stru.process_count>0){
- /* previous is progressive top */
- di_pre_stru.process_count = 0;
- }
- else{
- //check if source change
- #ifdef CHECK_VDIN_BUF_ERROR
- #define WR_CANVAS_BIT 0
- #define WR_CANVAS_WID 8
- #ifdef GET_VFRAME_DIRECTLY
- if (prov && prov->ops && prov->ops->peek)
- vframe = prov->ops->peek(prov->op_arg);
- else
- vframe = NULL;
- #else
- vframe = vf_peek(VFM_NAME);
- #endif
- if(vframe&&is_from_vdin(vframe)){
- if(vframe->canvas0Addr == READ_CBUS_REG_BITS((VDIN_WR_CTRL + 0), WR_CANVAS_BIT, WR_CANVAS_WID)){
- same_w_r_canvas_count++;
- }
- }
- #endif
- #ifdef GET_VFRAME_DIRECTLY
- if (prov && prov->ops && prov->ops->get)
- vframe = prov->ops->get(prov->op_arg);
- else
- vframe = NULL;
- #else
- vframe = vf_get(VFM_NAME);
- #endif
- if(vframe == NULL){
- return 0;
- }
- #ifdef DI_DEBUG
- di_print("%s: vf_get => %x\n", __func__, vframe);
- #endif
- provider_vframe_level--;
- di_buf = get_di_buf_head(QUEUE_IN_FREE);
- if((di_buf == NULL)||(di_buf->vframe == NULL)){
- #ifdef DI_DEBUG
- printk("%s: Error\n", __func__);
- #endif
- recovery_flag = 1;
- return 0;
- }
- memcpy(di_buf->vframe, vframe, sizeof(vframe_t));
- di_buf->vframe->private_data = di_buf;
- vframe_in[di_buf->index] = vframe;
- di_buf->seq = di_pre_stru.in_seq;
- di_pre_stru.in_seq++;
- queue_out(di_buf);
- if(is_source_change(vframe)){ /* source change*/
- if(di_pre_stru.di_mem_buf_dup_p){
- di_pre_stru.di_mem_buf_dup_p->pre_ref_count = 0;
- di_pre_stru.di_mem_buf_dup_p = NULL;
- }
- if(di_pre_stru.di_chan2_buf_dup_p){
- di_pre_stru.di_chan2_buf_dup_p->pre_ref_count = 0;
- di_pre_stru.di_chan2_buf_dup_p = NULL;
- }
- #ifdef DI_DEBUG
- di_print("%s: source change: %d/%d/%d=>%d/%d/%d\n", __func__,
- di_pre_stru.cur_inp_type, di_pre_stru.cur_width, di_pre_stru.cur_height,
- di_buf->vframe->type, di_buf->vframe->width, di_buf->vframe->height);
- #endif
- di_pre_stru.cur_width = di_buf->vframe->width;
- di_pre_stru.cur_height= di_buf->vframe->height;
- di_pre_stru.cur_prog_flag = is_progressive(di_buf->vframe);
- di_pre_stru.cur_inp_type = di_buf->vframe->type;
- di_pre_stru.source_change_flag = 1;
- di_pre_stru.same_field_source_flag = 0;
- #if defined(CONFIG_ARCH_MESON2)
- di_set_para_by_tvinfo(vframe);
- #endif
- }
- else{
- /* check if top/bot interleaved */
- if(di_pre_stru.cur_prog_flag == 0){
- if((di_pre_stru.cur_inp_type & VIDTYPE_TYPEMASK) ==
- (di_buf->vframe->type & VIDTYPE_TYPEMASK)){
- #ifdef CHECK_VDIN_BUF_ERROR
- if ((di_buf->vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)
- same_field_top_count++;
- else
- same_field_bot_count++;
- #endif
- if(di_pre_stru.same_field_source_flag<same_field_source_flag_th){
- /*some source's filed is top or bot always*/
- di_pre_stru.same_field_source_flag++;
- if(skip_wrong_field && is_from_vdin(di_buf->vframe)){
- ulong fiq_flag;
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- queue_in(di_buf, QUEUE_RECYCLE);
- raw_local_irq_restore(fiq_flag);
- return 0;
- }
- }
- }
- else{
- di_pre_stru.same_field_source_flag=0;
- }
- }
- di_pre_stru.cur_inp_type = di_buf->vframe->type;
- }
- if(is_bypass()){
- // bypass progressive
- di_buf->seq = di_pre_stru.pre_ready_seq++;
- di_buf->post_ref_count = 0;
- if(di_pre_stru.source_change_flag){
- di_buf->new_format_flag = 1;
- di_pre_stru.source_change_flag = 0;
- }
- else{
- di_buf->new_format_flag = 0;
- }
-
- if(bypass_state == 0){
- di_buf->new_format_flag = 1;
- bypass_state = 1;
- }
-
- queue_in(di_buf, QUEUE_PRE_READY);
- di_buf->post_proc_flag = 0;
- #ifdef DI_DEBUG
- di_print("%s: %s[%d] => pre_ready_list\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
- #endif
- return 0;
- }
- else if(is_progressive(vframe)){
- //n
- di_pre_stru.di_inp_buf = di_buf;
- if(di_pre_stru.prog_proc_type == 0){
- di_pre_stru.process_count = 1;
- }
- else{
- di_pre_stru.process_count = 0;
- }
- #ifdef DI_DEBUG
- di_print("%s: %s[%d] => di_inp_buf, process_count %d\n",
- __func__, vframe_type_name[di_buf->type], di_buf->index, di_pre_stru.process_count);
- #endif
- if(di_pre_stru.di_mem_buf_dup_p == NULL){//use n
- di_pre_stru.di_mem_buf_dup_p = di_buf;
- #ifdef DI_DEBUG
- di_print("%s: set di_mem_buf_dup_p to be di_inp_buf\n", __func__);
- #endif
- }
- }
- else{
- //n
- di_pre_stru.di_inp_buf = di_buf;
- #ifdef DI_DEBUG
- di_print("%s: %s[%d] => di_inp_buf\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
- #endif
- if(di_pre_stru.di_mem_buf_dup_p == NULL){// use n
- di_pre_stru.di_mem_buf_dup_p = di_buf;
- #ifdef DI_DEBUG
- di_print("%s: set di_mem_buf_dup_p to be di_inp_buf\n", __func__);
- #endif
- }
- }
- }
- /* di_wr_buf */
- di_buf= get_di_buf_head(QUEUE_LOCAL_FREE);
- if((di_buf == NULL)||(di_buf->vframe == NULL)){
- #ifdef DI_DEBUG
- printk("%s:Error\n", __func__);
- #endif
- recovery_flag = 1;
- return 0;
- }
-
- queue_out(di_buf);
- di_pre_stru.di_wr_buf = di_buf;
- di_pre_stru.di_wr_buf->pre_ref_count = 1;
- #ifdef DI_DEBUG
- di_print("%s: %s[%d] => di_wr_buf\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
- #endif
- memcpy(di_buf->vframe, di_pre_stru.di_inp_buf->vframe, sizeof(vframe_t));
- di_buf->vframe->private_data = di_buf;
- di_buf->vframe->canvas0Addr = di_buf->nr_canvas_idx;
- di_buf->vframe->canvas1Addr = di_buf->nr_canvas_idx;
- if(di_pre_stru.prog_proc_type){
- di_buf->vframe->type = VIDTYPE_PROGRESSIVE | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
- }
- else{
- if(((di_pre_stru.di_inp_buf->vframe->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)
- ||(di_pre_stru.process_count>0)){
- di_buf->vframe->type = VIDTYPE_INTERLACE_TOP | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
- }
- else{
- di_buf->vframe->type = VIDTYPE_INTERLACE_BOTTOM | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
- }
- }
- /* */
- if(is_progressive(di_pre_stru.di_inp_buf->vframe)){
- di_pre_stru.enable_mtnwr = 0;
- di_pre_stru.enable_pulldown_check = 0;
- di_buf->post_proc_flag = 0;
- }
- else{
- if(di_pre_stru.di_chan2_buf_dup_p == NULL){
- di_pre_stru.enable_mtnwr = 0;
- di_pre_stru.enable_pulldown_check = 0;
- di_buf->post_proc_flag = 2;
- }
- else{
- di_pre_stru.enable_mtnwr = 1;
- di_pre_stru.enable_pulldown_check = 1;
- di_buf->post_proc_flag = 1;
- }
- }
-
- #ifndef USE_LIST
- if((di_pre_stru.di_mem_buf_dup_p == di_pre_stru.di_wr_buf)||
- (di_pre_stru.di_chan2_buf_dup_p == di_pre_stru.di_wr_buf)){
- printk("+++++++++++++++++++++++\n");
- recovery_flag = 1;
- return 0;
- }
- #endif
- return 1;
- }
- static int check_recycle_buf(void)
- {
- di_buf_t *di_buf = NULL, *ptmp;
- int itmp;
- int ret = 0;
- queue_for_each_entry(di_buf, ptmp, QUEUE_RECYCLE, list) {
- if((di_buf->pre_ref_count == 0)&&(di_buf->post_ref_count == 0)){
- if(di_buf->type == VFRAME_TYPE_IN){
- queue_out(di_buf);
- if(vframe_in[di_buf->index]){
- #ifdef GET_VFRAME_DIRECTLY
- if (prov && prov->ops && prov->ops->put)
- prov->ops->put(vframe_in[di_buf->index], prov->op_arg);
- #else
- vf_put(vframe_in[di_buf->index], VFM_NAME);
- #endif
- #ifdef DI_DEBUG
- di_print("%s: vf_put(%d) %x\n", __func__, di_pre_stru.recycle_seq, vframe_in[di_buf->index]);
- #endif
- vframe_in[di_buf->index] = NULL;
- }
- queue_in(di_buf, QUEUE_IN_FREE);
- di_pre_stru.recycle_seq++;
- ret |= 1;
- }
- else{
- queue_out(di_buf);
- queue_in(di_buf, QUEUE_LOCAL_FREE);
- ret |= 2;
- }
- #ifdef DI_DEBUG
- di_print("%s: recycle %s[%d]\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
- #endif
- }
- }
- return ret;
- }
- static irqreturn_t de_irq(int irq, void *dev_instance)
- {
- unsigned int data32;
- data32 = Rd(DI_INTR_CTRL);
- //if ( (data32 & 0xf) != 0x1 ) {
- // printk("%s: error %x\n", __func__, data32);
- //} else {
- Wr(DI_INTR_CTRL, data32);
- //}
- //Wr(A9_0_IRQ_IN1_INTR_STAT_CLR, 1 << 14);
- //Rd(A9_0_IRQ_IN1_INTR_STAT_CLR);
- if(di_pre_stru.pre_de_busy==0){
- di_print("%s: wrong enter %x\n", __func__, Rd(DI_INTR_CTRL));
- return IRQ_HANDLED;
- }
- #ifdef DI_DEBUG
- di_print("%s: start\n", __func__);
- #endif
- di_pre_stru.pre_de_process_done = 1;
- di_pre_stru.pre_de_busy = 0;
- if(init_flag){
- //printk("%s:up di sema\n", __func__);
- trigger_pre_di_process('i');
- }
- #ifdef DI_DEBUG
- di_print("%s: end\n", __func__);
- #endif
- return IRQ_HANDLED;
- }
- /*
- di post process
- */
- static void inc_post_ref_count(di_buf_t* di_buf)
- {
- int post_blend_mode;
-
- if(di_buf == NULL){
- #ifdef DI_DEBUG
- printk("%s: Error\n", __func__);
- #endif
- recovery_flag = 1;
- }
-
- if(di_buf->pulldown_mode == 0)
- post_blend_mode = 0;
- else if(di_buf->pulldown_mode == 1)
- post_blend_mode =1;
- else
- post_blend_mode = 3;
- if(di_buf->di_buf_dup_p[1]){
- di_buf->di_buf_dup_p[1]->post_ref_count++;
- }
- if ( post_blend_mode != 1 ){
- if(di_buf->di_buf_dup_p[0]){
- di_buf->di_buf_dup_p[0]->post_ref_count++;
- }
- }
- if(di_buf->di_buf_dup_p[2]){
- di_buf->di_buf_dup_p[2]->post_ref_count++;
- }
- }
- static void dec_post_ref_count(di_buf_t* di_buf)
- {
- int post_blend_mode;
- if(di_buf == NULL){
- #ifdef DI_DEBUG
- printk("%s: Error\n", __func__);
- #endif
- recovery_flag = 1;
- }
- if(di_buf->pulldown_mode == 0)
- post_blend_mode = 0;
- else if(di_buf->pulldown_mode == 1)
- post_blend_mode =1;
- else
- post_blend_mode = 3;
- if(di_buf->di_buf_dup_p[1]){
- di_buf->di_buf_dup_p[1]->post_ref_count--;
- }
- if ( post_blend_mode != 1 ){
- if(di_buf->di_buf_dup_p[0]){
- di_buf->di_buf_dup_p[0]->post_ref_count--;
- }
- }
- if(di_buf->di_buf_dup_p[2]){
- di_buf->di_buf_dup_p[2]->post_ref_count--;
- }
- }
- static int de_post_disable_fun(void* arg)
- {
- disable_post_deinterlace_2();
- return 1; //called for new_format_flag, make video set video_property_changed
- }
- static int do_nothing_fun(void* arg)
- {
- return 0;
- }
- static int get_vscale_skip_count(unsigned par)
- {
- di_vscale_skip_count = (par >> 24)&0xff;
- }
- static int de_post_process(void* arg, unsigned zoom_start_x_lines,
- unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines)
- {
- di_buf_t* di_buf = (di_buf_t*)arg;
- int di_width, di_height, di_start_x, di_end_x, di_start_y, di_end_y;
- int hold_line = 10;
- int post_blend_en, post_blend_mode;
- get_vscale_skip_count(zoom_start_x_lines);
-
- zoom_start_x_lines = zoom_start_x_lines&0xffff;
- zoom_end_x_lines = zoom_end_x_lines&0xffff;
- zoom_start_y_lines = zoom_start_y_lines&0xffff;
- zoom_end_y_lines = zoom_end_y_lines&0xffff;
-
- if(di_buf->pulldown_mode == 0)
- post_blend_mode = 0;
- else if(di_buf->pulldown_mode == 1)
- post_blend_mode =1;
- else
- post_blend_mode = 3;
- //printk("post_blend_mode %d\n", post_blend_mode);
- if(init_flag == 0){
- return 0;
- }
- di_start_x = zoom_start_x_lines;
- di_end_x = zoom_end_x_lines;
- di_width = di_end_x - di_start_x + 1;
- di_start_y = (zoom_start_y_lines+1) & 0xfffffffe;
- di_end_y = (zoom_end_y_lines-1) | 0x1;
- di_height = di_end_y - di_start_y + 1;
- //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);
- if ( READ_MPEG_REG(DI_POST_SIZE) != ((di_width-1) | ((di_height-1)<<16))
- || (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) )
- {
- initial_di_post_2(di_width, di_height, hold_line);
- di_post_stru.di_buf0_mif.luma_x_start0 = di_start_x;
- di_post_stru.di_buf0_mif.luma_x_end0 = di_end_x;
- di_post_stru.di_buf0_mif.luma_y_start0 = di_start_y/2;
- di_post_stru.di_buf0_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
- di_post_stru.di_buf1_mif.luma_x_start0 = di_start_x;
- di_post_stru.di_buf1_mif.luma_x_end0 = di_end_x;
- di_post_stru.di_buf1_mif.luma_y_start0 = di_start_y/2;
- di_post_stru.di_buf1_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
- di_post_stru.di_mtncrd_mif.start_x = di_start_x;
- di_post_stru.di_mtncrd_mif.end_x = di_end_x;
- di_post_stru.di_mtncrd_mif.start_y = di_start_y/2;
- di_post_stru.di_mtncrd_mif.end_y = (di_end_y + 1)/2 - 1;
- di_post_stru.di_mtnprd_mif.start_x = di_start_x;
- di_post_stru.di_mtnprd_mif.end_x = di_end_x;
- di_post_stru.di_mtnprd_mif.start_y = di_start_y/2;
- di_post_stru.di_mtnprd_mif.end_y = (di_end_y + 1)/2 - 1;
- }
- di_post_stru.di_buf0_mif.canvas0_addr0 = di_buf->di_buf_dup_p[1]->nr_canvas_idx;
- if ( post_blend_mode == 1 )
- di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[2]->nr_canvas_idx;
- else
- di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[0]->nr_canvas_idx;
- di_post_stru.di_mtncrd_mif.canvas_num = di_buf->di_buf_dup_p[1]->mtn_canvas_idx;
- di_post_stru.di_mtnprd_mif.canvas_num = di_buf->di_buf_dup_p[2]->mtn_canvas_idx;
- post_blend_en = 1;
- enable_di_post_2 (
- &di_post_stru.di_buf0_mif,
- &di_post_stru.di_buf1_mif,
- NULL,
- &di_post_stru.di_mtncrd_mif,
- &di_post_stru.di_mtnprd_mif,
- 1, // ei enable
- post_blend_en, // blend enable
- post_blend_en, // blend mtn enable
- post_blend_mode, // blend mode.
- 1, // di_vpp_en.
- 0, // di_ddr_en.
- (di_buf->di_buf_dup_p[1]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_TOP ? 0 : 1, // 1 bottom generate top
- hold_line,
- reg_mtn_info
- );
- return 0;
- }
- static int de_post_process_pd(void* arg, unsigned zoom_start_x_lines,
- unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines)
- {
- di_buf_t* di_buf = (di_buf_t*)arg;
- int di_width, di_height, di_start_x, di_end_x, di_start_y, di_end_y;
- int hold_line = 10;
- int post_blend_mode;
- get_vscale_skip_count(zoom_start_x_lines);
- zoom_start_x_lines = zoom_start_x_lines&0xffff;
- zoom_end_x_lines = zoom_end_x_lines&0xffff;
- zoom_start_y_lines = zoom_start_y_lines&0xffff;
- zoom_end_y_lines = zoom_end_y_lines&0xffff;
- if(di_buf->pulldown_mode == 0)
- post_blend_mode = 0;
- else
- post_blend_mode =1;
- if(init_flag == 0){
- return 0;
- }
- di_start_x = zoom_start_x_lines;
- di_end_x = zoom_end_x_lines;
- di_width = di_end_x - di_start_x + 1;
- di_start_y = (zoom_start_y_lines+1) & 0xfffffffe;
- di_end_y = (zoom_end_y_lines-1) | 0x1;
- di_height = di_end_y - di_start_y + 1;
- //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);
- if ( READ_MPEG_REG(DI_POST_SIZE) != ((di_width-1) | ((di_height-1)<<16))
- || (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) )
- {
- initial_di_post_2(di_width, di_height, hold_line);
- di_post_stru.di_buf0_mif.luma_x_start0 = di_start_x;
- di_post_stru.di_buf0_mif.luma_x_end0 = di_end_x;
- di_post_stru.di_buf0_mif.luma_y_start0 = di_start_y/2;
- di_post_stru.di_buf0_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
- di_post_stru.di_buf1_mif.luma_x_start0 = di_start_x;
- di_post_stru.di_buf1_mif.luma_x_end0 = di_end_x;
- di_post_stru.di_buf1_mif.luma_y_start0 = di_start_y/2;
- di_post_stru.di_buf1_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
- di_post_stru.di_mtncrd_mif.start_x = di_start_x;
- di_post_stru.di_mtncrd_mif.end_x = di_end_x;
- di_post_stru.di_mtncrd_mif.start_y = di_start_y/2;
- di_post_stru.di_mtncrd_mif.end_y = (di_end_y + 1)/2 - 1;
- di_post_stru.di_mtnprd_mif.start_x = di_start_x;
- di_post_stru.di_mtnprd_mif.end_x = di_end_x;
- di_post_stru.di_mtnprd_mif.start_y = di_start_y/2;
- di_post_stru.di_mtnprd_mif.end_y = (di_end_y + 1)/2 - 1;
- }
- di_post_stru.di_buf0_mif.canvas0_addr0 = di_buf->di_buf_dup_p[1]->nr_canvas_idx;
- if ( post_blend_mode == 1 )
- di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[2]->nr_canvas_idx;
- else
- di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[0]->nr_canvas_idx;
- di_post_stru.di_mtncrd_mif.canvas_num = di_buf->di_buf_dup_p[1]->mtn_canvas_idx;
- di_post_stru.di_mtnprd_mif.canvas_num = di_buf->di_buf_dup_p[2]->mtn_canvas_idx;
- enable_di_post_pd (
- &di_post_stru.di_buf0_mif,
- &di_post_stru.di_buf1_mif,
- NULL,
- &di_post_stru.di_mtncrd_mif,
- &di_post_stru.di_mtnprd_mif,
- 1, // ei enable
- 1, // blend enable
- 1, // blend mtn enable
- post_blend_mode, // blend mode.
- 1, // di_vpp_en.
- 0, // di_ddr_en.
- (di_buf->di_buf_dup_p[1]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_TOP ? 0 : 1, // 1 bottom generate top
- hold_line
- );
- return 0;
- }
- static int de_post_process_prog(void* arg, unsigned zoom_start_x_lines,
- unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines)
- {
- di_buf_t* di_buf = (di_buf_t*)arg;
- int di_width, di_height, di_start_x, di_end_x, di_start_y, di_end_y;
- int hold_line = 10;
- int post_blend_mode;
- get_vscale_skip_count(zoom_start_x_lines);
- zoom_start_x_lines = zoom_start_x_lines&0xffff;
- zoom_end_x_lines = zoom_end_x_lines&0xffff;
- zoom_start_y_lines = zoom_start_y_lines&0xffff;
- zoom_end_y_lines = zoom_end_y_lines&0xffff;
- post_blend_mode =1;
- if(init_flag == 0){
- return 0;
- }
- di_start_x = zoom_start_x_lines;
- di_end_x = zoom_end_x_lines;
- di_width = di_end_x - di_start_x + 1;
- di_start_y = (zoom_start_y_lines+1) & 0xfffffffe;
- di_end_y = (zoom_end_y_lines-1) | 0x1;
- di_height = di_end_y - di_start_y + 1;
- //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);
- if ( READ_MPEG_REG(DI_POST_SIZE) != ((di_width-1) | ((di_height-1)<<16))
- || (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) )
- {
- initial_di_post_2(di_width, di_height, hold_line);
- di_post_stru.di_buf0_mif.luma_x_start0 = di_start_x;
- di_post_stru.di_buf0_mif.luma_x_end0 = di_end_x;
- di_post_stru.di_buf0_mif.luma_y_start0 = di_start_y/2;
- di_post_stru.di_buf0_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
- di_post_stru.di_buf1_mif.luma_x_start0 = di_start_x;
- di_post_stru.di_buf1_mif.luma_x_end0 = di_end_x;
- di_post_stru.di_buf1_mif.luma_y_start0 = di_start_y/2;
- di_post_stru.di_buf1_mif.luma_y_end0 = (di_end_y + 1)/2 - 1;
- di_post_stru.di_mtncrd_mif.start_x = di_start_x;
- di_post_stru.di_mtncrd_mif.end_x = di_end_x;
- di_post_stru.di_mtncrd_mif.start_y = di_start_y/2;
- di_post_stru.di_mtncrd_mif.end_y = (di_end_y + 1)/2 - 1;
- di_post_stru.di_mtnprd_mif.start_x = di_start_x;
- di_post_stru.di_mtnprd_mif.end_x = di_end_x;
- di_post_stru.di_mtnprd_mif.start_y = di_start_y/2;
- di_post_stru.di_mtnprd_mif.end_y = (di_end_y + 1)/2 - 1;
- }
- di_post_stru.di_buf0_mif.canvas0_addr0 = di_buf->di_buf_dup_p[0]->nr_canvas_idx;
- di_post_stru.di_buf1_mif.canvas0_addr0 = di_buf->di_buf_dup_p[1]->nr_canvas_idx;
- di_post_stru.di_mtncrd_mif.canvas_num = di_buf->di_buf_dup_p[0]->mtn_canvas_idx;
- di_post_stru.di_mtnprd_mif.canvas_num = di_buf->di_buf_dup_p[1]->mtn_canvas_idx;
- enable_di_post_pd (
- &di_post_stru.di_buf0_mif,
- &di_post_stru.di_buf1_mif,
- NULL,
- &di_post_stru.di_mtncrd_mif,
- &di_post_stru.di_mtnprd_mif,
- 1, // ei enable
- 1, // blend enable
- 1, // blend mtn enable
- post_blend_mode, // blend mode.
- 1, // di_vpp_en.
- 0, // di_ddr_en.
- (di_buf->di_buf_dup_p[0]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_TOP ? 0 : 1, // 1 bottom generate top
- hold_line
- );
- return 0;
- }
- #ifdef FORCE_BOB_SUPPORT
- static int de_post_process_force_bob(void* arg, unsigned zoom_start_x_lines,
- unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines)
- {
- de_post_process(arg, zoom_start_x_lines, zoom_end_x_lines, zoom_start_y_lines, zoom_end_y_lines);
- WRITE_MPEG_REG(DI_BLEND_CTRL, READ_MPEG_REG(DI_BLEND_CTRL)&0xffefffff);
- return 0;
- }
- #endif
- int pd_detect_rst ;
- static void recycle_vframe_type_post(di_buf_t* di_buf)
- {
- int i;
- if(di_buf == NULL){
- #ifdef DI_DEBUG
- printk("%s:Error\n", __func__);
- #endif
- recovery_flag = 1;
- return;
- }
- if( di_buf->vframe->process_fun == de_post_process_pd
- || di_buf->vframe->process_fun == de_post_process
- #ifdef FORCE_BOB_SUPPORT
- || di_buf->vframe->process_fun == de_post_process_force_bob
- #endif
- ){
- dec_post_ref_count(di_buf);
- }
- for(i=0;i<2;i++){
- if(di_buf->di_buf[i])
- queue_in(di_buf->di_buf[i], QUEUE_RECYCLE);
- }
- queue_out(di_buf); //remove it from display_list_head
- queue_in(di_buf, QUEUE_POST_FREE);
- }
- #ifdef DI_DEBUG
- static void recycle_vframe_type_post_print(di_buf_t* di_buf, const char* func)
- {
- int i;
- di_print("%s:", func);
- for(i=0;i<2;i++){
- if(di_buf->di_buf[i]){
- di_print("%s[%d]<%d>=>recycle_list; ", vframe_type_name[di_buf->di_buf[i]->type], di_buf->di_buf[i]->index, i);
- }
- }
- di_print("%s[%d] =>post_free_list\n", vframe_type_name[di_buf->type], di_buf->index);
- }
- #endif
- static int process_post_vframe(void)
- {
- /*
- 1) get buf from post_free_list, config it according to buf in pre_ready_list, send it to post_ready_list
- (it will be send to post_free_list in di_vf_put())
- 2) get buf from pre_ready_list, attach it to buf from post_free_list
- (it will be send to recycle_list in di_vf_put() )
- */
- ulong fiq_flag;
- int i,pulldown_mode_hise;
- int ret = 0;
- int buffer_keep_count = 3;
- di_buf_t* di_buf = NULL;
- di_buf_t *ready_di_buf;
- di_buf_t *p = NULL, *ptmp;
- int itmp;
- int ready_count = list_count(QUEUE_PRE_READY);
- if(queue_empty(QUEUE_POST_FREE)){
- return 0;
- }
- if(ready_count>0){
- ready_di_buf = get_di_buf_head(QUEUE_PRE_READY);
- if((ready_di_buf == NULL)||(ready_di_buf->vframe == NULL)){
- #ifdef DI_DEBUG
- printk("%s:Error1\n", __func__);
- #endif
- recovery_flag = 1;
- return 0;
- }
- if(ready_di_buf->post_proc_flag){
- /*if((pulldown_buffer_mode&1)
- &&(real_buf_mgr_mode==0)){
- buffer_keep_count = 4;
- }
- else{
- buffer_keep_count = 3;
- }*/
- if(ready_count>=buffer_keep_count){
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- di_buf = get_di_buf_head(QUEUE_POST_FREE);
- if((di_buf == NULL)||(di_buf->vframe == NULL)){
- #ifdef DI_DEBUG
- printk("%s:Error2\n", __func__);
- #endif
- raw_local_irq_restore(fiq_flag);
- recovery_flag = 1;
- return 0;
- }
- queue_out(di_buf);
- raw_local_irq_restore(fiq_flag);
- i = 0;
- queue_for_each_entry(p, ptmp, QUEUE_PRE_READY, list) {
- di_buf->di_buf_dup_p[i++] = p;
- if(i>=buffer_keep_count)
- break;
- }
- if(i<buffer_keep_count){
- #ifdef DI_DEBUG
- printk("%s:Error3\n", __func__);
- #endif
- recovery_flag = 1;
- return 0;
- }
- memcpy(di_buf->vframe, di_buf->di_buf_dup_p[1]->vframe, sizeof(vframe_t));
- di_buf->vframe->private_data = di_buf;
- if(di_buf->di_buf_dup_p[1]->post_proc_flag == 3){//dummy, not for display
- di_buf->di_buf[0] = di_buf->di_buf_dup_p[0];
- di_buf->di_buf[1] = NULL;
- queue_out(di_buf->di_buf[0]);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- queue_in(di_buf, QUEUE_TMP);
- recycle_vframe_type_post(di_buf);
- raw_local_irq_restore(fiq_flag);
- #ifdef DI_DEBUG
- di_print("%s <dummy>: ", __func__);
- #endif
- }
- else{
- if(di_buf->di_buf_dup_p[1]->post_proc_flag == 2){
- reset_pulldown_state();
- di_buf->pulldown_mode = 1; /* blend with di_buf->di_buf_dup_p[2] */
- }
- else{
- int pulldown_type=-1; /* 0, 2:2; 1, m:n */
- int win_pd_type[5] = {-1,-1,-1,-1,-1};
- int ii;
- int pulldown_mode2;
- insert_pd_his(&di_buf->di_buf_dup_p[1]->field_pd_info);
- if(buffer_keep_count==4){
- //4 buffers
- 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]
- pattern_check_pre_2(0, &di_buf->di_buf_dup_p[3]->field_pd_info,
- &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[2]->pulldown_mode,
- &di_buf->di_buf_dup_p[1]->pulldown_mode,
- &pulldown_type, &field_pd_th
- );
- for(ii=0;ii<MAX_WIN_NUM; ii++){
- 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]
- pattern_check_pre_2(ii+1, &di_buf->di_buf_dup_p[3]->win_pd_info[ii],
- &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[2]->win_pd_mode[ii]),
- &(di_buf->di_buf_dup_p[1]->win_pd_mode[ii]),
- &(win_pd_type[ii]), &win_pd_th[ii]
- );
- }
- }
- else{
- //3 buffers
- 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]
- pattern_check_pre_2(0, &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[0]->field_pd_info,
- &di_buf->di_buf_dup_p[1]->pulldown_mode,
- NULL, &pulldown_type, &field_pd_th);
- for(ii=0;ii<MAX_WIN_NUM; ii++){
- 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]
- pattern_check_pre_2(ii+1, &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[0]->win_pd_info[ii],
- &(di_buf->di_buf_dup_p[1]->win_pd_mode[ii]),
- NULL,&(win_pd_type[ii]), &win_pd_th[ii]
- );
- }
- }
- pulldown_mode_hise = pulldown_mode2 = detect_pd32();
- if(di_log_flag&DI_LOG_PULLDOWN)
- {
- di_buf_t* dp = di_buf->di_buf_dup_p[1];
- di_print("%02d (%x%x%x) %08x %06x %08x %06x %02x %02x %02x %02x %02x %02x %02x %02x ", dp->seq%100,
- dp->pulldown_mode<0?0xf:dp->pulldown_mode, pulldown_type<0?0xf:pulldown_type,
- pulldown_mode2<0?0xf:pulldown_mode2,
- dp->field_pd_info.frame_diff, dp->field_pd_info.frame_diff_num,
- dp->field_pd_info.field_diff, dp->field_pd_info.field_diff_num,
- dp->field_pd_info.frame_diff_by_pre, dp->field_pd_info.frame_diff_num_by_pre,
- dp->field_pd_info.field_diff_by_pre, dp->field_pd_info.field_diff_num_by_pre,
- dp->field_pd_info.field_diff_by_next, dp->field_pd_info.field_diff_num_by_next,
- dp->field_pd_info.frame_diff_skew_ratio, dp->field_pd_info.frame_diff_num_skew_ratio);
- for(ii=0; ii<MAX_WIN_NUM; ii++){
- 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],
- win_pd_type[ii]<0?0xf:win_pd_type[ii],
- dp->win_pd_info[ii].frame_diff, dp->win_pd_info[ii].frame_diff_num,
- dp->win_pd_info[ii].field_diff, dp->win_pd_info[ii].field_diff_num,
- dp->win_pd_info[ii].frame_diff_by_pre, dp->win_pd_info[ii].frame_diff_num_by_pre,
- dp->win_pd_info[ii].field_diff_by_pre, dp->win_pd_info[ii].field_diff_num_by_pre,
- dp->win_pd_info[ii].field_diff_by_next, dp->win_pd_info[ii].field_diff_num_by_next,
- dp->win_pd_info[ii].frame_diff_skew_ratio, dp->win_pd_info[ii].frame_diff_num_skew_ratio);
- }
- di_print("\n");
- }
- di_buf->pulldown_mode = -1;
- if(pulldown_detect){
- if(pulldown_detect&0x1){
- di_buf->pulldown_mode = di_buf->di_buf_dup_p[1]->pulldown_mode; //used by de_post_process
- }
- if(pulldown_detect&0x10){
- if((pulldown_mode2 >=0) && (pd_detect_rst > 15)){
- di_buf->pulldown_mode = pulldown_mode2;
- }
- }
- if(pd_detect_rst <= 32)
- pd_detect_rst ++;
- if((pulldown_win_mode&0xfffff)!=0){
- int ii;
- unsigned mode;
- for(ii=0; ii<5; ii++){
- mode = (pulldown_win_mode>>(ii*4))&0xf;
- if(mode==1){
- if(di_buf->di_buf_dup_p[1]->pulldown_mode == 0){
- if((di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num*win_pd_th[ii].field_diff_num_th) >=
- pd_win_prop[ii].pixels_num){
- break;
- }
- }
- else{
- if((di_buf->di_buf_dup_p[2]->win_pd_info[ii].field_diff_num*win_pd_th[ii].field_diff_num_th) >=
- pd_win_prop[ii].pixels_num){
- break;
- }
- }
- if ((ii!= 0) &&
- (ii!= 5) &&
- (ii!= 4) &&
- (pulldown_mode2 == 1) &&
- (((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) &&
- ((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) &&
- ((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)
- )
- )
- {
- di_print("out %x %06x %06x \n",
- ii,
- di_buf->di_buf_dup_p[2]->win_pd_info[ii].field_diff_num,
- di_buf->di_buf_dup_p[1]->win_pd_info[ii].field_diff_num);
- pd_detect_rst =0;
- break;
- }
- if ((ii!= 0) &&
- (ii!= 5) &&
- (ii!= 4) &&
- (pulldown_mode2 == 0) &&
- ((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) &&
- ((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)
- )
- {
- pd_detect_rst =0;
- break;
- }
- }
- else if(mode==2){
- if( (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]->field_pd_info.field_diff_num_pattern )
- ){
- break;
- }
- if( (pulldown_type == 1) &&
- (di_buf->di_buf_dup_p[1]->win_pd_info[ii].frame_diff_num_pattern
- != di_buf->di_buf_dup_p[1]->field_pd_info.frame_diff_num_pattern )
- ){
- break;
- }
- }
- else if(mode==3){
- if((di_buf->di_buf_dup_p[1]->win_pd_mode[ii]!= di_buf->di_buf_dup_p[1]->pulldown_mode)
- ||(pulldown_type!=win_pd_type[ii])){
- break;
- }
- }
- }
- if(ii<5){
- di_buf->pulldown_mode = -1;
- if(mode==1){
- // printk("Deinterlace pulldown %s, win%d pd field_diff_num %08x/%08x is too big\n",
- // (pulldown_type==0)?"2:2":"3:2", ii, pd_win_prop[ii].pixels_num,
- // (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
- // );
- }
- else if(mode==2){
- // printk("Deinterlace pulldown %s, win%d pd pattern %08x is different from field pd pattern %08x\n",
- // (pulldown_type==0)?"2:2":"3:2", ii,
- // (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,
- // (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
- // );
- }
- else{
- // printk("Deinterlace pulldown, win%d pd type (%d, %d) is different from field pd type (%d, %d)\n",
- // ii, di_buf->di_buf_dup_p[1]->win_pd_mode[ii], win_pd_type[ii],
- // di_buf->di_buf_dup_p[1]->pulldown_mode, pulldown_type);
- }
- }
- }
- /*
- if(di_buf->pulldown_mode>=0)
- printk("%s pulldown\n", (pulldown_type==0)?"2:2":"m:n");
- if((di_buf->vframe->tvin_sig_fmt == TVIN_SIG_FMT_CVBS_PAL_I)
- && (pulldown_type == 1)){
- //m:n not do
- di_buf->pulldown_mode = -1;
- printk("m:n ignore\n");
- }
- if((di_buf->vframe->tvin_sig_fmt == TVIN_SIG_FMT_CVBS_NTSC_M)
- && (pulldown_type == 0)){
- //2:2 not do
- di_buf->pulldown_mode = -1;
- printk("2:2 ignore\n");
- }
- */
- if(di_buf->pulldown_mode != -1){
- pulldown_count++;
- }
- #if defined(CONFIG_ARCH_MESON2)
- if(di_buf->vframe->source_type == VFRAME_SOURCE_TYPE_TUNER) {
- di_buf->pulldown_mode = -1;
- //printk("2:2 ignore\n");
- }
- #endif
- }
- }
- #ifdef FORCE_BOB_SUPPORT
- /*added for hisense*/
- if(pd_enable){
- if(pulldown_mode_hise == 2)
- force_bob_flag = 1;
- else
- force_bob_flag = 0;
- }
- if(force_bob_flag!=0){
- di_buf->vframe->type = VIDTYPE_PROGRESSIVE| VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
- if((force_bob_flag==1)||(force_bob_flag==2)){
- di_buf->vframe->duration<<=1;
- }
- di_buf->vframe->private_data = di_buf;
- if(di_buf->di_buf_dup_p[1]->new_format_flag){ //if(di_buf->di_buf_dup_p[1]->post_proc_flag == 2){
- di_buf->vframe->early_process_fun = de_post_disable_fun;
- }
- else{
- di_buf->vframe->early_process_fun = do_nothing_fun;
- }
- di_buf->vframe->process_fun = de_post_process_force_bob;
- inc_post_ref_count(di_buf);
- di_buf->di_buf[0] = di_buf->di_buf_dup_p[0];
- di_buf->di_buf[1] = NULL;
- queue_out(di_buf->di_buf[0]);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- if((frame_count<start_frame_drop_count)||
- (((di_buf->di_buf_dup_p[1]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_TOP)
- && ((force_bob_flag&1)==0))||
- (((di_buf->di_buf_dup_p[1]->vframe->type & VIDTYPE_TYPEMASK)==VIDTYPE_INTERLACE_BOTTOM)
- && ((force_bob_flag&2)==0))){
-
- queue_in(di_buf, QUEUE_TMP);
- recycle_vframe_type_post(di_buf);
- #ifdef DI_DEBUG
- recycle_vframe_type_post_print(di_buf, __func__);
- #endif
- }
- else{
- queue_in(di_buf, QUEUE_POST_READY);
- }
- frame_count++;
- raw_local_irq_restore(fiq_flag);
- }
- else{
- #endif
- di_buf->vframe->type = VIDTYPE_PROGRESSIVE| VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
- if(di_buf->di_buf_dup_p[1]->new_format_flag){ //if(di_buf->di_buf_dup_p[1]->post_proc_flag == 2){
- di_buf->vframe->early_process_fun = de_post_disable_fun;
- }
- else{
- di_buf->vframe->early_process_fun = do_nothing_fun;
- }
- if(di_buf->pulldown_mode >= 0){
- di_buf->vframe->process_fun = de_post_process_pd;
- inc_post_ref_count(di_buf);
- }
- else{
- di_buf->vframe->process_fun = de_post_process;
- inc_post_ref_count(di_buf);
- }
- di_buf->di_buf[0] = di_buf->di_buf_dup_p[0];
- di_buf->di_buf[1] = NULL;
- queue_out(di_buf->di_buf[0]);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- if(frame_count<start_frame_drop_count){
- queue_in(di_buf, QUEUE_TMP);
- recycle_vframe_type_post(di_buf);
- #ifdef DI_DEBUG
- recycle_vframe_type_post_print(di_buf, __func__);
- #endif
- }
- else{
- queue_in(di_buf, QUEUE_POST_READY);
- }
- frame_count++;
- raw_local_irq_restore(fiq_flag);
- #ifdef FORCE_BOB_SUPPORT
- }
- #endif
- #ifdef DI_DEBUG
- di_print("%s <interlace>: ", __func__);
- #endif
- }
- ret = 1;
- }
- }
- else{
- if(is_progressive(ready_di_buf->vframe)||
- ready_di_buf->type == VFRAME_TYPE_IN){
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- di_buf = get_di_buf_head(QUEUE_POST_FREE);
- if((di_buf == NULL)||(di_buf->vframe == NULL)){
- #ifdef DI_DEBUG
- printk("%s:Error4\n", __func__);
- #endif
- raw_local_irq_restore(fiq_flag);
- recovery_flag = 1;
- return 0;
- }
- queue_out(di_buf);
- raw_local_irq_restore(fiq_flag);
- memcpy(di_buf->vframe, ready_di_buf->vframe, sizeof(vframe_t));
- di_buf->vframe->private_data = di_buf;
- if(frame_packing_mode == 1){
- #if defined(CONFIG_ARCH_MESON2)
- if(di_buf->vframe->trans_fmt == TVIN_TFMT_3D_FP){
- if(di_buf->vframe->height == 2205){
- di_buf->vframe->height = 1080;
- }
- if(di_buf->vframe->height == 1470){
- di_buf->vframe->height = 720;
- }
- }
- #endif
- }
- else{
- if(di_buf->vframe->height > 2000){ //work around hw problem
- di_buf->vframe->height = 2000;
- }
- }
- if(ready_di_buf->new_format_flag){
- di_buf->vframe->early_process_fun = de_post_disable_fun;
- }
- else{
- di_buf->vframe->early_process_fun = do_nothing_fun;
- }
- di_buf->vframe->process_fun = NULL;
- di_buf->di_buf[0] = ready_di_buf;
- di_buf->di_buf[1] = NULL;
- queue_out(ready_di_buf);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- if(frame_count<start_frame_drop_count){
- queue_in(di_buf, QUEUE_TMP);
- recycle_vframe_type_post(di_buf);
- #ifdef DI_DEBUG
- recycle_vframe_type_post_print(di_buf, __func__);
- #endif
- }
- else{
- queue_in(di_buf, QUEUE_POST_READY);
- }
- frame_count++;
- raw_local_irq_restore(fiq_flag);
- #ifdef DI_DEBUG
- di_print("%s <prog by frame>: ", __func__);
- #endif
- ret = 1;
- }
- else if(ready_count>=2){
- unsigned char prog_tb_field_proc_type = (prog_proc_config>>1)&0x3;
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- di_buf = get_di_buf_head(QUEUE_POST_FREE);
- if((di_buf == NULL)||(di_buf->vframe==NULL)){
- #ifdef DI_DEBUG
- printk("%s:Error5\n", __func__);
- #endif
- raw_local_irq_restore(fiq_flag);
- recovery_flag = 1;
- return 0;
- }
- queue_out(di_buf);
- raw_local_irq_restore(fiq_flag);
- i = 0;
- queue_for_each_entry(p, ptmp, QUEUE_PRE_READY, list) {
- di_buf->di_buf_dup_p[i++] = p;
- if(i>=2)
- break;
- }
- if(i<2){
- #ifdef DI_DEBUG
- printk("%s:Error6\n", __func__);
- #endif
- recovery_flag = 1;
- return 0;
- }
- memcpy(di_buf->vframe, di_buf->di_buf_dup_p[0]->vframe, sizeof(vframe_t));
- di_buf->vframe->private_data = di_buf;
- if((prog_tb_field_proc_type == 1)||((real_buf_mgr_mode&1)==1)){
- di_buf->vframe->type = VIDTYPE_PROGRESSIVE| VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
- if(di_buf->di_buf_dup_p[0]->new_format_flag){
- di_buf->vframe->early_process_fun = de_post_disable_fun;
- }
- else{
- di_buf->vframe->early_process_fun = do_nothing_fun;
- }
- di_buf->vframe->process_fun = de_post_process_prog;
- }
- else if(prog_tb_field_proc_type == 0){
- //do weave by vpp
- 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
- if((di_buf->di_buf_dup_p[0]->new_format_flag)
- ||(READ_MPEG_REG(DI_IF1_GEN_REG)&1)){
- di_buf->vframe->early_process_fun = de_post_disable_fun;
- }
- else{
- di_buf->vframe->early_process_fun = do_nothing_fun;
- }
- di_buf->vframe->process_fun = NULL;
- di_buf->vframe->canvas0Addr = di_buf->di_buf_dup_p[0]->nr_canvas_idx; //top
- di_buf->vframe->canvas1Addr = di_buf->di_buf_dup_p[1]->nr_canvas_idx; //bot
- }
- else{
- di_buf->vframe->type = VIDTYPE_PROGRESSIVE | VIDTYPE_VIU_422 | VIDTYPE_VIU_SINGLE_PLANE | VIDTYPE_VIU_FIELD;
- di_buf->vframe->height >>= 1;
- if((di_buf->di_buf_dup_p[0]->new_format_flag)
- ||(READ_MPEG_REG(DI_IF1_GEN_REG)&1)){
- di_buf->vframe->early_process_fun = de_post_disable_fun;
- }
- else{
- di_buf->vframe->early_process_fun = do_nothing_fun;
- }
- if(prog_tb_field_proc_type == 2){
- di_buf->vframe->canvas0Addr = di_buf->di_buf_dup_p[0]->nr_canvas_idx; //top
- di_buf->vframe->canvas1Addr = di_buf->di_buf_dup_p[0]->nr_canvas_idx;
- }
- else{
- di_buf->vframe->canvas0Addr = di_buf->di_buf_dup_p[1]->nr_canvas_idx; //top
- di_buf->vframe->canvas1Addr = di_buf->di_buf_dup_p[1]->nr_canvas_idx;
- }
- }
- di_buf->di_buf[0] = di_buf->di_buf_dup_p[0];
- di_buf->di_buf[1] = di_buf->di_buf_dup_p[1];
- queue_out(di_buf->di_buf[0]);
- queue_out(di_buf->di_buf[1]);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- if(frame_count<start_frame_drop_count){
- queue_in(di_buf, QUEUE_TMP);
- recycle_vframe_type_post(di_buf);
- #ifdef DI_DEBUG
- recycle_vframe_type_post_print(di_buf, __func__);
- #endif
- }
- else{
- queue_in(di_buf, QUEUE_POST_READY);
- }
- frame_count++;
- raw_local_irq_restore(fiq_flag);
- #ifdef DI_DEBUG
- di_print("%s <prog by field>: ", __func__);
- #endif
- ret = 1;
- }
- }
- #ifdef DI_DEBUG
- if(di_buf){
- di_print("%s[%d](", vframe_type_name[di_buf->type], di_buf->index);
- for(i=0; i< 2; i++){
- if(di_buf->di_buf[i])
- di_print("%s[%d],",vframe_type_name[di_buf->di_buf[i]->type], di_buf->di_buf[i]->index);
- }
- di_print(")(vframe type %x dur %d)", di_buf->vframe->type, di_buf->vframe->duration);
- if(di_buf->di_buf_dup_p[1]&&(di_buf->di_buf_dup_p[1]->post_proc_flag == 3)){
- di_print("=> recycle_list\n");
- }
- else{
- di_print("=> post_ready_list\n");
- }
- }
- #endif
- }
- return ret;
- }
- /*
- di task
- */
- static void di_process(void)
- {
- ulong flags;
- ulong fiq_flag;
- vframe_t * vframe;
- /* add for di Reg re-init */
- //di_set_para_by_tvinfo(vframe);
- if((di_pre_stru.unreg_req_flag||di_pre_stru.force_unreg_req_flag||di_pre_stru.disable_req_flag)&&
- (di_pre_stru.pre_de_busy==0)){
- //printk("===unreg_req_flag\n");
- if(di_pre_stru.force_unreg_req_flag||di_pre_stru.disable_req_flag){
- #ifdef DI_DEBUG
- di_print("%s: force_unreg\n", __func__);
- #endif
- printk("%s: force_unreg\n", __func__);
- if(bypass_state == 0){
- vf_notify_receiver(VFM_NAME,VFRAME_EVENT_PROVIDER_FORCE_BLACKOUT,NULL);
- }
- goto unreg;
- }
- else if(((real_buf_mgr_mode&1)==1)&&(is_bypass()==0)&&(recovery_flag==0)){
- if(init_flag){
- #ifdef DI_DEBUG
- di_print("%s: di_clean_in_buf\n", __func__);
- #endif
- spin_lock_irqsave(&plist_lock, flags);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
-
- di_clean_in_buf();
- raw_local_irq_restore(fiq_flag);
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- }
- else{
- unreg:
- init_flag = 0;
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- if(bypass_state == 0){
- DisableVideoLayer();
- }
-
- vf_unreg_provider(&di_vf_prov);
- raw_local_irq_restore(fiq_flag);
- spin_lock_irqsave(&plist_lock, flags);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- #ifdef DI_DEBUG
- di_print("%s: di_uninit_buf\n", __func__);
- #endif
- di_uninit_buf();
- raw_local_irq_restore(fiq_flag);
- spin_unlock_irqrestore(&plist_lock, flags);
-
- di_pre_stru.force_unreg_req_flag = 0;
- di_pre_stru.disable_req_flag = 0;
- recovery_flag = 0;
- }
- di_pre_stru.unreg_req_flag = 0;
- }
- if(init_flag == 0){
- #ifdef GET_VFRAME_DIRECTLY
- if (prov && prov->ops && prov->ops->peek)
- vframe = prov->ops->peek(prov->op_arg);
- else
- vframe = NULL;
- #else
- vframe = vf_peek(VFM_NAME);
- #endif
- if(vframe){
- /* add for di Reg re-init */
- #if defined(CONFIG_ARCH_MESON2)
- di_set_para_by_tvinfo(vframe);
- #endif
- if(di_printk_flag&2){
- di_printk_flag=1;
- }
- #ifdef DI_DEBUG
- di_print("%s: vframe come => di_init_buf\n", __func__);
- #endif
- if(is_progressive(vframe)&&is_from_vdin(vframe)&&(prog_proc_config&0x1)&&((real_buf_mgr_mode&1)==0)){
- spin_lock_irqsave(&plist_lock, flags);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- di_init_buf(vframe->width, vframe->height, 1);
- raw_local_irq_restore(fiq_flag);
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- else{
- spin_lock_irqsave(&plist_lock, flags);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- di_init_buf(default_width, default_height, 0);
- raw_local_irq_restore(fiq_flag);
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- vf_provider_init(&di_vf_prov, VFM_NAME, &deinterlace_vf_provider, NULL);
- vf_reg_provider(&di_vf_prov);
- reset_pulldown_state();
- init_flag = 1;
- }
- }
- else{
- #if 1
- //for vdin, need re-init buffers
- if(((real_buf_mgr_mode&1)==1)&&(is_bypass()==0)){
- }
- else{
- #ifdef GET_VFRAME_DIRECTLY
- if (prov && prov->ops && prov->ops->peek)
- vframe = prov->ops->peek(prov->op_arg);
- else
- vframe = NULL;
- #else
- vframe = vf_peek(VFM_NAME);
- #endif
- if(vframe &&
- is_source_change(vframe)
- &&is_from_vdin(vframe)){
- printk("===source_change\n");
- spin_lock_irqsave(&plist_lock, flags);
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- vf_unreg_provider(&di_vf_prov);
- #ifdef DI_DEBUG
- di_print("%s: di_uninit_buf 2\n", __func__);
- #endif
- di_uninit_buf();
- if(is_progressive(vframe)&&is_from_vdin(vframe)&&(prog_proc_config&0x1)&&((real_buf_mgr_mode&1)==0)){
- di_init_buf(vframe->width, vframe->height, 1);
- }
- else{
- di_init_buf(default_width, default_height, 0);
- }
- /* add for di Reg re-init */
- //di_set_para_by_tvinfo(vframe);
- vf_reg_provider(&di_vf_prov);
- raw_local_irq_restore(fiq_flag);
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- }
- #endif
- }
- if((init_flag)&&(recovery_flag == 0)){
- spin_lock_irqsave(&plist_lock, flags);
- if(di_pre_stru.pre_de_process_done){
- pre_de_done_buf_config();
- WRITE_MPEG_REG(DI_PRE_CTRL, 0x3 << 30); //disable, and reset
- di_pre_stru.pre_de_process_done = 0;
- #if 1
- //for debug
- if(di_pre_stru.process_count==0){
- if(prog_proc_config&0x10){
- if(prog_proc_config&0x1){
- di_pre_stru.prog_proc_type = 1;
- }
- else{
- di_pre_stru.prog_proc_type = 0;
- }
- prog_proc_config &= (~0x10);
- }
- }
- #endif
- }
- raw_local_save_flags(fiq_flag);
- local_fiq_disable();
- while(check_recycle_buf()&1){};
- raw_local_irq_restore(fiq_flag);
- if((di_pre_stru.pre_de_busy==0) && pre_de_buf_config()){
- pre_de_process();
- }
- while(process_post_vframe()){};
- #ifdef GET_VFRAME_DIRECTLY
- put_get_disp_buf();
- #endif
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- }
- void di_timer_handle(struct work_struct *work)
- {
- if(di_pre_stru.pre_de_busy){
- di_pre_stru.pre_de_busy_timer_count++;
- if(di_pre_stru.pre_de_busy_timer_count>=100){
- di_pre_stru.pre_de_busy_timer_count = 0;
- di_pre_stru.pre_de_busy = 0;
- pr_info("******* DI ********** wait pre_de_irq timeout\n");
- #if defined(CONFIG_ARCH_MESON2)
- set_foreign_affairs(FOREIGN_AFFAIRS_01);
- if(pre_de_irq_check){
- pr_info("DI: Force RESET\n");
- WRITE_MPEG_REG(WATCHDOG_RESET, 0);
- WRITE_MPEG_REG(WATCHDOG_TC,(1<<WATCHDOG_ENABLE_BIT)|(50));
- }
- #endif
- }
- }
- #ifdef RUN_DI_PROCESS_IN_TIMER
- {
- int i;
- for(i=0; i<10; i++){
- if(active_flag){
- di_process();
- }
- }
- }
- #endif
- if(init_flag){
- trigger_pre_di_process('t');
- }
- }
- static int di_task_handle(void *data)
- {
- while (1)
- {
- down_interruptible(&di_sema);
- if(active_flag){
- di_process();
- }
- }
- return 0;
- }
- /*
- provider/receiver interface
- */
- static int di_receiver_event_fun(int type, void* data, void* arg)
- {
- int i;
- ulong flags;
- if(type == VFRAME_EVENT_PROVIDER_UNREG){
- #ifdef DI_DEBUG
- di_print("%s: vf_notify_receiver unreg\n", __func__);
- #endif
- #ifdef GET_VFRAME_DIRECTLY
- spin_lock_irqsave(&plist_lock, flags);
- prov = NULL;
- spin_unlock_irqrestore(&plist_lock, flags);
- #endif
- di_pre_stru.unreg_req_flag = 1;
- provider_vframe_level = 0;
- trigger_pre_di_process('n');
- }
- else if(type == VFRAME_EVENT_PROVIDER_LIGHT_UNREG){
- #ifdef DI_DEBUG
- di_print("%s: vf_notify_receiver ligth unreg\n", __func__);
- #endif
- provider_vframe_level = 0;
- spin_lock_irqsave(&plist_lock, flags);
- for(i=0; i<MAX_IN_BUF_NUM; i++){
- #ifdef DI_DEBUG
- if(vframe_in[i]){
- printk("DI:clear vframe_in[%d]\n", i);
- }
- #endif
- vframe_in[i] = NULL;
- }
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- else if(type == VFRAME_EVENT_PROVIDER_VFRAME_READY){
- #ifdef DI_DEBUG
- di_print("%s: vframe ready\n", __func__);
- #endif
- provider_vframe_level++;
- trigger_pre_di_process('r');
- }
- else if(type == VFRAME_EVENT_PROVIDER_QUREY_STATE){
- int in_buf_num = 0;
- if(recovery_flag){
- return RECEIVER_INACTIVE;
- }
-
- for(i=0; i<MAX_IN_BUF_NUM; i++){
- if(vframe_in[i]!=NULL){
- in_buf_num++;
- }
- }
- if(bypass_state==1){
- if(in_buf_num>1){
- return RECEIVER_ACTIVE ;
- }else{
- return RECEIVER_INACTIVE;
- }
- }
- else{
- if(in_buf_num>0){
- return RECEIVER_ACTIVE ;
- }else{
- return RECEIVER_INACTIVE;
- }
- }
- }
- else if(type == VFRAME_EVENT_PROVIDER_REG){
- #ifdef GET_VFRAME_DIRECTLY
- prov = vf_get_provider(VFM_NAME);
- #endif
- }
-
- return 0;
- }
- static vframe_t *di_vf_peek(void* arg)
- {
- vframe_t* vframe_ret = NULL;
- di_buf_t* di_buf = NULL;
- #ifdef GET_VFRAME_DIRECTLY
- return NULL;
- #endif
- if((init_flag == 0)||recovery_flag)
- return NULL;
- if((run_flag == DI_RUN_FLAG_PAUSE)||
- (run_flag == DI_RUN_FLAG_STEP_DONE))
- return NULL;
- if((disp_frame_count==0)&&(is_bypass()==0)){
- int ready_count = list_count(QUEUE_POST_READY);
- if(ready_count>start_frame_hold_count){
- di_buf = get_di_buf_head(QUEUE_POST_READY);
- if(di_buf){
- vframe_ret = di_buf->vframe;
- }
- }
- }
- else{
- if(!queue_empty(QUEUE_POST_READY)){
- di_buf = get_di_buf_head(QUEUE_POST_READY);
- if(di_buf){
- vframe_ret = di_buf->vframe;
- }
- }
- }
- #ifdef DI_DEBUG
- if(vframe_ret){
- di_print("%s: %s[%d]:%x\n", __func__, vframe_type_name[di_buf->type], di_buf->index, vframe_ret);
- }
- #endif
- return vframe_ret;
- }
- static vframe_t *di_vf_get(void* arg)
- {
- vframe_t* vframe_ret = NULL;
- di_buf_t* di_buf = NULL;
- ulong flags;
- #ifdef GET_VFRAME_DIRECTLY
- return NULL;
- #endif
- if((init_flag == 0)||recovery_flag)
- return NULL;
- if((run_flag == DI_RUN_FLAG_PAUSE)||
- (run_flag == DI_RUN_FLAG_STEP_DONE))
- return NULL;
- if((disp_frame_count==0)&&(is_bypass()==0)){
- int ready_count = list_count(QUEUE_POST_READY);
- if(ready_count>start_frame_hold_count){
- goto get_vframe;
- }
- }
- else if (!queue_empty(QUEUE_POST_READY)){
- get_vframe:
- log_buffer_state("get");
- if(receiver_is_amvideo == 0){
- spin_lock_irqsave(&plist_lock, flags);
- }
- di_buf = get_di_buf_head(QUEUE_POST_READY);
- queue_out(di_buf);
- queue_in(di_buf, QUEUE_DISPLAY); //add it into display_list
- if(receiver_is_amvideo == 0){
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- if(di_buf){
- vframe_ret = di_buf->vframe;
- }
- disp_frame_count++;
- if(run_flag == DI_RUN_FLAG_STEP){
- run_flag = DI_RUN_FLAG_STEP_DONE;
- }
- }
- #ifdef DI_DEBUG
- if(vframe_ret){
- di_print("%s: %s[%d]:%x\n", __func__, vframe_type_name[di_buf->type], di_buf->index, vframe_ret);
- }
- #endif
- return vframe_ret;
- }
- static void di_vf_put(vframe_t *vf, void* arg)
- {
- di_buf_t* di_buf = (di_buf_t*)vf->private_data;
- ulong flags;
- #ifdef GET_VFRAME_DIRECTLY
- return;
- #endif
- if((init_flag == 0)||recovery_flag){
- #ifdef DI_DEBUG
- di_print("%s: %x\n", __func__, vf);
- #endif
- return;
- }
- log_buffer_state("put");
- if(di_buf->type == VFRAME_TYPE_POST){
- if(receiver_is_amvideo == 0){
- spin_lock_irqsave(&plist_lock, flags);
- }
- if(is_in_queue(di_buf, QUEUE_DISPLAY)){
- recycle_vframe_type_post(di_buf);
- }
- if(receiver_is_amvideo == 0){
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- #ifdef DI_DEBUG
- recycle_vframe_type_post_print(di_buf, __func__);
- #endif
- }
- else{
- if(receiver_is_amvideo == 0){
- spin_lock_irqsave(&plist_lock, flags);
- }
- queue_in(di_buf, QUEUE_RECYCLE);
- if(receiver_is_amvideo == 0){
- spin_unlock_irqrestore(&plist_lock, flags);
- }
- #ifdef DI_DEBUG
- di_print("%s: %s[%d] =>recycle_list\n", __func__, vframe_type_name[di_buf->type], di_buf->index);
- #endif
- }
- trigger_pre_di_process('p');
- }
- static int di_event_cb(int type, void *data, void *private_data)
- {
- int i;
- if(type == VFRAME_EVENT_RECEIVER_FORCE_UNREG){
- #ifdef DI_DEBUG
- di_print("%s: VFRAME_EVENT_RECEIVER_FORCE_UNREG\n", __func__);
- #endif
- di_pre_stru.force_unreg_req_flag = 1;
- provider_vframe_level = 0;
- trigger_pre_di_process('f');
- while(di_pre_stru.force_unreg_req_flag){
- msleep(1);
- }
- }
- return 0;
- }
- #ifdef GET_VFRAME_DIRECTLY
- extern vframe_t* di_recycle_buffer;
- extern vframe_t* di_vframe_buffer;
- static void put_get_disp_buf(void)
- {
- di_buf_t* di_buf;
- if(di_vframe_buffer == NULL ){
- if (!queue_empty(QUEUE_POST_READY)){
- di_buf = get_di_buf_head(QUEUE_POST_READY);
- if(di_buf){
- queue_out(di_buf);
- queue_in(di_buf, QUEUE_DISPLAY); //add it into display_list
- di_vframe_buffer = di_buf->vframe;
- }
- }
- }
- if(di_recycle_buffer){
- di_buf = (di_buf_t*)(di_recycle_buffer->private_data);
- di_recycle_buffer = NULL;
- if(is_in_queue(di_buf, QUEUE_DISPLAY)){
- recycle_vframe_type_post(di_buf);
- }
- #ifdef DI_DEBUG
- recycle_vframe_type_post_print(di_buf, __func__);
- #endif
- }
- }
- #endif
- /*****************************
- * di driver file_operations
- *
- ******************************/
- static int di_open(struct inode *node, struct file *file)
- {
- di_dev_t *di_in_devp;
- /* Get the per-device structure that contains this cdev */
- di_in_devp = container_of(node->i_cdev, di_dev_t, cdev);
- file->private_data = di_in_devp;
- return 0;
- }
- static int di_release(struct inode *node, struct file *file)
- {
- //di_dev_t *di_in_devp = file->private_data;
- /* Reset file pointer */
- /* Release some other fields */
- /* ... */
- return 0;
- }
- #ifndef CONFIG_ARCH_MESON6
- static int di_ioctl(struct inode *node, struct file *file, unsigned int cmd, unsigned long args)
- {
- int r = 0;
- switch (cmd) {
- default:
- break;
- }
- return r;
- }
- #endif
- const static struct file_operations di_fops = {
- .owner = THIS_MODULE,
- .open = di_open,
- .release = di_release,
- #ifndef CONFIG_ARCH_MESON6
- .ioctl = di_ioctl,
- #endif
- };
- static int di_probe(struct platform_device *pdev)
- {
- int r;
- struct resource *mem;
- int buf_num_avail;
- pr_dbg("di_probe\n");
- r = alloc_chrdev_region(&di_id, 0, DI_COUNT, DEVICE_NAME);
- if (r < 0) {
- pr_error("Can't register major for di device\n");
- return r;
- }
- di_class = class_create(THIS_MODULE, DEVICE_NAME);
- if (IS_ERR(di_class))
- {
- unregister_chrdev_region(di_id, DI_COUNT);
- return -1;
- }
- memset(&di_device, 0, sizeof(di_dev_t));
- cdev_init(&(di_device.cdev), &di_fops);
- di_device.cdev.owner = THIS_MODULE;
- cdev_add(&(di_device.cdev), di_id, DI_COUNT);
- di_device.devt = MKDEV(MAJOR(di_id), 0);
- di_device.dev = device_create(di_class, &pdev->dev, di_device.devt, &di_device, "di%d", 0); //kernel>=2.6.27
- if (di_device.dev == NULL) {
- pr_error("device_create create error\n");
- class_destroy(di_class);
- r = -EEXIST;
- return r;
- }
- device_create_file(di_device.dev, &dev_attr_config);
- device_create_file(di_device.dev, &dev_attr_debug);
- device_create_file(di_device.dev, &dev_attr_log);
- device_create_file(di_device.dev, &dev_attr_parameters);
- device_create_file(di_device.dev, &dev_attr_status);
- if (!(mem = platform_get_resource(pdev, IORESOURCE_MEM, 0)))
- {
- pr_error("\ndeinterlace memory resource undefined.\n");
- return -EFAULT;
- }
- // declare deinterlace memory
- di_print("Deinterlace memory: start = 0x%x, end = 0x%x, size=0x%x\n", mem->start, mem->end, mem->end-mem->start);
- di_mem_start = mem->start;
- di_mem_size = mem->end - mem->start + 1;
- init_flag = 0;
- /* set start_frame_hold_count base on buffer size */
- buf_num_avail = di_mem_size/(default_width*(default_height+8)*5/4);
- if(buf_num_avail > MAX_LOCAL_BUF_NUM){
- buf_num_avail = MAX_LOCAL_BUF_NUM;
- }
- if(buf_num_avail > 6){
- start_frame_hold_count = buf_num_avail-6;
- }
- if(start_frame_hold_count > 4){
- start_frame_hold_count = 4;
- }
- /**/
- vf_receiver_init(&di_vf_recv, VFM_NAME, &di_vf_receiver, NULL);
- vf_reg_receiver(&di_vf_recv);
- active_flag = 1;
- //data32 = (*P_A9_0_IRQ_IN1_INTR_STAT_CLR);
- r = request_irq(INT_DEINTERLACE, &de_irq,
- IRQF_SHARED, "deinterlace",
- (void *)"deinterlace");
- #if defined(CONFIG_ARCH_MESON6)
- Wr(SYS_CPU_0_IRQ_IN1_INTR_MASK, Rd(SYS_CPU_0_IRQ_IN1_INTR_MASK)|(1<<14));
- #else
- Wr(A9_0_IRQ_IN1_INTR_MASK, Rd(A9_0_IRQ_IN1_INTR_MASK)|(1<<14));
- #endif
- #if defined(CONFIG_ARCH_MESON6)
- sema_init(&di_sema,1);
- #else
- init_MUTEX(&di_sema);
- #endif
- di_sema_init_flag=1;
- #ifdef FIQ_VSYNC
- fiq_handle_item.handle=di_vf_put_isr;
- fiq_handle_item.key=(u32)di_vf_put_isr;
- fiq_handle_item.name="di_vf_put_isr";
- if(register_fiq_bridge_handle(&fiq_handle_item)){
- pr_dbg("%s: register_fiq_bridge_handle fail\n", __func__);
- }
- #endif
- reset_di_para();
- di_hw_init();
- /* timer */
- INIT_WORK(&di_pre_work, di_timer_handle);
- init_timer(&di_pre_timer);
- di_pre_timer.data = (ulong) & di_pre_timer;
- di_pre_timer.function = di_pre_timer_cb;
- di_pre_timer.expires = jiffies + DI_PRE_INTERVAL;
- add_timer(&di_pre_timer);
- /**/
- #if (!(defined RUN_DI_PROCESS_IN_IRQ))&&(!(defined RUN_DI_PROCESS_IN_TIMER))
- di_device.task = kthread_run(di_task_handle, &di_device, "kthread_di");
- #endif
- return r;
- }
- static int di_remove(struct platform_device *pdev)
- {
- di_hw_uninit();
- di_device.di_event = 0xff;
- kthread_stop(di_device.task);
- #ifdef FIQ_VSYNC
- unregister_fiq_bridge_handle(&fiq_handle_item);
- #endif
- vf_unreg_provider(&di_vf_prov);
- vf_unreg_receiver(&di_vf_recv);
- di_uninit_buf();
- /* Remove the cdev */
- device_remove_file(di_device.dev, &dev_attr_config);
- device_remove_file(di_device.dev, &dev_attr_debug);
- device_remove_file(di_device.dev, &dev_attr_log);
- device_remove_file(di_device.dev, &dev_attr_parameters);
- device_remove_file(di_device.dev, &dev_attr_status);
- cdev_del(&di_device.cdev);
- device_destroy(di_class, di_id);
- class_destroy(di_class);
- unregister_chrdev_region(di_id, DI_COUNT);
- return 0;
- }
- static struct platform_driver di_driver = {
- .probe = di_probe,
- .remove = di_remove,
- .driver = {
- .name = DEVICE_NAME,
- .owner = THIS_MODULE,
- }
- };
- static struct platform_device* deinterlace_device = NULL;
- static int __init di_init(void)
- {
- if(boot_init_flag&INIT_FLAG_NOT_LOAD)
- return 0;
- pr_dbg("di_init\n");
- #if 0
- deinterlace_device = platform_device_alloc(DEVICE_NAME,0);
- if (!deinterlace_device) {
- pr_error("failed to alloc deinterlace_device\n");
- return -ENOMEM;
- }
- if(platform_device_add(deinterlace_device)){
- platform_device_put(deinterlace_device);
- pr_error("failed to add deinterlace_device\n");
- return -ENODEV;
- }
- if (platform_driver_register(&di_driver)) {
- pr_error("failed to register di module\n");
- platform_device_del(deinterlace_device);
- platform_device_put(deinterlace_device);
- return -ENODEV;
- }
- #else
- if (platform_driver_register(&di_driver)) {
- di_print("failed to register di module\n");
- return -ENODEV;
- }
- #endif
- return 0;
- }
- static void __exit di_exit(void)
- {
- pr_dbg("di_exit\n");
- platform_driver_unregister(&di_driver);
- platform_device_unregister(deinterlace_device);
- deinterlace_device = NULL;
- return ;
- }
- MODULE_PARM_DESC(bypass_hd, "\n bypass_hd \n");
- module_param(bypass_hd, int, 0664);
- MODULE_PARM_DESC(bypass_prog, "\n bypass_prog \n");
- module_param(bypass_prog, int, 0664);
- MODULE_PARM_DESC(bypass_all, "\n bypass_all \n");
- module_param(bypass_all, int, 0664);
- MODULE_PARM_DESC(bypass_vscale_skip, "\n bypass_vscale_skip \n");
- module_param(bypass_vscale_skip, int, 0664);
- MODULE_PARM_DESC(bypass_get_buf_threshold, "\n bypass_get_buf_threshold\n");
- module_param(bypass_get_buf_threshold, uint, 0664);
- MODULE_PARM_DESC(pulldown_detect, "\n pulldown_detect \n");
- module_param(pulldown_detect, int, 0664);
- MODULE_PARM_DESC(prog_proc_config, "\n prog_proc_config \n");
- module_param(prog_proc_config, int, 0664);
- MODULE_PARM_DESC(skip_wrong_field, "\n skip_wrong_field \n");
- module_param(skip_wrong_field, int, 0664);
- MODULE_PARM_DESC(frame_count, "\n frame_count \n");
- module_param(frame_count, int, 0664);
- MODULE_PARM_DESC(start_frame_drop_count, "\n start_frame_drop_count \n");
- module_param(start_frame_drop_count, int, 0664);
- MODULE_PARM_DESC(start_frame_hold_count, "\n start_frame_hold_count \n");
- module_param(start_frame_hold_count, int, 0664);
- module_init(di_init);
- module_exit(di_exit);
- MODULE_PARM_DESC(same_w_r_canvas_count, "\n canvas of write and read are same \n");
- module_param(same_w_r_canvas_count, long, 0664);
- MODULE_PARM_DESC(same_field_top_count, "\n same top field \n");
- module_param(same_field_top_count, long, 0664);
- MODULE_PARM_DESC(same_field_bot_count, "\n same bottom field \n");
- module_param(same_field_bot_count, long, 0664);
- MODULE_PARM_DESC(same_field_source_flag_th, "\n same_field_source_flag_th \n");
- module_param(same_field_source_flag_th, int, 0664);
- MODULE_PARM_DESC(pulldown_count, "\n pulldown_count \n");
- module_param(pulldown_count, long, 0664);
- MODULE_PARM_DESC(pulldown_buffer_mode, "\n pulldown_buffer_mode \n");
- module_param(pulldown_buffer_mode, long, 0664);
- MODULE_PARM_DESC(pulldown_win_mode, "\n pulldown_win_mode \n");
- module_param(pulldown_win_mode, long, 0664);
- MODULE_PARM_DESC(frame_packing_mode, "\n frame_packing_mode \n");
- module_param(frame_packing_mode, int, 0664);
- MODULE_PARM_DESC(di_log_flag, "\n di log flag \n");
- module_param(di_log_flag, int, 0664);
- MODULE_PARM_DESC(buf_state_log_threshold, "\n buf_state_log_threshold \n");
- module_param(buf_state_log_threshold, int, 0664);
- MODULE_PARM_DESC(buf_mgr_mode, "\n buf_mgr_mode\n");
- module_param(buf_mgr_mode, uint, 0664);
- MODULE_PARM_DESC(buf_mgr_mode_mask, "\n buf_mgr_mode_mask\n");
- module_param(buf_mgr_mode_mask, uint, 0664);
- MODULE_PARM_DESC(pre_de_irq_check, "\n pre_de_irq_check\n");
- module_param(pre_de_irq_check, uint, 0664);
- MODULE_PARM_DESC(bypass_state, "\n bypass_state\n");
- module_param(bypass_state, uint, 0664);
- MODULE_PARM_DESC(force_bob_flag, "\n force_bob_flag\n");
- module_param(force_bob_flag, uint, 0664);
- MODULE_PARM_DESC(di_vscale_skip_count, "\n di_vscale_skip_count\n");
- module_param(di_vscale_skip_count, uint, 0664);
- MODULE_PARM_DESC(version, "\n version\n");
- module_param(version, uint, 0664);
- MODULE_DESCRIPTION("AMLOGIC HDMI TX driver");
- MODULE_LICENSE("GPL");
- MODULE_VERSION("1.0.0");
- static char* next_token_ex(char* seperator, char *buf, unsigned size, unsigned offset, unsigned *token_len, unsigned *token_offset)
- { /* besides characters defined in seperator, '\"' are used as seperator; and any characters in '\"' will not act as seperator */
- char *pToken = NULL;
- char last_seperator = 0;
- char trans_char_flag = 0;
- if(buf){
- for (;offset<size;offset++){
- int ii=0;
- char ch;
- if (buf[offset] == '\\'){
- trans_char_flag = 1;
- continue;
- }
- while(((ch=seperator[ii++])!=buf[offset])&&(ch)){
- }
- if (ch){
- if (!pToken){
- continue;
- }
- else {
- if (last_seperator != '"'){
- *token_len = (unsigned)(buf + offset - pToken);
- *token_offset = offset;
- return pToken;
- }
- }
- }
- else if (!pToken)
- {
- if (trans_char_flag&&(buf[offset] == '"'))
- last_seperator = buf[offset];
- pToken = &buf[offset];
- }
- else if ((trans_char_flag&&(buf[offset] == '"'))&&(last_seperator == '"')){
- *token_len = (unsigned)(buf + offset - pToken - 2);
- *token_offset = offset + 1;
- return pToken + 1;
- }
- trans_char_flag = 0;
- }
- if (pToken) {
- *token_len = (unsigned)(buf + offset - pToken);
- *token_offset = offset;
- }
- }
- return pToken;
- }
- static int __init di_boot_para_setup(char *s)
- {
- char separator[]={' ',',',';',0x0};
- char *token;
- unsigned token_len, token_offset, offset=0;
- int size=strlen(s);
- do{
- token=next_token_ex(separator, s, size, offset, &token_len, &token_offset);
- if(token){
- if((token_len==3) && (strncmp(token, "off", token_len)==0)){
- boot_init_flag|=INIT_FLAG_NOT_LOAD;
- }
- }
- offset=token_offset;
- }while(token);
- return 0;
- }
- __setup("di=",di_boot_para_setup);
- vframe_t* get_di_inp_vframe(void)
- {
- vframe_t* vframe = NULL;
- if(di_pre_stru.di_inp_buf){
- vframe = di_pre_stru.di_inp_buf->vframe;
- }
- return vframe;
- }
|