<commit_before>/*
 * Copyright (c) 2021 <NAME>
 *
 * SPDX-License-Identifier: Apache-2.0
 */
#include <zephyr.h>
#include <pm/pm.h>
#include <soc.h>
#include <init.h>

#include <stm32wlxx_ll_utils.h>
#include <stm32wlxx_ll_bus.h>
#include <stm32wlxx_ll_cortex.h>
#include <stm32wlxx_ll_pwr.h>
#include <stm32wlxx_ll_rcc.h>
#include <stm32wlxx_ll_system.h>
#include <clock_control/clock_stm32_ll_common.h>

#include <logging/log.h>
LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);

/* Invoke Low Power/System Off specific Tasks */
__weak void pm_power_state_set(struct pm_state_info info)
{
	switch (info.state) {
	case PM_STATE_SUSPEND_TO_IDLE:
		LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI);
		LL_PWR_ClearFlag_WU();
		switch (info.substate_id) {
		case 1:
			LL_PWR_SetPowerMode(LL_PWR_MODE_STOP0);
			break;
		case 2:
			LL_PWR_SetPowerMode(LL_PWR_MODE_STOP1);
			break;
		case 3:
			LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
			break;
		default:
			LOG_DBG("Unsupported power substate-id %u", info.substate_id);
			return;
		}
		LL_LPM_EnableDeepSleep();
		k_cpu_idle();
		break;
	case PM_STATE_SOFT_OFF:
		LL_PWR_ClearFlag_WU();
		switch (info.substate_id) {
		case 0:
			LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
			break;
		case 1:
			LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);<commit_msg>soc: arm: stm32wl: wakeup from stop clock selection based on sysclk<commit_after>/*
 * Copyright (c) 2021 <NAME>
 *
 * SPDX-License-Identifier: Apache-2.0
 */
#include <zephyr.h>
#include <pm/pm.h>
#include <soc.h>
#include <init.h>

#include <stm32wlxx_ll_utils.h>
#include <stm32wlxx_ll_bus.h>
#include <stm32wlxx_ll_cortex.h>
#include <stm32wlxx_ll_pwr.h>
#include <stm32wlxx_ll_rcc.h>
#include <stm32wlxx_ll_system.h>
#include <clock_control/clock_stm32_ll_common.h>
#include <drivers/clock_control/stm32_clock_control.h>

#include <logging/log.h>
LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);

/* select MSI as wake-up system clock if configured, HSI otherwise */
#if STM32_SYSCLK_SRC_MSI
#define RCC_STOP_WAKEUPCLOCK_SELECTED LL_RCC_STOP_WAKEUPCLOCK_MSI
#else
#define RCC_STOP_WAKEUPCLOCK_SELECTED LL_RCC_STOP_WAKEUPCLOCK_HSI
#endif

/* Invoke Low Power/System Off specific Tasks */
__weak void pm_power_state_set(struct pm_state_info info)
{
	switch (info.state) {
	case PM_STATE_SUSPEND_TO_IDLE:
		LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED);
		LL_PWR_ClearFlag_WU();
		switch (info.substate_id) {
		case 1:
			LL_PWR_SetPowerMode(LL_PWR_MODE_STOP0);
			break;
		case 2:
			LL_PWR_SetPowerMode(LL_PWR_MODE_STOP1);
			break;
		case 3:
			LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
			break;
		default:
			LOG_DBG("Unsupported power substate-id %u", info.substate_id);
			return;
		}
		LL_LPM_EnableDeepSleep();
		k_cpu_idle();
		break;
	case PM_STATE_SOFT_OFF:
		LL_PWR_ClearFlag_WU();
		switch (info.substate_id) {
		case 0:
			LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
			break;
		case 1:
			LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
{'fraction_non_alphanumeric': 0.10654079568442347, 'fraction_numerical': 0.020903573836817263, 'mean_word_length': 5.773972602739726, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, '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': '2248008', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1287, 'n_words': 203}