mediatek: update patches
[openwrt/staging/chunkeey.git] / target / linux / mediatek / patches-4.4 / 0034-soc-mediatek-PMIC-wrap-split-SoC-specific-init-into-.patch
1 From b164dff8be266b531574e89a27eb3ce9e0b4e40a 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
5 callback
6
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.
13
14 Signed-off-by: John Crispin <blogic@openwrt.org>
15 ---
16 drivers/soc/mediatek/mtk-pmic-wrap.c | 67 +++++++++++++++++++++-------------
17 1 file changed, 42 insertions(+), 25 deletions(-)
18
19 diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c
20 index b22b664..22c89e9 100644
21 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
22 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
23 @@ -372,6 +372,7 @@ struct pmic_wrapper_type {
24 enum pwrap_type type;
25 u32 arb_en_all;
26 int (*init_reg_clock)(struct pmic_wrapper *wrp);
27 + int (*init_soc_specific)(struct pmic_wrapper *wrp);
28 };
29
30 static inline int pwrap_is_mt8135(struct pmic_wrapper *wrp)
31 @@ -665,6 +666,41 @@ static int pwrap_init_cipher(struct pmic_wrapper *wrp)
32 return 0;
33 }
34
35 +static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
36 +{
37 + /* enable pwrap events and pwrap bridge in AP side */
38 + pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
39 + pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
40 + writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
41 + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
42 + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
43 + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
44 + writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
45 + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
46 + writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
47 +
48 + /* enable PMIC event out and sources */
49 + if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
50 + pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
51 + dev_err(wrp->dev, "enable dewrap fail\n");
52 + return -EFAULT;
53 + }
54 +
55 + return 0;
56 +}
57 +
58 +static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper *wrp)
59 +{
60 + /* PMIC_DEWRAP enables */
61 + if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
62 + pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
63 + dev_err(wrp->dev, "enable dewrap fail\n");
64 + return -EFAULT;
65 + }
66 +
67 + return 0;
68 +}
69 +
70 static int pwrap_init(struct pmic_wrapper *wrp)
71 {
72 int ret;
73 @@ -743,31 +779,10 @@ static int pwrap_init(struct pmic_wrapper *wrp)
74 pwrap_writel(wrp, 0x5, PWRAP_STAUPD_PRD);
75 pwrap_writel(wrp, 0xff, PWRAP_STAUPD_GRPEN);
76
77 - if (pwrap_is_mt8135(wrp)) {
78 - /* enable pwrap events and pwrap bridge in AP side */
79 - pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
80 - pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
81 - writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
82 - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
83 - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
84 - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
85 - writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
86 - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
87 - writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
88 -
89 - /* enable PMIC event out and sources */
90 - if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
91 - pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
92 - dev_err(wrp->dev, "enable dewrap fail\n");
93 - return -EFAULT;
94 - }
95 - } else {
96 - /* PMIC_DEWRAP enables */
97 - if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
98 - pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
99 - dev_err(wrp->dev, "enable dewrap fail\n");
100 - return -EFAULT;
101 - }
102 + if (wrp->master->init_soc_specific) {
103 + ret = wrp->master->init_soc_specific(wrp);
104 + if (ret)
105 + return ret;
106 }
107
108 /* Setup the init done registers */
109 @@ -811,6 +826,7 @@ static struct pmic_wrapper_type pwrap_mt8135 = {
110 .type = PWRAP_MT8135,
111 .arb_en_all = 0x1ff,
112 .init_reg_clock = pwrap_mt8135_init_reg_clock,
113 + .init_soc_specific = pwrap_mt8135_init_soc_specific,
114 };
115
116 static struct pmic_wrapper_type pwrap_mt8173 = {
117 @@ -818,6 +834,7 @@ static struct pmic_wrapper_type pwrap_mt8173 = {
118 .type = PWRAP_MT8173,
119 .arb_en_all = 0x3f,
120 .init_reg_clock = pwrap_mt8173_init_reg_clock,
121 + .init_soc_specific = pwrap_mt8173_init_soc_specific,
122 };
123
124 static struct of_device_id of_pwrap_match_tbl[] = {
125 --
126 1.7.10.4
127