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 diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c
23 index 2d3a8faae124..e3398e37a7a6 100644
24 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
25 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
27 PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE | \
28 PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE)
30 +/* Group of bits used for shown slave capability */
31 +#define PWRAP_SLV_CAP_SPI BIT(0)
32 +#define PWRAP_SLV_CAP_DUALIO BIT(1)
33 +#define PWRAP_SLV_CAP_SECURITY BIT(2)
34 +#define HAS_CAP(_c, _x) (((_c) & (_x)) == (_x))
36 /* defines for slave device wrapper registers */
39 @@ -501,6 +507,8 @@ struct pmic_wrapper;
40 struct pwrap_slv_type {
43 + /* Flags indicating the capability for the target slave */
46 * pwrap operations are highly associated with the PMIC types,
47 * so the pointers added increases flexibility allowing determination
48 @@ -787,6 +795,37 @@ static int pwrap_init_sidly(struct pmic_wrapper *wrp)
52 +static int pwrap_init_dual_io(struct pmic_wrapper *wrp)
57 + /* Enable dual IO mode */
58 + pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_DIO_EN], 1);
60 + /* Check IDLE & INIT_DONE in advance */
61 + ret = pwrap_wait_for_state(wrp,
62 + pwrap_is_fsm_idle_and_sync_idle);
64 + dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
68 + pwrap_writel(wrp, 1, PWRAP_DIO_EN);
72 + wrp->slave->dew_regs[PWRAP_DEW_READ_TEST], &rdata);
73 + if (rdata != PWRAP_DEW_READ_TEST_VAL) {
75 + "Read failed on DIO mode: 0x%04x!=0x%04x\n",
76 + PWRAP_DEW_READ_TEST_VAL, rdata);
83 static int pwrap_mt8135_init_reg_clock(struct pmic_wrapper *wrp)
85 pwrap_writel(wrp, 0x4, PWRAP_CSHEXT);
86 @@ -935,6 +974,30 @@ static int pwrap_init_cipher(struct pmic_wrapper *wrp)
90 +static int pwrap_init_security(struct pmic_wrapper *wrp)
94 + /* Enable encryption */
95 + ret = pwrap_init_cipher(wrp);
99 + /* Signature checking - using CRC */
100 + if (pwrap_write(wrp,
101 + wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1))
104 + pwrap_writel(wrp, 0x1, PWRAP_CRC_EN);
105 + pwrap_writel(wrp, 0x0, PWRAP_SIG_MODE);
106 + pwrap_writel(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_VAL],
109 + wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
114 static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
116 /* enable pwrap events and pwrap bridge in AP side */
117 @@ -995,7 +1058,6 @@ static int pwrap_mt2701_init_soc_specific(struct pmic_wrapper *wrp)
118 static int pwrap_init(struct pmic_wrapper *wrp)
123 reset_control_reset(wrp->rstc);
124 if (wrp->rstc_bridge)
125 @@ -1007,10 +1069,12 @@ static int pwrap_init(struct pmic_wrapper *wrp)
126 pwrap_writel(wrp, 0, PWRAP_DCM_DBC_PRD);
129 - /* Reset SPI slave */
130 - ret = pwrap_reset_spislave(wrp);
133 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
134 + /* Reset SPI slave */
135 + ret = pwrap_reset_spislave(wrp);
140 pwrap_writel(wrp, 1, PWRAP_WRAP_EN);
142 @@ -1022,45 +1086,26 @@ static int pwrap_init(struct pmic_wrapper *wrp)
146 - /* Setup serial input delay */
147 - ret = pwrap_init_sidly(wrp);
151 - /* Enable dual IO mode */
152 - pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_DIO_EN], 1);
154 - /* Check IDLE & INIT_DONE in advance */
155 - ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle_and_sync_idle);
157 - dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
159 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
160 + /* Setup serial input delay */
161 + ret = pwrap_init_sidly(wrp);
166 - pwrap_writel(wrp, 1, PWRAP_DIO_EN);
169 - pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_READ_TEST], &rdata);
170 - if (rdata != PWRAP_DEW_READ_TEST_VAL) {
171 - dev_err(wrp->dev, "Read test failed after switch to DIO mode: 0x%04x != 0x%04x\n",
172 - PWRAP_DEW_READ_TEST_VAL, rdata);
174 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_DUALIO)) {
175 + /* Enable dual I/O mode */
176 + ret = pwrap_init_dual_io(wrp);
181 - /* Enable encryption */
182 - ret = pwrap_init_cipher(wrp);
186 - /* Signature checking - using CRC */
187 - if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1))
190 - pwrap_writel(wrp, 0x1, PWRAP_CRC_EN);
191 - pwrap_writel(wrp, 0x0, PWRAP_SIG_MODE);
192 - pwrap_writel(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_VAL],
194 - pwrap_writel(wrp, wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
195 + if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SECURITY)) {
196 + /* Enable security on bus */
197 + ret = pwrap_init_security(wrp);
202 if (wrp->master->type == PWRAP_MT8135)
203 pwrap_writel(wrp, 0x7, PWRAP_RRARB_EN);
204 @@ -1116,6 +1161,8 @@ static const struct regmap_config pwrap_regmap_config = {
205 static const struct pwrap_slv_type pmic_mt6323 = {
206 .dew_regs = mt6323_regs,
208 + .caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO |
209 + PWRAP_SLV_CAP_SECURITY,
210 .pwrap_read = pwrap_read16,
211 .pwrap_write = pwrap_write16,
213 @@ -1123,6 +1170,7 @@ static const struct pwrap_slv_type pmic_mt6323 = {
214 static const struct pwrap_slv_type pmic_mt6380 = {
218 .pwrap_read = pwrap_read32,
219 .pwrap_write = pwrap_write32,
221 @@ -1130,6 +1178,8 @@ static const struct pwrap_slv_type pmic_mt6380 = {
222 static const struct pwrap_slv_type pmic_mt6397 = {
223 .dew_regs = mt6397_regs,
225 + .caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO |
226 + PWRAP_SLV_CAP_SECURITY,
227 .pwrap_read = pwrap_read16,
228 .pwrap_write = pwrap_write16,