dispc.c 79 KB

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