From c2122bd8ae0f75f66a38bff4e5a4e5592ee3e21d Mon Sep 17 00:00:00 2001 From: ian Date: Mon, 20 May 2019 22:32:31 +0000 Subject: [PATCH] Reverse the bit logic of sc_led_modes_mask. Instead of initializing it to all-ones then carving out blocks of zeroes where specified values go, init it to all-zeroes, put in ones where values need to be masked, then use it as value &= ~sc_led_modes_mask. In addition to being more idiomatic, this means everything related to FDT data is initialized to zero along with the rest of the softc, and that allows removing some #ifdef FDT sections and wrapping the whole muge_set_leds() function in a single ifdef block. This also deletes the early-out from muge_set_leds() when an eeprom exists. Even if there is an eeprom with led config in it, the fdt data (if present) should override that, because the user is in control of the fdt data. --- sys/dev/usb/net/if_muge.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/sys/dev/usb/net/if_muge.c b/sys/dev/usb/net/if_muge.c index 1bc05c387f3..47d57a253fa 100644 --- a/sys/dev/usb/net/if_muge.c +++ b/sys/dev/usb/net/if_muge.c @@ -938,10 +938,10 @@ lan78xx_phy_init(struct muge_softc *sc) bmcr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR); /* Configure LED Modes. */ - if (sc->sc_led_modes_mask != 0xffff) { + if (sc->sc_led_modes_mask != 0) { lmsr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MUGE_PHY_LED_MODE); - lmsr &= sc->sc_led_modes_mask; + lmsr &= ~sc->sc_led_modes_mask; lmsr |= sc->sc_led_modes; lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MUGE_PHY_LED_MODE, lmsr); @@ -1526,20 +1526,13 @@ muge_set_mac_addr(struct usb_ether *ue) static void muge_set_leds(struct usb_ether *ue) { - struct muge_softc *sc = uether_getsc(ue); #ifdef FDT + struct muge_softc *sc = uether_getsc(ue); phandle_t node; pcell_t modes[4]; /* 4 LEDs are possible */ ssize_t proplen; uint32_t count; -#endif - sc->sc_leds = 0; /* no LED mode is set */ - sc->sc_led_modes = 0; - sc->sc_led_modes_mask = 0xffff; - if (lan78xx_eeprom_present(sc)) - return; -#ifdef FDT if ((node = usb_fdt_get_node(ue->ue_dev, ue->ue_udev)) != -1 && (proplen = OF_getencprop(node, "microchip,led-modes", modes, sizeof(modes))) > 0) { @@ -1550,7 +1543,7 @@ muge_set_leds(struct usb_ether *ue) (count > 3) * ETH_HW_CFG_LED3_EN_; while (count-- > 0) { sc->sc_led_modes |= (modes[count] & 0xf) << (4 * count); - sc->sc_led_modes_mask <<= 4; + sc->sc_led_modes_mask |= 0xf << (4 * count); } muge_dbg_printf(sc, "LED modes set from FDT data\n"); } -- 2.45.0