dispc.c 110 KB

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