ddp_manager.c 30 KB

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