From: Hans-Frieder Vogt <hfdevel@gmx.net>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: netdev@vger.kernel.org, andrew@lunn.ch, horms@kernel.org,
kuba@kernel.org, jiri@resnulli.us, pabeni@redhat.com
Subject: Re: [PATCH net-next v5 5/6] net: tn40xx: add mdio bus support
Date: Wed, 8 May 2024 20:08:57 +0200 [thread overview]
Message-ID: <1f28bc3c-3489-4fc7-b5de-20824631e5df@gmx.net> (raw)
> +static int tn40_mdio_read(struct tn40_priv *priv, int port, int device,
> + u16 regnum)
> +{
> + void __iomem *regs = priv->regs;
> + u32 tmp_reg, i;
> +
> + /* wait until MDIO is not busy */
> + if (tn40_mdio_get(priv, NULL))
> + return -EIO;
> +
> + i = ((device & 0x1F) | ((port & 0x1F) << 5));
instead of using numbers for the masks, you may use here the constants
defined in uapi/linux/mdio.h, to make the code more understandable
i = (device & MDIO_PHY_ID_DEVAD) | ((port << 5) & MDIO_PHY_ID_PRTAD);
> + writel(i, regs + TN40_REG_MDIO_CMD);
> + writel((u32)regnum, regs + TN40_REG_MDIO_ADDR);
> + if (tn40_mdio_get(priv, NULL))
> + return -EIO;
> +
> + writel(((1 << 15) | i), regs + TN40_REG_MDIO_CMD);
similarly here:
writel((MDIO_PHY_ID_C45 | i), regs + TN40_REG_MDIO_CMD);
> + /* read CMD_STAT until not busy */
> + if (tn40_mdio_get(priv, NULL))
> + return -EIO;
> +
> + tmp_reg = readl(regs + TN40_REG_MDIO_DATA);
> + return lower_16_bits(tmp_reg);
> +}
> +
> +static int tn40_mdio_write(struct tn40_priv *priv, int port, int device,
> + u16 regnum, u16 data)
> +{
> + void __iomem *regs = priv->regs;
> + u32 tmp_reg = 0;
> + int ret;
> +
> + /* wait until MDIO is not busy */
> + if (tn40_mdio_get(priv, NULL))
> + return -EIO;
> + writel(((device & 0x1F) | ((port & 0x1F) << 5)),
and also here, similarly:
writel((device & MDIO_PHY_ID_DEVAD) | ((port << 5) & MDIO_PHY_ID_PRTAD),
> + regs + TN40_REG_MDIO_CMD);
> + writel((u32)regnum, regs + TN40_REG_MDIO_ADDR);
> + if (tn40_mdio_get(priv, NULL))
> + return -EIO;
> + writel((u32)data, regs + TN40_REG_MDIO_DATA);
> + /* read CMD_STAT until not busy */
> + ret = tn40_mdio_get(priv, &tmp_reg);
> + if (ret)
> + return -EIO;
> +
> + if (TN40_GET_MDIO_RD_ERR(tmp_reg)) {
> + dev_err(&priv->pdev->dev, "MDIO error after write command\n");
> + return -EIO;
> + }
> + return 0;
> +}
--
Cheers,
Hans
next reply other threads:[~2024-05-08 18:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 18:08 Hans-Frieder Vogt [this message]
2024-05-08 18:25 ` [PATCH net-next v5 5/6] net: tn40xx: add mdio bus support Andrew Lunn
2024-05-08 19:30 ` Hans-Frieder Vogt
2024-05-09 9:52 ` Hans-Frieder Vogt
2024-05-09 10:59 ` FUJITA Tomonori
2024-05-09 11:16 ` Hans-Frieder Vogt
2024-05-09 11:25 ` FUJITA Tomonori
-- strict thread matches above, loose matches on Subject: below --
2024-05-08 11:39 [PATCH net-next v5 0/6] add ethernet driver for Tehuti Networks TN40xx chips FUJITA Tomonori
2024-05-08 11:39 ` [PATCH net-next v5 5/6] net: tn40xx: add mdio bus support FUJITA Tomonori
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=1f28bc3c-3489-4fc7-b5de-20824631e5df@gmx.net \
--to=hfdevel@gmx.net \
--cc=andrew@lunn.ch \
--cc=fujita.tomonori@gmail.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 read-only IMAP folder(s) and NNTP newsgroup(s).