summaryrefslogtreecommitdiff
path: root/patches.tizen/0145-sound-soc-samsung-Add-Trats-platform-audio-driver.patch
blob: f5de9193aa37b55d6dee5983bd7e00fc60cbc548 (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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
From efbbb1b1e58e713467f89f67f1122644c8fcff00 Mon Sep 17 00:00:00 2001
From: Tomasz Figa <t.figa@samsung.com>
Date: Thu, 28 Feb 2013 19:41:30 +0100
Subject: [PATCH 0145/1302] sound: soc: samsung: Add Trats platform audio
 driver

This patch adds ASoC platform glue driver for Trats board.

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
---
 sound/soc/samsung/Kconfig       |   6 +
 sound/soc/samsung/Makefile      |   2 +
 sound/soc/samsung/trats_mc1n2.c | 334 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 342 insertions(+)
 create mode 100644 sound/soc/samsung/trats_mc1n2.c

diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
index 475fb0d..0d321fc 100644
--- a/sound/soc/samsung/Kconfig
+++ b/sound/soc/samsung/Kconfig
@@ -199,6 +199,12 @@ config SND_SOC_TOBERMORY
 	select SND_SAMSUNG_I2S
 	select SND_SOC_WM8962
 
+config SND_SOC_TRATS
+	tristate "Audio support for Samsung Trats"
+	depends on SND_SOC_SAMSUNG && CPU_EXYNOS4210
+	select SND_SAMSUNG_I2S
+	select SND_SOC_MC1N2
+
 config SND_SOC_BELLS
 	tristate "Audio support for Wolfson Bells"
 	depends on SND_SOC_SAMSUNG && MACH_WLF_CRAGG_6410
diff --git a/sound/soc/samsung/Makefile b/sound/soc/samsung/Makefile
index 709f605..d2e9b37 100644
--- a/sound/soc/samsung/Makefile
+++ b/sound/soc/samsung/Makefile
@@ -40,6 +40,7 @@ snd-soc-smdk-wm8580pcm-objs := smdk_wm8580pcm.o
 snd-soc-smdk-wm8994pcm-objs := smdk_wm8994pcm.o
 snd-soc-speyside-objs := speyside.o
 snd-soc-tobermory-objs := tobermory.o
+snd-soc-trats-objs := trats_mc1n2.o
 snd-soc-lowland-objs := lowland.o
 snd-soc-littlemill-objs := littlemill.o
 snd-soc-bells-objs := bells.o
@@ -64,6 +65,7 @@ obj-$(CONFIG_SND_SOC_SMDK_WM8580_PCM) += snd-soc-smdk-wm8580pcm.o
 obj-$(CONFIG_SND_SOC_SMDK_WM8994_PCM) += snd-soc-smdk-wm8994pcm.o
 obj-$(CONFIG_SND_SOC_SPEYSIDE) += snd-soc-speyside.o
 obj-$(CONFIG_SND_SOC_TOBERMORY) += snd-soc-tobermory.o
+obj-$(CONFIG_SND_SOC_TRATS) += snd-soc-trats.o
 obj-$(CONFIG_SND_SOC_LOWLAND) += snd-soc-lowland.o
 obj-$(CONFIG_SND_SOC_LITTLEMILL) += snd-soc-littlemill.o
 obj-$(CONFIG_SND_SOC_BELLS) += snd-soc-bells.o
diff --git a/sound/soc/samsung/trats_mc1n2.c b/sound/soc/samsung/trats_mc1n2.c
new file mode 100644
index 0000000..83701dd
--- /dev/null
+++ b/sound/soc/samsung/trats_mc1n2.c
@@ -0,0 +1,334 @@
+/*
+ *  u1_mc1n2.c
+ *
+ *  Copyright (c) 2009 Samsung Electronics Co. Ltd
+ *  Author: aitdark.park  <aitdark.park@samsung.com>
+ *
+ *  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.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/suspend.h>
+
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+
+#include "../codecs/mc1n2/mc1n2.h"
+
+static bool xclkout_enabled;
+static struct clk *clkout;
+
+int mc1n2_set_mclk_source(bool on)
+{
+	if (xclkout_enabled == on)
+		return 0;
+
+	if (on)
+		clk_prepare_enable(clkout);
+	else
+		clk_disable_unprepare(clkout);
+
+	xclkout_enabled = on;
+	msleep(10);
+
+	return 0;
+}
+EXPORT_SYMBOL(mc1n2_set_mclk_source);
+
+static int u1_hifi_hw_params(struct snd_pcm_substream *substream,
+			      struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	int ret;
+
+	/* Set the codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+				| SND_SOC_DAIFMT_NB_NF
+				| SND_SOC_DAIFMT_CBM_CFM);
+	if (ret < 0)
+		return ret;
+
+	/* Set the cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
+				| SND_SOC_DAIFMT_NB_NF
+				| SND_SOC_DAIFMT_CBM_CFM);
+	if (ret < 0)
+		return ret;
+/* check later
+	ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_I2SV2_CLKSRC_CDCLK,
+				0, SND_SOC_CLOCK_IN);
+	if (ret < 0)
+		return ret;
+
+	ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_MUX,
+				0, SND_SOC_CLOCK_IN);
+	if (ret < 0)
+		return ret;
+*/
+
+	ret = snd_soc_dai_set_clkdiv(codec_dai, MC1N2_BCLK_MULT, MC1N2_LRCK_X32);
+
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+/* U1 Audio  extra controls */
+#define U1_AUDIO_OFF	0
+#define U1_HEADSET_OUT	1
+#define U1_MIC_IN	2
+#define U1_LINE_IN	3
+
+static int u1_aud_mode;
+
+static const char *u1_aud_scenario[] = {
+	[U1_AUDIO_OFF] = "Off",
+	[U1_HEADSET_OUT] = "Playback Headphones",
+	[U1_MIC_IN] = "Capture Mic",
+	[U1_LINE_IN] = "Capture Line",
+};
+
+static void u1_aud_ext_control(struct snd_soc_codec *codec)
+{
+	struct snd_soc_dapm_context *dapm = &codec->dapm;
+
+	switch (u1_aud_mode) {
+	case U1_HEADSET_OUT:
+		snd_soc_dapm_enable_pin(dapm, "Headset Out");
+		snd_soc_dapm_disable_pin(dapm, "Mic In");
+		snd_soc_dapm_disable_pin(dapm, "Line In");
+		break;
+	case U1_MIC_IN:
+		snd_soc_dapm_disable_pin(dapm, "Headset Out");
+		snd_soc_dapm_enable_pin(dapm, "Mic In");
+		snd_soc_dapm_disable_pin(dapm, "Line In");
+		break;
+	case U1_LINE_IN:
+		snd_soc_dapm_disable_pin(dapm, "Headset Out");
+		snd_soc_dapm_disable_pin(dapm, "Mic In");
+		snd_soc_dapm_enable_pin(dapm, "Line In");
+		break;
+	case U1_AUDIO_OFF:
+	default:
+		snd_soc_dapm_disable_pin(dapm, "Headset Out");
+		snd_soc_dapm_disable_pin(dapm, "Mic In");
+		snd_soc_dapm_disable_pin(dapm, "Line In");
+		break;
+	}
+
+	snd_soc_dapm_sync(dapm);
+}
+
+static int u1_mc1n2_getp(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	ucontrol->value.integer.value[0] = u1_aud_mode;
+	return 0;
+}
+
+static int u1_mc1n2_setp(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+	if (u1_aud_mode == ucontrol->value.integer.value[0])
+		return 0;
+
+	u1_aud_mode = ucontrol->value.integer.value[0];
+	u1_aud_ext_control(codec);
+
+	return 1;
+}
+
+static const struct snd_soc_dapm_widget u1_dapm_widgets[] = {
+	SND_SOC_DAPM_HP("Headset Out", NULL),
+	SND_SOC_DAPM_MIC("Mic In", NULL),
+	SND_SOC_DAPM_LINE("Line In", NULL),
+};
+
+static const struct soc_enum u1_aud_enum[] = {
+	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(u1_aud_scenario),
+			    u1_aud_scenario),
+};
+
+static const struct snd_kcontrol_new u1_aud_controls[] = {
+	SOC_ENUM_EXT("U1 Audio Mode", u1_aud_enum[0],
+		     u1_mc1n2_getp, u1_mc1n2_setp),
+};
+
+static const struct snd_soc_dapm_route u1_dapm_routes[] = {
+	/* Connections to Headset */
+	{"Headset Out", NULL, "HPOUT1L"},
+	{"Headset Out", NULL, "HPOUT1R"},
+	/* Connections to Mics */
+	{"IN1LN", NULL, "Mic In"},
+	{"IN1RN", NULL, "Mic In"},
+	/* Connections to Line In */
+	{"IN2LN", NULL, "Line In"},
+	{"IN2RN", NULL, "Line In"},
+};
+
+static int u1_hifiaudio_init(struct snd_soc_pcm_runtime *rtd)
+{
+	return 0;
+}
+
+/*
+ * U1 MC1N2 DAI operations.
+ */
+static struct snd_soc_ops u1_hifi_ops = {
+	.hw_params = u1_hifi_hw_params,
+};
+
+static struct snd_soc_dai_link u1_dai[] = {
+#if defined(CONFIG_SND_SAMSUNG_LP) || defined(CONFIG_SND_SAMSUNG_ALP)
+	{ /* Sec_Fifo DAI i/f */
+		.name = "MC1N2 Sec_FIFO TX",
+		.stream_name = "Sec_Dai",
+		.cpu_dai_name = "samsung-i2s.4",
+		.codec_dai_name = "mc1n2-da0i",
+#ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
+		.platform_name = "samsung-audio-idma",
+#else
+		.platform_name = "samsung-audio",
+#endif
+		.codec_name = "mc1n2.6-003a",
+		.init = u1_hifiaudio_init,
+		.ops = &u1_hifi_ops,
+	},
+#endif
+	{ /* Primary DAI i/f */
+		.name = "MC1N2 AIF1",
+		.stream_name = "hifiaudio",
+		.cpu_dai_name = "samsung-i2s.0",
+		.codec_dai_name = "mc1n2-da0i",
+		.platform_name = "samsung-audio",
+		.codec_name = "mc1n2.6-003a",
+		.init = u1_hifiaudio_init,
+		.ops = &u1_hifi_ops,
+	}
+};
+
+static int u1_card_suspend(struct snd_soc_card *card)
+{
+#warning FIXME
+#if 0
+	exynos4_sys_powerdown_parent_control(xclkout_enabled ? 1 : 0);
+#endif
+	return 0;
+}
+
+static struct snd_soc_card u1_snd_card = {
+	.name = "U1-YMU823",
+	.dai_link = u1_dai,
+	.num_links = ARRAY_SIZE(u1_dai),
+
+	.suspend_post = u1_card_suspend,
+};
+
+/* setup codec data from mc1n2 codec driver */
+extern void set_mc1n2_codec_data(struct mc1n2_setup *setup);
+
+static struct platform_device *u1_snd_device;
+
+static int u1_snd_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct clk *out_mux;
+	struct clk *parent;
+
+	if (pdev->dev.of_node) {
+		struct device_node *np = pdev->dev.of_node;
+		struct snd_soc_dai_link *link = u1_dai;
+
+		link->cpu_dai_name = NULL;
+		link->cpu_of_node = of_parse_phandle(np,
+						"samsung,i2s-controller", 0);
+		if (!link->cpu_of_node) {
+			dev_err(&pdev->dev, "failed to parse samsung,i2s-controller phandle\n");
+			return -EINVAL;
+		}
+
+		link->platform_name = NULL;
+		link->platform_of_node = link->cpu_of_node;
+
+		link->codec_name = NULL;
+		link->codec_of_node = of_parse_phandle(np,
+						"samsung,audio-codec", 0);
+		if (!link->codec_of_node) {
+			dev_err(&pdev->dev, "failed to parse samsung,audio-codec phandle\n");
+			return -EINVAL;
+		}
+	}
+
+	clkout = clk_get(&pdev->dev, "out");
+	if (IS_ERR(clkout)) {
+		dev_err(&pdev->dev, "failed to get out clock\n");
+		return PTR_ERR(clkout);
+	}
+
+	out_mux = clk_get(&pdev->dev, "out-mux");
+	if (IS_ERR(out_mux)) {
+		dev_err(&pdev->dev, "failed to get out mux clock\n");
+		return PTR_ERR(out_mux);
+	}
+
+	parent = clk_get(&pdev->dev, "parent");
+	if (IS_ERR(parent)) {
+		dev_err(&pdev->dev, "failed to get parent clock\n");
+		return PTR_ERR(parent);
+	}
+
+	clk_set_parent(out_mux, parent);
+	mc1n2_set_mclk_source(true);
+
+	u1_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!u1_snd_device)
+		return -ENOMEM;
+
+	platform_set_drvdata(u1_snd_device, &u1_snd_card);
+
+	ret = platform_device_add(u1_snd_device);
+	if (ret) {
+		platform_device_put(u1_snd_device);
+	}
+
+	return ret;
+}
+
+static void u1_snd_remove(struct platform_device *pdev)
+{
+	platform_device_unregister(u1_snd_device);
+}
+
+static struct of_device_id u1_snd_of_matches[] = {
+	{ .compatible = "samsung,u1-platform-snd", },
+	{}
+};
+
+static struct platform_driver u1_snd_driver = {
+	.driver = {
+		.name = "u1-platform-snd",
+		.of_match_table = u1_snd_of_matches,
+	},
+	.probe	= u1_snd_probe,
+	.remove	= u1_snd_remove,
+};
+module_platform_driver(u1_snd_driver);
+
+MODULE_AUTHOR("aitdark, aitdark.park@samsung.com");
+MODULE_DESCRIPTION("ALSA SoC U1 MC1N2");
+MODULE_LICENSE("GPL");
-- 
1.8.3.2