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 05/24] platform/x86: ideapad-laptop: use for_each_set_bit() helper to simplify event processing
Date: Wed, 16 Dec 2020 01:39:20 +0000 [thread overview]
Message-ID: <20201216013857.360987-6-pobrn@protonmail.com> (raw)
In-Reply-To: <20201216013857.360987-1-pobrn@protonmail.com>
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 <pobrn@protonmail.com>
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index 11df791d702c..22e1b3fd3df5 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -11,6 +11,7 @@
#include <acpi/video.h>
#include <linux/acpi.h>
#include <linux/backlight.h>
+#include <linux/bitops.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/dmi.h>
@@ -738,22 +739,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;
}
}
}
@@ -884,7 +883,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;
@@ -892,44 +891,42 @@ 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);
}
}
}
--
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 ` Barnabás Pőcze [this message]
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 ` [PATCH 12/24] platform/x86: ideapad-laptop: rework and create new ACPI helpers Barnabás Pőcze
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-6-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