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: stable@vger.kernel.org # 4.9+
Signed-off-by: Peter Rosin <peda@axentia.se>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by Peter Rosin and committed by Guenter Roeck 68615eb0 bd467e4e

Changed files
+25
Documentation
devicetree
bindings
hwmon
drivers
hwmon
+4
Documentation/devicetree/bindings/hwmon/jc42.txt
··· 34 34 35 35 - reg: I2C address 36 36 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 + 37 41 Example: 38 42 39 43 temp-sensor@1a {
+21
drivers/hwmon/jc42.c
··· 22 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 23 */ 24 24 25 + #include <linux/bitops.h> 25 26 #include <linux/module.h> 26 27 #include <linux/init.h> 27 28 #include <linux/slab.h> ··· 46 45 #define JC42_REG_TEMP 0x05 47 46 #define JC42_REG_MANID 0x06 48 47 #define JC42_REG_DEVICEID 0x07 48 + #define JC42_REG_SMBUS 0x22 /* NXP and Atmel, possibly others? */ 49 49 50 50 /* Status bits in temperature register */ 51 51 #define JC42_ALARM_CRIT_BIT 15 ··· 76 74 #define STM_MANID 0x104a /* ST Microelectronics */ 77 75 #define GT_MANID 0x1c68 /* Giantec */ 78 76 #define GT_MANID2 0x132d /* Giantec, 2nd mfg ID */ 77 + 78 + /* SMBUS register */ 79 + #define SMBUS_STMOUT BIT(7) /* SMBus time-out, active low */ 79 80 80 81 /* Supported chips */ 81 82 ··· 499 494 return cap; 500 495 501 496 data->extended = !!(cap & JC42_CAP_RANGE); 497 + 498 + if (device_property_read_bool(dev, "smbus-timeout-disable")) { 499 + int smbus; 500 + 501 + /* 502 + * Not all chips support this register, but from a 503 + * quick read of various datasheets no chip appears 504 + * incompatible with the below attempt to disable 505 + * the timeout. And the whole thing is opt-in... 506 + */ 507 + smbus = i2c_smbus_read_word_swapped(client, JC42_REG_SMBUS); 508 + if (smbus < 0) 509 + return smbus; 510 + i2c_smbus_write_word_swapped(client, JC42_REG_SMBUS, 511 + smbus | SMBUS_STMOUT); 512 + } 502 513 503 514 config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG); 504 515 if (config < 0)