* [PATCH v2 1/2] regulator: dt-bindings: add hi3798cv200 regulator
2026-10-09 21:43 [PATCH v2 0/2] regulator: support the HiSilicon STB PMOC voltage rails David Yang
@ 2026-10-09 21:43 ` David Yang
2026-10-09 21:52 ` sashiko-bot
2026-10-09 21:43 ` [PATCH v2 2/2] regulator: histb: add voltage regulator driver David Yang
1 sibling, 1 reply; 5+ messages in thread
From: David Yang @ 2026-10-09 21:43 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown
Cc: David Yang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-kernel, devicetree
The PMOC block of the HiSilicon STB SoCs (Hi3798cv200/mv100/mv200)
drives an external converter with a PWM signal. Add dt-binding doc.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
.../hisilicon,hi3798cv200-regulator.yaml | 48 +++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100644 Documentation/devicetree/bindings/regulator/hisilicon,hi3798cv200-regulator.yaml
diff --git a/Documentation/devicetree/bindings/regulator/hisilicon,hi3798cv200-regulator.yaml b/Documentation/devicetree/bindings/regulator/hisilicon,hi3798cv200-regulator.yaml
new file mode 100644
index 000000000000..812d94aca1f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/hisilicon,hi3798cv200-regulator.yaml
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/hisilicon,hi3798cv200-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: HiSilicon STB voltage regulator
+
+maintainers:
+ - David Yang <mmyangfl@gmail.com>
+
+description: |
+ HiSilicon STB SoCs (Hi3798cv200/mv100/mv200) provide PWM outputs in the PMOC
+ block which drive an external converter.
+
+ The voltage range depends on the board design: reference designs specify
+ 0.65 V to 1.15 V for the Hi3798cv200, and 0.7 V to 1.25 V for the Hi3798mv200;
+ a customized board has to figure out its own. The regulator itself has no
+ other source of calibration.
+
+properties:
+ compatible:
+ const: hisilicon,hi3798cv200-regulator
+
+ reg:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+ - regulator-min-microvolt
+ - regulator-max-microvolt
+
+allOf:
+ - $ref: regulator.yaml#
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ vddcpu: regulator@8a23018 {
+ compatible = "hisilicon,hi3798cv200-regulator";
+ reg = <0x8a23018 0x4>;
+ regulator-name = "vdd-cpu";
+ regulator-min-microvolt = <650000>;
+ regulator-max-microvolt = <1150000>;
+ regulator-always-on;
+ };
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v2 2/2] regulator: histb: add voltage regulator driver
2026-10-09 21:43 [PATCH v2 0/2] regulator: support the HiSilicon STB PMOC voltage rails David Yang
2026-10-09 21:43 ` [PATCH v2 1/2] regulator: dt-bindings: add hi3798cv200 regulator David Yang
@ 2026-10-09 21:43 ` David Yang
1 sibling, 0 replies; 5+ messages in thread
From: David Yang @ 2026-10-09 21:43 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown
Cc: David Yang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-kernel, devicetree
Add a driver for the voltage rails on HiSilicon STB SoCs which are
controlled by the PMOC block through a PWM signal, as described by the
hisilicon,hi3798cv200-regulator binding.
The name conventions follow those of pcie-histb.c.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
MAINTAINERS | 7 ++
drivers/regulator/Kconfig | 7 ++
drivers/regulator/Makefile | 1 +
drivers/regulator/histb-regulator.c | 162 ++++++++++++++++++++++++++++
4 files changed, 177 insertions(+)
create mode 100644 drivers/regulator/histb-regulator.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 65e8a4b5c90b..18b86d69ad07 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11910,6 +11910,13 @@ S: Maintained
F: Documentation/devicetree/bindings/mfd/hisilicon,hi6421-spmi-pmic.yaml
F: drivers/mfd/hi6421-spmi-pmic.c
+HISILICON STB VOLTAGE REGULATOR DRIVER
+M: David Yang <mmyangfl@gmail.com>
+L: linux-kernel@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/regulator/hisilicon,hi3798cv200-regulator.yaml
+F: drivers/regulator/histb-regulator.c
+
HISILICON TRUE RANDOM NUMBER GENERATOR V2 SUPPORT
M: Weili Qian <qianweili@huawei.com>
S: Maintained
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 89789ac7a786..a059c5b2bafc 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -487,6 +487,13 @@ config REGULATOR_HI6421V600
HiSilicon Hi6421v600 PMU / Codec IC.
This is used on Kirin 3670 boards, like HiKey 970.
+config REGULATOR_HISI_STB
+ tristate "HiSilicon STB voltage regulator support"
+ depends on ARCH_HISI || COMPILE_TEST
+ help
+ This driver provides support for the voltage regulators of the
+ HiSilicon STB SoCs, including Hi3798cv200, Hi3798mv100, Hi3798mv200.
+
config REGULATOR_ISL9305
tristate "Intersil ISL9305 regulator"
depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 5a764cec8df8..a2efd2bc3e0d 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -57,6 +57,7 @@ obj-$(CONFIG_REGULATOR_HI6421) += hi6421-regulator.o
obj-$(CONFIG_REGULATOR_HI6421V530) += hi6421v530-regulator.o
obj-$(CONFIG_REGULATOR_HI6421V600) += hi6421v600-regulator.o
obj-$(CONFIG_REGULATOR_HI655X) += hi655x-regulator.o
+obj-$(CONFIG_REGULATOR_HISI_STB) += histb-regulator.o
obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
obj-$(CONFIG_REGULATOR_ISL9305) += isl9305.o
obj-$(CONFIG_REGULATOR_FP9931) += fp9931.o
diff --git a/drivers/regulator/histb-regulator.c b/drivers/regulator/histb-regulator.c
new file mode 100644
index 000000000000..c6d8defc81da
--- /dev/null
+++ b/drivers/regulator/histb-regulator.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
+/*
+ * Regulator driver for the PWM controlled voltage regulators of HiSilicon STB
+ * SoCs
+ *
+ * May work on Hi3716mv410/420 Hi3796mv100/200 Hi3798cv200/mv100/mv200 but not
+ * thoroughly tested
+ *
+ * Copyright (c) 2026 David Yang
+ */
+
+#include <linux/bitfield.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+
+/*
+ * Duty cycle + 1 and period + 1 are counted in periods of the oscillator
+ * clock (usually 24 MHz), and a larger duty cycle means a lower output
+ * voltage.
+ */
+#define HISTB_DUTY GENMASK(31, 16)
+#define HISTB_PERIOD GENMASK(15, 0)
+
+/* 24 MHz / 240 = 100 kHz, arbitrarily chosen but should be enough */
+#define HISTB_PWM_PERIOD 240
+
+struct histb_regulator {
+ struct regulator_desc desc;
+ void __iomem *base;
+ int min_uV;
+ int max_uV;
+};
+
+static int histb_regulator_get_voltage(struct regulator_dev *rdev)
+{
+ struct histb_regulator *priv = rdev_get_drvdata(rdev);
+ u32 val;
+ u32 period;
+ u32 duty;
+ u64 uV;
+
+ val = readl_relaxed(priv->base);
+ period = FIELD_GET(HISTB_PERIOD, val);
+ duty = FIELD_GET(HISTB_DUTY, val);
+
+ /* an empty counter range leaves the output high */
+ if (duty <= 1 || period <= 1)
+ return priv->max_uV;
+
+ duty--;
+ period--;
+ if (duty >= period)
+ return priv->min_uV;
+
+ uV = (u64)(priv->max_uV - priv->min_uV) * duty;
+
+ return priv->max_uV - DIV_ROUND_CLOSEST_ULL(uV, period);
+}
+
+static int
+histb_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
+ unsigned int *selector)
+{
+ struct histb_regulator *priv = rdev_get_drvdata(rdev);
+ unsigned int duty;
+ u32 val;
+
+ if (min_uV >= priv->max_uV)
+ duty = 0;
+ else if (min_uV <= priv->min_uV)
+ duty = HISTB_PWM_PERIOD;
+ else
+ /* rounding down keeps the output at or above the request */
+ duty = DIV_ROUND_DOWN_ULL((u64)(priv->max_uV - min_uV) *
+ HISTB_PWM_PERIOD,
+ priv->max_uV - priv->min_uV);
+
+ val = FIELD_PREP(HISTB_DUTY, duty + 1) |
+ FIELD_PREP(HISTB_PERIOD, HISTB_PWM_PERIOD + 1);
+ writel_relaxed(val, priv->base);
+
+ return 0;
+}
+
+static const struct regulator_ops histb_regulator_ops = {
+ .get_voltage = histb_regulator_get_voltage,
+ .set_voltage = histb_regulator_set_voltage,
+};
+
+static int histb_regulator_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct histb_regulator *priv;
+ struct regulator_init_data *init_data;
+ struct regulator_config config = {};
+ struct regulator_dev *rdev;
+
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ init_data = of_get_regulator_init_data(dev, dev->of_node, &priv->desc);
+ if (!init_data)
+ return -ENOMEM;
+
+ priv->min_uV = init_data->constraints.min_uV;
+ priv->max_uV = init_data->constraints.max_uV;
+ if (priv->min_uV <= 0 || priv->max_uV <= priv->min_uV) {
+ dev_err(dev, "invalid voltage range (%d..%d uV)\n",
+ priv->min_uV, priv->max_uV);
+ return -EINVAL;
+ }
+
+ priv->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(priv->base))
+ return PTR_ERR(priv->base);
+
+ priv->desc.name = dev_name(dev);
+ priv->desc.type = REGULATOR_VOLTAGE;
+ priv->desc.ops = &histb_regulator_ops;
+ priv->desc.owner = THIS_MODULE;
+ priv->desc.continuous_voltage_range = true;
+
+ config.dev = dev;
+ config.init_data = init_data;
+ config.driver_data = priv;
+ config.of_node = dev->of_node;
+
+ rdev = devm_regulator_register(dev, &priv->desc, &config);
+ if (IS_ERR(rdev))
+ return dev_err_probe(dev, PTR_ERR(rdev),
+ "failed to register %s\n",
+ priv->desc.name);
+
+ return 0;
+}
+
+static const struct of_device_id histb_regulator_of_match[] = {
+ { .compatible = "hisilicon,hi3798cv200-regulator" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, histb_regulator_of_match);
+
+static struct platform_driver histb_regulator_driver = {
+ .probe = histb_regulator_probe,
+ .driver = {
+ .name = "hi3798cv200-regulator",
+ .of_match_table = histb_regulator_of_match,
+ },
+};
+module_platform_driver(histb_regulator_driver);
+
+MODULE_DESCRIPTION("HiSilicon STB regulator driver");
+MODULE_AUTHOR("David Yang <mmyangfl@gmail.com>");
+MODULE_LICENSE("Dual MIT/GPL");
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread