dispc.c 96 KB

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