aboutsummaryrefslogtreecommitdiffstats
path: root/testing/linux-amlogic/0002-ASoC-meson-add-meson-audio-core-driver.patch
blob: 6acbf80c86e2469c735d9d67dc2a87a6c017ad11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
From 4770a464de7b87bc849e4e110f197ef9fa7bccf6 Mon Sep 17 00:00:00 2001
From: Jerome Brunet <jbrunet@baylibre.com>
Date: Thu, 30 Mar 2017 11:49:55 +0200
Subject: [PATCH] ASoC: meson: add meson audio core driver

This patch adds support for the audio core driver for the Amlogic Meson SoC
family. The purpose of this driver is to properly reset the audio block and
provide register access for the different devices scattered in this address
space. This includes output and input DMAs, pcm, i2s and spdif dai, card
level routing, internal codec for the gxl variant

For more information, please refer to the section 5 of the public datasheet
of the S905 (gxbb). This datasheet is available here: [0].

[0]: http://dn.odroid.com/S905/DataSheet/S905_Public_Datasheet_V1.1.4.pdf

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>

---
 sound/soc/meson/Kconfig      |  10 +++
 sound/soc/meson/Makefile     |   4 +
 sound/soc/meson/audio-core.c | 190 +++++++++++++++++++++++++++++++++++++++++++
 sound/soc/meson/audio-core.h |  28 +++++++
 4 files changed, 232 insertions(+)
 create mode 100644 sound/soc/meson/audio-core.c
 create mode 100644 sound/soc/meson/audio-core.h

diff --git a/sound/soc/meson/Kconfig b/sound/soc/meson/Kconfig
index 8af8bc3..ed432d4 100644
--- a/sound/soc/meson/Kconfig
+++ b/sound/soc/meson/Kconfig
@@ -63,3 +63,13 @@ config SND_MESON_AXG_SPDIFOUT
 	  in the Amlogic AXG SoC family
 
 endmenu
+
+menuconfig SND_SOC_MESON
+	tristate "ASoC support for Amlogic Meson SoCs"
+	depends on ARCH_MESON
+	select MFD_CORE
+	select REGMAP_MMIO
+	help
+	  Say Y or M if you want to add support for codecs attached to
+	  the Amlogic Meson SoCs Audio interfaces. You will also need to
+	  select the audio interfaces to support below.
diff --git a/sound/soc/meson/Makefile b/sound/soc/meson/Makefile
index c5e003b..768d7c4 100644
--- a/sound/soc/meson/Makefile
+++ b/sound/soc/meson/Makefile
@@ -19,3 +19,7 @@ obj-$(CONFIG_SND_MESON_AXG_TDMIN) += snd-soc-meson-axg-tdmin.o
 obj-$(CONFIG_SND_MESON_AXG_TDMOUT) += snd-soc-meson-axg-tdmout.o
 obj-$(CONFIG_SND_MESON_AXG_SOUND_CARD) += snd-soc-meson-axg-sound-card.o
 obj-$(CONFIG_SND_MESON_AXG_SPDIFOUT) += snd-soc-meson-axg-spdifout.o
