From patchwork Wed Apr 17 16:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13633614 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5150B17106C for ; Wed, 17 Apr 2024 16:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372395; cv=none; b=LH5it28mXf+xf2EtZmEkASypcKbw1Qxd2AP3XooG/WVZzT4zesEcDtX5gGkVf0GPLJk0Nv+DSlsAlDfE0OPyD6ajYu/zzH+76f4/qTfYjUHKlt4bjZZ/1M5EAeloPKX+uzinIinCuOD2JT9cD9V7PWs2B/EteZgCYyqkCvBGVwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372395; c=relaxed/simple; bh=aAFwxEH9B04eDbJYtJ1Hy7LMAWj5FCYFYLDchXUy0dI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bfCCyiPkgEq7Gy8l7I49Jj0Ia5tJJrC8iJ4kwfvU2HkovSe9zgIpyZqFsCUYXDusVfHyFLg4Q7SwLpT0Kuid+A2lohR6twqoUFKhWAHLLHRmWAR7Au8giAcV8QOgccw8Vv85KXZOt531Vkp5tJTHTVwEsIOV6o+UdYVhXLbE5zE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Vn4Slse3; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Vn4Slse3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713372393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8QDLQob6Cd6fzwRXQb40w2r9Vkd42hTzyinA+naePrA=; b=Vn4Slse3qWOP5VBjql6e3+I7MpfBjJgo5GDb7/t6aj0hbA3AC4ih7XVC3BYJjGEUoOrY2e nMfFyVpRmMD2Ue4LLznQN/7Wlzjp2o7ZcE6v8/W87LLKkXBqh4LmgPu9yAnRENXEyR1S+S oYhmnNSFCiES+gHYvx1CP1cFZF/IDZY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-FPFbip6GP9W5WbMtVLT0NA-1; Wed, 17 Apr 2024 12:46:28 -0400 X-MC-Unique: FPFbip6GP9W5WbMtVLT0NA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A48D834FB4; Wed, 17 Apr 2024 16:46:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6FDF2166B36; Wed, 17 Apr 2024 16:46:27 +0000 (UTC) From: Hans de Goede To: Jonathan Cameron Cc: Hans de Goede , Lars-Peter Clausen , Sean Rhodes , linux-iio@vger.kernel.org Subject: [PATCH 1/4] iio: accel: kxcjk-1013: Simplify ACPI ROTM mount matrix retreival Date: Wed, 17 Apr 2024 18:46:13 +0200 Message-ID: <20240417164616.74651-2-hdegoede@redhat.com> In-Reply-To: <20240417164616.74651-1-hdegoede@redhat.com> References: <20240417164616.74651-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 There is no reason to limit the parsing 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 the: if (!adev || !acpi_has_method(adev->handle, "ROTM")) return false; check will skip checking the ROTM method silently. Move the check to see if there is an ACPI companion at all into kxj_acpi_orientation() and drop the wrapper checking the HID. Cc: Sean Rhodes Signed-off-by: Hans de Goede --- drivers/iio/accel/kxcjk-1013.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c index 126e8bdd6d0e..bb1660667bb0 100644 --- a/drivers/iio/accel/kxcjk-1013.c +++ b/drivers/iio/accel/kxcjk-1013.c @@ -637,8 +637,8 @@ static int kxcjk1013_set_power_state(struct kxcjk1013_data *data, bool on) } #ifdef CONFIG_ACPI -static bool kxj_acpi_orientation(struct device *dev, - struct iio_mount_matrix *orientation) +static bool kxj1009_apply_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); @@ -648,7 +648,7 @@ static bool kxj_acpi_orientation(struct device *dev, int i, j, val[3]; bool ret = false; - if (!acpi_has_method(adev->handle, "ROTM")) + if (!adev || !acpi_has_method(adev->handle, "ROTM")) return false; status = acpi_evaluate_object(adev->handle, "ROTM", NULL, &buffer); @@ -695,17 +695,6 @@ static bool kxj_acpi_orientation(struct device *dev, 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) From patchwork Wed Apr 17 16:46:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13633616 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E5C1171078 for ; Wed, 17 Apr 2024 16:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372396; cv=none; b=DaoOiShKIkmEzM6fObrubqYST/keJUi59ydwRQ/nWVh0oKYNATyM54qDjpOyR50aeUI7h4R7cafu8sNy4xqyzpx9/Cpxj3oLEm7+lkkJX0bha760hW1m002H9ylzRRJZt55IP/6L8vpYOfIrKNtybtbvPWFVQEFxtCrIVEIGer8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372396; c=relaxed/simple; bh=vduD0yi6Cr5fHGRN7hsRvFdJHNoHsUqHEGrgwjg/2vc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZqmvKnlX/JwFfxIEAjkjN6zrn6PXSF7RLUe+JB5fCkhKrwmQA2WW/fTaBe5N75ShtdPyCFQU7sEXOJAbNZQgF3zj0HNUIEuv/IbJtfc1WiFmbvBYQB0Da/U/c2MMSTAtEwnMu/T8wgpZiZHXx0egnJ71U+YNZihtvarY8noAZoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WkvldJ3i; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WkvldJ3i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713372393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vXiTOwWf7QtT7cGme0wZnz+KOBJfI78QTu3yOuIzb1Y=; b=WkvldJ3i6Q9tOqJ3o5VrJFxIU4JvqF5PR4MrpXOFJ4PAw7Vq+Dq4xDUSIVf89qdWzkNPA1 dCBLS/JtYfHXRoDuwSY7CJz25w1USOt50qy2x8Te7dASHZMiFAgjZWA/Q4IiflMzVReikE 4BcADDPOGkBU0O7HO0mzy7852lWtnz4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-rOT5_K0SObCP_fhjE-R8-A-1; Wed, 17 Apr 2024 12:46:29 -0400 X-MC-Unique: rOT5_K0SObCP_fhjE-R8-A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7FF423810D43; Wed, 17 Apr 2024 16:46:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB3642166B31; Wed, 17 Apr 2024 16:46:28 +0000 (UTC) From: Hans de Goede To: Jonathan Cameron Cc: Hans de Goede , Lars-Peter Clausen , Sean Rhodes , linux-iio@vger.kernel.org Subject: [PATCH 2/4] iio: accel: kxcjk-1013: Move ACPI ROTM parsing to new acpi-helpers.h Date: Wed, 17 Apr 2024 18:46:14 +0200 Message-ID: <20240417164616.74651-3-hdegoede@redhat.com> In-Reply-To: <20240417164616.74651-1-hdegoede@redhat.com> References: <20240417164616.74651-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 The ACPI "ROTM" rotation matrix parsing code atm is already duplicated between bmc150-accel-core.c and kxcjk-1013.c and a third user of this is coming. Move the ROTM parsing from kxcjk-1013.c, which has slightly better error logging (and otherwise is 100% identical), into a new acpi-helpers.h file so that it can be shared. Other then moving the code the only 2 other changes are: 1. Rename the function to acpi_read_mount_matrix() to make clear this is a generic ACPI mount matrix read function. 2. Add a "char *acpi_method" parameter since some bmc150 dual-accel setups (360° hinges with 1 accel in kbd/base + 1 in display half) declare both accels in a single ACPI device with 2 different method names for the 2 matrices. Cc: Sean Rhodes Signed-off-by: Hans de Goede --- drivers/iio/accel/acpi-helpers.h | 76 ++++++++++++++++++++++++++++++++ drivers/iio/accel/kxcjk-1013.c | 71 ++--------------------------- 2 files changed, 79 insertions(+), 68 deletions(-) create mode 100644 drivers/iio/accel/acpi-helpers.h diff --git a/drivers/iio/accel/acpi-helpers.h b/drivers/iio/accel/acpi-helpers.h new file mode 100644 index 000000000000..a4357925bf07 --- /dev/null +++ b/drivers/iio/accel/acpi-helpers.h @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* ACPI helper functions for parsing ACPI rotation matrices */ + +#include +#include +#include +#include + +#ifdef CONFIG_ACPI +static inline bool acpi_read_mount_matrix(struct device *dev, + struct iio_mount_matrix *orientation, + char *acpi_method) +{ + 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 (!adev || !acpi_has_method(adev->handle, acpi_method)) + return false; + + status = acpi_evaluate_object(adev->handle, acpi_method, 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; +} +#else +static inline bool acpi_read_mount_matrix(struct device *dev, + struct iio_mount_matrix *orientation, + char *acpi_method) +{ + return false; +} +#endif diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c index bb1660667bb0..7e19278491dc 100644 --- a/drivers/iio/accel/kxcjk-1013.c +++ b/drivers/iio/accel/kxcjk-1013.c @@ -24,6 +24,8 @@ #include #include +#include "acpi-helpers.h" + #define KXCJK1013_DRV_NAME "kxcjk1013" #define KXCJK1013_IRQ_NAME "kxcjk1013_event" @@ -636,73 +638,6 @@ static int kxcjk1013_set_power_state(struct kxcjk1013_data *data, bool on) return 0; } -#ifdef CONFIG_ACPI -static bool kxj1009_apply_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 (!adev || !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; -} -#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; @@ -1533,7 +1468,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 (!acpi_read_mount_matrix(&client->dev, &data->orientation, "ROTM")) { ret = iio_read_mount_matrix(&client->dev, &data->orientation); if (ret) return ret; From patchwork Wed Apr 17 16:46:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13633617 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE2D516FF5A for ; Wed, 17 Apr 2024 16:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372397; cv=none; b=fDX7m5QSs+P1XXKAq5iL8ewGjqtZwJJyjbeXmMoOiBs5cCLoDqJzfUanTbHEMAWmyICBFnLzkP97t4zZ7/CrJyhdyBLIrFYPJfskr7CUJtnWQWFExRr7kNdZTx9psCzKPQ/oQ6ayO0ZeoQUgFvF48qiCsnovA0fHXxNiNAx8AXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372397; c=relaxed/simple; bh=JRLv+7c6/54HDoGYrbdHXHSK8O4NnP+tTLDS2tZlvxk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KMmP+20Q0uAxTVBxtjZczeCy1J8+LWRZ3Y4CNZlXTgdVrIJ17yVtZ6P7x5HxeuX0OCjc3Wog/HUxWABvPueGUXmaZcO1msbOqmuGt8kniyb/Y6ebGVGZqKcVXbrUCJufGoWe2zgLnusIimItVlCsef+wTtQij6bqiLR0jGmctP8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eO1VePKN; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eO1VePKN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713372394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bCvduDYfaBEzJg7iPTcnkiyhAz7LjPATOqpFPP2ip+k=; b=eO1VePKNje4gxuBDrCreQTt9yzKmMCu9aD2vl1h+1JznKA+R9QM5+eown29hbfdu0QVMp+ STJii1+mJRjUUjkbc/XR7hgsw/ylcN29r093BvisCZu6Sddg+aiY4ogYxTH6/CENO5Mond fP7dwPz9HRqEQVjRVIfJjDVDFF4CeUA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-aA40ODwfO4eZHW80P8DDkw-1; Wed, 17 Apr 2024 12:46:30 -0400 X-MC-Unique: aA40ODwfO4eZHW80P8DDkw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 777C828EC121; Wed, 17 Apr 2024 16:46:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0B2F2166B32; Wed, 17 Apr 2024 16:46:29 +0000 (UTC) From: Hans de Goede To: Jonathan Cameron Cc: Hans de Goede , Lars-Peter Clausen , Sean Rhodes , linux-iio@vger.kernel.org Subject: [PATCH 3/4] iio: bmc150-accel-core: Use acpi_read_mount_matrix() helper Date: Wed, 17 Apr 2024 18:46:15 +0200 Message-ID: <20240417164616.74651-4-hdegoede@redhat.com> In-Reply-To: <20240417164616.74651-1-hdegoede@redhat.com> References: <20240417164616.74651-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Replace the duplicate ACPI "ROTM" data parsing code with the new shared acpi_read_mount_matrix() helper. Signed-off-by: Hans de Goede --- 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 #include +#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, From patchwork Wed Apr 17 16:46:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13633618 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5470F16FF5A for ; Wed, 17 Apr 2024 16:46:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372399; cv=none; b=KqvFsII2seX8ZBDHvAm0qcarYmpzhj3IMVOUqLd5H1wB5TeXq0Os+qlrU5nA8msRdeTa86IKqOEnhcU8o4Oa7fPq3AdaS/J2ScJkBsJ5w30JXZWG2kMo4bL5VT6LC3pLntaiUbqZg0/ex+/3DiFzi6eSXUrvm+hVY2t1VVIhjAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372399; c=relaxed/simple; bh=wZ3QxhBJiaOMw/VyXlSBTx2mSSnLkPa1eNl03oRZ8f0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aFUu9TnNAWZFJuhpW4vKCXabuwiOn/qTq5Ejpo5yugnRrJMBz1cNIISXMYiC8GwF70e4TlJ7HnT8nSv8S3IJSS03+zbpxQwIuUyjCfs1Y9GncW+PyxjQDlg5O7kx/5Q8C0H2/Wjrr7vPYXhtmbAdxn8HjCFsPCfRfzvpYy4fgaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZhKFfV9Q; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZhKFfV9Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713372397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/kWFFgyICdCuvnm6V12HK3Hu8XORVXgNv8ShxjjESyI=; b=ZhKFfV9QTGSyMMuqOIasC+6BuYUGI3MmnQUbChLlU04rEYEBifGiGfDflyZeifYp3eDYn+ jXoiy+D6+ok9S5eRYKl4Qiw+jrH0ylwCjCsca2Kofyn/Zlqkm6qcKppKUS/DrqZygx2Hoa qAQTAwVsWwaxIOvRtE92dSzmVzZqYFo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-39-XODW_6XMPNqUmD23ZU9WDQ-1; Wed, 17 Apr 2024 12:46:35 -0400 X-MC-Unique: XODW_6XMPNqUmD23ZU9WDQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6C65E18065AE; Wed, 17 Apr 2024 16:46:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5A022166B34; Wed, 17 Apr 2024 16:46:30 +0000 (UTC) From: Hans de Goede To: Jonathan Cameron Cc: Hans de Goede , Lars-Peter Clausen , Sean Rhodes , linux-iio@vger.kernel.org Subject: [PATCH 4/4] iio: accel: mxc4005: Read orientation matrix from ACPI ROTM method Date: Wed, 17 Apr 2024 18:46:16 +0200 Message-ID: <20240417164616.74651-5-hdegoede@redhat.com> In-Reply-To: <20240417164616.74651-1-hdegoede@redhat.com> References: <20240417164616.74651-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Some devices use the semi-standard ACPI "ROTM" method to store the accelerometers orientation matrix. Add support for this using the new acpi_read_mount_matrix() helper, if the helper fails to read the matrix fall back to iio_read_mount_matrix() which will try to get it from device-properties (devicetree) and if that fails it will fill the matrix with the identity matrix. Link: https://bugzilla.kernel.org/show_bug.cgi?id=218578 Signed-off-by: Hans de Goede --- drivers/iio/accel/mxc4005.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c index 9f38d3a08299..c54c98a4d902 100644 --- a/drivers/iio/accel/mxc4005.c +++ b/drivers/iio/accel/mxc4005.c @@ -17,6 +17,8 @@ #include #include +#include "acpi-helpers.h" + #define MXC4005_DRV_NAME "mxc4005" #define MXC4005_IRQ_NAME "mxc4005_event" #define MXC4005_REGMAP_NAME "mxc4005_regmap" @@ -65,6 +67,7 @@ struct mxc4005_data { struct mutex mutex; struct regmap *regmap; struct iio_trigger *dready_trig; + struct iio_mount_matrix orientation; /* Ensure timestamp is naturally aligned */ struct { __be16 chans[3]; @@ -272,6 +275,20 @@ static int mxc4005_write_raw(struct iio_dev *indio_dev, } } +static const struct iio_mount_matrix * +mxc4005_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct mxc4005_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + +static const struct iio_chan_spec_ext_info mxc4005_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, mxc4005_get_mount_matrix), + { } +}; + static const struct iio_info mxc4005_info = { .read_raw = mxc4005_read_raw, .write_raw = mxc4005_write_raw, @@ -298,6 +315,7 @@ static const unsigned long mxc4005_scan_masks[] = { .shift = 4, \ .endianness = IIO_BE, \ }, \ + .ext_info = mxc4005_ext_info, \ } static const struct iio_chan_spec mxc4005_channels[] = { @@ -440,6 +458,12 @@ static int mxc4005_probe(struct i2c_client *client) mutex_init(&data->mutex); + if (!acpi_read_mount_matrix(&client->dev, &data->orientation, "ROTM")) { + ret = iio_read_mount_matrix(&client->dev, &data->orientation); + if (ret) + return ret; + } + indio_dev->channels = mxc4005_channels; indio_dev->num_channels = ARRAY_SIZE(mxc4005_channels); indio_dev->available_scan_masks = mxc4005_scan_masks;