ddp_manager.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. #define LOG_TAG "ddp_manager"
  36. /*
  37. #include <linux/slab.h>
  38. #include <linux/sched.h>
  39. #include <linux/mutex.h>
  40. */
  41. //#include <platform/lcm_drv.h>
  42. #include <string.h>
  43. #include <platform/ddp_reg.h>
  44. #include <platform/ddp_path.h>
  45. #include <platform/ddp_manager.h>
  46. #include <platform/ddp_log.h>
  47. #include <platform/ddp_dump.h>
  48. extern DDP_MODULE_DRIVER * ddp_modules_driver[DISP_MODULE_NUM];
  49. #define DDP_MAX_MANAGER_HANDLE (DISP_MUTEX_DDP_COUNT+DISP_MUTEX_DDP_FIRST)
  50. typedef struct {
  51. unsigned int init;
  52. DISP_PATH_EVENT event;
  53. //wait_queue_head_t wq;
  54. unsigned long long data;
  55. } DPMGR_WQ_HANDLE;
  56. typedef struct {
  57. DDP_IRQ_BIT irq_bit;
  58. } DDP_IRQ_EVENT_MAPPING;
  59. typedef struct {
  60. cmdqRecHandle cmdqhandle;
  61. int hwmutexid;
  62. int power_sate;
  63. DDP_MODE mode;
  64. //struct mutex mutex_lock;
  65. DDP_IRQ_EVENT_MAPPING irq_event_map[DISP_PATH_EVENT_NUM];
  66. DPMGR_WQ_HANDLE wq_list[DISP_PATH_EVENT_NUM];
  67. DDP_SCENARIO_ENUM scenario;
  68. disp_ddp_path_config last_config;
  69. } ddp_path_handle_t, *ddp_path_handle;
  70. typedef struct {
  71. int handle_cnt;
  72. int mutex_idx;
  73. int power_sate;
  74. //struct mutex mutex_lock;
  75. DISP_MODULE_ENUM module_usage_table[DISP_MODULE_NUM];
  76. ddp_path_handle module_path_table[DISP_MODULE_NUM];
  77. ddp_path_handle handle_pool[DDP_MAX_MANAGER_HANDLE];
  78. } DDP_MANAGER_CONTEXT;
  79. static ddp_path_handle_t g_handle;
  80. #define DEFAULT_IRQ_EVENT_SCENARIO (3)
  81. static DDP_IRQ_EVENT_MAPPING ddp_irq_event_list[DEFAULT_IRQ_EVENT_SCENARIO][DISP_PATH_EVENT_NUM] = {
  82. {
  83. //ovl0 path
  84. {DDP_IRQ_RDMA0_START }, /*FRAME_START*/
  85. {DDP_IRQ_RDMA0_DONE }, /*FRAME_DONE*/
  86. {DDP_IRQ_RDMA0_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  87. {DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  88. {DDP_IRQ_WDMA0_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
  89. {DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_STOP*/
  90. {DDP_IRQ_RDMA0_REG_UPDATE }, /*IF_CMD_DONE*/
  91. {DDP_IRQ_DSI0_EXT_TE }, /*IF_VSYNC*/
  92. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  93. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  94. },
  95. {
  96. //ovl1 path
  97. {DDP_IRQ_RDMA1_START }, /*FRAME_START*/
  98. {DDP_IRQ_RDMA1_DONE }, /*FRAME_DONE*/
  99. {DDP_IRQ_RDMA1_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  100. {DDP_IRQ_RDMA1_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  101. {DDP_IRQ_WDMA1_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
  102. {DDP_IRQ_RDMA1_TARGET_LINE }, /*FRAME_STOP*/
  103. {DDP_IRQ_RDMA1_REG_UPDATE }, /*IF_CMD_DONE*/
  104. {DDP_IRQ_RDMA1_TARGET_LINE }, /*IF_VSYNC*/
  105. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  106. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  107. },
  108. {
  109. // rdma path
  110. {DDP_IRQ_RDMA2_START }, /*FRAME_START*/
  111. {DDP_IRQ_RDMA2_DONE }, /*FRAME_DONE*/
  112. {DDP_IRQ_RDMA2_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  113. {DDP_IRQ_RDMA2_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  114. {DDP_IRQ_UNKNOW }, /*FRAME_COMPLETE*/
  115. {DDP_IRQ_RDMA2_TARGET_LINE }, /*FRAME_STOP*/
  116. {DDP_IRQ_RDMA2_REG_UPDATE }, /*IF_CMD_DONE*/
  117. {DDP_IRQ_RDMA2_TARGET_LINE }, /*IF_VSYNC*/
  118. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  119. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  120. },
  121. };
  122. static DDP_MANAGER_CONTEXT* _get_context(void)
  123. {
  124. static int is_context_inited = 0;
  125. static DDP_MANAGER_CONTEXT context;
  126. if (!is_context_inited) {
  127. memset((void*)&context, 0, sizeof(DDP_MANAGER_CONTEXT));
  128. context.mutex_idx = (1<<DISP_MUTEX_DDP_COUNT) - 1;
  129. //mutex_init(&context.mutex_lock);
  130. is_context_inited = 1;
  131. }
  132. return &context;
  133. }
  134. static int path_top_clock_off()
  135. {
  136. int i =0;
  137. int r = 0;
  138. DDP_MANAGER_CONTEXT * context = _get_context();
  139. if (context->power_sate) {
  140. for (i=0; i< DDP_MAX_MANAGER_HANDLE; i++) {
  141. if (context->handle_pool[i] != NULL && context->handle_pool[i]->power_sate !=0) {
  142. return 0;
  143. }
  144. }
  145. context->power_sate = 0;
  146. r = ddp_path_top_clock_off();
  147. }
  148. return r;
  149. }
  150. static int path_top_clock_on()
  151. {
  152. DDP_MANAGER_CONTEXT * context = _get_context();
  153. if (!context->power_sate) {
  154. context->power_sate = 1;
  155. ddp_path_top_clock_on();
  156. }
  157. return 0;
  158. }
  159. static ddp_path_handle find_handle_by_module(DISP_MODULE_ENUM module)
  160. {
  161. return _get_context()->module_path_table[module];
  162. }
  163. static int dpmgr_module_notify(DISP_MODULE_ENUM module, DISP_PATH_EVENT event)
  164. {
  165. ddp_path_handle handle = find_handle_by_module(module);
  166. return dpmgr_signal_event(handle,event);
  167. }
  168. static int assign_default_irqs_table(DDP_SCENARIO_ENUM scenario,DDP_IRQ_EVENT_MAPPING * irq_events)
  169. {
  170. int idx = 0;
  171. switch (scenario) {
  172. case DDP_SCENARIO_PRIMARY_DISP:
  173. case DDP_SCENARIO_PRIMARY_OVL_MEMOUT:
  174. case DDP_SCENARIO_PRIMARY_ALL:
  175. case DDP_SCENARIO_PRIMARY_RDMA0_COLOR0_DISP:
  176. case DDP_SCENARIO_PRIMARY_RDMA0_DISP:
  177. case DDP_SCENARIO_PRIMARY_OD_MEMOUT:
  178. case DDP_SCENARIO_DISPLAY_INTERFACE:
  179. case DDP_SCENARIO_MULTIPLE_OVL:
  180. idx = 0;
  181. break;
  182. case DDP_SCENARIO_SUB_DISP:
  183. case DDP_SCENARIO_SUB_OVL_MEMOUT:
  184. case DDP_SCENARIO_SUB_ALL:
  185. case DDP_SCENARIO_SUB_RDMA1_DISP:
  186. idx = 1;
  187. break;
  188. case DDP_SCENARIO_SUB_RDMA2_DISP:
  189. idx = 2;
  190. break;
  191. default:
  192. DISP_LOG_E("unknow scenario %d\n",scenario);
  193. }
  194. DISP_LOG_I("assign default irqs table index %d\n",idx);
  195. memcpy(irq_events,ddp_irq_event_list[idx],sizeof(ddp_irq_event_list[idx]));
  196. return 0;
  197. }
  198. static int acquire_free_bit(unsigned int total)
  199. {
  200. int free_id =0 ;
  201. while (total) {
  202. if (total & 0x1) {
  203. return free_id;
  204. }
  205. total>>=1;
  206. ++free_id;
  207. }
  208. return -1;
  209. }
  210. static int acquire_mutex(DDP_SCENARIO_ENUM scenario)
  211. {
  212. ///: primay use mutex 0
  213. int mutex_id =0 ;
  214. DDP_MANAGER_CONTEXT * content = _get_context();
  215. int mutex_idx_free = content->mutex_idx;
  216. ASSERT(scenario >= 0 && scenario < DDP_SCENARIO_MAX);
  217. while (mutex_idx_free) {
  218. if (mutex_idx_free & 0x1) {
  219. content->mutex_idx &= (~(0x1<<mutex_id));
  220. mutex_id += DISP_MUTEX_DDP_FIRST;
  221. break;
  222. }
  223. mutex_idx_free>>=1;
  224. ++mutex_id;
  225. }
  226. ASSERT(mutex_id < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT));
  227. DISP_LOG_I("scenario %s acquire mutex %d , left mutex 0x%x!\n",
  228. ddp_get_scenario_name(scenario), mutex_id, content->mutex_idx);
  229. return mutex_id;
  230. }
  231. static int release_mutex(int mutex_idx)
  232. {
  233. DDP_MANAGER_CONTEXT * content = _get_context();
  234. ASSERT(mutex_idx < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT));
  235. content->mutex_idx |= 1<< (mutex_idx-DISP_MUTEX_DDP_FIRST);
  236. DISP_LOG_I("release mutex %d , left mutex 0x%x!\n",
  237. mutex_idx, content->mutex_idx);
  238. return 0;
  239. }
  240. int dpmgr_path_set_video_mode(disp_path_handle dp_handle, int is_vdo_mode)
  241. {
  242. ddp_path_handle handle = NULL;
  243. ASSERT(dp_handle != NULL);
  244. handle = (ddp_path_handle)dp_handle;
  245. handle->mode = is_vdo_mode ? DDP_VIDEO_MODE : DDP_CMD_MODE;
  246. DISP_LOG_I("set scenario %s mode %s\n",ddp_get_scenario_name(handle->scenario),
  247. is_vdo_mode ? "Video Mode":"Cmd Mode");
  248. return 0;
  249. }
  250. disp_path_handle dpmgr_create_path(DDP_SCENARIO_ENUM scenario, cmdqRecHandle cmdq_handle)
  251. {
  252. int i =0;
  253. int module_name ;
  254. ddp_path_handle path_handle = NULL;
  255. int * modules = ddp_get_scenario_list(scenario);
  256. int module_num = ddp_get_module_num(scenario);
  257. DDP_MANAGER_CONTEXT * content = _get_context();
  258. //path_handle = kzalloc(sizeof(uint8_t*) * sizeof(ddp_path_handle_t), GFP_KERNEL);
  259. memset((void*)(&g_handle), 0, sizeof(ddp_path_handle_t));
  260. path_handle = &g_handle;
  261. if (NULL != path_handle) {
  262. path_handle->cmdqhandle = cmdq_handle;
  263. path_handle->scenario = scenario;
  264. path_handle->hwmutexid = acquire_mutex(scenario);
  265. assign_default_irqs_table(scenario,path_handle->irq_event_map);
  266. DISP_LOG_I("create handle 0x%x on scenario %s\n",(unsigned int)path_handle,ddp_get_scenario_name(scenario));
  267. for ( i=0; i< module_num; i++) {
  268. module_name = modules[i];
  269. content->module_usage_table[module_name]++;
  270. content->module_path_table[module_name] = path_handle;
  271. }
  272. content->handle_cnt ++;
  273. content->handle_pool[path_handle->hwmutexid] = path_handle;
  274. } else {
  275. DISP_LOG_E("Fail to create handle on scenario %s\n",ddp_get_scenario_name(scenario));
  276. }
  277. return path_handle;
  278. }
  279. int dpmgr_destroy_path(disp_path_handle dp_handle)
  280. {
  281. int i =0;
  282. int module_name ;
  283. ASSERT(dp_handle != NULL);
  284. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  285. int *modules;
  286. int module_num;
  287. DDP_MANAGER_CONTEXT * content = _get_context();
  288. if (handle != NULL) {
  289. DISP_LOG_I("destroy path handle 0x%x on scenario %s\n",(unsigned int)handle,ddp_get_scenario_name(handle->scenario));
  290. modules = ddp_get_scenario_list(handle->scenario);
  291. module_num = ddp_get_module_num(handle->scenario);
  292. release_mutex(handle->hwmutexid);
  293. ddp_disconnect_path(handle->scenario,handle->cmdqhandle);
  294. for ( i=0; i< module_num; i++) {
  295. module_name = modules[i];
  296. content->module_usage_table[module_name]--;
  297. content->module_path_table[module_name] = NULL;
  298. }
  299. content->handle_cnt --;
  300. ASSERT(content->handle_cnt >=0);
  301. content->handle_pool[handle->hwmutexid] = NULL;
  302. // kfree(handle);
  303. } else {
  304. DISP_LOG_I("destroy path handle, dp_handle is NULL\n");
  305. }
  306. return 0;
  307. }
  308. int dpmgr_path_add_dump(disp_path_handle dp_handle, ENGINE_DUMP engine,int encmdq )
  309. {
  310. ASSERT(dp_handle != NULL);
  311. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  312. ASSERT(handle->scenario ==DDP_SCENARIO_PRIMARY_DISP || handle->scenario ==DDP_SCENARIO_SUB_DISP);
  313. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  314. DISP_MODULE_ENUM wdma = ddp_is_scenario_on_primary(handle->scenario) ? DISP_MODULE_WDMA0: DISP_MODULE_WDMA1;
  315. // update contxt
  316. DDP_MANAGER_CONTEXT * context = _get_context();
  317. context->module_usage_table[wdma]++;
  318. context->module_path_table[wdma] = handle;
  319. handle->scenario = DDP_SCENARIO_PRIMARY_ALL;
  320. // update connected
  321. ddp_connect_path(handle->scenario,cmdqHandle);
  322. ddp_mutex_set(handle->hwmutexid, handle->scenario, handle->mode, cmdqHandle);
  323. //wdma just need start.
  324. if (ddp_modules_driver[wdma] != 0) {
  325. if (ddp_modules_driver[wdma]->init!= 0) {
  326. ddp_modules_driver[wdma]->init(wdma, cmdqHandle);
  327. }
  328. if (ddp_modules_driver[wdma]->start!= 0) {
  329. ddp_modules_driver[wdma]->start(wdma, cmdqHandle);
  330. }
  331. }
  332. return 0;
  333. }
  334. int dpmgr_path_remove_dump(disp_path_handle dp_handle, int encmdq )
  335. {
  336. ASSERT(dp_handle != NULL);
  337. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  338. ASSERT(handle->scenario ==DDP_SCENARIO_PRIMARY_DISP || handle->scenario ==DDP_SCENARIO_PRIMARY_ALL
  339. || handle->scenario ==DDP_SCENARIO_SUB_DISP || handle->scenario ==DDP_SCENARIO_SUB_ALL);
  340. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  341. DISP_MODULE_ENUM wdma = ddp_is_scenario_on_primary(handle->scenario) ? DISP_MODULE_WDMA0: DISP_MODULE_WDMA1;
  342. // update contxt
  343. DDP_MANAGER_CONTEXT * context = _get_context();
  344. context->module_usage_table[wdma]--;
  345. context->module_path_table[wdma] = 0;
  346. //wdma just need stop
  347. if (ddp_modules_driver[wdma] != 0) {
  348. if (ddp_modules_driver[wdma]->stop!= 0) {
  349. ddp_modules_driver[wdma]->stop(wdma, cmdqHandle);
  350. }
  351. if (ddp_modules_driver[wdma]->deinit!= 0) {
  352. ddp_modules_driver[wdma]->deinit(wdma, cmdqHandle);
  353. }
  354. }
  355. ddp_disconnect_path(DDP_SCENARIO_PRIMARY_OVL_MEMOUT,cmdqHandle);
  356. handle->scenario = DDP_SCENARIO_PRIMARY_DISP;
  357. // update connected
  358. ddp_connect_path(handle->scenario,cmdqHandle);
  359. ddp_mutex_set(handle->hwmutexid, handle->scenario, handle->mode, cmdqHandle);
  360. return 0;
  361. }
  362. int dpmgr_path_set_dst_module(disp_path_handle dp_handle,DISP_MODULE_ENUM dst_module)
  363. {
  364. ASSERT(dp_handle != NULL);
  365. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  366. ASSERT((handle->scenario >= 0 && handle->scenario < DDP_SCENARIO_MAX));
  367. DISP_LOG_I("set dst module on scenario %s, module %s\n",
  368. ddp_get_scenario_name(handle->scenario),ddp_get_module_name(dst_module));
  369. return ddp_set_dst_module(handle->scenario, dst_module);
  370. }
  371. DISP_MODULE_ENUM dpmgr_path_get_dst_module(disp_path_handle dp_handle)
  372. {
  373. ASSERT(dp_handle != NULL);
  374. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  375. ASSERT((handle->scenario >= 0 && handle->scenario < DDP_SCENARIO_MAX));
  376. DISP_MODULE_ENUM dst_module = ddp_get_dst_module(handle->scenario);
  377. DISP_LOG_I("get dst module on scenario %s, module %s\n",
  378. ddp_get_scenario_name(handle->scenario),ddp_get_module_name(dst_module));
  379. return dst_module;
  380. }
  381. int dpmgr_path_init(disp_path_handle dp_handle, int encmdq)
  382. {
  383. int i=0;
  384. int module_name ;
  385. ASSERT(dp_handle != NULL);
  386. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  387. int * modules = ddp_get_scenario_list(handle->scenario);
  388. int module_num = ddp_get_module_num(handle->scenario);
  389. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  390. DISP_LOG_I("path init on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  391. //open top clock
  392. ddp_path_top_clock_on();
  393. //turn off m4u
  394. ddp_path_m4u_off();
  395. //seting mutex
  396. ddp_mutex_set(handle->hwmutexid,
  397. handle->scenario,
  398. handle->mode,
  399. cmdqHandle);
  400. //connect path;
  401. ddp_connect_path(handle->scenario,cmdqHandle);
  402. // each module init
  403. for ( i=0; i< module_num; i++) {
  404. module_name = modules[i];
  405. if (ddp_modules_driver[module_name] != 0) {
  406. if (ddp_modules_driver[module_name]->init!= 0) {
  407. ddp_modules_driver[module_name]->init(module_name, cmdqHandle);
  408. }
  409. if (ddp_modules_driver[module_name]->set_listener!= 0) {
  410. ddp_modules_driver[module_name]->set_listener(module_name,dpmgr_module_notify);
  411. }
  412. }
  413. }
  414. //after init this path will power on;
  415. handle->power_sate = 1;
  416. return 0;
  417. }
  418. int dpmgr_path_deinit(disp_path_handle dp_handle, int encmdq)
  419. {
  420. int i=0;
  421. int module_name ;
  422. ASSERT(dp_handle != NULL);
  423. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  424. int * modules = ddp_get_scenario_list(handle->scenario);
  425. int module_num = ddp_get_module_num(handle->scenario);
  426. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  427. DISP_LOG_I("path deinit on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  428. ddp_mutex_clear(handle->hwmutexid,cmdqHandle);
  429. ddp_disconnect_path(handle->scenario, cmdqHandle);
  430. for ( i=0; i< module_num; i++) {
  431. module_name = modules[i];
  432. if (ddp_modules_driver[module_name] != 0) {
  433. if (ddp_modules_driver[module_name]->deinit!= 0) {
  434. ddp_modules_driver[module_name]->deinit(module_name, cmdqHandle);
  435. }
  436. if (ddp_modules_driver[module_name]->set_listener!= 0) {
  437. ddp_modules_driver[module_name]->set_listener(module_name,NULL);
  438. }
  439. }
  440. }
  441. handle->power_sate = 0;
  442. //close top clock when last path init
  443. path_top_clock_off();
  444. return 0;
  445. }
  446. int dpmgr_path_start(disp_path_handle dp_handle, int encmdq)
  447. {
  448. int i=0;
  449. int module_name ;
  450. ASSERT(dp_handle != NULL);
  451. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  452. int * modules = ddp_get_scenario_list(handle->scenario);
  453. int module_num = ddp_get_module_num(handle->scenario);
  454. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  455. DISP_LOG_I("path start on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  456. for ( i=0; i< module_num; i++) {
  457. module_name = modules[i];
  458. if (ddp_modules_driver[module_name] != 0) {
  459. if (ddp_modules_driver[module_name]->start!= 0) {
  460. ddp_modules_driver[module_name]->start(module_name, cmdqHandle);
  461. }
  462. }
  463. }
  464. return 0;
  465. }
  466. int dpmgr_path_stop(disp_path_handle dp_handle, int encmdq)
  467. {
  468. int i=0;
  469. int module_name ;
  470. ASSERT(dp_handle != NULL);
  471. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  472. int * modules = ddp_get_scenario_list(handle->scenario);
  473. int module_num = ddp_get_module_num(handle->scenario);
  474. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  475. DISP_LOG_I("path stop on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  476. for ( i=0; i< module_num; i++) {
  477. module_name = modules[i];
  478. if (ddp_modules_driver[module_name] != 0) {
  479. if (ddp_modules_driver[module_name]->stop!= 0) {
  480. ddp_modules_driver[module_name]->stop(module_name, cmdqHandle);
  481. }
  482. }
  483. }
  484. return 0;
  485. }
  486. int dpmgr_path_reset(disp_path_handle dp_handle, int encmdq)
  487. {
  488. int i=0;
  489. int module_name ;
  490. ASSERT(dp_handle != NULL);
  491. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  492. int * modules = ddp_get_scenario_list(handle->scenario);
  493. int module_num = ddp_get_module_num(handle->scenario);
  494. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  495. DISP_LOG_I("path reset on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  496. for ( i=0; i< module_num; i++) {
  497. module_name = modules[i];
  498. if (ddp_modules_driver[module_name] != 0) {
  499. if (ddp_modules_driver[module_name]->reset != 0) {
  500. ddp_modules_driver[module_name]->reset(module_name, cmdqHandle);
  501. }
  502. }
  503. }
  504. return 0;
  505. }
  506. int dpmgr_path_config(disp_path_handle dp_handle, disp_ddp_path_config * config, int encmdq)
  507. {
  508. int i=0;
  509. int module_name ;
  510. ASSERT(dp_handle != NULL);
  511. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  512. int * modules = ddp_get_scenario_list(handle->scenario);
  513. int module_num = ddp_get_module_num(handle->scenario);
  514. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  515. DISP_LOG_I("path config ovl %d, rdma %d, wdma %d, dst %d on handle 0x%x scenario %s \n",
  516. config->ovl_dirty,
  517. config->rdma_dirty,
  518. config->wdma_dirty,
  519. config->dst_dirty,
  520. (unsigned int)handle,
  521. ddp_get_scenario_name(handle->scenario));
  522. memcpy(&handle->last_config, config, sizeof(disp_ddp_path_config));
  523. for ( i=0; i< module_num; i++) {
  524. module_name = modules[i];
  525. if (ddp_modules_driver[module_name] != 0) {
  526. if (ddp_modules_driver[module_name]->config!= 0) {
  527. ddp_modules_driver[module_name]->config(module_name, config, cmdqHandle);
  528. }
  529. }
  530. }
  531. return 0;
  532. }
  533. disp_ddp_path_config *dpmgr_path_get_last_config(disp_path_handle dp_handle)
  534. {
  535. ASSERT(dp_handle != NULL);
  536. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  537. handle->last_config.ovl_dirty =0;
  538. handle->last_config.rdma_dirty =0;
  539. handle->last_config.wdma_dirty =0;
  540. handle->last_config.dst_dirty =0;
  541. return &handle->last_config;
  542. }
  543. int dpmgr_path_build_cmdq(disp_path_handle dp_handle, void *trigger_loop_handle, CMDQ_STATE state)
  544. {
  545. int i=0;
  546. int module_name ;
  547. ASSERT(dp_handle != NULL);
  548. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  549. int * modules = ddp_get_scenario_list(handle->scenario);
  550. int module_num = ddp_get_module_num(handle->scenario);
  551. DISP_LOG_D("path build cmdq on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  552. for ( i=0; i< module_num; i++) {
  553. module_name = modules[i];
  554. if (ddp_modules_driver[module_name] != 0) {
  555. if (ddp_modules_driver[module_name]->build_cmdq!= 0) {
  556. DISP_LOG_D("%s build cmdq, state=%d\n",ddp_get_module_name(module_name), state);
  557. ddp_modules_driver[module_name]->build_cmdq(module_name, trigger_loop_handle, state); // now just 0;
  558. }
  559. }
  560. }
  561. return 0;
  562. }
  563. int dpmgr_path_trigger(disp_path_handle dp_handle, void *trigger_loop_handle, int encmdq)
  564. {
  565. ASSERT(dp_handle != NULL);
  566. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  567. DISP_LOG_I("dpmgr_path_trigger on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  568. // if(trigger_loop_handle)
  569. //{
  570. // ddp_mutex_enable(handle->hwmutexid,handle->scenario,trigger_loop_handle);
  571. //}
  572. //else
  573. {
  574. int i=0;
  575. int * modules = ddp_get_scenario_list(handle->scenario);
  576. int module_num = ddp_get_module_num(handle->scenario);
  577. int module_name ;
  578. //if(encmdq == CMDQ_DISABLE)
  579. {
  580. ddp_mutex_enable(handle->hwmutexid,handle->scenario,trigger_loop_handle);
  581. }
  582. for ( i=0; i< module_num; i++) {
  583. module_name = modules[i];
  584. if (ddp_modules_driver[module_name] != 0) {
  585. if (ddp_modules_driver[module_name]->trigger!= 0) {
  586. ddp_modules_driver[module_name]->trigger(module_name, trigger_loop_handle);
  587. }
  588. }
  589. }
  590. }
  591. return 0;
  592. }
  593. int dpmgr_path_flush(disp_path_handle dp_handle,int encmdq)
  594. {
  595. ASSERT(dp_handle != NULL);
  596. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  597. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  598. DISP_LOG_I("path flush on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  599. return ddp_mutex_enable(handle->hwmutexid,handle->scenario,cmdqHandle);
  600. }
  601. int dpmgr_path_power_off(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
  602. {
  603. int i=0;
  604. int module_name ;
  605. ASSERT(dp_handle != NULL);
  606. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  607. int * modules = ddp_get_scenario_list(handle->scenario);
  608. int module_num = ddp_get_module_num(handle->scenario);
  609. DISP_LOG_I("path power off on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  610. for ( i=0; i< module_num; i++) {
  611. module_name = modules[i];
  612. if (ddp_modules_driver[module_name] != 0) {
  613. if (ddp_modules_driver[module_name]->power_off!= 0) {
  614. DISP_LOG_I(" %s power off\n",ddp_get_module_name(module_name));
  615. ddp_modules_driver[module_name]->power_off(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
  616. }
  617. }
  618. }
  619. handle->power_sate = 0;
  620. path_top_clock_off();
  621. return 0;
  622. }
  623. int dpmgr_path_power_on(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
  624. {
  625. int i=0;
  626. int module_name ;
  627. ASSERT(dp_handle != NULL);
  628. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  629. int * modules = ddp_get_scenario_list(handle->scenario);
  630. int module_num = ddp_get_module_num(handle->scenario);
  631. DISP_LOG_I("path power on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  632. path_top_clock_on();
  633. for ( i=0; i< module_num; i++) {
  634. module_name = modules[i];
  635. if (ddp_modules_driver[module_name] != 0) {
  636. if (ddp_modules_driver[module_name]->power_on!= 0) {
  637. DISP_LOG_I("%s power on\n",ddp_get_module_name(module_name));
  638. ddp_modules_driver[module_name]->power_on(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
  639. }
  640. }
  641. }
  642. //modules on this path will resume power on;
  643. handle->power_sate = 1;
  644. return 0;
  645. }
  646. int dpmgr_path_set_parameter(disp_path_handle dp_handle, int io_evnet, void * data)
  647. {
  648. return 0;
  649. }
  650. int dpmgr_path_get_parameter(disp_path_handle dp_handle,int io_evnet, void * data )
  651. {
  652. return 0;
  653. }
  654. int dpmgr_path_is_idle(disp_path_handle dp_handle)
  655. {
  656. ASSERT(dp_handle != NULL);
  657. return !dpmgr_path_is_busy(dp_handle);
  658. }
  659. int dpmgr_path_is_busy(disp_path_handle dp_handle)
  660. {
  661. int i=0;
  662. int module_name ;
  663. ASSERT(dp_handle != NULL);
  664. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  665. int * modules = ddp_get_scenario_list(handle->scenario);
  666. int module_num = ddp_get_module_num(handle->scenario);
  667. DISP_LOG_V("path check busy on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  668. for ( i=module_num-1; i>=0; i--) {
  669. module_name = modules[i];
  670. if (ddp_modules_driver[module_name] != 0) {
  671. if (ddp_modules_driver[module_name]->is_busy!= 0) {
  672. if (ddp_modules_driver[module_name]->is_busy(module_name)) {
  673. DISP_LOG_V("%s is busy\n", ddp_get_module_name(module_name));
  674. return 1;
  675. }
  676. }
  677. }
  678. }
  679. return 0;
  680. }
  681. int dpmgr_set_lcm_utils(disp_path_handle dp_handle, void *lcm_drv)
  682. {
  683. int i=0;
  684. int module_name ;
  685. ASSERT(dp_handle != NULL);
  686. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  687. int * modules = ddp_get_scenario_list(handle->scenario);
  688. int module_num = ddp_get_module_num(handle->scenario);
  689. DISP_LOG_V("path set lcm drv handle 0x%x\n",(unsigned int)handle);
  690. for ( i=0; i< module_num; i++) {
  691. module_name = modules[i];
  692. if (ddp_modules_driver[module_name] != 0) {
  693. if ((ddp_modules_driver[module_name]->set_lcm_utils!= 0)&&lcm_drv) {
  694. DISP_LOG_I("%s set lcm utils\n",ddp_get_module_name(module_name));
  695. ddp_modules_driver[module_name]->set_lcm_utils(module_name, lcm_drv); // now just 0;
  696. }
  697. }
  698. }
  699. return 0;
  700. }
  701. int dpmgr_enable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  702. {
  703. ASSERT(dp_handle != NULL);
  704. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  705. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  706. DISP_LOG_I("enable event on scenario %s, event %d, irtbit 0x%x\n",
  707. ddp_get_scenario_name(handle->scenario),
  708. event,
  709. handle->irq_event_map[event].irq_bit);
  710. if (!wq_handle->init) {
  711. //init_waitqueue_head(&(wq_handle->wq));
  712. wq_handle->init = 1;
  713. wq_handle->data= 0;
  714. wq_handle->event = event;
  715. }
  716. return 0;
  717. }
  718. int dpmgr_map_event_to_irq(disp_path_handle dp_handle, DISP_PATH_EVENT event, DDP_IRQ_BIT irq_bit)
  719. {
  720. ASSERT(dp_handle != NULL);
  721. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  722. DDP_IRQ_EVENT_MAPPING *irq_table = handle->irq_event_map;
  723. if (event < DISP_PATH_EVENT_NUM) {
  724. DISP_LOG_I("map event %d to irq 0x%x on scenario %s\n",event,irq_bit,ddp_get_scenario_name(handle->scenario));
  725. irq_table[event].irq_bit= irq_bit;
  726. return 0;
  727. }
  728. DISP_LOG_E("fail to map event %d to irq 0x%x on scenario %s\n",event,irq_bit,ddp_get_scenario_name(handle->scenario));
  729. return -1;
  730. }
  731. int dpmgr_disable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  732. {
  733. ASSERT(dp_handle != NULL);
  734. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  735. DISP_LOG_I("disable event %d on scenario %s \n",event,ddp_get_scenario_name(handle->scenario));
  736. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  737. wq_handle->init = 0;
  738. wq_handle->data= 0;
  739. return 0;
  740. }
  741. int dpmgr_check_status(disp_path_handle dp_handle)
  742. {
  743. int i =0;
  744. int module_name ;
  745. ASSERT(dp_handle != NULL);
  746. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  747. int * modules = ddp_get_scenario_list(handle->scenario);
  748. int module_num = ddp_get_module_num(handle->scenario);
  749. DISP_LOG_I("check status on scenario %s, module_num %d \n",
  750. ddp_get_scenario_name(handle->scenario),module_num);
  751. ddp_check_path(handle->scenario);
  752. ddp_check_mutex(handle->hwmutexid,handle->scenario,
  753. handle->mode);
  754. //ddp_check_signal(handle->scenario);
  755. for ( i=0; i< module_num; i++) {
  756. module_name = modules[i];
  757. ddp_dump_analysis(module_name);
  758. if (i == DISP_MODULE_DSI0 || i == DISP_MODULE_DSI1 || i == DISP_MODULE_DSIDUAL) {
  759. if (ddp_modules_driver[i] != 0) {
  760. if (ddp_modules_driver[i]->dump_info!= 0) {
  761. ddp_modules_driver[i]->dump_info(i, 1);
  762. }
  763. }
  764. }
  765. }
  766. ddp_dump_analysis(DISP_MODULE_CONFIG);
  767. ddp_dump_analysis(DISP_MODULE_MUTEX);
  768. for ( i=0; i< module_num; i++) {
  769. module_name = modules[i];
  770. ddp_dump_reg(module_name);
  771. }
  772. ddp_dump_reg(DISP_MODULE_CONFIG);
  773. ddp_dump_reg(DISP_MODULE_MUTEX);
  774. return 0;
  775. }
  776. int dpmgr_wait_event_timeout(disp_path_handle dp_handle, DISP_PATH_EVENT event, int timeout)
  777. {
  778. int ret = -1;
  779. ASSERT(dp_handle != NULL);
  780. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  781. DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
  782. DDP_IRQ_EVENT_MAPPING *irqmap = handle->irq_event_map;
  783. DISP_MODULE_ENUM module = IRQBIT_MODULE(irqmap[event].irq_bit);
  784. int q_bit = IRQBIT_BIT(irqmap[event].irq_bit);
  785. if (wq_handle->init) {
  786. //DISP_LOG_V("wait event %d timeout %d on scenario %s\n", event,timeout,ddp_get_scenario_name(handle->scenario));
  787. //should poling
  788. if (ddp_modules_driver[module] !=0 && ddp_modules_driver[module]->polling_irq != 0) {
  789. ret = ddp_modules_driver[module]->polling_irq(module,q_bit,timeout);
  790. }
  791. if (ret > 0) {
  792. //DISP_LOG_V("received event %d left time %d on scenario %s \n", event, ret,ddp_get_scenario_name(handle->scenario));
  793. } else {
  794. DISP_LOG_E("wait %d timeout ret %d on scenario %d \n", event,ret,handle->scenario);
  795. dpmgr_check_status(handle);
  796. }
  797. return ret;
  798. }
  799. DISP_LOG_E("wait event %d not initialized on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  800. return ret;
  801. }
  802. int dpmgr_wait_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  803. {
  804. int ret = -1;
  805. ASSERT(dp_handle != NULL);
  806. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  807. DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
  808. DDP_IRQ_EVENT_MAPPING *irqmap = handle->irq_event_map;
  809. DISP_MODULE_ENUM module = IRQBIT_MODULE(irqmap[event].irq_bit);
  810. int q_bit = IRQBIT_BIT(irqmap[event].irq_bit);
  811. if (wq_handle->init) {
  812. DISP_LOG_V("wait event %d on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  813. if (ddp_modules_driver[module] !=0 && ddp_modules_driver[module]->polling_irq != 0) {
  814. ret = ddp_modules_driver[module]->polling_irq(module,q_bit,-1);
  815. }
  816. DISP_LOG_V("received event %d on scenario %s \n", event, ddp_get_scenario_name(handle->scenario));
  817. return ret;
  818. }
  819. DISP_LOG_E("wait event %d not initialized on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  820. return ret;
  821. }
  822. int dpmgr_signal_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  823. {
  824. ASSERT(dp_handle != NULL);
  825. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  826. if (handle->wq_list[event].init) {
  827. //wq_handle->data = sched_clock();
  828. DISP_LOG_V("wake up evnet %d on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  829. //wake_up_interruptible(&(handle->wq_list[event].wq));
  830. }
  831. return 0;
  832. }
  833. static void dpmgr_irq_handler(DISP_MODULE_ENUM module,unsigned int regvalue)
  834. {
  835. int i = 0;
  836. int j = 0;
  837. int irq_bits_num =0;
  838. unsigned int irq_bit = 0;
  839. ddp_path_handle handle = NULL;
  840. DISP_PATH_EVENT event = DISP_PATH_EVENT_NONE;
  841. DISP_LOG_V("irq handler module %d, regvalue 0x%x\n", module,regvalue);
  842. handle = find_handle_by_module(module);
  843. if (handle == NULL) {
  844. return;
  845. }
  846. irq_bits_num = ddp_get_module_max_irq_bit(module);
  847. for (i = 0; i<=irq_bits_num; i++) {
  848. if (regvalue & (0x1<<i)) {
  849. irq_bit = (module<<16 | 0x1<<i);
  850. for (j = 0; j < DISP_PATH_EVENT_NUM; j++) {
  851. if (handle->wq_list[j].init && (irq_bit == handle->irq_event_map[j].irq_bit)) {
  852. //handle->wq_list[j].data =sched_clock();
  853. DISP_LOG_V("irq signal event %d on cycle %llu on scenario %s\n",
  854. event, handle->wq_list[j].data ,ddp_get_scenario_name(handle->scenario));
  855. //wake_up_interruptible(&(handle->wq_list[j].wq));
  856. }
  857. }
  858. }
  859. }
  860. return ;
  861. }
  862. int dpmgr_init(void)
  863. {
  864. DISP_LOG_I("ddp manager init\n");
  865. //return disp_register_irq_callback(dpmgr_irq_handler);
  866. return 0;
  867. }