devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Daniel Golle <daniel@makrotopia.org>, linux-hwmon@vger.kernel.org
Cc: devicetree@vger.kernel.org, "Axel Lin" <axel.lin@ingics.com>,
	"Per Dalén" <per.dalen@appeartv.com>
Subject: Re: [PATCH] hwmon: (ltc4151) Make shunt-resistor configurable
Date: Sun, 24 Jul 2016 22:19:00 -0700	[thread overview]
Message-ID: <5795A144.2020300@roeck-us.net> (raw)
In-Reply-To: <20160724202620.GA30245@makrotopia.org>

On 07/24/2016 01:26 PM, Daniel Golle wrote:
> Allow to specify the resistance of the attached shunt via DT by
> adding the shunt-resistor property. Fall-back to the previous
> default (1 mOhm) if unset.
>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>   drivers/hwmon/ltc4151.c | 26 ++++++++++++++++++++++++--
>   1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/ltc4151.c b/drivers/hwmon/ltc4151.c
> index c86a184..f856e44 100644
> --- a/drivers/hwmon/ltc4151.c
> +++ b/drivers/hwmon/ltc4151.c
> @@ -30,6 +30,8 @@
>
>   #include <linux/kernel.h>
>   #include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>

I don't immediately see why this include file would be necessary.

>   #include <linux/init.h>
>   #include <linux/err.h>
>   #include <linux/slab.h>
> @@ -52,6 +54,7 @@ struct ltc4151_data {
>   	struct mutex update_lock;
>   	bool valid;
>   	unsigned long last_updated; /* in jiffies */
> +	unsigned int shunt; /* in micro ohms */
>
>   	/* Registers */
>   	u8 regs[6];
> @@ -111,9 +114,9 @@ static int ltc4151_get_value(struct ltc4151_data *data, u8 reg)
>   	case LTC4151_SENSE_H:
>   		/*
>   		 * 20uV resolution. Convert to current as measured with
> -		 * an 1 mOhm sense resistor, in mA.
> +		 * a given sense resistor, in mA.
>   		 */
> -		val = val * 20;
> +		val = val * 20 * 1000 / data->shunt;
>   		break;
>   	case LTC4151_VIN_H:
>   		/* 25 mV per increment */
> @@ -176,6 +179,7 @@ static int ltc4151_probe(struct i2c_client *client,
>   	struct device *dev = &client->dev;
>   	struct ltc4151_data *data;
>   	struct device *hwmon_dev;
> +	u32 shunt;
>
>   	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
>   		return -ENODEV;
> @@ -184,6 +188,14 @@ static int ltc4151_probe(struct i2c_client *client,
>   	if (!data)
>   		return -ENOMEM;
>
> +#ifdef CONFIG_OF

#ifdef is unnecessary. Worse, it results in

drivers/hwmon/ltc4151.c: In function ‘ltc4151_probe’:
drivers/hwmon/ltc4151.c:182:6: warning: unused variable ‘shunt’

if CONFIG_OF is not defined.

> +	if (!of_property_read_u32(client->dev.of_node, "shunt-resistor", &shunt)
> +		&& shunt > 0 )

checkpatch error

> +		data->shunt = shunt;

shunt == 0 is silently accepted and replaced with 1000. This is quite unusual.
Any reason ? If not, return -EINVAL might be more appropriate for shunt == 0.

> +	else
> +#endif
> +		data->shunt = 1000; /* 1 mOhm if not set */
> +
>   	data->client = client;
>   	mutex_init(&data->update_lock);
>
> @@ -199,10 +211,20 @@ static const struct i2c_device_id ltc4151_id[] = {
>   };
>   MODULE_DEVICE_TABLE(i2c, ltc4151_id);
>
> +#ifdef CONFIG_OF

#ifdef is unnecessary.

> +static const struct of_device_id ltc4151_match[] = {
> +	{ .compatible = "lltc,ltc4151" },

This as well as the property need to be documented.

> +	{},
> +};
> +#endif
> +
>   /* This is the driver that will be inserted */
>   static struct i2c_driver ltc4151_driver = {
> +	.class		= I2C_CLASS_HWMON,

This is an unrelated change, and appears to be quite pointless,
since the driver does not have a detect function.
Any reason for adding it ? If so, please explain, and submit
as separate patch.

>   	.driver = {
>   		.name	= "ltc4151",
> +		.owner  = THIS_MODULE,

Is this now necessary again ? If so, please explain, and submit
as separate patch.

> +		.of_match_table = of_match_ptr(ltc4151_match),
>   	},
>   	.probe		= ltc4151_probe,
>   	.id_table	= ltc4151_id,
>

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2016-07-25  5:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-24 20:26 [PATCH] hwmon: (ltc4151) Make shunt-resistor configurable Daniel Golle
2016-07-25  5:19 ` Guenter Roeck [this message]
     [not found]   ` <5795A144.2020300-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2016-07-25 11:56     ` [PATCH 1/2 v2] " Daniel Golle
     [not found]       ` <20160725115558.GA18360-g5gK2j5usbvCyp4qypjU+w@public.gmane.org>
2016-07-30 16:00         ` Guenter Roeck
     [not found]           ` <579CCF0E.9050506-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2016-07-30 16:11             ` Daniel Golle
     [not found]               ` <20160730161133.GA17568-g5gK2j5usbvCyp4qypjU+w@public.gmane.org>
2016-07-30 16:26                 ` Guenter Roeck
2016-07-25 11:56     ` [PATCH 2/2] hwmon: (ltc4151) Add devicetree binding for ltc4151 Daniel Golle
     [not found]       ` <20160725115616.GA31557-g5gK2j5usbvCyp4qypjU+w@public.gmane.org>
2016-07-27 14:48         ` Rob Herring
2016-08-01 10:07           ` [PATCH v2 1/2] hwmon: (ltc4151) Make shunt-resistor configurable Daniel Golle
2016-08-01 10:08           ` [PATCH 2/2] hwmon: (ltc4151) Add devicetree binding for ltc4151 Daniel Golle

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=5795A144.2020300@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=axel.lin@ingics.com \
    --cc=daniel@makrotopia.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=per.dalen@appeartv.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;
as well as URLs for NNTP newsgroup(s).