c0100bf3879d20296df70ad49445d6393b18c417
[openwrt/svn-archive/archive.git] / target / linux / mediatek / patches-4.4 / 0027-soc-mediatek-PMIC-wrap-Clear-the-vldclr-if-state-mac.patch
1 From 2fc7dd0f48d9c2096d76562a1960b78b064701f7 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 27/81] soc: mediatek: PMIC wrap: Clear the vldclr if state
5 machine stay on FSM_VLDCLR state.
6
7 Sometimes PMIC is too busy to send data in time to cause pmic wrap timeout,
8 because pmic wrap is waiting for FSM_VLDCLR after finishing WACS2_CMD. It
9 just return error when issue happened, so the state machine will stay on
10 FSM_VLDCLR state when data send back later by PMIC and timeout again in next
11 time because pmic wrap waiting for FSM_IDLE state at the beginning of the
12 read/write function.
13
14 Clear the vldclr when timeout if state machine stay on FSM_VLDCLR.
15
16 Signed-off-by: Henry Chen <henryc.chen@mediatek.com>
17 Tested-by: Ricky Liang <jcliang@chromium.org>
18 Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
19 ---
20 drivers/soc/mediatek/mtk-pmic-wrap.c | 22 ++++++++++++++++++++--
21 1 file changed, 20 insertions(+), 2 deletions(-)
22
23 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
24 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
25 @@ -412,6 +412,20 @@ static bool pwrap_is_fsm_vldclr(struct p
26 return PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_WFVLDCLR;
27 }
28
29 +/*
30 + * Timeout issue sometimes caused by the last read command
31 + * failed because pmic wrap could not got the FSM_VLDCLR
32 + * in time after finishing WACS2_CMD. It made state machine
33 + * still on FSM_VLDCLR and timeout next time.
34 + * Check the status of FSM and clear the vldclr to recovery the
35 + * error.
36 + */
37 +static inline void pwrap_leave_fsm_vldclr(struct pmic_wrapper *wrp)
38 +{
39 + if (pwrap_is_fsm_vldclr(wrp))
40 + pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
41 +}
42 +
43 static bool pwrap_is_sync_idle(struct pmic_wrapper *wrp)
44 {
45 return pwrap_readl(wrp, PWRAP_WACS2_RDATA) & PWRAP_STATE_SYNC_IDLE0;
46 @@ -445,8 +459,10 @@ static int pwrap_write(struct pmic_wrapp
47 int ret;
48
49 ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
50 - if (ret)
51 + if (ret) {
52 + pwrap_leave_fsm_vldclr(wrp);
53 return ret;
54 + }
55
56 pwrap_writel(wrp, (1 << 31) | ((adr >> 1) << 16) | wdata,
57 PWRAP_WACS2_CMD);
58 @@ -459,8 +475,10 @@ static int pwrap_read(struct pmic_wrappe
59 int ret;
60
61 ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
62 - if (ret)
63 + if (ret) {
64 + pwrap_leave_fsm_vldclr(wrp);
65 return ret;
66 + }
67
68 pwrap_writel(wrp, (adr >> 1) << 16, PWRAP_WACS2_CMD);
69