Re: [PATCH] dt-bindings: hwmon: Add nct7802 bindings

From: Guenter Roeck
Date: Tue Sep 14 2021 - 11:09:05 EST


On Tue, Sep 14, 2021 at 08:41:36AM -0400, Oskar Senft wrote:
> Hi Guenter
>
> > https://lore.kernel.org/linux-hwmon/cover.1631021349.git.krzysztof.adamski@xxxxxxxxx/
> >
> > That specifically includes the ability to enable or disable channels
> > using the standard 'status' property. While that series is primarily
> > for the n-factor property supported by the tmp421, the same approach
> > can be used for [temperature] sensor properties on other chips as well.
>
> Good pointer! I should be able to replicate that for the LTD (@0) and
> RTDs (1, 2, 3) in a similar way.
>
> > I put [temperature] in [] because we'd need to find a means to express
> > if the sub-nodes are for temperature, voltage, or something else, but
> > I think the basic principle is sound.
> Following the example from tmp421, this could then be like this:
>

Something like that, only we'll need something to distinguish
temperature sensors from other sensor types, eg voltage or current.
Maybe a "type" property. I'd suggest "sensor-type", but we have
non-sensor attributes such as fan count and pwm values which should
be covered as well. But it looks like a good start for a set of
generic sensor properties.

> i2c {
> #address-cells = <1>;
> #size-cells = <0>;
>
> nct7802@28 {
> compatible = "nuvoton,nct7802";
> reg = <0x28>;
> #address-cells = <1>;
> #size-cells = <0>;
>
> /* LTD */
> input@0 {
> reg = <0x0>;
> status = "okay";

Not sure what the default is here ('okay' or 'disabled').
We'd also need to define what to do if there is no data
for a given sensor.

> /* No "mode" attribute here*/
> label = "local temp";
> };
>
> /* RTD1 */
> input@1 {
> reg = <0x1>;
> mode = <0x2>; /* 3904 transistor */
> label = "voltage mode";

That isn't the idea for "label", as "label" would be expected to
show up as tempX_label (and a label of "voltage mode" would be odd).
The label should indicate where the sensor is located on a board,
such as "inlet" or "outlet".

> };
>
> input@2 {
> reg = <0x2>;
> mode = <0x4>; /* thermistor */
> label = "thermistor mode";
> };
>
> /* RTD3 */
> input@3 {
> reg = <0x3>;
> mode = <0x3>; /* thermal diode */
> label = "current mode";
> status = "disabled";
> };
> };
> };
>
> I noticed that "nct7802_temp_is_visible" only allows the temperature
> sensor to be visible for current and thermistor but not voltage. Is
> that right?
>
No, that is a bug.

> Before I go and change the driver further, I'd like to make sure we
> agree on the interface.
>
> Also: Is nct7802_temp_is_visible called again after temp_type_store
> was called (I didn't try it)?
>
No. That would not be the idea. If enabling / disabling a sensor
is supposed with the _enable attribute (and/or with devicetree),
the affected sensor should always be instantiated, and reading
sensor data should return -ENODATA if the sensor is disabled.

Thanks,
Guenter