From patchwork Tue Apr 18 11:10:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 1770070 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=OOrwxdJ+; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q11S43zjCz1ybC for ; Tue, 18 Apr 2023 21:10:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbjDRLKm (ORCPT ); Tue, 18 Apr 2023 07:10:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231258AbjDRLKj (ORCPT ); Tue, 18 Apr 2023 07:10:39 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5232F26AD; Tue, 18 Apr 2023 04:10:26 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a5so15607855ejb.6; Tue, 18 Apr 2023 04:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681816224; x=1684408224; 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=ClcmwgNB66OteygA0EuqrobbOiZGS0nq7YJHw1f4dDg=; b=OOrwxdJ+TptltfgKD7mdKkIfYgYrnRqhR5f1CHF0y/M/cOfoGgcypaJxvFgBGWCyMJ XiiKwzwdlRHbvaR9iZ9EL1Hr/bGOKMRXPsu+bnYu1VG1c1lEaphNWpAoEgtNWioZhElL i9CnT9jfNk0Y+DriIrt/bagd6+bkUhFg+U/z2kqaWju2YLt4/4lvo1Copw6hb1sxddKW QcuCU5vTjM5BsACMOz3PxcAT1swrk5VJ1eXCLnyJpcxGtExdTDJ2AzpFZkyCP2pQXRts 1tjDmmAlYVkNfhuGyoGlqXZBc70TgtmNWngQQ7x+Rww98Dyh9bwiCloZfg/hnCXq21sj 3A+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681816224; x=1684408224; 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=ClcmwgNB66OteygA0EuqrobbOiZGS0nq7YJHw1f4dDg=; b=AtQUxRBS+PL7CXK/9KnTUhC1PY+xtJjhzE8+Sw+a5ETgR+qtqs23DZLHvPMt7JK4Ew mI+azvezqiK58+8DYlNfgmEDIQlqkhlTo71bwHGDzHPGaBTB5cfvxYGpRaqaJw8qVYh7 zpzFCgMhySi8JJT8/+Pl7O2OhJZmageDmfcH19qxjUrElbK2tY6MW33rZYnpMwyKQ3+W TQW569LefCCQqRO+V4pW7/fTg1kjhYPIODmrm1V9AyZQNyae7fziArtBohc9h30OFudx fdIBfKFM6omg54FdopLAjRlEq7YhqYnJyYgqZbvIUxgWxS4H37R5kn6GgpOGel+5wTOW ItGQ== X-Gm-Message-State: AAQBX9d+qZ0XxjN9Szy5q6+7hsInmcmW2ZG64ObezJWVlpgw5kPH3KAw GjlG5eRGS67Y7aIT7HYtxNs35D1OET8s4Rkt X-Google-Smtp-Source: AKy350YUcWUslAB83rGB1sJiMcb3ESb7iU6P49FaB2iONWpAlFBAnGQY6ghGDMjz1mpDQHpmzUgnJw== X-Received: by 2002:a17:906:1354:b0:94f:6d10:ad9f with SMTP id x20-20020a170906135400b0094f6d10ad9fmr6280009ejb.42.1681816224592; Tue, 18 Apr 2023 04:10:24 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id n26-20020a170906379a00b0094eef800850sm5954554ejc.204.2023.04.18.04.10.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 04:10:24 -0700 (PDT) From: Benjamin Bara Date: Tue, 18 Apr 2023 13:10:00 +0200 Subject: [PATCH v5 1/6] kernel/reboot: emergency_restart: set correct system_state MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v5-1-ab090e03284d@skidata.com> References: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, peterz@infradead.org, 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Benjamin Bara As the emergency restart does not call kernel_restart_prepare(), the system_state stays in SYSTEM_RUNNING. Since bae1d3a05a8b, this 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. Fixes: bae1d3a05a8b ("i2c: core: remove use of in_atomic()") 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 Tue Apr 18 11:10:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 1770072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=WHN88Vc9; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q11SD6kqCz1ybC for ; Tue, 18 Apr 2023 21:10:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229721AbjDRLKv (ORCPT ); Tue, 18 Apr 2023 07:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbjDRLKl (ORCPT ); Tue, 18 Apr 2023 07:10:41 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 903D38A45; Tue, 18 Apr 2023 04:10:27 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id ud9so71931986ejc.7; Tue, 18 Apr 2023 04:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681816226; x=1684408226; 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=WbgVQUp/vUincJRkcsp/7lCVaCrW8ZOrNJHo4G9adBQ=; b=WHN88Vc9KjwSakLtGnGRxSGwAb5hfpAeWjrK647q2A6PsNe5izO5GzkcJPGI6sW6uj jB3D7Irqtyf8vjBNUGd/V5iWbc33CbakCySOYjxTRlG2vwGY74x31/Nrsu/rKr9/4xFT 92cYgR8Bh9Ety6g/cq9dARHDFOqjXBmeFGqwQdzNsTNwlv44D/61gPvXcw9MEUeIPOBS wmNeAvp4LasaHVBPseGpSDFceiHLT9vSdnbCtPtgmuDbOGE0vV4l0Ns3FXceRcZY8k9u WFml/gABit3ZGZtcXwQK9BvXEA+W1gI15Hf6JETIxj6FWY9QezjNL7mcKmYdE5zXwBEd 30ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681816226; x=1684408226; 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=WbgVQUp/vUincJRkcsp/7lCVaCrW8ZOrNJHo4G9adBQ=; b=LE/WloCH2Wq6UpxrwpBwpbVT9GjDzoIQA1LkdBGl3MHIIZoiERHioZI843jkUp7ctp U6QirwDGMN87AX0p//k7Y5E42FT00cwU2Xqsn+UpEOAoD5enL5D8hv9tP/pPXMBKmc8+ 2s2/BrT04GwS5H6hC24GJ7rN0nVR/qCpdvnQJQwDyH60pFN5EVgUlYs8xL1m7FA7fSR9 PYzzycwYW+3d6Kns7WB6OckL1xAxtOtG+PgwwsgOrTuW6cRP9R+4KESQwGF7LyS+OSEE A76zsn4j1wq62XUo4tM6xnmZGwgk7A9kSm6rSRZ2wzmrI1ORcTMU2pat8PSlmzmHQopz 0XSA== X-Gm-Message-State: AAQBX9doFR5taJzWOrrj5VECH8i9ZUAQGwqTj5h+qi1rD8EBYdXerspc 1fa8uNemTJwK/liJSD+VgsC2zsYT3BV/Mr4a X-Google-Smtp-Source: AKy350ZuIdjnhggkyP+eOiGXyizYmsnDJvuabPw9yGecpbmmPdEmaRx0JM48/q9ZC1e4KuZrdXMHYA== X-Received: by 2002:a17:906:240f:b0:94f:1a11:e08b with SMTP id z15-20020a170906240f00b0094f1a11e08bmr9336774eja.20.1681816225496; Tue, 18 Apr 2023 04:10:25 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id n26-20020a170906379a00b0094eef800850sm5954554ejc.204.2023.04.18.04.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 04:10:25 -0700 (PDT) From: Benjamin Bara Date: Tue, 18 Apr 2023 13:10:01 +0200 Subject: [PATCH v5 2/6] i2c: core: run atomic i2c xfer when !preemptible MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v5-2-ab090e03284d@skidata.com> References: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, peterz@infradead.org, 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Benjamin Bara Since bae1d3a05a8b, i2c transfers are non-atomic if preemption is disabled. However, non-atomic i2c transfers require preemption (e.g. in wait_for_completion() while waiting for the DMA). panic() calls preempt_disable_notrace() before calling emergency_restart(). Therefore, if an i2c device is used for the restart, the xfer should be atomic. This avoids 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 Use !preemptible() instead, which is basically the same check as pre-v5.2. Fixes: bae1d3a05a8b ("i2c: core: remove use of in_atomic()") Cc: stable@vger.kernel.org # v5.2+ Suggested-by: Dmitry Osipenko Acked-by: Wolfram Sang 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 Tue Apr 18 11:10:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 1770074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=dEWUK2L/; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q11SF68Gjz1ybC for ; Tue, 18 Apr 2023 21:10:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231258AbjDRLKx (ORCPT ); Tue, 18 Apr 2023 07:10:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231329AbjDRLKn (ORCPT ); Tue, 18 Apr 2023 07:10:43 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65DE27EE5; Tue, 18 Apr 2023 04:10:28 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id u3so20144661ejj.12; Tue, 18 Apr 2023 04:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681816226; x=1684408226; 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=bX5R8Ja4/uQ1bZhivXwMqgCiLJVs+CVwud3ONCpJxg4=; b=dEWUK2L/qiMDsvLULfsZ414bpwpYpTDmkHTWlleST4Bklyia1xTBu53xFuzjgyzmBD Rx63//4AOelp6qS8ms7b8XbegUpcKFr8f1Rl1RPaxCcBK/toaVjoAMoojmJRsczndzUx GDZPPOSRAeAKhFCszcWYxfQwYKU2CY+L7EfXaH72qAFdAuRSHl4OwBJYv5DqmTQh7NaT UhVISvzH5ILgN18fJtWr4PJaBNSDdtR+XyKDpvy7rb1TbvE5mO4V0BU+dqV1hfk1HgFw o2syFzneCf5xRlr2aqiF8peZnlIebzPsOWhDiRgcvkadPHN7w+aZHXan0q83MmVtEJbN wJDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681816226; x=1684408226; 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=bX5R8Ja4/uQ1bZhivXwMqgCiLJVs+CVwud3ONCpJxg4=; b=LjV7VqA5ZIdv6855NYpZg3tTT77X8qCvUd8HRwp1lPMh5SzvhQPM23WcO20E79prfV RyN6Y6UGOxV6k6l82Y7cs/Ru7qHb2ogLPdaByrJs/C/GjsdcnPWiqQRDxavDR5IMXR1X uVPAyOdGemlknXIwk5J5Stthb/FnycmP1YC7GwUqe3zAcWaYiJuDxQBslSntom+ZeoiX 4NihNoyabokmF39EJp9tmENnscfaYh4XuquWOTDHX6PJmYcg1/CUywkmJ7gAdDktrLUu oM+cJKK0MIcxvHuxMEKUOaM8cxpN4A4AdulU/r4EBAYbvVFjba7AGebaxWxuaDfm625E XUQw== X-Gm-Message-State: AAQBX9dkHnA7Y/RJLiQj+Z/HOZk7+DYru7sSzjTRr05QBu8pDIGMO3q+ uABic8LIWLHpmKAk2LgAp/FkwME02cvcVxln X-Google-Smtp-Source: AKy350ajtZ8vLoqucYqQMFTZaUzvE9MwMljTvcwfiUagc47PMCdndDAPNrFr2Cl7UkFSgr4HIrbePA== X-Received: by 2002:a17:907:78cd:b0:94e:5b0b:7bd1 with SMTP id kv13-20020a17090778cd00b0094e5b0b7bd1mr9561393ejc.74.1681816226432; Tue, 18 Apr 2023 04:10:26 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id n26-20020a170906379a00b0094eef800850sm5954554ejc.204.2023.04.18.04.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 04:10:26 -0700 (PDT) From: Benjamin Bara Date: Tue, 18 Apr 2023 13:10:02 +0200 Subject: [PATCH v5 3/6] kernel/reboot: add device to sys_off_handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v5-3-ab090e03284d@skidata.com> References: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, peterz@infradead.org, 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Benjamin Bara If the dev is known (e.g. a devm-based sys_off_handler is used), it can be passed to the handler's callback to have it available there. Otherwise, cb_data might be set to the dev in most of the cases. Signed-off-by: Benjamin Bara --- include/linux/reboot.h | 3 +++ kernel/reboot.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/linux/reboot.h b/include/linux/reboot.h index 2b6bb593be5b..c4cc3b89ced1 100644 --- a/include/linux/reboot.h +++ b/include/linux/reboot.h @@ -129,11 +129,14 @@ enum sys_off_mode { * @cb_data: User's callback data. * @cmd: Command string. Currently used only by the sys-off restart mode, * NULL otherwise. + * @dev: Device of the sys-off handler. Only if known (devm_register_*), + * NULL otherwise. */ struct sys_off_data { int mode; void *cb_data; const char *cmd; + struct device *dev; }; struct sys_off_handler * diff --git a/kernel/reboot.c b/kernel/reboot.c index 6ebef11c8876..395a0ea3c7a8 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -55,6 +55,7 @@ struct sys_off_handler { enum sys_off_mode mode; bool blocking; void *list; + struct device *dev; }; /* @@ -324,6 +325,7 @@ static int sys_off_notify(struct notifier_block *nb, data.cb_data = handler->cb_data; data.mode = mode; data.cmd = cmd; + data.dev = handler->dev; return handler->sys_off_cb(&data); } @@ -511,6 +513,7 @@ int devm_register_sys_off_handler(struct device *dev, handler = register_sys_off_handler(mode, priority, callback, cb_data); if (IS_ERR(handler)) return PTR_ERR(handler); + handler->dev = dev; return devm_add_action_or_reset(dev, devm_unregister_sys_off_handler, handler); From patchwork Tue Apr 18 11:10: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: 1770076 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=oqKwkmHH; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q11SG6FrPz1ybC for ; Tue, 18 Apr 2023 21:10:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231347AbjDRLKx (ORCPT ); Tue, 18 Apr 2023 07:10:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbjDRLKu (ORCPT ); Tue, 18 Apr 2023 07:10:50 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 703DB8A66; Tue, 18 Apr 2023 04:10:29 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id u3so20144783ejj.12; Tue, 18 Apr 2023 04:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681816228; x=1684408228; 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=2+lVoOUZtTyyGsfBDgf4AuGO750yYFu7Mx4N6XxgK8A=; b=oqKwkmHHVS+H8bUhXUZX4FkxJlTh9qLquZdEKUEFxPmIXSv1JV8pzI0Yl/VWl3N+Og WowhtLxCZb+75/EQv/FN4xF0olBBjuQ48Su3XSFibCDT8cT+o27vbx+RHIAWvn8LOPzi 9nHDp/ANxACSih3O58T+BSrjvvkwRjXWXRW+ylFBTrjMm6dhOO5zW/Al68hcy9jpQvJv ZMoHDlICGWpFNSG5wWuJ/oDm3uhcp3DNoGzyQFkOBczOd8AawyQicwGcR733hXTWnxEd kzJVpojpP5rYPqHrLcnTlA7I0z7jDcB+Isu9gVb7dn3DtPPDHbun3WN8qMJWbsyHVQq7 w6rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681816228; x=1684408228; 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=2+lVoOUZtTyyGsfBDgf4AuGO750yYFu7Mx4N6XxgK8A=; b=Te9EJV6iWGE+0D4t5XiI3nPuf8ySeBEwMyx37S7lGVtGsSCEy/VJLABEUHhu8zwWU0 ZZBngQ5gD5peD2a4ooQZI+yfMO20kFZ7MgevY+ucpwhmFWJlVjo4RlDuByNR7ImGNHXo Ie/s3aBTp1w4XUIJ+GVYENvbDfeCixqxM4LsU5iHoYk+8xh12E404JFJvkieruY1g/av 2a9SPPaonePJ+n5YkP0bQSZa6a4vr2EIzCZGuQx0RX+wJPtXzRi/fasRFBH+qUONF+Se TkmZsa0sfp0q3Kk/EHDMzsimfgu41fXRJtYVQouHN2lsjrAhCGy+Kztx6kc8Wt7gJSxJ 01ow== X-Gm-Message-State: AAQBX9cPj+if7Q95B2mT7C8Ok4M4uwu4APSRSEHXJFhJk7fHXRiymOPE VoxRVsMFKefVRbTFA6Qtb17akHr7QlDP2DoR X-Google-Smtp-Source: AKy350ZBsFtOh8G6fWSdZGjumqB6awkFXkuucbnhj6efn7LKhoojGJ+kdr5pouYYgb09xtZwd2FNhA== X-Received: by 2002:a17:906:8619:b0:94a:93cf:6b11 with SMTP id o25-20020a170906861900b0094a93cf6b11mr9560731ejx.27.1681816227421; Tue, 18 Apr 2023 04:10:27 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id n26-20020a170906379a00b0094eef800850sm5954554ejc.204.2023.04.18.04.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 04:10:27 -0700 (PDT) From: Benjamin Bara Date: Tue, 18 Apr 2023 13:10:03 +0200 Subject: [PATCH v5 4/6] kernel/reboot: sys_off_notify: always return NOTIFY_DONE MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v5-4-ab090e03284d@skidata.com> References: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, peterz@infradead.org, 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Benjamin Bara A failed sys_off_handler should not be able to skip other registered handlers. Therefore, report the error but always return NOTIFY_DONE, to indicate that atomic_notifier_call_chain() should continue. Signed-off-by: Benjamin Bara --- kernel/reboot.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/reboot.c b/kernel/reboot.c index 395a0ea3c7a8..689a147bc1dc 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -320,6 +320,7 @@ static int sys_off_notify(struct notifier_block *nb, { struct sys_off_handler *handler; struct sys_off_data data = {}; + int ret; handler = container_of(nb, struct sys_off_handler, nb); data.cb_data = handler->cb_data; @@ -327,7 +328,11 @@ static int sys_off_notify(struct notifier_block *nb, data.cmd = cmd; data.dev = handler->dev; - return handler->sys_off_cb(&data); + ret = handler->sys_off_cb(&data); + if (ret != NOTIFY_DONE) + dev_err(handler->dev, "sys_off_handler failed: %d\n", notifier_to_errno(ret)); + + return NOTIFY_DONE; } static struct sys_off_handler platform_sys_off_handler; From patchwork Tue Apr 18 11:10: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: 1770079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=EGyHKN4t; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q11SN1tSmz23tD for ; Tue, 18 Apr 2023 21:11:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231375AbjDRLK7 (ORCPT ); Tue, 18 Apr 2023 07:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231318AbjDRLKv (ORCPT ); Tue, 18 Apr 2023 07:10:51 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53051900B; Tue, 18 Apr 2023 04:10:30 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a5so15608361ejb.6; Tue, 18 Apr 2023 04:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681816228; x=1684408228; 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=JtS1ygcE2PjsdNhXBk8/87DjMxp+o7uwRjOEEP3Mvzg=; b=EGyHKN4tkpwCWGxolzyBJYMI1qiKu9MJqhR4HMS9CtxNfzyvVgXTZgTbMTne2rP+TI f+Or0zNlj6x+eRX0mhSEQpAlrkzK9QQhib/QbNWQ89/+tKQhFZkgOJB5AOaJm4uNyFp6 9SCyGdxXpgDR8aCyg/KbQcLgZ+3LnIsfAY2ZpqRPjfjRuGphucmqEt99P1nEWHRDQ6SM /c9r9/g3N9VWdyLN/VT6iprYz2ZQyv/4wrjj2Llym40Tkac5CD5IU4bu7Sf3s0RnIDeD KAeIERFoF0Vc/QwSbLTyrUZ+EhJtbs5a0hLqFMtU+Hl+N1+CIW0u7CFIKVWRIB4YRrY0 0Dcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681816228; x=1684408228; 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=JtS1ygcE2PjsdNhXBk8/87DjMxp+o7uwRjOEEP3Mvzg=; b=ODhJ/2zAOLPc+GR8CudrX6PxBwf48nWVKOxraJh6JI7NLUIwkEweGVrB1V4glY904v TobFNmGyZje8D11bo9MRmKHLkeaNqeep4K4Oite2m/Zsi2ykByIa3s2WyEABbv153uJu sB+qhATm3zGYzDv3pB4dx7S208lSlmxXwGuAiIvG4bveLAKE2cJA+i3HGu4pYg4hjYtV qoWWJSBwnwoR15BlORXtMu6puaPXbPy0b+Gu6/J+M+0eICaDSOKGjvTsKcf8GU8CYiNW YCQiYRh4mF2AJNJkHAnqE/qwoWYutrI4CnjW2C+ZAt3nf5tFyq+2a+61YvFFHK1eKteB /hRw== X-Gm-Message-State: AAQBX9cE/Hij0RzAEFshuGRINEEcuuXtsZT5O/2FAYSxPvkcbMS1jUUx qD8JwY0qNPY+sCq1/iCFqOmpnLyOX1HxRNF8 X-Google-Smtp-Source: AKy350aiSYTxmVZXM26WUlSVE3chRj7TlJhSs8yk84VKvLGeniNoQajvh5tAJWas8/8PdWWiS+1MiQ== X-Received: by 2002:a17:906:240f:b0:94f:1a11:e08b with SMTP id z15-20020a170906240f00b0094f1a11e08bmr9336918eja.20.1681816228437; Tue, 18 Apr 2023 04:10:28 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id n26-20020a170906379a00b0094eef800850sm5954554ejc.204.2023.04.18.04.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 04:10:28 -0700 (PDT) From: Benjamin Bara Date: Tue, 18 Apr 2023 13:10:04 +0200 Subject: [PATCH v5 5/6] mfd: tps6586x: use devm-based power off handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v5-5-ab090e03284d@skidata.com> References: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, peterz@infradead.org, 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Benjamin Bara Convert the power off handler to a devm-based power off handler. Signed-off-by: Benjamin Bara --- drivers/mfd/tps6586x.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index 2d947f3f606a..226e856e34e0 100644 --- a/drivers/mfd/tps6586x.c +++ b/drivers/mfd/tps6586x.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -457,13 +458,21 @@ 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; + int ret; + + /* bring pmic into SLEEP state. this takes at least 10ms. */ + ret = tps6586x_clr_bits(data->dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT); + if (ret) + return notifier_from_errno(ret); + + ret = tps6586x_set_bits(data->dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT); + if (ret) + return notifier_from_errno(ret); - tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT); + mdelay(50); + return notifier_from_errno(-ETIME); } static void tps6586x_print_version(struct i2c_client *client, int version) @@ -559,9 +568,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, + NULL); + if (ret) { + dev_err(&client->dev, "register power off handler failed: %d\n", ret); + goto err_add_devs; + } } return 0; From patchwork Tue Apr 18 11:10: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: 1770080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=KdRrHgyS; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q11SZ6qBLz1ybC for ; Tue, 18 Apr 2023 21:11:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231429AbjDRLLJ (ORCPT ); Tue, 18 Apr 2023 07:11:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231393AbjDRLKz (ORCPT ); Tue, 18 Apr 2023 07:10:55 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F0378690; Tue, 18 Apr 2023 04:10:31 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id xd13so38215535ejb.4; Tue, 18 Apr 2023 04:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681816229; x=1684408229; 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=Uj87T+hG7LXIYMqH9ajwVI/kHwGEYduJ3KruAcTVFbY=; b=KdRrHgyS6gjueA0u8yVZOCP0GyvZT6zqYwmIirNo6dJ1bVal0AoDargg1S+op4S4XB aGjWZiAoVvUrhgWbrzfWXJG1AXq1FX7duI3VqWVvMSnmQ6orDSQIrDTNQIjSRggPo0NU DsHEmRR1yuUGWUqgA0XychhS6yx3JZca22wKDsz1KkapBDhGZ+73nZfrGF2/RJVn14Zu lLGLaqOpO4Xi5hxpGInTLlpL7jkpMVP7d4ZOHxXhbBMaMcx1DJpY9Q5yikFbj9g27WnZ rI6fvPrVb20j2o8aKPAXZgYKTFhoB43Zjk+UCDkMmYSdJlRo83mXiAVWc6YPxdyKpokh F41w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681816229; x=1684408229; 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=Uj87T+hG7LXIYMqH9ajwVI/kHwGEYduJ3KruAcTVFbY=; b=KpPpQxVBKeGsYEhbBfVgyzqNx1JUfRG1FV2JTnLo5D3X01tVaCDfLuzGvfhA34DP5/ qAlnj875hdvW4E4odRI4H6OKX0aHsL58jc+gMSI9RlzQvjGBVnZm9qmwqh0KdSuYuruG B35r3bggvw/h3LEN3mcHi9oBTrM36C/ySHZKstN4/SDx6gXDPbCMlcc9DMV2uNFeduw9 mz904CxvyEmLuf36aMhP7AkxxXBb97wO8c57hbCM23oL0vKSDF+koI8ibY/sowZl1Rkg /1wOs4vhp879BighlY6FVvx2fx7Udz6S6465TL19kqo5MC8LI31mNjCH597FWVT8KlU0 TPgQ== X-Gm-Message-State: AAQBX9c9S46uw0yU07pdBakC7du58XUAjZjbUGnRvlOvmZkdIxzsLRTW M4FcpEnQQ0eno3jyiLnJAyFp5NrifgyPjSwQ X-Google-Smtp-Source: AKy350bXbwagTXdOA606HRqRvyKKhdNP8U0+PTGkWU4hjNNAesTtpKJMMkFzJ5cU6Rx+2nwcElEzGg== X-Received: by 2002:a17:906:2bc7:b0:94e:ef09:544c with SMTP id n7-20020a1709062bc700b0094eef09544cmr9665939ejg.10.1681816229387; Tue, 18 Apr 2023 04:10:29 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id n26-20020a170906379a00b0094eef800850sm5954554ejc.204.2023.04.18.04.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 04:10:29 -0700 (PDT) From: Benjamin Bara Date: Tue, 18 Apr 2023 13:10:05 +0200 Subject: [PATCH v5 6/6] mfd: tps6586x: register restart handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v5-6-ab090e03284d@skidata.com> References: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v5-0-ab090e03284d@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com Cc: dmitry.osipenko@collabora.com, peterz@infradead.org, 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-tegra@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 8f0c714ad9be. 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 (because it is not used). 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, which takes at least 10ms (as the data sheet states). This avoids the hang-up. Tested on a TPS658640. Signed-off-by: Benjamin Bara --- drivers/mfd/tps6586x.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index 226e856e34e0..f7665b368071 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) @@ -475,6 +476,24 @@ static int tps6586x_power_off_handler(struct sys_off_data *data) return notifier_from_errno(-ETIME); } +static int tps6586x_restart_handler(struct sys_off_data *data) +{ + int ret; + + /* tps6586x only provides a hard/cold reboot, skip others. */ + if (data->mode != REBOOT_UNDEFINED && data->mode != REBOOT_COLD && + data->mode != REBOOT_HARD) + return NOTIFY_DONE; + + /* bring pmic into HARD REBOOT state. this takes at least 10ms. */ + ret = tps6586x_set_bits(data->dev, TPS6586X_SUPPLYENE, SOFT_RST_BIT); + if (ret) + return notifier_from_errno(ret); + + mdelay(20); + return notifier_from_errno(-ETIME); +} + static void tps6586x_print_version(struct i2c_client *client, int version) { const char *name; @@ -575,6 +594,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, + NULL); + if (ret) { + dev_err(&client->dev, "register restart handler failed: %d\n", ret); + goto err_add_devs; + } } return 0;