kernel: update kernel 4.4 to version 4.4.7
[openwrt.git] / target / linux / mediatek / patches-4.4 / 0034-soc-mediatek-PMIC-wrap-split-SoC-specific-init-into-.patch
1 From b2287b0afb757870ce0f4324bb4bc597d3f90a2a 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/81] 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 --- 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 {
22         enum pwrap_type type;
23         u32 arb_en_all;
24         int (*init_reg_clock)(struct pmic_wrapper *wrp);
25 +       int (*init_soc_specific)(struct pmic_wrapper *wrp);
26  };
27  
28  static inline int pwrap_is_mt8135(struct pmic_wrapper *wrp)
29 @@ -665,6 +666,41 @@ static int pwrap_init_cipher(struct pmic
30         return 0;
31  }
32  
33 +static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
34 +{
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);
45 +
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");
50 +               return -EFAULT;
51 +       }
52 +
53 +       return 0;
54 +}
55 +
56 +static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper *wrp)
57 +{
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");
62 +               return -EFAULT;
63 +       }
64 +
65 +       return 0;
66 +}
67 +
68  static int pwrap_init(struct pmic_wrapper *wrp)
69  {
70         int ret;
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);
74  
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);
86 -
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");
91 -                       return -EFAULT;
92 -               }
93 -       } else {
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");
98 -                       return -EFAULT;
99 -               }
100 +       if (wrp->master->init_soc_specific) {
101 +               ret = wrp->master->init_soc_specific(wrp);
102 +               if (ret)
103 +                       return ret;
104         }
105  
106         /* Setup the init done registers */
107 @@ -811,6 +826,7 @@ static struct pmic_wrapper_type pwrap_mt
108         .type = PWRAP_MT8135,
109         .arb_en_all = 0x1ff,
110         .init_reg_clock = pwrap_mt8135_init_reg_clock,
111 +       .init_soc_specific = pwrap_mt8135_init_soc_specific,
112  };
113  
114  static struct pmic_wrapper_type pwrap_mt8173 = {
115 @@ -818,6 +834,7 @@ static struct pmic_wrapper_type pwrap_mt
116         .type = PWRAP_MT8173,
117         .arb_en_all = 0x3f,
118         .init_reg_clock = pwrap_mt8173_init_reg_clock,
119 +       .init_soc_specific = pwrap_mt8173_init_soc_specific,
120  };
121  
122  static struct of_device_id of_pwrap_match_tbl[] = {