Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3315327pxf; Mon, 15 Mar 2021 07:01:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt1saXfOQoj++wrU06bXAa0lcL1q9yaFTrqGKvUcUKlMSdLrAQXXPp/I5fJkQ+kkocgJ6b X-Received: by 2002:a05:6402:3047:: with SMTP id bu7mr30177938edb.227.1615816859772; Mon, 15 Mar 2021 07:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615816859; cv=none; d=google.com; s=arc-20160816; b=kp6VLgBgDcVrqBqC1xWQ7HGJUUWL6cL27JqXfW1YyQwPeHIqrzliPBBZ8XosOyocPr XqsE2KiCdogbjB48w3AhR+GY2/ksIzbfd7O5AIY/7VM+Q2FCkDX5GfLaJFZv1tFJc0V3 rFTZJ8lok4fFBGtc39J/TRBvSV80SLIZlDfK74xwjhsoiC2RVZm5yyAkYgbAToMydFia 3UFUSCJJ0Qhs+pAPpl6ZcuxRVI8eZ6aVxjMuqen8KLeFXlBv9h8uUCmQ+wkg0lpSKMZs zUmTV6x/+yq+tVFSPTM30X5fXlGvJ7e6jqJhn25soyJVVk/2G5HqYQfRHlzuf44RbPlF lLkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s80wG0QVc7s71Vmi1/R8vw1OV76QplZTV/Vk/xwyIDo=; b=DeICFZfiiRe3XCphPQAICpjmViXifYtpGiObLAWK4otaXNqS/6hbE9RyZlePQ4IbXH jjIT99/jSi2nvKjJp0MWMKXARipHLDtwYehSEd+5iMI9rA2vxc/vAI0KqzrTn2FuOg8p SGtC6l2P0LK/LzxEmv4WkkXZwZ4dbIX2i8zUPX86VdsKQujrdBzvRYfDAF9Z1rBApn1h n3uKdwcn8e9rXC2obBtLADiVa8y2lVeVffnYq5OizNFFEdwsyHsinHQwiEl08VvbANFm pNU0xfoio34Xh3zQM4hP3tZKOvD1cDZA79RUbQ4CS0Z5MtBe3/botgCvhDmmXr0WoT9c mMEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Cd6ozKQz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i25si3060087eje.58.2021.03.15.07.00.37; Mon, 15 Mar 2021 07:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Cd6ozKQz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbhCON7l (ORCPT + 99 others); Mon, 15 Mar 2021 09:59:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:59270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231611AbhCONy5 (ORCPT ); Mon, 15 Mar 2021 09:54:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6ABE364EEC; Mon, 15 Mar 2021 13:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816496; bh=UkfYB3iuj51x07Lnblew2NlIB6Xy7CbiW2rKzYvaodk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cd6ozKQzD2YkrfLy04mC3CWZXdxJKqV+l95QioD4+BaM8vkL/KIbJwmKsy6xZyWCJ 0y5G74dvn3CEu7U/a5UiSk5UE52Sw5lPcRWqEuS54uHgJCfudyH4DldQJz+0PJerjV 40PawrFLdtd0rcleyV/SvfCo+lIU43+ZwJJdBu98= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Boyang Yu , Guenter Roeck , Paul Menzel Subject: [PATCH 4.9 72/78] hwmon: (lm90) Fix max6658 sporadic wrong temperature reading Date: Mon, 15 Mar 2021 14:52:35 +0100 Message-Id: <20210315135214.421593339@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135212.060847074@linuxfoundation.org> References: <20210315135212.060847074@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Boyang Yu commit 62456189f3292c62f87aef363f204886dc1d4b48 upstream. max6658 may report unrealistically high temperature during the driver initialization, for which, its overtemp alarm pin also gets asserted. For certain devices implementing overtemp protection based on that pin, it may further trigger a reset to the device. By reproducing the problem, the wrong reading is found to be coincident with changing the conversion rate. To mitigate this issue, set the stop bit before changing the conversion rate and unset it thereafter. After such change, the wrong reading is not reproduced. Apply this change only to the max6657 kind for now, controlled by flag LM90_PAUSE_ON_CONFIG. Signed-off-by: Boyang Yu Signed-off-by: Guenter Roeck Cc: Paul Menzel Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/lm90.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -186,6 +186,7 @@ enum chips { lm90, adm1032, lm99, lm86, #define LM90_HAVE_EMERGENCY_ALARM (1 << 5)/* emergency alarm */ #define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */ #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */ +#define LM90_PAUSE_FOR_CONFIG (1 << 8) /* Pause conversion for config */ /* LM90 status */ #define LM90_STATUS_LTHRM (1 << 0) /* local THERM limit tripped */ @@ -286,6 +287,7 @@ static const struct lm90_params lm90_par .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, }, [max6657] = { + .flags = LM90_PAUSE_FOR_CONFIG, .alert_alarms = 0x7c, .max_convrate = 8, .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, @@ -486,6 +488,38 @@ static inline int lm90_select_remote_cha return 0; } +static int lm90_write_convrate(struct i2c_client *client, + struct lm90_data *data, int val) +{ + int err; + int config_orig, config_stop; + + /* Save config and pause conversion */ + if (data->flags & LM90_PAUSE_FOR_CONFIG) { + config_orig = lm90_read_reg(client, LM90_REG_R_CONFIG1); + if (config_orig < 0) + return config_orig; + config_stop = config_orig | 0x40; + if (config_orig != config_stop) { + err = i2c_smbus_write_byte_data(client, + LM90_REG_W_CONFIG1, + config_stop); + if (err < 0) + return err; + } + } + + /* Set conv rate */ + err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, val); + + /* Revert change to config */ + if (data->flags & LM90_PAUSE_FOR_CONFIG && config_orig != config_stop) + i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, + config_orig); + + return err; +} + /* * Set conversion rate. * client->update_lock must be held when calling this function (unless we are @@ -506,7 +540,7 @@ static int lm90_set_convrate(struct i2c_ if (interval >= update_interval * 3 / 4) break; - err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, i); + err = lm90_write_convrate(client, data, i); data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); return err; } @@ -1512,8 +1546,7 @@ static void lm90_restore_conf(void *_dat struct i2c_client *client = data->client; /* Restore initial configuration */ - i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, - data->convrate_orig); + lm90_write_convrate(client, data, data->convrate_orig); i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, data->config_orig); } @@ -1530,12 +1563,13 @@ static int lm90_init_client(struct i2c_c /* * Start the conversions. */ - lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ config = lm90_read_reg(client, LM90_REG_R_CONFIG1); if (config < 0) return config; data->config_orig = config; + lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ + /* Check Temperature Range Select */ if (data->kind == adt7461 || data->kind == tmp451) { if (config & 0x04)