From nobody Sat Sep 26 01:06:25 2026 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 4EE463C37A5 for ; Sun, 6 Sep 2026 14:17:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704240; cv=none; b=MuL63ODate7HX4MgPp/SVfTx7p5Lklb6JOZu9kZ+vvxmNgYIFXw6V8yWW6Uy6ZBrb3COmjZEZwMuRGCKFOOzbK0UBqOXjdzAucFj2OplfpqxcZVeMoLzs5o1pLMyKaj0B6kEqMsDex8wFue8DnJtT91VSCiYLERYH88c22nrgU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704240; c=relaxed/simple; bh=MtIxUv1HUhphqto5paraCNIhe7tNRBGeSF/voPqNm34=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VJZ3WvUFFOp0e8fhtyKr5TnVgWeEnSKmDlYHXdxTKHzhAwvp0jz0qERKfwEvmHTy95LUWSfC8vRnd2hF97UP+7Y1wRdnysVdzLFc/PfvNLGwc3MupWV/v6YetetED4dUPh6v8FEprsShacYyckwUUQNidEAY+tF+elX3toUSpe8= 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=ocTCpsOd; arc=none smtp.client-ip=209.85.221.48 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="ocTCpsOd" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-485850cbac3so1600029f8f.3 for ; Sun, 06 Sep 2026 07:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788704236; x=1789309036; 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=OZO6dxofZbAitz209jLurPVDhx0uGUtYXwmfwELJ9t4=; b=ocTCpsOdKEaX1m0bVB3mFuD3pNGW8tGTfzKLuY0p8ZY+TifFYfQ9wN68ZvXMM57Egh 7EFs59t7SXk8zJelVjY2KHNYV/GXH6QYuPkdojsjBiX+Xql64hJvE8X1u9SwYLUvdKow /p++jFhYKFVo4Rxtl24lIPioiiaaTqGpP9/8hgAkOoRqLdjGvK9DgY2+61ZZWH0QqjKA 74uiHYf2d+70gtdVLgsAn7vpes/XZHHWzwdgJvK/XPQlovN9GqhdZpj6//0m43wAMl9F PpbgAyPYt/HLACjfGJxua7Y9HcwbGXuHK3qArvW5ShI72IoMS5YZ1L8UIta8R+E9Vp4n SVSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788704236; x=1789309036; 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=OZO6dxofZbAitz209jLurPVDhx0uGUtYXwmfwELJ9t4=; b=f/LYqH3wzOrgrjFPmuIxhmZgVv5iHRNFyDvnZu6/v8Uaem+lCZnUyBGbhVm2hyc3EV 7ZfXjiJh41DtqgNz73wuYipZhHvccXxc/eZP2xv9H+DGaVLezqZUkI4C5jZMOsn4/hHn zB7xsIkHSJXWk4MpbL87oQpahZjxvaGhdFnZwLtvQTAYiV5PnW2IT1fjMNboyj7BxJAg oMy28sHS9sSxOhunfBC2ybvdrD5OZYibeAEX0eej5u2mi8NmlbYdB7c+tGxaduZBFhZP nNefL84v659QGRP3cqyIs6Hmw/FOYnvjIVs2okB4bOTOcDBzU2gfhfAoZ4EP747Yt+kY B8Bw== X-Forwarded-Encrypted: i=1; AKwUvBzY1Fy0E6ub5Dq8GVBtusAQHHNIshnl/7ip2qtoIbzAlLlQFFGR0KnrrrJoq0h3yFQAOezQLfABNNzO9Qg=@vger.kernel.org X-Gm-Message-State: AFuF++mETAAax1ZSolZAjLG9jtHCJpesIStzEn2EoQCZeym6ECzDRvcN dZYOx9Bg5bU32LHEVL8fDQPJUWDGxuKJwkiKKdSF/dTLu0dcK0gxts3l+dNRi6ViaYY= X-Gm-Gg: AYBFou2lw+nnV8wyWpZtvo/IBqtOncRFrPCavGomGS7lapb7cDnIA7dVASLuTV+yeOY ByVqUcHNkQ5XOhYx6+bWVjwNRZMkiSisLjIBCOAE8Joue0RKSjyLXirMUdHfxwCadkQrKgjtrlq lobJEnXhSQqrl58+L2T+qtRlYu05iCR3dUBs1YXRmqstSFEYGygxkKZoLj0zpB8l6ukjw7mNb3K I12YM9Hthlo2r+ndwabjhuSSyrr1Z2FyXBSEWKnYXhqxjvdLvBPURP6cQVkk7AXT7+WMzH6Lmlo qscryIk2e2vUH3pWOBp9l0EQV0A+1/rHRmfBqoniD3/G9wyxThHz8/DTCCGx1EXVECNqKkmzkva p31htxzYuVDsE1tMpaZkby8OmNwzrsVMDMnsHMzrpEsMM07tntWnqZqEkCOxBO5ul33+57NiVKH 0JHUm6DzQBv/c6D3uGImauxKWij3HgMAz6TJ7/KvWtl6BRpQpC35lycIX+iIsvBFpcg3LuR4K8a I2ilFM5znU= X-Received: by 2002:a05:6000:4694:b0:482:ee81:f0ca with SMTP id ffacd0b85a97d-485872a56e6mr16211183f8f.12.1788704236345; Sun, 06 Sep 2026 07:17:16 -0700 (PDT) Received: from [192.168.0.35] ([109.76.250.151]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48588390e30sm21669763f8f.7.2026.09.06.07.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 07:17:15 -0700 (PDT) From: Bryan O'Donoghue Date: Sun, 06 Sep 2026 15:17:05 +0100 Subject: [PATCH v17 1/5] phy: core: Fix use-after-free in phy_get paths 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: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-1-e2197a3e2551@linaro.org> References: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@linaro.org> In-Reply-To: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@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 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 X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5297; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=MtIxUv1HUhphqto5paraCNIhe7tNRBGeSF/voPqNm34=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqnXXnNTbjHP1icmE8CNbsM2qqgpcwLeDli3+4S jx/nJgd6m6JAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCap115wAKCRAicTuzoY3I OsvCD/9XaIr+mf2+5wtcbGX1M8ZayA8JGUaFMtEP5bzX9qb6j99iLte9gvMMF+ng+mVpDDlMXlq F4viiBVP7DRZ6PFDURdFYdvVjixU5+cqqS6IL0PYo5MVwAYaofA3xmhVrWGtSfZbi7crF4ak9x/ OMDSglf2fIxnav+lOrXGatz0SwtavCSwLe/JnySXNq3foHMiiIUXFrtqYSyNk8nR9L/sv9onkaG aEQB5Oq1mTbptQjHngGnbB0aWpH76u0KRxZbEiD99it5nmT1JJVx1rDt9ht5NhgtJ/BHfj0cs+a ksTGZzSYe7theqmfYeBr5gkSYezPBTksdCd1Hc1Tp32F5BZ2SmQRyHhYRLOPb17m/u6zZ4g/ff8 0bObPz+KXCW8z1PNZG6DNuzcmzpaQB20P97OSpFzNs/6KGqrXqq/4W2PS6WFT0P9J6pKWiDqW2C 9llL0FlhKe2AYv3xY7mBvxhNOt1J2Vx+auz0sWJyzTA/P0cbVFiwyzHN643hGh3rC5QuQDCMl5S Z4ADJmtDiNi3G+E9t01e51ROIAOSuFD8kKemoPUaFnJW5G1wjSG16lvFf/PdH8R8ESa24UOloMo hl3hNZ30QIYsFPZ723dX78PvOZnY7GNnENHKxqKo0lNzGgbkxv3001jqrFWFXS46T7QJcviNrKd k5PA22ShQ8STAGQ== 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 Signed-off-by: Bryan O'Donoghue Reviewed-by: Manivannan Sadhasivam --- 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 Sat Sep 26 01:06:25 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 276083D9DDF for ; Sun, 6 Sep 2026 14:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704242; cv=none; b=ThW92+QS5ZaykBGlfdALI48xc8pzvi+8VmQgDPgsY7q7KN9mIxG/ywKR/jxwePcnCGQZuTKh+iUbzWk9wuV/Arew4fl6xYobSLPu9IZ/wiXqGtFKmdhoUBS6YxGkiH3H2pskr0GYBv1uMLQaMUr79C8dpfwIIRyZoxglGcPw684= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704242; c=relaxed/simple; bh=jvWI5bCo2G0nPMiyIWWUCCvc8PV85ddqSgmXfNNkRqI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VRfILe8weAqHia+i2ltyQaSnTfdiHnj/nx3kIOwpNSXZE3nXKBJCxUfsDxIeWDnsZJhADMEhBHchSzE2UnrG1WLxrUfOyEtwhQ+eqZWc+e2h3F+kAxY0OilCDOCqharRMFeKNibQN6OyuR49pXpID8WibPze95K2alc1cReQI74= 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=ejA8hSTa; arc=none smtp.client-ip=209.85.221.46 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="ejA8hSTa" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-482dd6ee390so2940938f8f.3 for ; Sun, 06 Sep 2026 07:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788704238; x=1789309038; 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=P6nCQrtjn5sjZ36INdWU9AmImwt4exmEpBcYwRBKS5A=; b=ejA8hSTa496+Gf3ZmfZYiLbruB9/3+Zfjhl/1guGm185otDrSDZCAfjWawM9VZ+zcR oq3Kk0fvViUbzMDNQC9f8gdvmk7nmUPfmbkvhKb7/Ka7F82g2mhx6nXzuGnOQIZLHgGB BmoJ7Xbh34RrQyTPs5dH6X6TtHzNJ7Rswjii6yLHb+C5o6XMlF5i3FWIYCytMsvzFfLB kH1pofXZYECXUTdNvpyRwf4OhawWlVGQcl0iw65vGoOe30M80DH62wx/OGJTzFWg3qZz 5qCdxZoBtYOSGIR9dx8JSswgXIc8ES96N8f57axgYc6EgV2MdLczRIlhSi4CrFY6tMl2 dp2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788704238; x=1789309038; 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=P6nCQrtjn5sjZ36INdWU9AmImwt4exmEpBcYwRBKS5A=; b=AR94wsOjILbJGln5mdrpCXyM/gDl62laxOknv3mMAUURbZe6C+y9Xktg7YBvx4WGoe zlCj5/B0MKXYTD1uY2z+eVDenBf58Mpuf4+i28trTXU3GwdR2gP5laQuSs0wWI4H88Pb k5NdUujkMD2/IeKamMS6snNB6M9RQ1soumbLYtsulQ3PTCsZzW76/s1Mkxlu52wppe/B 76Gcb7wLR2DeaUf9Bmyb0hePDz2QoODf38z9H9IQfsYLj9AQI/lCnqZIcQ3ii9CFE9av iFzOWClL6EWTYr059EeEptBjOAnHA5O+vV5hOmaKd++rIuh20ASnkvpco65dYraGmm/j YtiQ== X-Forwarded-Encrypted: i=1; AKwUvBxzyWX+/LckBn1L+rDWxG7ZbU7NNx3xgRoB8LwN2LeqMpqnwE3FNHDj/REuE4OWFX84TCeKTRy2fsrQ2PU=@vger.kernel.org X-Gm-Message-State: AFuF++nzuvE8x2cvK8xmuxUxSPRx4smdqiFqktL+I9TUVorpaKt7iPIi 1aPhwPNliRU0HU3jdk+9pKBZCnajAnIW9Xq7tQyYrNH7XBqf0+/W/QLXUBZklueSErU= X-Gm-Gg: AYBFou0+TEXRnDyDTEbuxE9xw3M2Oa3iZQG1K8JOWW0JQDZaLID/vnJHKe8w9pv00d7 nFcnVKOqPuPNDuItXNP7Q7HEJnga06tq/4S/o5cqy28FudJ6sh3oac3NvOHblnPaV+Ckny/FlVJ LskHwDP/A+ve33SIx+L1JadlSyVdfg8HxO7I0/ZVr0exu++o/v3Gz/G1T3GJIcFE3LtQy3n5COt WxOl/Yd1oLafWDND+OYdEy1JkD0rvGn9yXzeV/m4IYPon7d+D24gGDcpz4sbb/wlQHsqmfhdnYz zsMv6zHtiqZka1V+qpHhamWtsjWs5VSmOf1aIWZFhLiVZSXP17Fd0jeWLu+IE9EOqNnjU6H5dIH CBz5ZNQxmY1gtVOArYtRP5dBF2l3Qfx449CWwydoldbtFCdDdKFfn+P7F4SXURXZ5IxBIQYIIRJ goU6cHyLhCRWjYc1jYlJ28Cx/6VBIA5E4yCOIg1QctyiBqLAuFjRAuDuHBuv0rchYotEBrBgQR X-Received: by 2002:a05:6000:288e:b0:485:8c16:a33f with SMTP id ffacd0b85a97d-4858c16a5d0mr15303316f8f.52.1788704237969; Sun, 06 Sep 2026 07:17:17 -0700 (PDT) Received: from [192.168.0.35] ([109.76.250.151]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48588390e30sm21669763f8f.7.2026.09.06.07.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 07:17:17 -0700 (PDT) From: Bryan O'Donoghue Date: Sun, 06 Sep 2026 15:17:06 +0100 Subject: [PATCH v17 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: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-2-e2197a3e2551@linaro.org> References: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@linaro.org> In-Reply-To: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@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 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=5277; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=jvWI5bCo2G0nPMiyIWWUCCvc8PV85ddqSgmXfNNkRqI=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqnXXnDSGHKwKTESqqDCOzytTAZZJRnV69xpAvH JPy2g1Mp3CJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCap115wAKCRAicTuzoY3I OphMD/0QQhIpf3hL1zoUSontuG9Asjf87QOcmpl33UcLPb/2dC+pgdjGNqTuw4/BVYHdyyVmmhs tI7fOu1gmTrHTFsKb4Soyx1SNf8MRPBLIYDnUMOJqwOtPkWna6chShd/S5JXAwUCWp+XN+QbbNO ToDneWwCAEw5J013xX9sdunn6QeI3RZcDzOYYDLUAhk/Mr+q4rNlV1uVnLVkMPJoVmrsEEoq+Zu UQcN4V4RwyKb8tN6HkcYtnie6YEvuuAfTT7P7O5zg0uAUGyFLj7ToF2wgTYu6t3VsjaCjdHpkOX AULqXQ7aUSxqfmWUMdytonNfm4gSSjKtMhnW9YPM5DDe3O1DxuOhoB1wHILuAUURy59tIOfrgdA RGr2yg1yB2Igz4PPrZGgJrfHFRKzEqixnU6L1d2RUbpBQpgZie9VKn4Hjk4grMq1oFUL9ZgavwQ gaeM3OipCV+Ziw8U+LuPWY23LzqI5b7uLwHr3Z4toV40P0kn0+5rljJsCihkeAlgZWXiAhV/v+q 5HTVZ1A4EKKZLJUo0RfRlOu791SODL+bwM4neUCs+SPNW6fBLHYoyz9wkBnKfHT2vzZ2MSfiD3k g6JLkChI7RqSAgNDasCJ3ZmBd9nWV/pXKYmjMv6wZl0r+aKPzChhX09eZOJ9pi7k12bNfiE89Ks 35FPHPmWjhZLygA== 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. Signed-off-by: Bryan O'Donoghue --- drivers/phy/phy-core.c | 95 +++++++++++++++++++++++++++++++++++++--------= ---- include/linux/phy/phy.h | 6 ++++ 2 files changed, 78 insertions(+), 23 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 89addd732bff3..490a7cde6d40a 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -606,22 +606,51 @@ 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 * @index: the index of the phy * - * Returns the phy associated with the given phandle value, - * after getting a refcount to it or -ENODEV if there is no such phy or - * -EPROBE_DEFER if there is a phandle to the phy, but the device is - * not yet loaded. This function uses of_xlate call back function provided - * while registering the phy_provider to find the phy instance. + * Returns the phy associated with the given phandle value after getting + * a refcount to it; -ENODEV if there is no such phy or the phy is + * disabled; -EPROBE_DEFER if the phy provider is not yet available. */ 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 +666,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 +1015,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 Sat Sep 26 01:06:25 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 4CF443D9534 for ; Sun, 6 Sep 2026 14:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704244; cv=none; b=Jyt7w4NNP5HTAmQ7Q5tN8DjtlgPxdEeIixjSxG6zekPtnWILV76dzq1XjcCdodSqMWtR5V0JUgXoyXhN5AJUd7L50YrecrJcJC0eHY0IgVjLP2QWTm3Hgim8P+VFORbQIIG1Us3uRDklS17D+CqIuzMMvJ0nNoE6JnO1Iufc0aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704244; c=relaxed/simple; bh=ov6l6XYXYWQFGwdR6skU1nY1vxsBWDotX7Kg0ih6rxA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ixgkMwfEI3PUqNn6jNdXF7geXk/bDkFWB3I1Af78hIt4waTaVDGrHHF+jUUC3kBxPSQDAzvbj4JY673MQeYIMchJEhQCGEfy30Wok0eDw5DvurwwqDl4ONj/GoRfSsYrbGY45NMptUfaOT5Ui0dUtCU+SkkWhICxEWHEpobaKdQ= 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=d/y6WZcI; arc=none smtp.client-ip=209.85.221.47 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="d/y6WZcI" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-482f2ee53e7so1822597f8f.1 for ; Sun, 06 Sep 2026 07:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788704239; x=1789309039; 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=+LoCl+EbBl/1yupzEbeoWPgLAsEGydOXRIOMMFAJTXk=; b=d/y6WZcIZR7usfqSr27rbLLfe/LRprr1YhIZbvC3gEDrRV16wyqieeiOMUFC0tTB6t wyVIWl4QtgvHQSTv5dBwOcYubflL9IY5uQ+H7rBh+F/DmfWbIR7tzlhcK7126hRMiV6s b7QxnEA9wrGu/lXLpZLAI+9/FL3mJn2xS228XtychbRJAa9pO1FFoMUwVD+C6au7bcFZ RMcQVPmEWfI3CKdLhfIc8kkvVObGUXkkxKfbzfTRO5eA0ltXwDPVI5XO3W7ia7onguk/ c7u0vX2Q8XBSy0qTuEHh0vXLcH4msO5rTAm/7oVowzqMQpUL8mN0pyXHcuCEaaPvINvA 2XoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788704239; x=1789309039; 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=+LoCl+EbBl/1yupzEbeoWPgLAsEGydOXRIOMMFAJTXk=; b=phIa87dDN4+/qPuZgDZNMk4eBHWcSmSvSEm2mUOhLyrIGOh5vTHfHhD4kUXii008Cr 26DbBNX3Ztf41sUYcBCwZkD6woFDPef5Dv7CCKoy9MrbGMTu2TUQfAARb0jV8Weat7GE 8bUvnKMAtOifFgQF3fccio7VRG/7yDlH/5AWrxoo5PftqRBuM3f59R2SLXsc4/pHm9iP Jj+nrz/pJkgJSNz4DiL82RiH1f5VWl3LEPpVu8LbOEc6xhYDs/r7GdR87nzgZS0JPjcl nN2yCGV+2dQZ1YVDoo8qdf8X/Fdz0ObDHxsVgqEXCceRzZ8t6LavK7htsDkh4H+dKq1e pIEA== X-Forwarded-Encrypted: i=1; AKwUvBzgyOWJt82HW3GObhFw0xs81A8LqGDyukOWGfJNwMhp4WCpAV3FoyWsMLJDVZYJYsNtciTwqdAk61mwiXg=@vger.kernel.org X-Gm-Message-State: AFuF++kRR+TiUItebbV1nDIyu1H22enbaYMjVgdocM6xjW/+Vrto0G6i KfaDhDUA7iZmK7KutA0t9LdPyZ/RT8YJhQ4eQ0TjBu9/CdbbkFGtrqdwf3YxFza8/MI= X-Gm-Gg: AYBFou3DoVyjoLWeb/2Ut7PGDq9QSaJSq2JPgJkzUv3GG41hP4XcTYLw5/wabB1/Gnd pwNhft3cB6QzdDUgsjqY8cA502Hb2noxx8GL8Pusm4vic439znl274hgJo50/zCFBo5EAFnUCBG z55i5wEV0a++lgyNsTUTij+J56MxwSo/l9IyMnxqtjKdpf7gsRYxc0cv187uiyq5oZw4m+q5DYv MrkngY/TkgQYPlCW3e8Hr4VfubCQafuKFC733j7cImSry3C9/TAbttk8isQnNh5xj8IfxOWrMFz 0JloGoT3iw8OMHI3dj0nDW38lklRTrnFoCRpMGNDaSOlxei9Y/GL64E/wgmnT4xuJdheDj6aOwb xdLMatj9xw3BeiCF88EiFekjTDV5cr5DzDImaU4HWdF/3yBqF8KfWkNSniHKS3ZZr6/ayg/RfYV 7PQdjwIrShS4bCD0omPZ7L1yupYfvepMDIE/GxTsd6Ab7AuaFu+0GxOcQuvzayrEgY0Fam3hBRN Il/BAHIzxc= X-Received: by 2002:a05:6000:4694:b0:47f:80d1:be0a with SMTP id ffacd0b85a97d-485872a0086mr16514274f8f.14.1788704239558; Sun, 06 Sep 2026 07:17:19 -0700 (PDT) Received: from [192.168.0.35] ([109.76.250.151]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48588390e30sm21669763f8f.7.2026.09.06.07.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 07:17:19 -0700 (PDT) From: Bryan O'Donoghue Date: Sun, 06 Sep 2026 15:17:07 +0100 Subject: [PATCH v17 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: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-3-e2197a3e2551@linaro.org> References: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@linaro.org> In-Reply-To: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@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 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=2684; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=ov6l6XYXYWQFGwdR6skU1nY1vxsBWDotX7Kg0ih6rxA=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqnXXottT+aCtr6MjD/BRcmrfiSRLV+IZIlfnKt eM/LwhIIQ6JAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCap116AAKCRAicTuzoY3I OqjlD/9FVmT5Cto23JuMUI5C5HJFt91vUFg9Zlu/nuBlbEVbwyeOchh9fygRZ63v8J1w+phrKNZ U1vrhEqqV95TfHiXhYW6bTSjx4JmQSzoGI/GY/tl3Eabvj/cjuhVOhE7eKTqwAYGjr3m/gmGXVK Dy7Nb0X9mUU0DkA1rknz8ZVgegHUCMfTFFJ0h7vRNm3qJk/Cx32Hi7B4ZOWHK0SG3WQ5ct76vaH kZP6dva1Wy3zHWhK9/gXgoS/xcghdXMsgo1OvKbBVP3k1kZqm5kRBaq8CGbeh4LJ5zIlzPiR6Ij LPcW29TiYYd5V4zhG49+JFaEGBMhidSCqTnrMijltFqT1zC5OX8I7hTCgijaQNSIqHTa8S46CaA zAvmk/Nvrb9Gv2ZKqL/kyMpchLuYc3H8HUKZQNq+Yl/xqqVIZmNrzFx2YnMBIW+M/ggpEdue+4t vLHQDhuGrh1XLpj3Yp+6jdYx4VIBbrzcR9HZi1aXWR1WAlfMm+hMLtuiSOxqHJLk7tVGSMWkWE+ ddEMRnZ9ER1ulWtGeQOdzPjou1oWIvlesIN/1SoY/LzApIKsMFi7da9zizDieSeU7tUMQAtYT9r Zg8lkd487QQq994MfGnw/W9S85JPTWXYok6UjI/tHyxjc6lDbQE0kdn2JNEyWD9/pcYb8aC8xQr vYhRQI8R5DApCdA== 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. Signed-off-by: Bryan O'Donoghue Reviewed-by: Manivannan Sadhasivam --- 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 490a7cde6d40a..2e3581ecb42ee 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1050,6 +1050,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 Sat Sep 26 01:06:25 2026 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 08BF53DA7C3 for ; Sun, 6 Sep 2026 14:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704251; cv=none; b=XKIDi0vo6tKIA/wHE7lnk/D9NO3KInH4W48/Kxil/DcFqiBu7gQCsx442VhqwCjyL1KB/53CN1/xw/W8dkgTcplPsUGP8DdwKdmcJfjx/uD8944utrYKuiT+CBgs0wiAk+HGBSBdjBUeak0ur6RcWFihH7b6tEHJKjWty2Vrj3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704251; c=relaxed/simple; bh=YIJJdG8F7qvkpKCTmBVhA8FGxfejNI1V+jwzJ32M+4o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uTGvlxDWR3KzScxWkPZOrsOOH2dmBpiDS6jyJkgw1igX9dPKq1k0JSz/wzk78H9t8koaaElh2BlmpH4KjTuqSdRrMVQvTRCZKxxH+IfJ6nfHd8zIaOEtNWi3l2Q5XCEOxxAcAlq9/D6Tk0sp/uJK/Q+xSMAkTmdCAKX5xqkuYDM= 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=vIZzW7aN; arc=none smtp.client-ip=209.85.221.49 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="vIZzW7aN" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-485850cbac3so1600082f8f.3 for ; Sun, 06 Sep 2026 07:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788704241; x=1789309041; 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=SFRs5gGLiDPOnHZoeYS5F95xIoLCLe/yvxqAbvUutf4=; b=vIZzW7aNThFRdPh3iIyVCPTc9kEi6HkFo20/POmWYv5KswmgP+SG5+w/MnnwICs7qV swtpmFqTfRTlyGUlkVHioId5BxEDjzjabHZkcIwgB0F2pVAQGd/h1CkKE1WYYWoZ/t7u wdcE6E/QvLClnjoPFkiJ44KaTRUkNW/+RDjWbvwXGjJIdmvYvKFGYvxqdDn9u8EbpfPu NkYcQ9V82MdTMZHeS3QoLKOqs4KJ8jbdSOCDNmcniQSscVTob5EloUnmjT7W9YFT7NJd 856j3brZSKZKJg7mWxUnzSwM7DvbGFbiHqzBQKkTL4wMRhcv1g1MYmEcJ4ZvTVnQsB6R 69zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788704241; x=1789309041; 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=SFRs5gGLiDPOnHZoeYS5F95xIoLCLe/yvxqAbvUutf4=; b=Cqby+yX1vB8OF4HP/BgiH8YPHqb0G8/XUqGPqeTDf6TrjGvt0556yq98v60nKxUhSH pgwf5RsdUG46Jo4VngN498k/fFnpWGoVjq9msY4M3kAiChX9u8DHbJw8Tk48xeBhkdZG 3RcsWLcEkN4vZvOV5IaE0rDWphNC9tgM9+QJVqPNwJaFYBWw6G6/hr1adf+NwEEv96pM LeQ+F4XVKn/EJk31k/beVJHSdVAV+kUzObg+JH1owZ+HfT/hNOjrPp7siEmSjl2lKYlb BxSlRjwr9buNQXQmHEoxWCaRZrHKN3ZQKQ+op6ML13nV9qUDg5IJeD8/cxrtBJbPSBXX /o8g== X-Forwarded-Encrypted: i=1; AKwUvByGJA3VJIVdsCN++E/VFSrVMeR1MMIL8tZx2SAIQTtdrRpH5OPgCwNtXc4oSMc8JQVNis6ibdoVlmYwweg=@vger.kernel.org X-Gm-Message-State: AFuF++nEQqIjFlXGZoNNxhVD7kkuzb300IaS2qu4KEAJ2wcnKBAfukJ2 Yqqzu3KzNG7COXoXTfyBsXLULXKUkDFb35FUvRZO7A5+1WDPzBe/OVAP/ZE3zI0x67s= X-Gm-Gg: AYBFou02zz6xEi8HwnPz6K8KPdXrqZCau4IulXAgZ39FukbXKGeByE/8xKaOyuihBjs OiCNipvz93bja/qH//uX3ezR04HKiDz6RIiehrrj7Jfw+LjeFNs8E6+SUHkKhMDGrIkY8yoj8rM LdFC5EvCY8rULOW1sIaxsbRuxgkXPtYh5mp9S0x0ZxPx+BRg5aL2EqR569XLxzuulFpq162Ibs3 eJzY58MTvRA8EOu3ZzmsLNLKD1UCGBWIAbBNGMLAGcc3I3+FJPtmdG5HRZ0tW2wxNnixGAhi6m2 BZAIu/u4CE2d6LpS98agjMb3bIX5nSe9eP4OpHsZDsXZtqQyNsZe8gdHxR0kaTgpZhVsUcbOAOD dbP08Htmx847WostKUL9xQp+L4VMiynaNbhsuRfrRrF0SOgcTKUtBynpWb/cTtFfTHlwQlGLTuC u49T/aG9rYIY9BlMmB+N0oruMmWNeb+14xWnjEKiUHALS4KPEYlHyvTTHXtRGWr0yOBqTVijI0x A== X-Received: by 2002:a05:6000:2c11:b0:485:8c16:a34d with SMTP id ffacd0b85a97d-4858c16a841mr15860285f8f.37.1788704241137; Sun, 06 Sep 2026 07:17:21 -0700 (PDT) Received: from [192.168.0.35] ([109.76.250.151]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48588390e30sm21669763f8f.7.2026.09.06.07.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 07:17:20 -0700 (PDT) From: Bryan O'Donoghue Date: Sun, 06 Sep 2026 15:17:08 +0100 Subject: [PATCH v17 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: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-4-e2197a3e2551@linaro.org> References: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@linaro.org> In-Reply-To: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@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 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 , Nihal Kumar Gupta , Dmitry Baryshkov X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=17246; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=YIJJdG8F7qvkpKCTmBVhA8FGxfejNI1V+jwzJ32M+4o=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqnXXoW9IKvjK6Apo9Hkd8WvO8TkHdDRwDY0TBM 0b7HabJvMmJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCap116AAKCRAicTuzoY3I OnQiEACWnEcKd0JFehBfDSdDBB6c84jZDymOx5Cqa2r1omrITI9m7ihhcfR5waMn/C791Uun1p7 p60Mi1WvfEulNZSxIZTmFQxe/IjTKTts5KUZ6xzUh6JEhtHNWkIeefKmZIupfKsTQx0tNYn9mNH 3pHKIrLGBIIjEcEfqr+W1dsjVRadc3GNYchmHLAHK3q5CfHKJtZ11EwoEA3IbhROKacjSAIwk2D 3MVJjV2TWH7qPeTd9zDk0YekK8CP0dSwHKjhx7JgYMtu/I7sJaOgGejUYmqsp0o+S1aiQVdrUpi zrQFbLYboNWxmEYvAIeTAYTpnmHcquqqnalz+PaTKPjl4hKTGd66LlSgwuZcXGp3JwiVPtIcpRr MVRxSy32H/Wbnv94VyG4gD9gckx4mY85YvhUbHJmPIUsg6Rx8xoOWLuNpAZ9E2UnV4qxKRehe4u jvSOVS95c33OaWatsLVN0WHc/NwNgdt9MTcLRoTBNA2mOzF4mN69ck/QNfznNrXqt1rcUyOutxG 7cGHkiZeHyjQtfwCH0RnHdbviXxODST76XeRheme40cW1/qrhRxJoLyTDfFBqejP8gPHQe7aOQR NRwPyNtef4QhMKDnxf1+KhyL2sAyVO7BUuMMPrANSc1/gugssp63v77xd68sgsvg59IE0t77osa 9pUOWcM0DPBhxhQ== 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: Nihal Kumar Gupta Reviewed-by: Loic Poulain Reviewed-by: Dmitry Baryshkov Signed-off-by: Bryan O'Donoghue Acked-by: Manivannan Sadhasivam --- drivers/media/platform/qcom/camss/Kconfig | 1 + drivers/media/platform/qcom/camss/camss-csiphy.c | 177 +++++++++++++++++++= ++-- 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, 263 insertions(+), 31 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..e00748dd83b02 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,88 @@ 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 < 0) { + dev_err(dev, + "Cannot get CSI2 transmitter's link frequency\n"); + return -EINVAL; + } + + phy_mipi_dphy_get_default_config_for_hsclk(link_freq, num_lanes, dphy_cfg= ); + + phy_set_mode(csiphy->phy, PHY_MODE_MIPI_DPHY); + + 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 +651,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 +788,56 @@ 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); + + ret =3D phy_init(csiphy->phy); + if (ret) + dev_err(dev, "%s init fail %d\n", csiphy->name, ret); + +done: + return ret; +} + /* * csiphy_link_setup - Setup CSIPHY connections * @entity: Pointer to media entity structure @@ -743,8 +872,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 +891,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 +923,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", @@ -828,6 +971,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 Sat Sep 26 01:06:25 2026 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 861C03D9048 for ; Sun, 6 Sep 2026 14:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704251; cv=none; b=HHToFxgXxmhUQBgPM3gVdvp2oDrc5iHD8p9Dik7rDJXDoQnNakt+shZ9LHxr1mJx70dowMOlhQh8SUSBZgJlfbyUn8M7ab9nRGPlh6oigv4QY+D4NtuCDw1LbIv0TS1a0DpnD6JiY8ziJRcrN9+UVgEd9gX/Y2DBGc11QOQwHm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788704251; c=relaxed/simple; bh=4JOk2Hi8g7gu1SpQ/dGzbw1/zf+MVi4St5Xw4UG5IUU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dEdowl95Fmq72wrEj4P/QugoIflKv+So7Vqn//m0Ff+DvAyg6R5OafzooR//Goq3z1RCXhhThqhIO+lyzSLxwjVmI97nITAkzn4Jb+CMNgngiF91H9DZ62YomjKiJXzP7aaEHf55Eitv1C5DrY3rPS5gKPlCwwHHKldPXA2hdG4= 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=rHV+qfzM; arc=none smtp.client-ip=209.85.221.49 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="rHV+qfzM" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-48444ec4fe2so1476404f8f.0 for ; Sun, 06 Sep 2026 07:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788704243; x=1789309043; 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=3oY2AlOIEvJzDvrLKGXM3wmsBcdbDubrfZ+V9KSGxD4=; b=rHV+qfzM6Ex5+/1YtzNlXy84KOhH83kAxwgYicso5cwsacUJ2CJIpbGVKjSQ+sGakE 3jEuEKeGSyUP2nlxg0xzrN0nW2kp+1aqADj5vPN52MmRinSOUn8Eu5QDpyoaJ5K/7qTE rcdwg1j+rXJ+OEnK/ZnNjQpqjQo+yk6+zaKZSwtsFhdgAWWz04nuS0C8E8Fv6u/Zkhhw 1jKtivWHGR36eLkmn7PnvxvsmLdmT3yjpVOpSHo+FrB9UmvzQ1yCDELVDYjQb3+k/xkW JqG8+suf0zzF3UUCONpiFrW3wLqT10sNNI8NeNzOM8opwbMYhKpPA4Gw9eKpoFWcY8uB Wzgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788704243; x=1789309043; 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=3oY2AlOIEvJzDvrLKGXM3wmsBcdbDubrfZ+V9KSGxD4=; b=osPHfV9T/ZExSqrPPtYfidetPp74gajDUEpuVN7AvAicx98TsFNW4fHW91Tm1khtl9 vW1oQJLzyrV663my9q6DdQfTXhR977N0gkYNraIP2YxVtXbQOJO5NW0udFJsc0grPCAJ If2/4Ldcy6NLDDoyjyjxtg2OiCeX0duOI0H/witUSTtTTvsgRmekZKZXo3QiY5EWKPm2 6ACRrrr3m1ioe/DjeHsWSvELPM5o+0UGUkdRUoe0OPFC00X6/D5N3/4jRsRVLjJmfNJ8 KmVgQTtXFkWmBzDwtewZ0VRi/zbl4wIBJhakfQjyRn0GdOMEtwUZn+NaFE+11jKTZ7ct Sy9g== X-Forwarded-Encrypted: i=1; AKwUvBzVKe1m5hB1lSE09gl//nCMV7OB+Ww/B8Qnht250pHS3NbB2hBBwgXwbLNF98SW7TIp1aDYJ+iFqW/UzDw=@vger.kernel.org X-Gm-Message-State: AFuF++m583BmtdSpjr/X5BlHNjUBT2Atuj2Sy2n8O7Mygz6k3Bdz03Ep aCFmuQTxHNo5HCuOWs0OElie7wYBRfMl0RK9Ple5EwFi2mwEuXgUK0LKWb0c1ks/zNg= X-Gm-Gg: AYBFou2V3blFgdsWCL9kmyb26kj6ekyaKL0SUzyGIExdWIXzMZIvftoitONlhUFSb77 Pv9aMZuIyHReBdSI+M0EK+2UAC6egJfFSWjKz0kFZgpQm68Hc8TVH1Ot3jaPks4tG71MXqaNIEI y6sASzN41h3cKVDLUlaqvDfa6HP0ad7e9Tpt2qc9QjlD04lUBLjfSBQ9sZ/xbcIuFbQGJ7MLBIS NXIzhLSVWrG9vfGg83MWeTh1wUOVc17zM/1RCrreG1AFNZ/zQ5+k2ccFp6LIEhq4VUN8+uwXoXK DKZq4Xw0w1DkEU6LrFWervIw+UexD4J1A2yIliE4VP76EAcTWjnzzKRo6Eo/mfWJwy6VLl1unnu friQmECmWQoVG9d4oRAV+DKYi9qHXXh7t6WrfNVR4yb3v75xPxJ6I5TZjQNtle/KFmsBTcFej3J Q5Aj4NbTJqGW2HE5MFl857awJDO+C10e4nBpBWLoqiACAV4hj+tawuh3I4fFLy7FqyYuFcLK7h X-Received: by 2002:a5d:5f89:0:b0:485:892b:bdad with SMTP id ffacd0b85a97d-485892bbf0bmr30611491f8f.12.1788704242631; Sun, 06 Sep 2026 07:17:22 -0700 (PDT) Received: from [192.168.0.35] ([109.76.250.151]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48588390e30sm21669763f8f.7.2026.09.06.07.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 07:17:22 -0700 (PDT) From: Bryan O'Donoghue Date: Sun, 06 Sep 2026 15:17:09 +0100 Subject: [PATCH v17 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: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-5-e2197a3e2551@linaro.org> References: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@linaro.org> In-Reply-To: <20260906-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v17-0-e2197a3e2551@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 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=2510; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=4JOk2Hi8g7gu1SpQ/dGzbw1/zf+MVi4St5Xw4UG5IUU=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqnXXoH9VPldgdu7R1ntY6a2BIdl8cjC5uvSJAI TLXjIFNoaiJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCap116AAKCRAicTuzoY3I Otm0EAChJV802lFTATmtLqqDUMwtkzn6JIwJNVtgDDOK6aREDhOVcmip3ZYh8bAF5d1WuSfSHbe Dsrg4ph3lA4WWiMTOAaoo/MImXhCT6Uyd993lwMpk8nyupZexMkgACQgmoc1iNebBfnahDQp5zf AGhQpMY4ogelQd4ixACVio6KgYDPCiJdClpzJrMnEpN84s5+30REkkctniPbn4M9aNV4MLq3gNF hFVgL93xKjNLo3x6yt+D8/ipcjfVDq0SkNkmLoapn7qSb1pLABmaIh/vcTVyEqOIY1/+evNIYpe uXeZjoJ1n1UWRHLC1CchbcSkAMZV4donLKx99QudDtM6StHoKruvQWr9cD7VbJiIvhSIKwAzQXD OhTEAIR36NZG2baw1cFdu5GoxNek+gxs/qI24KtrUfOxw3JL93WDXoUtThv8orngxZnIL7Stpbg YrLqt+FE56bj7rhj/PaXY+h0uSDq0XzJEben2E6imV1xwlUsyAMXEpiq+aTCDlXkg8KKURrRANA aHm/p8AoSU73O+yeDgVrlOHTwzwSjr4Y5JRE7aJobvo/sv7inVbqdhuECuIlTCx8XA2zjVXtJS/ k+4SRthkoflOkR6zobNdiKLhIGC1de4brCoLaSPKYrQtkkQ9iK4MBTOsYHOI2kfDS7TD0CmyalK DVgZujw13DcEUlQ== 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. Signed-off-by: Bryan O'Donoghue Reviewed-by: Nihal Kumar Gupta Tested-by: Nihal Kumar Gupta # Glymur CRD --- drivers/media/platform/qcom/camss/camss.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/plat= form/qcom/camss/camss.c index 84097d82d99c9..07b3cddca5840 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 lncfg->num_data) { + 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