From nobody Thu Oct 2 02:15:05 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 AC44B26E6FE for ; Thu, 25 Sep 2025 12:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758803883; cv=none; b=GKgw1TNZmULgMF2zD5ACINWbwkNRtqBY+H4yyeXXDaVOwvSp8vYqfB0FQeZmyzWpLNGq2uLwF6Zf33ycTbWdaPpdwhfKdtfBa2cXvL3XkxglElOlYBGbirSOgtqIJq2GP6T1dOmn34jxZPNx4QPQoDm+/OZG7g6fhhMXSYIkchk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758803883; c=relaxed/simple; bh=cE6dqP10Uu7Ap+7dTimu+BxM1SJYWWd/P7RXknWJ/Ao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m6TACExJWfReQk+uaeVyZjK6jKRmDlpyg7ei0K3wOL3K6eAEhgYy1Db99EJdSZlASV7y8lhWbNOoCX+Fti7lQCRsohfW9BdURiFMvS9UeyENcyTp4FDlH+Ey7vqVFE3+R0itkZWWH9kMUYpDsPB0bf3LnN2GhC0i4pH9hvhKPOo= 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=tajFAysD; arc=none smtp.client-ip=185.171.202.116 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="tajFAysD" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id F202DC011FA; Thu, 25 Sep 2025 12:37:42 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 40B526062C; Thu, 25 Sep 2025 12:38:00 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 46B97102F1895; Thu, 25 Sep 2025 14:37:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1758803879; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=DBmZYj9uOOiozLigWRqEkHlxIev9s38O1X01yQhnqPo=; b=tajFAysDfCgDA/mszBL8ZF2V0D7e+a1m4dYYsSJ1FVpFIiZbTMRPD9+VyCUyXTho5VrMem LumFryZdWz7lrpm2VFAG8tE55IjuHF8YyWtMEtyY8FAGmOOu9nzotDfu0bRTtQp59sVzTj /7aPegnI9Xel32kRu6XXtDIPRaj8tOL+H/eVk8sV75xzY/pBCpnn0yUmFF2aD1IwMffyKV 7pVhjSOcTbrINdxYLgs8jsW45ghqUHqLYD1fg8rvFo0+m1FmREtFfua1YGW6QWOpukaObw AEXBv0k5gUk76QV7cCh9t7aGBEZwo1ki6zj971hi4BzFVkjuDjiezK1qPTP2vQ== From: Romain Gantois Date: Thu, 25 Sep 2025 14:37:37 +0200 Subject: [PATCH v2 5/5] 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: <20250925-ltm8054-driver-v2-5-bb61a401a0dc@bootlin.com> References: <20250925-ltm8054-driver-v2-0-bb61a401a0dc@bootlin.com> In-Reply-To: <20250925-ltm8054-driver-v2-0-bb61a401a0dc@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: Hans de Goede , 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 | 113 ++++++++++++++++++++++++++++++= +++- 2 files changed, 112 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c48b2af350974b3715a1ecf05dec656a92268294..e9ee6ed9fe3587c542223a6d6be= 78412e96797ee 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 Analog Devices 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 bc8cf98b5a3b5663481d148330de70a8165e5981..172ec32c5a9517c6fb38ded8095= ffc8e1acf55f0 100644 --- a/drivers/regulator/ltm8054-regulator.c +++ b/drivers/regulator/ltm8054-regulator.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -26,10 +28,25 @@ #include #include =20 +#include + /* The LTM8054 regulates its FB pin to 1.2V */ #define LTM8054_FB_uV 1200000 =20 +/* Threshold voltage between the Vout and Iout pins which triggers current + * limiting. + */ +#define LTM8054_VOUT_IOUT_MAX_uV 58000 + +#define LTM8054_MAX_CTL_uV 1200000 +#define LTM8054_MIN_CTL_uV 50000 + struct ltm8054_priv { + struct iio_channel *ctl_dac; + + int min_uA; + int max_uA; + struct regulator_desc rdesc; }; =20 @@ -43,18 +60,103 @@ static int ltm8054_scale(unsigned int uV, u32 r1, u32 = r2) return uV + tmp; } =20 -static const struct regulator_ops ltm8054_regulator_ops =3D { }; +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_uV; + 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_uV); + + 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, +}; + +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) + return ret; + + if (type !=3D IIO_VOLTAGE) + return -EINVAL; + + priv->ctl_dac =3D ctl_dac; + + return 0; +} =20 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 device_property_read_u32_array(dev, "lltc,fb-voltage-divider", r,= ARRAY_SIZE(r)); + ret =3D device_property_read_u32(dev, "adi,iout-rsense-micro-ohms", &rsen= se); + if (ret) + return ret; + + if (rsense =3D=3D 0) + return -EINVAL; + + /* The maximum output current limit is the one set by the Rsense resistor= */ + tmp =3D (u64)LTM8054_VOUT_IOUT_MAX_uV * MICRO; + do_div(tmp, rsense); + priv->max_uA =3D tmp; + + /* + * Applying a voltage below LTM8054_MAX_CTL_uV on the CTL pin reduces + * the output current limit. If this level drops below + * LTM8054_MIN_CTL_uV the regulator stops switching. + */ + + tmp =3D (u64)priv->max_uA * LTM8054_MIN_CTL_uV; + do_div(tmp, LTM8054_MAX_CTL_uV); + priv->min_uA =3D tmp; + + ret =3D device_property_read_u32_array(dev, "lltc,fb-voltage-divider", r,= 2); if (ret) return ret; =20 @@ -62,6 +164,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); @@ -99,6 +204,10 @@ static int ltm8054_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "failed to parse device tree\n"); =20 + ret =3D ltm8054_init_ctl_dac(pdev, priv); + if (ret) + return dev_err_probe(dev, ret, "failed to initialize CTL DAC\n"); + rdev =3D devm_regulator_register(dev, &priv->rdesc, &config); if (IS_ERR(rdev)) return dev_err_probe(dev, PTR_ERR(rdev), "failed to register regulator\n= "); --=20 2.51.0