Commit 0c7edef7 authored by Sanjay Vallimanalan's avatar Sanjay Vallimanalan Committed by Benjamin Cabé
Browse files

soc: mspm0: add power management support



TI MSPM0 series supports range of power modes (RUN/SLEEP, STOP, STANDBY)
supporting low power operations. Provides automatic restoration to
RUN mode on wakeup from any low power state.

Signed-off-by: default avatarSanjay Vallimanalan <sanjay@linumiz.com>
Signed-off-by: default avatarParthiban Nallathambi <parthiban@linumiz.com>
parent 97a587d9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2,3 +2,5 @@

zephyr_sources(soc.c)
zephyr_include_directories(.)

zephyr_sources_ifdef(CONFIG_PM power.c)
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2025 Linumiz GmbH
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <soc.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/pm/pm.h>
#include <zephyr/logging/log.h>

#include <ti/driverlib/driverlib.h>

LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);

static void set_mode_run(uint8_t state)
{
	switch (state) {
	case DL_SYSCTL_POWER_POLICY_RUN_SLEEP0:
		DL_SYSCTL_setPowerPolicyRUN0SLEEP0();
		break;
	case DL_SYSCTL_POWER_POLICY_RUN_SLEEP1:
		DL_SYSCTL_setPowerPolicyRUN1SLEEP1();
		break;
	case DL_SYSCTL_POWER_POLICY_RUN_SLEEP2:
		DL_SYSCTL_setPowerPolicyRUN2SLEEP2();
		break;
	}
}

static void set_mode_stop(uint8_t state)
{
	switch (state) {
	case DL_SYSCTL_POWER_POLICY_STOP0:
		DL_SYSCTL_setPowerPolicySTOP0();
		break;
	case DL_SYSCTL_POWER_POLICY_STOP1:
		DL_SYSCTL_setPowerPolicySTOP1();
		break;
	case DL_SYSCTL_POWER_POLICY_STOP2:
		DL_SYSCTL_setPowerPolicySTOP2();
		break;
	}
}

static void set_mode_standby(uint8_t state)
{
	switch (state) {
	case DL_SYSCTL_POWER_POLICY_STANDBY0:
		DL_SYSCTL_setPowerPolicySTANDBY0();
		break;
	case DL_SYSCTL_POWER_POLICY_STANDBY1:
		DL_SYSCTL_setPowerPolicySTANDBY1();
		break;
	}
}

void pm_state_set(enum pm_state state, uint8_t substate_id)
{
	switch (state) {
	case PM_STATE_RUNTIME_IDLE:
		set_mode_run(substate_id);
		break;
	case PM_STATE_SUSPEND_TO_IDLE:
		set_mode_stop(substate_id);
		break;
	case PM_STATE_STANDBY:
		set_mode_standby(substate_id);
		break;
	default:
		LOG_DBG("Unsupported power state %u", state);
		return;
	}

	__WFI();
}

void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
{
	DL_SYSCTL_setPowerPolicyRUN0SLEEP0();
	irq_unlock(0);
}
+1 −0
Original line number Diff line number Diff line
@@ -13,5 +13,6 @@ config SOC_SERIES_MSPM0G
	select BUILD_OUTPUT_BIN
	select BUILD_OUTPUT_HEX
	select HAS_MSPM0_SDK
	select HAS_PM
	select CLOCK_CONTROL
	select SOC_EARLY_INIT_HOOK
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ config SOC_SERIES_MSPM0L
	select BUILD_OUTPUT_BIN
	select BUILD_OUTPUT_HEX
	select HAS_MSPM0_SDK
	select HAS_PM
	select CLOCK_CONTROL
	select SOC_EARLY_INIT_HOOK