mt_disp_drv.c 24 KB

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