From patchwork Mon Jan 8 13:28:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10149617 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 A8EF3602CA for ; Mon, 8 Jan 2018 13:34:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A416205F7 for ; Mon, 8 Jan 2018 13:34:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DCA3283BF; Mon, 8 Jan 2018 13:34:36 +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 1A255205F7 for ; Mon, 8 Jan 2018 13:34:36 +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=lkIRRcSRWWDSnEembbVgyIgbKW8tqgn4kHyBZko6x0Q=; b=DhVQT+U3q/C/IVUansP5EXfPo8 vqG884VMqvmpoBoFAI6aZNkYuQtJvt78G/xKcjM7l/or6LzedumhnnpvDOHdOP2mr6BxW4OygHb2c h1O38PWKSTL51R1r3FBK+ijZOwd9LVeMDcm4pPpf1mjMiOqPMCxDBOmPYRjbGoNwlJweGqip8qd7v 2IDZn60YNFm9z+OGwcQKcW6kaYZaJQxOlIK6gLGUWY1gux3crQse+aWSY8Bfa+M9F/aahzJWYix89 D2Z4CVcVvZg0gp47kohe4ZcMnFV30meOtL1SMRMCqpadUr0k0qC7D///rz4JApReNlsgNttl+gXIL g86qCIpQ==; 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 1eYXZO-0007Mq-Du; Mon, 08 Jan 2018 13:34:30 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eYXV8-0003P1-Oq for linux-arm-kernel@lists.infradead.org; Mon, 08 Jan 2018 13:30:41 +0000 Received: by mail-wr0-x242.google.com with SMTP id n9so875352wrg.2 for ; Mon, 08 Jan 2018 05:29:56 -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=zvaTTcfXtuzr1lD0vuoooMntsEE/356EFRYm5/iSR3U=; b=P8W0dFPOT+qQ0FriyOGe08cIwBV4dKMIiGpr4mLBrazuA9g9Kmq/CHsPW8TL3EIi8K Cs98WQdH/8qMwH2xNrNRetElGhskT79ApAQSIMpxrrtKUzIlC5mKnN9yg7mN/KerMcfT uelZafb+Vg9oMV0JD3pYghFbHd5JGuXFZ0Ce0= 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=zvaTTcfXtuzr1lD0vuoooMntsEE/356EFRYm5/iSR3U=; b=hL/1tv5R5cmN667HxWjiDal82helxWtMseNMbHqFdLeOzoEP6eP37yaLIuUBCBTfpo lBnftHEWRYgaN8cCouKSl14jRfA7b4h6SmAihmrd+XwuMLs3s0SHx46+ThaMsiPrSyd3 K8DfR1McRazRAag6WOjCvt9rvvCcfe+x3u2cPxuDkSkLhUbWWcSvoEB0RocZ1k1ajsrY fnmER1kxwUTFlb8PXH22p7gHB5UuBtSu0yZQYjx38u+in6bd44n3IuDSnTEsvgHRrkyH 1QwaXvn9iA27qr8lgNa5r2fCCfYLsdpVFMhW1AvUyvd3OXYAOdThwojE1/XpS2ZS98pF i3vQ== X-Gm-Message-State: AKGB3mJ1liRpbDtQhb8GZEa+6MdhusveXT5rU1+s7UMvZ9oKcwrhhPOO Xto6S4uXxmGHXZ42WgNeL9zhtQ== X-Google-Smtp-Source: ACJfBovoaoW/XwYbcywj/mbshEuXFe8JsS89iog0nGp88/jyi4/QvmXRCQZ7TCDmW2X5TXfNdW0uUw== X-Received: by 10.223.157.206 with SMTP id q14mr11001614wre.21.1515418195160; Mon, 08 Jan 2018 05:29:55 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jan 2018 05:29:54 -0800 (PST) From: Daniel Lezcano To: tglx@linutronix.de Subject: [PATCH 18/20] clocksource/drivers/stm32: Add the clocksource Date: Mon, 8 Jan 2018 14:28:57 +0100 Message-Id: <1515418139-23276-18-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_053007_168449_A4BAFD11 X-CRM114-Status: GOOD ( 14.28 ) 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 From: Benjamin Gaignard The scene is set for the clocksource, let's add it for this driver. Signed-off-by: Benjamin Gaignard Signed-off-by: Daniel Lezcano Tested-by: Benjamin Gaignard Acked-by: Benjamin Gaignard --- drivers/clocksource/timer-stm32.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c index 1891924..4634f4d 100644 --- a/drivers/clocksource/timer-stm32.c +++ b/drivers/clocksource/timer-stm32.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "timer-of.h" @@ -80,6 +81,13 @@ static int stm32_timer_of_bits_get(struct timer_of *to) return pd->bits; } +static void __iomem *stm32_timer_cnt __read_mostly; + +static u64 notrace stm32_read_sched_clock(void) +{ + return readl_relaxed(stm32_timer_cnt); +} + static void stm32_clock_event_disable(struct timer_of *to) { writel_relaxed(0, timer_of_base(to) + TIM_DIER); @@ -204,6 +212,31 @@ static void __init stm32_timer_set_prescaler(struct timer_of *to) to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ); } +static int __init stm32_clocksource_init(struct timer_of *to) +{ + u32 bits = stm32_timer_of_bits_get(to); + const char *name = to->np->full_name; + + /* + * This driver allows to register several timers and relies on + * the generic time framework to select the right one. + * However, nothing allows to do the same for the + * sched_clock. We are not interested in a sched_clock for the + * 16bits timers but only for the 32bits, so if no 32bits + * timer registered yet, we select this 32bits timer as a + * sched_clock. + */ + if (bits == 32 && !stm32_timer_cnt) { + stm32_timer_cnt = timer_of_base(to) + TIM_CNT; + sched_clock_register(stm32_read_sched_clock, bits, timer_of_rate(to)); + pr_info("%s: STM32 sched_clock registered\n", name); + } + + return clocksource_mmio_init(timer_of_base(to) + TIM_CNT, name, + timer_of_rate(to), bits == 32 ? 250 : 100, + bits, clocksource_mmio_readl_up); +} + static void __init stm32_clockevent_init(struct timer_of *to) { u32 bits = stm32_timer_of_bits_get(to); @@ -256,6 +289,10 @@ static int __init stm32_timer_init(struct device_node *node) stm32_timer_set_prescaler(to); + ret = stm32_clocksource_init(to); + if (ret) + goto deinit; + stm32_clockevent_init(to); return 0;