Skip to content

Commit c7440ac

Browse files
committed
Merge branch 'topic/hda-micmute-led' into for-next
This is a patch set inspired by the recent patch Kai-Heng posted about the HD-audio mic-mute LED control. Currently HD-audio driver deals with the mute and mic-mute LED in several different ways: primarily with the direct callback of vmaster hook and capture sync hook, while another with the LED class device binding. The latter has been used for binding with the platform device LEDs like Thinkpad, Dell, Huawei. And, yet, recently we added our own LED classdev for the mic-mute LED on some HP systems although they are controlled directly with the callback; it's exposed, however, for the DMIC that is governed by a different ASoC driver. This patch set is an attempt to sort out and make them consistent: namely, * All LEDs are now controlled via LED class device * The generic driver provides helper functions to easily build up the LED class dev and the relevant mixer controls * Conversion of the existing framework and clean ups The patches are lightly tested in my side with a couple of machines and also through hda-emu tests. Some devices receive new kcontrols for the mute LED behavior (that have been missing so far), but anything else look good though my tests. Link: https://lore.kernel.org/r/20200618110842.27238-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
2 parents f34a4c9 + c9e272f commit c7440ac

7 files changed

Lines changed: 248 additions & 216 deletions

File tree

‎sound/pci/hda/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ config SND_HDA
88
select SND_JACK
99
select SND_HDA_CORE
1010

11+
config SND_HDA_GENERIC_LEDS
12+
bool
13+
1114
config SND_HDA_INTEL
1215
tristate "HD Audio PCI"
1316
depends on SND_PCI
@@ -91,6 +94,7 @@ config SND_HDA_PATCH_LOADER
9194
config SND_HDA_CODEC_REALTEK
9295
tristate "Build Realtek HD-audio codec support"
9396
select SND_HDA_GENERIC
97+
select SND_HDA_GENERIC_LEDS
9498
help
9599
Say Y or M here to include Realtek HD-audio codec support in
96100
snd-hda-intel driver, such as ALC880.
@@ -111,6 +115,7 @@ comment "Set to Y if you want auto-loading the codec driver"
111115
config SND_HDA_CODEC_SIGMATEL
112116
tristate "Build IDT/Sigmatel HD-audio codec support"
113117
select SND_HDA_GENERIC
118+
select SND_HDA_GENERIC_LEDS
114119
help
115120
Say Y or M here to include IDT (Sigmatel) HD-audio codec support in
116121
snd-hda-intel driver, such as STAC9200.
@@ -155,6 +160,7 @@ comment "Set to Y if you want auto-loading the codec driver"
155160
config SND_HDA_CODEC_CONEXANT
156161
tristate "Build Conexant HD-audio codec support"
157162
select SND_HDA_GENERIC
163+
select SND_HDA_GENERIC_LEDS
158164
help
159165
Say Y or M here to include Conexant HD-audio codec support in
160166
snd-hda-intel driver, such as CX20549.
@@ -215,6 +221,9 @@ comment "Set to Y if you want auto-loading the codec driver"
215221

216222
config SND_HDA_GENERIC
217223
tristate "Enable generic HD-audio codec parser"
224+
select LEDS_CLASS if SND_HDA_GENERIC_LEDS
225+
select LEDS_TRIGGERS if SND_HDA_GENERIC_LEDS
226+
select LEDS_TRIGGER_AUDIO if SND_HDA_GENERIC_LEDS
218227
help
219228
Say Y or M here to enable the generic HD-audio codec parser
220229
in snd-hda-intel driver.

‎sound/pci/hda/hda_generic.c‎

Lines changed: 89 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,6 +3887,66 @@ static int parse_mic_boost(struct hda_codec *codec)
38873887
return 0;
38883888
}
38893889

