mediatek: sync and patches add support for several boards
[openwrt.git] / target / linux / mediatek / patches-4.4 / 0038-soc-mediatek-PMIC-wrap-remove-pwrap_is_mt8135-and-pw.patch
1 From e16393b2c78cc95ec124a46e8da8cfb2af333f00 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 20 Jan 2016 10:54:18 +0100
4 Subject: [PATCH 38/90] soc: mediatek: PMIC wrap: remove pwrap_is_mt8135() and
5  pwrap_is_mt8173()
6
7 With more SoCs being added the list of helper functions like these would
8 grow. To mitigate this problem we remove the existing helpers and change
9 the code to test against the pmic type stored inside the pmic specific
10 datastructure that our context structure points at. There is one usage of
11 pwrap_is_mt8135() that is ambiguous as the test should not be dependent on
12 mt8135, but rather on the existence of a bridge. Add a new element to
13 pmic_wrapper_type to indicate if a bridge is present and use this where
14 appropriate.
15
16 Signed-off-by: John Crispin <blogic@openwrt.org>
17 ---
18  drivers/soc/mediatek/mtk-pmic-wrap.c |   28 ++++++++++++----------------
19  1 file changed, 12 insertions(+), 16 deletions(-)
20
21 diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c
22 index aa54df3..a2bacda 100644
23 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
24 +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
25 @@ -374,20 +374,11 @@ struct pmic_wrapper_type {
26         u32 int_en_all;
27         u32 spi_w;
28         u32 wdt_src;
29 +       int has_bridge:1;
30         int (*init_reg_clock)(struct pmic_wrapper *wrp);
31         int (*init_soc_specific)(struct pmic_wrapper *wrp);
32  };
33  
34 -static inline int pwrap_is_mt8135(struct pmic_wrapper *wrp)
35 -{
36 -       return wrp->master->type == PWRAP_MT8135;
37 -}
38 -
39 -static inline int pwrap_is_mt8173(struct pmic_wrapper *wrp)
40 -{
41 -       return wrp->master->type == PWRAP_MT8173;
42 -}
43 -
44  static u32 pwrap_readl(struct pmic_wrapper *wrp, enum pwrap_regs reg)
45  {
46         return readl(wrp->base + wrp->master->regs[reg]);
47 @@ -619,11 +610,14 @@ static int pwrap_init_cipher(struct pmic_wrapper *wrp)
48         pwrap_writel(wrp, 0x1, PWRAP_CIPHER_KEY_SEL);
49         pwrap_writel(wrp, 0x2, PWRAP_CIPHER_IV_SEL);
50  
51 -       if (pwrap_is_mt8135(wrp)) {
52 +       switch (wrp->master->type) {
53 +       case PWRAP_MT8135:
54                 pwrap_writel(wrp, 1, PWRAP_CIPHER_LOAD);
55                 pwrap_writel(wrp, 1, PWRAP_CIPHER_START);
56 -       } else {
57 +               break;
58 +       case PWRAP_MT8173:
59                 pwrap_writel(wrp, 1, PWRAP_CIPHER_EN);
60 +               break;
61         }
62  
63         /* Config cipher mode @PMIC */
64 @@ -713,7 +707,7 @@ static int pwrap_init(struct pmic_wrapper *wrp)
65         if (wrp->rstc_bridge)
66                 reset_control_reset(wrp->rstc_bridge);
67  
68 -       if (pwrap_is_mt8173(wrp)) {
69 +       if (wrp->master->type == PWRAP_MT8173) {
70                 /* Enable DCM */
71                 pwrap_writel(wrp, 3, PWRAP_DCM_EN);
72                 pwrap_writel(wrp, 0, PWRAP_DCM_DBC_PRD);
73 @@ -773,7 +767,7 @@ static int pwrap_init(struct pmic_wrapper *wrp)
74         pwrap_writel(wrp, PWRAP_DEW_CRC_VAL, PWRAP_SIG_ADR);
75         pwrap_writel(wrp, wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
76  
77 -       if (pwrap_is_mt8135(wrp))
78 +       if (wrp->master->type == PWRAP_MT8135)
79                 pwrap_writel(wrp, 0x7, PWRAP_RRARB_EN);
80  
81         pwrap_writel(wrp, 0x1, PWRAP_WACS0_EN);
82 @@ -793,7 +787,7 @@ static int pwrap_init(struct pmic_wrapper *wrp)
83         pwrap_writel(wrp, 1, PWRAP_INIT_DONE0);
84         pwrap_writel(wrp, 1, PWRAP_INIT_DONE1);
85  
86 -       if (pwrap_is_mt8135(wrp)) {
87 +       if (wrp->master->has_bridge) {
88                 writel(1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INIT_DONE3);
89                 writel(1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INIT_DONE4);
90         }
91 @@ -831,6 +825,7 @@ static struct pmic_wrapper_type pwrap_mt8135 = {
92         .int_en_all = ~(BIT(31) | BIT(1)),
93         .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
94         .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
95 +       .has_bridge = 1,
96         .init_reg_clock = pwrap_mt8135_init_reg_clock,
97         .init_soc_specific = pwrap_mt8135_init_soc_specific,
98  };
99 @@ -842,6 +837,7 @@ static struct pmic_wrapper_type pwrap_mt8173 = {
100         .int_en_all = ~(BIT(31) | BIT(1)),
101         .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
102         .wdt_src = PWRAP_WDT_SRC_MASK_NO_STAUPD,
103 +       .has_bridge = 0,
104         .init_reg_clock = pwrap_mt8173_init_reg_clock,
105         .init_soc_specific = pwrap_mt8173_init_soc_specific,
106  };
107 @@ -889,7 +885,7 @@ static int pwrap_probe(struct platform_device *pdev)
108                 return ret;
109         }
110  
111 -       if (pwrap_is_mt8135(wrp)) {
112 +       if (wrp->master->has_bridge) {
113                 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
114                                 "pwrap-bridge");
115                 wrp->bridge_base = devm_ioremap_resource(wrp->dev, res);
116 -- 
117 1.7.10.4
118