ddp_path.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  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_reg_pq.h"
  37. #include "platform/ddp_path.h"
  38. #include "platform/ddp_info.h"
  39. #include "platform/ddp_log.h"
  40. #include "platform/spm.h"
  41. extern ddp_module ddp_modules[DISP_MODULE_NUM];
  42. #define DDP_ENING_NUM (20) /* max module num of path */
  43. #define DDP_MOUT_MAX 8
  44. #define DDP_SOUT_MAX 8
  45. #define DDP_MUTEX_MAX 4
  46. /* struct for mutex mod */
  47. typedef struct module_map_s {
  48. DISP_MODULE_ENUM module;
  49. int bit;
  50. int mod_num;
  51. } module_map_t;
  52. typedef struct {
  53. int m;
  54. int v;
  55. } m_to_b;
  56. typedef struct mout_s {
  57. int id;
  58. m_to_b out_id_bit_map[DDP_MOUT_MAX];
  59. volatile unsigned long *reg;
  60. unsigned int reg_val;
  61. } mout_t;
  62. typedef struct selection_s {
  63. int id;
  64. int id_bit_map[DDP_SOUT_MAX];
  65. volatile unsigned long *reg;
  66. unsigned int reg_val;
  67. } sel_t;
  68. int primary_disp_dsc_module_list[DDP_ENING_NUM] = {
  69. DISP_MODULE_OVL0_2L, DISP_MODULE_OVL0,
  70. DISP_MODULE_RDMA0,
  71. DISP_MODULE_COLOR0, DISP_MODULE_CCORR0, DISP_MODULE_CCORR1,
  72. DISP_MODULE_AAL0, DISP_MODULE_GAMMA0,
  73. DISP_MODULE_POSTMASK0, DISP_MODULE_DITHER0, DISP_MODULE_SPR0_VIRTUAL,
  74. DISP_MODULE_DSC_WRAP0_CORE0,
  75. DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  76. -1,
  77. };
  78. int module_list_scenario[DDP_SCENARIO_MAX][DDP_ENING_NUM] = {
  79. /* DDP_SCENARIO_PRIMARY_DISP */
  80. {
  81. DISP_MODULE_OVL0_2L,
  82. DISP_MODULE_OVL0, DISP_MODULE_RDMA0,
  83. DISP_MODULE_COLOR0,
  84. DISP_MODULE_CCORR0, DISP_MODULE_CCORR1,
  85. DISP_MODULE_AAL0, DISP_MODULE_GAMMA0,
  86. DISP_MODULE_POSTMASK0, DISP_MODULE_DITHER0,
  87. DISP_MODULE_SPR0_VIRTUAL,
  88. DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  89. -1,
  90. },
  91. /* DDP_SCENARIO_PRIMARY_BYPASS_PQ_DISP */
  92. {
  93. DISP_MODULE_OVL0_2L, DISP_MODULE_OVL0,
  94. DISP_MODULE_RDMA0,
  95. DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  96. -1,
  97. },
  98. /* DDP_SCENARIO_PRIMARY_RDMA0_COLOR0_DISP0 */
  99. {
  100. DISP_MODULE_RDMA0,
  101. DISP_MODULE_COLOR0,
  102. DISP_MODULE_CCORR0, DISP_MODULE_CCORR1,
  103. DISP_MODULE_AAL0, DISP_MODULE_GAMMA0,
  104. DISP_MODULE_POSTMASK0, DISP_MODULE_DITHER0,
  105. DISP_MODULE_SPR0_VIRTUAL,
  106. DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  107. -1,
  108. },
  109. /* DDP_SCENARIO_PRIMARY_RDMA0_DISP */
  110. {
  111. DISP_MODULE_RDMA0,
  112. DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  113. -1,
  114. },
  115. /* DDP_SCENARIO_PRIMARY_OVL_MEMOUT */
  116. {
  117. DISP_MODULE_OVL0_2L, DISP_MODULE_OVL0,
  118. DISP_MODULE_WDMA0,
  119. -1,
  120. },
  121. /* DDP_SCENARIO_PRIMARY0_OVL_PQ_MEMOUT */
  122. {
  123. DISP_MODULE_OVL0_2L, DISP_MODULE_OVL0,
  124. DISP_MODULE_RDMA0,
  125. DISP_MODULE_COLOR0,
  126. DISP_MODULE_CCORR0, DISP_MODULE_CCORR1,
  127. DISP_MODULE_AAL0, DISP_MODULE_GAMMA0,
  128. DISP_MODULE_POSTMASK0, DISP_MODULE_DITHER0,
  129. DISP_MODULE_WDMA0, -1,
  130. },
  131. /* DDP_SCENARIO_PRIMARY_ALL */
  132. {
  133. DISP_MODULE_OVL0_2L, DISP_MODULE_OVL0,
  134. DISP_MODULE_WDMA0,
  135. DISP_MODULE_RDMA0,
  136. DISP_MODULE_COLOR0,
  137. DISP_MODULE_CCORR0, DISP_MODULE_CCORR1,
  138. DISP_MODULE_AAL0, DISP_MODULE_GAMMA0,
  139. DISP_MODULE_POSTMASK0, DISP_MODULE_DITHER0,
  140. DISP_MODULE_SPR0_VIRTUAL,
  141. DISP_MODULE_PWM0, DISP_MODULE_DSI0,
  142. -1,
  143. },
  144. };
  145. /* 1st para is mout's input, 2nd para is mout's output */
  146. static mout_t mout_map[] = {
  147. /* DISP_TOVL0_OUT0_MOUT_EN*/
  148. {DISP_MODULE_OVL0_2L,
  149. {{DISP_MODULE_RDMA0, 1 << 0},
  150. {DISP_MODULE_RSZ0, 1 << 1},
  151. {DISP_MODULE_WDMA0, 1 << 2},
  152. {-1, 0} },
  153. 0, 0},
  154. /* DISP_TOVL0_OUT1_MOUT_EN */
  155. {DISP_MODULE_OVL0,
  156. {{DISP_MODULE_RDMA0, 1 << 0},
  157. {DISP_MODULE_RSZ0, 1 << 1},
  158. {DISP_MODULE_WDMA0, 1 << 2},
  159. {-1, 0} },
  160. 0, 0},
  161. /* DISP_RSZ0_MOUT_EN */
  162. {DISP_MODULE_RSZ0,
  163. {{DISP_MODULE_RDMA0, 1 << 0},
  164. {DISP_MODULE_WDMA0, 1 << 1},
  165. {-1, 0} },
  166. 0, 0},
  167. /* DISP_DITHER0_MOUT_EN */
  168. {DISP_MODULE_DITHER0,
  169. {{DISP_MODULE_SPR0_VIRTUAL, 1 << 0},
  170. {DISP_MODULE_CM0, 1 << 1},
  171. {DISP_MODULE_WDMA0, 1 << 2},
  172. {-1, 0} },
  173. 0, 0},
  174. /* DISP_SPR0_MOUT_EN */
  175. {DISP_MODULE_SPR0_VIRTUAL,
  176. {{DISP_MODULE_DSI0, 1 << 0},
  177. {DISP_MODULE_WDMA0, 1 << 1},
  178. {DISP_MODULE_DSC_WRAP0_CORE0, 1 << 2},
  179. {-1, 0} },
  180. 0, 0},
  181. };
  182. static sel_t sel_out_map[] = {
  183. /* DISP_RDMA0_RSZ0_SOUT_SEL */
  184. {DISP_MODULE_RDMA0, {DISP_MODULE_DSI0,
  185. DISP_MODULE_COLOR0, -1}, 0, 0},
  186. };
  187. /* 1st para is sout's output, 2nd para is sout's input */
  188. static sel_t sel_in_map[] = {
  189. /* DISP_RSZ0_SEL_IN */
  190. {DISP_MODULE_RSZ0, {DISP_MODULE_OVL0_2L,
  191. DISP_MODULE_OVL0, -1}, 0, 0},
  192. /* DISP_RDMA0_SEL_IN */
  193. {DISP_MODULE_RDMA0, {DISP_MODULE_OVL0,
  194. DISP_MODULE_RSZ0,
  195. DISP_MODULE_OVL0_2L, -1}, 0, 0},
  196. /* DISP_BYPASS_SPR0_SEL_IN */
  197. {DISP_MODULE_SPR0_VIRTUAL, {DISP_MODULE_DITHER0,
  198. DISP_MODULE_SPR0, -1}, 0, 0},
  199. /* DSI0_SEL_IN */
  200. {DISP_MODULE_DSI0, {DISP_MODULE_RDMA0,
  201. DISP_MODULE_SPR0_VIRTUAL,
  202. DISP_MODULE_DSC_WRAP0_CORE0, -1}, 0, 0},
  203. /* DISP_WDMA0_SEL_IN */
  204. {DISP_MODULE_WDMA0, {DISP_MODULE_SPR0_VIRTUAL,
  205. DISP_MODULE_RSZ0, DISP_MODULE_OVL0_2L, DISP_MODULE_OVL0,
  206. DISP_MODULE_DITHER0, -1}, 0, 0},
  207. };
  208. int ddp_path_init(void)
  209. {
  210. int i;
  211. mout_map[0].reg =
  212. (unsigned long *)DISP_TOVL0_OUT0_MOUT_EN;
  213. mout_map[1].reg =
  214. (unsigned long *)DISP_TOVL0_OUT1_MOUT_EN;
  215. mout_map[2].reg =
  216. (unsigned long *)DISP_RSZ0_MOUT_EN;
  217. mout_map[3].reg =
  218. (unsigned long *)DISP_DITHER0_MOUT_EN;
  219. mout_map[4].reg =
  220. (unsigned long *)DISP_SPR0_MOUT_EN;
  221. sel_out_map[0].reg = (unsigned long *)
  222. DISP_RDMA0_RSZ0_SOUT_SEL;
  223. /* sel_in */
  224. sel_in_map[0].reg =
  225. (unsigned long *)DISP_RSZ0_SEL_IN;
  226. sel_in_map[1].reg =
  227. (unsigned long *)DISP_RDMA0_SEL_IN;
  228. sel_in_map[2].reg =
  229. (unsigned long *)DISP_BYPASS_SPR0_SEL_IN;
  230. sel_in_map[3].reg =
  231. (unsigned long *)DSI0_SEL_IN;
  232. sel_in_map[4].reg =
  233. (unsigned long *)DISP_WDMA0_SEL_IN;
  234. for (i = 0; i < 5; i++) {
  235. DISP_REG_SET_FIELD(NULL, REG_FLD_MMU_EN,
  236. DISP_REG_SMI_LARB0_NON_SEC_CON + i * 4, 0x0);
  237. DISP_REG_SET_FIELD(NULL, REG_FLD_MMU_EN,
  238. DISP_REG_SMI_LARB1_NON_SEC_CON + i * 4, 0x0);
  239. }
  240. return 0;
  241. }
  242. static module_map_t module_mutex_map[DISP_MODULE_NUM] = {
  243. {DISP_MODULE_CONFIG, -1, 0},
  244. {DISP_MODULE_MUTEX, -1, 0},
  245. {DISP_MODULE_SMI_COMMON, -1, 0},
  246. {DISP_MODULE_SMI_LARB0, -1, 0},
  247. {DISP_MODULE_SMI_LARB1, -1, 0},
  248. {DISP_MODULE_OVL0, 0, 0},
  249. {DISP_MODULE_OVL0_2L, 1, 0},
  250. {DISP_MODULE_RDMA0, 2, 0},
  251. {DISP_MODULE_RSZ0, 3, 0},
  252. {DISP_MODULE_COLOR0, 4, 0},
  253. {DISP_MODULE_CCORR0, 5, 0},
  254. {DISP_MODULE_CCORR1, 6, 0},
  255. {DISP_MODULE_AAL0, 7, 0},
  256. {DISP_MODULE_GAMMA0, 8, 0},
  257. {DISP_MODULE_POSTMASK0, 9, 0},
  258. {DISP_MODULE_DITHER0, 10, 0},
  259. {DISP_MODULE_CM0, 11, 0},
  260. {DISP_MODULE_SPR0, 12, 0},
  261. {DISP_MODULE_SPR0_VIRTUAL, -1, 0},
  262. {DISP_MODULE_DSC_WRAP0_CORE0, 13, 0},
  263. {DISP_MODULE_DSI0, 14, 0},
  264. {DISP_MODULE_WDMA0, 15, 0},
  265. {DISP_MODULE_PWM0, 16, 0},
  266. {DISP_MODULE_DSIDUAL, -1, 0},
  267. {DISP_MODULE_DSI1, -1, 0},
  268. {DISP_MODULE_MIPI0, -1, 0},
  269. {DISP_MODULE_SPLIT0, -1, 0},
  270. {DISP_MODULE_UNKNOWN, -1, 0},
  271. };
  272. char *ddp_get_scenario_name(DDP_SCENARIO_ENUM scenario)
  273. {
  274. switch (scenario) {
  275. /* primary display */
  276. case DDP_SCENARIO_PRIMARY_DISP:
  277. return "primary_disp";
  278. case DDP_SCENARIO_PRIMARY_BYPASS_PQ_DISP:
  279. return "primary_bypass_pq";
  280. case DDP_SCENARIO_PRIMARY_RDMA0_COLOR0_DISP0:
  281. return "primary_rdma0_color0_disp0";
  282. case DDP_SCENARIO_PRIMARY_RDMA0_DISP:
  283. return "primary_rdma0_disp";
  284. case DDP_SCENARIO_PRIMARY_OVL_MEMOUT:
  285. return "primary_ovl_memout";
  286. case DDP_SCENARIO_PRIMARY_ALL:
  287. return "primary_all";
  288. /* sub display */
  289. case DDP_SCENARIO_SUB_DISP:
  290. return "sub_disp";
  291. case DDP_SCENARIO_SUB_ALL:
  292. return "sub_all";
  293. /* others */
  294. default:
  295. DDPMSG("invalid scenario id=%d\n", scenario);
  296. return "unknown";
  297. }
  298. }
  299. int ddp_is_scenario_on_primary(DDP_SCENARIO_ENUM scenario)
  300. {
  301. int on_primary = 0;
  302. switch (scenario) {
  303. case DDP_SCENARIO_PRIMARY_DISP:
  304. case DDP_SCENARIO_PRIMARY_RDMA0_DISP:
  305. case DDP_SCENARIO_PRIMARY_OVL_MEMOUT:
  306. case DDP_SCENARIO_PRIMARY_ALL:
  307. on_primary = 1;
  308. break;
  309. default:
  310. DDPMSG("invalid scenario id=%d\n", scenario);
  311. }
  312. return on_primary;
  313. }
  314. char *ddp_get_mutex_sof_name(unsigned int regval)
  315. {
  316. if (regval == SOF_VAL_MUTEX0_SOF_SINGLE_MODE)
  317. return "single";
  318. else if (regval == SOF_VAL_MUTEX0_SOF_FROM_DSI0)
  319. return "dsi0";
  320. else if (regval == SOF_VAL_MUTEX0_SOF_FROM_DPI)
  321. return "dpi";
  322. DDPDUMP("%s, unknown reg=%d\n", __func__, regval);
  323. return "unknown";
  324. }
  325. char *ddp_get_mode_name(DDP_MODE ddp_mode)
  326. {
  327. switch (ddp_mode) {
  328. case DDP_VIDEO_MODE:
  329. return "vido_mode";
  330. case DDP_CMD_MODE:
  331. return "cmd_mode";
  332. default:
  333. DDPMSG("invalid ddp mode =%d\n", ddp_mode);
  334. return "unknown";
  335. }
  336. }
  337. static int ddp_get_module_num_l(int *module_list)
  338. {
  339. unsigned int num = 0;
  340. while (*(module_list + num) != -1) {
  341. num++;
  342. if (num == DDP_ENING_NUM)
  343. break;
  344. }
  345. return num;
  346. }
  347. /* config mout/msel to creat a compelte path */
  348. static void ddp_connect_path_l(int *module_list, void *handle)
  349. {
  350. unsigned int j, k;
  351. int step = 0;
  352. unsigned int mout = 0;
  353. unsigned int reg_mout = 0;
  354. unsigned int mout_idx = 0;
  355. int module_num = ddp_get_module_num_l(module_list);
  356. DDPDBG("connect_path: %s to %s\n", ddp_get_module_name(module_list[0]),
  357. ddp_get_module_name(module_list[module_num - 1]));
  358. /* connect mout */
  359. for (int i = 0; i < module_num - 1; i++) {
  360. for (j = 0; j < sizeof(mout_map)/sizeof(mout_map[0]); j++) {
  361. if (module_list[i] == mout_map[j].id) {
  362. /* find next module which can be connected */
  363. step = i + 1;
  364. while (ddp_modules[module_list[step]].can_connect== 0
  365. && step < module_num) {
  366. step++;
  367. }
  368. ASSERT(step < module_num);
  369. mout = mout_map[j].reg_val;
  370. for (k = 0; k < DDP_MOUT_MAX; k++) {
  371. if (mout_map[j].out_id_bit_map[k].m == -1)
  372. break;
  373. if (mout_map[j].out_id_bit_map[k].m == module_list[step]) {
  374. mout |= mout_map[j].out_id_bit_map[k].v;
  375. reg_mout |= mout;
  376. mout_idx = j;
  377. DDPDBG("connect mout %s to %s bits 0x%x\n",
  378. ddp_get_module_name(module_list[i]),
  379. ddp_get_module_name(module_list[step]),
  380. reg_mout);
  381. break;
  382. }
  383. }
  384. mout_map[j].reg_val = mout;
  385. mout = 0;
  386. }
  387. }
  388. if (reg_mout) {
  389. DISP_REG_SET(handle, mout_map[mout_idx].reg, reg_mout);
  390. reg_mout = 0;
  391. mout_idx = 0;
  392. }
  393. }
  394. /* connect out select */
  395. for (int i = 0; i < module_num - 1; i++) {
  396. for (j = 0; j < sizeof(sel_out_map)/sizeof(sel_out_map[0]); j++) {
  397. if (module_list[i] == sel_out_map[j].id) {
  398. step = i + 1;
  399. /* find next module which can be connected */
  400. while (ddp_modules[module_list[step]].can_connect== 0
  401. && step < module_num) {
  402. step++;
  403. }
  404. ASSERT(step < module_num);
  405. for (k = 0; k < DDP_SOUT_MAX; k++) {
  406. if (sel_out_map[j].id_bit_map[k] == -1)
  407. break;
  408. if (sel_out_map[j].id_bit_map[k] == module_list[step]) {
  409. DDPDBG("connect out_s %s to %s, value=%d\n",
  410. ddp_get_module_name(module_list[i]),
  411. ddp_get_module_name(module_list[step]), k);
  412. DISP_REG_SET(handle, sel_out_map[j].reg,
  413. (uint16_t) k);
  414. break;
  415. }
  416. }
  417. }
  418. }
  419. }
  420. /* connect input select */
  421. for (int i = 1; i < module_num; i++) {
  422. for (j = 0; j < sizeof(sel_in_map)/sizeof(sel_in_map[0]); j++) {
  423. if (module_list[i] == sel_in_map[j].id) {
  424. int found = 0;
  425. step = i - 1;
  426. /* find next module which can be connected */
  427. while (ddp_modules[module_list[step]].can_connect == 0 && step > 0)
  428. step--;
  429. ASSERT(step >= 0);
  430. for (k = 0; k < DDP_SOUT_MAX; k++) {
  431. if (sel_in_map[j].id_bit_map[k] == -1)
  432. break;
  433. if (sel_in_map[j].id_bit_map[k] == module_list[step]) {
  434. DDPDBG("connect in_s %s to %s, value=%d\n",
  435. ddp_get_module_name(module_list[step]),
  436. ddp_get_module_name(module_list[i]), k);
  437. DISP_REG_SET(handle, sel_in_map[j].reg,
  438. (uint16_t) k);
  439. found = 1;
  440. break;
  441. }
  442. }
  443. if (!found)
  444. DDPERR("%s error: %s sel_in not set\n", __func__,
  445. ddp_get_module_name(module_list[i]));
  446. }
  447. }
  448. }
  449. }
  450. static void ddp_check_path_l(int *module_list)
  451. {
  452. unsigned int j, k;
  453. int step = 0;
  454. int valid = 0;
  455. unsigned int mout;
  456. unsigned int path_error = 0;
  457. int module_num = ddp_get_module_num_l(module_list);
  458. DDPDUMP("check_path: %s to %s\n", ddp_get_module_name(module_list[0])
  459. , ddp_get_module_name(module_list[module_num - 1]));
  460. /* check mout */
  461. for (int i = 0; i < module_num - 1; i++) {
  462. for (j = 0; j < sizeof(mout_map)/sizeof(mout_map[0]); j++) {
  463. if (module_list[i] == mout_map[j].id) {
  464. mout = 0;
  465. /* find next module which can be connected */
  466. step = i + 1;
  467. while (ddp_modules[module_list[step]].can_connect== 0
  468. && step < module_num) {
  469. step++;
  470. }
  471. ASSERT(step < module_num);
  472. for (k = 0; k < DDP_MOUT_MAX; k++) {
  473. if (mout_map[j].out_id_bit_map[k].m == -1)
  474. break;
  475. if (mout_map[j].out_id_bit_map[k].m == module_list[step]) {
  476. mout |= mout_map[j].out_id_bit_map[k].v;
  477. valid = 1;
  478. break;
  479. }
  480. }
  481. if (valid == 0) {
  482. DDPDUMP("err: %s mout, connect next module %s failed\n",
  483. ddp_get_module_name(module_list[i]),
  484. ddp_get_module_name(module_list[i+1]));
  485. path_error +=1;
  486. }else if (valid == 1) {
  487. valid = 0;
  488. if ((DISP_REG_GET(mout_map[j].reg) & mout) == 0) {
  489. path_error += 1;
  490. DDPDUMP("error:%s mout, expect=0x%x, real=0x%x\n",
  491. ddp_get_module_name(module_list[i]),
  492. mout, DISP_REG_GET(mout_map[j].reg));
  493. } else if (DISP_REG_GET(mout_map[j].reg) != mout) {
  494. DDPDUMP
  495. ("warning: %s mout expect=0x%x, real=0x%x\n",
  496. ddp_get_module_name(module_list[i]), mout,
  497. DISP_REG_GET(mout_map[j].reg));
  498. }
  499. }
  500. break;
  501. }
  502. }
  503. }
  504. /* check out select */
  505. for (int i = 0; i < module_num - 1; i++) {
  506. for (j = 0; j < sizeof(sel_out_map)/sizeof(sel_out_map[0]); j++) {
  507. if (module_list[i] != sel_out_map[j].id)
  508. continue;
  509. /* find next module which can be connected */
  510. step = i + 1;
  511. while (ddp_modules[module_list[step]].can_connect== 0
  512. && step < module_num) {
  513. step++;
  514. }
  515. ASSERT(step < module_num);
  516. for (k = 0; k < DDP_SOUT_MAX; k++) {
  517. if (sel_out_map[j].id_bit_map[k] == -1) {
  518. path_error += 1;
  519. DDPDUMP
  520. ("error:out_s %s not connect to %s\n",
  521. ddp_get_module_name(module_list[i]),
  522. ddp_get_module_name(module_list[step]));
  523. break;
  524. }
  525. if (sel_out_map[j].id_bit_map[k] == module_list[step]) {
  526. if (DISP_REG_GET(sel_out_map[j].reg) != k) {
  527. path_error += 1;
  528. DDPDUMP
  529. ("error:out_s %s not connect to %s, expect=0x%x, real=0x%x\n",
  530. ddp_get_module_name(module_list[i]),
  531. ddp_get_module_name(module_list[step]),
  532. k, DISP_REG_GET(sel_out_map[j].reg));
  533. }
  534. break;
  535. }
  536. }
  537. }
  538. }
  539. /* check input select */
  540. for (int i = 1; i < module_num; i++) {
  541. for (j = 0; j < sizeof(sel_in_map)/sizeof(sel_in_map[0]); j++) {
  542. if (module_list[i] != sel_in_map[j].id)
  543. continue;
  544. /* find next module which can be connected */
  545. step = i - 1;
  546. while (ddp_modules[module_list[step]].can_connect == 0 && step > 0)
  547. step--;
  548. ASSERT(step >= 0);
  549. for (k = 0; k < DDP_SOUT_MAX; k++) {
  550. if (sel_in_map[j].id_bit_map[k] == -1) {
  551. path_error += 1;
  552. DDPDUMP
  553. ("error:in_s %s not connect to %s\n",
  554. ddp_get_module_name(module_list[i]),
  555. ddp_get_module_name(module_list[step]));
  556. break;
  557. }
  558. if (sel_in_map[j].id_bit_map[k] == module_list[step]) {
  559. if (DISP_REG_GET(sel_in_map[j].reg) != k) {
  560. path_error += 1;
  561. DDPDUMP("error:in_s %s not conn to %s,expect0x%x,real0x%x\n",
  562. ddp_get_module_name(module_list[step]),
  563. ddp_get_module_name(module_list[i]), k,
  564. DISP_REG_GET(sel_in_map[j].reg));
  565. }
  566. break;
  567. }
  568. }
  569. }
  570. }
  571. if (path_error == 0) {
  572. DDPDUMP("path: %s to %s is connected\n", ddp_get_module_name(module_list[0]),
  573. ddp_get_module_name(module_list[module_num - 1]));
  574. } else {
  575. DDPDUMP("path: %s to %s not connected!!!\n", ddp_get_module_name(module_list[0]),
  576. ddp_get_module_name(module_list[module_num - 1]));
  577. }
  578. }
  579. static void ddp_disconnect_path_l(int *module_list, void *handle)
  580. {
  581. unsigned int j, k;
  582. int step = 0;
  583. unsigned int mout = 0;
  584. unsigned int reg_mout = 0;
  585. unsigned int mout_idx = 0;
  586. int module_num = ddp_get_module_num_l(module_list);
  587. DDPDBG("disconnect_path: %s to %s\n", ddp_get_module_name(module_list[0]),
  588. ddp_get_module_name(module_list[module_num - 1]));
  589. for (int i = 0; i < module_num - 1; i++) {
  590. for (j = 0; j < sizeof(mout_map)/sizeof(mout_map[0]); j++) {
  591. if (module_list[i] == mout_map[j].id) {
  592. /* find next module which can be connected */
  593. step = i + 1;
  594. while (ddp_modules[module_list[step]].can_connect== 0
  595. && step < module_num) {
  596. step++;
  597. }
  598. ASSERT(step < module_num);
  599. for (k = 0; k < DDP_MOUT_MAX; k++) {
  600. if (mout_map[j].out_id_bit_map[k].m == -1)
  601. break;
  602. if (mout_map[j].out_id_bit_map[k].m == module_list[step]) {
  603. mout |= mout_map[j].out_id_bit_map[k].v;
  604. reg_mout |= mout;
  605. mout_idx = j;
  606. DDPDBG("disconnect mout %s to %s\n",
  607. ddp_get_module_name(module_list[i]),
  608. ddp_get_module_name(module_list[step]));
  609. break;
  610. }
  611. }
  612. /* update mout_value */
  613. mout_map[j].reg_val &= ~mout;
  614. mout = 0;
  615. }
  616. }
  617. if (reg_mout) {
  618. DISP_REG_SET(handle, mout_map[mout_idx].reg, mout_map[mout_idx].reg_val);
  619. reg_mout = 0;
  620. mout_idx = 0;
  621. }
  622. }
  623. }
  624. static int ddp_get_mutex_src(DISP_MODULE_ENUM dest_module, DDP_MODE ddp_mode,
  625. unsigned int *SOF_src, unsigned int *EOF_src)
  626. {
  627. unsigned int src_from_dst_module = 0;
  628. if (dest_module == DISP_MODULE_WDMA0) {
  629. if (ddp_mode == DDP_VIDEO_MODE)
  630. DISP_LOG_W("%s: dst_mode=%s, but is video mode !!\n", __func__,
  631. ddp_get_module_name(dest_module));
  632. *SOF_src = *EOF_src = SOF_VAL_MUTEX0_SOF_SINGLE_MODE;
  633. return 0;
  634. }
  635. if (dest_module == DISP_MODULE_DSI0 || dest_module == DISP_MODULE_DSIDUAL) {
  636. src_from_dst_module = SOF_VAL_MUTEX0_SOF_FROM_DSI0;
  637. } else {
  638. DDPERR("get mutex sof, invalid param dst module = %s(%d), dis mode %s\n",
  639. ddp_get_module_name(dest_module), dest_module, ddp_get_mode_name(ddp_mode));
  640. ASSERT(0);
  641. }
  642. if (ddp_mode == DDP_CMD_MODE) {
  643. *SOF_src = SOF_VAL_MUTEX0_SOF_SINGLE_MODE;
  644. if (0/*disp_helper_get_option(DISP_OPT_MUTEX_EOF_EN_FOR_CMD_MODE)*/)
  645. *EOF_src = src_from_dst_module;
  646. else
  647. *EOF_src = SOF_VAL_MUTEX0_EOF_SINGLE_MODE;
  648. } else {
  649. *SOF_src = *EOF_src = src_from_dst_module;
  650. }
  651. return 0;
  652. }
  653. /* id: mutex ID, 0~5 */
  654. static int ddp_mutex_set_l(int mutex_id, int *module_list, DDP_MODE ddp_mode, void *handle)
  655. {
  656. int i = 0;
  657. unsigned int value0 = 0;
  658. unsigned int value1 = 0;
  659. unsigned int sof_val;
  660. unsigned int sof_src, eof_src;
  661. int module_num = ddp_get_module_num_l(module_list);
  662. ddp_get_mutex_src(module_list[module_num - 1], ddp_mode, &sof_src, &eof_src);
  663. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  664. DDPERR("exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  665. return -1;
  666. }
  667. for (i = 0; i < module_num; i++) {
  668. if (module_mutex_map[module_list[i]].bit != -1) {
  669. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module_list[i]),
  670. mutex_id);
  671. if (module_mutex_map[module_list[i]].mod_num == 0) {
  672. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  673. value0 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  674. value0 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  675. } else {
  676. value0 |= (1 << module_mutex_map[module_list[i]].bit);
  677. }
  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, 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. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  719. expect_value0 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  720. expect_value0 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  721. } else {
  722. expect_value0 |= (1 << module_mutex_map[module_list[i]].bit);
  723. }
  724. }else if (module_mutex_map[module_list[i]].mod_num == 1) {
  725. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  726. expect_value1 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  727. expect_value1 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  728. } else {
  729. expect_value1 |= (1 << module_mutex_map[module_list[i]].bit);
  730. }
  731. }
  732. }
  733. }
  734. if (expect_value0 != real_value0)
  735. DDPDUMP("error:mutex %d error: expect0 0x%x, real0 0x%x\n", mutex_id, expect_value0,
  736. real_value0);
  737. if (expect_value1 != real_value1)
  738. DDPDUMP("error:mutex %d error: expect1 0x%x, real1 0x%x\n", mutex_id, expect_value1,
  739. real_value1);
  740. val = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_SOF(mutex_id));
  741. real_sof = REG_FLD_VAL_GET(SOF_FLD_MUTEX0_SOF, val);
  742. real_eof = REG_FLD_VAL_GET(SOF_FLD_MUTEX0_EOF, val);
  743. ddp_get_mutex_src(module_list[module_num - 1], ddp_mode, &expect_sof, &expect_eof);
  744. if (expect_sof != real_sof)
  745. DDPDUMP("error:mutex %d sof error: expect %s, real %s\n", mutex_id,
  746. ddp_get_mutex_sof_name(expect_sof), ddp_get_mutex_sof_name(real_sof));
  747. if (expect_eof != real_eof)
  748. DDPDUMP("error:mutex %d eof error: expect %s, real %s\n", mutex_id,
  749. ddp_get_mutex_sof_name(expect_eof), ddp_get_mutex_sof_name(real_eof));
  750. }
  751. static int ddp_mutex_enable_l(int mutex_idx, void *handle)
  752. {
  753. DDPDBG("mutex %d enable\n", mutex_idx);
  754. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_CFG, 0);
  755. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_EN(mutex_idx), 1);
  756. return 0;
  757. }
  758. int ddp_get_module_num(DDP_SCENARIO_ENUM scenario)
  759. {
  760. return ddp_get_module_num_l(module_list_scenario[scenario]);
  761. }
  762. static void ddp_print_scenario(DDP_SCENARIO_ENUM scenario)
  763. {
  764. int i =0;
  765. char path[512]= {'\0'};
  766. int num = ddp_get_module_num(scenario);
  767. for (i = 0; i < num; i++)
  768. strncat(path, ddp_get_module_name(
  769. module_list_scenario[scenario][i]),
  770. (sizeof(path) - strlen(path) - 1));
  771. DDPMSG("scenario %s have modules: %s\n",ddp_get_scenario_name(scenario),path);
  772. }
  773. static int ddp_find_module_index(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  774. {
  775. int i = 0;
  776. for (i = 0; i < DDP_ENING_NUM; i++) {
  777. if (module_list_scenario[ddp_scenario][i] == (int)module)
  778. return i;
  779. }
  780. DDPDBG("find module: can not find module %s on scenario %s\n", ddp_get_module_name(module),
  781. ddp_get_scenario_name(ddp_scenario));
  782. return -1;
  783. }
  784. /* set display interface when kernel init */
  785. int ddp_set_dst_module(DDP_SCENARIO_ENUM scenario, DISP_MODULE_ENUM dst_module)
  786. {
  787. int i = 0;
  788. DDPMSG("ddp_set_dst_module, scenario=%s, dst_module=%s\n",
  789. ddp_get_scenario_name(scenario), ddp_get_module_name(dst_module));
  790. if (ddp_find_module_index(scenario, dst_module) > 0) {
  791. DDPDBG("%s is already on path\n", ddp_get_module_name(dst_module));
  792. return 0;
  793. }
  794. i = ddp_get_module_num_l(module_list_scenario[scenario]) - 1;
  795. ASSERT(i >= 0);
  796. if (dst_module == DISP_MODULE_DSIDUAL) {
  797. if (i < (DDP_ENING_NUM - 1)) {
  798. module_list_scenario[scenario][i++] = DISP_MODULE_SPLIT0;
  799. } else {
  800. DDPERR("set dst module over up bound\n");
  801. return -1;
  802. }
  803. } else {
  804. if (ddp_get_dst_module(scenario) == DISP_MODULE_DSIDUAL) {
  805. if (i >= 1) {
  806. module_list_scenario[scenario][i--] = -1;
  807. } else {
  808. DDPERR("set dst module over low bound\n");
  809. return -1;
  810. }
  811. }
  812. }
  813. module_list_scenario[scenario][i] = dst_module;
  814. if (scenario == DDP_SCENARIO_PRIMARY_ALL)
  815. ddp_set_dst_module(DDP_SCENARIO_PRIMARY_DISP, dst_module);
  816. ddp_print_scenario(scenario);
  817. return 0;
  818. }
  819. DISP_MODULE_ENUM ddp_get_dst_module(DDP_SCENARIO_ENUM ddp_scenario)
  820. {
  821. DISP_MODULE_ENUM module_name = DISP_MODULE_UNKNOWN;
  822. int module_num = ddp_get_module_num_l(module_list_scenario[ddp_scenario]) - 1;
  823. if (module_num >= 0)
  824. module_name = module_list_scenario[ddp_scenario][module_num];
  825. return module_name;
  826. }
  827. int *ddp_get_scenario_list(DDP_SCENARIO_ENUM ddp_scenario)
  828. {
  829. return module_list_scenario[ddp_scenario];
  830. }
  831. int ddp_is_module_in_scenario(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  832. {
  833. int i = 0;
  834. for (i = 0; i < DDP_ENING_NUM; i++) {
  835. if (module_list_scenario[ddp_scenario][i] == (int)module)
  836. return 1;
  837. }
  838. return 0;
  839. }
  840. int ddp_insert_module(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM place,
  841. DISP_MODULE_ENUM module)
  842. {
  843. int i = DDP_ENING_NUM - 1;
  844. int idx = ddp_find_module_index(ddp_scenario, place);
  845. if (idx < 0) {
  846. DDPERR("error: ddp_insert_module , place=%s is not in scenario %s!\n",
  847. ddp_get_module_name(place), ddp_get_scenario_name(ddp_scenario));
  848. return -1;
  849. }
  850. for (i = 0; i < DDP_ENING_NUM; i++) {
  851. if (module_list_scenario[ddp_scenario][i] == (int)module) {
  852. DDPERR("error: ddp_insert_module , module=%s is already in scenario %s!\n",
  853. ddp_get_module_name(module), ddp_get_scenario_name(ddp_scenario));
  854. return -1;
  855. }
  856. }
  857. /* should have empty room for insert */
  858. ASSERT(module_list_scenario[ddp_scenario][DDP_ENING_NUM - 1] == -1);
  859. for (i = DDP_ENING_NUM - 2; i >= idx; i--)
  860. module_list_scenario[ddp_scenario][i + 1] = module_list_scenario[ddp_scenario][i];
  861. module_list_scenario[ddp_scenario][idx] = module;
  862. {
  863. int *modules = ddp_get_scenario_list(ddp_scenario);
  864. int module_num = ddp_get_module_num(ddp_scenario);
  865. DDPMSG("after insert module, module list is:\n");
  866. for (i = 0; i < module_num; i++)
  867. DDPMSG("%s-", ddp_get_module_name(modules[i]));
  868. }
  869. return 0;
  870. }
  871. int ddp_remove_module(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  872. {
  873. int i = 0;
  874. int idx = ddp_find_module_index(ddp_scenario, module);
  875. if (idx < 0) {
  876. DDPERR("ddp_remove_module, can not find module %s in scenario %s\n",
  877. ddp_get_module_name(module), ddp_get_scenario_name(ddp_scenario));
  878. return -1;
  879. }
  880. for (i = idx; i < DDP_ENING_NUM - 1; i++)
  881. module_list_scenario[ddp_scenario][i] = module_list_scenario[ddp_scenario][i + 1];
  882. module_list_scenario[ddp_scenario][DDP_ENING_NUM - 1] = -1;
  883. {
  884. int *modules = ddp_get_scenario_list(ddp_scenario);
  885. int module_num = ddp_get_module_num(ddp_scenario);
  886. DDPMSG("after remove module, module list is:\n");
  887. for (i = 0; i < module_num; i++)
  888. DDPMSG("%s-", ddp_get_module_name(modules[i]));
  889. }
  890. return 0;
  891. }
  892. void ddp_connect_path(DDP_SCENARIO_ENUM scenario, void *handle)
  893. {
  894. DDPDBG("path connect on scenario %s\n", ddp_get_scenario_name(scenario));
  895. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  896. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP], handle);
  897. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT], handle);
  898. } else if (scenario == DDP_SCENARIO_SUB_ALL) {
  899. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_SUB_DISP], handle);
  900. } else {
  901. ddp_connect_path_l(module_list_scenario[scenario], handle);
  902. }
  903. return;
  904. }
  905. void ddp_disconnect_path(DDP_SCENARIO_ENUM scenario, void *handle)
  906. {
  907. DDPDBG("path disconnect on scenario %s\n", ddp_get_scenario_name(scenario));
  908. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  909. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP], handle);
  910. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT],
  911. handle);
  912. } else if (scenario == DDP_SCENARIO_SUB_ALL) {
  913. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_SUB_DISP], handle);
  914. } else {
  915. ddp_disconnect_path_l(module_list_scenario[scenario], handle);
  916. }
  917. return;
  918. }
  919. void ddp_check_path(DDP_SCENARIO_ENUM scenario)
  920. {
  921. DDPDBG("path check path on scenario %s\n", ddp_get_scenario_name(scenario));
  922. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  923. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP]);
  924. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_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. return;
  935. }
  936. int ddp_mutex_set(int mutex_id, DDP_SCENARIO_ENUM scenario, DDP_MODE mode, void *handle)
  937. {
  938. if (scenario < DDP_SCENARIO_MAX) {
  939. return ddp_mutex_set_l(mutex_id, module_list_scenario[scenario], mode, handle);
  940. } else {
  941. DDPERR("Invalid scenario %d when setting mutex\n", scenario);
  942. return -1;
  943. }
  944. return 0;
  945. }
  946. int ddp_mutex_Interrupt_enable(int mutex_id, void *handle)
  947. {
  948. DDPDBG("mutex %d interrupt enable\n", mutex_id);
  949. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0x1 << mutex_id, 0x1 << mutex_id);
  950. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 1 << (mutex_id + DISP_MUTEX_TOTAL),
  951. 0x1 << (mutex_id + DISP_MUTEX_TOTAL));
  952. return 0;
  953. }
  954. int ddp_mutex_Interrupt_disable(int mutex_id, void *handle)
  955. {
  956. DDPDBG("mutex %d interrupt disenable\n", mutex_id);
  957. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0, 0x1 << mutex_id);
  958. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0, 0x1 << (mutex_id + DISP_MUTEX_TOTAL));
  959. return 0;
  960. }
  961. int ddp_mutex_reset(int mutex_id, void *handle)
  962. {
  963. DDPDBG("mutex %d reset\n", mutex_id);
  964. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_RST(mutex_id), 1);
  965. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_RST(mutex_id), 0);
  966. return 0;
  967. }
  968. int ddp_is_moudule_in_mutex(int mutex_id, DISP_MODULE_ENUM module)
  969. {
  970. int ret = 0;
  971. uint32_t real_value = 0;
  972. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  973. DDPDUMP("error:check_moudule_in_mute fail:exceed mutex max (0 ~ %d)\n",
  974. DISP_MUTEX_DDP_LAST);
  975. return ret;
  976. }
  977. if (module_mutex_map[module].mod_num == 0) {
  978. real_value = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_MOD0(mutex_id));
  979. }
  980. if (1 == ((real_value >> module_mutex_map[module].bit) & 0x01))
  981. ret = 1;
  982. return ret;
  983. }
  984. int ddp_mutex_add_module(int mutex_id, DISP_MODULE_ENUM module, void *handle)
  985. {
  986. int value = 0;
  987. if (module < DISP_MODULE_UNKNOWN) {
  988. if (module_mutex_map[module].bit != -1) {
  989. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module),
  990. mutex_id);
  991. value |= (1 << module_mutex_map[module].bit);
  992. if (module_mutex_map[module].mod_num == 0) {
  993. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), value, value);
  994. }
  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. }
  1013. else if (module_mutex_map[module].mod_num == 1) {
  1014. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD1(mutex_id), 0, value);
  1015. }
  1016. }
  1017. }
  1018. return 0;
  1019. }
  1020. int ddp_mutex_clear(int mutex_id, void *handle)
  1021. {
  1022. DDPDBG("mutex %d clear\n", mutex_id);
  1023. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_MOD0(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_set_sof_wait(int mutex_id, cmdqRecHandle handle, int wait)
  1041. {
  1042. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  1043. DDPERR("exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  1044. return -1;
  1045. }
  1046. DISP_REG_SET_FIELD(handle, SOF_FLD_MUTEX0_SOF_WAIT, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), wait);
  1047. return 0;
  1048. }
  1049. int ddp_check_engine_status(int mutexID)
  1050. {
  1051. /* check engines' clock bit & enable bit & status bit before unlock mutex */
  1052. /* should not needed, in comdq do? */
  1053. int result = 0;
  1054. return result;
  1055. }
  1056. int ddp_path_top_clock_on(void)
  1057. {
  1058. DDPMSG("ddp path top clock on\n");
  1059. spm_mtcmos_ctrl_dis(1);
  1060. ddp_enable_module_clock(DISP_MODULE_SMI_COMMON);
  1061. ddp_enable_module_clock(DISP_MODULE_SMI_LARB0);
  1062. DDPMSG("ddp CG0:%x CG1:%x\n", DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  1063. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1));
  1064. #if 1 /* Force CG always on */
  1065. DDPMSG("[FPGA Only] before power on MMSYS:0x%x,0x%x,0x%x\n",
  1066. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  1067. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1),
  1068. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON2));
  1069. DISP_REG_SET(NULL, DISP_REG_CONFIG_MMSYS_CG_CLR0, 0xFFFFFFFF);
  1070. DISP_REG_SET(NULL, DISP_REG_CONFIG_MMSYS_CG_CLR1, 0xFFFFFFFF);
  1071. DISP_REG_SET(NULL, DISP_REG_CONFIG_MMSYS_CG_CLR2, 0xFFFFFFFF);
  1072. /*DISP_REG_SET(NULL, DISP_REG_CONFIG_MMSYS_CG_CLR2, 0xFFFFFFFF);*/
  1073. DDPMSG("[FPGA Only] before power on MMSYS:0x%x,0x%x,0x%x\n",
  1074. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  1075. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1),
  1076. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON2));
  1077. #endif
  1078. DDPMSG("SMI subcom before config:(0x%x,0x%x)\n",
  1079. DISP_REG_GET(DISP_REG_SMI_SUBCOM0_L1LEN),
  1080. DISP_REG_GET(DISP_REG_SMI_SUBCOM1_L1LEN));
  1081. DISP_REG_SET(NULL, DISP_REG_SMI_SUBCOM0_L1LEN, 0XA);
  1082. DISP_REG_SET(NULL, DISP_REG_SMI_SUBCOM1_L1LEN, 0XA);
  1083. DDPMSG("SMI subcom after config:(0x%x,0x%x)\n",
  1084. DISP_REG_GET(DISP_REG_SMI_SUBCOM0_L1LEN),
  1085. DISP_REG_GET(DISP_REG_SMI_SUBCOM1_L1LEN));
  1086. return 0;
  1087. }
  1088. int ddp_path_top_clock_off(void)
  1089. {
  1090. DDPMSG("ddp path top clock off\n");
  1091. ddp_disable_module_clock(DISP_MODULE_SMI_LARB0);
  1092. ddp_disable_module_clock(DISP_MODULE_SMI_COMMON);
  1093. DDPMSG("ddp CG0:%x CG1:%x\n", DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  1094. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1));
  1095. return 0;
  1096. }
  1097. int ddp_path_m4u_off(void)
  1098. {
  1099. int i;
  1100. DDPMSG("ddp path m4u off\n");
  1101. #ifdef MTKFB_NO_M4U
  1102. /* display ports bypass m4u.
  1103. ==== FBI WARNING: ==========
  1104. This function is hard code of m4u port setting !!!
  1105. Please ask M4U owner about it for new chip porting !!!
  1106. */
  1107. /*
  1108. M4U_PORT_DISP_OVL0,
  1109. M4U_PORT_DISP_2L_OVL0_LARB0,
  1110. M4U_PORT_DISP_RDMA0,
  1111. M4U_PORT_DISP_WDMA0,
  1112. */
  1113. for (i=0; i<4; i++)
  1114. DISP_REG_SET_FIELD(0, REG_FLD_MMU_EN, DISP_REG_SMI_LARB0_MMU_EN + i*4, 0);
  1115. /*
  1116. M4U_PORT_DISP_OVL1_2L,
  1117. M4U_PORT_DISP_RDMA1,
  1118. M4U_PORT_DISP_2L_OVL0,
  1119. */
  1120. /* not use SMI_LARB1 */
  1121. /*
  1122. for (i=0; i<3; i++)
  1123. DISP_REG_SET_FIELD(0, REG_FLD_MMU_EN, DISP_REG_SMI_LARB1_MMU_EN + i*4, 0);
  1124. */
  1125. #endif
  1126. return 0;
  1127. }
  1128. void primary_disp_module_list_insert_dsc(void)
  1129. {
  1130. unsigned int i = 0;
  1131. for (i = 0; i < DDP_ENING_NUM; i++)
  1132. module_list_scenario[DDP_SCENARIO_PRIMARY_DISP][i] =
  1133. primary_disp_dsc_module_list[i];
  1134. }