dispc.c 110 KB

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