From patchwork Tue May 9 19:02:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 680766 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 885FCC77B7C for ; Tue, 9 May 2023 19:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234772AbjEITDm (ORCPT ); Tue, 9 May 2023 15:03:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234410AbjEITDj (ORCPT ); Tue, 9 May 2023 15:03:39 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4431A4224; Tue, 9 May 2023 12:03:38 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-50bd2d7ba74so61810502a12.1; Tue, 09 May 2023 12:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683659016; x=1686251016; 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=JYhBuR4qpiaDvkhg6AZK8V7F0fbdddRjnrzxLmoLI8nDqKbdv7tPEmPeZaWGvGmc4/ f1ONolfAENAOEYgA/Pf8MAm2Ed1RDYhlmIssUlQC336Bhzji5gOpQ9Wo3Trd2F93ZiMP AC9lMomxq7i9L6Jj4qcSNVrgoBha8mmq1YMhRahx1i4/hFfA2oCGc/Md+zysak7gbxH9 i1+CrqAjW8qrMhnUy59U/KkuNBR3bi4PGLOTrH/8uQpYI2knKBU5h8YwY9umFxTaK1pL +n6+/UAIfE1VRDF0Nj3aLGoqSEKTg4Ybb6JOXMgn6/Ddc4v7rjS7fA+88tMfdbqi+krk uqUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683659016; x=1686251016; 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=eW5UyFpW3MO8KaGIahvKn8RgvKCgKDZVbV2by/AARg0jRv53Rffl7MJ9Xj+cBfVpS3 K0p3vIto4sXPNlE7uDDmtJApo3XP4gNLCoTUOP/5m+12u1SDHgB+4oH2oj8HWSDYDgZr s70edMzmGmmRfqTNkumvLngJXpYxpYWtgZcrfJql6YShLG2wqFe0jBMzodPWrN2A40Ml ViQqYZYGOeYfgecMVlE1XMQrbiYez1dglmQq9Q0K6j13l+FK08u7/BVstj0d0dA3h+vh MKXD/e4PHk9q++z/Z5kFJNvM/0KXhIUIayQf+ZGxjTfgkQST0D+wTquw4X1T896+nmra oNSQ== X-Gm-Message-State: AC+VfDzbyBrW3firk6/s0LZG+9PPBOhlM38AcZOQg0GYVYy2UEjFhL7x vWL+dtU7ziqqenqUHaXjhVSYbhIvND+6O7Wl X-Google-Smtp-Source: ACHHUZ4sqC9G7JlHs4jYEbeNTTDzn/nCy3hXXPEdhgwIei5SoIH/ZCCfsVZTJsGaEx7Cf0DwyzTSGQ== X-Received: by 2002:a17:907:3f22:b0:96a:2b4:eb69 with SMTP id hq34-20020a1709073f2200b0096a02b4eb69mr1662985ejc.31.1683659016408; Tue, 09 May 2023 12:03:36 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id e2-20020a170906c00200b009697aa5acfcsm1640232ejz.122.2023.05.09.12.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 12:03:35 -0700 (PDT) From: Benjamin Bara Date: Tue, 09 May 2023 21:02:59 +0200 Subject: [PATCH v6 1/5] kernel/reboot: emergency_restart: set correct system_state MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v6-1-af44a4cd82e9@skidata.com> References: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@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 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. 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 Tested-by: Nishanth Menon --- 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 May 9 19:03: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: 680765 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 A98B9C7EE2E for ; Tue, 9 May 2023 19:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234934AbjEITDp (ORCPT ); Tue, 9 May 2023 15:03:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234635AbjEITDk (ORCPT ); Tue, 9 May 2023 15:03:40 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F27649EE; Tue, 9 May 2023 12:03:39 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9661047f8b8so733150266b.0; Tue, 09 May 2023 12:03:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683659017; x=1686251017; 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=Afvjm2OnP/cD1G79QHO+6f/98CFgsDJipiNhtGgCLQ163WD/TgRIJOCoPI/htLTnM/ mvr/x3KmOS6hUNe2fRTGk+QZUyM5UdwnuHndH0eaaLvqqQxWHo7Nc9RM62YhrKaL67zz kG/Ie8OqEwT4yGD320fK8tpLWgWZulX2hZDCpphgltCOXrmoGuYym6dYM7mh84PGvLrb Y8/Te5E31rPgn0BpzH+2DbpV3T+dFATJXgeS+lANmT3i3+NPQ9EI0QeTZEUlH1BTSnwE Oomukj7VUTvhJ8Rw0y0xyHcHA4Dh7BC8BZRtm+0UCmNHwx8oSX8OtPCiIYhAKp3ZnHqo ywIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683659017; x=1686251017; 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=QFGy5AFP3WRuY/JfA8tv4PWIekrEHLZvD9b2A+HUDk1327RM8w/Z3MHwHEa5FK16xq aORT93GxvYjvJl8oY4d/ceOjIlZLRZSxsIyKnu5lms1wc+3y8+JBcf5GFue+Q/c7kJJV qw1c+J4qoCcBDbOAMfQdn1OsUmY1o3/GnmZBr3SFav5b5H3tvt+P2mkWfhECOceCPpei TTdu+US5mm4KZliZ0xlH2mC/+0tqsuNGpQoU7dWruWgKSIAHxkCGnR6vGjnbogqtHd1t zBhpmKLjav9/M4nCOG3nzqj8bUwPPIujp65Y3p0nHXGge07DqjJDkJRSdfJ2y9HWYfG0 FcRg== X-Gm-Message-State: AC+VfDzA/+aPnppaLI9/pqkEMr2/PEnqt3A5+ttONbH7+P+EG6P6bGH3 QEtYGwtQqwIYU60wNd+hIGyqxKuauNxqWvoh X-Google-Smtp-Source: ACHHUZ7SZPJq43m1vkwSM8OY9Jp1q+dUpgBMGulzGUFY6gKuPbX9x/U6HHzFHCtZEHrXxbptHT4TqQ== X-Received: by 2002:a17:907:3e05:b0:94e:988d:acc5 with SMTP id hp5-20020a1709073e0500b0094e988dacc5mr14025282ejc.46.1683659017415; Tue, 09 May 2023 12:03:37 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id e2-20020a170906c00200b009697aa5acfcsm1640232ejz.122.2023.05.09.12.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 12:03:37 -0700 (PDT) From: Benjamin Bara Date: Tue, 09 May 2023 21:03:00 +0200 Subject: [PATCH v6 2/5] i2c: core: run atomic i2c xfer when !preemptible MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v6-2-af44a4cd82e9@skidata.com> References: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@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 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 Reviewed-by: Dmitry Osipenko --- 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 May 9 19:03: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: 680404 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 BA6CFC7EE23 for ; Tue, 9 May 2023 19:03:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234986AbjEITDy (ORCPT ); Tue, 9 May 2023 15:03:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234959AbjEITDp (ORCPT ); Tue, 9 May 2023 15:03:45 -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 BEB9C4201; Tue, 9 May 2023 12:03:40 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-966400ee79aso631858866b.0; Tue, 09 May 2023 12:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683659019; x=1686251019; 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=s3/JyypJhOLprfB5qLzC/3u3JxM2Qm9MfuueSbMua157cqQO9vFJRafYM7+nr3WGQN Zmxe5ilXRu18zAkWwenKRiH5ly/tsRgRXzfTYjp0li6qwAgz6kzorHxhnIYZ9oWHhG3a +tHLPRuAfbaWYYoXZS8KhMaRqX/jYzUNMNEGK8WWI6oiX9YxrSiWMxRzz/fqcCFLOjxm G2rKzN1+yFkLJbMDXuE7Gd/mPh3sR/QAttNgs9buDSlsDf4DtD1XZxFuyywe4/1LEuPY 5gZ99ytLogoS/crM7Uvzp+ry0QqdixlDeVqij2uG3cLbiRKT7KvYkc371OP5q+YYFOoE jsuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683659019; x=1686251019; 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=VnK2JUhmiwqPsQftzDtKVE+ZL71svw6E6ktA3oU/Jck1+GtzGy07JWHcCDPpvn2qyo ETtPXtBLpCyU/sX+pu5XHPFfZ2hcEl2zc0ejt2t8yU2VaN0X5d8e8PRryn4zO3ObIqvA kah0CWcUILaXfBbG2wA5ksfry69YT4FU+k5F14aP/nDMNtJv6o0Z9MEavru36kLHiiQb /+gQd1JJQWAT7VLjlZT1y7natDjMZjmh3wII3u5y5bxK3Vksrj5NOHM6l7fOQTV3q4Pu 9K0sXXmmdRQfjZZ/l7mZz8zk0x6xvc5htfsmudO9PrQPR5orKdhgBqmh455VLe/IIuAw X19Q== X-Gm-Message-State: AC+VfDwySyXO0osuH7jxxCWmwQ9U9HNC7w8y5zemzx4z0kMs+nFE27vV f52KFvoMYoWMvjcrPaX6IwmTMETX70jEChmX X-Google-Smtp-Source: ACHHUZ4N9Cw7QXnfUCKm9htZoVdj+Co7WubEXVF1adu9SzJ+miBh5FHrk9VJot7LX2j+iIODsr3nPA== X-Received: by 2002:a17:907:e8f:b0:94e:e082:15b9 with SMTP id ho15-20020a1709070e8f00b0094ee08215b9mr14861016ejc.77.1683659018329; Tue, 09 May 2023 12:03:38 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id e2-20020a170906c00200b009697aa5acfcsm1640232ejz.122.2023.05.09.12.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 12:03:38 -0700 (PDT) From: Benjamin Bara Date: Tue, 09 May 2023 21:03:01 +0200 Subject: [PATCH v6 3/5] kernel/reboot: add device to sys_off_handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v6-3-af44a4cd82e9@skidata.com> References: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@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 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 May 9 19:03: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: 680403 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 E2A9DC77B7C for ; Tue, 9 May 2023 19:04:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235166AbjEITEC (ORCPT ); Tue, 9 May 2023 15:04:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234995AbjEITDq (ORCPT ); Tue, 9 May 2023 15:03:46 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 640E13A89; Tue, 9 May 2023 12:03:41 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-9661a1ff1e9so585041566b.1; Tue, 09 May 2023 12:03:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683659019; x=1686251019; 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=41onpHzQLEVrljVFMSZhqOmakDjAgDTWqK5CRbhigA0=; b=dW3Hcc1ywetN6Ic23ffj31/3v55J7Qvz5V/p3r3jo9eAN/rWaoB+0MDU8nYYGR71p/ 1Yycr1V2zHueNQCrplRox1+o6yIBrlLezAC9qGD9Umn9Aw05z3QkHfa5GnvScSBxjAv9 TjwtwX78JFSAkgEvaIuHL7FwTfFOC1RkNmu/WBtF7h/mkQo4UgdoWb/AYmM+7rl9X3M+ skqpXUEavyOKgJ1b7/SsMeVQH8E0l4P3UF0I0LQXMhR3EVV6mEYbhhzKnotkgq3IW3XY WEBjlcepf8KUQo6CdTTljBZnANAgb0vxqKb3tJIwIKifRqufqVo155ubm76zSoUDsNJ0 q00Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683659019; x=1686251019; 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=41onpHzQLEVrljVFMSZhqOmakDjAgDTWqK5CRbhigA0=; b=Memoc0Zgrg3/3zGWmxT8udalh6e372t4/Wqv2Mij+WU8fH7a7s62lWZq6a+MS3IaCp S0PhdoOm898XdzHSBu7Hc0zw8QGkKnjTSfTNTOvtoq/me6cZ+0gQrlGMnXa7MXQG+M/x 3+KJ6vc4KciFnU+2TddJtnsf3RtJ3czb2cZkUKd+BP66ZwdQeMjhPseHIW2fFCxMFR3h nM/ldH0m0otFUnnum80dxAxfeSRmOx9mdZFfXWXlISD7m37dzIXcTJyy5DZqnthCXPwy IQ7ngY9CzvmDM+d/Mx3WPwpJQ4E6sYwt/B9wji4r2tZlOWK9LQmmeuU2KSzGE17wBDVv whjQ== X-Gm-Message-State: AC+VfDzqv2IxW2eCusYMf/0ATBTfieH366KCA8ZR4ZXUbpMF5HhwbEMJ GCba+weeLIjdg4Cv4oBACtKjAMgKzVlg7Gp1 X-Google-Smtp-Source: ACHHUZ5FBMnnDtwDDNO2/H6qZ9X1kDVfqKsjE0ZHjszI7WNAp5BgKlqdRDobHjdJxpqnG0KRdB/+Hg== X-Received: by 2002:a17:907:9454:b0:94e:54ec:1a10 with SMTP id dl20-20020a170907945400b0094e54ec1a10mr12516223ejc.29.1683659019239; Tue, 09 May 2023 12:03:39 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id e2-20020a170906c00200b009697aa5acfcsm1640232ejz.122.2023.05.09.12.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 12:03:39 -0700 (PDT) From: Benjamin Bara Date: Tue, 09 May 2023 21:03:02 +0200 Subject: [PATCH v6 4/5] mfd: tps6586x: use devm-based power off handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v6-4-af44a4cd82e9@skidata.com> References: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@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 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 | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index 2d947f3f606a..b12c9e18970a 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; + + /* Put the PMIC into sleep state. This takes at least 20ms. */ + 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 May 9 19:03: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: 680764 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 B90C0C77B7C for ; Tue, 9 May 2023 19:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234959AbjEITD5 (ORCPT ); Tue, 9 May 2023 15:03:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234983AbjEITDp (ORCPT ); Tue, 9 May 2023 15:03:45 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84D283C15; Tue, 9 May 2023 12:03:42 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9619095f479so997324666b.1; Tue, 09 May 2023 12:03:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683659021; x=1686251021; 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=Lg+AaRFA0UQRvNOojE4EBlRJNw3ULgD7/078ZrdcKSc=; b=FRP9FGuh3WhE0zFzq6ReOR6WRHhCd7Lcym/WHCBZLuje1tKK571gGvNANpetGfMMoL NgtpCh8mqlJ9t09DtZWTj6GV8TT6j1ZXKvYX3mTHTMS+qZo8RElx3Hy/wKhnTcmjPLCN pQbuJIVGHJkXeIntHaMAn21+xYVxAxhejRkUZnweBGMNAG9e84aCAiY112dqxE88QIPh CoHWE8FIluBl04iImcIvmCje8KiJDfBCiIosA7DU6jqHdd+CzFQv2bJJ7KnjgK47dTEj P9HfCQ87WwSEiQNiUdaqLGbhQej5C0Y1X5kIiipxfSNNl0OT533VNxPwhGTZLcgXm7oO IjGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683659021; x=1686251021; 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=Lg+AaRFA0UQRvNOojE4EBlRJNw3ULgD7/078ZrdcKSc=; b=ckmydxHM1+qn3apUV8z6+OH38YL4RFBo9PcznREDJrCBRmXUAAMxJMqaFI0k9fK41F CTbn3BZxfIQGFKGIcuPc4cFP2VY2eytO5fi2CdgLtrjQyKwgEwCCUrL8QC32IQ8H/Mgs V3hmBw/wHIBp7qdfqV5NQfWkDAvci8Lvp9wNcImlAUciz3ePWk7MZOc/GaLtqouVUm5g EbhiF/3Lw8ZJBuqImsz9/VgwHz/ywN5VjtXLF13n1cXzR4916wPC0DhAXkVxDBqQeBFv L/NVJwJw0pJACpX6X75J3LFVWYY3X3tLlv4f7ZyKE14PU4oCaxrrD8gQ3ORaZSy8vdhv PToQ== X-Gm-Message-State: AC+VfDz6O2pMqjkkj8Te1r3LxzXsL9ShWcFATsYq4JljmdVHiupBObf7 QZ7bPkYIPT03d/4iuKZGM3KjXw6NyzVdcPvZ X-Google-Smtp-Source: ACHHUZ7K5NExcERUaziATQooKwQ1xXwdhlZ+QKnFckt4KMJEXCxZqUcZo1UdzvcVXuZXNmQpgKVlsQ== X-Received: by 2002:a17:907:6e0f:b0:94e:fe77:3f47 with SMTP id sd15-20020a1709076e0f00b0094efe773f47mr13781046ejc.67.1683659020286; Tue, 09 May 2023 12:03:40 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id e2-20020a170906c00200b009697aa5acfcsm1640232ejz.122.2023.05.09.12.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 12:03:39 -0700 (PDT) From: Benjamin Bara Date: Tue, 09 May 2023 21:03:03 +0200 Subject: [PATCH v6 5/5] mfd: tps6586x: register restart handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v6-5-af44a4cd82e9@skidata.com> References: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v6-0-af44a4cd82e9@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 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 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 provides a SOFT RST bit in the SUPPLYENE reg to request a (cold) reboot, which takes at least 20ms (as the data sheet states). This avoids the hang-up. Tested on a TPS658640. Signed-off-by: Benjamin Bara Reviewed-by: Dmitry Osipenko --- drivers/mfd/tps6586x.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index b12c9e18970a..3b8faa058e59 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; + + /* Put the PMIC into hard reboot state. This takes at least 20ms. */ + ret = tps6586x_set_bits(data->dev, TPS6586X_SUPPLYENE, SOFT_RST_BIT); + if (ret) + return notifier_from_errno(ret); + + mdelay(50); + 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;