From nobody Mon Jun 8 06:39:38 2026 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E14340B6F9; Fri, 5 Jun 2026 07:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780642866; cv=none; b=rIQCxRsQzWjwRfwjCdfl9XhqtMYc7BZdAcJUPdCKBnOo2uS2t7GGF0oOvW9cDPhJve4QIagI3L/Bp7OXgynDzz/6SPJQ+vUsueBE60T08r0z51HWjkx+xt9pYCelz88A8vyNRmOf0eWAVVX7zT9Dup03xt6HlczNugUcWpzA2ZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780642866; c=relaxed/simple; bh=Eq2/FqQK+/3GGvQH1jgzjXllW8SOFixYwWstqkvt+Ks=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jKGFQSZvEUhKAZOwKee8jNH8XyBeo6WXTHRex8hiMuVsYWUm5gcDs7VJbwQdQ664cQeJS0Fl/ljUXnqDy0DjwOqrjnTRDjzNnEnNkCihYxcvfcTymNaUniOmLqEyGRTFLYabZMybP/pI9DDMjjnwg0PWkQc0MjAGNFeUWOb+2OA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=GGaoMEEQ; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=h4ZJD7pW; arc=none smtp.client-ip=80.241.56.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="GGaoMEEQ"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="h4ZJD7pW" Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4gWslx34H3z9v3Q; Fri, 5 Jun 2026 09:01:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1780642861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OpNBtlw9n2UCJW3D0hBUmygvSZ9hYaw7j0NNMC94AK4=; b=GGaoMEEQI3Xwgau5/KSpvAySoomQK91gLt491999CJTJ6qWIxbsGyRWlpefLN9VdkpzswO JGAcgDUAzmc7UgPYlp4OKVWP4tJKbFhq5wsvnqMJ6OUU3pK0gOALDBwQFrNC6szaYKMIw2 6krzfuD35LZwtB+Qdtm5yuWQztwa6NpqaGvu4htpakZpnkGwh6M8ntZSXp2/9r5OfXQY03 FMMKyGXZi6x7fr28Nb5AfT9rYeJI8seAq2HSlQQiIHMZGwOwKE+5JUwwHWvy9ykS7kaP15 VRUvl/pXHMPpDyO6kFED+yZTmSRkanpNWF+zRJP6Pf3KK0NkF4iOUSH4HqUnFg== From: Maurice Hieronymus DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1780642859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OpNBtlw9n2UCJW3D0hBUmygvSZ9hYaw7j0NNMC94AK4=; b=h4ZJD7pWeiBrHP178TiWZuxtX1fdKlYrIYx1VcSOMs+fzU84EYqGbu5FcO9uzIEgn91tcS Jn5LZ2ope1hnWhoapqqxQyz/frTp8TYH0gFRD5hSu0z9fFZxcx5oZRFn2FphEN4y86L+Oz fr6v2oGNgsu3TatoZA7Cm9zbjwpwIShCh6Qt9G9a1z4VOqsku+joy1N4jRACQlNvi9g7hf Hm4rcBOOLU7Wgoqddlr3fTTyQbz00s+Hv6+R8c3LLyTgDkYXMMcQAKoqm3OQPJkzyAYRd+ 3wgGQiQ1dBDrTr66YS16GVW+Q4Hs7zg1EsKk/MLGVaCo6DkfRtOL9lXNx+T13Q== Date: Fri, 05 Jun 2026 08:59:59 +0200 Subject: [PATCH v2 1/2] rust: clk: Add ExclusiveClk wrapper for clk_rate_exclusive_get 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: <20260605-rate-exclusive-get-th1520-v2-1-695640bf7249@mailbox.org> References: <20260605-rate-exclusive-get-th1520-v2-0-695640bf7249@mailbox.org> In-Reply-To: <20260605-rate-exclusive-get-th1520-v2-0-695640bf7249@mailbox.org> To: Michael Turquette , Stephen Boyd , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Drew Fustini , Guo Ren , Fu Wei , Michal Wilczynski , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: linux-clk@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pwm@vger.kernel.org, Maurice Hieronymus X-Developer-Signature: v=1; a=ed25519-sha256; t=1780642818; l=3552; i=mhi@mailbox.org; s=20260525; h=from:subject:message-id; bh=Eq2/FqQK+/3GGvQH1jgzjXllW8SOFixYwWstqkvt+Ks=; b=EnPdbF7ZbiSZsoiQzpqVV642CEH+9nF8nNVKGzxReY0KS0hzY5ErgB16n/ogDC4ZIgDHlnxRs 3pOhFWYN/TeBhXC4PYk2qu9FhThAApgBG4qR+jGpgZpndrfq7TktHcu X-Developer-Key: i=mhi@mailbox.org; a=ed25519; pk=AHlEkGG3hpXZHntlEzF42Ip/LFyXWOgsNUvaHqAnV80= X-MBO-RS-META: btqxt863ejstfjtaxooubyxo1r5tg14c X-MBO-RS-ID: 46288b54c5fc677ce46 Add Rust bindings for clk_rate_exclusive_get() and clk_rate_exclusive_put(). Clk::rate_exclusive_get() consumes the Clk and returns an ExclusiveClk; the matching put is issued from its Drop impl. ExclusiveClk derefs to Clk so existing rate / prepare / enable APIs remain available on the locked handle. Reviewed-by: Alice Ryhl Signed-off-by: Maurice Hieronymus --- rust/kernel/clk.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 60 insertions(+) diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs index 7abbd0767d8c..f834f4833f18 100644 --- a/rust/kernel/clk.rs +++ b/rust/kernel/clk.rs @@ -249,6 +249,22 @@ pub fn set_rate(&self, rate: Hertz) -> Result { // [`clk_set_rate`]. to_result(unsafe { bindings::clk_set_rate(self.as_raw(), rate.= as_hz()) }) } + + /// Acquire exclusive control over the clock's rate. + /// + /// Consumes the [`Clk`] and returns an [`ExclusiveClk`] that rele= ases the exclusivity + /// when dropped. While held, no other consumer may change the clo= ck's rate. + /// + /// Equivalent to the kernel's [`clk_rate_exclusive_get`] API. Mus= t not be called from + /// atomic context. + /// + /// [`clk_rate_exclusive_get`]: https://docs.kernel.org/core-api/k= ernel-api.html#c.clk_rate_exclusive_get + pub fn rate_exclusive_get(self) -> Result { + // SAFETY: By the type invariants, self.as_raw() is a valid ar= gument for + // [`clk_rate_exclusive_get`]. + to_result(unsafe { bindings::clk_rate_exclusive_get(self.as_ra= w()) })?; + Ok(ExclusiveClk(self)) + } } =20 impl Drop for Clk { @@ -329,6 +345,50 @@ fn deref(&self) -> &Clk { &self.0 } } + + /// A [`Clk`] with exclusive control over its rate. + /// + /// While an [`ExclusiveClk`] exists, no other consumer of the same cl= ock may change its rate. + /// Obtained by calling [`Clk::rate_exclusive_get`]; the exclusivity i= s released automatically + /// when the value is dropped, after which the inner [`Clk`] is droppe= d as usual. + /// + /// # Invariants + /// + /// An [`ExclusiveClk`] instance owns a [`Clk`] for which `clk_rate_ex= clusive_get` has been + /// called and the matching `clk_rate_exclusive_put` has not yet been = called. + /// + /// # Examples + /// + /// ``` + /// use kernel::clk::{Clk, ExclusiveClk}; + /// use kernel::device::Device; + /// use kernel::error::Result; + /// + /// fn lock_rate(dev: &Device) -> Result { + /// let clk =3D Clk::get(dev, None)?; + /// clk.prepare_enable()?; + /// clk.rate_exclusive_get() + /// } + /// ``` + pub struct ExclusiveClk(Clk); + + // Make [`ExclusiveClk`] behave like [`Clk`]. + impl Deref for ExclusiveClk { + type Target =3D Clk; + + fn deref(&self) -> &Clk { + &self.0 + } + } + + impl Drop for ExclusiveClk { + fn drop(&mut self) { + // SAFETY: By the type invariants, self.as_raw() is a valid ar= gument for + // [`clk_rate_exclusive_put`] and balances the [`clk_rate_excl= usive_get`] call from + // [`Clk::rate_exclusive_get`]. + unsafe { bindings::clk_rate_exclusive_put(self.as_raw()) }; + } + } } =20 #[cfg(CONFIG_COMMON_CLK)] --=20 2.51.2 From nobody Mon Jun 8 06:39:38 2026 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99D2137DE90; Fri, 5 Jun 2026 07:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780642874; cv=none; b=M9mR4EU//e6Y2Pn9nKMppI6dQ4qCZwUnsV4S9u7MNpzSQYIMgsRGzDF6hezUTAL4LEry+f3JSGQ9DdSAp91AHFsakn9ztZjGvaghT/Y9iX7f8wOd9PymO1JDCfKl4MHysiniXoerrPOitIXcSaP0fOg7xkxeAXuHDjBuROYXvJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780642874; c=relaxed/simple; bh=60xrDe66k4ro+KvVbaFJv2mj9P8kpFvqUKywbpSaqwI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CfR/2rcHDALFb9cKk00kr9rjgGeBYSt+CCztkh6gDzZr5rLxhA0A3iJNZ/l1wC/8TV1HeZAz8G5T24SqUPXdjtlVVU3Y46OgvzrMVZvVomEUWfJwyTA3MsSUZlnP+rpuvUgFsQH/1zVv02abscmdnoyvWW7sAbtgJE3zUsf+B90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=JdHrpnDO; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=eYEFdiXU; arc=none smtp.client-ip=80.241.56.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="JdHrpnDO"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="eYEFdiXU" Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4gWsm66mFWz9vJQ; Fri, 5 Jun 2026 09:01:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1780642871; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5AisOK8s0MrDK37/TSGMnTNdk0xSn+SbMsbMUZ0nmfk=; b=JdHrpnDOYCj2thOK1j2uixDXieb+46nyuy9pggdoRq9ZmunnyGBU4yK4sQwIvzHXYpxMnU /jYA2ihhzuwJR9d2mhWdVOLRuYmfOCCBucoYXa5khSwDTK+GWNoeh0MkpJ9fqpdWLhGkqz ZjKRFTqNSHSseMskqKqmsS5e4nOgpKQue4rjiDG0kenW0Q2qx5m2SDCnaZQMXNP+JpXFlD GroEL7ugJNhbViNlNupCZyOUJqoMKXpnR91GYZyNUeddBAVFquBt38bgBWQivA4XRijC5r DaPoQHdXAqL3rJzQuazzo4JzVDQYihRXzuFmrtX08+gP0eKnMpjEbg7d9bn5WQ== From: Maurice Hieronymus DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1780642869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5AisOK8s0MrDK37/TSGMnTNdk0xSn+SbMsbMUZ0nmfk=; b=eYEFdiXUTttRaoD+Afyd77elgOXcd3PbYltjw5qY1wPSxqjrh0bAcBU4fi8ViG/wGiFoLL WLB95UAcV9UXQr7AmrW3OmfvHzbLVw2IzxSDelnbt4EIMddcPPNU7v+oM4+AxEgVEKdmUv AEhf0qkm0ASOCl0fsmfyH4ztqA5UDc47pAFHR8iZzNTLgJPGNcvKjvVX8U42QESQnIX6Iz BdcWageqTOo3PEwTcK9ysLezZjHQ4P2EgUWjUi8i8ivnHWGrQDYtnuP3Xr3q77hb+bcIU7 ITtyQF7JJNn5kCWc4ZYqpXBIP8CbKST5L8+nkNQtsSCOWgX40kpsjR5H2+PPMQ== Date: Fri, 05 Jun 2026 09:00:00 +0200 Subject: [PATCH v2 2/2] pwm: th1520: Lock clock rate with clk_rate_exclusive_get 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: <20260605-rate-exclusive-get-th1520-v2-2-695640bf7249@mailbox.org> References: <20260605-rate-exclusive-get-th1520-v2-0-695640bf7249@mailbox.org> In-Reply-To: <20260605-rate-exclusive-get-th1520-v2-0-695640bf7249@mailbox.org> To: Michael Turquette , Stephen Boyd , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Drew Fustini , Guo Ren , Fu Wei , Michal Wilczynski , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: linux-clk@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pwm@vger.kernel.org, Maurice Hieronymus X-Developer-Signature: v=1; a=ed25519-sha256; t=1780642818; l=1573; i=mhi@mailbox.org; s=20260525; h=from:subject:message-id; bh=60xrDe66k4ro+KvVbaFJv2mj9P8kpFvqUKywbpSaqwI=; b=WGnFX7PcxbBDEWUXjmEwNTBR0kSfl2DufCpeg/+PtLA111qvEc4g/HvbvGFUtb8xe+w8VJkIJ ajVQyrtia3FCoSl7ss/PX3cylicvjwS9bby/KwyEGzgtYLN+c49u4L1 X-Developer-Key: i=mhi@mailbox.org; a=ed25519; pk=AHlEkGG3hpXZHntlEzF42Ip/LFyXWOgsNUvaHqAnV80= X-MBO-RS-ID: 0b9247bacab9cefd338 X-MBO-RS-META: 3b51q85kj4buq3xszfzwttb54czpc51w The driver derives period and duty cycle from the clock rate read at probe, so a later rate change would silently miscompute waveforms. Switch to the new ExclusiveClk wrapper to hold the rate for the lifetime of the driver data and drop the corresponding TODO. Reviewed-by: Alice Ryhl Signed-off-by: Maurice Hieronymus --- drivers/pwm/pwm_th1520.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/pwm/pwm_th1520.rs b/drivers/pwm/pwm_th1520.rs index ddd44a5ce497..19e8621bc52c 100644 --- a/drivers/pwm/pwm_th1520.rs +++ b/drivers/pwm/pwm_th1520.rs @@ -22,7 +22,7 @@ =20 use core::ops::Deref; use kernel::{ - clk::Clk, + clk::{Clk, ExclusiveClk}, device::{Bound, Core, Device}, devres, io::{ @@ -93,7 +93,7 @@ struct Th1520WfHw { struct Th1520PwmDriverData { #[pin] iomem: devres::Devres>, - clk: Clk, + clk: ExclusiveClk, } =20 impl pwm::PwmOps for Th1520PwmDriverData { @@ -328,10 +328,8 @@ fn probe( let clk =3D Clk::get(dev, None)?; =20 clk.prepare_enable()?; + let clk =3D clk.rate_exclusive_get()?; =20 - // TODO: Get exclusive ownership of the clock to prevent rate chan= ges. - // The Rust equivalent of `clk_rate_exclusive_get()` is not yet av= ailable. - // This should be updated once it is implemented. let rate_hz =3D clk.rate().as_hz(); if rate_hz =3D=3D 0 { dev_err!(dev, "Clock rate is zero\n"); --=20 2.51.2