dispc.c 91 KB

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