Skip to content

Commit

Permalink
ksz9477: MMD indirect access check fix
Browse files Browse the repository at this point in the history
Instead of verifying MMD indirect access by checking
EEE ADVERTISEMENT register has value 0x6 (which may be changed),
the verification is done by write and check LED MODE register.
First write value Single-LED mode (0x10), then read the value back
to verify value matches with the written one and then finally write
back the original default value (0x00).
  • Loading branch information
Jari Nippula committed Sep 20, 2024
1 parent 7c4bf98 commit 7b20aa2
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions drivers/net/ksz9477.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,46 @@ int ksz9477_init(ksz9477_port_t master_port)
}

/* Check that indirect access to PHY MMD works.
* Default value of MMD EEE ADVERTISEMENT REGISTER is 0x6
* Write LED mode to single-LED mode and verify access by
* reading back the value.
*/

/* Set LED mode to sigle-LED mode */

regval16 = 0x10;
ret = ksz9477_mmd_write_indirect(KSZ9477_PORT_PHY1,
KSZ9477_MMD_DEV_LED_MODE,
0x00, &regval16, 1);
if (ret != OK)
{
nerr("MMD access failure. Failed write 0x%04x to "
"LED_MODE register: ret %d\n", regval16, ret);
return ret ? ret : -EINVAL;
}

/* Verify read returns Single-LED mode (0x10) */

ret = ksz9477_mmd_read_indirect(KSZ9477_PORT_PHY1,
KSZ9477_MMD_DEV_EEE_ADVERTISEMENT,
0x3c, &regval16, 1);
if (ret != OK || regval16 != 0x6)
KSZ9477_MMD_DEV_LED_MODE,
0x00, &regval16, 1);

if (ret != OK || regval16 != 0x10)
{
nerr("MMD access failure. Failed to verify LED_MODE "
"register value 0x10: ret %d, regval %04x\n", ret, regval16);
return ret ? ret : -EINVAL;
}

/* Set back to default value (0x00) */

regval16 = 0x00;
ret = ksz9477_mmd_write_indirect(KSZ9477_PORT_PHY1,
KSZ9477_MMD_DEV_LED_MODE,
0x00, &regval16, 1);
if (ret != OK)
{
nerr("MMD access failure, ret %d\n", ret);
nerr("MMD access failure. Failed to write 0x%04x to "
"LED_MODE register: ret %d\n", regval16, ret);
return ret ? ret : -EINVAL;
}

Expand Down

0 comments on commit 7b20aa2

Please sign in to comment.