ddp_path.c 37 KB

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