From patchwork Wed Dec 16 01:39:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E695C4361B for ; Wed, 16 Dec 2020 01:39:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F12C82311B for ; Wed, 16 Dec 2020 01:39:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725764AbgLPBjy (ORCPT ); Tue, 15 Dec 2020 20:39:54 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:19361 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725275AbgLPBjy (ORCPT ); Tue, 15 Dec 2020 20:39:54 -0500 Date: Wed, 16 Dec 2020 01:39:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082752; bh=G5Q/dImlhjgPdFyvZPfG1F6/jzaFuuMWOBF1F76yj5I=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=HTDpsMfduobjG5FeILV6QqFZxj2C2fVtqmJo1LEbF/EHOIy0ubcEifbtka3zfOkV7 WAUFdAWnA50e/1PxCABYmMEjoSLnW5ZwciH91I8Kt8JR31RjCztvyQ2jZi6N+YqALM pibl5xIBz1wXuBJjyC/CTKOtQOB1Tc3sr7F1CU/w= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 01/24] platform/x86: ideapad-laptop: remove unnecessary dev_set_drvdata() call Message-ID: <20201216013857.360987-2-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The driver core already sets the driver specific data on bind failure or removal. Thus the call is unnecessary. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 7598cd46cf60..9ed5bd8d955b 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -1071,7 +1071,6 @@ static int ideapad_acpi_remove(struct platform_device *pdev) ideapad_input_exit(priv); ideapad_debugfs_exit(priv); ideapad_sysfs_exit(priv); - dev_set_drvdata(&pdev->dev, NULL); return 0; } From patchwork Wed Dec 16 01:39:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35146C2BB48 for ; Wed, 16 Dec 2020 01:39:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E85B623109 for ; Wed, 16 Dec 2020 01:39:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725275AbgLPBjz (ORCPT ); Tue, 15 Dec 2020 20:39:55 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:32023 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725550AbgLPBjz (ORCPT ); Tue, 15 Dec 2020 20:39:55 -0500 Date: Wed, 16 Dec 2020 01:39:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082753; bh=sEEwi4cgN99o5qj+ZeyAM9IlOacYuj+VTMwAtdAanac=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=Su1NWBwCh6pHu5zezjIP7lDKPW5M4JKOJ98Mzws+y6L2hxOz/I2AjGLMoaPNiVymA UBbawcPMVkDQEFfzPsMdjJx2YDKggS/DHIQPocKVBVXzQN+OoRL+012tMPK8bbuKVt KpXyg5kzP3cPNtS83x/w7T/5sC8xOTc2OASv7d0M= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 02/24] platform/x86: ideapad-laptop: use appropriately typed variable to store the return value of ACPI methods Message-ID: <20201216013857.360987-3-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Use a variable with type `acpi_status` to store the return value of ACPI methods instead of a plain `int`. And use ACPI_{SUCCESS,FAILURE} macros where possible instead of direct comparison. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 9ed5bd8d955b..8b86e5547b59 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -971,6 +971,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) int cfg; struct ideapad_private *priv; struct acpi_device *adev; + acpi_status acpi_err; ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); if (ret) @@ -1018,22 +1019,26 @@ static int ideapad_acpi_add(struct platform_device *pdev) if (ret && ret != -ENODEV) goto backlight_failed; } - ret = acpi_install_notify_handler(adev->handle, - ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv); - if (ret) + acpi_err = acpi_install_notify_handler(adev->handle, + ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv); + if (ACPI_FAILURE(acpi_err)) { + ret = -EIO; goto notification_failed; + } #if IS_ENABLED(CONFIG_ACPI_WMI) for (i = 0; i < ARRAY_SIZE(ideapad_wmi_fnesc_events); i++) { - ret = wmi_install_notify_handler(ideapad_wmi_fnesc_events[i], - ideapad_wmi_notify, priv); - if (ret == AE_OK) { + acpi_err = wmi_install_notify_handler(ideapad_wmi_fnesc_events[i], + ideapad_wmi_notify, priv); + if (ACPI_SUCCESS(acpi_err)) { priv->fnesc_guid = ideapad_wmi_fnesc_events[i]; break; } } - if (ret != AE_OK && ret != AE_NOT_EXIST) + if (ACPI_FAILURE(acpi_err) && acpi_err != AE_NOT_EXIST) { + ret = -EIO; goto notification_failed_wmi; + } #endif return 0; From patchwork Wed Dec 16 01:39:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 998F7C4361B for ; Wed, 16 Dec 2020 01:40:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49C2A2311E for ; Wed, 16 Dec 2020 01:40:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725768AbgLPBkH (ORCPT ); Tue, 15 Dec 2020 20:40:07 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:64475 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725765AbgLPBkG (ORCPT ); Tue, 15 Dec 2020 20:40:06 -0500 Date: Wed, 16 Dec 2020 01:39:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082764; bh=I8WTNphY0a8gxRLYhZc/TnQgqwVa75aoC8NKbRi3VqM=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=ZWt63mlMBiKpqM9FNt+YoOdfZBBAvVlbQIlKV59dK12OKJTeAtUosrGTWjQuTzBpI beYMh1FFHt+resp0r1F7uH24IMZgfBARct03VIIcpupwwf4qSEiYBr6BvBaLdOyYsK 5SMYCIVyrKvuEyauAykX3+0y1ZnNQauff7nyScgA= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 03/24] platform/x86: ideapad-laptop: sort includes lexicographically Message-ID: <20201216013857.360987-4-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Managing includes is easier when they are sorted, so sort them lexicographically. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 8b86e5547b59..aefe83996be6 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -8,23 +8,23 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include -#include -#include -#include +#include #include -#include -#include -#include -#include #include -#include #include -#include -#include -#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define IDEAPAD_RFKILL_DEV_NUM (3) From patchwork Wed Dec 16 01:39:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17533C4361B for ; Wed, 16 Dec 2020 01:40:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E36252311E for ; Wed, 16 Dec 2020 01:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725769AbgLPBkH (ORCPT ); Tue, 15 Dec 2020 20:40:07 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:45261 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725550AbgLPBkH (ORCPT ); Tue, 15 Dec 2020 20:40:07 -0500 Date: Wed, 16 Dec 2020 01:39:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082764; bh=lPtPo6QjPZZAvGFPghv331j8n043gBexnNerXfAmyPY=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=KJ+yTBG8Iu6c8qCbLcCA8ijD6ecSYdTkKgw9Z2+/oVq4Sr1qtYluelD88uJ7uq9RT B5qO1q7mjDzcB7jWZbqWu63tizavOnNm/cPkgrgT6RNUefG1y+H74xzd8Kwx9u4sCc w2y183j6VZJIj93bqKecLoq3+sVhhmkDhrzoIx6U= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 04/24] platform/x86: ideapad-laptop: use sysfs_emit() Message-ID: <20201216013857.360987-5-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org sysfs_emit() has been introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's show() callback. Convert the ideapad-laptop module to utilize this new helper function. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index aefe83996be6..11df791d702c 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #define IDEAPAD_RFKILL_DEV_NUM (3) @@ -344,8 +345,8 @@ static ssize_t show_ideapad_cam(struct device *dev, struct ideapad_private *priv = dev_get_drvdata(dev); if (read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result)) - return sprintf(buf, "-1\n"); - return sprintf(buf, "%lu\n", result); + return sysfs_emit(buf, "-1\n"); + return sysfs_emit(buf, "%lu\n", result); } static ssize_t store_ideapad_cam(struct device *dev, @@ -375,8 +376,8 @@ static ssize_t show_ideapad_fan(struct device *dev, struct ideapad_private *priv = dev_get_drvdata(dev); if (read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result)) - return sprintf(buf, "-1\n"); - return sprintf(buf, "%lu\n", result); + return sysfs_emit(buf, "-1\n"); + return sysfs_emit(buf, "%lu\n", result); } static ssize_t store_ideapad_fan(struct device *dev, @@ -408,8 +409,8 @@ static ssize_t touchpad_show(struct device *dev, unsigned long result; if (read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result)) - return sprintf(buf, "-1\n"); - return sprintf(buf, "%lu\n", result); + return sysfs_emit(buf, "-1\n"); + return sysfs_emit(buf, "%lu\n", result); } /* Switch to RO for now: It might be revisited in the future */ @@ -441,8 +442,8 @@ static ssize_t conservation_mode_show(struct device *dev, unsigned long result; if (method_gbmd(priv->adev->handle, &result)) - return sprintf(buf, "-1\n"); - return sprintf(buf, "%u\n", test_bit(BM_CONSERVATION_BIT, &result)); + return sysfs_emit(buf, "-1\n"); + return sysfs_emit(buf, "%u\n", test_bit(BM_CONSERVATION_BIT, &result)); } static ssize_t conservation_mode_store(struct device *dev, @@ -477,10 +478,10 @@ static ssize_t fn_lock_show(struct device *dev, int fail = read_method_int(priv->adev->handle, "HALS", &hals); if (fail) - return sprintf(buf, "-1\n"); + return sysfs_emit(buf, "-1\n"); result = hals; - return sprintf(buf, "%u\n", test_bit(HA_FNLOCK_BIT, &result)); + return sysfs_emit(buf, "%u\n", test_bit(HA_FNLOCK_BIT, &result)); } static ssize_t fn_lock_store(struct device *dev, From patchwork Wed Dec 16 01:39:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1495C2BBCF for ; Wed, 16 Dec 2020 01:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76FF52311F for ; Wed, 16 Dec 2020 01:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725802AbgLPBku (ORCPT ); Tue, 15 Dec 2020 20:40:50 -0500 Received: from mail-02.mail-europe.com ([51.89.119.103]:56264 "EHLO mail-02.mail-europe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725803AbgLPBku (ORCPT ); Tue, 15 Dec 2020 20:40:50 -0500 Date: Wed, 16 Dec 2020 01:39:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082765; bh=XxkYsJ/YJaPiKvHbz0baBZQkmkFSZ3WEqVClkqWLKqQ=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=h2DkDVNlSMN++km3jzieZHY76F+clRxouj+7rSIAfUQJaZ3ypJ9/q0FigYd0ey8yl SbcM6V+yA2uh3j8ytX7za6T6hM1KswBdecWalqx844f+yTOE4Yy2Ig8429r/HZY2EW d79FDSa4Xcyuh5inGVBKaWNhVbN8VsEzVqhMuU9I= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 05/24] platform/x86: ideapad-laptop: use for_each_set_bit() helper to simplify event processing Message-ID: <20201216013857.360987-6-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The current code used the combination of a for loop + test_bit, which can be simplified using for_each_set_bit(), so utilize that. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 11df791d702c..22e1b3fd3df5 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -738,22 +739,20 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv) read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value); - for (bit = 0; bit < 16; bit++) { - if (test_bit(bit, &value)) { - switch (bit) { - case 0: /* Z580 */ - case 6: /* Z570 */ - /* Thermal Management button */ - ideapad_input_report(priv, 65); - break; - case 1: - /* OneKey Theater button */ - ideapad_input_report(priv, 64); - break; - default: - pr_info("Unknown special button: %lu\n", bit); - break; - } + for_each_set_bit(bit, &value, 16) { + switch (bit) { + case 0: /* Z580 */ + case 6: /* Z570 */ + /* Thermal Management button */ + ideapad_input_report(priv, 65); + break; + case 1: + /* OneKey Theater button */ + ideapad_input_report(priv, 64); + break; + default: + pr_info("Unknown special button: %lu\n", bit); + break; } } } @@ -884,7 +883,7 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv) static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) { struct ideapad_private *priv = data; - unsigned long vpc1, vpc2, vpc_bit; + unsigned long vpc1, vpc2, bit; if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1)) return; @@ -892,44 +891,42 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) return; vpc1 = (vpc2 << 8) | vpc1; - for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) { - if (test_bit(vpc_bit, &vpc1)) { - switch (vpc_bit) { - case 9: - ideapad_sync_rfk_state(priv); - break; - case 13: - case 11: - case 8: - case 7: - case 6: - ideapad_input_report(priv, vpc_bit); - break; - case 5: - ideapad_sync_touchpad_state(priv); - break; - case 4: - ideapad_backlight_notify_brightness(priv); - break; - case 3: - ideapad_input_novokey(priv); - break; - case 2: - ideapad_backlight_notify_power(priv); - break; - case 0: - ideapad_check_special_buttons(priv); - break; - case 1: - /* Some IdeaPads report event 1 every ~20 - * seconds while on battery power; some - * report this when changing to/from tablet - * mode. Squelch this event. - */ - break; - default: - pr_info("Unknown event: %lu\n", vpc_bit); - } + for_each_set_bit(bit, &vpc1, 16) { + switch (bit) { + case 9: + ideapad_sync_rfk_state(priv); + break; + case 13: + case 11: + case 8: + case 7: + case 6: + ideapad_input_report(priv, bit); + break; + case 5: + ideapad_sync_touchpad_state(priv); + break; + case 4: + ideapad_backlight_notify_brightness(priv); + break; + case 3: + ideapad_input_novokey(priv); + break; + case 2: + ideapad_backlight_notify_power(priv); + break; + case 0: + ideapad_check_special_buttons(priv); + break; + case 1: + /* Some IdeaPads report event 1 every ~20 + * seconds while on battery power; some + * report this when changing to/from tablet + * mode. Squelch this event. + */ + break; + default: + pr_info("Unknown event: %lu\n", bit); } } } From patchwork Wed Dec 16 01:39:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49C46C2BBCA for ; Wed, 16 Dec 2020 01:40:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B8472311F for ; Wed, 16 Dec 2020 01:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725765AbgLPBkM (ORCPT ); Tue, 15 Dec 2020 20:40:12 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:57223 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725550AbgLPBkM (ORCPT ); Tue, 15 Dec 2020 20:40:12 -0500 Date: Wed, 16 Dec 2020 01:39:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082770; bh=MibG3xxkzW+W6nOJRdn9gX9U0CpJ42qdnumGm+qEjCs=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=X6ao4scjMtPYSXpNVNMLAwwW2+Gqv8/Gx0dPgzawfOYsv7YgkYwO8ESZuIpFC+ulZ TQn7fT7rHGLtezi+i28eKcjeyRdJ5vn0DOYyMzC5LszKrmkauyUn3N6akskgNNu2xU k/02LcP/Zu2/vobt0TuGbkcXw8XADmxWVbiWsSpg= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 06/24] platform/x86: ideapad-laptop: use msecs_to_jiffies() helper instead of hand-crafted formula Message-ID: <20201216013857.360987-7-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The current code used a hand-crafted formulate to convert milliseconds to jiffies, replace it with the msecs_to_jiffies() function. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 22e1b3fd3df5..798723c88a68 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -188,7 +189,7 @@ static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) if (method_vpcw(handle, 1, cmd)) return -1; - for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; + for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { schedule(); if (method_vpcr(handle, 1, &val)) @@ -214,7 +215,7 @@ static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) if (method_vpcw(handle, 1, cmd)) return -1; - for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; + for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { schedule(); if (method_vpcr(handle, 1, &val)) From patchwork Wed Dec 16 01:39:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C006C4361B for ; Wed, 16 Dec 2020 01:40:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49B592311F for ; Wed, 16 Dec 2020 01:40:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725792AbgLPBke (ORCPT ); Tue, 15 Dec 2020 20:40:34 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:50678 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgLPBkd (ORCPT ); Tue, 15 Dec 2020 20:40:33 -0500 Date: Wed, 16 Dec 2020 01:39:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082770; bh=NkB7kbJVe4dp8t1ay4K8XBkHafYB6Uo+1zaC+/My/Wc=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=XZnbnCIBACrHtvBaXDrqMnlBP5BVKS2K1j7/OH7K6AXvjKmlTtsGk4Az13jkTC5rP UpB/H7odpwSa2oNM8UU4FGzU2bToOAWeAWPoaG6LI9kacuWSIFs70qUzHfGft/maWa xAMcdTXnpkRFD2Ch6wSKit2uTzyIP7KZ7tTVavJg= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 07/24] platform/x86: ideapad-laptop: use dev_{err,warn} or appropriate variant to display log messages Message-ID: <20201216013857.360987-8-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Having the device name in the log message makes it easier to determine in the context of which device the message was printed, so utilize the appropriate variants of dev_{err,warn,...} when printing log messages. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 798723c88a68..d9ac96f6b465 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -201,7 +201,7 @@ static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) return 0; } } - pr_err("timeout in %s\n", __func__); + acpi_handle_err(handle, "timeout in %s\n", __func__); return -1; } @@ -223,7 +223,7 @@ static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) if (val == 0) return 0; } - pr_err("timeout in %s\n", __func__); + acpi_handle_err(handle, "timeout in %s\n", __func__); return -1; } @@ -692,13 +692,15 @@ static int ideapad_input_init(struct ideapad_private *priv) error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); if (error) { - pr_err("Unable to setup input device keymap\n"); + dev_err(&priv->platform_device->dev, + "Unable to setup input device keymap\n"); goto err_free_dev; } error = input_register_device(inputdev); if (error) { - pr_err("Unable to register input device\n"); + dev_err(&priv->platform_device->dev, + "Unable to register input device\n"); goto err_free_dev; } @@ -752,7 +754,8 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv) ideapad_input_report(priv, 64); break; default: - pr_info("Unknown special button: %lu\n", bit); + dev_warn(&priv->platform_device->dev, + "Unknown special button: %lu\n", bit); break; } } @@ -818,7 +821,8 @@ static int ideapad_backlight_init(struct ideapad_private *priv) &ideapad_backlight_ops, &props); if (IS_ERR(blightdev)) { - pr_err("Could not register backlight device\n"); + dev_warn(&priv->platform_device->dev, + "Could not register backlight device\n"); return PTR_ERR(blightdev); } @@ -927,7 +931,8 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) */ break; default: - pr_info("Unknown event: %lu\n", bit); + dev_warn(&priv->platform_device->dev, + "Unknown event: %lu\n", bit); } } } @@ -935,12 +940,15 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) #if IS_ENABLED(CONFIG_ACPI_WMI) static void ideapad_wmi_notify(u32 value, void *context) { + struct ideapad_private *priv = context; + switch (value) { case 128: - ideapad_input_report(context, value); + ideapad_input_report(priv, value); break; default: - pr_info("Unknown WMI event %u\n", value); + dev_warn(&priv->platform_device->dev, + "Unknown WMI event: %u\n", value); } } #endif From patchwork Wed Dec 16 01:39:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BFA4C2BBCF for ; Wed, 16 Dec 2020 01:40:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 071462311E for ; Wed, 16 Dec 2020 01:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725785AbgLPBkY (ORCPT ); Tue, 15 Dec 2020 20:40:24 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:34128 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725550AbgLPBkY (ORCPT ); Tue, 15 Dec 2020 20:40:24 -0500 Date: Wed, 16 Dec 2020 01:39:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082781; bh=VkOOQi+ZkPYfoiIDG9iAawrkQXozPeNmJQW1T/c5jbI=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=PqG90gTWl6Sxo1395XjJzQr2PSGC03E6UDHTVgt0kqFIAopq1BI3mcJZ9k5cX1nWe TqyoXbCDkZMCMAkpGmnPt7BgQJNDETxzq0S6hFmnq6rU5Hear96kVfqMpEgKXMFYro z8SijJKkLRwCQ7KbpaAKmCbYOvqlzJ6STTxrO+bM= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 08/24] platform/x86: ideapad-laptop: convert ACPI helpers to return -EIO in case of failure Message-ID: <20201216013857.360987-9-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org ACPI helpers returned -1 in case of failure. Convert these functions to return appropriate error codes, and convert their users to propagate these error codes accordingly. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index d9ac96f6b465..1d43894d557e 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -115,7 +115,7 @@ static int read_method_int(acpi_handle handle, const char *method, int *val) status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); if (ACPI_FAILURE(status)) { *val = -1; - return -1; + return -EIO; } *val = result; return 0; @@ -136,7 +136,7 @@ static int method_int1(acpi_handle handle, char *method, int cmd) acpi_status status; status = acpi_execute_simple_method(handle, method, cmd); - return ACPI_FAILURE(status) ? -1 : 0; + return ACPI_FAILURE(status) ? -EIO : 0; } static int method_vpcr(acpi_handle handle, int cmd, int *ret) @@ -155,7 +155,7 @@ static int method_vpcr(acpi_handle handle, int cmd, int *ret) if (ACPI_FAILURE(status)) { *ret = -1; - return -1; + return -EIO; } *ret = result; return 0; @@ -177,54 +177,60 @@ static int method_vpcw(acpi_handle handle, int cmd, int data) status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); if (status != AE_OK) - return -1; + return -EIO; return 0; } static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) { - int val; + int val, err; unsigned long int end_jiffies; - if (method_vpcw(handle, 1, cmd)) - return -1; + err = method_vpcw(handle, 1, cmd); + if (err) + return err; for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { schedule(); - if (method_vpcr(handle, 1, &val)) - return -1; + err = method_vpcr(handle, 1, &val); + if (err) + return err; if (val == 0) { - if (method_vpcr(handle, 0, &val)) - return -1; + err = method_vpcr(handle, 0, &val); + if (err) + return err; *data = val; return 0; } } acpi_handle_err(handle, "timeout in %s\n", __func__); - return -1; + return -ETIMEDOUT; } static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) { - int val; + int val, err; unsigned long int end_jiffies; - if (method_vpcw(handle, 0, data)) - return -1; - if (method_vpcw(handle, 1, cmd)) - return -1; + err = method_vpcw(handle, 0, data); + if (err) + return err; + err = method_vpcw(handle, 1, cmd); + if (err) + return err; for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { schedule(); - if (method_vpcr(handle, 1, &val)) - return -1; + err = method_vpcr(handle, 1, &val); + if (err) + return err; if (val == 0) return 0; } acpi_handle_err(handle, "timeout in %s\n", __func__); - return -1; + return -ETIMEDOUT; } /* @@ -363,8 +369,8 @@ static ssize_t store_ideapad_cam(struct device *dev, if (sscanf(buf, "%i", &state) != 1) return -EINVAL; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -396,8 +402,8 @@ static ssize_t store_ideapad_fan(struct device *dev, if (state < 0 || state > 4 || state == 3) return -EINVAL; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -429,8 +435,8 @@ static ssize_t __maybe_unused touchpad_store(struct device *dev, return ret; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -463,8 +469,8 @@ static ssize_t conservation_mode_store(struct device *dev, ret = method_int1(priv->adev->handle, "SBMC", state ? BMCMD_CONSERVATION_ON : BMCMD_CONSERVATION_OFF); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -501,8 +507,8 @@ static ssize_t fn_lock_store(struct device *dev, ret = method_int1(priv->adev->handle, "SALS", state ? HACMD_FNLOCK_ON : HACMD_FNLOCK_OFF); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -740,7 +746,8 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv) { unsigned long bit, value; - read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value); + if (read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value)) + return; for_each_set_bit(bit, &value, 16) { switch (bit) { @@ -768,28 +775,33 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev) { struct ideapad_private *priv = bl_get_data(blightdev); unsigned long now; + int err; if (!priv) return -EINVAL; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now)) - return -EIO; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); + if (err) + return err; return now; } static int ideapad_backlight_update_status(struct backlight_device *blightdev) { struct ideapad_private *priv = bl_get_data(blightdev); + int err; if (!priv) return -EINVAL; - if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL, - blightdev->props.brightness)) - return -EIO; - if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER, - blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1)) - return -EIO; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL, + blightdev->props.brightness); + if (err) + return err; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER, + blightdev->props.power != FB_BLANK_POWERDOWN); + if (err) + return err; return 0; } @@ -804,13 +816,17 @@ static int ideapad_backlight_init(struct ideapad_private *priv) struct backlight_device *blightdev; struct backlight_properties props; unsigned long max, now, power; - - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max)) - return -EIO; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now)) - return -EIO; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power)) - return -EIO; + int err; + + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max); + if (err) + return err; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); + if (err) + return err; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power); + if (err) + return err; memset(&props, 0, sizeof(struct backlight_properties)); props.max_brightness = max; From patchwork Wed Dec 16 01:39:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 353AEC2BB48 for ; Wed, 16 Dec 2020 01:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E87F423120 for ; Wed, 16 Dec 2020 01:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725800AbgLPBkt (ORCPT ); Tue, 15 Dec 2020 20:40:49 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:10554 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgLPBkt (ORCPT ); Tue, 15 Dec 2020 20:40:49 -0500 Date: Wed, 16 Dec 2020 01:39:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082790; bh=sRQq/xEv3F9s5lmNZnqabsnU76C+BPqWl6gzVh4fuzw=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=jQy1gD2A1VcshIXFPo6RQ+GotKF0lyCvx7vAArBoRqwJq+TIXNQ06Evi+uk92VUO0 xgAjrBzH5+N1fwkGYhoZCXTk0coa+quMF061AYhqkWPDNOQxt+0gsH24Sn5iOS2gXm C14wgpH+COYQXj2sYPtYDh/LGkoEzn2omB8yE/u0= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 09/24] platform/x86: ideapad-laptop: always propagate error codes from device attributes' show() callback Message-ID: <20201216013857.360987-10-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Consumers can differentiate an error from a successful read much more easily if the read() call fails with the appropriate errno instead of returning a magic string like "-1". Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 1d43894d557e..b6b5a508a8b8 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -351,9 +351,11 @@ static ssize_t show_ideapad_cam(struct device *dev, { unsigned long result; struct ideapad_private *priv = dev_get_drvdata(dev); + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result)) - return sysfs_emit(buf, "-1\n"); + err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result); + if (err) + return err; return sysfs_emit(buf, "%lu\n", result); } @@ -382,9 +384,11 @@ static ssize_t show_ideapad_fan(struct device *dev, { unsigned long result; struct ideapad_private *priv = dev_get_drvdata(dev); + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result)) - return sysfs_emit(buf, "-1\n"); + err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result); + if (err) + return err; return sysfs_emit(buf, "%lu\n", result); } @@ -415,9 +419,11 @@ static ssize_t touchpad_show(struct device *dev, { struct ideapad_private *priv = dev_get_drvdata(dev); unsigned long result; + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result)) - return sysfs_emit(buf, "-1\n"); + err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); + if (err) + return err; return sysfs_emit(buf, "%lu\n", result); } @@ -448,9 +454,11 @@ static ssize_t conservation_mode_show(struct device *dev, { struct ideapad_private *priv = dev_get_drvdata(dev); unsigned long result; + int err; - if (method_gbmd(priv->adev->handle, &result)) - return sysfs_emit(buf, "-1\n"); + err = method_gbmd(priv->adev->handle, &result); + if (err) + return err; return sysfs_emit(buf, "%u\n", test_bit(BM_CONSERVATION_BIT, &result)); } @@ -486,7 +494,7 @@ static ssize_t fn_lock_show(struct device *dev, int fail = read_method_int(priv->adev->handle, "HALS", &hals); if (fail) - return sysfs_emit(buf, "-1\n"); + return fail; result = hals; return sysfs_emit(buf, "%u\n", test_bit(HA_FNLOCK_BIT, &result)); From patchwork Wed Dec 16 01:39:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D08F7C4361B for ; Wed, 16 Dec 2020 01:40:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A76732311F for ; Wed, 16 Dec 2020 01:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725796AbgLPBkg (ORCPT ); Tue, 15 Dec 2020 20:40:36 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:61118 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgLPBkg (ORCPT ); Tue, 15 Dec 2020 20:40:36 -0500 Date: Wed, 16 Dec 2020 01:39:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082789; bh=gmAxguOG3WaPpE2+DSl8Kqy0YaxUZSOoD96cmDjDB3Y=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=ThlGWdX1imE4aP0acZgajK0DfCeQHSoVGOaVahqvEjhRfZLK8pEAfsUOpeYuc/VJz sNIdwg8Vc8lsW5QG6YlueU3TUH41KPJxEfHkLDFxK2lCmX1gJpNv+nqUQ1s/DfK4Mx koM4fbNNhJWom4VTN/2mbKxpvUg73Uit7qEjE16I= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 10/24] platform/x86: ideapad-laptop: misc. device attribute changes Message-ID: <20201216013857.360987-11-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Do not handle zero length buffer separately. Use kstrtouint() instead of sscanf(). Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index b6b5a508a8b8..a615c42d1beb 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -363,13 +363,13 @@ static ssize_t store_ideapad_cam(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ret, state; + int ret; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned int state; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; + ret = kstrtouint(buf, 0, &state); + if (ret) + return ret; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); if (ret) return ret; @@ -396,14 +396,14 @@ static ssize_t store_ideapad_fan(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ret, state; + int ret; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned int state; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; - if (state < 0 || state > 4 || state == 3) + ret = kstrtouint(buf, 0, &state); + if (ret) + return ret; + if (state > 4 || state == 3) return -EINVAL; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); if (ret) From patchwork Wed Dec 16 01:39:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06B7AC2BBCD for ; Wed, 16 Dec 2020 01:40:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C8AE72311F for ; Wed, 16 Dec 2020 01:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725730AbgLPBku (ORCPT ); Tue, 15 Dec 2020 20:40:50 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:50678 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgLPBku (ORCPT ); Tue, 15 Dec 2020 20:40:50 -0500 Date: Wed, 16 Dec 2020 01:39:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082794; bh=Yh1HSVIA/EB37Qe4kY4Tq76O6kf8AVZAoxtHldxeo54=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=ogILRoTKF2x4mdKZKKdykVN/QWKEE1CleB84/svtSuCkZNbaJdNEhxuPELuFfQxv0 Q39yUBRNYC4gjxLKrlavgFwvc4wLUUdPdGwqBTMwRbjPs67BQLnrPgG5kRic5Nc/pp vOjIb0GHbbNZ6YM87cZsAHCYm1ljmrjh1Fjs1Q1I= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 11/24] platform/x86: ideapad-laptop: group and separate (un)related constants into enums Message-ID: <20201216013857.360987-12-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Group and rename constants depending on which ACPI interface they pertain to, and rename CFG_X constants to CFG_CAP_X. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index a615c42d1beb..ffe41bf5585f 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -31,14 +31,6 @@ #define IDEAPAD_RFKILL_DEV_NUM (3) -#define BM_CONSERVATION_BIT (5) -#define HA_FNLOCK_BIT (10) - -#define CFG_BT_BIT (16) -#define CFG_3G_BIT (17) -#define CFG_WIFI_BIT (18) -#define CFG_CAMERA_BIT (19) - #if IS_ENABLED(CONFIG_ACPI_WMI) static const char *const ideapad_wmi_fnesc_events[] = { "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6", /* Yoga 3 */ @@ -47,10 +39,28 @@ static const char *const ideapad_wmi_fnesc_events[] = { #endif enum { - BMCMD_CONSERVATION_ON = 3, - BMCMD_CONSERVATION_OFF = 5, - HACMD_FNLOCK_ON = 0xe, - HACMD_FNLOCK_OFF = 0xf, + CFG_CAP_BT_BIT = 16, + CFG_CAP_3G_BIT = 17, + CFG_CAP_WIFI_BIT = 18, + CFG_CAP_CAM_BIT = 19, +}; + +enum { + GBMD_CONSERVATION_STATE_BIT = 5, +}; + +enum { + SMBC_CONSERVATION_ON = 3, + SMBC_CONSERVATION_OFF = 5, +}; + +enum { + HALS_FNLOCK_STATE_BIT = 10, +}; + +enum { + SALS_FNLOCK_ON = 0xe, + SALS_FNLOCK_OFF = 0xf, }; enum { @@ -276,7 +286,7 @@ static int debugfs_status_show(struct seq_file *s, void *data) if (!method_gbmd(priv->adev->handle, &value)) { seq_printf(s, "Conservation mode:\t%s(%lu)\n", - test_bit(BM_CONSERVATION_BIT, &value) ? "On" : "Off", + test_bit(GBMD_CONSERVATION_STATE_BIT, &value) ? "On" : "Off", value); } @@ -293,13 +303,13 @@ static int debugfs_cfg_show(struct seq_file *s, void *data) } else { seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ", priv->cfg); - if (test_bit(CFG_BT_BIT, &priv->cfg)) + if (test_bit(CFG_CAP_BT_BIT, &priv->cfg)) seq_printf(s, "Bluetooth "); - if (test_bit(CFG_3G_BIT, &priv->cfg)) + if (test_bit(CFG_CAP_3G_BIT, &priv->cfg)) seq_printf(s, "3G "); - if (test_bit(CFG_WIFI_BIT, &priv->cfg)) + if (test_bit(CFG_CAP_WIFI_BIT, &priv->cfg)) seq_printf(s, "Wireless "); - if (test_bit(CFG_CAMERA_BIT, &priv->cfg)) + if (test_bit(CFG_CAP_CAM_BIT, &priv->cfg)) seq_printf(s, "Camera "); seq_printf(s, "\nGraphic: "); switch ((priv->cfg)&0x700) { @@ -459,7 +469,7 @@ static ssize_t conservation_mode_show(struct device *dev, err = method_gbmd(priv->adev->handle, &result); if (err) return err; - return sysfs_emit(buf, "%u\n", test_bit(BM_CONSERVATION_BIT, &result)); + return sysfs_emit(buf, "%u\n", test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); } static ssize_t conservation_mode_store(struct device *dev, @@ -475,8 +485,8 @@ static ssize_t conservation_mode_store(struct device *dev, return ret; ret = method_int1(priv->adev->handle, "SBMC", state ? - BMCMD_CONSERVATION_ON : - BMCMD_CONSERVATION_OFF); + SMBC_CONSERVATION_ON : + SMBC_CONSERVATION_OFF); if (ret) return ret; return count; @@ -497,7 +507,7 @@ static ssize_t fn_lock_show(struct device *dev, return fail; result = hals; - return sysfs_emit(buf, "%u\n", test_bit(HA_FNLOCK_BIT, &result)); + return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &result)); } static ssize_t fn_lock_store(struct device *dev, @@ -513,8 +523,8 @@ static ssize_t fn_lock_store(struct device *dev, return ret; ret = method_int1(priv->adev->handle, "SALS", state ? - HACMD_FNLOCK_ON : - HACMD_FNLOCK_OFF); + SALS_FNLOCK_ON : + SALS_FNLOCK_OFF); if (ret) return ret; return count; @@ -541,7 +551,7 @@ static umode_t ideapad_is_visible(struct kobject *kobj, bool supported; if (attr == &dev_attr_camera_power.attr) - supported = test_bit(CFG_CAMERA_BIT, &(priv->cfg)); + supported = test_bit(CFG_CAP_CAM_BIT, &priv->cfg); else if (attr == &dev_attr_fan_mode.attr) { unsigned long value; supported = !read_ec_data(priv->adev->handle, VPCCMD_R_FAN, @@ -574,9 +584,9 @@ struct ideapad_rfk_data { }; static const struct ideapad_rfk_data ideapad_rfk_data[] = { - { "ideapad_wlan", CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN }, - { "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH }, - { "ideapad_3g", CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN }, + { "ideapad_wlan", CFG_CAP_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN }, + { "ideapad_bluetooth", CFG_CAP_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH }, + { "ideapad_3g", CFG_CAP_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN }, }; static int ideapad_rfk_set(void *data, bool blocked) From patchwork Wed Dec 16 01:39:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 734B0C4361B for ; Wed, 16 Dec 2020 01:40:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34D122311F for ; Wed, 16 Dec 2020 01:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725804AbgLPBks (ORCPT ); Tue, 15 Dec 2020 20:40:48 -0500 Received: from mail1.protonmail.ch ([185.70.40.18]:16735 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgLPBks (ORCPT ); Tue, 15 Dec 2020 20:40:48 -0500 Date: Wed, 16 Dec 2020 01:39:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082804; bh=DgmPUx3W/67QFGkNXd324J/JN4g6wAdathSdkmCLLY0=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=hsnVjJNnthZTPL/EF61TLVLLa77WAHOVOcWTGdAJoRI+bUkE8MO/Z2b9/jH3eiWCC SxYdUc1Tq0X+lp9ym+iAK0Vw2oDnxJqIsZC0Y3wg0lpgHZ3nRWWx/0EEaO3w/QBp7R 8bkU4cyi3fsaLrszyo44GkTo5iZCo9c9Iywvjekk= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 12/24] platform/x86: ideapad-laptop: rework and create new ACPI helpers Message-ID: <20201216013857.360987-13-pobrn@protonmail.com> In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com> References: <20201216013857.360987-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Create dedicated helper functions for accessing the main ACPI methods: GBMD, SMBC, HALS, SALS; and utilize them. Use `unsigned long` consistently in every ACPI helper wherever possible. Change names to better express purpose. Do not assign values to output parameters in case of failure. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index ffe41bf5585f..795978e0d13e 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -117,41 +117,47 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); */ #define IDEAPAD_EC_TIMEOUT (200) /* in ms */ -static int read_method_int(acpi_handle handle, const char *method, int *val) +static int eval_int(acpi_handle handle, const char *method, unsigned long *val) { - acpi_status status; + acpi_status acpi_err; unsigned long long result; - status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); - if (ACPI_FAILURE(status)) { - *val = -1; + acpi_err = acpi_evaluate_integer(handle, (char *)method, NULL, &result); + if (ACPI_FAILURE(acpi_err)) return -EIO; - } *val = result; return 0; +} +static int eval_simple_method(acpi_handle handle, char *method, u64 arg) +{ + acpi_status acpi_err = acpi_execute_simple_method(handle, method, arg); + return ACPI_FAILURE(acpi_err) ? -EIO : 0; } -static int method_gbmd(acpi_handle handle, unsigned long *ret) +static int eval_gbmd(acpi_handle handle, unsigned long *val) { - int result, val; + return eval_int(handle, "GBMD", val); +} - result = read_method_int(handle, "GBMD", &val); - *ret = val; - return result; +static int eval_smbc(acpi_handle handle, unsigned long arg) +{ + return eval_simple_method(handle, "SMBC", arg); } -static int method_int1(acpi_handle handle, char *method, int cmd) +static int eval_hals(acpi_handle handle, unsigned long *val) { - acpi_status status; + return eval_int(handle, "HALS", val); +} - status = acpi_execute_simple_method(handle, method, cmd); - return ACPI_FAILURE(status) ? -EIO : 0; +static int eval_sals(acpi_handle handle, unsigned long arg) +{ + return eval_simple_method(handle, "SALS", arg); } -static int method_vpcr(acpi_handle handle, int cmd, int *ret) +static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *val) { - acpi_status status; + acpi_status acpi_err; unsigned long long result; struct acpi_object_list params; union acpi_object in_obj; @@ -161,22 +167,20 @@ static int method_vpcr(acpi_handle handle, int cmd, int *ret) in_obj.type = ACPI_TYPE_INTEGER; in_obj.integer.value = cmd; - status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); + acpi_err = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); - if (ACPI_FAILURE(status)) { - *ret = -1; + if (ACPI_FAILURE(acpi_err)) return -EIO; - } - *ret = result; + *val = result; return 0; } -static int method_vpcw(acpi_handle handle, int cmd, int data) +static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data) { struct acpi_object_list params; union acpi_object in_obj[2]; - acpi_status status; + acpi_status acpi_err; params.count = 2; params.pointer = in_obj; @@ -185,55 +189,50 @@ static int method_vpcw(acpi_handle handle, int cmd, int data) in_obj[1].type = ACPI_TYPE_INTEGER; in_obj[1].integer.value = data; - status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); - if (status != AE_OK) + acpi_err = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); + if (ACPI_FAILURE(acpi_err)) return -EIO; return 0; } -static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) +static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data) { - int val, err; - unsigned long int end_jiffies; + int err; + unsigned long int end_jiffies, val; - err = method_vpcw(handle, 1, cmd); + err = eval_vpcw(handle, 1, cmd); if (err) return err; for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { schedule(); - err = method_vpcr(handle, 1, &val); + err = eval_vpcr(handle, 1, &val); if (err) return err; - if (val == 0) { - err = method_vpcr(handle, 0, &val); - if (err) - return err; - *data = val; - return 0; - } + if (val == 0) + return eval_vpcr(handle, 0, data); } acpi_handle_err(handle, "timeout in %s\n", __func__); return -ETIMEDOUT; } -static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) +static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data) { - int val, err; - unsigned long int end_jiffies; + int err; + unsigned long end_jiffies, val; - err = method_vpcw(handle, 0, data); + err = eval_vpcw(handle, 0, data); if (err) return err; - err = method_vpcw(handle, 1, cmd); + err = eval_vpcw(handle, 1, cmd); if (err) return err; for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { schedule(); - err = method_vpcr(handle, 1, &val); + err = eval_vpcr(handle, 1, &val); if (err) return err; if (val == 0) @@ -284,7 +283,7 @@ static int debugfs_status_show(struct seq_file *s, void *data) value ? "On" : "Off", value); seq_puts(s, "=====================\n"); - if (!method_gbmd(priv->adev->handle, &value)) { + if (!eval_gbmd(priv->adev->handle, &value)) { seq_printf(s, "Conservation mode:\t%s(%lu)\n", test_bit(GBMD_CONSERVATION_STATE_BIT, &value) ? "On" : "Off", value); @@ -466,7 +465,7 @@ static ssize_t conservation_mode_show(struct device *dev, unsigned long result; int err; - err = method_gbmd(priv->adev->handle, &result); + err = eval_gbmd(priv->adev->handle, &result); if (err) return err; return sysfs_emit(buf, "%u\n", test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); @@ -484,9 +483,8 @@ static ssize_t conservation_mode_store(struct device *dev, if (ret) return ret; - ret = method_int1(priv->adev->handle, "SBMC", state ? - SMBC_CONSERVATION_ON : - SMBC_CONSERVATION_OFF); + ret = eval_smbc(priv->adev->handle, + state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF); if (ret) return ret; return count; @@ -499,15 +497,13 @@ static ssize_t fn_lock_show(struct device *dev, char *buf) { struct ideapad_private *priv = dev_get_drvdata(dev); - unsigned long result; - int hals; - int fail = read_method_int(priv->adev->handle, "HALS", &hals); + unsigned long hals; + int fail = eval_hals(priv->adev->handle, &hals); if (fail) return fail; - result = hals; - return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &result)); + return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &hals)); } static ssize_t fn_lock_store(struct device *dev, @@ -522,9 +518,8 @@ static ssize_t fn_lock_store(struct device *dev, if (ret) return ret; - ret = method_int1(priv->adev->handle, "SALS", state ? - SALS_FNLOCK_ON : - SALS_FNLOCK_OFF); + ret = eval_sals(priv->adev->handle, + state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF); if (ret) return ret; return count; @@ -1009,7 +1004,7 @@ static const struct dmi_system_id hw_rfkill_list[] = { static int ideapad_acpi_add(struct platform_device *pdev) { int ret, i; - int cfg; + unsigned long cfg; struct ideapad_private *priv; struct acpi_device *adev; acpi_status acpi_err; @@ -1018,7 +1013,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) if (ret) return -ENODEV; - if (read_method_int(adev->handle, "_CFG", &cfg)) + if (eval_int(adev->handle, "_CFG", &cfg)) return -ENODEV; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); From patchwork Wed Dec 16 01:40:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0369AC2BBCA for ; Wed, 16 Dec 2020 01:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C71332311F for ; Wed, 16 Dec 2020 01:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725806AbgLPBkt (ORCPT ); Tue, 15 Dec 2020 20:40:49 -0500 Received: from mail1.protonmail.ch ([185.70.40.18]:52039 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725800AbgLPBkt (ORCPT ); Tue, 15 Dec 2020 20:40:49 -0500 Date: Wed, 16 Dec 2020 01:40:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082806; bh=pUPxSemQjOgWSgnwW2JemCFVCGhFmBjlEKHfKgm10BI=; h=Date:To:From:Reply-To:Subject:From; b=UTBfGqjqtpFns9SDeBYke9uIQIY6pbIqjsnXbTqDgK1+AW+rykuzxS++6rCHHVUkC 4Z5U4LCubutMry6dl5ie+AALEVjldzyz6/CW44bgdKE1Eu1QjwrFcLeBSTzcvrcIfk 5S2zoBsAAggUm3NMNMgyXurI4ySeGN+9JM6cwDRQ= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 13/24] platform/x86: ideapad-laptop: rework is_visible() logic Message-ID: <20201216013857.360987-14-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Store the supported features in the driver private data, and modify the is_visible() callback to use it, and create ideapad_check_features() to populate it. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 795978e0d13e..d61710ad8803 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -104,8 +104,13 @@ struct ideapad_private { struct backlight_device *blightdev; struct dentry *debug; unsigned long cfg; - bool has_hw_rfkill_switch; const char *fnesc_guid; + struct { + bool fan_mode : 1, + conservation_mode : 1, + fn_lock : 1, + hw_rfkill_switch : 1; + } features; }; static bool no_bt_rfkill; @@ -543,22 +548,16 @@ static umode_t ideapad_is_visible(struct kobject *kobj, { struct device *dev = container_of(kobj, struct device, kobj); struct ideapad_private *priv = dev_get_drvdata(dev); - bool supported; + bool supported = true; if (attr == &dev_attr_camera_power.attr) supported = test_bit(CFG_CAP_CAM_BIT, &priv->cfg); - else if (attr == &dev_attr_fan_mode.attr) { - unsigned long value; - supported = !read_ec_data(priv->adev->handle, VPCCMD_R_FAN, - &value); - } else if (attr == &dev_attr_conservation_mode.attr) { - supported = acpi_has_method(priv->adev->handle, "GBMD") && - acpi_has_method(priv->adev->handle, "SBMC"); - } else if (attr == &dev_attr_fn_lock.attr) { - supported = acpi_has_method(priv->adev->handle, "HALS") && - acpi_has_method(priv->adev->handle, "SALS"); - } else - supported = true; + else if (attr == &dev_attr_fan_mode.attr) + supported = priv->features.fan_mode; + else if (attr == &dev_attr_conservation_mode.attr) + supported = priv->features.conservation_mode; + else if (attr == &dev_attr_fn_lock.attr) + supported = priv->features.fn_lock; return supported ? attr->mode : 0; } @@ -601,7 +600,7 @@ static void ideapad_sync_rfk_state(struct ideapad_private *priv) unsigned long hw_blocked = 0; int i; - if (priv->has_hw_rfkill_switch) { + if (priv->features.hw_rfkill_switch) { if (read_ec_data(priv->adev->handle, VPCCMD_R_RF, &hw_blocked)) return; hw_blocked = !hw_blocked; @@ -1001,6 +1000,23 @@ static const struct dmi_system_id hw_rfkill_list[] = { {} }; +static void ideapad_check_features(struct ideapad_private *priv) +{ + acpi_handle handle = priv->adev->handle; + unsigned long val; + + priv->features.hw_rfkill_switch = dmi_check_system(hw_rfkill_list); + + if (!read_ec_data(handle, VPCCMD_R_FAN, &val)) + priv->features.fan_mode = true; + + if (acpi_has_method(handle, "GBMD") && acpi_has_method(handle, "SBMC")) + priv->features.conservation_mode = true; + + if (acpi_has_method(handle, "HALS") && acpi_has_method(handle, "SALS")) + priv->features.fn_lock = true; +} + static int ideapad_acpi_add(struct platform_device *pdev) { int ret, i; @@ -1024,7 +1040,8 @@ static int ideapad_acpi_add(struct platform_device *pdev) priv->cfg = cfg; priv->adev = adev; priv->platform_device = pdev; - priv->has_hw_rfkill_switch = dmi_check_system(hw_rfkill_list); + + ideapad_check_features(priv); ret = ideapad_sysfs_init(priv); if (ret) @@ -1040,7 +1057,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) * On some models without a hw-switch (the yoga 2 13 at least) * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work. */ - if (!priv->has_hw_rfkill_switch) + if (!priv->features.hw_rfkill_switch) write_ec_cmd(priv->adev->handle, VPCCMD_W_RF, 1); for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) From patchwork Wed Dec 16 01:40:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1D04C2BB48 for ; Wed, 16 Dec 2020 01:40:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABF3D2311F for ; Wed, 16 Dec 2020 01:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725807AbgLPBky (ORCPT ); Tue, 15 Dec 2020 20:40:54 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:18249 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgLPBky (ORCPT ); Tue, 15 Dec 2020 20:40:54 -0500 Date: Wed, 16 Dec 2020 01:40:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082812; bh=VGnTaoqqXPsWZ7vNkWluSX6di+Y75ngcVsLsqd6s/oI=; h=Date:To:From:Reply-To:Subject:From; b=crKeBoHjN7WcGJzcCL0QsKMKxblJMfq58aljY7W/MuqzEH3WFP4LZeN8VP3ZF6ZrZ HCaIyVa6Z7UeGggN+zs4KSFhb8HNJDAohCPLnjFR3zyeruK9Z83Shdw8e0mHI2TpRe 30zq4CSeXryJ9P7py3O2ArqEUk2YzqR867Rociks= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 14/24] platform/x86: ideapad-laptop: check for Fn-lock support in HALS Message-ID: <20201216013857.360987-15-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Bit 9 in the return value of the HALS ACPI method is set if Fn-lock is supported. Change ideapad_check_features() to check it. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index d61710ad8803..8a654ac0546c 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -55,7 +55,9 @@ enum { }; enum { - HALS_FNLOCK_STATE_BIT = 10, + HALS_FNLOCK_SUPPORT_BIT = 9, + HALS_FNLOCK_STATE_BIT = 10, + HALS_HOTKEYS_PRIMARY_BIT = 11, }; enum { @@ -1013,8 +1015,11 @@ static void ideapad_check_features(struct ideapad_private *priv) if (acpi_has_method(handle, "GBMD") && acpi_has_method(handle, "SBMC")) priv->features.conservation_mode = true; - if (acpi_has_method(handle, "HALS") && acpi_has_method(handle, "SALS")) - priv->features.fn_lock = true; + if (acpi_has_method(handle, "HALS") && acpi_has_method(handle, "SALS")) { + if (!eval_hals(handle, &val)) + if (test_bit(HALS_FNLOCK_SUPPORT_BIT, &val)) + priv->features.fn_lock = true; + } } static int ideapad_acpi_add(struct platform_device *pdev) From patchwork Wed Dec 16 01:40:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8FD4C2BBCA for ; Wed, 16 Dec 2020 01:40:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE60423105 for ; Wed, 16 Dec 2020 01:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725783AbgLPBk5 (ORCPT ); Tue, 15 Dec 2020 20:40:57 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:53132 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgLPBk5 (ORCPT ); Tue, 15 Dec 2020 20:40:57 -0500 Date: Wed, 16 Dec 2020 01:40:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082815; bh=5zHreTeRxqAvSIZ5uJk3Xtr5f9cvwma33vYBbYRDlT0=; h=Date:To:From:Reply-To:Subject:From; b=Kavi04dmFCI4YQHLR+mI7W8PfMwuGKk5Bn5viBzNigYpPRXDmjd3WSCQkYd9hr7Ws AGe/YAV4sWRVC64wn6r1o69o4fFBIykkjvOAwoEpHwsgfdETySxnmgeap58v1B5jvm Kp1HAzit2hlpGsMSGzScSpzv1VvEoCgxr2hRUJjM= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 15/24] platform/x86: ideapad-laptop: check for touchpad support in _CFG Message-ID: <20201216013857.360987-16-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Bit 31 of _CFG is set if the device has a touchpad, check that in is_visible() for the touchpad attribute. Show 'touchpad', if supported, in the list of capabilities in the 'cfg' debugfs file. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 8a654ac0546c..1e11d5d9cd20 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -39,10 +39,11 @@ static const char *const ideapad_wmi_fnesc_events[] = { #endif enum { - CFG_CAP_BT_BIT = 16, - CFG_CAP_3G_BIT = 17, - CFG_CAP_WIFI_BIT = 18, - CFG_CAP_CAM_BIT = 19, + CFG_CAP_BT_BIT = 16, + CFG_CAP_3G_BIT = 17, + CFG_CAP_WIFI_BIT = 18, + CFG_CAP_CAM_BIT = 19, + CFG_CAP_TOUCHPAD_BIT = 31, }; enum { @@ -317,6 +318,8 @@ static int debugfs_cfg_show(struct seq_file *s, void *data) seq_printf(s, "Wireless "); if (test_bit(CFG_CAP_CAM_BIT, &priv->cfg)) seq_printf(s, "Camera "); + if (test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg)) + seq_printf(s, "Touchpad "); seq_printf(s, "\nGraphic: "); switch ((priv->cfg)&0x700) { case 0x100: @@ -556,6 +559,8 @@ static umode_t ideapad_is_visible(struct kobject *kobj, supported = test_bit(CFG_CAP_CAM_BIT, &priv->cfg); else if (attr == &dev_attr_fan_mode.attr) supported = priv->features.fan_mode; + else if (attr == &dev_attr_touchpad.attr) + supported = test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg); else if (attr == &dev_attr_conservation_mode.attr) supported = priv->features.conservation_mode; else if (attr == &dev_attr_fn_lock.attr) From patchwork Wed Dec 16 01:40:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B0A7C4361B for ; Wed, 16 Dec 2020 01:41:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B42323103 for ; Wed, 16 Dec 2020 01:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725819AbgLPBlF (ORCPT ); Tue, 15 Dec 2020 20:41:05 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:55885 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgLPBlF (ORCPT ); Tue, 15 Dec 2020 20:41:05 -0500 Date: Wed, 16 Dec 2020 01:40:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082822; bh=9wu1OOhy5SOquqSUo6d/kn3Qtgj2DATMSpwWIt/9FOE=; h=Date:To:From:Reply-To:Subject:From; b=iOMMgPDDHHwjfsVmfE8RkXM2u6ORMQ0IIJIYw2pv92Kr7H6AC3j31lQM2xlVG0zOx wgOsoQ4ccAs88sNVxLH8zGZzF1Kz26CxNdBFc3Nm8EzLsf+uRUUNTeqQD1Qw5wNhjR iKOXO+rzRqg7VLEPipYhAF1ayVuDKBXR5NCQVFLA= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 16/24] platform/x86: ideapad-laptop: change 'status' debugfs file format Message-ID: <20201216013857.360987-17-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Remove conservation mode reporting since it is already reported via the appropriate device attribute, and its state can be deduced from the value of GBMD. Add the return value of the GBMD and HALS ACPI methods to the output. Change the return value to -ENODATA when the driver-specific data is not available. Use seq_puts() where possible. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 1e11d5d9cd20..b1b77eb31779 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -259,43 +259,36 @@ static int debugfs_status_show(struct seq_file *s, void *data) unsigned long value; if (!priv) - return -EINVAL; + return -ENODATA; if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value)) seq_printf(s, "Backlight max:\t%lu\n", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value)) seq_printf(s, "Backlight now:\t%lu\n", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value)) - seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off"); - seq_printf(s, "=====================\n"); + seq_printf(s, "BL power value:\t%s (%lu)\n", value ? "on" : "off", value); + seq_puts(s, "=====================\n"); if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value)) - seq_printf(s, "Radio status:\t%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "Radio status:\t%s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value)) - seq_printf(s, "Wifi status:\t%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "Wifi status:\t%s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value)) - seq_printf(s, "BT status:\t%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "BT status:\t%s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value)) - seq_printf(s, "3G status:\t%s(%lu)\n", - value ? "On" : "Off", value); - seq_printf(s, "=====================\n"); + seq_printf(s, "3G status:\t%s (%lu)\n", value ? "on" : "off", value); + seq_puts(s, "=====================\n"); if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) - seq_printf(s, "Touchpad status:%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "Touchpad status:\t%s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value)) - seq_printf(s, "Camera status:\t%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "Camera status:\t%s (%lu)\n", value ? "on" : "off", value); seq_puts(s, "=====================\n"); - if (!eval_gbmd(priv->adev->handle, &value)) { - seq_printf(s, "Conservation mode:\t%s(%lu)\n", - test_bit(GBMD_CONSERVATION_STATE_BIT, &value) ? "On" : "Off", - value); - } + if (!eval_gbmd(priv->adev->handle, &value)) + seq_printf(s, "GBMD: %#010lx\n", value); + if (!eval_hals(priv->adev->handle, &value)) + seq_printf(s, "HALS: %#010lx\n", value); return 0; } From patchwork Wed Dec 16 01:40:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E277C4361B for ; Wed, 16 Dec 2020 01:41:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 433BD2310F for ; Wed, 16 Dec 2020 01:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725825AbgLPBlH (ORCPT ); Tue, 15 Dec 2020 20:41:07 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:40660 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbgLPBlH (ORCPT ); Tue, 15 Dec 2020 20:41:07 -0500 Date: Wed, 16 Dec 2020 01:40:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082825; bh=xN7zga3uuEFl39t+SdKQIEy6+Xkao5T9x0qM5fS77/o=; h=Date:To:From:Reply-To:Subject:From; b=h4rViDXSBK6bbcHGbqKiDGydkZWyqnyxiyKZHhOa7J3vCuxrZit/JGV9c2tMVtZkU Q9oXgmBPz0e1AbKkzmRZqimVsJ8OiTiBPc+vsebjmxUnySi26SEzxXNN2AifqihwPk 1KAYZJSQ+8Y9pVEh8CWHuRhyOOEV1usJ062Agr+E= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 17/24] platform/x86: ideapad-laptop: change 'cfg' debugfs file format Message-ID: <20201216013857.360987-18-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Return -ENODATA when the driver-specific data is not available. Minor formatting changes. Use seq_puts() where possible. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index b1b77eb31779..f5a1d7041aab 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -298,41 +298,44 @@ static int debugfs_cfg_show(struct seq_file *s, void *data) { struct ideapad_private *priv = s->private; - if (!priv) { - seq_printf(s, "cfg: N/A\n"); - } else { - seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ", - priv->cfg); - if (test_bit(CFG_CAP_BT_BIT, &priv->cfg)) - seq_printf(s, "Bluetooth "); - if (test_bit(CFG_CAP_3G_BIT, &priv->cfg)) - seq_printf(s, "3G "); - if (test_bit(CFG_CAP_WIFI_BIT, &priv->cfg)) - seq_printf(s, "Wireless "); - if (test_bit(CFG_CAP_CAM_BIT, &priv->cfg)) - seq_printf(s, "Camera "); - if (test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg)) - seq_printf(s, "Touchpad "); - seq_printf(s, "\nGraphic: "); - switch ((priv->cfg)&0x700) { - case 0x100: - seq_printf(s, "Intel"); - break; - case 0x200: - seq_printf(s, "ATI"); - break; - case 0x300: - seq_printf(s, "Nvidia"); - break; - case 0x400: - seq_printf(s, "Intel and ATI"); - break; - case 0x500: - seq_printf(s, "Intel and Nvidia"); - break; - } - seq_printf(s, "\n"); + if (!priv) + return -ENODATA; + + seq_printf(s, "_CFG: %#010lx\n\n", priv->cfg); + + seq_puts(s, "Capabilities:"); + if (test_bit(CFG_CAP_BT_BIT, &priv->cfg)) + seq_puts(s, " bluetooth"); + if (test_bit(CFG_CAP_3G_BIT, &priv->cfg)) + seq_puts(s, " 3G"); + if (test_bit(CFG_CAP_WIFI_BIT, &priv->cfg)) + seq_puts(s, " wifi"); + if (test_bit(CFG_CAP_CAM_BIT, &priv->cfg)) + seq_puts(s, " camera"); + if (test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg)) + seq_puts(s, " touchpad"); + seq_puts(s, "\n"); + + seq_puts(s, "Graphics:"); + switch (priv->cfg & 0x700) { + case 0x100: + seq_puts(s, "Intel"); + break; + case 0x200: + seq_puts(s, "ATI"); + break; + case 0x300: + seq_puts(s, "Nvidia"); + break; + case 0x400: + seq_puts(s, "Intel and ATI"); + break; + case 0x500: + seq_puts(s, "Intel and Nvidia"); + break; } + seq_puts(s, "\n"); + return 0; } DEFINE_SHOW_ATTRIBUTE(debugfs_cfg); From patchwork Wed Dec 16 01:40:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 490F0C4361B for ; Wed, 16 Dec 2020 01:40:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2197E2311F for ; Wed, 16 Dec 2020 01:40:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725803AbgLPBkw (ORCPT ); Tue, 15 Dec 2020 20:40:52 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:61118 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgLPBkw (ORCPT ); Tue, 15 Dec 2020 20:40:52 -0500 Date: Wed, 16 Dec 2020 01:40:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082827; bh=HJi5AUfMxqtNgTQevF6whXbRqXQamXwhB/LoZiKyVRw=; h=Date:To:From:Reply-To:Subject:From; b=Wx+fAM9XiFI5WIafXaSmIYQDtXNzhWhh7FzJY29IInIGguPNZZgpI7c8jUwmm5T/K rf1h7UGUWogc6mxiH3/aYNGd6vfrCJ+Z4t0DTm+M+HixmZmP82Qt4nBg/WK0+fykDh /2TmzNewSP76bfmcmVMPezhYZmv/deprmvLyq4Hw= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 18/24] Revert "platform/x86: ideapad-laptop: Switch touchpad attribute to be RO" Message-ID: <20201216013857.360987-19-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The touchpad can be enabled/disabled via this attribute on a Lenovo Yoga 520-14IKB. Allow writing as it provides legitimate functionality. This reverts commit 7f363145992cebf4ea760447f1cfdf6f81459683. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index f5a1d7041aab..fda49c236190 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -442,10 +442,9 @@ static ssize_t touchpad_show(struct device *dev, return sysfs_emit(buf, "%lu\n", result); } -/* Switch to RO for now: It might be revisited in the future */ -static ssize_t __maybe_unused touchpad_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t touchpad_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct ideapad_private *priv = dev_get_drvdata(dev); bool state; @@ -461,7 +460,7 @@ static ssize_t __maybe_unused touchpad_store(struct device *dev, return count; } -static DEVICE_ATTR_RO(touchpad); +static DEVICE_ATTR_RW(touchpad); static ssize_t conservation_mode_show(struct device *dev, struct device_attribute *attr, From patchwork Wed Dec 16 01:40:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45828C2BBD5 for ; Wed, 16 Dec 2020 01:42:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E85322D75 for ; Wed, 16 Dec 2020 01:42:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725816AbgLPBmG (ORCPT ); Tue, 15 Dec 2020 20:42:06 -0500 Received: from mail-02.mail-europe.com ([51.89.119.103]:56274 "EHLO mail-02.mail-europe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgLPBmG (ORCPT ); Tue, 15 Dec 2020 20:42:06 -0500 Date: Wed, 16 Dec 2020 01:40:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082839; bh=oF062iN+i3W85DyvyDTZOirSOlF2b4D8QgEa5vgClzY=; h=Date:To:From:Reply-To:Subject:From; b=NYRNfvSvmMzJ0ia0YyoDST6JZ/IA5X+q5pgE790JFS05gpXSzI29AKOUWaaDHSPgm KmD2wZYLkQQdgJU0t65Iu4TOmGpP5n6M9FtBpxlDkET7MiG6QTjT6o3HKYZ8npdmWJ bG+VJV56b1/R+TfqUUHBJV2nOwQ34CLvMI/vkd0s= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 19/24] platform/x86: ideapad-laptop: fix checkpatch warnings, more consistent style Message-ID: <20201216013857.360987-20-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Fix (almost all) checkpatch warnings. Reorder variable definitions from longest to shortest. Add more whitespaces for better readability. Rename variables named `ret` to `err` where appropriate. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index fda49c236190..491cadbf15ec 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -127,13 +127,15 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); static int eval_int(acpi_handle handle, const char *method, unsigned long *val) { - acpi_status acpi_err; unsigned long long result; + acpi_status acpi_err; acpi_err = acpi_evaluate_integer(handle, (char *)method, NULL, &result); if (ACPI_FAILURE(acpi_err)) return -EIO; + *val = result; + return 0; } @@ -165,10 +167,10 @@ static int eval_sals(acpi_handle handle, unsigned long arg) static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *val) { - acpi_status acpi_err; - unsigned long long result; struct acpi_object_list params; + unsigned long long result; union acpi_object in_obj; + acpi_status acpi_err; params.count = 1; params.pointer = &in_obj; @@ -176,12 +178,12 @@ static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *val) in_obj.integer.value = cmd; acpi_err = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); - if (ACPI_FAILURE(acpi_err)) return -EIO; + *val = result; - return 0; + return 0; } static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data) @@ -200,13 +202,14 @@ static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data) acpi_err = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); if (ACPI_FAILURE(acpi_err)) return -EIO; + return 0; } static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data) { + unsigned long end_jiffies, val; int err; - unsigned long int end_jiffies, val; err = eval_vpcw(handle, 1, cmd); if (err) @@ -214,39 +217,51 @@ static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *da for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { + schedule(); + err = eval_vpcr(handle, 1, &val); + if (err) return err; + if (val == 0) return eval_vpcr(handle, 0, data); } + acpi_handle_err(handle, "timeout in %s\n", __func__); + return -ETIMEDOUT; } static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data) { - int err; unsigned long end_jiffies, val; + int err; err = eval_vpcw(handle, 0, data); if (err) return err; + err = eval_vpcw(handle, 1, cmd); if (err) return err; for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { + schedule(); + err = eval_vpcr(handle, 1, &val); if (err) return err; + if (val == 0) return 0; } + acpi_handle_err(handle, "timeout in %s\n", __func__); + return -ETIMEDOUT; } @@ -263,30 +278,40 @@ static int debugfs_status_show(struct seq_file *s, void *data) if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value)) seq_printf(s, "Backlight max:\t%lu\n", value); + if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value)) seq_printf(s, "Backlight now:\t%lu\n", value); + if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value)) seq_printf(s, "BL power value:\t%s (%lu)\n", value ? "on" : "off", value); + seq_puts(s, "=====================\n"); if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value)) seq_printf(s, "Radio status:\t%s (%lu)\n", value ? "on" : "off", value); + if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value)) seq_printf(s, "Wifi status:\t%s (%lu)\n", value ? "on" : "off", value); + if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value)) seq_printf(s, "BT status:\t%s (%lu)\n", value ? "on" : "off", value); + if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value)) seq_printf(s, "3G status:\t%s (%lu)\n", value ? "on" : "off", value); + seq_puts(s, "=====================\n"); if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) seq_printf(s, "Touchpad status:\t%s (%lu)\n", value ? "on" : "off", value); + if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value)) seq_printf(s, "Camera status:\t%s (%lu)\n", value ? "on" : "off", value); + seq_puts(s, "=====================\n"); if (!eval_gbmd(priv->adev->handle, &value)) seq_printf(s, "GBMD: %#010lx\n", value); + if (!eval_hals(priv->adev->handle, &value)) seq_printf(s, "HALS: %#010lx\n", value); @@ -347,8 +372,8 @@ static void ideapad_debugfs_init(struct ideapad_private *priv) dir = debugfs_create_dir("ideapad", NULL); priv->debug = dir; - debugfs_create_file("cfg", S_IRUGO, dir, priv, &debugfs_cfg_fops); - debugfs_create_file("status", S_IRUGO, dir, priv, &debugfs_status_fops); + debugfs_create_file("cfg", 0444, dir, priv, &debugfs_cfg_fops); + debugfs_create_file("status", 0444, dir, priv, &debugfs_status_fops); } static void ideapad_debugfs_exit(struct ideapad_private *priv) @@ -360,73 +385,80 @@ static void ideapad_debugfs_exit(struct ideapad_private *priv) /* * sysfs */ -static ssize_t show_ideapad_cam(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t camera_power_show(struct device *dev, + struct device_attribute *attr, + char *buf) { - unsigned long result; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned long result; int err; err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result); if (err) return err; + return sysfs_emit(buf, "%lu\n", result); } -static ssize_t store_ideapad_cam(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t camera_power_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { - int ret; struct ideapad_private *priv = dev_get_drvdata(dev); unsigned int state; + int err; + + err = kstrtouint(buf, 0, &state); + if (err) + return err; + + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); + if (err) + return err; - ret = kstrtouint(buf, 0, &state); - if (ret) - return ret; - ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); - if (ret) - return ret; return count; } -static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam); +static DEVICE_ATTR_RW(camera_power); -static ssize_t show_ideapad_fan(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t fan_mode_show(struct device *dev, + struct device_attribute *attr, + char *buf) { - unsigned long result; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned long result; int err; err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result); if (err) return err; + return sysfs_emit(buf, "%lu\n", result); } -static ssize_t store_ideapad_fan(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t fan_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { - int ret; struct ideapad_private *priv = dev_get_drvdata(dev); unsigned int state; + int err; + + err = kstrtouint(buf, 0, &state); + if (err) + return err; - ret = kstrtouint(buf, 0, &state); - if (ret) - return ret; if (state > 4 || state == 3) return -EINVAL; - ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); - if (ret) - return ret; + + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); + if (err) + return err; + return count; } -static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan); +static DEVICE_ATTR_RW(fan_mode); static ssize_t touchpad_show(struct device *dev, struct device_attribute *attr, @@ -439,6 +471,7 @@ static ssize_t touchpad_show(struct device *dev, err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); if (err) return err; + return sysfs_emit(buf, "%lu\n", result); } @@ -448,23 +481,24 @@ static ssize_t touchpad_store(struct device *dev, { struct ideapad_private *priv = dev_get_drvdata(dev); bool state; - int ret; + int err; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + err = kstrtobool(buf, &state); + if (err) + return err; + + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); + if (err) + return err; - ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); - if (ret) - return ret; return count; } static DEVICE_ATTR_RW(touchpad); static ssize_t conservation_mode_show(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct ideapad_private *priv = dev_get_drvdata(dev); unsigned long result; @@ -473,25 +507,27 @@ static ssize_t conservation_mode_show(struct device *dev, err = eval_gbmd(priv->adev->handle, &result); if (err) return err; + return sysfs_emit(buf, "%u\n", test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); } static ssize_t conservation_mode_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { struct ideapad_private *priv = dev_get_drvdata(dev); bool state; - int ret; + int err; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + err = kstrtobool(buf, &state); + if (err) + return err; - ret = eval_smbc(priv->adev->handle, + err = eval_smbc(priv->adev->handle, state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF); - if (ret) - return ret; + if (err) + return err; + return count; } @@ -503,10 +539,11 @@ static ssize_t fn_lock_show(struct device *dev, { struct ideapad_private *priv = dev_get_drvdata(dev); unsigned long hals; - int fail = eval_hals(priv->adev->handle, &hals); + int err; - if (fail) - return fail; + err = eval_hals(priv->adev->handle, &hals); + if (err) + return err; return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &hals)); } @@ -517,22 +554,22 @@ static ssize_t fn_lock_store(struct device *dev, { struct ideapad_private *priv = dev_get_drvdata(dev); bool state; - int ret; + int err; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + err = kstrtobool(buf, &state); + if (err) + return err; - ret = eval_sals(priv->adev->handle, + err = eval_sals(priv->adev->handle, state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF); - if (ret) - return ret; + if (err) + return err; + return count; } static DEVICE_ATTR_RW(fn_lock); - static struct attribute *ideapad_attributes[] = { &dev_attr_camera_power.attr, &dev_attr_fan_mode.attr, @@ -615,16 +652,16 @@ static void ideapad_sync_rfk_state(struct ideapad_private *priv) static int ideapad_register_rfkill(struct ideapad_private *priv, int dev) { - int ret; - unsigned long sw_blocked; + unsigned long rf_enabled; + int err; - if (no_bt_rfkill && - (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) { + if (no_bt_rfkill && ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH) { /* Force to enable bluetooth when no_bt_rfkill=1 */ write_ec_cmd(priv->adev->handle, ideapad_rfk_data[dev].opcode, 1); return 0; } + priv->rfk_priv[dev].dev = dev; priv->rfk_priv[dev].priv = priv; @@ -636,19 +673,19 @@ static int ideapad_register_rfkill(struct ideapad_private *priv, int dev) if (!priv->rfk[dev]) return -ENOMEM; - if (read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1, - &sw_blocked)) { - rfkill_init_sw_state(priv->rfk[dev], 0); - } else { - sw_blocked = !sw_blocked; - rfkill_init_sw_state(priv->rfk[dev], sw_blocked); - } + err = read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode - 1, + &rf_enabled); + if (err) + rf_enabled = 1; + + rfkill_init_sw_state(priv->rfk[dev], !rf_enabled); - ret = rfkill_register(priv->rfk[dev]); - if (ret) { + err = rfkill_register(priv->rfk[dev]); + if (err) { rfkill_destroy(priv->rfk[dev]); - return ret; + return err; } + return 0; } @@ -667,7 +704,7 @@ static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev) static int ideapad_sysfs_init(struct ideapad_private *priv) { return sysfs_create_group(&priv->platform_device->dev.kobj, - &ideapad_attribute_group); + &ideapad_attribute_group); } static void ideapad_sysfs_exit(struct ideapad_private *priv) @@ -693,13 +730,13 @@ static const struct key_entry ideapad_keymap[] = { { KE_KEY, 67, { KEY_TOUCHPAD_ON } }, { KE_KEY, 128, { KEY_ESC } }, - { KE_END, 0 }, + { KE_END }, }; static int ideapad_input_init(struct ideapad_private *priv) { struct input_dev *inputdev; - int error; + int err; inputdev = input_allocate_device(); if (!inputdev) @@ -710,15 +747,15 @@ static int ideapad_input_init(struct ideapad_private *priv) inputdev->id.bustype = BUS_HOST; inputdev->dev.parent = &priv->platform_device->dev; - error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); - if (error) { + err = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); + if (err) { dev_err(&priv->platform_device->dev, "Unable to setup input device keymap\n"); goto err_free_dev; } - error = input_register_device(inputdev); - if (error) { + err = input_register_device(inputdev); + if (err) { dev_err(&priv->platform_device->dev, "Unable to register input device\n"); goto err_free_dev; @@ -729,7 +766,7 @@ static int ideapad_input_init(struct ideapad_private *priv) err_free_dev: input_free_device(inputdev); - return error; + return err; } static void ideapad_input_exit(struct ideapad_private *priv) @@ -750,6 +787,7 @@ static void ideapad_input_novokey(struct ideapad_private *priv) if (read_ec_data(priv->adev->handle, VPCCMD_R_NOVO, &long_pressed)) return; + if (long_pressed) ideapad_input_report(priv, 17); else @@ -812,6 +850,7 @@ static int ideapad_backlight_update_status(struct backlight_device *blightdev) blightdev->props.brightness); if (err) return err; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER, blightdev->props.power != FB_BLANK_POWERDOWN); if (err) @@ -872,13 +911,15 @@ static void ideapad_backlight_exit(struct ideapad_private *priv) static void ideapad_backlight_notify_power(struct ideapad_private *priv) { - unsigned long power; struct backlight_device *blightdev = priv->blightdev; + unsigned long power; if (!blightdev) return; + if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power)) return; + blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; } @@ -887,12 +928,10 @@ static void ideapad_backlight_notify_brightness(struct ideapad_private *priv) unsigned long now; /* if we control brightness via acpi video driver */ - if (priv->blightdev == NULL) { + if (!priv->blightdev) read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); - return; - } - - backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY); + else + backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY); } /* @@ -904,13 +943,15 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv) /* Without reading from EC touchpad LED doesn't switch state */ if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) { - /* Some IdeaPads don't really turn off touchpad - they only + unsigned char param; + /* + * Some IdeaPads don't really turn off touchpad - they only * switch the LED state. We (de)activate KBC AUX port to turn * touchpad off and on. We send KEY_TOUCHPAD_OFF and - * KEY_TOUCHPAD_ON to not to get out of sync with LED */ - unsigned char param; - i8042_command(¶m, value ? I8042_CMD_AUX_ENABLE : - I8042_CMD_AUX_DISABLE); + * KEY_TOUCHPAD_ON to not to get out of sync with LED + */ + i8042_command(¶m, + value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE); ideapad_input_report(priv, value ? 67 : 66); } } @@ -954,7 +995,8 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) ideapad_check_special_buttons(priv); break; case 1: - /* Some IdeaPads report event 1 every ~20 + /* + * Some IdeaPads report event 1 every ~20 * seconds while on battery power; some * report this when changing to/from tablet * mode. Squelch this event. @@ -1024,14 +1066,14 @@ static void ideapad_check_features(struct ideapad_private *priv) static int ideapad_acpi_add(struct platform_device *pdev) { - int ret, i; - unsigned long cfg; struct ideapad_private *priv; struct acpi_device *adev; acpi_status acpi_err; + unsigned long cfg; + int err, i; - ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); - if (ret) + err = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); + if (err) return -ENODEV; if (eval_int(adev->handle, "_CFG", &cfg)) @@ -1048,14 +1090,14 @@ static int ideapad_acpi_add(struct platform_device *pdev) ideapad_check_features(priv); - ret = ideapad_sysfs_init(priv); - if (ret) - return ret; + err = ideapad_sysfs_init(priv); + if (err) + return err; ideapad_debugfs_init(priv); - ret = ideapad_input_init(priv); - if (ret) + err = ideapad_input_init(priv); + if (err) goto input_failed; /* @@ -1073,14 +1115,16 @@ static int ideapad_acpi_add(struct platform_device *pdev) ideapad_sync_touchpad_state(priv); if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { - ret = ideapad_backlight_init(priv); - if (ret && ret != -ENODEV) + err = ideapad_backlight_init(priv); + if (err && err != -ENODEV) goto backlight_failed; } + acpi_err = acpi_install_notify_handler(adev->handle, - ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv); + ACPI_DEVICE_NOTIFY, + ideapad_acpi_notify, priv); if (ACPI_FAILURE(acpi_err)) { - ret = -EIO; + err = -EIO; goto notification_failed; } @@ -1093,28 +1137,36 @@ static int ideapad_acpi_add(struct platform_device *pdev) break; } } + if (ACPI_FAILURE(acpi_err) && acpi_err != AE_NOT_EXIST) { - ret = -EIO; + err = -EIO; goto notification_failed_wmi; } #endif return 0; + #if IS_ENABLED(CONFIG_ACPI_WMI) notification_failed_wmi: acpi_remove_notify_handler(priv->adev->handle, - ACPI_DEVICE_NOTIFY, ideapad_acpi_notify); + ACPI_DEVICE_NOTIFY, + ideapad_acpi_notify); #endif + notification_failed: ideapad_backlight_exit(priv); + backlight_failed: for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); + ideapad_input_exit(priv); + input_failed: ideapad_debugfs_exit(priv); ideapad_sysfs_exit(priv); - return ret; + + return err; } static int ideapad_acpi_remove(struct platform_device *pdev) @@ -1126,11 +1178,15 @@ static int ideapad_acpi_remove(struct platform_device *pdev) if (priv->fnesc_guid) wmi_remove_notify_handler(priv->fnesc_guid); #endif + acpi_remove_notify_handler(priv->adev->handle, - ACPI_DEVICE_NOTIFY, ideapad_acpi_notify); + ACPI_DEVICE_NOTIFY, + ideapad_acpi_notify); ideapad_backlight_exit(priv); + for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); + ideapad_input_exit(priv); ideapad_debugfs_exit(priv); ideapad_sysfs_exit(priv); @@ -1145,10 +1201,12 @@ static int ideapad_acpi_resume(struct device *device) if (!device) return -EINVAL; + priv = dev_get_drvdata(device); ideapad_sync_rfk_state(priv); ideapad_sync_touchpad_state(priv); + return 0; } #endif From patchwork Wed Dec 16 01:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5729BC2BBD4 for ; Wed, 16 Dec 2020 01:42:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AA2D230FB for ; Wed, 16 Dec 2020 01:42:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725817AbgLPBmJ (ORCPT ); Tue, 15 Dec 2020 20:42:09 -0500 Received: from mail-03.mail-europe.com ([91.134.188.129]:34828 "EHLO mail-03.mail-europe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgLPBmJ (ORCPT ); Tue, 15 Dec 2020 20:42:09 -0500 Date: Wed, 16 Dec 2020 01:40:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082846; bh=L0/O/uIOQ4Uwarm1brEpqnYZs0EoScnRdlNs9Ryo3Z4=; h=Date:To:From:Reply-To:Subject:From; b=s3Yo5lC3QB9m3a/p+hPPH9wzWN452LMQqbUPV9EtPzXddVl/cOtBE4KN4xHTppJHH K+2WjkXthh153bJsRfSWcQEf87KWdPJ4ghE942PDkbFafVtEEJDn1Vro4smpzL4Ptj c0lNwn8TJrlxLpgCyLaGPTpVcbnPxbzxFPZeNhyQ= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 20/24] platform/x86: ideapad-laptop: send notification about touchpad state change to sysfs Message-ID: <20201216013857.360987-21-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Consumers can determine if the value of an attribute changed much more easily if changes are broadcast using sysfs_notify(), so utilize it. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 491cadbf15ec..075056075b2d 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -953,6 +953,7 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv) i8042_command(¶m, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE); ideapad_input_report(priv, value ? 67 : 66); + sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad"); } } From patchwork Wed Dec 16 01:40:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3050C4361B for ; Wed, 16 Dec 2020 01:41:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C56FE22D75 for ; Wed, 16 Dec 2020 01:41:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725833AbgLPBlg (ORCPT ); Tue, 15 Dec 2020 20:41:36 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:45094 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbgLPBlg (ORCPT ); Tue, 15 Dec 2020 20:41:36 -0500 Date: Wed, 16 Dec 2020 01:40:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082843; bh=SNNA/jJUHx5LZShaJGbm+Lh0h+qnbxD1WMNynpqX81w=; h=Date:To:From:Reply-To:Subject:From; b=JuAsOi2rYN6N3WR64nzQD0z6hy6dW++71u5UhLkOJpPMk3NQcCqFXbGBnZ5ZIqYFP MO77j8F/Q6WsaVyi/bWAyII6G9QV9wdnO6m6/K6nRAbS+rdVPTofQ9awLzHgUx/BDb txVOwVH2KrvVCoxlIXwzcKP/M9vFIsJ5lFz98WJk= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 21/24] platform/x86: ideapad-laptop: add keyboard backlight control support Message-ID: <20201216013857.360987-22-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org On certain models it is possible to control/query the keyboard backlight via the SALS/HALS ACPI methods. Add support for that, and register an LED class device to expose this functionality. Tested on: Lenovo YOGA 520-14IKB 80X8 Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 075056075b2d..a43574e65f61 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -9,6 +9,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -56,12 +58,16 @@ enum { }; enum { + HALS_KBD_BL_SUPPORT_BIT = 4, + HALS_KBD_BL_STATE_BIT = 5, HALS_FNLOCK_SUPPORT_BIT = 9, HALS_FNLOCK_STATE_BIT = 10, HALS_HOTKEYS_PRIMARY_BIT = 11, }; enum { + SALS_KBD_BL_ON = 0x8, + SALS_KBD_BL_OFF = 0x9, SALS_FNLOCK_ON = 0xe, SALS_FNLOCK_OFF = 0xf, }; @@ -114,6 +120,11 @@ struct ideapad_private { fn_lock : 1, hw_rfkill_switch : 1; } features; + struct { + bool initialized; + struct led_classdev led; + unsigned int last_brightness; + } kbd_bl; }; static bool no_bt_rfkill; @@ -934,6 +945,110 @@ static void ideapad_backlight_notify_brightness(struct ideapad_private *priv) backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY); } +/* + * keyboard backlight + */ +static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv) +{ + unsigned long hals; + int err; + + err = eval_hals(priv->adev->handle, &hals); + if (err) + return err; + + return test_bit(HALS_KBD_BL_STATE_BIT, &hals); +} + +static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct led_classdev *led_cdev) +{ + struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led); + + return ideapad_kbd_bl_brightness_get(priv); +} + +static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, unsigned int brightness) +{ + int err; + + err = eval_sals(priv->adev->handle, + brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF); + if (err) + return err; + + priv->kbd_bl.last_brightness = brightness; + + return 0; +} + +static int ideapad_kbd_bl_led_cdev_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led); + + return ideapad_kbd_bl_brightness_set(priv, brightness); +} + +static void ideapad_kbd_bl_notify(struct ideapad_private *priv) +{ + int brightness; + + if (!priv->kbd_bl.initialized) + return; + + brightness = ideapad_kbd_bl_brightness_get(priv); + if (brightness < 0) + return; + + if (brightness == priv->kbd_bl.last_brightness) + return; + + priv->kbd_bl.last_brightness = brightness; + + led_classdev_notify_brightness_hw_changed(&priv->kbd_bl.led, brightness); +} + +static int ideapad_kbd_bl_init(struct ideapad_private *priv) +{ + unsigned long hals; + int err; + + err = eval_hals(priv->adev->handle, &hals); + if (err) + return err; + + if (!test_bit(HALS_KBD_BL_SUPPORT_BIT, &hals)) + return -ENODEV; + + err = ideapad_kbd_bl_brightness_get(priv); + if (err < 0) + return err; + + priv->kbd_bl.last_brightness = err; + + priv->kbd_bl.led.name = "platform::" LED_FUNCTION_KBD_BACKLIGHT; + priv->kbd_bl.led.max_brightness = 1; + priv->kbd_bl.led.brightness_get = ideapad_kbd_bl_led_cdev_brightness_get; + priv->kbd_bl.led.brightness_set_blocking = ideapad_kbd_bl_led_cdev_brightness_set; + priv->kbd_bl.led.flags = LED_BRIGHT_HW_CHANGED; + + err = led_classdev_register(&priv->platform_device->dev, &priv->kbd_bl.led); + if (err) + return err; + + priv->kbd_bl.initialized = true; + + return 0; +} + +static void ideapad_kbd_bl_exit(struct ideapad_private *priv) +{ + if (!priv->kbd_bl.initialized) + return; + + led_classdev_unregister(&priv->kbd_bl.led); +} + /* * module init/exit */ @@ -1000,8 +1115,9 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) * Some IdeaPads report event 1 every ~20 * seconds while on battery power; some * report this when changing to/from tablet - * mode. Squelch this event. + * mode. */ + ideapad_kbd_bl_notify(priv); break; default: dev_warn(&priv->platform_device->dev, @@ -1101,6 +1217,11 @@ static int ideapad_acpi_add(struct platform_device *pdev) if (err) goto input_failed; + err = ideapad_kbd_bl_init(priv); + if (err && err != -ENODEV) + dev_warn(&pdev->dev, + "Could not register keyboard backlight led: %d\n", err); + /* * On some models without a hw-switch (the yoga 2 13 at least) * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work. @@ -1161,6 +1282,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); + ideapad_kbd_bl_exit(priv); ideapad_input_exit(priv); input_failed: @@ -1188,6 +1310,7 @@ static int ideapad_acpi_remove(struct platform_device *pdev) for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); + ideapad_kbd_bl_exit(priv); ideapad_input_exit(priv); ideapad_debugfs_exit(priv); ideapad_sysfs_exit(priv); From patchwork Wed Dec 16 01:40:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2F0DC2BBCF for ; Wed, 16 Dec 2020 01:42:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C783422D75 for ; Wed, 16 Dec 2020 01:42:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725786AbgLPBls (ORCPT ); Tue, 15 Dec 2020 20:41:48 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:18514 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgLPBls (ORCPT ); Tue, 15 Dec 2020 20:41:48 -0500 Date: Wed, 16 Dec 2020 01:40:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082851; bh=m/4mDecNAFwWp4FOVItvUsnlVzJlQgrHmWND0EIwl34=; h=Date:To:From:Reply-To:Subject:From; b=VXKc8pZ/c/J7TiSMwqBse3cMyA4ND0/H6R3Pt4ACg33ftYsDSAL7e07gnEh3jKo1x /l0Z/Wgd7k4Q/jsc3ATfp+40HmSDuhU9fMLiJvhTzp9Y30T9OPVf30PPsqgosuId7K gNdzUOxf7QUc6uUICWppzNBIxdHYrIi13UXbKDT8= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 22/24] platform/x86: ideapad-laptop: add "always on USB charging" control support Message-ID: <20201216013857.360987-23-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Certain models have a so-called "always on USB charging" feature, which enables USB charging even when the computer is turned off or suspended, and which may be controlled/queried using the SALS/HALS ACPI methods. Expose this functionality via a new device attribute (usb_charging). Tested on: Lenovo YOGA 520-14IKB 80X8 Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index a43574e65f61..5f7883e59f21 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -58,18 +58,22 @@ enum { }; enum { - HALS_KBD_BL_SUPPORT_BIT = 4, - HALS_KBD_BL_STATE_BIT = 5, - HALS_FNLOCK_SUPPORT_BIT = 9, - HALS_FNLOCK_STATE_BIT = 10, - HALS_HOTKEYS_PRIMARY_BIT = 11, + HALS_KBD_BL_SUPPORT_BIT = 4, + HALS_KBD_BL_STATE_BIT = 5, + HALS_USB_CHARGING_SUPPORT_BIT = 6, + HALS_USB_CHARGING_STATE_BIT = 7, + HALS_FNLOCK_SUPPORT_BIT = 9, + HALS_FNLOCK_STATE_BIT = 10, + HALS_HOTKEYS_PRIMARY_BIT = 11, }; enum { - SALS_KBD_BL_ON = 0x8, - SALS_KBD_BL_OFF = 0x9, - SALS_FNLOCK_ON = 0xe, - SALS_FNLOCK_OFF = 0xf, + SALS_KBD_BL_ON = 0x8, + SALS_KBD_BL_OFF = 0x9, + SALS_USB_CHARGING_ON = 0xa, + SALS_USB_CHARGING_OFF = 0xb, + SALS_FNLOCK_ON = 0xe, + SALS_FNLOCK_OFF = 0xf, }; enum { @@ -118,6 +122,7 @@ struct ideapad_private { bool fan_mode : 1, conservation_mode : 1, fn_lock : 1, + usb_charging : 1, hw_rfkill_switch : 1; } features; struct { @@ -581,12 +586,50 @@ static ssize_t fn_lock_store(struct device *dev, static DEVICE_ATTR_RW(fn_lock); +static ssize_t usb_charging_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned long hals; + int err; + + err = eval_hals(priv->adev->handle, &hals); + if (err) + return err; + + return sysfs_emit(buf, "%u\n", test_bit(HALS_USB_CHARGING_STATE_BIT, &hals)); +} + +static ssize_t usb_charging_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ideapad_private *priv = dev_get_drvdata(dev); + bool state; + int err; + + err = kstrtobool(buf, &state); + if (err) + return err; + + err = eval_sals(priv->adev->handle, + state ? SALS_USB_CHARGING_ON : SALS_USB_CHARGING_OFF); + if (err) + return err; + + return count; +} + +static DEVICE_ATTR_RW(usb_charging); + static struct attribute *ideapad_attributes[] = { &dev_attr_camera_power.attr, &dev_attr_fan_mode.attr, &dev_attr_touchpad.attr, &dev_attr_conservation_mode.attr, &dev_attr_fn_lock.attr, + &dev_attr_usb_charging.attr, NULL }; @@ -608,6 +651,8 @@ static umode_t ideapad_is_visible(struct kobject *kobj, supported = priv->features.conservation_mode; else if (attr == &dev_attr_fn_lock.attr) supported = priv->features.fn_lock; + else if (attr == &dev_attr_usb_charging.attr) + supported = priv->features.usb_charging; return supported ? attr->mode : 0; } @@ -1175,9 +1220,13 @@ static void ideapad_check_features(struct ideapad_private *priv) priv->features.conservation_mode = true; if (acpi_has_method(handle, "HALS") && acpi_has_method(handle, "SALS")) { - if (!eval_hals(handle, &val)) + if (!eval_hals(handle, &val)) { if (test_bit(HALS_FNLOCK_SUPPORT_BIT, &val)) priv->features.fn_lock = true; + + if (test_bit(HALS_USB_CHARGING_SUPPORT_BIT, &val)) + priv->features.usb_charging = true; + } } } From patchwork Wed Dec 16 01:40:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D45EFC2BB48 for ; Wed, 16 Dec 2020 01:42:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E3B6230FC for ; Wed, 16 Dec 2020 01:42:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725287AbgLPBlm (ORCPT ); Tue, 15 Dec 2020 20:41:42 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:62151 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbgLPBlm (ORCPT ); Tue, 15 Dec 2020 20:41:42 -0500 Date: Wed, 16 Dec 2020 01:40:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082859; bh=a6ezRSEkPZZDlI1kU1jtxHxCet1zV+SE0ulPf/JjXx0=; h=Date:To:From:Reply-To:Subject:From; b=pVWXvx6LCvlCbIfqXbVXmSYT79U2vNwiEs+CQk5DPe7hS1FZWycsq/3XtgJbZL0bV 11WNzs6J1QuI2PIWHxpIBm4U5UvmlDvwcFu+CszAe/TLaV8Az93zSfubKZq774zPQI r4UHCIkihL/+AptNrzC2Abw3yE0aMWdn+FLkbPp4= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 23/24] Documentation/ABI: sysfs-platform-ideapad-laptop: update device attribute paths Message-ID: <20201216013857.360987-24-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The documentation referred to non-existent device attributes under a non-existent platform device. Update it with the current location of the attributes. Signed-off-by: Barnabás Pőcze diff --git a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop index fd2ac02bc5bd..e024678947c8 100644 --- a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop +++ b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop @@ -1,11 +1,11 @@ -What: /sys/devices/platform/ideapad/camera_power +What: /sys/bus/platform/devices/VPC2004:*/camera_power Date: Dec 2010 KernelVersion: 2.6.37 Contact: "Ike Panhc " Description: Control the power of camera module. 1 means on, 0 means off. -What: /sys/devices/platform/ideapad/fan_mode +What: /sys/bus/platform/devices/VPC2004:*/fan_mode Date: June 2012 KernelVersion: 3.6 Contact: "Maxim Mikityanskiy " @@ -18,7 +18,7 @@ Description: * 2 -> Dust Cleaning * 4 -> Efficient Thermal Dissipation Mode -What: /sys/devices/platform/ideapad/touchpad +What: /sys/bus/platform/devices/VPC2004:*/touchpad Date: May 2017 KernelVersion: 4.13 Contact: "Ritesh Raj Sarraf " @@ -27,7 +27,7 @@ Description: * 1 -> Switched On * 0 -> Switched Off -What: /sys/bus/pci/devices///VPC2004:00/fn_lock +What: /sys/bus/platform/devices/VPC2004:*/fn_lock Date: May 2018 KernelVersion: 4.18 Contact: "Oleg Keri " From patchwork Wed Dec 16 01:40:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11976151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 326A9C2BBCD for ; Wed, 16 Dec 2020 01:42:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1868230FB for ; Wed, 16 Dec 2020 01:42:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725782AbgLPBlv (ORCPT ); Tue, 15 Dec 2020 20:41:51 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:19234 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgLPBlu (ORCPT ); Tue, 15 Dec 2020 20:41:50 -0500 Date: Wed, 16 Dec 2020 01:40:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608082868; bh=ZDOaGZO1FZvYUEx2WVnib8Vp9DM8TW1tS+rpK8EWb9I=; h=Date:To:From:Reply-To:Subject:From; b=KCq8EZPCSMfUQbM+D09EdgNsflWniKdi4K9Kt+s6dXWP4+t4aULyXkSR5z8goLHVw brBdwyIE1/N8QiRf3R1hfUwv8RP9D/mHK9I0l5ufqekXMQlPwHpBmzm71SxJv8X3bk Ejo6aM9qVDB1tBFXElXsWMsRCTRRkHtLXuUUWmoM= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 24/24] Documentation/ABI: sysfs-platform-ideapad-laptop: conservation_mode and usb_charging Message-ID: <20201216013857.360987-25-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Document the conservation_mode and usb_charging attributes provided by the ideapad-laptop module. Signed-off-by: Barnabás Pőcze diff --git a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop index e024678947c8..c5aad51a8b7c 100644 --- a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop +++ b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop @@ -27,6 +27,15 @@ Description: * 1 -> Switched On * 0 -> Switched Off +What: /sys/bus/platform/devices/VPC2004:*/conservation_mode +Date: Aug 2017 +KernelVersion: 4.14 +Contact: platform-driver-x86@vger.kernel.org +Description: + Controls whether the conservation mode is enabled or not. + This feature limits the maximum battery charge percentage to + around 50-60% in order to prolong the lifetime of the battery. + What: /sys/bus/platform/devices/VPC2004:*/fn_lock Date: May 2018 KernelVersion: 4.18 @@ -41,3 +50,12 @@ Description: # echo "0" > \ /sys/bus/pci/devices/0000:00:1f.0/PNP0C09:00/VPC2004:00/fn_lock + +What: /sys/bus/platform/devices/VPC2004:*/usb_charging +Date: Dec 2020 +KernelVersion: 5.11 +Contact: platform-driver-x86@vger.kernel.org +Description: + Controls whether the "always on USB charging" feature is + enabled or not. This features enables charging USB devices + even if the computer is not turned on.