<commit_before>/* Copyright 2021 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.
 */

#include <zephyr.h>
#include <soc.h>

#include "console.h"
#include "cros_version.h"
#include "system.h"

#if IS_ZEPHYR_VERSION(2, 6)
#include <pm/pm.h>
#elif IS_ZEPHYR_VERSION(2, 5)
#include <power/power.h>
#else
#error "Unsupported Zephyr version"
#endif

static const struct pm_state_info pm_min_residency[] =
	PM_STATE_INFO_DT_ITEMS_LIST(DT_NODELABEL(cpu0));

/* CROS PM policy handler */
struct pm_state_info pm_policy_next_state(int32_t ticks)
{
	/* Deep sleep is allowed and console is not in use. */
	if (DEEP_SLEEP_ALLOWED != 0 && !npcx_power_console_is_in_use()) {
		for (int i = ARRAY_SIZE(pm_min_residency) - 1; i >= 0; i--) {
			/* Find suitable power state by residency time */
			if (ticks == K_TICKS_FOREVER ||
			    ticks >= k_us_to_ticks_ceil32(
					     pm_min_residency[i]
						     .min_residency_us)) {
				return pm_min_residency[i];
			}
		}
	}

	return (struct pm_state_info){ PM_STATE_ACTIVE, 0, 0 };
}

/* CROS PM device policy handler */
bool pm_policy_low_power_devices(enum pm_state state)
{
#if IS_ZEPHYR_VERSION(2, 6)
	bool ret = true;

	switch (state) {
	case PM_STATE_RUNTIME_IDLE:
		__fallthrough;
	case PM_STATE_SUSPEND_TO_IDLE:
		__fallthrough;
	case PM_STATE_STANDBY:
		break;
	default:
		ret = false;
		break;
	}

	return ret;
#elif IS_ZEPHYR_VERSION(2, 5)
	return pm_is_sleep_state(state);
#endif
}<commit_msg>zephyr: shim: compile out pm_policy_low_power_devices for v2.6<commit_after>/* Copyright 2021 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.
 */

#include <zephyr.h>
#include <soc.h>

#include "console.h"
#include "cros_version.h"
#include "system.h"

#if IS_ZEPHYR_VERSION(2, 6)
#include <pm/pm.h>
#elif IS_ZEPHYR_VERSION(2, 5)
#include <power/power.h>
#else
#error "Unsupported Zephyr version"
#endif

static const struct pm_state_info pm_min_residency[] =
	PM_STATE_INFO_DT_ITEMS_LIST(DT_NODELABEL(cpu0));

/* CROS PM policy handler */
struct pm_state_info pm_policy_next_state(int32_t ticks)
{
	/* Deep sleep is allowed and console is not in use. */
	if (DEEP_SLEEP_ALLOWED != 0 && !npcx_power_console_is_in_use()) {
		for (int i = ARRAY_SIZE(pm_min_residency) - 1; i >= 0; i--) {
			/* Find suitable power state by residency time */
			if (ticks == K_TICKS_FOREVER ||
			    ticks >= k_us_to_ticks_ceil32(
					     pm_min_residency[i]
						     .min_residency_us)) {
				return pm_min_residency[i];
			}
		}
	}

	return (struct pm_state_info){ PM_STATE_ACTIVE, 0, 0 };
}

#if IS_ZEPHYR_VERSION(2, 5)
/* CROS PM device policy handler */
bool pm_policy_low_power_devices(enum pm_state state)
{
	return pm_is_sleep_state(state);
}
#endif
{'fraction_non_alphanumeric': 0.11022530329289427, 'fraction_numerical': 0.015251299826689775, 'mean_word_length': 4.256830601092896, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '2216335', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1109, 'n_words': 285}