mt_disp_drv.c 21 KB

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