From nobody Sun May 10 21:19:55 2026 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 2C3D1C433F5 for ; Sat, 23 Apr 2022 18:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236722AbiDWSZ2 (ORCPT ); Sat, 23 Apr 2022 14:25:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234326AbiDWSZZ (ORCPT ); Sat, 23 Apr 2022 14:25:25 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 665421F7D66 for ; Sat, 23 Apr 2022 11:22:28 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id d6so8942887ede.8 for ; Sat, 23 Apr 2022 11:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SoODso8L6sa7HFQHYsZaXkKgSxN03O5HRSF7TAtJ05I=; b=IIhMyQGUP+qAMNy+t66Mti0gcd+eMv5Ml05OVND1KL9MNVic87rOjSitgplxY2FPA9 Uk6hUB8Wwnfva6dvYHwXOnoAUADXD2he6CjRO2lXusuJEoHA7daXLEG9Q7uafEJqw8dX v4UvpL+uVFNBfe+wdI+Ni/mNbq73+o0M1gKLqe1h8MYklc6ho1mYsjyHkc7Su7pOsv5r OzW5aI1YWvVHHgSgZIo0L2Q6HdyrbFR97Ejm0mahgkEk1JoXgTo33Pi5UN2p49YrH20X cCVpxmGKylBeKmq96xcy9jkLfyrJov8GD/xCNZFk9PGaQzePtXmOsB4QLSdqLeW6l8T9 MzTA== 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=SoODso8L6sa7HFQHYsZaXkKgSxN03O5HRSF7TAtJ05I=; b=pjhugrcxYGV8NvryYajDvhkZkp3sXs1DPu6yxONWw/LWkxJFXSZmyqOsUTzXn1L1cT ZjlICItpbyPB6/nRxPMCbxnpAQ9Jo5HQIXUpzOH6aG1XXdAec5aZ7FuSYs3xy8JqltT2 FxNrd/97gs0DPNWPiadtUrLppbp8JU62r939uf7uD4bntdYcNpjuHRJ9xvBT7LKbb/6R 9TIg8tK2/n1sqBdv6VbmUr54mwwaRVHN0pnRnBnK7PC9O1m4r6H/kJzfm6+T81nDwlyC m/3JL5ft1IxXun/nWscMt82pL6y+/Y5ZX5/J9kmtNuVQOvYZ2gRXlCeayDbeBXAtosdb Qp5Q== X-Gm-Message-State: AOAM532I1BQzjdkfVV1Px0rs5QYVIZN9f5QhNbo1zSEr+keXWhZP8qOx 7WbvtOEkHrNctjO4oZ5VQPMYvA== X-Google-Smtp-Source: ABdhPJx3YsAVMJBhIghLwOcLGYcr7mGbOJK7z8REh6VI3AXumSRWMKZZHZ6EDcCH5zYiE1Qulb+oFw== X-Received: by 2002:a05:6402:1941:b0:413:2b7e:676e with SMTP id f1-20020a056402194100b004132b7e676emr11372703edz.114.1650738147009; Sat, 23 Apr 2022 11:22:27 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-176-92.adslplus.ch. [188.155.176.92]) by smtp.gmail.com with ESMTPSA id g24-20020a056402321800b00423e43ebb60sm2399227eda.61.2022.04.23.11.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 11:22:26 -0700 (PDT) From: Krzysztof Kozlowski To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , ChiYuan Huang , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Krzysztof Kozlowski , Rob Herring Subject: [PATCH v2 1/2] regulator: dt-bindings: richtek,rt4801: use existing ena_gpiod feature Date: Sat, 23 Apr 2022 20:14:18 +0200 Message-Id: <20220423181419.19397-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220423181419.19397-1-krzysztof.kozlowski@linaro.org> References: <20220423181419.19397-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The binding and driver duplicated regulator core feature of controlling regulators with GPIOs (of_parse_cb + ena_gpiod) and created its own enable-gpios property with multiple GPIOs. This is a less preferred way, because enable-gpios should enable only one element, not multiple. It also duplicates existing solution. Deprecate the original 'enable-gpios' and add per-regulator property. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Rob Herring --- .../regulator/richtek,rt4801-regulator.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/regulator/richtek,rt4801-reg= ulator.yaml b/Documentation/devicetree/bindings/regulator/richtek,rt4801-re= gulator.yaml index 4a4dfa7d9d09..091150c4e579 100644 --- a/Documentation/devicetree/bindings/regulator/richtek,rt4801-regulator.= yaml +++ b/Documentation/devicetree/bindings/regulator/richtek,rt4801-regulator.= yaml @@ -32,8 +32,11 @@ properties: If only one gpio is specified, only one gpio used to control ENP/ENM. Else if both are specified, DSVP/DSVN could be controlled individual= ly. If this property not specified, treat both as always-on regulators. + + Property is deprecated. Use enable-gpios in each regulator. minItems: 1 maxItems: 2 + deprecated: true =20 patternProperties: "^DSV(P|N)$": @@ -42,6 +45,14 @@ patternProperties: description: Properties for single display bias regulator. =20 + properties: + enable-gpios: + description: + GPIO to use to enable DSVP/DSVN regulator. One GPIO can be confi= gured + for controlling both regulators. If this property not specified= for + any regulator, treat both as always-on regulators. + maxItems: 1 + required: - compatible - reg @@ -57,19 +68,20 @@ examples: rt4801@73 { compatible =3D "richtek,rt4801"; reg =3D <0x73>; - enable-gpios =3D <&gpio26 2 0>, <&gpio26 3 0>; =20 dsvp: DSVP { regulator-name =3D "rt4801,dsvp"; regulator-min-microvolt =3D <4000000>; regulator-max-microvolt =3D <6000000>; regulator-boot-on; + enable-gpios =3D <&gpio26 2 0>; }; dsvn: DSVN { regulator-name =3D "rt4801,dsvn"; regulator-min-microvolt =3D <4000000>; regulator-max-microvolt =3D <6000000>; regulator-boot-on; + enable-gpios =3D <&gpio26 3 0>; }; =20 }; --=20 2.32.0 From nobody Sun May 10 21:19:55 2026 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 CF996C433EF for ; Sat, 23 Apr 2022 18:22:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236734AbiDWSZd (ORCPT ); Sat, 23 Apr 2022 14:25:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235469AbiDWSZ1 (ORCPT ); Sat, 23 Apr 2022 14:25:27 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C2C1F7D68 for ; Sat, 23 Apr 2022 11:22:29 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id be20so5696197edb.12 for ; Sat, 23 Apr 2022 11:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Nvtk3WrJqJk+qmVO4Q6Di137/3oPd7qzHUoK/qF/8hw=; b=lO+OXKgCTtcaXG67Svqw2oQgTlbnzRtqNz+BeBXdsn2GRmxuHNgmTtUvpSHd/r/c7j OQgRPqEeUtcDlftqQhCrNE0M1p/C//4QIOjXd4xmCcKh7h68vGDXvYNJfrYi5iyCX5us jReAWbUSFKXrBTbf7WnSRQfm0lVC9YAGMCH2YOkhv6UixP5L4K11W0XOX6Bspb/xtSM/ /TqnScOU8iknMS1T23sqywMmo8oANvQtuOma42IXKqvS5FMTIaqHuAg2U2bk8mLXXF8Z wriL0TD2PvrsGnYyZhGpXlS4kYwGUCalx6TfbUY3bcmxSC6O5Zt9Y33lnP5A8DN2j9Yh Uz7Q== 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=Nvtk3WrJqJk+qmVO4Q6Di137/3oPd7qzHUoK/qF/8hw=; b=pe7u22XSenegOrp22xOoztjqh9+a+aR51xR2OCKxDPdvmOAgkkbeJnwoVkUme4Hizk 0lGCYBq4I4AQvM9JNC8Bqa5pywsQXSXOsTtDCaNQOkse4CznPE0n8p/RHn17YyeljbJ1 CxvGWvmwnV8CeiRM95XaMf1mMcuLZZtUKB0TYmm2lsy4g76hNlAASsjwWhNUV1hsjTBR XHSKh0Sx8n56Kbw1qKhLd5uR2jliGb4hBWviNpebRho9h5EuF1zkAMAf3EPYm88Ahexe lDbbyJqbOS4sIKeN0h0Td+RuS/510JC/IZRgV2qJPfhnp2z2oHTVRq2kh5zbe6DSa0qu UmOw== X-Gm-Message-State: AOAM530B+ncdvFit/TcYq6gZrX7eF230Yy4wtgMY92WMGDJNkFdcGezk N/itjgtNluMkOusJLPLsxFWNjCcLdXBxdw== X-Google-Smtp-Source: ABdhPJyg0jFFNwg0LctM7/+1curlTdprK5AH7XCrttRgbfW7DJCgpEf4E2D+vM9rzAyGQZIYOidADA== X-Received: by 2002:a05:6402:1291:b0:425:de54:f5b with SMTP id w17-20020a056402129100b00425de540f5bmr51958edv.154.1650738147896; Sat, 23 Apr 2022 11:22:27 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-176-92.adslplus.ch. [188.155.176.92]) by smtp.gmail.com with ESMTPSA id g24-20020a056402321800b00423e43ebb60sm2399227eda.61.2022.04.23.11.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 11:22:27 -0700 (PDT) From: Krzysztof Kozlowski To: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , ChiYuan Huang , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH v2 2/2] regulator: richtek,rt4801: use existing ena_gpiod feature Date: Sat, 23 Apr 2022 20:14:19 +0200 Message-Id: <20220423181419.19397-3-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220423181419.19397-1-krzysztof.kozlowski@linaro.org> References: <20220423181419.19397-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The driver duplicated regulator core feature of controlling regulators with GPIOs (of_parse_cb + ena_gpiod) and created its own enable-gpios property with multiple GPIOs. The core already does it. Keep old method for backwards compatibility. Signed-off-by: Krzysztof Kozlowski --- drivers/regulator/rt4801-regulator.c | 68 ++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/rt4801-regulator.c b/drivers/regulator/rt480= 1-regulator.c index 7a87788d3f09..22efe44cd3a0 100644 --- a/drivers/regulator/rt4801-regulator.c +++ b/drivers/regulator/rt4801-regulator.c @@ -29,17 +29,71 @@ =20 struct rt4801_priv { struct device *dev; + /* + * Driver supports enable GPIOs in two ways: + * 1. Legacy enable-gpios property with multiple entries and enable + * control handled by the driver. + * 2. Per-regulator enable-gpios property with enable control handled by + * the regulator core. + * + * The enable_gpios and enable_flag properties are for the (1) case. + */ struct gpio_descs *enable_gpios; unsigned int enable_flag; unsigned int volt_sel[DSV_OUT_MAX]; }; =20 +static int rt4801_of_parse_cb(struct device_node *np, + const struct regulator_desc *desc, + struct regulator_config *config) +{ + struct rt4801_priv *priv =3D config->driver_data; + + if (priv->enable_gpios) { + dev_warn(priv->dev, "duplicated enable-gpios property\n"); + return 0; + } + config->ena_gpiod =3D fwnode_gpiod_get_index(of_fwnode_handle(np), + "enable-gpios", + 0, + GPIOD_OUT_HIGH | + GPIOD_FLAGS_BIT_NONEXCLUSIVE, + "rt4801"); + if (IS_ERR(config->ena_gpiod)) + config->ena_gpiod =3D NULL; + + return 0; +} + +/* + * regulator_ops->is_enabled() implementation + */ +static int rt4801_is_enabled(struct regulator_dev *rdev) +{ + struct rt4801_priv *priv =3D rdev_get_drvdata(rdev); + int id =3D rdev_get_id(rdev); + + return !!(priv->enable_flag & BIT(id)); +} + +/* + * Internally used only is_enabled() implementation using also ena_pin from + * regulator core. + */ +static bool rt4801_is_enabled_ena_pin(struct regulator_dev *rdev) +{ + if (rdev->ena_pin) + return rdev->ena_gpio_state; + + return rt4801_is_enabled(rdev); +} + static int rt4801_set_voltage_sel(struct regulator_dev *rdev, unsigned int= selector) { struct rt4801_priv *priv =3D rdev_get_drvdata(rdev); int id =3D rdev_get_id(rdev), ret; =20 - if (priv->enable_flag & BIT(id)) { + if (rt4801_is_enabled_ena_pin(rdev)) { ret =3D regulator_set_voltage_sel_regmap(rdev, selector); if (ret) return ret; @@ -54,7 +108,7 @@ static int rt4801_get_voltage_sel(struct regulator_dev *= rdev) struct rt4801_priv *priv =3D rdev_get_drvdata(rdev); int id =3D rdev_get_id(rdev); =20 - if (priv->enable_flag & BIT(id)) + if (rt4801_is_enabled_ena_pin(rdev)) return regulator_get_voltage_sel_regmap(rdev); =20 return priv->volt_sel[id]; @@ -100,14 +154,6 @@ static int rt4801_disable(struct regulator_dev *rdev) return 0; } =20 -static int rt4801_is_enabled(struct regulator_dev *rdev) -{ - struct rt4801_priv *priv =3D rdev_get_drvdata(rdev); - int id =3D rdev_get_id(rdev); - - return !!(priv->enable_flag & BIT(id)); -} - static const struct regulator_ops rt4801_regulator_ops =3D { .list_voltage =3D regulator_list_voltage_linear, .set_voltage_sel =3D rt4801_set_voltage_sel, @@ -122,6 +168,7 @@ static const struct regulator_desc rt4801_regulator_des= cs[] =3D { .name =3D "DSVP", .ops =3D &rt4801_regulator_ops, .of_match =3D of_match_ptr("DSVP"), + .of_parse_cb =3D rt4801_of_parse_cb, .type =3D REGULATOR_VOLTAGE, .id =3D DSV_OUT_POS, .min_uV =3D MIN_UV, @@ -135,6 +182,7 @@ static const struct regulator_desc rt4801_regulator_des= cs[] =3D { .name =3D "DSVN", .ops =3D &rt4801_regulator_ops, .of_match =3D of_match_ptr("DSVN"), + .of_parse_cb =3D rt4801_of_parse_cb, .type =3D REGULATOR_VOLTAGE, .id =3D DSV_OUT_NEG, .min_uV =3D MIN_UV, --=20 2.32.0