dispc.c 98 KB

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