ddp_path.c 33 KB

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