0027-soc-mediatek-PMIC-wrap-Clear-the-vldclr-if-state-mac.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From 036862011a5d13e8c54d9d0f9fe838fea986df89 Mon Sep 17 00:00:00 2001
  2. From: Henry Chen <[email protected]>
  3. Date: Mon, 4 Jan 2016 20:02:52 +0800
  4. Subject: [PATCH 27/90] soc: mediatek: PMIC wrap: Clear the vldclr if state
  5. machine stay on FSM_VLDCLR state.
  6. Sometimes PMIC is too busy to send data in time to cause pmic wrap timeout,
  7. because pmic wrap is waiting for FSM_VLDCLR after finishing WACS2_CMD. It
  8. just return error when issue happened, so the state machine will stay on
  9. FSM_VLDCLR state when data send back later by PMIC and timeout again in next
  10. time because pmic wrap waiting for FSM_IDLE state at the beginning of the
  11. read/write function.
  12. Clear the vldclr when timeout if state machine stay on FSM_VLDCLR.
  13. Signed-off-by: Henry Chen <[email protected]>
  14. Tested-by: Ricky Liang <[email protected]>
  15. Signed-off-by: Matthias Brugger <[email protected]>
  16. ---
  17. drivers/soc/mediatek/mtk-pmic-wrap.c | 22 ++++++++++++++++++++--
  18. 1 file changed, 20 insertions(+), 2 deletions(-)
  19. diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c
  20. index 105597a..696071b 100644
  21. --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
  22. +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
  23. @@ -412,6 +412,20 @@ static bool pwrap_is_fsm_vldclr(struct pmic_wrapper *wrp)
  24. return PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_WFVLDCLR;
  25. }
  26. +/*
  27. + * Timeout issue sometimes caused by the last read command
  28. + * failed because pmic wrap could not got the FSM_VLDCLR
  29. + * in time after finishing WACS2_CMD. It made state machine
  30. + * still on FSM_VLDCLR and timeout next time.
  31. + * Check the status of FSM and clear the vldclr to recovery the
  32. + * error.
  33. + */
  34. +static inline void pwrap_leave_fsm_vldclr(struct pmic_wrapper *wrp)
  35. +{
  36. + if (pwrap_is_fsm_vldclr(wrp))
  37. + pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
  38. +}
  39. +
  40. static bool pwrap_is_sync_idle(struct pmic_wrapper *wrp)
  41. {
  42. return pwrap_readl(wrp, PWRAP_WACS2_RDATA) & PWRAP_STATE_SYNC_IDLE0;
  43. @@ -445,8 +459,10 @@ static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
  44. int ret;
  45. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
  46. - if (ret)
  47. + if (ret) {
  48. + pwrap_leave_fsm_vldclr(wrp);
  49. return ret;
  50. + }
  51. pwrap_writel(wrp, (1 << 31) | ((adr >> 1) << 16) | wdata,
  52. PWRAP_WACS2_CMD);
  53. @@ -459,8 +475,10 @@ static int pwrap_read(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
  54. int ret;
  55. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
  56. - if (ret)
  57. + if (ret) {
  58. + pwrap_leave_fsm_vldclr(wrp);
  59. return ret;
  60. + }
  61. pwrap_writel(wrp, (adr >> 1) << 16, PWRAP_WACS2_CMD);
  62. --
  63. 1.7.10.4