dispc.c 103 KB

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