video2.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832
  1. /*
  2. * AMLOGIC Audio/Video streaming port driver.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the named License,
  7. * or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  17. *
  18. *
  19. */
  20. #include <linux/version.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/interrupt.h>
  25. //#include <linux/fiq_bridge.h>
  26. #include <linux/fs.h>
  27. #include <mach/am_regs.h>
  28. #include <linux/string.h>
  29. #include <linux/io.h>
  30. #include <linux/mm.h>
  31. #include <linux/major.h>
  32. #include <linux/err.h>
  33. #include <linux/mutex.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/ctype.h>
  36. #include <linux/amports/ptsserv.h>
  37. #include <linux/amports/timestamp.h>
  38. #include <linux/amports/tsync.h>
  39. #include <linux/amports/canvas.h>
  40. #include <linux/amports/vframe.h>
  41. #include <linux/amports/vframe_provider.h>
  42. #include <linux/amports/vframe_receiver.h>
  43. #include <linux/amports/amstream.h>
  44. #include <linux/vout/vout_notify.h>
  45. #include <linux/sched.h>
  46. #include <linux/poll.h>
  47. #include <linux/clk.h>
  48. #include <linux/logo/logo.h>
  49. #ifdef CONFIG_PM
  50. #include <linux/delay.h>
  51. #include <linux/pm.h>
  52. #endif
  53. //#include <asm/fiq.h>
  54. #include <asm/uaccess.h>
  55. #ifdef CONFIG_TVIN_VIUIN
  56. #include <media/amlogic/656in.h>
  57. #endif
  58. #include "videolog.h"
  59. #ifdef CONFIG_AM_VIDEO_LOG
  60. #define AMLOG
  61. #endif
  62. #include <linux/amlog.h>
  63. MODULE_AMLOG(LOG_LEVEL_ERROR, 0, LOG_DEFAULT_LEVEL_DESC, LOG_MASK_DESC);
  64. #include "video.h"
  65. #include "vpp.h"
  66. #undef CONFIG_AM_DEINTERLACE
  67. #include "linux/amports/ve.h"
  68. #include "linux/amports/cm.h"
  69. #include "ve_regs.h"
  70. #include "amve.h"
  71. #include "cm_regs.h"
  72. #include "amcm.h"
  73. #define VIDEO2_GET_VFRAME_DIRECTLY
  74. static u32 debug = 0;
  75. #define RECEIVER_NAME "amvideo2"
  76. static int video_receiver_event_fun(int type, void* data, void*);
  77. static const struct vframe_receiver_op_s video_vf_receiver =
  78. {
  79. .event_cb = video_receiver_event_fun
  80. };
  81. static struct vframe_receiver_s video_vf_recv;
  82. #ifdef VIDEO2_GET_VFRAME_DIRECTLY
  83. static struct vframe_provider_s * prov = NULL;
  84. #endif
  85. #define DRIVER_NAME "amvideo2"
  86. #define MODULE_NAME "amvideo2"
  87. #define DEVICE_NAME "amvideo2"
  88. #undef FIQ_VSYNC
  89. //#define SLOW_SYNC_REPEAT
  90. //#define INTERLACE_FIELD_MATCH_PROCESS
  91. void vdin0_set_hscale(
  92. int src_w,
  93. int dst_w,
  94. int hsc_en,
  95. int prehsc_en,
  96. int hsc_bank_length,
  97. int hsc_rpt_p0_num,
  98. int hsc_ini_rcv_num,
  99. int hsc_ini_phase,
  100. int short_lineo_en
  101. );
  102. #ifdef FIQ_VSYNC
  103. #define BRIDGE_IRQ INT_TIMER_D
  104. #define BRIDGE_IRQ_SET() WRITE_CBUS_REG(ISA_TIMERD, 1)
  105. #endif
  106. #define RESERVE_CLR_FRAME
  107. #define EnableVideoLayer() \
  108. do { SET_MPEG_REG_MASK(VPP2_MISC, \
  109. VPP_VD1_PREBLEND | VPP_PREBLEND_EN | VPP_VD1_POSTBLEND); \
  110. } while (0)
  111. #define EnableVideoLayer2() \
  112. do { SET_MPEG_REG_MASK(VPP2_MISC, \
  113. VPP_VD2_PREBLEND | (0x1ff << VPP_VD2_ALPHA_BIT)); \
  114. } while (0)
  115. #define DisableVideoLayer() \
  116. do { CLEAR_MPEG_REG_MASK(VPP2_MISC, \
  117. VPP_VD1_PREBLEND|VPP_VD2_PREBLEND|VPP_VD2_POSTBLEND|VPP_VD1_POSTBLEND ); \
  118. } while (0)
  119. #define DisableVideoLayer_PREBELEND() \
  120. do { CLEAR_MPEG_REG_MASK(VPP2_MISC, \
  121. VPP_VD1_PREBLEND|VPP_VD2_PREBLEND); \
  122. } while (0)
  123. /*********************************************************/
  124. #define VOUT_TYPE_TOP_FIELD 0
  125. #define VOUT_TYPE_BOT_FIELD 1
  126. #define VOUT_TYPE_PROG 2
  127. #define VIDEO_DISABLE_NONE 0
  128. #define VIDEO_DISABLE_NORMAL 1
  129. #define VIDEO_DISABLE_FORNEXT 2
  130. #define MAX_ZOOM_RATIO 300
  131. #define DUR2PTS(x) ((x) - ((x) >> 4))
  132. #define DUR2PTS_RM(x) ((x) & 0xf)
  133. static const char video_dev_id[] = "amvideo2-dev";
  134. #ifdef CONFIG_PM
  135. typedef struct {
  136. int event;
  137. u32 vpp_misc;
  138. } video_pm_state_t;
  139. static video_pm_state_t pm_state;
  140. #endif
  141. #ifdef CONFIG_ARCH_MESON6
  142. static DEFINE_MUTEX(video_module_mutex);
  143. static DEFINE_SPINLOCK(lock);
  144. #else
  145. static DEFINE_MUTEX(video_module_mutex);
  146. static spinlock_t lock = SPIN_LOCK_UNLOCKED;
  147. #endif
  148. static u32 frame_par_ready_to_set, frame_par_force_to_set;
  149. static u32 vpts_remainder;
  150. static bool video_property_changed = false;
  151. static u32 video_notify_flag = 0;
  152. #ifdef CONFIG_POST_PROCESS_MANAGER_PPSCALER
  153. static u32 video_scaler_mode = 0;
  154. static int content_top = 0, content_left = 0, content_w = 0, content_h = 0;
  155. static int scaler_pos_changed = 0;
  156. #endif
  157. #if 0
  158. int video_property_notify(int flag)
  159. {
  160. video_property_changed = flag;
  161. return 0;
  162. }
  163. #ifdef CONFIG_POST_PROCESS_MANAGER_PPSCALER
  164. int video_scaler_notify(int flag)
  165. {
  166. video_scaler_mode = flag;
  167. video_property_changed = true;
  168. return 0;
  169. }
  170. u32 amvideo2_get_scaler_para(int* x, int* y, int* w, int* h, u32* ratio)
  171. {
  172. *x = content_left;
  173. *y = content_top;
  174. *w = content_w;
  175. *h = content_h;
  176. //*ratio = 100;
  177. return video_scaler_mode;
  178. }
  179. void amvideo2_set_scaler_para(int x, int y, int w, int h,int flag)
  180. {
  181. mutex_lock(&video_module_mutex);
  182. if(w < 2)
  183. w = 0;
  184. if(h < 2)
  185. h = 0;
  186. if(flag){
  187. if((content_left!=x)||(content_top!=y)||(content_w!=w)||(content_h!=h))
  188. scaler_pos_changed = 1;
  189. content_left = x;
  190. content_top = y;
  191. content_w = w;
  192. content_h = h;
  193. }else{
  194. vpp2_set_video_layer_position(x, y, w, h);
  195. }
  196. video_property_changed = true;
  197. mutex_unlock(&video_module_mutex);
  198. return;
  199. }
  200. u32 amvideo2_get_scaler_mode(void)
  201. {
  202. return video_scaler_mode;
  203. }
  204. #endif
  205. #endif
  206. /* display canvas */
  207. static u32 disp_canvas_index[6] = {
  208. DISPLAY2_CANVAS_BASE_INDEX,
  209. DISPLAY2_CANVAS_BASE_INDEX + 1,
  210. DISPLAY2_CANVAS_BASE_INDEX + 2,
  211. DISPLAY2_CANVAS_BASE_INDEX + 3,
  212. DISPLAY2_CANVAS_BASE_INDEX + 4,
  213. DISPLAY2_CANVAS_BASE_INDEX + 5,
  214. };
  215. static u32 disp_canvas[2];
  216. static u32 post_canvas = 0;
  217. static ulong keep_y_addr = 0, *keep_y_addr_remap = NULL;
  218. static ulong keep_u_addr = 0, *keep_u_addr_remap = NULL;
  219. static ulong keep_v_addr = 0, *keep_v_addr_remap = NULL;
  220. #define Y_BUFFER_SIZE 0x400000 // for 1280*800*3 yuv444 case
  221. #define U_BUFFER_SIZE 0x80000
  222. #define V_BUFFER_SIZE 0x80000
  223. /* zoom information */
  224. static u32 zoom_start_x_lines;
  225. static u32 zoom_end_x_lines;
  226. static u32 zoom_start_y_lines;
  227. static u32 zoom_end_y_lines;
  228. /* wide settings */
  229. static u32 wide_setting;
  230. /* black out policy */
  231. #if defined(CONFIG_JPEGLOGO)
  232. static u32 blackout = 0;
  233. #else
  234. static u32 blackout = 1;
  235. #endif
  236. /* disable video */
  237. static u32 disable_video = VIDEO_DISABLE_NONE;
  238. #ifdef SLOW_SYNC_REPEAT
  239. /* video frame repeat count */
  240. static u32 frame_repeat_count = 0;
  241. #endif
  242. static u32 clone = 1;
  243. static u32 stream_play_enable = 0;
  244. static u32 clone_vpts_remainder;
  245. static int clone_frame_rate_delay = 0;
  246. static int clone_frame_rate_set_value = 0;
  247. static int clone_frame_rate_force = 0;
  248. static int clone_frame_rate = 30;
  249. static int clone_frame_scale_width = 0;
  250. static int throw_frame = 0;
  251. /* vout */
  252. static const vinfo_t *vinfo = NULL;
  253. /* config */
  254. static vframe_t *cur_dispbuf = NULL;
  255. static vframe_t vf_local;
  256. static u32 vsync_pts_inc;
  257. /* frame rate calculate */
  258. static u32 last_frame_count = 0;
  259. static u32 frame_count = 0;
  260. static u32 last_frame_time = 0;
  261. static u32 timer_count =0 ;
  262. static vpp_frame_par_t *cur_frame_par, *next_frame_par;
  263. static vpp_frame_par_t frame_parms[2];
  264. /* vsync pass flag */
  265. static u32 wait_sync;
  266. #ifdef FIQ_VSYNC
  267. static bridge_item_t vsync_fiq_bridge;
  268. #endif
  269. /* trickmode i frame*/
  270. static u32 trickmode_i = 0;
  271. /* trickmode ff/fb */
  272. static u32 trickmode_fffb = 0;
  273. static atomic_t trickmode_framedone = ATOMIC_INIT(0);
  274. static const f2v_vphase_type_t vpp_phase_table[4][3] = {
  275. {F2V_P2IT, F2V_P2IB, F2V_P2P }, /* VIDTYPE_PROGRESSIVE */
  276. {F2V_IT2IT, F2V_IT2IB, F2V_IT2P}, /* VIDTYPE_INTERLACE_TOP */
  277. {F2V_P2IT, F2V_P2IB, F2V_P2P },
  278. {F2V_IB2IT, F2V_IB2IB, F2V_IB2P} /* VIDTYPE_INTERLACE_BOTTOM */
  279. };
  280. static const u8 skip_tab[6] = { 0x24, 0x04, 0x68, 0x48, 0x28, 0x08 };
  281. /* wait queue for poll */
  282. static wait_queue_head_t amvideo_trick_wait;
  283. #if 0
  284. /* video enhancement */
  285. static struct ve_bext_s ve_bext;
  286. static struct ve_dnlp_s ve_dnlp;
  287. static struct ve_hsvs_s ve_hsvs;
  288. static struct ve_ccor_s ve_ccor;
  289. static struct ve_benh_s ve_demo;
  290. static struct ve_demo_s ve_demo;
  291. typedef struct ve_regs_s {
  292. unsigned val : 32;
  293. unsigned reg : 14;
  294. unsigned port : 2; // port port_addr port_data remark
  295. // 0 NA NA direct access
  296. // 1 VPP_CHROMA_ADDR_PORT VPP_CHROMA_DATA_PORT CM port registers
  297. // 2 NA NA reserved
  298. // 3 NA NA reserved
  299. unsigned bit : 5;
  300. unsigned wid : 5;
  301. unsigned mode : 1; // 0:read, 1:write
  302. unsigned rsv : 5;
  303. } ve_regs_t;
  304. static uchar ve_dnlp_tgt[64], ve_dnlp_rt;
  305. static ulong ve_dnlp_lpf[64], ve_dnlp_reg[16];
  306. static ulong ve_benh_ve_benh_inv[32][2] = { // [0]: inv_10_0, [1]: inv_11
  307. {2047, 1}, {2047, 1}, { 0, 1}, {1365, 0}, {1024, 0}, { 819, 0}, { 683, 0}, { 585, 0},
  308. { 512, 0}, { 455, 0}, { 410, 0}, { 372, 0}, { 341, 0}, { 315, 0}, { 293, 0}, { 273, 0},
  309. { 256, 0}, { 241, 0}, { 228, 0}, { 216, 0}, { 205, 0}, { 195, 0}, { 186, 0}, { 178, 0},
  310. { 171, 0}, { 164, 0}, { 158, 0}, { 152, 0}, { 146, 0}, { 141, 0}, { 137, 0}, { 132, 0},
  311. };
  312. static ulong ve_reg_limit(ulong val, ulong wid)
  313. {
  314. if (val < (1 << wid)) {
  315. return(val);
  316. } else {
  317. return((1 << wid) - 1);
  318. }
  319. }
  320. #endif
  321. /*********************************************************/
  322. static inline vframe_t *video_vf_peek(void)
  323. {
  324. #ifdef VIDEO2_GET_VFRAME_DIRECTLY
  325. vframe_t* vframe = NULL;
  326. if (prov && prov->ops && prov->ops->peek){
  327. vframe = prov->ops->peek(prov->op_arg);
  328. }
  329. return vframe;
  330. #else
  331. return vf_peek(RECEIVER_NAME);
  332. #endif
  333. }
  334. static inline vframe_t *video_vf_get(void)
  335. {
  336. vframe_t *vf = NULL;
  337. #ifdef VIDEO2_GET_VFRAME_DIRECTLY
  338. vframe_t* vframe = NULL;
  339. if (prov && prov->ops && prov->ops->get){
  340. vframe = prov->ops->get(prov->op_arg);
  341. }
  342. return vframe;
  343. #else
  344. vf = vf_get(RECEIVER_NAME);
  345. if (vf) video_notify_flag |= VIDEO_NOTIFY_PROVIDER_GET;
  346. return vf;
  347. #endif
  348. }
  349. static int vf_get_states(vframe_states_t *states)
  350. {
  351. int ret = -1;
  352. unsigned long flags;
  353. #ifdef VIDEO2_GET_VFRAME_DIRECTLY
  354. spin_lock_irqsave(&lock, flags);
  355. if (prov && prov->ops && prov->ops->vf_states) {
  356. ret=prov->ops->vf_states(states, prov->op_arg);
  357. }
  358. spin_unlock_irqrestore(&lock, flags);
  359. #else
  360. struct vframe_provider_s *vfp;
  361. vfp = vf_get_provider(RECEIVER_NAME);
  362. spin_lock_irqsave(&lock, flags);
  363. if (vfp && vfp->ops && vfp->ops->vf_states) {
  364. ret=vfp->ops->vf_states(states, vfp->op_arg);
  365. }
  366. spin_unlock_irqrestore(&lock, flags);
  367. #endif
  368. return ret;
  369. }
  370. static inline void video_vf_put(vframe_t *vf)
  371. {
  372. #ifdef VIDEO2_GET_VFRAME_DIRECTLY
  373. if (prov && prov->ops && prov->ops->put){
  374. prov->ops->put(vf, prov->op_arg);
  375. }
  376. #else
  377. struct vframe_provider_s *vfp = vf_get_provider(RECEIVER_NAME);
  378. if (vfp) {
  379. vf_put(vf, RECEIVER_NAME);
  380. video_notify_flag |= VIDEO_NOTIFY_PROVIDER_PUT;
  381. }
  382. #endif
  383. }
  384. static void vpp_settings_h(vpp_frame_par_t *framePtr)
  385. {
  386. vppfilter_mode_t *vpp_filter = &framePtr->vpp_filter;
  387. u32 r1, r2, r3;
  388. r1 = framePtr->VPP_hsc_linear_startp - framePtr->VPP_hsc_startp;
  389. r2 = framePtr->VPP_hsc_linear_endp - framePtr->VPP_hsc_startp;
  390. r3 = framePtr->VPP_hsc_endp - framePtr->VPP_hsc_startp;
  391. WRITE_MPEG_REG(VPP2_POSTBLEND_VD1_H_START_END,
  392. ((framePtr->VPP_hsc_startp & VPP_VD_SIZE_MASK) << VPP_VD1_START_BIT) |
  393. ((framePtr->VPP_hsc_endp & VPP_VD_SIZE_MASK) << VPP_VD1_END_BIT));
  394. //WRITE_MPEG_REG(VPP_BLEND_VD2_H_START_END,
  395. // ((framePtr->VPP_hsc_startp & VPP_VD_SIZE_MASK) << VPP_VD1_START_BIT) |
  396. // ((framePtr->VPP_hsc_endp & VPP_VD_SIZE_MASK) << VPP_VD1_END_BIT));
  397. WRITE_MPEG_REG(VPP2_HSC_REGION12_STARTP,
  398. (0 << VPP_REGION1_BIT) |
  399. ((r1 & VPP_REGION_MASK) << VPP_REGION2_BIT));
  400. WRITE_MPEG_REG(VPP2_HSC_REGION34_STARTP,
  401. ((r2 & VPP_REGION_MASK) << VPP_REGION3_BIT) |
  402. ((r3 & VPP_REGION_MASK) << VPP_REGION4_BIT));
  403. WRITE_MPEG_REG(VPP2_HSC_REGION4_ENDP, r3);
  404. WRITE_MPEG_REG(VPP2_HSC_START_PHASE_STEP,
  405. vpp_filter->vpp_hf_start_phase_step);
  406. WRITE_MPEG_REG(VPP2_LINE_IN_LENGTH, framePtr->VPP_line_in_length_);
  407. WRITE_MPEG_REG(VPP2_PREBLEND_H_SIZE, framePtr->VPP_line_in_length_);
  408. }
  409. static void vpp_settings_v(vpp_frame_par_t *framePtr)
  410. {
  411. vppfilter_mode_t *vpp_filter = &framePtr->vpp_filter;
  412. u32 r;
  413. r = framePtr->VPP_vsc_endp - framePtr->VPP_vsc_startp;
  414. WRITE_MPEG_REG(VPP2_POSTBLEND_VD1_V_START_END,
  415. ((framePtr->VPP_vsc_startp & VPP_VD_SIZE_MASK) << VPP_VD1_START_BIT) |
  416. ((framePtr->VPP_vsc_endp & VPP_VD_SIZE_MASK) << VPP_VD1_END_BIT));
  417. //WRITE_MPEG_REG(VPP2_BLEND_VD2_V_START_END,
  418. // (((framePtr->VPP_vsc_endp / 2) & VPP_VD_SIZE_MASK) << VPP_VD1_START_BIT) |
  419. // (((framePtr->VPP_vsc_endp) & VPP_VD_SIZE_MASK) << VPP_VD1_END_BIT));
  420. WRITE_MPEG_REG(VPP2_VSC_REGION12_STARTP, 0);
  421. WRITE_MPEG_REG(VPP2_VSC_REGION34_STARTP,
  422. ((r & VPP_REGION_MASK) << VPP_REGION3_BIT) |
  423. ((r & VPP_REGION_MASK) << VPP_REGION4_BIT));
  424. WRITE_MPEG_REG(VPP2_VSC_REGION4_ENDP, r);
  425. WRITE_MPEG_REG(VPP2_VSC_START_PHASE_STEP,
  426. vpp_filter->vpp_vsc_start_phase_step);
  427. }
  428. static void zoom_display_horz(void)
  429. {
  430. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA_X0,
  431. (zoom_start_x_lines << VDIF_PIC_START_BIT) |
  432. (zoom_end_x_lines << VDIF_PIC_END_BIT));
  433. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA_X0,
  434. (zoom_start_x_lines / 2 << VDIF_PIC_START_BIT) |
  435. (zoom_end_x_lines / 2 << VDIF_PIC_END_BIT));
  436. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA_X1,
  437. (zoom_start_x_lines << VDIF_PIC_START_BIT) |
  438. (zoom_end_x_lines << VDIF_PIC_END_BIT));
  439. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA_X1,
  440. (zoom_start_x_lines / 2 << VDIF_PIC_START_BIT) |
  441. (zoom_end_x_lines / 2 << VDIF_PIC_END_BIT));
  442. WRITE_MPEG_REG(VIU2_VD1_FMT_W,
  443. ((zoom_end_x_lines - zoom_start_x_lines + 1) << VD1_FMT_LUMA_WIDTH_BIT) |
  444. ((zoom_end_x_lines / 2 - zoom_start_x_lines / 2 + 1) << VD1_FMT_CHROMA_WIDTH_BIT));
  445. #if 0
  446. WRITE_MPEG_REG(VD2_IF0_LUMA_X0,
  447. (zoom_start_x_lines << VDIF_PIC_START_BIT) |
  448. (zoom_end_x_lines << VDIF_PIC_END_BIT));
  449. WRITE_MPEG_REG(VD2_IF0_CHROMA_X0,
  450. (zoom_start_x_lines / 2 << VDIF_PIC_START_BIT) |
  451. (zoom_end_x_lines / 2 << VDIF_PIC_END_BIT));
  452. WRITE_MPEG_REG(VD2_IF0_LUMA_X1,
  453. (zoom_start_x_lines << VDIF_PIC_START_BIT) |
  454. (zoom_end_x_lines << VDIF_PIC_END_BIT));
  455. WRITE_MPEG_REG(VD2_IF0_CHROMA_X1,
  456. (zoom_start_x_lines / 2 << VDIF_PIC_START_BIT) |
  457. (zoom_end_x_lines / 2 << VDIF_PIC_END_BIT));
  458. WRITE_MPEG_REG(VIU_VD2_FMT_W,
  459. ((zoom_end_x_lines - zoom_start_x_lines + 1) << VD1_FMT_LUMA_WIDTH_BIT) |
  460. ((zoom_end_x_lines / 2 - zoom_start_x_lines / 2 + 1) << VD1_FMT_CHROMA_WIDTH_BIT));
  461. #endif
  462. }
  463. static void zoom_display_vert(void)
  464. {
  465. if ((cur_dispbuf) && (cur_dispbuf->type & VIDTYPE_MVC)) {
  466. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA_Y0,
  467. (zoom_start_y_lines * 2 << VDIF_PIC_START_BIT) |
  468. (zoom_end_y_lines * 2 << VDIF_PIC_END_BIT));
  469. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA_Y0,
  470. ((zoom_start_y_lines) << VDIF_PIC_START_BIT) |
  471. ((zoom_end_y_lines) << VDIF_PIC_END_BIT));
  472. //WRITE_MPEG_REG(VD2_IF0_LUMA_Y0,
  473. // (zoom_start_y_lines * 2 << VDIF_PIC_START_BIT) |
  474. // (zoom_end_y_lines * 2 << VDIF_PIC_END_BIT));
  475. //WRITE_MPEG_REG(VD2_IF0_CHROMA_Y0,
  476. // ((zoom_start_y_lines) << VDIF_PIC_START_BIT) |
  477. // ((zoom_end_y_lines) << VDIF_PIC_END_BIT));
  478. } else {
  479. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA_Y0,
  480. (zoom_start_y_lines << VDIF_PIC_START_BIT) |
  481. (zoom_end_y_lines << VDIF_PIC_END_BIT));
  482. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA_Y0,
  483. ((zoom_start_y_lines / 2) << VDIF_PIC_START_BIT) |
  484. ((zoom_end_y_lines / 2) << VDIF_PIC_END_BIT));
  485. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA_Y1,
  486. (zoom_start_y_lines << VDIF_PIC_START_BIT) |
  487. (zoom_end_y_lines << VDIF_PIC_END_BIT));
  488. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA_Y1,
  489. ((zoom_start_y_lines / 2) << VDIF_PIC_START_BIT) |
  490. ((zoom_end_y_lines / 2) << VDIF_PIC_END_BIT));
  491. }
  492. }
  493. static void vsync_toggle_frame(vframe_t *vf)
  494. {
  495. u32 first_picture = 0;
  496. #if 0
  497. if(vf->early_process_fun){
  498. vf->early_process_fun(vf->private_data);
  499. }
  500. else{
  501. if(READ_MPEG_REG(DI_IF1_GEN_REG)&0x1){
  502. //disable post di
  503. WRITE_MPEG_REG(DI_POST_CTRL, 0x3 << 30);
  504. WRITE_MPEG_REG(DI_POST_SIZE, (32-1) | ((128-1) << 16));
  505. WRITE_MPEG_REG(DI_IF1_GEN_REG, READ_MPEG_REG(DI_IF1_GEN_REG) & 0xfffffffe);
  506. }
  507. }
  508. #endif
  509. if(debug&0x4){
  510. printk("[Video2] %s vf=%x\n", __func__, vf);
  511. }
  512. if ((vf->width == 0) && (vf->height == 0)) {
  513. amlog_level(LOG_LEVEL_ERROR, "Video: invalid frame dimension\n");
  514. return;
  515. }
  516. if ((cur_dispbuf) && (cur_dispbuf != &vf_local) && (cur_dispbuf != vf)
  517. &&(video_property_changed != 2)) {
  518. video_vf_put(cur_dispbuf);
  519. } else {
  520. first_picture = 1;
  521. }
  522. if (video_property_changed) {
  523. video_property_changed = false;
  524. first_picture = 1;
  525. }
  526. /* switch buffer */
  527. post_canvas = vf->canvas0Addr;
  528. canvas_copy(vf->canvas0Addr & 0xff, disp_canvas_index[0]);
  529. canvas_copy((vf->canvas0Addr >> 8) & 0xff, disp_canvas_index[1]);
  530. canvas_copy((vf->canvas0Addr >> 16) & 0xff, disp_canvas_index[2]);
  531. canvas_copy(vf->canvas1Addr & 0xff, disp_canvas_index[3]);
  532. canvas_copy((vf->canvas1Addr >> 8) & 0xff, disp_canvas_index[4]);
  533. canvas_copy((vf->canvas1Addr >> 16) & 0xff, disp_canvas_index[5]);
  534. WRITE_MPEG_REG(VIU2_VD1_IF0_CANVAS0, disp_canvas[0]);
  535. WRITE_MPEG_REG(VIU2_VD1_IF0_CANVAS1, disp_canvas[1]);
  536. //WRITE_MPEG_REG(VD2_IF0_CANVAS0, disp_canvas[1]);
  537. //WRITE_MPEG_REG(VD2_IF0_CANVAS1, disp_canvas[1]);
  538. /* set video PTS */
  539. if((clone == 0)&&(stream_play_enable == 1)){
  540. if (cur_dispbuf != vf) {
  541. if (vf->pts != 0) {
  542. amlog_mask(LOG_MASK_TIMESTAMP,
  543. "vpts to vf->pts: 0x%x, scr: 0x%x, abs_scr: 0x%x\n",
  544. vf->pts, timestamp_pcrscr_get(), READ_MPEG_REG(SCR_HIU));
  545. timestamp_vpts_set(vf->pts);
  546. } else if (cur_dispbuf) {
  547. amlog_mask(LOG_MASK_TIMESTAMP,
  548. "vpts inc: 0x%x, scr: 0x%x, abs_scr: 0x%x\n",
  549. timestamp_vpts_get() + DUR2PTS(cur_dispbuf->duration),
  550. timestamp_pcrscr_get(), READ_MPEG_REG(SCR_HIU));
  551. timestamp_vpts_inc(DUR2PTS(cur_dispbuf->duration));
  552. vpts_remainder += DUR2PTS_RM(cur_dispbuf->duration);
  553. if (vpts_remainder >= 0xf) {
  554. vpts_remainder -= 0xf;
  555. timestamp_vpts_inc(-1);
  556. }
  557. }
  558. vf->type_backup = vf->type;
  559. }
  560. }
  561. /* enable new config on the new frames */
  562. if ((first_picture) ||
  563. (cur_dispbuf->bufWidth != vf->bufWidth) ||
  564. (cur_dispbuf->width != vf->width) ||
  565. (cur_dispbuf->height != vf->height) ||
  566. (cur_dispbuf->ratio_control != vf->ratio_control) ||
  567. ((cur_dispbuf->type_backup & VIDTYPE_INTERLACE) !=
  568. (vf->type_backup & VIDTYPE_INTERLACE))) {
  569. amlog_mask(LOG_MASK_FRAMEINFO,
  570. "%s %dx%d ar=0x%x\n",
  571. ((vf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP) ?
  572. "interlace-top" :
  573. ((vf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_BOTTOM) ?
  574. "interlace-bottom" :
  575. "progressive",
  576. vf->width,
  577. vf->height,
  578. vf->ratio_control);
  579. next_frame_par = (&frame_parms[0] == next_frame_par) ?
  580. &frame_parms[1] : &frame_parms[0];
  581. vpp2_set_filters(wide_setting, vf, next_frame_par, vinfo);
  582. /* apply new vpp settings */
  583. frame_par_ready_to_set = 1;
  584. } else {
  585. }
  586. cur_dispbuf = vf;
  587. if ((vf->type & VIDTYPE_NO_VIDEO_ENABLE) == 0) {
  588. if (disable_video == VIDEO_DISABLE_FORNEXT) {
  589. EnableVideoLayer();
  590. disable_video = VIDEO_DISABLE_NONE;
  591. }
  592. if (first_picture && (disable_video != VIDEO_DISABLE_NORMAL)) {
  593. EnableVideoLayer();
  594. if (cur_dispbuf->type & VIDTYPE_MVC)
  595. EnableVideoLayer2();
  596. }
  597. }
  598. if (first_picture) {
  599. frame_par_ready_to_set = 1;
  600. }
  601. }
  602. static int vsync_hold_line = 17;
  603. static void viu_set_dcu(vpp_frame_par_t *frame_par, vframe_t *vf)
  604. {
  605. u32 r;
  606. u32 vphase, vini_phase;
  607. u32 pat, loop;
  608. static const u32 vpat[] = {0, 0x8, 0x9, 0xa, 0xb, 0xc};
  609. r = (3 << VDIF_URGENT_BIT) |
  610. (vsync_hold_line << VDIF_HOLD_LINES_BIT) |
  611. VDIF_FORMAT_SPLIT |
  612. VDIF_CHRO_RPT_LAST |
  613. VDIF_ENABLE |
  614. VDIF_RESET_ON_GO_FIELD;
  615. if ((vf->type & VIDTYPE_VIU_SINGLE_PLANE) == 0) {
  616. r |= VDIF_SEPARATE_EN;
  617. } else {
  618. if (vf->type & VIDTYPE_VIU_422) {
  619. r |= VDIF_FORMAT_422;
  620. } else {
  621. r |= VDIF_FORMAT_RGB888_YUV444 | VDIF_DEMUX_MODE_RGB_444;
  622. }
  623. }
  624. WRITE_MPEG_REG(VIU2_VD1_IF0_GEN_REG, r);
  625. //WRITE_MPEG_REG(VD2_IF0_GEN_REG, r);
  626. /* chroma formatter */
  627. if (vf->type & VIDTYPE_VIU_444) {
  628. WRITE_MPEG_REG(VIU2_VD1_FMT_CTRL, HFORMATTER_YC_RATIO_1_1);
  629. //WRITE_MPEG_REG(VIU_VD2_FMT_CTRL, HFORMATTER_YC_RATIO_1_1);
  630. } else if (vf->type & VIDTYPE_VIU_FIELD) {
  631. vini_phase = 0xc << VFORMATTER_INIPHASE_BIT;
  632. vphase = ((vf->type & VIDTYPE_VIU_422) ? 0x10 : 0x08) << VFORMATTER_PHASE_BIT;
  633. WRITE_MPEG_REG(VIU2_VD1_FMT_CTRL,
  634. HFORMATTER_YC_RATIO_2_1 | HFORMATTER_EN |
  635. VFORMATTER_RPTLINE0_EN | vini_phase | vphase | VFORMATTER_EN);
  636. //WRITE_MPEG_REG(VIU_VD2_FMT_CTRL,
  637. // HFORMATTER_YC_RATIO_2_1 | HFORMATTER_EN |
  638. // VFORMATTER_RPTLINE0_EN | vini_phase | vphase | VFORMATTER_EN);
  639. } else if (vf->type & VIDTYPE_MVC) {
  640. WRITE_MPEG_REG(VIU2_VD1_FMT_CTRL,
  641. HFORMATTER_YC_RATIO_2_1 |
  642. HFORMATTER_EN |
  643. VFORMATTER_RPTLINE0_EN |
  644. (0xe << VFORMATTER_INIPHASE_BIT) |
  645. (((vf->type & VIDTYPE_VIU_422) ? 0x10 : 0x08) << VFORMATTER_PHASE_BIT) |
  646. VFORMATTER_EN);
  647. /*WRITE_MPEG_REG(VIU_VD2_FMT_CTRL,
  648. HFORMATTER_YC_RATIO_2_1 |
  649. HFORMATTER_EN |
  650. VFORMATTER_RPTLINE0_EN |
  651. (0xa << VFORMATTER_INIPHASE_BIT) |
  652. (((vf->type & VIDTYPE_VIU_422) ? 0x10 : 0x08) << VFORMATTER_PHASE_BIT) |
  653. VFORMATTER_EN);*/
  654. } else if ((vf->type & VIDTYPE_INTERLACE) &&
  655. (((vf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP))) {
  656. WRITE_MPEG_REG(VIU2_VD1_FMT_CTRL,
  657. HFORMATTER_YC_RATIO_2_1 |
  658. HFORMATTER_EN |
  659. VFORMATTER_RPTLINE0_EN |
  660. (0xe << VFORMATTER_INIPHASE_BIT) |
  661. (((vf->type & VIDTYPE_VIU_422) ? 0x10 : 0x08) << VFORMATTER_PHASE_BIT) |
  662. VFORMATTER_EN);
  663. /*WRITE_MPEG_REG(VIU_VD2_FMT_CTRL,
  664. HFORMATTER_YC_RATIO_2_1 |
  665. HFORMATTER_EN |
  666. VFORMATTER_RPTLINE0_EN |
  667. (0xe << VFORMATTER_INIPHASE_BIT) |
  668. (((vf->type & VIDTYPE_VIU_422) ? 0x10 : 0x08) << VFORMATTER_PHASE_BIT) |
  669. VFORMATTER_EN);*/
  670. } else {
  671. WRITE_MPEG_REG(VIU2_VD1_FMT_CTRL,
  672. HFORMATTER_YC_RATIO_2_1 |
  673. HFORMATTER_EN |
  674. VFORMATTER_RPTLINE0_EN |
  675. (0xa << VFORMATTER_INIPHASE_BIT) |
  676. (((vf->type & VIDTYPE_VIU_422) ? 0x10 : 0x08) << VFORMATTER_PHASE_BIT) |
  677. VFORMATTER_EN);
  678. /*WRITE_MPEG_REG(VIU_VD2_FMT_CTRL,
  679. HFORMATTER_YC_RATIO_2_1 |
  680. HFORMATTER_EN |
  681. VFORMATTER_RPTLINE0_EN |
  682. (0xa << VFORMATTER_INIPHASE_BIT) |
  683. (((vf->type & VIDTYPE_VIU_422) ? 0x10 : 0x08) << VFORMATTER_PHASE_BIT) |
  684. VFORMATTER_EN);*/
  685. }
  686. /* LOOP/SKIP pattern */
  687. pat = vpat[frame_par->vscale_skip_count];
  688. if (vf->type & VIDTYPE_VIU_FIELD) {
  689. loop = 0;
  690. if (vf->type & VIDTYPE_INTERLACE) {
  691. pat = vpat[frame_par->vscale_skip_count - 1];
  692. }
  693. } else if (vf->type & VIDTYPE_MVC) {
  694. loop = 0x11;
  695. pat = 0x80;
  696. } else if ((vf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP) {
  697. loop = 0x11;
  698. pat <<= 4;
  699. } else {
  700. loop = 0;
  701. }
  702. WRITE_MPEG_REG(VIU2_VD1_IF0_RPT_LOOP,
  703. (loop << VDIF_CHROMA_LOOP1_BIT) |
  704. (loop << VDIF_LUMA_LOOP1_BIT) |
  705. (loop << VDIF_CHROMA_LOOP0_BIT) |
  706. (loop << VDIF_LUMA_LOOP0_BIT));
  707. /*WRITE_MPEG_REG(VD2_IF0_RPT_LOOP,
  708. (loop << VDIF_CHROMA_LOOP1_BIT) |
  709. (loop << VDIF_LUMA_LOOP1_BIT) |
  710. (loop << VDIF_CHROMA_LOOP0_BIT) |
  711. (loop << VDIF_LUMA_LOOP0_BIT));*/
  712. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA0_RPT_PAT, pat);
  713. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA0_RPT_PAT, pat);
  714. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA1_RPT_PAT, pat);
  715. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA1_RPT_PAT, pat);
  716. if (vf->type & VIDTYPE_MVC)
  717. pat = 0x88;
  718. /*
  719. WRITE_MPEG_REG(VD2_IF0_LUMA0_RPT_PAT, pat);
  720. WRITE_MPEG_REG(VD2_IF0_CHROMA0_RPT_PAT, pat);
  721. WRITE_MPEG_REG(VD2_IF0_LUMA1_RPT_PAT, pat);
  722. WRITE_MPEG_REG(VD2_IF0_CHROMA1_RPT_PAT, pat);
  723. */
  724. /* picture 0/1 control */
  725. if (((vf->type & VIDTYPE_INTERLACE) == 0) &&
  726. ((vf->type & VIDTYPE_VIU_FIELD) == 0) &&
  727. ((vf->type & VIDTYPE_MVC) == 0)) {
  728. /* progressive frame in two pictures */
  729. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA_PSEL,
  730. (2 << 26) | /* two pic mode */
  731. (2 << 24) | /* use own last line */
  732. (2 << 8) | /* toggle pic 0 and 1, use pic0 first */
  733. (0x01)); /* loop pattern */
  734. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA_PSEL,
  735. (2 << 26) | /* two pic mode */
  736. (2 << 24) | /* use own last line */
  737. (2 << 8) | /* toggle pic 0 and 1, use pic0 first */
  738. (0x01)); /* loop pattern */
  739. } else {
  740. WRITE_MPEG_REG(VIU2_VD1_IF0_LUMA_PSEL, 0);
  741. WRITE_MPEG_REG(VIU2_VD1_IF0_CHROMA_PSEL, 0);
  742. //WRITE_MPEG_REG(VD2_IF0_LUMA_PSEL, 0);
  743. //WRITE_MPEG_REG(VD2_IF0_CHROMA_PSEL, 0);
  744. }
  745. }
  746. static int detect_vout_type(void)
  747. {
  748. #if defined(CONFIG_AM_TCON_OUTPUT)
  749. return VOUT_TYPE_PROG;
  750. #else
  751. int vout_type;
  752. int encp_enable = READ_MPEG_REG(ENCP_VIDEO_EN) & 1;
  753. if (encp_enable) {
  754. if (READ_MPEG_REG(ENCP_VIDEO_MODE) & (1 << 12)) {
  755. /* 1080I */
  756. if (READ_MPEG_REG(VENC_ENCP_LINE) < 562) {
  757. vout_type = VOUT_TYPE_TOP_FIELD;
  758. } else {
  759. vout_type = VOUT_TYPE_BOT_FIELD;
  760. }
  761. } else {
  762. vout_type = VOUT_TYPE_PROG;
  763. }
  764. } else {
  765. vout_type = (READ_MPEG_REG(VENC_STATA) & 1) ?
  766. VOUT_TYPE_BOT_FIELD : VOUT_TYPE_TOP_FIELD;
  767. }
  768. return vout_type;
  769. #endif
  770. }
  771. #ifdef INTERLACE_FIELD_MATCH_PROCESS
  772. static inline bool interlace_field_type_match(int vout_type, vframe_t *vf)
  773. {
  774. if (DUR2PTS(vf->duration) != vsync_pts_inc) {
  775. return false;
  776. }
  777. if ((vout_type == VOUT_TYPE_TOP_FIELD) &&
  778. ((vf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP)) {
  779. return true;
  780. } else if ((vout_type == VOUT_TYPE_BOT_FIELD) &&
  781. ((vf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_BOTTOM)) {
  782. return true;
  783. }
  784. return false;
  785. }
  786. #endif
  787. static int calc_hold_line(void)
  788. {
  789. if ((READ_MPEG_REG(ENCI_VIDEO_EN) & 1) == 0) {
  790. return READ_MPEG_REG(ENCP_VIDEO_VAVON_BLINE) >> 1;
  791. } else {
  792. return READ_MPEG_REG(VFIFO2VD_LINE_TOP_START) >> 1;
  793. }
  794. }
  795. #ifdef SLOW_SYNC_REPEAT
  796. /* add a new function to check if current display frame has been
  797. displayed for its duration */
  798. static inline bool duration_expire(vframe_t *cur_vf, vframe_t *next_vf, u32 dur)
  799. {
  800. u32 pts;
  801. s32 dur_disp;
  802. static s32 rpt_tab_idx = 0;
  803. static const u32 rpt_tab[4] = {0x100, 0x100, 0x300, 0x300};
  804. if ((cur_vf == NULL) || (cur_dispbuf == &vf_local)) {
  805. return true;
  806. }
  807. pts = next_vf->pts;
  808. if (pts == 0) {
  809. dur_disp = DUR2PTS(cur_vf->duration);
  810. } else {
  811. dur_disp = pts - timestamp_vpts_get();
  812. }
  813. if ((dur << 8) >= (dur_disp * rpt_tab[rpt_tab_idx & 3])) {
  814. rpt_tab_idx = (rpt_tab_idx + 1) & 3;
  815. return true;
  816. } else {
  817. return false;
  818. }
  819. }
  820. #endif
  821. static inline bool vpts_expire(vframe_t *cur_vf, vframe_t *next_vf)
  822. {
  823. u32 pts = next_vf->pts;
  824. u32 systime;
  825. if ((cur_vf == NULL) || (cur_dispbuf == &vf_local)) {
  826. return true;
  827. }
  828. if ((trickmode_i == 1) || ((trickmode_fffb == 1))) {
  829. if (0 == atomic_read(&trickmode_framedone)) {
  830. return true;
  831. } else {
  832. return false;
  833. }
  834. }
  835. if (next_vf->duration == 0) {
  836. return true;
  837. }
  838. systime = timestamp_pcrscr_get();
  839. if ((pts == 0) && (cur_dispbuf != &vf_local)) {
  840. pts = timestamp_vpts_get() + (cur_vf ? DUR2PTS(cur_vf->duration) : 0);
  841. }
  842. /* check video PTS discontinuity */
  843. else if (abs(systime - pts) > tsync_vpts_discontinuity_margin()) {
  844. pts = timestamp_vpts_get() + (cur_vf ? DUR2PTS(cur_vf->duration) : 0);
  845. if ((systime - pts) >= 0) {
  846. tsync_avevent_locked(VIDEO_TSTAMP_DISCONTINUITY, next_vf->pts);
  847. printk("video discontinue, system=0x%x vpts=0x%x\n", systime, pts);
  848. return true;
  849. }
  850. }
  851. return ((int)(timestamp_pcrscr_get() - pts) >= 0);
  852. }
  853. #if defined(CONFIG_CLK81_DFS)
  854. extern int check_and_set_clk81(void);
  855. #endif
  856. #ifndef VIDEO2_GET_VFRAME_DIRECTLY
  857. static void vsync_notify(void)
  858. {
  859. if (video_notify_flag & VIDEO_NOTIFY_TRICK_WAIT) {
  860. wake_up_interruptible(&amvideo_trick_wait);
  861. video_notify_flag &= ~VIDEO_NOTIFY_TRICK_WAIT;
  862. }
  863. if (video_notify_flag & VIDEO_NOTIFY_FRAME_WAIT) {
  864. video_notify_flag &= ~VIDEO_NOTIFY_FRAME_WAIT;
  865. vf_notify_provider(RECEIVER_NAME, VFRAME_EVENT_RECEIVER_FRAME_WAIT, NULL);
  866. }
  867. #ifdef CONFIG_POST_PROCESS_MANAGER_PPSCALER
  868. if (video_notify_flag & VIDEO_NOTIFY_POS_CHANGED) {
  869. video_notify_flag &= ~VIDEO_NOTIFY_POS_CHANGED;
  870. vf_notify_provider(RECEIVER_NAME, VFRAME_EVENT_RECEIVER_POS_CHANGED, NULL);
  871. }
  872. #endif
  873. if (video_notify_flag & (VIDEO_NOTIFY_PROVIDER_GET | VIDEO_NOTIFY_PROVIDER_PUT)) {
  874. int event = 0;
  875. if (video_notify_flag & VIDEO_NOTIFY_PROVIDER_GET)
  876. event |= VFRAME_EVENT_RECEIVER_GET;
  877. if (video_notify_flag & VIDEO_NOTIFY_PROVIDER_PUT)
  878. event |= VFRAME_EVENT_RECEIVER_PUT;
  879. vf_notify_provider(RECEIVER_NAME, event, NULL);
  880. video_notify_flag &= ~(VIDEO_NOTIFY_PROVIDER_GET | VIDEO_NOTIFY_PROVIDER_PUT);
  881. }
  882. #if defined(CONFIG_CLK81_DFS)
  883. check_and_set_clk81();
  884. #endif
  885. }
  886. #endif
  887. #ifdef FIQ_VSYNC
  888. static irqreturn_t vsync_bridge_isr(int irq, void *dev_id)
  889. {
  890. #ifndef VIDEO2_GET_VFRAME_DIRECTLY
  891. vsync_notify();
  892. #endif
  893. return IRQ_HANDLED;
  894. }
  895. #endif
  896. #if 1
  897. #define INTERVAL_BUF_SIZE 1200
  898. static unsigned int last_isr_enter_time = 0;
  899. //static unsigned int timerb_interval_buf[INTERVAL_BUF_SIZE];
  900. //static int timerb_interval_wr_pos = 0;
  901. static unsigned int isr_interval_max = 0;
  902. static unsigned int isr_run_time_max = 0;
  903. #endif
  904. #ifdef FIQ_VSYNC
  905. void vsync_fisr2(void)
  906. #else
  907. static irqreturn_t vsync_isr(int irq, void *dev_id)
  908. #endif
  909. {
  910. int hold_line;
  911. s32 i, vout_type;
  912. vframe_t *vf;
  913. #ifdef CONFIG_AM_VIDEO_LOG
  914. int toggle_cnt;
  915. #endif
  916. #if 1
  917. unsigned int cur_timerb_value;
  918. unsigned int interval;
  919. #endif
  920. #ifdef CONFIG_AM_VIDEO_LOG
  921. toggle_cnt = 0;
  922. #endif
  923. if(clone_frame_rate_delay!=0){
  924. clone_frame_rate_delay--;
  925. if(clone_frame_rate_delay==0){
  926. clone_frame_rate = clone_frame_rate_set_value;
  927. }
  928. }
  929. #ifndef CONFIG_ARCH_MESON6
  930. if(READ_MPEG_REG(ISA_TIMERB)==0){
  931. WRITE_MPEG_REG(ISA_TIMER_MUX, (READ_MPEG_REG(ISA_TIMER_MUX)&(~(3<<TIMER_B_INPUT_BIT)))
  932. |(TIMER_UNIT_1us<<TIMER_B_INPUT_BIT)|(1<<13)|(1<<17));
  933. WRITE_MPEG_REG(ISA_TIMERB, 0xffff);
  934. printk("Deinterlace: Init 100us TimerB\n");
  935. }
  936. cur_timerb_value = (unsigned int)(0x10000-(READ_MPEG_REG(ISA_TIMERB)>>16));
  937. if(cur_timerb_value > last_isr_enter_time){
  938. interval = cur_timerb_value-last_isr_enter_time;
  939. }
  940. else{
  941. interval = cur_timerb_value + 0x10000 - last_isr_enter_time;
  942. }
  943. last_isr_enter_time = cur_timerb_value;
  944. if(interval > isr_interval_max){
  945. isr_interval_max = interval;
  946. }
  947. if(debug&0x1){
  948. printk("[Video2] Enter %s %u %u\n", __func__, interval, cur_timerb_value);
  949. }
  950. #endif
  951. if(debug&0x100){
  952. do{
  953. vf=vf_get(RECEIVER_NAME);
  954. if(vf){
  955. vf_put(vf, RECEIVER_NAME);
  956. }
  957. }while(vf);
  958. }
  959. frame_count ++;
  960. timer_count ++;
  961. vout_type = detect_vout_type();
  962. hold_line = calc_hold_line();
  963. if((clone == 0)&&(stream_play_enable == 1)){
  964. timestamp_pcrscr_inc(vsync_pts_inc);
  965. timestamp_apts_inc(vsync_pts_inc);
  966. }
  967. #ifdef SLOW_SYNC_REPEAT
  968. frame_repeat_count++;
  969. #endif
  970. if ((!cur_dispbuf) || (cur_dispbuf == &vf_local)) {
  971. vf = video_vf_peek();
  972. if (vf) {
  973. if((clone == 0)&&(stream_play_enable == 1)){
  974. tsync_avevent_locked(VIDEO_START,
  975. (vf->pts) ? vf->pts : timestamp_vpts_get());
  976. }
  977. #ifdef SLOW_SYNC_REPEAT
  978. frame_repeat_count = 0;
  979. #endif
  980. } else if ((cur_dispbuf == &vf_local) && (video_property_changed)) {
  981. if (!blackout) {
  982. {
  983. /* setting video display property in unregister mode */
  984. u32 cur_index = cur_dispbuf->canvas0Addr;
  985. canvas_update_addr(cur_index & 0xff, (u32)keep_y_addr);
  986. canvas_update_addr((cur_index >> 8) & 0xff, (u32)keep_u_addr);
  987. canvas_update_addr((cur_index >> 16) & 0xff, (u32)keep_v_addr);
  988. }
  989. vsync_toggle_frame(cur_dispbuf);
  990. } else {
  991. video_property_changed = false;
  992. }
  993. } else {
  994. goto exit;
  995. }
  996. }
  997. /* buffer switch management */
  998. vf = video_vf_peek();
  999. if(debug&0x2){
  1000. printk("[Video2] %s vf_peek=>%x\n", __func__, vf);
  1001. }
  1002. /* setting video display property in underflow mode */
  1003. if ((!vf) && cur_dispbuf && (video_property_changed)) {
  1004. vsync_toggle_frame(cur_dispbuf);
  1005. }
  1006. while (vf) {
  1007. if(clone == 1){
  1008. if(throw_frame){
  1009. vf = video_vf_get();
  1010. #ifdef CONFIG_TVIN_VIUIN
  1011. if(vf->width >= 1280){
  1012. if(clone_frame_scale_width != 0){
  1013. vdin0_set_hscale(
  1014. vf->width, //int src_w,
  1015. clone_frame_scale_width, //int dst_w,
  1016. 1, //int hsc_en,
  1017. 0, //int prehsc_en,
  1018. 4, //int hsc_bank_length,
  1019. 1, //int hsc_rpt_p0_num,
  1020. 4, //int hsc_ini_rcv_num,
  1021. 0, //int hsc_ini_phase,
  1022. 1 //int short_lineo_en
  1023. );
  1024. vf->width = clone_frame_scale_width;
  1025. }
  1026. }else{
  1027. /*
  1028. the vframe is freescale processed , so nothing to change
  1029. freescale width&height is less than 800*600
  1030. */
  1031. }
  1032. #endif
  1033. video_vf_put(vf);
  1034. throw_frame--;
  1035. }
  1036. else if(clone_vpts_remainder < vsync_pts_inc){
  1037. vf = video_vf_get();
  1038. #ifdef CONFIG_TVIN_VIUIN
  1039. if(clone_frame_scale_width != 0){
  1040. vdin0_set_hscale(
  1041. vf->width, //int src_w,
  1042. clone_frame_scale_width, //int dst_w,
  1043. 1, //int hsc_en,
  1044. 0, //int prehsc_en,
  1045. 4, //int hsc_bank_length,
  1046. 1, //int hsc_rpt_p0_num,
  1047. 4, //int hsc_ini_rcv_num,
  1048. 0, //int hsc_ini_phase,
  1049. 1 //int short_lineo_en
  1050. );
  1051. vf->width = clone_frame_scale_width;
  1052. }
  1053. #endif
  1054. vsync_toggle_frame(vf);
  1055. //clone_vpts_remainder += DUR2PTS(vf->duration);
  1056. if(clone_frame_rate_force){
  1057. clone_vpts_remainder += (90000/clone_frame_rate_force);
  1058. }
  1059. else{
  1060. clone_vpts_remainder += (90000/clone_frame_rate);
  1061. }
  1062. }
  1063. else{
  1064. clone_vpts_remainder -= vsync_pts_inc;
  1065. }
  1066. break;
  1067. }
  1068. else if (vpts_expire(cur_dispbuf, vf)
  1069. #ifdef INTERLACE_FIELD_MATCH_PROCESS
  1070. || interlace_field_type_match(vout_type, vf)
  1071. #endif
  1072. ) {
  1073. amlog_mask(LOG_MASK_TIMESTAMP,
  1074. "VIDEO_PTS = 0x%x, cur_dur=0x%x, next_pts=0x%x, scr = 0x%x\n",
  1075. timestamp_vpts_get(),
  1076. (cur_dispbuf) ? cur_dispbuf->duration : 0,
  1077. vf->pts,
  1078. timestamp_pcrscr_get());
  1079. amlog_mask_if(toggle_cnt > 0, LOG_MASK_FRAMESKIP, "skipped\n");
  1080. vf = video_vf_get();
  1081. vsync_toggle_frame(vf);
  1082. if (trickmode_fffb == 1) {
  1083. atomic_set(&trickmode_framedone, 1);
  1084. video_notify_flag |= VIDEO_NOTIFY_TRICK_WAIT;
  1085. break;
  1086. }
  1087. #ifdef SLOW_SYNC_REPEAT
  1088. frame_repeat_count = 0;
  1089. #endif
  1090. vf = video_vf_peek();
  1091. if(debug&0x10000){
  1092. return;
  1093. }
  1094. } else {
  1095. #ifdef SLOW_SYNC_REPEAT
  1096. /* check if current frame's duration has expired, in this example
  1097. * it compares current frame display duration with 1/1/1/1.5 frame duration
  1098. * every 4 frames there will be one frame play longer than usual.
  1099. * you can adjust this array for any slow sync control as you want.
  1100. * The playback can be smoother than previous method.
  1101. */
  1102. if (duration_expire(cur_dispbuf, vf, frame_repeat_count * vsync_pts_inc) && timestamp_pcrscr_enable_state()) {
  1103. amlog_mask(LOG_MASK_SLOWSYNC,
  1104. "slow sync toggle, frame_repeat_count = %d\n",
  1105. frame_repeat_count);
  1106. amlog_mask(LOG_MASK_SLOWSYNC,
  1107. "system time = 0x%x, video time = 0x%x\n",
  1108. timestamp_pcrscr_get(), timestamp_vpts_get());
  1109. vf = video_vf_get();
  1110. vsync_toggle_frame(vf);
  1111. frame_repeat_count = 0;
  1112. vf = video_vf_peek();
  1113. } else
  1114. #endif
  1115. /* setting video display property in pause mode */
  1116. if (video_property_changed && cur_dispbuf) {
  1117. if (blackout) {
  1118. if (cur_dispbuf != &vf_local) {
  1119. vsync_toggle_frame(cur_dispbuf);
  1120. }
  1121. } else {
  1122. vsync_toggle_frame(cur_dispbuf);
  1123. }
  1124. }
  1125. break;
  1126. }
  1127. #ifdef CONFIG_AM_VIDEO_LOG
  1128. toggle_cnt++;
  1129. #endif
  1130. }
  1131. /* filter setting management */
  1132. if ((frame_par_ready_to_set) || (frame_par_force_to_set)) {
  1133. cur_frame_par = next_frame_par;
  1134. }
  1135. if (cur_dispbuf) {
  1136. f2v_vphase_t *vphase;
  1137. u32 vin_type = cur_dispbuf->type & VIDTYPE_TYPEMASK;
  1138. {
  1139. viu_set_dcu(cur_frame_par, cur_dispbuf);
  1140. }
  1141. /* vertical phase */
  1142. vphase = &cur_frame_par->VPP_vf_ini_phase_[vpp_phase_table[vin_type][vout_type]];
  1143. WRITE_MPEG_REG(VPP2_VSC_INI_PHASE, ((u32)(vphase->phase) << 8));
  1144. if (vphase->repeat_skip >= 0) {
  1145. /* skip lines */
  1146. WRITE_MPEG_REG_BITS(VPP2_VSC_PHASE_CTRL,
  1147. skip_tab[vphase->repeat_skip],
  1148. VPP_PHASECTL_INIRCVNUMT_BIT,
  1149. VPP_PHASECTL_INIRCVNUM_WID +
  1150. VPP_PHASECTL_INIRPTNUM_WID);
  1151. } else {
  1152. /* repeat first line */
  1153. WRITE_MPEG_REG_BITS(VPP2_VSC_PHASE_CTRL, 4,
  1154. VPP_PHASECTL_INIRCVNUMT_BIT,
  1155. VPP_PHASECTL_INIRCVNUM_WID);
  1156. WRITE_MPEG_REG_BITS(VPP2_VSC_PHASE_CTRL,
  1157. 1 - vphase->repeat_skip,
  1158. VPP_PHASECTL_INIRPTNUMT_BIT,
  1159. VPP_PHASECTL_INIRPTNUM_WID);
  1160. }
  1161. }
  1162. if (((frame_par_ready_to_set) || (frame_par_force_to_set)) &&
  1163. (cur_frame_par)) {
  1164. vppfilter_mode_t *vpp_filter = &cur_frame_par->vpp_filter;
  1165. if (cur_dispbuf) {
  1166. u32 zoom_start_y, zoom_end_y;
  1167. if (cur_dispbuf->type & VIDTYPE_INTERLACE) {
  1168. if (cur_dispbuf->type & VIDTYPE_VIU_FIELD) {
  1169. zoom_start_y = cur_frame_par->VPP_vd_start_lines_ >> 1;
  1170. zoom_end_y = (cur_frame_par->VPP_vd_end_lines_ + 1) >> 1;
  1171. } else {
  1172. zoom_start_y = cur_frame_par->VPP_vd_start_lines_;
  1173. zoom_end_y = cur_frame_par->VPP_vd_end_lines_;
  1174. }
  1175. } else {
  1176. if (cur_dispbuf->type & VIDTYPE_VIU_FIELD) {
  1177. zoom_start_y = cur_frame_par->VPP_vd_start_lines_;
  1178. zoom_end_y = cur_frame_par->VPP_vd_end_lines_;
  1179. } else {
  1180. zoom_start_y = cur_frame_par->VPP_vd_start_lines_ >> 1;
  1181. zoom_end_y = (cur_frame_par->VPP_vd_end_lines_ + 1) >> 1;
  1182. }
  1183. }
  1184. zoom_start_x_lines = cur_frame_par->VPP_hd_start_lines_;
  1185. zoom_end_x_lines = cur_frame_par->VPP_hd_end_lines_;
  1186. zoom_display_horz();
  1187. zoom_start_y_lines = zoom_start_y;
  1188. zoom_end_y_lines = zoom_end_y;
  1189. zoom_display_vert();
  1190. }
  1191. /* vpp filters */
  1192. SET_MPEG_REG_MASK(VPP2_SC_MISC,
  1193. VPP_SC_TOP_EN | VPP_SC_VERT_EN | VPP_SC_HORZ_EN);
  1194. /* horitontal filter settings */
  1195. WRITE_MPEG_REG_BITS(VPP2_SC_MISC,
  1196. vpp_filter->vpp_horz_coeff[0],
  1197. VPP_SC_HBANK_LENGTH_BIT,
  1198. VPP_SC_BANK_LENGTH_WID);
  1199. if (vpp_filter->vpp_horz_coeff[1] & 0x8000) {
  1200. WRITE_MPEG_REG(VPP2_SCALE_COEF_IDX, VPP_COEF_HORZ | VPP_COEF_9BIT);
  1201. } else {
  1202. WRITE_MPEG_REG(VPP2_SCALE_COEF_IDX, VPP_COEF_HORZ);
  1203. }
  1204. for (i = 0; i < (vpp_filter->vpp_horz_coeff[1] & 0xff); i++) {
  1205. WRITE_MPEG_REG(VPP2_SCALE_COEF, vpp_filter->vpp_horz_coeff[i + 2]);
  1206. }
  1207. /* vertical filter settings */
  1208. WRITE_MPEG_REG_BITS(VPP2_SC_MISC,
  1209. vpp_filter->vpp_vert_coeff[0],
  1210. VPP_SC_VBANK_LENGTH_BIT,
  1211. VPP_SC_BANK_LENGTH_WID);
  1212. WRITE_MPEG_REG(VPP2_SCALE_COEF_IDX, VPP_COEF_VERT);
  1213. for (i = 0; i < vpp_filter->vpp_vert_coeff[1]; i++) {
  1214. WRITE_MPEG_REG(VPP2_SCALE_COEF,
  1215. vpp_filter->vpp_vert_coeff[i + 2]);
  1216. }
  1217. WRITE_MPEG_REG(VPP2_PIC_IN_HEIGHT,
  1218. cur_frame_par->VPP_pic_in_height_);
  1219. WRITE_MPEG_REG_BITS(VPP2_HSC_PHASE_CTRL,
  1220. cur_frame_par->VPP_hf_ini_phase_,
  1221. VPP_HSC_TOP_INI_PHASE_BIT,
  1222. VPP_HSC_TOP_INI_PHASE_WID);
  1223. WRITE_MPEG_REG(VPP2_POSTBLEND_VD1_H_START_END,
  1224. ((cur_frame_par->VPP_post_blend_vd_h_start_ & VPP_VD_SIZE_MASK) << VPP_VD1_START_BIT) |
  1225. ((cur_frame_par->VPP_post_blend_vd_h_end_ & VPP_VD_SIZE_MASK) << VPP_VD1_END_BIT));
  1226. WRITE_MPEG_REG(VPP2_POSTBLEND_VD1_V_START_END,
  1227. ((cur_frame_par->VPP_post_blend_vd_v_start_ & VPP_VD_SIZE_MASK) << VPP_VD1_START_BIT) |
  1228. ((cur_frame_par->VPP_post_blend_vd_v_end_ & VPP_VD_SIZE_MASK) << VPP_VD1_END_BIT));
  1229. WRITE_MPEG_REG(VPP2_POSTBLEND_H_SIZE, cur_frame_par->VPP_post_blend_h_size_);
  1230. vpp_settings_h(cur_frame_par);
  1231. vpp_settings_v(cur_frame_par);
  1232. frame_par_ready_to_set = 0;
  1233. frame_par_force_to_set = 0;
  1234. } /* VPP one time settings */
  1235. wait_sync = 0;
  1236. if(cur_dispbuf && cur_dispbuf->process_fun && (cur_dispbuf->duration > 0)){
  1237. /* for new deinterlace driver */
  1238. cur_dispbuf->process_fun(cur_dispbuf->private_data, zoom_start_x_lines, zoom_end_x_lines, zoom_start_y_lines, zoom_end_y_lines);
  1239. }
  1240. exit:
  1241. if(timer_count > 50){
  1242. timer_count = 0 ;
  1243. video_notify_flag |= VIDEO_NOTIFY_FRAME_WAIT;
  1244. #ifdef CONFIG_POST_PROCESS_MANAGER_PPSCALER
  1245. if((video_scaler_mode)&&(scaler_pos_changed)){
  1246. video_notify_flag |= VIDEO_NOTIFY_POS_CHANGED;
  1247. scaler_pos_changed = 0;
  1248. }else{
  1249. scaler_pos_changed = 0;
  1250. video_notify_flag &= ~VIDEO_NOTIFY_POS_CHANGED;
  1251. }
  1252. #endif
  1253. }
  1254. #ifdef FIQ_VSYNC
  1255. if (video_notify_flag)
  1256. fiq_bridge_pulse_trigger(&vsync_fiq_bridge);
  1257. #ifndef CONFIG_ARCH_MESON6
  1258. cur_timerb_value = (unsigned int)(0x10000-(READ_MPEG_REG(ISA_TIMERB)>>16));
  1259. if(cur_timerb_value >= last_isr_enter_time){
  1260. interval = cur_timerb_value-last_isr_enter_time;
  1261. }
  1262. else{
  1263. interval = cur_timerb_value + 0x10000 - last_isr_enter_time;
  1264. }
  1265. if(interval > isr_run_time_max){
  1266. isr_run_time_max = interval;
  1267. }
  1268. if(debug&0x1){
  1269. printk("[Video2] Leave %s %u %u\n", __func__, interval, cur_timerb_value);
  1270. }
  1271. #endif
  1272. #else
  1273. #ifndef VIDEO2_GET_VFRAME_DIRECTLY
  1274. if (video_notify_flag)
  1275. vsync_notify();
  1276. #endif
  1277. return IRQ_HANDLED;
  1278. #endif
  1279. }
  1280. static int alloc_keep_buffer(void)
  1281. {
  1282. amlog_mask(LOG_MASK_KEEPBUF, "alloc_keep_buffer\n");
  1283. keep_y_addr = __get_free_pages(GFP_KERNEL, get_order(Y_BUFFER_SIZE));
  1284. if (!keep_y_addr) {
  1285. amlog_mask(LOG_MASK_KEEPBUF, "%s: failed to alloc y addr\n", __FUNCTION__);
  1286. goto err1;
  1287. }
  1288. keep_y_addr_remap = ioremap_nocache(virt_to_phys((u8 *)keep_y_addr), Y_BUFFER_SIZE);
  1289. if (!keep_y_addr_remap) {
  1290. amlog_mask(LOG_MASK_KEEPBUF, "%s: failed to remap y addr\n", __FUNCTION__);
  1291. goto err2;
  1292. }
  1293. keep_u_addr = __get_free_pages(GFP_KERNEL, get_order(U_BUFFER_SIZE));
  1294. if (!keep_u_addr) {
  1295. amlog_mask(LOG_MASK_KEEPBUF, "%s: failed to alloc u addr\n", __FUNCTION__);
  1296. goto err3;
  1297. }
  1298. keep_u_addr_remap = ioremap_nocache(virt_to_phys((u8 *)keep_u_addr), U_BUFFER_SIZE);
  1299. if (!keep_u_addr_remap) {
  1300. amlog_mask(LOG_MASK_KEEPBUF, "%s: failed to remap u addr\n", __FUNCTION__);
  1301. goto err4;
  1302. }
  1303. keep_v_addr = __get_free_pages(GFP_KERNEL, get_order(V_BUFFER_SIZE));
  1304. if (!keep_v_addr) {
  1305. amlog_mask(LOG_MASK_KEEPBUF, "%s: failed to alloc v addr\n", __FUNCTION__);
  1306. goto err5;
  1307. }
  1308. keep_v_addr_remap = ioremap_nocache(virt_to_phys((u8 *)keep_v_addr), U_BUFFER_SIZE);
  1309. if (!keep_v_addr_remap) {
  1310. amlog_mask(LOG_MASK_KEEPBUF, "%s: failed to remap v addr\n", __FUNCTION__);
  1311. goto err6;
  1312. }
  1313. return 0;
  1314. err6:
  1315. free_pages(keep_v_addr, get_order(U_BUFFER_SIZE));
  1316. keep_v_addr = 0;
  1317. err5:
  1318. iounmap(keep_u_addr_remap);
  1319. keep_u_addr_remap = NULL;
  1320. err4:
  1321. free_pages(keep_u_addr, get_order(U_BUFFER_SIZE));
  1322. keep_u_addr = 0;
  1323. err3:
  1324. iounmap(keep_y_addr_remap);
  1325. keep_y_addr_remap = NULL;
  1326. err2:
  1327. free_pages(keep_y_addr, get_order(Y_BUFFER_SIZE));
  1328. keep_y_addr = 0;
  1329. err1:
  1330. return -ENOMEM;
  1331. }
  1332. /*********************************************************
  1333. * FIQ Routines
  1334. *********************************************************/
  1335. static void vsync_fiq_up(void)
  1336. {
  1337. #ifdef FIQ_VSYNC
  1338. request_fiq(INT_VIU2_VSYNC, &vsync_fisr2);
  1339. #else
  1340. int r;
  1341. r = request_irq(INT_VIU2_VSYNC, &vsync_isr,
  1342. IRQF_SHARED, "vsync2",
  1343. (void *)video_dev_id);
  1344. #endif
  1345. }
  1346. static void vsync_fiq_down(void)
  1347. {
  1348. #ifdef FIQ_VSYNC
  1349. free_fiq(INT_VIU2_VSYNC, &vsync_fisr2);
  1350. #else
  1351. free_irq(INT_VIU2_VSYNC, (void *)video_dev_id);
  1352. #endif
  1353. }
  1354. /*int get_curren_frame_para(int* top ,int* left , int* bottom, int* right)
  1355. {
  1356. if(!cur_frame_par){
  1357. return -1;
  1358. }
  1359. *top = cur_frame_par->VPP_vd_start_lines_ ;
  1360. *left = cur_frame_par->VPP_hd_start_lines_ ;
  1361. *bottom = cur_frame_par->VPP_vd_end_lines_ ;
  1362. *right = cur_frame_par->VPP_hd_end_lines_;
  1363. return 0;
  1364. }*/
  1365. static void video_vf_unreg_provider(void)
  1366. {
  1367. ulong flags;
  1368. spin_lock_irqsave(&lock, flags);
  1369. if (cur_dispbuf) {
  1370. vf_local = *cur_dispbuf;
  1371. cur_dispbuf = &vf_local;
  1372. }
  1373. if (trickmode_fffb) {
  1374. atomic_set(&trickmode_framedone, 0);
  1375. }
  1376. if (blackout) {
  1377. #ifdef CONFIG_POST_PROCESS_MANAGER_PPSCALER
  1378. if(video_scaler_mode)
  1379. DisableVideoLayer_PREBELEND();
  1380. else
  1381. DisableVideoLayer();
  1382. #else
  1383. DisableVideoLayer();
  1384. #endif
  1385. }
  1386. //if (!trickmode_fffb)
  1387. {
  1388. printk("video2 %s\n", __func__);
  1389. //vf_keep_current();
  1390. }
  1391. if((clone == 0)&&(stream_play_enable == 1)){
  1392. tsync_avevent(VIDEO_STOP, 0);
  1393. }
  1394. spin_unlock_irqrestore(&lock, flags);
  1395. }
  1396. static void video_vf_light_unreg_provider(void)
  1397. {
  1398. ulong flags;
  1399. spin_lock_irqsave(&lock, flags);
  1400. if (cur_dispbuf) {
  1401. vf_local = *cur_dispbuf;
  1402. cur_dispbuf = &vf_local;
  1403. }
  1404. spin_unlock_irqrestore(&lock, flags);
  1405. }
  1406. static int video_receiver_event_fun(int type, void* data, void* private_data)
  1407. {
  1408. if(type == VFRAME_EVENT_PROVIDER_REG){
  1409. #ifdef VIDEO2_GET_VFRAME_DIRECTLY
  1410. prov = vf_get_provider(RECEIVER_NAME);
  1411. printk("video2 %s set prov\n", __func__);
  1412. #endif
  1413. stream_play_enable = 1;
  1414. }
  1415. else if(type == VFRAME_EVENT_PROVIDER_UNREG){
  1416. #ifdef VIDEO2_GET_VFRAME_DIRECTLY
  1417. prov = NULL;
  1418. #endif
  1419. video_vf_unreg_provider();
  1420. stream_play_enable = 0;
  1421. }
  1422. else if(type == VFRAME_EVENT_PROVIDER_LIGHT_UNREG){
  1423. video_vf_light_unreg_provider();
  1424. }
  1425. return 0;
  1426. }
  1427. /*unsigned int get_post_canvas(void)
  1428. {
  1429. return post_canvas;
  1430. }*/
  1431. static int canvas_dup(ulong *dst, ulong src_paddr, ulong size)
  1432. {
  1433. void __iomem *p = ioremap_wc(src_paddr, size);
  1434. if (p) {
  1435. memcpy(dst, p, size);
  1436. iounmap(p);
  1437. return 1;
  1438. }
  1439. return 0;
  1440. }
  1441. #if 0
  1442. unsigned int vf_keep_current(void)
  1443. {
  1444. u32 cur_index;
  1445. u32 y_index, u_index, v_index;
  1446. canvas_t cs0,cs1,cs2,cd;
  1447. if (blackout) {
  1448. return 0;
  1449. }
  1450. if (0 == (READ_MPEG_REG(VPP2_MISC) & VPP_VD1_POSTBLEND)) {
  1451. return 0;
  1452. }
  1453. if (!keep_y_addr_remap) {
  1454. //if (alloc_keep_buffer())
  1455. return -1;
  1456. }
  1457. cur_index = READ_MPEG_REG(VIU2_VD1_IF0_CANVAS0);
  1458. y_index = cur_index & 0xff;
  1459. u_index = (cur_index >> 8) & 0xff;
  1460. v_index = (cur_index >> 16) & 0xff;
  1461. if ((cur_dispbuf->type & VIDTYPE_VIU_422) == VIDTYPE_VIU_422) {
  1462. canvas_read(y_index,&cd);
  1463. if (keep_y_addr != canvas_get_addr(y_index) && /*must not the same address*/
  1464. canvas_dup(keep_y_addr_remap, canvas_get_addr(y_index), (cd.width)*(cd.height))) {
  1465. canvas_update_addr(y_index, (u32)keep_y_addr);
  1466. }
  1467. } else if ((cur_dispbuf->type & VIDTYPE_VIU_444) == VIDTYPE_VIU_444) {
  1468. canvas_read(y_index,&cd);
  1469. if (keep_y_addr != canvas_get_addr(y_index) && /*must not the same address*/
  1470. canvas_dup(keep_y_addr_remap, canvas_get_addr(y_index), (cd.width)*(cd.height))){
  1471. canvas_update_addr(y_index, (u32)keep_y_addr);
  1472. }
  1473. } else {
  1474. canvas_read(y_index,&cs0);
  1475. canvas_read(u_index,&cs1);
  1476. canvas_read(v_index,&cs2);
  1477. if (keep_y_addr != canvas_get_addr(y_index) && /*must not the same address*/
  1478. canvas_dup(keep_y_addr_remap, canvas_get_addr(y_index), (cs0.width *cs0.height)) &&
  1479. canvas_dup(keep_u_addr_remap, canvas_get_addr(u_index), (cs1.width *cs1.height)) &&
  1480. canvas_dup(keep_v_addr_remap, canvas_get_addr(v_index), (cs2.width *cs2.height))) {
  1481. canvas_update_addr(y_index, (u32)keep_y_addr);
  1482. canvas_update_addr(u_index, (u32)keep_u_addr);
  1483. canvas_update_addr(v_index, (u32)keep_v_addr);
  1484. }
  1485. }
  1486. return 0;
  1487. }
  1488. EXPORT_SYMBOL(get_post_canvas);
  1489. EXPORT_SYMBOL(vf_keep_current);
  1490. #endif
  1491. /*********************************************************
  1492. * /dev/amvideo APIs
  1493. *********************************************************/
  1494. static int amvideo_open(struct inode *inode, struct file *file)
  1495. {
  1496. return 0;
  1497. }
  1498. static int amvideo_release(struct inode *inode, struct file *file)
  1499. {
  1500. if (blackout) {
  1501. ///DisableVideoLayer();/*don't need it ,it have problem on pure music playing*/
  1502. }
  1503. return 0;
  1504. }
  1505. static int amvideo_ioctl(struct inode *inode, struct file *file,
  1506. unsigned int cmd, ulong arg)
  1507. {
  1508. int ret = 0;
  1509. switch (cmd) {
  1510. case AMSTREAM_IOC_TRICKMODE:
  1511. if (arg == TRICKMODE_I) {
  1512. trickmode_i = 1;
  1513. } else if (arg == TRICKMODE_FFFB) {
  1514. trickmode_fffb = 1;
  1515. } else {
  1516. trickmode_i = 0;
  1517. trickmode_fffb = 0;
  1518. }
  1519. atomic_set(&trickmode_framedone, 0);
  1520. tsync_trick_mode(trickmode_fffb);
  1521. break;
  1522. case AMSTREAM_IOC_TRICK_STAT:
  1523. *((u32 *)arg) = atomic_read(&trickmode_framedone);
  1524. break;
  1525. case AMSTREAM_IOC_VPAUSE:
  1526. tsync_avevent(VIDEO_PAUSE, arg);
  1527. break;
  1528. case AMSTREAM_IOC_AVTHRESH:
  1529. tsync_set_avthresh(arg);
  1530. break;
  1531. case AMSTREAM_IOC_SYNCTHRESH:
  1532. tsync_set_syncthresh(arg);
  1533. break;
  1534. case AMSTREAM_IOC_SYNCENABLE:
  1535. tsync_set_enable(arg);
  1536. break;
  1537. //case AMSTREAM_IOC_SET_SYNCDISCON:
  1538. // tsync_set_syncdiscont(arg);
  1539. // break;
  1540. //case AMSTREAM_IOC_GET_SYNCDISCON:
  1541. // *((u32 *)arg) = tsync_get_syncdiscont();
  1542. // break;
  1543. case AMSTREAM_IOC_CLEAR_VBUF: {
  1544. unsigned long flags;
  1545. spin_lock_irqsave(&lock, flags);
  1546. cur_dispbuf = NULL;
  1547. spin_unlock_irqrestore(&lock, flags);
  1548. }
  1549. break;
  1550. #ifndef CONFIG_ARCH_MESON6
  1551. /**********************************************************************
  1552. video enhancement ioctl
  1553. **********************************************************************/
  1554. case AMSTREAM_IOC_VE_DEBUG: {
  1555. struct ve_regs_s data;
  1556. #if 0
  1557. if (get_user((unsigned long long)data, (void __user *)arg))
  1558. #else
  1559. if (copy_from_user(&data, (void __user *)arg, sizeof(struct ve_regs_s)))
  1560. #endif
  1561. {
  1562. ret = -EFAULT;
  1563. } else {
  1564. ve_set_regs(&data);
  1565. if (!(data.mode)) { // read
  1566. #if 0
  1567. if (put_user((unsigned long long)data, (void __user *)arg))
  1568. #else
  1569. if (copy_to_user(&data, (void __user *)arg, sizeof(struct ve_regs_s)))
  1570. #endif
  1571. {
  1572. ret = -EFAULT;
  1573. }
  1574. }
  1575. }
  1576. break;
  1577. }
  1578. case AMSTREAM_IOC_VE_BEXT: {
  1579. struct ve_bext_s ve_bext;
  1580. if (copy_from_user(&ve_bext, (void __user *)arg, sizeof(struct ve_bext_s))) {
  1581. ret = -EFAULT;
  1582. break;
  1583. }
  1584. ve_set_bext(&ve_bext);
  1585. break;
  1586. }
  1587. case AMSTREAM_IOC_VE_DNLP: {
  1588. struct ve_dnlp_s ve_dnlp;
  1589. if (copy_from_user(&ve_dnlp, (void __user *)arg, sizeof(struct ve_dnlp_s))) {
  1590. ret = -EFAULT;
  1591. break;
  1592. }
  1593. ve_set_dnlp(&ve_dnlp);
  1594. break;
  1595. }
  1596. case AMSTREAM_IOC_VE_HSVS: {
  1597. struct ve_hsvs_s ve_hsvs;
  1598. if (copy_from_user(&ve_hsvs, (void __user *)arg, sizeof(struct ve_hsvs_s))) {
  1599. ret = -EFAULT;
  1600. break;
  1601. }
  1602. ve_set_hsvs(&ve_hsvs);
  1603. break;
  1604. }
  1605. case AMSTREAM_IOC_VE_CCOR: {
  1606. struct ve_ccor_s ve_ccor;
  1607. if (copy_from_user(&ve_ccor, (void __user *)arg, sizeof(struct ve_ccor_s))) {
  1608. ret = -EFAULT;
  1609. break;
  1610. }
  1611. ve_set_ccor(&ve_ccor);
  1612. break;
  1613. }
  1614. case AMSTREAM_IOC_VE_BENH: {
  1615. struct ve_benh_s ve_benh;
  1616. if (copy_from_user(&ve_benh, (void __user *)arg, sizeof(struct ve_benh_s))) {
  1617. ret = -EFAULT;
  1618. break;
  1619. }
  1620. ve_set_benh(&ve_benh);
  1621. break;
  1622. }
  1623. case AMSTREAM_IOC_VE_DEMO: {
  1624. struct ve_demo_s ve_demo;
  1625. if (copy_from_user(&ve_demo, (void __user *)arg, sizeof(struct ve_demo_s))) {
  1626. ret = -EFAULT;
  1627. break;
  1628. }
  1629. ve_set_demo(&ve_demo);
  1630. break;
  1631. }
  1632. /**********************************************************************
  1633. color management ioctl
  1634. **********************************************************************/
  1635. case AMSTREAM_IOC_CM_DEBUG: {
  1636. struct cm_regs_s data;
  1637. if (copy_from_user(&data, (void __user *)arg, sizeof(struct cm_regs_s))) {
  1638. ret = -EFAULT;
  1639. } else {
  1640. cm_set_regs(&data);
  1641. if (!(data.mode)) { // read
  1642. if (copy_to_user(&data, (void __user *)arg, sizeof(struct cm_regs_s))) {
  1643. ret = -EFAULT;
  1644. }
  1645. }
  1646. }
  1647. break;
  1648. }
  1649. case AMSTREAM_IOC_CM_REGION: {
  1650. struct cm_region_s cm_region;
  1651. if (copy_from_user(&cm_region, (void __user *)arg, sizeof(struct cm_region_s))) {
  1652. ret = -EFAULT;
  1653. break;
  1654. }
  1655. cm_set_region(&cm_region);
  1656. break;
  1657. }
  1658. case AMSTREAM_IOC_CM_TOP: {
  1659. struct cm_top_s cm_top;
  1660. if (copy_from_user(&cm_top, (void __user *)arg, sizeof(struct cm_top_s))) {
  1661. ret = -EFAULT;
  1662. break;
  1663. }
  1664. cm_set_top(&cm_top);
  1665. break;
  1666. }
  1667. case AMSTREAM_IOC_CM_DEMO: {
  1668. struct cm_demo_s cm_demo;
  1669. if (copy_from_user(&cm_demo, (void __user *)arg, sizeof(struct cm_demo_s))) {
  1670. ret = -EFAULT;
  1671. break;
  1672. }
  1673. cm_set_demo(&cm_demo);
  1674. break;
  1675. }
  1676. #endif
  1677. default:
  1678. return -EINVAL;
  1679. }
  1680. return 0;
  1681. }
  1682. static unsigned int amvideo_poll(struct file *file, poll_table *wait_table)
  1683. {
  1684. poll_wait(file, &amvideo_trick_wait, wait_table);
  1685. if (atomic_read(&trickmode_framedone)) {
  1686. atomic_set(&trickmode_framedone, 0);
  1687. return POLLOUT | POLLWRNORM;
  1688. }
  1689. return 0;
  1690. }
  1691. const static struct file_operations amvideo_fops = {
  1692. .owner = THIS_MODULE,
  1693. .open = amvideo_open,
  1694. .release = amvideo_release,
  1695. #ifdef CONFIG_ARCH_MESON6
  1696. .unlocked_ioctl = amvideo_ioctl,
  1697. #else
  1698. .ioctl = amvideo_ioctl,
  1699. #endif
  1700. .poll = amvideo_poll,
  1701. };
  1702. /*********************************************************
  1703. * SYSFS property functions
  1704. *********************************************************/
  1705. #define MAX_NUMBER_PARA 10
  1706. #define AMVIDEO_CLASS_NAME "video2"
  1707. static int parse_para(const char *para, int para_num, int *result)
  1708. {
  1709. char *endp;
  1710. const char *startp = para;
  1711. int *out = result;
  1712. int len = 0, count = 0;
  1713. if (!startp) {
  1714. return 0;
  1715. }
  1716. len = strlen(startp);
  1717. do {
  1718. //filter space out
  1719. while (startp && (isspace(*startp) || !isgraph(*startp)) && len) {
  1720. startp++;
  1721. len--;
  1722. }
  1723. if (len == 0) {
  1724. break;
  1725. }
  1726. *out++ = simple_strtol(startp, &endp, 0);
  1727. len -= endp - startp;
  1728. startp = endp;
  1729. count++;
  1730. } while ((endp) && (count < para_num) && (len > 0));
  1731. return count;
  1732. }
  1733. static void set_video_window(const char *para)
  1734. {
  1735. int parsed[4];
  1736. if (likely(parse_para(para, 4, parsed) == 4)) {
  1737. int w, h;
  1738. w = parsed[2] - parsed[0] + 1;
  1739. h = parsed[3] - parsed[1] + 1;
  1740. #ifdef CONFIG_POST_PROCESS_MANAGER_PPSCALER
  1741. if(video_scaler_mode){
  1742. if ((w == 1) && (h == 1)){
  1743. w= 0;
  1744. h = 0;
  1745. }
  1746. if((content_left!=parsed[0])||(content_top!=parsed[1])||(content_w!=w)||(content_h!=h))
  1747. scaler_pos_changed = 1;
  1748. content_left = parsed[0];
  1749. content_top = parsed[1];
  1750. content_w = w;
  1751. content_h = h;
  1752. //video_notify_flag = video_notify_flag|VIDEO_NOTIFY_POS_CHANGED;
  1753. }else
  1754. #endif
  1755. {
  1756. if ((w == 1) && (h == 1)) {
  1757. w = h = 0;
  1758. vpp2_set_video_layer_position(parsed[0], parsed[1], 0, 0);
  1759. } else if ((w > 0) && (h > 0)) {
  1760. vpp2_set_video_layer_position(parsed[0], parsed[1], w, h);
  1761. }
  1762. }
  1763. video_property_changed = true;
  1764. }
  1765. amlog_mask(LOG_MASK_SYSFS,
  1766. "video=>x0:%d,y0:%d,x1:%d,y1:%d\r\n ",
  1767. parsed[0], parsed[1], parsed[2], parsed[3]);
  1768. }
  1769. static ssize_t video_axis_show(struct class *cla, struct class_attribute *attr, char *buf)
  1770. {
  1771. int x, y, w, h;
  1772. #ifdef CONFIG_POST_PROCESS_MANAGER_PPSCALER
  1773. if(video_scaler_mode){
  1774. x = content_left;
  1775. y = content_top;
  1776. w = content_w;
  1777. h = content_h;
  1778. }else
  1779. #endif
  1780. {
  1781. vpp2_get_video_layer_position(&x, &y, &w, &h);
  1782. }
  1783. return snprintf(buf, 40, "%d %d %d %d\n", x, y, x + w - 1, y + h - 1);
  1784. }
  1785. static ssize_t video_axis_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1786. size_t count)
  1787. {
  1788. mutex_lock(&video_module_mutex);
  1789. set_video_window(buf);
  1790. mutex_unlock(&video_module_mutex);
  1791. return strnlen(buf, count);
  1792. }
  1793. static ssize_t video_zoom_show(struct class *cla, struct class_attribute *attr, char *buf)
  1794. {
  1795. u32 r = vpp2_get_zoom_ratio();
  1796. return snprintf(buf, 40, "%d\n", r);
  1797. }
  1798. static ssize_t video_zoom_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1799. size_t count)
  1800. {
  1801. u32 r;
  1802. char *endp;
  1803. r = simple_strtoul(buf, &endp, 0);
  1804. if ((r <= MAX_ZOOM_RATIO) && (r != vpp2_get_zoom_ratio())) {
  1805. vpp2_set_zoom_ratio(r);
  1806. video_property_changed = true;
  1807. }
  1808. return count;
  1809. }
  1810. static ssize_t video_screen_mode_show(struct class *cla, struct class_attribute *attr, char *buf)
  1811. {
  1812. const char *wide_str[] = {"normal", "full stretch", "4-3", "16-9", "normal-noscaleup"};
  1813. if (wide_setting < ARRAY_SIZE(wide_str)) {
  1814. return sprintf(buf, "%d:%s\n", wide_setting, wide_str[wide_setting]);
  1815. } else {
  1816. return 0;
  1817. }
  1818. }
  1819. static ssize_t video_screen_mode_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1820. size_t count)
  1821. {
  1822. unsigned long mode;
  1823. char *endp;
  1824. mode = simple_strtol(buf, &endp, 0);
  1825. if ((mode < VIDEO_WIDEOPTION_MAX) && (mode != wide_setting)) {
  1826. wide_setting = mode;
  1827. video_property_changed = true;
  1828. }
  1829. return count;
  1830. }
  1831. static ssize_t video_blackout_policy_show(struct class *cla, struct class_attribute *attr, char *buf)
  1832. {
  1833. return sprintf(buf, "%d\n", blackout);
  1834. }
  1835. static ssize_t video_blackout_policy_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1836. size_t count)
  1837. {
  1838. size_t r;
  1839. r = sscanf(buf, "%d", &blackout);
  1840. if (r != 1) {
  1841. return -EINVAL;
  1842. }
  1843. return count;
  1844. }
  1845. static ssize_t video_brightness_show(struct class *cla, struct class_attribute *attr, char *buf)
  1846. {
  1847. s32 val = (READ_MPEG_REG(VPP2_VADJ1_Y) >> 8) & 0x1ff;
  1848. val = (val << 23) >> 23;
  1849. return sprintf(buf, "%d\n", val);
  1850. }
  1851. static ssize_t video_brightness_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1852. size_t count)
  1853. {
  1854. size_t r;
  1855. int val;
  1856. r = sscanf(buf, "%d", &val);
  1857. if ((r != 1) || (val < -255) || (val > 255)) {
  1858. return -EINVAL;
  1859. }
  1860. WRITE_MPEG_REG_BITS(VPP2_VADJ1_Y, val, 8, 9);
  1861. WRITE_MPEG_REG(VPP2_VADJ_CTRL, VPP_VADJ1_EN);
  1862. return count;
  1863. }
  1864. static ssize_t video_contrast_show(struct class *cla, struct class_attribute *attr, char *buf)
  1865. {
  1866. return sprintf(buf, "%d\n", (int)(READ_MPEG_REG(VPP2_VADJ1_Y) & 0xff) - 0x80);
  1867. }
  1868. static ssize_t video_contrast_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1869. size_t count)
  1870. {
  1871. size_t r;
  1872. int val;
  1873. r = sscanf(buf, "%d", &val);
  1874. if ((r != 1) || (val < -127) || (val > 127)) {
  1875. return -EINVAL;
  1876. }
  1877. val += 0x80;
  1878. WRITE_MPEG_REG_BITS(VPP2_VADJ1_Y, val, 0, 8);
  1879. WRITE_MPEG_REG(VPP2_VADJ_CTRL, VPP_VADJ1_EN);
  1880. return count;
  1881. }
  1882. static ssize_t video_saturation_show(struct class *cla, struct class_attribute *attr, char *buf)
  1883. {
  1884. return sprintf(buf, "%d\n", READ_MPEG_REG(VPP2_VADJ1_Y) & 0xff);
  1885. }
  1886. static ssize_t video_saturation_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1887. size_t count)
  1888. {
  1889. size_t r;
  1890. int val;
  1891. r = sscanf(buf, "%d", &val);
  1892. if ((r != 1) || (val < -127) || (val > 127)) {
  1893. return -EINVAL;
  1894. }
  1895. WRITE_MPEG_REG_BITS(VPP2_VADJ1_Y, val, 0, 8);
  1896. WRITE_MPEG_REG(VPP2_VADJ_CTRL, VPP_VADJ1_EN);
  1897. return count;
  1898. }
  1899. static ssize_t video_disable_show(struct class *cla, struct class_attribute *attr, char *buf)
  1900. {
  1901. return sprintf(buf, "%d\n", disable_video);
  1902. }
  1903. static ssize_t video_disable_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1904. size_t count)
  1905. {
  1906. size_t r;
  1907. int val;
  1908. r = sscanf(buf, "%d", &val);
  1909. if (r != 1) {
  1910. return -EINVAL;
  1911. }
  1912. printk("video disable try be changed to %d by %s\n",val,current->comm);
  1913. if ((val < VIDEO_DISABLE_NONE) || (val > VIDEO_DISABLE_FORNEXT)) {
  1914. return -EINVAL;
  1915. }
  1916. disable_video = val;
  1917. if (disable_video != VIDEO_DISABLE_NONE) {
  1918. #ifdef CONFIG_POST_PROCESS_MANAGER_PPSCALER
  1919. if(video_scaler_mode)
  1920. DisableVideoLayer_PREBELEND();
  1921. else
  1922. DisableVideoLayer();
  1923. #else
  1924. DisableVideoLayer();
  1925. #endif
  1926. if ((disable_video == VIDEO_DISABLE_FORNEXT) && cur_dispbuf && (cur_dispbuf != &vf_local))
  1927. video_property_changed = true;
  1928. } else {
  1929. if (cur_dispbuf && (cur_dispbuf != &vf_local)) {
  1930. EnableVideoLayer();
  1931. }
  1932. }
  1933. return count;
  1934. }
  1935. static int tvin_started = 0;
  1936. static void stop_clone(void)
  1937. {
  1938. #ifdef CONFIG_TVIN_VIUIN
  1939. if(tvin_started){
  1940. stop_tvin_service(0);
  1941. tvin_started=0;
  1942. }
  1943. #endif
  1944. }
  1945. static int start_clone(void)
  1946. {
  1947. int ret = -1;
  1948. #ifdef CONFIG_TVIN_VIUIN
  1949. tvin_parm_t para;
  1950. const vinfo_t *info = get_current_vinfo();
  1951. if(tvin_started){
  1952. stop_tvin_service(0);
  1953. tvin_started=0;
  1954. ret = 0;
  1955. }
  1956. if(info){
  1957. printk("%s source is %s\n", __func__, info->name);
  1958. clone_vpts_remainder = 0;
  1959. para.fmt_info.h_active = info->width;
  1960. para.fmt_info.v_active = info->height;
  1961. para.port = TVIN_PORT_VIU_ENCT;
  1962. para.fmt_info.fmt = TVIN_SIG_FMT_MAX+1;//TVIN_SIG_FMT_MAX+1;TVIN_SIG_FMT_CAMERA_1280X720P_30Hz
  1963. para.fmt_info.frame_rate = clone_frame_rate*10;
  1964. para.fmt_info.hsync_phase = 1;
  1965. para.fmt_info.vsync_phase = 0;
  1966. start_tvin_service(0,&para);
  1967. tvin_started = 1;
  1968. printk("%s: source %dx%d\n", __func__,info->width, info->height);
  1969. ret = 0;
  1970. }
  1971. #endif
  1972. return ret;
  1973. }
  1974. static ssize_t video_clone_show(struct class *cla, struct class_attribute *attr, char *buf)
  1975. {
  1976. return sprintf(buf, "%d\n", clone);
  1977. }
  1978. static ssize_t video_clone_store(struct class *cla, struct class_attribute *attr, const char *buf,
  1979. size_t count)
  1980. {
  1981. size_t r;
  1982. int val;
  1983. r = sscanf(buf, "%d", &val);
  1984. if (r != 1) {
  1985. return -EINVAL;
  1986. }
  1987. printk("video clone try be changed to %d by %s\n",val,current->comm);
  1988. if ((val < 0) || (val > 1)) {
  1989. return -EINVAL;
  1990. }
  1991. if(clone != val){
  1992. if (val != 0) {
  1993. start_clone();
  1994. clone = 1;
  1995. } else {
  1996. stop_clone();
  1997. clone = 0;
  1998. }
  1999. }
  2000. return count;
  2001. }
  2002. static ssize_t frame_addr_show(struct class *cla, struct class_attribute *attr, char *buf)
  2003. {
  2004. canvas_t canvas;
  2005. u32 addr[3];
  2006. if (cur_dispbuf) {
  2007. canvas_read(cur_dispbuf->canvas0Addr & 0xff, &canvas);
  2008. addr[0] = canvas.addr;
  2009. canvas_read((cur_dispbuf->canvas0Addr >> 8) & 0xff, &canvas);
  2010. addr[1] = canvas.addr;
  2011. canvas_read((cur_dispbuf->canvas0Addr >> 16) & 0xff, &canvas);
  2012. addr[2] = canvas.addr;
  2013. return sprintf(buf, "0x%x-0x%x-0x%x\n", addr[0], addr[1], addr[2]);
  2014. }
  2015. return sprintf(buf, "NA\n");
  2016. }
  2017. static ssize_t frame_canvas_width_show(struct class *cla, struct class_attribute *attr, char *buf)
  2018. {
  2019. canvas_t canvas;
  2020. u32 width[3];
  2021. if (cur_dispbuf) {
  2022. canvas_read(cur_dispbuf->canvas0Addr & 0xff, &canvas);
  2023. width[0] = canvas.width;
  2024. canvas_read((cur_dispbuf->canvas0Addr >> 8) & 0xff, &canvas);
  2025. width[1] = canvas.width;
  2026. canvas_read((cur_dispbuf->canvas0Addr >> 16) & 0xff, &canvas);
  2027. width[2] = canvas.width;
  2028. return sprintf(buf, "%d-%d-%d\n", width[0], width[1], width[2]);
  2029. }
  2030. return sprintf(buf, "NA\n");
  2031. }
  2032. static ssize_t frame_canvas_height_show(struct class *cla, struct class_attribute *attr, char *buf)
  2033. {
  2034. canvas_t canvas;
  2035. u32 height[3];
  2036. if (cur_dispbuf) {
  2037. canvas_read(cur_dispbuf->canvas0Addr & 0xff, &canvas);
  2038. height[0] = canvas.height;
  2039. canvas_read((cur_dispbuf->canvas0Addr >> 8) & 0xff, &canvas);
  2040. height[1] = canvas.height;
  2041. canvas_read((cur_dispbuf->canvas0Addr >> 16) & 0xff, &canvas);
  2042. height[2] = canvas.height;
  2043. return sprintf(buf, "%d-%d-%d\n", height[0], height[1], height[2]);
  2044. }
  2045. return sprintf(buf, "NA\n");
  2046. }
  2047. static ssize_t frame_width_show(struct class *cla, struct class_attribute *attr, char *buf)
  2048. {
  2049. if (cur_dispbuf) {
  2050. return sprintf(buf, "%d\n", cur_dispbuf->width);
  2051. }
  2052. return sprintf(buf, "NA\n");
  2053. }
  2054. static ssize_t frame_height_show(struct class *cla, struct class_attribute *attr, char *buf)
  2055. {
  2056. if (cur_dispbuf) {
  2057. return sprintf(buf, "%d\n", cur_dispbuf->height);
  2058. }
  2059. return sprintf(buf, "NA\n");
  2060. }
  2061. static ssize_t frame_format_show(struct class *cla, struct class_attribute *attr, char *buf)
  2062. {
  2063. if (cur_dispbuf) {
  2064. if ((cur_dispbuf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_TOP) {
  2065. return sprintf(buf, "interlace-top\n");
  2066. } else if ((cur_dispbuf->type & VIDTYPE_TYPEMASK) == VIDTYPE_INTERLACE_BOTTOM) {
  2067. return sprintf(buf, "interlace-bottom\n");
  2068. } else {
  2069. return sprintf(buf, "progressive\n");
  2070. }
  2071. }
  2072. return sprintf(buf, "NA\n");
  2073. }
  2074. static ssize_t frame_aspect_ratio_show(struct class *cla, struct class_attribute *attr, char *buf)
  2075. {
  2076. if (cur_dispbuf) {
  2077. u32 ar = (cur_dispbuf->ratio_control & DISP_RATIO_ASPECT_RATIO_MASK)
  2078. >> DISP_RATIO_ASPECT_RATIO_BIT;
  2079. if (ar) {
  2080. return sprintf(buf, "0x%x\n", ar);
  2081. } else
  2082. return sprintf(buf, "0x%x\n",
  2083. (cur_dispbuf->width << 8) / cur_dispbuf->height);
  2084. }
  2085. return sprintf(buf, "NA\n");
  2086. }
  2087. static ssize_t frame_rate_show(struct class *cla, struct class_attribute* attr, char* buf)
  2088. {
  2089. u32 cnt = frame_count - last_frame_count;
  2090. u32 time = jiffies;
  2091. u32 tmp = time;
  2092. u32 rate = 0;
  2093. size_t ret;
  2094. time -= last_frame_time;
  2095. last_frame_time = tmp;
  2096. last_frame_count = frame_count;
  2097. rate = cnt * HZ / time;
  2098. ret = sprintf(buf, "Frame rate is %d, and the panel refresh rate is %d, duration is: %d\n",
  2099. rate, vinfo->sync_duration_num / vinfo->sync_duration_den, time);
  2100. return ret;
  2101. }
  2102. static ssize_t vframe_states_show(struct class *cla, struct class_attribute* attr, char* buf)
  2103. {
  2104. int ret = 0;
  2105. vframe_states_t states;
  2106. if (vf_get_states(&states) == 0) {
  2107. ret += sprintf(buf + ret, "vframe_pool_size=%d\n", states.vf_pool_size);
  2108. ret += sprintf(buf + ret, "vframe buf_free_num=%d\n", states.buf_free_num);
  2109. ret += sprintf(buf + ret, "vframe buf_recycle_num=%d\n", states.buf_recycle_num);
  2110. ret += sprintf(buf + ret, "vframe buf_avail_num=%d\n", states.buf_avail_num);
  2111. } else {
  2112. ret += sprintf(buf + ret, "vframe no states\n");
  2113. }
  2114. return ret;
  2115. }
  2116. static ssize_t device_resolution_show(struct class *cla, struct class_attribute* attr, char* buf)
  2117. {
  2118. const vinfo_t *info = get_current_vinfo2();
  2119. if (info != NULL) {
  2120. return sprintf(buf, "%dx%d\n", info->width, info->height);
  2121. } else {
  2122. return sprintf(buf, "0x0\n");
  2123. }
  2124. }
  2125. static struct class_attribute amvideo_class_attrs[] = {
  2126. __ATTR(axis,
  2127. S_IRUGO | S_IWUSR,
  2128. video_axis_show,
  2129. video_axis_store),
  2130. __ATTR(screen_mode,
  2131. S_IRUGO | S_IWUSR,
  2132. video_screen_mode_show,
  2133. video_screen_mode_store),
  2134. __ATTR(blackout_policy,
  2135. S_IRUGO | S_IWUSR,
  2136. video_blackout_policy_show,
  2137. video_blackout_policy_store),
  2138. __ATTR(disable_video,
  2139. S_IRUGO | S_IWUSR,
  2140. video_disable_show,
  2141. video_disable_store),
  2142. __ATTR(zoom,
  2143. S_IRUGO | S_IWUSR,
  2144. video_zoom_show,
  2145. video_zoom_store),
  2146. __ATTR(brightness,
  2147. S_IRUGO | S_IWUSR,
  2148. video_brightness_show,
  2149. video_brightness_store),
  2150. __ATTR(contrast,
  2151. S_IRUGO | S_IWUSR,
  2152. video_contrast_show,
  2153. video_contrast_store),
  2154. __ATTR(saturation,
  2155. S_IRUGO | S_IWUSR,
  2156. video_saturation_show,
  2157. video_saturation_store),
  2158. __ATTR(clone,
  2159. S_IRUGO | S_IWUSR,
  2160. video_clone_show,
  2161. video_clone_store),
  2162. __ATTR_RO(device_resolution),
  2163. __ATTR_RO(frame_addr),
  2164. __ATTR_RO(frame_canvas_width),
  2165. __ATTR_RO(frame_canvas_height),
  2166. __ATTR_RO(frame_width),
  2167. __ATTR_RO(frame_height),
  2168. __ATTR_RO(frame_format),
  2169. __ATTR_RO(frame_aspect_ratio),
  2170. __ATTR_RO(frame_rate),
  2171. __ATTR_RO(vframe_states),
  2172. __ATTR_NULL
  2173. };
  2174. #ifdef CONFIG_PM
  2175. static int amvideo_class_suspend(struct device *dev, pm_message_t state)
  2176. {
  2177. pm_state.event = state.event;
  2178. if (state.event == PM_EVENT_SUSPEND) {
  2179. pm_state.vpp_misc = READ_MPEG_REG(VPP2_MISC);
  2180. DisableVideoLayer();
  2181. msleep(50);
  2182. }
  2183. return 0;
  2184. }
  2185. static int amvideo_class_resume(struct device *dev)
  2186. {
  2187. if (pm_state.event == PM_EVENT_SUSPEND) {
  2188. WRITE_MPEG_REG(VPP2_MISC, pm_state.vpp_misc);
  2189. pm_state.event = -1;
  2190. }
  2191. return 0;
  2192. }
  2193. #endif
  2194. static struct class amvideo_class = {
  2195. .name = AMVIDEO_CLASS_NAME,
  2196. .class_attrs = amvideo_class_attrs,
  2197. #ifdef CONFIG_PM
  2198. .suspend = amvideo_class_suspend,
  2199. .resume = amvideo_class_resume,
  2200. #endif
  2201. };
  2202. static struct device *amvideo_dev;
  2203. static int vout_notify_callback(struct notifier_block *block, unsigned long cmd , void *para)
  2204. {
  2205. const vinfo_t *info;
  2206. ulong flags;
  2207. if (cmd != VOUT_EVENT_MODE_CHANGE) {
  2208. return -1;
  2209. }
  2210. info = get_current_vinfo2();
  2211. spin_lock_irqsave(&lock, flags);
  2212. vinfo = info;
  2213. /* pre-calculate vsync_pts_inc in 90k unit */
  2214. vsync_pts_inc = 90000 * vinfo->sync_duration_den / vinfo->sync_duration_num;
  2215. spin_unlock_irqrestore(&lock, flags);
  2216. if(strncmp(info->name, "null", 4)){
  2217. if(clone){
  2218. start_clone();
  2219. }
  2220. }
  2221. return 0;
  2222. }
  2223. static struct notifier_block vout_notifier = {
  2224. .notifier_call = vout_notify_callback,
  2225. };
  2226. //vframe_t* get_cur_dispbuf(void)
  2227. //{
  2228. // return cur_dispbuf;
  2229. //}
  2230. static void vout_hook(void)
  2231. {
  2232. vout2_register_client(&vout_notifier);
  2233. /*
  2234. vinfo = get_current_vinfo2();
  2235. if (!vinfo) {
  2236. set_current_vmode2(VMODE_720P);
  2237. vinfo = get_current_vinfo2();
  2238. }
  2239. if (vinfo) {
  2240. vsync_pts_inc = 90000 * vinfo->sync_duration_den / vinfo->sync_duration_num;
  2241. }
  2242. */
  2243. #ifdef CONFIG_AM_VIDEO_LOG
  2244. if (vinfo) {
  2245. amlog_mask(LOG_MASK_VINFO, "vinfo = %p\n", vinfo);
  2246. amlog_mask(LOG_MASK_VINFO, "display platform %s:\n", vinfo->name);
  2247. amlog_mask(LOG_MASK_VINFO, "\tresolution %d x %d\n", vinfo->width, vinfo->height);
  2248. amlog_mask(LOG_MASK_VINFO, "\taspect ratio %d : %d\n", vinfo->aspect_ratio_num, vinfo->aspect_ratio_den);
  2249. amlog_mask(LOG_MASK_VINFO, "\tsync duration %d : %d\n", vinfo->sync_duration_num, vinfo->sync_duration_den);
  2250. }
  2251. #endif
  2252. }
  2253. /*********************************************************/
  2254. static int __init video2_early_init(void)
  2255. {
  2256. logo_object_t *init_logo_obj=NULL;
  2257. init_logo_obj = NULL; //get_current_logo_obj();
  2258. if(NULL==init_logo_obj || !init_logo_obj->para.loaded)
  2259. {
  2260. WRITE_MPEG_REG_BITS(VPP2_OFIFO_SIZE, 0x300,
  2261. VPP_OFIFO_SIZE_BIT, VPP_OFIFO_SIZE_WID);
  2262. CLEAR_MPEG_REG_MASK(VPP2_VSC_PHASE_CTRL, VPP_PHASECTL_TYPE_INTERLACE);
  2263. #ifndef CONFIG_FB_AML_TCON
  2264. SET_MPEG_REG_MASK(VPP2_MISC, VPP_OUT_SATURATE);
  2265. #endif
  2266. WRITE_MPEG_REG(VPP2_HOLD_LINES, 0x08080808);
  2267. }
  2268. return 0;
  2269. }
  2270. static int __init video2_init(void)
  2271. {
  2272. int r = 0;
  2273. ulong clk = clk_get_rate(clk_get_sys("clk_misc_pll", NULL));
  2274. #ifndef CONFIG_ARCH_MESON3
  2275. /* MALI clock settings */
  2276. if ((clk <= 750000000) &&
  2277. (clk >= 600000000)) {
  2278. WRITE_CBUS_REG(HHI_MALI_CLK_CNTL,
  2279. (2 << 9) | // select misc pll as clock source
  2280. (1 << 8) | // enable clock gating
  2281. (2 << 0)); // Misc clk / 3
  2282. } else {
  2283. WRITE_CBUS_REG(HHI_MALI_CLK_CNTL,
  2284. (3 << 9) | // select DDR clock as clock source
  2285. (1 << 8) | // enable clock gating
  2286. (1 << 0)); // DDR clk / 2
  2287. }
  2288. #endif
  2289. #ifdef RESERVE_CLR_FRAME
  2290. alloc_keep_buffer();
  2291. #endif
  2292. DisableVideoLayer();
  2293. cur_dispbuf = NULL;
  2294. #ifdef FIQ_VSYNC
  2295. /* enable fiq bridge */
  2296. vsync_fiq_bridge.handle = vsync_bridge_isr;
  2297. vsync_fiq_bridge.key=(u32)vsync_bridge_isr;
  2298. vsync_fiq_bridge.name="vsync_bridge_isr";
  2299. r = register_fiq_bridge_handle(&vsync_fiq_bridge);
  2300. if (r) {
  2301. amlog_level(LOG_LEVEL_ERROR, "video fiq bridge register error.\n");
  2302. r = -ENOENT;
  2303. goto err0;
  2304. }
  2305. #endif
  2306. /* sysfs node creation */
  2307. r = class_register(&amvideo_class);
  2308. if (r) {
  2309. amlog_level(LOG_LEVEL_ERROR, "create video class fail.\n");
  2310. #ifdef FIQ_VSYNC
  2311. free_irq(BRIDGE_IRQ, (void *)video_dev_id);
  2312. #else
  2313. free_irq(INT_VIU2_VSYNC, (void *)video_dev_id);
  2314. #endif
  2315. goto err1;
  2316. }
  2317. /* create video device */
  2318. r = register_chrdev(AMVIDEO2_MAJOR, "amvideo2", &amvideo_fops);
  2319. if (r < 0) {
  2320. amlog_level(LOG_LEVEL_ERROR, "Can't register major for amvideo device\n");
  2321. goto err2;
  2322. }
  2323. amvideo_dev = device_create(&amvideo_class, NULL,
  2324. MKDEV(AMVIDEO2_MAJOR, 0), NULL,
  2325. DEVICE_NAME);
  2326. if (IS_ERR(amvideo_dev)) {
  2327. amlog_level(LOG_LEVEL_ERROR, "Can't create amvideo device\n");
  2328. goto err3;
  2329. }
  2330. init_waitqueue_head(&amvideo_trick_wait);
  2331. vout_hook();
  2332. disp_canvas[0] = (disp_canvas_index[2] << 16) | (disp_canvas_index[1] << 8) | disp_canvas_index[0];
  2333. disp_canvas[1] = (disp_canvas_index[5] << 16) | (disp_canvas_index[4] << 8) | disp_canvas_index[3];
  2334. vsync_fiq_up();
  2335. vf_receiver_init(&video_vf_recv, RECEIVER_NAME, &video_vf_receiver, NULL);
  2336. vf_reg_receiver(&video_vf_recv);
  2337. return (0);
  2338. err3:
  2339. unregister_chrdev(AMVIDEO2_MAJOR, DEVICE_NAME);
  2340. err2:
  2341. #ifdef FIQ_VSYNC
  2342. unregister_fiq_bridge_handle(&vsync_fiq_bridge);
  2343. #endif
  2344. err1:
  2345. class_unregister(&amvideo_class);
  2346. #ifdef FIQ_VSYNC
  2347. err0:
  2348. #endif
  2349. return r;
  2350. }
  2351. static void __exit video2_exit(void)
  2352. {
  2353. vf_unreg_receiver(&video_vf_recv);
  2354. DisableVideoLayer();
  2355. //vsync_fiq_down();
  2356. device_destroy(&amvideo_class, MKDEV(AMVIDEO2_MAJOR, 0));
  2357. unregister_chrdev(AMVIDEO2_MAJOR, DEVICE_NAME);
  2358. #ifdef FIQ_VSYNC
  2359. unregister_fiq_bridge_handle(&vsync_fiq_bridge);
  2360. #endif
  2361. class_unregister(&amvideo_class);
  2362. }
  2363. void set_clone_frame_rate(unsigned int frame_rate, unsigned int delay)
  2364. {
  2365. clone_frame_rate_delay = delay;
  2366. clone_frame_rate_set_value = frame_rate;
  2367. if(delay==0){
  2368. clone_frame_rate = frame_rate;
  2369. }
  2370. }
  2371. EXPORT_SYMBOL(set_clone_frame_rate);
  2372. arch_initcall(video2_early_init);
  2373. module_init(video2_init);
  2374. module_exit(video2_exit);
  2375. module_param(debug, uint, 0664);
  2376. MODULE_PARM_DESC(debug, "\n debug flag \n");
  2377. MODULE_PARM_DESC(clone_frame_rate, "\n clone_frame_rate\n");
  2378. module_param(clone_frame_rate, uint, 0664);
  2379. MODULE_PARM_DESC(clone_frame_rate_force, "\n clone_frame_rate_force\n");
  2380. module_param(clone_frame_rate_force, uint, 0664);
  2381. MODULE_PARM_DESC(clone_frame_scale_width, "\n clone_frame_scale_width\n");
  2382. module_param(clone_frame_scale_width, uint, 0664);
  2383. MODULE_PARM_DESC(vsync_hold_line, "\n vsync_hold_line\n");
  2384. module_param(vsync_hold_line, uint, 0664);
  2385. MODULE_PARM_DESC(isr_interval_max, "\n isr_interval_max\n");
  2386. module_param(isr_interval_max, uint, 0664);
  2387. MODULE_PARM_DESC(isr_run_time_max, "\n isr_run_time_max\n");
  2388. module_param(isr_run_time_max, uint, 0664);
  2389. MODULE_PARM_DESC(throw_frame, "\n throw_frame\n");
  2390. module_param(throw_frame, uint, 0664);