From patchwork Wed Aug 9 19:24:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 712195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E666BC001DE for ; Wed, 9 Aug 2023 19:25:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233998AbjHITZh (ORCPT ); Wed, 9 Aug 2023 15:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233825AbjHITZX (ORCPT ); Wed, 9 Aug 2023 15:25:23 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777BC4697; Wed, 9 Aug 2023 12:24:18 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fbea14706eso807735e9.2; Wed, 09 Aug 2023 12:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691609057; x=1692213857; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=TwJSdhTVBtoRdC+WKmKXaSMWi9tGMReDfyfqFSEPiQo=; b=l6uiO69hwgNHoBkvQkUdh5VQBz4kBl67ce4b0UfA99F7TdZAeT97JcoZdmI0jFyf3P LbEEsXfH/0QduKrVBF7ZPQvK122wnQY5IIk9Fk9b3mP/oFmgAoeQk/ckJlTxGIIXZDGW oFTdCergjtSQbrCjaQvmwhRg0sgH/iYJzZr6ZS82++ftLbwGUh1PnPCWkGxLuER8SQkd Fm+gzYWzSe7M9TS0YQqmkfvycsl9/u+8y5VAU0l4ZX52P1h7ss/EIk++SkplVr5kb0di Q4zSPzVXIllhlALctiTAhVjMuTN3l/1rzYhSh92Q7mjvgyPJhvtOJlQRLdY2QvPdQ5TU LQhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691609057; x=1692213857; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TwJSdhTVBtoRdC+WKmKXaSMWi9tGMReDfyfqFSEPiQo=; b=aFYIZE1ZndAP8NIL9ZGyi2DR2gY/U6C3264at+PVgMpD1ieK99DfY4Z8P8cclhrm/M KD+Dq9QSJldKJaB8ziCTKLYE0dpMY4pGPyoQkHODaTe4k4iRSwkCHQL0WhVdwtd8OshG ug/3RkrPvjy4ulRMMt5/WC7iOsiTCPTNBveHjgWWEBxgKmw2SyiRDrVv14f8yDx6GqMY uO80ioKszCEF72B6Fg0+Rv0kIGQqvh29iUsPvS9LUkk/PQkKaxN7fWKvCOE2m5o+EBiN xOYoZ1yrVQt9m3C1rvsUB8dw/l7SBfGK5nxTV60WQO7lIhU/eSZL3sbjbCTqx9QDiNYY /zOg== X-Gm-Message-State: AOJu0YympxEvO3pTzw+uQRdRRJJq7OwsW6lfkZ9YOgMT8qqaGlwhycre fawmauVG/qhGkE+fjic60DMEzc6iLpQheXTN X-Google-Smtp-Source: AGHT+IF9sdUPmLqm+ZlJMWp96z/Kt4+IDWlhFua8Z4LNiAlk09X9pzqB6x/yhsoFxvbGdZPkQmD1iw== X-Received: by 2002:a05:600c:d7:b0:3fb:b5dc:dab1 with SMTP id u23-20020a05600c00d700b003fbb5dcdab1mr49248wmm.39.1691609056628; Wed, 09 Aug 2023 12:24:16 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id y9-20020a7bcd89000000b003fba6a0c881sm2776208wmj.43.2023.08.09.12.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 12:24:16 -0700 (PDT) From: Benjamin Bara Date: Wed, 09 Aug 2023 21:24:03 +0200 Subject: [PATCH v2 1/6] kernel/reboot: distinguish between cold and warm MIME-Version: 1.0 Message-Id: <20230809-pca9450-reboot-v2-1-b98b4f8139d5@skidata.com> References: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> In-Reply-To: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> To: Lee Jones , Thierry Reding , Jonathan Hunter , Tony Lindgren , Liam Girdwood , Mark Brown , Dmitry Osipenko , peng.fan@oss.nxp.com, rafael.j.wysocki@intel.com, Jerome Neanne Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benjamin Bara Currently, the kernel is not aware if the registered reboot handler is a cold/hard or warm/soft one. However, there exists a 'reboot_mode' kernel parameter which can be used to specify the type of reboot the kernel should use. This parameter is currently not very well supported, due to the lack of distinction possibilities. Instead, cold/hard reboot handlers are often registered with a higher priorization to indicate the kernel to prefer these over others. With a proper distinction possibility, the reboot_mode kernel parameter can be respected in a much simpler way. Additionally, a warning can be shown if no proper reboot handler is implemented. Due to the priorization of cold/hard reboot handlers, these are preferred implicitly and therefore the registration helper can be used instead. The "unspecified" handlers are still supported, as they are registered as "soft reboots" and are therefore called as fallback. Signed-off-by: Benjamin Bara --- v2: - fallback to warm handler if hard/cold restart requested but failed - improve commit message --- include/linux/reboot.h | 22 ++++++++++++ kernel/reboot.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 110 insertions(+), 6 deletions(-) diff --git a/include/linux/reboot.h b/include/linux/reboot.h index 2b6bb593be5b..05199aedb696 100644 --- a/include/linux/reboot.h +++ b/include/linux/reboot.h @@ -119,6 +119,20 @@ enum sys_off_mode { * Handlers restart system. Handlers are disallowed to sleep. */ SYS_OFF_MODE_RESTART, + + /** + * @SYS_OFF_MODE_RESTART_COLD: + * + * Handlers cold restart system. Handlers are disallowed to sleep. + */ + SYS_OFF_MODE_RESTART_COLD, + + /** + * @SYS_OFF_MODE_RESTART_WARM: + * + * Handlers warm restart system. Handlers are disallowed to sleep. + */ + SYS_OFF_MODE_RESTART_WARM, }; /** @@ -157,6 +171,14 @@ int devm_register_restart_handler(struct device *dev, int (*callback)(struct sys_off_data *data), void *cb_data); +int devm_register_cold_restart_handler(struct device *dev, + int (*callback)(struct sys_off_data *data), + void *cb_data); + +int devm_register_warm_restart_handler(struct device *dev, + int (*callback)(struct sys_off_data *data), + void *cb_data); + int register_platform_power_off(void (*power_off)(void)); void unregister_platform_power_off(void (*power_off)(void)); diff --git a/kernel/reboot.c b/kernel/reboot.c index 3bba88c7ffc6..ab99f450801f 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -146,9 +146,15 @@ EXPORT_SYMBOL(devm_register_reboot_notifier); /* * Notifier list for kernel code which wants to be called - * to restart the system. + * to cold restart the system. */ -static ATOMIC_NOTIFIER_HEAD(restart_handler_list); +static ATOMIC_NOTIFIER_HEAD(cold_restart_handler_list); + +/* + * Notifier list for kernel code which wants to be called + * to warm restart the system. + */ +static ATOMIC_NOTIFIER_HEAD(warm_restart_handler_list); /** * register_restart_handler - Register function to be called to reset @@ -190,7 +196,11 @@ static ATOMIC_NOTIFIER_HEAD(restart_handler_list); */ int register_restart_handler(struct notifier_block *nb) { - return atomic_notifier_chain_register(&restart_handler_list, nb); + /* + * Store all non-devm-based handlers in the warm list to ensure that the + * "specified" handler are preferred over the "unspecified" ones. + */ + return atomic_notifier_chain_register(&warm_restart_handler_list, nb); } EXPORT_SYMBOL(register_restart_handler); @@ -205,7 +215,14 @@ EXPORT_SYMBOL(register_restart_handler); */ int unregister_restart_handler(struct notifier_block *nb) { - return atomic_notifier_chain_unregister(&restart_handler_list, nb); + int ret; + + ret = atomic_notifier_chain_unregister(&warm_restart_handler_list, nb); + if (ret == -ENOENT) + ret = atomic_notifier_chain_unregister(&cold_restart_handler_list, + nb); + + return ret; } EXPORT_SYMBOL(unregister_restart_handler); @@ -222,7 +239,20 @@ EXPORT_SYMBOL(unregister_restart_handler); */ void do_kernel_restart(char *cmd) { - atomic_notifier_call_chain(&restart_handler_list, reboot_mode, cmd); + /* + * REBOOT_GPIO can be either cold or warm -> let handler decide. + * Prefer cold reboot if mode not specified. + */ + if (reboot_mode == REBOOT_UNDEFINED || reboot_mode == REBOOT_GPIO || + reboot_mode == REBOOT_HARD || reboot_mode == REBOOT_COLD) { + atomic_notifier_call_chain(&cold_restart_handler_list, + reboot_mode, cmd); + if (reboot_mode == REBOOT_HARD || reboot_mode == REBOOT_COLD) + pr_emerg("hard/cold reboot failed, fallback!\n"); + } + + /* Always execute warm handler as fallback */ + atomic_notifier_call_chain(&warm_restart_handler_list, reboot_mode, cmd); } void migrate_to_reboot_cpu(void) @@ -414,7 +444,15 @@ register_sys_off_handler(enum sys_off_mode mode, break; case SYS_OFF_MODE_RESTART: - handler->list = &restart_handler_list; + handler->list = &warm_restart_handler_list; + break; + + case SYS_OFF_MODE_RESTART_COLD: + handler->list = &cold_restart_handler_list; + break; + + case SYS_OFF_MODE_RESTART_WARM: + handler->list = &warm_restart_handler_list; break; default: @@ -560,6 +598,50 @@ int devm_register_restart_handler(struct device *dev, } EXPORT_SYMBOL_GPL(devm_register_restart_handler); +/** + * devm_register_cold_restart_handler - Register cold restart handler + * @dev: Device that registers callback + * @callback: Callback function + * @cb_data: Callback's argument + * + * Registers resource-managed sys-off handler with a default priority + * and using cold restart mode. + * + * Returns zero on success, or error code on failure. + */ +int devm_register_cold_restart_handler(struct device *dev, + int (*callback)(struct sys_off_data *data), + void *cb_data) +{ + return devm_register_sys_off_handler(dev, + SYS_OFF_MODE_RESTART_COLD, + SYS_OFF_PRIO_DEFAULT, + callback, cb_data); +} +EXPORT_SYMBOL_GPL(devm_register_cold_restart_handler); + +/** + * devm_register_warm_restart_handler - Register warm restart handler + * @dev: Device that registers callback + * @callback: Callback function + * @cb_data: Callback's argument + * + * Registers resource-managed sys-off handler with a default priority + * and using warm restart mode. + * + * Returns zero on success, or error code on failure. + */ +int devm_register_warm_restart_handler(struct device *dev, + int (*callback)(struct sys_off_data *data), + void *cb_data) +{ + return devm_register_sys_off_handler(dev, + SYS_OFF_MODE_RESTART_WARM, + SYS_OFF_PRIO_DEFAULT, + callback, cb_data); +} +EXPORT_SYMBOL_GPL(devm_register_warm_restart_handler); + static struct sys_off_handler *platform_power_off_handler; static int platform_power_off_notify(struct sys_off_data *data) From patchwork Wed Aug 9 19:24:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 712493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81B8CC04FDF for ; Wed, 9 Aug 2023 19:25:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233883AbjHITZi (ORCPT ); Wed, 9 Aug 2023 15:25:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233830AbjHITZX (ORCPT ); Wed, 9 Aug 2023 15:25:23 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28A771FCC; Wed, 9 Aug 2023 12:24:19 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe5eb84d8bso827625e9.2; Wed, 09 Aug 2023 12:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691609057; x=1692213857; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RfpbtjdcJpv0XZl6JBXl9uzE/kd/OCEJbio5jgIS0e8=; b=V8jffcHw146lNX+gH7aQ6rqWlq+TggBLwB3kM5kGUcBbBMC74bg0vz3qO1G4PUCdX4 piPE70n6PcVNaQ+LgQLW5qApXsEI+n1IpuHXF8fOpgOsDydJdVfAovVKDSLg2weGs4jm 8oGhg/BX7IoHEA4JLU5cZfgWMVUj8vsCE23Sst3Ktsjf/l8v73sWxQhecK62nHZXJfMr Erg5ywfdR88f7k6jSnWAx3JNk2eMN6f8V9juMA/PRV0CWXmYlqkTUVvRT3udiAiIeRjg cci8n4NZ0iyjn/kUwigB4sm2eZfdfDrb8oq5em642viUVpN5wm7at+3LGeCyNmZff0oJ WE0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691609057; x=1692213857; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RfpbtjdcJpv0XZl6JBXl9uzE/kd/OCEJbio5jgIS0e8=; b=YGbhyGnH+raOrRYGrM0JznkR7laLjfAJckdN9Nte9xm4jvRPgpPg62qQXSsJEcg5Kq B9kW/ONs4NSF63YlF83J3C9B6Ui6+fvqCSzWTJnxiDm+taW8SGYCfyIDU8o/8fMpwv4S +4f6cm1fnpb1azW2XtSSk2f7GWZRNS8I35TpZRhgfIXlhp5T/idmUAJOQdJyMTtMZKI7 dFFs99UvK5WHrXSxhh/StKukgvwbfcTf4qH8JA/OVI9NdycM/zM8Ykn3ed3RHOj4sGNm +GJ2+C1PcVMNiRJLyJUDJhGo1SdgovPoMoFdgpwRV2anVrBSUFlpZq/mjY74brdKtmRy hFbg== X-Gm-Message-State: AOJu0YxE6x/FT5oED3fVwU9h8dxTQRgmo6OW272XTcclPcGTTrZPduRb qfqCXD5EXBnhY0rqFVAY8OM= X-Google-Smtp-Source: AGHT+IHDL05waSU4g7vB3tCasXp+dwqLWXUXoRWv+YR+q28V9nA9kHHezq781zwZk0LSTjWPM5OreA== X-Received: by 2002:a05:600c:260d:b0:3f9:82f:bad1 with SMTP id h13-20020a05600c260d00b003f9082fbad1mr41677wma.40.1691609057577; Wed, 09 Aug 2023 12:24:17 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id y9-20020a7bcd89000000b003fba6a0c881sm2776208wmj.43.2023.08.09.12.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 12:24:17 -0700 (PDT) From: Benjamin Bara Date: Wed, 09 Aug 2023 21:24:04 +0200 Subject: [PATCH v2 2/6] mfd: rk8xx: Specify restart mode MIME-Version: 1.0 Message-Id: <20230809-pca9450-reboot-v2-2-b98b4f8139d5@skidata.com> References: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> In-Reply-To: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> To: Lee Jones , Thierry Reding , Jonathan Hunter , Tony Lindgren , Liam Girdwood , Mark Brown , Dmitry Osipenko , peng.fan@oss.nxp.com, rafael.j.wysocki@intel.com, Jerome Neanne Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benjamin Bara The current restart handler registration does not specify whether the restart is a cold or a warm one. Instead, cold ones are typically registered with a HIGH prio. Now, as do_kernel_restart() knows about the type, the priorization is implicitly done (cold restarts are executed first) and the reboot_mode kernel parameter (which is currently mostly ignored) can be respected. Signed-off-by: Benjamin Bara --- v2: - improve commit message - use registration helper instead --- drivers/mfd/rk8xx-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mfd/rk8xx-core.c b/drivers/mfd/rk8xx-core.c index 11a831e92da8..7faf8e1189f7 100644 --- a/drivers/mfd/rk8xx-core.c +++ b/drivers/mfd/rk8xx-core.c @@ -696,9 +696,9 @@ int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap switch (rk808->variant) { case RK809_ID: case RK817_ID: - ret = devm_register_sys_off_handler(dev, - SYS_OFF_MODE_RESTART, SYS_OFF_PRIO_HIGH, - &rk808_restart, rk808); + ret = devm_register_cold_restart_handler(dev, + &rk808_restart, + rk808); if (ret) dev_warn(dev, "failed to register rst handler, %d\n", ret); break; From patchwork Wed Aug 9 19:24:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 712194 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AC82C001E0 for ; Wed, 9 Aug 2023 19:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234013AbjHITZj (ORCPT ); Wed, 9 Aug 2023 15:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232708AbjHITZX (ORCPT ); Wed, 9 Aug 2023 15:25:23 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F636469B; Wed, 9 Aug 2023 12:24:20 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fe45481edfso978265e9.1; Wed, 09 Aug 2023 12:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691609059; x=1692213859; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=4s4F1OhGM2F2vHHKOW1vWDCfOxzfDUM3DsLfi6qRr88=; b=I6x+QXcY+cv6IfbN56TTUsFWUztfXPH1E4RBbTtT7alc3mS6dkT3mjKmCRHcTdd8+x 23RAyjDQBffMot+VZaj+tkawmDtro1SB2yjrDWxwI8ALA2oBJcOC9YbjIU7l2RQrzB4L HVlM+QEL5pQPNzXXg6u8N35KcXbEvmpSlU+gc79wul/x4iysTSzVzS8qo7kfoagW20un 1eK2MQ7ovTmVXIiC00kIsdn3ZBODVGosd8QKz5mE7VesM+wUvfD9xG4+yZbCUBZpdstQ XDl/3kzOmB7/MxyE5etlHLBOnWIF2Prd/6vY4EUG1XCILi1DhDPUJ6JiJEx2TvwCf/eb Z3OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691609059; x=1692213859; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4s4F1OhGM2F2vHHKOW1vWDCfOxzfDUM3DsLfi6qRr88=; b=L+VhTz9I2314bdlBN56nM9b99eHtxUkqdv3EAKYAr834g6sXmkP04oWAKgx4OnhJPS 4Ph1qE9CRG1Um/CudQfOGSvmIR4m2gDH4ipJDyigTp6oIrY5QkGa9LTpki1o7uqDnNnL YB/7fwHLCinLxKQWV5FZgUgVX4TQ1VGuWJ9ySTBf4VCMhl57NymNPy08c3I0+SE+Sufl w/0j8jzguhodDqYWo4Bxyz2xzJWM2z4LaTzXH1aWa2+AkLhyUtBUTVEFaAxnaOYeiIuH UY4s2ORWi4KGryuxsyNl8XelxzHHYbzrMeNxSB50iP9KlVWFD5svj7pZx1B3fvQISpZ/ 9ALg== X-Gm-Message-State: AOJu0YxUbH/0c6cFcOUDx7asW5IMWMZg4U0xZM3Ym/VD0/k6aNOVvSbQ TUwczFk4r5i6vivqei74Q7o= X-Google-Smtp-Source: AGHT+IGyKI26UZBMakZWSxNTY6XyqLZrn/T3u3x76uCrOLrwG3nqvBNVjn9MrLn7Kr5wTskrKIXcUQ== X-Received: by 2002:a7b:c859:0:b0:3fe:4cbc:c34c with SMTP id c25-20020a7bc859000000b003fe4cbcc34cmr71618wml.24.1691609058434; Wed, 09 Aug 2023 12:24:18 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id y9-20020a7bcd89000000b003fba6a0c881sm2776208wmj.43.2023.08.09.12.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 12:24:18 -0700 (PDT) From: Benjamin Bara Date: Wed, 09 Aug 2023 21:24:05 +0200 Subject: [PATCH v2 3/6] soc/tegra: pmc: Specify restart mode MIME-Version: 1.0 Message-Id: <20230809-pca9450-reboot-v2-3-b98b4f8139d5@skidata.com> References: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> In-Reply-To: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> To: Lee Jones , Thierry Reding , Jonathan Hunter , Tony Lindgren , Liam Girdwood , Mark Brown , Dmitry Osipenko , peng.fan@oss.nxp.com, rafael.j.wysocki@intel.com, Jerome Neanne Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org, Benjamin Bara , Thierry Reding X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benjamin Bara The current restart handler registration does not specify whether the restart is a cold or a warm one. Now, as do_kernel_restart() knows about the type, the priorization is implicitly done (cold restarts are executed first) and the reboot_mode kernel parameter (which is currently mostly ignored) can be respected. Acked-by: Thierry Reding Signed-off-by: Benjamin Bara --- v2: - improve commit message --- drivers/soc/tegra/pmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c index 162f52456f65..4f42febb9b0f 100644 --- a/drivers/soc/tegra/pmc.c +++ b/drivers/soc/tegra/pmc.c @@ -2962,7 +2962,7 @@ static int tegra_pmc_probe(struct platform_device *pdev) } err = devm_register_sys_off_handler(&pdev->dev, - SYS_OFF_MODE_RESTART, + SYS_OFF_MODE_RESTART_WARM, SYS_OFF_PRIO_LOW, tegra_pmc_restart_handler, NULL); if (err) { From patchwork Wed Aug 9 19:24:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 712492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9645AC04FE0 for ; Wed, 9 Aug 2023 19:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234016AbjHITZk (ORCPT ); Wed, 9 Aug 2023 15:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233898AbjHITZY (ORCPT ); Wed, 9 Aug 2023 15:25:24 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD3BC469E; Wed, 9 Aug 2023 12:24:20 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe5695b180so766935e9.2; Wed, 09 Aug 2023 12:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691609059; x=1692213859; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NOt3f0g945aFYg2SZ1NDdkMZ84STg236RQcHRWkmfW4=; b=DDxHxGri9oTwwqQwxsLMJqYtCmUXCLVfQoRKZz019EmDezDldAKtMoovGpHPw18Cij kacubnX0HtFxd4gkNqKf8/U5wpskoEnAhPCz+QOzUbSU/JpdhiBDifGYzNKjgc8/ScQW 69XA5ko2MvMS7GvlH+7Kcrja2Rmvk+7uop7dqjsUHzuEaokiGltfvELY/ix+9eB31gnH SQLapLpNtncXGyRFJ4Li/0QieX7e+oELRtK3ob01DFE1zO3cLpN2tqRgJEf4wUXmgNLi PSRwaMso4L8hTrnxaY2qT+CIqT+St+erwxgFJYev+adnvNfe3v+OKarePCYEfLhs43I6 +zMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691609059; x=1692213859; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NOt3f0g945aFYg2SZ1NDdkMZ84STg236RQcHRWkmfW4=; b=Opl+kM8SS7/oagBVm9oF0fJlHVTMDm8JwMnFH/Q3FSLr9QlozSpfd402LtmytYY2fD sFvncnYdRPk3p5OMgBGJyroXHKSI6PBkB3HRMv8J/D3pOs1eorGX2nvx1VSunq057Bau PwxJRh/NHtd6Z0B4u1OVbPzeO7ubyoJ7qyVImEaSnef78FX/eHodAl6SPdthU6uKweo+ t8wMrfLu812R6BKcpzTrH0Zw9Uj9HhoEydItW6e3ap+LX9rBJNlC9/Hnv8db6ivWK1nP +A6ehPTbZVEJZiSY/Cu5zpSKgzPIziW+qmcJSBaZI2baMgh/TnHGGEYX03s1IE2u6F/+ jq+Q== X-Gm-Message-State: AOJu0YzrjB/aor98j7sxabzOlvEcNIJDONU4MKznaSwmDHqIzMSXLqd3 mMbJqsUwy65NPVbuYc7sVoQ= X-Google-Smtp-Source: AGHT+IGYDpYRjob4tooKsa/vmj8iJrlfXsjhMGhyvtXGpMeKV4q7qO3jSQCFZ3uzukh96mh6T745DA== X-Received: by 2002:a05:600c:3641:b0:3fb:e189:3532 with SMTP id y1-20020a05600c364100b003fbe1893532mr63223wmq.20.1691609059385; Wed, 09 Aug 2023 12:24:19 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id y9-20020a7bcd89000000b003fba6a0c881sm2776208wmj.43.2023.08.09.12.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 12:24:19 -0700 (PDT) From: Benjamin Bara Date: Wed, 09 Aug 2023 21:24:06 +0200 Subject: [PATCH v2 4/6] mfd: tps65219: Specify restart mode MIME-Version: 1.0 Message-Id: <20230809-pca9450-reboot-v2-4-b98b4f8139d5@skidata.com> References: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> In-Reply-To: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> To: Lee Jones , Thierry Reding , Jonathan Hunter , Tony Lindgren , Liam Girdwood , Mark Brown , Dmitry Osipenko , peng.fan@oss.nxp.com, rafael.j.wysocki@intel.com, Jerome Neanne Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benjamin Bara The current restart handler registration does not specify whether the restart is a cold or a warm one. Instead, cold ones are typically registered with a HIGH prio. Now, as do_kernel_restart() knows about the type, the priorization is implicitly done (cold restarts are executed first) and the reboot_mode kernel parameter (which is currently mostly ignored) can be respected. Signed-off-by: Benjamin Bara --- v2: - improve commit message --- drivers/mfd/tps65219.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c index 0e0c42e4fdfc..85752b93256e 100644 --- a/drivers/mfd/tps65219.c +++ b/drivers/mfd/tps65219.c @@ -278,12 +278,21 @@ static int tps65219_probe(struct i2c_client *client) } } - ret = devm_register_restart_handler(tps->dev, - tps65219_restart_handler, - tps); + ret = devm_register_cold_restart_handler(tps->dev, + tps65219_restart_handler, + tps); if (ret) { - dev_err(tps->dev, "cannot register restart handler, %d\n", ret); + dev_err(tps->dev, "cannot register cold restart handler, %d\n", ret); + return ret; + } + + ret = devm_register_warm_restart_handler(tps->dev, + tps65219_restart_handler, + tps); + + if (ret) { + dev_err(tps->dev, "cannot register warm restart handler, %d\n", ret); return ret; } From patchwork Wed Aug 9 19:24:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 712491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0306C04A94 for ; Wed, 9 Aug 2023 19:25:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233988AbjHITZy (ORCPT ); Wed, 9 Aug 2023 15:25:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233946AbjHITZZ (ORCPT ); Wed, 9 Aug 2023 15:25:25 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B61C726AF; Wed, 9 Aug 2023 12:24:21 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fbea147034so980945e9.0; Wed, 09 Aug 2023 12:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691609060; x=1692213860; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=xNX6lDzJ0d718pSUe3xwW15aLLHHaMX3WIRGJs7J7yY=; b=R/R2f7Iha4oTPdSdqqRn/3phuO4mni0vOveqNYB1NVGlZjBijaLLQZxgWmytPyL2st ou6ZC5u8fyw6dRVhEg1TsKQLDJ5QtcPsoqneF9C0EuAtIwv8KJjAFfFVHNworkkfxLKC XFp9SSVKs6WO7od8DXC65Q5pTBmHVAugrYAyj1m8R5G2gCvnFZe/IMadhvPpVMzI5FW9 5T6Ifwbr4+M/EnzKhBfcDRgTS61hIYNcnSH1BKEp+eZr1idBcem+LjLp4E/SXzdGE2D7 Qqr4f20Zs83fBPauWNao0OaewHVzsoGcKGVPP3qe8o9GFN70vNeOtd2Kp158hek0aPJN 57JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691609060; x=1692213860; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xNX6lDzJ0d718pSUe3xwW15aLLHHaMX3WIRGJs7J7yY=; b=BiDvLOxZQil9Ac2oBOKyUKq78Ik6DsLNFhrWj5rgDYLzUNXj+MAsljBUYAwJDUGTne UoCv/F3hhNYTkIuPlr4NTZEfGit1Le2wvkYlSxxM+Jwu1F1iB9Fkz9pSD5bCfgmANg3G fPHheBJE1D1Am7Zpl+bGmt+EACQvxPKWGn5MEJJDU+0ehyzVtiobPgdzh1RM6SMEzXe6 jY/AcrYbJmAU0rKD7zMI7+I1PNt8HfMxGWiAzaMd2FlBffMa2ptnQGNH/Cd6UIDfhCOm huQiqXLV65cVpBmu06MRp+B0nfVxPtP6MXBCtAQ1IIUhKDuZX2Lv7H7iBNMAFCsmeSmZ RwmQ== X-Gm-Message-State: AOJu0YwyTeaxXCJMheQN8XeQKLqZlkEc030rkXDauB8i5Z3whBKto+Hh 5eSrBTRUlJXT2LZYb5YfoRE= X-Google-Smtp-Source: AGHT+IFpvId/KSK9vwzsmZMrX1Bn3EG+ercdKy6bm7+DDu9KUQFGsg/7todXUV/CbQjKKTbeQ5FiVQ== X-Received: by 2002:a05:600c:2307:b0:3fe:2463:2614 with SMTP id 7-20020a05600c230700b003fe24632614mr66196wmo.24.1691609060144; Wed, 09 Aug 2023 12:24:20 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id y9-20020a7bcd89000000b003fba6a0c881sm2776208wmj.43.2023.08.09.12.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 12:24:19 -0700 (PDT) From: Benjamin Bara Date: Wed, 09 Aug 2023 21:24:07 +0200 Subject: [PATCH v2 5/6] kernel/reboot: remove generic restart mode MIME-Version: 1.0 Message-Id: <20230809-pca9450-reboot-v2-5-b98b4f8139d5@skidata.com> References: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> In-Reply-To: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> To: Lee Jones , Thierry Reding , Jonathan Hunter , Tony Lindgren , Liam Girdwood , Mark Brown , Dmitry Osipenko , peng.fan@oss.nxp.com, rafael.j.wysocki@intel.com, Jerome Neanne Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benjamin Bara Remove the "unspecified" restart mode, as it is not in use anymore. New handler registrations should use the specified "cold" or "warm" instead. These respect the "reboot_mode" kernel parameter and enable implicit priorization (cold before warm) when the reboot_mode is unspecified. Signed-off-by: Benjamin Bara --- v2: - improve commit message --- include/linux/reboot.h | 11 ----------- kernel/reboot.c | 26 -------------------------- 2 files changed, 37 deletions(-) diff --git a/include/linux/reboot.h b/include/linux/reboot.h index 05199aedb696..ad1a7b4026c0 100644 --- a/include/linux/reboot.h +++ b/include/linux/reboot.h @@ -113,13 +113,6 @@ enum sys_off_mode { */ SYS_OFF_MODE_RESTART_PREPARE, - /** - * @SYS_OFF_MODE_RESTART: - * - * Handlers restart system. Handlers are disallowed to sleep. - */ - SYS_OFF_MODE_RESTART, - /** * @SYS_OFF_MODE_RESTART_COLD: * @@ -167,10 +160,6 @@ int devm_register_power_off_handler(struct device *dev, int (*callback)(struct sys_off_data *data), void *cb_data); -int devm_register_restart_handler(struct device *dev, - int (*callback)(struct sys_off_data *data), - void *cb_data); - int devm_register_cold_restart_handler(struct device *dev, int (*callback)(struct sys_off_data *data), void *cb_data); diff --git a/kernel/reboot.c b/kernel/reboot.c index ab99f450801f..af0e090dd087 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -443,10 +443,6 @@ register_sys_off_handler(enum sys_off_mode mode, handler->blocking = true; break; - case SYS_OFF_MODE_RESTART: - handler->list = &warm_restart_handler_list; - break; - case SYS_OFF_MODE_RESTART_COLD: handler->list = &cold_restart_handler_list; break; @@ -576,28 +572,6 @@ int devm_register_power_off_handler(struct device *dev, } EXPORT_SYMBOL_GPL(devm_register_power_off_handler); -/** - * devm_register_restart_handler - Register restart handler - * @dev: Device that registers callback - * @callback: Callback function - * @cb_data: Callback's argument - * - * Registers resource-managed sys-off handler with a default priority - * and using restart mode. - * - * Returns zero on success, or error code on failure. - */ -int devm_register_restart_handler(struct device *dev, - int (*callback)(struct sys_off_data *data), - void *cb_data) -{ - return devm_register_sys_off_handler(dev, - SYS_OFF_MODE_RESTART, - SYS_OFF_PRIO_DEFAULT, - callback, cb_data); -} -EXPORT_SYMBOL_GPL(devm_register_restart_handler); - /** * devm_register_cold_restart_handler - Register cold restart handler * @dev: Device that registers callback From patchwork Wed Aug 9 19:24:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 712193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BB25C001E0 for ; Wed, 9 Aug 2023 19:25:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234047AbjHITZx (ORCPT ); Wed, 9 Aug 2023 15:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233979AbjHITZZ (ORCPT ); Wed, 9 Aug 2023 15:25:25 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93E7F3C0B; Wed, 9 Aug 2023 12:24:22 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3fbea147034so981065e9.0; Wed, 09 Aug 2023 12:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691609061; x=1692213861; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pwigRAFAXBRS5qA8koF+a3Bv4bIxzklMHFE/MHDH5ok=; b=eve8xWI6YnHpUf/J5yzVBAv9L32VRTQu2RRy55ESICy3heLY5wjsRCBsUTwOV3DU5S RuCionFHq2S5hlamn5nk6ivk3p0gmVeJ+eCiq+Xqw7QaNzDlrYseRS9kV/CMGJj0NxFi sbdZfU7tnEQJeXq10+Gdoo2VA/PqCsQcWRKfWM42VjSwhxIHTIIVYQPCmxnMpVB87b8Y kCeVz9UkLYW5mE8Q6sDwY3Yarv0X9Nv6frMTlyQfQH0DwfK7d2c5WpiX3LFQyZGnWWOT SZW4itQ8mKpbTItkwF2hiWAD3pjZF/Dl96mgbqt4oPYTJhFU++j3nNXv4pI9+OknbFwN 3JfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691609061; x=1692213861; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pwigRAFAXBRS5qA8koF+a3Bv4bIxzklMHFE/MHDH5ok=; b=iTCml0erA9YB7UZgHTupKSQHYt86tAM17z/9sgSIhZSzIfRuUD4pO/dpXToXEdr6XL bDT+6Hh/7LrtSGDvWlaHdKw4p/faRt+V2025NwRxCYcs8FfmLXxz5Qe3XSHIcnjHuhVS 0rGkxnBCzhlaggWm0xKpvv3oEtbKLTRVDB0hBizuwg3QxNdBRM5D+ycmFOqMY+lp70AQ sPa7dB5DLrb7q48uWirL+Nplipwer7A16oYolN2wyuEbwiVdRKuB0T43SNHg498OlteL ct3j5ONnXBvFpC5k2T8SGHB5g+YAGS5UpIbCkX2eTrvs02+ok/D1eT5Rp1gc6Ox2N1Rc ypmw== X-Gm-Message-State: AOJu0YxVmmPpHDPqJDNcLqOecG5WhZaVF6lcmys3mJjfWOQo53ZO1L02 /F6ie9dlUvTKGe72hTysNa4= X-Google-Smtp-Source: AGHT+IH4yai+QveqDBLSuuppf6HAOS+JBSMVsO4zEnvYLlgX2iVgvxEkWco9vicnXKSN1lV+MYcEdg== X-Received: by 2002:a1c:7c0b:0:b0:3fd:e86b:f095 with SMTP id x11-20020a1c7c0b000000b003fde86bf095mr44652wmc.13.1691609060920; Wed, 09 Aug 2023 12:24:20 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id y9-20020a7bcd89000000b003fba6a0c881sm2776208wmj.43.2023.08.09.12.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 12:24:20 -0700 (PDT) From: Benjamin Bara Date: Wed, 09 Aug 2023 21:24:08 +0200 Subject: [PATCH v2 6/6] regulator: pca9450: register restart handlers MIME-Version: 1.0 Message-Id: <20230809-pca9450-reboot-v2-6-b98b4f8139d5@skidata.com> References: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> In-Reply-To: <20230809-pca9450-reboot-v2-0-b98b4f8139d5@skidata.com> To: Lee Jones , Thierry Reding , Jonathan Hunter , Tony Lindgren , Liam Girdwood , Mark Brown , Dmitry Osipenko , peng.fan@oss.nxp.com, rafael.j.wysocki@intel.com, Jerome Neanne Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Benjamin Bara The PCA9450 supports both, a warm and a cold reset. Implement both and register the respective handlers. Acked-by: Mark Brown Signed-off-by: Benjamin Bara --- drivers/regulator/pca9450-regulator.c | 59 +++++++++++++++++++++++++++++++++++ include/linux/regulator/pca9450.h | 7 +++++ 2 files changed, 66 insertions(+) diff --git a/drivers/regulator/pca9450-regulator.c b/drivers/regulator/pca9450-regulator.c index 2ab365d2749f..86903d677bf6 100644 --- a/drivers/regulator/pca9450-regulator.c +++ b/drivers/regulator/pca9450-regulator.c @@ -38,6 +38,11 @@ struct pca9450 { int irq; }; +static inline struct pca9450 *dev_to_pca9450(struct device *dev) +{ + return dev_get_drvdata(dev); +} + static const struct regmap_range pca9450_status_range = { .range_min = PCA9450_REG_INT1, .range_max = PCA9450_REG_PWRON_STAT, @@ -219,6 +224,42 @@ static int pca9450_set_dvs_levels(struct device_node *np, return ret; } +static int pca9450_cold_reset(struct pca9450 *pca9450) +{ + int ret; + + ret = regmap_write(pca9450->regmap, PCA9450_REG_SWRST, + SWRST_RESET_COLD_LDO12); + if (ret) + return ret; + + /* t_RESTART is 250 ms. */ + mdelay(500); + return -ETIME; +} + +static int pca9450_warm_reset(struct pca9450 *pca9450) +{ + int ret; + + ret = regmap_write(pca9450->regmap, PCA9450_REG_SWRST, + SWRST_RESET_WARM); + if (ret) + return ret; + + /* t_RESET is 20 ms. */ + mdelay(50); + return -ETIME; +} + +static int pca9450_restart_handler(struct sys_off_data *data) +{ + int (*handler)(struct pca9450 *) = data->cb_data; + struct pca9450 *pca9450 = dev_to_pca9450(data->dev); + + return handler(pca9450); +} + static const struct pca9450_regulator_desc pca9450a_regulators[] = { { .desc = { @@ -845,6 +886,24 @@ static int pca9450_i2c_probe(struct i2c_client *i2c) return PTR_ERR(pca9450->sd_vsel_gpio); } + ret = devm_register_cold_restart_handler(pca9450->dev, + pca9450_restart_handler, + pca9450_cold_reset); + if (ret) { + dev_err(&i2c->dev, "register cold restart handler failed: %d\n", + ret); + return ret; + } + + ret = devm_register_warm_restart_handler(pca9450->dev, + pca9450_restart_handler, + pca9450_warm_reset); + if (ret) { + dev_err(&i2c->dev, "register warm restart handler failed: %d\n", + ret); + return ret; + } + dev_info(&i2c->dev, "%s probed.\n", type == PCA9450_TYPE_PCA9450A ? "pca9450a" : "pca9450bc"); diff --git a/include/linux/regulator/pca9450.h b/include/linux/regulator/pca9450.h index 505c908dbb81..a72fd4942d5f 100644 --- a/include/linux/regulator/pca9450.h +++ b/include/linux/regulator/pca9450.h @@ -93,6 +93,13 @@ enum { PCA9450_MAX_REGISTER = 0x2F, }; +/* PCA9450 SW_RST bits */ +#define SWRST_NOACTION 0x00 +#define SWRST_RESET_REGS 0x05 +#define SWRST_RESET_COLD_LDO12 0x14 +#define SWRST_RESET_WARM 0x35 +#define SWRST_RESET_COLD 0x64 + /* PCA9450 BUCK ENMODE bits */ #define BUCK_ENMODE_OFF 0x00 #define BUCK_ENMODE_ONREQ 0x01