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
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
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>
19 drivers/soc/mediatek/mtk-pmic-wrap.c | 130 ++++++++++++++++++++++++-----------
20 1 file changed, 90 insertions(+), 40 deletions(-)
22 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
23 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
25 PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE | \
26 PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE)
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))
34 /* defines for slave device wrapper registers */
37 @@ -501,6 +507,8 @@ struct pmic_wrapper;
38 struct pwrap_slv_type {
41 + /* Flags indicating the capability for the target slave */
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_
50 +static int pwrap_init_dual_io(struct pmic_wrapper *wrp)
55 + /* Enable dual IO mode */
56 + pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_DIO_EN], 1);
58 + /* Check IDLE & INIT_DONE in advance */
59 + ret = pwrap_wait_for_state(wrp,
60 + pwrap_is_fsm_idle_and_sync_idle);
62 + dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
66 + pwrap_writel(wrp, 1, PWRAP_DIO_EN);
70 + wrp->slave->dew_regs[PWRAP_DEW_READ_TEST], &rdata);
71 + if (rdata != PWRAP_DEW_READ_TEST_VAL) {
73 + "Read failed on DIO mode: 0x%04x!=0x%04x\n",
74 + PWRAP_DEW_READ_TEST_VAL, rdata);
81 static int pwrap_mt8135_init_reg_clock(struct pmic_wrapper *wrp)
83 pwrap_writel(wrp, 0x4, PWRAP_CSHEXT);
84 @@ -935,6 +974,30 @@ static int pwrap_init_cipher(struct pmic
88 +static int pwrap_init_security(struct pmic_wrapper *wrp)
92 + /* Enable encryption */
93 + ret = pwrap_init_cipher(wrp);
97 + /* Signature checking - using CRC */
98 + if (pwrap_write(wrp,
99 + wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1))
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],
107 + wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
112 static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
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)
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);
127 - /* Reset SPI slave */
128 - ret = pwrap_reset_spislave(wrp);
131 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
132 + /* Reset SPI slave */
133 + ret = pwrap_reset_spislave(wrp);
138 pwrap_writel(wrp, 1, PWRAP_WRAP_EN);
140 @@ -1022,45 +1086,26 @@ static int pwrap_init(struct pmic_wrappe
144 - /* Setup serial input delay */
145 - ret = pwrap_init_sidly(wrp);
149 - /* Enable dual IO mode */
150 - pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_DIO_EN], 1);
152 - /* Check IDLE & INIT_DONE in advance */
153 - ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle_and_sync_idle);
155 - dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
157 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
158 + /* Setup serial input delay */
159 + ret = pwrap_init_sidly(wrp);
164 - pwrap_writel(wrp, 1, PWRAP_DIO_EN);
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);
172 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_DUALIO)) {
173 + /* Enable dual I/O mode */
174 + ret = pwrap_init_dual_io(wrp);
179 - /* Enable encryption */
180 - ret = pwrap_init_cipher(wrp);
184 - /* Signature checking - using CRC */
185 - if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1))
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],
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);
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,
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,
211 @@ -1123,6 +1170,7 @@ static const struct pwrap_slv_type pmic_
212 static const struct pwrap_slv_type pmic_mt6380 = {
216 .pwrap_read = pwrap_read32,
217 .pwrap_write = pwrap_write32,
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,
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,