From patchwork Wed Dec 21 21:09:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Castro X-Patchwork-Id: 35527 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3744252wrn; Wed, 21 Dec 2022 13:12:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXsJIL8iPau+JDLjM44NfJeGco5P11yHl5XUSkn+vb84JrwJqtNz1G+cWO0goeQTrGbQtJYD X-Received: by 2002:aa7:cf94:0:b0:47b:16f5:61dc with SMTP id z20-20020aa7cf94000000b0047b16f561dcmr2838165edx.37.1671657147538; Wed, 21 Dec 2022 13:12:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671657147; cv=none; d=google.com; s=arc-20160816; b=bc9e1uhQaN9bLrPHEtpCqvAz+nzWMX9R6grvNvVNrO3c4n6nfQOVFQxtG17RLb02Z+ VJ8jZjL8KzyUB2xW2AnzeX6dq489PVsHqnfY36xEvU2RwreELhYXvw+Whb1eMyzhts2V mgMf9gZ1BA+fwef6QAPjM3Prpj21E8OrSqsuHYOXMr59CLENyiqguTBavtS0AOTTn2tP FO2SaICeFueIT8iHgWkBWO08KHZMJmzunFHjZnL49qu9i9wg4xoCp0FD/Dp4FS290+To 5frN+G0SVts/nT+uMbG8O4NB76v5pQyJzdng2Ok6GhB+qT7WOaHbfcbPRmfrnOelWNPx W9+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ZOINuR7IDM4fbTZA29WCL8nEYJNEbEATU42EAR3XrY0=; b=WIWZ3xp/iNT4ca5F7IWwpyBG8Lge8pAh1XO1DKGFKfiyjiO3ZiuR9VmwGaDc0UM5d0 uAw+9ZSoFsCY68MhX5M9/cwa0PJ4fPKKJH30hAiItqsMatRHTdg7JgDXFtvK+I8dmD2I lxMVpDA8TPF8XyCJh0WhJPB3qxglHloi306b9Gy61KUMqAXAeIhKLWCxAZ8amZLGZt0N 9k94fAgdvb577+ZkyvXP1i9UAAd+1SPbPxQbzjD2nO0EF4wn6R4DXzVl2HCFpX3HaM8O 40B5/oJGdfntyfVCc+av177Qg5DmzDzOErAxIrLVdueaDJinLe5ZOwpj3dYzA6+hEUw6 bSuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020a056402255000b004614acc0706si16416912edb.250.2022.12.21.13.12.03; Wed, 21 Dec 2022 13:12:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234633AbiLUVKh (ORCPT + 99 others); Wed, 21 Dec 2022 16:10:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234967AbiLUVKH (ORCPT ); Wed, 21 Dec 2022 16:10:07 -0500 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A8B8E27B00; Wed, 21 Dec 2022 13:09:57 -0800 (PST) X-IronPort-AV: E=Sophos;i="5.96,263,1665414000"; d="scan'208";a="146995973" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 22 Dec 2022 06:09:56 +0900 Received: from mulinux.example.org (unknown [10.226.92.211]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 3E65F40DC546; Thu, 22 Dec 2022 06:09:50 +0900 (JST) From: Fabrizio Castro To: Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , Sebastian Reichel , Geert Uytterhoeven Cc: Fabrizio Castro , Lee Jones , linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Chris Paterson , Biju Das , linux-renesas-soc@vger.kernel.org, Laurent Pinchart , Jacopo Mondi Subject: [PATCH v2 4/4] power: reset: Add new driver for RZ/V2M PWC poweroff Date: Wed, 21 Dec 2022 21:09:17 +0000 Message-Id: <20221221210917.458537-5-fabrizio.castro.jz@renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221221210917.458537-1-fabrizio.castro.jz@renesas.com> References: <20221221210917.458537-1-fabrizio.castro.jz@renesas.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752859565209383543?= X-GMAIL-MSGID: =?utf-8?q?1752859565209383543?= The RZ/V2M PWC IP controls external power supplies and therefore can turn the power supplies off when powering down the system. Add driver to poweroff the system. Signed-off-by: Fabrizio Castro Acked-by: Sebastian Reichel --- v1->v2: Dropped OF match table and syscon as a result of the change in DT model drivers/power/reset/Kconfig | 9 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/rzv2m-pwc-poweroff.c | 67 ++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 drivers/power/reset/rzv2m-pwc-poweroff.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index a8c46ba5878f..1fcf691ae68e 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -303,4 +303,13 @@ config POWER_MLXBF help This driver supports reset or low power mode handling for Mellanox BlueField. +config POWER_RESET_RZV2M_PWC + tristate "Renesas RZ/V2M PWC Power OFF support" + depends on MFD_RZV2M_PWC_CORE || COMPILE_TEST + help + The RZ/V2M PWC IP controls external power supplies and therefore can + turn the power supplies off when powering down the system. + Enable this driver when PWC is in control of the system power supplies + and it's the preferred way to shutdown the system. + endif diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 0a39424fc558..f05a8abff2eb 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -36,3 +36,4 @@ obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o 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_POWER_RESET_RZV2M_PWC) += rzv2m-pwc-poweroff.o diff --git a/drivers/power/reset/rzv2m-pwc-poweroff.c b/drivers/power/reset/rzv2m-pwc-poweroff.c new file mode 100644 index 000000000000..f5bc383c22e1 --- /dev/null +++ b/drivers/power/reset/rzv2m-pwc-poweroff.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2022 Renesas Electronics Corporation + * + * Reset driver for Renesas RZ/V2M External Power Sequence Controller (PWC) + */ + +#include +#include +#include +#include +#include "../../mfd/rzv2m-pwc.h" + +#define PWC_PWCRST_RSTSOFTAX 0x1 +#define PWC_PWCCKEN_ENGCKMAIN 0x1 +#define PWC_PWCCTL_PWOFF 0x1 + +struct rzv2m_pwc_poweroff_priv { + void __iomem *base; + struct device *dev; +}; + +static int rzv2m_pwc_poweroff(struct sys_off_data *data) +{ + struct rzv2m_pwc_poweroff_priv *priv = + (struct rzv2m_pwc_poweroff_priv *)data->cb_data; + + writel(PWC_PWCRST_RSTSOFTAX, priv->base + PWC_PWCRST); + writel(PWC_PWCCKEN_ENGCKMAIN, priv->base + PWC_PWCCKEN); + writel(PWC_PWCCTL_PWOFF, priv->base + PWC_PWCCTL); + + mdelay(150); + + dev_err(priv->dev, "Failed to power off the system"); + + return NOTIFY_DONE; +} + +static int rzv2m_pwc_poweroff_probe(struct platform_device *pdev) +{ + struct rzv2m_pwc_priv *pdata = dev_get_drvdata(pdev->dev.parent); + struct rzv2m_pwc_poweroff_priv *priv; + + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->base = pdata->base; + priv->dev = &pdev->dev; + + return devm_register_power_off_handler(&pdev->dev, rzv2m_pwc_poweroff, + priv); +} + +static struct platform_driver rzv2m_pwc_poweroff_driver = { + .probe = rzv2m_pwc_poweroff_probe, + .driver = { + .name = "rzv2m_pwc_poweroff", + }, +}; +module_platform_driver(rzv2m_pwc_poweroff_driver); + +MODULE_ALIAS("platform:rzv2m_pwc_poweroff"); +MODULE_SOFTDEP("pre: rzv2m_pwc"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Fabrizio Castro "); +MODULE_DESCRIPTION("Renesas RZ/V2M PWC power OFF driver");