From patchwork Tue Oct 10 08:59:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 731583 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 1B6F3156C0 for ; Tue, 10 Oct 2023 08:59:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CE409F for ; Tue, 10 Oct 2023 01:59:20 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qq8a4-00016V-Oc; Tue, 10 Oct 2023 10:59:08 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qq8a3-000cTM-SW; Tue, 10 Oct 2023 10:59:07 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qq8a3-00ER1k-2f; Tue, 10 Oct 2023 10:59:07 +0200 From: Oleksij Rempel To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v1 1/3] regulator: dt-bindings: fixed-regulator: Add under-voltage interrupt support Date: Tue, 10 Oct 2023 10:59:04 +0200 Message-Id: <20231010085906.3440452-1-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: devicetree@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Add under-voltage interrupt support. This can be used with simple regulators having no other way to communicate an under-voltage event except as by toggling some GPIO line. Signed-off-by: Oleksij Rempel diff --git a/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml b/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml index ac0281b1cceb..0f8760ed2fb1 100644 --- a/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml +++ b/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml @@ -100,6 +100,14 @@ properties: vin-supply: description: Input supply phandle. + interrupts: + maxItems: 1 + description: + Under-voltage interrupt + + interrupt-names: + const: under-voltage + required: - compatible - regulator-name --- .../devicetree/bindings/regulator/fixed-regulator.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml b/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml index ac0281b1cceb..0f8760ed2fb1 100644 --- a/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml +++ b/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml @@ -100,6 +100,14 @@ properties: vin-supply: description: Input supply phandle. + interrupts: + maxItems: 1 + description: + Under-voltage interrupt + + interrupt-names: + const: under-voltage + required: - compatible - regulator-name From patchwork Tue Oct 10 08:59:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 731582 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 788C615AC3 for ; Tue, 10 Oct 2023 08:59:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1629DA4 for ; Tue, 10 Oct 2023 01:59:20 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qq8a4-00016W-Od; Tue, 10 Oct 2023 10:59:08 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qq8a3-000cTN-TD; Tue, 10 Oct 2023 10:59:07 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qq8a3-00ER1u-2k; Tue, 10 Oct 2023 10:59:07 +0200 From: Oleksij Rempel To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v1 2/3] regulator: fixed: add support for under-voltage IRQ Date: Tue, 10 Oct 2023 10:59:05 +0200 Message-Id: <20231010085906.3440452-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231010085906.3440452-1-o.rempel@pengutronix.de> References: <20231010085906.3440452-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: devicetree@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Add interrupt support for under-voltage notification. This functionality can be used on systems capable to detect under-voltage state and having enough capacity to let the SoC do some emergency preparation. Signed-off-by: Oleksij Rempel --- drivers/regulator/fixed.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 55130efae9b8..493dd244e4f4 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -105,6 +105,35 @@ static int reg_is_enabled(struct regulator_dev *rdev) return priv->enable_counter > 0; } +static irqreturn_t reg_fixed_under_voltage_irq_handler(int irq, void *data) +{ + struct fixed_voltage_data *priv = data; + struct regulator_dev *rdev = priv->dev; + + regulator_notifier_call_chain(rdev, REGULATOR_EVENT_UNDER_VOLTAGE, NULL); + + return IRQ_HANDLED; +} + +static int reg_fixed_get_irqs(struct device *dev, + struct fixed_voltage_data *priv) +{ + const char *uv = "under-voltage"; + int ret; + + ret = fwnode_irq_get_byname(dev_fwnode(dev), "under-voltage"); + /* This is optional IRQ. Ignore if not found */ + if (ret < 0) + return 0; + + ret = devm_request_threaded_irq(dev, ret, NULL, + reg_fixed_under_voltage_irq_handler, + IRQF_ONESHOT, uv, priv); + if (ret) + return dev_err_probe(dev, ret, "Failed to request %s IRQ\n", uv); + + return 0; +} /** * of_get_fixed_voltage_config - extract fixed_voltage_config structure info @@ -294,6 +323,10 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name, drvdata->desc.fixed_uV); + ret = reg_fixed_get_irqs(dev, drvdata); + if (ret) + return ret; + return 0; } From patchwork Tue Oct 10 08:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 732920 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 EEA981FCF for ; Tue, 10 Oct 2023 08:59:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A42D097 for ; Tue, 10 Oct 2023 01:59:19 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qq8a4-00016X-Oc; Tue, 10 Oct 2023 10:59:08 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qq8a3-000cTO-Tp; Tue, 10 Oct 2023 10:59:07 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qq8a3-00ER24-2o; Tue, 10 Oct 2023 10:59:07 +0200 From: Oleksij Rempel To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v1 3/3] regulator: fixed: forward under-voltage events Date: Tue, 10 Oct 2023 10:59:06 +0200 Message-Id: <20231010085906.3440452-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231010085906.3440452-1-o.rempel@pengutronix.de> References: <20231010085906.3440452-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: devicetree@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Add handler to forward under-voltage events. On systems for more or less complicated regulator chains we need to forward under-voltage events to actual driver which need to react on them. Signed-off-by: Oleksij Rempel --- drivers/regulator/fixed.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 493dd244e4f4..99d37f1ebbc9 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -33,6 +33,7 @@ struct fixed_voltage_data { struct regulator_desc desc; struct regulator_dev *dev; + struct notifier_block nb; struct clk *enable_clock; unsigned int enable_counter; @@ -105,6 +106,39 @@ static int reg_is_enabled(struct regulator_dev *rdev) return priv->enable_counter > 0; } +static int reg_fixed_regulator_notifier(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct fixed_voltage_data *priv = + container_of(nb, struct fixed_voltage_data, nb); + struct regulator_dev *rdev = priv->dev; + + if (event != REGULATOR_EVENT_UNDER_VOLTAGE_WARN && + event != REGULATOR_EVENT_UNDER_VOLTAGE) + return NOTIFY_OK; + + regulator_notifier_call_chain(rdev, event, NULL); + + return NOTIFY_OK; +} + +static int reg_fixed_register_reg_notifier(struct fixed_voltage_data *priv, + struct device *dev) +{ + struct regulator_dev *rdev = priv->dev; + int ret; + + if (!rdev->supply) + return 0; + + priv->nb.notifier_call = reg_fixed_regulator_notifier; + ret = devm_regulator_register_notifier(rdev->supply, &priv->nb); + if (ret) + return dev_err_probe(dev, ret, "Failed to register notifier\n"); + + return 0; +} + static irqreturn_t reg_fixed_under_voltage_irq_handler(int irq, void *data) { struct fixed_voltage_data *priv = data; @@ -327,7 +361,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) if (ret) return ret; - return 0; + return reg_fixed_register_reg_notifier(drvdata, dev); } #if defined(CONFIG_OF)