dispc.c 110 KB

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