Skip to content

soc : realtek: ec: rts5912: add support ULPM #86717

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

Merged
merged 1 commit into from
Apr 24, 2025

Conversation

Titan-Realtek
Copy link
Contributor

Port rts5912 ULPM on Zephyr

Comment on lines 9 to 23
status:
type: string
description: indicates the operational status of a device
enum:
- "ok" # Deprecated form
- "okay"
- "disabled"
- "reserved"
- "fail"
- "fail-sss"

compatible:
type: string-array
required: true
description: compatible strings
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not do this, include the base definition properly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks.

@@ -9,6 +9,7 @@ config SOC_SERIES_RTS5912
select SYS_CLOCK_EXISTS
select DYNAMIC_INTERRUPTS
select SOC_EARLY_INIT_HOOK
select HAS_POWEROFF if(SOC_RTS5912_ULPM)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
select HAS_POWEROFF if(SOC_RTS5912_ULPM)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks.


wkup-pin@0 {
reg = <0x0>;
/* wkup-pin-pol; */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented lines to go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks.

bool "Realtek RTS5912 ULPM (Ultra Low Power Mode)"
default y
depends on DT_HAS_REALTEK_RTS5912_ULPM_ENABLED
select POWEROFF
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
select POWEROFF
select HAS_POWEROFF

Users select POWEROFF if they want it not a soc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks.

@Titan-Realtek Titan-Realtek force-pushed the soc_ulpm_rts5912 branch 3 times, most recently from 9aa63f3 to 7d15a9a Compare March 9, 2025 22:41
@Titan-Realtek Titan-Realtek requested a review from nordicjm March 14, 2025 11:32
nordicjm
nordicjm previously approved these changes Mar 14, 2025

#define RTS5912_ULPM_NODE DT_NODELABEL(ulpm)

#define ULPM_RTS5912_MAX_NB_WKUP_PINS DT_INST_PROP(0, wkup_pins_nb)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace the wkup-pins-nb property with the macro DT_INST_CHILD_NUM_STATUS_OKAY(0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Keith
The wkup-pins-nb is used to check whether the id assigned to a child node exceeds the boundary.
There is another definition to calculate the child number.

#define WKUP_PIN_SIZE ARRAY_SIZE(wkup_pins_cfgs)

The max wkup pin number can prevent if someone add another new child and assign a wrong id number.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest renaming the property wkup-pins-max.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


#define ULPM_SLEEP(x) k_msleep(x)

#define RTS5912_ULPM_NODE DT_NODELABEL(ulpm)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use DT_DRV_INST(0) instead of the nodelabel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/** @endcond */

static struct wkup_pin_dt_cfg_t wkup_pins_cfgs[] = {
DT_FOREACH_CHILD(RTS5912_ULPM_NODE, WKUP_PIN_CFG_DT_COMMA)};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use DT_INST_FOREACH_CHILD(0, WKUP_PIN_CFG_DT_COMMA)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/**
* @brief Enable VOUT function and set the VOUT default value.
*/
void ULPMStart(void)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use snake-case for C code.
https://docs.zephyrproject.org/latest/contribute/style/code.html

Please fix all functions and variables added in this PR to use snake-case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

GPIO_Type *gpio_reg = RTS5912_GPIO_REG_BASE;
int i, id;

printk("rts5912 ULPM enabled\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use logging instead of printk throughout the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 38 to 41
wkup-pin-pol-auto:
type: boolean
description: |
True if auto detect current VIN level and set opposite polarity.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of the value of the `wkup-pin-pol-auto' property. The current state of the pin could change depending on the order drivers initialize.

I think it is enough that you include wkup-pin-pol property to explicitly set the polarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed. done.

Comment on lines 154 to 164
if (wkup_pins_cfgs[i].wkup_pin_pol_auto) {
/* get current pin state */
if (gpio_reg->GCR[RTS5912_VIN_GPIO_INDEX + id] &
GPIO_GCR_PINSTS_Msk) { /* Falling Edge */
sys_reg->VIVOCTRL |= BIT(SYSTEM_VIVOCTRL_VIN0POL_Pos + id);
printk("Falling Edge\n");
} else {
/* Rising Edge */
sys_reg->VIVOCTRL &= ~BIT(SYSTEM_VIVOCTRL_VIN0POL_Pos + id);
printk("Rising Edge\n");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't read the GPIO pin state by directly accessing the register. Instead you should add a gpios property to the node and use gpio_pin_get_raw().

However, I don't think the auto setting is useful, so you could just delete all the GPIO references in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the auto function.


#define RTS5912_ULPM_NODE DT_NODELABEL(ulpm)

#define ULPM_RTS5912_MAX_NB_WKUP_PINS DT_INST_PROP(0, wkup_pins_nb)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest renaming the property wkup-pins-max.

#define ULPM_RTS5912_MAX_NB_WKUP_PINS DT_INST_PROP(0, wkup_pins_nb)

#define RTS5912_VIN_GPIO_INDEX 112
#define RTS5912_SCCON_REG_BASE ((SYSTEM_Type *)(DT_REG_ADDR(DT_NODELABEL(sccon))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this driver needs to manipulate the system clock controller, you should add new routines to the clock_control_rts5912_sccon.c driver instead of accessing the registers directly.

That way all register reads and writes to the SCCON are contained in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The system clock control register not only has clock source power controller, it also includes specific controller register such as VIVO , LDO and etc... so, some specific function register won't exposed on clock_control_rts5912_sccon.c

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking comment:

You could add routines to clock_control_rts5912_sccon.c for reading and writing registers defined by the SYSTEM_Type structure.

uint32_t rts5912_read_sys_reg(int offset);
void rts5912_write_sys_reg(int offset, uint32_t write_value);

This avoids each driver having to look up the sccon nodelabel.

Otherwise, you can keep the direct register access to VIVOCTRL in this driver, but you should move the macro RTS5912_SCCON_REG_BASE to reg_system.h so that it can be shared by multiple drivers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Titan-Realtek ,

Could you please move RTS5912_SCCON_REG_BASE to reg/reg_system.h to avoid the multiple define and help to check other drivers have used this kind of MACRO.

Thanks!

@Titan-Realtek Titan-Realtek force-pushed the soc_ulpm_rts5912 branch 3 times, most recently from 10a0b9c to 6aa7001 Compare March 31, 2025 04:55

#define ULPM_RTS5912_MAX_NB_WKUP_PINS DT_INST_PROP(0, wkup_pins_max)

#define RTS5912_VIN_GPIO_INDEX 112
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This define is no longer used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

#define ULPM_RTS5912_MAX_NB_WKUP_PINS DT_INST_PROP(0, wkup_pins_nb)

#define RTS5912_VIN_GPIO_INDEX 112
#define RTS5912_SCCON_REG_BASE ((SYSTEM_Type *)(DT_REG_ADDR(DT_NODELABEL(sccon))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking comment:

You could add routines to clock_control_rts5912_sccon.c for reading and writing registers defined by the SYSTEM_Type structure.

uint32_t rts5912_read_sys_reg(int offset);
void rts5912_write_sys_reg(int offset, uint32_t write_value);

This avoids each driver having to look up the sccon nodelabel.

Otherwise, you can keep the direct register access to VIVOCTRL in this driver, but you should move the macro RTS5912_SCCON_REG_BASE to reg_system.h so that it can be shared by multiple drivers.

Comment on lines 14 to 16
#ifdef CONFIG_SOC_RTS5912_ULPM
rts5912_ulpm_enable();
#endif /* CONFIG_SOC_RTS5912_ULPM */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's preferred to use IS_ENABLED instead of #ifdef when possible.

Suggested change
#ifdef CONFIG_SOC_RTS5912_ULPM
rts5912_ulpm_enable();
#endif /* CONFIG_SOC_RTS5912_ULPM */
if (IS_ENABLED(CONFIG_SOC_RTS5912_ULPM) {
rts5912_ulpm_enable();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Comment on lines 52 to 53
/* wake up polarity auto detect and set */
bool wkup_pin_pol_auto;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wkup_pin_pol_auto is not used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done: removed.


BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) <= 1, "Unsupported number of instances");

#define ULPM_SLEEP(x) k_msleep(x)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor issue - there is no need to create a macro to wrap k_msleep() - just call this function directly.

Using a macro here makes it harder to understand the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Comment on lines 107 to 113
SYSTEM_Type *sys_reg = RTS5912_SCCON_REG_BASE;
/* Update Register & reset bit */
ULPM_SLEEP(10);
sys_reg->VIVOCTRL |= SYSTEM_VIVOCTRL_REGWREN_Msk;
ULPM_SLEEP(10);
sys_reg->VIVOCTRL &= ~(SYSTEM_VIVOCTRL_REGWREN_Msk);
ULPM_SLEEP(10);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is easier to understand without the ULPM_SLEEP wrapper.

Suggested change
SYSTEM_Type *sys_reg = RTS5912_SCCON_REG_BASE;
/* Update Register & reset bit */
ULPM_SLEEP(10);
sys_reg->VIVOCTRL |= SYSTEM_VIVOCTRL_REGWREN_Msk;
ULPM_SLEEP(10);
sys_reg->VIVOCTRL &= ~(SYSTEM_VIVOCTRL_REGWREN_Msk);
ULPM_SLEEP(10);
SYSTEM_Type *sys_reg = RTS5912_SCCON_REG_BASE;
/* Update Register & reset bit */
k_msleep(10);
sys_reg->VIVOCTRL |= SYSTEM_VIVOCTRL_REGWREN_Msk;
k_msleep(10);
sys_reg->VIVOCTRL &= ~(SYSTEM_VIVOCTRL_REGWREN_Msk);
k_msleep(10);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/* starts from 0 */
uint32_t wkup_pin_id;
/* wake up polarity */
uint8_t wkup_pin_pol;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint8_t wkup_pin_pol;
enum wkup_pin_pol pin_pol;

/* wake up polarity */
uint8_t wkup_pin_pol;
/* wake up pin mode, VIN / GPIO */
uint8_t wkup_pin_mode;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint8_t wkup_pin_mode;
enum wkup_pin_mode pin_mode;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

keith-zephyr
keith-zephyr previously approved these changes Apr 10, 2025

void z_sys_poweroff(void)
{
if (IS_ENABLED(CONFIG_SOC_RTS5912_ULPM)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Titan-Realtek ,
If the ulpm device doesn't be enabled in the environment and you call the z_sys_poweroff().
Is the code will stuck here forever?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


#define WKUP_PIN_NODE_LABEL(i) wkup_pin_##i

#define WKUP_PIN_NODE_ID_BY_IDX(idx) DT_CHILD(STM32_PWR_NODE, WKUP_PIN_NODE_LABEL(idx))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Titan-Realtek ,
Is STM32_PWR_NODE be nice to appear in here?

Besied this, please check all the Macro and header are used here.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

#define ULPM_RTS5912_MAX_NB_WKUP_PINS DT_INST_PROP(0, wkup_pins_nb)

#define RTS5912_VIN_GPIO_INDEX 112
#define RTS5912_SCCON_REG_BASE ((SYSTEM_Type *)(DT_REG_ADDR(DT_NODELABEL(sccon))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Titan-Realtek ,

Could you please move RTS5912_SCCON_REG_BASE to reg/reg_system.h to avoid the multiple define and help to check other drivers have used this kind of MACRO.

Thanks!

Port rts5912 ULPM on Zephyr

Signed-off-by: Titan Chen <[email protected]>
@JasonLin-RealTek JasonLin-RealTek self-requested a review April 24, 2025 02:56
@kartben kartben requested a review from Copilot April 24, 2025 06:41
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ports ULPM support for the rts5912 SOC on Zephyr by adding ULPM header and source files, updating register definitions, and integrating the functionality into the poweroff sequence and DTS bindings.

  • Added ULPM driver header and implementation files for ULPM control and wake-up pin configuration.
  • Updated system register definitions to accommodate new ULPM settings.
  • Integrated ULPM trigger in the SOC poweroff path and provided DTS binding for configuration.

Reviewed Changes

Copilot reviewed 5 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
soc/realtek/ec/rts5912/rts5912_ulpm.h Added header declarations for ULPM enable function.
soc/realtek/ec/rts5912/rts5912_ulpm.c Added ULPM driver implementation including register and pin setup.
soc/realtek/ec/rts5912/reg/reg_system.h Updated register definitions to include new VODEF settings.
soc/realtek/ec/rts5912/poweroff.c Integrated ULPM enable call for SOC poweroff procedure.
dts/bindings/power/realtek,rts5912-ulpm.yaml Added DTS binding for ULPM configuration.
Files not reviewed (3)
  • dts/arm/realtek/ec/rts5912.dtsi: Language not supported
  • soc/realtek/ec/rts5912/CMakeLists.txt: Language not supported
  • soc/realtek/ec/rts5912/Kconfig: Language not supported

Comment on lines +152 to +156
LOG_DBG("Falling Edge\n");
} else {
/* Rising Edge */
sys_reg->VIVOCTRL &= ~BIT(SYSTEM_VIVOCTRL_VIN0POL_Pos + id);
LOG_DBG("Rising Edge\n");
Copy link
Preview

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log messages for wake-up pin edge configuration appear reversed: when the pin polarity is RISING, the subsequent debug log outputs 'Falling Edge'. Please verify and correct the log messages to accurately reflect the hardware configuration.

Suggested change
LOG_DBG("Falling Edge\n");
} else {
/* Rising Edge */
sys_reg->VIVOCTRL &= ~BIT(SYSTEM_VIVOCTRL_VIN0POL_Pos + id);
LOG_DBG("Rising Edge\n");
LOG_DBG("Rising Edge\n");
} else {
/* Rising Edge */
sys_reg->VIVOCTRL &= ~BIT(SYSTEM_VIVOCTRL_VIN0POL_Pos + id);
LOG_DBG("Falling Edge\n");

Copilot uses AI. Check for mistakes.

void rts5912_ulpm_enable(void)
{
SYSTEM_Type *sys_reg = RTS5912_SCCON_REG_BASE;
int i, id;
Copy link
Preview

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'id' is declared as an int but is used to store a value from the unsigned field 'wkup_pin_id'. Consider declaring 'id' as uint32_t to maintain type consistency and ensure proper boundary checks.

Suggested change
int i, id;
int i;
uint32_t id;

Copilot uses AI. Check for mistakes.

@kartben kartben merged commit e6bb7fc into zephyrproject-rtos:main Apr 24, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants