dispc.c 99 KB

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