From: "Barnabás Pőcze" <pobrn@protonmail.com>
To: platform-driver-x86@vger.kernel.org,
Hans de Goede <hdegoede@redhat.com>,
Mark Gross <mgross@linux.intel.com>,
Ike Panhc <ike.pan@canonical.com>
Subject: [PATCH 12/24] platform/x86: ideapad-laptop: rework and create new ACPI helpers
Date: Wed, 16 Dec 2020 01:39:54 +0000 [thread overview]
Message-ID: <20201216013857.360987-13-pobrn@protonmail.com> (raw)
In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com>
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 <pobrn@protonmail.com>
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index ffe41bf5585f..795978e0d13e 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -117,41 +117,47 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
*/
#define IDEAPAD_EC_TIMEOUT (200) /* in ms */
-static int read_method_int(acpi_handle handle, const char *method, int *val)
+static int eval_int(acpi_handle handle, const char *method, unsigned long *val)
{
- acpi_status status;
+ acpi_status acpi_err;
unsigned long long result;
- status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
- if (ACPI_FAILURE(status)) {
- *val = -1;
+ acpi_err = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
+ if (ACPI_FAILURE(acpi_err))
return -EIO;
- }
*val = result;
return 0;
+}
+static int eval_simple_method(acpi_handle handle, char *method, u64 arg)
+{
+ acpi_status acpi_err = acpi_execute_simple_method(handle, method, arg);
+ return ACPI_FAILURE(acpi_err) ? -EIO : 0;
}
-static int method_gbmd(acpi_handle handle, unsigned long *ret)
+static int eval_gbmd(acpi_handle handle, unsigned long *val)
{
- int result, val;
+ return eval_int(handle, "GBMD", val);
+}
- result = read_method_int(handle, "GBMD", &val);
- *ret = val;
- return result;
+static int eval_smbc(acpi_handle handle, unsigned long arg)
+{
+ return eval_simple_method(handle, "SMBC", arg);
}
-static int method_int1(acpi_handle handle, char *method, int cmd)
+static int eval_hals(acpi_handle handle, unsigned long *val)
{
- acpi_status status;
+ return eval_int(handle, "HALS", val);
+}
- status = acpi_execute_simple_method(handle, method, cmd);
- return ACPI_FAILURE(status) ? -EIO : 0;
+static int eval_sals(acpi_handle handle, unsigned long arg)
+{
+ return eval_simple_method(handle, "SALS", arg);
}
-static int method_vpcr(acpi_handle handle, int cmd, int *ret)
+static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *val)
{
- acpi_status status;
+ acpi_status acpi_err;
unsigned long long result;
struct acpi_object_list params;
union acpi_object in_obj;
@@ -161,22 +167,20 @@ static int method_vpcr(acpi_handle handle, int cmd, int *ret)
in_obj.type = ACPI_TYPE_INTEGER;
in_obj.integer.value = cmd;
- status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result);
+ acpi_err = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result);
- if (ACPI_FAILURE(status)) {
- *ret = -1;
+ if (ACPI_FAILURE(acpi_err))
return -EIO;
- }
- *ret = result;
+ *val = result;
return 0;
}
-static int method_vpcw(acpi_handle handle, int cmd, int data)
+static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data)
{
struct acpi_object_list params;
union acpi_object in_obj[2];
- acpi_status status;
+ acpi_status acpi_err;
params.count = 2;
params.pointer = in_obj;
@@ -185,55 +189,50 @@ static int method_vpcw(acpi_handle handle, int cmd, int data)
in_obj[1].type = ACPI_TYPE_INTEGER;
in_obj[1].integer.value = data;
- status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL);
- if (status != AE_OK)
+ acpi_err = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL);
+ if (ACPI_FAILURE(acpi_err))
return -EIO;
return 0;
}
-static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data)
+static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data)
{
- int val, err;
- unsigned long int end_jiffies;
+ int err;
+ unsigned long int end_jiffies, val;
- err = method_vpcw(handle, 1, cmd);
+ err = eval_vpcw(handle, 1, cmd);
if (err)
return err;
for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
time_before(jiffies, end_jiffies);) {
schedule();
- err = method_vpcr(handle, 1, &val);
+ err = eval_vpcr(handle, 1, &val);
if (err)
return err;
- if (val == 0) {
- err = method_vpcr(handle, 0, &val);
- if (err)
- return err;
- *data = val;
- return 0;
- }
+ if (val == 0)
+ return eval_vpcr(handle, 0, data);
}
acpi_handle_err(handle, "timeout in %s\n", __func__);
return -ETIMEDOUT;
}
-static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
+static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data)
{
- int val, err;
- unsigned long int end_jiffies;
+ int err;
+ unsigned long end_jiffies, val;
- err = method_vpcw(handle, 0, data);
+ err = eval_vpcw(handle, 0, data);
if (err)
return err;
- err = method_vpcw(handle, 1, cmd);
+ err = eval_vpcw(handle, 1, cmd);
if (err)
return err;
for (end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
time_before(jiffies, end_jiffies);) {
schedule();
- err = method_vpcr(handle, 1, &val);
+ err = eval_vpcr(handle, 1, &val);
if (err)
return err;
if (val == 0)
@@ -284,7 +283,7 @@ static int debugfs_status_show(struct seq_file *s, void *data)
value ? "On" : "Off", value);
seq_puts(s, "=====================\n");
- if (!method_gbmd(priv->adev->handle, &value)) {
+ if (!eval_gbmd(priv->adev->handle, &value)) {
seq_printf(s, "Conservation mode:\t%s(%lu)\n",
test_bit(GBMD_CONSERVATION_STATE_BIT, &value) ? "On" : "Off",
value);
@@ -466,7 +465,7 @@ static ssize_t conservation_mode_show(struct device *dev,
unsigned long result;
int err;
- err = method_gbmd(priv->adev->handle, &result);
+ err = eval_gbmd(priv->adev->handle, &result);
if (err)
return err;
return sysfs_emit(buf, "%u\n", test_bit(GBMD_CONSERVATION_STATE_BIT, &result));
@@ -484,9 +483,8 @@ static ssize_t conservation_mode_store(struct device *dev,
if (ret)
return ret;
- ret = method_int1(priv->adev->handle, "SBMC", state ?
- SMBC_CONSERVATION_ON :
- SMBC_CONSERVATION_OFF);
+ ret = eval_smbc(priv->adev->handle,
+ state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF);
if (ret)
return ret;
return count;
@@ -499,15 +497,13 @@ static ssize_t fn_lock_show(struct device *dev,
char *buf)
{
struct ideapad_private *priv = dev_get_drvdata(dev);
- unsigned long result;
- int hals;
- int fail = read_method_int(priv->adev->handle, "HALS", &hals);
+ unsigned long hals;
+ int fail = eval_hals(priv->adev->handle, &hals);
if (fail)
return fail;
- result = hals;
- return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &result));
+ return sysfs_emit(buf, "%u\n", test_bit(HALS_FNLOCK_STATE_BIT, &hals));
}
static ssize_t fn_lock_store(struct device *dev,
@@ -522,9 +518,8 @@ static ssize_t fn_lock_store(struct device *dev,
if (ret)
return ret;
- ret = method_int1(priv->adev->handle, "SALS", state ?
- SALS_FNLOCK_ON :
- SALS_FNLOCK_OFF);
+ ret = eval_sals(priv->adev->handle,
+ state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF);
if (ret)
return ret;
return count;
@@ -1009,7 +1004,7 @@ static const struct dmi_system_id hw_rfkill_list[] = {
static int ideapad_acpi_add(struct platform_device *pdev)
{
int ret, i;
- int cfg;
+ unsigned long cfg;
struct ideapad_private *priv;
struct acpi_device *adev;
acpi_status acpi_err;
@@ -1018,7 +1013,7 @@ static int ideapad_acpi_add(struct platform_device *pdev)
if (ret)
return -ENODEV;
- if (read_method_int(adev->handle, "_CFG", &cfg))
+ if (eval_int(adev->handle, "_CFG", &cfg))
return -ENODEV;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
--
2.29.2
next prev parent reply other threads:[~2020-12-16 1:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-16 1:39 [PATCH 00/24] platform/x86: ideapad-laptop: cleanup, keyboard backlight and "always on USB charging" control support, reenable touchpad control Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 01/24] platform/x86: ideapad-laptop: remove unnecessary dev_set_drvdata() call Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 02/24] platform/x86: ideapad-laptop: use appropriately typed variable to store the return value of ACPI methods Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 03/24] platform/x86: ideapad-laptop: sort includes lexicographically Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 04/24] platform/x86: ideapad-laptop: use sysfs_emit() Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 05/24] platform/x86: ideapad-laptop: use for_each_set_bit() helper to simplify event processing Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 06/24] platform/x86: ideapad-laptop: use msecs_to_jiffies() helper instead of hand-crafted formula Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 07/24] platform/x86: ideapad-laptop: use dev_{err,warn} or appropriate variant to display log messages Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 08/24] platform/x86: ideapad-laptop: convert ACPI helpers to return -EIO in case of failure Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 09/24] platform/x86: ideapad-laptop: always propagate error codes from device attributes' show() callback Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 10/24] platform/x86: ideapad-laptop: misc. device attribute changes Barnabás Pőcze
2020-12-16 1:39 ` [PATCH 11/24] platform/x86: ideapad-laptop: group and separate (un)related constants into enums Barnabás Pőcze
2020-12-16 1:39 ` Barnabás Pőcze [this message]
2021-01-04 12:03 ` [PATCH 00/24] platform/x86: ideapad-laptop: cleanup, keyboard backlight and "always on USB charging" control support, reenable touchpad control Barnabás Pőcze
2021-01-04 14:03 ` Hans de Goede
2021-01-04 14:10 ` Barnabás Pőcze
2021-01-06 18:23 ` Hans de Goede
2021-01-06 20:42 ` Barnabás Pőcze
2021-01-06 20:49 ` Barnabás Pőcze
2021-01-06 21:08 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201216013857.360987-13-pobrn@protonmail.com \
--to=pobrn@protonmail.com \
--cc=hdegoede@redhat.com \
--cc=ike.pan@canonical.com \
--cc=mgross@linux.intel.com \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox