Re: [PATCH v4 4/7] iio: adc: hx711: introduce hx711_chip_info per-variant structure
From: Andy Shevchenko
Date: Mon Apr 27 2026 - 10:14:48 EST
On Mon, Apr 27, 2026 at 03:39:35PM +0530, Piyush Patle wrote:
> Add struct hx711_chip_info to hold per-variant static configuration:
> device name, IIO channel spec array, IIO info ops pointer, and channel
> count. Store a chip_info pointer in hx711_data and populate indio_dev
> fields from it at probe time instead of hardcoding them.
>
> Use device_get_match_data() to look up the chip_info pointer from the
> of_device_id table. Guard against a NULL return so that the driver
> fails cleanly if probed via the platform name match path without
> associated match data.
>
> No functional change for existing HX711 users.
All the above is fine, but I missed the answer to the question "why?"
You need to add that this is preparatory change to add more HW support
or something alike along these words.
...
> +static const struct hx711_chip_info hx711_chip = {
> + .name = "hx711",
> + .channels = hx711_chan_spec,
> + .iio_info = &hx711_iio_info,
> + .num_channels = ARRAY_SIZE(hx711_chan_spec),
The array_size.h inclusion should go with this patch.
> +};
...
> struct device *dev = &pdev->dev;
> struct hx711_data *hx711_data;
> + const struct hx711_chip_info *chip_info;
Preserve reversed xmas tree order.
> struct iio_dev *indio_dev;
> int ret;
> int i;
...
> + chip_info = device_get_match_data(dev);
> + if (!chip_info)
> + return dev_err_probe(dev, -ENODEV, "missing match data\n");
Since we are here, it's not match data, it's driver data. "missing driver data".
> + hx711_data->chip_info = chip_info;
+ Blank line.
> /*
--
With Best Regards,
Andy Shevchenko