leds: trigger: audio: Add audio jack plugging indicator led
PATCH 1/2 leds: trigger: audio: Add audio jack plugging indicator led
On the Lenovo P520 front panel, there is a headset plugging indicator led. According to LENOVO's requirement, this led should be on if the front headset audio jack is plugged, otherwise the led should be off.
We tested with windows, if we plugged a headphone/headset in that jack, the led was on, if we removed the headphone/headset from that jack, the led was off.
Here we add JACKPLUG led in the ledtrig_audio, then we could call ledtrig_audio_set() in the alsa driver to control that led.
--- drivers/leds/trigger/Kconfig | 4 ++-- drivers/leds/trigger/ledtrig-audio.c | 7 +++++-- include/linux/leds.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-)
drivers/leds/trigger/Kconfig +2 -2
@@ -138,10 +138,10 @@ config LEDS_TRIGGER_PATTERN If unsure, say N config LEDS_TRIGGER_AUDIO - tristate "Audio Mute LED Trigger" + tristate "Audio Mute and Jack Plugging LED Trigger" help This allows LEDs to be controlled by audio drivers for following - the audio mute and mic-mute changes. + the audio mute, mic-mute and jack plugging changes. If unsure, say N endif # LEDS_TRIGGERS
drivers/leds/trigger/ledtrig-audio.c +5 -2
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 // -// Audio Mute LED trigger +// Audio Mute And Jack Plugging LED trigger // #include <linux/kernel.h>
@@ -29,6 +29,8 @@ static int __init ledtrig_audio_init(void) &ledtrig_audio[LED_AUDIO_MUTE]);led_trigger_register_simple ("audio-micmute" , &ledtrig_audio[LED_AUDIO_MICMUTE ]); +led_trigger_register_simple ("audio-jackplug" , + &ledtrig_audio[LED_AUDIO_JACKPLUG ]);return 0 ; }module_init (ledtrig_audio_init);
@@ -37,8 +39,9 @@ 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 ]); +led_trigger_unregister_simple (ledtrig_audio[LED_AUDIO_JACKPLUG ]); }module_exit (ledtrig_audio_exit); -MODULE_DESCRIPTION ("LED trigger for audio mute control" ); +MODULE_DESCRIPTION ("LED trigger for audio mute and jack plugging control" );MODULE_LICENSE ("GPL v2" );
include/linux/leds.h +1 -0
@@ -584,6 +584,7 @@ struct led_pattern {enum led_audio {LED_AUDIO_MUTE ,/* master mute LED */ LED_AUDIO_MICMUTE ,/* mic mute LED */ +LED_AUDIO_JACKPLUG ,/* audio jack plug indicator LED */ NUM_AUDIO_LEDS };
Signature · 1 line
2.17.1
PATCH 2/2 ALSA: hda/realtek - enable jack plugging indicator led on LENOVO P520
There is a headset jack plugging indicator led on the LENOVO P520 front panel, we expect this led to be on if we plug a headphone or headset in that jack, and expect this led to be off if there is nothing plugged in that jack.
After adding the JACKPLUG led in the ledtrig_audio.c, we could add led control in the hda audio driver via ledtrig API.
On the LENOVO P520, the jack indicator led connects to the alc233 gpio2, we hook a callback in the unsol event handler to update this led.
--- sound/pci/hda/hda_generic.c | 26 ++++++++++++++++++++++ sound/pci/hda/hda_generic.h | 3 +++ sound/pci/hda/patch_realtek.c | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)
sound/pci/hda/hda_generic.c +26 -0
@@ -3888,6 +3888,32 @@ static int parse_mic_boost(struct hda_codec *codec) }#ifdef CONFIG_SND_HDA_GENERIC_LEDS +/** +* snd_dha_gen_add_jackplug_led_cdev - Create a LED classdev and enable as jack plugging LED +* @codec: the HDA codec +* @callback: the callback for LED classdev brightness_set_blocking +*/ +int snd_hda_gen_add_jackplug_led_cdev (struct hda_codec *codec, +int (*callback)(struct led_classdev *, +enum led_brightness )) +{ +struct led_classdev *cdev; + + cdev =devm_kzalloc (&codec->core.dev,sizeof (*cdev),GFP_KERNEL ); +if (!cdev) +return -ENOMEM ; + + cdev->name ="hda::jackplug" ; + cdev->max_brightness =1 ; + cdev->default_trigger ="audio-jackplug" ; + cdev->brightness_set_blocking = callback; + cdev->brightness =ledtrig_audio_get (LED_AUDIO_JACKPLUG ); + cdev->flags =LED_CORE_SUSPENDRESUME ; + +return devm_led_classdev_register (&codec->core.dev, cdev); +} +EXPORT_SYMBOL_GPL (snd_hda_gen_add_jackplug_led_cdev); +/* * vmaster mute LED hook helpers */
sound/pci/hda/hda_generic.h +3 -0
@@ -360,5 +360,8 @@ int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,int snd_hda_gen_add_micmute_led_cdev (struct hda_codec *codec,int (*callback)(struct led_classdev *,enum led_brightness )); +int snd_hda_gen_add_jackplug_led_cdev (struct hda_codec *codec, +int (*callback)(struct led_classdev *, +enum led_brightness ));#endif /* __SOUND_HDA_GENERIC_H */
sound/pci/hda/patch_realtek.c +42 -0
74 lines not on this page · raw message
Signature · 1 line
2.17.1
Please ignore this patchset, our QA retested this led under Windows, the led was always on after booting no matter users plug in or plug out.
If the led could change under Windows in future, I will resend the patchset.
Thanks,
Hui.
Quoted 79 lines · Hui Wang
On the Lenovo P520 front panel, there is a headset plugging indicator led. According to LENOVO's requirement, this led should be on if the front headset audio jack is plugged, otherwise the led should be off.
We tested with windows, if we plugged a headphone/headset in that jack, the led was on, if we removed the headphone/headset from that jack, the led was off.
Here we add JACKPLUG led in the
ledtrig_audio, then we could callledtrig_audio_set()in the alsa driver to control that led.Signed-off-by Hui Wang <[email protected]>--- drivers/leds/trigger/Kconfig | 4 ++-- drivers/leds/trigger/ledtrig-audio.c | 7 +++++-- include/linux/leds.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-)drivers/leds/trigger/Kconfig +2
-2@@ -138,10 +138,10 @@ config LEDS_TRIGGER_PATTERN If unsure, say N config LEDS_TRIGGER_AUDIO - tristate "Audio Mute LED Trigger" + tristate "Audio Mute and Jack Plugging LED Trigger" help This allows LEDs to be controlled by audio drivers for following - the audio mute and mic-mute changes. + the audio mute, mic-mute and jack plugging changes. If unsure, say N endif # LEDS_TRIGGERSdrivers/leds/trigger/ledtrig-audio.c +5
-2@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 // -// Audio Mute LED trigger +// Audio Mute And Jack Plugging LED trigger // #include <linux/kernel.h> @@ -29,6 +29,8 @@ static int __init ledtrig_audio_init(void) &ledtrig_audio[LED_AUDIO_MUTE]);led_trigger_register_simple ("audio-micmute" , &ledtrig_audio[LED_AUDIO_MICMUTE ]); +led_trigger_register_simple ("audio-jackplug" , + &ledtrig_audio[LED_AUDIO_JACKPLUG ]);return 0 ; }module_init (ledtrig_audio_init);@@ -37,8 +39,9 @@ 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 ]); +led_trigger_unregister_simple (ledtrig_audio[LED_AUDIO_JACKPLUG ]); }module_exit (ledtrig_audio_exit); -MODULE_DESCRIPTION ("LED trigger for audio mute control" ); +MODULE_DESCRIPTION ("LED trigger for audio mute and jack plugging control" );MODULE_LICENSE ("GPL v2" );include/linux/leds.h +1
-0@@ -584,6 +584,7 @@ struct led_pattern {enum led_audio {LED_AUDIO_MUTE ,/* master mute LED */ LED_AUDIO_MICMUTE ,/* mic mute LED */ +LED_AUDIO_JACKPLUG ,/* audio jack plug indicator LED */ NUM_AUDIO_LEDS };