/*
 * Main timer handle: check every PWRKEY_DETECT_FREQUENCY to see
 * if power key is pressed.
 * Shutdown the device if power key is release before
 * (PWRKEY_LONG_PRESS_COUNT/MPM_SLEEP_TIMETICK_COUNT) seconds.
 */
static enum handler_return long_press_pwrkey_timer_func(struct timer *p_timer,
	void *arg)
{
	uint32_t sclk_count = platform_get_sclk_count();

	/*
	 * The following condition is treated as the power key
	 * is pressed long enough.
	 * 1. if the power key is pressed last for PWRKEY_LONG_PRESS_COUNT.
	 */
	if (sclk_count > PWRKEY_LONG_PRESS_COUNT) {
		timer_cancel(p_timer);
		pon_timer_complete = 1;
	} else {
		if (pm8x41_get_pwrkey_is_pressed()) {
			/*
			 * For normal man response is > 0.1 secs, so we use 0.05 secs default
			 * for software to be safely detect if there is a key release action.
			 */
			timer_set_oneshot(p_timer, PWRKEY_DETECT_FREQUENCY,
				long_press_pwrkey_timer_func, NULL);
		} else {
			shutdown_device();
		}
	}

	return INT_RESCHEDULE;
}
Esempio n. 2
0
/*
 * Function to support for shutdown detection
 * If below condition is met, the function will shut down
 * the device. Otherwise it will do nothing and return to
 * normal boot.
 * condition:
 * 1. it is triggered by power key &&
 * 2. the power key is released before
 * (PWRKEY_LONG_PRESS_COUNT/MPM_SLEEP_TIMETICK_COUNT) seconds.
 */
void shutdown_detect()
{
	/*
	 * If it is booted by power key tirigger.
	 * Initialize pon_timer and call long_press_pwrkey_timer_func
	 * function to check if the power key is last press long enough.
	 */
	if (is_pwrkey_pon_reason()) {
		if(!pm8x41_get_pwrkey_is_pressed()){
			shutdown_device();
		}
		timer_initialize(&pon_timer);
		timer_set_oneshot(&pon_timer, 0,(timer_callback)long_press_pwrkey_timer_func, NULL);

		/*
		 * Wait until long press power key timeout
		 *
		 * It will be confused to end users if we shutdown the device
		 * after the splash screen displayed. But it can be moved the
		 * wait here if the boot time is much more considered.
		 */
		wait_for_long_pwrkey_pressed();
	}
}
Esempio n. 3
0
static int target_power_key(void)
{
	return pm8x41_get_pwrkey_is_pressed();
}