mediatek: backport upstream mediatek patches
[oweals/openwrt.git] / target / linux / mediatek / patches-4.14 / 0185-ASoC-mediatek-modify-MT2701-AFE-driver-to-adapt-mfd-.patch
1 From 310ca2954c7cce10d716001ff869bc255494e3df Mon Sep 17 00:00:00 2001
2 From: Ryder Lee <ryder.lee@mediatek.com>
3 Date: Thu, 4 Jan 2018 15:44:08 +0800
4 Subject: [PATCH 185/224] ASoC: mediatek: modify MT2701 AFE driver to adapt mfd
5  device
6
7 As the new MFD parent is in place, modify MT2701 AFE driver to adapt it.
8
9 Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
10 Signed-off-by: Mark Brown <broonie@kernel.org>
11 ---
12  sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 45 +++++++++++++-----------------
13  sound/soc/mediatek/mt2701/mt2701-reg.h     |  1 -
14  2 files changed, 20 insertions(+), 26 deletions(-)
15
16 diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
17 index 0edadca12a5e..f0cd08fa5c5d 100644
18 --- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
19 +++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
20 @@ -17,6 +17,7 @@
21  
22  #include <linux/delay.h>
23  #include <linux/module.h>
24 +#include <linux/mfd/syscon.h>
25  #include <linux/of.h>
26  #include <linux/of_address.h>
27  #include <linux/pm_runtime.h>
28 @@ -1368,14 +1369,6 @@ static const struct mt2701_i2s_data mt2701_i2s_data[MT2701_I2S_NUM][2] = {
29         },
30  };
31  
32 -static const struct regmap_config mt2701_afe_regmap_config = {
33 -       .reg_bits = 32,
34 -       .reg_stride = 4,
35 -       .val_bits = 32,
36 -       .max_register = AFE_END_ADDR,
37 -       .cache_type = REGCACHE_NONE,
38 -};
39 -
40  static irqreturn_t mt2701_asys_isr(int irq_id, void *dev)
41  {
42         int id;
43 @@ -1414,9 +1407,9 @@ static int mt2701_afe_runtime_resume(struct device *dev)
44  
45  static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev)
46  {
47 +       struct snd_soc_component *component;
48         struct mtk_base_afe *afe;
49         struct mt2701_afe_private *afe_priv;
50 -       struct resource *res;
51         struct device *dev;
52         int i, irq_id, ret;
53  
54 @@ -1446,17 +1439,11 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev)
55                 return ret;
56         }
57  
58 -       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
59 -
60 -       afe->base_addr = devm_ioremap_resource(&pdev->dev, res);
61 -
62 -       if (IS_ERR(afe->base_addr))
63 -               return PTR_ERR(afe->base_addr);
64 -
65 -       afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr,
66 -               &mt2701_afe_regmap_config);
67 -       if (IS_ERR(afe->regmap))
68 -               return PTR_ERR(afe->regmap);
69 +       afe->regmap = syscon_node_to_regmap(dev->parent->of_node);
70 +       if (!afe->regmap) {
71 +               dev_err(dev, "could not get regmap from parent\n");
72 +               return -ENODEV;
73 +       }
74  
75         mutex_init(&afe->irq_alloc_lock);
76  
77 @@ -1490,6 +1477,12 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev)
78                         = &mt2701_i2s_data[i][I2S_IN];
79         }
80  
81 +       component = kzalloc(sizeof(*component), GFP_KERNEL);
82 +       if (!component)
83 +               return -ENOMEM;
84 +
85 +       component->regmap = afe->regmap;
86 +
87         afe->mtk_afe_hardware = &mt2701_afe_hardware;
88         afe->memif_fs = mt2701_memif_fs;
89         afe->irq_fs = mt2701_irq_fs;
90 @@ -1502,7 +1495,7 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev)
91         ret = mt2701_init_clock(afe);
92         if (ret) {
93                 dev_err(dev, "init clock error\n");
94 -               return ret;
95 +               goto err_init_clock;
96         }
97  
98         platform_set_drvdata(pdev, afe);
99 @@ -1521,10 +1514,10 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev)
100                 goto err_platform;
101         }
102  
103 -       ret = snd_soc_register_component(&pdev->dev,
104 -                                        &mt2701_afe_pcm_dai_component,
105 -                                        mt2701_afe_pcm_dais,
106 -                                        ARRAY_SIZE(mt2701_afe_pcm_dais));
107 +       ret = snd_soc_add_component(dev, component,
108 +                                   &mt2701_afe_pcm_dai_component,
109 +                                   mt2701_afe_pcm_dais,
110 +                                   ARRAY_SIZE(mt2701_afe_pcm_dais));
111         if (ret) {
112                 dev_warn(dev, "err_dai_component\n");
113                 goto err_dai_component;
114 @@ -1538,6 +1531,8 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev)
115         pm_runtime_put_sync(dev);
116  err_pm_disable:
117         pm_runtime_disable(dev);
118 +err_init_clock:
119 +       kfree(component);
120  
121         return ret;
122  }
123 diff --git a/sound/soc/mediatek/mt2701/mt2701-reg.h b/sound/soc/mediatek/mt2701/mt2701-reg.h
124 index f17c76f37b5f..18e676974f22 100644
125 --- a/sound/soc/mediatek/mt2701/mt2701-reg.h
126 +++ b/sound/soc/mediatek/mt2701/mt2701-reg.h
127 @@ -145,5 +145,4 @@
128  #define ASYS_I2S_CON_WIDE_MODE_SET(x)  ((x) << 1)
129  #define ASYS_I2S_IN_PHASE_FIX          (0x1 << 31)
130  
131 -#define AFE_END_ADDR 0x15e0
132  #endif
133 -- 
134 2.11.0
135