MTK 关机充电

充电相关文件目录 alps\vendor\mediatek\proprietary\external\charger\

充电控制函数:charging_control.cpp

// total_time : ms
// interval : ms
static void draw_with_interval(void (*func)(int, int), int bc, int total_time_msec, int interval_msec)
{
	struct timeval start;
	int resume_started = 0, backlight_started = 0, cnt = 0;
	int fd_fb = -1, err = 0;
	char filename[32] = {0};
	gettimeofday(&start, NULL);

	while((!time_exceed(start, total_time_msec)) && (common_flag == false))
	{
        // check if need to draw animation before performing drawing
		if (!is_charging_source_available())
			return;
		if (!resume_started) {
			resume_started = 1;
			request_suspend(false);
			/* make fb unblank */
			snprintf(filename, sizeof(filename), "/dev/graphics/fb0");
			fd_fb = open(filename, O_RDWR);
			if (fd_fb < 0) {
				KPOC_LOGI("Failed to open fb0 device: %s", strerror(errno));
			}
			err = ioctl(fd_fb, FBIOBLANK, FB_BLANK_UNBLANK);
			if (err < 0) {
				KPOC_LOGI("Failed to unblank fb0 device: %s", strerror(errno));
			}
			if (fd_fb >= 0)
				close(fd_fb);
		}

		func(bc, ++cnt);
		if (!backlight_started) {
			backlight_started = 1;
			usleep(200*1000);
			start_backlight();
		}
		KPOC_LOGI("draw_with_interval... key_trigger_suspend = %d\n",key_trigger_suspend);
		usleep(interval_msec*1000);
	}
}
#define charging_source_waiting_duration_ms 3000
#define charging_source_waiting_interval_ms 200

static void* draw_thread_routine(void *arg)
{
	int i, bc, bc_offset = 0;
	int fd_fb = -1, err =0;
	char buf[PROPERTY_VALUE_MAX];
	char filename[32] = {0};
	
    // protect the following critical section for the 1st time
    pthread_mutex_lock(&mutex);
	do {
		KPOC_LOGI("draw thread working...\n");
        // move here to avoid suspend when syncing with surfaceflinger
		//在别处初始化为 1
        if(firstTime){
            // make sure charging source online when in KPOC mode
            // add 2s tolerance
            if(wait_until(is_charging_source_available, 
                        charging_source_waiting_duration_ms,
                        charging_source_waiting_interval_ms))
            {
                KPOC_LOGI("wait until charging source available\n");
            }else{
                KPOC_LOGI("charging source not available for %d ms at KPOC starup\n",
                        charging_source_waiting_duration_ms);
            }
            firstTime = 0;
        }

		inDraw = 1;

		// check the bc offest value
		bc = get_capacity();
		//这个函数内部有一段时间的循环控制,最主要是这个函数操作图标显示以及背光开与关
		draw_with_interval(bootlogo_show_charging, bc, nChgAnimDuration_msec, nCbInterval_msec);
		
		stop_backlight();

        // @@@ draw fb again to refresh ddp
        bootlogo_show_charging(bc, 1);

		/* make fb blank */
		snprintf(filename, sizeof(filename), "/dev/graphics/fb0");
		fd_fb = open(filename, O_RDWR);
		if (fd_fb < 0) {
			KPOC_LOGI("Failed to open fb0 device: %s", strerror(errno));
		}
		err = ioctl(fd_fb, FBIOBLANK, FB_BLANK_POWERDOWN);
		if (err < 0) {
			KPOC_LOGI("Failed to blank fb0 device: %s", strerror(errno));
		}
		if (fd_fb >= 0)
			close(fd_fb);
		//循环一遍之后,进入睡眠
		request_suspend(true);

		inDraw = 0;

		pthread_mutex_unlock(&mutex);

		KPOC_LOGI("draw thread waiting...\n");
        pthread_mutex_lock(&mutex);
		pthread_cond_wait(&cond, &mutex);

	} while(1);
	pthread_exit(NULL);
	return NULL;
}
void charging_control()
{
	firstTime = 1;
	ret = pthread_create(&draw_thread, &attrd, draw_thread_routine, NULL);
}

充电是会被编译成模块的,最终生成 system/vendor/bin/kpoc_charger

kernel-3.18\drivers\misc\mediatek\video\common\aal20\ddp_pwm.c

vendor\mediatek\proprietary\bootable\bootloader\lk\platform\mt6735\ddp_pwm.c

以上两个文件的函数都会被用到 

注意:关机充电需要对背光的结点具有读写权限

device\mediatek\common\sepolicy\bsp\kpoc_charger.te中添加

allow kpoc_charger lcd_bl_file:file rw_file_perms;

device\mediatek\common\sepolicy\bsp\file.te中添加

type lcd_bl_file, file_type,sysfs_type;

device\mediatek\common\sepolicy\bsp\file_contexts中添加

/sys/devices/platform/leds-mt65xx/leds/lcd-backlight/brightness u:object_r:lcd_bl_file:s0

device\mediatek\common\sepolicy\bsp\system_app.te中添加

allow system_app lcd_bl_file:file rw_file_perms; 

device\mediatek\common\sepolicy\bsp\system_server.te中添加

allow system_server lcd_bl_file:file rw_file_perms;

 

转载于:https://my.oschina.net/u/592470/blog/887096

你可能感兴趣的:(MTK 关机充电)