From patchwork Fri Apr 28 11:28:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 88613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp878735vqo; Fri, 28 Apr 2023 05:05:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67zKQb67k7XMsMp6ikHvk5ozYXLv7WCj8Hx9WTzEfJE/AKpFSQ+TWlGIlpaMoH3gxfMSvJ X-Received: by 2002:a05:6a20:12d6:b0:f3:256:24d3 with SMTP id v22-20020a056a2012d600b000f3025624d3mr6895563pzg.11.1682683551705; Fri, 28 Apr 2023 05:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682683551; cv=none; d=google.com; s=arc-20160816; b=kBnNPaWKVfEGGzj4rV4OSiIBaKyck4bRs8htAL9eulKPtJhKIc4fBxIeTi+udEIa6t a7ZPRIdt+e+1GIM8I+G5W1nEn9rWDnjU02ReIGM9hsMaRpZAMYVcv3p46DFNMnl21qWU cyutNPL5Jjg0kak4v79fc9Gis+eqwwXWCur/YW22w/Z92YOqPZlT96V+ObqO4cBJBquG FHdz/5I9cvvoOrafKPKPQXZSnNYMsQiagYyOqdnjqms1ISrmaJRxNtgU6XDBEIRBEVse 4arrJdMKW4P3Cm6VnxTrMqBd2KyUvzTxb98rrQcwXcAe4mAvU/Bw5CFpy4x301CpbKUJ Xdvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MNil8LLz7Ox6rqRyom3f5t42db/SNzYEqHrz9Y8QZII=; b=QWMWYIRlI4NtcR9CiqihCuapsFQQG4WeYwD27AV42D6ZhtRZTCT1K+gbqDBem+vnsY iQUkgeVc8HipCsDyMqMoDfdprBHZJu21UqQo0d/JYYeOpLxqO3bzobJtOotblAUlxSEF jn00g6TKAty3irKTQK+B98UFMEQ6gY/kVJaG06mtlY8yxjhehQxWqIlC7NaKY3H5EAgc Q+bslq1YA3zIx8VOjiDu1nlyPj5e6clKy0UA+Q4WWfBFShYkW5siJpTolK4O1h2HlLzh dubVyYRFC1OLYw4Ku+RcE4fQGfgDjdsqpu3g2PIYNOhJB1w8XVrBA96ARrLzWVCwN2Tx SKDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=default2211 header.b=mP741+E1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a63e507000000b00518580cb7b8si6109731pgh.269.2023.04.28.05.05.35; Fri, 28 Apr 2023 05:05:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@geanix.com header.s=default2211 header.b=mP741+E1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345894AbjD1Lqx (ORCPT + 99 others); Fri, 28 Apr 2023 07:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjD1Lqu (ORCPT ); Fri, 28 Apr 2023 07:46:50 -0400 Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE34C527E for ; Fri, 28 Apr 2023 04:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=MNil8LLz7Ox6rqRyom3f5t42db/SNzYEqHrz9Y8QZII=; b=mP741+E1WrkAiZS3Stw8tt8u26 HVBNwJtjecABGkdZFrWmSejTqgTF0YYATszT15ldXbSKWfY8swgcL+0UbIPta82rPK2y5FC3QfInZ aCM+Fuk10Wa9qLL+HBx/78eIHPYsiEVAbwPB3PhAvd9yMdZDVbznpX8ukAtJbu2AucP3O2DVKkPuA aA9G68YbYWldXk8G1jvBZU1CKPmGDhWPhzO6v79Qlwa72DJ6KTp6lVgzEuZ9elEEB+9cpV56T5w1k 4MsJ1JWrZC63dJj57fVuknrBLKqdP7o4MBKSxuWwlTlnNsuAINqbOMwE/LAb9nws9Lir0KpF2DgMf Ik/6bH1w==; Received: from sslproxy02.your-server.de ([78.47.166.47]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1psMHV-000Ldm-0C; Fri, 28 Apr 2023 13:28:53 +0200 Received: from [185.17.218.86] (helo=zen..) by sslproxy02.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1psMHU-00021I-OB; Fri, 28 Apr 2023 13:28:52 +0200 From: Sean Nyekjaer To: Lee Jones Cc: p.paillet@st.com, Sean Nyekjaer , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler Date: Fri, 28 Apr 2023 13:28:46 +0200 Message-Id: <20230428112847.2146348-2-sean@geanix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230428112847.2146348-1-sean@geanix.com> References: <20230428112847.2146348-1-sean@geanix.com> MIME-Version: 1.0 X-Authenticated-Sender: sean@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.8/26890/Fri Apr 28 09:22:55 2023) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764421587825012348?= X-GMAIL-MSGID: =?utf-8?q?1764421587825012348?= Use devm_register_sys_off_handler() that allows to register multiple power-off handlers. This can be enabled by adding "st,pmic-poweroff" to device-tree. Signed-off-by: Sean Nyekjaer --- drivers/mfd/stpmic1.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c index 4c9b18d9dec8..c628141eb03c 100644 --- a/drivers/mfd/stpmic1.c +++ b/drivers/mfd/stpmic1.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,33 @@ static const struct regmap_irq_chip stpmic1_regmap_irq_chip = { .num_irqs = ARRAY_SIZE(stpmic1_irqs), }; +static int stpmic1_power_off(struct sys_off_data *data) +{ + struct stpmic1 *ddata = data->cb_data; + + regmap_update_bits(ddata->regmap, MAIN_CR, + SOFTWARE_SWITCH_OFF, SOFTWARE_SWITCH_OFF); + + return NOTIFY_DONE; +} + +static int stpmic1_power_off_prepare_init(struct stpmic1 *ddata) +{ + int ret; + + ret = devm_register_sys_off_handler(ddata->dev, + SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_DEFAULT, + stpmic1_power_off, + ddata); + if (ret) { + dev_err(ddata->dev, "failed to register sys-off handler: %d\n", ret); + return ret; + } + + return 0; +} + static int stpmic1_probe(struct i2c_client *i2c) { struct stpmic1 *ddata; @@ -159,6 +187,12 @@ static int stpmic1_probe(struct i2c_client *i2c) return ret; } + if (of_property_read_bool(i2c->dev.of_node, "st,pmic-poweroff")) { + ret = stpmic1_power_off_prepare_init(ddata); + if (ret) + return ret; + } + return devm_of_platform_populate(dev); }