dispc.c 96 KB

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