dispc.c 103 KB

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