From patchwork Wed Jun 13 11:32:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10462097 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 7085E6020A for ; Wed, 13 Jun 2018 11:47:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F57D27F97 for ; Wed, 13 Jun 2018 11:47:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 540F728511; Wed, 13 Jun 2018 11:47:46 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 F3D5A27F97 for ; Wed, 13 Jun 2018 11:47:45 +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=DeTYMNaM7teYKG5MHw3wUD+ATlFFNNmNkv5/iL65CHg=; b=naPA4V7Lvy0aPmjEY7lhh3r1+O y1AaGae1G8EBv3JA91+7ttwk54wziaOmDiKeif9vEmqPGBsjtGBXtAlHWvr4WK8uYRVPwjSi8uwsC Y392Db4QhaK84JrWLVxpI2BKpcefh2GlXv05kZLvPosfpq3nJOTTlJ34HdTZN5xUzPwi50fDMhzM1 k4Bdg14C+DuaVJMdlrigq9qtMCerIIkIEyrTQum2D7VhxtSAT4z8lGPXbn/5KypdPLt+JIlSgPyPN rJ8s79/38jkktVPSX7uSLuEapuOAJBBYgI4k1vdw4MkIX9ZJwa0FYwDNU0xrdvzVq/QFwKe6gSegJ 70Xo7ngA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fT4FY-0006fk-Rd; Wed, 13 Jun 2018 11:47:40 +0000 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fT41l-0001io-LT for linux-arm-kernel@lists.infradead.org; Wed, 13 Jun 2018 11:33:44 +0000 Received: by mail-pl0-x243.google.com with SMTP id b14-v6so1380437pls.5 for ; Wed, 13 Jun 2018 04:33:15 -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 :in-reply-to:references; bh=ChAuc8lHvl/YQvwortB1kFZ67NvvCDDalDvR66fi15s=; b=DUOpp5nAmdrtHRyQb6PaSZNfAE3m6sZnlPGP1mmIAaHXGQp0FoXsqh51Vcw28Tw5xn fG0ENvQ0ssbmVGPyGu5b9cEr2UNxsC5JIcmUEYGFN5n1bVfJIo7vMhCpV1ZKsXvMBf4f D/bTyXn2tIZVgc9tlCNd0EgRE0byK1KWocuEw= 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:in-reply-to:references; bh=ChAuc8lHvl/YQvwortB1kFZ67NvvCDDalDvR66fi15s=; b=c4MkiKn816uyddtG4izz0q9Dj+Mekr3ghfxcQ7omZADQZy49Mxw+HW+NQreAswTTy1 h8Wq8LdKe5vo7lYSvV/re7WGolQJXKnYmkQRFj0a26FbRiEvk+MVUBcW/3zmIcCiV41/ 1yETPG+huov8n4xLxbzavSMt+4IxHKina0v3uURAxbXSpuMiyYtvVP/PxE6YmF7lEhEF bu8Apo/itQ8dPLK3hd7GqakX8bvFLaKtGPUDZUyXj/uVfYHO0PGMC5iUJFB5NBAsHC7v 3fPvwXwOo+u9auIcnMoT4WiM7EEl9FQTsKBJU4FCh5A9biQymx+mp1fCBhlZuySZZzSD w8Pw== X-Gm-Message-State: APt69E0ZI9tC9mib1cthFWT4GHeWMIAW3PvemJhI0RIbKY9W7MXbU5JY RSI+6F4XBBOIbql2gWeSgYqgEA== X-Google-Smtp-Source: ADUXVKJyd2UpfyXGO955Lxj4ezEgVH7f/LyMWkVY544weQZGGStnRqbMnqyQ9Jrkuu2ugV1s1PJ/8Q== X-Received: by 2002:a17:902:1127:: with SMTP id d36-v6mr4855932pla.267.1528889594807; Wed, 13 Jun 2018 04:33:14 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id h8-v6sm2745370pgq.35.2018.06.13.04.33.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Jun 2018 04:33:14 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de, john.stultz@linaro.org, daniel.lezcano@linaro.org, arnd@arndb.de, tony@atomide.com, aaro.koskinen@iki.fi, linux@armlinux.org.uk, mark.rutland@arm.com, marc.zyngier@arm.com Subject: [PATCH 2/8] clocksource: sprd: Add one persistent timer for Spreadtrum platform Date: Wed, 13 Jun 2018 19:32:29 +0800 Message-Id: <95ec43d6f335e31d6e1da4eb0db522008728363b.1528878545.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_043325_956071_8AC059DF X-CRM114-Status: GOOD ( 12.44 ) 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: kstewart@linuxfoundation.org, alexandre.belloni@bootlin.com, heiko@sntech.de, peterz@infradead.org, viresh.kumar@linaro.org, linus.walleij@linaro.org, linux-kernel@vger.kernel.org, thierry.reding@gmail.com, hpa@zytor.com, mingo@kernel.org, x86@kernel.org, jonathanh@nvidia.com, paulmck@linux.vnet.ibm.com, len.brown@intel.com, mlichvar@redhat.com, broonie@kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, douly.fnst@cn.fujitsu.com, baolin.wang@linaro.org, gregkh@linuxfoundation.org, rdunlap@infradead.org, rajvi.jingar@intel.com, pombredanne@nexb.com 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 On Spreadtrum SC9860 platform, we need one persistent timer to calculate the suspend time to compensate the OS time. This patch registers one Spreadtrum AON timer as persistent timer, which runs at 32bit and periodic mode. Signed-off-by: Baolin Wang --- drivers/clocksource/Kconfig | 1 + drivers/clocksource/timer-sprd.c | 80 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index dec0dd8..7f11c6c 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -455,6 +455,7 @@ config SPRD_TIMER depends on (ARCH_SPRD || COMPILE_TEST) default ARCH_SPRD select TIMER_OF + select PERSISTENT_CLOCK help Enables support for the Spreadtrum timer driver. diff --git a/drivers/clocksource/timer-sprd.c b/drivers/clocksource/timer-sprd.c index ef9ebea..c6f657a 100644 --- a/drivers/clocksource/timer-sprd.c +++ b/drivers/clocksource/timer-sprd.c @@ -3,8 +3,11 @@ * Copyright (C) 2017 Spreadtrum Communications Inc. */ +#include #include #include +#include +#include #include "timer-of.h" @@ -157,3 +160,80 @@ static int __init sprd_timer_init(struct device_node *np) } TIMER_OF_DECLARE(sc9860_timer, "sprd,sc9860-timer", sprd_timer_init); + +void __iomem *pbase; + +static u64 sprd_persistent_timer_read(void) +{ + return ~(u64)readl_relaxed(pbase + TIMER_VALUE_SHDW_LO) & + CLOCKSOURCE_MASK(32); +} + +static void sprd_persistent_timer_disable(void) +{ + sprd_timer_disable(pbase); +} + +static void sprd_persistent_timer_enable(void) +{ + sprd_timer_disable(pbase); + sprd_timer_update_counter(pbase, TIMER_VALUE_LO_MASK); + sprd_timer_enable(pbase, TIMER_CTL_PERIOD_MODE); +} + +static int __init sprd_persistent_timer_init(struct device_node *np) +{ + struct clk *clk; + u32 freq; + int ret; + + clk = of_clk_get(np, 0); + if (IS_ERR(clk)) { + pr_err("Can't get timer clock for %pOF\n", np); + return PTR_ERR(clk); + } + + ret = clk_prepare_enable(clk); + if (ret) { + pr_err("Failed to enable clock for %pOF\n", np); + clk_put(clk); + return ret; + } + + freq = clk_get_rate(clk); + if (!freq) { + pr_err("Failed to get clock rate for %pOF\n", np); + ret = -EINVAL; + goto clk_rate_err; + } + + pbase = of_io_request_and_map(np, 0, of_node_full_name(np)); + if (IS_ERR(pbase)) { + pr_err("Can't map timer registers for %pOF\n", np); + ret = PTR_ERR(pbase); + goto clk_rate_err; + } + + sprd_persistent_timer_enable(); + + ret = persistent_clock_init_and_register(sprd_persistent_timer_read, + CLOCKSOURCE_MASK(32), freq, 0); + if (ret) { + pr_err("Failed to register persistent clock for %pOF\n", np); + goto persist_err; + } + + return 0; + +persist_err: + sprd_persistent_timer_disable(); + iounmap(pbase); +clk_rate_err: + clk_disable_unprepare(clk); + clk_put(clk); + + return ret; +} + +TIMER_OF_DECLARE(sc9860_persistent_timer, "sprd,sc9860-persistent-timer", + sprd_persistent_timer_init);