- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3
 
soc: mspm0: add power management support #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c790220
              0ac0e69
              27d9843
              9db609a
              aaa58b1
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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); | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright (c) 2025 Linumiz GmbH | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| 
     | 
||
| #include <soc.h> | ||
| #include <zephyr/drivers/hwinfo.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/sys/poweroff.h> | ||
| #include <zephyr/toolchain.h> | ||
| 
     | 
||
| #include <ti/driverlib/driverlib.h> | ||
| 
     | 
||
| void z_sys_poweroff(void) | ||
| { | ||
| DL_SYSCTL_setPowerPolicySHUTDOWN(); | ||
| __WFI(); | ||
| 
     | 
||
| CODE_UNREACHABLE; | ||
| } | ||
| 
     | 
||
| static int ti_mspm0_poweroff_init(void) | ||
| { | ||
| int ret; | ||
| uint32_t rst_cause; | ||
| 
     | 
||
| ret = hwinfo_get_reset_cause(&rst_cause); | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. depends on HWINFO driver  | 
||
| if (ret != 0) { | ||
| return ret; | ||
| } | ||
| 
     | 
||
| if (RESET_LOW_POWER_WAKE == rst_cause) { | ||
| DL_SYSCTL_releaseShutdownIO(); | ||
| } | ||
| 
     | 
||
| return 0; | ||
| } | ||
| 
     | 
||
| SYS_INIT(ti_mspm0_poweroff_init, POST_KERNEL, 0); | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -13,5 +13,7 @@ config SOC_SERIES_MSPM0G | |
| select BUILD_OUTPUT_BIN | ||
| select BUILD_OUTPUT_HEX | ||
| select HAS_MSPM0_SDK | ||
| select HAS_PM | ||
| select HAS_POWEROFF | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this as well to poweroff commit  | 
||
| select CLOCK_CONTROL | ||
| select SOC_EARLY_INIT_HOOK | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -12,6 +12,8 @@ config SOC_SERIES_MSPM0L | |
| select BUILD_OUTPUT_BIN | ||
| select BUILD_OUTPUT_HEX | ||
| select HAS_MSPM0_SDK | ||
| select HAS_PM | ||
| select HAS_POWEROFF | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto  | 
||
| select CLOCK_CONTROL | ||
| select SOC_EARLY_INIT_HOOK | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate commit for poweroff