2023-09-22 05:15:18

by Stefan Binding

[permalink] [raw]
Subject: [PATCH v5 0/4] Support mute notifications for CS35L41 HDA

Some systems use a special keyboard shortcut to mute speaker audio.
On systems using CS35L41 HDA which have this shortcut, add a
mechanism which uses ACPI notifications to determine when the
shortcut is pressed, and then mute the amps inside the driver.

Since this is not a normal mute mechanism, it does not go through
userspace. To allow userspace to be able to track this special
state, add an ALSA control which tracks the state of this forced
mute

Changes since v2:
- Fixed compile issue when CONFIG_ACPI is missing

Changes since v3:
- Split first patch into 3 separate patches
- Ensure all acpi code is protected by check for CONFIG_ACPI in
realtek driver

Changes since v4:
- Rebase onto for-next branch

Stefan Binding (4):
ALSA: hda: cs35l41: Add notification support into component binding
ALSA: hda/realtek: Support ACPI Notification framework via component
binding
ALSA: hda: cs35l41: Support mute notifications for CS35L41 HDA
ALSA: hda: cs35l41: Add read-only ALSA control for forced mute

sound/pci/hda/cs35l41_hda.c | 132 ++++++++++++++++++++++++++++++----
sound/pci/hda/cs35l41_hda.h | 3 +
sound/pci/hda/hda_component.h | 4 ++
sound/pci/hda/patch_realtek.c | 83 ++++++++++++++++++++-
4 files changed, 208 insertions(+), 14 deletions(-)

--
2.34.1


2023-09-22 05:33:10

by Stefan Binding

[permalink] [raw]
Subject: [PATCH v5 1/4] ALSA: hda: cs35l41: Add notification support into component binding

Some systems support a notification from ACPI, which can be used
for different things.

Only one handler can be registered for the acpi notification, but all
amps need to receive that notification, we can register a single handler
inside the component master, so that it can then notify through the
component framework.

This is required to support mute notifications from ACPI.

Signed-off-by: Stefan Binding <[email protected]>
---
sound/pci/hda/hda_component.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/sound/pci/hda/hda_component.h b/sound/pci/hda/hda_component.h
index f170aec967c1..bbd6f0ed16c1 100644
--- a/sound/pci/hda/hda_component.h
+++ b/sound/pci/hda/hda_component.h
@@ -6,6 +6,7 @@
* Cirrus Logic International Semiconductor Ltd.
*/

+#include <linux/acpi.h>
#include <linux/component.h>

#define HDA_MAX_COMPONENTS 4
@@ -15,6 +16,9 @@ struct hda_component {
struct device *dev;
char name[HDA_MAX_NAME_SIZE];
struct hda_codec *codec;
+ struct acpi_device *adev;
+ bool acpi_notifications_supported;
+ void (*acpi_notify)(acpi_handle handle, u32 event, struct device *dev);
void (*pre_playback_hook)(struct device *dev, int action);
void (*playback_hook)(struct device *dev, int action);
void (*post_playback_hook)(struct device *dev, int action);
--
2.34.1

2023-09-22 07:38:09

by Stefan Binding

[permalink] [raw]
Subject: [PATCH v5 4/4] ALSA: hda: cs35l41: Add read-only ALSA control for forced mute

When the CS35L41 amp is requested to mute using the ACPI
notification mechanism, userspace is not notified that the amp
is muted. To allow userspace to know about the mute, add an
ALSA control which tracks the forced mute override.
This control does not track the overall mute state of the amp,
since the amp is only unmuted during playback anyway, instead
it tracks the mute override request from the ACPI notification.

Signed-off-by: Stefan Binding <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index 18ca00c0a8cd..92b815ce193b 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -972,6 +972,15 @@ static int cs35l41_fw_load_ctl_get(struct snd_kcontrol *kcontrol,
return 0;
}

+static int cs35l41_mute_override_ctl_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol);
+
+ ucontrol->value.integer.value[0] = cs35l41->mute_override;
+ return 0;
+}
+
static void cs35l41_fw_load_work(struct work_struct *work)
{
struct cs35l41_hda *cs35l41 = container_of(work, struct cs35l41_hda, fw_load_work);
@@ -1055,6 +1064,7 @@ static int cs35l41_create_controls(struct cs35l41_hda *cs35l41)
{
char fw_type_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
char fw_load_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
+ char mute_override_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
struct snd_kcontrol_new fw_type_ctl = {
.name = fw_type_ctl_name,
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
@@ -1069,12 +1079,21 @@ static int cs35l41_create_controls(struct cs35l41_hda *cs35l41)
.get = cs35l41_fw_load_ctl_get,
.put = cs35l41_fw_load_ctl_put,
};
+ struct snd_kcontrol_new mute_override_ctl = {
+ .name = mute_override_ctl_name,
+ .iface = SNDRV_CTL_ELEM_IFACE_CARD,
+ .info = snd_ctl_boolean_mono_info,
+ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+ .get = cs35l41_mute_override_ctl_get,
+ };
int ret;

scnprintf(fw_type_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s DSP1 Firmware Type",
cs35l41->amp_name);
scnprintf(fw_load_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s DSP1 Firmware Load",
cs35l41->amp_name);
+ scnprintf(mute_override_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s Forced Mute Status",
+ cs35l41->amp_name);

ret = snd_ctl_add(cs35l41->codec->card, snd_ctl_new1(&fw_type_ctl, cs35l41));
if (ret) {
@@ -1092,6 +1111,15 @@ static int cs35l41_create_controls(struct cs35l41_hda *cs35l41)

dev_dbg(cs35l41->dev, "Added Control %s\n", fw_load_ctl.name);

+ ret = snd_ctl_add(cs35l41->codec->card, snd_ctl_new1(&mute_override_ctl, cs35l41));
+ if (ret) {
+ dev_err(cs35l41->dev, "Failed to add KControl %s = %d\n", mute_override_ctl.name,
+ ret);
+ return ret;
+ }
+
+ dev_dbg(cs35l41->dev, "Added Control %s\n", mute_override_ctl.name);
+
return 0;
}

--
2.34.1

2023-09-22 10:16:53

by Takashi Iwai

[permalink] [raw]
Subject: Re: [PATCH v5 0/4] Support mute notifications for CS35L41 HDA

On Thu, 21 Sep 2023 18:28:45 +0200,
Stefan Binding wrote:
>
> Some systems use a special keyboard shortcut to mute speaker audio.
> On systems using CS35L41 HDA which have this shortcut, add a
> mechanism which uses ACPI notifications to determine when the
> shortcut is pressed, and then mute the amps inside the driver.
>
> Since this is not a normal mute mechanism, it does not go through
> userspace. To allow userspace to be able to track this special
> state, add an ALSA control which tracks the state of this forced
> mute
>
> Changes since v2:
> - Fixed compile issue when CONFIG_ACPI is missing
>
> Changes since v3:
> - Split first patch into 3 separate patches
> - Ensure all acpi code is protected by check for CONFIG_ACPI in
> realtek driver
>
> Changes since v4:
> - Rebase onto for-next branch
>
> Stefan Binding (4):
> ALSA: hda: cs35l41: Add notification support into component binding
> ALSA: hda/realtek: Support ACPI Notification framework via component
> binding
> ALSA: hda: cs35l41: Support mute notifications for CS35L41 HDA
> ALSA: hda: cs35l41: Add read-only ALSA control for forced mute

Applied to for-next branch now. Thanks.


Takashi