mediatek: bump to v4.4
[openwrt/staging/chunkeey.git] / target / linux / mediatek / patches-4.4 / 0027-soc-mediatek-PMIC-wrap-Clear-the-vldclr-if-state-mac.patch
1 From af4a99b856b584b2426757e905e9b6f39906ce05 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/53] 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 diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c
24 index 105597a..696071b 100644
25 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
26 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
27 @@ -412,6 +412,20 @@ static bool pwrap_is_fsm_vldclr(struct pmic_wrapper *wrp)
28 return PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_WFVLDCLR;
29 }
30
31 +/*
32 + * Timeout issue sometimes caused by the last read command
33 + * failed because pmic wrap could not got the FSM_VLDCLR
34 + * in time after finishing WACS2_CMD. It made state machine
35 + * still on FSM_VLDCLR and timeout next time.
36 + * Check the status of FSM and clear the vldclr to recovery the
37 + * error.
38 + */
39 +static inline void pwrap_leave_fsm_vldclr(struct pmic_wrapper *wrp)
40 +{
41 + if (pwrap_is_fsm_vldclr(wrp))
42 + pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
43 +}
44 +
45 static bool pwrap_is_sync_idle(struct pmic_wrapper *wrp)
46 {
47 return pwrap_readl(wrp, PWRAP_WACS2_RDATA) & PWRAP_STATE_SYNC_IDLE0;
48 @@ -445,8 +459,10 @@ static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
49 int ret;
50
51 ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
52 - if (ret)
53 + if (ret) {
54 + pwrap_leave_fsm_vldclr(wrp);
55 return ret;
56 + }
57
58 pwrap_writel(wrp, (1 << 31) | ((adr >> 1) << 16) | wdata,
59 PWRAP_WACS2_CMD);
60 @@ -459,8 +475,10 @@ static int pwrap_read(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
61 int ret;
62
63 ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
64 - if (ret)
65 + if (ret) {
66 + pwrap_leave_fsm_vldclr(wrp);
67 return ret;
68 + }
69
70 pwrap_writel(wrp, (adr >> 1) << 16, PWRAP_WACS2_CMD);
71
72 --
73 1.7.10.4
74