From patchwork Tue Jun 6 12:44:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 9768849 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 1E4466035D for ; Tue, 6 Jun 2017 12:45:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3CAE26E74 for ; Tue, 6 Jun 2017 12:45:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E816F2834A; Tue, 6 Jun 2017 12:45:05 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID 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 E2E8326E74 for ; Tue, 6 Jun 2017 12:45:04 +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=KUMWcFhBY1kUDwAr9Dm4yED1q8jAhy2KwG+j43T5hFs=; b=tqgWaVxKngymfGfhJGRcL25zfa adH2rRPnip1CSnlJy0y9E/Ton4yJuY3dI5z+xlH3d1gML5T66c7T0AFb+suW6w6LIPoTQyW0K/uVK 6b3yTnlzmCKlxdcgrdajnAv7veO8eEigXPD2SyFbtx/oax3X7DXcpteuJo9w2l8qsIzSPvOW8yY6+ zz+pZE9etVdecfANAmKR4V3lAzY/63DzDCrmJiMlO3Zp4tbgKfZz+YCsTXtyTf/I8JZ6jIiYAfUBz Eahre4G7XuCgJYuQTVC37lORII/D+8iEcpKNVaorSJRZqn60EjSKFiidXBvs+VaMMVD8LTLjm23fI qzkVQPkg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIDr5-00077P-Dq; Tue, 06 Jun 2017 12:45:03 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIDqr-0006vX-TG for linux-arm-kernel@lists.infradead.org; Tue, 06 Jun 2017 12:44:51 +0000 Received: by mail-wm0-x229.google.com with SMTP id x70so36248631wme.0 for ; Tue, 06 Jun 2017 05:44:29 -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=lFGaAGzZYzKbX5d1R1FHW0G3UYMy2E11PyIUW1V1gAQ=; b=K0LQ1MgP3p1ncpvLJ79bZ0MuV9IEXJac6uw7HL+eU4WoRjxruekM4nvRY6j1ONHxJC O5D4A12tpwTIwiyHSmCqoJ9Omi4oNKNvDInAe0TkiH69cU04eW9kgQG8H/mrYyhSf3N6 5lIyBkef38ifB7SuU/V0YyUSQvRScX/TYqdic= 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=lFGaAGzZYzKbX5d1R1FHW0G3UYMy2E11PyIUW1V1gAQ=; b=X6q/XGyX4eBKQEvnjE04H3BuQy36ngV4Mqy+NvrJ9bqXAocLZNmWlYLKdEZYzri/r5 gTpmIIO6d8yfAhvBBzZL/GihLBueB+UZZwctYkDsUezxTn3a4Q2tK3xJfLNcXtE57J1t 2Ey7VTf2OIjz6Hn3DExzbxWfHLcxPf3jez3TMmJw1uj+9+f9meARMaNCxKAj+7I6QN1X UtswTTIixndfb7nmx96RuAcCR7RUPf91RSLy0uXifFVF2x2PFVlrq6iUe3ubCXNExTpM 8xl5/l5JGkc0ess/PZ5OsaGwZI5K+1SgKM/9zc2axkwVju/nUmgdG4VsBBXraLDSyQ71 nhXg== X-Gm-Message-State: AODbwcA/ouQC876VDshQljTfeQHZGNOYZeeX6SDphk9yhLPF76Bg6tG2 dU6wtxOHnI1MODzC X-Received: by 10.28.28.146 with SMTP id c140mr12135101wmc.122.1496753068109; Tue, 06 Jun 2017 05:44:28 -0700 (PDT) Received: from localhost.localdomain ([2001:41d0:fe90:b800:3f16:bcf7:601c:a13b]) by smtp.gmail.com with ESMTPSA id w17sm6277827wra.34.2017.06.06.05.44.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Jun 2017 05:44:27 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Subject: [PATCH 2/2] clocksource/drivers/keystone: Use the timer-of common routine Date: Tue, 6 Jun 2017 14:44:12 +0200 Message-Id: <1496753054-7489-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496753054-7489-1-git-send-email-daniel.lezcano@linaro.org> References: <1496753054-7489-1-git-send-email-daniel.lezcano@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170606_054450_092669_81C7B2A2 X-CRM114-Status: GOOD ( 17.80 ) 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: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Santosh Shilimkar 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 The previous patch provided a common init routine for the OF drivers. The keystone driver is given as example on the improvement and usage of the common initialization routine. Signed-off-by: Daniel Lezcano --- drivers/clocksource/Kconfig | 1 + drivers/clocksource/timer-keystone.c | 117 +++++++++++++---------------------- 2 files changed, 44 insertions(+), 74 deletions(-) diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 4ba230d..f1ed520 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -216,6 +216,7 @@ config KEYSTONE_TIMER depends on GENERIC_CLOCKEVENTS depends on ARM || ARM64 select CLKSRC_MMIO + select TIMER_OF help Enables support for the Keystone timer. diff --git a/drivers/clocksource/timer-keystone.c b/drivers/clocksource/timer-keystone.c index 0eee032..84b2523 100644 --- a/drivers/clocksource/timer-keystone.c +++ b/drivers/clocksource/timer-keystone.c @@ -18,6 +18,8 @@ #include #include +#include "timer-of.h" + #define TIMER_NAME "timer-keystone" /* Timer register offsets */ @@ -37,26 +39,16 @@ #define TGCR_TIM_UNRESET_MASK 0x03 #define INTCTLSTAT_ENINT_MASK 0x01 -/** - * struct keystone_timer: holds timer's data - * @base: timer memory base address - * @hz_period: cycles per HZ period - * @event_dev: event device based on timer - */ -static struct keystone_timer { - void __iomem *base; - unsigned long hz_period; - struct clock_event_device event_dev; -} timer; +static struct timer_of to; static inline u32 keystone_timer_readl(unsigned long rg) { - return readl_relaxed(timer.base + rg); + return readl_relaxed(timer_of_base(&to) + rg); } static inline void keystone_timer_writel(u32 val, unsigned long rg) { - writel_relaxed(val, timer.base + rg); + writel_relaxed(val, timer_of_base(&to) + rg); } /** @@ -123,6 +115,7 @@ static irqreturn_t keystone_timer_interrupt(int irq, void *dev_id) struct clock_event_device *evt = dev_id; evt->event_handler(evt); + return IRQ_HANDLED; } @@ -140,43 +133,42 @@ static int keystone_shutdown(struct clock_event_device *evt) static int keystone_set_periodic(struct clock_event_device *evt) { - keystone_timer_config(timer.hz_period, TCR_ENAMODE_PERIODIC_MASK); + struct timer_of *to = to_timer_of(evt); + + keystone_timer_config(timer_of_period(to), TCR_ENAMODE_PERIODIC_MASK); + return 0; } +static struct timer_of to = { + .flags = TIMER_OF_IRQ | + TIMER_OF_CLOCK | + TIMER_OF_BASE, + + .clkevt = { + .features = CLOCK_EVT_FEAT_PERIODIC | + CLOCK_EVT_FEAT_ONESHOT, + .set_next_event = keystone_set_next_event, + .set_state_shutdown = keystone_shutdown, + .set_state_periodic = keystone_set_periodic, + .set_state_oneshot = keystone_shutdown, + .cpumask = cpu_all_mask, + .owner = THIS_MODULE, + .name = TIMER_NAME, + }, + + .of_irq = { + .handler = keystone_timer_interrupt, + }, +}; + static int __init keystone_timer_init(struct device_node *np) { - struct clock_event_device *event_dev = &timer.event_dev; - unsigned long rate; - struct clk *clk; - int irq, error; - - irq = irq_of_parse_and_map(np, 0); - if (!irq) { - pr_err("%s: failed to map interrupts\n", __func__); - return -EINVAL; - } - - timer.base = of_iomap(np, 0); - if (!timer.base) { - pr_err("%s: failed to map registers\n", __func__); - return -ENXIO; - } - - clk = of_clk_get(np, 0); - if (IS_ERR(clk)) { - pr_err("%s: failed to get clock\n", __func__); - iounmap(timer.base); - return PTR_ERR(clk); - } - - error = clk_prepare_enable(clk); - if (error) { - pr_err("%s: failed to enable clock\n", __func__); - goto err; - } - - rate = clk_get_rate(clk); + int ret; + + ret = timer_of_init(np, &to); + if (ret) + return ret; /* disable, use internal clock source */ keystone_timer_writel(0, TCR); @@ -193,38 +185,15 @@ static int __init keystone_timer_init(struct device_node *np) keystone_timer_writel(0, TIM12); keystone_timer_writel(0, TIM34); - timer.hz_period = DIV_ROUND_UP(rate, HZ); - /* enable timer interrupts */ keystone_timer_writel(INTCTLSTAT_ENINT_MASK, INTCTLSTAT); - error = request_irq(irq, keystone_timer_interrupt, IRQF_TIMER, - TIMER_NAME, event_dev); - if (error) { - pr_err("%s: failed to setup irq\n", __func__); - goto err; - } - - /* setup clockevent */ - event_dev->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; - event_dev->set_next_event = keystone_set_next_event; - event_dev->set_state_shutdown = keystone_shutdown; - event_dev->set_state_periodic = keystone_set_periodic; - event_dev->set_state_oneshot = keystone_shutdown; - event_dev->cpumask = cpu_all_mask; - event_dev->owner = THIS_MODULE; - event_dev->name = TIMER_NAME; - event_dev->irq = irq; - - clockevents_config_and_register(event_dev, rate, 1, ULONG_MAX); - - pr_info("keystone timer clock @%lu Hz\n", rate); + clockevents_config_and_register(&to.clkevt, timer_of_rate(&to), + 1, ULONG_MAX); + + pr_info("keystone timer clock @%lu Hz\n", timer_of_rate(&to)); + return 0; -err: - clk_put(clk); - iounmap(timer.base); - return error; } -TIMER_OF_DECLARE(keystone_timer, "ti,keystone-timer", - keystone_timer_init); +TIMER_OF_DECLARE(keystone_timer, "ti,keystone-timer", keystone_timer_init);