| Message ID | 20261103-h616-pwm-v8-v11-0-07abb59575c3@gmail.com (mailing list archive) |
|---|---|
| Headers |
Return-Path: <linux-sunxi+bounces-27091-sunxi=pue.re@lists.linux.dev>
X-Original-To: noreply@patchwork.local
Delivered-To: noreply@patchwork.local
Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mxe881.netcup.net (Postfix) with ESMTPS id A57D31C421A
for <noreply@patchwork.local>; Tue, 3 Nov 2026 09:43:51 +0100 (CET)
Authentication-Results: mxe881;
dkim=pass header.d=gmail.com;
spf=pass (sender IP is 172.232.135.74)
smtp.mailfrom=linux-sunxi+bounces-27091-noreply=patchwork.local@lists.linux.dev
smtp.helo=sto.lore.kernel.org
Received-SPF: pass (mxe881: domain of lists.linux.dev designates
172.232.135.74 as permitted sender) client-ip=172.232.135.74;
envelope-from=linux-sunxi+bounces-27091-noreply=patchwork.local@lists.linux.dev;
helo=sto.lore.kernel.org;
Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org
[100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 8B38A60365B
for <noreply@patchwork.local>; Tue, 3 Nov 2026 08:41:32 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793695235;
b=R7O9xOZVG+U3bKZGFtFCDsS+IIqVpfcH6PTAY9SgMQkf4foo03/zbazEjBH4HEIHl+2z
ZXCItPWRDd3BbfLUsjEtzaSA7YeS5kCd2dFBWhFeEUcbtou5HsdniR0+1GKodexFD71s5
Ry6q8b8zLv+VpmgyOaMTMgf+QN1GIoL4SwUH+Q2yD3X8nQuS7vtB+awkdFVcEOTnusWoo
sH5L0gx4IbJVnCpevmctwVS7GTAFQIelBiwshuioRaU5DJv3yWdmWlJ5x3+ag6I7phcVg
wnwf7END8xeNz0dzMrVVUWvUjeWSsnFQeBlltbb/ZYXDWi1xz5VeDjzASGs9CRU5x7A==
ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793695235;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:Subject:Date:Message-Id:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer;
bh=gKEeZqtZAu8+s0Ua1x2I8P/JLZraxDn6ha7UOnJcDMc=;
b=zWn7LCKJgO1ENbJZO/ylIB8KGVHDwDYqypfknNfnR4KcVp6afw+jXnNuCmhoFk0EaAqW
PRNbo6rH1bzWJzepNGKiynoX74XYhXoFzL+/OUpg23sWwyOOJk941rqvXf2ENvCwaIHiA
En5ZmHeX4qt6v4WVK279CjAM9mFI+mla7sF4UHlEBj9xESAzH8lzFybjTu17fLg3wdVxy
5YQkLlk7Yyzl0DK1ekWY8CCYdVj5gNnu1nUKP0lqfh1RI+ZRQ2Nop0xmkoditM+Tr1Jg1
EQLamF2SrhC3xM2CrvCAVAhv1WqJhghsJ3BkCtTPSjgh1zbS4myqKYmfEctgzaA9kjg==
ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256
header.s=20260707 header.b=Av5I7cBT;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 93831606A947;
Tue, 3 Nov 2026 08:40:35 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key,
unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256
header.s=20260707 header.b=Av5I7cBT
X-Original-To: linux-sunxi@lists.linux.dev
Authentication-Results: smtp.subspace.kernel.org;
arc=none smtp.remote-ip=209.85.161.47
ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793695235;
b=PdAYymkBj/gF6wJCj56HhyiL+R10urABrt5xSeEoZZFBaCO3QYITwcGRjFpttKwU4WWB
7LW+EI+q7UT6cV9Auo9JUc7yi5H4i7Nba6o+wtW361vxRxVuCpk0oEsmD0Qpnh3GIVzqK
mkQ9Tc/5benGBcwO67f6DRLXkDwYy4OG7mVLHtoEfLVMBr4UipiPe7DEUx6KTA9047ahI
jWwujudzr5qldfdxYtj1YyacKYYJBu7apqLBbv+GE1hgBoPUintPmuvISuyfNA4vbPvt2
A2nXOsjcux2H3Zbk0Dcq/Yqo4QW5Urt2gPkt3S+mYzxjDLDfekK8bKiiqKNQqBWOYng==
ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793695235;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:Subject:Date:Message-Id:MIME-Version:Content-Type:
Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer;
bh=gKEeZqtZAu8+s0Ua1x2I8P/JLZraxDn6ha7UOnJcDMc=;
b=ZbZg4Ffa7S1RZCnSB77CyAfZvs2gy4KRGJ9fMTyKyyGEHEhbDHzimF4mpnbhywn5rHoG
OhF7YVJXPtXYD7ZO/AlmcwdY2S+QvrfbD33guGWpbfZBPBiSDYyYCywkHf/XFlDEzfQad
QXfThDviZJPAg4I7qSM9ZazVxm7ZxjF9pPJ3esw9CN3QYr6uOb7uCMvGazhLT/rj5BS0/
m/uDYHJcrddb9bKjxaYWwJ+VuiuVahid0XaZYxuF5n/Sark0oSMNnwOwlcVHEMTZB7cdE
lF89WMSe1DWUlK+a3uxI2jcqybfUco807vGs26bc6FO0g5dC8aCSZXUBEKrv2t2CL+Q==
ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256
header.s=20260707 header.b=Av5I7cBT;
arc=none smtp.remote-ip=209.85.161.47
Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com
[209.85.161.47])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest
SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04977606A974
for <linux-sunxi@lists.linux.dev>; Tue, 3 Nov 2026 08:40:34 +0000 (UTC)
DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 04977606A974
Authentication-Results: smtp.subspace.kernel.org;
dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
spf=pass smtp.mailfrom=gmail.com
Received: by mail-oo1-f47.google.com with SMTP id
006d021491bc7-6ddef424972so2826504eaf.3
for <linux-sunxi@lists.linux.dev>;
Tue, 03 Nov 2026 00:40:34 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793695234; x=1794300034;
darn=lists.linux.dev;
h=cc:to:content-transfer-encoding:content-type:mime-version
:message-id:date:subject:from:from:to:cc:subject:date:message-id
:reply-to:content-type;
bh=gKEeZqtZAu8+s0Ua1x2I8P/JLZraxDn6ha7UOnJcDMc=;
b=Av5I7cBTYz051WmlJ0rIF1k6rMnwXQ0RNVuVzr9gPK+Ykov25I0FNmuw0GKTYX6H8l
/VMnOGFaPAONct/BotHY4Jb6er5VjbojrPjv5r0vb1g+qrd34O+vKamkwNEAHlcmmjw1
2nLYskbSCT4cGRMRqooi4It2C1IgIftqQRP4SrB/837QH2Ac0LIIf1tkOiPA8PvbCqQo
2i3ROUAx88FQhm25YiFxpZis9VQ9dyvfv9/zRdjy7cuPamcLvmA5q+x33LtKithvzNOL
Gw1fnCxxmyjOK1A2S2JrSKYotYx/tuZKq6o0GgbiTMPfxG8daTyyC+V7lmCxEW2hJHCU
eyvw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793695234; x=1794300034;
h=cc:to:content-transfer-encoding:content-type:mime-version
:message-id:date:subject:from:x-gm-gg:x-gm-message-state:from:to:cc
:subject:date:message-id:reply-to:content-type;
bh=gKEeZqtZAu8+s0Ua1x2I8P/JLZraxDn6ha7UOnJcDMc=;
b=yq2CwMdQSVj6Ez+omLKOJUtm1+QTaz4LwRUknDrb5Q8vQsdOfuEqX0mwBoVjReBTNv
o0NmI6SJgMssbNtigwr3RiGeaRGbqhYTVFG30n4guVVt6YiW+r1k8bFra4GWVH1+LlQt
YKgPq46reDdhgUIa8PXBw0cqjmXlP5xJES6N+36aTC267NcybOhrbaIq3rcWsAx7ev7u
c6zgkb6IpbCAvxLiRuc2+qrpNxIQ53hCFiXxxXhRcU4fGG03xd4X2XsDeLivZ3EG3Wr4
Ggqd2vrE51F/8hMmeKNc9UbNZjS2eh8eYSD+7fpjQviWbtgK8GM5ajh45jUmIaPIgk+L
cq/Q==
X-Forwarded-Encrypted: i=1;
AKwUvBxJAYzl0CRLLGDPZxG6O9oMhoMspLHu/LXAGLU8hH7SwnKuxjzQ/oiISsJoz6trWgU0r5DmmunAXyTEsA==@lists.linux.dev
X-Gm-Message-State: APuU4Z+9Z5im4esDkG3wOoLNyhS4pC3k849Hffmj99EsuYvYicW7LTKp
jvjAlOWKHzENn81fePTzUs1tpyEbLhnrz1KjFvaAsPs1P4JFVkgrQS2G
X-Gm-Gg: AYBFou0pXzxKtdrMX/6kpigv5uVLD21Yb9dvpHdxWICSUDVkenw7BKop+Df+5VJSwAB
tZA7bQRWiE8dboS3A5Lmtl2ohDHRkb0vqm18Rere9dxm3ju9OrPdgU8QeKz76jtlVDwxuvgfD+G
YdvpQafYKWLKh8TozexSCk0srBDwe2guj+y/VCGMohZusZp+uIBWr5c3oqCXM8ED/MtXdevzhmR
ZpNAQDyaij9BOZd7Abql8X4MExZwkXJmny6X/6wP2hTNlaA6vVuGh7d8igZ9jpseAyE8k28Pir4
bXPsOVJLH59fSYvGvLvOiEILicjnKwB+Uig9rj1G+dTYIhQ3w+5hgN8a82MHpWvoCzv4qnR7REM
sHkR09DU7CZUA5KKN/KcFy5f+gGyBbLGm9WXzM26/JQWZfsV/hCRkCgUdlt9fRNoAHyCf1g518L
d6XNqK3xBAGpYnplF8RIQhgqCBUkGL5xGqOPhEpltAnAKb9sUC0hMO6bwsVoWW3z1xyG0Magxqf
v5CeOSJqAfAhewnqeaSmBZ8lIN6fEVyCOE9JPtIVzvIwHAaD9hDHVdeOKEaXhr87bVgFYAZ3uUo
eXWSJztR5rXq80NTASrh1J4bZKuXXdGB070qfqWCbZElyQsZShfK0DY5bxd0hzHQ9xdP9QBGnn9
9QUiXt6OboIZ5LFgbcjSnszaU6E6b3Dg8XtsUPp659Gj1yaN8qo7hYG7JsV9/kWh9zfDYCpFBfz
BgXyx+31YbkNbIaNQVXm3ihwt38io5fr7s+SNMD51poAo/bG2aKyg=
X-Received: by 2002:a05:6820:4888:b0:70a:598b:12a9 with SMTP id
006d021491bc7-714f2a077b4mr6082560eaf.53.1793695233866;
Tue, 03 Nov 2026 00:40:33 -0800 (PST)
Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49])
by smtp.gmail.com with ESMTPSA id
006d021491bc7-714f3081097sm10520397eaf.13.2026.11.03.00.40.32
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 03 Nov 2026 00:40:33 -0800 (PST)
From: James Hilliard <james.hilliard1@gmail.com>
Subject: [PATCH v11 0/5] Introduce Allwinner H616 PWM controller
Date: Tue, 03 Nov 2026 01:40:25 -0700
Message-Id: <20261103-h616-pwm-v8-v11-0-07abb59575c3@gmail.com>
X-Mailing-List: linux-sunxi@lists.linux.dev
List-Id: <linux-sunxi.lists.linux.dev>
List-Post: <mailto:linux-sunxi@lists.linux.dev>
List-Help: <mailto:linux-sunxi+help@lists.linux.dev>
List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev>
List-Owner: <mailto:linux-sunxi+owner@lists.linux.dev>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
X-B4-Tracking: v=1; b=H4sIAAAAAAAC/5XSyWrDMBAG4FcJPldmFq095T1KD17kWKW2g+y4L
SHvXjmlOMmhuCAQEvr+GSSds9HH4MfseXfOop/DGIY+LRCfdlnVFv3Bi1CnjYyANFhg0WrU4vj
RidkKT1g4kgYccZbEMfomfF7jXl5/1uOpfPPVtEQsJ5o4dGJqoy/WVAOMighVjo6scgJFDKl4r
POD74dTvS+HYXoPfV4N3RLShnEa4te16RmXYkuQQgKFAMQuR6WZFf+dtHQ40w1HA5YUyNwCkd6
A+RdrQGJwzEQ5Mhm2bgOXK2dQ4NApl5NiYCM3cLVyiRoZJbp8uco0b+D6gctUNnENis0Gblb+v
we8artqC/LuU6UBoi7ZFKXVJAu/P3RFeF+tW60jvLcuWTalrzQBNo16tAi3mO4xwlK5qnxZeiy
KsrnVl8vlG6RM7EguAwAA
X-Change-ID: 20260803-h616-pwm-v8-e21a92470923
To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= <ukleinek@kernel.org>,
Stephen Boyd <sboyd@kernel.org>, Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Richard Genoud <richard.genoud@bootlin.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>, Conor Dooley <conor+dt@kernel.org>,
Chen-Yu Tsai <wens@kernel.org>, Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>, Maxime Ripard <mripard@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
Michael Turquette <mturquette@baylibre.com>,
Paul Kocialkowski <paulk@sys-base.io>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
John Stultz <jstultz@google.com>, Joao Schim <joao@schimsalabim.eu>,
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 <james.hilliard1@gmail.com>,
Conor Dooley <conor.dooley@microchip.com>
X-Mailer: b4 0.15.2
X-MORS-Enabled: yes
X-MORS-DOMAIN: patchwork.local
X-MORS-HOSTING: hosting172546
X-MORS-USER: hosting172546
X-getmail-retrieved-from-mailbox: INBOX
|
| Series |
Introduce Allwinner H616 PWM controller
|
|
Message
James Hilliard
Nov. 3, 2026, 8:40 a.m. UTC
The H616 controller has six PWM outputs, paired as 0/1, 2/3 and 4/5. Each pair shares a source mux, gate and power-of-two divider. Each channel adds a prescaler and waveform generator, with a bypass for clock output. The bypass can supply the input clock for the co-packaged AC200/AC300 PHY. The series separates PWM waveform support and exported bypass clocks into distinct patches. Internal CCF pair clocks model the shared hardware, while PWM request/free and clock prepare/unprepare arbitrate ownership of each output. Active PWM outputs and prepared bypass clocks protect their shared rate against incompatible sibling requests. Firmware-active outputs are preserved until a consumer changes them. Hardware-enable checks protect their shared gate and rate even before Linux has an owner for them; there is no driver-local unused-output sweep. A conflicting shared-rate request is rejected while an inherited output remains enabled. In particular, assigned-clock-rates cannot override an incompatible firmware-active output. Firmware must leave a compatible configuration or disable the conflicting outputs for that request to work. The clock-provider interface reports the actual pair rate and makes rate protection visible to CCF. In contrast, drivers/clk/clk-pwm.c advertises a fixed frequency without checking the rounded PWM result: a 42 ns, 21 ns request selects 24 MHz bypass when available, but can become 25 MHz when a sibling holds the pair at 100 MHz. The direct provider still permits CCF rounding; it does not guarantee that every requested rate is available. The bounded TLA+ models and accompanying implementation checks are available with their assumptions and limitations at: https://github.com/jameshilliard/linux-h616-pwm-tla Signed-off-by: James Hilliard <james.hilliard1@gmail.com> Assisted-by: Codex:gpt-5 --- Changes v10 -> v11: - rebase onto pwm/for-next at 9ad5602d4943 - compare candidate waveforms before nanosecond rounding, retaining period-first ordering across pair rates and bypass half-cycles - protect the pair rate across waveform readback so an exported-clock consumer cannot mix a new register configuration with a stale rate - use the provider-owned handle for the temporary hold, separately from the PWM handles used to change the rate - Link to v10: https://patch.msgid.link/20260922-h616-pwm-v8-v10-0-dccebbe1aabf@gmail.com Changes v9 -> v10: - validate the single clock-specifier argument before reading its channel index (reported by Sashiko) - Link to v9: https://patch.msgid.link/20260921-h616-pwm-v8-v9-0-37bec6201ff5@gmail.com Changes v8 -> v9: - split PWM waveform support and exported bypass-clock support into separate patches, retaining internal CCF pair clocks in the PWM patch - preserve unclaimed firmware outputs instead of stopping them at sync_state(); replace the empty disable_unused callback with CLK_IGNORE_UNUSED - embed the fixed six-channel topology in the pwm_chip allocation, remove single-variant match data, and use a channel-indexed clock lookup - store bypass clock state directly in each channel and recover the channel from its clk_hw without a separate wrapper - avoid module self-pinning by acquiring internal clock consumer handles only while a PWM is requested; use provider-owned handles for notifiers and rate readback - use scoped locking and protect rate_exclusive with the register lock, keeping CCF operations outside it; remove ownership WARN_ON_ONCE calls - explain unsupported pulse/dead-zone reads and rename the waveform conversion helper to match its callback - pre-encode waveform registers, isolate update preparation and rollback, combine candidate comparison/selection, and remove redundant rounding corrections and private waveform-field checks - normalize polarity readback, use ordinary boolean waveform flags, and remove the redundant bypass recalc_rate callback - clarify the clk-pwm rounding limitation and correct the v7 topology description - Link to v8: https://patch.msgid.link/20260804-h616-pwm-v8-v8-0-db37ab8624ae@gmail.com Changes v7 -> v8: - require both the module and bus input clocks for H616 - clear the complete two-bit clock-source selector field - leave rate and period registers untouched when disabling a channel - distinguish PWM-owned bypass signals from clock-owned bypass outputs - round shortest-period requests using the fastest achievable clock - encode constant levels without overflowing the 16-bit active-cycle field - require #clock-cells for the H616 clock provider (reported by Sashiko) - allocate clock topology state per device, use the fixed two-parent map, and use managed clock registration (reported by Sashiko and suggested by Philipp) - deassert reset before registering clocks and keep the reset handle local (reported by Sashiko and suggested by Philipp) - arbitrate channel ownership in clock prepare/unprepare and select bypass only while the clock output is enabled (reported by Sashiko) - roll back failed PWM requests and serialize channel release (reported by Sashiko) - protect the shared pair source while either sibling channel is active (reported by Sashiko) - preserve the 65536-tick duty intermediate before polarity conversion (reported by Sashiko) - keep the hardware-waveform state within the PWM core storage limit - clarify that either co-packaged AC200 or AC300 PHY uses the bypass clock - drop driver Tested-by tags after the clock implementation was reworked - quantize inverted waveforms in hardware ticks and report their physical offset - force released channels off so stale waveforms cannot restart with a sibling - track the active and pending cycle for the period-update handshake, adapt the sleep interval to bound MMIO polling on long periods, and honor the PCLK rate constraint - quiesce rate, polarity and bypass transitions before reprogramming the output - clear unsupported pulse mode when programming periodic waveforms - describe the bypass clock cells and simplify the fixed parent topology - avoid resetting active pair registers during probe - model only shared pair clocks in CCF and program per-channel dividers directly - make pair-rate changes transactional and hold exclusivity only while an output is active - implement formal waveform rounding across all parent, divider and bypass choices - preserve firmware-active outputs through generic unused-clock cleanup, stop any still-unclaimed channels at sync_state(), reconcile empty pair gates through CCF, and reject pair retuning while either output is active - clear dormant dead-zone state when both pair outputs are disabled, while rejecting active dead-zone and pulse modes which the PWM API cannot represent - correct the hardware topology to show the pair gate before div_m - Link to v7: https://patch.msgid.link/20260703152215.192859-1-richard.genoud@bootlin.com Changes v6 -> v7: - Cc Common Clock Framework maintainers (suggested by Uwe) - add missing static before SUN8I_PWM_X_BYPASS_GATE - reorder code in probe to fix potential lifecycle issues - set pwmcc_data[i].parent_names to NULL in sun8i_pwm_unregister_clk Changes v5 -> v6: - remove trailing junk after the patch 4 commit message - remove Tested-by tags where they do not apply Changes v4 -> v5: - fix bypass handling for channels greater than 1 - add colons to clarify two debug messages - switch from H616 to sun8i prefixes in code, filenames and module names - fix consistency issues in macro parameters - rename confusing macros Changes v3 -> v4: - gather Acked-by and Tested-by tags - fix a pointer-to-integer cast size warning on ARC - add a managed action for clk_hw_unregister_composite (suggested by Philipp) - remove the unused pwm_remove function (suggested by Philipp) Changes v2 -> v3: - use U32_MAX instead of defining UINT32_MAX - document U32_MAX usage in clk_round_rate() - define clk_table_div_m using macros - fix formatting - correct the parent clock order - simplify code using scoped_guard() - add a missing const qualifier and rename to_h616_pwm_chip() to h616_pwm_from_chip() - add missing error messages and remove redundant ones - rename cnt to period_ticks and duty_cnt to duty_ticks - fix PWM_PERIOD_MAX - add the remove callback - replace DIV_ROUND_CLOSEST_ULL with DIV_ROUND_UP_ULL - add H616 prefixes - protect _reg in macros - switch from apply/get_state to waveforms - shrink struct h616_pwm_channel Changes v1 -> v2: - add missing headers - remove MODULE_ALIAS (suggested by Krzysztof) - use the sun4i-pwm binding instead of adding a new one (suggested by Krzysztof) - retrieve parent clocks from the device tree - change num_parents to unsigned int To: Uwe Kleine-König <ukleinek@kernel.org> To: Rob Herring <robh@kernel.org> To: Krzysztof Kozlowski <krzk+dt@kernel.org> To: Conor Dooley <conor+dt@kernel.org> To: Chen-Yu Tsai <wens@kernel.org> To: Jernej Skrabec <jernej.skrabec@gmail.com> To: Samuel Holland <samuel@sholland.org> To: Maxime Ripard <mripard@kernel.org> To: Richard Genoud <richard.genoud@bootlin.com> To: Philipp Zabel <p.zabel@pengutronix.de> Cc: linux-pwm@vger.kernel.org Cc: devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-sunxi@lists.linux.dev Cc: linux-kernel@vger.kernel.org --- Richard Genoud (5): dt-bindings: pwm: allwinner: add h616 pwm compatible pwm: sun8i: Add H616 PWM support pwm: sun8i: export the bypass outputs as clocks arm64: dts: allwinner: h616: add PWM controller MAINTAINERS: Add entry on Allwinner sun8i/H616 PWM driver .../bindings/pwm/allwinner,sun4i-a10-pwm.yaml | 33 +- MAINTAINERS | 5 + arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi | 47 + drivers/pwm/Kconfig | 12 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-sun8i.c | 1317 ++++++++++++++++++++ 6 files changed, 1414 insertions(+), 1 deletion(-) --- base-commit: 9ad5602d4943635ea2b3b73d1a720161f88da1a1 change-id: 20260803-h616-pwm-v8-e21a92470923 Best regards, -- James Hilliard <james.hilliard1@gmail.com>
Comments
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] pwm: sun8i: rate_exclusive leak in sun8i_pwm_prepare_update() on error - [Medium] pwm: sun8i: false -EOPNOTSUPP in sun8i_pwm_clear_idle_deadzone() - [Medium] pwm: sun8i: race in sun8i_pwm_put_rate() clearing rate_exclusive early -- commit 2ea581bca416bf89c24368c5ae4769a990d47584 Author: Richard Genoud <richard.genoud@bootlin.com> pwm: sun8i: Add H616 PWM support This commit adds waveform support for the six-channel Allwinner H616 PWM controller, modeling shared pair clocks in CCF and programming channel-local dividers and period/duty registers directly. > diff --git a/drivers/pwm/pwm-sun8i.c b/drivers/pwm/pwm-sun8i.c > new file mode 100644 > index 0000000000000..bcc2c57443780 > --- /dev/null > +++ b/drivers/pwm/pwm-sun8i.c [ ... ] > +static void sun8i_pwm_put_rate(struct sun8i_pwm_chip *sun8i_chip, > + unsigned int idx) > +{ > + struct sun8i_pwm_channel *chan = &sun8i_chip->channels[idx]; > + bool exclusive; > + > + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) { > + exclusive = chan->rate_exclusive; > + chan->rate_exclusive = false; > + } > + /* CCF takes the prepare mutex and may call back into this driver. */ > + if (exclusive) > + clk_rate_exclusive_put(chan->pair_clk); > +} [ ... ] > +static void sun8i_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) > +{ > + struct sun8i_pwm_chip *sun8i_chip = sun8i_pwm_from_chip(chip); > + struct sun8i_pwm_channel *chan = &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 = NULL; > +} [Severity: Medium] Can clearing chan->rate_exclusive before clk_rate_exclusive_put() in drivers/pwm/pwm-sun8i.c:sun8i_pwm_put_rate() race with a concurrent waveform update on the sibling channel? In the PWM core, __pwm_put() calls ops->free() (sun8i_pwm_free()) under pwm_lock without holding pwmchip_lock(chip), while waveform callbacks (sun8i_pwm_round_waveform_tohw() and sun8i_pwm_write_waveform()) run under pwmchip_lock(chip) without pwm_lock. When an enabled channel is freed on one CPU while its sibling channel is being updated on another CPU: CPU0 CPU1 sun8i_pwm_free(idx) sun8i_pwm_set_enabled_locked(idx, false) sun8i_pwm_put_rate(idx) chan->rate_exclusive = false sun8i_pwm_round_waveform_tohw(idx ^ 1) sun8i_pwm_pair_rate_constrained() -> returns false sun8i_pwm_write_waveform(idx ^ 1) sun8i_pwm_prepare_update() sun8i_pwm_set_enabled_locked(false) clk_set_rate(pair_clk, new_rate) -> fails with -EBUSY clk_rate_exclusive_put(chan->pair_clk) Because both SUN8I_PWM_ENABLE(idx) and chan->rate_exclusive are already cleared before clk_rate_exclusive_put() drops CCF rate protection, sun8i_pwm_pair_rate_constrained() on the sibling channel sees the pair as unconstrained and attempts to change pair_rate, causing clk_set_rate() to fail with -EBUSY while the freeing channel's protect_count is still held. [ ... ] > +static bool > +sun8i_pwm_pair_rate_constrained(struct sun8i_pwm_chip *sun8i_chip, > + unsigned int idx) > +{ > + unsigned int sibling = 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 = SUN8I_PWM_PAIR_IDX(idx); > + u32 pdzcr, per; > + > + guard(spinlock_irqsave)(&sun8i_chip->lock); > + pdzcr = sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PDZCR(pair)); > + if (!(pdzcr & SUN8I_PWM_PDZCR_ENABLE)) > + return 0; > + > + per = sun8i_pwm_readl(sun8i_chip, SUN8I_PWM_PER); > + if (per & sun8i_pwm_pair_enable_mask(pair)) > + return -EOPNOTSUPP; > + > + pdzcr &= ~SUN8I_PWM_PDZCR_ENABLE; > + sun8i_pwm_writel(sun8i_chip, pdzcr, SUN8I_PWM_PDZCR(pair)); > + > + return 0; > +} [Severity: Medium] In drivers/pwm/pwm-sun8i.c:sun8i_pwm_clear_idle_deadzone(), can checking only SUN8I_PWM_PER return a false -EOPNOTSUPP when a channel in the pair is enabled in bypass mode? In sun8i_pwm_read_waveform(), SUN8I_PWM_PDZCR_ENABLE is ignored when wfhw->bypass_en is true: if (wfhw->enabled && !wfhw->bypass_en && ((pdzcr & SUN8I_PWM_PDZCR_ENABLE) || (pcr & SUN8I_PWM_PCR_MODE))) return -EOPNOTSUPP; Similarly, sun8i_pwm_write_waveform() skips sun8i_pwm_clear_idle_deadzone() when wfhw->bypass_en is true and sets SUN8I_PWM_ENABLE(pwm->hwpwm) in SUN8I_PWM_PER. If a pair has a dormant SUN8I_PWM_PDZCR_ENABLE bit set and a channel in that pair is enabled in bypass mode (either by firmware or a prior sun8i_pwm_write_waveform() call), a subsequent call to sun8i_pwm_write_waveform() with !wfhw->bypass_en calls sun8i_pwm_clear_idle_deadzone() before sun8i_pwm_prepare_update() stops the channel. Because sun8i_pwm_clear_idle_deadzone() checks per & sun8i_pwm_pair_enable_mask(pair) without checking whether the enabled channel is in bypass mode (or is the channel being reconfigured out of bypass mode), won't it reject the update with -EOPNOTSUPP instead of clearing the dormant dead-zone bit? [ ... ] > +static int sun8i_pwm_prepare_update(struct pwm_chip *chip, unsigned int idx, > + const struct sun8i_pwm_waveform *wfhw, > + struct sun8i_pwm_waveform *old) > +{ > + struct sun8i_pwm_chip *sun8i_chip = sun8i_pwm_from_chip(chip); > + struct sun8i_pwm_channel *chan = &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 = chan->rate_exclusive; > + > + if (!had_exclusive) { > + ret = clk_rate_exclusive_get(chan->pair_clk); > + if (ret) > + return ret; > + scoped_guard(spinlock_irqsave, &sun8i_chip->lock) > + chan->rate_exclusive = true; > + } [ ... ] > + /* Live PPR updates require unchanged configuration and a faster PCLK. */ > + bus_rate = clk_get_rate(sun8i_chip->bus_clk); > + stop = old->enabled && > + (old->bypass_en != wfhw->bypass_en || rate != wfhw->pair_rate || > + (!wfhw->bypass_en && > + (((old->pcr ^ wfhw->pcr) & > + (SUN8I_PWM_PCR_WAVEFORM_MASK | SUN8I_PWM_PCR_MODE)) || > + bus_rate <= 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 == wfhw->pair_rate) > + return 0; > + > + ret = clk_set_rate(chan->pair_clk, wfhw->pair_rate); > + if (!ret && sun8i_pwm_get_pair_rate(sun8i_chip, idx) == wfhw->pair_rate) > + return 0; > + if (!ret) > + ret = -EINVAL; > + > + if (sun8i_pwm_get_pair_rate(sun8i_chip, idx) != rate) { > + restore_ret = clk_set_rate(chan->pair_clk, rate); > + if (restore_ret || sun8i_pwm_get_pair_rate(sun8i_chip, idx) != 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; > +} [Severity: Medium] Does drivers/pwm/pwm-sun8i.c:sun8i_pwm_prepare_update() leak chan->rate_exclusive (and leave SUN8I_PWM_PCCR_BYPASS_BIT(idx) set) when restoring the pair clock rate fails on an already-enabled channel? When updating an active channel (old->enabled is true, so had_exclusive is true) that requires changing pair_rate, stop is true and the channel is disabled in SUN8I_PWM_PER via sun8i_pwm_set_enabled_locked(sun8i_chip, idx, false). If clk_set_rate(chan->pair_clk, wfhw->pair_rate) fails (or rounds to a different rate) and the rollback clk_set_rate(chan->pair_clk, rate) also fails to restore the original rate, the error path jumps to put_rate without re-enabling the channel in hardware. At put_rate, sun8i_pwm_put_rate() is only called when !had_exclusive. Since had_exclusive is true, chan->rate_exclusive remains true and clk_rate_exclusive_put(chan->pair_clk) is not called even though the channel is now disabled in hardware (and if old->bypass_en was true, its bypass bit in SUN8I_PWM_PCCR is also left set), preventing the sibling channel from changing the shared pair clock rate.