dispc.c 133 KB

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