Re: [PATCH] iio: afe: iio-rescale: Add platform IDs
From: Andy Shevchenko
Date: Tue Oct 13 2026 - 17:22:34 EST
On Thu, Oct 08, 2026 at 11:27:59PM +0200, Fabio Forni via B4 Relay wrote:
> When a rescaler is probed starting from a `struct swnode`,
How? Pure platform devices can't be probed from 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
Read Submitting Patches documentation on imperative mode (search for
'This patch').
> it couldn't fetch the rescaler configuration from the match table.
...
> +static const struct platform_device_id rescale_platform_ids[] = {
> + { .name = "current-sense-amplifier",
> + .driver_data = CURRENT_SENSE_AMPLIFIER, },
Drop trailing inner commas and make these one-liners (yes, long ones).
{ .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, },
> + { }
> +};
> 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;
Keep reversed xmas tree order, please.
> int sizeof_ext_info;
> int sizeof_priv;
> int i;
...
> rescale->cfg = device_get_match_data(dev);
> + if (!rescale->cfg) {
> + id = platform_get_device_id(pdev);
> + if (!id)
> + return dev_err_probe(dev,
> + -EINVAL,
ENODATA
> + "missing or invalid device configuration");
> +
> + rescale->cfg = &rescale_cfg[id->driver_data];
> + }
And it's better to make it a helper, actually we have drivers [1] that do
something similar, I would recommend you considering adding that helper
directly into platform driver core. But at least local one is a good start.
[1] for example, drivers/pinctrl/intel/pinctrl-intel.c.
--
With Best Regards,
Andy Shevchenko