dispc.c 80 KB

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