From nobody Thu May 7 20:27:01 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 1D62BC433F5 for ; Wed, 18 May 2022 20:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242390AbiERUJ4 (ORCPT ); Wed, 18 May 2022 16:09:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242364AbiERUJu (ORCPT ); Wed, 18 May 2022 16:09:50 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65E272375DE for ; Wed, 18 May 2022 13:09:49 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id e28so3571243wra.10 for ; Wed, 18 May 2022 13:09:49 -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=0KczXNl/9anABcy3K+RQeZFJPAxsjOIOqB1/DLsrKFc=; b=NyHVRqHreDZKcytz8hWSWGRyMBK/Gyu/ugTIj5yEj9xTVltz5sneAJBFLbJHE93iEv uIvMsS6cq1K6950Twamwn/p8HkDYu7ytRmsH4Vi1I2PpB86LAsnZhoETu1oBPRwhRKOh dw4Z50DfUo5AE1P4eFpaBiXHirzI3xETzvAtYq4mTQhjn5nwog9pVPbJOZ25opwuDjXo mN2dHmI6K3B+snsTrb3h8xYMjIHoCy8tMsxUFV0zzeD+IpzqH0R3vJ0AVZTXv0++E3Va PNrPpg/QOEQXWoPC1zPW9vuiIjrnUeAKcazOxUgSYb/kQvIEOOim1hSfPDyM7XHUoQqw It2w== 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=0KczXNl/9anABcy3K+RQeZFJPAxsjOIOqB1/DLsrKFc=; b=4pQNbr4nChj25hxcsRIZpKMxIg6Z8cI9l3zS0hp3cToBhgI9DKeSmeEJLbCXmDkzXH hApJnKNXUZJ7/nCRWCR4gPHPoQfD42Mm52I98R5Xzrq1YG+eyGwpibqF6ZxK4WLlyory +jDGI9xeUXDCgad3lb+PMaCju8J2mGCUiB64r+Z3wMDIj4yHvPBK+kdWIxj3jpPHgCv8 fbLOnVVu4krxsNN9tOcYbe70Gj78KmeLBqbKui1Zabk9FX+iu5SI5Jhkue0TXFCxo61N 0w8Rutj5Oq80WzLAiJF2SZu0hE+4B0fLWyTXS/S706LuEaSo8OvJpcEuCx+S/Wi9cN11 k2JQ== X-Gm-Message-State: AOAM531SE/LgbJdSpyDZTMC4B3i0IjSH68hS80LovgwkQteMqgmfx266 7Mlypk3H7jkclCFnDz48FlJETA== X-Google-Smtp-Source: ABdhPJx1F7rRI2kbz2zJ8CXGzIHQjz1zodLDahnKCtWpusExTDqLaFpDJacqbNurT39m8xSu+p9daQ== X-Received: by 2002:a5d:47c9:0:b0:20c:80bb:a296 with SMTP id o9-20020a5d47c9000000b0020c80bba296mr1117991wrc.384.1652904587664; Wed, 18 May 2022 13:09:47 -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 o23-20020a05600c511700b0039456c00ba7sm6859281wms.1.2022.05.18.13.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:09:47 -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 v2 1/5] regulator: Add of_get_regulator_from_list Date: Wed, 18 May 2022 20:09:35 +0000 Message-Id: <20220518200939.689308-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com> References: <20220518200939.689308-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" of_get_regulator_from_list() permits to get a regulator from a regulators list. Then add support for such list in of_get_regulator() Signed-off-by: Corentin Labbe --- drivers/regulator/core.c | 44 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1e54a833f2cf..09578c3595de 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -351,6 +351,33 @@ static void regulator_lock_dependent(struct regulator_= dev *rdev, mutex_unlock(®ulator_list_mutex); } =20 +/** + * of_get_regulator_from_list - get a regulator device node based on suppl= y name + * from a DT regulators list + * @dev: Device pointer for the consumer (of regulator) device + * @np: The device node where to search for regulators list + * @supply: regulator supply name + * + * Extract the regulator device node corresponding to the supply name. + * returns the device node corresponding to the regulator if found, else + * returns NULL. + */ +static struct device_node *of_get_regulator_from_list(struct device *dev, + struct device_node *np, + const char *supply) +{ + struct of_phandle_args regspec; + int index, ret; + + index =3D of_property_match_string(np, "regulator-names", supply); + if (index >=3D 0) { + ret =3D of_parse_phandle_with_args(np, "regulators", NULL, index, ®sp= ec); + if (ret =3D=3D 0) + return regspec.np; + } + return NULL; +} + /** * of_get_child_regulator - get a child regulator device node * based on supply name @@ -362,17 +389,23 @@ static void regulator_lock_dependent(struct regulator= _dev *rdev, * returns the device node corresponding to the regulator if found, else * returns NULL. */ -static struct device_node *of_get_child_regulator(struct device_node *pare= nt, - const char *prop_name) +static struct device_node *of_get_child_regulator(struct device *dev, + struct device_node *parent, + const char *supply) { struct device_node *regnode =3D NULL; struct device_node *child =3D NULL; + char prop_name[64]; /* 64 is max size of property name */ =20 + snprintf(prop_name, 64, "%s-supply", supply); for_each_child_of_node(parent, child) { + regnode =3D of_get_regulator_from_list(dev, child, supply); + if (regnode) + return regnode; regnode =3D of_parse_phandle(child, prop_name, 0); =20 if (!regnode) { - regnode =3D of_get_child_regulator(child, prop_name); + regnode =3D of_get_child_regulator(dev, child, prop_name); if (regnode) goto err_node_put; } else { @@ -401,12 +434,15 @@ static struct device_node *of_get_regulator(struct de= vice *dev, const char *supp char prop_name[64]; /* 64 is max size of property name */ =20 dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); + regnode =3D of_get_regulator_from_list(dev, dev->of_node, supply); + if (regnode) + return regnode; =20 snprintf(prop_name, 64, "%s-supply", supply); regnode =3D of_parse_phandle(dev->of_node, prop_name, 0); =20 if (!regnode) { - regnode =3D of_get_child_regulator(dev->of_node, prop_name); + regnode =3D of_get_child_regulator(dev, dev->of_node, supply); if (regnode) return regnode; =20 --=20 2.35.1 From nobody Thu May 7 20:27:01 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 2EBD7C433FE for ; Wed, 18 May 2022 20:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242410AbiERUKF (ORCPT ); Wed, 18 May 2022 16:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242350AbiERUJv (ORCPT ); Wed, 18 May 2022 16:09:51 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70A512375DD for ; Wed, 18 May 2022 13:09:50 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id w4so4131462wrg.12 for ; Wed, 18 May 2022 13:09:50 -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=SriQP5QFvjv+22faclUlTpDEJWTfd/KIKG1YNKb9hlI=; b=J4LewnuHwL3OxcTIVsMV6xN29ahSYB41PufuCCLLZzBavi8wqCUKbAi0RjpMnBEpa5 noxOj3l/Q0xa0pfPtdvf18gKW9Zb/EZaRa/SOxIXnyxjw+nuiJb5QP5Q6GQR5P1GglVi JFHu9Ng85tUZ/O9Sni3weCi6mg7weoktZDBqFRtWbtamXTRTq3qS6/kmEPrzaItPPhXM KyOlMGsf+AphBrM5hvPo9sL4hpneCx/gYzeyF2xGgBAX7rF84qgKn4c3qUhmUOWjcsDg tHhCmxt7XboKoK+gHTmUYvQd0fnpwDrMxVY+s2J+1UdWz6fGjXwJ8f6y7QumTnTlUZ3R AZTg== 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=SriQP5QFvjv+22faclUlTpDEJWTfd/KIKG1YNKb9hlI=; b=naQcGApTybp6BQzl+V9biY0BDoKmb1+8WzyuOXj01eilD5ABx+dC7Slp0I8b+oetWI QgwTdF2w2K8JPrFEnJWiheCZ9UR210qaEA3j7EaQa/KeePObJSnqNPCMFfHqRcWwL4wU R2B6xSB1Bi+gug9qnt59lJhYLQUtEjezHTBhXnwk9FtD8k+9IPYYFxey9gBt4UTdf8MH 3L+xfTpD0PWNhlqnG2/+euh1K3bCnWYTYQNBMe50wpEIQ1uDog7LYD2JdQC/hs3zKpLe VwIpAqSsThcpLU7Ychjswvi2hq2RKw6WaL51liryD2r0dG9L40oDDpuZQYRq2K3ikUpT Vz0Q== X-Gm-Message-State: AOAM530ioZk+uhYwyhsl4PaSoczGuAUdZhbNY2xxLaBke8VzYSIjc8rG Tg0V6l2u9+bMZ3bNSa/YM0LTAw== X-Google-Smtp-Source: ABdhPJzppEln44MKcc9NY2qMbwnqkJ2Uq4IVab5lsOYJZ/r22l4fVuEatjuvyjoXfolPItUTNK1ZoA== X-Received: by 2002:a05:6000:186f:b0:20c:5f3d:44a4 with SMTP id d15-20020a056000186f00b0020c5f3d44a4mr1126253wri.152.1652904588901; Wed, 18 May 2022 13:09:48 -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 o23-20020a05600c511700b0039456c00ba7sm6859281wms.1.2022.05.18.13.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:09:48 -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 v2 2/5] regulator: Add regulator_bulk_get_all Date: Wed, 18 May 2022 20:09:36 +0000 Message-Id: <20220518200939.689308-3-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com> References: <20220518200939.689308-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 get names from a regulators list. Signed-off-by: Corentin Labbe --- drivers/regulator/core.c | 49 ++++++++++++++++++++++++++++++ include/linux/regulator/consumer.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 09578c3595de..719ce9a0db1b 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -4849,6 +4849,55 @@ static void regulator_bulk_enable_async(void *data, = async_cookie_t cookie) bulk->ret =3D regulator_enable(bulk->consumer); } =20 +/** + * regulator_bulk_get_all - get multiple regulator consumers + * + * @dev: Device to supply + * @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; + int i, ret; + struct regulator *tmp; + const char *p; + + num_consumers =3D of_property_count_elems_of_size(np, "regulators", + sizeof(phandle)); + if (num_consumers <=3D 0) + return num_consumers; + + ret =3D of_property_count_strings(np, "regulator-names"); + if (ret !=3D num_consumers) { + dev_err(dev, "regulators and regulator-names does not have the same size= \n"); + return -EINVAL; + } + *consumers =3D kmalloc_array(num_consumers, sizeof(struct regulator_bulk_= data), GFP_KERNEL); + if (!*consumers) + return -ENOMEM; + for (i =3D 0; i < num_consumers; i++) { + ret =3D of_property_read_string_helper(np, "regulator-names", &p, 1, i); + if (ret <=3D 0) + goto error; + tmp =3D regulator_get(dev, p); + (*consumers)[i].consumer =3D tmp; + } + return num_consumers; +error: + while (--i >=3D 0) + regulator_put(consumers[i]->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 20:27:01 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 52EC7C433F5 for ; Wed, 18 May 2022 20:10:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242421AbiERUKJ (ORCPT ); Wed, 18 May 2022 16:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242364AbiERUKA (ORCPT ); Wed, 18 May 2022 16:10:00 -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 77FD72375F3 for ; Wed, 18 May 2022 13:09:51 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j25so4149778wrc.9 for ; Wed, 18 May 2022 13:09:51 -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=zWSv1nsIrifugG1nZe+GG3CiYU/pokPOKop6RME5qNI=; b=qCU5VnLvgmoMb3sOSQ/yF4RotpAJ/DggXO7ITDvwgXeUbi++LQbYCQZVvxAC9EWHYJ Aq60BDj9bXJOIRTA+nNPwZ6iuQYMVUinVtV2xEl7u0NhDY+FdcL+1lUs5E0xAJZ2lGOc jZbWd59afyneSyQLuQmk5EgWYVPDMgInKRMAlVI23UIY343D34oREuXRKZnrUmUJwdqf 91nElBZnYyKcy0ewUU+t1WoWWyBeHW4XnkE65hQj4NLWTS7KQ56VuJe62d89P1iPDt39 5volX/xxiaQoVctOPh19b9jEBOX3pyctNFjSARMLa5VIR/FhqvDlcJF945k6Qklgtt91 mZuw== 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=zWSv1nsIrifugG1nZe+GG3CiYU/pokPOKop6RME5qNI=; b=H0e+DSdhLIyweNNGGWqwf2TbK7ARTwBtDlfNsYT38S54/FncijidpGR4DzqhNAMSu8 Iog4HYfu0RvErdqaHePs35NE0UQshMGPE+wsskDH7LBPcgqww/itw0gFpPUIQk2YqSqR w8M86o3mfvh3Nq3Y5HRe62MCL7aIXL16lc8TS2N2rOwThRl59p1LQjh1YKkMUKbXr2cc aLW771NsJ8kxiuvGPZzm15lc9N+2D438Xwr0qOrs3XlTMEYMfuqhXoSMCuOFqcAVo0LK Q4bNe9Sat/KlLt7u5XmsT0t8g1RlLkVSRAnlZCKqMTL2Y2lYejCIJatS5xixMPoTNjqC XMIQ== X-Gm-Message-State: AOAM532a8ktFnXPbP7nM5ngn/UUhteeAeRdA7JyB3NtiaNP06ygZ4rtM BsiGH0dZ+C4UX0afAQpnor7Agw== X-Google-Smtp-Source: ABdhPJxKaX4nnr3QSNO0ZrccrSGjmO+tuS/umKcp/f/i8ZDGyDoxnlqao/HKDNSLYAaLrFkeftXIQA== X-Received: by 2002:adf:eb82:0:b0:20c:a2eb:5fe6 with SMTP id t2-20020adfeb82000000b0020ca2eb5fe6mr1091386wrn.563.1652904590013; Wed, 18 May 2022 13:09:50 -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 o23-20020a05600c511700b0039456c00ba7sm6859281wms.1.2022.05.18.13.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:09:49 -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 v2 3/5] phy: handle optional regulator for PHY Date: Wed, 18 May 2022 20:09:37 +0000 Message-Id: <20220518200939.689308-4-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com> References: <20220518200939.689308-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 --- drivers/net/mdio/Kconfig | 1 + drivers/net/mdio/fwnode_mdio.c | 34 ++++++++++++++++++++++++++++++---- drivers/net/phy/phy_device.c | 10 ++++++++++ include/linux/phy.h | 3 +++ 4 files changed, 44 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..c97ccb0863f9 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,33 @@ 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; + } else { + dev_err(&bus->dev, "Fail to regulator_bulk_get_all err=3D%d\n", 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 +149,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 +167,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 20:27:01 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 CFBA5C433EF for ; Wed, 18 May 2022 20:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242472AbiERUKX (ORCPT ); Wed, 18 May 2022 16:10:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242398AbiERUKA (ORCPT ); Wed, 18 May 2022 16:10:00 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 919D120F4D7 for ; Wed, 18 May 2022 13:09:52 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id f2so4209648wrc.0 for ; Wed, 18 May 2022 13:09:52 -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=OAGkT1M5jMR9soataqZ/aDlCf+slpduEKHamzxDek+k=; b=nWSEVQAcxxJIiQkZxG8xgSo5vu5I9ZUHiImr8EADEL8kSkFbfVM8Z+pM6spbJA7xIS x2EBkxIl74cC6FLEssPgc6edf8Kk1rhUVcEReBqLBiYH601c150gPmU22b3TeXotis0S 6cJ1RtsIKomQ414rySZaGUyuVcbJcHgmi3M/ScbiW0g+tnr3uixJjSARK+khNPx0Wu20 Da19MgE010SDvuxpfHelPqh9BNATH8CsxheYNWGZyFBmqLo5hAUbGzsbTfEHHRc2xjNg InDxaIl+0rtY3n4ABjaBp9sji3I8l4Y0Fcw0mfILYcoSgry7sN6ziRIUQntFfiJ/YKmO OQrw== 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=OAGkT1M5jMR9soataqZ/aDlCf+slpduEKHamzxDek+k=; b=bRbTbKgBuKivk1ubgZmcTGiwp3Fo6OltkMuUlL4qPDG203TeqPBDKcPld98OhwKtGq Dth/cY1AhmISv9LcnBAI+O6QnzH6cVaGZR9zcGogmMM0Rl9K7KWt6T7GUbB21GS8iNv2 PoVvyxstO5a/t17Nh4nM0RilEiM/pL8idbDKkUCERJ+v5p4PaO90/XzLUeJ7ZpLQfiom oSKoaunHo4bdzhLbS9zkX2FYQG46O7RForJKt9j51nd0zAMhV07aTqRtxhYvmWTDzSgW x8Jqxk5cf9kqfrUV/EgG1YgOQe2Dsy+rm0VNWYgz0phRGk9BVPdHGW6sEi99ETs+eNOv HfCA== X-Gm-Message-State: AOAM531Mt11sX0dnqmKv/zhApBZLaY60LXhLYdjzOsiL4+zpzuNX5JjF hMtTTCqh57Ba7B6k7Euc+mB38w== X-Google-Smtp-Source: ABdhPJx7027jt1OtEzgemX8nNGTw2DPHXeDkAAtNb+diLtz+l8F2qMFU1DeU5NN/nWByXPmhBkliSw== X-Received: by 2002:a5d:4741:0:b0:20d:2a5:6b2d with SMTP id o1-20020a5d4741000000b0020d02a56b2dmr1161260wrs.100.1652904591171; Wed, 18 May 2022 13:09:51 -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 o23-20020a05600c511700b0039456c00ba7sm6859281wms.1.2022.05.18.13.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:09:50 -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 v2 4/5] dt-bindings: net: Add documentation for optional regulators Date: Wed, 18 May 2022 20:09:38 +0000 Message-Id: <20220518200939.689308-5-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com> References: <20220518200939.689308-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 entries for the new optional regulators. Signed-off-by: Corentin Labbe --- Documentation/devicetree/bindings/net/ethernet-phy.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Docu= mentation/devicetree/bindings/net/ethernet-phy.yaml index ed1415a4381f..bd59e5cc0a55 100644 --- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml @@ -153,6 +153,15 @@ properties: used. The absence of this property indicates the muxers should be configured so that the external PHY is used. =20 + regulators: + description: + List of phandle to regulators needed for the PHY + + regulator-names: + description: + List of regulator name strings sorted in the same order as the + regulators property. + resets: maxItems: 1 =20 --=20 2.35.1 From nobody Thu May 7 20:27:01 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 AEECFC433F5 for ; Wed, 18 May 2022 20:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242424AbiERUKQ (ORCPT ); Wed, 18 May 2022 16:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242417AbiERUKF (ORCPT ); Wed, 18 May 2022 16:10:05 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E567239796 for ; Wed, 18 May 2022 13:09:54 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id m2-20020a1ca302000000b003943bc63f98so1609212wme.4 for ; Wed, 18 May 2022 13:09:54 -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=gmIO/D4Ceaesv/SdaQGf7VpiPn4xB80QGFNJbqSVbYc=; b=vPcmgPS1Zkav7EL8kAY3mLgR+8wgJTaoIpwtC8pZglq1poCcoa4VPa4pSJdm98yba3 Dc9i8L8D17fg1dDV1MciA85vi0SwtvTf0cIWWa0jaWi7FlHTh81D3xxtAYUio5a7q9yo oVb1izlVGPk2k31vczCTsEvwhVj4scccR45jYEXUJzfd+kt6Y1S3y8bdLsIML35boUm4 D/00jIZVyCNxRNFcViiyr0lvuZb2bnlheBghCO/T6idKUPOe+w2viE9ZGodiSxZ6rPym 6w1tRY/kpkOqM0ShsI/anVPC7SJgVvi0Sd3tKll0sY9mdRGB6Bc1w3QjAdiKooMiMpPO ODTg== 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=gmIO/D4Ceaesv/SdaQGf7VpiPn4xB80QGFNJbqSVbYc=; b=ceLDTs8DwlONgJ+CB45dj1+TyJzhLaEuYkT3EnpgffvFHcoTegc10j3kr35scKKld8 Fopdv86aTeqSnhvI8a/T+vnr6FZJHUg8qO9t/549fARknw0DkIgp8ezUwWt0w3JVH+W5 xxGtavNPo9YE2dozXL3SaWF+DRsdRa8lgoNgYv3SE8TA2xvCf5kTDprIAhYEsJfds13b fFQFeDNGu2SXJRMF0A3kljHZDcG8E1o69+2JsLPMd6YAVV2taYph8PtDEZpBJKGID66d XnHJc7ds1T37XU1SrLFpxgFZxE3QjL3d1rTIQEyGDmfL7gD/fLqcqw0RPAh9R7O46/34 84jg== X-Gm-Message-State: AOAM531Mm7b8K0wbO4H+7VyfbNCyjgthWIAAnZmnTMUu+Y50BrbKL/Hz r4qkGeJBvdhD6YgkBaW7kbRfCA== X-Google-Smtp-Source: ABdhPJwlu63b6+jK/4XJihJY2QnEy9b9pt9pGCMB3OHShfvK84RY+TPog8SwVoHsv1ZZ3Xh7i0PkEA== X-Received: by 2002:a05:600c:1c84:b0:394:5de0:2475 with SMTP id k4-20020a05600c1c8400b003945de02475mr888627wms.27.1652904592329; Wed, 18 May 2022 13:09:52 -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 o23-20020a05600c511700b0039456c00ba7sm6859281wms.1.2022.05.18.13.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:09:51 -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 v2 5/5] arm64: dts: allwinner: orange-pi-3: Enable ethernet Date: Wed, 18 May 2022 20:09:39 +0000 Message-Id: <20220518200939.689308-6-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com> References: <20220518200939.689308-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..c3749b7302ba 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. + */ + regulators =3D <®_gmac_2v5>, <®_aldo2>; + regulator-names =3D "phy-io", "phy"; + + 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