3890+
#ifdef CONFIG_SND_HDA_GENERIC_LEDS
3891+
/*
3892+
* vmaster mute LED hook helpers
3893+
*/
3894+
3895+
static int create_mute_led_cdev(struct hda_codec *codec,
3896+
int (*callback)(struct led_classdev *,
3897+
enum led_brightness),
3898+
bool micmute)
3899+
{
3900+
struct led_classdev *cdev;
3901+
3902+
cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL);
3903+
if (!cdev)
3904+
return -ENOMEM;
3905+
3906+
cdev->name = micmute ? "hda::micmute" : "hda::mute";
3907+
cdev->max_brightness = 1;
3908+
cdev->default_trigger = micmute ? "audio-micmute" : "audio-mute";
3909+
cdev->brightness_set_blocking = callback;
3910+
cdev->brightness = ledtrig_audio_get(micmute ? LED_AUDIO_MICMUTE : LED_AUDIO_MUTE);
3911+
cdev->flags = LED_CORE_SUSPENDRESUME;
3912+
3913+
return devm_led_classdev_register(&codec->core.dev, cdev);
3914+
}
3915+
3916+
static void vmaster_update_mute_led(void *private_data, int enabled)
3917+
{
3918+
ledtrig_audio_set(LED_AUDIO_MUTE, enabled ? LED_OFF : LED_ON);
3919+
}
3920+
3921+
/**
3922+
* snd_dha_gen_add_mute_led_cdev - Create a LED classdev and enable as vmaster mute LED
3923+
* @codec: the HDA codec
3924+
* @callback: the callback for LED classdev brightness_set_blocking
3925+
*/
3926+
int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,
3927+
int (*callback)(struct led_classdev *,
3928+
enum led_brightness))
3929+
{
3930+
struct hda_gen_spec *spec = codec->spec;
3931+
int err;
3932+
3933+
if (callback) {
3934+
err = create_mute_led_cdev(codec, callback, false);
3935+
if (err) {
3936+
codec_warn(codec, "failed to create a mute LED cdev\n");
3937+
return err;
3938+
}
3939+
}
3940+
3941+
if (spec->vmaster_mute.hook)
3942+
codec_err(codec, "vmaster hook already present before cdev!\n");
3943+
3944+
spec->vmaster_mute.hook = vmaster_update_mute_led;
3945+
spec->vmaster_mute_enum = 1;
3946+
return 0;
3947+
}
3948+
EXPORT_SYMBOL_GPL(snd_hda_gen_add_mute_led_cdev);
3949+
38903950
/*
38913951
* mic mute LED hook helpers
38923952
*/
@@ -3921,8 +3981,8 @@ static void call_micmute_led_update(struct hda_codec *codec)
39213981
if (val == spec->micmute_led.led_value)
39223982
return;
39233983
spec->micmute_led.led_value = val;
3924-
if (spec->micmute_led.update)
3925-
spec->micmute_led.update(codec);
3984+
ledtrig_audio_set(LED_AUDIO_MICMUTE,
3985+
spec->micmute_led.led_value ? LED_ON : LED_OFF);
39263986
}
39273987

