Skip to content

Commit 68615eb

Browse files
peda-rgroeck
authored andcommitted
hwmon: (jc42) optionally try to disable the SMBUS timeout
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. Cc: [email protected] # 4.9+ Signed-off-by: Peter Rosin <[email protected]> Acked-by: Rob Herring <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent bd467e4 commit 68615eb

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Documentation/devicetree/bindings/hwmon/jc42.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Required properties:
3434

3535
- reg: I2C address
3636

37+
Optional properties:
38+
- smbus-timeout-disable: When set, the smbus timeout function will be disabled.
39+
This is not supported on all chips.
40+
3741
Example:
3842

3943
temp-sensor@1a {

drivers/hwmon/jc42.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2323
*/
2424

25+
#include <linux/bitops.h>
2526
#include <linux/module.h>
2627
#include <linux/init.h>
2728
#include <linux/slab.h>
@@ -45,6 +46,7 @@ static const unsigned short normal_i2c[] = {
4546
#define JC42_REG_TEMP 0x05
4647
#define JC42_REG_MANID 0x06
4748
#define JC42_REG_DEVICEID 0x07
49+
#define JC42_REG_SMBUS 0x22 /* NXP and Atmel, possibly others? */
4850

4951
/* Status bits in temperature register */
5052
#define JC42_ALARM_CRIT_BIT 15
@@ -75,6 +77,9 @@ static const unsigned short normal_i2c[] = {
7577
#define GT_MANID 0x1c68 /* Giantec */
7678
#define GT_MANID2 0x132d /* Giantec, 2nd mfg ID */
7779

80+
/* SMBUS register */
81+
#define SMBUS_STMOUT BIT(7) /* SMBus time-out, active low */
82+
7883
/* Supported chips */
7984

8085
/* Analog Devices */
@@ -495,6 +500,22 @@ static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id)
495500

496501
data->extended = !!(cap & JC42_CAP_RANGE);
497502

503+
if (device_property_read_bool(dev, "smbus-timeout-disable")) {
504+
int smbus;
505+
506+
/*
507+
* Not all chips support this register, but from a
508+
* quick read of various datasheets no chip appears
509+
* incompatible with the below attempt to disable
510+
* the timeout. And the whole thing is opt-in...
511+
*/
512+
smbus = i2c_smbus_read_word_swapped(client, JC42_REG_SMBUS);
513+
if (smbus < 0)
514+
return smbus;
515+
i2c_smbus_write_word_swapped(client, JC42_REG_SMBUS,
516+
smbus | SMBUS_STMOUT);
517+
}
518+
498519
config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
499520
if (config < 0)
500521
return config;

0 commit comments

Comments
 (0)