From patchwork Sat Jul 15 07:53:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 1808088 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=dvTbeBsi; 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 4R30wG0hndz20cl for ; Sat, 15 Jul 2023 17:53:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbjGOHxo (ORCPT ); Sat, 15 Jul 2023 03:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbjGOHxn (ORCPT ); Sat, 15 Jul 2023 03:53:43 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F21335B3; Sat, 15 Jul 2023 00:53:42 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-316f589549cso167070f8f.1; Sat, 15 Jul 2023 00:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689407621; x=1691999621; 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=hkZwqb3Vffoas0KVRKwKV1wchqc/EYndL8Fu8HZrU3o=; b=dvTbeBsiheUTHcMMniyY/m4PoV4r6uJMCT0r8qcXyNJq8w33m1VsaEqZyZOyfNSVYC otHuqvaOlMgsikX9JrvgNmfEPOJpZClaXShrU/pSz7hIFd1bkYW1tzextkt5V26iiB+p JveQFRxvZDsJhCEDDfsrohk4Ngp/umuexp6RGiV+HAwKTUkRPPrFgL1yKk/Tz3N3kM3Q YjOE3uTDuG91TlnOXDl93PeGe+hdTjueyRxEK61aO/1whE5my1y/By3/9EQ+FSQ9YtDb EDnNI21GGWJsG+NIOj/uqpm5cCX6y2MasJOfBiLQH9Oe9L0CMWTni4/x42kA4X+AfZq8 Ym8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689407621; x=1691999621; 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=hkZwqb3Vffoas0KVRKwKV1wchqc/EYndL8Fu8HZrU3o=; b=XjekmUX94d49Apwzo8Q5MvSZGee6mRgORY9NJ+LGTReYQG0wsw4kaYLV/YIdEQeuDe yLO3iMAT4QAdD1t7Igydamhq1npn1/xakC4qveXMYNNmyl7M6RMfdK0+5hptzrxXdCvU oQlCHaOkQorvQbISiJqp4la5dAxV8VhWP8dm/ceR3kCVGeSBTydphrqcUMZq2yItLbLW nZ/eLAy/LyVYpY7FbmjQL4wibEVjesYCEPnchMXzvHMaXczR2zkPFYeWsqM5rHm1HE19 a96lwd+omhlzugNqD0p561oCh5nMgNFDRLst9+aqIq1VB+qNMZV8vJMx0nwZHanhv4f5 Egfw== X-Gm-Message-State: ABy/qLaJme/JM8O/I0rwI/uM7gnaHSPX+RcZAKQ27dGzoRY4cxKLtWxi 9hsQ5hBSSgmFgHtXzV6MGFNBfuMqqzQkFQAo X-Google-Smtp-Source: APBJJlGw8BKGae83Ti0dFAC+Xvl5fT43WIHmXQehaFygK2EtfDNujLdnjv/1SCD/9eNY7q1jx7+g7Q== X-Received: by 2002:adf:f1ca:0:b0:314:5f6f:68ce with SMTP id z10-20020adff1ca000000b003145f6f68cemr5388310wro.66.1689407620997; Sat, 15 Jul 2023 00:53:40 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id f6-20020adff586000000b003142eb75724sm13001271wro.24.2023.07.15.00.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 00:53:40 -0700 (PDT) From: Benjamin Bara Date: Sat, 15 Jul 2023 09:53:23 +0200 Subject: [PATCH v7 1/5] kernel/reboot: emergency_restart: set correct system_state MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v7-1-18699d5dcd76@skidata.com> References: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com, Wolfram Sang 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, Nishanth Menon 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_BLOCKED,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+ Reviewed-by: Dmitry Osipenko Tested-by: Nishanth Menon 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 Sat Jul 15 07:53:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 1808090 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=O8evkQvg; 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 4R30wH2pGhz242f for ; Sat, 15 Jul 2023 17:53:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230365AbjGOHxp (ORCPT ); Sat, 15 Jul 2023 03:53:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230328AbjGOHxo (ORCPT ); Sat, 15 Jul 2023 03:53:44 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73443358E; Sat, 15 Jul 2023 00:53:43 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-316f4abb1e1so291797f8f.3; Sat, 15 Jul 2023 00:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689407622; x=1691999622; 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=y+obao1vrgT6KgLyos6QbGdIaBLL4NR6czetr68SUf8=; b=O8evkQvgJtq7ml+5tf0IhSV1zngA5Z7BkV4VKvBJ0F2zCtW4ZeTAWs0VxF7Q+oLnx1 amSHIqAOq85VPHMQUgCqXX8z1FprthpkaNSgXrTW2qc+zdfDZd3w2lcff0p+GXSU7MIx K0kOnWc5kfIGSlmRhExfFWq4PTSmxp/bDWHvnoQSMqcSCl7FCrHCojGvXfsEoCVzJsda D9hl7SY1B7omLGkf3ATPOv4DvA/VbZkooZ8g8oe1p5xrNrBV3Wmk+UtkDGVPB6O+teG9 Xec/PRid17C8i3dNUw9/jJlN6Jbuv/ppzKoESL4wqJR7SY5jjAiFefjo6KW4d7awxuvy saug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689407622; x=1691999622; 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=y+obao1vrgT6KgLyos6QbGdIaBLL4NR6czetr68SUf8=; b=f5P1qdbZeGOyUGQjXZEp/P0qCIPor/WTtAQzjA0LunqNWgIKpIEo+PmL+Kfh9HHGy6 moO7F17tKsgtz28IfJguc6gfg5L35OGuCYgu/OktavVCoFzmACesVcB1XDdNEb4x3KbO 6TdwVxh0uQVHC4NkxTt2AbAkeqc9m16mN7bstnskRRe9M6lkwNgRHwW9CzLjPCUnf+O6 zuULLrFacT+BHCwECA1xYH5aBSb/pkzody67XJMS9aVrG/3+F1MEWYLm62Z9bSDoDijV VeSBWq6727H7retiCiVNWp0lT+PXZsseAY0i//HNis54p04cpr4zTf3Z6CkFZqZasZVA sKTQ== X-Gm-Message-State: ABy/qLZwbHyASQQ/juZDK7LUOH86kN/dzOQQuif6KqeIQEpwHw3/eLmX 31gxka5xaM/YCSJMyNmN1dUW/WCXBvXUW3rb X-Google-Smtp-Source: APBJJlF9bB3nAEEihMb2nZ7+5Y9uwEUlEU6kZi1nhDv6kvU0/EUdBRl0gq0XcG1IFKVrhp+XiAHBKA== X-Received: by 2002:adf:e801:0:b0:313:fe1b:f444 with SMTP id o1-20020adfe801000000b00313fe1bf444mr5761068wrm.68.1689407621760; Sat, 15 Jul 2023 00:53:41 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id f6-20020adff586000000b003142eb75724sm13001271wro.24.2023.07.15.00.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 00:53:41 -0700 (PDT) From: Benjamin Bara Date: Sat, 15 Jul 2023 09:53:24 +0200 Subject: [PATCH v7 2/5] i2c: core: run atomic i2c xfer when !preemptible MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v7-2-18699d5dcd76@skidata.com> References: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com, Wolfram Sang 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, Nishanth Menon 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_BLOCKED,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 Reviewed-by: Dmitry Osipenko Tested-by: Nishanth Menon Signed-off-by: Benjamin Bara Tested-by: Michael Walle --- 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 Sat Jul 15 07:53:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 1808092 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=knUXx6Q/; 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 4R30wH5mprz20bh for ; Sat, 15 Jul 2023 17:53:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230387AbjGOHxq (ORCPT ); Sat, 15 Jul 2023 03:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbjGOHxp (ORCPT ); Sat, 15 Jul 2023 03:53:45 -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 3AAFE35B3; Sat, 15 Jul 2023 00:53:44 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fba8e2aa52so26926055e9.1; Sat, 15 Jul 2023 00:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689407622; x=1691999622; 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=hMFNGkQWy0XgQD1M7WLotDgHQHKNsdR7qapEAzcCtKU=; b=knUXx6Q/kxZ4pQTG6QoR/jTseWzsNLa7cNz3w/haUKvCT7V8jcGBfdT4Vtl9AdxhLN FrW3emWhJU5V/uxjiI4UN/blsGkWrisQWuDi71lv1f2qDHJIn7JknQ2SppcyPuvKuYIp FEeFORjEX46EC639gaoVv6Ybmuvb4oK7gYnQ9EIkOqKSlMvc1FrdobYL60rsi/me7lUk tuinX7Lihv3UWMqgIjgF/88Do77GVgANMffACm23YSKFwmZ2dtuQtlHjCBHnZMK3wxhC tB+oQb6so7jVKz7KhcfP1r5uM0297l1gjYiFc4c5ZBdfQrQmFjMByd9mSAwkPaRa94hN uNWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689407622; x=1691999622; 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=hMFNGkQWy0XgQD1M7WLotDgHQHKNsdR7qapEAzcCtKU=; b=LfgqUWjr5SbmUZZaA0b9OhWse2lLN5uJrkhNCoDRvnA62OKdHnrVtFFPRMpjpaYdg9 yPYEoeCfyXIrxXFZfzeia22i4X7H4D9/mmXGL3SOZ98lA87t0eW1i8DMBjhD2K36A3tk A7HnmxMvAOxMzR+Zt8WJrOCLRD87PyQEskqfj5iQvdHCPwj9Gd9muCwTCuM3eLSjznjc mxJuEXWkbqs2K3ml7W7ENXWMjdR9RggE+XqPZn22DJJIPhqMOWFvJ4igj3/Nukta3Cu4 IXtFx4wviaSBqhSnNYkNQXZGyvi0IhGzeHjGmiF/4E70+2FsymJ2JRa8nZffWq/az3cJ sJKg== X-Gm-Message-State: ABy/qLbA7OPApaZ8/izeWtEs/ab+Etl6JkR6XZ7Ggs0DBy1OrClNE1qd KVq76Bw9Ff0I4NrwJsZnpk4= X-Google-Smtp-Source: APBJJlFFIHburZ+jenisgWg9lxIuKcRQurMrcxImCKydDON7PN/2NPJuxM59yH38/XA/4PtDP+44BQ== X-Received: by 2002:a5d:498d:0:b0:314:13d8:8ae7 with SMTP id r13-20020a5d498d000000b0031413d88ae7mr6239736wrq.26.1689407622586; Sat, 15 Jul 2023 00:53:42 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id f6-20020adff586000000b003142eb75724sm13001271wro.24.2023.07.15.00.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 00:53:42 -0700 (PDT) From: Benjamin Bara Date: Sat, 15 Jul 2023 09:53:25 +0200 Subject: [PATCH v7 3/5] kernel/reboot: add device to sys_off_handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v7-3-18699d5dcd76@skidata.com> References: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com, Wolfram Sang 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_BLOCKED,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. Reviewed-by: Dmitry Osipenko 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 Sat Jul 15 07:53:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 1808094 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=PwVsFYtm; 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 4R30wJ4vP6z242g for ; Sat, 15 Jul 2023 17:53:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbjGOHxr (ORCPT ); Sat, 15 Jul 2023 03:53:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjGOHxp (ORCPT ); Sat, 15 Jul 2023 03:53:45 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC18D358E; Sat, 15 Jul 2023 00:53:44 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3128fcd58f3so2814267f8f.1; Sat, 15 Jul 2023 00:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689407623; x=1691999623; 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=nXdgGZmClIw2y5+yLCGfpXc796bXl4kQ7ee+T64K4uo=; b=PwVsFYtmxvMSiAQEHcjIruM/oKJvm+GZdX+v3EQVMIjtyg9G/ze9ZJQrmxv4NCw2pg MZgq2fvxZPW3dB59NBhXebmxWXn5rI60bAB7Ft7GCdITE98aby6YFcITPaB29924RAsQ qIefRk5vX7D7yyTWk4g036C3P7ViAFHRXO0bTUms6xHfeQracKlxOTSoV5ueSyVXzfc9 LWF764WuYYIgh8+h13z+jRQuaCsi0w7pb8ZPLvxji8nUx922MEjxSgS0DgIV12rjr6+5 R+zvz5KiL3PEoN5AMQChw95XLCrRj/fRinaV2R+SczBRtcFr4lgSUz7ZMCGddPok5VJG PKFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689407623; x=1691999623; 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=nXdgGZmClIw2y5+yLCGfpXc796bXl4kQ7ee+T64K4uo=; b=FRvs+Jdoi9OSVgQcSJGwPDxDemKRXLYV2Q6bketS22YzHwO7UjzqYTLgJ0e+sCUE59 jYwnbzFePqYYmrjvFOk9zMaG8qBvbuN4t279C6Z/AqOMM2zbOjrXJkbBccmvCUjft4Q3 ioVViu+hHG/MRlunEptWcehZbA0PHQmgK4Y2RQwJyyK/j/ZwLTKNyoFRH/LEFfLY/ilw i+JRsA1pSpz+I2OgW6zNFREZ5v8JCHfEgblXLiW050eGF7nSUAYqy8VcxSqTWTldarQO JA03lsblMeLrpfEQKIpPpzOX4Wq64dck1vBqqA0xrzXLZMuTRxVW00+mR+arOpVSCa2Z KnHg== X-Gm-Message-State: ABy/qLZ+HlZWd7bUZ2gGxVuH4wue/F/T4RpsrI5SOV+6jmnwDYkQSEc3 l/Dd3tTZhlPkbotuby0GSXSXz1ix+Epecxk4 X-Google-Smtp-Source: APBJJlEjboW0Mw0GJEMKk4o267Y0opjo4z5gbY5NMkdzMHWR0B1D43okIC5wkBrr8J5rn9EsemQdbQ== X-Received: by 2002:a5d:44ca:0:b0:314:1582:6eb4 with SMTP id z10-20020a5d44ca000000b0031415826eb4mr6133679wrr.46.1689407623357; Sat, 15 Jul 2023 00:53:43 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id f6-20020adff586000000b003142eb75724sm13001271wro.24.2023.07.15.00.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 00:53:43 -0700 (PDT) From: Benjamin Bara Date: Sat, 15 Jul 2023 09:53:26 +0200 Subject: [PATCH v7 4/5] mfd: tps6586x: use devm-based power off handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v7-4-18699d5dcd76@skidata.com> References: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com, Wolfram Sang 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_BLOCKED,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. Acked-for-MFD-by: Lee Jones Reviewed-by: Dmitry Osipenko 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..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 Sat Jul 15 07:53:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 1808096 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=S0yWZlEf; 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 4R30wK3nTHz20cl for ; Sat, 15 Jul 2023 17:53:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230424AbjGOHxr (ORCPT ); Sat, 15 Jul 2023 03:53:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbjGOHxq (ORCPT ); Sat, 15 Jul 2023 03:53:46 -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 A1E6935B3; Sat, 15 Jul 2023 00:53:45 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbef8ad9bbso24223965e9.0; Sat, 15 Jul 2023 00:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689407624; x=1691999624; 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=cO8MaIrmzLIgpAh79j/PTcb6h7we+UptA1d76S5ZSws=; b=S0yWZlEfOXQCIdfQ7MJ/pLor2v4HmMmfN9UlsoKQIFHefBL4zXFQXlEFgONXXWVska yQev/sBOgNu08yX6LX/1S1dWqBlm9HVCLPnbVNUbi5RtP18YMGtiLxjcOA4jViUCfD28 Ek7fKcPmlKPSEIOgJ+Uaq3iKtPnB/P936EDPHSo7JaeMAZ1fm1jyZSKE++/1XSDTce/w uzvdU7nc/SdoK5kfjpF/r/8cbNFkE85OeSFlbztuRFmCCimEswkNMV2af8AM/4ziq9xe CRCFl2qBwDBxVo54zLGeTEhT5HVF11+7yZ2slZ21TocaPHIfDAnoutrPXOd0xEkBxyTX t+AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689407624; x=1691999624; 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=cO8MaIrmzLIgpAh79j/PTcb6h7we+UptA1d76S5ZSws=; b=XG8APEn6gt6GVcoYBFjlKb++LuKoJERvTTITFzqixMAFe9zVnl6v27F0nIQa9LZKpq k8z1aums1zSvxlAwpjdpYN9qBJTlkuZf3E3yIFoWcAm1+C1GG8XgfUmr+lnGP9l9hF5n iqht54BCiPd9nA1v8oeAJ3i72GYGFllnJNrj3WlSzvacctuepHmlUMj6pREWP+Y0cAb6 m17iISO/pIN9hCfzsAjg4uaGp/HsmP+jjWjKB0it2ff7aCDhBDtVVwfdE30FMGAjZ8Ri 1m8VBRIJru9SLMmGrTFD7u0CuQvC05/8O02lVEEEFtp0VD6QlDalsZn+b1rzMsGIUFry aS4A== X-Gm-Message-State: ABy/qLYlN4/OKdhyVK6a2//aZPle8AJtef81sD1NpgqEPj7osYXaQ08i L25CN3WoXtrzubSXTY8H1OA= X-Google-Smtp-Source: APBJJlGro5VHrnSJt5gm25Ax8kAN55eHOQJS1zTEspa+DjFeZWNzb+DbAda48F6OBIRsbIG1wX1WEg== X-Received: by 2002:a1c:cc15:0:b0:3fc:48e:581e with SMTP id h21-20020a1ccc15000000b003fc048e581emr5990254wmb.24.1689407624088; Sat, 15 Jul 2023 00:53:44 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id f6-20020adff586000000b003142eb75724sm13001271wro.24.2023.07.15.00.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 00:53:43 -0700 (PDT) From: Benjamin Bara Date: Sat, 15 Jul 2023 09:53:27 +0200 Subject: [PATCH v7 5/5] mfd: tps6586x: register restart handler MIME-Version: 1.0 Message-Id: <20230327-tegra-pmic-reboot-v7-5-18699d5dcd76@skidata.com> References: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> In-Reply-To: <20230327-tegra-pmic-reboot-v7-0-18699d5dcd76@skidata.com> To: Wolfram Sang , Lee Jones , rafael.j.wysocki@intel.com, Wolfram Sang 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_BLOCKED,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 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. Reviewed-by: Dmitry Osipenko Acked-for-MFD-by: Lee Jones Signed-off-by: Benjamin Bara --- drivers/mfd/tps6586x.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index b12c9e18970a..1777d8d3a990 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,19 @@ 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; + + /* 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 +589,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;