dispc.c 90 KB

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