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 <sound/soc.h>
14 #include <sound/pcm_params.h>
16 #include <asm/mach-types.h>
18 #include "../codecs/wm8580.h"
22 * Default CFG switch settings to use this driver:
24 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
27 /* SMDK has a 12MHZ crystal attached to WM8580 */
28 #define SMDK_WM8580_FREQ 12000000
30 static int smdk_hw_params(struct snd_pcm_substream
*substream
,
31 struct snd_pcm_hw_params
*params
)
33 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
34 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
35 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
39 switch (params_format(params
)) {
40 case SNDRV_PCM_FORMAT_U8
:
41 case SNDRV_PCM_FORMAT_S8
:
44 case SNDRV_PCM_FORMAT_U16_LE
:
45 case SNDRV_PCM_FORMAT_S16_LE
:
52 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
53 * This criterion can't be met if we request PLL output
54 * as {8000x256, 64000x256, 11025x256}Hz.
55 * As a wayout, we rather change rfs to a minimum value that
56 * results in (params_rate(params) * rfs), and itself, acceptable
57 * to both - the CODEC and the CPU.
59 switch (params_rate(params
)) {
79 pll_out
= params_rate(params
) * rfs
;
81 /* Set the Codec DAI configuration */
82 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
83 | SND_SOC_DAIFMT_NB_NF
84 | SND_SOC_DAIFMT_CBM_CFM
);
88 /* Set the AP DAI configuration */
89 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
90 | SND_SOC_DAIFMT_NB_NF
91 | SND_SOC_DAIFMT_CBM_CFM
);
95 /* Set WM8580 to drive MCLK from its PLLA */
96 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8580_MCLK
,
101 ret
= snd_soc_dai_set_pll(codec_dai
, WM8580_PLLA
, 0,
102 SMDK_WM8580_FREQ
, pll_out
);
106 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8580_CLKSRC_PLLA
,
107 pll_out
, SND_SOC_CLOCK_IN
);
115 * SMDK WM8580 DAI operations.
117 static struct snd_soc_ops smdk_ops
= {
118 .hw_params
= smdk_hw_params
,
121 /* SMDK Playback widgets */
122 static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk
[] = {
123 SND_SOC_DAPM_HP("Front", NULL
),
124 SND_SOC_DAPM_HP("Center+Sub", NULL
),
125 SND_SOC_DAPM_HP("Rear", NULL
),
128 /* SMDK Capture widgets */
129 static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt
[] = {
130 SND_SOC_DAPM_MIC("MicIn", NULL
),
131 SND_SOC_DAPM_LINE("LineIn", NULL
),
134 /* SMDK-PAIFTX connections */
135 static const struct snd_soc_dapm_route audio_map_tx
[] = {
136 /* MicIn feeds AINL */
137 {"AINL", NULL
, "MicIn"},
139 /* LineIn feeds AINL/R */
140 {"AINL", NULL
, "LineIn"},
141 {"AINR", NULL
, "LineIn"},
144 /* SMDK-PAIFRX connections */
145 static const struct snd_soc_dapm_route audio_map_rx
[] = {
146 /* Front Left/Right are fed VOUT1L/R */
147 {"Front", NULL
, "VOUT1L"},
148 {"Front", NULL
, "VOUT1R"},
150 /* Center/Sub are fed VOUT2L/R */
151 {"Center+Sub", NULL
, "VOUT2L"},
152 {"Center+Sub", NULL
, "VOUT2R"},
154 /* Rear Left/Right are fed VOUT3L/R */
155 {"Rear", NULL
, "VOUT3L"},
156 {"Rear", NULL
, "VOUT3R"},
159 static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime
*rtd
)
161 struct snd_soc_codec
*codec
= rtd
->codec
;
162 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
164 /* Add smdk specific Capture widgets */
165 snd_soc_dapm_new_controls(dapm
, wm8580_dapm_widgets_cpt
,
166 ARRAY_SIZE(wm8580_dapm_widgets_cpt
));
168 /* Set up PAIFTX audio path */
169 snd_soc_dapm_add_routes(dapm
, audio_map_tx
, ARRAY_SIZE(audio_map_tx
));
171 /* Enabling the microphone requires the fitting of a 0R
172 * resistor to connect the line from the microphone jack.
174 snd_soc_dapm_disable_pin(dapm
, "MicIn");
176 /* signal a DAPM event */
177 snd_soc_dapm_sync(dapm
);
182 static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime
*rtd
)
184 struct snd_soc_codec
*codec
= rtd
->codec
;
185 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
187 /* Add smdk specific Playback widgets */
188 snd_soc_dapm_new_controls(dapm
, wm8580_dapm_widgets_pbk
,
189 ARRAY_SIZE(wm8580_dapm_widgets_pbk
));
191 /* Set up PAIFRX audio path */
192 snd_soc_dapm_add_routes(dapm
, audio_map_rx
, ARRAY_SIZE(audio_map_rx
));
194 /* signal a DAPM event */
195 snd_soc_dapm_sync(dapm
);
206 static struct snd_soc_dai_link smdk_dai
[] = {
207 [PRI_PLAYBACK
] = { /* Primary Playback i/f */
208 .name
= "WM8580 PAIF RX",
209 .stream_name
= "Playback",
210 .cpu_dai_name
= "samsung-i2s.0",
211 .codec_dai_name
= "wm8580-hifi-playback",
212 .platform_name
= "samsung-audio",
213 .codec_name
= "wm8580-codec.0-001b",
214 .init
= smdk_wm8580_init_paifrx
,
217 [PRI_CAPTURE
] = { /* Primary Capture i/f */
218 .name
= "WM8580 PAIF TX",
219 .stream_name
= "Capture",
220 .cpu_dai_name
= "samsung-i2s.0",
221 .codec_dai_name
= "wm8580-hifi-capture",
222 .platform_name
= "samsung-audio",
223 .codec_name
= "wm8580-codec.0-001b",
224 .init
= smdk_wm8580_init_paiftx
,
227 [SEC_PLAYBACK
] = { /* Sec_Fifo Playback i/f */
228 .name
= "Sec_FIFO TX",
229 .stream_name
= "Playback",
230 .cpu_dai_name
= "samsung-i2s.x",
231 .codec_dai_name
= "wm8580-hifi-playback",
232 .platform_name
= "samsung-audio",
233 .codec_name
= "wm8580-codec.0-001b",
234 .init
= smdk_wm8580_init_paifrx
,
239 static struct snd_soc_card smdk
= {
241 .dai_link
= smdk_dai
,
245 static struct platform_device
*smdk_snd_device
;
247 static int __init
smdk_audio_init(void)
252 if (machine_is_smdkc100()
253 || machine_is_smdkv210() || machine_is_smdkc110()) {
255 /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
256 str
= (char *)smdk_dai
[SEC_PLAYBACK
].cpu_dai_name
;
257 str
[strlen(str
) - 1] = '0' + SAMSUNG_I2S_SECOFF
;
258 } else if (machine_is_smdk6410()) {
259 str
= (char *)smdk_dai
[PRI_PLAYBACK
].cpu_dai_name
;
260 str
[strlen(str
) - 1] = '2';
261 str
= (char *)smdk_dai
[PRI_CAPTURE
].cpu_dai_name
;
262 str
[strlen(str
) - 1] = '2';
265 smdk_snd_device
= platform_device_alloc("soc-audio", -1);
266 if (!smdk_snd_device
)
269 platform_set_drvdata(smdk_snd_device
, &smdk
);
270 ret
= platform_device_add(smdk_snd_device
);
273 platform_device_put(smdk_snd_device
);
277 module_init(smdk_audio_init
);
279 static void __exit
smdk_audio_exit(void)
281 platform_device_unregister(smdk_snd_device
);
283 module_exit(smdk_audio_exit
);
285 MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
286 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
287 MODULE_LICENSE("GPL");