From patchwork Sat Jan 30 04:26:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David Rivshin (Allworx)" X-Patchwork-Id: 8169491 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 64AD99F818 for ; Sat, 30 Jan 2016 04:30:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8DDE220396 for ; Sat, 30 Jan 2016 04:30:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 15EED2039C for ; Sat, 30 Jan 2016 04:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755813AbcA3Eah (ORCPT ); Fri, 29 Jan 2016 23:30:37 -0500 Received: from mail-qg0-f67.google.com ([209.85.192.67]:32782 "EHLO mail-qg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754238AbcA3Eag (ORCPT ); Fri, 29 Jan 2016 23:30:36 -0500 Received: by mail-qg0-f67.google.com with SMTP id o11so6644678qge.0; Fri, 29 Jan 2016 20:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F+N9yqBVFIdiu/uUIfBX65mkN8qWSO5bxOBEzrwfh0I=; b=yXvd/MOYIQAeuS5reDont8YRXkkIC+O3a01boOa0f2Qv+inmIFNG0cd85F70X0gOs6 eBOvCtVcw4lZrD08ogvPVwnI5M/2rcyneP0nWA02eOo+2KtJIVeC4r1nAcxD4d1g2cb9 NrPSb2sobuy+jCymVqaLMkKMj1liflbj2/+QoZU+4H23eC0gDAgSHKH0Zm/AmFvbeZRa I+MtxfDQwL1CcK0zXXwcHaZVQevfq8us/uq2+tvgHvs3b0TiLkn1WMGmgqQAqgmG5rAA L1Fs9fxgZe1GpFKTe4MU2Er15n6PRgoeOEiFuM1dwBdavlkGKo9BLkeqM7D32MSPfS8w NPPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F+N9yqBVFIdiu/uUIfBX65mkN8qWSO5bxOBEzrwfh0I=; b=Yeb+WBYCjRDLkX8o5xr+YptVB+AwxR7VI6t/Bf3lR10JYpWuQ8ofL5z289TAlUyPdx jKN5PTuK49gREHzpKM4rlxYw+k67FSgnZTkwAIqY+WhnyM/oBax8hMRmpuxKy1s+wDev gdVMg1Tt3DJDT4GIcC1i/dI1cb9ZgVn9+xmGs82n3wgfOYvMTmh5S8oM5QPorMJTNse/ RrSr+cTvZ83ce0fK6THoIAJ+PDHC10V8VYgi7d/p8285MRv3d5boVkTkuJ7pUMMSIDT/ I6/YCG2vlLKyRh+tP66GTO7Z2QhcgaKUPIGXwUKOx2hAP/RZUGguJSDCkmW5JES1WZT3 YrEg== X-Gm-Message-State: AG10YOR64LorTDhrnHNHzmIHKUtvThtdi/dN+s4feKQi1T9nU1MGShuzXLKVj19P+9Q2LQ== X-Received: by 10.140.134.74 with SMTP id 71mr15954580qhg.75.1454128235231; Fri, 29 Jan 2016 20:30:35 -0800 (PST) Received: from drivshin-linux.crosskeys.inscitek.com ([24.213.148.66]) by smtp.gmail.com with ESMTPSA id y104sm8404563qgd.33.2016.01.29.20.30.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jan 2016 20:30:34 -0800 (PST) From: "David Rivshin (Allworx)" To: linux-pwm@vger.kernel.org, Thierry Reding , Neil Armstrong Cc: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Tony Lindgren , Grant Erickson , NeilBrown , Joachim Eastwood Subject: [PATCH 3/4] pwm: omap-dmtimer: round load and match values rather than truncate Date: Fri, 29 Jan 2016 23:26:53 -0500 Message-Id: <1454128014-22866-4-git-send-email-drivshin.allworx@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454128014-22866-1-git-send-email-drivshin.allworx@gmail.com> References: <1454128014-22866-1-git-send-email-drivshin.allworx@gmail.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Rivshin When converting period and duty_cycle from nanoseconds to fclk cycles, the error introduced by the integer division can be appreciable, especially in the case of slow fclk or short period. Use DIV_ROUND_CLOSEST_ULL() so that the error is kept to +/- 0.5 clock cycles. Fixes: 6604c6556db9 ("pwm: Add PWM driver for OMAP using dual-mode timers") Signed-off-by: David Rivshin Acked-by: Neil Armstrong --- drivers/pwm/pwm-omap-dmtimer.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/pwm/pwm-omap-dmtimer.c b/drivers/pwm/pwm-omap-dmtimer.c index 103d729..8c9953c 100644 --- a/drivers/pwm/pwm-omap-dmtimer.c +++ b/drivers/pwm/pwm-omap-dmtimer.c @@ -49,11 +49,7 @@ to_pwm_omap_dmtimer_chip(struct pwm_chip *chip) static u32 pwm_omap_dmtimer_get_clock_cycles(unsigned long clk_rate, int ns) { - u64 c = (u64)clk_rate * ns; - - do_div(c, NSEC_PER_SEC); - - return c; + return DIV_ROUND_CLOSEST_ULL((u64)clk_rate * ns, NSEC_PER_SEC); } static void pwm_omap_dmtimer_start(struct pwm_omap_dmtimer_chip *omap)