dispc.c 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951
  1. /*
  2. * Copyright (C) 2009 Nokia Corporation
  3. * Author: Tomi Valkeinen <tomi.valkeinen@ti.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 void dispc_ovl_configure_burst_type(struct dispc_device *dispc,
  964. enum omap_plane_id plane,
  965. enum omap_dss_rotation_type rotation)
  966. {
  967. if (dispc_has_feature(dispc, FEAT_BURST_2D) == 0)
  968. return;
  969. if (rotation == OMAP_DSS_ROT_TILER)
  970. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
  971. else
  972. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
  973. }
  974. static void dispc_ovl_set_channel_out(struct dispc_device *dispc,
  975. enum omap_plane_id plane,
  976. enum omap_channel channel)
  977. {
  978. int shift;
  979. u32 val;
  980. int chan = 0, chan2 = 0;
  981. switch (plane) {
  982. case OMAP_DSS_GFX:
  983. shift = 8;
  984. break;
  985. case OMAP_DSS_VIDEO1:
  986. case OMAP_DSS_VIDEO2:
  987. case OMAP_DSS_VIDEO3:
  988. shift = 16;
  989. break;
  990. default:
  991. BUG();
  992. return;
  993. }
  994. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  995. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  996. switch (channel) {
  997. case OMAP_DSS_CHANNEL_LCD:
  998. chan = 0;
  999. chan2 = 0;
  1000. break;
  1001. case OMAP_DSS_CHANNEL_DIGIT:
  1002. chan = 1;
  1003. chan2 = 0;
  1004. break;
  1005. case OMAP_DSS_CHANNEL_LCD2:
  1006. chan = 0;
  1007. chan2 = 1;
  1008. break;
  1009. case OMAP_DSS_CHANNEL_LCD3:
  1010. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  1011. chan = 0;
  1012. chan2 = 2;
  1013. } else {
  1014. BUG();
  1015. return;
  1016. }
  1017. break;
  1018. case OMAP_DSS_CHANNEL_WB:
  1019. chan = 0;
  1020. chan2 = 3;
  1021. break;
  1022. default:
  1023. BUG();
  1024. return;
  1025. }
  1026. val = FLD_MOD(val, chan, shift, shift);
  1027. val = FLD_MOD(val, chan2, 31, 30);
  1028. } else {
  1029. val = FLD_MOD(val, channel, shift, shift);
  1030. }
  1031. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
  1032. }
  1033. static enum omap_channel dispc_ovl_get_channel_out(struct dispc_device *dispc,
  1034. enum omap_plane_id plane)
  1035. {
  1036. int shift;
  1037. u32 val;
  1038. switch (plane) {
  1039. case OMAP_DSS_GFX:
  1040. shift = 8;
  1041. break;
  1042. case OMAP_DSS_VIDEO1:
  1043. case OMAP_DSS_VIDEO2:
  1044. case OMAP_DSS_VIDEO3:
  1045. shift = 16;
  1046. break;
  1047. default:
  1048. BUG();
  1049. return 0;
  1050. }
  1051. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1052. if (FLD_GET(val, shift, shift) == 1)
  1053. return OMAP_DSS_CHANNEL_DIGIT;
  1054. if (!dispc_has_feature(dispc, FEAT_MGR_LCD2))
  1055. return OMAP_DSS_CHANNEL_LCD;
  1056. switch (FLD_GET(val, 31, 30)) {
  1057. case 0:
  1058. default:
  1059. return OMAP_DSS_CHANNEL_LCD;
  1060. case 1:
  1061. return OMAP_DSS_CHANNEL_LCD2;
  1062. case 2:
  1063. return OMAP_DSS_CHANNEL_LCD3;
  1064. case 3:
  1065. return OMAP_DSS_CHANNEL_WB;
  1066. }
  1067. }
  1068. static void dispc_ovl_set_burst_size(struct dispc_device *dispc,
  1069. enum omap_plane_id plane,
  1070. enum omap_burst_size burst_size)
  1071. {
  1072. static const unsigned int shifts[] = { 6, 14, 14, 14, 14, };
  1073. int shift;
  1074. shift = shifts[plane];
  1075. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), burst_size,
  1076. shift + 1, shift);
  1077. }
  1078. static void dispc_configure_burst_sizes(struct dispc_device *dispc)
  1079. {
  1080. int i;
  1081. const int burst_size = BURST_SIZE_X8;
  1082. /* Configure burst size always to maximum size */
  1083. for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
  1084. dispc_ovl_set_burst_size(dispc, i, burst_size);
  1085. if (dispc->feat->has_writeback)
  1086. dispc_ovl_set_burst_size(dispc, OMAP_DSS_WB, burst_size);
  1087. }
  1088. static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc,
  1089. enum omap_plane_id plane)
  1090. {
  1091. /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
  1092. return dispc->feat->burst_size_unit * 8;
  1093. }
  1094. static bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
  1095. enum omap_plane_id plane, u32 fourcc)
  1096. {
  1097. const u32 *modes;
  1098. unsigned int i;
  1099. modes = dispc->feat->supported_color_modes[plane];
  1100. for (i = 0; modes[i]; ++i) {
  1101. if (modes[i] == fourcc)
  1102. return true;
  1103. }
  1104. return false;
  1105. }
  1106. static const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
  1107. enum omap_plane_id plane)
  1108. {
  1109. return dispc->feat->supported_color_modes[plane];
  1110. }
  1111. static void dispc_mgr_enable_cpr(struct dispc_device *dispc,
  1112. enum omap_channel channel, bool enable)
  1113. {
  1114. if (channel == OMAP_DSS_CHANNEL_DIGIT)
  1115. return;
  1116. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_CPR, enable);
  1117. }
  1118. static void dispc_mgr_set_cpr_coef(struct dispc_device *dispc,
  1119. enum omap_channel channel,
  1120. const struct omap_dss_cpr_coefs *coefs)
  1121. {
  1122. u32 coef_r, coef_g, coef_b;
  1123. if (!dss_mgr_is_lcd(channel))
  1124. return;
  1125. coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
  1126. FLD_VAL(coefs->rb, 9, 0);
  1127. coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
  1128. FLD_VAL(coefs->gb, 9, 0);
  1129. coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
  1130. FLD_VAL(coefs->bb, 9, 0);
  1131. dispc_write_reg(dispc, DISPC_CPR_COEF_R(channel), coef_r);
  1132. dispc_write_reg(dispc, DISPC_CPR_COEF_G(channel), coef_g);
  1133. dispc_write_reg(dispc, DISPC_CPR_COEF_B(channel), coef_b);
  1134. }
  1135. static void dispc_ovl_set_vid_color_conv(struct dispc_device *dispc,
  1136. enum omap_plane_id plane, bool enable)
  1137. {
  1138. u32 val;
  1139. BUG_ON(plane == OMAP_DSS_GFX);
  1140. val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1141. val = FLD_MOD(val, enable, 9, 9);
  1142. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
  1143. }
  1144. static void dispc_ovl_enable_replication(struct dispc_device *dispc,
  1145. enum omap_plane_id plane,
  1146. enum omap_overlay_caps caps,
  1147. bool enable)
  1148. {
  1149. static const unsigned int shifts[] = { 5, 10, 10, 10 };
  1150. int shift;
  1151. if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
  1152. return;
  1153. shift = shifts[plane];
  1154. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
  1155. }
  1156. static void dispc_mgr_set_size(struct dispc_device *dispc,
  1157. enum omap_channel channel, u16 width, u16 height)
  1158. {
  1159. u32 val;
  1160. val = FLD_VAL(height - 1, dispc->feat->mgr_height_start, 16) |
  1161. FLD_VAL(width - 1, dispc->feat->mgr_width_start, 0);
  1162. dispc_write_reg(dispc, DISPC_SIZE_MGR(channel), val);
  1163. }
  1164. static void dispc_init_fifos(struct dispc_device *dispc)
  1165. {
  1166. u32 size;
  1167. int fifo;
  1168. u8 start, end;
  1169. u32 unit;
  1170. int i;
  1171. unit = dispc->feat->buffer_size_unit;
  1172. dispc_get_reg_field(dispc, FEAT_REG_FIFOSIZE, &start, &end);
  1173. for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
  1174. size = REG_GET(dispc, DISPC_OVL_FIFO_SIZE_STATUS(fifo),
  1175. start, end);
  1176. size *= unit;
  1177. dispc->fifo_size[fifo] = size;
  1178. /*
  1179. * By default fifos are mapped directly to overlays, fifo 0 to
  1180. * ovl 0, fifo 1 to ovl 1, etc.
  1181. */
  1182. dispc->fifo_assignment[fifo] = fifo;
  1183. }
  1184. /*
  1185. * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
  1186. * causes problems with certain use cases, like using the tiler in 2D
  1187. * mode. The below hack swaps the fifos of GFX and WB planes, thus
  1188. * giving GFX plane a larger fifo. WB but should work fine with a
  1189. * smaller fifo.
  1190. */
  1191. if (dispc->feat->gfx_fifo_workaround) {
  1192. u32 v;
  1193. v = dispc_read_reg(dispc, DISPC_GLOBAL_BUFFER);
  1194. v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
  1195. v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
  1196. v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
  1197. v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
  1198. dispc_write_reg(dispc, DISPC_GLOBAL_BUFFER, v);
  1199. dispc->fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
  1200. dispc->fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
  1201. }
  1202. /*
  1203. * Setup default fifo thresholds.
  1204. */
  1205. for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
  1206. u32 low, high;
  1207. const bool use_fifomerge = false;
  1208. const bool manual_update = false;
  1209. dispc_ovl_compute_fifo_thresholds(dispc, i, &low, &high,
  1210. use_fifomerge, manual_update);
  1211. dispc_ovl_set_fifo_threshold(dispc, i, low, high);
  1212. }
  1213. if (dispc->feat->has_writeback) {
  1214. u32 low, high;
  1215. const bool use_fifomerge = false;
  1216. const bool manual_update = false;
  1217. dispc_ovl_compute_fifo_thresholds(dispc, OMAP_DSS_WB,
  1218. &low, &high, use_fifomerge,
  1219. manual_update);
  1220. dispc_ovl_set_fifo_threshold(dispc, OMAP_DSS_WB, low, high);
  1221. }
  1222. }
  1223. static u32 dispc_ovl_get_fifo_size(struct dispc_device *dispc,
  1224. enum omap_plane_id plane)
  1225. {
  1226. int fifo;
  1227. u32 size = 0;
  1228. for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
  1229. if (dispc->fifo_assignment[fifo] == plane)
  1230. size += dispc->fifo_size[fifo];
  1231. }
  1232. return size;
  1233. }
  1234. void dispc_ovl_set_fifo_threshold(struct dispc_device *dispc,
  1235. enum omap_plane_id plane,
  1236. u32 low, u32 high)
  1237. {
  1238. u8 hi_start, hi_end, lo_start, lo_end;
  1239. u32 unit;
  1240. unit = dispc->feat->buffer_size_unit;
  1241. WARN_ON(low % unit != 0);
  1242. WARN_ON(high % unit != 0);
  1243. low /= unit;
  1244. high /= unit;
  1245. dispc_get_reg_field(dispc, FEAT_REG_FIFOHIGHTHRESHOLD,
  1246. &hi_start, &hi_end);
  1247. dispc_get_reg_field(dispc, FEAT_REG_FIFOLOWTHRESHOLD,
  1248. &lo_start, &lo_end);
  1249. DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
  1250. plane,
  1251. REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1252. lo_start, lo_end) * unit,
  1253. REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1254. hi_start, hi_end) * unit,
  1255. low * unit, high * unit);
  1256. dispc_write_reg(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
  1257. FLD_VAL(high, hi_start, hi_end) |
  1258. FLD_VAL(low, lo_start, lo_end));
  1259. /*
  1260. * configure the preload to the pipeline's high threhold, if HT it's too
  1261. * large for the preload field, set the threshold to the maximum value
  1262. * that can be held by the preload register
  1263. */
  1264. if (dispc_has_feature(dispc, FEAT_PRELOAD) &&
  1265. dispc->feat->set_max_preload && plane != OMAP_DSS_WB)
  1266. dispc_write_reg(dispc, DISPC_OVL_PRELOAD(plane),
  1267. min(high, 0xfffu));
  1268. }
  1269. void dispc_enable_fifomerge(struct dispc_device *dispc, bool enable)
  1270. {
  1271. if (!dispc_has_feature(dispc, FEAT_FIFO_MERGE)) {
  1272. WARN_ON(enable);
  1273. return;
  1274. }
  1275. DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
  1276. REG_FLD_MOD(dispc, DISPC_CONFIG, enable ? 1 : 0, 14, 14);
  1277. }
  1278. void dispc_ovl_compute_fifo_thresholds(struct dispc_device *dispc,
  1279. enum omap_plane_id plane,
  1280. u32 *fifo_low, u32 *fifo_high,
  1281. bool use_fifomerge, bool manual_update)
  1282. {
  1283. /*
  1284. * All sizes are in bytes. Both the buffer and burst are made of
  1285. * buffer_units, and the fifo thresholds must be buffer_unit aligned.
  1286. */
  1287. unsigned int buf_unit = dispc->feat->buffer_size_unit;
  1288. unsigned int ovl_fifo_size, total_fifo_size, burst_size;
  1289. int i;
  1290. burst_size = dispc_ovl_get_burst_size(dispc, plane);
  1291. ovl_fifo_size = dispc_ovl_get_fifo_size(dispc, plane);
  1292. if (use_fifomerge) {
  1293. total_fifo_size = 0;
  1294. for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
  1295. total_fifo_size += dispc_ovl_get_fifo_size(dispc, i);
  1296. } else {
  1297. total_fifo_size = ovl_fifo_size;
  1298. }
  1299. /*
  1300. * We use the same low threshold for both fifomerge and non-fifomerge
  1301. * cases, but for fifomerge we calculate the high threshold using the
  1302. * combined fifo size
  1303. */
  1304. if (manual_update && dispc_has_feature(dispc, FEAT_OMAP3_DSI_FIFO_BUG)) {
  1305. *fifo_low = ovl_fifo_size - burst_size * 2;
  1306. *fifo_high = total_fifo_size - burst_size;
  1307. } else if (plane == OMAP_DSS_WB) {
  1308. /*
  1309. * Most optimal configuration for writeback is to push out data
  1310. * to the interconnect the moment writeback pushes enough pixels
  1311. * in the FIFO to form a burst
  1312. */
  1313. *fifo_low = 0;
  1314. *fifo_high = burst_size;
  1315. } else {
  1316. *fifo_low = ovl_fifo_size - burst_size;
  1317. *fifo_high = total_fifo_size - buf_unit;
  1318. }
  1319. }
  1320. static void dispc_ovl_set_mflag(struct dispc_device *dispc,
  1321. enum omap_plane_id plane, bool enable)
  1322. {
  1323. int bit;
  1324. if (plane == OMAP_DSS_GFX)
  1325. bit = 14;
  1326. else
  1327. bit = 23;
  1328. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
  1329. }
  1330. static void dispc_ovl_set_mflag_threshold(struct dispc_device *dispc,
  1331. enum omap_plane_id plane,
  1332. int low, int high)
  1333. {
  1334. dispc_write_reg(dispc, DISPC_OVL_MFLAG_THRESHOLD(plane),
  1335. FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
  1336. }
  1337. static void dispc_init_mflag(struct dispc_device *dispc)
  1338. {
  1339. int i;
  1340. /*
  1341. * HACK: NV12 color format and MFLAG seem to have problems working
  1342. * together: using two displays, and having an NV12 overlay on one of
  1343. * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
  1344. * Changing MFLAG thresholds and PRELOAD to certain values seem to
  1345. * remove the errors, but there doesn't seem to be a clear logic on
  1346. * which values work and which not.
  1347. *
  1348. * As a work-around, set force MFLAG to always on.
  1349. */
  1350. dispc_write_reg(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE,
  1351. (1 << 0) | /* MFLAG_CTRL = force always on */
  1352. (0 << 2)); /* MFLAG_START = disable */
  1353. for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
  1354. u32 size = dispc_ovl_get_fifo_size(dispc, i);
  1355. u32 unit = dispc->feat->buffer_size_unit;
  1356. u32 low, high;
  1357. dispc_ovl_set_mflag(dispc, i, true);
  1358. /*
  1359. * Simulation team suggests below thesholds:
  1360. * HT = fifosize * 5 / 8;
  1361. * LT = fifosize * 4 / 8;
  1362. */
  1363. low = size * 4 / 8 / unit;
  1364. high = size * 5 / 8 / unit;
  1365. dispc_ovl_set_mflag_threshold(dispc, i, low, high);
  1366. }
  1367. if (dispc->feat->has_writeback) {
  1368. u32 size = dispc_ovl_get_fifo_size(dispc, OMAP_DSS_WB);
  1369. u32 unit = dispc->feat->buffer_size_unit;
  1370. u32 low, high;
  1371. dispc_ovl_set_mflag(dispc, OMAP_DSS_WB, true);
  1372. /*
  1373. * Simulation team suggests below thesholds:
  1374. * HT = fifosize * 5 / 8;
  1375. * LT = fifosize * 4 / 8;
  1376. */
  1377. low = size * 4 / 8 / unit;
  1378. high = size * 5 / 8 / unit;
  1379. dispc_ovl_set_mflag_threshold(dispc, OMAP_DSS_WB, low, high);
  1380. }
  1381. }
  1382. static void dispc_ovl_set_fir(struct dispc_device *dispc,
  1383. enum omap_plane_id plane,
  1384. int hinc, int vinc,
  1385. enum omap_color_component color_comp)
  1386. {
  1387. u32 val;
  1388. if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
  1389. u8 hinc_start, hinc_end, vinc_start, vinc_end;
  1390. dispc_get_reg_field(dispc, FEAT_REG_FIRHINC,
  1391. &hinc_start, &hinc_end);
  1392. dispc_get_reg_field(dispc, FEAT_REG_FIRVINC,
  1393. &vinc_start, &vinc_end);
  1394. val = FLD_VAL(vinc, vinc_start, vinc_end) |
  1395. FLD_VAL(hinc, hinc_start, hinc_end);
  1396. dispc_write_reg(dispc, DISPC_OVL_FIR(plane), val);
  1397. } else {
  1398. val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
  1399. dispc_write_reg(dispc, DISPC_OVL_FIR2(plane), val);
  1400. }
  1401. }
  1402. static void dispc_ovl_set_vid_accu0(struct dispc_device *dispc,
  1403. enum omap_plane_id plane, int haccu,
  1404. int vaccu)
  1405. {
  1406. u32 val;
  1407. u8 hor_start, hor_end, vert_start, vert_end;
  1408. dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
  1409. &hor_start, &hor_end);
  1410. dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
  1411. &vert_start, &vert_end);
  1412. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1413. FLD_VAL(haccu, hor_start, hor_end);
  1414. dispc_write_reg(dispc, DISPC_OVL_ACCU0(plane), val);
  1415. }
  1416. static void dispc_ovl_set_vid_accu1(struct dispc_device *dispc,
  1417. enum omap_plane_id plane, int haccu,
  1418. int vaccu)
  1419. {
  1420. u32 val;
  1421. u8 hor_start, hor_end, vert_start, vert_end;
  1422. dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
  1423. &hor_start, &hor_end);
  1424. dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
  1425. &vert_start, &vert_end);
  1426. val = FLD_VAL(vaccu, vert_start, vert_end) |
  1427. FLD_VAL(haccu, hor_start, hor_end);
  1428. dispc_write_reg(dispc, DISPC_OVL_ACCU1(plane), val);
  1429. }
  1430. static void dispc_ovl_set_vid_accu2_0(struct dispc_device *dispc,
  1431. enum omap_plane_id plane, int haccu,
  1432. int vaccu)
  1433. {
  1434. u32 val;
  1435. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1436. dispc_write_reg(dispc, DISPC_OVL_ACCU2_0(plane), val);
  1437. }
  1438. static void dispc_ovl_set_vid_accu2_1(struct dispc_device *dispc,
  1439. enum omap_plane_id plane, int haccu,
  1440. int vaccu)
  1441. {
  1442. u32 val;
  1443. val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
  1444. dispc_write_reg(dispc, DISPC_OVL_ACCU2_1(plane), val);
  1445. }
  1446. static void dispc_ovl_set_scale_param(struct dispc_device *dispc,
  1447. enum omap_plane_id plane,
  1448. u16 orig_width, u16 orig_height,
  1449. u16 out_width, u16 out_height,
  1450. bool five_taps, u8 rotation,
  1451. enum omap_color_component color_comp)
  1452. {
  1453. int fir_hinc, fir_vinc;
  1454. fir_hinc = 1024 * orig_width / out_width;
  1455. fir_vinc = 1024 * orig_height / out_height;
  1456. dispc_ovl_set_scale_coef(dispc, plane, fir_hinc, fir_vinc, five_taps,
  1457. color_comp);
  1458. dispc_ovl_set_fir(dispc, plane, fir_hinc, fir_vinc, color_comp);
  1459. }
  1460. static void dispc_ovl_set_accu_uv(struct dispc_device *dispc,
  1461. enum omap_plane_id plane,
  1462. u16 orig_width, u16 orig_height,
  1463. u16 out_width, u16 out_height,
  1464. bool ilace, u32 fourcc, u8 rotation)
  1465. {
  1466. int h_accu2_0, h_accu2_1;
  1467. int v_accu2_0, v_accu2_1;
  1468. int chroma_hinc, chroma_vinc;
  1469. int idx;
  1470. struct accu {
  1471. s8 h0_m, h0_n;
  1472. s8 h1_m, h1_n;
  1473. s8 v0_m, v0_n;
  1474. s8 v1_m, v1_n;
  1475. };
  1476. const struct accu *accu_table;
  1477. const struct accu *accu_val;
  1478. static const struct accu accu_nv12[4] = {
  1479. { 0, 1, 0, 1 , -1, 2, 0, 1 },
  1480. { 1, 2, -3, 4 , 0, 1, 0, 1 },
  1481. { -1, 1, 0, 1 , -1, 2, 0, 1 },
  1482. { -1, 2, -1, 2 , -1, 1, 0, 1 },
  1483. };
  1484. static const struct accu accu_nv12_ilace[4] = {
  1485. { 0, 1, 0, 1 , -3, 4, -1, 4 },
  1486. { -1, 4, -3, 4 , 0, 1, 0, 1 },
  1487. { -1, 1, 0, 1 , -1, 4, -3, 4 },
  1488. { -3, 4, -3, 4 , -1, 1, 0, 1 },
  1489. };
  1490. static const struct accu accu_yuv[4] = {
  1491. { 0, 1, 0, 1, 0, 1, 0, 1 },
  1492. { 0, 1, 0, 1, 0, 1, 0, 1 },
  1493. { -1, 1, 0, 1, 0, 1, 0, 1 },
  1494. { 0, 1, 0, 1, -1, 1, 0, 1 },
  1495. };
  1496. /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
  1497. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1498. default:
  1499. case DRM_MODE_ROTATE_0:
  1500. idx = 0;
  1501. break;
  1502. case DRM_MODE_ROTATE_90:
  1503. idx = 3;
  1504. break;
  1505. case DRM_MODE_ROTATE_180:
  1506. idx = 2;
  1507. break;
  1508. case DRM_MODE_ROTATE_270:
  1509. idx = 1;
  1510. break;
  1511. }
  1512. switch (fourcc) {
  1513. case DRM_FORMAT_NV12:
  1514. if (ilace)
  1515. accu_table = accu_nv12_ilace;
  1516. else
  1517. accu_table = accu_nv12;
  1518. break;
  1519. case DRM_FORMAT_YUYV:
  1520. case DRM_FORMAT_UYVY:
  1521. accu_table = accu_yuv;
  1522. break;
  1523. default:
  1524. BUG();
  1525. return;
  1526. }
  1527. accu_val = &accu_table[idx];
  1528. chroma_hinc = 1024 * orig_width / out_width;
  1529. chroma_vinc = 1024 * orig_height / out_height;
  1530. h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
  1531. h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
  1532. v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
  1533. v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
  1534. dispc_ovl_set_vid_accu2_0(dispc, plane, h_accu2_0, v_accu2_0);
  1535. dispc_ovl_set_vid_accu2_1(dispc, plane, h_accu2_1, v_accu2_1);
  1536. }
  1537. static void dispc_ovl_set_scaling_common(struct dispc_device *dispc,
  1538. enum omap_plane_id plane,
  1539. u16 orig_width, u16 orig_height,
  1540. u16 out_width, u16 out_height,
  1541. bool ilace, bool five_taps,
  1542. bool fieldmode, u32 fourcc,
  1543. u8 rotation)
  1544. {
  1545. int accu0 = 0;
  1546. int accu1 = 0;
  1547. u32 l;
  1548. dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
  1549. out_width, out_height, five_taps,
  1550. rotation, DISPC_COLOR_COMPONENT_RGB_Y);
  1551. l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  1552. /* RESIZEENABLE and VERTICALTAPS */
  1553. l &= ~((0x3 << 5) | (0x1 << 21));
  1554. l |= (orig_width != out_width) ? (1 << 5) : 0;
  1555. l |= (orig_height != out_height) ? (1 << 6) : 0;
  1556. l |= five_taps ? (1 << 21) : 0;
  1557. /* VRESIZECONF and HRESIZECONF */
  1558. if (dispc_has_feature(dispc, FEAT_RESIZECONF)) {
  1559. l &= ~(0x3 << 7);
  1560. l |= (orig_width <= out_width) ? 0 : (1 << 7);
  1561. l |= (orig_height <= out_height) ? 0 : (1 << 8);
  1562. }
  1563. /* LINEBUFFERSPLIT */
  1564. if (dispc_has_feature(dispc, FEAT_LINEBUFFERSPLIT)) {
  1565. l &= ~(0x1 << 22);
  1566. l |= five_taps ? (1 << 22) : 0;
  1567. }
  1568. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
  1569. /*
  1570. * field 0 = even field = bottom field
  1571. * field 1 = odd field = top field
  1572. */
  1573. if (ilace && !fieldmode) {
  1574. accu1 = 0;
  1575. accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
  1576. if (accu0 >= 1024/2) {
  1577. accu1 = 1024/2;
  1578. accu0 -= accu1;
  1579. }
  1580. }
  1581. dispc_ovl_set_vid_accu0(dispc, plane, 0, accu0);
  1582. dispc_ovl_set_vid_accu1(dispc, plane, 0, accu1);
  1583. }
  1584. static void dispc_ovl_set_scaling_uv(struct dispc_device *dispc,
  1585. enum omap_plane_id plane,
  1586. u16 orig_width, u16 orig_height,
  1587. u16 out_width, u16 out_height,
  1588. bool ilace, bool five_taps,
  1589. bool fieldmode, u32 fourcc,
  1590. u8 rotation)
  1591. {
  1592. int scale_x = out_width != orig_width;
  1593. int scale_y = out_height != orig_height;
  1594. bool chroma_upscale = plane != OMAP_DSS_WB;
  1595. const struct drm_format_info *info;
  1596. info = drm_format_info(fourcc);
  1597. if (!dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE))
  1598. return;
  1599. if (!info->is_yuv) {
  1600. /* reset chroma resampling for RGB formats */
  1601. if (plane != OMAP_DSS_WB)
  1602. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
  1603. 0, 8, 8);
  1604. return;
  1605. }
  1606. dispc_ovl_set_accu_uv(dispc, plane, orig_width, orig_height, out_width,
  1607. out_height, ilace, fourcc, rotation);
  1608. switch (fourcc) {
  1609. case DRM_FORMAT_NV12:
  1610. if (chroma_upscale) {
  1611. /* UV is subsampled by 2 horizontally and vertically */
  1612. orig_height >>= 1;
  1613. orig_width >>= 1;
  1614. } else {
  1615. /* UV is downsampled by 2 horizontally and vertically */
  1616. orig_height <<= 1;
  1617. orig_width <<= 1;
  1618. }
  1619. break;
  1620. case DRM_FORMAT_YUYV:
  1621. case DRM_FORMAT_UYVY:
  1622. /* For YUV422 with 90/270 rotation, we don't upsample chroma */
  1623. if (!drm_rotation_90_or_270(rotation)) {
  1624. if (chroma_upscale)
  1625. /* UV is subsampled by 2 horizontally */
  1626. orig_width >>= 1;
  1627. else
  1628. /* UV is downsampled by 2 horizontally */
  1629. orig_width <<= 1;
  1630. }
  1631. /* must use FIR for YUV422 if rotated */
  1632. if ((rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0)
  1633. scale_x = scale_y = true;
  1634. break;
  1635. default:
  1636. BUG();
  1637. return;
  1638. }
  1639. if (out_width != orig_width)
  1640. scale_x = true;
  1641. if (out_height != orig_height)
  1642. scale_y = true;
  1643. dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
  1644. out_width, out_height, five_taps,
  1645. rotation, DISPC_COLOR_COMPONENT_UV);
  1646. if (plane != OMAP_DSS_WB)
  1647. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
  1648. (scale_x || scale_y) ? 1 : 0, 8, 8);
  1649. /* set H scaling */
  1650. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
  1651. /* set V scaling */
  1652. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
  1653. }
  1654. static void dispc_ovl_set_scaling(struct dispc_device *dispc,
  1655. enum omap_plane_id plane,
  1656. u16 orig_width, u16 orig_height,
  1657. u16 out_width, u16 out_height,
  1658. bool ilace, bool five_taps,
  1659. bool fieldmode, u32 fourcc,
  1660. u8 rotation)
  1661. {
  1662. BUG_ON(plane == OMAP_DSS_GFX);
  1663. dispc_ovl_set_scaling_common(dispc, plane, orig_width, orig_height,
  1664. out_width, out_height, ilace, five_taps,
  1665. fieldmode, fourcc, rotation);
  1666. dispc_ovl_set_scaling_uv(dispc, plane, orig_width, orig_height,
  1667. out_width, out_height, ilace, five_taps,
  1668. fieldmode, fourcc, rotation);
  1669. }
  1670. static void dispc_ovl_set_rotation_attrs(struct dispc_device *dispc,
  1671. enum omap_plane_id plane, u8 rotation,
  1672. enum omap_dss_rotation_type rotation_type,
  1673. u32 fourcc)
  1674. {
  1675. bool row_repeat = false;
  1676. int vidrot = 0;
  1677. /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
  1678. if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY) {
  1679. if (rotation & DRM_MODE_REFLECT_X) {
  1680. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1681. case DRM_MODE_ROTATE_0:
  1682. vidrot = 2;
  1683. break;
  1684. case DRM_MODE_ROTATE_90:
  1685. vidrot = 1;
  1686. break;
  1687. case DRM_MODE_ROTATE_180:
  1688. vidrot = 0;
  1689. break;
  1690. case DRM_MODE_ROTATE_270:
  1691. vidrot = 3;
  1692. break;
  1693. }
  1694. } else {
  1695. switch (rotation & DRM_MODE_ROTATE_MASK) {
  1696. case DRM_MODE_ROTATE_0:
  1697. vidrot = 0;
  1698. break;
  1699. case DRM_MODE_ROTATE_90:
  1700. vidrot = 3;
  1701. break;
  1702. case DRM_MODE_ROTATE_180:
  1703. vidrot = 2;
  1704. break;
  1705. case DRM_MODE_ROTATE_270:
  1706. vidrot = 1;
  1707. break;
  1708. }
  1709. }
  1710. if (drm_rotation_90_or_270(rotation))
  1711. row_repeat = true;
  1712. else
  1713. row_repeat = false;
  1714. }
  1715. /*
  1716. * OMAP4/5 Errata i631:
  1717. * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
  1718. * rows beyond the framebuffer, which may cause OCP error.
  1719. */
  1720. if (fourcc == DRM_FORMAT_NV12 && rotation_type != OMAP_DSS_ROT_TILER)
  1721. vidrot = 1;
  1722. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
  1723. if (dispc_has_feature(dispc, FEAT_ROWREPEATENABLE))
  1724. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
  1725. row_repeat ? 1 : 0, 18, 18);
  1726. if (dispc_ovl_color_mode_supported(dispc, plane, DRM_FORMAT_NV12)) {
  1727. bool doublestride =
  1728. fourcc == DRM_FORMAT_NV12 &&
  1729. rotation_type == OMAP_DSS_ROT_TILER &&
  1730. !drm_rotation_90_or_270(rotation);
  1731. /* DOUBLESTRIDE */
  1732. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
  1733. doublestride, 22, 22);
  1734. }
  1735. }
  1736. static int color_mode_to_bpp(u32 fourcc)
  1737. {
  1738. switch (fourcc) {
  1739. case DRM_FORMAT_NV12:
  1740. return 8;
  1741. case DRM_FORMAT_RGBX4444:
  1742. case DRM_FORMAT_RGB565:
  1743. case DRM_FORMAT_ARGB4444:
  1744. case DRM_FORMAT_YUYV:
  1745. case DRM_FORMAT_UYVY:
  1746. case DRM_FORMAT_RGBA4444:
  1747. case DRM_FORMAT_XRGB4444:
  1748. case DRM_FORMAT_ARGB1555:
  1749. case DRM_FORMAT_XRGB1555:
  1750. return 16;
  1751. case DRM_FORMAT_RGB888:
  1752. return 24;
  1753. case DRM_FORMAT_XRGB8888:
  1754. case DRM_FORMAT_ARGB8888:
  1755. case DRM_FORMAT_RGBA8888:
  1756. case DRM_FORMAT_RGBX8888:
  1757. return 32;
  1758. default:
  1759. BUG();
  1760. return 0;
  1761. }
  1762. }
  1763. static s32 pixinc(int pixels, u8 ps)
  1764. {
  1765. if (pixels == 1)
  1766. return 1;
  1767. else if (pixels > 1)
  1768. return 1 + (pixels - 1) * ps;
  1769. else if (pixels < 0)
  1770. return 1 - (-pixels + 1) * ps;
  1771. else
  1772. BUG();
  1773. return 0;
  1774. }
  1775. static void calc_offset(u16 screen_width, u16 width,
  1776. u32 fourcc, bool fieldmode, unsigned int field_offset,
  1777. unsigned int *offset0, unsigned int *offset1,
  1778. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim,
  1779. enum omap_dss_rotation_type rotation_type, u8 rotation)
  1780. {
  1781. u8 ps;
  1782. ps = color_mode_to_bpp(fourcc) / 8;
  1783. DSSDBG("scrw %d, width %d\n", screen_width, width);
  1784. if (rotation_type == OMAP_DSS_ROT_TILER &&
  1785. (fourcc == DRM_FORMAT_UYVY || fourcc == DRM_FORMAT_YUYV) &&
  1786. drm_rotation_90_or_270(rotation)) {
  1787. /*
  1788. * HACK: ROW_INC needs to be calculated with TILER units.
  1789. * We get such 'screen_width' that multiplying it with the
  1790. * YUV422 pixel size gives the correct TILER container width.
  1791. * However, 'width' is in pixels and multiplying it with YUV422
  1792. * pixel size gives incorrect result. We thus multiply it here
  1793. * with 2 to match the 32 bit TILER unit size.
  1794. */
  1795. width *= 2;
  1796. }
  1797. /*
  1798. * field 0 = even field = bottom field
  1799. * field 1 = odd field = top field
  1800. */
  1801. *offset0 = field_offset * screen_width * ps;
  1802. *offset1 = 0;
  1803. *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
  1804. (fieldmode ? screen_width : 0), ps);
  1805. if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY)
  1806. *pix_inc = pixinc(x_predecim, 2 * ps);
  1807. else
  1808. *pix_inc = pixinc(x_predecim, ps);
  1809. }
  1810. /*
  1811. * This function is used to avoid synclosts in OMAP3, because of some
  1812. * undocumented horizontal position and timing related limitations.
  1813. */
  1814. static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
  1815. const struct videomode *vm, u16 pos_x,
  1816. u16 width, u16 height, u16 out_width, u16 out_height,
  1817. bool five_taps)
  1818. {
  1819. const int ds = DIV_ROUND_UP(height, out_height);
  1820. unsigned long nonactive;
  1821. static const u8 limits[3] = { 8, 10, 20 };
  1822. u64 val, blank;
  1823. int i;
  1824. nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
  1825. vm->hback_porch - out_width;
  1826. i = 0;
  1827. if (out_height < height)
  1828. i++;
  1829. if (out_width < width)
  1830. i++;
  1831. blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
  1832. lclk, pclk);
  1833. DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
  1834. if (blank <= limits[i])
  1835. return -EINVAL;
  1836. /* FIXME add checks for 3-tap filter once the limitations are known */
  1837. if (!five_taps)
  1838. return 0;
  1839. /*
  1840. * Pixel data should be prepared before visible display point starts.
  1841. * So, atleast DS-2 lines must have already been fetched by DISPC
  1842. * during nonactive - pos_x period.
  1843. */
  1844. val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
  1845. DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
  1846. val, max(0, ds - 2) * width);
  1847. if (val < max(0, ds - 2) * width)
  1848. return -EINVAL;
  1849. /*
  1850. * All lines need to be refilled during the nonactive period of which
  1851. * only one line can be loaded during the active period. So, atleast
  1852. * DS - 1 lines should be loaded during nonactive period.
  1853. */
  1854. val = div_u64((u64)nonactive * lclk, pclk);
  1855. DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
  1856. val, max(0, ds - 1) * width);
  1857. if (val < max(0, ds - 1) * width)
  1858. return -EINVAL;
  1859. return 0;
  1860. }
  1861. static unsigned long calc_core_clk_five_taps(unsigned long pclk,
  1862. const struct videomode *vm, u16 width,
  1863. u16 height, u16 out_width, u16 out_height,
  1864. u32 fourcc)
  1865. {
  1866. u32 core_clk = 0;
  1867. u64 tmp;
  1868. if (height <= out_height && width <= out_width)
  1869. return (unsigned long) pclk;
  1870. if (height > out_height) {
  1871. unsigned int ppl = vm->hactive;
  1872. tmp = (u64)pclk * height * out_width;
  1873. do_div(tmp, 2 * out_height * ppl);
  1874. core_clk = tmp;
  1875. if (height > 2 * out_height) {
  1876. if (ppl == out_width)
  1877. return 0;
  1878. tmp = (u64)pclk * (height - 2 * out_height) * out_width;
  1879. do_div(tmp, 2 * out_height * (ppl - out_width));
  1880. core_clk = max_t(u32, core_clk, tmp);
  1881. }
  1882. }
  1883. if (width > out_width) {
  1884. tmp = (u64)pclk * width;
  1885. do_div(tmp, out_width);
  1886. core_clk = max_t(u32, core_clk, tmp);
  1887. if (fourcc == DRM_FORMAT_XRGB8888)
  1888. core_clk <<= 1;
  1889. }
  1890. return core_clk;
  1891. }
  1892. static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
  1893. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1894. {
  1895. if (height > out_height && width > out_width)
  1896. return pclk * 4;
  1897. else
  1898. return pclk * 2;
  1899. }
  1900. static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
  1901. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1902. {
  1903. unsigned int hf, vf;
  1904. /*
  1905. * FIXME how to determine the 'A' factor
  1906. * for the no downscaling case ?
  1907. */
  1908. if (width > 3 * out_width)
  1909. hf = 4;
  1910. else if (width > 2 * out_width)
  1911. hf = 3;
  1912. else if (width > out_width)
  1913. hf = 2;
  1914. else
  1915. hf = 1;
  1916. if (height > out_height)
  1917. vf = 2;
  1918. else
  1919. vf = 1;
  1920. return pclk * vf * hf;
  1921. }
  1922. static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
  1923. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1924. {
  1925. /*
  1926. * If the overlay/writeback is in mem to mem mode, there are no
  1927. * downscaling limitations with respect to pixel clock, return 1 as
  1928. * required core clock to represent that we have sufficient enough
  1929. * core clock to do maximum downscaling
  1930. */
  1931. if (mem_to_mem)
  1932. return 1;
  1933. if (width > out_width)
  1934. return DIV_ROUND_UP(pclk, out_width) * width;
  1935. else
  1936. return pclk;
  1937. }
  1938. static int dispc_ovl_calc_scaling_24xx(struct dispc_device *dispc,
  1939. unsigned long pclk, unsigned long lclk,
  1940. const struct videomode *vm,
  1941. u16 width, u16 height,
  1942. u16 out_width, u16 out_height,
  1943. u32 fourcc, bool *five_taps,
  1944. int *x_predecim, int *y_predecim,
  1945. int *decim_x, int *decim_y,
  1946. u16 pos_x, unsigned long *core_clk,
  1947. bool mem_to_mem)
  1948. {
  1949. int error;
  1950. u16 in_width, in_height;
  1951. int min_factor = min(*decim_x, *decim_y);
  1952. const int maxsinglelinewidth = dispc->feat->max_line_width;
  1953. *five_taps = false;
  1954. do {
  1955. in_height = height / *decim_y;
  1956. in_width = width / *decim_x;
  1957. *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
  1958. in_height, out_width, out_height, mem_to_mem);
  1959. error = (in_width > maxsinglelinewidth || !*core_clk ||
  1960. *core_clk > dispc_core_clk_rate(dispc));
  1961. if (error) {
  1962. if (*decim_x == *decim_y) {
  1963. *decim_x = min_factor;
  1964. ++*decim_y;
  1965. } else {
  1966. swap(*decim_x, *decim_y);
  1967. if (*decim_x < *decim_y)
  1968. ++*decim_x;
  1969. }
  1970. }
  1971. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  1972. if (error) {
  1973. DSSERR("failed to find scaling settings\n");
  1974. return -EINVAL;
  1975. }
  1976. if (in_width > maxsinglelinewidth) {
  1977. DSSERR("Cannot scale max input width exceeded\n");
  1978. return -EINVAL;
  1979. }
  1980. return 0;
  1981. }
  1982. static int dispc_ovl_calc_scaling_34xx(struct dispc_device *dispc,
  1983. unsigned long pclk, unsigned long lclk,
  1984. const struct videomode *vm,
  1985. u16 width, u16 height,
  1986. u16 out_width, u16 out_height,
  1987. u32 fourcc, bool *five_taps,
  1988. int *x_predecim, int *y_predecim,
  1989. int *decim_x, int *decim_y,
  1990. u16 pos_x, unsigned long *core_clk,
  1991. bool mem_to_mem)
  1992. {
  1993. int error;
  1994. u16 in_width, in_height;
  1995. const int maxsinglelinewidth = dispc->feat->max_line_width;
  1996. do {
  1997. in_height = height / *decim_y;
  1998. in_width = width / *decim_x;
  1999. *five_taps = in_height > out_height;
  2000. if (in_width > maxsinglelinewidth)
  2001. if (in_height > out_height &&
  2002. in_height < out_height * 2)
  2003. *five_taps = false;
  2004. again:
  2005. if (*five_taps)
  2006. *core_clk = calc_core_clk_five_taps(pclk, vm,
  2007. in_width, in_height, out_width,
  2008. out_height, fourcc);
  2009. else
  2010. *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
  2011. in_height, out_width, out_height,
  2012. mem_to_mem);
  2013. error = check_horiz_timing_omap3(pclk, lclk, vm,
  2014. pos_x, in_width, in_height, out_width,
  2015. out_height, *five_taps);
  2016. if (error && *five_taps) {
  2017. *five_taps = false;
  2018. goto again;
  2019. }
  2020. error = (error || in_width > maxsinglelinewidth * 2 ||
  2021. (in_width > maxsinglelinewidth && *five_taps) ||
  2022. !*core_clk || *core_clk > dispc_core_clk_rate(dispc));
  2023. if (!error) {
  2024. /* verify that we're inside the limits of scaler */
  2025. if (in_width / 4 > out_width)
  2026. error = 1;
  2027. if (*five_taps) {
  2028. if (in_height / 4 > out_height)
  2029. error = 1;
  2030. } else {
  2031. if (in_height / 2 > out_height)
  2032. error = 1;
  2033. }
  2034. }
  2035. if (error)
  2036. ++*decim_y;
  2037. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  2038. if (error) {
  2039. DSSERR("failed to find scaling settings\n");
  2040. return -EINVAL;
  2041. }
  2042. if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
  2043. in_height, out_width, out_height, *five_taps)) {
  2044. DSSERR("horizontal timing too tight\n");
  2045. return -EINVAL;
  2046. }
  2047. if (in_width > (maxsinglelinewidth * 2)) {
  2048. DSSERR("Cannot setup scaling\n");
  2049. DSSERR("width exceeds maximum width possible\n");
  2050. return -EINVAL;
  2051. }
  2052. if (in_width > maxsinglelinewidth && *five_taps) {
  2053. DSSERR("cannot setup scaling with five taps\n");
  2054. return -EINVAL;
  2055. }
  2056. return 0;
  2057. }
  2058. static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc,
  2059. unsigned long pclk, unsigned long lclk,
  2060. const struct videomode *vm,
  2061. u16 width, u16 height,
  2062. u16 out_width, u16 out_height,
  2063. u32 fourcc, bool *five_taps,
  2064. int *x_predecim, int *y_predecim,
  2065. int *decim_x, int *decim_y,
  2066. u16 pos_x, unsigned long *core_clk,
  2067. bool mem_to_mem)
  2068. {
  2069. u16 in_width, in_width_max;
  2070. int decim_x_min = *decim_x;
  2071. u16 in_height = height / *decim_y;
  2072. const int maxsinglelinewidth = dispc->feat->max_line_width;
  2073. const int maxdownscale = dispc->feat->max_downscale;
  2074. if (mem_to_mem) {
  2075. in_width_max = out_width * maxdownscale;
  2076. } else {
  2077. in_width_max = dispc_core_clk_rate(dispc)
  2078. / DIV_ROUND_UP(pclk, out_width);
  2079. }
  2080. *decim_x = DIV_ROUND_UP(width, in_width_max);
  2081. *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
  2082. if (*decim_x > *x_predecim)
  2083. return -EINVAL;
  2084. do {
  2085. in_width = width / *decim_x;
  2086. } while (*decim_x <= *x_predecim &&
  2087. in_width > maxsinglelinewidth && ++*decim_x);
  2088. if (in_width > maxsinglelinewidth) {
  2089. DSSERR("Cannot scale width exceeds max line width\n");
  2090. return -EINVAL;
  2091. }
  2092. if (*decim_x > 4 && fourcc != DRM_FORMAT_NV12) {
  2093. /*
  2094. * Let's disable all scaling that requires horizontal
  2095. * decimation with higher factor than 4, until we have
  2096. * better estimates of what we can and can not
  2097. * do. However, NV12 color format appears to work Ok
  2098. * with all decimation factors.
  2099. *
  2100. * When decimating horizontally by more that 4 the dss
  2101. * is not able to fetch the data in burst mode. When
  2102. * this happens it is hard to tell if there enough
  2103. * bandwidth. Despite what theory says this appears to
  2104. * be true also for 16-bit color formats.
  2105. */
  2106. DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)\n", *decim_x);
  2107. return -EINVAL;
  2108. }
  2109. *core_clk = dispc->feat->calc_core_clk(pclk, in_width, in_height,
  2110. out_width, out_height, mem_to_mem);
  2111. return 0;
  2112. }
  2113. #define DIV_FRAC(dividend, divisor) \
  2114. ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
  2115. static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
  2116. enum omap_plane_id plane,
  2117. unsigned long pclk, unsigned long lclk,
  2118. enum omap_overlay_caps caps,
  2119. const struct videomode *vm,
  2120. u16 width, u16 height,
  2121. u16 out_width, u16 out_height,
  2122. u32 fourcc, bool *five_taps,
  2123. int *x_predecim, int *y_predecim, u16 pos_x,
  2124. enum omap_dss_rotation_type rotation_type,
  2125. bool mem_to_mem)
  2126. {
  2127. int maxhdownscale = dispc->feat->max_downscale;
  2128. int maxvdownscale = dispc->feat->max_downscale;
  2129. const int max_decim_limit = 16;
  2130. unsigned long core_clk = 0;
  2131. int decim_x, decim_y, ret;
  2132. if (width == out_width && height == out_height)
  2133. return 0;
  2134. if (plane == OMAP_DSS_WB) {
  2135. switch (fourcc) {
  2136. case DRM_FORMAT_NV12:
  2137. maxhdownscale = maxvdownscale = 2;
  2138. break;
  2139. case DRM_FORMAT_YUYV:
  2140. case DRM_FORMAT_UYVY:
  2141. maxhdownscale = 2;
  2142. maxvdownscale = 4;
  2143. break;
  2144. default:
  2145. break;
  2146. }
  2147. }
  2148. if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
  2149. DSSERR("cannot calculate scaling settings: pclk is zero\n");
  2150. return -EINVAL;
  2151. }
  2152. if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
  2153. return -EINVAL;
  2154. if (mem_to_mem) {
  2155. *x_predecim = *y_predecim = 1;
  2156. } else {
  2157. *x_predecim = max_decim_limit;
  2158. *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
  2159. dispc_has_feature(dispc, FEAT_BURST_2D)) ?
  2160. 2 : max_decim_limit;
  2161. }
  2162. decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxhdownscale);
  2163. decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxvdownscale);
  2164. if (decim_x > *x_predecim || out_width > width * 8)
  2165. return -EINVAL;
  2166. if (decim_y > *y_predecim || out_height > height * 8)
  2167. return -EINVAL;
  2168. ret = dispc->feat->calc_scaling(dispc, pclk, lclk, vm, width, height,
  2169. out_width, out_height, fourcc,
  2170. five_taps, x_predecim, y_predecim,
  2171. &decim_x, &decim_y, pos_x, &core_clk,
  2172. mem_to_mem);
  2173. if (ret)
  2174. return ret;
  2175. 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",
  2176. width, height,
  2177. out_width, out_height,
  2178. out_width / width, DIV_FRAC(out_width, width),
  2179. out_height / height, DIV_FRAC(out_height, height),
  2180. decim_x, decim_y,
  2181. width / decim_x, height / decim_y,
  2182. out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
  2183. out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
  2184. *five_taps ? 5 : 3,
  2185. core_clk, dispc_core_clk_rate(dispc));
  2186. if (!core_clk || core_clk > dispc_core_clk_rate(dispc)) {
  2187. DSSERR("failed to set up scaling, "
  2188. "required core clk rate = %lu Hz, "
  2189. "current core clk rate = %lu Hz\n",
  2190. core_clk, dispc_core_clk_rate(dispc));
  2191. return -EINVAL;
  2192. }
  2193. *x_predecim = decim_x;
  2194. *y_predecim = decim_y;
  2195. return 0;
  2196. }
  2197. static int dispc_ovl_setup_common(struct dispc_device *dispc,
  2198. enum omap_plane_id plane,
  2199. enum omap_overlay_caps caps,
  2200. u32 paddr, u32 p_uv_addr,
  2201. u16 screen_width, int pos_x, int pos_y,
  2202. u16 width, u16 height,
  2203. u16 out_width, u16 out_height,
  2204. u32 fourcc, u8 rotation, u8 zorder,
  2205. u8 pre_mult_alpha, u8 global_alpha,
  2206. enum omap_dss_rotation_type rotation_type,
  2207. bool replication, const struct videomode *vm,
  2208. bool mem_to_mem)
  2209. {
  2210. bool five_taps = true;
  2211. bool fieldmode = false;
  2212. int r, cconv = 0;
  2213. unsigned int offset0, offset1;
  2214. s32 row_inc;
  2215. s32 pix_inc;
  2216. u16 frame_width;
  2217. unsigned int field_offset = 0;
  2218. u16 in_height = height;
  2219. u16 in_width = width;
  2220. int x_predecim = 1, y_predecim = 1;
  2221. bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
  2222. unsigned long pclk = dispc_plane_pclk_rate(dispc, plane);
  2223. unsigned long lclk = dispc_plane_lclk_rate(dispc, plane);
  2224. const struct drm_format_info *info;
  2225. info = drm_format_info(fourcc);
  2226. /* when setting up WB, dispc_plane_pclk_rate() returns 0 */
  2227. if (plane == OMAP_DSS_WB)
  2228. pclk = vm->pixelclock;
  2229. if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
  2230. return -EINVAL;
  2231. if (info->is_yuv && (in_width & 1)) {
  2232. DSSERR("input width %d is not even for YUV format\n", in_width);
  2233. return -EINVAL;
  2234. }
  2235. out_width = out_width == 0 ? width : out_width;
  2236. out_height = out_height == 0 ? height : out_height;
  2237. if (plane != OMAP_DSS_WB) {
  2238. if (ilace && height == out_height)
  2239. fieldmode = true;
  2240. if (ilace) {
  2241. if (fieldmode)
  2242. in_height /= 2;
  2243. pos_y /= 2;
  2244. out_height /= 2;
  2245. DSSDBG("adjusting for ilace: height %d, pos_y %d, out_height %d\n",
  2246. in_height, pos_y, out_height);
  2247. }
  2248. }
  2249. if (!dispc_ovl_color_mode_supported(dispc, plane, fourcc))
  2250. return -EINVAL;
  2251. r = dispc_ovl_calc_scaling(dispc, plane, pclk, lclk, caps, vm, in_width,
  2252. in_height, out_width, out_height, fourcc,
  2253. &five_taps, &x_predecim, &y_predecim, pos_x,
  2254. rotation_type, mem_to_mem);
  2255. if (r)
  2256. return r;
  2257. in_width = in_width / x_predecim;
  2258. in_height = in_height / y_predecim;
  2259. if (x_predecim > 1 || y_predecim > 1)
  2260. DSSDBG("predecimation %d x %x, new input size %d x %d\n",
  2261. x_predecim, y_predecim, in_width, in_height);
  2262. if (info->is_yuv && (in_width & 1)) {
  2263. DSSDBG("predecimated input width is not even for YUV format\n");
  2264. DSSDBG("adjusting input width %d -> %d\n",
  2265. in_width, in_width & ~1);
  2266. in_width &= ~1;
  2267. }
  2268. if (info->is_yuv)
  2269. cconv = 1;
  2270. if (ilace && !fieldmode) {
  2271. /*
  2272. * when downscaling the bottom field may have to start several
  2273. * source lines below the top field. Unfortunately ACCUI
  2274. * registers will only hold the fractional part of the offset
  2275. * so the integer part must be added to the base address of the
  2276. * bottom field.
  2277. */
  2278. if (!in_height || in_height == out_height)
  2279. field_offset = 0;
  2280. else
  2281. field_offset = in_height / out_height / 2;
  2282. }
  2283. /* Fields are independent but interleaved in memory. */
  2284. if (fieldmode)
  2285. field_offset = 1;
  2286. offset0 = 0;
  2287. offset1 = 0;
  2288. row_inc = 0;
  2289. pix_inc = 0;
  2290. if (plane == OMAP_DSS_WB)
  2291. frame_width = out_width;
  2292. else
  2293. frame_width = in_width;
  2294. calc_offset(screen_width, frame_width,
  2295. fourcc, fieldmode, field_offset,
  2296. &offset0, &offset1, &row_inc, &pix_inc,
  2297. x_predecim, y_predecim,
  2298. rotation_type, rotation);
  2299. DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
  2300. offset0, offset1, row_inc, pix_inc);
  2301. dispc_ovl_set_color_mode(dispc, plane, fourcc);
  2302. dispc_ovl_configure_burst_type(dispc, plane, rotation_type);
  2303. if (dispc->feat->reverse_ilace_field_order)
  2304. swap(offset0, offset1);
  2305. dispc_ovl_set_ba0(dispc, plane, paddr + offset0);
  2306. dispc_ovl_set_ba1(dispc, plane, paddr + offset1);
  2307. if (fourcc == DRM_FORMAT_NV12) {
  2308. dispc_ovl_set_ba0_uv(dispc, plane, p_uv_addr + offset0);
  2309. dispc_ovl_set_ba1_uv(dispc, plane, p_uv_addr + offset1);
  2310. }
  2311. if (dispc->feat->last_pixel_inc_missing)
  2312. row_inc += pix_inc - 1;
  2313. dispc_ovl_set_row_inc(dispc, plane, row_inc);
  2314. dispc_ovl_set_pix_inc(dispc, plane, pix_inc);
  2315. DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
  2316. in_height, out_width, out_height);
  2317. dispc_ovl_set_pos(dispc, plane, caps, pos_x, pos_y);
  2318. dispc_ovl_set_input_size(dispc, plane, in_width, in_height);
  2319. if (caps & OMAP_DSS_OVL_CAP_SCALE) {
  2320. dispc_ovl_set_scaling(dispc, plane, in_width, in_height,
  2321. out_width, out_height, ilace, five_taps,
  2322. fieldmode, fourcc, rotation);
  2323. dispc_ovl_set_output_size(dispc, plane, out_width, out_height);
  2324. dispc_ovl_set_vid_color_conv(dispc, plane, cconv);
  2325. }
  2326. dispc_ovl_set_rotation_attrs(dispc, plane, rotation, rotation_type,
  2327. fourcc);
  2328. dispc_ovl_set_zorder(dispc, plane, caps, zorder);
  2329. dispc_ovl_set_pre_mult_alpha(dispc, plane, caps, pre_mult_alpha);
  2330. dispc_ovl_setup_global_alpha(dispc, plane, caps, global_alpha);
  2331. dispc_ovl_enable_replication(dispc, plane, caps, replication);
  2332. return 0;
  2333. }
  2334. static int dispc_ovl_setup(struct dispc_device *dispc,
  2335. enum omap_plane_id plane,
  2336. const struct omap_overlay_info *oi,
  2337. const struct videomode *vm, bool mem_to_mem,
  2338. enum omap_channel channel)
  2339. {
  2340. int r;
  2341. enum omap_overlay_caps caps = dispc->feat->overlay_caps[plane];
  2342. const bool replication = true;
  2343. DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
  2344. " %dx%d, cmode %x, rot %d, chan %d repl %d\n",
  2345. plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
  2346. oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
  2347. oi->fourcc, oi->rotation, channel, replication);
  2348. dispc_ovl_set_channel_out(dispc, plane, channel);
  2349. r = dispc_ovl_setup_common(dispc, plane, caps, oi->paddr, oi->p_uv_addr,
  2350. oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
  2351. oi->out_width, oi->out_height, oi->fourcc, oi->rotation,
  2352. oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
  2353. oi->rotation_type, replication, vm, mem_to_mem);
  2354. return r;
  2355. }
  2356. static int dispc_wb_setup(struct dispc_device *dispc,
  2357. const struct omap_dss_writeback_info *wi,
  2358. bool mem_to_mem, const struct videomode *vm,
  2359. enum dss_writeback_channel channel_in)
  2360. {
  2361. int r;
  2362. u32 l;
  2363. enum omap_plane_id plane = OMAP_DSS_WB;
  2364. const int pos_x = 0, pos_y = 0;
  2365. const u8 zorder = 0, global_alpha = 0;
  2366. const bool replication = true;
  2367. bool truncation;
  2368. int in_width = vm->hactive;
  2369. int in_height = vm->vactive;
  2370. enum omap_overlay_caps caps =
  2371. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
  2372. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2373. in_height /= 2;
  2374. DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
  2375. "rot %d\n", wi->paddr, wi->p_uv_addr, in_width,
  2376. in_height, wi->width, wi->height, wi->fourcc, wi->rotation);
  2377. r = dispc_ovl_setup_common(dispc, plane, caps, wi->paddr, wi->p_uv_addr,
  2378. wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
  2379. wi->height, wi->fourcc, wi->rotation, zorder,
  2380. wi->pre_mult_alpha, global_alpha, wi->rotation_type,
  2381. replication, vm, mem_to_mem);
  2382. if (r)
  2383. return r;
  2384. switch (wi->fourcc) {
  2385. case DRM_FORMAT_RGB565:
  2386. case DRM_FORMAT_RGB888:
  2387. case DRM_FORMAT_ARGB4444:
  2388. case DRM_FORMAT_RGBA4444:
  2389. case DRM_FORMAT_RGBX4444:
  2390. case DRM_FORMAT_ARGB1555:
  2391. case DRM_FORMAT_XRGB1555:
  2392. case DRM_FORMAT_XRGB4444:
  2393. truncation = true;
  2394. break;
  2395. default:
  2396. truncation = false;
  2397. break;
  2398. }
  2399. /* setup extra DISPC_WB_ATTRIBUTES */
  2400. l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
  2401. l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
  2402. l = FLD_MOD(l, channel_in, 18, 16); /* CHANNELIN */
  2403. l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
  2404. if (mem_to_mem)
  2405. l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
  2406. else
  2407. l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
  2408. dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
  2409. if (mem_to_mem) {
  2410. /* WBDELAYCOUNT */
  2411. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
  2412. } else {
  2413. u32 wbdelay;
  2414. if (channel_in == DSS_WB_TV_MGR)
  2415. wbdelay = vm->vsync_len + vm->vback_porch;
  2416. else
  2417. wbdelay = vm->vfront_porch + vm->vsync_len +
  2418. vm->vback_porch;
  2419. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2420. wbdelay /= 2;
  2421. wbdelay = min(wbdelay, 255u);
  2422. /* WBDELAYCOUNT */
  2423. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
  2424. }
  2425. return 0;
  2426. }
  2427. static bool dispc_has_writeback(struct dispc_device *dispc)
  2428. {
  2429. return dispc->feat->has_writeback;
  2430. }
  2431. static int dispc_ovl_enable(struct dispc_device *dispc,
  2432. enum omap_plane_id plane, bool enable)
  2433. {
  2434. DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
  2435. REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
  2436. return 0;
  2437. }
  2438. static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc,
  2439. bool act_high)
  2440. {
  2441. if (!dispc_has_feature(dispc, FEAT_LCDENABLEPOL))
  2442. return;
  2443. REG_FLD_MOD(dispc, DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
  2444. }
  2445. void dispc_lcd_enable_signal(struct dispc_device *dispc, bool enable)
  2446. {
  2447. if (!dispc_has_feature(dispc, FEAT_LCDENABLESIGNAL))
  2448. return;
  2449. REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 28, 28);
  2450. }
  2451. void dispc_pck_free_enable(struct dispc_device *dispc, bool enable)
  2452. {
  2453. if (!dispc_has_feature(dispc, FEAT_PCKFREEENABLE))
  2454. return;
  2455. REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 27, 27);
  2456. }
  2457. static void dispc_mgr_enable_fifohandcheck(struct dispc_device *dispc,
  2458. enum omap_channel channel,
  2459. bool enable)
  2460. {
  2461. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
  2462. }
  2463. static void dispc_mgr_set_lcd_type_tft(struct dispc_device *dispc,
  2464. enum omap_channel channel)
  2465. {
  2466. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STNTFT, 1);
  2467. }
  2468. static void dispc_set_loadmode(struct dispc_device *dispc,
  2469. enum omap_dss_load_mode mode)
  2470. {
  2471. REG_FLD_MOD(dispc, DISPC_CONFIG, mode, 2, 1);
  2472. }
  2473. static void dispc_mgr_set_default_color(struct dispc_device *dispc,
  2474. enum omap_channel channel, u32 color)
  2475. {
  2476. dispc_write_reg(dispc, DISPC_DEFAULT_COLOR(channel), color);
  2477. }
  2478. static void dispc_mgr_set_trans_key(struct dispc_device *dispc,
  2479. enum omap_channel ch,
  2480. enum omap_dss_trans_key_type type,
  2481. u32 trans_key)
  2482. {
  2483. mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKSELECTION, type);
  2484. dispc_write_reg(dispc, DISPC_TRANS_COLOR(ch), trans_key);
  2485. }
  2486. static void dispc_mgr_enable_trans_key(struct dispc_device *dispc,
  2487. enum omap_channel ch, bool enable)
  2488. {
  2489. mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKENABLE, enable);
  2490. }
  2491. static void dispc_mgr_enable_alpha_fixed_zorder(struct dispc_device *dispc,
  2492. enum omap_channel ch,
  2493. bool enable)
  2494. {
  2495. if (!dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER))
  2496. return;
  2497. if (ch == OMAP_DSS_CHANNEL_LCD)
  2498. REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 18, 18);
  2499. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  2500. REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 19, 19);
  2501. }
  2502. static void dispc_mgr_setup(struct dispc_device *dispc,
  2503. enum omap_channel channel,
  2504. const struct omap_overlay_manager_info *info)
  2505. {
  2506. dispc_mgr_set_default_color(dispc, channel, info->default_color);
  2507. dispc_mgr_set_trans_key(dispc, channel, info->trans_key_type,
  2508. info->trans_key);
  2509. dispc_mgr_enable_trans_key(dispc, channel, info->trans_enabled);
  2510. dispc_mgr_enable_alpha_fixed_zorder(dispc, channel,
  2511. info->partial_alpha_enabled);
  2512. if (dispc_has_feature(dispc, FEAT_CPR)) {
  2513. dispc_mgr_enable_cpr(dispc, channel, info->cpr_enable);
  2514. dispc_mgr_set_cpr_coef(dispc, channel, &info->cpr_coefs);
  2515. }
  2516. }
  2517. static void dispc_mgr_set_tft_data_lines(struct dispc_device *dispc,
  2518. enum omap_channel channel,
  2519. u8 data_lines)
  2520. {
  2521. int code;
  2522. switch (data_lines) {
  2523. case 12:
  2524. code = 0;
  2525. break;
  2526. case 16:
  2527. code = 1;
  2528. break;
  2529. case 18:
  2530. code = 2;
  2531. break;
  2532. case 24:
  2533. code = 3;
  2534. break;
  2535. default:
  2536. BUG();
  2537. return;
  2538. }
  2539. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_TFTDATALINES, code);
  2540. }
  2541. static void dispc_mgr_set_io_pad_mode(struct dispc_device *dispc,
  2542. enum dss_io_pad_mode mode)
  2543. {
  2544. u32 l;
  2545. int gpout0, gpout1;
  2546. switch (mode) {
  2547. case DSS_IO_PAD_MODE_RESET:
  2548. gpout0 = 0;
  2549. gpout1 = 0;
  2550. break;
  2551. case DSS_IO_PAD_MODE_RFBI:
  2552. gpout0 = 1;
  2553. gpout1 = 0;
  2554. break;
  2555. case DSS_IO_PAD_MODE_BYPASS:
  2556. gpout0 = 1;
  2557. gpout1 = 1;
  2558. break;
  2559. default:
  2560. BUG();
  2561. return;
  2562. }
  2563. l = dispc_read_reg(dispc, DISPC_CONTROL);
  2564. l = FLD_MOD(l, gpout0, 15, 15);
  2565. l = FLD_MOD(l, gpout1, 16, 16);
  2566. dispc_write_reg(dispc, DISPC_CONTROL, l);
  2567. }
  2568. static void dispc_mgr_enable_stallmode(struct dispc_device *dispc,
  2569. enum omap_channel channel, bool enable)
  2570. {
  2571. mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STALLMODE, enable);
  2572. }
  2573. static void dispc_mgr_set_lcd_config(struct dispc_device *dispc,
  2574. enum omap_channel channel,
  2575. const struct dss_lcd_mgr_config *config)
  2576. {
  2577. dispc_mgr_set_io_pad_mode(dispc, config->io_pad_mode);
  2578. dispc_mgr_enable_stallmode(dispc, channel, config->stallmode);
  2579. dispc_mgr_enable_fifohandcheck(dispc, channel, config->fifohandcheck);
  2580. dispc_mgr_set_clock_div(dispc, channel, &config->clock_info);
  2581. dispc_mgr_set_tft_data_lines(dispc, channel, config->video_port_width);
  2582. dispc_lcd_enable_signal_polarity(dispc, config->lcden_sig_polarity);
  2583. dispc_mgr_set_lcd_type_tft(dispc, channel);
  2584. }
  2585. static bool _dispc_mgr_size_ok(struct dispc_device *dispc,
  2586. u16 width, u16 height)
  2587. {
  2588. return width <= dispc->feat->mgr_width_max &&
  2589. height <= dispc->feat->mgr_height_max;
  2590. }
  2591. static bool _dispc_lcd_timings_ok(struct dispc_device *dispc,
  2592. int hsync_len, int hfp, int hbp,
  2593. int vsw, int vfp, int vbp)
  2594. {
  2595. if (hsync_len < 1 || hsync_len > dispc->feat->sw_max ||
  2596. hfp < 1 || hfp > dispc->feat->hp_max ||
  2597. hbp < 1 || hbp > dispc->feat->hp_max ||
  2598. vsw < 1 || vsw > dispc->feat->sw_max ||
  2599. vfp < 0 || vfp > dispc->feat->vp_max ||
  2600. vbp < 0 || vbp > dispc->feat->vp_max)
  2601. return false;
  2602. return true;
  2603. }
  2604. static bool _dispc_mgr_pclk_ok(struct dispc_device *dispc,
  2605. enum omap_channel channel,
  2606. unsigned long pclk)
  2607. {
  2608. if (dss_mgr_is_lcd(channel))
  2609. return pclk <= dispc->feat->max_lcd_pclk;
  2610. else
  2611. return pclk <= dispc->feat->max_tv_pclk;
  2612. }
  2613. static int dispc_mgr_check_timings(struct dispc_device *dispc,
  2614. enum omap_channel channel,
  2615. const struct videomode *vm)
  2616. {
  2617. if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive))
  2618. return MODE_BAD;
  2619. if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock))
  2620. return MODE_BAD;
  2621. if (dss_mgr_is_lcd(channel)) {
  2622. /* TODO: OMAP4+ supports interlace for LCD outputs */
  2623. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  2624. return MODE_BAD;
  2625. if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len,
  2626. vm->hfront_porch, vm->hback_porch,
  2627. vm->vsync_len, vm->vfront_porch,
  2628. vm->vback_porch))
  2629. return MODE_BAD;
  2630. }
  2631. return MODE_OK;
  2632. }
  2633. static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc,
  2634. enum omap_channel channel,
  2635. const struct videomode *vm)
  2636. {
  2637. u32 timing_h, timing_v, l;
  2638. bool onoff, rf, ipc, vs, hs, de;
  2639. timing_h = FLD_VAL(vm->hsync_len - 1, dispc->feat->sw_start, 0) |
  2640. FLD_VAL(vm->hfront_porch - 1, dispc->feat->fp_start, 8) |
  2641. FLD_VAL(vm->hback_porch - 1, dispc->feat->bp_start, 20);
  2642. timing_v = FLD_VAL(vm->vsync_len - 1, dispc->feat->sw_start, 0) |
  2643. FLD_VAL(vm->vfront_porch, dispc->feat->fp_start, 8) |
  2644. FLD_VAL(vm->vback_porch, dispc->feat->bp_start, 20);
  2645. dispc_write_reg(dispc, DISPC_TIMING_H(channel), timing_h);
  2646. dispc_write_reg(dispc, DISPC_TIMING_V(channel), timing_v);
  2647. if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
  2648. vs = false;
  2649. else
  2650. vs = true;
  2651. if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
  2652. hs = false;
  2653. else
  2654. hs = true;
  2655. if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
  2656. de = false;
  2657. else
  2658. de = true;
  2659. if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
  2660. ipc = false;
  2661. else
  2662. ipc = true;
  2663. /* always use the 'rf' setting */
  2664. onoff = true;
  2665. if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE)
  2666. rf = true;
  2667. else
  2668. rf = false;
  2669. l = FLD_VAL(onoff, 17, 17) |
  2670. FLD_VAL(rf, 16, 16) |
  2671. FLD_VAL(de, 15, 15) |
  2672. FLD_VAL(ipc, 14, 14) |
  2673. FLD_VAL(hs, 13, 13) |
  2674. FLD_VAL(vs, 12, 12);
  2675. /* always set ALIGN bit when available */
  2676. if (dispc->feat->supports_sync_align)
  2677. l |= (1 << 18);
  2678. dispc_write_reg(dispc, DISPC_POL_FREQ(channel), l);
  2679. if (dispc->syscon_pol) {
  2680. const int shifts[] = {
  2681. [OMAP_DSS_CHANNEL_LCD] = 0,
  2682. [OMAP_DSS_CHANNEL_LCD2] = 1,
  2683. [OMAP_DSS_CHANNEL_LCD3] = 2,
  2684. };
  2685. u32 mask, val;
  2686. mask = (1 << 0) | (1 << 3) | (1 << 6);
  2687. val = (rf << 0) | (ipc << 3) | (onoff << 6);
  2688. mask <<= 16 + shifts[channel];
  2689. val <<= 16 + shifts[channel];
  2690. regmap_update_bits(dispc->syscon_pol, dispc->syscon_pol_offset,
  2691. mask, val);
  2692. }
  2693. }
  2694. static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
  2695. enum display_flags low)
  2696. {
  2697. if (flags & high)
  2698. return 1;
  2699. if (flags & low)
  2700. return -1;
  2701. return 0;
  2702. }
  2703. /* change name to mode? */
  2704. static void dispc_mgr_set_timings(struct dispc_device *dispc,
  2705. enum omap_channel channel,
  2706. const struct videomode *vm)
  2707. {
  2708. unsigned int xtot, ytot;
  2709. unsigned long ht, vt;
  2710. struct videomode t = *vm;
  2711. DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
  2712. if (dispc_mgr_check_timings(dispc, channel, &t)) {
  2713. BUG();
  2714. return;
  2715. }
  2716. if (dss_mgr_is_lcd(channel)) {
  2717. _dispc_mgr_set_lcd_timings(dispc, channel, &t);
  2718. xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
  2719. ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
  2720. ht = vm->pixelclock / xtot;
  2721. vt = vm->pixelclock / xtot / ytot;
  2722. DSSDBG("pck %lu\n", vm->pixelclock);
  2723. DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
  2724. t.hsync_len, t.hfront_porch, t.hback_porch,
  2725. t.vsync_len, t.vfront_porch, t.vback_porch);
  2726. DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
  2727. vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
  2728. vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
  2729. vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
  2730. vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
  2731. vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
  2732. DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
  2733. } else {
  2734. if (t.flags & DISPLAY_FLAGS_INTERLACED)
  2735. t.vactive /= 2;
  2736. if (dispc->feat->supports_double_pixel)
  2737. REG_FLD_MOD(dispc, DISPC_CONTROL,
  2738. !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
  2739. 19, 17);
  2740. }
  2741. dispc_mgr_set_size(dispc, channel, t.hactive, t.vactive);
  2742. }
  2743. static void dispc_mgr_set_lcd_divisor(struct dispc_device *dispc,
  2744. enum omap_channel channel, u16 lck_div,
  2745. u16 pck_div)
  2746. {
  2747. BUG_ON(lck_div < 1);
  2748. BUG_ON(pck_div < 1);
  2749. dispc_write_reg(dispc, DISPC_DIVISORo(channel),
  2750. FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
  2751. if (!dispc_has_feature(dispc, FEAT_CORE_CLK_DIV) &&
  2752. channel == OMAP_DSS_CHANNEL_LCD)
  2753. dispc->core_clk_rate = dispc_fclk_rate(dispc) / lck_div;
  2754. }
  2755. static void dispc_mgr_get_lcd_divisor(struct dispc_device *dispc,
  2756. enum omap_channel channel, int *lck_div,
  2757. int *pck_div)
  2758. {
  2759. u32 l;
  2760. l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
  2761. *lck_div = FLD_GET(l, 23, 16);
  2762. *pck_div = FLD_GET(l, 7, 0);
  2763. }
  2764. static unsigned long dispc_fclk_rate(struct dispc_device *dispc)
  2765. {
  2766. unsigned long r;
  2767. enum dss_clk_source src;
  2768. src = dss_get_dispc_clk_source(dispc->dss);
  2769. if (src == DSS_CLK_SRC_FCK) {
  2770. r = dss_get_dispc_clk_rate(dispc->dss);
  2771. } else {
  2772. struct dss_pll *pll;
  2773. unsigned int clkout_idx;
  2774. pll = dss_pll_find_by_src(dispc->dss, src);
  2775. clkout_idx = dss_pll_get_clkout_idx_for_src(src);
  2776. r = pll->cinfo.clkout[clkout_idx];
  2777. }
  2778. return r;
  2779. }
  2780. static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
  2781. enum omap_channel channel)
  2782. {
  2783. int lcd;
  2784. unsigned long r;
  2785. enum dss_clk_source src;
  2786. /* for TV, LCLK rate is the FCLK rate */
  2787. if (!dss_mgr_is_lcd(channel))
  2788. return dispc_fclk_rate(dispc);
  2789. src = dss_get_lcd_clk_source(dispc->dss, channel);
  2790. if (src == DSS_CLK_SRC_FCK) {
  2791. r = dss_get_dispc_clk_rate(dispc->dss);
  2792. } else {
  2793. struct dss_pll *pll;
  2794. unsigned int clkout_idx;
  2795. pll = dss_pll_find_by_src(dispc->dss, src);
  2796. clkout_idx = dss_pll_get_clkout_idx_for_src(src);
  2797. r = pll->cinfo.clkout[clkout_idx];
  2798. }
  2799. lcd = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
  2800. return r / lcd;
  2801. }
  2802. static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
  2803. enum omap_channel channel)
  2804. {
  2805. unsigned long r;
  2806. if (dss_mgr_is_lcd(channel)) {
  2807. int pcd;
  2808. u32 l;
  2809. l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
  2810. pcd = FLD_GET(l, 7, 0);
  2811. r = dispc_mgr_lclk_rate(dispc, channel);
  2812. return r / pcd;
  2813. } else {
  2814. return dispc->tv_pclk_rate;
  2815. }
  2816. }
  2817. void dispc_set_tv_pclk(struct dispc_device *dispc, unsigned long pclk)
  2818. {
  2819. dispc->tv_pclk_rate = pclk;
  2820. }
  2821. static unsigned long dispc_core_clk_rate(struct dispc_device *dispc)
  2822. {
  2823. return dispc->core_clk_rate;
  2824. }
  2825. static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
  2826. enum omap_plane_id plane)
  2827. {
  2828. enum omap_channel channel;
  2829. if (plane == OMAP_DSS_WB)
  2830. return 0;
  2831. channel = dispc_ovl_get_channel_out(dispc, plane);
  2832. return dispc_mgr_pclk_rate(dispc, channel);
  2833. }
  2834. static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
  2835. enum omap_plane_id plane)
  2836. {
  2837. enum omap_channel channel;
  2838. if (plane == OMAP_DSS_WB)
  2839. return 0;
  2840. channel = dispc_ovl_get_channel_out(dispc, plane);
  2841. return dispc_mgr_lclk_rate(dispc, channel);
  2842. }
  2843. static void dispc_dump_clocks_channel(struct dispc_device *dispc,
  2844. struct seq_file *s,
  2845. enum omap_channel channel)
  2846. {
  2847. int lcd, pcd;
  2848. enum dss_clk_source lcd_clk_src;
  2849. seq_printf(s, "- %s -\n", mgr_desc[channel].name);
  2850. lcd_clk_src = dss_get_lcd_clk_source(dispc->dss, channel);
  2851. seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
  2852. dss_get_clk_source_name(lcd_clk_src));
  2853. dispc_mgr_get_lcd_divisor(dispc, channel, &lcd, &pcd);
  2854. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2855. dispc_mgr_lclk_rate(dispc, channel), lcd);
  2856. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2857. dispc_mgr_pclk_rate(dispc, channel), pcd);
  2858. }
  2859. void dispc_dump_clocks(struct dispc_device *dispc, struct seq_file *s)
  2860. {
  2861. enum dss_clk_source dispc_clk_src;
  2862. int lcd;
  2863. u32 l;
  2864. if (dispc_runtime_get(dispc))
  2865. return;
  2866. seq_printf(s, "- DISPC -\n");
  2867. dispc_clk_src = dss_get_dispc_clk_source(dispc->dss);
  2868. seq_printf(s, "dispc fclk source = %s\n",
  2869. dss_get_clk_source_name(dispc_clk_src));
  2870. seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate(dispc));
  2871. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
  2872. seq_printf(s, "- DISPC-CORE-CLK -\n");
  2873. l = dispc_read_reg(dispc, DISPC_DIVISOR);
  2874. lcd = FLD_GET(l, 23, 16);
  2875. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2876. (dispc_fclk_rate(dispc)/lcd), lcd);
  2877. }
  2878. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD);
  2879. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  2880. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD2);
  2881. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  2882. dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD3);
  2883. dispc_runtime_put(dispc);
  2884. }
  2885. static int dispc_dump_regs(struct seq_file *s, void *p)
  2886. {
  2887. struct dispc_device *dispc = s->private;
  2888. int i, j;
  2889. const char *mgr_names[] = {
  2890. [OMAP_DSS_CHANNEL_LCD] = "LCD",
  2891. [OMAP_DSS_CHANNEL_DIGIT] = "TV",
  2892. [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
  2893. [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
  2894. };
  2895. const char *ovl_names[] = {
  2896. [OMAP_DSS_GFX] = "GFX",
  2897. [OMAP_DSS_VIDEO1] = "VID1",
  2898. [OMAP_DSS_VIDEO2] = "VID2",
  2899. [OMAP_DSS_VIDEO3] = "VID3",
  2900. [OMAP_DSS_WB] = "WB",
  2901. };
  2902. const char **p_names;
  2903. #define DUMPREG(dispc, r) \
  2904. seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(dispc, r))
  2905. if (dispc_runtime_get(dispc))
  2906. return 0;
  2907. /* DISPC common registers */
  2908. DUMPREG(dispc, DISPC_REVISION);
  2909. DUMPREG(dispc, DISPC_SYSCONFIG);
  2910. DUMPREG(dispc, DISPC_SYSSTATUS);
  2911. DUMPREG(dispc, DISPC_IRQSTATUS);
  2912. DUMPREG(dispc, DISPC_IRQENABLE);
  2913. DUMPREG(dispc, DISPC_CONTROL);
  2914. DUMPREG(dispc, DISPC_CONFIG);
  2915. DUMPREG(dispc, DISPC_CAPABLE);
  2916. DUMPREG(dispc, DISPC_LINE_STATUS);
  2917. DUMPREG(dispc, DISPC_LINE_NUMBER);
  2918. if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
  2919. dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
  2920. DUMPREG(dispc, DISPC_GLOBAL_ALPHA);
  2921. if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
  2922. DUMPREG(dispc, DISPC_CONTROL2);
  2923. DUMPREG(dispc, DISPC_CONFIG2);
  2924. }
  2925. if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
  2926. DUMPREG(dispc, DISPC_CONTROL3);
  2927. DUMPREG(dispc, DISPC_CONFIG3);
  2928. }
  2929. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2930. DUMPREG(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE);
  2931. #undef DUMPREG
  2932. #define DISPC_REG(i, name) name(i)
  2933. #define DUMPREG(dispc, i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
  2934. (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
  2935. dispc_read_reg(dispc, DISPC_REG(i, r)))
  2936. p_names = mgr_names;
  2937. /* DISPC channel specific registers */
  2938. for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
  2939. DUMPREG(dispc, i, DISPC_DEFAULT_COLOR);
  2940. DUMPREG(dispc, i, DISPC_TRANS_COLOR);
  2941. DUMPREG(dispc, i, DISPC_SIZE_MGR);
  2942. if (i == OMAP_DSS_CHANNEL_DIGIT)
  2943. continue;
  2944. DUMPREG(dispc, i, DISPC_TIMING_H);
  2945. DUMPREG(dispc, i, DISPC_TIMING_V);
  2946. DUMPREG(dispc, i, DISPC_POL_FREQ);
  2947. DUMPREG(dispc, i, DISPC_DIVISORo);
  2948. DUMPREG(dispc, i, DISPC_DATA_CYCLE1);
  2949. DUMPREG(dispc, i, DISPC_DATA_CYCLE2);
  2950. DUMPREG(dispc, i, DISPC_DATA_CYCLE3);
  2951. if (dispc_has_feature(dispc, FEAT_CPR)) {
  2952. DUMPREG(dispc, i, DISPC_CPR_COEF_R);
  2953. DUMPREG(dispc, i, DISPC_CPR_COEF_G);
  2954. DUMPREG(dispc, i, DISPC_CPR_COEF_B);
  2955. }
  2956. }
  2957. p_names = ovl_names;
  2958. for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
  2959. DUMPREG(dispc, i, DISPC_OVL_BA0);
  2960. DUMPREG(dispc, i, DISPC_OVL_BA1);
  2961. DUMPREG(dispc, i, DISPC_OVL_POSITION);
  2962. DUMPREG(dispc, i, DISPC_OVL_SIZE);
  2963. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
  2964. DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
  2965. DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
  2966. DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
  2967. DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
  2968. if (dispc_has_feature(dispc, FEAT_PRELOAD))
  2969. DUMPREG(dispc, i, DISPC_OVL_PRELOAD);
  2970. if (dispc_has_feature(dispc, FEAT_MFLAG))
  2971. DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
  2972. if (i == OMAP_DSS_GFX) {
  2973. DUMPREG(dispc, i, DISPC_OVL_WINDOW_SKIP);
  2974. DUMPREG(dispc, i, DISPC_OVL_TABLE_BA);
  2975. continue;
  2976. }
  2977. DUMPREG(dispc, i, DISPC_OVL_FIR);
  2978. DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
  2979. DUMPREG(dispc, i, DISPC_OVL_ACCU0);
  2980. DUMPREG(dispc, i, DISPC_OVL_ACCU1);
  2981. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  2982. DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
  2983. DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
  2984. DUMPREG(dispc, i, DISPC_OVL_FIR2);
  2985. DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
  2986. DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
  2987. }
  2988. if (dispc_has_feature(dispc, FEAT_ATTR2))
  2989. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
  2990. }
  2991. if (dispc->feat->has_writeback) {
  2992. i = OMAP_DSS_WB;
  2993. DUMPREG(dispc, i, DISPC_OVL_BA0);
  2994. DUMPREG(dispc, i, DISPC_OVL_BA1);
  2995. DUMPREG(dispc, i, DISPC_OVL_SIZE);
  2996. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
  2997. DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
  2998. DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
  2999. DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
  3000. DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
  3001. if (dispc_has_feature(dispc, FEAT_MFLAG))
  3002. DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
  3003. DUMPREG(dispc, i, DISPC_OVL_FIR);
  3004. DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
  3005. DUMPREG(dispc, i, DISPC_OVL_ACCU0);
  3006. DUMPREG(dispc, i, DISPC_OVL_ACCU1);
  3007. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  3008. DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
  3009. DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
  3010. DUMPREG(dispc, i, DISPC_OVL_FIR2);
  3011. DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
  3012. DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
  3013. }
  3014. if (dispc_has_feature(dispc, FEAT_ATTR2))
  3015. DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
  3016. }
  3017. #undef DISPC_REG
  3018. #undef DUMPREG
  3019. #define DISPC_REG(plane, name, i) name(plane, i)
  3020. #define DUMPREG(dispc, plane, name, i) \
  3021. seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
  3022. (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
  3023. dispc_read_reg(dispc, DISPC_REG(plane, name, i)))
  3024. /* Video pipeline coefficient registers */
  3025. /* start from OMAP_DSS_VIDEO1 */
  3026. for (i = 1; i < dispc_get_num_ovls(dispc); i++) {
  3027. for (j = 0; j < 8; j++)
  3028. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H, j);
  3029. for (j = 0; j < 8; j++)
  3030. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV, j);
  3031. for (j = 0; j < 5; j++)
  3032. DUMPREG(dispc, i, DISPC_OVL_CONV_COEF, j);
  3033. if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
  3034. for (j = 0; j < 8; j++)
  3035. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V, j);
  3036. }
  3037. if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
  3038. for (j = 0; j < 8; j++)
  3039. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H2, j);
  3040. for (j = 0; j < 8; j++)
  3041. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV2, j);
  3042. for (j = 0; j < 8; j++)
  3043. DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V2, j);
  3044. }
  3045. }
  3046. dispc_runtime_put(dispc);
  3047. #undef DISPC_REG
  3048. #undef DUMPREG
  3049. return 0;
  3050. }
  3051. /* calculate clock rates using dividers in cinfo */
  3052. int dispc_calc_clock_rates(struct dispc_device *dispc,
  3053. unsigned long dispc_fclk_rate,
  3054. struct dispc_clock_info *cinfo)
  3055. {
  3056. if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
  3057. return -EINVAL;
  3058. if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
  3059. return -EINVAL;
  3060. cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
  3061. cinfo->pck = cinfo->lck / cinfo->pck_div;
  3062. return 0;
  3063. }
  3064. bool dispc_div_calc(struct dispc_device *dispc, unsigned long dispc_freq,
  3065. unsigned long pck_min, unsigned long pck_max,
  3066. dispc_div_calc_func func, void *data)
  3067. {
  3068. int lckd, lckd_start, lckd_stop;
  3069. int pckd, pckd_start, pckd_stop;
  3070. unsigned long pck, lck;
  3071. unsigned long lck_max;
  3072. unsigned long pckd_hw_min, pckd_hw_max;
  3073. unsigned int min_fck_per_pck;
  3074. unsigned long fck;
  3075. #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
  3076. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  3077. #else
  3078. min_fck_per_pck = 0;
  3079. #endif
  3080. pckd_hw_min = dispc->feat->min_pcd;
  3081. pckd_hw_max = 255;
  3082. lck_max = dss_get_max_fck_rate(dispc->dss);
  3083. pck_min = pck_min ? pck_min : 1;
  3084. pck_max = pck_max ? pck_max : ULONG_MAX;
  3085. lckd_start = max(DIV_ROUND_UP(dispc_freq, lck_max), 1ul);
  3086. lckd_stop = min(dispc_freq / pck_min, 255ul);
  3087. for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
  3088. lck = dispc_freq / lckd;
  3089. pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
  3090. pckd_stop = min(lck / pck_min, pckd_hw_max);
  3091. for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
  3092. pck = lck / pckd;
  3093. /*
  3094. * For OMAP2/3 the DISPC fclk is the same as LCD's logic
  3095. * clock, which means we're configuring DISPC fclk here
  3096. * also. Thus we need to use the calculated lck. For
  3097. * OMAP4+ the DISPC fclk is a separate clock.
  3098. */
  3099. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
  3100. fck = dispc_core_clk_rate(dispc);
  3101. else
  3102. fck = lck;
  3103. if (fck < pck * min_fck_per_pck)
  3104. continue;
  3105. if (func(lckd, pckd, lck, pck, data))
  3106. return true;
  3107. }
  3108. }
  3109. return false;
  3110. }
  3111. void dispc_mgr_set_clock_div(struct dispc_device *dispc,
  3112. enum omap_channel channel,
  3113. const struct dispc_clock_info *cinfo)
  3114. {
  3115. DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
  3116. DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
  3117. dispc_mgr_set_lcd_divisor(dispc, channel, cinfo->lck_div,
  3118. cinfo->pck_div);
  3119. }
  3120. int dispc_mgr_get_clock_div(struct dispc_device *dispc,
  3121. enum omap_channel channel,
  3122. struct dispc_clock_info *cinfo)
  3123. {
  3124. unsigned long fck;
  3125. fck = dispc_fclk_rate(dispc);
  3126. cinfo->lck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
  3127. cinfo->pck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 7, 0);
  3128. cinfo->lck = fck / cinfo->lck_div;
  3129. cinfo->pck = cinfo->lck / cinfo->pck_div;
  3130. return 0;
  3131. }
  3132. static u32 dispc_read_irqstatus(struct dispc_device *dispc)
  3133. {
  3134. return dispc_read_reg(dispc, DISPC_IRQSTATUS);
  3135. }
  3136. static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask)
  3137. {
  3138. dispc_write_reg(dispc, DISPC_IRQSTATUS, mask);
  3139. }
  3140. static void dispc_write_irqenable(struct dispc_device *dispc, u32 mask)
  3141. {
  3142. u32 old_mask = dispc_read_reg(dispc, DISPC_IRQENABLE);
  3143. /* clear the irqstatus for newly enabled irqs */
  3144. dispc_clear_irqstatus(dispc, (mask ^ old_mask) & mask);
  3145. dispc_write_reg(dispc, DISPC_IRQENABLE, mask);
  3146. /* flush posted write */
  3147. dispc_read_reg(dispc, DISPC_IRQENABLE);
  3148. }
  3149. void dispc_enable_sidle(struct dispc_device *dispc)
  3150. {
  3151. /* SIDLEMODE: smart idle */
  3152. REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 2, 4, 3);
  3153. }
  3154. void dispc_disable_sidle(struct dispc_device *dispc)
  3155. {
  3156. REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
  3157. }
  3158. static u32 dispc_mgr_gamma_size(struct dispc_device *dispc,
  3159. enum omap_channel channel)
  3160. {
  3161. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3162. if (!dispc->feat->has_gamma_table)
  3163. return 0;
  3164. return gdesc->len;
  3165. }
  3166. static void dispc_mgr_write_gamma_table(struct dispc_device *dispc,
  3167. enum omap_channel channel)
  3168. {
  3169. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3170. u32 *table = dispc->gamma_table[channel];
  3171. unsigned int i;
  3172. DSSDBG("%s: channel %d\n", __func__, channel);
  3173. for (i = 0; i < gdesc->len; ++i) {
  3174. u32 v = table[i];
  3175. if (gdesc->has_index)
  3176. v |= i << 24;
  3177. else if (i == 0)
  3178. v |= 1 << 31;
  3179. dispc_write_reg(dispc, gdesc->reg, v);
  3180. }
  3181. }
  3182. static void dispc_restore_gamma_tables(struct dispc_device *dispc)
  3183. {
  3184. DSSDBG("%s()\n", __func__);
  3185. if (!dispc->feat->has_gamma_table)
  3186. return;
  3187. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD);
  3188. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_DIGIT);
  3189. if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
  3190. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD2);
  3191. if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
  3192. dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD3);
  3193. }
  3194. static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
  3195. { .red = 0, .green = 0, .blue = 0, },
  3196. { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
  3197. };
  3198. static void dispc_mgr_set_gamma(struct dispc_device *dispc,
  3199. enum omap_channel channel,
  3200. const struct drm_color_lut *lut,
  3201. unsigned int length)
  3202. {
  3203. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3204. u32 *table = dispc->gamma_table[channel];
  3205. uint i;
  3206. DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
  3207. channel, length, gdesc->len);
  3208. if (!dispc->feat->has_gamma_table)
  3209. return;
  3210. if (lut == NULL || length < 2) {
  3211. lut = dispc_mgr_gamma_default_lut;
  3212. length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
  3213. }
  3214. for (i = 0; i < length - 1; ++i) {
  3215. uint first = i * (gdesc->len - 1) / (length - 1);
  3216. uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
  3217. uint w = last - first;
  3218. u16 r, g, b;
  3219. uint j;
  3220. if (w == 0)
  3221. continue;
  3222. for (j = 0; j <= w; j++) {
  3223. r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
  3224. g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
  3225. b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
  3226. r >>= 16 - gdesc->bits;
  3227. g >>= 16 - gdesc->bits;
  3228. b >>= 16 - gdesc->bits;
  3229. table[first + j] = (r << (gdesc->bits * 2)) |
  3230. (g << gdesc->bits) | b;
  3231. }
  3232. }
  3233. if (dispc->is_enabled)
  3234. dispc_mgr_write_gamma_table(dispc, channel);
  3235. }
  3236. static int dispc_init_gamma_tables(struct dispc_device *dispc)
  3237. {
  3238. int channel;
  3239. if (!dispc->feat->has_gamma_table)
  3240. return 0;
  3241. for (channel = 0; channel < ARRAY_SIZE(dispc->gamma_table); channel++) {
  3242. const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
  3243. u32 *gt;
  3244. if (channel == OMAP_DSS_CHANNEL_LCD2 &&
  3245. !dispc_has_feature(dispc, FEAT_MGR_LCD2))
  3246. continue;
  3247. if (channel == OMAP_DSS_CHANNEL_LCD3 &&
  3248. !dispc_has_feature(dispc, FEAT_MGR_LCD3))
  3249. continue;
  3250. gt = devm_kmalloc_array(&dispc->pdev->dev, gdesc->len,
  3251. sizeof(u32), GFP_KERNEL);
  3252. if (!gt)
  3253. return -ENOMEM;
  3254. dispc->gamma_table[channel] = gt;
  3255. dispc_mgr_set_gamma(dispc, channel, NULL, 0);
  3256. }
  3257. return 0;
  3258. }
  3259. static void _omap_dispc_initial_config(struct dispc_device *dispc)
  3260. {
  3261. u32 l;
  3262. /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
  3263. if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
  3264. l = dispc_read_reg(dispc, DISPC_DIVISOR);
  3265. /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
  3266. l = FLD_MOD(l, 1, 0, 0);
  3267. l = FLD_MOD(l, 1, 23, 16);
  3268. dispc_write_reg(dispc, DISPC_DIVISOR, l);
  3269. dispc->core_clk_rate = dispc_fclk_rate(dispc);
  3270. }
  3271. /* Use gamma table mode, instead of palette mode */
  3272. if (dispc->feat->has_gamma_table)
  3273. REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 3, 3);
  3274. /* For older DSS versions (FEAT_FUNCGATED) this enables
  3275. * func-clock auto-gating. For newer versions
  3276. * (dispc->feat->has_gamma_table) this enables tv-out gamma tables.
  3277. */
  3278. if (dispc_has_feature(dispc, FEAT_FUNCGATED) ||
  3279. dispc->feat->has_gamma_table)
  3280. REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 9, 9);
  3281. dispc_setup_color_conv_coef(dispc);
  3282. dispc_set_loadmode(dispc, OMAP_DSS_LOAD_FRAME_ONLY);
  3283. dispc_init_fifos(dispc);
  3284. dispc_configure_burst_sizes(dispc);
  3285. dispc_ovl_enable_zorder_planes(dispc);
  3286. if (dispc->feat->mstandby_workaround)
  3287. REG_FLD_MOD(dispc, DISPC_MSTANDBY_CTRL, 1, 0, 0);
  3288. if (dispc_has_feature(dispc, FEAT_MFLAG))
  3289. dispc_init_mflag(dispc);
  3290. }
  3291. static const enum dispc_feature_id omap2_dispc_features_list[] = {
  3292. FEAT_LCDENABLEPOL,
  3293. FEAT_LCDENABLESIGNAL,
  3294. FEAT_PCKFREEENABLE,
  3295. FEAT_FUNCGATED,
  3296. FEAT_ROWREPEATENABLE,
  3297. FEAT_RESIZECONF,
  3298. };
  3299. static const enum dispc_feature_id omap3_dispc_features_list[] = {
  3300. FEAT_LCDENABLEPOL,
  3301. FEAT_LCDENABLESIGNAL,
  3302. FEAT_PCKFREEENABLE,
  3303. FEAT_FUNCGATED,
  3304. FEAT_LINEBUFFERSPLIT,
  3305. FEAT_ROWREPEATENABLE,
  3306. FEAT_RESIZECONF,
  3307. FEAT_CPR,
  3308. FEAT_PRELOAD,
  3309. FEAT_FIR_COEF_V,
  3310. FEAT_ALPHA_FIXED_ZORDER,
  3311. FEAT_FIFO_MERGE,
  3312. FEAT_OMAP3_DSI_FIFO_BUG,
  3313. };
  3314. static const enum dispc_feature_id am43xx_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. };
  3328. static const enum dispc_feature_id omap4_dispc_features_list[] = {
  3329. FEAT_MGR_LCD2,
  3330. FEAT_CORE_CLK_DIV,
  3331. FEAT_HANDLE_UV_SEPARATE,
  3332. FEAT_ATTR2,
  3333. FEAT_CPR,
  3334. FEAT_PRELOAD,
  3335. FEAT_FIR_COEF_V,
  3336. FEAT_ALPHA_FREE_ZORDER,
  3337. FEAT_FIFO_MERGE,
  3338. FEAT_BURST_2D,
  3339. };
  3340. static const enum dispc_feature_id omap5_dispc_features_list[] = {
  3341. FEAT_MGR_LCD2,
  3342. FEAT_MGR_LCD3,
  3343. FEAT_CORE_CLK_DIV,
  3344. FEAT_HANDLE_UV_SEPARATE,
  3345. FEAT_ATTR2,
  3346. FEAT_CPR,
  3347. FEAT_PRELOAD,
  3348. FEAT_FIR_COEF_V,
  3349. FEAT_ALPHA_FREE_ZORDER,
  3350. FEAT_FIFO_MERGE,
  3351. FEAT_BURST_2D,
  3352. FEAT_MFLAG,
  3353. };
  3354. static const struct dss_reg_field omap2_dispc_reg_fields[] = {
  3355. [FEAT_REG_FIRHINC] = { 11, 0 },
  3356. [FEAT_REG_FIRVINC] = { 27, 16 },
  3357. [FEAT_REG_FIFOLOWTHRESHOLD] = { 8, 0 },
  3358. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 24, 16 },
  3359. [FEAT_REG_FIFOSIZE] = { 8, 0 },
  3360. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  3361. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  3362. };
  3363. static const struct dss_reg_field omap3_dispc_reg_fields[] = {
  3364. [FEAT_REG_FIRHINC] = { 12, 0 },
  3365. [FEAT_REG_FIRVINC] = { 28, 16 },
  3366. [FEAT_REG_FIFOLOWTHRESHOLD] = { 11, 0 },
  3367. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 27, 16 },
  3368. [FEAT_REG_FIFOSIZE] = { 10, 0 },
  3369. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  3370. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  3371. };
  3372. static const struct dss_reg_field omap4_dispc_reg_fields[] = {
  3373. [FEAT_REG_FIRHINC] = { 12, 0 },
  3374. [FEAT_REG_FIRVINC] = { 28, 16 },
  3375. [FEAT_REG_FIFOLOWTHRESHOLD] = { 15, 0 },
  3376. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 31, 16 },
  3377. [FEAT_REG_FIFOSIZE] = { 15, 0 },
  3378. [FEAT_REG_HORIZONTALACCU] = { 10, 0 },
  3379. [FEAT_REG_VERTICALACCU] = { 26, 16 },
  3380. };
  3381. static const enum omap_overlay_caps omap2_dispc_overlay_caps[] = {
  3382. /* OMAP_DSS_GFX */
  3383. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3384. /* OMAP_DSS_VIDEO1 */
  3385. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3386. OMAP_DSS_OVL_CAP_REPLICATION,
  3387. /* OMAP_DSS_VIDEO2 */
  3388. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3389. OMAP_DSS_OVL_CAP_REPLICATION,
  3390. };
  3391. static const enum omap_overlay_caps omap3430_dispc_overlay_caps[] = {
  3392. /* OMAP_DSS_GFX */
  3393. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_POS |
  3394. OMAP_DSS_OVL_CAP_REPLICATION,
  3395. /* OMAP_DSS_VIDEO1 */
  3396. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3397. OMAP_DSS_OVL_CAP_REPLICATION,
  3398. /* OMAP_DSS_VIDEO2 */
  3399. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3400. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3401. };
  3402. static const enum omap_overlay_caps omap3630_dispc_overlay_caps[] = {
  3403. /* OMAP_DSS_GFX */
  3404. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
  3405. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3406. /* OMAP_DSS_VIDEO1 */
  3407. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
  3408. OMAP_DSS_OVL_CAP_REPLICATION,
  3409. /* OMAP_DSS_VIDEO2 */
  3410. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3411. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_POS |
  3412. OMAP_DSS_OVL_CAP_REPLICATION,
  3413. };
  3414. static const enum omap_overlay_caps omap4_dispc_overlay_caps[] = {
  3415. /* OMAP_DSS_GFX */
  3416. OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
  3417. OMAP_DSS_OVL_CAP_ZORDER | OMAP_DSS_OVL_CAP_POS |
  3418. OMAP_DSS_OVL_CAP_REPLICATION,
  3419. /* OMAP_DSS_VIDEO1 */
  3420. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3421. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3422. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3423. /* OMAP_DSS_VIDEO2 */
  3424. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3425. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3426. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3427. /* OMAP_DSS_VIDEO3 */
  3428. OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
  3429. OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
  3430. OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
  3431. };
  3432. #define COLOR_ARRAY(arr...) (const u32[]) { arr, 0 }
  3433. static const u32 *omap2_dispc_supported_color_modes[] = {
  3434. /* OMAP_DSS_GFX */
  3435. COLOR_ARRAY(
  3436. DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
  3437. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888),
  3438. /* OMAP_DSS_VIDEO1 */
  3439. COLOR_ARRAY(
  3440. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3441. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3442. DRM_FORMAT_UYVY),
  3443. /* OMAP_DSS_VIDEO2 */
  3444. COLOR_ARRAY(
  3445. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3446. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3447. DRM_FORMAT_UYVY),
  3448. };
  3449. static const u32 *omap3_dispc_supported_color_modes[] = {
  3450. /* OMAP_DSS_GFX */
  3451. COLOR_ARRAY(
  3452. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3453. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3454. DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
  3455. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
  3456. /* OMAP_DSS_VIDEO1 */
  3457. COLOR_ARRAY(
  3458. DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888,
  3459. DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
  3460. DRM_FORMAT_YUYV, DRM_FORMAT_UYVY),
  3461. /* OMAP_DSS_VIDEO2 */
  3462. COLOR_ARRAY(
  3463. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3464. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3465. DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
  3466. DRM_FORMAT_UYVY, DRM_FORMAT_ARGB8888,
  3467. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
  3468. };
  3469. static const u32 *omap4_dispc_supported_color_modes[] = {
  3470. /* OMAP_DSS_GFX */
  3471. COLOR_ARRAY(
  3472. DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
  3473. DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
  3474. DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
  3475. DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888,
  3476. DRM_FORMAT_ARGB1555, DRM_FORMAT_XRGB4444,
  3477. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB1555),
  3478. /* OMAP_DSS_VIDEO1 */
  3479. COLOR_ARRAY(
  3480. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3481. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3482. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3483. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3484. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3485. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3486. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3487. DRM_FORMAT_RGBX8888),
  3488. /* OMAP_DSS_VIDEO2 */
  3489. COLOR_ARRAY(
  3490. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3491. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3492. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3493. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3494. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3495. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3496. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3497. DRM_FORMAT_RGBX8888),
  3498. /* OMAP_DSS_VIDEO3 */
  3499. COLOR_ARRAY(
  3500. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3501. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3502. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3503. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3504. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3505. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3506. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3507. DRM_FORMAT_RGBX8888),
  3508. /* OMAP_DSS_WB */
  3509. COLOR_ARRAY(
  3510. DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
  3511. DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
  3512. DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
  3513. DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
  3514. DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
  3515. DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
  3516. DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
  3517. DRM_FORMAT_RGBX8888),
  3518. };
  3519. static const struct dispc_features omap24xx_dispc_feats = {
  3520. .sw_start = 5,
  3521. .fp_start = 15,
  3522. .bp_start = 27,
  3523. .sw_max = 64,
  3524. .vp_max = 255,
  3525. .hp_max = 256,
  3526. .mgr_width_start = 10,
  3527. .mgr_height_start = 26,
  3528. .mgr_width_max = 2048,
  3529. .mgr_height_max = 2048,
  3530. .max_lcd_pclk = 66500000,
  3531. .max_downscale = 2,
  3532. /*
  3533. * Assume the line width buffer to be 768 pixels as OMAP2 DISPC scaler
  3534. * cannot scale an image width larger than 768.
  3535. */
  3536. .max_line_width = 768,
  3537. .min_pcd = 2,
  3538. .calc_scaling = dispc_ovl_calc_scaling_24xx,
  3539. .calc_core_clk = calc_core_clk_24xx,
  3540. .num_fifos = 3,
  3541. .features = omap2_dispc_features_list,
  3542. .num_features = ARRAY_SIZE(omap2_dispc_features_list),
  3543. .reg_fields = omap2_dispc_reg_fields,
  3544. .num_reg_fields = ARRAY_SIZE(omap2_dispc_reg_fields),
  3545. .overlay_caps = omap2_dispc_overlay_caps,
  3546. .supported_color_modes = omap2_dispc_supported_color_modes,
  3547. .num_mgrs = 2,
  3548. .num_ovls = 3,
  3549. .buffer_size_unit = 1,
  3550. .burst_size_unit = 8,
  3551. .no_framedone_tv = true,
  3552. .set_max_preload = false,
  3553. .last_pixel_inc_missing = true,
  3554. };
  3555. static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
  3556. .sw_start = 5,
  3557. .fp_start = 15,
  3558. .bp_start = 27,
  3559. .sw_max = 64,
  3560. .vp_max = 255,
  3561. .hp_max = 256,
  3562. .mgr_width_start = 10,
  3563. .mgr_height_start = 26,
  3564. .mgr_width_max = 2048,
  3565. .mgr_height_max = 2048,
  3566. .max_lcd_pclk = 173000000,
  3567. .max_tv_pclk = 59000000,
  3568. .max_downscale = 4,
  3569. .max_line_width = 1024,
  3570. .min_pcd = 1,
  3571. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3572. .calc_core_clk = calc_core_clk_34xx,
  3573. .num_fifos = 3,
  3574. .features = omap3_dispc_features_list,
  3575. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3576. .reg_fields = omap3_dispc_reg_fields,
  3577. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3578. .overlay_caps = omap3430_dispc_overlay_caps,
  3579. .supported_color_modes = omap3_dispc_supported_color_modes,
  3580. .num_mgrs = 2,
  3581. .num_ovls = 3,
  3582. .buffer_size_unit = 1,
  3583. .burst_size_unit = 8,
  3584. .no_framedone_tv = true,
  3585. .set_max_preload = false,
  3586. .last_pixel_inc_missing = true,
  3587. };
  3588. static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
  3589. .sw_start = 7,
  3590. .fp_start = 19,
  3591. .bp_start = 31,
  3592. .sw_max = 256,
  3593. .vp_max = 4095,
  3594. .hp_max = 4096,
  3595. .mgr_width_start = 10,
  3596. .mgr_height_start = 26,
  3597. .mgr_width_max = 2048,
  3598. .mgr_height_max = 2048,
  3599. .max_lcd_pclk = 173000000,
  3600. .max_tv_pclk = 59000000,
  3601. .max_downscale = 4,
  3602. .max_line_width = 1024,
  3603. .min_pcd = 1,
  3604. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3605. .calc_core_clk = calc_core_clk_34xx,
  3606. .num_fifos = 3,
  3607. .features = omap3_dispc_features_list,
  3608. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3609. .reg_fields = omap3_dispc_reg_fields,
  3610. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3611. .overlay_caps = omap3430_dispc_overlay_caps,
  3612. .supported_color_modes = omap3_dispc_supported_color_modes,
  3613. .num_mgrs = 2,
  3614. .num_ovls = 3,
  3615. .buffer_size_unit = 1,
  3616. .burst_size_unit = 8,
  3617. .no_framedone_tv = true,
  3618. .set_max_preload = false,
  3619. .last_pixel_inc_missing = true,
  3620. };
  3621. static const struct dispc_features omap36xx_dispc_feats = {
  3622. .sw_start = 7,
  3623. .fp_start = 19,
  3624. .bp_start = 31,
  3625. .sw_max = 256,
  3626. .vp_max = 4095,
  3627. .hp_max = 4096,
  3628. .mgr_width_start = 10,
  3629. .mgr_height_start = 26,
  3630. .mgr_width_max = 2048,
  3631. .mgr_height_max = 2048,
  3632. .max_lcd_pclk = 173000000,
  3633. .max_tv_pclk = 59000000,
  3634. .max_downscale = 4,
  3635. .max_line_width = 1024,
  3636. .min_pcd = 1,
  3637. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3638. .calc_core_clk = calc_core_clk_34xx,
  3639. .num_fifos = 3,
  3640. .features = omap3_dispc_features_list,
  3641. .num_features = ARRAY_SIZE(omap3_dispc_features_list),
  3642. .reg_fields = omap3_dispc_reg_fields,
  3643. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3644. .overlay_caps = omap3630_dispc_overlay_caps,
  3645. .supported_color_modes = omap3_dispc_supported_color_modes,
  3646. .num_mgrs = 2,
  3647. .num_ovls = 3,
  3648. .buffer_size_unit = 1,
  3649. .burst_size_unit = 8,
  3650. .no_framedone_tv = true,
  3651. .set_max_preload = false,
  3652. .last_pixel_inc_missing = true,
  3653. };
  3654. static const struct dispc_features am43xx_dispc_feats = {
  3655. .sw_start = 7,
  3656. .fp_start = 19,
  3657. .bp_start = 31,
  3658. .sw_max = 256,
  3659. .vp_max = 4095,
  3660. .hp_max = 4096,
  3661. .mgr_width_start = 10,
  3662. .mgr_height_start = 26,
  3663. .mgr_width_max = 2048,
  3664. .mgr_height_max = 2048,
  3665. .max_lcd_pclk = 173000000,
  3666. .max_tv_pclk = 59000000,
  3667. .max_downscale = 4,
  3668. .max_line_width = 1024,
  3669. .min_pcd = 1,
  3670. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3671. .calc_core_clk = calc_core_clk_34xx,
  3672. .num_fifos = 3,
  3673. .features = am43xx_dispc_features_list,
  3674. .num_features = ARRAY_SIZE(am43xx_dispc_features_list),
  3675. .reg_fields = omap3_dispc_reg_fields,
  3676. .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
  3677. .overlay_caps = omap3430_dispc_overlay_caps,
  3678. .supported_color_modes = omap3_dispc_supported_color_modes,
  3679. .num_mgrs = 1,
  3680. .num_ovls = 3,
  3681. .buffer_size_unit = 1,
  3682. .burst_size_unit = 8,
  3683. .no_framedone_tv = true,
  3684. .set_max_preload = false,
  3685. .last_pixel_inc_missing = true,
  3686. };
  3687. static const struct dispc_features omap44xx_dispc_feats = {
  3688. .sw_start = 7,
  3689. .fp_start = 19,
  3690. .bp_start = 31,
  3691. .sw_max = 256,
  3692. .vp_max = 4095,
  3693. .hp_max = 4096,
  3694. .mgr_width_start = 10,
  3695. .mgr_height_start = 26,
  3696. .mgr_width_max = 2048,
  3697. .mgr_height_max = 2048,
  3698. .max_lcd_pclk = 170000000,
  3699. .max_tv_pclk = 185625000,
  3700. .max_downscale = 4,
  3701. .max_line_width = 2048,
  3702. .min_pcd = 1,
  3703. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3704. .calc_core_clk = calc_core_clk_44xx,
  3705. .num_fifos = 5,
  3706. .features = omap4_dispc_features_list,
  3707. .num_features = ARRAY_SIZE(omap4_dispc_features_list),
  3708. .reg_fields = omap4_dispc_reg_fields,
  3709. .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
  3710. .overlay_caps = omap4_dispc_overlay_caps,
  3711. .supported_color_modes = omap4_dispc_supported_color_modes,
  3712. .num_mgrs = 3,
  3713. .num_ovls = 4,
  3714. .buffer_size_unit = 16,
  3715. .burst_size_unit = 16,
  3716. .gfx_fifo_workaround = true,
  3717. .set_max_preload = true,
  3718. .supports_sync_align = true,
  3719. .has_writeback = true,
  3720. .supports_double_pixel = true,
  3721. .reverse_ilace_field_order = true,
  3722. .has_gamma_table = true,
  3723. .has_gamma_i734_bug = true,
  3724. };
  3725. static const struct dispc_features omap54xx_dispc_feats = {
  3726. .sw_start = 7,
  3727. .fp_start = 19,
  3728. .bp_start = 31,
  3729. .sw_max = 256,
  3730. .vp_max = 4095,
  3731. .hp_max = 4096,
  3732. .mgr_width_start = 11,
  3733. .mgr_height_start = 27,
  3734. .mgr_width_max = 4096,
  3735. .mgr_height_max = 4096,
  3736. .max_lcd_pclk = 170000000,
  3737. .max_tv_pclk = 186000000,
  3738. .max_downscale = 4,
  3739. .max_line_width = 2048,
  3740. .min_pcd = 1,
  3741. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3742. .calc_core_clk = calc_core_clk_44xx,
  3743. .num_fifos = 5,
  3744. .features = omap5_dispc_features_list,
  3745. .num_features = ARRAY_SIZE(omap5_dispc_features_list),
  3746. .reg_fields = omap4_dispc_reg_fields,
  3747. .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
  3748. .overlay_caps = omap4_dispc_overlay_caps,
  3749. .supported_color_modes = omap4_dispc_supported_color_modes,
  3750. .num_mgrs = 4,
  3751. .num_ovls = 4,
  3752. .buffer_size_unit = 16,
  3753. .burst_size_unit = 16,
  3754. .gfx_fifo_workaround = true,
  3755. .mstandby_workaround = true,
  3756. .set_max_preload = true,
  3757. .supports_sync_align = true,
  3758. .has_writeback = true,
  3759. .supports_double_pixel = true,
  3760. .reverse_ilace_field_order = true,
  3761. .has_gamma_table = true,
  3762. .has_gamma_i734_bug = true,
  3763. };
  3764. static irqreturn_t dispc_irq_handler(int irq, void *arg)
  3765. {
  3766. struct dispc_device *dispc = arg;
  3767. if (!dispc->is_enabled)
  3768. return IRQ_NONE;
  3769. return dispc->user_handler(irq, dispc->user_data);
  3770. }
  3771. static int dispc_request_irq(struct dispc_device *dispc, irq_handler_t handler,
  3772. void *dev_id)
  3773. {
  3774. int r;
  3775. if (dispc->user_handler != NULL)
  3776. return -EBUSY;
  3777. dispc->user_handler = handler;
  3778. dispc->user_data = dev_id;
  3779. /* ensure the dispc_irq_handler sees the values above */
  3780. smp_wmb();
  3781. r = devm_request_irq(&dispc->pdev->dev, dispc->irq, dispc_irq_handler,
  3782. IRQF_SHARED, "OMAP DISPC", dispc);
  3783. if (r) {
  3784. dispc->user_handler = NULL;
  3785. dispc->user_data = NULL;
  3786. }
  3787. return r;
  3788. }
  3789. static void dispc_free_irq(struct dispc_device *dispc, void *dev_id)
  3790. {
  3791. devm_free_irq(&dispc->pdev->dev, dispc->irq, dispc);
  3792. dispc->user_handler = NULL;
  3793. dispc->user_data = NULL;
  3794. }
  3795. static u32 dispc_get_memory_bandwidth_limit(struct dispc_device *dispc)
  3796. {
  3797. u32 limit = 0;
  3798. /* Optional maximum memory bandwidth */
  3799. of_property_read_u32(dispc->pdev->dev.of_node, "max-memory-bandwidth",
  3800. &limit);
  3801. return limit;
  3802. }
  3803. /*
  3804. * Workaround for errata i734 in DSS dispc
  3805. * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
  3806. *
  3807. * For gamma tables to work on LCD1 the GFX plane has to be used at
  3808. * least once after DSS HW has come out of reset. The workaround
  3809. * sets up a minimal LCD setup with GFX plane and waits for one
  3810. * vertical sync irq before disabling the setup and continuing with
  3811. * the context restore. The physical outputs are gated during the
  3812. * operation. This workaround requires that gamma table's LOADMODE
  3813. * is set to 0x2 in DISPC_CONTROL1 register.
  3814. *
  3815. * For details see:
  3816. * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
  3817. * Literature Number: SWPZ037E
  3818. * Or some other relevant errata document for the DSS IP version.
  3819. */
  3820. static const struct dispc_errata_i734_data {
  3821. struct videomode vm;
  3822. struct omap_overlay_info ovli;
  3823. struct omap_overlay_manager_info mgri;
  3824. struct dss_lcd_mgr_config lcd_conf;
  3825. } i734 = {
  3826. .vm = {
  3827. .hactive = 8, .vactive = 1,
  3828. .pixelclock = 16000000,
  3829. .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
  3830. .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
  3831. .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
  3832. DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
  3833. DISPLAY_FLAGS_PIXDATA_POSEDGE,
  3834. },
  3835. .ovli = {
  3836. .screen_width = 1,
  3837. .width = 1, .height = 1,
  3838. .fourcc = DRM_FORMAT_XRGB8888,
  3839. .rotation = DRM_MODE_ROTATE_0,
  3840. .rotation_type = OMAP_DSS_ROT_NONE,
  3841. .pos_x = 0, .pos_y = 0,
  3842. .out_width = 0, .out_height = 0,
  3843. .global_alpha = 0xff,
  3844. .pre_mult_alpha = 0,
  3845. .zorder = 0,
  3846. },
  3847. .mgri = {
  3848. .default_color = 0,
  3849. .trans_enabled = false,
  3850. .partial_alpha_enabled = false,
  3851. .cpr_enable = false,
  3852. },
  3853. .lcd_conf = {
  3854. .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
  3855. .stallmode = false,
  3856. .fifohandcheck = false,
  3857. .clock_info = {
  3858. .lck_div = 1,
  3859. .pck_div = 2,
  3860. },
  3861. .video_port_width = 24,
  3862. .lcden_sig_polarity = 0,
  3863. },
  3864. };
  3865. static struct i734_buf {
  3866. size_t size;
  3867. dma_addr_t paddr;
  3868. void *vaddr;
  3869. } i734_buf;
  3870. static int dispc_errata_i734_wa_init(struct dispc_device *dispc)
  3871. {
  3872. if (!dispc->feat->has_gamma_i734_bug)
  3873. return 0;
  3874. i734_buf.size = i734.ovli.width * i734.ovli.height *
  3875. color_mode_to_bpp(i734.ovli.fourcc) / 8;
  3876. i734_buf.vaddr = dma_alloc_writecombine(&dispc->pdev->dev,
  3877. i734_buf.size, &i734_buf.paddr,
  3878. GFP_KERNEL);
  3879. if (!i734_buf.vaddr) {
  3880. dev_err(&dispc->pdev->dev, "%s: dma_alloc_writecombine failed\n",
  3881. __func__);
  3882. return -ENOMEM;
  3883. }
  3884. return 0;
  3885. }
  3886. static void dispc_errata_i734_wa_fini(struct dispc_device *dispc)
  3887. {
  3888. if (!dispc->feat->has_gamma_i734_bug)
  3889. return;
  3890. dma_free_writecombine(&dispc->pdev->dev, i734_buf.size, i734_buf.vaddr,
  3891. i734_buf.paddr);
  3892. }
  3893. static void dispc_errata_i734_wa(struct dispc_device *dispc)
  3894. {
  3895. u32 framedone_irq = dispc_mgr_get_framedone_irq(dispc,
  3896. OMAP_DSS_CHANNEL_LCD);
  3897. struct omap_overlay_info ovli;
  3898. struct dss_lcd_mgr_config lcd_conf;
  3899. u32 gatestate;
  3900. unsigned int count;
  3901. if (!dispc->feat->has_gamma_i734_bug)
  3902. return;
  3903. gatestate = REG_GET(dispc, DISPC_CONFIG, 8, 4);
  3904. ovli = i734.ovli;
  3905. ovli.paddr = i734_buf.paddr;
  3906. lcd_conf = i734.lcd_conf;
  3907. /* Gate all LCD1 outputs */
  3908. REG_FLD_MOD(dispc, DISPC_CONFIG, 0x1f, 8, 4);
  3909. /* Setup and enable GFX plane */
  3910. dispc_ovl_setup(dispc, OMAP_DSS_GFX, &ovli, &i734.vm, false,
  3911. OMAP_DSS_CHANNEL_LCD);
  3912. dispc_ovl_enable(dispc, OMAP_DSS_GFX, true);
  3913. /* Set up and enable display manager for LCD1 */
  3914. dispc_mgr_setup(dispc, OMAP_DSS_CHANNEL_LCD, &i734.mgri);
  3915. dispc_calc_clock_rates(dispc, dss_get_dispc_clk_rate(dispc->dss),
  3916. &lcd_conf.clock_info);
  3917. dispc_mgr_set_lcd_config(dispc, OMAP_DSS_CHANNEL_LCD, &lcd_conf);
  3918. dispc_mgr_set_timings(dispc, OMAP_DSS_CHANNEL_LCD, &i734.vm);
  3919. dispc_clear_irqstatus(dispc, framedone_irq);
  3920. /* Enable and shut the channel to produce just one frame */
  3921. dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, true);
  3922. dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, false);
  3923. /* Busy wait for framedone. We can't fiddle with irq handlers
  3924. * in PM resume. Typically the loop runs less than 5 times and
  3925. * waits less than a micro second.
  3926. */
  3927. count = 0;
  3928. while (!(dispc_read_irqstatus(dispc) & framedone_irq)) {
  3929. if (count++ > 10000) {
  3930. dev_err(&dispc->pdev->dev, "%s: framedone timeout\n",
  3931. __func__);
  3932. break;
  3933. }
  3934. }
  3935. dispc_ovl_enable(dispc, OMAP_DSS_GFX, false);
  3936. /* Clear all irq bits before continuing */
  3937. dispc_clear_irqstatus(dispc, 0xffffffff);
  3938. /* Restore the original state to LCD1 output gates */
  3939. REG_FLD_MOD(dispc, DISPC_CONFIG, gatestate, 8, 4);
  3940. }
  3941. static const struct dispc_ops dispc_ops = {
  3942. .read_irqstatus = dispc_read_irqstatus,
  3943. .clear_irqstatus = dispc_clear_irqstatus,
  3944. .write_irqenable = dispc_write_irqenable,
  3945. .request_irq = dispc_request_irq,
  3946. .free_irq = dispc_free_irq,
  3947. .runtime_get = dispc_runtime_get,
  3948. .runtime_put = dispc_runtime_put,
  3949. .get_num_ovls = dispc_get_num_ovls,
  3950. .get_num_mgrs = dispc_get_num_mgrs,
  3951. .get_memory_bandwidth_limit = dispc_get_memory_bandwidth_limit,
  3952. .mgr_enable = dispc_mgr_enable,
  3953. .mgr_is_enabled = dispc_mgr_is_enabled,
  3954. .mgr_get_vsync_irq = dispc_mgr_get_vsync_irq,
  3955. .mgr_get_framedone_irq = dispc_mgr_get_framedone_irq,
  3956. .mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq,
  3957. .mgr_go_busy = dispc_mgr_go_busy,
  3958. .mgr_go = dispc_mgr_go,
  3959. .mgr_set_lcd_config = dispc_mgr_set_lcd_config,
  3960. .mgr_check_timings = dispc_mgr_check_timings,
  3961. .mgr_set_timings = dispc_mgr_set_timings,
  3962. .mgr_setup = dispc_mgr_setup,
  3963. .mgr_gamma_size = dispc_mgr_gamma_size,
  3964. .mgr_set_gamma = dispc_mgr_set_gamma,
  3965. .ovl_enable = dispc_ovl_enable,
  3966. .ovl_setup = dispc_ovl_setup,
  3967. .ovl_get_color_modes = dispc_ovl_get_color_modes,
  3968. .wb_get_framedone_irq = dispc_wb_get_framedone_irq,
  3969. .wb_setup = dispc_wb_setup,
  3970. .has_writeback = dispc_has_writeback,
  3971. .wb_go_busy = dispc_wb_go_busy,
  3972. .wb_go = dispc_wb_go,
  3973. };
  3974. /* DISPC HW IP initialisation */
  3975. static const struct of_device_id dispc_of_match[] = {
  3976. { .compatible = "ti,omap2-dispc", .data = &omap24xx_dispc_feats },
  3977. { .compatible = "ti,omap3-dispc", .data = &omap36xx_dispc_feats },
  3978. { .compatible = "ti,omap4-dispc", .data = &omap44xx_dispc_feats },
  3979. { .compatible = "ti,omap5-dispc", .data = &omap54xx_dispc_feats },
  3980. { .compatible = "ti,dra7-dispc", .data = &omap54xx_dispc_feats },
  3981. {},
  3982. };
  3983. static const struct soc_device_attribute dispc_soc_devices[] = {
  3984. { .machine = "OMAP3[45]*",
  3985. .revision = "ES[12].?", .data = &omap34xx_rev1_0_dispc_feats },
  3986. { .machine = "OMAP3[45]*", .data = &omap34xx_rev3_0_dispc_feats },
  3987. { .machine = "AM35*", .data = &omap34xx_rev3_0_dispc_feats },
  3988. { .machine = "AM43*", .data = &am43xx_dispc_feats },
  3989. { /* sentinel */ }
  3990. };
  3991. static int dispc_bind(struct device *dev, struct device *master, void *data)
  3992. {
  3993. struct platform_device *pdev = to_platform_device(dev);
  3994. const struct soc_device_attribute *soc;
  3995. struct dss_device *dss = dss_get_device(master);
  3996. struct dispc_device *dispc;
  3997. u32 rev;
  3998. int r = 0;
  3999. struct resource *dispc_mem;
  4000. struct device_node *np = pdev->dev.of_node;
  4001. dispc = kzalloc(sizeof(*dispc), GFP_KERNEL);
  4002. if (!dispc)
  4003. return -ENOMEM;
  4004. dispc->pdev = pdev;
  4005. platform_set_drvdata(pdev, dispc);
  4006. dispc->dss = dss;
  4007. spin_lock_init(&dispc->control_lock);
  4008. /*
  4009. * The OMAP3-based models can't be told apart using the compatible
  4010. * string, use SoC device matching.
  4011. */
  4012. soc = soc_device_match(dispc_soc_devices);
  4013. if (soc)
  4014. dispc->feat = soc->data;
  4015. else
  4016. dispc->feat = of_match_device(dispc_of_match, &pdev->dev)->data;
  4017. r = dispc_errata_i734_wa_init(dispc);
  4018. if (r)
  4019. goto err_free;
  4020. dispc_mem = platform_get_resource(dispc->pdev, IORESOURCE_MEM, 0);
  4021. dispc->base = devm_ioremap_resource(&pdev->dev, dispc_mem);
  4022. if (IS_ERR(dispc->base)) {
  4023. r = PTR_ERR(dispc->base);
  4024. goto err_free;
  4025. }
  4026. dispc->irq = platform_get_irq(dispc->pdev, 0);
  4027. if (dispc->irq < 0) {
  4028. DSSERR("platform_get_irq failed\n");
  4029. r = -ENODEV;
  4030. goto err_free;
  4031. }
  4032. if (np && of_property_read_bool(np, "syscon-pol")) {
  4033. dispc->syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
  4034. if (IS_ERR(dispc->syscon_pol)) {
  4035. dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
  4036. r = PTR_ERR(dispc->syscon_pol);
  4037. goto err_free;
  4038. }
  4039. if (of_property_read_u32_index(np, "syscon-pol", 1,
  4040. &dispc->syscon_pol_offset)) {
  4041. dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
  4042. r = -EINVAL;
  4043. goto err_free;
  4044. }
  4045. }
  4046. r = dispc_init_gamma_tables(dispc);
  4047. if (r)
  4048. goto err_free;
  4049. pm_runtime_enable(&pdev->dev);
  4050. r = dispc_runtime_get(dispc);
  4051. if (r)
  4052. goto err_runtime_get;
  4053. _omap_dispc_initial_config(dispc);
  4054. rev = dispc_read_reg(dispc, DISPC_REVISION);
  4055. dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
  4056. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  4057. dispc_runtime_put(dispc);
  4058. dss->dispc = dispc;
  4059. dss->dispc_ops = &dispc_ops;
  4060. dispc->debugfs = dss_debugfs_create_file(dss, "dispc", dispc_dump_regs,
  4061. dispc);
  4062. return 0;
  4063. err_runtime_get:
  4064. pm_runtime_disable(&pdev->dev);
  4065. err_free:
  4066. kfree(dispc);
  4067. return r;
  4068. }
  4069. static void dispc_unbind(struct device *dev, struct device *master, void *data)
  4070. {
  4071. struct dispc_device *dispc = dev_get_drvdata(dev);
  4072. struct dss_device *dss = dispc->dss;
  4073. dss_debugfs_remove_file(dispc->debugfs);
  4074. dss->dispc = NULL;
  4075. dss->dispc_ops = NULL;
  4076. pm_runtime_disable(dev);
  4077. dispc_errata_i734_wa_fini(dispc);
  4078. kfree(dispc);
  4079. }
  4080. static const struct component_ops dispc_component_ops = {
  4081. .bind = dispc_bind,
  4082. .unbind = dispc_unbind,
  4083. };
  4084. static int dispc_probe(struct platform_device *pdev)
  4085. {
  4086. return component_add(&pdev->dev, &dispc_component_ops);
  4087. }
  4088. static int dispc_remove(struct platform_device *pdev)
  4089. {
  4090. component_del(&pdev->dev, &dispc_component_ops);
  4091. return 0;
  4092. }
  4093. static int dispc_runtime_suspend(struct device *dev)
  4094. {
  4095. struct dispc_device *dispc = dev_get_drvdata(dev);
  4096. dispc->is_enabled = false;
  4097. /* ensure the dispc_irq_handler sees the is_enabled value */
  4098. smp_wmb();
  4099. /* wait for current handler to finish before turning the DISPC off */
  4100. synchronize_irq(dispc->irq);
  4101. dispc_save_context(dispc);
  4102. return 0;
  4103. }
  4104. static int dispc_runtime_resume(struct device *dev)
  4105. {
  4106. struct dispc_device *dispc = dev_get_drvdata(dev);
  4107. /*
  4108. * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
  4109. * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
  4110. * _omap_dispc_initial_config(). We can thus use it to detect if
  4111. * we have lost register context.
  4112. */
  4113. if (REG_GET(dispc, DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
  4114. _omap_dispc_initial_config(dispc);
  4115. dispc_errata_i734_wa(dispc);
  4116. dispc_restore_context(dispc);
  4117. dispc_restore_gamma_tables(dispc);
  4118. }
  4119. dispc->is_enabled = true;
  4120. /* ensure the dispc_irq_handler sees the is_enabled value */
  4121. smp_wmb();
  4122. return 0;
  4123. }
  4124. static const struct dev_pm_ops dispc_pm_ops = {
  4125. .runtime_suspend = dispc_runtime_suspend,
  4126. .runtime_resume = dispc_runtime_resume,
  4127. };
  4128. struct platform_driver omap_dispchw_driver = {
  4129. .probe = dispc_probe,
  4130. .remove = dispc_remove,
  4131. .driver = {
  4132. .name = "omapdss_dispc",
  4133. .pm = &dispc_pm_ops,
  4134. .of_match_table = dispc_of_match,
  4135. .suppress_bind_attrs = true,
  4136. },
  4137. };