dispc.c 80 KB

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