linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: linux@roeck-us.net (Guenter Roeck)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 1/2] hwmon: (jc42) optionally try to disable the SMBUS timeout
Date: Mon, 27 Nov 2017 08:48:37 -0800	[thread overview]
Message-ID: <20171127164837.GA19580@roeck-us.net> (raw)
In-Reply-To: <20171127163101.27859-2-peda@axentia.se>

On Mon, Nov 27, 2017 at 05:31:00PM +0100, Peter Rosin wrote:
> With a nxp,se97 chip on an atmel sama5d31 board, the I2C adapter driver
> is not always capable of avoiding the 25-35 ms timeout as specified by
> the SMBUS protocol. This may cause silent corruption of the last bit of
> any transfer, e.g. a one is read instead of a zero if the sensor chip
> times out. This also affects the eeprom half of the nxp-se97 chip, where
> this silent corruption was originally noticed. Other I2C adapters probably
> suffer similar issues, e.g. bit-banging comes to mind as risky...
> 
> The SMBUS register in the nxp chip is not a standard Jedec register, but
> it is not special to the nxp chips either, at least the atmel chips
> have the same mechanism. Therefore, do not special case this on the
> manufacturer, it is opt-in via the device property anyway.
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>

Looks ok to me. I'll apply after Rob's approval.

Guenter

> ---
>  Documentation/devicetree/bindings/hwmon/jc42.txt |  4 ++++
>  drivers/hwmon/jc42.c                             | 21 +++++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/hwmon/jc42.txt b/Documentation/devicetree/bindings/hwmon/jc42.txt
> index 07a250498fbb..f569db58f64a 100644
> --- a/Documentation/devicetree/bindings/hwmon/jc42.txt
> +++ b/Documentation/devicetree/bindings/hwmon/jc42.txt
> @@ -34,6 +34,10 @@ Required properties:
>  
>  - reg: I2C address
>  
> +Optional properties:
> +- smbus-timeout-disable: When set, the smbus timeout function will be disabled.
> +			 This is not supported on all chips.
> +
>  Example:
>  
>  temp-sensor at 1a {
> diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
> index 5f11dc014ed6..e5234f953a6d 100644
> --- a/drivers/hwmon/jc42.c
> +++ b/drivers/hwmon/jc42.c
> @@ -22,6 +22,7 @@
>   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
>   */
>  
> +#include <linux/bitops.h>
>  #include <linux/module.h>
>  #include <linux/init.h>
>  #include <linux/slab.h>
> @@ -45,6 +46,7 @@ static const unsigned short normal_i2c[] = {
>  #define JC42_REG_TEMP		0x05
>  #define JC42_REG_MANID		0x06
>  #define JC42_REG_DEVICEID	0x07
> +#define JC42_REG_SMBUS		0x22 /* NXP and Atmel, possibly others? */
>  
>  /* Status bits in temperature register */
>  #define JC42_ALARM_CRIT_BIT	15
> @@ -75,6 +77,9 @@ static const unsigned short normal_i2c[] = {
>  #define GT_MANID		0x1c68	/* Giantec */
>  #define GT_MANID2		0x132d	/* Giantec, 2nd mfg ID */
>  
> +/* SMBUS register */
> +#define SMBUS_STMOUT		BIT(7)  /* SMBus time-out, active low */
> +
>  /* Supported chips */
>  
>  /* Analog Devices */
> @@ -495,6 +500,22 @@ static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id)
>  
>  	data->extended = !!(cap & JC42_CAP_RANGE);
>  
> +	if (device_property_read_bool(dev, "smbus-timeout-disable")) {
> +		int smbus;
> +
> +		/*
> +		 * Not all chips support this register, but from a
> +		 * quick read of various datasheets no chip appears
> +		 * incompatible with the below attempt to disable
> +		 * the timeout. And the whole thing is opt-in...
> +		 */
> +		smbus = i2c_smbus_read_word_swapped(client, JC42_REG_SMBUS);
> +		if (smbus < 0)
> +			return smbus;
> +		i2c_smbus_write_word_swapped(client, JC42_REG_SMBUS,
> +					     smbus | SMBUS_STMOUT);
> +	}
> +
>  	config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
>  	if (config < 0)
>  		return config;
> -- 
> 2.11.0
> 

  reply	other threads:[~2017-11-27 16:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27 16:30 [PATCH v2 0/2] Sluggish AT91 I2C driver causes SMBus timeouts Peter Rosin
2017-11-27 16:31 ` [PATCH v2 1/2] hwmon: (jc42) optionally try to disable the SMBUS timeout Peter Rosin
2017-11-27 16:48   ` Guenter Roeck [this message]
2017-11-28 15:01   ` Rob Herring
2017-11-29 20:52   ` [v2,1/2] " Guenter Roeck
2017-11-27 16:31 ` [PATCH v2 2/2] ARM: dts: at91: disable the nxp, se97b SMBUS timeout on the TSE-850 Peter Rosin
2017-11-29 20:53   ` [PATCH v2 2/2] ARM: dts: at91: disable the nxp,se97b " Guenter Roeck
2017-11-29 20:56     ` Alexandre Belloni
2017-11-30 17:16       ` Guenter Roeck
2017-11-30 17:26         ` Alexandre Belloni
2017-11-30 18:46           ` Peter Rosin
2017-11-30 21:17             ` Guenter Roeck
2017-12-04 19:39               ` Alexandre Belloni

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=20171127164837.GA19580@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-arm-kernel@lists.infradead.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).