dispc.c 86 KB

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