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 /* add goni specific widgets */
103 snd_soc_dapm_new_controls(dapm
, goni_dapm_widgets
,
104 ARRAY_SIZE(goni_dapm_widgets
));
106 /* set up goni specific audio routes */
107 snd_soc_dapm_add_routes(dapm
, goni_dapm_routes
,
108 ARRAY_SIZE(goni_dapm_routes
));
110 /* set endpoints to not connected */
111 snd_soc_dapm_nc_pin(dapm
, "IN2LP:VXRN");
112 snd_soc_dapm_nc_pin(dapm
, "IN2RP:VXRP");
113 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1N");
114 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1P");
115 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2N");
116 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2P");
118 if (machine_is_aquila()) {
119 snd_soc_dapm_nc_pin(dapm
, "SPKOUTRN");
120 snd_soc_dapm_nc_pin(dapm
, "SPKOUTRP");
123 snd_soc_dapm_sync(dapm
);
125 /* Headset jack detection */
126 ret
= snd_soc_jack_new(codec
, "Headset Jack",
127 SND_JACK_HEADSET
| SND_JACK_MECHANICAL
| SND_JACK_AVOUT
,
132 ret
= snd_soc_jack_add_pins(&jack
, ARRAY_SIZE(jack_pins
), jack_pins
);
136 ret
= snd_soc_jack_add_gpios(&jack
, ARRAY_SIZE(jack_gpios
), jack_gpios
);
143 static int goni_hifi_hw_params(struct snd_pcm_substream
*substream
,
144 struct snd_pcm_hw_params
*params
)
146 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
147 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
148 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
149 unsigned int pll_out
= 24000000;
152 /* set the cpu DAI configuration */
153 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
154 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM
);
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 goni_hifi_ops
= {
180 .hw_params
= goni_hifi_hw_params
,
183 static int goni_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
= "goni-voice-dai",
221 .rates
= SNDRV_PCM_RATE_8000
,
222 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
226 .rates
= SNDRV_PCM_RATE_8000
,
227 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
230 static struct snd_soc_ops goni_voice_ops
= {
231 .hw_params
= goni_voice_hw_params
,
234 static struct snd_soc_dai_link goni_dai
[] = {
237 .stream_name
= "WM8994 HiFi",
238 .cpu_dai_name
= "samsung-i2s.0",
239 .codec_dai_name
= "wm8994-hifi",
240 .platform_name
= "samsung-audio",
241 .codec_name
= "wm8994-codec.0-0x1a",
242 .init
= goni_wm8994_init
,
243 .ops
= &goni_hifi_ops
,
245 .name
= "WM8994 Voice",
246 .stream_name
= "Voice",
247 .cpu_dai_name
= "goni-voice-dai",
248 .codec_dai_name
= "wm8994-voice",
249 .platform_name
= "samsung-audio",
250 .codec_name
= "wm8994-codec.0-0x1a",
251 .ops
= &goni_voice_ops
,
255 static struct snd_soc_card goni
= {
257 .dai_link
= goni_dai
,
258 .num_links
= ARRAY_SIZE(goni_dai
),
261 static int __init
goni_init(void)
265 if (machine_is_aquila()) {
266 voice_dai
.name
= aquila_str
[CPU_VOICE_DAI
];
267 goni_dai
[1].cpu_dai_name
= aquila_str
[CPU_VOICE_DAI
];
268 goni
.name
= aquila_str
[MACHINE_NAME
];
269 } else if (!machine_is_goni())
272 goni_snd_device
= platform_device_alloc("soc-audio", -1);
273 if (!goni_snd_device
)
276 /* register voice DAI here */
277 ret
= snd_soc_register_dai(&goni_snd_device
->dev
, &voice_dai
);
279 platform_device_put(goni_snd_device
);
283 platform_set_drvdata(goni_snd_device
, &goni
);
284 ret
= platform_device_add(goni_snd_device
);
287 snd_soc_unregister_dai(&goni_snd_device
->dev
);
288 platform_device_put(goni_snd_device
);
294 static void __exit
goni_exit(void)
296 snd_soc_unregister_dai(&goni_snd_device
->dev
);
297 platform_device_unregister(goni_snd_device
);
300 module_init(goni_init
);
301 module_exit(goni_exit
);
303 /* Module information */
304 MODULE_DESCRIPTION("ALSA SoC WM8994 GONI(S5PV210)");
305 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
306 MODULE_LICENSE("GPL");