[alsa-devel] [PATCH v2 0/6] Introduce audio-mute LED trigger (and conversions to it)
Hi,
this is revised patch series for adding a new LED trigger audio-mute and audio-micmute, and converting the HD-audio driver and the platform drivers to use the LED trigger instead of the ugly direct dynamic symbol binding.
v2 series addressed a couple of issues Andy suggested, and changed the led class dev names to "platform::xxx" as discussed in the previous thread.
The latest version of patches are found in topic/leds-trigger branch in my sound git tree. git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
As these are cross-tree patches, the branch above is based cleanly on v4.20-rc3. From now on, it'll stay as an immutable branch, so feel free to merge into other trees.
thanks,
Takashi
===
Takashi Iwai (6): leds: trigger: Introduce audio mute LED trigger platform/x86: dell-laptop: Add micmute LED trigger support platform/x86: thinkpad_acpi: Add audio mute LED classdev support ALSA: hda - Support led audio trigger platform/x86: dell-laptop: Drop superfluous exported function platform/x86: thinkpad_acpi: Drop superfluous exported function
drivers/leds/trigger/Kconfig | 7 +++ drivers/leds/trigger/Makefile | 1 + drivers/leds/trigger/ledtrig-audio.c | 44 ++++++++++++++++++ drivers/platform/x86/Kconfig | 4 ++ drivers/platform/x86/dell-laptop.c | 27 ++++++++--- drivers/platform/x86/thinkpad_acpi.c | 67 +++++++++++++++++++++------- include/linux/dell-led.h | 7 --- include/linux/leds.h | 20 +++++++++ include/linux/thinkpad_acpi.h | 16 ------- sound/pci/hda/dell_wmi_helper.c | 48 -------------------- sound/pci/hda/hda_generic.c | 31 +++++++++++++ sound/pci/hda/hda_generic.h | 2 + sound/pci/hda/patch_realtek.c | 17 +++---- sound/pci/hda/thinkpad_helper.c | 43 +++--------------- 14 files changed, 194 insertions(+), 140 deletions(-) create mode 100644 drivers/leds/trigger/ledtrig-audio.c delete mode 100644 include/linux/dell-led.h delete mode 100644 include/linux/thinkpad_acpi.h delete mode 100644 sound/pci/hda/dell_wmi_helper.c
This patch adds a new LED trigger for coupling the audio mixer change with the LED on laptops or other devices. Currently there are two trigger types, "audio-mute" and "audio-micmute".
The audio driver triggers the LED brightness change via ledtrig_audio_set() call with the proper type (either mute or mic-mute). OTOH, the consumers may call ledtrig_audio_get() for the initial brightness value that may have been set by the audio driver beforehand.
This new stuff will be used by HD-audio codec driver and some platform drivers (thinkpad_acpi and dell-laptop, also upcoming huawei-wmi).
Acked-by: Jacek Anaszewski jacek.anaszewski@gmail.com Acked-by: Pavel Machek pavel@ucw.cz Acked-by: Pali Rohár pali.rohar@gmail.com Signed-off-by: Takashi Iwai tiwai@suse.de --- drivers/leds/trigger/Kconfig | 7 +++++ drivers/leds/trigger/Makefile | 1 + drivers/leds/trigger/ledtrig-audio.c | 44 ++++++++++++++++++++++++++++ include/linux/leds.h | 20 +++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 drivers/leds/trigger/ledtrig-audio.c
diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig index b76fc3cdc8f8..23cc85e2e0e5 100644 --- a/drivers/leds/trigger/Kconfig +++ b/drivers/leds/trigger/Kconfig @@ -136,4 +136,11 @@ config LEDS_TRIGGER_PATTERN which is a series of tuples, of brightness and duration (ms). If unsure, say N
+config LEDS_TRIGGER_AUDIO + tristate "Audio Mute LED Trigger" + help + This allows LEDs to be controlled by audio drivers for following + the audio mute and mic-mute changes. + If unsure, say N + endif # LEDS_TRIGGERS diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile index 9bcb64ee8123..733a83e2a718 100644 --- a/drivers/leds/trigger/Makefile +++ b/drivers/leds/trigger/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o obj-$(CONFIG_LEDS_TRIGGER_PANIC) += ledtrig-panic.o obj-$(CONFIG_LEDS_TRIGGER_NETDEV) += ledtrig-netdev.o obj-$(CONFIG_LEDS_TRIGGER_PATTERN) += ledtrig-pattern.o +obj-$(CONFIG_LEDS_TRIGGER_AUDIO) += ledtrig-audio.o diff --git a/drivers/leds/trigger/ledtrig-audio.c b/drivers/leds/trigger/ledtrig-audio.c new file mode 100644 index 000000000000..f76621e88482 --- /dev/null +++ b/drivers/leds/trigger/ledtrig-audio.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Audio Mute LED trigger +// + +#include <linux/kernel.h> +#include <linux/leds.h> +#include <linux/module.h> + +static struct led_trigger *ledtrig_audio[NUM_AUDIO_LEDS]; +static enum led_brightness audio_state[NUM_AUDIO_LEDS]; + +enum led_brightness ledtrig_audio_get(enum led_audio type) +{ + return audio_state[type]; +} +EXPORT_SYMBOL_GPL(ledtrig_audio_get); + +void ledtrig_audio_set(enum led_audio type, enum led_brightness state) +{ + audio_state[type] = state; + led_trigger_event(ledtrig_audio[type], state); +} +EXPORT_SYMBOL_GPL(ledtrig_audio_set); + +static int __init ledtrig_audio_init(void) +{ + led_trigger_register_simple("audio-mute", + &ledtrig_audio[LED_AUDIO_MUTE]); + led_trigger_register_simple("audio-micmute", + &ledtrig_audio[LED_AUDIO_MICMUTE]); + return 0; +} +module_init(ledtrig_audio_init); + +static void __exit ledtrig_audio_exit(void) +{ + led_trigger_unregister_simple(ledtrig_audio[LED_AUDIO_MUTE]); + led_trigger_unregister_simple(ledtrig_audio[LED_AUDIO_MICMUTE]); +} +module_exit(ledtrig_audio_exit); + +MODULE_DESCRIPTION("LED trigger for audio mute control"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/leds.h b/include/linux/leds.h index 7393a316d9fa..580cbaef789a 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -487,4 +487,24 @@ struct led_pattern { int brightness; };
+enum led_audio { + LED_AUDIO_MUTE, /* master mute LED */ + LED_AUDIO_MICMUTE, /* mic mute LED */ + NUM_AUDIO_LEDS +}; + +#if IS_ENABLED(CONFIG_LEDS_TRIGGER_AUDIO) +enum led_brightness ledtrig_audio_get(enum led_audio type); +void ledtrig_audio_set(enum led_audio type, enum led_brightness state); +#else +static inline enum led_brightness ledtrig_audio_get(enum led_audio type) +{ + return LED_OFF; +} +static inline void ledtrig_audio_set(enum led_audio type, + enum led_brightness state) +{ +} +#endif + #endif /* __LINUX_LEDS_H_INCLUDED */
This patch adds the LED trigger support for audio mic-mute control. As of this patch, the LED device isn't tied with the audio driver, and can be changed via user-space at "platform::micmute" sysfs entry. (This new prefix "platform" is the agreement among people for indicating the generic laptop / system-wide attribute.)
The binding with HD-audio is still done via the existing exported dell_micmute_led_set(). It will be replaced with the LED trigger binding in later patches.
Also this selects CONFIG_LEDS_TRIGGERS and CONFIG_LEDS_TRIGGERS_AUDIO unconditionally. Strictly speaking, these aren't 100% mandatory, but leaving these manual selections would lead to a functional regression easily once after converting from the dynamic symbol binding to the LEDs trigger in a later patch.
Acked-by: Jacek Anaszewski jacek.anaszewski@gmail.com Acked-by: Pavel Machek pavel@ucw.cz Acked-by: Andy Shevchenko andy.shevchenko@gmail.com Acked-by: Pali Rohár pali.rohar@gmail.com Signed-off-by: Takashi Iwai tiwai@suse.de --- drivers/platform/x86/Kconfig | 2 ++ drivers/platform/x86/dell-laptop.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 54f6a40c75c6..9b9cc3cc33e9 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -177,6 +177,8 @@ config DELL_LAPTOP select POWER_SUPPLY select LEDS_CLASS select NEW_LEDS + select LEDS_TRIGGERS + select LEDS_TRIGGER_AUDIO ---help--- This driver adds support for rfkill and backlight control to Dell laptops (except for some models covered by the Compal driver). diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c index 06978c14c83b..0db2dbf7b0d1 100644 --- a/drivers/platform/x86/dell-laptop.c +++ b/drivers/platform/x86/dell-laptop.c @@ -2131,6 +2131,23 @@ int dell_micmute_led_set(int state) } EXPORT_SYMBOL_GPL(dell_micmute_led_set);
+static int micmute_led_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + int state = brightness != LED_OFF; + int err; + + err = dell_micmute_led_set(state); + return err < 0 ? err : 0; +} + +static struct led_classdev micmute_led_cdev = { + .name = "platform::micmute", + .max_brightness = 1, + .brightness_set_blocking = micmute_led_set, + .default_trigger = "audio-micmute", +}; + static int __init dell_init(void) { struct calling_interface_token *token; @@ -2175,6 +2192,11 @@ static int __init dell_init(void)
dell_laptop_register_notifier(&dell_laptop_notifier);
+ micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE); + ret = led_classdev_register(&platform_device->dev, &micmute_led_cdev); + if (ret < 0) + goto fail_led; + if (acpi_video_get_backlight_type() != acpi_backlight_vendor) return 0;
@@ -2220,6 +2242,8 @@ static int __init dell_init(void) fail_get_brightness: backlight_device_unregister(dell_backlight_device); fail_backlight: + led_classdev_unregister(&micmute_led_cdev); +fail_led: dell_cleanup_rfkill(); fail_rfkill: platform_device_del(platform_device); @@ -2239,6 +2263,7 @@ static void __exit dell_exit(void) touchpad_led_exit(); kbd_led_exit(); backlight_device_unregister(dell_backlight_device); + led_classdev_unregister(&micmute_led_cdev); dell_cleanup_rfkill(); if (platform_device) { platform_device_unregister(platform_device);
In the upcoming change, the binding of audio mute / mic-mute LED controls will be switched with LED trigger. This patch is the last piece of preparation: adding the audio mute / mic-mute LED class devices to thinkpad_acpi driver.
Two devices, platform::mute and platform::micmute, will be added for controlling the mute LED and mic-mute LED, respectively. The new prefix "platform" is the suggestion by upstream for indicating the generic laptop attribute.
Also this selects CONFIG_LEDS_TRIGGERS and CONFIG_LEDS_TRIGGERS_AUDIO unconditionally. Strictly speaking, these aren't 100% mandatory, but leaving these manual selections would lead to a functional regression easily once after converting from the dynamic symbol binding to the LEDs trigger in a later patch.
Acked-by: Jacek Anaszewski jacek.anaszewski@gmail.com Acked-by: Pavel Machek pavel@ucw.cz Acked-by: Andy Shevchenko andy.shevchenko@gmail.com Acked-by: Henrique de Moraes Holschuh hmh@hmh.eng.br Acked-by: Pali Rohár pali.rohar@gmail.com Signed-off-by: Takashi Iwai tiwai@suse.de --- drivers/platform/x86/Kconfig | 2 + drivers/platform/x86/thinkpad_acpi.c | 57 +++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 9b9cc3cc33e9..87f70e8f4dd0 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -495,6 +495,8 @@ config THINKPAD_ACPI select NVRAM select NEW_LEDS select LEDS_CLASS + select LEDS_TRIGGERS + select LEDS_TRIGGER_AUDIO ---help--- This is a driver for the IBM and Lenovo ThinkPad laptops. It adds support for Fn-Fx key combinations, Bluetooth control, video diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index fde08a997557..3d2c1f5f22e2 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -9203,17 +9203,58 @@ int tpacpi_led_set(int whichled, bool on) } EXPORT_SYMBOL_GPL(tpacpi_led_set);
+static int tpacpi_led_mute_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + return tpacpi_led_set(TPACPI_LED_MUTE, brightness != LED_OFF); +} + +static int tpacpi_led_micmute_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + return tpacpi_led_set(TPACPI_LED_MICMUTE, brightness != LED_OFF); +} + +static struct led_classdev mute_led_cdev[] = { + [TPACPI_LED_MUTE] = { + .name = "platform::mute", + .max_brightness = 1, + .brightness_set_blocking = tpacpi_led_mute_set, + .default_trigger = "audio-mute", + }, + [TPACPI_LED_MICMUTE] = { + .name = "platform::micmute", + .max_brightness = 1, + .brightness_set_blocking = tpacpi_led_micmute_set, + .default_trigger = "audio-micmute", + }, +}; + static int mute_led_init(struct ibm_init_struct *iibm) { + static enum led_audio types[] = { + [TPACPI_LED_MUTE] = LED_AUDIO_MUTE, + [TPACPI_LED_MICMUTE] = LED_AUDIO_MICMUTE, + }; acpi_handle temp; - int i; + int i, err;
for (i = 0; i < TPACPI_LED_MAX; i++) { struct tp_led_table *t = &led_tables[i]; - if (ACPI_SUCCESS(acpi_get_handle(hkey_handle, t->name, &temp))) - mute_led_on_off(t, false); - else + if (ACPI_FAILURE(acpi_get_handle(hkey_handle, t->name, &temp))) { t->state = -ENODEV; + continue; + } + + mute_led_cdev[i].brightness = ledtrig_audio_get(types[i]); + err = led_classdev_register(&tpacpi_pdev->dev, &mute_led_cdev[i]); + if (err < 0) { + while (i--) { + if (led_tables[i].state >= 0) + led_classdev_unregister(&mute_led_cdev[i]); + } + return err; + } } return 0; } @@ -9222,8 +9263,12 @@ static void mute_led_exit(void) { int i;
- for (i = 0; i < TPACPI_LED_MAX; i++) - tpacpi_led_set(i, false); + for (i = 0; i < TPACPI_LED_MAX; i++) { + if (led_tables[i].state >= 0) { + led_classdev_unregister(&mute_led_cdev[i]); + tpacpi_led_set(i, false); + } + } }
static void mute_led_resume(void)
Now all relevant platform drivers are providing the LED audio trigger, we can switch the mute LED control with the LED trigger, finally.
For the mic-mute LED trigger, a common fixup function, snd_hda_gen_fixup_micmute_led(), is provided to be called for the corresponding quirk entries. This sets up the capture sync hook with ledtrig_audio_set() call appropriately.
For the mute LED trigger, which is done currently only for thinkpad_acpi, the call is replaced with ledtrig_audio_set() as well.
Overall, the beauty of the new implementation is that the whole ugly bindings with request_symbol() are dropped, and also that it provides more flexibility to users.
One potential behavior change by this patch is that the mute LED enum may be created on machines that actually have no LED device. In the former code, we did test-call and abort binding if the test failed. But with the LED-trigger binding, this test isn't possible, and the actual check is done in the LED class device side. So it's the downside of simpleness.
Also, note that the HD-audio codec driver doesn't select CONFIG_LEDS and co by itself. It's supposed to be selected by the platform drivers instead.
Acked-by: Jacek Anaszewski jacek.anaszewski@gmail.com Acked-by: Pavel Machek pavel@ucw.cz Acked-by: Pali Rohár pali.rohar@gmail.com Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/pci/hda/dell_wmi_helper.c | 48 --------------------------------- sound/pci/hda/hda_generic.c | 31 +++++++++++++++++++++ sound/pci/hda/hda_generic.h | 2 ++ sound/pci/hda/patch_realtek.c | 17 +++++------- sound/pci/hda/thinkpad_helper.c | 43 +++++------------------------ 5 files changed, 46 insertions(+), 95 deletions(-) delete mode 100644 sound/pci/hda/dell_wmi_helper.c
diff --git a/sound/pci/hda/dell_wmi_helper.c b/sound/pci/hda/dell_wmi_helper.c deleted file mode 100644 index bbd6c87a4ed6..000000000000 --- a/sound/pci/hda/dell_wmi_helper.c +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* Helper functions for Dell Mic Mute LED control; - * to be included from codec driver - */ - -#if IS_ENABLED(CONFIG_DELL_LAPTOP) -#include <linux/dell-led.h> - -static int (*dell_micmute_led_set_func)(int); - -static void dell_micmute_update(struct hda_codec *codec) -{ - struct hda_gen_spec *spec = codec->spec; - - dell_micmute_led_set_func(spec->micmute_led.led_value); -} - -static void alc_fixup_dell_wmi(struct hda_codec *codec, - const struct hda_fixup *fix, int action) -{ - bool removefunc = false; - - if (action == HDA_FIXUP_ACT_PROBE) { - if (!dell_micmute_led_set_func) - dell_micmute_led_set_func = symbol_request(dell_micmute_led_set); - if (!dell_micmute_led_set_func) { - codec_warn(codec, "Failed to find dell wmi symbol dell_micmute_led_set\n"); - return; - } - - removefunc = (dell_micmute_led_set_func(false) < 0) || - (snd_hda_gen_add_micmute_led(codec, - dell_micmute_update) < 0); - } - - if (dell_micmute_led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) { - symbol_put(dell_micmute_led_set); - dell_micmute_led_set_func = NULL; - } -} - -#else /* CONFIG_DELL_LAPTOP */ -static void alc_fixup_dell_wmi(struct hda_codec *codec, - const struct hda_fixup *fix, int action) -{ -} - -#endif /* CONFIG_DELL_LAPTOP */ diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 276150f29cda..4095cd7c56c6 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -29,6 +29,7 @@ #include <linux/string.h> #include <linux/bitops.h> #include <linux/module.h> +#include <linux/leds.h> #include <sound/core.h> #include <sound/jack.h> #include <sound/tlv.h> @@ -4035,6 +4036,36 @@ int snd_hda_gen_add_micmute_led(struct hda_codec *codec, } EXPORT_SYMBOL_GPL(snd_hda_gen_add_micmute_led);
+#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO) +static void call_ledtrig_micmute(struct hda_codec *codec) +{ + struct hda_gen_spec *spec = codec->spec; + + ledtrig_audio_set(LED_AUDIO_MICMUTE, + spec->micmute_led.led_value ? LED_ON : LED_OFF); +} +#endif + +/** + * snd_hda_gen_fixup_micmute_led - A fixup for mic-mute LED trigger + * + * Pass this function to the quirk entry if another driver supports the + * audio mic-mute LED trigger. Then this will bind the mixer capture switch + * change with the LED. + * + * Note that this fixup has to be called after other fixup that sets + * cap_sync_hook. Otherwise the chaining wouldn't work. + */ +void snd_hda_gen_fixup_micmute_led(struct hda_codec *codec, + const struct hda_fixup *fix, int action) +{ +#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO) + if (action == HDA_FIXUP_ACT_PROBE) + snd_hda_gen_add_micmute_led(codec, call_ledtrig_micmute); +#endif +} +EXPORT_SYMBOL_GPL(snd_hda_gen_fixup_micmute_led); + /* * parse digital I/Os and set up NIDs in BIOS auto-parse mode */ diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h index 10123664fa61..78d77042b05a 100644 --- a/sound/pci/hda/hda_generic.h +++ b/sound/pci/hda/hda_generic.h @@ -357,5 +357,7 @@ int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin);
int snd_hda_gen_add_micmute_led(struct hda_codec *codec, void (*hook)(struct hda_codec *)); +void snd_hda_gen_fixup_micmute_led(struct hda_codec *codec, + const struct hda_fixup *fix, int action);
#endif /* __SOUND_HDA_GENERIC_H */ diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index fa61674a5605..993d34c141c2 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -5368,9 +5368,6 @@ static void alc_fixup_thinkpad_acpi(struct hda_codec *codec, hda_fixup_thinkpad_acpi(codec, fix, action); }
-/* for dell wmi mic mute led */ -#include "dell_wmi_helper.c" - /* for alc295_fixup_hp_top_speakers */ #include "hp_x360_helper.c"
@@ -5448,7 +5445,7 @@ enum { ALC292_FIXUP_TPT440_DOCK, ALC292_FIXUP_TPT440, ALC283_FIXUP_HEADSET_MIC, - ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED, + ALC255_FIXUP_MIC_MUTE_LED, ALC282_FIXUP_ASPIRE_V5_PINS, ALC280_FIXUP_HP_GPIO4, ALC286_FIXUP_HP_GPIO_LED, @@ -5740,7 +5737,7 @@ static const struct hda_fixup alc269_fixups[] = { .type = HDA_FIXUP_FUNC, .v.func = alc_fixup_headset_mode, .chained = true, - .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED + .chain_id = ALC255_FIXUP_MIC_MUTE_LED }, [ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = { .type = HDA_FIXUP_FUNC, @@ -5966,7 +5963,7 @@ static const struct hda_fixup alc269_fixups[] = { .type = HDA_FIXUP_FUNC, .v.func = alc_fixup_headset_mode_alc255, .chained = true, - .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED + .chain_id = ALC255_FIXUP_MIC_MUTE_LED }, [ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC] = { .type = HDA_FIXUP_FUNC, @@ -6001,9 +5998,9 @@ static const struct hda_fixup alc269_fixups[] = { { }, }, }, - [ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED] = { + [ALC255_FIXUP_MIC_MUTE_LED] = { .type = HDA_FIXUP_FUNC, - .v.func = alc_fixup_dell_wmi, + .v.func = snd_hda_gen_fixup_micmute_led, }, [ALC282_FIXUP_ASPIRE_V5_PINS] = { .type = HDA_FIXUP_PINS, @@ -6062,7 +6059,7 @@ static const struct hda_fixup alc269_fixups[] = { .type = HDA_FIXUP_FUNC, .v.func = alc_fixup_headset_mode_dell_alc288, .chained = true, - .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED + .chain_id = ALC255_FIXUP_MIC_MUTE_LED }, [ALC288_FIXUP_DELL1_MIC_NO_PRESENCE] = { .type = HDA_FIXUP_PINS, @@ -6719,7 +6716,7 @@ static const struct hda_model_fixup alc269_fixup_models[] = { {.id = ALC255_FIXUP_DELL2_MIC_NO_PRESENCE, .name = "alc255-dell2"}, {.id = ALC293_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "alc293-dell1"}, {.id = ALC283_FIXUP_HEADSET_MIC, .name = "alc283-headset"}, - {.id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED, .name = "alc255-dell-mute"}, + {.id = ALC255_FIXUP_MIC_MUTE_LED, .name = "alc255-dell-mute"}, {.id = ALC282_FIXUP_ASPIRE_V5_PINS, .name = "aspire-v5"}, {.id = ALC280_FIXUP_HP_GPIO4, .name = "hp-gpio4"}, {.id = ALC286_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"}, diff --git a/sound/pci/hda/thinkpad_helper.c b/sound/pci/hda/thinkpad_helper.c index 568575b72f2f..4089feb8c68e 100644 --- a/sound/pci/hda/thinkpad_helper.c +++ b/sound/pci/hda/thinkpad_helper.c @@ -3,12 +3,11 @@ * to be included from codec driver */
-#if IS_ENABLED(CONFIG_THINKPAD_ACPI) +#if IS_ENABLED(CONFIG_THINKPAD_ACPI) && IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
#include <linux/acpi.h> -#include <linux/thinkpad_acpi.h> +#include <linux/leds.h>
-static int (*led_set_func)(int, bool); static void (*old_vmaster_hook)(void *, int);
static bool is_thinkpad(struct hda_codec *codec) @@ -23,50 +22,20 @@ static void update_tpacpi_mute_led(void *private_data, int enabled) if (old_vmaster_hook) old_vmaster_hook(private_data, enabled);
- if (led_set_func) - led_set_func(TPACPI_LED_MUTE, !enabled); -} - -static void update_tpacpi_micmute(struct hda_codec *codec) -{ - struct hda_gen_spec *spec = codec->spec; - - led_set_func(TPACPI_LED_MICMUTE, spec->micmute_led.led_value); + ledtrig_audio_set(LED_AUDIO_MUTE, enabled ? LED_OFF : LED_ON); }
static void hda_fixup_thinkpad_acpi(struct hda_codec *codec, const struct hda_fixup *fix, int action) { struct hda_gen_spec *spec = codec->spec; - bool removefunc = false;
if (action == HDA_FIXUP_ACT_PROBE) { if (!is_thinkpad(codec)) return; - if (!led_set_func) - led_set_func = symbol_request(tpacpi_led_set); - if (!led_set_func) { - codec_warn(codec, - "Failed to find thinkpad-acpi symbol tpacpi_led_set\n"); - return; - } - - removefunc = true; - if (led_set_func(TPACPI_LED_MUTE, false) >= 0) { - old_vmaster_hook = spec->vmaster_mute.hook; - spec->vmaster_mute.hook = update_tpacpi_mute_led; - removefunc = false; - } - if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0 && - !snd_hda_gen_add_micmute_led(codec, - update_tpacpi_micmute)) - removefunc = false; - } - - if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) { - symbol_put(tpacpi_led_set); - led_set_func = NULL; - old_vmaster_hook = NULL; + old_vmaster_hook = spec->vmaster_mute.hook; + spec->vmaster_mute.hook = update_tpacpi_mute_led; + snd_hda_gen_fixup_micmute_led(codec, fix, action); } }
Since we've switched to the LED trigger for binding with HD-audio, we can drop the exported function as well as the whole linux/dell-led.h.
Acked-by: Jacek Anaszewski jacek.anaszewski@gmail.com Acked-by: Pavel Machek pavel@ucw.cz Acked-by: Andy Shevchenko andy.shevchenko@gmail.com Acked-by: Pali Rohár pali.rohar@gmail.com Signed-off-by: Takashi Iwai tiwai@suse.de --- drivers/platform/x86/dell-laptop.c | 22 +++++----------------- include/linux/dell-led.h | 7 ------- 2 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 include/linux/dell-led.h
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c index 0db2dbf7b0d1..fb071e6a5058 100644 --- a/drivers/platform/x86/dell-laptop.c +++ b/drivers/platform/x86/dell-laptop.c @@ -29,7 +29,6 @@ #include <linux/mm.h> #include <linux/i8042.h> #include <linux/debugfs.h> -#include <linux/dell-led.h> #include <linux/seq_file.h> #include <acpi/video.h> #include "dell-rbtn.h" @@ -2109,17 +2108,17 @@ static struct notifier_block dell_laptop_notifier = { .notifier_call = dell_laptop_notifier_call, };
-int dell_micmute_led_set(int state) +static int micmute_led_set(struct led_classdev *led_cdev, + enum led_brightness brightness) { struct calling_interface_buffer buffer; struct calling_interface_token *token; + int state = brightness != LED_OFF;
if (state == 0) token = dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE); - else if (state == 1) - token = dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE); else - return -EINVAL; + token = dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE);
if (!token) return -ENODEV; @@ -2127,18 +2126,7 @@ int dell_micmute_led_set(int state) dell_fill_request(&buffer, token->location, token->value, 0, 0); dell_send_request(&buffer, CLASS_TOKEN_WRITE, SELECT_TOKEN_STD);
- return state; -} -EXPORT_SYMBOL_GPL(dell_micmute_led_set); - -static int micmute_led_set(struct led_classdev *led_cdev, - enum led_brightness brightness) -{ - int state = brightness != LED_OFF; - int err; - - err = dell_micmute_led_set(state); - return err < 0 ? err : 0; + return 0; }
static struct led_classdev micmute_led_cdev = { diff --git a/include/linux/dell-led.h b/include/linux/dell-led.h deleted file mode 100644 index 92521471517f..000000000000 --- a/include/linux/dell-led.h +++ /dev/null @@ -1,7 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __DELL_LED_H__ -#define __DELL_LED_H__ - -int dell_micmute_led_set(int on); - -#endif
Since we've switched to the LED trigger for binding with HD-audio, we can drop the exported function as well as the whole linux/thinkpad_acpi.h.
The own TPACPI_LED_MUTE and TPACPI_LED_MICMUTE definitions are replaced with the identical ones for LEDS, i.e. LED_AUDIO_MUTE and LED_AUDIO_MICMUTE, respectively. They are no longer needed as referred only locally.
Acked-by: Jacek Anaszewski jacek.anaszewski@gmail.com Acked-by: Pavel Machek pavel@ucw.cz Acked-by: Andy Shevchenko andy.shevchenko@gmail.com Acked-by: Henrique de Moraes Holschuh hmh@hmh.eng.br Acked-by: Pali Rohár pali.rohar@gmail.com Signed-off-by: Takashi Iwai tiwai@suse.de --- drivers/platform/x86/thinkpad_acpi.c | 30 ++++++++++------------------ include/linux/thinkpad_acpi.h | 16 --------------- 2 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 include/linux/thinkpad_acpi.h
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 3d2c1f5f22e2..21ffb961585a 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -81,7 +81,6 @@ #include <linux/acpi.h> #include <linux/pci_ids.h> #include <linux/power_supply.h> -#include <linux/thinkpad_acpi.h> #include <sound/core.h> #include <sound/control.h> #include <sound/initval.h> @@ -9150,6 +9149,7 @@ static struct ibm_struct fan_driver_data = { * Mute LED subdriver */
+#define TPACPI_LED_MAX 2
struct tp_led_table { acpi_string name; @@ -9158,13 +9158,13 @@ struct tp_led_table { int state; };
-static struct tp_led_table led_tables[] = { - [TPACPI_LED_MUTE] = { +static struct tp_led_table led_tables[TPACPI_LED_MAX] = { + [LED_AUDIO_MUTE] = { .name = "SSMS", .on_value = 1, .off_value = 0, }, - [TPACPI_LED_MICMUTE] = { + [LED_AUDIO_MICMUTE] = { .name = "MMTS", .on_value = 2, .off_value = 0, @@ -9189,40 +9189,36 @@ static int mute_led_on_off(struct tp_led_table *t, bool state) return state; }
-int tpacpi_led_set(int whichled, bool on) +static int tpacpi_led_set(int whichled, bool on) { struct tp_led_table *t;
- if (whichled < 0 || whichled >= TPACPI_LED_MAX) - return -EINVAL; - t = &led_tables[whichled]; if (t->state < 0 || t->state == on) return t->state; return mute_led_on_off(t, on); } -EXPORT_SYMBOL_GPL(tpacpi_led_set);
static int tpacpi_led_mute_set(struct led_classdev *led_cdev, enum led_brightness brightness) { - return tpacpi_led_set(TPACPI_LED_MUTE, brightness != LED_OFF); + return tpacpi_led_set(LED_AUDIO_MUTE, brightness != LED_OFF); }
static int tpacpi_led_micmute_set(struct led_classdev *led_cdev, enum led_brightness brightness) { - return tpacpi_led_set(TPACPI_LED_MICMUTE, brightness != LED_OFF); + return tpacpi_led_set(LED_AUDIO_MICMUTE, brightness != LED_OFF); }
-static struct led_classdev mute_led_cdev[] = { - [TPACPI_LED_MUTE] = { +static struct led_classdev mute_led_cdev[TPACPI_LED_MAX] = { + [LED_AUDIO_MUTE] = { .name = "platform::mute", .max_brightness = 1, .brightness_set_blocking = tpacpi_led_mute_set, .default_trigger = "audio-mute", }, - [TPACPI_LED_MICMUTE] = { + [LED_AUDIO_MICMUTE] = { .name = "platform::micmute", .max_brightness = 1, .brightness_set_blocking = tpacpi_led_micmute_set, @@ -9232,10 +9228,6 @@ static struct led_classdev mute_led_cdev[] = {
static int mute_led_init(struct ibm_init_struct *iibm) { - static enum led_audio types[] = { - [TPACPI_LED_MUTE] = LED_AUDIO_MUTE, - [TPACPI_LED_MICMUTE] = LED_AUDIO_MICMUTE, - }; acpi_handle temp; int i, err;
@@ -9246,7 +9238,7 @@ static int mute_led_init(struct ibm_init_struct *iibm) continue; }
- mute_led_cdev[i].brightness = ledtrig_audio_get(types[i]); + mute_led_cdev[i].brightness = ledtrig_audio_get(i); err = led_classdev_register(&tpacpi_pdev->dev, &mute_led_cdev[i]); if (err < 0) { while (i--) { diff --git a/include/linux/thinkpad_acpi.h b/include/linux/thinkpad_acpi.h deleted file mode 100644 index 9fb317970c01..000000000000 --- a/include/linux/thinkpad_acpi.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __THINKPAD_ACPI_H__ -#define __THINKPAD_ACPI_H__ - -/* These two functions return 0 if success, or negative error code - (e g -ENODEV if no led present) */ - -enum { - TPACPI_LED_MUTE, - TPACPI_LED_MICMUTE, - TPACPI_LED_MAX, -}; - -int tpacpi_led_set(int whichled, bool on); - -#endif
On Thu, 29 Nov 2018 08:31:25 +0100, Takashi Iwai wrote:
Hi,
this is revised patch series for adding a new LED trigger audio-mute and audio-micmute, and converting the HD-audio driver and the platform drivers to use the LED trigger instead of the ugly direct dynamic symbol binding.
v2 series addressed a couple of issues Andy suggested, and changed the led class dev names to "platform::xxx" as discussed in the previous thread.
The latest version of patches are found in topic/leds-trigger branch in my sound git tree. git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
As these are cross-tree patches, the branch above is based cleanly on v4.20-rc3. From now on, it'll stay as an immutable branch, so feel free to merge into other trees.
FYI, I merged to for-next branch now.
Takashi
participants (1)
-
Takashi Iwai