aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2024-04-25 14:57:52 +0200
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2024-04-29 20:53:25 +0100
commite074cc3080d507b3680160248bb5b450d7009efb (patch)
tree2d6acc3926972f15ac1fb02ffa240f7c5a73789a
parent02eae0bb9538dc7dcb5a6bc2c3066bd6ca682969 (diff)
downloadiio-e074cc3080d507b3680160248bb5b450d7009efb.tar.gz
iio: accel: kxcjk-1013: Use new iio_read_acpi_mount_matrix() helper
Replace the duplicate ACPI "ROTM" data parsing code with the new shared iio_read_acpi_mount_matrix() helper. This also removes the limiting of the "ROTM" mount matrix to only ACPI devices with an ACPI HID (Hardware-ID) of "KIOX000A". If kxcjk-1013 ACPI devices with another HID have a ROTM method that should still be parsed and if the method is not there then iio_read_acpi_mount_matrix() will fail silently. Acked-by: Rafael J. Wysocki <rafael@kernel.org> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20240425125754.76010-3-hdegoede@redhat.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r--drivers/iio/accel/kxcjk-1013.c80
1 files changed, 1 insertions, 79 deletions
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 126e8bdd6d0ed3..8280d2bef0a374 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -636,84 +636,6 @@ static int kxcjk1013_set_power_state(struct kxcjk1013_data *data, bool on)
return 0;
}
-#ifdef CONFIG_ACPI
-static bool kxj_acpi_orientation(struct device *dev,
- struct iio_mount_matrix *orientation)
-{
- struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
- struct acpi_device *adev = ACPI_COMPANION(dev);
- char *str;
- union acpi_object *obj, *elements;
- acpi_status status;
- int i, j, val[3];
- bool ret = false;
-
- if (!acpi_has_method(adev->handle, "ROTM"))
- return false;
-
- status = acpi_evaluate_object(adev->handle, "ROTM", NULL, &buffer);
- if (ACPI_FAILURE(status)) {
- dev_err(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) {
- dev_err(dev, "Unknown ACPI mount matrix package format\n");
- goto out_free_buffer;
- }
-
- elements = obj->package.elements;
- for (i = 0; i < 3; i++) {
- if (elements[i].type != ACPI_TYPE_STRING) {
- dev_err(dev, "Unknown ACPI mount matrix element format\n");
- goto out_free_buffer;
- }
-
- str = elements[i].string.pointer;
- if (sscanf(str, "%d %d %d", &val[0], &val[1], &val[2]) != 3) {
- dev_err(dev, "Incorrect ACPI mount matrix string format\n");
- goto out_free_buffer;
- }
-
- 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:
- dev_err(dev, "Invalid value in ACPI mount matrix: %d\n", val[j]);
- goto out_free_buffer;
- }
- orientation->rotation[i * 3 + j] = str;
- }
- }
-
- ret = true;
-
-out_free_buffer:
- kfree(buffer.pointer);
- return ret;
-}
-
-static bool kxj1009_apply_acpi_orientation(struct device *dev,
- struct iio_mount_matrix *orientation)
-{
- struct acpi_device *adev = ACPI_COMPANION(dev);
-
- if (adev && acpi_dev_hid_uid_match(adev, "KIOX000A", NULL))
- return kxj_acpi_orientation(dev, orientation);
-
- return false;
-}
-#else
-static bool kxj1009_apply_acpi_orientation(struct device *dev,
- struct iio_mount_matrix *orientation)
-{
- return false;
-}
-#endif
-
static int kxcjk1013_chip_update_thresholds(struct kxcjk1013_data *data)
{
int ret;
@@ -1544,7 +1466,7 @@ static int kxcjk1013_probe(struct i2c_client *client)
} else {
data->active_high_intr = true; /* default polarity */
- if (!kxj1009_apply_acpi_orientation(&client->dev, &data->orientation)) {
+ if (!iio_read_acpi_mount_matrix(&client->dev, &data->orientation, "ROTM")) {
ret = iio_read_mount_matrix(&client->dev, &data->orientation);
if (ret)
return ret;