Subject: Re: [PATCH v3 2/3] lan78xx: Read LED states from Device Tree

From: Andrew Lunn <[email-masked]>
Date: Thu, 19 Apr 2018 17:19:21 +0200

> @@ -2077,6 +2085,28 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
>  	mii_adv = (u32)mii_advertise_flowctrl(dev->fc_request_control);
>  	phydev->advertising |= mii_adv_to_ethtool_adv_t(mii_adv);
>  
> +	if (phydev->mdio.dev.of_node) {
> +		u32 reg;
> +		int len;
> +
> +		len = of_property_count_elems_of_size(phydev->mdio.dev.of_node,
> +						      "microchip,led-modes",
> +						      sizeof(u32));
> +		if (len >= 0) {
> +			/* Ensure the appropriate LEDs are enabled */
> +			lan78xx_read_reg(dev, HW_CFG, &reg);
> +			reg &= ~(HW_CFG_LED0_EN_ |
> +				 HW_CFG_LED1_EN_ |
> +				 HW_CFG_LED2_EN_ |
> +				 HW_CFG_LED3_EN_);
> +			reg |= (len > 0) * HW_CFG_LED0_EN_ |
> +				(len > 1) * HW_CFG_LED1_EN_ |
> +				(len > 2) * HW_CFG_LED2_EN_ |
> +				(len > 3) * HW_CFG_LED3_EN_;
> +			lan78xx_write_reg(dev, HW_CFG, reg);
> +		}
> +	}
> +

Humm. Not nice. But i cannot think of a cleaner way of doing this.

Reviewed-by: Andrew Lunn <[email-masked]>

    Andrew