Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <andy.shevchenko@gmail.com>
Link: https://patch.msgid.link/20240826212344.866928-2-andy.shevchenko@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andy Shevchenko and committed by
Jonathan Cameron
17601ab9 2f1dddc9

+1 -69
+1 -69
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 2646 2646 return 0; 2647 2647 } 2648 2648 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 - 2716 2649 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, 2717 2650 struct regmap *regmap) 2718 2651 { ··· 2720 2787 return err; 2721 2788 } 2722 2789 2723 - err = lsm6dsx_get_acpi_mount_matrix(hw->dev, &hw->orientation); 2724 - if (err) { 2790 + if (!iio_read_acpi_mount_matrix(hw->dev, &hw->orientation, "ROTM")) { 2725 2791 err = iio_read_mount_matrix(hw->dev, &hw->orientation); 2726 2792 if (err) 2727 2793 return err;