Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp862958rwd; Tue, 13 Jun 2023 01:06:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6f50pu8Uu+d7JtfyTECgrsEN/6ZBOGlLJZ6r4XoMg8RM3wA5awc3twof91n4FGxraV7xUl X-Received: by 2002:a05:6a20:2591:b0:115:8be3:3d76 with SMTP id k17-20020a056a20259100b001158be33d76mr13909295pzd.6.1686643603211; Tue, 13 Jun 2023 01:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686643603; cv=none; d=google.com; s=arc-20160816; b=vwemNm1qR3Aeuk6ufmmCCzNU6a4LJKxOTk5qo/mBty6Tk8faoruUla668Wbg//kkD2 ks56xnNE5ceo4/q7vTR93KKlaaXinE5cn56NgFMKD5Eo27bMio9ulB0dM5Aq2XIAIq57 /19Rw5WpreM0eRU8RBLWMiFnLybTbhLel/s/n/mom4QLbSHNQaeJcwkjDCLtaeS7odYY a3/aOBTnqiax2sFtz50ubtc7xuVvFZ9vdap239rgFvPJt1YYj/NhlyO7ISWa6+9kLaTS 1BTXetXTJ59yn5c8KcrZsEuJkeBd0i0RR4dUzFaR6Z1WInMlYzfKziugfioG9BVLgNWu mPMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ksmnYzaAZG4SFOtuZwLT0Gj07ow0mCiA7tlTY9FP1/Y=; b=nm9k5g2vAP5S1AMhR93I7c2c1qV5JavkSPnJFILZ7FtcQvFhwzTw1m429fheU01MpT XgVlu7eIUyvoqSo57GD5JbQnJ4xGECjT33TIRP4Gc8y7JmiWQD8ceniYSHJY6NTsW0rF ETFUaiX2cju3W+B3UyaKGYV7UTCo1JG/W8DSt98yxPZTov3UmAvqm8cTR2xlt/JFcOnM fYLVeZtL7FSvx13KkEc7iZ5+ZFtz7d7qIzb/Zi89iPJaJmPG5p53RAsyaxnThX5oJgAA a51aujKdbNjWm4JE1wu8vWz3CtSia+DyD0m8erfeQVNi+iUjkTWzCddYM7AFccLjfv4a BsIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20221208.gappssmtp.com header.s=20221208 header.b="d/XOUvzX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a187-20020a624dc4000000b00665bd58cd5fsi1333790pfb.11.2023.06.13.01.06.22; Tue, 13 Jun 2023 01:06:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20221208.gappssmtp.com header.s=20221208 header.b="d/XOUvzX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240612AbjFMHxK (ORCPT + 99 others); Tue, 13 Jun 2023 03:53:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240050AbjFMHxH (ORCPT ); Tue, 13 Jun 2023 03:53:07 -0400 Received: from mail-vk1-xa31.google.com (mail-vk1-xa31.google.com [IPv6:2607:f8b0:4864:20::a31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A5ADE7D for ; Tue, 13 Jun 2023 00:53:05 -0700 (PDT) Received: by mail-vk1-xa31.google.com with SMTP id 71dfb90a1353d-46e0a9aaa01so135894e0c.1 for ; Tue, 13 Jun 2023 00:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1686642784; x=1689234784; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ksmnYzaAZG4SFOtuZwLT0Gj07ow0mCiA7tlTY9FP1/Y=; b=d/XOUvzXq7CkULBNjOF5cPQ9T8PQ4GUN2VTUb4tV5GYUOU/bcCMFJER5wRcTiOAxaO VEqeTPG5/GSimPhYdVoDC/uqRBqssvbhFmMqZ2UPpATKuDu0zcPmCBugjzLiimaHg+0O 9wZ1rW7T5SAVt/6r/SykeSUB1kSjjeu1v/QF9yZNVYeWYL/CqPipZS2RqbveG9GDYWQl 3yZcujcboW/sNqe2RjBd/XPxGCpKyPsA5S0Wt8H20ztGP/P8e2a+LHAM1iWQz7y5UEUU byzRaCp7blF315uAiXD/wO22ggP+a/pLSa4fq9EoyeAoPW6lXUTFE4Oe4EeVpTJurQyN Z0bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686642784; x=1689234784; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ksmnYzaAZG4SFOtuZwLT0Gj07ow0mCiA7tlTY9FP1/Y=; b=Zr+DH9bUcRM+bkuspiK5JaXaW3enJUx5eyW3TDBTUVPTr9fnQqL2o2PCuiHJBgbA97 QzHiuZ54t71hahV9KhFEkOOnEa5eRQzbewrw0SbmjuS6kw/4y08Zm/1/Dv//qNq3WTg6 Hmw/mwK3mP2mbGonAMUjBbbvdkty0FDyQ7csTVM1vaKg46ZQZan/EHudmGqYwjTZLz9N be1Wc9YjqwOjFUUIka91FKUkO3cP0A2tdwfWmoFZnyAdXvZyZa5Lk/9jmIIWTbMjtUkS htX9/uc62DeL2LyjIrZtZU3uFrp9q/LG0PU0MhEgHIQ5w8zPI+EW1Ep3RVNzH+GWue/1 4Xtg== X-Gm-Message-State: AC+VfDzXCbrEb8Z6kuFyp+o3EMHKoXSPA/mD/6RO12PcIvP1udm5Y+O7 He80BLFhQREK7r0lGit+YU49t8dBh4Qquqx12IDaag== X-Received: by 2002:a1f:bd58:0:b0:46d:fd21:76fb with SMTP id n85-20020a1fbd58000000b0046dfd2176fbmr580943vkf.10.1686642784529; Tue, 13 Jun 2023 00:53:04 -0700 (PDT) MIME-Version: 1.0 References: <20230612092355.87937-1-brgl@bgdev.pl> <20230612092355.87937-13-brgl@bgdev.pl> <20230612203255.72t52ucry7zzq3em@halaney-x13s> In-Reply-To: <20230612203255.72t52ucry7zzq3em@halaney-x13s> From: Bartosz Golaszewski Date: Tue, 13 Jun 2023 09:52:53 +0200 Message-ID: Subject: Re: [PATCH 12/26] net: stmmac: dwmac-qcom-ethqos: add support for the optional serdes phy To: Andrew Halaney Cc: Vinod Koul , Bhupesh Sharma , Andy Gross , Bjorn Andersson , Konrad Dybcio , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Kishon Vijay Abraham I , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 12, 2023 at 10:33=E2=80=AFPM Andrew Halaney wrote: > > On Mon, Jun 12, 2023 at 11:23:41AM +0200, Bartosz Golaszewski wrote: > > From: Bartosz Golaszewski > > > > On sa8775p platforms, there's a SGMII SerDes PHY between the MAC and > > external PHY that we need to enable and configure. > > > > Signed-off-by: Bartosz Golaszewski > > --- > > .../stmicro/stmmac/dwmac-qcom-ethqos.c | 37 +++++++++++++++++++ > > 1 file changed, 37 insertions(+) > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/= drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c > > index 8ed05f29fe8b..3438b6229351 100644 > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c > > @@ -6,6 +6,7 @@ > > #include > > #include > > #include > > +#include > > #include > > > > #include "stmmac.h" > > @@ -93,6 +94,7 @@ struct qcom_ethqos { > > > > unsigned int rgmii_clk_rate; > > struct clk *rgmii_clk; > > + struct phy *serdes_phy; > > unsigned int speed; > > > > const struct ethqos_emac_por *por; > > @@ -566,6 +568,30 @@ static void ethqos_fix_mac_speed(void *priv, unsig= ned int speed) > > ethqos_configure(ethqos); > > } > > > > +static int qcom_ethqos_serdes_powerup(struct net_device *ndev, void *p= riv) > > +{ > > + struct qcom_ethqos *ethqos =3D priv; > > + int ret; > > + > > + ret =3D phy_set_speed(ethqos->serdes_phy, ethqos->speed); > > + if (ret) > > + return ret; > > + > > + ret =3D phy_init(ethqos->serdes_phy); > > + if (ret) > > + return ret; > > + > > + return phy_power_on(ethqos->serdes_phy); > > The docs say (phy.rst): > > The general order of calls should be:: > > [devm_][of_]phy_get() > phy_init() > phy_power_on() > [phy_set_mode[_ext]()] > ... > phy_power_off() > phy_exit() > [[of_]phy_put()] > > Some PHY drivers may not implement :c:func:`phy_init` or :c:func:`phy= _power_on`, > but controllers should always call these functions to be compatible w= ith other > PHYs. Some PHYs may require :c:func:`phy_set_mode `= , while > others may use a default mode (typically configured via devicetree or= other > firmware). For compatibility, you should always call this function if= you know > what mode you will be using. Generally, this function should be calle= d after > :c:func:`phy_power_on`, although some PHY drivers may allow it at any= time. > > Not really dictating you need to do that order, but if possible I think > calling phy_set_speed after init + power_on is more generic. Not sure if > that plays nice with the phy driver in this series or not. > > Otherwise, I think this looks good. > I had to rework the PHY driver code a bit for this order to work but it'll be good now in v2. Thanks! Bart > > +} > > + > > +static void qcom_ethqos_serdes_powerdown(struct net_device *ndev, void= *priv) > > +{ > > + struct qcom_ethqos *ethqos =3D priv; > > + > > + phy_power_off(ethqos->serdes_phy); > > + phy_exit(ethqos->serdes_phy); > > +} > > + > > static int ethqos_clks_config(void *priv, bool enabled) > > { > > struct qcom_ethqos *ethqos =3D priv; > > @@ -651,6 +677,12 @@ static int qcom_ethqos_probe(struct platform_devic= e *pdev) > > if (ret) > > goto out_config_dt; > > > > + ethqos->serdes_phy =3D devm_phy_optional_get(dev, "serdes"); > > + if (IS_ERR(ethqos->serdes_phy)) { > > + ret =3D PTR_ERR(ethqos->serdes_phy); > > + goto out_config_dt; > > + } > > + > > ethqos->speed =3D SPEED_1000; > > ethqos_update_rgmii_clk(ethqos, SPEED_1000); > > ethqos_set_func_clk_en(ethqos); > > @@ -666,6 +698,11 @@ static int qcom_ethqos_probe(struct platform_devic= e *pdev) > > if (of_device_is_compatible(np, "qcom,qcs404-ethqos")) > > plat_dat->rx_clk_runs_in_lpi =3D 1; > > > > + if (ethqos->serdes_phy) { > > + plat_dat->serdes_powerup =3D qcom_ethqos_serdes_powerup; > > + plat_dat->serdes_powerdown =3D qcom_ethqos_serdes_powerd= own; > > + } > > + > > ret =3D stmmac_dvr_probe(dev, plat_dat, &stmmac_res); > > if (ret) > > goto out_config_dt; > > -- > > 2.39.2 > > >