<commit_before>/* Copyright 2015 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/*
 * MEDIATEK SoC power sequencing module for Chrome EC
 *
 * This implements the following features:
 *
 * - Cold reset powers on the AP
 *
 *  When powered off:
 *  - Press pwron turns on the AP
 *  - Hold pwron turns on the AP, and then 10s later turns it off and leaves
 *    it off until pwron is released and pressed again
 *
 *  When powered on:
 *  - The PMIC PWRON signal is released <= 1 second after the power button is
 *    released
 *  - Holding pwron for 10s powers off the AP
 *  - Pressing and releasing pwron within that 10s is ignored
 *  - If POWER_GOOD is dropped by the AP, then we power the AP off
 *  - If SUSPEND_L goes low, enter suspend mode.
 *
 */

#include "battery.h"
#include "chipset.h" /* ./common/chipset.c implements chipset functions too */
#include "common.h"
#include "gpio.h"
#include "hooks.h"
#include "keyboard_scan.h"
#include "lid_switch.h"
#include "power.h"
#include "power_button.h"
#include "power_led.h"
#include "system.h"
#include "task.h"
#include "test_util.h"
#include "util.h"

#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)

#define INT_BOTH_PULL_UP	(GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH)

/* masks for power signals */
#define IN_POWER_GOOD POWER_SIGNAL_MASK(MTK_POWER_GOOD)
#define IN_SUSPEND POWER_SIGNAL_MASK(MTK_SUSPEND_ASSERTED)

/* Long power key press to force shutdown */
#define DELAY_FORCE_SHUTDOWN  (10000 * MSEC)	/* 10 seconds */

/*
 * The minimum time to assert the PMIC PWRON pin is 20ms.
 * Give it longer to ensure the PMIC doesn't lose it.
 */
#define PMIC_PWRON_DEBOUNCE_TIME  (60 * MSEC)

/*
 * The power signal from SoC should be kept at least 50ms.
 */
#define POWER_DEBOUNCE_TIME     (50 * MSEC)

/*
 * The time to bootup the PMIC from power-off to power-on.
 */
#define PMIC_PWRON_PRESS_TIME   (5000 * MSEC)

/*
 * The minimum time to assert the PMIC THERM pin is 32us. However,
 * it needs to be extended to about 50ms to let the 5V rail
 * dissipate fully.
 */
#define PMIC_THERM_HOLD_TIME  (50 * MSEC)

/*
 * If the power key is pressed to turn on, then held for this long, we
 * power off.
 *
 * Normal case: User releases power button and chipset_task() goes
 *    into the inner loop, waiting for next event to occur (power button
 *    press or POWER_GOOD == 0).
 */
#define DELAY_SHUTDOWN_ON_POWER_HOLD	(10000 * MSEC)	/* 10 seconds */

/*<commit_msg>oak: power: set 8s for long power key press to force shutdown<commit_after>/* Copyright 2015 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/*
 * MEDIATEK SoC power sequencing module for Chrome EC
 *
 * This implements the following features:
 *
 * - Cold reset powers on the AP
 *
 *  When powered off:
 *  - Press pwron turns on the AP
 *  - Hold pwron turns on the AP, and then 8s later turns it off and leaves
 *    it off until pwron is released and pressed again
 *
 *  When powered on:
 *  - The PMIC PWRON signal is released <= 1 second after the power button is
 *    released
 *  - Holding pwron for 8s powers off the AP
 *  - Pressing and releasing pwron within that 8s is ignored
 *  - If POWER_GOOD is dropped by the AP, then we power the AP off
 *  - If SUSPEND_L goes low, enter suspend mode.
 *
 */

#include "battery.h"
#include "chipset.h" /* ./common/chipset.c implements chipset functions too */
#include "common.h"
#include "gpio.h"
#include "hooks.h"
#include "keyboard_scan.h"
#include "lid_switch.h"
#include "power.h"
#include "power_button.h"
#include "power_led.h"
#include "system.h"
#include "task.h"
#include "test_util.h"
#include "util.h"

#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)

#define INT_BOTH_PULL_UP	(GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH)

/* masks for power signals */
#define IN_POWER_GOOD POWER_SIGNAL_MASK(MTK_POWER_GOOD)
#define IN_SUSPEND POWER_SIGNAL_MASK(MTK_SUSPEND_ASSERTED)

/* Long power key press to force shutdown */
#define DELAY_FORCE_SHUTDOWN  (8000 * MSEC)	/* 8 seconds */

/*
 * The minimum time to assert the PMIC PWRON pin is 20ms.
 * Give it longer to ensure the PMIC doesn't lose it.
 */
#define PMIC_PWRON_DEBOUNCE_TIME  (60 * MSEC)

/*
 * The power signal from SoC should be kept at least 50ms.
 */
#define POWER_DEBOUNCE_TIME     (50 * MSEC)

/*
 * The time to bootup the PMIC from power-off to power-on.
 */
#define PMIC_PWRON_PRESS_TIME   (5000 * MSEC)

/*
 * The minimum time to assert the PMIC THERM pin is 32us. However,
 * it needs to be extended to about 50ms to let the 5V rail
 * dissipate fully.
 */
#define PMIC_THERM_HOLD_TIME  (50 * MSEC)

/*
 * If the power key is pressed to turn on, then held for this long, we
 * power off.
 *
 * Normal case: User releases power button and chipset_task() goes
 *    into the inner loop, waiting for next event to occur (power button
 *    press or POWER_GOOD == 0).
 */
#define DELAY_SHUTDOWN_ON_POWER_HOLD	(8000 * MSEC)	/* 8 seconds */

/*
{'fraction_non_alphanumeric': 0.09272550921435499, 'fraction_numerical': 0.016294859359844812, 'mean_word_length': 3.530755711775044, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2527875', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1761, 'n_words': 681}