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
*codec_dai
= rtd
->codec_dai
;
39 switch (params_width(params
)) {
50 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
51 * This criterion can't be met if we request PLL output
52 * as {8000x256, 64000x256, 11025x256}Hz.
53 * As a wayout, we rather change rfs to a minimum value that
54 * results in (params_rate(params) * rfs), and itself, acceptable
55 * to both - the CODEC and the CPU.
57 switch (params_rate(params
)) {
77 pll_out
= params_rate(params
) * rfs
;
79 /* Set WM8580 to drive MCLK from its PLLA */
80 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8580_MCLK
,
85 ret
= snd_soc_dai_set_pll(codec_dai
, WM8580_PLLA
, 0,
86 SMDK_WM8580_FREQ
, pll_out
);
90 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8580_CLKSRC_PLLA
,
91 pll_out
, SND_SOC_CLOCK_IN
);
99 * SMDK WM8580 DAI operations.
101 static struct snd_soc_ops smdk_ops
= {
102 .hw_params
= smdk_hw_params
,
105 /* SMDK Playback widgets */
106 static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets
[] = {
107 SND_SOC_DAPM_HP("Front", NULL
),
108 SND_SOC_DAPM_HP("Center+Sub", NULL
),
109 SND_SOC_DAPM_HP("Rear", NULL
),
111 SND_SOC_DAPM_MIC("MicIn", NULL
),
112 SND_SOC_DAPM_LINE("LineIn", NULL
),
115 /* SMDK-PAIFTX connections */
116 static const struct snd_soc_dapm_route smdk_wm8580_audio_map
[] = {
117 /* MicIn feeds AINL */
118 {"AINL", NULL
, "MicIn"},
120 /* LineIn feeds AINL/R */
121 {"AINL", NULL
, "LineIn"},
122 {"AINR", NULL
, "LineIn"},
124 /* Front Left/Right are fed VOUT1L/R */
125 {"Front", NULL
, "VOUT1L"},
126 {"Front", NULL
, "VOUT1R"},
128 /* Center/Sub are fed VOUT2L/R */
129 {"Center+Sub", NULL
, "VOUT2L"},
130 {"Center+Sub", NULL
, "VOUT2R"},
132 /* Rear Left/Right are fed VOUT3L/R */
133 {"Rear", NULL
, "VOUT3L"},
134 {"Rear", NULL
, "VOUT3R"},
137 static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime
*rtd
)
139 /* Enabling the microphone requires the fitting of a 0R
140 * resistor to connect the line from the microphone jack.
142 snd_soc_dapm_disable_pin(&rtd
->card
->dapm
, "MicIn");
153 #define SMDK_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
154 SND_SOC_DAIFMT_CBM_CFM)
156 static struct snd_soc_dai_link smdk_dai
[] = {
157 [PRI_PLAYBACK
] = { /* Primary Playback i/f */
158 .name
= "WM8580 PAIF RX",
159 .stream_name
= "Playback",
160 .cpu_dai_name
= "samsung-i2s.0",
161 .codec_dai_name
= "wm8580-hifi-playback",
162 .platform_name
= "samsung-i2s.0",
163 .codec_name
= "wm8580.0-001b",
164 .dai_fmt
= SMDK_DAI_FMT
,
167 [PRI_CAPTURE
] = { /* Primary Capture i/f */
168 .name
= "WM8580 PAIF TX",
169 .stream_name
= "Capture",
170 .cpu_dai_name
= "samsung-i2s.0",
171 .codec_dai_name
= "wm8580-hifi-capture",
172 .platform_name
= "samsung-i2s.0",
173 .codec_name
= "wm8580.0-001b",
174 .dai_fmt
= SMDK_DAI_FMT
,
175 .init
= smdk_wm8580_init_paiftx
,
178 [SEC_PLAYBACK
] = { /* Sec_Fifo Playback i/f */
179 .name
= "Sec_FIFO TX",
180 .stream_name
= "Playback",
181 .cpu_dai_name
= "samsung-i2s-sec",
182 .codec_dai_name
= "wm8580-hifi-playback",
183 .platform_name
= "samsung-i2s-sec",
184 .codec_name
= "wm8580.0-001b",
185 .dai_fmt
= SMDK_DAI_FMT
,
190 static struct snd_soc_card smdk
= {
192 .owner
= THIS_MODULE
,
193 .dai_link
= smdk_dai
,
196 .dapm_widgets
= smdk_wm8580_dapm_widgets
,
197 .num_dapm_widgets
= ARRAY_SIZE(smdk_wm8580_dapm_widgets
),
198 .dapm_routes
= smdk_wm8580_audio_map
,
199 .num_dapm_routes
= ARRAY_SIZE(smdk_wm8580_audio_map
),
202 static struct platform_device
*smdk_snd_device
;
204 static int __init
smdk_audio_init(void)
209 if (machine_is_smdkc100()
210 || machine_is_smdkv210() || machine_is_smdkc110()) {
212 } else if (machine_is_smdk6410()) {
213 str
= (char *)smdk_dai
[PRI_PLAYBACK
].cpu_dai_name
;
214 str
[strlen(str
) - 1] = '2';
215 str
= (char *)smdk_dai
[PRI_CAPTURE
].cpu_dai_name
;
216 str
[strlen(str
) - 1] = '2';
219 smdk_snd_device
= platform_device_alloc("soc-audio", -1);
220 if (!smdk_snd_device
)
223 platform_set_drvdata(smdk_snd_device
, &smdk
);
224 ret
= platform_device_add(smdk_snd_device
);
227 platform_device_put(smdk_snd_device
);
231 module_init(smdk_audio_init
);
233 static void __exit
smdk_audio_exit(void)
235 platform_device_unregister(smdk_snd_device
);
237 module_exit(smdk_audio_exit
);
239 MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
240 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
241 MODULE_LICENSE("GPL");