lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220609150851.23084-3-max.oss.09@gmail.com>
Date:   Thu,  9 Jun 2022 17:08:48 +0200
From:   Max Krummenacher <max.oss.09@...il.com>
To:     max.krummenacher@...adex.com
Cc:     Ulf Hansson <ulf.hansson@...aro.org>, linux-pm@...r.kernel.org,
        Francesco Dolcini <francesco.dolcini@...adex.com>,
        Mark Brown <broonie@...nel.org>,
        "Rafael J . Wysocki" <rafael@...nel.org>,
        Kevin Hilman <khilman@...nel.org>, linux-kernel@...r.kernel.org
Subject: [PATCH v1 2/5] pm: add regulator power domain controller

From: Max Krummenacher <max.krummenacher@...adex.com>

Acts as a power domain controller which switches its domain power by
enabling/disabling a regulator.

Signed-off-by: Max Krummenacher <max.krummenacher@...adex.com>
---

 drivers/power/Kconfig                |   1 +
 drivers/power/Makefile               |   5 +-
 drivers/power/domain/Kconfig         |   7 ++
 drivers/power/domain/Makefile        |   2 +
 drivers/power/domain/regulator-pdc.c | 112 +++++++++++++++++++++++++++
 5 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100644 drivers/power/domain/Kconfig
 create mode 100644 drivers/power/domain/Makefile
 create mode 100644 drivers/power/domain/regulator-pdc.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 696bf77a7042..e8eebee629d5 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
+source "drivers/power/domain/Kconfig"
 source "drivers/power/reset/Kconfig"
 source "drivers/power/supply/Kconfig"
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index effbf0377f32..4323a8c8c328 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-$(CONFIG_POWER_RESET)	+= reset/
-obj-$(CONFIG_POWER_SUPPLY)	+= supply/
+obj-$(CONFIG_PM_GENERIC_DOMAINS)	+= domain/
+obj-$(CONFIG_POWER_RESET)		+= reset/
+obj-$(CONFIG_POWER_SUPPLY)		+= supply/
diff --git a/drivers/power/domain/Kconfig b/drivers/power/domain/Kconfig
new file mode 100644
index 000000000000..74c50baf2df0
--- /dev/null
+++ b/drivers/power/domain/Kconfig
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config POWER_DOMAIN_REGULATOR
+	bool "A power domain controller using a regulator for power control"
+	help
+	  Say Y here to enable a power domain controller which uses a regulator
+	  to control its power domain.
diff --git a/drivers/power/domain/Makefile b/drivers/power/domain/Makefile
new file mode 100644
index 000000000000..13b3378fb11f
--- /dev/null
+++ b/drivers/power/domain/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_POWER_DOMAIN_REGULATOR)	+= regulator-pdc.o
diff --git a/drivers/power/domain/regulator-pdc.c b/drivers/power/domain/regulator-pdc.c
new file mode 100644
index 000000000000..e03cfe901d70
--- /dev/null
+++ b/drivers/power/domain/regulator-pdc.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * A power domain controller which uses a regulator to control its power domain.
+ *
+ * Copyright 2022 Toradex
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <linux/regulator/consumer.h>
+
+struct reg_pd {
+	struct device *dev;
+	struct generic_pm_domain pd;
+	struct regulator *supply;
+};
+
+static int reg_pd_power_off(struct generic_pm_domain *domain)
+{
+	struct reg_pd *pd = container_of(domain, struct reg_pd, pd);
+
+	return regulator_disable(pd->supply);
+}
+
+static int reg_pd_power_on(struct generic_pm_domain *domain)
+{
+	struct reg_pd *pd = container_of(domain, struct reg_pd, pd);
+
+	return regulator_enable(pd->supply);
+}
+
+static const struct of_device_id reg_pd_of_match[] = {
+	{
+		.compatible = "regulator-pm-pd",
+	},
+	{ },
+};
+
+static int reg_pd_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct of_phandle_args child, parent;
+	struct reg_pd *pd;
+	const char *name;
+	int ret;
+
+	pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
+	if (!pd) {
+		of_node_put(np);
+		return -ENOMEM;
+	}
+	pd->dev = dev;
+
+	if (of_property_read_string(np, "label", &name) < 0)
+		name = kbasename(np->full_name);
+	pd->pd.name = kstrdup_const(name, GFP_KERNEL);
+	if (!pd->pd.name)
+		return -ENOMEM;
+
+	pd->supply = devm_regulator_get(dev, "power");
+	if (IS_ERR(pd->supply))
+		return dev_err_probe(dev, PTR_ERR(pd->supply),
+				     "failed to get regulator\n");
+
+	pd->pd.power_off = reg_pd_power_off;
+	pd->pd.power_on = reg_pd_power_on;
+
+	ret = pm_genpd_init(&pd->pd, NULL, true);
+	if (ret)
+		goto err_out;
+	ret = of_genpd_add_provider_simple(np, &pd->pd);
+	if (ret)
+		goto err_out;
+
+	if (of_parse_phandle_with_args(np, "power-domains",
+				      "#power-domain-cells", 0, &parent) == 0) {
+		child.np = np;
+		child.args_count = 0;
+
+		if (of_genpd_add_subdomain(&parent, &child))
+			pr_warn("%pOF failed to add subdomain: %pOF\n",
+				parent.np, child.np);
+		else
+			pr_info("%pOF has as child subdomain: %pOF.\n",
+				parent.np, child.np);
+	}
+
+	return 0;
+
+err_out:
+	dev_warn(dev, "failed to probe pd %s", pd->pd.name);
+	return ret;
+}
+
+static struct platform_driver reg_pd_driver = {
+	.driver = {
+		.name	= "regulator_power_domain",
+		.of_match_table = reg_pd_of_match,
+		.owner	= THIS_MODULE,
+	},
+	.probe = reg_pd_probe,
+};
+
+static __init int reg_pd_init(void)
+{
+	return platform_driver_register(&reg_pd_driver);
+}
+core_initcall(reg_pd_init);
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