dispc.c 80 KB

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