dispc.c 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966
  1. /*
  2. * Copyright (C) 2009 Nokia Corporation
  3. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  4. *
  5. * Some code and ideas taken from drivers/video/omap/ driver
  6. * by Imre Deak.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published by
  10. * the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #define DSS_SUBSYS_NAME "DISPC"
  21. #include <linux/kernel.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/export.h>
  25. #include <linux/clk.h>
  26. #include <linux/io.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/delay.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/hardirq.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/pm_runtime.h>
  34. #include <linux/sizes.h>
  35. #include <linux/mfd/syscon.h>
  36. #include <linux/regmap.h>
  37. #include <linux/of.h>
  38. #include <linux/of_device.h>
  39. #include <linux/component.h>
  40. #include <linux/sys_soc.h>
  41. #include <drm/drm_fourcc.h>
  42. #include <drm/drm_blend.h>
  43. #include "omapdss.h"
  44. #include "dss.h"
  45. #include "dispc.h"
  46. struct dispc_device;
  47. /* DISPC */
  48. #define DISPC_SZ_REGS SZ_4K
  49. enum omap_burst_size {
  50. BURST_SIZE_X2 = 0,
  51. BURST_SIZE_X4 = 1,
  52. BURST_SIZE_X8 = 2,
  53. };
  54. #define REG_GET(dispc, idx, start, end) \
  55. FLD_GET(dispc_read_reg(dispc, idx), start, end)
  56. #define REG_FLD_MOD(dispc, idx, val, start, end) \
  57. dispc_write_reg(dispc, idx, \
  58. FLD_MOD(dispc_read_reg(dispc, idx), val, start, end))
  59. /* DISPC has feature id */
  60. enum dispc_feature_id {
  61. FEAT_LCDENABLEPOL,
  62. FEAT_LCDENABLESIGNAL,
  63. FEAT_PCKFREEENABLE,
  64. FEAT_FUNCGATED,
  65. FEAT_MGR_LCD2,
  66. FEAT_MGR_LCD3,
  67. FEAT_LINEBUFFERSPLIT,
  68. FEAT_ROWREPEATENABLE,
  69. FEAT_RESIZECONF,
  70. /* Independent core clk divider */
  71. FEAT_CORE_CLK_DIV,
  72. FEAT_HANDLE_UV_SEPARATE,
  73. FEAT_ATTR2,
  74. FEAT_CPR,
  75. FEAT_PRELOAD,
  76. FEAT_FIR_COEF_V,
  77. FEAT_ALPHA_FIXED_ZORDER,
  78. FEAT_ALPHA_FREE_ZORDER,
  79. FEAT_FIFO_MERGE,
  80. /* An unknown HW bug causing the normal FIFO thresholds not to work */
  81. FEAT_OMAP3_DSI_FIFO_BUG,
  82. FEAT_BURST_2D,
  83. FEAT_MFLAG,
  84. };
  85. struct dispc_features {
  86. u8 sw_start;
  87. u8 fp_start;
  88. u8 bp_start;
  89. u16 sw_max;
  90. u16 vp_max;
  91. u16 hp_max;
  92. u8 mgr_width_start;
  93. u8 mgr_height_start;
  94. u16 mgr_width_max;
  95. u16 mgr_height_max;
  96. unsigned long max_lcd_pclk;
  97. unsigned long max_tv_pclk;
  98. unsigned int max_downscale;
  99. unsigned int max_line_width;
  100. unsigned int min_pcd;
  101. int (*calc_scaling)(struct dispc_device *dispc,
  102. unsigned long pclk, unsigned long lclk,
  103. const struct videomode *vm,
  104. u16 width, u16 height, u16 out_width, u16 out_height,
  105. u32 fourcc, bool *five_taps,
  106. int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
  107. u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
  108. unsigned long (*calc_core_clk) (unsigned long pclk,
  109. u16 width, u16 height, u16 out_width, u16 out_height,
  110. bool mem_to_mem);
  111. u8 num_fifos;
  112. const enum dispc_feature_id *features;
  113. unsigned int num_features;
  114. const struct dss_reg_field *reg_fields;
  115. const unsigned int num_reg_fields;
  116. const enum omap_overlay_caps *overlay_caps;
  117. const u32 **supported_color_modes;
  118. unsigned int num_mgrs;
  119. unsigned int num_ovls;
  120. unsigned int buffer_size_unit;
  121. unsigned int burst_size_unit;
  122. /* swap GFX & WB fifos */
  123. bool gfx_fifo_workaround:1;
  124. /* no DISPC_IRQ_FRAMEDONETV on this SoC */
  125. bool no_framedone_tv:1;
  126. /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
  127. bool mstandby_workaround:1;
  128. bool set_max_preload:1;
  129. /* PIXEL_INC is not added to the last pixel of a line */
  130. bool last_pixel_inc_missing:1;
  131. /* POL_FREQ has ALIGN bit */
  132. bool supports_sync_align:1;
  133. bool has_writeback:1;
  134. bool supports_double_pixel:1;
  135. /*
  136. * Field order for VENC is different than HDMI. We should handle this in
  137. * some intelligent manner, but as the SoCs have either HDMI or VENC,
  138. * never both, we can just use this flag for now.
  139. */
  140. bool reverse_ilace_field_order:1;
  141. bool has_gamma_table:1;
  142. bool has_gamma_i734_bug:1;
  143. };
  144. #define DISPC_MAX_NR_FIFOS 5
  145. #define DISPC_MAX_CHANNEL_GAMMA 4
  146. struct dispc_device {
  147. struct platform_device *pdev;
  148. void __iomem *base;
  149. struct dss_device *dss;
  150. struct dss_debugfs_entry *debugfs;
  151. int irq;
  152. irq_handler_t user_handler;
  153. void *user_data;
  154. unsigned long core_clk_rate;
  155. unsigned long tv_pclk_rate;
  156. u32 fifo_size[DISPC_MAX_NR_FIFOS];
  157. /* maps which plane is using a fifo. fifo-id -> plane-id */
  158. int fifo_assignment[DISPC_MAX_NR_FIFOS];
  159. bool ctx_valid;
  160. u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
  161. u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA];
  162. const struct dispc_features *feat;
  163. bool is_enabled;
  164. struct regmap *syscon_pol;
  165. u32 syscon_pol_offset;
  166. /* DISPC_CONTROL & DISPC_CONFIG lock*/
  167. spinlock_t control_lock;
  168. };
  169. enum omap_color_component {
  170. /* used for all color formats for OMAP3 and earlier
  171. * and for RGB and Y color component on OMAP4
  172. */
  173. DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
  174. /* used for UV component for
  175. * DRM_FORMAT_YUYV, DRM_FORMAT_UYVY, DRM_FORMAT_NV12
  176. * color formats on OMAP4
  177. */
  178. DISPC_COLOR_COMPONENT_UV = 1 << 1,
  179. };
  180. enum mgr_reg_fields {
  181. DISPC_MGR_FLD_ENABLE,
  182. DISPC_MGR_FLD_STNTFT,
  183. DISPC_MGR_FLD_GO,
  184. DISPC_MGR_FLD_TFTDATALINES,
  185. DISPC_MGR_FLD_STALLMODE,
  186. DISPC_MGR_FLD_TCKENABLE,
  187. DISPC_MGR_FLD_TCKSELECTION,
  188. DISPC_MGR_FLD_CPR,
  189. DISPC_MGR_FLD_FIFOHANDCHECK,
  190. /* used to maintain a count of the above fields */
  191. DISPC_MGR_FLD_NUM,
  192. };
  193. /* DISPC register field id */
  194. enum dispc_feat_reg_field {
  195. FEAT_REG_FIRHINC,
  196. FEAT_REG_FIRVINC,
  197. FEAT_REG_FIFOHIGHTHRESHOLD,
  198. FEAT_REG_FIFOLOWTHRESHOLD,
  199. FEAT_REG_FIFOSIZE,
  200. FEAT_REG_HORIZONTALACCU,
  201. FEAT_REG_VERTICALACCU,
  202. };
  203. struct dispc_reg_field {
  204. u16 reg;
  205. u8 high;
  206. u8 low;
  207. };
  208. struct dispc_gamma_desc {
  209. u32 len;
  210. u32 bits;
  211. u16 reg;
  212. bool has_index;
  213. };
  214. static const struct {
  215. const char *name;
  216. u32 vsync_irq;
  217. u32 framedone_irq;
  218. u32 sync_lost_irq;
  219. struct dispc_gamma_desc gamma;
  220. struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
  221. } mgr_desc[] = {
  222. [OMAP_DSS_CHANNEL_LCD] = {
  223. .name = "LCD",
  224. .vsync_irq = DISPC_IRQ_VSYNC,
  225. .framedone_irq = DISPC_IRQ_FRAMEDONE,
  226. .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
  227. .gamma = {
  228. .len = 256,
  229. .bits = 8,
  230. .reg = DISPC_GAMMA_TABLE0,
  231. .has_index = true,
  232. },
  233. .reg_desc = {
  234. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
  235. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
  236. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
  237. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
  238. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
  239. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
  240. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
  241. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
  242. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
  243. },
  244. },
  245. [OMAP_DSS_CHANNEL_DIGIT] = {
  246. .name = "DIGIT",
  247. .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
  248. .framedone_irq = DISPC_IRQ_FRAMEDONETV,
  249. .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
  250. .gamma = {
  251. .len = 1024,
  252. .bits = 10,
  253. .reg = DISPC_GAMMA_TABLE2,
  254. .has_index = false,
  255. },
  256. .reg_desc = {
  257. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
  258. [DISPC_MGR_FLD_STNTFT] = { },
  259. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
  260. [DISPC_MGR_FLD_TFTDATALINES] = { },
  261. [DISPC_MGR_FLD_STALLMODE] = { },
  262. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
  263. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
  264. [DISPC_MGR_FLD_CPR] = { },
  265. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
  266. },
  267. },
  268. [OMAP_DSS_CHANNEL_LCD2] = {
  269. .name = "LCD2",
  270. .vsync_irq = DISPC_IRQ_VSYNC2,
  271. .framedone_irq = DISPC_IRQ_FRAMEDONE2,
  272. .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
  273. .gamma = {
  274. .len = 256,
  275. .bits = 8,
  276. .reg = DISPC_GAMMA_TABLE1,
  277. .has_index = true,
  278. },
  279. .reg_desc = {
  280. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
  281. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
  282. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
  283. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
  284. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
  285. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
  286. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
  287. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
  288. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
  289. },
  290. },
  291. [OMAP_DSS_CHANNEL_LCD3] = {
  292. .name = "LCD3",
  293. .vsync_irq = DISPC_IRQ_VSYNC3,
  294. .framedone_irq = DISPC_IRQ_FRAMEDONE3,
  295. .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
  296. .gamma = {
  297. .len = 256,
  298. .bits = 8,
  299. .reg = DISPC_GAMMA_TABLE3,
  300. .has_index = true,
  301. },
  302. .reg_desc = {
  303. [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
  304. [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
  305. [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
  306. [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
  307. [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
  308. [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
  309. [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
  310. [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
  311. [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
  312. },
  313. },
  314. };
  315. static unsigned long dispc_fclk_rate(struct dispc_device *dispc);
  316. static unsigned long dispc_core_clk_rate(struct dispc_device *dispc);
  317. static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
  318. enum omap_channel channel);
  319. static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
  320. enum omap_channel channel);
  321. static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
  322. enum omap_plane_id plane);
  323. static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
  324. enum omap_plane_id plane);
  325. static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask);
  326. static inline void dispc_write_reg(struct dispc_device *dispc, u16 idx, u32 val)
  327. {
  328. __raw_writel(val, dispc->base + idx);
  329. }
  330. static inline u32 dispc_read_reg(struct dispc_device *dispc, u16 idx)
  331. {
  332. return __raw_readl(dispc->base + idx);
  333. }
  334. static u32 mgr_fld_read(struct dispc_device *dispc, enum omap_channel channel,
  335. enum mgr_reg_fields regfld)
  336. {
  337. const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
  338. return REG_GET(dispc, rfld.reg, rfld.high, rfld.low);
  339. }
  340. static void mgr_fld_write(struct dispc_device *dispc, enum omap_channel channel,
  341. enum mgr_reg_fields regfld, int val)
  342. {
  343. const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
  344. const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
  345. unsigned long flags;
  346. if (need_lock) {
  347. spin_lock_irqsave(&dispc->control_lock, flags);
  348. REG_FLD_MOD(dispc, rfld.reg, val, rfld.high, rfld.low);
  349. spin_unlock_irqrestore(&dispc->control_lock, flags);
  350. } else {
  351. REG_FLD_MOD(dispc, rfld.reg, val, rfld.high, rfld.low);
  352. }
  353. }
  354. static int dispc_get_num_ovls(struct dispc_device *dispc)
  355. {
  356. return dispc->feat->num_ovls;
  357. }
  358. static int dispc_get_num_mgrs(struct dispc_device *dispc)
  359. {
  360. return dispc->feat->num_mgrs;
  361. }
  362. static void dispc_get_reg_field(struct dispc_device *dispc,
  363. enum dispc_feat_reg_field id,
  364. u8 *start, u8 *end)
  365. {
  366. if (id >= dispc->feat->num_reg_fields)
  367. BUG();
  368. *start = dispc->feat->reg_fields[id].start;
  369. *end = dispc->feat->reg_fields[id].end;
  370. }
  371. static bool dispc_has_feature(struct dispc_device *dispc,
  372. enum dispc_feature_id id)
  373. {
  374. unsigned int i;
  375. for (i = 0; i < dispc->feat->num_features; i++) {
  376. if (dispc->feat->features[i] == id)
  377. return true;
  378. }
  379. return false;
  380. }
  381. #define SR(dispc, reg) \
  382. dispc->ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(dispc, DISPC_##reg)
  383. #define RR(dispc, reg) \
  384. dispc_write_reg(dispc, DISPC_##reg, dispc->ctx[DISPC_##reg / sizeof(u32)])
  385. static void dispc_save_context(struct dispc_device *dispc)
  386. {
  387. int i, j;
  388. DSSDBG("dispc_save_context\n");
  389. SR(dispc, IRQENABLE);
  390. SR(dispc, CONTROL);
  391. SR(dispc, CONFIG);
  392. SR(dispc, LINE_NUMBER);
  393. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  394. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  395. SR(dispc, GLOBAL_ALPHA);
  396. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  397. SR(dispc, CONTROL2);
  398. SR(dispc, CONFIG2);
  399. }
  400. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  401. SR(dispc, CONTROL3);
  402. SR(dispc, CONFIG3);
  403. }
  404. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  405. SR(dispc, DEFAULT_COLOR(i));
  406. SR(dispc, TRANS_COLOR(i));
  407. SR(dispc, SIZE_MGR(i));
  408. if (i == OMAP_DSS_CHANNEL_DIGIT)
  409. continue;
  410. SR(dispc, TIMING_H(i));
  411. SR(dispc, TIMING_V(i));
  412. SR(dispc, POL_FREQ(i));
  413. SR(dispc, DIVISORo(i));
  414. SR(dispc, DATA_CYCLE1(i));
  415. SR(dispc, DATA_CYCLE2(i));
  416. SR(dispc, DATA_CYCLE3(i));
  417. if (dispc_has_feature(dispc, FEAT_CPR)) {
  418. SR(dispc, CPR_COEF_R(i));
  419. SR(dispc, CPR_COEF_G(i));
  420. SR(dispc, CPR_COEF_B(i));
  421. }
  422. }
  423. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  424. SR(dispc, OVL_BA0(i));
  425. SR(dispc, OVL_BA1(i));
  426. SR(dispc, OVL_POSITION(i));
  427. SR(dispc, OVL_SIZE(i));
  428. SR(dispc, OVL_ATTRIBUTES(i));
  429. SR(dispc, OVL_FIFO_THRESHOLD(i));
  430. SR(dispc, OVL_ROW_INC(i));
  431. SR(dispc, OVL_PIXEL_INC(i));
  432. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  433. SR(dispc, OVL_PRELOAD(i));
  434. if (i == OMAP_DSS_GFX) {
  435. SR(dispc, OVL_WINDOW_SKIP(i));
  436. SR(dispc, OVL_TABLE_BA(i));
  437. continue;
  438. }
  439. SR(dispc, OVL_FIR(i));
  440. SR(dispc, OVL_PICTURE_SIZE(i));
  441. SR(dispc, OVL_ACCU0(i));
  442. SR(dispc, OVL_ACCU1(i));
  443. for (j = 0; j < 8; j++)
  444. SR(dispc, OVL_FIR_COEF_H(i, j));
  445. for (j = 0; j < 8; j++)
  446. SR(dispc, OVL_FIR_COEF_HV(i, j));
  447. for (j = 0; j < 5; j++)
  448. SR(dispc, OVL_CONV_COEF(i, j));
  449. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  450. for (j = 0; j < 8; j++)
  451. SR(dispc, OVL_FIR_COEF_V(i, j));
  452. }
  453. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  454. SR(dispc, OVL_BA0_UV(i));
  455. SR(dispc, OVL_BA1_UV(i));
  456. SR(dispc, OVL_FIR2(i));
  457. SR(dispc, OVL_ACCU2_0(i));
  458. SR(dispc, OVL_ACCU2_1(i));
  459. for (j = 0; j < 8; j++)
  460. SR(dispc, OVL_FIR_COEF_H2(i, j));
  461. for (j = 0; j < 8; j++)
  462. SR(dispc, OVL_FIR_COEF_HV2(i, j));
  463. for (j = 0; j < 8; j++)
  464. SR(dispc, OVL_FIR_COEF_V2(i, j));
  465. }
  466. if (dispc_has_feature(dispc, FEAT_ATTR2))
  467. SR(dispc, OVL_ATTRIBUTES2(i));
  468. }
  469. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  470. SR(dispc, DIVISOR);
  471. dispc->ctx_valid = true;
  472. DSSDBG("context saved\n");
  473. }
  474. static void dispc_restore_context(struct dispc_device *dispc)
  475. {
  476. int i, j;
  477. DSSDBG("dispc_restore_context\n");
  478. if (!dispc->ctx_valid)
  479. return;
  480. /*RR(dispc, IRQENABLE);*/
  481. /*RR(dispc, CONTROL);*/
  482. RR(dispc, CONFIG);
  483. RR(dispc, LINE_NUMBER);
  484. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  485. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  486. RR(dispc, GLOBAL_ALPHA);
  487. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  488. RR(dispc, CONFIG2);
  489. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  490. RR(dispc, CONFIG3);
  491. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  492. RR(dispc, DEFAULT_COLOR(i));
  493. RR(dispc, TRANS_COLOR(i));
  494. RR(dispc, SIZE_MGR(i));
  495. if (i == OMAP_DSS_CHANNEL_DIGIT)
  496. continue;
  497. RR(dispc, TIMING_H(i));
  498. RR(dispc, TIMING_V(i));
  499. RR(dispc, POL_FREQ(i));
  500. RR(dispc, DIVISORo(i));
  501. RR(dispc, DATA_CYCLE1(i));
  502. RR(dispc, DATA_CYCLE2(i));
  503. RR(dispc, DATA_CYCLE3(i));
  504. if (dispc_has_feature(dispc, FEAT_CPR)) {
  505. RR(dispc, CPR_COEF_R(i));
  506. RR(dispc, CPR_COEF_G(i));
  507. RR(dispc, CPR_COEF_B(i));
  508. }
  509. }
  510. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  511. RR(dispc, OVL_BA0(i));
  512. RR(dispc, OVL_BA1(i));
  513. RR(dispc, OVL_POSITION(i));
  514. RR(dispc, OVL_SIZE(i));
  515. RR(dispc, OVL_ATTRIBUTES(i));
  516. RR(dispc, OVL_FIFO_THRESHOLD(i));
  517. RR(dispc, OVL_ROW_INC(i));
  518. RR(dispc, OVL_PIXEL_INC(i));
  519. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  520. RR(dispc, OVL_PRELOAD(i));
  521. if (i == OMAP_DSS_GFX) {
  522. RR(dispc, OVL_WINDOW_SKIP(i));
  523. RR(dispc, OVL_TABLE_BA(i));
  524. continue;
  525. }
  526. RR(dispc, OVL_FIR(i));
  527. RR(dispc, OVL_PICTURE_SIZE(i));
  528. RR(dispc, OVL_ACCU0(i));
  529. RR(dispc, OVL_ACCU1(i));
  530. for (j = 0; j < 8; j++)
  531. RR(dispc, OVL_FIR_COEF_H(i, j));
  532. for (j = 0; j < 8; j++)
  533. RR(dispc, OVL_FIR_COEF_HV(i, j));
  534. for (j = 0; j < 5; j++)
  535. RR(dispc, OVL_CONV_COEF(i, j));
  536. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  537. for (j = 0; j < 8; j++)
  538. RR(dispc, OVL_FIR_COEF_V(i, j));
  539. }
  540. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  541. RR(dispc, OVL_BA0_UV(i));
  542. RR(dispc, OVL_BA1_UV(i));
  543. RR(dispc, OVL_FIR2(i));
  544. RR(dispc, OVL_ACCU2_0(i));
  545. RR(dispc, OVL_ACCU2_1(i));
  546. for (j = 0; j < 8; j++)
  547. RR(dispc, OVL_FIR_COEF_H2(i, j));
  548. for (j = 0; j < 8; j++)
  549. RR(dispc, OVL_FIR_COEF_HV2(i, j));
  550. for (j = 0; j < 8; j++)
  551. RR(dispc, OVL_FIR_COEF_V2(i, j));
  552. }
  553. if (dispc_has_feature(dispc, FEAT_ATTR2))
  554. RR(dispc, OVL_ATTRIBUTES2(i));
  555. }
  556. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  557. RR(dispc, DIVISOR);
  558. /* enable last, because LCD & DIGIT enable are here */
  559. RR(dispc, CONTROL);
  560. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  561. RR(dispc, CONTROL2);
  562. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  563. RR(dispc, CONTROL3);
  564. /* clear spurious SYNC_LOST_DIGIT interrupts */
  565. dispc_clear_irqstatus(dispc, DISPC_IRQ_SYNC_LOST_DIGIT);
  566. /*
  567. * enable last so IRQs won't trigger before
  568. * the context is fully restored
  569. */
  570. RR(dispc, IRQENABLE);
  571. DSSDBG("context restored\n");
  572. }
  573. #undef SR
  574. #undef RR
  575. int dispc_runtime_get(struct dispc_device *dispc)
  576. {
  577. int r;
  578. DSSDBG("dispc_runtime_get\n");
  579. r = pm_runtime_get_sync(&dispc->pdev->dev);
  580. WARN_ON(r < 0);
  581. return r < 0 ? r : 0;
  582. }
  583. void dispc_runtime_put(struct dispc_device *dispc)
  584. {
  585. int r;
  586. DSSDBG("dispc_runtime_put\n");
  587. r = pm_runtime_put_sync(&dispc->pdev->dev);
  588. WARN_ON(r < 0 && r != -ENOSYS);
  589. }
  590. static u32 dispc_mgr_get_vsync_irq(struct dispc_device *dispc,
  591. enum omap_channel channel)
  592. {
  593. return mgr_desc[channel].vsync_irq;
  594. }
  595. static u32 dispc_mgr_get_framedone_irq(struct dispc_device *dispc,
  596. enum omap_channel channel)
  597. {
  598. if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc->feat->no_framedone_tv)
  599. return 0;
  600. return mgr_desc[channel].framedone_irq;
  601. }
  602. static u32 dispc_mgr_get_sync_lost_irq(struct dispc_device *dispc,
  603. enum omap_channel channel)
  604. {
  605. return mgr_desc[channel].sync_lost_irq;
  606. }
  607. static u32 dispc_wb_get_framedone_irq(struct dispc_device *dispc)
  608. {
  609. return DISPC_IRQ_FRAMEDONEWB;
  610. }
  611. static void dispc_mgr_enable(struct dispc_device *dispc,
  612. enum omap_channel channel, bool enable)
  613. {
  614. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_ENABLE, enable);
  615. /* flush posted write */
  616. mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
  617. }
  618. static bool dispc_mgr_is_enabled(struct dispc_device *dispc,
  619. enum omap_channel channel)
  620. {
  621. return !!mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
  622. }
  623. static bool dispc_mgr_go_busy(struct dispc_device *dispc,
  624. enum omap_channel channel)
  625. {
  626. return mgr_fld_read(dispc, channel, DISPC_MGR_FLD_GO) == 1;
  627. }
  628. static void dispc_mgr_go(struct dispc_device *dispc, enum omap_channel channel)
  629. {
  630. WARN_ON(!dispc_mgr_is_enabled(dispc, channel));
  631. WARN_ON(dispc_mgr_go_busy(dispc, channel));
  632. DSSDBG("GO %s\n", mgr_desc[channel].name);
  633. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_GO, 1);
  634. }
  635. static bool dispc_wb_go_busy(struct dispc_device *dispc)
  636. {
  637. return REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
  638. }
  639. static void dispc_wb_go(struct dispc_device *dispc)
  640. {
  641. enum omap_plane_id plane = OMAP_DSS_WB;
  642. bool enable, go;
  643. enable = REG_GET(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
  644. if (!enable)
  645. return;
  646. go = REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
  647. if (go) {
  648. DSSERR("GO bit not down for WB\n");
  649. return;
  650. }
  651. REG_FLD_MOD(dispc, DISPC_CONTROL2, 1, 6, 6);
  652. }
  653. static void dispc_ovl_write_firh_reg(struct dispc_device *dispc,
  654. enum omap_plane_id plane, int reg,
  655. u32 value)
  656. {
  657. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H(plane, reg), value);
  658. }
  659. static void dispc_ovl_write_firhv_reg(struct dispc_device *dispc,
  660. enum omap_plane_id plane, int reg,
  661. u32 value)
  662. {
  663. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV(plane, reg), value);
  664. }
  665. static void dispc_ovl_write_firv_reg(struct dispc_device *dispc,
  666. enum omap_plane_id plane, int reg,
  667. u32 value)
  668. {
  669. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V(plane, reg), value);
  670. }
  671. static void dispc_ovl_write_firh2_reg(struct dispc_device *dispc,
  672. enum omap_plane_id plane, int reg,
  673. u32 value)
  674. {
  675. BUG_ON(plane == OMAP_DSS_GFX);
  676. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H2(plane, reg), value);
  677. }
  678. static void dispc_ovl_write_firhv2_reg(struct dispc_device *dispc,
  679. enum omap_plane_id plane, int reg,
  680. u32 value)
  681. {
  682. BUG_ON(plane == OMAP_DSS_GFX);
  683. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
  684. }
  685. static void dispc_ovl_write_firv2_reg(struct dispc_device *dispc,
  686. enum omap_plane_id plane, int reg,
  687. u32 value)
  688. {
  689. BUG_ON(plane == OMAP_DSS_GFX);
  690. dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V2(plane, reg), value);
  691. }
  692. static void dispc_ovl_set_scale_coef(struct dispc_device *dispc,
  693. enum omap_plane_id plane, int fir_hinc,
  694. int fir_vinc, int five_taps,
  695. enum omap_color_component color_comp)
  696. {
  697. const struct dispc_coef *h_coef, *v_coef;
  698. int i;
  699. h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
  700. v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
  701. if (!h_coef || !v_coef) {
  702. dev_err(&dispc->pdev->dev, "%s: failed to find scale coefs\n",
  703. __func__);
  704. return;
  705. }
  706. for (i = 0; i < 8; i++) {
  707. u32 h, hv;
  708. h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
  709. | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
  710. | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
  711. | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
  712. hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
  713. | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
  714. | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
  715. | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
  716. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  717. dispc_ovl_write_firh_reg(dispc, plane, i, h);
  718. dispc_ovl_write_firhv_reg(dispc, plane, i, hv);
  719. } else {
  720. dispc_ovl_write_firh2_reg(dispc, plane, i, h);
  721. dispc_ovl_write_firhv2_reg(dispc, plane, i, hv);
  722. }
  723. }
  724. if (five_taps) {
  725. for (i = 0; i < 8; i++) {
  726. u32 v;
  727. v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
  728. | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
  729. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
  730. dispc_ovl_write_firv_reg(dispc, plane, i, v);
  731. else
  732. dispc_ovl_write_firv2_reg(dispc, plane, i, v);
  733. }
  734. }
  735. }
  736. struct csc_coef_yuv2rgb {
  737. int ry, rcb, rcr, gy, gcb, gcr, by, bcb, bcr;
  738. bool full_range;
  739. };
  740. struct csc_coef_rgb2yuv {
  741. int yr, yg, yb, cbr, cbg, cbb, crr, crg, crb;
  742. bool full_range;
  743. };
  744. static void dispc_ovl_write_color_conv_coef(struct dispc_device *dispc,
  745. enum omap_plane_id plane,
  746. const struct csc_coef_yuv2rgb *ct)
  747. {
  748. #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
  749. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
  750. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
  751. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
  752. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
  753. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
  754. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
  755. #undef CVAL
  756. }
  757. static void dispc_wb_write_color_conv_coef(struct dispc_device *dispc,
  758. const struct csc_coef_rgb2yuv *ct)
  759. {
  760. const enum omap_plane_id plane = OMAP_DSS_WB;
  761. #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
  762. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->yg, ct->yr));
  763. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->crr, ct->yb));
  764. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->crb, ct->crg));
  765. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->cbg, ct->cbr));
  766. dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->cbb));
  767. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
  768. #undef CVAL
  769. }
  770. static void dispc_setup_color_conv_coef(struct dispc_device *dispc)
  771. {
  772. int i;
  773. int num_ovl = dispc_get_num_ovls(dispc);
  774. /* YUV -> RGB, ITU-R BT.601, limited range */
  775. const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt601_lim = {
  776. 298, 0, 409, /* ry, rcb, rcr */
  777. 298, -100, -208, /* gy, gcb, gcr */
  778. 298, 516, 0, /* by, bcb, bcr */
  779. false, /* limited range */
  780. };
  781. /* RGB -> YUV, ITU-R BT.601, limited range */
  782. const struct csc_coef_rgb2yuv coefs_rgb2yuv_bt601_lim = {
  783. 66, 129, 25, /* yr, yg, yb */
  784. -38, -74, 112, /* cbr, cbg, cbb */
  785. 112, -94, -18, /* crr, crg, crb */
  786. false, /* limited range */
  787. };
  788. for (i = 1; i < num_ovl; i++)
  789. dispc_ovl_write_color_conv_coef(dispc, i, &coefs_yuv2rgb_bt601_lim);
  790. if (dispc->feat->has_writeback)
  791. dispc_wb_write_color_conv_coef(dispc, &coefs_rgb2yuv_bt601_lim);
  792. }
  793. static void dispc_ovl_set_ba0(struct dispc_device *dispc,
  794. enum omap_plane_id plane, u32 paddr)
  795. {
  796. dispc_write_reg(dispc, DISPC_OVL_BA0(plane), paddr);
  797. }
  798. static void dispc_ovl_set_ba1(struct dispc_device *dispc,
  799. enum omap_plane_id plane, u32 paddr)
  800. {
  801. dispc_write_reg(dispc, DISPC_OVL_BA1(plane), paddr);
  802. }
  803. static void dispc_ovl_set_ba0_uv(struct dispc_device *dispc,
  804. enum omap_plane_id plane, u32 paddr)
  805. {
  806. dispc_write_reg(dispc, DISPC_OVL_BA0_UV(plane), paddr);
  807. }
  808. static void dispc_ovl_set_ba1_uv(struct dispc_device *dispc,
  809. enum omap_plane_id plane, u32 paddr)
  810. {
  811. dispc_write_reg(dispc, DISPC_OVL_BA1_UV(plane), paddr);
  812. }
  813. static void dispc_ovl_set_pos(struct dispc_device *dispc,
  814. enum omap_plane_id plane,
  815. enum omap_overlay_caps caps, int x, int y)
  816. {
  817. u32 val;
  818. if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
  819. return;
  820. val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
  821. dispc_write_reg(dispc, DISPC_OVL_POSITION(plane), val);
  822. }
  823. static void dispc_ovl_set_input_size(struct dispc_device *dispc,
  824. enum omap_plane_id plane, int width,
  825. int height)
  826. {
  827. u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  828. if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
  829. dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
  830. else
  831. dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
  832. }
  833. static void dispc_ovl_set_output_size(struct dispc_device *dispc,
  834. enum omap_plane_id plane, int width,
  835. int height)
  836. {
  837. u32 val;
  838. BUG_ON(plane == OMAP_DSS_GFX);
  839. val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
  840. if (plane == OMAP_DSS_WB)
  841. dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
  842. else
  843. dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
  844. }
  845. static void dispc_ovl_set_zorder(struct dispc_device *dispc,
  846. enum omap_plane_id plane,
  847. enum omap_overlay_caps caps, u8 zorder)
  848. {
  849. if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
  850. return;
  851. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
  852. }
  853. static void dispc_ovl_enable_zorder_planes(struct dispc_device *dispc)
  854. {
  855. int i;
  856. if (!dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  857. return;
  858. for (i = 0; i < dispc_get_num_ovls(dispc); i++)
  859. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
  860. }
  861. static void dispc_ovl_set_pre_mult_alpha(struct dispc_device *dispc,
  862. enum omap_plane_id plane,
  863. enum omap_overlay_caps caps,
  864. bool enable)
  865. {
  866. if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
  867. return;
  868. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
  869. }
  870. static void dispc_ovl_setup_global_alpha(struct dispc_device *dispc,
  871. enum omap_plane_id plane,
  872. enum omap_overlay_caps caps,
  873. u8 global_alpha)
  874. {
  875. static const unsigned int shifts[] = { 0, 8, 16, 24, };
  876. int shift;
  877. if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
  878. return;
  879. shift = shifts[plane];
  880. REG_FLD_MOD(dispc, DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
  881. }
  882. static void dispc_ovl_set_pix_inc(struct dispc_device *dispc,
  883. enum omap_plane_id plane, s32 inc)
  884. {
  885. dispc_write_reg(dispc, DISPC_OVL_PIXEL_INC(plane), inc);
  886. }
  887. static void dispc_ovl_set_row_inc(struct dispc_device *dispc,
  888. enum omap_plane_id plane, s32 inc)
  889. {
  890. dispc_write_reg(dispc, DISPC_OVL_ROW_INC(plane), inc);
  891. }
  892. static void dispc_ovl_set_color_mode(struct dispc_device *dispc,
  893. enum omap_plane_id plane, u32 fourcc)
  894. {
  895. u32 m = 0;
  896. if (plane != OMAP_DSS_GFX) {
  897. switch (fourcc) {
  898. case DRM_FORMAT_NV12:
  899. m = 0x0; break;
  900. case DRM_FORMAT_XRGB4444:
  901. m = 0x1; break;
  902. case DRM_FORMAT_RGBA4444:
  903. m = 0x2; break;
  904. case DRM_FORMAT_RGBX4444:
  905. m = 0x4; break;
  906. case DRM_FORMAT_ARGB4444:
  907. m = 0x5; break;
  908. case DRM_FORMAT_RGB565:
  909. m = 0x6; break;
  910. case DRM_FORMAT_ARGB1555:
  911. m = 0x7; break;
  912. case DRM_FORMAT_XRGB8888:
  913. m = 0x8; break;
  914. case DRM_FORMAT_RGB888:
  915. m = 0x9; break;
  916. case DRM_FORMAT_YUYV:
  917. m = 0xa; break;
  918. case DRM_FORMAT_UYVY:
  919. m = 0xb; break;
  920. case DRM_FORMAT_ARGB8888:
  921. m = 0xc; break;
  922. case DRM_FORMAT_RGBA8888:
  923. m = 0xd; break;
  924. case DRM_FORMAT_RGBX8888:
  925. m = 0xe; break;
  926. case DRM_FORMAT_XRGB1555:
  927. m = 0xf; break;
  928. default:
  929. BUG(); return;
  930. }
  931. } else {
  932. switch (fourcc) {
  933. case DRM_FORMAT_RGBX4444:
  934. m = 0x4; break;
  935. case DRM_FORMAT_ARGB4444:
  936. m = 0x5; break;
  937. case DRM_FORMAT_RGB565:
  938. m = 0x6; break;
  939. case DRM_FORMAT_ARGB1555:
  940. m = 0x7; break;
  941. case DRM_FORMAT_XRGB8888:
  942. m = 0x8; break;
  943. case DRM_FORMAT_RGB888:
  944. m = 0x9; break;
  945. case DRM_FORMAT_XRGB4444:
  946. m = 0xa; break;
  947. case DRM_FORMAT_RGBA4444:
  948. m = 0xb; break;
  949. case DRM_FORMAT_ARGB8888:
  950. m = 0xc; break;
  951. case DRM_FORMAT_RGBA8888:
  952. m = 0xd; break;
  953. case DRM_FORMAT_RGBX8888:
  954. m = 0xe; break;
  955. case DRM_FORMAT_XRGB1555:
  956. m = 0xf; break;
  957. default:
  958. BUG(); return;
  959. }
  960. }
  961. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
  962. }
  963. static bool format_is_yuv(u32 fourcc)
  964. {
  965. switch (fourcc) {
  966. case DRM_FORMAT_YUYV:
  967. case DRM_FORMAT_UYVY:
  968. case DRM_FORMAT_NV12:
  969. return true;
  970. default:
  971. return false;
  972. }
  973. }
  974. static void dispc_ovl_configure_burst_type(struct dispc_device *dispc,
  975. enum omap_plane_id plane,
  976. enum omap_dss_rotation_type rotation)
  977. {
  978. if (dispc_has_feature(dispc, FEAT_BURST_2D) == 0)
  979. return;
  980. if (rotation == OMAP_DSS_ROT_TILER)
  981. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
  982. else
  983. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
  984. }
  985. static void dispc_ovl_set_channel_out(struct dispc_device *dispc,
  986. enum omap_plane_id plane,
  987. enum omap_channel channel)
  988. {
  989. int shift;
  990. u32 val;
  991. int chan = 0, chan2 = 0;
  992. switch (plane) {
  993. case OMAP_DSS_GFX:
  994. shift = 8;
  995. break;
  996. case OMAP_DSS_VIDEO1:
  997. case OMAP_DSS_VIDEO2:
  998. case OMAP_DSS_VIDEO3:
  999. shift = 16;
  1000. break;
  1001. default:
  1002. BUG();
  1003. return;
  1004. }
  1005. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1006. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  1007. switch (channel) {
  1008. case OMAP_DSS_CHANNEL_LCD:
  1009. chan = 0;
  1010. chan2 = 0;
  1011. break;
  1012. case OMAP_DSS_CHANNEL_DIGIT:
  1013. chan = 1;
  1014. chan2 = 0;
  1015. break;
  1016. case OMAP_DSS_CHANNEL_LCD2:
  1017. chan = 0;
  1018. chan2 = 1;
  1019. break;
  1020. case OMAP_DSS_CHANNEL_LCD3:
  1021. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  1022. chan = 0;
  1023. chan2 = 2;
  1024. } else {
  1025. BUG();
  1026. return;
  1027. }
  1028. break;
  1029. case OMAP_DSS_CHANNEL_WB:
  1030. chan = 0;
  1031. chan2 = 3;
  1032. break;
  1033. default:
  1034. BUG();
  1035. return;
  1036. }
  1037. val = FLD_MOD(val, chan, shift, shift);
  1038. val = FLD_MOD(val, chan2, 31, 30);
  1039. } else {
  1040. val = FLD_MOD(val, channel, shift, shift);
  1041. }
  1042. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
  1043. }
  1044. static enum omap_channel dispc_ovl_get_channel_out(struct dispc_device *dispc,
  1045. enum omap_plane_id plane)
  1046. {
  1047. int shift;
  1048. u32 val;
  1049. switch (plane) {
  1050. case OMAP_DSS_GFX:
  1051. shift = 8;
  1052. break;
  1053. case OMAP_DSS_VIDEO1:
  1054. case OMAP_DSS_VIDEO2:
  1055. case OMAP_DSS_VIDEO3:
  1056. shift = 16;
  1057. break;
  1058. default:
  1059. BUG();
  1060. return 0;
  1061. }
  1062. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1063. if (FLD_GET(val, shift, shift) == 1)
  1064. return OMAP_DSS_CHANNEL_DIGIT;
  1065. if (!dispc_has_feature(dispc, FEAT_MGR_LCD2))
  1066. return OMAP_DSS_CHANNEL_LCD;
  1067. switch (FLD_GET(val, 31, 30)) {
  1068. case 0:
  1069. default:
  1070. return OMAP_DSS_CHANNEL_LCD;
  1071. case 1:
  1072. return OMAP_DSS_CHANNEL_LCD2;
  1073. case 2:
  1074. return OMAP_DSS_CHANNEL_LCD3;
  1075. case 3:
  1076. return OMAP_DSS_CHANNEL_WB;
  1077. }
  1078. }
  1079. static void dispc_ovl_set_burst_size(struct dispc_device *dispc,
  1080. enum omap_plane_id plane,
  1081. enum omap_burst_size burst_size)
  1082. {
  1083. static const unsigned int shifts[] = { 6, 14, 14, 14, 14, };
  1084. int shift;
  1085. shift = shifts[plane];
  1086. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), burst_size,
  1087. shift + 1, shift);
  1088. }
  1089. static void dispc_configure_burst_sizes(struct dispc_device *dispc)
  1090. {
  1091. int i;
  1092. const int burst_size = BURST_SIZE_X8;
  1093. /* Configure burst size always to maximum size */
  1094. for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
  1095. dispc_ovl_set_burst_size(dispc, i, burst_size);
  1096. if (dispc->feat->has_writeback)
  1097. dispc_ovl_set_burst_size(dispc, OMAP_DSS_WB, burst_size);
  1098. }
  1099. static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc,
  1100. enum omap_plane_id plane)
  1101. {
  1102. /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
  1103. return dispc->feat->burst_size_unit * 8;
  1104. }
  1105. static bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
  1106. enum omap_plane_id plane, u32 fourcc)
  1107. {
  1108. const u32 *modes;
  1109. unsigned int i;
  1110. modes = dispc->feat->supported_color_modes[plane];
  1111. for (i = 0; modes[i]; ++i) {
  1112. if (modes[i] == fourcc)
  1113. return true;
  1114. }
  1115. return false;
  1116. }
  1117. static const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
  1118. enum omap_plane_id plane)
  1119. {
  1120. return dispc->feat->supported_color_modes[plane];
  1121. }
  1122. static void dispc_mgr_enable_cpr(struct dispc_device *dispc,
  1123. enum omap_channel channel, bool enable)
  1124. {
  1125. if (channel == OMAP_DSS_CHANNEL_DIGIT)
  1126. return;
  1127. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_CPR, enable);
  1128. }
  1129. static void dispc_mgr_set_cpr_coef(struct dispc_device *dispc,
  1130. enum omap_channel channel,
  1131. const struct omap_dss_cpr_coefs *coefs)
  1132. {
  1133. u32 coef_r, coef_g, coef_b;
  1134. if (!dss_mgr_is_lcd(channel))
  1135. return;
  1136. coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
  1137. FLD_VAL(coefs->rb, 9, 0);
  1138. coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
  1139. FLD_VAL(coefs->gb, 9, 0);
  1140. coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
  1141. FLD_VAL(coefs->bb, 9, 0);
  1142. dispc_write_reg(dispc, DISPC_CPR_COEF_R(channel), coef_r);
  1143. dispc_write_reg(dispc, DISPC_CPR_COEF_G(channel), coef_g);
  1144. dispc_write_reg(dispc, DISPC_CPR_COEF_B(channel), coef_b);
  1145. }
  1146. static void dispc_ovl_set_vid_color_conv(struct dispc_device *dispc,
  1147. enum omap_plane_id plane, bool enable)
  1148. {
  1149. u32 val;
  1150. BUG_ON(plane == OMAP_DSS_GFX);
  1151. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1152. val = FLD_MOD(val, enable, 9, 9);
  1153. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
  1154. }
  1155. static void dispc_ovl_enable_replication(struct dispc_device *dispc,
  1156. enum omap_plane_id plane,
  1157. enum omap_overlay_caps caps,
  1158. bool enable)
  1159. {
  1160. static const unsigned int shifts[] = { 5, 10, 10, 10 };
  1161. int shift;
  1162. if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
  1163. return;
  1164. shift = shifts[plane];
  1165. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
  1166. }
  1167. static void dispc_mgr_set_size(struct dispc_device *dispc,
  1168. enum omap_channel channel, u16 width, u16 height)
  1169. {
  1170. u32 val;
  1171. val = FLD_VAL(height - 1, dispc->feat->mgr_height_start, 16) |
  1172. FLD_VAL(width - 1, dispc->feat->mgr_width_start, 0);
  1173. dispc_write_reg(dispc, DISPC_SIZE_MGR(channel), val);
  1174. }
  1175. static void dispc_init_fifos(struct dispc_device *dispc)
  1176. {
  1177. u32 size;
  1178. int fifo;
  1179. u8 start, end;
  1180. u32 unit;
  1181. int i;
  1182. unit = dispc->feat->buffer_size_unit;
  1183. dispc_get_reg_field(dispc, FEAT_REG_FIFOSIZE, &start, &end);
  1184. for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
  1185. size = REG_GET(dispc, DISPC_OVL_FIFO_SIZE_STATUS(fifo),
  1186. start, end);
  1187. size *= unit;
  1188. dispc->fifo_size[fifo] = size;
  1189. /*
  1190. * By default fifos are mapped directly to overlays, fifo 0 to
  1191. * ovl 0, fifo 1 to ovl 1, etc.
  1192. */
  1193. dispc->fifo_assignment[fifo] = fifo;
  1194. }
  1195. /*
  1196. * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
  1197. * causes problems with certain use cases, like using the tiler in 2D
  1198. * mode. The below hack swaps the fifos of GFX and WB planes, thus
  1199. * giving GFX plane a larger fifo. WB but should work fine with a
  1200. * smaller fifo.
  1201. */
  1202. if (dispc->feat->gfx_fifo_workaround) {
  1203. u32 v;
  1204. v = dispc_read_reg(dispc, DISPC_GLOBAL_BUFFER);
  1205. v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
  1206. v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
  1207. v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
  1208. v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
  1209. dispc_write_reg(dispc, DISPC_GLOBAL_BUFFER, v);
  1210. dispc->fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
  1211. dispc->fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
  1212. }
  1213. /*
  1214. * Setup default fifo thresholds.
  1215. */
  1216. for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
  1217. u32 low, high;
  1218. const bool use_fifomerge = false;
  1219. const bool manual_update = false;
  1220. dispc_ovl_compute_fifo_thresholds(dispc, i, &low, &high,
  1221. use_fifomerge, manual_update);
  1222. dispc_ovl_set_fifo_threshold(dispc, i, low, high);
  1223. }
  1224. if (dispc->feat->has_writeback) {
  1225. u32 low, high;
  1226. const bool use_fifomerge = false;
  1227. const bool manual_update = false;
  1228. dispc_ovl_compute_fifo_thresholds(dispc, OMAP_DSS_WB,
  1229. &low, &high, use_fifomerge,
  1230. manual_update);
  1231. dispc_ovl_set_fifo_threshold(dispc, OMAP_DSS_WB, low, high);
  1232. }
  1233. }
  1234. static u32 dispc_ovl_get_fifo_size(struct dispc_device *dispc,
  1235. enum omap_plane_id plane)
  1236. {
  1237. int fifo;
  1238. u32 size = 0;
  1239. for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
  1240. if (dispc->fifo_assignment[fifo] == plane)
  1241. size += dispc->fifo_size[fifo];
  1242. }
  1243. return size;
  1244. }
  1245. void dispc_ovl_set_fifo_threshold(struct dispc_device *dispc,
  1246. enum omap_plane_id plane,
  1247. u32 low, u32 high)
  1248. {
  1249. u8 hi_start, hi_end, lo_start, lo_end;
  1250. u32 unit;
  1251. unit = dispc->feat->buffer_size_unit;
  1252. WARN_ON(low % unit != 0);
  1253. WARN_ON(high % unit != 0);
  1254. low /= unit;
  1255. high /= unit;
  1256. dispc_get_reg_field(dispc, FEAT_REG_FIFOHIGHTHRESHOLD,
  1257. &hi_start, &hi_end);
  1258. dispc_get_reg_field(dispc, FEAT_REG_FIFOLOWTHRESHOLD,
  1259. &lo_start, &lo_end);
  1260. DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
  1261. plane,
  1262. REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1263. lo_start, lo_end) * unit,
  1264. REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1265. hi_start, hi_end) * unit,
  1266. low * unit, high * unit);
  1267. dispc_write_reg(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1268. FLD_VAL(high, hi_start, hi_end) |
  1269. FLD_VAL(low, lo_start, lo_end));
  1270. /*
  1271. * configure the preload to the pipeline's high threhold, if HT it's too
  1272. * large for the preload field, set the threshold to the maximum value
  1273. * that can be held by the preload register
  1274. */
  1275. if (dispc_has_feature(dispc, FEAT_PRELOAD) &&
  1276. dispc->feat->set_max_preload && plane != OMAP_DSS_WB)
  1277. dispc_write_reg(dispc, DISPC_OVL_PRELOAD(plane),
  1278. min(high, 0xfffu));
  1279. }
  1280. void dispc_enable_fifomerge(struct dispc_device *dispc, bool enable)
  1281. {
  1282. if (!dispc_has_feature(dispc, FEAT_FIFO_MERGE)) {
  1283. WARN_ON(enable);
  1284. return;
  1285. }
  1286. DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
  1287. REG_FLD_MOD(dispc, DISPC_CONFIG, enable ? 1 : 0, 14, 14);
  1288. }
  1289. void dispc_ovl_compute_fifo_thresholds(struct dispc_device *dispc,
  1290. enum omap_plane_id plane,
  1291. u32 *fifo_low, u32 *fifo_high,
  1292. bool use_fifomerge, bool manual_update)
  1293. {
  1294. /*
  1295. * All sizes are in bytes. Both the buffer and burst are made of
  1296. * buffer_units, and the fifo thresholds must be buffer_unit aligned.
  1297. */
  1298. unsigned int buf_unit = dispc->feat->buffer_size_unit;
  1299. unsigned int ovl_fifo_size, total_fifo_size, burst_size;
  1300. int i;
  1301. burst_size = dispc_ovl_get_burst_size(dispc, plane);
  1302. ovl_fifo_size = dispc_ovl_get_fifo_size(dispc, plane);
  1303. if (use_fifomerge) {
  1304. total_fifo_size = 0;
  1305. for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
  1306. total_fifo_size += dispc_ovl_get_fifo_size(dispc, i);
  1307. } else {
  1308. total_fifo_size = ovl_fifo_size;
  1309. }
  1310. /*
  1311. * We use the same low threshold for both fifomerge and non-fifomerge
  1312. * cases, but for fifomerge we calculate the high threshold using the
  1313. * combined fifo size
  1314. */
  1315. if (manual_update && dispc_has_feature(dispc, FEAT_OMAP3_DSI_FIFO_BUG)) {
  1316. *fifo_low = ovl_fifo_size - burst_size * 2;
  1317. *fifo_high = total_fifo_size - burst_size;
  1318. } else if (plane == OMAP_DSS_WB) {
  1319. /*
  1320. * Most optimal configuration for writeback is to push out data
  1321. * to the interconnect the moment writeback pushes enough pixels
  1322. * in the FIFO to form a burst
  1323. */
  1324. *fifo_low = 0;
  1325. *fifo_high = burst_size;
  1326. } else {
  1327. *fifo_low = ovl_fifo_size - burst_size;
  1328. *fifo_high = total_fifo_size - buf_unit;
  1329. }
  1330. }
  1331. static void dispc_ovl_set_mflag(struct dispc_device *dispc,
  1332. enum omap_plane_id plane, bool enable)
  1333. {
  1334. int bit;
  1335. if (plane == OMAP_DSS_GFX)
  1336. bit = 14;
  1337. else
  1338. bit = 23;
  1339. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
  1340. }
  1341. static void dispc_ovl_set_mflag_threshold(struct dispc_device *dispc,
  1342. enum omap_plane_id plane,
  1343. int low, int high)
  1344. {
  1345. dispc_write_reg(dispc, DISPC_OVL_MFLAG_THRESHOLD(plane),
  1346. FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
  1347. }
  1348. static void dispc_init_mflag(struct dispc_device *dispc)
  1349. {
  1350. int i;
  1351. /*
  1352. * HACK: NV12 color format and MFLAG seem to have problems working
  1353. * together: using two displays, and having an NV12 overlay on one of
  1354. * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
  1355. * Changing MFLAG thresholds and PRELOAD to certain values seem to
  1356. * remove the errors, but there doesn't seem to be a clear logic on
  1357. * which values work and which not.
  1358. *
  1359. * As a work-around, set force MFLAG to always on.
  1360. */
  1361. dispc_write_reg(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE,
  1362. (1 << 0) | /* MFLAG_CTRL = force always on */
  1363. (0 << 2)); /* MFLAG_START = disable */
  1364. for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
  1365. u32 size = dispc_ovl_get_fifo_size(dispc, i);
  1366. u32 unit = dispc->feat->buffer_size_unit;
  1367. u32 low, high;
  1368. dispc_ovl_set_mflag(dispc, i, true);
  1369. /*
  1370. * Simulation team suggests below thesholds:
  1371. * HT = fifosize * 5 / 8;
  1372. * LT = fifosize * 4 / 8;
  1373. */
  1374. low = size * 4 / 8 / unit;
  1375. high = size * 5 / 8 / unit;
  1376. dispc_ovl_set_mflag_threshold(dispc, i, low, high);
  1377. }
  1378. if (dispc->feat->has_writeback) {
  1379. u32 size = dispc_ovl_get_fifo_size(dispc, OMAP_DSS_WB);
  1380. u32 unit = dispc->feat->buffer_size_unit;
  1381. u32 low, high;
  1382. dispc_ovl_set_mflag(dispc, OMAP_DSS_WB, true);
  1383. /*
  1384. * Simulation team suggests below thesholds:
  1385. * HT = fifosize * 5 / 8;
  1386. * LT = fifosize * 4 / 8;
  1387. */
  1388. low = size * 4 / 8 / unit;
  1389. high = size * 5 / 8 / unit;
  1390. dispc_ovl_set_mflag_threshold(dispc, OMAP_DSS_WB, low, high);
  1391. }
  1392. }
  1393. static void dispc_ovl_set_fir(struct dispc_device *dispc,
  1394. enum omap_plane_id plane,
  1395. int hinc, int vinc,
  1396. enum omap_color_component color_comp)
  1397. {
  1398. u32 val;
  1399. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  1400. u8 hinc_start, hinc_end, vinc_start, vinc_end;
  1401. dispc_get_reg_field(dispc, FEAT_REG_FIRHINC,
  1402. &hinc_start, &hinc_end);
  1403. dispc_get_reg_field(dispc, FEAT_REG_FIRVINC,
  1404. &vinc_start, &vinc_end);
  1405. val = FLD_VAL(vinc, vinc_start, vinc_end) |
  1406. FLD_VAL(hinc, hinc_start, hinc_end);
  1407. dispc_write_reg(dispc, DISPC_OVL_FIR(plane), val);
  1408. } else {
  1409. val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
  1410. dispc_write_reg(dispc, DISPC_OVL_FIR2(plane), val);
  1411. }
  1412. }
  1413. static void dispc_ovl_set_vid_accu0(struct dispc_device *dispc,
  1414. enum omap_plane_id plane, int haccu,
  1415. int vaccu)
  1416. {
  1417. u32 val;
  1418. u8 hor_start, hor_end, vert_start, vert_end;
  1419. dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
  1420. &hor_start, &hor_end);
  1421. dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
  1422. &vert_start, &vert_end);
  1423. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1424. FLD_VAL(haccu, hor_start, hor_end);
  1425. dispc_write_reg(dispc, DISPC_OVL_ACCU0(plane), val);
  1426. }
  1427. static void dispc_ovl_set_vid_accu1(struct dispc_device *dispc,
  1428. enum omap_plane_id plane, int haccu,
  1429. int vaccu)
  1430. {
  1431. u32 val;
  1432. u8 hor_start, hor_end, vert_start, vert_end;
  1433. dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
  1434. &hor_start, &hor_end);
  1435. dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
  1436. &vert_start, &vert_end);
  1437. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1438. FLD_VAL(haccu, hor_start, hor_end);
  1439. dispc_write_reg(dispc, DISPC_OVL_ACCU1(plane), val);
  1440. }
  1441. static void dispc_ovl_set_vid_accu2_0(struct dispc_device *dispc,
  1442. enum omap_plane_id plane, int haccu,
  1443. int vaccu)
  1444. {
  1445. u32 val;
  1446. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1447. dispc_write_reg(dispc, DISPC_OVL_ACCU2_0(plane), val);
  1448. }
  1449. static void dispc_ovl_set_vid_accu2_1(struct dispc_device *dispc,
  1450. enum omap_plane_id plane, int haccu,
  1451. int vaccu)
  1452. {
  1453. u32 val;
  1454. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1455. dispc_write_reg(dispc, DISPC_OVL_ACCU2_1(plane), val);
  1456. }
  1457. static void dispc_ovl_set_scale_param(struct dispc_device *dispc,
  1458. enum omap_plane_id plane,
  1459. u16 orig_width, u16 orig_height,
  1460. u16 out_width, u16 out_height,
  1461. bool five_taps, u8 rotation,
  1462. enum omap_color_component color_comp)
  1463. {
  1464. int fir_hinc, fir_vinc;
  1465. fir_hinc = 1024 * orig_width / out_width;
  1466. fir_vinc = 1024 * orig_height / out_height;
  1467. dispc_ovl_set_scale_coef(dispc, plane, fir_hinc, fir_vinc, five_taps,
  1468. color_comp);
  1469. dispc_ovl_set_fir(dispc, plane, fir_hinc, fir_vinc, color_comp);
  1470. }
  1471. static void dispc_ovl_set_accu_uv(struct dispc_device *dispc,
  1472. enum omap_plane_id plane,
  1473. u16 orig_width, u16 orig_height,
  1474. u16 out_width, u16 out_height,
  1475. bool ilace, u32 fourcc, u8 rotation)
  1476. {
  1477. int h_accu2_0, h_accu2_1;
  1478. int v_accu2_0, v_accu2_1;
  1479. int chroma_hinc, chroma_vinc;
  1480. int idx;
  1481. struct accu {
  1482. s8 h0_m, h0_n;
  1483. s8 h1_m, h1_n;
  1484. s8 v0_m, v0_n;
  1485. s8 v1_m, v1_n;
  1486. };
  1487. const struct accu *accu_table;
  1488. const struct accu *accu_val;
  1489. static const struct accu accu_nv12[4] = {
  1490. { 0, 1, 0, 1 , -1, 2, 0, 1 },
  1491. { 1, 2, -3, 4 , 0, 1, 0, 1 },
  1492. { -1, 1, 0, 1 , -1, 2, 0, 1 },
  1493. { -1, 2, -1, 2 , -1, 1, 0, 1 },
  1494. };
  1495. static const struct accu accu_nv12_ilace[4] = {
  1496. { 0, 1, 0, 1 , -3, 4, -1, 4 },
  1497. { -1, 4, -3, 4 , 0, 1, 0, 1 },
  1498. { -1, 1, 0, 1 , -1, 4, -3, 4 },
  1499. { -3, 4, -3, 4 , -1, 1, 0, 1 },
  1500. };
  1501. static const struct accu accu_yuv[4] = {
  1502. { 0, 1, 0, 1, 0, 1, 0, 1 },
  1503. { 0, 1, 0, 1, 0, 1, 0, 1 },
  1504. { -1, 1, 0, 1, 0, 1, 0, 1 },
  1505. { 0, 1, 0, 1, -1, 1, 0, 1 },
  1506. };
  1507. /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
  1508. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1509. default:
  1510. case DRM_MODE_ROTATE_0:
  1511. idx = 0;
  1512. break;
  1513. case DRM_MODE_ROTATE_90:
  1514. idx = 3;
  1515. break;
  1516. case DRM_MODE_ROTATE_180:
  1517. idx = 2;
  1518. break;
  1519. case DRM_MODE_ROTATE_270:
  1520. idx = 1;
  1521. break;
  1522. }
  1523. switch (fourcc) {
  1524. case DRM_FORMAT_NV12:
  1525. if (ilace)
  1526. accu_table = accu_nv12_ilace;
  1527. else
  1528. accu_table = accu_nv12;
  1529. break;
  1530. case DRM_FORMAT_YUYV:
  1531. case DRM_FORMAT_UYVY:
  1532. accu_table = accu_yuv;
  1533. break;
  1534. default:
  1535. BUG();
  1536. return;
  1537. }
  1538. accu_val = &accu_table[idx];
  1539. chroma_hinc = 1024 * orig_width / out_width;
  1540. chroma_vinc = 1024 * orig_height / out_height;
  1541. h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
  1542. h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
  1543. v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
  1544. v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
  1545. dispc_ovl_set_vid_accu2_0(dispc, plane, h_accu2_0, v_accu2_0);
  1546. dispc_ovl_set_vid_accu2_1(dispc, plane, h_accu2_1, v_accu2_1);
  1547. }
  1548. static void dispc_ovl_set_scaling_common(struct dispc_device *dispc,
  1549. enum omap_plane_id plane,
  1550. u16 orig_width, u16 orig_height,
  1551. u16 out_width, u16 out_height,
  1552. bool ilace, bool five_taps,
  1553. bool fieldmode, u32 fourcc,
  1554. u8 rotation)
  1555. {
  1556. int accu0 = 0;
  1557. int accu1 = 0;
  1558. u32 l;
  1559. dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
  1560. out_width, out_height, five_taps,
  1561. rotation, DISPC_COLOR_COMPONENT_RGB_Y);
  1562. l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1563. /* RESIZEENABLE and VERTICALTAPS */
  1564. l &= ~((0x3 << 5) | (0x1 << 21));
  1565. l |= (orig_width != out_width) ? (1 << 5) : 0;
  1566. l |= (orig_height != out_height) ? (1 << 6) : 0;
  1567. l |= five_taps ? (1 << 21) : 0;
  1568. /* VRESIZECONF and HRESIZECONF */
  1569. if (dispc_has_feature(dispc, FEAT_RESIZECONF)) {
  1570. l &= ~(0x3 << 7);
  1571. l |= (orig_width <= out_width) ? 0 : (1 << 7);
  1572. l |= (orig_height <= out_height) ? 0 : (1 << 8);
  1573. }
  1574. /* LINEBUFFERSPLIT */
  1575. if (dispc_has_feature(dispc, FEAT_LINEBUFFERSPLIT)) {
  1576. l &= ~(0x1 << 22);
  1577. l |= five_taps ? (1 << 22) : 0;
  1578. }
  1579. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
  1580. /*
  1581. * field 0 = even field = bottom field
  1582. * field 1 = odd field = top field
  1583. */
  1584. if (ilace && !fieldmode) {
  1585. accu1 = 0;
  1586. accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
  1587. if (accu0 >= 1024/2) {
  1588. accu1 = 1024/2;
  1589. accu0 -= accu1;
  1590. }
  1591. }
  1592. dispc_ovl_set_vid_accu0(dispc, plane, 0, accu0);
  1593. dispc_ovl_set_vid_accu1(dispc, plane, 0, accu1);
  1594. }
  1595. static void dispc_ovl_set_scaling_uv(struct dispc_device *dispc,
  1596. enum omap_plane_id plane,
  1597. u16 orig_width, u16 orig_height,
  1598. u16 out_width, u16 out_height,
  1599. bool ilace, bool five_taps,
  1600. bool fieldmode, u32 fourcc,
  1601. u8 rotation)
  1602. {
  1603. int scale_x = out_width != orig_width;
  1604. int scale_y = out_height != orig_height;
  1605. bool chroma_upscale = plane != OMAP_DSS_WB;
  1606. if (!dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE))
  1607. return;
  1608. if (!format_is_yuv(fourcc)) {
  1609. /* reset chroma resampling for RGB formats */
  1610. if (plane != OMAP_DSS_WB)
  1611. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
  1612. 0, 8, 8);
  1613. return;
  1614. }
  1615. dispc_ovl_set_accu_uv(dispc, plane, orig_width, orig_height, out_width,
  1616. out_height, ilace, fourcc, rotation);
  1617. switch (fourcc) {
  1618. case DRM_FORMAT_NV12:
  1619. if (chroma_upscale) {
  1620. /* UV is subsampled by 2 horizontally and vertically */
  1621. orig_height >>= 1;
  1622. orig_width >>= 1;
  1623. } else {
  1624. /* UV is downsampled by 2 horizontally and vertically */
  1625. orig_height <<= 1;
  1626. orig_width <<= 1;
  1627. }
  1628. break;
  1629. case DRM_FORMAT_YUYV:
  1630. case DRM_FORMAT_UYVY:
  1631. /* For YUV422 with 90/270 rotation, we don't upsample chroma */
  1632. if (!drm_rotation_90_or_270(rotation)) {
  1633. if (chroma_upscale)
  1634. /* UV is subsampled by 2 horizontally */
  1635. orig_width >>= 1;
  1636. else
  1637. /* UV is downsampled by 2 horizontally */
  1638. orig_width <<= 1;
  1639. }
  1640. /* must use FIR for YUV422 if rotated */
  1641. if ((rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0)
  1642. scale_x = scale_y = true;
  1643. break;
  1644. default:
  1645. BUG();
  1646. return;
  1647. }
  1648. if (out_width != orig_width)
  1649. scale_x = true;
  1650. if (out_height != orig_height)
  1651. scale_y = true;
  1652. dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
  1653. out_width, out_height, five_taps,
  1654. rotation, DISPC_COLOR_COMPONENT_UV);
  1655. if (plane != OMAP_DSS_WB)
  1656. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
  1657. (scale_x || scale_y) ? 1 : 0, 8, 8);
  1658. /* set H scaling */
  1659. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
  1660. /* set V scaling */
  1661. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
  1662. }
  1663. static void dispc_ovl_set_scaling(struct dispc_device *dispc,
  1664. enum omap_plane_id plane,
  1665. u16 orig_width, u16 orig_height,
  1666. u16 out_width, u16 out_height,
  1667. bool ilace, bool five_taps,
  1668. bool fieldmode, u32 fourcc,
  1669. u8 rotation)
  1670. {
  1671. BUG_ON(plane == OMAP_DSS_GFX);
  1672. dispc_ovl_set_scaling_common(dispc, plane, orig_width, orig_height,
  1673. out_width, out_height, ilace, five_taps,
  1674. fieldmode, fourcc, rotation);
  1675. dispc_ovl_set_scaling_uv(dispc, plane, orig_width, orig_height,
  1676. out_width, out_height, ilace, five_taps,
  1677. fieldmode, fourcc, rotation);
  1678. }
  1679. static void dispc_ovl_set_rotation_attrs(struct dispc_device *dispc,
  1680. enum omap_plane_id plane, u8 rotation,
  1681. enum omap_dss_rotation_type rotation_type,
  1682. u32 fourcc)
  1683. {
  1684. bool row_repeat = false;
  1685. int vidrot = 0;
  1686. /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
  1687. if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY) {
  1688. if (rotation & DRM_MODE_REFLECT_X) {
  1689. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1690. case DRM_MODE_ROTATE_0:
  1691. vidrot = 2;
  1692. break;
  1693. case DRM_MODE_ROTATE_90:
  1694. vidrot = 1;
  1695. break;
  1696. case DRM_MODE_ROTATE_180:
  1697. vidrot = 0;
  1698. break;
  1699. case DRM_MODE_ROTATE_270:
  1700. vidrot = 3;
  1701. break;
  1702. }
  1703. } else {
  1704. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1705. case DRM_MODE_ROTATE_0:
  1706. vidrot = 0;
  1707. break;
  1708. case DRM_MODE_ROTATE_90:
  1709. vidrot = 3;
  1710. break;
  1711. case DRM_MODE_ROTATE_180:
  1712. vidrot = 2;
  1713. break;
  1714. case DRM_MODE_ROTATE_270:
  1715. vidrot = 1;
  1716. break;
  1717. }
  1718. }
  1719. if (drm_rotation_90_or_270(rotation))
  1720. row_repeat = true;
  1721. else
  1722. row_repeat = false;
  1723. }
  1724. /*
  1725. * OMAP4/5 Errata i631:
  1726. * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
  1727. * rows beyond the framebuffer, which may cause OCP error.
  1728. */
  1729. if (fourcc == DRM_FORMAT_NV12 && rotation_type != OMAP_DSS_ROT_TILER)
  1730. vidrot = 1;
  1731. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
  1732. if (dispc_has_feature(dispc, FEAT_ROWREPEATENABLE))
  1733. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
  1734. row_repeat ? 1 : 0, 18, 18);
  1735. if (dispc_ovl_color_mode_supported(dispc, plane, DRM_FORMAT_NV12)) {
  1736. bool doublestride =
  1737. fourcc == DRM_FORMAT_NV12 &&
  1738. rotation_type == OMAP_DSS_ROT_TILER &&
  1739. !drm_rotation_90_or_270(rotation);
  1740. /* DOUBLESTRIDE */
  1741. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
  1742. doublestride, 22, 22);
  1743. }
  1744. }
  1745. static int color_mode_to_bpp(u32 fourcc)
  1746. {
  1747. switch (fourcc) {
  1748. case DRM_FORMAT_NV12:
  1749. return 8;
  1750. case DRM_FORMAT_RGBX4444:
  1751. case DRM_FORMAT_RGB565:
  1752. case DRM_FORMAT_ARGB4444:
  1753. case DRM_FORMAT_YUYV:
  1754. case DRM_FORMAT_UYVY:
  1755. case DRM_FORMAT_RGBA4444:
  1756. case DRM_FORMAT_XRGB4444:
  1757. case DRM_FORMAT_ARGB1555:
  1758. case DRM_FORMAT_XRGB1555:
  1759. return 16;
  1760. case DRM_FORMAT_RGB888:
  1761. return 24;
  1762. case DRM_FORMAT_XRGB8888:
  1763. case DRM_FORMAT_ARGB8888:
  1764. case DRM_FORMAT_RGBA8888:
  1765. case DRM_FORMAT_RGBX8888:
  1766. return 32;
  1767. default:
  1768. BUG();
  1769. return 0;
  1770. }
  1771. }
  1772. static s32 pixinc(int pixels, u8 ps)
  1773. {
  1774. if (pixels == 1)
  1775. return 1;
  1776. else if (pixels > 1)
  1777. return 1 + (pixels - 1) * ps;
  1778. else if (pixels < 0)
  1779. return 1 - (-pixels + 1) * ps;
  1780. else
  1781. BUG();
  1782. return 0;
  1783. }
  1784. static void calc_offset(u16 screen_width, u16 width,
  1785. u32 fourcc, bool fieldmode, unsigned int field_offset,
  1786. unsigned int *offset0, unsigned int *offset1,
  1787. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim,
  1788. enum omap_dss_rotation_type rotation_type, u8 rotation)
  1789. {
  1790. u8 ps;
  1791. ps = color_mode_to_bpp(fourcc) / 8;
  1792. DSSDBG("scrw %d, width %d\n", screen_width, width);
  1793. if (rotation_type == OMAP_DSS_ROT_TILER &&
  1794. (fourcc == DRM_FORMAT_UYVY || fourcc == DRM_FORMAT_YUYV) &&
  1795. drm_rotation_90_or_270(rotation)) {
  1796. /*
  1797. * HACK: ROW_INC needs to be calculated with TILER units.
  1798. * We get such 'screen_width' that multiplying it with the
  1799. * YUV422 pixel size gives the correct TILER container width.
  1800. * However, 'width' is in pixels and multiplying it with YUV422
  1801. * pixel size gives incorrect result. We thus multiply it here
  1802. * with 2 to match the 32 bit TILER unit size.
  1803. */
  1804. width *= 2;
  1805. }
  1806. /*
  1807. * field 0 = even field = bottom field
  1808. * field 1 = odd field = top field
  1809. */
  1810. *offset0 = field_offset * screen_width * ps;
  1811. *offset1 = 0;
  1812. *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
  1813. (fieldmode ? screen_width : 0), ps);
  1814. if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY)
  1815. *pix_inc = pixinc(x_predecim, 2 * ps);
  1816. else
  1817. *pix_inc = pixinc(x_predecim, ps);
  1818. }
  1819. /*
  1820. * This function is used to avoid synclosts in OMAP3, because of some
  1821. * undocumented horizontal position and timing related limitations.
  1822. */
  1823. static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
  1824. const struct videomode *vm, u16 pos_x,
  1825. u16 width, u16 height, u16 out_width, u16 out_height,
  1826. bool five_taps)
  1827. {
  1828. const int ds = DIV_ROUND_UP(height, out_height);
  1829. unsigned long nonactive;
  1830. static const u8 limits[3] = { 8, 10, 20 };
  1831. u64 val, blank;
  1832. int i;
  1833. nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
  1834. vm->hback_porch - out_width;
  1835. i = 0;
  1836. if (out_height < height)
  1837. i++;
  1838. if (out_width < width)
  1839. i++;
  1840. blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
  1841. lclk, pclk);
  1842. DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
  1843. if (blank <= limits[i])
  1844. return -EINVAL;
  1845. /* FIXME add checks for 3-tap filter once the limitations are known */
  1846. if (!five_taps)
  1847. return 0;
  1848. /*
  1849. * Pixel data should be prepared before visible display point starts.
  1850. * So, atleast DS-2 lines must have already been fetched by DISPC
  1851. * during nonactive - pos_x period.
  1852. */
  1853. val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
  1854. DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
  1855. val, max(0, ds - 2) * width);
  1856. if (val < max(0, ds - 2) * width)
  1857. return -EINVAL;
  1858. /*
  1859. * All lines need to be refilled during the nonactive period of which
  1860. * only one line can be loaded during the active period. So, atleast
  1861. * DS - 1 lines should be loaded during nonactive period.
  1862. */
  1863. val = div_u64((u64)nonactive * lclk, pclk);
  1864. DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
  1865. val, max(0, ds - 1) * width);
  1866. if (val < max(0, ds - 1) * width)
  1867. return -EINVAL;
  1868. return 0;
  1869. }
  1870. static unsigned long calc_core_clk_five_taps(unsigned long pclk,
  1871. const struct videomode *vm, u16 width,
  1872. u16 height, u16 out_width, u16 out_height,
  1873. u32 fourcc)
  1874. {
  1875. u32 core_clk = 0;
  1876. u64 tmp;
  1877. if (height <= out_height && width <= out_width)
  1878. return (unsigned long) pclk;
  1879. if (height > out_height) {
  1880. unsigned int ppl = vm->hactive;
  1881. tmp = (u64)pclk * height * out_width;
  1882. do_div(tmp, 2 * out_height * ppl);
  1883. core_clk = tmp;
  1884. if (height > 2 * out_height) {
  1885. if (ppl == out_width)
  1886. return 0;
  1887. tmp = (u64)pclk * (height - 2 * out_height) * out_width;
  1888. do_div(tmp, 2 * out_height * (ppl - out_width));
  1889. core_clk = max_t(u32, core_clk, tmp);
  1890. }
  1891. }
  1892. if (width > out_width) {
  1893. tmp = (u64)pclk * width;
  1894. do_div(tmp, out_width);
  1895. core_clk = max_t(u32, core_clk, tmp);
  1896. if (fourcc == DRM_FORMAT_XRGB8888)
  1897. core_clk <<= 1;
  1898. }
  1899. return core_clk;
  1900. }
  1901. static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
  1902. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1903. {
  1904. if (height > out_height && width > out_width)
  1905. return pclk * 4;
  1906. else
  1907. return pclk * 2;
  1908. }
  1909. static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
  1910. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1911. {
  1912. unsigned int hf, vf;
  1913. /*
  1914. * FIXME how to determine the 'A' factor
  1915. * for the no downscaling case ?
  1916. */
  1917. if (width > 3 * out_width)
  1918. hf = 4;
  1919. else if (width > 2 * out_width)
  1920. hf = 3;
  1921. else if (width > out_width)
  1922. hf = 2;
  1923. else
  1924. hf = 1;
  1925. if (height > out_height)
  1926. vf = 2;
  1927. else
  1928. vf = 1;
  1929. return pclk * vf * hf;
  1930. }
  1931. static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
  1932. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1933. {
  1934. /*
  1935. * If the overlay/writeback is in mem to mem mode, there are no
  1936. * downscaling limitations with respect to pixel clock, return 1 as
  1937. * required core clock to represent that we have sufficient enough
  1938. * core clock to do maximum downscaling
  1939. */
  1940. if (mem_to_mem)
  1941. return 1;
  1942. if (width > out_width)
  1943. return DIV_ROUND_UP(pclk, out_width) * width;
  1944. else
  1945. return pclk;
  1946. }
  1947. static int dispc_ovl_calc_scaling_24xx(struct dispc_device *dispc,
  1948. unsigned long pclk, unsigned long lclk,
  1949. const struct videomode *vm,
  1950. u16 width, u16 height,
  1951. u16 out_width, u16 out_height,
  1952. u32 fourcc, bool *five_taps,
  1953. int *x_predecim, int *y_predecim,
  1954. int *decim_x, int *decim_y,
  1955. u16 pos_x, unsigned long *core_clk,
  1956. bool mem_to_mem)
  1957. {
  1958. int error;
  1959. u16 in_width, in_height;
  1960. int min_factor = min(*decim_x, *decim_y);
  1961. const int maxsinglelinewidth = dispc->feat->max_line_width;
  1962. *five_taps = false;
  1963. do {
  1964. in_height = height / *decim_y;
  1965. in_width = width / *decim_x;
  1966. *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
  1967. in_height, out_width, out_height, mem_to_mem);
  1968. error = (in_width > maxsinglelinewidth || !*core_clk ||
  1969. *core_clk > dispc_core_clk_rate(dispc));
  1970. if (error) {
  1971. if (*decim_x == *decim_y) {
  1972. *decim_x = min_factor;
  1973. ++*decim_y;
  1974. } else {
  1975. swap(*decim_x, *decim_y);
  1976. if (*decim_x < *decim_y)
  1977. ++*decim_x;
  1978. }
  1979. }
  1980. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  1981. if (error) {
  1982. DSSERR("failed to find scaling settings\n");
  1983. return -EINVAL;
  1984. }
  1985. if (in_width > maxsinglelinewidth) {
  1986. DSSERR("Cannot scale max input width exceeded\n");
  1987. return -EINVAL;
  1988. }
  1989. return 0;
  1990. }
  1991. static int dispc_ovl_calc_scaling_34xx(struct dispc_device *dispc,
  1992. unsigned long pclk, unsigned long lclk,
  1993. const struct videomode *vm,
  1994. u16 width, u16 height,
  1995. u16 out_width, u16 out_height,
  1996. u32 fourcc, bool *five_taps,
  1997. int *x_predecim, int *y_predecim,
  1998. int *decim_x, int *decim_y,
  1999. u16 pos_x, unsigned long *core_clk,
  2000. bool mem_to_mem)
  2001. {
  2002. int error;
  2003. u16 in_width, in_height;
  2004. const int maxsinglelinewidth = dispc->feat->max_line_width;
  2005. do {
  2006. in_height = height / *decim_y;
  2007. in_width = width / *decim_x;
  2008. *five_taps = in_height > out_height;
  2009. if (in_width > maxsinglelinewidth)
  2010. if (in_height > out_height &&
  2011. in_height < out_height * 2)
  2012. *five_taps = false;
  2013. again:
  2014. if (*five_taps)
  2015. *core_clk = calc_core_clk_five_taps(pclk, vm,
  2016. in_width, in_height, out_width,
  2017. out_height, fourcc);
  2018. else
  2019. *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
  2020. in_height, out_width, out_height,
  2021. mem_to_mem);
  2022. error = check_horiz_timing_omap3(pclk, lclk, vm,
  2023. pos_x, in_width, in_height, out_width,
  2024. out_height, *five_taps);
  2025. if (error && *five_taps) {
  2026. *five_taps = false;
  2027. goto again;
  2028. }
  2029. error = (error || in_width > maxsinglelinewidth * 2 ||
  2030. (in_width > maxsinglelinewidth && *five_taps) ||
  2031. !*core_clk || *core_clk > dispc_core_clk_rate(dispc));
  2032. if (!error) {
  2033. /* verify that we're inside the limits of scaler */
  2034. if (in_width / 4 > out_width)
  2035. error = 1;
  2036. if (*five_taps) {
  2037. if (in_height / 4 > out_height)
  2038. error = 1;
  2039. } else {
  2040. if (in_height / 2 > out_height)
  2041. error = 1;
  2042. }
  2043. }
  2044. if (error)
  2045. ++*decim_y;
  2046. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  2047. if (error) {
  2048. DSSERR("failed to find scaling settings\n");
  2049. return -EINVAL;
  2050. }
  2051. if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
  2052. in_height, out_width, out_height, *five_taps)) {
  2053. DSSERR("horizontal timing too tight\n");
  2054. return -EINVAL;
  2055. }
  2056. if (in_width > (maxsinglelinewidth * 2)) {
  2057. DSSERR("Cannot setup scaling\n");
  2058. DSSERR("width exceeds maximum width possible\n");
  2059. return -EINVAL;
  2060. }
  2061. if (in_width > maxsinglelinewidth && *five_taps) {
  2062. DSSERR("cannot setup scaling with five taps\n");
  2063. return -EINVAL;
  2064. }
  2065. return 0;
  2066. }
  2067. static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc,
  2068. unsigned long pclk, unsigned long lclk,
  2069. const struct videomode *vm,
  2070. u16 width, u16 height,
  2071. u16 out_width, u16 out_height,
  2072. u32 fourcc, bool *five_taps,
  2073. int *x_predecim, int *y_predecim,
  2074. int *decim_x, int *decim_y,
  2075. u16 pos_x, unsigned long *core_clk,
  2076. bool mem_to_mem)
  2077. {
  2078. u16 in_width, in_width_max;
  2079. int decim_x_min = *decim_x;
  2080. u16 in_height = height / *decim_y;
  2081. const int maxsinglelinewidth = dispc->feat->max_line_width;
  2082. const int maxdownscale = dispc->feat->max_downscale;
  2083. if (mem_to_mem) {
  2084. in_width_max = out_width * maxdownscale;
  2085. } else {
  2086. in_width_max = dispc_core_clk_rate(dispc)
  2087. / DIV_ROUND_UP(pclk, out_width);
  2088. }
  2089. *decim_x = DIV_ROUND_UP(width, in_width_max);
  2090. *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
  2091. if (*decim_x > *x_predecim)
  2092. return -EINVAL;
  2093. do {
  2094. in_width = width / *decim_x;
  2095. } while (*decim_x <= *x_predecim &&
  2096. in_width > maxsinglelinewidth && ++*decim_x);
  2097. if (in_width > maxsinglelinewidth) {
  2098. DSSERR("Cannot scale width exceeds max line width\n");
  2099. return -EINVAL;
  2100. }
  2101. if (*decim_x > 4 && fourcc != DRM_FORMAT_NV12) {
  2102. /*
  2103. * Let's disable all scaling that requires horizontal
  2104. * decimation with higher factor than 4, until we have
  2105. * better estimates of what we can and can not
  2106. * do. However, NV12 color format appears to work Ok
  2107. * with all decimation factors.
  2108. *
  2109. * When decimating horizontally by more that 4 the dss
  2110. * is not able to fetch the data in burst mode. When
  2111. * this happens it is hard to tell if there enough
  2112. * bandwidth. Despite what theory says this appears to
  2113. * be true also for 16-bit color formats.
  2114. */
  2115. DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)\n", *decim_x);
  2116. return -EINVAL;
  2117. }
  2118. *core_clk = dispc->feat->calc_core_clk(pclk, in_width, in_height,
  2119. out_width, out_height, mem_to_mem);
  2120. return 0;
  2121. }
  2122. #define DIV_FRAC(dividend, divisor) \
  2123. ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
  2124. static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
  2125. enum omap_plane_id plane,
  2126. unsigned long pclk, unsigned long lclk,
  2127. enum omap_overlay_caps caps,
  2128. const struct videomode *vm,
  2129. u16 width, u16 height,
  2130. u16 out_width, u16 out_height,
  2131. u32 fourcc, bool *five_taps,
  2132. int *x_predecim, int *y_predecim, u16 pos_x,
  2133. enum omap_dss_rotation_type rotation_type,
  2134. bool mem_to_mem)
  2135. {
  2136. int maxhdownscale = dispc->feat->max_downscale;
  2137. int maxvdownscale = dispc->feat->max_downscale;
  2138. const int max_decim_limit = 16;
  2139. unsigned long core_clk = 0;
  2140. int decim_x, decim_y, ret;
  2141. if (width == out_width && height == out_height)
  2142. return 0;
  2143. if (plane == OMAP_DSS_WB) {
  2144. switch (fourcc) {
  2145. case DRM_FORMAT_NV12:
  2146. maxhdownscale = maxvdownscale = 2;
  2147. break;
  2148. case DRM_FORMAT_YUYV:
  2149. case DRM_FORMAT_UYVY:
  2150. maxhdownscale = 2;
  2151. maxvdownscale = 4;
  2152. break;
  2153. default:
  2154. break;
  2155. }
  2156. }
  2157. if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
  2158. DSSERR("cannot calculate scaling settings: pclk is zero\n");
  2159. return -EINVAL;
  2160. }
  2161. if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
  2162. return -EINVAL;
  2163. if (mem_to_mem) {
  2164. *x_predecim = *y_predecim = 1;
  2165. } else {
  2166. *x_predecim = max_decim_limit;
  2167. *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
  2168. dispc_has_feature(dispc, FEAT_BURST_2D)) ?
  2169. 2 : max_decim_limit;
  2170. }
  2171. decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxhdownscale);
  2172. decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxvdownscale);
  2173. if (decim_x > *x_predecim || out_width > width * 8)
  2174. return -EINVAL;
  2175. if (decim_y > *y_predecim || out_height > height * 8)
  2176. return -EINVAL;
  2177. ret = dispc->feat->calc_scaling(dispc, pclk, lclk, vm, width, height,
  2178. out_width, out_height, fourcc,
  2179. five_taps, x_predecim, y_predecim,
  2180. &decim_x, &decim_y, pos_x, &core_clk,
  2181. mem_to_mem);
  2182. if (ret)
  2183. return ret;
  2184. DSSDBG("%dx%d -> %dx%d (%d.%02d x %d.%02d), decim %dx%d %dx%d (%d.%02d x %d.%02d), taps %d, req clk %lu, cur clk %lu\n",
  2185. width, height,
  2186. out_width, out_height,
  2187. out_width / width, DIV_FRAC(out_width, width),
  2188. out_height / height, DIV_FRAC(out_height, height),
  2189. decim_x, decim_y,
  2190. width / decim_x, height / decim_y,
  2191. out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
  2192. out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
  2193. *five_taps ? 5 : 3,
  2194. core_clk, dispc_core_clk_rate(dispc));
  2195. if (!core_clk || core_clk > dispc_core_clk_rate(dispc)) {
  2196. DSSERR("failed to set up scaling, "
  2197. "required core clk rate = %lu Hz, "
  2198. "current core clk rate = %lu Hz\n",
  2199. core_clk, dispc_core_clk_rate(dispc));
  2200. return -EINVAL;
  2201. }
  2202. *x_predecim = decim_x;
  2203. *y_predecim = decim_y;
  2204. return 0;
  2205. }
  2206. static int dispc_ovl_setup_common(struct dispc_device *dispc,
  2207. enum omap_plane_id plane,
  2208. enum omap_overlay_caps caps,
  2209. u32 paddr, u32 p_uv_addr,
  2210. u16 screen_width, int pos_x, int pos_y,
  2211. u16 width, u16 height,
  2212. u16 out_width, u16 out_height,
  2213. u32 fourcc, u8 rotation, u8 zorder,
  2214. u8 pre_mult_alpha, u8 global_alpha,
  2215. enum omap_dss_rotation_type rotation_type,
  2216. bool replication, const struct videomode *vm,
  2217. bool mem_to_mem)
  2218. {
  2219. bool five_taps = true;
  2220. bool fieldmode = false;
  2221. int r, cconv = 0;
  2222. unsigned int offset0, offset1;
  2223. s32 row_inc;
  2224. s32 pix_inc;
  2225. u16 frame_width, frame_height;
  2226. unsigned int field_offset = 0;
  2227. u16 in_height = height;
  2228. u16 in_width = width;
  2229. int x_predecim = 1, y_predecim = 1;
  2230. bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
  2231. unsigned long pclk = dispc_plane_pclk_rate(dispc, plane);
  2232. unsigned long lclk = dispc_plane_lclk_rate(dispc, plane);
  2233. /* when setting up WB, dispc_plane_pclk_rate() returns 0 */
  2234. if (plane == OMAP_DSS_WB)
  2235. pclk = vm->pixelclock;
  2236. if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
  2237. return -EINVAL;
  2238. if (format_is_yuv(fourcc) && (in_width & 1)) {
  2239. DSSERR("input width %d is not even for YUV format\n", in_width);
  2240. return -EINVAL;
  2241. }
  2242. out_width = out_width == 0 ? width : out_width;
  2243. out_height = out_height == 0 ? height : out_height;
  2244. if (plane != OMAP_DSS_WB) {
  2245. if (ilace && height == out_height)
  2246. fieldmode = true;
  2247. if (ilace) {
  2248. if (fieldmode)
  2249. in_height /= 2;
  2250. pos_y /= 2;
  2251. out_height /= 2;
  2252. DSSDBG("adjusting for ilace: height %d, pos_y %d, out_height %d\n",
  2253. in_height, pos_y, out_height);
  2254. }
  2255. }
  2256. if (!dispc_ovl_color_mode_supported(dispc, plane, fourcc))
  2257. return -EINVAL;
  2258. r = dispc_ovl_calc_scaling(dispc, plane, pclk, lclk, caps, vm, in_width,
  2259. in_height, out_width, out_height, fourcc,
  2260. &five_taps, &x_predecim, &y_predecim, pos_x,
  2261. rotation_type, mem_to_mem);
  2262. if (r)
  2263. return r;
  2264. in_width = in_width / x_predecim;
  2265. in_height = in_height / y_predecim;
  2266. if (x_predecim > 1 || y_predecim > 1)
  2267. DSSDBG("predecimation %d x %x, new input size %d x %d\n",
  2268. x_predecim, y_predecim, in_width, in_height);
  2269. if (format_is_yuv(fourcc) && (in_width & 1)) {
  2270. DSSDBG("predecimated input width is not even for YUV format\n");
  2271. DSSDBG("adjusting input width %d -> %d\n",
  2272. in_width, in_width & ~1);
  2273. in_width &= ~1;
  2274. }
  2275. if (format_is_yuv(fourcc))
  2276. cconv = 1;
  2277. if (ilace && !fieldmode) {
  2278. /*
  2279. * when downscaling the bottom field may have to start several
  2280. * source lines below the top field. Unfortunately ACCUI
  2281. * registers will only hold the fractional part of the offset
  2282. * so the integer part must be added to the base address of the
  2283. * bottom field.
  2284. */
  2285. if (!in_height || in_height == out_height)
  2286. field_offset = 0;
  2287. else
  2288. field_offset = in_height / out_height / 2;
  2289. }
  2290. /* Fields are independent but interleaved in memory. */
  2291. if (fieldmode)
  2292. field_offset = 1;
  2293. offset0 = 0;
  2294. offset1 = 0;
  2295. row_inc = 0;
  2296. pix_inc = 0;
  2297. if (plane == OMAP_DSS_WB) {
  2298. frame_width = out_width;
  2299. frame_height = out_height;
  2300. } else {
  2301. frame_width = in_width;
  2302. frame_height = height;
  2303. }
  2304. calc_offset(screen_width, frame_width,
  2305. fourcc, fieldmode, field_offset,
  2306. &offset0, &offset1, &row_inc, &pix_inc,
  2307. x_predecim, y_predecim,
  2308. rotation_type, rotation);
  2309. DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
  2310. offset0, offset1, row_inc, pix_inc);
  2311. dispc_ovl_set_color_mode(dispc, plane, fourcc);
  2312. dispc_ovl_configure_burst_type(dispc, plane, rotation_type);
  2313. if (dispc->feat->reverse_ilace_field_order)
  2314. swap(offset0, offset1);
  2315. dispc_ovl_set_ba0(dispc, plane, paddr + offset0);
  2316. dispc_ovl_set_ba1(dispc, plane, paddr + offset1);
  2317. if (fourcc == DRM_FORMAT_NV12) {
  2318. dispc_ovl_set_ba0_uv(dispc, plane, p_uv_addr + offset0);
  2319. dispc_ovl_set_ba1_uv(dispc, plane, p_uv_addr + offset1);
  2320. }
  2321. if (dispc->feat->last_pixel_inc_missing)
  2322. row_inc += pix_inc - 1;
  2323. dispc_ovl_set_row_inc(dispc, plane, row_inc);
  2324. dispc_ovl_set_pix_inc(dispc, plane, pix_inc);
  2325. DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
  2326. in_height, out_width, out_height);
  2327. dispc_ovl_set_pos(dispc, plane, caps, pos_x, pos_y);
  2328. dispc_ovl_set_input_size(dispc, plane, in_width, in_height);
  2329. if (caps & OMAP_DSS_OVL_CAP_SCALE) {
  2330. dispc_ovl_set_scaling(dispc, plane, in_width, in_height,
  2331. out_width, out_height, ilace, five_taps,
  2332. fieldmode, fourcc, rotation);
  2333. dispc_ovl_set_output_size(dispc, plane, out_width, out_height);
  2334. dispc_ovl_set_vid_color_conv(dispc, plane, cconv);
  2335. }
  2336. dispc_ovl_set_rotation_attrs(dispc, plane, rotation, rotation_type,
  2337. fourcc);
  2338. dispc_ovl_set_zorder(dispc, plane, caps, zorder);
  2339. dispc_ovl_set_pre_mult_alpha(dispc, plane, caps, pre_mult_alpha);
  2340. dispc_ovl_setup_global_alpha(dispc, plane, caps, global_alpha);
  2341. dispc_ovl_enable_replication(dispc, plane, caps, replication);
  2342. return 0;
  2343. }
  2344. static int dispc_ovl_setup(struct dispc_device *dispc,
  2345. enum omap_plane_id plane,
  2346. const struct omap_overlay_info *oi,
  2347. const struct videomode *vm, bool mem_to_mem,
  2348. enum omap_channel channel)
  2349. {
  2350. int r;
  2351. enum omap_overlay_caps caps = dispc->feat->overlay_caps[plane];
  2352. const bool replication = true;
  2353. DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
  2354. " %dx%d, cmode %x, rot %d, chan %d repl %d\n",
  2355. plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
  2356. oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
  2357. oi->fourcc, oi->rotation, channel, replication);
  2358. dispc_ovl_set_channel_out(dispc, plane, channel);
  2359. r = dispc_ovl_setup_common(dispc, plane, caps, oi->paddr, oi->p_uv_addr,
  2360. oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
  2361. oi->out_width, oi->out_height, oi->fourcc, oi->rotation,
  2362. oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
  2363. oi->rotation_type, replication, vm, mem_to_mem);
  2364. return r;
  2365. }
  2366. static int dispc_wb_setup(struct dispc_device *dispc,
  2367. const struct omap_dss_writeback_info *wi,
  2368. bool mem_to_mem, const struct videomode *vm,
  2369. enum dss_writeback_channel channel_in)
  2370. {
  2371. int r;
  2372. u32 l;
  2373. enum omap_plane_id plane = OMAP_DSS_WB;
  2374. const int pos_x = 0, pos_y = 0;
  2375. const u8 zorder = 0, global_alpha = 0;
  2376. const bool replication = true;
  2377. bool truncation;
  2378. int in_width = vm->hactive;
  2379. int in_height = vm->vactive;
  2380. enum omap_overlay_caps caps =
  2381. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
  2382. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2383. in_height /= 2;
  2384. DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
  2385. "rot %d\n", wi->paddr, wi->p_uv_addr, in_width,
  2386. in_height, wi->width, wi->height, wi->fourcc, wi->rotation);
  2387. r = dispc_ovl_setup_common(dispc, plane, caps, wi->paddr, wi->p_uv_addr,
  2388. wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
  2389. wi->height, wi->fourcc, wi->rotation, zorder,
  2390. wi->pre_mult_alpha, global_alpha, wi->rotation_type,
  2391. replication, vm, mem_to_mem);
  2392. if (r)
  2393. return r;
  2394. switch (wi->fourcc) {
  2395. case DRM_FORMAT_RGB565:
  2396. case DRM_FORMAT_RGB888:
  2397. case DRM_FORMAT_ARGB4444:
  2398. case DRM_FORMAT_RGBA4444:
  2399. case DRM_FORMAT_RGBX4444:
  2400. case DRM_FORMAT_ARGB1555:
  2401. case DRM_FORMAT_XRGB1555:
  2402. case DRM_FORMAT_XRGB4444:
  2403. truncation = true;
  2404. break;
  2405. default:
  2406. truncation = false;
  2407. break;
  2408. }
  2409. /* setup extra DISPC_WB_ATTRIBUTES */
  2410. l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  2411. l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
  2412. l = FLD_MOD(l, channel_in, 18, 16); /* CHANNELIN */
  2413. l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
  2414. if (mem_to_mem)
  2415. l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
  2416. else
  2417. l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
  2418. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
  2419. if (mem_to_mem) {
  2420. /* WBDELAYCOUNT */
  2421. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
  2422. } else {
  2423. u32 wbdelay;
  2424. if (channel_in == DSS_WB_TV_MGR)
  2425. wbdelay = vm->vsync_len + vm->vback_porch;
  2426. else
  2427. wbdelay = vm->vfront_porch + vm->vsync_len +
  2428. vm->vback_porch;
  2429. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2430. wbdelay /= 2;
  2431. wbdelay = min(wbdelay, 255u);
  2432. /* WBDELAYCOUNT */
  2433. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
  2434. }
  2435. return 0;
  2436. }
  2437. static bool dispc_has_writeback(struct dispc_device *dispc)
  2438. {
  2439. return dispc->feat->has_writeback;
  2440. }
  2441. static int dispc_ovl_enable(struct dispc_device *dispc,
  2442. enum omap_plane_id plane, bool enable)
  2443. {
  2444. DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
  2445. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
  2446. return 0;
  2447. }
  2448. static enum omap_dss_output_id
  2449. dispc_mgr_get_supported_outputs(struct dispc_device *dispc,
  2450. enum omap_channel channel)
  2451. {
  2452. return dss_get_supported_outputs(dispc->dss, channel);
  2453. }
  2454. static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc,
  2455. bool act_high)
  2456. {
  2457. if (!dispc_has_feature(dispc, FEAT_LCDENABLEPOL))
  2458. return;
  2459. REG_FLD_MOD(dispc, DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
  2460. }
  2461. void dispc_lcd_enable_signal(struct dispc_device *dispc, bool enable)
  2462. {
  2463. if (!dispc_has_feature(dispc, FEAT_LCDENABLESIGNAL))
  2464. return;
  2465. REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 28, 28);
  2466. }
  2467. void dispc_pck_free_enable(struct dispc_device *dispc, bool enable)
  2468. {
  2469. if (!dispc_has_feature(dispc, FEAT_PCKFREEENABLE))
  2470. return;
  2471. REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 27, 27);
  2472. }
  2473. static void dispc_mgr_enable_fifohandcheck(struct dispc_device *dispc,
  2474. enum omap_channel channel,
  2475. bool enable)
  2476. {
  2477. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
  2478. }
  2479. static void dispc_mgr_set_lcd_type_tft(struct dispc_device *dispc,
  2480. enum omap_channel channel)
  2481. {
  2482. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STNTFT, 1);
  2483. }
  2484. static void dispc_set_loadmode(struct dispc_device *dispc,
  2485. enum omap_dss_load_mode mode)
  2486. {
  2487. REG_FLD_MOD(dispc, DISPC_CONFIG, mode, 2, 1);
  2488. }
  2489. static void dispc_mgr_set_default_color(struct dispc_device *dispc,
  2490. enum omap_channel channel, u32 color)
  2491. {
  2492. dispc_write_reg(dispc, DISPC_DEFAULT_COLOR(channel), color);
  2493. }
  2494. static void dispc_mgr_set_trans_key(struct dispc_device *dispc,
  2495. enum omap_channel ch,
  2496. enum omap_dss_trans_key_type type,
  2497. u32 trans_key)
  2498. {
  2499. mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKSELECTION, type);
  2500. dispc_write_reg(dispc, DISPC_TRANS_COLOR(ch), trans_key);
  2501. }
  2502. static void dispc_mgr_enable_trans_key(struct dispc_device *dispc,
  2503. enum omap_channel ch, bool enable)
  2504. {
  2505. mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKENABLE, enable);
  2506. }
  2507. static void dispc_mgr_enable_alpha_fixed_zorder(struct dispc_device *dispc,
  2508. enum omap_channel ch,
  2509. bool enable)
  2510. {
  2511. if (!dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER))
  2512. return;
  2513. if (ch == OMAP_DSS_CHANNEL_LCD)
  2514. REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 18, 18);
  2515. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  2516. REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 19, 19);
  2517. }
  2518. static void dispc_mgr_setup(struct dispc_device *dispc,
  2519. enum omap_channel channel,
  2520. const struct omap_overlay_manager_info *info)
  2521. {
  2522. dispc_mgr_set_default_color(dispc, channel, info->default_color);
  2523. dispc_mgr_set_trans_key(dispc, channel, info->trans_key_type,
  2524. info->trans_key);
  2525. dispc_mgr_enable_trans_key(dispc, channel, info->trans_enabled);
  2526. dispc_mgr_enable_alpha_fixed_zorder(dispc, channel,
  2527. info->partial_alpha_enabled);
  2528. if (dispc_has_feature(dispc, FEAT_CPR)) {
  2529. dispc_mgr_enable_cpr(dispc, channel, info->cpr_enable);
  2530. dispc_mgr_set_cpr_coef(dispc, channel, &info->cpr_coefs);
  2531. }
  2532. }
  2533. static void dispc_mgr_set_tft_data_lines(struct dispc_device *dispc,
  2534. enum omap_channel channel,
  2535. u8 data_lines)
  2536. {
  2537. int code;
  2538. switch (data_lines) {
  2539. case 12:
  2540. code = 0;
  2541. break;
  2542. case 16:
  2543. code = 1;
  2544. break;
  2545. case 18:
  2546. code = 2;
  2547. break;
  2548. case 24:
  2549. code = 3;
  2550. break;
  2551. default:
  2552. BUG();
  2553. return;
  2554. }
  2555. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_TFTDATALINES, code);
  2556. }
  2557. static void dispc_mgr_set_io_pad_mode(struct dispc_device *dispc,
  2558. enum dss_io_pad_mode mode)
  2559. {
  2560. u32 l;
  2561. int gpout0, gpout1;
  2562. switch (mode) {
  2563. case DSS_IO_PAD_MODE_RESET:
  2564. gpout0 = 0;
  2565. gpout1 = 0;
  2566. break;
  2567. case DSS_IO_PAD_MODE_RFBI:
  2568. gpout0 = 1;
  2569. gpout1 = 0;
  2570. break;
  2571. case DSS_IO_PAD_MODE_BYPASS:
  2572. gpout0 = 1;
  2573. gpout1 = 1;
  2574. break;
  2575. default:
  2576. BUG();
  2577. return;
  2578. }
  2579. l = dispc_read_reg(dispc, DISPC_CONTROL);
  2580. l = FLD_MOD(l, gpout0, 15, 15);
  2581. l = FLD_MOD(l, gpout1, 16, 16);
  2582. dispc_write_reg(dispc, DISPC_CONTROL, l);
  2583. }
  2584. static void dispc_mgr_enable_stallmode(struct dispc_device *dispc,
  2585. enum omap_channel channel, bool enable)
  2586. {
  2587. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STALLMODE, enable);
  2588. }
  2589. static void dispc_mgr_set_lcd_config(struct dispc_device *dispc,
  2590. enum omap_channel channel,
  2591. const struct dss_lcd_mgr_config *config)
  2592. {
  2593. dispc_mgr_set_io_pad_mode(dispc, config->io_pad_mode);
  2594. dispc_mgr_enable_stallmode(dispc, channel, config->stallmode);
  2595. dispc_mgr_enable_fifohandcheck(dispc, channel, config->fifohandcheck);
  2596. dispc_mgr_set_clock_div(dispc, channel, &config->clock_info);
  2597. dispc_mgr_set_tft_data_lines(dispc, channel, config->video_port_width);
  2598. dispc_lcd_enable_signal_polarity(dispc, config->lcden_sig_polarity);
  2599. dispc_mgr_set_lcd_type_tft(dispc, channel);
  2600. }
  2601. static bool _dispc_mgr_size_ok(struct dispc_device *dispc,
  2602. u16 width, u16 height)
  2603. {
  2604. return width <= dispc->feat->mgr_width_max &&
  2605. height <= dispc->feat->mgr_height_max;
  2606. }
  2607. static bool _dispc_lcd_timings_ok(struct dispc_device *dispc,
  2608. int hsync_len, int hfp, int hbp,
  2609. int vsw, int vfp, int vbp)
  2610. {
  2611. if (hsync_len < 1 || hsync_len > dispc->feat->sw_max ||
  2612. hfp < 1 || hfp > dispc->feat->hp_max ||
  2613. hbp < 1 || hbp > dispc->feat->hp_max ||
  2614. vsw < 1 || vsw > dispc->feat->sw_max ||
  2615. vfp < 0 || vfp > dispc->feat->vp_max ||
  2616. vbp < 0 || vbp > dispc->feat->vp_max)
  2617. return false;
  2618. return true;
  2619. }
  2620. static bool _dispc_mgr_pclk_ok(struct dispc_device *dispc,
  2621. enum omap_channel channel,
  2622. unsigned long pclk)
  2623. {
  2624. if (dss_mgr_is_lcd(channel))
  2625. return pclk <= dispc->feat->max_lcd_pclk;
  2626. else
  2627. return pclk <= dispc->feat->max_tv_pclk;
  2628. }
  2629. bool dispc_mgr_timings_ok(struct dispc_device *dispc, enum omap_channel channel,
  2630. const struct videomode *vm)
  2631. {
  2632. if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive))
  2633. return false;
  2634. if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock))
  2635. return false;
  2636. if (dss_mgr_is_lcd(channel)) {
  2637. /* TODO: OMAP4+ supports interlace for LCD outputs */
  2638. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2639. return false;
  2640. if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len,
  2641. vm->hfront_porch, vm->hback_porch,
  2642. vm->vsync_len, vm->vfront_porch,
  2643. vm->vback_porch))
  2644. return false;
  2645. }
  2646. return true;
  2647. }
  2648. static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc,
  2649. enum omap_channel channel,
  2650. const struct videomode *vm)
  2651. {
  2652. u32 timing_h, timing_v, l;
  2653. bool onoff, rf, ipc, vs, hs, de;
  2654. timing_h = FLD_VAL(vm->hsync_len - 1, dispc->feat->sw_start, 0) |
  2655. FLD_VAL(vm->hfront_porch - 1, dispc->feat->fp_start, 8) |
  2656. FLD_VAL(vm->hback_porch - 1, dispc->feat->bp_start, 20);
  2657. timing_v = FLD_VAL(vm->vsync_len - 1, dispc->feat->sw_start, 0) |
  2658. FLD_VAL(vm->vfront_porch, dispc->feat->fp_start, 8) |
  2659. FLD_VAL(vm->vback_porch, dispc->feat->bp_start, 20);
  2660. dispc_write_reg(dispc, DISPC_TIMING_H(channel), timing_h);
  2661. dispc_write_reg(dispc, DISPC_TIMING_V(channel), timing_v);
  2662. if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
  2663. vs = false;
  2664. else
  2665. vs = true;
  2666. if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
  2667. hs = false;
  2668. else
  2669. hs = true;
  2670. if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
  2671. de = false;
  2672. else
  2673. de = true;
  2674. if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
  2675. ipc = false;
  2676. else
  2677. ipc = true;
  2678. /* always use the 'rf' setting */
  2679. onoff = true;
  2680. if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE)
  2681. rf = true;
  2682. else
  2683. rf = false;
  2684. l = FLD_VAL(onoff, 17, 17) |
  2685. FLD_VAL(rf, 16, 16) |
  2686. FLD_VAL(de, 15, 15) |
  2687. FLD_VAL(ipc, 14, 14) |
  2688. FLD_VAL(hs, 13, 13) |
  2689. FLD_VAL(vs, 12, 12);
  2690. /* always set ALIGN bit when available */
  2691. if (dispc->feat->supports_sync_align)
  2692. l |= (1 << 18);
  2693. dispc_write_reg(dispc, DISPC_POL_FREQ(channel), l);
  2694. if (dispc->syscon_pol) {
  2695. const int shifts[] = {
  2696. [OMAP_DSS_CHANNEL_LCD] = 0,
  2697. [OMAP_DSS_CHANNEL_LCD2] = 1,
  2698. [OMAP_DSS_CHANNEL_LCD3] = 2,
  2699. };
  2700. u32 mask, val;
  2701. mask = (1 << 0) | (1 << 3) | (1 << 6);
  2702. val = (rf << 0) | (ipc << 3) | (onoff << 6);
  2703. mask <<= 16 + shifts[channel];
  2704. val <<= 16 + shifts[channel];
  2705. regmap_update_bits(dispc->syscon_pol, dispc->syscon_pol_offset,
  2706. mask, val);
  2707. }
  2708. }
  2709. static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
  2710. enum display_flags low)
  2711. {
  2712. if (flags & high)
  2713. return 1;
  2714. if (flags & low)
  2715. return -1;
  2716. return 0;
  2717. }
  2718. /* change name to mode? */
  2719. static void dispc_mgr_set_timings(struct dispc_device *dispc,
  2720. enum omap_channel channel,
  2721. const struct videomode *vm)
  2722. {
  2723. unsigned int xtot, ytot;
  2724. unsigned long ht, vt;
  2725. struct videomode t = *vm;
  2726. DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
  2727. if (!dispc_mgr_timings_ok(dispc, channel, &t)) {
  2728. BUG();
  2729. return;
  2730. }
  2731. if (dss_mgr_is_lcd(channel)) {
  2732. _dispc_mgr_set_lcd_timings(dispc, channel, &t);
  2733. xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
  2734. ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
  2735. ht = vm->pixelclock / xtot;
  2736. vt = vm->pixelclock / xtot / ytot;
  2737. DSSDBG("pck %lu\n", vm->pixelclock);
  2738. DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
  2739. t.hsync_len, t.hfront_porch, t.hback_porch,
  2740. t.vsync_len, t.vfront_porch, t.vback_porch);
  2741. DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
  2742. vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
  2743. vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
  2744. vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
  2745. vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
  2746. vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
  2747. DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
  2748. } else {
  2749. if (t.flags & DISPLAY_FLAGS_INTERLACED)
  2750. t.vactive /= 2;
  2751. if (dispc->feat->supports_double_pixel)
  2752. REG_FLD_MOD(dispc, DISPC_CONTROL,
  2753. !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
  2754. 19, 17);
  2755. }
  2756. dispc_mgr_set_size(dispc, channel, t.hactive, t.vactive);
  2757. }
  2758. static void dispc_mgr_set_lcd_divisor(struct dispc_device *dispc,
  2759. enum omap_channel channel, u16 lck_div,
  2760. u16 pck_div)
  2761. {
  2762. BUG_ON(lck_div < 1);
  2763. BUG_ON(pck_div < 1);
  2764. dispc_write_reg(dispc, DISPC_DIVISORo(channel),
  2765. FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
  2766. if (!dispc_has_feature(dispc, FEAT_CORE_CLK_DIV) &&
  2767. channel == OMAP_DSS_CHANNEL_LCD)
  2768. dispc->core_clk_rate = dispc_fclk_rate(dispc) / lck_div;
  2769. }
  2770. static void dispc_mgr_get_lcd_divisor(struct dispc_device *dispc,
  2771. enum omap_channel channel, int *lck_div,
  2772. int *pck_div)
  2773. {
  2774. u32 l;
  2775. l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
  2776. *lck_div = FLD_GET(l, 23, 16);
  2777. *pck_div = FLD_GET(l, 7, 0);
  2778. }
  2779. static unsigned long dispc_fclk_rate(struct dispc_device *dispc)
  2780. {
  2781. unsigned long r;
  2782. enum dss_clk_source src;
  2783. src = dss_get_dispc_clk_source(dispc->dss);
  2784. if (src == DSS_CLK_SRC_FCK) {
  2785. r = dss_get_dispc_clk_rate(dispc->dss);
  2786. } else {
  2787. struct dss_pll *pll;
  2788. unsigned int clkout_idx;
  2789. pll = dss_pll_find_by_src(dispc->dss, src);
  2790. clkout_idx = dss_pll_get_clkout_idx_for_src(src);
  2791. r = pll->cinfo.clkout[clkout_idx];
  2792. }
  2793. return r;
  2794. }
  2795. static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
  2796. enum omap_channel channel)
  2797. {
  2798. int lcd;
  2799. unsigned long r;
  2800. enum dss_clk_source src;
  2801. /* for TV, LCLK rate is the FCLK rate */
  2802. if (!dss_mgr_is_lcd(channel))
  2803. return dispc_fclk_rate(dispc);
  2804. src = dss_get_lcd_clk_source(dispc->dss, channel);
  2805. if (src == DSS_CLK_SRC_FCK) {
  2806. r = dss_get_dispc_clk_rate(dispc->dss);
  2807. } else {
  2808. struct dss_pll *pll;
  2809. unsigned int clkout_idx;
  2810. pll = dss_pll_find_by_src(dispc->dss, src);
  2811. clkout_idx = dss_pll_get_clkout_idx_for_src(src);
  2812. r = pll->cinfo.clkout[clkout_idx];
  2813. }
  2814. lcd = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
  2815. return r / lcd;
  2816. }
  2817. static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
  2818. enum omap_channel channel)
  2819. {
  2820. unsigned long r;
  2821. if (dss_mgr_is_lcd(channel)) {
  2822. int pcd;
  2823. u32 l;
  2824. l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
  2825. pcd = FLD_GET(l, 7, 0);
  2826. r = dispc_mgr_lclk_rate(dispc, channel);
  2827. return r / pcd;
  2828. } else {
  2829. return dispc->tv_pclk_rate;
  2830. }
  2831. }
  2832. void dispc_set_tv_pclk(struct dispc_device *dispc, unsigned long pclk)
  2833. {
  2834. dispc->tv_pclk_rate = pclk;
  2835. }
  2836. static unsigned long dispc_core_clk_rate(struct dispc_device *dispc)
  2837. {
  2838. return dispc->core_clk_rate;
  2839. }
  2840. static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
  2841. enum omap_plane_id plane)
  2842. {
  2843. enum omap_channel channel;
  2844. if (plane == OMAP_DSS_WB)
  2845. return 0;
  2846. channel = dispc_ovl_get_channel_out(dispc, plane);
  2847. return dispc_mgr_pclk_rate(dispc, channel);
  2848. }
  2849. static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
  2850. enum omap_plane_id plane)
  2851. {
  2852. enum omap_channel channel;
  2853. if (plane == OMAP_DSS_WB)
  2854. return 0;
  2855. channel = dispc_ovl_get_channel_out(dispc, plane);
  2856. return dispc_mgr_lclk_rate(dispc, channel);
  2857. }
  2858. static void dispc_dump_clocks_channel(struct dispc_device *dispc,
  2859. struct seq_file *s,
  2860. enum omap_channel channel)
  2861. {
  2862. int lcd, pcd;
  2863. enum dss_clk_source lcd_clk_src;
  2864. seq_printf(s, "- %s -\n", mgr_desc[channel].name);
  2865. lcd_clk_src = dss_get_lcd_clk_source(dispc->dss, channel);
  2866. seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
  2867. dss_get_clk_source_name(lcd_clk_src));
  2868. dispc_mgr_get_lcd_divisor(dispc, channel, &lcd, &pcd);
  2869. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2870. dispc_mgr_lclk_rate(dispc, channel), lcd);
  2871. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2872. dispc_mgr_pclk_rate(dispc, channel), pcd);
  2873. }
  2874. void dispc_dump_clocks(struct dispc_device *dispc, struct seq_file *s)
  2875. {
  2876. enum dss_clk_source dispc_clk_src;
  2877. int lcd;
  2878. u32 l;
  2879. if (dispc_runtime_get(dispc))
  2880. return;
  2881. seq_printf(s, "- DISPC -\n");
  2882. dispc_clk_src = dss_get_dispc_clk_source(dispc->dss);
  2883. seq_printf(s, "dispc fclk source = %s\n",
  2884. dss_get_clk_source_name(dispc_clk_src));
  2885. seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate(dispc));
  2886. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
  2887. seq_printf(s, "- DISPC-CORE-CLK -\n");
  2888. l = dispc_read_reg(dispc, DISPC_DIVISOR);
  2889. lcd = FLD_GET(l, 23, 16);
  2890. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2891. (dispc_fclk_rate(dispc)/lcd), lcd);
  2892. }
  2893. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD);
  2894. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  2895. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD2);
  2896. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  2897. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD3);
  2898. dispc_runtime_put(dispc);
  2899. }
  2900. static int dispc_dump_regs(struct seq_file *s, void *p)
  2901. {
  2902. struct dispc_device *dispc = s->private;
  2903. int i, j;
  2904. const char *mgr_names[] = {
  2905. [OMAP_DSS_CHANNEL_LCD] = "LCD",
  2906. [OMAP_DSS_CHANNEL_DIGIT] = "TV",
  2907. [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
  2908. [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
  2909. };
  2910. const char *ovl_names[] = {
  2911. [OMAP_DSS_GFX] = "GFX",
  2912. [OMAP_DSS_VIDEO1] = "VID1",
  2913. [OMAP_DSS_VIDEO2] = "VID2",
  2914. [OMAP_DSS_VIDEO3] = "VID3",
  2915. [OMAP_DSS_WB] = "WB",
  2916. };
  2917. const char **p_names;
  2918. #define DUMPREG(dispc, r) \
  2919. seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(dispc, r))
  2920. if (dispc_runtime_get(dispc))
  2921. return 0;
  2922. /* DISPC common registers */
  2923. DUMPREG(dispc, DISPC_REVISION);
  2924. DUMPREG(dispc, DISPC_SYSCONFIG);
  2925. DUMPREG(dispc, DISPC_SYSSTATUS);
  2926. DUMPREG(dispc, DISPC_IRQSTATUS);
  2927. DUMPREG(dispc, DISPC_IRQENABLE);
  2928. DUMPREG(dispc, DISPC_CONTROL);
  2929. DUMPREG(dispc, DISPC_CONFIG);
  2930. DUMPREG(dispc, DISPC_CAPABLE);
  2931. DUMPREG(dispc, DISPC_LINE_STATUS);
  2932. DUMPREG(dispc, DISPC_LINE_NUMBER);
  2933. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  2934. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  2935. DUMPREG(dispc, DISPC_GLOBAL_ALPHA);
  2936. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  2937. DUMPREG(dispc, DISPC_CONTROL2);
  2938. DUMPREG(dispc, DISPC_CONFIG2);
  2939. }
  2940. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  2941. DUMPREG(dispc, DISPC_CONTROL3);
  2942. DUMPREG(dispc, DISPC_CONFIG3);
  2943. }
  2944. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2945. DUMPREG(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE);
  2946. #undef DUMPREG
  2947. #define DISPC_REG(i, name) name(i)
  2948. #define DUMPREG(dispc, i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
  2949. (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
  2950. dispc_read_reg(dispc, DISPC_REG(i, r)))
  2951. p_names = mgr_names;
  2952. /* DISPC channel specific registers */
  2953. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  2954. DUMPREG(dispc, i, DISPC_DEFAULT_COLOR);
  2955. DUMPREG(dispc, i, DISPC_TRANS_COLOR);
  2956. DUMPREG(dispc, i, DISPC_SIZE_MGR);
  2957. if (i == OMAP_DSS_CHANNEL_DIGIT)
  2958. continue;
  2959. DUMPREG(dispc, i, DISPC_TIMING_H);
  2960. DUMPREG(dispc, i, DISPC_TIMING_V);
  2961. DUMPREG(dispc, i, DISPC_POL_FREQ);
  2962. DUMPREG(dispc, i, DISPC_DIVISORo);
  2963. DUMPREG(dispc, i, DISPC_DATA_CYCLE1);
  2964. DUMPREG(dispc, i, DISPC_DATA_CYCLE2);
  2965. DUMPREG(dispc, i, DISPC_DATA_CYCLE3);
  2966. if (dispc_has_feature(dispc, FEAT_CPR)) {
  2967. DUMPREG(dispc, i, DISPC_CPR_COEF_R);
  2968. DUMPREG(dispc, i, DISPC_CPR_COEF_G);
  2969. DUMPREG(dispc, i, DISPC_CPR_COEF_B);
  2970. }
  2971. }
  2972. p_names = ovl_names;
  2973. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  2974. DUMPREG(dispc, i, DISPC_OVL_BA0);
  2975. DUMPREG(dispc, i, DISPC_OVL_BA1);
  2976. DUMPREG(dispc, i, DISPC_OVL_POSITION);
  2977. DUMPREG(dispc, i, DISPC_OVL_SIZE);
  2978. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
  2979. DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
  2980. DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
  2981. DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
  2982. DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
  2983. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  2984. DUMPREG(dispc, i, DISPC_OVL_PRELOAD);
  2985. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2986. DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
  2987. if (i == OMAP_DSS_GFX) {
  2988. DUMPREG(dispc, i, DISPC_OVL_WINDOW_SKIP);
  2989. DUMPREG(dispc, i, DISPC_OVL_TABLE_BA);
  2990. continue;
  2991. }
  2992. DUMPREG(dispc, i, DISPC_OVL_FIR);
  2993. DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
  2994. DUMPREG(dispc, i, DISPC_OVL_ACCU0);
  2995. DUMPREG(dispc, i, DISPC_OVL_ACCU1);
  2996. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  2997. DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
  2998. DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
  2999. DUMPREG(dispc, i, DISPC_OVL_FIR2);
  3000. DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
  3001. DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
  3002. }
  3003. if (dispc_has_feature(dispc, FEAT_ATTR2))
  3004. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
  3005. }
  3006. if (dispc->feat->has_writeback) {
  3007. i = OMAP_DSS_WB;
  3008. DUMPREG(dispc, i, DISPC_OVL_BA0);
  3009. DUMPREG(dispc, i, DISPC_OVL_BA1);
  3010. DUMPREG(dispc, i, DISPC_OVL_SIZE);
  3011. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
  3012. DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
  3013. DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
  3014. DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
  3015. DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
  3016. if (dispc_has_feature(dispc, FEAT_MFLAG))
  3017. DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
  3018. DUMPREG(dispc, i, DISPC_OVL_FIR);
  3019. DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
  3020. DUMPREG(dispc, i, DISPC_OVL_ACCU0);
  3021. DUMPREG(dispc, i, DISPC_OVL_ACCU1);
  3022. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  3023. DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
  3024. DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
  3025. DUMPREG(dispc, i, DISPC_OVL_FIR2);
  3026. DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
  3027. DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
  3028. }
  3029. if (dispc_has_feature(dispc, FEAT_ATTR2))
  3030. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
  3031. }
  3032. #undef DISPC_REG
  3033. #undef DUMPREG
  3034. #define DISPC_REG(plane, name, i) name(plane, i)
  3035. #define DUMPREG(dispc, plane, name, i) \
  3036. seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
  3037. (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
  3038. dispc_read_reg(dispc, DISPC_REG(plane, name, i)))
  3039. /* Video pipeline coefficient registers */
  3040. /* start from OMAP_DSS_VIDEO1 */
  3041. for (i = 1; i < dispc_get_num_ovls(dispc); i++) {
  3042. for (j = 0; j < 8; j++)
  3043. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H, j);
  3044. for (j = 0; j < 8; j++)
  3045. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV, j);
  3046. for (j = 0; j < 5; j++)
  3047. DUMPREG(dispc, i, DISPC_OVL_CONV_COEF, j);
  3048. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  3049. for (j = 0; j < 8; j++)
  3050. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V, j);
  3051. }
  3052. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  3053. for (j = 0; j < 8; j++)
  3054. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H2, j);
  3055. for (j = 0; j < 8; j++)
  3056. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV2, j);
  3057. for (j = 0; j < 8; j++)
  3058. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V2, j);
  3059. }
  3060. }
  3061. dispc_runtime_put(dispc);
  3062. #undef DISPC_REG
  3063. #undef DUMPREG
  3064. return 0;
  3065. }
  3066. /* calculate clock rates using dividers in cinfo */
  3067. int dispc_calc_clock_rates(struct dispc_device *dispc,
  3068. unsigned long dispc_fclk_rate,
  3069. struct dispc_clock_info *cinfo)
  3070. {
  3071. if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
  3072. return -EINVAL;
  3073. if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
  3074. return -EINVAL;
  3075. cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
  3076. cinfo->pck = cinfo->lck / cinfo->pck_div;
  3077. return 0;
  3078. }
  3079. bool dispc_div_calc(struct dispc_device *dispc, unsigned long dispc_freq,
  3080. unsigned long pck_min, unsigned long pck_max,
  3081. dispc_div_calc_func func, void *data)
  3082. {
  3083. int lckd, lckd_start, lckd_stop;
  3084. int pckd, pckd_start, pckd_stop;
  3085. unsigned long pck, lck;
  3086. unsigned long lck_max;
  3087. unsigned long pckd_hw_min, pckd_hw_max;
  3088. unsigned int min_fck_per_pck;
  3089. unsigned long fck;
  3090. #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
  3091. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  3092. #else
  3093. min_fck_per_pck = 0;
  3094. #endif
  3095. pckd_hw_min = dispc->feat->min_pcd;
  3096. pckd_hw_max = 255;
  3097. lck_max = dss_get_max_fck_rate(dispc->dss);
  3098. pck_min = pck_min ? pck_min : 1;
  3099. pck_max = pck_max ? pck_max : ULONG_MAX;
  3100. lckd_start = max(DIV_ROUND_UP(dispc_freq, lck_max), 1ul);
  3101. lckd_stop = min(dispc_freq / pck_min, 255ul);
  3102. for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
  3103. lck = dispc_freq / lckd;
  3104. pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
  3105. pckd_stop = min(lck / pck_min, pckd_hw_max);
  3106. for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
  3107. pck = lck / pckd;
  3108. /*
  3109. * For OMAP2/3 the DISPC fclk is the same as LCD's logic
  3110. * clock, which means we're configuring DISPC fclk here
  3111. * also. Thus we need to use the calculated lck. For
  3112. * OMAP4+ the DISPC fclk is a separate clock.
  3113. */
  3114. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  3115. fck = dispc_core_clk_rate(dispc);
  3116. else
  3117. fck = lck;
  3118. if (fck < pck * min_fck_per_pck)
  3119. continue;
  3120. if (func(lckd, pckd, lck, pck, data))
  3121. return true;
  3122. }
  3123. }
  3124. return false;
  3125. }
  3126. void dispc_mgr_set_clock_div(struct dispc_device *dispc,
  3127. enum omap_channel channel,
  3128. const struct dispc_clock_info *cinfo)
  3129. {
  3130. DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
  3131. DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
  3132. dispc_mgr_set_lcd_divisor(dispc, channel, cinfo->lck_div,
  3133. cinfo->pck_div);
  3134. }
  3135. int dispc_mgr_get_clock_div(struct dispc_device *dispc,
  3136. enum omap_channel channel,
  3137. struct dispc_clock_info *cinfo)
  3138. {
  3139. unsigned long fck;
  3140. fck = dispc_fclk_rate(dispc);
  3141. cinfo->lck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
  3142. cinfo->pck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 7, 0);
  3143. cinfo->lck = fck / cinfo->lck_div;
  3144. cinfo->pck = cinfo->lck / cinfo->pck_div;
  3145. return 0;
  3146. }
  3147. static u32 dispc_read_irqstatus(struct dispc_device *dispc)
  3148. {
  3149. return dispc_read_reg(dispc, DISPC_IRQSTATUS);
  3150. }
  3151. static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask)
  3152. {
  3153. dispc_write_reg(dispc, DISPC_IRQSTATUS, mask);
  3154. }
  3155. static void dispc_write_irqenable(struct dispc_device *dispc, u32 mask)
  3156. {
  3157. u32 old_mask = dispc_read_reg(dispc, DISPC_IRQENABLE);
  3158. /* clear the irqstatus for newly enabled irqs */
  3159. dispc_clear_irqstatus(dispc, (mask ^ old_mask) & mask);
  3160. dispc_write_reg(dispc, DISPC_IRQENABLE, mask);
  3161. /* flush posted write */
  3162. dispc_read_reg(dispc, DISPC_IRQENABLE);
  3163. }
  3164. void dispc_enable_sidle(struct dispc_device *dispc)
  3165. {
  3166. /* SIDLEMODE: smart idle */
  3167. REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 2, 4, 3);
  3168. }
  3169. void dispc_disable_sidle(struct dispc_device *dispc)
  3170. {
  3171. REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
  3172. }
  3173. static u32 dispc_mgr_gamma_size(struct dispc_device *dispc,
  3174. enum omap_channel channel)
  3175. {
  3176. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3177. if (!dispc->feat->has_gamma_table)
  3178. return 0;
  3179. return gdesc->len;
  3180. }
  3181. static void dispc_mgr_write_gamma_table(struct dispc_device *dispc,
  3182. enum omap_channel channel)
  3183. {
  3184. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3185. u32 *table = dispc->gamma_table[channel];
  3186. unsigned int i;
  3187. DSSDBG("%s: channel %d\n", __func__, channel);
  3188. for (i = 0; i < gdesc->len; ++i) {
  3189. u32 v = table[i];
  3190. if (gdesc->has_index)
  3191. v |= i << 24;
  3192. else if (i == 0)
  3193. v |= 1 << 31;
  3194. dispc_write_reg(dispc, gdesc->reg, v);
  3195. }
  3196. }
  3197. static void dispc_restore_gamma_tables(struct dispc_device *dispc)
  3198. {
  3199. DSSDBG("%s()\n", __func__);
  3200. if (!dispc->feat->has_gamma_table)
  3201. return;
  3202. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD);
  3203. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_DIGIT);
  3204. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  3205. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD2);
  3206. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  3207. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD3);
  3208. }
  3209. static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
  3210. { .red = 0, .green = 0, .blue = 0, },
  3211. { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
  3212. };
  3213. static void dispc_mgr_set_gamma(struct dispc_device *dispc,
  3214. enum omap_channel channel,
  3215. const struct drm_color_lut *lut,
  3216. unsigned int length)
  3217. {
  3218. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3219. u32 *table = dispc->gamma_table[channel];
  3220. uint i;
  3221. DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
  3222. channel, length, gdesc->len);
  3223. if (!dispc->feat->has_gamma_table)
  3224. return;
  3225. if (lut == NULL || length < 2) {
  3226. lut = dispc_mgr_gamma_default_lut;
  3227. length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
  3228. }
  3229. for (i = 0; i < length - 1; ++i) {
  3230. uint first = i * (gdesc->len - 1) / (length - 1);
  3231. uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
  3232. uint w = last - first;
  3233. u16 r, g, b;
  3234. uint j;
  3235. if (w == 0)
  3236. continue;
  3237. for (j = 0; j <= w; j++) {
  3238. r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
  3239. g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
  3240. b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
  3241. r >>= 16 - gdesc->bits;
  3242. g >>= 16 - gdesc->bits;
  3243. b >>= 16 - gdesc->bits;
  3244. table[first + j] = (r << (gdesc->bits * 2)) |
  3245. (g << gdesc->bits) | b;
  3246. }
  3247. }
  3248. if (dispc->is_enabled)
  3249. dispc_mgr_write_gamma_table(dispc, channel);
  3250. }
  3251. static int dispc_init_gamma_tables(struct dispc_device *dispc)
  3252. {
  3253. int channel;
  3254. if (!dispc->feat->has_gamma_table)
  3255. return 0;
  3256. for (channel = 0; channel < ARRAY_SIZE(dispc->gamma_table); channel++) {
  3257. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3258. u32 *gt;
  3259. if (channel == OMAP_DSS_CHANNEL_LCD2 &&
  3260. !dispc_has_feature(dispc, FEAT_MGR_LCD2))
  3261. continue;
  3262. if (channel == OMAP_DSS_CHANNEL_LCD3 &&
  3263. !dispc_has_feature(dispc, FEAT_MGR_LCD3))
  3264. continue;
  3265. gt = devm_kmalloc_array(&dispc->pdev->dev, gdesc->len,
  3266. sizeof(u32), GFP_KERNEL);
  3267. if (!gt)
  3268. return -ENOMEM;
  3269. dispc->gamma_table[channel] = gt;
  3270. dispc_mgr_set_gamma(dispc, channel, NULL, 0);
  3271. }
  3272. return 0;
  3273. }
  3274. static void _omap_dispc_initial_config(struct dispc_device *dispc)
  3275. {
  3276. u32 l;
  3277. /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
  3278. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
  3279. l = dispc_read_reg(dispc, DISPC_DIVISOR);
  3280. /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
  3281. l = FLD_MOD(l, 1, 0, 0);
  3282. l = FLD_MOD(l, 1, 23, 16);
  3283. dispc_write_reg(dispc, DISPC_DIVISOR, l);
  3284. dispc->core_clk_rate = dispc_fclk_rate(dispc);
  3285. }
  3286. /* Use gamma table mode, instead of palette mode */
  3287. if (dispc->feat->has_gamma_table)
  3288. REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 3, 3);
  3289. /* For older DSS versions (FEAT_FUNCGATED) this enables
  3290. * func-clock auto-gating. For newer versions
  3291. * (dispc->feat->has_gamma_table) this enables tv-out gamma tables.
  3292. */
  3293. if (dispc_has_feature(dispc, FEAT_FUNCGATED) ||
  3294. dispc->feat->has_gamma_table)
  3295. REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 9, 9);
  3296. dispc_setup_color_conv_coef(dispc);
  3297. dispc_set_loadmode(dispc, OMAP_DSS_LOAD_FRAME_ONLY);
  3298. dispc_init_fifos(dispc);
  3299. dispc_configure_burst_sizes(dispc);
  3300. dispc_ovl_enable_zorder_planes(dispc);
  3301. if (dispc->feat->mstandby_workaround)
  3302. REG_FLD_MOD(dispc, DISPC_MSTANDBY_CTRL, 1, 0, 0);
  3303. if (dispc_has_feature(dispc, FEAT_MFLAG))
  3304. dispc_init_mflag(dispc);
  3305. }
  3306. static const enum dispc_feature_id omap2_dispc_features_list[] = {
  3307. FEAT_LCDENABLEPOL,
  3308. FEAT_LCDENABLESIGNAL,
  3309. FEAT_PCKFREEENABLE,
  3310. FEAT_FUNCGATED,
  3311. FEAT_ROWREPEATENABLE,
  3312. FEAT_RESIZECONF,
  3313. };
  3314. static const enum dispc_feature_id omap3_dispc_features_list[] = {
  3315. FEAT_LCDENABLEPOL,
  3316. FEAT_LCDENABLESIGNAL,
  3317. FEAT_PCKFREEENABLE,
  3318. FEAT_FUNCGATED,
  3319. FEAT_LINEBUFFERSPLIT,
  3320. FEAT_ROWREPEATENABLE,
  3321. FEAT_RESIZECONF,
  3322. FEAT_CPR,
  3323. FEAT_PRELOAD,
  3324. FEAT_FIR_COEF_V,
  3325. FEAT_ALPHA_FIXED_ZORDER,
  3326. FEAT_FIFO_MERGE,
  3327. FEAT_OMAP3_DSI_FIFO_BUG,
  3328. };
  3329. static const enum dispc_feature_id am43xx_dispc_features_list[] = {
  3330. FEAT_LCDENABLEPOL,
  3331. FEAT_LCDENABLESIGNAL,
  3332. FEAT_PCKFREEENABLE,
  3333. FEAT_FUNCGATED,
  3334. FEAT_LINEBUFFERSPLIT,
  3335. FEAT_ROWREPEATENABLE,
  3336. FEAT_RESIZECONF,
  3337. FEAT_CPR,
  3338. FEAT_PRELOAD,
  3339. FEAT_FIR_COEF_V,
  3340. FEAT_ALPHA_FIXED_ZORDER,
  3341. FEAT_FIFO_MERGE,
  3342. };
  3343. static const enum dispc_feature_id omap4_dispc_features_list[] = {
  3344. FEAT_MGR_LCD2,
  3345. FEAT_CORE_CLK_DIV,
  3346. FEAT_HANDLE_UV_SEPARATE,
  3347. FEAT_ATTR2,
  3348. FEAT_CPR,
  3349. FEAT_PRELOAD,
  3350. FEAT_FIR_COEF_V,
  3351. FEAT_ALPHA_FREE_ZORDER,
  3352. FEAT_FIFO_MERGE,
  3353. FEAT_BURST_2D,
  3354. };
  3355. static const enum dispc_feature_id omap5_dispc_features_list[] = {
  3356. FEAT_MGR_LCD2,
  3357. FEAT_MGR_LCD3,
  3358. FEAT_CORE_CLK_DIV,
  3359. FEAT_HANDLE_UV_SEPARATE,
  3360. FEAT_ATTR2,
  3361. FEAT_CPR,
  3362. FEAT_PRELOAD,
  3363. FEAT_FIR_COEF_V,
  3364. FEAT_ALPHA_FREE_ZORDER,
  3365. FEAT_FIFO_MERGE,
  3366. FEAT_BURST_2D,
  3367. FEAT_MFLAG,
  3368. };
  3369. static const struct dss_reg_field omap2_dispc_reg_fields[] = {
  3370. [FEAT_REG_FIRHINC] = { 11, 0 },
  3371. [FEAT_REG_FIRVINC] = { 27, 16 },
  3372. [FEAT_REG_FIFOLOWTHRESHOLD] = { 8, 0 },
  3373. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 24, 16 },
  3374. [FEAT_REG_FIFOSIZE] = { 8, 0 },
  3375. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  3376. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  3377. };
  3378. static const struct dss_reg_field omap3_dispc_reg_fields[] = {
  3379. [FEAT_REG_FIRHINC] = { 12, 0 },
  3380. [FEAT_REG_FIRVINC] = { 28, 16 },
  3381. [FEAT_REG_FIFOLOWTHRESHOLD] = { 11, 0 },
  3382. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 27, 16 },
  3383. [FEAT_REG_FIFOSIZE] = { 10, 0 },
  3384. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  3385. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  3386. };
  3387. static const struct dss_reg_field omap4_dispc_reg_fields[] = {
  3388. [FEAT_REG_FIRHINC] = { 12, 0 },
  3389. [FEAT_REG_FIRVINC] = { 28, 16 },
  3390. [FEAT_REG_FIFOLOWTHRESHOLD] = { 15, 0 },
  3391. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 31, 16 },
  3392. [FEAT_REG_FIFOSIZE] = { 15, 0 },
  3393. [FEAT_REG_HORIZONTALACCU] = { 10, 0 },
  3394. [FEAT_REG_VERTICALACCU] = { 26, 16 },
  3395. };
  3396. static const enum omap_overlay_caps omap2_dispc_overlay_caps[] = {
  3397. /* OMAP_DSS_GFX */
  3398. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3399. /* OMAP_DSS_VIDEO1 */
  3400. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3401. OMAP_DSS_OVL_CAP_REPLICATION,
  3402. /* OMAP_DSS_VIDEO2 */
  3403. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3404. OMAP_DSS_OVL_CAP_REPLICATION,
  3405. };
  3406. static const enum omap_overlay_caps omap3430_dispc_overlay_caps[] = {
  3407. /* OMAP_DSS_GFX */
  3408. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_POS |
  3409. OMAP_DSS_OVL_CAP_REPLICATION,
  3410. /* OMAP_DSS_VIDEO1 */
  3411. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3412. OMAP_DSS_OVL_CAP_REPLICATION,
  3413. /* OMAP_DSS_VIDEO2 */
  3414. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3415. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3416. };
  3417. static const enum omap_overlay_caps omap3630_dispc_overlay_caps[] = {
  3418. /* OMAP_DSS_GFX */
  3419. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
  3420. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3421. /* OMAP_DSS_VIDEO1 */
  3422. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3423. OMAP_DSS_OVL_CAP_REPLICATION,
  3424. /* OMAP_DSS_VIDEO2 */
  3425. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3426. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_POS |
  3427. OMAP_DSS_OVL_CAP_REPLICATION,
  3428. };
  3429. static const enum omap_overlay_caps omap4_dispc_overlay_caps[] = {
  3430. /* OMAP_DSS_GFX */
  3431. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
  3432. OMAP_DSS_OVL_CAP_ZORDER | OMAP_DSS_OVL_CAP_POS |
  3433. OMAP_DSS_OVL_CAP_REPLICATION,
  3434. /* OMAP_DSS_VIDEO1 */
  3435. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3436. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3437. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3438. /* OMAP_DSS_VIDEO2 */
  3439. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3440. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3441. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3442. /* OMAP_DSS_VIDEO3 */
  3443. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3444. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3445. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3446. };
  3447. #define COLOR_ARRAY(arr...) (const u32[]) { arr, 0 }
  3448. static const u32 *omap2_dispc_supported_color_modes[] = {
  3449. /* OMAP_DSS_GFX */
  3450. COLOR_ARRAY(
  3451. DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
  3452. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888),
  3453. /* OMAP_DSS_VIDEO1 */
  3454. COLOR_ARRAY(
  3455. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3456. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3457. DRM_FORMAT_UYVY),
  3458. /* OMAP_DSS_VIDEO2 */
  3459. COLOR_ARRAY(
  3460. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3461. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3462. DRM_FORMAT_UYVY),
  3463. };
  3464. static const u32 *omap3_dispc_supported_color_modes[] = {
  3465. /* OMAP_DSS_GFX */
  3466. COLOR_ARRAY(
  3467. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3468. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3469. DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
  3470. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
  3471. /* OMAP_DSS_VIDEO1 */
  3472. COLOR_ARRAY(
  3473. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888,
  3474. DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
  3475. DRM_FORMAT_YUYV, DRM_FORMAT_UYVY),
  3476. /* OMAP_DSS_VIDEO2 */
  3477. COLOR_ARRAY(
  3478. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3479. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3480. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3481. DRM_FORMAT_UYVY, DRM_FORMAT_ARGB8888,
  3482. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
  3483. };
  3484. static const u32 *omap4_dispc_supported_color_modes[] = {
  3485. /* OMAP_DSS_GFX */
  3486. COLOR_ARRAY(
  3487. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3488. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3489. DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
  3490. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888,
  3491. DRM_FORMAT_ARGB1555, DRM_FORMAT_XRGB4444,
  3492. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB1555),
  3493. /* OMAP_DSS_VIDEO1 */
  3494. COLOR_ARRAY(
  3495. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3496. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3497. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3498. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3499. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3500. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3501. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3502. DRM_FORMAT_RGBX8888),
  3503. /* OMAP_DSS_VIDEO2 */
  3504. COLOR_ARRAY(
  3505. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3506. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3507. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3508. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3509. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3510. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3511. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3512. DRM_FORMAT_RGBX8888),
  3513. /* OMAP_DSS_VIDEO3 */
  3514. COLOR_ARRAY(
  3515. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3516. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3517. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3518. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3519. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3520. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3521. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3522. DRM_FORMAT_RGBX8888),
  3523. /* OMAP_DSS_WB */
  3524. COLOR_ARRAY(
  3525. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3526. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3527. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3528. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3529. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3530. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3531. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3532. DRM_FORMAT_RGBX8888),
  3533. };
  3534. static const struct dispc_features omap24xx_dispc_feats = {
  3535. .sw_start = 5,
  3536. .fp_start = 15,
  3537. .bp_start = 27,
  3538. .sw_max = 64,
  3539. .vp_max = 255,
  3540. .hp_max = 256,
  3541. .mgr_width_start = 10,
  3542. .mgr_height_start = 26,
  3543. .mgr_width_max = 2048,
  3544. .mgr_height_max = 2048,
  3545. .max_lcd_pclk = 66500000,
  3546. .max_downscale = 2,
  3547. /*
  3548. * Assume the line width buffer to be 768 pixels as OMAP2 DISPC scaler
  3549. * cannot scale an image width larger than 768.
  3550. */
  3551. .max_line_width = 768,
  3552. .min_pcd = 2,
  3553. .calc_scaling = dispc_ovl_calc_scaling_24xx,
  3554. .calc_core_clk = calc_core_clk_24xx,
  3555. .num_fifos = 3,
  3556. .features = omap2_dispc_features_list,
  3557. .num_features = ARRAY_SIZE(omap2_dispc_features_list),
  3558. .reg_fields = omap2_dispc_reg_fields,
  3559. .num_reg_fields = ARRAY_SIZE(omap2_dispc_reg_fields),
  3560. .overlay_caps = omap2_dispc_overlay_caps,
  3561. .supported_color_modes = omap2_dispc_supported_color_modes,
  3562. .num_mgrs = 2,
  3563. .num_ovls = 3,
  3564. .buffer_size_unit = 1,
  3565. .burst_size_unit = 8,
  3566. .no_framedone_tv = true,
  3567. .set_max_preload = false,
  3568. .last_pixel_inc_missing = true,
  3569. };
  3570. static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
  3571. .sw_start = 5,
  3572. .fp_start = 15,
  3573. .bp_start = 27,
  3574. .sw_max = 64,
  3575. .vp_max = 255,
  3576. .hp_max = 256,
  3577. .mgr_width_start = 10,
  3578. .mgr_height_start = 26,
  3579. .mgr_width_max = 2048,
  3580. .mgr_height_max = 2048,
  3581. .max_lcd_pclk = 173000000,
  3582. .max_tv_pclk = 59000000,
  3583. .max_downscale = 4,
  3584. .max_line_width = 1024,
  3585. .min_pcd = 1,
  3586. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3587. .calc_core_clk = calc_core_clk_34xx,
  3588. .num_fifos = 3,
  3589. .features = omap3_dispc_features_list,
  3590. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3591. .reg_fields = omap3_dispc_reg_fields,
  3592. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3593. .overlay_caps = omap3430_dispc_overlay_caps,
  3594. .supported_color_modes = omap3_dispc_supported_color_modes,
  3595. .num_mgrs = 2,
  3596. .num_ovls = 3,
  3597. .buffer_size_unit = 1,
  3598. .burst_size_unit = 8,
  3599. .no_framedone_tv = true,
  3600. .set_max_preload = false,
  3601. .last_pixel_inc_missing = true,
  3602. };
  3603. static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
  3604. .sw_start = 7,
  3605. .fp_start = 19,
  3606. .bp_start = 31,
  3607. .sw_max = 256,
  3608. .vp_max = 4095,
  3609. .hp_max = 4096,
  3610. .mgr_width_start = 10,
  3611. .mgr_height_start = 26,
  3612. .mgr_width_max = 2048,
  3613. .mgr_height_max = 2048,
  3614. .max_lcd_pclk = 173000000,
  3615. .max_tv_pclk = 59000000,
  3616. .max_downscale = 4,
  3617. .max_line_width = 1024,
  3618. .min_pcd = 1,
  3619. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3620. .calc_core_clk = calc_core_clk_34xx,
  3621. .num_fifos = 3,
  3622. .features = omap3_dispc_features_list,
  3623. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3624. .reg_fields = omap3_dispc_reg_fields,
  3625. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3626. .overlay_caps = omap3430_dispc_overlay_caps,
  3627. .supported_color_modes = omap3_dispc_supported_color_modes,
  3628. .num_mgrs = 2,
  3629. .num_ovls = 3,
  3630. .buffer_size_unit = 1,
  3631. .burst_size_unit = 8,
  3632. .no_framedone_tv = true,
  3633. .set_max_preload = false,
  3634. .last_pixel_inc_missing = true,
  3635. };
  3636. static const struct dispc_features omap36xx_dispc_feats = {
  3637. .sw_start = 7,
  3638. .fp_start = 19,
  3639. .bp_start = 31,
  3640. .sw_max = 256,
  3641. .vp_max = 4095,
  3642. .hp_max = 4096,
  3643. .mgr_width_start = 10,
  3644. .mgr_height_start = 26,
  3645. .mgr_width_max = 2048,
  3646. .mgr_height_max = 2048,
  3647. .max_lcd_pclk = 173000000,
  3648. .max_tv_pclk = 59000000,
  3649. .max_downscale = 4,
  3650. .max_line_width = 1024,
  3651. .min_pcd = 1,
  3652. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3653. .calc_core_clk = calc_core_clk_34xx,
  3654. .num_fifos = 3,
  3655. .features = omap3_dispc_features_list,
  3656. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3657. .reg_fields = omap3_dispc_reg_fields,
  3658. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3659. .overlay_caps = omap3630_dispc_overlay_caps,
  3660. .supported_color_modes = omap3_dispc_supported_color_modes,
  3661. .num_mgrs = 2,
  3662. .num_ovls = 3,
  3663. .buffer_size_unit = 1,
  3664. .burst_size_unit = 8,
  3665. .no_framedone_tv = true,
  3666. .set_max_preload = false,
  3667. .last_pixel_inc_missing = true,
  3668. };
  3669. static const struct dispc_features am43xx_dispc_feats = {
  3670. .sw_start = 7,
  3671. .fp_start = 19,
  3672. .bp_start = 31,
  3673. .sw_max = 256,
  3674. .vp_max = 4095,
  3675. .hp_max = 4096,
  3676. .mgr_width_start = 10,
  3677. .mgr_height_start = 26,
  3678. .mgr_width_max = 2048,
  3679. .mgr_height_max = 2048,
  3680. .max_lcd_pclk = 173000000,
  3681. .max_tv_pclk = 59000000,
  3682. .max_downscale = 4,
  3683. .max_line_width = 1024,
  3684. .min_pcd = 1,
  3685. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3686. .calc_core_clk = calc_core_clk_34xx,
  3687. .num_fifos = 3,
  3688. .features = am43xx_dispc_features_list,
  3689. .num_features = ARRAY_SIZE(am43xx_dispc_features_list),
  3690. .reg_fields = omap3_dispc_reg_fields,
  3691. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3692. .overlay_caps = omap3430_dispc_overlay_caps,
  3693. .supported_color_modes = omap3_dispc_supported_color_modes,
  3694. .num_mgrs = 1,
  3695. .num_ovls = 3,
  3696. .buffer_size_unit = 1,
  3697. .burst_size_unit = 8,
  3698. .no_framedone_tv = true,
  3699. .set_max_preload = false,
  3700. .last_pixel_inc_missing = true,
  3701. };
  3702. static const struct dispc_features omap44xx_dispc_feats = {
  3703. .sw_start = 7,
  3704. .fp_start = 19,
  3705. .bp_start = 31,
  3706. .sw_max = 256,
  3707. .vp_max = 4095,
  3708. .hp_max = 4096,
  3709. .mgr_width_start = 10,
  3710. .mgr_height_start = 26,
  3711. .mgr_width_max = 2048,
  3712. .mgr_height_max = 2048,
  3713. .max_lcd_pclk = 170000000,
  3714. .max_tv_pclk = 185625000,
  3715. .max_downscale = 4,
  3716. .max_line_width = 2048,
  3717. .min_pcd = 1,
  3718. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3719. .calc_core_clk = calc_core_clk_44xx,
  3720. .num_fifos = 5,
  3721. .features = omap4_dispc_features_list,
  3722. .num_features = ARRAY_SIZE(omap4_dispc_features_list),
  3723. .reg_fields = omap4_dispc_reg_fields,
  3724. .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
  3725. .overlay_caps = omap4_dispc_overlay_caps,
  3726. .supported_color_modes = omap4_dispc_supported_color_modes,
  3727. .num_mgrs = 3,
  3728. .num_ovls = 4,
  3729. .buffer_size_unit = 16,
  3730. .burst_size_unit = 16,
  3731. .gfx_fifo_workaround = true,
  3732. .set_max_preload = true,
  3733. .supports_sync_align = true,
  3734. .has_writeback = true,
  3735. .supports_double_pixel = true,
  3736. .reverse_ilace_field_order = true,
  3737. .has_gamma_table = true,
  3738. .has_gamma_i734_bug = true,
  3739. };
  3740. static const struct dispc_features omap54xx_dispc_feats = {
  3741. .sw_start = 7,
  3742. .fp_start = 19,
  3743. .bp_start = 31,
  3744. .sw_max = 256,
  3745. .vp_max = 4095,
  3746. .hp_max = 4096,
  3747. .mgr_width_start = 11,
  3748. .mgr_height_start = 27,
  3749. .mgr_width_max = 4096,
  3750. .mgr_height_max = 4096,
  3751. .max_lcd_pclk = 170000000,
  3752. .max_tv_pclk = 186000000,
  3753. .max_downscale = 4,
  3754. .max_line_width = 2048,
  3755. .min_pcd = 1,
  3756. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3757. .calc_core_clk = calc_core_clk_44xx,
  3758. .num_fifos = 5,
  3759. .features = omap5_dispc_features_list,
  3760. .num_features = ARRAY_SIZE(omap5_dispc_features_list),
  3761. .reg_fields = omap4_dispc_reg_fields,
  3762. .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
  3763. .overlay_caps = omap4_dispc_overlay_caps,
  3764. .supported_color_modes = omap4_dispc_supported_color_modes,
  3765. .num_mgrs = 4,
  3766. .num_ovls = 4,
  3767. .buffer_size_unit = 16,
  3768. .burst_size_unit = 16,
  3769. .gfx_fifo_workaround = true,
  3770. .mstandby_workaround = true,
  3771. .set_max_preload = true,
  3772. .supports_sync_align = true,
  3773. .has_writeback = true,
  3774. .supports_double_pixel = true,
  3775. .reverse_ilace_field_order = true,
  3776. .has_gamma_table = true,
  3777. .has_gamma_i734_bug = true,
  3778. };
  3779. static irqreturn_t dispc_irq_handler(int irq, void *arg)
  3780. {
  3781. struct dispc_device *dispc = arg;
  3782. if (!dispc->is_enabled)
  3783. return IRQ_NONE;
  3784. return dispc->user_handler(irq, dispc->user_data);
  3785. }
  3786. static int dispc_request_irq(struct dispc_device *dispc, irq_handler_t handler,
  3787. void *dev_id)
  3788. {
  3789. int r;
  3790. if (dispc->user_handler != NULL)
  3791. return -EBUSY;
  3792. dispc->user_handler = handler;
  3793. dispc->user_data = dev_id;
  3794. /* ensure the dispc_irq_handler sees the values above */
  3795. smp_wmb();
  3796. r = devm_request_irq(&dispc->pdev->dev, dispc->irq, dispc_irq_handler,
  3797. IRQF_SHARED, "OMAP DISPC", dispc);
  3798. if (r) {
  3799. dispc->user_handler = NULL;
  3800. dispc->user_data = NULL;
  3801. }
  3802. return r;
  3803. }
  3804. static void dispc_free_irq(struct dispc_device *dispc, void *dev_id)
  3805. {
  3806. devm_free_irq(&dispc->pdev->dev, dispc->irq, dispc);
  3807. dispc->user_handler = NULL;
  3808. dispc->user_data = NULL;
  3809. }
  3810. static u32 dispc_get_memory_bandwidth_limit(struct dispc_device *dispc)
  3811. {
  3812. u32 limit = 0;
  3813. /* Optional maximum memory bandwidth */
  3814. of_property_read_u32(dispc->pdev->dev.of_node, "max-memory-bandwidth",
  3815. &limit);
  3816. return limit;
  3817. }
  3818. /*
  3819. * Workaround for errata i734 in DSS dispc
  3820. * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
  3821. *
  3822. * For gamma tables to work on LCD1 the GFX plane has to be used at
  3823. * least once after DSS HW has come out of reset. The workaround
  3824. * sets up a minimal LCD setup with GFX plane and waits for one
  3825. * vertical sync irq before disabling the setup and continuing with
  3826. * the context restore. The physical outputs are gated during the
  3827. * operation. This workaround requires that gamma table's LOADMODE
  3828. * is set to 0x2 in DISPC_CONTROL1 register.
  3829. *
  3830. * For details see:
  3831. * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
  3832. * Literature Number: SWPZ037E
  3833. * Or some other relevant errata document for the DSS IP version.
  3834. */
  3835. static const struct dispc_errata_i734_data {
  3836. struct videomode vm;
  3837. struct omap_overlay_info ovli;
  3838. struct omap_overlay_manager_info mgri;
  3839. struct dss_lcd_mgr_config lcd_conf;
  3840. } i734 = {
  3841. .vm = {
  3842. .hactive = 8, .vactive = 1,
  3843. .pixelclock = 16000000,
  3844. .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
  3845. .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
  3846. .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
  3847. DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
  3848. DISPLAY_FLAGS_PIXDATA_POSEDGE,
  3849. },
  3850. .ovli = {
  3851. .screen_width = 1,
  3852. .width = 1, .height = 1,
  3853. .fourcc = DRM_FORMAT_XRGB8888,
  3854. .rotation = DRM_MODE_ROTATE_0,
  3855. .rotation_type = OMAP_DSS_ROT_NONE,
  3856. .pos_x = 0, .pos_y = 0,
  3857. .out_width = 0, .out_height = 0,
  3858. .global_alpha = 0xff,
  3859. .pre_mult_alpha = 0,
  3860. .zorder = 0,
  3861. },
  3862. .mgri = {
  3863. .default_color = 0,
  3864. .trans_enabled = false,
  3865. .partial_alpha_enabled = false,
  3866. .cpr_enable = false,
  3867. },
  3868. .lcd_conf = {
  3869. .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
  3870. .stallmode = false,
  3871. .fifohandcheck = false,
  3872. .clock_info = {
  3873. .lck_div = 1,
  3874. .pck_div = 2,
  3875. },
  3876. .video_port_width = 24,
  3877. .lcden_sig_polarity = 0,
  3878. },
  3879. };
  3880. static struct i734_buf {
  3881. size_t size;
  3882. dma_addr_t paddr;
  3883. void *vaddr;
  3884. } i734_buf;
  3885. static int dispc_errata_i734_wa_init(struct dispc_device *dispc)
  3886. {
  3887. if (!dispc->feat->has_gamma_i734_bug)
  3888. return 0;
  3889. i734_buf.size = i734.ovli.width * i734.ovli.height *
  3890. color_mode_to_bpp(i734.ovli.fourcc) / 8;
  3891. i734_buf.vaddr = dma_alloc_writecombine(&dispc->pdev->dev,
  3892. i734_buf.size, &i734_buf.paddr,
  3893. GFP_KERNEL);
  3894. if (!i734_buf.vaddr) {
  3895. dev_err(&dispc->pdev->dev, "%s: dma_alloc_writecombine failed\n",
  3896. __func__);
  3897. return -ENOMEM;
  3898. }
  3899. return 0;
  3900. }
  3901. static void dispc_errata_i734_wa_fini(struct dispc_device *dispc)
  3902. {
  3903. if (!dispc->feat->has_gamma_i734_bug)
  3904. return;
  3905. dma_free_writecombine(&dispc->pdev->dev, i734_buf.size, i734_buf.vaddr,
  3906. i734_buf.paddr);
  3907. }
  3908. static void dispc_errata_i734_wa(struct dispc_device *dispc)
  3909. {
  3910. u32 framedone_irq = dispc_mgr_get_framedone_irq(dispc,
  3911. OMAP_DSS_CHANNEL_LCD);
  3912. struct omap_overlay_info ovli;
  3913. struct dss_lcd_mgr_config lcd_conf;
  3914. u32 gatestate;
  3915. unsigned int count;
  3916. if (!dispc->feat->has_gamma_i734_bug)
  3917. return;
  3918. gatestate = REG_GET(dispc, DISPC_CONFIG, 8, 4);
  3919. ovli = i734.ovli;
  3920. ovli.paddr = i734_buf.paddr;
  3921. lcd_conf = i734.lcd_conf;
  3922. /* Gate all LCD1 outputs */
  3923. REG_FLD_MOD(dispc, DISPC_CONFIG, 0x1f, 8, 4);
  3924. /* Setup and enable GFX plane */
  3925. dispc_ovl_setup(dispc, OMAP_DSS_GFX, &ovli, &i734.vm, false,
  3926. OMAP_DSS_CHANNEL_LCD);
  3927. dispc_ovl_enable(dispc, OMAP_DSS_GFX, true);
  3928. /* Set up and enable display manager for LCD1 */
  3929. dispc_mgr_setup(dispc, OMAP_DSS_CHANNEL_LCD, &i734.mgri);
  3930. dispc_calc_clock_rates(dispc, dss_get_dispc_clk_rate(dispc->dss),
  3931. &lcd_conf.clock_info);
  3932. dispc_mgr_set_lcd_config(dispc, OMAP_DSS_CHANNEL_LCD, &lcd_conf);
  3933. dispc_mgr_set_timings(dispc, OMAP_DSS_CHANNEL_LCD, &i734.vm);
  3934. dispc_clear_irqstatus(dispc, framedone_irq);
  3935. /* Enable and shut the channel to produce just one frame */
  3936. dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, true);
  3937. dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, false);
  3938. /* Busy wait for framedone. We can't fiddle with irq handlers
  3939. * in PM resume. Typically the loop runs less than 5 times and
  3940. * waits less than a micro second.
  3941. */
  3942. count = 0;
  3943. while (!(dispc_read_irqstatus(dispc) & framedone_irq)) {
  3944. if (count++ > 10000) {
  3945. dev_err(&dispc->pdev->dev, "%s: framedone timeout\n",
  3946. __func__);
  3947. break;
  3948. }
  3949. }
  3950. dispc_ovl_enable(dispc, OMAP_DSS_GFX, false);
  3951. /* Clear all irq bits before continuing */
  3952. dispc_clear_irqstatus(dispc, 0xffffffff);
  3953. /* Restore the original state to LCD1 output gates */
  3954. REG_FLD_MOD(dispc, DISPC_CONFIG, gatestate, 8, 4);
  3955. }
  3956. static const struct dispc_ops dispc_ops = {
  3957. .read_irqstatus = dispc_read_irqstatus,
  3958. .clear_irqstatus = dispc_clear_irqstatus,
  3959. .write_irqenable = dispc_write_irqenable,
  3960. .request_irq = dispc_request_irq,
  3961. .free_irq = dispc_free_irq,
  3962. .runtime_get = dispc_runtime_get,
  3963. .runtime_put = dispc_runtime_put,
  3964. .get_num_ovls = dispc_get_num_ovls,
  3965. .get_num_mgrs = dispc_get_num_mgrs,
  3966. .get_memory_bandwidth_limit = dispc_get_memory_bandwidth_limit,
  3967. .mgr_enable = dispc_mgr_enable,
  3968. .mgr_is_enabled = dispc_mgr_is_enabled,
  3969. .mgr_get_vsync_irq = dispc_mgr_get_vsync_irq,
  3970. .mgr_get_framedone_irq = dispc_mgr_get_framedone_irq,
  3971. .mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq,
  3972. .mgr_go_busy = dispc_mgr_go_busy,
  3973. .mgr_go = dispc_mgr_go,
  3974. .mgr_set_lcd_config = dispc_mgr_set_lcd_config,
  3975. .mgr_set_timings = dispc_mgr_set_timings,
  3976. .mgr_setup = dispc_mgr_setup,
  3977. .mgr_get_supported_outputs = dispc_mgr_get_supported_outputs,
  3978. .mgr_gamma_size = dispc_mgr_gamma_size,
  3979. .mgr_set_gamma = dispc_mgr_set_gamma,
  3980. .ovl_enable = dispc_ovl_enable,
  3981. .ovl_setup = dispc_ovl_setup,
  3982. .ovl_get_color_modes = dispc_ovl_get_color_modes,
  3983. .wb_get_framedone_irq = dispc_wb_get_framedone_irq,
  3984. .wb_setup = dispc_wb_setup,
  3985. .has_writeback = dispc_has_writeback,
  3986. .wb_go_busy = dispc_wb_go_busy,
  3987. .wb_go = dispc_wb_go,
  3988. };
  3989. /* DISPC HW IP initialisation */
  3990. static const struct of_device_id dispc_of_match[] = {
  3991. { .compatible = "ti,omap2-dispc", .data = &omap24xx_dispc_feats },
  3992. { .compatible = "ti,omap3-dispc", .data = &omap36xx_dispc_feats },
  3993. { .compatible = "ti,omap4-dispc", .data = &omap44xx_dispc_feats },
  3994. { .compatible = "ti,omap5-dispc", .data = &omap54xx_dispc_feats },
  3995. { .compatible = "ti,dra7-dispc", .data = &omap54xx_dispc_feats },
  3996. {},
  3997. };
  3998. static const struct soc_device_attribute dispc_soc_devices[] = {
  3999. { .machine = "OMAP3[45]*",
  4000. .revision = "ES[12].?", .data = &omap34xx_rev1_0_dispc_feats },
  4001. { .machine = "OMAP3[45]*", .data = &omap34xx_rev3_0_dispc_feats },
  4002. { .machine = "AM35*", .data = &omap34xx_rev3_0_dispc_feats },
  4003. { .machine = "AM43*", .data = &am43xx_dispc_feats },
  4004. { /* sentinel */ }
  4005. };
  4006. static int dispc_bind(struct device *dev, struct device *master, void *data)
  4007. {
  4008. struct platform_device *pdev = to_platform_device(dev);
  4009. const struct soc_device_attribute *soc;
  4010. struct dss_device *dss = dss_get_device(master);
  4011. struct dispc_device *dispc;
  4012. u32 rev;
  4013. int r = 0;
  4014. struct resource *dispc_mem;
  4015. struct device_node *np = pdev->dev.of_node;
  4016. dispc = kzalloc(sizeof(*dispc), GFP_KERNEL);
  4017. if (!dispc)
  4018. return -ENOMEM;
  4019. dispc->pdev = pdev;
  4020. platform_set_drvdata(pdev, dispc);
  4021. dispc->dss = dss;
  4022. spin_lock_init(&dispc->control_lock);
  4023. /*
  4024. * The OMAP3-based models can't be told apart using the compatible
  4025. * string, use SoC device matching.
  4026. */
  4027. soc = soc_device_match(dispc_soc_devices);
  4028. if (soc)
  4029. dispc->feat = soc->data;
  4030. else
  4031. dispc->feat = of_match_device(dispc_of_match, &pdev->dev)->data;
  4032. r = dispc_errata_i734_wa_init(dispc);
  4033. if (r)
  4034. goto err_free;
  4035. dispc_mem = platform_get_resource(dispc->pdev, IORESOURCE_MEM, 0);
  4036. dispc->base = devm_ioremap_resource(&pdev->dev, dispc_mem);
  4037. if (IS_ERR(dispc->base)) {
  4038. r = PTR_ERR(dispc->base);
  4039. goto err_free;
  4040. }
  4041. dispc->irq = platform_get_irq(dispc->pdev, 0);
  4042. if (dispc->irq < 0) {
  4043. DSSERR("platform_get_irq failed\n");
  4044. r = -ENODEV;
  4045. goto err_free;
  4046. }
  4047. if (np && of_property_read_bool(np, "syscon-pol")) {
  4048. dispc->syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
  4049. if (IS_ERR(dispc->syscon_pol)) {
  4050. dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
  4051. r = PTR_ERR(dispc->syscon_pol);
  4052. goto err_free;
  4053. }
  4054. if (of_property_read_u32_index(np, "syscon-pol", 1,
  4055. &dispc->syscon_pol_offset)) {
  4056. dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
  4057. r = -EINVAL;
  4058. goto err_free;
  4059. }
  4060. }
  4061. r = dispc_init_gamma_tables(dispc);
  4062. if (r)
  4063. goto err_free;
  4064. pm_runtime_enable(&pdev->dev);
  4065. r = dispc_runtime_get(dispc);
  4066. if (r)
  4067. goto err_runtime_get;
  4068. _omap_dispc_initial_config(dispc);
  4069. rev = dispc_read_reg(dispc, DISPC_REVISION);
  4070. dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
  4071. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  4072. dispc_runtime_put(dispc);
  4073. dss->dispc = dispc;
  4074. dss->dispc_ops = &dispc_ops;
  4075. dispc->debugfs = dss_debugfs_create_file(dss, "dispc", dispc_dump_regs,
  4076. dispc);
  4077. return 0;
  4078. err_runtime_get:
  4079. pm_runtime_disable(&pdev->dev);
  4080. err_free:
  4081. kfree(dispc);
  4082. return r;
  4083. }
  4084. static void dispc_unbind(struct device *dev, struct device *master, void *data)
  4085. {
  4086. struct dispc_device *dispc = dev_get_drvdata(dev);
  4087. struct dss_device *dss = dispc->dss;
  4088. dss_debugfs_remove_file(dispc->debugfs);
  4089. dss->dispc = NULL;
  4090. dss->dispc_ops = NULL;
  4091. pm_runtime_disable(dev);
  4092. dispc_errata_i734_wa_fini(dispc);
  4093. kfree(dispc);
  4094. }
  4095. static const struct component_ops dispc_component_ops = {
  4096. .bind = dispc_bind,
  4097. .unbind = dispc_unbind,
  4098. };
  4099. static int dispc_probe(struct platform_device *pdev)
  4100. {
  4101. return component_add(&pdev->dev, &dispc_component_ops);
  4102. }
  4103. static int dispc_remove(struct platform_device *pdev)
  4104. {
  4105. component_del(&pdev->dev, &dispc_component_ops);
  4106. return 0;
  4107. }
  4108. static int dispc_runtime_suspend(struct device *dev)
  4109. {
  4110. struct dispc_device *dispc = dev_get_drvdata(dev);
  4111. dispc->is_enabled = false;
  4112. /* ensure the dispc_irq_handler sees the is_enabled value */
  4113. smp_wmb();
  4114. /* wait for current handler to finish before turning the DISPC off */
  4115. synchronize_irq(dispc->irq);
  4116. dispc_save_context(dispc);
  4117. return 0;
  4118. }
  4119. static int dispc_runtime_resume(struct device *dev)
  4120. {
  4121. struct dispc_device *dispc = dev_get_drvdata(dev);
  4122. /*
  4123. * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
  4124. * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
  4125. * _omap_dispc_initial_config(). We can thus use it to detect if
  4126. * we have lost register context.
  4127. */
  4128. if (REG_GET(dispc, DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
  4129. _omap_dispc_initial_config(dispc);
  4130. dispc_errata_i734_wa(dispc);
  4131. dispc_restore_context(dispc);
  4132. dispc_restore_gamma_tables(dispc);
  4133. }
  4134. dispc->is_enabled = true;
  4135. /* ensure the dispc_irq_handler sees the is_enabled value */
  4136. smp_wmb();
  4137. return 0;
  4138. }
  4139. static const struct dev_pm_ops dispc_pm_ops = {
  4140. .runtime_suspend = dispc_runtime_suspend,
  4141. .runtime_resume = dispc_runtime_resume,
  4142. };
  4143. struct platform_driver omap_dispchw_driver = {
  4144. .probe = dispc_probe,
  4145. .remove = dispc_remove,
  4146. .driver = {
  4147. .name = "omapdss_dispc",
  4148. .pm = &dispc_pm_ops,
  4149. .of_match_table = dispc_of_match,
  4150. .suppress_bind_attrs = true,
  4151. },
  4152. };