dispc.c 87 KB

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