Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4578318ybp; Mon, 14 Oct 2019 06:55:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBooaEZ+jvnR8e1elu05Jo9slPoElpTsQqaHETz7gpgJBTCgXgaX3eYquObB0QjTaOh9Uz X-Received: by 2002:aa7:dc47:: with SMTP id g7mr28369923edu.153.1571061333929; Mon, 14 Oct 2019 06:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571061333; cv=none; d=google.com; s=arc-20160816; b=XMxbgJK7BbM/O2UsnyiPRyU7S08zUInVQRDawj60EatxRhyYXDvE/UEhH+y2FpSRT6 /weaqgIGYWeW2OB7q+hOSm4UaLMY+7Qo+QF2AD2YRMsNZdqfrPOzMLhBM8Gz0AkeCw/z rIu+lExYiWIxGyNat3L/oayX58E1yuLJMF5RPwvY3FtK7tVb8DJI9QAzNJ5c3Y27Weba 2RIl/spf7YrBDa5AC4KN4Ebb/8iAert+SpjbWH476CRxCuN4mh+bSnSJXOW/vBOWuXxF vcvaL+FqqdJiP8ATqeAK4R0bkdSs1ylYhpq4ALuc21EG/NfRaB0fPufpxknuSxV31klw bj6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=GZ2TtIHtv0wHL5AQgQxRXwSP7I7O/j1w+no/JiChWIs=; b=kgE1xYWhl8RfyObBbt9HlbqP9557vkUZyZX300iznTi8HZfLKlRUdQPdMYeb1JKuyC vltvc03i9nzje/JZxoQoxnlV0TyaQtjklTxtonVN9Ek+DS9itm8HakRL4INSJmkmz0f5 uTjoeP3VJB2Dx7ML2rtOB1I0ewfeT6NuYEmZyrc5SYx54lLOB5q14/d/Y8Zhxqh7UUyz vnsh8TxYV/Cl9lpYlX7gGSKoZPISqh5JQgSAXP/W+iZiWDsaEyBnMWqeg9V7M99Oncuh YK64wqvv4ZmVJBc8E7aOfGi75ZvNYdoP9uP8Jwh2PCX3WOvFhKYY0ZwGfzQYn2PD3xt0 rVFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@megous.com header.s=mail header.b=qeaJSpN7; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=megous.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si11241890ejh.169.2019.10.14.06.55.10; Mon, 14 Oct 2019 06:55:33 -0700 (PDT) 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=fail header.i=@megous.com header.s=mail header.b=qeaJSpN7; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=megous.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732359AbfJNNxP (ORCPT + 99 others); Mon, 14 Oct 2019 09:53:15 -0400 Received: from vps.xff.cz ([195.181.215.36]:39696 "EHLO vps.xff.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731092AbfJNNxO (ORCPT ); Mon, 14 Oct 2019 09:53:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megous.com; s=mail; t=1571061192; bh=46QzCIBZ/9atA9i8sP3TsXg10uJJ6p13+mX/uBQH05Y=; h=From:To:Cc:Subject:Date:From; b=qeaJSpN7BUJp2ZteQ5BjyIkVRC6U0UOhE7/gTCpY+DprLpl8kJMvhno9FN5fEXAj/ vqfuwWbW7gK6ALcnPDN5dGh0qLtwAAR92w1PbxUXFpnTl3wx9TeUVdsvoQiTHkucCk 6LgmSYX/mtr2I/n5v+Sbbo87xQkbzlHzWd6xUGPY= From: megous@megous.com Cc: Ondrej Jirman , Thierry Reding , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Chen-Yu Tsai , linux-pwm@vger.kernel.org (open list:PWM SUBSYSTEM), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Allwinner sunXi SoC support), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] pwm: sun4i: Fix incorrect calculation of duty_cycle/period Date: Mon, 14 Oct 2019 15:53:03 +0200 Message-Id: <20191014135303.2944058-1-megous@megous.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ondrej Jirman Since 5.4-rc1, pwm_apply_state calls ->get_state after ->apply if available, and this revealed an issue with integer precision when calculating duty_cycle and period for the currently set state in ->get_state callback. This issue manifested in broken backlight on several Allwinner based devices. Previously this worked, because ->apply updated the passed state directly. Fixes: deb9c462f4e53 ("pwm: sun4i: Don't update the state for the caller of pwm_apply_state") Signed-off-by: Ondrej Jirman --- drivers/pwm/pwm-sun4i.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 6f5840a1a82d..05273725a9ff 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -137,10 +137,10 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, val = sun4i_pwm_readl(sun4i_pwm, PWM_CH_PRD(pwm->hwpwm)); - tmp = prescaler * NSEC_PER_SEC * PWM_REG_DTY(val); + tmp = (u64)prescaler * NSEC_PER_SEC * PWM_REG_DTY(val); state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate); - tmp = prescaler * NSEC_PER_SEC * PWM_REG_PRD(val); + tmp = (u64)prescaler * NSEC_PER_SEC * PWM_REG_PRD(val); state->period = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate); } -- 2.23.0