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: 123419 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp11390886qgn; Thu, 4 Jan 2018 04:52:48 -0800 (PST) X-Google-Smtp-Source: ACJfBou0JGtMyz5kcUoPkJ1VjEV+ZFfYXRaUpi+sJRU8hBx0bgqwq3HpE3oLVXvatlBEX3Ibb096 X-Received: by 10.84.240.139 with SMTP id z11mr4556713plk.348.1515070368874; Thu, 04 Jan 2018 04:52:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515070368; cv=none; d=google.com; s=arc-20160816; b=Idn0Zxq3nDyy1mic03F4/Kzk8gVdxUYDgxQzOFocqffvf4qQ/LJjfbSAaqWPhHiqWr AoEm+ohJbpV1c3UlEL18E39okZnE/NS4BMsg3gnMia4sp3UaiAO5qpz2hI0lW/xi6IwQ gaMQCG7sQmeBqWjb6e6FKTr6HH+LxXrQtNibFN3OBHG+U5GRATojHHW15qqk0e4HfLyi VzxPvF9G+22JIkcVZU7CFN5kUljK3XSDPHVbX7wtOvYJzZtFb2sSm3QPO3YLc3E6SIiE Qp/t7bNej8BLAeE2zYjw4FVbaOJRpYY+6KPdFvZwa3k3VFaarXXgZaQH/qR9AxW2LeTF lkPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=W1UN4RiKQIqNn9o0WibTbGzXVi2IFRoGRjTvmPwfcoI=; b=Epfsp4WpzxKfcS3QxsjtYw9B5i4gCJ7vGluVGemApE35rKvYZ2OArSmEJfB4QQgpNn kSl4u2IBkOqHsycGcLHzaPfEQ39UJK0ChElkHBi0SpIKvx3VSajmc/E6e1c3CDCaAwWO rLQEGXEqjQengdkDVI0Q+Ifd+I16t9dTlW8uG0OPslCcVwTE9bv20PztJM8FkqbqydFZ zXCRZuo4J1MO22J55ZURgDjKQxy5f2ZwkxzjhgsODuhHDpxglfOpL/L/MaSGhbLZB9hC Xn6eGLI5q0Yrc86uu15q+NBOC6lglATsk5v+UcIUPA9uBggCkk9YI9B7oBhKTewflSXH M0EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LSrmbEnd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si1999070pgr.829.2018.01.04.04.52.48; Thu, 04 Jan 2018 04:52:48 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b=LSrmbEnd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752889AbeADMva (ORCPT + 27 others); Thu, 4 Jan 2018 07:51:30 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:46559 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752820AbeADMv1 (ORCPT ); Thu, 4 Jan 2018 07:51:27 -0500 Received: by mail-wr0-f194.google.com with SMTP id g17so1382037wrd.13 for ; Thu, 04 Jan 2018 04:51:26 -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=EAkV5QCvSYlJb2FYU6FQfMS7QUajZKp5KOXMJc069Q6fD+JniOEB79E3SI4M/nHzkI zvKIIqFr0dF0MpIroU9GZ5bYwyn4ph6M476qHKx35wtmbb2vs4OksTbu3GYxcahgN8HI VPI7KrceLsvGfKXn+ek+fCTdIhNwi4EglFzBTLGV0GcBs98ts4fZunCAVhpfeREYiESw y9DBwwLqZoH3gVrYZI0jT4GHj+e6Xwzo7eChGMVHFQwq8Q42LOll/qWubuOEu/OOPZOS c4dqCsUNFsp2pwWV+mMWpOCehoc4ctOjeebsHwfwcZurV53tDP8D3GJWlaTv2eoF1Ndc te/w== X-Gm-Message-State: AKGB3mIdr6tY26RqT0sQyCAO/jhboKvmbaMg9vzXRiOi3VpI4ONMT/j8 FNoSF4pM8r22HP2FXYtETt+qEg== 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 Cc: linux-kernel@vger.kernel.org, benjamin.gaignard@linaro.org, Benjamin Gaignard , Maxime Coquelin , Alexandre Torgue , linux-arm-kernel@lists.infradead.org (moderated list:ARM/STM32 ARCHITECTURE) 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.4 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);