From patchwork Fri Jan 19 13:25:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13523794 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 A852854BE9 for ; Fri, 19 Jan 2024 13:25:43 +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=1705670745; cv=none; b=o8PIq+hozpwcTinZ4E4SPdivYwFqTDSh1l2jcIpEQYk6klf/81yXrwCfZdhREfncU6Os+2lgGIuxcQIDRlHFQZWSEMzYg7ivWWbuBN7obWS5btjhUwti+OqVbM2TrSTGRqU85kVl0EO5DZjiWuGs3Dq01P68AjDGwkoR8udWbT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670745; c=relaxed/simple; bh=yxObVGl9FlHXCDPkT1CCVeqiUamoD375a9LA8yEV5Ro=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tzJjIqlv/Ub6StxqHsKD4hNgQM19KL1PsKh8ziP6wItebidiks/WtIlaSc4bpdT8jue2xdINBguDXv+wZSPS0GZpqAphqRRgCW97Bc58R5noujC+DzyTRKrrr2zc2znL0evRSdje41wndR9ep2whJ6AgA46sUEX+xHfUiw6Gtas= 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-00074F-C2; 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-000viG-4z; 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-00F97h-0G; 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 1/7] dt-bindings: power: reset: add generic PSCR binding trackers Date: Fri, 19 Jan 2024 14:25:15 +0100 Message-Id: <20240119132521.3609945-2-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: linux-pm@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: linux-pm@vger.kernel.org Add binding for Power State Change Reason (PSCR) subsystem Signed-off-by: Oleksij Rempel --- .../devicetree/bindings/power/reset/pscr.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/reset/pscr.yaml diff --git a/Documentation/devicetree/bindings/power/reset/pscr.yaml b/Documentation/devicetree/bindings/power/reset/pscr.yaml new file mode 100644 index 000000000000..1ce973f3473c --- /dev/null +++ b/Documentation/devicetree/bindings/power/reset/pscr.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/state-change/pscr.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Power State Change Reason (PSCR) + +maintainers: + - Oleksij Rempel + +description: Binding for devices responsable to store reasons for power state + changes such as reboot and power-off. Reasons like unknown, under voltage, + and over temperature are captured for diagnostic or automatic recovery + purposes. + +properties: + $nodename: + pattern: "^pscr(@.*|-([0-9]|[1-9][0-9]+))?$" + + pscr-unknown: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Value to indicate an unknown reason for the power state change. + + pscr-under-voltage: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + Value to indicate an under-voltage condition of a system critical + regulator as the reason for the power state change. + + pscr-over-current: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + Value to indicate an over-current condition of a system ctitical regulator + as the reason for the power state change. + + pscr-regulator-failure: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + Value to indicate an unknow, system ctitical regulator related failure + as the reason for the power state change. + + pscr-over-temperature: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + Value to indicate a system critical over-temperature condition as the + reason for the power state change. + +additionalProperties: true + +... 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: 13523797 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 E484554FBE 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=1705670747; cv=none; b=VCa84UO7+bFqmfO4Qpb3mWwVW8+tD/PW5t/m35EM1Oko1OZ4PoS8MOrSidKbFUV6GW8t97yghtkMh1S1WRypXwAiLGo4hPese8FdnpXwfRUgQaquGy05EftnD2OFu8u+dv8pLsvCtX/69GAUI2zu4ccqJ2bTIVCIhf/v1e8/zO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670747; c=relaxed/simple; bh=3Glzu+0PbXiGnMMmOn9Xn/tWC6n+7I7VVFwZl4dJEDA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c3gN8e6ObTBvdAj0HoE14r5EcIYNpRhFKjAhN90nqRLjjK/iNy27Nn40M5J1cyzR4uOHxJq4qREHnKYJ+rN85ochwRfU6xOgGNJcZpSInx+s01WX4TINQlt6HuC3dXLD6FK/+BCPBPY81gQwTdZh8VoaBuOYLXtoj5hB/DzM3wk= 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: linux-pm@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: linux-pm@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: 13523790 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 C918853E1D for ; Fri, 19 Jan 2024 13:25:41 +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=1705670743; cv=none; b=HixgWi+sh6FjyGUdjXsnp6yXqzawW0zum2+ukg8jXngPYz+IzbTQhufwp67tRXMubIwb1XZiEvI1f/OJU9Wo06XaNmCGQJIkWAeB7FyxXgj392OLr0OM607AJh4d1057yc7qsFJAWKd8eJf3bIzogpZoLnvVgcyDxMpA78yXoCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670743; c=relaxed/simple; bh=y/hGCVajOvX8o6Efi9UdqxsGrdX7qFeQ/WFMS56UPW4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EnDpaYiM6S/A2UsXxmpeRoicuf33WdVX1qPAE8iJsjkysB3uk7KT+TCAhvMM4raNZ+694zK2pom/9yDz87H4rLwQxvIeiAmCicwZ0I9cxRHWK6yn1ArngzSDmCmJM0ZcKNq7nJ3yx9bIux6UQW2EavhKfu1ww8Coo9/2/I3JX3U= 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: linux-pm@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: linux-pm@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:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13523795 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 0E68C54BFF for ; Fri, 19 Jan 2024 13:25:43 +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=1705670745; cv=none; b=kY5jlQqd9/NV1rSigXqIcWXoP6xbUVP9lFgsJbkmSJD3QlZTTi5Rrn/7Fd9BTV+ZxwSapQLK1VzICNYx9jlT4Ewesw0LPVaPTJt+feHGvcjKmXcsutyYFMCH7x+BgWBAxNlL+fAyY+XV/IhaY+iL5Mm8vgSNVJxPEn24Dswceyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670745; c=relaxed/simple; bh=XRisp6Vk9LcyDYqrO7hm1pl+pjDkrGL7bL4CcMKtXaY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BWKRq2dQp9cuK3EO6UEaQAMMSlbvJ4Ovd7wwqVqsflFgKolayoo/ul0BoXfpzvdQwpbbzki9DF+FMtQTEmbAmbKpzmsvFNpeiUWCzy4EEaKeUMi/U4PouzXvwHE+MPxK57sUXgBM1ZMa6ZIGkCqTtNjrQGnV+jqykH/rgQ7KJG8= 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-00074I-C2; 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-000viM-7a; 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-00F98B-0X; 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 4/7] nvmem: provide consumer access to cell size metrics Date: Fri, 19 Jan 2024 14:25:18 +0100 Message-Id: <20240119132521.3609945-5-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: linux-pm@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: linux-pm@vger.kernel.org Add nvmem_cell_get_size() function to provide access to cell size metrics. In some cases we may get cell size less as consumer would expect it. So, nvmem_cell_write() would fail with incorrect buffer size. Signed-off-by: Oleksij Rempel --- drivers/nvmem/core.c | 25 +++++++++++++++++++++++++ include/linux/nvmem-consumer.h | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index bf42b7e826db..6c5b785b804b 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1753,6 +1753,31 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) EXPORT_SYMBOL_GPL(nvmem_cell_write); +/** + * nvmem_cell_get_size() - Get the size of a given nvmem cell + * @cell: nvmem cell to be queried. + * @bytes: Pointer to store the size of the cell in bytes. Can be NULL. + * @bits: Pointer to store the size of the cell in bits. Can be NULL. + * + * Return: 0 on success or negative on failure. + */ +int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, size_t *bits) +{ + struct nvmem_cell_entry *entry = cell->entry; + + if (!entry->nvmem) + return -EINVAL; + + if (bytes) + *bytes = entry->bytes; + + if (bits) + *bits = entry->nbits; + + return 0; +} +EXPORT_SYMBOL_GPL(nvmem_cell_get_size); + static int nvmem_cell_read_common(struct device *dev, const char *cell_id, void *val, size_t count) { diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 6ec4b9743e25..a174b05514b4 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -56,6 +56,7 @@ void nvmem_cell_put(struct nvmem_cell *cell); void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); +int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, size_t *bits); int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val); int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); @@ -127,6 +128,12 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell, return -EOPNOTSUPP; } +static inline int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, + size_t *bits) +{ + return -EOPNOTSUPP; +} + static inline int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val) { From patchwork Fri Jan 19 13:25:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13523791 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 AA89453E10 for ; Fri, 19 Jan 2024 13:25:41 +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=1705670743; cv=none; b=f14Ey5IYRlNaNlP14zhBGBMBjN8PLaxwn+NRENbCNa6PdMnly9RBVJvfgBHcKWya8Z3GAGB9EMiruOT6cGqA6uus1R6EDNF/BK8Tb6aEMa8wZ2kbO0svLDboQ8H80nFYDXMPMyFUrymbTQhIP+yYRmIVBGU2M1dvbM/p7h6g1SM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670743; c=relaxed/simple; bh=C3KOqcCPboHE8CVljWUDfdheWimD/KSO18sHrtBids4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u/7Wt37BeKi2b4jvEWXxZghpwUbSLu4a5YNYbqDLA+l1dm1KIBnz3mfRQ6jNSiOGnAV4YzVBflK9LMoqtaqWNSdzvdGDUbzCZabi/ouIMVmsD3J6cdjY5JeZ5TdTjA/dFojWc7AdwKR0asAHvVk2DWuyt+a9ByJGunqMuwHpjfA= 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-00074J-C2; 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-000viN-8m; 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-00F98M-0b; 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 5/7] power: reset: add PSCR NVMEM Driver for Storing Power State Change Reasons Date: Fri, 19 Jan 2024 14:25:19 +0100 Message-Id: <20240119132521.3609945-6-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: linux-pm@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: linux-pm@vger.kernel.org This driver utilizes the Power State Change Reasons (PSCR) framework to store specific power state change information, such as shutdown or reboot reasons, into a designated non-volatile memory (NVMEM) cell. Signed-off-by: Oleksij Rempel --- drivers/power/reset/Kconfig | 11 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/pscr-nvmem.c | 100 +++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 drivers/power/reset/pscr-nvmem.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index da76e84302b9..a110dff599af 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -324,3 +324,14 @@ menuconfig PSCR timeouts. If unsure, say N. + +if PSCR + +config PSCR_NVMEM + tristate "Generic NVMEM-based Power State Change Reason Tracking" + depends on OF + help + Enabling this option adds support for storing power state change + reasons in a NVMEM cell. + +endif diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index d9d744302c68..e7985d81ac8a 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -32,6 +32,7 @@ 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_PSCR_NVMEM) += pscr-nvmem.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-nvmem.c b/drivers/power/reset/pscr-nvmem.c new file mode 100644 index 000000000000..74048341b7d7 --- /dev/null +++ b/drivers/power/reset/pscr-nvmem.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) Vaisala Oyj. All rights reserved. +// Copyright (c) 2024 Pengutronix, Oleksij Rempel +/* + * Based on drivers/power/reset/nvmem-reboot-mode.c + * Copyright (c) Vaisala Oyj. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include + +struct pscr_nvmem { + struct pscr_driver pscr_drv; + struct nvmem_cell *cell; + size_t max_magic_bytes; +}; + +static int pscr_nvmem_write(struct pscr_driver *pscr_drv, u32 magic) +{ + struct pscr_nvmem *priv = container_of(pscr_drv, struct pscr_nvmem, + pscr_drv); + size_t size = min(priv->max_magic_bytes, sizeof(magic)); + int ret; + + ret = nvmem_cell_write(priv->cell, &magic, size); + if (ret < 0) + dev_err(pscr_drv->dev, "update reason bits failed: %pe\n", + ERR_PTR(ret)); + + return ret; +} + +static int pscr_nvmem_probe(struct platform_device *pdev) +{ + const char *pscr = "pscr"; + struct pscr_nvmem *priv; + size_t bytes, bits, magic_bits; + int ret; + + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->pscr_drv.dev = &pdev->dev; + priv->pscr_drv.write = pscr_nvmem_write; + + priv->cell = devm_nvmem_cell_get(&pdev->dev, pscr); + if (IS_ERR(priv->cell)) + return dev_err_probe(&pdev->dev, PTR_ERR(priv->cell), + "failed to get the nvmem %s cell\n", pscr); + + ret = nvmem_cell_get_size(priv->cell, &bytes, &bits); + if (ret < 0) + return dev_err_probe(&pdev->dev, ret, "failed to get the nvmem %s size\n", + pscr); + + if (!bytes || bytes > sizeof(u32) || bits > 32) + return dev_err_probe(&pdev->dev, -EINVAL, "invalid nvmem %s size. bytes: %zu, bits: %zu\n", + pscr, bytes, bits); + + ret = devm_pscr_register(&pdev->dev, &priv->pscr_drv); + if (ret) + return dev_err_probe(&pdev->dev, ret, "failed to register pscr driver\n"); + + magic_bits = fls(priv->pscr_drv.max_magic); + priv->max_magic_bytes = DIV_ROUND_UP(magic_bits, 8); + + if (!bits) + bits = bytes * 8; + + if (magic_bits > bits) + return dev_err_probe(&pdev->dev, -EINVAL, "provided magic can't fit into nvmem %s. bytes: %zu, bits: %zu, magic_bits: %zu\n", + pscr, bytes, bits, magic_bits); + + return ret; +} + +static const struct of_device_id pscr_nvmem_of_match[] = { + { .compatible = "pscr-nvmem" }, + {} +}; +MODULE_DEVICE_TABLE(of, pscr_nvmem_of_match); + +static struct platform_driver pscr_nvmem_driver = { + .probe = pscr_nvmem_probe, + .driver = { + .name = "pscr-nvmem", + .of_match_table = pscr_nvmem_of_match, + }, +}; +module_platform_driver(pscr_nvmem_driver); + +MODULE_AUTHOR("Oleksij Rempel "); +MODULE_DESCRIPTION("NVMEM Driver for Power State Change Reason Tracking"); +MODULE_LICENSE("GPL v2"); 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: 13523793 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 063185472A for ; Fri, 19 Jan 2024 13:25:43 +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=1705670744; cv=none; b=mv3Rd2ybj5l1kpiYkPE8I8ge3zSzuR5N/hiYhkRLZZXdjurkoQ/E6y263oDNxHgBcJcGuhSPb+QSqPE4rr+uy//55xUGexJLA8P3rnP2aCiG8D9wniBWqdSNKEb/CxX5CjNMfmt63FSFH0velPmKhowbSdBT4uBVHHQ/Ih45OjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670744; c=relaxed/simple; bh=jDr0KT8gV5WT+Ey/AytkyFJuAM5xTX5pg/4GXSSHhOk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WUToz/7+KU6ARVfYQ9vpFINKcJAdx3T46C/eRwooXQylIa5r3tMDHAl+urEzuYe3Ughh9n5HbmhnvdetEK2QFhj76Dpz+S46e2EcMK3YOGKFjWEtiEGmGedG7P/PA8+Dqe2lhGBGZ31BamNe9CCre/cZPGyZ+AWTn9lUBgvUwUs= 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: linux-pm@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: linux-pm@vger.kernel.org Store the state change reason to some black box, for later investigation. Signed-off-by: Oleksij Rempel Reviewed-by: Mark Brown --- 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); } From patchwork Fri Jan 19 13:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13523792 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 4FDF954646 for ; Fri, 19 Jan 2024 13:25:42 +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=1705670743; cv=none; b=IzUV2lfMECBye0RIvZaYc3kXY1joTZdpj0HG0cQ8aF1JMyhLDI1m1c0q57sjLAdukvE5iwhNQ4cI/MfaoafOb4NHVAhsAj0ZdObP6UW9om8mbz+Q3r73nLRZM8L1mPpH0SJQV2sv7Kv2avTDp9VzeE+tzkp0+1XbgNOuc2sF4+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670743; c=relaxed/simple; bh=FG8+XP94f/Ig6ekDFdWhMR1QY436ISnaJd2Qe3LwG1s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f7QQMqezfL79GxLYMDvpAZ1CaVP+jjOPIjv2YTAV1dZ0QsStvZ01J664gfnXwveIpmRsq2wGe6QdxlIRI3BbmiJAf1T110Re2IYm+fBD6seeBTZ9G/i/I8JnBUQQZfhgwb993t1ZQOV/jTcCVUt+3r3rJhccHILAO7cgg604Pe8= 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-00074L-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-000viS-AL; 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-00F98h-0j; 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 7/7] thermal: core: set Power State Change Reason before hw_protection_shutdown() Date: Fri, 19 Jan 2024 14:25:21 +0100 Message-Id: <20240119132521.3609945-8-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: linux-pm@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: linux-pm@vger.kernel.org Store the state change reason to some black box for later investigation. Signed-off-by: Oleksij Rempel --- drivers/thermal/thermal_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 9c17d35ccbbd..5ee3a59d7a0e 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -325,6 +326,7 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz) dev_emerg(&tz->device, "%s: critical temperature reached, " "shutting down\n", tz->type); + set_power_state_change_reason(PSCR_OVERTEMPERATURE); hw_protection_shutdown("Temperature too high", poweroff_delay_ms); } EXPORT_SYMBOL(thermal_zone_device_critical);