All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>
To: jbhayana@google.com, jic23@kernel.org
Cc: lars@metafoo.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, Vasyl.Vavrychuk@opensynergy.com,
	andriy.tryshnivskyy@opensynergy.com
Subject: [PATCH v4 1/1] iio/scmi: Add reading "raw" attribute.
Date: Fri,  8 Oct 2021 16:58:42 +0300	[thread overview]
Message-ID: <20211008135842.21896-2-andriy.tryshnivskyy@opensynergy.com> (raw)
In-Reply-To: <20211008135842.21896-1-andriy.tryshnivskyy@opensynergy.com>

Add scmi_iio_get_raw() to read "raw" attribute.

Signed-off-by: Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>
---
 drivers/iio/common/scmi_sensors/scmi_iio.c | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c b/drivers/iio/common/scmi_sensors/scmi_iio.c
index 7cf2bf282cef..c3bd48ea85b8 100644
--- a/drivers/iio/common/scmi_sensors/scmi_iio.c
+++ b/drivers/iio/common/scmi_sensors/scmi_iio.c
@@ -311,6 +311,67 @@ static const struct iio_info scmi_iio_info = {
 	.write_raw = scmi_iio_write_raw,
 };
 
+static ssize_t scmi_iio_get_raw(struct iio_dev *iio_dev, uintptr_t private,
+				const struct iio_chan_spec *chan, char *buf)
+{
+	struct scmi_iio_priv *sensor = iio_priv(iio_dev);
+	int err;
+	u32 sensor_config;
+	struct scmi_sensor_reading readings[SCMI_IIO_NUM_OF_AXIS];
+	int len = 0;
+
+	err = iio_device_claim_direct_mode(iio_dev);
+	if (err) {
+		dev_err(&iio_dev->dev,
+			"Error in climing direct mode for sensor %s err %d",
+			sensor->sensor_info->name, err);
+		return len;
+	}
+
+	sensor_config = FIELD_PREP(SCMI_SENS_CFG_SENSOR_ENABLED_MASK,
+				   SCMI_SENS_CFG_SENSOR_ENABLE);
+	err = sensor->sensor_ops->config_set(
+		sensor->ph, sensor->sensor_info->id, sensor_config);
+	if (err) {
+		dev_err(&iio_dev->dev, "Error in enabling sensor %s err %d",
+			sensor->sensor_info->name, err);
+		return len;
+	}
+
+	err = sensor->sensor_ops->reading_get_timestamped(
+		sensor->ph, sensor->sensor_info->id,
+		sensor->sensor_info->num_axis, readings);
+	if (err) {
+		dev_err(&iio_dev->dev,
+			"Error in reading raw attribute for sensor %s err %d",
+			sensor->sensor_info->name, err);
+		return len;
+	}
+
+	sensor_config = FIELD_PREP(SCMI_SENS_CFG_SENSOR_ENABLED_MASK,
+				   SCMI_SENS_CFG_SENSOR_DISABLE);
+	err = sensor->sensor_ops->config_set(
+		sensor->ph, sensor->sensor_info->id, sensor_config);
+	if (err) {
+		dev_err(&iio_dev->dev, "Error in enabling sensor %s err %d",
+			sensor->sensor_info->name, err);
+		return len;
+	}
+
+	iio_device_release_direct_mode(iio_dev);
+	if (err) {
+		dev_err(&iio_dev->dev,
+			"Error in releasing direct mode for sensor %s err %d",
+			sensor->sensor_info->name, err);
+		return len;
+	}
+
+	len = scnprintf(buf, PAGE_SIZE, "%lld\n",
+			readings[chan->scan_index].value);
+
+	return len;
+}
+
 static ssize_t scmi_iio_get_raw_available(struct iio_dev *iio_dev,
 					  uintptr_t private,
 					  const struct iio_chan_spec *chan,
@@ -355,6 +416,11 @@ static ssize_t scmi_iio_get_raw_available(struct iio_dev *iio_dev,
 }
 
 static const struct iio_chan_spec_ext_info scmi_iio_ext_info[] = {
+	{
+		.name = "raw",
+		.read = scmi_iio_get_raw,
+		.shared = IIO_SEPARATE,
+	},
 	{
 		.name = "raw_available",
 		.read = scmi_iio_get_raw_available,
-- 
2.17.1


  reply	other threads:[~2021-10-08 13:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-08 13:58 [PATCH v4 0/1] iio/scmi: Add reading "raw" attribute Andriy Tryshnivskyy
2021-10-08 13:58 ` Andriy Tryshnivskyy [this message]
2021-10-08 15:01 ` Andriy Tryshnivskyy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211008135842.21896-2-andriy.tryshnivskyy@opensynergy.com \
    --to=andriy.tryshnivskyy@opensynergy.com \
    --cc=Vasyl.Vavrychuk@opensynergy.com \
    --cc=jbhayana@google.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.