From patchwork Thu May 15 18:55:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Charkov X-Patchwork-Id: 890891 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 B02BB26982D; Thu, 15 May 2025 18:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747335334; cv=none; b=Yeh3vyTDbwCd/+MvDUKj2UPYKb7sUBNyN0AZNKiiSFvY9jFZ5CjwyRWF3axZcZ3ZaMJFQbhnT998dOp93ekSdDMjA/WFK/9Gfb29EVzVKmMlPcNmTVxqx3ABJWv8eXWQBV702IWSC9yzqmja/WuX6T9C6dpoeIjufW4/bJk8Kv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747335334; c=relaxed/simple; bh=yNxDhm/uuiO8dmzR5EBORWvZsJNFwbuRqrNhv+/q4vw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GFkbIeh5vta3ZdUZayhyAt6XaPgKwur3vDLdQpDIJGlPtoKwZ559jqx8Bw/PswESLfHd6GIekuXzkfIjEYASiak89gqiAxPJ9AHLZks3XKslfHnSfYAaYMcH8NMOEC5O0h3Y8pbW678T+Y3NdmTajyFAKaFqxTeTVoXeVEvEnRw= 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=m5KfyAoj; arc=none smtp.client-ip=209.85.167.44 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="m5KfyAoj" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-54b09cb06b0so1557646e87.1; Thu, 15 May 2025 11:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747335331; x=1747940131; 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=EfvGa2EDVDelSmhnP0283dUZyM9fnNxCHCR9wjNeA94=; b=m5KfyAojESTVK0tcjP5q3KuJCF38puGWosqUzWAneOn1Qq0PIHocHSzI9GaITnq/VN eaT98elAkedOD/eyJccboA3q3ay+GfYRrW0GhLxg5jFxpLo9dxNWmA3Hdm8V+dpTXjHj vdJbGw/Zo9vtv2slCp1hPjjcRmHnLe+V1LaWdXDSLHqhtIFxsBUqp4AmT2RD959qsFxM QOddaW0ELQ5RBjE2pBJqlhyq2n5vMAC5IQR2sBTLpgoMPx9qrH3g4L7NRGtf/3wgAjkd Jl4lcc0pOmFBiGOLsV7JnpHgNnJ0ELiEmNRhmtifzcT+pZERjCz3HWfCYqwxw8XLhvAe vD+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747335331; x=1747940131; 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=EfvGa2EDVDelSmhnP0283dUZyM9fnNxCHCR9wjNeA94=; b=D5hQhjgrb1dFPRUj1uMcefEGkk7tdnGIO1Nmp57CJmHTgY1s8L6pRf/3d0EDKN7j3F qZBsOVrqamwsDcq+o2Ho0bPRSqTimDuG2vTI2Gq5nPTdMAobxkC6htOfOHczmcBAHwpj NyOqZlcKSwtyETLIAzQXn2u/h1NIxgfBkCftLfKQCDOjtcbBIz7jfFnBe6OoUZto93fj 87tMJ5gKg9MEnj3M2gmlh1GLNFAeC4MIM46SHujmGgS2H3y1rbCU5R3ljscPAcACM4NG lL7xyUirESSvTVUnnq3BtOj1ERfcRIjoeM1Cv2b5dHlKgBOQJXpp00Sel45Y6X4dd+rN qvaw== X-Forwarded-Encrypted: i=1; AJvYcCUtXI1zT9VgfJC2R32wjF197AKLvTFulXo9II+Rc05rYcAv76HUVpsR2dMW3wBH7GEdqYm5auOKMrHx@vger.kernel.org, AJvYcCVDvEdHri10chwDDNl9pepdqxlPPu+c1BfcHYEzKECRGIBxKQkl422S9xk+1ann3a4qH7q/2rNIUuJzIgg8@vger.kernel.org, AJvYcCVHmxy0UXzuz2dT1pipVUqGEVXtbuO9YL7JukZ1DxXVDehWBHpf3f1haCnCklXgFmJdC5ihQBYVrng0xxZyBl4=@vger.kernel.org X-Gm-Message-State: AOJu0YzdzVEm3Z8vgfIHyraDFVftb4I60LqII4ej/KRJ6TsXMZeD/Zlp uGD/gGEzoJqSCDXrOXaMSMcOcoKK8aV+owWzRCNkjagcgGeKBqF5eIgV X-Gm-Gg: ASbGncvg7iqsVH0ZCB1S+jx8xwIAFI/XzQQ56X2E3wvrUDc5T2j03X/74cByC3Etcsh eG3IIXzED5J/nQ0j3MevF44C1sb+J1+/a8sQra2R6yd9Lc0KMJK81ZOXr5VFKGFF5pqD6+U7a0z Vw7BhweD1kNQkZw1gjUYja3O3aPUQcdvZiRH+LTfxw7igCcS+7yDIJw5UVr6/iB7RE+qAIuFq/k J5tUpOZjgEzAJ0Yr3KdfbAxamteAiVrhLRst9l+TSqZ0o9D940PI2uQbBCZgE0/GO/kWtka3uw6 pYTwRMNcVZZKxqFHGajIgcZgny4/gQ8ggw23UhvX/Ux/xutY52DsggNj3dTHwTjj X-Google-Smtp-Source: AGHT+IGwGxrvOSfW01fCcygvtE81OaRuc1eoF2HsrgiOy6ljMEknHiCgS823LFFyZKoREeRhf+Vzsg== X-Received: by 2002:a05:6512:6301:b0:545:2a7f:8f79 with SMTP id 2adb3069b0e04-550e71b4a93mr192311e87.16.1747335330530; Thu, 15 May 2025 11:55:30 -0700 (PDT) Received: from NB-GIGA003.letovo.school ([95.167.212.10]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-550e702dd8asm60389e87.196.2025.05.15.11.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:55:29 -0700 (PDT) From: Alexey Charkov Date: Thu, 15 May 2025 21:55:26 +0300 Subject: [PATCH v3 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: <20250515-vt8500-timer-updates-v3-1-2197a1b062bd@gmail.com> References: <20250515-vt8500-timer-updates-v3-0-2197a1b062bd@gmail.com> In-Reply-To: <20250515-vt8500-timer-updates-v3-0-2197a1b062bd@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=1747335328; l=3775; i=alchark@gmail.com; s=20250416; h=from:subject:message-id; bh=yNxDhm/uuiO8dmzR5EBORWvZsJNFwbuRqrNhv+/q4vw=; b=NRQGss8+va4KZKjCJRO11/7j3cq4lJKPSHXgToJoCXBCupR0aSzlOR8ZJakm75pow+quIu++K Y+rqzvZ5vE9DICWK24cfXrlUVIy5I/LI9KL+WoZ+G4jBnJYxG9yiyjH 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 69511c3b2b76fb7090a2a550f4c59a7daf188493..b8b2843491c47182a4fc6c76f5c29b6c411830a6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3434,6 +3434,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 Thu May 15 18:55:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Charkov X-Patchwork-Id: 890574 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 0A36C28AAE1; Thu, 15 May 2025 18:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747335335; cv=none; b=Tm4sHCFhljgTfAZXRpd77PLwDsv+1N//G/sXtIXNMQByOG8kYkdZKz38m8a/ZSJvbIImyIYi7iHPtTMwAqNTjRcHwfd2zCuY+GoKHoAvlNJJf7HctyYYRZC4/RYxzqC44SR2Zvw2fD49n9GzssNVRYvteyi+rk23681ngmzd71w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747335335; c=relaxed/simple; bh=4CyYsnhnKma2xppJbhsHsOk6fmvNYSaorpOr7AaIMyg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gTlOl09Jf30z66TXLaa4/osoinKKQHghZGn4GmUG30cACsHTuIIPSbwMZZvWZ/vx0gEV94gUJv9pJY6gZhXcgu1XtzL5/gDPU7MdZUDGMclnMMv+h5ysFHPXd9pPTORbqGtKVkhVp21p7pEKAUbThribAgr6ty6jrcJgwZlhnjs= 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=LcgJ6W5e; arc=none smtp.client-ip=209.85.167.46 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="LcgJ6W5e" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-54298ec925bso1873553e87.3; Thu, 15 May 2025 11:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747335332; x=1747940132; 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=LcgJ6W5eChWX28qT8zq85zPjd/BZxawfJCAjGJILnZ8h8is/VsM4FWRefrbzU2YUbS bz4UsC4lwsIAR6CMnaigbVwLnC//fhTP9gTJMiERX46N80NSqLcoEcuckMtK8Lx9FDTe 2+1Iv9E5gGZOh3DqJEJd02dh2pamRSyMxh5gZgCrwauEk+p7fa2P1WtdFBFjByA4t4e9 /9rq4euSoFI3O7qXYG3gP6paPaIYnSaVc6B0IdPB4huPh5eUBYA+6ctg/K7jTgpyhk7+ fwerbjJz8u/yaUuQmfQ3r1rrN/Qsxme4OMRuLQzNujkgvxAUEPiS+9rfd0jORMRMb3M3 BtIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747335332; x=1747940132; 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=a+u/PfAPhqybJxfk+4MZtpP0r4Lu7U4zhl2p8a6Mlqymn8pKxfzB7hgIuclbWdpK24 1ASH3M5sAWyajWDMqYavtuullSWkh1OFi8nRG41tjfR8oNJ2WX9UXXOpZBGrw27vvgVT pT75EJosgtruxGKNdXG6U2FWaWnycI+WD1qASd9N79Z0RsTMSYtGrNrUbEPjGZCwQLVI 9yPGdshzx5TXmtmbRZAPJx6P1Ms2rvhngiUCcpYLuQQBqLa/3MTlGvzOY+f/OZ7pvfzl +ezbIQ6tUO7t8Pjoa4yEUuuA7iPIBSaslNMetufscwGc7qeBmnqiDz2eexf2D5Nj8yB/ D2kQ== X-Forwarded-Encrypted: i=1; AJvYcCUE3muT5ULE9w6YBjstZhAUx+OTWiQZbLVNuEc2QhGJe7kuJ7X3LWVO5l+UZA8JtrEwOD0g3Rax2iPKUoHA@vger.kernel.org, AJvYcCVY7C5PlWbfZ4xZ0pOnDLzFVArkQMqpO9SPtDQ/fjGqQ5Jb26XGiJ1VeubXbKiV5cEkt7C9leDK27uS@vger.kernel.org, AJvYcCVhOZY7jBrC9c8sjgBEDuhed1m1ACBkXtDTAmxR8lrZ9X92r4gvUFwLnG7mmUDTENxCPahMNF4t3p8/lMSlsEA=@vger.kernel.org X-Gm-Message-State: AOJu0YxJCPoQP6lLFDFT3+oCB1C/mr9eaOy//JJzF7QMMWxW0+sEoubw M8KiRDArd7JbJkhvSr4l0lEnumlxFIyJ0VMzF+EXZNdzGj/LncJQqW/5 X-Gm-Gg: ASbGncvqoWnxJKb4LMTs/9u0cI/M3nlmtGBjULSR+OVQUFf+a0aD+yabEekMIZrjtcz jyHmt/a16URJ+zcHoHc19nS8MCPdrErt8aH67TuhgtigmaXDhstrRkBXp0UVsvGwhZ6ZYsF5HkA veDdalHEXWKxsL/3clW6vPsi4LUepqt8Yweg6C4+wY0pDCSm7zhwWMlXkGTfoAQOpjWUW9RzSF+ KDth6cQ57vB9IJ2uBtVZzJUopv/a3wLD8T7tBCMY6zzt2yppzPHuQ3BW/9yT78AM2ZDwfKfKBkw FvY/ycMtx2w/ffplkrAFicowaa9yoPhlzxmClX+QwmNp27Wn/zHI3IyoXoWt8STP X-Google-Smtp-Source: AGHT+IHApBPb/phj1NVTHxxkqJc2zUdEfupFPSOaxaq4axktTPQJcm8n1VDeCMcQoF0U6De0zLqslA== X-Received: by 2002:a05:6512:31d1:b0:54f:bc43:dafb with SMTP id 2adb3069b0e04-550e7243888mr215821e87.43.1747335331765; Thu, 15 May 2025 11:55:31 -0700 (PDT) Received: from NB-GIGA003.letovo.school ([95.167.212.10]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-550e702dd8asm60389e87.196.2025.05.15.11.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:55:31 -0700 (PDT) From: Alexey Charkov Date: Thu, 15 May 2025 21:55:27 +0300 Subject: [PATCH v3 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: <20250515-vt8500-timer-updates-v3-2-2197a1b062bd@gmail.com> References: <20250515-vt8500-timer-updates-v3-0-2197a1b062bd@gmail.com> In-Reply-To: <20250515-vt8500-timer-updates-v3-0-2197a1b062bd@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=1747335328; l=4723; i=alchark@gmail.com; s=20250416; h=from:subject:message-id; bh=4CyYsnhnKma2xppJbhsHsOk6fmvNYSaorpOr7AaIMyg=; b=oax/cP43gm6/fN+1TVTnpNq77UoNNvIAD9cQbR19U34VFUVdyq2fIGy/3QiCSwVASJSocHcBl gHX4ZTGOHRIAxWTYub6LTkjMpWNNQhcWHPEoZWR9SQ3DKbXm/Qp759D 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 Thu May 15 18:55:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Charkov X-Patchwork-Id: 890890 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 017D128DF09; Thu, 15 May 2025 18:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747335336; cv=none; b=oQ63J+dsPoxYtg7JJpWf/yqj9RWgK5Ln724d64BhD4OOh/zmMQDwQdofJ+32PZYJzp59RAenKz1fpnHWtW5Du4uw+x0rVrlKNPQbiRbEidR2pa0hoylH1r4fAqWavBAvFTZ7KaY3/CEvhdbjpzzdyuFCjn/5Eo4khe9LPJ6rwbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747335336; c=relaxed/simple; bh=QbpS/kQkJJiwh5PckUNMqicAThM5PNWf6q83MVBs0Vs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dHWrXsE/29Go5CxFBFFjDkeNwLJ7P5DGF8dXkMqfW7EMAQ/aVgJgLS/yK37u4Eo3Y1gxy3an/laEaXqRly0mTvrYfbzoPs7JPim7g88zK/m8PEiWmb8YeH5+3DP1m4eMHD2btucPN0Jdoca+vPGbZfVQa/bkweYHlbklQMv1zYQ= 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=O2KWIiPT; arc=none smtp.client-ip=209.85.167.47 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="O2KWIiPT" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-54acc0cd458so1560912e87.0; Thu, 15 May 2025 11:55:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747335333; x=1747940133; 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=89X5cDkgwMX67Wp+mdH+TqpQpjI3cSH5Pn7YIWEV0tU=; b=O2KWIiPTuzhYw1iCjjZ/n3vhzKfoYF04pYxQ2ZXnYRaFK/PBcccuBKBcuKzDxiNtGa 0N9PJsprqb+T+G8rBh8gybzHOqXPqu8y+cCcwqKq+gkUiewQntZQ8GVRmFdjA9WEih87 AtwD+OUZ7jpKC2E6rCXT6aaZsbz70XutPwrrfg8yxcW/HtJyU6WN2p7OXOM1xDwKcUoy 6/GG3BiLvGh8NFu/iXRsl11wTxH4wxNsosmZL9rg0EovncUFSrQRKTUyLGfsIag9JwW9 33J2Xn5/1o/ySY2Gu5aJC5DY5fvGETUTbH00kxY5NgHaaxzQA6vRMkQVh/TERD6miqXI XKgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747335333; x=1747940133; 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=89X5cDkgwMX67Wp+mdH+TqpQpjI3cSH5Pn7YIWEV0tU=; b=fLzEnGigpVoclmu0PXnCCsjbpS8iah0Tq8Li7xTWxefPktp2iMir7+ZaOBB0+jMwV8 AdPqE5Ga0OiX567adbbfj+ve/DokdQnuDNjFpsD4Z9E1N0xPifQVMmJawcC3+OW/WjJe IfBnbikushpiwvi+Ghg9eMO1PuUdr53V8iGSzdt3qhRG+AqxasI1N9PmTq9chVcVXN3D oaGtQie3qEKLq8XWljcMTTEwet6Y5/L5XmqvldDltdYhDNwG7vo41p0ggR4KwmQuFzhk wFQy/VwUmIU6saHL+AUkPd2q7JOgTeEs+PfR+/+LuEg8xfHCZSAOac/vDitL1UV2TNci aSrA== X-Forwarded-Encrypted: i=1; AJvYcCUDpCGN9IKsPyfFXoXd7WqTTpMwkdLsF/X9EBii+Lj9rSkYT3C893Tq0IF3CNa8bV/F21WD6b2EVZpf2gyD@vger.kernel.org, AJvYcCVMbFeNqF3W7VDQJaGVa5jxUNXDXpxHyr1u0x2iaCiw/3w2UntbBZz6YItwoNuS5rXoxlVcFW64Tj5C@vger.kernel.org, AJvYcCXM4pbE453HGQZNL9b7nAAfS9qd3lz4NMbZPTB7ESWfTpZmoCI8WdyPEazlqgfIMJB5hoi15U/rdm5mBP/A8uA=@vger.kernel.org X-Gm-Message-State: AOJu0YyNwm2VTeJ1rkO5YIkWBx+jW39C71rbtYP4niCYiJ6xzKvSqY4f rijfWhgfQtPkcTS74zbQevwhHgeBQjRMw4QaXNqEMTTMahYo53Ap4Hhn X-Gm-Gg: ASbGncvTcHqVVoXTJs/x7ELvtCgZK9JlQeZx75KnfS8SpGIuvZXfkj2gnHwZw0a32Hn xSd2koIaOqIxeiu+6K3ZuZ8LYE34VcPF5W2VYp2u8jtveYs49hITWEPkr9C5enLlSaarX0zWrRh YVTDlxq7EYsf2bFJkkV5kZ5mgH57LPVDK9Bs4WH5Atryh2oKnmcinGLPNIp8uHsgmdjxrujmiI+ m4RJlN9UhrSZKz/LK1lutK/oOV8S9mOy2IDlTITkFBeZJP/q5cTED/kaH5ey1I3C1DnHX0ZTNVz BcziAAi/JktIkoYXmfeSgRBfiQE2NtI7R2zTXi5hHPFavMRLcHPvKVUdmmY1jLVm X-Google-Smtp-Source: AGHT+IFXphhaPfRYQNVaaNL19dEd3OxAeFx5dTiTdykGmgZQ7ms0RJw5IjYe+nVQU2nwQqYh4pYpSA== X-Received: by 2002:a05:6512:3e04:b0:54b:f33:cc16 with SMTP id 2adb3069b0e04-550e71b2359mr207965e87.16.1747335332811; Thu, 15 May 2025 11:55:32 -0700 (PDT) Received: from NB-GIGA003.letovo.school ([95.167.212.10]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-550e702dd8asm60389e87.196.2025.05.15.11.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:55:32 -0700 (PDT) From: Alexey Charkov Date: Thu, 15 May 2025 21:55:28 +0300 Subject: [PATCH v3 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: <20250515-vt8500-timer-updates-v3-3-2197a1b062bd@gmail.com> References: <20250515-vt8500-timer-updates-v3-0-2197a1b062bd@gmail.com> In-Reply-To: <20250515-vt8500-timer-updates-v3-0-2197a1b062bd@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=1747335328; l=4681; i=alchark@gmail.com; s=20250416; h=from:subject:message-id; bh=QbpS/kQkJJiwh5PckUNMqicAThM5PNWf6q83MVBs0Vs=; b=NNBbfD5AkIXlxdWKECjLPB/BWipzyhlLO3lQ2bGgNY4WpyUStbEqnzJqvlhuzrdozgq9Wdp/4 Rok+ZGrpZS4BrkT3pqfAh/A97GspyxUL7USnY8hmvT2cWFBEYgTAV8x 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 a platform device for the watchdog and give it access to the MMIO registers base of the timer through platform data. Signed-off-by: Alexey Charkov --- drivers/clocksource/timer-vt8500.c | 68 +++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/drivers/clocksource/timer-vt8500.c b/drivers/clocksource/timer-vt8500.c index 9f28f30dcaf83ab4e9c89952175b0d4c75bd6b40..122cc046140d5e9edff20ff41a49b4e62064dd40 100644 --- a/drivers/clocksource/timer-vt8500.c +++ b/drivers/clocksource/timer-vt8500.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #define VT8500_TIMER_OFFSET 0x0100 #define VT8500_TIMER_HZ 3000000 @@ -55,6 +57,9 @@ #define MIN_OSCR_DELTA 16 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) { @@ -81,15 +86,15 @@ 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_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 +136,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 +147,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 +173,55 @@ static int __init vt8500_timer_init(struct device_node *np) return 0; } +/* + * 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 platform_device *vt8500_watchdog_device; + 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"); + + vt8500_watchdog_device = platform_device_alloc("vt8500-wdt", -1); + if (!vt8500_watchdog_device) + return dev_err_probe(dev, -ENOMEM, + "Failed to allocate vt8500-wdt"); + + /* Pass the base address as platform data and nothing else */ + vt8500_watchdog_device->dev.platform_data = regbase; + vt8500_watchdog_device->dev.parent = dev; + + ret = platform_device_add(vt8500_watchdog_device); + if (ret) + platform_device_put(vt8500_watchdog_device); + + return ret; +} + +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); From patchwork Thu May 15 18:55:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Charkov X-Patchwork-Id: 890573 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 30E01298CB2; Thu, 15 May 2025 18:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747335338; cv=none; b=Ly3NQMM9MFZYxXcBX278wyTfa7ZLa5Nyy1T46N/v0+/eNrkP878ANydYP4KbtFbDLSnAXidSeB4xFQ6H1dr2nYws7LUzw4GkmiXW9/VqYtXtJJWsgPUGQlPfUNAvHJAohKQC8+bUYxqio5Wq+giChS8KzG3HZjD7sHZYx1hXJFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747335338; c=relaxed/simple; bh=2XFRYiD91queAeJhWuLHIGRtox7ITgkji4UZkOxOnJU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ICJRjAuwV3dbXpIeYkewj2/+vuEJUTfxeQsnZmDw/FIh1Ij57LeqyJ+zsPuZgMd8SMmguyNz09KeCklx+xzN3DsIjLqSqE9qkATiVX+u5vZqI2zvgu6MxwohPQnz/LcftJWIuujmD8YXlLmO4Vum6HfSOV7cNOgQtNZDT5aiDak= 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=JTN9/uSz; arc=none smtp.client-ip=209.85.167.51 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="JTN9/uSz" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-54d98aa5981so1865963e87.0; Thu, 15 May 2025 11:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747335334; x=1747940134; 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=1kWPjrBd/613IEnzahoCitSYpNjnmHuaFTPRIcMwrRo=; b=JTN9/uSzIULndI7E8oFaroP0xua9KObivcdelI/J+SFB2CYv0RlfXSo2mUX9eE8hoQ SyNl3YQGWWA2OvHzZhB9tsRaDNvUEfyybZxZWnKInbiPXlzuD/y2CmKTS7i8o8KvDwYD Vpv613FrgZTjm8VDG1rOkRtOf8PwZSZ+CoQhHp+toBywYMj1PI2vnMJQZDfIiLQGOa09 yqZWLYwUdklVv+tZcSgE34VwkCf7tJT6Ns6sv276aMCuzqn7pWUSd26f/CE1OzV3Ews0 fAOuB9AQ/c63VaYqmFw763fjX34qrlM+J3IHeGt5KYCjesi1C9ezvQGW2F8Q3yswv2qc HRkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747335334; x=1747940134; 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=1kWPjrBd/613IEnzahoCitSYpNjnmHuaFTPRIcMwrRo=; b=Ac7bqNhrJLW4F8ru1VKMltVWNpYwEFimGfuBOcuDAo/lmiTX9J4lP4brirBySmyYao q6aRb491XIlGM987c4UORlkcxJfzxDDwKyvkjNflMgZ2KfP783lHZpWEj4+TruKnSSlp ls6bZ340nvXMeZufP3txoDMUtd+G6CoHGq0GY7M/Zag2ewyztqzyRscUkBLXLxV3jYAr FaCu12377toHEbLUu+LSCVn03cWexUSBKFMsUrB5rEmNKRCNLFaLH66e7fKKRKmB8emg NKspR9QRdHc2arVB1VIn1gBdGKiQ09+fRnfJfKR0a2gFgrzn6Way4U9IGe9bh94++Hx6 A1Wg== X-Forwarded-Encrypted: i=1; AJvYcCVtLcofmKVoFQrRN0E8L3bSymgXalWAGnQTwngyj928UVyBWJnzPvq/iEtjQttCxOH4J95gLBhx2IrryZCw7hQ=@vger.kernel.org, AJvYcCWXoFplM64LOYx43TIlKm0DMp38f7qahNTrKO/zQg2HOv9Em8zKehUY9pfUUh8tB+zD7b24qDXwTnLF@vger.kernel.org, AJvYcCWnyStsf1lQcvYMtS224/LjYP45qb0SVTCSqjGZugcjtPhGVqpPTOLX+37aPY1ZMF8r7vq1Bc+wZPe7+8ED@vger.kernel.org X-Gm-Message-State: AOJu0Yy6ynEgK/f9DNtimkYAZazzkNUNkK4irZESnnLpXQrxJDEW1aGW ihmiK+QdkzX4g6a2JUILwFlLsyTjv6E+bcOmqxqmCF66dLcPvs5Qap/q X-Gm-Gg: ASbGnctHyzFKjf0Zgd524ZTJDddgofnaLQ5BTYNog3Hgff3j6CI1exnghnUrXjASk4H S+ciSUxaL6S/tzHuu/bmL7UQvyjffUKnjK4/p8MvR8C8bK0Ut5KCrNYlHk5GpdZvNZA7qGD52Y4 bInDpxZfPQUo81X6/0nSPNfRr4cFuMMdvkfOm0QVBFx84loebH4HnrzwCLdszmVCI3NPzmmFJfO yBAhGwYlIC6I9GpYP4/yhKMVbn+FfDJWipyu4toy03EqZAXCXTK8x6EZQMZ1fSMFmzhPKFXFqb9 apHSAPt0JCY0fNOdGjaKBon9Zw0xUX8fl1eBAMWnD/q8+RPRgcytBme1gcNEbOwH X-Google-Smtp-Source: AGHT+IGEs4fWZGHCmoPX8DHxcqfmeaQBK7SGcY2ZAhMdx5ivNIe71+v8W7lZ8Ob1Opu59vWYlaooiQ== X-Received: by 2002:a05:6512:31d2:b0:54a:cc76:ad5e with SMTP id 2adb3069b0e04-550e71981e2mr223781e87.3.1747335333916; Thu, 15 May 2025 11:55:33 -0700 (PDT) Received: from NB-GIGA003.letovo.school ([95.167.212.10]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-550e702dd8asm60389e87.196.2025.05.15.11.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:55:33 -0700 (PDT) From: Alexey Charkov Date: Thu, 15 May 2025 21:55:29 +0300 Subject: [PATCH v3 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: <20250515-vt8500-timer-updates-v3-4-2197a1b062bd@gmail.com> References: <20250515-vt8500-timer-updates-v3-0-2197a1b062bd@gmail.com> In-Reply-To: <20250515-vt8500-timer-updates-v3-0-2197a1b062bd@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=1747335328; l=6862; i=alchark@gmail.com; s=20250416; h=from:subject:message-id; bh=2XFRYiD91queAeJhWuLHIGRtox7ITgkji4UZkOxOnJU=; b=TCQO3le/NzI+O9M2LYnIFQZPy6L1dVDvBwVsgTeULw4pXLs/se7iBNx5Z11uwcTanQn+OeT+N PalmzHKo5kvAqLiKno6ziebxGbP/kUaEgcuoAV8Kx+bhK2dIPyFI6nq 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 a child platform device of the timer device, and just reuses the MMIO registers already remapped by the timer driver. This is similar to the approach taken by gxp-wdt.c Signed-off-by: Alexey Charkov --- MAINTAINERS | 1 + drivers/watchdog/Kconfig | 14 +++++ drivers/watchdog/Makefile | 1 + drivers/watchdog/vt8500-wdt.c | 116 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index b8b2843491c47182a4fc6c76f5c29b6c411830a6..d809643b76ad299ca1c08804540b08cc4a7184a6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3446,6 +3446,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 ARM/ZYNQ ARCHITECTURE M: Michal Simek diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 0d8d37f712e8cfb4bf8156853baa13c23a57d6d9..429e4e775f1f458fd457067a3a039a5d544b4818 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -2003,6 +2003,20 @@ 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 + 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..8e605c850dd9f42c90104f362b74adac63dd9fdb --- /dev/null +++ b/drivers/watchdog/vt8500-wdt.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2025 Alexey Charkov +#include +#include +#include +#include +#include + +#define TIMER_MATCH_REG(x) (4 * (x)) +#define TIMER_COUNT_REG 0x0010 /* clocksource counter */ + +#define TIMER_WATCHDOG_EN_REG 0x0018 +#define TIMER_WD_EN BIT(0) + +#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 VT8500_TIMER_HZ 3000000 +#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) + +struct vt8500_wdt { + void __iomem *regbase; + struct watchdog_device wdd; +}; + +static u64 vt8500_timer_read(void __iomem *regbase) +{ + int loops = msecs_to_loops(10); + + 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_REG); +} + +static int vt8500_watchdog_start(struct watchdog_device *wdd) +{ + struct vt8500_wdt *drvdata = watchdog_get_drvdata(wdd); + u64 cycles = wdd->timeout * VT8500_TIMER_HZ; + u64 deadline = vt8500_timer_read(drvdata->regbase) + cycles; + + writel((u32)deadline, drvdata->regbase + TIMER_MATCH_REG(0)); + writel(TIMER_WD_EN, drvdata->regbase + TIMER_WATCHDOG_EN_REG); + return 0; +} + +static int vt8500_watchdog_stop(struct watchdog_device *wdd) +{ + struct vt8500_wdt *drvdata = watchdog_get_drvdata(wdd); + + writel(0, drvdata->regbase + TIMER_WATCHDOG_EN_REG); + 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 platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct vt8500_wdt *drvdata; + + drvdata = devm_kzalloc(dev, sizeof(struct vt8500_wdt), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; + + /* + * The register area where the timer and watchdog reside is disarranged. + * Hence mapping individual register blocks for the timer and watchdog + * is not recommended as they would have access to each others + * registers. The timer driver creates the watchdog as a child device. + * During the watchdogs creation, the timer driver passes the base + * address to the watchdog over the private interface. + */ + + drvdata->regbase = (void __iomem *)dev->platform_data; + + drvdata->wdd.info = &vt8500_watchdog_info; + drvdata->wdd.ops = &vt8500_watchdog_ops; + drvdata->wdd.max_hw_heartbeat_ms = -1UL / (VT8500_TIMER_HZ / 1000); + drvdata->wdd.parent = dev; + + watchdog_set_drvdata(&drvdata->wdd, drvdata); + + return devm_watchdog_register_device(dev, &drvdata->wdd); +} + +static struct platform_driver vt8500_wdt_driver = { + .probe = vt8500_wdt_probe, + .driver = { + .name = "vt8500-wdt", + }, +}; +module_platform_driver(vt8500_wdt_driver); + +MODULE_AUTHOR("Alexey Charkov "); +MODULE_DESCRIPTION("Driver for the VIA VT8500 watchdog timer"); +MODULE_LICENSE("GPL");