Re: [PATCH v2 2/2] iio: afe: iio-rescale: Add platform IDs

From: Jonathan Cameron

Date: Fri Nov 27 2026 - 19:30:24 EST


On Sat, 28 Nov 2026 00:22:10 +0100
Fabio Forni via B4 Relay <devnull+development.redaril.me@xxxxxxxxxx> wrote:

> From: Fabio Forni <development@xxxxxxxxxx>
>
> When a rescaler is dynamically instantiated and configured with swnode,
> device_get_match_data() will always set rescale->cfg to NULL, because
> device_get_match_data() is unimplemented for software nodes.
>
> Define a platform_device_id table (a replica of the of_device_id table)
> and call the platform_get_match_data() helper, to deal with both
> swnode-based and non-swnode-based instantiation methods.
>
> Signed-off-by: Fabio Forni <development@xxxxxxxxxx>
> ---
> drivers/iio/afe/iio-rescale.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
> index c01292a15a29..c268dbaaaea6 100644
> --- a/drivers/iio/afe/iio-rescale.c
> +++ b/drivers/iio/afe/iio-rescale.c
> @@ -518,6 +518,21 @@ 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 = (kernel_ulong_t)&rescale_cfg[CURRENT_SENSE_AMPLIFIER] },
{
.name = ...
.driver_data = ...
}, {
.name = ...
Or
},
{

I don't mind on that bit, but use a few more lines to make it easier
to add additional fields in future and generally make it easier to read.


> + { .name = "current-sense-shunt",
> + .driver_data = (kernel_ulong_t)&rescale_cfg[CURRENT_SENSE_SHUNT] },
> + { .name = "voltage-divider",
> + .driver_data = (kernel_ulong_t)&rescale_cfg[VOLTAGE_DIVIDER] },
> + { .name = "temperature-sense-rtd",
> + .driver_data = (kernel_ulong_t)&rescale_cfg[TEMP_SENSE_RTD] },
> + { .name = "temperature-transducer",
> + .driver_data = (kernel_ulong_t)&rescale_cfg[TEMP_TRANSDUCER] },
> + { }
> +};
> +MODULE_DEVICE_TABLE(platform, rescale_platform_ids);
> +
> static int rescale_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> @@ -548,7 +563,7 @@ static int rescale_probe(struct platform_device *pdev)
>
> rescale = iio_priv(indio_dev);
>
> - rescale->cfg = device_get_match_data(dev);
> + rescale->cfg = platform_get_match_data(pdev);

Can we get a failure here? Forcing a driver bind to a device not in the tables
tends to end up with NULL and it is common to just fail probe if that happens.

> rescale->numerator = 1;
> rescale->denominator = 1;
> rescale->offset = 0;
> @@ -603,6 +618,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);
>
>