All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: jdelvare@suse.com, robh+dt@kernel.org, mark.rutland@arm.com,
	logan.shaw@alliedtelesis.co.nz, linux-hwmon@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 4/5] hwmon: (adt7475) Add attenuator bypass support
Date: Tue, 3 Mar 2020 13:05:08 -0800	[thread overview]
Message-ID: <20200303210508.GD14692@roeck-us.net> (raw)
In-Reply-To: <20200227084642.7057-5-chris.packham@alliedtelesis.co.nz>

On Thu, Feb 27, 2020 at 09:46:41PM +1300, Chris Packham wrote:
> From: Logan Shaw <logan.shaw@alliedtelesis.co.nz>
> 
> Added support for reading DTS properties to set attenuators on
> device probe for the ADT7473, ADT7475, ADT7476, and ADT7490.
> 
> Signed-off-by: Logan Shaw <logan.shaw@alliedtelesis.co.nz>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

Applied, with two small changes; see inline.

Thanks,
Guenter

> ---
> 
> Notes:
>     Changes in v5:
>     - None
>     
>     Changes in v4:
>     - use vendor prefix for new property
>     
>     Changes in v3:
>     - move config2 to struct adt7475_data
>     - set_property_bit() new helper function to set/clear bit based on dt
>       property value.
>     - rename to use load_attenuators()
> 
>  drivers/hwmon/adt7475.c | 61 +++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 58 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
> index 01c2eeb02aa9..3649b18359dc 100644
> --- a/drivers/hwmon/adt7475.c
> +++ b/drivers/hwmon/adt7475.c
> @@ -19,6 +19,7 @@
>  #include <linux/hwmon-vid.h>
>  #include <linux/err.h>
>  #include <linux/jiffies.h>
> +#include <linux/of.h>
>  #include <linux/util_macros.h>
>  
>  /* Indexes for the sysfs hooks */
> @@ -193,6 +194,7 @@ struct adt7475_data {
>  	unsigned long measure_updated;
>  	bool valid;
>  
> +	u8 config2;
>  	u8 config4;
>  	u8 config5;
>  	u8 has_voltage;
> @@ -1458,6 +1460,55 @@ static int adt7475_update_limits(struct i2c_client *client)
>  	return 0;
>  }
>  
> +static int set_property_bit(const struct i2c_client *client, char *property,
> +			  u8 *config, u8 bit_index)

Aligned continuation line with '('.

> +{
> +	u32 prop_value = 0;
> +	int ret = of_property_read_u32(client->dev.of_node, property,
> +					&prop_value);
> +
> +	if (!ret) {
> +		if (prop_value)
> +			*config |= (1 << bit_index);
> +		else
> +			*config &= ~(1 << bit_index);
> +	}
> +
> +	return ret;
> +}
> +
> +static int load_attenuators(const struct i2c_client *client, int chip,
> +			    struct adt7475_data *data)
> +{
> +	int ret;
> +
> +	if (chip == adt7476 || chip == adt7490) {
> +		set_property_bit(client, "adi,bypass-attenuator-in0",
> +				 &data->config4, 4);
> +		set_property_bit(client, "adi,bypass-attenuator-in1",
> +				 &data->config4, 5);
> +		set_property_bit(client, "adi,bypass-attenuator-in3",
> +				 &data->config4, 6);
> +		set_property_bit(client, "adi,bypass-attenuator-in4",
> +				 &data->config4, 7);
> +
> +		ret = i2c_smbus_write_byte_data(client, REG_CONFIG4,
> +						data->config4);
> +		if (ret < 0)
> +			return ret;
> +	} else if (chip == adt7473 || chip == adt7475) {
> +		set_property_bit(client, "adi,bypass-attenuator-in1",
> +				 &data->config2, 5);
> +
> +		ret = i2c_smbus_write_byte_data(client, REG_CONFIG2,
> +						data->config2);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
> +	return 0;
> +}
> +
>  static int adt7475_probe(struct i2c_client *client,
>  			 const struct i2c_device_id *id)
>  {
> @@ -1472,7 +1523,7 @@ static int adt7475_probe(struct i2c_client *client,
>  	struct adt7475_data *data;
>  	struct device *hwmon_dev;
>  	int i, ret = 0, revision, group_num = 0;
> -	u8 config2, config3;
> +	u8 config3;
>  
>  	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
>  	if (data == NULL)
> @@ -1546,8 +1597,12 @@ static int adt7475_probe(struct i2c_client *client,
>  	}
>  
>  	/* Voltage attenuators can be bypassed, globally or individually */
> -	config2 = adt7475_read(REG_CONFIG2);
> -	if (config2 & CONFIG2_ATTN) {
> +	data->config2 = adt7475_read(REG_CONFIG2);
> +	ret = load_attenuators(client, chip, data);
> +	if (ret)
> +		dev_err(&client->dev, "Error configuring attenuator bypass\n");

I would expect this to be a dev_warn() or to abort and return an error.
Assuming you want the code to continue in this case, I changed the message
to dev_warn(). If that is not what you want, please let me know.

> +
> +	if (data->config2 & CONFIG2_ATTN) {
>  		data->bypass_attn = (0x3 << 3) | 0x3;
>  	} else {
>  		data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |

  reply	other threads:[~2020-03-03 21:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27  8:46 [PATCH v5 0/5] hwmon: (adt7475) attenuator bypass and pwm invert Chris Packham
2020-02-27  8:46 ` [PATCH v5 1/5] dt-bindings: hwmon: Document adt7475 binding Chris Packham
2020-03-03 21:00   ` Guenter Roeck
2020-02-27  8:46 ` [PATCH v5 2/5] dt-bindings: hwmon: Document adt7475 bypass-attenuator property Chris Packham
2020-03-03 21:00   ` Guenter Roeck
2020-02-27  8:46 ` [PATCH v5 3/5] dt-bindings: hwmon: Document adt7475 pwm-active-state property Chris Packham
2020-03-03  1:25   ` Rob Herring
2020-03-03 21:01   ` Guenter Roeck
2020-02-27  8:46 ` [PATCH v5 4/5] hwmon: (adt7475) Add attenuator bypass support Chris Packham
2020-03-03 21:05   ` Guenter Roeck [this message]
2020-02-27  8:46 ` [PATCH v5 5/5] hwmon: (adt7475) Add support for inverting pwm output Chris Packham
2020-03-03 21:08   ` 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=20200303210508.GD14692@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=logan.shaw@alliedtelesis.co.nz \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.