dispc.c 102 KB

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