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

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