ddp_path.c 34 KB

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