From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29E56EFCD6D for ; Mon, 9 Mar 2026 09:19:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:References:To:From:Subject:Cc:Message-Id:Date:Mime-Version: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=M8lkyMwIYVNjq/xbFwMwg6IMvE8GNA5oNiJFWI8eoY0=; b=Xvg8DcBSyEXYQBLtT1c+aVql5z FMPxw8eNqUZL1BYVyMxPRhNVLUDKH2pYaHwgzHTMkBZiymEq7yPbFDThVDJk6i75idQ8BAEYMHY61 BcXfgFBL2I6Ja/3Hso4boWDqq9fZtSAE8G4yHE9bWhH5vHcluWp870HbDibYkEKpN7Sa91lAfCl8b zUVQLDz23LerEO4UiSLqy/TXi7NEVSFa/MBJ+O6i6FfKlZIQcYPI0BimFu3nikRCZihv/XA7nUfXv 59tiL43F+9JXF8+n/GpOnIKedL5uv09xMzeHDd3Jekn5IPdNs5foKtHCN+oh/KEmYPoKkz2JQm8m6 hMrWxJCA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vzWlX-00000006xEN-37nV; Mon, 09 Mar 2026 09:19:07 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vzWlS-00000006xAz-1GoC for linux-phy@lists.infradead.org; Mon, 09 Mar 2026 09:19:05 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-439b790af67so4612801f8f.0 for ; Mon, 09 Mar 2026 02:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1773047940; x=1773652740; darn=lists.infradead.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=kNiLR6YNrMRtTldTWTQRiLTdnMm5k8O8M4DvpvHP74I=; b=OeoimyfhGyCEPhz/f/T7GVP0+x0lQSO2xUcbi6R6/S+cgxqAKAYmRmFRcyyGDWgqmy GO5kJlGrsHfj3Rumw9tulmFf9Jokd5J8wqLOVZWc9yeR9fsco7LDSURBb47RlzDyhDg1 GNEZOItDyE0UPKPlYvGSc2oN2Ija96UwF0qGV1e8zP667X0uaijeeZy9yTs2ph6XtePA 7+I4WzXE+lfk0Bp+SzHnztkEM8doWI7hMSTWNlfeBqE+xn81McqTBAMHDhPUQFBaNgPk GY3oCU/CVSmdgFuuofYXyhKgSGjTwe6wYXN3oeIu/TLnVinODE456hffHmtyCWq3X1lb Zeqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773047940; x=1773652740; h=in-reply-to:references:to:from:subject:cc:message-id:date :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kNiLR6YNrMRtTldTWTQRiLTdnMm5k8O8M4DvpvHP74I=; b=oKkPJrsgjSdX6xM2m2MTd9Ss5JJS+IsvfO6aNyoDmZAyf6aN+hiJJqamRepj+nyLt2 5qc6WJZuy3Bw+HJanqb5BqURfMqSX1ugFLiLRGAXiH12GS2xNOCa8YCkrB8niVUsj5Mi 5EHCR5juj5dVYt1sYEr/G/hzUpI08AHIBAgoNL6U20/AxRn6bYAFgBvwOmVyfVVoUsHl usiym+qoVoAJ50Jya2GZZ51tnIiLEMYgIpRYle5cDnJLiEZJNS3TC+53AAXJFsBWOYBg becoqInj0YQuRqOwuGh4b7Hyp05NyGFg1P21Q2R2brFClY15rAuw5h+Ad95Z2Yww2POl W8mg== X-Forwarded-Encrypted: i=1; AJvYcCX29d8XSOTlkNQcYssNJ85PEb9nHlwLJnQicqWDHu9TvWFBXVfh22zXK7XTMjkGxV5IsdPyQadRykw=@lists.infradead.org X-Gm-Message-State: AOJu0YygK4AT3eHWR4ODBVXMX9A+fnsY8+35mKFIe0QYniGAvFt9bImH 4txDIO1r+eM2FgQcdhq0yi8HW5GPIOjnx8C6oPbpBgpc2iZC1fhYBbwmo0AWf5mL6GA= X-Gm-Gg: ATEYQzzmu7A7z/Iv0Sc6LxPgB4UZCK3miUYBNlKp/toZL97XUnPrPdODjK7iwLWVjqm yUdwmUXSOBqf2WgyPXWHYftCYINRJxibWS3CDLxJY7F2lFWt4dbJndtFUMXxdAUdarN4cHZtAYn x6y/QfE2zjFw1HS8uGvibI1ln3Yy49zw8gCwioXPz0KvWaDHks8zDBMRFIQjEAbotlsjEjB0Z/K LgI8awhm1Xy/WR8omYq5nUs6MVj/rAUwyWUqcKP+eCG8auAfNtH1GVNu4JXn2a7BHm4DQPi+JTj BcO4FYZc6/EgSWQ224+aIt1I0qMD+HKJQLrIksWWbZPDIvVf9R38j4XLea9JXWGxOIa2ToZM1JO R88IbUqQ2iT304uhfRpAu4ShRwWuz9YT54eY4k6Hjr4hGiko9VmeMcA9f8ZQ4xHQ0deFd7VbqpO 5Sch97OzdcNcaW1ZY= X-Received: by 2002:a05:6000:603:b0:439:909f:c5a3 with SMTP id ffacd0b85a97d-439da3277d9mr17145973f8f.4.1773047939930; Mon, 09 Mar 2026 02:18:59 -0700 (PDT) Received: from localhost ([195.52.25.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439dada9116sm23029936f8f.14.2026.03.09.02.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 02:18:59 -0700 (PDT) Mime-Version: 1.0 Date: Mon, 09 Mar 2026 10:18:50 +0100 Message-Id: Cc: "Vinod Koul" , "Neil Armstrong" , , , , , , , , , , , , , , , , , , , , , "Andrzej Hajda" , "Robert Foss" , "Laurent Pinchart" , "Jonas Karlman" , "Jernej Skrabec" , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" , "David Airlie" , "Simona Vetter" , "Andy Yan" , "Marc Kleine-Budde" , "Vincent Mailhol" , "Nicolas Ferre" , "Alexandre Belloni" , "Claudiu Beznea" , "Markus Schneider-Pargmann" , "Geert Uytterhoeven" , "Magnus Damm" Subject: Re: [PATCH v2 phy-next 14/24] phy: introduce phy_get_max_link_rate() helper for consumers From: "Markus Schneider-Pargmann" To: , X-Mailer: aerc 0.21.0 References: <20260308114009.2546587-1-vladimir.oltean@nxp.com> <20260308114009.2546587-15-vladimir.oltean@nxp.com> In-Reply-To: <20260308114009.2546587-15-vladimir.oltean@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260309_021902_537945_5592B369 X-CRM114-Status: GOOD ( 26.86 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============4544276736771705293==" Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org --===============4544276736771705293== Content-Type: multipart/signed; boundary=840703edd9f3f1e1e79a02bb78a8d4f69f696b0531524c2c45c8075436e0; micalg=pgp-sha512; protocol="application/pgp-signature" --840703edd9f3f1e1e79a02bb78a8d4f69f696b0531524c2c45c8075436e0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Hi, On Sun Mar 8, 2026 at 12:39 PM CET, vladimir.oltean wrote: > Consumer drivers shouldn't dereference struct phy, not even to get to > its attributes. > > We have phy_get_bus_width() as a precedent for getting the bus_width > attribute, so let's add phy_get_max_link_rate() and use it in DRM and > CAN drivers. > > In CAN drivers, the transceiver is acquired through devm_phy_optional_get= () > and NULL is given by the API as a non-error case, so the PHY API should > also tolerate NULL coming back to it. This means we can further simplify > the call sites that test for the NULL quality of the transceiver. Thanks for adding this. > > Signed-off-by: Vladimir Oltean > --- > Cc: Andrzej Hajda > Cc: Neil Armstrong > Cc: Robert Foss > Cc: Laurent Pinchart > Cc: Jonas Karlman > Cc: Jernej Skrabec > Cc: Maarten Lankhorst > Cc: Maxime Ripard > Cc: Thomas Zimmermann > Cc: David Airlie > Cc: Simona Vetter > Cc: Andy Yan > Cc: Marc Kleine-Budde > Cc: Vincent Mailhol > Cc: Nicolas Ferre > Cc: Alexandre Belloni > Cc: Claudiu Beznea > Cc: Markus Schneider-Pargmann > Cc: Geert Uytterhoeven > Cc: Magnus Damm > > v1->v2: make phy_get_bus_width() NULL-tolerant to simplify CAN callers > --- > drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 4 ++-- > drivers/gpu/drm/bridge/synopsys/dw-dp.c | 2 +- > drivers/net/can/at91_can.c | 3 +-- > drivers/net/can/flexcan/flexcan-core.c | 3 +-- > drivers/net/can/m_can/m_can_platform.c | 3 +-- For m_can: Acked-by: Markus Schneider-Pargmann Best Markus > drivers/net/can/rcar/rcar_canfd.c | 3 +-- > drivers/phy/phy-core.c | 9 +++++++++ > include/linux/phy/phy.h | 6 ++++++ > 8 files changed, 22 insertions(+), 11 deletions(-) > > diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/driver= s/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > index a8b6ae58cb0a..ed7ed82ddb64 100644 > --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > @@ -1300,7 +1300,7 @@ static u32 cdns_mhdp_get_training_interval_us(struc= t cdns_mhdp_device *mhdp, > =20 > static void cdns_mhdp_fill_host_caps(struct cdns_mhdp_device *mhdp) > { > - unsigned int link_rate; > + u32 link_rate; > =20 > /* Get source capabilities based on PHY attributes */ > =20 > @@ -1308,7 +1308,7 @@ static void cdns_mhdp_fill_host_caps(struct cdns_mh= dp_device *mhdp) > if (!mhdp->host.lanes_cnt) > mhdp->host.lanes_cnt =3D 4; > =20 > - link_rate =3D mhdp->phy->attrs.max_link_rate; > + link_rate =3D phy_get_max_link_rate(mhdp->phy); > if (!link_rate) > link_rate =3D drm_dp_bw_code_to_link_rate(DP_LINK_BW_8_1); > else > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-dp.c b/drivers/gpu/drm/br= idge/synopsys/dw-dp.c > index 4ab6922dd79c..79c72ee8e263 100644 > --- a/drivers/gpu/drm/bridge/synopsys/dw-dp.c > +++ b/drivers/gpu/drm/bridge/synopsys/dw-dp.c > @@ -536,7 +536,7 @@ static int dw_dp_link_parse(struct dw_dp *dp, struct = drm_connector *connector) > =20 > link->revision =3D link->dpcd[DP_DPCD_REV]; > link->rate =3D min_t(u32, min(dp->plat_data.max_link_rate, > - dp->phy->attrs.max_link_rate * 100), > + phy_get_max_link_rate(dp->phy) * 100), > drm_dp_max_link_rate(link->dpcd)); > link->lanes =3D min_t(u8, phy_get_bus_width(dp->phy), > drm_dp_max_lane_count(link->dpcd)); > diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c > index 58da323f14d7..7749da0a58f6 100644 > --- a/drivers/net/can/at91_can.c > +++ b/drivers/net/can/at91_can.c > @@ -1125,8 +1125,7 @@ static int at91_can_probe(struct platform_device *p= dev) > =20 > can_rx_offload_add_timestamp(dev, &priv->offload); > =20 > - if (transceiver) > - priv->can.bitrate_max =3D transceiver->attrs.max_link_rate; > + priv->can.bitrate_max =3D phy_get_max_link_rate(transceiver); > =20 > if (at91_is_sam9263(priv)) > dev->sysfs_groups[0] =3D &at91_sysfs_attr_group; > diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/fle= xcan/flexcan-core.c > index f5d22c61503f..093e48b8da58 100644 > --- a/drivers/net/can/flexcan/flexcan-core.c > +++ b/drivers/net/can/flexcan/flexcan-core.c > @@ -2210,8 +2210,7 @@ static int flexcan_probe(struct platform_device *pd= ev) > priv->reg_xceiver =3D reg_xceiver; > priv->transceiver =3D transceiver; > =20 > - if (transceiver) > - priv->can.bitrate_max =3D transceiver->attrs.max_link_rate; > + priv->can.bitrate_max =3D phy_get_max_link_rate(transceiver); > =20 > if (priv->devtype_data.quirks & FLEXCAN_QUIRK_NR_IRQ_3) { > priv->irq_boff =3D platform_get_irq(pdev, 1); > diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_c= an/m_can_platform.c > index 56da411878af..2a0f163a683a 100644 > --- a/drivers/net/can/m_can/m_can_platform.c > +++ b/drivers/net/can/m_can/m_can_platform.c > @@ -131,8 +131,7 @@ static int m_can_plat_probe(struct platform_device *p= dev) > goto probe_fail; > } > =20 > - if (transceiver) > - mcan_class->can.bitrate_max =3D transceiver->attrs.max_link_rate; > + mcan_class->can.bitrate_max =3D phy_get_max_link_rate(transceiver); > =20 > priv->base =3D addr; > priv->mram_base =3D mram_addr; > diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rca= r_canfd.c > index eaf8cac78038..9062db48d477 100644 > --- a/drivers/net/can/rcar/rcar_canfd.c > +++ b/drivers/net/can/rcar/rcar_canfd.c > @@ -1884,8 +1884,7 @@ static int rcar_canfd_channel_probe(struct rcar_can= fd_global *gpriv, u32 ch, > priv->transceiver =3D transceiver; > priv->channel =3D ch; > priv->gpriv =3D gpriv; > - if (transceiver) > - priv->can.bitrate_max =3D transceiver->attrs.max_link_rate; > + priv->can.bitrate_max =3D phy_get_max_link_rate(transceiver); > priv->can.clock.freq =3D fcan_freq; > dev_info(dev, "can_clk rate is %u\n", priv->can.clock.freq); > =20 > diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c > index 0d0be494cfd7..737a760d97d1 100644 > --- a/drivers/phy/phy-core.c > +++ b/drivers/phy/phy-core.c > @@ -647,6 +647,15 @@ void phy_set_bus_width(struct phy *phy, int bus_widt= h) > } > EXPORT_SYMBOL_GPL(phy_set_bus_width); > =20 > +u32 phy_get_max_link_rate(struct phy *phy) > +{ > + if (!phy) > + return 0; > + > + return phy->attrs.max_link_rate; > +} > +EXPORT_SYMBOL_GPL(phy_get_max_link_rate); > + > /** > * _of_phy_get() - lookup and obtain a reference to a phy by phandle > * @np: device_node for which to get the phy > diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h > index a7e2432ca1ae..34b656084caf 100644 > --- a/include/linux/phy/phy.h > +++ b/include/linux/phy/phy.h > @@ -57,6 +57,7 @@ int phy_notify_disconnect(struct phy *phy, int port); > int phy_notify_state(struct phy *phy, union phy_notify state); > int phy_get_bus_width(struct phy *phy); > void phy_set_bus_width(struct phy *phy, int bus_width); > +u32 phy_get_max_link_rate(struct phy *phy); > #else > static inline struct phy *phy_get(struct device *dev, const char *string= ) > { > @@ -256,6 +257,11 @@ static inline int phy_get_bus_width(struct phy *phy) > static inline void phy_set_bus_width(struct phy *phy, int bus_width) > { > } > + > +static inline u32 phy_get_max_link_rate(struct phy *phy) > +{ > + return 0; > +} > #endif /* IS_ENABLED(CONFIG_GENERIC_PHY) */ > =20 > #endif /* __PHY_CONSUMER_H */ --840703edd9f3f1e1e79a02bb78a8d4f69f696b0531524c2c45c8075436e0 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iKMEABYKAEsWIQSJYVVm/x+5xmOiprOFwVZpkBVKUwUCaa6QehsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwyLDIRHG1zcEBiYXlsaWJyZS5jb20ACgkQhcFWaZAVSlO3 cwEAzFZFZ21Yi1E3bmSFVrYlzos6oRC2RIJXE4meDDVCTjUA/2INMu045NS1yRGm V6PI/m62S0rUjMso1TupNVful6QE =gdIq -----END PGP SIGNATURE----- --840703edd9f3f1e1e79a02bb78a8d4f69f696b0531524c2c45c8075436e0-- --===============4544276736771705293== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy --===============4544276736771705293==--