From patchwork Mon Jan 8 13:28:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10149633 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 3B054602CA for ; Mon, 8 Jan 2018 13:38:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F5242856B for ; Mon, 8 Jan 2018 13:38:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 141D228632; Mon, 8 Jan 2018 13:38:25 +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=unavailable 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 913652856B for ; Mon, 8 Jan 2018 13:38:24 +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=zDSTiBlXieWbNvQTKlrgkgAhBu3ssxb+KyCz1TfW3Aw=; b=PWN6PQihIXmQr0KRz4jbuic1s2 Kc7IHvXYNUYoVmjX2hAs12UgwF0anHV8XDcWRVMZ6OLOKiHgAvcFvtyz92TH2+YFDVAwkAbk/LquM dRZpNsQJIW+vs9N5GybwjEW58e/QST0oGN7hAstr+POSzROGCnmuadM54Rxw+ZhdlCmjBZgix8DMv 3pVSMa3uBy6VZJqNUeTozI9UajonG0ozRf5HRxc5UUuq8JYY6YAVYcXiN7lST95gvHcdYU4pjl4xr 27xU1ouzvBTts40rUPCDL2pMoo3OGa0NFBI8GN4x8KOvBSk7+vuGjukAafSc9s6l9UGf3HzL35M9M bIUS9lgw==; 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 1eYXd5-0001X4-It; Mon, 08 Jan 2018 13:38:19 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eYXV1-0003Jt-8K for linux-arm-kernel@lists.infradead.org; Mon, 08 Jan 2018 13:30:19 +0000 Received: by mail-wm0-x241.google.com with SMTP id t8so14098450wmc.3 for ; Mon, 08 Jan 2018 05:29:49 -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=nDOEEh5UOozwDUN/iFWwB3KodhOX8zynnknLsAj1HYg=; b=L7LosHk5Myw7nnbnKT5dKmw5KzoSU2+icbIyzw5++bjtcIrVgG/hz33fhkEh6GMPof j5a/k36r8gkMF5VHvUzot4J15Zr1SFuTMuUby2jrPFZpwchrWfR9lRAT7LBQFqIb/mHB tFFnRHFeiECyIGrPJJAiP8gNiXyyAVxYSwk20= 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=nDOEEh5UOozwDUN/iFWwB3KodhOX8zynnknLsAj1HYg=; b=E9QC8uFmIL6SSQXmb38RoNPaZy84xDDAjwTu1obrL1e9ZjYixoUZKxUkk7ayw2JNbl fFTNQTDLUnOWT1L+m/7qhxqtd4TOopFgeQp8p0EjInLzag3Alx77sfsh9LZRlR/XqE11 8kAgG0MKkOGBCekuVU7mb769HfuOHXfm00YJZr0eyoQwXJJflyGi84HWadx5L6kf0e90 PKbW/wuV656NCE3hCgM82nh7cYfprhLsVfaTgLP0HwqptUYSortVvpjssnevKgtnsnE+ XgOS5tn49DvYVKJRmgYLVkS1eG3Dio/IO/7MXd01/enDGZ8DG/TpIAj8quj1YlkO9PaU U9XA== X-Gm-Message-State: AKGB3mLeG6XxD+BIK2WMOhsya3NVLpNM6TbQZGgq4MzwSdUIz0NKaZqH MoRI2FDlKpnzH4/kHvEcbIyLyA== X-Google-Smtp-Source: ACJfBotyXvtpufj0eH0y0d3GC4w3h1pPcEEgQUQk4jOOsVZyfn7CcvoB5s+7cPODXBMROPiW1Y/gSQ== X-Received: by 10.28.155.71 with SMTP id d68mr8851943wme.75.1515418187643; Mon, 08 Jan 2018 05:29:47 -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.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jan 2018 05:29:47 -0800 (PST) From: Daniel Lezcano To: tglx@linutronix.de Subject: [PATCH 14/20] clocksource/drivers/stm32: Encapsulate the timer width sorting out function Date: Mon, 8 Jan 2018 14:28:53 +0100 Message-Id: <1515418139-23276-14-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_052959_697417_6DFCF988 X-CRM114-Status: GOOD ( 14.52 ) 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 In order to clarify and encapsulate the code for the next changes move the timer width check into a function and add some documentation. Signed-off-by: Daniel Lezcano Tested-by: Benjamin Gaignard Acked-by: Benjamin Gaignard --- drivers/clocksource/timer-stm32.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c index 14b7a2b..862134e 100644 --- a/drivers/clocksource/timer-stm32.c +++ b/drivers/clocksource/timer-stm32.c @@ -80,9 +80,27 @@ static irqreturn_t stm32_clock_event_handler(int irq, void *dev_id) return IRQ_HANDLED; } +/** + * stm32_timer_width - Sort out the timer width (32/16) + * @to: a pointer to a timer-of structure + * + * Write the 32bits max value and read/return the result. If the timer + * is a 32bits width, the result will be UINT_MAX, otherwise it will + * be truncated by the 16bits register to USHRT_MAX. + * + * Returns UINT_MAX if the timer is 32bits width, USHRT_MAX if it is a + * 16bits width. + */ +static u32 __init stm32_timer_width(struct timer_of *to) +{ + writel_relaxed(UINT_MAX, timer_of_base(to) + TIM_ARR); + + return readl_relaxed(timer_of_base(to) + TIM_ARR); +} + static void __init stm32_clockevent_init(struct timer_of *to) { - unsigned long max_delta; + u32 width = 0; int prescaler; to->clkevt.name = to->np->full_name; @@ -93,10 +111,8 @@ static void __init stm32_clockevent_init(struct timer_of *to) to->clkevt.tick_resume = stm32_clock_event_shutdown; to->clkevt.set_next_event = stm32_clock_event_set_next_event; - /* Detect whether the timer is 16 or 32 bits */ - writel_relaxed(~0U, timer_of_base(to) + TIM_ARR); - max_delta = readl_relaxed(timer_of_base(to) + TIM_ARR); - if (max_delta == ~0U) { + width = stm32_timer_width(to); + if (width == UINT_MAX) { prescaler = 1; to->clkevt.rating = 250; } else { @@ -115,10 +131,10 @@ static void __init stm32_clockevent_init(struct timer_of *to) to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ); clockevents_config_and_register(&to->clkevt, - timer_of_rate(to), 0x1, max_delta); + timer_of_rate(to), 0x1, width); pr_info("%pOF: STM32 clockevent driver initialized (%d bits)\n", - to->np, max_delta == UINT_MAX ? 32 : 16); + to->np, width == UINT_MAX ? 32 : 16); } static int __init stm32_timer_init(struct device_node *node)