From patchwork Wed Feb 3 21:54:16 2021 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: 12065419 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 5CB85C433E0 for ; Wed, 3 Feb 2021 21:55:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1016864E4E for ; Wed, 3 Feb 2021 21:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231865AbhBCVzA (ORCPT ); Wed, 3 Feb 2021 16:55:00 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:34416 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231807AbhBCVzA (ORCPT ); Wed, 3 Feb 2021 16:55:00 -0500 Date: Wed, 03 Feb 2021 21:54:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389257; bh=5gAqn1Uyyzp6MO4df2yrBHmNngOgwJaLQf2Gis59Edo=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=n0zfcP2KxztNUEw6050BmNOWjqZhNXtYU1ml4PmJK7b4HPiCliT/3qG3eZztQbETG gbiwVBlWwIa3WJVCLmEvgqXLX7sCaJFXuZZ+U1FNaLUQ2d9LPEZSxYo9LdL52gF93X FNTEFfY+HK2VUQYGuCXmscfdPYrsbAUWYSC/Ix18= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 01/29] platform/x86: ideapad-laptop: remove unnecessary dev_set_drvdata() call Message-ID: <20210203215403.290792-2-pobrn@protonmail.com> In-Reply-To: <20210203215403.290792-1-pobrn@protonmail.com> References: <20210203215403.290792-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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index cc42af2a0a98..18c71e28ebc8 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -1369,7 +1369,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 Feb 3 21:54:23 2021 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: 12065423 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 D01D3C433E0 for ; Wed, 3 Feb 2021 21:55:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89DCC64E4E for ; Wed, 3 Feb 2021 21:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231318AbhBCVzM (ORCPT ); Wed, 3 Feb 2021 16:55:12 -0500 Received: from mail1.protonmail.ch ([185.70.40.18]:36457 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbhBCVzM (ORCPT ); Wed, 3 Feb 2021 16:55:12 -0500 Date: Wed, 03 Feb 2021 21:54:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389268; bh=f+s3FKUUVIlhtTL6sCAW7iQ8CbpTkQoqYumsK5ubpmo=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=tRpCTRyPQQO87NpJ3iitPt1UxXd556Wsnq09rbYVDstNmYUl/4za33kAGZRznXphD OIWQT+QL1Y/u//pNXXdMCuDfQapdESO8i8v5YuA0TDolkdsLR8J6z3aYG1w6Zt5B55 DSIN7LLZUp3YpXuBAs8tvyHWpGZlBAOJHLbHQRag= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 02/29] platform/x86: ideapad-laptop: remove unnecessary NULL checks Message-ID: <20210203215403.290792-3-pobrn@protonmail.com> In-Reply-To: <20210203215403.290792-1-pobrn@protonmail.com> References: <20210203215403.290792-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The checks that are removed test pointers which should not be NULL. If they are NULL, that indicates a bug in a different part of the kernel. Instead of silently bailing out, let it fail loudly. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 18c71e28ebc8..415d362a642a 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -264,9 +264,6 @@ static int debugfs_status_show(struct seq_file *s, void *data) struct ideapad_private *priv = s->private; unsigned long value; - if (!priv) - return -EINVAL; - 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)) @@ -311,39 +308,36 @@ 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_BT_BIT, &priv->cfg)) - seq_printf(s, "Bluetooth "); - if (test_bit(CFG_3G_BIT, &priv->cfg)) - seq_printf(s, "3G "); - if (test_bit(CFG_WIFI_BIT, &priv->cfg)) - seq_printf(s, "Wireless "); - if (test_bit(CFG_CAMERA_BIT, &priv->cfg)) - seq_printf(s, "Camera "); - 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"); + seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ", + priv->cfg); + if (test_bit(CFG_BT_BIT, &priv->cfg)) + seq_printf(s, "Bluetooth "); + if (test_bit(CFG_3G_BIT, &priv->cfg)) + seq_printf(s, "3G "); + if (test_bit(CFG_WIFI_BIT, &priv->cfg)) + seq_printf(s, "Wireless "); + if (test_bit(CFG_CAMERA_BIT, &priv->cfg)) + seq_printf(s, "Camera "); + 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"); + return 0; } DEFINE_SHOW_ATTRIBUTE(debugfs_cfg); @@ -1050,9 +1044,6 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev) struct ideapad_private *priv = bl_get_data(blightdev); unsigned long now; - if (!priv) - return -EINVAL; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now)) return -EIO; return now; @@ -1062,9 +1053,6 @@ static int ideapad_backlight_update_status(struct backlight_device *blightdev) { struct ideapad_private *priv = bl_get_data(blightdev); - if (!priv) - return -EINVAL; - if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL, blightdev->props.brightness)) return -EIO; @@ -1374,13 +1362,9 @@ static int ideapad_acpi_remove(struct platform_device *pdev) } #ifdef CONFIG_PM_SLEEP -static int ideapad_acpi_resume(struct device *device) +static int ideapad_acpi_resume(struct device *dev) { - struct ideapad_private *priv; - - if (!device) - return -EINVAL; - priv = dev_get_drvdata(device); + struct ideapad_private *priv = dev_get_drvdata(dev); ideapad_sync_rfk_state(priv); ideapad_sync_touchpad_state(priv); From patchwork Wed Feb 3 21:54:30 2021 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: 12065425 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 237AEC433DB for ; Wed, 3 Feb 2021 21:55:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE71864DA3 for ; Wed, 3 Feb 2021 21:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231807AbhBCVzX (ORCPT ); Wed, 3 Feb 2021 16:55:23 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:51985 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbhBCVzR (ORCPT ); Wed, 3 Feb 2021 16:55:17 -0500 Date: Wed, 03 Feb 2021 21:54:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389275; bh=EkuQhPTwsgios21TGbBlmurmq797cuqHZ37F+Hax0n0=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=UJ1CkW79tYxTw45TeTMBel/25AAJkE/yuBhx2+eGQyF6OGfsRe0zuMglG1TlU2kfQ aUJ0VN90yRo+xW8C5YcaGSUtqIPeIP17tuACg72TREryg6EZvdN+FJBmFvziR3YOZY N8WffISJPOJp0fTgKgw9xXZK+7E5gYNVdep0KpMM= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 03/29] platform/x86: ideapad-laptop: use appropriately typed variable to store the return value of ACPI methods Message-ID: <20210203215403.290792-4-pobrn@protonmail.com> In-Reply-To: <20210203215403.290792-1-pobrn@protonmail.com> References: <20210203215403.290792-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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 415d362a642a..6c1ed5153a37 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -1247,6 +1247,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) int cfg; struct ideapad_private *priv; struct acpi_device *adev; + acpi_status status; ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); if (ret) @@ -1303,22 +1304,27 @@ 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) + status = acpi_install_notify_handler(adev->handle, + ACPI_DEVICE_NOTIFY, + ideapad_acpi_notify, priv); + if (ACPI_FAILURE(status)) { + 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) { + status = wmi_install_notify_handler(ideapad_wmi_fnesc_events[i], + ideapad_wmi_notify, priv); + if (ACPI_SUCCESS(status)) { priv->fnesc_guid = ideapad_wmi_fnesc_events[i]; break; } } - if (ret != AE_OK && ret != AE_NOT_EXIST) + if (ACPI_FAILURE(status) && status != AE_NOT_EXIST) { + ret = -EIO; goto notification_failed_wmi; + } #endif return 0; From patchwork Wed Feb 3 21:54:36 2021 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: 12065427 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 19BDCC433E6 for ; Wed, 3 Feb 2021 21:55:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5F6764E4E for ; Wed, 3 Feb 2021 21:55:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbhBCVzZ (ORCPT ); Wed, 3 Feb 2021 16:55:25 -0500 Received: from mail-40136.protonmail.ch ([185.70.40.136]:10997 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231467AbhBCVzY (ORCPT ); Wed, 3 Feb 2021 16:55:24 -0500 Date: Wed, 03 Feb 2021 21:54:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389281; bh=T3ugBCX4TFAf26kXNuKtpVS5/dvFV1Zc5GJK+FnEgRg=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=djtSMata//yzU7U6mllcqdQ9E7wJYuOPmWnv3lNFe/OIAGt2Fa3Pao8u1GVcUoxOL ifNzIdhhSYieosh4Cd1XxLS8/oOj4h9KwlB+G6SF9Fa39juOcRou8QG1BeeWnEml0f EbRFxbweLw1/ybQIiliDOSg/7l75EKr9TswEcc5Q= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 04/29] platform/x86: ideapad-laptop: sort includes lexicographically Message-ID: <20210203215403.290792-5-pobrn@protonmail.com> In-Reply-To: <20210203215403.290792-1-pobrn@protonmail.com> References: <20210203215403.290792-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 Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 6c1ed5153a37..e3016c18e88e 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -8,23 +8,24 @@ #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 Feb 3 21:54:43 2021 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: 12065429 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 660BBC433DB for ; Wed, 3 Feb 2021 21:55:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 106E664F9A for ; Wed, 3 Feb 2021 21:55:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232201AbhBCVzb (ORCPT ); Wed, 3 Feb 2021 16:55:31 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:41423 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232108AbhBCVz2 (ORCPT ); Wed, 3 Feb 2021 16:55:28 -0500 Date: Wed, 03 Feb 2021 21:54:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389286; bh=qhmXq/5bkOhV9BvAXs4K914G776z1Hr2na4WW8M20/U=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=NJcAcmtegKlDjDdQQWUPqbGMl58pza/jhplwx4BU/hOV0mzfRbjFxToup/0BXIS7U 3HUdSjPteMtNuDaA8y5hkNcVN+PjZf/hMep297hgnR0wyM6VQy0QB7mZvL1hElU0a6 66NlFE4ORihwwsRPBXkdung8Qmgiom06cAYdkBlw= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 05/29] platform/x86: ideapad-laptop: add missing call to submodule destructor Message-ID: <20210203215403.290792-6-pobrn@protonmail.com> In-Reply-To: <20210203215403.290792-1-pobrn@protonmail.com> References: <20210203215403.290792-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org ideapad_dytc_profile_exit() is not called in ideapad_acpi_add() in the error path. Add the missing call. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index e3016c18e88e..7ee5ac662f80 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -1337,6 +1337,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) notification_failed: ideapad_backlight_exit(priv); backlight_failed: + ideapad_dytc_profile_exit(priv); for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); ideapad_input_exit(priv); From patchwork Wed Feb 3 21:54:56 2021 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: 12065431 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 E5C93C43381 for ; Wed, 3 Feb 2021 21:55:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C56964FA1 for ; Wed, 3 Feb 2021 21:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232239AbhBCVzm (ORCPT ); Wed, 3 Feb 2021 16:55:42 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:17297 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbhBCVzl (ORCPT ); Wed, 3 Feb 2021 16:55:41 -0500 Date: Wed, 03 Feb 2021 21:54:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389299; bh=ykhvblhKmUjGKt2G35opDACkKEzDfyLq4Bd9STMQwHc=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=ABWBut1u8Qjpok+2OWGyMT2mpMtaCUouGDzG2ID+xQ+EKHqGnqgTNOz05s03elB79 X/jWi4BW3QYoViu1XD5pXpCXTD/A/FyuOW1xY40sRcwXWUz4r7u7PhBFoYA8ThPGBg C5BDWQCIpEUKHj8riOH1U1T7OdvxyDcNG0LsTm9c= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 06/29] platform/x86: ideapad-laptop: use sysfs_emit() Message-ID: <20210203215403.290792-7-pobrn@protonmail.com> In-Reply-To: <20210203215403.290792-1-pobrn@protonmail.com> References: <20210203215403.290792-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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 7ee5ac662f80..1a91588399f5 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -371,8 +372,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, @@ -402,8 +403,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, @@ -435,8 +436,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 */ @@ -468,8 +469,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, @@ -504,10 +505,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 Feb 3 21:55:05 2021 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: 12065433 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 9A61BC433DB for ; Wed, 3 Feb 2021 21:56:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FB4B64E46 for ; Wed, 3 Feb 2021 21:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232246AbhBCVzx (ORCPT ); Wed, 3 Feb 2021 16:55:53 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:14442 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbhBCVzu (ORCPT ); Wed, 3 Feb 2021 16:55:50 -0500 Date: Wed, 03 Feb 2021 21:55:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389309; bh=uhVsg3wUltw4ZQwVc85owA2LXpbtaeadZAEmUDAT9SE=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=ICvsH8Fxao3nm50ePKMHCwwU89cwP4SqQnjIKY6DbOY2V+0z0IDZCtpA9n8r3RTK9 8BGDBTxTkz5fGyZPxaEFPPIkZ2C/j3x78De827EJYHQOMOkTowLe5H4Hi9LUdla0r3 Ho+LMfx+0jPHVeZGLW9lvNcKiU/0n3V1gl96Iqb0= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 07/29] platform/x86: ideapad-laptop: use device_{add,remove}_group Message-ID: <20210203215403.290792-8-pobrn@protonmail.com> In-Reply-To: <20210203215403.290792-1-pobrn@protonmail.com> References: <20210203215403.290792-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Use device_{add,remove}_group instead of sysfs_{add,remove}_group. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 1a91588399f5..2153688012c3 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -924,14 +924,14 @@ 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); + return device_add_group(&priv->platform_device->dev, + &ideapad_attribute_group); } static void ideapad_sysfs_exit(struct ideapad_private *priv) { - sysfs_remove_group(&priv->platform_device->dev.kobj, - &ideapad_attribute_group); + device_remove_group(&priv->platform_device->dev, + &ideapad_attribute_group); } /* From patchwork Wed Feb 3 21:55:15 2021 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: 12065435 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 B2064C433E0 for ; Wed, 3 Feb 2021 21:56:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7726C64DA3 for ; Wed, 3 Feb 2021 21:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232249AbhBCV4D (ORCPT ); Wed, 3 Feb 2021 16:56:03 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:30676 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbhBCV4D (ORCPT ); Wed, 3 Feb 2021 16:56:03 -0500 Date: Wed, 03 Feb 2021 21:55:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389320; bh=x3aQRgl913VT8FHvqljlHG/7oeM3UXs7wLFITXQCmd8=; h=Date:To:From:Reply-To:Subject:From; b=l7K/BRMpeB0t/zizbMdTvDLG4dqi9Nwr4yq/qSpjvxS1xRKX1sAHE6kjgwAVbpvcj yICtmAQ5owHgloh5nnWhWqB6KxsaTq5Mrwjvcja6lNZahO/ze8LpIODxtt1fOQEoHn xyTr06hwRHbzyQFPjMcq+jjYqnsnSucbh4AaPY9s= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 08/29] platform/x86: ideapad-laptop: use kobj_to_dev() Message-ID: <20210203215403.290792-9-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Use kobj_to_dev() instead of open-coding the container_of() macro. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 2153688012c3..30ea97143567 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -547,7 +547,7 @@ static umode_t ideapad_is_visible(struct kobject *kobj, struct attribute *attr, int idx) { - struct device *dev = container_of(kobj, struct device, kobj); + struct device *dev = kobj_to_dev(kobj); struct ideapad_private *priv = dev_get_drvdata(dev); bool supported; From patchwork Wed Feb 3 21:55:21 2021 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: 12065437 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 CA654C433E6 for ; Wed, 3 Feb 2021 21:56:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74E7964F74 for ; Wed, 3 Feb 2021 21:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232279AbhBCV4V (ORCPT ); Wed, 3 Feb 2021 16:56:21 -0500 Received: from mail-40136.protonmail.ch ([185.70.40.136]:28123 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232270AbhBCV4L (ORCPT ); Wed, 3 Feb 2021 16:56:11 -0500 Date: Wed, 03 Feb 2021 21:55:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389328; bh=yPZwJ1R12939t2HLBgqQcdWgI3iD3zxvfJsHHi+lZ5s=; h=Date:To:From:Reply-To:Subject:From; b=lVKrqkLaI4bY7sA3VwwfekdlZhu+88iDKkjqP5D63OeUO7UOR/+YAhRaw2Xa6TZCh iwkKyv+lQxLLQ5/qoCpjKOwCesRPhd2Z9+H9hOoovWvnIKq9ASQzH76k5mnLVmCx6B huX8qkZZRW9OmwT6SJboyzZEEi7+RLGtadgvuf8Q= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 09/29] platform/x86: ideapad-laptop: use for_each_set_bit() helper to simplify event processing Message-ID: <20210203215403.290792-10-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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 30ea97143567..5978770bac2a 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -1018,22 +1019,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; } } } @@ -1161,7 +1160,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; @@ -1169,44 +1168,43 @@ 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 Feb 3 21:55:27 2021 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: 12065441 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 647E5C43331 for ; Wed, 3 Feb 2021 21:56:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B3CF64E4E for ; Wed, 3 Feb 2021 21:56:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231775AbhBCV40 (ORCPT ); Wed, 3 Feb 2021 16:56:26 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:38261 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232324AbhBCV4U (ORCPT ); Wed, 3 Feb 2021 16:56:20 -0500 Date: Wed, 03 Feb 2021 21:55:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389335; bh=5BojEyWqgjIwpmsO6GiMVDIqgbvxL5yh3ZgG6Fg1kdM=; h=Date:To:From:Reply-To:Subject:From; b=Ma2h6TWoKglZN2HtzzFk87CwqrPVIzGawR283Muwn7w4F6LQuS+OySDKKc62tdFfx cJhAx/UQZRcgP1TDEiKeMMGNbYXSmEOHqV3FYEt5YARzqGepQbo/j0kQRO2r8fTRbT IeReXdg81JHMeMK/R/CMlbyLXl18JJdXZMO1FGnY= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 10/29] platform/x86: ideapad-laptop: use msecs_to_jiffies() helper instead of hand-crafted formula Message-ID: <20210203215403.290792-11-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 formula to convert milliseconds to jiffies, replace it with the msecs_to_jiffies() function. Furthermore, use a while loop instead of for loop for shorter lines and simplicity. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 5978770bac2a..bb7eb9c1f0ec 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -221,8 +222,9 @@ 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; - time_before(jiffies, end_jiffies);) { + end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; + + while (time_before(jiffies, end_jiffies)) { schedule(); if (method_vpcr(handle, 1, &val)) return -1; @@ -247,8 +249,9 @@ 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; - time_before(jiffies, end_jiffies);) { + end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; + + while (time_before(jiffies, end_jiffies)) { schedule(); if (method_vpcr(handle, 1, &val)) return -1; From patchwork Wed Feb 3 21:55:32 2021 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: 12065439 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 262ACC4332B for ; Wed, 3 Feb 2021 21:56:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 035A864F6B for ; Wed, 3 Feb 2021 21:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232313AbhBCV4V (ORCPT ); Wed, 3 Feb 2021 16:56:21 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:29902 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232319AbhBCV4U (ORCPT ); Wed, 3 Feb 2021 16:56:20 -0500 Date: Wed, 03 Feb 2021 21:55:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389334; bh=chIH/ghy4eLyGIh7IItlDQm6hmoPy8z/b8igGxILJfQ=; h=Date:To:From:Reply-To:Subject:From; b=NwTO/m6vXS+IwBF8aIFqZALjzXLBgxcgIPsGyc/cs+j2EJE7TxL4mAc7k6kNFqEmw sOmCuH5pD0GZM4+z5AsBoshtShO+cm6aMJ423TNibkeEhCSfnDEPEz+9wEM2DC4C04 Q86i7Ro3+x2l/NuDYfKPHLYuUrUTiNU9+O8BTV9c= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 11/29] platform/x86: ideapad-laptop: use dev_{err,warn} or appropriate variant to display log messages Message-ID: <20210203215403.290792-12-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 bb7eb9c1f0ec..1aa3a05c3360 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -235,7 +235,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; } @@ -258,7 +258,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; } @@ -974,13 +974,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; } @@ -1034,7 +1036,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_info(&priv->platform_device->dev, + "Unknown special button: %lu\n", bit); break; } } @@ -1094,7 +1097,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_err(&priv->platform_device->dev, + "Could not register backlight device\n"); return PTR_ERR(blightdev); } @@ -1207,7 +1211,8 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) */ break; default: - pr_info("Unknown event: %lu\n", bit); + dev_info(&priv->platform_device->dev, + "Unknown event: %lu\n", bit); } } } @@ -1215,12 +1220,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_info(&priv->platform_device->dev, + "Unknown WMI event: %u\n", value); } } #endif From patchwork Wed Feb 3 21:55:37 2021 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: 12065443 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 C4630C433E0 for ; Wed, 3 Feb 2021 21:56:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8499464E4E for ; Wed, 3 Feb 2021 21:56:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232347AbhBCV4e (ORCPT ); Wed, 3 Feb 2021 16:56:34 -0500 Received: from mail1.protonmail.ch ([185.70.40.18]:10769 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232297AbhBCV41 (ORCPT ); Wed, 3 Feb 2021 16:56:27 -0500 Date: Wed, 03 Feb 2021 21:55:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389345; bh=xIYUklR6JXPR7jT3gxjvvDuu8/xilC90GGgK9K1ZMxQ=; h=Date:To:From:Reply-To:Subject:From; b=D4xZdxBw2cMeaV8VwxU1TE5vdcMSuu1+GcYY6BXqH887nB0zjX9+g61+D9bcNaRL6 y5uGrc1oBgrZ2452KI+9wkK69qD3BijzP9NacEAZ+Dv72w30SGpeL20DeHT3OJehF9 w4H2/ELXIB355hnjmKgcuVE41m96w275YWIQ4+E4= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 12/29] platform/x86: ideapad-laptop: check return value of debugfs_create_dir() for errors Message-ID: <20210203215403.290792-13-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org debugfs_create_dir() may return an ERR_PTR(), add a check to ideapad_debugfs_init() that handles the case when that occurs. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 1aa3a05c3360..ba0bd344f5ed 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -350,9 +351,11 @@ DEFINE_SHOW_ATTRIBUTE(debugfs_cfg); static void ideapad_debugfs_init(struct ideapad_private *priv) { - struct dentry *dir; + struct dentry *dir = debugfs_create_dir("ideapad", NULL); + + if (IS_ERR(dir)) + return; - dir = debugfs_create_dir("ideapad", NULL); priv->debug = dir; debugfs_create_file("cfg", S_IRUGO, dir, priv, &debugfs_cfg_fops); From patchwork Wed Feb 3 21:55:43 2021 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: 12065445 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 62282C433DB for ; Wed, 3 Feb 2021 21:56:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2041064E46 for ; Wed, 3 Feb 2021 21:56:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232297AbhBCV4f (ORCPT ); Wed, 3 Feb 2021 16:56:35 -0500 Received: from mail-40136.protonmail.ch ([185.70.40.136]:48927 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232324AbhBCV4a (ORCPT ); Wed, 3 Feb 2021 16:56:30 -0500 Date: Wed, 03 Feb 2021 21:55:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389346; bh=GhcHBs8j0uBYIt/Z2xUQNs7vDHmcB0oah9z/slNJzN0=; h=Date:To:From:Reply-To:Subject:From; b=vecFyt4NwN/6WtPiRDo9/wrvlx9hsxXE8JY5Xn5NpXjRKRUC0YuA+DcAi7K+tbghy X7fq6v3v4QJFqY429bjo5iQNYi4QW8Nso0a4ff/+dYNaNJoj+BwZ6JrjDWGwge/XQc nvKZe9eG9CrMWxrqa/f8g654WYUH2bX7sKPgjvC8= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 13/29] platform/x86: ideapad-laptop: convert ACPI helpers to return -EIO in case of failure Message-ID: <20210203215403.290792-14-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 ba0bd344f5ed..7815ec93f546 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -127,7 +127,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; @@ -148,7 +148,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_dytc(acpi_handle handle, int cmd, int *ret) @@ -167,7 +167,7 @@ static int method_dytc(acpi_handle handle, int cmd, int *ret) if (ACPI_FAILURE(status)) { *ret = -1; - return -1; + return -EIO; } *ret = result; return 0; @@ -189,7 +189,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; @@ -211,56 +211,62 @@ 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; unsigned long int end_jiffies; + int val, err; - if (method_vpcw(handle, 1, cmd)) - return -1; + err = method_vpcw(handle, 1, cmd); + if (err) + return err; end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; while (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; unsigned long int end_jiffies; + int val, err; - 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; end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; while (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; } /* @@ -395,8 +401,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; } @@ -428,8 +434,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; } @@ -461,8 +467,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; } @@ -495,8 +501,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; } @@ -533,8 +539,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; } @@ -1025,7 +1031,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) { @@ -1053,22 +1060,27 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev) { struct ideapad_private *priv = bl_get_data(blightdev); unsigned long now; + int err; - 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 (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; } @@ -1083,13 +1095,17 @@ static int ideapad_backlight_init(struct ideapad_private *priv) struct backlight_device *blightdev; struct backlight_properties props; unsigned long max, now, power; + int err; - 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; + 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 Feb 3 21:55:48 2021 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: 12065447 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 67091C433E0 for ; Wed, 3 Feb 2021 21:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21E2A64E46 for ; Wed, 3 Feb 2021 21:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbhBCV4k (ORCPT ); Wed, 3 Feb 2021 16:56:40 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:16297 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232324AbhBCV4j (ORCPT ); Wed, 3 Feb 2021 16:56:39 -0500 Date: Wed, 03 Feb 2021 21:55:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389356; bh=9IOq1PI2s28VN/ey4rKGDnB7P2XZG7UCvROOWDx1nUo=; h=Date:To:From:Reply-To:Subject:From; b=kY5Ja6rFLrI1qqe29bnEH+a1CitK/Kz3SOuTaCfwgjLhKYnzNL/sVp7NbY0+uTd4Q Jiq6FbG7XvOritvvuH+jS275vBdL+akSfJm7xIDoxh2VjeBxpJYYgO79VkZcPxjNpo 8q0DK4a4Uk8YK6bFSoyGK9am1+LhJcDxUPypo7uk= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 14/29] platform/x86: ideapad-laptop: always propagate error codes from device attributes' show() callback Message-ID: <20210203215403.290792-15-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 an appropriate errno instead of returning a magic string like "-1". This introduces an ABI change, but not many users are expected to be relying on the previous behavior, and this change makes this module conforming to the standard behavior that sysfs attribute show/store callbacks return an appropriate errno in case of failure. Thus the ABI breakage is deemed justified. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 7815ec93f546..70aa775e80ad 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -383,9 +383,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); } @@ -414,9 +416,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); } @@ -447,9 +451,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); } @@ -480,9 +486,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)); } @@ -518,7 +526,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 Feb 3 21:55:53 2021 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: 12065449 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 C0CE9C433DB for ; Wed, 3 Feb 2021 21:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76EF464E46 for ; Wed, 3 Feb 2021 21:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232324AbhBCV4l (ORCPT ); Wed, 3 Feb 2021 16:56:41 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:40275 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232366AbhBCV4k (ORCPT ); Wed, 3 Feb 2021 16:56:40 -0500 Date: Wed, 03 Feb 2021 21:55:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389358; bh=Hv90NEpSErVY37H/qgkp68BU+eDOPY0KcZCwUyw0JCY=; h=Date:To:From:Reply-To:Subject:From; b=VmFedQwgAPkbSi/IDZEyYymWwby7R46PT4WKaRoat3+5Rk873Z1e0ujGNmbCtrWkI JQXZi01TJPwPpVB4P3unauPO+V4lSKS3eRyvPqJH+PQy0Jlyt/REbGX26l7ffBlnNG fIDd49noTMyB2APd0i8QyfNpmjk9gkA99VA1up5k= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 15/29] platform/x86: ideapad-laptop: misc. device attribute changes Message-ID: <20210203215403.290792-16-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(). Use kstrtobool() in store_ideapad_cam(). These introduce minor ABI changes, but it is expected that no users rely on the previous behavior. Thus the change is deemed justifed. Additionally, use `!!` to convert to `int` and use the "%d" format specifier in sysfs_emit() for boolean-like attributes. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 70aa775e80ad..00d9e23a0310 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -388,20 +388,20 @@ static ssize_t show_ideapad_cam(struct device *dev, err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result); if (err) return err; - return sysfs_emit(buf, "%lu\n", result); + return sysfs_emit(buf, "%d\n", !!result); } static ssize_t store_ideapad_cam(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ret, state; struct ideapad_private *priv = dev_get_drvdata(dev); + bool state; + int ret; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; + ret = kstrtobool(buf, &state); + if (ret) + return ret; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); if (ret) return ret; @@ -428,14 +428,14 @@ static ssize_t store_ideapad_fan(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ret, state; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned int state; + int ret; - 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) @@ -456,7 +456,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); + return sysfs_emit(buf, "%d\n", !!result); } /* Switch to RO for now: It might be revisited in the future */ @@ -491,7 +491,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, "%d\n", !!test_bit(BM_CONSERVATION_BIT, &result)); } static ssize_t conservation_mode_store(struct device *dev, @@ -529,7 +529,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, "%d\n", !!test_bit(HA_FNLOCK_BIT, &result)); } static ssize_t fn_lock_store(struct device *dev, From patchwork Wed Feb 3 21:55:59 2021 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: 12065451 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 7A269C433E0 for ; Wed, 3 Feb 2021 21:56:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3482464E4E for ; Wed, 3 Feb 2021 21:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232366AbhBCV4v (ORCPT ); Wed, 3 Feb 2021 16:56:51 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:59151 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231318AbhBCV4t (ORCPT ); Wed, 3 Feb 2021 16:56:49 -0500 Date: Wed, 03 Feb 2021 21:55:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389367; bh=gGyzy6J413D8Goh69tP/efDGaWYPLVeIpXBnutcEtvg=; h=Date:To:From:Reply-To:Subject:From; b=njEo/rQvK6GD+kwNa5vSwRlcTynD13s0pXSVkDCGzVwSr/FoU0G8/R9aY9D67jj5/ eCCPyGfI218akpuYAP+mx4oxFtdBYdn45YrgzBLLqmijmGk0FNti4H/ZWK/fvq4pEB Yy/Rs6Y5eXzLc3wE6YeDeEuk0fiLiFKM1N05X3ZE= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 16/29] platform/x86: ideapad-laptop: group and separate (un)related constants into enums Message-ID: <20210203215403.290792-17-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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 00d9e23a0310..e74f25ec4a27 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -34,14 +34,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 */ @@ -50,10 +42,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 { @@ -309,7 +319,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); } @@ -323,13 +333,13 @@ static int debugfs_cfg_show(struct seq_file *s, void *data) 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) { @@ -491,7 +501,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, "%d\n", !!test_bit(BM_CONSERVATION_BIT, &result)); + return sysfs_emit(buf, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); } static ssize_t conservation_mode_store(struct device *dev, @@ -507,8 +517,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; @@ -529,7 +539,7 @@ static ssize_t fn_lock_show(struct device *dev, return fail; result = hals; - return sysfs_emit(buf, "%d\n", !!test_bit(HA_FNLOCK_BIT, &result)); + return sysfs_emit(buf, "%d\n", !!test_bit(HALS_FNLOCK_STATE_BIT, &result)); } static ssize_t fn_lock_store(struct device *dev, @@ -545,8 +555,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; @@ -573,7 +583,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, @@ -859,9 +869,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 Feb 3 21:56:05 2021 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: 12065503 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 8B724C433E0 for ; Wed, 3 Feb 2021 21:57:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AF5B64E4E for ; Wed, 3 Feb 2021 21:57:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232446AbhBCV5K (ORCPT ); Wed, 3 Feb 2021 16:57:10 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:55328 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232401AbhBCV44 (ORCPT ); Wed, 3 Feb 2021 16:56:56 -0500 Date: Wed, 03 Feb 2021 21:56:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389371; bh=m6cWswUvZxAX9U/Iq10b+aJq/dBh0o2Uj+FAblNWLFA=; h=Date:To:From:Reply-To:Subject:From; b=I0FmE7T+UAdH7aX8qfgJ/hc+++XRJeIBRInq3TLLZ5rLKZ4nauKo11p8v3R1+g/ak 2L4UT7x2KdO0KmPa0LQI3bHAp66fpWrJVnduacP1WL+rUU0KHtw8ljuq8p1PHjoWoe y4oZ49fSHk9QLE9wCvXZLXvR4hHoFVPNI7C+Ulv8= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 17/29] platform/x86: ideapad-laptop: rework and create new ACPI helpers Message-ID: <20210203215403.290792-18-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 e74f25ec4a27..c8ab660cdacc 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -129,84 +129,78 @@ 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 *name, unsigned long *res) { - acpi_status status; unsigned long long result; + acpi_status status; - status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); - if (ACPI_FAILURE(status)) { - *val = -1; + status = acpi_evaluate_integer(handle, (char *)name, NULL, &result); + if (ACPI_FAILURE(status)) return -EIO; - } - *val = result; + *res = result; return 0; - } -static int method_gbmd(acpi_handle handle, unsigned long *ret) +static int exec_simple_method(acpi_handle handle, const char *name, unsigned long arg) { - int result, val; + acpi_status status = acpi_execute_simple_method(handle, (char *)name, arg); - result = read_method_int(handle, "GBMD", &val); - *ret = val; - return result; + return ACPI_FAILURE(status) ? -EIO : 0; } -static int method_int1(acpi_handle handle, char *method, int cmd) +static int eval_gbmd(acpi_handle handle, unsigned long *res) { - acpi_status status; - - status = acpi_execute_simple_method(handle, method, cmd); - return ACPI_FAILURE(status) ? -EIO : 0; + return eval_int(handle, "GBMD", res); } -static int method_dytc(acpi_handle handle, int cmd, int *ret) +static int exec_smbc(acpi_handle handle, unsigned long arg) { - acpi_status status; - unsigned long long result; - struct acpi_object_list params; - union acpi_object in_obj; - - params.count = 1; - params.pointer = &in_obj; - in_obj.type = ACPI_TYPE_INTEGER; - in_obj.integer.value = cmd; + return exec_simple_method(handle, "SMBC", arg); +} - status = acpi_evaluate_integer(handle, "DYTC", ¶ms, &result); +static int eval_hals(acpi_handle handle, unsigned long *res) +{ + return eval_int(handle, "HALS", res); +} - if (ACPI_FAILURE(status)) { - *ret = -1; - return -EIO; - } - *ret = result; - return 0; +static int exec_sals(acpi_handle handle, unsigned long arg) +{ + return exec_simple_method(handle, "SALS", arg); } -static int method_vpcr(acpi_handle handle, int cmd, int *ret) +static int eval_int_with_arg(acpi_handle handle, const char *name, unsigned long arg, unsigned long *res) { - acpi_status status; - unsigned long long result; struct acpi_object_list params; + unsigned long long result; union acpi_object in_obj; + acpi_status status; params.count = 1; params.pointer = &in_obj; in_obj.type = ACPI_TYPE_INTEGER; - in_obj.integer.value = cmd; + in_obj.integer.value = arg; - status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); - - if (ACPI_FAILURE(status)) { - *ret = -1; + status = acpi_evaluate_integer(handle, (char *)name, ¶ms, &result); + if (ACPI_FAILURE(status)) return -EIO; - } - *ret = result; + + if (res) + *res = result; + return 0; +} +static int eval_dytc(acpi_handle handle, unsigned long cmd, unsigned long *res) +{ + return eval_int_with_arg(handle, "DYTC", cmd, res); +} + +static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *res) +{ + return eval_int_with_arg(handle, "VPCR", cmd, res); } -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]; @@ -220,17 +214,17 @@ static int method_vpcw(acpi_handle handle, int cmd, int data) in_obj[1].integer.value = data; status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); - if (status != AE_OK) + if (ACPI_FAILURE(status)) 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) { - unsigned long int end_jiffies; - int val, err; + unsigned long end_jiffies, val; + int err; - err = method_vpcw(handle, 1, cmd); + err = eval_vpcw(handle, 1, cmd); if (err) return err; @@ -238,30 +232,25 @@ static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) while (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) { - unsigned long int end_jiffies; - int val, err; + unsigned long end_jiffies, val; + int err; - 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; @@ -269,7 +258,7 @@ static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) while (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) @@ -317,7 +306,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); @@ -498,7 +487,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, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); @@ -516,9 +505,7 @@ 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 = exec_smbc(priv->adev->handle, state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF); if (ret) return ret; return count; @@ -531,15 +518,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, "%d\n", !!test_bit(HALS_FNLOCK_STATE_BIT, &result)); + return sysfs_emit(buf, "%d\n", !!test_bit(HALS_FNLOCK_STATE_BIT, &hals)); } static ssize_t fn_lock_store(struct device *dev, @@ -554,9 +539,7 @@ 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 = exec_sals(priv->adev->handle, state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF); if (ret) return ret; return count; @@ -700,32 +683,31 @@ int dytc_profile_get(struct platform_profile_handler *pprof, * - enable CQL * If not in CQL mode, just run the command */ -int dytc_cql_command(struct ideapad_private *priv, int command, int *output) +int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd, unsigned long *output) { - int err, cmd_err, dummy; - int cur_funcmode; + int err, cmd_err, cur_funcmode; /* Determine if we are in CQL mode. This alters the commands we do */ - err = method_dytc(priv->adev->handle, DYTC_CMD_GET, output); + err = eval_dytc(priv->adev->handle, DYTC_CMD_GET, output); if (err) return err; cur_funcmode = (*output >> DYTC_GET_FUNCTION_BIT) & 0xF; /* Check if we're OK to return immediately */ - if ((command == DYTC_CMD_GET) && (cur_funcmode != DYTC_FUNCTION_CQL)) + if (cmd == DYTC_CMD_GET && cur_funcmode != DYTC_FUNCTION_CQL) return 0; if (cur_funcmode == DYTC_FUNCTION_CQL) { - err = method_dytc(priv->adev->handle, DYTC_DISABLE_CQL, &dummy); + err = eval_dytc(priv->adev->handle, DYTC_DISABLE_CQL, NULL); if (err) return err; } - cmd_err = method_dytc(priv->adev->handle, command, output); + cmd_err = eval_dytc(priv->adev->handle, cmd, output); /* Check return condition after we've restored CQL state */ if (cur_funcmode == DYTC_FUNCTION_CQL) { - err = method_dytc(priv->adev->handle, DYTC_ENABLE_CQL, &dummy); + err = eval_dytc(priv->adev->handle, DYTC_ENABLE_CQL, NULL); if (err) return err; } @@ -742,7 +724,6 @@ int dytc_profile_set(struct platform_profile_handler *pprof, { struct ideapad_dytc_priv *dytc; struct ideapad_private *priv; - int output; int err; dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); @@ -754,7 +735,7 @@ int dytc_profile_set(struct platform_profile_handler *pprof, if (profile == PLATFORM_PROFILE_BALANCED) { /* To get back to balanced mode we just issue a reset command */ - err = method_dytc(priv->adev->handle, DYTC_CMD_RESET, &output); + err = eval_dytc(priv->adev->handle, DYTC_CMD_RESET, NULL); if (err) goto unlock; } else { @@ -767,7 +748,7 @@ int dytc_profile_set(struct platform_profile_handler *pprof, /* Determine if we are in CQL mode. This alters the commands we do */ err = dytc_cql_command(priv, DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1), - &output); + NULL); if (err) goto unlock; } @@ -781,8 +762,8 @@ int dytc_profile_set(struct platform_profile_handler *pprof, static void dytc_profile_refresh(struct ideapad_private *priv) { enum platform_profile_option profile; - int output, err; - int perfmode; + unsigned long output; + int err, perfmode; mutex_lock(&priv->dytc->mutex); err = dytc_cql_command(priv, DYTC_CMD_GET, &output); @@ -800,9 +781,10 @@ static void dytc_profile_refresh(struct ideapad_private *priv) static int ideapad_dytc_profile_init(struct ideapad_private *priv) { - int err, output, dytc_version; + int err, dytc_version; + unsigned long output; - err = method_dytc(priv->adev->handle, DYTC_CMD_QUERY, &output); + err = eval_dytc(priv->adev->handle, DYTC_CMD_QUERY, &output); /* For all other errors we can flag the failure */ if (err) return err; @@ -1292,16 +1274,16 @@ static const struct dmi_system_id hw_rfkill_list[] = { static int ideapad_acpi_add(struct platform_device *pdev) { int ret, i; - int cfg; struct ideapad_private *priv; struct acpi_device *adev; acpi_status status; + unsigned long cfg; ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); 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 Feb 3 21:56:10 2021 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: 12065509 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 C0D1AC433E0 for ; Wed, 3 Feb 2021 21:57:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F9E164E4E for ; Wed, 3 Feb 2021 21:57:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232467AbhBCV5U (ORCPT ); Wed, 3 Feb 2021 16:57:20 -0500 Received: from mail1.protonmail.ch ([185.70.40.18]:61821 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232376AbhBCV5C (ORCPT ); Wed, 3 Feb 2021 16:57:02 -0500 Date: Wed, 03 Feb 2021 21:56:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389378; bh=CTIglaHxRXQDh+Zq6I880PTmpspSRZj5ejmlz+E39jY=; h=Date:To:From:Reply-To:Subject:From; b=ob3hQjHeoZDIKOuSiYW28lHT34ILrlEKu75VuD/Llbo8+1YnmyzsYz6RnzgT9HKk4 70DW+7hWwQb5mK+DyHVHR/TUNbzOYODMlB5E9evac5jHYSjhqdkXkJSekOcJYc8OHr YVggxa793fa48ybIazRFgoZRf6p9vZNxNN6UpSdc= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 18/29] platform/x86: ideapad-laptop: rework is_visible() logic Message-ID: <20210203215403.290792-19-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 c8ab660cdacc..77a8e19441ed 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -115,9 +115,15 @@ struct ideapad_private { struct ideapad_dytc_priv *dytc; struct dentry *debug; unsigned long cfg; - bool has_hw_rfkill_switch; - bool has_touchpad_switch; const char *fnesc_guid; + struct { + bool conservation_mode : 1; + bool dytc : 1; + bool fan_mode : 1; + bool fn_lock : 1; + bool hw_rfkill_switch : 1; + bool touchpad_ctrl_via_ec : 1; + } features; }; static bool no_bt_rfkill; @@ -563,24 +569,18 @@ static umode_t ideapad_is_visible(struct kobject *kobj, { struct device *dev = kobj_to_dev(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 if (attr == &dev_attr_touchpad.attr) - supported = priv->has_touchpad_switch; - else - supported = true; + else if (attr == &dev_attr_conservation_mode.attr) + supported = priv->features.conservation_mode; + else if (attr == &dev_attr_fan_mode.attr) + supported = priv->features.fan_mode; + else if (attr == &dev_attr_fn_lock.attr) + supported = priv->features.fn_lock; + else if (attr == &dev_attr_touchpad.attr) + supported = priv->features.touchpad_ctrl_via_ec; return supported ? attr->mode : 0; } @@ -784,6 +784,9 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv) int err, dytc_version; unsigned long output; + if (!priv->features.dytc) + return -ENODEV; + err = eval_dytc(priv->adev->handle, DYTC_CMD_QUERY, &output); /* For all other errors we can flag the failure */ if (err) @@ -873,7 +876,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; @@ -1167,7 +1170,7 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv) { unsigned long value; - if (!priv->has_touchpad_switch) + if (!priv->features.touchpad_ctrl_via_ec) return; /* Without reading from EC touchpad LED doesn't switch state */ @@ -1271,6 +1274,29 @@ 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); + + /* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */ + priv->features.touchpad_ctrl_via_ec = !acpi_dev_present("ELAN0634", NULL, -1); + + 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, "DYTC")) + priv->features.dytc = 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; @@ -1294,10 +1320,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); - /* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */ - priv->has_touchpad_switch = !acpi_dev_present("ELAN0634", NULL, -1); + ideapad_check_features(priv); ret = ideapad_sysfs_init(priv); if (ret) @@ -1313,11 +1337,11 @@ 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); /* The same for Touchpad */ - if (!priv->has_touchpad_switch) + if (!priv->features.touchpad_ctrl_via_ec) write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, 1); for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) @@ -1327,7 +1351,13 @@ static int ideapad_acpi_add(struct platform_device *pdev) ideapad_sync_rfk_state(priv); ideapad_sync_touchpad_state(priv); - ideapad_dytc_profile_init(priv); + ret = ideapad_dytc_profile_init(priv); + if (ret) { + if (ret != -ENODEV) + dev_warn(&pdev->dev, "Could not set up DYTC interface: %d\n", ret); + else + dev_info(&pdev->dev, "DYTC interface is not available\n"); + } if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { ret = ideapad_backlight_init(priv); From patchwork Wed Feb 3 21:56:16 2021 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: 12065505 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 23AD0C433DB for ; Wed, 3 Feb 2021 21:57:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6E7664D90 for ; Wed, 3 Feb 2021 21:57:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbhBCV5N (ORCPT ); Wed, 3 Feb 2021 16:57:13 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:18733 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232420AbhBCV5C (ORCPT ); Wed, 3 Feb 2021 16:57:02 -0500 Date: Wed, 03 Feb 2021 21:56:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389379; bh=90KXYhlIrAp0ubHBGpGIYNKKG7QLhFD22auhWR2MdOU=; h=Date:To:From:Reply-To:Subject:From; b=AQ0EMbmap8vlRFokRpbiRTSmt5aog2VOg+bodd4kXwoefs3LyteMYK4OGzWbhTeir 9/b1OhbbGw9gwuSuiPURpJk8L5NtiVlx3SktkHx3QkeuAiwePmDRdisv2AHl2svtcH nM9mz5qrzezS0HtHV64zeZmXmQv8TzeDyLIoTe48= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 19/29] platform/x86: ideapad-laptop: check for Fn-lock support in HALS Message-ID: <20210203215403.290792-20-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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 77a8e19441ed..549e220ae05b 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -58,7 +58,9 @@ enum { }; enum { - HALS_FNLOCK_STATE_BIT = 10, + HALS_FNLOCK_SUPPORT_BIT = 9, + HALS_FNLOCK_STATE_BIT = 10, + HALS_HOTKEYS_PRIMARY_BIT = 11, }; enum { @@ -1293,8 +1295,12 @@ static void ideapad_check_features(struct ideapad_private *priv) if (acpi_has_method(handle, "DYTC")) priv->features.dytc = 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 Feb 3 21:56:22 2021 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: 12065507 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 DEF9DC433E0 for ; Wed, 3 Feb 2021 21:57:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B28464D90 for ; Wed, 3 Feb 2021 21:57:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232457AbhBCV5P (ORCPT ); Wed, 3 Feb 2021 16:57:15 -0500 Received: from mail-40136.protonmail.ch ([185.70.40.136]:13705 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232443AbhBCV5H (ORCPT ); Wed, 3 Feb 2021 16:57:07 -0500 Date: Wed, 03 Feb 2021 21:56:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389384; bh=MAd8eR7pyMwSmeVtqMOsXuxNxx9Up8POoh0gK5wh9VY=; h=Date:To:From:Reply-To:Subject:From; b=Ea9lUj6T1HfVGK+f/TQ/jbkszm4IUjbZzuohPQBiOAPryN3KrwO+lR7iG8hsxRrmz p/9fNKiSN5DxWoiLTPv8CRb4ntdyBkfp1IUZTO5sJno9vuposEacd1DU9whVkWqUga MzS1ENkVt4RIG4NSjwzEYzkZ1Zi/ngVaxBLYtSnQ= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 20/29] platform/x86: ideapad-laptop: check for touchpad support in _CFG Message-ID: <20210203215403.290792-21-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Bit 30 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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 549e220ae05b..abb283cee47c 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -42,10 +42,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 = 30, }; enum { @@ -338,6 +339,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: @@ -582,7 +585,8 @@ static umode_t ideapad_is_visible(struct kobject *kobj, else if (attr == &dev_attr_fn_lock.attr) supported = priv->features.fn_lock; else if (attr == &dev_attr_touchpad.attr) - supported = priv->features.touchpad_ctrl_via_ec; + supported = priv->features.touchpad_ctrl_via_ec && + test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg); return supported ? attr->mode : 0; } From patchwork Wed Feb 3 21:56:34 2021 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: 12065511 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 50264C433DB for ; Wed, 3 Feb 2021 21:57:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11E3164E4E for ; Wed, 3 Feb 2021 21:57:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232489AbhBCV5X (ORCPT ); Wed, 3 Feb 2021 16:57:23 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:60287 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232437AbhBCV5T (ORCPT ); Wed, 3 Feb 2021 16:57:19 -0500 Date: Wed, 03 Feb 2021 21:56:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389396; bh=C1CXhYIg7zEljs/5GMK80XZju6QJkZ3iED1hMTJ9fmI=; h=Date:To:From:Reply-To:Subject:From; b=g5+H2ycq077PB8GrP0eHGN+PmK/Mbq2SJqGXe4NGHOW279BNza0WGgeaLBfHR8EaB d2ZS0+n/+W1ceRZumAZyDtBA2EFoVCCuuweD0X1rMeicNUVpYjY8iVBR8oYyVcS0vR 7KQLXm2l7Cfrb+ZfVQUr24gI3g5OuOekdchFk9DE= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 21/29] platform/x86: ideapad-laptop: change 'status' debugfs file format Message-ID: <20210203215403.290792-22-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. 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 abb283cee47c..34e93ac83d8e 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -286,40 +286,33 @@ static int debugfs_status_show(struct seq_file *s, void *data) unsigned long value; if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value)) - seq_printf(s, "Backlight max:\t%lu\n", value); + seq_printf(s, "Backlight max: %lu\n", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value)) - seq_printf(s, "Backlight now:\t%lu\n", value); + seq_printf(s, "Backlight now: %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: %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: %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: %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: %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: %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: %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: %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 Feb 3 21:56:39 2021 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: 12065513 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 9F630C433E6 for ; Wed, 3 Feb 2021 21:57:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52D0B64D90 for ; Wed, 3 Feb 2021 21:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232437AbhBCV5g (ORCPT ); Wed, 3 Feb 2021 16:57:36 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:36949 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232506AbhBCV52 (ORCPT ); Wed, 3 Feb 2021 16:57:28 -0500 Date: Wed, 03 Feb 2021 21:56:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389405; bh=KYuM2LWlGBHP3Fdn8PrtE8hJkOBjwRdF7fC1KJvyfIY=; h=Date:To:From:Reply-To:Subject:From; b=l5S04E4l7Uw6L5u8KRgfcnMqlbIqCdob1lok+jPZ2WEzUmlv15ERGTlT+6M65Yf4i OOKWHeSNUDGH2qK5MlSEKIrMncHimwAp8DqWbP7uG29xCCCwwDwttICemc/pf2inVt OOrtN+qaoviaqA0IcyVI0wPkdFooJP5IdS7erRI4= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 22/29] platform/x86: ideapad-laptop: change 'cfg' debugfs file format Message-ID: <20210203215403.290792-23-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org 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 34e93ac83d8e..0a5ca91cfe9e 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -322,37 +322,40 @@ static int debugfs_cfg_show(struct seq_file *s, void *data) { struct ideapad_private *priv = s->private; - seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ", - priv->cfg); + seq_printf(s, "_CFG: %#010lx\n\n", priv->cfg); + + seq_puts(s, "Capabilities:"); if (test_bit(CFG_CAP_BT_BIT, &priv->cfg)) - seq_printf(s, "Bluetooth "); + seq_puts(s, " bluetooth"); if (test_bit(CFG_CAP_3G_BIT, &priv->cfg)) - seq_printf(s, "3G "); + seq_puts(s, " 3G"); if (test_bit(CFG_CAP_WIFI_BIT, &priv->cfg)) - seq_printf(s, "Wireless "); + seq_puts(s, " wifi"); if (test_bit(CFG_CAP_CAM_BIT, &priv->cfg)) - seq_printf(s, "Camera "); + seq_puts(s, " camera"); if (test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg)) - seq_printf(s, "Touchpad "); - seq_printf(s, "\nGraphic: "); - switch ((priv->cfg)&0x700) { + seq_puts(s, " touchpad"); + seq_puts(s, "\n"); + + seq_puts(s, "Graphics: "); + switch (priv->cfg & 0x700) { case 0x100: - seq_printf(s, "Intel"); + seq_puts(s, "Intel"); break; case 0x200: - seq_printf(s, "ATI"); + seq_puts(s, "ATI"); break; case 0x300: - seq_printf(s, "Nvidia"); + seq_puts(s, "Nvidia"); break; case 0x400: - seq_printf(s, "Intel and ATI"); + seq_puts(s, "Intel and ATI"); break; case 0x500: - seq_printf(s, "Intel and Nvidia"); + seq_puts(s, "Intel and Nvidia"); break; } - seq_printf(s, "\n"); + seq_puts(s, "\n"); return 0; } From patchwork Wed Feb 3 21:56:44 2021 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: 12065517 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 065B2C433DB for ; Wed, 3 Feb 2021 21:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3CC364D90 for ; Wed, 3 Feb 2021 21:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232459AbhBCV5j (ORCPT ); Wed, 3 Feb 2021 16:57:39 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:61227 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232228AbhBCV5f (ORCPT ); Wed, 3 Feb 2021 16:57:35 -0500 Date: Wed, 03 Feb 2021 21:56:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389413; bh=5FxRRrkFmar4Ehcc8jR90bfyXi3La/APIkJIK7zVWvY=; h=Date:To:From:Reply-To:Subject:From; b=w3XlScM2zBiWhg45ZS+nCeSrGjm6HHDUeSjTyDNeN/VviSunJNxxOH79BCUEN/t83 Hlbh2fX8bjkHZToahgn+SnpPhTL/4qoTqiuJgg5mzzfIaEHatEQl/pph0TDyMZDKtz IdhfpgvymL6Up92R2BqcDAsILGIIZglW/bXTTLbs= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 23/29] Revert "platform/x86: ideapad-laptop: Switch touchpad attribute to be RO" Message-ID: <20210203215403.290792-24-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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 0a5ca91cfe9e..4fd9670100cb 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -465,10 +465,9 @@ static ssize_t touchpad_show(struct device *dev, return sysfs_emit(buf, "%d\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; @@ -484,7 +483,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 Feb 3 21:56:56 2021 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: 12065521 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 38036C433DB for ; Wed, 3 Feb 2021 21:58:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D229964F5F for ; Wed, 3 Feb 2021 21:58:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231421AbhBCV57 (ORCPT ); Wed, 3 Feb 2021 16:57:59 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:62442 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231807AbhBCV5v (ORCPT ); Wed, 3 Feb 2021 16:57:51 -0500 Date: Wed, 03 Feb 2021 21:56:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389425; bh=EuInSQ26C/gYqcH2XwOX6Y076F2/9EhamcUwmrXtHsU=; h=Date:To:From:Reply-To:Subject:From; b=FwOSc7uXo234cZhuq1dfzcwB4NWn/NkPlC1ZV8gGIxEOuniPSR9N174OwoECEd3Uo 4dXTIUPeCMMvVWAEpy+Y6l7Fckv5iPzUaPcOj5thyUhXPV0KTAt78eTCWwfU0YoGCF St6ZXVH0tz+nh55a5r35qTnc/YUCmyG+HJEw14j0= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 24/29] platform/x86: ideapad-laptop: fix checkpatch warnings, more consistent style Message-ID: <20210203215403.290792-25-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Fix all checkpatch warnings. Reorder variable definitions from longest to shortest. Add more whitespaces for better readability. Rename variables named `ret` to `err` where appropriate. Reorder sysfs attributes show/store callbacks and the `ideapad_attributes` array in lexicographic order. And other minor formatting changes. No significant functional changes are intended. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 4fd9670100cb..2068831c5fe8 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -32,7 +32,7 @@ #include -#define IDEAPAD_RFKILL_DEV_NUM (3) +#define IDEAPAD_RFKILL_DEV_NUM 3 #if IS_ENABLED(CONFIG_ACPI_WMI) static const char *const ideapad_wmi_fnesc_events[] = { @@ -99,7 +99,7 @@ enum { struct ideapad_dytc_priv { enum platform_profile_option current_profile; struct platform_profile_handler pprof; - struct mutex mutex; + struct mutex mutex; /* protects the DYTC interface */ struct ideapad_private *priv; }; @@ -136,7 +136,7 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); /* * ACPI Helpers */ -#define IDEAPAD_EC_TIMEOUT (200) /* in ms */ +#define IDEAPAD_EC_TIMEOUT 200 /* in ms */ static int eval_int(acpi_handle handle, const char *name, unsigned long *res) { @@ -146,7 +146,9 @@ static int eval_int(acpi_handle handle, const char *name, unsigned long *res) status = acpi_evaluate_integer(handle, (char *)name, NULL, &result); if (ACPI_FAILURE(status)) return -EIO; + *res = result; + return 0; } @@ -225,6 +227,7 @@ static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data) status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); if (ACPI_FAILURE(status)) return -EIO; + return 0; } @@ -241,13 +244,17 @@ static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *da while (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; } @@ -259,6 +266,7 @@ static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long dat err = eval_vpcw(handle, 0, data); if (err) return err; + err = eval_vpcw(handle, 1, cmd); if (err) return err; @@ -267,13 +275,17 @@ static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long dat while (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; } @@ -291,6 +303,7 @@ static int debugfs_status_show(struct seq_file *s, void *data) seq_printf(s, "Backlight now: %lu\n", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value)) seq_printf(s, "BL power value: %s (%lu)\n", value ? "on" : "off", value); + seq_puts(s, "=====================\n"); if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value)) @@ -301,12 +314,14 @@ static int debugfs_status_show(struct seq_file *s, void *data) seq_printf(s, "BT status: %s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value)) seq_printf(s, "3G status: %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); if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value)) seq_printf(s, "Camera status: %s (%lu)\n", value ? "on" : "off", value); + seq_puts(s, "=====================\n"); if (!eval_gbmd(priv->adev->handle, &value)) @@ -370,8 +385,8 @@ static void ideapad_debugfs_init(struct ideapad_private *priv) 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) @@ -383,75 +398,79 @@ 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, "%d\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) { struct ideapad_private *priv = dev_get_drvdata(dev); bool state; - int ret; - - ret = kstrtobool(buf, &state); - if (ret) - return ret; - ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); - if (ret) - return ret; + int err; + + err = kstrtobool(buf, &state); + if (err) + return err; + + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); + if (err) + return err; + 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 conservation_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); + err = eval_gbmd(priv->adev->handle, &result); if (err) return err; - return sysfs_emit(buf, "%lu\n", result); + + return sysfs_emit(buf, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); } -static ssize_t store_ideapad_fan(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t conservation_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct ideapad_private *priv = dev_get_drvdata(dev); - unsigned int state; - int ret; + bool state; + int err; + + err = kstrtobool(buf, &state); + if (err) + return err; + + err = exec_smbc(priv->adev->handle, state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF); + 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; return count; } -static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan); +static DEVICE_ATTR_RW(conservation_mode); -static ssize_t touchpad_show(struct device *dev, +static ssize_t fan_mode_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -459,113 +478,121 @@ static ssize_t touchpad_show(struct device *dev, unsigned long result; int err; - err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); + err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result); if (err) return err; - return sysfs_emit(buf, "%d\n", !!result); + + return sysfs_emit(buf, "%lu\n", result); } -static ssize_t touchpad_store(struct device *dev, +static ssize_t fan_mode_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 ret; + unsigned int state; + int err; + + err = kstrtouint(buf, 0, &state); + if (err) + return err; + + if (state > 4 || state == 3) + return -EINVAL; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, 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 DEVICE_ATTR_RW(fan_mode); -static ssize_t conservation_mode_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t fn_lock_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct ideapad_private *priv = dev_get_drvdata(dev); - unsigned long result; + unsigned long hals; int err; - err = eval_gbmd(priv->adev->handle, &result); + err = eval_hals(priv->adev->handle, &hals); if (err) return err; - return sysfs_emit(buf, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); + + return sysfs_emit(buf, "%d\n", !!test_bit(HALS_FNLOCK_STATE_BIT, &hals)); } -static ssize_t conservation_mode_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t fn_lock_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 ret; + int err; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + err = kstrtobool(buf, &state); + if (err) + return err; + + err = exec_sals(priv->adev->handle, state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF); + if (err) + return err; - ret = exec_smbc(priv->adev->handle, state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF); - if (ret) - return ret; return count; } -static DEVICE_ATTR_RW(conservation_mode); +static DEVICE_ATTR_RW(fn_lock); -static ssize_t fn_lock_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t touchpad_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct ideapad_private *priv = dev_get_drvdata(dev); - unsigned long hals; - int fail = eval_hals(priv->adev->handle, &hals); + unsigned long result; + int err; - if (fail) - return fail; + err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); + if (err) + return err; - return sysfs_emit(buf, "%d\n", !!test_bit(HALS_FNLOCK_STATE_BIT, &hals)); + return sysfs_emit(buf, "%d\n", !!result); } -static ssize_t fn_lock_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; - int ret; + int err; + + err = kstrtobool(buf, &state); + if (err) + return err; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); + if (err) + return err; - ret = exec_sals(priv->adev->handle, state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF); - if (ret) - return ret; return count; } -static DEVICE_ATTR_RW(fn_lock); - +static DEVICE_ATTR_RW(touchpad); 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_fan_mode.attr, &dev_attr_fn_lock.attr, + &dev_attr_touchpad.attr, NULL }; static umode_t ideapad_is_visible(struct kobject *kobj, - struct attribute *attr, - int idx) + struct attribute *attr, + int idx) { struct device *dev = kobj_to_dev(kobj); struct ideapad_private *priv = dev_get_drvdata(dev); @@ -642,6 +669,7 @@ static int convert_dytc_to_profile(int dytcmode, enum platform_profile_option *p default: /* Unknown mode */ return -EINVAL; } + return 0; } @@ -660,6 +688,7 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe default: /* Unknown profile */ return -EOPNOTSUPP; } + return 0; } @@ -667,24 +696,24 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe * dytc_profile_get: Function to register with platform_profile * handler. Returns current platform profile. */ -int dytc_profile_get(struct platform_profile_handler *pprof, - enum platform_profile_option *profile) +static int dytc_profile_get(struct platform_profile_handler *pprof, + enum platform_profile_option *profile) { - struct ideapad_dytc_priv *dytc; + struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); - dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); *profile = dytc->current_profile; return 0; } /* * Helper function - check if we are in CQL mode and if we are - * - disable CQL, + * - disable CQL, * - run the command * - enable CQL * If not in CQL mode, just run the command */ -int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd, unsigned long *output) +static int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd, + unsigned long *output) { int err, cmd_err, cur_funcmode; @@ -720,16 +749,13 @@ int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd, unsigned l * dytc_profile_set: Function to register with platform_profile * handler. Sets current platform profile. */ -int dytc_profile_set(struct platform_profile_handler *pprof, - enum platform_profile_option profile) +static int dytc_profile_set(struct platform_profile_handler *pprof, + enum platform_profile_option profile) { - struct ideapad_dytc_priv *dytc; - struct ideapad_private *priv; + struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); + struct ideapad_private *priv = dytc->priv; int err; - dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); - priv = dytc->priv; - err = mutex_lock_interruptible(&dytc->mutex); if (err) return err; @@ -747,16 +773,18 @@ int dytc_profile_set(struct platform_profile_handler *pprof, goto unlock; /* Determine if we are in CQL mode. This alters the commands we do */ - err = dytc_cql_command(priv, - DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1), - NULL); + err = dytc_cql_command(priv, DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1), + NULL); if (err) goto unlock; } + /* Success - update current profile */ dytc->current_profile = profile; + unlock: mutex_unlock(&dytc->mutex); + return err; } @@ -773,7 +801,10 @@ static void dytc_profile_refresh(struct ideapad_private *priv) return; perfmode = (output >> DYTC_GET_MODE_BIT) & 0xF; - convert_dytc_to_profile(perfmode, &profile); + + if (convert_dytc_to_profile(perfmode, &profile)) + return; + if (profile != priv->dytc->current_profile) { priv->dytc->current_profile = profile; platform_profile_notify(); @@ -794,14 +825,14 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv) return err; /* Check DYTC is enabled and supports mode setting */ - if (!(output & BIT(DYTC_QUERY_ENABLE_BIT))) + if (!test_bit(DYTC_QUERY_ENABLE_BIT, &output)) return -ENODEV; dytc_version = (output >> DYTC_QUERY_REV_BIT) & 0xF; if (dytc_version < 5) return -ENODEV; - priv->dytc = kzalloc(sizeof(struct ideapad_dytc_priv), GFP_KERNEL); + priv->dytc = kzalloc(sizeof(*priv->dytc), GFP_KERNEL); if (!priv->dytc) return -ENOMEM; @@ -819,17 +850,18 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv) /* Create platform_profile structure and register */ err = platform_profile_register(&priv->dytc->pprof); if (err) - goto mutex_destroy; + goto pp_reg_failed; /* Ensure initial values are correct */ dytc_profile_refresh(priv); return 0; -mutex_destroy: +pp_reg_failed: mutex_destroy(&priv->dytc->mutex); kfree(priv->dytc); priv->dytc = NULL; + return err; } @@ -841,6 +873,7 @@ static void ideapad_dytc_profile_exit(struct ideapad_private *priv) platform_profile_remove(); mutex_destroy(&priv->dytc->mutex); kfree(priv->dytc); + priv->dytc = NULL; } @@ -890,16 +923,15 @@ 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); + 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; @@ -911,20 +943,17 @@ 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 0; + + return err; } static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev) @@ -955,26 +984,25 @@ static void ideapad_sysfs_exit(struct ideapad_private *priv) * input device */ static const struct key_entry ideapad_keymap[] = { - { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } }, - { KE_KEY, 7, { KEY_CAMERA } }, - { KE_KEY, 8, { KEY_MICMUTE } }, - { KE_KEY, 11, { KEY_F16 } }, - { KE_KEY, 13, { KEY_WLAN } }, - { KE_KEY, 16, { KEY_PROG1 } }, - { KE_KEY, 17, { KEY_PROG2 } }, - { KE_KEY, 64, { KEY_PROG3 } }, - { KE_KEY, 65, { KEY_PROG4 } }, - { KE_KEY, 66, { KEY_TOUCHPAD_OFF } }, - { KE_KEY, 67, { KEY_TOUCHPAD_ON } }, + { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 7, { KEY_CAMERA } }, + { KE_KEY, 8, { KEY_MICMUTE } }, + { KE_KEY, 11, { KEY_F16 } }, + { KE_KEY, 13, { KEY_WLAN } }, + { KE_KEY, 16, { KEY_PROG1 } }, + { KE_KEY, 17, { KEY_PROG2 } }, + { KE_KEY, 64, { KEY_PROG3 } }, + { KE_KEY, 65, { KEY_PROG4 } }, + { KE_KEY, 66, { KEY_TOUCHPAD_OFF } }, + { 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) @@ -985,26 +1013,28 @@ 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"); + "Could not set up input device keymap: %d\n", err); 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"); + "Could not register input device: %d\n", err); goto err_free_dev; } priv->inputdev = inputdev; + return 0; err_free_dev: input_free_device(inputdev); - return error; + + return err; } static void ideapad_input_exit(struct ideapad_private *priv) @@ -1025,6 +1055,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 @@ -1040,8 +1071,8 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv) for_each_set_bit (bit, &value, 16) { switch (bit) { - case 0: /* Z580 */ case 6: /* Z570 */ + case 0: /* Z580 */ /* Thermal Management button */ ideapad_input_report(priv, 65); break; @@ -1069,6 +1100,7 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev) err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); if (err) return err; + return now; } @@ -1081,6 +1113,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) @@ -1104,30 +1137,36 @@ static int ideapad_backlight_init(struct ideapad_private *priv) 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)); + memset(&props, 0, sizeof(props)); + props.max_brightness = max; props.type = BACKLIGHT_PLATFORM; + blightdev = backlight_device_register("ideapad", &priv->platform_device->dev, priv, &ideapad_backlight_ops, &props); if (IS_ERR(blightdev)) { + err = PTR_ERR(blightdev); dev_err(&priv->platform_device->dev, - "Could not register backlight device\n"); - return PTR_ERR(blightdev); + "Could not register backlight device: %d\n", err); + return err; } priv->blightdev = blightdev; blightdev->props.brightness = now; blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; + backlight_update_status(blightdev); return 0; @@ -1141,13 +1180,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; } @@ -1156,12 +1197,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); } /* @@ -1176,13 +1215,14 @@ 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); } } @@ -1194,6 +1234,7 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1)) return; + if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2)) return; @@ -1201,9 +1242,6 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) for_each_set_bit (bit, &vpc1, 16) { switch (bit) { - case 9: - ideapad_sync_rfk_state(priv); - break; case 13: case 11: case 8: @@ -1211,6 +1249,9 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) case 6: ideapad_input_report(priv, bit); break; + case 9: + ideapad_sync_rfk_state(priv); + break; case 5: ideapad_sync_touchpad_state(priv); break; @@ -1223,16 +1264,17 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) 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 + /* + * 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; + case 0: + ideapad_check_special_buttons(priv); + break; default: dev_info(&priv->platform_device->dev, "Unknown event: %lu\n", bit); @@ -1304,14 +1346,14 @@ static void ideapad_check_features(struct ideapad_private *priv) static int ideapad_acpi_add(struct platform_device *pdev) { - int ret, i; struct ideapad_private *priv; struct acpi_device *adev; acpi_status status; 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)) @@ -1322,20 +1364,21 @@ static int ideapad_acpi_add(struct platform_device *pdev) return -ENOMEM; dev_set_drvdata(&pdev->dev, priv); + priv->cfg = cfg; priv->adev = adev; priv->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; /* @@ -1356,24 +1399,25 @@ static int ideapad_acpi_add(struct platform_device *pdev) ideapad_sync_rfk_state(priv); ideapad_sync_touchpad_state(priv); - ret = ideapad_dytc_profile_init(priv); - if (ret) { - if (ret != -ENODEV) - dev_warn(&pdev->dev, "Could not set up DYTC interface: %d\n", ret); + err = ideapad_dytc_profile_init(priv); + if (err) { + if (err != -ENODEV) + dev_warn(&pdev->dev, "Could not set up DYTC interface: %d\n", err); else dev_info(&pdev->dev, "DYTC interface is not available\n"); } 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; } + status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv); if (ACPI_FAILURE(status)) { - ret = -EIO; + err = -EIO; goto notification_failed; } @@ -1386,29 +1430,38 @@ static int ideapad_acpi_add(struct platform_device *pdev) break; } } + if (ACPI_FAILURE(status) && status != 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: ideapad_dytc_profile_exit(priv); + 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) @@ -1420,12 +1473,17 @@ 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); ideapad_dytc_profile_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); @@ -1450,8 +1508,8 @@ static int ideapad_acpi_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume); static const struct acpi_device_id ideapad_device_ids[] = { - { "VPC2004", 0}, - { "", 0}, + {"VPC2004", 0}, + {"", 0}, }; MODULE_DEVICE_TABLE(acpi, ideapad_device_ids); From patchwork Wed Feb 3 21:57:01 2021 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: 12065519 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 E5B3CC433E0 for ; Wed, 3 Feb 2021 21:58:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BB4064E4E for ; Wed, 3 Feb 2021 21:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231230AbhBCV55 (ORCPT ); Wed, 3 Feb 2021 16:57:57 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:61311 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232228AbhBCV5t (ORCPT ); Wed, 3 Feb 2021 16:57:49 -0500 Date: Wed, 03 Feb 2021 21:57:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389424; bh=AG4jrH82e4o9CdvlpSlQYJ2SZkUKJ+Pbuikp1H0i90c=; h=Date:To:From:Reply-To:Subject:From; b=hPqOE23CPlBIT0mp712gDI7E+kgHYqSpF4WsiG2iakQwm8CI1Tm0MSQU7z+yigxm+ 1gKZt2YqgP18mJFD87csvS2rEKI95MmEvp9EK6bTo6+diCPy0aP2Wnn7XHTMtYnhpd lDUmq+H4mAypDMtJiGHffpcOeHVbRzPxuav8shck= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 25/29] platform/x86: ideapad-laptop: send notification about touchpad state change to sysfs Message-ID: <20210203215403.290792-26-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 Reviewed-by: Hans de Goede Reviewed-by: Andy Shevchenko diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 2068831c5fe8..76b723f32c84 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -1224,6 +1224,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 Feb 3 21:57:07 2021 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: 12065515 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 1C81AC433E0 for ; Wed, 3 Feb 2021 21:57:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD14364D90 for ; Wed, 3 Feb 2021 21:57:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232430AbhBCV5e (ORCPT ); Wed, 3 Feb 2021 16:57:34 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:18733 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232437AbhBCV51 (ORCPT ); Wed, 3 Feb 2021 16:57:27 -0500 Date: Wed, 03 Feb 2021 21:57:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389429; bh=WIG875gim8mu7dwTflhai9jDItpRN/nZ3N/G6mWSqZ4=; h=Date:To:From:Reply-To:Subject:From; b=jp5QBBWrE7gbLXMowfdwTLwG6rUvyycIRX0CEQJFdBg5i2pnRkxgCg4IFUPA0t2tU 1xX4y4Vhq8Fgx/TLtctQur3PCCVvHn5WfqstejAvlG867032dxCHWeLyrDQN1MOvQI pPMDTVCqnb1CfhI2+nBD/EHWM4bBJN70+NjQFvwE= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 26/29] platform/x86: ideapad-laptop: add keyboard backlight control support Message-ID: <20210203215403.290792-27-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 76b723f32c84..c3f1b621c92f 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 @@ -22,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +34,8 @@ #include +#include + #define IDEAPAD_RFKILL_DEV_NUM 3 #if IS_ENABLED(CONFIG_ACPI_WMI) @@ -59,12 +63,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, }; @@ -125,8 +133,14 @@ struct ideapad_private { bool fan_mode : 1; bool fn_lock : 1; bool hw_rfkill_switch : 1; + bool kbd_bl : 1; bool touchpad_ctrl_via_ec : 1; } features; + struct { + bool initialized; + struct led_classdev led; + unsigned int last_brightness; + } kbd_bl; }; static bool no_bt_rfkill; @@ -1203,6 +1217,108 @@ 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 = exec_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) +{ + int brightness, err; + + if (!priv->features.kbd_bl) + return -ENODEV; + + if (WARN_ON(priv->kbd_bl.initialized)) + return -EEXIST; + + brightness = ideapad_kbd_bl_brightness_get(priv); + if (brightness < 0) + return brightness; + + priv->kbd_bl.last_brightness = brightness; + + 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; + + priv->kbd_bl.initialized = false; + + led_classdev_unregister(&priv->kbd_bl.led); +} + /* * module init/exit */ @@ -1270,8 +1386,10 @@ 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; some report this when the keyboard + * backlight has changed. */ + ideapad_kbd_bl_notify(priv); break; case 0: ideapad_check_special_buttons(priv); @@ -1341,6 +1459,9 @@ static void ideapad_check_features(struct ideapad_private *priv) if (!eval_hals(handle, &val)) { if (test_bit(HALS_FNLOCK_SUPPORT_BIT, &val)) priv->features.fn_lock = true; + + if (test_bit(HALS_KBD_BL_SUPPORT_BIT, &val)) + priv->features.kbd_bl = true; } } } @@ -1382,6 +1503,14 @@ static int ideapad_acpi_add(struct platform_device *pdev) if (err) goto input_failed; + err = ideapad_kbd_bl_init(priv); + if (err) { + if (err != -ENODEV) + dev_warn(&pdev->dev, "Could not set up keyboard backlight LED: %d\n", err); + else + dev_info(&pdev->dev, "Keyboard backlight control not available\n"); + } + /* * 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. @@ -1456,6 +1585,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: @@ -1485,6 +1615,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 Feb 3 21:57:13 2021 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: 12065523 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 37E8CC433DB for ; Wed, 3 Feb 2021 21:58:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F391C64E4E for ; Wed, 3 Feb 2021 21:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231807AbhBCV6J (ORCPT ); Wed, 3 Feb 2021 16:58:09 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:22808 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232491AbhBCV6F (ORCPT ); Wed, 3 Feb 2021 16:58:05 -0500 Date: Wed, 03 Feb 2021 21:57:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389443; bh=6i8W0eq7v7CIJ0RXzFn1bJ+I5Imthj5QS63mvNUev+E=; h=Date:To:From:Reply-To:Subject:From; b=C+Aj1QBtFiHf7nb7YTgZcg6gqjCDhGJWN6VpqWZHdSWYxmx5fuPKIfKXZi2hfLnAg mFkxTkllyegNbAFoUW4IgMrBQXyaGf5CU8cDp/GBoNhOQQ47TZcEKvmA1DTC86PsJo oEwyDB5E3fKXc8wQ6jvT+3gEciXh1VOmwSJngcdw= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 27/29] platform/x86: ideapad-laptop: add "always on USB charging" control support Message-ID: <20210203215403.290792-28-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/Documentation/ABI/testing/sysfs-platform-ideapad-laptop b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop index fd2ac02bc5bd..b17688d73922 100644 --- a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop +++ b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop @@ -41,3 +41,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: Feb 2021 +KernelVersion: 5.12 +Contact: platform-driver-x86@vger.kernel.org +Description: + Controls whether the "always on USB charging" feature is + enabled or not. This feature enables charging USB devices + even if the computer is not turned on. diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index c3f1b621c92f..12a74fddca49 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -63,18 +63,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 { @@ -135,6 +139,7 @@ struct ideapad_private { bool hw_rfkill_switch : 1; bool kbd_bl : 1; bool touchpad_ctrl_via_ec : 1; + bool usb_charging : 1; } features; struct { bool initialized; @@ -595,12 +600,49 @@ static ssize_t touchpad_store(struct device *dev, static DEVICE_ATTR_RW(touchpad); +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, "%d\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 = exec_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_conservation_mode.attr, &dev_attr_fan_mode.attr, &dev_attr_fn_lock.attr, &dev_attr_touchpad.attr, + &dev_attr_usb_charging.attr, NULL }; @@ -623,6 +665,8 @@ static umode_t ideapad_is_visible(struct kobject *kobj, else if (attr == &dev_attr_touchpad.attr) supported = priv->features.touchpad_ctrl_via_ec && test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg); + else if (attr == &dev_attr_usb_charging.attr) + supported = priv->features.usb_charging; return supported ? attr->mode : 0; } @@ -1462,6 +1506,9 @@ static void ideapad_check_features(struct ideapad_private *priv) if (test_bit(HALS_KBD_BL_SUPPORT_BIT, &val)) priv->features.kbd_bl = true; + + if (test_bit(HALS_USB_CHARGING_SUPPORT_BIT, &val)) + priv->features.usb_charging = true; } } } From patchwork Wed Feb 3 21:57:19 2021 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: 12065525 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 5B4BFC433E0 for ; Wed, 3 Feb 2021 21:58:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2843B64F5F for ; Wed, 3 Feb 2021 21:58:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232228AbhBCV6K (ORCPT ); Wed, 3 Feb 2021 16:58:10 -0500 Received: from mail1.protonmail.ch ([185.70.40.18]:36108 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232498AbhBCV6H (ORCPT ); Wed, 3 Feb 2021 16:58:07 -0500 Date: Wed, 03 Feb 2021 21:57:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389444; bh=SiLFfad6mFxKz8kjWlPsQKjBzSokyileB/8EdWSyBLU=; h=Date:To:From:Reply-To:Subject:From; b=AZxwRfpQvUo373sUeW/0WoiSSZeMNlE7MBy0qUGCHjDkZ7X443N88bmy8HuD6mjG8 UwmBE2FUjhX+yy3BQE5BGMJOn9lJUBsMnkbW54WiaTdyhl3QnMok5D07Fptsr22N5G mBUohtLHhKld0hwEuHmyF1qHIVxroo/pU0f4UNGw= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 28/29] Documentation/ABI: sysfs-platform-ideapad-laptop: update device attribute paths Message-ID: <20210203215403.290792-29-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. Fixes: b5c37b798f2d ("ideapad_laptop: convert ideapad device/driver to platform bus") 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 b17688d73922..5ec0dee9e707 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 Feb 3 21:57:26 2021 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: 12065527 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 05881C433DB for ; Wed, 3 Feb 2021 21:58:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3A1864D90 for ; Wed, 3 Feb 2021 21:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232108AbhBCV6U (ORCPT ); Wed, 3 Feb 2021 16:58:20 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:63174 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232249AbhBCV6Q (ORCPT ); Wed, 3 Feb 2021 16:58:16 -0500 Date: Wed, 03 Feb 2021 21:57:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389454; bh=NRdox9uK80FeSyw0JXeDXp+xsYb7sTbF42CRT+GBb38=; h=Date:To:From:Reply-To:Subject:From; b=FTVLQZt2qrpE22EeTzYbWUZInGVabuGf6Y9yeaa4V4aV9TWSSpMHEwDZG3w8l3CiX e4swTUgCCBMdN8Cvh1Yn3+aTJkZT0tFDO8inZmyObhuq7nwcEPtbZY+MLBQmbRlxCi VVYoX8WTeNFiMj+EkU/8HKkBeEpfv88tmwEH+4KM= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 29/29] Documentation/ABI: sysfs-platform-ideapad-laptop: conservation_mode attribute Message-ID: <20210203215403.290792-30-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Document the conservation_mode attributes provided by the ideapad-laptop module. Fixes: ade50296186a ("platform/x86: ideapad-laptop: Expose conservation mode switch") 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 5ec0dee9e707..4989ab266682 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