dispc.c 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063
  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. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
  1229. return;
  1230. }
  1231. dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
  1232. out_height, ilace, color_mode, rotation);
  1233. switch (color_mode) {
  1234. case OMAP_DSS_COLOR_NV12:
  1235. if (chroma_upscale) {
  1236. /* UV is subsampled by 2 horizontally and vertically */
  1237. orig_height >>= 1;
  1238. orig_width >>= 1;
  1239. } else {
  1240. /* UV is downsampled by 2 horizontally and vertically */
  1241. orig_height <<= 1;
  1242. orig_width <<= 1;
  1243. }
  1244. break;
  1245. case OMAP_DSS_COLOR_YUV2:
  1246. case OMAP_DSS_COLOR_UYVY:
  1247. /* For YUV422 with 90/270 rotation, we don't upsample chroma */
  1248. if (rotation == OMAP_DSS_ROT_0 ||
  1249. rotation == OMAP_DSS_ROT_180) {
  1250. if (chroma_upscale)
  1251. /* UV is subsampled by 2 horizontally */
  1252. orig_width >>= 1;
  1253. else
  1254. /* UV is downsampled by 2 horizontally */
  1255. orig_width <<= 1;
  1256. }
  1257. /* must use FIR for YUV422 if rotated */
  1258. if (rotation != OMAP_DSS_ROT_0)
  1259. scale_x = scale_y = true;
  1260. break;
  1261. default:
  1262. BUG();
  1263. return;
  1264. }
  1265. if (out_width != orig_width)
  1266. scale_x = true;
  1267. if (out_height != orig_height)
  1268. scale_y = true;
  1269. dispc_ovl_set_scale_param(plane, orig_width, orig_height,
  1270. out_width, out_height, five_taps,
  1271. rotation, DISPC_COLOR_COMPONENT_UV);
  1272. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
  1273. (scale_x || scale_y) ? 1 : 0, 8, 8);
  1274. /* set H scaling */
  1275. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
  1276. /* set V scaling */
  1277. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
  1278. }
  1279. static void dispc_ovl_set_scaling(enum omap_plane plane,
  1280. u16 orig_width, u16 orig_height,
  1281. u16 out_width, u16 out_height,
  1282. bool ilace, bool five_taps,
  1283. bool fieldmode, enum omap_color_mode color_mode,
  1284. u8 rotation)
  1285. {
  1286. BUG_ON(plane == OMAP_DSS_GFX);
  1287. dispc_ovl_set_scaling_common(plane,
  1288. orig_width, orig_height,
  1289. out_width, out_height,
  1290. ilace, five_taps,
  1291. fieldmode, color_mode,
  1292. rotation);
  1293. dispc_ovl_set_scaling_uv(plane,
  1294. orig_width, orig_height,
  1295. out_width, out_height,
  1296. ilace, five_taps,
  1297. fieldmode, color_mode,
  1298. rotation);
  1299. }
  1300. static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
  1301. bool mirroring, enum omap_color_mode color_mode)
  1302. {
  1303. bool row_repeat = false;
  1304. int vidrot = 0;
  1305. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1306. color_mode == OMAP_DSS_COLOR_UYVY) {
  1307. if (mirroring) {
  1308. switch (rotation) {
  1309. case OMAP_DSS_ROT_0:
  1310. vidrot = 2;
  1311. break;
  1312. case OMAP_DSS_ROT_90:
  1313. vidrot = 1;
  1314. break;
  1315. case OMAP_DSS_ROT_180:
  1316. vidrot = 0;
  1317. break;
  1318. case OMAP_DSS_ROT_270:
  1319. vidrot = 3;
  1320. break;
  1321. }
  1322. } else {
  1323. switch (rotation) {
  1324. case OMAP_DSS_ROT_0:
  1325. vidrot = 0;
  1326. break;
  1327. case OMAP_DSS_ROT_90:
  1328. vidrot = 1;
  1329. break;
  1330. case OMAP_DSS_ROT_180:
  1331. vidrot = 2;
  1332. break;
  1333. case OMAP_DSS_ROT_270:
  1334. vidrot = 3;
  1335. break;
  1336. }
  1337. }
  1338. if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
  1339. row_repeat = true;
  1340. else
  1341. row_repeat = false;
  1342. }
  1343. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
  1344. if (dss_has_feature(FEAT_ROWREPEATENABLE))
  1345. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
  1346. row_repeat ? 1 : 0, 18, 18);
  1347. }
  1348. static int color_mode_to_bpp(enum omap_color_mode color_mode)
  1349. {
  1350. switch (color_mode) {
  1351. case OMAP_DSS_COLOR_CLUT1:
  1352. return 1;
  1353. case OMAP_DSS_COLOR_CLUT2:
  1354. return 2;
  1355. case OMAP_DSS_COLOR_CLUT4:
  1356. return 4;
  1357. case OMAP_DSS_COLOR_CLUT8:
  1358. case OMAP_DSS_COLOR_NV12:
  1359. return 8;
  1360. case OMAP_DSS_COLOR_RGB12U:
  1361. case OMAP_DSS_COLOR_RGB16:
  1362. case OMAP_DSS_COLOR_ARGB16:
  1363. case OMAP_DSS_COLOR_YUV2:
  1364. case OMAP_DSS_COLOR_UYVY:
  1365. case OMAP_DSS_COLOR_RGBA16:
  1366. case OMAP_DSS_COLOR_RGBX16:
  1367. case OMAP_DSS_COLOR_ARGB16_1555:
  1368. case OMAP_DSS_COLOR_XRGB16_1555:
  1369. return 16;
  1370. case OMAP_DSS_COLOR_RGB24P:
  1371. return 24;
  1372. case OMAP_DSS_COLOR_RGB24U:
  1373. case OMAP_DSS_COLOR_ARGB32:
  1374. case OMAP_DSS_COLOR_RGBA32:
  1375. case OMAP_DSS_COLOR_RGBX32:
  1376. return 32;
  1377. default:
  1378. BUG();
  1379. return 0;
  1380. }
  1381. }
  1382. static s32 pixinc(int pixels, u8 ps)
  1383. {
  1384. if (pixels == 1)
  1385. return 1;
  1386. else if (pixels > 1)
  1387. return 1 + (pixels - 1) * ps;
  1388. else if (pixels < 0)
  1389. return 1 - (-pixels + 1) * ps;
  1390. else
  1391. BUG();
  1392. return 0;
  1393. }
  1394. static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
  1395. u16 screen_width,
  1396. u16 width, u16 height,
  1397. enum omap_color_mode color_mode, bool fieldmode,
  1398. unsigned int field_offset,
  1399. unsigned *offset0, unsigned *offset1,
  1400. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
  1401. {
  1402. u8 ps;
  1403. /* FIXME CLUT formats */
  1404. switch (color_mode) {
  1405. case OMAP_DSS_COLOR_CLUT1:
  1406. case OMAP_DSS_COLOR_CLUT2:
  1407. case OMAP_DSS_COLOR_CLUT4:
  1408. case OMAP_DSS_COLOR_CLUT8:
  1409. BUG();
  1410. return;
  1411. case OMAP_DSS_COLOR_YUV2:
  1412. case OMAP_DSS_COLOR_UYVY:
  1413. ps = 4;
  1414. break;
  1415. default:
  1416. ps = color_mode_to_bpp(color_mode) / 8;
  1417. break;
  1418. }
  1419. DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
  1420. width, height);
  1421. /*
  1422. * field 0 = even field = bottom field
  1423. * field 1 = odd field = top field
  1424. */
  1425. switch (rotation + mirror * 4) {
  1426. case OMAP_DSS_ROT_0:
  1427. case OMAP_DSS_ROT_180:
  1428. /*
  1429. * If the pixel format is YUV or UYVY divide the width
  1430. * of the image by 2 for 0 and 180 degree rotation.
  1431. */
  1432. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1433. color_mode == OMAP_DSS_COLOR_UYVY)
  1434. width = width >> 1;
  1435. case OMAP_DSS_ROT_90:
  1436. case OMAP_DSS_ROT_270:
  1437. *offset1 = 0;
  1438. if (field_offset)
  1439. *offset0 = field_offset * screen_width * ps;
  1440. else
  1441. *offset0 = 0;
  1442. *row_inc = pixinc(1 +
  1443. (y_predecim * screen_width - x_predecim * width) +
  1444. (fieldmode ? screen_width : 0), ps);
  1445. *pix_inc = pixinc(x_predecim, ps);
  1446. break;
  1447. case OMAP_DSS_ROT_0 + 4:
  1448. case OMAP_DSS_ROT_180 + 4:
  1449. /* If the pixel format is YUV or UYVY divide the width
  1450. * of the image by 2 for 0 degree and 180 degree
  1451. */
  1452. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1453. color_mode == OMAP_DSS_COLOR_UYVY)
  1454. width = width >> 1;
  1455. case OMAP_DSS_ROT_90 + 4:
  1456. case OMAP_DSS_ROT_270 + 4:
  1457. *offset1 = 0;
  1458. if (field_offset)
  1459. *offset0 = field_offset * screen_width * ps;
  1460. else
  1461. *offset0 = 0;
  1462. *row_inc = pixinc(1 -
  1463. (y_predecim * screen_width + x_predecim * width) -
  1464. (fieldmode ? screen_width : 0), ps);
  1465. *pix_inc = pixinc(x_predecim, ps);
  1466. break;
  1467. default:
  1468. BUG();
  1469. return;
  1470. }
  1471. }
  1472. static void calc_dma_rotation_offset(u8 rotation, bool mirror,
  1473. u16 screen_width,
  1474. u16 width, u16 height,
  1475. enum omap_color_mode color_mode, bool fieldmode,
  1476. unsigned int field_offset,
  1477. unsigned *offset0, unsigned *offset1,
  1478. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
  1479. {
  1480. u8 ps;
  1481. u16 fbw, fbh;
  1482. /* FIXME CLUT formats */
  1483. switch (color_mode) {
  1484. case OMAP_DSS_COLOR_CLUT1:
  1485. case OMAP_DSS_COLOR_CLUT2:
  1486. case OMAP_DSS_COLOR_CLUT4:
  1487. case OMAP_DSS_COLOR_CLUT8:
  1488. BUG();
  1489. return;
  1490. default:
  1491. ps = color_mode_to_bpp(color_mode) / 8;
  1492. break;
  1493. }
  1494. DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
  1495. width, height);
  1496. /* width & height are overlay sizes, convert to fb sizes */
  1497. if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
  1498. fbw = width;
  1499. fbh = height;
  1500. } else {
  1501. fbw = height;
  1502. fbh = width;
  1503. }
  1504. /*
  1505. * field 0 = even field = bottom field
  1506. * field 1 = odd field = top field
  1507. */
  1508. switch (rotation + mirror * 4) {
  1509. case OMAP_DSS_ROT_0:
  1510. *offset1 = 0;
  1511. if (field_offset)
  1512. *offset0 = *offset1 + field_offset * screen_width * ps;
  1513. else
  1514. *offset0 = *offset1;
  1515. *row_inc = pixinc(1 +
  1516. (y_predecim * screen_width - fbw * x_predecim) +
  1517. (fieldmode ? screen_width : 0), ps);
  1518. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1519. color_mode == OMAP_DSS_COLOR_UYVY)
  1520. *pix_inc = pixinc(x_predecim, 2 * ps);
  1521. else
  1522. *pix_inc = pixinc(x_predecim, ps);
  1523. break;
  1524. case OMAP_DSS_ROT_90:
  1525. *offset1 = screen_width * (fbh - 1) * ps;
  1526. if (field_offset)
  1527. *offset0 = *offset1 + field_offset * ps;
  1528. else
  1529. *offset0 = *offset1;
  1530. *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
  1531. y_predecim + (fieldmode ? 1 : 0), ps);
  1532. *pix_inc = pixinc(-x_predecim * screen_width, ps);
  1533. break;
  1534. case OMAP_DSS_ROT_180:
  1535. *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
  1536. if (field_offset)
  1537. *offset0 = *offset1 - field_offset * screen_width * ps;
  1538. else
  1539. *offset0 = *offset1;
  1540. *row_inc = pixinc(-1 -
  1541. (y_predecim * screen_width - fbw * x_predecim) -
  1542. (fieldmode ? screen_width : 0), ps);
  1543. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1544. color_mode == OMAP_DSS_COLOR_UYVY)
  1545. *pix_inc = pixinc(-x_predecim, 2 * ps);
  1546. else
  1547. *pix_inc = pixinc(-x_predecim, ps);
  1548. break;
  1549. case OMAP_DSS_ROT_270:
  1550. *offset1 = (fbw - 1) * ps;
  1551. if (field_offset)
  1552. *offset0 = *offset1 - field_offset * ps;
  1553. else
  1554. *offset0 = *offset1;
  1555. *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
  1556. y_predecim - (fieldmode ? 1 : 0), ps);
  1557. *pix_inc = pixinc(x_predecim * screen_width, ps);
  1558. break;
  1559. /* mirroring */
  1560. case OMAP_DSS_ROT_0 + 4:
  1561. *offset1 = (fbw - 1) * ps;
  1562. if (field_offset)
  1563. *offset0 = *offset1 + field_offset * screen_width * ps;
  1564. else
  1565. *offset0 = *offset1;
  1566. *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
  1567. (fieldmode ? screen_width : 0),
  1568. ps);
  1569. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1570. color_mode == OMAP_DSS_COLOR_UYVY)
  1571. *pix_inc = pixinc(-x_predecim, 2 * ps);
  1572. else
  1573. *pix_inc = pixinc(-x_predecim, ps);
  1574. break;
  1575. case OMAP_DSS_ROT_90 + 4:
  1576. *offset1 = 0;
  1577. if (field_offset)
  1578. *offset0 = *offset1 + field_offset * ps;
  1579. else
  1580. *offset0 = *offset1;
  1581. *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
  1582. y_predecim + (fieldmode ? 1 : 0),
  1583. ps);
  1584. *pix_inc = pixinc(x_predecim * screen_width, ps);
  1585. break;
  1586. case OMAP_DSS_ROT_180 + 4:
  1587. *offset1 = screen_width * (fbh - 1) * ps;
  1588. if (field_offset)
  1589. *offset0 = *offset1 - field_offset * screen_width * ps;
  1590. else
  1591. *offset0 = *offset1;
  1592. *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
  1593. (fieldmode ? screen_width : 0),
  1594. ps);
  1595. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1596. color_mode == OMAP_DSS_COLOR_UYVY)
  1597. *pix_inc = pixinc(x_predecim, 2 * ps);
  1598. else
  1599. *pix_inc = pixinc(x_predecim, ps);
  1600. break;
  1601. case OMAP_DSS_ROT_270 + 4:
  1602. *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
  1603. if (field_offset)
  1604. *offset0 = *offset1 - field_offset * ps;
  1605. else
  1606. *offset0 = *offset1;
  1607. *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
  1608. y_predecim - (fieldmode ? 1 : 0),
  1609. ps);
  1610. *pix_inc = pixinc(-x_predecim * screen_width, ps);
  1611. break;
  1612. default:
  1613. BUG();
  1614. return;
  1615. }
  1616. }
  1617. static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
  1618. enum omap_color_mode color_mode, bool fieldmode,
  1619. unsigned int field_offset, unsigned *offset0, unsigned *offset1,
  1620. s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
  1621. {
  1622. u8 ps;
  1623. switch (color_mode) {
  1624. case OMAP_DSS_COLOR_CLUT1:
  1625. case OMAP_DSS_COLOR_CLUT2:
  1626. case OMAP_DSS_COLOR_CLUT4:
  1627. case OMAP_DSS_COLOR_CLUT8:
  1628. BUG();
  1629. return;
  1630. default:
  1631. ps = color_mode_to_bpp(color_mode) / 8;
  1632. break;
  1633. }
  1634. DSSDBG("scrw %d, width %d\n", screen_width, width);
  1635. /*
  1636. * field 0 = even field = bottom field
  1637. * field 1 = odd field = top field
  1638. */
  1639. *offset1 = 0;
  1640. if (field_offset)
  1641. *offset0 = *offset1 + field_offset * screen_width * ps;
  1642. else
  1643. *offset0 = *offset1;
  1644. *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
  1645. (fieldmode ? screen_width : 0), ps);
  1646. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  1647. color_mode == OMAP_DSS_COLOR_UYVY)
  1648. *pix_inc = pixinc(x_predecim, 2 * ps);
  1649. else
  1650. *pix_inc = pixinc(x_predecim, ps);
  1651. }
  1652. /*
  1653. * This function is used to avoid synclosts in OMAP3, because of some
  1654. * undocumented horizontal position and timing related limitations.
  1655. */
  1656. static int check_horiz_timing_omap3(enum omap_plane plane,
  1657. const struct omap_video_timings *t, u16 pos_x,
  1658. u16 width, u16 height, u16 out_width, u16 out_height)
  1659. {
  1660. int DS = DIV_ROUND_UP(height, out_height);
  1661. unsigned long nonactive;
  1662. static const u8 limits[3] = { 8, 10, 20 };
  1663. u64 val, blank;
  1664. unsigned long pclk = dispc_plane_pclk_rate(plane);
  1665. unsigned long lclk = dispc_plane_lclk_rate(plane);
  1666. int i;
  1667. nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
  1668. i = 0;
  1669. if (out_height < height)
  1670. i++;
  1671. if (out_width < width)
  1672. i++;
  1673. blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
  1674. DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
  1675. if (blank <= limits[i])
  1676. return -EINVAL;
  1677. /*
  1678. * Pixel data should be prepared before visible display point starts.
  1679. * So, atleast DS-2 lines must have already been fetched by DISPC
  1680. * during nonactive - pos_x period.
  1681. */
  1682. val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
  1683. DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
  1684. val, max(0, DS - 2) * width);
  1685. if (val < max(0, DS - 2) * width)
  1686. return -EINVAL;
  1687. /*
  1688. * All lines need to be refilled during the nonactive period of which
  1689. * only one line can be loaded during the active period. So, atleast
  1690. * DS - 1 lines should be loaded during nonactive period.
  1691. */
  1692. val = div_u64((u64)nonactive * lclk, pclk);
  1693. DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
  1694. val, max(0, DS - 1) * width);
  1695. if (val < max(0, DS - 1) * width)
  1696. return -EINVAL;
  1697. return 0;
  1698. }
  1699. static unsigned long calc_core_clk_five_taps(enum omap_plane plane,
  1700. const struct omap_video_timings *mgr_timings, u16 width,
  1701. u16 height, u16 out_width, u16 out_height,
  1702. enum omap_color_mode color_mode)
  1703. {
  1704. u32 core_clk = 0;
  1705. u64 tmp;
  1706. unsigned long pclk = dispc_plane_pclk_rate(plane);
  1707. if (height <= out_height && width <= out_width)
  1708. return (unsigned long) pclk;
  1709. if (height > out_height) {
  1710. unsigned int ppl = mgr_timings->x_res;
  1711. tmp = pclk * height * out_width;
  1712. do_div(tmp, 2 * out_height * ppl);
  1713. core_clk = tmp;
  1714. if (height > 2 * out_height) {
  1715. if (ppl == out_width)
  1716. return 0;
  1717. tmp = pclk * (height - 2 * out_height) * out_width;
  1718. do_div(tmp, 2 * out_height * (ppl - out_width));
  1719. core_clk = max_t(u32, core_clk, tmp);
  1720. }
  1721. }
  1722. if (width > out_width) {
  1723. tmp = pclk * width;
  1724. do_div(tmp, out_width);
  1725. core_clk = max_t(u32, core_clk, tmp);
  1726. if (color_mode == OMAP_DSS_COLOR_RGB24U)
  1727. core_clk <<= 1;
  1728. }
  1729. return core_clk;
  1730. }
  1731. static unsigned long calc_core_clk_24xx(enum omap_plane plane, u16 width,
  1732. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1733. {
  1734. unsigned long pclk = dispc_plane_pclk_rate(plane);
  1735. if (height > out_height && width > out_width)
  1736. return pclk * 4;
  1737. else
  1738. return pclk * 2;
  1739. }
  1740. static unsigned long calc_core_clk_34xx(enum omap_plane plane, u16 width,
  1741. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1742. {
  1743. unsigned int hf, vf;
  1744. unsigned long pclk = dispc_plane_pclk_rate(plane);
  1745. /*
  1746. * FIXME how to determine the 'A' factor
  1747. * for the no downscaling case ?
  1748. */
  1749. if (width > 3 * out_width)
  1750. hf = 4;
  1751. else if (width > 2 * out_width)
  1752. hf = 3;
  1753. else if (width > out_width)
  1754. hf = 2;
  1755. else
  1756. hf = 1;
  1757. if (height > out_height)
  1758. vf = 2;
  1759. else
  1760. vf = 1;
  1761. return pclk * vf * hf;
  1762. }
  1763. static unsigned long calc_core_clk_44xx(enum omap_plane plane, u16 width,
  1764. u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
  1765. {
  1766. unsigned long pclk;
  1767. /*
  1768. * If the overlay/writeback is in mem to mem mode, there are no
  1769. * downscaling limitations with respect to pixel clock, return 1 as
  1770. * required core clock to represent that we have sufficient enough
  1771. * core clock to do maximum downscaling
  1772. */
  1773. if (mem_to_mem)
  1774. return 1;
  1775. pclk = dispc_plane_pclk_rate(plane);
  1776. if (width > out_width)
  1777. return DIV_ROUND_UP(pclk, out_width) * width;
  1778. else
  1779. return pclk;
  1780. }
  1781. static int dispc_ovl_calc_scaling_24xx(enum omap_plane plane,
  1782. const struct omap_video_timings *mgr_timings,
  1783. u16 width, u16 height, u16 out_width, u16 out_height,
  1784. enum omap_color_mode color_mode, bool *five_taps,
  1785. int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
  1786. u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
  1787. {
  1788. int error;
  1789. u16 in_width, in_height;
  1790. int min_factor = min(*decim_x, *decim_y);
  1791. const int maxsinglelinewidth =
  1792. dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
  1793. *five_taps = false;
  1794. do {
  1795. in_height = DIV_ROUND_UP(height, *decim_y);
  1796. in_width = DIV_ROUND_UP(width, *decim_x);
  1797. *core_clk = dispc.feat->calc_core_clk(plane, in_width,
  1798. in_height, out_width, out_height, mem_to_mem);
  1799. error = (in_width > maxsinglelinewidth || !*core_clk ||
  1800. *core_clk > dispc_core_clk_rate());
  1801. if (error) {
  1802. if (*decim_x == *decim_y) {
  1803. *decim_x = min_factor;
  1804. ++*decim_y;
  1805. } else {
  1806. swap(*decim_x, *decim_y);
  1807. if (*decim_x < *decim_y)
  1808. ++*decim_x;
  1809. }
  1810. }
  1811. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  1812. if (in_width > maxsinglelinewidth) {
  1813. DSSERR("Cannot scale max input width exceeded");
  1814. return -EINVAL;
  1815. }
  1816. return 0;
  1817. }
  1818. static int dispc_ovl_calc_scaling_34xx(enum omap_plane plane,
  1819. const struct omap_video_timings *mgr_timings,
  1820. u16 width, u16 height, u16 out_width, u16 out_height,
  1821. enum omap_color_mode color_mode, bool *five_taps,
  1822. int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
  1823. u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
  1824. {
  1825. int error;
  1826. u16 in_width, in_height;
  1827. int min_factor = min(*decim_x, *decim_y);
  1828. const int maxsinglelinewidth =
  1829. dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
  1830. do {
  1831. in_height = DIV_ROUND_UP(height, *decim_y);
  1832. in_width = DIV_ROUND_UP(width, *decim_x);
  1833. *core_clk = calc_core_clk_five_taps(plane, mgr_timings,
  1834. in_width, in_height, out_width, out_height, color_mode);
  1835. error = check_horiz_timing_omap3(plane, mgr_timings,
  1836. pos_x, in_width, in_height, out_width,
  1837. out_height);
  1838. if (in_width > maxsinglelinewidth)
  1839. if (in_height > out_height &&
  1840. in_height < out_height * 2)
  1841. *five_taps = false;
  1842. if (!*five_taps)
  1843. *core_clk = dispc.feat->calc_core_clk(plane, in_width,
  1844. in_height, out_width, out_height,
  1845. mem_to_mem);
  1846. error = (error || in_width > maxsinglelinewidth * 2 ||
  1847. (in_width > maxsinglelinewidth && *five_taps) ||
  1848. !*core_clk || *core_clk > dispc_core_clk_rate());
  1849. if (error) {
  1850. if (*decim_x == *decim_y) {
  1851. *decim_x = min_factor;
  1852. ++*decim_y;
  1853. } else {
  1854. swap(*decim_x, *decim_y);
  1855. if (*decim_x < *decim_y)
  1856. ++*decim_x;
  1857. }
  1858. }
  1859. } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
  1860. if (check_horiz_timing_omap3(plane, mgr_timings, pos_x, width, height,
  1861. out_width, out_height)){
  1862. DSSERR("horizontal timing too tight\n");
  1863. return -EINVAL;
  1864. }
  1865. if (in_width > (maxsinglelinewidth * 2)) {
  1866. DSSERR("Cannot setup scaling");
  1867. DSSERR("width exceeds maximum width possible");
  1868. return -EINVAL;
  1869. }
  1870. if (in_width > maxsinglelinewidth && *five_taps) {
  1871. DSSERR("cannot setup scaling with five taps");
  1872. return -EINVAL;
  1873. }
  1874. return 0;
  1875. }
  1876. static int dispc_ovl_calc_scaling_44xx(enum omap_plane plane,
  1877. const struct omap_video_timings *mgr_timings,
  1878. u16 width, u16 height, u16 out_width, u16 out_height,
  1879. enum omap_color_mode color_mode, bool *five_taps,
  1880. int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
  1881. u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
  1882. {
  1883. u16 in_width, in_width_max;
  1884. int decim_x_min = *decim_x;
  1885. u16 in_height = DIV_ROUND_UP(height, *decim_y);
  1886. const int maxsinglelinewidth =
  1887. dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
  1888. unsigned long pclk = dispc_plane_pclk_rate(plane);
  1889. const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
  1890. if (mem_to_mem)
  1891. in_width_max = DIV_ROUND_UP(out_width, maxdownscale);
  1892. else
  1893. in_width_max = dispc_core_clk_rate() /
  1894. DIV_ROUND_UP(pclk, out_width);
  1895. *decim_x = DIV_ROUND_UP(width, in_width_max);
  1896. *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
  1897. if (*decim_x > *x_predecim)
  1898. return -EINVAL;
  1899. do {
  1900. in_width = DIV_ROUND_UP(width, *decim_x);
  1901. } while (*decim_x <= *x_predecim &&
  1902. in_width > maxsinglelinewidth && ++*decim_x);
  1903. if (in_width > maxsinglelinewidth) {
  1904. DSSERR("Cannot scale width exceeds max line width");
  1905. return -EINVAL;
  1906. }
  1907. *core_clk = dispc.feat->calc_core_clk(plane, in_width, in_height,
  1908. out_width, out_height, mem_to_mem);
  1909. return 0;
  1910. }
  1911. static int dispc_ovl_calc_scaling(enum omap_plane plane,
  1912. enum omap_overlay_caps caps,
  1913. const struct omap_video_timings *mgr_timings,
  1914. u16 width, u16 height, u16 out_width, u16 out_height,
  1915. enum omap_color_mode color_mode, bool *five_taps,
  1916. int *x_predecim, int *y_predecim, u16 pos_x,
  1917. enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
  1918. {
  1919. const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
  1920. const int max_decim_limit = 16;
  1921. unsigned long core_clk = 0;
  1922. int decim_x, decim_y, ret;
  1923. if (width == out_width && height == out_height)
  1924. return 0;
  1925. if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
  1926. return -EINVAL;
  1927. *x_predecim = max_decim_limit;
  1928. *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
  1929. dss_has_feature(FEAT_BURST_2D)) ? 2 : max_decim_limit;
  1930. if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
  1931. color_mode == OMAP_DSS_COLOR_CLUT2 ||
  1932. color_mode == OMAP_DSS_COLOR_CLUT4 ||
  1933. color_mode == OMAP_DSS_COLOR_CLUT8) {
  1934. *x_predecim = 1;
  1935. *y_predecim = 1;
  1936. *five_taps = false;
  1937. return 0;
  1938. }
  1939. decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
  1940. decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
  1941. if (decim_x > *x_predecim || out_width > width * 8)
  1942. return -EINVAL;
  1943. if (decim_y > *y_predecim || out_height > height * 8)
  1944. return -EINVAL;
  1945. ret = dispc.feat->calc_scaling(plane, mgr_timings, width, height,
  1946. out_width, out_height, color_mode, five_taps,
  1947. x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
  1948. mem_to_mem);
  1949. if (ret)
  1950. return ret;
  1951. DSSDBG("required core clk rate = %lu Hz\n", core_clk);
  1952. DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
  1953. if (!core_clk || core_clk > dispc_core_clk_rate()) {
  1954. DSSERR("failed to set up scaling, "
  1955. "required core clk rate = %lu Hz, "
  1956. "current core clk rate = %lu Hz\n",
  1957. core_clk, dispc_core_clk_rate());
  1958. return -EINVAL;
  1959. }
  1960. *x_predecim = decim_x;
  1961. *y_predecim = decim_y;
  1962. return 0;
  1963. }
  1964. static int dispc_ovl_setup_common(enum omap_plane plane,
  1965. enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
  1966. u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
  1967. u16 out_width, u16 out_height, enum omap_color_mode color_mode,
  1968. u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
  1969. u8 global_alpha, enum omap_dss_rotation_type rotation_type,
  1970. bool replication, const struct omap_video_timings *mgr_timings,
  1971. bool mem_to_mem)
  1972. {
  1973. bool five_taps = true;
  1974. bool fieldmode = 0;
  1975. int r, cconv = 0;
  1976. unsigned offset0, offset1;
  1977. s32 row_inc;
  1978. s32 pix_inc;
  1979. u16 frame_height = height;
  1980. unsigned int field_offset = 0;
  1981. u16 in_height = height;
  1982. u16 in_width = width;
  1983. int x_predecim = 1, y_predecim = 1;
  1984. bool ilace = mgr_timings->interlace;
  1985. if (paddr == 0)
  1986. return -EINVAL;
  1987. out_width = out_width == 0 ? width : out_width;
  1988. out_height = out_height == 0 ? height : out_height;
  1989. if (ilace && height == out_height)
  1990. fieldmode = 1;
  1991. if (ilace) {
  1992. if (fieldmode)
  1993. in_height /= 2;
  1994. pos_y /= 2;
  1995. out_height /= 2;
  1996. DSSDBG("adjusting for ilace: height %d, pos_y %d, "
  1997. "out_height %d\n", in_height, pos_y,
  1998. out_height);
  1999. }
  2000. if (!dss_feat_color_mode_supported(plane, color_mode))
  2001. return -EINVAL;
  2002. r = dispc_ovl_calc_scaling(plane, caps, mgr_timings, in_width,
  2003. in_height, out_width, out_height, color_mode,
  2004. &five_taps, &x_predecim, &y_predecim, pos_x,
  2005. rotation_type, mem_to_mem);
  2006. if (r)
  2007. return r;
  2008. in_width = DIV_ROUND_UP(in_width, x_predecim);
  2009. in_height = DIV_ROUND_UP(in_height, y_predecim);
  2010. if (color_mode == OMAP_DSS_COLOR_YUV2 ||
  2011. color_mode == OMAP_DSS_COLOR_UYVY ||
  2012. color_mode == OMAP_DSS_COLOR_NV12)
  2013. cconv = 1;
  2014. if (ilace && !fieldmode) {
  2015. /*
  2016. * when downscaling the bottom field may have to start several
  2017. * source lines below the top field. Unfortunately ACCUI
  2018. * registers will only hold the fractional part of the offset
  2019. * so the integer part must be added to the base address of the
  2020. * bottom field.
  2021. */
  2022. if (!in_height || in_height == out_height)
  2023. field_offset = 0;
  2024. else
  2025. field_offset = in_height / out_height / 2;
  2026. }
  2027. /* Fields are independent but interleaved in memory. */
  2028. if (fieldmode)
  2029. field_offset = 1;
  2030. offset0 = 0;
  2031. offset1 = 0;
  2032. row_inc = 0;
  2033. pix_inc = 0;
  2034. if (rotation_type == OMAP_DSS_ROT_TILER)
  2035. calc_tiler_rotation_offset(screen_width, in_width,
  2036. color_mode, fieldmode, field_offset,
  2037. &offset0, &offset1, &row_inc, &pix_inc,
  2038. x_predecim, y_predecim);
  2039. else if (rotation_type == OMAP_DSS_ROT_DMA)
  2040. calc_dma_rotation_offset(rotation, mirror,
  2041. screen_width, in_width, frame_height,
  2042. color_mode, fieldmode, field_offset,
  2043. &offset0, &offset1, &row_inc, &pix_inc,
  2044. x_predecim, y_predecim);
  2045. else
  2046. calc_vrfb_rotation_offset(rotation, mirror,
  2047. screen_width, in_width, frame_height,
  2048. color_mode, fieldmode, field_offset,
  2049. &offset0, &offset1, &row_inc, &pix_inc,
  2050. x_predecim, y_predecim);
  2051. DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
  2052. offset0, offset1, row_inc, pix_inc);
  2053. dispc_ovl_set_color_mode(plane, color_mode);
  2054. dispc_ovl_configure_burst_type(plane, rotation_type);
  2055. dispc_ovl_set_ba0(plane, paddr + offset0);
  2056. dispc_ovl_set_ba1(plane, paddr + offset1);
  2057. if (OMAP_DSS_COLOR_NV12 == color_mode) {
  2058. dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
  2059. dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
  2060. }
  2061. dispc_ovl_set_row_inc(plane, row_inc);
  2062. dispc_ovl_set_pix_inc(plane, pix_inc);
  2063. DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
  2064. in_height, out_width, out_height);
  2065. dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
  2066. dispc_ovl_set_input_size(plane, in_width, in_height);
  2067. if (caps & OMAP_DSS_OVL_CAP_SCALE) {
  2068. dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
  2069. out_height, ilace, five_taps, fieldmode,
  2070. color_mode, rotation);
  2071. dispc_ovl_set_output_size(plane, out_width, out_height);
  2072. dispc_ovl_set_vid_color_conv(plane, cconv);
  2073. }
  2074. dispc_ovl_set_rotation_attrs(plane, rotation, mirror, color_mode);
  2075. dispc_ovl_set_zorder(plane, caps, zorder);
  2076. dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
  2077. dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
  2078. dispc_ovl_enable_replication(plane, caps, replication);
  2079. return 0;
  2080. }
  2081. int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
  2082. bool replication, const struct omap_video_timings *mgr_timings,
  2083. bool mem_to_mem)
  2084. {
  2085. int r;
  2086. struct omap_overlay *ovl = omap_dss_get_overlay(plane);
  2087. enum omap_channel channel;
  2088. channel = dispc_ovl_get_channel_out(plane);
  2089. DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
  2090. "%dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
  2091. plane, oi->paddr, oi->p_uv_addr, oi->screen_width, oi->pos_x,
  2092. oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
  2093. oi->color_mode, oi->rotation, oi->mirror, channel, replication);
  2094. r = dispc_ovl_setup_common(plane, ovl->caps, oi->paddr, oi->p_uv_addr,
  2095. oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
  2096. oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
  2097. oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
  2098. oi->rotation_type, replication, mgr_timings, mem_to_mem);
  2099. return r;
  2100. }
  2101. int dispc_ovl_enable(enum omap_plane plane, bool enable)
  2102. {
  2103. DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
  2104. REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
  2105. return 0;
  2106. }
  2107. static void dispc_disable_isr(void *data, u32 mask)
  2108. {
  2109. struct completion *compl = data;
  2110. complete(compl);
  2111. }
  2112. static void _enable_lcd_out(enum omap_channel channel, bool enable)
  2113. {
  2114. mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
  2115. /* flush posted write */
  2116. mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
  2117. }
  2118. static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
  2119. {
  2120. struct completion frame_done_completion;
  2121. bool is_on;
  2122. int r;
  2123. u32 irq;
  2124. /* When we disable LCD output, we need to wait until frame is done.
  2125. * Otherwise the DSS is still working, and turning off the clocks
  2126. * prevents DSS from going to OFF mode */
  2127. is_on = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
  2128. irq = mgr_desc[channel].framedone_irq;
  2129. if (!enable && is_on) {
  2130. init_completion(&frame_done_completion);
  2131. r = omap_dispc_register_isr(dispc_disable_isr,
  2132. &frame_done_completion, irq);
  2133. if (r)
  2134. DSSERR("failed to register FRAMEDONE isr\n");
  2135. }
  2136. _enable_lcd_out(channel, enable);
  2137. if (!enable && is_on) {
  2138. if (!wait_for_completion_timeout(&frame_done_completion,
  2139. msecs_to_jiffies(100)))
  2140. DSSERR("timeout waiting for FRAME DONE\n");
  2141. r = omap_dispc_unregister_isr(dispc_disable_isr,
  2142. &frame_done_completion, irq);
  2143. if (r)
  2144. DSSERR("failed to unregister FRAMEDONE isr\n");
  2145. }
  2146. }
  2147. static void _enable_digit_out(bool enable)
  2148. {
  2149. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
  2150. /* flush posted write */
  2151. dispc_read_reg(DISPC_CONTROL);
  2152. }
  2153. static void dispc_mgr_enable_digit_out(bool enable)
  2154. {
  2155. struct completion frame_done_completion;
  2156. enum dss_hdmi_venc_clk_source_select src;
  2157. int r, i;
  2158. u32 irq_mask;
  2159. int num_irqs;
  2160. if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
  2161. return;
  2162. src = dss_get_hdmi_venc_clk_source();
  2163. if (enable) {
  2164. unsigned long flags;
  2165. /* When we enable digit output, we'll get an extra digit
  2166. * sync lost interrupt, that we need to ignore */
  2167. spin_lock_irqsave(&dispc.irq_lock, flags);
  2168. dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  2169. _omap_dispc_set_irqs();
  2170. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2171. }
  2172. /* When we disable digit output, we need to wait until fields are done.
  2173. * Otherwise the DSS is still working, and turning off the clocks
  2174. * prevents DSS from going to OFF mode. And when enabling, we need to
  2175. * wait for the extra sync losts */
  2176. init_completion(&frame_done_completion);
  2177. if (src == DSS_HDMI_M_PCLK && enable == false) {
  2178. irq_mask = DISPC_IRQ_FRAMEDONETV;
  2179. num_irqs = 1;
  2180. } else {
  2181. irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
  2182. /* XXX I understand from TRM that we should only wait for the
  2183. * current field to complete. But it seems we have to wait for
  2184. * both fields */
  2185. num_irqs = 2;
  2186. }
  2187. r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
  2188. irq_mask);
  2189. if (r)
  2190. DSSERR("failed to register %x isr\n", irq_mask);
  2191. _enable_digit_out(enable);
  2192. for (i = 0; i < num_irqs; ++i) {
  2193. if (!wait_for_completion_timeout(&frame_done_completion,
  2194. msecs_to_jiffies(100)))
  2195. DSSERR("timeout waiting for digit out to %s\n",
  2196. enable ? "start" : "stop");
  2197. }
  2198. r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
  2199. irq_mask);
  2200. if (r)
  2201. DSSERR("failed to unregister %x isr\n", irq_mask);
  2202. if (enable) {
  2203. unsigned long flags;
  2204. spin_lock_irqsave(&dispc.irq_lock, flags);
  2205. dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
  2206. dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
  2207. _omap_dispc_set_irqs();
  2208. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2209. }
  2210. }
  2211. bool dispc_mgr_is_enabled(enum omap_channel channel)
  2212. {
  2213. return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
  2214. }
  2215. void dispc_mgr_enable(enum omap_channel channel, bool enable)
  2216. {
  2217. if (dss_mgr_is_lcd(channel))
  2218. dispc_mgr_enable_lcd_out(channel, enable);
  2219. else if (channel == OMAP_DSS_CHANNEL_DIGIT)
  2220. dispc_mgr_enable_digit_out(enable);
  2221. else
  2222. BUG();
  2223. }
  2224. void dispc_lcd_enable_signal_polarity(bool act_high)
  2225. {
  2226. if (!dss_has_feature(FEAT_LCDENABLEPOL))
  2227. return;
  2228. REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
  2229. }
  2230. void dispc_lcd_enable_signal(bool enable)
  2231. {
  2232. if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
  2233. return;
  2234. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
  2235. }
  2236. void dispc_pck_free_enable(bool enable)
  2237. {
  2238. if (!dss_has_feature(FEAT_PCKFREEENABLE))
  2239. return;
  2240. REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
  2241. }
  2242. void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
  2243. {
  2244. mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
  2245. }
  2246. void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
  2247. {
  2248. mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
  2249. }
  2250. void dispc_set_loadmode(enum omap_dss_load_mode mode)
  2251. {
  2252. REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
  2253. }
  2254. static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
  2255. {
  2256. dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
  2257. }
  2258. static void dispc_mgr_set_trans_key(enum omap_channel ch,
  2259. enum omap_dss_trans_key_type type,
  2260. u32 trans_key)
  2261. {
  2262. mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
  2263. dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
  2264. }
  2265. static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
  2266. {
  2267. mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
  2268. }
  2269. static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
  2270. bool enable)
  2271. {
  2272. if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
  2273. return;
  2274. if (ch == OMAP_DSS_CHANNEL_LCD)
  2275. REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
  2276. else if (ch == OMAP_DSS_CHANNEL_DIGIT)
  2277. REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
  2278. }
  2279. void dispc_mgr_setup(enum omap_channel channel,
  2280. struct omap_overlay_manager_info *info)
  2281. {
  2282. dispc_mgr_set_default_color(channel, info->default_color);
  2283. dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
  2284. dispc_mgr_enable_trans_key(channel, info->trans_enabled);
  2285. dispc_mgr_enable_alpha_fixed_zorder(channel,
  2286. info->partial_alpha_enabled);
  2287. if (dss_has_feature(FEAT_CPR)) {
  2288. dispc_mgr_enable_cpr(channel, info->cpr_enable);
  2289. dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
  2290. }
  2291. }
  2292. void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
  2293. {
  2294. int code;
  2295. switch (data_lines) {
  2296. case 12:
  2297. code = 0;
  2298. break;
  2299. case 16:
  2300. code = 1;
  2301. break;
  2302. case 18:
  2303. code = 2;
  2304. break;
  2305. case 24:
  2306. code = 3;
  2307. break;
  2308. default:
  2309. BUG();
  2310. return;
  2311. }
  2312. mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
  2313. }
  2314. void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
  2315. {
  2316. u32 l;
  2317. int gpout0, gpout1;
  2318. switch (mode) {
  2319. case DSS_IO_PAD_MODE_RESET:
  2320. gpout0 = 0;
  2321. gpout1 = 0;
  2322. break;
  2323. case DSS_IO_PAD_MODE_RFBI:
  2324. gpout0 = 1;
  2325. gpout1 = 0;
  2326. break;
  2327. case DSS_IO_PAD_MODE_BYPASS:
  2328. gpout0 = 1;
  2329. gpout1 = 1;
  2330. break;
  2331. default:
  2332. BUG();
  2333. return;
  2334. }
  2335. l = dispc_read_reg(DISPC_CONTROL);
  2336. l = FLD_MOD(l, gpout0, 15, 15);
  2337. l = FLD_MOD(l, gpout1, 16, 16);
  2338. dispc_write_reg(DISPC_CONTROL, l);
  2339. }
  2340. void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
  2341. {
  2342. mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
  2343. }
  2344. static bool _dispc_mgr_size_ok(u16 width, u16 height)
  2345. {
  2346. return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
  2347. height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
  2348. }
  2349. static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
  2350. int vsw, int vfp, int vbp)
  2351. {
  2352. if (hsw < 1 || hsw > dispc.feat->sw_max ||
  2353. hfp < 1 || hfp > dispc.feat->hp_max ||
  2354. hbp < 1 || hbp > dispc.feat->hp_max ||
  2355. vsw < 1 || vsw > dispc.feat->sw_max ||
  2356. vfp < 0 || vfp > dispc.feat->vp_max ||
  2357. vbp < 0 || vbp > dispc.feat->vp_max)
  2358. return false;
  2359. return true;
  2360. }
  2361. bool dispc_mgr_timings_ok(enum omap_channel channel,
  2362. const struct omap_video_timings *timings)
  2363. {
  2364. bool timings_ok;
  2365. timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
  2366. if (dss_mgr_is_lcd(channel))
  2367. timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
  2368. timings->hfp, timings->hbp,
  2369. timings->vsw, timings->vfp,
  2370. timings->vbp);
  2371. return timings_ok;
  2372. }
  2373. static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
  2374. int hfp, int hbp, int vsw, int vfp, int vbp,
  2375. enum omap_dss_signal_level vsync_level,
  2376. enum omap_dss_signal_level hsync_level,
  2377. enum omap_dss_signal_edge data_pclk_edge,
  2378. enum omap_dss_signal_level de_level,
  2379. enum omap_dss_signal_edge sync_pclk_edge)
  2380. {
  2381. u32 timing_h, timing_v, l;
  2382. bool onoff, rf, ipc;
  2383. timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
  2384. FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
  2385. FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
  2386. timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
  2387. FLD_VAL(vfp, dispc.feat->fp_start, 8) |
  2388. FLD_VAL(vbp, dispc.feat->bp_start, 20);
  2389. dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
  2390. dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
  2391. switch (data_pclk_edge) {
  2392. case OMAPDSS_DRIVE_SIG_RISING_EDGE:
  2393. ipc = false;
  2394. break;
  2395. case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
  2396. ipc = true;
  2397. break;
  2398. case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
  2399. default:
  2400. BUG();
  2401. }
  2402. switch (sync_pclk_edge) {
  2403. case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
  2404. onoff = false;
  2405. rf = false;
  2406. break;
  2407. case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
  2408. onoff = true;
  2409. rf = false;
  2410. break;
  2411. case OMAPDSS_DRIVE_SIG_RISING_EDGE:
  2412. onoff = true;
  2413. rf = true;
  2414. break;
  2415. default:
  2416. BUG();
  2417. };
  2418. l = dispc_read_reg(DISPC_POL_FREQ(channel));
  2419. l |= FLD_VAL(onoff, 17, 17);
  2420. l |= FLD_VAL(rf, 16, 16);
  2421. l |= FLD_VAL(de_level, 15, 15);
  2422. l |= FLD_VAL(ipc, 14, 14);
  2423. l |= FLD_VAL(hsync_level, 13, 13);
  2424. l |= FLD_VAL(vsync_level, 12, 12);
  2425. dispc_write_reg(DISPC_POL_FREQ(channel), l);
  2426. }
  2427. /* change name to mode? */
  2428. void dispc_mgr_set_timings(enum omap_channel channel,
  2429. struct omap_video_timings *timings)
  2430. {
  2431. unsigned xtot, ytot;
  2432. unsigned long ht, vt;
  2433. struct omap_video_timings t = *timings;
  2434. DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
  2435. if (!dispc_mgr_timings_ok(channel, &t)) {
  2436. BUG();
  2437. return;
  2438. }
  2439. if (dss_mgr_is_lcd(channel)) {
  2440. _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
  2441. t.vfp, t.vbp, t.vsync_level, t.hsync_level,
  2442. t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
  2443. xtot = t.x_res + t.hfp + t.hsw + t.hbp;
  2444. ytot = t.y_res + t.vfp + t.vsw + t.vbp;
  2445. ht = (timings->pixel_clock * 1000) / xtot;
  2446. vt = (timings->pixel_clock * 1000) / xtot / ytot;
  2447. DSSDBG("pck %u\n", timings->pixel_clock);
  2448. DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
  2449. t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
  2450. DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
  2451. t.vsync_level, t.hsync_level, t.data_pclk_edge,
  2452. t.de_level, t.sync_pclk_edge);
  2453. DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
  2454. } else {
  2455. if (t.interlace == true)
  2456. t.y_res /= 2;
  2457. }
  2458. dispc_mgr_set_size(channel, t.x_res, t.y_res);
  2459. }
  2460. static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
  2461. u16 pck_div)
  2462. {
  2463. BUG_ON(lck_div < 1);
  2464. BUG_ON(pck_div < 1);
  2465. dispc_write_reg(DISPC_DIVISORo(channel),
  2466. FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
  2467. }
  2468. static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
  2469. int *pck_div)
  2470. {
  2471. u32 l;
  2472. l = dispc_read_reg(DISPC_DIVISORo(channel));
  2473. *lck_div = FLD_GET(l, 23, 16);
  2474. *pck_div = FLD_GET(l, 7, 0);
  2475. }
  2476. unsigned long dispc_fclk_rate(void)
  2477. {
  2478. struct platform_device *dsidev;
  2479. unsigned long r = 0;
  2480. switch (dss_get_dispc_clk_source()) {
  2481. case OMAP_DSS_CLK_SRC_FCK:
  2482. r = clk_get_rate(dispc.dss_clk);
  2483. break;
  2484. case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
  2485. dsidev = dsi_get_dsidev_from_id(0);
  2486. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2487. break;
  2488. case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
  2489. dsidev = dsi_get_dsidev_from_id(1);
  2490. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2491. break;
  2492. default:
  2493. BUG();
  2494. return 0;
  2495. }
  2496. return r;
  2497. }
  2498. unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
  2499. {
  2500. struct platform_device *dsidev;
  2501. int lcd;
  2502. unsigned long r;
  2503. u32 l;
  2504. l = dispc_read_reg(DISPC_DIVISORo(channel));
  2505. lcd = FLD_GET(l, 23, 16);
  2506. switch (dss_get_lcd_clk_source(channel)) {
  2507. case OMAP_DSS_CLK_SRC_FCK:
  2508. r = clk_get_rate(dispc.dss_clk);
  2509. break;
  2510. case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
  2511. dsidev = dsi_get_dsidev_from_id(0);
  2512. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2513. break;
  2514. case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
  2515. dsidev = dsi_get_dsidev_from_id(1);
  2516. r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  2517. break;
  2518. default:
  2519. BUG();
  2520. return 0;
  2521. }
  2522. return r / lcd;
  2523. }
  2524. unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
  2525. {
  2526. unsigned long r;
  2527. if (dss_mgr_is_lcd(channel)) {
  2528. int pcd;
  2529. u32 l;
  2530. l = dispc_read_reg(DISPC_DIVISORo(channel));
  2531. pcd = FLD_GET(l, 7, 0);
  2532. r = dispc_mgr_lclk_rate(channel);
  2533. return r / pcd;
  2534. } else {
  2535. enum dss_hdmi_venc_clk_source_select source;
  2536. source = dss_get_hdmi_venc_clk_source();
  2537. switch (source) {
  2538. case DSS_VENC_TV_CLK:
  2539. return venc_get_pixel_clock();
  2540. case DSS_HDMI_M_PCLK:
  2541. return hdmi_get_pixel_clock();
  2542. default:
  2543. BUG();
  2544. return 0;
  2545. }
  2546. }
  2547. }
  2548. unsigned long dispc_core_clk_rate(void)
  2549. {
  2550. int lcd;
  2551. unsigned long fclk = dispc_fclk_rate();
  2552. if (dss_has_feature(FEAT_CORE_CLK_DIV))
  2553. lcd = REG_GET(DISPC_DIVISOR, 23, 16);
  2554. else
  2555. lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
  2556. return fclk / lcd;
  2557. }
  2558. static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
  2559. {
  2560. enum omap_channel channel = dispc_ovl_get_channel_out(plane);
  2561. return dispc_mgr_pclk_rate(channel);
  2562. }
  2563. static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
  2564. {
  2565. enum omap_channel channel = dispc_ovl_get_channel_out(plane);
  2566. if (dss_mgr_is_lcd(channel))
  2567. return dispc_mgr_lclk_rate(channel);
  2568. else
  2569. return dispc_fclk_rate();
  2570. }
  2571. static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
  2572. {
  2573. int lcd, pcd;
  2574. enum omap_dss_clk_source lcd_clk_src;
  2575. seq_printf(s, "- %s -\n", mgr_desc[channel].name);
  2576. lcd_clk_src = dss_get_lcd_clk_source(channel);
  2577. seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
  2578. dss_get_generic_clk_source_name(lcd_clk_src),
  2579. dss_feat_get_clk_source_name(lcd_clk_src));
  2580. dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
  2581. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2582. dispc_mgr_lclk_rate(channel), lcd);
  2583. seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
  2584. dispc_mgr_pclk_rate(channel), pcd);
  2585. }
  2586. void dispc_dump_clocks(struct seq_file *s)
  2587. {
  2588. int lcd;
  2589. u32 l;
  2590. enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
  2591. if (dispc_runtime_get())
  2592. return;
  2593. seq_printf(s, "- DISPC -\n");
  2594. seq_printf(s, "dispc fclk source = %s (%s)\n",
  2595. dss_get_generic_clk_source_name(dispc_clk_src),
  2596. dss_feat_get_clk_source_name(dispc_clk_src));
  2597. seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
  2598. if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
  2599. seq_printf(s, "- DISPC-CORE-CLK -\n");
  2600. l = dispc_read_reg(DISPC_DIVISOR);
  2601. lcd = FLD_GET(l, 23, 16);
  2602. seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
  2603. (dispc_fclk_rate()/lcd), lcd);
  2604. }
  2605. dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
  2606. if (dss_has_feature(FEAT_MGR_LCD2))
  2607. dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
  2608. if (dss_has_feature(FEAT_MGR_LCD3))
  2609. dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
  2610. dispc_runtime_put();
  2611. }
  2612. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2613. void dispc_dump_irqs(struct seq_file *s)
  2614. {
  2615. unsigned long flags;
  2616. struct dispc_irq_stats stats;
  2617. spin_lock_irqsave(&dispc.irq_stats_lock, flags);
  2618. stats = dispc.irq_stats;
  2619. memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
  2620. dispc.irq_stats.last_reset = jiffies;
  2621. spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
  2622. seq_printf(s, "period %u ms\n",
  2623. jiffies_to_msecs(jiffies - stats.last_reset));
  2624. seq_printf(s, "irqs %d\n", stats.irq_count);
  2625. #define PIS(x) \
  2626. seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
  2627. PIS(FRAMEDONE);
  2628. PIS(VSYNC);
  2629. PIS(EVSYNC_EVEN);
  2630. PIS(EVSYNC_ODD);
  2631. PIS(ACBIAS_COUNT_STAT);
  2632. PIS(PROG_LINE_NUM);
  2633. PIS(GFX_FIFO_UNDERFLOW);
  2634. PIS(GFX_END_WIN);
  2635. PIS(PAL_GAMMA_MASK);
  2636. PIS(OCP_ERR);
  2637. PIS(VID1_FIFO_UNDERFLOW);
  2638. PIS(VID1_END_WIN);
  2639. PIS(VID2_FIFO_UNDERFLOW);
  2640. PIS(VID2_END_WIN);
  2641. if (dss_feat_get_num_ovls() > 3) {
  2642. PIS(VID3_FIFO_UNDERFLOW);
  2643. PIS(VID3_END_WIN);
  2644. }
  2645. PIS(SYNC_LOST);
  2646. PIS(SYNC_LOST_DIGIT);
  2647. PIS(WAKEUP);
  2648. if (dss_has_feature(FEAT_MGR_LCD2)) {
  2649. PIS(FRAMEDONE2);
  2650. PIS(VSYNC2);
  2651. PIS(ACBIAS_COUNT_STAT2);
  2652. PIS(SYNC_LOST2);
  2653. }
  2654. if (dss_has_feature(FEAT_MGR_LCD3)) {
  2655. PIS(FRAMEDONE3);
  2656. PIS(VSYNC3);
  2657. PIS(ACBIAS_COUNT_STAT3);
  2658. PIS(SYNC_LOST3);
  2659. }
  2660. #undef PIS
  2661. }
  2662. #endif
  2663. static void dispc_dump_regs(struct seq_file *s)
  2664. {
  2665. int i, j;
  2666. const char *mgr_names[] = {
  2667. [OMAP_DSS_CHANNEL_LCD] = "LCD",
  2668. [OMAP_DSS_CHANNEL_DIGIT] = "TV",
  2669. [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
  2670. [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
  2671. };
  2672. const char *ovl_names[] = {
  2673. [OMAP_DSS_GFX] = "GFX",
  2674. [OMAP_DSS_VIDEO1] = "VID1",
  2675. [OMAP_DSS_VIDEO2] = "VID2",
  2676. [OMAP_DSS_VIDEO3] = "VID3",
  2677. };
  2678. const char **p_names;
  2679. #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
  2680. if (dispc_runtime_get())
  2681. return;
  2682. /* DISPC common registers */
  2683. DUMPREG(DISPC_REVISION);
  2684. DUMPREG(DISPC_SYSCONFIG);
  2685. DUMPREG(DISPC_SYSSTATUS);
  2686. DUMPREG(DISPC_IRQSTATUS);
  2687. DUMPREG(DISPC_IRQENABLE);
  2688. DUMPREG(DISPC_CONTROL);
  2689. DUMPREG(DISPC_CONFIG);
  2690. DUMPREG(DISPC_CAPABLE);
  2691. DUMPREG(DISPC_LINE_STATUS);
  2692. DUMPREG(DISPC_LINE_NUMBER);
  2693. if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
  2694. dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
  2695. DUMPREG(DISPC_GLOBAL_ALPHA);
  2696. if (dss_has_feature(FEAT_MGR_LCD2)) {
  2697. DUMPREG(DISPC_CONTROL2);
  2698. DUMPREG(DISPC_CONFIG2);
  2699. }
  2700. if (dss_has_feature(FEAT_MGR_LCD3)) {
  2701. DUMPREG(DISPC_CONTROL3);
  2702. DUMPREG(DISPC_CONFIG3);
  2703. }
  2704. #undef DUMPREG
  2705. #define DISPC_REG(i, name) name(i)
  2706. #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
  2707. 48 - strlen(#r) - strlen(p_names[i]), " ", \
  2708. dispc_read_reg(DISPC_REG(i, r)))
  2709. p_names = mgr_names;
  2710. /* DISPC channel specific registers */
  2711. for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
  2712. DUMPREG(i, DISPC_DEFAULT_COLOR);
  2713. DUMPREG(i, DISPC_TRANS_COLOR);
  2714. DUMPREG(i, DISPC_SIZE_MGR);
  2715. if (i == OMAP_DSS_CHANNEL_DIGIT)
  2716. continue;
  2717. DUMPREG(i, DISPC_DEFAULT_COLOR);
  2718. DUMPREG(i, DISPC_TRANS_COLOR);
  2719. DUMPREG(i, DISPC_TIMING_H);
  2720. DUMPREG(i, DISPC_TIMING_V);
  2721. DUMPREG(i, DISPC_POL_FREQ);
  2722. DUMPREG(i, DISPC_DIVISORo);
  2723. DUMPREG(i, DISPC_SIZE_MGR);
  2724. DUMPREG(i, DISPC_DATA_CYCLE1);
  2725. DUMPREG(i, DISPC_DATA_CYCLE2);
  2726. DUMPREG(i, DISPC_DATA_CYCLE3);
  2727. if (dss_has_feature(FEAT_CPR)) {
  2728. DUMPREG(i, DISPC_CPR_COEF_R);
  2729. DUMPREG(i, DISPC_CPR_COEF_G);
  2730. DUMPREG(i, DISPC_CPR_COEF_B);
  2731. }
  2732. }
  2733. p_names = ovl_names;
  2734. for (i = 0; i < dss_feat_get_num_ovls(); i++) {
  2735. DUMPREG(i, DISPC_OVL_BA0);
  2736. DUMPREG(i, DISPC_OVL_BA1);
  2737. DUMPREG(i, DISPC_OVL_POSITION);
  2738. DUMPREG(i, DISPC_OVL_SIZE);
  2739. DUMPREG(i, DISPC_OVL_ATTRIBUTES);
  2740. DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
  2741. DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
  2742. DUMPREG(i, DISPC_OVL_ROW_INC);
  2743. DUMPREG(i, DISPC_OVL_PIXEL_INC);
  2744. if (dss_has_feature(FEAT_PRELOAD))
  2745. DUMPREG(i, DISPC_OVL_PRELOAD);
  2746. if (i == OMAP_DSS_GFX) {
  2747. DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
  2748. DUMPREG(i, DISPC_OVL_TABLE_BA);
  2749. continue;
  2750. }
  2751. DUMPREG(i, DISPC_OVL_FIR);
  2752. DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
  2753. DUMPREG(i, DISPC_OVL_ACCU0);
  2754. DUMPREG(i, DISPC_OVL_ACCU1);
  2755. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  2756. DUMPREG(i, DISPC_OVL_BA0_UV);
  2757. DUMPREG(i, DISPC_OVL_BA1_UV);
  2758. DUMPREG(i, DISPC_OVL_FIR2);
  2759. DUMPREG(i, DISPC_OVL_ACCU2_0);
  2760. DUMPREG(i, DISPC_OVL_ACCU2_1);
  2761. }
  2762. if (dss_has_feature(FEAT_ATTR2))
  2763. DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
  2764. if (dss_has_feature(FEAT_PRELOAD))
  2765. DUMPREG(i, DISPC_OVL_PRELOAD);
  2766. }
  2767. #undef DISPC_REG
  2768. #undef DUMPREG
  2769. #define DISPC_REG(plane, name, i) name(plane, i)
  2770. #define DUMPREG(plane, name, i) \
  2771. seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
  2772. 46 - strlen(#name) - strlen(p_names[plane]), " ", \
  2773. dispc_read_reg(DISPC_REG(plane, name, i)))
  2774. /* Video pipeline coefficient registers */
  2775. /* start from OMAP_DSS_VIDEO1 */
  2776. for (i = 1; i < dss_feat_get_num_ovls(); i++) {
  2777. for (j = 0; j < 8; j++)
  2778. DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
  2779. for (j = 0; j < 8; j++)
  2780. DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
  2781. for (j = 0; j < 5; j++)
  2782. DUMPREG(i, DISPC_OVL_CONV_COEF, j);
  2783. if (dss_has_feature(FEAT_FIR_COEF_V)) {
  2784. for (j = 0; j < 8; j++)
  2785. DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
  2786. }
  2787. if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
  2788. for (j = 0; j < 8; j++)
  2789. DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
  2790. for (j = 0; j < 8; j++)
  2791. DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
  2792. for (j = 0; j < 8; j++)
  2793. DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
  2794. }
  2795. }
  2796. dispc_runtime_put();
  2797. #undef DISPC_REG
  2798. #undef DUMPREG
  2799. }
  2800. /* with fck as input clock rate, find dispc dividers that produce req_pck */
  2801. void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
  2802. struct dispc_clock_info *cinfo)
  2803. {
  2804. u16 pcd_min, pcd_max;
  2805. unsigned long best_pck;
  2806. u16 best_ld, cur_ld;
  2807. u16 best_pd, cur_pd;
  2808. pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
  2809. pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
  2810. best_pck = 0;
  2811. best_ld = 0;
  2812. best_pd = 0;
  2813. for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
  2814. unsigned long lck = fck / cur_ld;
  2815. for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
  2816. unsigned long pck = lck / cur_pd;
  2817. long old_delta = abs(best_pck - req_pck);
  2818. long new_delta = abs(pck - req_pck);
  2819. if (best_pck == 0 || new_delta < old_delta) {
  2820. best_pck = pck;
  2821. best_ld = cur_ld;
  2822. best_pd = cur_pd;
  2823. if (pck == req_pck)
  2824. goto found;
  2825. }
  2826. if (pck < req_pck)
  2827. break;
  2828. }
  2829. if (lck / pcd_min < req_pck)
  2830. break;
  2831. }
  2832. found:
  2833. cinfo->lck_div = best_ld;
  2834. cinfo->pck_div = best_pd;
  2835. cinfo->lck = fck / cinfo->lck_div;
  2836. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2837. }
  2838. /* calculate clock rates using dividers in cinfo */
  2839. int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
  2840. struct dispc_clock_info *cinfo)
  2841. {
  2842. if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
  2843. return -EINVAL;
  2844. if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
  2845. return -EINVAL;
  2846. cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
  2847. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2848. return 0;
  2849. }
  2850. void dispc_mgr_set_clock_div(enum omap_channel channel,
  2851. struct dispc_clock_info *cinfo)
  2852. {
  2853. DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
  2854. DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
  2855. dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
  2856. }
  2857. int dispc_mgr_get_clock_div(enum omap_channel channel,
  2858. struct dispc_clock_info *cinfo)
  2859. {
  2860. unsigned long fck;
  2861. fck = dispc_fclk_rate();
  2862. cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
  2863. cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
  2864. cinfo->lck = fck / cinfo->lck_div;
  2865. cinfo->pck = cinfo->lck / cinfo->pck_div;
  2866. return 0;
  2867. }
  2868. /* dispc.irq_lock has to be locked by the caller */
  2869. static void _omap_dispc_set_irqs(void)
  2870. {
  2871. u32 mask;
  2872. u32 old_mask;
  2873. int i;
  2874. struct omap_dispc_isr_data *isr_data;
  2875. mask = dispc.irq_error_mask;
  2876. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2877. isr_data = &dispc.registered_isr[i];
  2878. if (isr_data->isr == NULL)
  2879. continue;
  2880. mask |= isr_data->mask;
  2881. }
  2882. old_mask = dispc_read_reg(DISPC_IRQENABLE);
  2883. /* clear the irqstatus for newly enabled irqs */
  2884. dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
  2885. dispc_write_reg(DISPC_IRQENABLE, mask);
  2886. }
  2887. int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
  2888. {
  2889. int i;
  2890. int ret;
  2891. unsigned long flags;
  2892. struct omap_dispc_isr_data *isr_data;
  2893. if (isr == NULL)
  2894. return -EINVAL;
  2895. spin_lock_irqsave(&dispc.irq_lock, flags);
  2896. /* check for duplicate entry */
  2897. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2898. isr_data = &dispc.registered_isr[i];
  2899. if (isr_data->isr == isr && isr_data->arg == arg &&
  2900. isr_data->mask == mask) {
  2901. ret = -EINVAL;
  2902. goto err;
  2903. }
  2904. }
  2905. isr_data = NULL;
  2906. ret = -EBUSY;
  2907. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2908. isr_data = &dispc.registered_isr[i];
  2909. if (isr_data->isr != NULL)
  2910. continue;
  2911. isr_data->isr = isr;
  2912. isr_data->arg = arg;
  2913. isr_data->mask = mask;
  2914. ret = 0;
  2915. break;
  2916. }
  2917. if (ret)
  2918. goto err;
  2919. _omap_dispc_set_irqs();
  2920. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2921. return 0;
  2922. err:
  2923. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2924. return ret;
  2925. }
  2926. EXPORT_SYMBOL(omap_dispc_register_isr);
  2927. int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
  2928. {
  2929. int i;
  2930. unsigned long flags;
  2931. int ret = -EINVAL;
  2932. struct omap_dispc_isr_data *isr_data;
  2933. spin_lock_irqsave(&dispc.irq_lock, flags);
  2934. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  2935. isr_data = &dispc.registered_isr[i];
  2936. if (isr_data->isr != isr || isr_data->arg != arg ||
  2937. isr_data->mask != mask)
  2938. continue;
  2939. /* found the correct isr */
  2940. isr_data->isr = NULL;
  2941. isr_data->arg = NULL;
  2942. isr_data->mask = 0;
  2943. ret = 0;
  2944. break;
  2945. }
  2946. if (ret == 0)
  2947. _omap_dispc_set_irqs();
  2948. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  2949. return ret;
  2950. }
  2951. EXPORT_SYMBOL(omap_dispc_unregister_isr);
  2952. #ifdef DEBUG
  2953. static void print_irq_status(u32 status)
  2954. {
  2955. if ((status & dispc.irq_error_mask) == 0)
  2956. return;
  2957. printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
  2958. #define PIS(x) \
  2959. if (status & DISPC_IRQ_##x) \
  2960. printk(#x " ");
  2961. PIS(GFX_FIFO_UNDERFLOW);
  2962. PIS(OCP_ERR);
  2963. PIS(VID1_FIFO_UNDERFLOW);
  2964. PIS(VID2_FIFO_UNDERFLOW);
  2965. if (dss_feat_get_num_ovls() > 3)
  2966. PIS(VID3_FIFO_UNDERFLOW);
  2967. PIS(SYNC_LOST);
  2968. PIS(SYNC_LOST_DIGIT);
  2969. if (dss_has_feature(FEAT_MGR_LCD2))
  2970. PIS(SYNC_LOST2);
  2971. if (dss_has_feature(FEAT_MGR_LCD3))
  2972. PIS(SYNC_LOST3);
  2973. #undef PIS
  2974. printk("\n");
  2975. }
  2976. #endif
  2977. /* Called from dss.c. Note that we don't touch clocks here,
  2978. * but we presume they are on because we got an IRQ. However,
  2979. * an irq handler may turn the clocks off, so we may not have
  2980. * clock later in the function. */
  2981. static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
  2982. {
  2983. int i;
  2984. u32 irqstatus, irqenable;
  2985. u32 handledirqs = 0;
  2986. u32 unhandled_errors;
  2987. struct omap_dispc_isr_data *isr_data;
  2988. struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
  2989. spin_lock(&dispc.irq_lock);
  2990. irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
  2991. irqenable = dispc_read_reg(DISPC_IRQENABLE);
  2992. /* IRQ is not for us */
  2993. if (!(irqstatus & irqenable)) {
  2994. spin_unlock(&dispc.irq_lock);
  2995. return IRQ_NONE;
  2996. }
  2997. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2998. spin_lock(&dispc.irq_stats_lock);
  2999. dispc.irq_stats.irq_count++;
  3000. dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
  3001. spin_unlock(&dispc.irq_stats_lock);
  3002. #endif
  3003. #ifdef DEBUG
  3004. if (dss_debug)
  3005. print_irq_status(irqstatus);
  3006. #endif
  3007. /* Ack the interrupt. Do it here before clocks are possibly turned
  3008. * off */
  3009. dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
  3010. /* flush posted write */
  3011. dispc_read_reg(DISPC_IRQSTATUS);
  3012. /* make a copy and unlock, so that isrs can unregister
  3013. * themselves */
  3014. memcpy(registered_isr, dispc.registered_isr,
  3015. sizeof(registered_isr));
  3016. spin_unlock(&dispc.irq_lock);
  3017. for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
  3018. isr_data = &registered_isr[i];
  3019. if (!isr_data->isr)
  3020. continue;
  3021. if (isr_data->mask & irqstatus) {
  3022. isr_data->isr(isr_data->arg, irqstatus);
  3023. handledirqs |= isr_data->mask;
  3024. }
  3025. }
  3026. spin_lock(&dispc.irq_lock);
  3027. unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
  3028. if (unhandled_errors) {
  3029. dispc.error_irqs |= unhandled_errors;
  3030. dispc.irq_error_mask &= ~unhandled_errors;
  3031. _omap_dispc_set_irqs();
  3032. schedule_work(&dispc.error_work);
  3033. }
  3034. spin_unlock(&dispc.irq_lock);
  3035. return IRQ_HANDLED;
  3036. }
  3037. static void dispc_error_worker(struct work_struct *work)
  3038. {
  3039. int i;
  3040. u32 errors;
  3041. unsigned long flags;
  3042. static const unsigned fifo_underflow_bits[] = {
  3043. DISPC_IRQ_GFX_FIFO_UNDERFLOW,
  3044. DISPC_IRQ_VID1_FIFO_UNDERFLOW,
  3045. DISPC_IRQ_VID2_FIFO_UNDERFLOW,
  3046. DISPC_IRQ_VID3_FIFO_UNDERFLOW,
  3047. };
  3048. spin_lock_irqsave(&dispc.irq_lock, flags);
  3049. errors = dispc.error_irqs;
  3050. dispc.error_irqs = 0;
  3051. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  3052. dispc_runtime_get();
  3053. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  3054. struct omap_overlay *ovl;
  3055. unsigned bit;
  3056. ovl = omap_dss_get_overlay(i);
  3057. bit = fifo_underflow_bits[i];
  3058. if (bit & errors) {
  3059. DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
  3060. ovl->name);
  3061. dispc_ovl_enable(ovl->id, false);
  3062. dispc_mgr_go(ovl->manager->id);
  3063. msleep(50);
  3064. }
  3065. }
  3066. for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
  3067. struct omap_overlay_manager *mgr;
  3068. unsigned bit;
  3069. mgr = omap_dss_get_overlay_manager(i);
  3070. bit = mgr_desc[i].sync_lost_irq;
  3071. if (bit & errors) {
  3072. struct omap_dss_device *dssdev = mgr->get_device(mgr);
  3073. bool enable;
  3074. DSSERR("SYNC_LOST on channel %s, restarting the output "
  3075. "with video overlays disabled\n",
  3076. mgr->name);
  3077. enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
  3078. dssdev->driver->disable(dssdev);
  3079. for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
  3080. struct omap_overlay *ovl;
  3081. ovl = omap_dss_get_overlay(i);
  3082. if (ovl->id != OMAP_DSS_GFX &&
  3083. ovl->manager == mgr)
  3084. dispc_ovl_enable(ovl->id, false);
  3085. }
  3086. dispc_mgr_go(mgr->id);
  3087. msleep(50);
  3088. if (enable)
  3089. dssdev->driver->enable(dssdev);
  3090. }
  3091. }
  3092. if (errors & DISPC_IRQ_OCP_ERR) {
  3093. DSSERR("OCP_ERR\n");
  3094. for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
  3095. struct omap_overlay_manager *mgr;
  3096. struct omap_dss_device *dssdev;
  3097. mgr = omap_dss_get_overlay_manager(i);
  3098. dssdev = mgr->get_device(mgr);
  3099. if (dssdev && dssdev->driver)
  3100. dssdev->driver->disable(dssdev);
  3101. }
  3102. }
  3103. spin_lock_irqsave(&dispc.irq_lock, flags);
  3104. dispc.irq_error_mask |= errors;
  3105. _omap_dispc_set_irqs();
  3106. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  3107. dispc_runtime_put();
  3108. }
  3109. int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
  3110. {
  3111. void dispc_irq_wait_handler(void *data, u32 mask)
  3112. {
  3113. complete((struct completion *)data);
  3114. }
  3115. int r;
  3116. DECLARE_COMPLETION_ONSTACK(completion);
  3117. r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
  3118. irqmask);
  3119. if (r)
  3120. return r;
  3121. timeout = wait_for_completion_timeout(&completion, timeout);
  3122. omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
  3123. if (timeout == 0)
  3124. return -ETIMEDOUT;
  3125. if (timeout == -ERESTARTSYS)
  3126. return -ERESTARTSYS;
  3127. return 0;
  3128. }
  3129. int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
  3130. unsigned long timeout)
  3131. {
  3132. void dispc_irq_wait_handler(void *data, u32 mask)
  3133. {
  3134. complete((struct completion *)data);
  3135. }
  3136. int r;
  3137. DECLARE_COMPLETION_ONSTACK(completion);
  3138. r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
  3139. irqmask);
  3140. if (r)
  3141. return r;
  3142. timeout = wait_for_completion_interruptible_timeout(&completion,
  3143. timeout);
  3144. omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
  3145. if (timeout == 0)
  3146. return -ETIMEDOUT;
  3147. if (timeout == -ERESTARTSYS)
  3148. return -ERESTARTSYS;
  3149. return 0;
  3150. }
  3151. static void _omap_dispc_initialize_irq(void)
  3152. {
  3153. unsigned long flags;
  3154. spin_lock_irqsave(&dispc.irq_lock, flags);
  3155. memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
  3156. dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
  3157. if (dss_has_feature(FEAT_MGR_LCD2))
  3158. dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
  3159. if (dss_has_feature(FEAT_MGR_LCD3))
  3160. dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST3;
  3161. if (dss_feat_get_num_ovls() > 3)
  3162. dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
  3163. /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
  3164. * so clear it */
  3165. dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
  3166. _omap_dispc_set_irqs();
  3167. spin_unlock_irqrestore(&dispc.irq_lock, flags);
  3168. }
  3169. void dispc_enable_sidle(void)
  3170. {
  3171. REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
  3172. }
  3173. void dispc_disable_sidle(void)
  3174. {
  3175. REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
  3176. }
  3177. static void _omap_dispc_initial_config(void)
  3178. {
  3179. u32 l;
  3180. /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
  3181. if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
  3182. l = dispc_read_reg(DISPC_DIVISOR);
  3183. /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
  3184. l = FLD_MOD(l, 1, 0, 0);
  3185. l = FLD_MOD(l, 1, 23, 16);
  3186. dispc_write_reg(DISPC_DIVISOR, l);
  3187. }
  3188. /* FUNCGATED */
  3189. if (dss_has_feature(FEAT_FUNCGATED))
  3190. REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
  3191. _dispc_setup_color_conv_coef();
  3192. dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
  3193. dispc_init_fifos();
  3194. dispc_configure_burst_sizes();
  3195. dispc_ovl_enable_zorder_planes();
  3196. }
  3197. static const struct dispc_features omap24xx_dispc_feats __initconst = {
  3198. .sw_start = 5,
  3199. .fp_start = 15,
  3200. .bp_start = 27,
  3201. .sw_max = 64,
  3202. .vp_max = 255,
  3203. .hp_max = 256,
  3204. .calc_scaling = dispc_ovl_calc_scaling_24xx,
  3205. .calc_core_clk = calc_core_clk_24xx,
  3206. .num_fifos = 3,
  3207. };
  3208. static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
  3209. .sw_start = 5,
  3210. .fp_start = 15,
  3211. .bp_start = 27,
  3212. .sw_max = 64,
  3213. .vp_max = 255,
  3214. .hp_max = 256,
  3215. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3216. .calc_core_clk = calc_core_clk_34xx,
  3217. .num_fifos = 3,
  3218. };
  3219. static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
  3220. .sw_start = 7,
  3221. .fp_start = 19,
  3222. .bp_start = 31,
  3223. .sw_max = 256,
  3224. .vp_max = 4095,
  3225. .hp_max = 4096,
  3226. .calc_scaling = dispc_ovl_calc_scaling_34xx,
  3227. .calc_core_clk = calc_core_clk_34xx,
  3228. .num_fifos = 3,
  3229. };
  3230. static const struct dispc_features omap44xx_dispc_feats __initconst = {
  3231. .sw_start = 7,
  3232. .fp_start = 19,
  3233. .bp_start = 31,
  3234. .sw_max = 256,
  3235. .vp_max = 4095,
  3236. .hp_max = 4096,
  3237. .calc_scaling = dispc_ovl_calc_scaling_44xx,
  3238. .calc_core_clk = calc_core_clk_44xx,
  3239. .num_fifos = 5,
  3240. .gfx_fifo_workaround = true,
  3241. };
  3242. static int __init dispc_init_features(struct device *dev)
  3243. {
  3244. const struct dispc_features *src;
  3245. struct dispc_features *dst;
  3246. dst = devm_kzalloc(dev, sizeof(*dst), GFP_KERNEL);
  3247. if (!dst) {
  3248. dev_err(dev, "Failed to allocate DISPC Features\n");
  3249. return -ENOMEM;
  3250. }
  3251. if (cpu_is_omap24xx()) {
  3252. src = &omap24xx_dispc_feats;
  3253. } else if (cpu_is_omap34xx()) {
  3254. if (omap_rev() < OMAP3430_REV_ES3_0)
  3255. src = &omap34xx_rev1_0_dispc_feats;
  3256. else
  3257. src = &omap34xx_rev3_0_dispc_feats;
  3258. } else if (cpu_is_omap44xx()) {
  3259. src = &omap44xx_dispc_feats;
  3260. } else if (soc_is_omap54xx()) {
  3261. src = &omap44xx_dispc_feats;
  3262. } else {
  3263. return -ENODEV;
  3264. }
  3265. memcpy(dst, src, sizeof(*dst));
  3266. dispc.feat = dst;
  3267. return 0;
  3268. }
  3269. /* DISPC HW IP initialisation */
  3270. static int __init omap_dispchw_probe(struct platform_device *pdev)
  3271. {
  3272. u32 rev;
  3273. int r = 0;
  3274. struct resource *dispc_mem;
  3275. struct clk *clk;
  3276. dispc.pdev = pdev;
  3277. r = dispc_init_features(&dispc.pdev->dev);
  3278. if (r)
  3279. return r;
  3280. spin_lock_init(&dispc.irq_lock);
  3281. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  3282. spin_lock_init(&dispc.irq_stats_lock);
  3283. dispc.irq_stats.last_reset = jiffies;
  3284. #endif
  3285. INIT_WORK(&dispc.error_work, dispc_error_worker);
  3286. dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
  3287. if (!dispc_mem) {
  3288. DSSERR("can't get IORESOURCE_MEM DISPC\n");
  3289. return -EINVAL;
  3290. }
  3291. dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
  3292. resource_size(dispc_mem));
  3293. if (!dispc.base) {
  3294. DSSERR("can't ioremap DISPC\n");
  3295. return -ENOMEM;
  3296. }
  3297. dispc.irq = platform_get_irq(dispc.pdev, 0);
  3298. if (dispc.irq < 0) {
  3299. DSSERR("platform_get_irq failed\n");
  3300. return -ENODEV;
  3301. }
  3302. r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
  3303. IRQF_SHARED, "OMAP DISPC", dispc.pdev);
  3304. if (r < 0) {
  3305. DSSERR("request_irq failed\n");
  3306. return r;
  3307. }
  3308. clk = clk_get(&pdev->dev, "fck");
  3309. if (IS_ERR(clk)) {
  3310. DSSERR("can't get fck\n");
  3311. r = PTR_ERR(clk);
  3312. return r;
  3313. }
  3314. dispc.dss_clk = clk;
  3315. pm_runtime_enable(&pdev->dev);
  3316. r = dispc_runtime_get();
  3317. if (r)
  3318. goto err_runtime_get;
  3319. _omap_dispc_initial_config();
  3320. _omap_dispc_initialize_irq();
  3321. rev = dispc_read_reg(DISPC_REVISION);
  3322. dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
  3323. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  3324. dispc_runtime_put();
  3325. dss_debugfs_create_file("dispc", dispc_dump_regs);
  3326. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  3327. dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
  3328. #endif
  3329. return 0;
  3330. err_runtime_get:
  3331. pm_runtime_disable(&pdev->dev);
  3332. clk_put(dispc.dss_clk);
  3333. return r;
  3334. }
  3335. static int __exit omap_dispchw_remove(struct platform_device *pdev)
  3336. {
  3337. pm_runtime_disable(&pdev->dev);
  3338. clk_put(dispc.dss_clk);
  3339. return 0;
  3340. }
  3341. static int dispc_runtime_suspend(struct device *dev)
  3342. {
  3343. dispc_save_context();
  3344. return 0;
  3345. }
  3346. static int dispc_runtime_resume(struct device *dev)
  3347. {
  3348. dispc_restore_context();
  3349. return 0;
  3350. }
  3351. static const struct dev_pm_ops dispc_pm_ops = {
  3352. .runtime_suspend = dispc_runtime_suspend,
  3353. .runtime_resume = dispc_runtime_resume,
  3354. };
  3355. static struct platform_driver omap_dispchw_driver = {
  3356. .remove = __exit_p(omap_dispchw_remove),
  3357. .driver = {
  3358. .name = "omapdss_dispc",
  3359. .owner = THIS_MODULE,
  3360. .pm = &dispc_pm_ops,
  3361. },
  3362. };
  3363. int __init dispc_init_platform_driver(void)
  3364. {
  3365. return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
  3366. }
  3367. void __exit dispc_uninit_platform_driver(void)
  3368. {
  3369. platform_driver_unregister(&omap_dispchw_driver);
  3370. }