From nobody Thu Sep 24 13:41:52 2026 Received: from mail-oi2-f12.google.com (mail-oi2-f12.google.com [74.125.231.204]) (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 2292A42902A for ; Wed, 23 Sep 2026 05:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.204 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141787; cv=none; b=PqkH3ZA1ISGoLXxf7CzYiiCcu3QGdRHlBMVTgNl9Dcs1Y3JqunzQkgZgfGj5E+yV+kPCSpYcxQq4oFQhtT8W7v182ehSI6ZNuB/0NlHr1tVXchJz6BzGHa2llxne+cORqbRjee/pkgUoQCYZ7/qtFHX9rOyjCl0k5Irmsbc1j1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141787; c=relaxed/simple; bh=5k9VLU6OvtrGZi0gO1yZy16OfwqfrZmQwujeqIifWv0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s8yr2rJuOGpY07t/mx7B5PvqoV8ZFVC012GAzzQr6AVrqXojHtyvtrNOKk6vR+hrndDmil1IYNGWSsoXFloGtwXlCTdbHXXrQPPzcAJV3T7iNjjs35RG64YY+MKZtSY0frRz5o5Tw46NML5B8Hm++iOgjndfhgg6eaSmhcGWs6w= 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=F8XH63Z4; arc=none smtp.client-ip=74.125.231.204 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="F8XH63Z4" Received: by mail-oi2-f12.google.com with SMTP id 5614622812f47-4b37a36887bso376316b6e.2 for ; Tue, 22 Sep 2026 22:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790141784; x=1790746584; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=M4cUR/bgVx/Ef4Tc/Iqux+0dgmZ5BenjLrR4X+eBZEU=; b=F8XH63Z4doIji6bAgrFxU4KEekuBBKmXL51+Wdkbkecnt3xzvQGiJ1lj6kBiiQE78l 6vt0ZXymtZwSyYJYb3xeB4CmuzVVdbvwsvON9Pmdscl6FcrzMXmyawBtN9dynJ+8gwNN YRUrlwN1ZBsGdgrlCvm4KY6vI00oR6JgtnCqXh3Al3/tQWCPvopqWqeScOzz3ApR3aMF qSRL/1UsfSmgkSPUXWGNkGBcZRViDMufWKGPqpKEkvu0eyJHIDhDYBCEAH3MEwB3n2dY eFQMaLv4if3U391jU5QfTeY3iz8JDef7iyMh5NtrfQdMcNMF4tqbUgVjIHsb3OXZfhhQ /FRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790141784; x=1790746584; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=M4cUR/bgVx/Ef4Tc/Iqux+0dgmZ5BenjLrR4X+eBZEU=; b=FEFFvsbFr200cguqfIm6jkdWB6TljSC7TpHw2fbpTlAbB5CUjqqzQpJlYhdQ/Mvqd7 d9jSeYIj6yfvxG433rHYjElZFlbabkVaxbkLpODDb94Qnx4MPlKngIVVofzQnfp3uOek bVf8m4mkhZoqSFbsnfYbqU9DX8kWyiCT+SrixlqDd2bVnxZZtejIyE8vvl4C32HGRqlC KKiZvZxZ6IpuHTtHeIcCaAhwlJ/gFCd28MKrlAle4AOZnKHNS9PsesLFdLFwKtqGZxSL w082JH3KMEQpyeXNyzX1UFoq8TnGpobdznac3mRDXruBuzIXsDyypTzRPeO6RX+3waCy aqrQ== X-Forwarded-Encrypted: i=1; AKwUvBzI1i59a100z01jlSt6xpb2joeFUuPgFzowfS7zMuE+8Cb08P5ZmkYahDfAICT1RzpzcUj1iOEV2uY44Qk=@vger.kernel.org X-Gm-Message-State: AFuF++nyedUpb+oT958fvIVSkgFlSsr0U0S/MrO7mooAD99Rz1rqERId RiAVwo7mJvoXP/kqh+ll0km5t6/lPKa2BC7fOGvmV1qGJZ39LQdL+bM7 X-Gm-Gg: AYBFou2FUZcWv5GWbuB4a6o9xB3ibU/15z6YStt4Lonnd7ZfEb0Pw7J+mj0J5LuKTz0 +Dc5gSHBJZ3oJLsYmuGZYs6PL8IucePe0xWkVaghZDGT4A2YyG7FtRNdYWWK5RalWnwXPF/e6JY TNL0hje8tPxSJ3ARxPTDlkiTSxKzxL0z1n1j0h/y2krk9ePdWHEkPNfJqjrAw2/S/eyEegmw88x fkriaWVhHlBPeSEAwlIlxfRAYZFwet3QeSBUC1dNVgYOeMjZ4Yx+lrWT+G9Y71pHoBcMha1e6fd /G3RtjZfY2MflieB5XDwlPwTTJXpOTg1s5QJ9qJonpVnDIj/uis5NZoEzxplYH8Ada3dVU9b3bo rt4a9c0GWAlJIOrLMt9lY5RuD8CsL+0A2h8dGmxAyAzs7sHFPT+dWY7wna4s9L5f3p7NcuV1j/l m6llfulDo+8vgEMXjGtMs44x78oFRWfT+hqrBXSpOsrAfnySb03t086FACBIrEWaatYngz7K1z3 SLkqyT56GZZtMB/YkiVhw0RIAhXJbnP5OeMuE1c95uhWBIl+Big486Mh7i4hyI8pKakjlj8B7B7 ITKbLM2Awm4OdCJT0qBZnkiLsT9xLOL7MM/MnjeeX1lGsGMOEq8frvG6qEysI0nhNV7hCSIYBRR R1RXshd8OX4ax5n3PVNpM X-Received: by 2002:a05:6808:6b8a:b0:4c1:9127:c0fb with SMTP id 5614622812f47-4d5ba3c38b4mr1883196b6e.36.1790141784089; Tue, 22 Sep 2026 22:36:24 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4d5c4aed99bsm1436896b6e.12.2026.09.22.22.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 22:36:23 -0700 (PDT) From: James Hilliard Date: Tue, 22 Sep 2026 23:36:14 -0600 Subject: [PATCH v10 1/5] dt-bindings: pwm: allwinner: add h616 pwm compatible Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260922-h616-pwm-v8-v10-1-dccebbe1aabf@gmail.com> References: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> In-Reply-To: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Stephen Boyd , Brian Masney , Jerome Brunet , Richard Genoud , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard Cc: Philipp Zabel , Michael Turquette , Paul Kocialkowski , Thomas Petazzoni , John Stultz , Joao Schim , bigunclemax@gmail.com, linux-pwm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard , Conor Dooley X-Mailer: b4 0.15.2 From: Richard Genoud The Allwinner H616 PWM block differs from the A10 and H6 blocks, but it uses the same input clocks as H6, so extend the existing Allwinner PWM binding. The block has six channels that can generate PWM waveforms. Each channel also has a bypass that turns its output into a clock suitable for consumers such as the integrated X-Powers AC200 or AC300 Ethernet PHY. Require #clock-cells for H616 because the bypass clocks are part of its provider interface, while continuing to disallow the property for the older variants. Acked-by: Conor Dooley Signed-off-by: Richard Genoud Signed-off-by: James Hilliard --- .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 33 ++++++++++++++++++= +++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.= yaml b/Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml index 1197858e431f..3b1819c8630c 100644 --- a/Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml +++ b/Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml @@ -14,6 +14,13 @@ properties: "#pwm-cells": const: 3 =20 + "#clock-cells": + const: 1 + description: + The cell selects the PWM channel whose hardware bypass path is expor= ted + as a clock. Its rate follows the selected shared pair source and div= ider; + the PWM period, duty-cycle and polarity logic is bypassed. + compatible: oneOf: - const: allwinner,sun4i-a10-pwm @@ -36,6 +43,7 @@ properties: - const: allwinner,sun50i-h5-pwm - const: allwinner,sun5i-a13-pwm - const: allwinner,sun50i-h6-pwm + - const: allwinner,sun50i-h616-pwm =20 reg: maxItems: 1 @@ -62,7 +70,9 @@ allOf: properties: compatible: contains: - const: allwinner,sun50i-h6-pwm + enum: + - allwinner,sun50i-h6-pwm + - allwinner,sun50i-h616-pwm =20 then: properties: @@ -83,6 +93,27 @@ allOf: clocks: maxItems: 1 =20 + - if: + properties: + compatible: + contains: + const: allwinner,sun50i-h616-pwm + + then: + properties: + clocks: + minItems: 2 + + clock-names: + minItems: 2 + + required: + - "#clock-cells" + + else: + properties: + "#clock-cells": false + required: - compatible - reg --=20 2.53.0 From nobody Thu Sep 24 13:41:52 2026 Received: from mail-oi2-f13.google.com (mail-oi2-f13.google.com [74.125.231.205]) (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 E11504399E0 for ; Wed, 23 Sep 2026 05:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141792; cv=none; b=CJF/kM8I3SkuLIj41tTkKjhtPQo6YCOYmT+wpzcY8aAHsmD1gPK9sI2Y2oKoNFAa3UdyZ0pQBkS+slDwmAkvssKGtWjuhJhrg/nqHCOWNo6nb1Kk93Fvj7dA6fAAfXdOhdi84EmVPZ5ZhPLCVnw4BuNgExUJpzPz7haZaRAC2iU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141792; c=relaxed/simple; bh=NaP5go48DIg7ZP2vsh8v9L0+32c55LUSiW/3zQ6evCw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CE30j1zS+Cb1rAlCpio3x7AwndJ4h3uD8gM7xfV/57mLkw5NR97IR0KTHrxoe4sMDq8lYQVTWzZtp+CsvYoMZPee/Q1ogWzTZpZuNBa0S/UTh8GKbwxnvTTbyD25E+eOuujdTHVyp+hD7mmoNvwYRVRR7n/BNq52cWwy9+FNEaE= 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=qZCM/aU6; arc=none smtp.client-ip=74.125.231.205 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="qZCM/aU6" Received: by mail-oi2-f13.google.com with SMTP id 5614622812f47-4b37a3ed714so437515b6e.0 for ; Tue, 22 Sep 2026 22:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790141786; x=1790746586; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TmixJAuwq8ENbvDysNd8oI5Iik3FUsXX4Zkq+YJZJ3g=; b=qZCM/aU6myQ9V4CcV3WmlHCzpetYpGP3sIlz+58uZC4slTqupAtzpe1f3rMlR7gQjj UaFLqWFRb/bRBYpDbN9MDgs0vrGKNXzpa6IpINBhEkryYP0E+pctsBcqYWef1s/qoEtS ED3GzDff96+4XkNFttaZqqT4uYlp0FVH814uhtpmhYUuZldMM6q7mE+m6ZXV/IEoAUxd TJsD6MhAhBRDOif6uDCh9B31l298nLElpLKV8dSjs/to1H+K1qmYJPPzqqkb1YvU3nXX pjLJsJyhjkIj5gOWrm1d+wlvaDKIl3zfX7CMJ0B/kEBHVayF3a+vFFrjPmJ2SP+MLpGU V1tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790141786; x=1790746586; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=TmixJAuwq8ENbvDysNd8oI5Iik3FUsXX4Zkq+YJZJ3g=; b=Cv3FtzlVTJoojjR03Expa3+PWLQUx9T4qS0/6D0Syn5Ru8I0sTiFFg2+B1CdUDH9j6 Bf+m6wcO/fnpb4mK6H1tLXKDlGYIisyknJVSGlFSxpeMBBZGeJ/55Yn+MgF37REUzGpq xrmgxq29t5IWPUHTuHnWMKxkNFwYkfdCI96BzWxalGVosuhKX+Z0Z6dp24heKkJlyAG8 HPlLqWjpHIOps+H1/JQuJzrA/EFN5A0quUNrvL6SHcmXhNdxYGJnAxZt0s1ogXCj9SWS YV13qN1LFWVWdGry8aiK7wpuFoGqgZGPrwzDz79M1cdtPw9jxVpevyLXFTtwn/XcJfq5 CYkA== X-Forwarded-Encrypted: i=1; AKwUvBzJPPM1bApCnSTgTLnb0lyp3AvFx9bxP+juJp4EP+GtUCqWUBhucZGcyNH5fKYDB2leRNcDLCDnfq81XX8=@vger.kernel.org X-Gm-Message-State: AFuF++l8txsZ8lp1w0Nl+vRWpZFLUvYLSpO4RGuURuMtTl2hgVy9GTQQ ig1y/x4JGI3tyngVI1X2rbcDpHiFncsLO0uKt10iBeTWOC3rLvFcgbfL X-Gm-Gg: AYBFou0uQR9ojMfqfY8Y0eNotyYjiOk6wtn3POTab3A/VPUkHIhJ2FcEy7nnDqGAQD+ 2wkbzkzvfhdodL1cQJi248SqGldQUEsTkjGharKn66oQFwXVGLa80ZalZeexwfpAB/8at0TPgiB w9aUdTM0+7Nunye4hhWfp8npQH2Jv1HOgMJcVC202wpDCgdZBe4nqkjjo2EzbfqksUWDGFoo97b UDeYwaXm8+VDwzjvS1IrSs8CBbj/BeV64162qUs4YKbuOzdpJPLFogQa/ujJQk8bCPbe+gG924q gR2z8zc6MPldIF7LJdryfXimnLdM6xvYvfaSWW9eJ786BCG4aYN5BOYkqAeIO+c/qyuNywg58AV B3rkbk4FB+nRpYZbczbIdeu2luqfKnCK/Ix5nR29c6k0xWJZ4I+/o3RZtc6imRfpW9/YvsfIudK DzgIF1TgRFTx11ONA4ScBmhupwog5vdithRgNR5jaNOFvmUtbmLgnPdSpoO4J6eQZW5D8COT9Q+ iIA3C3hJzEgPBUbK1hgUTpI3Kxpd0RjUCeiuabTvz4TK288Wp0Jch9tIND7+4Ju4GFyQZTR64ro Zfgm568ao1fxabdMKaRHxRuJReJr+0HkvcWMoFhcytvAtLTqwEQXKlUeSXxMFBc4PRD4H7kSIxD 4TeLcIdyFaOAYQd5HeaJypKU4JGqk2DsO X-Received: by 2002:a05:6808:1383:b0:4c4:a240:9c3a with SMTP id 5614622812f47-4d5b6eea244mr1774765b6e.4.1790141785549; Tue, 22 Sep 2026 22:36:25 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4d5c4aed99bsm1436896b6e.12.2026.09.22.22.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 22:36:24 -0700 (PDT) From: James Hilliard Date: Tue, 22 Sep 2026 23:36:15 -0600 Subject: [PATCH v10 2/5] pwm: sun8i: Add H616 PWM support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260922-h616-pwm-v8-v10-2-dccebbe1aabf@gmail.com> References: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> In-Reply-To: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Stephen Boyd , Brian Masney , Jerome Brunet , Richard Genoud , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard Cc: Philipp Zabel , Michael Turquette , Paul Kocialkowski , Thomas Petazzoni , John Stultz , Joao Schim , bigunclemax@gmail.com, linux-pwm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.15.2 From: Richard Genoud Add waveform support for the six-channel Allwinner H616 PWM controller. Each pair of outputs shares a source mux, gate and power-of-two divider; each channel has its own prescaler and period/duty registers. Model the shared pair clocks in CCF and program the channel-local dividers directly. Protect the pair rate while a PWM is active. Also check the hardware enable bits before retuning or gating a pair, since firmware may have left an output running without a Linux consumer. Preserve such outputs until a consumer explicitly changes them; do not implement an unused-PWM sweep. Round period, duty and offset in the order required by the waveform API, including the hardware bypass path and the 65536-tick period boundary. Wait for pending period updates and quiesce the channel when changing its clock, prescaler, polarity or bypass mode. Live period updates additionally require PCLK to be faster than the PWM clock, as specified by the manual. Encode the channel register values during waveform conversion. Keep rate protection, safe quiescing and clock rollback in one preparation helper, leaving the write callback to apply the prepared values. Select candidates using one ordered comparison while retaining the bounded divider search. Pulse and coupled dead-zone modes cannot be represented by this API. Reject active unsupported modes, but clear dormant dead-zone configuration before programming an ordinary waveform. Allocate the fixed six-channel topology with the pwm_chip. Register the per-device clocks with managed helpers after deasserting reset. Acquire separate pair-clock consumer handles only while PWMs are requested, so internal clock references cannot prevent module removal. Use CCF's provider-owned handles for notifiers and rate readback, including readback of channels which have not been requested. Signed-off-by: Richard Genoud Co-developed-by: James Hilliard Signed-off-by: James Hilliard --- drivers/pwm/Kconfig | 11 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-sun8i.c | 1080 +++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 1092 insertions(+) diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 729776086879..d87d166e7836 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -748,6 +748,17 @@ config PWM_SUN4I To compile this driver as a module, choose M here: the module will be called pwm-sun4i. =20 +config PWM_SUN8I + tristate "Allwinner sun8i/sun50i PWM support" + depends on ARCH_SUNXI || COMPILE_TEST + depends on HAS_IOMEM && COMMON_CLK + help + PWM framework driver for Allwinner controllers whose channels share + paired source clocks. + + To compile this driver as a module, choose M here: the module + will be called pwm-sun8i. + config PWM_SUNPLUS tristate "Sunplus PWM support" depends on ARCH_SUNPLUS || COMPILE_TEST diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index 5630a521a7cf..9c922b1fd0b4 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -68,6 +68,7 @@ obj-$(CONFIG_PWM_STM32) +=3D pwm-stm32.o obj-$(CONFIG_PWM_STM32_LP) +=3D pwm-stm32-lp.o obj-$(CONFIG_PWM_STMPE) +=3D pwm-stmpe.o obj-$(CONFIG_PWM_SUN4I) +=3D pwm-sun4i.o +obj-$(CONFIG_PWM_SUN8I) +=3D pwm-sun8i.o obj-$(CONFIG_PWM_SUNPLUS) +=3D pwm-sunplus.o obj-$(CONFIG_PWM_TEGRA) +=3D pwm-tegra.o obj-$(CONFIG_PWM_TH1520) +=3D pwm_th1520.o diff --git a/drivers/pwm/pwm-sun8i.c b/drivers/pwm/pwm-sun8i.c new file mode 100644 index 000000000000..7e6c39815c18 --- /dev/null +++ b/drivers/pwm/pwm-sun8i.c @@ -0,0 +1,1080 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for Allwinner sun8i Pulse Width Modulation Controller + * + * (C) Copyright 2025 Richard Genoud, Bootlin + * (C) Copyright 2026 James Hilliard + * + * Based on drivers/pwm/pwm-sun4i.c with Copyright: + * + * Copyright (C) 2014 Alexandre Belloni + * + * Channels are paired (0/1, 2/3, 4/5). Each pair shares a clock source and + * first prescaler (div_m), while each channel has its own second prescaler + * (div_k) and bypass path. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SUN8I_PWM_NPWM 6 +#define SUN8I_PWM_NPAIRS (SUN8I_PWM_NPWM / 2) + +/* PWMCC Pairs Clock Configuration Registers */ +#define SUN8I_PWM_PCCR(pair) (0x20 + ((pair) * 0x4)) +#define SUN8I_PWM_PCCR_SRC_SHIFT 7 +#define SUN8I_PWM_PCCR_SRC_MASK GENMASK(1, 0) +#define SUN8I_PWM_PCCR_GATE_BIT 4 +#define SUN8I_PWM_PCCR_GATE BIT(SUN8I_PWM_PCCR_GATE_BIT) +#define SUN8I_PWM_PCCR_BYPASS_BIT(chan) ((chan) % 2 + 5) +#define SUN8I_PWM_PCCR_DIV_M_SHIFT 0 +#define SUN8I_PWM_PCCR_DIV_M_WIDTH 4 + +/* PWM Enable Register */ +#define SUN8I_PWM_PER 0x40 +#define SUN8I_PWM_ENABLE(chan) BIT(chan) + +/* PWM Control Register */ +#define SUN8I_PWM_PCR(chan) (0x60 + (chan) * 0x20) +#define SUN8I_PWM_PCR_PRESCAL_K_MASK GENMASK(7, 0) +#define SUN8I_PWM_PCR_ACTIVE_STATE BIT(8) +#define SUN8I_PWM_PCR_MODE BIT(9) +#define SUN8I_PWM_PCR_PULSE_START BIT(10) +#define SUN8I_PWM_PCR_PERIOD_READY BIT(11) /* 0: ready, 1: busy */ +#define SUN8I_PWM_PCR_WAVEFORM_MASK (SUN8I_PWM_PCR_PRESCAL_K_MASK | \ + SUN8I_PWM_PCR_ACTIVE_STATE) + +/* PWM Period Register */ +#define SUN8I_PWM_PPR(chan) (0x64 + (chan) * 0x20) +#define SUN8I_PWM_PPR_PERIOD_MASK GENMASK(31, 16) +#define SUN8I_PWM_PPR_DUTY_MASK GENMASK(15, 0) +#define SUN8I_PWM_PPR_PERIOD_VALUE(reg) (FIELD_GET(SUN8I_PWM_PPR_PERIOD_MA= SK, reg) + 1) +#define SUN8I_PWM_PPR_DUTY_VALUE(reg) FIELD_GET(SUN8I_PWM_PPR_DUTY_MASK, r= eg) +#define SUN8I_PWM_PPR_PERIOD(prd) FIELD_PREP(SUN8I_PWM_PPR_PERIOD_MASK, (p= rd) - 1) +#define SUN8I_PWM_PPR_DUTY(dty) FIELD_PREP(SUN8I_PWM_PPR_DUTY_MASK, dty) +#define SUN8I_PWM_PPR_PERIOD_MAX (FIELD_MAX(SUN8I_PWM_PPR_PERIOD_MASK) + 1) + +/* PWM pair dead-zone control registers. */ +#define SUN8I_PWM_PDZCR(pair) (0x30 + ((pair) * 0x4)) +#define SUN8I_PWM_PDZCR_ENABLE BIT(0) + +#define SUN8I_PWM_PERIOD_READY_MARGIN_US 50 +#define SUN8I_PWM_PERIOD_READY_MIN_POLL_US 10 +#define SUN8I_PWM_PERIOD_READY_MAX_POLL_US 10000 +#define SUN8I_PWM_PERIOD_READY_POLL_COUNT 1024 + +#define SUN8I_PWM_PAIR_IDX(chan) ((chan) >> 1) + +/* + * Block diagram of the PWM clock controller: + * + * _____ ______ ________ + * OSC24M --->| | | | | | + * APB1 ----->| Mux |--->| Gate |--->| /div_m |-----> SUN8I_PWM_clock_src_= xy + * |_____| |______| |________| + * ________ + * | | + * +->| /div_k |---> SUN8I_PWM_clock_x + * | |________| + * | ______ + * | | | + * +-->| Gate |----> SUN8I_PWM_bypass_clock_x + * | |______| + * SUN8I_PWM_clock_src_xy ---+ ________ + * | | | + * +->| /div_k |---> SUN8I_PWM_clock_y + * | |________| + * | ______ + * | | | + * +-->| Gate |----> SUN8I_PWM_bypass_clock_y + * |______| + * + * NB: when the bypass is set, all the PWM logic is bypassed. + * So, the duty cycle and polarity can't be modified (we just have a clock= ). + * The bypass in PWM mode is used to achieve a 1/2 relative duty cycle wit= h the + * fastest clock. + * + */ + +/* /div_m is a power-of-two divider limited to /256. */ +static const struct clk_div_table sun8i_pwm_div_m_table[] =3D { + { .val =3D 0, .div =3D 1 }, + { .val =3D 1, .div =3D 2 }, + { .val =3D 2, .div =3D 4 }, + { .val =3D 3, .div =3D 8 }, + { .val =3D 4, .div =3D 16 }, + { .val =3D 5, .div =3D 32 }, + { .val =3D 6, .div =3D 64 }, + { .val =3D 7, .div =3D 128 }, + { .val =3D 8, .div =3D 256 }, + { /* sentinel */ } +}; + +struct sun8i_pwm_chip; + +struct sun8i_pwm_pair { + struct clk_mux mux; + struct clk_hw gate_hw; + struct clk_divider divider; + struct clk_hw *hw; + struct notifier_block rate_nb; + struct sun8i_pwm_chip *chip; + unsigned int index; +}; + +struct sun8i_pwm_channel { + /* Separate CCF consumer, held only from PWM request to free. */ + struct clk *pair_clk; + u64 pending_period_ns; + bool rate_exclusive; +}; + +struct sun8i_pwm_chip { + struct sun8i_pwm_pair pairs[SUN8I_PWM_NPAIRS]; + struct sun8i_pwm_channel channels[SUN8I_PWM_NPWM]; + struct clk *bus_clk; + void __iomem *base; + /* Protects shared registers and rate_exclusive. */ + spinlock_t lock; +}; + +struct sun8i_pwm_waveform { + u32 pcr; + u32 ppr; + u32 pair_rate; + bool enabled; + bool bypass_en; +}; + +static inline struct sun8i_pwm_chip *sun8i_pwm_from_chip(const struct pwm_= chip *chip) +{ + return pwmchip_get_drvdata(chip); +} + +static unsigned long sun8i_pwm_get_pair_rate(struct sun8i_pwm_chip *sun8i_= chip, + unsigned int idx) +{ + struct sun8i_pwm_pair *pair =3D &sun8i_chip->pairs[SUN8I_PWM_PAIR_IDX(idx= )]; + + /* Readback also runs on channels without a PWM request. */ + return clk_get_rate(pair->hw->clk); +} + +static inline u32 sun8i_pwm_readl(struct sun8i_pwm_chip *sun8i_chip, + unsigned long offset) +{ + return readl(sun8i_chip->base + offset); +} + +static inline void sun8i_pwm_writel(struct sun8i_pwm_chip *sun8i_chip, + u32 val, unsigned long offset) +{ + writel(val, sun8i_chip->base + offset); +} + +static void sun8i_pwm_set_bypass_locked(struct sun8i_pwm_chip *sun8i_chip, + unsigned int idx, bool enable) +{ + unsigned long reg_offset; + u32 val; + + lockdep_assert_held(&sun8i_chip->lock); + + reg_offset =3D SUN8I_PWM_PCCR(SUN8I_PWM_PAIR_IDX(idx)); + val =3D sun8i_pwm_readl(sun8i_chip, reg_offset); + if (enable) + val |=3D BIT(SUN8I_PWM_PCCR_BYPASS_BIT(idx)); + else + val &=3D ~BIT(SUN8I_PWM_PCCR_BYPASS_BIT(idx)); + + sun8i_pwm_writel(sun8i_chip, val, reg_offset); +} + +static void sun8i_pwm_set_enabled_locked(struct sun8i_pwm_chip *sun8i_chip, + unsigned int idx, bool enable) +{ + u32 val; + + lockdep_assert_held(&sun8i_chip->lock); + + val =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); + if (enable) + val |=3D SUN8I_PWM_ENABLE(idx); + else + val &=3D ~SUN8I_PWM_ENABLE(idx); + sun8i_pwm_writel(sun8i_chip, val, SUN8I_PWM_PER); +} + +static bool +sun8i_pwm_channel_is_enabled_locked(struct sun8i_pwm_chip *sun8i_chip, + unsigned int idx) +{ + unsigned int pair =3D SUN8I_PWM_PAIR_IDX(idx); + u32 pccr, per; + + lockdep_assert_held(&sun8i_chip->lock); + + pccr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCCR(pair)); + per =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); + + return (pccr & SUN8I_PWM_PCCR_GATE) && + (per & SUN8I_PWM_ENABLE(idx)); +} + +static u32 sun8i_pwm_pair_enable_mask(unsigned int pair) +{ + return GENMASK(pair * 2 + 1, pair * 2); +} + +static inline struct sun8i_pwm_pair * +sun8i_pwm_pair_from_gate_hw(struct clk_hw *hw) +{ + return container_of(hw, struct sun8i_pwm_pair, gate_hw); +} + +static int sun8i_pwm_pair_gate_enable(struct clk_hw *hw) +{ + struct sun8i_pwm_pair *pair =3D sun8i_pwm_pair_from_gate_hw(hw); + struct sun8i_pwm_chip *sun8i_chip =3D pair->chip; + u32 pccr; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + pccr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCCR(pair->index)); + pccr |=3D SUN8I_PWM_PCCR_GATE; + sun8i_pwm_writel(sun8i_chip, pccr, SUN8I_PWM_PCCR(pair->index)); + + return 0; +} + +static void sun8i_pwm_pair_gate_disable(struct clk_hw *hw) +{ + struct sun8i_pwm_pair *pair =3D sun8i_pwm_pair_from_gate_hw(hw); + struct sun8i_pwm_chip *sun8i_chip =3D pair->chip; + unsigned long reg =3D SUN8I_PWM_PCCR(pair->index); + u32 pccr, per; + + /* CCF counts do not include outputs awaiting firmware-state handoff. */ + guard(spinlock_irqsave)(&sun8i_chip->lock); + per =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); + if (!(per & sun8i_pwm_pair_enable_mask(pair->index))) { + pccr =3D sun8i_pwm_readl(sun8i_chip, reg); + pccr &=3D ~SUN8I_PWM_PCCR_GATE; + sun8i_pwm_writel(sun8i_chip, pccr, reg); + } +} + +static int sun8i_pwm_pair_gate_is_enabled(struct clk_hw *hw) +{ + struct sun8i_pwm_pair *pair =3D sun8i_pwm_pair_from_gate_hw(hw); + struct sun8i_pwm_chip *sun8i_chip =3D pair->chip; + unsigned long reg =3D SUN8I_PWM_PCCR(pair->index); + + guard(spinlock_irqsave)(&sun8i_chip->lock); + + return !!(sun8i_pwm_readl(sun8i_chip, reg) & SUN8I_PWM_PCCR_GATE); +} + +static const struct clk_ops sun8i_pwm_pair_gate_ops =3D { + .enable =3D sun8i_pwm_pair_gate_enable, + .disable =3D sun8i_pwm_pair_gate_disable, + .is_enabled =3D sun8i_pwm_pair_gate_is_enabled, +}; + +static int sun8i_pwm_pair_rate_notifier(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct sun8i_pwm_pair *pair =3D + container_of(nb, struct sun8i_pwm_pair, rate_nb); + struct sun8i_pwm_chip *sun8i_chip =3D pair->chip; + bool active; + + if (event !=3D PRE_RATE_CHANGE) + return NOTIFY_DONE; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + active =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER) & + sun8i_pwm_pair_enable_mask(pair->index); + + return active ? NOTIFY_BAD : NOTIFY_OK; +} + +static void sun8i_pwm_put_rate(struct sun8i_pwm_chip *sun8i_chip, + unsigned int idx) +{ + struct sun8i_pwm_channel *chan =3D &sun8i_chip->channels[idx]; + bool exclusive; + + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + exclusive =3D chan->rate_exclusive; + chan->rate_exclusive =3D false; + } + /* CCF takes the prepare mutex and may call back into this driver. */ + if (exclusive) + clk_rate_exclusive_put(chan->pair_clk); +} + +static int sun8i_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct sun8i_pwm_chip *sun8i_chip =3D sun8i_pwm_from_chip(chip); + struct sun8i_pwm_channel *chan =3D &sun8i_chip->channels[pwm->hwpwm]; + unsigned int idx =3D pwm->hwpwm; + struct clk_hw *parent =3D sun8i_chip->pairs[SUN8I_PWM_PAIR_IDX(idx)].hw; + bool was_enabled; + int ret; + + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + was_enabled =3D + sun8i_pwm_channel_is_enabled_locked(sun8i_chip, idx); + } + + chan->pair_clk =3D clk_hw_get_clk(parent, NULL); + if (IS_ERR(chan->pair_clk)) { + ret =3D PTR_ERR(chan->pair_clk); + goto err_clear_clock; + } + + if (was_enabled) { + ret =3D clk_rate_exclusive_get(chan->pair_clk); + if (ret) + goto err_put_clock; + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) + chan->rate_exclusive =3D true; + } + + ret =3D clk_prepare_enable(chan->pair_clk); + if (ret) { + sun8i_pwm_put_rate(sun8i_chip, idx); + goto err_put_clock; + } + + return 0; + +err_put_clock: + clk_put(chan->pair_clk); +err_clear_clock: + chan->pair_clk =3D NULL; + + return ret; +} + +static void sun8i_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct sun8i_pwm_chip *sun8i_chip =3D sun8i_pwm_from_chip(chip); + struct sun8i_pwm_channel *chan =3D &sun8i_chip->channels[pwm->hwpwm]; + + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + sun8i_pwm_set_enabled_locked(sun8i_chip, pwm->hwpwm, false); + sun8i_pwm_set_bypass_locked(sun8i_chip, pwm->hwpwm, false); + } + + sun8i_pwm_put_rate(sun8i_chip, pwm->hwpwm); + clk_disable_unprepare(chan->pair_clk); + clk_put(chan->pair_clk); + chan->pair_clk =3D NULL; +} + +static int sun8i_pwm_read_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, + void *_wfhw) +{ + struct sun8i_pwm_waveform *wfhw =3D _wfhw; + struct sun8i_pwm_chip *sun8i_chip =3D sun8i_pwm_from_chip(chip); + unsigned int pair =3D SUN8I_PWM_PAIR_IDX(pwm->hwpwm); + unsigned long pair_rate; + u32 pccr, pcr, pdzcr, per, ppr; + + pair_rate =3D sun8i_pwm_get_pair_rate(sun8i_chip, pwm->hwpwm); + if (pair_rate > U32_MAX) + return -ERANGE; + + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + pccr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCCR(pair)); + per =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); + pcr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCR(pwm->hwpwm)); + ppr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PPR(pwm->hwpwm)); + pdzcr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PDZCR(pair)); + } + + *wfhw =3D (struct sun8i_pwm_waveform) { + .enabled =3D !!(pccr & SUN8I_PWM_PCCR_GATE) && + !!(per & SUN8I_PWM_ENABLE(pwm->hwpwm)), + .bypass_en =3D !!(pccr & + BIT(SUN8I_PWM_PCCR_BYPASS_BIT(pwm->hwpwm))), + .pcr =3D pcr & SUN8I_PWM_PCR_WAVEFORM_MASK, + .ppr =3D ppr, + .pair_rate =3D pair_rate, + }; + + /* The waveform API cannot describe coupled dead-zone or pulse mode. */ + if (wfhw->enabled && !wfhw->bypass_en && + ((pdzcr & SUN8I_PWM_PDZCR_ENABLE) || (pcr & SUN8I_PWM_PCR_MODE))) + return -EOPNOTSUPP; + + return 0; +} + +static u64 sun8i_pwm_ticks_to_ns(u32 ticks, u16 div_k, u32 pair_rate) +{ + return DIV_ROUND_UP_ULL(NSEC_PER_SEC * (u64)ticks * div_k, + pair_rate); +} + +static u64 sun8i_pwm_period_ns(const struct sun8i_pwm_waveform *wfhw) +{ + if (wfhw->bypass_en) + return DIV_ROUND_UP_ULL(NSEC_PER_SEC, wfhw->pair_rate); + + return sun8i_pwm_ticks_to_ns(SUN8I_PWM_PPR_PERIOD_VALUE(wfhw->ppr), + FIELD_GET(SUN8I_PWM_PCR_PRESCAL_K_MASK, wfhw->pcr) + 1, + wfhw->pair_rate); +} + +static void +__sun8i_pwm_round_waveform_fromhw(const struct sun8i_pwm_waveform *wfhw, + struct pwm_waveform *wf) +{ + u32 pair_rate =3D wfhw->pair_rate; + u32 period_ticks =3D SUN8I_PWM_PPR_PERIOD_VALUE(wfhw->ppr); + u32 duty_ticks =3D SUN8I_PWM_PPR_DUTY_VALUE(wfhw->ppr); + u16 div_k =3D FIELD_GET(SUN8I_PWM_PCR_PRESCAL_K_MASK, wfhw->pcr) + 1; + + wf->duty_offset_ns =3D 0; + + if (!wfhw->enabled || !pair_rate) { + wf->period_length_ns =3D 0; + wf->duty_length_ns =3D 0; + return; + } + + wf->period_length_ns =3D sun8i_pwm_period_ns(wfhw); + if (wfhw->bypass_en) { + wf->duty_length_ns =3D + DIV_ROUND_UP_ULL(NSEC_PER_SEC, + 2ULL * pair_rate); + return; + } + + duty_ticks =3D min(duty_ticks, period_ticks); + if (!(wfhw->pcr & SUN8I_PWM_PCR_ACTIVE_STATE)) { + /* Constant outputs have no edge and therefore no offset. */ + if (duty_ticks && duty_ticks < period_ticks) + wf->duty_offset_ns =3D + sun8i_pwm_ticks_to_ns(duty_ticks, div_k, pair_rate); + duty_ticks =3D period_ticks - duty_ticks; + } + wf->duty_length_ns =3D sun8i_pwm_ticks_to_ns(duty_ticks, div_k, pair_rate= ); +} + +static int sun8i_pwm_round_waveform_fromhw(struct pwm_chip *chip, + struct pwm_device *pwm, + const void *_wfhw, + struct pwm_waveform *wf) +{ + const struct sun8i_pwm_waveform *wfhw =3D _wfhw; + + __sun8i_pwm_round_waveform_fromhw(wfhw, wf); + + dev_dbg(pwmchip_parent(chip), + "pwm#%u: pair-rate=3D%u, pcr=3D%#x, ppr=3D%#x, bypass=3D%u -> %llu/%llu = [+%llu]\n", + pwm->hwpwm, wfhw->pair_rate, wfhw->pcr, wfhw->ppr, + wfhw->bypass_en, + wf->duty_length_ns, wf->period_length_ns, + wf->duty_offset_ns); + + return 0; +} + +static bool +sun8i_pwm_pair_rate_constrained(struct sun8i_pwm_chip *sun8i_chip, + unsigned int idx) +{ + unsigned int sibling =3D idx ^ 1; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + return sun8i_chip->channels[sibling].rate_exclusive || + sun8i_pwm_channel_is_enabled_locked(sun8i_chip, sibling); +} + +static int sun8i_pwm_clear_idle_deadzone(struct sun8i_pwm_chip *sun8i_chip, + unsigned int idx) +{ + unsigned int pair =3D SUN8I_PWM_PAIR_IDX(idx); + u32 pdzcr, per; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + pdzcr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PDZCR(pair)); + if (!(pdzcr & SUN8I_PWM_PDZCR_ENABLE)) + return 0; + + per =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); + if (per & sun8i_pwm_pair_enable_mask(pair)) + return -EOPNOTSUPP; + + pdzcr &=3D ~SUN8I_PWM_PDZCR_ENABLE; + sun8i_pwm_writel(sun8i_chip, pdzcr, SUN8I_PWM_PDZCR(pair)); + + return 0; +} + +static u64 sun8i_pwm_max_period_ns(struct sun8i_pwm_chip *sun8i_chip, + unsigned int idx) +{ + unsigned long pair_rate; + u32 pcr; + u16 div_k; + + pair_rate =3D sun8i_pwm_get_pair_rate(sun8i_chip, idx); + if (!pair_rate || pair_rate > U32_MAX) + return 0; + + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + pcr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCR(idx)); + } + div_k =3D FIELD_GET(SUN8I_PWM_PCR_PRESCAL_K_MASK, pcr) + 1; + + return sun8i_pwm_ticks_to_ns(SUN8I_PWM_PPR_PERIOD_MAX, div_k, + pair_rate); +} + +static int sun8i_pwm_wait_period_ready(struct pwm_chip *chip, unsigned int= idx) +{ + struct sun8i_pwm_chip *sun8i_chip =3D sun8i_pwm_from_chip(chip); + struct sun8i_pwm_channel *chan =3D &sun8i_chip->channels[idx]; + unsigned long poll_us; + u64 period_ns, timeout_us; + u32 val; + int ret; + + /* PPR contains the pending value, not necessarily the active period. */ + period_ns =3D chan->pending_period_ns; + if (!period_ns) + period_ns =3D sun8i_pwm_max_period_ns(sun8i_chip, idx); + timeout_us =3D DIV_ROUND_UP_ULL(period_ns, NSEC_PER_USEC) + + SUN8I_PWM_PERIOD_READY_MARGIN_US; + poll_us =3D clamp_t(u64, + DIV_ROUND_UP_ULL(timeout_us, + SUN8I_PWM_PERIOD_READY_POLL_COUNT), + SUN8I_PWM_PERIOD_READY_MIN_POLL_US, + SUN8I_PWM_PERIOD_READY_MAX_POLL_US); + + ret =3D readl_poll_timeout(sun8i_chip->base + SUN8I_PWM_PCR(idx), val, + !(val & SUN8I_PWM_PCR_PERIOD_READY), poll_us, + timeout_us); + if (!ret) + chan->pending_period_ns =3D 0; + else + dev_err_ratelimited(pwmchip_parent(chip), + "pwm#%u: update timeout after %llu us\n", + idx, timeout_us); + + return ret; +} + +/* + * Protect the rate and quiesce the output if a live update is unsafe. On + * failure restore the old clock before restarting an output we stopped. + * CCF operations must stay outside the register lock. + */ +static int sun8i_pwm_prepare_update(struct pwm_chip *chip, unsigned int id= x, + const struct sun8i_pwm_waveform *wfhw, + struct sun8i_pwm_waveform *old) +{ + struct sun8i_pwm_chip *sun8i_chip =3D sun8i_pwm_from_chip(chip); + struct sun8i_pwm_channel *chan =3D &sun8i_chip->channels[idx]; + unsigned long rate, bus_rate; + bool had_exclusive, stop; + u32 pccr; + int ret, restore_ret; + + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) + had_exclusive =3D chan->rate_exclusive; + + if (!had_exclusive) { + ret =3D clk_rate_exclusive_get(chan->pair_clk); + if (ret) + return ret; + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) + chan->rate_exclusive =3D true; + } + + /* Sample the old rate only after excluding other rate changes. */ + rate =3D sun8i_pwm_get_pair_rate(sun8i_chip, idx); + if (!rate || rate > U32_MAX) { + ret =3D -ERANGE; + goto put_rate; + } + old->pair_rate =3D rate; + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + old->enabled =3D sun8i_pwm_channel_is_enabled_locked(sun8i_chip, idx); + pccr =3D sun8i_pwm_readl(sun8i_chip, + SUN8I_PWM_PCCR(SUN8I_PWM_PAIR_IDX(idx))); + old->bypass_en =3D !!(pccr & BIT(SUN8I_PWM_PCCR_BYPASS_BIT(idx))); + old->pcr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCR(idx)); + old->ppr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PPR(idx)); + } + + if (rate !=3D wfhw->pair_rate && + sun8i_pwm_pair_rate_constrained(sun8i_chip, idx)) { + ret =3D -EBUSY; + goto put_rate; + } + + /* Live PPR updates require unchanged configuration and a faster PCLK. */ + bus_rate =3D clk_get_rate(sun8i_chip->bus_clk); + stop =3D old->enabled && + (old->bypass_en !=3D wfhw->bypass_en || rate !=3D wfhw->pair_rate || + (!wfhw->bypass_en && + (((old->pcr ^ wfhw->pcr) & + (SUN8I_PWM_PCR_WAVEFORM_MASK | SUN8I_PWM_PCR_MODE)) || + bus_rate <=3D DIV_ROUND_UP_ULL(wfhw->pair_rate, + FIELD_GET(SUN8I_PWM_PCR_PRESCAL_K_MASK, wfhw->pcr) + 1)))); + if (stop) { + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) + sun8i_pwm_set_enabled_locked(sun8i_chip, idx, false); + } + + if (rate =3D=3D wfhw->pair_rate) + return 0; + + ret =3D clk_set_rate(chan->pair_clk, wfhw->pair_rate); + if (!ret && sun8i_pwm_get_pair_rate(sun8i_chip, idx) =3D=3D wfhw->pair_ra= te) + return 0; + if (!ret) + ret =3D -EINVAL; + + if (sun8i_pwm_get_pair_rate(sun8i_chip, idx) !=3D rate) { + restore_ret =3D clk_set_rate(chan->pair_clk, rate); + if (restore_ret || sun8i_pwm_get_pair_rate(sun8i_chip, idx) !=3D rate) { + dev_err(pwmchip_parent(chip), + "pwm#%u: failed to restore pair clock rate %lu\n", + idx, rate); + goto put_rate; + } + } + if (stop) { + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) + sun8i_pwm_set_enabled_locked(sun8i_chip, idx, true); + } +put_rate: + if (!had_exclusive) + sun8i_pwm_put_rate(sun8i_chip, idx); + + return ret; +} + +static int sun8i_pwm_write_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, const void *_wfhw) +{ + const struct sun8i_pwm_waveform *wfhw =3D _wfhw; + struct sun8i_pwm_chip *sun8i_chip =3D sun8i_pwm_from_chip(chip); + struct sun8i_pwm_channel *chan =3D &sun8i_chip->channels[pwm->hwpwm]; + struct sun8i_pwm_waveform old; + u64 old_ns =3D 0, new_ns; + u32 pcr; + int ret; + + if (!wfhw->enabled) { + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + sun8i_pwm_set_enabled_locked(sun8i_chip, pwm->hwpwm, false); + sun8i_pwm_set_bypass_locked(sun8i_chip, pwm->hwpwm, false); + } + sun8i_pwm_put_rate(sun8i_chip, pwm->hwpwm); + return 0; + } + + if (!wfhw->bypass_en) { + ret =3D sun8i_pwm_clear_idle_deadzone(sun8i_chip, pwm->hwpwm); + if (ret) + return ret; + ret =3D sun8i_pwm_wait_period_ready(chip, pwm->hwpwm); + if (ret) + return ret; + } + + ret =3D sun8i_pwm_prepare_update(chip, pwm->hwpwm, wfhw, &old); + if (ret) + return ret; + + if (!wfhw->bypass_en) { + /* Apply only waveform fields; never replay status or W1S bits. */ + pcr =3D old.pcr & ~(SUN8I_PWM_PCR_WAVEFORM_MASK | + SUN8I_PWM_PCR_MODE | SUN8I_PWM_PCR_PULSE_START | + SUN8I_PWM_PCR_PERIOD_READY); + sun8i_pwm_writel(sun8i_chip, pcr | wfhw->pcr, + SUN8I_PWM_PCR(pwm->hwpwm)); + + if (old.enabled && !old.bypass_en) + old_ns =3D sun8i_pwm_period_ns(&old); + new_ns =3D sun8i_pwm_period_ns(wfhw); + chan->pending_period_ns =3D max(old_ns, new_ns); + sun8i_pwm_writel(sun8i_chip, wfhw->ppr, SUN8I_PWM_PPR(pwm->hwpwm)); + } + + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + sun8i_pwm_set_bypass_locked(sun8i_chip, pwm->hwpwm, wfhw->bypass_en); + sun8i_pwm_set_enabled_locked(sun8i_chip, pwm->hwpwm, true); + } + + return 0; +} + +struct sun8i_pwm_rounding { + const struct pwm_waveform *requested; + struct sun8i_pwm_waveform best; + struct pwm_waveform best_wf; + u32 current_pair_rate; + bool have_best; +}; + +static void +sun8i_pwm_choose_waveform(struct sun8i_pwm_rounding *rounding, + const struct sun8i_pwm_waveform *candidate) +{ + const struct pwm_waveform *requested =3D rounding->requested; + const struct pwm_waveform *best =3D &rounding->best_wf; + struct pwm_waveform wf; + bool better; + + __sun8i_pwm_round_waveform_fromhw(candidate, &wf); + /* A zero-duty, zero-offset cycle-mode candidate always exists. */ + if (wf.duty_length_ns > requested->duty_length_ns || + wf.duty_offset_ns > requested->duty_offset_ns) + return; + + if (!rounding->have_best) { + better =3D true; + } else if (wf.period_length_ns !=3D best->period_length_ns) { + /* Prefer the longest period below the request, else the shortest. */ + if (wf.period_length_ns > requested->period_length_ns) + better =3D wf.period_length_ns < best->period_length_ns; + else + better =3D best->period_length_ns > requested->period_length_ns || + wf.period_length_ns > best->period_length_ns; + } else if (wf.duty_length_ns !=3D best->duty_length_ns) { + better =3D wf.duty_length_ns > best->duty_length_ns; + } else if (wf.duty_offset_ns !=3D best->duty_offset_ns) { + better =3D wf.duty_offset_ns > best->duty_offset_ns; + } else { + /* Prefer the current pair rate when waveforms are equivalent. */ + better =3D candidate->pair_rate =3D=3D rounding->current_pair_rate && + rounding->best.pair_rate !=3D rounding->current_pair_rate; + } + if (!better) + return; + + rounding->best =3D *candidate; + rounding->best_wf =3D wf; + rounding->have_best =3D true; +} + +static struct sun8i_pwm_waveform +sun8i_pwm_round_cycle(const struct pwm_waveform *requested, u32 pair_rate, + u16 div_k) +{ + struct sun8i_pwm_waveform candidate =3D { + .enabled =3D true, + .pair_rate =3D pair_rate, + .pcr =3D FIELD_PREP(SUN8I_PWM_PCR_PRESCAL_K_MASK, div_k - 1), + }; + u64 denominator =3D NSEC_PER_SEC * (u64)div_k; + u64 duty_ticks, period_ticks; + u32 inactive_ticks; + + /* Floor division rounds down, except for the minimum one-tick period. */ + period_ticks =3D mul_u64_u64_div_u64(requested->period_length_ns, + pair_rate, denominator); + period_ticks =3D clamp_t(u64, period_ticks, 1, SUN8I_PWM_PPR_PERIOD_MAX); + duty_ticks =3D mul_u64_u64_div_u64(requested->duty_length_ns, + pair_rate, denominator); + duty_ticks =3D min(duty_ticks, period_ticks); + + /* + * Zero active ticks encode either constant level. For a toggling + * waveform, active-low mode places the rising edge after the inactive + * part, which is the only non-zero offset supported by the hardware. + */ + if (!duty_ticks) { + candidate.pcr |=3D SUN8I_PWM_PCR_ACTIVE_STATE; + } else if (duty_ticks =3D=3D period_ticks) { + duty_ticks =3D 0; + } else { + inactive_ticks =3D period_ticks - duty_ticks; + if (sun8i_pwm_ticks_to_ns(inactive_ticks, div_k, pair_rate) <=3D + requested->duty_offset_ns) + duty_ticks =3D inactive_ticks; + else + candidate.pcr |=3D SUN8I_PWM_PCR_ACTIVE_STATE; + } + + candidate.ppr =3D SUN8I_PWM_PPR_PERIOD(period_ticks) | + SUN8I_PWM_PPR_DUTY(duty_ticks); + + return candidate; +} + +static void +sun8i_pwm_consider_pair_rate(struct sun8i_pwm_rounding *rounding, u32 pair= _rate) +{ + struct sun8i_pwm_waveform candidate; + + for (unsigned int div_k =3D 1; div_k <=3D 256; div_k++) { + candidate =3D sun8i_pwm_round_cycle(rounding->requested, pair_rate, div_= k); + sun8i_pwm_choose_waveform(rounding, &candidate); + } + + candidate =3D (struct sun8i_pwm_waveform) { + .pair_rate =3D pair_rate, + .enabled =3D true, + .bypass_en =3D true, + }; + sun8i_pwm_choose_waveform(rounding, &candidate); +} + +static int sun8i_pwm_round_waveform_tohw(struct pwm_chip *chip, + struct pwm_device *pwm, + const struct pwm_waveform *wf, + void *_wfhw) +{ + struct sun8i_pwm_chip *sun8i_chip =3D sun8i_pwm_from_chip(chip); + struct sun8i_pwm_pair *pair =3D + &sun8i_chip->pairs[SUN8I_PWM_PAIR_IDX(pwm->hwpwm)]; + struct sun8i_pwm_waveform *wfhw =3D _wfhw; + struct sun8i_pwm_rounding rounding =3D { + .requested =3D wf, + }; + unsigned long current_rate; + + if (!wf->period_length_ns) { + *wfhw =3D (struct sun8i_pwm_waveform) { + .enabled =3D false, + }; + return 0; + } + + current_rate =3D sun8i_pwm_get_pair_rate(sun8i_chip, pwm->hwpwm); + if (!current_rate || current_rate > U32_MAX) + return -ERANGE; + rounding.current_pair_rate =3D current_rate; + + if (sun8i_pwm_pair_rate_constrained(sun8i_chip, pwm->hwpwm)) { + sun8i_pwm_consider_pair_rate(&rounding, current_rate); + } else { + for (unsigned int parent_idx =3D 0; + parent_idx < clk_hw_get_num_parents(pair->hw); + parent_idx++) { + struct clk_hw *parent; + unsigned long parent_rate; + + parent =3D clk_hw_get_parent_by_index(pair->hw, parent_idx); + if (!parent) + continue; + parent_rate =3D clk_hw_get_rate(parent); + if (!parent_rate) + continue; + + for (unsigned int i =3D 0; sun8i_pwm_div_m_table[i].div; + i++) { + u16 div_m =3D sun8i_pwm_div_m_table[i].div; + u64 pair_rate; + + pair_rate =3D DIV_ROUND_UP_ULL(parent_rate, div_m); + if (!pair_rate || pair_rate > U32_MAX) + continue; + sun8i_pwm_consider_pair_rate(&rounding, pair_rate); + } + } + } + + if (!rounding.have_best) + return -EINVAL; + *wfhw =3D rounding.best; + + dev_dbg(pwmchip_parent(chip), + "pwm#%u: %llu/%llu [+%llu] -> pair-rate=3D%u, pcr=3D%#x, ppr=3D%#x, bypa= ss=3D%u\n", + pwm->hwpwm, wf->duty_length_ns, wf->period_length_ns, + wf->duty_offset_ns, wfhw->pair_rate, wfhw->pcr, wfhw->ppr, + wfhw->bypass_en); + + return rounding.best_wf.period_length_ns > wf->period_length_ns; +} + +static const struct pwm_ops sun8i_pwm_ops =3D { + .request =3D sun8i_pwm_request, + .free =3D sun8i_pwm_free, + .sizeof_wfhw =3D sizeof(struct sun8i_pwm_waveform), + .round_waveform_tohw =3D sun8i_pwm_round_waveform_tohw, + .round_waveform_fromhw =3D sun8i_pwm_round_waveform_fromhw, + .read_waveform =3D sun8i_pwm_read_waveform, + .write_waveform =3D sun8i_pwm_write_waveform, +}; + +/* Register the shared mux, gate and /div_m clock for each channel pair. */ +static int sun8i_pwm_register_pair_clocks(struct device *dev, + struct sun8i_pwm_chip *sun8i_chip) +{ + static const struct clk_parent_data parent_data[] =3D { + { .index =3D 0 }, + { .index =3D 1 }, + }; + + for (unsigned int i =3D 0; i < SUN8I_PWM_NPAIRS; i++) { + struct sun8i_pwm_pair *pair =3D &sun8i_chip->pairs[i]; + void __iomem *reg =3D sun8i_chip->base + SUN8I_PWM_PCCR(i); + const char *name; + int ret; + + name =3D devm_kasprintf(dev, GFP_KERNEL, + "%s#pwm-clk-src%u%u", dev_name(dev), + i * 2, i * 2 + 1); + if (!name) + return -ENOMEM; + + pair->mux.reg =3D reg; + pair->mux.shift =3D SUN8I_PWM_PCCR_SRC_SHIFT; + pair->mux.mask =3D SUN8I_PWM_PCCR_SRC_MASK; + pair->mux.flags =3D CLK_MUX_ROUND_CLOSEST; + pair->mux.lock =3D &sun8i_chip->lock; + + pair->chip =3D sun8i_chip; + pair->index =3D i; + + pair->divider.reg =3D reg; + pair->divider.shift =3D SUN8I_PWM_PCCR_DIV_M_SHIFT; + pair->divider.width =3D SUN8I_PWM_PCCR_DIV_M_WIDTH; + pair->divider.table =3D sun8i_pwm_div_m_table; + pair->divider.lock =3D &sun8i_chip->lock; + + pair->hw =3D devm_clk_hw_register_composite_pdata(dev, name, + parent_data, + ARRAY_SIZE(parent_data), + &pair->mux.hw, &clk_mux_ops, + &pair->divider.hw, &clk_divider_ops, + &pair->gate_hw, &sun8i_pwm_pair_gate_ops, 0); + if (IS_ERR(pair->hw)) + return dev_err_probe(dev, PTR_ERR(pair->hw), + "Failed to register pair %u clock\n", i); + + /* Borrow CCF's handle so registration cannot pin this module. */ + pair->rate_nb.notifier_call =3D sun8i_pwm_pair_rate_notifier; + ret =3D devm_clk_notifier_register(dev, pair->hw->clk, &pair->rate_nb); + if (ret) + return dev_err_probe(dev, ret, + "Failed to protect pair %u clock rate\n", i); + } + + return 0; +} + +/* + * A disabled pair gate makes any set PER bits ineffective. Clear those st= ale + * enables before a clock consumer can turn the shared gate on and expose = an + * unrequested output. + */ +static void +sun8i_pwm_sanitize_disabled_pairs(struct sun8i_pwm_chip *sun8i_chip) +{ + u32 per; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + per =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); + for (unsigned int pair =3D 0; pair < SUN8I_PWM_NPAIRS; pair++) { + unsigned int first =3D pair * 2; + u32 pccr; + + pccr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCCR(pair)); + if (pccr & SUN8I_PWM_PCCR_GATE) + continue; + + per &=3D ~sun8i_pwm_pair_enable_mask(pair); + pccr &=3D ~BIT(SUN8I_PWM_PCCR_BYPASS_BIT(first)); + pccr &=3D ~BIT(SUN8I_PWM_PCCR_BYPASS_BIT(first + 1)); + sun8i_pwm_writel(sun8i_chip, pccr, SUN8I_PWM_PCCR(pair)); + } + sun8i_pwm_writel(sun8i_chip, per, SUN8I_PWM_PER); +} + +static int sun8i_pwm_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct sun8i_pwm_chip *sun8i_chip; + struct reset_control *rst; + struct pwm_chip *chip; + int ret; + + chip =3D devm_pwmchip_alloc(dev, SUN8I_PWM_NPWM, sizeof(*sun8i_chip)); + if (IS_ERR(chip)) + return dev_err_probe(dev, PTR_ERR(chip), + "Failed to allocate pwmchip\n"); + + sun8i_chip =3D sun8i_pwm_from_chip(chip); + spin_lock_init(&sun8i_chip->lock); + sun8i_chip->base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(sun8i_chip->base)) + return dev_err_probe(dev, PTR_ERR(sun8i_chip->base), + "Failed to get PWM base address\n"); + + sun8i_chip->bus_clk =3D devm_clk_get_enabled(dev, "bus"); + if (IS_ERR(sun8i_chip->bus_clk)) + return dev_err_probe(dev, PTR_ERR(sun8i_chip->bus_clk), + "Failed to get bus clock\n"); + + rst =3D devm_reset_control_get_shared_deasserted(dev, NULL); + if (IS_ERR(rst)) + return dev_err_probe(dev, PTR_ERR(rst), + "Failed to get reset control\n"); + + chip->ops =3D &sun8i_pwm_ops; + + sun8i_pwm_sanitize_disabled_pairs(sun8i_chip); + + ret =3D sun8i_pwm_register_pair_clocks(dev, sun8i_chip); + if (ret) + return ret; + + ret =3D devm_pwmchip_add(dev, chip); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to add PWM chip\n"); + + return 0; +} + +static const struct of_device_id sun8i_pwm_dt_ids[] =3D { + { + .compatible =3D "allwinner,sun50i-h616-pwm", + }, { + /* sentinel */ + } +}; +MODULE_DEVICE_TABLE(of, sun8i_pwm_dt_ids); + +static struct platform_driver sun8i_pwm_driver =3D { + .driver =3D { + .name =3D "sun8i-pwm", + .of_match_table =3D sun8i_pwm_dt_ids, + }, + .probe =3D sun8i_pwm_probe, +}; +module_platform_driver(sun8i_pwm_driver); + +MODULE_AUTHOR("Richard Genoud "); +MODULE_DESCRIPTION("Allwinner sun8i PWM driver"); +MODULE_LICENSE("GPL"); --=20 2.53.0 From nobody Thu Sep 24 13:41:52 2026 Received: from mail-oi2-f13.google.com (mail-oi2-f13.google.com [74.125.231.205]) (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 32695437846 for ; Wed, 23 Sep 2026 05:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141792; cv=none; b=dUbnMe6ACZoanmWhhQFF80g6hjLD52VTGrUX2WTSlPe1c6vKrjVZff93LanlU1AHEd30MX0RBTvlb2EvdQ+qSayN3TgcRezLy4VkfPZ8Jm48RQUJQ0AIUUkLxIlWTrUACYGhsy8L1Zv2nNZ5O2izUXAH9p7d+Z0y1zyeCpzeGtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141792; c=relaxed/simple; bh=qEF0C4lsHKeFuSDGZ09aNZCGxWyI9mBkVDKPyBuQmvA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FHHr/XqfcHQmp9Ow8Wsgb87bWvtsjAQYEM1rGYKVj/poXzuQAk0AEF0cwob2FJDulTSLbiY6cSu9w2ZvTgqTdXv+hbC3HwT7NLpuS6E6PzDrbxMoNWwadVIxN5HgrLkmSGzXu5R6XwQLf/q0IWtDGmg3qQ4hqUv73FgTQrokc9I= 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=L9BBnPt3; arc=none smtp.client-ip=74.125.231.205 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="L9BBnPt3" Received: by mail-oi2-f13.google.com with SMTP id 5614622812f47-4c112aaaf04so419972b6e.1 for ; Tue, 22 Sep 2026 22:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790141787; x=1790746587; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NgzL3+0VR2vstrnTbSdTY8Jq1CjVKq1PLO3C8WC/P48=; b=L9BBnPt3iLaM/QhWpBPmqWf8bhqBRZgDs8QTG9OtZXldwnInGHshasoH/BowcJXabZ r1jRTT/6/c1NSJ/A5qicj2PBjxX6uaIHyTbwdqqATi9CuTTwZLoA5g+k5jXuS1kPbIOo Kwsa0tnj7UDSsvwg3o0L86uKk9FleUkLp64atRYFbL5dGp7B+YMKFA4tn18N9N8m6pyr uliaG2GY+MiVbjvhjr3GYV4PT4O2CsHze0raosQT1jQalfXAhPQ6Hg4Kb1fBaGvZL6/D zcizJmCpUbquIN1AXeoyPdtIa7PKlhsrJbATpkyHNCa5iPkTU574COG+B/ImicEJnB+b UtqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790141787; x=1790746587; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=NgzL3+0VR2vstrnTbSdTY8Jq1CjVKq1PLO3C8WC/P48=; b=DXlTnW9qtuzT+BZxN0mK8XcTmXfmByrGsbnunhmUM1ntnvJ6wmgM1UsWcPF3ONrskV tTeZ5g5qdSvm+hroYxusuBwvTLCyvsXN3Te9KRRdx61AVI0Zg3nxMb8P1Vy7viM+7ZVk SGn3A2fnbFNVTi3OQNahmMOu5a3g9mokOeW++kXYYCSlW8GYavxapF6h4Jb2UDJStgKV d/xepQSsSTBoRCVu/YOH0U13rxqb0YgmZglxfWQkCKHO6XPNHlSlD30OZB7L/pa0hLaS ieiBJFvq6ypC+MSCbDRaSHMjRVxM9qFwTOMCt15AiYifGrwUzxPn1GRKx5xEt6FyWk2d h0sw== X-Forwarded-Encrypted: i=1; AKwUvBx8qD8VGEiUBnbdKigqkgbwlgPCtMaaD1CiGh40QZwiwf5+dklVigLlLQzHixYsu2Vy+6xVpCx8cWlgbJI=@vger.kernel.org X-Gm-Message-State: AFuF++njcYHBtDaKYA7IggP6Ip8gSz07U8nYrU65mwh+LAZppHurKBXb aCpK9Z5YK2fZ2MczAIpsy7chavFIT6BBVC6YTG1Jm+dPcGggDcNDKX0C X-Gm-Gg: AYBFou13COrN8gmcbPIpjpsZtY1JFz05nvKMGx1QCFveKx8bNsohZl9FcaKxHW+0Iky z4h/Q4QSMMpjtSFfgdwsojRSscM7Ts43ipQu2Hb8xHwrA6l0YS4SDkbnil8yL4/aBQg64pwcsh5 ldgTrGUV9/wjANNdpr1CyuPDLznElU8b8tx15CunaJbg7NR70p9stlzXM/fF3jhYbXu/qHCLXmB i55XVeAkQMBqmwOa0x3st8AFcB3CJRcaOkMS+d48LadoJP6N1WlI5GVK4VgEVsPd9DH2vc3ynk0 rwv0fktbtYLq4UjYo9H96LAqPi6EdZLTDjg9cES0Nf5FugL3w5kfB1UxGEI6fAPrPOLzlXhzV8q tdgRNvSY0jzicgR1p7vEksdU4Kxl0glQoFHa06BfRmy5oeZnPrNMnVWScgOp3YurCzBX7V7yLOG v0T6if62bLZF0ouG/exVsiwNlhx4iR3NQB5jNgTrU+yo4Yc0LLWqGBOOmdRnWhsb8rsNzjjqXm+ YBzhoIs6mKHCB4bIpOb0SQpNQA82QGBMelvtjRACtjMsMqrG5h0GVctbUXIOKwmHwxJjhZMV79j Y/DWS3U/CkEHvg8I7BLXne8UTmEP6yt0HCz/SKqS/5VlD5zAERU/2iFIXQixThmm6DaZCQOv+AA WMlygFiiuS8mglrBzqh5V X-Received: by 2002:a05:6808:4701:b0:4c3:ee9e:200d with SMTP id 5614622812f47-4d5b6eeed37mr1593391b6e.7.1790141786875; Tue, 22 Sep 2026 22:36:26 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4d5c4aed99bsm1436896b6e.12.2026.09.22.22.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 22:36:26 -0700 (PDT) From: James Hilliard Date: Tue, 22 Sep 2026 23:36:16 -0600 Subject: [PATCH v10 3/5] pwm: sun8i: export the bypass outputs as clocks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260922-h616-pwm-v8-v10-3-dccebbe1aabf@gmail.com> References: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> In-Reply-To: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Stephen Boyd , Brian Masney , Jerome Brunet , Richard Genoud , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard Cc: Philipp Zabel , Michael Turquette , Paul Kocialkowski , Thomas Petazzoni , John Stultz , Joao Schim , bigunclemax@gmail.com, linux-pwm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.15.2 From: Richard Genoud Expose each H616 PWM channel's hardware bypass as a CCF clock. Consumers such as the co-packaged AC200/AC300 PHY need a clock rather than PWM duty or polarity control. Keep the pair source protected for the complete prepared lifetime, and arbitrate ownership between PWM requests and clock prepare so both interfaces cannot drive the same output. drivers/clk/clk-pwm.c advertises a fixed frequency without reading back the rounded PWM rate. A 42 ns, 21 ns request does select 24 MHz bypass when it is available. However, with the pair constrained to 100 MHz by its sibling, the PWM rounding rules select a 40 ns, 20 ns waveform (25 MHz), while a pwm-clock configured for 24 MHz still reports 24 MHz. The direct provider instead reports the actual pair rate and makes its shared-rate protection visible to CCF. Consumers must still check the rate they receive. Use CLK_IGNORE_UNUSED to preserve unclaimed firmware bypass outputs, just as the PWM path preserves inherited waveforms. Normal consumer disable still turns the output off and releases its shared gate reference. Signed-off-by: Richard Genoud Co-developed-by: James Hilliard Signed-off-by: James Hilliard --- drivers/pwm/Kconfig | 3 +- drivers/pwm/pwm-sun8i.c | 180 ++++++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 180 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index d87d166e7836..d3c35a11859f 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -754,7 +754,8 @@ config PWM_SUN8I depends on HAS_IOMEM && COMMON_CLK help PWM framework driver for Allwinner controllers whose channels share - paired source clocks. + paired source clocks. In addition to PWM operation, each channel's + hardware bypass path can be exported as a clock output. =20 To compile this driver as a module, choose M here: the module will be called pwm-sun8i. diff --git a/drivers/pwm/pwm-sun8i.c b/drivers/pwm/pwm-sun8i.c index 7e6c39815c18..2a687ecb6adc 100644 --- a/drivers/pwm/pwm-sun8i.c +++ b/drivers/pwm/pwm-sun8i.c @@ -113,6 +113,9 @@ * The bypass in PWM mode is used to achieve a 1/2 relative duty cycle wit= h the * fastest clock. * + * SUN8I_PWM_clock_x/y serve for the PWM purpose. + * SUN8I_PWM_bypass_clock_x/y serve for the clock-provider purpose. + * */ =20 /* /div_m is a power-of-two divider limited to /256. */ @@ -129,6 +132,12 @@ static const struct clk_div_table sun8i_pwm_div_m_tabl= e[] =3D { { /* sentinel */ } }; =20 +enum sun8i_pwm_mode { + SUN8I_PWM_MODE_NONE, + SUN8I_PWM_MODE_PWM, + SUN8I_PWM_MODE_CLK, +}; + struct sun8i_pwm_chip; =20 struct sun8i_pwm_pair { @@ -142,8 +151,12 @@ struct sun8i_pwm_pair { }; =20 struct sun8i_pwm_channel { + struct clk_hw bypass_hw; + struct sun8i_pwm_chip *chip; + unsigned int index; /* Separate CCF consumer, held only from PWM request to free. */ struct clk *pair_clk; + enum sun8i_pwm_mode mode; u64 pending_period_ns; bool rate_exclusive; }; @@ -153,7 +166,7 @@ struct sun8i_pwm_chip { struct sun8i_pwm_channel channels[SUN8I_PWM_NPWM]; struct clk *bus_clk; void __iomem *base; - /* Protects shared registers and rate_exclusive. */ + /* Protects shared registers, channel ownership and rate_exclusive. */ spinlock_t lock; }; =20 @@ -317,6 +330,101 @@ static int sun8i_pwm_pair_rate_notifier(struct notifi= er_block *nb, return active ? NOTIFY_BAD : NOTIFY_OK; } =20 +static inline struct sun8i_pwm_channel * +sun8i_pwm_channel_from_hw(struct clk_hw *hw) +{ + return container_of(hw, struct sun8i_pwm_channel, bypass_hw); +} + +static int sun8i_pwm_bypass_prepare(struct clk_hw *hw) +{ + struct sun8i_pwm_channel *chan =3D sun8i_pwm_channel_from_hw(hw); + struct sun8i_pwm_chip *sun8i_chip =3D chan->chip; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + if (chan->mode !=3D SUN8I_PWM_MODE_NONE) + return -EBUSY; + + chan->mode =3D SUN8I_PWM_MODE_CLK; + return 0; +} + +static void sun8i_pwm_bypass_unprepare(struct clk_hw *hw) +{ + struct sun8i_pwm_channel *chan =3D sun8i_pwm_channel_from_hw(hw); + struct sun8i_pwm_chip *sun8i_chip =3D chan->chip; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + if (chan->mode !=3D SUN8I_PWM_MODE_CLK) + return; + + chan->mode =3D SUN8I_PWM_MODE_NONE; +} + +static int sun8i_pwm_bypass_enable(struct clk_hw *hw) +{ + struct sun8i_pwm_channel *chan =3D sun8i_pwm_channel_from_hw(hw); + struct sun8i_pwm_chip *sun8i_chip =3D chan->chip; + unsigned int pair =3D SUN8I_PWM_PAIR_IDX(chan->index); + u32 pccr, per; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + if (chan->mode !=3D SUN8I_PWM_MODE_CLK) + return -EBUSY; + + pccr =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCCR(pair)); + per =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); + if (!(pccr & BIT(SUN8I_PWM_PCCR_BYPASS_BIT(chan->index))) || + !(per & SUN8I_PWM_ENABLE(chan->index))) { + sun8i_pwm_set_enabled_locked(sun8i_chip, chan->index, false); + sun8i_pwm_set_bypass_locked(sun8i_chip, chan->index, true); + sun8i_pwm_set_enabled_locked(sun8i_chip, chan->index, true); + } + + return 0; +} + +static void sun8i_pwm_bypass_disable(struct clk_hw *hw) +{ + struct sun8i_pwm_channel *chan =3D sun8i_pwm_channel_from_hw(hw); + struct sun8i_pwm_chip *sun8i_chip =3D chan->chip; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + if (chan->mode !=3D SUN8I_PWM_MODE_CLK) + return; + + sun8i_pwm_set_enabled_locked(sun8i_chip, chan->index, false); + sun8i_pwm_set_bypass_locked(sun8i_chip, chan->index, false); +} + +static int sun8i_pwm_bypass_is_enabled(struct clk_hw *hw) +{ + struct sun8i_pwm_channel *chan =3D sun8i_pwm_channel_from_hw(hw); + struct sun8i_pwm_chip *sun8i_chip =3D chan->chip; + unsigned int pair =3D SUN8I_PWM_PAIR_IDX(chan->index); + bool enabled; + u32 val; + + guard(spinlock_irqsave)(&sun8i_chip->lock); + + val =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PCCR(pair)); + enabled =3D (val & SUN8I_PWM_PCCR_GATE) && + (val & BIT(SUN8I_PWM_PCCR_BYPASS_BIT(chan->index))); + + val =3D sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); + enabled =3D enabled && (val & SUN8I_PWM_ENABLE(chan->index)); + + return enabled; +} + +static const struct clk_ops sun8i_pwm_bypass_ops =3D { + .prepare =3D sun8i_pwm_bypass_prepare, + .unprepare =3D sun8i_pwm_bypass_unprepare, + .enable =3D sun8i_pwm_bypass_enable, + .disable =3D sun8i_pwm_bypass_disable, + .is_enabled =3D sun8i_pwm_bypass_is_enabled, +}; + static void sun8i_pwm_put_rate(struct sun8i_pwm_chip *sun8i_chip, unsigned int idx) { @@ -342,8 +450,12 @@ static int sun8i_pwm_request(struct pwm_chip *chip, st= ruct pwm_device *pwm) int ret; =20 scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + if (chan->mode !=3D SUN8I_PWM_MODE_NONE) + return -EBUSY; + was_enabled =3D sun8i_pwm_channel_is_enabled_locked(sun8i_chip, idx); + chan->mode =3D SUN8I_PWM_MODE_PWM; } =20 chan->pair_clk =3D clk_hw_get_clk(parent, NULL); @@ -372,6 +484,8 @@ static int sun8i_pwm_request(struct pwm_chip *chip, str= uct pwm_device *pwm) clk_put(chan->pair_clk); err_clear_clock: chan->pair_clk =3D NULL; + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) + chan->mode =3D SUN8I_PWM_MODE_NONE; =20 return ret; } @@ -382,6 +496,9 @@ static void sun8i_pwm_free(struct pwm_chip *chip, struc= t pwm_device *pwm) struct sun8i_pwm_channel *chan =3D &sun8i_chip->channels[pwm->hwpwm]; =20 scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { + if (chan->mode !=3D SUN8I_PWM_MODE_PWM) + return; + sun8i_pwm_set_enabled_locked(sun8i_chip, pwm->hwpwm, false); sun8i_pwm_set_bypass_locked(sun8i_chip, pwm->hwpwm, false); } @@ -390,6 +507,9 @@ static void sun8i_pwm_free(struct pwm_chip *chip, struc= t pwm_device *pwm) clk_disable_unprepare(chan->pair_clk); clk_put(chan->pair_clk); chan->pair_clk =3D NULL; + + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) + chan->mode =3D SUN8I_PWM_MODE_NONE; } =20 static int sun8i_pwm_read_waveform(struct pwm_chip *chip, @@ -510,7 +630,8 @@ sun8i_pwm_pair_rate_constrained(struct sun8i_pwm_chip *= sun8i_chip, unsigned int sibling =3D idx ^ 1; =20 guard(spinlock_irqsave)(&sun8i_chip->lock); - return sun8i_chip->channels[sibling].rate_exclusive || + return sun8i_chip->channels[sibling].mode =3D=3D SUN8I_PWM_MODE_CLK || + sun8i_chip->channels[sibling].rate_exclusive || sun8i_pwm_channel_is_enabled_locked(sun8i_chip, sibling); } =20 @@ -984,6 +1105,42 @@ static int sun8i_pwm_register_pair_clocks(struct devi= ce *dev, return 0; } =20 +/* Register the bypass clock for each channel. */ +static int sun8i_pwm_register_bypass_clocks(struct device *dev, + struct sun8i_pwm_chip *sun8i_chip) +{ + for (unsigned int i =3D 0; i < SUN8I_PWM_NPWM; i++) { + struct sun8i_pwm_channel *chan =3D &sun8i_chip->channels[i]; + struct clk_hw *parent =3D sun8i_chip->pairs[SUN8I_PWM_PAIR_IDX(i)].hw; + const char *name; + int ret; + + name =3D devm_kasprintf(dev, GFP_KERNEL, "%s#pwm-bypass%u", + dev_name(dev), i); + if (!name) + return -ENOMEM; + + chan->chip =3D sun8i_chip; + chan->index =3D i; + /* + * Protect the shared rate while prepared. Preserve unclaimed + * firmware outputs through CCF's unused-clock cleanup, as for + * PWM waveforms; only a consumer may turn them off. + */ + chan->bypass_hw.init =3D + CLK_HW_INIT_HW(name, parent, &sun8i_pwm_bypass_ops, + CLK_SET_RATE_PARENT | CLK_SET_RATE_GATE | + CLK_IGNORE_UNUSED); + + ret =3D devm_clk_hw_register(dev, &chan->bypass_hw); + if (ret) + return dev_err_probe(dev, ret, + "Failed to register bypass clock %u\n", i); + } + + return 0; +} + /* * A disabled pair gate makes any set PER bits ineffective. Clear those st= ale * enables before a clock consumer can turn the shared gate on and expose = an @@ -1012,6 +1169,17 @@ sun8i_pwm_sanitize_disabled_pairs(struct sun8i_pwm_c= hip *sun8i_chip) sun8i_pwm_writel(sun8i_chip, per, SUN8I_PWM_PER); } =20 +static struct clk_hw *sun8i_pwm_get_clk_hw(struct of_phandle_args *clkspec, + void *data) +{ + struct sun8i_pwm_chip *sun8i_chip =3D data; + + if (clkspec->args_count !=3D 1 || clkspec->args[0] >=3D SUN8I_PWM_NPWM) + return ERR_PTR(-EINVAL); + + return &sun8i_chip->channels[clkspec->args[0]].bypass_hw; +} + static int sun8i_pwm_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -1050,6 +1218,14 @@ static int sun8i_pwm_probe(struct platform_device *p= dev) if (ret) return ret; =20 + ret =3D sun8i_pwm_register_bypass_clocks(dev, sun8i_chip); + if (ret) + return ret; + + ret =3D devm_of_clk_add_hw_provider(dev, sun8i_pwm_get_clk_hw, sun8i_chip= ); + if (ret) + return dev_err_probe(dev, ret, "Failed to add HW clock provider\n"); + ret =3D devm_pwmchip_add(dev, chip); if (ret < 0) return dev_err_probe(dev, ret, "Failed to add PWM chip\n"); --=20 2.53.0 From nobody Thu Sep 24 13:41:52 2026 Received: from mail-oi2-f13.google.com (mail-oi2-f13.google.com [74.125.231.205]) (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 67FCC3A3E91 for ; Wed, 23 Sep 2026 05:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141793; cv=none; b=KDThSx7WygW9qx+nor3VDSUW4tqFoGFj+Q3tsMiawZ5uNqLOBueAizoCZHeHVnDcAshwkVUEUFk/lZQAXZ+NHyNd5kb49zFJQPZWlodoZQDfftoPyPvIbkNR8zqrm/IVXdELzRkzZmIpTAJR4NabH1RQrT+qF2bEo+zDPClsPW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141793; c=relaxed/simple; bh=cxjDKZ0MA9VUms6JcpknLJlKdT7ZoJ5aaylgo7tCtYM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W6v2w24mT+2lWy5gDMq4CWCRurCfbX5ykMz/frWLIV1KuhDkgB5S7EIfyxzLBJermgth1MAftjNeNVdSqUlA9SWam96I3y5PdT5F9BQ3eP57bhohxJxzNroOi7DxSkzW8iuOZyIl268/QF8G5xV1FgRMAwr4qHq/mk8LklZiJyk= 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=eEjd7w19; arc=none smtp.client-ip=74.125.231.205 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="eEjd7w19" Received: by mail-oi2-f13.google.com with SMTP id 5614622812f47-4c4923c9429so317465b6e.1 for ; Tue, 22 Sep 2026 22:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790141788; x=1790746588; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FHj476tA2byKc8arhZaw8Ci81fHtdMiGqz0hVZIDFng=; b=eEjd7w19w8vtUCtcvfPFqKj+v4qyTlmYkyRQ4urFWKUusuoEZChikhf01YcT8IXvG0 sdBfixDz4jR6z6ndfCO82+hQzPgYrVPgffnlY5KXy4EIGlZpsRGNY5YNVpottIh777zN 2cRMP59ybEikhrngtEuGOGtiRXgIekFlH9qOZ8scHPUtJz2I4i3btswhF5D1Q3RLPYQL +gMv9f0qilvdnixX3CThrE8ogJAtSmIbzcvuSmWlqF838gx8bkBYb7KN6n2JwsIW1rWC m8BSj5i48MguQtJJU4LfHPbiQAiA91W8DK2j4jp2S2nylKnsmeTY+mFT60JPhTyTrKrx d3VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790141788; x=1790746588; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FHj476tA2byKc8arhZaw8Ci81fHtdMiGqz0hVZIDFng=; b=weI7qAXKRIcMT7LLl7+hLzD6wZUGy5FhNxItdcybEr5LpHjJQ5P0iPQLGfQDPEfqae Xmsq1cRQFM75HwpR1B8VBNYdFw4D3rLwQ0SVWb34dI6CAZv/WRQbqImkEP1smCSM2hVq Pycy1mfWgMtgTHwJ24hbWLfRSvy0WK2gRA5Wcn/tEfNfIelt5xMplHHjrxbboVsaL0Ye NAX/EfGMIKV02dnrGT21Ttxuc5ntqZ9SyvDd5QQ26GWrP9D8RZ7q9gA9Hfy0H+W869Zs QsytfH5JzVdWsmSjm0RlMsirmQcxkwpLWR9tDFkubmOfAVdCVt68mZPrllDFdPw/+fyb 6izQ== X-Forwarded-Encrypted: i=1; AKwUvByi1d9ZCoNdIHzn6P1IBwFGyVPRiNPWofEuAHY9iNQMB9tnnOChL/aUTKkwnnxdhzmQf6BOV66T3WFf02I=@vger.kernel.org X-Gm-Message-State: AFuF++nQDRhAbKsAso1EUsXlqEHNQ97wAuY5mvIrpQA9tbFwgAuORzHq VlD0az3gkRU5/CSz0WY46JFOZbtuY7G13Ks7a7EyeMKKghwgJ21JiptW X-Gm-Gg: AYBFou0hLBs9rDnXBuMmtYSr2Zt1DIHTMjBKnsURLpgYEo83UarjP3uy/P4t9Kfz/bv 0aVYJNEGbqZo+qbVzK0OLBP9gmdaRmldntfHeQn8Bqaqexn3BW7vCI70ThTHfFLkDQs/BeZcw2R FLRuyJzlgoo7cEqoxpMKlk0vvnQIhaQZXZtJ8vHA5G6MaSEr1wa6nfR8TViDMGHtB40l33qbQWm 4gsIPzaOGssZkLGRxPSlGbmoSb1K1lOWdtKjepyCgG+IovnHKwwsFExuLwJ7SZu1Oac+/fESYhs odDwmmK/m7oQPBXCIakerViZelPIkXo5IbgBnYi2mrpylUGZWpkw6sP051wzFVc00FnuUp9/Jd7 gT4H6dt+4N3ft7XO7152CbphP4HOWFhXoC40w62COfd2/YcmnvbaI/Q2D0WzYAZ5l5QeBKQil4l ZVKa18ENKxNqk1ZP1VIPQL152nujAc96thytGDOZ4U0PfM9PNJlf9aOZFlIu0RmyzNC4vGfa9kn nuv6apqr+HpMcp6Q6OYrtMLIkqpykadum9F2OMhue2op0OJ4GwNIft29QBkW9YIC0kybM0YqwRi w2M0sa6nxSq9NQ+Nwnl9JN7AaPzXRmLdCKi7S0bsdzlGFRuxAtaOv6epfG+iSv3cDd8a2/vE4ej hG0i7RwZQf/E1dOIdR4sc X-Received: by 2002:a05:6808:1783:b0:4c6:eddf:ca6f with SMTP id 5614622812f47-4d5b6bda069mr1922304b6e.12.1790141788407; Tue, 22 Sep 2026 22:36:28 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4d5c4aed99bsm1436896b6e.12.2026.09.22.22.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 22:36:27 -0700 (PDT) From: James Hilliard Date: Tue, 22 Sep 2026 23:36:17 -0600 Subject: [PATCH v10 4/5] arm64: dts: allwinner: h616: add PWM controller Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260922-h616-pwm-v8-v10-4-dccebbe1aabf@gmail.com> References: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> In-Reply-To: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Stephen Boyd , Brian Masney , Jerome Brunet , Richard Genoud , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard Cc: Philipp Zabel , Michael Turquette , Paul Kocialkowski , Thomas Petazzoni , John Stultz , Joao Schim , bigunclemax@gmail.com, linux-pwm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.15.2 From: Richard Genoud The H616 has a PWM controller that can provide PWM signals, but also plain clocks. Add the PWM controller node and pins in the device tree. Signed-off-by: Richard Genoud Signed-off-by: James Hilliard --- arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi | 47 ++++++++++++++++++++++= ++++ 1 file changed, 47 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi b/arch/arm64/bo= ot/dts/allwinner/sun50i-h616.dtsi index 1598e86259ab..90fe56a1d3cd 100644 --- a/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi +++ b/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi @@ -281,6 +281,17 @@ watchdog: watchdog@30090a0 { clocks =3D <&osc24M>; }; =20 + pwm: pwm@300a000 { + compatible =3D "allwinner,sun50i-h616-pwm"; + reg =3D <0x0300a000 0x400>; + clocks =3D <&osc24M>, <&ccu CLK_BUS_PWM>; + clock-names =3D "mod", "bus"; + resets =3D <&ccu RST_BUS_PWM>; + #pwm-cells =3D <3>; + #clock-cells =3D <1>; + status =3D "disabled"; + }; + pio: pinctrl@300b000 { compatible =3D "allwinner,sun50i-h616-pinctrl"; reg =3D <0x0300b000 0x400>; @@ -385,6 +396,42 @@ nand_rb1_pin: nand-rb1-pin { bias-pull-up; }; =20 + /omit-if-no-ref/ + pwm0_pin: pwm0-pin { + pins =3D "PD28"; + function =3D "pwm0"; + }; + + /omit-if-no-ref/ + pwm1_pin: pwm1-pin { + pins =3D "PG19"; + function =3D "pwm1"; + }; + + /omit-if-no-ref/ + pwm2_pin: pwm2-pin { + pins =3D "PH2"; + function =3D "pwm2"; + }; + + /omit-if-no-ref/ + pwm3_pin: pwm3-pin { + pins =3D "PH0"; + function =3D "pwm3"; + }; + + /omit-if-no-ref/ + pwm4_pin: pwm4-pin { + pins =3D "PI14"; + function =3D "pwm4"; + }; + + /omit-if-no-ref/ + pwm5_pin: pwm5-pin { + pins =3D "PA12"; + function =3D "pwm5"; + }; + /omit-if-no-ref/ spi0_pins: spi0-pins { pins =3D "PC0", "PC2", "PC4"; --=20 2.53.0 From nobody Thu Sep 24 13:41:52 2026 Received: from mail-oi2-f13.google.com (mail-oi2-f13.google.com [74.125.231.205]) (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 54B23439F7E for ; Wed, 23 Sep 2026 05:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141794; cv=none; b=ed5JS/g4h/xujEaOiAxECHKJ+fx5Jvpryyv23J3n/A74lJWzG9zhlAsJrHMI8xSApUS0/d6istPvL3iycBGTBSH0pQO2ieo1lthOqwzVtOFNMm5owx0ACzAdE7+Mn7G8ucYC4cPqwK2dojqpbWO7eRaR+nZP5VzLieiVC0orZM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790141794; c=relaxed/simple; bh=OJS6mQlRWmTTimOyj6kC0TvQSBszoDm45iW9XPqV2AQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J68lSf5g69eJlgXN+zG2Gm88/rML6W9zzcrIiN65MwH10YGXrT6N4cqvVA4khRVZXw1dfYw7yDskHeqS/tL4ahi41gdU9fhxQhZGpgpSBi5ruGxcJ44NYm564jHPJFFYLMFsQ2yNtRdV9zUQ+DAOGypYwFvDC7+1C9BylAM/XGE= 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=hxUBZbHV; arc=none smtp.client-ip=74.125.231.205 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="hxUBZbHV" Received: by mail-oi2-f13.google.com with SMTP id 5614622812f47-4c537df4daaso283893b6e.1 for ; Tue, 22 Sep 2026 22:36:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790141790; x=1790746590; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xhBI/4MYKZ9FiatfUTHQXDlddZz4ARJ+4t2N8WN0Mwk=; b=hxUBZbHV6QCZXuCz2XUqH4RtTWSjfTtAuoAbuFYn36LKQ9UFFzkyYjzF681zZBcisc 8gX0HdHSSHLXMLJWsgtY7NJN8Mh3EKqnpDidPuVjlB1MQQfIqsVIwhx4aN57mur4AG2C DLJnCIaN41i/bMg5PjAzqI5BQQu7GQp3OGkgLYkVTaiH1tGvvvFKuBgo8QRZfr0aBtpH Ff+a2hfus3Hb/uK/Bl+HCweZCBtrfxN3/DSHnWNc1UatibpDktP5PmqUCHXkPQSlA9NU G2PmBYaijuANITHl0C8Ihh0xfNXA+UExUFohEDPfEW13k9XpVleZQAEefxpKgSmAPg7+ wxlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790141790; x=1790746590; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xhBI/4MYKZ9FiatfUTHQXDlddZz4ARJ+4t2N8WN0Mwk=; b=scQuIgkyYatrYN6oRzIk6/atQctMmWvi5r7yPgoJ8nbIh5TYDH0ZFm3/xFNh+dxPqy 1tBVqGJ4pZtuxmA/KnFmJ0CEf5ACYtTTmGwC6lBMVofQJbb0uwN/01/RvrKNc6pWy/HJ BkeKL8slntOE3qSMUS/rp+XTed9fMnN/Z0hB8X9FX8R2Uuov6J18AfaNE63vAQ1MVn29 ejzvT/aveNbPaaA0L0yzIEZlrjlVgjTBwp8CALWKP6815jzLE4gxsagfnsZ+ZXK7q2Rm MDiGKb3J5UaitMZpJJt1TA5Ze7xWP5H3aoYb46e/IZIN/YXG0OnHL7ksmLgx7qysII+D 9R0Q== X-Forwarded-Encrypted: i=1; AKwUvBww65w6s5P6n9Eo7jU9XQvpITOgfjEZKfKJe7udN4CO34ey96+k1zDPTOMSV3Q6XDtytGIpGBilrGolXDE=@vger.kernel.org X-Gm-Message-State: AFuF++nLDm3qHcei3NFZ3FcXsWNJJqVKSRmutv53JJUocqi7M8pFHyAv Se/QQ5LvlMofTY4ov3U8dpZ3V91v0+s6+iajfgJhBmS+xIIFqsOE/jrM X-Gm-Gg: AYBFou27qZA7s/VlMW4bVKpfj36aVTeQMV+Y2imTDr+uaJahVIvS8hlDwfAIpSOhZhN eXi/M2EaL8YIzS/GzMhFFQDzSw8AAT+hyJ3jxr+7ktBdt/l3sl9AA23ONPnP7VoyVH24QjcBVlC ZL3cn5kYWD260+YieGFfG+gwQO2HMjFjbQsFysloHhalPea8PM5SWyLIbP8ELNN83mmQfkhjzCz Xil1hnDxQwprDSSBl7GbNjARfVWv8uCedriyWFhxDdK4SBy3urfDdMuyjTgYq/fqJHO9QlWmpAP nkNEXZVhW6HnmEfjPSJha1b0nk1LZ80MnJ11CvcKSxG+eYYXRVnjx27/Ww7BamqF19rWROHTccr HeUpAP24ZLZ0ZPcG1HolArCUSNs3CM3Ql5uMuRK2pKt2jj5WA4jTorwna88x7HVC4GTHbtUSYsC tdekUr/Qzf0+6tnGLSlp8In6Nmbv7uNGG8KcWAxe+SLIJGIB2FzjeXw3IVU4mywBB+SvJSevAht ooxUG63fxYDfOgD0d7/5Ks1S+zHsyZjisY1afpgHzDRWUNx6ChszIvyygXJjV/AuYVJXyiojy8j WBqReB2NB7Z+Nfje7HKesOswpSg+FE2sMRWcJoGxJzuSFFyN8C5IHkH/NvF3pvYMh0NLs7lZgN0 q0DnN+udZlFsEEEuThb1s X-Received: by 2002:a05:6808:1495:b0:4b9:e5fa:8a1d with SMTP id 5614622812f47-4d5ba092ea7mr1861997b6e.34.1790141789974; Tue, 22 Sep 2026 22:36:29 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4d5c4aed99bsm1436896b6e.12.2026.09.22.22.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 22:36:29 -0700 (PDT) From: James Hilliard Date: Tue, 22 Sep 2026 23:36:18 -0600 Subject: [PATCH v10 5/5] MAINTAINERS: Add entry on Allwinner sun8i/H616 PWM driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260922-h616-pwm-v8-v10-5-dccebbe1aabf@gmail.com> References: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> In-Reply-To: <20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Stephen Boyd , Brian Masney , Jerome Brunet , Richard Genoud , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard Cc: Philipp Zabel , Michael Turquette , Paul Kocialkowski , Thomas Petazzoni , John Stultz , Joao Schim , bigunclemax@gmail.com, linux-pwm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.15.2 From: Richard Genoud Add myself as maintainer of Allwinner SUN8I PWM driver. Signed-off-by: Richard Genoud Signed-off-by: James Hilliard --- MAINTAINERS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index cc3cae2e378b..d9713b1044c2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -918,6 +918,11 @@ S: Maintained F: Documentation/devicetree/bindings/hwlock/allwinner,sun6i-a31-hwspinlock= .yaml F: drivers/hwspinlock/sun6i_hwspinlock.c =20 +ALLWINNER SUN8I PWM DRIVER +M: Richard Genoud +S: Maintained +F: drivers/pwm/pwm-sun8i.c + ALLWINNER THERMAL DRIVER M: Vasily Khoruzhick M: Yangtao Li --=20 2.53.0