dispc.c 102 KB

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