From nobody Thu Oct 2 13:03:49 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 7A0162FF669 for ; Tue, 16 Sep 2025 10:24:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018260; cv=none; b=c9twljSGfxvpZ1ZI8imQJgDC7dy1/leU5vr99ONMxb4/Chb+4fqzDn0WAr9yKe9f7QizfW8Tf8zTsnWKTSQTnOtx+XpKdj6Vv3kxS5isExV7IG8l9UGk4yofdZm+gnBk4OWjyWfh7ZgdT0X4FmzZSrYRm/dL3vAHSHcf7R/m+L4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018260; c=relaxed/simple; bh=1HH2OEcu+cpc+I8pNMm7X8z4A5Dj+Gawx9fnsMB1wgs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g1KDNF0LD4b9Ig6WDdoYR90DtkOPgGVe39WSJ0hYbQDgGoDAvMEYBNcOdE0XBB7hmT3/6SMH7d4iUsOKhGe1qiSFuydya7tF7ActwMg8zwSc04Gh5PLdkbsu9rE5+6H29Mp9fQktEggoKaR/KhwwUAHfto8knLDc0Lv+dAxMeYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=UncBYGta; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="UncBYGta" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id F3B4B4E40BDF; Tue, 16 Sep 2025 10:24:16 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C86376061E; Tue, 16 Sep 2025 10:24:16 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 65A7A102F16DF; Tue, 16 Sep 2025 12:24:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1758018255; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=QmgIZk8v+yaO4KbxgsVom5F3SapikDvNEzIqr0l6CME=; b=UncBYGtaNWoFCZJ9ojRw9CNZFtnDWAray699C2BrLgpRlFfZTYSWOJTl7MF0hpUsbVrzYK 7mP1E9hb0kxyQGcM02lhgOMz9c3s9wxSEcQwMMkSCJItE7BFsHn0e2vlp6MgdPEJJ0o6pB ZacmwpvfieXrR6eCnj/gZ9yIgYEPE9XPwsCdG84U3RjIPyOeTPbSV0Tjomo8IX4hmzEd31 A/Mih5Di3iAonrRaXQNsizoX/lJJnUyJbcF0yv2TiCMiousFV0lVA/2XVMPxHAlECoAKY1 KPfS5HwIE/1Empflk+Wk+LjQ+oSwt7A4S0xytUXb53A+tAkXl9X0LmJd01bBxA== From: Romain Gantois Date: Tue, 16 Sep 2025 12:24:06 +0200 Subject: [PATCH 1/4] regulator: dt-bindings: Add Linear Technology LTM8054 regulator 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: <20250916-ltm8054-driver-v1-1-fd4e781d33b9@bootlin.com> References: <20250916-ltm8054-driver-v1-0-fd4e781d33b9@bootlin.com> In-Reply-To: <20250916-ltm8054-driver-v1-0-fd4e781d33b9@bootlin.com> To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Romain Gantois X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 The Linear Technology LTM8054 is a Buck-Boost voltage regulator with an input range of 5V to 36V and an output range of 1.2V to 36V. The LTM8054's output voltage level is typically set using a voltage divider between the Vout and FB pins, the FB pin being constantly regulated to 1.2V. The output current limit of the LTM8054 may be statically set by placing a sense resistor on a dedicated pin. This limit can then be lowered by controlling the voltage level on the CTL pin. Describe the LTM8054 voltage regulator. Signed-off-by: Romain Gantois --- .../bindings/regulator/lltc,ltm8054.yaml | 77 ++++++++++++++++++= ++++ MAINTAINERS | 5 ++ 2 files changed, 82 insertions(+) diff --git a/Documentation/devicetree/bindings/regulator/lltc,ltm8054.yaml = b/Documentation/devicetree/bindings/regulator/lltc,ltm8054.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4db11be178b0e662ec51f3d3d73= 202f8c32625d3 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/lltc,ltm8054.yaml @@ -0,0 +1,77 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/lltc,ltm8054.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology LTM8054 buck-boost regulator + +maintainers: + - Romain Gantois + +description: + This regulator operates over an input voltage range of 5V to 36V, and can + output from 1.2V to 36V. The output voltage level is typically set with a + voltage divider between the Vout pin and the FB pin which is internally + regulated to 1.2V. + + The output current of the LTM8054 can be limited by tying the Iout pin t= o a + current sense resistor. This limit can be further lowered by applying a + voltage below 1.2V to the CTL pin. + +allOf: + - $ref: /schemas/regulator/regulator.yaml# + +properties: + compatible: + const: lltc,ltm8054 + + enable-gpios: + description: GPIO connected to the RUN pin. + maxItems: 1 + + lltc,fb-voltage-divider: + description: + An array of two integers containing the resistor values + R1 and R2 of the feedback voltage divider in Ohms. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + + lltc,iout-rsense-micro-ohms: + description: + Value of the output current sense resistor, in micro Ohms. + + io-channels: + items: + - description: DAC controlling the voltage level of the CTL pin. + + io-channel-names: + items: + - const: ctl + +required: + - compatible + - lltc,fb-voltage-divider + +additionalProperties: false + +examples: + - | + #include + + / { + + regulator { + compatible =3D "lltc,ltm8054"; + + enable-gpios =3D <&gpio0 1 GPIO_ACTIVE_HIGH>; + + lltc,fb-voltage-divider =3D <1000000 68000>; + + lltc,iout-rsense-micro-ohms =3D <20000>; + + io-channels =3D <&dac 1>; + io-channel-names =3D "ctl"; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index fe168477caa45799dfe07de2f54de6d6a1ce0615..7160179e6bf9d45a241582c1b6d= f8c0ebf6c3641 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14517,6 +14517,11 @@ W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt F: drivers/i2c/muxes/i2c-mux-ltc4306.c =20 +LTM8054 REGULATOR DRIVER +M: Romain Gantois +S: Maintained +F: Documentation/devicetree/bindings/regulator/lltc,ltm8054.yaml + LTP (Linux Test Project) M: Andrea Cervesato M: Cyril Hrubis --=20 2.51.0 From nobody Thu Oct 2 13:03:49 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 393D52F83D3; Tue, 16 Sep 2025 10:24:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018263; cv=none; b=Gmb1d68rsSFZVu3jylXnz9MJRCzXOxKtphR7AidbS3puQ8VFrmMSCaNOM2BFf/Xel6w+WAFfwoLEK4wHYd5d5PXteG8jRGmH7r9NZJ4tm1607oqQY475+0H8YuXSXrAa9og2h/hKoZQQEv6+HP3ZdaIRmYo8C+S8OTKodUidxeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018263; c=relaxed/simple; bh=JY0fFNmZkGmq+Wab0Bv84GX2dVej9Vw1GK950MMgu+k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R7YchVai0Z7RuMCKqbMK5BCDwTj5deXDn1kj2EMF57UKOdRV3l5HAbXnPg146dyQZmZLeydZA4h3TYVaAFuEAYbYoX09yJ4VQkdfQZawvrBUBXa5cqYLGU8Nfq2eY9c3xdhS24oZiwp8TNBq1wB+3qTCwKKf7FLVHDPB2HyWXb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=OqeqPqTB; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="OqeqPqTB" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 950B24E40BE1; Tue, 16 Sep 2025 10:24:18 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 6ABC46061E; Tue, 16 Sep 2025 10:24:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5CD85102F16E3; Tue, 16 Sep 2025 12:24:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1758018257; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=+w4qyJOBPfboDMhAjnHDcdTXTS+iPutFVtkMdVT7DPE=; b=OqeqPqTBJQmL7dz4Ya3Y4NvUZ2Qx3yawiot0xxwi5v33XjNj7OkUDfZvwDrB71ANLTHzz4 MsI1HCeK51gK6tDryCfoNlxi0ia/2oBZBEFa2Koc0evvx1bBWZtQ5Xr22ucW27hEcYgxB0 HHb1jJ9/4lKi6iPPKrB+TCajpzuxkyw/vbYmHJ4WZZtyH9RHwsfZ2RzAicjIYIvKAMrYxc KOGYOOVGclAXVpjEgcMOZmWHhSTNLlOaMtrJNt7i1ZMWaRZDDg4H2FGdEQNzJ7tXDIRPPl 2JtPXYPX5PsLNZkzJoAmT1QEe7ZltKAmsLStQuJm6TWGACvWOHEHQ87UwkUR1A== From: Romain Gantois Date: Tue, 16 Sep 2025 12:24:07 +0200 Subject: [PATCH 2/4] iio: add processed write API 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: <20250916-ltm8054-driver-v1-2-fd4e781d33b9@bootlin.com> References: <20250916-ltm8054-driver-v1-0-fd4e781d33b9@bootlin.com> In-Reply-To: <20250916-ltm8054-driver-v1-0-fd4e781d33b9@bootlin.com> To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Romain Gantois X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 Add a function to allow IIO consumers to write a processed value to a channel. Signed-off-by: Romain Gantois --- drivers/iio/inkern.c | 99 ++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/iio/consumer.h | 17 ++++++++ 2 files changed, 116 insertions(+) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index c174ebb7d5e6d183674b7ffb15c4ce0f65fa3aed..6486fdb7c66a4c84312541f0f42= cc24469972a9c 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -598,6 +598,85 @@ int iio_read_channel_average_raw(struct iio_channel *c= han, int *val) } EXPORT_SYMBOL_GPL(iio_read_channel_average_raw); =20 +static int iio_convert_processed_to_raw_unlocked(struct iio_channel *chan, + int processed, int *raw, + unsigned int scale) +{ + int scale_type, scale_val, scale_val2; + int offset_type, offset_val, offset_val2; + s64 tmp_num, tmp_den; + + scale_type =3D iio_channel_read(chan, &scale_val, &scale_val2, + IIO_CHAN_INFO_SCALE); + if (scale_type >=3D 0) { + switch (scale_type) { + case IIO_VAL_INT: + tmp_num =3D processed; + tmp_den =3D scale_val; + break; + case IIO_VAL_INT_PLUS_MICRO: + tmp_num =3D (s64)processed * 1000000LL; + + if (scale_val2 < 0) { + tmp_den =3D (s64)scale_val * 1000000LL - (s64)scale_val2; + tmp_den *=3D -1; + } else { + tmp_den =3D (s64)scale_val * 1000000LL + (s64)scale_val2; + } + + break; + case IIO_VAL_INT_PLUS_NANO: + tmp_num =3D (s64)processed * 1000000000LL; + + if (scale_val2 < 0) { + tmp_den =3D (s64)scale_val * 1000000000LL - (s64)scale_val2; + tmp_den *=3D -1; + } else { + tmp_den =3D (s64)scale_val * 1000000000LL + (s64)scale_val2; + } + + break; + case IIO_VAL_FRACTIONAL: + tmp_num =3D (s64)processed * (s64)scale_val2; + tmp_den =3D scale_val; + break; + case IIO_VAL_FRACTIONAL_LOG2: + tmp_num =3D (s64)processed << scale_val2; + tmp_den =3D scale_val; + break; + default: + return -EINVAL; + } + + tmp_den *=3D scale; + + *raw =3D div64_s64(tmp_num, tmp_den); + } + + offset_type =3D iio_channel_read(chan, &offset_val, &offset_val2, + IIO_CHAN_INFO_OFFSET); + if (offset_type >=3D 0) { + switch (offset_type) { + case IIO_VAL_INT: + case IIO_VAL_INT_PLUS_MICRO: + case IIO_VAL_INT_PLUS_NANO: + break; + case IIO_VAL_FRACTIONAL: + offset_val /=3D offset_val2; + break; + case IIO_VAL_FRACTIONAL_LOG2: + offset_val >>=3D offset_val2; + break; + default: + return -EINVAL; + } + + *raw -=3D offset_val; + } + + return 0; +} + static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, int raw, int *processed, unsigned int scale) @@ -1028,3 +1107,23 @@ ssize_t iio_read_channel_label(struct iio_channel *c= han, char *buf) return do_iio_read_channel_label(chan->indio_dev, chan->channel, buf); } EXPORT_SYMBOL_GPL(iio_read_channel_label); + +int iio_write_channel_processed_scale(struct iio_channel *chan, int val, + unsigned int scale) +{ + struct iio_dev_opaque *iio_dev_opaque =3D to_iio_dev_opaque(chan->indio_d= ev); + int ret, processed; + + guard(mutex)(&iio_dev_opaque->info_exist_lock); + + if (!chan->indio_dev->info) + return -ENODEV; + + ret =3D iio_convert_processed_to_raw_unlocked(chan, val, &processed, scal= e); + if (ret) + return ret; + + return iio_channel_write(chan, processed, 0, IIO_CHAN_INFO_RAW); +} +EXPORT_SYMBOL_GPL(iio_write_channel_processed_scale); + diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index 6a44796164792b2dd930f8168b14de327a80a6f7..79c4804a73b0652d4c16ee5ad07= c4543bccd6c92 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -451,4 +451,21 @@ ssize_t iio_write_channel_ext_info(struct iio_channel = *chan, const char *attr, */ ssize_t iio_read_channel_label(struct iio_channel *chan, char *buf); =20 +/** + * iio_write_channel_processed_scale() - scale and write processed value t= o a given channel + * @chan: The channel being queried. + * @val: Value to write. + * @scale: Scale factor to apply during the conversion + * + * Returns an error code or 0. + * + * This function writes a processed value to a channel. A processed value = means + * that this value will have the correct unit and not some device internal + * representation. If the device does not support writing a processed valu= e, the + * function will query the channel's scale and offset and write an appropr= iately + * transformed raw value. + */ +int iio_write_channel_processed_scale(struct iio_channel *chan, int val, + unsigned int scale); + #endif --=20 2.51.0 From nobody Thu Oct 2 13:03:49 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 5CCE93054D0 for ; Tue, 16 Sep 2025 10:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018264; cv=none; b=o6Kf6cqbykM53lXRj/kQbG/7D/CAwi4XCl1PL6I7EJcvMMXSJbLIe8EL8JKFpo2OpIuJKq9qz9MOIeU7/nDWepC8Ehz5amuqOEjIcmIqTho+wSjcCIAwGymhoGO3ui3Nz+qD7onUjkoMZQRMC7AJVbowx+DNjH6QDe8kEv+RFFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018264; c=relaxed/simple; bh=vC6bak3vajHp/KdZeZhz8m7Ms2hMvoLFBwxuzDF7oJI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q11TJ+GySVFxBNFthChkit0UbWdV1FnGc9RAaKgkk03LuJrlhsnAamXBdNo8HbIpWHfIHYxCp3rOqhDyR1GIsq3ILVuZnHlftYID4PAcfjGUZBipLb8uvBH8TKx2RJDIuGGNFidmgZ4SorCNiP70BWOOdaU1Br7cHa4qfaViSck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=0WpEc2FM; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="0WpEc2FM" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 075884E40BB5; Tue, 16 Sep 2025 10:24:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id D132F6061E; Tue, 16 Sep 2025 10:24:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 082BA102F16D4; Tue, 16 Sep 2025 12:24:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1758018259; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=odLlbEbxIjN2irzHQdkofES+um0xswwNXAgaifLMN0M=; b=0WpEc2FMItr0WO4B17EGk9jPpbGZnPISnz+SSyYUsRY+e/jLbibtu+PeRMqIZgDuoq+W0/ 4qoY0m1CWU+2CLNT78XdXz1/c9YC8/IccoKZDXj6NcPOHQ8V8VTFd1ynLpkC/k1/N0A0lr LvegIVF973yvQx4OGv51W0lb3cBe92i7oUfgslzGR6lKjmWIBdk0XwmGGyRBUXCw9zoDz0 lAF4zUoLWvoWVKtNYh1/jvbHoXDfYptSjfhP1m5jEcWkIoiRSfQcIg/kkmx/IgOi4fYj+R F/1LxPTChO4hSoBv1Y8JyhLQ8GiyY56lGQhSRqnVo154l+tIq4O4ioTTpCMqIQ== From: Romain Gantois Date: Tue, 16 Sep 2025 12:24:08 +0200 Subject: [PATCH 3/4] regulator: Support the LTM8054 voltage regulator 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: <20250916-ltm8054-driver-v1-3-fd4e781d33b9@bootlin.com> References: <20250916-ltm8054-driver-v1-0-fd4e781d33b9@bootlin.com> In-Reply-To: <20250916-ltm8054-driver-v1-0-fd4e781d33b9@bootlin.com> To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Romain Gantois X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 Add a stub driver for the Linear Technology LTM8054 Buck-Boost voltage regulator. This version only supports enabling/disabling the regulator via a GPIO, and reporting the output voltage level from the resistor divider values given in the device tree. Signed-off-by: Romain Gantois --- MAINTAINERS | 1 + drivers/regulator/Kconfig | 8 +++ drivers/regulator/Makefile | 1 + drivers/regulator/ltm8054-regulator.c | 120 ++++++++++++++++++++++++++++++= ++++ 4 files changed, 130 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 7160179e6bf9d45a241582c1b6df8c0ebf6c3641..4bc1a0e4c087060295a927da02f= 56c332269035f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14521,6 +14521,7 @@ LTM8054 REGULATOR DRIVER M: Romain Gantois S: Maintained F: Documentation/devicetree/bindings/regulator/lltc,ltm8054.yaml +F: drivers/regulator/ltm8054-regulator.c =20 LTP (Linux Test Project) M: Andrea Cervesato diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index eaa6df1c9f806652a21942bcb48084ba63f942d9..15fb71193b67d0b2daa631b6977= 8dde9323aedd2 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -577,6 +577,14 @@ config REGULATOR_LTC3676 This enables support for the LTC3676 8-output regulators controlled via I2C. =20 +config REGULATOR_LTM8054 + tristate "LTM8054 Buck-Boost voltage regulator" + help + This driver provides support for the Linear Technology LTM8054 + Buck-Boost micromodule regulator. The LTM8054 has an adjustable + output current limitation and a feedback pin for setting the + output voltage level. + config REGULATOR_MAX14577 tristate "Maxim 14577/77836 regulator" depends on MFD_MAX14577 diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index be98b29d6675d8be1ca984c2d137bdfc4ba2de87..0e61ef826c08f64ea638d19bf10= e69abf1526aa7 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -70,6 +70,7 @@ obj-$(CONFIG_REGULATOR_LP8788) +=3D lp8788-ldo.o obj-$(CONFIG_REGULATOR_LP8755) +=3D lp8755.o obj-$(CONFIG_REGULATOR_LTC3589) +=3D ltc3589.o obj-$(CONFIG_REGULATOR_LTC3676) +=3D ltc3676.o +obj-$(CONFIG_REGULATOR_LTM8054) +=3D ltm8054-regulator.o obj-$(CONFIG_REGULATOR_MAX14577) +=3D max14577-regulator.o obj-$(CONFIG_REGULATOR_MAX1586) +=3D max1586.o obj-$(CONFIG_REGULATOR_MAX5970) +=3D max5970-regulator.o diff --git a/drivers/regulator/ltm8054-regulator.c b/drivers/regulator/ltm8= 054-regulator.c new file mode 100644 index 0000000000000000000000000000000000000000..e41bd95da55fb87912e2cdf70ba= e231133c25745 --- /dev/null +++ b/drivers/regulator/ltm8054-regulator.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Linear Technology LTM8054 Buck-Boost regulator driver + * + * Copyright (C) 2025 Bootlin + */ + +#include +#include +#include +#include +#include +#include +#include + +/* The LTM8054 regulates its FB pin to 1.2V */ +#define LTM8054_FB_V 1200000 + +struct ltm8054_priv { + struct regulator_desc rdesc; +}; + +static int ltm8054_scale(unsigned int uV, u32 r1, u32 r2) +{ + u64 tmp; + + tmp =3D (u64)uV * r1; + do_div(tmp, r2); + + return uV + (unsigned int)tmp; +} + +static const struct regulator_ops ltm8054_regulator_ops =3D { +}; + +static int ltm8054_of_parse(struct device *dev, struct ltm8054_priv *priv, + struct regulator_config *config) +{ + struct device_node *np =3D dev->of_node; + u32 r[2]; + int ret; + + config->of_node =3D np; + + ret =3D of_property_read_u32_array(np, "lltc,fb-voltage-divider", r, 2); + if (ret) { + dev_err(dev, "Failed to parse voltage divider\n"); + return ret; + } + + priv->rdesc.fixed_uV =3D ltm8054_scale(LTM8054_FB_V, r[0], r[1]); + priv->rdesc.min_uV =3D priv->rdesc.fixed_uV; + priv->rdesc.n_voltages =3D 1; + + config->init_data =3D of_get_regulator_init_data(dev, + np, + &priv->rdesc); + if (!config->init_data) { + dev_err(dev, "failed to parse init data\n"); + return -EINVAL; + } + + config->ena_gpiod =3D devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LO= W); + if (IS_ERR(config->ena_gpiod)) { + dev_err(dev, "unable to acquire enable gpio\n"); + return PTR_ERR(config->ena_gpiod); + } + + return 0; +} + +static int ltm8054_probe(struct platform_device *pdev) +{ + struct regulator_config config =3D { 0 }; + struct regulator_dev *rdev; + struct ltm8054_priv *priv; + int ret; + + priv =3D devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->rdesc.name =3D "ltm8054-regulator", + priv->rdesc.ops =3D <m8054_regulator_ops, + priv->rdesc.type =3D REGULATOR_VOLTAGE, + priv->rdesc.owner =3D THIS_MODULE, + + config.dev =3D &pdev->dev; + config.driver_data =3D priv; + + ret =3D ltm8054_of_parse(&pdev->dev, priv, &config); + if (ret) + return dev_err_probe(&pdev->dev, ret, "failed to parse device tree\n"); + + rdev =3D devm_regulator_register(&pdev->dev, &priv->rdesc, &config); + if (IS_ERR(rdev)) + return dev_err_probe(&pdev->dev, PTR_ERR(rdev), "failed to register regu= lator\n"); + + return 0; +} + +static const struct of_device_id __maybe_unused ltm8054_of_match[] =3D { + { .compatible =3D "lltc,ltm8054", }, + {}, +}; +MODULE_DEVICE_TABLE(of, ltm8054_of_match); + +static struct platform_driver ltm8054_driver =3D { + .probe =3D ltm8054_probe, + .driver =3D { + .name =3D "ltm8054", + .of_match_table =3D of_match_ptr(ltm8054_of_match), + }, +}; + +module_platform_driver(ltm8054_driver); + +MODULE_DESCRIPTION("LTM8054 regulator driver"); +MODULE_AUTHOR("Romain Gantois "); +MODULE_LICENSE("GPL"); --=20 2.51.0 From nobody Thu Oct 2 13:03:49 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 E144B305E24 for ; Tue, 16 Sep 2025 10:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018265; cv=none; b=GuUZoqFUMJqJg6X7x1QxHE3aTU8liWnQW6qqjFJgPhwo5x+mHMZ5rRYTFC6h2nCUIxrPBqV31Hhr448AtNtUgN8jF0ujErn4CuqRDfsen55Fsn1YZRskwH6rhsSYCYmkPk7JhEuikMBvqu6MUm7ZUfYnXmsrvzkGM1s7xv3F40I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018265; c=relaxed/simple; bh=eno6mobSsV0Vz477n004Idm38KpAYuuVSri+PQ/cVmg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Hl1EsQEn696uV/Wsltr8nyyk7ZybY1K5xZFBhcb+2Z0PraWw9YCrBol5xOzn3sdGpaWS8posOQ7EdX6DFaMO/buhEi9OTy/dcThurs9gmc+JQ4bNRDup/ItJE28+CPYCYhIFoMbuqRMszlv9TwWrBSWAdFtH49w1g1HphI/hpBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=afZ84qiZ; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="afZ84qiZ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 742171A0D84; Tue, 16 Sep 2025 10:24:22 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4A5086061E; Tue, 16 Sep 2025 10:24:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 448C1102F16DF; Tue, 16 Sep 2025 12:24:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1758018261; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=7xH/6o5AG/ZkEV08qqD3o809y7CCiNGJ+1iwApjb1E0=; b=afZ84qiZvW+v0wFW+c7lZHQr3eOyRJFuW33zqsqor6rzpbz0wu0WoiaUVuu31jPiZ14wyZ jhuYm6fA8xj6+Wo02YvtK/AC/UKyuBzkwUXRu9+uQyqtyPQJdYKoLqTrN5VmXNsQajDT4Q NqCEpj6nf6xR6/nC7oRPRlGiUEhDyAmcCOOcUPLyIP0K8DrBmSRsJ+TmEGj/QO7A9K1CoB KicgAyHT5zpr3B4YH+sXkIh8E0fHV0wOY8fXdnL4m304OGEJy71MtKXgtbmdtKlh+bGGA7 EfGEuGYQfT4LzEfNNhxwamxwKcaG/o6z7sTtLttsE8UuQKDnENZuuWNDFrlzag== From: Romain Gantois Date: Tue, 16 Sep 2025 12:24:09 +0200 Subject: [PATCH 4/4] regulator: ltm8054: Support output current limit control 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: <20250916-ltm8054-driver-v1-4-fd4e781d33b9@bootlin.com> References: <20250916-ltm8054-driver-v1-0-fd4e781d33b9@bootlin.com> In-Reply-To: <20250916-ltm8054-driver-v1-0-fd4e781d33b9@bootlin.com> To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Romain Gantois X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 The LTM8054 supports setting a fixed output current limit using a sense resistor connected to a dedicated pin. This limit can then be lowered dynamically by varying the voltage level of the CTL pin. Support controlling the LTM8054's output current limit. Signed-off-by: Romain Gantois --- drivers/regulator/Kconfig | 1 + drivers/regulator/ltm8054-regulator.c | 109 ++++++++++++++++++++++++++++++= ++++ 2 files changed, 110 insertions(+) diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 15fb71193b67d0b2daa631b69778dde9323aedd2..22cf0e980351f21e3ef5b6611a3= 9cb48aeb503ea 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -579,6 +579,7 @@ config REGULATOR_LTC3676 =20 config REGULATOR_LTM8054 tristate "LTM8054 Buck-Boost voltage regulator" + depends on IIO help This driver provides support for the Linear Technology LTM8054 Buck-Boost micromodule regulator. The LTM8054 has an adjustable diff --git a/drivers/regulator/ltm8054-regulator.c b/drivers/regulator/ltm8= 054-regulator.c index e41bd95da55fb87912e2cdf70bae231133c25745..3b7b826e29cfb37415a7fb7cab6= 78cc33494d184 100644 --- a/drivers/regulator/ltm8054-regulator.c +++ b/drivers/regulator/ltm8054-regulator.c @@ -11,12 +11,27 @@ #include #include #include +#include +#include #include =20 +/* Threshold voltage between the Vout and Iout pins which triggers current + * limiting, in microvolts + */ +#define LTM8054_VOUT_IOUT_MAX 58000 + +#define LTM8054_MAX_CTL_V 1200000 +#define LTM8054_MIN_CTL_V 50000 + /* The LTM8054 regulates its FB pin to 1.2V */ #define LTM8054_FB_V 1200000 =20 struct ltm8054_priv { + struct iio_channel *ctl_dac; + + int min_uA; + int max_uA; + struct regulator_desc rdesc; }; =20 @@ -30,18 +45,105 @@ static int ltm8054_scale(unsigned int uV, u32 r1, u32 = r2) return uV + (unsigned int)tmp; } =20 +static int ltm8054_set_current_limit(struct regulator_dev *rdev, int min_u= A, int max_uA) +{ + struct ltm8054_priv *priv =3D rdev_get_drvdata(rdev); + u64 vdac_uV; + + min_uA =3D clamp_t(int, min_uA, priv->min_uA, priv->max_uA); + + /* adjusted current limit =3D Rsense current limit * CTL pin voltage / ma= x CTL pin voltage */ + vdac_uV =3D (u64)min_uA * LTM8054_MAX_CTL_V; + do_div(vdac_uV, priv->max_uA); + + dev_dbg(&rdev->dev, + "Setting current limit to %duA, CTL pin to %duV\n", min_uA, (int)vdac_uV= ); + + /* Standard IIO voltage unit is mV, scale accordingly. */ + return iio_write_channel_processed_scale(priv->ctl_dac, vdac_uV, 1000); +} + +static int ltm8054_get_current_limit(struct regulator_dev *rdev) +{ + struct ltm8054_priv *priv =3D rdev_get_drvdata(rdev); + int ret, vdac_uv; + u64 uA; + + ret =3D iio_read_channel_processed_scale(priv->ctl_dac, &vdac_uv, 1000); + if (ret < 0) { + dev_err(&rdev->dev, "failed to read CTL DAC voltage, err %d\n", ret); + return ret; + } + + uA =3D (u64)vdac_uv * priv->max_uA; + do_div(uA, LTM8054_MAX_CTL_V); + + return uA; +} + static const struct regulator_ops ltm8054_regulator_ops =3D { + .set_current_limit =3D ltm8054_set_current_limit, + .get_current_limit =3D ltm8054_get_current_limit, }; =20 +static int ltm8054_init_ctl_dac(struct platform_device *pdev, struct ltm80= 54_priv *priv) +{ + struct iio_channel *ctl_dac; + enum iio_chan_type type; + int ret; + + ctl_dac =3D devm_iio_channel_get(&pdev->dev, "ctl"); + if (IS_ERR(ctl_dac)) + return PTR_ERR(ctl_dac); + + ret =3D iio_get_channel_type(ctl_dac, &type); + if (ret < 0) + return ret; + + if (type !=3D IIO_VOLTAGE) + return -EINVAL; + + priv->ctl_dac =3D ctl_dac; + + return 0; +} + static int ltm8054_of_parse(struct device *dev, struct ltm8054_priv *priv, struct regulator_config *config) { struct device_node *np =3D dev->of_node; + u32 rsense; u32 r[2]; + u64 tmp; int ret; =20 config->of_node =3D np; =20 + ret =3D of_property_read_u32(np, "lltc,iout-rsense-micro-ohms", &rsense); + if (ret < 0) { + dev_err(dev, "failed to get sense resistor value\n"); + return ret; + } + + if (rsense =3D=3D 0) { + dev_err(dev, "invalid value zero for sense resistor\n"); + return -EINVAL; + } + + /* The maximum output current limit is the one set by the Rsense resistor= */ + tmp =3D 1000000 * (u64)LTM8054_VOUT_IOUT_MAX; + do_div(tmp, rsense); + priv->max_uA =3D tmp; + + /* Applying a voltage below LTM8054_MAX_CTL_V on the CTL pin reduces + * the output current limit. If this level drops below + * LTM8054_MIN_CTL_V the regulator stops switching + */ + + tmp =3D LTM8054_MIN_CTL_V * (u64)priv->max_uA; + do_div(tmp, (u32)LTM8054_MAX_CTL_V); + priv->min_uA =3D tmp; + ret =3D of_property_read_u32_array(np, "lltc,fb-voltage-divider", r, 2); if (ret) { dev_err(dev, "Failed to parse voltage divider\n"); @@ -52,6 +154,9 @@ static int ltm8054_of_parse(struct device *dev, struct l= tm8054_priv *priv, priv->rdesc.min_uV =3D priv->rdesc.fixed_uV; priv->rdesc.n_voltages =3D 1; =20 + dev_dbg(dev, "max_uA: %d min_uA: %d fixed_uV: %d\n", + priv->max_uA, priv->min_uA, priv->rdesc.fixed_uV); + config->init_data =3D of_get_regulator_init_data(dev, np, &priv->rdesc); @@ -92,6 +197,10 @@ static int ltm8054_probe(struct platform_device *pdev) if (ret) return dev_err_probe(&pdev->dev, ret, "failed to parse device tree\n"); =20 + ret =3D ltm8054_init_ctl_dac(pdev, priv); + if (ret) + return dev_err_probe(&pdev->dev, ret, "failed to initialize CTL DAC\n"); + rdev =3D devm_regulator_register(&pdev->dev, &priv->rdesc, &config); if (IS_ERR(rdev)) return dev_err_probe(&pdev->dev, PTR_ERR(rdev), "failed to register regu= lator\n"); --=20 2.51.0