History

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.

Jaska Uimonen committed 7 years ago

Commit 5d430011 parent b4be4274 files · +58 −0Browse files

Unified · Split

4 files
  1. include/uapi/sound/sof/tokens.h +4 −0
  2. sound/soc/sof/control.c +32 −0
  3. sound/soc/sof/sof-priv.h +9 −0
  4. sound/soc/sof/topology.c +13 −0
include/uapi/sound/sof/tokens.h+4−0
@@ -113,4 +113,8 @@ · 112 unmodified lines
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+32−0
@@ -11,8 +11,37 @@ · 10 unmodified lines
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, · 93 unmodified lines
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+9−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
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 { · 289 unmodified lines
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 { · 8 unmodified lines
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+13−0
@@ -682,6 +682,14 @@ static const struct sof_topology_token dmic_pdm_tokens[] = { · 681 unmodified lines
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, · 256 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t