1 // SPDX-License-Identifier: GPL-2.0+
3 #include "../codecs/wm8994.h"
4 #include <sound/pcm_params.h>
6 #include <linux/module.h>
10 * Default CFG switch settings to use this driver:
11 * SMDKV310: CFG5-1000, CFG7-111111
15 * Configure audio route as :-
16 * $ amixer sset 'DAC1' on,on
17 * $ amixer sset 'Right Headphone Mux' 'DAC'
18 * $ amixer sset 'Left Headphone Mux' 'DAC'
19 * $ amixer sset 'DAC1R Mixer AIF1.1' on
20 * $ amixer sset 'DAC1L Mixer AIF1.1' on
21 * $ amixer sset 'IN2L' on
22 * $ amixer sset 'IN2L PGA IN2LN' on
23 * $ amixer sset 'MIXINL IN2L' on
24 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
25 * $ amixer sset 'IN2R' on
26 * $ amixer sset 'IN2R PGA IN2RN' on
27 * $ amixer sset 'MIXINR IN2R' on
28 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
31 /* SMDK has a 16.934MHZ crystal attached to WM8994 */
32 #define SMDK_WM8994_FREQ 16934000
34 static int smdk_hw_params(struct snd_pcm_substream
*substream
,
35 struct snd_pcm_hw_params
*params
)
37 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
38 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
42 /* AIF1CLK should be >=3MHz for optimal performance */
43 if (params_width(params
) == 24)
44 pll_out
= params_rate(params
) * 384;
45 else if (params_rate(params
) == 8000 || params_rate(params
) == 11025)
46 pll_out
= params_rate(params
) * 512;
48 pll_out
= params_rate(params
) * 256;
50 ret
= snd_soc_dai_set_pll(codec_dai
, WM8994_FLL1
, WM8994_FLL_SRC_MCLK1
,
51 SMDK_WM8994_FREQ
, pll_out
);
55 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_FLL1
,
56 pll_out
, SND_SOC_CLOCK_IN
);
64 * SMDK WM8994 DAI operations.
66 static const struct snd_soc_ops smdk_ops
= {
67 .hw_params
= smdk_hw_params
,
70 static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime
*rtd
)
72 struct snd_soc_dapm_context
*dapm
= &rtd
->card
->dapm
;
75 snd_soc_dapm_nc_pin(dapm
, "HPOUT2P");
76 snd_soc_dapm_nc_pin(dapm
, "HPOUT2N");
77 snd_soc_dapm_nc_pin(dapm
, "SPKOUTLN");
78 snd_soc_dapm_nc_pin(dapm
, "SPKOUTLP");
79 snd_soc_dapm_nc_pin(dapm
, "SPKOUTRP");
80 snd_soc_dapm_nc_pin(dapm
, "SPKOUTRN");
81 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1N");
82 snd_soc_dapm_nc_pin(dapm
, "LINEOUT1P");
83 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2N");
84 snd_soc_dapm_nc_pin(dapm
, "LINEOUT2P");
85 snd_soc_dapm_nc_pin(dapm
, "IN1LP");
86 snd_soc_dapm_nc_pin(dapm
, "IN2LP:VXRN");
87 snd_soc_dapm_nc_pin(dapm
, "IN1RP");
88 snd_soc_dapm_nc_pin(dapm
, "IN2RP:VXRP");
93 SND_SOC_DAILINK_DEFS(aif1
,
94 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
95 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
96 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
98 SND_SOC_DAILINK_DEFS(fifo_tx
,
99 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s-sec")),
100 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
101 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s-sec")));
103 static struct snd_soc_dai_link smdk_dai
[] = {
104 { /* Primary DAI i/f */
105 .name
= "WM8994 AIF1",
106 .stream_name
= "Pri_Dai",
107 .init
= smdk_wm8994_init_paiftx
,
108 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
109 SND_SOC_DAIFMT_CBM_CFM
,
111 SND_SOC_DAILINK_REG(aif1
),
112 }, { /* Sec_Fifo Playback i/f */
113 .name
= "Sec_FIFO TX",
114 .stream_name
= "Sec_Dai",
115 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
116 SND_SOC_DAIFMT_CBM_CFM
,
118 SND_SOC_DAILINK_REG(fifo_tx
),
122 static struct snd_soc_card smdk
= {
124 .owner
= THIS_MODULE
,
125 .dai_link
= smdk_dai
,
126 .num_links
= ARRAY_SIZE(smdk_dai
),
129 static const struct of_device_id samsung_wm8994_of_match
[] = {
130 { .compatible
= "samsung,smdk-wm8994" },
133 MODULE_DEVICE_TABLE(of
, samsung_wm8994_of_match
);
135 static int smdk_audio_probe(struct platform_device
*pdev
)
138 struct device_node
*np
= pdev
->dev
.of_node
;
139 struct snd_soc_card
*card
= &smdk
;
141 card
->dev
= &pdev
->dev
;
144 smdk_dai
[0].cpus
->dai_name
= NULL
;
145 smdk_dai
[0].cpus
->of_node
= of_parse_phandle(np
,
146 "samsung,i2s-controller", 0);
147 if (!smdk_dai
[0].cpus
->of_node
) {
149 "Property 'samsung,i2s-controller' missing or invalid\n");
154 smdk_dai
[0].platforms
->name
= NULL
;
155 smdk_dai
[0].platforms
->of_node
= smdk_dai
[0].cpus
->of_node
;
158 ret
= devm_snd_soc_register_card(&pdev
->dev
, card
);
161 dev_err_probe(&pdev
->dev
, ret
, "snd_soc_register_card() failed\n");
166 static struct platform_driver smdk_audio_driver
= {
168 .name
= "smdk-audio-wm8994",
169 .of_match_table
= samsung_wm8994_of_match
,
170 .pm
= &snd_soc_pm_ops
,
172 .probe
= smdk_audio_probe
,
175 module_platform_driver(smdk_audio_driver
);
177 MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
178 MODULE_LICENSE("GPL");
179 MODULE_ALIAS("platform:smdk-audio-wm8994");