Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1574009yba; Tue, 2 Apr 2019 11:25:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2ZCxmZxF85Jb47QV+uceg7qat/o9rrjAuxUnA3Jc77YLmtfeUyWXP8m5bTGVAdEZUwitg X-Received: by 2002:a17:902:8d89:: with SMTP id v9mr55109712plo.230.1554229548603; Tue, 02 Apr 2019 11:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554229548; cv=none; d=google.com; s=arc-20160816; b=P22xn4Uqa16IHbMk8xUr0r34e+9ZzFSjfMbE67H1espmzWvo33dQgIDPhu9hLaO1zM 4lXBYF9amj3GV1RuEmoi6fuEsxQGihK00iRYs/4V8JEpfAmIHGhh/tZG+CYdXRCFMlq/ YIBD8yged8+Ax9dxEaR8QNiGxZdtAlEbUtJsfcHaBUStGI8s1w1OVqvw1Twt6rQ/xhrv +yrr7pWA0Jxkd0fPtvzEK2OjUfPLAMPO/biN2CW5uRqBScR5DznX+IaaaRqkU1cKSDk+ cu2MNj9lfYnUqID+dzY8AuePAaR1ECSu8ZDrpjAnJnPqdl003CuQzyCXHgb65WiOXHT0 ve8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8sihjgqoc5t6TF2f9uCFFXX89Tjhllt+FMOdISACn9Q=; b=BCyQc8b6kGxIM4HLfO4d4nKebb2xMrnvUXm9PjtTJfig+5/7Pzd7ek7bUi6Qx8LQB3 zSbbtz5fZDGr/kLpRtIMXKBD7OlpvfA0qbZ+WJ7heSwcfSSOIhE7M/tfsGBazrFIPW4z oexa7bB+2bXWnUF7/JHYOP8Y51/zKqgg5aIIrPlU+4j1kDLFbdue/fUcWGVwnRzxjYWm M1rFLPxdbQrbsm4da5x2h3uXHeKlJYQL/8nvWdvIi5kez2c7Iwpa8KzBQDiwyxUwl6Xm VfV9DzDztE6FRi6vj+10qg1tDA3j4dQQDCoTCb3MnSjZh4oGJ3kZWCMknkmIeaPLZC1j RVdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Mw6xpEkI; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s4si9433997plp.59.2019.04.02.11.25.33; Tue, 02 Apr 2019 11:25:48 -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=@gmail.com header.s=20161025 header.b=Mw6xpEkI; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731057AbfDBQtz (ORCPT + 99 others); Tue, 2 Apr 2019 12:49:55 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42494 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726314AbfDBQtz (ORCPT ); Tue, 2 Apr 2019 12:49:55 -0400 Received: by mail-wr1-f68.google.com with SMTP id g3so17538116wrx.9; Tue, 02 Apr 2019 09:49:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8sihjgqoc5t6TF2f9uCFFXX89Tjhllt+FMOdISACn9Q=; b=Mw6xpEkID9Ze8TOAfz0xNvirqWstOcMj7mGuM81cRUuXiBfomgcwTPE0DnWtt+oaST CjfaJYJ05Z9ZofjpKE3Taj+1oUfjn+yWN1bB/9rKYng9D+7RU6kfzMyr7G7w2eaVAkUR r4f/WchtLY1gTfZht5GQqh6IqCeCAEvX3JubKW7YQklgLdtmjzmAcUBHesVKNCVB3gTD 1wI31Gnq3nQCmxIhnHgJXOScWHMY7wVAHuvbZ8iYDfd/lCuVOgeVG3yw6RDgLFFPLJ87 H3ZOLUUVTqRz89kK3UA+9q1YPjoXmzBlKGl7EC5Hf/QdHqGNtXcM1tslgzRX1eGICc2K nojg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=8sihjgqoc5t6TF2f9uCFFXX89Tjhllt+FMOdISACn9Q=; b=dD4+RXkFDaSPHa+lk42nytp5Zr94YlFA4i2DxXDsNoRmiDkLrRMhhmHh0ay5rc7R2F Ff1CQUVwZ1zp1Jf0/rUaoWI7qV+fDkku/0RW+2y1eNQCXtqy/JwHSLQyogGcAUY44/i4 GHe1DgvhdQZ2rXWOvXz7gRFiG2a+Ex3QdG8TL55f7NGqabGXpyMQQPW591e5Z1VMa7Pc 4Km2ffcNI3SRb7NrIf8l6CeWxU1pMWHtGhltg9Xvq5xokm+UpjkWL5QZ/SMY58cj0hnf BPu2h/UVb6UWPwICFdSC9/VM50dJgj1Qzb/qO6oerx+kQY+1XcZWJCRabaud0HXkI1HA SBlg== X-Gm-Message-State: APjAAAX6T4n0j0Gj+rlywZaypPHif+SEJhhnFKn+PLNmQvXzY2yNWzQV 4NVZzjxphx/Noqzlj5RlMok= X-Received: by 2002:a5d:46c9:: with SMTP id g9mr2869490wrs.211.1554223792970; Tue, 02 Apr 2019 09:49:52 -0700 (PDT) Received: from localhost (pD9E51B25.dip0.t-ipconnect.de. [217.229.27.37]) by smtp.gmail.com with ESMTPSA id p3sm16978395wrx.71.2019.04.02.09.49.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 09:49:52 -0700 (PDT) Date: Tue, 2 Apr 2019 18:49:51 +0200 From: Thierry Reding To: Joseph Lo Cc: Daniel Lezcano , linux-kernel@vger.kernel.org, Jonathan Hunter , linux-tegra@vger.kernel.org, Thomas Gleixner , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] clocksource/drivers/tegra: rework for compensation of suspend time Message-ID: <20190402164951.GB7797@ulmo> References: <20190402030234.13488-1-josephl@nvidia.com> <20190402144603.GE8017@ulmo> <01028c3a-8e2e-835b-f886-ca5b85474cd2@nvidia.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1UWUbFP1cBYEclgG" Content-Disposition: inline In-Reply-To: <01028c3a-8e2e-835b-f886-ca5b85474cd2@nvidia.com> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --1UWUbFP1cBYEclgG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Apr 02, 2019 at 11:50:20PM +0800, Joseph Lo wrote: > On 4/2/19 10:46 PM, Thierry Reding wrote: > > On Tue, Apr 02, 2019 at 11:02:34AM +0800, Joseph Lo wrote: > > > Since the clocksource framework has the support for suspend time > > > compensation. Re-work the driver to use that, so we can reduce the > > > duplicate code. > > >=20 > > > Suggested-by: Daniel Lezcano > > > Signed-off-by: Joseph Lo > > > --- > > > drivers/clocksource/timer-tegra20.c | 63 +++++++++-----------------= --- > > > 1 file changed, 20 insertions(+), 43 deletions(-) > >=20 > > Nice! > >=20 > > >=20 > > > diff --git a/drivers/clocksource/timer-tegra20.c b/drivers/clocksourc= e/timer-tegra20.c > > > index fdb3d795a409..919b3568c495 100644 > > > --- a/drivers/clocksource/timer-tegra20.c > > > +++ b/drivers/clocksource/timer-tegra20.c > > > @@ -60,9 +60,6 @@ > > > static u32 usec_config; > > > static void __iomem *timer_reg_base; > > > #ifdef CONFIG_ARM > > > -static void __iomem *rtc_base; > > > -static struct timespec64 persistent_ts; > > > -static u64 persistent_ms, last_persistent_ms; > > > static struct delay_timer tegra_delay_timer; > > > #endif > > > @@ -199,40 +196,30 @@ static unsigned long tegra_delay_timer_read_cou= nter_long(void) > > > return readl(timer_reg_base + TIMERUS_CNTR_1US); > > > } > > > +static struct timer_of suspend_rtc_to =3D { > > > + .flags =3D TIMER_OF_BASE | TIMER_OF_CLOCK, > > > +}; > > > + > > > /* > > > * tegra_rtc_read - Reads the Tegra RTC registers > > > * Care must be taken that this funciton is not called while the > > > * tegra_rtc driver could be executing to avoid race conditions > > > * on the RTC shadow register > > > */ > > > -static u64 tegra_rtc_read_ms(void) > > > +static u64 tegra_rtc_read_ms(struct clocksource *cs) > > > { > > > - u32 ms =3D readl(rtc_base + RTC_MILLISECONDS); > > > - u32 s =3D readl(rtc_base + RTC_SHADOW_SECONDS); > > > + u32 ms =3D readl(timer_of_base(&suspend_rtc_to) + RTC_MILLISECONDS); > > > + u32 s =3D readl(timer_of_base(&suspend_rtc_to) + RTC_SHADOW_SECONDS= ); > > > return (u64)s * MSEC_PER_SEC + ms; > > > } > > > -/* > > > - * tegra_read_persistent_clock64 - Return time from a persistent cl= ock. > > > - * > > > - * Reads the time from a source which isn't disabled during PM, the > > > - * 32k sync timer. Convert the cycles elapsed since last read into > > > - * nsecs and adds to a monotonically increasing timespec64. > > > - * Care must be taken that this funciton is not called while the > > > - * tegra_rtc driver could be executing to avoid race conditions > > > - * on the RTC shadow register > > > - */ > > > -static void tegra_read_persistent_clock64(struct timespec64 *ts) > > > -{ > > > - u64 delta; > > > - > > > - last_persistent_ms =3D persistent_ms; > > > - persistent_ms =3D tegra_rtc_read_ms(); > > > - delta =3D persistent_ms - last_persistent_ms; > > > - > > > - timespec64_add_ns(&persistent_ts, delta * NSEC_PER_MSEC); > > > - *ts =3D persistent_ts; > > > -} > > > +static struct clocksource suspend_rtc_clocksource =3D { > > > + .name =3D "tegra_suspend_timer", > > > + .rating =3D 200, > > > + .read =3D tegra_rtc_read_ms, > > > + .mask =3D CLOCKSOURCE_MASK(32), > > > + .flags =3D CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTO= P, > > > +}; > > > #endif > > > static int tegra_timer_common_init(struct device_node *np, struct t= imer_of *to) > > > @@ -385,25 +372,15 @@ static int __init tegra_init_timer(struct devic= e_node *np) > > > static int __init tegra20_init_rtc(struct device_node *np) > > > { > > > - struct clk *clk; > > > + int ret; > > > - rtc_base =3D of_iomap(np, 0); > > > - if (!rtc_base) { > > > - pr_err("Can't map RTC registers\n"); > > > - return -ENXIO; > > > - } > > > + ret =3D timer_of_init(np, &suspend_rtc_to); > > > + if (ret) > > > + return ret; > > > - /* > > > - * rtc registers are used by read_persistent_clock, keep the rtc cl= ock > > > - * enabled > > > - */ > > > - clk =3D of_clk_get(np, 0); > > > - if (IS_ERR(clk)) > > > - pr_warn("Unable to get rtc-tegra clock\n"); > > > - else > > > - clk_prepare_enable(clk); > > > + clocksource_register_hz(&suspend_rtc_clocksource, 1000); > > > - return register_persistent_clock(tegra_read_persistent_clock64); > > > + return 0; > > > } > > > TIMER_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rt= c); > > > #endif > >=20 > > I wonder if there's any reason left for the #ifdefs now. My recollection > > is that these were only needed because register_persistent_clock() was > > not available on 64-bit ARM. The new APIs seem to be available > > regardless of architecture, so do we still need to differentiate? > >=20 >=20 > Actually, only Tegra20/30 that doesn't have ARM arch timer support need > this. The latter Tegra chips which have ARM arch timer support use TSC ( > time stamp counter or timer system counter depends on the chip it has > different name) as the timer source in the PMC. And it uses OSC during > runtime and switches to 32KHz always-on clock source to keep counting when > the chip is in the SC7 or LP0 state. >=20 > So I didn't change that for this reason. Okay, looks good then. Acked-by: Thierry Reding --1UWUbFP1cBYEclgG Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAlyjkq8ACgkQ3SOs138+ s6Hysg//b9UgRbVlTL6mp0e8viRfpi09fLqkEMjeDRQaqZGdh+Kcau/GJuX+OJCp PANjwQwYPYzZfP35IDT6Cc7Xvfct21ILCwKpfy8YustzIqHPdeBhvTzTm1gcf3JO YeqTX6lXBkhsUlVRMj1+EpQoAKCLD2+95CrIq73uCCJgRp7+TuwDkzP/SD/PbPHa GNquSSA2s8gUrrUr7eEA/Iy2WifrHd9s49M5agKrpv7kDcLKUmT6Ne9WOBBNrVBM BV4cDafnRtNbaLXpu0d0Dy5p3i/+Vov43/dErt0/cLodHVDagyv0jfVTsue1zeqK MsBP1R8QCKu2N/mdlEXvj/SEAKMqmKS+1ULHHBUbSe/HZ1lBkQIzTQ2iyCZ9aWXu eDo6N4H1jkiRyvDpuZoCTM9gbpn6SsU0d9roLWU7p9EtgDY0SlHlEFh2k21MBdYs wUAkUtvxGXISyYR7EeYVyrXnkrp08w5biPHO8AzdiMT3HciH6C9Gadlj5aClFReN ZmPO+PYEAVQW+EVaKkrM3E3a3nr2CKchmr7nzgqK/3fOq3A65hCotnIMMctMFBfO oee3GSoi0zZtSEd2b+E0vXGWk+BTXGWPboFvgkZI3yNEcUqYsqRlW5Xq5+gmYr98 Db0YEtoYBgvuk7LPouMzCb2hjmF8CZQplzAp4RUO7cTAlWDlP3o= =d9bl -----END PGP SIGNATURE----- --1UWUbFP1cBYEclgG--