dispc.c 80 KB

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