mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: afe: iio-rescale: Add platform IDs
@ 2026-10-08 21:27 Fabio Forni via B4 Relay
  2026-10-13 20:50 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Fabio Forni via B4 Relay @ 2026-10-08 21:27 UTC (permalink / raw)
  To: Peter Rosin, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko
  Cc: linux-iio, linux-kernel, Fabio Forni

From: Fabio Forni <development@redaril.me>

When a rescaler is probed starting from a `struct swnode`,
device_get_match_data() will always set rescale->cfg to NULL,
because device_get_match_data() is unimplemented for software nodes.

This commit makes the probe function fall back to platform IDs when
it couldn't fetch the rescaler configuration from the match table.

Signed-off-by: Fabio Forni <development@redaril.me>
---
 drivers/iio/afe/iio-rescale.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
index 3a6a09ffa526..fcdeeacedbe8 100644
--- a/drivers/iio/afe/iio-rescale.c
+++ b/drivers/iio/afe/iio-rescale.c
@@ -517,12 +517,28 @@ static const struct of_device_id rescale_match[] = {
 };
 MODULE_DEVICE_TABLE(of, rescale_match);
 
+static const struct platform_device_id rescale_platform_ids[] = {
+	{ .name = "current-sense-amplifier",
+	  .driver_data = CURRENT_SENSE_AMPLIFIER, },
+	{ .name = "current-sense-shunt",
+	  .driver_data = CURRENT_SENSE_SHUNT, },
+	{ .name = "voltage-divider",
+	  .driver_data = VOLTAGE_DIVIDER, },
+	{ .name = "temperature-sense-rtd",
+	  .driver_data = TEMP_SENSE_RTD, },
+	{ .name = "temperature-transducer",
+	  .driver_data = TEMP_TRANSDUCER, },
+	{ }
+};
+MODULE_DEVICE_TABLE(platform, rescale_platform_ids);
+
 static int rescale_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct iio_dev *indio_dev;
 	struct iio_channel *source;
 	struct rescale *rescale;
+	const struct platform_device_id *id;
 	int sizeof_ext_info;
 	int sizeof_priv;
 	int i;
@@ -548,6 +564,15 @@ static int rescale_probe(struct platform_device *pdev)
 	rescale = iio_priv(indio_dev);
 
 	rescale->cfg = device_get_match_data(dev);
+	if (!rescale->cfg) {
+		id = platform_get_device_id(pdev);
+		if (!id)
+			return dev_err_probe(dev,
+					     -EINVAL,
+					     "missing or invalid device configuration");
+
+		rescale->cfg = &rescale_cfg[id->driver_data];
+	}
 	rescale->numerator = 1;
 	rescale->denominator = 1;
 	rescale->offset = 0;
@@ -602,6 +627,7 @@ static struct platform_driver rescale_driver = {
 		.name = "iio-rescale",
 		.of_match_table = rescale_match,
 	},
+	.id_table = rescale_platform_ids,
 };
 module_platform_driver(rescale_driver);
 

---
base-commit: 6c377d19d4a5116d9bec5203aa3c6c11523e7898
change-id: 20261008-iio_rescale_platform_ids-0d2a7dac974a

Best regards,
-- 
Fabio Forni <development@redaril.me>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-13 20:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08 21:27 [PATCH] iio: afe: iio-rescale: Add platform IDs Fabio Forni via B4 Relay
2026-10-13 20:50 ` Andy Shevchenko

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®