dispc.c 80 KB

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