dispc.c 87 KB

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