dispc.c 102 KB

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