From: Andre Przywara <andre.przywara@arm.com>
To: Samuel Holland <samuel@sholland.org>,
Jagan Teki <jagan@amarulasolutions.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>,
Ramon Fried <rfried.dev@gmail.com>,
u-boot@lists.denx.de
Subject: Re: [PATCH v2 4/5] net: sun8i-emac: Use common syscon setup for R40
Date: Mon, 23 Jan 2023 17:24:00 +0000 [thread overview]
Message-ID: <d85b0b2e-92f0-ee38-9ccf-30cb31582307@arm.com> (raw)
In-Reply-To: <20230122225107.62464-5-samuel@sholland.org>
On 22/01/2023 22:51, Samuel Holland wrote:
> While R40 puts the EMAC syscon register at a different address from
> other variants, the relevant portion of the register's layout is the
> same. Factor out the register offset so the same code can be shared
> by all variants. This matches what the Linux driver does.
>
> This change provides two benefits beyond the simplification:
> - R40 boards now respect the RX delays from the devicetree
> - This resolves a warning on architectures where readl/writel
> expect the address to have a pointer type, not phys_addr_t.
>
Nice cleanup, and makes it obvious that the R40 isn't such a special
snowflake after all.
> Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Cheers,
Andre
> ---
>
> Changes in v2:
> - Add a structure for driver data, and put the syscon offset there
>
> drivers/net/sun8i_emac.c | 32 +++++++++++++++-----------------
> 1 file changed, 15 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c
> index 36cc2498b5..231aac19e3 100644
> --- a/drivers/net/sun8i_emac.c
> +++ b/drivers/net/sun8i_emac.c
> @@ -137,6 +137,7 @@ enum emac_variant_id {
>
> struct emac_variant {
> enum emac_variant_id variant;
> + uint syscon_offset;
> bool soc_has_internal_phy;
> bool support_rmii;
> };
> @@ -168,7 +169,7 @@ struct emac_eth_dev {
>
> const struct emac_variant *variant;
> void *mac_reg;
> - phys_addr_t sysctl_reg;
> + void *sysctl_reg;
> struct phy_device *phydev;
> struct mii_dev *bus;
> struct clk tx_clk;
> @@ -323,18 +324,7 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata,
> {
> u32 reg;
>
> - if (priv->variant->variant == R40_GMAC) {
> - /* Select RGMII for R40 */
> - reg = readl(priv->sysctl_reg + 0x164);
> - reg |= SC_ETCS_INT_GMII |
> - SC_EPIT |
> - (CONFIG_GMAC_TX_DELAY << SC_ETXDC_OFFSET);
> -
> - writel(reg, priv->sysctl_reg + 0x164);
> - return 0;
> - }
> -
> - reg = readl(priv->sysctl_reg + 0x30);
> + reg = readl(priv->sysctl_reg);
>
> reg = sun8i_emac_set_syscon_ephy(priv, reg);
>
> @@ -370,7 +360,7 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata,
> reg |= ((pdata->rx_delay_ps / 100) << SC_ERXDC_OFFSET)
> & SC_ERXDC_MASK;
>
> - writel(reg, priv->sysctl_reg + 0x30);
> + writel(reg, priv->sysctl_reg);
>
> return 0;
> }
> @@ -793,6 +783,7 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
> struct sun8i_eth_pdata *sun8i_pdata = dev_get_plat(dev);
> struct eth_pdata *pdata = &sun8i_pdata->eth_pdata;
> struct emac_eth_dev *priv = dev_get_priv(dev);
> + phys_addr_t syscon_base;
> const fdt32_t *reg;
> int node = dev_of_offset(dev);
> int offset = 0;
> @@ -838,13 +829,15 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
> __func__);
> return -EINVAL;
> }
> - priv->sysctl_reg = fdt_translate_address((void *)gd->fdt_blob,
> - offset, reg);
> - if (priv->sysctl_reg == FDT_ADDR_T_NONE) {
> +
> + syscon_base = fdt_translate_address((void *)gd->fdt_blob, offset, reg);
> + if (syscon_base == FDT_ADDR_T_NONE) {
> debug("%s: Cannot find syscon base address\n", __func__);
> return -EINVAL;
> }
>
> + priv->sysctl_reg = (void *)syscon_base + priv->variant->syscon_offset;
> +
> pdata->phy_interface = -1;
> priv->phyaddr = -1;
> priv->use_internal_phy = false;
> @@ -903,25 +896,30 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
>
> static const struct emac_variant emac_variant_a83t = {
> .variant = A83T_EMAC,
> + .syscon_offset = 0x30,
> };
>
> static const struct emac_variant emac_variant_h3 = {
> .variant = H3_EMAC,
> + .syscon_offset = 0x30,
> .soc_has_internal_phy = true,
> .support_rmii = true,
> };
>
> static const struct emac_variant emac_variant_r40 = {
> .variant = R40_GMAC,
> + .syscon_offset = 0x164,
> };
>
> static const struct emac_variant emac_variant_a64 = {
> .variant = A64_EMAC,
> + .syscon_offset = 0x30,
> .support_rmii = true,
> };
>
> static const struct emac_variant emac_variant_h6 = {
> .variant = H6_EMAC,
> + .syscon_offset = 0x30,
> .support_rmii = true,
> };
>
next prev parent reply other threads:[~2023-01-23 17:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-22 22:51 [PATCH v2 0/5] net: sun8i-emac: Allwinner D1 Support Samuel Holland
2023-01-22 22:51 ` [PATCH v2 1/5] net: sun8i-emac: Add a structure for variant data Samuel Holland
2023-01-23 17:21 ` Andre Przywara
2023-02-04 0:36 ` Ramon Fried
2023-01-22 22:51 ` [PATCH v2 2/5] net: sun8i-emac: Add a flag for RMII support Samuel Holland
2023-01-23 17:22 ` Andre Przywara
2023-02-04 0:36 ` Ramon Fried
2023-01-22 22:51 ` [PATCH v2 3/5] net: sun8i-emac: Add a flag for the internal PHY switch Samuel Holland
2023-01-23 17:23 ` Andre Przywara
2023-02-04 0:37 ` Ramon Fried
2023-01-22 22:51 ` [PATCH v2 4/5] net: sun8i-emac: Use common syscon setup for R40 Samuel Holland
2023-01-23 17:24 ` Andre Przywara [this message]
2023-02-04 0:37 ` Ramon Fried
2023-01-22 22:51 ` [PATCH v2 5/5] net: sun8i-emac: Remove the SoC variant ID Samuel Holland
2023-01-23 17:24 ` Andre Przywara
2023-02-04 0:38 ` Ramon Fried
2023-01-22 23:45 ` [PATCH v2 0/5] net: sun8i-emac: Allwinner D1 Support Andre Przywara
2023-02-01 0:26 ` Andre Przywara
2023-02-04 0:41 ` Ramon Fried
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=d85b0b2e-92f0-ee38-9ccf-30cb31582307@arm.com \
--to=andre.przywara@arm.com \
--cc=jagan@amarulasolutions.com \
--cc=joe.hershberger@ni.com \
--cc=rfried.dev@gmail.com \
--cc=samuel@sholland.org \
--cc=u-boot@lists.denx.de \
/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