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>
19 #include <sound/soc-dapm.h>
21 #include "../codecs/wm8580.h"
23 #include "s3c64xx-i2s.h"
26 * Default CFG switch settings to use this driver:
28 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
31 /* SMDK64XX has a 12MHZ crystal attached to WM8580 */
32 #define SMDK64XX_WM8580_FREQ 12000000
34 static int smdk64xx_hw_params(struct snd_pcm_substream
*substream
,
35 struct snd_pcm_hw_params
*params
)
37 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
38 struct snd_soc_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
39 struct snd_soc_dai
*codec_dai
= rtd
->dai
->codec_dai
;
43 switch (params_format(params
)) {
44 case SNDRV_PCM_FORMAT_U8
:
45 case SNDRV_PCM_FORMAT_S8
:
48 case SNDRV_PCM_FORMAT_U16_LE
:
49 case SNDRV_PCM_FORMAT_S16_LE
:
56 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
57 * This criterion can't be met if we request PLL output
58 * as {8000x256, 64000x256, 11025x256}Hz.
59 * As a wayout, we rather change rfs to a minimum value that
60 * results in (params_rate(params) * rfs), and itself, acceptable
61 * to both - the CODEC and the CPU.
63 switch (params_rate(params
)) {
83 pll_out
= params_rate(params
) * rfs
;
85 /* Set the Codec DAI configuration */
86 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
87 | SND_SOC_DAIFMT_NB_NF
88 | SND_SOC_DAIFMT_CBM_CFM
);
92 /* Set the AP DAI configuration */
93 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
94 | SND_SOC_DAIFMT_NB_NF
95 | SND_SOC_DAIFMT_CBM_CFM
);
99 ret
= snd_soc_dai_set_sysclk(cpu_dai
, S3C64XX_CLKSRC_CDCLK
,
100 0, SND_SOC_CLOCK_IN
);
104 /* We use PCLK for basic ops in SoC-Slave mode */
105 ret
= snd_soc_dai_set_sysclk(cpu_dai
, S3C64XX_CLKSRC_PCLK
,
106 0, SND_SOC_CLOCK_IN
);
110 /* Set WM8580 to drive MCLK from its PLLA */
111 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8580_MCLK
,
116 /* Explicitly set WM8580-DAC to source from MCLK */
117 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8580_DAC_CLKSEL
,
122 ret
= snd_soc_dai_set_pll(codec_dai
, WM8580_PLLA
, 0,
123 SMDK64XX_WM8580_FREQ
, pll_out
);
127 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C_I2SV2_DIV_BCLK
, bfs
);
131 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C_I2SV2_DIV_RCLK
, rfs
);
139 * SMDK64XX WM8580 DAI operations.
141 static struct snd_soc_ops smdk64xx_ops
= {
142 .hw_params
= smdk64xx_hw_params
,
145 /* SMDK64xx Playback widgets */
146 static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk
[] = {
147 SND_SOC_DAPM_HP("Front", NULL
),
148 SND_SOC_DAPM_HP("Center+Sub", NULL
),
149 SND_SOC_DAPM_HP("Rear", NULL
),
152 /* SMDK64xx Capture widgets */
153 static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt
[] = {
154 SND_SOC_DAPM_MIC("MicIn", NULL
),
155 SND_SOC_DAPM_LINE("LineIn", NULL
),
158 /* SMDK-PAIFTX connections */
159 static const struct snd_soc_dapm_route audio_map_tx
[] = {
160 /* MicIn feeds AINL */
161 {"AINL", NULL
, "MicIn"},
163 /* LineIn feeds AINL/R */
164 {"AINL", NULL
, "LineIn"},
165 {"AINR", NULL
, "LineIn"},
168 /* SMDK-PAIFRX connections */
169 static const struct snd_soc_dapm_route audio_map_rx
[] = {
170 /* Front Left/Right are fed VOUT1L/R */
171 {"Front", NULL
, "VOUT1L"},
172 {"Front", NULL
, "VOUT1R"},
174 /* Center/Sub are fed VOUT2L/R */
175 {"Center+Sub", NULL
, "VOUT2L"},
176 {"Center+Sub", NULL
, "VOUT2R"},
178 /* Rear Left/Right are fed VOUT3L/R */
179 {"Rear", NULL
, "VOUT3L"},
180 {"Rear", NULL
, "VOUT3R"},
183 static int smdk64xx_wm8580_init_paiftx(struct snd_soc_codec
*codec
)
185 /* Add smdk64xx specific Capture widgets */
186 snd_soc_dapm_new_controls(codec
, wm8580_dapm_widgets_cpt
,
187 ARRAY_SIZE(wm8580_dapm_widgets_cpt
));
189 /* Set up PAIFTX audio path */
190 snd_soc_dapm_add_routes(codec
, audio_map_tx
, ARRAY_SIZE(audio_map_tx
));
192 /* Enabling the microphone requires the fitting of a 0R
193 * resistor to connect the line from the microphone jack.
195 snd_soc_dapm_disable_pin(codec
, "MicIn");
197 /* signal a DAPM event */
198 snd_soc_dapm_sync(codec
);
203 static int smdk64xx_wm8580_init_paifrx(struct snd_soc_codec
*codec
)
205 /* Add smdk64xx specific Playback widgets */
206 snd_soc_dapm_new_controls(codec
, wm8580_dapm_widgets_pbk
,
207 ARRAY_SIZE(wm8580_dapm_widgets_pbk
));
209 /* Set up PAIFRX audio path */
210 snd_soc_dapm_add_routes(codec
, audio_map_rx
, ARRAY_SIZE(audio_map_rx
));
212 /* signal a DAPM event */
213 snd_soc_dapm_sync(codec
);
218 static struct snd_soc_dai_link smdk64xx_dai
[] = {
219 { /* Primary Playback i/f */
220 .name
= "WM8580 PAIF RX",
221 .stream_name
= "Playback",
222 .cpu_dai
= &s3c64xx_i2s_v4_dai
,
223 .codec_dai
= &wm8580_dai
[WM8580_DAI_PAIFRX
],
224 .init
= smdk64xx_wm8580_init_paifrx
,
225 .ops
= &smdk64xx_ops
,
227 { /* Primary Capture i/f */
228 .name
= "WM8580 PAIF TX",
229 .stream_name
= "Capture",
230 .cpu_dai
= &s3c64xx_i2s_v4_dai
,
231 .codec_dai
= &wm8580_dai
[WM8580_DAI_PAIFTX
],
232 .init
= smdk64xx_wm8580_init_paiftx
,
233 .ops
= &smdk64xx_ops
,
237 static struct snd_soc_card smdk64xx
= {
239 .platform
= &s3c24xx_soc_platform
,
240 .dai_link
= smdk64xx_dai
,
241 .num_links
= ARRAY_SIZE(smdk64xx_dai
),
244 static struct snd_soc_device smdk64xx_snd_devdata
= {
246 .codec_dev
= &soc_codec_dev_wm8580
,
249 static struct platform_device
*smdk64xx_snd_device
;
251 static int __init
smdk64xx_audio_init(void)
255 smdk64xx_snd_device
= platform_device_alloc("soc-audio", -1);
256 if (!smdk64xx_snd_device
)
259 platform_set_drvdata(smdk64xx_snd_device
, &smdk64xx_snd_devdata
);
260 smdk64xx_snd_devdata
.dev
= &smdk64xx_snd_device
->dev
;
261 ret
= platform_device_add(smdk64xx_snd_device
);
264 platform_device_put(smdk64xx_snd_device
);
268 module_init(smdk64xx_audio_init
);
270 MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
271 MODULE_DESCRIPTION("ALSA SoC SMDK64XX WM8580");
272 MODULE_LICENSE("GPL");