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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From 55231d8299d3dccde8588ed2e86c2bc0ef2e12ce Mon Sep 17 00:00:00 2001
  2. From: Henry Chen <henryc.chen@mediatek.com>
  3. Date: Mon, 4 Jan 2016 20:02:52 +0800
  4. Subject: [PATCH 027/102] 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 <henryc.chen@mediatek.com>
  14. Tested-by: Ricky Liang <jcliang@chromium.org>
  15. Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
  16. ---
  17. drivers/soc/mediatek/mtk-pmic-wrap.c | 22 ++++++++++++++++++++--
  18. 1 file changed, 20 insertions(+), 2 deletions(-)
  19. --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
  20. +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
  21. @@ -412,6 +412,20 @@ static bool pwrap_is_fsm_vldclr(struct p
  22. return PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_WFVLDCLR;
  23. }
  24. +/*
  25. + * Timeout issue sometimes caused by the last read command
  26. + * failed because pmic wrap could not got the FSM_VLDCLR
  27. + * in time after finishing WACS2_CMD. It made state machine
  28. + * still on FSM_VLDCLR and timeout next time.
  29. + * Check the status of FSM and clear the vldclr to recovery the
  30. + * error.
  31. + */
  32. +static inline void pwrap_leave_fsm_vldclr(struct pmic_wrapper *wrp)
  33. +{
  34. + if (pwrap_is_fsm_vldclr(wrp))
  35. + pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
  36. +}
  37. +
  38. static bool pwrap_is_sync_idle(struct pmic_wrapper *wrp)
  39. {
  40. return pwrap_readl(wrp, PWRAP_WACS2_RDATA) & PWRAP_STATE_SYNC_IDLE0;
  41. @@ -445,8 +459,10 @@ static int pwrap_write(struct pmic_wrapp
  42. int ret;
  43. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
  44. - if (ret)
  45. + if (ret) {
  46. + pwrap_leave_fsm_vldclr(wrp);
  47. return ret;
  48. + }
  49. pwrap_writel(wrp, (1 << 31) | ((adr >> 1) << 16) | wdata,
  50. PWRAP_WACS2_CMD);
  51. @@ -459,8 +475,10 @@ static int pwrap_read(struct pmic_wrappe
  52. int ret;
  53. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
  54. - if (ret)
  55. + if (ret) {
  56. + pwrap_leave_fsm_vldclr(wrp);
  57. return ret;
  58. + }
  59. pwrap_writel(wrp, (adr >> 1) << 16, PWRAP_WACS2_CMD);