From patchwork Thu Mar 12 21:55:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 449666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B34731400EA for ; Fri, 13 Mar 2015 08:56:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=d9uaXJ4J; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756005AbbCLV4p (ORCPT ); Thu, 12 Mar 2015 17:56:45 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:39437 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755867AbbCLV4d (ORCPT ); Thu, 12 Mar 2015 17:56:33 -0400 Received: by wiwl15 with SMTP id l15so1351874wiw.4; Thu, 12 Mar 2015 14:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HQRhKWWZtKfBrXVfz0t7MYzn9k+WKNlO6D32GZjzSwE=; b=d9uaXJ4JuJGWvJpexmVYIYpp1cZQ8Z5iiVzZM6c9wTKdpcJFcPqngl7Uo7lO+1mad5 MysuCrTkT5LNhHQEjnp0TR84QTOV9vGD5TnNMlfg9OoV0DAvAi20uY0XC+LMTGKJk5RQ YxmhJuUsNCWBPv42/NdzADFpwpz9qrxIfY9jt8Jc/WL0Vw0D+spvv0hZucQnpehqHlvE znsIrNYgJRLhgW4+TF1svPCY1I9N4T/4d1vysIFP4Z40xnq0j/pw0PHKHHZ4fkfJ0JCc CQk0GHJZJ84lEwsZ3Nxw7NtuIhan0w7Ytr2lqTi8xDb/SDnEndh38/n/haFsqH7/z4bh 0rOQ== X-Received: by 10.180.75.243 with SMTP id f19mr90906567wiw.94.1426197391385; Thu, 12 Mar 2015 14:56:31 -0700 (PDT) Received: from lmecul0520.st.com. (246.208.139.88.rev.sfr.net. [88.139.208.246]) by mx.google.com with ESMTPSA id hl8sm148976wjb.38.2015.03.12.14.56.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Mar 2015 14:56:30 -0700 (PDT) From: Maxime Coquelin X-Google-Original-From: Maxime Coquelin To: u.kleine-koenig@pengutronix.de, afaerber@suse.de, geert@linux-m68k.org, Rob Herring , Philipp Zabel , Linus Walleij , Arnd Bergmann , stefan@agner.ch, pmeerw@pmeerw.net, pebolle@tiscali.nl Cc: Jonathan Corbet , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Russell King , Daniel Lezcano , Thomas Gleixner , Greg Kroah-Hartman , Jiri Slaby , Andrew Morton , "David S. Miller" , Mauro Carvalho Chehab , Joe Perches , Antti Palosaari , Tejun Heo , Will Deacon , Nikolay Borisov , Rusty Russell , Kees Cook , Michal Marek , linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, linux-serial@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, mcoquelin.stm32@gmail.com Subject: [PATCH v3 04/15] clocksource: Add ARM System timer driver Date: Thu, 12 Mar 2015 22:55:50 +0100 Message-Id: <1426197361-19290-5-git-send-email-maxime.coquelin@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426197361-19290-1-git-send-email-maxime.coquelin@st.com> References: <1426197361-19290-1-git-send-email-maxime.coquelin@st.com> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Maxime Coquelin This patch adds clocksource support for ARMv7-M's System timer, also known as SysTick. Signed-off-by: Maxime Coquelin --- drivers/clocksource/Kconfig | 7 ++++ drivers/clocksource/Makefile | 1 + drivers/clocksource/armv7m_systick.c | 78 ++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 drivers/clocksource/armv7m_systick.c diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 1c2506f..b82e58b 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -134,6 +134,13 @@ config CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK help Use ARM global timer clock source as sched_clock +config ARMV7M_SYSTICK + bool + select CLKSRC_OF if OF + select CLKSRC_MMIO + help + This options enables support for the ARMv7M system timer unit + config ATMEL_PIT select CLKSRC_OF if OF def_bool SOC_AT91SAM9 || SOC_SAMA5 diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 752d5c7..1c9a643 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_MTK_TIMER) += mtk_timer.o obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o +obj-$(CONFIG_ARMV7M_SYSTICK) += armv7m_systick.o obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o obj-$(CONFIG_ARCH_HAS_TICK_BROADCAST) += dummy_timer.o obj-$(CONFIG_ARCH_KEYSTONE) += timer-keystone.o diff --git a/drivers/clocksource/armv7m_systick.c b/drivers/clocksource/armv7m_systick.c new file mode 100644 index 0000000..23d8249 --- /dev/null +++ b/drivers/clocksource/armv7m_systick.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) Maxime Coquelin 2015 + * Author: Maxime Coquelin + * License terms: GNU General Public License (GPL), version 2 + */ + +#include +#include +#include +#include +#include +#include +#include + +#define SYST_CSR 0x00 +#define SYST_RVR 0x04 +#define SYST_CVR 0x08 +#define SYST_CALIB 0x0c + +#define SYST_CSR_ENABLE BIT(0) + +#define SYSTICK_LOAD_RELOAD_MASK 0x00FFFFFF + +static void __init system_timer_of_register(struct device_node *np) +{ + struct clk *clk; + void __iomem *base; + u32 rate = 0; + int ret; + + base = of_iomap(np, 0); + if (!base) { + pr_warn("system-timer: invalid base address\n"); + return; + } + + clk = of_clk_get(np, 0); + if (!IS_ERR(clk)) { + ret = clk_prepare_enable(clk); + if (ret) { + clk_put(clk); + goto out_unmap; + } + + rate = clk_get_rate(clk); + } + + /* If no clock found, try to get clock-frequency property */ + if (!rate) { + ret = of_property_read_u32(np, "clock-frequency", &rate); + if (ret) + goto out_unmap; + } + + writel_relaxed(SYSTICK_LOAD_RELOAD_MASK, base + SYST_RVR); + writel_relaxed(SYST_CSR_ENABLE, base + SYST_CSR); + + ret = clocksource_mmio_init(base + SYST_CVR, "arm_system_timer", rate, + 200, 24, clocksource_mmio_readl_down); + if (ret) { + pr_err("failed to init clocksource (%d)\n", ret); + goto out_clk_disable; + } + + pr_info("ARM System timer initialized as clocksource\n"); + + return; + +out_clk_disable: + if (!IS_ERR(clk)) + clk_disable_unprepare(clk); +out_unmap: + iounmap(base); + WARN(ret, "ARM System timer register failed (%d)\n", ret); +} + +CLOCKSOURCE_OF_DECLARE(arm_systick, "arm,armv7m-systick", + system_timer_of_register);