4 * Copyright (c) 2009 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassisinghbrar@gmail.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/module.h>
14 #include <sound/soc.h>
15 #include <sound/pcm_params.h>
17 #include <asm/mach-types.h>
19 #include "../codecs/wm8580.h"
23 * Default CFG switch settings to use this driver:
25 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
28 /* SMDK has a 12MHZ crystal attached to WM8580 */
29 #define SMDK_WM8580_FREQ 12000000
31 static int smdk_hw_params(struct snd_pcm_substream
*substream
,
32 struct snd_pcm_hw_params
*params
)
34 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
35 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
36 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
40 switch (params_format(params
)) {
41 case SNDRV_PCM_FORMAT_U8
:
42 case SNDRV_PCM_FORMAT_S8
:
45 case SNDRV_PCM_FORMAT_U16_LE
:
46 case SNDRV_PCM_FORMAT_S16_LE
:
53 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
54 * This criterion can't be met if we request PLL output
55 * as {8000x256, 64000x256, 11025x256}Hz.
56 * As a wayout, we rather change rfs to a minimum value that
57 * results in (params_rate(params) * rfs), and itself, acceptable
58 * to both - the CODEC and the CPU.
60 switch (params_rate(params
)) {
80 pll_out
= params_rate(params
) * rfs
;
82 /* Set the Codec DAI configuration */
83 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
84 | SND_SOC_DAIFMT_NB_NF
85 | SND_SOC_DAIFMT_CBM_CFM
);
89 /* Set the AP DAI configuration */
90 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
91 | SND_SOC_DAIFMT_NB_NF
92 | SND_SOC_DAIFMT_CBM_CFM
);
96 /* Set WM8580 to drive MCLK from its PLLA */
97 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8580_MCLK
,
102 ret
= snd_soc_dai_set_pll(codec_dai
, WM8580_PLLA
, 0,
103 SMDK_WM8580_FREQ
, pll_out
);
107 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8580_CLKSRC_PLLA
,
108 pll_out
, SND_SOC_CLOCK_IN
);
116 * SMDK WM8580 DAI operations.
118 static struct snd_soc_ops smdk_ops
= {
119 .hw_params
= smdk_hw_params
,
122 /* SMDK Playback widgets */
123 static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets
[] = {
124 SND_SOC_DAPM_HP("Front", NULL
),
125 SND_SOC_DAPM_HP("Center+Sub", NULL
),
126 SND_SOC_DAPM_HP("Rear", NULL
),
128 SND_SOC_DAPM_MIC("MicIn", NULL
),
129 SND_SOC_DAPM_LINE("LineIn", NULL
),
132 /* SMDK-PAIFTX connections */
133 static const struct snd_soc_dapm_route smdk_wm8580_audio_map
[] = {
134 /* MicIn feeds AINL */
135 {"AINL", NULL
, "MicIn"},
137 /* LineIn feeds AINL/R */
138 {"AINL", NULL
, "LineIn"},
139 {"AINR", NULL
, "LineIn"},
141 /* Front Left/Right are fed VOUT1L/R */
142 {"Front", NULL
, "VOUT1L"},
143 {"Front", NULL
, "VOUT1R"},
145 /* Center/Sub are fed VOUT2L/R */
146 {"Center+Sub", NULL
, "VOUT2L"},
147 {"Center+Sub", NULL
, "VOUT2R"},
149 /* Rear Left/Right are fed VOUT3L/R */
150 {"Rear", NULL
, "VOUT3L"},
151 {"Rear", NULL
, "VOUT3R"},
154 static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime
*rtd
)
156 struct snd_soc_codec
*codec
= rtd
->codec
;
157 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
159 /* Enabling the microphone requires the fitting of a 0R
160 * resistor to connect the line from the microphone jack.
162 snd_soc_dapm_disable_pin(dapm
, "MicIn");
173 static struct snd_soc_dai_link smdk_dai
[] = {
174 [PRI_PLAYBACK
] = { /* Primary Playback i/f */
175 .name
= "WM8580 PAIF RX",
176 .stream_name
= "Playback",
177 .cpu_dai_name
= "samsung-i2s.0",
178 .codec_dai_name
= "wm8580-hifi-playback",
179 .platform_name
= "samsung-i2s.0",
180 .codec_name
= "wm8580.0-001b",
183 [PRI_CAPTURE
] = { /* Primary Capture i/f */
184 .name
= "WM8580 PAIF TX",
185 .stream_name
= "Capture",
186 .cpu_dai_name
= "samsung-i2s.0",
187 .codec_dai_name
= "wm8580-hifi-capture",
188 .platform_name
= "samsung-i2s.0",
189 .codec_name
= "wm8580.0-001b",
190 .init
= smdk_wm8580_init_paiftx
,
193 [SEC_PLAYBACK
] = { /* Sec_Fifo Playback i/f */
194 .name
= "Sec_FIFO TX",
195 .stream_name
= "Playback",
196 .cpu_dai_name
= "samsung-i2s.x",
197 .codec_dai_name
= "wm8580-hifi-playback",
198 .platform_name
= "samsung-i2s.x",
199 .codec_name
= "wm8580.0-001b",
204 static struct snd_soc_card smdk
= {
206 .owner
= THIS_MODULE
,
207 .dai_link
= smdk_dai
,
210 .dapm_widgets
= smdk_wm8580_dapm_widgets
,
211 .num_dapm_widgets
= ARRAY_SIZE(smdk_wm8580_dapm_widgets
),
212 .dapm_routes
= smdk_wm8580_audio_map
,
213 .num_dapm_routes
= ARRAY_SIZE(smdk_wm8580_audio_map
),
216 static struct platform_device
*smdk_snd_device
;
218 static int __init
smdk_audio_init(void)
223 if (machine_is_smdkc100()
224 || machine_is_smdkv210() || machine_is_smdkc110()) {
226 /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
227 str
= (char *)smdk_dai
[SEC_PLAYBACK
].cpu_dai_name
;
228 str
[strlen(str
) - 1] = '0' + SAMSUNG_I2S_SECOFF
;
229 } else if (machine_is_smdk6410()) {
230 str
= (char *)smdk_dai
[PRI_PLAYBACK
].cpu_dai_name
;
231 str
[strlen(str
) - 1] = '2';
232 str
= (char *)smdk_dai
[PRI_CAPTURE
].cpu_dai_name
;
233 str
[strlen(str
) - 1] = '2';
236 smdk_snd_device
= platform_device_alloc("soc-audio", -1);
237 if (!smdk_snd_device
)
240 platform_set_drvdata(smdk_snd_device
, &smdk
);
241 ret
= platform_device_add(smdk_snd_device
);
244 platform_device_put(smdk_snd_device
);
248 module_init(smdk_audio_init
);
250 static void __exit
smdk_audio_exit(void)
252 platform_device_unregister(smdk_snd_device
);
254 module_exit(smdk_audio_exit
);
256 MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
257 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
258 MODULE_LICENSE("GPL");