From patchwork Mon May 14 08:55:28 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: 135690 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1483831lji; Mon, 14 May 2018 01:56:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZolhx7HpkzxwfKcyjUOq2ZGNbe+8gbLNJa475ygNWzT7ffWUDr8d8WMCaPna3a7KqXi4Wj7 X-Received: by 2002:a17:902:8d85:: with SMTP id v5-v6mr8988263plo.93.1526288192765; Mon, 14 May 2018 01:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288192; cv=none; d=google.com; s=arc-20160816; b=nQ2Q1QWYwYNpiftFwj/HwNrKr5O3EVbw3kQedACDVdPg8w/Gw/xXgXcNw7r+RADvtt x5/BLAR01tVTfMIXXhhpUhpK/azdqh40cGzaEH/uILx98YMp6btc4b79RQQ4lBch3gu8 16tZ/uoihcrPVoPyuT9ByE9sactIrNkFhrKNHpiE3uEzEfBhUGr9jqh3FX3l0TlFuzxc H/zJog/FJpWJs7T/c/HPok0LuGtN2HgrSrp41tazZjO7wBn/9JzRre5LOATFNaB31N6A c6ZO32Sr8cEtQ08vqK3slr3/hSbbydy44T8stxsv4gPEyG+pVJWwKt1RCgC8VvPVVAyp tCFA== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=otXnHrArHRqD0yr3/v6hok4GHpBR10tlTjRkrESI19A=; b=lsRXLpcif80hwgqc+KUVyTBXrVWdg2bSSIjN1337itTaNUlA839SjIhY3NRWGu2DOr W4ZU0YpakzQ1MKWJN9UPD5uPhbm0ejsSEAed7VUmuhxabQLenDqGLVwivGRB1RJ+P0po NAa4bU2BfiB/4zk7R5KCYuvJex2DBlRghux91D/5KVFLEsOIrgwBWncq/QTG14V5q6SC Dy2ATU0bLcfxrHklgnOszQQqKID5nL7jjkPbQudzjNTrqxzxdduKmu+cGiW6t6FRgX+r WmnVoJxFg1zL5aZNqRzA9Cgp84lq08v79FNfHc29Zl5Jn3zRhLrj8rHZlpjzYKgdB6ly o0LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a56a65JF; 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 f59-v6si9464172plf.38.2018.05.14.01.56.32; Mon, 14 May 2018 01:56:32 -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=a56a65JF; 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 S1752160AbeENI4a (ORCPT + 29 others); Mon, 14 May 2018 04:56:30 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:35385 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752106AbeENI4Z (ORCPT ); Mon, 14 May 2018 04:56:25 -0400 Received: by mail-pl0-f67.google.com with SMTP id i5-v6so6977177plt.2 for ; Mon, 14 May 2018 01:56:25 -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=otXnHrArHRqD0yr3/v6hok4GHpBR10tlTjRkrESI19A=; b=a56a65JFxTN+ZV/zb7eYejlrJBN0IjaOGdyKIw6+4+mU0XuncntLzhuZ6SyFBzXoWn AXfkZgaSfAScv5um7ZT/1MO7vj1TXUzqDc/jrz2VQ85hp3i83/SZwWXjBUb/ASbc+ohZ rFd/NJYynpGSTaYC+m6kRaCvHEc75Esrw6Mxo= 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=otXnHrArHRqD0yr3/v6hok4GHpBR10tlTjRkrESI19A=; b=WZbsJtLMLeaUld+UijmkvUoklYpiiAlUSzvtqs6vsYR3O8JnOK0in2R9i39HN+zEp0 6v+FzsybDBtVzGF9vJA8xtbYXlDkWczR7FBrGSqJ6pU73NPPjitBy/X11eBvX9arD6LG 03WG/iQqf61CAuew3VtKHheVvrPwS0wfjZN2pBjT3/NMMROyPFZcZ29JEC0DEviRu+Vk DvIwq2JCCODZUwsACToMilqvCONurCpglY4UjaVxlz466L5vTd9nKDrefeinLkHmt2uH MqSUIKLzgGZCBYHZk1TZZmsPrN7J0pU+vqlznDRktN7QX/TgtcwYPIY/9ltn41v++wNt NBdA== X-Gm-Message-State: ALKqPwf6PGK4G6wiEwyNH9aSV4d+dIjN4aY9/+cSKC1oIk33a4NUHtPo KngsYHWTvmKLMJZdvZ8lKnX5Cg== X-Received: by 2002:a17:902:229:: with SMTP id 38-v6mr9002519plc.384.1526288184895; Mon, 14 May 2018 01:56:24 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id x71-v6sm23308158pfe.47.2018.05.14.01.56.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 01:56:24 -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 Cc: baolin.wang@linaro.org, broonie@kernel.org, paulmck@linux.vnet.ibm.com, mlichvar@redhat.com, rdunlap@infradead.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, thierry.reding@gmail.com, jonathanh@nvidia.com, heiko@sntech.de, linus.walleij@linaro.org, viresh.kumar@linaro.org, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, douly.fnst@cn.fujitsu.com, len.brown@intel.com, rajvi.jingar@intel.com, alexandre.belloni@bootlin.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [RFC PATCH 02/10] clocksource: sprd: Add one persistent timer for Spreadtrum platform Date: Mon, 14 May 2018 16:55:28 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) -- 1.7.9.5 diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 8e8a097..d7dddcc 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -453,6 +453,7 @@ config SPRD_TIMER bool "Spreadtrum timer driver" if COMPILE_TEST depends on HAS_IOMEM 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);