Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1225514rdb; Mon, 19 Feb 2024 08:07:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXgWHyNyF8yc/JgzhTy+3CLCNuSzRtTfhVVI2azVc/Q50hI2vPWB7J721g4n3K2UE9MhfYbeGDBDjuDXo+eVEFsw2FUhZag0DKBXCdYQA== X-Google-Smtp-Source: AGHT+IGe0YQs0gfAaSpfXp8Xr7z4ZNdqYHYwZIu9iIiBZc6LUL3yATbUhKr1nCBfD8w7oGDwHclX X-Received: by 2002:a17:906:b7d6:b0:a3e:b523:90b with SMTP id fy22-20020a170906b7d600b00a3eb523090bmr1272948ejb.14.1708358822599; Mon, 19 Feb 2024 08:07:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708358822; cv=pass; d=google.com; s=arc-20160816; b=NfPeTCdJvPIYmMbkmlw2EkvIWoiMmCwyIyC2VjwMQ/nSgl6mBYAmVQQU5L4G55GYhY p8HnSVRhqgaCkONsneP2EFRTaYt2hRsIzQm+sPadlJd+3GCEoPbmuklBWup9CxyfYvcp JuzX7FaKbsfJk6CqUiO7Gl/u2Ich0jV1sU6W6ozkxCWukpgxJ579KP+Sqsf/8lUOFF9H YCG3vAKplVqVZS/wlt9hhqMOBz70fA2zRd72XjPmuVWqzB8dhqpeJpkCmyRKVOYisNGA hmzJWArsyJS3R7Ku/xIYp7bF8ct4zYrZ1eUdR+yjXUv1sAIft3xHpzze4WT+3pR9ojQq s24A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:subject:cc:message-id:date :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=O6+K3p98rrkbJ5Yw3zsXbXs6AtGDMV+vIo5vbrjJJSM=; fh=mjp18cbNUMwYHrHF2QRhOqQK90WsB2hJWddXvah9dVE=; b=lbYc8A5dIb9Kqnk58fG73gp39fqfy/XSfq1gdZyXf2PR8Lp05EXLxC4rOGwiGQth85 nbXaC5TwC6D7rLGsDAG5rRRZP7hFiJS14SZbNK/7T1yv7U4ofLGy2vKX0tRpOQ/nrqlX aElNk8kpEJENbuOpry/aIUV+hftDeGCBH1auWsvfjwdLeOxuqLAU8qtEMLCk/BD87Lg8 6vTIa0qQI5iQIa+RVUDS9Owz4Y0uqfGjWj6AVIZhLu7uUHvikf3cVw7BshmfPAQ6syeo r/BZN3lz7hzf1cwt/4WYWHXJwOipjvgNeRn+LoRF+WkZmaD+UtFSh3Dashb1KuH/fH/p Btvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Q+mGaHHQ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-71639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71639-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ku11-20020a170907788b00b00a3e781b3c10si1279650ejc.504.2024.02.19.08.07.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 08:07:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Q+mGaHHQ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-71639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71639-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 349891F22056 for ; Mon, 19 Feb 2024 16:07:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FD192D022; Mon, 19 Feb 2024 16:06:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q+mGaHHQ" Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76BCA3308A; Mon, 19 Feb 2024 16:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708358813; cv=none; b=qjOF2N1pqy6YRhi6orxF86PCL3KLd9HjpGyQMHfXb80x0NlcXKLWyIFjFuTW3KykSN6fo5SxG3hGJhMyrZLHscNVnBfySkZUbKrLyH5FgFsBOhHuTxFSfxHxQSOE9BOHsj3PjU2kjInrx5i0yQjVc+birxRmSKVe3o8sP8FXT3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708358813; c=relaxed/simple; bh=o/Tt/aNgskIIpJbtYfiY1C/VVmJ60rm2VifCiLV87cc=; h=Content-Type:Mime-Version:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=YYDg777YoRxhxpsfOLhLBiVbXuHlxc8wmXZP07Ogud9ZSkUUUyujvXdi4iIAUk4z8jl5Dhscwkr2XK6wtoLNCeRKwbGTZaaYFwUdl2X6gr+gUTdHVG4P96dQoCcoIYpUbPSKhB4qyPCdFRDwU1vH1nDFefCj+p6ZpDKxPdyYG1A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q+mGaHHQ; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4126ada76bcso3223365e9.1; Mon, 19 Feb 2024 08:06:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708358810; x=1708963610; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=O6+K3p98rrkbJ5Yw3zsXbXs6AtGDMV+vIo5vbrjJJSM=; b=Q+mGaHHQoXC4I4wCHmVfJ0sWcEMMJp6uREVNXyBSuva7ymn5ssCJdrYzyi3DTZKzW5 CIGgtRFsyM6zsRDTEWNEUh41QSkItTDbchfJWEm3BQDHVcdMIsGJZZxu8T+/4r6v/4e6 IhRgDWJzLP1Nak2ScocNh9Tgx6rCj9EdqbO7jhx3Tw2mnhLngUr2ST/Dfmgq38kzUjto eQetmyuWXIJjO+w05WU8CY/quwyqKumSFVj3Yp2ha3SdsbGniX5xmDwa6wB34Vaf+drZ R/bbcTcNp7ZtDv86PKfQ8tnxTtINgCn/ppca1yBuWwuAV1yO82BK3Rr+SP3EhInQCp7u Quuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708358810; x=1708963610; h=in-reply-to:references:to:from:subject:cc:message-id:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O6+K3p98rrkbJ5Yw3zsXbXs6AtGDMV+vIo5vbrjJJSM=; b=aBjNVj7nKj8W4SraRekE6I/K+IXffvmUB+t97aAcdJltN0JkrDEXEcX2RMzA9F6Y5a wDWUmzTWuoMB4DrQdzcW/hNRSUWa6d6Xw/dTjaGoyNiApfijWv6cWeD7uysls/cqjMCt PII7Kce8PINsrOnDkd3XmuUpN3wQo4szQeCRQmdlNNjs4aII1W5qkE2Af6wWuubQWqoJ +u/FOAOkkrPC2xrqfby5xexHdae4bB52N/iDzjXp9zEnzjTBFX6F4bUYQE4x9LtXapz4 6ktm7l1EdBbZOOFJ+MUbvCvyGFA0ANe5EcLMuM3QenOn/3nS9XpZpzAt+LRLv0pKk7QN ntAQ== X-Forwarded-Encrypted: i=1; AJvYcCXkjF3ttnMRjhj79sV7/kYrJ0G939lPFGdKH5w9cGVc7HUoIvfmIaMCdxmNsGe1eyDcTnAECpg8W9kUuazKUldYC4UI7FAFZYyvqJju/m/eKmL8FHzxf847Qnt4+szkZJUFjGLZqR2EWoc= X-Gm-Message-State: AOJu0YzMRPLbuNKUH2Rc8VxR8pZapk4zEgiYMP7HUPf1ovD141QER/lh 0mrHri89UWf0kuF9pE2AqhcOx+9mSglF+2AXvZo9xY5y4s8w6GnG X-Received: by 2002:a05:600c:45ce:b0:412:69c6:6be9 with SMTP id s14-20020a05600c45ce00b0041269c66be9mr974948wmo.4.1708358809505; Mon, 19 Feb 2024 08:06:49 -0800 (PST) Received: from localhost (p200300e41f2d4600f22f74fffe1f3a53.dip0.t-ipconnect.de. [2003:e4:1f2d:4600:f22f:74ff:fe1f:3a53]) by smtp.gmail.com with ESMTPSA id t22-20020a7bc3d6000000b0040d5ae2906esm11691050wmj.30.2024.02.19.08.06.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Feb 2024 08:06:49 -0800 (PST) Content-Type: multipart/signed; boundary=b0da0a27ceabff049215f580b6f79f3cc323727d60ffb73d4a209fb6824b; micalg=pgp-sha256; protocol="application/pgp-signature" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Date: Mon, 19 Feb 2024 17:06:48 +0100 Message-Id: Cc: , , Subject: Re: [PATCH v2 1/2] clocksource/drivers/timer-tegra186: add WDIOC_GETTIMELEFT support From: "Thierry Reding" To: "Pohsun Su" , , , X-Mailer: aerc 0.16.0-1-0-g560d6168f0ed-dirty References: <20240216210258.24855-1-pohsuns@nvidia.com> <20240216210258.24855-2-pohsuns@nvidia.com> In-Reply-To: <20240216210258.24855-2-pohsuns@nvidia.com> --b0da0a27ceabff049215f580b6f79f3cc323727d60ffb73d4a209fb6824b Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 On Fri Feb 16, 2024 at 10:02 PM CET, Pohsun Su wrote: > This change adds support for WDIOC_GETTIMELEFT so userspace > programs can get the number of seconds before system reset by > the watchdog timer via ioctl. > > Signed-off-by: Pohsun Su > --- > drivers/clocksource/timer-tegra186.c | 44 +++++++++++++++++++++++++++- > 1 file changed, 43 insertions(+), 1 deletion(-) > > diff --git a/drivers/clocksource/timer-tegra186.c b/drivers/clocksource/t= imer-tegra186.c > index 304537dadf2c..8f516366da86 100644 > --- a/drivers/clocksource/timer-tegra186.c > +++ b/drivers/clocksource/timer-tegra186.c > @@ -1,8 +1,9 @@ > // SPDX-License-Identifier: GPL-2.0-only > /* > - * Copyright (c) 2019-2020 NVIDIA Corporation. All rights reserved. > + * Copyright (c) 2019-2024 NVIDIA Corporation. All rights reserved. > */ > =20 > +#include > #include > #include > #include > @@ -29,6 +30,7 @@ > =20 > #define TMRSR 0x004 > #define TMRSR_INTR_CLR BIT(30) > +#define TMRSR_PCV GENMASK(28, 0) > =20 > #define TMRCSSR 0x008 > #define TMRCSSR_SRC_USEC (0 << 0) > @@ -45,6 +47,9 @@ > #define WDTCR_TIMER_SOURCE_MASK 0xf > #define WDTCR_TIMER_SOURCE(x) ((x) & 0xf) > =20 > +#define WDTSR 0x004 > +#define WDTSR_CURRENT_EXPIRATION_COUNT GENMASK(14, 12) > + > #define WDTCMDR 0x008 > #define WDTCMDR_DISABLE_COUNTER BIT(1) > #define WDTCMDR_START_COUNTER BIT(0) > @@ -234,12 +239,49 @@ static int tegra186_wdt_set_timeout(struct watchdog= _device *wdd, > return 0; > } > =20 > +static unsigned int tegra186_wdt_get_timeleft(struct watchdog_device *wd= d) > +{ > + struct tegra186_wdt *wdt =3D to_tegra186_wdt(wdd); > + u32 timeleft; > + u32 expiration; > + > + if (!watchdog_active(&wdt->base)) { > + /* return zero if the watchdog timer is not activated. */ > + return 0; > + } > + > + /* > + * System power-on reset occurs on the fifth expiration of the watchdog= timer and so Is "system power-on reset" really what this is called? Power-on reset sounds like something that only happens after you power the device on, not something that can be triggered by the watchdog. > + * when the watchdog timer is configured, the actual value programmed i= nto the counter > + * is 1/5 of the timeout value. Once the counter reaches 0, expiration = count will be > + * increased by 1 and the down counter restarts. > + * Hence to get the time left before system reset we must combine 2 par= ts: > + * 1. value of the current down counter > + * 2. (number of counter expirations remaining) * (timeout/5) > + */ Can you wrap this comment so that it fits within 80 columns? It's fine to occasionally go beyond that limit if there's a good reason for it, but this comment doesn't seem to fall into that category. > + > + /* Get the current number of counter expirations. Should be a value bet= ween 0 and 4. */ > + expiration =3D FIELD_GET(WDTSR_CURRENT_EXPIRATION_COUNT, readl_relaxed(= wdt->regs + WDTSR)); > + > + /* Convert the current counter value to seconds, rounding up to the nea= rest second. */ > + timeleft =3D FIELD_GET(TMRSR_PCV, readl_relaxed(wdt->tmr->regs + TMRSR)= ); > + timeleft =3D (timeleft + USEC_PER_SEC / 2) / USEC_PER_SEC; Same for these. Maybe make an extra variable to store the register value in to get rid of some of that extra horizontal space. > + > + /* > + * Calculate the time remaining by adding the time for the counter valu= e > + * to the time of the counter expirations that remain. > + */ > + timeleft +=3D wdt->base.timeout * (4 - expiration) / 5; This doesn't quite match what the comment above says. Shouldn't this be: timeleft +=3D (wdt->base.timeout / 5) * (4 - expiration); instead? Thierry > + return timeleft; > +} > + > static const struct watchdog_ops tegra186_wdt_ops =3D { > .owner =3D THIS_MODULE, > .start =3D tegra186_wdt_start, > .stop =3D tegra186_wdt_stop, > .ping =3D tegra186_wdt_ping, > .set_timeout =3D tegra186_wdt_set_timeout, > + .get_timeleft =3D tegra186_wdt_get_timeleft, > }; > =20 > static struct tegra186_wdt *tegra186_wdt_create(struct tegra186_timer *t= egra, --b0da0a27ceabff049215f580b6f79f3cc323727d60ffb73d4a209fb6824b Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAmXTfJgACgkQ3SOs138+ s6GORA//ZiipCoOSu/wox8hsJdL/TpRaNXjRNKNMz0NErbEYulBe30SnI7eT5XTW lbTiLsc5jF+1u0PwmpYpOCpxH3iTWFbTR5GvSWE2DSjtVRkve+Laz6uYGetcip9w MdN4t53myl86ehPL9eWMJesi20aqyfRbKkLP/rG424LItSgjnAqdRNSMlnBGozBY 2CFa3GGepna7+3VSFGhHcuvslCFc9xIyg4kGcdsiAStPRtnVrx0XEW8KSUFT+u+b IjZi3w4EU3rYLCxvrrCQ8EcV0XMSQ7lmhcxFohsXK1cHx4hVtrTQ9RtXZcNQ3IZC DxfwqBDa4eeCWmek+8Y4a8jLvE32gAzPyuVrfLwCckVkmvGDicMNrt91Dtu3UABU aEsuKfM6DQJ0DXQeEqhwF3tfWSqbxIu9n0P20cBY65E/Pvu2yd+0VDW1VGUdGQba 64RHPWq/jvgQTOG+xX7S2gOjk/E/8Bnr2thKQ+eWsadU9ZMffOWFv+hyd+CfUnYk IQ6V0ZIWGf6zmvjubb1XK+UVigr8bD1CETRUF7QOkXppdlbm2+P7pACgaewdaMyY 2nDFrpCCi8jextNbkKCsMk5tI/0kAsLJBhYg48Ki2gFl4s9L4FO8927CjxaBIJXd oWJZDv766LuFtbYtvYCEXfBoqJvRWzq5v+dq5YVbl3Gp5qfJiM8= =dCoG -----END PGP SIGNATURE----- --b0da0a27ceabff049215f580b6f79f3cc323727d60ffb73d4a209fb6824b--