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 SND_SOC_DAILINK_DEFS(paif_rx
,
144 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.2")),
145 DAILINK_COMP_ARRAY(COMP_CODEC("wm8580.0-001b", "wm8580-hifi-playback")),
146 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
148 SND_SOC_DAILINK_DEFS(paif_tx
,
149 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.2")),
150 DAILINK_COMP_ARRAY(COMP_CODEC("wm8580.0-001b", "wm8580-hifi-capture")),
151 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
153 static struct snd_soc_dai_link smdk_dai
[] = {
154 [PRI_PLAYBACK
] = { /* Primary Playback i/f */
155 .name
= "WM8580 PAIF RX",
156 .stream_name
= "Playback",
157 .dai_fmt
= SMDK_DAI_FMT
,
159 SND_SOC_DAILINK_REG(paif_rx
),
161 [PRI_CAPTURE
] = { /* Primary Capture i/f */
162 .name
= "WM8580 PAIF TX",
163 .stream_name
= "Capture",
164 .dai_fmt
= SMDK_DAI_FMT
,
165 .init
= smdk_wm8580_init_paiftx
,
167 SND_SOC_DAILINK_REG(paif_tx
),
171 static struct snd_soc_card smdk
= {
173 .owner
= THIS_MODULE
,
174 .dai_link
= smdk_dai
,
175 .num_links
= ARRAY_SIZE(smdk_dai
),
177 .dapm_widgets
= smdk_wm8580_dapm_widgets
,
178 .num_dapm_widgets
= ARRAY_SIZE(smdk_wm8580_dapm_widgets
),
179 .dapm_routes
= smdk_wm8580_audio_map
,
180 .num_dapm_routes
= ARRAY_SIZE(smdk_wm8580_audio_map
),
183 static struct platform_device
*smdk_snd_device
;
185 static int __init
smdk_audio_init(void)
189 smdk_snd_device
= platform_device_alloc("soc-audio", -1);
190 if (!smdk_snd_device
)
193 platform_set_drvdata(smdk_snd_device
, &smdk
);
194 ret
= platform_device_add(smdk_snd_device
);
197 platform_device_put(smdk_snd_device
);
201 module_init(smdk_audio_init
);
203 static void __exit
smdk_audio_exit(void)
205 platform_device_unregister(smdk_snd_device
);
207 module_exit(smdk_audio_exit
);
209 MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
210 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
211 MODULE_LICENSE("GPL");