4 * Copyright (c) 2009 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassi.brar@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.
13 #include <linux/platform_device.h>
14 #include <linux/clk.h>
15 #include <sound/core.h>
16 #include <sound/pcm.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
20 #include <asm/mach-types.h>
22 #include "../codecs/wm8580.h"
27 * Default CFG switch settings to use this driver:
29 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
32 /* SMDK has a 12MHZ crystal attached to WM8580 */
33 #define SMDK_WM8580_FREQ 12000000
35 static int smdk_hw_params(struct snd_pcm_substream
*substream
,
36 struct snd_pcm_hw_params
*params
)
38 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
39 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
40 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
44 switch (params_format(params
)) {
45 case SNDRV_PCM_FORMAT_U8
:
46 case SNDRV_PCM_FORMAT_S8
:
49 case SNDRV_PCM_FORMAT_U16_LE
:
50 case SNDRV_PCM_FORMAT_S16_LE
:
57 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
58 * This criterion can't be met if we request PLL output
59 * as {8000x256, 64000x256, 11025x256}Hz.
60 * As a wayout, we rather change rfs to a minimum value that
61 * results in (params_rate(params) * rfs), and itself, acceptable
62 * to both - the CODEC and the CPU.
64 switch (params_rate(params
)) {
84 pll_out
= params_rate(params
) * rfs
;
86 /* Set the Codec DAI configuration */
87 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
88 | SND_SOC_DAIFMT_NB_NF
89 | SND_SOC_DAIFMT_CBM_CFM
);
93 /* Set the AP DAI configuration */
94 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
95 | SND_SOC_DAIFMT_NB_NF
96 | SND_SOC_DAIFMT_CBM_CFM
);
100 /* Set WM8580 to drive MCLK from its PLLA */
101 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8580_MCLK
,
106 ret
= snd_soc_dai_set_pll(codec_dai
, WM8580_PLLA
, 0,
107 SMDK_WM8580_FREQ
, pll_out
);
111 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8580_CLKSRC_PLLA
,
112 pll_out
, SND_SOC_CLOCK_IN
);
120 * SMDK WM8580 DAI operations.
122 static struct snd_soc_ops smdk_ops
= {
123 .hw_params
= smdk_hw_params
,
126 /* SMDK Playback widgets */
127 static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk
[] = {
128 SND_SOC_DAPM_HP("Front", NULL
),
129 SND_SOC_DAPM_HP("Center+Sub", NULL
),
130 SND_SOC_DAPM_HP("Rear", NULL
),
133 /* SMDK Capture widgets */
134 static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt
[] = {
135 SND_SOC_DAPM_MIC("MicIn", NULL
),
136 SND_SOC_DAPM_LINE("LineIn", NULL
),
139 /* SMDK-PAIFTX connections */
140 static const struct snd_soc_dapm_route audio_map_tx
[] = {
141 /* MicIn feeds AINL */
142 {"AINL", NULL
, "MicIn"},
144 /* LineIn feeds AINL/R */
145 {"AINL", NULL
, "LineIn"},
146 {"AINR", NULL
, "LineIn"},
149 /* SMDK-PAIFRX connections */
150 static const struct snd_soc_dapm_route audio_map_rx
[] = {
151 /* Front Left/Right are fed VOUT1L/R */
152 {"Front", NULL
, "VOUT1L"},
153 {"Front", NULL
, "VOUT1R"},
155 /* Center/Sub are fed VOUT2L/R */
156 {"Center+Sub", NULL
, "VOUT2L"},
157 {"Center+Sub", NULL
, "VOUT2R"},
159 /* Rear Left/Right are fed VOUT3L/R */
160 {"Rear", NULL
, "VOUT3L"},
161 {"Rear", NULL
, "VOUT3R"},
164 static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime
*rtd
)
166 struct snd_soc_codec
*codec
= rtd
->codec
;
167 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
169 /* Add smdk specific Capture widgets */
170 snd_soc_dapm_new_controls(dapm
, wm8580_dapm_widgets_cpt
,
171 ARRAY_SIZE(wm8580_dapm_widgets_cpt
));
173 /* Set up PAIFTX audio path */
174 snd_soc_dapm_add_routes(dapm
, audio_map_tx
, ARRAY_SIZE(audio_map_tx
));
176 /* Enabling the microphone requires the fitting of a 0R
177 * resistor to connect the line from the microphone jack.
179 snd_soc_dapm_disable_pin(dapm
, "MicIn");
181 /* signal a DAPM event */
182 snd_soc_dapm_sync(dapm
);
187 static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime
*rtd
)
189 struct snd_soc_codec
*codec
= rtd
->codec
;
190 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
192 /* Add smdk specific Playback widgets */
193 snd_soc_dapm_new_controls(dapm
, wm8580_dapm_widgets_pbk
,
194 ARRAY_SIZE(wm8580_dapm_widgets_pbk
));
196 /* Set up PAIFRX audio path */
197 snd_soc_dapm_add_routes(dapm
, audio_map_rx
, ARRAY_SIZE(audio_map_rx
));
199 /* signal a DAPM event */
200 snd_soc_dapm_sync(dapm
);
211 static struct snd_soc_dai_link smdk_dai
[] = {
212 [PRI_PLAYBACK
] = { /* Primary Playback i/f */
213 .name
= "WM8580 PAIF RX",
214 .stream_name
= "Playback",
215 .cpu_dai_name
= "samsung-i2s.0",
216 .codec_dai_name
= "wm8580-hifi-playback",
217 .platform_name
= "samsung-audio",
218 .codec_name
= "wm8580-codec.0-001b",
219 .init
= smdk_wm8580_init_paifrx
,
222 [PRI_CAPTURE
] = { /* Primary Capture i/f */
223 .name
= "WM8580 PAIF TX",
224 .stream_name
= "Capture",
225 .cpu_dai_name
= "samsung-i2s.0",
226 .codec_dai_name
= "wm8580-hifi-capture",
227 .platform_name
= "samsung-audio",
228 .codec_name
= "wm8580-codec.0-001b",
229 .init
= smdk_wm8580_init_paiftx
,
232 [SEC_PLAYBACK
] = { /* Sec_Fifo Playback i/f */
233 .name
= "Sec_FIFO TX",
234 .stream_name
= "Playback",
235 .cpu_dai_name
= "samsung-i2s.x",
236 .codec_dai_name
= "wm8580-hifi-playback",
237 .platform_name
= "samsung-audio",
238 .codec_name
= "wm8580-codec.0-001b",
239 .init
= smdk_wm8580_init_paifrx
,
244 static struct snd_soc_card smdk
= {
246 .dai_link
= smdk_dai
,
250 static struct platform_device
*smdk_snd_device
;
252 static int __init
smdk_audio_init(void)
257 if (machine_is_smdkc100() || machine_is_smdk6442()
258 || machine_is_smdkv210() || machine_is_smdkc110()) {
260 /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
261 str
= (char *)smdk_dai
[SEC_PLAYBACK
].cpu_dai_name
;
262 str
[strlen(str
) - 1] = '0' + SAMSUNG_I2S_SECOFF
;
263 } else if (machine_is_smdk6410()) {
264 str
= (char *)smdk_dai
[PRI_PLAYBACK
].cpu_dai_name
;
265 str
[strlen(str
) - 1] = '2';
266 str
= (char *)smdk_dai
[PRI_CAPTURE
].cpu_dai_name
;
267 str
[strlen(str
) - 1] = '2';
270 smdk_snd_device
= platform_device_alloc("soc-audio", -1);
271 if (!smdk_snd_device
)
274 platform_set_drvdata(smdk_snd_device
, &smdk
);
275 ret
= platform_device_add(smdk_snd_device
);
278 platform_device_put(smdk_snd_device
);
282 module_init(smdk_audio_init
);
284 static void __exit
smdk_audio_exit(void)
286 platform_device_unregister(smdk_snd_device
);
288 module_exit(smdk_audio_exit
);
290 MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
291 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
292 MODULE_LICENSE("GPL");