From nobody Fri Sep 25 02:12:38 2026 Received: from mail-ed2-f12.google.com (mail-ed2-f12.google.com [74.125.228.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DBD12F83B5 for ; Thu, 17 Sep 2026 15:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658726; cv=none; b=VY9pr8n0J/HPL/KqhBQk9ENA5vD25tHanHl2fLrF8GIqLiGvkSqOsIWziXCfm06XJjVBr4G3OBx/mDfVsI42fkE3MZ7Kg/f5v1DcODCRoqU4jzXn3cgt3ocasHiAZVHs671Lp1h7WYMkGVW6PnjykcYPA5HnFsskZWcuK2fbL7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658726; c=relaxed/simple; bh=d98IC8bz/qzZqOoRgoY7KC00p4aOgRN119tjHNyLlDk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V5R+kBU0b7jsHS72AV6spwUHPLJ+qOu7Z5WqfPXM/8wVAYhgiTKySmJ0xk66lbk6rjGeAFjxewdsfzKqVQrQJ9XzMy/tMMTMkt8VFBp4hbfzq19IiDxVvqCFUTe5reiBLMXORwuSGFezqF3KggMGz5KjS5Hig/+ALax2b7WX5n8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=oInOTxn/; arc=none smtp.client-ip=74.125.228.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oInOTxn/" Received: by mail-ed2-f12.google.com with SMTP id 4fb4d7f45d1cf-6a6056ac81fso1705479a12.2 for ; Thu, 17 Sep 2026 08:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789658713; x=1790263513; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AEJ+zdV5VeKxtZ9NMskLi/eRs52AJWTItT2AzvXaS5s=; b=oInOTxn/v3C0SgDWu1FKge1t9tS00IKSMv5N+ywDSPxPDrdmLWuNSK8kEFZN4JivfM GKIMmn3dOTCqMx8YZFapXJnjQuvpVThdgeJ4hKO75UOhIlHywGeJwaflu54mCW+wnuvv URxLN8oqyR1u9Ouf5j388VY3hp3YxNGgVlntPG5eqd5eLA1Rg7cAWfwCE4VyNJPiYvCH oHoQBTZGw9PNBIx2nZTnrnjKEeDrAiU9tbEQ9INkqdcQaxbI0uVTlVQlMoQhoqIKLFo7 11+FtYHRAFpIcb5nN4k8JJlFHrPudJkcMQOPROPqoFtRk6L2xvXToiSj2z2u8NA9Br3+ jG+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789658713; x=1790263513; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AEJ+zdV5VeKxtZ9NMskLi/eRs52AJWTItT2AzvXaS5s=; b=YuqSl12/xs5OvqgOJAAzNSq76zzuMCB8qgfBo59gZBugeuKz2aLy4zbd2/2JrLdffY 0CQ5Awk+Coy6m+eXtf10Gp80991DeX42xfrB/d00+U48hhzd5VzI8R9MrV4SCdKUduDb 4DZ1qJabdonojMnTvnZownG66wz9l5b3PYSqr+aj0V78sh1V2H8usQre3OyCF+cfsajl Vacr6xXDlvppCTTw62UFl7n2sUAGCEvcYbTpm2Q3kaGfJ71QvbSWmeuQrvN/Rm6piJxJ 12u/vz/jkdiksorvILUG7rlSdL4WrKMkwYUlegsnDtd9PPv0GUHH8vyXuzaG3MLHbHOn FTwQ== X-Forwarded-Encrypted: i=1; AKwUvBy1ngX7REMkMXxdAjwzbGF1F9FVhHRiHLQYteJKpGhBUJwOh1KzyRnQKyvSSmRvinVK5YJpaYvXHbKLVYw=@vger.kernel.org X-Gm-Message-State: AFuF++nLj/0EhG3Sc8PHM1sze77OCqx5HFOfKSu/+0Ll2UYCTLlkMAbG 3MsWECkCHrXX0qPsFWc+VWK0s1MoJFIzDia7HBFI/2I9bMXoL7ceovRvloZirQosEUI= X-Gm-Gg: AYBFou0Ol5MSsckA+lRZ6R/JWlwuvzjR1YN7JHDC5h/jS545C/leinLRIvO1MthnzYf I0CvxflEr/qlSZMzrg+2YbAxYY0X3HVe1sENJYtn1JpVeJZ06Xip2xyGeV6x+auik7ltIzQxTmh 4NLfpuVgLrzw5QerFnwWDSF5a9EgIXHAQP360BunpE/U5QGSDgDap0/Cai7FFrpLXypVoSU9CXn kgsIzBUMciQnbOUCSkcG2xGNRNmD1Vl+x/xLz7iFPi96GTy5jhSR+VPG3taBg/TJSU+z1sBbQtf QtKE7irQ4SrVYD0o+djTUlPkZPygo94GeoFoMttn8e7HTO5OxFO0fACGR3OEEC0mgRiA6GsPf7/ aDvgdYAZY5pYvWvinrNLEgcGCSAZquIeXig4ShecJPahoMYIIE2c/NllY3XNjRf7hrDK2fmpyJX mfChh4ZIO/auAXUw+M5oksBsXdrSn9LW7TOZfTToitaezvSqa5d96mixdEEYWmWW2FEw9GJulCe nXMQJGgLmA= X-Received: by 2002:a17:907:1c1f:b0:c26:2fc8:4e91 with SMTP id a640c23a62f3a-c29e5392cccmr517140166b.29.1789658713014; Thu, 17 Sep 2026 08:25:13 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c29de48755asm310587366b.24.2026.09.17.08.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 08:25:12 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 16:25:06 +0100 Subject: [PATCH v19 1/5] phy: core: Fix race-condition between _of_phy_get() and try_module_get() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-1-21ad8a76e941@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> To: Bjorn Andersson , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robert Foss , Todor Tomov , Mauro Carvalho Chehab , Konrad Dybcio , Vladimir Zapolskiy , Bryan O'Donoghue , Loic Poulain , Vinod Koul , Neil Armstrong , Greg Kroah-Hartman , Kishon Vijay Abraham I , Felipe Balbi , Manivannan Sadhasivam Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-phy@lists.infradead.org, Bryan O'Donoghue , Krzysztof Kozlowski , stable@vger.kernel.org, Manivannan Sadhasivam X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5374; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=d98IC8bz/qzZqOoRgoY7KC00p4aOgRN119tjHNyLlDk=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqrAZUcpays4h8JXL+XeOMyUq3TXK/VODBXi/Xc 5Ne9QjokSSJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqwGVAAKCRAicTuzoY3I OlpSEADC8Wf4hzNm01U+HNiK6W2iuoPHg+0s+ljuihZMu/yjAaIQCJ8cUfdyo2ANBUc6VYwDrZ6 d3SZ+56IGDtrjeCJmMWvaPBdwDxK1Y0Kn4u3O/5t5nKnCcKfGSzG6BtrPyd0SvSv0WBanOfuACU SHRjN5bWDTH07xwACU7X2RcImVCizg8aNUOCeEzU/r3zx/mRy3/pAH5uu46LOu3dsNOohbrr36w FMSssMA99++wsIHp5ueR+sR4+5C51bxhCoc0DaLGjIyghjxbyXhDyFj5mlnwMcuF91JyMVc74Xs uT1g7jAaSyUt5vNvEMvv5jkLR1VeEk4fE/5H8uoqokLaJ11hMyXP8oYANSNz6CvtmFvd6n305kI yyy3ADm3h3hA1Q8qEgp7kkHRwMysnpN+iz3bA47AAPoj8wD/xC4iNKZCCb4xjwoOMHTrLDzKwW1 yT9gz3Ulnlnh465vLNhAXmpfgNhrDC2B1W0BLA69jcUY/wWQZpRARsYHjqBAv7hNNuciqSjpaRj nAGjnjkua5Y/oIPupUek9jlHF1GrKTtP9lKrtBYC1wW8DWZB3BFdpofhkoKQ1mqwaup5rfGG4pR VlgC/w0eVfslozwyLPNfGbCfCH3BJHzvzcZsiAcUWIHJUxnU0sBgfZ5cEX3NFa26dXkRNYcmRmO JXZkJ6EoRI4XWYw== X-Developer-Key: i=bryan.odonoghue@linaro.org; a=openpgp; fpr=E693FB2AABA36DE117AB6FB422713BB3A18DC83A Sashiko asked during a patch review if the existing usage pattern had a race condition; specifically in of_phy_get() if it was possible between returning from _of_phy_get() and running try_module_get() that a module might be unbound leading to use-after-free. Looking at the code this appears to be so, there is no linkage between the phy and module under a synchronisation primitive. Using the phy_provider_mutex in phy_get() will ensure there is a link betwe= en the returned phy pointer and the module_get() bumping the module reference count. Amend phy_get(), of_phy_get() and devm_of_phy_get_by_index() to fix the same usage pattern. phy_provider_unregister() must take the phy_provider_mutex so amending phy_get()/of_phy_get() to take that same mutex guarantees there is no use-after-free. Fixes: ff764963479a1 ("drivers: phy: add generic PHY framework") Cc: stable@vger.kernel.org Reviewed-by: Loic Poulain Reviewed-by: Manivannan Sadhasivam Signed-off-by: Bryan O'Donoghue Tested-by: Oleg Keri # Lenovo Yoga Slim 7x Gen 11 (Glym= ur) --- drivers/phy/phy-core.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 21aaf2f76e53e..89addd732bff3 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -124,13 +124,13 @@ static struct phy *phy_find(struct device *dev, const= char *con_id) const char *dev_id =3D dev_name(dev); struct phy_lookup *p, *pl =3D NULL; =20 - mutex_lock(&phy_provider_mutex); + lockdep_assert_held(&phy_provider_mutex); + list_for_each_entry(p, &phys, node) if (!strcmp(p->dev_id, dev_id) && !strcmp(p->con_id, con_id)) { pl =3D p; break; } - mutex_unlock(&phy_provider_mutex); =20 return pl ? pl->phy : ERR_PTR(-ENODEV); } @@ -624,6 +624,8 @@ static struct phy *_of_phy_get(struct device_node *np, = int index) struct phy *phy =3D NULL; struct of_phandle_args args; =20 + lockdep_assert_held(&phy_provider_mutex); + ret =3D of_parse_phandle_with_args(np, "phys", "#phy-cells", index, &args); if (ret) @@ -635,11 +637,10 @@ static struct phy *_of_phy_get(struct device_node *np= , int index) goto out_put_node; } =20 - mutex_lock(&phy_provider_mutex); phy_provider =3D of_phy_provider_lookup(args.np); if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) { phy =3D ERR_PTR(-EPROBE_DEFER); - goto out_unlock; + goto out_put_node; } =20 if (!of_device_is_available(args.np)) { @@ -653,8 +654,6 @@ static struct phy *_of_phy_get(struct device_node *np, = int index) out_put_module: module_put(phy_provider->owner); =20 -out_unlock: - mutex_unlock(&phy_provider_mutex); out_put_node: of_node_put(args.np); =20 @@ -678,15 +677,21 @@ struct phy *of_phy_get(struct device_node *np, const = char *con_id) if (con_id) index =3D of_property_match_string(np, "phy-names", con_id); =20 + mutex_lock(&phy_provider_mutex); + phy =3D _of_phy_get(np, index); if (IS_ERR(phy)) - return phy; + goto out_unlock; =20 - if (!try_module_get(phy->ops->owner)) - return ERR_PTR(-EPROBE_DEFER); + if (!try_module_get(phy->ops->owner)) { + phy =3D ERR_PTR(-EPROBE_DEFER); + goto out_unlock; + } =20 get_device(&phy->dev); =20 +out_unlock: + mutex_unlock(&phy_provider_mutex); return phy; } EXPORT_SYMBOL_GPL(of_phy_get); @@ -786,6 +791,7 @@ struct phy *phy_get(struct device *dev, const char *str= ing) struct phy *phy; struct device_link *link; =20 + mutex_lock(&phy_provider_mutex); if (dev->of_node) { if (string) index =3D of_property_match_string(dev->of_node, "phy-names", @@ -796,15 +802,18 @@ struct phy *phy_get(struct device *dev, const char *s= tring) } else { if (string =3D=3D NULL) { dev_WARN(dev, "missing string\n"); - return ERR_PTR(-EINVAL); + phy =3D ERR_PTR(-EINVAL); + goto out_unlock; } phy =3D phy_find(dev, string); } if (IS_ERR(phy)) - return phy; + goto out_unlock; =20 - if (!try_module_get(phy->ops->owner)) - return ERR_PTR(-EPROBE_DEFER); + if (!try_module_get(phy->ops->owner)) { + phy =3D ERR_PTR(-EPROBE_DEFER); + goto out_unlock; + } =20 get_device(&phy->dev); =20 @@ -813,6 +822,8 @@ struct phy *phy_get(struct device *dev, const char *str= ing) dev_dbg(dev, "failed to create device link to %s\n", dev_name(phy->dev.parent)); =20 +out_unlock: + mutex_unlock(&phy_provider_mutex); return phy; } EXPORT_SYMBOL_GPL(phy_get); @@ -961,15 +972,17 @@ struct phy *devm_of_phy_get_by_index(struct device *d= ev, struct device_node *np, if (!ptr) return ERR_PTR(-ENOMEM); =20 + mutex_lock(&phy_provider_mutex); phy =3D _of_phy_get(np, index); if (IS_ERR(phy)) { devres_free(ptr); - return phy; + goto out_unlock; } =20 if (!try_module_get(phy->ops->owner)) { devres_free(ptr); - return ERR_PTR(-EPROBE_DEFER); + phy =3D ERR_PTR(-EPROBE_DEFER); + goto out_unlock; } =20 get_device(&phy->dev); @@ -982,6 +995,8 @@ struct phy *devm_of_phy_get_by_index(struct device *dev= , struct device_node *np, dev_dbg(dev, "failed to create device link to %s\n", dev_name(phy->dev.parent)); =20 +out_unlock: + mutex_unlock(&phy_provider_mutex); return phy; } EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index); --=20 2.55.0 From nobody Fri Sep 25 02:12:38 2026 Received: from mail-ej2-f24.google.com (mail-ej2-f24.google.com [74.125.228.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 717043A6B66 for ; Thu, 17 Sep 2026 15:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658731; cv=none; b=eH6n6FW3D3mTNEt/P+0nHe0E1TWBYfBrZHUXySVcyM+9cEsS96Bw8n505IQqu6vTv94BLAk/vnV4Bj3E0qUxWNrVUJHHyhtQgcJmU4FDK0gFpbXNV+V9ykyo0xl8Ro5Nb2yeAncKuOGkX4aO/GPuCm3vJ7QRpxdL3A8eSkbHzpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658731; c=relaxed/simple; bh=mbGaKzht6FTlTs32snTkWI2to5iPenkW5iUX9UmH+is=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MbTInP0fZq/9bZgjztDawy02v+L5wvgdSBSY36h9GCOeM5c+6ND9JZFe7KvdVAjVJf/FX+KLHvWfdVLfP8sk7HFDrP6a2hYxbe7W2mqBSTWDN8qVDzfcfKvK3PvQP3sCwu1O/xStOJk1Phq/ipqoi36VSBK3tzWTp9wCXEibGCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=KhiCVbxR; arc=none smtp.client-ip=74.125.228.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KhiCVbxR" Received: by mail-ej2-f24.google.com with SMTP id a640c23a62f3a-c29d33431c8so142655066b.2 for ; Thu, 17 Sep 2026 08:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789658714; x=1790263514; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=o60JRFM5WA2Unn1KPhBnuEVA9Bwozt76P6e95xSEIP4=; b=KhiCVbxRQiHbhOuaqsMD/ufL5PWmqglIizZyaktdQtQ6vv6weKRfyU1sdtZUyJKga9 y16JS/UCyiZKSh6JxCybNzfxD0mRf2ZnnuE6kUfBV2b8JKR1/mRwBQOvBRQGa0YyiJUs SEnFqt5tNk6MRsA6G5+gXVbN67beFmxbrdte6LBrNjSZswB+MrClgHjAW2hJTMCTiTm0 QBOSYkMGVv7zqaTUN1N1VjG90MzyCGzEEVm7Kob2OJu0nQ9f+nru78OzfxU7rdnMu+U7 VIaLrVHfXsaYIqGKSVqFXvmS19Rfyg2bOvjNMPsyJiISqwcsyOokSAzzoia2daqxHnf6 nB7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789658714; x=1790263514; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=o60JRFM5WA2Unn1KPhBnuEVA9Bwozt76P6e95xSEIP4=; b=bkbd4PquDTvaxVWaEGXufhv+4wtZgs489a2erbPcj1iDL9fkAw9icoJ4tT6ip3CqYo ZlW4Cr4fSAxOzEA+I4pTs4QXCiIQWX6zUFGWP/WvuUPPH4ifSHcnlIGcURWYUZtNJrqI FNrHZj68A0pCMgDOgCXLyZHxOQ6EKsZDXWfij2+YxSh+dHxw88OySxQN++Va6HQpq9Lu 5Xx4eBZhUi/FTnEs5awdATm7njhp5ZKL4QCeWJUnCHQFGaM6u2Tp4e6ayNPWZWBX56F+ QrE0wU8Cj9JCVX0qrU9qchir5pKkwnuEY4O08MiG0aKHxeaelQYwq6Z4oZ6s4sFAWMty 5JrQ== X-Forwarded-Encrypted: i=1; AKwUvBwIYMeionYG7/DyUvikPTjF3R8zqplj/UQUS/oy20Yfyd4fqrfx73amWG6Q4pRhxiZ9uy5U8w0nDKYrdpY=@vger.kernel.org X-Gm-Message-State: AFuF++k/qJdCACxPwCmVz9IGxLTrVFotr/zkOWOhgYroKHOpAEuHDX9P wtgAGfZqhVeJgMWphFTtrKvabWwDL1zQQ42USLyo3UBVlpk1rd4YLGT9LTUuHCMMLs8= X-Gm-Gg: AYBFou24TfeuSNGRtC70HyN7/cny6omezPQrhdYlP1OgFgtI+RcP0Va9O8JitiMghTC EC6IZk12lTl3BGIcWeKbs5ojTLDBGDd9mERpvfJ3912m8J2JiYGpS8YF/dqV7p1rza/gQzb14dA jnESRQNiCofVT7hw2TnzGXB5ZaMUWu/bA0Po9mE0kfQwFWbwjmkxp/qI25fP1JvuJOXoOPVWhEM jp3fXI9Hkr2czAUggDQA7Tju5VBFtmGWFo7R0JRwVnyvkl9zq6I1utMl770plufG3E5HZqzrF2u XgC/uCurtgW+Fy1fNI8qTx712awGMhl+TBLiVBujledRodIPCAWaMrPL5R+HulzJ1rt237MOYLL LpNnz0ue8gPyYrAEwEmhxiKUNRimPBs4zD5Ddw1kBgwvxL+TPtXxr37Qxbalx8rmcdL7DuxyHVa 5YNF3ev5r1EiE40IlkM2NS9GC1et9fD5tdFy1LAaCxsaejibjwwKBAhuZ9wDVwcIu6R3Rn/3GSp mbmj9iOrw== X-Received: by 2002:a17:907:9710:b0:c29:5021:f6f8 with SMTP id a640c23a62f3a-c29e53242afmr538141166b.36.1789658714541; Thu, 17 Sep 2026 08:25:14 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c29de48755asm310587366b.24.2026.09.17.08.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 08:25:14 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 16:25:07 +0100 Subject: [PATCH v19 2/5] phy: core: Add phy_get_by_of_node() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-2-21ad8a76e941@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> To: Bjorn Andersson , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robert Foss , Todor Tomov , Mauro Carvalho Chehab , Konrad Dybcio , Vladimir Zapolskiy , Bryan O'Donoghue , Loic Poulain , Vinod Koul , Neil Armstrong , Greg Kroah-Hartman , Kishon Vijay Abraham I , Felipe Balbi , Manivannan Sadhasivam Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-phy@lists.infradead.org, Bryan O'Donoghue , Krzysztof Kozlowski X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4777; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=mbGaKzht6FTlTs32snTkWI2to5iPenkW5iUX9UmH+is=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqrAZUHU+EUBv2jfs/6uvx3XSpJcXQOAF2wkNhp 4xPSk+jVhmJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqwGVAAKCRAicTuzoY3I Oj/JD/0cpegEhQJY+utxEKWKYDFyWdT/4jJLzXhcgV6CvyR3ZjDIylxCRO7VLw1hbn3ZNUBqTeQ RvlFIPUkPiwHrwxKcQ9IV72nAvFge9vf4EOfwOG4m+35E2LoSKyJDcQpl72qnizIBHpDw1b7pom pRyy63h3OTJqnNk1H9yW/2Iy/ngUemQLZNnght68QnFCowIjufu6y4ZgMT6/q2vqpSFe4NS2+9Z hWA8mJtFxiG5WHF2maX5EONgaQ+7edW8wWKcUVHBynIJiBNE2j+am9P/7I4xVhnQwqQNUV52F4C YlPz4hDIfD493XC7Ofufes2KwGNqimwi1IRnrT5cDfuQtF6vy6cdm0UUWsCuHwI5y6sggZybpnG IF3Q3E3zxQ20LeABfZrPdOx4MH7cyEeDsAmDzbvnc+39VXwbDpyeffztcpQCqxdEJnSQdUWD89U IjztmonFiLmRbJM1dx1URij3pdGi3PVSARx6A1LozuJzxvgLiZ5d3K197MRQJFMpt39L75Hipda WtenBqsGgQGtuOM1ijIW4X1yWjmAL4IJiCIjGYhjSz/5n4Z8er/nsQEu8Optsy5cj2K64qNWO/R ZeLkRjGYUKCT8yTBBqH0H05rUwW8/oZ3PYi4HsKytb9VVzxr643QhzzBzp3qyk8CrQGtTxUMQdn A5lPsQBjVKU33+A== X-Developer-Key: i=bryan.odonoghue@linaro.org; a=openpgp; fpr=E693FB2AABA36DE117AB6FB422713BB3A18DC83A Add new function phy_get_by_of_node() allowing lookup of a phy by device_node. Separates existing logic in _of_phy_get() into an internal helper method _of_phy_get_with_args() to allow for reuse in new method. Reviewed-by: Neil Armstrong Signed-off-by: Bryan O'Donoghue Tested-by: Oleg Keri # Lenovo Yoga Slim 7x Gen 11 (Glym= ur) --- drivers/phy/phy-core.c | 87 +++++++++++++++++++++++++++++++++++++++------= ---- include/linux/phy/phy.h | 6 ++++ 2 files changed, 75 insertions(+), 18 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 89addd732bff3..4a8e1d3cdfe75 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -606,6 +606,38 @@ int phy_validate(struct phy *phy, enum phy_mode mode, = int submode, } EXPORT_SYMBOL_GPL(phy_validate); =20 +/** + * _of_phy_get_with_args() - lookup and obtain a reference to a phy by of_= phandle_args + * @args: of_phandle_args to the phy + * + * Returns the phy from the provider's of_xlate, -ENODEV if disabled, + * -EPROBE_DEFER if the provider is not yet registered. + */ +static struct phy *_of_phy_get_with_args(struct of_phandle_args *args) +{ + struct phy *phy; + struct phy_provider *phy_provider; + + lockdep_assert_held(&phy_provider_mutex); + + phy_provider =3D of_phy_provider_lookup(args->np); + if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) + return ERR_PTR(-EPROBE_DEFER); + + if (!of_device_is_available(args->np)) { + dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); + phy =3D ERR_PTR(-ENODEV); + goto out_put_module; + } + + phy =3D phy_provider->of_xlate(phy_provider->dev, args); + +out_put_module: + module_put(phy_provider->owner); + + return phy; +} + /** * _of_phy_get() - lookup and obtain a reference to a phy by phandle * @np: device_node for which to get the phy @@ -620,8 +652,7 @@ EXPORT_SYMBOL_GPL(phy_validate); static struct phy *_of_phy_get(struct device_node *np, int index) { int ret; - struct phy_provider *phy_provider; - struct phy *phy =3D NULL; + struct phy *phy; struct of_phandle_args args; =20 lockdep_assert_held(&phy_provider_mutex); @@ -637,22 +668,7 @@ static struct phy *_of_phy_get(struct device_node *np,= int index) goto out_put_node; } =20 - phy_provider =3D of_phy_provider_lookup(args.np); - if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) { - phy =3D ERR_PTR(-EPROBE_DEFER); - goto out_put_node; - } - - if (!of_device_is_available(args.np)) { - dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); - phy =3D ERR_PTR(-ENODEV); - goto out_put_module; - } - - phy =3D phy_provider->of_xlate(phy_provider->dev, &args); - -out_put_module: - module_put(phy_provider->owner); + phy =3D _of_phy_get_with_args(&args); =20 out_put_node: of_node_put(args.np); @@ -1001,6 +1017,41 @@ struct phy *devm_of_phy_get_by_index(struct device *= dev, struct device_node *np, } EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index); =20 +/** + * phy_get_by_of_node() - lookup and obtain a reference to a phy by device= _node + * @np: node containing the phy + * + * Returns the phy associated with the device node or ERR_PTR. + */ +struct phy *phy_get_by_of_node(struct device_node *np) +{ + struct of_phandle_args args =3D { .np =3D np, .args_count =3D 0 }; + struct phy *phy; + + if (!np) + return ERR_PTR(-EINVAL); + + mutex_lock(&phy_provider_mutex); + + phy =3D _of_phy_get_with_args(&args); + + if (IS_ERR(phy)) + goto out_unlock; + + if (!try_module_get(phy->ops->owner)) { + phy =3D ERR_PTR(-EPROBE_DEFER); + goto out_unlock; + } + + get_device(&phy->dev); + +out_unlock: + mutex_unlock(&phy_provider_mutex); + + return phy; +} +EXPORT_SYMBOL_GPL(phy_get_by_of_node); + /** * 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 ea47975e288ae..71c2e16397130 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -284,6 +284,7 @@ struct phy *devm_of_phy_optional_get(struct device *dev= , struct device_node *np, const char *con_id); struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_nod= e *np, int index); +struct phy *phy_get_by_of_node(struct device_node *np); void of_phy_put(struct phy *phy); void phy_put(struct device *dev, struct phy *phy); void devm_phy_put(struct device *dev, struct phy *phy); @@ -493,6 +494,11 @@ static inline struct phy *devm_of_phy_get_by_index(str= uct device *dev, return ERR_PTR(-ENOSYS); } =20 +static inline struct phy *phy_get_by_of_node(struct device_node *np) +{ + return ERR_PTR(-ENOSYS); +} + static inline void of_phy_put(struct phy *phy) { } --=20 2.55.0 From nobody Fri Sep 25 02:12:38 2026 Received: from mail-wr2-f12.google.com (mail-wr2-f12.google.com [74.125.225.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 607513E9F9E for ; Thu, 17 Sep 2026 15:25:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658729; cv=none; b=ZoqGnz52RugdgnEqao1JsC8brG8a90lzN0dmKuxaKqLyQgieLAS9LdnMun+xjrswj8LOYKg1c9lqOV8o9f8PomLlkMm6ew1KHwAJBN84QpHdsCcvFDWoa+rY152RRdzEswQv5jydFFJRj8FSFI78wZXwnqQ0c2u4z1ME2AGOZrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658729; c=relaxed/simple; bh=cDzuifZ35uySk/UpiYP0iSj8OxDSP029LxC//N6wFuk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aGoCM3zvAcjZI6IoNDxfSFO2Cf4gDpKRxRsSop5e+q9zQJ1kM8cZE8uPNCtES4FEd6wCJZIVV3FRvVJGmiIg4ZTHxfdc+e1tsvkoc4Ef/HfuWhz0TIQY0pWKouhsDiyk2qaVFZQLO53NwWDTWFG8493+z4XsCjyCWB1BdjjFd8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TtJ8ZDz6; arc=none smtp.client-ip=74.125.225.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TtJ8ZDz6" Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-482f6350f91so710945f8f.1 for ; Thu, 17 Sep 2026 08:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789658716; x=1790263516; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NMwGESoTpoxCW93e8KzY70EiAiyUsNG/4JMq0LantCg=; b=TtJ8ZDz69SGBUUx3acUjEswfKRJKS1KsNVBlSV+VQ0n1Y/Iz9PKCeFh2zq5Xjaj9vF uqZxiulbtuis2jQKoq3X6ocqgPNMnkRKssEiRrp0sQ+1Lg4ZRUWct26O7TBS0aHEKwUR BeAql+KPKR7w/yfmhFwBtl7akDX+IwM5d+l1Bedv1GmgkGKyE5eIodx3oDCFaBticnlI 1qQpZFLVF3ZM3zoGwyhBrIE08TLRZw5IFCIUtJ5gxoF+a6NAjFf+B1wwk7OgqU+9EsD4 ifkTfz+V5FpSwx5rDX4QI2MFMDiu4XOTS/Kf2VXQo8e/ZAdELnwbB9Ku12Xyjknid21u nNHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789658716; x=1790263516; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=NMwGESoTpoxCW93e8KzY70EiAiyUsNG/4JMq0LantCg=; b=u0jOBcgSVpNOJccr+aHYrFnQGU050goNhjoPO2fh6Fuv3u3uoCusFucrf1VA/FDol5 MJSvGnugPA9iL0K8PCCoct5iTnqFep2N0kPybYxrhFxHZPGPIdd2WIIbfT68ioUWKh6D rBDM8GzkVtBfX9f+KWUHBwk89gGSq3TnLdH3LsISbZWHzqJKH4gDLQD96Lm59MPLZh/7 Cqh4F4Vl6Vvarj10ljZVMQLqAkEyDicwQ+AOw9IAl7802GGk6PYpbwrYuN39svsrWPri mA/u8GWuZObTVmX9Imne3MNOHiuVJ97O0ulFi2/i+NyEwLqm0cNV9MEfQcOo6qji538G 3cBQ== X-Forwarded-Encrypted: i=1; AKwUvBxT9j8AhnYKZnXnB3obPpTO6UUUt/behUmY0ManFhNzwzYcgzshd/22md0FHBynE8SnY9IU468Ahj21kpM=@vger.kernel.org X-Gm-Message-State: AFuF++lw2185GqpmDWjsb6YzFlfEzjofkP+kE2ATDo+SeLfYhCxLMzXQ GI5vsuCtomZkksDC2QTSMGcBfbCB/a8hMyKn6c4svvmdhooYXlIYIcnos+rwYWvQHzg= X-Gm-Gg: AYBFou0o7s4EK85ifmD68VMuzCLRYQyU3wwQW6pknY51LLAE90vW85fOmDMztR/dV13 gLP38vZ244t+y55MvBlbfxwttNFF++DGESHPVnxvqjFXOzCaUxDnu9cs6y7Z0nSix4yOh5Mw/jK HfExXSWSr2T3BUWeKFU7WlXGNxsApy3J8e/JoAjwCh3ipDRcNr+6GZzlFmcKtDFH8HvWRPEdpKv boNVYixW0EZIIxlUrx7P/wwbq+KjjqBbu35/kU2pYSMv9ULNWQArPOhV1VmoM0ETeqR/qX+NJsH UeqthtzJcFF/a3r/1rp04coMf7GttvC1xAA90AvC5sTJdBpYMw1blXMqJVXSeblBCSb3EYBnM3w DcQD6Njlp7kPrS6GCAWO1RcEuFECEHTH851EnBjxsaLW25omW9tLXJ1CmvdiwzU8NK6sTFdskSb B+Bi/1LxnrqA0G2ry/da9tSH0IqFEL78eERg1hTecJ2XFBH2I5Coa5zA7NqnKqcUO0nF+z6VZ9G Taag8x2iVUlgc1EcdpM X-Received: by 2002:a17:906:7948:b0:c29:3838:dd5e with SMTP id a640c23a62f3a-c29e530a3femr490991866b.40.1789658716124; Thu, 17 Sep 2026 08:25:16 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c29de48755asm310587366b.24.2026.09.17.08.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 08:25:15 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 16:25:08 +0100 Subject: [PATCH v19 3/5] phy: core: Add devm_phy_get_by_of_node() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-3-21ad8a76e941@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> To: Bjorn Andersson , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robert Foss , Todor Tomov , Mauro Carvalho Chehab , Konrad Dybcio , Vladimir Zapolskiy , Bryan O'Donoghue , Loic Poulain , Vinod Koul , Neil Armstrong , Greg Kroah-Hartman , Kishon Vijay Abraham I , Felipe Balbi , Manivannan Sadhasivam Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-phy@lists.infradead.org, Bryan O'Donoghue , Krzysztof Kozlowski , Manivannan Sadhasivam X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2761; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=cDzuifZ35uySk/UpiYP0iSj8OxDSP029LxC//N6wFuk=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqrAZU/wHfXG/AsAs5KrgH5lFusNCZNVd+gD81A 7AhwLisQJiJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqwGVAAKCRAicTuzoY3I Om1dD/43gYbDziRG/DuUzuN10axrWDggX4LKPE8in+SbMC1NywaNlOiv1v9HkNmMyUOu4oVYUSM 2OCymKhNER21y5sVRJA2j5jBKIFmecAKnW52FHzSEkuoeFd15U3wwocAU6arz7MrEAD9bSVIvvX JL1dGNm5Ze/bGeiL/RAGDDPITyjnbVfCIrwwin8DfQw0zMXFyabDVPsysXNYSC/zZ5a6HxTrcqe hn5NBF+m08nF0ZDfbUEhUeKJGW3OsqgcThRINrR4ZRZFxHf6uYVfqdcLq+HTdtKtBdAnBvkHgOa SHVJQ79VuefwsnWvWsBrBEKnlja2iLBVo2q35FdTnd0ZqRI0QcXSuVcuBhua/zzQ1xCgC2/hi4/ qX/Tts/1Fcj7r/h1w1RusuP3ySmiwo8ehmYuUKXFYBGFnEbKIepxYnloOZU8zgJtJU8A1qo/hb6 lRc9sYBLwSuyh1UKQl5YcxF4hXi5wWrCY73MGp0Bz5m4UbYCt8dwbALJgAfvVeycpmMujRLKwEY P8EnYQtGfqvf8lBT1F6NzDMarmCp2lNsvV8Q/RwN5gSlJ8WxaYfGeP/EnoofIMJbdPyChKS/MNO 7V5+mYWP2F/UQZJatdHn3i8aBXbWmnP1Nx7lKBniOh6LhbC0kN8H9Z3v42Bbee252sNk1YYBZFx I9n6sWr9c3Jm6gQ== X-Developer-Key: i=bryan.odonoghue@linaro.org; a=openpgp; fpr=E693FB2AABA36DE117AB6FB422713BB3A18DC83A Add a devm variant of phy_get_by_of_node() to allow for the familiar pattern of having devres automatically release resources on the driver's exit path. Reviewed-by: Manivannan Sadhasivam Signed-off-by: Bryan O'Donoghue Tested-by: Oleg Keri # Lenovo Yoga Slim 7x Gen 11 (Glym= ur) --- drivers/phy/phy-core.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 7 +++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 4a8e1d3cdfe75..e24a38662b484 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1052,6 +1052,40 @@ struct phy *phy_get_by_of_node(struct device_node *n= p) } EXPORT_SYMBOL_GPL(phy_get_by_of_node); =20 +/** + * devm_phy_get_by_of_node() - devm managed lookup and obtain phy referenc= e by device node + * @dev: device requesting the PHY + * @np: device_node of the PHY provider + * + * Returns phy associated with the device_node or ERR_PTR. devres manages + * releasing resources. + */ +struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node= *np) +{ + struct phy **ptr, *phy; + struct device_link *link; + + ptr =3D devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + phy =3D phy_get_by_of_node(np); + if (IS_ERR(phy)) { + devres_free(ptr); + return phy; + } + + *ptr =3D phy; + devres_add(dev, ptr); + link =3D device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); + if (!link) + dev_dbg(dev, "failed to create device link to %s\n", + dev_name(phy->dev.parent)); + + return phy; +} +EXPORT_SYMBOL_GPL(devm_phy_get_by_of_node); + /** * 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 71c2e16397130..14b924a88411f 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -285,6 +285,7 @@ struct phy *devm_of_phy_optional_get(struct device *dev= , struct device_node *np, struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_nod= e *np, int index); struct phy *phy_get_by_of_node(struct device_node *np); +struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node= *np); void of_phy_put(struct phy *phy); void phy_put(struct device *dev, struct phy *phy); void devm_phy_put(struct device *dev, struct phy *phy); @@ -499,6 +500,12 @@ static inline struct phy *phy_get_by_of_node(struct de= vice_node *np) return ERR_PTR(-ENOSYS); } =20 +static inline struct phy *devm_phy_get_by_of_node(struct device *dev, + struct device_node *np) +{ + return ERR_PTR(-ENOSYS); +} + static inline void of_phy_put(struct phy *phy) { } --=20 2.55.0 From nobody Fri Sep 25 02:12:38 2026 Received: from mail-ej2-f12.google.com (mail-ej2-f12.google.com [74.125.228.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4EFB4DAF97 for ; Thu, 17 Sep 2026 15:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658734; cv=none; b=qpLziFZwklO1CRUmWrJm7pHJaaTUW9B7UPN7NASpOC1DmkitU+FKunsUrEDEwB6gl+P80Rwh3Tekr8mJpV8qxg0rrlZ8MgATxAGpwaE3cdaMY7aoVwyJx41GB1ogsBkd5D9oena+DZXDIWNPaN9+y8pv4o+kR8rnwh5snNv3Iz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658734; c=relaxed/simple; bh=f09vqGxreX9xj4jU87a9RbysYDmF4tb6JPhpFI8rxk8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WhV7go5bXhfxoOego3fAMNSQnb4QwS6o9oEfTc5Kg7XWTPnHMOR0uKzA94UmFrj9jzx4aLlb4iVtPe7BqwYRqjPwjMWm+jpIrK+ZXcei0u6BzIgJv1KQxgSjl5588jnCYKDnkCa+bO/zfUYfCFEWn7xLZZipfbgzc1Aw190vjSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ayfs06CB; arc=none smtp.client-ip=74.125.228.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ayfs06CB" Received: by mail-ej2-f12.google.com with SMTP id a640c23a62f3a-c254f8694aeso66010566b.0 for ; Thu, 17 Sep 2026 08:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789658718; x=1790263518; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jJh4Bj896WxleG2/DfFUtEmq0Yj3ewz6DnoNw13Zf0k=; b=ayfs06CBAqx3QRbIBSj9Hxy5RTSgNo/MYkAnIAwVyd8iAA9ZMZTyBaunvfpLoPs1DC APts5TUO2i1ydaIgc0AHtKwnWIbA7R9EBVU/cymVzNulyftL3yZ6W+pyaIaqq3+Ykwlq Fq++JvoWURDfj0xzcCQwFAq/EQiqBMGTj8DPS9HzuCmCohvMVLAc3rIFPn7aSgJlPXs+ j6p+UrX4Kh4CqtRiolXCiglxgY5WgMRh3fEMkGZ/uPH5Fr7ooq4WdqaJn47NsTbGGfX0 +sdFL3bdF4pq6Ul+Wqr7u+V9m7geLO+gU7QiidoPS5fQMnU6SumbgfoMashaWK07qN+i vAvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789658718; x=1790263518; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jJh4Bj896WxleG2/DfFUtEmq0Yj3ewz6DnoNw13Zf0k=; b=1uJ6F/a1Lno+s92994dSZxyd1x7cgFmdgx0V7NNYWa9OgQqIncgdfZzbX97+kt7vpd LTX40fBEcGnwOB0Y3+90CDnjBbmrtg/JMooGazvr71rme81qPrWa2R7J8lLA4z8PqfCL /UsD/L+i1DSzwnbRYtmV+oHmdXTs+KuGrmzDyTDdKNf3MXEzkSZEFDz0TzxAGL8RuCY/ 7Lj/V2kOchkMUmlYpNsMlKAaWEL1PbQLlVIPJnvt4Iuxg3ez8bcAECIsDibEjhK50oSF 86qeGwDHjt53P53q/rXFXUKMa1KBKpX5GLytzEeY16Bminrutt2lGGztz1gmmCLJYj1/ 0MJg== X-Forwarded-Encrypted: i=1; AKwUvBzyo2lzZR8KVdDLRJJ46O/v3prmBCL27mlU3iRPEcKevwoIv0gBnM0tR1AMGvPqAN6h5jlUdfJXREZ9xdg=@vger.kernel.org X-Gm-Message-State: AFuF++m1gwJ0NYyAiXSheGkG2jGEu/0LF8NVm4mjHKR931HGSRTR2egO hfN0sP27HMSJi3nhmzCXyOVPkNwJtYhBpSQT81GtZwCk6IXtWxAQmWlquuUj8j4KN90= X-Gm-Gg: AYBFou2EMoTIuaBMLdQA+ifzfsSLGeT967YPTnUPjskN/ZT+LUAmqUkExTA4g9CN74N 5zOY20xkMyt51xCmO0m2EWEBjGoqbhNbw3mvFkSGkmLQ8CLhY6mpIEp40DAVShXvkaOGLRJk7Ig A+jWamOPXByiGzz8Bq80mB2UI8P+aUP67djUMyM0fOAiI+iVBSaj+QGVfnRJrKxbpmMie+qW3L6 jX7IR9qM41lvtnT5Xjv83NqZpKl3ZA3jaaODquoPW66K7JfM27oqeqSzy/HF1gHgFemmvIvLJhG MeoCLWE1DGSDOadzHCl1ykia6u1+GoadBBSQlUz4qk5YTLTjR+xhLbJfOhQCGQgmcoZcgkPFo3/ 8vo6+pjrgkW5zgCy1JU/HvDalDN8PS+7HPu5jaQLPKoNhJKVYci+onAIvt4RRaaBgMOivu5+HYk D4UUkMK7iHmfoMGdrl1rO+8rxCE+tTQNG/sACixQpemHIpg/yIyamnmzJpPVxepqmyIf/uZF0hN /uhh05Log== X-Received: by 2002:a17:906:9c82:b0:c24:6382:2648 with SMTP id a640c23a62f3a-c29f523b229mr321433866b.5.1789658717625; Thu, 17 Sep 2026 08:25:17 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c29de48755asm310587366b.24.2026.09.17.08.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 08:25:17 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 16:25:09 +0100 Subject: [PATCH v19 4/5] media: qcom: camss: Add support for PHY API devices Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-4-21ad8a76e941@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> To: Bjorn Andersson , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robert Foss , Todor Tomov , Mauro Carvalho Chehab , Konrad Dybcio , Vladimir Zapolskiy , Bryan O'Donoghue , Loic Poulain , Vinod Koul , Neil Armstrong , Greg Kroah-Hartman , Kishon Vijay Abraham I , Felipe Balbi , Manivannan Sadhasivam Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-phy@lists.infradead.org, Bryan O'Donoghue , Krzysztof Kozlowski X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=17787; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=f09vqGxreX9xj4jU87a9RbysYDmF4tb6JPhpFI8rxk8=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqrAZVvtATBJIU0nvNC4+aVQhzhWk6emUFEtrXm 8+38I67KpuJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqwGVQAKCRAicTuzoY3I Os5hD/9JL+5lCloUz31DDDFDAXsztBp3mUsEh2rGd9pcfZts++aeJE6ZAgpN76iYzGR6qeMM3rN WE/aLiHZZDStShpZwGQwxj61cRoUal/sRqjoXCg77VdKfsemNNALIs+YGKRDc3GZqkAotzfcO4t ppiH4D41RlHH2vYsYe3JmHPlvquXmC68m597TJqnqeOwIMXZHsfbx0ghLfx18KpddaNBSyR/aNI Q5UcLpm9m9J/0TqZDJi7FXBk8dVprt+5ryLF+OWfJQmiCPen24siXz7OJa3m46YWffjtcBUbQ8y 9Ocmm/b7/cxKxQsobc2nVWH+yGKbss5VjBciZBhNPXcHCcBUeV69Tptama0y8tfHM8XoksWceJd l1lErlNSgEDMyPXZ0NgoFqEoBDs3uU8pV/uykMPe/ajroo1JzoejYlX6iZ1v0FGmGwHJIpNq5jG CNpzDKi+oQO1gxpeK0DEY+udNwUrmYE15pKPBJB/pzGVt9+hM3heitdMpCk6PnER/23H5mDfAs4 PvfeOX+qgWy+c3FaFkIeUBuvtbgPNZ7uZPJva0yK5De8m/dtfS2vUl2BCefuTfvfLrJnYrTx3Ci kPgmC0Dha77KEnb2fa2RFPXCrv/K2LH/kLfEKTr/ADksmafb2HfEDsdG3BXPTCLxHpwGKrWZanv +WGhKtd0H0ETRTA== X-Developer-Key: i=bryan.odonoghue@linaro.org; a=openpgp; fpr=E693FB2AABA36DE117AB6FB422713BB3A18DC83A Add the ability to use a PHY pointer which interacts with the standard PHY API. In the first instance the code will try to use the new PHY interface. If no PHYs are present in the DT then the legacy method will be attempted. Signed-off-by: Bryan O'Donoghue Tested-by: Oleg Keri # Lenovo Yoga Slim 7x Gen 11 (Glym= ur) --- drivers/media/platform/qcom/camss/Kconfig | 1 + drivers/media/platform/qcom/camss/camss-csiphy.c | 200 +++++++++++++++++++= ++-- drivers/media/platform/qcom/camss/camss-csiphy.h | 11 +- drivers/media/platform/qcom/camss/camss.c | 104 ++++++++++-- drivers/media/platform/qcom/camss/camss.h | 1 + 5 files changed, 285 insertions(+), 32 deletions(-) diff --git a/drivers/media/platform/qcom/camss/Kconfig b/drivers/media/plat= form/qcom/camss/Kconfig index 4eda48cb1adf0..1edc5e5a1829e 100644 --- a/drivers/media/platform/qcom/camss/Kconfig +++ b/drivers/media/platform/qcom/camss/Kconfig @@ -7,3 +7,4 @@ config VIDEO_QCOM_CAMSS select VIDEO_V4L2_SUBDEV_API select VIDEOBUF2_DMA_SG select V4L2_FWNODE + select PHY_QCOM_MIPI_CSI2 diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/med= ia/platform/qcom/camss/camss-csiphy.c index 539ac4888b608..aaed7d0309dd6 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy.c +++ b/drivers/media/platform/qcom/camss/camss-csiphy.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include #include @@ -131,10 +133,10 @@ static u8 csiphy_get_bpp(const struct csiphy_format_i= nfo *formats, } =20 /* - * csiphy_set_clock_rates - Calculate and set clock rates on CSIPHY module + * csiphy_set_clock_rates_legacy - Calculate and set clock rates on CSIPHY= module * @csiphy: CSIPHY device */ -static int csiphy_set_clock_rates(struct csiphy_device *csiphy) +static int csiphy_set_clock_rates_legacy(struct csiphy_device *csiphy) { struct device *dev =3D csiphy->camss->dev; s64 link_freq; @@ -200,7 +202,7 @@ static int csiphy_set_clock_rates(struct csiphy_device = *csiphy) * * Return 0 on success or a negative error code otherwise */ -static int csiphy_set_power(struct v4l2_subdev *sd, int on) +static int csiphy_set_power_legacy(struct v4l2_subdev *sd, int on) { struct csiphy_device *csiphy =3D v4l2_get_subdevdata(sd); struct device *dev =3D csiphy->camss->dev; @@ -219,7 +221,7 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int= on) return ret; } =20 - ret =3D csiphy_set_clock_rates(csiphy); + ret =3D csiphy_set_clock_rates_legacy(csiphy); if (ret < 0) { regulator_bulk_disable(csiphy->num_supplies, csiphy->supplies); @@ -254,7 +256,7 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int= on) } =20 /* - * csiphy_stream_on - Enable streaming on CSIPHY module + * csiphy_stream_on_legacy - Enable streaming on CSIPHY module * @csiphy: CSIPHY device * * Helper function to enable streaming on CSIPHY module. @@ -262,7 +264,7 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int= on) * * Return 0 on success or a negative error code otherwise */ -static int csiphy_stream_on(struct csiphy_device *csiphy) +static int csiphy_stream_on_legacy(struct csiphy_device *csiphy) { struct csiphy_config *cfg =3D &csiphy->cfg; s64 link_freq; @@ -306,11 +308,98 @@ static int csiphy_stream_on(struct csiphy_device *csi= phy) * * Helper function to disable streaming on CSIPHY module */ -static void csiphy_stream_off(struct csiphy_device *csiphy) +static void csiphy_stream_off_legacy(struct csiphy_device *csiphy) { csiphy->res->hw_ops->lanes_disable(csiphy, &csiphy->cfg); } =20 +/* + * csiphy_stream_on - Enable streaming on CSIPHY module + * @csiphy: CSIPHY device + * + * Helper function to enable streaming on CSIPHY module. + * Main configuration of CSIPHY module is also done here. + * + * Return 0 on success or a negative error code otherwise + */ +static int csiphy_stream_on(struct csiphy_device *csiphy) +{ + u8 bpp =3D csiphy_get_bpp(csiphy->res->formats->formats, csiphy->res->for= mats->nformats, + csiphy->fmt[MSM_CSIPHY_PAD_SINK].code); + struct csiphy_lanes_cfg *lncfg =3D &csiphy->cfg.csi2->lane_cfg; + struct phy_configure_opts_mipi_dphy *dphy_cfg; + union phy_configure_opts dphy_opts =3D { 0 }; + struct device *dev =3D csiphy->camss->dev; + u8 num_lanes =3D lncfg->num_data; + s64 link_freq; + int ret; + + dphy_cfg =3D &dphy_opts.mipi_dphy; + + link_freq =3D camss_get_link_freq(&csiphy->subdev.entity, bpp, num_lanes); + + if (link_freq <=3D 0) { + dev_err(dev, + "Cannot get CSI2 transmitter's link frequency\n"); + return -EINVAL; + } + + ret =3D phy_mipi_dphy_get_default_config_for_hsclk(link_freq, num_lanes, + dphy_cfg); + if (ret < 0) { + dev_err(dev, "Invalid config for link frequency %lld\n", + link_freq); + return ret; + } + + ret =3D phy_set_mode(csiphy->phy, PHY_MODE_MIPI_DPHY); + if (ret) { + dev_err(dev, "Failed to set phy mode\n"); + return ret; + } + + ret =3D phy_configure(csiphy->phy, &dphy_opts); + if (ret) { + dev_err(dev, "failed to configure MIPI D-PHY\n"); + goto error; + } + + return phy_power_on(csiphy->phy); + +error: + return ret; +} + +/* + * csiphy_stream_off - Disable streaming on CSIPHY module + * @csiphy: CSIPHY device + * + * Helper function to disable streaming on CSIPHY module + */ +static void csiphy_stream_off(struct csiphy_device *csiphy) +{ + phy_power_off(csiphy->phy); +} + +/* + * csiphy_set_stream - Enable/disable streaming on CSIPHY module + * @sd: CSIPHY V4L2 subdevice + * @enable: Requested streaming state + * + * Return 0 on success or a negative error code otherwise + */ +static int csiphy_set_stream_legacy(struct v4l2_subdev *sd, int enable) +{ + struct csiphy_device *csiphy =3D v4l2_get_subdevdata(sd); + int ret =3D 0; + + if (enable) + ret =3D csiphy_stream_on_legacy(csiphy); + else + csiphy_stream_off_legacy(csiphy); + + return ret; +} =20 /* * csiphy_set_stream - Enable/disable streaming on CSIPHY module @@ -572,16 +661,16 @@ csiphy_match_clock_name(const char *clock_name, const= char *format, ...) } =20 /* - * msm_csiphy_subdev_init - Initialize CSIPHY device structure and resourc= es + * msm_csiphy_subdev_init_legacy - Initialize CSIPHY device structure and = resources * @csiphy: CSIPHY device * @res: CSIPHY module resources table * @id: CSIPHY module id * * Return 0 on success or a negative error code otherwise */ -int msm_csiphy_subdev_init(struct camss *camss, - struct csiphy_device *csiphy, - const struct camss_subdev_resources *res, u8 id) +int msm_csiphy_subdev_init_legacy(struct camss *camss, + struct csiphy_device *csiphy, + const struct camss_subdev_resources *res, u8 id) { struct device *dev =3D camss->dev; struct platform_device *pdev =3D to_platform_device(dev); @@ -709,6 +798,54 @@ int msm_csiphy_subdev_init(struct camss *camss, return ret; } =20 +/* + * msm_csiphy_subdev_init - Initialize CSIPHY device structure and resourc= es + * @camss: CAMSS structure + * @port: DT port index + * + * Return 0 on success or absence of link, negative error code otherwise + */ +int msm_csiphy_subdev_init(struct camss *camss, u8 port) +{ + const struct camss_subdev_resources *res =3D &camss->res->csiphy_res[port= ]; + struct csiphy_device *csiphy =3D &camss->csiphy[port]; + struct device *dev =3D camss->dev; + struct device_node *ep, *remote; + int ret; + + ep =3D of_graph_get_endpoint_by_regs(dev->of_node, port, -1); + if (!ep) + return 0; + + remote =3D of_graph_get_remote_port_parent(ep); + of_node_put(ep); + if (!remote) + return 0; + + if (!of_device_is_available(remote)) { + of_node_put(remote); + return 0; + } + + csiphy->phy =3D devm_phy_get_by_of_node(dev, remote); + of_node_put(remote); + if (IS_ERR(csiphy->phy)) { + ret =3D PTR_ERR(csiphy->phy); + goto done; + } + + csiphy->camss =3D camss; + csiphy->id =3D res->csiphy.id; + csiphy->res =3D &res->csiphy; + + snprintf(csiphy->name, ARRAY_SIZE(csiphy->name), "csi%d", csiphy->id); + + return 0; + +done: + return ret; +} + /* * csiphy_link_setup - Setup CSIPHY connections * @entity: Pointer to media entity structure @@ -743,8 +880,12 @@ static int csiphy_link_setup(struct media_entity *enti= ty, return 0; } =20 -static const struct v4l2_subdev_core_ops csiphy_core_ops =3D { - .s_power =3D csiphy_set_power, +static const struct v4l2_subdev_core_ops csiphy_core_ops_legacy =3D { + .s_power =3D csiphy_set_power_legacy, +}; + +static const struct v4l2_subdev_video_ops csiphy_video_ops_legacy =3D { + .s_stream =3D csiphy_set_stream_legacy, }; =20 static const struct v4l2_subdev_video_ops csiphy_video_ops =3D { @@ -758,8 +899,13 @@ static const struct v4l2_subdev_pad_ops csiphy_pad_ops= =3D { .set_fmt =3D csiphy_set_format, }; =20 +static const struct v4l2_subdev_ops csiphy_v4l2_ops_legacy =3D { + .core =3D &csiphy_core_ops_legacy, + .video =3D &csiphy_video_ops_legacy, + .pad =3D &csiphy_pad_ops, +}; + static const struct v4l2_subdev_ops csiphy_v4l2_ops =3D { - .core =3D &csiphy_core_ops, .video =3D &csiphy_video_ops, .pad =3D &csiphy_pad_ops, }; @@ -785,10 +931,15 @@ int msm_csiphy_register_entity(struct csiphy_device *= csiphy, { struct v4l2_subdev *sd =3D &csiphy->subdev; struct media_pad *pads =3D csiphy->pads; - struct device *dev =3D csiphy->camss->dev; + struct camss *camss =3D csiphy->camss; + struct device *dev =3D camss->dev; int ret; =20 - v4l2_subdev_init(sd, &csiphy_v4l2_ops); + if (camss->legacy_phy) + v4l2_subdev_init(sd, &csiphy_v4l2_ops_legacy); + else + v4l2_subdev_init(sd, &csiphy_v4l2_ops); + sd->internal_ops =3D &csiphy_v4l2_internal_ops; sd->flags |=3D V4L2_SUBDEV_FL_HAS_DEVNODE; snprintf(sd->name, ARRAY_SIZE(sd->name), "%s%d", @@ -816,9 +967,22 @@ int msm_csiphy_register_entity(struct csiphy_device *c= siphy, ret =3D v4l2_device_register_subdev(v4l2_dev, sd); if (ret < 0) { dev_err(dev, "Failed to register subdev: %d\n", ret); - media_entity_cleanup(&sd->entity); + goto media_entity_err; + } + + if (!IS_ERR(csiphy->phy)) { + ret =3D phy_init(csiphy->phy); + if (ret) { + dev_err(dev, "%s init fail %d\n", csiphy->name, ret); + v4l2_device_unregister_subdev(sd); + goto media_entity_err; + } } =20 + return 0; + +media_entity_err: + media_entity_cleanup(&sd->entity); return ret; } =20 @@ -828,6 +992,8 @@ int msm_csiphy_register_entity(struct csiphy_device *cs= iphy, */ void msm_csiphy_unregister_entity(struct csiphy_device *csiphy) { + if (!IS_ERR(csiphy->phy)) + phy_exit(csiphy->phy); v4l2_device_unregister_subdev(&csiphy->subdev); media_entity_cleanup(&csiphy->subdev.entity); } diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h b/drivers/med= ia/platform/qcom/camss/camss-csiphy.h index 9d9657b82f748..7a357044b9fdb 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy.h +++ b/drivers/media/platform/qcom/camss/camss-csiphy.h @@ -12,6 +12,7 @@ =20 #include #include +#include #include #include #include @@ -97,6 +98,7 @@ struct csiphy_device_regs { =20 struct csiphy_device { struct camss *camss; + struct phy *phy; u8 id; struct v4l2_subdev subdev; struct media_pad pads[MSM_CSIPHY_PADS_NUM]; @@ -104,6 +106,7 @@ struct csiphy_device { void __iomem *base_clk_mux; u32 irq; char irq_name[30]; + char name[16]; struct camss_clock *clock; bool *rate_set; int nclocks; @@ -118,9 +121,11 @@ struct csiphy_device { =20 struct camss_subdev_resources; =20 -int msm_csiphy_subdev_init(struct camss *camss, - struct csiphy_device *csiphy, - const struct camss_subdev_resources *res, u8 id); +int msm_csiphy_subdev_init_legacy(struct camss *camss, + struct csiphy_device *csiphy, + const struct camss_subdev_resources *res, u8 id); + +int msm_csiphy_subdev_init(struct camss *camss, u8 port); =20 int msm_csiphy_register_entity(struct csiphy_device *csiphy, struct v4l2_device *v4l2_dev); diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/plat= form/qcom/camss/camss.c index 2123f6388e3d7..84097d82d99c9 100644 --- a/drivers/media/platform/qcom/camss/camss.c +++ b/drivers/media/platform/qcom/camss/camss.c @@ -4799,8 +4799,43 @@ static int camss_parse_ports(struct camss *camss) fwnode_graph_for_each_endpoint(fwnode, ep) { struct camss_async_subdev *csd; =20 - csd =3D v4l2_async_nf_add_fwnode_remote(&camss->notifier, ep, - typeof(*csd)); + if (!fwnode_device_is_available(ep)) + continue; + + if (camss->legacy_phy) { + csd =3D v4l2_async_nf_add_fwnode_remote(&camss->notifier, ep, + typeof(*csd)); + } else { + struct fwnode_handle *phy_out, *phy_node, *phy_in, *sensor_ep; + + phy_out =3D fwnode_graph_get_remote_endpoint(ep); + if (!phy_out) + continue; + + phy_node =3D fwnode_graph_get_port_parent(phy_out); + fwnode_handle_put(phy_out); + if (!phy_node) + continue; + + phy_in =3D fwnode_graph_get_endpoint_by_id(phy_node, 0, 0, 0); + fwnode_handle_put(phy_node); + if (!phy_in) + continue; + + sensor_ep =3D fwnode_graph_get_remote_endpoint(phy_in); + fwnode_handle_put(phy_in); + if (!sensor_ep) + continue; + + csd =3D v4l2_async_nf_add_fwnode(&camss->notifier, sensor_ep, + struct camss_async_subdev); + fwnode_handle_put(sensor_ep); + if (IS_ERR(csd)) { + ret =3D PTR_ERR(csd); + goto err_cleanup; + } + } + if (IS_ERR(csd)) { ret =3D PTR_ERR(csd); goto err_cleanup; @@ -4819,6 +4854,29 @@ static int camss_parse_ports(struct camss *camss) return ret; } =20 +static void camss_detect_legacy_phy(struct camss *camss) +{ + struct device_node *remote; + struct device_node *ep; + + camss->legacy_phy =3D true; + + /* Find first remote-endpoint and determine if its a PHY */ + for_each_endpoint_of_node(camss->dev->of_node, ep) { + remote =3D of_graph_get_remote_port_parent(ep); + if (!remote) + continue; + + camss->legacy_phy =3D !of_node_name_eq(remote, "phy"); + of_node_put(remote); + of_node_put(ep); + break; + } + + dev_dbg(camss->dev, "legacy phy mode %s\n", + camss->legacy_phy ? "true" : "false"); +} + /* * camss_init_subdevices - Initialize subdev structures and resources * @camss: CAMSS device @@ -4832,14 +4890,21 @@ static int camss_init_subdevices(struct camss *cams= s) unsigned int i; int ret; =20 + camss_detect_legacy_phy(camss); + for (i =3D 0; i < camss->res->csiphy_num; i++) { - ret =3D msm_csiphy_subdev_init(camss, &camss->csiphy[i], - &res->csiphy_res[i], - res->csiphy_res[i].csiphy.id); + if (!camss->legacy_phy) { + ret =3D msm_csiphy_subdev_init(camss, i); + } else { + ret =3D msm_csiphy_subdev_init_legacy(camss, + &camss->csiphy[i], + &res->csiphy_res[i], + res->csiphy_res[i].csiphy.id); + } + if (ret < 0) { - dev_err(camss->dev, - "Failed to init csiphy%d sub-device: %d\n", - i, ret); + dev_err(camss->dev, "csiphy %d init fail\n", + res->csiphy_res[i].csiphy.id); return ret; } } @@ -4917,6 +4982,11 @@ inline void camss_link_err(struct camss *camss, ret); } =20 +static inline bool csiphy_enabled(struct camss *camss, struct csiphy_devic= e *c) +{ + return camss->legacy_phy || c->phy; +} + /* * camss_link_entities - Register subdev nodes and create links * @camss: CAMSS device @@ -4930,6 +5000,9 @@ static int camss_link_entities(struct camss *camss) =20 for (i =3D 0; i < camss->res->csiphy_num; i++) { for (j =3D 0; j < camss->res->csid_num; j++) { + if (!csiphy_enabled(camss, &camss->csiphy[i])) + continue; + ret =3D media_create_pad_link(&camss->csiphy[i].subdev.entity, MSM_CSIPHY_PAD_SRC, &camss->csid[j].subdev.entity, @@ -5056,6 +5129,9 @@ static int camss_register_entities(struct camss *cams= s) int ret; =20 for (i =3D 0; i < camss->res->csiphy_num; i++) { + if (!csiphy_enabled(camss, &camss->csiphy[i])) + continue; + ret =3D msm_csiphy_register_entity(&camss->csiphy[i], &camss->v4l2_dev); if (ret < 0) { @@ -5131,8 +5207,10 @@ static int camss_register_entities(struct camss *cam= ss) =20 i =3D camss->res->csiphy_num; err_reg_csiphy: - for (i--; i >=3D 0; i--) - msm_csiphy_unregister_entity(&camss->csiphy[i]); + for (i--; i >=3D 0; i--) { + if (csiphy_enabled(camss, &camss->csiphy[i])) + msm_csiphy_unregister_entity(&camss->csiphy[i]); + } =20 return ret; } @@ -5147,8 +5225,10 @@ static void camss_unregister_entities(struct camss *= camss) { unsigned int i; =20 - for (i =3D 0; i < camss->res->csiphy_num; i++) - msm_csiphy_unregister_entity(&camss->csiphy[i]); + for (i =3D 0; i < camss->res->csiphy_num; i++) { + if (csiphy_enabled(camss, &camss->csiphy[i])) + msm_csiphy_unregister_entity(&camss->csiphy[i]); + } =20 if (camss->tpg) { for (i =3D 0; i < camss->res->tpg_num; i++) diff --git a/drivers/media/platform/qcom/camss/camss.h b/drivers/media/plat= form/qcom/camss/camss.h index 93d691c8ac63b..ba3d51d9c0bf8 100644 --- a/drivers/media/platform/qcom/camss/camss.h +++ b/drivers/media/platform/qcom/camss/camss.h @@ -138,6 +138,7 @@ struct camss { struct device_link *genpd_link; struct icc_path *icc_path[ICC_SM8250_COUNT]; const struct camss_resources *res; + bool legacy_phy; }; =20 struct camss_camera_interface { --=20 2.55.0 From nobody Fri Sep 25 02:12:38 2026 Received: from mail-ej2-f43.google.com (mail-ej2-f43.google.com [74.125.228.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5823B4B44C6 for ; Thu, 17 Sep 2026 15:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658740; cv=none; b=GC8s3yir2b+VfqxC3ltATN1Db6Ysoj3KYM2mkK09EM+39qeM2qcB975Fwxc3BmiujLqasGUG9HYtNQjsXjd9NhDXMUSqyLY5Rit1c97P9tazBxlseE8DgJo49+tIEkHgw3qvpq2OwmAn5QNnTfNFWcTkp5w3BHxUXuuYZv1hifw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658740; c=relaxed/simple; bh=nAvKHTAAv3bLPDa8RtV69vy9lxOAzsfXW/WIHWa05a0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ORt1WPynnpOHRHWPV/7KstyzE8gcfT12CAgL+WnumSmxjyHYn0UFsPBWADWs6O6PTRCFl6isp/GWR60/pAxG2Cek1+SWWuFuZ0RUOJz6WTfQy7CxPylLogmfaIK3JekLbpRk/gtQNd5SBbkEzzW/A3ucKWyVLsjesoFv+8LeZw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=w1llmHBS; arc=none smtp.client-ip=74.125.228.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="w1llmHBS" Received: by mail-ej2-f43.google.com with SMTP id a640c23a62f3a-c254f9f7db0so150141566b.3 for ; Thu, 17 Sep 2026 08:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789658719; x=1790263519; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=XaaG9kQMPrqSpcZJreTasVAHAtAhXdOZx6qidBNV3Yk=; b=w1llmHBS6q6+W4/GGuf/sVFUprjcN5RneYzrTcGmVhAoCS+NCyV33Xl2CutJ7BuvnZ zg11Rgh7ZH4xUzgDrhxI5ESOkG3p1v00TlKMt4a8qe/+kDCrGLjn6cQDd7UrscV/TahI 4CiFbNy/5Db1J+QG0WlZU4LarcipDl+LjOgC4jpLqDVCUUwl0rY9PehVnm/oNhYvu3+2 6sbvR++P+ogDcWfhSOtghDu2fPGfplepNd++qURpkZ2kh4lBMbkTlmSMsSY8EqbPv/cz y9jZqsa026bquoNkQ8U2gxC5Q5xk3bdnPNI6yaEzFcIDpoUCPYuT3SxKo2wxJbQb+m7u R8BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789658719; x=1790263519; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=XaaG9kQMPrqSpcZJreTasVAHAtAhXdOZx6qidBNV3Yk=; b=W1UKYVl/qeth8Whw5CPBoIFJZ/6sOHfqohOn67fccR5GfVU2BOJmF69n7pYbQwWiNn ESXGLGQjGwdcxrFJocEN+ZxMOn4mf/j/nxpzMfu755+XU6W1xRecVzfwsohwxX8bg/d8 sanbEUeFeGEAq+fyUCT9tN/PiHjpVOM7LwqcJB88x6TSl4zwjCmj3xaWFhOrBhMz5msJ EZ9IAwLPZtTIDWezXdeey1mdOfBUBEEA9AFboiSFxfVGLgqL+ZVhqnP3UaSoQYL+v6Cj 2D4Sex4WwR59s1U/EMmzsUKAQ0MZ4dV4haVIoALA3DMDn7582bGEihzE51uhneNoqdB9 ydxQ== X-Forwarded-Encrypted: i=1; AKwUvBxZcOfsU6dkmD2lbIvxKeuFdvw4fBwNLPmh7oQ7DhkdcjVDSDeyaRlSsddjTd8JaGWeJAAuA1ClbyXnL/8=@vger.kernel.org X-Gm-Message-State: AFuF++kJ5aQ8PX6wuGm6r3fb7pyEdsem9VLp7bbDA5uU7o3BorR7DtdJ KcdoYVdExlKlsm4YsbL3gp3509GLR2sSF+gbHaxZZCE/ZjGbtSq6/oIFJl1r+Z5rvRk= X-Gm-Gg: AYBFou3M8Ok1DcJ5rKWNDt5BbZgemwvEp3BS/yUNXA9X/bDCA0FwMTmLa5W/TOZBQrF SbhWWBSicRTyIYmOgxuorgOwwOxc2jltJcOgB4p/34qhAFEf5QbamoW0bjJry3H9pi/n7t2CtkA 5ThcQGBBlfmTdqFODq3fFGF51s6dUZGDDX90fkOE7fqwwemt3dw1gOLWdkuRIN5bzmy8TIGIk1A uaXSSd95Y+sDk2EIxD8MGdut85ceVccMgC/fCz741zBMtAOaKJYp897be4h1vE621i0K/xcN1db AuH+O94wuNxphqRgGdeoPx5XKhfE/SP28FED5yhHYr91mSemugGR6uPbaw5rH3u1hH0JEJDEgSH RPbdWRmnzusjCN/kg6WsyTsq69z3Zb51CSmyMw9M4zVGtkVTtfvgHXa6FgcHD/0juLYzcph18q4 drSy19vr/5W/gJLaBUJqn3zYuLF3WkY299JFarz4xKgQyQ9RJoevTTfCkRIi6KzTMUbAK1iS8Ry DgHz97mLw8= X-Received: by 2002:a17:907:d642:b0:c25:8c74:71e6 with SMTP id a640c23a62f3a-c29e529041dmr506795166b.10.1789658719047; Thu, 17 Sep 2026 08:25:19 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c29de48755asm310587366b.24.2026.09.17.08.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 08:25:18 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 16:25:10 +0100 Subject: [PATCH v19 5/5] media: qcom: camss: Use data-lanes starting at 1 for new CSIPHY mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-5-21ad8a76e941@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v19-0-21ad8a76e941@linaro.org> To: Bjorn Andersson , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robert Foss , Todor Tomov , Mauro Carvalho Chehab , Konrad Dybcio , Vladimir Zapolskiy , Bryan O'Donoghue , Loic Poulain , Vinod Koul , Neil Armstrong , Greg Kroah-Hartman , Kishon Vijay Abraham I , Felipe Balbi , Manivannan Sadhasivam Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-phy@lists.infradead.org, Bryan O'Donoghue , Krzysztof Kozlowski X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3096; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=nAvKHTAAv3bLPDa8RtV69vy9lxOAzsfXW/WIHWa05a0=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqrAZVFsIMW2/vGXd4QQ7KAOZgAqwx0MFGvBcs0 hrm5SKiqNyJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqwGVQAKCRAicTuzoY3I OuPSD/0TKFuTYyRebGjbH7JeKR3zECbg6HM7ernZRFsj1tVkcH4V/eU3Lv4JMGpoj0aLtJpudEM nCbrlMuFKo5mhKevNWiGNTh1GUS4fsz6niVb0xPL5gtjDG/SFD+HYzQ88LIhNWkYd6GCDX05lj9 XqEPteTHrJeNN0wTa+Ohh9ZKB/ts7OfpbCViNa2/K1R0dVcSeBja9Fc3uw8FSW+UaTFeMKpLSW4 mQ+c6DvRZYiwzJX4fqenF1o2ccpAgULopn1zlp8iJEvJrtoK7h+4IOCumq3Z6+RV1UIOtcN5LBR Ov3vj8BbN4hkfcLYXSbE8d7yznJ4CYH2YxWfz4Zi0Jj35Vkkco8fCypyAmo9upvprKrrCAjoT79 SEpis1Bl6+0H1vnfBrmA1tssIga62V8L17p5in8BnDyycxGqFU/Bf2Nr60dGjZYFRlbouTffSGw l4l3XfiP0tWfOE52jXClgAGguPNPlmczmDKGyfly/D6giSYv0wPgFN64Ek7WAcu8/1Dez1Vyz+l Qnmm0O6+GCV+4sxywa4bIUdlRpCy7iBAQisalkJataEzrWhKeiJunIihGNvd6vJJnY3EoRU7EeD 02xc2kjaUjigbJNUvYvR80UIes2IfgXg8nLsjLJ54rdk47jUcEApzhHcRCvTZ1WoT4vwdF0M0tH T8OmLmEVh8mEI6g== X-Developer-Key: i=bryan.odonoghue@linaro.org; a=openpgp; fpr=E693FB2AABA36DE117AB6FB422713BB3A18DC83A Introducing a dedicated CSIPHY driver community feedback was both to move to data-lanes starting at index 1 on the PHY side and also to match that indexing scheme in the CSI decoder - CSID. CSID consumes the data-lanes property to determine which CSID lanes to switch on. For indexes starting at 1 we need to amend the logic somewhere. The PHY side code normalises the input data to register level meanings so, replicate that logic on the CSID side. Introduce a simple flag to differentiate between legacy indexing @ 0 and new indexing @ 1. Existing bindings are not affected. Reviewed-by: Loic Poulain Signed-off-by: Bryan O'Donoghue Tested-by: Oleg Keri # Lenovo Yoga Slim 7x Gen 11 (Glym= ur) --- drivers/media/platform/qcom/camss/camss-csiphy.h | 1 + drivers/media/platform/qcom/camss/camss.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h b/drivers/med= ia/platform/qcom/camss/camss-csiphy.h index 7a357044b9fdb..8c3319f2ca1cf 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy.h +++ b/drivers/media/platform/qcom/camss/camss-csiphy.h @@ -21,6 +21,7 @@ #define MSM_CSIPHY_PAD_SINK 0 #define MSM_CSIPHY_PAD_SRC 1 #define MSM_CSIPHY_PADS_NUM 2 +#define MSM_CSIPHY_MAX_DATA_LANE 4 =20 #define CSIPHY_GRP_ID 1 =20 diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/plat= form/qcom/camss/camss.c index 84097d82d99c9..6f58e729eaceb 100644 --- a/drivers/media/platform/qcom/camss/camss.c +++ b/drivers/media/platform/qcom/camss/camss.c @@ -4742,7 +4742,8 @@ static const struct parent_dev_ops vfe_parent_dev_ops= =3D { */ static int camss_parse_endpoint_node(struct device *dev, struct fwnode_handle *ep, - struct camss_async_subdev *csd) + struct camss_async_subdev *csd, + u8 lane_base) { struct csiphy_lanes_cfg *lncfg =3D &csd->interface.csi2.lane_cfg; struct v4l2_mbus_config_mipi_csi2 *mipi_csi2; @@ -4777,7 +4778,14 @@ static int camss_parse_endpoint_node(struct device *= dev, return -ENOMEM; =20 for (i =3D 0; i < lncfg->num_data; i++) { - lncfg->data[i].pos =3D mipi_csi2->data_lanes[i]; + u8 lane =3D mipi_csi2->data_lanes[i]; + + if (lane < lane_base || lane - lane_base >=3D MSM_CSIPHY_MAX_DATA_LANE) { + dev_err(dev, "invalid data-lane %u\n", lane); + return -EINVAL; + } + + lncfg->data[i].pos =3D mipi_csi2->data_lanes[i] - lane_base; lncfg->data[i].pol =3D mipi_csi2->lane_polarities[i + 1]; } =20 @@ -4794,6 +4802,7 @@ static int camss_parse_ports(struct camss *camss) { struct device *dev =3D camss->dev; struct fwnode_handle *fwnode =3D dev_fwnode(dev), *ep; + u8 lane_base =3D camss->legacy_phy ? 0 : 1; int ret; =20 fwnode_graph_for_each_endpoint(fwnode, ep) { @@ -4841,7 +4850,7 @@ static int camss_parse_ports(struct camss *camss) goto err_cleanup; } =20 - ret =3D camss_parse_endpoint_node(dev, ep, csd); + ret =3D camss_parse_endpoint_node(dev, ep, csd, lane_base); if (ret < 0) goto err_cleanup; } --=20 2.55.0