Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1508821rdb; Wed, 24 Jan 2024 19:10:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTrpSUS9qaE130e5gexTNy2f1sfQH6YI7y0MPw6DbVT3ngnDt20fqXx5UBpG2BIbRVrx18 X-Received: by 2002:a05:600c:c10:b0:40e:b207:37ad with SMTP id fm16-20020a05600c0c1000b0040eb20737admr103472wmb.130.1706152204973; Wed, 24 Jan 2024 19:10:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706152204; cv=pass; d=google.com; s=arc-20160816; b=vuLzJIGv8qQb/FFqC96eeBkir31r5cUojFGmyrfnxMOq4Xi9EDiMI75xK+MR1Mz5bx qhUNc4wWkXYEVXvJ6xE8dawLC0+76AovENbuSKx7h+b8jZMKyW+iFwymbAO+wgSOU/Uv 2oUVRrJZGQHvtCBOYi1v+wVqH75D+4Km7pjzX+Qe1xoDQaJChUlAZaZik/nFTvpFTuxd oARjQ1zUuj/V2uWiSN4B9+90r7iLNaHLfCCgLV9oo534mdqhRWqVSxm9Imh5klRsVw4T 8eaiCVQLk+ghiuPn7SRSo3m1+SjB8OqU5lGLROh2FdorASx7ZigQCPK7NcuAr/v5jykp EEOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lrdklVsb4mZGbXC8IZz4TXanjV2TvusP1cNEOZvhGEo=; fh=8v2OQwT0e/4mzSJfNnrkgSijoqadEWaNMSmTuHQsnfU=; b=hDEJpX2PmA+EbtnFwV6/EdCCAsKdkVYB1bRmr7HHSCoR9q+aZYwkQys+dYGPCrtquT D5b4wzQlWlVdaokociT4DzynutCkdZq6W7h2darDTW0Crx5sQ3TSYJTFMkfvWUohXfCM W2LMo6ozvNzoLrZccnk5cdRb1B2rgE3eEKk60PbDSWlUQcOyLt+Hd+mU6jatz6aXTMiq nIwti/er6XPYwmw3Wetb+xuMAKb9dS3EYJTEvm5849mr9B6okYUWmX33zMYeqI53o8cb 3wb5PBgMCocdXds7hK0krO3Nklgz+ANzNjCC4uZlaAZdFBmPAwWk2G1ALn2heqrB9A34 jk5Q== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-37914-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37914-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s12-20020a50d48c000000b0055c3b913bc4si3947590edi.192.2024.01.24.19.10.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 19:10:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37914-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-37914-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37914-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AB0691F2542A for ; Thu, 25 Jan 2024 03:10:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 263AE5C9A; Thu, 25 Jan 2024 03:09:09 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD2D010A0A for ; Thu, 25 Jan 2024 03:09:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706152148; cv=none; b=CmIYOXGUFa2EfmAT4lzAO7pnPjVi6z25QHlHGh9PH8N8mK0mqBkZnf/CpxnznnXInSY50iDdKI5ImrbvChHpWt+TUYE/noOfzS2VYivqPIvNzoBoIChdEcUpovKOl3pr36sK+vu16oyC9bqeVSaOhh5gCxIHBcQv2MRnl2GTnwc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706152148; c=relaxed/simple; bh=+HxDaiSN4fpd2HAPliDEpKUcx7oxWusM6UlFtpvLUiA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CvfHwOfQ2tdKAhqjnmdJxkpu1zQ9f7iJNdqZAomnwCpXXW8n1TAL9jdjxEBy3E37OVsrkc0aO5ENJ83EAs4Gy7ClzK0QAh3NY0wY8nFE7f6UoTOMgrtXrYYi7ldP8K5Fdmj5m+VfdUDbV5G+Lm+KkVOBI0lx0O31PMy/pGPr0tA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 40P38dAg061552; Thu, 25 Jan 2024 11:08:39 +0800 (+08) (envelope-from Wenhua.Lin@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx06.spreadtrum.com [10.0.1.11]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4TL5F60P66z2Rq2lv; Thu, 25 Jan 2024 11:01:14 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx06.spreadtrum.com (10.0.1.11) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 25 Jan 2024 11:08:37 +0800 From: Wenhua Lin To: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: Orson Zhai , Baolin Wang , Chunyan Zhang , , , , wenhua lin , Wenhua Lin , Xiongpeng Wu , zhaochen su , Zhaochen Su , Xiaolong Wang Subject: [PATCH V2 3/6] pwm: sprd: Optimize the calculation method of duty Date: Thu, 25 Jan 2024 10:55:30 +0800 Message-ID: <20240125025533.10315-4-Wenhua.Lin@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240125025533.10315-1-Wenhua.Lin@unisoc.com> References: <20240125025533.10315-1-Wenhua.Lin@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx06.spreadtrum.com (10.0.1.11) X-MAIL:SHSQR01.spreadtrum.com 40P38dAg061552 Use DIV_ROUND_CLOSEST_ULL to avoid overflow and improve accuracy when calculating duty. Signed-off-by: Wenhua Lin --- drivers/pwm/pwm-sprd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-sprd.c b/drivers/pwm/pwm-sprd.c index cc54aa77c7e6..8de3f9e154ce 100644 --- a/drivers/pwm/pwm-sprd.c +++ b/drivers/pwm/pwm-sprd.c @@ -156,7 +156,8 @@ static int sprd_pwm_config(struct sprd_pwm_chip *spc, struct pwm_device *pwm, * given settings (MOD and input clock). */ mod = spc->mod[pwm->hwpwm]; - duty = duty_ns * mod / period_ns; + tmp = (u64)duty_ns * mod; + duty = DIV_ROUND_CLOSEST_ULL(tmp, period_ns); tmp = (u64)chn->clk_rate * period_ns; do_div(tmp, NSEC_PER_SEC); -- 2.17.1