blob: 4a34f608e131127aa73a27618e6c5870d60c1e7e [file] [log] [blame]
Chanwoo Choif51582f2010-07-22 15:16:10 +09001/*
2 * goni_wm8994.c
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Chanwoo Choi <cw00.choi@samsung.com>
6 *
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.
11 *
12 */
13
Chanwoo Choif51582f2010-07-22 15:16:10 +090014#include <sound/soc.h>
Chanwoo Choif51582f2010-07-22 15:16:10 +090015#include <sound/jack.h>
Seungwhan Youn0378b6a2011-01-11 07:26:06 +090016
Chanwoo Choif51582f2010-07-22 15:16:10 +090017#include <asm/mach-types.h>
18#include <mach/gpio.h>
Chanwoo Choif51582f2010-07-22 15:16:10 +090019
Chanwoo Choif51582f2010-07-22 15:16:10 +090020#include "../codecs/wm8994.h"
Chanwoo Choif51582f2010-07-22 15:16:10 +090021
Jassi Brar3a56d0c2010-11-22 15:35:36 +090022#define MACHINE_NAME 0
23#define CPU_VOICE_DAI 1
24
25static const char *aquila_str[] = {
26 [MACHINE_NAME] = "aquila",
27 [CPU_VOICE_DAI] = "aquila-voice-dai",
28};
29
Chanwoo Choif51582f2010-07-22 15:16:10 +090030static struct snd_soc_card goni;
31static struct platform_device *goni_snd_device;
32
33/* 3.5 pie jack */
34static struct snd_soc_jack jack;
35
36/* 3.5 pie jack detection DAPM pins */
37static struct snd_soc_jack_pin jack_pins[] = {
38 {
39 .pin = "Headset Mic",
40 .mask = SND_JACK_MICROPHONE,
41 }, {
42 .pin = "Headset Stereophone",
43 .mask = SND_JACK_HEADPHONE | SND_JACK_MECHANICAL |
44 SND_JACK_AVOUT,
45 },
46};
47
48/* 3.5 pie jack detection gpios */
49static struct snd_soc_jack_gpio jack_gpios[] = {
50 {
51 .gpio = S5PV210_GPH0(6),
52 .name = "DET_3.5",
53 .report = SND_JACK_HEADSET | SND_JACK_MECHANICAL |
54 SND_JACK_AVOUT,
55 .debounce_time = 200,
56 },
57};
58
59static 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),
68};
69
70static const struct snd_soc_dapm_route goni_dapm_routes[] = {
71 {"Ext Left Spk", NULL, "SPKOUTLP"},
72 {"Ext Left Spk", NULL, "SPKOUTLN"},
73
74 {"Ext Right Spk", NULL, "SPKOUTRP"},
75 {"Ext Right Spk", NULL, "SPKOUTRN"},
76
77 {"Ext Rcv", NULL, "HPOUT2N"},
78 {"Ext Rcv", NULL, "HPOUT2P"},
79
80 {"Headset Stereophone", NULL, "HPOUT1L"},
81 {"Headset Stereophone", NULL, "HPOUT1R"},
82
83 {"IN1RN", NULL, "Headset Mic"},
84 {"IN1RP", NULL, "Headset Mic"},
85
86 {"IN1RN", NULL, "2nd Mic"},
87 {"IN1RP", NULL, "2nd Mic"},
88
89 {"IN1LN", NULL, "Main Mic"},
90 {"IN1LP", NULL, "Main Mic"},
91
92 {"IN2LN", NULL, "Radio In"},
93 {"IN2RN", NULL, "Radio In"},
94};
95
96static int goni_wm8994_init(struct snd_soc_pcm_runtime *rtd)
97{
98 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020099 struct snd_soc_dapm_context *dapm = &codec->dapm;
Chanwoo Choif51582f2010-07-22 15:16:10 +0900100 int ret;
101
Chanwoo Choif51582f2010-07-22 15:16:10 +0900102 /* set endpoints to not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200103 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");
Chanwoo Choif51582f2010-07-22 15:16:10 +0900109
Jassi Brar3a56d0c2010-11-22 15:35:36 +0900110 if (machine_is_aquila()) {
111 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
112 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
113 }
114
Chanwoo Choif51582f2010-07-22 15:16:10 +0900115 /* Headset jack detection */
Seungwhan Younf49be892010-12-22 18:46:24 +0900116 ret = snd_soc_jack_new(codec, "Headset Jack",
Chanwoo Choif51582f2010-07-22 15:16:10 +0900117 SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT,
118 &jack);
119 if (ret)
120 return ret;
121
122 ret = snd_soc_jack_add_pins(&jack, ARRAY_SIZE(jack_pins), jack_pins);
123 if (ret)
124 return ret;
125
126 ret = snd_soc_jack_add_gpios(&jack, ARRAY_SIZE(jack_gpios), jack_gpios);
127 if (ret)
128 return ret;
129
130 return 0;
131}
132
133static int goni_hifi_hw_params(struct snd_pcm_substream *substream,
134 struct snd_pcm_hw_params *params)
135{
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;
140 int ret = 0;
141
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);
145 if (ret < 0)
146 return ret;
147
Chanwoo Choif51582f2010-07-22 15:16:10 +0900148 /* 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);
151 if (ret < 0)
152 return ret;
153
154 /* set the codec FLL */
155 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out,
156 params_rate(params) * 256);
157 if (ret < 0)
158 return ret;
159
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);
163 if (ret < 0)
164 return ret;
165
166 return 0;
167}
168
169static struct snd_soc_ops goni_hifi_ops = {
170 .hw_params = goni_hifi_hw_params,
171};
172
173static int goni_voice_hw_params(struct snd_pcm_substream *substream,
174 struct snd_pcm_hw_params *params)
175{
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;
179 int ret = 0;
180
181 if (params_rate(params) != 8000)
182 return -EINVAL;
183
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);
187 if (ret < 0)
188 return ret;
189
190 /* set the codec FLL */
191 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out,
192 params_rate(params) * 256);
193 if (ret < 0)
194 return ret;
195
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);
199 if (ret < 0)
200 return ret;
201
202 return 0;
203}
204
205static struct snd_soc_dai_driver voice_dai = {
206 .name = "goni-voice-dai",
207 .id = 0,
208 .playback = {
209 .channels_min = 1,
210 .channels_max = 2,
211 .rates = SNDRV_PCM_RATE_8000,
212 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
213 .capture = {
214 .channels_min = 1,
215 .channels_max = 2,
216 .rates = SNDRV_PCM_RATE_8000,
217 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
218};
219
220static struct snd_soc_ops goni_voice_ops = {
221 .hw_params = goni_voice_hw_params,
222};
223
224static struct snd_soc_dai_link goni_dai[] = {
225{
226 .name = "WM8994",
227 .stream_name = "WM8994 HiFi",
Jassi Brarfcd8c742010-11-22 15:37:04 +0900228 .cpu_dai_name = "samsung-i2s.0",
Mark Brown69b91bc2011-04-27 18:24:35 +0100229 .codec_dai_name = "wm8994-aif1",
Jassi Brar58bb4072010-11-22 15:35:50 +0900230 .platform_name = "samsung-audio",
Mark Brown1270b012011-04-27 18:19:17 +0100231 .codec_name = "wm8994-codec.0-001a",
Chanwoo Choif51582f2010-07-22 15:16:10 +0900232 .init = goni_wm8994_init,
233 .ops = &goni_hifi_ops,
234}, {
235 .name = "WM8994 Voice",
236 .stream_name = "Voice",
237 .cpu_dai_name = "goni-voice-dai",
Mark Brown69b91bc2011-04-27 18:24:35 +0100238 .codec_dai_name = "wm8994-aif2",
Mark Brown1270b012011-04-27 18:19:17 +0100239 .codec_name = "wm8994-codec.0-001a",
Chanwoo Choif51582f2010-07-22 15:16:10 +0900240 .ops = &goni_voice_ops,
241},
242};
243
244static struct snd_soc_card goni = {
245 .name = "goni",
246 .dai_link = goni_dai,
247 .num_links = ARRAY_SIZE(goni_dai),
Mark Brown35f06782011-10-08 12:02:13 +0100248
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),
Chanwoo Choif51582f2010-07-22 15:16:10 +0900253};
254
255static int __init goni_init(void)
256{
257 int ret;
258
Jassi Brar3a56d0c2010-11-22 15:35:36 +0900259 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())
Chanwoo Choif51582f2010-07-22 15:16:10 +0900264 return -ENODEV;
265
266 goni_snd_device = platform_device_alloc("soc-audio", -1);
267 if (!goni_snd_device)
268 return -ENOMEM;
269
270 /* register voice DAI here */
271 ret = snd_soc_register_dai(&goni_snd_device->dev, &voice_dai);
Axel Lin853dc302010-11-26 14:51:56 +0800272 if (ret) {
273 platform_device_put(goni_snd_device);
Chanwoo Choif51582f2010-07-22 15:16:10 +0900274 return ret;
Axel Lin853dc302010-11-26 14:51:56 +0800275 }
Chanwoo Choif51582f2010-07-22 15:16:10 +0900276
277 platform_set_drvdata(goni_snd_device, &goni);
278 ret = platform_device_add(goni_snd_device);
279
Axel Lin853dc302010-11-26 14:51:56 +0800280 if (ret) {
281 snd_soc_unregister_dai(&goni_snd_device->dev);
Chanwoo Choif51582f2010-07-22 15:16:10 +0900282 platform_device_put(goni_snd_device);
Axel Lin853dc302010-11-26 14:51:56 +0800283 }
Chanwoo Choif51582f2010-07-22 15:16:10 +0900284
285 return ret;
286}
287
288static void __exit goni_exit(void)
289{
Axel Lin853dc302010-11-26 14:51:56 +0800290 snd_soc_unregister_dai(&goni_snd_device->dev);
Chanwoo Choif51582f2010-07-22 15:16:10 +0900291 platform_device_unregister(goni_snd_device);
292}
293
294module_init(goni_init);
295module_exit(goni_exit);
296
297/* Module information */
298MODULE_DESCRIPTION("ALSA SoC WM8994 GONI(S5PV210)");
299MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
300MODULE_LICENSE("GPL");