1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2020 Intel Corporation
5 * sof_sdw_rt5682 - Helpers to handle RT5682 from generic machine driver
8 #include <linux/device.h>
9 #include <linux/errno.h>
10 #include <linux/input.h>
11 #include <linux/soundwire/sdw.h>
12 #include <linux/soundwire/sdw_type.h>
13 #include <sound/control.h>
14 #include <sound/soc.h>
15 #include <sound/soc-acpi.h>
16 #include <sound/soc-dapm.h>
17 #include <sound/jack.h>
18 #include "sof_sdw_common.h"
20 static const struct snd_soc_dapm_widget rt5682_widgets
[] = {
21 SND_SOC_DAPM_HP("Headphone", NULL
),
22 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
25 static const struct snd_soc_dapm_route rt5682_map
[] = {
27 { "Headphone", NULL
, "rt5682 HPOL" },
28 { "Headphone", NULL
, "rt5682 HPOR" },
29 { "rt5682 IN1P", NULL
, "Headset Mic" },
32 static const struct snd_kcontrol_new rt5682_controls
[] = {
33 SOC_DAPM_PIN_SWITCH("Headphone"),
34 SOC_DAPM_PIN_SWITCH("Headset Mic"),
37 static struct snd_soc_jack_pin rt5682_jack_pins
[] = {
40 .mask
= SND_JACK_HEADPHONE
,
44 .mask
= SND_JACK_MICROPHONE
,
48 static int rt5682_rtd_init(struct snd_soc_pcm_runtime
*rtd
)
50 struct snd_soc_card
*card
= rtd
->card
;
51 struct mc_private
*ctx
= snd_soc_card_get_drvdata(card
);
52 struct snd_soc_dai
*codec_dai
= asoc_rtd_to_codec(rtd
, 0);
53 struct snd_soc_component
*component
= codec_dai
->component
;
54 struct snd_soc_jack
*jack
;
57 card
->components
= devm_kasprintf(card
->dev
, GFP_KERNEL
,
60 if (!card
->components
)
63 ret
= snd_soc_add_card_controls(card
, rt5682_controls
,
64 ARRAY_SIZE(rt5682_controls
));
66 dev_err(card
->dev
, "rt5682 control addition failed: %d\n", ret
);
70 ret
= snd_soc_dapm_new_controls(&card
->dapm
, rt5682_widgets
,
71 ARRAY_SIZE(rt5682_widgets
));
73 dev_err(card
->dev
, "rt5682 widgets addition failed: %d\n", ret
);
77 ret
= snd_soc_dapm_add_routes(&card
->dapm
, rt5682_map
,
78 ARRAY_SIZE(rt5682_map
));
81 dev_err(card
->dev
, "rt5682 map addition failed: %d\n", ret
);
85 ret
= snd_soc_card_jack_new(rtd
->card
, "Headset Jack",
86 SND_JACK_HEADSET
| SND_JACK_BTN_0
|
87 SND_JACK_BTN_1
| SND_JACK_BTN_2
|
91 ARRAY_SIZE(rt5682_jack_pins
));
93 dev_err(rtd
->card
->dev
, "Headset Jack creation failed: %d\n",
98 jack
= &ctx
->sdw_headset
;
100 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
101 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_1
, KEY_VOICECOMMAND
);
102 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_2
, KEY_VOLUMEUP
);
103 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_3
, KEY_VOLUMEDOWN
);
105 ret
= snd_soc_component_set_jack(component
, jack
, NULL
);
108 dev_err(rtd
->card
->dev
, "Headset Jack call-back failed: %d\n",
114 int sof_sdw_rt5682_init(const struct snd_soc_acpi_link_adr
*link
,
115 struct snd_soc_dai_link
*dai_links
,
116 struct sof_sdw_codec_info
*info
,
120 * headset should be initialized once.
121 * Do it with dai link for playback.
126 dai_links
->init
= rt5682_rtd_init
;