From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 82EB626D4E7 for ; Wed, 2 Jul 2025 13:12:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751461944; cv=none; b=LcDXzwJHtPwktDlD4s/Ig0+Ue9t2eqi+nmlSdpjb2AnjYgnL6HQZZJa9U2RGlAHRvwZ0mrGu3rwaSyxdYItWAFASL1aTOOrMYXvk0jYTWnXTmB+hg+fVvVw5Rp46O/JtngLZsBHj9VlhqGpGJssQXP4nGIEVDuTWStbJ4ZuDSjk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751461944; c=relaxed/simple; bh=fAe1pSCwvG+JbEAUEWuBmKD5l7BHh4JT9DVEQ4MqRmM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=U77YnpImmmrcYeW8wxyD1w0JAS6twHyyfB6fEGm21ft7GS5K4m778lQT6ajJdMRdsae0iXqRgqk2cOC06V+aNiMqdXHAoTfnSsVNAWgx9UEE62UDPw0slG/SLsJKJHc5J4emZyj2cS+QAt2vJ12EhnzZu2MfllfR6WhgHE2ziK0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nyKwXgSi; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nyKwXgSi" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3121aed2435so6305898a91.2 for ; Wed, 02 Jul 2025 06:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751461943; x=1752066743; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ytoK/nx9JW3TYPkFJe7nDJOlWgDHzDyFKz2wtGj0glc=; b=nyKwXgSiteI4TcT1DcvHbUfHslaBo9bzSZTZmf5kraMdVSVAub4YhseC3yXZ+bax7e JU72tcMX3nwEaHIAEsjHRt21WdRa/jTADUXbrL3W83hIo1TACF0NL5nILar/Lw+Le7ke w4yz9NbuDDp7uSvvoEONXC8tRvOGo71NTKFP0rpPIyR7jqURK63uf9ELFFWAXQ6fE8WU hdfuSC4wphQerZO5hGruqRwZdtViKXcIsI5baM4V0JliNNVbq/Utw8PoWgxUqOMFWmU0 XWWTr7+JGAJPu1BjScaXD4hSs4vdqMoMrpyJGBpJ5ldEi9Refplcp+H/Ch+A5FNzbB4l Uh/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751461943; x=1752066743; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ytoK/nx9JW3TYPkFJe7nDJOlWgDHzDyFKz2wtGj0glc=; b=nuYFO2ZH4nV+Hhjn4mG1qaeYJIpniJ/RBIlZSwRCzW/ZEiDP9EQNQe6NXYUiGM/IHC wMmkIAFWcLrAxTClUCO/FU8q+rIDvWsBwhnT9IvDHzuiXkWsTzAGdtfd95M3lyEHSUUS HOuZ/NlOJnnRAM3V3mQ4MmSTYQ23FFMPOT3wi0uzs57GlSfHMx7ixx2tdRIEwl6jIrM9 qd6D6nOvX922J8LHnY2ldmc1TEHWEA/qhupIMQdcvFVQyOFdfNR/QNEHEVOS+064885M 263ULSAg61fkLjn5RSS3UK49bEqKB5MftDV7T4iFRLGijXqc8acmgVT/ZmnYT+jfuWx2 yyqw== X-Forwarded-Encrypted: i=1; AJvYcCXhBU7uJFf8hNiawPf6mx6yFzO/VCUQdUjpsDBuH1bgGVpx93uErBsXNHWyoXKKfajhADwWVn1A2E3KyDxBmQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxeEiyEJbtury68m2+dVM1aGsHO8AZHSB0rW1ireO6kQJRX3y+N HCKcV/3/PucXZQ2JQ18l2PgyJmz/pdZAIchPCIu0ljXzk5nRBBNAbN6FhNv2BGqbTjSD5xhyEDA sOfJCV2k22Z3bV59vKCPnLJ7FpIkzgQCvGu+fjK64 X-Gm-Gg: ASbGnct6PBnC4ghn0BQ9vufatP7pBkuTNOcmclBkA4XcEk4RkfTfgQ6Y/2XVd7gvSUi ZqXtZtZTjKuFX0PI4yFYYt3hdZf/WiRmPFwNgnXETmzT2zyevKvJUG+zXj4YLCv/j889IKdzYBA Lw2k3udoXN21bgVo2/MjcJ/LyhiNwNMNXLn21Kd6kgWVwYLR3CbCsSu8OyFrIdwI8mRSDF2KM= X-Google-Smtp-Source: AGHT+IFiERqUE3Rnrk3I3rryjB/sI1mDdOe7LfYtqgmx6pOYxn6SUXRHBeINY2kZ0sAPWB/L5qYNOyRsrBV247YTrkA= X-Received: by 2002:a17:90b:570c:b0:311:ad7f:329c with SMTP id 98e67ed59e1d1-31a90bcadcfmr5412141a91.18.1751461942552; Wed, 02 Jul 2025 06:12:22 -0700 (PDT) Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20250627-topics-tyr-regulator-v6-0-1d015219b454@collabora.com> <20250627-topics-tyr-regulator-v6-1-1d015219b454@collabora.com> <1DFECD1D-9445-4D59-A727-37C527B5DFF5@collabora.com> In-Reply-To: <1DFECD1D-9445-4D59-A727-37C527B5DFF5@collabora.com> From: Alice Ryhl Date: Wed, 2 Jul 2025 15:12:08 +0200 X-Gm-Features: Ac12FXzwPJEj-QcLJVz3TrROG0dXHqdlvlhkJ4v6quqraoEz-bmVPqPGsJPe2yI Message-ID: Subject: Re: [PATCH v6 1/2] rust: regulator: add a bare minimum regulator abstraction To: Daniel Almeida Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Boris Brezillon , Sebastian Reichel , Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jul 2, 2025 at 3:03=E2=80=AFPM Daniel Almeida wrote: > > Hi Alice, > > > On 2 Jul 2025, at 07:35, Alice Ryhl wrote: > > > > On Fri, Jun 27, 2025 at 7:11=E2=80=AFPM Daniel Almeida > > wrote: > >> > >> Add a bare minimum regulator abstraction to be used by Rust drivers. > >> This abstraction adds a small subset of the regulator API, which is > >> thought to be sufficient for the drivers we have now. > >> > >> Regulators provide the power needed by many hardware blocks and thus a= re > >> likely to be needed by a lot of drivers. > >> > >> It was tested on rk3588, where it was used to power up the "mali" > >> regulator in order to power up the GPU. > >> > >> Signed-off-by: Daniel Almeida > > > > Overall looks reasonable to me. > > > >> +/// A trait that abstracts the ability to check if a [`Regulator`] is= enabled. > >> +pub trait IsEnabled: RegulatorState {} > >> +impl IsEnabled for Disabled {} > >> +impl IsEnabled for Dynamic {} > > > > Naming-wise, it's a bit weird that IsEnabled applies to everything > > *but* enabled. And also, the is_enabled() method should probably exist > > for only Dynamic anyway? > > I think it's the other way around? Enabled doesn't need this impl precise= ly > because of the Enabled token. IOW: > > Regulator::is_enabled() doesn't make sense. > > > And also, the is_enabled() method should probably exist for only Dynam= ic anyway? > > Also no, because Regulator isn't necessarily disabled. It just = was > not enabled by us, but might have been enabled by somebody else in the sy= stem. Okay. > >> +impl Drop for Regulator { > >> + fn drop(&mut self) { > >> + if core::any::TypeId::of::() =3D=3D core::any::TypeId::of:= :() { > > > > I would avoid this kind of logic. Instead, you can add an > > `disable_on_drop()` method or constant to the trait and check it here. > > > > Alice > > > > Can you expand on this? Along these lines: pub trait RegulatorState: 'static { const DISABLE_ON_DROP: bool; } impl RegulatorState for Enabled { const DISABLE_ON_DROP: bool =3D true; } impl RegulatorState for Disabled { const DISABLE_ON_DROP: bool =3D false; } impl RegulatorState for Dynamic { const DISABLE_ON_DROP: bool =3D false; } impl Drop for Regulator { fn drop(&mut self) { if T::DISABLE_ON_DROP { unsafe { bindings::regulator_disable(self.inner.as_ptr()) }; } unsafe { bindings::regulator_put(self.inner.as_ptr()) }; } }