dispc.c 77 KB

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