Re: [PATCH v7 4/5] iio: mcp9600: Recognize chip id for mcp9601

From: Andy Shevchenko
Date: Wed Aug 20 2025 - 06:09:18 EST


On Wed, Aug 20, 2025 at 2:45 AM Ben Collins <bcollins@xxxxxxxxxx> wrote:
>
> The current driver works with mcp9601, but emits a warning because it
> does not recognize the chip id.
>
> MCP9601 is a superset of MCP9600. The drivers works without changes
> on this chipset.
>
> However, the 9601 chip supports open/closed-circuit detection if wired
> properly, so we'll need to be able to differentiate between them.
>
> Moved "struct mcp9600_data" up in the file since a later patch will
> need it and chip_info before the declerations.

declarations

...

> +struct mcp9600_data {
> + struct i2c_client *client;
> +};
> +
> #define MCP9600_CHANNELS(hj_num_ev, hj_ev_spec_off, cj_num_ev, cj_ev_spec_off) \
> { \
> { \
> @@ -123,10 +133,6 @@ static const struct iio_chan_spec mcp9600_channels[][2] = {
> MCP9600_CHANNELS(2, 0, 2, 0), /* Alerts: 1 2 3 4 */
> };
>
> -struct mcp9600_data {
> - struct i2c_client *client;
> -};
> -

It's not obvious why this piece of change is needed. AFAICS it's a stray change.

...

> static int mcp9600_probe(struct i2c_client *client)
> {
> + const struct mcp_chip_info *chip_info = i2c_get_match_data(client);

> struct iio_dev *indio_dev;
> struct mcp9600_data *data;
> - int ret, ch_sel;
> + int ch_sel, dev_id, ret;

It's hard to maintain and prone to subtle errors if we split
assignment and check, so please move assignment here.

chip_info = i2c_get_match_data(client);

> + if (!chip_info)
> + return dev_err_probe(&client->dev, -EINVAL,

In such cases we usually use ENODEV.

> + "No chip-info found for device\n");

...

> + return dev_err_probe(&client->dev, dev_id,
> + "Failed to read device ID\n");

With

struct device *dev = &client->dev;

at the top of the function this and other statements become neater and
easier to follow. In particular, I believe this one may become a one
liner after the change.

--
With Best Regards,
Andy Shevchenko