Skip to content

Commit 727695e

Browse files
pameruosofrank-w
authored andcommitted
net: phy: as21xxx: apply a default LED configuration
The driver never programs the VEND1_LED_REG() event field on its own, it only reacts to the LED class devices instantiated by of_phy_leds(). Two things follow from that and both end up with dark RJ45 LEDs. Without a "leds" node in the PHY device tree node the event registers keep their post firmware-load reset value, which is not a link or activity pattern. With a "leds" node the situation is worse: of_phy_leds() runs from phy_probe(), long before phy_attach_direct() populates phydev->attached_dev, so phy_led_hw_control_get_device() returns NULL, the netdev trigger falls back to software mode with no interface bound and the initial brightness update writes EVENT_OFF to the PHY. Program a default from config_init(), which runs on phy_init_hw() and therefore after of_phy_leds(). Keep LED0 as link-plus-activity and change LED1 to indicate any link speed, matching the expected board behavior where yellow is solid when link is up. Userspace and the netdev trigger can still override this at any time through the LED class devices. While at it register config_init on the AS212xx and AS215xx entries too, so the default applies to every supported variant instead of only AS2101x. Signed-off-by: Pietro Ameruoso <p.ameruoso@live.it>
1 parent a1cfc7e commit 727695e

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

drivers/net/phy/as21xxx.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,53 @@ static int as21xxx_probe(struct phy_device *phydev)
640640
return 0;
641641
}
642642

643+
static int as21xxx_led_set_event(struct phy_device *phydev, u8 index,
644+
enum as21xxx_led_event event)
645+
{
646+
return phy_modify_mmd(phydev, MDIO_MMD_VEND1,
647+
VEND1_LED_REG(index),
648+
VEND1_LED_REG_A_EVENT,
649+
FIELD_PREP(VEND1_LED_REG_A_EVENT, event));
650+
}
651+
652+
#define AS21XXX_LED_BLINK_RATE_15_6HZ 0x1
653+
654+
/* Default LED setup:
655+
* LED0 On: link detected, blink: Rx/Tx activity
656+
* LED1 On: any link detected
657+
*
658+
* The firmware leaves the LED event registers unconfigured and registering
659+
* the DT LED class devices drives them to EVENT_OFF, so program the defaults
660+
* here. config_init() runs after of_phy_leds(), and userspace or the netdev
661+
* trigger can still override them later.
662+
*/
663+
static int as21xxx_led_config_default(struct phy_device *phydev)
664+
{
665+
int ret;
666+
667+
ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, VEND1_LED_CONF,
668+
VEND1_LED_CONFG_BLINK,
669+
FIELD_PREP(VEND1_LED_CONFG_BLINK,
670+
AS21XXX_LED_BLINK_RATE_15_6HZ));
671+
if (ret)
672+
return ret;
673+
674+
ret = as21xxx_led_set_event(phydev, 0,
675+
VEND1_LED_REG_A_EVENT_ON_LINK_BLINK_ACT);
676+
if (ret)
677+
return ret;
678+
679+
return as21xxx_led_set_event(phydev, 1, VEND1_LED_REG_A_EVENT_ON_LINK);
680+
}
681+
643682
static int as21xxx_config_init(struct phy_device *phydev)
644683
{
684+
int ret;
685+
686+
ret = as21xxx_led_config_default(phydev);
687+
if (ret)
688+
return ret;
689+
645690
if (phydev->interface == PHY_INTERFACE_MODE_USXGMII)
646691
return aeon_dpc_ra_enable(phydev);
647692

@@ -1159,6 +1204,7 @@ static struct phy_driver as21xxx_drivers[] = {
11591204
.name = "Aeonsemi AS21210PB1",
11601205
.probe = as21xxx_probe,
11611206
.match_phy_device = as21xxx_match_phy_device,
1207+
.config_init = as21xxx_config_init,
11621208
.read_status = as21xxx_read_status,
11631209
.read_mmd = as21xxx_read_mmd,
11641210
.led_brightness_set = as21xxx_led_brightness_set,
@@ -1173,6 +1219,7 @@ static struct phy_driver as21xxx_drivers[] = {
11731219
.name = "Aeonsemi AS21510JB1",
11741220
.probe = as21xxx_probe,
11751221
.match_phy_device = as21xxx_match_phy_device,
1222+
.config_init = as21xxx_config_init,
11761223
.read_status = as21xxx_read_status,
11771224
.read_mmd = as21xxx_read_mmd,
11781225
.led_brightness_set = as21xxx_led_brightness_set,
@@ -1187,6 +1234,7 @@ static struct phy_driver as21xxx_drivers[] = {
11871234
.name = "Aeonsemi AS21510PB1",
11881235
.probe = as21xxx_probe,
11891236
.match_phy_device = as21xxx_match_phy_device,
1237+
.config_init = as21xxx_config_init,
11901238
.read_status = as21xxx_read_status,
11911239
.read_mmd = as21xxx_read_mmd,
11921240
.led_brightness_set = as21xxx_led_brightness_set,
@@ -1201,6 +1249,7 @@ static struct phy_driver as21xxx_drivers[] = {
12011249
.name = "Aeonsemi AS21511JB1",
12021250
.probe = as21xxx_probe,
12031251
.match_phy_device = as21xxx_match_phy_device,
1252+
.config_init = as21xxx_config_init,
12041253
.read_status = as21xxx_read_status,
12051254
.read_mmd = as21xxx_read_mmd,
12061255
.led_brightness_set = as21xxx_led_brightness_set,
@@ -1215,6 +1264,7 @@ static struct phy_driver as21xxx_drivers[] = {
12151264
.name = "Aeonsemi AS21210JB1",
12161265
.probe = as21xxx_probe,
12171266
.match_phy_device = as21xxx_match_phy_device,
1267+
.config_init = as21xxx_config_init,
12181268
.read_status = as21xxx_read_status,
12191269
.read_mmd = as21xxx_read_mmd,
12201270
.led_brightness_set = as21xxx_led_brightness_set,
@@ -1229,6 +1279,7 @@ static struct phy_driver as21xxx_drivers[] = {
12291279
.name = "Aeonsemi AS21511PB1",
12301280
.probe = as21xxx_probe,
12311281
.match_phy_device = as21xxx_match_phy_device,
1282+
.config_init = as21xxx_config_init,
12321283
.read_status = as21xxx_read_status,
12331284
.read_mmd = as21xxx_read_mmd,
12341285
.led_brightness_set = as21xxx_led_brightness_set,

0 commit comments

Comments
 (0)