-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
soc : realtek: ec: rts5912: add support ULPM #86717
Conversation
b606358
to
6f7edd2
Compare
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 |
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.
Do not do this, include the base definition properly
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.
done, thanks.
soc/realtek/ec/rts5912/Kconfig
Outdated
@@ -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) |
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.
select HAS_POWEROFF if(SOC_RTS5912_ULPM) |
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.
done, thanks.
dts/arm/realtek/ec/rts5912.dtsi
Outdated
|
||
wkup-pin@0 { | ||
reg = <0x0>; | ||
/* wkup-pin-pol; */ |
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.
commented lines to go?
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.
done, thanks.
soc/realtek/ec/rts5912/Kconfig
Outdated
bool "Realtek RTS5912 ULPM (Ultra Low Power Mode)" | ||
default y | ||
depends on DT_HAS_REALTEK_RTS5912_ULPM_ENABLED | ||
select POWEROFF |
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.
select POWEROFF | |
select HAS_POWEROFF |
Users select POWEROFF if they want it not a soc
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.
done, thanks.
9aa63f3
to
7d15a9a
Compare
|
||
#define RTS5912_ULPM_NODE DT_NODELABEL(ulpm) | ||
|
||
#define ULPM_RTS5912_MAX_NB_WKUP_PINS DT_INST_PROP(0, wkup_pins_nb) |
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.
You can replace the wkup-pins-nb
property with the macro DT_INST_CHILD_NUM_STATUS_OKAY(0)
.
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.
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.
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.
I suggest renaming the property wkup-pins-max
.
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.
Done.
|
||
#define ULPM_SLEEP(x) k_msleep(x) | ||
|
||
#define RTS5912_ULPM_NODE DT_NODELABEL(ulpm) |
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.
Use DT_DRV_INST(0)
instead of the nodelabel.
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.
Done.
/** @endcond */ | ||
|
||
static struct wkup_pin_dt_cfg_t wkup_pins_cfgs[] = { | ||
DT_FOREACH_CHILD(RTS5912_ULPM_NODE, WKUP_PIN_CFG_DT_COMMA)}; |
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.
Use DT_INST_FOREACH_CHILD(0, WKUP_PIN_CFG_DT_COMMA)
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.
Done.
/** | ||
* @brief Enable VOUT function and set the VOUT default value. | ||
*/ | ||
void ULPMStart(void) |
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.
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.
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.
Done.
7d15a9a
to
2798444
Compare
GPIO_Type *gpio_reg = RTS5912_GPIO_REG_BASE; | ||
int i, id; | ||
|
||
printk("rts5912 ULPM enabled\n"); |
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.
Use logging instead of printk throughout the file.
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.
Done.
wkup-pin-pol-auto: | ||
type: boolean | ||
description: | | ||
True if auto detect current VIN level and set opposite polarity. |
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.
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.
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.
removed. done.
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"); | ||
} |
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.
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.
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.
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) |
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.
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)))) |
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.
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.
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.
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
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.
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.
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.
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!
10a0b9c
to
6aa7001
Compare
|
||
#define ULPM_RTS5912_MAX_NB_WKUP_PINS DT_INST_PROP(0, wkup_pins_max) | ||
|
||
#define RTS5912_VIN_GPIO_INDEX 112 |
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.
This define is no longer used.
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.
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)))) |
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.
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.
6aa7001
to
58bb2b8
Compare
soc/realtek/ec/rts5912/poweroff.c
Outdated
#ifdef CONFIG_SOC_RTS5912_ULPM | ||
rts5912_ulpm_enable(); | ||
#endif /* CONFIG_SOC_RTS5912_ULPM */ |
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.
It's preferred to use IS_ENABLED
instead of #ifdef
when possible.
#ifdef CONFIG_SOC_RTS5912_ULPM | |
rts5912_ulpm_enable(); | |
#endif /* CONFIG_SOC_RTS5912_ULPM */ | |
if (IS_ENABLED(CONFIG_SOC_RTS5912_ULPM) { | |
rts5912_ulpm_enable(); | |
} |
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.
done.
/* wake up polarity auto detect and set */ | ||
bool wkup_pin_pol_auto; |
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.
wkup_pin_pol_auto
is not used
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.
done: removed.
58bb2b8
to
fcaf9e4
Compare
|
||
BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) <= 1, "Unsupported number of instances"); | ||
|
||
#define ULPM_SLEEP(x) k_msleep(x) |
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.
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.
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.
done.
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); |
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.
This is easier to understand without the ULPM_SLEEP
wrapper.
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); |
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.
done
/* starts from 0 */ | ||
uint32_t wkup_pin_id; | ||
/* wake up polarity */ | ||
uint8_t wkup_pin_pol; |
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.
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; |
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.
uint8_t wkup_pin_mode; | |
enum wkup_pin_mode pin_mode; |
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.
done
fcaf9e4
to
c4829d8
Compare
|
||
void z_sys_poweroff(void) | ||
{ | ||
if (IS_ENABLED(CONFIG_SOC_RTS5912_ULPM)) { |
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.
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?
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.
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)) |
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.
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!
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.
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)))) |
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.
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!
c609abc
to
a0b24de
Compare
Port rts5912 ULPM on Zephyr Signed-off-by: Titan Chen <[email protected]>
a0b24de
to
365d1c5
Compare
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.
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
LOG_DBG("Falling Edge\n"); | ||
} else { | ||
/* Rising Edge */ | ||
sys_reg->VIVOCTRL &= ~BIT(SYSTEM_VIVOCTRL_VIN0POL_Pos + id); | ||
LOG_DBG("Rising Edge\n"); |
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.
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.
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; |
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.
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.
int i, id; | |
int i; | |
uint32_t id; |
Copilot uses AI. Check for mistakes.
Port rts5912 ULPM on Zephyr