Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Slawomir Stepien <sst@poczta.fm>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com,
	krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com,
	Slawomir Stepien <slawomir.stepien@nokia.com>
Subject: Re: [PATCH 7/8] hwmon: (lm90) read the channel's label from device-tree
Date: Fri, 20 May 2022 13:01:02 +0200	[thread overview]
Message-ID: <Yod07jXUCEQIYcRj@t480s.localdomain> (raw)
In-Reply-To: <bb833b7d-d3c1-0f63-019c-439ed0ec9aad@linaro.org>

On maj 20, 2022 12:15, Krzysztof Kozlowski wrote:
> On 20/05/2022 11:32, Slawomir Stepien wrote:
> > From: Slawomir Stepien <slawomir.stepien@nokia.com>
> > 
> > Try to read the channel's label from device-tree. Having label in
> > device-tree node is not mandatory.
> > 
> > Signed-off-by: Slawomir Stepien <slawomir.stepien@nokia.com>
> > ---
> >  drivers/hwmon/lm90.c | 70 ++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 70 insertions(+)
> > 
> > diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
> > index 67d48707a8d6..e81cc21e525f 100644
> > --- a/drivers/hwmon/lm90.c
> > +++ b/drivers/hwmon/lm90.c
> > @@ -525,6 +525,7 @@ struct lm90_data {
> >  	struct i2c_client *client;
> >  	struct device *hwmon_dev;
> >  	u32 channel_config[MAX_CHANNELS + 1];
> > +	const char *channel_label[MAX_CHANNELS];
> >  	struct hwmon_channel_info temp_info;
> >  	const struct hwmon_channel_info *info[MAX_CHANNELS];
> >  	struct hwmon_chip_info chip;
> > @@ -1393,6 +1394,7 @@ static umode_t lm90_temp_is_visible(const void *data, u32 attr, int channel)
> >  	case hwmon_temp_emergency_alarm:
> >  	case hwmon_temp_emergency_hyst:
> >  	case hwmon_temp_fault:
> > +	case hwmon_temp_label:
> >  		return 0444;
> >  	case hwmon_temp_min:
> >  	case hwmon_temp_max:
> > @@ -1486,6 +1488,16 @@ static int lm90_read(struct device *dev, enum hwmon_sensor_types type,
> >  	}
> >  }
> >  
> > +static int lm90_read_string(struct device *dev, enum hwmon_sensor_types type,
> > +			    u32 attr, int channel, const char **str)
> > +{
> > +	struct lm90_data *data = dev_get_drvdata(dev);
> > +
> > +	*str = data->channel_label[channel];
> > +
> > +	return 0;
> > +}
> > +
> >  static int lm90_write(struct device *dev, enum hwmon_sensor_types type,
> >  		      u32 attr, int channel, long val)
> >  {
> > @@ -1904,10 +1916,64 @@ static void lm90_regulator_disable(void *regulator)
> >  	regulator_disable(regulator);
> >  }
> >  
> > +static int lm90_probe_channel_from_dt(struct i2c_client *client,
> > +				      struct device_node *child,
> > +				      struct lm90_data *data)
> > +{
> > +	u32 id;
> > +	int err;
> > +	struct device *dev = &client->dev;
> > +
> > +	err = of_property_read_u32(child, "reg", &id);
> > +	if (err) {
> > +		dev_err(dev, "missing reg property of %pOFn\n", child);
> > +		return err;
> > +	}
> > +
> > +	if (id >= MAX_CHANNELS) {
> > +		dev_err(dev, "invalid reg %d in %pOFn\n", id, child);
> > +		return -EINVAL;
> > +	}
> > +
> > +	err = of_property_read_string(child, "label", &data->channel_label[id]);
> > +	if (err == -ENODATA || err == -EILSEQ) {
> > +		dev_err(dev, "invalid label in %pOFn\n", child);
> 
> You did not make it a required property, so why failing?

But if you have it in device-tree, then at least inform the user that there is some problem with it.

> > +		return err;
> > +	}
> > +
> > +	if (data->channel_label[id])
> > +		data->channel_config[id] |= HWMON_T_LABEL;
> > +
> > +	return 0;
> > +}
> > +
> > +static int lm90_parse_dt_channel_info(struct i2c_client *client,
> > +				      struct lm90_data *data)
> > +{
> > +	int err;
> > +	struct device_node *child;
> > +	struct device *dev = &client->dev;
> > +	const struct device_node *np = dev->of_node;
> > +
> > +	for_each_child_of_node(np, child) {
> > +		if (strcmp(child->name, "channel"))
> > +			continue;
> > +
> > +		err = lm90_probe_channel_from_dt(client, child, data);
> > +		if (err) {
> > +			of_node_put(child);
> > +			return err;
> > +		}
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  
> 
> No need for double blank lines.

Will fix in v2.

> >  static const struct hwmon_ops lm90_ops = {
> >  	.is_visible = lm90_is_visible,
> >  	.read = lm90_read,
> > +	.read_string = lm90_read_string,
> >  	.write = lm90_write,
> >  };
> >  
> > @@ -2027,6 +2093,10 @@ static int lm90_probe(struct i2c_client *client)
> >  					return err;
> >  			}
> >  		}
> > +
> > +		err = lm90_parse_dt_channel_info(client, data);
> > +		if (err)
> > +			return err;
> >  	}
> >  
> >  	/* Initialize the LM90 chip */
> 
> 
> Best regards,
> Krzysztof

