From patchwork Wed Jul 1 17:26:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 1321296 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=collabora.com Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yFwR6dhgz9sSt for ; Thu, 2 Jul 2020 21:19:03 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A5E9A82214; Thu, 2 Jul 2020 13:14:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id C10CA81B47; Wed, 1 Jul 2020 19:27:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1702B81B5E for ; Wed, 1 Jul 2020 19:27:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sebastian.reichel@collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id CB4B42A54CD Received: by jupiter.universe (Postfix, from userid 1000) id 25D4548010A; Wed, 1 Jul 2020 19:26:57 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Stefano Babic , Fabio Estevam , "NXP i.MX U-Boot Team" Cc: Jaehoon Chung , Simon Glass , u-boot@lists.denx.de Subject: [PATCH 07/12] poweroff: Introduce poweroff uclass Date: Wed, 1 Jul 2020 19:26:20 +0200 Message-Id: <20200701172625.121978-8-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701172625.121978-1-sebastian.reichel@collabora.com> References: <20200701172625.121978-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 02 Jul 2020 13:12:53 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 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 --- 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 diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 5910926faca4..5a76e23b5fb0 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -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 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 2dcc7bb99d02..924e99114ccd 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -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 diff --git a/drivers/power/poweroff-uclass.c b/drivers/power/poweroff-uclass.c new file mode 100644 index 000000000000..c7ffaaca9bee --- /dev/null +++ b/drivers/power/poweroff-uclass.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2019 Collabora Ltd. + * Copyright (c) 2019 GE Inc. + * + * Written by Sebastian Reichel + */ + +#include +#include +#include +#include + +#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", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 7837d459f18c..4adc415ffcfe 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -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 */ diff --git a/include/power/poweroff.h b/include/power/poweroff.h new file mode 100644 index 000000000000..ffaff24649a6 --- /dev/null +++ b/include/power/poweroff.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2019 Collabora Ltd. + * Copyright (c) 2019 GE Inc. + * + * Written by Sebastian Reichel + */ + +#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