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 <sound/soc.h>
15 #include <sound/jack.h>
17 #include <asm/mach-types.h>
18 #include <mach/gpio.h>
20 #include "../codecs/wm8994.h"
22 #define MACHINE_NAME 0
23 #define CPU_VOICE_DAI 1
25 static const char *aquila_str
[] = {
26 [MACHINE_NAME
] = "aquila",
27 [CPU_VOICE_DAI
] = "aquila-voice-dai",
30 static struct snd_soc_card goni
;
31 static struct platform_device
*goni_snd_device
;
34 static struct snd_soc_jack jack
;
36 /* 3.5 pie jack detection DAPM pins */
37 static struct snd_soc_jack_pin jack_pins
[] = {
40 .mask
= SND_JACK_MICROPHONE
,
42 .pin
= "Headset Stereophone",
43 .mask
= SND_JACK_HEADPHONE
| SND_JACK_MECHANICAL
|
48 /* 3.5 pie jack detection gpios */
49 static struct snd_soc_jack_gpio jack_gpios
[] = {
51 .gpio
= S5PV210_GPH0(6),
53 .report
= SND_JACK_HEADSET
| SND_JACK_MECHANICAL
|
59 static const struct snd_soc_dapm_widget goni_dapm_widgets
[] = {
60 SND_SOC_DAPM_SPK("Ext Left Spk", NULL
),
61 SND_SOC_DAPM_SPK("Ext Right 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 goni_dapm_routes
[] = {
71 {"Ext Left Spk", NULL
, "SPKOUTLP"},
72 {"Ext Left Spk", NULL
, "SPKOUTLN"},
74 {"Ext Right Spk", NULL
, "SPKOUTRP"},
75 {"Ext Right Spk", NULL
, "SPKOUTRN"},
77 {"Ext Rcv", NULL
, "HPOUT2N"},
78 {"Ext Rcv", NULL
, "HPOUT2P"},
80 {"Headset Stereophone", NULL
, "HPOUT1L"},
81 {"Headset Stereophone", NULL
, "HPOUT1R"},
83 {"IN1RN", NULL
, "Headset Mic"},
84 {"IN1RP", NULL
, "Headset Mic"},
86 {"IN1RN", NULL
, "2nd Mic"},
87 {"IN1RP", NULL
, "2nd Mic"},
89 {"IN1LN", NULL
, "Main Mic"},
90 {"IN1LP", NULL
, "Main Mic"},
92 {"IN2LN", NULL
, "Radio In"},
93 {"IN2RN", NULL
, "Radio In"},
96 static int goni_wm8994_init(struct snd_soc_pcm_runtime
*rtd
)
98 struct snd_soc_codec
*codec
= rtd
->codec
;
99 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
102 /* set endpoints to not connected */
103 snd_soc_dapm_nc_pin(dapm
, "IN2LP:VXRN");
104 snd_soc_dapm_nc_pin(dapm
, "IN2RP:VXRP");
105 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1N");
106 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1P");
107 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2N");
108 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2P");
110 if (machine_is_aquila()) {
111 snd_soc_dapm_nc_pin(dapm
, "SPKOUTRN");
112 snd_soc_dapm_nc_pin(dapm
, "SPKOUTRP");
115 /* Headset jack detection */
116 ret
= snd_soc_jack_new(codec
, "Headset Jack",
117 SND_JACK_HEADSET
| SND_JACK_MECHANICAL
| SND_JACK_AVOUT
,
122 ret
= snd_soc_jack_add_pins(&jack
, ARRAY_SIZE(jack_pins
), jack_pins
);
126 ret
= snd_soc_jack_add_gpios(&jack
, ARRAY_SIZE(jack_gpios
), jack_gpios
);
133 static int goni_hifi_hw_params(struct snd_pcm_substream
*substream
,
134 struct snd_pcm_hw_params
*params
)
136 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
137 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
138 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
139 unsigned int pll_out
= 24000000;
142 /* set the cpu DAI configuration */
143 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
144 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM
);
148 /* set codec DAI configuration */
149 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
150 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM
);
154 /* set the codec FLL */
155 ret
= snd_soc_dai_set_pll(codec_dai
, WM8994_FLL1
, 0, pll_out
,
156 params_rate(params
) * 256);
160 /* set the codec system clock */
161 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_FLL1
,
162 params_rate(params
) * 256, SND_SOC_CLOCK_IN
);
169 static struct snd_soc_ops goni_hifi_ops
= {
170 .hw_params
= goni_hifi_hw_params
,
173 static int goni_voice_hw_params(struct snd_pcm_substream
*substream
,
174 struct snd_pcm_hw_params
*params
)
176 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
177 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
178 unsigned int pll_out
= 24000000;
181 if (params_rate(params
) != 8000)
184 /* set codec DAI configuration */
185 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_LEFT_J
|
186 SND_SOC_DAIFMT_IB_IF
| SND_SOC_DAIFMT_CBM_CFM
);
190 /* set the codec FLL */
191 ret
= snd_soc_dai_set_pll(codec_dai
, WM8994_FLL2
, 0, pll_out
,
192 params_rate(params
) * 256);
196 /* set the codec system clock */
197 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_FLL2
,
198 params_rate(params
) * 256, SND_SOC_CLOCK_IN
);
205 static struct snd_soc_dai_driver voice_dai
= {
206 .name
= "goni-voice-dai",
211 .rates
= SNDRV_PCM_RATE_8000
,
212 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
216 .rates
= SNDRV_PCM_RATE_8000
,
217 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
220 static struct snd_soc_ops goni_voice_ops
= {
221 .hw_params
= goni_voice_hw_params
,
224 static struct snd_soc_dai_link goni_dai
[] = {
227 .stream_name
= "WM8994 HiFi",
228 .cpu_dai_name
= "samsung-i2s.0",
229 .codec_dai_name
= "wm8994-aif1",
230 .platform_name
= "samsung-audio",
231 .codec_name
= "wm8994-codec.0-001a",
232 .init
= goni_wm8994_init
,
233 .ops
= &goni_hifi_ops
,
235 .name
= "WM8994 Voice",
236 .stream_name
= "Voice",
237 .cpu_dai_name
= "goni-voice-dai",
238 .codec_dai_name
= "wm8994-aif2",
239 .codec_name
= "wm8994-codec.0-001a",
240 .ops
= &goni_voice_ops
,
244 static struct snd_soc_card goni
= {
246 .dai_link
= goni_dai
,
247 .num_links
= ARRAY_SIZE(goni_dai
),
249 .dapm_widgets
= goni_dapm_widgets
,
250 .num_dapm_widgets
= ARRAY_SIZE(goni_dapm_widgets
),
251 .dapm_routes
= goni_dapm_routes
,
252 .num_dapm_routes
= ARRAY_SIZE(goni_dapm_routes
),
255 static int __init
goni_init(void)
259 if (machine_is_aquila()) {
260 voice_dai
.name
= aquila_str
[CPU_VOICE_DAI
];
261 goni_dai
[1].cpu_dai_name
= aquila_str
[CPU_VOICE_DAI
];
262 goni
.name
= aquila_str
[MACHINE_NAME
];
263 } else if (!machine_is_goni())
266 goni_snd_device
= platform_device_alloc("soc-audio", -1);
267 if (!goni_snd_device
)
270 /* register voice DAI here */
271 ret
= snd_soc_register_dai(&goni_snd_device
->dev
, &voice_dai
);
273 platform_device_put(goni_snd_device
);
277 platform_set_drvdata(goni_snd_device
, &goni
);
278 ret
= platform_device_add(goni_snd_device
);
281 snd_soc_unregister_dai(&goni_snd_device
->dev
);
282 platform_device_put(goni_snd_device
);
288 static void __exit
goni_exit(void)
290 snd_soc_unregister_dai(&goni_snd_device
->dev
);
291 platform_device_unregister(goni_snd_device
);
294 module_init(goni_init
);
295 module_exit(goni_exit
);
297 /* Module information */
298 MODULE_DESCRIPTION("ALSA SoC WM8994 GONI(S5PV210)");
299 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
300 MODULE_LICENSE("GPL");