39283988
static void update_micmute_led(struct hda_codec *codec,
@@ -3994,69 +4054,53 @@ static const struct snd_kcontrol_new micmute_led_mode_ctl = {
39944054
.put = micmute_led_mode_put,
39954055
};
39964056

3997-
/**
3998-
* snd_hda_gen_add_micmute_led - helper for setting up mic mute LED hook
3999-
* @codec: the HDA codec
4000-
* @hook: the callback for updating LED
4001-
*
4002-
* Called from the codec drivers for offering the mic mute LED controls.
4003-
* When established, it sets up cap_sync_hook and triggers the callback at
4004-
* each time when the capture mixer switch changes. The callback is supposed
4005-
* to update the LED accordingly.
4006-
*
4007-
* Returns 0 if the hook is established or a negative error code.
4008-
*/
4009-
int snd_hda_gen_add_micmute_led(struct hda_codec *codec,
4010-
void (*hook)(struct hda_codec *))
4057+
/* Set up the capture sync hook for controlling the mic-mute LED */
4058+
static int add_micmute_led_hook(struct hda_codec *codec)
40114059
{
40124060
struct hda_gen_spec *spec = codec->spec;
40134061

40144062
spec->micmute_led.led_mode = MICMUTE_LED_FOLLOW_MUTE;
40154063
spec->micmute_led.capture = 0;
40164064
spec->micmute_led.led_value = 0;
40174065
spec->micmute_led.old_hook = spec->cap_sync_hook;
4018-
spec->micmute_led.update = hook;
40194066
spec->cap_sync_hook = update_micmute_led;
40204067
if (!snd_hda_gen_add_kctl(spec, NULL, &micmute_led_mode_ctl))
40214068
return -ENOMEM;
40224069
return 0;
40234070
}
4024-
EXPORT_SYMBOL_GPL(snd_hda_gen_add_micmute_led);
4025-
4026-
#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
4027-
static void call_ledtrig_micmute(struct hda_codec *codec)
4028-
{
4029-
struct hda_gen_spec *spec = codec->spec;
4030-
4031-
ledtrig_audio_set(LED_AUDIO_MICMUTE,
4032-
spec->micmute_led.led_value ? LED_ON : LED_OFF);
4033-
}
4034-
#endif
40354071

40364072
/**
4037-
* snd_hda_gen_fixup_micmute_led - A fixup for mic-mute LED trigger
4038-
*
4039-
* Pass this function to the quirk entry if another driver supports the
4040-
* audio mic-mute LED trigger. Then this will bind the mixer capture switch
4041-
* change with the LED.
4073+
* snd_dha_gen_add_micmute_led_cdev - Create a LED classdev and enable as mic-mute LED
4074+
* @codec: the HDA codec
4075+
* @callback: the callback for LED classdev brightness_set_blocking
40424076
*
4043-
* Note that this fixup has to be called after other fixup that sets
4044-
* cap_sync_hook. Otherwise the chaining wouldn't work.
4077+
* Called from the codec drivers for offering the mic mute LED controls.
4078+
* This creates a LED classdev and sets up the cap_sync_hook that is called at
4079+
* each time when the capture mixer switch changes.
40454080
*
4046-
* @codec: the HDA codec
4047-
* @fix: fixup pointer
4048-
* @action: only supports HDA_FIXUP_ACT_PROBE value
4081+
* When NULL is passed to @callback, no classdev is created but only the
4082+
* LED-trigger is set up.
40494083
*
4084+
* Returns 0 or a negative error.
40504085
*/
4051-
void snd_hda_gen_fixup_micmute_led(struct hda_codec *codec,
4052-
const struct hda_fixup *fix, int action)
4086+
int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
4087+
int (*callback)(struct led_classdev *,
4088+
enum led_brightness))
40534089
{
4054-
#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
4055-
if (action == HDA_FIXUP_ACT_PROBE)
4056-
snd_hda_gen_add_micmute_led(codec, call_ledtrig_micmute);
4057-
#endif
4090+
int err;
4091+
4092+
if (callback) {
4093+
err = create_mute_led_cdev(codec, callback, true);
4094+
if (err) {
4095+
codec_warn(codec, "failed to create a mic-mute LED cdev\n");
4096+
return err;
4097+
}
4098+
}
4099+
4100+
return add_micmute_led_hook(codec);
40584101
}
4059-
EXPORT_SYMBOL_GPL(snd_hda_gen_fixup_micmute_led);
4102+
EXPORT_SYMBOL_GPL(snd_hda_gen_add_micmute_led_cdev);
4103+
#endif /* CONFIG_SND_HDA_GENERIC_LEDS */
40604104

40614105
/*
40624106
* parse digital I/Os and set up NIDs in BIOS auto-parse mode

‎sound/pci/hda/hda_generic.h‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef __SOUND_HDA_GENERIC_H
99
#define __SOUND_HDA_GENERIC_H
1010

11+
#include <linux/leds.h>
12+
1113
/* table entry for multi-io paths */
1214
struct hda_multi_io {
1315
hda_nid_t pin; /* multi-io widget pin NID */
@@ -86,7 +88,6 @@ struct hda_micmute_hook {
8688
unsigned int led_mode;
8789
unsigned int capture;
8890
unsigned int led_value;
89-
void (*update)(struct hda_codec *codec);
9091
void (*old_hook)(struct hda_codec *codec,
9192
struct snd_kcontrol *kcontrol,
9293
struct snd_ctl_elem_value *ucontrol);
@@ -353,9 +354,11 @@ unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
353354
void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on);
354355
int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin);
355356

356-
int snd_hda_gen_add_micmute_led(struct hda_codec *codec,
357-
void (*hook)(struct hda_codec *));
358-
void snd_hda_gen_fixup_micmute_led(struct hda_codec *codec,
359-
const struct hda_fixup *fix, int action);
357+
int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,
358+
int (*callback)(struct led_classdev *,
359+
enum led_brightness));
360+
int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
361+
int (*callback)(struct led_classdev *,
362+
enum led_brightness));
360363

361364
#endif /* __SOUND_HDA_GENERIC_H */

‎sound/pci/hda/patch_conexant.c‎

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,16 @@ static void cx_auto_vmaster_hook(void *private_data, int enabled)
137137
}
138138

