dispc.c 78 KB

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