From patchwork Fri Jan 19 13:25:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 764065 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 214175579D for ; Fri, 19 Jan 2024 13:25:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670749; cv=none; b=ru0sT61nHhnFK5U0+y3HgPRODGbaDnOhHPAD7JjL6OZawG0NwZDyMwVwJOoZdRwNiv7FmG65vWrGsBtH9n46p6coNufBWnPdT40UEXXEbfnv7//2hzEB4xn+Sxzgj10rYjNOVAkhJ3iI6L/hf7XhGI+18Nw09jys8In5moi+2HE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670749; c=relaxed/simple; bh=3Glzu+0PbXiGnMMmOn9Xn/tWC6n+7I7VVFwZl4dJEDA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HcKcAoE40LtpHbYB9M607G2JudA7aBZWGssJ/Z1496dDyHCHnspOW9CA05w2emBWMje7hnz+EWWo/zn384K5bRBMOGLv7F1PUnKDt5qurgT+qxt+Mo+nBylmf4gN1S5uXvhw908r37aq+7/8TZV5MPCHO6ddhMcIpkuEzkg6caA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rQos7-00074G-C1; Fri, 19 Jan 2024 14:25:23 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQos6-000viH-60; Fri, 19 Jan 2024 14:25:22 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rQos6-00F97r-0M; Fri, 19 Jan 2024 14:25:22 +0100 From: Oleksij Rempel To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Srinivas Kandagatla Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?q?S=C3=B8ren_Andersen?= Subject: [RFC PATCH v1 2/7] power: reset: Introduce PSCR Tracking Framework for Non-Volatile Storage Date: Fri, 19 Jan 2024 14:25:16 +0100 Message-Id: <20240119132521.3609945-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240119132521.3609945-1-o.rempel@pengutronix.de> References: <20240119132521.3609945-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: devicetree@vger.kernel.org This commit introduces the Power State Change Reasons (PSCR) tracking framework into the kernel. The framework is vital for systems where PMICs or watchdogs cannot provide information on power state changes. It stores reasons for system shutdowns and reboots, like under-voltage or software-triggered events, in non-volatile hardware storage. This approach is essential for postmortem analysis in scenarios where traditional storage methods (block devices, RAM) are not feasible. The framework aids bootloaders and early-stage system components in recovery decision-making, although it does not cover resets caused by hardware issues like system freezes or watchdog timeouts. Signed-off-by: Oleksij Rempel --- drivers/power/reset/Kconfig | 19 +++ drivers/power/reset/Makefile | 1 + drivers/power/reset/pscr.c | 259 +++++++++++++++++++++++++++++++++++ include/linux/pscr.h | 40 ++++++ 4 files changed, 319 insertions(+) create mode 100644 drivers/power/reset/pscr.c create mode 100644 include/linux/pscr.h diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index fece990af4a7..da76e84302b9 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -305,3 +305,22 @@ config POWER_MLXBF This driver supports reset or low power mode handling for Mellanox BlueField. endif + +menuconfig PSCR + bool "Power State Change Reasons (PSCR) Tracking Framework" + help + Enables the Power State Change Reasons (PSCR) tracking framework. + + This framework is designed to store reasons for system shutdowns or + reboots, like under voltage or software-triggered events, in non-volatile + hardware storage. It is particularly useful for postmortem analysis, where + traditional storage methods (like block devices or RAM) are not feasible + due to immediate power-down requirements or insufficient power to retain + data. + + This is useful for bootloaders or other early-stage system components to + make recovery decisions based on the last known system state. Note that it + does not cover hardware-induced resets like system freezes or watchdog + timeouts. + + If unsure, say N. diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index a95d1bd275d1..d9d744302c68 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_POWER_RESET_KEYSTONE) += keystone-reset.o obj-$(CONFIG_POWER_RESET_SYSCON) += syscon-reboot.o obj-$(CONFIG_POWER_RESET_SYSCON_POWEROFF) += syscon-poweroff.o obj-$(CONFIG_POWER_RESET_RMOBILE) += rmobile-reset.o +obj-$(CONFIG_PSCR) += pscr.o obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o diff --git a/drivers/power/reset/pscr.c b/drivers/power/reset/pscr.c new file mode 100644 index 000000000000..7506ecbe1aad --- /dev/null +++ b/drivers/power/reset/pscr.c @@ -0,0 +1,259 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2016, Fuzhou Rockchip Electronics Co., Ltd +// Copyright (c) 2024 Pengutronix, Oleksij Rempel +/* + * Based on drivers/power/reset/reboot-mode.c + * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd + */ + +#include +#include +#include +#include +#include +#include +#include + +#define PREFIX "pscr-" + +struct reason_info { + enum power_state_change_reason pscr; + u32 magic; + struct list_head list; +}; + +enum power_state_change_reason system_pscr; + +struct pscr_map { + const char *reason; + enum power_state_change_reason pscr; +}; + +struct pscr_map pscr_map_table[] = { + { "unknown", PSCR_UNKNOWN }, + { "under-voltage", PSCR_UNDER_VOLTAGE }, + { "over-current", PSCR_OVER_CURRENT }, + { "regulator-failure", PSCR_REGULATOR_FAILURE }, + { "over-temperature", PSCR_OVERTEMPERATURE }, +}; + +static int find_reason_by_string(const char *reason) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(pscr_map_table); i++) { + if (!strcmp(reason, pscr_map_table[i].reason)) + return pscr_map_table[i].pscr; + } + + return -ENOENT; +} + +/** + * set_power_state_change_reason() - Set the system's power state change reason + * @reason: The enum value representing the power state change reason + * + * This function sets the system's power state change reason based on the + * provided enum value. + */ +void set_power_state_change_reason(enum power_state_change_reason reason) +{ + system_pscr = reason; +} +EXPORT_SYMBOL_GPL(set_power_state_change_reason); + +static unsigned int get_pscr_magic(struct pscr_driver *pscr_drv, + const char *cmd) +{ + struct reason_info *info; + + list_for_each_entry(info, &pscr_drv->head, list) { + if (info->pscr == system_pscr) + return info->magic; + } + + return 0; +} + +static int pscr_notify(struct notifier_block *this, + unsigned long reason, void *cmd) +{ + struct pscr_driver *pscr_drv = container_of(this, struct pscr_driver, + reboot_notifier); + unsigned int magic; + + magic = get_pscr_magic(pscr_drv, cmd); + if (magic) + pscr_drv->write(pscr_drv, magic); + + return NOTIFY_DONE; +} + +/** + * pscr_process_property() - Process a power state change reason property + * @pscr_drv: Pointer to the pscr_driver structure + * @prop: Pointer to the property structure to be processed + * + * This function processes a device tree property representing a power state + * change reason and initializes the relevant data structures. + * + * Returns: 0 on success, -ENOMEM on memory allocation failure. + */ +static int pscr_process_property(struct pscr_driver *pscr_drv, + struct property *prop) +{ + struct device *dev = pscr_drv->dev; + size_t len = strlen(PREFIX); + struct reason_info *info; + int ret; + + if (strncmp(prop->name, PREFIX, len)) + return 0; + + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + ret = of_property_read_u32(dev->of_node, prop->name, &info->magic); + if (ret) { + dev_err(dev, "Can't read magic number for %s: %pe\n", + prop->name, ERR_PTR(ret)); + devm_kfree(dev, info); + return 0; + } + + if (!info->magic) { + dev_err(dev, "%s with magic number == 0\n", prop->name); + devm_kfree(dev, info); + return 0; + } + + info->pscr = find_reason_by_string(prop->name + len); + if (info->pscr < 0) { + dev_err(dev, "unsupported reason name(%s): %pe\n", + prop->name, ERR_PTR(info->pscr)); + devm_kfree(dev, info); + return 0; + } + + if (info->magic > pscr_drv->max_magic) + pscr_drv->max_magic = info->magic; + + dev_dbg(dev, "registering reason = %s, magic = %d, pscr = %d\n", + prop->name, info->magic, info->pscr); + list_add_tail(&info->list, &pscr_drv->head); + + return 0; +} + +/* + * pscr_register() - Register the pscr driver and initialize power state change + * reasons + * @pscr_drv: Pointer to the pscr_driver structure + * + * This function registers the pscr driver and initializes power state change + * reasons based on device tree properties. + * + * Returns: 0 on success, -ENOMEM on memory allocation failure + */ +int pscr_register(struct pscr_driver *pscr_drv) +{ + struct device_node *np = pscr_drv->dev->of_node; + struct property *prop; + + INIT_LIST_HEAD(&pscr_drv->head); + + for_each_property_of_node(np, prop) { + int ret = pscr_process_property(pscr_drv, prop); + if (ret) + return ret; + } + + pscr_drv->reboot_notifier.notifier_call = pscr_notify; + register_reboot_notifier(&pscr_drv->reboot_notifier); + + return 0; +} +EXPORT_SYMBOL_GPL(pscr_register); + +/* + * pscr_unregister() - Unregister the pscr driver's reboot notifier + * @pscr_drv: Pointer to the pscr_driver structure + * + * This function unregisters the reboot notifier for the pscr driver. + */ +void pscr_unregister(struct pscr_driver *pscr_drv) +{ + unregister_reboot_notifier(&pscr_drv->reboot_notifier); +} +EXPORT_SYMBOL_GPL(pscr_unregister); + +static void devm_pscr_release(struct device *dev, void *res) +{ + pscr_unregister(*(struct pscr_driver **)res); +} + +/** + * devm_pscr_register - Register a device-managed PSCR driver + * @dev: Device to associate the PSCR driver with + * @pscr_drv: Pointer to the PSCR driver to be registered + * + * Registers a Power State Change Reason (PSCR) driver as a device-managed + * resource. + * + * Returns: 0 on successful registration or a negative error code on failure. + */ +int devm_pscr_register(struct device *dev, + struct pscr_driver *pscr_drv) +{ + struct pscr_driver **dr; + int rc; + + dr = devres_alloc(devm_pscr_release, sizeof(*dr), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + rc = pscr_register(pscr_drv); + if (rc) { + devres_free(dr); + return rc; + } + + *dr = pscr_drv; + devres_add(dev, dr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_pscr_register); + +static int devm_pscr_match(struct device *dev, void *res, void *data) +{ + struct pscr_driver **p = res; + + if (WARN_ON(!p || !*p)) + return 0; + + return *p == data; +} + +/** + * devm_pscr_unregister - Unregister a managed PSCR driver + * @dev: Device associated with the PSCR driver + * @pscr_drv: Pointer to the PSCR driver to unregister + * + * Unregisters a device-managed Power State Change Reason (PSCR) driver. + * It handles the cleanup and release of resources associated with the PSCR + * driver which was previously registered. + */ +void devm_pscr_unregister(struct device *dev, + struct pscr_driver *pscr_drv) +{ + WARN_ON(devres_release(dev, + devm_pscr_release, + devm_pscr_match, pscr_drv)); +} +EXPORT_SYMBOL_GPL(devm_pscr_unregister); + +MODULE_AUTHOR("Oleksij Rempel "); +MODULE_DESCRIPTION("Power State Change Reason (PSCR) tracking framework"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/pscr.h b/include/linux/pscr.h new file mode 100644 index 000000000000..bf66dd69d96d --- /dev/null +++ b/include/linux/pscr.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PSCR_H__ +#define __PSCR_H__ + +enum power_state_change_reason { + PSCR_UNKNOWN, + PSCR_UNDER_VOLTAGE, + PSCR_OVER_CURRENT, + PSCR_REGULATOR_FAILURE, + PSCR_OVERTEMPERATURE, +}; + +struct pscr_driver { + struct device *dev; + struct list_head head; + int (*write)(struct pscr_driver *pscr_drv, u32 magic); + struct notifier_block reboot_notifier; + u32 max_magic; +}; + +int pscr_register(struct pscr_driver *pscr_drv); +void pscr_unregister(struct pscr_driver *pscr_drv); +int devm_pscr_register(struct device *dev, + struct pscr_driver *pscr_drv); +void devm_pscr_unregister(struct device *dev, + struct pscr_driver *pscr_drv); + + +#if IS_ENABLED(CONFIG_PSCR) + +void set_power_state_change_reason(enum power_state_change_reason reason); + +#else + +static inline void set_power_state_change_reason(enum power_state_change_reason reason) +{ +} +#endif + +#endif From patchwork Fri Jan 19 13:25:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 764068 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4317F54FB1 for ; Fri, 19 Jan 2024 13:25:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670746; cv=none; b=oV8gSZGs62YToeR2lafW7v1faZu/+GEB7MJLU9nQZIdxyn1kJ0uVQ+i+PUVxW6c5fk+5lH5bklHlNcoXvbd9oPubQWLIqiHM+pps9rCqJ2x05lBEpiFnQg0bX/CvAjMQ6b4U63lazJ0TiJCucipVKb58NwIFQYAUeAZ6zBmD/h0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670746; c=relaxed/simple; bh=y/hGCVajOvX8o6Efi9UdqxsGrdX7qFeQ/WFMS56UPW4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TgnoM8l/xXWcADa3wknIbXM8vnJo6+mzAC0/3hiJ6FOnQBiwpxRWSO7oBlgN10Wd1sbH49npdE2xHJ3vAyXWoJsCoFyBF9Xj9Zhdy1qdtJ35WbTYa6ex6MNwowc2X8m+pWMNABh+3NX/GKkp26E5rmcyK5OXIJdVGlPb2yOirAs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rQos7-00074H-C1; Fri, 19 Jan 2024 14:25:23 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQos6-000viI-6t; Fri, 19 Jan 2024 14:25:22 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rQos6-00F981-0Q; Fri, 19 Jan 2024 14:25:22 +0100 From: Oleksij Rempel To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Srinivas Kandagatla Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?q?S=C3=B8ren_Andersen?= Subject: [RFC PATCH v1 3/7] dt-bindings: power: reset: add bindings for NVMEM hardware storing PSCR Data Date: Fri, 19 Jan 2024 14:25:17 +0100 Message-Id: <20240119132521.3609945-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240119132521.3609945-1-o.rempel@pengutronix.de> References: <20240119132521.3609945-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: devicetree@vger.kernel.org Add device tree bindings that describe hardware implementations of Non-Volatile Memory (NVMEM) used for storing Power State Change Reasons (PSCR). Signed-off-by: Oleksij Rempel --- .../bindings/power/reset/pscr-nvmem.yaml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/reset/pscr-nvmem.yaml diff --git a/Documentation/devicetree/bindings/power/reset/pscr-nvmem.yaml b/Documentation/devicetree/bindings/power/reset/pscr-nvmem.yaml new file mode 100644 index 000000000000..0642b470af41 --- /dev/null +++ b/Documentation/devicetree/bindings/power/reset/pscr-nvmem.yaml @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/state-change/pscr-nvmem.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Generic NVMEM Power State Change Reason storage + +maintainers: + - Oleksij Rempel + +description: This binding describes the Non-Volatile Memory (NVMEM) hardware + that stores Power State Change Reasons (PSCR). + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + const: pscr-nvmem + + nvmem-cells: + description: | + A phandle pointing to the nvmem-cells node where the power state change + reasons are stored. + maxItems: 1 + + nvmem-cell-names: + items: + - const: pscr + + pscr-unknown: + pscr-under-voltage: + pscr-over-current: + pscr-over-temperature: + +required: + - compatible + - nvmem-cells + - nvmem-cell-names + +additionalProperties: false + +examples: + - | + power-state-change-reason { + compatible = "pscr-nvmem"; + nvmem-cells = <&pscr_cell>; + nvmem-cell-names = "pscr"; + pscr-unknown = <1>; + pscr-under-voltage = <2>; + pscr-over-temperature = <3>; + }; +... From patchwork Fri Jan 19 13:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 764067 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20AE055763 for ; Fri, 19 Jan 2024 13:25:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670747; cv=none; b=BX3hJmZsrpBeOnEhfZ4f+9apwk8dhfN/sV0W3eb+Q0BU80jNdBYlaynSQ6VnihgznWTMNM2BIh1eyniE1llwYgOZ2DFl1REleqhMOIKiVROEHGNg77Jf04FwEPHKITEi1npoaze9pnsuJ1xQq57VDGUnGZXvSKspxOYY5BG0f2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670747; c=relaxed/simple; bh=jDr0KT8gV5WT+Ey/AytkyFJuAM5xTX5pg/4GXSSHhOk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kThHhMX7JCH4jqxVS9oZORGjsxI/gjH0W/u4tc7w1F/O02EqN6W3Vhc6uESAQAtO1l44Z34zIs/JT7nt3mYjAk9Rlgd5gehF0GQvb27fF3SU7pAXRATXdLWkB5U13nrWOoT6OfGgzU+3RgU3fV3DdJau/Bw7fAABlqDXL/lPOUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rQos7-00074K-C1; Fri, 19 Jan 2024 14:25:23 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQos6-000viQ-A0; Fri, 19 Jan 2024 14:25:22 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rQos6-00F98X-0f; Fri, 19 Jan 2024 14:25:22 +0100 From: Oleksij Rempel To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Srinivas Kandagatla Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?q?S=C3=B8ren_Andersen?= Subject: [RFC PATCH v1 6/7] regulator: set Power State Change Reason before hw_protection_shutdown() Date: Fri, 19 Jan 2024 14:25:20 +0100 Message-Id: <20240119132521.3609945-7-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240119132521.3609945-1-o.rempel@pengutronix.de> References: <20240119132521.3609945-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: devicetree@vger.kernel.org Store the state change reason to some black box, for later investigation. Signed-off-by: Oleksij Rempel --- drivers/regulator/core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a6cb84af989e..d8a45c89f14a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -5074,6 +5075,7 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free); static void regulator_handle_critical(struct regulator_dev *rdev, unsigned long event) { + enum power_state_change_reason pscr; const char *reason = NULL; if (!rdev->constraints->system_critical) @@ -5082,17 +5084,21 @@ static void regulator_handle_critical(struct regulator_dev *rdev, switch (event) { case REGULATOR_EVENT_UNDER_VOLTAGE: reason = "System critical regulator: voltage drop detected"; + pscr = PSCR_UNDER_VOLTAGE; break; case REGULATOR_EVENT_OVER_CURRENT: reason = "System critical regulator: over-current detected"; + pscr = PSCR_OVER_CURRENT; break; case REGULATOR_EVENT_FAIL: reason = "System critical regulator: unknown error"; + pscr = PSCR_REGULATOR_FAILURE; } if (!reason) return; + set_power_state_change_reason(pscr); hw_protection_shutdown(reason, rdev->constraints->uv_less_critical_window_ms); }