<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">Index: meson_dwmac.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/amlogic/meson_dwmac.c,v
retrieving revision 1.12
diff -u -p -r1.12 meson_dwmac.c
--- meson_dwmac.c	7 Nov 2021 19:21:32 -0000	1.12
+++ meson_dwmac.c	17 Nov 2021 19:02:52 -0000
@@ -1,4 +1,4 @@
-/* $NetBSD: meson_dwmac.c,v 1.12 2021/11/07 19:21:32 jmcneill Exp $ */
+/* $NetBSD: meson_dwmac.c,v 1.13 2021/11/17 11:57:27 jdc Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill &lt;jmcneill@invisible.ca&gt;
@@ -28,7 +28,7 @@
 
 #include &lt;sys/cdefs.h&gt;
 
-__KERNEL_RCSID(0, "$NetBSD: meson_dwmac.c,v 1.12 2021/11/07 19:21:32 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: meson_dwmac.c,v 1.13 2021/11/17 11:57:27 jdc Exp $");
 
 #include &lt;sys/param.h&gt;
 #include &lt;sys/bus.h&gt;
@@ -66,16 +66,17 @@ static const struct device_compatible_en
 };
 
 static int
-meson_dwmac_reset(const int phandle)
+meson_dwmac_reset_eth(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);
+	pin_reset = fdtbus_gpio_acquire(phandle, "snps,reset-gpio",
+	    GPIO_PIN_OUTPUT);
 	if (pin_reset == NULL)
-		return 0;
+		return ENXIO;
 
 	reset_delay_us = fdtbus_get_prop(phandle, "snps,reset-delays-us", &amp;len);
 	if (reset_delay_us == NULL || len != 12)
@@ -95,6 +96,41 @@ meson_dwmac_reset(const int phandle)
 	return 0;
 }
 
+static int
+meson_dwmac_reset_phy(const int phandle)
+{
+	struct fdtbus_gpio_pin *pin_reset;
+	const u_int *reset_assert_us, *reset_deassert_us, *reset_gpios;
+	bool reset_active_low;
+	int len, val;
+
+	pin_reset = fdtbus_gpio_acquire(phandle, "reset-gpios",
+	    GPIO_PIN_OUTPUT);
+	if (pin_reset == NULL)
+		return ENXIO;
+
+	reset_assert_us = fdtbus_get_prop(phandle, "reset-assert-us", &amp;len);
+	if (reset_assert_us == NULL || len != 4)
+		return ENXIO;
+	reset_deassert_us = fdtbus_get_prop(phandle, "reset-deassert-us", &amp;len);
+	if (reset_deassert_us == NULL || len != 4)
+		return ENXIO;
+	reset_gpios = fdtbus_get_prop(phandle, "reset-gpios", &amp;len);
+	if (reset_gpios == NULL || len != 12)
+		return ENXIO;
+
+	reset_active_low = be32toh(reset_gpios[2]);
+
+	val = reset_active_low ? 1 : 0;
+
+	fdtbus_gpio_write(pin_reset, val);
+	delay(be32toh(reset_assert_us[0]));
+	fdtbus_gpio_write(pin_reset, !val);
+	delay(be32toh(reset_deassert_us[0]));
+
+	return 0;
+}
+
 static void
 meson_dwmac_set_mode_rgmii(int phandle, bus_space_tag_t bst,
     bus_space_handle_t bsh, struct clk *clkin)
@@ -237,8 +273,19 @@ meson_dwmac_attach(device_t parent, devi
 	}
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
-	if (meson_dwmac_reset(phandle_phy) != 0)
-		aprint_error_dev(self, "PHY reset failed\n");
+	/*
+	 * Depending on the DTS, we need to check either the "snps,...",
+	 * properties on the ethernet node, or the "reset-..."
+	 * properties on the pny node for the MAC reset information.
+	 */
+
+	if (of_hasprop(phandle, "snps,reset-gpio")) {
+		if (meson_dwmac_reset_eth(phandle) != 0)
+			aprint_error_dev(self, "PHY reset failed\n");
+	} else {
+		if (meson_dwmac_reset_phy(phandle_phy) != 0)
+			aprint_error_dev(self, "PHY reset failed\n");
+	}
 
 	miiclk_rate = clk_get_rate(clk_gmac);
 	if (miiclk_rate &gt; 250 * 1000 * 1000)
</pre></body></html>