From nobody Mon Jun 15 18:37:06 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 25BBEC433EF for ; Mon, 25 Apr 2022 07:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235977AbiDYH2Q (ORCPT ); Mon, 25 Apr 2022 03:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234544AbiDYH2J (ORCPT ); Mon, 25 Apr 2022 03:28:09 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38C7C65AB for ; Mon, 25 Apr 2022 00:25:04 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id l18so1223269ejc.7 for ; Mon, 25 Apr 2022 00:25:04 -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=AmFJus8NbOetI0QrnOux4GaQiTNEofANqLpB7A6WRugvw+OiMut0H+jUTEvwyA1mp5 anYXLqISWTmYpVLdwOY8UCmXf7mq3ey/Koa/LqhF+d/+x5fUTZ7LpYP1icCHSPTrIXLo lKqFRc5yf05azrnqzYn23KQ1uy1SChcRflCmL6UGtZ7qQAume+Yvkm3+D/AtVaDufuUj v1XsKaV4lNwI6MzK/Y0sQT0HveaNT6G3VvcEYQn4V1ZjvWNr4irj1LwCemc6FnKx/fKd WbhiGR/OQwbW0pdJC8F6sOuclj/WGeFCj9nmG8cHT9xtNeJfQFAaOtoksFwu6XbBGK2G xSpw== 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=vetCfaQoiE9xMcxpuVPPSOmyyBcQkQZtUEMeSLiYmZ6GJiDhhXegPcDLiwPsbs065W oOZ9hXZWBYP2RAYK2vG9nEa1APafHJhdIXitU/BONacMMxYHUqu1WfMuf6gRztrkSvf6 bCq2IUardFrNh8zCwIeLk3Nj7cH6qsTcJ5F97Tfedyyjib50MCwTANa0gZyYtLSUUlKR 86u7fBD4izjKKHXo6wSQ63S7xo3kT9vNQJfFe8fia+vIQVJO3202GfNZcWjd2423A7LW 3GVQx33A4axSHZI8fw8U8h26hv3mVLvUgFk2aTTSOGCIHNRUY7kiJ4/VaMNmvpJHg59B 1s6Q== X-Gm-Message-State: AOAM531PA8Zf1TkmbsCjv1VmKfRGoPcrFhwFom7Jf/7r+1rG1oA7ufKb lwQb4+ZDftrepyxlNOzoBb/ijg== X-Google-Smtp-Source: ABdhPJzKnpdptt08dU79kDGzwycj/X+olIfJ/74b/VfkbElhCem+dohAecEIbqRw08tw5aKsrtzVOQ== X-Received: by 2002:a17:907:2cc4:b0:6ef:8108:ad11 with SMTP id hg4-20020a1709072cc400b006ef8108ad11mr14851775ejc.20.1650871502729; Mon, 25 Apr 2022 00:25:02 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-176-92.adslplus.ch. [188.155.176.92]) by smtp.gmail.com with ESMTPSA id ew15-20020a170907950f00b006f3a3d60b9csm44328ejc.63.2022.04.25.00.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 00:25:02 -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 v3 1/2] regulator: dt-bindings: richtek,rt4801: use existing ena_gpiod feature Date: Mon, 25 Apr 2022 09:24:54 +0200 Message-Id: <20220425072455.27356-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425072455.27356-1-krzysztof.kozlowski@linaro.org> References: <20220425072455.27356-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 Mon Jun 15 18:37:06 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 906E6C433EF for ; Mon, 25 Apr 2022 07:25:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235487AbiDYH2X (ORCPT ); Mon, 25 Apr 2022 03:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234824AbiDYH2J (ORCPT ); Mon, 25 Apr 2022 03:28:09 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FFB065E8 for ; Mon, 25 Apr 2022 00:25:05 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id m20so7120077ejj.10 for ; Mon, 25 Apr 2022 00:25:05 -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=7qcayQ5d+q+z0ZKjKvnlBCT5f3rdCkuSENpIujOsc0c=; b=j28TisVZ2eT3sOJZncj07IR4bq8jZH1b1KVQSn7oSDMBujfba1freM1yBmN7k9x022 MfW8wvNQMjRwjRWudZRG5Aq0yKg2Co18HGFDzkB4UR4j+DVpGyxyB2EMTFK/jPcoxlRV KLbsw4R0AvTbQKhuKiOMb9ZDIG1tv4Zp89R0SKR7Grjiow3jQAVZsCUh8EjepGXLX2Bl Qp2tteh8r4J1IpNCSm9iTyrpbLmlF74fSv26kmcDSuChX/JkQoU0XfjA9STDC393R/JZ oW+04/T8M7gxo6HAjlivUpncEBeZSGPy9PVtThATQNvy2fZaDTffylgmn+WXAmoWYoS2 Ji0A== 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=7qcayQ5d+q+z0ZKjKvnlBCT5f3rdCkuSENpIujOsc0c=; b=A4AD60CBOzYan2G7jTARo11d/y10CyiSz82GNbKCL978yi93ApEC7D0rCe9d7+Kg4z R6eOkpZDDHF/xBEVLz85qYpJVJC1sEeEMuaYgTFWReK2MeM2rWI4Vqqsi0KM6XcIsIvm zy+xMzfGX0tw4ISmogQ+P67vCBRuBcGDDuobN93WlhrTNeqJRtEilQrQbvlD5mBSoCwt VRXQ63ry0W/nCVWESSOMs0mVhPh17SuSIcLfdPFf2EWv2pJuyxqO52GIB/X0YQhXsuCP JircpUVzei/GiMEB7VqJxKGi65PwoVuYYHXVlQsGYoJtYkv0DNpxiGWKWY6hJ6yIWmyt OwBA== X-Gm-Message-State: AOAM530U2s56Qy6rKHd3q1Bv9Q3rtjNnCfoSwBbiWTt/wj2oU76rJUow NQfd7dkEBjZd06gc0Rc3S2TOwA== X-Google-Smtp-Source: ABdhPJxpB/sCZmdWbBjVSuQvAoFh6WcfY3j2pf5h5M0oR5V4ZOYHULDGhysVA5ec+hzKW8dQRqzc7w== X-Received: by 2002:a17:907:9005:b0:6da:81ae:a798 with SMTP id ay5-20020a170907900500b006da81aea798mr15152563ejc.699.1650871503792; Mon, 25 Apr 2022 00:25:03 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-176-92.adslplus.ch. [188.155.176.92]) by smtp.gmail.com with ESMTPSA id ew15-20020a170907950f00b006f3a3d60b9csm44328ejc.63.2022.04.25.00.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 00:25:03 -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 v3 2/2] regulator: richtek,rt4801: parse GPIOs per regulator Date: Mon, 25 Apr 2022 09:24:55 +0200 Message-Id: <20220425072455.27356-3-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425072455.27356-1-krzysztof.kozlowski@linaro.org> References: <20220425072455.27356-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" Having one enable-gpios property for all regulators is discouraged and instead, similarly to regulator core ena_gpiod feature, each GPIO should be present in each regulator node. Add support for parsing such GPIOs, keeping backwards compatibility. Signed-off-by: Krzysztof Kozlowski Tested-by: ChiYuan Huang --- drivers/regulator/rt4801-regulator.c | 49 +++++++++++++++++++++------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/regulator/rt4801-regulator.c b/drivers/regulator/rt480= 1-regulator.c index 7a87788d3f09..563d79196fdd 100644 --- a/drivers/regulator/rt4801-regulator.c +++ b/drivers/regulator/rt4801-regulator.c @@ -29,11 +29,33 @@ =20 struct rt4801_priv { struct device *dev; - struct gpio_descs *enable_gpios; + struct gpio_desc *enable_gpios[DSV_OUT_MAX]; 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; + int id =3D desc->id; + + if (priv->enable_gpios[id]) { + dev_warn(priv->dev, "duplicated enable-gpios property\n"); + return 0; + } + priv->enable_gpios[id] =3D devm_fwnode_gpiod_get_index(priv->dev, + of_fwnode_handle(np), + "enable", 0, + GPIOD_OUT_HIGH, + "rt4801"); + if (IS_ERR(priv->enable_gpios[id])) + priv->enable_gpios[id] =3D NULL; + + return 0; +} + static int rt4801_set_voltage_sel(struct regulator_dev *rdev, unsigned int= selector) { struct rt4801_priv *priv =3D rdev_get_drvdata(rdev); @@ -63,15 +85,14 @@ static int rt4801_get_voltage_sel(struct regulator_dev = *rdev) static int rt4801_enable(struct regulator_dev *rdev) { struct rt4801_priv *priv =3D rdev_get_drvdata(rdev); - struct gpio_descs *gpios =3D priv->enable_gpios; int id =3D rdev_get_id(rdev), ret; =20 - if (!gpios || gpios->ndescs <=3D id) { + if (!priv->enable_gpios[id]) { dev_warn(&rdev->dev, "no dedicated gpio can control\n"); goto bypass_gpio; } =20 - gpiod_set_value(gpios->desc[id], 1); + gpiod_set_value(priv->enable_gpios[id], 1); =20 bypass_gpio: ret =3D regmap_write(rdev->regmap, rdev->desc->vsel_reg, priv->volt_sel[i= d]); @@ -85,15 +106,14 @@ static int rt4801_enable(struct regulator_dev *rdev) static int rt4801_disable(struct regulator_dev *rdev) { struct rt4801_priv *priv =3D rdev_get_drvdata(rdev); - struct gpio_descs *gpios =3D priv->enable_gpios; int id =3D rdev_get_id(rdev); =20 - if (!gpios || gpios->ndescs <=3D id) { + if (!priv->enable_gpios[id]) { dev_warn(&rdev->dev, "no dedicated gpio can control\n"); goto bypass_gpio; } =20 - gpiod_set_value(gpios->desc[id], 0); + gpiod_set_value(priv->enable_gpios[id], 0); =20 bypass_gpio: priv->enable_flag &=3D ~BIT(id); @@ -122,6 +142,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 +156,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, @@ -172,10 +194,15 @@ static int rt4801_probe(struct i2c_client *i2c) return PTR_ERR(regmap); } =20 - priv->enable_gpios =3D devm_gpiod_get_array_optional(&i2c->dev, "enable",= GPIOD_OUT_HIGH); - if (IS_ERR(priv->enable_gpios)) { - dev_err(&i2c->dev, "Failed to get gpios\n"); - return PTR_ERR(priv->enable_gpios); + for (i =3D 0; i < DSV_OUT_MAX; i++) { + priv->enable_gpios[i] =3D devm_gpiod_get_index_optional(&i2c->dev, + "enable", + i, + GPIOD_OUT_HIGH); + if (IS_ERR(priv->enable_gpios[i])) { + dev_err(&i2c->dev, "Failed to get gpios\n"); + return PTR_ERR(priv->enable_gpios[i]); + } } =20 for (i =3D 0; i < DSV_OUT_MAX; i++) { --=20 2.32.0