[PATCH 03/10] power: reset: Add TWL6030 power driver, with minimal support for power off

From: Mithil Bavishi
Date: Sat Aug 20 2022 - 03:17:38 EST


From: Paul Kocialkowski <contact@xxxxxxxx>

This adds a TWL6030 power driver, that currently only supports powering
off the device when the TWL is used as system power controller.

This driver might be extended to support more power-related features of the
TWL6030.

Signed-off-by: Paul Kocialkowski <contact@xxxxxxxx>
Signed-off-by: Mithil Bavishi <bavishimithil@xxxxxxxxx>
---
drivers/power/reset/Kconfig | 10 ++++
drivers/power/reset/Makefile | 1 +
drivers/power/reset/twl6030-power.c | 93 +++++++++++++++++++++++++++++
3 files changed, 104 insertions(+)
create mode 100644 drivers/power/reset/twl6030-power.c

diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 39117b697..5156b1613 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -316,3 +316,13 @@ config TWL4030_POWER
and load scripts controlling which resources are switched off/on
or reset when a sleep, wakeup or warm reset event occurs.
endif
+
+config TWL6030_POWER
+ bool "TI TWL6030 power resources"
+ depends on TWL4030_CORE && ARM
+ help
+ Say yes here if you want to use the power resources on the
+ TWL6030 family chips.
+
+ When used as system power controller, this driver allows turning off
+ the main power supply.
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index e9db25b09..692d51cef 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -37,3 +37,4 @@ obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o
obj-$(CONFIG_NVMEM_REBOOT_MODE) += nvmem-reboot-mode.o
obj-$(CONFIG_POWER_MLXBF) += pwr-mlxbf.o
obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o
+obj-$(CONFIG_TWL6030_POWER) += twl6030-power.o
diff --git a/drivers/power/reset/twl6030-power.c b/drivers/power/reset/twl6030-power.c
new file mode 100644
index 000000000..78c8a02a3
--- /dev/null
+++ b/drivers/power/reset/twl6030-power.c
@@ -0,0 +1,93 @@
+/*
+ * TWL6030 power
+ *
+ * Copyright (C) 2016 Paul Kocialkowski <contact@xxxxxxxx>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/mfd/twl.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+
+#define TWL6030_PHOENIX_DEV_ON 0x25
+
+#define TWL6030_PHOENIX_APP_DEVOFF BIT(0)
+#define TWL6030_PHOENIX_CON_DEVOFF BIT(1)
+#define TWL6030_PHOENIX_MOD_DEVOFF BIT(2)
+
+void twl6030_power_off(void)
+{
+ int err;
+
+ err = twl_i2c_write_u8(TWL6030_MODULE_ID0, TWL6030_PHOENIX_APP_DEVOFF |
+ TWL6030_PHOENIX_CON_DEVOFF | TWL6030_PHOENIX_MOD_DEVOFF,
+ TWL6030_PHOENIX_DEV_ON);
+ if (err)
+ pr_err("TWL6030 Unable to power off\n");
+}
+
+static bool twl6030_power_use_poweroff(struct device_node *node)
+{
+ if (of_property_read_bool(node, "ti,system-power-controller"))
+ return true;
+
+ return false;
+}
+
+#ifdef CONFIG_OF
+static const struct of_device_id twl6030_power_of_match[] = {
+ {
+ .compatible = "ti,twl6030-power",
+ },
+ { },
+};
+
+MODULE_DEVICE_TABLE(of, twl6030_power_of_match);
+#endif /* CONFIG_OF */
+
+static int twl6030_power_probe(struct platform_device *pdev)
+{
+ struct device_node *node = pdev->dev.of_node;
+
+ if (!node) {
+ dev_err(&pdev->dev, "Platform data is missing\n");
+ return -EINVAL;
+ }
+
+ /* Board has to be wired properly to use this feature */
+ if (twl6030_power_use_poweroff(node) && !pm_power_off)
+ pm_power_off = twl6030_power_off;
+
+ return 0;
+}
+
+static int twl6030_power_remove(struct platform_device *pdev)
+{
+ return 0;
+}
+
+static struct platform_driver twl6030_power_driver = {
+ .driver = {
+ .name = "twl6030_power",
+ .of_match_table = of_match_ptr(twl6030_power_of_match),
+ },
+ .probe = twl6030_power_probe,
+ .remove = twl6030_power_remove,
+};
+
+module_platform_driver(twl6030_power_driver);
+
+MODULE_AUTHOR("Paul Kocialkowski <contact@xxxxxxxx>");
+MODULE_DESCRIPTION("Power management for TWL6030");
+MODULE_LICENSE("GPL");
--
2.25.1