From patchwork Thu May 5 23:25:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1627309 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=YQOvXL0V; 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 4KvVGx6JYNz9sBF for ; Fri, 6 May 2022 09:27:37 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KvVGx5P8gz3brt for ; Fri, 6 May 2022 09:27:37 +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=YQOvXL0V; 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=YQOvXL0V; 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 4KvVFK52zdz3bqJ for ; Fri, 6 May 2022 09:26:13 +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 5C7A3331; Thu, 5 May 2022 16:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1651793169; bh=L4IB0VoUFCWwJW2jk1V0bP//XVHc5hIoPCrUlnX1oXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YQOvXL0VJDatl+irFLuOtu1857mb91W96sEGVLTJ5zMg2eVP/bxSUFuFYRCL62/SZ w8OPcwBDnHJ0yvJfr8drtv0hZUbILNTpKKEfvF79Sek/cJZqsxhOjdQaFThODYu9cA Z9Pu8Fh8dfoGR637s6xOdQbtEw1qFQhc1OwlsRuM= From: Zev Weiss To: Mark Brown , Liam Girdwood , MyungJoo Ham , Chanwoo Choi , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org Subject: [PATCH v2 1/2] dt-bindings: connector: Add regulator-connector binding Date: Thu, 5 May 2022 16:25:56 -0700 Message-Id: <20220505232557.10936-2-zev@bewilderbeest.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220505232557.10936-1-zev@bewilderbeest.net> References: <20220505232557.10936-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" This describes a power connector supplied by a regulator, such as a power outlet on a power distribution unit (PDU). Signed-off-by: Zev Weiss Reviewed-by: Rob Herring --- .../connector/regulator-connector.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/connector/regulator-connector.yaml diff --git a/Documentation/devicetree/bindings/connector/regulator-connector.yaml b/Documentation/devicetree/bindings/connector/regulator-connector.yaml new file mode 100644 index 000000000000..96825b6f608a --- /dev/null +++ b/Documentation/devicetree/bindings/connector/regulator-connector.yaml @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/connector/regulator-connector.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Regulator output connector + +maintainers: + - Zev Weiss + +description: | + This describes a power connector supplied by a regulator, such as a + power outlet on a power distribution unit (PDU). The connector may + be standalone or merely one channel or set of pins within a ganged + physical connector carrying multiple independent power outputs. + +properties: + compatible: + const: regulator-connector + + vout-supply: + description: + Phandle of the regulator supplying the connector. + +required: + - compatible + - vout-supply + +additionalProperties: false + +examples: + - | + output { + compatible = "regulator-connector"; + vout-supply = <&output_reg>; + }; From patchwork Thu May 5 23:25:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1627308 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=Etv1jejN; 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 4KvVGF3RM3z9sBF for ; Fri, 6 May 2022 09:27:01 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KvVGF1ygMz3byL for ; Fri, 6 May 2022 09:27:01 +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=Etv1jejN; 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=Etv1jejN; 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 4KvVFK50Gyz3bq9 for ; Fri, 6 May 2022 09:26:13 +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 B3929824; Thu, 5 May 2022 16:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1651793169; bh=rjQ6bIFC7L3yFwYhOjGi4eWrvaaSejtl9wkPAzjsnU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Etv1jejNkYGu6jQ4YT3CN8ECZ5DCiA3jT85wfspeHOOCOOFXKNRQ/T3jUIGFg6HX1 lyy5PSW6BIrsTwux1bh3c583bj0VWdAKkZ4PjVFUNvxRNaJK9vPNQN4Oo6hlQ+zxma wZahqHNPd7xZhYG4I4RHxTRVWgcGoouo1tT4vzLI= From: Zev Weiss To: Mark Brown , Liam Girdwood , MyungJoo Ham , Chanwoo Choi Subject: [PATCH v2 2/2] extcon: Add extcon-regulator driver Date: Thu, 5 May 2022 16:25:57 -0700 Message-Id: <20220505232557.10936-3-zev@bewilderbeest.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220505232557.10936-1-zev@bewilderbeest.net> References: <20220505232557.10936-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" This driver supports power connectors supplied by a regulator, such as outlets on a power distribution unit (PDU). Its extcon functionality is currently quite limited, since the hardware it's initially targeting is very simple and doesn't really provide anything for the driver to interact with, but it can be extended as required for hardware that might offer more for it to do (e.g. a presence-detection mechanism). Its sole feature is a read/write sysfs attribute allowing userspace to switch the output on and off by enabling and disabling the supply regulator. Signed-off-by: Zev Weiss --- .../ABI/testing/sysfs-driver-extcon-regulator | 8 ++ MAINTAINERS | 8 ++ drivers/extcon/Kconfig | 8 ++ drivers/extcon/Makefile | 1 + drivers/extcon/extcon-regulator.c | 133 ++++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-extcon-regulator create mode 100644 drivers/extcon/extcon-regulator.c diff --git a/Documentation/ABI/testing/sysfs-driver-extcon-regulator b/Documentation/ABI/testing/sysfs-driver-extcon-regulator new file mode 100644 index 000000000000..b2f3141a1c49 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-extcon-regulator @@ -0,0 +1,8 @@ +What: /sys/bus/platform/drivers/extcon-regulator/*/state +Date: May 2022 +KernelVersion: 5.18 +Contact: Zev Weiss +Description: When read, provides the current power state of the connector, + either "on" or "off". Either string may also be written to + set the power state of the connector. +Users: OpenBMC diff --git a/MAINTAINERS b/MAINTAINERS index edc96cdb85e8..c30b6cf95ff1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16740,6 +16740,14 @@ F: Documentation/devicetree/bindings/regmap/ F: drivers/base/regmap/ F: include/linux/regmap.h +REGULATOR EXTCON DRIVER +M: Zev Weiss +L: openbmc@lists.ozlabs.org +S: Maintained +F: Documentation/ABI/testing/sysfs-driver-extcon-regulator +F: Documentation/devicetree/bindings/connector/regulator-connector.yaml +F: drivers/extcon/extcon-regulator.c + REISERFS FILE SYSTEM L: reiserfs-devel@vger.kernel.org S: Supported diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 0d42e49105dd..19fe76da6c75 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -143,6 +143,14 @@ config EXTCON_QCOM_SPMI_MISC Say Y here to enable SPMI PMIC based USB cable detection support on Qualcomm PMICs such as PM8941. +config EXTCON_REGULATOR + tristate "Regulator output extcon support" + depends on REGULATOR + help + Say y here to enable support for regulator-supplied external + power output connections, such as the outlets of a power + distribution unit (PDU). + config EXTCON_RT8973A tristate "Richtek RT8973A EXTCON support" depends on I2C diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 1b390d934ca9..1a1c32d4b23e 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o obj-$(CONFIG_EXTCON_PTN5150) += extcon-ptn5150.o obj-$(CONFIG_EXTCON_QCOM_SPMI_MISC) += extcon-qcom-spmi-misc.o +obj-$(CONFIG_EXTCON_REGULATOR) += extcon-regulator.o obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o diff --git a/drivers/extcon/extcon-regulator.c b/drivers/extcon/extcon-regulator.c new file mode 100644 index 000000000000..eec1bb3f4c09 --- /dev/null +++ b/drivers/extcon/extcon-regulator.c @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * extcon-regulator: extcon driver for regulator-supplied external power + * output connectors + * + * Copyright (C) 2022 Zev Weiss + */ + +#include +#include +#include +#include +#include +#include + +struct regulator_extcon_data { + struct extcon_dev *edev; + struct regulator *reg; + struct mutex lock; + unsigned int extcon_id; +}; + +static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct regulator_extcon_data *data = dev_get_drvdata(dev); + int status = regulator_is_enabled(data->reg); + + if (status < 0) + return status; + + return sysfs_emit(buf, "%s\n", status ? "on" : "off"); +} + +static ssize_t state_store(struct device *dev, struct device_attribute *attr, const char *buf, + size_t count) +{ + int status, wantstate; + struct regulator_extcon_data *data = dev_get_drvdata(dev); + struct regulator *reg = data->reg; + + if (sysfs_streq(buf, "on")) + wantstate = 1; + else if (sysfs_streq(buf, "off")) + wantstate = 0; + else + return -EINVAL; + + mutex_lock(&data->lock); + + status = regulator_is_enabled(reg); + + /* + * We need to ensure our enable/disable calls don't get imbalanced, so + * bail if we can't determine the current state. + */ + if (status < 0) + goto out; + + /* Nothing further needed if we're already in the desired state */ + if (!!status == wantstate) { + status = 0; + goto out; + } + + if (wantstate) + status = regulator_enable(reg); + else + status = regulator_disable(reg); + +out: + mutex_unlock(&data->lock); + + return status ? : count; +} + +static DEVICE_ATTR_RW(state); + +static struct attribute *regulator_extcon_attrs[] = { + &dev_attr_state.attr, + NULL, +}; +ATTRIBUTE_GROUPS(regulator_extcon); + +static int regulator_extcon_probe(struct platform_device *pdev) +{ + int ret; + struct regulator_extcon_data *data; + struct device *dev = &pdev->dev; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->reg = devm_regulator_get_exclusive(&pdev->dev, "vout"); + if (IS_ERR(data->reg)) + return PTR_ERR(data->reg); + + mutex_init(&data->lock); + + /* No cables currently supported */ + data->extcon_id = EXTCON_NONE; + + data->edev = devm_extcon_dev_allocate(dev, &data->extcon_id); + if (IS_ERR(data->edev)) + return PTR_ERR(data->edev); + + ret = devm_extcon_dev_register(dev, data->edev); + if (ret < 0) + return ret; + + platform_set_drvdata(pdev, data); + + return 0; +} + +static const struct of_device_id regulator_extcon_of_match_table[] = { + { .compatible = "regulator-connector" }, + { }, +}; + +static struct platform_driver regulator_extcon_driver = { + .driver = { + .name = "extcon-regulator", + .of_match_table = of_match_ptr(regulator_extcon_of_match_table), + .dev_groups = regulator_extcon_groups, + }, + .probe = regulator_extcon_probe, +}; +module_platform_driver(regulator_extcon_driver); + +MODULE_AUTHOR("Zev Weiss "); +MODULE_DESCRIPTION("Regulator extcon driver"); +MODULE_LICENSE("GPL");