public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "José Miguel Gonçalves" <jose.goncalves@inov.pt>,
	"Jean Delvare" <khali@linux-fr.org>,
	"Guenter Roeck" <guenter.roeck@ericsson.com>,
	lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] hwmon: HIH-6130: Support I2C bus drivers without I2C_FUNC_SMBUS_QUICK
Date: Tue, 10 Dec 2013 17:28:04 -0800	[thread overview]
Message-ID: <52A7BFA4.2080402@roeck-us.net> (raw)
In-Reply-To: <1386723462-21388-1-git-send-email-jose.goncalves@inov.pt>

On 12/10/2013 04:57 PM, José Miguel Gonçalves wrote:
> Some I2C bus drivers do not allow zero-lenght data transfers which are

s/lenght/length/

> required to start a mesurement with the HIH6130/1 sensor. Nevertheless,

s/mesurement/measurement/

> we can overcome this limitation by writing a zero dummy byte. This byte
> is ignored by the sensor and was verified to be working with the OMAP
> I2C bus driver in a BeagleBone board.
>
> Signed-off-by: José Miguel Gonçalves <jose.goncalves@inov.pt>
> ---
>   drivers/hwmon/hih6130.c |   16 ++++++++++++++--
>   1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/hih6130.c b/drivers/hwmon/hih6130.c
> index 2dc37c7..a860cc4 100644
> --- a/drivers/hwmon/hih6130.c
> +++ b/drivers/hwmon/hih6130.c
> @@ -121,8 +121,20 @@ static int hih6130_update_measurements(struct i2c_client *client)
>   	 */
>   	if (time_after(jiffies, hih6130->last_update + HZ) || !hih6130->valid) {
>
> -		/* write to slave address, no data, to request a measurement */
> -		ret = i2c_master_send(client, tmp, 0);
> +		/*
> +		 * Write to slave address, to request a measurement.

s/,//

> +		 * According with the datasheet it should be with no data, but
> +		 * for systems with I2C bus drivers that do not allow zero
> +		 * length packets we write one dummy byte to allow sensor
> +		 * measurements on them.
> +		 */
> +		if (i2c_get_functionality(client->adapter) &
> +		    I2C_FUNC_SMBUS_QUICK) {
> +			ret = i2c_master_send(client, tmp, 0);
> +		} else {
> +			tmp[0] = 0;
> +			ret = i2c_master_send(client, tmp, 1);
> +		}

You can simplify this code by introducing a variable to hold
the write length into struct hih6130. This variable can be
initialized with 1 or 0 in the probe function.

	if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_QUICK))
		hih6130->write_length = 0;
	else
		hih6130->write_length = 1;

Then replace above code with

	tmp[0] = 0;
	ret = i2c_master_send(client, tmp, hih6130->write_length);

This way you don't have to call i2c_{get,check}_functionality() repeatedly.

Thanks,
Guenter
	
>   		if (ret < 0)
>   			goto out;
>
>


      reply	other threads:[~2013-12-11  1:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11  0:57 [PATCH] hwmon: HIH-6130: Support I2C bus drivers without I2C_FUNC_SMBUS_QUICK José Miguel Gonçalves
2013-12-11  1:28 ` Guenter Roeck [this message]

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=52A7BFA4.2080402@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=guenter.roeck@ericsson.com \
    --cc=jose.goncalves@inov.pt \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.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