kernel: bump 4.14 to 4.14.44
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.14 / 0119-soc-mediatek-pwrap-refactor-pwrap_init-for-the-vario.patch
1 From 16bebe4ad52083316907fb7149c797cd331f5948 Mon Sep 17 00:00:00 2001
2 From: Sean Wang <sean.wang@mediatek.com>
3 Date: Wed, 18 Oct 2017 16:28:45 +0800
4 Subject: [PATCH 119/224] soc: mediatek: pwrap: refactor pwrap_init for the
5 various PMIC types
6
7 pwrap initialization is highly associated with the base SoC and the
8 target PMICs, so slight refactorization is made here for allowing
9 pwrap_init to run on those PMICs with different capability from the
10 previous MediaTek PMICs and the determination for the enablement of the
11 pwrap capability depending on PMIC type. Apart from this, the patch
12 makes the driver more extensible especially when more PMICs join into
13 the pwrap driver.
14
15 Signed-off-by: Chenglin Xu <chenglin.xu@mediatek.com>
16 Signed-off-by: Sean Wang <sean.wang@mediatek.com>
17 Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
18 ---
19 drivers/soc/mediatek/mtk-pmic-wrap.c | 130 ++++++++++++++++++++++++-----------
20 1 file changed, 90 insertions(+), 40 deletions(-)
21
22 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
23 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
24 @@ -70,6 +70,12 @@
25 PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE | \
26 PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE)
27
28 +/* Group of bits used for shown slave capability */
29 +#define PWRAP_SLV_CAP_SPI BIT(0)
30 +#define PWRAP_SLV_CAP_DUALIO BIT(1)
31 +#define PWRAP_SLV_CAP_SECURITY BIT(2)
32 +#define HAS_CAP(_c, _x) (((_c) & (_x)) == (_x))
33 +
34 /* defines for slave device wrapper registers */
35 enum dew_regs {
36 PWRAP_DEW_BASE,
37 @@ -501,6 +507,8 @@ struct pmic_wrapper;
38 struct pwrap_slv_type {
39 const u32 *dew_regs;
40 enum pmic_type type;
41 + /* Flags indicating the capability for the target slave */
42 + u32 caps;
43 /*
44 * pwrap operations are highly associated with the PMIC types,
45 * so the pointers added increases flexibility allowing determination
46 @@ -787,6 +795,37 @@ static int pwrap_init_sidly(struct pmic_
47 return 0;
48 }
49
50 +static int pwrap_init_dual_io(struct pmic_wrapper *wrp)
51 +{
52 + int ret;
53 + u32 rdata;
54 +
55 + /* Enable dual IO mode */
56 + pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_DIO_EN], 1);
57 +
58 + /* Check IDLE & INIT_DONE in advance */
59 + ret = pwrap_wait_for_state(wrp,
60 + pwrap_is_fsm_idle_and_sync_idle);
61 + if (ret) {
62 + dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
63 + return ret;
64 + }
65 +
66 + pwrap_writel(wrp, 1, PWRAP_DIO_EN);
67 +
68 + /* Read Test */
69 + pwrap_read(wrp,
70 + wrp->slave->dew_regs[PWRAP_DEW_READ_TEST], &rdata);
71 + if (rdata != PWRAP_DEW_READ_TEST_VAL) {
72 + dev_err(wrp->dev,
73 + "Read failed on DIO mode: 0x%04x!=0x%04x\n",
74 + PWRAP_DEW_READ_TEST_VAL, rdata);
75 + return -EFAULT;
76 + }
77 +
78 + return 0;
79 +}
80 +
81 static int pwrap_mt8135_init_reg_clock(struct pmic_wrapper *wrp)
82 {
83 pwrap_writel(wrp, 0x4, PWRAP_CSHEXT);
84 @@ -935,6 +974,30 @@ static int pwrap_init_cipher(struct pmic
85 return 0;
86 }
87
88 +static int pwrap_init_security(struct pmic_wrapper *wrp)
89 +{
90 + int ret;
91 +
92 + /* Enable encryption */
93 + ret = pwrap_init_cipher(wrp);
94 + if (ret)
95 + return ret;
96 +
97 + /* Signature checking - using CRC */
98 + if (pwrap_write(wrp,
99 + wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1))
100 + return -EFAULT;
101 +
102 + pwrap_writel(wrp, 0x1, PWRAP_CRC_EN);
103 + pwrap_writel(wrp, 0x0, PWRAP_SIG_MODE);
104 + pwrap_writel(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_VAL],
105 + PWRAP_SIG_ADR);
106 + pwrap_writel(wrp,
107 + wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
108 +
109 + return 0;
110 +}
111 +
112 static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
113 {
114 /* enable pwrap events and pwrap bridge in AP side */
115 @@ -995,7 +1058,6 @@ static int pwrap_mt2701_init_soc_specifi
116 static int pwrap_init(struct pmic_wrapper *wrp)
117 {
118 int ret;
119 - u32 rdata;
120
121 reset_control_reset(wrp->rstc);
122 if (wrp->rstc_bridge)
123 @@ -1007,10 +1069,12 @@ static int pwrap_init(struct pmic_wrappe
124 pwrap_writel(wrp, 0, PWRAP_DCM_DBC_PRD);
125 }
126
127 - /* Reset SPI slave */
128 - ret = pwrap_reset_spislave(wrp);
129 - if (ret)
130 - return ret;
131 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
132 + /* Reset SPI slave */
133 + ret = pwrap_reset_spislave(wrp);
134 + if (ret)
135 + return ret;
136 + }
137
138 pwrap_writel(wrp, 1, PWRAP_WRAP_EN);
139
140 @@ -1022,45 +1086,26 @@ static int pwrap_init(struct pmic_wrappe
141 if (ret)
142 return ret;
143
144 - /* Setup serial input delay */
145 - ret = pwrap_init_sidly(wrp);
146 - if (ret)
147 - return ret;
148 -
149 - /* Enable dual IO mode */
150 - pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_DIO_EN], 1);
151 -
152 - /* Check IDLE & INIT_DONE in advance */
153 - ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle_and_sync_idle);
154 - if (ret) {
155 - dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
156 - return ret;
157 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
158 + /* Setup serial input delay */
159 + ret = pwrap_init_sidly(wrp);
160 + if (ret)
161 + return ret;
162 }
163
164 - pwrap_writel(wrp, 1, PWRAP_DIO_EN);
165 -
166 - /* Read Test */
167 - pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_READ_TEST], &rdata);
168 - if (rdata != PWRAP_DEW_READ_TEST_VAL) {
169 - dev_err(wrp->dev, "Read test failed after switch to DIO mode: 0x%04x != 0x%04x\n",
170 - PWRAP_DEW_READ_TEST_VAL, rdata);
171 - return -EFAULT;
172 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_DUALIO)) {
173 + /* Enable dual I/O mode */
174 + ret = pwrap_init_dual_io(wrp);
175 + if (ret)
176 + return ret;
177 }
178
179 - /* Enable encryption */
180 - ret = pwrap_init_cipher(wrp);
181 - if (ret)
182 - return ret;
183 -
184 - /* Signature checking - using CRC */
185 - if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1))
186 - return -EFAULT;
187 -
188 - pwrap_writel(wrp, 0x1, PWRAP_CRC_EN);
189 - pwrap_writel(wrp, 0x0, PWRAP_SIG_MODE);
190 - pwrap_writel(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_VAL],
191 - PWRAP_SIG_ADR);
192 - pwrap_writel(wrp, wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
193 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SECURITY)) {
194 + /* Enable security on bus */
195 + ret = pwrap_init_security(wrp);
196 + if (ret)
197 + return ret;
198 + }
199
200 if (wrp->master->type == PWRAP_MT8135)
201 pwrap_writel(wrp, 0x7, PWRAP_RRARB_EN);
202 @@ -1116,6 +1161,8 @@ static const struct regmap_config pwrap_
203 static const struct pwrap_slv_type pmic_mt6323 = {
204 .dew_regs = mt6323_regs,
205 .type = PMIC_MT6323,
206 + .caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO |
207 + PWRAP_SLV_CAP_SECURITY,
208 .pwrap_read = pwrap_read16,
209 .pwrap_write = pwrap_write16,
210 };
211 @@ -1123,6 +1170,7 @@ static const struct pwrap_slv_type pmic_
212 static const struct pwrap_slv_type pmic_mt6380 = {
213 .dew_regs = NULL,
214 .type = PMIC_MT6380,
215 + .caps = 0,
216 .pwrap_read = pwrap_read32,
217 .pwrap_write = pwrap_write32,
218 };
219 @@ -1130,6 +1178,8 @@ static const struct pwrap_slv_type pmic_
220 static const struct pwrap_slv_type pmic_mt6397 = {
221 .dew_regs = mt6397_regs,
222 .type = PMIC_MT6397,
223 + .caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO |
224 + PWRAP_SLV_CAP_SECURITY,
225 .pwrap_read = pwrap_read16,
226 .pwrap_write = pwrap_write16,
227 };