dispc.c 103 KB

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