dispc.c 91 KB

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