From nobody Sat May 18 23:57:57 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1617733044; cv=none; d=zohomail.com; s=zohoarc; b=Wdb1IDxVDfGZmcn4UilhF7eee8m9LgYPCET7VHpSJoLqmTGgJFGAc+jaHkQUsxNz3FugsCcp+JsivFFfIEP9eWBOGLTBLXqKRxkZ9xPQ5OiYeVMwApviwI5jVNxSZvY4icDcLWFtFw+xrPRTLXLbR6r07FvaiW1bck9d0tPEA30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617733044; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:MIME-Version:Message-ID:References:Subject:To; bh=Elryf7DTE+ajkGNPBUbUw47tX7XLWuBfXwEe8faEp7U=; b=NEQspP1mfxbnA1/m2Kypv/PwRkq1JKolZUAPRqGUTUrVcDOrCwOW0jYgkFZWBqsyauTrTkZt/HIdysLdxzQclFOjtpyzNYBY3MZ0/aS5hSU2M02Rp38PcNDUAgh1LNmhgG9V+h6YpWzT8O/3sVyAPfb/PyxQo/esim67WhNuKqg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 1617733044020860.5762563137037; Tue, 6 Apr 2021 11:17:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237477AbhDFSRb (ORCPT ); Tue, 6 Apr 2021 14:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235539AbhDFSR3 (ORCPT ); Tue, 6 Apr 2021 14:17:29 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6410C06174A; Tue, 6 Apr 2021 11:17:19 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id c6so16107646lji.8; Tue, 06 Apr 2021 11:17:19 -0700 (PDT) Received: from DESKTOP-GSFPEC9.localdomain (broadband-46-242-10-29.ip.moscow.rt.ru. [46.242.10.29]) by smtp.gmail.com with ESMTPSA id b28sm2227397lfo.219.2021.04.06.11.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 11:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Elryf7DTE+ajkGNPBUbUw47tX7XLWuBfXwEe8faEp7U=; b=Q2RasqmQ1i4xIt+hQS30C4HKpDTKePb7Bxl8A4COmI+SoXf80VnURIcvvUAelmqQEL ZPflrRd6kBaY1mQ3if2eAn/m57v2i7AKQ8vBLteLU/QJUy/qDcLTYa6twu0+PwVKuq2M 7/zIjLLTK0kXOcmL3XL8dEQVFqZziNqfLRMxgw859sDOaAhFf2PQ+RxUsjpp/3jnjPYN LDk5VU7dTWgClECgKN/APRf6/ZdFXVFwkzHtx29mSTE1gnh7Y9wMWI44weFVqNgTLYzn ukLz3nYugNYjVt8Q1RQle8VKhUOtFRseBk6bTtGz/o4jfgTjateAuYdPoX8wiiTIk/FO oUzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Elryf7DTE+ajkGNPBUbUw47tX7XLWuBfXwEe8faEp7U=; b=IuoRDTt3ZcCAazft87XteQCmycJKJqf9FfHqJsrJtq+UiBLU6KK/8KZMMbJ2weQEx0 ZRgUyrxpTbp+/SBR70eqrYw1ETdNyl38sJSuUqXDxr0zI4ppSTHUGC5hpMyrbchcScmN pKjN2z55PyCuqMGlyxrGnnHBiByiI3aLEK25ohHriWsYMH5oDYuPFRPzns1/Ez/byH/7 pW0b5wppIObV6gZE6EokRBAg4vzJAe91UssibYc4qNyEcA4SQXlTOWMP30Emy9xJbw32 uOd72j2iHld8SI3VaTB3nmwskateC0xExyROfOWC4gSO9CSHD6lLMGLox8HaSDPDPrR+ dpPA== X-Gm-Message-State: AOAM533pZ0dGYWvOuRgRDrKdNLs5acB/JezQwWN53Gbgx84Z539aLhCM aqUx9rOurt8GJHnCB5M3PgA= X-Google-Smtp-Source: ABdhPJyXd7fgvuahaKbIkVMnxmoLStMkzAqaj4ghb2qvNay7OAte+L5Mn7kEb4fvgQZ+aHtxQMMVOg== X-Received: by 2002:a2e:140b:: with SMTP id u11mr20118577ljd.125.1617733038338; Tue, 06 Apr 2021 11:17:18 -0700 (PDT) From: Konstantin Aladyshev Cc: kunyi@google.com, Konstantin Aladyshev , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] hwmon: (sbtsi) Don't read sensor more than once if it doesn't respond Date: Tue, 6 Apr 2021 21:16:24 +0300 Message-Id: <20210406181624.713-1-aladyshev22@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" SBTSI sensors don't work when the CPU is off. In this case every 'i2c_smbus_read_byte_data' function would fail by a timeout. Currently temp1_max/temp1_min file reads can cause two such timeouts for every read. Restructure code so there will be no more than one timeout for every read operation. Signed-off-by: Konstantin Aladyshev --- Changes in v2: - Fix typo in a commit message - Don't swap temp_int/temp_dec checks at the end of the 'sbtsi_read' func= tion drivers/hwmon/sbtsi_temp.c | 55 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/drivers/hwmon/sbtsi_temp.c b/drivers/hwmon/sbtsi_temp.c index e35357c48b8e..4ae48635bb31 100644 --- a/drivers/hwmon/sbtsi_temp.c +++ b/drivers/hwmon/sbtsi_temp.c @@ -74,48 +74,47 @@ static int sbtsi_read(struct device *dev, enum hwmon_se= nsor_types type, u32 attr, int channel, long *val) { struct sbtsi_data *data =3D dev_get_drvdata(dev); + u8 temp_int_reg, temp_dec_reg; s32 temp_int, temp_dec; int err; =20 switch (attr) { case hwmon_temp_input: - /* - * ReadOrder bit specifies the reading order of integer and - * decimal part of CPU temp for atomic reads. If bit =3D=3D 0, - * reading integer part triggers latching of the decimal part, - * so integer part should be read first. If bit =3D=3D 1, read - * order should be reversed. - */ - err =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_CONFIG); - if (err < 0) - return err; - - mutex_lock(&data->lock); - if (err & BIT(SBTSI_CONFIG_READ_ORDER_SHIFT)) { - temp_dec =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_TEMP_DEC); - temp_int =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_TEMP_INT); - } else { - temp_int =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_TEMP_INT); - temp_dec =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_TEMP_DEC); - } - mutex_unlock(&data->lock); + temp_int_reg =3D SBTSI_REG_TEMP_INT; + temp_dec_reg =3D SBTSI_REG_TEMP_DEC; break; case hwmon_temp_max: - mutex_lock(&data->lock); - temp_int =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_TEMP_HIGH_= INT); - temp_dec =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_TEMP_HIGH_= DEC); - mutex_unlock(&data->lock); + temp_int_reg =3D SBTSI_REG_TEMP_HIGH_INT; + temp_dec_reg =3D SBTSI_REG_TEMP_HIGH_DEC; break; case hwmon_temp_min: - mutex_lock(&data->lock); - temp_int =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_TEMP_LOW_I= NT); - temp_dec =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_TEMP_LOW_D= EC); - mutex_unlock(&data->lock); + temp_int_reg =3D SBTSI_REG_TEMP_LOW_INT; + temp_dec_reg =3D SBTSI_REG_TEMP_LOW_DEC; break; default: return -EINVAL; } =20 + /* + * ReadOrder bit specifies the reading order of integer and + * decimal part of CPU temp for atomic reads. If bit =3D=3D 0, + * reading integer part triggers latching of the decimal part, + * so integer part should be read first. If bit =3D=3D 1, read + * order should be reversed. + */ + err =3D i2c_smbus_read_byte_data(data->client, SBTSI_REG_CONFIG); + if (err < 0) + return err; + + mutex_lock(&data->lock); + if (err & BIT(SBTSI_CONFIG_READ_ORDER_SHIFT)) { + temp_dec =3D i2c_smbus_read_byte_data(data->client, temp_dec_reg); + temp_int =3D i2c_smbus_read_byte_data(data->client, temp_int_reg); + } else { + temp_int =3D i2c_smbus_read_byte_data(data->client, temp_int_reg); + temp_dec =3D i2c_smbus_read_byte_data(data->client, temp_dec_reg); + } + mutex_unlock(&data->lock); =20 if (temp_int < 0) return temp_int; --=20 2.25.1