dispc.c 100 KB

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