mt_disp_drv.c 20 KB

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