From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D02A9606A31C for ; Mon, 30 Nov 2026 06:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=XTVCSQmF; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ALhtY5Be DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=Cj7SJS22ovWqVoAONdLtsgSUP7ccYKoEdjqfmFBZwl4=; b=XTVCSQmFa0l+2I ZuBSgc98flgUgP1c+av3cYVXwJiqYfDNCGSFx5o9+JO9dg/L9NpB5NQEnQpaNKcvYLY1DSNU3P4mi DuzpqQdOVeoAldOw/d6QFtSKDRFArTFHKWs5rvvHnWXltH8sEUWkcdvT77gC715t1fJwklNP8RHHD cTEcyzBgSaWq8OwgFVW1JjqYAaJVvCBkpmHT+9J/eoyNrBbF6nZOeEjxWojNzfBfzsD1lkUBYsNb/ +F8hf9U5ZCuaMBNzTJo4WruUigraRctPQ/yqLueH2w4iU4pgvSdTJjtQ/EcGHipcFojNLmwCtS3i1 TVWOdxTJC5U21ZZ63bXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXv0Q-00000003RZi-2FlV; Mon, 30 Nov 2026 06:36:54 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXv0F-00000003RRq-3eA3 for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 06:36:46 +0000 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-3b43d30822fso5214068a91.3 for ; Sun, 29 Nov 2026 22:36:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796020603; x=1796625403; darn=lists.infradead.org; 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:content-type; bh=Cj7SJS22ovWqVoAONdLtsgSUP7ccYKoEdjqfmFBZwl4=; b=ALhtY5Be4HjTPcGCW90oeXs4wMofy6TVHIyYBH6X+kCm4Eonlc/yox4KbrDW1jBi8R i3vTuBgZYqmtyhWP4jlfmZcAVyWFQxT6jOq/LiEBx7ic76p+KZ4ua7gI7x6d/0pWiRvf VCtu1XLj+BKEV67z92dydH1qgiyDcd5LguYHfVIpn+ONTWPwlLaER3LWYWhhDJKNMyX3 9Ea1uY9TEOlxi7k+liLOh0DxmcNata27oyc4phmdHGN5mvkJeCvDFgpGxHh8I5h1AU9R w+yLiI6/C52b0xNuEkeH6LcRQNMAdTF/Dxp8+IZejEZ/BC0w77BdgO1G6Log6k80uC9/ fAZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796020603; x=1796625403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Cj7SJS22ovWqVoAONdLtsgSUP7ccYKoEdjqfmFBZwl4=; b=TPkbWozRiuS7KDidlLdOxCIy0sOjCBgDstfeHRny7obgArrndoorwD3w4IumKv6Q3S LkfGZvUkloWHFETvmFrx2KDbgEFW5wmLJTtqMLiXmU2g9TatbB6p3mbhFAHBcKz4r56o bs3jR41DqaLx2Wz12UzuI0IVfEKBPmnGNsZxxTSyEIBxIkOclJCFH6HVTU6c52xGxU2b oAPB77BThpmTdm2T8ZRV8MxUNCrq0JU2HtDZdqDNENL12264x/vg0gL38u3yw2tOsnSF EHGVJfgEBCyuVKde2suUZt8n5r3UuVuEeAo1HRvmspmmcgW5O1cOo9CQk2hc/ljZ34Hn fJQg== X-Forwarded-Encrypted: i=1; AL+hErFEvO207J3aR1ITBV4v1IgNKQ99JQzhwqro6UXddnaYiXw7z6FbNuGD1IODC4picc+UoYcnDnqa7ivyVBfrMPEm@lists.infradead.org X-Gm-Message-State: APuU4Z8lQW8gqiauCF7yHHmC239pwypbcNUtC097U9SOV1Uh4tmTJwHC CQgvZNijKUeETx2GLzZeynsk40/UdOYRuxWK4hwqClH1eztv0ZTVYfE3 X-Gm-Gg: AZFdTZf327A6Ofo8I44T2Y4y2n6qgTpjvUfOTxdtYAEIPluFUyU9/DtKBamv5fbdBrs O0SkDS4VkAa4tgc8FDyeSNwN3dPi5CSj9qJmHlwnlVrLrTKdgmLu24nrmZnZ94sFn96r5NPHT36 e+OQTnOIeTgFWEMCz7LozlNI4OQ3g3KMDbVtO8Aob2Tfs6sGi7h3mywqgzKldvssmTCsolRIFDN q/07eHkhpfOefMa3I4+EP51KqyuhzxFdGuJuzJosdS+FwaAtxwC7HSFb0k54grXRma5/jbm8sdv KVj7uf+TvbkV5PSqg8jjA7mHoLl9IBmhud+WN0K+mzhGD0soSJ9S2eY/5m7U7xXJVTOB+nMU+eF ZLM5H049czLuD8x9J7e3xxkYdTCwJVPyYK14NQRdKUJHYCHQz0nu5FCzo4UBtL/0jSMfTUDF8pR 0vcFDf9LRo1YbLKUFCCQN2fNiyTU+TFnIauQ+TKGpuosW2wQU0m/zuEg+OAetQTzLDNSbSqmeGW vR134PMKGpROjHnI5GJeNuFyV3GvfNqfXOIWLrRdCOC81GlFOv8RR6n9dvWQHzJtPdlkB3RvsZ1 KNEU3qgWzEEj/521gUXaZbBJnlc= X-Received: by 2002:a17:90b:39a7:b0:3b3:bb55:d9c with SMTP id 98e67ed59e1d1-3b41c7b5dfamr31954328a91.2.1796020602889; Sun, 29 Nov 2026 22:36:42 -0800 (PST) Received: from localhost ([2001:19f0:8000:4ce8:5400:7ff:fe0e:e6b2]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41ad0b2c4sm50851254a91.4.2026.11.29.22.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 22:36:42 -0800 (PST) From: Inochi Amaoto To: Andy Shevchenko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Damien Le Moal , Niklas Cassel , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Aksh Garg , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Vinod Koul , Neil Armstrong , Vladimir Oltean , Rhys Tumelty , Inochi Amaoto , Qiang Yu , Manikandan K Pillai , "vladimir.oltean@nxp.com" , Hans Zhang <18255117159@163.com>, Yao Zi Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-phy@lists.infradead.org, Yixun Lan , Longbin Li Subject: [PATCH v6 4/8] phy: core: Add phy bulk data helper functions Date: Mon, 30 Nov 2026 14:36:03 +0800 Message-ID: <20261130063607.294823-5-inochiama@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261130063607.294823-1-inochiama@gmail.com> References: <20261130063607.294823-1-inochiama@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261129_223645_107644_15165F88 X-CRM114-Status: GOOD ( 20.38 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Add several helper functions that allow drivers to operate the many PHYs in one operation. This can relieve the driver owners' life who needs to handle many phys, as well as each phy error handling. Signed-off-by: Inochi Amaoto --- drivers/phy/phy-core.c | 120 ++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 38 +++++++++++++ 2 files changed, 158 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 5004d28b167a..6991e5359afb 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1100,6 +1100,126 @@ struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node *np) } EXPORT_SYMBOL_GPL(devm_phy_get_by_of_node); +/** + * phy_bulk_init() - initialize multiple PHYs + * @num_phys: number of entries in the phys array + * @phys: array of struct phy_bulk_data to initialize + * + * Initializes the PHYs in array order. If an initialization fails, all PHYs + * initialized by this call are exited in reverse order. + * + * Return: %0 if successful, a negative error code otherwise + */ +int phy_bulk_init(int num_phys, struct phy_bulk_data *phys) +{ + int ret, i; + + for (i = 0; i < num_phys; i++) { + ret = phy_init(phys[i].phy); + if (ret) + goto err; + } + + return 0; + +err: + while (i--) + phy_exit(phys[i].phy); + + return ret; +} +EXPORT_SYMBOL_GPL(phy_bulk_init); + +/** + * phy_bulk_exit() - exit multiple PHYs + * @num_phys: number of entries in the phys array + * @phys: array of struct phy_bulk_data to exit + * + * Exits the PHYs in reverse array order. If error occurs, all exited + * phys are inited again. + * + * Return: %0 if successful, or negative error code if one fails. + */ +int phy_bulk_exit(int num_phys, struct phy_bulk_data *phys) +{ + int ret, i; + + for (i = num_phys - 1; i >= 0; i--) { + ret = phy_exit(phys[i].phy); + if (ret) + goto err; + } + + return 0; + +err: + while (++i < num_phys) + phy_init(phys[i].phy); + + return ret; +} +EXPORT_SYMBOL_GPL(phy_bulk_exit); + +/** + * phy_bulk_power_on() - power on multiple PHYs + * @num_phys: number of entries in the phys array + * @phys: array of struct phy_bulk_data to power on + * + * Powers on the PHYs in array order. If a power-on operation fails, all PHYs + * powered on by this call are powered off in reverse order. + * + * Return: %0 if successful, or negative error code if one fails. + */ +int phy_bulk_power_on(int num_phys, struct phy_bulk_data *phys) +{ + int ret, i; + + for (i = 0; i < num_phys; i++) { + ret = phy_power_on(phys[i].phy); + if (ret) + goto err; + } + + return 0; + +err: + while (i--) + phy_power_off(phys[i].phy); + + return ret; +} +EXPORT_SYMBOL_GPL(phy_bulk_power_on); + +/** + * phy_bulk_power_off() - power off multiple PHYs + * @num_phys: number of entries in the phys array + * @phys: array of struct phy_bulk_data to power off + * + * Power off the PHYs in reverse order. If a powers off fails, already + * power-off phys are powered on again. + * + * Return: %0 if successful, the first negative error code otherwise + */ +int phy_bulk_power_off(int num_phys, struct phy_bulk_data *phys) +{ + int ret, i; + + for (i = num_phys - 1; i >= 0; i--) { + ret = phy_power_off(phys[i].phy); + if (ret) + goto err; + } + + return 0; + +err: + while (++i < num_phys) + phy_power_on(phys[i].phy); + + return ret; +} +EXPORT_SYMBOL_GPL(phy_bulk_power_off); + /** * phy_create() - create a new phy * @dev: device that is creating the new phy diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index c480d6cb42c5..c170d9aeeeb4 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -83,6 +83,18 @@ union phy_configure_opts { struct phy_configure_opts_hdmi hdmi; }; +/** + * struct phy_bulk_data - Data used for bulk phy operations. + * + * @id: phy consumer ID + */ +struct phy_bulk_data { + const char *id; + + /* private: Internal use */ + struct phy *phy; +}; + /** * struct phy_ops - set of function pointers for performing phy operations * @init: operation to be performed for initializing phy @@ -313,6 +325,12 @@ void devm_of_phy_provider_unregister(struct device *dev, struct phy_provider *phy_provider); int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id); void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id); + +int phy_bulk_init(int num_phys, struct phy_bulk_data *phys); +int phy_bulk_exit(int num_phys, struct phy_bulk_data *phys); +int phy_bulk_power_on(int num_phys, struct phy_bulk_data *phys); +int phy_bulk_power_off(int num_phys, struct phy_bulk_data *phys); + #else static inline int phy_pm_runtime_get(struct phy *phy) { @@ -584,6 +602,26 @@ phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id) } static inline void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id) { } + +static inline int phy_bulk_init(int num_phys, struct phy_bulk_data *phys) +{ + return 0; +} + +static inline int phy_bulk_exit(int num_phys, struct phy_bulk_data *phys) +{ + return 0; +} + +static inline int phy_bulk_power_on(int num_phys, struct phy_bulk_data *phys) +{ + return 0; +} + +static inline int phy_bulk_power_off(int num_phys, struct phy_bulk_data *phys) +{ + return 0; +} #endif #endif /* __DRIVERS_PHY_H */ -- 2.56.1