dispc.c 80 KB

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