From nobody Mon Apr 6 12:17:54 2026 Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) (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 4FE193C9EDF; Thu, 19 Mar 2026 11:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.121.34.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773919511; cv=none; b=NDkUgx02zJZEghCJQ8i/TVywoay4fVdtSm3rSQ3LDTdbLj91+quFEhUbOKdITQSkoE6wfQofz4cGwRSvALNKkmvVoPB9Yww70S6LsTlT5YACnxyJvKzonrE7396hQnRiZhxc/mOujseMh62gbu2MBTiUBbuK2ddBQ7LahEzACf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773919511; c=relaxed/simple; bh=Txc2V4ivMkzNQ7yHeSqWPSp21hBWm6Wl+B0+7l4VcZU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pNKVhNRuGo1RbetwJqO2yiRPr0mmqd8163SY5ZQAWmGz9aQaH/8GtFllUA9ynMPdSB1LJGMVORcuQD5ovG0YMKvT2e16l52al+1kkfz2DtFXxK6JASWie6V1mGJL44zxJYcQGU6dpchYja4PH7lki4eZf0lMjFA1DoLXxNuwrSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; arc=none smtp.client-ip=92.121.34.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id C0257202A99; Thu, 19 Mar 2026 12:25:00 +0100 (CET) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 86D25202AA6; Thu, 19 Mar 2026 12:25:00 +0100 (CET) Received: from lsv03900.swis.in-blr01.nxp.com (lsv03900.swis.in-blr01.nxp.com [10.12.177.15]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 32BEB18000A0; Thu, 19 Mar 2026 19:24:59 +0800 (+08) From: Lakshay Piplani To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org, alexandre.belloni@bootlin.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, broonie@kernel.org, lee@kernel.org, Frank.Li@nxp.com, lgirdwood@gmail.com Cc: vikash.bansal@nxp.com, priyanka.jain@nxp.com, aman.kumarpandey@nxp.com, lakshay.piplani@nxp.com, Frank Li Subject: [PATCH v7 5/7] regulator: p3h2x4x: Add driver for on-die regulators in NXP P3H2x4x i3c hub Date: Thu, 19 Mar 2026 16:54:39 +0530 Message-Id: <20260319112441.3888957-6-lakshay.piplani@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260319112441.3888957-1-lakshay.piplani@nxp.com> References: <20260319112441.3888957-1-lakshay.piplani@nxp.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: ClamAV using ClamSMTP Content-Type: text/plain; charset="utf-8" From: Aman Kumar Pandey The NXP P3H2x4x family integrates on-die regulators alongside I3C hub functionality. This driver registers the regulators using the MFD framework and exposes them via the regulator subsystem. Signed-off-by: Aman Kumar Pandey Signed-off-by: Vikash Bansal Reviewed-by: Frank Li --- Changes in v7: - No change, added Reviewed-By tag Changes in v6: - Use DEFINE_LOCK_GUARD_1 for reg lock/unlock=20 Changes in v5: - Updated dev_err_probe() for regmap_init failure. - Updated module description Changes in v4: - Split the driver into three separate patches (mfd, regulator and I3C hub) - Introduced driver for on-die regulators in NXP P3H2x4x I3C hub --- --- MAINTAINERS | 1 + drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/p3h2840_i3c_hub_regulator.c | 219 ++++++++++++++++++ 4 files changed, 231 insertions(+) create mode 100644 drivers/regulator/p3h2840_i3c_hub_regulator.c diff --git a/MAINTAINERS b/MAINTAINERS index 4f67fe64c833..7d142a1a8fb7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19102,6 +19102,7 @@ L: linux-i3c-owner@lists.infradead.org S: Maintained F: Documentation/devicetree/bindings/i3c/nxp,p3h2840.yaml F: drivers/mfd/p3h2840.c +F: drivers/regulator/p3h2840_i3c_hub_regulator.c F: include/linux/mfd/p3h2840.h =20 NXP PF5300/PF5301/PF5302 PMIC REGULATOR DEVICE DRIVER diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index d10b6f9243d5..290f441b7324 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1019,6 +1019,16 @@ config REGULATOR_MTK_DVFSRC of Mediatek. It allows for voting on regulator state between multiple users. =20 +config REGULATOR_P3H2X4X + tristate "P3H2X4X regulator support" + depends on MFD_P3H2X4X + help + This driver provides support for the voltage regulators of the + P3H244x/P3H284x multi-function I3C Hub device. + + Say M here if you want to include support for this regulator as + a module. The module will be named "p3h2840_i3c_hub_regulator". + config REGULATOR_PALMAS tristate "TI Palmas PMIC Regulators" depends on MFD_PALMAS diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 35639f3115fd..46f586ccde63 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -128,6 +128,7 @@ obj-$(CONFIG_REGULATOR_QCOM_RPMH) +=3D qcom-rpmh-regula= tor.o obj-$(CONFIG_REGULATOR_QCOM_SMD_RPM) +=3D qcom_smd-regulator.o obj-$(CONFIG_REGULATOR_QCOM_SPMI) +=3D qcom_spmi-regulator.o obj-$(CONFIG_REGULATOR_QCOM_USB_VBUS) +=3D qcom_usb_vbus-regulator.o +obj-$(CONFIG_REGULATOR_P3H2X4X) +=3D p3h2840_i3c_hub_regulator.o obj-$(CONFIG_REGULATOR_PALMAS) +=3D palmas-regulator.o obj-$(CONFIG_REGULATOR_PCA9450) +=3D pca9450-regulator.o obj-$(CONFIG_REGULATOR_PF0900) +=3D pf0900-regulator.o diff --git a/drivers/regulator/p3h2840_i3c_hub_regulator.c b/drivers/regula= tor/p3h2840_i3c_hub_regulator.c new file mode 100644 index 000000000000..b2d31ecd5f19 --- /dev/null +++ b/drivers/regulator/p3h2840_i3c_hub_regulator.c @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2025 NXP + * This P3H2x4x driver file contain functions for enable/disable regulator= and voltage set/get. + */ +#include +#include +#include +#include +#include +#include +#include + +#define P3H2x4x_LDO_AND_PULLUP_CONF 0x19 +#define P3H2x4x_LDO_ENABLE_DISABLE_MASK GENMASK(3, 0) +#define P3H2x4x_CP0_EN_LDO BIT(0) +#define P3H2x4x_CP1_EN_LDO BIT(1) +#define P3H2x4x_TP0145_EN_LDO BIT(2) +#define P3H2x4x_TP2367_EN_LDO BIT(3) + +#define P3H2x4x_NET_OPER_MODE_CONF 0x15 +#define P3H2x4x_VCCIO_LDO_CONF 0x16 +#define P3H2x4x_CP0_VCCIO_LDO_VOLTAGE_MASK GENMASK(1, 0) +#define P3H2x4x_CP0_VCCIO_LDO_VOLTAGE(x) \ + FIELD_PREP(P3H2x4x_CP0_VCCIO_LDO_VOLTAGE_MASK, x) +#define P3H2x4x_CP1_VCCIO_LDO_VOLTAGE_MASK GENMASK(3, 2) +#define P3H2x4x_CP1_VCCIO_LDO_VOLTAGE(x) \ + FIELD_PREP(P3H2x4x_CP1_VCCIO_LDO_VOLTAGE_MASK, x) +#define P3H2x4x_TP0145_VCCIO_LDO_VOLTAGE_MASK GENMASK(5, 4) +#define P3H2x4x_TP0145_VCCIO_LDO_VOLTAGE(x) \ + FIELD_PREP(P3H2x4x_TP0145_VCCIO_LDO_VOLTAGE_MASK, x) +#define P3H2x4x_TP2367_VCCIO_LDO_VOLTAGE_MASK GENMASK(7, 6) +#define P3H2x4x_TP2367_VCCIO_LDO_VOLTAGE(x) \ + FIELD_PREP(P3H2x4x_TP2367_VCCIO_LDO_VOLTAGE_MASK, x) +#define P3H2x4x_LDO_COUNT 4 + +struct p3h2x4x_regulator_dev { + struct regulator_dev *rp3h2x4x_dev[P3H2x4x_LDO_COUNT]; + struct regmap *regmap; +}; + +struct p3h2x4x_reg_state { + unsigned int orig; + bool restore; +}; + +static void p3h2x4x_reg_guard_enter(struct regulator_dev *rdev, + struct p3h2x4x_reg_state *state) +{ + state->restore =3D false; + + if (regmap_read(rdev->regmap, + P3H2x4x_DEV_REG_PROTECTION_CODE, + &state->orig)) + return; + + if (state->orig !=3D P3H2x4x_REGISTERS_UNLOCK_CODE) { + regmap_write(rdev->regmap, + P3H2x4x_DEV_REG_PROTECTION_CODE, + P3H2x4x_REGISTERS_UNLOCK_CODE); + state->restore =3D true; + } +} + +static void p3h2x4x_reg_guard_exit(struct regulator_dev *rdev, + struct p3h2x4x_reg_state *state) +{ + if (state->restore) + regmap_write(rdev->regmap, + P3H2x4x_DEV_REG_PROTECTION_CODE, + state->orig); +} + +DEFINE_LOCK_GUARD_1(p3h2x4x_reg, struct regulator_dev, + p3h2x4x_reg_guard_enter(_T->lock, &_T->state), + p3h2x4x_reg_guard_exit(_T->lock, &_T->state), + struct p3h2x4x_reg_state state); + +static int p3h2x4x_regulator_enable(struct regulator_dev *rdev) +{ + guard(p3h2x4x_reg)(rdev); + return regulator_enable_regmap(rdev); +} + +static int p3h2x4x_regulator_disable(struct regulator_dev *rdev) +{ + guard(p3h2x4x_reg)(rdev); + return regulator_disable_regmap(rdev); +} + +static int p3h2x4x_regulator_set_voltage_sel(struct regulator_dev *rdev, + unsigned int sel) +{ + guard(p3h2x4x_reg)(rdev); + return regulator_set_voltage_sel_regmap(rdev, sel); +} + +static const struct regulator_ops p3h2x4x_ldo_ops =3D { + .list_voltage =3D regulator_list_voltage_table, + .map_voltage =3D regulator_map_voltage_iterate, + .set_voltage_sel =3D p3h2x4x_regulator_set_voltage_sel, + .get_voltage_sel =3D regulator_get_voltage_sel_regmap, + .enable =3D p3h2x4x_regulator_enable, + .disable =3D p3h2x4x_regulator_disable, + .is_enabled =3D regulator_is_enabled_regmap, +}; + +static const unsigned int p3h2x4x_voltage_table[] =3D { + 1000000, + 1100000, + 1200000, + 1800000, +}; + +static struct regulator_desc p3h2x4x_regulators[] =3D { + { + .name =3D "ldo-cp0", + .of_match =3D of_match_ptr("ldo-cp0"), + .regulators_node =3D of_match_ptr("regulators"), + .volt_table =3D p3h2x4x_voltage_table, + .n_voltages =3D ARRAY_SIZE(p3h2x4x_voltage_table), + .ops =3D &p3h2x4x_ldo_ops, + .type =3D REGULATOR_VOLTAGE, + .owner =3D THIS_MODULE, + .enable_reg =3D P3H2x4x_LDO_AND_PULLUP_CONF, + .enable_mask =3D P3H2x4x_CP0_EN_LDO, + .vsel_reg =3D P3H2x4x_VCCIO_LDO_CONF, + .vsel_mask =3D P3H2x4x_CP0_VCCIO_LDO_VOLTAGE_MASK, + }, + { + .name =3D "ldo-cp1", + .of_match =3D of_match_ptr("ldo-cp1"), + .regulators_node =3D of_match_ptr("regulators"), + .volt_table =3D p3h2x4x_voltage_table, + .n_voltages =3D ARRAY_SIZE(p3h2x4x_voltage_table), + .ops =3D &p3h2x4x_ldo_ops, + .type =3D REGULATOR_VOLTAGE, + .owner =3D THIS_MODULE, + .enable_reg =3D P3H2x4x_LDO_AND_PULLUP_CONF, + .enable_mask =3D P3H2x4x_CP1_EN_LDO, + .vsel_reg =3D P3H2x4x_VCCIO_LDO_CONF, + .vsel_mask =3D P3H2x4x_CP1_VCCIO_LDO_VOLTAGE_MASK, + }, + { + .name =3D "ldo-tpg0", + .of_match =3D of_match_ptr("ldo-tpg0"), + .regulators_node =3D of_match_ptr("regulators"), + .volt_table =3D p3h2x4x_voltage_table, + .n_voltages =3D ARRAY_SIZE(p3h2x4x_voltage_table), + .ops =3D &p3h2x4x_ldo_ops, + .type =3D REGULATOR_VOLTAGE, + .owner =3D THIS_MODULE, + .enable_reg =3D P3H2x4x_LDO_AND_PULLUP_CONF, + .enable_mask =3D P3H2x4x_TP0145_EN_LDO, + .vsel_reg =3D P3H2x4x_VCCIO_LDO_CONF, + .vsel_mask =3D P3H2x4x_TP0145_VCCIO_LDO_VOLTAGE_MASK, + }, + { + .name =3D "ldo-tpg1", + .of_match =3D of_match_ptr("ldo-tpg1"), + .regulators_node =3D of_match_ptr("regulators"), + .volt_table =3D p3h2x4x_voltage_table, + .n_voltages =3D ARRAY_SIZE(p3h2x4x_voltage_table), + .ops =3D &p3h2x4x_ldo_ops, + .type =3D REGULATOR_VOLTAGE, + .owner =3D THIS_MODULE, + .enable_reg =3D P3H2x4x_LDO_AND_PULLUP_CONF, + .enable_mask =3D P3H2x4x_TP2367_EN_LDO, + .vsel_reg =3D P3H2x4x_VCCIO_LDO_CONF, + .vsel_mask =3D P3H2x4x_TP2367_VCCIO_LDO_VOLTAGE_MASK, + }, +}; + +static int p3h2x4x_regulator_probe(struct platform_device *pdev) +{ + struct p3h2x4x_dev *p3h2x4x =3D dev_get_drvdata(pdev->dev.parent); + struct p3h2x4x_regulator_dev *p3h2x4x_regulator; + struct regulator_config rcfg =3D { }; + struct device *dev =3D &pdev->dev; + struct regulator_dev *rdev; + int i; + + p3h2x4x_regulator =3D devm_kzalloc(dev, sizeof(*p3h2x4x_regulator), GFP_K= ERNEL); + if (!p3h2x4x_regulator) + return -ENOMEM; + + platform_set_drvdata(pdev, p3h2x4x_regulator); + + p3h2x4x_regulator->regmap =3D p3h2x4x->regmap; + device_set_of_node_from_dev(dev, dev->parent); + + rcfg.dev =3D dev; + rcfg.dev->of_node =3D dev->of_node; + rcfg.regmap =3D p3h2x4x_regulator->regmap; + rcfg.driver_data =3D p3h2x4x_regulator; + + for (i =3D 0; i < ARRAY_SIZE(p3h2x4x_regulators); i++) { + rdev =3D devm_regulator_register(&pdev->dev, &p3h2x4x_regulators[i], &rc= fg); + if (IS_ERR(rdev)) + return dev_err_probe(dev, PTR_ERR(rdev), "Failed to register %s\n", + p3h2x4x_regulators[i].name); + p3h2x4x_regulator->rp3h2x4x_dev[i] =3D rdev; + } + return 0; +} + +static struct platform_driver p3h2x4x_regulator_driver =3D { + .driver =3D { + .name =3D "p3h2x4x-regulator", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, + .probe =3D p3h2x4x_regulator_probe, +}; +module_platform_driver(p3h2x4x_regulator_driver); + +MODULE_AUTHOR("Aman Kumar Pandey "); +MODULE_AUTHOR("Vikash Bansal "); +MODULE_DESCRIPTION("P3H2x4x I3C HUB Regulator driver"); +MODULE_LICENSE("GPL"); --=20 2.25.1