dispc.c 103 KB

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