Skip to content

Commit 17601ab

Browse files
andy-shevjic23
authored andcommitted
iio: imu: st_lsm6dsx: Use iio_read_acpi_mount_matrix() helper
Replace the duplicate ACPI "ROTM" data parsing code with the new shared iio_read_acpi_mount_matrix() helper. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 2f1dddc commit 17601ab

File tree

1 file changed

+1
-69
lines changed

1 file changed

+1
-69
lines changed

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,73 +2646,6 @@ static int st_lsm6dsx_init_regulators(struct device *dev)
26462646
return 0;
26472647
}
26482648

2649-
#ifdef CONFIG_ACPI
2650-
2651-
static int lsm6dsx_get_acpi_mount_matrix(struct device *dev,
2652-
struct iio_mount_matrix *orientation)
2653-
{
2654-
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
2655-
struct acpi_device *adev = ACPI_COMPANION(dev);
2656-
union acpi_object *obj, *elements;
2657-
acpi_status status;
2658-
int i, j, val[3];
2659-
char *str;
2660-
2661-
if (!has_acpi_companion(dev))
2662-
return -EINVAL;
2663-
2664-
if (!acpi_has_method(adev->handle, "ROTM"))
2665-
return -EINVAL;
2666-
2667-
status = acpi_evaluate_object(adev->handle, "ROTM", NULL, &buffer);
2668-
if (ACPI_FAILURE(status)) {
2669-
dev_warn(dev, "Failed to get ACPI mount matrix: %d\n", status);
2670-
return -EINVAL;
2671-
}
2672-
2673-
obj = buffer.pointer;
2674-
if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3)
2675-
goto unknown_format;
2676-
2677-
elements = obj->package.elements;
2678-
for (i = 0; i < 3; i++) {
2679-
if (elements[i].type != ACPI_TYPE_STRING)
2680-
goto unknown_format;
2681-
2682-
str = elements[i].string.pointer;
2683-
if (sscanf(str, "%d %d %d", &val[0], &val[1], &val[2]) != 3)
2684-
goto unknown_format;
2685-
2686-
for (j = 0; j < 3; j++) {
2687-
switch (val[j]) {
2688-
case -1: str = "-1"; break;
2689-
case 0: str = "0"; break;
2690-
case 1: str = "1"; break;
2691-
default: goto unknown_format;
2692-
}
2693-
orientation->rotation[i * 3 + j] = str;
2694-
}
2695-
}
2696-
2697-
kfree(buffer.pointer);
2698-
return 0;
2699-
2700-
unknown_format:
2701-
dev_warn(dev, "Unknown ACPI mount matrix format, ignoring\n");
2702-
kfree(buffer.pointer);
2703-
return -EINVAL;
2704-
}
2705-
2706-
#else
2707-
2708-
static int lsm6dsx_get_acpi_mount_matrix(struct device *dev,
2709-
struct iio_mount_matrix *orientation)
2710-
{
2711-
return -EOPNOTSUPP;
2712-
}
2713-
2714-
#endif
2715-
27162649
int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
27172650
struct regmap *regmap)
27182651
{
@@ -2787,8 +2720,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
27872720
return err;
27882721
}
27892722

2790-
err = lsm6dsx_get_acpi_mount_matrix(hw->dev, &hw->orientation);
2791-
if (err) {
2723+
if (!iio_read_acpi_mount_matrix(hw->dev, &hw->orientation, "ROTM")) {
27922724
err = iio_read_mount_matrix(hw->dev, &hw->orientation);
27932725
if (err)
27942726
return err;

0 commit comments

Comments
 (0)