dispc.c 90 KB

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