Esempio n. 1
0
/**
 * Update backlight state.
 */
static void update_backlight(void)
{
	/*
	 * Enable backlight if lid is open; this is AND'd with the request from
	 * the AP in hardware.
	 */
	gpio_set_level(GPIO_ENABLE_BACKLIGHT, lid_is_open());
	if (lid_is_open())
		hook_call_deferred(&lp8555_enable_pwm_mode_data, 0);
}
/**
 * Update backlight state.
 */
static void update_backlight(void)
{
#ifdef CONFIG_BACKLIGHT_REQ_GPIO
	/* Enable the backlight if lid is open AND requested by AP */
	gpio_set_level(GPIO_ENABLE_BACKLIGHT, lid_is_open() &&
		       gpio_get_level(CONFIG_BACKLIGHT_REQ_GPIO));
#else
	/*
	 * Enable backlight if lid is open; this is AND'd with the request from
	 * the AP in hardware.
	 */
	gpio_set_level(GPIO_ENABLE_BACKLIGHT, lid_is_open());
#endif
}
Esempio n. 3
0
/**
 * Update status of non-debounced switches.
 *
 * Note that deferred functions are called in the same context as lid and
 * power button changes, so we don't need a mutex.
 */
static void switch_update(void)
{
	static uint8_t prev;

	/* Make sure this is safe to call before power_button_init() */
	if (!memmap_switches)
		return;

	prev = *memmap_switches;

	if (power_button_is_pressed())
		*memmap_switches |= EC_SWITCH_POWER_BUTTON_PRESSED;
	else
		*memmap_switches &= ~EC_SWITCH_POWER_BUTTON_PRESSED;

	if (lid_is_open())
		*memmap_switches |= EC_SWITCH_LID_OPEN;
	else
		*memmap_switches &= ~EC_SWITCH_LID_OPEN;

	if ((flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) == 0)
		*memmap_switches |= EC_SWITCH_WRITE_PROTECT_DISABLED;
	else
		*memmap_switches &= ~EC_SWITCH_WRITE_PROTECT_DISABLED;

#ifdef CONFIG_SWITCH_DEDICATED_RECOVERY
	if (gpio_get_level(GPIO_RECOVERY_L) == 0)
		*memmap_switches |= EC_SWITCH_DEDICATED_RECOVERY;
	else
		*memmap_switches &= ~EC_SWITCH_DEDICATED_RECOVERY;
#endif

	if (prev != *memmap_switches)
		CPRINTS("SW 0x%02x", *memmap_switches);
}
Esempio n. 4
0
static void fake_hibernate_lid_hook(void)
{
	if (fake_hibernate && lid_is_open()) {
		ccprints("%s() resets EC", __func__);
		cflush();
		system_reset(SYSTEM_RESET_HARD);
	}
}
Esempio n. 5
0
static void rockchip_lid_event(void)
{
	/* Power task only cares about lid-open events */
	if (!lid_is_open())
		return;

	lid_opened = 1;
	task_wake(TASK_ID_CHIPSET);
}
Esempio n. 6
0
void gesture_calc(uint32_t *event)
{
	/* Only check for gesture if lid is closed and tap detection is on */
	if (!tap_detection || lid_is_open())
		return;

	if (gesture_tap_for_battery())
		*event |= CONFIG_GESTURE_TAP_EVENT;
}
Esempio n. 7
0
static void hang_detect_lid(void)
{
	if (lid_is_open()) {
		if (hdparams.flags & EC_HANG_START_ON_LID_OPEN)
			hang_detect_start("lid open");
	} else {
		if (hdparams.flags & EC_HANG_START_ON_LID_CLOSE)
			hang_detect_start("lid close");
	}
}
Esempio n. 8
0
static void update_touchscreen(void)
{
	/*
	 * If the lid is closed; put the touchscreen in reset to save power.
	 * If the lid is open, take it out of reset so it can wake the
	 * processor (although just opening the lid should do that anyway, so
	 * we don't have to worry about it staying on while the AP is off).
	 */
	gpio_set_level(GPIO_TOUCHSCREEN_RESET_L, lid_is_open());
}
Esempio n. 9
0
void gesture_calc(void)
{
	/* Only check for gesture if lid is closed and tap detection is on */
	if (!tap_detection || lid_is_open())
		return;

	if (gesture_tap_for_battery()) {
		CPRINTS("Double Tap!");
		lightbar_sequence(LIGHTBAR_TAP);

		/* Don't need to run motion sense task for a while */
		task_wait_event(500 * MSEC);
	}
}
Esempio n. 10
0
static int pwr_led_set_color(enum led_color color)
{
	switch (color) {
	case LED_OFF:
		gpio_set_level(GPIO_POWER_LED, POWER_LED_OFF);
		break;
	case LED_WHITE:
		gpio_set_level(GPIO_POWER_LED,
			       lid_is_open() ? POWER_LED_ON : POWER_LED_OFF);
		break;
	default:
		return EC_ERROR_UNKNOWN;
	}
	return EC_SUCCESS;
}
Esempio n. 11
0
/**
 * Get raw power button signal state.
 *
 * @return 1 if power button is pressed, 0 if not pressed.
 */
