Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1291344ybl; Mon, 2 Dec 2019 00:57:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxgVT6iu+Y2cE8PvGKK/xR9w9/lonB/chYFqofXUY3ESE34+dq5VtbnvYQ5w5ijQITRlXzD X-Received: by 2002:a50:ed12:: with SMTP id j18mr63220342eds.172.1575277071761; Mon, 02 Dec 2019 00:57:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575277071; cv=none; d=google.com; s=arc-20160816; b=yN4qLcq1B3UKnR8pdpyugeCellvAuWheciqNRtmdBwOPUfp5VReHGBLH7MatD7YMYJ m7bxUBojs5M0wrlkx+O87ipWXTgx4wGSLpCUqPR88JADUs2+G8NSJkBtaFZTxvYFOjoH vOzdPy4jxqlfiobEgeyEdZ7/R9GgmxqLJbRodw1+Qq4ziA38OQOwhctKINhIUK61S16W REZKrn7AU6iDMaabAHWAMCW4n0tf/kZ9LKDW1APisNoYmxiOA7EFDA4oPbKQN9I20hs3 OZ1MC4Ao67qfgLn8llrsh0HrNPC+ZcYCzQgzHJhue8QZMikH028c3LGYCP1njIriKRyM 1ZUA== 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=IRwgM+nV9bQsrkkdaqvr4+p6pSJmiIYtzl1UgLZOmoI=; b=BP3pDAGOUoFxYSFO+w2A5mcjTM08IyX72P5+/Jy0fd4/iPee4VLvt6SyHTYed7NTQi lREmcL7AQwm9PDllkuOZ6sI6vlOB9xEGOY4070XWRc7HmusOYkCc820lT2xqC27MyJtf sDPEfNVpSiCCv7vEDGm7hfRvDx7B7rsg3W9vysptuU2T56jD9URPMUr8oDgxg8A1RvNG tMLjAejZzEV7NNSbyjuvZvdbM6tHCFa2uZGSN2B1Z3XgTZDgxoxlULXDcdYzU931iLWC ZOe2HirtZpTQl3FoRZWHsGRA4dBqpXsK6W5a71yLLBtHJ11kSX7dgTAPoNrqYWyxNge5 mbNA== 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 h14si3200886ejj.4.2019.12.02.00.57.28; Mon, 02 Dec 2019 00:57:51 -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 S1727049AbfLBIz5 (ORCPT + 99 others); Mon, 2 Dec 2019 03:55:57 -0500 Received: from baptiste.telenet-ops.be ([195.130.132.51]:39280 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726350AbfLBIz5 (ORCPT ); Mon, 2 Dec 2019 03:55:57 -0500 Received: from ramsan ([84.195.182.253]) by baptiste.telenet-ops.be with bizsmtp id Ywvn2100Q5USYZQ01wvopW; Mon, 02 Dec 2019 09:55:54 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1ibhUh-0002ZA-RE; Mon, 02 Dec 2019 09:55:47 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1ibhUh-0005lK-Oo; Mon, 02 Dec 2019 09:55:47 +0100 From: Geert Uytterhoeven To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: Jacopo Mondi , Wolfram Sang , linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2] iio: adc: max9611: Fix too short conversion time delay Date: Mon, 2 Dec 2019 09:55:46 +0100 Message-Id: <20191202085546.21655-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. Maxim Technical Support confirmed this was tested with temperature Ta=25 degreeC, and promised to inform me if a maximum/minimum value is available (they didn't get back to me, so I assume it is not). 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 3000-3300 µ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 Reviewed-by: Jacopo Mondi --- 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. v2: - Add Reviewed-by, - Add feedback from Maxim Technical Support, - Increase delay from 2000-2200 µs to 3000-3300 µs to play safe. --- drivers/iio/adc/max9611.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c index da073d72f649f829..135793db4fad6b2c 100644 --- a/drivers/iio/adc/max9611.c +++ b/drivers/iio/adc/max9611.c @@ -89,6 +89,12 @@ #define MAX9611_TEMP_SCALE_NUM 1000000 #define MAX9611_TEMP_SCALE_DIV 2083 +/* + * Conversion time is 2 ms (typically) at Ta=25 degreeC + * No maximum value is known, so play it safe. + */ +#define MAX9611_CONV_TIME_US_RANGE 3000, 3300 + struct max9611_dev { struct device *dev; struct i2c_client *i2c_client; @@ -238,9 +244,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 +513,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