From patchwork Tue May 20 20:01:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Charkov X-Patchwork-Id: 891885 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 A23062857C5; Tue, 20 May 2025 20:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747771329; cv=none; b=UG42xHcMw5vMMpoXnVT+w4DdFCCE3UhHpi42ZdPyDLfchEtUIuQbjeyNhZlX/3Uxn5nt/mMX2b+HgiPRLH8ZCnFBPO2YgrTJY3YImxBQyDtJGKHMrsRmMHxmo/ry8rC9w1i04YZEXBVMoYko8G1VDaQoYhQEm54LMvLpW+ikMMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747771329; c=relaxed/simple; bh=qFsMhUVZOqzuNFYPlJDTF3BR26c7gUmeV5+bIDXnEJ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ra1UfAkq62vXHcQW6EFWobAzLL5iBzAfQGnBNz4L/QjIlvRySRji90GGHb3RqzhSJvRrN964E+CYjrzOLAmTl9IrQlqrrvY8PaA1wTuhdePtiBDft4tk9cOzmxcyrL6Q7igPGGs9zG09zUjbPg2g4xf15xUBkUAVtSohHpW9e8I= 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=ezpJvUp5; arc=none smtp.client-ip=209.85.210.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ezpJvUp5" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7399a2dc13fso7618063b3a.2; Tue, 20 May 2025 13:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747771326; x=1748376126; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Gxfsw6I6YYTP0VMGydqnNXEY5NLxoTpA+PjreYTGiOE=; b=ezpJvUp5juIr81oOiNXbnrFgCZwOn9PXVpPmtE/GAyygtvqJfLoKOF+gA9RhhoPTrF XA9SJPFnnHj05RqtWCH/wYbskV/NL664WhrCVEOwKxpQg3W0765AcPO0C2c2vH7Alu5C oKyfhJIOBm0ns7bMj7Pc/7oaRq9ZiK3RPkBIgeMREsaUiUczqHWCI8ePgad6G8SnbyV8 EkVzES9h/TfGwI5ddupd7LNWf1muE/vKUuhSsdq/XzP+UoBX1TrI/dqj2L3XAX5FXth4 7/blT7st7FWyxqKjC6t8+Rf3euNFP3o4YUIDMv5vJgjTgBSIHIONt+prBUgsV7Wjy0WD 0vPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747771326; x=1748376126; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gxfsw6I6YYTP0VMGydqnNXEY5NLxoTpA+PjreYTGiOE=; b=rq8I9+XbjNabrUFYGwiq7Fhuu3yzNBr/1LpxLMK0HRGTvbB/TGWnUPaBSN0SVDyWiM Ql6iqgo6uZO2XY9ZfMg4atwp4KG/D5Ye89V02jSSOtWd3r6wiHDRxiTsDwvm0uEcv7vN TfOCnHiQPlwElwhkti7/o19zKGbnNh0YtrMLHVpN+BT9ud57SJU7qNCFrgmkmskmlEjx kRoe9CnBaLnHYgyglSaVHrPdS1FnDQqoSvp0HC1aEZLZ9hgugye/M4Qjj3H9Fi53I5XO cQpar7aFokvtVB0/KNW5DSkwJefwOMBp/Xwf22KmbMh4gvmHA/3DXPZF3pEvDSnfUYpD S0gw== X-Forwarded-Encrypted: i=1; AJvYcCWEvgB6BjrmmYa+1rOZU14VOoWHLxJxg/FwFD7I8jlnqMYQqoV8cbdXQ3AjT81ha2rz6tGkx7QrmZco@vger.kernel.org, AJvYcCWGIDFi4+Db9/R1G6e2KBxWCZHGp1yW/sRzd0UCJ8jTRMo27mgsjPmdnn7MaUwDQBFU40346QoNpZOvYyzwTdU=@vger.kernel.org, AJvYcCWQEuwyIp2Z21BkDIknxXxanwWthb9HTEaXWpC89OypwetQOnLwcAE4fkf0pwJZ9e94m/We5IPNw2SXn7CV@vger.kernel.org X-Gm-Message-State: AOJu0YwY5K2S3CMIwIPdHFQCCgq77M9Y87NU/K7R0yl3/tKQ2GSpKnQq /uNfN9XsxqEIA7jxNkbK/11DzucURUIpaOwrBbzynM4U7LhjrwLbPVrPXGxuB2YwqbI= X-Gm-Gg: ASbGncsAOY3a0WSzmUB1fWTS2VU6Cnmu7nkFc9kLWcnhcRkqGiWEmTO6huM2wRHzWRs qm4F5FDMGO1YYRsIwjm33joDD7YcRGOl9fo1W8uwwOK1JxIlWFA+fI9UUsKAyHRMnj2+LjhKcfS YPztmt4dh8R2UvFH2aHq2rPdkV5M6/SiXWej9aqmCEaRBWneaF/AEbVcDemlJ8PVS5/0eBnM4fa 2CANgmu6M55V2aSu7OOqcpCQKO7NXmaCYCg9Srqc4SYj67QvFGnDgYQiLBvp0VTmLEE2CTjOP/Q 0aICfZRpqzWS+SYJ7U+ymPqpgE5hfSjeK+QFQFfPIjCF/1V5dkLOHl1VbseqA8A= X-Google-Smtp-Source: AGHT+IGupbKGW386mhivPJAiIzzStBvVkq8NfXE2ktxMR1iGMRXrHF0+aT/Q9O1XVoEce0sp1CdPLw== X-Received: by 2002:a05:6a20:a129:b0:1f5:8e54:9f10 with SMTP id adf61e73a8af0-2170cde51b5mr31255972637.34.1747771326368; Tue, 20 May 2025 13:02:06 -0700 (PDT) Received: from NB-GIGA003.letovo.school ([5.194.95.139]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b26eaf5a0d0sm8412340a12.14.2025.05.20.13.01.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 13:02:06 -0700 (PDT) From: Alexey Charkov Date: Wed, 21 May 2025 00:01:41 +0400 Subject: [PATCH v4 1/4] dt-bindings: timer: via,vt8500-timer: Convert to YAML Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250521-vt8500-timer-updates-v4-1-2d4306a16ae4@gmail.com> References: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com> In-Reply-To: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com> To: Krzysztof Kozlowski , Daniel Lezcano , Thomas Gleixner , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Wim Van Sebroeck , Guenter Roeck Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-watchdog@vger.kernel.org, Alexey Charkov X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747771315; l=3775; i=alchark@gmail.com; s=20250416; h=from:subject:message-id; bh=qFsMhUVZOqzuNFYPlJDTF3BR26c7gUmeV5+bIDXnEJ4=; b=M5hJXbl/goJAem+GG1Z//IC/PZa2E1v3pqaTFzunJwsYFk02s0669dI6dFxu7ArHDcdsFQ+XZ c1xPI7+iLrABoRq+wo+hj6OWQt3O3XUvxk0xjpnZ8JzblWq7XtYOlJk X-Developer-Key: i=alchark@gmail.com; a=ed25519; pk=ltKbQzKLTJPiDgPtcHxdo+dzFthCCMtC3V9qf7+0rkc= Rewrite the textual description for the VIA/WonderMedia timer as YAML schema. The IP can generate up to four interrupts from four respective match registers, so reflect that in the schema. Reviewed-by: Rob Herring (Arm) Signed-off-by: Alexey Charkov --- .../devicetree/bindings/timer/via,vt8500-timer.txt | 15 ------- .../bindings/timer/via,vt8500-timer.yaml | 51 ++++++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/Documentation/devicetree/bindings/timer/via,vt8500-timer.txt b/Documentation/devicetree/bindings/timer/via,vt8500-timer.txt deleted file mode 100644 index 901c73f0d8ef05fb54d517b807d04f80eef2e736..0000000000000000000000000000000000000000 --- a/Documentation/devicetree/bindings/timer/via,vt8500-timer.txt +++ /dev/null @@ -1,15 +0,0 @@ -VIA/Wondermedia VT8500 Timer ------------------------------------------------------ - -Required properties: -- compatible : "via,vt8500-timer" -- reg : Should contain 1 register ranges(address and length) -- interrupts : interrupt for the timer - -Example: - - timer@d8130100 { - compatible = "via,vt8500-timer"; - reg = <0xd8130100 0x28>; - interrupts = <36>; - }; diff --git a/Documentation/devicetree/bindings/timer/via,vt8500-timer.yaml b/Documentation/devicetree/bindings/timer/via,vt8500-timer.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e748149948f3140d4a158f800b91e70bf9c4f042 --- /dev/null +++ b/Documentation/devicetree/bindings/timer/via,vt8500-timer.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/timer/via,vt8500-timer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: VIA/Wondermedia VT8500 Timer + +description: + This is the timer block that is a standalone part of the system power + management controller on VIA/WonderMedia SoCs (VIA VT8500 and alike). + The hardware has a single 32-bit counter running at 3 MHz and four match + registers, each of which is associated with a dedicated match interrupt, + and the first of which can also serve as the system watchdog (if the + watchdog function is enabled, it will reset the system upon match instead + of triggering its respective interrupt) + +maintainers: + - Alexey Charkov + +properties: + compatible: + const: via,vt8500-timer + + reg: + maxItems: 1 + + interrupts: + minItems: 1 + items: + - description: Channel 0 match. Note that if the watchdog function + is enabled, this interrupt will not fire and the system will + reboot instead once the counter reaches match register 0 value + - description: Channel 1 match + - description: Channel 2 match + - description: Channel 3 match + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + timer@d8130100 { + compatible = "via,vt8500-timer"; + reg = <0xd8130100 0x28>; + interrupts = <36>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 3563492e4eba48b9e9389687fc9ac2a881c47ddf..783e5ee6854b69cca87b6f0763844d28b4b2213f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3435,6 +3435,7 @@ M: Krzysztof Kozlowski L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) S: Odd Fixes F: Documentation/devicetree/bindings/i2c/i2c-wmt.txt +F: Documentation/devicetree/bindings/timer/via,vt8500-timer.yaml F: arch/arm/boot/dts/vt8500/ F: arch/arm/mach-vt8500/ F: drivers/clocksource/timer-vt8500.c From patchwork Tue May 20 20:01:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Charkov X-Patchwork-Id: 891512 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 4A25727EC98; Tue, 20 May 2025 20:02:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747771338; cv=none; b=FVKnB0Sxp9c5s6daZ6SzDyAVlaBKMkPuEH+P9O1V7cC2xX/3jocNgfYHdhxaKQE/u7hsC/DPA37PciTDJW14FKfPeeNr3rl5ZJhZLSC4JwkADwsI1jrvyOM2nuP29DdSUns2GwmOSpT/HOzptZcyhebFl5w/d8lITsmqn/KcGzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747771338; c=relaxed/simple; bh=4CyYsnhnKma2xppJbhsHsOk6fmvNYSaorpOr7AaIMyg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X+5IZo04tXAhbYcPQYR5VfQ2ZEmydb4HaALRgf3OD9uVAvoBaTW+1ExKRnYE0tofzTVThQ9jP+kTfnK8770dDqpI+tCutK1w9QUpH/o+0/CkmUoYKP7NWgltwkcb0Oyq3fVyJ/DVUEaIfNs0J78fQJRmLaYTgd5kHy7ZuHYoWQU= 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=WgJvUAcG; arc=none smtp.client-ip=209.85.210.178 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WgJvUAcG" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-74267c68c11so5262756b3a.0; Tue, 20 May 2025 13:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747771336; x=1748376136; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=K/YRE9eWWpFH2r4v7/hrx7dmjRCdICuJbKw6jMjRMZw=; b=WgJvUAcGfQaeKfMDAsvBplOu9tZVUj3UrnarowRJpZE8LgWcDtpkWSfdF55gLileib QrIdz/WwoFaxUVBaRBHmBHSAlk4lS2eCeCsm1/5vH5jEhe4TNLFXbCgFNPajkVE1cqG7 VkDXTVGX2pPXISXYmdvV2DBMkLQijlxBi7/z8zyZabecYVVBFwQZvrKrQJvtRZSe9HiS YGiFxhoZFt3GNYxHjhOeolf2HiuJrAvj5/WSb50Gd9Sd9oOvSOjmDg3W+Oc6EbXv3oJf sncsLMpwWt4YJRIHyV4p0O04zoWTv7fy2UOnF2NkJEsHyxgdj5FqHs80lZQ3MsLBQc4j xweg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747771336; x=1748376136; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K/YRE9eWWpFH2r4v7/hrx7dmjRCdICuJbKw6jMjRMZw=; b=ISXt3Q/x6Pb9aQ0Y8Mw/9apqZpz3y3JRs6ucNXMlfMankYb07qTxZVYdKIbU59S0wY jPJsDepskDb37LgY+/xz8ICWrWuYKXrQGRipWvjned6qfxgtROvktwzQQY4Z9HTKOMar DqHn4FQh1+kRItus3xqynjtFryXIsaZzALnYeF2o9B7oxrBHqn7ASVhOzWOGc5DRcRGh 6S9hlNxt79kuKZ+L1AWFNFSBj89S3hD9r+Xr8mVZJhKmO/EoEgLQ8u4/4QrUE7qf0YdW rSTBKlFKpYusrzgbFJpo+g6g3XH2Qto57jZZLkvpsWS64LeWJgx/4rfzlx+PiAJgjBrv lvYA== X-Forwarded-Encrypted: i=1; AJvYcCUPajLhY6GngarJflxfglIAIQRca689XYcuJlCXCeN3ZnmO3GTNkJHhEU7jtCdSfIbfvEDwdrRETbkzsDYIxRE=@vger.kernel.org, AJvYcCUXUGtL4w2/YV40vvUMctbRTqyI0W9v5xvGb+uhGWOOz3MDuBBplHs4+9n9boUiXLInsNNlOCYagNA95r4/@vger.kernel.org, AJvYcCVNuICEtVGYk0TY6/3BXiL47vOt7fJv70+bfs4uJYDQogMHc2ELZuZ2kTctu8/bbIopO+eSWEsgGqDa@vger.kernel.org X-Gm-Message-State: AOJu0YxK6fzRSHzHE3WCDAN3mv8kfdnrB3blJlW2fWCYIHzl5fLzXn6I s10caTp6VddX6OtOyiYrX6taX65qj/okPNcH7A2mpSwnPXYqAQDxoqEpRWns/XmGLm8= X-Gm-Gg: ASbGncsKH5wvoCU5y06AQGCWNPakmLGTzPZBiNoZ7mLgfSDr/yV7ifSAGEVo21PuxfU pWdXxHOmzRQrFHq/h2Nw6rdBqfCqpxvL5mXjOA4saoVtL6htnhEf+Wizt4yp9ibHLmgcjSexFiL 99lfz90K3n9FL5t6n5AJukGRD4aVJ/GO+7HFOvkz3fWt314zJhStQ76JFpiI6mz59P1+1m5tnq8 OO83pt43FKwNijRfkOgbjb45DixTOiTWM8BXHNEeu3B/BF9YiPjRzRUJqqeEneom/BHr4h/Yj5x P1nU+eg7+b/RarARbOQeg0jqQEPApa03aFZRwM10zIjn3S/74wYZiqCl9cOzSqqkZkd7B3r8Pg= = X-Google-Smtp-Source: AGHT+IHbuXHg/W6vSnqxmLG1ArO4kGbvEMiBikDCtc9Lx0vI8sgYtzMvJhfgnt11IeXH89wjamvdZw== X-Received: by 2002:a05:6a21:1807:b0:203:becd:f9ce with SMTP id adf61e73a8af0-2170ce3a504mr24910455637.39.1747771336150; Tue, 20 May 2025 13:02:16 -0700 (PDT) Received: from NB-GIGA003.letovo.school ([5.194.95.139]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b26eaf5a0d0sm8412340a12.14.2025.05.20.13.02.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 13:02:15 -0700 (PDT) From: Alexey Charkov Date: Wed, 21 May 2025 00:01:42 +0400 Subject: [PATCH v4 2/4] clocksource/drivers/timer-vt8500: Add defines for magic constants Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250521-vt8500-timer-updates-v4-2-2d4306a16ae4@gmail.com> References: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com> In-Reply-To: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com> To: Krzysztof Kozlowski , Daniel Lezcano , Thomas Gleixner , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Wim Van Sebroeck , Guenter Roeck Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-watchdog@vger.kernel.org, Alexey Charkov X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747771315; l=4723; i=alchark@gmail.com; s=20250416; h=from:subject:message-id; bh=4CyYsnhnKma2xppJbhsHsOk6fmvNYSaorpOr7AaIMyg=; b=AUuQnvbMDrfd8awkB3JMwlMLN9vm/FLiD+sdVZUb6xH9xoS1U1VL883Aoif/LNQPN3hW7AWAi ydT1S7bhS8CBszZsQt/uWDV5nxhBwd7Gd9dchd8CIXQJdq9qFKnyrHo X-Developer-Key: i=alchark@gmail.com; a=ed25519; pk=ltKbQzKLTJPiDgPtcHxdo+dzFthCCMtC3V9qf7+0rkc= Add defines for all known registers and their bits to make the code more self-explanatory. While at that, replace _VAL suffixes with more intuitive _REG suffixes on register offsets. No functional changes. Signed-off-by: Alexey Charkov --- drivers/clocksource/timer-vt8500.c | 65 ++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/drivers/clocksource/timer-vt8500.c b/drivers/clocksource/timer-vt8500.c index a469b1b5f97233202bf01298b9f612e07026c20c..9f28f30dcaf83ab4e9c89952175b0d4c75bd6b40 100644 --- a/drivers/clocksource/timer-vt8500.c +++ b/drivers/clocksource/timer-vt8500.c @@ -24,15 +24,31 @@ #define VT8500_TIMER_OFFSET 0x0100 #define VT8500_TIMER_HZ 3000000 -#define TIMER_MATCH_VAL 0x0000 -#define TIMER_COUNT_VAL 0x0010 -#define TIMER_STATUS_VAL 0x0014 -#define TIMER_IER_VAL 0x001c /* interrupt enable */ -#define TIMER_CTRL_VAL 0x0020 -#define TIMER_AS_VAL 0x0024 /* access status */ -#define TIMER_COUNT_R_ACTIVE (1 << 5) /* not ready for read */ -#define TIMER_COUNT_W_ACTIVE (1 << 4) /* not ready for write */ -#define TIMER_MATCH_W_ACTIVE (1 << 0) /* not ready for write */ + +#define TIMER_MATCH_REG(x) (4 * (x)) +#define TIMER_COUNT_REG 0x0010 /* clocksource counter */ + +#define TIMER_STATUS_REG 0x0014 +#define TIMER_STATUS_MATCH(x) BIT((x)) +#define TIMER_STATUS_CLEARALL (TIMER_STATUS_MATCH(0) | \ + TIMER_STATUS_MATCH(1) | \ + TIMER_STATUS_MATCH(2) | \ + TIMER_STATUS_MATCH(3)) + +#define TIMER_WATCHDOG_EN_REG 0x0018 +#define TIMER_WD_EN BIT(0) + +#define TIMER_INT_EN_REG 0x001c /* interrupt enable */ +#define TIMER_INT_EN_MATCH(x) BIT((x)) + +#define TIMER_CTRL_REG 0x0020 +#define TIMER_CTRL_ENABLE BIT(0) /* enable clocksource counter */ +#define TIMER_CTRL_RD_REQ BIT(1) /* request counter read */ + +#define TIMER_ACC_STS_REG 0x0024 /* access status */ +#define TIMER_ACC_WR_MATCH(x) BIT((x)) /* writing Match (x) value */ +#define TIMER_ACC_WR_COUNTER BIT(4) /* writing clocksource counter */ +#define TIMER_ACC_RD_COUNTER BIT(5) /* reading clocksource counter */ #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) @@ -43,11 +59,12 @@ static void __iomem *regbase; static u64 vt8500_timer_read(struct clocksource *cs) { int loops = msecs_to_loops(10); - writel(3, regbase + TIMER_CTRL_VAL); - while ((readl((regbase + TIMER_AS_VAL)) & TIMER_COUNT_R_ACTIVE) - && --loops) + + writel(TIMER_CTRL_ENABLE | TIMER_CTRL_RD_REQ, regbase + TIMER_CTRL_REG); + while (readl(regbase + TIMER_ACC_STS_REG) & TIMER_ACC_RD_COUNTER + && --loops) cpu_relax(); - return readl(regbase + TIMER_COUNT_VAL); + return readl(regbase + TIMER_COUNT_REG); } static struct clocksource clocksource = { @@ -63,23 +80,25 @@ static int vt8500_timer_set_next_event(unsigned long cycles, { int loops = msecs_to_loops(10); u64 alarm = clocksource.read(&clocksource) + cycles; - while ((readl(regbase + TIMER_AS_VAL) & TIMER_MATCH_W_ACTIVE) - && --loops) + + while (readl(regbase + TIMER_ACC_STS_REG) & TIMER_ACC_WR_MATCH(0) + && --loops) cpu_relax(); - writel((unsigned long)alarm, regbase + TIMER_MATCH_VAL); + writel((unsigned long)alarm, regbase + TIMER_MATCH_REG(0)); if ((signed)(alarm - clocksource.read(&clocksource)) <= MIN_OSCR_DELTA) return -ETIME; - writel(1, regbase + TIMER_IER_VAL); + writel(TIMER_INT_EN_MATCH(0), regbase + TIMER_INT_EN_REG); return 0; } static int vt8500_shutdown(struct clock_event_device *evt) { - writel(readl(regbase + TIMER_CTRL_VAL) | 1, regbase + TIMER_CTRL_VAL); - writel(0, regbase + TIMER_IER_VAL); + writel(readl(regbase + TIMER_CTRL_REG) | TIMER_CTRL_ENABLE, + regbase + TIMER_CTRL_REG); + writel(0, regbase + TIMER_INT_EN_REG); return 0; } @@ -95,7 +114,7 @@ static struct clock_event_device clockevent = { static irqreturn_t vt8500_timer_interrupt(int irq, void *dev_id) { struct clock_event_device *evt = dev_id; - writel(0xf, regbase + TIMER_STATUS_VAL); + writel(TIMER_STATUS_CLEARALL, regbase + TIMER_STATUS_REG); evt->event_handler(evt); return IRQ_HANDLED; @@ -119,9 +138,9 @@ static int __init vt8500_timer_init(struct device_node *np) return -EINVAL; } - writel(1, regbase + TIMER_CTRL_VAL); - writel(0xf, regbase + TIMER_STATUS_VAL); - writel(~0, regbase + TIMER_MATCH_VAL); + writel(TIMER_CTRL_ENABLE, regbase + TIMER_CTRL_REG); + writel(TIMER_STATUS_CLEARALL, regbase + TIMER_STATUS_REG); + writel(~0, regbase + TIMER_MATCH_REG(0)); ret = clocksource_register_hz(&clocksource, VT8500_TIMER_HZ); if (ret) { From patchwork Tue May 20 20:01:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Charkov X-Patchwork-Id: 891884 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 F2F9B2882D5; Tue, 20 May 2025 20:02:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747771348; cv=none; b=ELvQU+OPR7NBKE9ZDH01v1PQi1d2P/AByjhHGdLuL0fCEzGMmTbxcZl8xpacbNFE6Kk7gImJkLCbeqqM8EJXxyXgKCJZZ1wCAVtFZ+rFIi+CFr+p6b934x9W/EDUdajJia2fBM1mXjtZBEA+d6wusL8PQORuK78dHYEueXhHRtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747771348; c=relaxed/simple; bh=4Tq1P5wMAyzNhGs6OsPD/EAgY3O3LxnsxawhPzisegU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p3Wo9rdZoVnco/UPqFiRN9mAo9fyzzTqkRFO5mEyurw6UW9ILZ+XaRZS3BIkf/V53ZFILanaKqKAqqvcp/WWsj/WjFKD4maH78ztn4pydqt4wL+xpihVzqnRgKh9o0ypSmZNg9aTyf25i0bVKuAz5hEIQWkb0k8ceAUqaRLMIKk= 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=EG7ZmRIb; arc=none smtp.client-ip=209.85.210.182 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EG7ZmRIb" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-742c2ed0fe1so3512305b3a.1; Tue, 20 May 2025 13:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747771346; x=1748376146; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EVj4QdpKyJy1TysJDpfKSHEayttC0HkOKItZdYkWES8=; b=EG7ZmRIbUWmnEa5fR0SOj0qDDrVUZn1e/QQ92ykgKE2PpoX6VVFBmJCHpuapaKqXD2 RUj3jHscTbe6FavARstD3wO12TpnW6gGnXBc/hVDBV4pPk7U7SzSMBHJaPHOpZtCIBH0 H1ep5y4lfagORfYHu+uX7klgdqdDhcnWyV5MnirdT7VOCAU/3NKr0fsWkgpp/BIPoQaH 7RFonklpake7jFh9n80xCpjZk7G80KhWxsq3RtmDtx5WPPF8fBku1PIfUxDyW2rkeOe0 7JtfZJVTlm21LhJU6js+NrXfydmnUJKCdiHl1+U/oq7M4ky8zCR27Cdhbgg4TOnI4g+f 8krw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747771346; x=1748376146; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EVj4QdpKyJy1TysJDpfKSHEayttC0HkOKItZdYkWES8=; b=gePVqZvAmM3UQemn0UAHMJJeKjC0rtS3ltSELQbbeDbXjgS/6NOsynVfxnY+NDVtYE H2TRVylZEiCgNqDyk+Dz/NRtbLyaPBFPpuKkgEODgyrXrE0xMdP+B9Y48RN31BtN4sVg m4kv5Mlzcu4WBfwkKFc621LVYerbHojMhtPJ7mq15uaqBYXRqtOCkS0BqReKZe+4Auz7 3ofmYueh1uUYm89da3DLk5x1ZGnT0PloxJl5gMDfFoBcnCEPtpVvryFhem7W3m9EBaD9 zuLp5MY0dxbz973IBbd/CBoJwuMIypRHnSTOtoVzQ+gqHSq00XJF3ogLRpbvUc1fNe+T Ci1A== X-Forwarded-Encrypted: i=1; AJvYcCUNsOZR++NdRQdErv+cocwAgmr4+BtcAzcum3LSjsfTqWubbE7qiE1L1/Q3E3Lzf0bboDb/OQwMUXAt@vger.kernel.org, AJvYcCVZhR26NEUWkoiR3tj6SrADLMR04Mr/7ZUB6B9SCvf4dYoOxGjDk9l4oLRhhxbNex1ivqtsS95mjYbfh9Da@vger.kernel.org, AJvYcCVlg1u/ttTvQMBh7ZbLNYqrFwR+q4YZz246q9W9a1VIU9lSno1+vl10tyBHjrW7i/Et79RXs0NzziM4Zi76qBM=@vger.kernel.org X-Gm-Message-State: AOJu0YzjOyHXzrKPh6CS9UFgADCbwKMTAkwfXN8wx3glFd8nj9Y6chz7 NtshdwBGymQjdMax4ERUiBk9XyGwdpNiABjBJ5ntHRF8AWjQvHdBPhbbsxb5yPJTyN8= X-Gm-Gg: ASbGncsj/P+ZCAKb+Trqeu3uUNMjBaKgWBmftckSKYyOCJRsR3X25vRPwP9314WrZC1 nodsrzey+sNzPjeXWdNMvbkFar9bVo8wPjilYKmNaDvK5w+ZzPmqgpe6ErLdL0r9+z1y/dyGGot UgkOS+0XHiDgT5Azhk+yZjdyy5Wa+L8MuHtQk6FLNhv9vM2Domjm4SAqY0r7di/O5bpzk+kIWSN 44mO4w1Ua333vxJybVbKhB5OLGFHGlIq+zj3eeo3khUKquNqdZ9dqxyzgA3V6zyRIO/4ll5RILw uwJBnJTOcuQfETxLJGHlvG3bbhlhVx3pDtcU51rOIAZD8ia9Y9pcil6Wof6oWzA= X-Google-Smtp-Source: AGHT+IHawJXBy+wXx8lstzqPJ4hjRI0aRBTMUAoi7fZ7uwVulgJmYoOmNI0Nfk2+Fj+HzTGI99vvJA== X-Received: by 2002:a05:6a20:881:b0:215:eafc:abda with SMTP id adf61e73a8af0-216218a2ddemr19786796637.18.1747771345791; Tue, 20 May 2025 13:02:25 -0700 (PDT) Received: from NB-GIGA003.letovo.school ([5.194.95.139]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b26eaf5a0d0sm8412340a12.14.2025.05.20.13.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 13:02:25 -0700 (PDT) From: Alexey Charkov Date: Wed, 21 May 2025 00:01:43 +0400 Subject: [PATCH v4 3/4] clocksource/drivers/timer-vt8500: Prepare for watchdog functionality Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250521-vt8500-timer-updates-v4-3-2d4306a16ae4@gmail.com> References: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com> In-Reply-To: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com> To: Krzysztof Kozlowski , Daniel Lezcano , Thomas Gleixner , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Wim Van Sebroeck , Guenter Roeck Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-watchdog@vger.kernel.org, Alexey Charkov X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747771315; l=9776; i=alchark@gmail.com; s=20250416; h=from:subject:message-id; bh=4Tq1P5wMAyzNhGs6OsPD/EAgY3O3LxnsxawhPzisegU=; b=uwtxTk93WEH7YrvWVoi9J9CaR1kb87nXPsGnRmAIu+AWAHsg+jnclK3pyXQr+Pj2ccGqeRJga 21uRFgu8JIqCszMuFcJbwHyZY4C/9wOm2xrCdxNCADnB918wDTeRRQ2 X-Developer-Key: i=alchark@gmail.com; a=ed25519; pk=ltKbQzKLTJPiDgPtcHxdo+dzFthCCMtC3V9qf7+0rkc= VIA/WonderMedia system timer can generate a watchdog reset when its clocksource counter matches the value in the match register 0 and watchdog function is enabled. For this to work, obvously the clock event device must use a different match register (1~3) and respective interrupt. Check if at least two interrupts are provided by the device tree, then use match register 1 for system clock events and reserve match register 0 for the watchdog. Instantiate an auxiliary device for the watchdog Signed-off-by: Alexey Charkov --- MAINTAINERS | 1 + drivers/clocksource/Kconfig | 1 + drivers/clocksource/timer-vt8500.c | 141 +++++++++++++++++++++++++++---------- include/linux/vt8500-timer.h | 48 +++++++++++++ 4 files changed, 152 insertions(+), 39 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 783e5ee6854b69cca87b6f0763844d28b4b2213f..5362095240627f613638197fda275db6edc16cf7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3447,6 +3447,7 @@ F: drivers/tty/serial/vt8500_serial.c F: drivers/video/fbdev/vt8500lcdfb.* F: drivers/video/fbdev/wm8505fb* F: drivers/video/fbdev/wmt_ge_rops.* +F: include/linux/vt8500-timer.h ARM/ZYNQ ARCHITECTURE M: Michal Simek diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 487c8525996724fbf9c6e9726dabb478d86513b9..92f071aade10b7c0f0bba4b47dc6228a5e50360f 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -178,6 +178,7 @@ config TEGRA186_TIMER config VT8500_TIMER bool "VT8500 timer driver" if COMPILE_TEST depends on HAS_IOMEM + select AUXILIARY_BUS help Enables support for the VT8500 driver. diff --git a/drivers/clocksource/timer-vt8500.c b/drivers/clocksource/timer-vt8500.c index 9f28f30dcaf83ab4e9c89952175b0d4c75bd6b40..91ebb63e14a85ba34c09f89855b4d5f3f9585d03 100644 --- a/drivers/clocksource/timer-vt8500.c +++ b/drivers/clocksource/timer-vt8500.c @@ -11,50 +11,24 @@ * Alexey Charkov. Minor changes have been made for Device Tree Support. */ +#include #include #include #include #include #include -#include #include #include #include - -#define VT8500_TIMER_OFFSET 0x0100 -#define VT8500_TIMER_HZ 3000000 - -#define TIMER_MATCH_REG(x) (4 * (x)) -#define TIMER_COUNT_REG 0x0010 /* clocksource counter */ - -#define TIMER_STATUS_REG 0x0014 -#define TIMER_STATUS_MATCH(x) BIT((x)) -#define TIMER_STATUS_CLEARALL (TIMER_STATUS_MATCH(0) | \ - TIMER_STATUS_MATCH(1) | \ - TIMER_STATUS_MATCH(2) | \ - TIMER_STATUS_MATCH(3)) - -#define TIMER_WATCHDOG_EN_REG 0x0018 -#define TIMER_WD_EN BIT(0) - -#define TIMER_INT_EN_REG 0x001c /* interrupt enable */ -#define TIMER_INT_EN_MATCH(x) BIT((x)) - -#define TIMER_CTRL_REG 0x0020 -#define TIMER_CTRL_ENABLE BIT(0) /* enable clocksource counter */ -#define TIMER_CTRL_RD_REQ BIT(1) /* request counter read */ - -#define TIMER_ACC_STS_REG 0x0024 /* access status */ -#define TIMER_ACC_WR_MATCH(x) BIT((x)) /* writing Match (x) value */ -#define TIMER_ACC_WR_COUNTER BIT(4) /* writing clocksource counter */ -#define TIMER_ACC_RD_COUNTER BIT(5) /* reading clocksource counter */ - -#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) - -#define MIN_OSCR_DELTA 16 +#include +#include +#include static void __iomem *regbase; +static unsigned int sys_timer_ch; /* which match register to use + * for the system timer + */ static u64 vt8500_timer_read(struct clocksource *cs) { @@ -75,21 +49,26 @@ static struct clocksource clocksource = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; +static u64 vt8500_timer_next(u64 cycles) +{ + return clocksource.read(&clocksource) + cycles; +} + static int vt8500_timer_set_next_event(unsigned long cycles, struct clock_event_device *evt) { int loops = msecs_to_loops(10); - u64 alarm = clocksource.read(&clocksource) + cycles; + u64 alarm = vt8500_timer_next(cycles); - while (readl(regbase + TIMER_ACC_STS_REG) & TIMER_ACC_WR_MATCH(0) + while (readl(regbase + TIMER_ACC_STS_REG) & TIMER_ACC_WR_MATCH(sys_timer_ch) && --loops) cpu_relax(); - writel((unsigned long)alarm, regbase + TIMER_MATCH_REG(0)); + writel((unsigned long)alarm, regbase + TIMER_MATCH_REG(sys_timer_ch)); if ((signed)(alarm - clocksource.read(&clocksource)) <= MIN_OSCR_DELTA) return -ETIME; - writel(TIMER_INT_EN_MATCH(0), regbase + TIMER_INT_EN_REG); + writel(TIMER_INT_EN_MATCH(sys_timer_ch), regbase + TIMER_INT_EN_REG); return 0; } @@ -131,7 +110,9 @@ static int __init vt8500_timer_init(struct device_node *np) return -ENXIO; } - timer_irq = irq_of_parse_and_map(np, 0); + sys_timer_ch = of_irq_count(np) > 1 ? 1 : 0; + + timer_irq = irq_of_parse_and_map(np, sys_timer_ch); if (!timer_irq) { pr_err("%s: Missing irq description in Device Tree\n", __func__); @@ -140,7 +121,7 @@ static int __init vt8500_timer_init(struct device_node *np) writel(TIMER_CTRL_ENABLE, regbase + TIMER_CTRL_REG); writel(TIMER_STATUS_CLEARALL, regbase + TIMER_STATUS_REG); - writel(~0, regbase + TIMER_MATCH_REG(0)); + writel(~0, regbase + TIMER_MATCH_REG(sys_timer_ch)); ret = clocksource_register_hz(&clocksource, VT8500_TIMER_HZ); if (ret) { @@ -166,4 +147,86 @@ static int __init vt8500_timer_init(struct device_node *np) return 0; } +static void vt8500_timer_aux_uninit(void *data) +{ + auxiliary_device_uninit(data); +} + +static void vt8500_timer_aux_delete(void *data) +{ + auxiliary_device_delete(data); +} + +static void vt8500_timer_aux_release(struct device *dev) +{ + struct auxiliary_device *aux; + + aux = container_of(dev, struct auxiliary_device, dev); + kfree(aux); +} + +/* + * This probe gets called after the timer is already up and running. This will + * create the watchdog device as a child since the registers are shared. + */ +static int vt8500_timer_probe(struct platform_device *pdev) +{ + struct vt8500_wdt_info *wdt_info; + struct device *dev = &pdev->dev; + int ret; + + if (!sys_timer_ch) { + dev_info(dev, "Not enabling watchdog: only one irq was given"); + return 0; + } + + if (!regbase) + return dev_err_probe(dev, -ENOMEM, + "Timer not initialized, cannot create watchdog"); + + wdt_info = kzalloc(sizeof(*wdt_info), GFP_KERNEL); + if (!wdt_info) + return dev_err_probe(dev, -ENOMEM, + "Failed to allocate vt8500-wdt info"); + + wdt_info->timer_next = &vt8500_timer_next; + wdt_info->wdt_en = regbase + TIMER_WATCHDOG_EN_REG; + wdt_info->wdt_match = regbase + TIMER_MATCH_REG(0); + wdt_info->auxdev.name = "vt8500-wdt"; + wdt_info->auxdev.dev.parent = dev; + wdt_info->auxdev.dev.release = &vt8500_timer_aux_release; + + ret = auxiliary_device_init(&wdt_info->auxdev); + if (ret) { + kfree(wdt_info); + return ret; + } + ret = devm_add_action_or_reset(dev, vt8500_timer_aux_uninit, + &wdt_info->auxdev); + if (ret) + return ret; + + ret = auxiliary_device_add(&wdt_info->auxdev); + if (ret) + return ret; + return devm_add_action_or_reset(dev, vt8500_timer_aux_delete, + &wdt_info->auxdev); +} + +static const struct of_device_id vt8500_timer_of_match[] = { + { .compatible = "via,vt8500-timer", }, + {}, +}; + +static struct platform_driver vt8500_timer_driver = { + .probe = vt8500_timer_probe, + .driver = { + .name = "vt8500-timer", + .of_match_table = vt8500_timer_of_match, + .suppress_bind_attrs = true, + }, +}; + +builtin_platform_driver(vt8500_timer_driver); + TIMER_OF_DECLARE(vt8500, "via,vt8500-timer", vt8500_timer_init); diff --git a/include/linux/vt8500-timer.h b/include/linux/vt8500-timer.h new file mode 100644 index 0000000000000000000000000000000000000000..97ee0716cd84c447b38bbc05535f63fc43e73ef3 --- /dev/null +++ b/include/linux/vt8500-timer.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef LINUX_VT8500_TIMER_H_ +#define LINUX_VT8500_TIMER_H_ + +#include +#include +#include +#include + +#define VT8500_TIMER_HZ 3000000 + +#define TIMER_MATCH_REG(x) (4 * (x)) +#define TIMER_COUNT_REG 0x0010 /* clocksource counter */ + +#define TIMER_STATUS_REG 0x0014 +#define TIMER_STATUS_MATCH(x) BIT((x)) +#define TIMER_STATUS_CLEARALL (TIMER_STATUS_MATCH(0) | \ + TIMER_STATUS_MATCH(1) | \ + TIMER_STATUS_MATCH(2) | \ + TIMER_STATUS_MATCH(3)) + +#define TIMER_WATCHDOG_EN_REG 0x0018 +#define TIMER_WD_EN BIT(0) + +#define TIMER_INT_EN_REG 0x001c /* interrupt enable */ +#define TIMER_INT_EN_MATCH(x) BIT((x)) + +#define TIMER_CTRL_REG 0x0020 +#define TIMER_CTRL_ENABLE BIT(0) /* enable clocksource counter */ +#define TIMER_CTRL_RD_REQ BIT(1) /* request counter read */ + +#define TIMER_ACC_STS_REG 0x0024 /* access status */ +#define TIMER_ACC_WR_MATCH(x) BIT((x)) /* writing Match (x) value */ +#define TIMER_ACC_WR_COUNTER BIT(4) /* writing clocksource counter */ +#define TIMER_ACC_RD_COUNTER BIT(5) /* reading clocksource counter */ + +#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) + +#define MIN_OSCR_DELTA 16 + +struct vt8500_wdt_info { + struct auxiliary_device auxdev; + u64 (*timer_next)(u64 cycles); + void __iomem *wdt_en; + void __iomem *wdt_match; +}; + +#endif /* LINUX_VT8500_TIMER_H_ */ From patchwork Tue May 20 20:01:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Charkov X-Patchwork-Id: 891511 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 750FD288CB7; Tue, 20 May 2025 20:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747771358; cv=none; b=hyP6mObjSbELJdWENNnLY+3MiJUBjBsHzSm5Vx0fUhdirQ6o1/YxF6FVNfjHM5S4XysG+aaszojHi+e3uxv0ijRDL+1wXJ+u2c9NfXmzB/vv9MSgAqHl8mBlImvnvIYq7ayWbq/DNZoLZ1wsbEG+2sRcTAgWFgIG+TKoiiHgCoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747771358; c=relaxed/simple; bh=qeLngx3703X+Z3T6OTmsiw5w/nGbO6F+UA6hRWuYz9Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sXFi0qeVFUzk4eJvG/9sgAOItnle/Zdwt7gFemlPkEHVdSpaThiFXdbrfoKTBmImblBd56ridUZItU2YXAXRF/9I9hMse6jacwyknQyoWpb4cD4hbi0B4cTuZGq5syt4r/xqCQ8xgLq57yGkRbnXSBwRpG7Hj8WyASnC1wdILKI= 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=SZZnJfM/; arc=none smtp.client-ip=209.85.210.173 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SZZnJfM/" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-742b614581dso4570715b3a.3; Tue, 20 May 2025 13:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747771355; x=1748376155; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OilI7sycFnkHdmKoo1s8NQ3T9dco8FEq3kcJbQef9xQ=; b=SZZnJfM/agtJ/2K6aK9B6aSfpjT9jr6/1dZ3SHAq8MT0FoOUQSzzoAaHHURE9ePMrE BUtwb+J6T10Ng7edeGhMB67TlnLY+BCsJ0UxesLAEblbyb+n0q/iuSh9hyycWjf+qvoL 6adY7/GY+F9xXdFIT2Gq1WA4Wh60zgU8D0rCWR+iFze9QDkBmJEp04nW6N4qORUujshn jMcNL5LENlIZVyJqqElH93VnmljXV0ue/BE2VHZBYK1pE7ki5mCzDK9Q6KNdxN+eNTdV 7L45IzHrRe88pbxQDf9hsXR+Cq77r1CBzUySprlqY4T+VbrWPmumRlO2u9RpFYRtE8m5 zmOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747771355; x=1748376155; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OilI7sycFnkHdmKoo1s8NQ3T9dco8FEq3kcJbQef9xQ=; b=h/DwTcxAg+GyL8MFJbbYUXACFFEX9EZsUsGopdMcc3opWeUpimFt683NaYsFkgoSKf 37To0W9HGubkps1BPCRebr6IL/SMTQNp5ScCnvEhL4aIZYgZmh5HLwzOBnPyQIV32Wt2 f7Ad8zPh5b45mALODmVWaeWoLrmm9cnozISkJksjXS+3wgLpATXsO2l4Qr7iqoTDcTJw X/tayb7WGJsZ+B6nRJq3ELMztOMI74h6/fS6ABJbbOITK9VFm0v7ei+YhFWiKCrDAmvO tAkYdT91bdRyvz/t1PVm5R/5jisC7WesU4ULIBKrg4EuBlQqquEtdn6W7gmzxGu3O9VM 0LNg== X-Forwarded-Encrypted: i=1; AJvYcCVUH8m5Oue0hVloZLC98jYIQXYjixrKwI9oavH0n0rKyUo0wAHLKHT+9fSnsHbU22aRs2cip+sRna+QykouHvk=@vger.kernel.org, AJvYcCVtgKGlX+4B6tLgC69GzQ7QEHBbTW+4LzfpQl/rdEVgGTKa4DUVKEmr92ruGvO1c55GqXo09KLUviaS@vger.kernel.org, AJvYcCWnemXXA2Es0qMSUExRD8eDwF8+5u/70e2eH4kzBz012AANpnRDJ8+/GtcWzVw1pZjIP2Tk33/R+pdQCkp/@vger.kernel.org X-Gm-Message-State: AOJu0YxkhTcH4u+e61nGmMvro/5NPr6Lkj9XCiAj/YsnJc1W7fIW05/i xD9yl4vnjEPJc836AX1sEMOvubuSdLRg631O4LoMu3QIJxJIMQctfwlJi73yc7h/H4g= X-Gm-Gg: ASbGncuo0/PLFuavUBjUmeNidMGDeIA2JfUSc5m0fqaElne3zXdU+T2lqR9l97AQSqs xxwmiCY2EDN+enOhX5F+MO3U2Juq5w7/4CzxAoab9Uptu7BTn858BvFXEweWDoY1+5qCqp5euL+ J7TXkqUSP/GIMA9j/CD/RIPT7mxfmjkBxJ3X3wT2N7xQ9+oWTQEuyCsxHBUo9/FBZ9W5GnKUy1C VwRCUxEvtJV4gu3kptPnqtZNXyfZcFeaYDoZW+j9yZEVT0SUUaoPwHDQWVvMLFqvg55D/BdOgXZ Rmjp0aCiwM1rxk9x+z29FQx5MJjVtPpQqXsWxlJE/rJFInvXXdcryrJWXKiInaw= X-Google-Smtp-Source: AGHT+IEhswQQobet3SESatd0Ctpu3CzAb+wp/b+kOVjsj+yXjzeVIvW0SymyOexlFvQlNXrXVnoyHQ== X-Received: by 2002:a05:6a20:6f8c:b0:215:f519:e2dc with SMTP id adf61e73a8af0-2170cb25042mr26000159637.14.1747771355447; Tue, 20 May 2025 13:02:35 -0700 (PDT) Received: from NB-GIGA003.letovo.school ([5.194.95.139]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b26eaf5a0d0sm8412340a12.14.2025.05.20.13.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 13:02:35 -0700 (PDT) From: Alexey Charkov Date: Wed, 21 May 2025 00:01:44 +0400 Subject: [PATCH v4 4/4] watchdog: Add support for VIA/WonderMedia SoC watchdog functionality Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250521-vt8500-timer-updates-v4-4-2d4306a16ae4@gmail.com> References: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com> In-Reply-To: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com> To: Krzysztof Kozlowski , Daniel Lezcano , Thomas Gleixner , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Wim Van Sebroeck , Guenter Roeck Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-watchdog@vger.kernel.org, Alexey Charkov X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747771315; l=5323; i=alchark@gmail.com; s=20250416; h=from:subject:message-id; bh=qeLngx3703X+Z3T6OTmsiw5w/nGbO6F+UA6hRWuYz9Q=; b=E9764OMTvoClSJRuZ7a/FQ8x0MgaPIWF+b2u9p2Kz7GTxhjaJrF7IO8KAdCNGK8Pe5jJohMLN ZuEitiKIh3NDdywXAKwsst8un4CHZtcsI0DSGnvdnIblGrV0iZNwYlO X-Developer-Key: i=alchark@gmail.com; a=ed25519; pk=ltKbQzKLTJPiDgPtcHxdo+dzFthCCMtC3V9qf7+0rkc= VIA/WonderMedia SoCs can use their system timer's first channel as a watchdog device which will reset the system if the clocksource counter matches the value given in its match register 0 and if the watchdog function is enabled. Since the watchdog function is tightly coupled to the timer itself, it is implemented as an auxiliary device of the timer device Signed-off-by: Alexey Charkov --- MAINTAINERS | 1 + drivers/watchdog/Kconfig | 15 ++++++++ drivers/watchdog/Makefile | 1 + drivers/watchdog/vt8500-wdt.c | 80 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 5362095240627f613638197fda275db6edc16cf7..97d1842625dbdf7fdca3556260662dab469ed091 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3447,6 +3447,7 @@ F: drivers/tty/serial/vt8500_serial.c F: drivers/video/fbdev/vt8500lcdfb.* F: drivers/video/fbdev/wm8505fb* F: drivers/video/fbdev/wmt_ge_rops.* +F: drivers/watchdog/vt8500-wdt.c F: include/linux/vt8500-timer.h ARM/ZYNQ ARCHITECTURE diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 0d8d37f712e8cfb4bf8156853baa13c23a57d6d9..8049ae630301a98123f97f6e3ee868bd3bf1534a 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -2003,6 +2003,21 @@ config PIC32_DMT To compile this driver as a loadable module, choose M here. The module will be called pic32-dmt. +config VT8500_WATCHDOG + tristate "VIA/WonderMedia VT8500 watchdog support" + depends on ARCH_VT8500 || COMPILE_TEST + select WATCHDOG_CORE + select AUXILIARY_BUS + help + VIA/WonderMedia SoCs can use their system timer as a hardware + watchdog, as long as the first timer channel is free from other + uses and respective function is enabled in its registers. To + make use of it, say Y here and ensure that the device tree + lists at least two interrupts for the VT8500 timer device. + + To compile this driver as a module, choose M here. + The module will be called vt8500-wdt. + # PARISC Architecture # POWERPC Architecture diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index c9482904bf870a085c7fce2a439ac5089b6e6fee..3072786bf226c357102be3734fe6e701f753d45b 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -101,6 +101,7 @@ obj-$(CONFIG_MSC313E_WATCHDOG) += msc313e_wdt.o obj-$(CONFIG_APPLE_WATCHDOG) += apple_wdt.o obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o obj-$(CONFIG_MARVELL_GTI_WDT) += marvell_gti_wdt.o +obj-$(CONFIG_VT8500_WATCHDOG) += vt8500-wdt.o # X86 (i386 + ia64 + x86_64) Architecture obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o diff --git a/drivers/watchdog/vt8500-wdt.c b/drivers/watchdog/vt8500-wdt.c new file mode 100644 index 0000000000000000000000000000000000000000..54fe5ad7695de36f6b3c1d28e955f00bef00e9db --- /dev/null +++ b/drivers/watchdog/vt8500-wdt.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2025 Alexey Charkov +#include +#include +#include +#include +#include +#include +#include + +static int vt8500_watchdog_start(struct watchdog_device *wdd) +{ + struct vt8500_wdt_info *info = watchdog_get_drvdata(wdd); + u64 deadline = info->timer_next(wdd->timeout * VT8500_TIMER_HZ); + + writel((u32)deadline, info->wdt_match); + writel(TIMER_WD_EN, info->wdt_en); + return 0; +} + +static int vt8500_watchdog_stop(struct watchdog_device *wdd) +{ + struct vt8500_wdt_info *info = watchdog_get_drvdata(wdd); + + writel(0, info->wdt_en); + return 0; +} + +static const struct watchdog_ops vt8500_watchdog_ops = { + .start = vt8500_watchdog_start, + .stop = vt8500_watchdog_stop, +}; + +static const struct watchdog_info vt8500_watchdog_info = { + .identity = "VIA VT8500 watchdog", + .options = WDIOF_MAGICCLOSE | + WDIOF_KEEPALIVEPING | + WDIOF_SETTIMEOUT, +}; + +static int vt8500_wdt_probe(struct auxiliary_device *auxdev, + const struct auxiliary_device_id *id) +{ + struct vt8500_wdt_info *info; + struct watchdog_device *wdd; + + wdd = devm_kzalloc(&auxdev->dev, sizeof(*wdd), GFP_KERNEL); + if (!wdd) + return -ENOMEM; + + wdd->info = &vt8500_watchdog_info; + wdd->ops = &vt8500_watchdog_ops; + wdd->max_hw_heartbeat_ms = U32_MAX / (VT8500_TIMER_HZ / 1000); + wdd->parent = &auxdev->dev; + + info = container_of(auxdev, struct vt8500_wdt_info, auxdev); + watchdog_set_drvdata(wdd, info); + + return devm_watchdog_register_device(&auxdev->dev, wdd); +} + +static const struct auxiliary_device_id vt8500_wdt_ids[] = { + { .name = "timer_vt8500.vt8500-wdt" }, + {}, +}; + +MODULE_DEVICE_TABLE(auxiliary, my_auxiliary_id_table); + +static struct auxiliary_driver vt8500_wdt_driver = { + .name = "vt8500-wdt", + .probe = vt8500_wdt_probe, + .id_table = vt8500_wdt_ids, +}; +module_auxiliary_driver(vt8500_wdt_driver); + +MODULE_AUTHOR("Alexey Charkov "); +MODULE_DESCRIPTION("Driver for the VIA VT8500 watchdog timer"); +MODULE_LICENSE("GPL");