-- 
Slawomir Stepien

  reply	other threads:[~2022-05-20 11:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20  9:32 [PATCH 0/8] Add support for ADT7481 in lm90 Slawomir Stepien
2022-05-20  9:32 ` [PATCH 1/8] dt-bindings: hwmon: " Slawomir Stepien
2022-05-20 10:08   ` Krzysztof Kozlowski
2022-05-20  9:32 ` [PATCH 2/8] dt-bindings: hwmon: Add 'extended-range-enable' property support " Slawomir Stepien
2022-05-20 10:09   ` Krzysztof Kozlowski
2022-05-20 10:57     ` Slawomir Stepien
2022-05-20  9:32 ` [PATCH 3/8] dt-bindings: hwmon: Allow specifying channels for lm90 Slawomir Stepien
2022-05-20 10:13   ` Krzysztof Kozlowski
2022-05-20 12:38     ` Slawomir Stepien
2022-05-20 12:47       ` Krzysztof Kozlowski
2022-05-20 13:23         ` Slawomir Stepien
2022-05-20 13:34           ` Krzysztof Kozlowski
2022-05-20 14:02       ` Guenter Roeck
2022-05-20 13:42     ` Guenter Roeck
2022-05-20 14:09       ` Krzysztof Kozlowski
2022-05-20 14:22         ` Guenter Roeck
2022-05-24 11:53           ` Slawomir Stepien
2022-05-24 12:17             ` Slawomir Stepien
2022-05-24 17:27               ` Slawomir Stepien
2022-05-24 17:59                 ` Krzysztof Kozlowski
2022-05-25  7:07                   ` Slawomir Stepien
2022-05-20  9:32 ` [PATCH 4/8] hwmon: (lm90) add support for ADT7481 Slawomir Stepien
2022-05-20  9:32 ` [PATCH 5/8] hwmon: (lm90) define maximum number of channels that are supported Slawomir Stepien
2022-05-21  2:36   ` Guenter Roeck
2022-05-22 14:59     ` Slawomir Stepien
2022-05-20  9:32 ` [PATCH 6/8] hwmon: (lm90) enable the extended temperature range Slawomir Stepien
2022-05-20  9:32 ` [PATCH 7/8] hwmon: (lm90) read the channel's label from device-tree Slawomir Stepien
2022-05-20 10:15   ` Krzysztof Kozlowski
2022-05-20 11:01     ` Slawomir Stepien [this message]
2022-05-20 11:41       ` Krzysztof Kozlowski
2022-05-20  9:32 ` [PATCH 8/8] hwmon: (lm90) read the channel's offset " Slawomir Stepien
2022-05-20 13:45 ` [PATCH 0/8] Add support for ADT7481 in lm90 Guenter Roeck
2022-05-20 16:01   ` Guenter Roeck
2022-05-22 14:52     ` Slawomir Stepien
2022-05-22 15:00       ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yod07jXUCEQIYcRj@t480s.localdomain \
    --to=sst@poczta.fm \
    --cc=alexander.sverdlin@nokia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=krzysztof.adamski@nokia.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=przemyslaw.cencner@nokia.com \
    --cc=robh+dt@kernel.org \
    --cc=slawomir.stepien@nokia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox