From patchwork Mon Mar 27 13:57:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 668018 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 5CE0AC77B62 for ; Mon, 27 Mar 2023 13:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232671AbjC0N6h (ORCPT ); Mon, 27 Mar 2023 09:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232806AbjC0N6Z (ORCPT ); Mon, 27 Mar 2023 09:58:25 -0400 Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D8F40C6; Mon, 27 Mar 2023 06:58:25 -0700 (PDT) Received: by mail-ua1-x933.google.com with SMTP id r7so6422367uaj.2; Mon, 27 Mar 2023 06:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679925504; 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=RbQS5zutEzfJYNaqkxdL9nLc8p49ExIzbuyhSxQJkfQ=; b=p5LsK61hvAoejly5RT/XyubS4vTQm18wYHk3CjXYFXxwe5WX8NNfuS7Dr+gaiJkmks tkTOXdg6tNNvzI0lITqEyBjFK3TjIT6dSnriLci/3Vj96A1VGpXj1UG3oh2YWpyewNI9 D6Z8tbVj+drESfGNNqNPucxVRUq0PqKP0crtiLdrbDq28wXsArvatYR8o7YB0bqa2LSk gb6Aqs5nulHXHo/GOZl4zXkr7bIbCwzGdLScArHGNYNM/5ZRhjm8v8grrl/m3TfdoMz7 7Gv1XJmoLRIPN0198jz3giDHmhJZPS5ozrhk0fbu3RBqfXxgEJ3PaW32WXmRrFc1iq5i fUjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679925504; 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=RbQS5zutEzfJYNaqkxdL9nLc8p49ExIzbuyhSxQJkfQ=; b=Sb8GRT7XkIR0g69wStEboFMNTzqwlsSg+tWIxdNzZGl+Xn4m7Jj6+aIh5azBxWkPmZ KAC9J1DB1alHlZ5dY3yeqMEZQeYvbh0ha2jyTruPRWNuzyfGqpMmPYBaanHlXlBvMwE6 9iwZQ79fNutVyoCg/6pMHGX/c4kJw25wmqKAIHt7cpaie7MYYXfedrovXN0gWnp+/nPA D93ahTmoxO7caDXvhs6AQeODOUOlWQ1o4dW4yId1JZuXOSV1mLmG0n3UZwifJWVpQXkD gyD1M/CJAH2FxAAwdXiZMAPq89I70AbSlM3Q31POjJHmEl1x/dJfdNIVDZjrK6C+cE+g Lm2g== X-Gm-Message-State: AAQBX9dn1/VBg3/GirkIlFCDkr8yRoMfx7p0Ui2oEjo6k/1F43LKuscD YNjXZYTyKFpqNbu+bIfFBb0= X-Google-Smtp-Source: AKy350ZiGz6J6WdYGaWwBybCjOYrebAiX4r6AxIV7zwim3JCF77bw+CD865zxEPZs31aNSsbUPWBDg== X-Received: by 2002:a05:6122:1801:b0:432:6c1:3aa8 with SMTP id ay1-20020a056122180100b0043206c13aa8mr4715979vkb.16.1679925504296; Mon, 27 Mar 2023 06:58:24 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id 135-20020a1f198d000000b004367f3393b8sm2731072vkz.28.2023.03.27.06.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 06:58:24 -0700 (PDT) From: Benjamin Bara Date: Mon, 27 Mar 2023 15:57:43 +0200 Subject: [PATCH v3 1/4] kernel/reboot: emergency_restart: set correct system_state MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v3-1-3c0ee3567e14@skidata.com> References: <20230327-tegra-pmic-reboot-v3-0-3c0ee3567e14@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v3-0-3c0ee3567e14@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, jonathanh@nvidia.com, richard.leitner@linux.dev, treding@nvidia.com, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, Benjamin Bara , stable@vger.kernel.org X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Benjamin Bara As the emergency restart does not call kernel_restart_prepare(), the system_state stays in SYSTEM_RUNNING. This e.g. hinders i2c_in_atomic_xfer_mode() from becoming active, and therefore might lead to avoidable warnings in the restart handlers, e.g.: [ 12.667612] WARNING: CPU: 1 PID: 1 at kernel/rcu/tree_plugin.h:318 rcu_note_context_switch+0x33c/0x6b0 [ 12.676926] Voluntary context switch within RCU read-side critical section! ... [ 12.742376] schedule_timeout from wait_for_completion_timeout+0x90/0x114 [ 12.749179] wait_for_completion_timeout from tegra_i2c_wait_completion+0x40/0x70 ... [ 12.994527] atomic_notifier_call_chain from machine_restart+0x34/0x58 [ 13.001050] machine_restart from panic+0x2a8/0x32c Avoid these by setting the correct system_state. Cc: stable@vger.kernel.org # v5.2+ Signed-off-by: Benjamin Bara --- kernel/reboot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/reboot.c b/kernel/reboot.c index 3bba88c7ffc6..6ebef11c8876 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -74,6 +74,7 @@ void __weak (*pm_power_off)(void); void emergency_restart(void) { kmsg_dump(KMSG_DUMP_EMERG); + system_state = SYSTEM_RESTART; machine_emergency_restart(); } EXPORT_SYMBOL_GPL(emergency_restart); From patchwork Mon Mar 27 13:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 667676 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 B719BC77B74 for ; Mon, 27 Mar 2023 13:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbjC0N6i (ORCPT ); Mon, 27 Mar 2023 09:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232829AbjC0N62 (ORCPT ); Mon, 27 Mar 2023 09:58:28 -0400 Received: from mail-ua1-x931.google.com (mail-ua1-x931.google.com [IPv6:2607:f8b0:4864:20::931]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 825BE40C6; Mon, 27 Mar 2023 06:58:27 -0700 (PDT) Received: by mail-ua1-x931.google.com with SMTP id ay14so6371275uab.13; Mon, 27 Mar 2023 06:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679925506; 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=j6S8aoTE4XnnRICI4Cgexe87+BA2EHTmrbOrkOlGf2A=; b=MeGA2aX8swVDI8IPhdkrhlR6D4VrY8TSanhpNBzqCzAluqH7Vjsf475BEzj4Y68VU2 IK4fySExIoLx9D+GhhKkaXQ6N1/WHi8ztzvXxA/VQq3xxWmwQb9xoIS8sOqleTv2kqPa DoNVh+eFi0eEuToRiGZd62Mz3IuLc8s6GkCUppnLsptvxdoHaCv8+y6ClhW3ukmW3hqY nykWW6FKmy+nPRkRCQnwlIunRNqoxXR4lQLIed2JodP495nRWmn+6yq1H1PlBZqFhGL3 P/qB/deBFt3fGujcdWC6GWQDjwdDjr3n6iSybxJTnOB/051TO7XlTBwKZ5n6jHRPR8Gh dIFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679925506; 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=j6S8aoTE4XnnRICI4Cgexe87+BA2EHTmrbOrkOlGf2A=; b=D7hqRv2T3DPcdwi+RvBAtSkt+n+iguS0f4KDO5MG+tSH28hb6R99KKnY0v8SLr9x7K bv3EwIU30X0kSjIhXl4yVmXCHCQdlC1PfZkVr+MlYSUCltLQmivMrpdQ7Z18V8hq8rOG jsduEETX2bHtzoPB/kqXj7WqDnIQAgpZ1GIdX0XttnLYa6OGseZ/Isds5K00leTyuNSV EZV7g8hV1IesJd1Igl0VfQRs1xQp8aJ9Dx3ERy5mhIFw17EyjbeR+gJ/Bvuy0Ev9Eie7 0XHdeA8Cyg1p4REE5yyKSl5AkU8RWVAGOoyeOxQ6vI4bSuHMVrMf84bhxeQeeee58cFt nT3w== X-Gm-Message-State: AAQBX9cXtBWPLbij+kRZXWzjRvKZEqNifrYV6Kgr7x6wKctu/poKwDc4 0ai3OxV7X1yX6WdKT9L7caU= X-Google-Smtp-Source: AKy350ajpLrRrIpIks6kZM2w8ItRjpnPJgbVsTQao3G1CbHXQRwBqmUCijkqXBqAKVNgTKtScjYrxw== X-Received: by 2002:a05:6122:c9c:b0:436:ec6:8840 with SMTP id ba28-20020a0561220c9c00b004360ec68840mr4932371vkb.0.1679925506502; Mon, 27 Mar 2023 06:58:26 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id 135-20020a1f198d000000b004367f3393b8sm2731072vkz.28.2023.03.27.06.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 06:58:26 -0700 (PDT) From: Benjamin Bara Date: Mon, 27 Mar 2023 15:57:44 +0200 Subject: [PATCH v3 2/4] i2c: core: run atomic i2c xfer when !preemptible MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v3-2-3c0ee3567e14@skidata.com> References: <20230327-tegra-pmic-reboot-v3-0-3c0ee3567e14@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v3-0-3c0ee3567e14@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, jonathanh@nvidia.com, richard.leitner@linux.dev, treding@nvidia.com, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, Benjamin Bara , stable@vger.kernel.org X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Benjamin Bara A panic() calls preempt_disable_notrace() before calling emergency_restart(). If an i2c device is used for the restart, the xfer should not schedule out (to avoid warnings like): [ 12.667612] WARNING: CPU: 1 PID: 1 at kernel/rcu/tree_plugin.h:318 rcu_note_context_switch+0x33c/0x6b0 [ 12.676926] Voluntary context switch within RCU read-side critical section! ... [ 12.742376] schedule_timeout from wait_for_completion_timeout+0x90/0x114 [ 12.749179] wait_for_completion_timeout from tegra_i2c_wait_completion+0x40/0x70 ... [ 12.994527] atomic_notifier_call_chain from machine_restart+0x34/0x58 [ 13.001050] machine_restart from panic+0x2a8/0x32c Therefore, not only check for disabled IRQs but also for preemptible. Cc: stable@vger.kernel.org # v5.2+ Suggested-by: Dmitry Osipenko Signed-off-by: Benjamin Bara --- drivers/i2c/i2c-core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h index 1247e6e6e975..05b8b8dfa9bd 100644 --- a/drivers/i2c/i2c-core.h +++ b/drivers/i2c/i2c-core.h @@ -29,7 +29,7 @@ int i2c_dev_irq_from_resources(const struct resource *resources, */ static inline bool i2c_in_atomic_xfer_mode(void) { - return system_state > SYSTEM_RUNNING && irqs_disabled(); + return system_state > SYSTEM_RUNNING && !preemptible(); } static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap) From patchwork Mon Mar 27 13:57:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 668017 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 A5186C77B73 for ; Mon, 27 Mar 2023 13:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232769AbjC0N6j (ORCPT ); Mon, 27 Mar 2023 09:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232837AbjC0N6a (ORCPT ); Mon, 27 Mar 2023 09:58:30 -0400 Received: from mail-ua1-x931.google.com (mail-ua1-x931.google.com [IPv6:2607:f8b0:4864:20::931]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D4133C00; Mon, 27 Mar 2023 06:58:29 -0700 (PDT) Received: by mail-ua1-x931.google.com with SMTP id x33so6384153uaf.12; Mon, 27 Mar 2023 06:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679925508; 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=4y7RHA98qLuFsz3JDJ246X3y2mp8vITzNXl8/trhahM=; b=ZU3Q7yqm3khuYericsbX/ZLFoa+VkYN7jJ/hd2K7a/tsHtQL1wXdWXB5G1SOHvQz0p mLYVkYLSyXIS8rDGZXYxwJLGkOx2FWwpCmfltprEw+BJVa41VN1tx0/6uS3j2CehmlV9 /YNhEnEYC+ZyKk615/kc30FXLTu3gS92Lo+uhGTp6so65W4RPVwiURnGi1N4UO3DzMim pof11WsEPbsYXCYDPvvNDMRzC4dY3KZIzyNIXAbaESxPVkOajthID//wzFIYzTJG8B9h 6ayWKuZZCF5FgBMumEFXiUkHM/UJ8VZCWL9dDeUp8WN2GbzOS/9++HPj628UJKsxLvr7 1iew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679925508; 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=4y7RHA98qLuFsz3JDJ246X3y2mp8vITzNXl8/trhahM=; b=RNtCWPROywZgDxpoQDnRowet/qrA/omuhd7VXbfHOmVW4V5cdx2v9ZnzMF2jK7IOpP XBJIghsqS5JhjySooViXDrEr32BGhd9pZMuAKTYQeMLaKZUN9v9ObQFTMFEcJ2xiFfnY ofC8DhcOiOmHHYRa5V6iJrI4RN7djp3t/KDODgG10xLCMQFzC3ET0vRX6anXb8MWfEfZ YkYAnEzyoSMSdVgBoR2V1oFbb0kasqxpXOrVYOA+NAzrfO0dTfLNqwc2SawJG6orMv+J FPJrgy9HsuBHya3ejkHDwVCfbuRXLkR3riVUy5seBME8CyHSQOyg9PRyIATbjhsj1S// 9DHg== X-Gm-Message-State: AAQBX9fA+NdCLZhPfOg8SzBcYXf5Ks7ZFL8oGo26R0p0PY6vYbonlDTJ y8PnNiOEKt+KH04wUu/bCQQ= X-Google-Smtp-Source: AKy350bTpCZeZBYIJUxgULlpNIJsD9bEqu5L8bcdmiT8ZlfFx9c6w5QGgXyMp057jz2959mDdlOxhA== X-Received: by 2002:a05:6122:13b0:b0:435:e8a8:29e0 with SMTP id n16-20020a05612213b000b00435e8a829e0mr4364596vkp.6.1679925508575; Mon, 27 Mar 2023 06:58:28 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id 135-20020a1f198d000000b004367f3393b8sm2731072vkz.28.2023.03.27.06.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 06:58:28 -0700 (PDT) From: Benjamin Bara Date: Mon, 27 Mar 2023 15:57:45 +0200 Subject: [PATCH v3 3/4] mfd: tps6586x: use devm-based power off handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v3-3-3c0ee3567e14@skidata.com> References: <20230327-tegra-pmic-reboot-v3-0-3c0ee3567e14@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v3-0-3c0ee3567e14@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, jonathanh@nvidia.com, richard.leitner@linux.dev, treding@nvidia.com, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Benjamin Bara Convert the power off handler to a devm-based power off handler. Signed-off-by: Benjamin Bara Reviewed-by: Dmitry Osipenko --- drivers/mfd/tps6586x.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index 2d947f3f606a..93f1bf440191 100644 --- a/drivers/mfd/tps6586x.c +++ b/drivers/mfd/tps6586x.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -457,13 +458,16 @@ static const struct regmap_config tps6586x_regmap_config = { .cache_type = REGCACHE_RBTREE, }; -static struct device *tps6586x_dev; -static void tps6586x_power_off(void) +static int tps6586x_power_off_handler(struct sys_off_data *data) { - if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT)) - return; + struct device *tps6586x_dev = data->cb_data; + int ret; + + ret = tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT); + if (ret) + return ret; - tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT); + return tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT); } static void tps6586x_print_version(struct i2c_client *client, int version) @@ -559,9 +563,13 @@ static int tps6586x_i2c_probe(struct i2c_client *client) goto err_add_devs; } - if (pdata->pm_off && !pm_power_off) { - tps6586x_dev = &client->dev; - pm_power_off = tps6586x_power_off; + if (pdata->pm_off) { + ret = devm_register_power_off_handler(&client->dev, &tps6586x_power_off_handler, + &client->dev); + if (ret) { + dev_err(&client->dev, "register power off handler failed: %d\n", ret); + goto err_add_devs; + } } return 0; From patchwork Mon Mar 27 13:57:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 667675 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 F0EA5C77B75 for ; Mon, 27 Mar 2023 13:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232799AbjC0N6k (ORCPT ); Mon, 27 Mar 2023 09:58:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232838AbjC0N6b (ORCPT ); Mon, 27 Mar 2023 09:58:31 -0400 Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 127893C00; Mon, 27 Mar 2023 06:58:31 -0700 (PDT) Received: by mail-ua1-x933.google.com with SMTP id r7so6422635uaj.2; Mon, 27 Mar 2023 06:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679925510; 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=sJi9k0SusRoBJX6bd5XD9Ah+7FRBbKHs2NSnZLEQwl0=; b=focFGVZKHAYnSHwxsLeQfvbDZEaTLOe1a92lQloTQNCzqL0KziKQqfumOQid1ngq1m DPLBOccNhN1hVYHkj6kkRABsonQ7SvmLVsRZ/qlO8wVZLgNyQdB66P40BmhdwFJmwTYG WaQgY3aGPrLlY2DISHPTQgBlqHSLrlbuY9ZG5zhxMOHzOqre/iLhI/jjdFqWoCPsl9iZ a7OVWIYsgd1Xq8PWR655+4ClZveczP64UB4wl6Ifo/aoYwtkkVeWckK9CECKUo0H7vn1 eLYT7SYdIA2y3btczc/C1Ijr2BB1ZAPI7EPzluDxZ4eIR05VsUoD5CJbCp0n24CTRNek MOwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679925510; 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=sJi9k0SusRoBJX6bd5XD9Ah+7FRBbKHs2NSnZLEQwl0=; b=F48fZ6NjXhisHVj2caETCa0PywwX7xUIsjZMHOUyhl2dHt0P/Lf2x4myu8pX2AwS4V /W7J/odH2yTFeC4zCnKDiwoiV+LOGyrTQrehW/X6ieVq2Y9+eE1z8+8xVny42YAybSeQ NcYknq8cxqPnL3j/S6K8TYC7X4Xe7YbZvLvaK6JOrtzsBxeNaVDSSRB1pEVllg2DmZI/ TcZTP2Oz1w/WfB2c0Iv120p5MtClASjgeSzqQ2/5zyoOzZnV6+bWbBUtJIUNGqHKY4S3 h0SGOQmbdwd4a7vGGCc+YDZITdnF0iJfoL2V4Ud0US6g1dP2Ei4BUumfBucpE6y7Ivf6 c66g== X-Gm-Message-State: AAQBX9c6hCWHckot5pgQeZHyRLeQLQq7zWa4cArpYlCx/L8w+XwiGGVA X/ewaZs9go/0QK7dgtjkoV4= X-Google-Smtp-Source: AKy350ZyIcCs4NoQw4jqpwzxJW41AoFAtKNvyMHb4Ao/416i7Bz9wVzuOXP+8yFQwuuMe4CnC/ZPmw== X-Received: by 2002:a1f:6e4a:0:b0:403:23cb:4773 with SMTP id j71-20020a1f6e4a000000b0040323cb4773mr4238755vkc.2.1679925510654; Mon, 27 Mar 2023 06:58:30 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id 135-20020a1f198d000000b004367f3393b8sm2731072vkz.28.2023.03.27.06.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 06:58:30 -0700 (PDT) From: Benjamin Bara Date: Mon, 27 Mar 2023 15:57:46 +0200 Subject: [PATCH v3 4/4] mfd: tps6586x: register restart handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v3-4-3c0ee3567e14@skidata.com> References: <20230327-tegra-pmic-reboot-v3-0-3c0ee3567e14@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v3-0-3c0ee3567e14@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, jonathanh@nvidia.com, richard.leitner@linux.dev, treding@nvidia.com, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Benjamin Bara There are a couple of boards which use a tps6586x as "ti,system-power-controller", e.g. the tegra20-tamonten.dtsi. For these, the only registered restart handler is the warm reboot via tegra's PMC. As the bootloader of the tegra20 requires the VDE, it must be ensured that VDE is enabled (which is the case after a cold reboot). For the "normal reboot", this is basically the case since 8f0c714ad9be1ef774c98e8819a7a571451cb019. However, this workaround is not executed in case of an emergency restart. In case of an emergency restart, the system now simply hangs in the bootloader, as VDE is not enabled (as not in use). The TPS658629-Q1 (unfortunately the only TPS6586x with public data sheet) provides a SOFT RST bit in the SUPPLYENE reg to request a (cold) reboot. This avoids the hang-up. Tested on a TPS658640. Signed-off-by: Benjamin Bara --- drivers/mfd/tps6586x.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index 93f1bf440191..c8adf6a08277 100644 --- a/drivers/mfd/tps6586x.c +++ b/drivers/mfd/tps6586x.c @@ -30,6 +30,7 @@ #include #define TPS6586X_SUPPLYENE 0x14 +#define SOFT_RST_BIT BIT(0) #define EXITSLREQ_BIT BIT(1) #define SLEEP_MODE_BIT BIT(3) @@ -470,6 +471,17 @@ static int tps6586x_power_off_handler(struct sys_off_data *data) return tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT); } +static int tps6586x_restart_handler(struct sys_off_data *data) +{ + struct device *tps6586x_dev = data->cb_data; + + /* bring pmic into HARD REBOOT state */ + tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SOFT_RST_BIT); + + mdelay(500); + return 0; +} + static void tps6586x_print_version(struct i2c_client *client, int version) { const char *name; @@ -570,6 +582,13 @@ static int tps6586x_i2c_probe(struct i2c_client *client) dev_err(&client->dev, "register power off handler failed: %d\n", ret); goto err_add_devs; } + + ret = devm_register_restart_handler(&client->dev, &tps6586x_restart_handler, + &client->dev); + if (ret) { + dev_err(&client->dev, "register restart handler failed: %d\n", ret); + goto err_add_devs; + } } return 0;