dispc.c 95 KB

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