Debian Codegraph @

src/vendorcode/google/chromeos/battery.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <ec/google/chromeec/ec.h>
4 #include <bootsplash.h>
5
6 /*
7 * Check if low battery shutdown is needed
8 *
9 * This function checks if the system needs to shut down due to a critically low
10 * battery level. It performs the following actions:
11 *
12 * 1. If Chrome EC is not supported, returns false (no shutdown needed).
13 * 2. Uses static variables to cache the result and avoid repeated checks.
14 * 3. If the battery level has not been checked yet:
15 * - Queries the Chrome EC to determine if the battery is below the critical threshold.
16 * - If the battery is below the threshold, sets the result to true.
17 * 4. Returns the cached result.
18 */
19 bool platform_is_low_battery_shutdown_needed(void)
20 {
21 if (!CONFIG(EC_GOOGLE_CHROMEEC))
22 return false;
23
24 static bool result = false;
25 static bool checked = false;
26
27 if (!checked) {
28 if (google_chromeec_is_below_critical_threshold())
29 result = true;
30 checked = true;
31 }
32
33 return result;
34 }