dispc.c 104 KB

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