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_width(params
)) {
51 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
52 * This criterion can't be met if we request PLL output
53 * as {8000x256, 64000x256, 11025x256}Hz.
54 * As a wayout, we rather change rfs to a minimum value that
55 * results in (params_rate(params) * rfs), and itself, acceptable
56 * to both - the CODEC and the CPU.
58 switch (params_rate(params
)) {
78 pll_out
= params_rate(params
) * rfs
;
80 /* Set the Codec DAI configuration */
81 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
82 | SND_SOC_DAIFMT_NB_NF
83 | SND_SOC_DAIFMT_CBM_CFM
);
87 /* Set the AP DAI configuration */
88 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
89 | SND_SOC_DAIFMT_NB_NF
90 | SND_SOC_DAIFMT_CBM_CFM
);
94 /* Set WM8580 to drive MCLK from its PLLA */
95 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8580_MCLK
,
100 ret
= snd_soc_dai_set_pll(codec_dai
, WM8580_PLLA
, 0,
101 SMDK_WM8580_FREQ
, pll_out
);
105 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8580_CLKSRC_PLLA
,
106 pll_out
, SND_SOC_CLOCK_IN
);
114 * SMDK WM8580 DAI operations.
116 static struct snd_soc_ops smdk_ops
= {
117 .hw_params
= smdk_hw_params
,
120 /* SMDK Playback widgets */
121 static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets
[] = {
122 SND_SOC_DAPM_HP("Front", NULL
),
123 SND_SOC_DAPM_HP("Center+Sub", NULL
),
124 SND_SOC_DAPM_HP("Rear", NULL
),
126 SND_SOC_DAPM_MIC("MicIn", NULL
),
127 SND_SOC_DAPM_LINE("LineIn", NULL
),
130 /* SMDK-PAIFTX connections */
131 static const struct snd_soc_dapm_route smdk_wm8580_audio_map
[] = {
132 /* MicIn feeds AINL */
133 {"AINL", NULL
, "MicIn"},
135 /* LineIn feeds AINL/R */
136 {"AINL", NULL
, "LineIn"},
137 {"AINR", NULL
, "LineIn"},
139 /* Front Left/Right are fed VOUT1L/R */
140 {"Front", NULL
, "VOUT1L"},
141 {"Front", NULL
, "VOUT1R"},
143 /* Center/Sub are fed VOUT2L/R */
144 {"Center+Sub", NULL
, "VOUT2L"},
145 {"Center+Sub", NULL
, "VOUT2R"},
147 /* Rear Left/Right are fed VOUT3L/R */
148 {"Rear", NULL
, "VOUT3L"},
149 {"Rear", NULL
, "VOUT3R"},
152 static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime
*rtd
)
154 struct snd_soc_codec
*codec
= rtd
->codec
;
155 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
157 /* Enabling the microphone requires the fitting of a 0R
158 * resistor to connect the line from the microphone jack.
160 snd_soc_dapm_disable_pin(dapm
, "MicIn");
171 static struct snd_soc_dai_link smdk_dai
[] = {
172 [PRI_PLAYBACK
] = { /* Primary Playback i/f */
173 .name
= "WM8580 PAIF RX",
174 .stream_name
= "Playback",
175 .cpu_dai_name
= "samsung-i2s.0",
176 .codec_dai_name
= "wm8580-hifi-playback",
177 .platform_name
= "samsung-i2s.0",
178 .codec_name
= "wm8580.0-001b",
181 [PRI_CAPTURE
] = { /* Primary Capture i/f */
182 .name
= "WM8580 PAIF TX",
183 .stream_name
= "Capture",
184 .cpu_dai_name
= "samsung-i2s.0",
185 .codec_dai_name
= "wm8580-hifi-capture",
186 .platform_name
= "samsung-i2s.0",
187 .codec_name
= "wm8580.0-001b",
188 .init
= smdk_wm8580_init_paiftx
,
191 [SEC_PLAYBACK
] = { /* Sec_Fifo Playback i/f */
192 .name
= "Sec_FIFO TX",
193 .stream_name
= "Playback",
194 .cpu_dai_name
= "samsung-i2s-sec",
195 .codec_dai_name
= "wm8580-hifi-playback",
196 .platform_name
= "samsung-i2s-sec",
197 .codec_name
= "wm8580.0-001b",
202 static struct snd_soc_card smdk
= {
204 .owner
= THIS_MODULE
,
205 .dai_link
= smdk_dai
,
208 .dapm_widgets
= smdk_wm8580_dapm_widgets
,
209 .num_dapm_widgets
= ARRAY_SIZE(smdk_wm8580_dapm_widgets
),
210 .dapm_routes
= smdk_wm8580_audio_map
,
211 .num_dapm_routes
= ARRAY_SIZE(smdk_wm8580_audio_map
),
214 static struct platform_device
*smdk_snd_device
;
216 static int __init
smdk_audio_init(void)
221 if (machine_is_smdkc100()
222 || machine_is_smdkv210() || machine_is_smdkc110()) {
224 } else if (machine_is_smdk6410()) {
225 str
= (char *)smdk_dai
[PRI_PLAYBACK
].cpu_dai_name
;
226 str
[strlen(str
) - 1] = '2';
227 str
= (char *)smdk_dai
[PRI_CAPTURE
].cpu_dai_name
;
228 str
[strlen(str
) - 1] = '2';
231 smdk_snd_device
= platform_device_alloc("soc-audio", -1);
232 if (!smdk_snd_device
)
235 platform_set_drvdata(smdk_snd_device
, &smdk
);
236 ret
= platform_device_add(smdk_snd_device
);
239 platform_device_put(smdk_snd_device
);
243 module_init(smdk_audio_init
);
245 static void __exit
smdk_audio_exit(void)
247 platform_device_unregister(smdk_snd_device
);
249 module_exit(smdk_audio_exit
);
251 MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
252 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
253 MODULE_LICENSE("GPL");