From patchwork Thu May 9 11:10:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 163712 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp819481ilr; Thu, 9 May 2019 04:12:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwt2Wbzly4U8DcC36vlPy+4smHQw1xZ+Pn0/V80dtJEe6mH0RnahGFjPCickRLACurcw/xF X-Received: by 2002:a63:5110:: with SMTP id f16mr4629704pgb.107.1557400346866; Thu, 09 May 2019 04:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557400346; cv=none; d=google.com; s=arc-20160816; b=ZsSMO4oKFKxLnCmKJ6/AmpDSiqGA21vvd8kxI0y0wW49AfHAUc7JyHWx4dg3kupGNV I4WVcwDavx1HSCC4NdxnyYckUA5Jx/O9vPb6fIyx8T4EVaIy4aG+8dLBQIEp7HBPn7YJ 44wtVYQkSWF37OH5dYeqpUKANIaC/31nxiyjWKXWVjbPn/hyqK9ed9XVwe/dBvlx6kmp J7p48O9Q7xyW9YOT7rOJEsojV6hS9kQrKmNThLlc+eHFiKaVY4By/+VwpeRk9GQTnc9T h1Ez20PHIDVFvPFAuVRHmfuWnIOlscu7g9PETSFJXO808XUGzw8VauYPsC1G/UuWX35H vSxQ== 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; bh=P3ip9Z1kPiurKcUpueirhLQ3VIip1Pisqdmbkd91afc=; b=pKcH9qnqFwOO72Y4cMlYlYAGKYFPOXeziTAQBHaq07AQK1KLKQl1kLxFzLk9SyKAOb 4zOQwEiL0+Z7q3W/JjKIF2YjmooKYOiHXa/lL2nWCX2EARk5xTZ5CRK4GL9MJj18mdu5 41muYKpFqctSnYwHvKWiGke80GHtScRO8zNE+2k67zfBtOmfwoDPf1lXXw16ZSq6ezLX 6+uCtEG7Z5CH3sfC/hBIrv9fAuKlBN45qEcFNB+10P1WZrpOvdgmGjrjjAi+GxgzbGOB jhXXXkavZuX/N8x4cDGLepg+/zaHDYfJjp6nXMvnTONHDueX0Azqn2z/Q+7/QGfjB/Vu vqhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tk0VK6es; 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 w23si2406374plk.109.2019.05.09.04.12.26; Thu, 09 May 2019 04:12:26 -0700 (PDT) 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=tk0VK6es; 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 S1726881AbfEILMZ (ORCPT + 30 others); Thu, 9 May 2019 07:12:25 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36689 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726084AbfEILLg (ORCPT ); Thu, 9 May 2019 07:11:36 -0400 Received: by mail-wr1-f68.google.com with SMTP id o4so2474504wra.3 for ; Thu, 09 May 2019 04:11:35 -0700 (PDT) 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=P3ip9Z1kPiurKcUpueirhLQ3VIip1Pisqdmbkd91afc=; b=tk0VK6eshbXc6vdh9kh06KVLt040/1a5YvqavcZdlyogvdnIi3Z4HZkhRrNJRUkW84 xqnY2WsmFfZfGeJbBbR9m3uFHGPMOEER+cg+fqfietDdEX3q2cmAinp1Jo+R0pIxEdVq G6L3qpNF4MXaUC3UR0KMADi7lzEcItYMrTSh/SPHPSeeobxMkAWn+V58X8qYKjFnn/0b aWOblHDwIRNXcUZkRerNr4YyY6EpXF92AEedpI/t2y2+UgLPzB8YqUOyQ49nB77PuEH2 Ap9ByMxHDdVNzDOCOF5Zm8sVKdY0dbdu3ANM1dRnFhFqpUZwWcs7GXJsXLhLZRgeZl0E SCbA== 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=P3ip9Z1kPiurKcUpueirhLQ3VIip1Pisqdmbkd91afc=; b=saBPHrHFeQdWyDIOW7JU/okfetYYowJ9PjpWjgZTcHhTJW0Tt6vK05Neuf9+Hy0m0J 0aafSRR/vYIbvpzqHv3HGRw2ywi6MBazv/Wv/Ak8Krzp4Gb4uNjVYCZr9MEmgdrG/dXn FvPHtBVLG4MT7euXqeKzvYtOT1cPUiUoQyiARQzJ3P6+MSLe1xL8ePrMik/Q635Flefk AJbIqPBi8DCfhlWIYn43RzQ8uSDhXHDE4qPzsWulLUTZJyBGp542y4NhYGAKvpbflJR7 nlMLcnbnaKcTT8lpcVzqz8PgUJ5yUAw0N3SqaP8a3EpnDAa92VjAZk4tHHrL0OWKS9rD rbHA== X-Gm-Message-State: APjAAAVFPqxLjE7jLhMyG1YKj0OebQHh6CaXrHzPoRpxi7TyszYAWlcU BgF19XzCr6zX3U4qDWUHVthMQQ== X-Received: by 2002:a5d:400b:: with SMTP id n11mr638415wrp.123.1557400294149; Thu, 09 May 2019 04:11:34 -0700 (PDT) Received: from mai.irit.fr ([141.115.39.235]) by smtp.gmail.com with ESMTPSA id z7sm2299778wme.26.2019.05.09.04.11.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 04:11:33 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, Sugaya Taichi Subject: [PATCH 06/15] clocksource/drivers/timer-milbeaut: Cleanup common register accesses Date: Thu, 9 May 2019 13:10:39 +0200 Message-Id: <20190509111048.11151-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190509111048.11151-1-daniel.lezcano@linaro.org> References: <7e786ba3-a664-8fd9-dd17-6a5be996a712@linaro.org> <20190509111048.11151-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sugaya Taichi Aggregate common register accesses into shared functions for maintainability. Signed-off-by: Sugaya Taichi Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-milbeaut.c | 62 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 23 deletions(-) -- 2.17.1 diff --git a/drivers/clocksource/timer-milbeaut.c b/drivers/clocksource/timer-milbeaut.c index f4780619dbaf..fa9fb4eacade 100644 --- a/drivers/clocksource/timer-milbeaut.c +++ b/drivers/clocksource/timer-milbeaut.c @@ -26,8 +26,8 @@ #define MLB_TMR_TMCSR_CSL_DIV2 0 #define MLB_TMR_DIV_CNT 2 -#define MLB_TMR_SRC_CH (1) -#define MLB_TMR_EVT_CH (0) +#define MLB_TMR_SRC_CH 1 +#define MLB_TMR_EVT_CH 0 #define MLB_TMR_SRC_CH_OFS (MLB_TMR_REGSZPCH * MLB_TMR_SRC_CH) #define MLB_TMR_EVT_CH_OFS (MLB_TMR_REGSZPCH * MLB_TMR_EVT_CH) @@ -43,6 +43,8 @@ #define MLB_TMR_EVT_TMRLR2_OFS (MLB_TMR_EVT_CH_OFS + MLB_TMR_TMRLR2_OFS) #define MLB_TIMER_RATING 500 +#define MLB_TIMER_ONESHOT 0 +#define MLB_TIMER_PERIODIC 1 static irqreturn_t mlb_timer_interrupt(int irq, void *dev_id) { @@ -59,38 +61,53 @@ static irqreturn_t mlb_timer_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static int mlb_set_state_periodic(struct clock_event_device *clk) +static void mlb_evt_timer_start(struct timer_of *to, bool periodic) { - struct timer_of *to = to_timer_of(clk); u32 val = MLB_TMR_TMCSR_CSL_DIV2; + val |= MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE; + if (periodic) + val |= MLB_TMR_TMCSR_RELD; writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); +} + +static void mlb_evt_timer_stop(struct timer_of *to) +{ + u32 val = readl_relaxed(timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); - writel_relaxed(to->of_clk.period, timer_of_base(to) + - MLB_TMR_EVT_TMRLR1_OFS); - val |= MLB_TMR_TMCSR_RELD | MLB_TMR_TMCSR_CNTE | - MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE; + val &= ~MLB_TMR_TMCSR_CNTE; writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); +} + +static void mlb_evt_timer_register_count(struct timer_of *to, unsigned long cnt) +{ + writel_relaxed(cnt, timer_of_base(to) + MLB_TMR_EVT_TMRLR1_OFS); +} + +static int mlb_set_state_periodic(struct clock_event_device *clk) +{ + struct timer_of *to = to_timer_of(clk); + + mlb_evt_timer_stop(to); + mlb_evt_timer_register_count(to, to->of_clk.period); + mlb_evt_timer_start(to, MLB_TIMER_PERIODIC); return 0; } static int mlb_set_state_oneshot(struct clock_event_device *clk) { struct timer_of *to = to_timer_of(clk); - u32 val = MLB_TMR_TMCSR_CSL_DIV2; - writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); - val |= MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE; - writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); + mlb_evt_timer_stop(to); + mlb_evt_timer_start(to, MLB_TIMER_ONESHOT); return 0; } static int mlb_set_state_shutdown(struct clock_event_device *clk) { struct timer_of *to = to_timer_of(clk); - u32 val = MLB_TMR_TMCSR_CSL_DIV2; - writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); + mlb_evt_timer_stop(to); return 0; } @@ -99,22 +116,21 @@ static int mlb_clkevt_next_event(unsigned long event, { struct timer_of *to = to_timer_of(clk); - writel_relaxed(event, timer_of_base(to) + MLB_TMR_EVT_TMRLR1_OFS); - writel_relaxed(MLB_TMR_TMCSR_CSL_DIV2 | - MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_INTE | - MLB_TMR_TMCSR_TRG, timer_of_base(to) + - MLB_TMR_EVT_TMCSR_OFS); + mlb_evt_timer_stop(to); + mlb_evt_timer_register_count(to, event); + mlb_evt_timer_start(to, MLB_TIMER_ONESHOT); return 0; } static int mlb_config_clock_source(struct timer_of *to) { - writel_relaxed(0, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS); - writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMR_OFS); + u32 val = MLB_TMR_TMCSR_CSL_DIV2; + + writel_relaxed(val, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS); writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMRLR1_OFS); writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMRLR2_OFS); - writel_relaxed(BIT(4) | BIT(1) | BIT(0), timer_of_base(to) + - MLB_TMR_SRC_TMCSR_OFS); + val |= MLB_TMR_TMCSR_RELD | MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG; + writel_relaxed(val, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS); return 0; }