dispc.c 81 KB

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