From patchwork Thu Feb 8 17:03:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 198510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp318660dyd; Thu, 8 Feb 2024 09:13:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXAATAf0qtSestn9yXjOqSvGKTmmQgSttYbSSAWzufrzAxQDR5qz2UEDhnFgw2+r8b2W6krR5GFnVC8vQ5tzHvT4Ednyg== X-Google-Smtp-Source: AGHT+IFpz1V48r9YnmqN2J2uHvd50nzZTqA2qKE1NrKtYG867iEOA2ZtAGsl1deBJQfULZiZcDB8 X-Received: by 2002:a17:90a:53c2:b0:296:1ac3:c572 with SMTP id y60-20020a17090a53c200b002961ac3c572mr252678pjh.13.1707412431472; Thu, 08 Feb 2024 09:13:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707412431; cv=pass; d=google.com; s=arc-20160816; b=Cwp9OIGbu9zht1Zwaa8OebRBcl1Ie2V8bbeVbskOK8vuHV3a6ffKSzkin2p939SfNp fu12Fp7+6c+uJ+JgfjMoa8Q6qfESk8Zl7Q7aRABkmFwLe7etjf4SlFc3rUlh/OQ/MLS/ ctD0gT2YGYcmyFm7lvQ7ac5c95DiofKRGnV2ruTpPB4HgpaqkhAE/4uw84bv6Q9nK/it E8sAGGCiLT5S9AFlVn+tapIa7AWxvIp7rDHKVhl5WB3rlB3ZCARgto/wJIU8o+B0GxkH wxeubBriuY7KTnWEp7KcKotfOeTUuNl0XlCucaq0+Eg5NvD4DluhG4P3D8Ul+ClUzWN8 5plg== 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=2cm9ruqVmpJKRpRfi1ywbymPKB5JK0jfSdZffEo1IXY=; fh=8poBLsuDatWg6rMxU4QN60hV3SGNlDdvebi/SHyZjws=; b=N5ajkryBDC8zXYofyFyR1BhhlpVuLNrw67ArmKlsz4k8772+bsyP8tYyYdGSgMQAL9 n1+God/lXYwoCU6HzxWSEQSGJlM8sb2ghFlSNnPM5prwflIzi2jWZmA+XNwGfCuFFzX3 YKISDgfSGHf9lWeWNisJPPkokq4Q/12NtKrChxgKxKvDDL2vAujgrTdYVFosmL359St6 tFaENk1iQADBpzCy+e5Kk3rSt/9pkfXYpxoKWKAwbW9/pdv+2/lBYYsRiE2cn7Uwm0T9 u9FpTlzVePdUY4e/V3iFa+6dCC1tpaNxnuHIckJmLb6UxK/pQgbgboNJw84ifcDnaYQG rtaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="a2mm/96D"; 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-58414-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58414-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com X-Forwarded-Encrypted: i=2; AJvYcCVl9o79Q3Swhuj+F7JCLZzsS24vJCCcuOzrGAm/hXHZXGi0RgWHqJa2E9FHQytvXUie9+BMZ1i8i1tphp8TRQk6Dk0T0g== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id pj8-20020a17090b4f4800b00296c2c83cffsi1909617pjb.68.2024.02.08.09.13.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 09:13:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58414-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="a2mm/96D"; 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-58414-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58414-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BEAF22847A7 for ; Thu, 8 Feb 2024 17:09:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9E3B1339B8; Thu, 8 Feb 2024 17:04:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="a2mm/96D" 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 BDECD84FB4; Thu, 8 Feb 2024 17:04:37 +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=1707411879; cv=none; b=kYB7s1jIYPi5Q7YOLZjeUmt08AAubI45xFIVQrDFuYQsfVpNXGk4yOUEF1uOkobCzTARnqWxGuMfqVpurS8MDRz9HM2fhC7LigoW+7UezqUVJthG0EuSnCO7geBmIlqyrUlmqy2lI+Mqge5472BkMMODKPLokxqXFmH48FUdmcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707411879; c=relaxed/simple; bh=piwvd9XDrLI4E6nIns4idZqQIBccnh+XSsbLYNv6vd0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p90RG+GHZe0r1ntiT3k7bRbFcpWRlufmVIaAfvOhhLYf0R+kxBCKhDFgRt2W6Jh1LURllTRgPGGGvE3WgAyt4z0XWiEPdWQoFe3F9KG5K6ISZqWPKuGHKxtobSMx146fiYM8Y1LOuUSn0J+cs/J3dZp0hxNEK81ds7U23+5ejZk= 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=a2mm/96D; 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 lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 418H4EgM018136; Thu, 8 Feb 2024 11:04:14 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1707411854; bh=2cm9ruqVmpJKRpRfi1ywbymPKB5JK0jfSdZffEo1IXY=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=a2mm/96D/h/wVGxYXwiMncfstNtfHFmpzKH4wJTmb/tRA4GbRPKHCEmsMhR6ksrDN urzQNhBn9oLvRVQ0HWXMs+XhpBCybLK44kPY1M3x6JnCFcartY68vi/0oHCYR5HW7F kRoT+U7jAtnCV2bfcagQrDO0gjGiOTLVt3nYn19s= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 418H4DxE023306 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 Feb 2024 11:04:14 -0600 Received: from DLEE101.ent.ti.com (157.170.170.31) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Thu, 8 Feb 2024 11:04:13 -0600 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE101.ent.ti.com (157.170.170.31) 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; Thu, 8 Feb 2024 11:04:13 -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 418H4B64091006; Thu, 8 Feb 2024 11:04:13 -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 v3 02/19] power: reset: atc260x-poweroff: Use devm_register_sys_off_handler(POWER_OFF) Date: Thu, 8 Feb 2024 11:03:53 -0600 Message-ID: <20240208170410.67975-3-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240208170410.67975-1-afd@ti.com> References: <20240208170410.67975-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: 1790351698067969884 X-GMAIL-MSGID: 1790351698067969884 Use device life-cycle managed register function to simplify probe and exit paths. Signed-off-by: Andrew Davis --- drivers/power/reset/atc260x-poweroff.c | 38 ++++++++++---------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/power/reset/atc260x-poweroff.c b/drivers/power/reset/atc260x-poweroff.c index ce2748d3282c3..e3e4621ccb1dd 100644 --- a/drivers/power/reset/atc260x-poweroff.c +++ b/drivers/power/reset/atc260x-poweroff.c @@ -19,9 +19,6 @@ struct atc260x_pwrc { int (*do_poweroff)(const struct atc260x_pwrc *pwrc, bool restart); }; -/* Global variable needed only for pm_power_off */ -static struct atc260x_pwrc *atc260x_pwrc_data; - static int atc2603c_do_poweroff(const struct atc260x_pwrc *pwrc, bool restart) { int ret, deep_sleep = 0; @@ -164,11 +161,15 @@ static int atc2609a_init(const struct atc260x_pwrc *pwrc) return ret; } -static void atc260x_pwrc_pm_handler(void) +static int atc260x_pwrc_pm_handler(struct sys_off_data *data) { - atc260x_pwrc_data->do_poweroff(atc260x_pwrc_data, false); + struct atc260x_pwrc *pwrc = data->cb_data; + + pwrc->do_poweroff(pwrc, false); WARN_ONCE(1, "Unable to power off system\n"); + + return NOTIFY_DONE; } static int atc260x_pwrc_restart_handler(struct sys_off_data *data) @@ -211,14 +212,14 @@ static int atc260x_pwrc_probe(struct platform_device *pdev) if (ret) return ret; - platform_set_drvdata(pdev, priv); - - if (!pm_power_off) { - atc260x_pwrc_data = priv; - pm_power_off = atc260x_pwrc_pm_handler; - } else { - dev_warn(priv->dev, "Poweroff callback already assigned\n"); - } + ret = devm_register_sys_off_handler(priv->dev, + SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_DEFAULT, + atc260x_pwrc_pm_handler, + priv); + if (ret) + dev_err(priv->dev, "failed to register power-off handler: %d\n", + ret); ret = devm_register_sys_off_handler(priv->dev, SYS_OFF_MODE_RESTART, @@ -232,19 +233,8 @@ static int atc260x_pwrc_probe(struct platform_device *pdev) return ret; } -static void atc260x_pwrc_remove(struct platform_device *pdev) -{ - struct atc260x_pwrc *priv = platform_get_drvdata(pdev); - - if (atc260x_pwrc_data == priv) { - pm_power_off = NULL; - atc260x_pwrc_data = NULL; - } -} - static struct platform_driver atc260x_pwrc_driver = { .probe = atc260x_pwrc_probe, - .remove_new = atc260x_pwrc_remove, .driver = { .name = "atc260x-pwrc", },