Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Slawomir Stepien <sst@poczta.fm>
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	jdelvare@suse.com, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com,
	krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com,
	slawomir.stepien@nokia.com
Subject: Re: [PATCH 6/7] hwmon: (lm90) Read the channel's label from device-tree
Date: Sun, 5 Jun 2022 11:06:52 -0700	[thread overview]
Message-ID: <20220605180652.GA3151812@roeck-us.net> (raw)
In-Reply-To: <20220525073657.573327-7-sst@poczta.fm>

On Wed, May 25, 2022 at 09:36:56AM +0200, 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>

Applied to hwmon-next.

Thanks,
Guenter

> ---
>  drivers/hwmon/lm90.c | 72 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 72 insertions(+)
> 
> diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
> index 82b020ffd490..3837c4ab5833 100644
> --- a/drivers/hwmon/lm90.c
> +++ b/drivers/hwmon/lm90.c
> @@ -688,6 +688,7 @@ struct lm90_data {
>  	struct device *hwmon_dev;
>  	u32 chip_config[2];
>  	u32 channel_config[MAX_CHANNELS + 1];
> +	const char *channel_label[MAX_CHANNELS];
>  	struct hwmon_channel_info chip_info;
>  	struct hwmon_channel_info temp_info;
>  	const struct hwmon_channel_info *info[3];
> @@ -1610,6 +1611,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:
> @@ -1729,6 +1731,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)
>  {
> @@ -2634,10 +2646,63 @@ 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 property value %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 property in %pOFn\n", child);
> +		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;
> +}
>  
>  static const struct hwmon_ops lm90_ops = {
>  	.is_visible = lm90_is_visible,
>  	.read = lm90_read,
> +	.read_string = lm90_read_string,
>  	.write = lm90_write,
>  };
>  
> @@ -2775,6 +2840,13 @@ static int lm90_probe(struct i2c_client *client)
>  	/* Set maximum conversion rate */
>  	data->max_convrate = lm90_params[data->kind].max_convrate;
>  
> +	/* Parse device-tree channel information */
> +	if (client->dev.of_node) {
> +		err = lm90_parse_dt_channel_info(client, data);
> +		if (err)
> +			return err;
> +	}
> +
>  	/* Initialize the LM90 chip */
>  	err = lm90_init_client(client, data);
>  	if (err < 0) {

  reply	other threads:[~2022-06-05 18:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25  7:36 Extend the device-tree binding for lm90 Slawomir Stepien
2022-05-25  7:36 ` [PATCH 1/7] dt-bindings: hwmon: Add compatible string for ADT7481 in lm90 Slawomir Stepien
2022-05-26  1:54   ` Rob Herring
2022-06-05 17:52   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 2/7] dt-bindings: hwmon: Allow specifying channels for lm90 Slawomir Stepien
2022-05-26  1:55   ` Rob Herring
2022-06-05 17:53   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 3/7] hwmon: (lm90) Add compatible entry for adt7481 Slawomir Stepien
2022-06-05 17:54   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 4/7] hwmon: (lm90) Add support for 2nd remote channel's offset register Slawomir Stepien
2022-06-05 18:03   ` Guenter Roeck
2022-06-06  6:30     ` Slawomir Stepien
2022-06-06  6:50       ` Guenter Roeck
2022-06-06  6:56         ` Slawomir Stepien
2022-06-06 12:14         ` Slawomir Stepien
2022-06-06 14:15           ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 5/7] hwmon: (lm90) Define maximum number of channels that are supported Slawomir Stepien
2022-06-05 18:05   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 6/7] hwmon: (lm90) Read the channel's label from device-tree Slawomir Stepien
2022-06-05 18:06   ` Guenter Roeck [this message]
2022-05-25  7:36 ` [PATCH 7/7] hwmon: (lm90) Read the channel's temperature offset " Slawomir Stepien
2022-06-05 18:10   ` Guenter Roeck
2022-06-06  6:32     ` Slawomir Stepien

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=20220605180652.GA3151812@roeck-us.net \
    --to=linux@roeck-us.net \
    --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=linux-hwmon@vger.kernel.org \
    --cc=przemyslaw.cencner@nokia.com \
    --cc=robh+dt@kernel.org \
    --cc=slawomir.stepien@nokia.com \
    --cc=sst@poczta.fm \
    /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