From nobody Thu May 7 17:33:37 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 2BBA1C433EF for ; Mon, 23 May 2022 05:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234385AbiEWF2j (ORCPT ); Mon, 23 May 2022 01:28:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232767AbiEWF2T (ORCPT ); Mon, 23 May 2022 01:28:19 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44E861EC58 for ; Sun, 22 May 2022 22:28:17 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id p189so8002312wmp.3 for ; Sun, 22 May 2022 22:28:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=am8B+AfzENDAWt/qUpAzFaFRwymNfGJXzUuOXFbCk5M=; b=epimhOkcWXRnlpp8as0ZW+FCbrusHfj/ITRwlU6Vhp/3I6NG2pkCv6U0JAXbECrxAi 5JgX4XrBwfOygUCyihy2r2LJEbBes9nonYi7JaEe6elkb5RyKPBNoj6DDWiL3rX/GLl1 xyLLbKsrVDmAJYjht4vIWAonOCNupzue4YniEXzr4VTxfQwYF5kqaSTlLp8sPhRngcLu dOYDtisMlBvTmVCC60hthfCVO5+6Au+C6JDq1HGzNPZwzZ5oP42aotzyjgnXulr9QUV5 abEN04R+Umu8SsgDhPFY2wzEbh+hTg683evjd6Oy4unU/bhxeSf3igPWv144MTNMYyj5 7oOQ== 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=am8B+AfzENDAWt/qUpAzFaFRwymNfGJXzUuOXFbCk5M=; b=1AZ8gNECjtqNxht+Kq3rKjdwSEAx7imvwbIQFTW1aTpJGGzEtCF6IFBdEJnM/XQxEM hh2ClVzKozvmNYrUvIp4wDua7wPYX73NkLEWkdLbm7JUTvg5s17Dv3QgviZy2iDTKdhV 1yIHX7aLzNrd+iCiG/Tcir7H31fOy8cvSIt4Ppzg5uZc+Ek11U0yMBttCvurkmb5DG2+ atpZOeeIznmKvWkQdXAFdivXo7KJ//CoG33svfT/orM2wyqTZBkRi5B9fXzXwjVsaknk 2GK9aQ64eUVMlG0Be1VLc78K1eFFExWjZevu31SZ5ovBFkmUQijjvliV0he4qj+bkAYN HYGA== X-Gm-Message-State: AOAM530LbPaEsrlOjspPP0laRZCTrgjwTWTYlVinfDPltW0NKhHpuyU0 z7Dew0neMP89hZoHNEWodxtbVg== X-Google-Smtp-Source: ABdhPJzm/entZ+SLPL0EhI0XgtI+1xyVC6MTxHThdpeAizznoJknLGj7DCHKY7ficjfSib+0ndrkiA== X-Received: by 2002:a05:600c:348e:b0:397:3f81:2168 with SMTP id a14-20020a05600c348e00b003973f812168mr2752873wmq.168.1653283695871; Sun, 22 May 2022 22:28:15 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id h2-20020a1ccc02000000b0039466988f6csm7802414wmb.31.2022.05.22.22.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 22:28:15 -0700 (PDT) From: Corentin Labbe To: andrew@lunn.ch, broonie@kernel.org, calvin.johnson@oss.nxp.com, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, jernej.skrabec@gmail.com, krzysztof.kozlowski+dt@linaro.org, kuba@kernel.org, lgirdwood@gmail.com, linux@armlinux.org.uk, pabeni@redhat.com, robh+dt@kernel.org, samuel@sholland.org, wens@csie.org Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, netdev@vger.kernel.org, Corentin Labbe Subject: [PATCH v3 1/3] regulator: Add regulator_bulk_get_all Date: Mon, 23 May 2022 05:28:05 +0000 Message-Id: <20220523052807.4044800-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523052807.4044800-1-clabbe@baylibre.com> References: <20220523052807.4044800-1-clabbe@baylibre.com> 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" It work exactly like regulator_bulk_get() but instead of working on a provided list of names, it seek all consumers properties matching xxx-supply. Signed-off-by: Corentin Labbe Reported-by: kernel test robot --- drivers/regulator/core.c | 92 ++++++++++++++++++++++++++++++ include/linux/regulator/consumer.h | 2 + 2 files changed, 94 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1e54a833f2cf..7286bcf3821a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -4813,6 +4813,98 @@ static void regulator_bulk_enable_async(void *data, = async_cookie_t cookie) bulk->ret =3D regulator_enable(bulk->consumer); } =20 +/* + * Check if name is a supply name according to the '*-supply' pattern + * return 0 if false + * return length of supply name without the -supply + */ +static int is_supply_name(const char *name) +{ + int strs, i; + + strs =3D strlen(name); + /* string need to be at minimum len(x-supply) */ + if (strs < 8) + return 0; + for (i =3D strs - 6; i > 0; i--) { + /* find first '-' and check if right part is supply */ + if (name[i] !=3D '-') + continue; + if (strcmp(name + i + 1, "supply") !=3D 0) + return 0; + return i; + } + return 0; +} + +/* + * regulator_bulk_get_all - get multiple regulator consumers + * + * @dev: Device to supply + * @np: device node to search for consumers + * @consumers: Configuration of consumers; clients are stored here. + * + * @return number of regulators on success, an errno on failure. + * + * This helper function allows drivers to get several regulator + * consumers in one operation. If any of the regulators cannot be + * acquired then any regulators that were allocated will be freed + * before returning to the caller. + */ +int regulator_bulk_get_all(struct device *dev, struct device_node *np, + struct regulator_bulk_data **consumers) +{ + int num_consumers =3D 0; + struct regulator *tmp; + struct property *prop; + int i, n =3D 0, ret; + char name[64]; + + *consumers =3D NULL; + +/* + * first pass: get numbers of xxx-supply + * second pass: fill consumers + * */ +restart: + for_each_property_of_node(np, prop) { + i =3D is_supply_name(prop->name); + if (i =3D=3D 0) + continue; + if (!*consumers) { + num_consumers++; + continue; + } else { + memcpy(name, prop->name, i); + name[i] =3D '\0'; + tmp =3D regulator_get(dev, name); + if (!tmp) { + ret =3D -EINVAL; + goto error; + } + (*consumers)[n].consumer =3D tmp; + n++; + continue; + } + } + if (*consumers) + return num_consumers; + if (num_consumers =3D=3D 0) + return 0; + *consumers =3D kmalloc_array(num_consumers, + sizeof(struct regulator_bulk_data), + GFP_KERNEL); + if (!*consumers) + return -ENOMEM; + goto restart; + +error: + while (--n >=3D 0) + regulator_put(consumers[n]->consumer); + return ret; +} +EXPORT_SYMBOL_GPL(regulator_bulk_get_all); + /** * regulator_bulk_enable - enable multiple regulator consumers * diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/c= onsumer.h index bbf6590a6dec..b9b1d1cbdd07 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -238,6 +238,8 @@ int regulator_disable_deferred(struct regulator *regula= tor, int ms); =20 int __must_check regulator_bulk_get(struct device *dev, int num_consumers, struct regulator_bulk_data *consumers); +int __must_check regulator_bulk_get_all(struct device *dev, struct device_= node *np, + struct regulator_bulk_data **consumers); int __must_check devm_regulator_bulk_get(struct device *dev, int num_consu= mers, struct regulator_bulk_data *consumers); int __must_check regulator_bulk_enable(int num_consumers, --=20 2.35.1 From nobody Thu May 7 17:33:37 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 3096DC433F5 for ; Mon, 23 May 2022 05:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355637AbiEWF2n (ORCPT ); Mon, 23 May 2022 01:28:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349939AbiEWF2V (ORCPT ); Mon, 23 May 2022 01:28:21 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 605CB1FA5C for ; Sun, 22 May 2022 22:28:18 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id p10so1009207wrg.12 for ; Sun, 22 May 2022 22:28:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hMbtP4l5NIdbJN9Ls/o3wbRNRvLgMN2alg0s8sMcV/I=; b=Rrc+F4WHPKFtZbfdPZhfGR1Bun8uOgA4F0ZgY8Iow4MAXe84LfyEgUj1wulOfOuBbT A6gowSS2SmqRoLu8mvZJFB+CSST0OEgqe1V1axQ+fvtefIxmzDb8yS3XVUZl2VuZW2np oQDnOgAuWRxjf9LkJ/qreSL/CeHxKmuBmu4Fg+wfAY5DNwP4fhM1YH2Hm6s0bwjc4Tyr EBwAlDZI3LICLlQHL3cLv4tF8uFcsWKDOZJdW2hU50jlqPL6VsY2dDIsGRUHIAn9oFFX bagJQ3t+GR6tjlYCXXQOECYOxhjUvUmVORQMCihCbgUULVOqx/vAkA/YJYPH/Xnnn/r1 94bQ== 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=hMbtP4l5NIdbJN9Ls/o3wbRNRvLgMN2alg0s8sMcV/I=; b=DFqpa4zAcT9maseMBiLaqlGPVebFOg4DwiCc2EAHF94zRAWsXmyqQoZDD0W/nNiL1p /lhU+kXGXaA7gGdZhnQQ6rsRycGUl0vpDNEVSNdGNMa2scbajkRNcvYSyU+++OW40zNz rCPL4TFkR62zg6DU1uPOw5JeTkalvxWY4YU6QzQKRK9kme9+tLtMzSOWohfDTpGbSoIL Pcxyaa/8e9YmxySkz5hHV1RXzrZZ/PpPpaqvuwHQGacHUNfc3zj/IZGnt+jeIICSMOur IQatJo+DBq3yCACXggqzftot3Phrn6r4Dhq6IDZPlv1bgrm5UaffIQEn9QW3M1ZvORTD N7Nw== X-Gm-Message-State: AOAM531UfMx+nfTOojt6b8WXDA5OFeiOxpki0XSexT40ZRmhYGhQYjzk kb3EvmqpGPLs8/lNg3VkNCu3bQ== X-Google-Smtp-Source: ABdhPJwPH32818/ysyCFl3DUF5kdKny0XUvYHvdybODc/cafFr8AsehjAS9sZfOvGlftg89tpe6jgg== X-Received: by 2002:a05:6000:178d:b0:20f:e960:2f2 with SMTP id e13-20020a056000178d00b0020fe96002f2mr250812wrg.569.1653283696986; Sun, 22 May 2022 22:28:16 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id h2-20020a1ccc02000000b0039466988f6csm7802414wmb.31.2022.05.22.22.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 22:28:16 -0700 (PDT) From: Corentin Labbe To: andrew@lunn.ch, broonie@kernel.org, calvin.johnson@oss.nxp.com, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, jernej.skrabec@gmail.com, krzysztof.kozlowski+dt@linaro.org, kuba@kernel.org, lgirdwood@gmail.com, linux@armlinux.org.uk, pabeni@redhat.com, robh+dt@kernel.org, samuel@sholland.org, wens@csie.org Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, netdev@vger.kernel.org, Corentin Labbe Subject: [PATCH v3 2/3] phy: handle optional regulator for PHY Date: Mon, 23 May 2022 05:28:06 +0000 Message-Id: <20220523052807.4044800-3-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523052807.4044800-1-clabbe@baylibre.com> References: <20220523052807.4044800-1-clabbe@baylibre.com> 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" Add handling of optional regulators for PHY. Regulators need to be enabled before PHY scanning, so MDIO bus initiate this task. Signed-off-by: Corentin Labbe Signed-off-by: Corentin Labbe Reported-by: kernel test robot --- drivers/net/mdio/Kconfig | 1 + drivers/net/mdio/fwnode_mdio.c | 36 ++++++++++++++++++++++++++++++---- drivers/net/phy/phy_device.c | 10 ++++++++++ include/linux/phy.h | 3 +++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig index bfa16826a6e1..3f8098fac74b 100644 --- a/drivers/net/mdio/Kconfig +++ b/drivers/net/mdio/Kconfig @@ -22,6 +22,7 @@ config MDIO_BUS config FWNODE_MDIO def_tristate PHYLIB depends on (ACPI || OF) || COMPILE_TEST + depends on REGULATOR select FIXED_PHY help FWNODE MDIO bus (Ethernet PHY) accessors diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 1c1584fca632..7f0d3bc81c52 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Calvin Johnson "); MODULE_LICENSE("GPL"); @@ -94,7 +95,10 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct phy_device *phy; bool is_c45 =3D false; u32 phy_id; - int rc; + int rc, reg_cnt =3D 0; + struct regulator_bulk_data *consumers; + struct device_node *nchild =3D NULL; + u32 reg; =20 mii_ts =3D fwnode_find_mii_timestamper(child); if (IS_ERR(mii_ts)) @@ -105,15 +109,35 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (rc >=3D 0) is_c45 =3D true; =20 + for_each_child_of_node(bus->dev.of_node, nchild) { + of_property_read_u32(nchild, "reg", ®); + if (reg !=3D addr) + continue; + reg_cnt =3D regulator_bulk_get_all(&bus->dev, nchild, &consumers); + if (reg_cnt > 0) { + rc =3D regulator_bulk_enable(reg_cnt, consumers); + if (rc) + return rc; + } + if (reg_cnt < 0) { + dev_err(&bus->dev, "Fail to regulator_bulk_get_all err=3D%d\n", reg_cnt= ); + return reg_cnt; + } + } + if (is_c45 || fwnode_get_phy_id(child, &phy_id)) phy =3D get_phy_device(bus, addr, is_c45); else phy =3D phy_device_create(bus, addr, phy_id, 0, NULL); if (IS_ERR(phy)) { unregister_mii_timestamper(mii_ts); - return PTR_ERR(phy); + rc =3D PTR_ERR(phy); + goto error; } =20 + phy->regulator_cnt =3D reg_cnt; + phy->consumers =3D consumers; + if (is_acpi_node(child)) { phy->irq =3D bus->irq[addr]; =20 @@ -127,14 +151,14 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (rc) { phy_device_free(phy); fwnode_handle_put(phy->mdio.dev.fwnode); - return rc; + goto error; } } else if (is_of_node(child)) { rc =3D fwnode_mdiobus_phy_device_register(bus, phy, child, addr); if (rc) { unregister_mii_timestamper(mii_ts); phy_device_free(phy); - return rc; + goto error; } } =20 @@ -145,5 +169,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (mii_ts) phy->mii_ts =3D mii_ts; return 0; +error: + if (reg_cnt > 0) + regulator_bulk_disable(reg_cnt, consumers); + return rc; } EXPORT_SYMBOL(fwnode_mdiobus_register_phy); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 431a8719c635..711919e40ef7 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1785,6 +1786,9 @@ int phy_suspend(struct phy_device *phydev) if (!ret) phydev->suspended =3D true; =20 + if (phydev->regulator_cnt > 0) + regulator_bulk_disable(phydev->regulator_cnt, phydev->consumers); + return ret; } EXPORT_SYMBOL(phy_suspend); @@ -1811,6 +1815,12 @@ int phy_resume(struct phy_device *phydev) { int ret; =20 + if (phydev->regulator_cnt > 0) { + ret =3D regulator_bulk_enable(phydev->regulator_cnt, phydev->consumers); + if (ret) + return ret; + } + mutex_lock(&phydev->lock); ret =3D __phy_resume(phydev); mutex_unlock(&phydev->lock); diff --git a/include/linux/phy.h b/include/linux/phy.h index 508f1149665b..ef4e0ce67194 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -704,6 +704,9 @@ struct phy_device { void (*phy_link_change)(struct phy_device *phydev, bool up); void (*adjust_link)(struct net_device *dev); =20 + int regulator_cnt; + struct regulator_bulk_data *consumers; + #if IS_ENABLED(CONFIG_MACSEC) /* MACsec management functions */ const struct macsec_ops *macsec_ops; --=20 2.35.1 From nobody Thu May 7 17:33:37 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 F2718C433F5 for ; Mon, 23 May 2022 05:28:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349008AbiEWF2v (ORCPT ); Mon, 23 May 2022 01:28:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355608AbiEWF2V (ORCPT ); Mon, 23 May 2022 01:28:21 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2377165BC for ; Sun, 22 May 2022 22:28:19 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id r23so19660424wrr.2 for ; Sun, 22 May 2022 22:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kwRG8kJghq1J9woEQ8/8+NXh3AtgpEI2TuVWVjMfZMk=; b=0HpAzyrF8+FK9s9Lv6r8HnmS4n2VHb3e9NI+PYcrMI8MijK0B5XoHtXRkv0pI5tmky DTvP09m+Llj+BF8ipr7By+iseFMo7gGLtq7vYu96ZGeSz8zR0CmdFjxa2rF61Q3PyTwY 5fEIB+1cjJNCHPS/dqw3StWXVMUIT3lUwunNjpKiEUWCJwQHOQjt+RFSK+miW6Z4zbXs MWvJvH5fNK1m37DX7lV/wbjEtMDmkUVmoLJADDbcCKXYidinq0Ke37o8BrAO6EZyFLdC sFfsslVnXtIGNMmhcoHGHRzHo5UgF4kTZ2ol6Bar+kuhYmFZ4qSF3OhS2bQXw91eRaVo C3Og== 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=kwRG8kJghq1J9woEQ8/8+NXh3AtgpEI2TuVWVjMfZMk=; b=JamCiVyqwGmFP8sazL5ZjLtU6QZstFIS2j5f22FmWnjq1RNGWvOAhDjpjIjFKJ/v18 9z0NeN/YcZg+CEEjphlgfr4bbUDZo6MLsWdLosBTZdLZ6r2uTW47D+FBgUjIAD7+rcqG Ih2ZRTm6CskOjqxVbmohmdYoer9iIZ/sIV8hOim7BtKoqDCGbRMtOU6gjYQU/81zzrWq ZdR//HDzh1XSmNn8aiSD08cs3D97NB9nj4ISYAyiQPB+bfEZ5sUEHjH/yftNInGUWvE3 Gu/ZYJ3TOSfBq3I07/A2AKVvWMeF+CKHHuyZtbwUX0hGjHmK3SB5mYlOUXGbApHWp4Vg jmkw== X-Gm-Message-State: AOAM531JpCeVgJN2bQFo+TghhLrKYJbzWuNGNY79OmmHYWy9uX//CYXI AKAVTgcybipKbbpCFg1v/YexDw== X-Google-Smtp-Source: ABdhPJy4dOiHRi8RxJS1vDYeuYztM8ZLIeJ4Hy3+HL2NtCowcnxhvWlaJf6kQexvMGXqL2AAqtP4hw== X-Received: by 2002:a5d:4bd2:0:b0:20f:cb39:c035 with SMTP id l18-20020a5d4bd2000000b0020fcb39c035mr6890506wrt.709.1653283698116; Sun, 22 May 2022 22:28:18 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id h2-20020a1ccc02000000b0039466988f6csm7802414wmb.31.2022.05.22.22.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 22:28:17 -0700 (PDT) From: Corentin Labbe To: andrew@lunn.ch, broonie@kernel.org, calvin.johnson@oss.nxp.com, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, jernej.skrabec@gmail.com, krzysztof.kozlowski+dt@linaro.org, kuba@kernel.org, lgirdwood@gmail.com, linux@armlinux.org.uk, pabeni@redhat.com, robh+dt@kernel.org, samuel@sholland.org, wens@csie.org Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, netdev@vger.kernel.org, =?UTF-8?q?Ond=C5=99ej=20Jirman?= , Corentin Labbe Subject: [PATCH v3 3/3] arm64: dts: allwinner: orange-pi-3: Enable ethernet Date: Mon, 23 May 2022 05:28:07 +0000 Message-Id: <20220523052807.4044800-4-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523052807.4044800-1-clabbe@baylibre.com> References: <20220523052807.4044800-1-clabbe@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ond=C5=99ej Jirman Orange Pi 3 has two regulators that power the Realtek RTL8211E PHY. According to the datasheet, both regulators need to be enabled at the same time, or that "phy-io" should be enabled slightly earlier than "phy" regulator. RTL8211E/RTL8211EG datasheet says: Note 4: 2.5V (or 1.8/1.5V) RGMII power should be risen simultaneously or slightly earlier than 3.3V power. Rising 2.5V (or 1.8/1.5V) power later than 3.3V power may lead to errors. The timing is set in DT via startup-delay-us. Signed-off-by: Ondrej Jirman Signed-off-by: Corentin Labbe --- .../dts/allwinner/sun50i-h6-orangepi-3.dts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h6-orangepi-3.dts b/arch/= arm64/boot/dts/allwinner/sun50i-h6-orangepi-3.dts index c45d7b7fb39a..2760a0bf76d5 100644 --- a/arch/arm64/boot/dts/allwinner/sun50i-h6-orangepi-3.dts +++ b/arch/arm64/boot/dts/allwinner/sun50i-h6-orangepi-3.dts @@ -13,6 +13,7 @@ / { compatible =3D "xunlong,orangepi-3", "allwinner,sun50i-h6"; =20 aliases { + ethernet0 =3D &emac; serial0 =3D &uart0; serial1 =3D &uart1; }; @@ -55,6 +56,15 @@ led-1 { }; }; =20 + reg_gmac_2v5: gmac-2v5 { + compatible =3D "regulator-fixed"; + regulator-name =3D "gmac-2v5"; + regulator-min-microvolt =3D <2500000>; + regulator-max-microvolt =3D <2500000>; + enable-active-high; + gpio =3D <&pio 3 6 GPIO_ACTIVE_HIGH>; /* PD6 */ + }; + reg_vcc5v: vcc5v { /* board wide 5V supply directly from the DC jack */ compatible =3D "regulator-fixed"; @@ -113,6 +123,33 @@ &ehci3 { status =3D "okay"; }; =20 +&emac { + pinctrl-names =3D "default"; + pinctrl-0 =3D <&ext_rgmii_pins>; + phy-mode =3D "rgmii-id"; + phy-handle =3D <&ext_rgmii_phy>; + status =3D "okay"; +}; + +&mdio { + ext_rgmii_phy: ethernet-phy@1 { + compatible =3D "ethernet-phy-ieee802.3-c22"; + reg =3D <1>; + /* + * The board uses 2.5V RGMII signalling. Power sequence to enable + * the phy is to enable GMAC-2V5 and GMAC-3V (aldo2) power rails + * at the same time and to wait 100ms. The driver enables phy-io + * first. Delay is achieved with enable-ramp-delay on reg_aldo2. + */ + phy-io-supply =3D <®_gmac_2v5>; + ephy-supply =3D <®_aldo2>; + + reset-gpios =3D <&pio 3 14 GPIO_ACTIVE_LOW>; /* PD14 */ + reset-assert-us =3D <15000>; + reset-deassert-us =3D <40000>; + }; +}; + &gpu { mali-supply =3D <®_dcdcc>; status =3D "okay"; @@ -211,6 +248,7 @@ reg_aldo2: aldo2 { regulator-min-microvolt =3D <3300000>; regulator-max-microvolt =3D <3300000>; regulator-name =3D "vcc33-audio-tv-ephy-mac"; + regulator-enable-ramp-delay =3D <100000>; }; =20 /* ALDO3 is shorted to CLDO1 */ --=20 2.35.1