From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751926AbcFYCyP (ORCPT ); Fri, 24 Jun 2016 22:54:15 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:41442 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751818AbcFYCyO (ORCPT ); Fri, 24 Jun 2016 22:54:14 -0400 From: Guenter Roeck To: Mark Brown Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Guenter Roeck , Nishanth Menon Subject: [RFT PATCH] regmap-i2c: Only use I2C_FUNC_I2C if val_bits == 8 Date: Fri, 24 Jun 2016 19:53:53 -0700 Message-Id: <1466823233-31501-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.5.0 X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On chips with a register value size of 16 bits, I2C block reads will typically not return the expected values. Instead, returned values are most likely undefined if an operation crosses a register boundary. This can be observed, for example, with a TMP102 connected to an omap i2c controller. With this chip, the initial regmap read operation to fill the register cache looks as follows (debug log from modified kernel). omap_i2c 48070000.i2c: MSG[0]: add=0x0048, len: 1, flags: 0x0 omap_i2c 48070000.i2c: [0] 0x00 omap_i2c 48070000.i2c: MSG[1]: add=0x0048, len: 8, flags: 0x1 omap_i2c 48070000.i2c: [0] 0x23 omap_i2c 48070000.i2c: [1] 0xa0 omap_i2c 48070000.i2c: [2] 0xff omap_i2c 48070000.i2c: [3] 0xff omap_i2c 48070000.i2c: [4] 0xff omap_i2c 48070000.i2c: [5] 0xff omap_i2c 48070000.i2c: [6] 0xff omap_i2c 48070000.i2c: [7] 0xff Reported-by: Nishanth Menon Cc: Nishanth Menon Signed-off-by: Guenter Roeck --- Nishanth, it would be great if you can test this patch, to see if it solves the problem you had observed. Please note that https://patchwork.kernel.org/patch/9191185/ needs to be applied first (it is available in next-20160624). drivers/base/regmap/regmap-i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c index 4735318f4268..f319e6829816 100644 --- a/drivers/base/regmap/regmap-i2c.c +++ b/drivers/base/regmap/regmap-i2c.c @@ -257,7 +257,8 @@ static struct regmap_bus regmap_i2c_smbus_i2c_block = { static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, const struct regmap_config *config) { - if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) + if (config->val_bits == 8 && + i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) return ®map_i2c; else if (config->val_bits == 8 && config->reg_bits == 8 && i2c_check_functionality(i2c->adapter, -- 2.5.0