dispc.c 109 KB

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