power: pmic: mtk-pwrap: add more capability flags
cover power: pmic: mtk-pwrap: add more capability flags
After using the mtk-pwrap driver a bit, we noticed that there were a few places where it was writing to registers that were not defined on all platforms. The undefined registers are treated as 0, which is the DONE2 register on the affected platforms. This could cause the DONE2 register to have an incorrect value, which could cause Linux to re-initialize the PMIC unnecessarily.
To avoid this issue and ensure that we only write to registers that are defined on a given platform, we can add some more capability flags to conditionally call any register writes that aren't common to all platforms.
---
David Lechner (3):
power: pmic: mtk-pwrap: add init capability flag
power: pmic: mtk-pwrap: add PWRAP_CAP_WDT_SRC flag
power: pmic: mtk-pwrap: drop PWRAP_SLV_CAP_DUALIO on mt6359
drivers/power/pmic/mtk-pwrap.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
---
base-commit: 80a4c49a4ab2ad06fa84a8b7bdf6e33b3b5101bf
change-id: 20260317-mtk-pmic-fixes-c1523b1b0dad
Best regards,
Signature · 1 line
David Lechner <[email protected]>
PATCH 1/3 power: pmic: mtk-pwrap: add init capability flag
Add a PWRAP_CAP_INIT capability flag to specify if it is safe to call pwrap_init() or not. Not all targets define the registers accessed by pwrap_init(). In that case, it is expected that an earlier bootloader has already initialized the PMIC. If not, we now return an error instead of trying to access undefined registers.
--- drivers/power/pmic/mtk-pwrap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/power/pmic/mtk-pwrap.c +8 -1
@@ -62,6 +62,8 @@ static const struct pmic_child_info mt6359_pmic_children_info[] = {#define PWRAP_CAP_INT1_EN BIT(3)#define PWRAP_CAP_WDT_SRC1 BIT(4)#define PWRAP_CAP_ARB BIT(5) +/* To implement this capability, the registers used in pwrap_init() must be defined. */ +#define PWRAP_CAP_INIT BIT(6)/* defines for slave device wrapper registers */ enum dew_regs {
@@ -752,6 +754,11 @@ static int mtk_pwrap_probe(struct udevice *dev)* Skip initialization here in this case. */ if (!pwrap_readl (wrp,PWRAP_INIT_DONE2 )) { +if (!HAS_CAP (wrp->master->caps,PWRAP_CAP_INIT )) { +dev_err (dev,"initialization is required but not supported\n" ); +return -ENODEV ; + } + ret =pwrap_init (wrp);if (ret) {dev_err (dev,"init failed with %d\n" , ret);
@@ -905,7 +912,7 @@ static const struct pmic_wrapper_type pwrap_mt8365 = { .int1_en_all = 0x0, .spi_w = PWRAP_MAN_CMD_SPI_WRITE, .wdt_src = PWRAP_WDT_SRC_MASK_ALL, - .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1, + .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1 | PWRAP_CAP_INIT, };static const struct udevice_id mtk_pwrap_ids[] = {
Signature · 1 line
2.43.0
Re: [PATCH 1/3] power: pmic: mtk-pwrap: add init capability flag
Quoted 26 lines · David Lechner
Add a
PWRAP_CAP_INITcapability flag to specify if it is safe to callpwrap_init()or not. Not all targets define the registers accessed bypwrap_init(). In that case, it is expected that an earlier bootloader has already initialized the PMIC. If not, we now return an error instead of trying to access undefined registers.Signed-off-by David Lechner <[email protected]>--- drivers/power/pmic/mtk-pwrap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/power/pmic/mtk-pwrap.c +2
-0@@ -62,6 +62,8 @@ static const struct pmic_child_info mt6359_pmic_children_info[] = {#define PWRAP_CAP_INT1_EN BIT(3)#define PWRAP_CAP_WDT_SRC1 BIT(4)#define PWRAP_CAP_ARB BIT(5) +/* To implement this capability, the registers used in pwrap_init() must be defined. */ +#define PWRAP_CAP_INIT BIT(6)/* defines for slave device wrapper registers */ enum dew_regs {
drivers/power/pmic/mtk-pwrap.c static int mtk_pwrap_probe(struct udevice *dev) · line 759
Quoted 6 lines
drivers/power/pmic/mtk-pwrap.c +3
-0@@ -752,6 +754,11 @@ static int mtk_pwrap_probe(struct udevice *dev)* Skip initialization here in this case. */ if (!pwrap_readl (wrp,PWRAP_INIT_DONE2 )) { +if (!HAS_CAP (wrp->master->caps,PWRAP_CAP_INIT )) { +dev_err (dev,"initialization is required but not supported\n" ); +return -ENODEV ;
what about : return -ENOTSUPP ?
Quoted 18 lines
drivers/power/pmic/mtk-pwrap.c +3
-2+ } + ret =pwrap_init (wrp);if (ret) {dev_err (dev,"init failed with %d\n" , ret);@@ -905,7 +912,7 @@ static const struct pmic_wrapper_type pwrap_mt8365 = { .int1_en_all = 0x0, .spi_w = PWRAP_MAN_CMD_SPI_WRITE, .wdt_src = PWRAP_WDT_SRC_MASK_ALL, - .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1, + .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1 | PWRAP_CAP_INIT, };static const struct udevice_id mtk_pwrap_ids[] = { --2.43.0
Re: [PATCH 1/3] power: pmic: mtk-pwrap: add init capability flag
In reply to David LechnerQuoted 51 lines · David Lechner
Add a
PWRAP_CAP_INITcapability flag to specify if it is safe to callpwrap_init()or not. Not all targets define the registers accessed bypwrap_init(). In that case, it is expected that an earlier bootloader
has already initialized the PMIC. If not, we now return an error instead
of trying to access undefined registers.Signed-off-by David Lechner <[email protected]>---
drivers/power/pmic/mtk-pwrap.c | 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)drivers/power/pmic/mtk- renamed from drivers/power/pmic/mtk-pwrap.c +0
-0
pwrap.c
index446b78fb0ee..9ff06fdb3bd100644drivers/power/pmic/mtk-pwrap.c +1
-0@@ -62,6 +62,8 @@ static const struct pmic_child_info mt6359_pmic_children_info[] = { #define PWRAP_CAP_INT1_EN BIT(3) #define PWRAP_CAP_WDT_SRC1 BIT(4) #define PWRAP_CAP_ARB BIT(5) +/* To implement this capability, the registers used in pwrap_init() must be defined. */
+#definePWRAP_CAP_INITBIT(6)
/* defines for slave device wrapper registers */
enumdew_regs{drivers/power/pmic/mtk-pwrap.c +5
-0@@ -752,6 +754,11 @@ static int mtk_pwrap_probe(struct udevice *dev)* Skip initialization here in this case. */ if (!pwrap_readl(wrp, PWRAP_INIT_DONE2)) { +if (!HAS_CAP (wrp->master->caps,PWRAP_CAP_INIT )) { + dev_err(dev, "initialization is required but not supported\n"); + return -ENODEV; + } + ret = pwrap_init(wrp); if (ret) {
dev_err(dev, "init failed with %d\n", ret);drivers/power/pmic/mtk-pwrap.c +1
-1@@ -905,7 +912,7 @@ static const struct pmic_wrapper_type pwrap_mt8365 = { .int1_en_all = 0x0, .spi_w = PWRAP_MAN_CMD_SPI_WRITE, .wdt_src = PWRAP_WDT_SRC_MASK_ALL, - .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1, + .caps =PWRAP_CAP_INT1_EN |PWRAP_CAP_WDT_SRC1 | PWRAP_CAP_INIT, };
Quoted 3 lines
static const structudevice_idmtk_pwrap_ids[] = {
Thanks!
Macpaul Lin
PATCH 2/3 power: pmic: mtk-pwrap: add PWRAP_CAP_WDT_SRC flag
In reply to David LechnerAdd a PWRAP_CAP_WDT_SRC flag to indicate if a PMIC wrapper has a WDT_SRC or not. Then use this to conditionally enable the watchdog timer.
Prior to this change, since the register was not defined, it defaulted to 0, so the wrong register (DONE2) was being written to.
--- drivers/power/pmic/mtk-pwrap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/power/pmic/mtk-pwrap.c +7 -5
@@ -60,10 +60,11 @@ static const struct pmic_child_info mt6359_pmic_children_info[] = {/* Group of bits used for shown pwrap capability */ #define PWRAP_CAP_INT1_EN BIT(3) -#define PWRAP_CAP_WDT_SRC1 BIT(4) -#define PWRAP_CAP_ARB BIT(5) +#define PWRAP_CAP_WDT_SRC BIT(4) +#define PWRAP_CAP_WDT_SRC1 BIT(5) +#define PWRAP_CAP_ARB BIT(6)/* To implement this capability, the registers used in pwrap_init() must be defined. */ -#define PWRAP_CAP_INIT BIT(6) +#define PWRAP_CAP_INIT BIT(7)/* defines for slave device wrapper registers */ enum dew_regs {
@@ -780,7 +781,8 @@ static int mtk_pwrap_probe(struct udevice *dev)* Since STAUPD was not used on mt8173 platform, * so STAUPD of WDT_SRC which should be turned off */ -pwrap_writel (wrp, wrp->master->wdt_src,PWRAP_WDT_SRC_EN ); +if (HAS_CAP (wrp->master->caps,PWRAP_CAP_WDT_SRC )) +pwrap_writel (wrp, wrp->master->wdt_src,PWRAP_WDT_SRC_EN );if (HAS_CAP (wrp->master->caps,PWRAP_CAP_WDT_SRC1 ))pwrap_writel (wrp, wrp->master->wdt_src,PWRAP_WDT_SRC_EN_1 );
@@ -912,7 +914,7 @@ static const struct pmic_wrapper_type pwrap_mt8365 = { .int1_en_all = 0x0, .spi_w = PWRAP_MAN_CMD_SPI_WRITE, .wdt_src = PWRAP_WDT_SRC_MASK_ALL, - .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1 | PWRAP_CAP_INIT, + .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC | PWRAP_CAP_WDT_SRC1 | PWRAP_CAP_INIT, };static const struct udevice_id mtk_pwrap_ids[] = {
Signature · 1 line
2.43.0
Re: [PATCH 2/3] power: pmic: mtk-pwrap: add PWRAP_CAP_WDT_SRC flag
Quoted 18 lines · David Lechner
Add a
PWRAP_CAP_WDT_SRCflag to indicate if a PMIC wrapper has aWDT_SRCor not. Then use this to conditionally enable the watchdog timer.Prior to this change, since the register was not defined, it defaulted to 0, so the wrong register (DONE2) was being written to.
Signed-off-by David Lechner <[email protected]>--- drivers/power/pmic/mtk-pwrap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/power/pmic/mtk-pwrap.c +0
-0@@ -60,10 +60,11 @@ static const struct pmic_child_info mt6359_pmic_children_info[] = {
drivers/power/pmic/mtk-pwrap.c static const struct pmic_child_info mt6359_pmic_children_info[] = { · line 67
Quoted 10 lines
drivers/power/pmic/mtk-pwrap.c +4
-3/* Group of bits used for shown pwrap capability */ #define PWRAP_CAP_INT1_EN BIT(3) -#define PWRAP_CAP_WDT_SRC1 BIT(4) -#define PWRAP_CAP_ARB BIT(5) +#define PWRAP_CAP_WDT_SRC BIT(4) +#define PWRAP_CAP_WDT_SRC1 BIT(5) +#define PWRAP_CAP_ARB BIT(6)/* To implement this capability, the registers used in pwrap_init() must be defined. */ -#define PWRAP_CAP_INIT BIT(6) +#define PWRAP_CAP_INIT BIT(7)
can you reorder patch 1 and 2 to avoid modifying PWRAP_CAP_INIT twice ?
Quoted 26 lines
drivers/power/pmic/mtk-pwrap.c +3
-3/* defines for slave device wrapper registers */ enum dew_regs {@@ -780,7 +781,8 @@ static int mtk_pwrap_probe(struct udevice *dev)* Since STAUPD was not used on mt8173 platform, * so STAUPD of WDT_SRC which should be turned off */ -pwrap_writel (wrp, wrp->master->wdt_src,PWRAP_WDT_SRC_EN ); +if (HAS_CAP (wrp->master->caps,PWRAP_CAP_WDT_SRC )) +pwrap_writel (wrp, wrp->master->wdt_src,PWRAP_WDT_SRC_EN );if (HAS_CAP (wrp->master->caps,PWRAP_CAP_WDT_SRC1 ))pwrap_writel (wrp, wrp->master->wdt_src,PWRAP_WDT_SRC_EN_1 );@@ -912,7 +914,7 @@ static const struct pmic_wrapper_type pwrap_mt8365 = { .int1_en_all = 0x0, .spi_w = PWRAP_MAN_CMD_SPI_WRITE, .wdt_src = PWRAP_WDT_SRC_MASK_ALL, - .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1 | PWRAP_CAP_INIT, + .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC | PWRAP_CAP_WDT_SRC1 | PWRAP_CAP_INIT, };static const struct udevice_id mtk_pwrap_ids[] = { --2.43.0
Re: [PATCH 2/3] power: pmic: mtk-pwrap: add PWRAP_CAP_WDT_SRC flag
In reply to David LechnerQuoted 56 lines · David Lechner
Add a
PWRAP_CAP_WDT_SRCflag to indicate if a PMIC wrapper has aWDT_SRC
or not. Then use this to conditionally enable the watchdog timer.Prior to this change, since the register was not defined, it defaulted
to 0, so the wrong register (DONE2) was being written to.Signed-off-by David Lechner <[email protected]>---
drivers/power/pmic/mtk-pwrap.c | 12 +++++++-----1 file changed, 7 insertions(+), 5 deletions(-)drivers/power/pmic/mtk- renamed from drivers/power/pmic/mtk-pwrap.c +0
-0
pwrap.c
index9ff06fdb3bd..d8498646921100644drivers/power/pmic/mtk-pwrap.c +0
-0@@ -60,10 +60,11 @@ static const struct pmic_child_info mt6359_pmic_children_info[] = {
/* Group of bits used for shown pwrap capability */
#definePWRAP_CAP_INT1_ENBIT(3)drivers/power/pmic/mtk-pwrap.c +3
-2-#define PWRAP_CAP_WDT_SRC1 BIT(4) -#define PWRAP_CAP_ARB BIT(5) +#define PWRAP_CAP_WDT_SRC BIT(4) +#define PWRAP_CAP_WDT_SRC1 BIT(5) +#define PWRAP_CAP_ARB BIT(6)/* To implement this capability, the registers used in
pwrap_init()must be defined. */drivers/power/pmic/mtk-pwrap.c +1
-1-#define PWRAP_CAP_INIT BIT(6) +#define PWRAP_CAP_INIT BIT(7)
/* defines for slave device wrapper registers */
enumdew_regs{drivers/power/pmic/mtk-pwrap.c +2
-1@@ -780,7 +781,8 @@ static int mtk_pwrap_probe(struct udevice *dev)* Since STAUPD was not used on mt8173 platform, * so STAUPD of WDT_SRC which should be turned off */ -pwrap_writel (wrp, wrp->master->wdt_src,PWRAP_WDT_SRC_EN ); +if (HAS_CAP (wrp->master->caps,PWRAP_CAP_WDT_SRC )) +pwrap_writel (wrp, wrp->master->wdt_src,PWRAP_WDT_SRC_EN );
if (HAS_CAP(wrp->master->caps, PWRAP_CAP_WDT_SRC1))pwrap_writel(wrp, wrp->master->wdt_src, PWRAP_WDT_SRC_EN_1);drivers/power/pmic/mtk-pwrap.c +1
-1@@ -912,7 +914,7 @@ static const struct pmic_wrapper_type pwrap_mt8365 = { .int1_en_all = 0x0, .spi_w = PWRAP_MAN_CMD_SPI_WRITE, .wdt_src = PWRAP_WDT_SRC_MASK_ALL, - .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1 |PWRAP_CAP_INIT , + .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC | PWRAP_CAP_WDT_SRC1 | PWRAP_CAP_INIT,
Quoted 4 lines
};
static const structudevice_idmtk_pwrap_ids[] = {
Thanks!
Macpaul Lin
PATCH 3/3 power: pmic: mtk-pwrap: drop PWRAP_SLV_CAP_DUALIO on mt6359
In reply to David LechnerDrop the PWRAP_SLV_CAP_DUALIO flag from the mt6359 PMIC definition. The mt6359p variant of the PMIC does support dual I/O.
Prior to this change, the driver would attempt to write to the PWRAP_DEW_DIO_EN register, which was not defined, so would write register 0 (DONE2).
--- drivers/power/pmic/mtk-pwrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/pmic/mtk-pwrap.c +1 -1
@@ -665,7 +665,7 @@ static const struct pwrap_slv_type pmic_mt6357 = {static const struct pwrap_slv_type pmic_mt6359 = { .dew_regs = mt6359_regs, - .caps =PWRAP_SLV_CAP_DUALIO , + .caps =0 , };static const struct udevice_id mtk_pmic_ids[] = {
Signature · 1 line
2.43.0
Re: [PATCH 3/3] power: pmic: mtk-pwrap: drop PWRAP_SLV_CAP_DUALIO on mt6359
Quoted 25 lines · David Lechner
Drop the
PWRAP_SLV_CAP_DUALIOflag from the mt6359 PMIC definition. The
mt6359p variant of the PMIC does support dual I/O.Prior to this change, the driver would attempt to write to the
PWRAP_DEW_DIO_ENregister, which was not defined, so would write register 0 (DONE2).Signed-off-by David Lechner <[email protected]>---
drivers/power/pmic/mtk-pwrap.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/pmic/mtk- renamed from drivers/power/pmic/mtk-pwrap.c +0
-0
pwrap.c
indexd8498646921..6a2c9044b9e100644drivers/power/pmic/mtk-pwrap.c +0
-0@@ -665,7 +665,7 @@ static const struct pwrap_slv_type pmic_mt6357 = {
static const structpwrap_slv_typepmic_mt6359= { .dew_regs =mt6359_regs,drivers/power/pmic/mtk-pwrap.c +1
-1- .caps = PWRAP_SLV_CAP_DUALIO, + .caps = 0,
Quoted 5 lines
};
static const structudevice_idmtk_pmic_ids[] = {
Thanks!
Macpaul Lin