dispc.c 105 KB

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