dispc.c 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2009 Nokia Corporation
  4. * Author: Tomi Valkeinen <[email protected]>
  5. *
  6. * Some code and ideas taken from drivers/video/omap/ driver
  7. * by Imre Deak.
  8. */
  9. #define DSS_SUBSYS_NAME "DISPC"
  10. #include <linux/kernel.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/vmalloc.h>
  13. #include <linux/export.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/jiffies.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/delay.h>
  19. #include <linux/workqueue.h>
  20. #include <linux/hardirq.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/pm_runtime.h>
  23. #include <linux/sizes.h>
  24. #include <linux/mfd/syscon.h>
  25. #include <linux/regmap.h>
  26. #include <linux/of.h>
  27. #include <linux/of_device.h>
  28. #include <linux/component.h>
  29. #include <linux/sys_soc.h>
  30. #include <drm/drm_fourcc.h>
  31. #include <drm/drm_blend.h>
  32. #include "omapdss.h"
  33. #include "dss.h"
  34. #include "dispc.h"
  35. struct dispc_device;
  36. /* DISPC */
  37. #define DISPC_SZ_REGS SZ_4K
  38. enum omap_burst_size {
  39. BURST_SIZE_X2 = 0,
  40. BURST_SIZE_X4 = 1,
  41. BURST_SIZE_X8 = 2,
  42. };
  43. #define REG_GET(dispc, idx, start, end) \
  44. FLD_GET(dispc_read_reg(dispc, idx), start, end)
  45. #define REG_FLD_MOD(dispc, idx, val, start, end) \
  46. dispc_write_reg(dispc, idx, \
  47. FLD_MOD(dispc_read_reg(dispc, idx), val, start, end))
  48. /* DISPC has feature id */
  49. enum dispc_feature_id {
  50. FEAT_LCDENABLEPOL,
  51. FEAT_LCDENABLESIGNAL,
  52. FEAT_PCKFREEENABLE,
  53. FEAT_FUNCGATED,
  54. FEAT_MGR_LCD2,
  55. FEAT_MGR_LCD3,
  56. FEAT_LINEBUFFERSPLIT,
  57. FEAT_ROWREPEATENABLE,
  58. FEAT_RESIZECONF,
  59. /* Independent core clk divider */
  60. FEAT_CORE_CLK_DIV,
  61. FEAT_HANDLE_UV_SEPARATE,
  62. FEAT_ATTR2,
  63. FEAT_CPR,
  64. FEAT_PRELOAD,
  65. FEAT_FIR_COEF_V,
  66. FEAT_ALPHA_FIXED_ZORDER,
  67. FEAT_ALPHA_FREE_ZORDER,
  68. FEAT_FIFO_MERGE,
  69. /* An unknown HW bug causing the normal FIFO thresholds not to work */
  70. FEAT_OMAP3_DSI_FIFO_BUG,
  71. FEAT_BURST_2D,
  72. FEAT_MFLAG,
  73. };
  74. struct dispc_features {
  75. u8 sw_start;
  76. u8 fp_start;
  77. u8 bp_start;
  78. u16 sw_max;
  79. u16 vp_max;
  80. u16 hp_max;
  81. u8 mgr_width_start;
  82. u8 mgr_height_start;
  83. u16 mgr_width_max;
  84. u16 mgr_height_max;
  85. u16 ovl_width_max;
  86. u16 ovl_height_max;
  87. unsigned long max_lcd_pclk;
  88. unsigned long max_tv_pclk;
  89. unsigned int max_downscale;
  90. unsigned int max_line_width;
  91. unsigned int min_pcd;
  92. int (*calc_scaling)(struct dispc_device *dispc,
  93. unsigned long pclk, unsigned long lclk,
  94. const struct videomode *vm,
  95. u16 width, u16 height, u16 out_width, u16 out_height,
  96. u32 fourcc, bool *five_taps,
  97. int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
  98. u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
  99. unsigned long (*calc_core_clk) (unsigned long pclk,
  100. u16 width, u16 height, u16 out_width, u16 out_height,
  101. bool mem_to_mem);
  102. u8 num_fifos;
  103. const enum dispc_feature_id *features;
  104. unsigned int num_features;
  105. const struct dss_reg_field *reg_fields;
  106. const unsigned int num_reg_fields;
  107. const enum omap_overlay_caps *overlay_caps;
  108. const u32 **supported_color_modes;
  109. const u32 *supported_scaler_color_modes;
  110. unsigned int num_mgrs;
  111. unsigned int num_ovls;
  112. unsigned int buffer_size_unit;
  113. unsigned int burst_size_unit;
  114. /* swap GFX & WB fifos */
  115. bool gfx_fifo_workaround:1;
  116. /* no DISPC_IRQ_FRAMEDONETV on this SoC */
  117. bool no_framedone_tv:1;
  118. /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
  119. bool mstandby_workaround:1;
  120. bool set_max_preload:1;
  121. /* PIXEL_INC is not added to the last pixel of a line */
  122. bool last_pixel_inc_missing:1;
  123. /* POL_FREQ has ALIGN bit */
  124. bool supports_sync_align:1;
  125. bool has_writeback:1;
  126. bool supports_double_pixel:1;
  127. /*
  128. * Field order for VENC is different than HDMI. We should handle this in
  129. * some intelligent manner, but as the SoCs have either HDMI or VENC,
  130. * never both, we can just use this flag for now.
  131. */
  132. bool reverse_ilace_field_order:1;
  133. bool has_gamma_table:1;
  134. bool has_gamma_i734_bug:1;
  135. };
  136. #define DISPC_MAX_NR_FIFOS 5
  137. #define DISPC_MAX_CHANNEL_GAMMA 4
  138. struct dispc_device {
  139. struct platform_device *pdev;
  140. void __iomem *base;
  141. struct dss_device *dss;
  142. struct dss_debugfs_entry *debugfs;
  143. int irq;
  144. irq_handler_t user_handler;
  145. void *user_data;
  146. unsigned long core_clk_rate;
  147. unsigned long tv_pclk_rate;
  148. u32 fifo_size[DISPC_MAX_NR_FIFOS];
  149. /* maps which plane is using a fifo. fifo-id -> plane-id */
  150. int fifo_assignment[DISPC_MAX_NR_FIFOS];
  151. bool ctx_valid;
  152. u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
  153. u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA];
  154. const struct dispc_features *feat;
  155. bool is_enabled;
  156. struct regmap *syscon_pol;
  157. u32 syscon_pol_offset;
  158. };
  159. enum omap_color_component {
  160. /* used for all color formats for OMAP3 and earlier
  161. * and for RGB and Y color component on OMAP4
  162. */
  163. DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
  164. /* used for UV component for
  165. * DRM_FORMAT_YUYV, DRM_FORMAT_UYVY, DRM_FORMAT_NV12
  166. * color formats on OMAP4
  167. */
  168. DISPC_COLOR_COMPONENT_UV = 1 << 1,
  169. };
  170. enum mgr_reg_fields {
  171. DISPC_MGR_FLD_ENABLE,
  172. DISPC_MGR_FLD_STNTFT,
  173. DISPC_MGR_FLD_GO,
  174. DISPC_MGR_FLD_TFTDATALINES,
  175. DISPC_MGR_FLD_STALLMODE,
  176. DISPC_MGR_FLD_TCKENABLE,
  177. DISPC_MGR_FLD_TCKSELECTION,
  178. DISPC_MGR_FLD_CPR,
  179. DISPC_MGR_FLD_FIFOHANDCHECK,
  180. /* used to maintain a count of the above fields */
  181. DISPC_MGR_FLD_NUM,
  182. };
  183. /* DISPC register field id */
  184. enum dispc_feat_reg_field {
  185. FEAT_REG_FIRHINC,
  186. FEAT_REG_FIRVINC,
  187. FEAT_REG_FIFOHIGHTHRESHOLD,
  188. FEAT_REG_FIFOLOWTHRESHOLD,
  189. FEAT_REG_FIFOSIZE,
  190. FEAT_REG_HORIZONTALACCU,
  191. FEAT_REG_VERTICALACCU,
  192. };
  193. struct dispc_reg_field {
  194. u16 reg;
  195. u8 high;
  196. u8 low;
  197. };
  198. struct dispc_gamma_desc {
  199. u32 len;
  200. u32 bits;
  201. u16 reg;
  202. bool has_index;
  203. };
  204. static const struct {
  205. const char *name;
  206. u32 vsync_irq;
  207. u32 framedone_irq;
  208. u32 sync_lost_irq;
  209. struct dispc_gamma_desc gamma;
  210. struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
  211. } mgr_desc[] = {
  212. [OMAP_DSS_CHANNEL_LCD] = {
  213. .name = "LCD",
  214. .vsync_irq = DISPC_IRQ_VSYNC,
  215. .framedone_irq = DISPC_IRQ_FRAMEDONE,
  216. .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
  217. .gamma = {
  218. .len = 256,
  219. .bits = 8,
  220. .reg = DISPC_GAMMA_TABLE0,
  221. .has_index = true,
  222. },
  223. .reg_desc = {
  224. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
  225. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
  226. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
  227. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
  228. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
  229. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
  230. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
  231. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
  232. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
  233. },
  234. },
  235. [OMAP_DSS_CHANNEL_DIGIT] = {
  236. .name = "DIGIT",
  237. .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
  238. .framedone_irq = DISPC_IRQ_FRAMEDONETV,
  239. .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
  240. .gamma = {
  241. .len = 1024,
  242. .bits = 10,
  243. .reg = DISPC_GAMMA_TABLE2,
  244. .has_index = false,
  245. },
  246. .reg_desc = {
  247. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
  248. [DISPC_MGR_FLD_STNTFT] = { },
  249. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
  250. [DISPC_MGR_FLD_TFTDATALINES] = { },
  251. [DISPC_MGR_FLD_STALLMODE] = { },
  252. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
  253. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
  254. [DISPC_MGR_FLD_CPR] = { },
  255. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
  256. },
  257. },
  258. [OMAP_DSS_CHANNEL_LCD2] = {
  259. .name = "LCD2",
  260. .vsync_irq = DISPC_IRQ_VSYNC2,
  261. .framedone_irq = DISPC_IRQ_FRAMEDONE2,
  262. .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
  263. .gamma = {
  264. .len = 256,
  265. .bits = 8,
  266. .reg = DISPC_GAMMA_TABLE1,
  267. .has_index = true,
  268. },
  269. .reg_desc = {
  270. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
  271. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
  272. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
  273. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
  274. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
  275. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
  276. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
  277. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
  278. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
  279. },
  280. },
  281. [OMAP_DSS_CHANNEL_LCD3] = {
  282. .name = "LCD3",
  283. .vsync_irq = DISPC_IRQ_VSYNC3,
  284. .framedone_irq = DISPC_IRQ_FRAMEDONE3,
  285. .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
  286. .gamma = {
  287. .len = 256,
  288. .bits = 8,
  289. .reg = DISPC_GAMMA_TABLE3,
  290. .has_index = true,
  291. },
  292. .reg_desc = {
  293. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
  294. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
  295. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
  296. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
  297. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
  298. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
  299. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
  300. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
  301. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
  302. },
  303. },
  304. };
  305. static unsigned long dispc_fclk_rate(struct dispc_device *dispc);
  306. static unsigned long dispc_core_clk_rate(struct dispc_device *dispc);
  307. static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
  308. enum omap_channel channel);
  309. static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
  310. enum omap_channel channel);
  311. static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
  312. enum omap_plane_id plane);
  313. static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
  314. enum omap_plane_id plane);
  315. static inline void dispc_write_reg(struct dispc_device *dispc, u16 idx, u32 val)
  316. {
  317. __raw_writel(val, dispc->base + idx);
  318. }
  319. static inline u32 dispc_read_reg(struct dispc_device *dispc, u16 idx)
  320. {
  321. return __raw_readl(dispc->base + idx);
  322. }
  323. static u32 mgr_fld_read(struct dispc_device *dispc, enum omap_channel channel,
  324. enum mgr_reg_fields regfld)
  325. {
  326. const struct dispc_reg_field *rfld = &mgr_desc[channel].reg_desc[regfld];
  327. return REG_GET(dispc, rfld->reg, rfld->high, rfld->low);
  328. }
  329. static void mgr_fld_write(struct dispc_device *dispc, enum omap_channel channel,
  330. enum mgr_reg_fields regfld, int val)
  331. {
  332. const struct dispc_reg_field *rfld = &mgr_desc[channel].reg_desc[regfld];
  333. REG_FLD_MOD(dispc, rfld->reg, val, rfld->high, rfld->low);
  334. }
  335. int dispc_get_num_ovls(struct dispc_device *dispc)
  336. {
  337. return dispc->feat->num_ovls;
  338. }
  339. int dispc_get_num_mgrs(struct dispc_device *dispc)
  340. {
  341. return dispc->feat->num_mgrs;
  342. }
  343. static void dispc_get_reg_field(struct dispc_device *dispc,
  344. enum dispc_feat_reg_field id,
  345. u8 *start, u8 *end)
  346. {
  347. BUG_ON(id >= dispc->feat->num_reg_fields);
  348. *start = dispc->feat->reg_fields[id].start;
  349. *end = dispc->feat->reg_fields[id].end;
  350. }
  351. static bool dispc_has_feature(struct dispc_device *dispc,
  352. enum dispc_feature_id id)
  353. {
  354. unsigned int i;
  355. for (i = 0; i < dispc->feat->num_features; i++) {
  356. if (dispc->feat->features[i] == id)
  357. return true;
  358. }
  359. return false;
  360. }
  361. #define SR(dispc, reg) \
  362. dispc->ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(dispc, DISPC_##reg)
  363. #define RR(dispc, reg) \
  364. dispc_write_reg(dispc, DISPC_##reg, dispc->ctx[DISPC_##reg / sizeof(u32)])
  365. static void dispc_save_context(struct dispc_device *dispc)
  366. {
  367. int i, j;
  368. DSSDBG("dispc_save_context\n");
  369. SR(dispc, IRQENABLE);
  370. SR(dispc, CONTROL);
  371. SR(dispc, CONFIG);
  372. SR(dispc, LINE_NUMBER);
  373. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  374. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  375. SR(dispc, GLOBAL_ALPHA);
  376. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  377. SR(dispc, CONTROL2);
  378. SR(dispc, CONFIG2);
  379. }
  380. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  381. SR(dispc, CONTROL3);
  382. SR(dispc, CONFIG3);
  383. }
  384. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  385. SR(dispc, DEFAULT_COLOR(i));
  386. SR(dispc, TRANS_COLOR(i));
  387. SR(dispc, SIZE_MGR(i));
  388. if (i == OMAP_DSS_CHANNEL_DIGIT)
  389. continue;
  390. SR(dispc, TIMING_H(i));
  391. SR(dispc, TIMING_V(i));
  392. SR(dispc, POL_FREQ(i));
  393. SR(dispc, DIVISORo(i));
  394. SR(dispc, DATA_CYCLE1(i));
  395. SR(dispc, DATA_CYCLE2(i));
  396. SR(dispc, DATA_CYCLE3(i));
  397. if (dispc_has_feature(dispc, FEAT_CPR)) {
  398. SR(dispc, CPR_COEF_R(i));
  399. SR(dispc, CPR_COEF_G(i));
  400. SR(dispc, CPR_COEF_B(i));
  401. }
  402. }
  403. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  404. SR(dispc, OVL_BA0(i));
  405. SR(dispc, OVL_BA1(i));
  406. SR(dispc, OVL_POSITION(i));
  407. SR(dispc, OVL_SIZE(i));
  408. SR(dispc, OVL_ATTRIBUTES(i));
  409. SR(dispc, OVL_FIFO_THRESHOLD(i));
  410. SR(dispc, OVL_ROW_INC(i));
  411. SR(dispc, OVL_PIXEL_INC(i));
  412. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  413. SR(dispc, OVL_PRELOAD(i));
  414. if (i == OMAP_DSS_GFX) {
  415. SR(dispc, OVL_WINDOW_SKIP(i));
  416. SR(dispc, OVL_TABLE_BA(i));
  417. continue;
  418. }
  419. SR(dispc, OVL_FIR(i));
  420. SR(dispc, OVL_PICTURE_SIZE(i));
  421. SR(dispc, OVL_ACCU0(i));
  422. SR(dispc, OVL_ACCU1(i));
  423. for (j = 0; j < 8; j++)
  424. SR(dispc, OVL_FIR_COEF_H(i, j));
  425. for (j = 0; j < 8; j++)
  426. SR(dispc, OVL_FIR_COEF_HV(i, j));
  427. for (j = 0; j < 5; j++)
  428. SR(dispc, OVL_CONV_COEF(i, j));
  429. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  430. for (j = 0; j < 8; j++)
  431. SR(dispc, OVL_FIR_COEF_V(i, j));
  432. }
  433. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  434. SR(dispc, OVL_BA0_UV(i));
  435. SR(dispc, OVL_BA1_UV(i));
  436. SR(dispc, OVL_FIR2(i));
  437. SR(dispc, OVL_ACCU2_0(i));
  438. SR(dispc, OVL_ACCU2_1(i));
  439. for (j = 0; j < 8; j++)
  440. SR(dispc, OVL_FIR_COEF_H2(i, j));
  441. for (j = 0; j < 8; j++)
  442. SR(dispc, OVL_FIR_COEF_HV2(i, j));
  443. for (j = 0; j < 8; j++)
  444. SR(dispc, OVL_FIR_COEF_V2(i, j));
  445. }
  446. if (dispc_has_feature(dispc, FEAT_ATTR2))
  447. SR(dispc, OVL_ATTRIBUTES2(i));
  448. }
  449. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  450. SR(dispc, DIVISOR);
  451. dispc->ctx_valid = true;
  452. DSSDBG("context saved\n");
  453. }
  454. static void dispc_restore_context(struct dispc_device *dispc)
  455. {
  456. int i, j;
  457. DSSDBG("dispc_restore_context\n");
  458. if (!dispc->ctx_valid)
  459. return;
  460. /*RR(dispc, IRQENABLE);*/
  461. /*RR(dispc, CONTROL);*/
  462. RR(dispc, CONFIG);
  463. RR(dispc, LINE_NUMBER);
  464. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  465. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  466. RR(dispc, GLOBAL_ALPHA);
  467. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  468. RR(dispc, CONFIG2);
  469. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  470. RR(dispc, CONFIG3);
  471. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  472. RR(dispc, DEFAULT_COLOR(i));
  473. RR(dispc, TRANS_COLOR(i));
  474. RR(dispc, SIZE_MGR(i));
  475. if (i == OMAP_DSS_CHANNEL_DIGIT)
  476. continue;
  477. RR(dispc, TIMING_H(i));
  478. RR(dispc, TIMING_V(i));
  479. RR(dispc, POL_FREQ(i));
  480. RR(dispc, DIVISORo(i));
  481. RR(dispc, DATA_CYCLE1(i));
  482. RR(dispc, DATA_CYCLE2(i));
  483. RR(dispc, DATA_CYCLE3(i));
  484. if (dispc_has_feature(dispc, FEAT_CPR)) {
  485. RR(dispc, CPR_COEF_R(i));
  486. RR(dispc, CPR_COEF_G(i));
  487. RR(dispc, CPR_COEF_B(i));
  488. }
  489. }
  490. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  491. RR(dispc, OVL_BA0(i));
  492. RR(dispc, OVL_BA1(i));
  493. RR(dispc, OVL_POSITION(i));
  494. RR(dispc, OVL_SIZE(i));
  495. RR(dispc, OVL_ATTRIBUTES(i));
  496. RR(dispc, OVL_FIFO_THRESHOLD(i));
  497. RR(dispc, OVL_ROW_INC(i));
  498. RR(dispc, OVL_PIXEL_INC(i));
  499. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  500. RR(dispc, OVL_PRELOAD(i));
  501. if (i == OMAP_DSS_GFX) {
  502. RR(dispc, OVL_WINDOW_SKIP(i));
  503. RR(dispc, OVL_TABLE_BA(i));
  504. continue;
  505. }
  506. RR(dispc, OVL_FIR(i));
  507. RR(dispc, OVL_PICTURE_SIZE(i));
  508. RR(dispc, OVL_ACCU0(i));
  509. RR(dispc, OVL_ACCU1(i));
  510. for (j = 0; j < 8; j++)
  511. RR(dispc, OVL_FIR_COEF_H(i, j));
  512. for (j = 0; j < 8; j++)
  513. RR(dispc, OVL_FIR_COEF_HV(i, j));
  514. for (j = 0; j < 5; j++)
  515. RR(dispc, OVL_CONV_COEF(i, j));
  516. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  517. for (j = 0; j < 8; j++)
  518. RR(dispc, OVL_FIR_COEF_V(i, j));
  519. }
  520. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  521. RR(dispc, OVL_BA0_UV(i));
  522. RR(dispc, OVL_BA1_UV(i));
  523. RR(dispc, OVL_FIR2(i));
  524. RR(dispc, OVL_ACCU2_0(i));
  525. RR(dispc, OVL_ACCU2_1(i));
  526. for (j = 0; j < 8; j++)
  527. RR(dispc, OVL_FIR_COEF_H2(i, j));
  528. for (j = 0; j < 8; j++)
  529. RR(dispc, OVL_FIR_COEF_HV2(i, j));
  530. for (j = 0; j < 8; j++)
  531. RR(dispc, OVL_FIR_COEF_V2(i, j));
  532. }
  533. if (dispc_has_feature(dispc, FEAT_ATTR2))
  534. RR(dispc, OVL_ATTRIBUTES2(i));
  535. }
  536. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  537. RR(dispc, DIVISOR);
  538. /* enable last, because LCD & DIGIT enable are here */
  539. RR(dispc, CONTROL);
  540. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  541. RR(dispc, CONTROL2);
  542. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  543. RR(dispc, CONTROL3);
  544. /* clear spurious SYNC_LOST_DIGIT interrupts */
  545. dispc_clear_irqstatus(dispc, DISPC_IRQ_SYNC_LOST_DIGIT);
  546. /*
  547. * enable last so IRQs won't trigger before
  548. * the context is fully restored
  549. */
  550. RR(dispc, IRQENABLE);
  551. DSSDBG("context restored\n");
  552. }
  553. #undef SR
  554. #undef RR
  555. int dispc_runtime_get(struct dispc_device *dispc)
  556. {
  557. int r;
  558. DSSDBG("dispc_runtime_get\n");
  559. r = pm_runtime_get_sync(&dispc->pdev->dev);
  560. if (WARN_ON(r < 0)) {
  561. pm_runtime_put_noidle(&dispc->pdev->dev);
  562. return r;
  563. }
  564. return 0;
  565. }
  566. void dispc_runtime_put(struct dispc_device *dispc)
  567. {
  568. int r;
  569. DSSDBG("dispc_runtime_put\n");
  570. r = pm_runtime_put_sync(&dispc->pdev->dev);
  571. WARN_ON(r < 0 && r != -ENOSYS);
  572. }
  573. u32 dispc_mgr_get_vsync_irq(struct dispc_device *dispc,
  574. enum omap_channel channel)
  575. {
  576. return mgr_desc[channel].vsync_irq;
  577. }
  578. u32 dispc_mgr_get_framedone_irq(struct dispc_device *dispc,
  579. enum omap_channel channel)
  580. {
  581. if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc->feat->no_framedone_tv)
  582. return 0;
  583. return mgr_desc[channel].framedone_irq;
  584. }
  585. u32 dispc_mgr_get_sync_lost_irq(struct dispc_device *dispc,
  586. enum omap_channel channel)
  587. {
  588. return mgr_desc[channel].sync_lost_irq;
  589. }
  590. u32 dispc_wb_get_framedone_irq(struct dispc_device *dispc)
  591. {
  592. return DISPC_IRQ_FRAMEDONEWB;
  593. }
  594. void dispc_mgr_enable(struct dispc_device *dispc,
  595. enum omap_channel channel, bool enable)
  596. {
  597. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_ENABLE, enable);
  598. /* flush posted write */
  599. mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
  600. }
  601. static bool dispc_mgr_is_enabled(struct dispc_device *dispc,
  602. enum omap_channel channel)
  603. {
  604. return !!mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
  605. }
  606. bool dispc_mgr_go_busy(struct dispc_device *dispc,
  607. enum omap_channel channel)
  608. {
  609. return mgr_fld_read(dispc, channel, DISPC_MGR_FLD_GO) == 1;
  610. }
  611. void dispc_mgr_go(struct dispc_device *dispc, enum omap_channel channel)
  612. {
  613. WARN_ON(!dispc_mgr_is_enabled(dispc, channel));
  614. WARN_ON(dispc_mgr_go_busy(dispc, channel));
  615. DSSDBG("GO %s\n", mgr_desc[channel].name);
  616. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_GO, 1);
  617. }
  618. bool dispc_wb_go_busy(struct dispc_device *dispc)
  619. {
  620. return REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
  621. }
  622. void dispc_wb_go(struct dispc_device *dispc)
  623. {
  624. enum omap_plane_id plane = OMAP_DSS_WB;
  625. bool enable, go;
  626. enable = REG_GET(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
  627. if (!enable)
  628. return;
  629. go = REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
  630. if (go) {
  631. DSSERR("GO bit not down for WB\n");
  632. return;
  633. }
  634. REG_FLD_MOD(dispc, DISPC_CONTROL2, 1, 6, 6);
  635. }
  636. static void dispc_ovl_write_firh_reg(struct dispc_device *dispc,
  637. enum omap_plane_id plane, int reg,
  638. u32 value)
  639. {
  640. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H(plane, reg), value);
  641. }
  642. static void dispc_ovl_write_firhv_reg(struct dispc_device *dispc,
  643. enum omap_plane_id plane, int reg,
  644. u32 value)
  645. {
  646. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV(plane, reg), value);
  647. }
  648. static void dispc_ovl_write_firv_reg(struct dispc_device *dispc,
  649. enum omap_plane_id plane, int reg,
  650. u32 value)
  651. {
  652. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V(plane, reg), value);
  653. }
  654. static void dispc_ovl_write_firh2_reg(struct dispc_device *dispc,
  655. enum omap_plane_id plane, int reg,
  656. u32 value)
  657. {
  658. BUG_ON(plane == OMAP_DSS_GFX);
  659. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H2(plane, reg), value);
  660. }
  661. static void dispc_ovl_write_firhv2_reg(struct dispc_device *dispc,
  662. enum omap_plane_id plane, int reg,
  663. u32 value)
  664. {
  665. BUG_ON(plane == OMAP_DSS_GFX);
  666. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
  667. }
  668. static void dispc_ovl_write_firv2_reg(struct dispc_device *dispc,
  669. enum omap_plane_id plane, int reg,
  670. u32 value)
  671. {
  672. BUG_ON(plane == OMAP_DSS_GFX);
  673. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V2(plane, reg), value);
  674. }
  675. static void dispc_ovl_set_scale_coef(struct dispc_device *dispc,
  676. enum omap_plane_id plane, int fir_hinc,
  677. int fir_vinc, int five_taps,
  678. enum omap_color_component color_comp)
  679. {
  680. const struct dispc_coef *h_coef, *v_coef;
  681. int i;
  682. h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
  683. v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
  684. if (!h_coef || !v_coef) {
  685. dev_err(&dispc->pdev->dev, "%s: failed to find scale coefs\n",
  686. __func__);
  687. return;
  688. }
  689. for (i = 0; i < 8; i++) {
  690. u32 h, hv;
  691. h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
  692. | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
  693. | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
  694. | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
  695. hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
  696. | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
  697. | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
  698. | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
  699. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  700. dispc_ovl_write_firh_reg(dispc, plane, i, h);
  701. dispc_ovl_write_firhv_reg(dispc, plane, i, hv);
  702. } else {
  703. dispc_ovl_write_firh2_reg(dispc, plane, i, h);
  704. dispc_ovl_write_firhv2_reg(dispc, plane, i, hv);
  705. }
  706. }
  707. if (five_taps) {
  708. for (i = 0; i < 8; i++) {
  709. u32 v;
  710. v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
  711. | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
  712. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
  713. dispc_ovl_write_firv_reg(dispc, plane, i, v);
  714. else
  715. dispc_ovl_write_firv2_reg(dispc, plane, i, v);
  716. }
  717. }
  718. }
  719. struct csc_coef_yuv2rgb {
  720. int ry, rcb, rcr, gy, gcb, gcr, by, bcb, bcr;
  721. bool full_range;
  722. };
  723. struct csc_coef_rgb2yuv {
  724. int yr, yg, yb, cbr, cbg, cbb, crr, crg, crb;
  725. bool full_range;
  726. };
  727. static void dispc_ovl_write_color_conv_coef(struct dispc_device *dispc,
  728. enum omap_plane_id plane,
  729. const struct csc_coef_yuv2rgb *ct)
  730. {
  731. #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
  732. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
  733. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
  734. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
  735. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
  736. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
  737. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
  738. #undef CVAL
  739. }
  740. /* YUV -> RGB, ITU-R BT.601, full range */
  741. static const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt601_full = {
  742. 256, 0, 358, /* ry, rcb, rcr |1.000 0.000 1.402|*/
  743. 256, -88, -182, /* gy, gcb, gcr |1.000 -0.344 -0.714|*/
  744. 256, 452, 0, /* by, bcb, bcr |1.000 1.772 0.000|*/
  745. true, /* full range */
  746. };
  747. /* YUV -> RGB, ITU-R BT.601, limited range */
  748. static const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt601_lim = {
  749. 298, 0, 409, /* ry, rcb, rcr |1.164 0.000 1.596|*/
  750. 298, -100, -208, /* gy, gcb, gcr |1.164 -0.392 -0.813|*/
  751. 298, 516, 0, /* by, bcb, bcr |1.164 2.017 0.000|*/
  752. false, /* limited range */
  753. };
  754. /* YUV -> RGB, ITU-R BT.709, full range */
  755. static const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt709_full = {
  756. 256, 0, 402, /* ry, rcb, rcr |1.000 0.000 1.570|*/
  757. 256, -48, -120, /* gy, gcb, gcr |1.000 -0.187 -0.467|*/
  758. 256, 475, 0, /* by, bcb, bcr |1.000 1.856 0.000|*/
  759. true, /* full range */
  760. };
  761. /* YUV -> RGB, ITU-R BT.709, limited range */
  762. static const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt709_lim = {
  763. 298, 0, 459, /* ry, rcb, rcr |1.164 0.000 1.793|*/
  764. 298, -55, -136, /* gy, gcb, gcr |1.164 -0.213 -0.533|*/
  765. 298, 541, 0, /* by, bcb, bcr |1.164 2.112 0.000|*/
  766. false, /* limited range */
  767. };
  768. static void dispc_ovl_set_csc(struct dispc_device *dispc,
  769. enum omap_plane_id plane,
  770. enum drm_color_encoding color_encoding,
  771. enum drm_color_range color_range)
  772. {
  773. const struct csc_coef_yuv2rgb *csc;
  774. switch (color_encoding) {
  775. default:
  776. case DRM_COLOR_YCBCR_BT601:
  777. if (color_range == DRM_COLOR_YCBCR_FULL_RANGE)
  778. csc = &coefs_yuv2rgb_bt601_full;
  779. else
  780. csc = &coefs_yuv2rgb_bt601_lim;
  781. break;
  782. case DRM_COLOR_YCBCR_BT709:
  783. if (color_range == DRM_COLOR_YCBCR_FULL_RANGE)
  784. csc = &coefs_yuv2rgb_bt709_full;
  785. else
  786. csc = &coefs_yuv2rgb_bt709_lim;
  787. break;
  788. }
  789. dispc_ovl_write_color_conv_coef(dispc, plane, csc);
  790. }
  791. static void dispc_ovl_set_ba0(struct dispc_device *dispc,
  792. enum omap_plane_id plane, u32 paddr)
  793. {
  794. dispc_write_reg(dispc, DISPC_OVL_BA0(plane), paddr);
  795. }
  796. static void dispc_ovl_set_ba1(struct dispc_device *dispc,
  797. enum omap_plane_id plane, u32 paddr)
  798. {
  799. dispc_write_reg(dispc, DISPC_OVL_BA1(plane), paddr);
  800. }
  801. static void dispc_ovl_set_ba0_uv(struct dispc_device *dispc,
  802. enum omap_plane_id plane, u32 paddr)
  803. {
  804. dispc_write_reg(dispc, DISPC_OVL_BA0_UV(plane), paddr);
  805. }
  806. static void dispc_ovl_set_ba1_uv(struct dispc_device *dispc,
  807. enum omap_plane_id plane, u32 paddr)
  808. {
  809. dispc_write_reg(dispc, DISPC_OVL_BA1_UV(plane), paddr);
  810. }
  811. static void dispc_ovl_set_pos(struct dispc_device *dispc,
  812. enum omap_plane_id plane,
  813. enum omap_overlay_caps caps, int x, int y)
  814. {
  815. u32 val;
  816. if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
  817. return;
  818. val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
  819. dispc_write_reg(dispc, DISPC_OVL_POSITION(plane), val);
  820. }
  821. static void dispc_ovl_set_input_size(struct dispc_device *dispc,
  822. enum omap_plane_id plane, int width,
  823. int height)
  824. {
  825. u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  826. if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
  827. dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
  828. else
  829. dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
  830. }
  831. static void dispc_ovl_set_output_size(struct dispc_device *dispc,
  832. enum omap_plane_id plane, int width,
  833. int height)
  834. {
  835. u32 val;
  836. BUG_ON(plane == OMAP_DSS_GFX);
  837. val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  838. if (plane == OMAP_DSS_WB)
  839. dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
  840. else
  841. dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
  842. }
  843. static void dispc_ovl_set_zorder(struct dispc_device *dispc,
  844. enum omap_plane_id plane,
  845. enum omap_overlay_caps caps, u8 zorder)
  846. {
  847. if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
  848. return;
  849. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
  850. }
  851. static void dispc_ovl_enable_zorder_planes(struct dispc_device *dispc)
  852. {
  853. int i;
  854. if (!dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  855. return;
  856. for (i = 0; i < dispc_get_num_ovls(dispc); i++)
  857. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
  858. }
  859. static void dispc_ovl_set_pre_mult_alpha(struct dispc_device *dispc,
  860. enum omap_plane_id plane,
  861. enum omap_overlay_caps caps,
  862. bool enable)
  863. {
  864. if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
  865. return;
  866. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
  867. }
  868. static void dispc_ovl_setup_global_alpha(struct dispc_device *dispc,
  869. enum omap_plane_id plane,
  870. enum omap_overlay_caps caps,
  871. u8 global_alpha)
  872. {
  873. static const unsigned int shifts[] = { 0, 8, 16, 24, };
  874. int shift;
  875. if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
  876. return;
  877. shift = shifts[plane];
  878. REG_FLD_MOD(dispc, DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
  879. }
  880. static void dispc_ovl_set_pix_inc(struct dispc_device *dispc,
  881. enum omap_plane_id plane, s32 inc)
  882. {
  883. dispc_write_reg(dispc, DISPC_OVL_PIXEL_INC(plane), inc);
  884. }
  885. static void dispc_ovl_set_row_inc(struct dispc_device *dispc,
  886. enum omap_plane_id plane, s32 inc)
  887. {
  888. dispc_write_reg(dispc, DISPC_OVL_ROW_INC(plane), inc);
  889. }
  890. static void dispc_ovl_set_color_mode(struct dispc_device *dispc,
  891. enum omap_plane_id plane, u32 fourcc)
  892. {
  893. u32 m = 0;
  894. if (plane != OMAP_DSS_GFX) {
  895. switch (fourcc) {
  896. case DRM_FORMAT_NV12:
  897. m = 0x0; break;
  898. case DRM_FORMAT_XRGB4444:
  899. m = 0x1; break;
  900. case DRM_FORMAT_RGBA4444:
  901. m = 0x2; break;
  902. case DRM_FORMAT_RGBX4444:
  903. m = 0x4; break;
  904. case DRM_FORMAT_ARGB4444:
  905. m = 0x5; break;
  906. case DRM_FORMAT_RGB565:
  907. m = 0x6; break;
  908. case DRM_FORMAT_ARGB1555:
  909. m = 0x7; break;
  910. case DRM_FORMAT_XRGB8888:
  911. m = 0x8; break;
  912. case DRM_FORMAT_RGB888:
  913. m = 0x9; break;
  914. case DRM_FORMAT_YUYV:
  915. m = 0xa; break;
  916. case DRM_FORMAT_UYVY:
  917. m = 0xb; break;
  918. case DRM_FORMAT_ARGB8888:
  919. m = 0xc; break;
  920. case DRM_FORMAT_RGBA8888:
  921. m = 0xd; break;
  922. case DRM_FORMAT_RGBX8888:
  923. m = 0xe; break;
  924. case DRM_FORMAT_XRGB1555:
  925. m = 0xf; break;
  926. default:
  927. BUG(); return;
  928. }
  929. } else {
  930. switch (fourcc) {
  931. case DRM_FORMAT_RGBX4444:
  932. m = 0x4; break;
  933. case DRM_FORMAT_ARGB4444:
  934. m = 0x5; break;
  935. case DRM_FORMAT_RGB565:
  936. m = 0x6; break;
  937. case DRM_FORMAT_ARGB1555:
  938. m = 0x7; break;
  939. case DRM_FORMAT_XRGB8888:
  940. m = 0x8; break;
  941. case DRM_FORMAT_RGB888:
  942. m = 0x9; break;
  943. case DRM_FORMAT_XRGB4444:
  944. m = 0xa; break;
  945. case DRM_FORMAT_RGBA4444:
  946. m = 0xb; break;
  947. case DRM_FORMAT_ARGB8888:
  948. m = 0xc; break;
  949. case DRM_FORMAT_RGBA8888:
  950. m = 0xd; break;
  951. case DRM_FORMAT_RGBX8888:
  952. m = 0xe; break;
  953. case DRM_FORMAT_XRGB1555:
  954. m = 0xf; break;
  955. default:
  956. BUG(); return;
  957. }
  958. }
  959. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
  960. }
  961. static void dispc_ovl_configure_burst_type(struct dispc_device *dispc,
  962. enum omap_plane_id plane,
  963. enum omap_dss_rotation_type rotation)
  964. {
  965. if (dispc_has_feature(dispc, FEAT_BURST_2D) == 0)
  966. return;
  967. if (rotation == OMAP_DSS_ROT_TILER)
  968. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
  969. else
  970. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
  971. }
  972. static void dispc_ovl_set_channel_out(struct dispc_device *dispc,
  973. enum omap_plane_id plane,
  974. enum omap_channel channel)
  975. {
  976. int shift;
  977. u32 val;
  978. int chan = 0, chan2 = 0;
  979. switch (plane) {
  980. case OMAP_DSS_GFX:
  981. shift = 8;
  982. break;
  983. case OMAP_DSS_VIDEO1:
  984. case OMAP_DSS_VIDEO2:
  985. case OMAP_DSS_VIDEO3:
  986. shift = 16;
  987. break;
  988. default:
  989. BUG();
  990. return;
  991. }
  992. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  993. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  994. switch (channel) {
  995. case OMAP_DSS_CHANNEL_LCD:
  996. chan = 0;
  997. chan2 = 0;
  998. break;
  999. case OMAP_DSS_CHANNEL_DIGIT:
  1000. chan = 1;
  1001. chan2 = 0;
  1002. break;
  1003. case OMAP_DSS_CHANNEL_LCD2:
  1004. chan = 0;
  1005. chan2 = 1;
  1006. break;
  1007. case OMAP_DSS_CHANNEL_LCD3:
  1008. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  1009. chan = 0;
  1010. chan2 = 2;
  1011. } else {
  1012. BUG();
  1013. return;
  1014. }
  1015. break;
  1016. case OMAP_DSS_CHANNEL_WB:
  1017. chan = 0;
  1018. chan2 = 3;
  1019. break;
  1020. default:
  1021. BUG();
  1022. return;
  1023. }
  1024. val = FLD_MOD(val, chan, shift, shift);
  1025. val = FLD_MOD(val, chan2, 31, 30);
  1026. } else {
  1027. val = FLD_MOD(val, channel, shift, shift);
  1028. }
  1029. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
  1030. }
  1031. static enum omap_channel dispc_ovl_get_channel_out(struct dispc_device *dispc,
  1032. enum omap_plane_id plane)
  1033. {
  1034. int shift;
  1035. u32 val;
  1036. switch (plane) {
  1037. case OMAP_DSS_GFX:
  1038. shift = 8;
  1039. break;
  1040. case OMAP_DSS_VIDEO1:
  1041. case OMAP_DSS_VIDEO2:
  1042. case OMAP_DSS_VIDEO3:
  1043. shift = 16;
  1044. break;
  1045. default:
  1046. BUG();
  1047. return 0;
  1048. }
  1049. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1050. if (FLD_GET(val, shift, shift) == 1)
  1051. return OMAP_DSS_CHANNEL_DIGIT;
  1052. if (!dispc_has_feature(dispc, FEAT_MGR_LCD2))
  1053. return OMAP_DSS_CHANNEL_LCD;
  1054. switch (FLD_GET(val, 31, 30)) {
  1055. case 0:
  1056. default:
  1057. return OMAP_DSS_CHANNEL_LCD;
  1058. case 1:
  1059. return OMAP_DSS_CHANNEL_LCD2;
  1060. case 2:
  1061. return OMAP_DSS_CHANNEL_LCD3;
  1062. case 3:
  1063. return OMAP_DSS_CHANNEL_WB;
  1064. }
  1065. }
  1066. static void dispc_ovl_set_burst_size(struct dispc_device *dispc,
  1067. enum omap_plane_id plane,
  1068. enum omap_burst_size burst_size)
  1069. {
  1070. static const unsigned int shifts[] = { 6, 14, 14, 14, 14, };
  1071. int shift;
  1072. shift = shifts[plane];
  1073. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), burst_size,
  1074. shift + 1, shift);
  1075. }
  1076. static void dispc_configure_burst_sizes(struct dispc_device *dispc)
  1077. {
  1078. int i;
  1079. const int burst_size = BURST_SIZE_X8;
  1080. /* Configure burst size always to maximum size */
  1081. for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
  1082. dispc_ovl_set_burst_size(dispc, i, burst_size);
  1083. if (dispc->feat->has_writeback)
  1084. dispc_ovl_set_burst_size(dispc, OMAP_DSS_WB, burst_size);
  1085. }
  1086. static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc,
  1087. enum omap_plane_id plane)
  1088. {
  1089. /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
  1090. return dispc->feat->burst_size_unit * 8;
  1091. }
  1092. bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
  1093. enum omap_plane_id plane, u32 fourcc)
  1094. {
  1095. const u32 *modes;
  1096. unsigned int i;
  1097. modes = dispc->feat->supported_color_modes[plane];
  1098. for (i = 0; modes[i]; ++i) {
  1099. if (modes[i] == fourcc)
  1100. return true;
  1101. }
  1102. return false;
  1103. }
  1104. const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
  1105. enum omap_plane_id plane)
  1106. {
  1107. return dispc->feat->supported_color_modes[plane];
  1108. }
  1109. static void dispc_mgr_enable_cpr(struct dispc_device *dispc,
  1110. enum omap_channel channel, bool enable)
  1111. {
  1112. if (channel == OMAP_DSS_CHANNEL_DIGIT)
  1113. return;
  1114. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_CPR, enable);
  1115. }
  1116. static void dispc_mgr_set_cpr_coef(struct dispc_device *dispc,
  1117. enum omap_channel channel,
  1118. const struct omap_dss_cpr_coefs *coefs)
  1119. {
  1120. u32 coef_r, coef_g, coef_b;
  1121. if (!dss_mgr_is_lcd(channel))
  1122. return;
  1123. coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
  1124. FLD_VAL(coefs->rb, 9, 0);
  1125. coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
  1126. FLD_VAL(coefs->gb, 9, 0);
  1127. coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
  1128. FLD_VAL(coefs->bb, 9, 0);
  1129. dispc_write_reg(dispc, DISPC_CPR_COEF_R(channel), coef_r);
  1130. dispc_write_reg(dispc, DISPC_CPR_COEF_G(channel), coef_g);
  1131. dispc_write_reg(dispc, DISPC_CPR_COEF_B(channel), coef_b);
  1132. }
  1133. static void dispc_ovl_set_vid_color_conv(struct dispc_device *dispc,
  1134. enum omap_plane_id plane, bool enable)
  1135. {
  1136. u32 val;
  1137. BUG_ON(plane == OMAP_DSS_GFX);
  1138. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1139. val = FLD_MOD(val, enable, 9, 9);
  1140. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
  1141. }
  1142. static void dispc_ovl_enable_replication(struct dispc_device *dispc,
  1143. enum omap_plane_id plane,
  1144. enum omap_overlay_caps caps,
  1145. bool enable)
  1146. {
  1147. static const unsigned int shifts[] = { 5, 10, 10, 10 };
  1148. int shift;
  1149. if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
  1150. return;
  1151. shift = shifts[plane];
  1152. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
  1153. }
  1154. static void dispc_mgr_set_size(struct dispc_device *dispc,
  1155. enum omap_channel channel, u16 width, u16 height)
  1156. {
  1157. u32 val;
  1158. val = FLD_VAL(height - 1, dispc->feat->mgr_height_start, 16) |
  1159. FLD_VAL(width - 1, dispc->feat->mgr_width_start, 0);
  1160. dispc_write_reg(dispc, DISPC_SIZE_MGR(channel), val);
  1161. }
  1162. static void dispc_init_fifos(struct dispc_device *dispc)
  1163. {
  1164. u32 size;
  1165. int fifo;
  1166. u8 start, end;
  1167. u32 unit;
  1168. int i;
  1169. unit = dispc->feat->buffer_size_unit;
  1170. dispc_get_reg_field(dispc, FEAT_REG_FIFOSIZE, &start, &end);
  1171. for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
  1172. size = REG_GET(dispc, DISPC_OVL_FIFO_SIZE_STATUS(fifo),
  1173. start, end);
  1174. size *= unit;
  1175. dispc->fifo_size[fifo] = size;
  1176. /*
  1177. * By default fifos are mapped directly to overlays, fifo 0 to
  1178. * ovl 0, fifo 1 to ovl 1, etc.
  1179. */
  1180. dispc->fifo_assignment[fifo] = fifo;
  1181. }
  1182. /*
  1183. * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
  1184. * causes problems with certain use cases, like using the tiler in 2D
  1185. * mode. The below hack swaps the fifos of GFX and WB planes, thus
  1186. * giving GFX plane a larger fifo. WB but should work fine with a
  1187. * smaller fifo.
  1188. */
  1189. if (dispc->feat->gfx_fifo_workaround) {
  1190. u32 v;
  1191. v = dispc_read_reg(dispc, DISPC_GLOBAL_BUFFER);
  1192. v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
  1193. v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
  1194. v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
  1195. v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
  1196. dispc_write_reg(dispc, DISPC_GLOBAL_BUFFER, v);
  1197. dispc->fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
  1198. dispc->fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
  1199. }
  1200. /*
  1201. * Setup default fifo thresholds.
  1202. */
  1203. for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
  1204. u32 low, high;
  1205. const bool use_fifomerge = false;
  1206. const bool manual_update = false;
  1207. dispc_ovl_compute_fifo_thresholds(dispc, i, &low, &high,
  1208. use_fifomerge, manual_update);
  1209. dispc_ovl_set_fifo_threshold(dispc, i, low, high);
  1210. }
  1211. if (dispc->feat->has_writeback) {
  1212. u32 low, high;
  1213. const bool use_fifomerge = false;
  1214. const bool manual_update = false;
  1215. dispc_ovl_compute_fifo_thresholds(dispc, OMAP_DSS_WB,
  1216. &low, &high, use_fifomerge,
  1217. manual_update);
  1218. dispc_ovl_set_fifo_threshold(dispc, OMAP_DSS_WB, low, high);
  1219. }
  1220. }
  1221. static u32 dispc_ovl_get_fifo_size(struct dispc_device *dispc,
  1222. enum omap_plane_id plane)
  1223. {
  1224. int fifo;
  1225. u32 size = 0;
  1226. for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
  1227. if (dispc->fifo_assignment[fifo] == plane)
  1228. size += dispc->fifo_size[fifo];
  1229. }
  1230. return size;
  1231. }
  1232. void dispc_ovl_set_fifo_threshold(struct dispc_device *dispc,
  1233. enum omap_plane_id plane,
  1234. u32 low, u32 high)
  1235. {
  1236. u8 hi_start, hi_end, lo_start, lo_end;
  1237. u32 unit;
  1238. unit = dispc->feat->buffer_size_unit;
  1239. WARN_ON(low % unit != 0);
  1240. WARN_ON(high % unit != 0);
  1241. low /= unit;
  1242. high /= unit;
  1243. dispc_get_reg_field(dispc, FEAT_REG_FIFOHIGHTHRESHOLD,
  1244. &hi_start, &hi_end);
  1245. dispc_get_reg_field(dispc, FEAT_REG_FIFOLOWTHRESHOLD,
  1246. &lo_start, &lo_end);
  1247. DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
  1248. plane,
  1249. REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1250. lo_start, lo_end) * unit,
  1251. REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1252. hi_start, hi_end) * unit,
  1253. low * unit, high * unit);
  1254. dispc_write_reg(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1255. FLD_VAL(high, hi_start, hi_end) |
  1256. FLD_VAL(low, lo_start, lo_end));
  1257. /*
  1258. * configure the preload to the pipeline's high threhold, if HT it's too
  1259. * large for the preload field, set the threshold to the maximum value
  1260. * that can be held by the preload register
  1261. */
  1262. if (dispc_has_feature(dispc, FEAT_PRELOAD) &&
  1263. dispc->feat->set_max_preload && plane != OMAP_DSS_WB)
  1264. dispc_write_reg(dispc, DISPC_OVL_PRELOAD(plane),
  1265. min(high, 0xfffu));
  1266. }
  1267. void dispc_enable_fifomerge(struct dispc_device *dispc, bool enable)
  1268. {
  1269. if (!dispc_has_feature(dispc, FEAT_FIFO_MERGE)) {
  1270. WARN_ON(enable);
  1271. return;
  1272. }
  1273. DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
  1274. REG_FLD_MOD(dispc, DISPC_CONFIG, enable ? 1 : 0, 14, 14);
  1275. }
  1276. void dispc_ovl_compute_fifo_thresholds(struct dispc_device *dispc,
  1277. enum omap_plane_id plane,
  1278. u32 *fifo_low, u32 *fifo_high,
  1279. bool use_fifomerge, bool manual_update)
  1280. {
  1281. /*
  1282. * All sizes are in bytes. Both the buffer and burst are made of
  1283. * buffer_units, and the fifo thresholds must be buffer_unit aligned.
  1284. */
  1285. unsigned int buf_unit = dispc->feat->buffer_size_unit;
  1286. unsigned int ovl_fifo_size, total_fifo_size, burst_size;
  1287. int i;
  1288. burst_size = dispc_ovl_get_burst_size(dispc, plane);
  1289. ovl_fifo_size = dispc_ovl_get_fifo_size(dispc, plane);
  1290. if (use_fifomerge) {
  1291. total_fifo_size = 0;
  1292. for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
  1293. total_fifo_size += dispc_ovl_get_fifo_size(dispc, i);
  1294. } else {
  1295. total_fifo_size = ovl_fifo_size;
  1296. }
  1297. /*
  1298. * We use the same low threshold for both fifomerge and non-fifomerge
  1299. * cases, but for fifomerge we calculate the high threshold using the
  1300. * combined fifo size
  1301. */
  1302. if (manual_update && dispc_has_feature(dispc, FEAT_OMAP3_DSI_FIFO_BUG)) {
  1303. *fifo_low = ovl_fifo_size - burst_size * 2;
  1304. *fifo_high = total_fifo_size - burst_size;
  1305. } else if (plane == OMAP_DSS_WB) {
  1306. /*
  1307. * Most optimal configuration for writeback is to push out data
  1308. * to the interconnect the moment writeback pushes enough pixels
  1309. * in the FIFO to form a burst
  1310. */
  1311. *fifo_low = 0;
  1312. *fifo_high = burst_size;
  1313. } else {
  1314. *fifo_low = ovl_fifo_size - burst_size;
  1315. *fifo_high = total_fifo_size - buf_unit;
  1316. }
  1317. }
  1318. static void dispc_ovl_set_mflag(struct dispc_device *dispc,
  1319. enum omap_plane_id plane, bool enable)
  1320. {
  1321. int bit;
  1322. if (plane == OMAP_DSS_GFX)
  1323. bit = 14;
  1324. else
  1325. bit = 23;
  1326. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
  1327. }
  1328. static void dispc_ovl_set_mflag_threshold(struct dispc_device *dispc,
  1329. enum omap_plane_id plane,
  1330. int low, int high)
  1331. {
  1332. dispc_write_reg(dispc, DISPC_OVL_MFLAG_THRESHOLD(plane),
  1333. FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
  1334. }
  1335. static void dispc_init_mflag(struct dispc_device *dispc)
  1336. {
  1337. int i;
  1338. /*
  1339. * HACK: NV12 color format and MFLAG seem to have problems working
  1340. * together: using two displays, and having an NV12 overlay on one of
  1341. * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
  1342. * Changing MFLAG thresholds and PRELOAD to certain values seem to
  1343. * remove the errors, but there doesn't seem to be a clear logic on
  1344. * which values work and which not.
  1345. *
  1346. * As a work-around, set force MFLAG to always on.
  1347. */
  1348. dispc_write_reg(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE,
  1349. (1 << 0) | /* MFLAG_CTRL = force always on */
  1350. (0 << 2)); /* MFLAG_START = disable */
  1351. for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
  1352. u32 size = dispc_ovl_get_fifo_size(dispc, i);
  1353. u32 unit = dispc->feat->buffer_size_unit;
  1354. u32 low, high;
  1355. dispc_ovl_set_mflag(dispc, i, true);
  1356. /*
  1357. * Simulation team suggests below thesholds:
  1358. * HT = fifosize * 5 / 8;
  1359. * LT = fifosize * 4 / 8;
  1360. */
  1361. low = size * 4 / 8 / unit;
  1362. high = size * 5 / 8 / unit;
  1363. dispc_ovl_set_mflag_threshold(dispc, i, low, high);
  1364. }
  1365. if (dispc->feat->has_writeback) {
  1366. u32 size = dispc_ovl_get_fifo_size(dispc, OMAP_DSS_WB);
  1367. u32 unit = dispc->feat->buffer_size_unit;
  1368. u32 low, high;
  1369. dispc_ovl_set_mflag(dispc, OMAP_DSS_WB, true);
  1370. /*
  1371. * Simulation team suggests below thesholds:
  1372. * HT = fifosize * 5 / 8;
  1373. * LT = fifosize * 4 / 8;
  1374. */
  1375. low = size * 4 / 8 / unit;
  1376. high = size * 5 / 8 / unit;
  1377. dispc_ovl_set_mflag_threshold(dispc, OMAP_DSS_WB, low, high);
  1378. }
  1379. }
  1380. static void dispc_ovl_set_fir(struct dispc_device *dispc,
  1381. enum omap_plane_id plane,
  1382. int hinc, int vinc,
  1383. enum omap_color_component color_comp)
  1384. {
  1385. u32 val;
  1386. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  1387. u8 hinc_start, hinc_end, vinc_start, vinc_end;
  1388. dispc_get_reg_field(dispc, FEAT_REG_FIRHINC,
  1389. &hinc_start, &hinc_end);
  1390. dispc_get_reg_field(dispc, FEAT_REG_FIRVINC,
  1391. &vinc_start, &vinc_end);
  1392. val = FLD_VAL(vinc, vinc_start, vinc_end) |
  1393. FLD_VAL(hinc, hinc_start, hinc_end);
  1394. dispc_write_reg(dispc, DISPC_OVL_FIR(plane), val);
  1395. } else {
  1396. val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
  1397. dispc_write_reg(dispc, DISPC_OVL_FIR2(plane), val);
  1398. }
  1399. }
  1400. static void dispc_ovl_set_vid_accu0(struct dispc_device *dispc,
  1401. enum omap_plane_id plane, int haccu,
  1402. int vaccu)
  1403. {
  1404. u32 val;
  1405. u8 hor_start, hor_end, vert_start, vert_end;
  1406. dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
  1407. &hor_start, &hor_end);
  1408. dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
  1409. &vert_start, &vert_end);
  1410. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1411. FLD_VAL(haccu, hor_start, hor_end);
  1412. dispc_write_reg(dispc, DISPC_OVL_ACCU0(plane), val);
  1413. }
  1414. static void dispc_ovl_set_vid_accu1(struct dispc_device *dispc,
  1415. enum omap_plane_id plane, int haccu,
  1416. int vaccu)
  1417. {
  1418. u32 val;
  1419. u8 hor_start, hor_end, vert_start, vert_end;
  1420. dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
  1421. &hor_start, &hor_end);
  1422. dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
  1423. &vert_start, &vert_end);
  1424. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1425. FLD_VAL(haccu, hor_start, hor_end);
  1426. dispc_write_reg(dispc, DISPC_OVL_ACCU1(plane), val);
  1427. }
  1428. static void dispc_ovl_set_vid_accu2_0(struct dispc_device *dispc,
  1429. enum omap_plane_id plane, int haccu,
  1430. int vaccu)
  1431. {
  1432. u32 val;
  1433. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1434. dispc_write_reg(dispc, DISPC_OVL_ACCU2_0(plane), val);
  1435. }
  1436. static void dispc_ovl_set_vid_accu2_1(struct dispc_device *dispc,
  1437. enum omap_plane_id plane, int haccu,
  1438. int vaccu)
  1439. {
  1440. u32 val;
  1441. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1442. dispc_write_reg(dispc, DISPC_OVL_ACCU2_1(plane), val);
  1443. }
  1444. static void dispc_ovl_set_scale_param(struct dispc_device *dispc,
  1445. enum omap_plane_id plane,
  1446. u16 orig_width, u16 orig_height,
  1447. u16 out_width, u16 out_height,
  1448. bool five_taps, u8 rotation,
  1449. enum omap_color_component color_comp)
  1450. {
  1451. int fir_hinc, fir_vinc;
  1452. fir_hinc = 1024 * orig_width / out_width;
  1453. fir_vinc = 1024 * orig_height / out_height;
  1454. dispc_ovl_set_scale_coef(dispc, plane, fir_hinc, fir_vinc, five_taps,
  1455. color_comp);
  1456. dispc_ovl_set_fir(dispc, plane, fir_hinc, fir_vinc, color_comp);
  1457. }
  1458. static void dispc_ovl_set_accu_uv(struct dispc_device *dispc,
  1459. enum omap_plane_id plane,
  1460. u16 orig_width, u16 orig_height,
  1461. u16 out_width, u16 out_height,
  1462. bool ilace, u32 fourcc, u8 rotation)
  1463. {
  1464. int h_accu2_0, h_accu2_1;
  1465. int v_accu2_0, v_accu2_1;
  1466. int chroma_hinc, chroma_vinc;
  1467. int idx;
  1468. struct accu {
  1469. s8 h0_m, h0_n;
  1470. s8 h1_m, h1_n;
  1471. s8 v0_m, v0_n;
  1472. s8 v1_m, v1_n;
  1473. };
  1474. const struct accu *accu_table;
  1475. const struct accu *accu_val;
  1476. static const struct accu accu_nv12[4] = {
  1477. { 0, 1, 0, 1 , -1, 2, 0, 1 },
  1478. { 1, 2, -3, 4 , 0, 1, 0, 1 },
  1479. { -1, 1, 0, 1 , -1, 2, 0, 1 },
  1480. { -1, 2, -1, 2 , -1, 1, 0, 1 },
  1481. };
  1482. static const struct accu accu_nv12_ilace[4] = {
  1483. { 0, 1, 0, 1 , -3, 4, -1, 4 },
  1484. { -1, 4, -3, 4 , 0, 1, 0, 1 },
  1485. { -1, 1, 0, 1 , -1, 4, -3, 4 },
  1486. { -3, 4, -3, 4 , -1, 1, 0, 1 },
  1487. };
  1488. static const struct accu accu_yuv[4] = {
  1489. { 0, 1, 0, 1, 0, 1, 0, 1 },
  1490. { 0, 1, 0, 1, 0, 1, 0, 1 },
  1491. { -1, 1, 0, 1, 0, 1, 0, 1 },
  1492. { 0, 1, 0, 1, -1, 1, 0, 1 },
  1493. };
  1494. /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
  1495. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1496. default:
  1497. case DRM_MODE_ROTATE_0:
  1498. idx = 0;
  1499. break;
  1500. case DRM_MODE_ROTATE_90:
  1501. idx = 3;
  1502. break;
  1503. case DRM_MODE_ROTATE_180:
  1504. idx = 2;
  1505. break;
  1506. case DRM_MODE_ROTATE_270:
  1507. idx = 1;
  1508. break;
  1509. }
  1510. switch (fourcc) {
  1511. case DRM_FORMAT_NV12:
  1512. if (ilace)
  1513. accu_table = accu_nv12_ilace;
  1514. else
  1515. accu_table = accu_nv12;
  1516. break;
  1517. case DRM_FORMAT_YUYV:
  1518. case DRM_FORMAT_UYVY:
  1519. accu_table = accu_yuv;
  1520. break;
  1521. default:
  1522. BUG();
  1523. return;
  1524. }
  1525. accu_val = &accu_table[idx];
  1526. chroma_hinc = 1024 * orig_width / out_width;
  1527. chroma_vinc = 1024 * orig_height / out_height;
  1528. h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
  1529. h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
  1530. v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
  1531. v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
  1532. dispc_ovl_set_vid_accu2_0(dispc, plane, h_accu2_0, v_accu2_0);
  1533. dispc_ovl_set_vid_accu2_1(dispc, plane, h_accu2_1, v_accu2_1);
  1534. }
  1535. static void dispc_ovl_set_scaling_common(struct dispc_device *dispc,
  1536. enum omap_plane_id plane,
  1537. u16 orig_width, u16 orig_height,
  1538. u16 out_width, u16 out_height,
  1539. bool ilace, bool five_taps,
  1540. bool fieldmode, u32 fourcc,
  1541. u8 rotation)
  1542. {
  1543. int accu0 = 0;
  1544. int accu1 = 0;
  1545. u32 l;
  1546. dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
  1547. out_width, out_height, five_taps,
  1548. rotation, DISPC_COLOR_COMPONENT_RGB_Y);
  1549. l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1550. /* RESIZEENABLE and VERTICALTAPS */
  1551. l &= ~((0x3 << 5) | (0x1 << 21));
  1552. l |= (orig_width != out_width) ? (1 << 5) : 0;
  1553. l |= (orig_height != out_height) ? (1 << 6) : 0;
  1554. l |= five_taps ? (1 << 21) : 0;
  1555. /* VRESIZECONF and HRESIZECONF */
  1556. if (dispc_has_feature(dispc, FEAT_RESIZECONF)) {
  1557. l &= ~(0x3 << 7);
  1558. l |= (orig_width <= out_width) ? 0 : (1 << 7);
  1559. l |= (orig_height <= out_height) ? 0 : (1 << 8);
  1560. }
  1561. /* LINEBUFFERSPLIT */
  1562. if (dispc_has_feature(dispc, FEAT_LINEBUFFERSPLIT)) {
  1563. l &= ~(0x1 << 22);
  1564. l |= five_taps ? (1 << 22) : 0;
  1565. }
  1566. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
  1567. /*
  1568. * field 0 = even field = bottom field
  1569. * field 1 = odd field = top field
  1570. */
  1571. if (ilace && !fieldmode) {
  1572. accu1 = 0;
  1573. accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
  1574. if (accu0 >= 1024/2) {
  1575. accu1 = 1024/2;
  1576. accu0 -= accu1;
  1577. }
  1578. }
  1579. dispc_ovl_set_vid_accu0(dispc, plane, 0, accu0);
  1580. dispc_ovl_set_vid_accu1(dispc, plane, 0, accu1);
  1581. }
  1582. static void dispc_ovl_set_scaling_uv(struct dispc_device *dispc,
  1583. enum omap_plane_id plane,
  1584. u16 orig_width, u16 orig_height,
  1585. u16 out_width, u16 out_height,
  1586. bool ilace, bool five_taps,
  1587. bool fieldmode, u32 fourcc,
  1588. u8 rotation)
  1589. {
  1590. int scale_x = out_width != orig_width;
  1591. int scale_y = out_height != orig_height;
  1592. bool chroma_upscale = plane != OMAP_DSS_WB;
  1593. const struct drm_format_info *info;
  1594. info = drm_format_info(fourcc);
  1595. if (!dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE))
  1596. return;
  1597. if (!info->is_yuv) {
  1598. /* reset chroma resampling for RGB formats */
  1599. if (plane != OMAP_DSS_WB)
  1600. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
  1601. 0, 8, 8);
  1602. return;
  1603. }
  1604. dispc_ovl_set_accu_uv(dispc, plane, orig_width, orig_height, out_width,
  1605. out_height, ilace, fourcc, rotation);
  1606. switch (fourcc) {
  1607. case DRM_FORMAT_NV12:
  1608. if (chroma_upscale) {
  1609. /* UV is subsampled by 2 horizontally and vertically */
  1610. orig_height >>= 1;
  1611. orig_width >>= 1;
  1612. } else {
  1613. /* UV is downsampled by 2 horizontally and vertically */
  1614. orig_height <<= 1;
  1615. orig_width <<= 1;
  1616. }
  1617. break;
  1618. case DRM_FORMAT_YUYV:
  1619. case DRM_FORMAT_UYVY:
  1620. /* For YUV422 with 90/270 rotation, we don't upsample chroma */
  1621. if (!drm_rotation_90_or_270(rotation)) {
  1622. if (chroma_upscale)
  1623. /* UV is subsampled by 2 horizontally */
  1624. orig_width >>= 1;
  1625. else
  1626. /* UV is downsampled by 2 horizontally */
  1627. orig_width <<= 1;
  1628. }
  1629. /* must use FIR for YUV422 if rotated */
  1630. if ((rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0)
  1631. scale_x = scale_y = true;
  1632. break;
  1633. default:
  1634. BUG();
  1635. return;
  1636. }
  1637. if (out_width != orig_width)
  1638. scale_x = true;
  1639. if (out_height != orig_height)
  1640. scale_y = true;
  1641. dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
  1642. out_width, out_height, five_taps,
  1643. rotation, DISPC_COLOR_COMPONENT_UV);
  1644. if (plane != OMAP_DSS_WB)
  1645. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
  1646. (scale_x || scale_y) ? 1 : 0, 8, 8);
  1647. /* set H scaling */
  1648. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
  1649. /* set V scaling */
  1650. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
  1651. }
  1652. static void dispc_ovl_set_scaling(struct dispc_device *dispc,
  1653. enum omap_plane_id plane,
  1654. u16 orig_width, u16 orig_height,
  1655. u16 out_width, u16 out_height,
  1656. bool ilace, bool five_taps,
  1657. bool fieldmode, u32 fourcc,
  1658. u8 rotation)
  1659. {
  1660. BUG_ON(plane == OMAP_DSS_GFX);
  1661. dispc_ovl_set_scaling_common(dispc, plane, orig_width, orig_height,
  1662. out_width, out_height, ilace, five_taps,
  1663. fieldmode, fourcc, rotation);
  1664. dispc_ovl_set_scaling_uv(dispc, plane, orig_width, orig_height,
  1665. out_width, out_height, ilace, five_taps,
  1666. fieldmode, fourcc, rotation);
  1667. }
  1668. static void dispc_ovl_set_rotation_attrs(struct dispc_device *dispc,
  1669. enum omap_plane_id plane, u8 rotation,
  1670. enum omap_dss_rotation_type rotation_type,
  1671. u32 fourcc)
  1672. {
  1673. bool row_repeat = false;
  1674. int vidrot = 0;
  1675. /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
  1676. if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY) {
  1677. if (rotation & DRM_MODE_REFLECT_X) {
  1678. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1679. case DRM_MODE_ROTATE_0:
  1680. vidrot = 2;
  1681. break;
  1682. case DRM_MODE_ROTATE_90:
  1683. vidrot = 1;
  1684. break;
  1685. case DRM_MODE_ROTATE_180:
  1686. vidrot = 0;
  1687. break;
  1688. case DRM_MODE_ROTATE_270:
  1689. vidrot = 3;
  1690. break;
  1691. }
  1692. } else {
  1693. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1694. case DRM_MODE_ROTATE_0:
  1695. vidrot = 0;
  1696. break;
  1697. case DRM_MODE_ROTATE_90:
  1698. vidrot = 3;
  1699. break;
  1700. case DRM_MODE_ROTATE_180:
  1701. vidrot = 2;
  1702. break;
  1703. case DRM_MODE_ROTATE_270:
  1704. vidrot = 1;
  1705. break;
  1706. }
  1707. }
  1708. if (drm_rotation_90_or_270(rotation))
  1709. row_repeat = true;
  1710. else
  1711. row_repeat = false;
  1712. }
  1713. /*
  1714. * OMAP4/5 Errata i631:
  1715. * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
  1716. * rows beyond the framebuffer, which may cause OCP error.
  1717. */
  1718. if (fourcc == DRM_FORMAT_NV12 && rotation_type != OMAP_DSS_ROT_TILER)
  1719. vidrot = 1;
  1720. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
  1721. if (dispc_has_feature(dispc, FEAT_ROWREPEATENABLE))
  1722. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
  1723. row_repeat ? 1 : 0, 18, 18);
  1724. if (dispc_ovl_color_mode_supported(dispc, plane, DRM_FORMAT_NV12)) {
  1725. bool doublestride =
  1726. fourcc == DRM_FORMAT_NV12 &&
  1727. rotation_type == OMAP_DSS_ROT_TILER &&
  1728. !drm_rotation_90_or_270(rotation);
  1729. /* DOUBLESTRIDE */
  1730. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
  1731. doublestride, 22, 22);
  1732. }
  1733. }
  1734. static int color_mode_to_bpp(u32 fourcc)
  1735. {
  1736. switch (fourcc) {
  1737. case DRM_FORMAT_NV12:
  1738. return 8;
  1739. case DRM_FORMAT_RGBX4444:
  1740. case DRM_FORMAT_RGB565:
  1741. case DRM_FORMAT_ARGB4444:
  1742. case DRM_FORMAT_YUYV:
  1743. case DRM_FORMAT_UYVY:
  1744. case DRM_FORMAT_RGBA4444:
  1745. case DRM_FORMAT_XRGB4444:
  1746. case DRM_FORMAT_ARGB1555:
  1747. case DRM_FORMAT_XRGB1555:
  1748. return 16;
  1749. case DRM_FORMAT_RGB888:
  1750. return 24;
  1751. case DRM_FORMAT_XRGB8888:
  1752. case DRM_FORMAT_ARGB8888:
  1753. case DRM_FORMAT_RGBA8888:
  1754. case DRM_FORMAT_RGBX8888:
  1755. return 32;
  1756. default:
  1757. BUG();
  1758. return 0;
  1759. }
  1760. }
  1761. static s32 pixinc(int pixels, u8 ps)
  1762. {
  1763. if (pixels == 1)
  1764. return 1;
  1765. else if (pixels > 1)
  1766. return 1 + (pixels - 1) * ps;
  1767. else if (pixels < 0)
  1768. return 1 - (-pixels + 1) * ps;
  1769. BUG();
  1770. }
  1771. static void calc_offset(u16 screen_width, u16 width,
  1772. u32 fourcc, bool fieldmode, unsigned int field_offset,
  1773. unsigned int *offset0, unsigned int *offset1,
  1774. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim,
  1775. enum omap_dss_rotation_type rotation_type, u8 rotation)
  1776. {
  1777. u8 ps;
  1778. ps = color_mode_to_bpp(fourcc) / 8;
  1779. DSSDBG("scrw %d, width %d\n", screen_width, width);
  1780. if (rotation_type == OMAP_DSS_ROT_TILER &&
  1781. (fourcc == DRM_FORMAT_UYVY || fourcc == DRM_FORMAT_YUYV) &&
  1782. drm_rotation_90_or_270(rotation)) {
  1783. /*
  1784. * HACK: ROW_INC needs to be calculated with TILER units.
  1785. * We get such 'screen_width' that multiplying it with the
  1786. * YUV422 pixel size gives the correct TILER container width.
  1787. * However, 'width' is in pixels and multiplying it with YUV422
  1788. * pixel size gives incorrect result. We thus multiply it here
  1789. * with 2 to match the 32 bit TILER unit size.
  1790. */
  1791. width *= 2;
  1792. }
  1793. /*
  1794. * field 0 = even field = bottom field
  1795. * field 1 = odd field = top field
  1796. */
  1797. *offset0 = field_offset * screen_width * ps;
  1798. *offset1 = 0;
  1799. *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
  1800. (fieldmode ? screen_width : 0), ps);
  1801. if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY)
  1802. *pix_inc = pixinc(x_predecim, 2 * ps);
  1803. else
  1804. *pix_inc = pixinc(x_predecim, ps);
  1805. }
  1806. /*
  1807. * This function is used to avoid synclosts in OMAP3, because of some
  1808. * undocumented horizontal position and timing related limitations.
  1809. */
  1810. static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
  1811. const struct videomode *vm, u16 pos_x,
  1812. u16 width, u16 height, u16 out_width, u16 out_height,
  1813. bool five_taps)
  1814. {
  1815. const int ds = DIV_ROUND_UP(height, out_height);
  1816. unsigned long nonactive;
  1817. static const u8 limits[3] = { 8, 10, 20 };
  1818. u64 val, blank;
  1819. int i;
  1820. nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
  1821. vm->hback_porch - out_width;
  1822. i = 0;
  1823. if (out_height < height)
  1824. i++;
  1825. if (out_width < width)
  1826. i++;
  1827. blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
  1828. lclk, pclk);
  1829. DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
  1830. if (blank <= limits[i])
  1831. return -EINVAL;
  1832. /* FIXME add checks for 3-tap filter once the limitations are known */
  1833. if (!five_taps)
  1834. return 0;
  1835. /*
  1836. * Pixel data should be prepared before visible display point starts.
  1837. * So, atleast DS-2 lines must have already been fetched by DISPC
  1838. * during nonactive - pos_x period.
  1839. */
  1840. val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
  1841. DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
  1842. val, max(0, ds - 2) * width);
  1843. if (val < max(0, ds - 2) * width)
  1844. return -EINVAL;
  1845. /*
  1846. * All lines need to be refilled during the nonactive period of which
  1847. * only one line can be loaded during the active period. So, atleast
  1848. * DS - 1 lines should be loaded during nonactive period.
  1849. */
  1850. val = div_u64((u64)nonactive * lclk, pclk);
  1851. DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
  1852. val, max(0, ds - 1) * width);
  1853. if (val < max(0, ds - 1) * width)
  1854. return -EINVAL;
  1855. return 0;
  1856. }
  1857. static unsigned long calc_core_clk_five_taps(unsigned long pclk,
  1858. const struct videomode *vm, u16 width,
  1859. u16 height, u16 out_width, u16 out_height,
  1860. u32 fourcc)
  1861. {
  1862. u32 core_clk = 0;
  1863. u64 tmp;
  1864. if (height <= out_height && width <= out_width)
  1865. return (unsigned long) pclk;
  1866. if (height > out_height) {
  1867. unsigned int ppl = vm->hactive;
  1868. tmp = (u64)pclk * height * out_width;
  1869. do_div(tmp, 2 * out_height * ppl);
  1870. core_clk = tmp;
  1871. if (height > 2 * out_height) {
  1872. if (ppl == out_width)
  1873. return 0;
  1874. tmp = (u64)pclk * (height - 2 * out_height) * out_width;
  1875. do_div(tmp, 2 * out_height * (ppl - out_width));
  1876. core_clk = max_t(u32, core_clk, tmp);
  1877. }
  1878. }
  1879. if (width > out_width) {
  1880. tmp = (u64)pclk * width;
  1881. do_div(tmp, out_width);
  1882. core_clk = max_t(u32, core_clk, tmp);
  1883. if (fourcc == DRM_FORMAT_XRGB8888)
  1884. core_clk <<= 1;
  1885. }
  1886. return core_clk;
  1887. }
  1888. static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
  1889. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1890. {
  1891. if (height > out_height && width > out_width)
  1892. return pclk * 4;
  1893. else
  1894. return pclk * 2;
  1895. }
  1896. static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
  1897. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1898. {
  1899. unsigned int hf, vf;
  1900. /*
  1901. * FIXME how to determine the 'A' factor
  1902. * for the no downscaling case ?
  1903. */
  1904. if (width > 3 * out_width)
  1905. hf = 4;
  1906. else if (width > 2 * out_width)
  1907. hf = 3;
  1908. else if (width > out_width)
  1909. hf = 2;
  1910. else
  1911. hf = 1;
  1912. if (height > out_height)
  1913. vf = 2;
  1914. else
  1915. vf = 1;
  1916. return pclk * vf * hf;
  1917. }
  1918. static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
  1919. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1920. {
  1921. /*
  1922. * If the overlay/writeback is in mem to mem mode, there are no
  1923. * downscaling limitations with respect to pixel clock, return 1 as
  1924. * required core clock to represent that we have sufficient enough
  1925. * core clock to do maximum downscaling
  1926. */
  1927. if (mem_to_mem)
  1928. return 1;
  1929. if (width > out_width)
  1930. return DIV_ROUND_UP(pclk, out_width) * width;
  1931. else
  1932. return pclk;
  1933. }
  1934. static int dispc_ovl_calc_scaling_24xx(struct dispc_device *dispc,
  1935. unsigned long pclk, unsigned long lclk,
  1936. const struct videomode *vm,
  1937. u16 width, u16 height,
  1938. u16 out_width, u16 out_height,
  1939. u32 fourcc, bool *five_taps,
  1940. int *x_predecim, int *y_predecim,
  1941. int *decim_x, int *decim_y,
  1942. u16 pos_x, unsigned long *core_clk,
  1943. bool mem_to_mem)
  1944. {
  1945. int error;
  1946. u16 in_width, in_height;
  1947. int min_factor = min(*decim_x, *decim_y);
  1948. const int maxsinglelinewidth = dispc->feat->max_line_width;
  1949. *five_taps = false;
  1950. do {
  1951. in_height = height / *decim_y;
  1952. in_width = width / *decim_x;
  1953. *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
  1954. in_height, out_width, out_height, mem_to_mem);
  1955. error = (in_width > maxsinglelinewidth || !*core_clk ||
  1956. *core_clk > dispc_core_clk_rate(dispc));
  1957. if (error) {
  1958. if (*decim_x == *decim_y) {
  1959. *decim_x = min_factor;
  1960. ++*decim_y;
  1961. } else {
  1962. swap(*decim_x, *decim_y);
  1963. if (*decim_x < *decim_y)
  1964. ++*decim_x;
  1965. }
  1966. }
  1967. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  1968. if (error) {
  1969. DSSERR("failed to find scaling settings\n");
  1970. return -EINVAL;
  1971. }
  1972. if (in_width > maxsinglelinewidth) {
  1973. DSSERR("Cannot scale max input width exceeded\n");
  1974. return -EINVAL;
  1975. }
  1976. return 0;
  1977. }
  1978. static int dispc_ovl_calc_scaling_34xx(struct dispc_device *dispc,
  1979. unsigned long pclk, unsigned long lclk,
  1980. const struct videomode *vm,
  1981. u16 width, u16 height,
  1982. u16 out_width, u16 out_height,
  1983. u32 fourcc, bool *five_taps,
  1984. int *x_predecim, int *y_predecim,
  1985. int *decim_x, int *decim_y,
  1986. u16 pos_x, unsigned long *core_clk,
  1987. bool mem_to_mem)
  1988. {
  1989. int error;
  1990. u16 in_width, in_height;
  1991. const int maxsinglelinewidth = dispc->feat->max_line_width;
  1992. do {
  1993. in_height = height / *decim_y;
  1994. in_width = width / *decim_x;
  1995. *five_taps = in_height > out_height;
  1996. if (in_width > maxsinglelinewidth)
  1997. if (in_height > out_height &&
  1998. in_height < out_height * 2)
  1999. *five_taps = false;
  2000. again:
  2001. if (*five_taps)
  2002. *core_clk = calc_core_clk_five_taps(pclk, vm,
  2003. in_width, in_height, out_width,
  2004. out_height, fourcc);
  2005. else
  2006. *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
  2007. in_height, out_width, out_height,
  2008. mem_to_mem);
  2009. error = check_horiz_timing_omap3(pclk, lclk, vm,
  2010. pos_x, in_width, in_height, out_width,
  2011. out_height, *five_taps);
  2012. if (error && *five_taps) {
  2013. *five_taps = false;
  2014. goto again;
  2015. }
  2016. error = (error || in_width > maxsinglelinewidth * 2 ||
  2017. (in_width > maxsinglelinewidth && *five_taps) ||
  2018. !*core_clk || *core_clk > dispc_core_clk_rate(dispc));
  2019. if (!error) {
  2020. /* verify that we're inside the limits of scaler */
  2021. if (in_width / 4 > out_width)
  2022. error = 1;
  2023. if (*five_taps) {
  2024. if (in_height / 4 > out_height)
  2025. error = 1;
  2026. } else {
  2027. if (in_height / 2 > out_height)
  2028. error = 1;
  2029. }
  2030. }
  2031. if (error)
  2032. ++*decim_y;
  2033. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  2034. if (error) {
  2035. DSSERR("failed to find scaling settings\n");
  2036. return -EINVAL;
  2037. }
  2038. if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
  2039. in_height, out_width, out_height, *five_taps)) {
  2040. DSSERR("horizontal timing too tight\n");
  2041. return -EINVAL;
  2042. }
  2043. if (in_width > (maxsinglelinewidth * 2)) {
  2044. DSSERR("Cannot setup scaling\n");
  2045. DSSERR("width exceeds maximum width possible\n");
  2046. return -EINVAL;
  2047. }
  2048. if (in_width > maxsinglelinewidth && *five_taps) {
  2049. DSSERR("cannot setup scaling with five taps\n");
  2050. return -EINVAL;
  2051. }
  2052. return 0;
  2053. }
  2054. static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc,
  2055. unsigned long pclk, unsigned long lclk,
  2056. const struct videomode *vm,
  2057. u16 width, u16 height,
  2058. u16 out_width, u16 out_height,
  2059. u32 fourcc, bool *five_taps,
  2060. int *x_predecim, int *y_predecim,
  2061. int *decim_x, int *decim_y,
  2062. u16 pos_x, unsigned long *core_clk,
  2063. bool mem_to_mem)
  2064. {
  2065. u16 in_width, in_width_max;
  2066. int decim_x_min = *decim_x;
  2067. u16 in_height = height / *decim_y;
  2068. const int maxsinglelinewidth = dispc->feat->max_line_width;
  2069. const int maxdownscale = dispc->feat->max_downscale;
  2070. if (mem_to_mem) {
  2071. in_width_max = out_width * maxdownscale;
  2072. } else {
  2073. in_width_max = dispc_core_clk_rate(dispc)
  2074. / DIV_ROUND_UP(pclk, out_width);
  2075. }
  2076. *decim_x = DIV_ROUND_UP(width, in_width_max);
  2077. *decim_x = max(*decim_x, decim_x_min);
  2078. if (*decim_x > *x_predecim)
  2079. return -EINVAL;
  2080. do {
  2081. in_width = width / *decim_x;
  2082. } while (*decim_x <= *x_predecim &&
  2083. in_width > maxsinglelinewidth && ++*decim_x);
  2084. if (in_width > maxsinglelinewidth) {
  2085. DSSERR("Cannot scale width exceeds max line width\n");
  2086. return -EINVAL;
  2087. }
  2088. if (*decim_x > 4 && fourcc != DRM_FORMAT_NV12) {
  2089. /*
  2090. * Let's disable all scaling that requires horizontal
  2091. * decimation with higher factor than 4, until we have
  2092. * better estimates of what we can and can not
  2093. * do. However, NV12 color format appears to work Ok
  2094. * with all decimation factors.
  2095. *
  2096. * When decimating horizontally by more that 4 the dss
  2097. * is not able to fetch the data in burst mode. When
  2098. * this happens it is hard to tell if there enough
  2099. * bandwidth. Despite what theory says this appears to
  2100. * be true also for 16-bit color formats.
  2101. */
  2102. DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)\n", *decim_x);
  2103. return -EINVAL;
  2104. }
  2105. *core_clk = dispc->feat->calc_core_clk(pclk, in_width, in_height,
  2106. out_width, out_height, mem_to_mem);
  2107. return 0;
  2108. }
  2109. enum omap_overlay_caps dispc_ovl_get_caps(struct dispc_device *dispc, enum omap_plane_id plane)
  2110. {
  2111. return dispc->feat->overlay_caps[plane];
  2112. }
  2113. #define DIV_FRAC(dividend, divisor) \
  2114. ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
  2115. static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
  2116. enum omap_plane_id plane,
  2117. unsigned long pclk, unsigned long lclk,
  2118. enum omap_overlay_caps caps,
  2119. const struct videomode *vm,
  2120. u16 width, u16 height,
  2121. u16 out_width, u16 out_height,
  2122. u32 fourcc, bool *five_taps,
  2123. int *x_predecim, int *y_predecim, u16 pos_x,
  2124. enum omap_dss_rotation_type rotation_type,
  2125. bool mem_to_mem)
  2126. {
  2127. int maxhdownscale = dispc->feat->max_downscale;
  2128. int maxvdownscale = dispc->feat->max_downscale;
  2129. const int max_decim_limit = 16;
  2130. unsigned long core_clk = 0;
  2131. int decim_x, decim_y, ret;
  2132. if (width == out_width && height == out_height)
  2133. return 0;
  2134. if (dispc->feat->supported_scaler_color_modes) {
  2135. const u32 *modes = dispc->feat->supported_scaler_color_modes;
  2136. unsigned int i;
  2137. for (i = 0; modes[i]; ++i) {
  2138. if (modes[i] == fourcc)
  2139. break;
  2140. }
  2141. if (modes[i] == 0)
  2142. return -EINVAL;
  2143. }
  2144. if (plane == OMAP_DSS_WB) {
  2145. switch (fourcc) {
  2146. case DRM_FORMAT_NV12:
  2147. maxhdownscale = maxvdownscale = 2;
  2148. break;
  2149. case DRM_FORMAT_YUYV:
  2150. case DRM_FORMAT_UYVY:
  2151. maxhdownscale = 2;
  2152. maxvdownscale = 4;
  2153. break;
  2154. default:
  2155. break;
  2156. }
  2157. }
  2158. if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
  2159. DSSERR("cannot calculate scaling settings: pclk is zero\n");
  2160. return -EINVAL;
  2161. }
  2162. if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
  2163. return -EINVAL;
  2164. if (mem_to_mem) {
  2165. *x_predecim = *y_predecim = 1;
  2166. } else {
  2167. *x_predecim = max_decim_limit;
  2168. *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
  2169. dispc_has_feature(dispc, FEAT_BURST_2D)) ?
  2170. 2 : max_decim_limit;
  2171. }
  2172. decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxhdownscale);
  2173. decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxvdownscale);
  2174. if (decim_x > *x_predecim || out_width > width * 8)
  2175. return -EINVAL;
  2176. if (decim_y > *y_predecim || out_height > height * 8)
  2177. return -EINVAL;
  2178. ret = dispc->feat->calc_scaling(dispc, pclk, lclk, vm, width, height,
  2179. out_width, out_height, fourcc,
  2180. five_taps, x_predecim, y_predecim,
  2181. &decim_x, &decim_y, pos_x, &core_clk,
  2182. mem_to_mem);
  2183. if (ret)
  2184. return ret;
  2185. DSSDBG("%dx%d -> %dx%d (%d.%02d x %d.%02d), decim %dx%d %dx%d (%d.%02d x %d.%02d), taps %d, req clk %lu, cur clk %lu\n",
  2186. width, height,
  2187. out_width, out_height,
  2188. out_width / width, DIV_FRAC(out_width, width),
  2189. out_height / height, DIV_FRAC(out_height, height),
  2190. decim_x, decim_y,
  2191. width / decim_x, height / decim_y,
  2192. out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
  2193. out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
  2194. *five_taps ? 5 : 3,
  2195. core_clk, dispc_core_clk_rate(dispc));
  2196. if (!core_clk || core_clk > dispc_core_clk_rate(dispc)) {
  2197. DSSERR("failed to set up scaling, "
  2198. "required core clk rate = %lu Hz, "
  2199. "current core clk rate = %lu Hz\n",
  2200. core_clk, dispc_core_clk_rate(dispc));
  2201. return -EINVAL;
  2202. }
  2203. *x_predecim = decim_x;
  2204. *y_predecim = decim_y;
  2205. return 0;
  2206. }
  2207. void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height)
  2208. {
  2209. *width = dispc->feat->ovl_width_max;
  2210. *height = dispc->feat->ovl_height_max;
  2211. }
  2212. static int dispc_ovl_setup_common(struct dispc_device *dispc,
  2213. enum omap_plane_id plane,
  2214. enum omap_overlay_caps caps,
  2215. u32 paddr, u32 p_uv_addr,
  2216. u16 screen_width, int pos_x, int pos_y,
  2217. u16 width, u16 height,
  2218. u16 out_width, u16 out_height,
  2219. u32 fourcc, u8 rotation, u8 zorder,
  2220. u8 pre_mult_alpha, u8 global_alpha,
  2221. enum omap_dss_rotation_type rotation_type,
  2222. bool replication, const struct videomode *vm,
  2223. bool mem_to_mem,
  2224. enum drm_color_encoding color_encoding,
  2225. enum drm_color_range color_range)
  2226. {
  2227. bool five_taps = true;
  2228. bool fieldmode = false;
  2229. int r, cconv = 0;
  2230. unsigned int offset0, offset1;
  2231. s32 row_inc;
  2232. s32 pix_inc;
  2233. u16 frame_width;
  2234. unsigned int field_offset = 0;
  2235. u16 in_height = height;
  2236. u16 in_width = width;
  2237. int x_predecim = 1, y_predecim = 1;
  2238. bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
  2239. unsigned long pclk = dispc_plane_pclk_rate(dispc, plane);
  2240. unsigned long lclk = dispc_plane_lclk_rate(dispc, plane);
  2241. const struct drm_format_info *info;
  2242. info = drm_format_info(fourcc);
  2243. /* when setting up WB, dispc_plane_pclk_rate() returns 0 */
  2244. if (plane == OMAP_DSS_WB)
  2245. pclk = vm->pixelclock;
  2246. if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
  2247. return -EINVAL;
  2248. if (info->is_yuv && (in_width & 1)) {
  2249. DSSERR("input width %d is not even for YUV format\n", in_width);
  2250. return -EINVAL;
  2251. }
  2252. out_width = out_width == 0 ? width : out_width;
  2253. out_height = out_height == 0 ? height : out_height;
  2254. if (plane != OMAP_DSS_WB) {
  2255. if (ilace && height == out_height)
  2256. fieldmode = true;
  2257. if (ilace) {
  2258. if (fieldmode)
  2259. in_height /= 2;
  2260. pos_y /= 2;
  2261. out_height /= 2;
  2262. DSSDBG("adjusting for ilace: height %d, pos_y %d, out_height %d\n",
  2263. in_height, pos_y, out_height);
  2264. }
  2265. }
  2266. if (!dispc_ovl_color_mode_supported(dispc, plane, fourcc))
  2267. return -EINVAL;
  2268. r = dispc_ovl_calc_scaling(dispc, plane, pclk, lclk, caps, vm, in_width,
  2269. in_height, out_width, out_height, fourcc,
  2270. &five_taps, &x_predecim, &y_predecim, pos_x,
  2271. rotation_type, mem_to_mem);
  2272. if (r)
  2273. return r;
  2274. in_width = in_width / x_predecim;
  2275. in_height = in_height / y_predecim;
  2276. if (x_predecim > 1 || y_predecim > 1)
  2277. DSSDBG("predecimation %d x %x, new input size %d x %d\n",
  2278. x_predecim, y_predecim, in_width, in_height);
  2279. if (info->is_yuv && (in_width & 1)) {
  2280. DSSDBG("predecimated input width is not even for YUV format\n");
  2281. DSSDBG("adjusting input width %d -> %d\n",
  2282. in_width, in_width & ~1);
  2283. in_width &= ~1;
  2284. }
  2285. if (info->is_yuv)
  2286. cconv = 1;
  2287. if (ilace && !fieldmode) {
  2288. /*
  2289. * when downscaling the bottom field may have to start several
  2290. * source lines below the top field. Unfortunately ACCUI
  2291. * registers will only hold the fractional part of the offset
  2292. * so the integer part must be added to the base address of the
  2293. * bottom field.
  2294. */
  2295. if (!in_height || in_height == out_height)
  2296. field_offset = 0;
  2297. else
  2298. field_offset = in_height / out_height / 2;
  2299. }
  2300. /* Fields are independent but interleaved in memory. */
  2301. if (fieldmode)
  2302. field_offset = 1;
  2303. offset0 = 0;
  2304. offset1 = 0;
  2305. row_inc = 0;
  2306. pix_inc = 0;
  2307. if (plane == OMAP_DSS_WB)
  2308. frame_width = out_width;
  2309. else
  2310. frame_width = in_width;
  2311. calc_offset(screen_width, frame_width,
  2312. fourcc, fieldmode, field_offset,
  2313. &offset0, &offset1, &row_inc, &pix_inc,
  2314. x_predecim, y_predecim,
  2315. rotation_type, rotation);
  2316. DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
  2317. offset0, offset1, row_inc, pix_inc);
  2318. dispc_ovl_set_color_mode(dispc, plane, fourcc);
  2319. dispc_ovl_configure_burst_type(dispc, plane, rotation_type);
  2320. if (dispc->feat->reverse_ilace_field_order)
  2321. swap(offset0, offset1);
  2322. dispc_ovl_set_ba0(dispc, plane, paddr + offset0);
  2323. dispc_ovl_set_ba1(dispc, plane, paddr + offset1);
  2324. if (fourcc == DRM_FORMAT_NV12) {
  2325. dispc_ovl_set_ba0_uv(dispc, plane, p_uv_addr + offset0);
  2326. dispc_ovl_set_ba1_uv(dispc, plane, p_uv_addr + offset1);
  2327. }
  2328. if (dispc->feat->last_pixel_inc_missing)
  2329. row_inc += pix_inc - 1;
  2330. dispc_ovl_set_row_inc(dispc, plane, row_inc);
  2331. dispc_ovl_set_pix_inc(dispc, plane, pix_inc);
  2332. DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
  2333. in_height, out_width, out_height);
  2334. dispc_ovl_set_pos(dispc, plane, caps, pos_x, pos_y);
  2335. dispc_ovl_set_input_size(dispc, plane, in_width, in_height);
  2336. if (caps & OMAP_DSS_OVL_CAP_SCALE) {
  2337. dispc_ovl_set_scaling(dispc, plane, in_width, in_height,
  2338. out_width, out_height, ilace, five_taps,
  2339. fieldmode, fourcc, rotation);
  2340. dispc_ovl_set_output_size(dispc, plane, out_width, out_height);
  2341. dispc_ovl_set_vid_color_conv(dispc, plane, cconv);
  2342. if (plane != OMAP_DSS_WB)
  2343. dispc_ovl_set_csc(dispc, plane, color_encoding, color_range);
  2344. }
  2345. dispc_ovl_set_rotation_attrs(dispc, plane, rotation, rotation_type,
  2346. fourcc);
  2347. dispc_ovl_set_zorder(dispc, plane, caps, zorder);
  2348. dispc_ovl_set_pre_mult_alpha(dispc, plane, caps, pre_mult_alpha);
  2349. dispc_ovl_setup_global_alpha(dispc, plane, caps, global_alpha);
  2350. dispc_ovl_enable_replication(dispc, plane, caps, replication);
  2351. return 0;
  2352. }
  2353. int dispc_ovl_setup(struct dispc_device *dispc,
  2354. enum omap_plane_id plane,
  2355. const struct omap_overlay_info *oi,
  2356. const struct videomode *vm, bool mem_to_mem,
  2357. enum omap_channel channel)
  2358. {
  2359. int r;
  2360. enum omap_overlay_caps caps = dispc->feat->overlay_caps[plane];
  2361. const bool replication = true;
  2362. DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
  2363. " %dx%d, cmode %x, rot %d, chan %d repl %d\n",
  2364. plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
  2365. oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
  2366. oi->fourcc, oi->rotation, channel, replication);
  2367. dispc_ovl_set_channel_out(dispc, plane, channel);
  2368. r = dispc_ovl_setup_common(dispc, plane, caps, oi->paddr, oi->p_uv_addr,
  2369. oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
  2370. oi->out_width, oi->out_height, oi->fourcc, oi->rotation,
  2371. oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
  2372. oi->rotation_type, replication, vm, mem_to_mem,
  2373. oi->color_encoding, oi->color_range);
  2374. return r;
  2375. }
  2376. int dispc_wb_setup(struct dispc_device *dispc,
  2377. const struct omap_dss_writeback_info *wi,
  2378. bool mem_to_mem, const struct videomode *vm,
  2379. enum dss_writeback_channel channel_in)
  2380. {
  2381. int r;
  2382. u32 l;
  2383. enum omap_plane_id plane = OMAP_DSS_WB;
  2384. const int pos_x = 0, pos_y = 0;
  2385. const u8 zorder = 0, global_alpha = 0;
  2386. const bool replication = true;
  2387. bool truncation;
  2388. int in_width = vm->hactive;
  2389. int in_height = vm->vactive;
  2390. enum omap_overlay_caps caps =
  2391. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
  2392. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2393. in_height /= 2;
  2394. DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
  2395. "rot %d\n", wi->paddr, wi->p_uv_addr, in_width,
  2396. in_height, wi->width, wi->height, wi->fourcc, wi->rotation);
  2397. r = dispc_ovl_setup_common(dispc, plane, caps, wi->paddr, wi->p_uv_addr,
  2398. wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
  2399. wi->height, wi->fourcc, wi->rotation, zorder,
  2400. wi->pre_mult_alpha, global_alpha, wi->rotation_type,
  2401. replication, vm, mem_to_mem, DRM_COLOR_YCBCR_BT601,
  2402. DRM_COLOR_YCBCR_LIMITED_RANGE);
  2403. if (r)
  2404. return r;
  2405. switch (wi->fourcc) {
  2406. case DRM_FORMAT_RGB565:
  2407. case DRM_FORMAT_RGB888:
  2408. case DRM_FORMAT_ARGB4444:
  2409. case DRM_FORMAT_RGBA4444:
  2410. case DRM_FORMAT_RGBX4444:
  2411. case DRM_FORMAT_ARGB1555:
  2412. case DRM_FORMAT_XRGB1555:
  2413. case DRM_FORMAT_XRGB4444:
  2414. truncation = true;
  2415. break;
  2416. default:
  2417. truncation = false;
  2418. break;
  2419. }
  2420. /* setup extra DISPC_WB_ATTRIBUTES */
  2421. l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  2422. l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
  2423. l = FLD_MOD(l, channel_in, 18, 16); /* CHANNELIN */
  2424. l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
  2425. if (mem_to_mem)
  2426. l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
  2427. else
  2428. l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
  2429. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
  2430. if (mem_to_mem) {
  2431. /* WBDELAYCOUNT */
  2432. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
  2433. } else {
  2434. u32 wbdelay;
  2435. if (channel_in == DSS_WB_TV_MGR)
  2436. wbdelay = vm->vsync_len + vm->vback_porch;
  2437. else
  2438. wbdelay = vm->vfront_porch + vm->vsync_len +
  2439. vm->vback_porch;
  2440. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2441. wbdelay /= 2;
  2442. wbdelay = min(wbdelay, 255u);
  2443. /* WBDELAYCOUNT */
  2444. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
  2445. }
  2446. return 0;
  2447. }
  2448. bool dispc_has_writeback(struct dispc_device *dispc)
  2449. {
  2450. return dispc->feat->has_writeback;
  2451. }
  2452. int dispc_ovl_enable(struct dispc_device *dispc,
  2453. enum omap_plane_id plane, bool enable)
  2454. {
  2455. DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
  2456. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
  2457. return 0;
  2458. }
  2459. static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc,
  2460. bool act_high)
  2461. {
  2462. if (!dispc_has_feature(dispc, FEAT_LCDENABLEPOL))
  2463. return;
  2464. REG_FLD_MOD(dispc, DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
  2465. }
  2466. void dispc_lcd_enable_signal(struct dispc_device *dispc, bool enable)
  2467. {
  2468. if (!dispc_has_feature(dispc, FEAT_LCDENABLESIGNAL))
  2469. return;
  2470. REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 28, 28);
  2471. }
  2472. void dispc_pck_free_enable(struct dispc_device *dispc, bool enable)
  2473. {
  2474. if (!dispc_has_feature(dispc, FEAT_PCKFREEENABLE))
  2475. return;
  2476. REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 27, 27);
  2477. }
  2478. static void dispc_mgr_enable_fifohandcheck(struct dispc_device *dispc,
  2479. enum omap_channel channel,
  2480. bool enable)
  2481. {
  2482. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
  2483. }
  2484. static void dispc_mgr_set_lcd_type_tft(struct dispc_device *dispc,
  2485. enum omap_channel channel)
  2486. {
  2487. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STNTFT, 1);
  2488. }
  2489. static void dispc_set_loadmode(struct dispc_device *dispc,
  2490. enum omap_dss_load_mode mode)
  2491. {
  2492. REG_FLD_MOD(dispc, DISPC_CONFIG, mode, 2, 1);
  2493. }
  2494. static void dispc_mgr_set_default_color(struct dispc_device *dispc,
  2495. enum omap_channel channel, u32 color)
  2496. {
  2497. dispc_write_reg(dispc, DISPC_DEFAULT_COLOR(channel), color);
  2498. }
  2499. static void dispc_mgr_set_trans_key(struct dispc_device *dispc,
  2500. enum omap_channel ch,
  2501. enum omap_dss_trans_key_type type,
  2502. u32 trans_key)
  2503. {
  2504. mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKSELECTION, type);
  2505. dispc_write_reg(dispc, DISPC_TRANS_COLOR(ch), trans_key);
  2506. }
  2507. static void dispc_mgr_enable_trans_key(struct dispc_device *dispc,
  2508. enum omap_channel ch, bool enable)
  2509. {
  2510. mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKENABLE, enable);
  2511. }
  2512. static void dispc_mgr_enable_alpha_fixed_zorder(struct dispc_device *dispc,
  2513. enum omap_channel ch,
  2514. bool enable)
  2515. {
  2516. if (!dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER))
  2517. return;
  2518. if (ch == OMAP_DSS_CHANNEL_LCD)
  2519. REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 18, 18);
  2520. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  2521. REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 19, 19);
  2522. }
  2523. void dispc_mgr_setup(struct dispc_device *dispc,
  2524. enum omap_channel channel,
  2525. const struct omap_overlay_manager_info *info)
  2526. {
  2527. dispc_mgr_set_default_color(dispc, channel, info->default_color);
  2528. dispc_mgr_set_trans_key(dispc, channel, info->trans_key_type,
  2529. info->trans_key);
  2530. dispc_mgr_enable_trans_key(dispc, channel, info->trans_enabled);
  2531. dispc_mgr_enable_alpha_fixed_zorder(dispc, channel,
  2532. info->partial_alpha_enabled);
  2533. if (dispc_has_feature(dispc, FEAT_CPR)) {
  2534. dispc_mgr_enable_cpr(dispc, channel, info->cpr_enable);
  2535. dispc_mgr_set_cpr_coef(dispc, channel, &info->cpr_coefs);
  2536. }
  2537. }
  2538. static void dispc_mgr_set_tft_data_lines(struct dispc_device *dispc,
  2539. enum omap_channel channel,
  2540. u8 data_lines)
  2541. {
  2542. int code;
  2543. switch (data_lines) {
  2544. case 12:
  2545. code = 0;
  2546. break;
  2547. case 16:
  2548. code = 1;
  2549. break;
  2550. case 18:
  2551. code = 2;
  2552. break;
  2553. case 24:
  2554. code = 3;
  2555. break;
  2556. default:
  2557. BUG();
  2558. return;
  2559. }
  2560. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_TFTDATALINES, code);
  2561. }
  2562. static void dispc_mgr_set_io_pad_mode(struct dispc_device *dispc,
  2563. enum dss_io_pad_mode mode)
  2564. {
  2565. u32 l;
  2566. int gpout0, gpout1;
  2567. switch (mode) {
  2568. case DSS_IO_PAD_MODE_RESET:
  2569. gpout0 = 0;
  2570. gpout1 = 0;
  2571. break;
  2572. case DSS_IO_PAD_MODE_RFBI:
  2573. gpout0 = 1;
  2574. gpout1 = 0;
  2575. break;
  2576. case DSS_IO_PAD_MODE_BYPASS:
  2577. gpout0 = 1;
  2578. gpout1 = 1;
  2579. break;
  2580. default:
  2581. BUG();
  2582. return;
  2583. }
  2584. l = dispc_read_reg(dispc, DISPC_CONTROL);
  2585. l = FLD_MOD(l, gpout0, 15, 15);
  2586. l = FLD_MOD(l, gpout1, 16, 16);
  2587. dispc_write_reg(dispc, DISPC_CONTROL, l);
  2588. }
  2589. static void dispc_mgr_enable_stallmode(struct dispc_device *dispc,
  2590. enum omap_channel channel, bool enable)
  2591. {
  2592. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STALLMODE, enable);
  2593. }
  2594. void dispc_mgr_set_lcd_config(struct dispc_device *dispc,
  2595. enum omap_channel channel,
  2596. const struct dss_lcd_mgr_config *config)
  2597. {
  2598. dispc_mgr_set_io_pad_mode(dispc, config->io_pad_mode);
  2599. dispc_mgr_enable_stallmode(dispc, channel, config->stallmode);
  2600. dispc_mgr_enable_fifohandcheck(dispc, channel, config->fifohandcheck);
  2601. dispc_mgr_set_clock_div(dispc, channel, &config->clock_info);
  2602. dispc_mgr_set_tft_data_lines(dispc, channel, config->video_port_width);
  2603. dispc_lcd_enable_signal_polarity(dispc, config->lcden_sig_polarity);
  2604. dispc_mgr_set_lcd_type_tft(dispc, channel);
  2605. }
  2606. static bool _dispc_mgr_size_ok(struct dispc_device *dispc,
  2607. u16 width, u16 height)
  2608. {
  2609. return width <= dispc->feat->mgr_width_max &&
  2610. height <= dispc->feat->mgr_height_max;
  2611. }
  2612. static bool _dispc_lcd_timings_ok(struct dispc_device *dispc,
  2613. int hsync_len, int hfp, int hbp,
  2614. int vsw, int vfp, int vbp)
  2615. {
  2616. if (hsync_len < 1 || hsync_len > dispc->feat->sw_max ||
  2617. hfp < 1 || hfp > dispc->feat->hp_max ||
  2618. hbp < 1 || hbp > dispc->feat->hp_max ||
  2619. vsw < 1 || vsw > dispc->feat->sw_max ||
  2620. vfp < 0 || vfp > dispc->feat->vp_max ||
  2621. vbp < 0 || vbp > dispc->feat->vp_max)
  2622. return false;
  2623. return true;
  2624. }
  2625. static bool _dispc_mgr_pclk_ok(struct dispc_device *dispc,
  2626. enum omap_channel channel,
  2627. unsigned long pclk)
  2628. {
  2629. if (dss_mgr_is_lcd(channel))
  2630. return pclk <= dispc->feat->max_lcd_pclk;
  2631. else
  2632. return pclk <= dispc->feat->max_tv_pclk;
  2633. }
  2634. int dispc_mgr_check_timings(struct dispc_device *dispc,
  2635. enum omap_channel channel,
  2636. const struct videomode *vm)
  2637. {
  2638. if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive))
  2639. return MODE_BAD;
  2640. if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock))
  2641. return MODE_BAD;
  2642. if (dss_mgr_is_lcd(channel)) {
  2643. /* TODO: OMAP4+ supports interlace for LCD outputs */
  2644. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2645. return MODE_BAD;
  2646. if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len,
  2647. vm->hfront_porch, vm->hback_porch,
  2648. vm->vsync_len, vm->vfront_porch,
  2649. vm->vback_porch))
  2650. return MODE_BAD;
  2651. }
  2652. return MODE_OK;
  2653. }
  2654. static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc,
  2655. enum omap_channel channel,
  2656. const struct videomode *vm)
  2657. {
  2658. u32 timing_h, timing_v, l;
  2659. bool onoff, rf, ipc, vs, hs, de;
  2660. timing_h = FLD_VAL(vm->hsync_len - 1, dispc->feat->sw_start, 0) |
  2661. FLD_VAL(vm->hfront_porch - 1, dispc->feat->fp_start, 8) |
  2662. FLD_VAL(vm->hback_porch - 1, dispc->feat->bp_start, 20);
  2663. timing_v = FLD_VAL(vm->vsync_len - 1, dispc->feat->sw_start, 0) |
  2664. FLD_VAL(vm->vfront_porch, dispc->feat->fp_start, 8) |
  2665. FLD_VAL(vm->vback_porch, dispc->feat->bp_start, 20);
  2666. dispc_write_reg(dispc, DISPC_TIMING_H(channel), timing_h);
  2667. dispc_write_reg(dispc, DISPC_TIMING_V(channel), timing_v);
  2668. vs = !!(vm->flags & DISPLAY_FLAGS_VSYNC_LOW);
  2669. hs = !!(vm->flags & DISPLAY_FLAGS_HSYNC_LOW);
  2670. de = !!(vm->flags & DISPLAY_FLAGS_DE_LOW);
  2671. ipc = !!(vm->flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE);
  2672. onoff = true; /* always use the 'rf' setting */
  2673. rf = !!(vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE);
  2674. l = FLD_VAL(onoff, 17, 17) |
  2675. FLD_VAL(rf, 16, 16) |
  2676. FLD_VAL(de, 15, 15) |
  2677. FLD_VAL(ipc, 14, 14) |
  2678. FLD_VAL(hs, 13, 13) |
  2679. FLD_VAL(vs, 12, 12);
  2680. /* always set ALIGN bit when available */
  2681. if (dispc->feat->supports_sync_align)
  2682. l |= (1 << 18);
  2683. dispc_write_reg(dispc, DISPC_POL_FREQ(channel), l);
  2684. if (dispc->syscon_pol) {
  2685. const int shifts[] = {
  2686. [OMAP_DSS_CHANNEL_LCD] = 0,
  2687. [OMAP_DSS_CHANNEL_LCD2] = 1,
  2688. [OMAP_DSS_CHANNEL_LCD3] = 2,
  2689. };
  2690. u32 mask, val;
  2691. mask = (1 << 0) | (1 << 3) | (1 << 6);
  2692. val = (rf << 0) | (ipc << 3) | (onoff << 6);
  2693. mask <<= 16 + shifts[channel];
  2694. val <<= 16 + shifts[channel];
  2695. regmap_update_bits(dispc->syscon_pol, dispc->syscon_pol_offset,
  2696. mask, val);
  2697. }
  2698. }
  2699. static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
  2700. enum display_flags low)
  2701. {
  2702. if (flags & high)
  2703. return 1;
  2704. if (flags & low)
  2705. return -1;
  2706. return 0;
  2707. }
  2708. /* change name to mode? */
  2709. void dispc_mgr_set_timings(struct dispc_device *dispc,
  2710. enum omap_channel channel,
  2711. const struct videomode *vm)
  2712. {
  2713. unsigned int xtot, ytot;
  2714. unsigned long ht, vt;
  2715. struct videomode t = *vm;
  2716. DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
  2717. if (dispc_mgr_check_timings(dispc, channel, &t)) {
  2718. BUG();
  2719. return;
  2720. }
  2721. if (dss_mgr_is_lcd(channel)) {
  2722. _dispc_mgr_set_lcd_timings(dispc, channel, &t);
  2723. xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
  2724. ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
  2725. ht = vm->pixelclock / xtot;
  2726. vt = vm->pixelclock / xtot / ytot;
  2727. DSSDBG("pck %lu\n", vm->pixelclock);
  2728. DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
  2729. t.hsync_len, t.hfront_porch, t.hback_porch,
  2730. t.vsync_len, t.vfront_porch, t.vback_porch);
  2731. DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
  2732. vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
  2733. vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
  2734. vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
  2735. vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
  2736. vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
  2737. DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
  2738. } else {
  2739. if (t.flags & DISPLAY_FLAGS_INTERLACED)
  2740. t.vactive /= 2;
  2741. if (dispc->feat->supports_double_pixel)
  2742. REG_FLD_MOD(dispc, DISPC_CONTROL,
  2743. !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
  2744. 19, 17);
  2745. }
  2746. dispc_mgr_set_size(dispc, channel, t.hactive, t.vactive);
  2747. }
  2748. static void dispc_mgr_set_lcd_divisor(struct dispc_device *dispc,
  2749. enum omap_channel channel, u16 lck_div,
  2750. u16 pck_div)
  2751. {
  2752. BUG_ON(lck_div < 1);
  2753. BUG_ON(pck_div < 1);
  2754. dispc_write_reg(dispc, DISPC_DIVISORo(channel),
  2755. FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
  2756. if (!dispc_has_feature(dispc, FEAT_CORE_CLK_DIV) &&
  2757. channel == OMAP_DSS_CHANNEL_LCD)
  2758. dispc->core_clk_rate = dispc_fclk_rate(dispc) / lck_div;
  2759. }
  2760. static void dispc_mgr_get_lcd_divisor(struct dispc_device *dispc,
  2761. enum omap_channel channel, int *lck_div,
  2762. int *pck_div)
  2763. {
  2764. u32 l;
  2765. l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
  2766. *lck_div = FLD_GET(l, 23, 16);
  2767. *pck_div = FLD_GET(l, 7, 0);
  2768. }
  2769. static unsigned long dispc_fclk_rate(struct dispc_device *dispc)
  2770. {
  2771. unsigned long r;
  2772. enum dss_clk_source src;
  2773. src = dss_get_dispc_clk_source(dispc->dss);
  2774. if (src == DSS_CLK_SRC_FCK) {
  2775. r = dss_get_dispc_clk_rate(dispc->dss);
  2776. } else {
  2777. struct dss_pll *pll;
  2778. unsigned int clkout_idx;
  2779. pll = dss_pll_find_by_src(dispc->dss, src);
  2780. clkout_idx = dss_pll_get_clkout_idx_for_src(src);
  2781. r = pll->cinfo.clkout[clkout_idx];
  2782. }
  2783. return r;
  2784. }
  2785. static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
  2786. enum omap_channel channel)
  2787. {
  2788. int lcd;
  2789. unsigned long r;
  2790. enum dss_clk_source src;
  2791. /* for TV, LCLK rate is the FCLK rate */
  2792. if (!dss_mgr_is_lcd(channel))
  2793. return dispc_fclk_rate(dispc);
  2794. src = dss_get_lcd_clk_source(dispc->dss, channel);
  2795. if (src == DSS_CLK_SRC_FCK) {
  2796. r = dss_get_dispc_clk_rate(dispc->dss);
  2797. } else {
  2798. struct dss_pll *pll;
  2799. unsigned int clkout_idx;
  2800. pll = dss_pll_find_by_src(dispc->dss, src);
  2801. clkout_idx = dss_pll_get_clkout_idx_for_src(src);
  2802. r = pll->cinfo.clkout[clkout_idx];
  2803. }
  2804. lcd = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
  2805. return r / lcd;
  2806. }
  2807. static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
  2808. enum omap_channel channel)
  2809. {
  2810. unsigned long r;
  2811. if (dss_mgr_is_lcd(channel)) {
  2812. int pcd;
  2813. u32 l;
  2814. l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
  2815. pcd = FLD_GET(l, 7, 0);
  2816. r = dispc_mgr_lclk_rate(dispc, channel);
  2817. return r / pcd;
  2818. } else {
  2819. return dispc->tv_pclk_rate;
  2820. }
  2821. }
  2822. void dispc_set_tv_pclk(struct dispc_device *dispc, unsigned long pclk)
  2823. {
  2824. dispc->tv_pclk_rate = pclk;
  2825. }
  2826. static unsigned long dispc_core_clk_rate(struct dispc_device *dispc)
  2827. {
  2828. return dispc->core_clk_rate;
  2829. }
  2830. static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
  2831. enum omap_plane_id plane)
  2832. {
  2833. enum omap_channel channel;
  2834. if (plane == OMAP_DSS_WB)
  2835. return 0;
  2836. channel = dispc_ovl_get_channel_out(dispc, plane);
  2837. return dispc_mgr_pclk_rate(dispc, channel);
  2838. }
  2839. static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
  2840. enum omap_plane_id plane)
  2841. {
  2842. enum omap_channel channel;
  2843. if (plane == OMAP_DSS_WB)
  2844. return 0;
  2845. channel = dispc_ovl_get_channel_out(dispc, plane);
  2846. return dispc_mgr_lclk_rate(dispc, channel);
  2847. }
  2848. static void dispc_dump_clocks_channel(struct dispc_device *dispc,
  2849. struct seq_file *s,
  2850. enum omap_channel channel)
  2851. {
  2852. int lcd, pcd;
  2853. enum dss_clk_source lcd_clk_src;
  2854. seq_printf(s, "- %s -\n", mgr_desc[channel].name);
  2855. lcd_clk_src = dss_get_lcd_clk_source(dispc->dss, channel);
  2856. seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
  2857. dss_get_clk_source_name(lcd_clk_src));
  2858. dispc_mgr_get_lcd_divisor(dispc, channel, &lcd, &pcd);
  2859. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2860. dispc_mgr_lclk_rate(dispc, channel), lcd);
  2861. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2862. dispc_mgr_pclk_rate(dispc, channel), pcd);
  2863. }
  2864. void dispc_dump_clocks(struct dispc_device *dispc, struct seq_file *s)
  2865. {
  2866. enum dss_clk_source dispc_clk_src;
  2867. int lcd;
  2868. u32 l;
  2869. if (dispc_runtime_get(dispc))
  2870. return;
  2871. seq_printf(s, "- DISPC -\n");
  2872. dispc_clk_src = dss_get_dispc_clk_source(dispc->dss);
  2873. seq_printf(s, "dispc fclk source = %s\n",
  2874. dss_get_clk_source_name(dispc_clk_src));
  2875. seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate(dispc));
  2876. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
  2877. seq_printf(s, "- DISPC-CORE-CLK -\n");
  2878. l = dispc_read_reg(dispc, DISPC_DIVISOR);
  2879. lcd = FLD_GET(l, 23, 16);
  2880. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2881. (dispc_fclk_rate(dispc)/lcd), lcd);
  2882. }
  2883. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD);
  2884. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  2885. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD2);
  2886. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  2887. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD3);
  2888. dispc_runtime_put(dispc);
  2889. }
  2890. static int dispc_dump_regs(struct seq_file *s, void *p)
  2891. {
  2892. struct dispc_device *dispc = s->private;
  2893. int i, j;
  2894. const char *mgr_names[] = {
  2895. [OMAP_DSS_CHANNEL_LCD] = "LCD",
  2896. [OMAP_DSS_CHANNEL_DIGIT] = "TV",
  2897. [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
  2898. [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
  2899. };
  2900. const char *ovl_names[] = {
  2901. [OMAP_DSS_GFX] = "GFX",
  2902. [OMAP_DSS_VIDEO1] = "VID1",
  2903. [OMAP_DSS_VIDEO2] = "VID2",
  2904. [OMAP_DSS_VIDEO3] = "VID3",
  2905. [OMAP_DSS_WB] = "WB",
  2906. };
  2907. const char **p_names;
  2908. #define DUMPREG(dispc, r) \
  2909. seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(dispc, r))
  2910. if (dispc_runtime_get(dispc))
  2911. return 0;
  2912. /* DISPC common registers */
  2913. DUMPREG(dispc, DISPC_REVISION);
  2914. DUMPREG(dispc, DISPC_SYSCONFIG);
  2915. DUMPREG(dispc, DISPC_SYSSTATUS);
  2916. DUMPREG(dispc, DISPC_IRQSTATUS);
  2917. DUMPREG(dispc, DISPC_IRQENABLE);
  2918. DUMPREG(dispc, DISPC_CONTROL);
  2919. DUMPREG(dispc, DISPC_CONFIG);
  2920. DUMPREG(dispc, DISPC_CAPABLE);
  2921. DUMPREG(dispc, DISPC_LINE_STATUS);
  2922. DUMPREG(dispc, DISPC_LINE_NUMBER);
  2923. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  2924. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  2925. DUMPREG(dispc, DISPC_GLOBAL_ALPHA);
  2926. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  2927. DUMPREG(dispc, DISPC_CONTROL2);
  2928. DUMPREG(dispc, DISPC_CONFIG2);
  2929. }
  2930. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  2931. DUMPREG(dispc, DISPC_CONTROL3);
  2932. DUMPREG(dispc, DISPC_CONFIG3);
  2933. }
  2934. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2935. DUMPREG(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE);
  2936. #undef DUMPREG
  2937. #define DISPC_REG(i, name) name(i)
  2938. #define DUMPREG(dispc, i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
  2939. (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
  2940. dispc_read_reg(dispc, DISPC_REG(i, r)))
  2941. p_names = mgr_names;
  2942. /* DISPC channel specific registers */
  2943. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  2944. DUMPREG(dispc, i, DISPC_DEFAULT_COLOR);
  2945. DUMPREG(dispc, i, DISPC_TRANS_COLOR);
  2946. DUMPREG(dispc, i, DISPC_SIZE_MGR);
  2947. if (i == OMAP_DSS_CHANNEL_DIGIT)
  2948. continue;
  2949. DUMPREG(dispc, i, DISPC_TIMING_H);
  2950. DUMPREG(dispc, i, DISPC_TIMING_V);
  2951. DUMPREG(dispc, i, DISPC_POL_FREQ);
  2952. DUMPREG(dispc, i, DISPC_DIVISORo);
  2953. DUMPREG(dispc, i, DISPC_DATA_CYCLE1);
  2954. DUMPREG(dispc, i, DISPC_DATA_CYCLE2);
  2955. DUMPREG(dispc, i, DISPC_DATA_CYCLE3);
  2956. if (dispc_has_feature(dispc, FEAT_CPR)) {
  2957. DUMPREG(dispc, i, DISPC_CPR_COEF_R);
  2958. DUMPREG(dispc, i, DISPC_CPR_COEF_G);
  2959. DUMPREG(dispc, i, DISPC_CPR_COEF_B);
  2960. }
  2961. }
  2962. p_names = ovl_names;
  2963. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  2964. DUMPREG(dispc, i, DISPC_OVL_BA0);
  2965. DUMPREG(dispc, i, DISPC_OVL_BA1);
  2966. DUMPREG(dispc, i, DISPC_OVL_POSITION);
  2967. DUMPREG(dispc, i, DISPC_OVL_SIZE);
  2968. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
  2969. DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
  2970. DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
  2971. DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
  2972. DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
  2973. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  2974. DUMPREG(dispc, i, DISPC_OVL_PRELOAD);
  2975. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2976. DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
  2977. if (i == OMAP_DSS_GFX) {
  2978. DUMPREG(dispc, i, DISPC_OVL_WINDOW_SKIP);
  2979. DUMPREG(dispc, i, DISPC_OVL_TABLE_BA);
  2980. continue;
  2981. }
  2982. DUMPREG(dispc, i, DISPC_OVL_FIR);
  2983. DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
  2984. DUMPREG(dispc, i, DISPC_OVL_ACCU0);
  2985. DUMPREG(dispc, i, DISPC_OVL_ACCU1);
  2986. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  2987. DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
  2988. DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
  2989. DUMPREG(dispc, i, DISPC_OVL_FIR2);
  2990. DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
  2991. DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
  2992. }
  2993. if (dispc_has_feature(dispc, FEAT_ATTR2))
  2994. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
  2995. }
  2996. if (dispc->feat->has_writeback) {
  2997. i = OMAP_DSS_WB;
  2998. DUMPREG(dispc, i, DISPC_OVL_BA0);
  2999. DUMPREG(dispc, i, DISPC_OVL_BA1);
  3000. DUMPREG(dispc, i, DISPC_OVL_SIZE);
  3001. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
  3002. DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
  3003. DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
  3004. DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
  3005. DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
  3006. if (dispc_has_feature(dispc, FEAT_MFLAG))
  3007. DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
  3008. DUMPREG(dispc, i, DISPC_OVL_FIR);
  3009. DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
  3010. DUMPREG(dispc, i, DISPC_OVL_ACCU0);
  3011. DUMPREG(dispc, i, DISPC_OVL_ACCU1);
  3012. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  3013. DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
  3014. DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
  3015. DUMPREG(dispc, i, DISPC_OVL_FIR2);
  3016. DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
  3017. DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
  3018. }
  3019. if (dispc_has_feature(dispc, FEAT_ATTR2))
  3020. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
  3021. }
  3022. #undef DISPC_REG
  3023. #undef DUMPREG
  3024. #define DISPC_REG(plane, name, i) name(plane, i)
  3025. #define DUMPREG(dispc, plane, name, i) \
  3026. seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
  3027. (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
  3028. dispc_read_reg(dispc, DISPC_REG(plane, name, i)))
  3029. /* Video pipeline coefficient registers */
  3030. /* start from OMAP_DSS_VIDEO1 */
  3031. for (i = 1; i < dispc_get_num_ovls(dispc); i++) {
  3032. for (j = 0; j < 8; j++)
  3033. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H, j);
  3034. for (j = 0; j < 8; j++)
  3035. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV, j);
  3036. for (j = 0; j < 5; j++)
  3037. DUMPREG(dispc, i, DISPC_OVL_CONV_COEF, j);
  3038. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  3039. for (j = 0; j < 8; j++)
  3040. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V, j);
  3041. }
  3042. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  3043. for (j = 0; j < 8; j++)
  3044. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H2, j);
  3045. for (j = 0; j < 8; j++)
  3046. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV2, j);
  3047. for (j = 0; j < 8; j++)
  3048. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V2, j);
  3049. }
  3050. }
  3051. dispc_runtime_put(dispc);
  3052. #undef DISPC_REG
  3053. #undef DUMPREG
  3054. return 0;
  3055. }
  3056. /* calculate clock rates using dividers in cinfo */
  3057. int dispc_calc_clock_rates(struct dispc_device *dispc,
  3058. unsigned long dispc_fclk_rate,
  3059. struct dispc_clock_info *cinfo)
  3060. {
  3061. if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
  3062. return -EINVAL;
  3063. if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
  3064. return -EINVAL;
  3065. cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
  3066. cinfo->pck = cinfo->lck / cinfo->pck_div;
  3067. return 0;
  3068. }
  3069. bool dispc_div_calc(struct dispc_device *dispc, unsigned long dispc_freq,
  3070. unsigned long pck_min, unsigned long pck_max,
  3071. dispc_div_calc_func func, void *data)
  3072. {
  3073. int lckd, lckd_start, lckd_stop;
  3074. int pckd, pckd_start, pckd_stop;
  3075. unsigned long pck, lck;
  3076. unsigned long lck_max;
  3077. unsigned long pckd_hw_min, pckd_hw_max;
  3078. unsigned int min_fck_per_pck;
  3079. unsigned long fck;
  3080. #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
  3081. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  3082. #else
  3083. min_fck_per_pck = 0;
  3084. #endif
  3085. pckd_hw_min = dispc->feat->min_pcd;
  3086. pckd_hw_max = 255;
  3087. lck_max = dss_get_max_fck_rate(dispc->dss);
  3088. pck_min = pck_min ? pck_min : 1;
  3089. pck_max = pck_max ? pck_max : ULONG_MAX;
  3090. lckd_start = max(DIV_ROUND_UP(dispc_freq, lck_max), 1ul);
  3091. lckd_stop = min(dispc_freq / pck_min, 255ul);
  3092. for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
  3093. lck = dispc_freq / lckd;
  3094. pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
  3095. pckd_stop = min(lck / pck_min, pckd_hw_max);
  3096. for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
  3097. pck = lck / pckd;
  3098. /*
  3099. * For OMAP2/3 the DISPC fclk is the same as LCD's logic
  3100. * clock, which means we're configuring DISPC fclk here
  3101. * also. Thus we need to use the calculated lck. For
  3102. * OMAP4+ the DISPC fclk is a separate clock.
  3103. */
  3104. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  3105. fck = dispc_core_clk_rate(dispc);
  3106. else
  3107. fck = lck;
  3108. if (fck < pck * min_fck_per_pck)
  3109. continue;
  3110. if (func(lckd, pckd, lck, pck, data))
  3111. return true;
  3112. }
  3113. }
  3114. return false;
  3115. }
  3116. void dispc_mgr_set_clock_div(struct dispc_device *dispc,
  3117. enum omap_channel channel,
  3118. const struct dispc_clock_info *cinfo)
  3119. {
  3120. DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
  3121. DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
  3122. dispc_mgr_set_lcd_divisor(dispc, channel, cinfo->lck_div,
  3123. cinfo->pck_div);
  3124. }
  3125. int dispc_mgr_get_clock_div(struct dispc_device *dispc,
  3126. enum omap_channel channel,
  3127. struct dispc_clock_info *cinfo)
  3128. {
  3129. unsigned long fck;
  3130. fck = dispc_fclk_rate(dispc);
  3131. cinfo->lck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
  3132. cinfo->pck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 7, 0);
  3133. cinfo->lck = fck / cinfo->lck_div;
  3134. cinfo->pck = cinfo->lck / cinfo->pck_div;
  3135. return 0;
  3136. }
  3137. u32 dispc_read_irqstatus(struct dispc_device *dispc)
  3138. {
  3139. return dispc_read_reg(dispc, DISPC_IRQSTATUS);
  3140. }
  3141. void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask)
  3142. {
  3143. dispc_write_reg(dispc, DISPC_IRQSTATUS, mask);
  3144. }
  3145. void dispc_write_irqenable(struct dispc_device *dispc, u32 mask)
  3146. {
  3147. u32 old_mask = dispc_read_reg(dispc, DISPC_IRQENABLE);
  3148. /* clear the irqstatus for newly enabled irqs */
  3149. dispc_clear_irqstatus(dispc, (mask ^ old_mask) & mask);
  3150. dispc_write_reg(dispc, DISPC_IRQENABLE, mask);
  3151. /* flush posted write */
  3152. dispc_read_reg(dispc, DISPC_IRQENABLE);
  3153. }
  3154. void dispc_enable_sidle(struct dispc_device *dispc)
  3155. {
  3156. /* SIDLEMODE: smart idle */
  3157. REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 2, 4, 3);
  3158. }
  3159. void dispc_disable_sidle(struct dispc_device *dispc)
  3160. {
  3161. REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
  3162. }
  3163. u32 dispc_mgr_gamma_size(struct dispc_device *dispc,
  3164. enum omap_channel channel)
  3165. {
  3166. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3167. if (!dispc->feat->has_gamma_table)
  3168. return 0;
  3169. return gdesc->len;
  3170. }
  3171. static void dispc_mgr_write_gamma_table(struct dispc_device *dispc,
  3172. enum omap_channel channel)
  3173. {
  3174. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3175. u32 *table = dispc->gamma_table[channel];
  3176. unsigned int i;
  3177. DSSDBG("%s: channel %d\n", __func__, channel);
  3178. for (i = 0; i < gdesc->len; ++i) {
  3179. u32 v = table[i];
  3180. if (gdesc->has_index)
  3181. v |= i << 24;
  3182. else if (i == 0)
  3183. v |= 1 << 31;
  3184. dispc_write_reg(dispc, gdesc->reg, v);
  3185. }
  3186. }
  3187. static void dispc_restore_gamma_tables(struct dispc_device *dispc)
  3188. {
  3189. DSSDBG("%s()\n", __func__);
  3190. if (!dispc->feat->has_gamma_table)
  3191. return;
  3192. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD);
  3193. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_DIGIT);
  3194. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  3195. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD2);
  3196. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  3197. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD3);
  3198. }
  3199. static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
  3200. { .red = 0, .green = 0, .blue = 0, },
  3201. { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
  3202. };
  3203. void dispc_mgr_set_gamma(struct dispc_device *dispc,
  3204. enum omap_channel channel,
  3205. const struct drm_color_lut *lut,
  3206. unsigned int length)
  3207. {
  3208. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3209. u32 *table = dispc->gamma_table[channel];
  3210. uint i;
  3211. DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
  3212. channel, length, gdesc->len);
  3213. if (!dispc->feat->has_gamma_table)
  3214. return;
  3215. if (lut == NULL || length < 2) {
  3216. lut = dispc_mgr_gamma_default_lut;
  3217. length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
  3218. }
  3219. for (i = 0; i < length - 1; ++i) {
  3220. uint first = i * (gdesc->len - 1) / (length - 1);
  3221. uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
  3222. uint w = last - first;
  3223. u16 r, g, b;
  3224. uint j;
  3225. if (w == 0)
  3226. continue;
  3227. for (j = 0; j <= w; j++) {
  3228. r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
  3229. g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
  3230. b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
  3231. r >>= 16 - gdesc->bits;
  3232. g >>= 16 - gdesc->bits;
  3233. b >>= 16 - gdesc->bits;
  3234. table[first + j] = (r << (gdesc->bits * 2)) |
  3235. (g << gdesc->bits) | b;
  3236. }
  3237. }
  3238. if (dispc->is_enabled)
  3239. dispc_mgr_write_gamma_table(dispc, channel);
  3240. }
  3241. static int dispc_init_gamma_tables(struct dispc_device *dispc)
  3242. {
  3243. int channel;
  3244. if (!dispc->feat->has_gamma_table)
  3245. return 0;
  3246. for (channel = 0; channel < ARRAY_SIZE(dispc->gamma_table); channel++) {
  3247. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3248. u32 *gt;
  3249. if (channel == OMAP_DSS_CHANNEL_LCD2 &&
  3250. !dispc_has_feature(dispc, FEAT_MGR_LCD2))
  3251. continue;
  3252. if (channel == OMAP_DSS_CHANNEL_LCD3 &&
  3253. !dispc_has_feature(dispc, FEAT_MGR_LCD3))
  3254. continue;
  3255. gt = devm_kmalloc_array(&dispc->pdev->dev, gdesc->len,
  3256. sizeof(u32), GFP_KERNEL);
  3257. if (!gt)
  3258. return -ENOMEM;
  3259. dispc->gamma_table[channel] = gt;
  3260. dispc_mgr_set_gamma(dispc, channel, NULL, 0);
  3261. }
  3262. return 0;
  3263. }
  3264. static void _omap_dispc_initial_config(struct dispc_device *dispc)
  3265. {
  3266. u32 l;
  3267. /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
  3268. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
  3269. l = dispc_read_reg(dispc, DISPC_DIVISOR);
  3270. /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
  3271. l = FLD_MOD(l, 1, 0, 0);
  3272. l = FLD_MOD(l, 1, 23, 16);
  3273. dispc_write_reg(dispc, DISPC_DIVISOR, l);
  3274. dispc->core_clk_rate = dispc_fclk_rate(dispc);
  3275. }
  3276. /* Use gamma table mode, instead of palette mode */
  3277. if (dispc->feat->has_gamma_table)
  3278. REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 3, 3);
  3279. /* For older DSS versions (FEAT_FUNCGATED) this enables
  3280. * func-clock auto-gating. For newer versions
  3281. * (dispc->feat->has_gamma_table) this enables tv-out gamma tables.
  3282. */
  3283. if (dispc_has_feature(dispc, FEAT_FUNCGATED) ||
  3284. dispc->feat->has_gamma_table)
  3285. REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 9, 9);
  3286. dispc_set_loadmode(dispc, OMAP_DSS_LOAD_FRAME_ONLY);
  3287. dispc_init_fifos(dispc);
  3288. dispc_configure_burst_sizes(dispc);
  3289. dispc_ovl_enable_zorder_planes(dispc);
  3290. if (dispc->feat->mstandby_workaround)
  3291. REG_FLD_MOD(dispc, DISPC_MSTANDBY_CTRL, 1, 0, 0);
  3292. if (dispc_has_feature(dispc, FEAT_MFLAG))
  3293. dispc_init_mflag(dispc);
  3294. }
  3295. static const enum dispc_feature_id omap2_dispc_features_list[] = {
  3296. FEAT_LCDENABLEPOL,
  3297. FEAT_LCDENABLESIGNAL,
  3298. FEAT_PCKFREEENABLE,
  3299. FEAT_FUNCGATED,
  3300. FEAT_ROWREPEATENABLE,
  3301. FEAT_RESIZECONF,
  3302. };
  3303. static const enum dispc_feature_id omap3_dispc_features_list[] = {
  3304. FEAT_LCDENABLEPOL,
  3305. FEAT_LCDENABLESIGNAL,
  3306. FEAT_PCKFREEENABLE,
  3307. FEAT_FUNCGATED,
  3308. FEAT_LINEBUFFERSPLIT,
  3309. FEAT_ROWREPEATENABLE,
  3310. FEAT_RESIZECONF,
  3311. FEAT_CPR,
  3312. FEAT_PRELOAD,
  3313. FEAT_FIR_COEF_V,
  3314. FEAT_ALPHA_FIXED_ZORDER,
  3315. FEAT_FIFO_MERGE,
  3316. FEAT_OMAP3_DSI_FIFO_BUG,
  3317. };
  3318. static const enum dispc_feature_id am43xx_dispc_features_list[] = {
  3319. FEAT_LCDENABLEPOL,
  3320. FEAT_LCDENABLESIGNAL,
  3321. FEAT_PCKFREEENABLE,
  3322. FEAT_FUNCGATED,
  3323. FEAT_LINEBUFFERSPLIT,
  3324. FEAT_ROWREPEATENABLE,
  3325. FEAT_RESIZECONF,
  3326. FEAT_CPR,
  3327. FEAT_PRELOAD,
  3328. FEAT_FIR_COEF_V,
  3329. FEAT_ALPHA_FIXED_ZORDER,
  3330. FEAT_FIFO_MERGE,
  3331. };
  3332. static const enum dispc_feature_id omap4_dispc_features_list[] = {
  3333. FEAT_MGR_LCD2,
  3334. FEAT_CORE_CLK_DIV,
  3335. FEAT_HANDLE_UV_SEPARATE,
  3336. FEAT_ATTR2,
  3337. FEAT_CPR,
  3338. FEAT_PRELOAD,
  3339. FEAT_FIR_COEF_V,
  3340. FEAT_ALPHA_FREE_ZORDER,
  3341. FEAT_FIFO_MERGE,
  3342. FEAT_BURST_2D,
  3343. };
  3344. static const enum dispc_feature_id omap5_dispc_features_list[] = {
  3345. FEAT_MGR_LCD2,
  3346. FEAT_MGR_LCD3,
  3347. FEAT_CORE_CLK_DIV,
  3348. FEAT_HANDLE_UV_SEPARATE,
  3349. FEAT_ATTR2,
  3350. FEAT_CPR,
  3351. FEAT_PRELOAD,
  3352. FEAT_FIR_COEF_V,
  3353. FEAT_ALPHA_FREE_ZORDER,
  3354. FEAT_FIFO_MERGE,
  3355. FEAT_BURST_2D,
  3356. FEAT_MFLAG,
  3357. };
  3358. static const struct dss_reg_field omap2_dispc_reg_fields[] = {
  3359. [FEAT_REG_FIRHINC] = { 11, 0 },
  3360. [FEAT_REG_FIRVINC] = { 27, 16 },
  3361. [FEAT_REG_FIFOLOWTHRESHOLD] = { 8, 0 },
  3362. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 24, 16 },
  3363. [FEAT_REG_FIFOSIZE] = { 8, 0 },
  3364. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  3365. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  3366. };
  3367. static const struct dss_reg_field omap3_dispc_reg_fields[] = {
  3368. [FEAT_REG_FIRHINC] = { 12, 0 },
  3369. [FEAT_REG_FIRVINC] = { 28, 16 },
  3370. [FEAT_REG_FIFOLOWTHRESHOLD] = { 11, 0 },
  3371. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 27, 16 },
  3372. [FEAT_REG_FIFOSIZE] = { 10, 0 },
  3373. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  3374. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  3375. };
  3376. static const struct dss_reg_field omap4_dispc_reg_fields[] = {
  3377. [FEAT_REG_FIRHINC] = { 12, 0 },
  3378. [FEAT_REG_FIRVINC] = { 28, 16 },
  3379. [FEAT_REG_FIFOLOWTHRESHOLD] = { 15, 0 },
  3380. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 31, 16 },
  3381. [FEAT_REG_FIFOSIZE] = { 15, 0 },
  3382. [FEAT_REG_HORIZONTALACCU] = { 10, 0 },
  3383. [FEAT_REG_VERTICALACCU] = { 26, 16 },
  3384. };
  3385. static const enum omap_overlay_caps omap2_dispc_overlay_caps[] = {
  3386. /* OMAP_DSS_GFX */
  3387. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3388. /* OMAP_DSS_VIDEO1 */
  3389. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3390. OMAP_DSS_OVL_CAP_REPLICATION,
  3391. /* OMAP_DSS_VIDEO2 */
  3392. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3393. OMAP_DSS_OVL_CAP_REPLICATION,
  3394. };
  3395. static const enum omap_overlay_caps omap3430_dispc_overlay_caps[] = {
  3396. /* OMAP_DSS_GFX */
  3397. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_POS |
  3398. OMAP_DSS_OVL_CAP_REPLICATION,
  3399. /* OMAP_DSS_VIDEO1 */
  3400. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3401. OMAP_DSS_OVL_CAP_REPLICATION,
  3402. /* OMAP_DSS_VIDEO2 */
  3403. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3404. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3405. };
  3406. static const enum omap_overlay_caps omap3630_dispc_overlay_caps[] = {
  3407. /* OMAP_DSS_GFX */
  3408. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
  3409. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3410. /* OMAP_DSS_VIDEO1 */
  3411. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3412. OMAP_DSS_OVL_CAP_REPLICATION,
  3413. /* OMAP_DSS_VIDEO2 */
  3414. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3415. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_POS |
  3416. OMAP_DSS_OVL_CAP_REPLICATION,
  3417. };
  3418. static const enum omap_overlay_caps omap4_dispc_overlay_caps[] = {
  3419. /* OMAP_DSS_GFX */
  3420. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
  3421. OMAP_DSS_OVL_CAP_ZORDER | OMAP_DSS_OVL_CAP_POS |
  3422. OMAP_DSS_OVL_CAP_REPLICATION,
  3423. /* OMAP_DSS_VIDEO1 */
  3424. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3425. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3426. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3427. /* OMAP_DSS_VIDEO2 */
  3428. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3429. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3430. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3431. /* OMAP_DSS_VIDEO3 */
  3432. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3433. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3434. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3435. };
  3436. #define COLOR_ARRAY(arr...) (const u32[]) { arr, 0 }
  3437. static const u32 *omap2_dispc_supported_color_modes[] = {
  3438. /* OMAP_DSS_GFX */
  3439. COLOR_ARRAY(
  3440. DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
  3441. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888),
  3442. /* OMAP_DSS_VIDEO1 */
  3443. COLOR_ARRAY(
  3444. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3445. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3446. DRM_FORMAT_UYVY),
  3447. /* OMAP_DSS_VIDEO2 */
  3448. COLOR_ARRAY(
  3449. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3450. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3451. DRM_FORMAT_UYVY),
  3452. };
  3453. static const u32 *omap3_dispc_supported_color_modes[] = {
  3454. /* OMAP_DSS_GFX */
  3455. COLOR_ARRAY(
  3456. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3457. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3458. DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
  3459. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
  3460. /* OMAP_DSS_VIDEO1 */
  3461. COLOR_ARRAY(
  3462. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888,
  3463. DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
  3464. DRM_FORMAT_YUYV, DRM_FORMAT_UYVY),
  3465. /* OMAP_DSS_VIDEO2 */
  3466. COLOR_ARRAY(
  3467. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3468. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3469. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3470. DRM_FORMAT_UYVY, DRM_FORMAT_ARGB8888,
  3471. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
  3472. };
  3473. static const u32 *omap4_dispc_supported_color_modes[] = {
  3474. /* OMAP_DSS_GFX */
  3475. COLOR_ARRAY(
  3476. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3477. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3478. DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
  3479. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888,
  3480. DRM_FORMAT_ARGB1555, DRM_FORMAT_XRGB4444,
  3481. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB1555),
  3482. /* OMAP_DSS_VIDEO1 */
  3483. COLOR_ARRAY(
  3484. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3485. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3486. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3487. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3488. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3489. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3490. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3491. DRM_FORMAT_RGBX8888),
  3492. /* OMAP_DSS_VIDEO2 */
  3493. COLOR_ARRAY(
  3494. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3495. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3496. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3497. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3498. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3499. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3500. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3501. DRM_FORMAT_RGBX8888),
  3502. /* OMAP_DSS_VIDEO3 */
  3503. COLOR_ARRAY(
  3504. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3505. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3506. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3507. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3508. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3509. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3510. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3511. DRM_FORMAT_RGBX8888),
  3512. /* OMAP_DSS_WB */
  3513. COLOR_ARRAY(
  3514. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3515. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3516. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3517. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3518. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3519. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3520. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3521. DRM_FORMAT_RGBX8888),
  3522. };
  3523. static const u32 omap3_dispc_supported_scaler_color_modes[] = {
  3524. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_YUYV,
  3525. DRM_FORMAT_UYVY,
  3526. 0,
  3527. };
  3528. static const struct dispc_features omap24xx_dispc_feats = {
  3529. .sw_start = 5,
  3530. .fp_start = 15,
  3531. .bp_start = 27,
  3532. .sw_max = 64,
  3533. .vp_max = 255,
  3534. .hp_max = 256,
  3535. .mgr_width_start = 10,
  3536. .mgr_height_start = 26,
  3537. .mgr_width_max = 2048,
  3538. .mgr_height_max = 2048,
  3539. .ovl_width_max = 2048,
  3540. .ovl_height_max = 2048,
  3541. .max_lcd_pclk = 66500000,
  3542. .max_downscale = 2,
  3543. /*
  3544. * Assume the line width buffer to be 768 pixels as OMAP2 DISPC scaler
  3545. * cannot scale an image width larger than 768.
  3546. */
  3547. .max_line_width = 768,
  3548. .min_pcd = 2,
  3549. .calc_scaling = dispc_ovl_calc_scaling_24xx,
  3550. .calc_core_clk = calc_core_clk_24xx,
  3551. .num_fifos = 3,
  3552. .features = omap2_dispc_features_list,
  3553. .num_features = ARRAY_SIZE(omap2_dispc_features_list),
  3554. .reg_fields = omap2_dispc_reg_fields,
  3555. .num_reg_fields = ARRAY_SIZE(omap2_dispc_reg_fields),
  3556. .overlay_caps = omap2_dispc_overlay_caps,
  3557. .supported_color_modes = omap2_dispc_supported_color_modes,
  3558. .supported_scaler_color_modes = COLOR_ARRAY(DRM_FORMAT_XRGB8888),
  3559. .num_mgrs = 2,
  3560. .num_ovls = 3,
  3561. .buffer_size_unit = 1,
  3562. .burst_size_unit = 8,
  3563. .no_framedone_tv = true,
  3564. .set_max_preload = false,
  3565. .last_pixel_inc_missing = true,
  3566. };
  3567. static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
  3568. .sw_start = 5,
  3569. .fp_start = 15,
  3570. .bp_start = 27,
  3571. .sw_max = 64,
  3572. .vp_max = 255,
  3573. .hp_max = 256,
  3574. .mgr_width_start = 10,
  3575. .mgr_height_start = 26,
  3576. .mgr_width_max = 2048,
  3577. .mgr_height_max = 2048,
  3578. .ovl_width_max = 2048,
  3579. .ovl_height_max = 2048,
  3580. .max_lcd_pclk = 173000000,
  3581. .max_tv_pclk = 59000000,
  3582. .max_downscale = 4,
  3583. .max_line_width = 1024,
  3584. .min_pcd = 1,
  3585. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3586. .calc_core_clk = calc_core_clk_34xx,
  3587. .num_fifos = 3,
  3588. .features = omap3_dispc_features_list,
  3589. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3590. .reg_fields = omap3_dispc_reg_fields,
  3591. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3592. .overlay_caps = omap3430_dispc_overlay_caps,
  3593. .supported_color_modes = omap3_dispc_supported_color_modes,
  3594. .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
  3595. .num_mgrs = 2,
  3596. .num_ovls = 3,
  3597. .buffer_size_unit = 1,
  3598. .burst_size_unit = 8,
  3599. .no_framedone_tv = true,
  3600. .set_max_preload = false,
  3601. .last_pixel_inc_missing = true,
  3602. };
  3603. static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
  3604. .sw_start = 7,
  3605. .fp_start = 19,
  3606. .bp_start = 31,
  3607. .sw_max = 256,
  3608. .vp_max = 4095,
  3609. .hp_max = 4096,
  3610. .mgr_width_start = 10,
  3611. .mgr_height_start = 26,
  3612. .mgr_width_max = 2048,
  3613. .mgr_height_max = 2048,
  3614. .ovl_width_max = 2048,
  3615. .ovl_height_max = 2048,
  3616. .max_lcd_pclk = 173000000,
  3617. .max_tv_pclk = 59000000,
  3618. .max_downscale = 4,
  3619. .max_line_width = 1024,
  3620. .min_pcd = 1,
  3621. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3622. .calc_core_clk = calc_core_clk_34xx,
  3623. .num_fifos = 3,
  3624. .features = omap3_dispc_features_list,
  3625. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3626. .reg_fields = omap3_dispc_reg_fields,
  3627. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3628. .overlay_caps = omap3430_dispc_overlay_caps,
  3629. .supported_color_modes = omap3_dispc_supported_color_modes,
  3630. .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
  3631. .num_mgrs = 2,
  3632. .num_ovls = 3,
  3633. .buffer_size_unit = 1,
  3634. .burst_size_unit = 8,
  3635. .no_framedone_tv = true,
  3636. .set_max_preload = false,
  3637. .last_pixel_inc_missing = true,
  3638. };
  3639. static const struct dispc_features omap36xx_dispc_feats = {
  3640. .sw_start = 7,
  3641. .fp_start = 19,
  3642. .bp_start = 31,
  3643. .sw_max = 256,
  3644. .vp_max = 4095,
  3645. .hp_max = 4096,
  3646. .mgr_width_start = 10,
  3647. .mgr_height_start = 26,
  3648. .mgr_width_max = 2048,
  3649. .mgr_height_max = 2048,
  3650. .ovl_width_max = 2048,
  3651. .ovl_height_max = 2048,
  3652. .max_lcd_pclk = 173000000,
  3653. .max_tv_pclk = 59000000,
  3654. .max_downscale = 4,
  3655. .max_line_width = 1024,
  3656. .min_pcd = 1,
  3657. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3658. .calc_core_clk = calc_core_clk_34xx,
  3659. .num_fifos = 3,
  3660. .features = omap3_dispc_features_list,
  3661. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3662. .reg_fields = omap3_dispc_reg_fields,
  3663. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3664. .overlay_caps = omap3630_dispc_overlay_caps,
  3665. .supported_color_modes = omap3_dispc_supported_color_modes,
  3666. .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
  3667. .num_mgrs = 2,
  3668. .num_ovls = 3,
  3669. .buffer_size_unit = 1,
  3670. .burst_size_unit = 8,
  3671. .no_framedone_tv = true,
  3672. .set_max_preload = false,
  3673. .last_pixel_inc_missing = true,
  3674. };
  3675. static const struct dispc_features am43xx_dispc_feats = {
  3676. .sw_start = 7,
  3677. .fp_start = 19,
  3678. .bp_start = 31,
  3679. .sw_max = 256,
  3680. .vp_max = 4095,
  3681. .hp_max = 4096,
  3682. .mgr_width_start = 10,
  3683. .mgr_height_start = 26,
  3684. .mgr_width_max = 2048,
  3685. .mgr_height_max = 2048,
  3686. .ovl_width_max = 2048,
  3687. .ovl_height_max = 2048,
  3688. .max_lcd_pclk = 173000000,
  3689. .max_tv_pclk = 59000000,
  3690. .max_downscale = 4,
  3691. .max_line_width = 1024,
  3692. .min_pcd = 1,
  3693. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3694. .calc_core_clk = calc_core_clk_34xx,
  3695. .num_fifos = 3,
  3696. .features = am43xx_dispc_features_list,
  3697. .num_features = ARRAY_SIZE(am43xx_dispc_features_list),
  3698. .reg_fields = omap3_dispc_reg_fields,
  3699. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3700. .overlay_caps = omap3430_dispc_overlay_caps,
  3701. .supported_color_modes = omap3_dispc_supported_color_modes,
  3702. .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
  3703. .num_mgrs = 1,
  3704. .num_ovls = 3,
  3705. .buffer_size_unit = 1,
  3706. .burst_size_unit = 8,
  3707. .no_framedone_tv = true,
  3708. .set_max_preload = false,
  3709. .last_pixel_inc_missing = true,
  3710. };
  3711. static const struct dispc_features omap44xx_dispc_feats = {
  3712. .sw_start = 7,
  3713. .fp_start = 19,
  3714. .bp_start = 31,
  3715. .sw_max = 256,
  3716. .vp_max = 4095,
  3717. .hp_max = 4096,
  3718. .mgr_width_start = 10,
  3719. .mgr_height_start = 26,
  3720. .mgr_width_max = 2048,
  3721. .mgr_height_max = 2048,
  3722. .ovl_width_max = 2048,
  3723. .ovl_height_max = 2048,
  3724. .max_lcd_pclk = 170000000,
  3725. .max_tv_pclk = 185625000,
  3726. .max_downscale = 4,
  3727. .max_line_width = 2048,
  3728. .min_pcd = 1,
  3729. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3730. .calc_core_clk = calc_core_clk_44xx,
  3731. .num_fifos = 5,
  3732. .features = omap4_dispc_features_list,
  3733. .num_features = ARRAY_SIZE(omap4_dispc_features_list),
  3734. .reg_fields = omap4_dispc_reg_fields,
  3735. .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
  3736. .overlay_caps = omap4_dispc_overlay_caps,
  3737. .supported_color_modes = omap4_dispc_supported_color_modes,
  3738. .num_mgrs = 3,
  3739. .num_ovls = 4,
  3740. .buffer_size_unit = 16,
  3741. .burst_size_unit = 16,
  3742. .gfx_fifo_workaround = true,
  3743. .set_max_preload = true,
  3744. .supports_sync_align = true,
  3745. .has_writeback = true,
  3746. .supports_double_pixel = true,
  3747. .reverse_ilace_field_order = true,
  3748. .has_gamma_table = true,
  3749. .has_gamma_i734_bug = true,
  3750. };
  3751. static const struct dispc_features omap54xx_dispc_feats = {
  3752. .sw_start = 7,
  3753. .fp_start = 19,
  3754. .bp_start = 31,
  3755. .sw_max = 256,
  3756. .vp_max = 4095,
  3757. .hp_max = 4096,
  3758. .mgr_width_start = 11,
  3759. .mgr_height_start = 27,
  3760. .mgr_width_max = 4096,
  3761. .mgr_height_max = 4096,
  3762. .ovl_width_max = 2048,
  3763. .ovl_height_max = 4096,
  3764. .max_lcd_pclk = 170000000,
  3765. .max_tv_pclk = 192000000,
  3766. .max_downscale = 4,
  3767. .max_line_width = 2048,
  3768. .min_pcd = 1,
  3769. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3770. .calc_core_clk = calc_core_clk_44xx,
  3771. .num_fifos = 5,
  3772. .features = omap5_dispc_features_list,
  3773. .num_features = ARRAY_SIZE(omap5_dispc_features_list),
  3774. .reg_fields = omap4_dispc_reg_fields,
  3775. .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
  3776. .overlay_caps = omap4_dispc_overlay_caps,
  3777. .supported_color_modes = omap4_dispc_supported_color_modes,
  3778. .num_mgrs = 4,
  3779. .num_ovls = 4,
  3780. .buffer_size_unit = 16,
  3781. .burst_size_unit = 16,
  3782. .gfx_fifo_workaround = true,
  3783. .mstandby_workaround = true,
  3784. .set_max_preload = true,
  3785. .supports_sync_align = true,
  3786. .has_writeback = true,
  3787. .supports_double_pixel = true,
  3788. .reverse_ilace_field_order = true,
  3789. .has_gamma_table = true,
  3790. .has_gamma_i734_bug = true,
  3791. };
  3792. static irqreturn_t dispc_irq_handler(int irq, void *arg)
  3793. {
  3794. struct dispc_device *dispc = arg;
  3795. if (!dispc->is_enabled)
  3796. return IRQ_NONE;
  3797. return dispc->user_handler(irq, dispc->user_data);
  3798. }
  3799. int dispc_request_irq(struct dispc_device *dispc, irq_handler_t handler,
  3800. void *dev_id)
  3801. {
  3802. int r;
  3803. if (dispc->user_handler != NULL)
  3804. return -EBUSY;
  3805. dispc->user_handler = handler;
  3806. dispc->user_data = dev_id;
  3807. /* ensure the dispc_irq_handler sees the values above */
  3808. smp_wmb();
  3809. r = devm_request_irq(&dispc->pdev->dev, dispc->irq, dispc_irq_handler,
  3810. IRQF_SHARED, "OMAP DISPC", dispc);
  3811. if (r) {
  3812. dispc->user_handler = NULL;
  3813. dispc->user_data = NULL;
  3814. }
  3815. return r;
  3816. }
  3817. void dispc_free_irq(struct dispc_device *dispc, void *dev_id)
  3818. {
  3819. devm_free_irq(&dispc->pdev->dev, dispc->irq, dispc);
  3820. dispc->user_handler = NULL;
  3821. dispc->user_data = NULL;
  3822. }
  3823. u32 dispc_get_memory_bandwidth_limit(struct dispc_device *dispc)
  3824. {
  3825. u32 limit = 0;
  3826. /* Optional maximum memory bandwidth */
  3827. of_property_read_u32(dispc->pdev->dev.of_node, "max-memory-bandwidth",
  3828. &limit);
  3829. return limit;
  3830. }
  3831. /*
  3832. * Workaround for errata i734 in DSS dispc
  3833. * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
  3834. *
  3835. * For gamma tables to work on LCD1 the GFX plane has to be used at
  3836. * least once after DSS HW has come out of reset. The workaround
  3837. * sets up a minimal LCD setup with GFX plane and waits for one
  3838. * vertical sync irq before disabling the setup and continuing with
  3839. * the context restore. The physical outputs are gated during the
  3840. * operation. This workaround requires that gamma table's LOADMODE
  3841. * is set to 0x2 in DISPC_CONTROL1 register.
  3842. *
  3843. * For details see:
  3844. * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
  3845. * Literature Number: SWPZ037E
  3846. * Or some other relevant errata document for the DSS IP version.
  3847. */
  3848. static const struct dispc_errata_i734_data {
  3849. struct videomode vm;
  3850. struct omap_overlay_info ovli;
  3851. struct omap_overlay_manager_info mgri;
  3852. struct dss_lcd_mgr_config lcd_conf;
  3853. } i734 = {
  3854. .vm = {
  3855. .hactive = 8, .vactive = 1,
  3856. .pixelclock = 16000000,
  3857. .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
  3858. .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
  3859. .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
  3860. DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
  3861. DISPLAY_FLAGS_PIXDATA_POSEDGE,
  3862. },
  3863. .ovli = {
  3864. .screen_width = 1,
  3865. .width = 1, .height = 1,
  3866. .fourcc = DRM_FORMAT_XRGB8888,
  3867. .rotation = DRM_MODE_ROTATE_0,
  3868. .rotation_type = OMAP_DSS_ROT_NONE,
  3869. .pos_x = 0, .pos_y = 0,
  3870. .out_width = 0, .out_height = 0,
  3871. .global_alpha = 0xff,
  3872. .pre_mult_alpha = 0,
  3873. .zorder = 0,
  3874. },
  3875. .mgri = {
  3876. .default_color = 0,
  3877. .trans_enabled = false,
  3878. .partial_alpha_enabled = false,
  3879. .cpr_enable = false,
  3880. },
  3881. .lcd_conf = {
  3882. .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
  3883. .stallmode = false,
  3884. .fifohandcheck = false,
  3885. .clock_info = {
  3886. .lck_div = 1,
  3887. .pck_div = 2,
  3888. },
  3889. .video_port_width = 24,
  3890. .lcden_sig_polarity = 0,
  3891. },
  3892. };
  3893. static struct i734_buf {
  3894. size_t size;
  3895. dma_addr_t paddr;
  3896. void *vaddr;
  3897. } i734_buf;
  3898. static int dispc_errata_i734_wa_init(struct dispc_device *dispc)
  3899. {
  3900. if (!dispc->feat->has_gamma_i734_bug)
  3901. return 0;
  3902. i734_buf.size = i734.ovli.width * i734.ovli.height *
  3903. color_mode_to_bpp(i734.ovli.fourcc) / 8;
  3904. i734_buf.vaddr = dma_alloc_wc(&dispc->pdev->dev, i734_buf.size,
  3905. &i734_buf.paddr, GFP_KERNEL);
  3906. if (!i734_buf.vaddr) {
  3907. dev_err(&dispc->pdev->dev, "%s: dma_alloc_wc failed\n",
  3908. __func__);
  3909. return -ENOMEM;
  3910. }
  3911. return 0;
  3912. }
  3913. static void dispc_errata_i734_wa_fini(struct dispc_device *dispc)
  3914. {
  3915. if (!dispc->feat->has_gamma_i734_bug)
  3916. return;
  3917. dma_free_wc(&dispc->pdev->dev, i734_buf.size, i734_buf.vaddr,
  3918. i734_buf.paddr);
  3919. }
  3920. static void dispc_errata_i734_wa(struct dispc_device *dispc)
  3921. {
  3922. u32 framedone_irq = dispc_mgr_get_framedone_irq(dispc,
  3923. OMAP_DSS_CHANNEL_LCD);
  3924. struct omap_overlay_info ovli;
  3925. struct dss_lcd_mgr_config lcd_conf;
  3926. u32 gatestate;
  3927. unsigned int count;
  3928. if (!dispc->feat->has_gamma_i734_bug)
  3929. return;
  3930. gatestate = REG_GET(dispc, DISPC_CONFIG, 8, 4);
  3931. ovli = i734.ovli;
  3932. ovli.paddr = i734_buf.paddr;
  3933. lcd_conf = i734.lcd_conf;
  3934. /* Gate all LCD1 outputs */
  3935. REG_FLD_MOD(dispc, DISPC_CONFIG, 0x1f, 8, 4);
  3936. /* Setup and enable GFX plane */
  3937. dispc_ovl_setup(dispc, OMAP_DSS_GFX, &ovli, &i734.vm, false,
  3938. OMAP_DSS_CHANNEL_LCD);
  3939. dispc_ovl_enable(dispc, OMAP_DSS_GFX, true);
  3940. /* Set up and enable display manager for LCD1 */
  3941. dispc_mgr_setup(dispc, OMAP_DSS_CHANNEL_LCD, &i734.mgri);
  3942. dispc_calc_clock_rates(dispc, dss_get_dispc_clk_rate(dispc->dss),
  3943. &lcd_conf.clock_info);
  3944. dispc_mgr_set_lcd_config(dispc, OMAP_DSS_CHANNEL_LCD, &lcd_conf);
  3945. dispc_mgr_set_timings(dispc, OMAP_DSS_CHANNEL_LCD, &i734.vm);
  3946. dispc_clear_irqstatus(dispc, framedone_irq);
  3947. /* Enable and shut the channel to produce just one frame */
  3948. dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, true);
  3949. dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, false);
  3950. /* Busy wait for framedone. We can't fiddle with irq handlers
  3951. * in PM resume. Typically the loop runs less than 5 times and
  3952. * waits less than a micro second.
  3953. */
  3954. count = 0;
  3955. while (!(dispc_read_irqstatus(dispc) & framedone_irq)) {
  3956. if (count++ > 10000) {
  3957. dev_err(&dispc->pdev->dev, "%s: framedone timeout\n",
  3958. __func__);
  3959. break;
  3960. }
  3961. }
  3962. dispc_ovl_enable(dispc, OMAP_DSS_GFX, false);
  3963. /* Clear all irq bits before continuing */
  3964. dispc_clear_irqstatus(dispc, 0xffffffff);
  3965. /* Restore the original state to LCD1 output gates */
  3966. REG_FLD_MOD(dispc, DISPC_CONFIG, gatestate, 8, 4);
  3967. }
  3968. /* DISPC HW IP initialisation */
  3969. static const struct of_device_id dispc_of_match[] = {
  3970. { .compatible = "ti,omap2-dispc", .data = &omap24xx_dispc_feats },
  3971. { .compatible = "ti,omap3-dispc", .data = &omap36xx_dispc_feats },
  3972. { .compatible = "ti,omap4-dispc", .data = &omap44xx_dispc_feats },
  3973. { .compatible = "ti,omap5-dispc", .data = &omap54xx_dispc_feats },
  3974. { .compatible = "ti,dra7-dispc", .data = &omap54xx_dispc_feats },
  3975. {},
  3976. };
  3977. static const struct soc_device_attribute dispc_soc_devices[] = {
  3978. { .machine = "OMAP3[45]*",
  3979. .revision = "ES[12].?", .data = &omap34xx_rev1_0_dispc_feats },
  3980. { .machine = "OMAP3[45]*", .data = &omap34xx_rev3_0_dispc_feats },
  3981. { .machine = "AM35*", .data = &omap34xx_rev3_0_dispc_feats },
  3982. { .machine = "AM43*", .data = &am43xx_dispc_feats },
  3983. { /* sentinel */ }
  3984. };
  3985. static int dispc_bind(struct device *dev, struct device *master, void *data)
  3986. {
  3987. struct platform_device *pdev = to_platform_device(dev);
  3988. const struct soc_device_attribute *soc;
  3989. struct dss_device *dss = dss_get_device(master);
  3990. struct dispc_device *dispc;
  3991. u32 rev;
  3992. int r = 0;
  3993. struct device_node *np = pdev->dev.of_node;
  3994. dispc = kzalloc(sizeof(*dispc), GFP_KERNEL);
  3995. if (!dispc)
  3996. return -ENOMEM;
  3997. dispc->pdev = pdev;
  3998. platform_set_drvdata(pdev, dispc);
  3999. dispc->dss = dss;
  4000. /*
  4001. * The OMAP3-based models can't be told apart using the compatible
  4002. * string, use SoC device matching.
  4003. */
  4004. soc = soc_device_match(dispc_soc_devices);
  4005. if (soc)
  4006. dispc->feat = soc->data;
  4007. else
  4008. dispc->feat = of_match_device(dispc_of_match, &pdev->dev)->data;
  4009. r = dispc_errata_i734_wa_init(dispc);
  4010. if (r)
  4011. goto err_free;
  4012. dispc->base = devm_platform_ioremap_resource(pdev, 0);
  4013. if (IS_ERR(dispc->base)) {
  4014. r = PTR_ERR(dispc->base);
  4015. goto err_free;
  4016. }
  4017. dispc->irq = platform_get_irq(dispc->pdev, 0);
  4018. if (dispc->irq < 0) {
  4019. DSSERR("platform_get_irq failed\n");
  4020. r = -ENODEV;
  4021. goto err_free;
  4022. }
  4023. if (np && of_property_read_bool(np, "syscon-pol")) {
  4024. dispc->syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
  4025. if (IS_ERR(dispc->syscon_pol)) {
  4026. dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
  4027. r = PTR_ERR(dispc->syscon_pol);
  4028. goto err_free;
  4029. }
  4030. if (of_property_read_u32_index(np, "syscon-pol", 1,
  4031. &dispc->syscon_pol_offset)) {
  4032. dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
  4033. r = -EINVAL;
  4034. goto err_free;
  4035. }
  4036. }
  4037. r = dispc_init_gamma_tables(dispc);
  4038. if (r)
  4039. goto err_free;
  4040. pm_runtime_enable(&pdev->dev);
  4041. r = dispc_runtime_get(dispc);
  4042. if (r)
  4043. goto err_runtime_get;
  4044. _omap_dispc_initial_config(dispc);
  4045. rev = dispc_read_reg(dispc, DISPC_REVISION);
  4046. dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
  4047. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  4048. dispc_runtime_put(dispc);
  4049. dss->dispc = dispc;
  4050. dispc->debugfs = dss_debugfs_create_file(dss, "dispc", dispc_dump_regs,
  4051. dispc);
  4052. return 0;
  4053. err_runtime_get:
  4054. pm_runtime_disable(&pdev->dev);
  4055. err_free:
  4056. kfree(dispc);
  4057. return r;
  4058. }
  4059. static void dispc_unbind(struct device *dev, struct device *master, void *data)
  4060. {
  4061. struct dispc_device *dispc = dev_get_drvdata(dev);
  4062. struct dss_device *dss = dispc->dss;
  4063. dss_debugfs_remove_file(dispc->debugfs);
  4064. dss->dispc = NULL;
  4065. pm_runtime_disable(dev);
  4066. dispc_errata_i734_wa_fini(dispc);
  4067. kfree(dispc);
  4068. }
  4069. static const struct component_ops dispc_component_ops = {
  4070. .bind = dispc_bind,
  4071. .unbind = dispc_unbind,
  4072. };
  4073. static int dispc_probe(struct platform_device *pdev)
  4074. {
  4075. return component_add(&pdev->dev, &dispc_component_ops);
  4076. }
  4077. static int dispc_remove(struct platform_device *pdev)
  4078. {
  4079. component_del(&pdev->dev, &dispc_component_ops);
  4080. return 0;
  4081. }
  4082. static __maybe_unused int dispc_runtime_suspend(struct device *dev)
  4083. {
  4084. struct dispc_device *dispc = dev_get_drvdata(dev);
  4085. dispc->is_enabled = false;
  4086. /* ensure the dispc_irq_handler sees the is_enabled value */
  4087. smp_wmb();
  4088. /* wait for current handler to finish before turning the DISPC off */
  4089. synchronize_irq(dispc->irq);
  4090. dispc_save_context(dispc);
  4091. return 0;
  4092. }
  4093. static __maybe_unused int dispc_runtime_resume(struct device *dev)
  4094. {
  4095. struct dispc_device *dispc = dev_get_drvdata(dev);
  4096. /*
  4097. * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
  4098. * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
  4099. * _omap_dispc_initial_config(). We can thus use it to detect if
  4100. * we have lost register context.
  4101. */
  4102. if (REG_GET(dispc, DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
  4103. _omap_dispc_initial_config(dispc);
  4104. dispc_errata_i734_wa(dispc);
  4105. dispc_restore_context(dispc);
  4106. dispc_restore_gamma_tables(dispc);
  4107. }
  4108. dispc->is_enabled = true;
  4109. /* ensure the dispc_irq_handler sees the is_enabled value */
  4110. smp_wmb();
  4111. return 0;
  4112. }
  4113. static const struct dev_pm_ops dispc_pm_ops = {
  4114. SET_RUNTIME_PM_OPS(dispc_runtime_suspend, dispc_runtime_resume, NULL)
  4115. SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
  4116. };
  4117. struct platform_driver omap_dispchw_driver = {
  4118. .probe = dispc_probe,
  4119. .remove = dispc_remove,
  4120. .driver = {
  4121. .name = "omapdss_dispc",
  4122. .pm = &dispc_pm_ops,
  4123. .of_match_table = dispc_of_match,
  4124. .suppress_bind_attrs = true,
  4125. },
  4126. };