ddp_path.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #define LOG_TAG "ddp_path"
  32. #include "platform/mt_irq.h"
  33. #include "platform/mt_irq.h"
  34. #include "platform/disp_drv_platform.h"
  35. #include "platform/ddp_reg.h"
  36. #include "platform/ddp_path.h"
  37. #include "platform/ddp_info.h"
  38. #include "platform/ddp_log.h"
  39. #include <string.h>
  40. #define BIT_NUM (8)
  41. typedef struct module_map_s {
  42. DISP_MODULE_ENUM module;
  43. int bit;
  44. int mod_num;
  45. } module_map_t;
  46. typedef struct {
  47. unsigned int m;
  48. int v;
  49. } m_to_b;
  50. typedef struct mout_s {
  51. unsigned int id;
  52. m_to_b out_id_bit_map[BIT_NUM];
  53. volatile unsigned long *reg;
  54. unsigned int reg_val;
  55. } mout_t;
  56. typedef struct selection_s {
  57. unsigned int id;
  58. unsigned int id_bit_map[BIT_NUM];
  59. volatile unsigned long *reg;
  60. unsigned int reg_val;
  61. } sel_t;
  62. #define DDP_ENING_NUM (20)
  63. #define DDP_MOUT_NUM 10
  64. #define DDP_SEL_OUT_NUM 10
  65. #define DDP_SEL_IN_NUM 20
  66. #define DDP_MUTEX_MAX 5
  67. unsigned int module_list_scenario[DDP_SCENARIO_MAX][DDP_ENING_NUM] = {
  68. /*PRIMARY_DISP */
  69. {
  70. DISP_MODULE_OVL0, DISP_MODULE_OVL0_2L, DISP_MODULE_RDMA0, DISP_MODULE_COLOR0,
  71. DISP_MODULE_CCORR0, DISP_MODULE_AAL0, DISP_MODULE_GAMMA0, DISP_MODULE_DITHER0,
  72. DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  73. DISP_MODULE_NONE,
  74. },
  75. /*PRIMARY_RDMA0_COLOR0_DISP */
  76. {
  77. DISP_MODULE_RDMA0, DISP_MODULE_COLOR0, DISP_MODULE_CCORR0, DISP_MODULE_AAL0,
  78. DISP_MODULE_GAMMA0, DISP_MODULE_DITHER0, DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  79. DISP_MODULE_NONE,
  80. },
  81. /*PRIMARY_RDMA0_DISP */
  82. {
  83. DISP_MODULE_RDMA0, DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  84. DISP_MODULE_NONE,
  85. },
  86. /* DDP_SCENARIO_PRIMARY_OVL_MEMOUT */
  87. {
  88. DISP_MODULE_OVL0, DISP_MODULE_OVL0_2L, DISP_MODULE_WDMA_VIRTUAL0,
  89. DISP_MODULE_WDMA_VIRTUAL1, DISP_MODULE_WDMA0,
  90. DISP_MODULE_NONE,
  91. },
  92. /* DDP_SCENARIO_PRIMARY_ALL */
  93. {
  94. DISP_MODULE_OVL0, DISP_MODULE_OVL0_2L, DISP_MODULE_WDMA_VIRTUAL0,
  95. DISP_MODULE_WDMA_VIRTUAL1, DISP_MODULE_WDMA0, DISP_MODULE_RDMA0,
  96. DISP_MODULE_COLOR0, DISP_MODULE_CCORR0, DISP_MODULE_AAL0, DISP_MODULE_GAMMA0,
  97. DISP_MODULE_DITHER0, DISP_MODULE_DSI0,
  98. DISP_MODULE_NONE,
  99. },
  100. /* DDP_SCENARIO_SUB_DISP */
  101. {
  102. DISP_MODULE_OVL1_2L, DISP_MODULE_RDMA1, DISP_MODULE_DPI,
  103. DISP_MODULE_NONE,
  104. },
  105. /* DDP_SCENARIO_SUB_RDMA1_DISP */
  106. {
  107. DISP_MODULE_RDMA1, DISP_MODULE_DPI,
  108. DISP_MODULE_NONE,
  109. },
  110. };
  111. /* 1st para is mout's input, 2nd para is mout's output */
  112. static mout_t mout_map[DDP_MOUT_NUM] = {
  113. /* OVL_MOUT */
  114. {DISP_MODULE_OVL0,
  115. {{DISP_MODULE_RDMA0, 1 << 0}, {DISP_MODULE_WDMA_VIRTUAL0, 1 << 2},
  116. {DISP_MODULE_OVL0_2L, 1 << 4}, {DISP_MODULE_NONE, 0} },
  117. 0, 0},/* bit1 mdp_wrot, bit3 mdp_rsz */
  118. /* OVL0_2L_MOUT */
  119. {DISP_MODULE_OVL0_2L,
  120. {{DISP_MODULE_RDMA0, 1 << 0}, {DISP_MODULE_WDMA_VIRTUAL0, 1 << 2},
  121. {DISP_MODULE_OVL1_2L, 1 << 4}, {DISP_MODULE_NONE, 0} },
  122. 0, 0},
  123. /* OVL1_2L_MOUT */
  124. {DISP_MODULE_OVL1_2L,
  125. {{DISP_MODULE_RDMA0, 1 << 0}, {DISP_MODULE_WDMA_VIRTUAL0, 1 << 2},
  126. {DISP_MODULE_RDMA1, 1 << 4}, {DISP_MODULE_NONE, 0} },
  127. 0, 0},
  128. /* DITHER0_MOUT */
  129. {DISP_MODULE_DITHER0,
  130. {{DISP_MODULE_DSI0, 1 << 0}, {DISP_MODULE_WDMA_VIRTUAL0, 1 << 3},
  131. {DISP_MODULE_NONE, 0} },
  132. 0, 0}
  133. };
  134. static sel_t sel_out_map[DDP_SEL_OUT_NUM] = {
  135. /* RDMA0_SOUT */
  136. {DISP_MODULE_RDMA0,
  137. {DISP_MODULE_DSI0, DISP_MODULE_COLOR0,
  138. DISP_MODULE_CCORR0}, 0, 0},
  139. /* RDMA1_SOUT */
  140. {DISP_MODULE_RDMA1,
  141. {DISP_MODULE_DSI0, DISP_MODULE_DPI}, 0, 0},
  142. };
  143. /* 1st para is sout's output, 2nd para is sout's input */
  144. static sel_t sel_in_map[DDP_SEL_IN_NUM] = {
  145. /* COLOR_SEL */
  146. {DISP_MODULE_CCORR0, {DISP_MODULE_COLOR0, DISP_MODULE_RDMA0, DISP_MODULE_NONE}, 0, 0},
  147. /* RDMA_SEL */
  148. {DISP_MODULE_RDMA0, {DISP_MODULE_OVL0, DISP_MODULE_OVL0_2L,
  149. DISP_MODULE_OVL1_2L, DISP_MODULE_NONE}, 0, 0},
  150. /* WDMA_SEL */
  151. {DISP_MODULE_WDMA_VIRTUAL1, {DISP_MODULE_WDMA_VIRTUAL0,
  152. DISP_MODULE_DITHER0, DISP_MODULE_NONE}, 0, 0},
  153. /* OVL_TO_WDMA_SEL */
  154. {DISP_MODULE_WDMA_VIRTUAL0, {DISP_MODULE_OVL0, DISP_MODULE_OVL0_2L,
  155. DISP_MODULE_OVL1_2L, DISP_MODULE_NONE}, 0, 0},
  156. /* WDMA0_SEL */
  157. {DISP_MODULE_WDMA0, {DISP_MODULE_NUM, DISP_MODULE_NUM,
  158. DISP_MODULE_NUM, DISP_MODULE_WDMA_VIRTUAL1, DISP_MODULE_NONE}, 0, 0},
  159. /* DSI_SEL */
  160. {DISP_MODULE_DSI0, {DISP_MODULE_DITHER0, DISP_MODULE_RDMA0,
  161. DISP_MODULE_NUM, DISP_MODULE_RDMA1, DISP_MODULE_NONE}, 0, 0},
  162. /* DPI0_SEL */
  163. {DISP_MODULE_DPI, {DISP_MODULE_NUM, DISP_MODULE_RDMA0,
  164. DISP_MODULE_RDMA1, DISP_MODULE_DITHER0, DISP_MODULE_NONE}, 0, 0},
  165. };
  166. int ddp_path_init(void)
  167. {
  168. /* mout */
  169. mout_map[0].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_OVL0_MOUT_EN;
  170. mout_map[1].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_OVL0_2L_MOUT_EN;
  171. mout_map[2].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_OVL1_2L_MOUT_EN;
  172. mout_map[3].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_DITHER_MOUT_EN;
  173. /* sel_out */
  174. sel_out_map[0].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_RDMA0_SOUT_SEL_IN;
  175. sel_out_map[1].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_RDMA1_SOUT_SEL_IN;
  176. /* sel_in */
  177. sel_in_map[0].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_COLOR_OUT_SEL_IN;
  178. sel_in_map[1].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_PATH0_SEL_IN;
  179. sel_in_map[2].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_WDMA0_PRE_SEL_IN;
  180. sel_in_map[3].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_OVLTOWDMA_SEL_IN;
  181. sel_in_map[4].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_WDMA0_SEL_IN;
  182. sel_in_map[5].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_DSI0_SEL_IN;
  183. sel_in_map[6].reg = (volatile unsigned long *)DISP_REG_CONFIG_DISP_DPI0_SEL_IN;
  184. return 0;
  185. }
  186. static module_map_t module_mutex_map[DISP_MODULE_NUM] = {
  187. {DISP_MODULE_OVL0, 9, 0},
  188. {DISP_MODULE_OVL1, -1, 0},
  189. {DISP_MODULE_OVL0_2L, 10, 0},
  190. {DISP_MODULE_OVL1_2L, 11, 0},
  191. {DISP_MODULE_OVL0_VIRTUAL, -1, 0},
  192. {DISP_MODULE_OVL0_2L_VIRTUAL, -1, 0},
  193. {DISP_MODULE_OVL1_2L_VIRTUAL, -1, 0},
  194. {DISP_MODULE_RDMA0, 0, 0},
  195. {DISP_MODULE_RDMA1, 1, 0},
  196. {DISP_MODULE_RDMA2, -1, 0},
  197. {DISP_MODULE_WDMA0, 12, 0},
  198. {DISP_MODULE_WDMA1, -1, 0},
  199. {DISP_MODULE_WDMA_VIRTUAL0, -1, 0},
  200. {DISP_MODULE_WDMA_VIRTUAL1, -1, 0},
  201. {DISP_MODULE_COLOR0, 13, 0},
  202. {DISP_MODULE_COLOR1, -1, 0},
  203. {DISP_MODULE_CCORR0, 14, 0},
  204. {DISP_MODULE_CCORR1, -1, 0},
  205. {DISP_MODULE_AAL0, 15, 0},
  206. {DISP_MODULE_AAL1, -1, 0},
  207. {DISP_MODULE_GAMMA0, 16, 0},
  208. {DISP_MODULE_GAMMA1, -1, 0},
  209. {DISP_MODULE_OD, -1, 0},
  210. {DISP_MODULE_DITHER0, 17, 0},
  211. {DISP_MODULE_DITHER1, -1, 0},
  212. {DISP_MODULE_PATH0, -1, 0},
  213. {DISP_MODULE_PATH1, -1, 0},
  214. {DISP_MODULE_UFOE, -1, 0},
  215. {DISP_MODULE_DSC, -1, 0},
  216. {DISP_MODULE_DSC_2ND, -1, 0},
  217. {DISP_MODULE_SPLIT0, -1, 0},
  218. {DISP_MODULE_DPI, 20, 0},
  219. {DISP_MODULE_DSI0, 19, 0},
  220. {DISP_MODULE_DSI1, -1, 0},
  221. {DISP_MODULE_DSIDUAL, -1, 0},
  222. {DISP_MODULE_PWM0, 18, 0},
  223. {DISP_MODULE_PWM1, -1, 0},
  224. {DISP_MODULE_CONFIG, -1, 0},
  225. {DISP_MODULE_MUTEX, -1, 0},
  226. {DISP_MODULE_SMI_COMMON, -1, 0},
  227. {DISP_MODULE_SMI_LARB0, -1, 0},
  228. {DISP_MODULE_SMI_LARB1, -1, 0},
  229. {DISP_MODULE_MIPI0, -1, 0},
  230. {DISP_MODULE_MIPI1, -1, 0},
  231. {DISP_MODULE_RSZ0, -1, 0},
  232. {DISP_MODULE_RSZ1, -1, 0},
  233. {DISP_MODULE_UNKNOWN, -1, 0},
  234. };
  235. /* module can be connect if 1 */
  236. static module_map_t module_can_connect[DISP_MODULE_NUM] = {
  237. {DISP_MODULE_OVL0, 1, 0},
  238. {DISP_MODULE_OVL1, 0, 0},
  239. {DISP_MODULE_OVL0_2L, 1, 0},
  240. {DISP_MODULE_OVL1_2L, 1, 0},
  241. {DISP_MODULE_OVL0_VIRTUAL, 0, 0},
  242. {DISP_MODULE_OVL0_2L_VIRTUAL, 0, 0},
  243. {DISP_MODULE_OVL1_2L_VIRTUAL, 0, 0},
  244. {DISP_MODULE_RDMA0, 1, 0},
  245. {DISP_MODULE_RDMA1, 1, 0},
  246. {DISP_MODULE_RDMA2, 0, 0},
  247. {DISP_MODULE_WDMA0, 1, 0},
  248. {DISP_MODULE_WDMA1, 0, 0},
  249. {DISP_MODULE_WDMA_VIRTUAL0, 0, 0},
  250. {DISP_MODULE_WDMA_VIRTUAL1, 0, 0},
  251. {DISP_MODULE_COLOR0, 1, 0},
  252. {DISP_MODULE_COLOR1, 0, 0},
  253. {DISP_MODULE_CCORR0, 1, 0},
  254. {DISP_MODULE_CCORR1, 0, 0},
  255. {DISP_MODULE_AAL0, 1, 0},
  256. {DISP_MODULE_AAL1, 0, 0},
  257. {DISP_MODULE_GAMMA0, 1, 0},
  258. {DISP_MODULE_GAMMA1, 0, 0},
  259. {DISP_MODULE_OD, 0, 0},
  260. {DISP_MODULE_DITHER0, 1, 0},
  261. {DISP_MODULE_DITHER1, 0, 0},
  262. {DISP_MODULE_PATH0, 0, 0},
  263. {DISP_MODULE_PATH1, 0, 0},
  264. {DISP_MODULE_UFOE, 0, 0},
  265. {DISP_MODULE_DSC, 0, 0},
  266. {DISP_MODULE_DSC_2ND, 0, 0},
  267. {DISP_MODULE_SPLIT0, 0, 0},
  268. {DISP_MODULE_DPI, 1, 0},
  269. {DISP_MODULE_DSI0, 1, 0},
  270. {DISP_MODULE_DSI1, 0, 0},
  271. {DISP_MODULE_DSIDUAL, 0, 0},
  272. {DISP_MODULE_PWM0, 0, 0},
  273. {DISP_MODULE_PWM1, 0, 0},
  274. {DISP_MODULE_CONFIG, 0, 0},
  275. {DISP_MODULE_MUTEX, 0, 0},
  276. {DISP_MODULE_SMI_COMMON, 0, 0},
  277. {DISP_MODULE_SMI_LARB0, 0, 0},
  278. {DISP_MODULE_SMI_LARB1, 0, 0},
  279. {DISP_MODULE_MIPI0, 0, 0},
  280. {DISP_MODULE_MIPI1, 0, 0},
  281. {DISP_MODULE_RSZ0, 0, 0},
  282. {DISP_MODULE_RSZ1, 0, 0},
  283. {DISP_MODULE_UNKNOWN, 0, 0},
  284. };
  285. char *ddp_get_scenario_name(DDP_SCENARIO_ENUM scenario)
  286. {
  287. switch (scenario) {
  288. case DDP_SCENARIO_PRIMARY_DISP:
  289. return "primary_disp";
  290. case DDP_SCENARIO_PRIMARY_RDMA0_COLOR0_DISP:
  291. return "primary_rdma0_color0_disp";
  292. case DDP_SCENARIO_PRIMARY_RDMA0_DISP:
  293. return "primary_rdma0_disp";
  294. case DDP_SCENARIO_PRIMARY_OVL_MEMOUT:
  295. return "primary_ovl_memout";
  296. case DDP_SCENARIO_SUB_DISP:
  297. return "sub_disp";
  298. case DDP_SCENARIO_SUB_RDMA1_DISP:
  299. return "sub_rdma1_disp";
  300. case DDP_SCENARIO_SUB_OVL_MEMOUT:
  301. return "sub_ovl_memout";
  302. case DDP_SCENARIO_PRIMARY_ALL:
  303. return "primary_all";
  304. case DDP_SCENARIO_SUB_ALL:
  305. return "sub_all";
  306. default:
  307. DDPMSG("invalid scenario id=%d\n", scenario);
  308. return "unknown";
  309. }
  310. }
  311. int ddp_is_scenario_on_primary(DDP_SCENARIO_ENUM scenario)
  312. {
  313. int on_primary = 0;
  314. switch (scenario) {
  315. case DDP_SCENARIO_PRIMARY_DISP:
  316. case DDP_SCENARIO_PRIMARY_RDMA0_COLOR0_DISP:
  317. case DDP_SCENARIO_PRIMARY_RDMA0_DISP:
  318. case DDP_SCENARIO_PRIMARY_OVL_MEMOUT:
  319. case DDP_SCENARIO_PRIMARY_ALL:
  320. on_primary = 1;
  321. break;
  322. case DDP_SCENARIO_SUB_DISP:
  323. case DDP_SCENARIO_SUB_RDMA1_DISP:
  324. case DDP_SCENARIO_SUB_OVL_MEMOUT:
  325. case DDP_SCENARIO_SUB_ALL:
  326. on_primary = 0;
  327. break;
  328. default:
  329. DDPMSG("invalid scenario id=%d\n", scenario);
  330. }
  331. return on_primary;
  332. }
  333. char *ddp_get_mutex_sof_name(unsigned int regval)
  334. {
  335. if (regval == SOF_VAL_MUTEX0_SOF_SINGLE_MODE)
  336. return "single";
  337. else if (regval == SOF_VAL_MUTEX0_SOF_FROM_DSI0)
  338. return "dsi0";
  339. else if (regval == SOF_VAL_MUTEX0_SOF_FROM_DPI)
  340. return "dpi";
  341. DDPDUMP("%s, unknown reg=%d\n", __func__, regval);
  342. return "unknown";
  343. }
  344. char *ddp_get_mode_name(DDP_MODE ddp_mode)
  345. {
  346. switch (ddp_mode) {
  347. case DDP_VIDEO_MODE:
  348. return "vido_mode";
  349. case DDP_CMD_MODE:
  350. return "cmd_mode";
  351. default:
  352. DDPMSG("invalid ddp mode =%d\n", ddp_mode);
  353. return "unknown";
  354. }
  355. }
  356. static unsigned int ddp_get_module_num_l(unsigned int *module_list)
  357. {
  358. unsigned int num = 0;
  359. while (*(module_list + num) != DISP_MODULE_NONE) {
  360. num++;
  361. if (num == DDP_ENING_NUM)
  362. break;
  363. }
  364. return num;
  365. }
  366. /* config mout/msel to creat a compelte path */
  367. static void ddp_connect_path_l(unsigned int *module_list, void *handle)
  368. {
  369. int i, j, k;
  370. int step = 0;
  371. unsigned int mout = 0;
  372. unsigned int reg_mout = 0;
  373. unsigned int mout_idx = 0;
  374. int module_num = ddp_get_module_num_l(module_list);
  375. DDPDBG("connect_path: %s to %s\n", ddp_get_module_name(module_list[0]),
  376. ddp_get_module_name(module_list[module_num - 1]));
  377. /* connect mout */
  378. for (i = 0; i < module_num - 1; i++) {
  379. for (j = 0; j < DDP_MOUT_NUM; j++) {
  380. if (module_list[i] == mout_map[j].id) {
  381. /* find next module which can be connected */
  382. step = i + 1;
  383. while (module_can_connect[module_list[step]].bit == 0
  384. && step < module_num) {
  385. step++;
  386. }
  387. ASSERT(step < module_num);
  388. mout = mout_map[j].reg_val;
  389. for (k = 0; k < 5; k++) {
  390. if (mout_map[j].out_id_bit_map[k].m == DISP_MODULE_NONE)
  391. break;
  392. if (mout_map[j].out_id_bit_map[k].m == module_list[step]) {
  393. mout |= mout_map[j].out_id_bit_map[k].v;
  394. reg_mout |= mout;
  395. mout_idx = j;
  396. DDPDBG("connect mout %s to %s bits 0x%x\n",
  397. ddp_get_module_name(module_list[i]),
  398. ddp_get_module_name(module_list[step]),
  399. reg_mout);
  400. break;
  401. }
  402. }
  403. mout_map[j].reg_val = mout;
  404. mout = 0;
  405. }
  406. }
  407. if (reg_mout) {
  408. DISP_REG_SET(handle, mout_map[mout_idx].reg, reg_mout);
  409. reg_mout = 0;
  410. mout_idx = 0;
  411. }
  412. }
  413. /* connect out select */
  414. for (i = 0; i < module_num - 1; i++) {
  415. for (j = 0; j < DDP_SEL_OUT_NUM; j++) {
  416. if (module_list[i] == sel_out_map[j].id) {
  417. step = i + 1;
  418. /* find next module which can be connected */
  419. while (module_can_connect[module_list[step]].bit == 0
  420. && step < module_num) {
  421. step++;
  422. }
  423. ASSERT(step < module_num);
  424. for (k = 0; k < 4; k++) {
  425. if (sel_out_map[j].id_bit_map[k] == DISP_MODULE_NONE)
  426. break;
  427. if (sel_out_map[j].id_bit_map[k] == module_list[step]) {
  428. DDPDBG("connect out_s %s to %s, value=%d\n",
  429. ddp_get_module_name(module_list[i]),
  430. ddp_get_module_name(module_list[step]), k);
  431. DISP_REG_SET(handle, sel_out_map[j].reg,
  432. (uint16_t) k);
  433. break;
  434. }
  435. }
  436. }
  437. }
  438. }
  439. /* connect input select */
  440. for (i = 1; i < module_num; i++) {
  441. for (j = 0; j < DDP_SEL_IN_NUM; j++) {
  442. if (module_list[i] == sel_in_map[j].id) {
  443. int found = 0;
  444. step = i - 1;
  445. /* find next module which can be connected */
  446. while (module_can_connect[module_list[step]].bit == 0 && step > 0)
  447. step--;
  448. ASSERT(step >= 0);
  449. for (k = 0; k < 4; k++) {
  450. if (sel_in_map[j].id_bit_map[k] == DISP_MODULE_NONE)
  451. break;
  452. if (sel_in_map[j].id_bit_map[k] == module_list[step]) {
  453. DDPDBG("connect in_s %s to %s, value=%d\n",
  454. ddp_get_module_name(module_list[step]),
  455. ddp_get_module_name(module_list[i]), k);
  456. DISP_REG_SET(handle, sel_in_map[j].reg,
  457. (uint16_t) k);
  458. found = 1;
  459. break;
  460. }
  461. }
  462. if (!found)
  463. DDPERR("%s error: %s sel_in not set\n", __func__,
  464. ddp_get_module_name(module_list[i]));
  465. }
  466. }
  467. }
  468. }
  469. static void ddp_check_path_l(unsigned int *module_list)
  470. {
  471. int i, j;
  472. unsigned int k;
  473. int step = 0;
  474. int valid = 0;
  475. unsigned int mout;
  476. unsigned int path_error = 0;
  477. int module_num = ddp_get_module_num_l(module_list);
  478. DDPDUMP("check_path: %s to %s\n", ddp_get_module_name(module_list[0])
  479. , ddp_get_module_name(module_list[module_num - 1]));
  480. /* check mout */
  481. for (i = 0; i < module_num - 1; i++) {
  482. for (j = 0; j < DDP_MOUT_NUM; j++) {
  483. if (module_list[i] == mout_map[j].id) {
  484. mout = 0;
  485. /* find next module which can be connected */
  486. step = i + 1;
  487. while (module_can_connect[module_list[step]].bit == 0
  488. && step < module_num) {
  489. step++;
  490. }
  491. ASSERT(step < module_num);
  492. for (k = 0; k < 5; k++) {
  493. if (mout_map[j].out_id_bit_map[k].m == DISP_MODULE_NONE)
  494. break;
  495. if (mout_map[j].out_id_bit_map[k].m == module_list[step]) {
  496. mout |= mout_map[j].out_id_bit_map[k].v;
  497. valid = 1;
  498. break;
  499. }
  500. }
  501. if (valid) {
  502. valid = 0;
  503. if ((DISP_REG_GET(mout_map[j].reg) & mout) == 0) {
  504. path_error += 1;
  505. DDPDUMP("error:%s mout, expect=0x%x, real=0x%x\n",
  506. ddp_get_module_name(module_list[i]),
  507. mout, DISP_REG_GET(mout_map[j].reg));
  508. } else if (DISP_REG_GET(mout_map[j].reg) != mout) {
  509. DDPDUMP
  510. ("warning: %s mout expect=0x%x, real=0x%x\n",
  511. ddp_get_module_name(module_list[i]), mout,
  512. DISP_REG_GET(mout_map[j].reg));
  513. }
  514. }
  515. break;
  516. }
  517. }
  518. }
  519. /* check out select */
  520. for (i = 0; i < module_num - 1; i++) {
  521. for (j = 0; j < DDP_SEL_OUT_NUM; j++) {
  522. if (module_list[i] != sel_out_map[j].id)
  523. continue;
  524. /* find next module which can be connected */
  525. step = i + 1;
  526. while (module_can_connect[module_list[step]].bit == 0
  527. && step < module_num) {
  528. step++;
  529. }
  530. ASSERT(step < module_num);
  531. for (k = 0; k < 4; k++) {
  532. if (sel_out_map[j].id_bit_map[k] == DISP_MODULE_NONE)
  533. break;
  534. if (sel_out_map[j].id_bit_map[k] == module_list[step]) {
  535. if (DISP_REG_GET(sel_out_map[j].reg) != k) {
  536. path_error += 1;
  537. DDPDUMP
  538. ("error:out_s %s not connect to %s, expect=0x%x, real=0x%x\n",
  539. ddp_get_module_name(module_list[i]),
  540. ddp_get_module_name(module_list[step]),
  541. k, DISP_REG_GET(sel_out_map[j].reg));
  542. }
  543. break;
  544. }
  545. }
  546. }
  547. }
  548. /* check input select */
  549. for (i = 1; i < module_num; i++) {
  550. for (j = 0; j < DDP_SEL_IN_NUM; j++) {
  551. if (module_list[i] != sel_in_map[j].id)
  552. continue;
  553. /* find next module which can be connected */
  554. step = i - 1;
  555. while (module_can_connect[module_list[step]].bit == 0 && step > 0)
  556. step--;
  557. ASSERT(step >= 0);
  558. for (k = 0; k < 4; k++) {
  559. if (sel_in_map[j].id_bit_map[k] == DISP_MODULE_NONE)
  560. break;
  561. if (sel_in_map[j].id_bit_map[k] == module_list[step]) {
  562. if (DISP_REG_GET(sel_in_map[j].reg) != k) {
  563. path_error += 1;
  564. DDPDUMP("error:in_s %s not conn to %s,expect0x%x,real0x%x\n",
  565. ddp_get_module_name(module_list[step]),
  566. ddp_get_module_name(module_list[i]), k,
  567. DISP_REG_GET(sel_in_map[j].reg));
  568. }
  569. break;
  570. }
  571. }
  572. }
  573. }
  574. if (path_error == 0) {
  575. DDPDUMP("path: %s to %s is connected\n", ddp_get_module_name(module_list[0]),
  576. ddp_get_module_name(module_list[module_num - 1]));
  577. } else {
  578. DDPDUMP("path: %s to %s not connected!!!\n", ddp_get_module_name(module_list[0]),
  579. ddp_get_module_name(module_list[module_num - 1]));
  580. }
  581. }
  582. static void ddp_disconnect_path_l(unsigned int *module_list, void *handle)
  583. {
  584. int i, j, k;
  585. int step = 0;
  586. unsigned int mout = 0;
  587. unsigned int reg_mout = 0;
  588. unsigned int mout_idx = 0;
  589. int module_num = ddp_get_module_num_l(module_list);
  590. DDPDBG("disconnect_path: %s to %s\n", ddp_get_module_name(module_list[0]),
  591. ddp_get_module_name(module_list[module_num - 1]));
  592. for (i = 0; i < module_num - 1; i++) {
  593. for (j = 0; j < DDP_MOUT_NUM; j++) {
  594. if (module_list[i] == mout_map[j].id) {
  595. /* find next module which can be connected */
  596. step = i + 1;
  597. while (module_can_connect[module_list[step]].bit == 0
  598. && step < module_num) {
  599. step++;
  600. }
  601. ASSERT(step < module_num);
  602. for (k = 0; k < 5; k++) {
  603. if (mout_map[j].out_id_bit_map[k].m == DISP_MODULE_NONE)
  604. break;
  605. if (mout_map[j].out_id_bit_map[k].m == module_list[step]) {
  606. mout |= mout_map[j].out_id_bit_map[k].v;
  607. reg_mout |= mout;
  608. mout_idx = j;
  609. DDPDBG("disconnect mout %s to %s\n",
  610. ddp_get_module_name(module_list[i]),
  611. ddp_get_module_name(module_list[step]));
  612. break;
  613. }
  614. }
  615. /* update mout_value */
  616. mout_map[j].reg_val &= ~mout;
  617. mout = 0;
  618. }
  619. }
  620. if (reg_mout) {
  621. DISP_REG_SET(handle, mout_map[mout_idx].reg, mout_map[mout_idx].reg_val);
  622. reg_mout = 0;
  623. mout_idx = 0;
  624. }
  625. }
  626. }
  627. static int ddp_get_mutex_src(DISP_MODULE_ENUM dest_module, DDP_MODE ddp_mode,
  628. unsigned int *SOF_src, unsigned int *EOF_src)
  629. {
  630. unsigned int src_from_dst_module = 0;
  631. if (dest_module == DISP_MODULE_WDMA0 || dest_module == DISP_MODULE_WDMA1) {
  632. if (ddp_mode == DDP_VIDEO_MODE)
  633. DISP_LOG_W("%s: dst_mode=%s, but is video mode !!\n", __func__,
  634. ddp_get_module_name(dest_module));
  635. *SOF_src = *EOF_src = SOF_VAL_MUTEX0_SOF_SINGLE_MODE;
  636. return 0;
  637. }
  638. if (dest_module == DISP_MODULE_DSI0 || dest_module == DISP_MODULE_DSIDUAL) {
  639. src_from_dst_module = SOF_VAL_MUTEX0_SOF_FROM_DSI0;
  640. } else if (dest_module == DISP_MODULE_DPI) {
  641. src_from_dst_module = SOF_VAL_MUTEX0_SOF_FROM_DPI;
  642. } else {
  643. DDPERR("get mutex sof, invalid param dst module = %s(%d), dis mode %s\n",
  644. ddp_get_module_name(dest_module), dest_module, ddp_get_mode_name(ddp_mode));
  645. ASSERT(0);
  646. }
  647. if (ddp_mode == DDP_CMD_MODE) {
  648. *SOF_src = SOF_VAL_MUTEX0_SOF_SINGLE_MODE;
  649. if (0/*disp_helper_get_option(DISP_OPT_MUTEX_EOF_EN_FOR_CMD_MODE)*/)
  650. *EOF_src = src_from_dst_module;
  651. else
  652. *EOF_src = SOF_VAL_MUTEX0_EOF_DISABLE;
  653. } else {
  654. *SOF_src = *EOF_src = src_from_dst_module;
  655. }
  656. return 0;
  657. }
  658. /* id: mutex ID, 0~5 */
  659. static int ddp_mutex_set_l(int mutex_id, unsigned int *module_list, DDP_MODE ddp_mode, void *handle)
  660. {
  661. int i = 0;
  662. unsigned int value0 = 0;
  663. unsigned int value1 = 0;
  664. unsigned int sof_val;
  665. unsigned int sof_src, eof_src;
  666. int module_num = ddp_get_module_num_l(module_list);
  667. ddp_get_mutex_src(module_list[module_num - 1], ddp_mode, &sof_src, &eof_src);
  668. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  669. DDPERR("exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  670. return -1;
  671. }
  672. for (i = 0; i < module_num; i++) {
  673. if (module_mutex_map[module_list[i]].bit != -1) {
  674. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module_list[i]),
  675. mutex_id);
  676. if (module_mutex_map[module_list[i]].mod_num == 0) {
  677. value0 |= (1 << module_mutex_map[module_list[i]].bit);
  678. } else if (module_mutex_map[module_list[i]].mod_num == 1) {
  679. /* DISP_MODULE_DSIDUAL is special */
  680. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  681. value1 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  682. value1 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  683. } else {
  684. value1 |= (1 << module_mutex_map[module_list[i]].bit);
  685. }
  686. }
  687. } else {
  688. DDPDBG("module %s not added to mutex %d\n",
  689. ddp_get_module_name(module_list[i]), mutex_id);
  690. }
  691. }
  692. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), value0);
  693. sof_val = REG_FLD_VAL(SOF_FLD_MUTEX0_SOF, sof_src);
  694. sof_val |= REG_FLD_VAL(SOF_FLD_MUTEX0_EOF, eof_src);
  695. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), sof_val);
  696. DDPDBG("mutex %d value=0x%x, sof=%s, eof=%s\n", mutex_id,
  697. value0, ddp_get_mutex_sof_name(sof_src), ddp_get_mutex_sof_name(eof_src));
  698. return 0;
  699. }
  700. static void ddp_check_mutex_l(int mutex_id, unsigned int *module_list, DDP_MODE ddp_mode)
  701. {
  702. int i = 0;
  703. uint32_t real_value0 = 0;
  704. uint32_t real_value1 = 0;
  705. uint32_t expect_value0 = 0;
  706. uint32_t expect_value1 = 0;
  707. unsigned int real_sof, real_eof, val;
  708. unsigned int expect_sof, expect_eof;
  709. int module_num = ddp_get_module_num_l(module_list);
  710. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  711. DDPDUMP("error:check mutex fail:exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  712. return;
  713. }
  714. real_value0 = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_MOD0(mutex_id));
  715. for (i = 0; i < module_num; i++) {
  716. if (module_mutex_map[module_list[i]].bit != -1) {
  717. if (module_mutex_map[module_list[i]].mod_num == 0) {
  718. expect_value0 |= (1 << module_mutex_map[module_list[i]].bit);
  719. } else if (module_mutex_map[module_list[i]].mod_num == 1) {
  720. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  721. expect_value1 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  722. expect_value1 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  723. } else {
  724. expect_value1 |= (1 << module_mutex_map[module_list[i]].bit);
  725. }
  726. }
  727. }
  728. }
  729. if (expect_value0 != real_value0)
  730. DDPDUMP("error:mutex %d error: expect0 0x%x, real0 0x%x\n", mutex_id, expect_value0,
  731. real_value0);
  732. if (expect_value1 != real_value1)
  733. DDPDUMP("error:mutex %d error: expect1 0x%x, real1 0x%x\n", mutex_id, expect_value1,
  734. real_value1);
  735. val = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_SOF(mutex_id));
  736. real_sof = REG_FLD_VAL_GET(SOF_FLD_MUTEX0_SOF, val);
  737. real_eof = REG_FLD_VAL_GET(SOF_FLD_MUTEX0_EOF, val);
  738. ddp_get_mutex_src(module_list[module_num - 1], ddp_mode, &expect_sof, &expect_eof);
  739. if (expect_sof != real_sof)
  740. DDPDUMP("error:mutex %d sof error: expect %s, real %s\n", mutex_id,
  741. ddp_get_mutex_sof_name(expect_sof), ddp_get_mutex_sof_name(real_sof));
  742. if (expect_eof != real_eof)
  743. DDPDUMP("error:mutex %d eof error: expect %s, real %s\n", mutex_id,
  744. ddp_get_mutex_sof_name(expect_eof), ddp_get_mutex_sof_name(real_eof));
  745. }
  746. static int ddp_mutex_enable_l(int mutex_idx, void *handle)
  747. {
  748. DDPDBG("mutex %d enable\n", mutex_idx);
  749. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_EN(mutex_idx), 1);
  750. return 0;
  751. }
  752. int ddp_get_module_num(DDP_SCENARIO_ENUM scenario)
  753. {
  754. return ddp_get_module_num_l(module_list_scenario[scenario]);
  755. }
  756. static void ddp_print_scenario(DDP_SCENARIO_ENUM scenario)
  757. {
  758. int i =0;
  759. char path[512]= {'\0'};
  760. int num = ddp_get_module_num(scenario);
  761. for (i = 0; i < num; i++)
  762. strncat(path, ddp_get_module_name(module_list_scenario[scenario][i]),
  763. (sizeof(path) - strlen(path) - 1));
  764. DDPMSG("scenario %s have modules: %s\n",ddp_get_scenario_name(scenario),path);
  765. }
  766. static int ddp_find_module_index(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  767. {
  768. int i = 0;
  769. for (i = 0; i < DDP_ENING_NUM; i++) {
  770. if (module_list_scenario[ddp_scenario][i] == module)
  771. return i;
  772. }
  773. DDPDBG("find module: can not find module %s on scenario %s\n", ddp_get_module_name(module),
  774. ddp_get_scenario_name(ddp_scenario));
  775. return -1;
  776. }
  777. /* set display interface when kernel init */
  778. int ddp_set_dst_module(DDP_SCENARIO_ENUM scenario, DISP_MODULE_ENUM dst_module)
  779. {
  780. int i = 0;
  781. DDPMSG("ddp_set_dst_module, scenario=%s, dst_module=%s\n",
  782. ddp_get_scenario_name(scenario), ddp_get_module_name(dst_module));
  783. if (ddp_find_module_index(scenario, dst_module) > 0) {
  784. DDPDBG("%s is already on path\n", ddp_get_module_name(dst_module));
  785. return 0;
  786. }
  787. i = ddp_get_module_num_l(module_list_scenario[scenario]) - 1;
  788. ASSERT(i >= 0);
  789. if (dst_module == DISP_MODULE_DSIDUAL) {
  790. if (i < (DDP_ENING_NUM - 1)) {
  791. module_list_scenario[scenario][i++] = DISP_MODULE_SPLIT0;
  792. } else {
  793. DDPERR("set dst module over up bound\n");
  794. return -1;
  795. }
  796. } else {
  797. if (ddp_get_dst_module(scenario) == DISP_MODULE_DSIDUAL) {
  798. if (i >= 1) {
  799. module_list_scenario[scenario][i--] = -1;
  800. } else {
  801. DDPERR("set dst module over low bound\n");
  802. return -1;
  803. }
  804. }
  805. }
  806. module_list_scenario[scenario][i] = dst_module;
  807. if (scenario == DDP_SCENARIO_PRIMARY_ALL)
  808. ddp_set_dst_module(DDP_SCENARIO_PRIMARY_DISP, dst_module);
  809. else if (scenario == DDP_SCENARIO_SUB_ALL)
  810. ddp_set_dst_module(DDP_SCENARIO_SUB_RDMA1_DISP, dst_module);
  811. ddp_print_scenario(scenario);
  812. return 0;
  813. }
  814. DISP_MODULE_ENUM ddp_get_dst_module(DDP_SCENARIO_ENUM ddp_scenario)
  815. {
  816. DISP_MODULE_ENUM module_name = DISP_MODULE_UNKNOWN;
  817. int module_num = ddp_get_module_num_l(module_list_scenario[ddp_scenario]) - 1;
  818. if (module_num >= 0)
  819. module_name = module_list_scenario[ddp_scenario][module_num];
  820. return module_name;
  821. }
  822. unsigned int *ddp_get_scenario_list(DDP_SCENARIO_ENUM ddp_scenario)
  823. {
  824. return module_list_scenario[ddp_scenario];
  825. }
  826. int ddp_is_module_in_scenario(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  827. {
  828. int i = 0;
  829. for (i = 0; i < DDP_ENING_NUM; i++) {
  830. if (module_list_scenario[ddp_scenario][i] == module)
  831. return 1;
  832. }
  833. return 0;
  834. }
  835. int ddp_insert_module(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM place,
  836. DISP_MODULE_ENUM module)
  837. {
  838. int i = DDP_ENING_NUM - 1;
  839. int idx = ddp_find_module_index(ddp_scenario, place);
  840. if (idx < 0) {
  841. DDPERR("error: ddp_insert_module , place=%s is not in scenario %s!\n",
  842. ddp_get_module_name(place), ddp_get_scenario_name(ddp_scenario));
  843. return -1;
  844. }
  845. for (i = 0; i < DDP_ENING_NUM; i++) {
  846. if (module_list_scenario[ddp_scenario][i] == module) {
  847. DDPERR("error: ddp_insert_module , module=%s is already in scenario %s!\n",
  848. ddp_get_module_name(module), ddp_get_scenario_name(ddp_scenario));
  849. return -1;
  850. }
  851. }
  852. /* should have empty room for insert */
  853. ASSERT(module_list_scenario[ddp_scenario][DDP_ENING_NUM - 1] == DISP_MODULE_NONE);
  854. for (i = DDP_ENING_NUM - 2; i >= idx; i--)
  855. module_list_scenario[ddp_scenario][i + 1] = module_list_scenario[ddp_scenario][i];
  856. module_list_scenario[ddp_scenario][idx] = module;
  857. {
  858. unsigned int *modules = ddp_get_scenario_list(ddp_scenario);
  859. int module_num = ddp_get_module_num(ddp_scenario);
  860. DDPMSG("after insert module, module list is:\n");
  861. for (i = 0; i < module_num; i++)
  862. DDPMSG("%s-", ddp_get_module_name(modules[i]));
  863. }
  864. return 0;
  865. }
  866. int ddp_remove_module(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  867. {
  868. int i = 0;
  869. int idx = ddp_find_module_index(ddp_scenario, module);
  870. if (idx < 0) {
  871. DDPERR("ddp_remove_module, can not find module %s in scenario %s\n",
  872. ddp_get_module_name(module), ddp_get_scenario_name(ddp_scenario));
  873. return -1;
  874. }
  875. for (i = idx; i < DDP_ENING_NUM - 1; i++)
  876. module_list_scenario[ddp_scenario][i] = module_list_scenario[ddp_scenario][i + 1];
  877. module_list_scenario[ddp_scenario][DDP_ENING_NUM - 1] = -1;
  878. {
  879. unsigned int *modules = ddp_get_scenario_list(ddp_scenario);
  880. int module_num = ddp_get_module_num(ddp_scenario);
  881. DDPMSG("after remove module, module list is:\n");
  882. for (i = 0; i < module_num; i++)
  883. DDPMSG("%s-", ddp_get_module_name(modules[i]));
  884. }
  885. return 0;
  886. }
  887. void ddp_connect_path(DDP_SCENARIO_ENUM scenario, void *handle)
  888. {
  889. DDPDBG("path connect on scenario %s\n", ddp_get_scenario_name(scenario));
  890. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  891. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP], handle);
  892. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT], handle);
  893. } else if (scenario == DDP_SCENARIO_SUB_ALL) {
  894. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_SUB_DISP], handle);
  895. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_SUB_OVL_MEMOUT], handle);
  896. } else {
  897. ddp_connect_path_l(module_list_scenario[scenario], handle);
  898. }
  899. return;
  900. }
  901. void ddp_disconnect_path(DDP_SCENARIO_ENUM scenario, void *handle)
  902. {
  903. DDPDBG("path disconnect on scenario %s\n", ddp_get_scenario_name(scenario));
  904. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  905. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP], handle);
  906. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT],
  907. handle);
  908. } else if (scenario == DDP_SCENARIO_SUB_ALL) {
  909. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_SUB_DISP], handle);
  910. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_SUB_OVL_MEMOUT], handle);
  911. } else {
  912. ddp_disconnect_path_l(module_list_scenario[scenario], handle);
  913. }
  914. return;
  915. }
  916. void ddp_check_path(DDP_SCENARIO_ENUM scenario)
  917. {
  918. DDPDBG("path check path on scenario %s\n", ddp_get_scenario_name(scenario));
  919. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  920. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP]);
  921. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT]);
  922. } else if (scenario == DDP_SCENARIO_SUB_ALL) {
  923. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_SUB_DISP]);
  924. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_SUB_OVL_MEMOUT]);
  925. } else {
  926. ddp_check_path_l(module_list_scenario[scenario]);
  927. }
  928. return;
  929. }
  930. void ddp_check_mutex(int mutex_id, DDP_SCENARIO_ENUM scenario, DDP_MODE mode)
  931. {
  932. DDPDBG("check mutex %d on scenario %s\n", mutex_id, ddp_get_scenario_name(scenario));
  933. ddp_check_mutex_l(mutex_id, module_list_scenario[scenario], mode);
  934. }
  935. int ddp_mutex_set(int mutex_id, DDP_SCENARIO_ENUM scenario, DDP_MODE mode, void *handle)
  936. {
  937. if (scenario < DDP_SCENARIO_MAX) {
  938. return ddp_mutex_set_l(mutex_id, module_list_scenario[scenario], mode, handle);
  939. } else {
  940. DDPERR("Invalid scenario %d when setting mutex\n", scenario);
  941. return -1;
  942. }
  943. return 0;
  944. }
  945. int ddp_mutex_Interrupt_enable(int mutex_id, void *handle)
  946. {
  947. DDPDBG("mutex %d interrupt enable\n", mutex_id);
  948. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0x1 << mutex_id, 0x1 << mutex_id);
  949. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 1 << (mutex_id + DISP_MUTEX_TOTAL),
  950. 0x1 << (mutex_id + DISP_MUTEX_TOTAL));
  951. return 0;
  952. }
  953. int ddp_mutex_Interrupt_disable(int mutex_id, void *handle)
  954. {
  955. DDPDBG("mutex %d interrupt disenable\n", mutex_id);
  956. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0, 0x1 << mutex_id);
  957. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0, 0x1 << (mutex_id + DISP_MUTEX_TOTAL));
  958. return 0;
  959. }
  960. int ddp_mutex_reset(int mutex_id, void *handle)
  961. {
  962. DDPDBG("mutex %d reset\n", mutex_id);
  963. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_RST(mutex_id), 1);
  964. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_RST(mutex_id), 0);
  965. return 0;
  966. }
  967. int ddp_is_moudule_in_mutex(int mutex_id, DISP_MODULE_ENUM module)
  968. {
  969. int ret = 0;
  970. uint32_t real_value = 0;
  971. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  972. DDPDUMP("error:check_moudule_in_mute fail:exceed mutex max (0 ~ %d)\n",
  973. DISP_MUTEX_DDP_LAST);
  974. return ret;
  975. }
  976. if (module_mutex_map[module].mod_num == 0) {
  977. real_value = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_MOD0(mutex_id));
  978. } else if (module_mutex_map[module].mod_num == 1) {
  979. real_value = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_MOD1(mutex_id));
  980. }
  981. if (1 == ((real_value >> module_mutex_map[module].bit) & 0x01))
  982. ret = 1;
  983. return ret;
  984. }
  985. int ddp_mutex_add_module(int mutex_id, DISP_MODULE_ENUM module, void *handle)
  986. {
  987. int value = 0;
  988. if (module < DISP_MODULE_UNKNOWN) {
  989. if (module_mutex_map[module].bit != -1) {
  990. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module),
  991. mutex_id);
  992. value |= (1 << module_mutex_map[module].bit);
  993. if (module_mutex_map[module].mod_num == 0) {
  994. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), value, value);
  995. } else if (module_mutex_map[module].mod_num == 1) {
  996. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD1(mutex_id), value, value);
  997. }
  998. }
  999. }
  1000. return 0;
  1001. }
  1002. int ddp_mutex_remove_module(int mutex_id, DISP_MODULE_ENUM module, void *handle)
  1003. {
  1004. int value = 0;
  1005. if (module < DISP_MODULE_UNKNOWN) {
  1006. if (module_mutex_map[module].bit != -1) {
  1007. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module),
  1008. mutex_id);
  1009. value |= (1 << module_mutex_map[module].bit);
  1010. if (module_mutex_map[module].mod_num == 0) {
  1011. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), 0, value);
  1012. } else if (module_mutex_map[module].mod_num == 1) {
  1013. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD1(mutex_id), 0, value);
  1014. }
  1015. }
  1016. }
  1017. return 0;
  1018. }
  1019. int ddp_mutex_clear(int mutex_id, void *handle)
  1020. {
  1021. DDPDBG("mutex %d clear\n", mutex_id);
  1022. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), 0);
  1023. /*DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_MOD1(mutex_id), 0);*/
  1024. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), 0);
  1025. /* enough or not */
  1026. /*reset mutex */
  1027. ddp_mutex_reset(mutex_id, handle);
  1028. return 0;
  1029. }
  1030. int ddp_mutex_enable(int mutex_id, DDP_SCENARIO_ENUM scenario, void *handle)
  1031. {
  1032. return ddp_mutex_enable_l(mutex_id, handle);
  1033. }
  1034. int ddp_mutex_disable(int mutex_id, DDP_SCENARIO_ENUM scenario, void *handle)
  1035. {
  1036. DDPDBG("mutex %d disable\n", mutex_id);
  1037. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_EN(mutex_id), 0);
  1038. return 0;
  1039. }
  1040. int ddp_mutex_get(int mutex_id, DDP_SCENARIO_ENUM scenario, void *handle)
  1041. {
  1042. DDPDBG("mutex %d get\n", mutex_id);
  1043. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_GET(mutex_id), 1);
  1044. return 0;
  1045. }
  1046. int ddp_mutex_release(int mutex_id, DDP_SCENARIO_ENUM scenario, void *handle)
  1047. {
  1048. DDPDBG("mutex %d release\n", mutex_id);
  1049. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_GET(mutex_id), 0);
  1050. return 0;
  1051. }
  1052. int ddp_mutex_set_sof_wait(int mutex_id, cmdqRecHandle handle, int wait)
  1053. {
  1054. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  1055. DDPERR("exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  1056. return -1;
  1057. }
  1058. DISP_REG_SET_FIELD(handle, SOF_FLD_MUTEX0_SOF_WAIT, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), wait);
  1059. return 0;
  1060. }
  1061. int ddp_check_engine_status(int mutexID)
  1062. {
  1063. /* check engines' clock bit & enable bit & status bit before unlock mutex */
  1064. /* should not needed, in comdq do? */
  1065. int result = 0;
  1066. return result;
  1067. }
  1068. int ddp_path_top_clock_on(void)
  1069. {
  1070. DDPMSG("ddp path top clock on\n");
  1071. ddp_enable_module_clock(DISP_MODULE_SMI_COMMON);
  1072. ddp_enable_module_clock(DISP_MODULE_SMI_LARB0);
  1073. ddp_enable_module_clock(DISP_MODULE_SMI_LARB1);
  1074. DDPMSG("ddp CG0:%x CG1:%x\n", DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  1075. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1));
  1076. return 0;
  1077. }
  1078. int ddp_path_top_clock_off(void)
  1079. {
  1080. DDPMSG("ddp path top clock off\n");
  1081. ddp_disable_module_clock(DISP_MODULE_SMI_LARB0);
  1082. ddp_enable_module_clock(DISP_MODULE_SMI_LARB1);
  1083. ddp_disable_module_clock(DISP_MODULE_SMI_COMMON);
  1084. DDPMSG("ddp CG0:%x CG1:%x\n", DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  1085. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1));
  1086. return 0;
  1087. }
  1088. int ddp_path_m4u_off(void)
  1089. {
  1090. int i;
  1091. #ifdef MTKFB_NO_M4U
  1092. /* display ports bypass m4u.
  1093. ==== FBI WARNING: ==========
  1094. This function is hard code of m4u port setting !!!
  1095. Please ask M4U owner about it for new chip porting !!!
  1096. */
  1097. /*
  1098. M4U_PORT_DISP_OVL0,
  1099. M4U_PORT_DISP_2L_OVL0_LARB0,
  1100. M4U_PORT_DISP_2L_OVL1_LARB0,
  1101. M4U_PORT_DISP_RDMA0,
  1102. M4U_PORT_DISP_RDMA1,
  1103. M4U_PORT_DISP_WDMA0,
  1104. */
  1105. for (i=0; i<6; i++)
  1106. DISP_REG_SET_FIELD(0, REG_FLD_MMU_EN, DISP_REG_SMI_LARB0_MMU_EN + i*4, 0);
  1107. #endif
  1108. return 0;
  1109. }