From patchwork Thu Jan 4 12:50:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10144681 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 650676034B for ; Thu, 4 Jan 2018 12:54:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5029E28537 for ; Thu, 4 Jan 2018 12:54:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 439BC28634; Thu, 4 Jan 2018 12:54:54 +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 8185728537 for ; Thu, 4 Jan 2018 12:54:53 +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=GKsfOTW6C1uWCfILFmmuwejZ0D2tihPQo4gM5eEtyqY=; b=XLkcj6kee+2S7OF/Io6Ktp/HqF 6PYUOwEuQleNWMD9rvG5A0dC615E5F0/EDrETgRcQu0Ryn0V0mV7a4xQSRH/fsE/GJOXd721s48A/ PNFK+dQ3tCwjQIXyyQ7gWEy159VjC7k4vHg9/kfMTUEVSglEcLNd9grCGWDUsgII3LuIJtZuCvv85 H8+q9T4Xbzut5hBIlmZE38V9DIzZ6zOVrEKeZ/wX0r+v8vJ5dL06wyjZDGS81bvQxUonDyyS8MWIY qn7Q2XKN4EFagl0gAGXtBRhF8bzRb+2G5/E9pe9jUG/YicmNPHIpVLj9uX0umf3LQORv9ebjH001j tROzAgmg==; 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 1eX52l-0007zj-LD; Thu, 04 Jan 2018 12:54:47 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eX4zi-0005t0-42 for linux-arm-kernel@lists.infradead.org; Thu, 04 Jan 2018 12:51:54 +0000 Received: by mail-wr0-x243.google.com with SMTP id f8so1394613wre.4 for ; Thu, 04 Jan 2018 04:51:27 -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=W1UN4RiKQIqNn9o0WibTbGzXVi2IFRoGRjTvmPwfcoI=; b=LSrmbEndDA+7Vqu9FbRTqoeP1yTEMLjNJTD/fSMYJsIPhAv0AlmTOupwJvTQUuNnbl 7tKZZnsxbOGr5a+dzluT7OS/SxzvRQyP3OkOUjSZK+KT5qhMAgk314GQ8+kDucaluGhF QF4DkOBQ1eTM4aYeyn+YZqIijdWo6bPbbTHYE= 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=W1UN4RiKQIqNn9o0WibTbGzXVi2IFRoGRjTvmPwfcoI=; b=WjRKIgclCVgIRG4io+nYZyqSUDTvQoOj/sNMf+umYMppuUvS3f5xsnJPcHfTU6Wl5h Ee9Jh5LPkbnEY3RG4kYI4kKzb/Z0Elp/GdpL66w5a/1RUh04a989OskwKUs5HikmepIB 8e0CcDpjsLAaA2Fhtjl4+UWRz7CNCq6/0LUzQk7ejLPDLzEIKjuvp6/FtQRJbNLNSv7u kxgdyOIf8JHoBIINf5YONtwB26N7yl+2bxbkagXoGIpdtXNuNARIVwoi2Ms0MoF/tufv of7ymonKkill9Nym8/egpOBO4p7YEFWxTD4Rcaf9pXvU5HLZExIi/LRwLFh6LX4Q4uzK DQ8Q== X-Gm-Message-State: AKGB3mLmdMkjQWLNcYhwDNIuKcIJN5hg8t8Rk/TWFYr3W+5QKRr3L5ms pgEN7NISKm9TRbe95EDdbg0UYQ== X-Google-Smtp-Source: ACJfBot4gCYIoLnAXTatGY1jfIgZ6S9yOM3cKyAyMu17NXTWC01ezChBpKNSpD8Bkt6HYBuy0r/biA== X-Received: by 10.223.134.115 with SMTP id 48mr4561068wrw.213.1515070286117; Thu, 04 Jan 2018 04:51:26 -0800 (PST) Received: from mai.lan ([2001:41d0:fe90:b800:c10d:405d:d60:60bb]) by smtp.gmail.com with ESMTPSA id d71sm3668348wma.7.2018.01.04.04.51.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Jan 2018 04:51:25 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, tglx@linutronix.de Subject: [PATCH 07/12] clocksource/drivers/stm32: Compute a prescaler value with a targeted rate Date: Thu, 4 Jan 2018 13:50:23 +0100 Message-Id: <1515070228-10481-8-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515070228-10481-1-git-send-email-daniel.lezcano@linaro.org> References: <1515070228-10481-1-git-send-email-daniel.lezcano@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180104_045139_098886_380E4060 X-CRM114-Status: GOOD ( 14.35 ) 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: benjamin.gaignard@linaro.org, Alexandre Torgue , linux-kernel@vger.kernel.org, Maxime Coquelin , "moderated list:ARM/STM32 ARCHITECTURE" , 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. [Daniel Lezcano]: Massaged the changelog and added comment. Signed-off-by: Benjamin Gaignard Signed-off-by: Daniel Lezcano --- 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);