net: sun8i-emac: Allwinner D1 Support
Subsystems (2)
Samuel Holland
maintainercover net: sun8i-emac: Allwinner D1 Support
D1 is a RISC-V SoC containing an EMAC compatible with the A64 EMAC. However, there are a couple of issues with the driver preventing it being built for RISC-V. These are resolved by patches 2-3. Patch 1 is a general cleanup.
Samuel Holland (3):
net: sun8i-emac: Downgrade printf during probe to debug
net: sun8i-emac: Drop use of arch-specific header
net: sun8i-emac: Use common syscon setup for R40
drivers/net/sun8i_emac.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
Signature · 1 line
2.35.1
Samuel Holland
maintainerPATCH 1/3 net: sun8i-emac: Downgrade printf during probe to debug
This just prints the PHY mode taken from the devicetree. It does not need to be printed during every boot.
---
drivers/net/sun8i_emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/sun8i_emac.c +1 -1
@@ -857,7 +857,7 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) priv->phyaddr =fdtdec_get_int (gd->fdt_blob, offset,"reg" ,-1 ); pdata->phy_interface =dev_read_phy_mode (dev); -printf ("phy interface%d\n" , pdata->phy_interface); +debug ("phy interface %d\n" , pdata->phy_interface);if (pdata->phy_interface ==PHY_INTERFACE_MODE_NA )return -EINVAL ;
Signature · 1 line
2.35.1
Re: [PATCH 1/3] net: sun8i-emac: Downgrade printf during probe to debug
Quoted 2 lines · On Fri, 15 Jul 2022 00:20:56 -0500 Samuel Holland <[email protected]> wrote:
This just prints the PHY mode taken from the devicetree. It does not need to be printed during every boot.
That's true, but I think a more important reason is that it spoils the output, doesn't it? It reads:
Net: phy interface9
eth0: ethernet@1c30000
at the moment, but I guess the intention was just:
Net: eth0: ethernet@1c30000
So given that, and the fact that "interface9" is not really helpful, that looks alright to me.
Quoted 1 line
Signed-off-by Samuel Holland <[email protected]>
Thanks,
Andre
Quoted 18 lines
---
drivers/net/sun8i_emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/sun8i_emac.c +1
-1@@ -857,7 +857,7 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) priv->phyaddr =fdtdec_get_int (gd->fdt_blob, offset,"reg" ,-1 ); pdata->phy_interface =dev_read_phy_mode (dev); -printf ("phy interface%d\n" , pdata->phy_interface); +debug ("phy interface %d\n" , pdata->phy_interface);if (pdata->phy_interface ==PHY_INTERFACE_MODE_NA )return -EINVAL ;
Ramon Fried
Reviewed-byRe: [PATCH 1/3] net: sun8i-emac: Downgrade printf during probe to debug
Quoted 35 lines · Andre Przywara
Quoted 2 lines · On Fri, 15 Jul 2022 00:20:56 -0500 Samuel Holland <[email protected]> wrote:
This just prints the PHY mode taken from the devicetree. It does not need to be printed during every boot.
That's true, but I think a more important reason is that it spoils the output, doesn't it? It reads:
Net: phy interface9
eth0: ethernet@1c30000
at the moment, but I guess the intention was just:
Net: eth0: ethernet@1c30000So given that, and the fact that "interface9" is not really helpful, that looks alright to me.
Quoted 1 line
Signed-off-by Samuel Holland <[email protected]>Reviewed-by Andre Przywara <[email protected]>Thanks,
AndreQuoted 12 lines
---
drivers/net/sun8i_emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/sun8i_emac.c +0
-0@@ -857,7 +857,7 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) priv->phyaddr =fdtdec_get_int (gd->fdt_blob, offset,"reg" ,-1 );
Quoted 7 lines
drivers/net/sun8i_emac.c static int sun8i_emac_eth_of_to_plat(struct udevice *dev) · line 863
Quoted 6 lines
drivers/net/sun8i_emac.c +1
-1pdata->phy_interface =dev_read_phy_mode (dev); -printf ("phy interface%d\n" , pdata->phy_interface); +debug ("phy interface %d\n" , pdata->phy_interface);if (pdata->phy_interface ==PHY_INTERFACE_MODE_NA )return -EINVAL ;
Samuel Holland
maintainerPATCH 2/3 net: sun8i-emac: Drop use of arch-specific header
In reply to Samuel HollandThis header is not used since commit abdbefba2a4e ("net: sun8i_emac: Use consistent clock bitfield definitions"). Dropping it allows the driver to be architecture-independent.
---
drivers/net/sun8i_emac.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/sun8i_emac.c +0 -1
@@ -16,7 +16,6 @@#include <asm/global_data.h> #include <asm/gpio.h> #include <asm/io.h> -#include <asm/arch/clock.h> #include <common.h> #include <clk.h> #include <dm.h>
Signature · 1 line
2.35.1
Re: [PATCH 2/3] net: sun8i-emac: Drop use of arch-specific header
On Fri, 15 Jul 2022 00:20:57 -0500
Samuel Holland <[email protected]> wrote:
Hi,
Quoted 3 lines
This header is not used since commit
abdbefba2a4e("net:sun8i_emac: Use consistent clock bitfield definitions"). Dropping it allows the driver to be architecture-independent.
Yes, we don't need this header anymore (all boards compile fine without it), and indeed it seems to be this commit you mentioned that changed that.
Quoted 1 line
Signed-off-by Samuel Holland <[email protected]>
Cheers,
Andre
Quoted 15 lines
drivers/net/sun8i_emac.c | 1 - 1 file changed, 1 deletion(-)drivers/net/sun8i_emac.c +0
-1@@ -16,7 +16,6 @@#include <asm/global_data.h> #include <asm/gpio.h> #include <asm/io.h> -#include <asm/arch/clock.h> #include <common.h> #include <clk.h> #include <dm.h>
Re: [PATCH 2/3] net: sun8i-emac: Drop use of arch-specific header
In reply to Samuel HollandQuoted 24 lines · Samuel Holland
This header is not used since commit
abdbefba2a4e("net:sun8i_emac: Use consistent clock bitfield definitions"). Dropping it allows the driver to be architecture-independent.Signed-off-by Samuel Holland <[email protected]>---
drivers/net/sun8i_emac.c | 1 - 1 file changed, 1 deletion(-)drivers/net/sun8i_emac.c +0
-2@@ -16,7 +16,6 @@#include <asm/global_data.h> #include <asm/gpio.h> #include <asm/io.h> -#include <asm/arch/clock.h> #include <common.h> #include <clk.h> #include <dm.h> --
Quoted 2 lines
2.35.1
Samuel Holland
maintainerPATCH 3/3 net: sun8i-emac: Use common syscon setup for R40
In reply to Samuel HollandWhile 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.
---
drivers/net/sun8i_emac.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)
drivers/net/sun8i_emac.c +12 -17
@@ -162,7 +162,7 @@ struct emac_eth_dev {enum 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;
@@ -317,18 +317,7 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata, {u32 reg; -if (priv->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);
@@ -369,7 +358,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 ; }
@@ -792,6 +781,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 ;
@@ -837,13 +827,18 @@ 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 ; } +if (priv->variant ==R40_GMAC ) + priv->sysctl_reg = (void *)syscon_base +0x164 ; +else + priv->sysctl_reg = (void *)syscon_base +0x30 ; + pdata->phy_interface =-1 ; priv->phyaddr =-1 ; priv->use_internal_phy = false;
Signature · 1 line
2.35.1
Re: [PATCH 3/3] net: sun8i-emac: Use common syscon setup for R40
Quoted 76 lines · Samuel Holland
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, notphys_addr_t.Signed-off-by Samuel Holland <[email protected]>---
drivers/net/sun8i_emac.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)drivers/net/sun8i_emac.c +6
-17@@ -162,7 +162,7 @@ struct emac_eth_dev {enum 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;@@ -317,18 +317,7 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata, {u32 reg; -if (priv->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);@@ -369,7 +358,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 ; }@@ -792,6 +781,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 ;@@ -837,13 +827,18 @@ 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);
drivers/net/sun8i_emac.c static int sun8i_emac_eth_of_to_plat(struct udevice *dev) · line 841
Quoted 10 lines
drivers/net/sun8i_emac.c +6
-0+if (syscon_base ==FDT_ADDR_T_NONE ) {debug ("%s: Cannot find syscon base address\n" , __func__);return -EINVAL ; } +if (priv->variant ==R40_GMAC ) + priv->sysctl_reg = (void *)syscon_base +0x164 ; +else + priv->sysctl_reg = (void *)syscon_base +0x30 ; +
Better to get syscon fields from driver data as this driver support DM.
Jagan.