From patchwork Wed Sep 14 12:15:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Wassenberg X-Patchwork-Id: 9331307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 00DC860231 for ; Wed, 14 Sep 2016 12:16:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5A1F29D2A for ; Wed, 14 Sep 2016 12:16:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D985D29D40; Wed, 14 Sep 2016 12:16:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79A5129D2A for ; Wed, 14 Sep 2016 12:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754710AbcINMQ1 (ORCPT ); Wed, 14 Sep 2016 08:16:27 -0400 Received: from a.mx.secunet.com ([62.96.220.36]:48123 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751168AbcINMQ1 (ORCPT ); Wed, 14 Sep 2016 08:16:27 -0400 Received: from localhost (alg1 [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id D81601A075F; Wed, 14 Sep 2016 14:16:18 +0200 (CEST) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 5pWao3QlTuyU; Wed, 14 Sep 2016 14:16:15 +0200 (CEST) Received: from mail-essen-01.secunet.de (unknown [10.53.40.204]) by a.mx.secunet.com (Postfix) with ESMTP id 4A67E1A075D; Wed, 14 Sep 2016 14:16:15 +0200 (CEST) Received: from [10.182.7.39] (10.182.7.39) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server (TLS) id 14.3.301.0; Wed, 14 Sep 2016 14:16:02 +0200 From: Dennis Wassenberg Subject: [PATCH v2 2/2] hda: thinkpad_helper: Add support for hid-lenovo LED control Organization: secunet Security Networks To: , , , Takashi Iwai , , Benjamin Tissoires , "Andrew Duggan" , , , , , Message-ID: <433b6428-8ef3-fc7a-86ba-4cbcda7f12fd@secunet.com> Date: Wed, 14 Sep 2016 14:15:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-Originating-IP: [10.182.7.39] X-G-Data-MailSecurity-for-Exchange-SpamLevel: 0 X-G-Data-MailSecurity-for-Exchange-SpamFilter: 0; 1; str=0001.0A0C0208.57D93F94.01AE,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-G-Data-MailSecurity-for-Exchange-State: 0 X-G-Data-MailSecurity-for-Exchange-Error: 0 X-G-Data-MailSecurity-for-Exchange-Sender: 32 X-G-Data-MailSecurity-for-Exchange-Server: d65e63f7-5c15-413f-8f63-c0d707471c93 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 X-G-Data-MailSecurity-for-Exchange-Guid: 111EEBB7-1893-40E3-A96D-BFE0ADE16CD0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make the thinkpad_helper able to support not only led control over acpi with thinkpad_acpi driver but also led control over hid-lenovo. The hid-lenovo driver adapted the led control api of thinkpad_acpi. Make the thinkpad_acpi and hid-lenovo able to work combined to support connected Lenovo USB keyboards at Lenovo Thinkpad devices. Signed-off-by: Dennis Wassenberg --- Changes v1 -> v2 (suggested by Takashi Iwai): * Adapt to not rename fixup_thinkpad_acpi to fixup_thinkpad * Made sure that it works even with one of kconfigs is disabled sound/pci/hda/thinkpad_helper.c | 182 +++++++++++++++++++++++++++++++--------- 1 file changed, 144 insertions(+), 38 deletions(-) } #endif /* CONFIG_THINKPAD_ACPI */ + diff --git a/sound/pci/hda/thinkpad_helper.c b/sound/pci/hda/thinkpad_helper.c index f0955fd..0d98624 100644 --- a/sound/pci/hda/thinkpad_helper.c +++ b/sound/pci/hda/thinkpad_helper.c @@ -1,83 +1,188 @@ /* Helper functions for Thinkpad LED control; * to be included from codec driver + * + * These helper functions include both LED control over thinkpad_acpi and + * hid-lenovo */ -#if IS_ENABLED(CONFIG_THINKPAD_ACPI) +#if IS_ENABLED(CONFIG_THINKPAD_ACPI) || IS_ENABLED(CONFIG_HID_LENOVO) #include +#include #include -static int (*led_set_func)(int, bool); +static int (*led_set_func_tpacpi)(int, bool); +static int (*led_set_func_hid_lenovo)(int, bool); static void (*old_vmaster_hook)(void *, int); static bool is_thinkpad(struct hda_codec *codec) { + return (codec->core.subsystem_id >> 16 == 0x17aa); +} + +static bool is_thinkpad_acpi(struct hda_codec *codec) +{ return (codec->core.subsystem_id >> 16 == 0x17aa) && (acpi_dev_found("LEN0068") || acpi_dev_found("IBM0068")); } -static void update_tpacpi_mute_led(void *private_data, int enabled) +static void update_thinkpad_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); +#if IS_ENABLED(CONFIG_THINKPAD_ACPI) + if (led_set_func_tpacpi) + led_set_func_tpacpi(TPACPI_LED_MUTE, !enabled); +#endif +#if IS_ENABLED(CONFIG_HID_LENOVO) + if (led_set_func_hid_lenovo) + led_set_func_hid_lenovo(HID_LENOVO_LED_MUTE, !enabled); +#endif } -static void update_tpacpi_micmute_led(struct hda_codec *codec, + + +static void update_thinkpad_micmute_led(struct hda_codec *codec, struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - if (!ucontrol || !led_set_func) + if (!ucontrol) return; if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) { /* TODO: How do I verify if it's a mono or stereo here? */ bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]; - led_set_func(TPACPI_LED_MICMUTE, !val); +#if IS_ENABLED(CONFIG_THINKPAD_ACPI) + if (led_set_func_tpacpi) + led_set_func_tpacpi(TPACPI_LED_MICMUTE, !val); +#endif +#if IS_ENABLED(CONFIG_HID_LENOVO) + if (led_set_func_hid_lenovo) + led_set_func_hid_lenovo(HID_LENOVO_LED_MICMUTE, !val); +#endif } } -static void hda_fixup_thinkpad_acpi(struct hda_codec *codec, - const struct hda_fixup *fix, int action) +#if IS_ENABLED(CONFIG_THINKPAD_ACPI) +static int hda_fixup_thinkpad_acpi_prepare(struct hda_codec *codec) { struct hda_gen_spec *spec = codec->spec; - bool removefunc = false; + int ret = -ENXIO; - 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; - } + if (!is_thinkpad(codec)) + return -ENODEV; + if (!is_thinkpad_acpi(codec)) + return -ENODEV; + if (!led_set_func_tpacpi) + led_set_func_tpacpi = symbol_request(tpacpi_led_set); + if (!led_set_func_tpacpi) { + codec_warn(codec, + "Failed to find thinkpad-acpi symbol tpacpi_led_set\n"); + return -ENOENT; + } - 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) { - if (spec->num_adc_nids > 1) - codec_dbg(codec, - "Skipping micmute LED control due to several ADCs"); - else { - spec->cap_sync_hook = update_tpacpi_micmute_led; - removefunc = false; - } + if (led_set_func_tpacpi(TPACPI_LED_MUTE, false) >= 0) { + old_vmaster_hook = spec->vmaster_mute.hook; + spec->vmaster_mute.hook = update_thinkpad_mute_led; + ret = 0; + } + + if (led_set_func_tpacpi(TPACPI_LED_MICMUTE, false) >= 0) { + if (spec->num_adc_nids > 1) + codec_dbg(codec, + "Skipping micmute LED control due to several ADCs"); + else { + spec->cap_sync_hook = update_thinkpad_micmute_led; + ret = 0; } } - if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) { + return ret; +} + +static void hda_fixup_thinkpad_acpi_setup(struct hda_codec *codec, int action) +{ + int ret = 0; + + if (action == HDA_FIXUP_ACT_PROBE) { + ret = hda_fixup_thinkpad_acpi_prepare(codec); + } + + if (led_set_func_tpacpi && + (action == HDA_FIXUP_ACT_FREE || ret)) { + symbol_put(tpacpi_led_set); - led_set_func = NULL; + led_set_func_tpacpi = NULL; + old_vmaster_hook = NULL; + } +} +#else +static void hda_fixup_thinkpad_acpi_setup(struct hda_codec *codec, int action) +{ + return 0; +} +#endif + +#if IS_ENABLED(CONFIG_HID_LENOVO) +static int hda_fixup_thinkpad_hid_prepare(struct hda_codec *codec) +{ + struct hda_gen_spec *spec = codec->spec; + int ret = 0; + + if (!is_thinkpad(codec)) + return -ENODEV; + if (!led_set_func_hid_lenovo) + led_set_func_hid_lenovo = symbol_request(hid_lenovo_led_set); + if (!led_set_func_hid_lenovo) { + codec_warn(codec, + "Failed to find hid-lenovo symbol hid_lenovo_led_set\n"); + return -ENOENT; + } + + if (update_thinkpad_mute_led != spec->vmaster_mute.hook) + old_vmaster_hook = spec->vmaster_mute.hook; + + /* do not remove hook if setting delay does not work currently because + * it is a usb hid devices which is not connected right now + * maybe is will be connected later + */ + led_set_func_hid_lenovo(HID_LENOVO_LED_MUTE, false); + spec->vmaster_mute.hook = update_thinkpad_mute_led; + + led_set_func_hid_lenovo(HID_LENOVO_LED_MICMUTE, false); + spec->cap_sync_hook = update_thinkpad_micmute_led; + + return ret; +} + +static void hda_fixup_thinkpad_hid_setup(struct hda_codec *codec, int action) +{ + int ret = 0; + + if (action == HDA_FIXUP_ACT_PROBE) { + ret = hda_fixup_thinkpad_hid_prepare(codec); + } + + if (led_set_func_hid_lenovo && + (action == HDA_FIXUP_ACT_FREE || ret)) { + + symbol_put(hid_lenovo_led_set); + led_set_func_hid_lenovo = NULL; old_vmaster_hook = NULL; } } +#else +static void hda_fixup_thinkpad_hid_setup(struct hda_codec *codec, int action) +{ +} +#endif + +/** this fixup is not for acpi case only, it will handle hid-lenovo as well */ +static void hda_fixup_thinkpad_acpi(struct hda_codec *codec, + const struct hda_fixup *fix, int action) +{ + hda_fixup_thinkpad_acpi_setup(codec, action); + hda_fixup_thinkpad_hid_setup(codec, action); +} #else /* CONFIG_THINKPAD_ACPI */ @@ -87,3 +192,4 @@ static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,