Module Name: src Committed By: jdc Date: Fri Nov 19 07:04:27 UTC 2021
Modified Files: src/sys/arch/arm/amlogic: meson_dwmac.c Log Message: PR port-evbarm/50416 Redo the previous change. The "snps,..." properties are on the ethernet node and the "reset-..." properties are on the phy node. Handle this by creating a separate reset routine for each case. Idea from Jared. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/amlogic/meson_dwmac.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/amlogic/meson_dwmac.c diff -u src/sys/arch/arm/amlogic/meson_dwmac.c:1.13 src/sys/arch/arm/amlogic/meson_dwmac.c:1.14 --- src/sys/arch/arm/amlogic/meson_dwmac.c:1.13 Wed Nov 17 11:57:27 2021 +++ src/sys/arch/arm/amlogic/meson_dwmac.c Fri Nov 19 07:04:27 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: meson_dwmac.c,v 1.13 2021/11/17 11:57:27 jdc Exp $ */ +/* $NetBSD: meson_dwmac.c,v 1.14 2021/11/19 07:04:27 jdc Exp $ */ /*- * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> @@ -28,7 +28,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: meson_dwmac.c,v 1.13 2021/11/17 11:57:27 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: meson_dwmac.c,v 1.14 2021/11/19 07:04:27 jdc Exp $"); #include <sys/param.h> #include <sys/bus.h> @@ -66,72 +66,69 @@ 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; - const u_int *reset_assert_us, *reset_deassert_us, *reset_gpios; bool reset_active_low; int len, val; - /* - * Depending on the DTS, we need to check either the "snps,...", - * or the "reset-..." properties for the MAC reset information. - */ - pin_reset = fdtbus_gpio_acquire(phandle, "snps,reset-gpio", GPIO_PIN_OUTPUT); - if (pin_reset != NULL) { + if (pin_reset == NULL) + return ENXIO; - reset_delay_us = fdtbus_get_prop(phandle, - "snps,reset-delays-us", &len); - if (reset_delay_us == NULL || len != 12) - return ENXIO; + 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"); + reset_active_low = of_hasprop(phandle, "snps,reset-active-low"); - val = reset_active_low ? 1 : 0; + 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])); + 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; - } + 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) { - reset_assert_us = fdtbus_get_prop(phandle, - "reset-assert-us", &len); - if (reset_assert_us == NULL || len != 4) - return ENXIO; - reset_deassert_us = fdtbus_get_prop(phandle, - "reset-deassert-us", &len); - if (reset_deassert_us == NULL || len != 4) - return ENXIO; - reset_gpios = fdtbus_get_prop(phandle, - "reset-gpios", &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])); + if (pin_reset == NULL) + return ENXIO; - return 0; - } + reset_assert_us = fdtbus_get_prop(phandle, "reset-assert-us", &len); + if (reset_assert_us == NULL || len != 4) + return ENXIO; + reset_deassert_us = fdtbus_get_prop(phandle, "reset-deassert-us", &len); + if (reset_deassert_us == NULL || len != 4) + return ENXIO; + reset_gpios = fdtbus_get_prop(phandle, "reset-gpios", &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 ENXIO; + return 0; } static void @@ -276,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 phy 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 > 250 * 1000 * 1000)