Commit 221a5344 authored by Parthiban Veerasooran's avatar Parthiban Veerasooran Committed by Paolo Abeni

net: phy: microchip_t1s: replace read-modify-write code with phy_modify_mmd

Replace read-modify-write code in the lan867x_config_init function to
avoid handling data type mismatch and to simplify the code.
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarParthiban Veerasooran <Parthiban.Veerasooran@microchip.com>
Reviewed-by: default avatarRamón Nordin Rodriguez <ramon.nordin.rodriguez@ferroamp.se>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent ca33db4a
...@@ -31,19 +31,19 @@ ...@@ -31,19 +31,19 @@
* W 0x1F 0x0099 0x7F80 ------ * W 0x1F 0x0099 0x7F80 ------
*/ */
static const int lan867x_fixup_registers[12] = { static const u32 lan867x_fixup_registers[12] = {
0x00D0, 0x00D1, 0x0084, 0x0085, 0x00D0, 0x00D1, 0x0084, 0x0085,
0x008A, 0x0087, 0x0088, 0x008B, 0x008A, 0x0087, 0x0088, 0x008B,
0x0080, 0x00F1, 0x0096, 0x0099, 0x0080, 0x00F1, 0x0096, 0x0099,
}; };
static const int lan867x_fixup_values[12] = { static const u16 lan867x_fixup_values[12] = {
0x0002, 0x0000, 0x3380, 0x0006, 0x0002, 0x0000, 0x3380, 0x0006,
0xC000, 0x801C, 0x033F, 0x0404, 0xC000, 0x801C, 0x033F, 0x0404,
0x0600, 0x2400, 0x2000, 0x7F80, 0x0600, 0x2400, 0x2000, 0x7F80,
}; };
static const int lan867x_fixup_masks[12] = { static const u16 lan867x_fixup_masks[12] = {
0x0E03, 0x0300, 0xFFC0, 0x000F, 0x0E03, 0x0300, 0xFFC0, 0x000F,
0xF800, 0x801C, 0x1FFF, 0xFFFF, 0xF800, 0x801C, 0x1FFF, 0xFFFF,
0x0600, 0x7F00, 0x2000, 0xFFFF, 0x0600, 0x7F00, 0x2000, 0xFFFF,
...@@ -51,35 +51,20 @@ static const int lan867x_fixup_masks[12] = { ...@@ -51,35 +51,20 @@ static const int lan867x_fixup_masks[12] = {
static int lan867x_config_init(struct phy_device *phydev) static int lan867x_config_init(struct phy_device *phydev)
{ {
/* HW quirk: Microchip states in the application note (AN1699) for the phy
* that a set of read-modify-write (rmw) operations has to be performed
* on a set of seemingly magic registers.
* The result of these operations is just described as 'optimal performance'
* Microchip gives no explanation as to what these mmd regs do,
* in fact they are marked as reserved in the datasheet.
* It is unclear if phy_modify_mmd would be safe to use or if a write
* really has to happen to each register.
* In order to exactly conform to what is stated in the AN phy_write_mmd is
* used, which might then write the same value back as read + modified.
*/
int reg_value;
int err; int err;
int reg;
/* Read-Modified Write Pseudocode (from AN1699) /* Reference to AN1699
* current_val = read_register(mmd, addr) // Read current register value * https://ww1.microchip.com/downloads/aemDocuments/documents/AIS/ProductDocuments/SupportingCollateral/AN-LAN8670-1-2-config-60001699.pdf
* new_val = current_val AND (NOT mask) // Clear bit fields to be written * AN1699 says Read, Modify, Write, but the Write is not required if the
* new_val = new_val OR value // Set bits * register already has the required value. So it is safe to use
* write_register(mmd, addr, new_val) // Write back updated register value * phy_modify_mmd here.
*/ */
for (int i = 0; i < ARRAY_SIZE(lan867x_fixup_registers); i++) { for (int i = 0; i < ARRAY_SIZE(lan867x_fixup_registers); i++) {
reg = lan867x_fixup_registers[i]; err = phy_modify_mmd(phydev, MDIO_MMD_VEND2,
reg_value = phy_read_mmd(phydev, MDIO_MMD_VEND2, reg); lan867x_fixup_registers[i],
reg_value &= ~lan867x_fixup_masks[i]; lan867x_fixup_masks[i],
reg_value |= lan867x_fixup_values[i]; lan867x_fixup_values[i]);
err = phy_write_mmd(phydev, MDIO_MMD_VEND2, reg, reg_value); if (err)
if (err != 0)
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment