From patchwork Mon Feb 12 16:28:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 199900 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp29890dyb; Mon, 12 Feb 2024 08:33:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXZjEPx1hgil6VyH9A+X/KFAJWR1LKpoccnfWyYyykyc44Oo1JOY8KSkUwxu0SHlwTqbxp8o0g0u9MC0LvfUzVGEIJ/Nw== X-Google-Smtp-Source: AGHT+IELgLx08sleR15Lna+qFJ9vLs5SCF6FKJ0yOhe2hKeSJT/AK/gvzR783l/PmlKBZA5NByQn X-Received: by 2002:aa7:d1d4:0:b0:560:d9d5:7b0f with SMTP id g20-20020aa7d1d4000000b00560d9d57b0fmr5004206edp.22.1707755598414; Mon, 12 Feb 2024 08:33:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707755598; cv=pass; d=google.com; s=arc-20160816; b=c9RAjwMFt7gUqtQtAdwyumXQYDmdGeVqy60YfthJtftUThdrF1px0eTOdpt0E1YWKE yjAEVL/08JlSqgyhK04kHOtu6vWk3FkBIoPnj2MB8QpwSwLwfhriBXyVst3NkZ47HJbC fx433QpoCmU+NdJ+cej8cOiLASJRKbb5cN/V9ez9/bAI8UF9FYXcttlgazEwq+FSyrwy wD+LKIdmzp2mX1rM6vDIl/TOvHRTne+kwmvRGoHn/b8kNsML2xf+sPMqw5Q2MTKDUCmO mnw+D75vXkwR+WZgS7RHrEFD/HZRGNUKXleQkGDBZDJ8dfdVIGKeIBnxk3UGZ1lXoIJU Dg9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+yoH0oyAcvSMYuuy/HNbc6iZw+avNZNinJT/iIL/4IE=; fh=K33/rwd8WBL3i1rSZjaBJw8eXJjwaXRtXDC3DbQOeX4=; b=fFvnNbiodh2BAexkXt519fW4dBxbKahFJFmMT25oJT1yquCCPhn7SHsMpLOAqF6+56 wuxTaizNKRBrCpNFMPhkt7J7fpnqA5RDuLiMaQfh8aiW+qfhGoItf0Cx54DfjPwCdd71 MByh8lr6BXOSVxEUQ0i3TV+1e51dpd3mFyrtkH/ST9sYqbdTXYubu6c1HsL2s3zgz2IA Y0g3umkVjt4IOTF19WsN6EJDArp7JglA08CM9QNIYSgIJLDKh5Xv59rjUSaK71jUTZKr B4c4/lfrh3LArudL446XgKLO6TfC6VmpGw9czi7s7AJJGQN9FAHJG7WK/VONWvP3f7xC 1RbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=TLK16n9+; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-61967-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61967-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com X-Forwarded-Encrypted: i=2; AJvYcCXRERzrW/JFj9qG+YGaOdI7rHq/Jz3CFdnd3vVgsG+csAQ0/NP/21uVyDUMgUgDP/PmKJesT/8M8Hgnzo00ND6Hhr5h6w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s23-20020a50ab17000000b00561781085a5si2378727edc.254.2024.02.12.08.33.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:33:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61967-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=TLK16n9+; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-61967-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61967-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0A12A1F22387 for ; Mon, 12 Feb 2024 16:33:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 818A14C627; Mon, 12 Feb 2024 16:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="TLK16n9+" Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0578C3F9DD; Mon, 12 Feb 2024 16:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707755333; cv=none; b=gNGYccmxXTQOFUOeJTjFqEwWyv7R/xG5BF2E/1UYXBR7QYyOlEIIPcI3P0LAEDghNJFNDYQlDsQxF45KDSXx/t/o5YiGmFB2+1MpUtrO9t+I352+qgpQfHu7XHhFtT/1SxEjwGDp3NQ5dohtCwST8n/34avKjWPwpv8MP9LJiR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707755333; c=relaxed/simple; bh=b1HCM6PNhU5iOFP0yy2ZAE2FiVY5BYt6sfsBzt/lauQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JZmLGvmEJUHS7PJb8bsfa1jkxQjA3QO73mUQC5JBf6Ar9XWhLpyLhQvgiSlszrWUkBQsVMMQnO930i2Em+jsukpVRU3Uwqyu0535ygIPsR0IfrJOpWUrZxcJvXiPHEDUwNZ3fH0cu0ngI9cU333Z9tweBrcEmBlZFX2Wd7SHxlU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=TLK16n9+; arc=none smtp.client-ip=198.47.23.248 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 41CGSgvQ045218; Mon, 12 Feb 2024 10:28:42 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1707755322; bh=+yoH0oyAcvSMYuuy/HNbc6iZw+avNZNinJT/iIL/4IE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=TLK16n9+GoYhFp3X8+Bkq58+TF+rHyEGH68TaeP6+J15nmF4tWNuo96NjrW8ke5j1 c2kc/JV4Dl59yTQDPmCCJg2OruvzrIRDVtURi3K9cKICpPrsKOsJVjj24kGTXu1DL3 IcHlxuXakdZWIFr0Drl9wXmjKFUdkEwnsfsy5ORw= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 41CGSgXb046974 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Feb 2024 10:28:42 -0600 Received: from DFLE115.ent.ti.com (10.64.6.36) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 12 Feb 2024 10:28:41 -0600 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 12 Feb 2024 10:28:41 -0600 Received: from lelvsmtp5.itg.ti.com ([10.249.42.149]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 41CGSWRA090688; Mon, 12 Feb 2024 10:28:41 -0600 From: Andrew Davis To: Sebastian Reichel , Manivannan Sadhasivam , Cristian Ciocaltea , Florian Fainelli , Ray Jui , Scott Branden , Bjorn Andersson , Konrad Dybcio , Sean Wang , Matthias Brugger , AngeloGioacchino Del Regno CC: , , , , , , Andrew Davis Subject: [PATCH v4 14/19] power: reset: regulator-poweroff: Use devm_register_sys_off_handler(POWER_OFF) Date: Mon, 12 Feb 2024 10:28:26 -0600 Message-ID: <20240212162831.67838-15-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212162831.67838-1-afd@ti.com> References: <20240212162831.67838-1-afd@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790711534689899537 X-GMAIL-MSGID: 1790711534689899537 Use device life-cycle managed register function to simplify probe and exit paths. Signed-off-by: Andrew Davis --- drivers/power/reset/regulator-poweroff.c | 36 +++++++++--------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/drivers/power/reset/regulator-poweroff.c b/drivers/power/reset/regulator-poweroff.c index 15160809c423a..fed4978e38580 100644 --- a/drivers/power/reset/regulator-poweroff.c +++ b/drivers/power/reset/regulator-poweroff.c @@ -13,18 +13,15 @@ #include #include #include +#include #include #define TIMEOUT_MS 3000 -/* - * Hold configuration here, cannot be more than one instance of the driver - * since pm_power_off itself is global. - */ -static struct regulator *cpu_regulator; - -static void regulator_poweroff_do_poweroff(void) +static int regulator_poweroff_do_poweroff(struct sys_off_data *data) { + struct regulator *cpu_regulator = data->cb_data; + if (cpu_regulator && regulator_is_enabled(cpu_regulator)) regulator_force_disable(cpu_regulator); @@ -32,30 +29,24 @@ static void regulator_poweroff_do_poweroff(void) mdelay(TIMEOUT_MS); WARN_ON(1); + + return NOTIFY_DONE; } static int regulator_poweroff_probe(struct platform_device *pdev) { - /* If a pm_power_off function has already been added, leave it alone */ - if (pm_power_off != NULL) { - dev_err(&pdev->dev, - "%s: pm_power_off function already registered\n", - __func__); - return -EBUSY; - } + struct regulator *cpu_regulator; cpu_regulator = devm_regulator_get(&pdev->dev, "cpu"); if (IS_ERR(cpu_regulator)) return PTR_ERR(cpu_regulator); - pm_power_off = ®ulator_poweroff_do_poweroff; - return 0; -} - -static void regulator_poweroff_remove(struct platform_device *pdev) -{ - if (pm_power_off == ®ulator_poweroff_do_poweroff) - pm_power_off = NULL; + /* Set this handler to low priority to not override an existing handler */ + return devm_register_sys_off_handler(&pdev->dev, + SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_LOW, + regulator_poweroff_do_poweroff, + cpu_regulator); } static const struct of_device_id of_regulator_poweroff_match[] = { @@ -66,7 +57,6 @@ MODULE_DEVICE_TABLE(of, of_regulator_poweroff_match); static struct platform_driver regulator_poweroff_driver = { .probe = regulator_poweroff_probe, - .remove_new = regulator_poweroff_remove, .driver = { .name = "poweroff-regulator", .of_match_table = of_regulator_poweroff_match,