dispc.c 80 KB

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