From patchwork Mon Apr 22 10:02:18 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: 13638255 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 1C2FE13C3CE for ; Mon, 22 Apr 2024 10:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713780151; cv=none; b=sgPJoevskDisBt+8BdeFjlYvaEG7LwQL1sutnFvARCZjTsTGsxERysxD+4qA381VACYuiqZ5PcGfq+avKhLp4NGqb+I9vW1JtaHvhBgV5i9rCM1Shl38qYFSJd7olWbpxtt6DSggplsXZmwyvbi4kx1Q2E044pv9W+DoQKvHXMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713780151; c=relaxed/simple; bh=wZ3QxhBJiaOMw/VyXlSBTx2mSSnLkPa1eNl03oRZ8f0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BEY0z0+I6vpxjvbbmNHsOFrDeVD++J1CTCWw+pBLSOtqtt5aogN66hdsKAOAJpzc9OYWa+ZEU20KwLUAXvDub1vWkRX18m14HxMO6BmhUmyJe9C5RLtN1rcryFe45klAaVbQeJyhKWgdhxJ3sM7S1Ko9Y0LhGZAigdg7wi0BptM= 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=cgK+WAMm; arc=none smtp.client-ip=170.10.133.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="cgK+WAMm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713780149; 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=cgK+WAMmOYeYp7xxDW2+waC/3oHpfYESKf74+Jkz8a23+D1F1fIYzNJGVZqRO+pxNs7vl2 DtXbvReDkF709RiARNNQ4SP1ryB/Oga9oFQ178o1YOlYf+tnSQrTYVPSc9fiu8zZVQEocD dBWrscXCkp2Rr2QOg+aJD7QEdhXl3/s= 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-352-vegu3ixBNdaEY3q59NzfYQ-1; Mon, 22 Apr 2024 06:02:27 -0400 X-MC-Unique: vegu3ixBNdaEY3q59NzfYQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 34497104B507; Mon, 22 Apr 2024 10:02:27 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C49D44047; Mon, 22 Apr 2024 10:02:26 +0000 (UTC) From: Hans de Goede To: Jonathan Cameron Cc: Hans de Goede , Lars-Peter Clausen , Sean Rhodes , "Rafael J . Wysocki" , linux-iio@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [PATCH v2 4/4] iio: accel: mxc4005: Read orientation matrix from ACPI ROTM method Date: Mon, 22 Apr 2024 12:02:18 +0200 Message-ID: <20240422100218.7693-5-hdegoede@redhat.com> In-Reply-To: <20240422100218.7693-1-hdegoede@redhat.com> References: <20240422100218.7693-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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;