Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1612597ybc; Wed, 13 Nov 2019 01:22:48 -0800 (PST) X-Google-Smtp-Source: APXvYqxRZrjoZ/Y8ZiRqmPG93UA+njBos+kFaF5NnqwneMH7cC1w4BlZ3/+u8DHQtjz0yltSq5vD X-Received: by 2002:aa7:d552:: with SMTP id u18mr2459087edr.86.1573636967945; Wed, 13 Nov 2019 01:22:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573636967; cv=none; d=google.com; s=arc-20160816; b=AOg4vNjzL+kX7Ujx9/G9Isb+z5Z3gPQzdCTZneQh3QMifPofuTuTeaQeRNkC91wKKl glMDRhIqPaclDEoohn0HVkI7R9tlIAhzQq9Uof0/Rne21biYU8b93Lz2cND0i22HOsLc zSVM6Mh1a9tsRNYHBg52fwDWYB3zKEQSLKmAPAoCg0F7ojoe1BWJVR7PZKxvfLKKXcGM PSSLYIXLkMiMDa0TKeUCAxE5ignH4f1MpnzN5PGvnHHeWdVjtGQ2+kNbEQk/U8ZJYe7D 3KTICSP1SiJSE2SWS+qBDOoFyJvOlB4K1JJYBgHtXMknqBtceKuWanXZibC5AajJ9zg3 Q8hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=vTBPEdrYQpNdDIg22tb3TWjilh48hXEj3Yve0e0pZoI=; b=A62mSqc5cC9o+TR6muL+rSR/k7QN2/rY8II0h/zctvm8Owh9Pzfn9Be0zEEuvm33+Y r6Q979n/jLDL1nWdOxi2wO1H7cKNLAzbeOBNhCJ/pa55gaRZG0RlNk+eWlW0sT0s7CcS e1bTXAzaKFGZLazKgaidQY6B0adCbi8kvYfZupIfzujLjvg1/cKarIMgSVUMSHVl25mN JTT1ygMjSvc1hF3Mk9yziHMrcR9hWZ7vrChoY1P8Dx/TvbPKKmcKM6IkewC/QE1pr7+k NJrpp3KtQi+BgbkPwVF6NiDWgNwrs9lwMXiFyJqi4hAIaHo7xEbFVNKDbYnEnJE1zmEJ VP2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d7si938060eda.429.2019.11.13.01.22.23; Wed, 13 Nov 2019 01:22:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727343AbfKMJVt (ORCPT + 99 others); Wed, 13 Nov 2019 04:21:49 -0500 Received: from andre.telenet-ops.be ([195.130.132.53]:51888 "EHLO andre.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727316AbfKMJVq (ORCPT ); Wed, 13 Nov 2019 04:21:46 -0500 Received: from ramsan ([84.195.182.253]) by andre.telenet-ops.be with bizsmtp id RMMk2100G5USYZQ01MMkEE; Wed, 13 Nov 2019 10:21:44 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1iUoqO-0001qZ-7m; Wed, 13 Nov 2019 10:21:44 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1iUoqO-0006Bh-5R; Wed, 13 Nov 2019 10:21:44 +0100 From: Geert Uytterhoeven To: Jacopo Mondi , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: Wolfram Sang , linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] iio: adc: max9611: Fix too short conversion time delay Date: Wed, 13 Nov 2019 10:21:33 +0100 Message-Id: <20191113092133.23723-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As of commit b9ddd5091160793e ("iio: adc: max9611: Fix temperature reading in probe"), max9611 initialization sometimes fails on the Salvator-X(S) development board with: max9611 4-007f: Invalid value received from ADC 0x8000: aborting max9611: probe of 4-007f failed with error -5 The max9611 driver tests communications with the chip by reading the die temperature during the probe function, which returns an invalid value. According to the datasheet, the typical ADC conversion time is 2 ms, but no minimum or maximum values are provided. However, the driver assumes a 1 ms conversion time. Usually the usleep_range() call returns after more than 1.8 ms, hence it succeeds. When it returns earlier, the data register may be read too early, and the previous measurement value will be returned. After boot, this is the temperature POR (power-on reset) value, causing the failure above. Fix this by increasing the delay from 1000-2000 µs to 2000-2200 µs. Note that this issue has always been present, but it was exposed by the aformentioned commit. Fixes: 69780a3bbc0b1e7e ("iio: adc: Add Maxim max9611 ADC driver") Signed-off-by: Geert Uytterhoeven --- This problem was exposed in v5.3. After this patch, probing of the two max9611 sensors succeeded during ca. 3000 boot cycles on Salvator-X(S) boards, equipped with various R-Car H3/M3-W/M3-N SoCs. --- drivers/iio/adc/max9611.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c index da073d72f649f829..b0755f25356d700d 100644 --- a/drivers/iio/adc/max9611.c +++ b/drivers/iio/adc/max9611.c @@ -89,6 +89,11 @@ #define MAX9611_TEMP_SCALE_NUM 1000000 #define MAX9611_TEMP_SCALE_DIV 2083 +/* + * Conversion time is 2 ms (typically) + */ +#define MAX9611_CONV_TIME_US_RANGE 2000, 2200 + struct max9611_dev { struct device *dev; struct i2c_client *i2c_client; @@ -238,9 +243,9 @@ static int max9611_read_single(struct max9611_dev *max9611, /* * need a delay here to make register configuration - * stabilize. 1 msec at least, from empirical testing. + * stabilize. */ - usleep_range(1000, 2000); + usleep_range(MAX9611_CONV_TIME_US_RANGE); ret = i2c_smbus_read_word_swapped(max9611->i2c_client, reg_addr); if (ret < 0) { @@ -507,7 +512,7 @@ static int max9611_init(struct max9611_dev *max9611) MAX9611_REG_CTRL2, 0); return ret; } - usleep_range(1000, 2000); + usleep_range(MAX9611_CONV_TIME_US_RANGE); return 0; } -- 2.17.1