mt_disp_drv.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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. #include <string.h>
  32. #include <stdlib.h>
  33. #include <video_fb.h>
  34. #include <libfdt.h>
  35. #include <platform/disp_drv_platform.h>
  36. #include <target/board.h>
  37. #include <env.h>
  38. #include "lcm_drv.h"
  39. #include <platform/mt_gpt.h>
  40. #include <platform/primary_display.h>
  41. #include <arch/arm/mmu.h>
  42. #include <platform/disp_drv_log.h>
  43. #include "memory_layout.h"
  44. #include <platform/boot_mode.h>
  45. #include <pal_log.h>
  46. //#define DFO_DISP
  47. #define FB_LAYER 0
  48. #if defined(MTK_ROUND_CORNER_SUPPORT) && !defined(DISP_HW_RC)
  49. # define BOOT_MENU_LAYER 1
  50. # define TOP_LAYER 2
  51. # define BOTTOM_LAYER 3
  52. #else
  53. # define BOOT_MENU_LAYER 3
  54. #endif
  55. unsigned long long fb_addr_pa_k = 0;
  56. static void *fb_addr_pa = NULL;
  57. static void *fb_addr = NULL;
  58. static void *logo_db_addr = NULL;
  59. static void *logo_db_addr_pa = NULL;
  60. static UINT32 fb_size = 0;
  61. static UINT32 fb_offset_logo = 0; // counter of fb_size
  62. static UINT32 fb_isdirty = 0;
  63. static UINT32 redoffset_32bit = 1; // ABGR
  64. #if (MTK_DUAL_DISPLAY_SUPPORT == 2)
  65. unsigned long long ext_fb_addr_pa_k = 0;
  66. static void *ext_fb_addr_pa = NULL;
  67. static void *ext_fb_addr = NULL;
  68. static void *ext_logo_db_addr = NULL;
  69. static void *ext_logo_db_addr_pa = NULL;
  70. static UINT32 ext_fb_size = 0;
  71. static UINT32 ext_fb_offset_logo = 0; // counter of fb_size
  72. static UINT32 ext_fb_isdirty = 0;
  73. #endif
  74. extern LCM_PARAMS *lcm_params;
  75. extern void disp_log_enable(int enable);
  76. extern void dbi_log_enable(int enable);
  77. extern void * memset(void *,int,unsigned int);
  78. extern void arch_clean_cache_range(addr_t start, size_t len);
  79. extern UINT32 memory_size(void);
  80. UINT32 mt_disp_get_vram_size(void)
  81. {
  82. return DISP_GetVRamSize();
  83. }
  84. #if (MTK_DUAL_DISPLAY_SUPPORT == 2)
  85. UINT32 mt_disp_get_ext_vram_size(void)
  86. {
  87. return EXT_DISP_GetVRamSize();
  88. }
  89. #endif
  90. #ifdef DFO_DISP
  91. static disp_dfo_item_t disp_dfo_setting[] = {
  92. {"LCM_FAKE_WIDTH", 0},
  93. {"LCM_FAKE_HEIGHT", 0},
  94. {"DISP_DEBUG_SWITCH", 0}
  95. };
  96. #define MT_DISP_DFO_DEBUG
  97. #ifdef MT_DISP_DFO_DEBUG
  98. #define disp_dfo_printf(string, args...) dprintf(INFO,"[DISP_DFO]"string, ##args)
  99. #else
  100. #define disp_dfo_printf(string, args...) ()
  101. #endif
  102. unsigned int mt_disp_parse_dfo_setting(void)
  103. {
  104. unsigned int i, j=0 ;
  105. char tmp[11];
  106. char *buffer = NULL;
  107. char *ptr = NULL;
  108. buffer = (char *)get_env("DFO");
  109. disp_dfo_printf("env buffer = %s\n", buffer);
  110. if (buffer != NULL) {
  111. for (i = 0; i< (sizeof(disp_dfo_setting)/sizeof(disp_dfo_item_t)); i++) {
  112. j = 0;
  113. memset((void*)tmp, 0, sizeof(tmp)/sizeof(tmp[0]));
  114. ptr = strstr(buffer, disp_dfo_setting[i].name);
  115. if (ptr == NULL) continue;
  116. disp_dfo_printf("disp_dfo_setting[%d].name = [%s]\n", i, ptr);
  117. do {} while ((*ptr++) != ',');
  118. do {tmp[j++] = *ptr++;}
  119. while (*ptr != ',' && j < sizeof(tmp)/sizeof(tmp[0]));
  120. disp_dfo_setting[i].value = atoi((const char*)tmp);
  121. disp_dfo_printf("disp_dfo_setting[%d].name = [%s|%d]\n", i, tmp, disp_dfo_setting[i].value);
  122. }
  123. } else {
  124. disp_dfo_printf("env buffer = NULL\n");
  125. }
  126. return 0;
  127. }
  128. int mt_disp_get_dfo_setting(const char *string, unsigned int *value)
  129. {
  130. char *disp_name;
  131. int disp_value;
  132. unsigned int i = 0;
  133. if (string == NULL)
  134. return -1;
  135. for (i=0; i<(sizeof(disp_dfo_setting)/sizeof(disp_dfo_item_t)); i++) {
  136. disp_name = disp_dfo_setting[i].name;
  137. disp_value = disp_dfo_setting[i].value;
  138. if (!strcmp(disp_name, string)) {
  139. *value = disp_value;
  140. disp_dfo_printf("%s = [DEC]%d [HEX]0x%08x\n", disp_name, disp_value, disp_value);
  141. return 0;
  142. }
  143. }
  144. return 0;
  145. }
  146. #endif
  147. static void _mtkfb_draw_block(unsigned int addr, unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int color)
  148. {
  149. unsigned int i = 0;
  150. unsigned int j = 0;
  151. void* start_addr = (void*)(addr+ALIGN_TO(CFG_DISPLAY_WIDTH, MTK_FB_ALIGNMENT)*4*y+x*4);
  152. unsigned int pitch = ALIGN_TO(CFG_DISPLAY_WIDTH, MTK_FB_ALIGNMENT)*4;
  153. unsigned int* line_addr = start_addr;
  154. for (j=0; j<h; j++) {
  155. line_addr = start_addr;
  156. for (i = 0; i<w; i++) {
  157. line_addr[i] = color;
  158. }
  159. start_addr += pitch;
  160. }
  161. }
  162. static int _mtkfb_internal_test(unsigned int va, unsigned int w, unsigned int h)
  163. {
  164. /* this is for debug, used in bring up day */
  165. unsigned int i = 0;
  166. unsigned int color = 0;
  167. int _internal_test_block_size = 120;
  168. for (i = 0; i < w * h / _internal_test_block_size / _internal_test_block_size; i++) {
  169. color = (i & 0x1) * 0xff;
  170. color += 0xff000000U;
  171. _mtkfb_draw_block(va,
  172. i % (w / _internal_test_block_size) * _internal_test_block_size,
  173. i / (w / _internal_test_block_size) * _internal_test_block_size,
  174. _internal_test_block_size, _internal_test_block_size, color);
  175. }
  176. primary_display_trigger(1);
  177. return 0;
  178. }
  179. static int _mtkfb_internal_test2()
  180. {
  181. /* this is for debug, used in bring up day */
  182. unsigned int i = 0;
  183. unsigned int color;
  184. unsigned int bar_num=16;
  185. unsigned int bar_size;
  186. bar_size = fb_size / bar_num;
  187. for (i = 0; i < bar_num; i++) {
  188. color = i%2 ? 0 : 0xff;
  189. memset(fb_addr + i * bar_size, color, bar_size);
  190. }
  191. primary_display_trigger(1);
  192. return 0;
  193. }
  194. #if (MTK_DUAL_DISPLAY_SUPPORT == 2)
  195. static void _ext_mtkfb_draw_block(unsigned int addr, unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int color)
  196. {
  197. int i = 0;
  198. int j = 0;
  199. void* start_addr = addr+ALIGN_TO(CFG_EXT_DISPLAY_WIDTH, MTK_FB_ALIGNMENT)*4*y+x*4;
  200. unsigned int pitch = ALIGN_TO(CFG_EXT_DISPLAY_WIDTH, MTK_FB_ALIGNMENT)*4;
  201. unsigned int* line_addr = start_addr;
  202. for (j=0; j<h; j++) {
  203. line_addr = start_addr;
  204. for (i = 0; i<w; i++) {
  205. line_addr[i] = color;
  206. }
  207. start_addr += pitch;
  208. }
  209. }
  210. static int _ext_mtkfb_internal_test(unsigned int va, unsigned int w, unsigned int h)
  211. {
  212. /* this is for debug, used in bring up day */
  213. unsigned int i = 0;
  214. unsigned int color = 0;
  215. int _internal_test_block_size = 120;
  216. for (i = 0; i < w * h / _internal_test_block_size / _internal_test_block_size; i++) {
  217. color = (i & 0x1) * 0xff;
  218. color += 0xff000000U;
  219. _mtkfb_draw_block(va,
  220. i % (w / _internal_test_block_size) * _internal_test_block_size,
  221. i / (w / _internal_test_block_size) * _internal_test_block_size,
  222. _internal_test_block_size, _internal_test_block_size, color);
  223. }
  224. arch_clean_cache_range((unsigned int)ext_fb_addr, EXT_DISP_GetFBRamSize());
  225. external_display_trigger(1);
  226. return 0;
  227. }
  228. static int _ext_mtkfb_internal_test2()
  229. {
  230. /* this is for debug, used in bring up day */
  231. unsigned int i = 0;
  232. unsigned int color;
  233. int bar_num=16;
  234. unsigned int bar_size;
  235. bar_size = ext_fb_size / bar_num;
  236. for (i = 0; i < bar_num; i++) {
  237. color = i%2 ? 0 : 0xff;
  238. memset(ext_fb_addr + i * bar_size, color, bar_size);
  239. }
  240. arch_clean_cache_range((unsigned int)ext_fb_addr, EXT_DISP_GetFBRamSize());
  241. external_display_trigger(1);
  242. return 0;
  243. }
  244. #endif
  245. #if defined(MTK_ROUND_CORNER_SUPPORT) && !defined(DISP_HW_RC)
  246. void assemble_image(void *dst, void *left, void *right, int h, int picture_w, int w)
  247. {
  248. int i = 0;
  249. for (i = 0; i < h; i++) {
  250. memcpy(dst+picture_w*i*2, left+2*w*i, w*2);
  251. memcpy(dst+(picture_w*(i+1)-w)*2, right+2*w*i, w*2);
  252. }
  253. }
  254. int round_corner_init(unsigned int *top_pa, unsigned int *bottom_pa, LCM_ROUND_CORNER *rc_params)
  255. {
  256. unsigned int h = rc_params->h;
  257. unsigned int w = rc_params->w;
  258. unsigned int pitch = DISP_GetScreenWidth();
  259. unsigned char *left_top = rc_params->lt_addr;
  260. unsigned char *left_bottom = rc_params->lb_addr;
  261. unsigned char *right_top = rc_params->rt_addr;
  262. unsigned char *right_bottom = rc_params->rb_addr;
  263. unsigned int buf_size = 0;
  264. static void *top_addr_va = NULL;
  265. static void *bottom_addr_va = NULL;
  266. if (h == 0 || w == 0 || left_top == NULL || left_bottom == NULL
  267. || right_top == NULL || right_bottom == NULL) {
  268. dprintf(CRITICAL, "the round corner params is invalid, please check the lcm config\n");
  269. return -1;
  270. }
  271. buf_size = h * pitch * 2;
  272. *top_pa = (unsigned int)(fb_addr_pa + DISP_GetVRamSize() - 2 * buf_size);
  273. top_addr_va = fb_addr + DISP_GetVRamSize() - 2 * buf_size;
  274. dprintf(INFO,"top_addr_va: 0x%08x, top_pa: 0x%08x\n", (unsigned int)top_addr_va, *top_pa);
  275. *bottom_pa = (unsigned int)(fb_addr_pa + DISP_GetVRamSize() - buf_size);
  276. bottom_addr_va = fb_addr + DISP_GetVRamSize() - buf_size;
  277. dprintf(INFO,"bottom_addr_va: 0x%08x, bottom_pa: 0x%08x\n", (unsigned int)bottom_addr_va, *bottom_pa);
  278. assemble_image((void *)top_addr_va, (void *)left_top, (void *)right_top, h, pitch, w);
  279. assemble_image((void *)bottom_addr_va, (void *)left_bottom, (void *)right_bottom, h, pitch, w);
  280. return 0;
  281. }
  282. #endif
  283. void mt_disp_init(void *lcdbase)
  284. {
  285. UINT32 boot_mode_addr = 0;
  286. #if defined(MTK_ROUND_CORNER_SUPPORT) && !defined(DISP_HW_RC)
  287. int ret = -1;
  288. unsigned int top_addr_pa = 0;
  289. unsigned int bottom_addr_pa = 0;
  290. LCM_ROUND_CORNER *round_corner = primary_display_get_corner_params();
  291. #endif
  292. /// fb base pa and va
  293. fb_addr_pa_k = arm_mmu_va2pa((unsigned int)lcdbase);
  294. fb_addr_pa = (void *)(unsigned int)(fb_addr_pa_k & 0xffffffffull);
  295. fb_addr = lcdbase;
  296. dprintf(0,"fb_va: 0x%08x, fb_pa: 0x%08x, fb_pa_k: 0x%llx\n", (unsigned int)fb_addr, (unsigned int)fb_addr_pa, fb_addr_pa_k);
  297. fb_size = ALIGN_TO(CFG_DISPLAY_WIDTH, MTK_FB_ALIGNMENT) * ALIGN_TO(CFG_DISPLAY_HEIGHT, MTK_FB_ALIGNMENT) * CFG_DISPLAY_BPP / 8;
  298. // pa;
  299. boot_mode_addr = ((UINT32)fb_addr_pa + fb_size);
  300. logo_db_addr_pa = (void *)(u32)mblock_reserve_ext(&g_boot_arg->mblock_info,
  301. LK_LOGO_MAX_SIZE, PAGE_SIZE, 0x80000000, 0, "logo_db_addr_pa");
  302. if (!logo_db_addr_pa) {
  303. pal_log_err("Warning! logo_db_addr_pa is not taken from mb\n");
  304. assert(0);
  305. }
  306. // va;
  307. logo_db_addr = logo_db_addr_pa;
  308. fb_offset_logo = 0;
  309. primary_display_init(NULL);
  310. memset((void*)lcdbase, 0x0, DISP_GetVRamSize());
  311. disp_input_config input;
  312. #if defined(MTK_ROUND_CORNER_SUPPORT) && !defined(DISP_HW_RC)
  313. if (round_corner->round_corner_en) {
  314. if (round_corner != NULL)
  315. ret = round_corner_init(&top_addr_pa, &bottom_addr_pa, round_corner);
  316. if (ret == 0) {
  317. memset(&input, 0, sizeof(input));
  318. input.layer = TOP_LAYER;
  319. input.layer_en = 1;
  320. input.fmt = eRGBA4444;
  321. input.addr = top_addr_pa;
  322. input.src_x = 0;
  323. input.src_y = 0;
  324. input.src_w = CFG_DISPLAY_WIDTH;
  325. input.src_h = round_corner->h;
  326. input.src_pitch = CFG_DISPLAY_WIDTH*2;
  327. input.dst_x = 0;
  328. input.dst_y = 0;
  329. input.dst_w = CFG_DISPLAY_WIDTH;
  330. input.dst_h = round_corner->h;
  331. input.aen = 1;
  332. input.alpha = 0xff;
  333. primary_display_config_input(&input);
  334. memset(&input, 0, sizeof(input));
  335. input.layer = BOTTOM_LAYER;
  336. input.layer_en = 1;
  337. input.fmt = eRGBA4444;
  338. input.addr = bottom_addr_pa;
  339. input.src_x = 0;
  340. input.src_y = 0;
  341. input.src_w = CFG_DISPLAY_WIDTH;
  342. input.src_h = round_corner->h;
  343. input.src_pitch = CFG_DISPLAY_WIDTH*2;
  344. input.dst_x = 0;
  345. input.dst_y = CFG_DISPLAY_HEIGHT-round_corner->h;
  346. input.dst_w = CFG_DISPLAY_WIDTH;
  347. input.dst_h = round_corner->h;
  348. input.aen = 1;
  349. input.alpha = 0xff;
  350. primary_display_config_input(&input);
  351. }
  352. }
  353. #endif
  354. memset(&input, 0, sizeof(disp_input_config));
  355. input.layer = BOOT_MENU_LAYER;
  356. input.layer_en = 1;
  357. input.fmt = redoffset_32bit ? eBGRA8888 : eRGBA8888;
  358. input.addr = boot_mode_addr;
  359. input.src_x = 0;
  360. input.src_y = 0;
  361. input.src_w = CFG_DISPLAY_WIDTH;
  362. input.src_h = CFG_DISPLAY_HEIGHT;
  363. input.src_pitch = CFG_DISPLAY_WIDTH*4;
  364. input.dst_x = 0;
  365. input.dst_y = 0;
  366. input.dst_w = CFG_DISPLAY_WIDTH;
  367. input.dst_h = CFG_DISPLAY_HEIGHT;
  368. input.aen = 1;
  369. input.alpha = 0xff;
  370. primary_display_config_input(&input);
  371. memset(&input, 0, sizeof(disp_input_config));
  372. input.layer = FB_LAYER;
  373. input.layer_en = 1;
  374. input.fmt = redoffset_32bit ? eBGRA8888 : eRGBA8888;
  375. input.addr = (unsigned int)fb_addr_pa;
  376. input.src_x = 0;
  377. input.src_y = 0;
  378. input.src_w = CFG_DISPLAY_WIDTH;
  379. input.src_h = CFG_DISPLAY_HEIGHT;
  380. input.src_pitch = ALIGN_TO(CFG_DISPLAY_WIDTH, MTK_FB_ALIGNMENT)*4;
  381. input.dst_x = 0;
  382. input.dst_y = 0;
  383. input.dst_w = CFG_DISPLAY_WIDTH;
  384. input.dst_h = CFG_DISPLAY_HEIGHT;
  385. input.aen = 1;
  386. input.alpha = 0xff;
  387. primary_display_config_input(&input);
  388. #if 0
  389. /* debug for bringup */
  390. dprintf(CRITICAL, "display show background\n");
  391. primary_display_trigger(TRUE);
  392. mdelay(100);
  393. primary_display_diagnose();
  394. /*
  395. while(1) {
  396. primary_display_trigger(TRUE);
  397. if (!primary_display_is_video_mode()) {
  398. dprintf(CRITICAL,"cmd mode trigger wait\n");
  399. mdelay(100);
  400. }
  401. primary_display_diagnose();
  402. }
  403. */
  404. dprintf(CRITICAL, "display internal test\n");
  405. _mtkfb_internal_test2(fb_addr, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  406. mdelay(100);
  407. primary_display_diagnose();
  408. #endif
  409. #ifdef DFO_DISP
  410. unsigned int lcm_fake_width = 0;
  411. unsigned int lcm_fake_height = 0;
  412. mt_disp_parse_dfo_setting();
  413. if ((0 == mt_disp_get_dfo_setting("LCM_FAKE_WIDTH", &lcm_fake_width)) && (0 == mt_disp_get_dfo_setting("LCM_FAKE_HEIGHT", &lcm_fake_height))) {
  414. if (DISP_STATUS_OK != DISP_Change_LCM_Resolution(lcm_fake_width, lcm_fake_height)) {
  415. dprintf(INFO,"[DISP_DFO]WARNING!!! Change LCM Resolution FAILED!!!\n");
  416. }
  417. }
  418. #endif
  419. DISPMSG("mt_disp_init() done\n");
  420. }
  421. #if (MTK_DUAL_DISPLAY_SUPPORT == 2)
  422. void mt_ext_disp_init(void *lcdbase)
  423. {
  424. UINT32 ext_boot_mode_addr = 0;
  425. /// fb base pa and va
  426. ext_fb_addr_pa_k = arm_mmu_va2pa(lcdbase);
  427. ext_fb_addr_pa = ext_fb_addr_pa_k & 0xffffffffull;
  428. ext_fb_addr = lcdbase;
  429. dprintf(0,"ext_fb_va: 0x%08x, ext_fb_pa: 0x%08x, ext_fb_pa_k: 0x%llx\n", ext_fb_addr, ext_fb_addr_pa, ext_fb_addr_pa_k);
  430. ext_fb_size = ALIGN_TO(CFG_EXT_DISPLAY_WIDTH, MTK_FB_ALIGNMENT) * ALIGN_TO(CFG_EXT_DISPLAY_HEIGHT, MTK_FB_ALIGNMENT) * CFG_EXT_DISPLAY_BPP / 8;
  431. // pa;
  432. ext_boot_mode_addr = ((UINT32)ext_fb_addr_pa + ext_fb_size);
  433. //ext_logo_db_addr_pa = (void *)((UINT32) SCRATCH_ADDR + SCRATCH_SIZE);
  434. // va;
  435. //ext_logo_db_addr = (void *)((UINT32) SCRATCH_ADDR + SCRATCH_SIZE);
  436. ext_fb_offset_logo = 0;
  437. external_display_init(NULL);
  438. memset((void*)lcdbase, 0x0, EXT_DISP_GetVRamSize());
  439. disp_input_config ext_input;
  440. memset(&ext_input, 0, sizeof(disp_input_config));
  441. ext_input.layer = BOOT_MENU_LAYER;
  442. ext_input.layer_en = 1;
  443. ext_input.fmt = redoffset_32bit ? eBGRA8888 : eRGBA8888;
  444. ext_input.addr = ext_boot_mode_addr;
  445. ext_input.src_x = 0;
  446. ext_input.src_y = 0;
  447. ext_input.src_w = CFG_EXT_DISPLAY_WIDTH;
  448. ext_input.src_h = CFG_EXT_DISPLAY_HEIGHT;
  449. ext_input.src_pitch = CFG_EXT_DISPLAY_WIDTH*4;
  450. ext_input.dst_x = 0;
  451. ext_input.aen = 1;
  452. ext_input.alpha = 0xff;
  453. external_display_config_input(&ext_input);
  454. memset(&ext_input, 0, sizeof(disp_input_config));
  455. ext_input.layer = FB_LAYER;
  456. ext_input.layer_en = 1;
  457. ext_input.fmt = redoffset_32bit ? eBGRA8888 : eRGBA8888;
  458. ext_input.addr = ext_fb_addr_pa;
  459. ext_input.src_x = 0;
  460. ext_input.src_y = 0;
  461. ext_input.src_w = CFG_EXT_DISPLAY_WIDTH;
  462. ext_input.src_h = CFG_EXT_DISPLAY_HEIGHT;
  463. ext_input.src_pitch = ALIGN_TO(CFG_EXT_DISPLAY_WIDTH, MTK_FB_ALIGNMENT)*4;
  464. ext_input.dst_x = 0;
  465. ext_input.dst_y = 0;
  466. ext_input.dst_w = CFG_EXT_DISPLAY_WIDTH;
  467. ext_input.dst_h = CFG_EXT_DISPLAY_HEIGHT;
  468. ext_input.aen = 1;
  469. ext_input.alpha = 0xff;
  470. external_display_config_input(&ext_input);
  471. /* external internal test */
  472. #if 1
  473. dprintf(CRITICAL, "external display internal test\n");
  474. /* _ext_mtkfb_internal_test(ext_fb_addr, CFG_EXT_DISPLAY_WIDTH, CFG_EXT_DISPLAY_HEIGHT); */
  475. _ext_mtkfb_internal_test2();
  476. #endif
  477. DISPMSG("mt_ext_disp_init() done\n");
  478. }
  479. void mt_ext_disp_deinit(void)
  480. {
  481. external_display_suspend();
  482. }
  483. #endif
  484. void mt_disp_power(BOOL on)
  485. {
  486. dprintf(0,"mt_disp_power %d\n",on);
  487. return;
  488. }
  489. void mt_free_logo_from_mblock(void)
  490. {
  491. if (logo_db_addr_pa) {
  492. mblock_create(&g_boot_arg->mblock_info,
  493. &g_boot_arg->orig_dram_info,
  494. (u64)(unsigned long)logo_db_addr_pa, (u64)(LK_LOGO_MAX_SIZE));
  495. logo_db_addr_pa = NULL;
  496. logo_db_addr = NULL;
  497. }
  498. }
  499. void* mt_get_logo_db_addr(void)
  500. {
  501. dprintf(0,"mt_get_logo_db_addr: 0x%08x\n",(unsigned int)logo_db_addr);
  502. return logo_db_addr;
  503. }
  504. void* mt_get_logo_db_addr_pa(void)
  505. {
  506. dprintf(0,"mt_get_logo_db_addr_pa: 0x%08x\n",(unsigned int)logo_db_addr_pa);
  507. return logo_db_addr_pa;
  508. }
  509. void* mt_get_fb_addr(void)
  510. {
  511. fb_isdirty = 1;
  512. return (void*)((UINT32)fb_addr + fb_offset_logo * fb_size);
  513. }
  514. void* mt_get_tempfb_addr(void)
  515. {
  516. //use offset = 2 as tempfb for decompress logo
  517. dprintf(0,"mt_get_tempfb_addr: 0x%08x ,fb_addr 0x%08x\n",(unsigned int)((UINT32)fb_addr + 2*fb_size),(unsigned int)fb_addr);
  518. return (void*)((UINT32)fb_addr + 2*fb_size);
  519. }
  520. UINT32 mt_get_fb_size(void)
  521. {
  522. return fb_size;
  523. }
  524. #if (MTK_DUAL_DISPLAY_SUPPORT == 2)
  525. void* mt_get_ext_logo_db_addr(void)
  526. {
  527. dprintf(0,"mt_get_ext_logo_db_addr: 0x%08x\n",ext_logo_db_addr);
  528. return ext_logo_db_addr;
  529. }
  530. void* mt_get_ext_logo_db_addr_pa(void)
  531. {
  532. dprintf(0,"mt_get_ext_logo_db_addr_pa: 0x%08x\n",ext_logo_db_addr_pa);
  533. return ext_logo_db_addr_pa;
  534. }
  535. void* mt_get_ext_fb_addr(void)
  536. {
  537. ext_fb_isdirty = 1;
  538. return (void*)((UINT32)ext_fb_addr + ext_fb_offset_logo * ext_fb_size);
  539. }
  540. void* mt_get_ext_tempfb_addr(void)
  541. {
  542. //use offset = 2 as tempfb for decompress logo
  543. dprintf(0,"mt_get_ext_tempfb_addr: 0x%08x ,ext_fb_addr 0x%08x\n",(void*)((UINT32)ext_fb_addr + 2*ext_fb_size),(void*)ext_fb_addr);
  544. return (void*)((UINT32)ext_fb_addr + 2 * ext_fb_size);
  545. }
  546. INT32 mt_get_ext_fb_size(void)
  547. {
  548. return ext_fb_size;
  549. }
  550. #endif
  551. void mt_disp_update(UINT32 x, UINT32 y, UINT32 width, UINT32 height)
  552. {
  553. arch_clean_cache_range((unsigned int)fb_addr, DISP_GetFBRamSize());
  554. primary_display_trigger(TRUE);
  555. }
  556. #if (MTK_DUAL_DISPLAY_SUPPORT == 2)
  557. void mt_ext_disp_update(UINT32 x, UINT32 y, UINT32 width, UINT32 height)
  558. {
  559. unsigned int va = ext_fb_addr;
  560. arch_clean_cache_range((unsigned int)ext_fb_addr, EXT_DISP_GetFBRamSize());
  561. external_display_trigger(TRUE);
  562. if (!external_display_is_video_mode()) {
  563. /*video mode no need to wait*/
  564. dprintf(CRITICAL,"cmd mode trigger wait\n");
  565. mdelay(30);
  566. }
  567. }
  568. #endif
  569. static void mt_disp_adjusting_hardware_addr(void)
  570. {
  571. dprintf(CRITICAL,"mt_disp_adjusting_hardware_addr fb_offset_logo = %d fb_size=%d\n",fb_offset_logo,fb_size);
  572. if (fb_offset_logo == 0) {
  573. mt_get_fb_addr();
  574. memcpy(fb_addr,(void *)((UINT32)fb_addr + 3 * fb_size),fb_size);
  575. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  576. }
  577. }
  578. UINT32 mt_disp_get_lcd_time(void)
  579. {
  580. static unsigned int fps = 0;
  581. if (!fps) {
  582. fps = primary_display_get_vsync_interval();
  583. dprintf(CRITICAL, "%s, fps=%d\n", __func__, fps);
  584. if (!fps)
  585. fps = 6000;
  586. }
  587. return fps;
  588. }
  589. int mt_disp_config_frame_buffer(void *fdt)
  590. {
  591. extern unsigned int g_fb_base;
  592. extern unsigned int g_fb_size;
  593. unsigned int fb_base_h =0;
  594. unsigned int fb_base_l = g_fb_base & 0xffffffff;
  595. int offset;
  596. int ret;
  597. fb_base_h = cpu_to_fdt32(fb_base_h);
  598. fb_base_l = cpu_to_fdt32(fb_base_l);
  599. g_fb_size = cpu_to_fdt32(g_fb_size);
  600. /* placed in the DT chosen node */
  601. offset = fdt_path_offset(fdt, "/chosen");
  602. if (offset < 0) {
  603. return offset;
  604. }
  605. ret = fdt_setprop(fdt, offset, "atag,videolfb-fb_base_h", &fb_base_h, sizeof(fb_base_h));
  606. ret = fdt_setprop(fdt, offset, "atag,videolfb-fb_base_l", &fb_base_l, sizeof(fb_base_l));
  607. ret = fdt_setprop(fdt, offset, "atag,videolfb-vramSize", &g_fb_size, sizeof(g_fb_size));
  608. return ret;
  609. }
  610. // Attention: this api indicates whether the lcm is connected
  611. int DISP_IsLcmFound(void)
  612. {
  613. return primary_display_is_lcm_connected();
  614. }
  615. const char* mt_disp_get_lcm_id(void)
  616. {
  617. return primary_display_get_lcm_name();
  618. }
  619. #if (MTK_DUAL_DISPLAY_SUPPORT == 2)
  620. const char* mt_ext_disp_get_lcm_id(void)
  621. {
  622. return external_display_get_lcm_name();
  623. }
  624. int EXT_DISP_IsLcmFound(void)
  625. {
  626. return external_display_is_lcm_connected();
  627. }
  628. #endif
  629. void disp_get_fb_address(UINT32 *fbVirAddr, UINT32 *fbPhysAddr)
  630. {
  631. *fbVirAddr = (UINT32)fb_addr;
  632. *fbPhysAddr = (UINT32)fb_addr;
  633. }
  634. UINT32 mt_disp_get_redoffset_32bit(void)
  635. {
  636. return redoffset_32bit;
  637. }
  638. // ---------------------------------------------------------------------------
  639. // Export Functions - Console
  640. // ---------------------------------------------------------------------------
  641. #ifdef CONFIG_CFB_CONSOLE
  642. // video_hw_init -- called by drv_video_init() for framebuffer console
  643. void *video_hw_init (void)
  644. {
  645. static GraphicDevice s_mt65xx_gd;
  646. memset(&s_mt65xx_gd, 0, sizeof(GraphicDevice));
  647. s_mt65xx_gd.frameAdrs = (UINT32)fb_addr+fb_size;
  648. s_mt65xx_gd.winSizeX = CFG_DISPLAY_WIDTH;
  649. s_mt65xx_gd.winSizeY = CFG_DISPLAY_HEIGHT;
  650. s_mt65xx_gd.gdfIndex = CFB_X888RGB_32BIT;
  651. dprintf(0, "s_mt65xx_gd.gdfIndex=%d", s_mt65xx_gd.gdfIndex);
  652. s_mt65xx_gd.gdfBytesPP = CFG_DISPLAY_BPP / 8;
  653. s_mt65xx_gd.memSize = s_mt65xx_gd.winSizeX * s_mt65xx_gd.winSizeY * s_mt65xx_gd.gdfBytesPP;
  654. return &s_mt65xx_gd;
  655. }
  656. void video_set_lut(unsigned int index, /* color number */
  657. unsigned char r, /* red */
  658. unsigned char g, /* green */
  659. unsigned char b) /* blue */
  660. {
  661. dprintf(CRITICAL, "%s\n", __func__);
  662. }
  663. #endif // CONFIG_CFB_CONSOLE