Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2706527pxv; Sun, 11 Jul 2021 23:20:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJfJSMuJoINtvgybG7hUXxBZJ9z5ZRxygVh/fOAOQ2UzmfAJSIDD7/T2ObzIsmB5+qUE84 X-Received: by 2002:a92:da86:: with SMTP id u6mr21304936iln.265.1626070803802; Sun, 11 Jul 2021 23:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626070803; cv=none; d=google.com; s=arc-20160816; b=sSo5XwARTPlD0i0F7VEfUYST/muQ0LCndL2hr1j9ofqi4rl34iVCYNyYLysOt1kWI6 sjPrh8XSNLVAHXpZQVNfPpg455/6fnsTTB8YP6Y8AfjvXWpNzg0xsEMLkJNhw3aqbeEb gi/4efZGMDhInhboDD0r9K5rxknxGfSqP7kPdeoKAlbA1M1LEK+WUsi45c0wMX16uQjY JsCMwHKARTY2nT7sfKOnlrnWeCt98Mqs7Ag2zKqcfvPxG3Al4Pj15jZCkF/Wj0fud2Jd T0FRbKMqxDKZFW2Nbu27S6GXgfDsjpRVU5cKvExegzk3VKMtphChH/uENTvwcr6DEq4X T/+Q== 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=7F5TT//GfMlFDxsBvvRVzQVB39Xt+GXwk80Z0LdApnQ=; b=D5mveCXiE2qphAD91XaHguLmo+mSByl27eguw2dbDpyMu7ivgNFwuAzpayiRqC2eO+ NJVWarmmpkMO+Hm8YJES2KYMqRPUGAGhpXOrM18uOgqyqTpxa1ungKrXPRGC+lHloFaZ iMCmofLorgDy1xUduBPLGs9gQfN2oJJq4y1puGS/ROGXcDSBf2EX6aH75G4tDchoGN+W j2fmxllOwzZ+4r177l51KGoumcWSPCSxFtF1s/u8pWQENiqrYHQ1DFMRoQA4u8usJx6Z ERRSEztUUladoVpAkaQRqDJV12qgSEEs3QVSgA1TPwwOViKKassGdzV/x0nO6BLo86k8 U21w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ep6X1wog; 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 h17si17605252jav.42.2021.07.11.23.19.51; Sun, 11 Jul 2021 23:20:03 -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=Ep6X1wog; 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 S234359AbhGLGWM (ORCPT + 99 others); Mon, 12 Jul 2021 02:22:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:38148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234346AbhGLGVF (ORCPT ); Mon, 12 Jul 2021 02:21:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ECC586113E; Mon, 12 Jul 2021 06:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070694; bh=enivGW5S8figon2mHX17bP7vwFjM+yvQSXMNBhr8mBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ep6X1wogilaaSzSUNU/PUKX7g7ikzV1yfd3++M8wxNOkkisy2u6F6Mev/KA+FvB2S XvQYU2Gs9cjGK6CfOuT8ddy1lEwL3fg4nx3pyyUNawdG8AbpeslCXWFXz9XXkq8Rxr QUhoO1pG15fmxXmJcmmZxeVmbvKcYKKExeEtG5Lo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Jan=20Kundr=C3=A1t?= , =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= , Guenter Roeck , =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= , Sasha Levin Subject: [PATCH 5.4 099/348] hwmon: (max31790) Report correct current pwm duty cycles Date: Mon, 12 Jul 2021 08:08:03 +0200 Message-Id: <20210712060714.807228783@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@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: Guenter Roeck [ Upstream commit 897f6339893b741a5d68ae8e2475df65946041c2 ] The MAX31790 has two sets of registers for pwm duty cycles, one to request a duty cycle and one to read the actual current duty cycle. Both do not have to be the same. When reporting the pwm duty cycle to the user, the actual pwm duty cycle from pwm duty cycle registers needs to be reported. When setting it, the pwm target duty cycle needs to be written. Since we don't know the actual pwm duty cycle after a target pwm duty cycle has been written, set the valid flag to false to indicate that actual pwm duty cycle should be read from the chip instead of using cached values. Cc: Jan Kundrát Cc: Václav Kubernát Signed-off-by: Guenter Roeck Tested-by: Václav Kubernát Reviewed-by: Jan Kundrát Link: https://lore.kernel.org/r/20210526154022.3223012-3-linux@roeck-us.net Signed-off-by: Sasha Levin --- Documentation/hwmon/max31790.rst | 3 ++- drivers/hwmon/max31790.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst index 84c62a12ef3a..9f12aac4fab5 100644 --- a/Documentation/hwmon/max31790.rst +++ b/Documentation/hwmon/max31790.rst @@ -39,5 +39,6 @@ fan[1-12]_input RO fan tachometer speed in RPM fan[1-12]_fault RO fan experienced fault fan[1-6]_target RW desired fan speed in RPM pwm[1-6]_enable RW regulator mode, 0=disabled, 1=manual mode, 2=rpm mode -pwm[1-6] RW fan target duty cycle (0-255) +pwm[1-6] RW read: current pwm duty cycle, + write: target pwm duty cycle (0-255) ================== === ======================================================= diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 117fb79ef294..344be7829d58 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -104,7 +104,7 @@ static struct max31790_data *max31790_update_device(struct device *dev) data->tach[NR_CHANNEL + i] = rv; } else { rv = i2c_smbus_read_word_swapped(client, - MAX31790_REG_PWMOUT(i)); + MAX31790_REG_PWM_DUTY_CYCLE(i)); if (rv < 0) goto abort; data->pwm[i] = rv; @@ -299,10 +299,10 @@ static int max31790_write_pwm(struct device *dev, u32 attr, int channel, err = -EINVAL; break; } - data->pwm[channel] = val << 8; + data->valid = false; err = i2c_smbus_write_word_swapped(client, MAX31790_REG_PWMOUT(channel), - data->pwm[channel]); + val << 8); break; case hwmon_pwm_enable: fan_config = data->fan_config[channel]; -- 2.30.2