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: accel: kxcjk-1013: Implement ACPI method ROTM to retrieve mount matrix.

Implement kxj_acpi_orientation to retrieve mount matrix
from ACPI ROTM method

Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
Link: https://lore.kernel.org/r/19d7a10aae5238a2c8db37da1f74edb86480e17e.1708293140.git.sean@starlabs.systems
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Sean Rhodes and committed by
Jonathan Cameron
3b4ebff2 ffe7c46c

+84 -3
+84 -3
drivers/iio/accel/kxcjk-1013.c
··· 636 636 return 0; 637 637 } 638 638 639 + #ifdef CONFIG_ACPI 640 + static bool kxj_acpi_orientation(struct device *dev, 641 + struct iio_mount_matrix *orientation) 642 + { 643 + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 644 + struct acpi_device *adev = ACPI_COMPANION(dev); 645 + char *str; 646 + union acpi_object *obj, *elements; 647 + acpi_status status; 648 + int i, j, val[3]; 649 + bool ret = false; 650 + 651 + if (!acpi_has_method(adev->handle, "ROTM")) 652 + return false; 653 + 654 + status = acpi_evaluate_object(adev->handle, "ROTM", NULL, &buffer); 655 + if (ACPI_FAILURE(status)) { 656 + dev_err(dev, "Failed to get ACPI mount matrix: %d\n", status); 657 + return false; 658 + } 659 + 660 + obj = buffer.pointer; 661 + if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3) { 662 + dev_err(dev, "Unknown ACPI mount matrix package format\n"); 663 + goto out_free_buffer; 664 + } 665 + 666 + elements = obj->package.elements; 667 + for (i = 0; i < 3; i++) { 668 + if (elements[i].type != ACPI_TYPE_STRING) { 669 + dev_err(dev, "Unknown ACPI mount matrix element format\n"); 670 + goto out_free_buffer; 671 + } 672 + 673 + str = elements[i].string.pointer; 674 + if (sscanf(str, "%d %d %d", &val[0], &val[1], &val[2]) != 3) { 675 + dev_err(dev, "Incorrect ACPI mount matrix string format\n"); 676 + goto out_free_buffer; 677 + } 678 + 679 + for (j = 0; j < 3; j++) { 680 + switch (val[j]) { 681 + case -1: str = "-1"; break; 682 + case 0: str = "0"; break; 683 + case 1: str = "1"; break; 684 + default: 685 + dev_err(dev, "Invalid value in ACPI mount matrix: %d\n", val[j]); 686 + goto out_free_buffer; 687 + } 688 + orientation->rotation[i * 3 + j] = str; 689 + } 690 + } 691 + 692 + ret = true; 693 + 694 + out_free_buffer: 695 + kfree(buffer.pointer); 696 + return ret; 697 + } 698 + 699 + static bool kxj1009_apply_acpi_orientation(struct device *dev, 700 + struct iio_mount_matrix *orientation) 701 + { 702 + struct acpi_device *adev = ACPI_COMPANION(dev); 703 + 704 + if (adev && acpi_dev_hid_uid_match(adev, "KIOX000A", NULL)) 705 + return kxj_acpi_orientation(dev, orientation); 706 + 707 + return false; 708 + } 709 + #else 710 + static bool kxj1009_apply_acpi_orientation(struct device *dev, 711 + struct iio_mount_matrix *orientation) 712 + { 713 + return false; 714 + } 715 + #endif 716 + 639 717 static int kxcjk1013_chip_update_thresholds(struct kxcjk1013_data *data) 640 718 { 641 719 int ret; ··· 1544 1466 } else { 1545 1467 data->active_high_intr = true; /* default polarity */ 1546 1468 1547 - ret = iio_read_mount_matrix(&client->dev, &data->orientation); 1548 - if (ret) 1549 - return ret; 1469 + if (!kxj1009_apply_acpi_orientation(&client->dev, &data->orientation)) { 1470 + ret = iio_read_mount_matrix(&client->dev, &data->orientation); 1471 + if (ret) 1472 + return ret; 1473 + } 1474 + 1550 1475 } 1551 1476 1552 1477 ret = devm_regulator_bulk_get_enable(&client->dev,