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.
Unified · Split
| @@ -113,4 +113,8 @@ · 112 unmodified lines | ||
| 113 | 113 | /* ESAI */ |
| 114 | 114 | #define SOF_TKN_IMX_ESAI_MCLK_ID 1100 |
| 115 | 115 | |
| 116 | +/* Led control for mute switches */ | |
| 117 | +#define SOF_TKN_MUTE_LED_USE 1300 | |
| 118 | +#define SOF_TKN_MUTE_LED_DIRECTION 1301 | |
| 119 | + | |
| 116 | 120 | #endif |
| @@ -11,8 +11,37 @@ · 10 unmodified lines | ||
| 11 | 11 | /* Mixer Controls */ |
| 12 | 12 | |
| 13 | 13 | #include <linux/pm_runtime.h> |
| 14 | +#include <linux/leds.h> | |
| 14 | 15 | #include "sof-priv.h" |
| 15 | 16 | |
| 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 | + | |
| 16 | 45 | static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size) |
| 17 | 46 | { |
| 18 | 47 | if (value >= size) |
| @@ -112,6 +141,9 @@ int snd_sof_switch_put(struct snd_kcontrol *kcontrol, · 93 unmodified lines | ||
| 112 | 141 | cdata->chanv[i].channel = i; |
| 113 | 142 | } |
| 114 | 143 | |
| 144 | + if (scontrol->led_ctl.use_led) | |
| 145 | + update_mute_led(scontrol, kcontrol, ucontrol); | |
| 146 | + | |
| 115 | 147 | /* notify DSP of mixer updates */ |
| 116 | 148 | if (pm_runtime_active(sdev->dev)) |
| 117 | 149 | snd_sof_ipc_set_get_comp_data(sdev->ipc, scontrol, |
| @@ -15,6 +15,7 @@ · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | #include <sound/hdaudio.h> |
| 17 | 17 | #include <sound/soc.h> |
| 18 | +#include <sound/control.h> | |
| 18 | 19 | |
| 19 | 20 | #include <sound/sof.h> |
| 20 | 21 | #include <sound/sof/stream.h> /* needs to be included before control.h */ |
| @@ -310,6 +311,12 @@ struct snd_sof_pcm { · 289 unmodified lines | ||
| 310 | 311 | bool prepared[2]; /* PCM_PARAMS set successfully */ |
| 311 | 312 | }; |
| 312 | 313 | |
| 314 | +struct snd_sof_led_control { | |
| 315 | + unsigned int use_led; | |
| 316 | + unsigned int direction; | |
| 317 | + unsigned int led_value; | |
| 318 | +}; | |
| 319 | + | |
| 313 | 320 | /* ALSA SOF Kcontrol device */ |
| 314 | 321 | struct snd_sof_control { |
| 315 | 322 | struct snd_sof_dev *sdev; |
| @@ -324,6 +331,8 @@ struct snd_sof_control { · 8 unmodified lines | ||
| 324 | 331 | u32 *volume_table; /* volume table computed from tlv data*/ |
| 325 | 332 | |
| 326 | 333 | struct list_head list; /* list in sdev control list */ |
| 334 | + | |
| 335 | + struct snd_sof_led_control led_ctl; | |
| 327 | 336 | }; |
| 328 | 337 | |
| 329 | 338 | /* ASoC SOF DAPM widget */ |
| @@ -682,6 +682,14 @@ static const struct sof_topology_token dmic_pdm_tokens[] = { · 681 unmodified lines | ||
| 682 | 682 | static const struct sof_topology_token hda_tokens[] = { |
| 683 | 683 | }; |
| 684 | 684 | |
| 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 | + | |
| 685 | 693 | static void sof_parse_uuid_tokens(struct snd_soc_component *scomp, |
| 686 | 694 | void *object, |
| 687 | 695 | const struct sof_topology_token *tokens, |
| @@ -944,6 +952,11 @@ static int sof_control_load_volume(struct snd_soc_component *scomp, · 256 unmodified lines | ||
| 944 | 952 | } |
| 945 | 953 | |
| 946 | 954 | 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 | + | |
| 947 | 960 | dev_dbg(sdev->dev, "tplg: load kcontrol index %d chans %d\n", |
| 948 | 961 | scontrol->comp_id, scontrol->num_channels); |
| 949 | 962 | |