dispc.c 91 KB

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