From patchwork Sun Jan 30 23:37:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 538371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9191AC433F5 for ; Sun, 30 Jan 2022 23:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357170AbiA3Xkm (ORCPT ); Sun, 30 Jan 2022 18:40:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357405AbiA3XiF (ORCPT ); Sun, 30 Jan 2022 18:38:05 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F6E1C061760; Sun, 30 Jan 2022 15:38:03 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id u14so23251503lfo.11; Sun, 30 Jan 2022 15:38:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wEeGalIPQ9GIIDvt4ZGJ+mYKkZoiFtMFy2ITVcPwwOI=; b=jXXBBfwPJ7SdtaD0pclW/HMx76vc8RahjAuPQm5Z/0dXxW/074tzfimlFO1HkDBvcr oaZmouil0FqH92hbizW5my46ifg5DAFhrVT4LPFQpqXlLAxmnLJ6s1I5wLZSpyLZkBO0 wmI0HqfYIjv7H9ry2CW8BCr2FKRe9TovMRMPOdztHPrunU9Y7lzjTWnUadttQIH5bcvW vttSNQ9r1vC1IZO5YVlqjP01k8/CcmcrMHA8TiKEuoGV1yx8sOgJc71/KAtv9CA4CYS0 o8OCrmOu9r4n3DeN2/5U1nzk/Hg0gBL3B1cSmVdN8RggR9Ftjf3x1TwywZSLzo/+Zh9b 2sCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wEeGalIPQ9GIIDvt4ZGJ+mYKkZoiFtMFy2ITVcPwwOI=; b=y4kMksU65D1pJavAk3ETN4c8isOcOOiiONvGRreiivH+/h02zucilMkzrRM1OerMoJ PofIEb4kUs93yZEjfkQUCGb44UUCn0Dsh+AfuIJ01Z95FmGo20x09tbfSEJXScPcd/aa pO50QreBfP1Fk/Dzz9Pp+N0Xr9EgUfXfVKbTQ3k4txNxuUtrkQGbSvNj+veGDIYZ38zf opbKEswjakjqTO0VI0MO7lNzm2eIjnpIbK144dWOWEJbDX7fJD4skzeUZSt17bJRerE4 tc9/UxHPcyd7DfHnUvZmQEisT1y7TvdwSYhAKS1sXMx9gLNTnUfAM2nZIIm5FuPQlU5F tdoQ== X-Gm-Message-State: AOAM531c+MK5ymDQtlFQamP51XPbA8uhsziubhpEl2ffJPkJdhIQy/yk SpcKubuphbqfqULRr7sbxJs= X-Google-Smtp-Source: ABdhPJxKcR6AU2adDJMgqBbtDaQvM6Qs2pl/Zem+Cp2eBfoUK309RxSg7fIwfBi/lJNJPdOsuZTuaw== X-Received: by 2002:a05:6512:402a:: with SMTP id br42mr13689925lfb.336.1643585881636; Sun, 30 Jan 2022 15:38:01 -0800 (PST) Received: from localhost.localdomain (109-252-138-126.dynamic.spd-mgts.ru. [109.252.138.126]) by smtp.gmail.com with ESMTPSA id a24sm1262950ljp.112.2022.01.30.15.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 15:38:01 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Russell King , Catalin Marinas , Will Deacon , Guo Ren , Geert Uytterhoeven , Greg Ungerer , Joshua Thompson , Thomas Bogendoerfer , Sebastian Reichel , Linus Walleij , Philipp Zabel , Greentime Hu , Vincent Chen , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Yoshinori Sato , Rich Felker , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , "Rafael J. Wysocki" , Len Brown , Santosh Shilimkar , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Pavel Machek , Lee Jones , Andrew Morton , Guenter Roeck , Daniel Lezcano , Andy Shevchenko , Ulf Hansson , alankao@andestech.com, "K . C . Kuen-Chern Lin" , =?utf-8?b?TWljaGHFgiBNaXJv?= =?utf-8?b?c8WCYXc=?= Cc: linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org, xen-devel@lists.xenproject.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v6 20/21] regulator: pfuze100: Use devm_register_sys_off_handler() Date: Mon, 31 Jan 2022 02:37:17 +0300 Message-Id: <20220130233718.21544-21-digetx@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220130233718.21544-1-digetx@gmail.com> References: <20220130233718.21544-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use devm_register_sys_off_handler() that replaces global pm_power_off_prepare variable and allows to register multiple power-off handlers. Acked-by: Mark Brown Signed-off-by: Dmitry Osipenko --- drivers/regulator/pfuze100-regulator.c | 38 ++++++++++---------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c index d60d7d1b7fa2..2eca8d43a097 100644 --- a/drivers/regulator/pfuze100-regulator.c +++ b/drivers/regulator/pfuze100-regulator.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,7 @@ struct pfuze_chip { struct pfuze_regulator regulator_descs[PFUZE100_MAX_REGULATOR]; struct regulator_dev *regulators[PFUZE100_MAX_REGULATOR]; struct pfuze_regulator *pfuze_regulators; + struct sys_off_handler sys_off; }; static const int pfuze100_swbst[] = { @@ -569,10 +571,10 @@ static inline struct device_node *match_of_node(int index) return pfuze_matches[index].of_node; } -static struct pfuze_chip *syspm_pfuze_chip; - -static void pfuze_power_off_prepare(void) +static void pfuze_power_off_prepare(struct power_off_prep_data *data) { + struct pfuze_chip *syspm_pfuze_chip = data->cb_data; + dev_info(syspm_pfuze_chip->dev, "Configure standby mode for power off"); /* Switch from default mode: APS/APS to APS/Off */ @@ -611,24 +613,23 @@ static void pfuze_power_off_prepare(void) static int pfuze_power_off_prepare_init(struct pfuze_chip *pfuze_chip) { + int err; + if (pfuze_chip->chip_id != PFUZE100) { dev_warn(pfuze_chip->dev, "Requested pm_power_off_prepare handler for not supported chip\n"); return -ENODEV; } - if (pm_power_off_prepare) { - dev_warn(pfuze_chip->dev, "pm_power_off_prepare is already registered.\n"); - return -EBUSY; - } + pfuze_chip->sys_off.power_off_prepare_cb = pfuze_power_off_prepare; + pfuze_chip->sys_off.cb_data = pfuze_chip; - if (syspm_pfuze_chip) { - dev_warn(pfuze_chip->dev, "syspm_pfuze_chip is already set.\n"); - return -EBUSY; + err = devm_register_sys_off_handler(pfuze_chip->dev, &pfuze_chip->sys_off); + if (err) { + dev_err(pfuze_chip->dev, + "failed to register sys-off handler: %d\n", err); + return err; } - syspm_pfuze_chip = pfuze_chip; - pm_power_off_prepare = pfuze_power_off_prepare; - return 0; } @@ -837,23 +838,12 @@ static int pfuze100_regulator_probe(struct i2c_client *client, return 0; } -static int pfuze100_regulator_remove(struct i2c_client *client) -{ - if (syspm_pfuze_chip) { - syspm_pfuze_chip = NULL; - pm_power_off_prepare = NULL; - } - - return 0; -} - static struct i2c_driver pfuze_driver = { .driver = { .name = "pfuze100-regulator", .of_match_table = pfuze_dt_ids, }, .probe = pfuze100_regulator_probe, - .remove = pfuze100_regulator_remove, }; module_i2c_driver(pfuze_driver);