public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: linux-iio@vger.kernel.org
Cc: "Marek Vasut" <marex@denx.de>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>
Subject: [PATCH 4/5] iio: light: noa1305: Report available scale values
Date: Mon, 15 Jul 2024 20:28:58 +0200	[thread overview]
Message-ID: <20240715183120.143417-4-marex@denx.de> (raw)
In-Reply-To: <20240715183120.143417-1-marex@denx.de>

Make use of the new static table of scale values and expose available
scale values via sysfs attribute of the IIO device.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
---
 drivers/iio/light/noa1305.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
index 202a5c1bbf798..e778714a942a0 100644
--- a/drivers/iio/light/noa1305.c
+++ b/drivers/iio/light/noa1305.c
@@ -102,9 +102,29 @@ static const struct iio_chan_spec noa1305_channels[] = {
 		.type = IIO_LIGHT,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+		.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE),
 	}
 };
 
+static int noa1305_read_avail(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      const int **vals, int *type,
+			      int *length, long mask)
+{
+	if (chan->type != IIO_LIGHT)
+		return -EINVAL;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		*vals = noa1305_scale_available;
+		*length = ARRAY_SIZE(noa1305_scale_available);
+		*type = IIO_VAL_FRACTIONAL;
+		return IIO_AVAIL_LIST;
+	default:
+		return -EINVAL;
+	}
+}
+
 static int noa1305_read_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int *val, int *val2, long mask)
@@ -125,6 +145,7 @@ static int noa1305_read_raw(struct iio_dev *indio_dev,
 }
 
 static const struct iio_info noa1305_info = {
+	.read_avail = noa1305_read_avail,
 	.read_raw = noa1305_read_raw,
 };
 
-- 
2.43.0


  parent reply	other threads:[~2024-07-15 18:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15 18:28 [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Marek Vasut
2024-07-15 18:28 ` [PATCH 2/5] iio: light: noa1305: Assign val in noa1305_measure() Marek Vasut
2024-07-15 18:28 ` [PATCH 3/5] iio: light: noa1305: Use static table lookup of scale values Marek Vasut
2024-07-15 18:28 ` Marek Vasut [this message]
2024-07-15 18:28 ` [PATCH 5/5] iio: light: noa1305: Make integration time configurable Marek Vasut
2024-07-20 13:29 ` [PATCH 1/5] iio: light: noa1305: Simplify noa1305_read_raw() Jonathan Cameron
2024-07-20 16:22   ` Marek Vasut

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=20240715183120.143417-4-marex@denx.de \
    --to=marex@denx.de \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox