dispc.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615
  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. {
  851. /*
  852. * All sizes are in bytes. Both the buffer and burst are made of
  853. * buffer_units, and the fifo thresholds must be buffer_unit aligned.
  854. */
  855. unsigned buf_unit = dss_feat_get_buffer_size_unit();
  856. unsigned ovl_fifo_size, total_fifo_size, burst_size;
  857. int i;
  858. burst_size = dispc_ovl_get_burst_size(plane);
  859. ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
  860. if (use_fifomerge) {
  861. total_fifo_size = 0;
  862. for (i = 0; i < omap_dss_get_num_overlays(); ++i)
  863. total_fifo_size += dispc_ovl_get_fifo_size(i);
  864. } else {
  865. total_fifo_size = ovl_fifo_size;
  866. }
  867. /*
  868. * We use the same low threshold for both fifomerge and non-fifomerge
  869. * cases, but for fifomerge we calculate the high threshold using the
  870. * combined fifo size
  871. */
  872. if (dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
  873. *fifo_low = ovl_fifo_size - burst_size * 2;
  874. *fifo_high = total_fifo_size - burst_size;
  875. } else {
  876. *fifo_low = ovl_fifo_size - burst_size;
  877. *fifo_high = total_fifo_size - buf_unit;
  878. }
  879. }
  880. static void dispc_ovl_set_fir(enum omap_plane plane,
  881. int hinc, int vinc,
  882. enum omap_color_component color_comp)
  883. {
  884. u32 val;
  885. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  886. u8 hinc_start, hinc_end, vinc_start, vinc_end;
  887. dss_feat_get_reg_field(FEAT_REG_FIRHINC,
  888. &hinc_start, &hinc_end);
  889. dss_feat_get_reg_field(FEAT_REG_FIRVINC,
  890. &vinc_start, &vinc_end);
  891. val = FLD_VAL(vinc, vinc_start, vinc_end) |
  892. FLD_VAL(hinc, hinc_start, hinc_end);
  893. dispc_write_reg(DISPC_OVL_FIR(plane), val);
  894. } else {
  895. val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
  896. dispc_write_reg(DISPC_OVL_FIR2(plane), val);
  897. }
  898. }
  899. static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
  900. {
  901. u32 val;
  902. u8 hor_start, hor_end, vert_start, vert_end;
  903. dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
  904. dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
  905. val = FLD_VAL(vaccu, vert_start, vert_end) |
  906. FLD_VAL(haccu, hor_start, hor_end);
  907. dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
  908. }
  909. static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
  910. {
  911. u32 val;
  912. u8 hor_start, hor_end, vert_start, vert_end;
  913. dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
  914. dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
  915. val = FLD_VAL(vaccu, vert_start, vert_end) |
  916. FLD_VAL(haccu, hor_start, hor_end);
  917. dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
  918. }
  919. static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
  920. int vaccu)
  921. {
  922. u32 val;
  923. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  924. dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
  925. }
  926. static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
  927. int vaccu)
  928. {
  929. u32 val;
  930. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  931. dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
  932. }
  933. static void dispc_ovl_set_scale_param(enum omap_plane plane,
  934. u16 orig_width, u16 orig_height,
  935. u16 out_width, u16 out_height,
  936. bool five_taps, u8 rotation,
  937. enum omap_color_component color_comp)
  938. {
  939. int fir_hinc, fir_vinc;
  940. fir_hinc = 1024 * orig_width / out_width;
  941. fir_vinc = 1024 * orig_height / out_height;
  942. dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
  943. color_comp);
  944. dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
  945. }
  946. static void dispc_ovl_set_scaling_common(enum omap_plane plane,
  947. u16 orig_width, u16 orig_height,
  948. u16 out_width, u16 out_height,
  949. bool ilace, bool five_taps,
  950. bool fieldmode, enum omap_color_mode color_mode,
  951. u8 rotation)
  952. {
  953. int accu0 = 0;
  954. int accu1 = 0;
  955. u32 l;
  956. dispc_ovl_set_scale_param(plane, orig_width, orig_height,
  957. out_width, out_height, five_taps,
  958. rotation, DISPC_COLOR_COMPONENT_RGB_Y);
  959. l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
  960. /* RESIZEENABLE and VERTICALTAPS */
  961. l &= ~((0x3 << 5) | (0x1 << 21));
  962. l |= (orig_width != out_width) ? (1 << 5) : 0;
  963. l |= (orig_height != out_height) ? (1 << 6) : 0;
  964. l |= five_taps ? (1 << 21) : 0;
  965. /* VRESIZECONF and HRESIZECONF */
  966. if (dss_has_feature(FEAT_RESIZECONF)) {
  967. l &= ~(0x3 << 7);
  968. l |= (orig_width <= out_width) ? 0 : (1 << 7);
  969. l |= (orig_height <= out_height) ? 0 : (1 << 8);
  970. }
  971. /* LINEBUFFERSPLIT */
  972. if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
  973. l &= ~(0x1 << 22);
  974. l |= five_taps ? (1 << 22) : 0;
  975. }
  976. dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
  977. /*
  978. * field 0 = even field = bottom field
  979. * field 1 = odd field = top field
  980. */
  981. if (ilace && !fieldmode) {
  982. accu1 = 0;
  983. accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
  984. if (accu0 >= 1024/2) {
  985. accu1 = 1024/2;
  986. accu0 -= accu1;
  987. }
  988. }
  989. dispc_ovl_set_vid_accu0(plane, 0, accu0);
  990. dispc_ovl_set_vid_accu1(plane, 0, accu1);
  991. }
  992. static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
  993. u16 orig_width, u16 orig_height,
  994. u16 out_width, u16 out_height,
  995. bool ilace, bool five_taps,
  996. bool fieldmode, enum omap_color_mode color_mode,
  997. u8 rotation)
  998. {
  999. int scale_x = out_width != orig_width;
  1000. int scale_y = out_height != orig_height;
  1001. if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
  1002. return;
  1003. if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
  1004. color_mode != OMAP_DSS_COLOR_UYVY &&
  1005. color_mode != OMAP_DSS_COLOR_NV12)) {
  1006. /* reset chroma resampling for RGB formats */
  1007. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
  1008. return;
  1009. }
  1010. switch (color_mode) {
  1011. case OMAP_DSS_COLOR_NV12:
  1012. /* UV is subsampled by 2 vertically*/
  1013. orig_height >>= 1;
  1014. /* UV is subsampled by 2 horz.*/
  1015. orig_width >>= 1;
  1016. break;
  1017. case OMAP_DSS_COLOR_YUV2:
  1018. case OMAP_DSS_COLOR_UYVY:
  1019. /*For YUV422 with 90/270 rotation,
  1020. *we don't upsample chroma
  1021. */
  1022. if (rotation == OMAP_DSS_ROT_0 ||
  1023. rotation == OMAP_DSS_ROT_180)
  1024. /* UV is subsampled by 2 hrz*/
  1025. orig_width >>= 1;
  1026. /* must use FIR for YUV422 if rotated */
  1027. if (rotation != OMAP_DSS_ROT_0)
  1028. scale_x = scale_y = true;
  1029. break;
  1030. default:
  1031. BUG();
  1032. }
  1033. if (out_width != orig_width)
  1034. scale_x = true;
  1035. if (out_height != orig_height)
  1036. scale_y = true;
  1037. dispc_ovl_set_scale_param(plane, orig_width, orig_height,
  1038. out_width, out_height, five_taps,
  1039. rotation, DISPC_COLOR_COMPONENT_UV);
  1040. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
  1041. (scale_x || scale_y) ? 1 : 0, 8, 8);
  1042. /* set H scaling */
  1043. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
  1044. /* set V scaling */
  1045. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
  1046. dispc_ovl_set_vid_accu2_0(plane, 0x80, 0);
  1047. dispc_ovl_set_vid_accu2_1(plane, 0x80, 0);
  1048. }
  1049. static void dispc_ovl_set_scaling(enum omap_plane plane,
  1050. u16 orig_width, u16 orig_height,
  1051. u16 out_width, u16 out_height,
  1052. bool ilace, bool five_taps,
  1053. bool fieldmode, enum omap_color_mode color_mode,
  1054. u8 rotation)
  1055. {
  1056. BUG_ON(plane == OMAP_DSS_GFX);
  1057. dispc_ovl_set_scaling_common(plane,
  1058. orig_width, orig_height,
  1059. out_width, out_height,
  1060. ilace, five_taps,
  1061. fieldmode, color_mode,
  1062. rotation);
  1063. dispc_ovl_set_scaling_uv(plane,
  1064. orig_width, orig_height,
  1065. out_width, out_height,
  1066. ilace, five_taps,
  1067. fieldmode, color_mode,
  1068. rotation);
  1069. }
  1070. static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
  1071. bool mirroring, enum omap_color_mode color_mode)
  1072. {
  1073. bool row_repeat = false;
  1074. int vidrot = 0;
  1075. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1076. color_mode == OMAP_DSS_COLOR_UYVY) {
  1077. if (mirroring) {
  1078. switch (rotation) {
  1079. case OMAP_DSS_ROT_0:
  1080. vidrot = 2;
  1081. break;
  1082. case OMAP_DSS_ROT_90:
  1083. vidrot = 1;
  1084. break;
  1085. case OMAP_DSS_ROT_180:
  1086. vidrot = 0;
  1087. break;
  1088. case OMAP_DSS_ROT_270:
  1089. vidrot = 3;
  1090. break;
  1091. }
  1092. } else {
  1093. switch (rotation) {
  1094. case OMAP_DSS_ROT_0:
  1095. vidrot = 0;
  1096. break;
  1097. case OMAP_DSS_ROT_90:
  1098. vidrot = 1;
  1099. break;
  1100. case OMAP_DSS_ROT_180:
  1101. vidrot = 2;
  1102. break;
  1103. case OMAP_DSS_ROT_270:
  1104. vidrot = 3;
  1105. break;
  1106. }
  1107. }
  1108. if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
  1109. row_repeat = true;
  1110. else
  1111. row_repeat = false;
  1112. }
  1113. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
  1114. if (dss_has_feature(FEAT_ROWREPEATENABLE))
  1115. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
  1116. row_repeat ? 1 : 0, 18, 18);
  1117. }
  1118. static int color_mode_to_bpp(enum omap_color_mode color_mode)
  1119. {
  1120. switch (color_mode) {
  1121. case OMAP_DSS_COLOR_CLUT1:
  1122. return 1;
  1123. case OMAP_DSS_COLOR_CLUT2:
  1124. return 2;
  1125. case OMAP_DSS_COLOR_CLUT4:
  1126. return 4;
  1127. case OMAP_DSS_COLOR_CLUT8:
  1128. case OMAP_DSS_COLOR_NV12:
  1129. return 8;
  1130. case OMAP_DSS_COLOR_RGB12U:
  1131. case OMAP_DSS_COLOR_RGB16:
  1132. case OMAP_DSS_COLOR_ARGB16:
  1133. case OMAP_DSS_COLOR_YUV2:
  1134. case OMAP_DSS_COLOR_UYVY:
  1135. case OMAP_DSS_COLOR_RGBA16:
  1136. case OMAP_DSS_COLOR_RGBX16:
  1137. case OMAP_DSS_COLOR_ARGB16_1555:
  1138. case OMAP_DSS_COLOR_XRGB16_1555:
  1139. return 16;
  1140. case OMAP_DSS_COLOR_RGB24P:
  1141. return 24;
  1142. case OMAP_DSS_COLOR_RGB24U:
  1143. case OMAP_DSS_COLOR_ARGB32:
  1144. case OMAP_DSS_COLOR_RGBA32:
  1145. case OMAP_DSS_COLOR_RGBX32:
  1146. return 32;
  1147. default:
  1148. BUG();
  1149. }
  1150. }
  1151. static s32 pixinc(int pixels, u8 ps)
  1152. {
  1153. if (pixels == 1)
  1154. return 1;
  1155. else if (pixels > 1)
  1156. return 1 + (pixels - 1) * ps;
  1157. else if (pixels < 0)
  1158. return 1 - (-pixels + 1) * ps;
  1159. else
  1160. BUG();
  1161. }
  1162. static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
  1163. u16 screen_width,
  1164. u16 width, u16 height,
  1165. enum omap_color_mode color_mode, bool fieldmode,
  1166. unsigned int field_offset,
  1167. unsigned *offset0, unsigned *offset1,
  1168. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
  1169. {
  1170. u8 ps;
  1171. /* FIXME CLUT formats */
  1172. switch (color_mode) {
  1173. case OMAP_DSS_COLOR_CLUT1:
  1174. case OMAP_DSS_COLOR_CLUT2:
  1175. case OMAP_DSS_COLOR_CLUT4:
  1176. case OMAP_DSS_COLOR_CLUT8:
  1177. BUG();
  1178. return;
  1179. case OMAP_DSS_COLOR_YUV2:
  1180. case OMAP_DSS_COLOR_UYVY:
  1181. ps = 4;
  1182. break;
  1183. default:
  1184. ps = color_mode_to_bpp(color_mode) / 8;
  1185. break;
  1186. }
  1187. DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
  1188. width, height);
  1189. /*
  1190. * field 0 = even field = bottom field
  1191. * field 1 = odd field = top field
  1192. */
  1193. switch (rotation + mirror * 4) {
  1194. case OMAP_DSS_ROT_0:
  1195. case OMAP_DSS_ROT_180:
  1196. /*
  1197. * If the pixel format is YUV or UYVY divide the width
  1198. * of the image by 2 for 0 and 180 degree rotation.
  1199. */
  1200. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1201. color_mode == OMAP_DSS_COLOR_UYVY)
  1202. width = width >> 1;
  1203. case OMAP_DSS_ROT_90:
  1204. case OMAP_DSS_ROT_270:
  1205. *offset1 = 0;
  1206. if (field_offset)
  1207. *offset0 = field_offset * screen_width * ps;
  1208. else
  1209. *offset0 = 0;
  1210. *row_inc = pixinc(1 +
  1211. (y_predecim * screen_width - x_predecim * width) +
  1212. (fieldmode ? screen_width : 0), ps);
  1213. *pix_inc = pixinc(x_predecim, ps);
  1214. break;
  1215. case OMAP_DSS_ROT_0 + 4:
  1216. case OMAP_DSS_ROT_180 + 4:
  1217. /* If the pixel format is YUV or UYVY divide the width
  1218. * of the image by 2 for 0 degree and 180 degree
  1219. */
  1220. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1221. color_mode == OMAP_DSS_COLOR_UYVY)
  1222. width = width >> 1;
  1223. case OMAP_DSS_ROT_90 + 4:
  1224. case OMAP_DSS_ROT_270 + 4:
  1225. *offset1 = 0;
  1226. if (field_offset)
  1227. *offset0 = field_offset * screen_width * ps;
  1228. else
  1229. *offset0 = 0;
  1230. *row_inc = pixinc(1 -
  1231. (y_predecim * screen_width + x_predecim * width) -
  1232. (fieldmode ? screen_width : 0), ps);
  1233. *pix_inc = pixinc(x_predecim, ps);
  1234. break;
  1235. default:
  1236. BUG();
  1237. }
  1238. }
  1239. static void calc_dma_rotation_offset(u8 rotation, bool mirror,
  1240. u16 screen_width,
  1241. u16 width, u16 height,
  1242. enum omap_color_mode color_mode, bool fieldmode,
  1243. unsigned int field_offset,
  1244. unsigned *offset0, unsigned *offset1,
  1245. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
  1246. {
  1247. u8 ps;
  1248. u16 fbw, fbh;
  1249. /* FIXME CLUT formats */
  1250. switch (color_mode) {
  1251. case OMAP_DSS_COLOR_CLUT1:
  1252. case OMAP_DSS_COLOR_CLUT2:
  1253. case OMAP_DSS_COLOR_CLUT4:
  1254. case OMAP_DSS_COLOR_CLUT8:
  1255. BUG();
  1256. return;
  1257. default:
  1258. ps = color_mode_to_bpp(color_mode) / 8;
  1259. break;
  1260. }
  1261. DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
  1262. width, height);
  1263. /* width & height are overlay sizes, convert to fb sizes */
  1264. if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
  1265. fbw = width;
  1266. fbh = height;
  1267. } else {
  1268. fbw = height;
  1269. fbh = width;
  1270. }
  1271. /*
  1272. * field 0 = even field = bottom field
  1273. * field 1 = odd field = top field
  1274. */
  1275. switch (rotation + mirror * 4) {
  1276. case OMAP_DSS_ROT_0:
  1277. *offset1 = 0;
  1278. if (field_offset)
  1279. *offset0 = *offset1 + field_offset * screen_width * ps;
  1280. else
  1281. *offset0 = *offset1;
  1282. *row_inc = pixinc(1 +
  1283. (y_predecim * screen_width - fbw * x_predecim) +
  1284. (fieldmode ? screen_width : 0), ps);
  1285. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1286. color_mode == OMAP_DSS_COLOR_UYVY)
  1287. *pix_inc = pixinc(x_predecim, 2 * ps);
  1288. else
  1289. *pix_inc = pixinc(x_predecim, ps);
  1290. break;
  1291. case OMAP_DSS_ROT_90:
  1292. *offset1 = screen_width * (fbh - 1) * ps;
  1293. if (field_offset)
  1294. *offset0 = *offset1 + field_offset * ps;
  1295. else
  1296. *offset0 = *offset1;
  1297. *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
  1298. y_predecim + (fieldmode ? 1 : 0), ps);
  1299. *pix_inc = pixinc(-x_predecim * screen_width, ps);
  1300. break;
  1301. case OMAP_DSS_ROT_180:
  1302. *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
  1303. if (field_offset)
  1304. *offset0 = *offset1 - field_offset * screen_width * ps;
  1305. else
  1306. *offset0 = *offset1;
  1307. *row_inc = pixinc(-1 -
  1308. (y_predecim * screen_width - fbw * x_predecim) -
  1309. (fieldmode ? screen_width : 0), ps);
  1310. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1311. color_mode == OMAP_DSS_COLOR_UYVY)
  1312. *pix_inc = pixinc(-x_predecim, 2 * ps);
  1313. else
  1314. *pix_inc = pixinc(-x_predecim, ps);
  1315. break;
  1316. case OMAP_DSS_ROT_270:
  1317. *offset1 = (fbw - 1) * ps;
  1318. if (field_offset)
  1319. *offset0 = *offset1 - field_offset * ps;
  1320. else
  1321. *offset0 = *offset1;
  1322. *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
  1323. y_predecim - (fieldmode ? 1 : 0), ps);
  1324. *pix_inc = pixinc(x_predecim * screen_width, ps);
  1325. break;
  1326. /* mirroring */
  1327. case OMAP_DSS_ROT_0 + 4:
  1328. *offset1 = (fbw - 1) * ps;
  1329. if (field_offset)
  1330. *offset0 = *offset1 + field_offset * screen_width * ps;
  1331. else
  1332. *offset0 = *offset1;
  1333. *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
  1334. (fieldmode ? screen_width : 0),
  1335. ps);
  1336. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1337. color_mode == OMAP_DSS_COLOR_UYVY)
  1338. *pix_inc = pixinc(-x_predecim, 2 * ps);
  1339. else
  1340. *pix_inc = pixinc(-x_predecim, ps);
  1341. break;
  1342. case OMAP_DSS_ROT_90 + 4:
  1343. *offset1 = 0;
  1344. if (field_offset)
  1345. *offset0 = *offset1 + field_offset * ps;
  1346. else
  1347. *offset0 = *offset1;
  1348. *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
  1349. y_predecim + (fieldmode ? 1 : 0),
  1350. ps);
  1351. *pix_inc = pixinc(x_predecim * screen_width, ps);
  1352. break;
  1353. case OMAP_DSS_ROT_180 + 4:
  1354. *offset1 = screen_width * (fbh - 1) * ps;
  1355. if (field_offset)
  1356. *offset0 = *offset1 - field_offset * screen_width * ps;
  1357. else
  1358. *offset0 = *offset1;
  1359. *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
  1360. (fieldmode ? screen_width : 0),
  1361. ps);
  1362. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1363. color_mode == OMAP_DSS_COLOR_UYVY)
  1364. *pix_inc = pixinc(x_predecim, 2 * ps);
  1365. else
  1366. *pix_inc = pixinc(x_predecim, ps);
  1367. break;
  1368. case OMAP_DSS_ROT_270 + 4:
  1369. *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
  1370. if (field_offset)
  1371. *offset0 = *offset1 - field_offset * ps;
  1372. else
  1373. *offset0 = *offset1;
  1374. *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
  1375. y_predecim - (fieldmode ? 1 : 0),
  1376. ps);
  1377. *pix_inc = pixinc(-x_predecim * screen_width, ps);
  1378. break;
  1379. default:
  1380. BUG();
  1381. }
  1382. }
  1383. /*
  1384. * This function is used to avoid synclosts in OMAP3, because of some
  1385. * undocumented horizontal position and timing related limitations.
  1386. */
  1387. static int check_horiz_timing_omap3(enum omap_channel channel,
  1388. const struct omap_video_timings *t, u16 pos_x,
  1389. u16 width, u16 height, u16 out_width, u16 out_height)
  1390. {
  1391. int DS = DIV_ROUND_UP(height, out_height);
  1392. unsigned long nonactive, lclk, pclk;
  1393. static const u8 limits[3] = { 8, 10, 20 };
  1394. u64 val, blank;
  1395. int i;
  1396. nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
  1397. pclk = dispc_mgr_pclk_rate(channel);
  1398. if (dispc_mgr_is_lcd(channel))
  1399. lclk = dispc_mgr_lclk_rate(channel);
  1400. else
  1401. lclk = dispc_fclk_rate();
  1402. i = 0;
  1403. if (out_height < height)
  1404. i++;
  1405. if (out_width < width)
  1406. i++;
  1407. blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
  1408. DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
  1409. if (blank <= limits[i])
  1410. return -EINVAL;
  1411. /*
  1412. * Pixel data should be prepared before visible display point starts.
  1413. * So, atleast DS-2 lines must have already been fetched by DISPC
  1414. * during nonactive - pos_x period.
  1415. */
  1416. val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
  1417. DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
  1418. val, max(0, DS - 2) * width);
  1419. if (val < max(0, DS - 2) * width)
  1420. return -EINVAL;
  1421. /*
  1422. * All lines need to be refilled during the nonactive period of which
  1423. * only one line can be loaded during the active period. So, atleast
  1424. * DS - 1 lines should be loaded during nonactive period.
  1425. */
  1426. val = div_u64((u64)nonactive * lclk, pclk);
  1427. DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
  1428. val, max(0, DS - 1) * width);
  1429. if (val < max(0, DS - 1) * width)
  1430. return -EINVAL;
  1431. return 0;
  1432. }
  1433. static unsigned long calc_core_clk_five_taps(enum omap_channel channel,
  1434. const struct omap_video_timings *mgr_timings, u16 width,
  1435. u16 height, u16 out_width, u16 out_height,
  1436. enum omap_color_mode color_mode)
  1437. {
  1438. u32 core_clk = 0;
  1439. u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
  1440. if (height <= out_height && width <= out_width)
  1441. return (unsigned long) pclk;
  1442. if (height > out_height) {
  1443. unsigned int ppl = mgr_timings->x_res;
  1444. tmp = pclk * height * out_width;
  1445. do_div(tmp, 2 * out_height * ppl);
  1446. core_clk = tmp;
  1447. if (height > 2 * out_height) {
  1448. if (ppl == out_width)
  1449. return 0;
  1450. tmp = pclk * (height - 2 * out_height) * out_width;
  1451. do_div(tmp, 2 * out_height * (ppl - out_width));
  1452. core_clk = max_t(u32, core_clk, tmp);
  1453. }
  1454. }
  1455. if (width > out_width) {
  1456. tmp = pclk * width;
  1457. do_div(tmp, out_width);
  1458. core_clk = max_t(u32, core_clk, tmp);
  1459. if (color_mode == OMAP_DSS_COLOR_RGB24U)
  1460. core_clk <<= 1;
  1461. }
  1462. return core_clk;
  1463. }
  1464. static unsigned long calc_core_clk(enum omap_channel channel, u16 width,
  1465. u16 height, u16 out_width, u16 out_height)
  1466. {
  1467. unsigned int hf, vf;
  1468. unsigned long pclk = dispc_mgr_pclk_rate(channel);
  1469. /*
  1470. * FIXME how to determine the 'A' factor
  1471. * for the no downscaling case ?
  1472. */
  1473. if (width > 3 * out_width)
  1474. hf = 4;
  1475. else if (width > 2 * out_width)
  1476. hf = 3;
  1477. else if (width > out_width)
  1478. hf = 2;
  1479. else
  1480. hf = 1;
  1481. if (height > out_height)
  1482. vf = 2;
  1483. else
  1484. vf = 1;
  1485. if (cpu_is_omap24xx()) {
  1486. if (vf > 1 && hf > 1)
  1487. return pclk * 4;
  1488. else
  1489. return pclk * 2;
  1490. } else if (cpu_is_omap34xx()) {
  1491. return pclk * vf * hf;
  1492. } else {
  1493. if (hf > 1)
  1494. return DIV_ROUND_UP(pclk, out_width) * width;
  1495. else
  1496. return pclk;
  1497. }
  1498. }
  1499. static int dispc_ovl_calc_scaling(enum omap_plane plane,
  1500. enum omap_channel channel,
  1501. const struct omap_video_timings *mgr_timings,
  1502. u16 width, u16 height, u16 out_width, u16 out_height,
  1503. enum omap_color_mode color_mode, bool *five_taps,
  1504. int *x_predecim, int *y_predecim, u16 pos_x)
  1505. {
  1506. struct omap_overlay *ovl = omap_dss_get_overlay(plane);
  1507. const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
  1508. const int maxsinglelinewidth =
  1509. dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
  1510. const int max_decim_limit = 16;
  1511. unsigned long core_clk = 0;
  1512. int decim_x, decim_y, error, min_factor;
  1513. u16 in_width, in_height, in_width_max = 0;
  1514. if (width == out_width && height == out_height)
  1515. return 0;
  1516. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
  1517. return -EINVAL;
  1518. *x_predecim = max_decim_limit;
  1519. *y_predecim = max_decim_limit;
  1520. if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
  1521. color_mode == OMAP_DSS_COLOR_CLUT2 ||
  1522. color_mode == OMAP_DSS_COLOR_CLUT4 ||
  1523. color_mode == OMAP_DSS_COLOR_CLUT8) {
  1524. *x_predecim = 1;
  1525. *y_predecim = 1;
  1526. *five_taps = false;
  1527. return 0;
  1528. }
  1529. decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
  1530. decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
  1531. min_factor = min(decim_x, decim_y);
  1532. if (decim_x > *x_predecim || out_width > width * 8)
  1533. return -EINVAL;
  1534. if (decim_y > *y_predecim || out_height > height * 8)
  1535. return -EINVAL;
  1536. if (cpu_is_omap24xx()) {
  1537. *five_taps = false;
  1538. do {
  1539. in_height = DIV_ROUND_UP(height, decim_y);
  1540. in_width = DIV_ROUND_UP(width, decim_x);
  1541. core_clk = calc_core_clk(channel, in_width, in_height,
  1542. out_width, out_height);
  1543. error = (in_width > maxsinglelinewidth || !core_clk ||
  1544. core_clk > dispc_core_clk_rate());
  1545. if (error) {
  1546. if (decim_x == decim_y) {
  1547. decim_x = min_factor;
  1548. decim_y++;
  1549. } else {
  1550. swap(decim_x, decim_y);
  1551. if (decim_x < decim_y)
  1552. decim_x++;
  1553. }
  1554. }
  1555. } while (decim_x <= *x_predecim && decim_y <= *y_predecim &&
  1556. error);
  1557. if (in_width > maxsinglelinewidth) {
  1558. DSSERR("Cannot scale max input width exceeded");
  1559. return -EINVAL;
  1560. }
  1561. } else if (cpu_is_omap34xx()) {
  1562. do {
  1563. in_height = DIV_ROUND_UP(height, decim_y);
  1564. in_width = DIV_ROUND_UP(width, decim_x);
  1565. core_clk = calc_core_clk_five_taps(channel, mgr_timings,
  1566. in_width, in_height, out_width, out_height,
  1567. color_mode);
  1568. error = check_horiz_timing_omap3(channel, mgr_timings,
  1569. pos_x, in_width, in_height, out_width,
  1570. out_height);
  1571. if (in_width > maxsinglelinewidth)
  1572. if (in_height > out_height &&
  1573. in_height < out_height * 2)
  1574. *five_taps = false;
  1575. if (!*five_taps)
  1576. core_clk = calc_core_clk(channel, in_width,
  1577. in_height, out_width, out_height);
  1578. error = (error || in_width > maxsinglelinewidth * 2 ||
  1579. (in_width > maxsinglelinewidth && *five_taps) ||
  1580. !core_clk || core_clk > dispc_core_clk_rate());
  1581. if (error) {
  1582. if (decim_x == decim_y) {
  1583. decim_x = min_factor;
  1584. decim_y++;
  1585. } else {
  1586. swap(decim_x, decim_y);
  1587. if (decim_x < decim_y)
  1588. decim_x++;
  1589. }
  1590. }
  1591. } while (decim_x <= *x_predecim && decim_y <= *y_predecim
  1592. && error);
  1593. if (check_horiz_timing_omap3(channel, mgr_timings, pos_x, width,
  1594. height, out_width, out_height)){
  1595. DSSERR("horizontal timing too tight\n");
  1596. return -EINVAL;
  1597. }
  1598. if (in_width > (maxsinglelinewidth * 2)) {
  1599. DSSERR("Cannot setup scaling");
  1600. DSSERR("width exceeds maximum width possible");
  1601. return -EINVAL;
  1602. }
  1603. if (in_width > maxsinglelinewidth && *five_taps) {
  1604. DSSERR("cannot setup scaling with five taps");
  1605. return -EINVAL;
  1606. }
  1607. } else {
  1608. int decim_x_min = decim_x;
  1609. in_height = DIV_ROUND_UP(height, decim_y);
  1610. in_width_max = dispc_core_clk_rate() /
  1611. DIV_ROUND_UP(dispc_mgr_pclk_rate(channel),
  1612. out_width);
  1613. decim_x = DIV_ROUND_UP(width, in_width_max);
  1614. decim_x = decim_x > decim_x_min ? decim_x : decim_x_min;
  1615. if (decim_x > *x_predecim)
  1616. return -EINVAL;
  1617. do {
  1618. in_width = DIV_ROUND_UP(width, decim_x);
  1619. } while (decim_x <= *x_predecim &&
  1620. in_width > maxsinglelinewidth && decim_x++);
  1621. if (in_width > maxsinglelinewidth) {
  1622. DSSERR("Cannot scale width exceeds max line width");
  1623. return -EINVAL;
  1624. }
  1625. core_clk = calc_core_clk(channel, in_width, in_height,
  1626. out_width, out_height);
  1627. }
  1628. DSSDBG("required core clk rate = %lu Hz\n", core_clk);
  1629. DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
  1630. if (!core_clk || core_clk > dispc_core_clk_rate()) {
  1631. DSSERR("failed to set up scaling, "
  1632. "required core clk rate = %lu Hz, "
  1633. "current core clk rate = %lu Hz\n",
  1634. core_clk, dispc_core_clk_rate());
  1635. return -EINVAL;
  1636. }
  1637. *x_predecim = decim_x;
  1638. *y_predecim = decim_y;
  1639. return 0;
  1640. }
  1641. int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
  1642. bool ilace, bool replication,
  1643. const struct omap_video_timings *mgr_timings)
  1644. {
  1645. struct omap_overlay *ovl = omap_dss_get_overlay(plane);
  1646. bool five_taps = true;
  1647. bool fieldmode = 0;
  1648. int r, cconv = 0;
  1649. unsigned offset0, offset1;
  1650. s32 row_inc;
  1651. s32 pix_inc;
  1652. u16 frame_height = oi->height;
  1653. unsigned int field_offset = 0;
  1654. u16 in_height = oi->height;
  1655. u16 in_width = oi->width;
  1656. u16 out_width, out_height;
  1657. enum omap_channel channel;
  1658. int x_predecim = 1, y_predecim = 1;
  1659. channel = dispc_ovl_get_channel_out(plane);
  1660. DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
  1661. "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d\n",
  1662. plane, oi->paddr, oi->p_uv_addr,
  1663. oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
  1664. oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
  1665. oi->mirror, ilace, channel, replication);
  1666. if (oi->paddr == 0)
  1667. return -EINVAL;
  1668. out_width = oi->out_width == 0 ? oi->width : oi->out_width;
  1669. out_height = oi->out_height == 0 ? oi->height : oi->out_height;
  1670. if (ilace && oi->height == out_height)
  1671. fieldmode = 1;
  1672. if (ilace) {
  1673. if (fieldmode)
  1674. in_height /= 2;
  1675. oi->pos_y /= 2;
  1676. out_height /= 2;
  1677. DSSDBG("adjusting for ilace: height %d, pos_y %d, "
  1678. "out_height %d\n",
  1679. in_height, oi->pos_y, out_height);
  1680. }
  1681. if (!dss_feat_color_mode_supported(plane, oi->color_mode))
  1682. return -EINVAL;
  1683. r = dispc_ovl_calc_scaling(plane, channel, mgr_timings, in_width,
  1684. in_height, out_width, out_height, oi->color_mode,
  1685. &five_taps, &x_predecim, &y_predecim, oi->pos_x);
  1686. if (r)
  1687. return r;
  1688. in_width = DIV_ROUND_UP(in_width, x_predecim);
  1689. in_height = DIV_ROUND_UP(in_height, y_predecim);
  1690. if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
  1691. oi->color_mode == OMAP_DSS_COLOR_UYVY ||
  1692. oi->color_mode == OMAP_DSS_COLOR_NV12)
  1693. cconv = 1;
  1694. if (ilace && !fieldmode) {
  1695. /*
  1696. * when downscaling the bottom field may have to start several
  1697. * source lines below the top field. Unfortunately ACCUI
  1698. * registers will only hold the fractional part of the offset
  1699. * so the integer part must be added to the base address of the
  1700. * bottom field.
  1701. */
  1702. if (!in_height || in_height == out_height)
  1703. field_offset = 0;
  1704. else
  1705. field_offset = in_height / out_height / 2;
  1706. }
  1707. /* Fields are independent but interleaved in memory. */
  1708. if (fieldmode)
  1709. field_offset = 1;
  1710. if (oi->rotation_type == OMAP_DSS_ROT_DMA)
  1711. calc_dma_rotation_offset(oi->rotation, oi->mirror,
  1712. oi->screen_width, in_width, frame_height,
  1713. oi->color_mode, fieldmode, field_offset,
  1714. &offset0, &offset1, &row_inc, &pix_inc,
  1715. x_predecim, y_predecim);
  1716. else
  1717. calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
  1718. oi->screen_width, in_width, frame_height,
  1719. oi->color_mode, fieldmode, field_offset,
  1720. &offset0, &offset1, &row_inc, &pix_inc,
  1721. x_predecim, y_predecim);
  1722. DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
  1723. offset0, offset1, row_inc, pix_inc);
  1724. dispc_ovl_set_color_mode(plane, oi->color_mode);
  1725. dispc_ovl_set_ba0(plane, oi->paddr + offset0);
  1726. dispc_ovl_set_ba1(plane, oi->paddr + offset1);
  1727. if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
  1728. dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
  1729. dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
  1730. }
  1731. dispc_ovl_set_row_inc(plane, row_inc);
  1732. dispc_ovl_set_pix_inc(plane, pix_inc);
  1733. DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, in_width,
  1734. in_height, out_width, out_height);
  1735. dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
  1736. dispc_ovl_set_pic_size(plane, in_width, in_height);
  1737. if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
  1738. dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
  1739. out_height, ilace, five_taps, fieldmode,
  1740. oi->color_mode, oi->rotation);
  1741. dispc_ovl_set_vid_size(plane, out_width, out_height);
  1742. dispc_ovl_set_vid_color_conv(plane, cconv);
  1743. }
  1744. dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
  1745. oi->color_mode);
  1746. dispc_ovl_set_zorder(plane, oi->zorder);
  1747. dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
  1748. dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
  1749. dispc_ovl_enable_replication(plane, replication);
  1750. return 0;
  1751. }
  1752. int dispc_ovl_enable(enum omap_plane plane, bool enable)
  1753. {
  1754. DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
  1755. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
  1756. return 0;
  1757. }
  1758. static void dispc_disable_isr(void *data, u32 mask)
  1759. {
  1760. struct completion *compl = data;
  1761. complete(compl);
  1762. }
  1763. static void _enable_lcd_out(enum omap_channel channel, bool enable)
  1764. {
  1765. if (channel == OMAP_DSS_CHANNEL_LCD2) {
  1766. REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0);
  1767. /* flush posted write */
  1768. dispc_read_reg(DISPC_CONTROL2);
  1769. } else {
  1770. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
  1771. dispc_read_reg(DISPC_CONTROL);
  1772. }
  1773. }
  1774. static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
  1775. {
  1776. struct completion frame_done_completion;
  1777. bool is_on;
  1778. int r;
  1779. u32 irq;
  1780. /* When we disable LCD output, we need to wait until frame is done.
  1781. * Otherwise the DSS is still working, and turning off the clocks
  1782. * prevents DSS from going to OFF mode */
  1783. is_on = channel == OMAP_DSS_CHANNEL_LCD2 ?
  1784. REG_GET(DISPC_CONTROL2, 0, 0) :
  1785. REG_GET(DISPC_CONTROL, 0, 0);
  1786. irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 :
  1787. DISPC_IRQ_FRAMEDONE;
  1788. if (!enable && is_on) {
  1789. init_completion(&frame_done_completion);
  1790. r = omap_dispc_register_isr(dispc_disable_isr,
  1791. &frame_done_completion, irq);
  1792. if (r)
  1793. DSSERR("failed to register FRAMEDONE isr\n");
  1794. }
  1795. _enable_lcd_out(channel, enable);
  1796. if (!enable && is_on) {
  1797. if (!wait_for_completion_timeout(&frame_done_completion,
  1798. msecs_to_jiffies(100)))
  1799. DSSERR("timeout waiting for FRAME DONE\n");
  1800. r = omap_dispc_unregister_isr(dispc_disable_isr,
  1801. &frame_done_completion, irq);
  1802. if (r)
  1803. DSSERR("failed to unregister FRAMEDONE isr\n");
  1804. }
  1805. }
  1806. static void _enable_digit_out(bool enable)
  1807. {
  1808. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
  1809. /* flush posted write */
  1810. dispc_read_reg(DISPC_CONTROL);
  1811. }
  1812. static void dispc_mgr_enable_digit_out(bool enable)
  1813. {
  1814. struct completion frame_done_completion;
  1815. enum dss_hdmi_venc_clk_source_select src;
  1816. int r, i;
  1817. u32 irq_mask;
  1818. int num_irqs;
  1819. if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
  1820. return;
  1821. src = dss_get_hdmi_venc_clk_source();
  1822. if (enable) {
  1823. unsigned long flags;
  1824. /* When we enable digit output, we'll get an extra digit
  1825. * sync lost interrupt, that we need to ignore */
  1826. spin_lock_irqsave(&dispc.irq_lock, flags);
  1827. dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  1828. _omap_dispc_set_irqs();
  1829. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  1830. }
  1831. /* When we disable digit output, we need to wait until fields are done.
  1832. * Otherwise the DSS is still working, and turning off the clocks
  1833. * prevents DSS from going to OFF mode. And when enabling, we need to
  1834. * wait for the extra sync losts */
  1835. init_completion(&frame_done_completion);
  1836. if (src == DSS_HDMI_M_PCLK && enable == false) {
  1837. irq_mask = DISPC_IRQ_FRAMEDONETV;
  1838. num_irqs = 1;
  1839. } else {
  1840. irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
  1841. /* XXX I understand from TRM that we should only wait for the
  1842. * current field to complete. But it seems we have to wait for
  1843. * both fields */
  1844. num_irqs = 2;
  1845. }
  1846. r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
  1847. irq_mask);
  1848. if (r)
  1849. DSSERR("failed to register %x isr\n", irq_mask);
  1850. _enable_digit_out(enable);
  1851. for (i = 0; i < num_irqs; ++i) {
  1852. if (!wait_for_completion_timeout(&frame_done_completion,
  1853. msecs_to_jiffies(100)))
  1854. DSSERR("timeout waiting for digit out to %s\n",
  1855. enable ? "start" : "stop");
  1856. }
  1857. r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
  1858. irq_mask);
  1859. if (r)
  1860. DSSERR("failed to unregister %x isr\n", irq_mask);
  1861. if (enable) {
  1862. unsigned long flags;
  1863. spin_lock_irqsave(&dispc.irq_lock, flags);
  1864. dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
  1865. dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
  1866. _omap_dispc_set_irqs();
  1867. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  1868. }
  1869. }
  1870. bool dispc_mgr_is_enabled(enum omap_channel channel)
  1871. {
  1872. if (channel == OMAP_DSS_CHANNEL_LCD)
  1873. return !!REG_GET(DISPC_CONTROL, 0, 0);
  1874. else if (channel == OMAP_DSS_CHANNEL_DIGIT)
  1875. return !!REG_GET(DISPC_CONTROL, 1, 1);
  1876. else if (channel == OMAP_DSS_CHANNEL_LCD2)
  1877. return !!REG_GET(DISPC_CONTROL2, 0, 0);
  1878. else
  1879. BUG();
  1880. }
  1881. void dispc_mgr_enable(enum omap_channel channel, bool enable)
  1882. {
  1883. if (dispc_mgr_is_lcd(channel))
  1884. dispc_mgr_enable_lcd_out(channel, enable);
  1885. else if (channel == OMAP_DSS_CHANNEL_DIGIT)
  1886. dispc_mgr_enable_digit_out(enable);
  1887. else
  1888. BUG();
  1889. }
  1890. void dispc_lcd_enable_signal_polarity(bool act_high)
  1891. {
  1892. if (!dss_has_feature(FEAT_LCDENABLEPOL))
  1893. return;
  1894. REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
  1895. }
  1896. void dispc_lcd_enable_signal(bool enable)
  1897. {
  1898. if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
  1899. return;
  1900. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
  1901. }
  1902. void dispc_pck_free_enable(bool enable)
  1903. {
  1904. if (!dss_has_feature(FEAT_PCKFREEENABLE))
  1905. return;
  1906. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
  1907. }
  1908. void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
  1909. {
  1910. if (channel == OMAP_DSS_CHANNEL_LCD2)
  1911. REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
  1912. else
  1913. REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
  1914. }
  1915. void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
  1916. enum omap_lcd_display_type type)
  1917. {
  1918. int mode;
  1919. switch (type) {
  1920. case OMAP_DSS_LCD_DISPLAY_STN:
  1921. mode = 0;
  1922. break;
  1923. case OMAP_DSS_LCD_DISPLAY_TFT:
  1924. mode = 1;
  1925. break;
  1926. default:
  1927. BUG();
  1928. return;
  1929. }
  1930. if (channel == OMAP_DSS_CHANNEL_LCD2)
  1931. REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3);
  1932. else
  1933. REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
  1934. }
  1935. void dispc_set_loadmode(enum omap_dss_load_mode mode)
  1936. {
  1937. REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
  1938. }
  1939. static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
  1940. {
  1941. dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
  1942. }
  1943. static void dispc_mgr_set_trans_key(enum omap_channel ch,
  1944. enum omap_dss_trans_key_type type,
  1945. u32 trans_key)
  1946. {
  1947. if (ch == OMAP_DSS_CHANNEL_LCD)
  1948. REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
  1949. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  1950. REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
  1951. else /* OMAP_DSS_CHANNEL_LCD2 */
  1952. REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11);
  1953. dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
  1954. }
  1955. static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
  1956. {
  1957. if (ch == OMAP_DSS_CHANNEL_LCD)
  1958. REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
  1959. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  1960. REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
  1961. else /* OMAP_DSS_CHANNEL_LCD2 */
  1962. REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
  1963. }
  1964. static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
  1965. bool enable)
  1966. {
  1967. if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
  1968. return;
  1969. if (ch == OMAP_DSS_CHANNEL_LCD)
  1970. REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
  1971. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  1972. REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
  1973. }
  1974. void dispc_mgr_setup(enum omap_channel channel,
  1975. struct omap_overlay_manager_info *info)
  1976. {
  1977. dispc_mgr_set_default_color(channel, info->default_color);
  1978. dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
  1979. dispc_mgr_enable_trans_key(channel, info->trans_enabled);
  1980. dispc_mgr_enable_alpha_fixed_zorder(channel,
  1981. info->partial_alpha_enabled);
  1982. if (dss_has_feature(FEAT_CPR)) {
  1983. dispc_mgr_enable_cpr(channel, info->cpr_enable);
  1984. dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
  1985. }
  1986. }
  1987. void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
  1988. {
  1989. int code;
  1990. switch (data_lines) {
  1991. case 12:
  1992. code = 0;
  1993. break;
  1994. case 16:
  1995. code = 1;
  1996. break;
  1997. case 18:
  1998. code = 2;
  1999. break;
  2000. case 24:
  2001. code = 3;
  2002. break;
  2003. default:
  2004. BUG();
  2005. return;
  2006. }
  2007. if (channel == OMAP_DSS_CHANNEL_LCD2)
  2008. REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8);
  2009. else
  2010. REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
  2011. }
  2012. void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
  2013. {
  2014. u32 l;
  2015. int gpout0, gpout1;
  2016. switch (mode) {
  2017. case DSS_IO_PAD_MODE_RESET:
  2018. gpout0 = 0;
  2019. gpout1 = 0;
  2020. break;
  2021. case DSS_IO_PAD_MODE_RFBI:
  2022. gpout0 = 1;
  2023. gpout1 = 0;
  2024. break;
  2025. case DSS_IO_PAD_MODE_BYPASS:
  2026. gpout0 = 1;
  2027. gpout1 = 1;
  2028. break;
  2029. default:
  2030. BUG();
  2031. return;
  2032. }
  2033. l = dispc_read_reg(DISPC_CONTROL);
  2034. l = FLD_MOD(l, gpout0, 15, 15);
  2035. l = FLD_MOD(l, gpout1, 16, 16);
  2036. dispc_write_reg(DISPC_CONTROL, l);
  2037. }
  2038. void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
  2039. {
  2040. if (channel == OMAP_DSS_CHANNEL_LCD2)
  2041. REG_FLD_MOD(DISPC_CONTROL2, enable, 11, 11);
  2042. else
  2043. REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11);
  2044. }
  2045. static bool _dispc_mgr_size_ok(u16 width, u16 height)
  2046. {
  2047. return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
  2048. height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
  2049. }
  2050. static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
  2051. int vsw, int vfp, int vbp)
  2052. {
  2053. if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
  2054. if (hsw < 1 || hsw > 64 ||
  2055. hfp < 1 || hfp > 256 ||
  2056. hbp < 1 || hbp > 256 ||
  2057. vsw < 1 || vsw > 64 ||
  2058. vfp < 0 || vfp > 255 ||
  2059. vbp < 0 || vbp > 255)
  2060. return false;
  2061. } else {
  2062. if (hsw < 1 || hsw > 256 ||
  2063. hfp < 1 || hfp > 4096 ||
  2064. hbp < 1 || hbp > 4096 ||
  2065. vsw < 1 || vsw > 256 ||
  2066. vfp < 0 || vfp > 4095 ||
  2067. vbp < 0 || vbp > 4095)
  2068. return false;
  2069. }
  2070. return true;
  2071. }
  2072. bool dispc_mgr_timings_ok(enum omap_channel channel,
  2073. const struct omap_video_timings *timings)
  2074. {
  2075. bool timings_ok;
  2076. timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
  2077. if (dispc_mgr_is_lcd(channel))
  2078. timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
  2079. timings->hfp, timings->hbp,
  2080. timings->vsw, timings->vfp,
  2081. timings->vbp);
  2082. return timings_ok;
  2083. }
  2084. static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
  2085. int hfp, int hbp, int vsw, int vfp, int vbp)
  2086. {
  2087. u32 timing_h, timing_v;
  2088. if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
  2089. timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
  2090. FLD_VAL(hbp-1, 27, 20);
  2091. timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
  2092. FLD_VAL(vbp, 27, 20);
  2093. } else {
  2094. timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
  2095. FLD_VAL(hbp-1, 31, 20);
  2096. timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
  2097. FLD_VAL(vbp, 31, 20);
  2098. }
  2099. dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
  2100. dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
  2101. }
  2102. /* change name to mode? */
  2103. void dispc_mgr_set_timings(enum omap_channel channel,
  2104. struct omap_video_timings *timings)
  2105. {
  2106. unsigned xtot, ytot;
  2107. unsigned long ht, vt;
  2108. DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res,
  2109. timings->y_res);
  2110. if (!dispc_mgr_timings_ok(channel, timings))
  2111. BUG();
  2112. if (dispc_mgr_is_lcd(channel)) {
  2113. _dispc_mgr_set_lcd_timings(channel, timings->hsw, timings->hfp,
  2114. timings->hbp, timings->vsw, timings->vfp,
  2115. timings->vbp);
  2116. xtot = timings->x_res + timings->hfp + timings->hsw +
  2117. timings->hbp;
  2118. ytot = timings->y_res + timings->vfp + timings->vsw +
  2119. timings->vbp;
  2120. ht = (timings->pixel_clock * 1000) / xtot;
  2121. vt = (timings->pixel_clock * 1000) / xtot / ytot;
  2122. DSSDBG("pck %u\n", timings->pixel_clock);
  2123. DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
  2124. timings->hsw, timings->hfp, timings->hbp,
  2125. timings->vsw, timings->vfp, timings->vbp);
  2126. DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
  2127. }
  2128. dispc_mgr_set_size(channel, timings->x_res, timings->y_res);
  2129. }
  2130. static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
  2131. u16 pck_div)
  2132. {
  2133. BUG_ON(lck_div < 1);
  2134. BUG_ON(pck_div < 1);
  2135. dispc_write_reg(DISPC_DIVISORo(channel),
  2136. FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
  2137. }
  2138. static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
  2139. int *pck_div)
  2140. {
  2141. u32 l;
  2142. l = dispc_read_reg(DISPC_DIVISORo(channel));
  2143. *lck_div = FLD_GET(l, 23, 16);
  2144. *pck_div = FLD_GET(l, 7, 0);
  2145. }
  2146. unsigned long dispc_fclk_rate(void)
  2147. {
  2148. struct platform_device *dsidev;
  2149. unsigned long r = 0;
  2150. switch (dss_get_dispc_clk_source()) {
  2151. case OMAP_DSS_CLK_SRC_FCK:
  2152. r = clk_get_rate(dispc.dss_clk);
  2153. break;
  2154. case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
  2155. dsidev = dsi_get_dsidev_from_id(0);
  2156. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2157. break;
  2158. case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
  2159. dsidev = dsi_get_dsidev_from_id(1);
  2160. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2161. break;
  2162. default:
  2163. BUG();
  2164. }
  2165. return r;
  2166. }
  2167. unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
  2168. {
  2169. struct platform_device *dsidev;
  2170. int lcd;
  2171. unsigned long r;
  2172. u32 l;
  2173. l = dispc_read_reg(DISPC_DIVISORo(channel));
  2174. lcd = FLD_GET(l, 23, 16);
  2175. switch (dss_get_lcd_clk_source(channel)) {
  2176. case OMAP_DSS_CLK_SRC_FCK:
  2177. r = clk_get_rate(dispc.dss_clk);
  2178. break;
  2179. case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
  2180. dsidev = dsi_get_dsidev_from_id(0);
  2181. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2182. break;
  2183. case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
  2184. dsidev = dsi_get_dsidev_from_id(1);
  2185. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2186. break;
  2187. default:
  2188. BUG();
  2189. }
  2190. return r / lcd;
  2191. }
  2192. unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
  2193. {
  2194. unsigned long r;
  2195. if (dispc_mgr_is_lcd(channel)) {
  2196. int pcd;
  2197. u32 l;
  2198. l = dispc_read_reg(DISPC_DIVISORo(channel));
  2199. pcd = FLD_GET(l, 7, 0);
  2200. r = dispc_mgr_lclk_rate(channel);
  2201. return r / pcd;
  2202. } else {
  2203. enum dss_hdmi_venc_clk_source_select source;
  2204. source = dss_get_hdmi_venc_clk_source();
  2205. switch (source) {
  2206. case DSS_VENC_TV_CLK:
  2207. return venc_get_pixel_clock();
  2208. case DSS_HDMI_M_PCLK:
  2209. return hdmi_get_pixel_clock();
  2210. default:
  2211. BUG();
  2212. }
  2213. }
  2214. }
  2215. unsigned long dispc_core_clk_rate(void)
  2216. {
  2217. int lcd;
  2218. unsigned long fclk = dispc_fclk_rate();
  2219. if (dss_has_feature(FEAT_CORE_CLK_DIV))
  2220. lcd = REG_GET(DISPC_DIVISOR, 23, 16);
  2221. else
  2222. lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
  2223. return fclk / lcd;
  2224. }
  2225. void dispc_dump_clocks(struct seq_file *s)
  2226. {
  2227. int lcd, pcd;
  2228. u32 l;
  2229. enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
  2230. enum omap_dss_clk_source lcd_clk_src;
  2231. if (dispc_runtime_get())
  2232. return;
  2233. seq_printf(s, "- DISPC -\n");
  2234. seq_printf(s, "dispc fclk source = %s (%s)\n",
  2235. dss_get_generic_clk_source_name(dispc_clk_src),
  2236. dss_feat_get_clk_source_name(dispc_clk_src));
  2237. seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
  2238. if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
  2239. seq_printf(s, "- DISPC-CORE-CLK -\n");
  2240. l = dispc_read_reg(DISPC_DIVISOR);
  2241. lcd = FLD_GET(l, 23, 16);
  2242. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2243. (dispc_fclk_rate()/lcd), lcd);
  2244. }
  2245. seq_printf(s, "- LCD1 -\n");
  2246. lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD);
  2247. seq_printf(s, "lcd1_clk source = %s (%s)\n",
  2248. dss_get_generic_clk_source_name(lcd_clk_src),
  2249. dss_feat_get_clk_source_name(lcd_clk_src));
  2250. dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
  2251. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2252. dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
  2253. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2254. dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
  2255. if (dss_has_feature(FEAT_MGR_LCD2)) {
  2256. seq_printf(s, "- LCD2 -\n");
  2257. lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD2);
  2258. seq_printf(s, "lcd2_clk source = %s (%s)\n",
  2259. dss_get_generic_clk_source_name(lcd_clk_src),
  2260. dss_feat_get_clk_source_name(lcd_clk_src));
  2261. dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
  2262. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2263. dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
  2264. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2265. dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
  2266. }
  2267. dispc_runtime_put();
  2268. }
  2269. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2270. void dispc_dump_irqs(struct seq_file *s)
  2271. {
  2272. unsigned long flags;
  2273. struct dispc_irq_stats stats;
  2274. spin_lock_irqsave(&dispc.irq_stats_lock, flags);
  2275. stats = dispc.irq_stats;
  2276. memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
  2277. dispc.irq_stats.last_reset = jiffies;
  2278. spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
  2279. seq_printf(s, "period %u ms\n",
  2280. jiffies_to_msecs(jiffies - stats.last_reset));
  2281. seq_printf(s, "irqs %d\n", stats.irq_count);
  2282. #define PIS(x) \
  2283. seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
  2284. PIS(FRAMEDONE);
  2285. PIS(VSYNC);
  2286. PIS(EVSYNC_EVEN);
  2287. PIS(EVSYNC_ODD);
  2288. PIS(ACBIAS_COUNT_STAT);
  2289. PIS(PROG_LINE_NUM);
  2290. PIS(GFX_FIFO_UNDERFLOW);
  2291. PIS(GFX_END_WIN);
  2292. PIS(PAL_GAMMA_MASK);
  2293. PIS(OCP_ERR);
  2294. PIS(VID1_FIFO_UNDERFLOW);
  2295. PIS(VID1_END_WIN);
  2296. PIS(VID2_FIFO_UNDERFLOW);
  2297. PIS(VID2_END_WIN);
  2298. if (dss_feat_get_num_ovls() > 3) {
  2299. PIS(VID3_FIFO_UNDERFLOW);
  2300. PIS(VID3_END_WIN);
  2301. }
  2302. PIS(SYNC_LOST);
  2303. PIS(SYNC_LOST_DIGIT);
  2304. PIS(WAKEUP);
  2305. if (dss_has_feature(FEAT_MGR_LCD2)) {
  2306. PIS(FRAMEDONE2);
  2307. PIS(VSYNC2);
  2308. PIS(ACBIAS_COUNT_STAT2);
  2309. PIS(SYNC_LOST2);
  2310. }
  2311. #undef PIS
  2312. }
  2313. #endif
  2314. void dispc_dump_regs(struct seq_file *s)
  2315. {
  2316. int i, j;
  2317. const char *mgr_names[] = {
  2318. [OMAP_DSS_CHANNEL_LCD] = "LCD",
  2319. [OMAP_DSS_CHANNEL_DIGIT] = "TV",
  2320. [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
  2321. };
  2322. const char *ovl_names[] = {
  2323. [OMAP_DSS_GFX] = "GFX",
  2324. [OMAP_DSS_VIDEO1] = "VID1",
  2325. [OMAP_DSS_VIDEO2] = "VID2",
  2326. [OMAP_DSS_VIDEO3] = "VID3",
  2327. };
  2328. const char **p_names;
  2329. #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
  2330. if (dispc_runtime_get())
  2331. return;
  2332. /* DISPC common registers */
  2333. DUMPREG(DISPC_REVISION);
  2334. DUMPREG(DISPC_SYSCONFIG);
  2335. DUMPREG(DISPC_SYSSTATUS);
  2336. DUMPREG(DISPC_IRQSTATUS);
  2337. DUMPREG(DISPC_IRQENABLE);
  2338. DUMPREG(DISPC_CONTROL);
  2339. DUMPREG(DISPC_CONFIG);
  2340. DUMPREG(DISPC_CAPABLE);
  2341. DUMPREG(DISPC_LINE_STATUS);
  2342. DUMPREG(DISPC_LINE_NUMBER);
  2343. if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
  2344. dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
  2345. DUMPREG(DISPC_GLOBAL_ALPHA);
  2346. if (dss_has_feature(FEAT_MGR_LCD2)) {
  2347. DUMPREG(DISPC_CONTROL2);
  2348. DUMPREG(DISPC_CONFIG2);
  2349. }
  2350. #undef DUMPREG
  2351. #define DISPC_REG(i, name) name(i)
  2352. #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
  2353. 48 - strlen(#r) - strlen(p_names[i]), " ", \
  2354. dispc_read_reg(DISPC_REG(i, r)))
  2355. p_names = mgr_names;
  2356. /* DISPC channel specific registers */
  2357. for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
  2358. DUMPREG(i, DISPC_DEFAULT_COLOR);
  2359. DUMPREG(i, DISPC_TRANS_COLOR);
  2360. DUMPREG(i, DISPC_SIZE_MGR);
  2361. if (i == OMAP_DSS_CHANNEL_DIGIT)
  2362. continue;
  2363. DUMPREG(i, DISPC_DEFAULT_COLOR);
  2364. DUMPREG(i, DISPC_TRANS_COLOR);
  2365. DUMPREG(i, DISPC_TIMING_H);
  2366. DUMPREG(i, DISPC_TIMING_V);
  2367. DUMPREG(i, DISPC_POL_FREQ);
  2368. DUMPREG(i, DISPC_DIVISORo);
  2369. DUMPREG(i, DISPC_SIZE_MGR);
  2370. DUMPREG(i, DISPC_DATA_CYCLE1);
  2371. DUMPREG(i, DISPC_DATA_CYCLE2);
  2372. DUMPREG(i, DISPC_DATA_CYCLE3);
  2373. if (dss_has_feature(FEAT_CPR)) {
  2374. DUMPREG(i, DISPC_CPR_COEF_R);
  2375. DUMPREG(i, DISPC_CPR_COEF_G);
  2376. DUMPREG(i, DISPC_CPR_COEF_B);
  2377. }
  2378. }
  2379. p_names = ovl_names;
  2380. for (i = 0; i < dss_feat_get_num_ovls(); i++) {
  2381. DUMPREG(i, DISPC_OVL_BA0);
  2382. DUMPREG(i, DISPC_OVL_BA1);
  2383. DUMPREG(i, DISPC_OVL_POSITION);
  2384. DUMPREG(i, DISPC_OVL_SIZE);
  2385. DUMPREG(i, DISPC_OVL_ATTRIBUTES);
  2386. DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
  2387. DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
  2388. DUMPREG(i, DISPC_OVL_ROW_INC);
  2389. DUMPREG(i, DISPC_OVL_PIXEL_INC);
  2390. if (dss_has_feature(FEAT_PRELOAD))
  2391. DUMPREG(i, DISPC_OVL_PRELOAD);
  2392. if (i == OMAP_DSS_GFX) {
  2393. DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
  2394. DUMPREG(i, DISPC_OVL_TABLE_BA);
  2395. continue;
  2396. }
  2397. DUMPREG(i, DISPC_OVL_FIR);
  2398. DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
  2399. DUMPREG(i, DISPC_OVL_ACCU0);
  2400. DUMPREG(i, DISPC_OVL_ACCU1);
  2401. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  2402. DUMPREG(i, DISPC_OVL_BA0_UV);
  2403. DUMPREG(i, DISPC_OVL_BA1_UV);
  2404. DUMPREG(i, DISPC_OVL_FIR2);
  2405. DUMPREG(i, DISPC_OVL_ACCU2_0);
  2406. DUMPREG(i, DISPC_OVL_ACCU2_1);
  2407. }
  2408. if (dss_has_feature(FEAT_ATTR2))
  2409. DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
  2410. if (dss_has_feature(FEAT_PRELOAD))
  2411. DUMPREG(i, DISPC_OVL_PRELOAD);
  2412. }
  2413. #undef DISPC_REG
  2414. #undef DUMPREG
  2415. #define DISPC_REG(plane, name, i) name(plane, i)
  2416. #define DUMPREG(plane, name, i) \
  2417. seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
  2418. 46 - strlen(#name) - strlen(p_names[plane]), " ", \
  2419. dispc_read_reg(DISPC_REG(plane, name, i)))
  2420. /* Video pipeline coefficient registers */
  2421. /* start from OMAP_DSS_VIDEO1 */
  2422. for (i = 1; i < dss_feat_get_num_ovls(); i++) {
  2423. for (j = 0; j < 8; j++)
  2424. DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
  2425. for (j = 0; j < 8; j++)
  2426. DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
  2427. for (j = 0; j < 5; j++)
  2428. DUMPREG(i, DISPC_OVL_CONV_COEF, j);
  2429. if (dss_has_feature(FEAT_FIR_COEF_V)) {
  2430. for (j = 0; j < 8; j++)
  2431. DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
  2432. }
  2433. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  2434. for (j = 0; j < 8; j++)
  2435. DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
  2436. for (j = 0; j < 8; j++)
  2437. DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
  2438. for (j = 0; j < 8; j++)
  2439. DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
  2440. }
  2441. }
  2442. dispc_runtime_put();
  2443. #undef DISPC_REG
  2444. #undef DUMPREG
  2445. }
  2446. static void _dispc_mgr_set_pol_freq(enum omap_channel channel, bool onoff,
  2447. bool rf, bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi,
  2448. u8 acb)
  2449. {
  2450. u32 l = 0;
  2451. DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n",
  2452. onoff, rf, ieo, ipc, ihs, ivs, acbi, acb);
  2453. l |= FLD_VAL(onoff, 17, 17);
  2454. l |= FLD_VAL(rf, 16, 16);
  2455. l |= FLD_VAL(ieo, 15, 15);
  2456. l |= FLD_VAL(ipc, 14, 14);
  2457. l |= FLD_VAL(ihs, 13, 13);
  2458. l |= FLD_VAL(ivs, 12, 12);
  2459. l |= FLD_VAL(acbi, 11, 8);
  2460. l |= FLD_VAL(acb, 7, 0);
  2461. dispc_write_reg(DISPC_POL_FREQ(channel), l);
  2462. }
  2463. void dispc_mgr_set_pol_freq(enum omap_channel channel,
  2464. enum omap_panel_config config, u8 acbi, u8 acb)
  2465. {
  2466. _dispc_mgr_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
  2467. (config & OMAP_DSS_LCD_RF) != 0,
  2468. (config & OMAP_DSS_LCD_IEO) != 0,
  2469. (config & OMAP_DSS_LCD_IPC) != 0,
  2470. (config & OMAP_DSS_LCD_IHS) != 0,
  2471. (config & OMAP_DSS_LCD_IVS) != 0,
  2472. acbi, acb);
  2473. }
  2474. /* with fck as input clock rate, find dispc dividers that produce req_pck */
  2475. void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
  2476. struct dispc_clock_info *cinfo)
  2477. {
  2478. u16 pcd_min, pcd_max;
  2479. unsigned long best_pck;
  2480. u16 best_ld, cur_ld;
  2481. u16 best_pd, cur_pd;
  2482. pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
  2483. pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
  2484. if (!is_tft)
  2485. pcd_min = 3;
  2486. best_pck = 0;
  2487. best_ld = 0;
  2488. best_pd = 0;
  2489. for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
  2490. unsigned long lck = fck / cur_ld;
  2491. for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
  2492. unsigned long pck = lck / cur_pd;
  2493. long old_delta = abs(best_pck - req_pck);
  2494. long new_delta = abs(pck - req_pck);
  2495. if (best_pck == 0 || new_delta < old_delta) {
  2496. best_pck = pck;
  2497. best_ld = cur_ld;
  2498. best_pd = cur_pd;
  2499. if (pck == req_pck)
  2500. goto found;
  2501. }
  2502. if (pck < req_pck)
  2503. break;
  2504. }
  2505. if (lck / pcd_min < req_pck)
  2506. break;
  2507. }
  2508. found:
  2509. cinfo->lck_div = best_ld;
  2510. cinfo->pck_div = best_pd;
  2511. cinfo->lck = fck / cinfo->lck_div;
  2512. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2513. }
  2514. /* calculate clock rates using dividers in cinfo */
  2515. int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
  2516. struct dispc_clock_info *cinfo)
  2517. {
  2518. if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
  2519. return -EINVAL;
  2520. if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
  2521. return -EINVAL;
  2522. cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
  2523. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2524. return 0;
  2525. }
  2526. int dispc_mgr_set_clock_div(enum omap_channel channel,
  2527. struct dispc_clock_info *cinfo)
  2528. {
  2529. DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
  2530. DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
  2531. dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
  2532. return 0;
  2533. }
  2534. int dispc_mgr_get_clock_div(enum omap_channel channel,
  2535. struct dispc_clock_info *cinfo)
  2536. {
  2537. unsigned long fck;
  2538. fck = dispc_fclk_rate();
  2539. cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
  2540. cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
  2541. cinfo->lck = fck / cinfo->lck_div;
  2542. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2543. return 0;
  2544. }
  2545. /* dispc.irq_lock has to be locked by the caller */
  2546. static void _omap_dispc_set_irqs(void)
  2547. {
  2548. u32 mask;
  2549. u32 old_mask;
  2550. int i;
  2551. struct omap_dispc_isr_data *isr_data;
  2552. mask = dispc.irq_error_mask;
  2553. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2554. isr_data = &dispc.registered_isr[i];
  2555. if (isr_data->isr == NULL)
  2556. continue;
  2557. mask |= isr_data->mask;
  2558. }
  2559. old_mask = dispc_read_reg(DISPC_IRQENABLE);
  2560. /* clear the irqstatus for newly enabled irqs */
  2561. dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
  2562. dispc_write_reg(DISPC_IRQENABLE, mask);
  2563. }
  2564. int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
  2565. {
  2566. int i;
  2567. int ret;
  2568. unsigned long flags;
  2569. struct omap_dispc_isr_data *isr_data;
  2570. if (isr == NULL)
  2571. return -EINVAL;
  2572. spin_lock_irqsave(&dispc.irq_lock, flags);
  2573. /* check for duplicate entry */
  2574. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2575. isr_data = &dispc.registered_isr[i];
  2576. if (isr_data->isr == isr && isr_data->arg == arg &&
  2577. isr_data->mask == mask) {
  2578. ret = -EINVAL;
  2579. goto err;
  2580. }
  2581. }
  2582. isr_data = NULL;
  2583. ret = -EBUSY;
  2584. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2585. isr_data = &dispc.registered_isr[i];
  2586. if (isr_data->isr != NULL)
  2587. continue;
  2588. isr_data->isr = isr;
  2589. isr_data->arg = arg;
  2590. isr_data->mask = mask;
  2591. ret = 0;
  2592. break;
  2593. }
  2594. if (ret)
  2595. goto err;
  2596. _omap_dispc_set_irqs();
  2597. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2598. return 0;
  2599. err:
  2600. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2601. return ret;
  2602. }
  2603. EXPORT_SYMBOL(omap_dispc_register_isr);
  2604. int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
  2605. {
  2606. int i;
  2607. unsigned long flags;
  2608. int ret = -EINVAL;
  2609. struct omap_dispc_isr_data *isr_data;
  2610. spin_lock_irqsave(&dispc.irq_lock, flags);
  2611. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2612. isr_data = &dispc.registered_isr[i];
  2613. if (isr_data->isr != isr || isr_data->arg != arg ||
  2614. isr_data->mask != mask)
  2615. continue;
  2616. /* found the correct isr */
  2617. isr_data->isr = NULL;
  2618. isr_data->arg = NULL;
  2619. isr_data->mask = 0;
  2620. ret = 0;
  2621. break;
  2622. }
  2623. if (ret == 0)
  2624. _omap_dispc_set_irqs();
  2625. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2626. return ret;
  2627. }
  2628. EXPORT_SYMBOL(omap_dispc_unregister_isr);
  2629. #ifdef DEBUG
  2630. static void print_irq_status(u32 status)
  2631. {
  2632. if ((status & dispc.irq_error_mask) == 0)
  2633. return;
  2634. printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
  2635. #define PIS(x) \
  2636. if (status & DISPC_IRQ_##x) \
  2637. printk(#x " ");
  2638. PIS(GFX_FIFO_UNDERFLOW);
  2639. PIS(OCP_ERR);
  2640. PIS(VID1_FIFO_UNDERFLOW);
  2641. PIS(VID2_FIFO_UNDERFLOW);
  2642. if (dss_feat_get_num_ovls() > 3)
  2643. PIS(VID3_FIFO_UNDERFLOW);
  2644. PIS(SYNC_LOST);
  2645. PIS(SYNC_LOST_DIGIT);
  2646. if (dss_has_feature(FEAT_MGR_LCD2))
  2647. PIS(SYNC_LOST2);
  2648. #undef PIS
  2649. printk("\n");
  2650. }
  2651. #endif
  2652. /* Called from dss.c. Note that we don't touch clocks here,
  2653. * but we presume they are on because we got an IRQ. However,
  2654. * an irq handler may turn the clocks off, so we may not have
  2655. * clock later in the function. */
  2656. static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
  2657. {
  2658. int i;
  2659. u32 irqstatus, irqenable;
  2660. u32 handledirqs = 0;
  2661. u32 unhandled_errors;
  2662. struct omap_dispc_isr_data *isr_data;
  2663. struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
  2664. spin_lock(&dispc.irq_lock);
  2665. irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
  2666. irqenable = dispc_read_reg(DISPC_IRQENABLE);
  2667. /* IRQ is not for us */
  2668. if (!(irqstatus & irqenable)) {
  2669. spin_unlock(&dispc.irq_lock);
  2670. return IRQ_NONE;
  2671. }
  2672. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2673. spin_lock(&dispc.irq_stats_lock);
  2674. dispc.irq_stats.irq_count++;
  2675. dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
  2676. spin_unlock(&dispc.irq_stats_lock);
  2677. #endif
  2678. #ifdef DEBUG
  2679. if (dss_debug)
  2680. print_irq_status(irqstatus);
  2681. #endif
  2682. /* Ack the interrupt. Do it here before clocks are possibly turned
  2683. * off */
  2684. dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
  2685. /* flush posted write */
  2686. dispc_read_reg(DISPC_IRQSTATUS);
  2687. /* make a copy and unlock, so that isrs can unregister
  2688. * themselves */
  2689. memcpy(registered_isr, dispc.registered_isr,
  2690. sizeof(registered_isr));
  2691. spin_unlock(&dispc.irq_lock);
  2692. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2693. isr_data = &registered_isr[i];
  2694. if (!isr_data->isr)
  2695. continue;
  2696. if (isr_data->mask & irqstatus) {
  2697. isr_data->isr(isr_data->arg, irqstatus);
  2698. handledirqs |= isr_data->mask;
  2699. }
  2700. }
  2701. spin_lock(&dispc.irq_lock);
  2702. unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
  2703. if (unhandled_errors) {
  2704. dispc.error_irqs |= unhandled_errors;
  2705. dispc.irq_error_mask &= ~unhandled_errors;
  2706. _omap_dispc_set_irqs();
  2707. schedule_work(&dispc.error_work);
  2708. }
  2709. spin_unlock(&dispc.irq_lock);
  2710. return IRQ_HANDLED;
  2711. }
  2712. static void dispc_error_worker(struct work_struct *work)
  2713. {
  2714. int i;
  2715. u32 errors;
  2716. unsigned long flags;
  2717. static const unsigned fifo_underflow_bits[] = {
  2718. DISPC_IRQ_GFX_FIFO_UNDERFLOW,
  2719. DISPC_IRQ_VID1_FIFO_UNDERFLOW,
  2720. DISPC_IRQ_VID2_FIFO_UNDERFLOW,
  2721. DISPC_IRQ_VID3_FIFO_UNDERFLOW,
  2722. };
  2723. static const unsigned sync_lost_bits[] = {
  2724. DISPC_IRQ_SYNC_LOST,
  2725. DISPC_IRQ_SYNC_LOST_DIGIT,
  2726. DISPC_IRQ_SYNC_LOST2,
  2727. };
  2728. spin_lock_irqsave(&dispc.irq_lock, flags);
  2729. errors = dispc.error_irqs;
  2730. dispc.error_irqs = 0;
  2731. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2732. dispc_runtime_get();
  2733. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  2734. struct omap_overlay *ovl;
  2735. unsigned bit;
  2736. ovl = omap_dss_get_overlay(i);
  2737. bit = fifo_underflow_bits[i];
  2738. if (bit & errors) {
  2739. DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
  2740. ovl->name);
  2741. dispc_ovl_enable(ovl->id, false);
  2742. dispc_mgr_go(ovl->manager->id);
  2743. mdelay(50);
  2744. }
  2745. }
  2746. for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
  2747. struct omap_overlay_manager *mgr;
  2748. unsigned bit;
  2749. mgr = omap_dss_get_overlay_manager(i);
  2750. bit = sync_lost_bits[i];
  2751. if (bit & errors) {
  2752. struct omap_dss_device *dssdev = mgr->device;
  2753. bool enable;
  2754. DSSERR("SYNC_LOST on channel %s, restarting the output "
  2755. "with video overlays disabled\n",
  2756. mgr->name);
  2757. enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
  2758. dssdev->driver->disable(dssdev);
  2759. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  2760. struct omap_overlay *ovl;
  2761. ovl = omap_dss_get_overlay(i);
  2762. if (ovl->id != OMAP_DSS_GFX &&
  2763. ovl->manager == mgr)
  2764. dispc_ovl_enable(ovl->id, false);
  2765. }
  2766. dispc_mgr_go(mgr->id);
  2767. mdelay(50);
  2768. if (enable)
  2769. dssdev->driver->enable(dssdev);
  2770. }
  2771. }
  2772. if (errors & DISPC_IRQ_OCP_ERR) {
  2773. DSSERR("OCP_ERR\n");
  2774. for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
  2775. struct omap_overlay_manager *mgr;
  2776. mgr = omap_dss_get_overlay_manager(i);
  2777. if (mgr->device && mgr->device->driver)
  2778. mgr->device->driver->disable(mgr->device);
  2779. }
  2780. }
  2781. spin_lock_irqsave(&dispc.irq_lock, flags);
  2782. dispc.irq_error_mask |= errors;
  2783. _omap_dispc_set_irqs();
  2784. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2785. dispc_runtime_put();
  2786. }
  2787. int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
  2788. {
  2789. void dispc_irq_wait_handler(void *data, u32 mask)
  2790. {
  2791. complete((struct completion *)data);
  2792. }
  2793. int r;
  2794. DECLARE_COMPLETION_ONSTACK(completion);
  2795. r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
  2796. irqmask);
  2797. if (r)
  2798. return r;
  2799. timeout = wait_for_completion_timeout(&completion, timeout);
  2800. omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
  2801. if (timeout == 0)
  2802. return -ETIMEDOUT;
  2803. if (timeout == -ERESTARTSYS)
  2804. return -ERESTARTSYS;
  2805. return 0;
  2806. }
  2807. int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
  2808. unsigned long timeout)
  2809. {
  2810. void dispc_irq_wait_handler(void *data, u32 mask)
  2811. {
  2812. complete((struct completion *)data);
  2813. }
  2814. int r;
  2815. DECLARE_COMPLETION_ONSTACK(completion);
  2816. r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
  2817. irqmask);
  2818. if (r)
  2819. return r;
  2820. timeout = wait_for_completion_interruptible_timeout(&completion,
  2821. timeout);
  2822. omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
  2823. if (timeout == 0)
  2824. return -ETIMEDOUT;
  2825. if (timeout == -ERESTARTSYS)
  2826. return -ERESTARTSYS;
  2827. return 0;
  2828. }
  2829. static void _omap_dispc_initialize_irq(void)
  2830. {
  2831. unsigned long flags;
  2832. spin_lock_irqsave(&dispc.irq_lock, flags);
  2833. memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
  2834. dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
  2835. if (dss_has_feature(FEAT_MGR_LCD2))
  2836. dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
  2837. if (dss_feat_get_num_ovls() > 3)
  2838. dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
  2839. /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
  2840. * so clear it */
  2841. dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
  2842. _omap_dispc_set_irqs();
  2843. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2844. }
  2845. void dispc_enable_sidle(void)
  2846. {
  2847. REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
  2848. }
  2849. void dispc_disable_sidle(void)
  2850. {
  2851. REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
  2852. }
  2853. static void _omap_dispc_initial_config(void)
  2854. {
  2855. u32 l;
  2856. /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
  2857. if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
  2858. l = dispc_read_reg(DISPC_DIVISOR);
  2859. /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
  2860. l = FLD_MOD(l, 1, 0, 0);
  2861. l = FLD_MOD(l, 1, 23, 16);
  2862. dispc_write_reg(DISPC_DIVISOR, l);
  2863. }
  2864. /* FUNCGATED */
  2865. if (dss_has_feature(FEAT_FUNCGATED))
  2866. REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
  2867. _dispc_setup_color_conv_coef();
  2868. dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
  2869. dispc_read_plane_fifo_sizes();
  2870. dispc_configure_burst_sizes();
  2871. dispc_ovl_enable_zorder_planes();
  2872. }
  2873. /* DISPC HW IP initialisation */
  2874. static int omap_dispchw_probe(struct platform_device *pdev)
  2875. {
  2876. u32 rev;
  2877. int r = 0;
  2878. struct resource *dispc_mem;
  2879. struct clk *clk;
  2880. dispc.pdev = pdev;
  2881. spin_lock_init(&dispc.irq_lock);
  2882. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2883. spin_lock_init(&dispc.irq_stats_lock);
  2884. dispc.irq_stats.last_reset = jiffies;
  2885. #endif
  2886. INIT_WORK(&dispc.error_work, dispc_error_worker);
  2887. dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
  2888. if (!dispc_mem) {
  2889. DSSERR("can't get IORESOURCE_MEM DISPC\n");
  2890. return -EINVAL;
  2891. }
  2892. dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
  2893. resource_size(dispc_mem));
  2894. if (!dispc.base) {
  2895. DSSERR("can't ioremap DISPC\n");
  2896. return -ENOMEM;
  2897. }
  2898. dispc.irq = platform_get_irq(dispc.pdev, 0);
  2899. if (dispc.irq < 0) {
  2900. DSSERR("platform_get_irq failed\n");
  2901. return -ENODEV;
  2902. }
  2903. r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
  2904. IRQF_SHARED, "OMAP DISPC", dispc.pdev);
  2905. if (r < 0) {
  2906. DSSERR("request_irq failed\n");
  2907. return r;
  2908. }
  2909. clk = clk_get(&pdev->dev, "fck");
  2910. if (IS_ERR(clk)) {
  2911. DSSERR("can't get fck\n");
  2912. r = PTR_ERR(clk);
  2913. return r;
  2914. }
  2915. dispc.dss_clk = clk;
  2916. pm_runtime_enable(&pdev->dev);
  2917. r = dispc_runtime_get();
  2918. if (r)
  2919. goto err_runtime_get;
  2920. _omap_dispc_initial_config();
  2921. _omap_dispc_initialize_irq();
  2922. rev = dispc_read_reg(DISPC_REVISION);
  2923. dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
  2924. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  2925. dispc_runtime_put();
  2926. return 0;
  2927. err_runtime_get:
  2928. pm_runtime_disable(&pdev->dev);
  2929. clk_put(dispc.dss_clk);
  2930. return r;
  2931. }
  2932. static int omap_dispchw_remove(struct platform_device *pdev)
  2933. {
  2934. pm_runtime_disable(&pdev->dev);
  2935. clk_put(dispc.dss_clk);
  2936. return 0;
  2937. }
  2938. static int dispc_runtime_suspend(struct device *dev)
  2939. {
  2940. dispc_save_context();
  2941. dss_runtime_put();
  2942. return 0;
  2943. }
  2944. static int dispc_runtime_resume(struct device *dev)
  2945. {
  2946. int r;
  2947. r = dss_runtime_get();
  2948. if (r < 0)
  2949. return r;
  2950. dispc_restore_context();
  2951. return 0;
  2952. }
  2953. static const struct dev_pm_ops dispc_pm_ops = {
  2954. .runtime_suspend = dispc_runtime_suspend,
  2955. .runtime_resume = dispc_runtime_resume,
  2956. };
  2957. static struct platform_driver omap_dispchw_driver = {
  2958. .probe = omap_dispchw_probe,
  2959. .remove = omap_dispchw_remove,
  2960. .driver = {
  2961. .name = "omapdss_dispc",
  2962. .owner = THIS_MODULE,
  2963. .pm = &dispc_pm_ops,
  2964. },
  2965. };
  2966. int dispc_init_platform_driver(void)
  2967. {
  2968. return platform_driver_register(&omap_dispchw_driver);
  2969. }
  2970. void dispc_uninit_platform_driver(void)
  2971. {
  2972. return platform_driver_unregister(&omap_dispchw_driver);
  2973. }