From: <Arun.Ramadoss@microchip.com>
To: <netdev@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<yanhong.wang@starfivetech.com>, <linux-kernel@vger.kernel.org>,
<devicetree@vger.kernel.org>
Cc: <andrew@lunn.ch>, <robh+dt@kernel.org>, <pgwipeout@gmail.com>,
<kernel@esmil.dk>, <kuba@kernel.org>, <pabeni@redhat.com>,
<edumazet@google.com>, <richardcochran@gmail.com>,
<krzysztof.kozlowski+dt@linaro.org>, <davem@davemloft.net>,
<hkallweit1@gmail.com>
Subject: Re: [PATCH v2 6/9] net: phy: motorcomm: Add YT8531 phy support
Date: Fri, 16 Dec 2022 08:41:09 +0000 [thread overview]
Message-ID: <ea9ed7f72adb0bd83581e9f55f99fb8630e7bc48.camel@microchip.com> (raw)
In-Reply-To: <20221216070632.11444-7-yanhong.wang@starfivetech.com>
Hi Yanhong,
On Fri, 2022-12-16 at 15:06 +0800, Yanhong Wang wrote:
> This adds basic support for the Motorcomm YT8531
> Gigabit Ethernet PHY.
>
> Signed-off-by: Yanhong Wang <yanhong.wang@starfivetech.com>
> ---
> drivers/net/phy/Kconfig | 3 +-
> drivers/net/phy/motorcomm.c | 202
> ++++++++++++++++++++++++++++++++++++
> 2 files changed, 204 insertions(+), 1 deletion(-)
>
>
> +static int ytphy_read_ext(struct phy_device *phydev, u32 regnum)
> +{
> + int ret;
> + int val;
> +
> + ret = __phy_write(phydev, YT8511_PAGE_SELECT, regnum);
> + if (ret < 0)
> + return ret;
You are returning the error value as well as the read value in the
function. But in the config_init, you are not checking the error value,
just using the value directly. So instead of returning both the value
and error, you may consider return error and for value use call by
reference.
> +
> + val = __phy_read(phydev, YT8511_PAGE);
> +
> + return val;
> +}
> +
> +
> static int yt8511_config_init(struct phy_device *phydev)
> {
> int oldpage, ret = 0;
> @@ -111,6 +191,116 @@ static int yt8511_config_init(struct phy_device
> *phydev)
> return phy_restore_page(phydev, oldpage, ret);
> }
>
> +static int ytphy_config_init(struct phy_device *phydev)
> +{
> + struct device_node *of_node;
> + u32 val;
> + u32 mask;
> + u32 cfg;
> + int ret;
> + int i = 0;
i initialized here as well as in for loop.
> +
> + of_node = phydev->mdio.dev.of_node;
> + if (of_node) {
to reduce the ident level, you may consider returning here by checking
if(!of_node)
return -EINVAL;
> + ret = of_property_read_u32(of_node,
> ytphy_rxden_grp[0].name, &cfg);
> + if (!ret) {
> + mask = ytphy_rxden_grp[0].mask;
> + val = ytphy_read_ext(phydev,
> YTPHY_EXT_CHIP_CONFIG);
> +
> + /* check the cfg overflow or not */
> + cfg = cfg > mask >> (ffs(mask) - 1) ? mask :
> cfg;
> +
> + val &= ~mask;
> + val |= FIELD_PREP(mask, cfg);
> + ytphy_write_ext(phydev, YTPHY_EXT_CHIP_CONFIG,
> val);
> + }
> +
> + val = ytphy_read_ext(phydev, YTPHY_EXT_RGMII_CONFIG1);
> + for (i = 0; i < ARRAY_SIZE(ytphy_rxtxd_grp); i++) {
> + ret = of_property_read_u32(of_node,
> ytphy_rxtxd_grp[i].name, &cfg);
> + if (!ret) {
> + mask = ytphy_rxtxd_grp[i].mask;
> +
> + /* check the cfg overflow or not */
> + cfg = cfg > mask >> (ffs(mask) - 1) ?
> mask : cfg;
> +
> + val &= ~mask;
> + val |= cfg << (ffs(mask) - 1);
> + }
> + }
> + return ytphy_write_ext(phydev, YTPHY_EXT_RGMII_CONFIG1,
> val);
> + }
> +
> + phydev_err(phydev, "Get of node fail\n");
> +
> + return -EINVAL;
> +}
> +
> +static void ytphy_link_change_notify(struct phy_device *phydev)
> +{
> + u32 val;
> + struct ytphy_priv_t *ytphy_priv = phydev->priv;
reverse christmas tree
> +
> + if (phydev->speed < 0)
> + return;
> +
> +
> +static int yt8531_probe(struct phy_device *phydev)
> +{
> + struct ytphy_priv_t *priv;
> + const struct device_node *of_node;
Reverse christmas tree.
> + u32 val;
> + int ret;
> +
> + priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv),
> GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + of_node = phydev->mdio.dev.of_node;
> + if (of_node) {
> + ret = of_property_read_u32(of_node,
> ytphy_txinver_grp[0].name, &val);
> + if (!ret)
> + priv->tx_inverted_1000 = val;
> +
> + ret = of_property_read_u32(of_node,
> ytphy_txinver_grp[1].name, &val);
> + if (!ret)
> + priv->tx_inverted_100 = val;
> +
> + ret = of_property_read_u32(of_node,
> ytphy_txinver_grp[2].name, &val);
> + if (!ret)
> + priv->tx_inverted_10 = val;
> + }
> + phydev->priv = priv;
> +
> + return 0;
> +}
> +
>
next prev parent reply other threads:[~2022-12-16 8:41 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-16 7:06 [PATCH v2 0/9] Add Ethernet driver for StarFive JH7110 SoC Yanhong Wang
2022-12-16 7:06 ` [PATCH v2 1/9] dt-bindings: net: snps,dwmac: Add dwmac-5.20 version Yanhong Wang
2022-12-16 7:06 ` [PATCH v2 2/9] dt-bindings: net: snps,dwmac: Update the maxitems number of resets and reset-names Yanhong Wang
2022-12-16 11:03 ` Krzysztof Kozlowski
2022-12-20 6:48 ` yanhong wang
2022-12-20 9:21 ` Krzysztof Kozlowski
2022-12-27 7:48 ` yanhong wang
2022-12-27 8:18 ` Krzysztof Kozlowski
2022-12-16 7:06 ` [PATCH v2 3/9] net: stmmac: platform: Add snps,dwmac-5.20 IP compatible string Yanhong Wang
2022-12-16 7:06 ` [PATCH v2 4/9] dt-bindings: net: Add bindings for StarFive dwmac Yanhong Wang
2022-12-16 11:05 ` Krzysztof Kozlowski
2022-12-20 6:53 ` yanhong wang
2022-12-16 11:06 ` Krzysztof Kozlowski
2022-12-20 6:57 ` yanhong wang
2022-12-20 18:03 ` Rob Herring
2022-12-16 7:06 ` [PATCH v2 5/9] dt-bindings: net: motorcomm: add support for Motorcomm YT8531 Yanhong Wang
2022-12-16 11:15 ` Krzysztof Kozlowski
2022-12-27 9:38 ` yanhong wang
2022-12-27 9:52 ` Krzysztof Kozlowski
2022-12-28 3:23 ` yanhong wang
2022-12-28 9:11 ` Krzysztof Kozlowski
2022-12-28 9:24 ` yanhong wang
2022-12-16 7:06 ` [PATCH v2 6/9] net: phy: motorcomm: Add YT8531 phy support Yanhong Wang
2022-12-16 8:41 ` Arun.Ramadoss [this message]
2022-12-16 11:58 ` Heiner Kallweit
2022-12-21 1:16 ` yanhong wang
2022-12-20 14:20 ` Andrew Lunn
2022-12-16 7:06 ` [PATCH v2 7/9] net: stmmac: Add glue layer for StarFive JH71x0 SoCs Yanhong Wang
2022-12-16 11:19 ` Krzysztof Kozlowski
2022-12-16 7:06 ` [PATCH v2 8/9] riscv: dts: starfive: jh7110: Add ethernet device node Yanhong Wang
2022-12-16 7:06 ` [PATCH v2 9/9] riscv: dts: starfive: visionfive-v2: Add phy clock delay train configuration Yanhong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea9ed7f72adb0bd83581e9f55f99fb8630e7bc48.camel@microchip.com \
--to=arun.ramadoss@microchip.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kernel@esmil.dk \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pgwipeout@gmail.com \
--cc=richardcochran@gmail.com \
--cc=robh+dt@kernel.org \
--cc=yanhong.wang@starfivetech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).