dispc.c 128 KB

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