From patchwork Wed Mar 29 01:45:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Kallmeyer X-Patchwork-Id: 668411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AA20C77B6D for ; Wed, 29 Mar 2023 01:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbjC2Bqa (ORCPT ); Tue, 28 Mar 2023 21:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbjC2Bq2 (ORCPT ); Tue, 28 Mar 2023 21:46:28 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 960A419BF; Tue, 28 Mar 2023 18:46:27 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id kq3so13457651plb.13; Tue, 28 Mar 2023 18:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680054387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i2b2cYygU+LX0ZvIUsqKn/3NwRFS+je4j5ssTIHKMfQ=; b=aDYjeK83fTUMm1iKawl+mFIlXt5lnPMqHMgIrVDp+BCteZoj2bx8hOKrsviU6lkxzh XGIKIUeaGxpI+yFjWkvGvt/b1SvJhZkcsywtTjHk1i7VMz2Pa75nl9+44TxzCCTbBBDY fjsZ6Ia1h27iK5q4dr72nT83QUs+ingr4oS0OG8HQwzV1EKexy8PcE9/P1fCgGnwg6kY DhJV5xoiM4s8u6gMA7t0RGQwiZ0Tam15atvEuZUT+m/REG3txxoRTlELDEaGUgSfLJ1W 5X5Gy7fMuajhEErs3NxlUMIdl7Ldwfv++p3jJ4beosd5h0BASsJ98gXxTqBMQW9tcbZ5 5GnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680054387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i2b2cYygU+LX0ZvIUsqKn/3NwRFS+je4j5ssTIHKMfQ=; b=q+8Q3APWqfmaYWEzp8W6ZUsDrEka/iYYCzmYNKKPcwtqm9QagpxtkGGHhc4RJx5sob C+J2pSLQC5Sg5Aw2sC6BR6+Mw2n7edP/Lns220cEFET6tPFQvasck3mbAy7jieXHYnvY mIpk1Rw92/do4vyCBm0nG4r0LXtNzu9Y9kh7bTUMTDi5vYoAYRmyxKD9yp+pWaueiKLx Q1wiBjCGejPgIHAOsahV5UZi0qHelwMxpftVc9ccczM+H9vFpQtfehiFgjAfejkotDNm IyqCmseQyAWishzj1dkU6iBqiXg6mh8DZVpUc31H5lGdao+9qcuUr/njlLJQLa+tRYDh irgQ== X-Gm-Message-State: AAQBX9fSljofNHF9HdLOvogITIkLbGsU6RrYXpJvJCiZXRcH0sisThMt avnVkopiwMSeYx8EUid4VTAvx92KRPJydQ== X-Google-Smtp-Source: AKy350Yx+lp+Kwtz7Y4i5dw2OPkXq6EMPiMjWO/6/HOIsrj5b7nf/107CkBzUz6quk97unMq6OM7Kw== X-Received: by 2002:a17:90a:1a48:b0:237:c5cc:15bf with SMTP id 8-20020a17090a1a4800b00237c5cc15bfmr18911263pjl.13.1680054386854; Tue, 28 Mar 2023 18:46:26 -0700 (PDT) Received: from localhost.localdomain ([47.147.242.129]) by smtp.gmail.com with ESMTPSA id nv8-20020a17090b1b4800b00233cde36909sm203918pjb.21.2023.03.28.18.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 18:46:26 -0700 (PDT) From: Andrew Kallmeyer To: platform-driver-x86@vger.kernel.org Cc: Andrew Kallmeyer , Gergo Koteles , Ike Panhc , linux-input@vger.kernel.org, Hans de Goede , Armin Wolf , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 1/2] platform/x86: Move ideapad ACPI helpers to a new header Date: Tue, 28 Mar 2023 18:45:58 -0700 Message-Id: <20230329014559.44494-2-kallmeyeras@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230329014559.44494-1-kallmeyeras@gmail.com> References: <20230329014559.44494-1-kallmeyeras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org These functions will be used by a driver written by Gergo Koteles to detect the tablet mode switch in Lenovo Yoga laptops. These changes were discussed in review of that patch. This is the minimal set of functions needed in that driver, there are several more small functions left in the ACPI Helpers section in ideapad-laptop.c. The only change is the functions are now marked inline as requested in the review comments. Signed-off-by: Andrew Kallmeyer Link: https://lore.kernel.org/r/20221004214332.35934-1-soyer@irl.hu/ --- drivers/platform/x86/ideapad-laptop.c | 135 +---------------------- drivers/platform/x86/ideapad-laptop.h | 151 ++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 134 deletions(-) create mode 100644 drivers/platform/x86/ideapad-laptop.h diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 0eb5bfdd8..55f56697e 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -31,6 +30,7 @@ #include #include #include +#include "ideapad-laptop.h" #include @@ -85,33 +85,6 @@ enum { SALS_FNLOCK_OFF = 0xf, }; -enum { - VPCCMD_R_VPC1 = 0x10, - VPCCMD_R_BL_MAX, - VPCCMD_R_BL, - VPCCMD_W_BL, - VPCCMD_R_WIFI, - VPCCMD_W_WIFI, - VPCCMD_R_BT, - VPCCMD_W_BT, - VPCCMD_R_BL_POWER, - VPCCMD_R_NOVO, - VPCCMD_R_VPC2, - VPCCMD_R_TOUCHPAD, - VPCCMD_W_TOUCHPAD, - VPCCMD_R_CAMERA, - VPCCMD_W_CAMERA, - VPCCMD_R_3G, - VPCCMD_W_3G, - VPCCMD_R_ODD, /* 0x21 */ - VPCCMD_W_FAN, - VPCCMD_R_RF, - VPCCMD_W_RF, - VPCCMD_R_FAN = 0x2B, - VPCCMD_R_SPECIAL_BUTTONS = 0x31, - VPCCMD_W_BL_POWER = 0x33, -}; - struct ideapad_dytc_priv { enum platform_profile_option current_profile; struct platform_profile_handler pprof; @@ -227,7 +200,6 @@ static void ideapad_shared_exit(struct ideapad_private *priv) /* * ACPI Helpers */ -#define IDEAPAD_EC_TIMEOUT 200 /* in ms */ static int eval_int(acpi_handle handle, const char *name, unsigned long *res) { @@ -270,116 +242,11 @@ static int exec_sals(acpi_handle handle, unsigned long arg) return exec_simple_method(handle, "SALS", arg); } -static int eval_int_with_arg(acpi_handle handle, const char *name, unsigned long arg, unsigned long *res) -{ - 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 = arg; - - status = acpi_evaluate_integer(handle, (char *)name, ¶ms, &result); - if (ACPI_FAILURE(status)) - return -EIO; - - 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 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; - - params.count = 2; - params.pointer = in_obj; - in_obj[0].type = ACPI_TYPE_INTEGER; - in_obj[0].integer.value = cmd; - in_obj[1].type = ACPI_TYPE_INTEGER; - in_obj[1].integer.value = data; - - status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); - if (ACPI_FAILURE(status)) - return -EIO; - - return 0; -} - -static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data) -{ - unsigned long end_jiffies, val; - int err; - - err = eval_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(); - - err = eval_vpcr(handle, 1, &val); - if (err) - return err; - - if (val == 0) - return eval_vpcr(handle, 0, data); - } - - acpi_handle_err(handle, "timeout in %s\n", __func__); - - return -ETIMEDOUT; -} - -static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data) -{ - unsigned long end_jiffies, val; - int err; - - err = eval_vpcw(handle, 0, data); - if (err) - return err; - - err = eval_vpcw(handle, 1, cmd); - if (err) - return err; - - end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; - - 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; -} - /* * debugfs */ diff --git a/drivers/platform/x86/ideapad-laptop.h b/drivers/platform/x86/ideapad-laptop.h new file mode 100644 index 000000000..7dd8ce027 --- /dev/null +++ b/drivers/platform/x86/ideapad-laptop.h @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * ideapad-laptop.h - Lenovo IdeaPad ACPI Extras + * + * Copyright © 2010 Intel Corporation + * Copyright © 2010 David Woodhouse + */ + +#ifndef _IDEAPAD_LAPTOP_H_ +#define _IDEAPAD_LAPTOP_H_ + +#include +#include +#include + +enum { + VPCCMD_R_VPC1 = 0x10, + VPCCMD_R_BL_MAX, + VPCCMD_R_BL, + VPCCMD_W_BL, + VPCCMD_R_WIFI, + VPCCMD_W_WIFI, + VPCCMD_R_BT, + VPCCMD_W_BT, + VPCCMD_R_BL_POWER, + VPCCMD_R_NOVO, + VPCCMD_R_VPC2, + VPCCMD_R_TOUCHPAD, + VPCCMD_W_TOUCHPAD, + VPCCMD_R_CAMERA, + VPCCMD_W_CAMERA, + VPCCMD_R_3G, + VPCCMD_W_3G, + VPCCMD_R_ODD, /* 0x21 */ + VPCCMD_W_FAN, + VPCCMD_R_RF, + VPCCMD_W_RF, + VPCCMD_R_FAN = 0x2B, + VPCCMD_R_SPECIAL_BUTTONS = 0x31, + VPCCMD_W_BL_POWER = 0x33, +}; + +static inline int eval_int_with_arg(acpi_handle handle, const char *name, unsigned long arg, unsigned long *res) +{ + 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 = arg; + + status = acpi_evaluate_integer(handle, (char *)name, ¶ms, &result); + if (ACPI_FAILURE(status)) + return -EIO; + + if (res) + *res = result; + + return 0; +} + +static inline int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *res) +{ + return eval_int_with_arg(handle, "VPCR", cmd, res); +} + +static inline 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; + + params.count = 2; + params.pointer = in_obj; + in_obj[0].type = ACPI_TYPE_INTEGER; + in_obj[0].integer.value = cmd; + in_obj[1].type = ACPI_TYPE_INTEGER; + in_obj[1].integer.value = data; + + status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); + if (ACPI_FAILURE(status)) + return -EIO; + + return 0; +} + +#define IDEAPAD_EC_TIMEOUT 200 /* in ms */ + +static inline int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data) +{ + unsigned long end_jiffies, val; + int err; + + err = eval_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(); + + err = eval_vpcr(handle, 1, &val); + if (err) + return err; + + if (val == 0) + return eval_vpcr(handle, 0, data); + } + + acpi_handle_err(handle, "timeout in %s\n", __func__); + + return -ETIMEDOUT; +} + +static inline int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data) +{ + unsigned long end_jiffies, val; + int err; + + err = eval_vpcw(handle, 0, data); + if (err) + return err; + + err = eval_vpcw(handle, 1, cmd); + if (err) + return err; + + end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; + + 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; +} + +#undef IDEAPAD_EC_TIMEOUT +#endif /* !_IDEAPAD_LAPTOP_H_ */