+
+snd-soc-meson-audio-core-objs	 := audio-core.o
+
+obj-$(CONFIG_SND_SOC_MESON) += snd-soc-meson-audio-core.o
\ No newline at end of file
diff --git a/sound/soc/meson/audio-core.c b/sound/soc/meson/audio-core.c
new file mode 100644
index 0000000..99993ec
--- /dev/null
+++ b/sound/soc/meson/audio-core.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2017 BayLibre, SAS
+ * Author: Jerome Brunet <jbrunet@baylibre.com>
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/clk.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+
+#include "audio-core.h"
+
+#define DRV_NAME "meson-audio-core"
+
+static const char * const acore_clock_names[] = { "aiu_top",
+						  "aiu_glue",
+						  "audin" };
+
+static int meson_acore_init_clocks(struct device *dev)
+{
+	struct clk *clock;
+	int i, ret;
+
+	for (i = 0; i < ARRAY_SIZE(acore_clock_names); i++) {
+		clock = devm_clk_get(dev, acore_clock_names[i]);
+		if (IS_ERR(clock)) {
+			if (PTR_ERR(clock) != -EPROBE_DEFER)
+				dev_err(dev, "Failed to get %s clock\n",
+					acore_clock_names[i]);
+			return PTR_ERR(clock);
+		}
+
+		ret = clk_prepare_enable(clock);
+		if (ret) {
+			dev_err(dev, "Failed to enable %s clock\n",
+				acore_clock_names[i]);
+			return ret;
+		}
+
+		ret = devm_add_action_or_reset(dev,
+				(void(*)(void *))clk_disable_unprepare,
+				clock);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static const char * const acore_reset_names[] = { "aiu",
+						  "audin" };
+
+static int meson_acore_init_resets(struct device *dev)
+{
+	struct reset_control *reset;
+	int i, ret;
+
+	for (i = 0; i < ARRAY_SIZE(acore_reset_names); i++) {
+		reset = devm_reset_control_get_exclusive(dev,
+							 acore_reset_names[i]);
+		if (IS_ERR(reset)) {
+			if (PTR_ERR(reset) != -EPROBE_DEFER)
+				dev_err(dev, "Failed to get %s reset\n",
+					acore_reset_names[i]);
+			return PTR_ERR(reset);
+		}
+
+		ret = reset_control_reset(reset);
+		if (ret) {
+			dev_err(dev, "Failed to pulse %s reset\n",
+				acore_reset_names[i]);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static const struct regmap_config meson_acore_regmap_config = {
+	.reg_bits       = 32,
+	.val_bits       = 32,
+	.reg_stride     = 4,
+};
+
+static const struct mfd_cell meson_acore_devs[] = {
+	{
+		.name = "meson-i2s-dai",
+		.of_compatible = "amlogic,meson-i2s-dai",
+	},
+	{
+		.name = "meson-spdif-dai",
+		.of_compatible = "amlogic,meson-spdif-dai",
+	},
+	{
+		.name = "meson-aiu-i2s-dma",
+		.of_compatible = "amlogic,meson-aiu-i2s-dma",
+	},
+	{
+		.name = "meson-aiu-spdif-dma",
+		.of_compatible = "amlogic,meson-aiu-spdif-dma",
+	},
+};
+
+static int meson_acore_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct meson_audio_core_data *data;
+	struct resource *res;
+	void __iomem *regs;
+	int ret;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, data);
+
+	ret = meson_acore_init_clocks(dev);
+	if (ret)
+		return ret;
+
+	ret = meson_acore_init_resets(dev);
+	if (ret)
+		return ret;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aiu");
+	regs = devm_ioremap_resource(dev, res);
+	if (IS_ERR(regs))
+		return PTR_ERR(regs);
+
+	data->aiu = devm_regmap_init_mmio(dev, regs,
+					  &meson_acore_regmap_config);
+	if (IS_ERR(data->aiu)) {
+		dev_err(dev, "Couldn't create the AIU regmap\n");
+		return PTR_ERR(data->aiu);
+	}
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "audin");
+	regs = devm_ioremap_resource(dev, res);
+	if (IS_ERR(regs))
+		return PTR_ERR(regs);
+
+	data->audin = devm_regmap_init_mmio(dev, regs,
+					    &meson_acore_regmap_config);
+	if (IS_ERR(data->audin)) {
+		dev_err(dev, "Couldn't create the AUDIN regmap\n");
+		return PTR_ERR(data->audin);
+	}
+
+	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, meson_acore_devs,
+				    ARRAY_SIZE(meson_acore_devs), NULL, 0,
+				    NULL);
+}
+
+static const struct of_device_id meson_acore_of_match[] = {
+	{ .compatible = "amlogic,meson-audio-core", },
+	{ .compatible = "amlogic,meson-gxbb-audio-core", },
+	{ .compatible = "amlogic,meson-gxl-audio-core", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, meson_acore_of_match);
+
+static struct platform_driver meson_acore_pdrv = {
+	.probe = meson_acore_probe,
+	.driver = {
+		.name = DRV_NAME,
+		.of_match_table = meson_acore_of_match,
+	},
+};
+module_platform_driver(meson_acore_pdrv);
+
+MODULE_DESCRIPTION("Meson Audio Core Driver");
+MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
+MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/meson/audio-core.h b/sound/soc/meson/audio-core.h
new file mode 100644
index 0000000..6e7a24c
--- /dev/null
+++ b/sound/soc/meson/audio-core.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2017 BayLibre, SAS
+ * Author: Jerome Brunet <jbrunet@baylibre.com>
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_AUDIO_CORE_H_
+#define _MESON_AUDIO_CORE_H_
+
+struct meson_audio_core_data {
+	struct regmap *aiu;
+	struct regmap *audin;
+};
+
+#endif /* _MESON_AUDIO_CORE_H_ */