From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796020603; b=i0/8x3RPVCSO8fFpOXSd9DSPaUbnP6OeamMucmxtqcJlFgzOZImvLi3/L4qmFe/nEJcA o4oUMmzkEEEHK7d/nB+lqVqH+MX8jsknc5Jd8+/Bcuy+wWWD2w2KIG3sk3XJaRML29CjI cZwi2dSZkUkfTgDp1LKtCDjUAJ1QyELRHy2kjN3d7AGBtNhbHeIHpz1ne+G42+x2SkTKq dcna0ni8aAryQ6Ky7+fseLtpGFJT6YL99xUJJ4sqjYktmsq1U2IejnWwchDjtDr6Y5z/F jJcmSj0xIQhqaF1ZedgGzNmF2f9U1rrrq6oXMA+HSFNqRfDqxrOV8me7UXoYj2ThxIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020603; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=Cj7SJS22ovWqVoAONdLtsgSUP7ccYKoEdjqfmFBZwl4=; b=XcmlXuuWL1d9QCjAdfJ5+clR6t/M6O8N8rmcJm02QA5md1UuVH1ouSjGnm/apQtrSpfe LpsL+yNvzUq08wYvTUeM1BnmdDw9T6Uska84i1i3RG9P8mVxtgOA9MmpDUsAm5Ycgnhe9 zXdSr4Z4/uEQrW31cT9Vndth2mdZOfXBjFOLe3ztEOtFa8VkSdAm/f3qkGLUhZdZ/39Nt xxyhhOHct6c91wuc6Inj+ObHhLx/X9Rawg6sdBH0fgQ6sIfOcS4QJU56VftCZcuRk+kZL wYSt0D7v2ZBC/i6laprvadX2DNHq9cTEsEAvUcXmBpxnbrI/sfmPuq70FzP9xARiUGw== 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="NOuv/A5R"; arc=none smtp.remote-ip=209.85.216.43 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 84D29606A32D for ; Mon, 30 Nov 2026 06:36:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 84D29606A32D 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=NOuv/A5R Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3ae1da332bcso4877599a91.2 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=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=Cj7SJS22ovWqVoAONdLtsgSUP7ccYKoEdjqfmFBZwl4=; b=NOuv/A5RaXb8ql+XxgoZ1jewzOJNQM9tDQhm4GsvhTlW/ubMet54kxrP9Q94GHs4Rs g4VwbjceN8sc2yi510pVbuUF0tSymd0+PXkSktAHtz0QxU/FKtc7ETDSi0r7YKMn4/yI V3OEWQlz0AQdYygj8TaJag3Atpse6YGTG0jIvGAX46nIu0J7hK/+elphq3t85b0kHYFy c9hCxfQU7etCoAF+EtTGaEYDZF7Jy40BsMCNqBfzsTKqIwEhoM0dgS+427AfAOCKn3vI 6bbnSDjRiaRmGKTV9vufGi2Wbod+Fc6rzY0tYF+3NQnJ69fm7IGr8IzQy+LsFMsGbVRs CwQQ== 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=UBVVwjzRzvVCVZor0/yYC20CXU3KjXTnKXY/+oC4AlILzweRDoXKDLVmbBe/GclyS2 YK0df0YRV2ZdpuH5cOW6eMFZsDZJrDlUZGnGcgZXNb89RUBx0+Y91MrV5JRSQdRfjj7y cCb5RpY018XDtrIpEUt/FAiCQpgVmGHfUC2kkPHZoNVL5cdzAumNW+B2WrOeW4JeKMv9 kuuEnlCpdrUzVNMboQkSQbJb1a+YBtrp8bRbmIVJ1sIoKYwCkQ81md+l8M5RhBeLElSj lIZXDtkq9OwVCMMvKgPzw5lzXv/ssQZJZMxc760EE1ExvCCnr5/i+6iNBk0amUMDOI7d JuCQ== X-Forwarded-Encrypted: i=1; AL+hErHX880cjCQ44rqqcSrx6diPg4o3qtbB2w9zyLdmDYVnjj/kPrx4DvtcfNf34NFFuQE9VTPkpKcHJd0=@vger.kernel.org X-Gm-Message-State: APuU4Z872w297J9fU8brJxpChlOpJKi+RSFsYre4IHw3oE83ts8DGhYf TbPQFioNMbEGVjwdZ4toCD/ZhfUfDYpWhlratiLmN6zxKrIeDsypBwCv X-Gm-Gg: AZFdTZcB4+8dCebEo9d96CcV4fgCzMGFYzG0yfkr6KrjAlT+A0+Ac2djXsdqig4B85W qju5Zb0SY2yhKwmnR0j21na2nc9/ZMF25fIEBEYqDZy7BYvpbfMcgwdwL2EuNGruJ3O1ijOG0hh sY8uDlsp+VCd+lVBbi1aLsg/8YM6AbNFJf4ONrUWjSWerROocNYLn0U0/WZ+9DjmicLnY2pQ846 2LYjGla9booHOrqcqDKUlpRLnXLyhkbo1WALEjt8aJvG4ks4jNlpVKY33wsyIrgDDn8c9zCBBm3 3jDpkaJa3L38qsA4aUPx1RwOWIOsdsKnu7XbklW9pqMjJ1/Gq/a8n6s/XNFR54OKD6n/RUplo57 NXZ4/p4Nd6m6gjRDFBeiaEZ0x5MXeaatei8MsB6DiyW80V4WrO4Fg695cnHIghma1sYZJx1HUaY UdpijrobFZ6rbP1nYZezdOWlcaaiiAnS9YtCn/TMkRHGT74G3M4YLzeEVxcWi1isQpEc4WRSelK 1PiTf/UwXmZxH3CCiNDRQWC6cLquFw8Y9YSjMnxYanPmKoJ61zJnGZQBUQZyZ59OfLQ2AP+uQW9 VN1DqmIe3lXXmSdDCSGlXHuDMuM= 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-Mailing-List: linux-ide@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 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