From nobody Fri Sep 25 02:45:56 2026 Received: from mail-ed2-f16.google.com (mail-ed2-f16.google.com [74.125.228.80]) (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 5BFE54D0CC5 for ; Thu, 17 Sep 2026 11:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.80 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643319; cv=none; b=CXqxXSYIjCKuussfMV9Wdw9YMB0ro0UMPSQrU5YWGppnS26MoH2p8sgE8eeFdrd6jmyvHD0PZae5ZrfWwWgmIeqOiH3j3YYYH5G67E6G/01rBPpn1kgCm3NFdi9i9tjfqlenB2G7zUI6rAKRdS/N/JEW9Mz/nzYDehms8A0TiyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643319; c=relaxed/simple; bh=d98IC8bz/qzZqOoRgoY7KC00p4aOgRN119tjHNyLlDk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gBMXRrvx3mLsfEVFvEp9AQE7TiAW10xvAaLMa5QkhTixr+mCe/WiD/db3CrjNd55Toe5kwZta2yAl6BRaa4ygAxPg+kYnTvnwtrFrHdzAmvjw63O6gK6jVovk1l1sArmBqbklhXSu+mW4Pt37BcdhzCgoGkYP33GMPnNVQVNv6E= 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=mzhzJXgc; arc=none smtp.client-ip=74.125.228.80 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="mzhzJXgc" Received: by mail-ed2-f16.google.com with SMTP id 4fb4d7f45d1cf-6a9984f9adcso1137461a12.0 for ; Thu, 17 Sep 2026 04:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789643284; x=1790248084; 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=mzhzJXgcirNjihwgMv3mQXjwIot6kr3xEn8JNpdZf/iX0LAOgbqikClznhFQI4JOUF K3Xagxbn7ww1Mh7feKXsj7ROfqYMj4X+jFTh9FVRIGCB+Ufj4aTnnvWTTC10ZdLe6mey wcJ0e/Vj8KLOGlrCRT5uxCiBX4S4cf4yOXinzo4X9DEmlpqLW2HzHYajm6zUBTrN/Lag UNtcrYSAU1ln+8CUV8EX7kMm7GxjYoAhcjBGax/pRFaYP9NDEqXxg855yGUhkHJZqvtT AC6Yt360wFN4SSv/m+WfxI+XrCaa+KVpL4MnZsKNEAuTLOYroeFXfwq2Qu+VxM5EhzEB IPfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789643284; x=1790248084; 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=Iqs7f13lEk4uktBrQnC5WYGKVoROLmK4sw9KWEmDZVhy9+wx1ysTnhbtVo1fEUHMCy qQ+Dl6fI+mEiGmNnQwCzS8yftOKCrTW9+CsrnqkSFWmrvlgMrslWt/DpbE0EisHHQxRD g687H+56f3uIp9XSiAE8UuZoarFfg4UTEQCVrLO81K/+8jpTNBxAMW28x7UYRsypHBv+ s1EjJj31IUAY/lO4QkXsp98HD1Z8ZWsUPih7RFAr5ex6mlOlcgVQ9hHdOaTMluEfFgMu +npY+wXiz85PefufwSdCnqlXw6ZTeEMql30A1UdW3BRQNy+QCrURJpgVdU9juJ0DkaIg HmTw== X-Forwarded-Encrypted: i=1; AKwUvBw2ac0ezWYRNouS50MccqM/JhlLCqxY+4eDXV2N9DXOW9X54703lrCuN6PgrKZWms5CaQblhtwlrLGLc2w=@vger.kernel.org X-Gm-Message-State: AFuF++kJ4t15u/eIVqb1DB548hrF2hFmPTbjMLewoEmT5+AW+GCNdgvr ancwmdAAa09KPfDsyEibuwELtHK7gtC16vZeITngTo7P92zdYUCZ/ycrZ8iUboYD+1E= X-Gm-Gg: AYBFou1s2TLh4QJn51EmKefo7AWWhBxxpOSeuIWNiAHgPA9SvAB9FWIH78GtKjFNZ0s nh39y3OOCE9AjWuFfuElqKI5/ZXLz6dNuZ1pt9UzUPr0JZ0duEvE/pA+QiOUnji/0tgToxFr6a2 p2I8u95//K/mTjMabALejkPjd5wkWYOnyoxwBXxSfpjQj3QHRVtuMM5IjoA/p9VFFZYB1BrcWRQ cnXEkv4BvcJs/XQaOhBaVNcxpL2kGglk0daeDwsCiJTkTxsfMszqPcJN9V5dy8c/q+66UmyFUDH AyvWGk/8Ksmz233r2nFgwcMwIJvIo+mULol6B7p0THEiItFWUkRaVtbnDbWKOt/kVbr1Q4w88Je fn2Ufr+btnZUurH0M/G/EFHXgKOy8KBCyWkaZwYGb8Z10bBk78JWxBLBEQa+2GN8qb2Kj+qyZu+ Z/83cLQjfYeY6BR8CXgonCNYpiajpQaG5XUfzQvT5xARfGDEnwMqZokBw6hZqyYeObZI4S4LJRY sepGYRfkQ== X-Received: by 2002:a05:6402:4143:b0:6a9:8db2:5c61 with SMTP id 4fb4d7f45d1cf-6aa224695ccmr4351003a12.45.1789643284160; Thu, 17 Sep 2026 04:08:04 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6aa1d27ad36sm3175656a12.21.2026.09.17.04.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 04:08:02 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 12:07:54 +0100 Subject: [PATCH v18 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-v18-1-f85c9103177e@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@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/ZANAwAKASJxO7Ohjcg6AcsmYgBqq8oMMJX8EVikfzcwZo+32PzQIvs5wQtUxfWdE sUxbNbKSIGJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqvKDAAKCRAicTuzoY3I Op4QEACLqBWFgsDynn7Sx8zizEGZQf0msF2clsc/4OOxnUZedrMbGoYJBncg5EFWGgmQYXHN/Tr q/EHXaU4yA1q+sE33FpsVL0vD+ZFX3B+qdFfPssZbjCJnosk+qr9oJU7z/EVFZ3iYKpT5Uw/yjk ibiwxeGZuHlHZKaI1/9hBJrBygc+MUj0ZeE/XFJk0p2oKE4+FRam7sQ4r6dObIacxQouRO4qria /e8EZYjMnX6ACat6MiUJP3Apl7aIAN02TlOMepauG5UEOS+4hZ8HW9vKdjr3WGmAR0g/R06L7AO czp5wzzNYL9ACJ9o9gPaL2CQ+aG10c7hrx0AWfFNzlvw9KQkM3lWdrki2nBxbqngh+JEDHOEHml iDHp/IoNzL18wP9iH2UsfanebC0m/MEdDLthbEEaFFE0elycfUzb4iFGqqKAswKZdhT+cLPl47g 6Ay6HJ4BGvh8aSccNrbqkYss0ePy2CfjIjPFntYzNL/F+747Uz8dgI0+nVAbXoCsckRj1jvWb6i QPkQp1eImIMQbE+qtRgLYuclBVvVNFPC0po9XO/O/b/k7TwdhAYuXzw2qG0H0AMBb4BE/+OijG1 MJKn28BoDey2+hDIsgC0ay24j6ahFK+OTRXQaGTg4xaHjBOk0kShV4taFFm1Nki8wUrFQKxjQA0 eETl4wv2NWaGDNQ== 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 --- 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:45:56 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 C9D6A4A689C for ; Thu, 17 Sep 2026 11:08:10 +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=1789643334; cv=none; b=swIf4TyYE8Aizq3nX/hb3p8j/WTh44iu97aC9AMR4JBIAMJKPJ19GJOO+MF5CbkOVoqxT4xUEctZY0DfOThch2SY4Wv7EvS07E0y3kVBrBGDfF6x3sHC4PfjDDr2ogTQMFO2amWoQA8zBS/IyaioKrwA5e4QYmzjDYLFHtEo6lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643334; c=relaxed/simple; bh=jvWI5bCo2G0nPMiyIWWUCCvc8PV85ddqSgmXfNNkRqI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RmdLnPvpWWBOzxJ2zflp0lWNLh56M+TyNppTFGI8sWe6WbindM+ZzjvxXUB6zYWkWppQacuuS9kJY2rpNgCH5iGhhWngHzUrM3C1in3KrV3k3sMJ10gWhivcTLOOxFO/bzM3dCLzeiIOBxSO1gl3EvA9DKDxRrDAyTkBd2X4tME= 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=amRZXAIM; 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="amRZXAIM" Received: by mail-ed2-f12.google.com with SMTP id 4fb4d7f45d1cf-6a60590a85cso1486116a12.0 for ; Thu, 17 Sep 2026 04:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789643286; x=1790248086; 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=amRZXAIM2HT6n1xYQ1g4xhnUXi9Nws/e3Mxr0J2muU6vHMAIT5rQyaKZcnM2Pa9j6r mOsNGj31vC+n1J8FTIXzknNGbzMBc4RSXa0Nn26p1WN/xBL1+E/BtpiVLPKGPRh532lR /0ZSEYNkiAczGgTazWsa0zYbA8b4QFf8CphcPBKsFAZJahyLOxg3H2qdxUq8+PTOY176 AcWYhL51xDPg19RwbGE2e/3L18li3sEH6y3MKnbogNN9mtjhjwd58qTax++a+ZpDFplP RiF8YaMXlwYs6T4zEs55yx1Pk9brItPSm/igptA7fD/2qqACLpVHPFKx56Ty18YemiEx kcew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789643286; x=1790248086; 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=1/6fbA2wd/8JLEVrp0W+D37sNtlbegX4VBLNSm7Y8yFvEpmEnLu7dtXxo5SmmE8Bfl Ma4FG4kY20KGN0sIuCkdP2V39ZtoH//hnEzxu5JYy4ZbvTVtQkSxOfqKnvc1EhgFa3B2 yS2jI3iMHaLNNjEBYtBvPWpAQcTE4ze3fK3cJFQzGzNJqLFhg34T1jME9tZypV8scMww gCKHhTsNGefiEf4X7+ocQ3+OGtZYzB8lCz2az/08kHQESOEgflolHG8/yF447jQQqTDb DGz+hP03aUNLXMmAYAIcAEFj19RJNXexqJFLVGKx1cWgXMEsOggTwa6yAmEKlh0tnxRH Pp+w== X-Forwarded-Encrypted: i=1; AKwUvBwTujDi2O4CU9kGZF5A3saqjk9hqUbzehb+U0T6xA1nTubJwx7pH8d3KCI3op1VqWyKqgofaO0UK6KQnJA=@vger.kernel.org X-Gm-Message-State: AFuF++nnH6NQFWW8BULR6g8P9vlGEYTHQs88gKy+QUQhhNMk1Z4rJuOz c3zg9dSvOKLg/fwXXnSZJKsjVOW+pFTn/uREWxfQVYgOzBJAU1s8s+LkxebszFK5ZAs= X-Gm-Gg: AYBFou0CcGSHCw/8gv2wlsSu6laGpLfnVlRj9wBu0DbBJERAoQxmVuJpEWjatIT82Qf nvlEb1aQ3COy0wOq2uyj2Vd+bb5MtRsaL0f99Mv4ZjfXLIDvZ4MFmd1SZjg69VBYYII2VsQZnGM 6nS7Gv9ShXojAustwNUDlVfCDwNYVih87dgmEG8r7SSoofDPcYJek/rO2uKwG0cOyXxt4jDE+qz aQjafz+EHsQnFYb1eSg/CcQynF2XtzjGB0v2BVuuEctXEJ+1DxRDXRphWvJT0rOB4SqKtD0esag U3gLHSEoZiAjvyDzRBFXv94uF9l7ZJ+gbtJT5fE5aUohusUaO2n4+Ik9T4hZBxe93N4ernypTvT cCoqMkD6mT66Zu/XCV5/xBdPhaTgDFSUGaaAHgmddwJp9PFcWfnAkUg31t+Fivq4206L5VrydtA Byr3WoTYU2mxj/owbSL6oFxbe7BX1aaPbCpuswFNg1SmUgF43b2/grAZY9LJfoap1pkDgALdmpZ PFtIY8zaPwi25Bw9Mxm X-Received: by 2002:a05:6402:4613:b0:6a9:8d5e:66a6 with SMTP id 4fb4d7f45d1cf-6aa22250e8emr3965332a12.11.1789643285855; Thu, 17 Sep 2026 04:08:05 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6aa1d27ad36sm3175656a12.21.2026.09.17.04.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 04:08:05 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 12:07:55 +0100 Subject: [PATCH v18 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-v18-2-f85c9103177e@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@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=5277; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=jvWI5bCo2G0nPMiyIWWUCCvc8PV85ddqSgmXfNNkRqI=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqq8oNQFwYjOrE5sJSPDVGnBsCu7pHv0Xs4Nip5 +q6A5L2XnSJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqvKDQAKCRAicTuzoY3I OoN/D/9/ujwtfypWaiH4Z1lIQEe5mE67i5ps3oTGkIyMPMGUlL1YT4d1xW65q1Hb8qHoTMqKOIY 7MB/6mlluGLLvEqx0lKoFOMUI6eklV7KSqaJbzQU071gtGJCXyxQ71IfPienvv2DovfDawKIQGV E5cWLUjeH1d/Jz7GwXQ7aXduTbbE6AvhJMFkLJ4IBJpMjspjPFgVzy08wnje3bdEzgpud0WvQah HZ05ort2X2ceV34Xq/ohdulHB2ePbsw0K/WGSw0XBjkwJJGrxIux31pJJezuqhJv3stLntTIgdi oVi0FSUTiHWtJqVeLZBJBpAS+uZUaYE04bO0tzluUFDG1Cl5OFmmjHYpBA4hIVYTJB0BNGB8eQr CCNps0y9bDpFf0ICj6O1Zg+whA1H7QTYlpP01ZBuxJg6Uvr+u78uol404/zLUU52PHL1Rgm1np1 P13peA4UH49/RzipVuUqda09koVEKMzn+MNt/U4JRZlYyfaqc082baNNyUErJrQVLfpZcLcDe/D G8XhN/sg9hZWojTgel2EECFFHQOuZMP3/IKT6d8vlrHP/M+sHe33x8ZV6tf74tPCrJS62A3wBe7 MDow1qYEbg6bd9QBTH1gXDyacLiZ2DaYS5EXTamnnWfZ+2bPCZ53K7lfrF8GUvQcvhNHzQrnJz6 fXC5li+1i8oILnA== 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 Reviewed-by: Neil Armstrong --- 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 Fri Sep 25 02:45:56 2026 Received: from mail-ed2-f31.google.com (mail-ed2-f31.google.com [74.125.228.95]) (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 AA0EF4D2EE6 for ; Thu, 17 Sep 2026 11:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.95 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643309; cv=none; b=mnKt8lhcU4EcC7jp6KzoMojxzgyDyOaac1nBMrxZpS0q3LbuQPJDkw4rRfyy7EYX6JxEc2/odYkvN3ZJAodX6KVrfM7WnmQkKGFwchO9qgQUT0HBQfg1VUlP6rJGnAJckNoPyDNcZ2pcPNLYgHao+hILp6gYWhB5NDeoxLWHVl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643309; c=relaxed/simple; bh=jZig0GPFi4JGT2mSmtHGaqcYKCoZ1vTJV6/UKomI3Ak=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K8ArZpdV3oFpljorXScZk7buLNzTcXm1uGMBC8Z5cdU2ClSd2vIWKd7D9syr+eH0l9mEr9o62+m3oNyXF6f+VNmJ7laDRtVeIrV9GHYQCS3oNhphZLnZKhGxWwub2R1Ac4I+mXIQwN14SvhdqbtyTlYMOA4j61VIVnSI/1nrTS4= 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=ij9YHA3G; arc=none smtp.client-ip=74.125.228.95 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="ij9YHA3G" Received: by mail-ed2-f31.google.com with SMTP id 4fb4d7f45d1cf-6aa053900f5so1209363a12.1 for ; Thu, 17 Sep 2026 04:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789643288; x=1790248088; 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=Gk5CbotewI/hTG+Sbs6BsiiN0sqU8afmxYBSAW5T38Y=; b=ij9YHA3Gc97MLC+ujNE72ZIZ1LAG9jcW3AD8nhOyUEh7qAjvMO3+lIC9svsB3R4tto 5mJSgvpPtViE5svCF3b8yykWNLpcL0Hgy09QqIwHpVcYFahstTR3I3yRxpaJ1SeR2stU 2q6nbfNqCMH2gXxNrj6x9R0B4O0QZhwoddoe0yHazk5IU5bnZudMJYkVVmyZaS1HzXYh 2AjWJs35zsaG2iJSk2oauKXK3mfXagJn1IhKgkkV5j7z4G1dore9egbkUdvlyLJWnKon jD4GFX65jKG51nj2IjOTwATb6t4iFLsKQ9W8cNzMg1JxanZ57rIHTeEEnmrBBiCMZK7Z WRFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789643288; x=1790248088; 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=Gk5CbotewI/hTG+Sbs6BsiiN0sqU8afmxYBSAW5T38Y=; b=ANm9qYVGl5RcBNmV/FyyqVAa184uwswNEz/v0ODPrLE0mTfBZ/coI++fCY2zxbhskX 5OwMe+RHg4KLd94TCNyQkX0/Px1QIX3vBAuWV9qwOsc4hoNjzxphvKpU2J0+9mqevNQP ZHZRPS//rI5S5eVdZxSZziVLvBhlMavCQX1KRVLqIZcLJj0yccVn+2ZRgVtCyEgMVzHP HQolfTTLFD+Z71dDb8JtkiuV3kjIBchF5A26HZs49NaDD0NOYkwOu0FcRbr90Lvp7luI 04Ic+POzxkhA3RAAf0cX6ib+4l6pX4bcby2QhL7Bw2GKcwOf8aAOFKeUSbmeJWZcKTXW anog== X-Forwarded-Encrypted: i=1; AKwUvBwcl7wC2RSTsLorvjQ424ZqXGVpF8o4cDuQ3MZNyD6Tk9HELbqla0KGRgv/dXSs3FPfLQs3LQPB4AmF+Ek=@vger.kernel.org X-Gm-Message-State: AFuF++kLgak8v2wkvo7li5jxFsT4ciCjmVIAwoLXIAjsu0lPmwRVYOds PhcPUQrBWrtC/dYTrbB0ezJqY/7hyNv3TEDTfupshIqlrxgTonUXlylj53LYGtz1RH4= X-Gm-Gg: AYBFou3qHhZQgyP0uFtuGikGeITRFOvI5ZFWgr4EcaJWluQso1z0jxcxwsmJ8KeInpu BaoRH0fNBCd0raGY3IAodKFBB6jVF6T1jtzDB41WtlD9v5WcApWev2JmlraXrtXrZ/hic0MXd2R jL5MKj5ATqW/qZZawxjooYmks/r0h5qb6xISxJxE/a2tb3+QeH+LNjXLvBI31tgr20Qc7TPi0+/ PSEu6OOcV+1SoiC3Q77L64iPa66af7XxplBS3VPC/hkg3H6PaXiN5eAlGldfYkTF3aK5s5jNjxP suw27e3O5oFdanS1Dy/dEXAp+ZDci6go+CLr4lxUtUNhewLXCP4Lp4/TlrxBAVG27GBqQEvmdzc 5gy3ZaMh5xFKz/Z4CPG4ixQAmaKahbIezwBL/t7iU+kZrVXxVIUms8TBEjgenX7/SSzyXvAiu/5 xkR05nanz8ZINN8YbcJ0A8BOnIjVcIg1GjZJa4Q5zhW2S6K3h8LorTtkFAPqwmTvJrpiu5n91rS R85kVYNGw== X-Received: by 2002:a05:6402:3789:b0:6a9:98de:6d8d with SMTP id 4fb4d7f45d1cf-6aa2245fd0fmr4559524a12.45.1789643288181; Thu, 17 Sep 2026 04:08:08 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6aa1d27ad36sm3175656a12.21.2026.09.17.04.08.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 04:08:07 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 12:07:56 +0100 Subject: [PATCH v18 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-v18-3-f85c9103177e@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@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=3025; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=jZig0GPFi4JGT2mSmtHGaqcYKCoZ1vTJV6/UKomI3Ak=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqq8oN0qkfPJbt5KiSUYWeyLkllH1amOK1AmkdG ghzm8ZiDniJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqvKDQAKCRAicTuzoY3I OidvD/9Wbx1buQl9vPxQFx4ksC1URoaDw4zXpIA7asxsSY0Tw0FB7Sl/anU/VvUJubBDJQW8Ane OM9lxPTn9QeZygPlF0UFlruopLa4p2QorC7tz1yiZYnZFPZRNAQ/1pFRy4VXWdmH8073weEDaKz 2REFS3hMUM+aqEtjC6Q2Rg1ss/D758r/32aQPKfhngY+9Fyj9isDEqQthLNyQP3p9u6e30xaXSm IQPpt2NqqktI+wV7kP4rmg033OMWYy2vhSGCXRm2mGGiuJWIWK1DNpoRxknFgBsb3TgkSJPQ6ZZ 69yh6dvNHE03VdnSFs7vp5AnTncEUMwUnhbhbWCZAWomEBw4BDIreLcvYXV1jgOAl3x7ugNcE5J bMRREHchI8l3ToxtZVX+VBSm765mTQYF5uGP5ZJPGbuFN/asLnv4DgTk0extlc3UPTGvyhDaMyN u53BR6vWHWfnAiJARCfRMXnzbI+tySPwPxdpbdjvqP6TmqDoXfNlYeJN+qE0oUtRQytpVoBRSN+ 6K0qWeLXvs/SZeJ9zzO20hwipw73J9zsG9cPwEzqt7JtDugLvKM5LRXpBibQA2qfQNczk5YlZCJ aetO79SKbftdOqdNfKQxnwlehGjJ81bzT+Tu9SeVc7l0COOWG+n5ZNwFxGumXtZXGeK0rMwhIvk X37/gReJiudbw7w== 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 --- drivers/phy/phy-core.c | 36 +++++++++++++++++++++++++++++++++++- include/linux/phy/phy.h | 7 +++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 490a7cde6d40a..10e9323566803 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -833,7 +833,7 @@ struct phy *phy_get(struct device *dev, const char *str= ing) =20 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_err(dev, "failed to create device link to %s\n", dev_name(phy->dev.parent)); =20 out_unlock: @@ -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 Fri Sep 25 02:45:56 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 2E04A4BD7AD for ; Thu, 17 Sep 2026 11:08:14 +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=1789643299; cv=none; b=jgmNCj0sjMVJc3mhUPMeZ9a6y7G6hwpfPIZgRysy3wMHPqtQQycW/hhMldf9h/kB8Rk4t07dBHVb3f/iXx1ANPnuaIDErd1TLYtV+b24IU2lmsFGfbt9sQbgi4GDvfNSZh4/xd2Tl0QVuZH/FCR+EmRs6MmcPx2urLz9VX+QoUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643299; c=relaxed/simple; bh=f09vqGxreX9xj4jU87a9RbysYDmF4tb6JPhpFI8rxk8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TiMQcpgk9/U8zhW5OrUw97nMXCxcBElYFZ149n3Nd/9GNfIchdn26I9hSeBaCgK8BquXNVcii+iFUZWVCKhpju9EwfoBNPI9OdGwQVPdv4BTBSeD2BPZXBPrBXarzC1Hn7fikFt3dFfMHqlEOrkMTjDe9ae2b9XExFyV9eIIMO0= 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=T/B7ukQm; 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="T/B7ukQm" Received: by mail-ed2-f12.google.com with SMTP id 4fb4d7f45d1cf-6a67fa7a64eso1110241a12.1 for ; Thu, 17 Sep 2026 04:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789643290; x=1790248090; 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=T/B7ukQm7WmEfgfak7GaueqCeX1np/W8HB43BtMlF86aEqsUE7xXLlD2wKEcioJAW2 i4JAhBpqTBm7VqZ/HzF1Oq9qagKE1l+CBFNWpcmjwsKKYSRWi6RKU03sEwm/9PsdljqN 45V/IKH+H9D3N3EWqpckFqomJSfCAtjy8pLehWQMBb/WO4pPpNEeu6OBeG7DihHHC77J VxtVHAwr3J3mQ9xVriwyae3Ehq4coQ5VcZMrR/NJWP1pF72dWyy46NrDfJfbMf18htq1 sOS/xhEcvAwePd3eYG9goxAIDiIURjGYTJ4skpFBeSC+McKI5cMrDCgiT0tmmnGWc185 VMKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789643290; x=1790248090; 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=g/MOyluNexxUpI51cWdyC/e84c36WNJpp4u91TytGWynt8FH9WF3AslYxAnzFJtOQk pAl3NUUKM4fcw7KwZxZxrHDAIUlc+fDg1+UkV8cQe0n1b5nwEquBD+S57VfnPzeIOEV+ iybjD6dNxZulKL7TTX7BHYLMgxe/JbnUwweHfVFFacWdVLvbCsMlmH/5NQQYOQ0pJsaR epmFcFR6MKGTg204zQdjrOfwSLLmWVvyRvSNOLhrqwjRMspa0Qq9Je5DFIEu+FEeOCUJ 0JcJ+uVJ3XAIQ4f8RsMeOEkuuqsn696sy3WpgcSr+rnxdBsP56dZ9aueZq9nxBc5m18+ 8ekg== X-Forwarded-Encrypted: i=1; AKwUvByQjJ9IDNr8ZHjktswGG+zRpVhl6YLUXZZzyXsWmcuBXr5tdAb1UTa8s+IDMoYaG3AdIfo9JfKJrzCZ5nA=@vger.kernel.org X-Gm-Message-State: AFuF++m3A57JVAOnEV9g8+o52+INSMx5w4BXEiFFxS0p2Jv2tcHbe/3a YU5KXM0IBhumrUNI42piX+U02a390GzWx2VXqgePaFx6B6oRA28QlBmJzrByXvThXF8= X-Gm-Gg: AYBFou314RY9itT8so6oAPOiGIvZpjmfNcyTD4uHFEVfa7teNTYTtkbaMQR4UEmTNZ6 fiy1JQooBzm9Sh/OmonyIptLsJXeR9ybVV2nj3jZy/+werbFHEWAfUDvh5FHtENAJC8adbcSPS2 eXVHQD8z7RbSTYFPs8nltDHydPu8sFNEZ3GZvfjkaK71htaZrPpEczKIrKXeTtCrLR9gb8lofK9 YAdi2PUup99bv2sa0TrMUYBFrzw8rxYCwZRAiviGiDJSB8k0nz3CqlBZngs2+98F9ighjdQf4sZ 7+yaYXCmbzbeh9/m8QUp4fM4KGHHYrINQA7Sye3fwjpVlz4r8LatFTPXrmkcVkmPAtfN2+UCtqT 6QKjheaTEGqrm12wbMwk21hP3At+lYzWkRiPW17cNmsPPDF5vqCx51GOBqI4S4Q+PpI/d0RAq8J 5AQ2UpfRfB9CDF0Fl/x24fWku6ULUyNRMMMqg6rIZo57VvGsS2XtU4FHbCuFIqJTu3AEXYcwlE/ 0Zr7QZaig== X-Received: by 2002:a05:6402:20d3:10b0:6aa:4529:4cb8 with SMTP id 4fb4d7f45d1cf-6aa4529566fmr591167a12.31.1789643289919; Thu, 17 Sep 2026 04:08:09 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6aa1d27ad36sm3175656a12.21.2026.09.17.04.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 04:08:09 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 12:07:57 +0100 Subject: [PATCH v18 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-v18-4-f85c9103177e@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@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/ZANAwAKASJxO7Ohjcg6AcsmYgBqq8oN99+SKXOYMSXm1q/usOXC3RaylwujxUGAg NzmiXUJ0TKJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqvKDQAKCRAicTuzoY3I OichD/9b8p6anJdPPJGPzJ0kMKFxQg0RrCtl9kxnVBhNrzhhszbzHUwp3qyBwsOn5KmKdnypRjn FtU1E4UhEEqAca+ekcQeYoZuWYGDh9Qe+pksQx2zKNs/ttPG0T/8HxEEGXly46EACSe3+vh9NlT zKVWzHNj7hbt2db9fL/s17aVyUHojMm3f0XmpCSiPuyZ1JKbMw2YWKX9VpzvUPxuDwY6s7ODcdo BfufbA3ZeqfNEI9Df+sZQ+RQMih1iuCOA8ZHfeunpImThNB4fEOJLw3zw+gUjb7Oc5t7cWjv8G8 alARGGdj71r1a7k9v5RgLlW4VL7d0UiYavkHmbpz5zAOhWZz7V/VRC4e53AnJ2ZnwVqbDnPHep8 +D1oR9Pfdvby/0d76kHmK5hbx5/HetceZwTfauq0mVgj5csB7gGrp4u/AgAGIwEHAOaQ4OiKe8k hGZvD+qgrUn7AmkBnTlzIqikg4/q1Ng8cBguy2BxnqH9SaachKluA/h2Dbow0FJLBh9mPGd9eMJ dFpJ3dP0XhiPSZMhVPuKDAaLOMzcf7Pxwso01IoyJmccP0GvgZt6w8mIzwiALeeOoVegWh1O/wZ jriSL+4mi2K9PL+/Yml9ekWeLgINvWKoiHL0RfLs6thqZb0KE/3Y6OOSv2Ru6HROIo57dr9TQID 72VjjV85E4FeIUw== 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 --- 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:45:56 2026 Received: from mail-ej2-f21.google.com (mail-ej2-f21.google.com [74.125.228.149]) (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 7173E4B53E4 for ; Thu, 17 Sep 2026 11:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643306; cv=none; b=C6fYQmG+thZxdXokReyWBqpDU/KIjPIcqu5sDqvhqyr4SueQEEART9Uqyq6ZcebU7eQwcHp5ChZpUXyQFzmSxsO+NBc0LA8VJmFNR8CrWXtU3jJ6uCJ566J1wpk/PIr3jvjsXs1htsCyRtAJgakxS7n7ZyRcCbXpdXVkpgsLtW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643306; c=relaxed/simple; bh=3K1Wns2lPwIAk0N4nkF5l6lG+fPy1HfHc9I4aSmbkCY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aZ+8Wd94rSereRLv6mHvumnJmYNf5t/vvWJj4ejy7szNdpuGZkfSOFqm98OGFvEmSor2YZxD+kHeF4UnpA++aohpDgLKHObGQ6Hfx4sQkjStITxXRhSzPDC9XMYMp+Ui2MVMN117+x9AgD0Lov1ppYBN9JpIyaZ7LAuAu/ZKnZc= 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=UB5WE7rr; arc=none smtp.client-ip=74.125.228.149 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="UB5WE7rr" Received: by mail-ej2-f21.google.com with SMTP id a640c23a62f3a-c254fa663c2so92893466b.3 for ; Thu, 17 Sep 2026 04:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789643292; x=1790248092; 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=K9De4Bw8APMeoKIGZUf5pgiyvld0+No1J4AiF85NjjQ=; b=UB5WE7rrFoIFso30pur6PhoqZO3UsMWeTlC5rt8KyumKVWy5AfXSiQ58/5pUfwgVY1 Z9PBWetiiY6WnN9PXRAOgMkWDb0yNlv2zVnDEmnVt2C5f/kQQSzb3nFTDelLTrJhxnSK 4OsVCJOLwU6/envyhf6PD6tGMC51ZIYl3L9V6CKkiSh2lbojN/B7CQbQBRfxLCNwphi+ zELHe5Zq3BnBOwFUyIE3Oov3qGi0AgMQO4VrIA0tyrVPQY5WxJC16uX2gBk/JDeD3u27 fMowW8K8UHgbu8ueATVE/zAy1pQmZrRjeCgh4IWwzb/leXlaqGbqoSx6PpCkGqqp3Yyb WEXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789643292; x=1790248092; 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=K9De4Bw8APMeoKIGZUf5pgiyvld0+No1J4AiF85NjjQ=; b=Bu5Zi2JeajNfA0XcbW3N3xTel0QRjknf58G+Ec1x9nJev32gEIlQlAepoYH4BxX9wy lBeW6qeHyRkR1JbSJ9l/SfZ+YjRlq5k6hReAaBArQtNwCQPcNNd75OOJTUjbYHYc660E Ut5zzFyDfr/JlGQOFSU3dSJTrRBgiM88zhGwuEkTYV8+NK//LdeMbl7m4gP+8A5QL5fK tBQ7cOhWk4AWmOOwu2Ww8yTsoMsWTiY7hqsju7kf0kAakKBFfyi2sPC0aF+iWPP0wwHx vrF0dMxz3Q1GKaPLuqvhp5Unqq7o6DYuSb7rogC7z8bb0iOnWiRbm0QzNB+Jmjd9PMEe U+Pg== X-Forwarded-Encrypted: i=1; AKwUvBwJmy37uU/xtTvcfs0syyNEq2fS0jz6P7zYVyQmCAqHEfWR4PgLKDP8WzeQ/0Y7hUaI5PLnfLHolo1fVC4=@vger.kernel.org X-Gm-Message-State: AFuF++nmCWYqT6JWT1zRA/TuJ+tdzLBoBHZxaSQq/vyF0ePXTTpXDHVv CZhAU6ygwWuJWP1+JEQmdD5P4p7W9XsZOlf4JXQ4zu63Eq2DOasa0ztIK3fhuMRCTBw= X-Gm-Gg: AYBFou3jxcjr3zotVzQ8Q2J2IW30ZUgp8XGR/Dd+uwZv/mV3ol/ZBUwHxuBlCtxx6QB iNPh+y97FAQlHzTLPQ+ULRBhOoTjDmSq40Tk/aUPFG+1kSI7s9DcZCFbHVd7r6Pr41MDrhDQcmw 5JKox3BVcnvdCqT27m0jhq4TVUpyozsyKvHbI9bYcyBOAUs9XPyY4fPoaCwcNthv6MxrhaoZw+t OFbANG0ENIN5ItCzVEemSAQ6vAJEfcUwxZotdcDr6aUOXywVl8YkKWxbyUwppJ0VVzK324bKgr1 PdGXPDPpeUQQddKK7AO7czNtABE9QvZ+yj6/bSz8GQ8gElF1tjr9YNsejP9gG8SRCwA4z1OhTjw /HO6u7Jz4xz56AMSatRAuChCQhGgjypQjDILhhT8c3SGhw2b81H4BPBdDpP3DMyZ/1CkhnzkfjQ eUBDfKC0UCoPBuhaVmcltgxPOcG5BprOUV++b7eJEz9OwNAlxUfXyQ/UI7IvkQtWR3kns76iMSM ZZSKG7Pa/dn/sK3ENMG X-Received: by 2002:a17:907:9413:b0:c29:f5d5:5a91 with SMTP id a640c23a62f3a-c29f5d56155mr214243466b.27.1789643291860; Thu, 17 Sep 2026 04:08:11 -0700 (PDT) Received: from [192.168.0.35] ([109.76.29.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6aa1d27ad36sm3175656a12.21.2026.09.17.04.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 04:08:11 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 17 Sep 2026 12:07:58 +0100 Subject: [PATCH v18 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-v18-5-f85c9103177e@linaro.org> References: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@linaro.org> In-Reply-To: <20260917-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v18-0-f85c9103177e@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=3037; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=3K1Wns2lPwIAk0N4nkF5l6lG+fPy1HfHc9I4aSmbkCY=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBqq8oOWuwN5GeQzkydan3FwspjkROv2M+IBYbix x82AYZOpFSJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaqvKDgAKCRAicTuzoY3I OhSQEACPjJCybxAhAztKMpAOOfiJT5w5srhu+b1CydFNTScLP0PcSyghjchf8j6M3WnQqISen5d 8L+TVJyakKdcBoXRlGukGmo2YZaRaEv6oKdtDg+TMd5NGx+yfOSt3QTu9+tRlWFKVhqufJGFHON CbHLo/fZ4jDVj7Yt4+0EohAl3mnhUFlDPIz23mULdcyYkCv2DzFYsEsfL9BRlc719qdkwGkQGTJ xw/XyXpiuwHYinUCSA8ScznX1rI1t3lIBkxafPK/eu1vEl9QPaIntMqXjRV/EjEgRIIfBiQeqFJ WDgtBrB+n8UY6PTXacTjlYTWRAKeInVMy6EzJdJf2FqgYloNRGq6Xp7keBeGFdSz/6OFnFnfLHN 5JmB942iroMSpCsWbKEJU0qcJs11z7/sdXmVeY+JJBGoF/f0GxIKIjsToscqwMJSChofMzFHvWD RqWyZkuzfoPUNneZRO7YvRZWVgUA5aAoRNJ37maW0pG51ZABE94xOscPlREwWaRDof90+s1E7pH SNfk06cjfSt0QExu7N1MJ2rsIb4VB3lQ3wjRbv0440Eqa7Tb86ImjDawqRm8Y5vWEsnvxTWEuA4 eHPO23rtzrZWGl8b4NEEXI0jEj6ud9KkNs1d0BLSZrIVo/NWu4DD+VqFNk50oC2Y9wCm34miscM Frsa6qGwGfBM2FQ== 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: Loic Poulain --- 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