Skip to content

Commit 5d43001

Browse files
Jaska Uimonenbroonie
authored andcommitted
ASoC: SOF: acpi led support for switch controls
Currently sof doesn't support acpi leds with mute switches. So implement acpi leds following quite shamelessly existing HDA implementation by Takashi Iwai. Mute leds can be enabled in topology by adding led and direction token in switch control private data. Signed-off-by: Jaska Uimonen <jaska.uimonen@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20191008164443.1358-10-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent b4be427 commit 5d43001

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎include/uapi/sound/sof/tokens.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,8 @@
113113
/* ESAI */
114114
#define SOF_TKN_IMX_ESAI_MCLK_ID 1100
115115

116+
/* Led control for mute switches */
117+
#define SOF_TKN_MUTE_LED_USE 1300
118+
#define SOF_TKN_MUTE_LED_DIRECTION 1301
119+
116120
#endif

‎sound/soc/sof/control.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,37 @@
1111
/* Mixer Controls */
1212

1313
#include <linux/pm_runtime.h>
14+
#include <linux/leds.h>
1415
#include "sof-priv.h"
1516

17+
static void update_mute_led(struct snd_sof_control *scontrol,
18+
struct snd_kcontrol *kcontrol,
19+
struct snd_ctl_elem_value *ucontrol)
20+
{
21+
unsigned int temp = 0;
22+
unsigned int mask;
23+
int i;
24+
25+
mask = 1U << snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
26+
27+
for (i = 0; i < scontrol->num_channels; i++) {
28+
if (ucontrol->value.integer.value[i]) {
29+
temp |= mask;
30+
break;
31+
}
32+
}
33+
34+
if (temp == scontrol->led_ctl.led_value)
35+
return;
36+
37+
scontrol->led_ctl.led_value = temp;
38+
39+
if (!scontrol->led_ctl.direction)
40+
ledtrig_audio_set(LED_AUDIO_MUTE, temp ? LED_OFF : LED_ON);
41+
else
42+
ledtrig_audio_set(LED_AUDIO_MICMUTE, temp ? LED_OFF : LED_ON);
43+
}
44+
1645
static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size)
1746
{
1847
if (value >= size)
@@ -112,6 +141,9 @@ int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
112141
cdata->chanv[i].channel = i;
113142
}
114143

144+
if (scontrol->led_ctl.use_led)
145+
update_mute_led(scontrol, kcontrol, ucontrol);
146+
115147
/* notify DSP of mixer updates */
116148
if (pm_runtime_active(sdev->dev))
117149
snd_sof_ipc_set_get_comp_data(sdev->ipc, scontrol,

‎sound/soc/sof/sof-priv.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <sound/hdaudio.h>
1717
#include <sound/soc.h>
18+
#include <sound/control.h>
1819

1920
#include <sound/sof.h>
2021
#include <sound/sof/stream.h> /* needs to be included before control.h */
@@ -310,6 +311,12 @@ struct snd_sof_pcm {
310311
bool prepared[2]; /* PCM_PARAMS set successfully */
311312
};
312313

314+
struct snd_sof_led_control {
315+
unsigned int use_led;
316+
unsigned int direction;
317+
unsigned int led_value;
318+
};
319+
313320
/* ALSA SOF Kcontrol device */
314321
struct snd_sof_control {
315322
struct snd_sof_dev *sdev;
@@ -324,6 +331,8 @@ struct snd_sof_control {
324331
u32 *volume_table; /* volume table computed from tlv data*/
325332

326333
struct list_head list; /* list in sdev control list */
334+
335+
struct snd_sof_led_control led_ctl;
327336
};
328337

329338
/* ASoC SOF DAPM widget */

‎sound/soc/sof/topology.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,14 @@ static const struct sof_topology_token dmic_pdm_tokens[] = {
682682
static const struct sof_topology_token hda_tokens[] = {
683683
};
684684

685+
/* Leds */
686+
static const struct sof_topology_token led_tokens[] = {
687+
{SOF_TKN_MUTE_LED_USE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
688+
offsetof(struct snd_sof_led_control, use_led), 0},
689+
{SOF_TKN_MUTE_LED_DIRECTION, SND_SOC_TPLG_TUPLE_TYPE_WORD,
690+
get_token_u32, offsetof(struct snd_sof_led_control, direction), 0},
691+
};
692+
685693
static void sof_parse_uuid_tokens(struct snd_soc_component *scomp,
686694
void *object,
687695
const struct sof_topology_token *tokens,
@@ -944,6 +952,11 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,
944952
}
945953

946954
out:
955+
/* set up possible led control from mixer private data */
956+
ret = sof_parse_tokens(scomp, &scontrol->led_ctl, led_tokens,
957+
ARRAY_SIZE(led_tokens), mc->priv.array,
958+
le32_to_cpu(mc->priv.size));
959+
947960
dev_dbg(sdev->dev, "tplg: load kcontrol index %d chans %d\n",
948961
scontrol->comp_id, scontrol->num_channels);
949962

0 commit comments

Comments
 (0)