dispc.c 102 KB

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