dispc.c 78 KB

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