static int raw_power_button_pressed(void)
{
	if (simulate_power_pressed)
		return 1;

#ifndef CONFIG_POWER_BUTTON_IGNORE_LID
	/*
	 * Always indicate power button released if the lid is closed.
	 * This prevents waking the system if the device is squashed enough to
	 * press the power button through the closed lid.
	 */
	if (!lid_is_open())
		return 0;
#endif

	return power_button_signal_asserted();
}
Esempio n. 12
0
/**
 * Setup backlight controller and turn it on.
 */
static void lp8555_enable_pwm_mode(void)
{
	int reg;
	int rv;

	/*
	 * If not in S0, then PCH backlight enable will not be on, and if
	 * lid is closed EC backlight enable will not be on. Since these
	 * two signals are AND'ed together, no point in trying to talk to
	 * the lp8555 if either one of them is not true.
	 */
	if (!chipset_in_state(CHIPSET_STATE_ON) || !lid_is_open())
		return;

	/* Enable PWM mode. */
	rv = lp8555_read_with_retry(LP8555_REG_CONFIG, &reg);
	if (rv != EC_SUCCESS)
		return;
	reg &= ~LP8555_REG_CONFIG_MODE_MASK;
	reg |= LP8555_REG_CONFIG_MODE_PWM;
	rv = lp8555_write_with_retry(LP8555_REG_CONFIG, reg);
	if (rv != EC_SUCCESS)
		return;

	/* Set max LED current to 23mA. */
	rv = lp8555_write_with_retry(LP8555_REG_CURRENT,
				     LP8555_REG_CURRENT_MAXCURR_23MA);
	if (rv != EC_SUCCESS)
		return;

	/* Set the rate of brightness change. */
	rv = lp8555_write_with_retry(LP8555_REG_STEP,
				     LP8555_REG_STEP_STEP_200MS |
				     LP8555_REG_STEP_PWM_IN_HYST_8LSB |
				     LP8555_REG_STEP_SMOOTH_HEAVY);
	if (rv != EC_SUCCESS)
		return;

	/* Power on. */
	rv = lp8555_read_with_retry(LP8555_REG_COMMAND, &reg);
	if (rv != EC_SUCCESS)
		return;
	reg |= LP8555_REG_COMMAND_ON;
	rv = lp8555_write_with_retry(LP8555_REG_COMMAND, reg);
}
Esempio n. 13
0
/* Console commands */
static int command_tap_info(int argc, char **argv)
{
	int val;

	ccprintf("tap:   %s\n", (tap_detection && !lid_is_open()) ?
					"on" : "off");

	if (argc > 1) {
		if (!parse_bool(argv[1], &val))
			return EC_ERROR_PARAM1;
		tap_debug = val;
	}

	ccprintf("debug: %s\n", tap_debug ? "on" : "off");
	ccprintf("odr:   %d\n", sensor->drv->get_data_rate(sensor));

	return EC_SUCCESS;
}
Esempio n. 14
0
int main()
{
    init_timer();
    init_ATX_power();
    init_serial();
    init_stdio();
    init_safety_switches();
    init_i2c();
    init_laser_power();
    init_heaters();
    init_main_laser();
    sei();

    enable_ATX_power();
    uint32_t b = millisecond_time();
    while (!ATX_power_state()) {
        enable_ATX_power();
        continue;
    }
    uint32_t a = millisecond_time();
    printf("ATX power: %ld msec\n", a - b);
    enable_heater_1();          // aka water pump
    delay_milliseconds(2000);
    enable_heater_0();          // aka high voltage supply
    set_laser_power(4095 / 3);  // 1/3rd power
    printf("Main Laser!  Danger!\n");

    while (true) {
        if (getchar() == '\r') {
            if (e_is_stopped())
                printf("Emergency Stop.  No fire.\n");
            else if (lid_is_open())
                printf("Lid is open.  No fire.\n");
            else {
                printf("Fire!\n");
                enable_main_laser();
                delay_milliseconds(PULSE_MS);
                disable_main_laser();
            }
        }
    }
}
Esempio n. 15
0
/**
 * Update backlight state.
 */
static void update_backlight(void)
{
	int pch_value;

	pch_value = gpio_get_level(GPIO_PCH_BKLTEN);

	/* Immediately disable the backlight when the lid is closed or the PCH
	 * is instructing the backlight to be disabled. */
	if (!lid_is_open() || !pch_value) {
		/* If there was a scheduled callback pending make sure it picks
		 * up the disabled value. */
		backlight_deferred_value = 0;
		gpio_set_level(GPIO_ENABLE_BACKLIGHT, 0);
		/* Cancel pending hook */
		hook_call_deferred(&set_backlight_value, -1);
		return;
	}
	/* Handle a 0->1 transition by calling a deferred hook. */
	if (pch_value && !backlight_deferred_value) {
		backlight_deferred_value = 1;
		hook_call_deferred(&set_backlight_value, BL_ENABLE_DELAY_US);
	}
}
Esempio n. 16
0
enum power_state power_handle_state(enum power_state state)
{
	int value;
	static int boot_from_g3;

