dispc.c 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434
  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. 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. 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. static void dispc_ovl_set_fir(enum omap_plane plane,
  875. int hinc, int vinc,
  876. enum omap_color_component color_comp)
  877. {
  878. u32 val;
  879. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  880. u8 hinc_start, hinc_end, vinc_start, vinc_end;
  881. dss_feat_get_reg_field(FEAT_REG_FIRHINC,
  882. &hinc_start, &hinc_end);
  883. dss_feat_get_reg_field(FEAT_REG_FIRVINC,
  884. &vinc_start, &vinc_end);
  885. val = FLD_VAL(vinc, vinc_start, vinc_end) |
  886. FLD_VAL(hinc, hinc_start, hinc_end);
  887. dispc_write_reg(DISPC_OVL_FIR(plane), val);
  888. } else {
  889. val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
  890. dispc_write_reg(DISPC_OVL_FIR2(plane), val);
  891. }
  892. }
  893. static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
  894. {
  895. u32 val;
  896. u8 hor_start, hor_end, vert_start, vert_end;
  897. dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
  898. dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
  899. val = FLD_VAL(vaccu, vert_start, vert_end) |
  900. FLD_VAL(haccu, hor_start, hor_end);
  901. dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
  902. }
  903. static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
  904. {
  905. u32 val;
  906. u8 hor_start, hor_end, vert_start, vert_end;
  907. dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
  908. dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
  909. val = FLD_VAL(vaccu, vert_start, vert_end) |
  910. FLD_VAL(haccu, hor_start, hor_end);
  911. dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
  912. }
  913. static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
  914. int vaccu)
  915. {
  916. u32 val;
  917. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  918. dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
  919. }
  920. static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
  921. int vaccu)
  922. {
  923. u32 val;
  924. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  925. dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
  926. }
  927. static void dispc_ovl_set_scale_param(enum omap_plane plane,
  928. u16 orig_width, u16 orig_height,
  929. u16 out_width, u16 out_height,
  930. bool five_taps, u8 rotation,
  931. enum omap_color_component color_comp)
  932. {
  933. int fir_hinc, fir_vinc;
  934. fir_hinc = 1024 * orig_width / out_width;
  935. fir_vinc = 1024 * orig_height / out_height;
  936. dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
  937. color_comp);
  938. dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
  939. }
  940. static void dispc_ovl_set_scaling_common(enum omap_plane plane,
  941. u16 orig_width, u16 orig_height,
  942. u16 out_width, u16 out_height,
  943. bool ilace, bool five_taps,
  944. bool fieldmode, enum omap_color_mode color_mode,
  945. u8 rotation)
  946. {
  947. int accu0 = 0;
  948. int accu1 = 0;
  949. u32 l;
  950. dispc_ovl_set_scale_param(plane, orig_width, orig_height,
  951. out_width, out_height, five_taps,
  952. rotation, DISPC_COLOR_COMPONENT_RGB_Y);
  953. l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
  954. /* RESIZEENABLE and VERTICALTAPS */
  955. l &= ~((0x3 << 5) | (0x1 << 21));
  956. l |= (orig_width != out_width) ? (1 << 5) : 0;
  957. l |= (orig_height != out_height) ? (1 << 6) : 0;
  958. l |= five_taps ? (1 << 21) : 0;
  959. /* VRESIZECONF and HRESIZECONF */
  960. if (dss_has_feature(FEAT_RESIZECONF)) {
  961. l &= ~(0x3 << 7);
  962. l |= (orig_width <= out_width) ? 0 : (1 << 7);
  963. l |= (orig_height <= out_height) ? 0 : (1 << 8);
  964. }
  965. /* LINEBUFFERSPLIT */
  966. if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
  967. l &= ~(0x1 << 22);
  968. l |= five_taps ? (1 << 22) : 0;
  969. }
  970. dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
  971. /*
  972. * field 0 = even field = bottom field
  973. * field 1 = odd field = top field
  974. */
  975. if (ilace && !fieldmode) {
  976. accu1 = 0;
  977. accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
  978. if (accu0 >= 1024/2) {
  979. accu1 = 1024/2;
  980. accu0 -= accu1;
  981. }
  982. }
  983. dispc_ovl_set_vid_accu0(plane, 0, accu0);
  984. dispc_ovl_set_vid_accu1(plane, 0, accu1);
  985. }
  986. static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
  987. u16 orig_width, u16 orig_height,
  988. u16 out_width, u16 out_height,
  989. bool ilace, bool five_taps,
  990. bool fieldmode, enum omap_color_mode color_mode,
  991. u8 rotation)
  992. {
  993. int scale_x = out_width != orig_width;
  994. int scale_y = out_height != orig_height;
  995. if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
  996. return;
  997. if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
  998. color_mode != OMAP_DSS_COLOR_UYVY &&
  999. color_mode != OMAP_DSS_COLOR_NV12)) {
  1000. /* reset chroma resampling for RGB formats */
  1001. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
  1002. return;
  1003. }
  1004. switch (color_mode) {
  1005. case OMAP_DSS_COLOR_NV12:
  1006. /* UV is subsampled by 2 vertically*/
  1007. orig_height >>= 1;
  1008. /* UV is subsampled by 2 horz.*/
  1009. orig_width >>= 1;
  1010. break;
  1011. case OMAP_DSS_COLOR_YUV2:
  1012. case OMAP_DSS_COLOR_UYVY:
  1013. /*For YUV422 with 90/270 rotation,
  1014. *we don't upsample chroma
  1015. */
  1016. if (rotation == OMAP_DSS_ROT_0 ||
  1017. rotation == OMAP_DSS_ROT_180)
  1018. /* UV is subsampled by 2 hrz*/
  1019. orig_width >>= 1;
  1020. /* must use FIR for YUV422 if rotated */
  1021. if (rotation != OMAP_DSS_ROT_0)
  1022. scale_x = scale_y = true;
  1023. break;
  1024. default:
  1025. BUG();
  1026. }
  1027. if (out_width != orig_width)
  1028. scale_x = true;
  1029. if (out_height != orig_height)
  1030. scale_y = true;
  1031. dispc_ovl_set_scale_param(plane, orig_width, orig_height,
  1032. out_width, out_height, five_taps,
  1033. rotation, DISPC_COLOR_COMPONENT_UV);
  1034. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
  1035. (scale_x || scale_y) ? 1 : 0, 8, 8);
  1036. /* set H scaling */
  1037. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
  1038. /* set V scaling */
  1039. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
  1040. dispc_ovl_set_vid_accu2_0(plane, 0x80, 0);
  1041. dispc_ovl_set_vid_accu2_1(plane, 0x80, 0);
  1042. }
  1043. static void dispc_ovl_set_scaling(enum omap_plane plane,
  1044. u16 orig_width, u16 orig_height,
  1045. u16 out_width, u16 out_height,
  1046. bool ilace, bool five_taps,
  1047. bool fieldmode, enum omap_color_mode color_mode,
  1048. u8 rotation)
  1049. {
  1050. BUG_ON(plane == OMAP_DSS_GFX);
  1051. dispc_ovl_set_scaling_common(plane,
  1052. orig_width, orig_height,
  1053. out_width, out_height,
  1054. ilace, five_taps,
  1055. fieldmode, color_mode,
  1056. rotation);
  1057. dispc_ovl_set_scaling_uv(plane,
  1058. orig_width, orig_height,
  1059. out_width, out_height,
  1060. ilace, five_taps,
  1061. fieldmode, color_mode,
  1062. rotation);
  1063. }
  1064. static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
  1065. bool mirroring, enum omap_color_mode color_mode)
  1066. {
  1067. bool row_repeat = false;
  1068. int vidrot = 0;
  1069. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1070. color_mode == OMAP_DSS_COLOR_UYVY) {
  1071. if (mirroring) {
  1072. switch (rotation) {
  1073. case OMAP_DSS_ROT_0:
  1074. vidrot = 2;
  1075. break;
  1076. case OMAP_DSS_ROT_90:
  1077. vidrot = 1;
  1078. break;
  1079. case OMAP_DSS_ROT_180:
  1080. vidrot = 0;
  1081. break;
  1082. case OMAP_DSS_ROT_270:
  1083. vidrot = 3;
  1084. break;
  1085. }
  1086. } else {
  1087. switch (rotation) {
  1088. case OMAP_DSS_ROT_0:
  1089. vidrot = 0;
  1090. break;
  1091. case OMAP_DSS_ROT_90:
  1092. vidrot = 1;
  1093. break;
  1094. case OMAP_DSS_ROT_180:
  1095. vidrot = 2;
  1096. break;
  1097. case OMAP_DSS_ROT_270:
  1098. vidrot = 3;
  1099. break;
  1100. }
  1101. }
  1102. if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
  1103. row_repeat = true;
  1104. else
  1105. row_repeat = false;
  1106. }
  1107. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
  1108. if (dss_has_feature(FEAT_ROWREPEATENABLE))
  1109. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
  1110. row_repeat ? 1 : 0, 18, 18);
  1111. }
  1112. static int color_mode_to_bpp(enum omap_color_mode color_mode)
  1113. {
  1114. switch (color_mode) {
  1115. case OMAP_DSS_COLOR_CLUT1:
  1116. return 1;
  1117. case OMAP_DSS_COLOR_CLUT2:
  1118. return 2;
  1119. case OMAP_DSS_COLOR_CLUT4:
  1120. return 4;
  1121. case OMAP_DSS_COLOR_CLUT8:
  1122. case OMAP_DSS_COLOR_NV12:
  1123. return 8;
  1124. case OMAP_DSS_COLOR_RGB12U:
  1125. case OMAP_DSS_COLOR_RGB16:
  1126. case OMAP_DSS_COLOR_ARGB16:
  1127. case OMAP_DSS_COLOR_YUV2:
  1128. case OMAP_DSS_COLOR_UYVY:
  1129. case OMAP_DSS_COLOR_RGBA16:
  1130. case OMAP_DSS_COLOR_RGBX16:
  1131. case OMAP_DSS_COLOR_ARGB16_1555:
  1132. case OMAP_DSS_COLOR_XRGB16_1555:
  1133. return 16;
  1134. case OMAP_DSS_COLOR_RGB24P:
  1135. return 24;
  1136. case OMAP_DSS_COLOR_RGB24U:
  1137. case OMAP_DSS_COLOR_ARGB32:
  1138. case OMAP_DSS_COLOR_RGBA32:
  1139. case OMAP_DSS_COLOR_RGBX32:
  1140. return 32;
  1141. default:
  1142. BUG();
  1143. }
  1144. }
  1145. static s32 pixinc(int pixels, u8 ps)
  1146. {
  1147. if (pixels == 1)
  1148. return 1;
  1149. else if (pixels > 1)
  1150. return 1 + (pixels - 1) * ps;
  1151. else if (pixels < 0)
  1152. return 1 - (-pixels + 1) * ps;
  1153. else
  1154. BUG();
  1155. }
  1156. static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
  1157. u16 screen_width,
  1158. u16 width, u16 height,
  1159. enum omap_color_mode color_mode, bool fieldmode,
  1160. unsigned int field_offset,
  1161. unsigned *offset0, unsigned *offset1,
  1162. s32 *row_inc, s32 *pix_inc)
  1163. {
  1164. u8 ps;
  1165. /* FIXME CLUT formats */
  1166. switch (color_mode) {
  1167. case OMAP_DSS_COLOR_CLUT1:
  1168. case OMAP_DSS_COLOR_CLUT2:
  1169. case OMAP_DSS_COLOR_CLUT4:
  1170. case OMAP_DSS_COLOR_CLUT8:
  1171. BUG();
  1172. return;
  1173. case OMAP_DSS_COLOR_YUV2:
  1174. case OMAP_DSS_COLOR_UYVY:
  1175. ps = 4;
  1176. break;
  1177. default:
  1178. ps = color_mode_to_bpp(color_mode) / 8;
  1179. break;
  1180. }
  1181. DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
  1182. width, height);
  1183. /*
  1184. * field 0 = even field = bottom field
  1185. * field 1 = odd field = top field
  1186. */
  1187. switch (rotation + mirror * 4) {
  1188. case OMAP_DSS_ROT_0:
  1189. case OMAP_DSS_ROT_180:
  1190. /*
  1191. * If the pixel format is YUV or UYVY divide the width
  1192. * of the image by 2 for 0 and 180 degree rotation.
  1193. */
  1194. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1195. color_mode == OMAP_DSS_COLOR_UYVY)
  1196. width = width >> 1;
  1197. case OMAP_DSS_ROT_90:
  1198. case OMAP_DSS_ROT_270:
  1199. *offset1 = 0;
  1200. if (field_offset)
  1201. *offset0 = field_offset * screen_width * ps;
  1202. else
  1203. *offset0 = 0;
  1204. *row_inc = pixinc(1 + (screen_width - width) +
  1205. (fieldmode ? screen_width : 0),
  1206. ps);
  1207. *pix_inc = pixinc(1, ps);
  1208. break;
  1209. case OMAP_DSS_ROT_0 + 4:
  1210. case OMAP_DSS_ROT_180 + 4:
  1211. /* If the pixel format is YUV or UYVY divide the width
  1212. * of the image by 2 for 0 degree and 180 degree
  1213. */
  1214. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1215. color_mode == OMAP_DSS_COLOR_UYVY)
  1216. width = width >> 1;
  1217. case OMAP_DSS_ROT_90 + 4:
  1218. case OMAP_DSS_ROT_270 + 4:
  1219. *offset1 = 0;
  1220. if (field_offset)
  1221. *offset0 = field_offset * screen_width * ps;
  1222. else
  1223. *offset0 = 0;
  1224. *row_inc = pixinc(1 - (screen_width + width) -
  1225. (fieldmode ? screen_width : 0),
  1226. ps);
  1227. *pix_inc = pixinc(1, ps);
  1228. break;
  1229. default:
  1230. BUG();
  1231. }
  1232. }
  1233. static void calc_dma_rotation_offset(u8 rotation, bool mirror,
  1234. u16 screen_width,
  1235. u16 width, u16 height,
  1236. enum omap_color_mode color_mode, bool fieldmode,
  1237. unsigned int field_offset,
  1238. unsigned *offset0, unsigned *offset1,
  1239. s32 *row_inc, s32 *pix_inc)
  1240. {
  1241. u8 ps;
  1242. u16 fbw, fbh;
  1243. /* FIXME CLUT formats */
  1244. switch (color_mode) {
  1245. case OMAP_DSS_COLOR_CLUT1:
  1246. case OMAP_DSS_COLOR_CLUT2:
  1247. case OMAP_DSS_COLOR_CLUT4:
  1248. case OMAP_DSS_COLOR_CLUT8:
  1249. BUG();
  1250. return;
  1251. default:
  1252. ps = color_mode_to_bpp(color_mode) / 8;
  1253. break;
  1254. }
  1255. DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
  1256. width, height);
  1257. /* width & height are overlay sizes, convert to fb sizes */
  1258. if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
  1259. fbw = width;
  1260. fbh = height;
  1261. } else {
  1262. fbw = height;
  1263. fbh = width;
  1264. }
  1265. /*
  1266. * field 0 = even field = bottom field
  1267. * field 1 = odd field = top field
  1268. */
  1269. switch (rotation + mirror * 4) {
  1270. case OMAP_DSS_ROT_0:
  1271. *offset1 = 0;
  1272. if (field_offset)
  1273. *offset0 = *offset1 + field_offset * screen_width * ps;
  1274. else
  1275. *offset0 = *offset1;
  1276. *row_inc = pixinc(1 + (screen_width - fbw) +
  1277. (fieldmode ? screen_width : 0),
  1278. ps);
  1279. *pix_inc = pixinc(1, ps);
  1280. break;
  1281. case OMAP_DSS_ROT_90:
  1282. *offset1 = screen_width * (fbh - 1) * ps;
  1283. if (field_offset)
  1284. *offset0 = *offset1 + field_offset * ps;
  1285. else
  1286. *offset0 = *offset1;
  1287. *row_inc = pixinc(screen_width * (fbh - 1) + 1 +
  1288. (fieldmode ? 1 : 0), ps);
  1289. *pix_inc = pixinc(-screen_width, ps);
  1290. break;
  1291. case OMAP_DSS_ROT_180:
  1292. *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
  1293. if (field_offset)
  1294. *offset0 = *offset1 - field_offset * screen_width * ps;
  1295. else
  1296. *offset0 = *offset1;
  1297. *row_inc = pixinc(-1 -
  1298. (screen_width - fbw) -
  1299. (fieldmode ? screen_width : 0),
  1300. ps);
  1301. *pix_inc = pixinc(-1, ps);
  1302. break;
  1303. case OMAP_DSS_ROT_270:
  1304. *offset1 = (fbw - 1) * ps;
  1305. if (field_offset)
  1306. *offset0 = *offset1 - field_offset * ps;
  1307. else
  1308. *offset0 = *offset1;
  1309. *row_inc = pixinc(-screen_width * (fbh - 1) - 1 -
  1310. (fieldmode ? 1 : 0), ps);
  1311. *pix_inc = pixinc(screen_width, ps);
  1312. break;
  1313. /* mirroring */
  1314. case OMAP_DSS_ROT_0 + 4:
  1315. *offset1 = (fbw - 1) * ps;
  1316. if (field_offset)
  1317. *offset0 = *offset1 + field_offset * screen_width * ps;
  1318. else
  1319. *offset0 = *offset1;
  1320. *row_inc = pixinc(screen_width * 2 - 1 +
  1321. (fieldmode ? screen_width : 0),
  1322. ps);
  1323. *pix_inc = pixinc(-1, ps);
  1324. break;
  1325. case OMAP_DSS_ROT_90 + 4:
  1326. *offset1 = 0;
  1327. if (field_offset)
  1328. *offset0 = *offset1 + field_offset * ps;
  1329. else
  1330. *offset0 = *offset1;
  1331. *row_inc = pixinc(-screen_width * (fbh - 1) + 1 +
  1332. (fieldmode ? 1 : 0),
  1333. ps);
  1334. *pix_inc = pixinc(screen_width, ps);
  1335. break;
  1336. case OMAP_DSS_ROT_180 + 4:
  1337. *offset1 = screen_width * (fbh - 1) * ps;
  1338. if (field_offset)
  1339. *offset0 = *offset1 - field_offset * screen_width * ps;
  1340. else
  1341. *offset0 = *offset1;
  1342. *row_inc = pixinc(1 - screen_width * 2 -
  1343. (fieldmode ? screen_width : 0),
  1344. ps);
  1345. *pix_inc = pixinc(1, ps);
  1346. break;
  1347. case OMAP_DSS_ROT_270 + 4:
  1348. *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
  1349. if (field_offset)
  1350. *offset0 = *offset1 - field_offset * ps;
  1351. else
  1352. *offset0 = *offset1;
  1353. *row_inc = pixinc(screen_width * (fbh - 1) - 1 -
  1354. (fieldmode ? 1 : 0),
  1355. ps);
  1356. *pix_inc = pixinc(-screen_width, ps);
  1357. break;
  1358. default:
  1359. BUG();
  1360. }
  1361. }
  1362. static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
  1363. u16 height, u16 out_width, u16 out_height,
  1364. enum omap_color_mode color_mode)
  1365. {
  1366. u32 fclk = 0;
  1367. u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
  1368. if (height <= out_height && width <= out_width)
  1369. return (unsigned long) pclk;
  1370. if (height > out_height) {
  1371. struct omap_dss_device *dssdev = dispc_mgr_get_device(channel);
  1372. unsigned int ppl = dssdev->panel.timings.x_res;
  1373. tmp = pclk * height * out_width;
  1374. do_div(tmp, 2 * out_height * ppl);
  1375. fclk = tmp;
  1376. if (height > 2 * out_height) {
  1377. if (ppl == out_width)
  1378. return 0;
  1379. tmp = pclk * (height - 2 * out_height) * out_width;
  1380. do_div(tmp, 2 * out_height * (ppl - out_width));
  1381. fclk = max(fclk, (u32) tmp);
  1382. }
  1383. }
  1384. if (width > out_width) {
  1385. tmp = pclk * width;
  1386. do_div(tmp, out_width);
  1387. fclk = max(fclk, (u32) tmp);
  1388. if (color_mode == OMAP_DSS_COLOR_RGB24U)
  1389. fclk <<= 1;
  1390. }
  1391. return fclk;
  1392. }
  1393. static unsigned long calc_fclk(enum omap_channel channel, u16 width,
  1394. u16 height, u16 out_width, u16 out_height)
  1395. {
  1396. unsigned int hf, vf;
  1397. /*
  1398. * FIXME how to determine the 'A' factor
  1399. * for the no downscaling case ?
  1400. */
  1401. if (width > 3 * out_width)
  1402. hf = 4;
  1403. else if (width > 2 * out_width)
  1404. hf = 3;
  1405. else if (width > out_width)
  1406. hf = 2;
  1407. else
  1408. hf = 1;
  1409. if (height > out_height)
  1410. vf = 2;
  1411. else
  1412. vf = 1;
  1413. if (cpu_is_omap24xx()) {
  1414. if (vf > 1 && hf > 1)
  1415. return dispc_mgr_pclk_rate(channel) * 4;
  1416. else
  1417. return dispc_mgr_pclk_rate(channel) * 2;
  1418. } else if (cpu_is_omap34xx()) {
  1419. return dispc_mgr_pclk_rate(channel) * vf * hf;
  1420. } else {
  1421. return dispc_mgr_pclk_rate(channel) * hf;
  1422. }
  1423. }
  1424. static int dispc_ovl_calc_scaling(enum omap_plane plane,
  1425. enum omap_channel channel, u16 width, u16 height,
  1426. u16 out_width, u16 out_height,
  1427. enum omap_color_mode color_mode, bool *five_taps)
  1428. {
  1429. struct omap_overlay *ovl = omap_dss_get_overlay(plane);
  1430. const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
  1431. const int maxsinglelinewidth =
  1432. dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
  1433. unsigned long fclk = 0;
  1434. if (width == out_width && height == out_height)
  1435. return 0;
  1436. if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
  1437. return -EINVAL;
  1438. if (out_width < width / maxdownscale ||
  1439. out_width > width * 8)
  1440. return -EINVAL;
  1441. if (out_height < height / maxdownscale ||
  1442. out_height > height * 8)
  1443. return -EINVAL;
  1444. if (cpu_is_omap24xx()) {
  1445. if (width > maxsinglelinewidth)
  1446. DSSERR("Cannot scale max input width exceeded");
  1447. *five_taps = false;
  1448. fclk = calc_fclk(channel, width, height, out_width,
  1449. out_height);
  1450. } else if (cpu_is_omap34xx()) {
  1451. if (width > (maxsinglelinewidth * 2)) {
  1452. DSSERR("Cannot setup scaling");
  1453. DSSERR("width exceeds maximum width possible");
  1454. return -EINVAL;
  1455. }
  1456. fclk = calc_fclk_five_taps(channel, width, height, out_width,
  1457. out_height, color_mode);
  1458. if (width > maxsinglelinewidth) {
  1459. if (height > out_height && height < out_height * 2)
  1460. *five_taps = false;
  1461. else {
  1462. DSSERR("cannot setup scaling with five taps");
  1463. return -EINVAL;
  1464. }
  1465. }
  1466. if (!*five_taps)
  1467. fclk = calc_fclk(channel, width, height, out_width,
  1468. out_height);
  1469. } else {
  1470. if (width > maxsinglelinewidth) {
  1471. DSSERR("Cannot scale width exceeds max line width");
  1472. return -EINVAL;
  1473. }
  1474. fclk = calc_fclk(channel, width, height, out_width,
  1475. out_height);
  1476. }
  1477. DSSDBG("required fclk rate = %lu Hz\n", fclk);
  1478. DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
  1479. if (!fclk || fclk > dispc_fclk_rate()) {
  1480. DSSERR("failed to set up scaling, "
  1481. "required fclk rate = %lu Hz, "
  1482. "current fclk rate = %lu Hz\n",
  1483. fclk, dispc_fclk_rate());
  1484. return -EINVAL;
  1485. }
  1486. return 0;
  1487. }
  1488. int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
  1489. bool ilace, bool replication)
  1490. {
  1491. struct omap_overlay *ovl = omap_dss_get_overlay(plane);
  1492. bool five_taps = true;
  1493. bool fieldmode = 0;
  1494. int r, cconv = 0;
  1495. unsigned offset0, offset1;
  1496. s32 row_inc;
  1497. s32 pix_inc;
  1498. u16 frame_height = oi->height;
  1499. unsigned int field_offset = 0;
  1500. u16 outw, outh;
  1501. enum omap_channel channel;
  1502. channel = dispc_ovl_get_channel_out(plane);
  1503. DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
  1504. "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d\n",
  1505. plane, oi->paddr, oi->p_uv_addr,
  1506. oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
  1507. oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
  1508. oi->mirror, ilace, channel, replication);
  1509. if (oi->paddr == 0)
  1510. return -EINVAL;
  1511. outw = oi->out_width == 0 ? oi->width : oi->out_width;
  1512. outh = oi->out_height == 0 ? oi->height : oi->out_height;
  1513. if (ilace && oi->height == outh)
  1514. fieldmode = 1;
  1515. if (ilace) {
  1516. if (fieldmode)
  1517. oi->height /= 2;
  1518. oi->pos_y /= 2;
  1519. outh /= 2;
  1520. DSSDBG("adjusting for ilace: height %d, pos_y %d, "
  1521. "out_height %d\n",
  1522. oi->height, oi->pos_y, outh);
  1523. }
  1524. if (!dss_feat_color_mode_supported(plane, oi->color_mode))
  1525. return -EINVAL;
  1526. r = dispc_ovl_calc_scaling(plane, channel, oi->width, oi->height,
  1527. outw, outh, oi->color_mode,
  1528. &five_taps);
  1529. if (r)
  1530. return r;
  1531. if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
  1532. oi->color_mode == OMAP_DSS_COLOR_UYVY ||
  1533. oi->color_mode == OMAP_DSS_COLOR_NV12)
  1534. cconv = 1;
  1535. if (ilace && !fieldmode) {
  1536. /*
  1537. * when downscaling the bottom field may have to start several
  1538. * source lines below the top field. Unfortunately ACCUI
  1539. * registers will only hold the fractional part of the offset
  1540. * so the integer part must be added to the base address of the
  1541. * bottom field.
  1542. */
  1543. if (!oi->height || oi->height == outh)
  1544. field_offset = 0;
  1545. else
  1546. field_offset = oi->height / outh / 2;
  1547. }
  1548. /* Fields are independent but interleaved in memory. */
  1549. if (fieldmode)
  1550. field_offset = 1;
  1551. if (oi->rotation_type == OMAP_DSS_ROT_DMA)
  1552. calc_dma_rotation_offset(oi->rotation, oi->mirror,
  1553. oi->screen_width, oi->width, frame_height,
  1554. oi->color_mode, fieldmode, field_offset,
  1555. &offset0, &offset1, &row_inc, &pix_inc);
  1556. else
  1557. calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
  1558. oi->screen_width, oi->width, frame_height,
  1559. oi->color_mode, fieldmode, field_offset,
  1560. &offset0, &offset1, &row_inc, &pix_inc);
  1561. DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
  1562. offset0, offset1, row_inc, pix_inc);
  1563. dispc_ovl_set_color_mode(plane, oi->color_mode);
  1564. dispc_ovl_set_ba0(plane, oi->paddr + offset0);
  1565. dispc_ovl_set_ba1(plane, oi->paddr + offset1);
  1566. if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
  1567. dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
  1568. dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
  1569. }
  1570. dispc_ovl_set_row_inc(plane, row_inc);
  1571. dispc_ovl_set_pix_inc(plane, pix_inc);
  1572. DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, oi->width,
  1573. oi->height, outw, outh);
  1574. dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
  1575. dispc_ovl_set_pic_size(plane, oi->width, oi->height);
  1576. if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
  1577. dispc_ovl_set_scaling(plane, oi->width, oi->height,
  1578. outw, outh,
  1579. ilace, five_taps, fieldmode,
  1580. oi->color_mode, oi->rotation);
  1581. dispc_ovl_set_vid_size(plane, outw, outh);
  1582. dispc_ovl_set_vid_color_conv(plane, cconv);
  1583. }
  1584. dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
  1585. oi->color_mode);
  1586. dispc_ovl_set_zorder(plane, oi->zorder);
  1587. dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
  1588. dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
  1589. dispc_ovl_enable_replication(plane, replication);
  1590. return 0;
  1591. }
  1592. int dispc_ovl_enable(enum omap_plane plane, bool enable)
  1593. {
  1594. DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
  1595. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
  1596. return 0;
  1597. }
  1598. static void dispc_disable_isr(void *data, u32 mask)
  1599. {
  1600. struct completion *compl = data;
  1601. complete(compl);
  1602. }
  1603. static void _enable_lcd_out(enum omap_channel channel, bool enable)
  1604. {
  1605. if (channel == OMAP_DSS_CHANNEL_LCD2) {
  1606. REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0);
  1607. /* flush posted write */
  1608. dispc_read_reg(DISPC_CONTROL2);
  1609. } else {
  1610. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
  1611. dispc_read_reg(DISPC_CONTROL);
  1612. }
  1613. }
  1614. static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
  1615. {
  1616. struct completion frame_done_completion;
  1617. bool is_on;
  1618. int r;
  1619. u32 irq;
  1620. /* When we disable LCD output, we need to wait until frame is done.
  1621. * Otherwise the DSS is still working, and turning off the clocks
  1622. * prevents DSS from going to OFF mode */
  1623. is_on = channel == OMAP_DSS_CHANNEL_LCD2 ?
  1624. REG_GET(DISPC_CONTROL2, 0, 0) :
  1625. REG_GET(DISPC_CONTROL, 0, 0);
  1626. irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 :
  1627. DISPC_IRQ_FRAMEDONE;
  1628. if (!enable && is_on) {
  1629. init_completion(&frame_done_completion);
  1630. r = omap_dispc_register_isr(dispc_disable_isr,
  1631. &frame_done_completion, irq);
  1632. if (r)
  1633. DSSERR("failed to register FRAMEDONE isr\n");
  1634. }
  1635. _enable_lcd_out(channel, enable);
  1636. if (!enable && is_on) {
  1637. if (!wait_for_completion_timeout(&frame_done_completion,
  1638. msecs_to_jiffies(100)))
  1639. DSSERR("timeout waiting for FRAME DONE\n");
  1640. r = omap_dispc_unregister_isr(dispc_disable_isr,
  1641. &frame_done_completion, irq);
  1642. if (r)
  1643. DSSERR("failed to unregister FRAMEDONE isr\n");
  1644. }
  1645. }
  1646. static void _enable_digit_out(bool enable)
  1647. {
  1648. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
  1649. /* flush posted write */
  1650. dispc_read_reg(DISPC_CONTROL);
  1651. }
  1652. static void dispc_mgr_enable_digit_out(bool enable)
  1653. {
  1654. struct completion frame_done_completion;
  1655. enum dss_hdmi_venc_clk_source_select src;
  1656. int r, i;
  1657. u32 irq_mask;
  1658. int num_irqs;
  1659. if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
  1660. return;
  1661. src = dss_get_hdmi_venc_clk_source();
  1662. if (enable) {
  1663. unsigned long flags;
  1664. /* When we enable digit output, we'll get an extra digit
  1665. * sync lost interrupt, that we need to ignore */
  1666. spin_lock_irqsave(&dispc.irq_lock, flags);
  1667. dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  1668. _omap_dispc_set_irqs();
  1669. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  1670. }
  1671. /* When we disable digit output, we need to wait until fields are done.
  1672. * Otherwise the DSS is still working, and turning off the clocks
  1673. * prevents DSS from going to OFF mode. And when enabling, we need to
  1674. * wait for the extra sync losts */
  1675. init_completion(&frame_done_completion);
  1676. if (src == DSS_HDMI_M_PCLK && enable == false) {
  1677. irq_mask = DISPC_IRQ_FRAMEDONETV;
  1678. num_irqs = 1;
  1679. } else {
  1680. irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
  1681. /* XXX I understand from TRM that we should only wait for the
  1682. * current field to complete. But it seems we have to wait for
  1683. * both fields */
  1684. num_irqs = 2;
  1685. }
  1686. r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
  1687. irq_mask);
  1688. if (r)
  1689. DSSERR("failed to register %x isr\n", irq_mask);
  1690. _enable_digit_out(enable);
  1691. for (i = 0; i < num_irqs; ++i) {
  1692. if (!wait_for_completion_timeout(&frame_done_completion,
  1693. msecs_to_jiffies(100)))
  1694. DSSERR("timeout waiting for digit out to %s\n",
  1695. enable ? "start" : "stop");
  1696. }
  1697. r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
  1698. irq_mask);
  1699. if (r)
  1700. DSSERR("failed to unregister %x isr\n", irq_mask);
  1701. if (enable) {
  1702. unsigned long flags;
  1703. spin_lock_irqsave(&dispc.irq_lock, flags);
  1704. dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
  1705. dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
  1706. _omap_dispc_set_irqs();
  1707. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  1708. }
  1709. }
  1710. bool dispc_mgr_is_enabled(enum omap_channel channel)
  1711. {
  1712. if (channel == OMAP_DSS_CHANNEL_LCD)
  1713. return !!REG_GET(DISPC_CONTROL, 0, 0);
  1714. else if (channel == OMAP_DSS_CHANNEL_DIGIT)
  1715. return !!REG_GET(DISPC_CONTROL, 1, 1);
  1716. else if (channel == OMAP_DSS_CHANNEL_LCD2)
  1717. return !!REG_GET(DISPC_CONTROL2, 0, 0);
  1718. else
  1719. BUG();
  1720. }
  1721. void dispc_mgr_enable(enum omap_channel channel, bool enable)
  1722. {
  1723. if (dispc_mgr_is_lcd(channel))
  1724. dispc_mgr_enable_lcd_out(channel, enable);
  1725. else if (channel == OMAP_DSS_CHANNEL_DIGIT)
  1726. dispc_mgr_enable_digit_out(enable);
  1727. else
  1728. BUG();
  1729. }
  1730. void dispc_lcd_enable_signal_polarity(bool act_high)
  1731. {
  1732. if (!dss_has_feature(FEAT_LCDENABLEPOL))
  1733. return;
  1734. REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
  1735. }
  1736. void dispc_lcd_enable_signal(bool enable)
  1737. {
  1738. if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
  1739. return;
  1740. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
  1741. }
  1742. void dispc_pck_free_enable(bool enable)
  1743. {
  1744. if (!dss_has_feature(FEAT_PCKFREEENABLE))
  1745. return;
  1746. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
  1747. }
  1748. void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
  1749. {
  1750. if (channel == OMAP_DSS_CHANNEL_LCD2)
  1751. REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
  1752. else
  1753. REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
  1754. }
  1755. void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
  1756. enum omap_lcd_display_type type)
  1757. {
  1758. int mode;
  1759. switch (type) {
  1760. case OMAP_DSS_LCD_DISPLAY_STN:
  1761. mode = 0;
  1762. break;
  1763. case OMAP_DSS_LCD_DISPLAY_TFT:
  1764. mode = 1;
  1765. break;
  1766. default:
  1767. BUG();
  1768. return;
  1769. }
  1770. if (channel == OMAP_DSS_CHANNEL_LCD2)
  1771. REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3);
  1772. else
  1773. REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
  1774. }
  1775. void dispc_set_loadmode(enum omap_dss_load_mode mode)
  1776. {
  1777. REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
  1778. }
  1779. static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
  1780. {
  1781. dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
  1782. }
  1783. static void dispc_mgr_set_trans_key(enum omap_channel ch,
  1784. enum omap_dss_trans_key_type type,
  1785. u32 trans_key)
  1786. {
  1787. if (ch == OMAP_DSS_CHANNEL_LCD)
  1788. REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
  1789. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  1790. REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
  1791. else /* OMAP_DSS_CHANNEL_LCD2 */
  1792. REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11);
  1793. dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
  1794. }
  1795. static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
  1796. {
  1797. if (ch == OMAP_DSS_CHANNEL_LCD)
  1798. REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
  1799. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  1800. REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
  1801. else /* OMAP_DSS_CHANNEL_LCD2 */
  1802. REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
  1803. }
  1804. static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
  1805. bool enable)
  1806. {
  1807. if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
  1808. return;
  1809. if (ch == OMAP_DSS_CHANNEL_LCD)
  1810. REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
  1811. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  1812. REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
  1813. }
  1814. void dispc_mgr_setup(enum omap_channel channel,
  1815. struct omap_overlay_manager_info *info)
  1816. {
  1817. dispc_mgr_set_default_color(channel, info->default_color);
  1818. dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
  1819. dispc_mgr_enable_trans_key(channel, info->trans_enabled);
  1820. dispc_mgr_enable_alpha_fixed_zorder(channel,
  1821. info->partial_alpha_enabled);
  1822. if (dss_has_feature(FEAT_CPR)) {
  1823. dispc_mgr_enable_cpr(channel, info->cpr_enable);
  1824. dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
  1825. }
  1826. }
  1827. void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
  1828. {
  1829. int code;
  1830. switch (data_lines) {
  1831. case 12:
  1832. code = 0;
  1833. break;
  1834. case 16:
  1835. code = 1;
  1836. break;
  1837. case 18:
  1838. code = 2;
  1839. break;
  1840. case 24:
  1841. code = 3;
  1842. break;
  1843. default:
  1844. BUG();
  1845. return;
  1846. }
  1847. if (channel == OMAP_DSS_CHANNEL_LCD2)
  1848. REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8);
  1849. else
  1850. REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
  1851. }
  1852. void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
  1853. {
  1854. u32 l;
  1855. int gpout0, gpout1;
  1856. switch (mode) {
  1857. case DSS_IO_PAD_MODE_RESET:
  1858. gpout0 = 0;
  1859. gpout1 = 0;
  1860. break;
  1861. case DSS_IO_PAD_MODE_RFBI:
  1862. gpout0 = 1;
  1863. gpout1 = 0;
  1864. break;
  1865. case DSS_IO_PAD_MODE_BYPASS:
  1866. gpout0 = 1;
  1867. gpout1 = 1;
  1868. break;
  1869. default:
  1870. BUG();
  1871. return;
  1872. }
  1873. l = dispc_read_reg(DISPC_CONTROL);
  1874. l = FLD_MOD(l, gpout0, 15, 15);
  1875. l = FLD_MOD(l, gpout1, 16, 16);
  1876. dispc_write_reg(DISPC_CONTROL, l);
  1877. }
  1878. void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
  1879. {
  1880. if (channel == OMAP_DSS_CHANNEL_LCD2)
  1881. REG_FLD_MOD(DISPC_CONTROL2, enable, 11, 11);
  1882. else
  1883. REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11);
  1884. }
  1885. static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
  1886. int vsw, int vfp, int vbp)
  1887. {
  1888. if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
  1889. if (hsw < 1 || hsw > 64 ||
  1890. hfp < 1 || hfp > 256 ||
  1891. hbp < 1 || hbp > 256 ||
  1892. vsw < 1 || vsw > 64 ||
  1893. vfp < 0 || vfp > 255 ||
  1894. vbp < 0 || vbp > 255)
  1895. return false;
  1896. } else {
  1897. if (hsw < 1 || hsw > 256 ||
  1898. hfp < 1 || hfp > 4096 ||
  1899. hbp < 1 || hbp > 4096 ||
  1900. vsw < 1 || vsw > 256 ||
  1901. vfp < 0 || vfp > 4095 ||
  1902. vbp < 0 || vbp > 4095)
  1903. return false;
  1904. }
  1905. return true;
  1906. }
  1907. bool dispc_lcd_timings_ok(struct omap_video_timings *timings)
  1908. {
  1909. return _dispc_lcd_timings_ok(timings->hsw, timings->hfp,
  1910. timings->hbp, timings->vsw,
  1911. timings->vfp, timings->vbp);
  1912. }
  1913. static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
  1914. int hfp, int hbp, int vsw, int vfp, int vbp)
  1915. {
  1916. u32 timing_h, timing_v;
  1917. if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
  1918. timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
  1919. FLD_VAL(hbp-1, 27, 20);
  1920. timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
  1921. FLD_VAL(vbp, 27, 20);
  1922. } else {
  1923. timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
  1924. FLD_VAL(hbp-1, 31, 20);
  1925. timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
  1926. FLD_VAL(vbp, 31, 20);
  1927. }
  1928. dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
  1929. dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
  1930. }
  1931. /* change name to mode? */
  1932. void dispc_mgr_set_lcd_timings(enum omap_channel channel,
  1933. struct omap_video_timings *timings)
  1934. {
  1935. unsigned xtot, ytot;
  1936. unsigned long ht, vt;
  1937. if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
  1938. timings->hbp, timings->vsw,
  1939. timings->vfp, timings->vbp))
  1940. BUG();
  1941. _dispc_mgr_set_lcd_timings(channel, timings->hsw, timings->hfp,
  1942. timings->hbp, timings->vsw, timings->vfp,
  1943. timings->vbp);
  1944. dispc_mgr_set_lcd_size(channel, timings->x_res, timings->y_res);
  1945. xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp;
  1946. ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp;
  1947. ht = (timings->pixel_clock * 1000) / xtot;
  1948. vt = (timings->pixel_clock * 1000) / xtot / ytot;
  1949. DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res,
  1950. timings->y_res);
  1951. DSSDBG("pck %u\n", timings->pixel_clock);
  1952. DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
  1953. timings->hsw, timings->hfp, timings->hbp,
  1954. timings->vsw, timings->vfp, timings->vbp);
  1955. DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
  1956. }
  1957. static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
  1958. u16 pck_div)
  1959. {
  1960. BUG_ON(lck_div < 1);
  1961. BUG_ON(pck_div < 1);
  1962. dispc_write_reg(DISPC_DIVISORo(channel),
  1963. FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
  1964. }
  1965. static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
  1966. int *pck_div)
  1967. {
  1968. u32 l;
  1969. l = dispc_read_reg(DISPC_DIVISORo(channel));
  1970. *lck_div = FLD_GET(l, 23, 16);
  1971. *pck_div = FLD_GET(l, 7, 0);
  1972. }
  1973. unsigned long dispc_fclk_rate(void)
  1974. {
  1975. struct platform_device *dsidev;
  1976. unsigned long r = 0;
  1977. switch (dss_get_dispc_clk_source()) {
  1978. case OMAP_DSS_CLK_SRC_FCK:
  1979. r = clk_get_rate(dispc.dss_clk);
  1980. break;
  1981. case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
  1982. dsidev = dsi_get_dsidev_from_id(0);
  1983. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  1984. break;
  1985. case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
  1986. dsidev = dsi_get_dsidev_from_id(1);
  1987. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  1988. break;
  1989. default:
  1990. BUG();
  1991. }
  1992. return r;
  1993. }
  1994. unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
  1995. {
  1996. struct platform_device *dsidev;
  1997. int lcd;
  1998. unsigned long r;
  1999. u32 l;
  2000. l = dispc_read_reg(DISPC_DIVISORo(channel));
  2001. lcd = FLD_GET(l, 23, 16);
  2002. switch (dss_get_lcd_clk_source(channel)) {
  2003. case OMAP_DSS_CLK_SRC_FCK:
  2004. r = clk_get_rate(dispc.dss_clk);
  2005. break;
  2006. case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
  2007. dsidev = dsi_get_dsidev_from_id(0);
  2008. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2009. break;
  2010. case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
  2011. dsidev = dsi_get_dsidev_from_id(1);
  2012. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2013. break;
  2014. default:
  2015. BUG();
  2016. }
  2017. return r / lcd;
  2018. }
  2019. unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
  2020. {
  2021. unsigned long r;
  2022. if (dispc_mgr_is_lcd(channel)) {
  2023. int pcd;
  2024. u32 l;
  2025. l = dispc_read_reg(DISPC_DIVISORo(channel));
  2026. pcd = FLD_GET(l, 7, 0);
  2027. r = dispc_mgr_lclk_rate(channel);
  2028. return r / pcd;
  2029. } else {
  2030. struct omap_dss_device *dssdev =
  2031. dispc_mgr_get_device(channel);
  2032. switch (dssdev->type) {
  2033. case OMAP_DISPLAY_TYPE_VENC:
  2034. return venc_get_pixel_clock();
  2035. case OMAP_DISPLAY_TYPE_HDMI:
  2036. return hdmi_get_pixel_clock();
  2037. default:
  2038. BUG();
  2039. }
  2040. }
  2041. }
  2042. void dispc_dump_clocks(struct seq_file *s)
  2043. {
  2044. int lcd, pcd;
  2045. u32 l;
  2046. enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
  2047. enum omap_dss_clk_source lcd_clk_src;
  2048. if (dispc_runtime_get())
  2049. return;
  2050. seq_printf(s, "- DISPC -\n");
  2051. seq_printf(s, "dispc fclk source = %s (%s)\n",
  2052. dss_get_generic_clk_source_name(dispc_clk_src),
  2053. dss_feat_get_clk_source_name(dispc_clk_src));
  2054. seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
  2055. if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
  2056. seq_printf(s, "- DISPC-CORE-CLK -\n");
  2057. l = dispc_read_reg(DISPC_DIVISOR);
  2058. lcd = FLD_GET(l, 23, 16);
  2059. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2060. (dispc_fclk_rate()/lcd), lcd);
  2061. }
  2062. seq_printf(s, "- LCD1 -\n");
  2063. lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD);
  2064. seq_printf(s, "lcd1_clk source = %s (%s)\n",
  2065. dss_get_generic_clk_source_name(lcd_clk_src),
  2066. dss_feat_get_clk_source_name(lcd_clk_src));
  2067. dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
  2068. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2069. dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
  2070. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2071. dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
  2072. if (dss_has_feature(FEAT_MGR_LCD2)) {
  2073. seq_printf(s, "- LCD2 -\n");
  2074. lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD2);
  2075. seq_printf(s, "lcd2_clk source = %s (%s)\n",
  2076. dss_get_generic_clk_source_name(lcd_clk_src),
  2077. dss_feat_get_clk_source_name(lcd_clk_src));
  2078. dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
  2079. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2080. dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
  2081. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2082. dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
  2083. }
  2084. dispc_runtime_put();
  2085. }
  2086. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2087. void dispc_dump_irqs(struct seq_file *s)
  2088. {
  2089. unsigned long flags;
  2090. struct dispc_irq_stats stats;
  2091. spin_lock_irqsave(&dispc.irq_stats_lock, flags);
  2092. stats = dispc.irq_stats;
  2093. memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
  2094. dispc.irq_stats.last_reset = jiffies;
  2095. spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
  2096. seq_printf(s, "period %u ms\n",
  2097. jiffies_to_msecs(jiffies - stats.last_reset));
  2098. seq_printf(s, "irqs %d\n", stats.irq_count);
  2099. #define PIS(x) \
  2100. seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
  2101. PIS(FRAMEDONE);
  2102. PIS(VSYNC);
  2103. PIS(EVSYNC_EVEN);
  2104. PIS(EVSYNC_ODD);
  2105. PIS(ACBIAS_COUNT_STAT);
  2106. PIS(PROG_LINE_NUM);
  2107. PIS(GFX_FIFO_UNDERFLOW);
  2108. PIS(GFX_END_WIN);
  2109. PIS(PAL_GAMMA_MASK);
  2110. PIS(OCP_ERR);
  2111. PIS(VID1_FIFO_UNDERFLOW);
  2112. PIS(VID1_END_WIN);
  2113. PIS(VID2_FIFO_UNDERFLOW);
  2114. PIS(VID2_END_WIN);
  2115. if (dss_feat_get_num_ovls() > 3) {
  2116. PIS(VID3_FIFO_UNDERFLOW);
  2117. PIS(VID3_END_WIN);
  2118. }
  2119. PIS(SYNC_LOST);
  2120. PIS(SYNC_LOST_DIGIT);
  2121. PIS(WAKEUP);
  2122. if (dss_has_feature(FEAT_MGR_LCD2)) {
  2123. PIS(FRAMEDONE2);
  2124. PIS(VSYNC2);
  2125. PIS(ACBIAS_COUNT_STAT2);
  2126. PIS(SYNC_LOST2);
  2127. }
  2128. #undef PIS
  2129. }
  2130. #endif
  2131. void dispc_dump_regs(struct seq_file *s)
  2132. {
  2133. int i, j;
  2134. const char *mgr_names[] = {
  2135. [OMAP_DSS_CHANNEL_LCD] = "LCD",
  2136. [OMAP_DSS_CHANNEL_DIGIT] = "TV",
  2137. [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
  2138. };
  2139. const char *ovl_names[] = {
  2140. [OMAP_DSS_GFX] = "GFX",
  2141. [OMAP_DSS_VIDEO1] = "VID1",
  2142. [OMAP_DSS_VIDEO2] = "VID2",
  2143. [OMAP_DSS_VIDEO3] = "VID3",
  2144. };
  2145. const char **p_names;
  2146. #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
  2147. if (dispc_runtime_get())
  2148. return;
  2149. /* DISPC common registers */
  2150. DUMPREG(DISPC_REVISION);
  2151. DUMPREG(DISPC_SYSCONFIG);
  2152. DUMPREG(DISPC_SYSSTATUS);
  2153. DUMPREG(DISPC_IRQSTATUS);
  2154. DUMPREG(DISPC_IRQENABLE);
  2155. DUMPREG(DISPC_CONTROL);
  2156. DUMPREG(DISPC_CONFIG);
  2157. DUMPREG(DISPC_CAPABLE);
  2158. DUMPREG(DISPC_LINE_STATUS);
  2159. DUMPREG(DISPC_LINE_NUMBER);
  2160. if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
  2161. dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
  2162. DUMPREG(DISPC_GLOBAL_ALPHA);
  2163. if (dss_has_feature(FEAT_MGR_LCD2)) {
  2164. DUMPREG(DISPC_CONTROL2);
  2165. DUMPREG(DISPC_CONFIG2);
  2166. }
  2167. #undef DUMPREG
  2168. #define DISPC_REG(i, name) name(i)
  2169. #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
  2170. 48 - strlen(#r) - strlen(p_names[i]), " ", \
  2171. dispc_read_reg(DISPC_REG(i, r)))
  2172. p_names = mgr_names;
  2173. /* DISPC channel specific registers */
  2174. for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
  2175. DUMPREG(i, DISPC_DEFAULT_COLOR);
  2176. DUMPREG(i, DISPC_TRANS_COLOR);
  2177. DUMPREG(i, DISPC_SIZE_MGR);
  2178. if (i == OMAP_DSS_CHANNEL_DIGIT)
  2179. continue;
  2180. DUMPREG(i, DISPC_DEFAULT_COLOR);
  2181. DUMPREG(i, DISPC_TRANS_COLOR);
  2182. DUMPREG(i, DISPC_TIMING_H);
  2183. DUMPREG(i, DISPC_TIMING_V);
  2184. DUMPREG(i, DISPC_POL_FREQ);
  2185. DUMPREG(i, DISPC_DIVISORo);
  2186. DUMPREG(i, DISPC_SIZE_MGR);
  2187. DUMPREG(i, DISPC_DATA_CYCLE1);
  2188. DUMPREG(i, DISPC_DATA_CYCLE2);
  2189. DUMPREG(i, DISPC_DATA_CYCLE3);
  2190. if (dss_has_feature(FEAT_CPR)) {
  2191. DUMPREG(i, DISPC_CPR_COEF_R);
  2192. DUMPREG(i, DISPC_CPR_COEF_G);
  2193. DUMPREG(i, DISPC_CPR_COEF_B);
  2194. }
  2195. }
  2196. p_names = ovl_names;
  2197. for (i = 0; i < dss_feat_get_num_ovls(); i++) {
  2198. DUMPREG(i, DISPC_OVL_BA0);
  2199. DUMPREG(i, DISPC_OVL_BA1);
  2200. DUMPREG(i, DISPC_OVL_POSITION);
  2201. DUMPREG(i, DISPC_OVL_SIZE);
  2202. DUMPREG(i, DISPC_OVL_ATTRIBUTES);
  2203. DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
  2204. DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
  2205. DUMPREG(i, DISPC_OVL_ROW_INC);
  2206. DUMPREG(i, DISPC_OVL_PIXEL_INC);
  2207. if (dss_has_feature(FEAT_PRELOAD))
  2208. DUMPREG(i, DISPC_OVL_PRELOAD);
  2209. if (i == OMAP_DSS_GFX) {
  2210. DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
  2211. DUMPREG(i, DISPC_OVL_TABLE_BA);
  2212. continue;
  2213. }
  2214. DUMPREG(i, DISPC_OVL_FIR);
  2215. DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
  2216. DUMPREG(i, DISPC_OVL_ACCU0);
  2217. DUMPREG(i, DISPC_OVL_ACCU1);
  2218. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  2219. DUMPREG(i, DISPC_OVL_BA0_UV);
  2220. DUMPREG(i, DISPC_OVL_BA1_UV);
  2221. DUMPREG(i, DISPC_OVL_FIR2);
  2222. DUMPREG(i, DISPC_OVL_ACCU2_0);
  2223. DUMPREG(i, DISPC_OVL_ACCU2_1);
  2224. }
  2225. if (dss_has_feature(FEAT_ATTR2))
  2226. DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
  2227. if (dss_has_feature(FEAT_PRELOAD))
  2228. DUMPREG(i, DISPC_OVL_PRELOAD);
  2229. }
  2230. #undef DISPC_REG
  2231. #undef DUMPREG
  2232. #define DISPC_REG(plane, name, i) name(plane, i)
  2233. #define DUMPREG(plane, name, i) \
  2234. seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
  2235. 46 - strlen(#name) - strlen(p_names[plane]), " ", \
  2236. dispc_read_reg(DISPC_REG(plane, name, i)))
  2237. /* Video pipeline coefficient registers */
  2238. /* start from OMAP_DSS_VIDEO1 */
  2239. for (i = 1; i < dss_feat_get_num_ovls(); i++) {
  2240. for (j = 0; j < 8; j++)
  2241. DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
  2242. for (j = 0; j < 8; j++)
  2243. DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
  2244. for (j = 0; j < 5; j++)
  2245. DUMPREG(i, DISPC_OVL_CONV_COEF, j);
  2246. if (dss_has_feature(FEAT_FIR_COEF_V)) {
  2247. for (j = 0; j < 8; j++)
  2248. DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
  2249. }
  2250. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  2251. for (j = 0; j < 8; j++)
  2252. DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
  2253. for (j = 0; j < 8; j++)
  2254. DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
  2255. for (j = 0; j < 8; j++)
  2256. DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
  2257. }
  2258. }
  2259. dispc_runtime_put();
  2260. #undef DISPC_REG
  2261. #undef DUMPREG
  2262. }
  2263. static void _dispc_mgr_set_pol_freq(enum omap_channel channel, bool onoff,
  2264. bool rf, bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi,
  2265. u8 acb)
  2266. {
  2267. u32 l = 0;
  2268. DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n",
  2269. onoff, rf, ieo, ipc, ihs, ivs, acbi, acb);
  2270. l |= FLD_VAL(onoff, 17, 17);
  2271. l |= FLD_VAL(rf, 16, 16);
  2272. l |= FLD_VAL(ieo, 15, 15);
  2273. l |= FLD_VAL(ipc, 14, 14);
  2274. l |= FLD_VAL(ihs, 13, 13);
  2275. l |= FLD_VAL(ivs, 12, 12);
  2276. l |= FLD_VAL(acbi, 11, 8);
  2277. l |= FLD_VAL(acb, 7, 0);
  2278. dispc_write_reg(DISPC_POL_FREQ(channel), l);
  2279. }
  2280. void dispc_mgr_set_pol_freq(enum omap_channel channel,
  2281. enum omap_panel_config config, u8 acbi, u8 acb)
  2282. {
  2283. _dispc_mgr_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
  2284. (config & OMAP_DSS_LCD_RF) != 0,
  2285. (config & OMAP_DSS_LCD_IEO) != 0,
  2286. (config & OMAP_DSS_LCD_IPC) != 0,
  2287. (config & OMAP_DSS_LCD_IHS) != 0,
  2288. (config & OMAP_DSS_LCD_IVS) != 0,
  2289. acbi, acb);
  2290. }
  2291. /* with fck as input clock rate, find dispc dividers that produce req_pck */
  2292. void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
  2293. struct dispc_clock_info *cinfo)
  2294. {
  2295. u16 pcd_min, pcd_max;
  2296. unsigned long best_pck;
  2297. u16 best_ld, cur_ld;
  2298. u16 best_pd, cur_pd;
  2299. pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
  2300. pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
  2301. if (!is_tft)
  2302. pcd_min = 3;
  2303. best_pck = 0;
  2304. best_ld = 0;
  2305. best_pd = 0;
  2306. for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
  2307. unsigned long lck = fck / cur_ld;
  2308. for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
  2309. unsigned long pck = lck / cur_pd;
  2310. long old_delta = abs(best_pck - req_pck);
  2311. long new_delta = abs(pck - req_pck);
  2312. if (best_pck == 0 || new_delta < old_delta) {
  2313. best_pck = pck;
  2314. best_ld = cur_ld;
  2315. best_pd = cur_pd;
  2316. if (pck == req_pck)
  2317. goto found;
  2318. }
  2319. if (pck < req_pck)
  2320. break;
  2321. }
  2322. if (lck / pcd_min < req_pck)
  2323. break;
  2324. }
  2325. found:
  2326. cinfo->lck_div = best_ld;
  2327. cinfo->pck_div = best_pd;
  2328. cinfo->lck = fck / cinfo->lck_div;
  2329. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2330. }
  2331. /* calculate clock rates using dividers in cinfo */
  2332. int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
  2333. struct dispc_clock_info *cinfo)
  2334. {
  2335. if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
  2336. return -EINVAL;
  2337. if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
  2338. return -EINVAL;
  2339. cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
  2340. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2341. return 0;
  2342. }
  2343. int dispc_mgr_set_clock_div(enum omap_channel channel,
  2344. struct dispc_clock_info *cinfo)
  2345. {
  2346. DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
  2347. DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
  2348. dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
  2349. return 0;
  2350. }
  2351. int dispc_mgr_get_clock_div(enum omap_channel channel,
  2352. struct dispc_clock_info *cinfo)
  2353. {
  2354. unsigned long fck;
  2355. fck = dispc_fclk_rate();
  2356. cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
  2357. cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
  2358. cinfo->lck = fck / cinfo->lck_div;
  2359. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2360. return 0;
  2361. }
  2362. /* dispc.irq_lock has to be locked by the caller */
  2363. static void _omap_dispc_set_irqs(void)
  2364. {
  2365. u32 mask;
  2366. u32 old_mask;
  2367. int i;
  2368. struct omap_dispc_isr_data *isr_data;
  2369. mask = dispc.irq_error_mask;
  2370. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2371. isr_data = &dispc.registered_isr[i];
  2372. if (isr_data->isr == NULL)
  2373. continue;
  2374. mask |= isr_data->mask;
  2375. }
  2376. old_mask = dispc_read_reg(DISPC_IRQENABLE);
  2377. /* clear the irqstatus for newly enabled irqs */
  2378. dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
  2379. dispc_write_reg(DISPC_IRQENABLE, mask);
  2380. }
  2381. int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
  2382. {
  2383. int i;
  2384. int ret;
  2385. unsigned long flags;
  2386. struct omap_dispc_isr_data *isr_data;
  2387. if (isr == NULL)
  2388. return -EINVAL;
  2389. spin_lock_irqsave(&dispc.irq_lock, flags);
  2390. /* check for duplicate entry */
  2391. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2392. isr_data = &dispc.registered_isr[i];
  2393. if (isr_data->isr == isr && isr_data->arg == arg &&
  2394. isr_data->mask == mask) {
  2395. ret = -EINVAL;
  2396. goto err;
  2397. }
  2398. }
  2399. isr_data = NULL;
  2400. ret = -EBUSY;
  2401. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2402. isr_data = &dispc.registered_isr[i];
  2403. if (isr_data->isr != NULL)
  2404. continue;
  2405. isr_data->isr = isr;
  2406. isr_data->arg = arg;
  2407. isr_data->mask = mask;
  2408. ret = 0;
  2409. break;
  2410. }
  2411. if (ret)
  2412. goto err;
  2413. _omap_dispc_set_irqs();
  2414. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2415. return 0;
  2416. err:
  2417. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2418. return ret;
  2419. }
  2420. EXPORT_SYMBOL(omap_dispc_register_isr);
  2421. int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
  2422. {
  2423. int i;
  2424. unsigned long flags;
  2425. int ret = -EINVAL;
  2426. struct omap_dispc_isr_data *isr_data;
  2427. spin_lock_irqsave(&dispc.irq_lock, flags);
  2428. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2429. isr_data = &dispc.registered_isr[i];
  2430. if (isr_data->isr != isr || isr_data->arg != arg ||
  2431. isr_data->mask != mask)
  2432. continue;
  2433. /* found the correct isr */
  2434. isr_data->isr = NULL;
  2435. isr_data->arg = NULL;
  2436. isr_data->mask = 0;
  2437. ret = 0;
  2438. break;
  2439. }
  2440. if (ret == 0)
  2441. _omap_dispc_set_irqs();
  2442. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2443. return ret;
  2444. }
  2445. EXPORT_SYMBOL(omap_dispc_unregister_isr);
  2446. #ifdef DEBUG
  2447. static void print_irq_status(u32 status)
  2448. {
  2449. if ((status & dispc.irq_error_mask) == 0)
  2450. return;
  2451. printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
  2452. #define PIS(x) \
  2453. if (status & DISPC_IRQ_##x) \
  2454. printk(#x " ");
  2455. PIS(GFX_FIFO_UNDERFLOW);
  2456. PIS(OCP_ERR);
  2457. PIS(VID1_FIFO_UNDERFLOW);
  2458. PIS(VID2_FIFO_UNDERFLOW);
  2459. if (dss_feat_get_num_ovls() > 3)
  2460. PIS(VID3_FIFO_UNDERFLOW);
  2461. PIS(SYNC_LOST);
  2462. PIS(SYNC_LOST_DIGIT);
  2463. if (dss_has_feature(FEAT_MGR_LCD2))
  2464. PIS(SYNC_LOST2);
  2465. #undef PIS
  2466. printk("\n");
  2467. }
  2468. #endif
  2469. /* Called from dss.c. Note that we don't touch clocks here,
  2470. * but we presume they are on because we got an IRQ. However,
  2471. * an irq handler may turn the clocks off, so we may not have
  2472. * clock later in the function. */
  2473. static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
  2474. {
  2475. int i;
  2476. u32 irqstatus, irqenable;
  2477. u32 handledirqs = 0;
  2478. u32 unhandled_errors;
  2479. struct omap_dispc_isr_data *isr_data;
  2480. struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
  2481. spin_lock(&dispc.irq_lock);
  2482. irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
  2483. irqenable = dispc_read_reg(DISPC_IRQENABLE);
  2484. /* IRQ is not for us */
  2485. if (!(irqstatus & irqenable)) {
  2486. spin_unlock(&dispc.irq_lock);
  2487. return IRQ_NONE;
  2488. }
  2489. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2490. spin_lock(&dispc.irq_stats_lock);
  2491. dispc.irq_stats.irq_count++;
  2492. dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
  2493. spin_unlock(&dispc.irq_stats_lock);
  2494. #endif
  2495. #ifdef DEBUG
  2496. if (dss_debug)
  2497. print_irq_status(irqstatus);
  2498. #endif
  2499. /* Ack the interrupt. Do it here before clocks are possibly turned
  2500. * off */
  2501. dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
  2502. /* flush posted write */
  2503. dispc_read_reg(DISPC_IRQSTATUS);
  2504. /* make a copy and unlock, so that isrs can unregister
  2505. * themselves */
  2506. memcpy(registered_isr, dispc.registered_isr,
  2507. sizeof(registered_isr));
  2508. spin_unlock(&dispc.irq_lock);
  2509. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2510. isr_data = &registered_isr[i];
  2511. if (!isr_data->isr)
  2512. continue;
  2513. if (isr_data->mask & irqstatus) {
  2514. isr_data->isr(isr_data->arg, irqstatus);
  2515. handledirqs |= isr_data->mask;
  2516. }
  2517. }
  2518. spin_lock(&dispc.irq_lock);
  2519. unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
  2520. if (unhandled_errors) {
  2521. dispc.error_irqs |= unhandled_errors;
  2522. dispc.irq_error_mask &= ~unhandled_errors;
  2523. _omap_dispc_set_irqs();
  2524. schedule_work(&dispc.error_work);
  2525. }
  2526. spin_unlock(&dispc.irq_lock);
  2527. return IRQ_HANDLED;
  2528. }
  2529. static void dispc_error_worker(struct work_struct *work)
  2530. {
  2531. int i;
  2532. u32 errors;
  2533. unsigned long flags;
  2534. static const unsigned fifo_underflow_bits[] = {
  2535. DISPC_IRQ_GFX_FIFO_UNDERFLOW,
  2536. DISPC_IRQ_VID1_FIFO_UNDERFLOW,
  2537. DISPC_IRQ_VID2_FIFO_UNDERFLOW,
  2538. DISPC_IRQ_VID3_FIFO_UNDERFLOW,
  2539. };
  2540. static const unsigned sync_lost_bits[] = {
  2541. DISPC_IRQ_SYNC_LOST,
  2542. DISPC_IRQ_SYNC_LOST_DIGIT,
  2543. DISPC_IRQ_SYNC_LOST2,
  2544. };
  2545. spin_lock_irqsave(&dispc.irq_lock, flags);
  2546. errors = dispc.error_irqs;
  2547. dispc.error_irqs = 0;
  2548. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2549. dispc_runtime_get();
  2550. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  2551. struct omap_overlay *ovl;
  2552. unsigned bit;
  2553. ovl = omap_dss_get_overlay(i);
  2554. bit = fifo_underflow_bits[i];
  2555. if (bit & errors) {
  2556. DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
  2557. ovl->name);
  2558. dispc_ovl_enable(ovl->id, false);
  2559. dispc_mgr_go(ovl->manager->id);
  2560. mdelay(50);
  2561. }
  2562. }
  2563. for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
  2564. struct omap_overlay_manager *mgr;
  2565. unsigned bit;
  2566. mgr = omap_dss_get_overlay_manager(i);
  2567. bit = sync_lost_bits[i];
  2568. if (bit & errors) {
  2569. struct omap_dss_device *dssdev = mgr->device;
  2570. bool enable;
  2571. DSSERR("SYNC_LOST on channel %s, restarting the output "
  2572. "with video overlays disabled\n",
  2573. mgr->name);
  2574. enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
  2575. dssdev->driver->disable(dssdev);
  2576. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  2577. struct omap_overlay *ovl;
  2578. ovl = omap_dss_get_overlay(i);
  2579. if (ovl->id != OMAP_DSS_GFX &&
  2580. ovl->manager == mgr)
  2581. dispc_ovl_enable(ovl->id, false);
  2582. }
  2583. dispc_mgr_go(mgr->id);
  2584. mdelay(50);
  2585. if (enable)
  2586. dssdev->driver->enable(dssdev);
  2587. }
  2588. }
  2589. if (errors & DISPC_IRQ_OCP_ERR) {
  2590. DSSERR("OCP_ERR\n");
  2591. for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
  2592. struct omap_overlay_manager *mgr;
  2593. mgr = omap_dss_get_overlay_manager(i);
  2594. if (mgr->device && mgr->device->driver)
  2595. mgr->device->driver->disable(mgr->device);
  2596. }
  2597. }
  2598. spin_lock_irqsave(&dispc.irq_lock, flags);
  2599. dispc.irq_error_mask |= errors;
  2600. _omap_dispc_set_irqs();
  2601. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2602. dispc_runtime_put();
  2603. }
  2604. int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
  2605. {
  2606. void dispc_irq_wait_handler(void *data, u32 mask)
  2607. {
  2608. complete((struct completion *)data);
  2609. }
  2610. int r;
  2611. DECLARE_COMPLETION_ONSTACK(completion);
  2612. r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
  2613. irqmask);
  2614. if (r)
  2615. return r;
  2616. timeout = wait_for_completion_timeout(&completion, timeout);
  2617. omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
  2618. if (timeout == 0)
  2619. return -ETIMEDOUT;
  2620. if (timeout == -ERESTARTSYS)
  2621. return -ERESTARTSYS;
  2622. return 0;
  2623. }
  2624. int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
  2625. unsigned long timeout)
  2626. {
  2627. void dispc_irq_wait_handler(void *data, u32 mask)
  2628. {
  2629. complete((struct completion *)data);
  2630. }
  2631. int r;
  2632. DECLARE_COMPLETION_ONSTACK(completion);
  2633. r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
  2634. irqmask);
  2635. if (r)
  2636. return r;
  2637. timeout = wait_for_completion_interruptible_timeout(&completion,
  2638. timeout);
  2639. omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
  2640. if (timeout == 0)
  2641. return -ETIMEDOUT;
  2642. if (timeout == -ERESTARTSYS)
  2643. return -ERESTARTSYS;
  2644. return 0;
  2645. }
  2646. #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
  2647. void dispc_fake_vsync_irq(void)
  2648. {
  2649. u32 irqstatus = DISPC_IRQ_VSYNC;
  2650. int i;
  2651. WARN_ON(!in_interrupt());
  2652. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2653. struct omap_dispc_isr_data *isr_data;
  2654. isr_data = &dispc.registered_isr[i];
  2655. if (!isr_data->isr)
  2656. continue;
  2657. if (isr_data->mask & irqstatus)
  2658. isr_data->isr(isr_data->arg, irqstatus);
  2659. }
  2660. }
  2661. #endif
  2662. static void _omap_dispc_initialize_irq(void)
  2663. {
  2664. unsigned long flags;
  2665. spin_lock_irqsave(&dispc.irq_lock, flags);
  2666. memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
  2667. dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
  2668. if (dss_has_feature(FEAT_MGR_LCD2))
  2669. dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
  2670. if (dss_feat_get_num_ovls() > 3)
  2671. dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
  2672. /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
  2673. * so clear it */
  2674. dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
  2675. _omap_dispc_set_irqs();
  2676. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2677. }
  2678. void dispc_enable_sidle(void)
  2679. {
  2680. REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
  2681. }
  2682. void dispc_disable_sidle(void)
  2683. {
  2684. REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
  2685. }
  2686. static void _omap_dispc_initial_config(void)
  2687. {
  2688. u32 l;
  2689. /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
  2690. if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
  2691. l = dispc_read_reg(DISPC_DIVISOR);
  2692. /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
  2693. l = FLD_MOD(l, 1, 0, 0);
  2694. l = FLD_MOD(l, 1, 23, 16);
  2695. dispc_write_reg(DISPC_DIVISOR, l);
  2696. }
  2697. /* FUNCGATED */
  2698. if (dss_has_feature(FEAT_FUNCGATED))
  2699. REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
  2700. /* L3 firewall setting: enable access to OCM RAM */
  2701. /* XXX this should be somewhere in plat-omap */
  2702. if (cpu_is_omap24xx())
  2703. __raw_writel(0x402000b0, OMAP2_L3_IO_ADDRESS(0x680050a0));
  2704. _dispc_setup_color_conv_coef();
  2705. dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
  2706. dispc_read_plane_fifo_sizes();
  2707. dispc_configure_burst_sizes();
  2708. dispc_ovl_enable_zorder_planes();
  2709. }
  2710. /* DISPC HW IP initialisation */
  2711. static int omap_dispchw_probe(struct platform_device *pdev)
  2712. {
  2713. u32 rev;
  2714. int r = 0;
  2715. struct resource *dispc_mem;
  2716. struct clk *clk;
  2717. dispc.pdev = pdev;
  2718. clk = clk_get(&pdev->dev, "fck");
  2719. if (IS_ERR(clk)) {
  2720. DSSERR("can't get fck\n");
  2721. r = PTR_ERR(clk);
  2722. goto err_get_clk;
  2723. }
  2724. dispc.dss_clk = clk;
  2725. spin_lock_init(&dispc.irq_lock);
  2726. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2727. spin_lock_init(&dispc.irq_stats_lock);
  2728. dispc.irq_stats.last_reset = jiffies;
  2729. #endif
  2730. INIT_WORK(&dispc.error_work, dispc_error_worker);
  2731. dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
  2732. if (!dispc_mem) {
  2733. DSSERR("can't get IORESOURCE_MEM DISPC\n");
  2734. r = -EINVAL;
  2735. goto err_ioremap;
  2736. }
  2737. dispc.base = ioremap(dispc_mem->start, resource_size(dispc_mem));
  2738. if (!dispc.base) {
  2739. DSSERR("can't ioremap DISPC\n");
  2740. r = -ENOMEM;
  2741. goto err_ioremap;
  2742. }
  2743. dispc.irq = platform_get_irq(dispc.pdev, 0);
  2744. if (dispc.irq < 0) {
  2745. DSSERR("platform_get_irq failed\n");
  2746. r = -ENODEV;
  2747. goto err_irq;
  2748. }
  2749. r = request_irq(dispc.irq, omap_dispc_irq_handler, IRQF_SHARED,
  2750. "OMAP DISPC", dispc.pdev);
  2751. if (r < 0) {
  2752. DSSERR("request_irq failed\n");
  2753. goto err_irq;
  2754. }
  2755. pm_runtime_enable(&pdev->dev);
  2756. r = dispc_runtime_get();
  2757. if (r)
  2758. goto err_runtime_get;
  2759. _omap_dispc_initial_config();
  2760. _omap_dispc_initialize_irq();
  2761. rev = dispc_read_reg(DISPC_REVISION);
  2762. dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
  2763. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  2764. dispc_runtime_put();
  2765. return 0;
  2766. err_runtime_get:
  2767. pm_runtime_disable(&pdev->dev);
  2768. free_irq(dispc.irq, dispc.pdev);
  2769. err_irq:
  2770. iounmap(dispc.base);
  2771. err_ioremap:
  2772. clk_put(dispc.dss_clk);
  2773. err_get_clk:
  2774. return r;
  2775. }
  2776. static int omap_dispchw_remove(struct platform_device *pdev)
  2777. {
  2778. pm_runtime_disable(&pdev->dev);
  2779. clk_put(dispc.dss_clk);
  2780. free_irq(dispc.irq, dispc.pdev);
  2781. iounmap(dispc.base);
  2782. return 0;
  2783. }
  2784. static int dispc_runtime_suspend(struct device *dev)
  2785. {
  2786. dispc_save_context();
  2787. dss_runtime_put();
  2788. return 0;
  2789. }
  2790. static int dispc_runtime_resume(struct device *dev)
  2791. {
  2792. int r;
  2793. r = dss_runtime_get();
  2794. if (r < 0)
  2795. return r;
  2796. dispc_restore_context();
  2797. return 0;
  2798. }
  2799. static const struct dev_pm_ops dispc_pm_ops = {
  2800. .runtime_suspend = dispc_runtime_suspend,
  2801. .runtime_resume = dispc_runtime_resume,
  2802. };
  2803. static struct platform_driver omap_dispchw_driver = {
  2804. .probe = omap_dispchw_probe,
  2805. .remove = omap_dispchw_remove,
  2806. .driver = {
  2807. .name = "omapdss_dispc",
  2808. .owner = THIS_MODULE,
  2809. .pm = &dispc_pm_ops,
  2810. },
  2811. };
  2812. int dispc_init_platform_driver(void)
  2813. {
  2814. return platform_driver_register(&omap_dispchw_driver);
  2815. }
  2816. void dispc_uninit_platform_driver(void)
  2817. {
  2818. return platform_driver_unregister(&omap_dispchw_driver);
  2819. }