public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Aleksandrs Vinarskis <alex.vinarskis@gmail.com>
To: Aleksandrs Vinarskis <alex.vinarskis@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	jens.glathe@oldschoolsolutions.biz,
	konrad.dybcio@oss.qualcomm.com
Subject: [RFC PATCH v1 2/2] regulator: Introduce dummy regulator consumer driver
Date: Sat,  7 Jun 2025 23:25:39 +0200	[thread overview]
Message-ID: <20250607212654.126412-3-alex.vinarskis@gmail.com> (raw)
In-Reply-To: <20250607212654.126412-1-alex.vinarskis@gmail.com>

Introduce a very simple dummy consumer driver. Designed to consume
a single regulator 'vdd', the driver will power-on on probe and PM
suspend (if supported), power-off on remove and PM resume (if enabled).

Signed-off-by: Aleksandrs Vinarskis <alex.vinarskis@gmail.com>
---
 drivers/regulator/Kconfig          |  9 ++++
 drivers/regulator/Makefile         |  1 +
 drivers/regulator/dummy-consumer.c | 85 ++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+)
 create mode 100644 drivers/regulator/dummy-consumer.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 6d8988387da4..eb907ecbcbe8 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -30,6 +30,15 @@ config REGULATOR_DEBUG
 	help
 	  Say yes here to enable debugging support.
 
+config REGULATOR_DUMMY_CONSUMER
+	tristate "Dummy regulator consumer support"
+	help
+	  This driver provides a dummy consumer for a device behind an
+	  USB phy (for example) that needs power supplies, but has no
+	  own device node since it's enumerated by USB.
+
+	  If unsure, say no.
+
 config REGULATOR_FIXED_VOLTAGE
 	tristate "Fixed voltage regulator support"
 	help
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index c0bc7a0f4e67..e1d1029fd87a 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -5,6 +5,7 @@
 
 
 obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o devres.o irq_helpers.o
+obj-$(CONFIG_REGULATOR_DUMMY_CONSUMER) += dummy-consumer.o
 obj-$(CONFIG_REGULATOR_NETLINK_EVENTS) += event.o
 obj-$(CONFIG_OF) += of_regulator.o
 obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
diff --git a/drivers/regulator/dummy-consumer.c b/drivers/regulator/dummy-consumer.c
new file mode 100644
index 000000000000..813c7abce660
--- /dev/null
+++ b/drivers/regulator/dummy-consumer.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025, Aleksandrs Vinarskis
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/regulator/consumer.h>
+
+struct dummy_consumer_data {
+	struct regulator *regulator;
+};
+
+static int dummy_consumer_probe(struct platform_device *pdev)
+{
+	struct dummy_consumer_data *data;
+	int ret;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->regulator = devm_regulator_get(&pdev->dev, "vdd");
+	if (IS_ERR(data->regulator)) {
+		dev_err(&pdev->dev, "Failed to get regulator\n");
+		return PTR_ERR(data->regulator);
+	}
+
+	ret = regulator_enable(data->regulator);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to enable regulator: %d\n", ret);
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, data);
+
+	dev_dbg(&pdev->dev, "Dummy regulator consumer initialized\n");
+	return 0;
+}
+
+static void dummy_consumer_remove(struct platform_device *pdev)
+{
+	struct dummy_consumer_data *data = platform_get_drvdata(pdev);
+
+	regulator_disable(data->regulator);
+}
+
+static int dummy_consumer_resume(struct device *dev)
+{
+	struct dummy_consumer_data *data = dev_get_drvdata(dev);
+
+	return regulator_enable(data->regulator);
+}
+
+static int dummy_consumer_suspend(struct device *dev)
+{
+	struct dummy_consumer_data *data = dev_get_drvdata(dev);
+
+	return regulator_disable(data->regulator);
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(dummy_consumer_pm, dummy_consumer_suspend, dummy_consumer_resume);
+
+static const struct of_device_id dummy_consumer_of_match[] = {
+	{ .compatible = "regulator-dummy-consumer", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, dummy_consumer_of_match);
+
+static struct platform_driver dummy_consumer_driver = {
+	.driver = {
+		.name = "regulator-dummy-consumer",
+		.of_match_table = dummy_consumer_of_match,
+		.pm = pm_sleep_ptr(&dummy_consumer_pm),
+	},
+	.probe = dummy_consumer_probe,
+	.remove = dummy_consumer_remove,
+};
+module_platform_driver(dummy_consumer_driver);
+
+MODULE_AUTHOR("Aleksandrs Vinarskis <alex.vinarskis@gmail.com>");
+MODULE_DESCRIPTION("Dummy regulator consumer driver");
+MODULE_LICENSE("GPL");
-- 
2.45.2


  parent reply	other threads:[~2025-06-07 21:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-07 21:25 [RFC PATCH v1 0/2] Introduce dummy regulator consumer Aleksandrs Vinarskis
2025-06-07 21:25 ` [RFC PATCH v1 1/2] regulator: Add dummy regulator consumer binding Aleksandrs Vinarskis
2025-06-08 22:33   ` Rob Herring (Arm)
2025-06-07 21:25 ` Aleksandrs Vinarskis [this message]
2025-06-08 22:33 ` [RFC PATCH v1 0/2] Introduce dummy regulator consumer Mark Brown
2025-06-09 20:32   ` Aleksandrs Vinarskis
2025-06-09 20:50     ` Mark Brown
2025-06-09 21:15       ` Aleksandrs Vinarskis
2025-06-10 13:51         ` Mark Brown
2025-06-28  6:14           ` Jens Glathe
2025-06-28 14:35             ` Konrad Dybcio
2025-06-30 13:11               ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250607212654.126412-3-alex.vinarskis@gmail.com \
    --to=alex.vinarskis@gmail.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jens.glathe@oldschoolsolutions.biz \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox