@@ -373,4 +373,13 @@ config POWER_MT6323
This adds poweroff driver for mt6323
this pmic is used on mt7623 / Bananapi R2
+config POWEROFF
+ bool "power-off support"
+ depends on DM
+ help
+ Most boards have support to power-off themself. U-Boot provides
+ a uclass API to implement this feature. Poweroff drivers can
+ provide access to board-specific implementations. Using device
+ tree for configuration is recommended.
+
endmenu
@@ -21,3 +21,5 @@ obj-$(CONFIG_POWER_FSL) += power_fsl.o
obj-$(CONFIG_POWER_I2C) += power_i2c.o
obj-$(CONFIG_POWER_SPI) += power_spi.o
obj-$(CONFIG_POWER_MT6323) += mt6323.o
+
+obj-$(CONFIG_POWEROFF) += poweroff-uclass.o
new file mode 100644
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 Collabora Ltd.
+ * Copyright (c) 2019 GE Inc.
+ *
+ * Written by Sebastian Reichel <sebastian.reichel at collabora.com>
+ */
+
+#include <command.h>
+#include <dm.h>
+#include <errno.h>
+#include <power/poweroff.h>
+
+#ifdef CONFIG_CMD_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = uclass_get_device(UCLASS_POWEROFF, 0, &dev);
+ if (ret) {
+ printf("Could not find poweroff device: %d\n", ret);
+ return ret;
+ }
+
+ return dm_poweroff(dev);
+}
+#endif
+
+int dm_poweroff(struct udevice *dev)
+{
+ struct poweroff_ops *ops = poweroff_get_ops(dev);
+
+ if (!ops->poweroff)
+ return -ENOSYS;
+
+ return ops->poweroff(dev);
+}
+
+UCLASS_DRIVER(poweroff) = {
+ .id = UCLASS_POWEROFF,
+ .name = "poweroff",
+};
@@ -84,6 +84,7 @@ enum uclass_id {
UCLASS_PINCONFIG, /* Pin configuration node device */
UCLASS_PINCTRL, /* Pinctrl (pin muxing/configuration) device */
UCLASS_PMIC, /* PMIC I/O device */
+ UCLASS_POWEROFF, /* Poweroff, e.g. via gpio or a special register */
UCLASS_POWER_DOMAIN, /* (SoC) Power domains */
UCLASS_PWM, /* Pulse-width modulator */
UCLASS_PWRSEQ, /* Power sequence device */
new file mode 100644
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2019 Collabora Ltd.
+ * Copyright (c) 2019 GE Inc.
+ *
+ * Written by Sebastian Reichel <sebastian.reichel at collabora.com>
+ */
+
+#ifndef __POWEROFF_H
+#define __POWEROFF_H
+
+struct poweroff_ops {
+ /**
+ * poweroff() - poweroff the system
+ *
+ * @dev: Device used for powering off the system
+ * @return -ve on error (system is powered off otherwise)
+ */
+ int (*poweroff)(struct udevice *dev);
+};
+
+#define poweroff_get_ops(dev) ((struct poweroff_ops *)(dev)->driver->ops)
+
+/**
+ * dm_poweroff() - Poweroff system via DM poweroff driver
+ *
+ * @dev: Device used for powering off the system
+ * @return -ve on error (system is powered off otherwise)
+ */
+int dm_poweroff(struct udevice *dev);
+
+#endif
This adds infrastructure for DM based poweroff drivers including a generic poweroff command, that is exposed via existing CONFIG_CMD_POWEROFF and uses the first registered poweroff driver. Signed-off-by: Sebastian Reichel <sebastian.reichel at collabora.com> --- drivers/power/Kconfig | 9 +++++++ drivers/power/Makefile | 2 ++ drivers/power/poweroff-uclass.c | 43 +++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/power/poweroff.h | 32 ++++++++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 drivers/power/poweroff-uclass.c create mode 100644 include/power/poweroff.h