4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Chanwoo Choi <cw00.choi@samsung.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
17 #include <linux/platform_device.h>
18 #include <sound/soc.h>
19 #include <sound/soc-dapm.h>
20 #include <sound/jack.h>
21 #include <asm/mach-types.h>
22 #include <mach/gpio.h>
23 #include <mach/regs-clock.h>
25 #include <linux/mfd/wm8994/core.h>
26 #include <linux/mfd/wm8994/registers.h>
27 #include "../codecs/wm8994.h"
29 #include "s3c64xx-i2s.h"
31 static struct snd_soc_card aquila;
32 static struct platform_device *aquila_snd_device;
35 static struct snd_soc_jack jack;
37 /* 3.5 pie jack detection DAPM pins */
38 static struct snd_soc_jack_pin jack_pins[] = {
41 .mask = SND_JACK_MICROPHONE,
43 .pin = "Headset Stereophone",
44 .mask = SND_JACK_HEADPHONE | SND_JACK_MECHANICAL |
49 /* 3.5 pie jack detection gpios */
50 static struct snd_soc_jack_gpio jack_gpios[] = {
52 .gpio = S5PV210_GPH0(6),
54 .report = SND_JACK_HEADSET | SND_JACK_MECHANICAL |
60 static const struct snd_soc_dapm_widget aquila_dapm_widgets[] = {
61 SND_SOC_DAPM_SPK("Ext Spk", NULL),
62 SND_SOC_DAPM_SPK("Ext Rcv", NULL),
63 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
64 SND_SOC_DAPM_MIC("Headset Mic", NULL),
65 SND_SOC_DAPM_MIC("Main Mic", NULL),
66 SND_SOC_DAPM_MIC("2nd Mic", NULL),
67 SND_SOC_DAPM_LINE("Radio In", NULL),
70 static const struct snd_soc_dapm_route aquila_dapm_routes[] = {
71 {"Ext Spk", NULL, "SPKOUTLP"},
72 {"Ext Spk", NULL, "SPKOUTLN"},
74 {"Ext Rcv", NULL, "HPOUT2N"},
75 {"Ext Rcv", NULL, "HPOUT2P"},
77 {"Headset Stereophone", NULL, "HPOUT1L"},
78 {"Headset Stereophone", NULL, "HPOUT1R"},
80 {"IN1RN", NULL, "Headset Mic"},
81 {"IN1RP", NULL, "Headset Mic"},
83 {"IN1RN", NULL, "2nd Mic"},
84 {"IN1RP", NULL, "2nd Mic"},
86 {"IN1LN", NULL, "Main Mic"},
87 {"IN1LP", NULL, "Main Mic"},
89 {"IN2LN", NULL, "Radio In"},
90 {"IN2RN", NULL, "Radio In"},
93 static int aquila_wm8994_init(struct snd_soc_pcm_runtime *rtd)
95 struct snd_soc_codec *codec = rtd->codec;
96 struct snd_soc_dapm_context *dapm = &codec->dapm;
99 /* add aquila specific widgets */
100 snd_soc_dapm_new_controls(dapm, aquila_dapm_widgets,
101 ARRAY_SIZE(aquila_dapm_widgets));
103 /* set up aquila specific audio routes */
104 snd_soc_dapm_add_routes(dapm, aquila_dapm_routes,
105 ARRAY_SIZE(aquila_dapm_routes));
107 /* set endpoints to not connected */
108 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
109 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
110 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
111 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
112 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
113 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
114 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
115 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
117 snd_soc_dapm_sync(dapm);
119 /* Headset jack detection */
120 ret = snd_soc_jack_new(&aquila, "Headset Jack",
121 SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT,
126 ret = snd_soc_jack_add_pins(&jack, ARRAY_SIZE(jack_pins), jack_pins);
130 ret = snd_soc_jack_add_gpios(&jack, ARRAY_SIZE(jack_gpios), jack_gpios);
137 static int aquila_hifi_hw_params(struct snd_pcm_substream *substream,
138 struct snd_pcm_hw_params *params)
140 struct snd_soc_pcm_runtime *rtd = substream->private_data;
141 struct snd_soc_dai *codec_dai = rtd->codec_dai;
142 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
143 unsigned int pll_out = 24000000;
146 /* set the cpu DAI configuration */
147 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
148 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
152 /* set the cpu system clock */
153 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
154 0, SND_SOC_CLOCK_IN);
158 /* set codec DAI configuration */
159 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
160 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
164 /* set the codec FLL */
165 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out,
166 params_rate(params) * 256);
170 /* set the codec system clock */
171 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
172 params_rate(params) * 256, SND_SOC_CLOCK_IN);
179 static struct snd_soc_ops aquila_hifi_ops = {
180 .hw_params = aquila_hifi_hw_params,
183 static int aquila_voice_hw_params(struct snd_pcm_substream *substream,
184 struct snd_pcm_hw_params *params)
186 struct snd_soc_pcm_runtime *rtd = substream->private_data;
187 struct snd_soc_dai *codec_dai = rtd->codec_dai;
188 unsigned int pll_out = 24000000;
191 if (params_rate(params) != 8000)
194 /* set codec DAI configuration */
195 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
196 SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
200 /* set the codec FLL */
201 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out,
202 params_rate(params) * 256);
206 /* set the codec system clock */
207 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
208 params_rate(params) * 256, SND_SOC_CLOCK_IN);
215 static struct snd_soc_dai_driver voice_dai = {
216 .name = "aquila-voice-dai",
220 .rates = SNDRV_PCM_RATE_8000,
221 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
225 .rates = SNDRV_PCM_RATE_8000,
226 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
229 static struct snd_soc_ops aquila_voice_ops = {
230 .hw_params = aquila_voice_hw_params,
233 static struct snd_soc_dai_link aquila_dai[] = {
236 .stream_name = "WM8994 HiFi",
237 .cpu_dai_name = "s3c64xx-i2s-v4",
238 .codec_dai_name = "wm8994-hifi",
239 .platform_name = "s3c24xx-pcm-audio",
240 .codec_name = "wm8994-codec.0-0x1a",
241 .init = aquila_wm8994_init,
242 .ops = &aquila_hifi_ops,
244 .name = "WM8994 Voice",
245 .stream_name = "Voice",
246 .cpu_dai_name = "aquila-voice-dai",
247 .codec_dai_name = "wm8994-voice",
248 .platform_name = "s3c24xx-pcm-audio",
249 .codec_name = "wm8994-codec.0-0x1a",
250 .ops = &aquila_voice_ops,
254 static struct snd_soc_card aquila = {
256 .dai_link = aquila_dai,
257 .num_links = ARRAY_SIZE(aquila_dai),
260 static int __init aquila_init(void)
264 if (!machine_is_aquila())
267 aquila_snd_device = platform_device_alloc("soc-audio", -1);
268 if (!aquila_snd_device)
271 /* register voice DAI here */
272 ret = snd_soc_register_dai(&aquila_snd_device->dev, &voice_dai);
276 platform_set_drvdata(aquila_snd_device, &aquila);
277 ret = platform_device_add(aquila_snd_device);
280 platform_device_put(aquila_snd_device);
285 static void __exit aquila_exit(void)
287 platform_device_unregister(aquila_snd_device);
290 module_init(aquila_init);
291 module_exit(aquila_exit);
293 /* Module information */
294 MODULE_DESCRIPTION("ALSA SoC WM8994 Aquila(S5PC110)");
295 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
296 MODULE_LICENSE("GPL");