linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Logan Shaw <logan.shaw@alliedtelesis.co.nz>,
	jdelvare@suse.com, robh+dt@kernel.org
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, Joshua.Scott@alliedtelesis.co.nz,
	Chris.Packham@alliedtelesis.co.nz
Subject: Re: [PATCH v4 1/2] hwmon: (adt7475) Added attenuator bypass support
Date: Wed, 22 Jan 2020 07:03:55 -0800	[thread overview]
Message-ID: <09750637-1b1c-9bf0-2a52-5dfd77fb3450@roeck-us.net> (raw)
In-Reply-To: <20200120001703.9927-2-logan.shaw@alliedtelesis.co.nz>

On 1/19/20 4:17 PM, Logan Shaw wrote:
> 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>
> ---
> ---
>   drivers/hwmon/adt7475.c | 76 +++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 76 insertions(+)
> 
> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
> index 6c64d50c9aae..2bb787acb363 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 */
> @@ -1457,6 +1458,76 @@ static int adt7475_update_limits(struct i2c_client *client)
>   	return 0;
>   }
>   
> +/**

I don't see the point of adding this private comment into the documentation.

> + * Attempts to read a u32 property from the DTS, if there is no error and
> + * the properties value is zero then the bit given by parameter bit_index
> + * is cleared in the parameter config. If the value is non-zero then the bit
> + * is set.
> + *
> + * If reading the dts property returned an error code then it is returned and
> + * the config parameter is not modified.
> + */
> +static int modify_config_from_dts_prop(const struct i2c_client *client,
> +								char *dts_property, u8 *config, u8 bit_index) {

Alignment is far off. Please run "checkpatch --strict" and fix all problems
it reports.

total: 6 errors, 12 warnings, 9 checks, 94 lines checked

is a bit much.

modify_config_from_dts_prop and dts_property are unnecessary long and result
in multi-line code. Please use shorter function/parameter names.

> +	u32 is_attenuator_bypassed = 0;
> +	int ret = of_property_read_u32(client->dev.of_node, dts_property,
> +									&is_attenuator_bypassed);
> +
> +	if (! ret) {
> +			if (is_attenuator_bypassed)
> +		*config |= (1 << bit_index);
> +	else
> +		*config &= ~(1 << bit_index);
> +	}
> +
> +	return ret;

This return value is never used. Please drop it.

> +}
> +
> +/**
> + * Reads all individual voltage input bypass attenuator properties from the
> + * DTS, and if the property is present the corresponding bit is set in the
> + * register.
> +
> + * Properties are in the form of "bypass-attenuator-inx", where x is an
> + * integer from the set {0, 1, 3, 4} (can not bypass in2 attenuator).
> +.*
> + * The adt7473 and adt7475 only support bypassing in1.
> + *
> + * Returns a negative error code if there was an error writing to the register.
> + */
> +static int load_all_bypass_attenuators(const struct i2c_client *client,
> +					      int chip, u8 *config2, u8 *config4)
> +{
> +	u8 config2_copy = *config2;
> +	u8 config4_copy = *config4;
> +
Two "copy" variables are unnecessary, as only one is ever used.

> +	if (chip == adt7476 || chip == adt7490) {
> +		modify_config_from_dts_prop(client, "bypass-attenuator-in0",
> +									&config4_copy, 4);
> +		modify_config_from_dts_prop(client, "bypass-attenuator-in1",
> +									&config4_copy, 5);
> +		modify_config_from_dts_prop(client, "bypass-attenuator-in3",
> +									&config4_copy, 6);
> +		modify_config_from_dts_prop(client, "bypass-attenuator-in4",
> +									&config4_copy, 7);
> +
> +		if (i2c_smbus_write_byte_data(client, REG_CONFIG4, config4_copy) < 0)
> +			return -EREMOTEIO;
> +
> +		*config4 = config4_copy;
> +	} else if (chip == adt7473 || chip == adt7475) {
> +		modify_config_from_dts_prop(client, "bypass-attenuator-in1",
> +									&config2_copy, 5);
> +
> +		if (i2c_smbus_write_byte_data(client, REG_CONFIG2, config2_copy) < 0)
> +			return -EREMOTEIO;

Please do not override error codes.

> +
> +		*config2 = config2_copy;
> +	}
> +
> +	return 0;
> +}
> +
>   static int adt7475_probe(struct i2c_client *client,
>   			 const struct i2c_device_id *id)
>   {
> @@ -1546,6 +1617,11 @@ static int adt7475_probe(struct i2c_client *client,
>   
>   	/* Voltage attenuators can be bypassed, globally or individually */
>   	config2 = adt7475_read(REG_CONFIG2);
> +	if (load_all_bypass_attenuators(client, chip,
> +						&config2, &(data->config4)) < 0)
> +		dev_warn(&client->dev,
> +			 "Error setting bypass attenuator bits\n");
> +
>   	if (config2 & CONFIG2_ATTN) {
>   		data->bypass_attn = (0x3 << 3) | 0x3;
>   	} else {
> 


  reply	other threads:[~2020-01-22 15:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-20  0:17 [PATCH v4 0/2] hwmon: (adt7475) Added attenuator bypass support Logan Shaw
2020-01-20  0:17 ` [PATCH v4 1/2] " Logan Shaw
2020-01-22 15:03   ` Guenter Roeck [this message]
2020-01-20  0:17 ` [PATCH v4 2/2] " Logan Shaw
2020-01-21 18:00   ` Rob Herring
2020-01-22 14:47   ` 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=09750637-1b1c-9bf0-2a52-5dfd77fb3450@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=Chris.Packham@alliedtelesis.co.nz \
    --cc=Joshua.Scott@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=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 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).