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);