dispc.c 92 KB

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