mt_disp_drv.c 25 KB

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