diff mbox series

[RFC,v2,1/6] ath79: ensure QCA956x gmac0 mux selects sgmii

Message ID e5f9b99670dadb177395f1830a610e9c3f9d71c2.1595193767.git.sander@svanheule.net
State New
Headers show
Series ath79: support for TP-Link EAP2x5 1-port devices | expand

Commit Message

Sander Vanheule July 19, 2020, 9:24 p.m. UTC
Some bootloaders do not set up gmac0 properly, leaving it disconnected
from the sgmii interface. If the user specificies phy-mode sgmii, then
use the gmac-config/device node to ensure the mux is configured
correctly.

Signed-off-by: Sander Vanheule <sander@svanheule.net>
Cc: David Bauer <mail@david-bauer.net>
---
 .../net/ethernet/atheros/ag71xx/ag71xx_main.c | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

David Bauer July 22, 2020, 10:28 a.m. UTC | #1
Hi Sander,

this looks good, however there are two minor improvements still open.

On 7/19/20 11:24 PM, Sander Vanheule wrote:
> Some bootloaders do not set up gmac0 properly, leaving it disconnected
> from the sgmii interface. If the user specificies phy-mode sgmii, then
> use the gmac-config/device node to ensure the mux is configured
> correctly.
> 
> Signed-off-by: Sander Vanheule <sander@svanheule.net>
> Cc: David Bauer <mail@david-bauer.net>
> ---
>   .../net/ethernet/atheros/ag71xx/ag71xx_main.c | 38 +++++++++++++++++++
>   1 file changed, 38 insertions(+)
> 
> diff --git a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
> index d611007a86..e86dbfffcf 100644
> --- a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
> +++ b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
> @@ -665,6 +665,40 @@ out:
>   	of_node_put(np);
>   }
>   
> +static void ag71xx_mux_select_sgmii_qca956x(struct device_node *np)
> +{
> +	struct device_node *np_dev;
> +	void __iomem *gmac_base;
> +	int err = 0;

Remove this, as it is only assigned but never accessed.

> +	u32 serdes_cal;

This is never used.

I'll test this patch on my QCA9563 and QCA9561 devices and report back.

Best wishes
David

> +	u32 t;
> +
> +	np = of_get_child_by_name(np, "gmac-config");
> +	if (!np)
> +		return;
> +
> +	np_dev = of_parse_phandle(np, "device", 0);
> +	if (!np_dev)
> +		goto out;
> +
> +	gmac_base = of_iomap(np_dev, 0);
> +	if (!gmac_base) {
> +		pr_err("%pOF: can't map GMAC registers\n", np_dev);
> +		err = -ENOMEM;
> +		goto err_iomap;
> +	}
> +
> +	t = __raw_readl(gmac_base + QCA956X_GMAC_REG_ETH_CFG);
> +	t |= QCA956X_ETH_CFG_GE0_SGMII;
> +	__raw_writel(t, gmac_base + QCA956X_GMAC_REG_ETH_CFG);
> +
> +	iounmap(gmac_base);
> +err_iomap:
> +	of_node_put(np_dev);
> +out:
> +	of_node_put(np);
> +}
> +
>   static void ath79_mii_ctrl_set_if(struct ag71xx *ag, unsigned int mii_if)
>   {
>   	u32 t;
> @@ -1566,6 +1600,10 @@ static int ag71xx_probe(struct platform_device *pdev)
>   		return ag->phy_if_mode;
>   	}
>   
> +	if (of_device_is_compatible(np, "qca,qca9560-eth") &&
> +	    ag->phy_if_mode == PHY_INTERFACE_MODE_SGMII)
> +		ag71xx_mux_select_sgmii_qca956x(np);
> +
>   	if (of_property_read_u32(np, "qca,mac-idx", &ag->mac_idx))
>   		ag->mac_idx = -1;
>   	if (ag->mii_base)
>
Sander Vanheule July 22, 2020, 4:33 p.m. UTC | #2
Hi David,

On Wed, 2020-07-22 at 12:28 +0200, David Bauer wrote:
> Hi Sander,
> 
> this looks good, however there are two minor improvements still open.
> 
> > +	int err = 0;
> 
> Remove this, as it is only assigned but never accessed.
> 
> > +	u32 serdes_cal;
> 
> This is never used.
> 

I had copied the bulk of this function from the qca956x serdes init
function (patch 2/6), so I missed these when editing the code. Should
be all cleaned up now. Since the err variable was also unused in patch
2/6, I've removed it there too.

> I'll test this patch on my QCA9563 and QCA9561 devices and report
> back.

I've now tested it on my EAP245 v1 and v3. Both have a QCA9563, but
only the latter has the ethernet interface enabled correctly by the
bootloader (and didn't need this patch).

Best,
Sander
diff mbox series

Patch

diff --git a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
index d611007a86..e86dbfffcf 100644
--- a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
+++ b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
@@ -665,6 +665,40 @@  out:
 	of_node_put(np);
 }
 
+static void ag71xx_mux_select_sgmii_qca956x(struct device_node *np)
+{
+	struct device_node *np_dev;
+	void __iomem *gmac_base;
+	int err = 0;
+	u32 serdes_cal;
+	u32 t;
+
+	np = of_get_child_by_name(np, "gmac-config");
+	if (!np)
+		return;
+
+	np_dev = of_parse_phandle(np, "device", 0);
+	if (!np_dev)
+		goto out;
+
+	gmac_base = of_iomap(np_dev, 0);
+	if (!gmac_base) {
+		pr_err("%pOF: can't map GMAC registers\n", np_dev);
+		err = -ENOMEM;
+		goto err_iomap;
+	}
+
+	t = __raw_readl(gmac_base + QCA956X_GMAC_REG_ETH_CFG);
+	t |= QCA956X_ETH_CFG_GE0_SGMII;
+	__raw_writel(t, gmac_base + QCA956X_GMAC_REG_ETH_CFG);
+
+	iounmap(gmac_base);
+err_iomap:
+	of_node_put(np_dev);
+out:
+	of_node_put(np);
+}
+
 static void ath79_mii_ctrl_set_if(struct ag71xx *ag, unsigned int mii_if)
 {
 	u32 t;
@@ -1566,6 +1600,10 @@  static int ag71xx_probe(struct platform_device *pdev)
 		return ag->phy_if_mode;
 	}
 
+	if (of_device_is_compatible(np, "qca,qca9560-eth") &&
+	    ag->phy_if_mode == PHY_INTERFACE_MODE_SGMII)
+		ag71xx_mux_select_sgmii_qca956x(np);
+
 	if (of_property_read_u32(np, "qca,mac-idx", &ag->mac_idx))
 		ag->mac_idx = -1;
 	if (ag->mii_base)