From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795581453; b=21nGP1f/1XypyEEPFWdLBVDSz/I2gqdiznN5kHJWNxpk6+QVecQER+ZLFLymkrLzD9Xt xcv6TXYFkB8uXzV5BFexy5n4wcRceDgvlrE8LgKol88Qr5SY7Xo+yBJElAPMtjCyLOZKE kTbnEERiLpsUfN7/p+PgxzYv+AaT3vBHWLwIDd/jtDjcHzxqzxL9EW1VQzmZtmATRQnw5 8IEM1ebfmAbSU5mXzrPpGjLtAL0ZJhzxZJW7nNGOGHnpWnreCyBrSxEikZwbairLl2mJ3 gRiOpgtsGvKg59WFs5VEKiaf9irDL3umBB3I8JvwinGrpJCNttpahJeXgm6loV6e9fg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795581453; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=rkE7p4aQLSp2kYV7vRBIkJ3P+8n0i8bdfYVP4ePHIkQ=; b=cL5KcmeHqRjeE19Z+oBCpaONk+EkKvW6neS9/8sY+XebtzIEVVFPsKzxKdS1ce0CfFjf jaeiBauvfkIamSaDykqak3ggT8Y3BEB5viwgPdc2nL5Cz9Lib4l3ycjqRH2f3Z+dPSf6m JBl6DWrcnDPkkQqLgmfGW+j5LxUwqxWnbMpv/kPnI6WSWf6er0ZpedDsq0o8MYvD2dE7E kgnDRS3Tq8oSWjHLuldoqacpYTvXkljyWTzcqGkAL9TYPrPNaNTv8/WF5f3Njim3U+5DP KxVf7RhKZvdNIr96et1EuWdpmKuH0Rj5MTw+ucoSKSBjgmS6Ab2U96chVDRgEv62nOA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xTXrqdTe; arc=none smtp.remote-ip=209.85.210.181 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E175606A333 for ; Wed, 25 Nov 2026 04:37:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2E175606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xTXrqdTe Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8a0880a46e7so3183976b3a.1 for ; Tue, 24 Nov 2026 20:37:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795581452; x=1796186252; darn=vger.kernel.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=xTXrqdTe+k1Bcn1+GxFlxR2ebQqsRT1M6j+6aYNb9r7mHlRo1fwWLDw4IySXue6Dcl KBC1LPnqdZpfI/A+9xmUzotNvieDwV3SMZ4p8tIm9TdJ8zO6mwFBwH3pm3xWXrevrabk K2w07uepa6D84x7VWDXgxWsceiGrwKmT0aobivANPe75XkwyR4R4xCcK1XmFWgM9LT2m x73zYmJNUkyLBfdibwDMgg04dO2Cn7IXlVfBYXZu8tF152ii0uqWAh3Mhxg0ey3JmFg4 1fIS8fEaOY7anibxyTO+n5sgar3Ls0+2rGe3zJpPeCBNZofGyNj3rnccEVzZB4wgIeUh iCmQ== 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=1i4JwdK/LBEokKwTXcvbE6r0muadWn2ssyW9D2TS3NQiunLkFRyabbmmObKx4rAFE7 btoH8gFocYjMmvXsbnu/5a1s+AFrEzRMBX/jXYZtiTNk5kjDIFP5y8h2KI6sqnulgSx/ OG9nm7nTAurBy9xhAljB1RZSz30KoIzF3AvmMVLBwGJEzZF5lj4qn4eJJK7DMRSc9ae5 nwbvQBukO+YQ9hP1E2qKpJQ+ruxJMOwWGCfIerwgkxclG/qs/gf8nNw9uwwT0buCBauh XYfnzwU44zLkJqFwADzSiXppm/eY5E7BL+0lIBLOqGFvuWkz7+Q2x2AgBnHX3OSEmy/3 LKSA== X-Gm-Message-State: APuU4Z/aHBpEIBPmVT/6QsVGAlu+SrIdAd5xppEHugqly+zTLauzY0ia T7j0hvHA9SCHqxG2XBhPRrYPPcmhX2VFyPjYsVNJHbvBWG8kwZhQ7leO X-Gm-Gg: AZFdTZcUgbKGqJ4I/E1yw/c8E+zP97x1sNq1jwSUaV93gGtK2BXDsDBCzKs9P2QmJl+ 0cOAMlEzOAxE9WUUhTfeRupKMSunSblgYzbSouVfMWnVBAMceL5znz4kODMdzINcgLMS3xBcyg+ pTV6+8MIvaciDhEh9LlXmK6AetUSdKAFHZkOG/o2m6Bm993dBNBDBtd+wscyGIwq1ttIoPv5dLM Y+Yd+dO+8mfx6ZyRQOqjvFPHvVlLrdqB7REYeSTZ9v/8MEDN365zWyS0OhqNRqD1Sn+oqM4BgHi WHwLJoSVEUu4RGePuoH7uR3ZMTW9Z6PBj1wdOaqJb+aO3JGsl3acxzTNT8AhQVzha9vmb3j127W i/mzsSSjJEiX31Q2gktxMPdjAorsR6HdxEnjACwO540/FsK1Byi1vI/HrxX8XoMD1bgPPs13eUP dimqPIJLCuRLV4Kx7fWywlCbmPf5EyHZ4LvXS084QwFxsmijFPfgzGsWS9dgdxgxevPWnxe+pZr zcM2YlijHVWG5Zli4jNYPgpx9qYTZK35menfMwcAptpGikAlwE/HYkYQAzn2FdQr9/SWNfR0Pmo urVAhXN0ynevMIvtP1PhSSidWWRwWAAkyjAL3yUldYmyUMCw 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-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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