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 5336C606A321 for ; Wed, 25 Nov 2026 04:37:52 +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=HHL0Yer5; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=rhrjmgRs; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aKXhvxJt DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=RvrluitlqtrCUAfk+K/wfkOZCNs1yZTypvvXjHqnbTQ=; b=HHL0Yer5MV9OmGMak0oR/NfyLy jAOkCoLqQrd2/TgF+LeP//w1SrMeI7xzOL5xlxT0nuqj7LWkKH7K2Y9ME6o0yPz+UbHKHJiIOh0Ov DFFfLswscAVMlray+C0jMIuuSwJvn4/WLEa49GT5GPdXYgCXgCKfK/fiKMgn2EbVPuttpjqqpxrW+ VeZ9x19wlWpRnebXx3rZ0whlc0Ady2/yszUko5Jl2mkFz885krB2p/WtKfwR/caSFfu8KVtEn79FC 9xYMIKSCGzaYJwwQ9NhH0MhdpDfCfM71G3+vqIQuWME33jdW5wX5+WJkx24DsdxL4KyLlUy+ZD8yV 3ZjeBksg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xW4lU-00000008Oyh-0DQu; Wed, 25 Nov 2026 04:37:52 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xW4lG-00000008Op3-03Lg for linux-phy@bombadil.infradead.org; Wed, 25 Nov 2026 04:37:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=rkE7p4aQLSp2kYV7vRBIkJ3P+8n0i8bdfYVP4ePHIkQ=; b=rhrjmgRsVzBAKBrSZ3RwvFd49l 3fWhlnfzBstp/jc/nmc3JTKLDAOADLKhcJRuBSYMERrjSUmmBKGxVO12CJ492cXeZNXPtxvOfV6xn ErBQ5zowDdMib/HOw9BsrscLaH8tjlTZ/sxUHSsaUl346qiMHgAbiBDM1Y/v/r2mBckrrwFReKAyN 4noN5j4yVP3xAwMTUhIoariNcaSJg1neFXg0sIzifwQ36Mzs/V1THgRW5bNheatlSoblghdv7VppI dVW7diILDGBw8nAczF0duHVVEoykg16XkPixEXRUju2O/vXBIZ6H9YUUBk0guu40nxeCvRY7w6Ro4 GaDYm/8Q==; Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by desiato.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xW4lD-00000004pvD-0lZm for linux-phy@lists.infradead.org; Wed, 25 Nov 2026 04:37:36 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-8a0880a46e7so3183962b3a.1 for ; Tue, 24 Nov 2026 20:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795581452; x=1796186252; 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=rkE7p4aQLSp2kYV7vRBIkJ3P+8n0i8bdfYVP4ePHIkQ=; b=aKXhvxJtX7N7I8kvn/b2Nhwrqg7Vf+QB7NgGZMMB2WF+8hi9/dmqs+pHm3M8dUcDL5 P9zawTA6oHRShW1T4fyw8E1yoDtRhUdDviKnjeD2zK/Yr7y5UkFLpmln2CV19ZRMFmSl B2IAUr/DtK6a+XXXJmNGwDOh1Z9Ij0C/Wfu2ad3s7pCIzmSlKc8dofBWtD7t2EBhIKY4 YrX/X0s/8JIW5RL8t5je5LlQ+3YLc0jQh9ddVng+aIKI9zSp8wrklqzrCSpT8PEJ19no bnDln8T7tQ2RcfSje7e7G7fpn4YhJB6+UPga+GECvsAYleNOlruJQzHQxgtpRvLUTuGC 7BXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795581452; x=1796186252; 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=rkE7p4aQLSp2kYV7vRBIkJ3P+8n0i8bdfYVP4ePHIkQ=; b=LWq5tp8UzBV70vjka8+lQcH8Op/B/nLXJnG1EpmMzSFrOm81E1rJI8RLlXK/UDqObh hsBrZH+pa/6Jdx/EJws3m+ojwuJtsVgqHagMSiL2pOD/PFMo0zrrPmYYSbV1uVIXRau/ l82ljJhM/67lF2PpdY0pgO1baHHBmI+wq2Ul+BAKSuzuOdYp/WS66jEW5via36DKbR3C KzCp29cHrseiBIXJpAs1zLQtjysDFMj60O4gB286rYnsy89EliR7UaRxWp7ovFi76w7f b5I6x3NEfi6tNml5n3VF5UZ6U8PH43nAyH2c+qWVHSrMn0K6eAAwNd6rsk4s3d44QQxE dHkw== X-Forwarded-Encrypted: i=1; AL+hErHgf/ilerRdBKqdzCXGTcouYKDHZhjEIFLlao4Xjf8BcLzH08oQy4wjE37LpajL043YO20DcP2ReUc=@lists.infradead.org X-Gm-Message-State: APuU4Z8qhza4qHSXgFjm/gxGq7+cMtnF5OxR/rq7DTeF4jA4aiLMgiz+ 3U+PytB/sYORfBfwWpPbbRVZEEhdwlxzq0aFLRxOsBUG4glM0fCUdnay X-Gm-Gg: AZFdTZe1bRLX+aMmk5mvglVCgim+UoFpOgU5GmeZresFy67yHMleU4ptr2rNpcFPAci ZZy45kcwd4/kynPwSZo2Z1zRdqlkMMWwiWTY9G5Ck2PczWWvWjWqnmturAwSgBrZZ26wPo9SH5Q VYZyGJyFRgoQM9llcRELbRxf60AMCqoeBNIuwOiYak3UwpvQotNQ5YaAYZZkrtw3NGSRmlTEhos aYrXRfMdybzK2L3jwnBGuF6j95jLriVJBf5DYd9Py1Kcq6v7jFt+7LaZrN/9iVmMzWU9M1Hpr21 GNrYmnA/k+8D0vgekhre5jpd7huSKlNQP0RvWsMyNMKmxisHI5jxfBgpPIM30sVS2dOhM4WHnuA h/hEtrlqfp6UW//tZFuYES3v6apZeJ432YSVoI5lLmH592NzLr1RjN5r+sv9MkQnVWdx0hZHkCi yeQMp/ck9ARo9k17agjQM/AkmQSOW06Tr/Db0j5aAZcvS899UJ4lpfgQEzwyIHpcCaXyWqU3W/D u2CU16mS4TBcRx6RLA57wtbseDfAbMSEmncyZxnJPsNvLZxF52Dlw8nmu5UGKwkZq4gM/iYeNR1 uaRz54KAvtdRa5kmqtb24xjIZjihTYwo5V8yA7LLSsqV3tZB X-Received: by 2002:a05:6a00:4107:b0:89f:ed19:f0ba with SMTP id d2e1a72fcca58-8c7dd9d67bbmr11654419b3a.23.1795581452525; Tue, 24 Nov 2026 20:37:32 -0800 (PST) Received: from localhost ([2001:19f0:8000:4ce8:5400:7ff:fe0e:e6b2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c873c1e2f3sm7882825b3a.54.2026.11.24.20.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 20:37:32 -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 , Inochi Amaoto , Rhys Tumelty , Manikandan K Pillai , "vladimir.oltean@nxp.com" , Qiang Yu , 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 v5 5/8] phy: core: Add managed phy bulk data helper functions Date: Wed, 25 Nov 2026 12:36:36 +0800 Message-ID: <20261125043639.249525-6-inochiama@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125043639.249525-1-inochiama@gmail.com> References: <20261125043639.249525-1-inochiama@gmail.com> X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261125_043735_359696_D3075D16 X-CRM114-Status: GOOD ( 18.55 ) X-Spam-Score: -0.2 (/) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-phy" X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,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 device managed variants of the phy bulk helper functions. So the driver can benefit from automatically managed phy handles. Signed-off-by: Inochi Amaoto --- drivers/phy/phy-core.c | 139 ++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 31 +++++++++ 2 files changed, 170 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 87a317a144b4..eeba1b899c20 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1281,6 +1281,145 @@ static void phy_bulk_put_all(struct device *dev, int num_phys, kfree(phys); } +struct phy_bulk_devres { + struct phy_bulk_data *phys; + int num_phys; +}; + +static void devm_phy_bulk_release(struct device *dev, void *res) +{ + struct phy_bulk_devres *devres = res; + + phy_bulk_put(dev, devres->num_phys, devres->phys); +} + +/** + * devm_phy_bulk_get() - managed lookup of multiple PHYs + * @dev: device that requests the PHYs + * @num_phys: number of entries in the phys array + * @phys: array of struct phy_bulk_data with PHY names set + * + * Gets the PHYs using phy_bulk_get() and associates the references with + * @dev. The references are automatically released on driver detach. + * + * Return: %0 if successful, a negative error code otherwise + */ +int devm_phy_bulk_get(struct device *dev, int num_phys, + struct phy_bulk_data *phys) +{ + struct phy_bulk_devres *devres; + int ret; + + devres = devres_alloc(devm_phy_bulk_release, sizeof(*devres), + GFP_KERNEL); + if (!devres) + return -ENOMEM; + + ret = phy_bulk_get(dev, num_phys, phys); + if (ret) { + devres_free(devres); + return ret; + } + + devres->phys = phys; + devres->num_phys = num_phys; + devres_add(dev, devres); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_phy_bulk_get); + +static int devm_phy_bulk_match(struct device *dev, void *res, void *match_data) +{ + struct phy_bulk_devres *devres = res; + + return devres->phys == match_data; +} + +static void devm_phy_bulk_release_all(struct device *dev, void *res) +{ + struct phy_bulk_devres *devres = res; + + phy_bulk_put_all(dev, devres->num_phys, devres->phys); +} + +/** + * devm_phy_bulk_get_all() - managed lookup of all PHYs requested by a device + * @dev: device that requests the PHYs + * @phys: pointer to store the allocated array of struct phy_bulk_data + * + * The function calls devm_of_phy_bulk_get_all() directly, but sets the + * @np parameter to dev_of_node(dev). + * + * Return: the number of PHYs on success, %0 if no PHYs are found, or a + * negative error code otherwise + */ +int devm_phy_bulk_get_all(struct device *dev, struct phy_bulk_data **phys) +{ + return devm_of_phy_bulk_get_all(dev, dev_of_node(dev), phys); +} +EXPORT_SYMBOL_GPL(devm_phy_bulk_get_all); + +/** + * devm_of_phy_bulk_get_all() - managed lookup of all PHYs from a device node + * @dev: device that requests the PHYs + * @np: device node containing the PHY references + * @phys: pointer to store the allocated array of struct phy_bulk_data + * + * Gets all PHYs from the specified device node, associates the allocated array + * and PHY references with @dev, and creates a device link for each PHY. They + * are automatically released on driver detach. + * + * Return: the number of PHYs on success, %0 if no PHYs are found, or a + * negative error code otherwise + */ +int devm_of_phy_bulk_get_all(struct device *dev, struct device_node *np, + struct phy_bulk_data **phys) +{ + struct phy_bulk_devres *devres; + int ret; + + devres = devres_alloc(devm_phy_bulk_release_all, sizeof(*devres), + GFP_KERNEL); + if (!devres) + return -ENOMEM; + + ret = of_phy_bulk_get_all(np, &devres->phys); + if (ret > 0) { + for (int i = 0; i < ret; i++) + phy_add_device_link(dev, devres->phys[i].phy); + *phys = devres->phys; + devres->num_phys = ret; + devres_add(dev, devres); + } else { + devres_free(devres); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_of_phy_bulk_get_all); + +/** + * devm_phy_bulk_put_all() - release the multiple PHY + * @dev: device that wants to release this phy + * @phy: the phy bulk data returned by devm_phy_bulk_get_all() + * + * destroys the devres associated with this phy bulk data and invokes + * phy_bulk_put to release the phy. + */ +void devm_phy_bulk_put_all(struct device *dev, struct phy_bulk_data *phy) +{ + int r; + + if (!phy) + return; + + r = devres_release(dev, devm_phy_bulk_release_all, + devm_phy_bulk_match, phy); + dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); +} +EXPORT_SYMBOL_GPL(devm_phy_bulk_put_all); + /** * phy_bulk_init() - initialize multiple PHYs * @num_phys: number of entries in the phys array diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index c170d9aeeeb4..a51b3c283efd 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -326,6 +326,13 @@ void devm_of_phy_provider_unregister(struct device *dev, 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 devm_phy_bulk_get(struct device *dev, int num_phys, + struct phy_bulk_data *phys); +int devm_phy_bulk_get_all(struct device *dev, struct phy_bulk_data **phys); +int devm_of_phy_bulk_get_all(struct device *dev, struct device_node *np, + struct phy_bulk_data **phys); +void devm_phy_bulk_put_all(struct device *dev, struct phy_bulk_data *phy); + 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); @@ -603,6 +610,30 @@ 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 devm_phy_bulk_get(struct device *dev, int num_phys, + struct phy_bulk_data *phys) +{ + return -EOPNOTSUPP; +} + +static inline int devm_of_phy_bulk_get_all(struct device *dev, + struct device_node *np, + struct phy_bulk_data **phys) +{ + return 0; +} + +static inline int devm_phy_bulk_get_all(struct device *dev, + struct phy_bulk_data **phys) +{ + return 0; +} + +static inline void devm_phy_bulk_put_all(struct device *dev, + struct phy_bulk_data *phy) +{ +} + static inline int phy_bulk_init(int num_phys, struct phy_bulk_data *phys) { return 0; -- 2.56.1 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy