soc: mediatek: PMIC wrap: Clear the vldclr if state machine is stay on FSM_VLDCLR state.
PATCH 1/1 soc: mediatek: PMIC wrap: Clear the vldclr if state machine is stay on FSM_VLDCLR state.
Sometimes PMIC is too busy to send data in time to cause pmic wrap timeout, because pmic wrap is waiting for FSM_VLDCLR after finishing WACS2_CMD. It just return error when issue happened, so the state machine will stay on FSM_VLDCLR state when data send back later by PMIC and timeout again in next time because pmic wrap waiting for FSM_IDLE state at the begining of the read/write function.
Clear the vldclr when timeout if state machine is stay on FSM_VLDCLR.
--- drivers/soc/mediatek/mtk-pmic-wrap.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/soc/mediatek/mtk-pmic-wrap.c +14 -2
@@ -443,10 +443,16 @@ static int pwrap_wait_for_state(struct pmic_wrapper *wrp,static int pwrap_write (struct pmic_wrapper *wrp,u32 adr,u32 wdata) {int ret; +u32 val; ret =pwrap_wait_for_state (wrp, pwrap_is_fsm_idle); -if (ret) +if (ret) { +/* Clear vldclr bit if state is on the WACS_FSM_WFVLDCLR */ + val =pwrap_readl (wrp,PWRAP_WACS2_RDATA ); +if (PWRAP_GET_WACS_FSM (val) ==PWRAP_WACS_FSM_WFVLDCLR ) +pwrap_writel (wrp,1 ,PWRAP_WACS2_VLDCLR );return ret; + }pwrap_writel (wrp, (1 <<31 ) | ((adr >>1 ) <<16 ) | wdata,PWRAP_WACS2_CMD );
@@ -457,10 +463,16 @@ static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)static int pwrap_read (struct pmic_wrapper *wrp,u32 adr,u32 *rdata) {int ret; +u32 val; ret =pwrap_wait_for_state (wrp, pwrap_is_fsm_idle); -if (ret) +if (ret) { +/* Clear vldclr bit if state is on the WACS_FSM_WFVLDCLR */ + val =pwrap_readl (wrp,PWRAP_WACS2_RDATA ); +if (PWRAP_GET_WACS_FSM (val) ==PWRAP_WACS_FSM_WFVLDCLR ) +pwrap_writel (wrp,1 ,PWRAP_WACS2_VLDCLR );return ret; + }pwrap_writel (wrp, (adr >>1 ) <<16 ,PWRAP_WACS2_CMD );
Signature · 1 line
1.9.1
Matthias Brugger
maintainerQuoted 23 lines · Henry Chen
Sometimes PMIC is too busy to send data in time to cause pmic wrap timeout, because pmic wrap is waiting for
FSM_VLDCLRafter finishingWACS2_CMD. It just return error when issue happened, so the state machine will stay onFSM_VLDCLRstate when data send back later by PMIC and timeout again in next time because pmic wrap waiting forFSM_IDLEstate at the begining of the read/write function.Clear the vldclr when timeout if state machine is stay on
FSM_VLDCLR.Signed-off-by Henry Chen <[email protected]>--- drivers/soc/mediatek/mtk-pmic-wrap.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/soc/mediatek/mtk-pmic-wrap.c +1
-0@@ -443,10 +443,16 @@ static int pwrap_wait_for_state(struct pmic_wrapper *wrp,static int pwrap_write (struct pmic_wrapper *wrp,u32 adr,u32 wdata) {int ret; +u32 val;
drivers/soc/mediatek/mtk-pmic-wrap.c static int pwrap_wait_for_state(struct pmic_wrapper *wrp, · line 455
Quoted 10 lines
drivers/soc/mediatek/mtk-pmic-wrap.c +6
-1ret =pwrap_wait_for_state (wrp, pwrap_is_fsm_idle); -if (ret) +if (ret) { +/* Clear vldclr bit if state is on the WACS_FSM_WFVLDCLR */ + val =pwrap_readl (wrp,PWRAP_WACS2_RDATA ); +if (PWRAP_GET_WACS_FSM (val) ==PWRAP_WACS_FSM_WFVLDCLR ) +pwrap_writel (wrp,1 ,PWRAP_WACS2_VLDCLR );return ret; + }
I would prefer to have this encapsulated in a (inline) function. Maybe with better description then just the one line comment.
Thanks,
Matthias
Quoted 22 lines
drivers/soc/mediatek/mtk-pmic-wrap.c +7
-1pwrap_writel (wrp, (1 <<31 ) | ((adr >>1 ) <<16 ) | wdata,PWRAP_WACS2_CMD );@@ -457,10 +463,16 @@ static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)static int pwrap_read (struct pmic_wrapper *wrp,u32 adr,u32 *rdata) {int ret; +u32 val; ret =pwrap_wait_for_state (wrp, pwrap_is_fsm_idle); -if (ret) +if (ret) { +/* Clear vldclr bit if state is on the WACS_FSM_WFVLDCLR */ + val =pwrap_readl (wrp,PWRAP_WACS2_RDATA ); +if (PWRAP_GET_WACS_FSM (val) ==PWRAP_WACS_FSM_WFVLDCLR ) +pwrap_writel (wrp,1 ,PWRAP_WACS2_VLDCLR );return ret; + }pwrap_writel (wrp, (adr >>1 ) <<16 ,PWRAP_WACS2_CMD );
Hi Matthias,
Quoted 39 lines · Matthias Brugger
Quoted 23 lines · Henry Chen
Sometimes PMIC is too busy to send data in time to cause pmic wrap timeout, because pmic wrap is waiting for
FSM_VLDCLRafter finishingWACS2_CMD. It just return error when issue happened, so the state machine will stay onFSM_VLDCLRstate when data send back later by PMIC and timeout again in next time because pmic wrap waiting forFSM_IDLEstate at the begining of the read/write function.Clear the vldclr when timeout if state machine is stay on
FSM_VLDCLR.Signed-off-by Henry Chen <[email protected]>--- drivers/soc/mediatek/mtk-pmic-wrap.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/soc/mediatek/mtk-pmic-wrap.c +1
-0@@ -443,10 +443,16 @@ static int pwrap_wait_for_state(struct pmic_wrapper *wrp,static int pwrap_write (struct pmic_wrapper *wrp,u32 adr,u32 wdata) {int ret; +u32 val;drivers/soc/mediatek/mtk-pmic-wrap.c static int pwrap_wait_for_state(struct pmic_wrapper *wrp, · line 455
Quoted 10 lines
drivers/soc/mediatek/mtk-pmic-wrap.c +6
-1ret =pwrap_wait_for_state (wrp, pwrap_is_fsm_idle); -if (ret) +if (ret) { +/* Clear vldclr bit if state is on the WACS_FSM_WFVLDCLR */ + val =pwrap_readl (wrp,PWRAP_WACS2_RDATA ); +if (PWRAP_GET_WACS_FSM (val) ==PWRAP_WACS_FSM_WFVLDCLR ) +pwrap_writel (wrp,1 ,PWRAP_WACS2_VLDCLR );return ret; + }I would prefer to have this encapsulated in a (inline) function. Maybe with better description then just the one line comment.
Quoted 2 lines
Thanks,
Matthias
Ok, I will make the description more clear, do you means write the function like below and used it on pwrap_write/pwrap_read.
static inline void pwrap_leave_fsm_vldclr(struct pmic_wrapper *wrp)
{
if (pwrap_is_fsm_vldclr(wrp))
pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
}Thanks,
Henry
Quoted 23 lines
Quoted 23 lines
drivers/soc/mediatek/mtk-pmic-wrap.c +7
-1pwrap_writel (wrp, (1 <<31 ) | ((adr >>1 ) <<16 ) | wdata,PWRAP_WACS2_CMD );@@ -457,10 +463,16 @@ static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)static int pwrap_read (struct pmic_wrapper *wrp,u32 adr,u32 *rdata) {int ret; +u32 val; ret =pwrap_wait_for_state (wrp, pwrap_is_fsm_idle); -if (ret) +if (ret) { +/* Clear vldclr bit if state is on the WACS_FSM_WFVLDCLR */ + val =pwrap_readl (wrp,PWRAP_WACS2_RDATA ); +if (PWRAP_GET_WACS_FSM (val) ==PWRAP_WACS_FSM_WFVLDCLR ) +pwrap_writel (wrp,1 ,PWRAP_WACS2_VLDCLR );return ret; + }pwrap_writel (wrp, (adr >>1 ) <<16 ,PWRAP_WACS2_CMD );
Matthias Brugger
maintainerQuoted 45 lines · Henry Chen
Hi Matthias,
Quoted 39 lines · Matthias Brugger
Quoted 23 lines · Henry Chen
Sometimes PMIC is too busy to send data in time to cause pmic wrap timeout, because pmic wrap is waiting for
FSM_VLDCLRafter finishingWACS2_CMD. It just return error when issue happened, so the state machine will stay onFSM_VLDCLRstate when data send back later by PMIC and timeout again in next time because pmic wrap waiting forFSM_IDLEstate at the begining of the read/write function.Clear the vldclr when timeout if state machine is stay on
FSM_VLDCLR.Signed-off-by Henry Chen <[email protected]>--- drivers/soc/mediatek/mtk-pmic-wrap.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/soc/mediatek/mtk-pmic-wrap.c +1
-0@@ -443,10 +443,16 @@ static int pwrap_wait_for_state(struct pmic_wrapper *wrp,static int pwrap_write (struct pmic_wrapper *wrp,u32 adr,u32 wdata) {int ret; +u32 val;drivers/soc/mediatek/mtk-pmic-wrap.c static int pwrap_wait_for_state(struct pmic_wrapper *wrp, · line 455
Quoted 10 lines
drivers/soc/mediatek/mtk-pmic-wrap.c +6
-1ret =pwrap_wait_for_state (wrp, pwrap_is_fsm_idle); -if (ret) +if (ret) { +/* Clear vldclr bit if state is on the WACS_FSM_WFVLDCLR */ + val =pwrap_readl (wrp,PWRAP_WACS2_RDATA ); +if (PWRAP_GET_WACS_FSM (val) ==PWRAP_WACS_FSM_WFVLDCLR ) +pwrap_writel (wrp,1 ,PWRAP_WACS2_VLDCLR );return ret; + }I would prefer to have this encapsulated in a (inline) function. Maybe with better description then just the one line comment.
Quoted 2 lines
Thanks,
Matthias
Quoted 9 lines
Ok, I will make the description more clear, do you means write the function like below and used it on pwrap_write/pwrap_read.
static inline void
pwrap_leave_fsm_vldclr(struct pmic_wrapper *wrp){ if (pwrap_is_fsm_vldclr(wrp)) pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR); }
I didn't remind of pwrap_is_fsm_vldclr neither, nice.
Yes please use this function and add a descriptive comment on the top, so that in the future it is clear what is happening here.
Thanks,
Matthias
Quoted 29 lines
Thanks,
HenryQuoted 23 lines
Quoted 23 lines
drivers/soc/mediatek/mtk-pmic-wrap.c +7
-1pwrap_writel (wrp, (1 <<31 ) | ((adr >>1 ) <<16 ) | wdata,PWRAP_WACS2_CMD );@@ -457,10 +463,16 @@ static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)static int pwrap_read (struct pmic_wrapper *wrp,u32 adr,u32 *rdata) {int ret; +u32 val; ret =pwrap_wait_for_state (wrp, pwrap_is_fsm_idle); -if (ret) +if (ret) { +/* Clear vldclr bit if state is on the WACS_FSM_WFVLDCLR */ + val =pwrap_readl (wrp,PWRAP_WACS2_RDATA ); +if (PWRAP_GET_WACS_FSM (val) ==PWRAP_WACS_FSM_WFVLDCLR ) +pwrap_writel (wrp,1 ,PWRAP_WACS2_VLDCLR );return ret; + }pwrap_writel (wrp, (adr >>1 ) <<16 ,PWRAP_WACS2_CMD );