	switch (state) {
	case POWER_G3:
		boot_from_g3 = check_for_power_on_event();
		if (boot_from_g3)
			return POWER_G3S5;
		break;

	case POWER_G3S5:
		return POWER_S5;

	case POWER_S5:
		if (boot_from_g3) {
			value = boot_from_g3;
			boot_from_g3 = 0;
		} else {
			value = check_for_power_on_event();
		}

		if (value) {
			CPRINTS("power on %d", value);
			return POWER_S5S3;
		}
		return state;

	case POWER_S5S3:
		hook_notify(HOOK_CHIPSET_PRE_INIT);

		power_on();

		disable_sleep(SLEEP_MASK_AP_RUN);
		powerled_set_state(POWERLED_STATE_ON);

		if (power_wait_signals(IN_POWER_GOOD) == EC_SUCCESS) {
			CPRINTS("POWER_GOOD seen");
			if (power_button_wait_for_release(
					DELAY_SHUTDOWN_ON_POWER_HOLD) ==
					EC_SUCCESS) {
				power_button_was_pressed = 0;
				set_pmic_pwron(0);

				/* setup misc gpio for S3/S0 functionality */
				gpio_set_flags(GPIO_SUSPEND_L, GPIO_INPUT
					| GPIO_INT_BOTH | GPIO_PULL_DOWN);
				gpio_set_flags(GPIO_EC_INT_L, GPIO_OUTPUT
						| GPIO_OUT_HIGH);

				/* Call hooks now that AP is running */
				hook_notify(HOOK_CHIPSET_STARTUP);

				return POWER_S3;
			} else {
				CPRINTS("long-press button, shutdown");
				power_off();
				/*
				 * Since the AP may be up already, return S0S3
				 * state to go through the suspend hook.
				 */
				return POWER_S0S3;
			}
		} else {
			CPRINTS("POWER_GOOD not seen in time");
		}

		chipset_turn_off_power_rails();
		return POWER_S5;

	case POWER_S3:
		if (!(power_get_signals() & IN_POWER_GOOD))
			return POWER_S3S5;
		else if (!(power_get_signals() & IN_SUSPEND))
			return POWER_S3S0;
		return state;

	case POWER_S3S0:
		powerled_set_state(POWERLED_STATE_ON);
		hook_notify(HOOK_CHIPSET_RESUME);
		return POWER_S0;

	case POWER_S0:
		value = check_for_power_off_event();
		if (value) {
			CPRINTS("power off %d", value);
			power_off();
			return POWER_S0S3;
		} else if (power_get_signals() & IN_SUSPEND)
			return POWER_S0S3;
		return state;

	case POWER_S0S3:
		if (lid_is_open())
			powerled_set_state(POWERLED_STATE_SUSPEND);
		else
			powerled_set_state(POWERLED_STATE_OFF);
		/* Call hooks here since we don't know it prior to AP suspend */
		hook_notify(HOOK_CHIPSET_SUSPEND);
		return POWER_S3;

	case POWER_S3S5:
		power_button_wait_for_release(-1);
		power_button_was_pressed = 0;
		return POWER_S5;

	case POWER_S5G3:
		return POWER_G3;
	}

	return state;
}
Esempio n. 17
0
/**
 * Initialize backlight module.
 */
static void backlight_init(void)
{
	gpio_enable_interrupt(GPIO_PCH_BL_EN);
	gpio_set_level(GPIO_ENABLE_BACKLIGHT, lid_is_open());
}
Esempio n. 18
0
static void inductive_charging_deferred_update(void)
{
	int lid_open = lid_is_open();
	gpio_set_level(GPIO_BASE_CHG_VDD_EN, !lid_open);
	inductive_charging_interrupt(GPIO_LID_OPEN);
}
Esempio n. 19
0
/**
 * Handle switch changes based on lid event.
 */
static void powerbtn_x86_lid_change(void)
{
	/* If chipset is off, pulse the power button on lid open to wake it. */
	if (lid_is_open() && chipset_in_state(CHIPSET_STATE_ANY_OFF))
		power_button_pch_pulse();
}
Esempio n. 20
0
static void pwm_kblight_lid_change(void)
{
	pwm_enable(PWM_CH_KBLIGHT, lid_is_open());
}
Esempio n. 21
0
static void wait_for_lid_debounce(void)
{
	while (lid_is_open() != gpio_get_level(GPIO_LID_OPEN))
		msleep(20);
}