1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright (c) 2009 Samsung Electronics Co. Ltd
4 // Author: Jaswinder Singh <jassisinghbrar@gmail.com>
6 #include <linux/module.h>
8 #include <sound/pcm_params.h>
10 #include "../codecs/wm8580.h"
14 * Default CFG switch settings to use this driver:
16 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
19 /* SMDK has a 12MHZ crystal attached to WM8580 */
20 #define SMDK_WM8580_FREQ 12000000
22 static int smdk_hw_params(struct snd_pcm_substream *substream,
23 struct snd_pcm_hw_params *params)
25 struct snd_soc_pcm_runtime *rtd = substream->private_data;
26 struct snd_soc_dai *codec_dai = rtd->codec_dai;
30 switch (params_width(params)) {
38 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
39 * This criterion can't be met if we request PLL output
40 * as {8000x256, 64000x256, 11025x256}Hz.
41 * As a wayout, we rather change rfs to a minimum value that
42 * results in (params_rate(params) * rfs), and itself, acceptable
43 * to both - the CODEC and the CPU.
45 switch (params_rate(params)) {
65 pll_out = params_rate(params) * rfs;
67 /* Set WM8580 to drive MCLK from its PLLA */
68 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
73 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
74 SMDK_WM8580_FREQ, pll_out);
78 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
79 pll_out, SND_SOC_CLOCK_IN);
87 * SMDK WM8580 DAI operations.
89 static struct snd_soc_ops smdk_ops = {
90 .hw_params = smdk_hw_params,
93 /* SMDK Playback widgets */
94 static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
95 SND_SOC_DAPM_HP("Front", NULL),
96 SND_SOC_DAPM_HP("Center+Sub", NULL),
97 SND_SOC_DAPM_HP("Rear", NULL),
99 SND_SOC_DAPM_MIC("MicIn", NULL),
100 SND_SOC_DAPM_LINE("LineIn", NULL),
103 /* SMDK-PAIFTX connections */
104 static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
105 /* MicIn feeds AINL */
106 {"AINL", NULL, "MicIn"},
108 /* LineIn feeds AINL/R */
109 {"AINL", NULL, "LineIn"},
110 {"AINR", NULL, "LineIn"},
112 /* Front Left/Right are fed VOUT1L/R */
113 {"Front", NULL, "VOUT1L"},
114 {"Front", NULL, "VOUT1R"},
116 /* Center/Sub are fed VOUT2L/R */
117 {"Center+Sub", NULL, "VOUT2L"},
118 {"Center+Sub", NULL, "VOUT2R"},
120 /* Rear Left/Right are fed VOUT3L/R */
121 {"Rear", NULL, "VOUT3L"},
122 {"Rear", NULL, "VOUT3R"},
125 static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
127 /* Enabling the microphone requires the fitting of a 0R
128 * resistor to connect the line from the microphone jack.
130 snd_soc_dapm_disable_pin(&rtd->card->dapm, "MicIn");
140 #define SMDK_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
141 SND_SOC_DAIFMT_CBM_CFM)
143 static struct snd_soc_dai_link smdk_dai[] = {
144 [PRI_PLAYBACK] = { /* Primary Playback i/f */
145 .name = "WM8580 PAIF RX",
146 .stream_name = "Playback",
147 .cpu_dai_name = "samsung-i2s.2",
148 .codec_dai_name = "wm8580-hifi-playback",
149 .platform_name = "samsung-i2s.0",
150 .codec_name = "wm8580.0-001b",
151 .dai_fmt = SMDK_DAI_FMT,
154 [PRI_CAPTURE] = { /* Primary Capture i/f */
155 .name = "WM8580 PAIF TX",
156 .stream_name = "Capture",
157 .cpu_dai_name = "samsung-i2s.2",
158 .codec_dai_name = "wm8580-hifi-capture",
159 .platform_name = "samsung-i2s.0",
160 .codec_name = "wm8580.0-001b",
161 .dai_fmt = SMDK_DAI_FMT,
162 .init = smdk_wm8580_init_paiftx,
167 static struct snd_soc_card smdk = {
169 .owner = THIS_MODULE,
170 .dai_link = smdk_dai,
171 .num_links = ARRAY_SIZE(smdk_dai),
173 .dapm_widgets = smdk_wm8580_dapm_widgets,
174 .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
175 .dapm_routes = smdk_wm8580_audio_map,
176 .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
179 static struct platform_device *smdk_snd_device;
181 static int __init smdk_audio_init(void)
185 smdk_snd_device = platform_device_alloc("soc-audio", -1);
186 if (!smdk_snd_device)
189 platform_set_drvdata(smdk_snd_device, &smdk);
190 ret = platform_device_add(smdk_snd_device);
193 platform_device_put(smdk_snd_device);
197 module_init(smdk_audio_init);
199 static void __exit smdk_audio_exit(void)
201 platform_device_unregister(smdk_snd_device);
203 module_exit(smdk_audio_exit);
205 MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
206 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
207 MODULE_LICENSE("GPL");