dispc.c 94 KB

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