Module Name:    src
Committed By:   jmcneill
Date:           Sat Oct  7 19:42:45 UTC 2017

Modified Files:
        src/sys/arch/arm/sunxi: sunxi_gmac.c

Log Message:
Support snps,reset-gpio property and deassert optional stmmaceth reset.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_gmac.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/sunxi_gmac.c
diff -u src/sys/arch/arm/sunxi/sunxi_gmac.c:1.1 src/sys/arch/arm/sunxi/sunxi_gmac.c:1.2
--- src/sys/arch/arm/sunxi/sunxi_gmac.c:1.1	Sat Oct  7 13:28:59 2017
+++ src/sys/arch/arm/sunxi/sunxi_gmac.c	Sat Oct  7 19:42:45 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_gmac.c,v 1.1 2017/10/07 13:28:59 jmcneill Exp $ */
+/* $NetBSD: sunxi_gmac.c,v 1.2 2017/10/07 19:42:45 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca>
@@ -28,13 +28,14 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_gmac.c,v 1.1 2017/10/07 13:28:59 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_gmac.c,v 1.2 2017/10/07 19:42:45 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
 #include <sys/device.h>
 #include <sys/intr.h>
 #include <sys/systm.h>
+#include <sys/gpio.h>
 
 #include <net/if.h>
 #include <net/if_ether.h>
@@ -56,6 +57,36 @@ static const char * compatible[] = {
 };
 
 static int
+sunxi_gmac_reset(const int phandle)
+{
+	struct fdtbus_gpio_pin *pin_reset;
+	const u_int *reset_delay_us;
+	bool reset_active_low;
+	int len, val;
+
+	pin_reset = fdtbus_gpio_acquire(phandle, "snps,reset-gpio", GPIO_PIN_OUTPUT);
+	if (pin_reset == NULL)
+		return 0;
+
+	reset_delay_us = fdtbus_get_prop(phandle, "snps,reset-delays-us", &len);
+	if (reset_delay_us == NULL || len != 12)
+		return ENXIO;
+
+	reset_active_low = of_hasprop(phandle, "snps,reset-active-low");
+
+	val = reset_active_low ? 1 : 0;
+
+	fdtbus_gpio_write(pin_reset, val);
+	delay(be32toh(reset_delay_us[0]));
+	fdtbus_gpio_write(pin_reset, !val);
+	delay(be32toh(reset_delay_us[1]));
+	fdtbus_gpio_write(pin_reset, val);
+	delay(be32toh(reset_delay_us[2]));
+
+	return 0;
+}
+
+static int
 sunxi_gmac_intr(void *arg)
 {
 	return dwc_gmac_intr(arg);
@@ -76,6 +107,7 @@ sunxi_gmac_attach(device_t parent, devic
 	struct fdt_attach_args * const faa = aux;
 	const int phandle = faa->faa_phandle;
 	struct clk *clk_gmac, *clk_gmac_tx;
+	struct fdtbus_reset *rst_gmac;
 	const char *phy_mode;
 	char intrstr[128];
 	bus_addr_t addr;
@@ -106,6 +138,8 @@ sunxi_gmac_attach(device_t parent, devic
 		return;
 	}
 
+	rst_gmac = fdtbus_reset_get(phandle, "stmmaceth");
+
 	phy_mode = fdtbus_get_string(phandle, "phy-mode");
 	if (phy_mode == NULL) {
 		aprint_error(": missing 'phy-mode' property\n");
@@ -131,6 +165,11 @@ sunxi_gmac_attach(device_t parent, devic
 		return;
 	}
 
+	if (rst_gmac != NULL && fdtbus_reset_deassert(rst_gmac) != 0) {
+		aprint_error(": couldn't de-assert reset\n");
+		return;
+	}
+
 	aprint_naive("\n");
 	aprint_normal(": GMAC\n");
 
@@ -140,6 +179,9 @@ sunxi_gmac_attach(device_t parent, devic
 	}
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
+	if (sunxi_gmac_reset(phandle) != 0)
+		aprint_error_dev(self, "PHY reset failed\n");
+
 	dwc_gmac_attach(sc, GMAC_MII_CLK_150_250M_DIV102);
 }
 

Reply via email to