From patchwork Wed May 18 20:09:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12854057 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 879A4C433EF for ; Wed, 18 May 2022 20:09:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242378AbiERUJw (ORCPT ); Wed, 18 May 2022 16:09:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242355AbiERUJu (ORCPT ); Wed, 18 May 2022 16:09:50 -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 65CE020F4D7 for ; Wed, 18 May 2022 13:09:49 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id w4so4131419wrg.12 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=BbH64ETLnvpPtTQ8PjuuzKQpK2itbUUWXLybZQQlmzKQ8nq4TOk+IIWiV5IuN/rokN BLIe7AZkTcMzN9LoQVG0uOJfx4ONL/0WmI3z43gWUvz79TARSrlw+yJd8XdetDyVPqkP kz+tktbi16jw6p3qXUKTwnIUu9ywu+PXqfsKWSWJlWHku/PJ/ou8YWHSAY6/6zfSek2P 5rw5xfWZrjkT5W+X3Rw/7wYXVfly+gRwbYrljhr2Wc7Fi5m9H0jkb53dvY6aQzYsyGjJ gDxADqKFmDR0Qz9JAU3R9Bx8SxzXeIcuWFuL2lDjWRnsq9f7vU7rQ5hrLK95uXzhfM8V CswA== X-Gm-Message-State: AOAM5308jOa10LocCdnYpgNJSKBxGqf1LYW7892EbFPpsYVcIonkwKky LEs9ZxU5oiZ2knzNVOTR2d2l/Q== 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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); } +/** + * of_get_regulator_from_list - get a regulator device node based on supply 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 = of_property_match_string(np, "regulator-names", supply); + if (index >= 0) { + ret = of_parse_phandle_with_args(np, "regulators", NULL, index, ®spec); + if (ret == 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 *parent, - 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 = NULL; struct device_node *child = NULL; + char prop_name[64]; /* 64 is max size of property name */ + snprintf(prop_name, 64, "%s-supply", supply); for_each_child_of_node(parent, child) { + regnode = of_get_regulator_from_list(dev, child, supply); + if (regnode) + return regnode; regnode = of_parse_phandle(child, prop_name, 0); if (!regnode) { - regnode = of_get_child_regulator(child, prop_name); + regnode = 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 device *dev, const char *supp char prop_name[64]; /* 64 is max size of property name */ dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); + regnode = of_get_regulator_from_list(dev, dev->of_node, supply); + if (regnode) + return regnode; snprintf(prop_name, 64, "%s-supply", supply); regnode = of_parse_phandle(dev->of_node, prop_name, 0); if (!regnode) { - regnode = of_get_child_regulator(dev->of_node, prop_name); + regnode = of_get_child_regulator(dev, dev->of_node, supply); if (regnode) return regnode; From patchwork Wed May 18 20:09:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12854058 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 7AE3EC433EF for ; Wed, 18 May 2022 20:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242406AbiERUKB (ORCPT ); Wed, 18 May 2022 16:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242372AbiERUJv (ORCPT ); Wed, 18 May 2022 16:09:51 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 655E320F4D4 for ; Wed, 18 May 2022 13:09:50 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id e28so3571302wra.10 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=aWfgjTsjcidNsGjmKEAA0Aa/MN8mDG+gml1MGS+shr+ou9i3mnmU6unJUUt9wldMc6 jS0RjoXO8FLN5Lk90jl/PnPx6Rjs5nVcJHKN/x5Iv03vlYDRRePT1bVs1osZng3E7t2a O1qJXrAKtun+ec9Amc0/87YjQWjsyIF84eu0CsOMDZYOgWfSR13GSsG3nFXuPE8xpL7N n2vriiJv2rOaD3xlF4lKWkaURFs2YPFtPs2LcuV53CUkyep6kZisrHaf3yyzuNhzbNz2 eA9LLq9D7QseNx+F3W+Bh6rjqOTKseoA+eP2cljV3bp5okDDd0I9C4bJYOK6mFwVGysm WLtA== X-Gm-Message-State: AOAM532nVDastopzAoWa2RKdLCTcoeHW6KT9CogksPu2OAsr7nwa3/jL ieONDkrHoNl9lHb9u1H2jsETQw== 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 = regulator_enable(bulk->consumer); } +/** + * 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 = of_property_count_elems_of_size(np, "regulators", + sizeof(phandle)); + if (num_consumers <= 0) + return num_consumers; + + ret = of_property_count_strings(np, "regulator-names"); + if (ret != num_consumers) { + dev_err(dev, "regulators and regulator-names does not have the same size\n"); + return -EINVAL; + } + *consumers = kmalloc_array(num_consumers, sizeof(struct regulator_bulk_data), GFP_KERNEL); + if (!*consumers) + return -ENOMEM; + for (i = 0; i < num_consumers; i++) { + ret = of_property_read_string_helper(np, "regulator-names", &p, 1, i); + if (ret <= 0) + goto error; + tmp = regulator_get(dev, p); + (*consumers)[i].consumer = tmp; + } + return num_consumers; +error: + while (--i >= 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/consumer.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 *regulator, int ms); 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_consumers, struct regulator_bulk_data *consumers); int __must_check regulator_bulk_enable(int num_consumers, From patchwork Wed May 18 20:09:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12854059 X-Patchwork-Delegate: kuba@kernel.org 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 748EDC433F5 for ; Wed, 18 May 2022 20:10:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242458AbiERUKH (ORCPT ); Wed, 18 May 2022 16:10:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242392AbiERUKA (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 77F562375F1 for ; Wed, 18 May 2022 13:09:51 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id h5so3027930wrb.11 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=lxsokjSvZQlnE+5vGPgbuzA/ZRgGlrZb4KBqpP0+jcTW/hcga+v9oVBYT1daE3clLj njIacrozfRio8rGaKwGsMmNbJjT28m8zz8q2xwZ/NbiQnSo4bGdmSuM2mncbt7LCS8SY thFDhD4LdT51Yuy2XviJoh4PjdDj4ad4eRwmRSeuod4tRTAG7epfGr3+ZZ33fHWRTCVl cTpcdFkwu0jFCxPPqm++VXLp43R2Sw4MT3+oHEXeFD2rTrdVeL4uEO48iS0h8g98faV5 GzJAJGMx/gasENbH9Nk602OMIAfHK7ucKRKFJwf3b+EPGhKejc/x4uSvmb56+M231IdH rC7A== X-Gm-Message-State: AOAM530GvqCY63wF8C71al9J3JhH/s6NyqCnMXyC8Bmd+TDH3bJmfxIG n1iBeOKZW4h+5WKgn8JgcfEZDA== 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 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 = false; u32 phy_id; - int rc; + int rc, reg_cnt = 0; + struct regulator_bulk_data *consumers; + struct device_node *nchild = NULL; + u32 reg; mii_ts = 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 >= 0) is_c45 = true; + for_each_child_of_node(bus->dev.of_node, nchild) { + of_property_read_u32(nchild, "reg", ®); + if (reg != addr) + continue; + reg_cnt = regulator_bulk_get_all(&bus->dev, nchild, &consumers); + if (reg_cnt > 0) { + rc = regulator_bulk_enable(reg_cnt, consumers); + if (rc) + return rc; + } else { + dev_err(&bus->dev, "Fail to regulator_bulk_get_all err=%d\n", reg_cnt); + } + } + if (is_c45 || fwnode_get_phy_id(child, &phy_id)) phy = get_phy_device(bus, addr, is_c45); else phy = phy_device_create(bus, addr, phy_id, 0, NULL); if (IS_ERR(phy)) { unregister_mii_timestamper(mii_ts); - return PTR_ERR(phy); + rc = PTR_ERR(phy); + goto error; } + phy->regulator_cnt = reg_cnt; + phy->consumers = consumers; + if (is_acpi_node(child)) { phy->irq = bus->irq[addr]; @@ -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 = fwnode_mdiobus_phy_device_register(bus, phy, child, addr); if (rc) { unregister_mii_timestamper(mii_ts); phy_device_free(phy); - return rc; + goto error; } } @@ -145,5 +167,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (mii_ts) phy->mii_ts = 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 = true; + 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; + if (phydev->regulator_cnt > 0) { + ret = regulator_bulk_enable(phydev->regulator_cnt, phydev->consumers); + if (ret) + return ret; + } + mutex_lock(&phydev->lock); ret = __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); + int regulator_cnt; + struct regulator_bulk_data *consumers; + #if IS_ENABLED(CONFIG_MACSEC) /* MACsec management functions */ const struct macsec_ops *macsec_ops; From patchwork Wed May 18 20:09:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12854060 X-Patchwork-Delegate: kuba@kernel.org 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 29BB6C433EF for ; Wed, 18 May 2022 20:10:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242423AbiERUKJ (ORCPT ); Wed, 18 May 2022 16:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242394AbiERUKA (ORCPT ); Wed, 18 May 2022 16:10:00 -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 902A22375F7 for ; Wed, 18 May 2022 13:09:51 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id e28so3571243wra.10 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=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=l8bwE1YgCC0jbKjZw3WqC5U/4eRTdN07/dfscmOFdEr+QkLy77OMvgTqOLi++zfTV3 T8qlYCV2Wr9mP67QJVH3IMcn6qS0TxqBwNf/c1wF+OsYwJqoxLaq7Q9M3KOJ3xXJELTC tQKrljGz2U2U3Do7nduMJWAeFf0IMbZAbY8vKZ/x0GiVhwEjRImC3D3SGxtIL+rXR+QG pqxR7BtCm1/UITRCLsitUkdxn2EcTnDHTawBXg0NdNhhSdE1mi7PmAk5tOTCkP9Ot++f bks2t28SLdrf1i0EGvMyz2BsjW1CehwoX/rNO5N7GCc6+OIK0TOHOwkBdwvZIqu37gp2 vUSg== X-Gm-Message-State: AOAM531NqoB7ZYu6JJUyYJbABIYQrR3vm7IIhEeJZrmf9tT/5hs3gvXB z431fESB465TJ5K42tjcNFadSg== 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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/Documentation/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. + 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 From patchwork Wed May 18 20:09:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 12854061 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 2080BC433EF for ; Wed, 18 May 2022 20:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242412AbiERUKK (ORCPT ); Wed, 18 May 2022 16:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242418AbiERUKF (ORCPT ); Wed, 18 May 2022 16:10:05 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0228239789 for ; Wed, 18 May 2022 13:09:53 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id k126-20020a1ca184000000b003943fd07180so1605398wme.3 for ; Wed, 18 May 2022 13:09:53 -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=gfXUt5ZPivVxw5W7xYjhXZhkJJV9fBQjfKOQipvWdjKGx2JJiwwdWZ6l1pEkBYi/88 2MZT1aNePKazYeqagkeHToNFCuvHtcdvgcM+Mz9XRdb+p93BUeWLF2lSll4Iqm0RTO5L Hosl1irZkIPrbdpGb7OB1ik+WfWf5RJjoqNQx37T2NPMfmMM0QZzVxIjrA61+BCchWi2 V5vV4SEI+OZWVKQV6KQFFU+gTEKD+rHeTc/Tyy3jW7lGYxWTu1azUo9Hz9bjws2gyn24 vkrd7wBdkneUJGbH3diXP4yDIsRi2q0chJNQCi4TkPfdAZKxOW0wEbTgUVmZzVw29mYN 4Pug== X-Gm-Message-State: AOAM530KWQ7aF91wSJsFfQbGX9VdlsNfI95sMXRPchuteTl+UMTkBfGJ iYeTI8YiE8o5e9DGdLiJ2+Ve7A== 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_Jirman?= , 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: OndÅ™ej 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 = "xunlong,orangepi-3", "allwinner,sun50i-h6"; aliases { + ethernet0 = &emac; serial0 = &uart0; serial1 = &uart1; }; @@ -55,6 +56,15 @@ led-1 { }; }; + reg_gmac_2v5: gmac-2v5 { + compatible = "regulator-fixed"; + regulator-name = "gmac-2v5"; + regulator-min-microvolt = <2500000>; + regulator-max-microvolt = <2500000>; + enable-active-high; + gpio = <&pio 3 6 GPIO_ACTIVE_HIGH>; /* PD6 */ + }; + reg_vcc5v: vcc5v { /* board wide 5V supply directly from the DC jack */ compatible = "regulator-fixed"; @@ -113,6 +123,33 @@ &ehci3 { status = "okay"; }; +&emac { + pinctrl-names = "default"; + pinctrl-0 = <&ext_rgmii_pins>; + phy-mode = "rgmii-id"; + phy-handle = <&ext_rgmii_phy>; + status = "okay"; +}; + +&mdio { + ext_rgmii_phy: ethernet-phy@1 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <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 = <®_gmac_2v5>, <®_aldo2>; + regulator-names = "phy-io", "phy"; + + reset-gpios = <&pio 3 14 GPIO_ACTIVE_LOW>; /* PD14 */ + reset-assert-us = <15000>; + reset-deassert-us = <40000>; + }; +}; + &gpu { mali-supply = <®_dcdcc>; status = "okay"; @@ -211,6 +248,7 @@ reg_aldo2: aldo2 { regulator-min-microvolt = <3300000>; regulator-max-microvolt = <3300000>; regulator-name = "vcc33-audio-tv-ephy-mac"; + regulator-enable-ramp-delay = <100000>; }; /* ALDO3 is shorted to CLDO1 */