1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * linux/sound/soc/pxa/brownstone.c
5 * Copyright (C) 2011 Marvell International Ltd.
8 #include <linux/module.h>
9 #include <sound/core.h>
10 #include <sound/pcm.h>
11 #include <sound/soc.h>
12 #include <sound/jack.h>
14 #include "../codecs/wm8994.h"
17 static const struct snd_kcontrol_new brownstone_dapm_control
[] = {
18 SOC_DAPM_PIN_SWITCH("Ext Spk"),
21 static const struct snd_soc_dapm_widget brownstone_dapm_widgets
[] = {
22 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
23 SND_SOC_DAPM_HP("Headset Stereophone", NULL
),
24 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
25 SND_SOC_DAPM_MIC("Main Mic", NULL
),
28 static const struct snd_soc_dapm_route brownstone_audio_map
[] = {
29 {"Ext Spk", NULL
, "SPKOUTLP"},
30 {"Ext Spk", NULL
, "SPKOUTLN"},
31 {"Ext Spk", NULL
, "SPKOUTRP"},
32 {"Ext Spk", NULL
, "SPKOUTRN"},
34 {"Headset Stereophone", NULL
, "HPOUT1L"},
35 {"Headset Stereophone", NULL
, "HPOUT1R"},
37 {"IN1RN", NULL
, "Headset Mic"},
39 {"DMIC1DAT", NULL
, "MICBIAS1"},
40 {"MICBIAS1", NULL
, "Main Mic"},
43 static int brownstone_wm8994_hw_params(struct snd_pcm_substream
*substream
,
44 struct snd_pcm_hw_params
*params
)
46 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
47 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
48 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
49 int freq_out
, sspa_mclk
, sysclk
;
51 if (params_rate(params
) > 11025) {
52 freq_out
= params_rate(params
) * 512;
53 sysclk
= params_rate(params
) * 256;
54 sspa_mclk
= params_rate(params
) * 64;
56 freq_out
= params_rate(params
) * 1024;
57 sysclk
= params_rate(params
) * 512;
58 sspa_mclk
= params_rate(params
) * 64;
61 snd_soc_dai_set_sysclk(cpu_dai
, MMP_SSPA_CLK_AUDIO
, freq_out
, 0);
62 snd_soc_dai_set_pll(cpu_dai
, MMP_SYSCLK
, 0, freq_out
, sysclk
);
63 snd_soc_dai_set_pll(cpu_dai
, MMP_SSPA_CLK
, 0, freq_out
, sspa_mclk
);
65 /* set wm8994 sysclk */
66 snd_soc_dai_set_sysclk(codec_dai
, WM8994_SYSCLK_MCLK1
, sysclk
, 0);
71 /* machine stream operations */
72 static const struct snd_soc_ops brownstone_ops
= {
73 .hw_params
= brownstone_wm8994_hw_params
,
76 SND_SOC_DAILINK_DEFS(wm8994
,
77 DAILINK_COMP_ARRAY(COMP_CPU("mmp-sspa-dai.0")),
78 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
79 DAILINK_COMP_ARRAY(COMP_PLATFORM("mmp-pcm-audio")));
81 static struct snd_soc_dai_link brownstone_wm8994_dai
[] = {
84 .stream_name
= "WM8994 HiFi",
85 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
86 SND_SOC_DAIFMT_CBS_CFS
,
87 .ops
= &brownstone_ops
,
88 SND_SOC_DAILINK_REG(wm8994
),
92 /* audio machine driver */
93 static struct snd_soc_card brownstone
= {
96 .dai_link
= brownstone_wm8994_dai
,
97 .num_links
= ARRAY_SIZE(brownstone_wm8994_dai
),
99 .controls
= brownstone_dapm_control
,
100 .num_controls
= ARRAY_SIZE(brownstone_dapm_control
),
101 .dapm_widgets
= brownstone_dapm_widgets
,
102 .num_dapm_widgets
= ARRAY_SIZE(brownstone_dapm_widgets
),
103 .dapm_routes
= brownstone_audio_map
,
104 .num_dapm_routes
= ARRAY_SIZE(brownstone_audio_map
),
105 .fully_routed
= true,
108 static int brownstone_probe(struct platform_device
*pdev
)
112 brownstone
.dev
= &pdev
->dev
;
113 ret
= devm_snd_soc_register_card(&pdev
->dev
, &brownstone
);
115 dev_err(&pdev
->dev
, "snd_soc_register_card() failed: %d\n",
120 static struct platform_driver mmp_driver
= {
122 .name
= "brownstone-audio",
123 .pm
= &snd_soc_pm_ops
,
125 .probe
= brownstone_probe
,
128 module_platform_driver(mmp_driver
);
130 MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
131 MODULE_DESCRIPTION("ALSA SoC Brownstone");
132 MODULE_LICENSE("GPL");
133 MODULE_ALIAS("platform:brownstone-audio");