From patchwork Wed Jan 13 18:21: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: 12017521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 8BBCFC433DB for ; Wed, 13 Jan 2021 18:22:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DE2F23441 for ; Wed, 13 Jan 2021 18:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727851AbhAMSWd (ORCPT ); Wed, 13 Jan 2021 13:22:33 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:26280 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbhAMSWc (ORCPT ); Wed, 13 Jan 2021 13:22:32 -0500 Date: Wed, 13 Jan 2021 18:21:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1610562108; bh=WypS/mQ7Bcw5YU+gDNdIXzxr4CA5eWGEajvvrVc38z0=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=h9i6LkOTYACQC1sus5AWnEd8/8el+srV1VIVg+7AHL/mENam7teOraUOn1PzKNSRK F3COafQazhrxuI/ZgLAlAdTedjxkc9un+fEFufk0txSEfjG72UBoxORJPUn/5oOiPw 2hBNeawr0SeeuLl5Bd2Lw+Q7iPesMxKuIjrOOZp8= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v2 12/24] platform/x86: ideapad-laptop: rework and create new ACPI helpers Message-ID: <20210113182016.166049-13-pobrn@protonmail.com> In-Reply-To: <20210113182016.166049-1-pobrn@protonmail.com> References: <20210113182016.166049-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Create dedicated helper functions for accessing the main ACPI methods: GBMD, SMBC, HALS, SALS; and utilize them. Use `unsigned long` consistently in every ACPI helper wherever possible. Change names to better express purpose. Do not assign values to output parameters in case of failure. Signed-off-by: Barnabás Pőcze Reviewed-by: Hans de Goede diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 5f36e77d9058..c3234e0931a9 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -119,41 +119,47 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); */ #define IDEAPAD_EC_TIMEOUT (200) /* in ms */ -static int read_method_int(acpi_handle handle, const char *method, int *val) +static int eval_int(acpi_handle handle, const char *method, unsigned long *val) { - acpi_status status; + acpi_status acpi_err; unsigned long long result; - status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); - if (ACPI_FAILURE(status)) { - *val = -1; + acpi_err = acpi_evaluate_integer(handle, (char *)method, NULL, &result); + if (ACPI_FAILURE(acpi_err)) return -EIO; - } *val = result; return 0; +} +static int eval_simple_method(acpi_handle handle, char *method, u64 arg) +{ + acpi_status acpi_err = acpi_execute_simple_method(handle, method, arg); + return ACPI_FAILURE(acpi_err) ? -EIO : 0; } -static int method_gbmd(acpi_handle handle, unsigned long *ret) +static int eval_gbmd(acpi_handle handle, unsigned long *val) { - int result, val; + return eval_int(handle, "GBMD", val); +} - result = read_method_int(handle, "GBMD", &val); - *ret = val; - return result; +static int eval_smbc(acpi_handle handle, unsigned long arg) +{ + return eval_simple_method(handle, "SMBC", arg); } -static int method_int1(acpi_handle handle, char *method, int cmd) +static int eval_hals(acpi_handle handle, unsigned long *val) { - acpi_status status; + return eval_int(handle, "HALS", val); +} - status = acpi_execute_simple_method(handle, method, cmd); - return ACPI_FAILURE(status) ? -EIO : 0; +static int eval_sals(acpi_handle handle, unsigned long arg) +{ + return eval_simple_method(handle, "SALS", arg); } -static int method_vpcr(acpi_handle handle, int cmd, int *ret) +static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *val) { - acpi_status status; + acpi_status acpi_err; unsigned long long result; struct acpi_object_list params; union acpi_object in_obj; @@ -163,22 +169,20 @@ static int method_vpcr(acpi_handle handle, int cmd, int *ret) in_obj.type = ACPI_TYPE_INTEGER; in_obj.integer.value = cmd; - status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); + acpi_err = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); - if (ACPI_FAILURE(status)) { - *ret = -1; + if (ACPI_FAILURE(acpi_err)) return -EIO; - } - *ret = result; + *val = result; return 0; } -static int method_vpcw(acpi_handle handle, int cmd, int data) +static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data) { struct acpi_object_list params; union acpi_object in_obj[2]; - acpi_status status; + acpi_status acpi_err; params.count = 2; params.pointer = in_obj; @@ -187,55 +191,50 @@ static int method_vpcw(acpi_handle handle, int cmd, int data) in_obj[1].type = ACPI_TYPE_INTEGER; in_obj[1].integer.value = data; - status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); - if (status != AE_OK) + acpi_err = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); + if (ACPI_FAILURE(acpi_err)) return -EIO; return 0; } -static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) +static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data) { - int val, err; - unsigned long int end_jiffies; + int err; + unsigned long int end_jiffies, val; - err = method_vpcw(handle, 1, cmd); + err = eval_vpcw(handle, 1, cmd); if (err) return err; for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { schedule(); - err = method_vpcr(handle, 1, &val); + err = eval_vpcr(handle, 1, &val); if (err) return err; - if (val == 0) { - err = method_vpcr(handle, 0, &val); - if (err) - return err; - *data = val; - return 0; - } + if (val == 0) + return eval_vpcr(handle, 0, data); } acpi_handle_err(handle, "timeout in %s\n", __func__); return -ETIMEDOUT; } -static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) +static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data) { - int val, err; - unsigned long int end_jiffies; + int err; + unsigned long end_jiffies, val; - err = method_vpcw(handle, 0, data); + err = eval_vpcw(handle, 0, data); if (err) return err; - err = method_vpcw(handle, 1, cmd); + err = eval_vpcw(handle, 1, cmd); if (err) return err; for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; time_before(jiffies, end_jiffies);) { schedule(); - err = method_vpcr(handle, 1, &val); + err = eval_vpcr(handle, 1, &val); if (err) return err; if (val == 0) @@ -286,7 +285,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); @@ -468,7 +467,7 @@ static ssize_t conservation_mode_show(struct device *dev, unsigned long result; int err; - err = method_gbmd(priv->adev->handle, &result); + err = eval_gbmd(priv->adev->handle, &result); if (err) return err; return sysfs_emit(buf, "%u\n", test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); @@ -486,9 +485,8 @@ static ssize_t conservation_mode_store(struct device *dev, if (ret) return ret; - ret = method_int1(priv->adev->handle, "SBMC", state ? - SMBC_CONSERVATION_ON : - SMBC_CONSERVATION_OFF); + ret = eval_smbc(priv->adev->handle, + state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF); if (ret) return ret; return count; @@ -501,15 +499,13 @@ static ssize_t fn_lock_show(struct device *dev, char *buf) { struct ideapad_private *priv = dev_get_drvdata(dev); - unsigned long result; - int hals; - int fail = read_method_int(priv->adev->handle, "HALS", &hals); + unsigned long hals; + int fail = eval_hals(priv->adev->handle, &hals); if (fail) return fail; - result = hals; - return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &result)); + return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &hals)); } static ssize_t fn_lock_store(struct device *dev, @@ -524,9 +520,8 @@ static ssize_t fn_lock_store(struct device *dev, if (ret) return ret; - ret = method_int1(priv->adev->handle, "SALS", state ? - SALS_FNLOCK_ON : - SALS_FNLOCK_OFF); + ret = eval_sals(priv->adev->handle, + state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF); if (ret) return ret; return count; @@ -1016,7 +1011,7 @@ static const struct dmi_system_id hw_rfkill_list[] = { static int ideapad_acpi_add(struct platform_device *pdev) { int ret, i; - int cfg; + unsigned long cfg; struct ideapad_private *priv; struct acpi_device *adev; acpi_status acpi_err; @@ -1025,7 +1020,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) if (ret) return -ENODEV; - if (read_method_int(adev->handle, "_CFG", &cfg)) + if (eval_int(adev->handle, "_CFG", &cfg)) return -ENODEV; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);