139139
/* turn on/off EAPD according to Master switch (inversely!) for mute LED */
140-
static void cx_auto_vmaster_hook_mute_led(void *private_data, int enabled)
140+
static int cx_auto_vmaster_mute_led(struct led_classdev *led_cdev,
141+
enum led_brightness brightness)
141142
{
142-
struct hda_codec *codec = private_data;
143+
struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
143144
struct conexant_spec *spec = codec->spec;
144145

145146
snd_hda_codec_write(codec, spec->mute_led_eapd, 0,
146147
AC_VERB_SET_EAPD_BTLENABLE,
147-
enabled ? 0x00 : 0x02);
148+
brightness ? 0x02 : 0x00);
149+
return 0;
148150
}
149151

150152
static int cx_auto_init(struct hda_codec *codec)
@@ -566,7 +568,7 @@ static void cxt_fixup_mute_led_eapd(struct hda_codec *codec,
566568
if (action == HDA_FIXUP_ACT_PRE_PROBE) {
567569
spec->mute_led_eapd = 0x1b;
568570
spec->dynamic_eapd = 1;
569-
spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook_mute_led;
571+
snd_hda_gen_add_mute_led_cdev(codec, cx_auto_vmaster_mute_led);
570572
}
571573
}
572574

@@ -631,21 +633,25 @@ static void cxt_update_gpio_led(struct hda_codec *codec, unsigned int mask,
631633
}
632634

633635
/* turn on/off mute LED via GPIO per vmaster hook */
634-
static void cxt_fixup_gpio_mute_hook(void *private_data, int enabled)
636+
static int cxt_gpio_mute_update(struct led_classdev *led_cdev,
637+
enum led_brightness brightness)
635638
{
636-
struct hda_codec *codec = private_data;
639+
struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
637640
struct conexant_spec *spec = codec->spec;
638-
/* muted -> LED on */
639-
cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, !enabled);
641+
642+
cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, brightness);
643+
return 0;
640644
}
641645

642646
/* turn on/off mic-mute LED via GPIO per capture hook */
643-
static void cxt_gpio_micmute_update(struct hda_codec *codec)
647+
static int cxt_gpio_micmute_update(struct led_classdev *led_cdev,
648+
enum led_brightness brightness)
644649
{
650+
struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
645651
struct conexant_spec *spec = codec->spec;
646652

647-
cxt_update_gpio_led(codec, spec->gpio_mic_led_mask,
648-
spec->gen.micmute_led.led_value);
653+
cxt_update_gpio_led(codec, spec->gpio_mic_led_mask, brightness);
654+
return 0;
649655
}
650656

651657

@@ -660,12 +666,12 @@ static void cxt_fixup_mute_led_gpio(struct hda_codec *codec,
660666
};
661667

662668
if (action == HDA_FIXUP_ACT_PRE_PROBE) {
663-
spec->gen.vmaster_mute.hook = cxt_fixup_gpio_mute_hook;
669+
snd_hda_gen_add_mute_led_cdev(codec, cxt_gpio_mute_update);
664670
spec->gpio_led = 0;
665671
spec->mute_led_polarity = 0;
666672
spec->gpio_mute_led_mask = 0x01;
667673
spec->gpio_mic_led_mask = 0x02;
668-
snd_hda_gen_add_micmute_led(codec, cxt_gpio_micmute_update);
674+
snd_hda_gen_add_micmute_led_cdev(codec, cxt_gpio_micmute_update);
669675
}
670676
snd_hda_add_verbs(codec, gpio_init);
671677
if (spec->gpio_led)
@@ -988,8 +994,6 @@ static int patch_conexant_auto(struct hda_codec *codec)
988994

989995
cx_auto_parse_eapd(codec);
990996
spec->gen.own_eapd_ctl = 1;
991-
if (spec->dynamic_eapd)
992-
spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
993997

994998
switch (codec->core.vendor_id) {
995999
case 0x14f15045:
@@ -1022,17 +1026,8 @@ static int patch_conexant_auto(struct hda_codec *codec)
10221026
break;
10231027
}
10241028

1025-
/* Show mute-led control only on HP laptops
1026-
* This is a sort of white-list: on HP laptops, EAPD corresponds
1027-
* only to the mute-LED without actualy amp function. Meanwhile,
1028-
* others may use EAPD really as an amp switch, so it might be
1029-
* not good to expose it blindly.
1030-
*/
1031-
switch (codec->core.subsystem_id >> 16) {
1032-
case 0x103c:
1033-
spec->gen.vmaster_mute_enum = 1;
1034-
break;
1035-
}
1029+
if (!spec->gen.vmaster_mute.hook && spec->dynamic_eapd)
1030+
spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
10361031

10371032
snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
10381033

0 commit comments

Comments
 (0)