From patchwork Mon Feb 5 19:44:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 197027 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1157235dyb; Mon, 5 Feb 2024 13:33:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHs5q2EAC1RvpTvHHmVoCpHse+Ag9CSpfBJAYYCg3vS4N76lFSZXE32EJREJDTJP6da2jwB X-Received: by 2002:a05:6358:93a8:b0:175:e1fd:11f8 with SMTP id h40-20020a05635893a800b00175e1fd11f8mr1060025rwb.29.1707168797599; Mon, 05 Feb 2024 13:33:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707168797; cv=pass; d=google.com; s=arc-20160816; b=HLWoBFyAXAS1xB9uhgrl0yTrfvQuSNDEOcRtSJ9fZpmTegdKJRGoRYwu/AoWyurZl/ lkl6Nto2/CsTsnWd3ISX2VYgqm4/wvobRukaiBZGBPSOdbYsvXmQn50CkK9H6INdGPjA J3AKcEliaw6ZCPbtBBCLjk6CBLLgr4eb4LwmroPToEkPVl86rY2t2lL+hg5+udMNCE1I xBSFPQXcdCcptmw6NdOs+yMHm3aN/vfL8hWA/8glZATR8rSdPhk5rAvnxrryU2q90UeK Wkjcvse1wlPo5kFP7X8/e3AtEcWnEHke9+4qCuFIDMW/uDzREMtKsWVXOqkp2M5zkLJ8 5Vag== 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=7Wxp+3RUoILMb+OMwOoXd6SSvzW4dV0tdT2bZv008c4=; b=0g6MMkSedP1RFUzBJOtQckFo4cZPTiL10WpTbaNZMokHCcnAzdisXpUHJ9kVPY1Lfr 5oepk8aCg+QSC2FurpPd1FCLy2e7YRprVAABQia6/olIJy5Ayj4VyXWCOOzRZCz1u2QR 4U0VlTboBmYSCdYPPgzl2xaSOopdbAhRnRB1NpMjQAtuEQPS5IdiQIv62IPPeHIyRW6+ uGLBPtSwV408IpHGMKBVrucsXblqqElNxFp6msjE7tot0oXFVzsXpdhBd7rfG4lSz7We aOhZSF1OEBcgvtKggImKpT/Z4gozYtL03qDDjRfjUpGrqO/2rMCIvY5XNwREi7U0HHPW aP5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="F9iI/LUd"; 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-53846-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53846-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com X-Forwarded-Encrypted: i=1; AJvYcCUP30i4CgXhJH3g8ERHlIwqZc4oiXXsPqoJOsvrUQZnrQ+kTVnRRIqYPsoJj3Vj96CyN35d83AdxAlDyilfVwhWOfQYGg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 1-20020a631441000000b005d8b8c6f94csi462536pgu.565.2024.02.05.13.33.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:33:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53846-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="F9iI/LUd"; 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-53846-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53846-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 045D428DCCD for ; Mon, 5 Feb 2024 21:26:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6A17745C5; Mon, 5 Feb 2024 19:45:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="F9iI/LUd" Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (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 818A167C73; Mon, 5 Feb 2024 19:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707162304; cv=none; b=UAvKAMGSnNLrPhW1k5IjUFpLVfKa+koWOrDqjMDLKwaNbndDr09nWZ1KaY9yHTuxBbi0sNTuqoOyXmKk3By8o+MBtQVoCV+Gjw01Rz/kNV5iqJvg9O9uu/M4zbyz8EAD1TAbNWDvgWe8BZGy8C3/bbtRrLNQR28A3hnr4WvAUFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707162304; c=relaxed/simple; bh=b1HCM6PNhU5iOFP0yy2ZAE2FiVY5BYt6sfsBzt/lauQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D7xjpDQz0MIu1Xc1uZtqymacYCAiEELYl+W8Na0DvoQqX2MM1Q83Z+tEqIW82V6Ng9RWNWtI/y4+nB2EixZxfO+O2WIXjtbXSeIm+DBThhye2xwxPhn0M2xU51nnRboqZuTmMIx0cdhZ5JVi1Kq9DwxgziTPnH3P+OD/KRCdCc4= 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=F9iI/LUd; arc=none smtp.client-ip=198.47.19.141 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 fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 415Jim2e010991; Mon, 5 Feb 2024 13:44:48 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1707162288; bh=+yoH0oyAcvSMYuuy/HNbc6iZw+avNZNinJT/iIL/4IE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=F9iI/LUd62aO4jAa5xw0Msug8EiYAOLBWp7QTaKA02TbzRmqYHEkJpjkya+uSv0q3 5uKlMIABgZXPUh60SVK4wZCVVdekaBR3EAqm6kisPeH5DyLEUqUf7ptfYi36jVRx3R A/2jNOmItuKLr9HIwyCUfv5V7YWNoa+5hQNTc/UU= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 415Jimbi073209 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 5 Feb 2024 13:44:48 -0600 Received: from DLEE112.ent.ti.com (157.170.170.23) 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; Mon, 5 Feb 2024 13:44:48 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE112.ent.ti.com (157.170.170.23) 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, 5 Feb 2024 13:44:48 -0600 Received: from lelvsmtp5.itg.ti.com ([10.249.42.149]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 415JicQb028467; Mon, 5 Feb 2024 13:44:47 -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 v2 14/19] power: reset: regulator-poweroff: Use devm_register_sys_off_handler(POWER_OFF) Date: Mon, 5 Feb 2024 13:44:32 -0600 Message-ID: <20240205194437.180802-15-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240205194437.180802-1-afd@ti.com> References: <20240205194437.180802-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: 1790096229081031217 X-GMAIL-MSGID: 1790096229081031217 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,