lkml.org 
[lkml]   [2022]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2 6/9] net: phy: motorcomm: Add YT8531 phy support
Date
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;
> +}
> +
>
\
 
 \ /
  Last update: 2022-12-16 09:42    [W:0.269 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site