ddp_path.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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, -1}, 0, 0},
  129. /* DISP_RDMA0_SOUT_SEL */
  130. {DISP_MODULE_RSZ0_VIRTUAL1, {DISP_MODULE_DSI0,
  131. DISP_MODULE_COLOR0, DISP_MODULE_CCORR0, -1}, 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 == 0) {
  413. DDPDUMP("err: %s mout, connect next module %s failed\n",
  414. ddp_get_module_name(module_list[i]),
  415. ddp_get_module_name(module_list[i+1]));
  416. path_error +=1;
  417. }else if (valid == 1) {
  418. valid = 0;
  419. if ((DISP_REG_GET(mout_map[j].reg) & mout) == 0) {
  420. path_error += 1;
  421. DDPDUMP("error:%s mout, expect=0x%x, real=0x%x\n",
  422. ddp_get_module_name(module_list[i]),
  423. mout, DISP_REG_GET(mout_map[j].reg));
  424. } else if (DISP_REG_GET(mout_map[j].reg) != mout) {
  425. DDPDUMP
  426. ("warning: %s mout expect=0x%x, real=0x%x\n",
  427. ddp_get_module_name(module_list[i]), mout,
  428. DISP_REG_GET(mout_map[j].reg));
  429. }
  430. }
  431. break;
  432. }
  433. }
  434. }
  435. /* check out select */
  436. for (int i = 0; i < module_num - 1; i++) {
  437. for (j = 0; j < sizeof(sel_out_map)/sizeof(sel_out_map[0]); j++) {
  438. if (module_list[i] != sel_out_map[j].id)
  439. continue;
  440. /* find next module which can be connected */
  441. step = i + 1;
  442. while (ddp_modules[module_list[step]].can_connect== 0
  443. && step < module_num) {
  444. step++;
  445. }
  446. ASSERT(step < module_num);
  447. for (k = 0; k < DDP_SOUT_MAX; k++) {
  448. if (sel_out_map[j].id_bit_map[k] == -1) {
  449. path_error += 1;
  450. DDPDUMP
  451. ("error:out_s %s not connect to %s\n",
  452. ddp_get_module_name(module_list[i]),
  453. ddp_get_module_name(module_list[step]));
  454. break;
  455. }
  456. if (sel_out_map[j].id_bit_map[k] == module_list[step]) {
  457. if (DISP_REG_GET(sel_out_map[j].reg) != k) {
  458. path_error += 1;
  459. DDPDUMP
  460. ("error:out_s %s not connect to %s, expect=0x%x, real=0x%x\n",
  461. ddp_get_module_name(module_list[i]),
  462. ddp_get_module_name(module_list[step]),
  463. k, DISP_REG_GET(sel_out_map[j].reg));
  464. }
  465. break;
  466. }
  467. }
  468. }
  469. }
  470. /* check input select */
  471. for (int i = 1; i < module_num; i++) {
  472. for (j = 0; j < sizeof(sel_in_map)/sizeof(sel_in_map[0]); j++) {
  473. if (module_list[i] != sel_in_map[j].id)
  474. continue;
  475. /* find next module which can be connected */
  476. step = i - 1;
  477. while (ddp_modules[module_list[step]].can_connect == 0 && step > 0)
  478. step--;
  479. ASSERT(step >= 0);
  480. for (k = 0; k < DDP_SOUT_MAX; k++) {
  481. if (sel_in_map[j].id_bit_map[k] == -1) {
  482. path_error += 1;
  483. DDPDUMP
  484. ("error:in_s %s not connect to %s\n",
  485. ddp_get_module_name(module_list[i]),
  486. ddp_get_module_name(module_list[step]));
  487. break;
  488. }
  489. if (sel_in_map[j].id_bit_map[k] == module_list[step]) {
  490. if (DISP_REG_GET(sel_in_map[j].reg) != k) {
  491. path_error += 1;
  492. DDPDUMP("error:in_s %s not conn to %s,expect0x%x,real0x%x\n",
  493. ddp_get_module_name(module_list[step]),
  494. ddp_get_module_name(module_list[i]), k,
  495. DISP_REG_GET(sel_in_map[j].reg));
  496. }
  497. break;
  498. }
  499. }
  500. }
  501. }
  502. if (path_error == 0) {
  503. DDPDUMP("path: %s to %s is connected\n", ddp_get_module_name(module_list[0]),
  504. ddp_get_module_name(module_list[module_num - 1]));
  505. } else {
  506. DDPDUMP("path: %s to %s not connected!!!\n", ddp_get_module_name(module_list[0]),
  507. ddp_get_module_name(module_list[module_num - 1]));
  508. }
  509. }
  510. static void ddp_disconnect_path_l(int *module_list, void *handle)
  511. {
  512. unsigned int j, k;
  513. int step = 0;
  514. unsigned int mout = 0;
  515. unsigned int reg_mout = 0;
  516. unsigned int mout_idx = 0;
  517. int module_num = ddp_get_module_num_l(module_list);
  518. DDPDBG("disconnect_path: %s to %s\n", ddp_get_module_name(module_list[0]),
  519. ddp_get_module_name(module_list[module_num - 1]));
  520. for (int i = 0; i < module_num - 1; i++) {
  521. for (j = 0; j < sizeof(mout_map)/sizeof(mout_map[0]); j++) {
  522. if (module_list[i] == mout_map[j].id) {
  523. /* find next module which can be connected */
  524. step = i + 1;
  525. while (ddp_modules[module_list[step]].can_connect== 0
  526. && step < module_num) {
  527. step++;
  528. }
  529. ASSERT(step < module_num);
  530. for (k = 0; k < DDP_MOUT_MAX; k++) {
  531. if (mout_map[j].out_id_bit_map[k].m == -1)
  532. break;
  533. if (mout_map[j].out_id_bit_map[k].m == module_list[step]) {
  534. mout |= mout_map[j].out_id_bit_map[k].v;
  535. reg_mout |= mout;
  536. mout_idx = j;
  537. DDPDBG("disconnect mout %s to %s\n",
  538. ddp_get_module_name(module_list[i]),
  539. ddp_get_module_name(module_list[step]));
  540. break;
  541. }
  542. }
  543. /* update mout_value */
  544. mout_map[j].reg_val &= ~mout;
  545. mout = 0;
  546. }
  547. }
  548. if (reg_mout) {
  549. DISP_REG_SET(handle, mout_map[mout_idx].reg, mout_map[mout_idx].reg_val);
  550. reg_mout = 0;
  551. mout_idx = 0;
  552. }
  553. }
  554. }
  555. static int ddp_get_mutex_src(DISP_MODULE_ENUM dest_module, DDP_MODE ddp_mode,
  556. unsigned int *SOF_src, unsigned int *EOF_src)
  557. {
  558. unsigned int src_from_dst_module = 0;
  559. if (dest_module == DISP_MODULE_WDMA0) {
  560. if (ddp_mode == DDP_VIDEO_MODE)
  561. DISP_LOG_W("%s: dst_mode=%s, but is video mode !!\n", __func__,
  562. ddp_get_module_name(dest_module));
  563. *SOF_src = *EOF_src = SOF_VAL_MUTEX0_SOF_SINGLE_MODE;
  564. return 0;
  565. }
  566. if (dest_module == DISP_MODULE_DSI0 || dest_module == DISP_MODULE_DSIDUAL) {
  567. src_from_dst_module = SOF_VAL_MUTEX0_SOF_FROM_DSI0;
  568. } else {
  569. DDPERR("get mutex sof, invalid param dst module = %s(%d), dis mode %s\n",
  570. ddp_get_module_name(dest_module), dest_module, ddp_get_mode_name(ddp_mode));
  571. ASSERT(0);
  572. }
  573. if (ddp_mode == DDP_CMD_MODE) {
  574. *SOF_src = SOF_VAL_MUTEX0_SOF_SINGLE_MODE;
  575. if (0/*disp_helper_get_option(DISP_OPT_MUTEX_EOF_EN_FOR_CMD_MODE)*/)
  576. *EOF_src = src_from_dst_module;
  577. else
  578. *EOF_src = SOF_VAL_MUTEX0_EOF_SINGLE_MODE;
  579. } else {
  580. *SOF_src = *EOF_src = src_from_dst_module;
  581. }
  582. return 0;
  583. }
  584. /* id: mutex ID, 0~5 */
  585. static int ddp_mutex_set_l(int mutex_id, int *module_list, DDP_MODE ddp_mode, void *handle)
  586. {
  587. int i = 0;
  588. unsigned int value0 = 0;
  589. unsigned int value1 = 0;
  590. unsigned int sof_val;
  591. unsigned int sof_src, eof_src;
  592. int module_num = ddp_get_module_num_l(module_list);
  593. ddp_get_mutex_src(module_list[module_num - 1], ddp_mode, &sof_src, &eof_src);
  594. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  595. DDPERR("exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  596. return -1;
  597. }
  598. for (i = 0; i < module_num; i++) {
  599. if (module_mutex_map[module_list[i]].bit != -1) {
  600. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module_list[i]),
  601. mutex_id);
  602. if (module_mutex_map[module_list[i]].mod_num == 0) {
  603. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  604. value0 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  605. value0 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  606. } else {
  607. value0 |= (1 << module_mutex_map[module_list[i]].bit);
  608. }
  609. } else if (module_mutex_map[module_list[i]].mod_num == 1) {
  610. /* DISP_MODULE_DSIDUAL is special */
  611. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  612. value1 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  613. value1 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  614. } else {
  615. value1 |= (1 << module_mutex_map[module_list[i]].bit);
  616. }
  617. }
  618. } else {
  619. DDPDBG("module %s not added to mutex %d\n",
  620. ddp_get_module_name(module_list[i]), mutex_id);
  621. }
  622. }
  623. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), value0);
  624. sof_val = REG_FLD_VAL(SOF_FLD_MUTEX0_SOF, sof_src);
  625. sof_val |= REG_FLD_VAL(SOF_FLD_MUTEX0_EOF, eof_src);
  626. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), sof_val);
  627. DDPDBG("mutex %d value=0x%x, sof=%s, eof=%s\n", mutex_id,
  628. value0, ddp_get_mutex_sof_name(sof_src), ddp_get_mutex_sof_name(eof_src));
  629. return 0;
  630. }
  631. static void ddp_check_mutex_l(int mutex_id, int *module_list, DDP_MODE ddp_mode)
  632. {
  633. int i = 0;
  634. uint32_t real_value0 = 0;
  635. uint32_t real_value1 = 0;
  636. uint32_t expect_value0 = 0;
  637. uint32_t expect_value1 = 0;
  638. unsigned int real_sof, real_eof, val;
  639. unsigned int expect_sof, expect_eof;
  640. int module_num = ddp_get_module_num_l(module_list);
  641. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  642. DDPDUMP("error:check mutex fail:exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  643. return;
  644. }
  645. real_value0 = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_MOD0(mutex_id));
  646. for (i = 0; i < module_num; i++) {
  647. if (module_mutex_map[module_list[i]].bit != -1) {
  648. if (module_mutex_map[module_list[i]].mod_num == 0) {
  649. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  650. expect_value0 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  651. expect_value0 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  652. } else {
  653. expect_value0 |= (1 << module_mutex_map[module_list[i]].bit);
  654. }
  655. }else if (module_mutex_map[module_list[i]].mod_num == 1) {
  656. if (DISP_MODULE_DSIDUAL == module_mutex_map[module_list[i]].module) {
  657. expect_value1 |= (1 << module_mutex_map[DISP_MODULE_DSI0].bit); /* DISP MODULE enum must start from 0 */
  658. expect_value1 |= (1 << module_mutex_map[DISP_MODULE_DSI1].bit);
  659. } else {
  660. expect_value1 |= (1 << module_mutex_map[module_list[i]].bit);
  661. }
  662. }
  663. }
  664. }
  665. if (expect_value0 != real_value0)
  666. DDPDUMP("error:mutex %d error: expect0 0x%x, real0 0x%x\n", mutex_id, expect_value0,
  667. real_value0);
  668. if (expect_value1 != real_value1)
  669. DDPDUMP("error:mutex %d error: expect1 0x%x, real1 0x%x\n", mutex_id, expect_value1,
  670. real_value1);
  671. val = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_SOF(mutex_id));
  672. real_sof = REG_FLD_VAL_GET(SOF_FLD_MUTEX0_SOF, val);
  673. real_eof = REG_FLD_VAL_GET(SOF_FLD_MUTEX0_EOF, val);
  674. ddp_get_mutex_src(module_list[module_num - 1], ddp_mode, &expect_sof, &expect_eof);
  675. if (expect_sof != real_sof)
  676. DDPDUMP("error:mutex %d sof error: expect %s, real %s\n", mutex_id,
  677. ddp_get_mutex_sof_name(expect_sof), ddp_get_mutex_sof_name(real_sof));
  678. if (expect_eof != real_eof)
  679. DDPDUMP("error:mutex %d eof error: expect %s, real %s\n", mutex_id,
  680. ddp_get_mutex_sof_name(expect_eof), ddp_get_mutex_sof_name(real_eof));
  681. }
  682. static int ddp_mutex_enable_l(int mutex_idx, void *handle)
  683. {
  684. DDPDBG("mutex %d enable\n", mutex_idx);
  685. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_CFG, 0);
  686. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_EN(mutex_idx), 1);
  687. return 0;
  688. }
  689. int ddp_get_module_num(DDP_SCENARIO_ENUM scenario)
  690. {
  691. return ddp_get_module_num_l(module_list_scenario[scenario]);
  692. }
  693. static void ddp_print_scenario(DDP_SCENARIO_ENUM scenario)
  694. {
  695. int i =0;
  696. char path[512]= {'\0'};
  697. int num = ddp_get_module_num(scenario);
  698. for (i = 0; i < num; i++)
  699. strncat(path, ddp_get_module_name(module_list_scenario[scenario][i]), sizeof(path));
  700. DDPMSG("scenario %s have modules: %s\n",ddp_get_scenario_name(scenario),path);
  701. }
  702. static int ddp_find_module_index(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  703. {
  704. int i = 0;
  705. for (i = 0; i < DDP_ENING_NUM; i++) {
  706. if (module_list_scenario[ddp_scenario][i] == (int)module)
  707. return i;
  708. }
  709. DDPDBG("find module: can not find module %s on scenario %s\n", ddp_get_module_name(module),
  710. ddp_get_scenario_name(ddp_scenario));
  711. return -1;
  712. }
  713. /* set display interface when kernel init */
  714. int ddp_set_dst_module(DDP_SCENARIO_ENUM scenario, DISP_MODULE_ENUM dst_module)
  715. {
  716. int i = 0;
  717. DDPMSG("ddp_set_dst_module, scenario=%s, dst_module=%s\n",
  718. ddp_get_scenario_name(scenario), ddp_get_module_name(dst_module));
  719. if (ddp_find_module_index(scenario, dst_module) > 0) {
  720. DDPDBG("%s is already on path\n", ddp_get_module_name(dst_module));
  721. return 0;
  722. }
  723. i = ddp_get_module_num_l(module_list_scenario[scenario]) - 1;
  724. ASSERT(i >= 0);
  725. if (dst_module == DISP_MODULE_DSIDUAL) {
  726. if (i < (DDP_ENING_NUM - 1)) {
  727. module_list_scenario[scenario][i++] = DISP_MODULE_SPLIT0;
  728. } else {
  729. DDPERR("set dst module over up bound\n");
  730. return -1;
  731. }
  732. } else {
  733. if (ddp_get_dst_module(scenario) == DISP_MODULE_DSIDUAL) {
  734. if (i >= 1) {
  735. module_list_scenario[scenario][i--] = -1;
  736. } else {
  737. DDPERR("set dst module over low bound\n");
  738. return -1;
  739. }
  740. }
  741. }
  742. module_list_scenario[scenario][i] = dst_module;
  743. if (scenario == DDP_SCENARIO_PRIMARY_ALL)
  744. ddp_set_dst_module(DDP_SCENARIO_PRIMARY_DISP, dst_module);
  745. ddp_print_scenario(scenario);
  746. return 0;
  747. }
  748. DISP_MODULE_ENUM ddp_get_dst_module(DDP_SCENARIO_ENUM ddp_scenario)
  749. {
  750. DISP_MODULE_ENUM module_name = DISP_MODULE_UNKNOWN;
  751. int module_num = ddp_get_module_num_l(module_list_scenario[ddp_scenario]) - 1;
  752. if (module_num >= 0)
  753. module_name = module_list_scenario[ddp_scenario][module_num];
  754. return module_name;
  755. }
  756. int *ddp_get_scenario_list(DDP_SCENARIO_ENUM ddp_scenario)
  757. {
  758. return module_list_scenario[ddp_scenario];
  759. }
  760. int ddp_is_module_in_scenario(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  761. {
  762. int i = 0;
  763. for (i = 0; i < DDP_ENING_NUM; i++) {
  764. if (module_list_scenario[ddp_scenario][i] == (int)module)
  765. return 1;
  766. }
  767. return 0;
  768. }
  769. int ddp_insert_module(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM place,
  770. DISP_MODULE_ENUM module)
  771. {
  772. int i = DDP_ENING_NUM - 1;
  773. int idx = ddp_find_module_index(ddp_scenario, place);
  774. if (idx < 0) {
  775. DDPERR("error: ddp_insert_module , place=%s is not in scenario %s!\n",
  776. ddp_get_module_name(place), ddp_get_scenario_name(ddp_scenario));
  777. return -1;
  778. }
  779. for (i = 0; i < DDP_ENING_NUM; i++) {
  780. if (module_list_scenario[ddp_scenario][i] == (int)module) {
  781. DDPERR("error: ddp_insert_module , module=%s is already in scenario %s!\n",
  782. ddp_get_module_name(module), ddp_get_scenario_name(ddp_scenario));
  783. return -1;
  784. }
  785. }
  786. /* should have empty room for insert */
  787. ASSERT(module_list_scenario[ddp_scenario][DDP_ENING_NUM - 1] == -1);
  788. for (i = DDP_ENING_NUM - 2; i >= idx; i--)
  789. module_list_scenario[ddp_scenario][i + 1] = module_list_scenario[ddp_scenario][i];
  790. module_list_scenario[ddp_scenario][idx] = module;
  791. {
  792. int *modules = ddp_get_scenario_list(ddp_scenario);
  793. int module_num = ddp_get_module_num(ddp_scenario);
  794. DDPMSG("after insert module, module list is:\n");
  795. for (i = 0; i < module_num; i++)
  796. DDPMSG("%s-", ddp_get_module_name(modules[i]));
  797. }
  798. return 0;
  799. }
  800. int ddp_remove_module(DDP_SCENARIO_ENUM ddp_scenario, DISP_MODULE_ENUM module)
  801. {
  802. int i = 0;
  803. int idx = ddp_find_module_index(ddp_scenario, module);
  804. if (idx < 0) {
  805. DDPERR("ddp_remove_module, can not find module %s in scenario %s\n",
  806. ddp_get_module_name(module), ddp_get_scenario_name(ddp_scenario));
  807. return -1;
  808. }
  809. for (i = idx; i < DDP_ENING_NUM - 1; i++)
  810. module_list_scenario[ddp_scenario][i] = module_list_scenario[ddp_scenario][i + 1];
  811. module_list_scenario[ddp_scenario][DDP_ENING_NUM - 1] = -1;
  812. {
  813. int *modules = ddp_get_scenario_list(ddp_scenario);
  814. int module_num = ddp_get_module_num(ddp_scenario);
  815. DDPMSG("after remove module, module list is:\n");
  816. for (i = 0; i < module_num; i++)
  817. DDPMSG("%s-", ddp_get_module_name(modules[i]));
  818. }
  819. return 0;
  820. }
  821. void ddp_connect_path(DDP_SCENARIO_ENUM scenario, void *handle)
  822. {
  823. DDPDBG("path connect on scenario %s\n", ddp_get_scenario_name(scenario));
  824. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  825. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP], handle);
  826. ddp_connect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT], handle);
  827. } else {
  828. ddp_connect_path_l(module_list_scenario[scenario], handle);
  829. }
  830. return;
  831. }
  832. void ddp_disconnect_path(DDP_SCENARIO_ENUM scenario, void *handle)
  833. {
  834. DDPDBG("path disconnect on scenario %s\n", ddp_get_scenario_name(scenario));
  835. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  836. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP], handle);
  837. ddp_disconnect_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT],
  838. handle);
  839. } else {
  840. ddp_disconnect_path_l(module_list_scenario[scenario], handle);
  841. }
  842. return;
  843. }
  844. void ddp_check_path(DDP_SCENARIO_ENUM scenario)
  845. {
  846. DDPDBG("path check path on scenario %s\n", ddp_get_scenario_name(scenario));
  847. if (scenario == DDP_SCENARIO_PRIMARY_ALL) {
  848. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_DISP]);
  849. ddp_check_path_l(module_list_scenario[DDP_SCENARIO_PRIMARY_OVL_MEMOUT]);
  850. } else {
  851. ddp_check_path_l(module_list_scenario[scenario]);
  852. }
  853. return;
  854. }
  855. void ddp_check_mutex(int mutex_id, DDP_SCENARIO_ENUM scenario, DDP_MODE mode)
  856. {
  857. DDPDBG("check mutex %d on scenario %s\n", mutex_id, ddp_get_scenario_name(scenario));
  858. ddp_check_mutex_l(mutex_id, module_list_scenario[scenario], mode);
  859. return;
  860. }
  861. int ddp_mutex_set(int mutex_id, DDP_SCENARIO_ENUM scenario, DDP_MODE mode, void *handle)
  862. {
  863. if (scenario < DDP_SCENARIO_MAX) {
  864. return ddp_mutex_set_l(mutex_id, module_list_scenario[scenario], mode, handle);
  865. } else {
  866. DDPERR("Invalid scenario %d when setting mutex\n", scenario);
  867. return -1;
  868. }
  869. return 0;
  870. }
  871. int ddp_mutex_Interrupt_enable(int mutex_id, void *handle)
  872. {
  873. DDPDBG("mutex %d interrupt enable\n", mutex_id);
  874. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0x1 << mutex_id, 0x1 << mutex_id);
  875. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 1 << (mutex_id + DISP_MUTEX_TOTAL),
  876. 0x1 << (mutex_id + DISP_MUTEX_TOTAL));
  877. return 0;
  878. }
  879. int ddp_mutex_Interrupt_disable(int mutex_id, void *handle)
  880. {
  881. DDPDBG("mutex %d interrupt disenable\n", mutex_id);
  882. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0, 0x1 << mutex_id);
  883. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_INTEN, 0, 0x1 << (mutex_id + DISP_MUTEX_TOTAL));
  884. return 0;
  885. }
  886. int ddp_mutex_reset(int mutex_id, void *handle)
  887. {
  888. DDPDBG("mutex %d reset\n", mutex_id);
  889. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_RST(mutex_id), 1);
  890. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_RST(mutex_id), 0);
  891. return 0;
  892. }
  893. int ddp_is_moudule_in_mutex(int mutex_id, DISP_MODULE_ENUM module)
  894. {
  895. int ret = 0;
  896. uint32_t real_value = 0;
  897. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  898. DDPDUMP("error:check_moudule_in_mute fail:exceed mutex max (0 ~ %d)\n",
  899. DISP_MUTEX_DDP_LAST);
  900. return ret;
  901. }
  902. if (module_mutex_map[module].mod_num == 0) {
  903. real_value = DISP_REG_GET(DISP_REG_CONFIG_MUTEX_MOD0(mutex_id));
  904. }
  905. if (1 == ((real_value >> module_mutex_map[module].bit) & 0x01))
  906. ret = 1;
  907. return ret;
  908. }
  909. int ddp_mutex_add_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), value, value);
  919. }
  920. }
  921. }
  922. return 0;
  923. }
  924. int ddp_mutex_remove_module(int mutex_id, DISP_MODULE_ENUM module, void *handle)
  925. {
  926. int value = 0;
  927. if (module < DISP_MODULE_UNKNOWN) {
  928. if (module_mutex_map[module].bit != -1) {
  929. DDPDBG("module %s added to mutex %d\n", ddp_get_module_name(module),
  930. mutex_id);
  931. value |= (1 << module_mutex_map[module].bit);
  932. if (module_mutex_map[module].mod_num == 0) {
  933. DISP_REG_MASK(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), 0, value);
  934. }
  935. }
  936. }
  937. return 0;
  938. }
  939. int ddp_mutex_clear(int mutex_id, void *handle)
  940. {
  941. DDPDBG("mutex %d clear\n", mutex_id);
  942. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_MOD0(mutex_id), 0);
  943. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), 0);
  944. /* enough or not */
  945. /*reset mutex */
  946. ddp_mutex_reset(mutex_id, handle);
  947. return 0;
  948. }
  949. int ddp_mutex_enable(int mutex_id, DDP_SCENARIO_ENUM scenario, void *handle)
  950. {
  951. return ddp_mutex_enable_l(mutex_id, handle);
  952. }
  953. int ddp_mutex_disable(int mutex_id, DDP_SCENARIO_ENUM scenario, void *handle)
  954. {
  955. DDPDBG("mutex %d disable\n", mutex_id);
  956. DISP_REG_SET(handle, DISP_REG_CONFIG_MUTEX_EN(mutex_id), 0);
  957. return 0;
  958. }
  959. int ddp_mutex_set_sof_wait(int mutex_id, cmdqRecHandle handle, int wait)
  960. {
  961. if (mutex_id < DISP_MUTEX_DDP_FIRST || mutex_id > DISP_MUTEX_DDP_LAST) {
  962. DDPERR("exceed mutex max (0 ~ %d)\n", DISP_MUTEX_DDP_LAST);
  963. return -1;
  964. }
  965. DISP_REG_SET_FIELD(handle, SOF_FLD_MUTEX0_SOF_WAIT, DISP_REG_CONFIG_MUTEX_SOF(mutex_id), wait);
  966. return 0;
  967. }
  968. int ddp_check_engine_status(int mutexID)
  969. {
  970. /* check engines' clock bit & enable bit & status bit before unlock mutex */
  971. /* should not needed, in comdq do? */
  972. int result = 0;
  973. return result;
  974. }
  975. int ddp_path_top_clock_on(void)
  976. {
  977. DDPMSG("ddp path top clock on\n");
  978. spm_mtcmos_ctrl_dis(1);
  979. ddp_enable_module_clock(DISP_MODULE_SMI_COMMON);
  980. ddp_enable_module_clock(DISP_MODULE_SMI_LARB0);
  981. DDPMSG("ddp CG0:%x CG1:%x\n", DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  982. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1));
  983. return 0;
  984. }
  985. int ddp_path_top_clock_off(void)
  986. {
  987. DDPMSG("ddp path top clock off\n");
  988. ddp_disable_module_clock(DISP_MODULE_SMI_LARB0);
  989. ddp_disable_module_clock(DISP_MODULE_SMI_COMMON);
  990. DDPMSG("ddp CG0:%x CG1:%x\n", DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON0),
  991. DISP_REG_GET(DISP_REG_CONFIG_MMSYS_CG_CON1));
  992. return 0;
  993. }
  994. int ddp_path_m4u_off(void)
  995. {
  996. int i;
  997. DDPMSG("ddp path m4u off\n");
  998. #ifdef MTKFB_NO_M4U
  999. /* display ports bypass m4u.
  1000. ==== FBI WARNING: ==========
  1001. This function is hard code of m4u port setting !!!
  1002. Please ask M4U owner about it for new chip porting !!!
  1003. */
  1004. /*
  1005. M4U_PORT_DISP_OVL0,
  1006. M4U_PORT_DISP_2L_OVL0_LARB0,
  1007. M4U_PORT_DISP_RDMA0,
  1008. M4U_PORT_DISP_WDMA0,
  1009. */
  1010. for (i=0; i<4; i++)
  1011. DISP_REG_SET_FIELD(0, REG_FLD_MMU_EN, DISP_REG_SMI_LARB0_MMU_EN + i*4, 0);
  1012. /*
  1013. M4U_PORT_DISP_OVL1_2L,
  1014. M4U_PORT_DISP_RDMA1,
  1015. M4U_PORT_DISP_2L_OVL0,
  1016. */
  1017. /* not use SMI_LARB1 */
  1018. /*
  1019. for (i=0; i<3; i++)
  1020. DISP_REG_SET_FIELD(0, REG_FLD_MMU_EN, DISP_REG_SMI_LARB1_MMU_EN + i*4, 0);
  1021. */
  1022. #endif
  1023. return 0;
  1024. }