dispc.c 103 KB

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