ddp_path.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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,
  683. ddp_get_module_name(module_list_scenario[scenario][i]),
  684. (sizeof(path) - strlen(path) - 1));
  685. DDPMSG("scenario %s have modules: %s\n",ddp_get_scenario_name(scenario),path);
  686. }
  687. static int ddp_find_module_index(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  688. {
  689. int i = 0;
  690. for (i = 0; i < DDP_ENING_NUM; i++) {
  691. if (module_list_scenario[ddp_scenario][i] == (int)module)
  692. return i;
  693. }
  694. DDPDBG("find module: can not find module %s on scenario %s\n", ddp_get_module_name(module),
  695. ddp_get_scenario_name(ddp_scenario));
  696. return -1;
  697. }
  698. /* set display interface when kernel init */
  699. int ddp_set_dst_module(DDP_SCENARIO_ENUM scenario, DISP_MODULE_ENUM dst_module)
  700. {
  701. int i = 0;
  702. DDPMSG("ddp_set_dst_module, scenario=%s, dst_module=%s\n",
  703. ddp_get_scenario_name(scenario), ddp_get_module_name(dst_module));
  704. if (ddp_find_module_index(scenario, dst_module) > 0) {
  705. DDPDBG("%s is already on path\n", ddp_get_module_name(dst_module));
  706. return 0;
  707. }
  708. i = ddp_get_module_num_l(module_list_scenario[scenario]) - 1;
  709. ASSERT(i >= 0);
  710. if (dst_module == DISP_MODULE_DSIDUAL) {
  711. if (i < (DDP_ENING_NUM - 1)) {
  712. module_list_scenario[scenario][i++] = DISP_MODULE_SPLIT0;
  713. } else {
  714. DDPERR("set dst module over up bound\n");
  715. return -1;
  716. }
  717. } else {
  718. if (ddp_get_dst_module(scenario) == DISP_MODULE_DSIDUAL) {
  719. if (i >= 1) {
  720. module_list_scenario[scenario][i--] = -1;
  721. } else {
  722. DDPERR("set dst module over low bound\n");
  723. return -1;
  724. }
  725. }
  726. }
  727. module_list_scenario[scenario][i] = dst_module;
  728. if (scenario == DDP_SCENARIO_PRIMARY_ALL)
  729. ddp_set_dst_module(DDP_SCENARIO_PRIMARY_DISP, dst_module);
  730. ddp_print_scenario(scenario);
  731. return 0;
  732. }
  733. DISP_MODULE_ENUM ddp_get_dst_module(DDP_SCENARIO_ENUM ddp_scenario)
  734. {
  735. DISP_MODULE_ENUM module_name = DISP_MODULE_UNKNOWN;
  736. int module_num = ddp_get_module_num_l(module_list_scenario[ddp_scenario]) - 1;
  737. if (module_num >= 0)
  738. module_name = module_list_scenario[ddp_scenario][module_num];
  739. return module_name;
  740. }
  741. int *ddp_get_scenario_list(DDP_SCENARIO_ENUM ddp_scenario)
  742. {
  743. return module_list_scenario[ddp_scenario];
  744. }
  745. int ddp_is_module_in_scenario(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  746. {
  747. int i = 0;
  748. for (i = 0; i < DDP_ENING_NUM; i++) {
  749. if (module_list_scenario[ddp_scenario][i] == (int)module)
  750. return 1;
  751. }
  752. return 0;
  753. }
  754. int ddp_insert_module(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM place,
  755. DISP_MODULE_ENUM module)
  756. {
  757. int i = DDP_ENING_NUM - 1;
  758. int idx = ddp_find_module_index(ddp_scenario, place);
  759. if (idx < 0) {
  760. DDPERR("error: ddp_insert_module , place=%s is not in scenario %s!\n",
  761. ddp_get_module_name(place), ddp_get_scenario_name(ddp_scenario));
  762. return -1;
  763. }
  764. for (i = 0; i < DDP_ENING_NUM; i++) {
  765. if (module_list_scenario[ddp_scenario][i] == (int)module) {
  766. DDPERR("error: ddp_insert_module , module=%s is already in scenario %s!\n",
  767. ddp_get_module_name(module), ddp_get_scenario_name(ddp_scenario));
  768. return -1;
  769. }
  770. }
  771. /* should have empty room for insert */
  772. ASSERT(module_list_scenario[ddp_scenario][DDP_ENING_NUM - 1] == -1);
  773. for (i = DDP_ENING_NUM - 2; i >= idx; i--)
  774. module_list_scenario[ddp_scenario][i + 1] = module_list_scenario[ddp_scenario][i];
  775. module_list_scenario[ddp_scenario][idx] = module;
  776. {
  777. int *modules = ddp_get_scenario_list(ddp_scenario);
  778. int module_num = ddp_get_module_num(ddp_scenario);
  779. DDPMSG("after insert module, module list is:\n");
  780. for (i = 0; i < module_num; i++)
  781. DDPMSG("%s-", ddp_get_module_name(modules[i]));
  782. }
  783. return 0;
  784. }
  785. int ddp_remove_module(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  786. {
  787. int i = 0;
  788. int idx = ddp_find_module_index(ddp_scenario, module);
  789. if (idx < 0) {
  790. DDPERR("ddp_remove_module, can not find module %s in scenario %s\n",
  791. ddp_get_module_name(module), ddp_get_scenario_name(ddp_scenario));
  792. return -1;
  793. }
  794. for (i = idx; i < DDP_ENING_NUM - 1; i++)
  795. module_list_scenario[ddp_scenario][i] = module_list_scenario[ddp_scenario][i + 1];
  796. module_list_scenario[ddp_scenario][DDP_ENING_NUM - 1] = -1;
  797. {
  798. int *modules = ddp_get_scenario_list(ddp_scenario);
  799. int module_num = ddp_get_module_num(ddp_scenario);
  800. DDPMSG("after remove module, module list is:\n");
  801. for (i = 0; i < module_num; i++)
  802. DDPMSG("%s-", ddp_get_module_name(modules[i]));
  803. }
  804. return 0;
  805. }
  806. void ddp_connect_path(DDP_SCENARIO_ENUM scenario, void *handle)
  807. {
  808. DDPDBG("path connect on scenario %s\n", ddp_get_scenario_name(scenario));
  809. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  810. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP], handle);
  811. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT], handle);
  812. } else {
  813. ddp_connect_path_l(module_list_scenario[scenario], handle);
  814. }
  815. return;
  816. }
  817. void ddp_disconnect_path(DDP_SCENARIO_ENUM scenario, void *handle)
  818. {
  819. DDPDBG("path disconnect on scenario %s\n", ddp_get_scenario_name(scenario));
  820. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  821. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP], handle);
  822. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT],
  823. handle);
  824. } else {
  825. ddp_disconnect_path_l(module_list_scenario[scenario], handle);
  826. }
  827. return;
  828. }
  829. void ddp_check_path(DDP_SCENARIO_ENUM scenario)
  830. {
  831. DDPDBG("path check path on scenario %s\n", ddp_get_scenario_name(scenario));
  832. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  833. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP]);
  834. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT]);
  835. } else {
  836. ddp_check_path_l(module_list_scenario[scenario]);
  837. }
  838. return;
  839. }
  840. void ddp_check_mutex(int mutex_id, DDP_SCENARIO_ENUM scenario, DDP_MODE mode)
  841. {
  842. DDPDBG("check mutex %d on scenario %s\n", mutex_id, ddp_get_scenario_name(scenario));
  843. ddp_check_mutex_l(mutex_id, module_list_scenario[scenario], mode);
  844. return;
  845. }
  846. int ddp_mutex_set(int mutex_id, DDP_SCENARIO_ENUM scenario, DDP_MODE mode, void *handle)
  847. {
  848. if (scenario < DDP_SCENARIO_MAX) {
  849. return ddp_mutex_set_l(mutex_id, module_list_scenario[scenario], mode, handle);
  850. } else {
  851. DDPERR("Invalid scenario %d when setting mutex\n", scenario);
  852. return -1;
  853. }
  854. return 0;
  855. }
  856. int ddp_mutex_Interrupt_enable(int mutex_id, void *handle)
  857. {
  858. DDPDBG("mutex %d interrupt enable\n", mutex_id);
  859. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0x1 << mutex_id, 0x1 << mutex_id);
  860. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 1 << (mutex_id + DISP_MUTEX_TOTAL),
  861. 0x1 << (mutex_id + DISP_MUTEX_TOTAL));
  862. return 0;
  863. }
  864. int ddp_mutex_Interrupt_disable(int mutex_id, void *handle)
  865. {
  866. DDPDBG("mutex %d interrupt disenable\n", mutex_id);
  867. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0, 0x1 << mutex_id);
  868. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0, 0x1 << (mutex_id + DISP_MUTEX_TOTAL));
  869. return 0;
  870. }
  871. int ddp_mutex_reset(int mutex_id, void *handle)
  872. {
  873. DDPDBG("mutex %d reset\n", mutex_id);
  874. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_RST(mutex_id), 1);
  875. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_RST(mutex_id), 0);
  876. return 0;
  877. }
  878. int ddp_is_moudule_in_mutex(int mutex_id, DISP_MODULE_ENUM module)
  879. {
  880. int ret = 0;
  881. uint32_t real_value = 0;
  882. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  883. DDPDUMP("error:check_moudule_in_mute fail:exceed mutex max (0 ~ %d)\n",
  884. DISP_MUTEX_DDP_LAST);
  885. return ret;
  886. }
  887. if (module_mutex_map[module].mod_num == 0) {
  888. real_value = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_MOD0(mutex_id));
  889. }
  890. if (1 == ((real_value >> module_mutex_map[module].bit) & 0x01))
  891. ret = 1;
  892. return ret;
  893. }
  894. int ddp_mutex_add_module(int mutex_id, DISP_MODULE_ENUM module, void *handle)
  895. {
  896. int value = 0;
  897. if (module < DISP_MODULE_UNKNOWN) {
  898. if (module_mutex_map[module].bit != -1) {
  899. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module),
  900. mutex_id);
  901. value |= (1 << module_mutex_map[module].bit);
  902. if (module_mutex_map[module].mod_num == 0) {
  903. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), value, value);
  904. }
  905. }
  906. }
  907. return 0;
  908. }
  909. int ddp_mutex_remove_module(int mutex_id, DISP_MODULE_ENUM module, void *handle)
  910. {
  911. int value = 0;
  912. if (module < DISP_MODULE_UNKNOWN) {
  913. if (module_mutex_map[module].bit != -1) {
  914. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module),
  915. mutex_id);
  916. value |= (1 << module_mutex_map[module].bit);
  917. if (module_mutex_map[module].mod_num == 0) {
  918. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), 0, value);
  919. }
  920. }
  921. }
  922. return 0;
  923. }
  924. int ddp_mutex_clear(int mutex_id, void *handle)
  925. {
  926. DDPDBG("mutex %d clear\n", mutex_id);
  927. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), 0);
  928. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), 0);
  929. /* enough or not */
  930. /*reset mutex */
  931. ddp_mutex_reset(mutex_id, handle);
  932. return 0;
  933. }
  934. int ddp_mutex_enable(int mutex_id, DDP_SCENARIO_ENUM scenario, void *handle)
  935. {
  936. return ddp_mutex_enable_l(mutex_id, handle);
  937. }
  938. int ddp_mutex_disable(int mutex_id, DDP_SCENARIO_ENUM scenario, void *handle)
  939. {
  940. DDPDBG("mutex %d disable\n", mutex_id);
  941. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_EN(mutex_id), 0);
  942. return 0;
  943. }
  944. int ddp_mutex_set_sof_wait(int mutex_id, cmdqRecHandle handle, int wait)
  945. {
  946. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  947. DDPERR("exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  948. return -1;
  949. }
  950. DISP_REG_SET_FIELD(handle, SOF_FLD_MUTEX0_SOF_WAIT, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), wait);
  951. return 0;
  952. }
  953. int ddp_check_engine_status(int mutexID)
  954. {
  955. /* check engines' clock bit & enable bit & status bit before unlock mutex */
  956. /* should not needed, in comdq do? */
  957. int result = 0;
  958. return result;
  959. }
  960. int ddp_path_top_clock_on(void)
  961. {
  962. DDPMSG("ddp path top clock on\n");
  963. spm_mtcmos_ctrl_dis(1);
  964. ddp_enable_module_clock(DISP_MODULE_SMI_COMMON);
  965. ddp_enable_module_clock(DISP_MODULE_SMI_LARB0);
  966. DDPMSG("ddp CG0:%x CG1:%x\n", DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  967. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1));
  968. return 0;
  969. }
  970. int ddp_path_top_clock_off(void)
  971. {
  972. DDPMSG("ddp path top clock off\n");
  973. ddp_disable_module_clock(DISP_MODULE_SMI_LARB0);
  974. ddp_disable_module_clock(DISP_MODULE_SMI_COMMON);
  975. DDPMSG("ddp CG0:%x CG1:%x\n", DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  976. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1));
  977. return 0;
  978. }
  979. int ddp_path_m4u_off(void)
  980. {
  981. int i;
  982. DDPMSG("ddp path m4u off\n");
  983. #ifdef MTKFB_NO_M4U
  984. /* display ports bypass m4u.
  985. ==== FBI WARNING: ==========
  986. This function is hard code of m4u port setting !!!
  987. Please ask M4U owner about it for new chip porting !!!
  988. */
  989. /*
  990. M4U_PORT_DISP_OVL0,
  991. M4U_PORT_DISP_2L_OVL0_LARB0,
  992. M4U_PORT_DISP_RDMA0,
  993. M4U_PORT_DISP_WDMA0,
  994. */
  995. for (i=0; i<4; i++)
  996. DISP_REG_SET_FIELD(0, REG_FLD_MMU_EN, DISP_REG_SMI_LARB0_MMU_EN + i*4, 0);
  997. /*
  998. M4U_PORT_DISP_OVL1_2L,
  999. M4U_PORT_DISP_RDMA1,
  1000. M4U_PORT_DISP_2L_OVL0,
  1001. */
  1002. /* Cervino not use SMI_LARB1 */
  1003. /*
  1004. for (i=0; i<3; i++)
  1005. DISP_REG_SET_FIELD(0, REG_FLD_MMU_EN, DISP_REG_SMI_LARB1_MMU_EN + i*4, 0);
  1006. */
  1007. #endif
  1008. return 0;
  1009. }