From owner-svn-src-all@freebsd.org Mon May 20 18:41:08 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5FA2215B564A; Mon, 20 May 2019 18:41:08 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 025AF8CBCF; Mon, 20 May 2019 18:41:08 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D2C2822280; Mon, 20 May 2019 18:41:07 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4KIf7uk091576; Mon, 20 May 2019 18:41:07 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4KIf7eD091575; Mon, 20 May 2019 18:41:07 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201905201841.x4KIf7eD091575@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Mon, 20 May 2019 18:41:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r348001 - head/sys/dev/usb/net X-SVN-Group: head X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: head/sys/dev/usb/net X-SVN-Commit-Revision: 348001 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 025AF8CBCF X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.973,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 May 2019 18:41:08 -0000 Author: emaste Date: Mon May 20 18:41:07 2019 New Revision: 348001 URL: https://svnweb.freebsd.org/changeset/base/348001 Log: muge: configure LEDs per dtb (for Raspberry Pi 3B+) Also apply some style(9) and remove the message about EEPROM configuration (if there's an EEPROM the hardware handles LED configuration itself). PR: 237325 Reviewed by: ian MFC after: 2 weeks Submitted by: Ralf Modified: head/sys/dev/usb/net/if_muge.c Modified: head/sys/dev/usb/net/if_muge.c ============================================================================== --- head/sys/dev/usb/net/if_muge.c Mon May 20 18:35:23 2019 (r348000) +++ head/sys/dev/usb/net/if_muge.c Mon May 20 18:41:07 2019 (r348001) @@ -173,6 +173,7 @@ struct muge_softc { struct mtx sc_mtx; struct usb_xfer *sc_xfer[MUGE_N_TRANSFER]; int sc_phyno; + uint32_t sc_leds; /* Settings for the mac control (MAC_CSR) register. */ uint32_t sc_rfe_ctl; @@ -891,6 +892,7 @@ lan78xx_phy_init(struct muge_softc *sc) muge_dbg_printf(sc, "Initializing PHY.\n"); uint16_t bmcr; usb_ticks_t start_ticks; + uint32_t hw_reg; const usb_ticks_t max_ticks = USB_MS_TO_TICKS(1000); MUGE_LOCK_ASSERT(sc, MA_OWNED); @@ -931,6 +933,15 @@ lan78xx_phy_init(struct muge_softc *sc) bmcr |= BMCR_AUTOEN; lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR, bmcr); bmcr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR); + + /* Enable appropriate LEDs. */ + if (sc->sc_leds != 0 && + lan78xx_read_reg(sc, ETH_HW_CFG, &hw_reg) == 0) { + hw_reg &= ~(ETH_HW_CFG_LEDO_EN_ | ETH_HW_CFG_LED1_EN_ | + ETH_HW_CFG_LED2_EN_ | ETH_HW_CFG_LED3_EN_ ); + hw_reg |= sc->sc_leds; + lan78xx_write_reg(sc, ETH_HW_CFG, hw_reg); + } return (0); } @@ -1523,6 +1534,37 @@ muge_fdt_find_mac(const char *compatible, unsigned cha return (ENXIO); } + +/** + * muge_fdt_count_led_modes - read number of LED modes from node + * @compatible: compatible string for DTB node in the form + * "usb[N]NNN,[M]MMM" + * where NNN is vendor id and MMM is product id + * @amount: memory to store number of LED entries to + * + * Tries to find matching node in DTS and obtain number of entries from it. + * + * RETURNS: + * Returns 0 on success, error code otherwise + */ +static int +muge_fdt_count_led_modes(struct muge_softc *sc, const char *compatible, + uint32_t *amount) +{ + phandle_t node, root; + ssize_t proplen; + + *amount = 0; + root = OF_finddevice("/"); + node = muge_fdt_find_eth_node(root, compatible); + if (node != -1 && + (proplen = OF_getproplen(node, "microchip,led-modes")) > 0) { + *amount = proplen / sizeof( uint32_t ); + return (0); + } + + return (ENXIO); +} #endif /** @@ -1591,6 +1633,41 @@ muge_set_mac_addr(struct usb_ether *ue) } /** + * muge_set_leds - Initializes NIC LEDs pattern + * @ue: the USB ethernet device + * + * Tries to store the LED modes. + * Supports only DTB blob like the Linux driver does. + */ +static void +muge_set_leds(struct usb_ether *ue) +{ + struct muge_softc *sc = uether_getsc(ue); +#ifdef FDT + char compatible[16]; + struct usb_attach_arg *uaa = device_get_ivars(ue->ue_dev); + uint32_t count; +#endif + + sc->sc_leds = 0; /* no LED mode is set */ + if (lan78xx_eeprom_present(sc)) + return; +#ifdef FDT + snprintf(compatible, sizeof(compatible), "usb%x,%x", + uaa->info.idVendor, uaa->info.idProduct); + if (muge_fdt_count_led_modes(sc, compatible, &count) == 0) { + sc->sc_leds = (count > 0) * ETH_HW_CFG_LEDO_EN_ | + (count > 1) * ETH_HW_CFG_LED1_EN_ | + (count > 2) * ETH_HW_CFG_LED2_EN_ | + (count > 3) * ETH_HW_CFG_LED3_EN_; + muge_dbg_printf(sc, "LED modes set from FDT blob\n"); + return; + } +#endif + muge_dbg_printf(sc, "LED configuration not available\n"); +} + +/** * muge_attach_post - Called after the driver attached to the USB interface * @ue: the USB ethernet device * @@ -1610,6 +1687,7 @@ muge_attach_post(struct usb_ether *ue) sc->sc_phyno = 1; muge_set_mac_addr(ue); + muge_set_leds(ue); /* Initialise the chip for the first time */ lan78xx_chip_init(sc);