dispc.c 79 KB

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