dispc.c 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2009 Nokia Corporation
  4. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  5. *
  6. * Some code and ideas taken from drivers/video/omap/ driver
  7. * by Imre Deak.
  8. */
  9. #define DSS_SUBSYS_NAME "DISPC"
  10. #include <linux/kernel.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/vmalloc.h>
  13. #include <linux/export.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/jiffies.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/delay.h>
  19. #include <linux/workqueue.h>
  20. #include <linux/hardirq.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/pm_runtime.h>
  23. #include <linux/property.h>
  24. #include <linux/sizes.h>
  25. #include <linux/mfd/syscon.h>
  26. #include <linux/regmap.h>
  27. #include <linux/of.h>
  28. #include <linux/component.h>
  29. #include <linux/sys_soc.h>
  30. #include <drm/drm_fourcc.h>
  31. #include <drm/drm_blend.h>
  32. #include "omapdss.h"
  33. #include "dss.h"
  34. #include "dispc.h"
  35. struct dispc_device;
  36. /* DISPC */
  37. #define DISPC_SZ_REGS SZ_4K
  38. enum omap_burst_size {
  39. BURST_SIZE_X2 = 0,
  40. BURST_SIZE_X4 = 1,
  41. BURST_SIZE_X8 = 2,
  42. };
  43. #define REG_GET(dispc, idx, start, end) \
  44. FLD_GET(dispc_read_reg(dispc, idx), start, end)
  45. #define REG_FLD_MOD(dispc, idx, val, start, end) \
  46. dispc_write_reg(dispc, idx, \
  47. FLD_MOD(dispc_read_reg(dispc, idx), val, start, end))
  48. /* DISPC has feature id */
  49. enum dispc_feature_id {
  50. FEAT_LCDENABLEPOL,
  51. FEAT_LCDENABLESIGNAL,
  52. FEAT_PCKFREEENABLE,
  53. FEAT_FUNCGATED,
  54. FEAT_MGR_LCD2,
  55. FEAT_MGR_LCD3,
  56. FEAT_LINEBUFFERSPLIT,
  57. FEAT_ROWREPEATENABLE,
  58. FEAT_RESIZECONF,
  59. /* Independent core clk divider */
  60. FEAT_CORE_CLK_DIV,
  61. FEAT_HANDLE_UV_SEPARATE,
  62. FEAT_ATTR2,
  63. FEAT_CPR,
  64. FEAT_PRELOAD,
  65. FEAT_FIR_COEF_V,
  66. FEAT_ALPHA_FIXED_ZORDER,
  67. FEAT_ALPHA_FREE_ZORDER,
  68. FEAT_FIFO_MERGE,
  69. /* An unknown HW bug causing the normal FIFO thresholds not to work */
  70. FEAT_OMAP3_DSI_FIFO_BUG,
  71. FEAT_BURST_2D,
  72. FEAT_MFLAG,
  73. };
  74. struct dispc_features {
  75. u8 sw_start;
  76. u8 fp_start;
  77. u8 bp_start;
  78. u16 sw_max;
  79. u16 vp_max;
  80. u16 hp_max;
  81. u8 mgr_width_start;
  82. u8 mgr_height_start;
  83. u16 mgr_width_max;
  84. u16 mgr_height_max;
  85. u16 ovl_width_max;
  86. u16 ovl_height_max;
  87. unsigned long max_lcd_pclk;
  88. unsigned long max_tv_pclk;
  89. unsigned int max_downscale;
  90. unsigned int max_line_width;
  91. unsigned int min_pcd;
  92. int (*calc_scaling)(struct dispc_device *dispc,
  93. unsigned long pclk, unsigned long lclk,
  94. const struct videomode *vm,
  95. u16 width, u16 height, u16 out_width, u16 out_height,
  96. u32 fourcc, bool *five_taps,
  97. int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
  98. u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
  99. unsigned long (*calc_core_clk) (unsigned long pclk,
  100. u16 width, u16 height, u16 out_width, u16 out_height,
  101. bool mem_to_mem);
  102. u8 num_fifos;
  103. const enum dispc_feature_id *features;
  104. unsigned int num_features;
  105. const struct dss_reg_field *reg_fields;
  106. const unsigned int num_reg_fields;
  107. const enum omap_overlay_caps *overlay_caps;
  108. const u32 **supported_color_modes;
  109. const u32 *supported_scaler_color_modes;
  110. unsigned int num_mgrs;
  111. unsigned int num_ovls;
  112. unsigned int buffer_size_unit;
  113. unsigned int burst_size_unit;
  114. /* swap GFX & WB fifos */
  115. bool gfx_fifo_workaround:1;
  116. /* no DISPC_IRQ_FRAMEDONETV on this SoC */
  117. bool no_framedone_tv:1;
  118. /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
  119. bool mstandby_workaround:1;
  120. bool set_max_preload:1;
  121. /* PIXEL_INC is not added to the last pixel of a line */
  122. bool last_pixel_inc_missing:1;
  123. /* POL_FREQ has ALIGN bit */
  124. bool supports_sync_align:1;
  125. bool has_writeback:1;
  126. bool supports_double_pixel:1;
  127. /*
  128. * Field order for VENC is different than HDMI. We should handle this in
  129. * some intelligent manner, but as the SoCs have either HDMI or VENC,
  130. * never both, we can just use this flag for now.
  131. */
  132. bool reverse_ilace_field_order:1;
  133. bool has_gamma_table:1;
  134. bool has_gamma_i734_bug:1;
  135. };
  136. #define DISPC_MAX_NR_FIFOS 5
  137. #define DISPC_MAX_CHANNEL_GAMMA 4
  138. struct dispc_device {
  139. struct platform_device *pdev;
  140. void __iomem *base;
  141. struct dss_device *dss;
  142. struct dss_debugfs_entry *debugfs;
  143. int irq;
  144. irq_handler_t user_handler;
  145. void *user_data;
  146. unsigned long core_clk_rate;
  147. unsigned long tv_pclk_rate;
  148. u32 fifo_size[DISPC_MAX_NR_FIFOS];
  149. /* maps which plane is using a fifo. fifo-id -> plane-id */
  150. int fifo_assignment[DISPC_MAX_NR_FIFOS];
  151. bool ctx_valid;
  152. u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
  153. u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA];
  154. const struct dispc_features *feat;
  155. bool is_enabled;
  156. struct regmap *syscon_pol;
  157. u32 syscon_pol_offset;
  158. };
  159. enum omap_color_component {
  160. /* used for all color formats for OMAP3 and earlier
  161. * and for RGB and Y color component on OMAP4
  162. */
  163. DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
  164. /* used for UV component for
  165. * DRM_FORMAT_YUYV, DRM_FORMAT_UYVY, DRM_FORMAT_NV12
  166. * color formats on OMAP4
  167. */
  168. DISPC_COLOR_COMPONENT_UV = 1 << 1,
  169. };
  170. enum mgr_reg_fields {
  171. DISPC_MGR_FLD_ENABLE,
  172. DISPC_MGR_FLD_STNTFT,
  173. DISPC_MGR_FLD_GO,
  174. DISPC_MGR_FLD_TFTDATALINES,
  175. DISPC_MGR_FLD_STALLMODE,
  176. DISPC_MGR_FLD_TCKENABLE,
  177. DISPC_MGR_FLD_TCKSELECTION,
  178. DISPC_MGR_FLD_CPR,
  179. DISPC_MGR_FLD_FIFOHANDCHECK,
  180. /* used to maintain a count of the above fields */
  181. DISPC_MGR_FLD_NUM,
  182. };
  183. /* DISPC register field id */
  184. enum dispc_feat_reg_field {
  185. FEAT_REG_FIRHINC,
  186. FEAT_REG_FIRVINC,
  187. FEAT_REG_FIFOHIGHTHRESHOLD,
  188. FEAT_REG_FIFOLOWTHRESHOLD,
  189. FEAT_REG_FIFOSIZE,
  190. FEAT_REG_HORIZONTALACCU,
  191. FEAT_REG_VERTICALACCU,
  192. };
  193. struct dispc_reg_field {
  194. u16 reg;
  195. u8 high;
  196. u8 low;
  197. };
  198. struct dispc_gamma_desc {
  199. u32 len;
  200. u32 bits;
  201. u16 reg;
  202. bool has_index;
  203. };
  204. static const struct {
  205. const char *name;
  206. u32 vsync_irq;
  207. u32 framedone_irq;
  208. u32 sync_lost_irq;
  209. struct dispc_gamma_desc gamma;
  210. struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
  211. } mgr_desc[] = {
  212. [OMAP_DSS_CHANNEL_LCD] = {
  213. .name = "LCD",
  214. .vsync_irq = DISPC_IRQ_VSYNC,
  215. .framedone_irq = DISPC_IRQ_FRAMEDONE,
  216. .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
  217. .gamma = {
  218. .len = 256,
  219. .bits = 8,
  220. .reg = DISPC_GAMMA_TABLE0,
  221. .has_index = true,
  222. },
  223. .reg_desc = {
  224. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
  225. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
  226. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
  227. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
  228. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
  229. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
  230. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
  231. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
  232. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
  233. },
  234. },
  235. [OMAP_DSS_CHANNEL_DIGIT] = {
  236. .name = "DIGIT",
  237. .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
  238. .framedone_irq = DISPC_IRQ_FRAMEDONETV,
  239. .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
  240. .gamma = {
  241. .len = 1024,
  242. .bits = 10,
  243. .reg = DISPC_GAMMA_TABLE2,
  244. .has_index = false,
  245. },
  246. .reg_desc = {
  247. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
  248. [DISPC_MGR_FLD_STNTFT] = { },
  249. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
  250. [DISPC_MGR_FLD_TFTDATALINES] = { },
  251. [DISPC_MGR_FLD_STALLMODE] = { },
  252. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
  253. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
  254. [DISPC_MGR_FLD_CPR] = { },
  255. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
  256. },
  257. },
  258. [OMAP_DSS_CHANNEL_LCD2] = {
  259. .name = "LCD2",
  260. .vsync_irq = DISPC_IRQ_VSYNC2,
  261. .framedone_irq = DISPC_IRQ_FRAMEDONE2,
  262. .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
  263. .gamma = {
  264. .len = 256,
  265. .bits = 8,
  266. .reg = DISPC_GAMMA_TABLE1,
  267. .has_index = true,
  268. },
  269. .reg_desc = {
  270. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
  271. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
  272. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
  273. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
  274. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
  275. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
  276. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
  277. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
  278. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
  279. },
  280. },
  281. [OMAP_DSS_CHANNEL_LCD3] = {
  282. .name = "LCD3",
  283. .vsync_irq = DISPC_IRQ_VSYNC3,
  284. .framedone_irq = DISPC_IRQ_FRAMEDONE3,
  285. .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
  286. .gamma = {
  287. .len = 256,
  288. .bits = 8,
  289. .reg = DISPC_GAMMA_TABLE3,
  290. .has_index = true,
  291. },
  292. .reg_desc = {
  293. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
  294. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
  295. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
  296. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
  297. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
  298. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
  299. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
  300. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
  301. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
  302. },
  303. },
  304. };
  305. static unsigned long dispc_fclk_rate(struct dispc_device *dispc);
  306. static unsigned long dispc_core_clk_rate(struct dispc_device *dispc);
  307. static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
  308. enum omap_channel channel);
  309. static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
  310. enum omap_channel channel);
  311. static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
  312. enum omap_plane_id plane);
  313. static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
  314. enum omap_plane_id plane);
  315. static inline void dispc_write_reg(struct dispc_device *dispc, u16 idx, u32 val)
  316. {
  317. __raw_writel(val, dispc->base + idx);
  318. }
  319. static inline u32 dispc_read_reg(struct dispc_device *dispc, u16 idx)
  320. {
  321. return __raw_readl(dispc->base + idx);
  322. }
  323. static u32 mgr_fld_read(struct dispc_device *dispc, enum omap_channel channel,
  324. enum mgr_reg_fields regfld)
  325. {
  326. const struct dispc_reg_field *rfld = &mgr_desc[channel].reg_desc[regfld];
  327. return REG_GET(dispc, rfld->reg, rfld->high, rfld->low);
  328. }
  329. static void mgr_fld_write(struct dispc_device *dispc, enum omap_channel channel,
  330. enum mgr_reg_fields regfld, int val)
  331. {
  332. const struct dispc_reg_field *rfld = &mgr_desc[channel].reg_desc[regfld];
  333. REG_FLD_MOD(dispc, rfld->reg, val, rfld->high, rfld->low);
  334. }
  335. int dispc_get_num_ovls(struct dispc_device *dispc)
  336. {
  337. return dispc->feat->num_ovls;
  338. }
  339. int dispc_get_num_mgrs(struct dispc_device *dispc)
  340. {
  341. return dispc->feat->num_mgrs;
  342. }
  343. static void dispc_get_reg_field(struct dispc_device *dispc,
  344. enum dispc_feat_reg_field id,
  345. u8 *start, u8 *end)
  346. {
  347. BUG_ON(id >= dispc->feat->num_reg_fields);
  348. *start = dispc->feat->reg_fields[id].start;
  349. *end = dispc->feat->reg_fields[id].end;
  350. }
  351. static bool dispc_has_feature(struct dispc_device *dispc,
  352. enum dispc_feature_id id)
  353. {
  354. unsigned int i;
  355. for (i = 0; i < dispc->feat->num_features; i++) {
  356. if (dispc->feat->features[i] == id)
  357. return true;
  358. }
  359. return false;
  360. }
  361. #define SR(dispc, reg) \
  362. dispc->ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(dispc, DISPC_##reg)
  363. #define RR(dispc, reg) \
  364. dispc_write_reg(dispc, DISPC_##reg, dispc->ctx[DISPC_##reg / sizeof(u32)])
  365. static void dispc_save_context(struct dispc_device *dispc)
  366. {
  367. int i, j;
  368. DSSDBG("dispc_save_context\n");
  369. SR(dispc, IRQENABLE);
  370. SR(dispc, CONTROL);
  371. SR(dispc, CONFIG);
  372. SR(dispc, LINE_NUMBER);
  373. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  374. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  375. SR(dispc, GLOBAL_ALPHA);
  376. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  377. SR(dispc, CONTROL2);
  378. SR(dispc, CONFIG2);
  379. }
  380. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  381. SR(dispc, CONTROL3);
  382. SR(dispc, CONFIG3);
  383. }
  384. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  385. SR(dispc, DEFAULT_COLOR(i));
  386. SR(dispc, TRANS_COLOR(i));
  387. SR(dispc, SIZE_MGR(i));
  388. if (i == OMAP_DSS_CHANNEL_DIGIT)
  389. continue;
  390. SR(dispc, TIMING_H(i));
  391. SR(dispc, TIMING_V(i));
  392. SR(dispc, POL_FREQ(i));
  393. SR(dispc, DIVISORo(i));
  394. SR(dispc, DATA_CYCLE1(i));
  395. SR(dispc, DATA_CYCLE2(i));
  396. SR(dispc, DATA_CYCLE3(i));
  397. if (dispc_has_feature(dispc, FEAT_CPR)) {
  398. SR(dispc, CPR_COEF_R(i));
  399. SR(dispc, CPR_COEF_G(i));
  400. SR(dispc, CPR_COEF_B(i));
  401. }
  402. }
  403. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  404. SR(dispc, OVL_BA0(i));
  405. SR(dispc, OVL_BA1(i));
  406. SR(dispc, OVL_POSITION(i));
  407. SR(dispc, OVL_SIZE(i));
  408. SR(dispc, OVL_ATTRIBUTES(i));
  409. SR(dispc, OVL_FIFO_THRESHOLD(i));
  410. SR(dispc, OVL_ROW_INC(i));
  411. SR(dispc, OVL_PIXEL_INC(i));
  412. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  413. SR(dispc, OVL_PRELOAD(i));
  414. if (i == OMAP_DSS_GFX) {
  415. SR(dispc, OVL_WINDOW_SKIP(i));
  416. SR(dispc, OVL_TABLE_BA(i));
  417. continue;
  418. }
  419. SR(dispc, OVL_FIR(i));
  420. SR(dispc, OVL_PICTURE_SIZE(i));
  421. SR(dispc, OVL_ACCU0(i));
  422. SR(dispc, OVL_ACCU1(i));
  423. for (j = 0; j < 8; j++)
  424. SR(dispc, OVL_FIR_COEF_H(i, j));
  425. for (j = 0; j < 8; j++)
  426. SR(dispc, OVL_FIR_COEF_HV(i, j));
  427. for (j = 0; j < 5; j++)
  428. SR(dispc, OVL_CONV_COEF(i, j));
  429. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  430. for (j = 0; j < 8; j++)
  431. SR(dispc, OVL_FIR_COEF_V(i, j));
  432. }
  433. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  434. SR(dispc, OVL_BA0_UV(i));
  435. SR(dispc, OVL_BA1_UV(i));
  436. SR(dispc, OVL_FIR2(i));
  437. SR(dispc, OVL_ACCU2_0(i));
  438. SR(dispc, OVL_ACCU2_1(i));
  439. for (j = 0; j < 8; j++)
  440. SR(dispc, OVL_FIR_COEF_H2(i, j));
  441. for (j = 0; j < 8; j++)
  442. SR(dispc, OVL_FIR_COEF_HV2(i, j));
  443. for (j = 0; j < 8; j++)
  444. SR(dispc, OVL_FIR_COEF_V2(i, j));
  445. }
  446. if (dispc_has_feature(dispc, FEAT_ATTR2))
  447. SR(dispc, OVL_ATTRIBUTES2(i));
  448. }
  449. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  450. SR(dispc, DIVISOR);
  451. dispc->ctx_valid = true;
  452. DSSDBG("context saved\n");
  453. }
  454. static noinline_for_stack void dispc_restore_context(struct dispc_device *dispc)
  455. {
  456. int i, j;
  457. DSSDBG("dispc_restore_context\n");
  458. if (!dispc->ctx_valid)
  459. return;
  460. /*RR(dispc, IRQENABLE);*/
  461. /*RR(dispc, CONTROL);*/
  462. RR(dispc, CONFIG);
  463. RR(dispc, LINE_NUMBER);
  464. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  465. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  466. RR(dispc, GLOBAL_ALPHA);
  467. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  468. RR(dispc, CONFIG2);
  469. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  470. RR(dispc, CONFIG3);
  471. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  472. RR(dispc, DEFAULT_COLOR(i));
  473. RR(dispc, TRANS_COLOR(i));
  474. RR(dispc, SIZE_MGR(i));
  475. if (i == OMAP_DSS_CHANNEL_DIGIT)
  476. continue;
  477. RR(dispc, TIMING_H(i));
  478. RR(dispc, TIMING_V(i));
  479. RR(dispc, POL_FREQ(i));
  480. RR(dispc, DIVISORo(i));
  481. RR(dispc, DATA_CYCLE1(i));
  482. RR(dispc, DATA_CYCLE2(i));
  483. RR(dispc, DATA_CYCLE3(i));
  484. if (dispc_has_feature(dispc, FEAT_CPR)) {
  485. RR(dispc, CPR_COEF_R(i));
  486. RR(dispc, CPR_COEF_G(i));
  487. RR(dispc, CPR_COEF_B(i));
  488. }
  489. }
  490. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  491. RR(dispc, OVL_BA0(i));
  492. RR(dispc, OVL_BA1(i));
  493. RR(dispc, OVL_POSITION(i));
  494. RR(dispc, OVL_SIZE(i));
  495. RR(dispc, OVL_ATTRIBUTES(i));
  496. RR(dispc, OVL_FIFO_THRESHOLD(i));
  497. RR(dispc, OVL_ROW_INC(i));
  498. RR(dispc, OVL_PIXEL_INC(i));
  499. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  500. RR(dispc, OVL_PRELOAD(i));
  501. if (i == OMAP_DSS_GFX) {
  502. RR(dispc, OVL_WINDOW_SKIP(i));
  503. RR(dispc, OVL_TABLE_BA(i));
  504. continue;
  505. }
  506. RR(dispc, OVL_FIR(i));
  507. RR(dispc, OVL_PICTURE_SIZE(i));
  508. RR(dispc, OVL_ACCU0(i));
  509. RR(dispc, OVL_ACCU1(i));
  510. for (j = 0; j < 8; j++)
  511. RR(dispc, OVL_FIR_COEF_H(i, j));
  512. for (j = 0; j < 8; j++)
  513. RR(dispc, OVL_FIR_COEF_HV(i, j));
  514. for (j = 0; j < 5; j++)
  515. RR(dispc, OVL_CONV_COEF(i, j));
  516. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  517. for (j = 0; j < 8; j++)
  518. RR(dispc, OVL_FIR_COEF_V(i, j));
  519. }
  520. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  521. RR(dispc, OVL_BA0_UV(i));
  522. RR(dispc, OVL_BA1_UV(i));
  523. RR(dispc, OVL_FIR2(i));
  524. RR(dispc, OVL_ACCU2_0(i));
  525. RR(dispc, OVL_ACCU2_1(i));
  526. for (j = 0; j < 8; j++)
  527. RR(dispc, OVL_FIR_COEF_H2(i, j));
  528. for (j = 0; j < 8; j++)
  529. RR(dispc, OVL_FIR_COEF_HV2(i, j));
  530. for (j = 0; j < 8; j++)
  531. RR(dispc, OVL_FIR_COEF_V2(i, j));
  532. }
  533. if (dispc_has_feature(dispc, FEAT_ATTR2))
  534. RR(dispc, OVL_ATTRIBUTES2(i));
  535. }
  536. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  537. RR(dispc, DIVISOR);
  538. /* enable last, because LCD & DIGIT enable are here */
  539. RR(dispc, CONTROL);
  540. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  541. RR(dispc, CONTROL2);
  542. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  543. RR(dispc, CONTROL3);
  544. /* clear spurious SYNC_LOST_DIGIT interrupts */
  545. dispc_clear_irqstatus(dispc, DISPC_IRQ_SYNC_LOST_DIGIT);
  546. /*
  547. * enable last so IRQs won't trigger before
  548. * the context is fully restored
  549. */
  550. RR(dispc, IRQENABLE);
  551. DSSDBG("context restored\n");
  552. }
  553. #undef SR
  554. #undef RR
  555. int dispc_runtime_get(struct dispc_device *dispc)
  556. {
  557. int r;
  558. DSSDBG("dispc_runtime_get\n");
  559. r = pm_runtime_get_sync(&dispc->pdev->dev);
  560. if (WARN_ON(r < 0)) {
  561. pm_runtime_put_noidle(&dispc->pdev->dev);
  562. return r;
  563. }
  564. return 0;
  565. }
  566. void dispc_runtime_put(struct dispc_device *dispc)
  567. {
  568. int r;
  569. DSSDBG("dispc_runtime_put\n");
  570. r = pm_runtime_put_sync(&dispc->pdev->dev);
  571. WARN_ON(r < 0 && r != -ENOSYS);
  572. }
  573. u32 dispc_mgr_get_vsync_irq(struct dispc_device *dispc,
  574. enum omap_channel channel)
  575. {
  576. return mgr_desc[channel].vsync_irq;
  577. }
  578. u32 dispc_mgr_get_framedone_irq(struct dispc_device *dispc,
  579. enum omap_channel channel)
  580. {
  581. if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc->feat->no_framedone_tv)
  582. return 0;
  583. return mgr_desc[channel].framedone_irq;
  584. }
  585. u32 dispc_mgr_get_sync_lost_irq(struct dispc_device *dispc,
  586. enum omap_channel channel)
  587. {
  588. return mgr_desc[channel].sync_lost_irq;
  589. }
  590. void dispc_mgr_enable(struct dispc_device *dispc,
  591. enum omap_channel channel, bool enable)
  592. {
  593. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_ENABLE, enable);
  594. /* flush posted write */
  595. mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
  596. }
  597. static bool dispc_mgr_is_enabled(struct dispc_device *dispc,
  598. enum omap_channel channel)
  599. {
  600. return !!mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
  601. }
  602. bool dispc_mgr_go_busy(struct dispc_device *dispc,
  603. enum omap_channel channel)
  604. {
  605. return mgr_fld_read(dispc, channel, DISPC_MGR_FLD_GO) == 1;
  606. }
  607. void dispc_mgr_go(struct dispc_device *dispc, enum omap_channel channel)
  608. {
  609. WARN_ON(!dispc_mgr_is_enabled(dispc, channel));
  610. WARN_ON(dispc_mgr_go_busy(dispc, channel));
  611. DSSDBG("GO %s\n", mgr_desc[channel].name);
  612. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_GO, 1);
  613. }
  614. static void dispc_ovl_write_firh_reg(struct dispc_device *dispc,
  615. enum omap_plane_id plane, int reg,
  616. u32 value)
  617. {
  618. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H(plane, reg), value);
  619. }
  620. static void dispc_ovl_write_firhv_reg(struct dispc_device *dispc,
  621. enum omap_plane_id plane, int reg,
  622. u32 value)
  623. {
  624. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV(plane, reg), value);
  625. }
  626. static void dispc_ovl_write_firv_reg(struct dispc_device *dispc,
  627. enum omap_plane_id plane, int reg,
  628. u32 value)
  629. {
  630. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V(plane, reg), value);
  631. }
  632. static void dispc_ovl_write_firh2_reg(struct dispc_device *dispc,
  633. enum omap_plane_id plane, int reg,
  634. u32 value)
  635. {
  636. BUG_ON(plane == OMAP_DSS_GFX);
  637. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H2(plane, reg), value);
  638. }
  639. static void dispc_ovl_write_firhv2_reg(struct dispc_device *dispc,
  640. enum omap_plane_id plane, int reg,
  641. u32 value)
  642. {
  643. BUG_ON(plane == OMAP_DSS_GFX);
  644. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
  645. }
  646. static void dispc_ovl_write_firv2_reg(struct dispc_device *dispc,
  647. enum omap_plane_id plane, int reg,
  648. u32 value)
  649. {
  650. BUG_ON(plane == OMAP_DSS_GFX);
  651. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V2(plane, reg), value);
  652. }
  653. static void dispc_ovl_set_scale_coef(struct dispc_device *dispc,
  654. enum omap_plane_id plane, int fir_hinc,
  655. int fir_vinc, int five_taps,
  656. enum omap_color_component color_comp)
  657. {
  658. const struct dispc_coef *h_coef, *v_coef;
  659. int i;
  660. h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
  661. v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
  662. if (!h_coef || !v_coef) {
  663. dev_err(&dispc->pdev->dev, "%s: failed to find scale coefs\n",
  664. __func__);
  665. return;
  666. }
  667. for (i = 0; i < 8; i++) {
  668. u32 h, hv;
  669. h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
  670. | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
  671. | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
  672. | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
  673. hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
  674. | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
  675. | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
  676. | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
  677. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  678. dispc_ovl_write_firh_reg(dispc, plane, i, h);
  679. dispc_ovl_write_firhv_reg(dispc, plane, i, hv);
  680. } else {
  681. dispc_ovl_write_firh2_reg(dispc, plane, i, h);
  682. dispc_ovl_write_firhv2_reg(dispc, plane, i, hv);
  683. }
  684. }
  685. if (five_taps) {
  686. for (i = 0; i < 8; i++) {
  687. u32 v;
  688. v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
  689. | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
  690. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
  691. dispc_ovl_write_firv_reg(dispc, plane, i, v);
  692. else
  693. dispc_ovl_write_firv2_reg(dispc, plane, i, v);
  694. }
  695. }
  696. }
  697. struct csc_coef_yuv2rgb {
  698. int ry, rcb, rcr, gy, gcb, gcr, by, bcb, bcr;
  699. bool full_range;
  700. };
  701. static void dispc_ovl_write_color_conv_coef(struct dispc_device *dispc,
  702. enum omap_plane_id plane,
  703. const struct csc_coef_yuv2rgb *ct)
  704. {
  705. #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
  706. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
  707. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
  708. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
  709. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
  710. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
  711. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
  712. #undef CVAL
  713. }
  714. /* YUV -> RGB, ITU-R BT.601, full range */
  715. static const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt601_full = {
  716. 256, 0, 358, /* ry, rcb, rcr |1.000 0.000 1.402|*/
  717. 256, -88, -182, /* gy, gcb, gcr |1.000 -0.344 -0.714|*/
  718. 256, 452, 0, /* by, bcb, bcr |1.000 1.772 0.000|*/
  719. true, /* full range */
  720. };
  721. /* YUV -> RGB, ITU-R BT.601, limited range */
  722. static const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt601_lim = {
  723. 298, 0, 409, /* ry, rcb, rcr |1.164 0.000 1.596|*/
  724. 298, -100, -208, /* gy, gcb, gcr |1.164 -0.392 -0.813|*/
  725. 298, 516, 0, /* by, bcb, bcr |1.164 2.017 0.000|*/
  726. false, /* limited range */
  727. };
  728. /* YUV -> RGB, ITU-R BT.709, full range */
  729. static const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt709_full = {
  730. 256, 0, 402, /* ry, rcb, rcr |1.000 0.000 1.570|*/
  731. 256, -48, -120, /* gy, gcb, gcr |1.000 -0.187 -0.467|*/
  732. 256, 475, 0, /* by, bcb, bcr |1.000 1.856 0.000|*/
  733. true, /* full range */
  734. };
  735. /* YUV -> RGB, ITU-R BT.709, limited range */
  736. static const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt709_lim = {
  737. 298, 0, 459, /* ry, rcb, rcr |1.164 0.000 1.793|*/
  738. 298, -55, -136, /* gy, gcb, gcr |1.164 -0.213 -0.533|*/
  739. 298, 541, 0, /* by, bcb, bcr |1.164 2.112 0.000|*/
  740. false, /* limited range */
  741. };
  742. static void dispc_ovl_set_csc(struct dispc_device *dispc,
  743. enum omap_plane_id plane,
  744. enum drm_color_encoding color_encoding,
  745. enum drm_color_range color_range)
  746. {
  747. const struct csc_coef_yuv2rgb *csc;
  748. switch (color_encoding) {
  749. default:
  750. case DRM_COLOR_YCBCR_BT601:
  751. if (color_range == DRM_COLOR_YCBCR_FULL_RANGE)
  752. csc = &coefs_yuv2rgb_bt601_full;
  753. else
  754. csc = &coefs_yuv2rgb_bt601_lim;
  755. break;
  756. case DRM_COLOR_YCBCR_BT709:
  757. if (color_range == DRM_COLOR_YCBCR_FULL_RANGE)
  758. csc = &coefs_yuv2rgb_bt709_full;
  759. else
  760. csc = &coefs_yuv2rgb_bt709_lim;
  761. break;
  762. }
  763. dispc_ovl_write_color_conv_coef(dispc, plane, csc);
  764. }
  765. static void dispc_ovl_set_ba0(struct dispc_device *dispc,
  766. enum omap_plane_id plane, u32 paddr)
  767. {
  768. dispc_write_reg(dispc, DISPC_OVL_BA0(plane), paddr);
  769. }
  770. static void dispc_ovl_set_ba1(struct dispc_device *dispc,
  771. enum omap_plane_id plane, u32 paddr)
  772. {
  773. dispc_write_reg(dispc, DISPC_OVL_BA1(plane), paddr);
  774. }
  775. static void dispc_ovl_set_ba0_uv(struct dispc_device *dispc,
  776. enum omap_plane_id plane, u32 paddr)
  777. {
  778. dispc_write_reg(dispc, DISPC_OVL_BA0_UV(plane), paddr);
  779. }
  780. static void dispc_ovl_set_ba1_uv(struct dispc_device *dispc,
  781. enum omap_plane_id plane, u32 paddr)
  782. {
  783. dispc_write_reg(dispc, DISPC_OVL_BA1_UV(plane), paddr);
  784. }
  785. static void dispc_ovl_set_pos(struct dispc_device *dispc,
  786. enum omap_plane_id plane,
  787. enum omap_overlay_caps caps, int x, int y)
  788. {
  789. u32 val;
  790. if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
  791. return;
  792. val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
  793. dispc_write_reg(dispc, DISPC_OVL_POSITION(plane), val);
  794. }
  795. static void dispc_ovl_set_input_size(struct dispc_device *dispc,
  796. enum omap_plane_id plane, int width,
  797. int height)
  798. {
  799. u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  800. if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
  801. dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
  802. else
  803. dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
  804. }
  805. static void dispc_ovl_set_output_size(struct dispc_device *dispc,
  806. enum omap_plane_id plane, int width,
  807. int height)
  808. {
  809. u32 val;
  810. BUG_ON(plane == OMAP_DSS_GFX);
  811. val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  812. if (plane == OMAP_DSS_WB)
  813. dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
  814. else
  815. dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
  816. }
  817. static void dispc_ovl_set_zorder(struct dispc_device *dispc,
  818. enum omap_plane_id plane,
  819. enum omap_overlay_caps caps, u8 zorder)
  820. {
  821. if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
  822. return;
  823. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
  824. }
  825. static void dispc_ovl_enable_zorder_planes(struct dispc_device *dispc)
  826. {
  827. int i;
  828. if (!dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  829. return;
  830. for (i = 0; i < dispc_get_num_ovls(dispc); i++)
  831. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
  832. }
  833. static void dispc_ovl_set_pre_mult_alpha(struct dispc_device *dispc,
  834. enum omap_plane_id plane,
  835. enum omap_overlay_caps caps,
  836. bool enable)
  837. {
  838. if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
  839. return;
  840. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
  841. }
  842. static void dispc_ovl_setup_global_alpha(struct dispc_device *dispc,
  843. enum omap_plane_id plane,
  844. enum omap_overlay_caps caps,
  845. u8 global_alpha)
  846. {
  847. static const unsigned int shifts[] = { 0, 8, 16, 24, };
  848. int shift;
  849. if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
  850. return;
  851. shift = shifts[plane];
  852. REG_FLD_MOD(dispc, DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
  853. }
  854. static void dispc_ovl_set_pix_inc(struct dispc_device *dispc,
  855. enum omap_plane_id plane, s32 inc)
  856. {
  857. dispc_write_reg(dispc, DISPC_OVL_PIXEL_INC(plane), inc);
  858. }
  859. static void dispc_ovl_set_row_inc(struct dispc_device *dispc,
  860. enum omap_plane_id plane, s32 inc)
  861. {
  862. dispc_write_reg(dispc, DISPC_OVL_ROW_INC(plane), inc);
  863. }
  864. static void dispc_ovl_set_color_mode(struct dispc_device *dispc,
  865. enum omap_plane_id plane, u32 fourcc)
  866. {
  867. u32 m = 0;
  868. if (plane != OMAP_DSS_GFX) {
  869. switch (fourcc) {
  870. case DRM_FORMAT_NV12:
  871. m = 0x0; break;
  872. case DRM_FORMAT_XRGB4444:
  873. m = 0x1; break;
  874. case DRM_FORMAT_RGBA4444:
  875. m = 0x2; break;
  876. case DRM_FORMAT_RGBX4444:
  877. m = 0x4; break;
  878. case DRM_FORMAT_ARGB4444:
  879. m = 0x5; break;
  880. case DRM_FORMAT_RGB565:
  881. m = 0x6; break;
  882. case DRM_FORMAT_ARGB1555:
  883. m = 0x7; break;
  884. case DRM_FORMAT_XRGB8888:
  885. m = 0x8; break;
  886. case DRM_FORMAT_RGB888:
  887. m = 0x9; break;
  888. case DRM_FORMAT_YUYV:
  889. m = 0xa; break;
  890. case DRM_FORMAT_UYVY:
  891. m = 0xb; break;
  892. case DRM_FORMAT_ARGB8888:
  893. m = 0xc; break;
  894. case DRM_FORMAT_RGBA8888:
  895. m = 0xd; break;
  896. case DRM_FORMAT_RGBX8888:
  897. m = 0xe; break;
  898. case DRM_FORMAT_XRGB1555:
  899. m = 0xf; break;
  900. default:
  901. BUG(); return;
  902. }
  903. } else {
  904. switch (fourcc) {
  905. case DRM_FORMAT_RGBX4444:
  906. m = 0x4; break;
  907. case DRM_FORMAT_ARGB4444:
  908. m = 0x5; break;
  909. case DRM_FORMAT_RGB565:
  910. m = 0x6; break;
  911. case DRM_FORMAT_ARGB1555:
  912. m = 0x7; break;
  913. case DRM_FORMAT_XRGB8888:
  914. m = 0x8; break;
  915. case DRM_FORMAT_RGB888:
  916. m = 0x9; break;
  917. case DRM_FORMAT_XRGB4444:
  918. m = 0xa; break;
  919. case DRM_FORMAT_RGBA4444:
  920. m = 0xb; break;
  921. case DRM_FORMAT_ARGB8888:
  922. m = 0xc; break;
  923. case DRM_FORMAT_RGBA8888:
  924. m = 0xd; break;
  925. case DRM_FORMAT_RGBX8888:
  926. m = 0xe; break;
  927. case DRM_FORMAT_XRGB1555:
  928. m = 0xf; break;
  929. default:
  930. BUG(); return;
  931. }
  932. }
  933. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
  934. }
  935. static void dispc_ovl_configure_burst_type(struct dispc_device *dispc,
  936. enum omap_plane_id plane,
  937. enum omap_dss_rotation_type rotation)
  938. {
  939. if (dispc_has_feature(dispc, FEAT_BURST_2D) == 0)
  940. return;
  941. if (rotation == OMAP_DSS_ROT_TILER)
  942. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
  943. else
  944. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
  945. }
  946. static void dispc_ovl_set_channel_out(struct dispc_device *dispc,
  947. enum omap_plane_id plane,
  948. enum omap_channel channel)
  949. {
  950. int shift;
  951. u32 val;
  952. int chan = 0, chan2 = 0;
  953. switch (plane) {
  954. case OMAP_DSS_GFX:
  955. shift = 8;
  956. break;
  957. case OMAP_DSS_VIDEO1:
  958. case OMAP_DSS_VIDEO2:
  959. case OMAP_DSS_VIDEO3:
  960. shift = 16;
  961. break;
  962. default:
  963. BUG();
  964. return;
  965. }
  966. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  967. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  968. switch (channel) {
  969. case OMAP_DSS_CHANNEL_LCD:
  970. chan = 0;
  971. chan2 = 0;
  972. break;
  973. case OMAP_DSS_CHANNEL_DIGIT:
  974. chan = 1;
  975. chan2 = 0;
  976. break;
  977. case OMAP_DSS_CHANNEL_LCD2:
  978. chan = 0;
  979. chan2 = 1;
  980. break;
  981. case OMAP_DSS_CHANNEL_LCD3:
  982. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  983. chan = 0;
  984. chan2 = 2;
  985. } else {
  986. BUG();
  987. return;
  988. }
  989. break;
  990. case OMAP_DSS_CHANNEL_WB:
  991. chan = 0;
  992. chan2 = 3;
  993. break;
  994. default:
  995. BUG();
  996. return;
  997. }
  998. val = FLD_MOD(val, chan, shift, shift);
  999. val = FLD_MOD(val, chan2, 31, 30);
  1000. } else {
  1001. val = FLD_MOD(val, channel, shift, shift);
  1002. }
  1003. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
  1004. }
  1005. static enum omap_channel dispc_ovl_get_channel_out(struct dispc_device *dispc,
  1006. enum omap_plane_id plane)
  1007. {
  1008. int shift;
  1009. u32 val;
  1010. switch (plane) {
  1011. case OMAP_DSS_GFX:
  1012. shift = 8;
  1013. break;
  1014. case OMAP_DSS_VIDEO1:
  1015. case OMAP_DSS_VIDEO2:
  1016. case OMAP_DSS_VIDEO3:
  1017. shift = 16;
  1018. break;
  1019. default:
  1020. BUG();
  1021. return 0;
  1022. }
  1023. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1024. if (FLD_GET(val, shift, shift) == 1)
  1025. return OMAP_DSS_CHANNEL_DIGIT;
  1026. if (!dispc_has_feature(dispc, FEAT_MGR_LCD2))
  1027. return OMAP_DSS_CHANNEL_LCD;
  1028. switch (FLD_GET(val, 31, 30)) {
  1029. case 0:
  1030. default:
  1031. return OMAP_DSS_CHANNEL_LCD;
  1032. case 1:
  1033. return OMAP_DSS_CHANNEL_LCD2;
  1034. case 2:
  1035. return OMAP_DSS_CHANNEL_LCD3;
  1036. case 3:
  1037. return OMAP_DSS_CHANNEL_WB;
  1038. }
  1039. }
  1040. static void dispc_ovl_set_burst_size(struct dispc_device *dispc,
  1041. enum omap_plane_id plane,
  1042. enum omap_burst_size burst_size)
  1043. {
  1044. static const unsigned int shifts[] = { 6, 14, 14, 14, 14, };
  1045. int shift;
  1046. shift = shifts[plane];
  1047. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), burst_size,
  1048. shift + 1, shift);
  1049. }
  1050. static void dispc_configure_burst_sizes(struct dispc_device *dispc)
  1051. {
  1052. int i;
  1053. const int burst_size = BURST_SIZE_X8;
  1054. /* Configure burst size always to maximum size */
  1055. for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
  1056. dispc_ovl_set_burst_size(dispc, i, burst_size);
  1057. if (dispc->feat->has_writeback)
  1058. dispc_ovl_set_burst_size(dispc, OMAP_DSS_WB, burst_size);
  1059. }
  1060. static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc,
  1061. enum omap_plane_id plane)
  1062. {
  1063. /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
  1064. return dispc->feat->burst_size_unit * 8;
  1065. }
  1066. bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
  1067. enum omap_plane_id plane, u32 fourcc)
  1068. {
  1069. const u32 *modes;
  1070. unsigned int i;
  1071. modes = dispc->feat->supported_color_modes[plane];
  1072. for (i = 0; modes[i]; ++i) {
  1073. if (modes[i] == fourcc)
  1074. return true;
  1075. }
  1076. return false;
  1077. }
  1078. const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
  1079. enum omap_plane_id plane)
  1080. {
  1081. return dispc->feat->supported_color_modes[plane];
  1082. }
  1083. static void dispc_mgr_enable_cpr(struct dispc_device *dispc,
  1084. enum omap_channel channel, bool enable)
  1085. {
  1086. if (channel == OMAP_DSS_CHANNEL_DIGIT)
  1087. return;
  1088. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_CPR, enable);
  1089. }
  1090. static void dispc_mgr_set_cpr_coef(struct dispc_device *dispc,
  1091. enum omap_channel channel,
  1092. const struct omap_dss_cpr_coefs *coefs)
  1093. {
  1094. u32 coef_r, coef_g, coef_b;
  1095. if (!dss_mgr_is_lcd(channel))
  1096. return;
  1097. coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
  1098. FLD_VAL(coefs->rb, 9, 0);
  1099. coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
  1100. FLD_VAL(coefs->gb, 9, 0);
  1101. coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
  1102. FLD_VAL(coefs->bb, 9, 0);
  1103. dispc_write_reg(dispc, DISPC_CPR_COEF_R(channel), coef_r);
  1104. dispc_write_reg(dispc, DISPC_CPR_COEF_G(channel), coef_g);
  1105. dispc_write_reg(dispc, DISPC_CPR_COEF_B(channel), coef_b);
  1106. }
  1107. static void dispc_ovl_set_vid_color_conv(struct dispc_device *dispc,
  1108. enum omap_plane_id plane, bool enable)
  1109. {
  1110. u32 val;
  1111. BUG_ON(plane == OMAP_DSS_GFX);
  1112. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1113. val = FLD_MOD(val, enable, 9, 9);
  1114. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
  1115. }
  1116. static void dispc_ovl_enable_replication(struct dispc_device *dispc,
  1117. enum omap_plane_id plane,
  1118. enum omap_overlay_caps caps,
  1119. bool enable)
  1120. {
  1121. static const unsigned int shifts[] = { 5, 10, 10, 10 };
  1122. int shift;
  1123. if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
  1124. return;
  1125. shift = shifts[plane];
  1126. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
  1127. }
  1128. static void dispc_mgr_set_size(struct dispc_device *dispc,
  1129. enum omap_channel channel, u16 width, u16 height)
  1130. {
  1131. u32 val;
  1132. val = FLD_VAL(height - 1, dispc->feat->mgr_height_start, 16) |
  1133. FLD_VAL(width - 1, dispc->feat->mgr_width_start, 0);
  1134. dispc_write_reg(dispc, DISPC_SIZE_MGR(channel), val);
  1135. }
  1136. static void dispc_init_fifos(struct dispc_device *dispc)
  1137. {
  1138. u32 size;
  1139. int fifo;
  1140. u8 start, end;
  1141. u32 unit;
  1142. int i;
  1143. unit = dispc->feat->buffer_size_unit;
  1144. dispc_get_reg_field(dispc, FEAT_REG_FIFOSIZE, &start, &end);
  1145. for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
  1146. size = REG_GET(dispc, DISPC_OVL_FIFO_SIZE_STATUS(fifo),
  1147. start, end);
  1148. size *= unit;
  1149. dispc->fifo_size[fifo] = size;
  1150. /*
  1151. * By default fifos are mapped directly to overlays, fifo 0 to
  1152. * ovl 0, fifo 1 to ovl 1, etc.
  1153. */
  1154. dispc->fifo_assignment[fifo] = fifo;
  1155. }
  1156. /*
  1157. * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
  1158. * causes problems with certain use cases, like using the tiler in 2D
  1159. * mode. The below hack swaps the fifos of GFX and WB planes, thus
  1160. * giving GFX plane a larger fifo. WB but should work fine with a
  1161. * smaller fifo.
  1162. */
  1163. if (dispc->feat->gfx_fifo_workaround) {
  1164. u32 v;
  1165. v = dispc_read_reg(dispc, DISPC_GLOBAL_BUFFER);
  1166. v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
  1167. v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
  1168. v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
  1169. v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
  1170. dispc_write_reg(dispc, DISPC_GLOBAL_BUFFER, v);
  1171. dispc->fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
  1172. dispc->fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
  1173. }
  1174. /*
  1175. * Setup default fifo thresholds.
  1176. */
  1177. for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
  1178. u32 low, high;
  1179. const bool use_fifomerge = false;
  1180. const bool manual_update = false;
  1181. dispc_ovl_compute_fifo_thresholds(dispc, i, &low, &high,
  1182. use_fifomerge, manual_update);
  1183. dispc_ovl_set_fifo_threshold(dispc, i, low, high);
  1184. }
  1185. if (dispc->feat->has_writeback) {
  1186. u32 low, high;
  1187. const bool use_fifomerge = false;
  1188. const bool manual_update = false;
  1189. dispc_ovl_compute_fifo_thresholds(dispc, OMAP_DSS_WB,
  1190. &low, &high, use_fifomerge,
  1191. manual_update);
  1192. dispc_ovl_set_fifo_threshold(dispc, OMAP_DSS_WB, low, high);
  1193. }
  1194. }
  1195. static u32 dispc_ovl_get_fifo_size(struct dispc_device *dispc,
  1196. enum omap_plane_id plane)
  1197. {
  1198. int fifo;
  1199. u32 size = 0;
  1200. for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
  1201. if (dispc->fifo_assignment[fifo] == plane)
  1202. size += dispc->fifo_size[fifo];
  1203. }
  1204. return size;
  1205. }
  1206. void dispc_ovl_set_fifo_threshold(struct dispc_device *dispc,
  1207. enum omap_plane_id plane,
  1208. u32 low, u32 high)
  1209. {
  1210. u8 hi_start, hi_end, lo_start, lo_end;
  1211. u32 unit;
  1212. unit = dispc->feat->buffer_size_unit;
  1213. WARN_ON(low % unit != 0);
  1214. WARN_ON(high % unit != 0);
  1215. low /= unit;
  1216. high /= unit;
  1217. dispc_get_reg_field(dispc, FEAT_REG_FIFOHIGHTHRESHOLD,
  1218. &hi_start, &hi_end);
  1219. dispc_get_reg_field(dispc, FEAT_REG_FIFOLOWTHRESHOLD,
  1220. &lo_start, &lo_end);
  1221. DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
  1222. plane,
  1223. REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1224. lo_start, lo_end) * unit,
  1225. REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1226. hi_start, hi_end) * unit,
  1227. low * unit, high * unit);
  1228. dispc_write_reg(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1229. FLD_VAL(high, hi_start, hi_end) |
  1230. FLD_VAL(low, lo_start, lo_end));
  1231. /*
  1232. * configure the preload to the pipeline's high threhold, if HT it's too
  1233. * large for the preload field, set the threshold to the maximum value
  1234. * that can be held by the preload register
  1235. */
  1236. if (dispc_has_feature(dispc, FEAT_PRELOAD) &&
  1237. dispc->feat->set_max_preload && plane != OMAP_DSS_WB)
  1238. dispc_write_reg(dispc, DISPC_OVL_PRELOAD(plane),
  1239. min(high, 0xfffu));
  1240. }
  1241. void dispc_ovl_compute_fifo_thresholds(struct dispc_device *dispc,
  1242. enum omap_plane_id plane,
  1243. u32 *fifo_low, u32 *fifo_high,
  1244. bool use_fifomerge, bool manual_update)
  1245. {
  1246. /*
  1247. * All sizes are in bytes. Both the buffer and burst are made of
  1248. * buffer_units, and the fifo thresholds must be buffer_unit aligned.
  1249. */
  1250. unsigned int buf_unit = dispc->feat->buffer_size_unit;
  1251. unsigned int ovl_fifo_size, total_fifo_size, burst_size;
  1252. int i;
  1253. burst_size = dispc_ovl_get_burst_size(dispc, plane);
  1254. ovl_fifo_size = dispc_ovl_get_fifo_size(dispc, plane);
  1255. if (use_fifomerge) {
  1256. total_fifo_size = 0;
  1257. for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
  1258. total_fifo_size += dispc_ovl_get_fifo_size(dispc, i);
  1259. } else {
  1260. total_fifo_size = ovl_fifo_size;
  1261. }
  1262. /*
  1263. * We use the same low threshold for both fifomerge and non-fifomerge
  1264. * cases, but for fifomerge we calculate the high threshold using the
  1265. * combined fifo size
  1266. */
  1267. if (manual_update && dispc_has_feature(dispc, FEAT_OMAP3_DSI_FIFO_BUG)) {
  1268. *fifo_low = ovl_fifo_size - burst_size * 2;
  1269. *fifo_high = total_fifo_size - burst_size;
  1270. } else if (plane == OMAP_DSS_WB) {
  1271. /*
  1272. * Most optimal configuration for writeback is to push out data
  1273. * to the interconnect the moment writeback pushes enough pixels
  1274. * in the FIFO to form a burst
  1275. */
  1276. *fifo_low = 0;
  1277. *fifo_high = burst_size;
  1278. } else {
  1279. *fifo_low = ovl_fifo_size - burst_size;
  1280. *fifo_high = total_fifo_size - buf_unit;
  1281. }
  1282. }
  1283. static void dispc_ovl_set_mflag(struct dispc_device *dispc,
  1284. enum omap_plane_id plane, bool enable)
  1285. {
  1286. int bit;
  1287. if (plane == OMAP_DSS_GFX)
  1288. bit = 14;
  1289. else
  1290. bit = 23;
  1291. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
  1292. }
  1293. static void dispc_ovl_set_mflag_threshold(struct dispc_device *dispc,
  1294. enum omap_plane_id plane,
  1295. int low, int high)
  1296. {
  1297. dispc_write_reg(dispc, DISPC_OVL_MFLAG_THRESHOLD(plane),
  1298. FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
  1299. }
  1300. static void dispc_init_mflag(struct dispc_device *dispc)
  1301. {
  1302. int i;
  1303. /*
  1304. * HACK: NV12 color format and MFLAG seem to have problems working
  1305. * together: using two displays, and having an NV12 overlay on one of
  1306. * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
  1307. * Changing MFLAG thresholds and PRELOAD to certain values seem to
  1308. * remove the errors, but there doesn't seem to be a clear logic on
  1309. * which values work and which not.
  1310. *
  1311. * As a work-around, set force MFLAG to always on.
  1312. */
  1313. dispc_write_reg(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE,
  1314. (1 << 0) | /* MFLAG_CTRL = force always on */
  1315. (0 << 2)); /* MFLAG_START = disable */
  1316. for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
  1317. u32 size = dispc_ovl_get_fifo_size(dispc, i);
  1318. u32 unit = dispc->feat->buffer_size_unit;
  1319. u32 low, high;
  1320. dispc_ovl_set_mflag(dispc, i, true);
  1321. /*
  1322. * Simulation team suggests below thesholds:
  1323. * HT = fifosize * 5 / 8;
  1324. * LT = fifosize * 4 / 8;
  1325. */
  1326. low = size * 4 / 8 / unit;
  1327. high = size * 5 / 8 / unit;
  1328. dispc_ovl_set_mflag_threshold(dispc, i, low, high);
  1329. }
  1330. if (dispc->feat->has_writeback) {
  1331. u32 size = dispc_ovl_get_fifo_size(dispc, OMAP_DSS_WB);
  1332. u32 unit = dispc->feat->buffer_size_unit;
  1333. u32 low, high;
  1334. dispc_ovl_set_mflag(dispc, OMAP_DSS_WB, true);
  1335. /*
  1336. * Simulation team suggests below thesholds:
  1337. * HT = fifosize * 5 / 8;
  1338. * LT = fifosize * 4 / 8;
  1339. */
  1340. low = size * 4 / 8 / unit;
  1341. high = size * 5 / 8 / unit;
  1342. dispc_ovl_set_mflag_threshold(dispc, OMAP_DSS_WB, low, high);
  1343. }
  1344. }
  1345. static void dispc_ovl_set_fir(struct dispc_device *dispc,
  1346. enum omap_plane_id plane,
  1347. int hinc, int vinc,
  1348. enum omap_color_component color_comp)
  1349. {
  1350. u32 val;
  1351. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  1352. u8 hinc_start, hinc_end, vinc_start, vinc_end;
  1353. dispc_get_reg_field(dispc, FEAT_REG_FIRHINC,
  1354. &hinc_start, &hinc_end);
  1355. dispc_get_reg_field(dispc, FEAT_REG_FIRVINC,
  1356. &vinc_start, &vinc_end);
  1357. val = FLD_VAL(vinc, vinc_start, vinc_end) |
  1358. FLD_VAL(hinc, hinc_start, hinc_end);
  1359. dispc_write_reg(dispc, DISPC_OVL_FIR(plane), val);
  1360. } else {
  1361. val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
  1362. dispc_write_reg(dispc, DISPC_OVL_FIR2(plane), val);
  1363. }
  1364. }
  1365. static void dispc_ovl_set_vid_accu0(struct dispc_device *dispc,
  1366. enum omap_plane_id plane, int haccu,
  1367. int vaccu)
  1368. {
  1369. u32 val;
  1370. u8 hor_start, hor_end, vert_start, vert_end;
  1371. dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
  1372. &hor_start, &hor_end);
  1373. dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
  1374. &vert_start, &vert_end);
  1375. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1376. FLD_VAL(haccu, hor_start, hor_end);
  1377. dispc_write_reg(dispc, DISPC_OVL_ACCU0(plane), val);
  1378. }
  1379. static void dispc_ovl_set_vid_accu1(struct dispc_device *dispc,
  1380. enum omap_plane_id plane, int haccu,
  1381. int vaccu)
  1382. {
  1383. u32 val;
  1384. u8 hor_start, hor_end, vert_start, vert_end;
  1385. dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
  1386. &hor_start, &hor_end);
  1387. dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
  1388. &vert_start, &vert_end);
  1389. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1390. FLD_VAL(haccu, hor_start, hor_end);
  1391. dispc_write_reg(dispc, DISPC_OVL_ACCU1(plane), val);
  1392. }
  1393. static void dispc_ovl_set_vid_accu2_0(struct dispc_device *dispc,
  1394. enum omap_plane_id plane, int haccu,
  1395. int vaccu)
  1396. {
  1397. u32 val;
  1398. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1399. dispc_write_reg(dispc, DISPC_OVL_ACCU2_0(plane), val);
  1400. }
  1401. static void dispc_ovl_set_vid_accu2_1(struct dispc_device *dispc,
  1402. enum omap_plane_id plane, int haccu,
  1403. int vaccu)
  1404. {
  1405. u32 val;
  1406. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1407. dispc_write_reg(dispc, DISPC_OVL_ACCU2_1(plane), val);
  1408. }
  1409. static void dispc_ovl_set_scale_param(struct dispc_device *dispc,
  1410. enum omap_plane_id plane,
  1411. u16 orig_width, u16 orig_height,
  1412. u16 out_width, u16 out_height,
  1413. bool five_taps, u8 rotation,
  1414. enum omap_color_component color_comp)
  1415. {
  1416. int fir_hinc, fir_vinc;
  1417. fir_hinc = 1024 * orig_width / out_width;
  1418. fir_vinc = 1024 * orig_height / out_height;
  1419. dispc_ovl_set_scale_coef(dispc, plane, fir_hinc, fir_vinc, five_taps,
  1420. color_comp);
  1421. dispc_ovl_set_fir(dispc, plane, fir_hinc, fir_vinc, color_comp);
  1422. }
  1423. static void dispc_ovl_set_accu_uv(struct dispc_device *dispc,
  1424. enum omap_plane_id plane,
  1425. u16 orig_width, u16 orig_height,
  1426. u16 out_width, u16 out_height,
  1427. bool ilace, u32 fourcc, u8 rotation)
  1428. {
  1429. int h_accu2_0, h_accu2_1;
  1430. int v_accu2_0, v_accu2_1;
  1431. int chroma_hinc, chroma_vinc;
  1432. int idx;
  1433. struct accu {
  1434. s8 h0_m, h0_n;
  1435. s8 h1_m, h1_n;
  1436. s8 v0_m, v0_n;
  1437. s8 v1_m, v1_n;
  1438. };
  1439. const struct accu *accu_table;
  1440. const struct accu *accu_val;
  1441. static const struct accu accu_nv12[4] = {
  1442. { 0, 1, 0, 1 , -1, 2, 0, 1 },
  1443. { 1, 2, -3, 4 , 0, 1, 0, 1 },
  1444. { -1, 1, 0, 1 , -1, 2, 0, 1 },
  1445. { -1, 2, -1, 2 , -1, 1, 0, 1 },
  1446. };
  1447. static const struct accu accu_nv12_ilace[4] = {
  1448. { 0, 1, 0, 1 , -3, 4, -1, 4 },
  1449. { -1, 4, -3, 4 , 0, 1, 0, 1 },
  1450. { -1, 1, 0, 1 , -1, 4, -3, 4 },
  1451. { -3, 4, -3, 4 , -1, 1, 0, 1 },
  1452. };
  1453. static const struct accu accu_yuv[4] = {
  1454. { 0, 1, 0, 1, 0, 1, 0, 1 },
  1455. { 0, 1, 0, 1, 0, 1, 0, 1 },
  1456. { -1, 1, 0, 1, 0, 1, 0, 1 },
  1457. { 0, 1, 0, 1, -1, 1, 0, 1 },
  1458. };
  1459. /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
  1460. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1461. default:
  1462. case DRM_MODE_ROTATE_0:
  1463. idx = 0;
  1464. break;
  1465. case DRM_MODE_ROTATE_90:
  1466. idx = 3;
  1467. break;
  1468. case DRM_MODE_ROTATE_180:
  1469. idx = 2;
  1470. break;
  1471. case DRM_MODE_ROTATE_270:
  1472. idx = 1;
  1473. break;
  1474. }
  1475. switch (fourcc) {
  1476. case DRM_FORMAT_NV12:
  1477. if (ilace)
  1478. accu_table = accu_nv12_ilace;
  1479. else
  1480. accu_table = accu_nv12;
  1481. break;
  1482. case DRM_FORMAT_YUYV:
  1483. case DRM_FORMAT_UYVY:
  1484. accu_table = accu_yuv;
  1485. break;
  1486. default:
  1487. BUG();
  1488. return;
  1489. }
  1490. accu_val = &accu_table[idx];
  1491. chroma_hinc = 1024 * orig_width / out_width;
  1492. chroma_vinc = 1024 * orig_height / out_height;
  1493. h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
  1494. h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
  1495. v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
  1496. v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
  1497. dispc_ovl_set_vid_accu2_0(dispc, plane, h_accu2_0, v_accu2_0);
  1498. dispc_ovl_set_vid_accu2_1(dispc, plane, h_accu2_1, v_accu2_1);
  1499. }
  1500. static void dispc_ovl_set_scaling_common(struct dispc_device *dispc,
  1501. enum omap_plane_id plane,
  1502. u16 orig_width, u16 orig_height,
  1503. u16 out_width, u16 out_height,
  1504. bool ilace, bool five_taps,
  1505. bool fieldmode, u32 fourcc,
  1506. u8 rotation)
  1507. {
  1508. int accu0 = 0;
  1509. int accu1 = 0;
  1510. u32 l;
  1511. dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
  1512. out_width, out_height, five_taps,
  1513. rotation, DISPC_COLOR_COMPONENT_RGB_Y);
  1514. l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1515. /* RESIZEENABLE and VERTICALTAPS */
  1516. l &= ~((0x3 << 5) | (0x1 << 21));
  1517. l |= (orig_width != out_width) ? (1 << 5) : 0;
  1518. l |= (orig_height != out_height) ? (1 << 6) : 0;
  1519. l |= five_taps ? (1 << 21) : 0;
  1520. /* VRESIZECONF and HRESIZECONF */
  1521. if (dispc_has_feature(dispc, FEAT_RESIZECONF)) {
  1522. l &= ~(0x3 << 7);
  1523. l |= (orig_width <= out_width) ? 0 : (1 << 7);
  1524. l |= (orig_height <= out_height) ? 0 : (1 << 8);
  1525. }
  1526. /* LINEBUFFERSPLIT */
  1527. if (dispc_has_feature(dispc, FEAT_LINEBUFFERSPLIT)) {
  1528. l &= ~(0x1 << 22);
  1529. l |= five_taps ? (1 << 22) : 0;
  1530. }
  1531. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
  1532. /*
  1533. * field 0 = even field = bottom field
  1534. * field 1 = odd field = top field
  1535. */
  1536. if (ilace && !fieldmode) {
  1537. accu1 = 0;
  1538. accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
  1539. if (accu0 >= 1024/2) {
  1540. accu1 = 1024/2;
  1541. accu0 -= accu1;
  1542. }
  1543. }
  1544. dispc_ovl_set_vid_accu0(dispc, plane, 0, accu0);
  1545. dispc_ovl_set_vid_accu1(dispc, plane, 0, accu1);
  1546. }
  1547. static void dispc_ovl_set_scaling_uv(struct dispc_device *dispc,
  1548. enum omap_plane_id plane,
  1549. u16 orig_width, u16 orig_height,
  1550. u16 out_width, u16 out_height,
  1551. bool ilace, bool five_taps,
  1552. bool fieldmode, u32 fourcc,
  1553. u8 rotation)
  1554. {
  1555. int scale_x = out_width != orig_width;
  1556. int scale_y = out_height != orig_height;
  1557. bool chroma_upscale = plane != OMAP_DSS_WB;
  1558. const struct drm_format_info *info;
  1559. info = drm_format_info(fourcc);
  1560. if (!dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE))
  1561. return;
  1562. if (!info->is_yuv) {
  1563. /* reset chroma resampling for RGB formats */
  1564. if (plane != OMAP_DSS_WB)
  1565. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
  1566. 0, 8, 8);
  1567. return;
  1568. }
  1569. dispc_ovl_set_accu_uv(dispc, plane, orig_width, orig_height, out_width,
  1570. out_height, ilace, fourcc, rotation);
  1571. switch (fourcc) {
  1572. case DRM_FORMAT_NV12:
  1573. if (chroma_upscale) {
  1574. /* UV is subsampled by 2 horizontally and vertically */
  1575. orig_height >>= 1;
  1576. orig_width >>= 1;
  1577. } else {
  1578. /* UV is downsampled by 2 horizontally and vertically */
  1579. orig_height <<= 1;
  1580. orig_width <<= 1;
  1581. }
  1582. break;
  1583. case DRM_FORMAT_YUYV:
  1584. case DRM_FORMAT_UYVY:
  1585. /* For YUV422 with 90/270 rotation, we don't upsample chroma */
  1586. if (!drm_rotation_90_or_270(rotation)) {
  1587. if (chroma_upscale)
  1588. /* UV is subsampled by 2 horizontally */
  1589. orig_width >>= 1;
  1590. else
  1591. /* UV is downsampled by 2 horizontally */
  1592. orig_width <<= 1;
  1593. }
  1594. /* must use FIR for YUV422 if rotated */
  1595. if ((rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0)
  1596. scale_x = scale_y = true;
  1597. break;
  1598. default:
  1599. BUG();
  1600. return;
  1601. }
  1602. if (out_width != orig_width)
  1603. scale_x = true;
  1604. if (out_height != orig_height)
  1605. scale_y = true;
  1606. dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
  1607. out_width, out_height, five_taps,
  1608. rotation, DISPC_COLOR_COMPONENT_UV);
  1609. if (plane != OMAP_DSS_WB)
  1610. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
  1611. (scale_x || scale_y) ? 1 : 0, 8, 8);
  1612. /* set H scaling */
  1613. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
  1614. /* set V scaling */
  1615. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
  1616. }
  1617. static void dispc_ovl_set_scaling(struct dispc_device *dispc,
  1618. enum omap_plane_id plane,
  1619. u16 orig_width, u16 orig_height,
  1620. u16 out_width, u16 out_height,
  1621. bool ilace, bool five_taps,
  1622. bool fieldmode, u32 fourcc,
  1623. u8 rotation)
  1624. {
  1625. BUG_ON(plane == OMAP_DSS_GFX);
  1626. dispc_ovl_set_scaling_common(dispc, plane, orig_width, orig_height,
  1627. out_width, out_height, ilace, five_taps,
  1628. fieldmode, fourcc, rotation);
  1629. dispc_ovl_set_scaling_uv(dispc, plane, orig_width, orig_height,
  1630. out_width, out_height, ilace, five_taps,
  1631. fieldmode, fourcc, rotation);
  1632. }
  1633. static void dispc_ovl_set_rotation_attrs(struct dispc_device *dispc,
  1634. enum omap_plane_id plane, u8 rotation,
  1635. enum omap_dss_rotation_type rotation_type,
  1636. u32 fourcc)
  1637. {
  1638. bool row_repeat = false;
  1639. int vidrot = 0;
  1640. /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
  1641. if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY) {
  1642. if (rotation & DRM_MODE_REFLECT_X) {
  1643. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1644. case DRM_MODE_ROTATE_0:
  1645. vidrot = 2;
  1646. break;
  1647. case DRM_MODE_ROTATE_90:
  1648. vidrot = 1;
  1649. break;
  1650. case DRM_MODE_ROTATE_180:
  1651. vidrot = 0;
  1652. break;
  1653. case DRM_MODE_ROTATE_270:
  1654. vidrot = 3;
  1655. break;
  1656. }
  1657. } else {
  1658. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1659. case DRM_MODE_ROTATE_0:
  1660. vidrot = 0;
  1661. break;
  1662. case DRM_MODE_ROTATE_90:
  1663. vidrot = 3;
  1664. break;
  1665. case DRM_MODE_ROTATE_180:
  1666. vidrot = 2;
  1667. break;
  1668. case DRM_MODE_ROTATE_270:
  1669. vidrot = 1;
  1670. break;
  1671. }
  1672. }
  1673. if (drm_rotation_90_or_270(rotation))
  1674. row_repeat = true;
  1675. else
  1676. row_repeat = false;
  1677. }
  1678. /*
  1679. * OMAP4/5 Errata i631:
  1680. * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
  1681. * rows beyond the framebuffer, which may cause OCP error.
  1682. */
  1683. if (fourcc == DRM_FORMAT_NV12 && rotation_type != OMAP_DSS_ROT_TILER)
  1684. vidrot = 1;
  1685. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
  1686. if (dispc_has_feature(dispc, FEAT_ROWREPEATENABLE))
  1687. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
  1688. row_repeat ? 1 : 0, 18, 18);
  1689. if (dispc_ovl_color_mode_supported(dispc, plane, DRM_FORMAT_NV12)) {
  1690. bool doublestride =
  1691. fourcc == DRM_FORMAT_NV12 &&
  1692. rotation_type == OMAP_DSS_ROT_TILER &&
  1693. !drm_rotation_90_or_270(rotation);
  1694. /* DOUBLESTRIDE */
  1695. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
  1696. doublestride, 22, 22);
  1697. }
  1698. }
  1699. static int color_mode_to_bpp(u32 fourcc)
  1700. {
  1701. switch (fourcc) {
  1702. case DRM_FORMAT_NV12:
  1703. return 8;
  1704. case DRM_FORMAT_RGBX4444:
  1705. case DRM_FORMAT_RGB565:
  1706. case DRM_FORMAT_ARGB4444:
  1707. case DRM_FORMAT_YUYV:
  1708. case DRM_FORMAT_UYVY:
  1709. case DRM_FORMAT_RGBA4444:
  1710. case DRM_FORMAT_XRGB4444:
  1711. case DRM_FORMAT_ARGB1555:
  1712. case DRM_FORMAT_XRGB1555:
  1713. return 16;
  1714. case DRM_FORMAT_RGB888:
  1715. return 24;
  1716. case DRM_FORMAT_XRGB8888:
  1717. case DRM_FORMAT_ARGB8888:
  1718. case DRM_FORMAT_RGBA8888:
  1719. case DRM_FORMAT_RGBX8888:
  1720. return 32;
  1721. default:
  1722. BUG();
  1723. return 0;
  1724. }
  1725. }
  1726. static s32 pixinc(int pixels, u8 ps)
  1727. {
  1728. if (pixels == 1)
  1729. return 1;
  1730. else if (pixels > 1)
  1731. return 1 + (pixels - 1) * ps;
  1732. else if (pixels < 0)
  1733. return 1 - (-pixels + 1) * ps;
  1734. BUG();
  1735. }
  1736. static void calc_offset(u16 screen_width, u16 width,
  1737. u32 fourcc, bool fieldmode, unsigned int field_offset,
  1738. unsigned int *offset0, unsigned int *offset1,
  1739. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim,
  1740. enum omap_dss_rotation_type rotation_type, u8 rotation)
  1741. {
  1742. u8 ps;
  1743. ps = color_mode_to_bpp(fourcc) / 8;
  1744. DSSDBG("scrw %d, width %d\n", screen_width, width);
  1745. if (rotation_type == OMAP_DSS_ROT_TILER &&
  1746. (fourcc == DRM_FORMAT_UYVY || fourcc == DRM_FORMAT_YUYV) &&
  1747. drm_rotation_90_or_270(rotation)) {
  1748. /*
  1749. * HACK: ROW_INC needs to be calculated with TILER units.
  1750. * We get such 'screen_width' that multiplying it with the
  1751. * YUV422 pixel size gives the correct TILER container width.
  1752. * However, 'width' is in pixels and multiplying it with YUV422
  1753. * pixel size gives incorrect result. We thus multiply it here
  1754. * with 2 to match the 32 bit TILER unit size.
  1755. */
  1756. width *= 2;
  1757. }
  1758. /*
  1759. * field 0 = even field = bottom field
  1760. * field 1 = odd field = top field
  1761. */
  1762. *offset0 = field_offset * screen_width * ps;
  1763. *offset1 = 0;
  1764. *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
  1765. (fieldmode ? screen_width : 0), ps);
  1766. if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY)
  1767. *pix_inc = pixinc(x_predecim, 2 * ps);
  1768. else
  1769. *pix_inc = pixinc(x_predecim, ps);
  1770. }
  1771. /*
  1772. * This function is used to avoid synclosts in OMAP3, because of some
  1773. * undocumented horizontal position and timing related limitations.
  1774. */
  1775. static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
  1776. const struct videomode *vm, u16 pos_x,
  1777. u16 width, u16 height, u16 out_width, u16 out_height,
  1778. bool five_taps)
  1779. {
  1780. const int ds = DIV_ROUND_UP(height, out_height);
  1781. unsigned long nonactive;
  1782. static const u8 limits[3] = { 8, 10, 20 };
  1783. u64 val, blank;
  1784. int i;
  1785. nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
  1786. vm->hback_porch - out_width;
  1787. i = 0;
  1788. if (out_height < height)
  1789. i++;
  1790. if (out_width < width)
  1791. i++;
  1792. blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
  1793. lclk, pclk);
  1794. DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
  1795. if (blank <= limits[i])
  1796. return -EINVAL;
  1797. /* FIXME add checks for 3-tap filter once the limitations are known */
  1798. if (!five_taps)
  1799. return 0;
  1800. /*
  1801. * Pixel data should be prepared before visible display point starts.
  1802. * So, atleast DS-2 lines must have already been fetched by DISPC
  1803. * during nonactive - pos_x period.
  1804. */
  1805. val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
  1806. DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
  1807. val, max(0, ds - 2) * width);
  1808. if (val < max(0, ds - 2) * width)
  1809. return -EINVAL;
  1810. /*
  1811. * All lines need to be refilled during the nonactive period of which
  1812. * only one line can be loaded during the active period. So, atleast
  1813. * DS - 1 lines should be loaded during nonactive period.
  1814. */
  1815. val = div_u64((u64)nonactive * lclk, pclk);
  1816. DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
  1817. val, max(0, ds - 1) * width);
  1818. if (val < max(0, ds - 1) * width)
  1819. return -EINVAL;
  1820. return 0;
  1821. }
  1822. static unsigned long calc_core_clk_five_taps(unsigned long pclk,
  1823. const struct videomode *vm, u16 width,
  1824. u16 height, u16 out_width, u16 out_height,
  1825. u32 fourcc)
  1826. {
  1827. u32 core_clk = 0;
  1828. u64 tmp;
  1829. if (height <= out_height && width <= out_width)
  1830. return (unsigned long) pclk;
  1831. if (height > out_height) {
  1832. unsigned int ppl = vm->hactive;
  1833. tmp = (u64)pclk * height * out_width;
  1834. do_div(tmp, 2 * out_height * ppl);
  1835. core_clk = tmp;
  1836. if (height > 2 * out_height) {
  1837. if (ppl == out_width)
  1838. return 0;
  1839. tmp = (u64)pclk * (height - 2 * out_height) * out_width;
  1840. do_div(tmp, 2 * out_height * (ppl - out_width));
  1841. core_clk = max_t(u32, core_clk, tmp);
  1842. }
  1843. }
  1844. if (width > out_width) {
  1845. tmp = (u64)pclk * width;
  1846. do_div(tmp, out_width);
  1847. core_clk = max_t(u32, core_clk, tmp);
  1848. if (fourcc == DRM_FORMAT_XRGB8888)
  1849. core_clk <<= 1;
  1850. }
  1851. return core_clk;
  1852. }
  1853. static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
  1854. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1855. {
  1856. if (height > out_height && width > out_width)
  1857. return pclk * 4;
  1858. else
  1859. return pclk * 2;
  1860. }
  1861. static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
  1862. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1863. {
  1864. unsigned int hf, vf;
  1865. /*
  1866. * FIXME how to determine the 'A' factor
  1867. * for the no downscaling case ?
  1868. */
  1869. if (width > 3 * out_width)
  1870. hf = 4;
  1871. else if (width > 2 * out_width)
  1872. hf = 3;
  1873. else if (width > out_width)
  1874. hf = 2;
  1875. else
  1876. hf = 1;
  1877. if (height > out_height)
  1878. vf = 2;
  1879. else
  1880. vf = 1;
  1881. return pclk * vf * hf;
  1882. }
  1883. static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
  1884. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1885. {
  1886. /*
  1887. * If the overlay/writeback is in mem to mem mode, there are no
  1888. * downscaling limitations with respect to pixel clock, return 1 as
  1889. * required core clock to represent that we have sufficient enough
  1890. * core clock to do maximum downscaling
  1891. */
  1892. if (mem_to_mem)
  1893. return 1;
  1894. if (width > out_width)
  1895. return DIV_ROUND_UP(pclk, out_width) * width;
  1896. else
  1897. return pclk;
  1898. }
  1899. static int dispc_ovl_calc_scaling_24xx(struct dispc_device *dispc,
  1900. unsigned long pclk, unsigned long lclk,
  1901. const struct videomode *vm,
  1902. u16 width, u16 height,
  1903. u16 out_width, u16 out_height,
  1904. u32 fourcc, bool *five_taps,
  1905. int *x_predecim, int *y_predecim,
  1906. int *decim_x, int *decim_y,
  1907. u16 pos_x, unsigned long *core_clk,
  1908. bool mem_to_mem)
  1909. {
  1910. int error;
  1911. u16 in_width, in_height;
  1912. int min_factor = min(*decim_x, *decim_y);
  1913. const int maxsinglelinewidth = dispc->feat->max_line_width;
  1914. *five_taps = false;
  1915. do {
  1916. in_height = height / *decim_y;
  1917. in_width = width / *decim_x;
  1918. *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
  1919. in_height, out_width, out_height, mem_to_mem);
  1920. error = (in_width > maxsinglelinewidth || !*core_clk ||
  1921. *core_clk > dispc_core_clk_rate(dispc));
  1922. if (error) {
  1923. if (*decim_x == *decim_y) {
  1924. *decim_x = min_factor;
  1925. ++*decim_y;
  1926. } else {
  1927. swap(*decim_x, *decim_y);
  1928. if (*decim_x < *decim_y)
  1929. ++*decim_x;
  1930. }
  1931. }
  1932. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  1933. if (error) {
  1934. DSSERR("failed to find scaling settings\n");
  1935. return -EINVAL;
  1936. }
  1937. if (in_width > maxsinglelinewidth) {
  1938. DSSERR("Cannot scale max input width exceeded\n");
  1939. return -EINVAL;
  1940. }
  1941. return 0;
  1942. }
  1943. static int dispc_ovl_calc_scaling_34xx(struct dispc_device *dispc,
  1944. unsigned long pclk, unsigned long lclk,
  1945. const struct videomode *vm,
  1946. u16 width, u16 height,
  1947. u16 out_width, u16 out_height,
  1948. u32 fourcc, bool *five_taps,
  1949. int *x_predecim, int *y_predecim,
  1950. int *decim_x, int *decim_y,
  1951. u16 pos_x, unsigned long *core_clk,
  1952. bool mem_to_mem)
  1953. {
  1954. int error;
  1955. u16 in_width, in_height;
  1956. const int maxsinglelinewidth = dispc->feat->max_line_width;
  1957. do {
  1958. in_height = height / *decim_y;
  1959. in_width = width / *decim_x;
  1960. *five_taps = in_height > out_height;
  1961. if (in_width > maxsinglelinewidth)
  1962. if (in_height > out_height &&
  1963. in_height < out_height * 2)
  1964. *five_taps = false;
  1965. again:
  1966. if (*five_taps)
  1967. *core_clk = calc_core_clk_five_taps(pclk, vm,
  1968. in_width, in_height, out_width,
  1969. out_height, fourcc);
  1970. else
  1971. *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
  1972. in_height, out_width, out_height,
  1973. mem_to_mem);
  1974. error = check_horiz_timing_omap3(pclk, lclk, vm,
  1975. pos_x, in_width, in_height, out_width,
  1976. out_height, *five_taps);
  1977. if (error && *five_taps) {
  1978. *five_taps = false;
  1979. goto again;
  1980. }
  1981. error = (error || in_width > maxsinglelinewidth * 2 ||
  1982. (in_width > maxsinglelinewidth && *five_taps) ||
  1983. !*core_clk || *core_clk > dispc_core_clk_rate(dispc));
  1984. if (!error) {
  1985. /* verify that we're inside the limits of scaler */
  1986. if (in_width / 4 > out_width)
  1987. error = 1;
  1988. if (*five_taps) {
  1989. if (in_height / 4 > out_height)
  1990. error = 1;
  1991. } else {
  1992. if (in_height / 2 > out_height)
  1993. error = 1;
  1994. }
  1995. }
  1996. if (error)
  1997. ++*decim_y;
  1998. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  1999. if (error) {
  2000. DSSERR("failed to find scaling settings\n");
  2001. return -EINVAL;
  2002. }
  2003. if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
  2004. in_height, out_width, out_height, *five_taps)) {
  2005. DSSERR("horizontal timing too tight\n");
  2006. return -EINVAL;
  2007. }
  2008. if (in_width > (maxsinglelinewidth * 2)) {
  2009. DSSERR("Cannot setup scaling\n");
  2010. DSSERR("width exceeds maximum width possible\n");
  2011. return -EINVAL;
  2012. }
  2013. if (in_width > maxsinglelinewidth && *five_taps) {
  2014. DSSERR("cannot setup scaling with five taps\n");
  2015. return -EINVAL;
  2016. }
  2017. return 0;
  2018. }
  2019. static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc,
  2020. unsigned long pclk, unsigned long lclk,
  2021. const struct videomode *vm,
  2022. u16 width, u16 height,
  2023. u16 out_width, u16 out_height,
  2024. u32 fourcc, bool *five_taps,
  2025. int *x_predecim, int *y_predecim,
  2026. int *decim_x, int *decim_y,
  2027. u16 pos_x, unsigned long *core_clk,
  2028. bool mem_to_mem)
  2029. {
  2030. u16 in_width, in_width_max;
  2031. int decim_x_min = *decim_x;
  2032. u16 in_height = height / *decim_y;
  2033. const int maxsinglelinewidth = dispc->feat->max_line_width;
  2034. const int maxdownscale = dispc->feat->max_downscale;
  2035. if (mem_to_mem) {
  2036. in_width_max = out_width * maxdownscale;
  2037. } else {
  2038. in_width_max = dispc_core_clk_rate(dispc)
  2039. / DIV_ROUND_UP(pclk, out_width);
  2040. }
  2041. *decim_x = DIV_ROUND_UP(width, in_width_max);
  2042. *decim_x = max(*decim_x, decim_x_min);
  2043. if (*decim_x > *x_predecim)
  2044. return -EINVAL;
  2045. do {
  2046. in_width = width / *decim_x;
  2047. } while (*decim_x <= *x_predecim &&
  2048. in_width > maxsinglelinewidth && ++*decim_x);
  2049. if (in_width > maxsinglelinewidth) {
  2050. DSSERR("Cannot scale width exceeds max line width\n");
  2051. return -EINVAL;
  2052. }
  2053. if (*decim_x > 4 && fourcc != DRM_FORMAT_NV12) {
  2054. /*
  2055. * Let's disable all scaling that requires horizontal
  2056. * decimation with higher factor than 4, until we have
  2057. * better estimates of what we can and can not
  2058. * do. However, NV12 color format appears to work Ok
  2059. * with all decimation factors.
  2060. *
  2061. * When decimating horizontally by more that 4 the dss
  2062. * is not able to fetch the data in burst mode. When
  2063. * this happens it is hard to tell if there enough
  2064. * bandwidth. Despite what theory says this appears to
  2065. * be true also for 16-bit color formats.
  2066. */
  2067. DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)\n", *decim_x);
  2068. return -EINVAL;
  2069. }
  2070. *core_clk = dispc->feat->calc_core_clk(pclk, in_width, in_height,
  2071. out_width, out_height, mem_to_mem);
  2072. return 0;
  2073. }
  2074. enum omap_overlay_caps dispc_ovl_get_caps(struct dispc_device *dispc, enum omap_plane_id plane)
  2075. {
  2076. return dispc->feat->overlay_caps[plane];
  2077. }
  2078. #define DIV_FRAC(dividend, divisor) \
  2079. ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
  2080. static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
  2081. enum omap_plane_id plane,
  2082. unsigned long pclk, unsigned long lclk,
  2083. enum omap_overlay_caps caps,
  2084. const struct videomode *vm,
  2085. u16 width, u16 height,
  2086. u16 out_width, u16 out_height,
  2087. u32 fourcc, bool *five_taps,
  2088. int *x_predecim, int *y_predecim, u16 pos_x,
  2089. enum omap_dss_rotation_type rotation_type,
  2090. bool mem_to_mem)
  2091. {
  2092. int maxhdownscale = dispc->feat->max_downscale;
  2093. int maxvdownscale = dispc->feat->max_downscale;
  2094. const int max_decim_limit = 16;
  2095. unsigned long core_clk = 0;
  2096. int decim_x, decim_y, ret;
  2097. if (width == out_width && height == out_height)
  2098. return 0;
  2099. if (dispc->feat->supported_scaler_color_modes) {
  2100. const u32 *modes = dispc->feat->supported_scaler_color_modes;
  2101. unsigned int i;
  2102. for (i = 0; modes[i]; ++i) {
  2103. if (modes[i] == fourcc)
  2104. break;
  2105. }
  2106. if (modes[i] == 0)
  2107. return -EINVAL;
  2108. }
  2109. if (plane == OMAP_DSS_WB) {
  2110. switch (fourcc) {
  2111. case DRM_FORMAT_NV12:
  2112. maxhdownscale = maxvdownscale = 2;
  2113. break;
  2114. case DRM_FORMAT_YUYV:
  2115. case DRM_FORMAT_UYVY:
  2116. maxhdownscale = 2;
  2117. maxvdownscale = 4;
  2118. break;
  2119. default:
  2120. break;
  2121. }
  2122. }
  2123. if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
  2124. DSSERR("cannot calculate scaling settings: pclk is zero\n");
  2125. return -EINVAL;
  2126. }
  2127. if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
  2128. return -EINVAL;
  2129. if (mem_to_mem) {
  2130. *x_predecim = *y_predecim = 1;
  2131. } else {
  2132. *x_predecim = max_decim_limit;
  2133. *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
  2134. dispc_has_feature(dispc, FEAT_BURST_2D)) ?
  2135. 2 : max_decim_limit;
  2136. }
  2137. decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxhdownscale);
  2138. decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxvdownscale);
  2139. if (decim_x > *x_predecim || out_width > width * 8)
  2140. return -EINVAL;
  2141. if (decim_y > *y_predecim || out_height > height * 8)
  2142. return -EINVAL;
  2143. ret = dispc->feat->calc_scaling(dispc, pclk, lclk, vm, width, height,
  2144. out_width, out_height, fourcc,
  2145. five_taps, x_predecim, y_predecim,
  2146. &decim_x, &decim_y, pos_x, &core_clk,
  2147. mem_to_mem);
  2148. if (ret)
  2149. return ret;
  2150. DSSDBG("%dx%d -> %dx%d (%d.%02d x %d.%02d), decim %dx%d %dx%d (%d.%02d x %d.%02d), taps %d, req clk %lu, cur clk %lu\n",
  2151. width, height,
  2152. out_width, out_height,
  2153. out_width / width, DIV_FRAC(out_width, width),
  2154. out_height / height, DIV_FRAC(out_height, height),
  2155. decim_x, decim_y,
  2156. width / decim_x, height / decim_y,
  2157. out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
  2158. out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
  2159. *five_taps ? 5 : 3,
  2160. core_clk, dispc_core_clk_rate(dispc));
  2161. if (!core_clk || core_clk > dispc_core_clk_rate(dispc)) {
  2162. DSSERR("failed to set up scaling, "
  2163. "required core clk rate = %lu Hz, "
  2164. "current core clk rate = %lu Hz\n",
  2165. core_clk, dispc_core_clk_rate(dispc));
  2166. return -EINVAL;
  2167. }
  2168. *x_predecim = decim_x;
  2169. *y_predecim = decim_y;
  2170. return 0;
  2171. }
  2172. void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height)
  2173. {
  2174. *width = dispc->feat->ovl_width_max;
  2175. *height = dispc->feat->ovl_height_max;
  2176. }
  2177. static int dispc_ovl_setup_common(struct dispc_device *dispc,
  2178. enum omap_plane_id plane,
  2179. enum omap_overlay_caps caps,
  2180. u32 paddr, u32 p_uv_addr,
  2181. u16 screen_width, int pos_x, int pos_y,
  2182. u16 width, u16 height,
  2183. u16 out_width, u16 out_height,
  2184. u32 fourcc, u8 rotation, u8 zorder,
  2185. u8 pre_mult_alpha, u8 global_alpha,
  2186. enum omap_dss_rotation_type rotation_type,
  2187. bool replication, const struct videomode *vm,
  2188. bool mem_to_mem,
  2189. enum drm_color_encoding color_encoding,
  2190. enum drm_color_range color_range)
  2191. {
  2192. bool five_taps = true;
  2193. bool fieldmode = false;
  2194. int r, cconv = 0;
  2195. unsigned int offset0, offset1;
  2196. s32 row_inc;
  2197. s32 pix_inc;
  2198. u16 frame_width;
  2199. unsigned int field_offset = 0;
  2200. u16 in_height = height;
  2201. u16 in_width = width;
  2202. int x_predecim = 1, y_predecim = 1;
  2203. bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
  2204. unsigned long pclk = dispc_plane_pclk_rate(dispc, plane);
  2205. unsigned long lclk = dispc_plane_lclk_rate(dispc, plane);
  2206. const struct drm_format_info *info;
  2207. info = drm_format_info(fourcc);
  2208. /* when setting up WB, dispc_plane_pclk_rate() returns 0 */
  2209. if (plane == OMAP_DSS_WB)
  2210. pclk = vm->pixelclock;
  2211. if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
  2212. return -EINVAL;
  2213. if (info->is_yuv && (in_width & 1)) {
  2214. DSSERR("input width %d is not even for YUV format\n", in_width);
  2215. return -EINVAL;
  2216. }
  2217. out_width = out_width == 0 ? width : out_width;
  2218. out_height = out_height == 0 ? height : out_height;
  2219. if (plane != OMAP_DSS_WB) {
  2220. if (ilace && height == out_height)
  2221. fieldmode = true;
  2222. if (ilace) {
  2223. if (fieldmode)
  2224. in_height /= 2;
  2225. pos_y /= 2;
  2226. out_height /= 2;
  2227. DSSDBG("adjusting for ilace: height %d, pos_y %d, out_height %d\n",
  2228. in_height, pos_y, out_height);
  2229. }
  2230. }
  2231. if (!dispc_ovl_color_mode_supported(dispc, plane, fourcc))
  2232. return -EINVAL;
  2233. r = dispc_ovl_calc_scaling(dispc, plane, pclk, lclk, caps, vm, in_width,
  2234. in_height, out_width, out_height, fourcc,
  2235. &five_taps, &x_predecim, &y_predecim, pos_x,
  2236. rotation_type, mem_to_mem);
  2237. if (r)
  2238. return r;
  2239. in_width = in_width / x_predecim;
  2240. in_height = in_height / y_predecim;
  2241. if (x_predecim > 1 || y_predecim > 1)
  2242. DSSDBG("predecimation %d x %x, new input size %d x %d\n",
  2243. x_predecim, y_predecim, in_width, in_height);
  2244. if (info->is_yuv && (in_width & 1)) {
  2245. DSSDBG("predecimated input width is not even for YUV format\n");
  2246. DSSDBG("adjusting input width %d -> %d\n",
  2247. in_width, in_width & ~1);
  2248. in_width &= ~1;
  2249. }
  2250. if (info->is_yuv)
  2251. cconv = 1;
  2252. if (ilace && !fieldmode) {
  2253. /*
  2254. * when downscaling the bottom field may have to start several
  2255. * source lines below the top field. Unfortunately ACCUI
  2256. * registers will only hold the fractional part of the offset
  2257. * so the integer part must be added to the base address of the
  2258. * bottom field.
  2259. */
  2260. if (!in_height || in_height == out_height)
  2261. field_offset = 0;
  2262. else
  2263. field_offset = in_height / out_height / 2;
  2264. }
  2265. /* Fields are independent but interleaved in memory. */
  2266. if (fieldmode)
  2267. field_offset = 1;
  2268. offset0 = 0;
  2269. offset1 = 0;
  2270. row_inc = 0;
  2271. pix_inc = 0;
  2272. if (plane == OMAP_DSS_WB)
  2273. frame_width = out_width;
  2274. else
  2275. frame_width = in_width;
  2276. calc_offset(screen_width, frame_width,
  2277. fourcc, fieldmode, field_offset,
  2278. &offset0, &offset1, &row_inc, &pix_inc,
  2279. x_predecim, y_predecim,
  2280. rotation_type, rotation);
  2281. DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
  2282. offset0, offset1, row_inc, pix_inc);
  2283. dispc_ovl_set_color_mode(dispc, plane, fourcc);
  2284. dispc_ovl_configure_burst_type(dispc, plane, rotation_type);
  2285. if (dispc->feat->reverse_ilace_field_order)
  2286. swap(offset0, offset1);
  2287. dispc_ovl_set_ba0(dispc, plane, paddr + offset0);
  2288. dispc_ovl_set_ba1(dispc, plane, paddr + offset1);
  2289. if (fourcc == DRM_FORMAT_NV12) {
  2290. dispc_ovl_set_ba0_uv(dispc, plane, p_uv_addr + offset0);
  2291. dispc_ovl_set_ba1_uv(dispc, plane, p_uv_addr + offset1);
  2292. }
  2293. if (dispc->feat->last_pixel_inc_missing)
  2294. row_inc += pix_inc - 1;
  2295. dispc_ovl_set_row_inc(dispc, plane, row_inc);
  2296. dispc_ovl_set_pix_inc(dispc, plane, pix_inc);
  2297. DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
  2298. in_height, out_width, out_height);
  2299. dispc_ovl_set_pos(dispc, plane, caps, pos_x, pos_y);
  2300. dispc_ovl_set_input_size(dispc, plane, in_width, in_height);
  2301. if (caps & OMAP_DSS_OVL_CAP_SCALE) {
  2302. dispc_ovl_set_scaling(dispc, plane, in_width, in_height,
  2303. out_width, out_height, ilace, five_taps,
  2304. fieldmode, fourcc, rotation);
  2305. dispc_ovl_set_output_size(dispc, plane, out_width, out_height);
  2306. dispc_ovl_set_vid_color_conv(dispc, plane, cconv);
  2307. if (plane != OMAP_DSS_WB)
  2308. dispc_ovl_set_csc(dispc, plane, color_encoding, color_range);
  2309. }
  2310. dispc_ovl_set_rotation_attrs(dispc, plane, rotation, rotation_type,
  2311. fourcc);
  2312. dispc_ovl_set_zorder(dispc, plane, caps, zorder);
  2313. dispc_ovl_set_pre_mult_alpha(dispc, plane, caps, pre_mult_alpha);
  2314. dispc_ovl_setup_global_alpha(dispc, plane, caps, global_alpha);
  2315. dispc_ovl_enable_replication(dispc, plane, caps, replication);
  2316. return 0;
  2317. }
  2318. int dispc_ovl_setup(struct dispc_device *dispc,
  2319. enum omap_plane_id plane,
  2320. const struct omap_overlay_info *oi,
  2321. const struct videomode *vm, bool mem_to_mem,
  2322. enum omap_channel channel)
  2323. {
  2324. int r;
  2325. enum omap_overlay_caps caps = dispc->feat->overlay_caps[plane];
  2326. const bool replication = true;
  2327. DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
  2328. " %dx%d, cmode %x, rot %d, chan %d repl %d\n",
  2329. plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
  2330. oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
  2331. oi->fourcc, oi->rotation, channel, replication);
  2332. dispc_ovl_set_channel_out(dispc, plane, channel);
  2333. r = dispc_ovl_setup_common(dispc, plane, caps, oi->paddr, oi->p_uv_addr,
  2334. oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
  2335. oi->out_width, oi->out_height, oi->fourcc, oi->rotation,
  2336. oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
  2337. oi->rotation_type, replication, vm, mem_to_mem,
  2338. oi->color_encoding, oi->color_range);
  2339. return r;
  2340. }
  2341. int dispc_ovl_enable(struct dispc_device *dispc,
  2342. enum omap_plane_id plane, bool enable)
  2343. {
  2344. DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
  2345. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
  2346. return 0;
  2347. }
  2348. static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc,
  2349. bool act_high)
  2350. {
  2351. if (!dispc_has_feature(dispc, FEAT_LCDENABLEPOL))
  2352. return;
  2353. REG_FLD_MOD(dispc, DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
  2354. }
  2355. void dispc_lcd_enable_signal(struct dispc_device *dispc, bool enable)
  2356. {
  2357. if (!dispc_has_feature(dispc, FEAT_LCDENABLESIGNAL))
  2358. return;
  2359. REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 28, 28);
  2360. }
  2361. void dispc_pck_free_enable(struct dispc_device *dispc, bool enable)
  2362. {
  2363. if (!dispc_has_feature(dispc, FEAT_PCKFREEENABLE))
  2364. return;
  2365. REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 27, 27);
  2366. }
  2367. static void dispc_mgr_enable_fifohandcheck(struct dispc_device *dispc,
  2368. enum omap_channel channel,
  2369. bool enable)
  2370. {
  2371. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
  2372. }
  2373. static void dispc_mgr_set_lcd_type_tft(struct dispc_device *dispc,
  2374. enum omap_channel channel)
  2375. {
  2376. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STNTFT, 1);
  2377. }
  2378. static void dispc_set_loadmode(struct dispc_device *dispc,
  2379. enum omap_dss_load_mode mode)
  2380. {
  2381. REG_FLD_MOD(dispc, DISPC_CONFIG, mode, 2, 1);
  2382. }
  2383. static void dispc_mgr_set_default_color(struct dispc_device *dispc,
  2384. enum omap_channel channel, u32 color)
  2385. {
  2386. dispc_write_reg(dispc, DISPC_DEFAULT_COLOR(channel), color);
  2387. }
  2388. static void dispc_mgr_set_trans_key(struct dispc_device *dispc,
  2389. enum omap_channel ch,
  2390. enum omap_dss_trans_key_type type,
  2391. u32 trans_key)
  2392. {
  2393. mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKSELECTION, type);
  2394. dispc_write_reg(dispc, DISPC_TRANS_COLOR(ch), trans_key);
  2395. }
  2396. static void dispc_mgr_enable_trans_key(struct dispc_device *dispc,
  2397. enum omap_channel ch, bool enable)
  2398. {
  2399. mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKENABLE, enable);
  2400. }
  2401. static void dispc_mgr_enable_alpha_fixed_zorder(struct dispc_device *dispc,
  2402. enum omap_channel ch,
  2403. bool enable)
  2404. {
  2405. if (!dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER))
  2406. return;
  2407. if (ch == OMAP_DSS_CHANNEL_LCD)
  2408. REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 18, 18);
  2409. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  2410. REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 19, 19);
  2411. }
  2412. void dispc_mgr_setup(struct dispc_device *dispc,
  2413. enum omap_channel channel,
  2414. const struct omap_overlay_manager_info *info)
  2415. {
  2416. dispc_mgr_set_default_color(dispc, channel, info->default_color);
  2417. dispc_mgr_set_trans_key(dispc, channel, info->trans_key_type,
  2418. info->trans_key);
  2419. dispc_mgr_enable_trans_key(dispc, channel, info->trans_enabled);
  2420. dispc_mgr_enable_alpha_fixed_zorder(dispc, channel,
  2421. info->partial_alpha_enabled);
  2422. if (dispc_has_feature(dispc, FEAT_CPR)) {
  2423. dispc_mgr_enable_cpr(dispc, channel, info->cpr_enable);
  2424. dispc_mgr_set_cpr_coef(dispc, channel, &info->cpr_coefs);
  2425. }
  2426. }
  2427. static void dispc_mgr_set_tft_data_lines(struct dispc_device *dispc,
  2428. enum omap_channel channel,
  2429. u8 data_lines)
  2430. {
  2431. int code;
  2432. switch (data_lines) {
  2433. case 12:
  2434. code = 0;
  2435. break;
  2436. case 16:
  2437. code = 1;
  2438. break;
  2439. case 18:
  2440. code = 2;
  2441. break;
  2442. case 24:
  2443. code = 3;
  2444. break;
  2445. default:
  2446. BUG();
  2447. return;
  2448. }
  2449. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_TFTDATALINES, code);
  2450. }
  2451. static void dispc_mgr_set_io_pad_mode(struct dispc_device *dispc,
  2452. enum dss_io_pad_mode mode)
  2453. {
  2454. u32 l;
  2455. int gpout0, gpout1;
  2456. switch (mode) {
  2457. case DSS_IO_PAD_MODE_RESET:
  2458. gpout0 = 0;
  2459. gpout1 = 0;
  2460. break;
  2461. case DSS_IO_PAD_MODE_RFBI:
  2462. gpout0 = 1;
  2463. gpout1 = 0;
  2464. break;
  2465. case DSS_IO_PAD_MODE_BYPASS:
  2466. gpout0 = 1;
  2467. gpout1 = 1;
  2468. break;
  2469. default:
  2470. BUG();
  2471. return;
  2472. }
  2473. l = dispc_read_reg(dispc, DISPC_CONTROL);
  2474. l = FLD_MOD(l, gpout0, 15, 15);
  2475. l = FLD_MOD(l, gpout1, 16, 16);
  2476. dispc_write_reg(dispc, DISPC_CONTROL, l);
  2477. }
  2478. static void dispc_mgr_enable_stallmode(struct dispc_device *dispc,
  2479. enum omap_channel channel, bool enable)
  2480. {
  2481. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STALLMODE, enable);
  2482. }
  2483. void dispc_mgr_set_lcd_config(struct dispc_device *dispc,
  2484. enum omap_channel channel,
  2485. const struct dss_lcd_mgr_config *config)
  2486. {
  2487. dispc_mgr_set_io_pad_mode(dispc, config->io_pad_mode);
  2488. dispc_mgr_enable_stallmode(dispc, channel, config->stallmode);
  2489. dispc_mgr_enable_fifohandcheck(dispc, channel, config->fifohandcheck);
  2490. dispc_mgr_set_clock_div(dispc, channel, &config->clock_info);
  2491. dispc_mgr_set_tft_data_lines(dispc, channel, config->video_port_width);
  2492. dispc_lcd_enable_signal_polarity(dispc, config->lcden_sig_polarity);
  2493. dispc_mgr_set_lcd_type_tft(dispc, channel);
  2494. }
  2495. static bool _dispc_mgr_size_ok(struct dispc_device *dispc,
  2496. u16 width, u16 height)
  2497. {
  2498. return width <= dispc->feat->mgr_width_max &&
  2499. height <= dispc->feat->mgr_height_max;
  2500. }
  2501. static bool _dispc_lcd_timings_ok(struct dispc_device *dispc,
  2502. int hsync_len, int hfp, int hbp,
  2503. int vsw, int vfp, int vbp)
  2504. {
  2505. if (hsync_len < 1 || hsync_len > dispc->feat->sw_max ||
  2506. hfp < 1 || hfp > dispc->feat->hp_max ||
  2507. hbp < 1 || hbp > dispc->feat->hp_max ||
  2508. vsw < 1 || vsw > dispc->feat->sw_max ||
  2509. vfp < 0 || vfp > dispc->feat->vp_max ||
  2510. vbp < 0 || vbp > dispc->feat->vp_max)
  2511. return false;
  2512. return true;
  2513. }
  2514. static bool _dispc_mgr_pclk_ok(struct dispc_device *dispc,
  2515. enum omap_channel channel,
  2516. unsigned long pclk)
  2517. {
  2518. if (dss_mgr_is_lcd(channel))
  2519. return pclk <= dispc->feat->max_lcd_pclk;
  2520. else
  2521. return pclk <= dispc->feat->max_tv_pclk;
  2522. }
  2523. int dispc_mgr_check_timings(struct dispc_device *dispc,
  2524. enum omap_channel channel,
  2525. const struct videomode *vm)
  2526. {
  2527. if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive))
  2528. return MODE_BAD;
  2529. if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock))
  2530. return MODE_BAD;
  2531. if (dss_mgr_is_lcd(channel)) {
  2532. /* TODO: OMAP4+ supports interlace for LCD outputs */
  2533. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2534. return MODE_BAD;
  2535. if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len,
  2536. vm->hfront_porch, vm->hback_porch,
  2537. vm->vsync_len, vm->vfront_porch,
  2538. vm->vback_porch))
  2539. return MODE_BAD;
  2540. }
  2541. return MODE_OK;
  2542. }
  2543. static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc,
  2544. enum omap_channel channel,
  2545. const struct videomode *vm)
  2546. {
  2547. u32 timing_h, timing_v, l;
  2548. bool onoff, rf, ipc, vs, hs, de;
  2549. timing_h = FLD_VAL(vm->hsync_len - 1, dispc->feat->sw_start, 0) |
  2550. FLD_VAL(vm->hfront_porch - 1, dispc->feat->fp_start, 8) |
  2551. FLD_VAL(vm->hback_porch - 1, dispc->feat->bp_start, 20);
  2552. timing_v = FLD_VAL(vm->vsync_len - 1, dispc->feat->sw_start, 0) |
  2553. FLD_VAL(vm->vfront_porch, dispc->feat->fp_start, 8) |
  2554. FLD_VAL(vm->vback_porch, dispc->feat->bp_start, 20);
  2555. dispc_write_reg(dispc, DISPC_TIMING_H(channel), timing_h);
  2556. dispc_write_reg(dispc, DISPC_TIMING_V(channel), timing_v);
  2557. vs = !!(vm->flags & DISPLAY_FLAGS_VSYNC_LOW);
  2558. hs = !!(vm->flags & DISPLAY_FLAGS_HSYNC_LOW);
  2559. de = !!(vm->flags & DISPLAY_FLAGS_DE_LOW);
  2560. ipc = !!(vm->flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE);
  2561. onoff = true; /* always use the 'rf' setting */
  2562. rf = !!(vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE);
  2563. l = FLD_VAL(onoff, 17, 17) |
  2564. FLD_VAL(rf, 16, 16) |
  2565. FLD_VAL(de, 15, 15) |
  2566. FLD_VAL(ipc, 14, 14) |
  2567. FLD_VAL(hs, 13, 13) |
  2568. FLD_VAL(vs, 12, 12);
  2569. /* always set ALIGN bit when available */
  2570. if (dispc->feat->supports_sync_align)
  2571. l |= (1 << 18);
  2572. dispc_write_reg(dispc, DISPC_POL_FREQ(channel), l);
  2573. if (dispc->syscon_pol) {
  2574. const int shifts[] = {
  2575. [OMAP_DSS_CHANNEL_LCD] = 0,
  2576. [OMAP_DSS_CHANNEL_LCD2] = 1,
  2577. [OMAP_DSS_CHANNEL_LCD3] = 2,
  2578. };
  2579. u32 mask, val;
  2580. mask = (1 << 0) | (1 << 3) | (1 << 6);
  2581. val = (rf << 0) | (ipc << 3) | (onoff << 6);
  2582. mask <<= 16 + shifts[channel];
  2583. val <<= 16 + shifts[channel];
  2584. regmap_update_bits(dispc->syscon_pol, dispc->syscon_pol_offset,
  2585. mask, val);
  2586. }
  2587. }
  2588. static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
  2589. enum display_flags low)
  2590. {
  2591. if (flags & high)
  2592. return 1;
  2593. if (flags & low)
  2594. return -1;
  2595. return 0;
  2596. }
  2597. /* change name to mode? */
  2598. void dispc_mgr_set_timings(struct dispc_device *dispc,
  2599. enum omap_channel channel,
  2600. const struct videomode *vm)
  2601. {
  2602. unsigned int xtot, ytot;
  2603. unsigned long ht, vt;
  2604. struct videomode t = *vm;
  2605. DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
  2606. if (dispc_mgr_check_timings(dispc, channel, &t)) {
  2607. BUG();
  2608. return;
  2609. }
  2610. if (dss_mgr_is_lcd(channel)) {
  2611. _dispc_mgr_set_lcd_timings(dispc, channel, &t);
  2612. xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
  2613. ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
  2614. ht = vm->pixelclock / xtot;
  2615. vt = vm->pixelclock / xtot / ytot;
  2616. DSSDBG("pck %lu\n", vm->pixelclock);
  2617. DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
  2618. t.hsync_len, t.hfront_porch, t.hback_porch,
  2619. t.vsync_len, t.vfront_porch, t.vback_porch);
  2620. DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
  2621. vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
  2622. vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
  2623. vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
  2624. vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
  2625. vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
  2626. DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
  2627. } else {
  2628. if (t.flags & DISPLAY_FLAGS_INTERLACED)
  2629. t.vactive /= 2;
  2630. if (dispc->feat->supports_double_pixel)
  2631. REG_FLD_MOD(dispc, DISPC_CONTROL,
  2632. !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
  2633. 19, 17);
  2634. }
  2635. dispc_mgr_set_size(dispc, channel, t.hactive, t.vactive);
  2636. }
  2637. static void dispc_mgr_set_lcd_divisor(struct dispc_device *dispc,
  2638. enum omap_channel channel, u16 lck_div,
  2639. u16 pck_div)
  2640. {
  2641. BUG_ON(lck_div < 1);
  2642. BUG_ON(pck_div < 1);
  2643. dispc_write_reg(dispc, DISPC_DIVISORo(channel),
  2644. FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
  2645. if (!dispc_has_feature(dispc, FEAT_CORE_CLK_DIV) &&
  2646. channel == OMAP_DSS_CHANNEL_LCD)
  2647. dispc->core_clk_rate = dispc_fclk_rate(dispc) / lck_div;
  2648. }
  2649. static void dispc_mgr_get_lcd_divisor(struct dispc_device *dispc,
  2650. enum omap_channel channel, int *lck_div,
  2651. int *pck_div)
  2652. {
  2653. u32 l;
  2654. l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
  2655. *lck_div = FLD_GET(l, 23, 16);
  2656. *pck_div = FLD_GET(l, 7, 0);
  2657. }
  2658. static unsigned long dispc_fclk_rate(struct dispc_device *dispc)
  2659. {
  2660. unsigned long r;
  2661. enum dss_clk_source src;
  2662. src = dss_get_dispc_clk_source(dispc->dss);
  2663. if (src == DSS_CLK_SRC_FCK) {
  2664. r = dss_get_dispc_clk_rate(dispc->dss);
  2665. } else {
  2666. struct dss_pll *pll;
  2667. unsigned int clkout_idx;
  2668. pll = dss_pll_find_by_src(dispc->dss, src);
  2669. clkout_idx = dss_pll_get_clkout_idx_for_src(src);
  2670. r = pll->cinfo.clkout[clkout_idx];
  2671. }
  2672. return r;
  2673. }
  2674. static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
  2675. enum omap_channel channel)
  2676. {
  2677. int lcd;
  2678. unsigned long r;
  2679. enum dss_clk_source src;
  2680. /* for TV, LCLK rate is the FCLK rate */
  2681. if (!dss_mgr_is_lcd(channel))
  2682. return dispc_fclk_rate(dispc);
  2683. src = dss_get_lcd_clk_source(dispc->dss, channel);
  2684. if (src == DSS_CLK_SRC_FCK) {
  2685. r = dss_get_dispc_clk_rate(dispc->dss);
  2686. } else {
  2687. struct dss_pll *pll;
  2688. unsigned int clkout_idx;
  2689. pll = dss_pll_find_by_src(dispc->dss, src);
  2690. clkout_idx = dss_pll_get_clkout_idx_for_src(src);
  2691. r = pll->cinfo.clkout[clkout_idx];
  2692. }
  2693. lcd = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
  2694. return r / lcd;
  2695. }
  2696. static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
  2697. enum omap_channel channel)
  2698. {
  2699. unsigned long r;
  2700. if (dss_mgr_is_lcd(channel)) {
  2701. int pcd;
  2702. u32 l;
  2703. l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
  2704. pcd = FLD_GET(l, 7, 0);
  2705. r = dispc_mgr_lclk_rate(dispc, channel);
  2706. return r / pcd;
  2707. } else {
  2708. return dispc->tv_pclk_rate;
  2709. }
  2710. }
  2711. void dispc_set_tv_pclk(struct dispc_device *dispc, unsigned long pclk)
  2712. {
  2713. dispc->tv_pclk_rate = pclk;
  2714. }
  2715. static unsigned long dispc_core_clk_rate(struct dispc_device *dispc)
  2716. {
  2717. return dispc->core_clk_rate;
  2718. }
  2719. static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
  2720. enum omap_plane_id plane)
  2721. {
  2722. enum omap_channel channel;
  2723. if (plane == OMAP_DSS_WB)
  2724. return 0;
  2725. channel = dispc_ovl_get_channel_out(dispc, plane);
  2726. return dispc_mgr_pclk_rate(dispc, channel);
  2727. }
  2728. static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
  2729. enum omap_plane_id plane)
  2730. {
  2731. enum omap_channel channel;
  2732. if (plane == OMAP_DSS_WB)
  2733. return 0;
  2734. channel = dispc_ovl_get_channel_out(dispc, plane);
  2735. return dispc_mgr_lclk_rate(dispc, channel);
  2736. }
  2737. static void dispc_dump_clocks_channel(struct dispc_device *dispc,
  2738. struct seq_file *s,
  2739. enum omap_channel channel)
  2740. {
  2741. int lcd, pcd;
  2742. enum dss_clk_source lcd_clk_src;
  2743. seq_printf(s, "- %s -\n", mgr_desc[channel].name);
  2744. lcd_clk_src = dss_get_lcd_clk_source(dispc->dss, channel);
  2745. seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
  2746. dss_get_clk_source_name(lcd_clk_src));
  2747. dispc_mgr_get_lcd_divisor(dispc, channel, &lcd, &pcd);
  2748. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2749. dispc_mgr_lclk_rate(dispc, channel), lcd);
  2750. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2751. dispc_mgr_pclk_rate(dispc, channel), pcd);
  2752. }
  2753. void dispc_dump_clocks(struct dispc_device *dispc, struct seq_file *s)
  2754. {
  2755. enum dss_clk_source dispc_clk_src;
  2756. int lcd;
  2757. u32 l;
  2758. if (dispc_runtime_get(dispc))
  2759. return;
  2760. seq_printf(s, "- DISPC -\n");
  2761. dispc_clk_src = dss_get_dispc_clk_source(dispc->dss);
  2762. seq_printf(s, "dispc fclk source = %s\n",
  2763. dss_get_clk_source_name(dispc_clk_src));
  2764. seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate(dispc));
  2765. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
  2766. seq_printf(s, "- DISPC-CORE-CLK -\n");
  2767. l = dispc_read_reg(dispc, DISPC_DIVISOR);
  2768. lcd = FLD_GET(l, 23, 16);
  2769. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2770. (dispc_fclk_rate(dispc)/lcd), lcd);
  2771. }
  2772. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD);
  2773. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  2774. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD2);
  2775. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  2776. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD3);
  2777. dispc_runtime_put(dispc);
  2778. }
  2779. static int dispc_dump_regs(struct seq_file *s, void *p)
  2780. {
  2781. struct dispc_device *dispc = s->private;
  2782. int i, j;
  2783. const char *mgr_names[] = {
  2784. [OMAP_DSS_CHANNEL_LCD] = "LCD",
  2785. [OMAP_DSS_CHANNEL_DIGIT] = "TV",
  2786. [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
  2787. [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
  2788. };
  2789. const char *ovl_names[] = {
  2790. [OMAP_DSS_GFX] = "GFX",
  2791. [OMAP_DSS_VIDEO1] = "VID1",
  2792. [OMAP_DSS_VIDEO2] = "VID2",
  2793. [OMAP_DSS_VIDEO3] = "VID3",
  2794. [OMAP_DSS_WB] = "WB",
  2795. };
  2796. const char **p_names;
  2797. #define DUMPREG(dispc, r) \
  2798. seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(dispc, r))
  2799. if (dispc_runtime_get(dispc))
  2800. return 0;
  2801. /* DISPC common registers */
  2802. DUMPREG(dispc, DISPC_REVISION);
  2803. DUMPREG(dispc, DISPC_SYSCONFIG);
  2804. DUMPREG(dispc, DISPC_SYSSTATUS);
  2805. DUMPREG(dispc, DISPC_IRQSTATUS);
  2806. DUMPREG(dispc, DISPC_IRQENABLE);
  2807. DUMPREG(dispc, DISPC_CONTROL);
  2808. DUMPREG(dispc, DISPC_CONFIG);
  2809. DUMPREG(dispc, DISPC_CAPABLE);
  2810. DUMPREG(dispc, DISPC_LINE_STATUS);
  2811. DUMPREG(dispc, DISPC_LINE_NUMBER);
  2812. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  2813. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  2814. DUMPREG(dispc, DISPC_GLOBAL_ALPHA);
  2815. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  2816. DUMPREG(dispc, DISPC_CONTROL2);
  2817. DUMPREG(dispc, DISPC_CONFIG2);
  2818. }
  2819. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  2820. DUMPREG(dispc, DISPC_CONTROL3);
  2821. DUMPREG(dispc, DISPC_CONFIG3);
  2822. }
  2823. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2824. DUMPREG(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE);
  2825. #undef DUMPREG
  2826. #define DISPC_REG(i, name) name(i)
  2827. #define DUMPREG(dispc, i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
  2828. (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
  2829. dispc_read_reg(dispc, DISPC_REG(i, r)))
  2830. p_names = mgr_names;
  2831. /* DISPC channel specific registers */
  2832. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  2833. DUMPREG(dispc, i, DISPC_DEFAULT_COLOR);
  2834. DUMPREG(dispc, i, DISPC_TRANS_COLOR);
  2835. DUMPREG(dispc, i, DISPC_SIZE_MGR);
  2836. if (i == OMAP_DSS_CHANNEL_DIGIT)
  2837. continue;
  2838. DUMPREG(dispc, i, DISPC_TIMING_H);
  2839. DUMPREG(dispc, i, DISPC_TIMING_V);
  2840. DUMPREG(dispc, i, DISPC_POL_FREQ);
  2841. DUMPREG(dispc, i, DISPC_DIVISORo);
  2842. DUMPREG(dispc, i, DISPC_DATA_CYCLE1);
  2843. DUMPREG(dispc, i, DISPC_DATA_CYCLE2);
  2844. DUMPREG(dispc, i, DISPC_DATA_CYCLE3);
  2845. if (dispc_has_feature(dispc, FEAT_CPR)) {
  2846. DUMPREG(dispc, i, DISPC_CPR_COEF_R);
  2847. DUMPREG(dispc, i, DISPC_CPR_COEF_G);
  2848. DUMPREG(dispc, i, DISPC_CPR_COEF_B);
  2849. }
  2850. }
  2851. p_names = ovl_names;
  2852. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  2853. DUMPREG(dispc, i, DISPC_OVL_BA0);
  2854. DUMPREG(dispc, i, DISPC_OVL_BA1);
  2855. DUMPREG(dispc, i, DISPC_OVL_POSITION);
  2856. DUMPREG(dispc, i, DISPC_OVL_SIZE);
  2857. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
  2858. DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
  2859. DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
  2860. DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
  2861. DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
  2862. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  2863. DUMPREG(dispc, i, DISPC_OVL_PRELOAD);
  2864. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2865. DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
  2866. if (i == OMAP_DSS_GFX) {
  2867. DUMPREG(dispc, i, DISPC_OVL_WINDOW_SKIP);
  2868. DUMPREG(dispc, i, DISPC_OVL_TABLE_BA);
  2869. continue;
  2870. }
  2871. DUMPREG(dispc, i, DISPC_OVL_FIR);
  2872. DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
  2873. DUMPREG(dispc, i, DISPC_OVL_ACCU0);
  2874. DUMPREG(dispc, i, DISPC_OVL_ACCU1);
  2875. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  2876. DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
  2877. DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
  2878. DUMPREG(dispc, i, DISPC_OVL_FIR2);
  2879. DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
  2880. DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
  2881. }
  2882. if (dispc_has_feature(dispc, FEAT_ATTR2))
  2883. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
  2884. }
  2885. if (dispc->feat->has_writeback) {
  2886. i = OMAP_DSS_WB;
  2887. DUMPREG(dispc, i, DISPC_OVL_BA0);
  2888. DUMPREG(dispc, i, DISPC_OVL_BA1);
  2889. DUMPREG(dispc, i, DISPC_OVL_SIZE);
  2890. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
  2891. DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
  2892. DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
  2893. DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
  2894. DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
  2895. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2896. DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
  2897. DUMPREG(dispc, i, DISPC_OVL_FIR);
  2898. DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
  2899. DUMPREG(dispc, i, DISPC_OVL_ACCU0);
  2900. DUMPREG(dispc, i, DISPC_OVL_ACCU1);
  2901. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  2902. DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
  2903. DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
  2904. DUMPREG(dispc, i, DISPC_OVL_FIR2);
  2905. DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
  2906. DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
  2907. }
  2908. if (dispc_has_feature(dispc, FEAT_ATTR2))
  2909. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
  2910. }
  2911. #undef DISPC_REG
  2912. #undef DUMPREG
  2913. #define DISPC_REG(plane, name, i) name(plane, i)
  2914. #define DUMPREG(dispc, plane, name, i) \
  2915. seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
  2916. (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
  2917. dispc_read_reg(dispc, DISPC_REG(plane, name, i)))
  2918. /* Video pipeline coefficient registers */
  2919. /* start from OMAP_DSS_VIDEO1 */
  2920. for (i = 1; i < dispc_get_num_ovls(dispc); i++) {
  2921. for (j = 0; j < 8; j++)
  2922. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H, j);
  2923. for (j = 0; j < 8; j++)
  2924. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV, j);
  2925. for (j = 0; j < 5; j++)
  2926. DUMPREG(dispc, i, DISPC_OVL_CONV_COEF, j);
  2927. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  2928. for (j = 0; j < 8; j++)
  2929. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V, j);
  2930. }
  2931. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  2932. for (j = 0; j < 8; j++)
  2933. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H2, j);
  2934. for (j = 0; j < 8; j++)
  2935. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV2, j);
  2936. for (j = 0; j < 8; j++)
  2937. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V2, j);
  2938. }
  2939. }
  2940. dispc_runtime_put(dispc);
  2941. #undef DISPC_REG
  2942. #undef DUMPREG
  2943. return 0;
  2944. }
  2945. /* calculate clock rates using dividers in cinfo */
  2946. int dispc_calc_clock_rates(struct dispc_device *dispc,
  2947. unsigned long dispc_fclk_rate,
  2948. struct dispc_clock_info *cinfo)
  2949. {
  2950. if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
  2951. return -EINVAL;
  2952. if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
  2953. return -EINVAL;
  2954. cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
  2955. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2956. return 0;
  2957. }
  2958. bool dispc_div_calc(struct dispc_device *dispc, unsigned long dispc_freq,
  2959. unsigned long pck_min, unsigned long pck_max,
  2960. dispc_div_calc_func func, void *data)
  2961. {
  2962. int lckd, lckd_start, lckd_stop;
  2963. int pckd, pckd_start, pckd_stop;
  2964. unsigned long pck, lck;
  2965. unsigned long lck_max;
  2966. unsigned long pckd_hw_min, pckd_hw_max;
  2967. unsigned int min_fck_per_pck;
  2968. unsigned long fck;
  2969. #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
  2970. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  2971. #else
  2972. min_fck_per_pck = 0;
  2973. #endif
  2974. pckd_hw_min = dispc->feat->min_pcd;
  2975. pckd_hw_max = 255;
  2976. lck_max = dss_get_max_fck_rate(dispc->dss);
  2977. pck_min = pck_min ? pck_min : 1;
  2978. pck_max = pck_max ? pck_max : ULONG_MAX;
  2979. lckd_start = max(DIV_ROUND_UP(dispc_freq, lck_max), 1ul);
  2980. lckd_stop = min(dispc_freq / pck_min, 255ul);
  2981. for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
  2982. lck = dispc_freq / lckd;
  2983. pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
  2984. pckd_stop = min(lck / pck_min, pckd_hw_max);
  2985. for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
  2986. pck = lck / pckd;
  2987. /*
  2988. * For OMAP2/3 the DISPC fclk is the same as LCD's logic
  2989. * clock, which means we're configuring DISPC fclk here
  2990. * also. Thus we need to use the calculated lck. For
  2991. * OMAP4+ the DISPC fclk is a separate clock.
  2992. */
  2993. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  2994. fck = dispc_core_clk_rate(dispc);
  2995. else
  2996. fck = lck;
  2997. if (fck < pck * min_fck_per_pck)
  2998. continue;
  2999. if (func(lckd, pckd, lck, pck, data))
  3000. return true;
  3001. }
  3002. }
  3003. return false;
  3004. }
  3005. void dispc_mgr_set_clock_div(struct dispc_device *dispc,
  3006. enum omap_channel channel,
  3007. const struct dispc_clock_info *cinfo)
  3008. {
  3009. DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
  3010. DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
  3011. dispc_mgr_set_lcd_divisor(dispc, channel, cinfo->lck_div,
  3012. cinfo->pck_div);
  3013. }
  3014. u32 dispc_read_irqstatus(struct dispc_device *dispc)
  3015. {
  3016. return dispc_read_reg(dispc, DISPC_IRQSTATUS);
  3017. }
  3018. void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask)
  3019. {
  3020. dispc_write_reg(dispc, DISPC_IRQSTATUS, mask);
  3021. }
  3022. void dispc_write_irqenable(struct dispc_device *dispc, u32 mask)
  3023. {
  3024. u32 old_mask = dispc_read_reg(dispc, DISPC_IRQENABLE);
  3025. /* clear the irqstatus for newly enabled irqs */
  3026. dispc_clear_irqstatus(dispc, (mask ^ old_mask) & mask);
  3027. dispc_write_reg(dispc, DISPC_IRQENABLE, mask);
  3028. /* flush posted write */
  3029. dispc_read_reg(dispc, DISPC_IRQENABLE);
  3030. }
  3031. void dispc_enable_sidle(struct dispc_device *dispc)
  3032. {
  3033. /* SIDLEMODE: smart idle */
  3034. REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 2, 4, 3);
  3035. }
  3036. void dispc_disable_sidle(struct dispc_device *dispc)
  3037. {
  3038. REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
  3039. }
  3040. u32 dispc_mgr_gamma_size(struct dispc_device *dispc,
  3041. enum omap_channel channel)
  3042. {
  3043. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3044. if (!dispc->feat->has_gamma_table)
  3045. return 0;
  3046. return gdesc->len;
  3047. }
  3048. static void dispc_mgr_write_gamma_table(struct dispc_device *dispc,
  3049. enum omap_channel channel)
  3050. {
  3051. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3052. u32 *table = dispc->gamma_table[channel];
  3053. unsigned int i;
  3054. DSSDBG("%s: channel %d\n", __func__, channel);
  3055. for (i = 0; i < gdesc->len; ++i) {
  3056. u32 v = table[i];
  3057. if (gdesc->has_index)
  3058. v |= i << 24;
  3059. else if (i == 0)
  3060. v |= 1 << 31;
  3061. dispc_write_reg(dispc, gdesc->reg, v);
  3062. }
  3063. }
  3064. static void dispc_restore_gamma_tables(struct dispc_device *dispc)
  3065. {
  3066. DSSDBG("%s()\n", __func__);
  3067. if (!dispc->feat->has_gamma_table)
  3068. return;
  3069. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD);
  3070. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_DIGIT);
  3071. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  3072. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD2);
  3073. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  3074. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD3);
  3075. }
  3076. static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
  3077. { .red = 0, .green = 0, .blue = 0, },
  3078. { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
  3079. };
  3080. void dispc_mgr_set_gamma(struct dispc_device *dispc,
  3081. enum omap_channel channel,
  3082. const struct drm_color_lut *lut,
  3083. unsigned int length)
  3084. {
  3085. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3086. u32 *table = dispc->gamma_table[channel];
  3087. uint i;
  3088. DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
  3089. channel, length, gdesc->len);
  3090. if (!dispc->feat->has_gamma_table)
  3091. return;
  3092. if (lut == NULL || length < 2) {
  3093. lut = dispc_mgr_gamma_default_lut;
  3094. length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
  3095. }
  3096. for (i = 0; i < length - 1; ++i) {
  3097. uint first = i * (gdesc->len - 1) / (length - 1);
  3098. uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
  3099. uint w = last - first;
  3100. u16 r, g, b;
  3101. uint j;
  3102. if (w == 0)
  3103. continue;
  3104. for (j = 0; j <= w; j++) {
  3105. r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
  3106. g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
  3107. b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
  3108. r >>= 16 - gdesc->bits;
  3109. g >>= 16 - gdesc->bits;
  3110. b >>= 16 - gdesc->bits;
  3111. table[first + j] = (r << (gdesc->bits * 2)) |
  3112. (g << gdesc->bits) | b;
  3113. }
  3114. }
  3115. if (dispc->is_enabled)
  3116. dispc_mgr_write_gamma_table(dispc, channel);
  3117. }
  3118. static int dispc_init_gamma_tables(struct dispc_device *dispc)
  3119. {
  3120. int channel;
  3121. if (!dispc->feat->has_gamma_table)
  3122. return 0;
  3123. for (channel = 0; channel < ARRAY_SIZE(dispc->gamma_table); channel++) {
  3124. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3125. u32 *gt;
  3126. if (channel == OMAP_DSS_CHANNEL_LCD2 &&
  3127. !dispc_has_feature(dispc, FEAT_MGR_LCD2))
  3128. continue;
  3129. if (channel == OMAP_DSS_CHANNEL_LCD3 &&
  3130. !dispc_has_feature(dispc, FEAT_MGR_LCD3))
  3131. continue;
  3132. gt = devm_kmalloc_array(&dispc->pdev->dev, gdesc->len,
  3133. sizeof(u32), GFP_KERNEL);
  3134. if (!gt)
  3135. return -ENOMEM;
  3136. dispc->gamma_table[channel] = gt;
  3137. dispc_mgr_set_gamma(dispc, channel, NULL, 0);
  3138. }
  3139. return 0;
  3140. }
  3141. static void _omap_dispc_initial_config(struct dispc_device *dispc)
  3142. {
  3143. u32 l;
  3144. /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
  3145. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
  3146. l = dispc_read_reg(dispc, DISPC_DIVISOR);
  3147. /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
  3148. l = FLD_MOD(l, 1, 0, 0);
  3149. l = FLD_MOD(l, 1, 23, 16);
  3150. dispc_write_reg(dispc, DISPC_DIVISOR, l);
  3151. dispc->core_clk_rate = dispc_fclk_rate(dispc);
  3152. }
  3153. /* Use gamma table mode, instead of palette mode */
  3154. if (dispc->feat->has_gamma_table)
  3155. REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 3, 3);
  3156. /* For older DSS versions (FEAT_FUNCGATED) this enables
  3157. * func-clock auto-gating. For newer versions
  3158. * (dispc->feat->has_gamma_table) this enables tv-out gamma tables.
  3159. */
  3160. if (dispc_has_feature(dispc, FEAT_FUNCGATED) ||
  3161. dispc->feat->has_gamma_table)
  3162. REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 9, 9);
  3163. dispc_set_loadmode(dispc, OMAP_DSS_LOAD_FRAME_ONLY);
  3164. dispc_init_fifos(dispc);
  3165. dispc_configure_burst_sizes(dispc);
  3166. dispc_ovl_enable_zorder_planes(dispc);
  3167. if (dispc->feat->mstandby_workaround)
  3168. REG_FLD_MOD(dispc, DISPC_MSTANDBY_CTRL, 1, 0, 0);
  3169. if (dispc_has_feature(dispc, FEAT_MFLAG))
  3170. dispc_init_mflag(dispc);
  3171. }
  3172. static const enum dispc_feature_id omap2_dispc_features_list[] = {
  3173. FEAT_LCDENABLEPOL,
  3174. FEAT_LCDENABLESIGNAL,
  3175. FEAT_PCKFREEENABLE,
  3176. FEAT_FUNCGATED,
  3177. FEAT_ROWREPEATENABLE,
  3178. FEAT_RESIZECONF,
  3179. };
  3180. static const enum dispc_feature_id omap3_dispc_features_list[] = {
  3181. FEAT_LCDENABLEPOL,
  3182. FEAT_LCDENABLESIGNAL,
  3183. FEAT_PCKFREEENABLE,
  3184. FEAT_FUNCGATED,
  3185. FEAT_LINEBUFFERSPLIT,
  3186. FEAT_ROWREPEATENABLE,
  3187. FEAT_RESIZECONF,
  3188. FEAT_CPR,
  3189. FEAT_PRELOAD,
  3190. FEAT_FIR_COEF_V,
  3191. FEAT_ALPHA_FIXED_ZORDER,
  3192. FEAT_FIFO_MERGE,
  3193. FEAT_OMAP3_DSI_FIFO_BUG,
  3194. };
  3195. static const enum dispc_feature_id am43xx_dispc_features_list[] = {
  3196. FEAT_LCDENABLEPOL,
  3197. FEAT_LCDENABLESIGNAL,
  3198. FEAT_PCKFREEENABLE,
  3199. FEAT_FUNCGATED,
  3200. FEAT_LINEBUFFERSPLIT,
  3201. FEAT_ROWREPEATENABLE,
  3202. FEAT_RESIZECONF,
  3203. FEAT_CPR,
  3204. FEAT_PRELOAD,
  3205. FEAT_FIR_COEF_V,
  3206. FEAT_ALPHA_FIXED_ZORDER,
  3207. FEAT_FIFO_MERGE,
  3208. };
  3209. static const enum dispc_feature_id omap4_dispc_features_list[] = {
  3210. FEAT_MGR_LCD2,
  3211. FEAT_CORE_CLK_DIV,
  3212. FEAT_HANDLE_UV_SEPARATE,
  3213. FEAT_ATTR2,
  3214. FEAT_CPR,
  3215. FEAT_PRELOAD,
  3216. FEAT_FIR_COEF_V,
  3217. FEAT_ALPHA_FREE_ZORDER,
  3218. FEAT_FIFO_MERGE,
  3219. FEAT_BURST_2D,
  3220. };
  3221. static const enum dispc_feature_id omap5_dispc_features_list[] = {
  3222. FEAT_MGR_LCD2,
  3223. FEAT_MGR_LCD3,
  3224. FEAT_CORE_CLK_DIV,
  3225. FEAT_HANDLE_UV_SEPARATE,
  3226. FEAT_ATTR2,
  3227. FEAT_CPR,
  3228. FEAT_PRELOAD,
  3229. FEAT_FIR_COEF_V,
  3230. FEAT_ALPHA_FREE_ZORDER,
  3231. FEAT_FIFO_MERGE,
  3232. FEAT_BURST_2D,
  3233. FEAT_MFLAG,
  3234. };
  3235. static const struct dss_reg_field omap2_dispc_reg_fields[] = {
  3236. [FEAT_REG_FIRHINC] = { 11, 0 },
  3237. [FEAT_REG_FIRVINC] = { 27, 16 },
  3238. [FEAT_REG_FIFOLOWTHRESHOLD] = { 8, 0 },
  3239. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 24, 16 },
  3240. [FEAT_REG_FIFOSIZE] = { 8, 0 },
  3241. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  3242. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  3243. };
  3244. static const struct dss_reg_field omap3_dispc_reg_fields[] = {
  3245. [FEAT_REG_FIRHINC] = { 12, 0 },
  3246. [FEAT_REG_FIRVINC] = { 28, 16 },
  3247. [FEAT_REG_FIFOLOWTHRESHOLD] = { 11, 0 },
  3248. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 27, 16 },
  3249. [FEAT_REG_FIFOSIZE] = { 10, 0 },
  3250. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  3251. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  3252. };
  3253. static const struct dss_reg_field omap4_dispc_reg_fields[] = {
  3254. [FEAT_REG_FIRHINC] = { 12, 0 },
  3255. [FEAT_REG_FIRVINC] = { 28, 16 },
  3256. [FEAT_REG_FIFOLOWTHRESHOLD] = { 15, 0 },
  3257. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 31, 16 },
  3258. [FEAT_REG_FIFOSIZE] = { 15, 0 },
  3259. [FEAT_REG_HORIZONTALACCU] = { 10, 0 },
  3260. [FEAT_REG_VERTICALACCU] = { 26, 16 },
  3261. };
  3262. static const enum omap_overlay_caps omap2_dispc_overlay_caps[] = {
  3263. /* OMAP_DSS_GFX */
  3264. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3265. /* OMAP_DSS_VIDEO1 */
  3266. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3267. OMAP_DSS_OVL_CAP_REPLICATION,
  3268. /* OMAP_DSS_VIDEO2 */
  3269. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3270. OMAP_DSS_OVL_CAP_REPLICATION,
  3271. };
  3272. static const enum omap_overlay_caps omap3430_dispc_overlay_caps[] = {
  3273. /* OMAP_DSS_GFX */
  3274. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_POS |
  3275. OMAP_DSS_OVL_CAP_REPLICATION,
  3276. /* OMAP_DSS_VIDEO1 */
  3277. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3278. OMAP_DSS_OVL_CAP_REPLICATION,
  3279. /* OMAP_DSS_VIDEO2 */
  3280. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3281. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3282. };
  3283. static const enum omap_overlay_caps omap3630_dispc_overlay_caps[] = {
  3284. /* OMAP_DSS_GFX */
  3285. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
  3286. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3287. /* OMAP_DSS_VIDEO1 */
  3288. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3289. OMAP_DSS_OVL_CAP_REPLICATION,
  3290. /* OMAP_DSS_VIDEO2 */
  3291. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3292. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_POS |
  3293. OMAP_DSS_OVL_CAP_REPLICATION,
  3294. };
  3295. static const enum omap_overlay_caps omap4_dispc_overlay_caps[] = {
  3296. /* OMAP_DSS_GFX */
  3297. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
  3298. OMAP_DSS_OVL_CAP_ZORDER | OMAP_DSS_OVL_CAP_POS |
  3299. OMAP_DSS_OVL_CAP_REPLICATION,
  3300. /* OMAP_DSS_VIDEO1 */
  3301. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3302. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3303. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3304. /* OMAP_DSS_VIDEO2 */
  3305. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3306. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3307. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3308. /* OMAP_DSS_VIDEO3 */
  3309. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3310. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3311. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3312. };
  3313. #define COLOR_ARRAY(arr...) (const u32[]) { arr, 0 }
  3314. static const u32 *omap2_dispc_supported_color_modes[] = {
  3315. /* OMAP_DSS_GFX */
  3316. COLOR_ARRAY(
  3317. DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
  3318. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888),
  3319. /* OMAP_DSS_VIDEO1 */
  3320. COLOR_ARRAY(
  3321. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3322. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3323. DRM_FORMAT_UYVY),
  3324. /* OMAP_DSS_VIDEO2 */
  3325. COLOR_ARRAY(
  3326. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3327. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3328. DRM_FORMAT_UYVY),
  3329. };
  3330. static const u32 *omap3_dispc_supported_color_modes[] = {
  3331. /* OMAP_DSS_GFX */
  3332. COLOR_ARRAY(
  3333. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3334. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3335. DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
  3336. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
  3337. /* OMAP_DSS_VIDEO1 */
  3338. COLOR_ARRAY(
  3339. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888,
  3340. DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
  3341. DRM_FORMAT_YUYV, DRM_FORMAT_UYVY),
  3342. /* OMAP_DSS_VIDEO2 */
  3343. COLOR_ARRAY(
  3344. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3345. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3346. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3347. DRM_FORMAT_UYVY, DRM_FORMAT_ARGB8888,
  3348. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
  3349. };
  3350. static const u32 *omap4_dispc_supported_color_modes[] = {
  3351. /* OMAP_DSS_GFX */
  3352. COLOR_ARRAY(
  3353. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3354. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3355. DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
  3356. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888,
  3357. DRM_FORMAT_ARGB1555, DRM_FORMAT_XRGB4444,
  3358. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB1555),
  3359. /* OMAP_DSS_VIDEO1 */
  3360. COLOR_ARRAY(
  3361. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3362. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3363. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3364. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3365. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3366. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3367. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3368. DRM_FORMAT_RGBX8888),
  3369. /* OMAP_DSS_VIDEO2 */
  3370. COLOR_ARRAY(
  3371. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3372. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3373. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3374. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3375. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3376. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3377. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3378. DRM_FORMAT_RGBX8888),
  3379. /* OMAP_DSS_VIDEO3 */
  3380. COLOR_ARRAY(
  3381. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3382. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3383. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3384. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3385. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3386. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3387. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3388. DRM_FORMAT_RGBX8888),
  3389. /* OMAP_DSS_WB */
  3390. COLOR_ARRAY(
  3391. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3392. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3393. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3394. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3395. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3396. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3397. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3398. DRM_FORMAT_RGBX8888),
  3399. };
  3400. static const u32 omap3_dispc_supported_scaler_color_modes[] = {
  3401. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_YUYV,
  3402. DRM_FORMAT_UYVY,
  3403. 0,
  3404. };
  3405. static const struct dispc_features omap24xx_dispc_feats = {
  3406. .sw_start = 5,
  3407. .fp_start = 15,
  3408. .bp_start = 27,
  3409. .sw_max = 64,
  3410. .vp_max = 255,
  3411. .hp_max = 256,
  3412. .mgr_width_start = 10,
  3413. .mgr_height_start = 26,
  3414. .mgr_width_max = 2048,
  3415. .mgr_height_max = 2048,
  3416. .ovl_width_max = 2048,
  3417. .ovl_height_max = 2048,
  3418. .max_lcd_pclk = 66500000,
  3419. .max_downscale = 2,
  3420. /*
  3421. * Assume the line width buffer to be 768 pixels as OMAP2 DISPC scaler
  3422. * cannot scale an image width larger than 768.
  3423. */
  3424. .max_line_width = 768,
  3425. .min_pcd = 2,
  3426. .calc_scaling = dispc_ovl_calc_scaling_24xx,
  3427. .calc_core_clk = calc_core_clk_24xx,
  3428. .num_fifos = 3,
  3429. .features = omap2_dispc_features_list,
  3430. .num_features = ARRAY_SIZE(omap2_dispc_features_list),
  3431. .reg_fields = omap2_dispc_reg_fields,
  3432. .num_reg_fields = ARRAY_SIZE(omap2_dispc_reg_fields),
  3433. .overlay_caps = omap2_dispc_overlay_caps,
  3434. .supported_color_modes = omap2_dispc_supported_color_modes,
  3435. .supported_scaler_color_modes = COLOR_ARRAY(DRM_FORMAT_XRGB8888),
  3436. .num_mgrs = 2,
  3437. .num_ovls = 3,
  3438. .buffer_size_unit = 1,
  3439. .burst_size_unit = 8,
  3440. .no_framedone_tv = true,
  3441. .set_max_preload = false,
  3442. .last_pixel_inc_missing = true,
  3443. };
  3444. static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
  3445. .sw_start = 5,
  3446. .fp_start = 15,
  3447. .bp_start = 27,
  3448. .sw_max = 64,
  3449. .vp_max = 255,
  3450. .hp_max = 256,
  3451. .mgr_width_start = 10,
  3452. .mgr_height_start = 26,
  3453. .mgr_width_max = 2048,
  3454. .mgr_height_max = 2048,
  3455. .ovl_width_max = 2048,
  3456. .ovl_height_max = 2048,
  3457. .max_lcd_pclk = 173000000,
  3458. .max_tv_pclk = 59000000,
  3459. .max_downscale = 4,
  3460. .max_line_width = 1024,
  3461. .min_pcd = 1,
  3462. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3463. .calc_core_clk = calc_core_clk_34xx,
  3464. .num_fifos = 3,
  3465. .features = omap3_dispc_features_list,
  3466. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3467. .reg_fields = omap3_dispc_reg_fields,
  3468. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3469. .overlay_caps = omap3430_dispc_overlay_caps,
  3470. .supported_color_modes = omap3_dispc_supported_color_modes,
  3471. .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
  3472. .num_mgrs = 2,
  3473. .num_ovls = 3,
  3474. .buffer_size_unit = 1,
  3475. .burst_size_unit = 8,
  3476. .no_framedone_tv = true,
  3477. .set_max_preload = false,
  3478. .last_pixel_inc_missing = true,
  3479. };
  3480. static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
  3481. .sw_start = 7,
  3482. .fp_start = 19,
  3483. .bp_start = 31,
  3484. .sw_max = 256,
  3485. .vp_max = 4095,
  3486. .hp_max = 4096,
  3487. .mgr_width_start = 10,
  3488. .mgr_height_start = 26,
  3489. .mgr_width_max = 2048,
  3490. .mgr_height_max = 2048,
  3491. .ovl_width_max = 2048,
  3492. .ovl_height_max = 2048,
  3493. .max_lcd_pclk = 173000000,
  3494. .max_tv_pclk = 59000000,
  3495. .max_downscale = 4,
  3496. .max_line_width = 1024,
  3497. .min_pcd = 1,
  3498. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3499. .calc_core_clk = calc_core_clk_34xx,
  3500. .num_fifos = 3,
  3501. .features = omap3_dispc_features_list,
  3502. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3503. .reg_fields = omap3_dispc_reg_fields,
  3504. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3505. .overlay_caps = omap3430_dispc_overlay_caps,
  3506. .supported_color_modes = omap3_dispc_supported_color_modes,
  3507. .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
  3508. .num_mgrs = 2,
  3509. .num_ovls = 3,
  3510. .buffer_size_unit = 1,
  3511. .burst_size_unit = 8,
  3512. .no_framedone_tv = true,
  3513. .set_max_preload = false,
  3514. .last_pixel_inc_missing = true,
  3515. };
  3516. static const struct dispc_features omap36xx_dispc_feats = {
  3517. .sw_start = 7,
  3518. .fp_start = 19,
  3519. .bp_start = 31,
  3520. .sw_max = 256,
  3521. .vp_max = 4095,
  3522. .hp_max = 4096,
  3523. .mgr_width_start = 10,
  3524. .mgr_height_start = 26,
  3525. .mgr_width_max = 2048,
  3526. .mgr_height_max = 2048,
  3527. .ovl_width_max = 2048,
  3528. .ovl_height_max = 2048,
  3529. .max_lcd_pclk = 173000000,
  3530. .max_tv_pclk = 59000000,
  3531. .max_downscale = 4,
  3532. .max_line_width = 1024,
  3533. .min_pcd = 1,
  3534. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3535. .calc_core_clk = calc_core_clk_34xx,
  3536. .num_fifos = 3,
  3537. .features = omap3_dispc_features_list,
  3538. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3539. .reg_fields = omap3_dispc_reg_fields,
  3540. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3541. .overlay_caps = omap3630_dispc_overlay_caps,
  3542. .supported_color_modes = omap3_dispc_supported_color_modes,
  3543. .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
  3544. .num_mgrs = 2,
  3545. .num_ovls = 3,
  3546. .buffer_size_unit = 1,
  3547. .burst_size_unit = 8,
  3548. .no_framedone_tv = true,
  3549. .set_max_preload = false,
  3550. .last_pixel_inc_missing = true,
  3551. };
  3552. static const struct dispc_features am43xx_dispc_feats = {
  3553. .sw_start = 7,
  3554. .fp_start = 19,
  3555. .bp_start = 31,
  3556. .sw_max = 256,
  3557. .vp_max = 4095,
  3558. .hp_max = 4096,
  3559. .mgr_width_start = 10,
  3560. .mgr_height_start = 26,
  3561. .mgr_width_max = 2048,
  3562. .mgr_height_max = 2048,
  3563. .ovl_width_max = 2048,
  3564. .ovl_height_max = 2048,
  3565. .max_lcd_pclk = 173000000,
  3566. .max_tv_pclk = 59000000,
  3567. .max_downscale = 4,
  3568. .max_line_width = 1024,
  3569. .min_pcd = 1,
  3570. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3571. .calc_core_clk = calc_core_clk_34xx,
  3572. .num_fifos = 3,
  3573. .features = am43xx_dispc_features_list,
  3574. .num_features = ARRAY_SIZE(am43xx_dispc_features_list),
  3575. .reg_fields = omap3_dispc_reg_fields,
  3576. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3577. .overlay_caps = omap3430_dispc_overlay_caps,
  3578. .supported_color_modes = omap3_dispc_supported_color_modes,
  3579. .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
  3580. .num_mgrs = 1,
  3581. .num_ovls = 3,
  3582. .buffer_size_unit = 1,
  3583. .burst_size_unit = 8,
  3584. .no_framedone_tv = true,
  3585. .set_max_preload = false,
  3586. .last_pixel_inc_missing = true,
  3587. };
  3588. static const struct dispc_features omap44xx_dispc_feats = {
  3589. .sw_start = 7,
  3590. .fp_start = 19,
  3591. .bp_start = 31,
  3592. .sw_max = 256,
  3593. .vp_max = 4095,
  3594. .hp_max = 4096,
  3595. .mgr_width_start = 10,
  3596. .mgr_height_start = 26,
  3597. .mgr_width_max = 2048,
  3598. .mgr_height_max = 2048,
  3599. .ovl_width_max = 2048,
  3600. .ovl_height_max = 2048,
  3601. .max_lcd_pclk = 170000000,
  3602. .max_tv_pclk = 185625000,
  3603. .max_downscale = 4,
  3604. .max_line_width = 2048,
  3605. .min_pcd = 1,
  3606. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3607. .calc_core_clk = calc_core_clk_44xx,
  3608. .num_fifos = 5,
  3609. .features = omap4_dispc_features_list,
  3610. .num_features = ARRAY_SIZE(omap4_dispc_features_list),
  3611. .reg_fields = omap4_dispc_reg_fields,
  3612. .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
  3613. .overlay_caps = omap4_dispc_overlay_caps,
  3614. .supported_color_modes = omap4_dispc_supported_color_modes,
  3615. .num_mgrs = 3,
  3616. .num_ovls = 4,
  3617. .buffer_size_unit = 16,
  3618. .burst_size_unit = 16,
  3619. .gfx_fifo_workaround = true,
  3620. .set_max_preload = true,
  3621. .supports_sync_align = true,
  3622. .has_writeback = true,
  3623. .supports_double_pixel = true,
  3624. .reverse_ilace_field_order = true,
  3625. .has_gamma_table = true,
  3626. .has_gamma_i734_bug = true,
  3627. };
  3628. static const struct dispc_features omap54xx_dispc_feats = {
  3629. .sw_start = 7,
  3630. .fp_start = 19,
  3631. .bp_start = 31,
  3632. .sw_max = 256,
  3633. .vp_max = 4095,
  3634. .hp_max = 4096,
  3635. .mgr_width_start = 11,
  3636. .mgr_height_start = 27,
  3637. .mgr_width_max = 4096,
  3638. .mgr_height_max = 4096,
  3639. .ovl_width_max = 2048,
  3640. .ovl_height_max = 4096,
  3641. .max_lcd_pclk = 170000000,
  3642. .max_tv_pclk = 192000000,
  3643. .max_downscale = 4,
  3644. .max_line_width = 2048,
  3645. .min_pcd = 1,
  3646. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3647. .calc_core_clk = calc_core_clk_44xx,
  3648. .num_fifos = 5,
  3649. .features = omap5_dispc_features_list,
  3650. .num_features = ARRAY_SIZE(omap5_dispc_features_list),
  3651. .reg_fields = omap4_dispc_reg_fields,
  3652. .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
  3653. .overlay_caps = omap4_dispc_overlay_caps,
  3654. .supported_color_modes = omap4_dispc_supported_color_modes,
  3655. .num_mgrs = 4,
  3656. .num_ovls = 4,
  3657. .buffer_size_unit = 16,
  3658. .burst_size_unit = 16,
  3659. .gfx_fifo_workaround = true,
  3660. .mstandby_workaround = true,
  3661. .set_max_preload = true,
  3662. .supports_sync_align = true,
  3663. .has_writeback = true,
  3664. .supports_double_pixel = true,
  3665. .reverse_ilace_field_order = true,
  3666. .has_gamma_table = true,
  3667. .has_gamma_i734_bug = true,
  3668. };
  3669. static irqreturn_t dispc_irq_handler(int irq, void *arg)
  3670. {
  3671. struct dispc_device *dispc = arg;
  3672. if (!dispc->is_enabled)
  3673. return IRQ_NONE;
  3674. return dispc->user_handler(irq, dispc->user_data);
  3675. }
  3676. int dispc_request_irq(struct dispc_device *dispc, irq_handler_t handler,
  3677. void *dev_id)
  3678. {
  3679. int r;
  3680. if (dispc->user_handler != NULL)
  3681. return -EBUSY;
  3682. dispc->user_handler = handler;
  3683. dispc->user_data = dev_id;
  3684. /* ensure the dispc_irq_handler sees the values above */
  3685. smp_wmb();
  3686. r = devm_request_irq(&dispc->pdev->dev, dispc->irq, dispc_irq_handler,
  3687. IRQF_SHARED, "OMAP DISPC", dispc);
  3688. if (r) {
  3689. dispc->user_handler = NULL;
  3690. dispc->user_data = NULL;
  3691. }
  3692. return r;
  3693. }
  3694. void dispc_free_irq(struct dispc_device *dispc, void *dev_id)
  3695. {
  3696. devm_free_irq(&dispc->pdev->dev, dispc->irq, dispc);
  3697. dispc->user_handler = NULL;
  3698. dispc->user_data = NULL;
  3699. }
  3700. u32 dispc_get_memory_bandwidth_limit(struct dispc_device *dispc)
  3701. {
  3702. u32 limit = 0;
  3703. /* Optional maximum memory bandwidth */
  3704. of_property_read_u32(dispc->pdev->dev.of_node, "max-memory-bandwidth",
  3705. &limit);
  3706. return limit;
  3707. }
  3708. /*
  3709. * Workaround for errata i734 in DSS dispc
  3710. * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
  3711. *
  3712. * For gamma tables to work on LCD1 the GFX plane has to be used at
  3713. * least once after DSS HW has come out of reset. The workaround
  3714. * sets up a minimal LCD setup with GFX plane and waits for one
  3715. * vertical sync irq before disabling the setup and continuing with
  3716. * the context restore. The physical outputs are gated during the
  3717. * operation. This workaround requires that gamma table's LOADMODE
  3718. * is set to 0x2 in DISPC_CONTROL1 register.
  3719. *
  3720. * For details see:
  3721. * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
  3722. * Literature Number: SWPZ037E
  3723. * Or some other relevant errata document for the DSS IP version.
  3724. */
  3725. static const struct dispc_errata_i734_data {
  3726. struct videomode vm;
  3727. struct omap_overlay_info ovli;
  3728. struct omap_overlay_manager_info mgri;
  3729. struct dss_lcd_mgr_config lcd_conf;
  3730. } i734 = {
  3731. .vm = {
  3732. .hactive = 8, .vactive = 1,
  3733. .pixelclock = 16000000,
  3734. .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
  3735. .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
  3736. .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
  3737. DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
  3738. DISPLAY_FLAGS_PIXDATA_POSEDGE,
  3739. },
  3740. .ovli = {
  3741. .screen_width = 1,
  3742. .width = 1, .height = 1,
  3743. .fourcc = DRM_FORMAT_XRGB8888,
  3744. .rotation = DRM_MODE_ROTATE_0,
  3745. .rotation_type = OMAP_DSS_ROT_NONE,
  3746. .pos_x = 0, .pos_y = 0,
  3747. .out_width = 0, .out_height = 0,
  3748. .global_alpha = 0xff,
  3749. .pre_mult_alpha = 0,
  3750. .zorder = 0,
  3751. },
  3752. .mgri = {
  3753. .default_color = 0,
  3754. .trans_enabled = false,
  3755. .partial_alpha_enabled = false,
  3756. .cpr_enable = false,
  3757. },
  3758. .lcd_conf = {
  3759. .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
  3760. .stallmode = false,
  3761. .fifohandcheck = false,
  3762. .clock_info = {
  3763. .lck_div = 1,
  3764. .pck_div = 2,
  3765. },
  3766. .video_port_width = 24,
  3767. .lcden_sig_polarity = 0,
  3768. },
  3769. };
  3770. static struct i734_buf {
  3771. size_t size;
  3772. dma_addr_t paddr;
  3773. void *vaddr;
  3774. } i734_buf;
  3775. static int dispc_errata_i734_wa_init(struct dispc_device *dispc)
  3776. {
  3777. if (!dispc->feat->has_gamma_i734_bug)
  3778. return 0;
  3779. i734_buf.size = i734.ovli.width * i734.ovli.height *
  3780. color_mode_to_bpp(i734.ovli.fourcc) / 8;
  3781. i734_buf.vaddr = dma_alloc_wc(&dispc->pdev->dev, i734_buf.size,
  3782. &i734_buf.paddr, GFP_KERNEL);
  3783. if (!i734_buf.vaddr) {
  3784. dev_err(&dispc->pdev->dev, "%s: dma_alloc_wc failed\n",
  3785. __func__);
  3786. return -ENOMEM;
  3787. }
  3788. return 0;
  3789. }
  3790. static void dispc_errata_i734_wa_fini(struct dispc_device *dispc)
  3791. {
  3792. if (!dispc->feat->has_gamma_i734_bug)
  3793. return;
  3794. dma_free_wc(&dispc->pdev->dev, i734_buf.size, i734_buf.vaddr,
  3795. i734_buf.paddr);
  3796. }
  3797. static void dispc_errata_i734_wa(struct dispc_device *dispc)
  3798. {
  3799. u32 framedone_irq = dispc_mgr_get_framedone_irq(dispc,
  3800. OMAP_DSS_CHANNEL_LCD);
  3801. struct omap_overlay_info ovli;
  3802. struct dss_lcd_mgr_config lcd_conf;
  3803. u32 gatestate;
  3804. unsigned int count;
  3805. if (!dispc->feat->has_gamma_i734_bug)
  3806. return;
  3807. gatestate = REG_GET(dispc, DISPC_CONFIG, 8, 4);
  3808. ovli = i734.ovli;
  3809. ovli.paddr = i734_buf.paddr;
  3810. lcd_conf = i734.lcd_conf;
  3811. /* Gate all LCD1 outputs */
  3812. REG_FLD_MOD(dispc, DISPC_CONFIG, 0x1f, 8, 4);
  3813. /* Setup and enable GFX plane */
  3814. dispc_ovl_setup(dispc, OMAP_DSS_GFX, &ovli, &i734.vm, false,
  3815. OMAP_DSS_CHANNEL_LCD);
  3816. dispc_ovl_enable(dispc, OMAP_DSS_GFX, true);
  3817. /* Set up and enable display manager for LCD1 */
  3818. dispc_mgr_setup(dispc, OMAP_DSS_CHANNEL_LCD, &i734.mgri);
  3819. dispc_calc_clock_rates(dispc, dss_get_dispc_clk_rate(dispc->dss),
  3820. &lcd_conf.clock_info);
  3821. dispc_mgr_set_lcd_config(dispc, OMAP_DSS_CHANNEL_LCD, &lcd_conf);
  3822. dispc_mgr_set_timings(dispc, OMAP_DSS_CHANNEL_LCD, &i734.vm);
  3823. dispc_clear_irqstatus(dispc, framedone_irq);
  3824. /* Enable and shut the channel to produce just one frame */
  3825. dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, true);
  3826. dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, false);
  3827. /* Busy wait for framedone. We can't fiddle with irq handlers
  3828. * in PM resume. Typically the loop runs less than 5 times and
  3829. * waits less than a micro second.
  3830. */
  3831. count = 0;
  3832. while (!(dispc_read_irqstatus(dispc) & framedone_irq)) {
  3833. if (count++ > 10000) {
  3834. dev_err(&dispc->pdev->dev, "%s: framedone timeout\n",
  3835. __func__);
  3836. break;
  3837. }
  3838. }
  3839. dispc_ovl_enable(dispc, OMAP_DSS_GFX, false);
  3840. /* Clear all irq bits before continuing */
  3841. dispc_clear_irqstatus(dispc, 0xffffffff);
  3842. /* Restore the original state to LCD1 output gates */
  3843. REG_FLD_MOD(dispc, DISPC_CONFIG, gatestate, 8, 4);
  3844. }
  3845. /* DISPC HW IP initialisation */
  3846. static const struct of_device_id dispc_of_match[] = {
  3847. { .compatible = "ti,omap2-dispc", .data = &omap24xx_dispc_feats },
  3848. { .compatible = "ti,omap3-dispc", .data = &omap36xx_dispc_feats },
  3849. { .compatible = "ti,omap4-dispc", .data = &omap44xx_dispc_feats },
  3850. { .compatible = "ti,omap5-dispc", .data = &omap54xx_dispc_feats },
  3851. { .compatible = "ti,dra7-dispc", .data = &omap54xx_dispc_feats },
  3852. {},
  3853. };
  3854. static const struct soc_device_attribute dispc_soc_devices[] = {
  3855. { .machine = "OMAP3[45]*",
  3856. .revision = "ES[12].?", .data = &omap34xx_rev1_0_dispc_feats },
  3857. { .machine = "OMAP3[45]*", .data = &omap34xx_rev3_0_dispc_feats },
  3858. { .machine = "AM35*", .data = &omap34xx_rev3_0_dispc_feats },
  3859. { .machine = "AM43*", .data = &am43xx_dispc_feats },
  3860. { /* sentinel */ }
  3861. };
  3862. static int dispc_bind(struct device *dev, struct device *master, void *data)
  3863. {
  3864. struct platform_device *pdev = to_platform_device(dev);
  3865. const struct soc_device_attribute *soc;
  3866. struct dss_device *dss = dss_get_device(master);
  3867. struct dispc_device *dispc;
  3868. u32 rev;
  3869. int r = 0;
  3870. struct device_node *np = pdev->dev.of_node;
  3871. dispc = kzalloc_obj(*dispc);
  3872. if (!dispc)
  3873. return -ENOMEM;
  3874. dispc->pdev = pdev;
  3875. platform_set_drvdata(pdev, dispc);
  3876. dispc->dss = dss;
  3877. /*
  3878. * The OMAP3-based models can't be told apart using the compatible
  3879. * string, use SoC device matching.
  3880. */
  3881. soc = soc_device_match(dispc_soc_devices);
  3882. if (soc)
  3883. dispc->feat = soc->data;
  3884. else
  3885. dispc->feat = device_get_match_data(&pdev->dev);
  3886. r = dispc_errata_i734_wa_init(dispc);
  3887. if (r)
  3888. goto err_free;
  3889. dispc->base = devm_platform_ioremap_resource(pdev, 0);
  3890. if (IS_ERR(dispc->base)) {
  3891. r = PTR_ERR(dispc->base);
  3892. goto err_free;
  3893. }
  3894. dispc->irq = platform_get_irq(dispc->pdev, 0);
  3895. if (dispc->irq < 0) {
  3896. DSSERR("platform_get_irq failed\n");
  3897. r = -ENODEV;
  3898. goto err_free;
  3899. }
  3900. if (np && of_property_read_bool(np, "syscon-pol")) {
  3901. dispc->syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
  3902. if (IS_ERR(dispc->syscon_pol)) {
  3903. dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
  3904. r = PTR_ERR(dispc->syscon_pol);
  3905. goto err_free;
  3906. }
  3907. if (of_property_read_u32_index(np, "syscon-pol", 1,
  3908. &dispc->syscon_pol_offset)) {
  3909. dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
  3910. r = -EINVAL;
  3911. goto err_free;
  3912. }
  3913. }
  3914. r = dispc_init_gamma_tables(dispc);
  3915. if (r)
  3916. goto err_free;
  3917. pm_runtime_enable(&pdev->dev);
  3918. r = dispc_runtime_get(dispc);
  3919. if (r)
  3920. goto err_runtime_get;
  3921. _omap_dispc_initial_config(dispc);
  3922. rev = dispc_read_reg(dispc, DISPC_REVISION);
  3923. dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
  3924. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  3925. dispc_runtime_put(dispc);
  3926. dss->dispc = dispc;
  3927. dispc->debugfs = dss_debugfs_create_file(dss, "dispc", dispc_dump_regs,
  3928. dispc);
  3929. return 0;
  3930. err_runtime_get:
  3931. pm_runtime_disable(&pdev->dev);
  3932. err_free:
  3933. kfree(dispc);
  3934. return r;
  3935. }
  3936. static void dispc_unbind(struct device *dev, struct device *master, void *data)
  3937. {
  3938. struct dispc_device *dispc = dev_get_drvdata(dev);
  3939. struct dss_device *dss = dispc->dss;
  3940. dss_debugfs_remove_file(dispc->debugfs);
  3941. dss->dispc = NULL;
  3942. pm_runtime_disable(dev);
  3943. dispc_errata_i734_wa_fini(dispc);
  3944. kfree(dispc);
  3945. }
  3946. static const struct component_ops dispc_component_ops = {
  3947. .bind = dispc_bind,
  3948. .unbind = dispc_unbind,
  3949. };
  3950. static int dispc_probe(struct platform_device *pdev)
  3951. {
  3952. return component_add(&pdev->dev, &dispc_component_ops);
  3953. }
  3954. static void dispc_remove(struct platform_device *pdev)
  3955. {
  3956. component_del(&pdev->dev, &dispc_component_ops);
  3957. }
  3958. static __maybe_unused int dispc_runtime_suspend(struct device *dev)
  3959. {
  3960. struct dispc_device *dispc = dev_get_drvdata(dev);
  3961. dispc->is_enabled = false;
  3962. /* ensure the dispc_irq_handler sees the is_enabled value */
  3963. smp_wmb();
  3964. /* wait for current handler to finish before turning the DISPC off */
  3965. synchronize_irq(dispc->irq);
  3966. dispc_save_context(dispc);
  3967. return 0;
  3968. }
  3969. static __maybe_unused int dispc_runtime_resume(struct device *dev)
  3970. {
  3971. struct dispc_device *dispc = dev_get_drvdata(dev);
  3972. /*
  3973. * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
  3974. * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
  3975. * _omap_dispc_initial_config(). We can thus use it to detect if
  3976. * we have lost register context.
  3977. */
  3978. if (REG_GET(dispc, DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
  3979. _omap_dispc_initial_config(dispc);
  3980. dispc_errata_i734_wa(dispc);
  3981. dispc_restore_context(dispc);
  3982. dispc_restore_gamma_tables(dispc);
  3983. }
  3984. dispc->is_enabled = true;
  3985. /* ensure the dispc_irq_handler sees the is_enabled value */
  3986. smp_wmb();
  3987. return 0;
  3988. }
  3989. static const struct dev_pm_ops dispc_pm_ops = {
  3990. SET_RUNTIME_PM_OPS(dispc_runtime_suspend, dispc_runtime_resume, NULL)
  3991. SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
  3992. };
  3993. struct platform_driver omap_dispchw_driver = {
  3994. .probe = dispc_probe,
  3995. .remove = dispc_remove,
  3996. .driver = {
  3997. .name = "omapdss_dispc",
  3998. .pm = &dispc_pm_ops,
  3999. .of_match_table = dispc_of_match,
  4000. .suppress_bind_attrs = true,
  4001. },
  4002. };