dispc.c 102 KB

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