Skip to contentSkip to conversation

net: ath79: add ag71xx Ethernet driver

PATCH Superseded Oleksij Rempel 2 participants 4 messages Aug 18, 2017 – Sep 12, 2017

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 net: ath79: add ag71xx Ethernet driver

From: Yegor Yefremov <[email protected]>

---
 arch/mips/mach-ath79/include/mach/ar71xx_regs.h |  12 +
 drivers/net/Kconfig                             |   7 +
 drivers/net/Makefile                            |   1 +
 drivers/net/ag71xx.c                            | 530 ++++++++++++++++++++++++
 4 files changed, 550 insertions(+)
 create mode 100644 drivers/net/ag71xx.c
arch/mips/mach-ath79/include/mach/ar71xx_regs.h +12 -0
index f56c3f724..31d33b3c4 100644
@@ -102,6 +102,8 @@
 #define AR933X_PLL_CLOCK_CTRL_REG	0x08
 #define AR933X_PLL_DITHER_FRAC_REG	0x10
 #define AR933X_PLL_DITHER_REG		0x14
+#define AR933X_ETHSW_CLOCK_CONTROL_REG	0x24
+#define AR933X_ETH_XMII_CONTROL_REG	0x2c
 
 #define AR933X_PLL_CPU_CONFIG_NINT_SHIFT	10
 #define AR933X_PLL_CPU_CONFIG_NINT_MASK		0x3f
@@ -125,6 +127,16 @@
 #define AR933X_RESET_REG_RESET_MODULE		0x1c
 #define AR933X_RESET_REG_BOOTSTRAP		0xac
 
+#define AR933X_RESET_GE1_MDIO           BIT(23)
+#define AR933X_RESET_GE0_MDIO           BIT(22)
+#define AR933X_RESET_GE1_MAC            BIT(13)
+#define AR933X_RESET_WMAC               BIT(11)
+#define AR933X_RESET_GE0_MAC            BIT(9)
+#define AR933X_RESET_SWITCH             BIT(8)
+#define AR933X_RESET_USB_HOST           BIT(5)
+#define AR933X_RESET_USB_PHY            BIT(4)
+#define AR933X_RESET_USBSUS_OVERRIDE    BIT(3)
+
 #define AR71XX_RESET_FULL_CHIP		BIT(24)
 
 #define AR933X_BOOTSTRAP_REF_CLK_40	BIT(0)
drivers/net/Kconfig +7 -0
index c3980e78f..9d69b6aeb 100644
@@ -204,6 +204,13 @@ config DRIVER_NET_EFI_SNP
 	bool "EFI SNP ethernet driver"
 	depends on EFI_BOOTUP
 
+config DRIVER_NET_AG71XX
+	bool "Atheros AG71xx ethernet driver"
+	depends on MACH_MIPS_ATH79
+	select PHYLIB
+	help
+	  This option enables support for Atheros AG71XX ethernet chip.
+
 config DRIVER_NET_TSE
 	depends on NIOS2
 	bool "Altera TSE ethernet driver"
drivers/net/Makefile +1 -0
index 42ea208e3..86c8ac32f 100644
@@ -30,3 +30,4 @@ obj-$(CONFIG_DRIVER_NET_SMC91111)	+= smc91111.o
 obj-$(CONFIG_DRIVER_NET_TAP)		+= tap.o
 obj-$(CONFIG_DRIVER_NET_TSE)		+= altera_tse.o
 obj-$(CONFIG_DRIVER_NET_EFI_SNP)	+= efi-snp.o
+obj-$(CONFIG_DRIVER_NET_AG71XX)		+= ag71xx.o
drivers/net/ag71xx.c new file +530 -0

530 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/3 net: ag71xx: bit 19 should be set to 1 for GE0

From: Antony Pavlov <[email protected]>

---
 drivers/net/ag71xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ag71xx.c +2 -1
index b2e066be3..d13bf9171 100644
@@ -492,7 +492,8 @@ static int ag71xx_probe(struct device_d *dev)
 	ag71xx_wr(priv, AG71XX_REG_FIFO_CFG2, 0xAAA0555);
 
 	ag71xx_wr(priv, AG71XX_REG_FIFO_CFG4, 0x3ffff);
