realtek: pcs: rtl93xx: add shared MAC mode wrapper

RTL930x and RTL931x share a set of extras around MAC mode writes:

 - a post-write delay (kept for consistency with the original RTL930x
   behaviour; harmless on RTL931x)
 - the force-mode bit (RTL931x only, nullable field)

Add rtpcs_93xx_sds_set_mac_mode() as a shared wrapper around the
generic rtpcs_sds_set_mac_mode() that applies each of these extras
unconditionally; the nullable field makes the force-bit write a no-op
on RTL930x.

Route the three RTL93xx call sites (the 930x and 931x set_mode
dispatchers, and 931x set_ip_mode's OFF transition) through the
wrapper, removing the duplicated force-bit handling from each.

The USXGMII submode write stays out of the wrapper and is called
explicitly from the 930x dispatcher via rtpcs_93xx_sds_apply_usxgmii_submode().
Keeping submode as a separate step leaves room for RTL931x to apply it
from its IP-mode path once the submode register is wired up, without
retrofitting a MAC-mode wrapper with side effects.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23040
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
Jonas Jelonek 2026-04-22 07:39:58 +00:00 committed by Robert Marko
parent 1eeb9027d5
commit 6a23733437

View File

@ -1446,6 +1446,32 @@ static int rtpcs_93xx_sds_apply_usxgmii_submode(struct rtpcs_serdes *sds,
return regmap_field_write(sds->swcore_regs.usxgmii_submode, submode);
}
/*
* RTL93XX wrapper: set MAC mode, then handle variant-specific extras:
* - post-write delay (required on 930x)
* - force-mode bit (931x only; nullable field)
*
* Each extra no-ops on the variant that doesn't need it either because
* the corresponding regmap_field is NULL, or because the mode doesn't match.
*/
static int rtpcs_93xx_sds_set_mac_mode(struct rtpcs_serdes *sds, enum rtpcs_sds_mode hw_mode)
{
int ret;
ret = rtpcs_sds_set_mac_mode(sds, hw_mode);
if (ret)
return ret;
msleep(10);
if (sds->swcore_regs.mac_mode_force) {
ret = regmap_field_write(sds->swcore_regs.mac_mode_force, 1);
if (ret)
return ret;
}
return 0;
}
/* RTL930X */
/* This mapping is not coherent so it cannot be expressed arithmetically */
@ -1789,12 +1815,10 @@ static int rtpcs_930x_sds_set_mode(struct rtpcs_serdes *sds, enum rtpcs_sds_mode
break;
}
ret = rtpcs_sds_set_mac_mode(sds, hw_mode);
ret = rtpcs_93xx_sds_set_mac_mode(sds, hw_mode);
if (ret)
return ret;
msleep(10);
return rtpcs_93xx_sds_apply_usxgmii_submode(sds, hw_mode);
}
@ -3190,11 +3214,7 @@ static int rtpcs_931x_sds_set_ip_mode(struct rtpcs_serdes *sds,
/* clear symbol error count before changing mode */
rtpcs_931x_sds_clear_symerr(sds, hw_mode);
ret = rtpcs_sds_set_mac_mode(sds, RTPCS_SDS_MODE_OFF);
if (ret)
return ret;
ret = regmap_field_write(sds->swcore_regs.mac_mode_force, 1);
ret = rtpcs_93xx_sds_set_mac_mode(sds, RTPCS_SDS_MODE_OFF);
if (ret)
return ret;
@ -3248,14 +3268,10 @@ static int rtpcs_931x_sds_set_ip_mode(struct rtpcs_serdes *sds,
static int rtpcs_931x_sds_set_mode(struct rtpcs_serdes *sds,
enum rtpcs_sds_mode hw_mode)
{
if (hw_mode == RTPCS_SDS_MODE_XSGMII) {
int ret = rtpcs_sds_set_mac_mode(sds, hw_mode);
if (ret)
return ret;
if (hw_mode == RTPCS_SDS_MODE_XSGMII)
return rtpcs_93xx_sds_set_mac_mode(sds, hw_mode);
return regmap_field_write(sds->swcore_regs.mac_mode_force, 1);
} else
return rtpcs_931x_sds_set_ip_mode(sds, hw_mode);
return rtpcs_931x_sds_set_ip_mode(sds, hw_mode);
}
static void rtpcs_931x_sds_reset(struct rtpcs_serdes *sds)