dispc.c 80 KB

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