From patchwork Mon Jan 8 13:28:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10149631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46348602CA for ; Mon, 8 Jan 2018 13:38:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2998C2839C for ; Mon, 8 Jan 2018 13:38:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DC2728573; Mon, 8 Jan 2018 13:38:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 91D262839C for ; Mon, 8 Jan 2018 13:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=oMJ7e64xjg2D9kuy/BMulw2iM35IzZzC5KaLE82TyLw=; b=CxqGNxH2SoE8zARgJb1111aMRQ CAwJpWd6k6jSZ/pnSXAgjCrpgsEzoT07WXlNl1DiIXCa/JcB2QaYXidTcBHHChRj+XLugI3dsIJ8N 4J8OsHSQEGA33rHjkWWPBHmstKPe4TX7isjtq8cLr+D8SxNJLjB1T50dgKKF16Nb0pO/vNV47Bi6+ fdc3wcIMTFPoWeXh0lTuaketX19Bd4idyKfu6hLxg7bBct/Rer1Waw87EvnOhUHZEPUcel0U9ug8W iciEOx693L2wYC46cjFGbJS1XLUn0QEV0WfrbV8Zvq1Xa+JGEpOOQZq7l6ps8ZDfIWDFbwJBYSqfX bbidGAew==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eYXcl-0001KF-I7; Mon, 08 Jan 2018 13:37:59 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eYXV3-0003L3-A3 for linux-arm-kernel@lists.infradead.org; Mon, 08 Jan 2018 13:30:14 +0000 Received: by mail-wm0-x242.google.com with SMTP id r78so14190816wme.5 for ; Mon, 08 Jan 2018 05:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C2u3XKqf0LKFXaORJ7Yri2u/Iml2MgQlBrxLcnQJAR4=; b=AqFnQKvxKySnYo1Nz9ftr8QL6jkLvAYyPclbCKBkUZLUUmyMHogOD4RgnvB3u/zwXr crlz4qzn5y67hd6T5UY4cyec9Jt5Cp2ExD1ZXtNAKKCKWu1KixnkEMXg+SeNpWl5MGya 2GhWAqUUL+iK1zt4DDXMmlZVEaENYdrZgbwiU= 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; bh=C2u3XKqf0LKFXaORJ7Yri2u/Iml2MgQlBrxLcnQJAR4=; b=H2uh0uxK49iko2x1NyJoXq9pCR7d/lMrzgXI4Sumpy0tVk+VZK2Ladq/Hyc7qoss33 epSDPcaOAYI5bMQ9VS02mCUo9XCm+uIjAN/xH+dYy6pqIvt/xcEXSfQyCKfBsEeoFoib 6Hu9L83wnxq/LAVQJLKoKDOgAXNdeRi5kpso3xBoNgpLbHwnfqB9zYp9YUx7MSI+J3nc xSYxYsldX1eCzSzlH/EXQb/9lHyYDeBkfMWDId5+q4m8F8HZglc/p+WuKONOOW37e3ND OTnks7F9RfSQ/392rnaKf/Na8+lWAgs3NYahZ9jzBru9NZJhx8Dj7fLDeAmZh5qVmpbC EcYw== X-Gm-Message-State: AKGB3mKLbWW57oWukGTFUT9TcxBwr1SQhLcvSPR2lBIOo5TF4hpi4fNC kYeiMu+ocTN6h6MaoAMwCJgFwQ== X-Google-Smtp-Source: ACJfBouAf+LIIXbD2hH+Ma2qvWMwWsMLDhFeCU/fxe7J2s/sWXgRY6B6ffwrvLg89Ver/XUBxrFM1g== X-Received: by 10.28.149.131 with SMTP id x125mr8737221wmd.129.1515418189549; Mon, 08 Jan 2018 05:29:49 -0800 (PST) Received: from mai.lan ([2001:41d0:fe90:b800:312a:53a5:1bef:6622]) by smtp.gmail.com with ESMTPSA id q196sm14354222wmb.22.2018.01.08.05.29.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jan 2018 05:29:48 -0800 (PST) From: Daniel Lezcano To: tglx@linutronix.de Subject: [PATCH 15/20] clocksource/drivers/stm32: Compute a prescaler value with a targeted rate Date: Mon, 8 Jan 2018 14:28:54 +0100 Message-Id: <1515418139-23276-15-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515418139-23276-1-git-send-email-daniel.lezcano@linaro.org> References: <1bbaef2e-4080-3f54-7db3-a8989acfd691@free.fr> <1515418139-23276-1-git-send-email-daniel.lezcano@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180108_053001_764822_567F2EFB X-CRM114-Status: GOOD ( 14.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "moderated list:ARM/STM32 ARCHITECTURE" , Alexandre Torgue , linux-kernel@vger.kernel.org, Maxime Coquelin , Benjamin Gaignard MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Benjamin Gaignard The prescaler value is arbitrarily set to 1024 without any regard to the timer frequency. For 32bits timers, there is no need to set a prescaler value as they wrap in an acceptable interval and give the opportunity to have precise timers on this platform. However, for 16bits timers a prescaler value is needed if we don't want to wrap too often per second which is unefficient and adds more and more error margin. With a targeted clock of 10MHz, the 16bits are precise enough whatever the timer frequency is as we will compute the prescaler. Signed-off-by: Benjamin Gaignard Signed-off-by: Daniel Lezcano Tested-by: Benjamin Gaignard Acked-by: Benjamin Gaignard --- drivers/clocksource/timer-stm32.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c index 862134e..ac55896 100644 --- a/drivers/clocksource/timer-stm32.c +++ b/drivers/clocksource/timer-stm32.c @@ -37,6 +37,9 @@ #define TIM_EGR_UG BIT(0) +#define TIM_PSC_MAX USHRT_MAX +#define TIM_PSC_CLKRATE 10000 + static int stm32_clock_event_shutdown(struct clock_event_device *clkevt) { struct timer_of *to = to_timer_of(clkevt); @@ -116,7 +119,14 @@ static void __init stm32_clockevent_init(struct timer_of *to) prescaler = 1; to->clkevt.rating = 250; } else { - prescaler = 1024; + prescaler = DIV_ROUND_CLOSEST(timer_of_rate(to), + TIM_PSC_CLKRATE); + /* + * The prescaler register is an u16, the variable + * can't be greater than TIM_PSC_MAX, let's cap it in + * this case. + */ + prescaler = prescaler < TIM_PSC_MAX ? prescaler : TIM_PSC_MAX; to->clkevt.rating = 100; } writel_relaxed(0, timer_of_base(to) + TIM_ARR);