1 From d82889cec95358b917fcf29fc3214980deb138b9 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 20 Jan 2016 10:12:00 +0100
4 Subject: [PATCH 34/91] soc: mediatek: PMIC wrap: split SoC specific init into
7 This patch moves the SoC specific wrapper init code into separate callback
8 to avoid pwrap_init() getting too large. This is done by adding a new
9 element called init_special to pmic_wrapper_type. Each currently supported
10 SoC gets its own version of the callback and we copy the code that was
11 previously inside pwrap_init() to these new callbacks. Finally we point the
12 2 instances of pmic_wrapper_type at the 2 new functions.
14 Signed-off-by: John Crispin <blogic@openwrt.org>
16 drivers/soc/mediatek/mtk-pmic-wrap.c | 67 +++++++++++++++++++++-------------
17 1 file changed, 42 insertions(+), 25 deletions(-)
19 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
20 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
21 @@ -372,6 +372,7 @@ struct pmic_wrapper_type {
24 int (*init_reg_clock)(struct pmic_wrapper *wrp);
25 + int (*init_soc_specific)(struct pmic_wrapper *wrp);
28 static inline int pwrap_is_mt8135(struct pmic_wrapper *wrp)
29 @@ -665,6 +666,41 @@ static int pwrap_init_cipher(struct pmic
33 +static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
35 + /* enable pwrap events and pwrap bridge in AP side */
36 + pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
37 + pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
38 + writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
39 + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
40 + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
41 + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
42 + writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
43 + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
44 + writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
46 + /* enable PMIC event out and sources */
47 + if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
48 + pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
49 + dev_err(wrp->dev, "enable dewrap fail\n");
56 +static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper *wrp)
58 + /* PMIC_DEWRAP enables */
59 + if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
60 + pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
61 + dev_err(wrp->dev, "enable dewrap fail\n");
68 static int pwrap_init(struct pmic_wrapper *wrp)
71 @@ -743,31 +779,10 @@ static int pwrap_init(struct pmic_wrappe
72 pwrap_writel(wrp, 0x5, PWRAP_STAUPD_PRD);
73 pwrap_writel(wrp, 0xff, PWRAP_STAUPD_GRPEN);
75 - if (pwrap_is_mt8135(wrp)) {
76 - /* enable pwrap events and pwrap bridge in AP side */
77 - pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
78 - pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
79 - writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
80 - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
81 - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
82 - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
83 - writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
84 - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
85 - writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
87 - /* enable PMIC event out and sources */
88 - if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
89 - pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
90 - dev_err(wrp->dev, "enable dewrap fail\n");
94 - /* PMIC_DEWRAP enables */
95 - if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
96 - pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
97 - dev_err(wrp->dev, "enable dewrap fail\n");
100 + if (wrp->master->init_soc_specific) {
101 + ret = wrp->master->init_soc_specific(wrp);
106 /* Setup the init done registers */
107 @@ -811,6 +826,7 @@ static struct pmic_wrapper_type pwrap_mt
108 .type = PWRAP_MT8135,
110 .init_reg_clock = pwrap_mt8135_init_reg_clock,
111 + .init_soc_specific = pwrap_mt8135_init_soc_specific,
114 static struct pmic_wrapper_type pwrap_mt8173 = {
115 @@ -818,6 +834,7 @@ static struct pmic_wrapper_type pwrap_mt
116 .type = PWRAP_MT8173,
118 .init_reg_clock = pwrap_mt8173_init_reg_clock,
119 + .init_soc_specific = pwrap_mt8173_init_soc_specific,
122 static struct of_device_id of_pwrap_match_tbl[] = {