ddp_manager.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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. //open top clock
  357. path_top_clock_on();
  358. //turn off m4u
  359. ddp_path_m4u_off();
  360. //init ddp_path structure
  361. ddp_path_init();
  362. /* now we start to init this path */
  363. //seting mutex
  364. ddp_mutex_set(handle->hwmutexid,
  365. handle->scenario,
  366. handle->mode,
  367. cmdqHandle);
  368. //connect path;
  369. _dpmgr_path_connect(handle->scenario, cmdqHandle);
  370. // each module init
  371. for (i=0; i< module_num; i++) {
  372. module_name = modules[i];
  373. if (ddp_modules_driver[module_name] != 0) {
  374. if (ddp_modules_driver[module_name]->init!= 0) {
  375. ddp_modules_driver[module_name]->init(module_name, cmdqHandle);
  376. }
  377. if (ddp_modules_driver[module_name]->set_listener!= 0) {
  378. ddp_modules_driver[module_name]->set_listener(module_name,dpmgr_module_notify);
  379. }
  380. }
  381. }
  382. //after init this path will power on;
  383. handle->power_sate = 1;
  384. return 0;
  385. }
  386. int dpmgr_path_deinit(disp_path_handle dp_handle, int encmdq)
  387. {
  388. int i=0;
  389. int module_name ;
  390. ASSERT(dp_handle != NULL);
  391. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  392. int * modules = ddp_get_scenario_list(handle->scenario);
  393. int module_num = ddp_get_module_num(handle->scenario);
  394. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  395. DISP_LOG_I("path deinit on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  396. ddp_mutex_clear(handle->hwmutexid,cmdqHandle);
  397. _dpmgr_path_disconnect(handle->scenario, cmdqHandle);
  398. for ( i=0; i< module_num; i++) {
  399. module_name = modules[i];
  400. if (ddp_modules_driver[module_name] != 0) {
  401. if (ddp_modules_driver[module_name]->deinit!= 0) {
  402. DISP_LOG_V("scenario %s deinit module %s\n",ddp_get_scenario_name(handle->scenario),
  403. ddp_get_module_name(module_name));
  404. ddp_modules_driver[module_name]->deinit(module_name, cmdqHandle);
  405. }
  406. if (ddp_modules_driver[module_name]->set_listener!= 0) {
  407. ddp_modules_driver[module_name]->set_listener(module_name,NULL);
  408. }
  409. }
  410. }
  411. handle->power_sate = 0;
  412. //close top clock when last path init
  413. path_top_clock_off();
  414. return 0;
  415. }
  416. int dpmgr_path_start(disp_path_handle dp_handle, int encmdq)
  417. {
  418. int i=0;
  419. int module_name;
  420. ASSERT(dp_handle != NULL);
  421. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  422. int *modules = ddp_get_scenario_list(handle->scenario);
  423. int module_num = ddp_get_module_num(handle->scenario);
  424. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  425. DISP_LOG_V("path start on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  426. for ( i=0; i< module_num; i++) {
  427. module_name = modules[i];
  428. if (ddp_modules_driver[module_name] != 0) {
  429. if (ddp_modules_driver[module_name]->start!= 0) {
  430. ddp_modules_driver[module_name]->start(module_name, cmdqHandle);
  431. }
  432. }
  433. }
  434. return 0;
  435. }
  436. int dpmgr_path_stop(disp_path_handle dp_handle, int encmdq)
  437. {
  438. int i=0;
  439. int module_name ;
  440. ASSERT(dp_handle != NULL);
  441. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  442. int * modules = ddp_get_scenario_list(handle->scenario);
  443. int module_num = ddp_get_module_num(handle->scenario);
  444. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  445. DISP_LOG_I("path stop on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  446. for ( i=0; i< module_num; i++) {
  447. module_name = modules[i];
  448. if (ddp_modules_driver[module_name] != 0) {
  449. if (ddp_modules_driver[module_name]->stop!= 0) {
  450. DISP_LOG_V("scenario %s stop module %s \n",ddp_get_scenario_name(handle->scenario),
  451. ddp_get_module_name(module_name));
  452. ddp_modules_driver[module_name]->stop(module_name, cmdqHandle);
  453. }
  454. }
  455. }
  456. return 0;
  457. }
  458. int dpmgr_path_reset(disp_path_handle dp_handle, int encmdq)
  459. {
  460. int i=0;
  461. int module_name ;
  462. ASSERT(dp_handle != NULL);
  463. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  464. int * modules = ddp_get_scenario_list(handle->scenario);
  465. int module_num = ddp_get_module_num(handle->scenario);
  466. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  467. DISP_LOG_I("path reset on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  468. for ( i=0; i< module_num; i++) {
  469. module_name = modules[i];
  470. if (ddp_modules_driver[module_name] != 0) {
  471. if (ddp_modules_driver[module_name]->reset != 0) {
  472. DISP_LOG_V("scenario %s reset module %s \n",ddp_get_scenario_name(handle->scenario),
  473. ddp_get_module_name(module_name));
  474. ddp_modules_driver[module_name]->reset(module_name, cmdqHandle);
  475. }
  476. }
  477. }
  478. return 0;
  479. }
  480. static unsigned int dpmgr_is_PQ(DISP_MODULE_ENUM module)
  481. {
  482. unsigned int isPQ = 0;
  483. switch (module) {
  484. case DISP_MODULE_COLOR0:
  485. case DISP_MODULE_CCORR0:
  486. case DISP_MODULE_AAL0:
  487. case DISP_MODULE_GAMMA0:
  488. case DISP_MODULE_DITHER0:
  489. isPQ = 1;
  490. break;
  491. default:
  492. isPQ = 0;
  493. }
  494. return isPQ;
  495. }
  496. int dpmgr_path_config(disp_path_handle dp_handle, disp_ddp_path_config *config, int encmdq)
  497. {
  498. int i=0;
  499. int module_name;
  500. ASSERT(dp_handle != NULL);
  501. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  502. int *modules = ddp_get_scenario_list(handle->scenario);
  503. int module_num = ddp_get_module_num(handle->scenario);
  504. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  505. DISP_LOG_V("path config ovl %d, rdma %d, wdma %d, dst %d on handle 0x%x scenario %s \n",
  506. config->ovl_dirty,
  507. config->rdma_dirty,
  508. config->wdma_dirty,
  509. config->dst_dirty,
  510. (unsigned int)handle,
  511. ddp_get_scenario_name(handle->scenario));
  512. memcpy(&handle->last_config, config, sizeof(disp_ddp_path_config));
  513. for (i=0; i< module_num; i++) {
  514. module_name = modules[i];
  515. if (ddp_modules_driver[module_name] != 0) {
  516. if (ddp_modules_driver[module_name]->config!= 0) {
  517. ddp_modules_driver[module_name]->config(module_name, config, cmdqHandle);
  518. }
  519. /* now all PQ modules are bypassed by itself in LK, don't need this, just for future using */
  520. if (dpmgr_is_PQ(module_name) == 1) {
  521. if (ddp_modules_driver[module_name]->bypass != NULL)
  522. ddp_modules_driver[module_name]->bypass(module_name, 1);
  523. }
  524. }
  525. }
  526. return 0;
  527. }
  528. disp_ddp_path_config *dpmgr_path_get_last_config(disp_path_handle dp_handle)
  529. {
  530. ASSERT(dp_handle != NULL);
  531. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  532. handle->last_config.ovl_dirty =0;
  533. handle->last_config.rdma_dirty =0;
  534. handle->last_config.wdma_dirty =0;
  535. handle->last_config.dst_dirty =0;
  536. return &handle->last_config;
  537. }
  538. int dpmgr_path_build_cmdq(disp_path_handle dp_handle, void *trigger_loop_handle, CMDQ_STATE state)
  539. {
  540. int i=0;
  541. int module_name ;
  542. ASSERT(dp_handle != NULL);
  543. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  544. int * modules = ddp_get_scenario_list(handle->scenario);
  545. int module_num = ddp_get_module_num(handle->scenario);
  546. DISP_LOG_D("path build cmdq on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  547. for ( i=0; i< module_num; i++) {
  548. module_name = modules[i];
  549. if (ddp_modules_driver[module_name] != 0) {
  550. if (ddp_modules_driver[module_name]->build_cmdq!= 0) {
  551. DISP_LOG_D("%s build cmdq, state=%d\n",ddp_get_module_name(module_name), state);
  552. ddp_modules_driver[module_name]->build_cmdq(module_name, trigger_loop_handle, state); // now just 0;
  553. }
  554. }
  555. }
  556. return 0;
  557. }
  558. int dpmgr_path_trigger(disp_path_handle dp_handle, void *trigger_loop_handle, int encmdq)
  559. {
  560. ASSERT(dp_handle != NULL);
  561. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  562. DISP_LOG_V("dpmgr_path_trigger on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  563. int i=0;
  564. int *modules = ddp_get_scenario_list(handle->scenario);
  565. int module_num = ddp_get_module_num(handle->scenario);
  566. int module_name;
  567. ddp_mutex_enable(handle->hwmutexid,handle->scenario,trigger_loop_handle);
  568. for (i=0; i< module_num; i++) {
  569. module_name = modules[i];
  570. if (ddp_modules_driver[module_name] != 0) {
  571. if (ddp_modules_driver[module_name]->trigger!= 0) {
  572. ddp_modules_driver[module_name]->trigger(module_name, trigger_loop_handle);
  573. }
  574. }
  575. }
  576. return 0;
  577. }
  578. int dpmgr_path_flush(disp_path_handle dp_handle,int encmdq)
  579. {
  580. ASSERT(dp_handle != NULL);
  581. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  582. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  583. DISP_LOG_I("path flush on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  584. return ddp_mutex_enable(handle->hwmutexid,handle->scenario,cmdqHandle);
  585. }
  586. int dpmgr_path_power_off(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
  587. {
  588. int i=0;
  589. int module_name ;
  590. ASSERT(dp_handle != NULL);
  591. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  592. int * modules = ddp_get_scenario_list(handle->scenario);
  593. int module_num = ddp_get_module_num(handle->scenario);
  594. DISP_LOG_I("path power off on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  595. for ( i=0; i< module_num; i++) {
  596. module_name = modules[i];
  597. if (ddp_modules_driver[module_name] != 0) {
  598. if (ddp_modules_driver[module_name]->power_off!= 0) {
  599. DISP_LOG_I(" %s power off\n",ddp_get_module_name(module_name));
  600. ddp_modules_driver[module_name]->power_off(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
  601. }
  602. }
  603. }
  604. handle->power_sate = 0;
  605. path_top_clock_off();
  606. return 0;
  607. }
  608. int dpmgr_path_power_on(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
  609. {
  610. int i=0;
  611. int module_name ;
  612. ASSERT(dp_handle != NULL);
  613. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  614. int * modules = ddp_get_scenario_list(handle->scenario);
  615. int module_num = ddp_get_module_num(handle->scenario);
  616. DISP_LOG_I("path power on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  617. path_top_clock_on();
  618. for ( i=0; i< module_num; i++) {
  619. module_name = modules[i];
  620. if (ddp_modules_driver[module_name] != 0) {
  621. if (ddp_modules_driver[module_name]->power_on!= 0) {
  622. DISP_LOG_I("%s power on\n",ddp_get_module_name(module_name));
  623. ddp_modules_driver[module_name]->power_on(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
  624. }
  625. }
  626. }
  627. //modules on this path will resume power on;
  628. handle->power_sate = 1;
  629. return 0;
  630. }
  631. int dpmgr_path_set_parameter(disp_path_handle dp_handle, int io_evnet, void * data)
  632. {
  633. return 0;
  634. }
  635. int dpmgr_path_get_parameter(disp_path_handle dp_handle,int io_evnet, void * data )
  636. {
  637. return 0;
  638. }
  639. int dpmgr_path_is_idle(disp_path_handle dp_handle)
  640. {
  641. ASSERT(dp_handle != NULL);
  642. return !dpmgr_path_is_busy(dp_handle);
  643. }
  644. int dpmgr_path_is_busy(disp_path_handle dp_handle)
  645. {
  646. int i=0;
  647. int module_name;
  648. ASSERT(dp_handle != NULL);
  649. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  650. int *modules = ddp_get_scenario_list(handle->scenario);
  651. int module_num = ddp_get_module_num(handle->scenario);
  652. DISP_LOG_V("path check busy on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  653. for (i=module_num-1; i>=0; i--) {
  654. module_name = modules[i];
  655. if (ddp_modules_driver[module_name] != 0) {
  656. if (ddp_modules_driver[module_name]->is_busy!= 0) {
  657. if (ddp_modules_driver[module_name]->is_busy(module_name)) {
  658. DISP_LOG_V("%s is busy\n", ddp_get_module_name(module_name));
  659. return 1;
  660. }
  661. }
  662. }
  663. }
  664. return 0;
  665. }
  666. int dpmgr_set_lcm_utils(disp_path_handle dp_handle, void *lcm_drv)
  667. {
  668. int i=0;
  669. int module_name;
  670. ASSERT(dp_handle != NULL);
  671. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  672. int *modules = ddp_get_scenario_list(handle->scenario);
  673. int module_num = ddp_get_module_num(handle->scenario);
  674. DISP_LOG_V("path set lcm drv handle 0x%x\n",(unsigned int)handle);
  675. for ( i=0; i< module_num; i++) {
  676. module_name = modules[i];
  677. if (ddp_modules_driver[module_name] != 0) {
  678. if ((ddp_modules_driver[module_name]->set_lcm_utils!= 0)&&lcm_drv) {
  679. DISP_LOG_I("%s set lcm utils\n",ddp_get_module_name(module_name));
  680. ddp_modules_driver[module_name]->set_lcm_utils(module_name, lcm_drv); // now just 0;
  681. }
  682. }
  683. }
  684. return 0;
  685. }
  686. int dpmgr_enable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  687. {
  688. ASSERT(dp_handle != NULL);
  689. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  690. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  691. DISP_LOG_I("enable event on scenario %s, event %d, irtbit 0x%x\n",
  692. ddp_get_scenario_name(handle->scenario),
  693. event,
  694. handle->irq_event_map[event].irq_bit);
  695. if (!wq_handle->init) {
  696. //init_waitqueue_head(&(wq_handle->wq));
  697. wq_handle->init = 1;
  698. wq_handle->data= 0;
  699. wq_handle->event = event;
  700. }
  701. return 0;
  702. }
  703. int dpmgr_map_event_to_irq(disp_path_handle dp_handle, DISP_PATH_EVENT event, DDP_IRQ_BIT irq_bit)
  704. {
  705. ASSERT(dp_handle != NULL);
  706. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  707. DDP_IRQ_EVENT_MAPPING *irq_table = handle->irq_event_map;
  708. if (event < DISP_PATH_EVENT_NUM) {
  709. DISP_LOG_I("map event %d to irq 0x%x on scenario %s\n",event,irq_bit,ddp_get_scenario_name(handle->scenario));
  710. irq_table[event].irq_bit= irq_bit;
  711. return 0;
  712. }
  713. 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));
  714. return -1;
  715. }
  716. int dpmgr_disable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  717. {
  718. ASSERT(dp_handle != NULL);
  719. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  720. DISP_LOG_I("disable event %d on scenario %s \n",event,ddp_get_scenario_name(handle->scenario));
  721. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  722. wq_handle->init = 0;
  723. wq_handle->data= 0;
  724. return 0;
  725. }
  726. int dpmgr_check_status(disp_path_handle dp_handle)
  727. {
  728. int i =0;
  729. int module_name ;
  730. ASSERT(dp_handle != NULL);
  731. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  732. int * modules = ddp_get_scenario_list(handle->scenario);
  733. int module_num = ddp_get_module_num(handle->scenario);
  734. DISP_LOG_I("check status on scenario %s, module_num %d \n",
  735. ddp_get_scenario_name(handle->scenario),module_num);
  736. ddp_check_path(handle->scenario);
  737. ddp_check_mutex(handle->hwmutexid,handle->scenario,
  738. handle->mode);
  739. //ddp_check_signal(handle->scenario);
  740. for ( i=0; i< module_num; i++) {
  741. module_name = modules[i];
  742. ddp_dump_analysis(module_name);
  743. if (i == DISP_MODULE_DSI0 || i == DISP_MODULE_DSI1 || i == DISP_MODULE_DSIDUAL) {
  744. if (ddp_modules_driver[i] != 0) {
  745. if (ddp_modules_driver[i]->dump_info!= 0) {
  746. ddp_modules_driver[i]->dump_info(i, 1);
  747. }
  748. }
  749. }
  750. }
  751. ddp_dump_analysis(DISP_MODULE_CONFIG);
  752. ddp_dump_analysis(DISP_MODULE_MUTEX);
  753. for ( i=0; i< module_num; i++) {
  754. module_name = modules[i];
  755. ddp_dump_reg(module_name);
  756. }
  757. ddp_dump_reg(DISP_MODULE_CONFIG);
  758. ddp_dump_reg(DISP_MODULE_MUTEX);
  759. return 0;
  760. }
  761. int dpmgr_wait_event_timeout(disp_path_handle dp_handle, DISP_PATH_EVENT event, int timeout)
  762. {
  763. int ret = -1;
  764. ASSERT(dp_handle != NULL);
  765. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  766. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  767. DDP_IRQ_EVENT_MAPPING *irqmap = handle->irq_event_map;
  768. DISP_MODULE_ENUM module = IRQBIT_MODULE(irqmap[event].irq_bit);
  769. int q_bit = IRQBIT_BIT(irqmap[event].irq_bit);
  770. if (wq_handle->init) {
  771. //DISP_LOG_V("wait event %d timeout %d on scenario %s\n", event,timeout,ddp_get_scenario_name(handle->scenario));
  772. //should poling
  773. if (ddp_modules_driver[module] !=0 && ddp_modules_driver[module]->polling_irq != 0) {
  774. ret = ddp_modules_driver[module]->polling_irq(module, q_bit, timeout);
  775. }
  776. if (ret > 0) {
  777. //DISP_LOG_V("received event %d left time %d on scenario %s \n", event, ret,ddp_get_scenario_name(handle->scenario));
  778. } else {
  779. DISP_LOG_E("wait %d timeout ret %d on scenario %d \n", event, ret, handle->scenario);
  780. dpmgr_check_status(handle);
  781. }
  782. return ret;
  783. }
  784. DISP_LOG_E("wait event %d not initialized on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  785. return ret;
  786. }
  787. int dpmgr_wait_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  788. {
  789. int ret = -1;
  790. ASSERT(dp_handle != NULL);
  791. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  792. DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
  793. DDP_IRQ_EVENT_MAPPING *irqmap = handle->irq_event_map;
  794. DISP_MODULE_ENUM module = IRQBIT_MODULE(irqmap[event].irq_bit);
  795. int q_bit = IRQBIT_BIT(irqmap[event].irq_bit);
  796. if (wq_handle->init) {
  797. DISP_LOG_V("wait event %d on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  798. if (ddp_modules_driver[module] !=0 && ddp_modules_driver[module]->polling_irq != 0) {
  799. ret = ddp_modules_driver[module]->polling_irq(module,q_bit,-1);
  800. }
  801. DISP_LOG_V("received event %d on scenario %s \n", event, ddp_get_scenario_name(handle->scenario));
  802. return ret;
  803. }
  804. DISP_LOG_E("wait event %d not initialized on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  805. return ret;
  806. }
  807. int dpmgr_signal_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  808. {
  809. ASSERT(dp_handle != NULL);
  810. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  811. if (handle->wq_list[event].init) {
  812. //wq_handle->data = sched_clock();
  813. DISP_LOG_V("wake up evnet %d on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  814. //wake_up_interruptible(&(handle->wq_list[event].wq));
  815. }
  816. return 0;
  817. }
  818. int dpmgr_init(void)
  819. {
  820. DISP_LOG_I("ddp manager init\n");
  821. ddp_init_modules_driver();
  822. return 0;
  823. }