From patchwork Mon Feb 12 16:28:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 199892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp28100dyb; Mon, 12 Feb 2024 08:30:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUbTcJtl/mzA8ATgy9omyd955llaEIFK39IuzesHZvYOUnwn4By3barMBWVirPYt6HdupM0R+cNablIIwI/QBWCGetOWQ== X-Google-Smtp-Source: AGHT+IGwnZQzw6ToIfzouYfCpc0LNPmj9mmp6wKBosWIcfSwLDxR1Jn3yDTuyYHag4rWegHeutez X-Received: by 2002:a9d:5615:0:b0:6e1:13a2:3948 with SMTP id e21-20020a9d5615000000b006e113a23948mr7148616oti.5.1707755436387; Mon, 12 Feb 2024 08:30:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707755436; cv=pass; d=google.com; s=arc-20160816; b=MzkORGIksVhOZjLOVr70VeLiz6/uJbvwRQmUdJGyxAXTN0b0TVE+7hbwMp61J/Uyft n17o3h37zpL1mC8tsDSBAGJyjukjufb/FhyIzbP0Yoiei4U7pTsOQ7j/81SCdDKhfYq2 ECPOX3NfClYQZ63a6ScebAFg4mlJjIcRAXky70ToHXv4TFs3QJqPmu952ALkM4+UZ/Js Tz6FjkZ2C1+sRfmxgYt7f38kQ+V4sMdth+qBp6hYB9tTAkVJOEyPYBoBp1iTWTBooPyv vqn6qWqLV/c6W9Zlueuwk584hFrzNE2FX2bK4CIsqo/iRKCZDAXMTQcjpj0XYLQbgsRr ebBQ== 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=i7qWnsqZcMyjCPrKe+aclIBz5H0LOd1Ak6wM/UWv8kY=; b=0tnFBqQ+Vv5W7XAU7xX+OR43BmRTrknYGHFYup7TT21ivG0d2ey/33PROFlf7DLhvW IOWOhtnXSaPqn8KnYIIodiJStYvO0/ZhqqLhZY4rEtKM9eMhGYGkZfHc8Ps5pP5pDT98 Ng11VLWaSPdBji/ymk3aYKuroVLdbBh0l0AqAWin0ffjm7WkmnqSlqJWyqVBTmenY5ez lTVIEbTf6hfbVpcoW5XoiC4G6xotA6Si0Kz1KBUVWZcwKvFgDfrCpCU+fNcqQeaKzrNu erW4UvUdhkHQ2poMzyI1xzIIewKBeVnW61112+/0B28hisOBA+Fppfb8445jijCQV5BE JeZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=c6jSXBVH; 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-61958-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61958-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com X-Forwarded-Encrypted: i=2; AJvYcCW+YWnRKzRiHwyxjYpqbnE1nF89nWDQ4YQwDxgS5tARdduQ+XEzTcrDMo/EbrwN3NQ2vfnrxKCIgh74HnSbtEiYW4JVMw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h8-20020ac85848000000b0042c5fb192b6si834744qth.348.2024.02.12.08.30.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:30:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61958-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=c6jSXBVH; 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-61958-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61958-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1FE771C21730 for ; Mon, 12 Feb 2024 16:30:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A23A53FB1E; Mon, 12 Feb 2024 16:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="c6jSXBVH" Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (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 825C53D38D; Mon, 12 Feb 2024 16:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707755329; cv=none; b=DCAhJ6MdXPtBs3otgRYFBvYFUejuvAHdhkYN5b8x+oinEwGItRFNH611AgIHVTLHr6PheXqwGGR2ZPEMP7kumOoeXZ38K9WoAtrhqVhIfIXs+WdI5ced9ivib5m/pRZ20j0yKlSnuVUWPiuJ+S6KLj7Rc9ClhDbqUX0K23fI61A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707755329; c=relaxed/simple; bh=piwvd9XDrLI4E6nIns4idZqQIBccnh+XSsbLYNv6vd0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u9GlWnGY+cJQvd9s+ZQKNNqfaC6YGpB3qMk+hMuKFt2RvqdWHCYb8wZ0immd404qEZhEXG41Smhr6ds/COvcmZpTEtCJwwaIW2qQ52Nw66xrTaK/JGDPOxrLO0YC7w140cnSqJacOFC5chV8+Rxv20QHhmrSWPEG8ExHrAucMDE= 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=c6jSXBVH; arc=none smtp.client-ip=198.47.23.249 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 lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 41CGSYv2004138; Mon, 12 Feb 2024 10:28:34 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1707755314; bh=2cm9ruqVmpJKRpRfi1ywbymPKB5JK0jfSdZffEo1IXY=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=c6jSXBVHtvnTWWCo724wItjQ8Y/gpXn7j/EbWFtPX6MrjgYdu5WCu/Xdoeed1Op19 qpbgtQDbVdnGysO2Sx9iNyZK4A1BhgWsaAuFYzTqJd11SCYrEUjah/QDaUKZSCfoC2 dkFIBQ6MKAh+Tf0M72HhnFNr2C9cLjx+1Zo/DLyU= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 41CGSY2g024836 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Feb 2024 10:28:34 -0600 Received: from DFLE109.ent.ti.com (10.64.6.30) 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; Mon, 12 Feb 2024 10:28:34 -0600 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) 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 via Frontend Transport; Mon, 12 Feb 2024 10:28:34 -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 41CGSWQw090688; Mon, 12 Feb 2024 10:28:33 -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 02/19] power: reset: atc260x-poweroff: Use devm_register_sys_off_handler(POWER_OFF) Date: Mon, 12 Feb 2024 10:28:14 -0600 Message-ID: <20240212162831.67838-3-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: 1790711364587912323 X-GMAIL-MSGID: 1790711364587912323 Use device life-cycle managed register function to simplify probe and exit paths. Signed-off-by: Andrew Davis Reviewed-by: Cristian Ciocaltea --- 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", },