dispc.c 103 KB

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