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/jack.h>
20 #include <asm/mach-types.h>
21 #include <mach/gpio.h>
22 #include <mach/regs-clock.h>
24 #include <linux/mfd/wm8994/core.h>
25 #include <linux/mfd/wm8994/registers.h>
26 #include "../codecs/wm8994.h"
30 #define MACHINE_NAME 0
31 #define CPU_VOICE_DAI 1
33 static const char *aquila_str
[] = {
34 [MACHINE_NAME
] = "aquila",
35 [CPU_VOICE_DAI
] = "aquila-voice-dai",
38 static struct snd_soc_card goni
;
39 static struct platform_device
*goni_snd_device
;
42 static struct snd_soc_jack jack
;
44 /* 3.5 pie jack detection DAPM pins */
45 static struct snd_soc_jack_pin jack_pins
[] = {
48 .mask
= SND_JACK_MICROPHONE
,
50 .pin
= "Headset Stereophone",
51 .mask
= SND_JACK_HEADPHONE
| SND_JACK_MECHANICAL
|
56 /* 3.5 pie jack detection gpios */
57 static struct snd_soc_jack_gpio jack_gpios
[] = {
59 .gpio
= S5PV210_GPH0(6),
61 .report
= SND_JACK_HEADSET
| SND_JACK_MECHANICAL
|
67 static const struct snd_soc_dapm_widget goni_dapm_widgets
[] = {
68 SND_SOC_DAPM_SPK("Ext Left Spk", NULL
),
69 SND_SOC_DAPM_SPK("Ext Right Spk", NULL
),
70 SND_SOC_DAPM_SPK("Ext Rcv", NULL
),
71 SND_SOC_DAPM_HP("Headset Stereophone", NULL
),
72 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
73 SND_SOC_DAPM_MIC("Main Mic", NULL
),
74 SND_SOC_DAPM_MIC("2nd Mic", NULL
),
75 SND_SOC_DAPM_LINE("Radio In", NULL
),
78 static const struct snd_soc_dapm_route goni_dapm_routes
[] = {
79 {"Ext Left Spk", NULL
, "SPKOUTLP"},
80 {"Ext Left Spk", NULL
, "SPKOUTLN"},
82 {"Ext Right Spk", NULL
, "SPKOUTRP"},
83 {"Ext Right Spk", NULL
, "SPKOUTRN"},
85 {"Ext Rcv", NULL
, "HPOUT2N"},
86 {"Ext Rcv", NULL
, "HPOUT2P"},
88 {"Headset Stereophone", NULL
, "HPOUT1L"},
89 {"Headset Stereophone", NULL
, "HPOUT1R"},
91 {"IN1RN", NULL
, "Headset Mic"},
92 {"IN1RP", NULL
, "Headset Mic"},
94 {"IN1RN", NULL
, "2nd Mic"},
95 {"IN1RP", NULL
, "2nd Mic"},
97 {"IN1LN", NULL
, "Main Mic"},
98 {"IN1LP", NULL
, "Main Mic"},
100 {"IN2LN", NULL
, "Radio In"},
101 {"IN2RN", NULL
, "Radio In"},
104 static int goni_wm8994_init(struct snd_soc_pcm_runtime
*rtd
)
106 struct snd_soc_codec
*codec
= rtd
->codec
;
107 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
110 /* add goni specific widgets */
111 snd_soc_dapm_new_controls(dapm
, goni_dapm_widgets
,
112 ARRAY_SIZE(goni_dapm_widgets
));
114 /* set up goni specific audio routes */
115 snd_soc_dapm_add_routes(dapm
, goni_dapm_routes
,
116 ARRAY_SIZE(goni_dapm_routes
));
118 /* set endpoints to not connected */
119 snd_soc_dapm_nc_pin(dapm
, "IN2LP:VXRN");
120 snd_soc_dapm_nc_pin(dapm
, "IN2RP:VXRP");
121 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1N");
122 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1P");
123 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2N");
124 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2P");
126 if (machine_is_aquila()) {
127 snd_soc_dapm_nc_pin(dapm
, "SPKOUTRN");
128 snd_soc_dapm_nc_pin(dapm
, "SPKOUTRP");
131 snd_soc_dapm_sync(dapm
);
133 /* Headset jack detection */
134 ret
= snd_soc_jack_new(&goni
, "Headset Jack",
135 SND_JACK_HEADSET
| SND_JACK_MECHANICAL
| SND_JACK_AVOUT
,
140 ret
= snd_soc_jack_add_pins(&jack
, ARRAY_SIZE(jack_pins
), jack_pins
);
144 ret
= snd_soc_jack_add_gpios(&jack
, ARRAY_SIZE(jack_gpios
), jack_gpios
);
151 static int goni_hifi_hw_params(struct snd_pcm_substream
*substream
,
152 struct snd_pcm_hw_params
*params
)
154 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
155 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
156 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
157 unsigned int pll_out
= 24000000;
160 /* set the cpu DAI configuration */
161 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
162 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM
);
166 /* set codec DAI configuration */
167 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
168 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM
);
172 /* set the codec FLL */
173 ret
= snd_soc_dai_set_pll(codec_dai
, WM8994_FLL1
, 0, pll_out
,
174 params_rate(params
) * 256);
178 /* set the codec system clock */
179 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_FLL1
,
180 params_rate(params
) * 256, SND_SOC_CLOCK_IN
);
187 static struct snd_soc_ops goni_hifi_ops
= {
188 .hw_params
= goni_hifi_hw_params
,
191 static int goni_voice_hw_params(struct snd_pcm_substream
*substream
,
192 struct snd_pcm_hw_params
*params
)
194 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
195 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
196 unsigned int pll_out
= 24000000;
199 if (params_rate(params
) != 8000)
202 /* set codec DAI configuration */
203 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_LEFT_J
|
204 SND_SOC_DAIFMT_IB_IF
| SND_SOC_DAIFMT_CBM_CFM
);
208 /* set the codec FLL */
209 ret
= snd_soc_dai_set_pll(codec_dai
, WM8994_FLL2
, 0, pll_out
,
210 params_rate(params
) * 256);
214 /* set the codec system clock */
215 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_FLL2
,
216 params_rate(params
) * 256, SND_SOC_CLOCK_IN
);
223 static struct snd_soc_dai_driver voice_dai
= {
224 .name
= "goni-voice-dai",
229 .rates
= SNDRV_PCM_RATE_8000
,
230 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
234 .rates
= SNDRV_PCM_RATE_8000
,
235 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
238 static struct snd_soc_ops goni_voice_ops
= {
239 .hw_params
= goni_voice_hw_params
,
242 static struct snd_soc_dai_link goni_dai
[] = {
245 .stream_name
= "WM8994 HiFi",
246 .cpu_dai_name
= "samsung-i2s.0",
247 .codec_dai_name
= "wm8994-hifi",
248 .platform_name
= "samsung-audio",
249 .codec_name
= "wm8994-codec.0-0x1a",
250 .init
= goni_wm8994_init
,
251 .ops
= &goni_hifi_ops
,
253 .name
= "WM8994 Voice",
254 .stream_name
= "Voice",
255 .cpu_dai_name
= "goni-voice-dai",
256 .codec_dai_name
= "wm8994-voice",
257 .platform_name
= "samsung-audio",
258 .codec_name
= "wm8994-codec.0-0x1a",
259 .ops
= &goni_voice_ops
,
263 static struct snd_soc_card goni
= {
265 .dai_link
= goni_dai
,
266 .num_links
= ARRAY_SIZE(goni_dai
),
269 static int __init
goni_init(void)
273 if (machine_is_aquila()) {
274 voice_dai
.name
= aquila_str
[CPU_VOICE_DAI
];
275 goni_dai
[1].cpu_dai_name
= aquila_str
[CPU_VOICE_DAI
];
276 goni
.name
= aquila_str
[MACHINE_NAME
];
277 } else if (!machine_is_goni())
280 goni_snd_device
= platform_device_alloc("soc-audio", -1);
281 if (!goni_snd_device
)
284 /* register voice DAI here */
285 ret
= snd_soc_register_dai(&goni_snd_device
->dev
, &voice_dai
);
289 platform_set_drvdata(goni_snd_device
, &goni
);
290 ret
= platform_device_add(goni_snd_device
);
293 platform_device_put(goni_snd_device
);
298 static void __exit
goni_exit(void)
300 platform_device_unregister(goni_snd_device
);
303 module_init(goni_init
);
304 module_exit(goni_exit
);
306 /* Module information */
307 MODULE_DESCRIPTION("ALSA SoC WM8994 GONI(S5PV210)");
308 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
309 MODULE_LICENSE("GPL");