Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4150ybl; Tue, 7 Jan 2020 13:00:02 -0800 (PST) X-Google-Smtp-Source: APXvYqwsPPsGowAdlOAGRbRGLNMyseKzIRc6ewSm06YdFOwjzuKtG0bcxBSlcbuKxZvjzb6lt7zV X-Received: by 2002:a9d:6251:: with SMTP id i17mr1723228otk.14.1578430802447; Tue, 07 Jan 2020 13:00:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578430802; cv=none; d=google.com; s=arc-20160816; b=pb6/A5l25K1eEF0exRP4vCqb09UJUnMmTEUYURKZUYmzo2UtkNClxusK0I+zP126qA ijYGHuJ5ZXSklN869nEOW162T1R8NZJm7R6nwrE0FYLbD0n7exsECi6v/t9CW9q6NxEI IsenDIklqrwyYyQcApNHK5IcC/3PX656vM48Zp6fSrMYVcQ5c9d3huAQtTWzTcwVQqVF Sxu+OCW7eeorsEhcSu9DR0HvwtwAQlKuPSrD8d8C8QR6luH6qYJzxir5Qxgv7l4sihZt WreGc+i5Duka6rrllaNSYcR890xHXkd9uVcoDYDeY9oXiZUbSLWWPlJMsvpdKfHv++iR MVxg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=peJ4ghl22BMwMpTbWL6JU0cIlUslg0Zk2qSaLjdAofs=; b=D2cFlfNDylRpYcKKZBkS3uZLhl1UTpwGUJYXfcNq3M56FvafOYqKX0eay12d48bRAV EKZzecaBzxoMQMKoEnIuPuiFnasi+eBISqog8cW6Ws+sM0Ix4ps9k3k3ZYtWiWBZ+68F IWAp+1BmqolnvHJurdKvVvoELsSu2WKXYRfTyT+zDACpBXVo8UqKvDfgn2z8ZqbhNdBu QMDTXxbl+xqx2tgbTPJemC0DLLnoaabBxrCjhgDh51xLv+qYh8STRqfMZOSXOnnI3g4s Ag+maHMLPhDu4dUhAwvUzeZdsPY3Be5IILyptlsnFahpzz4waI985zZG8AUGEZKVlw5m UoXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kHaUU6Mj; 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 e5si539359oti.104.2020.01.07.12.59.50; Tue, 07 Jan 2020 13:00:02 -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; dkim=pass header.i=@kernel.org header.s=default header.b=kHaUU6Mj; 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 S1727657AbgAGU5k (ORCPT + 99 others); Tue, 7 Jan 2020 15:57:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:55116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727644AbgAGU5i (ORCPT ); Tue, 7 Jan 2020 15:57:38 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DA39B214D8; Tue, 7 Jan 2020 20:57:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578430657; bh=Fvdmao4BueJAo03lMNJQlQCFQEpi41lbiq/pv0dcGvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kHaUU6MjfTtab9H3qvEC0GGmhcHapDAcRLWgeJgJM5ecb2aPLFpvuAy62LqunwK4A hqW21+YE+IK1qcRgd6HMTFRWMTbs7FC2+7ZYZCbI2B5bbMkeiHtmJ4DzJ6JTM6eKda FdP9jYbjR3SAam1EXr0iS1bXzncYV6hiNDY6EjUw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Jacopo Mondi , Wolfram Sang , Jonathan Cameron , Sasha Levin Subject: [PATCH 5.4 015/191] iio: adc: max9611: Fix too short conversion time delay Date: Tue, 7 Jan 2020 21:52:15 +0100 Message-Id: <20200107205333.822802831@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205332.984228665@linuxfoundation.org> References: <20200107205332.984228665@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Geert Uytterhoeven [ Upstream commit 9fd229c478fbf77c41c8528aa757ef14210365f6 ] 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 Reviewed-by: Wolfram Sang Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/adc/max9611.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c index da073d72f649..e480529b3f04 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; @@ -236,11 +242,9 @@ static int max9611_read_single(struct max9611_dev *max9611, return ret; } - /* - * need a delay here to make register configuration - * stabilize. 1 msec at least, from empirical testing. - */ - usleep_range(1000, 2000); + /* need a delay here to make register configuration stabilize. */ + + usleep_range(MAX9611_CONV_TIME_US_RANGE); ret = i2c_smbus_read_word_swapped(max9611->i2c_client, reg_addr); if (ret < 0) { @@ -507,7 +511,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.20.1