mt_disp_drv.c 18 KB

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