-	ag71xx_wr(priv, AG71XX_REG_FIFO_CFG5, 0x66b82);
+	/* bit 19 should be set to 1 for GE0 */
+	ag71xx_wr(priv, AG71XX_REG_FIFO_CFG5, (0x66b82) | (1 << 19));
 	ag71xx_wr(priv, AG71XX_REG_FIFO_CFG3, 0x1f00140);
 
 	priv->rx_buffer = xmemalign(PAGE_SIZE, NO_OF_RX_FIFOS * MAX_RBUFF_SZ);
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 3/3 add ar9331.dtsi and enable mac0

In reply to Oleksij Rempel
---
 arch/mips/dts/ar9331.dtsi       | 12 ++++++++++++
 arch/mips/dts/tplink-mr3020.dts |  5 +++++
 2 files changed, 17 insertions(+)
 create mode 100644 arch/mips/dts/ar9331.dtsi
arch/mips/dts/ar9331.dtsi new file +12 -0
new file mode 100644
index 000000000..109af8664
@@ -0,0 +1,12 @@
+/ {
+	ahb {
+		mac0: mac@19000000 {
+			compatible = "qca,ar7100-gmac", "qca,ar9331-gmac";
+			reg = <0x18070000 0x00000100>,
+			      <0x19000000 0x01000000>;
+			reg-names = "gmac", "ge0";
+			phy-mode = "mii";
+			status = "disabled";
+               };
+	};
+};
arch/mips/dts/tplink-mr3020.dts +5 -0
index eaae11edd..6f1ad1350 100644
@@ -1,4 +1,5 @@
 #include <mips/qca/ar9331_tl_mr3020.dts>
+#include "ar9331.dtsi"
 
 / {
 	aliases {
@@ -24,3 +25,7 @@
 		reg = <0x80000 0x10000>;
 	};
 };
+
+&mac0 {
+	status = "okay";
+};
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
In reply to Oleksij Rempel
Quoted 29 lines · Oleksij Rempel

From: Yegor Yefremov <[email protected]>

---
 arch/mips/mach-ath79/include/mach/ar71xx_regs.h |  12 +
 drivers/net/Kconfig                             |   7 +
 drivers/net/Makefile                            |   1 +
 drivers/net/ag71xx.c                            | 530 ++++++++++++++++++++++++
 4 files changed, 550 insertions(+)
 create mode 100644 drivers/net/ag71xx.c
drivers/net/ag71xx.c new file +17 -0
+static int ag71xx_ether_send(struct eth_device *edev, void *packet, int length)
+{
+	struct ag71xx *priv = edev->priv;
+	struct device_d *dev = priv->dev;
+	ag7240_desc_t *f = &priv->fifo_tx[priv->next_tx];
+	int i;
+
+	/* flush */
+	dma_sync_single_for_device((unsigned long)packet, length, DMA_TO_DEVICE);
+
+	f->pkt_start_addr = virt_to_phys(packet);
+	f->res1 = 0;
+	f->pkt_size = length;
+	f->is_empty = 0;
+	ag71xx_wr(priv, AG71XX_REG_TX_DESC, virt_to_phys(f));
+	ag71xx_wr(priv, AG71XX_REG_TX_CTRL, TX_CTRL_TXE);
+

drivers/net/ag71xx.c line 360

Quoted 10 lines
drivers/net/ag71xx.c new file +10 -0
+	/* flush again?! */
+	dma_sync_single_for_cpu((unsigned long)packet, length, DMA_TO_DEVICE);
+
+	for (i = 0; i < MAX_WAIT; i++) {
+		udelay(100);
+		if (f->is_empty) {
+			break;
+		}
+	}
+

Use a is_timeout() loop. With this you won't have a minimum delay of 100us and also not a granularity of 100us.

Quoted 4 lines
drivers/net/ag71xx.c new file +4 -0
+	if (i == MAX_WAIT) {
+		dev_err(dev, "Tx Timed out\n");
+	}
+
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox