From patchwork Tue Nov 15 07:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 20228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2571914wru; Mon, 14 Nov 2022 23:39:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7BLDnrPmzjDTGl11Ohii/9CW5TfyBTFPZQ0GOCbt51TZ5pCZeySKQ/iDdM/ifFMVdmumna X-Received: by 2002:aa7:92ca:0:b0:56c:6bcc:cf0e with SMTP id k10-20020aa792ca000000b0056c6bcccf0emr17177807pfa.64.1668497956268; Mon, 14 Nov 2022 23:39:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668497956; cv=none; d=google.com; s=arc-20160816; b=L9jibeNaK9KRJZyGXdcwFMe5V8ivxCfX9I42jhENzdgXAd9dirLAiFIC3fXD/XRoBk DU1HaxID8CBXmdgOgeITCWc8K8aN1WMq71HwhKCn/OsnE/UmpYhSyRMhsFqPlAgy9zyn Jm0Ji9vCOsJKEqQkFwcBITqHPzE9Mzj8QA+RYnEVTRdBch31zq1+n/57SJYmAO68p1QV IBsf1s56H7kr/Qu43nodxTDFP/B33X2ZXy+n/hk7qZXxDGwPX/T4N0kDUT/RUHMtZuum VgP11pRM42ZEa2IFCdLRyCgSNv+qB9lEbXT3VQBanIn1JQUtvfiMghzozVtek+w5sHxV DBaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U/b/69ztk+aptsMOgAQxQD/dTqenV+HzjSfACGH7onc=; b=XhAwixs5TQrkDe4JdjKa1kSWxNnnzxFCKnntaqMNrAjTbsfW/jBXDKt3tnirpxcYjn z76kOoNrrfmP1m4jExyemsikFsKxYLzTxFjIz5MRyXSPuiEKJyY5BUtkHaf+BjIq59VR di31y37p/Us13PfYO9VQ5bRsMtIXILGydzYmPGP4az9f/PAgr03RcImuDQOefw5yhx4B YMTAc347xCLaQy7zvl8ffRUQuu54c5gKunhI48l3UCCgC9h9NQ/LcW9VSQe3fKn1xT+V HhIIdicoWEjs7uLZwaMspaYyoCR4z7mikN2uhy8l81jHwwcC6xzZykmYSw8jajRzophB X91w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=kfFW7nNB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020a170902d19500b00186971db5fbsi10346649plb.220.2022.11.14.23.39.02; Mon, 14 Nov 2022 23:39:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=kfFW7nNB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231966AbiKOHgY (ORCPT + 99 others); Tue, 15 Nov 2022 02:36:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232421AbiKOHgP (ORCPT ); Tue, 15 Nov 2022 02:36:15 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3797A209B9 for ; Mon, 14 Nov 2022 23:36:14 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id i186-20020a1c3bc3000000b003cfe29a5733so2598638wma.3 for ; Mon, 14 Nov 2022 23:36:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U/b/69ztk+aptsMOgAQxQD/dTqenV+HzjSfACGH7onc=; b=kfFW7nNBy9y1NH/vtLXH1qcMRSZFvJhZSTlD6RUgpoKsd4z8Xk0zZlCvMM84IDkLz5 rnkrCf/OidYwiIK4MqFgMco/ZEoxgOmpJQtCcdkyM9OsOWM7YqjFkmXaDrtQwlT3/zeM k332/Yry/hrhX6V9epzsOwGUh/xN5IArxlmtqw9wZNSJpVKE7dccUpw/C7n3WUOTRhNG XpnGjh86LPFhIhMEJsrmrspLpX48eLRGmaONxfhb6pzoCYqJAAfVM+Qrsz5Nqce57N2L POCFZHTouB6elYP25kSjPhK8lVaVmaWxYhKH9+3CWqgDQW8jn0dNCrc5Z3h4Bq4tIMAF Q+9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U/b/69ztk+aptsMOgAQxQD/dTqenV+HzjSfACGH7onc=; b=xsPzynpx1FEI71/TbeUau0veEUS2k6311QgVFRfCO3wQPggLPuQSINlS2Wrg/lWqav fxaJLSWxuzo/ODGKztESx0vRLEt6xHFQt+mKPCL0/fSYjFTs8YQHx1/UF352VqP9cFre Iw6+TmPs0UDonxlx7N5JKUy27kYJ+baqP5byBdV999TXnRiAwy+Zn7WWNGmCG8NET0lS nZbi+sTtnXHeK8RM/7zDcNwDz8OywYqhKDwd3EVekkAFM5kHDzTdLXFhO0MJ37PjWCh/ sEHYjG9Ek6W/4OqqtzffIyPBhG91inP8cGRmBnDKcMIqeh6g4JOUi0mvJI+2OIrZ9U6e 5o7g== X-Gm-Message-State: ANoB5pnMxykrYPbrnC72SGJC1NsW3zecj0FZK6zaAqy6QwskePhoh7HW izucKe1OL+6iEeP4sI0Eau8fkA== X-Received: by 2002:a05:600c:4196:b0:3c6:c05a:a50e with SMTP id p22-20020a05600c419600b003c6c05aa50emr433684wmh.81.1668497772752; Mon, 14 Nov 2022 23:36:12 -0800 (PST) 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 j13-20020a5d452d000000b0022cbf4cda62sm13836811wra.27.2022.11.14.23.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 23:36:12 -0800 (PST) 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, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH v4 1/3] regulator: Add of_regulator_bulk_get_all Date: Tue, 15 Nov 2022 07:36:01 +0000 Message-Id: <20221115073603.3425396-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221115073603.3425396-1-clabbe@baylibre.com> References: <20221115073603.3425396-1-clabbe@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749546912941615972?= X-GMAIL-MSGID: =?utf-8?q?1749546912941615972?= 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 --- drivers/regulator/of_regulator.c | 92 ++++++++++++++++++++++++++++++ include/linux/regulator/consumer.h | 8 +++ 2 files changed, 100 insertions(+) diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 0aff1c2886b5..584c92f1a317 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -701,3 +701,95 @@ struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev, return c_rdev; } + +/* + * 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 = strlen(name); + /* string need to be at minimum len(x-supply) */ + if (strs < 8) + return 0; + for (i = strs - 6; i > 0; i--) { + /* find first '-' and check if right part is supply */ + if (name[i] != '-') + continue; + if (strcmp(name + i + 1, "supply") != 0) + return 0; + return i; + } + return 0; +} + +/* + * of_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 of_regulator_bulk_get_all(struct device *dev, struct device_node *np, + struct regulator_bulk_data **consumers) +{ + int num_consumers = 0; + struct regulator *tmp; + struct property *prop; + int i, n = 0, ret; + char name[64]; + + *consumers = NULL; + + /* + * first pass: get numbers of xxx-supply + * second pass: fill consumers + */ +restart: + for_each_property_of_node(np, prop) { + i = is_supply_name(prop->name); + if (i == 0) + continue; + if (!*consumers) { + num_consumers++; + continue; + } else { + memcpy(name, prop->name, i); + name[i] = '\0'; + tmp = regulator_get(dev, name); + if (!tmp) { + ret = -EINVAL; + goto error; + } + (*consumers)[n].consumer = tmp; + n++; + continue; + } + } + if (*consumers) + return num_consumers; + if (num_consumers == 0) + return 0; + *consumers = kmalloc_array(num_consumers, + sizeof(struct regulator_bulk_data), + GFP_KERNEL); + if (!*consumers) + return -ENOMEM; + goto restart; + +error: + while (--n >= 0) + regulator_put(consumers[n]->consumer); + return ret; +} +EXPORT_SYMBOL_GPL(of_regulator_bulk_get_all); diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 628a52b8e63f..39b666b40ea6 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -244,6 +244,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 of_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); void devm_regulator_bulk_put(struct regulator_bulk_data *consumers); @@ -481,6 +483,12 @@ static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers, return 0; } +static inline int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, + struct regulator_bulk_data **consumers) +{ + return 0; +} + static inline int regulator_bulk_enable(int num_consumers, struct regulator_bulk_data *consumers) { From patchwork Tue Nov 15 07:36:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 20227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2571916wru; Mon, 14 Nov 2022 23:39:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7vGYoYdU4vVBndk5tv0rjf8h502ADSgzNM3po0p4Zf6qx39kYhu5KuInYrQY1FxiCf0dZA X-Received: by 2002:aa7:d9c8:0:b0:458:3f65:4e42 with SMTP id v8-20020aa7d9c8000000b004583f654e42mr14052042eds.39.1668497956681; Mon, 14 Nov 2022 23:39:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668497956; cv=none; d=google.com; s=arc-20160816; b=ZLYrh96onCPjWs+E+MFzdWKR1qcjvKp6SW//Xesjw7RipkU1hNhAgEWoX28lr3J10P Td7g69TVBblmeNPQms/E3vTkm2Q38e/eZC/LHEVSLDTB9AppxzVIrn1yG0Ts/q9vY12j wujPm5Ruc+hSuZk3NWKTEaaJbohTMgH+NYjQTX4N5eHyhD1B0wDBMpobRjueG0RS2LmR 5hCrNcVJ7rDqIAxhkJeIgz0SsPew6hC/G1GAy9NgXibNIVzIv47TAme3LJ60XefByUay 1bmjEBsEn4XWPzhzyvVpaGjkECC1iGtku6XX1K2rEP8GNb2mWnczAg2cILOu066QyQDB X9DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tofLe7VkhuAP8ykkOBP52ao1zn0HKFI/d0yOPPGhcQo=; b=ukv++JKwdCo0q+bNBif1wkET2cFTG/Zn9ON1/JzMOuYjIcn7+STp7irp+lFO6YES4Q RxOrX2HqaPSpSXhEIvSNZ2lXvQDvDDb6ROmp3Vw6q+7oeeNPkiqfQ9AHd366V/af/SQz zBr8CMfBzckns651MPDI8swJj8cYqWwI2qiKPfyTrpoG3ElL6c82rFZ4px+/AHe9qtTh NAeGAJfqFy10giI/UOwqEXOkUD6HNu7sJq2FfIICRbbtZ/fT3DtrwnZNc3sJp2rTH0WJ +Lv4+4Cbz5vtpY9rzwB8UZaiduVCpKDTQB4FTfEmnfcwbDq7jNO5FsuVJl6E3vmEt/Mt ZXcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=qPiL6puF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw18-20020a1709066a1200b007ae98ea45e0si11085478ejc.751.2022.11.14.23.38.53; Mon, 14 Nov 2022 23:39:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=qPiL6puF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbiKOHgb (ORCPT + 99 others); Tue, 15 Nov 2022 02:36:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232454AbiKOHgQ (ORCPT ); Tue, 15 Nov 2022 02:36:16 -0500 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 69985A193 for ; Mon, 14 Nov 2022 23:36:15 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id v1so22688837wrt.11 for ; Mon, 14 Nov 2022 23:36:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tofLe7VkhuAP8ykkOBP52ao1zn0HKFI/d0yOPPGhcQo=; b=qPiL6puFyXidlZ5GnQU+0u6EL9qAiYmCMt24RnSKcbIMSUr5Kmz8io3EDiisxn2Rvi RyK559oeh78DtbEgoT9QrR1UNYamo6xU7Fq66jqy6ADPulLvK6J4+5yy8vARriFEzId9 KD4AI4UjxSLma6Y2IKCLw4/lTppt0zGiIxCrPMV7tP7NEMQKJPpNYLkDnGDO5JctjEtX 3SCvPbQHLzTOBl2xrZlcwSjiZfrECeWbnNufsssKhB1JGrWRAUIY0DL5Moo23P97yJjp l4l7lw2H/hVJCTBdDE+NeftFAHLnDldHKR3HeLMj+SyMpmeFlNV6vP4qUfeFvhQ0cVNs o/FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tofLe7VkhuAP8ykkOBP52ao1zn0HKFI/d0yOPPGhcQo=; b=V3KmLOcFx9Ipw/O1YO+BC0SLZAmRfEt36L9zGdAVMiLikYdXcHGZbi4FGOjKvs1GBK zJDiicwkFrZYzMM91LObjVzEEJHQt6dOKPaZQgTqmSleMlppnDUYVj6NYPbZ5RF54H3j sCtg6hmkRjTFGF+Pcy4uSV4r3rqvwr6Gbfjb5mHBub/XfkTmTdxBEQz4d+dGaUPaYphj we5/WwG4dMmkysxi6CI/yiAAwDb/Pmhzl8+DuOnTWpugYtYerYY8tlYW7KndGO5dHtQB ZDsiKf53b7gZSt1RXyI+PjqpvNp2h+MoJLvGfsSuhX9tqy8gWCa/SwCBHyT7hFigq118 V62g== X-Gm-Message-State: ANoB5pkg1H9IbvbIOaqAjxq7ybR3G0G4Bjybtv8V8t5VB4OgiBbPbd96 2S9z7EZ2j6xiLwbtan9ZeNxilw== X-Received: by 2002:adf:dc91:0:b0:236:debd:bd65 with SMTP id r17-20020adfdc91000000b00236debdbd65mr9339427wrj.527.1668497773920; Mon, 14 Nov 2022 23:36:13 -0800 (PST) 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 j13-20020a5d452d000000b0022cbf4cda62sm13836811wra.27.2022.11.14.23.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 23:36:13 -0800 (PST) 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, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH v4 2/3] phy: handle optional regulator for PHY Date: Tue, 15 Nov 2022 07:36:02 +0000 Message-Id: <20221115073603.3425396-3-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221115073603.3425396-1-clabbe@baylibre.com> References: <20221115073603.3425396-1-clabbe@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749546913502341882?= X-GMAIL-MSGID: =?utf-8?q?1749546913502341882?= 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/fwnode_mdio.c | 31 ++++++++++++++++++++++++++++++- drivers/net/phy/phy_device.c | 10 ++++++++++ include/linux/phy.h | 3 +++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 689e728345ce..19a16072d4ca 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -10,6 +10,7 @@ #include #include #include +#include #include MODULE_AUTHOR("Calvin Johnson "); @@ -116,7 +117,9 @@ 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 = NULL; + struct device_node __maybe_unused *nchild = NULL; psec = fwnode_find_pse_control(child); if (IS_ERR(psec)) @@ -133,6 +136,26 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (rc >= 0) is_c45 = true; +#ifdef CONFIG_OF + for_each_child_of_node(bus->dev.of_node, nchild) { + u32 reg; + + of_property_read_u32(nchild, "reg", ®); + if (reg != addr) + continue; + reg_cnt = of_regulator_bulk_get_all(&bus->dev, nchild, &consumers); + if (reg_cnt > 0) { + rc = 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=%d\n", reg_cnt); + return reg_cnt; + } + } +#endif + if (is_c45 || fwnode_get_phy_id(child, &phy_id)) phy = get_phy_device(bus, addr, is_c45); else @@ -142,6 +165,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, goto clean_mii_ts; } + phy->regulator_cnt = reg_cnt; + phy->consumers = consumers; + if (is_acpi_node(child)) { phy->irq = bus->irq[addr]; @@ -180,6 +206,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, clean_pse: pse_control_put(psec); + 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 57849ac0384e..957e27c75eb2 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -1818,6 +1819,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); @@ -1844,6 +1848,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 9a3752c0c444..5d1311b35cc3 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -729,6 +729,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 Tue Nov 15 07:36:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 20229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2572065wru; Mon, 14 Nov 2022 23:39:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf7vpSKFIL8/Aa0rte9e2OkbHwUbTPOLE9oabrRzdtyjSi2LEpp0PObRYn0JSIYg0ZfYMQcB X-Received: by 2002:a17:90a:520d:b0:212:f4f1:96ee with SMTP id v13-20020a17090a520d00b00212f4f196eemr843033pjh.72.1668497980508; Mon, 14 Nov 2022 23:39:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668497980; cv=none; d=google.com; s=arc-20160816; b=n6OkwDsDv4yVDGT68qUB3vj9XJxw8GXfKKM/F4ccq/zJCTCy9SbEoypAVY2FRbNzW6 P8u+1EdDJOrrMYLxnBLpodmOH7+8dpi1yh2d98wN+O8vkCUX0hFhF5gSyzf7yK5lJKaJ wZVScto9t55vKGKrTtegfC0vBsuxDzuk4nUm87gnlCztS93cd4K520uO+B9FlJUCV2tw b56QpLMjGYONspG+dylmCclBngH7uBi+nUIv+yJKqfKnwrMNt2S41bGCUXvy3mOkhA9h hrqfdi2X/fuVJ80A45wvUzw6OVMs6TTcZLs1xHUOWzBW6nhwC6XRaZlwO4zaHcTHEeTU HwlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CSDVCUIFMlfZ7nF9KUJuPkMn+99GuqCPirWDXaDIqPw=; b=XImGIm8CIM5jW3Lmi99Eot2ivOLZ35u0Zo5mUm7h7M8OqtN9LbC5FUDJAosNJPtcIt MRCBOvl2AaMVpJqPTzRDtCuYhuaW95L1d3oBDpY0zmpnDZ91hxeAPWnFsRChySxqCL3U FAYeu8knapq0eMlHyGW5bu5aMDFiXstBVY60zvruoI9v/pSn1zR2RIauH9TybdclYRbw X/POGgxeOgGRNRAf21ZjK9flTOXfPk6KqieXMRsjqMIHgQRxDU4kOab15nmrJOnGOpVH VOe4PU9UexXq95EgF8zpyVdCaBdtdfYSLzsKVMavX76aiHSwQ2ey010CQEI0aEDuN6ok WAnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=lOwSFJwI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o4-20020a056a001bc400b0056ec686183fsi10368126pfw.366.2022.11.14.23.39.27; Mon, 14 Nov 2022 23:39:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=lOwSFJwI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232558AbiKOHgg (ORCPT + 99 others); Tue, 15 Nov 2022 02:36:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231704AbiKOHgS (ORCPT ); Tue, 15 Nov 2022 02:36:18 -0500 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 9E5DC18B30 for ; Mon, 14 Nov 2022 23:36:16 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id ay14-20020a05600c1e0e00b003cf6ab34b61so12462975wmb.2 for ; Mon, 14 Nov 2022 23:36:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CSDVCUIFMlfZ7nF9KUJuPkMn+99GuqCPirWDXaDIqPw=; b=lOwSFJwIzEoH9+BBlsV8ydJ8KFWxhnO/GNq6VadaMp8sZTEOlX4BPNGNaeJnzIi/Xt Hfh19SvvnzbwgS5c3uyGDzfyDi8OWtaOmeqs+zLuz2h7IW1isXGZ98sMl+Q0yMTeJK+w pMdu5rlXLrAAgP4iMPPPheHaN1JToL4kfYHgIhb+IQKUW5mVYoRgI9ZxU8h68z4QQDTT /8QHLCsHmJhvP5JTTxUbteVbS6fdRWB15waJ0AT7O9Od9p5GUjceBEFzM3UXdkR2uh8S qNXWaF+Lop2CJA8VmNfJviN4sIcaLNVoTm4BljVNj2E6yiORQRjnSm2kLQYGY92g9pzh vp7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CSDVCUIFMlfZ7nF9KUJuPkMn+99GuqCPirWDXaDIqPw=; b=tB2fXuQwz/2e5c1tFaP6TE+kkgySGWYp0pH05KNuTLKCUv3jh8ufX0ShBg2W4mdm1H SX67mhie46+31sZQYUaJpv8FzqlXQqpXuQcc2SJgwdbkg4bNQBBo4JfJ66bsSuoI5Yzd fDPfpeO5eW3ccmfIxF9ITZZwctk0Adi6b/OjFC7Okmd7TS3fAUn5jWzai41MRfw/B6Qx 10XgptpaRyRxH4mQXxZ2UEZp9zThzGxPCtCpwf6pd6hbSdtB4vvM2eEaxckk6A83ubJO CzFIGvxupA2KvuDQSqtgX6oduQpU9fmL08+NzxMKFfCVXHQlCwaPe1tmNZ89HiTONV9k TPIg== X-Gm-Message-State: ANoB5pnJ5GBEw/E6kQqJphTWPsIhVDpX3OuCiqlFL8kRetbj7jUVVhyM 1g+rKA9e8nm4j0p8PA1clnddbg== X-Received: by 2002:a1c:720f:0:b0:3cf:6f77:375 with SMTP id n15-20020a1c720f000000b003cf6f770375mr20265wmc.102.1668497775128; Mon, 14 Nov 2022 23:36:15 -0800 (PST) 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 j13-20020a5d452d000000b0022cbf4cda62sm13836811wra.27.2022.11.14.23.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 23:36:14 -0800 (PST) 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, linux-sunxi@googlegroups.com, =?utf-8?q?Ond=C5=99ej?= =?utf-8?q?_Jirman?= , Corentin Labbe Subject: [PATCH v4 3/3] arm64: dts: allwinner: orange-pi-3: Enable ethernet Date: Tue, 15 Nov 2022 07:36:03 +0000 Message-Id: <20221115073603.3425396-4-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221115073603.3425396-1-clabbe@baylibre.com> References: <20221115073603.3425396-1-clabbe@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749546938536259979?= X-GMAIL-MSGID: =?utf-8?q?1749546938536259979?= 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 6fc65e8db220..081b004f26ea 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. + */ + phy-io-supply = <®_gmac_2v5>; + ephy-supply = <®_aldo2>; + + 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 */