[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vd=gNzqWLSQcyc3MjHY7TAGizQ5TPS+99UCrnKDgUPTig@mail.gmail.com>
Date: Wed, 13 Aug 2025 18:49:30 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Ben Collins <bcollins@...ter.com>
Cc: Jonathan Cameron <jic23@...nel.org>, David Lechner <dlechner@...libre.com>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 4/5] iio: mcp9600: Add support for dtbinding of thermocouple-type
On Wed, Aug 13, 2025 at 5:17 PM Ben Collins <bcollins@...ter.com> wrote:
>
> Adds dtbinding check for thermocouple-type and sets sensor config
Adds --> Add
Btw, I do not see dtbinding check here. There is some validation code
or so. Please, make sure your commit message is close enough to what's
going on.
> to match. Add iio info attribute to show state as well.
...
> +#define MCP9600_SENSOR_CFG 0x5
0x05
> +#define MCP9600_SENSOR_TYPE_MASK GENMASK(6, 4)
...
> +/* Map dtbinding enums to mcp9600 sensor type */
I am not sure how this comment is useful, but since it does some
magic, this magic should be explained: why do you need to map these?
> +static const unsigned int mcp9600_type_map[] = {
> + [THERMOCOUPLE_TYPE_K] = 0,
> + [THERMOCOUPLE_TYPE_J] = 1,
> + [THERMOCOUPLE_TYPE_T] = 2,
> + [THERMOCOUPLE_TYPE_N] = 3,
> + [THERMOCOUPLE_TYPE_S] = 4,
> + [THERMOCOUPLE_TYPE_E] = 5,
> + [THERMOCOUPLE_TYPE_B] = 6,
> + [THERMOCOUPLE_TYPE_R] = 7,
> +};
Are they not 1:1?
...
> +/* Map mcp9600 sensor type to char */
> +static const int mcp9600_tc_types[] = {
> + 'B', 'E', 'J', 'K', 'N', 'R', 'S', 'T'
Please, leave the trailing comma, also why is this not indexed as the above?
> +};
...
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> - BIT(IIO_CHAN_INFO_SCALE), \
> + BIT(IIO_CHAN_INFO_SCALE) | \
> + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE), \
Make it only one line +, and *not* remove one / add two.
...
> static int mcp9600_read_raw(struct iio_dev *indio_dev,
> *val = 62;
> *val2 = 500000;
> return IIO_VAL_INT_PLUS_MICRO;
> + case IIO_CHAN_INFO_THERMOCOUPLE_TYPE:
> + *val = mcp9600_tc_types[data->thermocouple_type];
> + return IIO_VAL_CHAR;
> +
Stray blank line (I don't see the above is using it) or the above is
wrong and you need one more blank line. Not enough context to me w/o
looking into the driver code.
> default:
> return -EINVAL;
> }
> }
...
> +static int mcp9600_config(struct mcp9600_data *data)
> +{
> + struct i2c_client *client = data->client;
> + int ret, cfg;
Why is cfg signed?
> + cfg = FIELD_PREP(MCP9600_SENSOR_TYPE_MASK,
> + mcp9600_type_map[data->thermocouple_type]);
> +
> + ret = i2c_smbus_write_byte_data(client, MCP9600_SENSOR_CFG, cfg);
> + if (ret < 0) {
> + dev_err(&client->dev, "Failed to set sensor configuration\n");
> + return ret;
> + }
> +
> + return 0;
> +}
...
> + /* Accept type from dt with default of Type-K. */
> + data->thermocouple_type = THERMOCOUPLE_TYPE_K;
> + ret = device_property_read_u32(&client->dev, "thermocouple-type",
> + &data->thermocouple_type);
> + if (data->thermocouple_type >= ARRAY_SIZE(mcp9600_type_map))
> + return dev_err_probe(&client->dev, -EINVAL,
> + "Invalid thermocouple-type property %d.\n",
Please, make sure that all printf() specifiers are aligned with the
types of the respective parameters.
> + data->thermocouple_type);
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists