From patchwork Wed May 4 06:52:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1626084 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=F/gdYxKT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtSG16Zbrz9sG6 for ; Wed, 4 May 2022 16:53:13 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KtSG11t49z3bYJ for ; Wed, 4 May 2022 16:53:13 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=F/gdYxKT; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=2605:2700:0:5::4713:9cab; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=F/gdYxKT; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KtSFn6Mg0z2yJQ for ; Wed, 4 May 2022 16:53:01 +1000 (AEST) Received: from hatter.bewilderbeest.net (174-21-163-222.tukw.qwest.net [174.21.163.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 0497D169; Tue, 3 May 2022 23:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1651647180; bh=BUh+Rsl/Obk1fAz2PI0BDjzoYoH2gsCvCnElmZcQ9qQ=; h=From:To:Cc:Subject:Date:From; b=F/gdYxKTRu929oH24p5rNl7LOgh9DUC4rus214BYjpqdw/Nr7h+I7ReCoU4oqytHz eXnfJvdKKy93kZYFYMDJWZ5V3Ag5hln5diRcgVj9OM+eHATxJ8B7Vdg+nKwcOBF3H/ 7Ka3fx4In5blYZJ01lgJV/bzqHZFdW0yCfiXLrVI= From: Zev Weiss To: Mark Brown , Liam Girdwood , Rob Herring , Krzysztof Kozlowski Subject: [PATCH 1/6] dt-bindings: regulator: Add regulator-external-output property Date: Tue, 3 May 2022 23:52:47 -0700 Message-Id: <20220504065252.6955-1-zev@bewilderbeest.net> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Zev Weiss , Greg Kroah-Hartman Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Some regulators do not provide power to anything within the system described by a device tree, and simply supply an external output. The regulator-external-output property can now be used to mark such regulators. Signed-off-by: Zev Weiss --- Documentation/devicetree/bindings/regulator/regulator.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/regulator/regulator.yaml b/Documentation/devicetree/bindings/regulator/regulator.yaml index a9b66ececccf..0e418e68b0e6 100644 --- a/Documentation/devicetree/bindings/regulator/regulator.yaml +++ b/Documentation/devicetree/bindings/regulator/regulator.yaml @@ -226,6 +226,12 @@ properties: description: Maximum difference between current and target voltages that can be changed safely in a single step. + regulator-external-output: + description: The regulator's output is external to the system + described by the device-tree; no devices within the system are + downstream of it. + type: boolean + patternProperties: ".*-supply$": description: Input supply phandle(s) for this node From patchwork Wed May 4 06:52:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1626087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=CBZa54Pq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtSGh6GQPz9sG6 for ; Wed, 4 May 2022 16:53:48 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KtSGh598Nz3bdK for ; Wed, 4 May 2022 16:53:48 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=CBZa54Pq; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=CBZa54Pq; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KtSFp2CTfz2yJQ for ; Wed, 4 May 2022 16:53:02 +1000 (AEST) Received: from hatter.bewilderbeest.net (174-21-163-222.tukw.qwest.net [174.21.163.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 50BF9223; Tue, 3 May 2022 23:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1651647180; bh=NGgm9ZytERpttgSYTz22XkDyLz7akFtC0NdMbrSk3Qw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CBZa54PqXgXcLE6/k/HrFbeNJv4F6EzjUtzedbwiSK6Ap7+y1MjNaXUgqluZA8Ogc 3HWlcIB9V3AOqIT0ylHmV7qVu6qk1oC9wW7yCtJBqt/egcUXeUapVuDVO2E64hpJ+0 V/O0Pns/givWDrHjDLhDjz7XbCJkOq7YQ2VjHolg= From: Zev Weiss To: Mark Brown , Liam Girdwood , Rob Herring , Krzysztof Kozlowski Subject: [PATCH 2/6] dt-bindings: regulator: Add reg-external-output binding Date: Tue, 3 May 2022 23:52:48 -0700 Message-Id: <20220504065252.6955-2-zev@bewilderbeest.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504065252.6955-1-zev@bewilderbeest.net> References: <20220504065252.6955-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Zev Weiss , Greg Kroah-Hartman Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This describes an external output supplied by a regulator, such as a power outlet on a power distribution unit (PDU). Signed-off-by: Zev Weiss --- .../regulator/reg-external-output.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/reg-external-output.yaml diff --git a/Documentation/devicetree/bindings/regulator/reg-external-output.yaml b/Documentation/devicetree/bindings/regulator/reg-external-output.yaml new file mode 100644 index 000000000000..c00bee5bd9f2 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/reg-external-output.yaml @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/regulator/reg-external-output.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Regulator external output + +maintainers: + - Zev Weiss + +description: | + This describes an external output supplied by a regulator, such as + a power outlet on a power distribution unit (PDU). + +properties: + compatible: + const: reg-external-output + + vout-supply: + description: + Phandle of the regulator supplying the output, which should have + the regulator-external-output property. + +required: + - compatible + - vout-supply + +additionalProperties: false + +examples: + - | + output { + compatible = "reg-external-output"; + vout-supply = <&output_reg>; + }; From patchwork Wed May 4 06:52:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1626088 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=o2MJt1uJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtSHR1MfSz9sG6 for ; Wed, 4 May 2022 16:54:27 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KtSHM5B8Mz3bXN for ; Wed, 4 May 2022 16:54:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=o2MJt1uJ; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=o2MJt1uJ; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KtSFp4TzMz2yJQ for ; Wed, 4 May 2022 16:53:02 +1000 (AEST) Received: from hatter.bewilderbeest.net (174-21-163-222.tukw.qwest.net [174.21.163.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 9EA25629; Tue, 3 May 2022 23:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1651647180; bh=82pFgktAlz+Ya9WLKFBYjJeWqPhCiiVLL8JWL4SAXK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o2MJt1uJ8QPdLELePPyyROyP/vofajRxWWrl0OOTkl6ag82KXypgahCX+SlAf+3Yp MUALxwI70XmJIM77nkCcCIpvJGNVU+D84T9nlYcL8MXKn2e9UzAJaWU6fL7BgBTf/r 8z6c2of6W+7oqeGSiQVGiy1inh9vx+r0mvLxW8IY= From: Zev Weiss To: Mark Brown , Liam Girdwood Subject: [PATCH 3/6] regulator: core: Add error flags to sysfs attributes Date: Tue, 3 May 2022 23:52:49 -0700 Message-Id: <20220504065252.6955-3-zev@bewilderbeest.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504065252.6955-1-zev@bewilderbeest.net> References: <20220504065252.6955-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kroah-Hartman , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" If a regulator provides a get_error_flags() operation, its sysfs attributes will now include an entry for each defined REGULATOR_ERROR_* flag. Signed-off-by: Zev Weiss --- .../ABI/testing/sysfs-class-regulator | 81 +++++++++++++++++++ drivers/regulator/core.c | 45 +++++++++++ 2 files changed, 126 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-regulator b/Documentation/ABI/testing/sysfs-class-regulator index 8516f08806dd..475b9a372657 100644 --- a/Documentation/ABI/testing/sysfs-class-regulator +++ b/Documentation/ABI/testing/sysfs-class-regulator @@ -370,3 +370,84 @@ Description: 'unknown' means software cannot determine the state, or the reported state is invalid. + +What: /sys/class/regulator/.../under_voltage +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + under_voltage. This indicates if the device reports an + under-voltage fault (1) or not (0). + +What: /sys/class/regulator/.../over_current +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + over_current. This indicates if the device reports an + over-current fault (1) or not (0). + +What: /sys/class/regulator/.../regulation_out +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + regulation_out. This indicates if the device reports an + out-of-regulation fault (1) or not (0). + +What: /sys/class/regulator/.../fail +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + fail. This indicates if the device reports an output failure + (1) or not (0). + +What: /sys/class/regulator/.../over_temp +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + over_temp. This indicates if the device reports an + over-temperature fault (1) or not (0). + +What: /sys/class/regulator/.../under_voltage_warn +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + under_voltage_warn. This indicates if the device reports an + under-voltage warning (1) or not (0). + +What: /sys/class/regulator/.../over_current_warn +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + over_current_warn. This indicates if the device reports an + over-current warning (1) or not (0). + +What: /sys/class/regulator/.../over_voltage_warn +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + over_voltage_warn. This indicates if the device reports an + over-voltage warning (1) or not (0). + +What: /sys/class/regulator/.../over_temp_warn +Date: April 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: + Some regulator directories will contain a field called + over_temp_warn. This indicates if the device reports an + over-temperature warning (1) or not (0). diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d2553970a67b..9094bd8772e5 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -83,6 +83,7 @@ struct regulator_supply_alias { static int _regulator_is_enabled(struct regulator_dev *rdev); static int _regulator_disable(struct regulator *regulator); +static int _regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags); static int _regulator_get_current_limit(struct regulator_dev *rdev); static unsigned int _regulator_get_mode(struct regulator_dev *rdev); static int _notifier_call_chain(struct regulator_dev *rdev, @@ -911,6 +912,30 @@ static ssize_t bypass_show(struct device *dev, } static DEVICE_ATTR_RO(bypass); +#define REGULATOR_ERROR_ATTR(name, bit) \ + static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \ + char *buf) \ + { \ + int ret; \ + unsigned int flags; \ + struct regulator_dev *rdev = dev_get_drvdata(dev); \ + ret = _regulator_get_error_flags(rdev, &flags); \ + if (ret) \ + return ret; \ + return sysfs_emit(buf, "%d\n", !!(flags & (bit))); \ + } \ + static DEVICE_ATTR_RO(name) + +REGULATOR_ERROR_ATTR(under_voltage, REGULATOR_ERROR_UNDER_VOLTAGE); +REGULATOR_ERROR_ATTR(over_current, REGULATOR_ERROR_OVER_CURRENT); +REGULATOR_ERROR_ATTR(regulation_out, REGULATOR_ERROR_REGULATION_OUT); +REGULATOR_ERROR_ATTR(fail, REGULATOR_ERROR_FAIL); +REGULATOR_ERROR_ATTR(over_temp, REGULATOR_ERROR_OVER_TEMP); +REGULATOR_ERROR_ATTR(under_voltage_warn, REGULATOR_ERROR_UNDER_VOLTAGE_WARN); +REGULATOR_ERROR_ATTR(over_current_warn, REGULATOR_ERROR_OVER_CURRENT_WARN); +REGULATOR_ERROR_ATTR(over_voltage_warn, REGULATOR_ERROR_OVER_VOLTAGE_WARN); +REGULATOR_ERROR_ATTR(over_temp_warn, REGULATOR_ERROR_OVER_TEMP_WARN); + /* Calculate the new optimum regulator operating mode based on the new total * consumer load. All locks held by caller */ @@ -4971,6 +4996,15 @@ static struct attribute *regulator_dev_attrs[] = { &dev_attr_max_microvolts.attr, &dev_attr_min_microamps.attr, &dev_attr_max_microamps.attr, + &dev_attr_under_voltage.attr, + &dev_attr_over_current.attr, + &dev_attr_regulation_out.attr, + &dev_attr_fail.attr, + &dev_attr_over_temp.attr, + &dev_attr_under_voltage_warn.attr, + &dev_attr_over_current_warn.attr, + &dev_attr_over_voltage_warn.attr, + &dev_attr_over_temp_warn.attr, &dev_attr_suspend_standby_state.attr, &dev_attr_suspend_mem_state.attr, &dev_attr_suspend_disk_state.attr, @@ -5026,6 +5060,17 @@ static umode_t regulator_attr_is_visible(struct kobject *kobj, if (attr == &dev_attr_bypass.attr) return ops->get_bypass ? mode : 0; + if (attr == &dev_attr_under_voltage.attr || + attr == &dev_attr_over_current.attr || + attr == &dev_attr_regulation_out.attr || + attr == &dev_attr_fail.attr || + attr == &dev_attr_over_temp.attr || + attr == &dev_attr_under_voltage_warn.attr || + attr == &dev_attr_over_current_warn.attr || + attr == &dev_attr_over_voltage_warn.attr || + attr == &dev_attr_over_temp_warn.attr) + return ops->get_error_flags ? mode : 0; + /* constraints need specific supporting methods */ if (attr == &dev_attr_min_microvolts.attr || attr == &dev_attr_max_microvolts.attr) From patchwork Wed May 4 06:52:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1626089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=N4uL++YQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtSJ45fhMz9sG6 for ; Wed, 4 May 2022 16:55:00 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KtSJ44TF5z3bYw for ; Wed, 4 May 2022 16:55:00 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=N4uL++YQ; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=N4uL++YQ; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KtSFp5hjrz3064 for ; Wed, 4 May 2022 16:53:02 +1000 (AEST) Received: from hatter.bewilderbeest.net (174-21-163-222.tukw.qwest.net [174.21.163.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id DA0B3A11; Tue, 3 May 2022 23:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1651647181; bh=vCwgw617O/ewX8QDmnxBymU7T8PA39aGYTHp7lO2log=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N4uL++YQpdaJ8unIiXshkYfNDpxH9arZNEdbkLa5RClvz581Uo7SaG97xVN7X6lJy N/Y/cok5zegTItliQc4ngL+iVbY+QTtEgr8+Uk06OxHfN8AJUOn3h+YAQBx8ajLdXZ ztz5vegJQp65Tw6gSLJ+EeD5mZxiq5OHPuhwV07I= From: Zev Weiss To: Mark Brown , Liam Girdwood Subject: [PATCH 4/6] regulator: core: Add external-output support Date: Tue, 3 May 2022 23:52:50 -0700 Message-Id: <20220504065252.6955-4-zev@bewilderbeest.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504065252.6955-1-zev@bewilderbeest.net> References: <20220504065252.6955-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kroah-Hartman , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Regulators feeding external outputs (i.e. supplying devices we don't control) can be switched on and off by userspace via the 'state' sysfs attribute, which is now (conditionally) writable. They are also not automatically disabled in regulator_late_cleanup(), since we have no way of knowing that they're not actually in use. Signed-off-by: Zev Weiss --- .../ABI/testing/sysfs-class-regulator | 4 ++ drivers/regulator/core.c | 41 ++++++++++++++++--- drivers/regulator/of_regulator.c | 2 + include/linux/regulator/machine.h | 1 + 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-regulator b/Documentation/ABI/testing/sysfs-class-regulator index 475b9a372657..1c0451730df2 100644 --- a/Documentation/ABI/testing/sysfs-class-regulator +++ b/Documentation/ABI/testing/sysfs-class-regulator @@ -23,6 +23,10 @@ Description: 'unknown' means software cannot determine the state, or the reported state is invalid. + For regulators supplying external outputs, 'enabled' + or 'disabled' can be written to this file to turn the + regulator on and off. + NOTE: this field can be used in conjunction with microvolts or microamps to determine configured regulator output levels. diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 9094bd8772e5..b7617926336f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -83,6 +83,8 @@ struct regulator_supply_alias { static int _regulator_is_enabled(struct regulator_dev *rdev); static int _regulator_disable(struct regulator *regulator); +static int _regulator_do_enable(struct regulator_dev *rdev); +static int _regulator_do_disable(struct regulator_dev *rdev); static int _regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags); static int _regulator_get_current_limit(struct regulator_dev *rdev); static unsigned int _regulator_get_mode(struct regulator_dev *rdev); @@ -667,7 +669,33 @@ static ssize_t state_show(struct device *dev, return ret; } -static DEVICE_ATTR_RO(state); + +static ssize_t state_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct regulator_dev *rdev = dev_get_drvdata(dev); + bool enabled; + ssize_t ret = 0; + + if (sysfs_streq(buf, "enabled")) + enabled = true; + else if (sysfs_streq(buf, "disabled")) + enabled = false; + else + return -EINVAL; + + regulator_lock(rdev); + if (enabled != _regulator_is_enabled(rdev)) { + if (enabled) + ret = _regulator_do_enable(rdev); + else + ret = _regulator_do_disable(rdev); + } + regulator_unlock(rdev); + + return ret ? : count; +} +static DEVICE_ATTR_RW(state); static ssize_t status_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -5051,8 +5079,11 @@ static umode_t regulator_attr_is_visible(struct kobject *kobj, if (attr == &dev_attr_opmode.attr) return ops->get_mode ? mode : 0; - if (attr == &dev_attr_state.attr) + if (attr == &dev_attr_state.attr) { + if (!(rdev->constraints && rdev->constraints->external_output)) + mode &= ~0222; return (rdev->ena_pin || ops->is_enabled) ? mode : 0; + } if (attr == &dev_attr_status.attr) return ops->get_status ? mode : 0; @@ -6062,7 +6093,7 @@ static int regulator_late_cleanup(struct device *dev, void *data) struct regulation_constraints *c = rdev->constraints; int ret; - if (c && c->always_on) + if (c && (c->always_on || c->external_output)) return 0; if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS)) @@ -6114,8 +6145,8 @@ static void regulator_init_complete_work_function(struct work_struct *work) /* If we have a full configuration then disable any regulators * we have permission to change the status for and which are - * not in use or always_on. This is effectively the default - * for DT and ACPI as they have full constraints. + * not in use, always_on, or external_output. This is effectively + * the default for DT and ACPI as they have full constraints. */ class_for_each_device(®ulator_class, NULL, NULL, regulator_late_cleanup); diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index f54d4f176882..f48e6ea2b97e 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -96,6 +96,8 @@ static int of_get_regulation_constraints(struct device *dev, constraints->name = of_get_property(np, "regulator-name", NULL); + constraints->external_output = of_property_read_bool(np, "regulator-external-output"); + if (!of_property_read_u32(np, "regulator-min-microvolt", &pval)) constraints->min_uV = pval; diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 621b7f4a3639..a38e7db9f82e 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -219,6 +219,7 @@ struct regulation_constraints { unsigned over_voltage_detection:1; /* notify on over voltage */ unsigned under_voltage_detection:1; /* notify on under voltage */ unsigned over_temp_detection:1; /* notify on over temperature */ + unsigned external_output:1; /* output supplies only external devices */ }; /** From patchwork Wed May 4 06:52:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1626090 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=XIAM0IKu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtSJk5Hdxz9sG6 for ; Wed, 4 May 2022 16:55:34 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KtSJk3n9Gz3bgR for ; Wed, 4 May 2022 16:55:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=XIAM0IKu; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=XIAM0IKu; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KtSFq1Jslz3064 for ; Wed, 4 May 2022 16:53:02 +1000 (AEST) Received: from hatter.bewilderbeest.net (174-21-163-222.tukw.qwest.net [174.21.163.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 216F3B99; Tue, 3 May 2022 23:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1651647181; bh=m4z66kOy61XB3YkIh8WlfoxIbCbvY+16ZM4qwHUbBBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XIAM0IKuWfkMLBw5I6TN8RwRk6YfcPhRKWHhDJOoN2PFWLUeQpmPc9mW4qY/Su/wP 8V7TBbkcdPHDuXYEnOszXdHw+qsgXuKmWaQ4YzNNooLxzW+U9Nw/2JFKiRCgQ+m/bh PUzPEPIwAfpc1m4LbXJ1K5jSIp9XB7O0X+dcK1Ng= From: Zev Weiss To: Mark Brown , Liam Girdwood Subject: [PATCH 5/6] regulator: core: Add external get type Date: Tue, 3 May 2022 23:52:51 -0700 Message-Id: <20220504065252.6955-5-zev@bewilderbeest.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504065252.6955-1-zev@bewilderbeest.net> References: <20220504065252.6955-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kroah-Hartman , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" EXTERNAL_GET is similar to EXCLUSIVE_GET, but requires opt-in agreement from the supply (whose constraints must designate it as external_output). It is intended for use only within the regulator subsystem, and hence is not exposed in the public headers. Signed-off-by: Zev Weiss --- drivers/regulator/core.c | 16 +++++++++++++--- drivers/regulator/devres.c | 7 +++++++ drivers/regulator/internal.h | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b7617926336f..d873606eb41f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2087,6 +2087,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id, struct regulator_dev *rdev; struct regulator *regulator; struct device_link *link; + bool is_external; int ret; if (get_type >= MAX_GET_TYPE) { @@ -2129,8 +2130,9 @@ struct regulator *_regulator_get(struct device *dev, const char *id, break; case EXCLUSIVE_GET: + case EXTERNAL_GET: dev_warn(dev, - "dummy supplies not allowed for exclusive requests\n"); + "dummy supplies not allowed for exclusive or external requests\n"); fallthrough; default: @@ -2144,12 +2146,20 @@ struct regulator *_regulator_get(struct device *dev, const char *id, return regulator; } - if (get_type == EXCLUSIVE_GET && rdev->open_count) { + if ((get_type == EXCLUSIVE_GET || get_type == EXTERNAL_GET) && rdev->open_count) { regulator = ERR_PTR(-EBUSY); put_device(&rdev->dev); return regulator; } + /* EXTERNAL_GET is valid if and only if the regulator is designated for external output */ + is_external = rdev->constraints && rdev->constraints->external_output; + if ((get_type == EXTERNAL_GET) != is_external) { + regulator = ERR_PTR(-EINVAL); + put_device(&rdev->dev); + return regulator; + } + mutex_lock(®ulator_list_mutex); ret = (rdev->coupling_desc.n_resolved != rdev->coupling_desc.n_coupled); mutex_unlock(®ulator_list_mutex); @@ -2182,7 +2192,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id, } rdev->open_count++; - if (get_type == EXCLUSIVE_GET) { + if (get_type == EXCLUSIVE_GET || get_type == EXTERNAL_GET) { rdev->exclusive = 1; ret = _regulator_is_enabled(rdev); diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c index 9113233f41cd..36df9e9ff175 100644 --- a/drivers/regulator/devres.c +++ b/drivers/regulator/devres.c @@ -70,6 +70,13 @@ struct regulator *devm_regulator_get_exclusive(struct device *dev, } EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive); +/* For regulator-core internal use only */ +struct regulator *devm_regulator_get_external(struct device *dev, + const char *id) +{ + return _devm_regulator_get(dev, id, EXTERNAL_GET); +} + /** * devm_regulator_get_optional - Resource managed regulator_get_optional() * @dev: device to supply diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 1e9c71642143..c176a416c571 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -116,10 +116,13 @@ static inline bool of_check_coupling_data(struct regulator_dev *rdev) enum regulator_get_type { NORMAL_GET, EXCLUSIVE_GET, + EXTERNAL_GET, OPTIONAL_GET, MAX_GET_TYPE }; struct regulator *_regulator_get(struct device *dev, const char *id, enum regulator_get_type get_type); +struct regulator *devm_regulator_get_external(struct device *dev, + const char *id); #endif From patchwork Wed May 4 06:52:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1626091 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=mX7+SrYA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtSKP2f1nz9sG6 for ; Wed, 4 May 2022 16:56:09 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KtSKP1G0Qz3bYP for ; Wed, 4 May 2022 16:56:09 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=mX7+SrYA; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=mX7+SrYA; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KtSFq4c6Sz3064 for ; Wed, 4 May 2022 16:53:03 +1000 (AEST) Received: from hatter.bewilderbeest.net (174-21-163-222.tukw.qwest.net [174.21.163.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 5B216C64; Tue, 3 May 2022 23:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1651647181; bh=T+pl3SJCSzXLJOiH4mZIAgFL9b9XXugAhhglLLH5nDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mX7+SrYAMIBw0ZLAA5ZzfrgVbR8MjFejgzDqwOnI8FCj2J1NgvmTaWjXI+clUMs0N jR6qTIFaLnCw7hHAh74Z03lX/zB5GpyDTYCtkHc+Z170TfVPhO+XpLSTpxFWKm2z8K qWSrjHbBxfJbard91MS1vaOx+QKoy65660GrjmCg= From: Zev Weiss To: Mark Brown , Liam Girdwood Subject: [PATCH 6/6] regulator: core: Add external-consumer driver Date: Tue, 3 May 2022 23:52:52 -0700 Message-Id: <20220504065252.6955-6-zev@bewilderbeest.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504065252.6955-1-zev@bewilderbeest.net> References: <20220504065252.6955-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kroah-Hartman , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" An external consumer is a dummy device representing a device external to the system that is supplied by a regulator designated for external output. It is purely a virtual placeholder to instantiate a regulator by calling regulator_get() on it from its probe function. Signed-off-by: Zev Weiss --- drivers/regulator/Kconfig | 9 +++++++++ drivers/regulator/core.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 5ef2306fce04..5ec390687a81 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -56,6 +56,15 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config REGULATOR_EXTERNAL_CONSUMER + bool "External regulator consumer support" + help + Some regulators supply devices that are entirely external to + the system. This driver provides a placeholder consumer + representing such devices. + + If unsure, say no. + config REGULATOR_88PG86X tristate "Marvell 88PG86X voltage regulators" depends on I2C diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d873606eb41f..4f348b3d5290 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -6070,6 +6071,33 @@ static int regulator_summary_show(struct seq_file *s, void *data) DEFINE_SHOW_ATTRIBUTE(regulator_summary); #endif /* CONFIG_DEBUG_FS */ +#ifdef CONFIG_REGULATOR_EXTERNAL_CONSUMER +static int regulator_external_output_probe(struct platform_device *pdev) +{ + struct regulator *reg; + + reg = devm_regulator_get_external(&pdev->dev, "vout"); + if (IS_ERR(reg)) + return PTR_ERR(reg); + + return 0; +} + +static const struct of_device_id reg_external_consumer_of_match_table[] = { + { .compatible = "regulator-external-output" }, + { }, +}; + +static struct platform_driver reg_external_consumer_driver = { + .driver = { + .name = "reg-external-consumer", + .of_match_table = reg_external_consumer_of_match_table, + }, + .probe = regulator_external_output_probe, +}; +builtin_platform_driver(reg_external_consumer_driver); +#endif /* CONFIG_REGULATOR_EXTERNAL_CONSUMER */ + static int __init regulator_init(void) { int ret;