一、lk进入kmain()
1. vendor/mediatek/proprietary/bootable/bootloader/lk/arch/arm/srt0.S
1 bl kmain
二、初始化lk,分配framebuffer
1. vendor/mediatek/proprietary/bootable/bootloader/lk/kernel/main.c
1 void kmain(void) 2 { 3 #if !defined(MACH_FPGA) && !defined(SB_LK_BRINGUP) 4 boot_time = get_timer(0); 5 #endif 6 7 // get us into some sort of thread context 8 thread_init_early(); 9 10 // early arch stuff 11 arch_early_init(); 12 13 // do any super early platform initialization 14 platform_early_init(); 15 16 #if defined(MACH_FPGA) || defined(SB_LK_BRINGUP) 17 boot_time = get_timer(0); 18 #endif 19 20 // do any super early target initialization 21 target_early_init(); 22 23 dprintf(INFO, "welcome to lk "); 24 25 // deal with any static constructors 26 dprintf(SPEW, "calling constructors "); 27 call_constructors(); 28 29 // bring up the kernel heap 30 dprintf(SPEW, "initializing heap "); 31 heap_init(); 32 33 // initialize the threading system 34 dprintf(SPEW, "initializing threads "); 35 thread_init(); 36 37 // initialize the dpc system 38 dprintf(SPEW, "initializing dpc "); 39 dpc_init(); 40 41 // initialize kernel timers 42 dprintf(SPEW, "initializing timers "); 43 timer_init(); 44 45 #ifdef MTK_LK_IRRX_SUPPORT 46 mtk_ir_init(0); 47 #endif 48 49 50 #if (!ENABLE_NANDWRITE) 51 // create a thread to complete system initialization 52 dprintf(SPEW, "creating bootstrap completion thread "); 53 thread_resume(thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); 54 55 // enable interrupts 56 exit_critical_section(); 57 58 // become the idle thread 59 thread_become_idle(); 60 #else 61 bootstrap_nandwrite(); 62 #endif 63 }
1 static int bootstrap2(void *arg) 2 { 3 dprintf(SPEW, "top of bootstrap2() "); 4 5 arch_init(); 6 7 // XXX put this somewhere else 8 #if WITH_LIB_BIO 9 bio_init(); 10 #endif 11 #if WITH_LIB_FS 12 fs_init(); 13 #endif 14 15 // initialize the rest of the platform 16 dprintf(SPEW, "initializing platform "); 17 18 platform_init(); 19 20 // initialize the target 21 dprintf(SPEW, "initializing target "); 22 target_init(); 23 24 dprintf(SPEW, "calling apps_init() "); 25 apps_init(); 26 27 return 0; 28 }
2. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/platform.c
1 void platform_init(void) 2 { 3 #ifdef LK_PROFILING 4 unsigned int time_nand_emmc; 5 unsigned int time_led_init; 6 unsigned int time_env; 7 unsigned int time_disp_init; 8 unsigned int time_load_logo; 9 unsigned int time_backlight; 10 unsigned int time_boot_mode; 11 #ifdef MTK_SECURITY_SW_SUPPORT 12 unsigned int time_security_init; 13 #endif 14 unsigned int time_bat_init; 15 unsigned int time_RTC_boot_Check; 16 unsigned int time_show_logo; 17 unsigned int time_sw_env; 18 unsigned int time_platform_init; 19 20 time_platform_init = get_timer(0); 21 #endif 22 u64 pl_start_addr = 0; 23 plinfo_get_brom_header_block_size(&pl_start_addr); 24 25 dprintf(CRITICAL," ==LK info == "); 26 dprintf(CRITICAL," Build time:%s, %s ", __DATE__,__TIME__); 27 dprintf(CRITICAL," chip_code[0x%x] ", mt_get_chip_hw_code()); 28 dprintf(CRITICAL," chip_ver[0x%x] ", mt_get_chip_sw_ver()); 29 dprintf(CRITICAL," ==LK info == "); 30 dprintf(CRITICAL, "platform_init() "); 31 32 #if defined (MTK_EFUSE_DOWNGRADE) 33 set_sw_segment_code(); 34 #endif 35 36 mt_set_gpio_mode(GPIO11, GPIO_MODE_00); 37 mt_set_gpio_dir(GPIO11, GPIO_DIR_OUT); 38 mt_set_gpio_out(GPIO11, GPIO_OUT_ZERO); 39 40 mt_set_gpio_mode(GPIO119, GPIO_MODE_00); 41 mt_set_gpio_dir(GPIO119, GPIO_DIR_OUT); 42 mt_set_gpio_out(GPIO119, GPIO_OUT_ZERO); 43 44 #ifdef DUMMY_AP 45 dummy_ap_entry(); 46 #endif 47 48 #ifdef LK_PROFILING 49 time_nand_emmc = get_timer(0); 50 #endif 51 #ifdef MTK_EMMC_SUPPORT 52 mmc_legacy_init(1); 53 #else 54 #ifndef MACH_FPGA 55 nand_init(); 56 nand_driver_test(); 57 #endif 58 #endif 59 #ifdef LK_PROFILING 60 dprintf(INFO, "[PROFILE] ------- NAND/EMMC init takes %d ms -------- ", (int)get_timer(time_nand_emmc)); 61 #endif 62 #if defined(CFG_DTB_EARLY_LOADER_SUPPORT) 63 64 if (bldr_load_dtb("boot")<0) 65 { 66 printf("bldr_load_dtb fail "); 67 } 68 else 69 { 70 printf("bldr_load_dtb success "); 71 } 72 73 #endif 74 75 #ifndef MACH_FPGA 76 #ifdef LK_PROFILING 77 time_led_init = get_timer(0); 78 #endif 79 leds_init(); 80 #ifdef LK_PROFILING 81 dprintf(INFO, "[PROFILE] ------- led init takes %d ms -------- ", (int)get_timer(time_led_init)); 82 #endif 83 #endif 84 85 #ifdef MTK_KERNEL_POWER_OFF_CHARGING 86 if ((g_boot_arg->boot_reason == BR_USB) && (upmu_is_chr_det() == KAL_FALSE)) { 87 dprintf(INFO, "[%s] Unplugged Charger/Usb between Pre-loader and Uboot in Kernel Charging Mode, Power Off ", __func__); 88 mt6575_power_off(); 89 } 90 #endif 91 92 #ifdef LK_PROFILING 93 time_env = get_timer(0); 94 #endif 95 env_init(); 96 print_env(); 97 #ifdef MTK_USB2JTAG_SUPPORT 98 extern void usb2jtag_init(void); 99 usb2jtag_init(); 100 #endif 101 #ifdef LK_PROFILING 102 dprintf(INFO, "[PROFILE] ------- ENV init takes %d ms -------- ", (int)get_timer(time_env)); 103 #endif 104 105 #ifdef LK_PROFILING 106 time_disp_init = get_timer(0); 107 #endif 108 109 /* initialize the frame buffet information */ 110 #ifndef MACH_FPGA_NO_DISPLAY 111 g_fb_size = mt_disp_get_vram_size(); 112 #else 113 g_fb_size = 0x1000000; 114 #endif 115 116 #if 0 117 g_fb_base = memory_size() - g_fb_size + DRAM_PHY_ADDR; 118 #else 119 120 #if 0 121 if (g_is_64bit_kernel) { 122 g_fb_base = mblock_reserve(&g_boot_arg->mblock_info, g_fb_size, 0x200000, 0x100000000, RANKMAX); 123 g_fb_base = ALIGN_TO(g_fb_base,0x200000); // size 2MB align 124 } else { 125 g_fb_base = mblock_reserve(&g_boot_arg->mblock_info, g_fb_size, 0x100000, 0x100000000, RANKMAX); 126 } 127 #else 128 g_fb_base = mblock_reserve(&g_boot_arg->mblock_info, g_fb_size, 0x10000, 0x100000000, RANKMAX); 129 #endif 130 131 if (!g_fb_base) { 132 /* ERROR */ 133 } 134 #endif 135 136 dprintf(CRITICAL, "FB base = 0x%x, FB size = %d ", g_fb_base, g_fb_size); 137 138 #ifndef MACH_FPGA_NO_DISPLAY 139 mt_disp_init((void *)g_fb_base); 140 /* show black picture fisrtly in case of backlight is on before nothing is drawed*/ 141 mt_disp_fill_rect(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT, 0x0); 142 mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); 143 #ifdef LK_PROFILING 144 dprintf(INFO, "[PROFILE] ------- disp init takes %d ms -------- ", (int)get_timer(time_disp_init)); 145 #endif 146 147 #ifdef MTK_SECURITY_SW_SUPPORT 148 #ifdef LK_PROFILING 149 time_security_init = get_timer(0); 150 #endif 151 152 /* initialize security library */ 153 sec_func_init(pl_start_addr); 154 155 #ifdef LK_PROFILING 156 dprintf(INFO,"[PROFILE] ------- Security init takes %d ms -------- ", (int)get_timer(time_security_init)); 157 #endif 158 159 seclib_set_oemkey(g_oemkey, OEM_PUBK_SZ); 160 /* logo image authentication */ 161 if ( 0 != sec_logo_check() ) { 162 dprintf(CRITICAL,"<ASSERT> %s:line %d ",__FILE__,__LINE__); 163 while (1); 164 } 165 #ifdef MTK_DTBO_FEATURE 166 /* dtbo image authentication */ 167 if ( 0 != sec_dtbo_check() ) { 168 dprintf(CRITICAL,"<ASSERT> %s:line %d ",__FILE__,__LINE__); 169 while (1); 170 } 171 #endif 172 #endif 173 drv_video_init(); 174 #endif 175 176 /*for kpd pmic mode setting*/ 177 set_kpd_pmic_mode(); 178 179 #ifndef MACH_FPGA 180 #ifdef LK_PROFILING 181 time_boot_mode = get_timer(0); 182 #endif 183 boot_mode_select(); 184 #ifdef CFG_DTB_EARLY_LOADER_SUPPORT 185 /* reload dtb when boot mode = recovery */ 186 if ((g_boot_mode == RECOVERY_BOOT) && (bldr_load_dtb("recovery") < 0)) 187 dprintf(CRITICAL, "bldr_load_dtb fail "); 188 #endif 189 190 #ifdef LK_PROFILING 191 dprintf(INFO, "[PROFILE] ------- boot mode select takes %d ms -------- ", (int)get_timer(time_boot_mode)); 192 #endif 193 #endif 194 195 #ifndef MACH_FPGA_NO_DISPLAY 196 #ifdef LK_PROFILING 197 time_load_logo = get_timer(0); 198 #endif 199 mboot_common_load_logo((unsigned long)mt_get_logo_db_addr_pa(), "logo"); 200 #ifdef LK_PROFILING 201 dprintf(INFO, "[PROFILE] ------- load_logo takes %d ms -------- ", (int)get_timer(time_load_logo)); 202 #endif 203 #endif 204 205 /*Show download logo & message on screen */ 206 if (g_boot_arg->boot_mode == DOWNLOAD_BOOT) { 207 dprintf(CRITICAL, "[LK] boot mode is DOWNLOAD_BOOT "); 208 209 #ifdef MTK_SECURITY_SW_SUPPORT 210 /* verify da before jumping to da*/ 211 if (sec_usbdl_enabled()) { 212 u8 *da_addr = (u8*)g_boot_arg->da_info.addr; 213 u32 da_len = g_boot_arg->da_info.len; 214 u32 sig_len = g_boot_arg->da_info.sig_len; 215 u8 *sig_addr = (unsigned char *)da_addr + (da_len - sig_len); 216 217 if (da_len == 0 || sig_len == 0) { 218 dprintf(INFO, "[LK] da argument is invalid "); 219 dprintf(INFO, "da_addr = 0x%x ", (int)da_addr); 220 dprintf(INFO, "da_len = 0x%x ", da_len); 221 dprintf(INFO, "sig_len = 0x%x ", sig_len); 222 } 223 224 if (sec_usbdl_verify_da(da_addr, (da_len - sig_len), sig_addr, sig_len)) { 225 /* da verify fail */ 226 video_printf(" => Not authenticated tool, download stop... "); 227 while (1); /* fix me, should not be infinite loop in lk */ 228 } 229 } else 230 #endif 231 { 232 dprintf(INFO, " DA verification disabled... "); 233 } 234 235 #ifndef MACH_FPGA_NO_DISPLAY 236 mt_disp_show_boot_logo(); 237 #endif 238 video_printf(" => Downloading... "); 239 dprintf(CRITICAL, "enable backlight after show bootlogo! "); 240 mt65xx_backlight_on(); 241 242 mtk_wdt_disable(); //Disable wdt before jump to DA 243 platform_uninit(); 244 #ifdef HAVE_CACHE_PL310 245 l2_disable(); 246 #endif 247 arch_disable_cache(UCACHE); 248 arch_disable_mmu(); 249 #ifdef ENABLE_L2_SHARING 250 config_shared_SRAM_size(); 251 #endif 252 253 jump_da(g_boot_arg->da_info.addr, g_boot_arg->da_info.arg1, g_boot_arg->da_info.arg2); 254 } 255 256 #ifdef LK_PROFILING 257 time_bat_init = get_timer(0); 258 #endif 259 mt65xx_bat_init(); 260 #ifdef LK_PROFILING 261 dprintf(INFO, "[PROFILE] ------- battery init takes %d ms -------- ", (int)get_timer(time_bat_init)); 262 #endif 263 264 #ifndef CFG_POWER_CHARGING 265 #ifdef LK_PROFILING 266 time_RTC_boot_Check = get_timer(0); 267 #endif 268 /* NOTE: if define CFG_POWER_CHARGING, will rtc_boot_check() in mt65xx_bat_init() */ 269 rtc_boot_check(false); 270 #ifdef LK_PROFILING 271 dprintf(INFO, "[PROFILE] ------- RTC boot check Init takes %d ms -------- ", (int)get_timer(time_RTC_boot_Check)); 272 #endif 273 #endif 274 275 #ifdef LK_PROFILING 276 time_show_logo = get_timer(0); 277 #endif 278 #ifdef MTK_KERNEL_POWER_OFF_CHARGING 279 if (kernel_charging_boot() == 1) { 280 #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY 281 CHARGER_TYPE CHR_Type_num = CHARGER_UNKNOWN; 282 CHR_Type_num = hw_charging_get_charger_type(); 283 if ((g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) || 284 ((CHR_Type_num != STANDARD_HOST) && (CHR_Type_num != NONSTANDARD_CHARGER))) { 285 #endif 286 mt_disp_power(TRUE); 287 mt_disp_show_low_battery(); 288 mt65xx_leds_brightness_set(6, 110); 289 #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY 290 } 291 #endif 292 } else if (g_boot_mode != KERNEL_POWER_OFF_CHARGING_BOOT && g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) { 293 if (g_boot_mode != ALARM_BOOT && (g_boot_mode != FASTBOOT)) { 294 #ifndef MACH_FPGA_NO_DISPLAY 295 mt_disp_show_boot_logo(); 296 #endif 297 } 298 } 299 #else 300 if (g_boot_mode != ALARM_BOOT && (g_boot_mode != FASTBOOT)) { 301 #ifndef MACH_FPGA_NO_DISPLAY 302 mt_disp_show_boot_logo(); 303 #endif 304 } 305 #endif 306 #ifdef LK_PROFILING 307 time_backlight = get_timer(0); 308 #endif 309 310 #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY 311 if (!is_low_battery(0)) { 312 #endif 313 mt65xx_backlight_on(); 314 #ifndef MACH_FPGA_NO_DISPLAY 315 //pwm need display sof 316 mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); 317 #endif 318 #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY 319 } 320 #endif 321 322 #ifdef LK_PROFILING 323 dprintf(INFO, "[PROFILE] ------- backlight takes %d ms -------- ", (int)get_timer(time_backlight)); 324 #endif 325 326 #ifdef LK_PROFILING 327 dprintf(INFO, "[PROFILE] ------- show logo takes %d ms -------- ", (int)get_timer(time_show_logo)); 328 #endif 329 330 #ifndef MACH_FPGA 331 #ifdef LK_PROFILING 332 time_sw_env = get_timer(0); 333 #endif 334 sw_env(); 335 #ifdef LK_PROFILING 336 dprintf(INFO, "[PROFILE] ------- sw_env takes %d ms -------- ", (int)get_timer(time_sw_env)); 337 #endif 338 #endif 339 340 #ifdef LK_PROFILING 341 dprintf(INFO, "[PROFILE] ------- platform_init takes %d ms -------- ", (int)get_timer(time_platform_init)); 342 #endif 343 }
3. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/mt_disp_drv.c
1 UINT32 mt_disp_get_vram_size(void) 2 { 3 return DISP_GetVRamSize(); 4 }
4. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/primary_display.c
1 unsigned int DISP_GetVRamSize(void) 2 { 3 static UINT32 vramSize = 0; 4 5 printf("jjh DISP_GetVRamSize "); 6 7 if (0 == vramSize) { 8 vramSize = DISP_GetFBRamSize(); 9 10 vramSize += DAL_GetLayerSize(); 11 12 #if 0 13 if (g_is_64bit_kernel) { 14 vramSize = ALIGN_TO(vramSize, 0x400000); // both start addr and size needs 2MB align, so size must 4MB align 15 } else { 16 vramSize = ALIGN_TO(vramSize, 0x100000); // both start addr and size needs 2MB align, so size must 4MB align 17 } 18 #else 19 vramSize = ALIGN_TO(vramSize, 0x10000); // just align to 64KB is OK 20 #endif 21 22 DISPMSG("^^ DISP_GetVRamSize: %u bytes ", vramSize); 23 } 24 25 return vramSize; 26 }
1 UINT32 DISP_GetFBRamSize(void) 2 { 3 return ALIGN_TO(DISP_GetScreenWidth(), MTK_FB_ALIGNMENT) * DISP_GetScreenHeight() * ((DISP_GetScreenBpp() + 7) >> 3) * DISP_GetPages(); 4 }
1 UINT32 DISP_GetScreenWidth(void) 2 { 3 return primary_display_get_width(); 4 }
1 int primary_display_get_width(void) 2 { 3 if (pgc->plcm == NULL) { 4 pgc->plcm = disp_lcm_probe(NULL, LCM_INTERFACE_NOTDEFINED); 5 DISPMSG("lcm handle is null, after probe:0x%08x ",pgc->plcm); 6 if (pgc->plcm == NULL) 7 return 0; 8 } 9 10 if (pgc->plcm->params) { 11 return pgc->plcm->params->width; 12 } else { 13 DISPERR("lcm_params is null! "); 14 return 0; 15 } 16 }
5. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/disp_lcm.c
1 /* if lcm handle already probed, should return lcm handle directly */ 2 disp_lcm_handle *disp_lcm_probe(char *plcm_name, LCM_INTERFACE_ID lcm_id) 3 { 4 DISPFUNC(); 5 6 int ret = 0; 7 bool isLCMFound = false; 8 bool isLCMConnected = false; 9 10 LCM_DRIVER *lcm_drv = NULL; 11 LCM_PARAMS *lcm_param = NULL; 12 disp_lcm_handle *plcm = NULL; 13 14 #if defined(MTK_LCM_DEVICE_TREE_SUPPORT) 15 bool isLCMDtFound = false; 16 17 if (check_lcm_node_from_DT() == 0) { 18 lcm_drv = &lcm_common_drv; 19 isLCMFound = true; 20 isLCMDtFound = true; 21 } else 22 #endif 23 if (_lcm_count() == 0) { 24 DISPERR("no lcm driver defined in linux kernel driver "); 25 return NULL; 26 } else if (_lcm_count() == 1) { 27 lcm_drv = lcm_driver_list[0]; 28 isLCMFound = true; 29 } else { 30 /* in lk, plcm_name should always be NULL */ 31 if (plcm_name == NULL) { 32 int i = 0; 33 disp_path_handle handle = NULL; 34 disp_lcm_handle hlcm; 35 disp_lcm_handle *plcm = &hlcm; 36 LCM_PARAMS hlcm_param; 37 38 for (i=0; i<_lcm_count(); i++) { 39 memset((void*)&hlcm, 0, sizeof(disp_lcm_handle)); 40 memset((void*)&hlcm_param, 0, sizeof(LCM_PARAMS)); 41 42 lcm_drv= lcm_driver_list[i]; 43 lcm_drv->get_params(&hlcm_param); 44 plcm->drv = lcm_drv; 45 plcm->params = &hlcm_param; 46 plcm->lcm_if_id = plcm->params->lcm_if; 47 DISPMSG("we will check lcm: %s ", lcm_drv->name); 48 if (lcm_id == LCM_INTERFACE_NOTDEFINED ||(lcm_id != LCM_INTERFACE_NOTDEFINED && plcm->lcm_if_id == lcm_id)) { 49 handle = _display_interface_path_init(plcm); 50 if (handle == NULL) { 51 DISPERR("_display_interface_path_init returns NULL "); 52 goto FAIL; 53 } 54 55 if (lcm_drv->init_power) { 56 lcm_drv->init_power(); 57 } 58 59 if (lcm_drv->compare_id != NULL) { 60 if (lcm_drv->compare_id() != 0) { 61 isLCMFound = true; 62 _display_interface_path_deinit(handle); 63 dprintf(INFO,"we will use lcm: %s ", lcm_drv->name); 64 break; 65 } 66 } 67 68 _display_interface_path_deinit(handle); 69 } 70 } 71 72 if (isLCMFound == false) { 73 DISPERR("we have checked all lcm driver, but no lcm found "); 74 lcm_drv = lcm_driver_list[0]; 75 isLCMFound = true; 76 } 77 } else { 78 int i = 0; 79 for (i=0; i<_lcm_count(); i++) { 80 lcm_drv = lcm_driver_list[i]; 81 if (!strcmp(lcm_drv->name, plcm_name)) { 82 isLCMFound = true; 83 break; 84 } 85 } 86 } 87 } 88 89 if (isLCMFound == false) { 90 DISPERR("FATAL ERROR!!!No LCM Driver defined "); 91 return NULL; 92 } 93 94 plcm = &_disp_lcm_driver[0]; 95 lcm_param = &_disp_lcm_params; 96 if (plcm && lcm_param) { 97 plcm->params = lcm_param; 98 plcm->drv = lcm_drv; 99 } else { 100 DISPERR("FATAL ERROR!!!kzalloc plcm and plcm->params failed "); 101 goto FAIL; 102 } 103 104 #if defined(MTK_LCM_DEVICE_TREE_SUPPORT) 105 if (isLCMDtFound == true) 106 load_lcm_resources_from_DT(plcm->drv); 107 #endif 108 109 plcm->drv->get_params(plcm->params); 110 plcm->lcm_if_id = plcm->params->lcm_if; 111 /* below code is for lcm driver forward compatible */ 112 if (plcm->params->type == LCM_TYPE_DSI && plcm->params->lcm_if == LCM_INTERFACE_NOTDEFINED) 113 plcm->lcm_if_id = LCM_INTERFACE_DSI0; 114 if (plcm->params->type == LCM_TYPE_DPI && plcm->params->lcm_if == LCM_INTERFACE_NOTDEFINED) 115 plcm->lcm_if_id = LCM_INTERFACE_DPI0; 116 if (plcm->params->type == LCM_TYPE_DBI && plcm->params->lcm_if == LCM_INTERFACE_NOTDEFINED) 117 plcm->lcm_if_id = LCM_INTERFACE_DBI0; 118 #if 1 119 plcm->is_connected = isLCMConnected; 120 #endif 121 122 _dump_lcm_info(plcm); 123 return plcm; 124 125 FAIL: 126 127 return NULL; 128 }
1 int _lcm_count(void) 2 { 3 return lcm_count; 4 }
lcm_count在vendor/mediatek/proprietary/bootable/bootloader/lk/dev/lcm/mt65xx_lcm_list.c中定义:
1 unsigned int lcm_count = sizeof(lcm_driver_list) / sizeof(LCM_DRIVER *);
三、 disp 初始化
vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/platform.c
1 mt_disp_init((void *)g_fb_base);
1. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/mt_disp_drv.c
1 void mt_disp_init(void *lcdbase) 2 { 3 unsigned int lcm_fake_width = 0; 4 unsigned int lcm_fake_height = 0; 5 UINT32 boot_mode_addr = 0; 6 /// fb base pa and va 7 fb_addr_pa_k = arm_mmu_va2pa(lcdbase); 8 9 fb_addr_pa = fb_addr_pa_k & 0xffffffffull; 10 fb_addr = lcdbase; 11 12 dprintf(0,"fb_va: 0x%08x, fb_pa: 0x%08x, fb_pa_k: 0x%llx ", fb_addr, fb_addr_pa, fb_addr_pa_k); 13 14 fb_size = ALIGN_TO(CFG_DISPLAY_WIDTH, MTK_FB_ALIGNMENT) * CFG_DISPLAY_HEIGHT * CFG_DISPLAY_BPP / 8; 15 // pa; 16 boot_mode_addr = ((UINT32)fb_addr_pa + fb_size); 17 logo_db_addr_pa = (void *)((UINT32)fb_addr_pa - 4 * 1024 * 1024); 18 19 // va; 20 logo_db_addr = (void *)((UINT32)fb_addr - 4 * 1024 * 1024); 21 22 fb_offset_logo = 0; 23 24 primary_display_init(NULL); 25 memset((void*)lcdbase, 0x0, DISP_GetVRamSize()); 26 27 disp_input_config input; 28 memset(&input, 0, sizeof(disp_input_config)); 29 input.layer = BOOT_MENU_LAYER; 30 input.layer_en = 1; 31 input.fmt = redoffset_32bit ? eBGRA8888 : eRGBA8888; 32 input.addr = boot_mode_addr; 33 input.src_x = 0; 34 input.src_y = 0; 35 input.src_w = CFG_DISPLAY_WIDTH; 36 input.src_h = CFG_DISPLAY_HEIGHT; 37 input.src_pitch = CFG_DISPLAY_WIDTH*4; 38 input.dst_x = 0; 39 input.dst_y = 0; 40 input.dst_w = CFG_DISPLAY_WIDTH; 41 input.dst_h = CFG_DISPLAY_HEIGHT; 42 input.aen = 1; 43 input.alpha = 0xff; 44 45 primary_display_config_input(&input); 46 47 memset(&input, 0, sizeof(disp_input_config)); 48 input.layer = FB_LAYER; 49 input.layer_en = 1; 50 input.fmt = redoffset_32bit ? eBGRA8888 : eRGBA8888; 51 input.addr = fb_addr_pa; 52 input.src_x = 0; 53 input.src_y = 0; 54 input.src_w = CFG_DISPLAY_WIDTH; 55 input.src_h = CFG_DISPLAY_HEIGHT; 56 input.src_pitch = ALIGN_TO(CFG_DISPLAY_WIDTH, MTK_FB_ALIGNMENT)*4; 57 input.dst_x = 0; 58 input.dst_y = 0; 59 input.dst_w = CFG_DISPLAY_WIDTH; 60 input.dst_h = CFG_DISPLAY_HEIGHT; 61 62 input.aen = 1; 63 input.alpha = 0xff; 64 primary_display_config_input(&input); 65 66 67 //_mtkfb_internal_test(fb_addr, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); 68 69 #if 0 70 mt_disp_parse_dfo_setting(); 71 72 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))) { 73 if (DISP_STATUS_OK != DISP_Change_LCM_Resolution(lcm_fake_width, lcm_fake_height)) { 74 dprintf(INFO,"[DISP_DFO]WARNING!!! Change LCM Resolution FAILED!!! "); 75 } 76 } 77 #endif 78 79 }
2. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/primary_display.c
1 int primary_display_init(char *lcm_name) 2 { 3 DISPFUNC(); 4 DISP_STATUS ret = DISP_STATUS_OK; 5 DISP_MODULE_ENUM dst_module = 0; 6 7 unsigned int lcm_fake_width = 0; 8 unsigned int lcm_fake_height = 0; 9 LCM_PARAMS *lcm_param = NULL; 10 LCM_INTERFACE_ID lcm_id = LCM_INTERFACE_NOTDEFINED; 11 12 dpmgr_init(); 13 #ifndef DDP_LK_BOOT 14 mutex_init(&(pgc->lock)); 15 #endif 16 _primary_path_lock(); 17 18 if (pgc->plcm == NULL) 19 pgc->plcm = disp_lcm_probe( lcm_name, LCM_INTERFACE_NOTDEFINED); 20 mt_disp_parse_dfo_setting(); 21 22 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))) { 23 24 if (0 != primary_display_change_lcm_resolution(lcm_fake_width, lcm_fake_height)) { 25 DISPERR("[DISP_DFO]WARNING!!! Change LCM Resolution FAILED!!! "); 26 } 27 } 28 29 if (pgc->plcm == NULL) { 30 DISPCHECK("disp_lcm_probe returns null "); 31 ret = DISP_STATUS_ERROR; 32 goto done; 33 } else { 34 DISPCHECK("disp_lcm_probe SUCCESS "); 35 } 36 37 38 lcm_param = disp_lcm_get_params(pgc->plcm); 39 40 if (lcm_param == NULL) { 41 DISPERR("get lcm params FAILED "); 42 ret = DISP_STATUS_ERROR; 43 goto done; 44 } 45 46 if (primary_display_mode == DIRECT_LINK_MODE) { 47 _build_path_direct_link(); 48 49 DISPCHECK("primary display is DIRECT LINK MODE "); 50 } else if (primary_display_mode == DECOUPLE_MODE) { 51 _build_path_decouple(); 52 53 DISPCHECK("primary display is DECOUPLE MODE "); 54 } else if (primary_display_mode == SINGLE_LAYER_MODE) { 55 _build_path_single_layer(); 56 57 DISPCHECK("primary display is SINGLE LAYER MODE "); 58 } else if (primary_display_mode == DEBUG_RDMA1_DSI0_MODE) { 59 _build_path_debug_rdma1_dsi0(); 60 61 DISPCHECK("primary display is DEBUG RDMA1 DSI0 MODE "); 62 } else { 63 DISPCHECK("primary display mode is WRONG "); 64 } 65 66 _build_cmdq_trigger_loop(); 67 68 DISPCHECK("primary display BUILD cmdq trigger loop finished "); 69 70 _start_cmdq_trigger_loop(); 71 72 DISPCHECK("primary display START cmdq trigger loop finished "); 73 74 dpmgr_path_set_video_mode(pgc->dpmgr_handle, primary_display_is_video_mode()); 75 76 dpmgr_path_init(pgc->dpmgr_handle, CMDQ_DISABLE); 77 78 #ifdef MACH_FPGA 79 dpmgr_path_reset(pgc->dpmgr_handle, CMDQ_DISABLE); 80 #endif 81 82 disp_ddp_path_config data_config; 83 memset((void*)&data_config, 0, sizeof(disp_ddp_path_config)); 84 85 memcpy(&(data_config.dsi_config), &(lcm_param->dsi), sizeof(LCM_DSI_PARAMS)); 86 87 data_config.dst_w = lcm_param->width; 88 data_config.dst_h = lcm_param->height; 89 if (lcm_param->type == LCM_TYPE_DSI) { 90 if (lcm_param->dsi.data_format.format == LCM_DSI_FORMAT_RGB888) 91 data_config.lcm_bpp = 24; 92 else if (lcm_param->dsi.data_format.format == LCM_DSI_FORMAT_RGB565) 93 data_config.lcm_bpp = 16; 94 else if (lcm_param->dsi.data_format.format == LCM_DSI_FORMAT_RGB666) 95 data_config.lcm_bpp = 18; 96 } else if (lcm_param->type == LCM_TYPE_DPI) { 97 if ( lcm_param->dpi.format == LCM_DPI_FORMAT_RGB888) 98 data_config.lcm_bpp = 24; 99 else if ( lcm_param->dpi.format == LCM_DPI_FORMAT_RGB565) 100 data_config.lcm_bpp = 16; 101 if ( lcm_param->dpi.format == LCM_DPI_FORMAT_RGB666) 102 data_config.lcm_bpp = 18; 103 } 104 data_config.dst_dirty = 1; 105 #ifdef MACH_FPGA 106 data_config.ovl_dirty = 1; 107 #endif 108 109 ret = dpmgr_path_config(pgc->dpmgr_handle, &data_config, CMDQ_DISABLE); 110 ret = disp_lcm_init(pgc->plcm); 111 112 if (primary_display_is_video_mode()) { 113 dpmgr_map_event_to_irq(pgc->dpmgr_handle, DISP_PATH_EVENT_IF_VSYNC, DDP_IRQ_RDMA0_DONE); 114 } else { 115 116 } 117 118 dpmgr_enable_event(pgc->dpmgr_handle, DISP_PATH_EVENT_IF_VSYNC); 119 dpmgr_enable_event(pgc->dpmgr_handle, DISP_PATH_EVENT_FRAME_DONE); 120 121 #if ROME_TODO 122 if (esd_check_enable) { 123 wakeup(esd_check_task); 124 } 125 #endif 126 127 pgc->state = 1; 128 129 done: 130 131 _primary_path_unlock(); 132 return ret; 133 }
3. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/disp_lcm.c
1 int disp_lcm_init(disp_lcm_handle *plcm) 2 { 3 DISPFUNC(); 4 LCM_DRIVER *lcm_drv = NULL; 5 bool isLCMConnected = false; 6 7 if (_is_lcm_inited(plcm)) { 8 lcm_drv = plcm->drv; 9 10 if (lcm_drv->init_power) { 11 lcm_drv->init_power(); 12 } 13 14 if (lcm_drv->init) { 15 if (!disp_lcm_is_inited(plcm)) { 16 lcm_drv->init(); 17 } 18 } else { 19 DISPERR("FATAL ERROR, lcm_drv->init is null "); 20 return -1; 21 } 22 #if 1 23 if (LCM_TYPE_DSI == plcm->params->type) { 24 int ret = 0; 25 char buffer = 0; 26 unsigned int data_array[4]; 27 28 /* 29 * Some LCD may return fail when reading register 0x0A due to no getting maximum return size. 30 * Therefore, we add a command here to read maximum return size to avoid this problem. 31 */ 32 data_array[0] = 0x00013700; /* read a byte. */ 33 ret = DSI_set_cmdq(_get_dst_module_by_lcm(plcm), NULL, data_array, 1, 1); /* read maximum return size. */ 34 if (ret == 0) { 35 DISPMSG("read lcm maximum return size failed. "); 36 } 37 38 ret = 39 DSI_dcs_read_lcm_reg_v2(_get_dst_module_by_lcm(plcm), NULL, 0x0A, 40 &buffer, 1); 41 if (ret == 0) { 42 isLCMConnected = 0; 43 DISPMSG("lcm is not connected "); 44 } else { 45 isLCMConnected = 1; 46 DISPMSG("lcm is connected "); 47 } 48 } 49 if (plcm->params->dsi.edp_panel == 1) { 50 isLCMConnected = 1; 51 } 52 plcm->is_connected = isLCMConnected; 53 #endif 54 return 0; 55 } else { 56 DISPERR("plcm is null "); 57 return -1; 58 } 59 }
四、 disp LOGO 初始化
vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/platform.c
1 /* show black picture fisrtly in case of backlight is on before nothing is drawed*/ 2 mt_disp_fill_rect(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT, 0x0); 3 mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
1. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/mt_logo.c
1 /* 2 * Fill rectangle region for with black or other color 3 * 4 */ 5 void mt_disp_fill_rect(UINT32 left, UINT32 top, 6 UINT32 right, UINT32 bottom, 7 UINT32 color) 8 { 9 dprintf(INFO, "[lk logo: %s %d] ",__FUNCTION__,__LINE__); 10 init_fb_screen(); 11 RECT_REGION_T rect = {left, top, right, bottom}; 12 13 fill_rect_with_color(mt_get_fb_addr(), rect, color, phical_screen); 14 }
1 /* 2 * Initliaze charging animation parameters 3 * 4 */ 5 void init_fb_screen() 6 { 7 dprintf(INFO, "[lk logo: %s %d] ",__FUNCTION__,__LINE__); 8 unsigned int fb_size = mt_get_fb_size(); 9 logo_addr = mt_get_logo_db_addr(); 10 11 phical_screen.width = CFG_DISPLAY_WIDTH; 12 phical_screen.height = CFG_DISPLAY_HEIGHT; 13 phical_screen.fb_size = fb_size; 14 phical_screen.fill_dst_bits = CFG_DISPLAY_BPP; 15 phical_screen.bits_per_pixel = CFG_DISPLAY_BPP; 16 17 // in JB2.MP need to allign width and height to 32 ,but jb5.mp needn't 18 phical_screen.needAllign = 1; 19 phical_screen.allignWidth = ALIGN_TO(CFG_DISPLAY_WIDTH, MTK_FB_ALIGNMENT); 20 21 /* In GB, no need to adjust 180 showing logo ,for fb driver dealing the change */ 22 /* but in JB, need adjust it for screen 180 roration */ 23 phical_screen.need180Adjust = 0; // need sync with chip driver 24 25 dprintf(INFO, "[lk logo: %s %d]MTK_LCM_PHYSICAL_ROTATION = %s ",__FUNCTION__,__LINE__, MTK_LCM_PHYSICAL_ROTATION); 26 27 if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "270", 3)) { 28 phical_screen.rotation = 270; 29 } else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "90", 2)) { 30 phical_screen.rotation = 90; 31 } else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "180", 3) && (phical_screen.need180Adjust == 1)) { 32 phical_screen.rotation = 180; 33 } else { 34 phical_screen.rotation = 0; 35 } 36 37 sync_anim_version(); 38 if (show_animationm_ver == 1) { 39 unsigned int logonum; 40 unsigned int *db_addr = logo_addr; 41 42 unsigned int *pinfo = (unsigned int*)db_addr; 43 44 logonum = pinfo[0]; 45 dprintf(INFO, "[lk logo: %s %d]pinfo[0]=0x%08x, pinfo[1]=0x%08x, pinfo[2]=%d ", __FUNCTION__,__LINE__, 46 pinfo[0], pinfo[1], pinfo[2]); 47 48 dprintf(INFO, "[lk logo: %s %d]define ANIMATION_NEW:show new animation with capacity num ",__FUNCTION__,__LINE__); 49 dprintf(INFO, "[lk logo: %s %d]CAPACITY_LEFT =%d, CAPACITY_TOP =%d ",__FUNCTION__,__LINE__,(CAPACITY_LEFT) ,(CAPACITY_TOP) ); 50 dprintf(INFO, "[lk logo: %s %d]LCM_HEIGHT=%d, LCM_WIDTH=%d ",__FUNCTION__,__LINE__,(CAPACITY_RIGHT),(CAPACITY_BOTTOM)); 51 if (logonum < 6) { 52 show_animationm_ver = 0 ; 53 } else { 54 show_animationm_ver = 1 ; 55 } 56 } 57 58 }