dispc.c 89 KB

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