From: Joseph Telaak <joseph@telaak.dev>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Peter Rosin" <peda@lysator.liu.se>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Joseph Telaak" <joseph@telaak.dev>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux@analog.com, devicetree@vger.kernel.org
Subject: [PATCH v2 2/6] iio: potentiometer: mcp4018: Report the available wiper positions
Date: Wed, 25 Nov 2026 15:22:29 -0500 [thread overview]
Message-ID: <20261125-iio-ad5246-v2-2-8feeb630f0b6@telaak.dev> (raw)
In-Reply-To: <20261125-iio-ad5246-v2-0-8feeb630f0b6@telaak.dev>
Implement read_avail for the raw value, as ds1803, mcp4531, tpl0102 and
x9250 already do. User space then sees out_resistance0_raw_available,
and an in-kernel consumer can learn the wiper range with
iio_read_max_channel_raw() instead of hardcoding it.
Signed-off-by: Joseph Telaak <joseph@telaak.dev>
---
drivers/iio/potentiometer/mcp4018.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/iio/potentiometer/mcp4018.c b/drivers/iio/potentiometer/mcp4018.c
index b10b4b920dc0..d6387645853d 100644
--- a/drivers/iio/potentiometer/mcp4018.c
+++ b/drivers/iio/potentiometer/mcp4018.c
@@ -12,6 +12,8 @@
* mcp4019 1 128 5, 10, 50, 100
*/
+#include <linux/array_size.h>
+#include <linux/bits.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
@@ -49,9 +51,12 @@ static const struct iio_chan_spec mcp4018_channel = {
.output = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
};
+static const int mcp4018_wiper_avail[] = { 0, 1, MCP4018_WIPER_MAX };
+
static int mcp4018_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -93,9 +98,26 @@ static int mcp4018_write_raw(struct iio_dev *indio_dev,
return i2c_smbus_write_byte(data->client, val);
}
+static int mcp4018_read_avail(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ const int **vals, int *type, int *length,
+ long mask)
+{
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ *vals = mcp4018_wiper_avail;
+ *type = IIO_VAL_INT;
+ *length = ARRAY_SIZE(mcp4018_wiper_avail);
+ return IIO_AVAIL_RANGE;
+ default:
+ return -EINVAL;
+ }
+}
+
static const struct iio_info mcp4018_info = {
.read_raw = mcp4018_read_raw,
.write_raw = mcp4018_write_raw,
+ .read_avail = mcp4018_read_avail,
};
#define MCP4018_ID_TABLE(_name, cfg) { \
--
Git-155)
next prev parent reply other threads:[~2026-11-25 20:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 20:22 [PATCH v2 0/6] iio: potentiometer: mcp4018: Add Analog Devices AD5246 Joseph Telaak
2026-11-25 20:22 ` [PATCH v2 1/6] iio: ABI: Move out_resistance_raw_available to sysfs-bus-iio Joseph Telaak
2026-11-25 23:37 ` Jonathan Cameron
2026-11-25 20:22 ` Joseph Telaak [this message]
2026-11-25 20:22 ` [PATCH v2 3/6] dt-bindings: iio: potentiometer: Add Analog Devices AD5246 Joseph Telaak
2026-11-25 20:22 ` [PATCH v2 4/6] iio: potentiometer: mcp4018: Turn on the vdd supply Joseph Telaak
2026-11-25 20:22 ` [PATCH v2 5/6] iio: potentiometer: mcp4018: Move the scale divisor into the per-part config Joseph Telaak
2026-11-25 20:22 ` [PATCH v2 6/6] iio: potentiometer: mcp4018: Add Analog Devices AD5246 Joseph Telaak
2026-11-25 23:46 ` Jonathan Cameron
2026-11-26 1:29 ` [PATCH v2 0/6] " Jonathan Cameron
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=20261125-iio-ad5246-v2-2-8feeb630f0b6@telaak.dev \
--to=joseph@telaak.dev \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@analog.com \
--cc=nuno.sa@analog.com \
--cc=peda@lysator.liu.se \
--cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®