From: Hans de Goede <hdegoede@redhat.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Sean Rhodes <sean@starlabs.systems>,
"Rafael J . Wysocki" <rafael@kernel.org>,
linux-iio@vger.kernel.org, linux-acpi@vger.kernel.org
Subject: [PATCH v2 3/4] iio: bmc150-accel-core: Use acpi_read_mount_matrix() helper
Date: Mon, 22 Apr 2024 12:02:17 +0200 [thread overview]
Message-ID: <20240422100218.7693-4-hdegoede@redhat.com> (raw)
In-Reply-To: <20240422100218.7693-1-hdegoede@redhat.com>
Replace the duplicate ACPI "ROTM" data parsing code with the new
shared acpi_read_mount_matrix() helper.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/iio/accel/bmc150-accel-core.c | 45 ++-------------------------
1 file changed, 3 insertions(+), 42 deletions(-)
diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 110591804b4c..ace550b0ba40 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -23,6 +23,7 @@
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
+#include "acpi-helpers.h"
#include "bmc150-accel.h"
#define BMC150_ACCEL_DRV_NAME "bmc150_accel"
@@ -386,13 +387,9 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev,
struct iio_mount_matrix *orientation)
{
- struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct acpi_device *adev = ACPI_COMPANION(dev);
- char *name, *alt_name, *label, *str;
- union acpi_object *obj, *elements;
- acpi_status status;
- int i, j, val[3];
+ char *name, *alt_name, *label;
if (strcmp(dev_name(dev), "i2c-BOSC0200:base") == 0) {
alt_name = "ROMK";
@@ -411,43 +408,7 @@ static bool bmc150_apply_bosc0200_acpi_orientation(struct device *dev,
return false;
}
- status = acpi_evaluate_object(adev->handle, name, NULL, &buffer);
- if (ACPI_FAILURE(status)) {
- dev_warn(dev, "Failed to get ACPI mount matrix: %d\n", status);
- return false;
- }
-
- obj = buffer.pointer;
- if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3)
- goto unknown_format;
-
- elements = obj->package.elements;
- for (i = 0; i < 3; i++) {
- if (elements[i].type != ACPI_TYPE_STRING)
- goto unknown_format;
-
- str = elements[i].string.pointer;
- if (sscanf(str, "%d %d %d", &val[0], &val[1], &val[2]) != 3)
- goto unknown_format;
-
- for (j = 0; j < 3; j++) {
- switch (val[j]) {
- case -1: str = "-1"; break;
- case 0: str = "0"; break;
- case 1: str = "1"; break;
- default: goto unknown_format;
- }
- orientation->rotation[i * 3 + j] = str;
- }
- }
-
- kfree(buffer.pointer);
- return true;
-
-unknown_format:
- dev_warn(dev, "Unknown ACPI mount matrix format, ignoring\n");
- kfree(buffer.pointer);
- return false;
+ return acpi_read_mount_matrix(dev, orientation, name);
}
static bool bmc150_apply_dual250e_acpi_orientation(struct device *dev,
--
2.44.0
next prev parent reply other threads:[~2024-04-22 10:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 10:02 [PATCH v2 0/4] iio: accel: Share ACPI ROTM parsing between drivers and add it to mxc4005 Hans de Goede
2024-04-22 10:02 ` [PATCH v2 1/4] iio: accel: kxcjk-1013: Simplify ACPI ROTM mount matrix retreival Hans de Goede
2024-04-22 10:02 ` [PATCH v2 2/4] iio: accel: kxcjk-1013: Move ACPI ROTM parsing to new acpi-helpers.h Hans de Goede
2024-04-22 10:02 ` Hans de Goede [this message]
2024-04-22 10:02 ` [PATCH v2 4/4] iio: accel: mxc4005: Read orientation matrix from ACPI ROTM method Hans de Goede
2024-04-22 16:06 ` [PATCH v2 0/4] iio: accel: Share ACPI ROTM parsing between drivers and add it to mxc4005 Rafael J. Wysocki
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=20240422100218.7693-4-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sean@starlabs.systems \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).