mediatek: backport upstream mediatek patches
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.14 / 0117-soc-mediatek-pwrap-add-pwrap_read32-for-reading-in-3.patch
1 From 9c37953bd08daa3ca227098d763e980d1898add3 Mon Sep 17 00:00:00 2001
2 From: Sean Wang <sean.wang@mediatek.com>
3 Date: Wed, 18 Oct 2017 16:28:43 +0800
4 Subject: [PATCH 117/224] soc: mediatek: pwrap: add pwrap_read32 for reading in
5 32-bit mode
6
7 Some regulators such as MediaTek MT6380 has to be read in 32-bit mode.
8 So the patch adds pwrap_read32, rename old pwrap_read into pwrap_read16
9 and one function pointer is introduced for increasing flexibility allowing
10 the determination which mode is used by the pwrap slave detection through
11 device tree.
12
13 Signed-off-by: Chenglin Xu <chenglin.xu@mediatek.com>
14 Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
15 Signed-off-by: Sean Wang <sean.wang@mediatek.com>
16 Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
17 ---
18 drivers/soc/mediatek/mtk-pmic-wrap.c | 55 +++++++++++++++++++++++++++++++++++-
19 1 file changed, 54 insertions(+), 1 deletion(-)
20
21 diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c
22 index f095faac1e04..06930e2ebe4c 100644
23 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
24 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
25 @@ -487,6 +487,7 @@ static int mt8135_regs[] = {
26
27 enum pmic_type {
28 PMIC_MT6323,
29 + PMIC_MT6380,
30 PMIC_MT6397,
31 };
32
33 @@ -496,9 +497,16 @@ enum pwrap_type {
34 PWRAP_MT8173,
35 };
36
37 +struct pmic_wrapper;
38 struct pwrap_slv_type {
39 const u32 *dew_regs;
40 enum pmic_type type;
41 + /*
42 + * pwrap operations are highly associated with the PMIC types,
43 + * so the pointers added increases flexibility allowing determination
44 + * which type is used by the detection through device tree.
45 + */
46 + int (*pwrap_read)(struct pmic_wrapper *wrp, u32 adr, u32 *rdata);
47 };
48
49 struct pmic_wrapper {
50 @@ -609,7 +617,7 @@ static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
51 return 0;
52 }
53
54 -static int pwrap_read(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
55 +static int pwrap_read16(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
56 {
57 int ret;
58
59 @@ -632,6 +640,39 @@ static int pwrap_read(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
60 return 0;
61 }
62
63 +static int pwrap_read32(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
64 +{
65 + int ret, msb;
66 +
67 + *rdata = 0;
68 + for (msb = 0; msb < 2; msb++) {
69 + ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
70 + if (ret) {
71 + pwrap_leave_fsm_vldclr(wrp);
72 + return ret;
73 + }
74 +
75 + pwrap_writel(wrp, ((msb << 30) | (adr << 16)),
76 + PWRAP_WACS2_CMD);
77 +
78 + ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_vldclr);
79 + if (ret)
80 + return ret;
81 +
82 + *rdata += (PWRAP_GET_WACS_RDATA(pwrap_readl(wrp,
83 + PWRAP_WACS2_RDATA)) << (16 * msb));
84 +
85 + pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
86 + }
87 +
88 + return 0;
89 +}
90 +
91 +static int pwrap_read(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
92 +{
93 + return wrp->slave->pwrap_read(wrp, adr, rdata);
94 +}
95 +
96 static int pwrap_regmap_read(void *context, u32 adr, u32 *rdata)
97 {
98 return pwrap_read(context, adr, rdata);
99 @@ -752,6 +793,8 @@ static int pwrap_mt2701_init_reg_clock(struct pmic_wrapper *wrp)
100 pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_START);
101 pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_END);
102 break;
103 + default:
104 + break;
105 }
106
107 return 0;
108 @@ -815,6 +858,8 @@ static int pwrap_init_cipher(struct pmic_wrapper *wrp)
109 pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_EN],
110 0x1);
111 break;
112 + default:
113 + break;
114 }
115
116 /* wait for cipher data ready@AP */
117 @@ -1036,11 +1081,19 @@ static const struct regmap_config pwrap_regmap_config = {
118 static const struct pwrap_slv_type pmic_mt6323 = {
119 .dew_regs = mt6323_regs,
120 .type = PMIC_MT6323,
121 + .pwrap_read = pwrap_read16,
122 +};
123 +
124 +static const struct pwrap_slv_type pmic_mt6380 = {
125 + .dew_regs = NULL,
126 + .type = PMIC_MT6380,
127 + .pwrap_read = pwrap_read32,
128 };
129
130 static const struct pwrap_slv_type pmic_mt6397 = {
131 .dew_regs = mt6397_regs,
132 .type = PMIC_MT6397,
133 + .pwrap_read = pwrap_read16,
134 };
135
136 static const struct of_device_id of_slave_match_tbl[] = {
137 --
138 2.11.0
139