[PATCH v2 5/6] iio: potentiometer: mcp4018: Move the scale divisor into the per-part config

From: Joseph Telaak

Date: Wed Nov 25 2026 - 15:23:04 EST


The step is kohms / 127 for every MCP401x part. Keep the divisor in
struct mcp4018_cfg, so that parts with another step size can be added.
No functional change.

Signed-off-by: Joseph Telaak <joseph@xxxxxxxxxx>
---
drivers/iio/potentiometer/mcp4018.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/potentiometer/mcp4018.c b/drivers/iio/potentiometer/mcp4018.c
index 6ca6cd7cbf71..75a63a01acef 100644
--- a/drivers/iio/potentiometer/mcp4018.c
+++ b/drivers/iio/potentiometer/mcp4018.c
@@ -26,6 +26,8 @@

struct mcp4018_cfg {
int kohms;
+ /* Wiper position divisor: R = raw * kohms / div */
+ unsigned int div;
};

enum mcp4018_type {
@@ -36,10 +38,10 @@ enum mcp4018_type {
};

static const struct mcp4018_cfg mcp4018_cfg[] = {
- [MCP4018_502] = { .kohms = 5, },
- [MCP4018_103] = { .kohms = 10, },
- [MCP4018_503] = { .kohms = 50, },
- [MCP4018_104] = { .kohms = 100, },
+ [MCP4018_502] = { .kohms = 5, .div = MCP4018_WIPER_MAX, },
+ [MCP4018_103] = { .kohms = 10, .div = MCP4018_WIPER_MAX, },
+ [MCP4018_503] = { .kohms = 50, .div = MCP4018_WIPER_MAX, },
+ [MCP4018_104] = { .kohms = 100, .div = MCP4018_WIPER_MAX, },
};

struct mcp4018_data {
@@ -75,7 +77,7 @@ static int mcp4018_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = 1000 * data->cfg->kohms;
- *val2 = MCP4018_WIPER_MAX;
+ *val2 = data->cfg->div;
return IIO_VAL_FRACTIONAL;
}


--
Git-155)