From: Jonas Jelonek Date: Fri, 13 Feb 2026 22:05:32 +0000 (+0000) Subject: realtek: pcs: add SerDes register struct and use it X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb0bc84182ff44acd61701c6d7f685a1596dc133;p=thirdparty%2Fopenwrt.git realtek: pcs: add SerDes register struct and use it Slight differences between the variants of the Otto family are handled so far handled using function indirection by defining per-variant operations which are called from generic implementations. In several case, this can still be optimized because the variants only differ in some register addresses and/or bits while the procedure otherwise is exactly the same. To address this, add a new SerDes register struct where register fields can be described and later used by generic implementations which otherwise would need to be separate just because of slight differences. Add two register fields for autonegotiation to that register struct which are used by a successing patch to address a real issue. Signed-off-by: Jonas Jelonek Link: https://github.com/openwrt/openwrt/pull/22013 Signed-off-by: Robert Marko --- diff --git a/target/linux/realtek/files-6.12/drivers/net/pcs/pcs-rtl-otto.c b/target/linux/realtek/files-6.12/drivers/net/pcs/pcs-rtl-otto.c index b0c1674bb75..96dc3ab00f6 100644 --- a/target/linux/realtek/files-6.12/drivers/net/pcs/pcs-rtl-otto.c +++ b/target/linux/realtek/files-6.12/drivers/net/pcs/pcs-rtl-otto.c @@ -174,9 +174,23 @@ struct rtpcs_serdes_ops { void (*restart_autoneg)(struct rtpcs_serdes *sds); }; +struct rtpcs_sds_reg_field { + u8 page; + u8 reg; + u8 msb; + u8 lsb; +}; + +struct rtpcs_sds_regs { + struct rtpcs_sds_reg_field an_enable; + struct rtpcs_sds_reg_field an_restart; + struct rtpcs_sds_reg_field an_advertise; +}; + struct rtpcs_serdes { struct rtpcs_ctrl *ctrl; const struct rtpcs_serdes_ops *ops; + const struct rtpcs_sds_regs *regs; enum rtpcs_sds_mode hw_mode; u8 id; u8 num_of_links; @@ -218,6 +232,7 @@ struct rtpcs_config { const struct phylink_pcs_ops *pcs_ops; const struct rtpcs_serdes_ops *sds_ops; + const struct rtpcs_sds_regs *sds_regs; int (*init_serdes_common)(struct rtpcs_ctrl *ctrl); int (*setup_serdes)(struct rtpcs_serdes *sds, enum rtpcs_sds_mode hw_mode); }; @@ -313,6 +328,19 @@ static int rtpcs_sds_write(struct rtpcs_serdes *sds, int page, int regnum, u16 v return sds->ops->write(sds, page, regnum, 15, 0, value); } +__maybe_unused +static int rtpcs_sds_read_field(struct rtpcs_serdes *sds, const struct rtpcs_sds_reg_field *field) +{ + return sds->ops->read(sds, field->page, field->reg, field->msb, field->lsb); +} + +__maybe_unused +static int rtpcs_sds_write_field(struct rtpcs_serdes *sds, const struct rtpcs_sds_reg_field *field, + u16 value) +{ + return sds->ops->write(sds, field->page, field->reg, field->msb, field->lsb, value); +} + __maybe_unused static int rtpcs_sds_xsg_write_bits(struct rtpcs_serdes *sds, int page, int regnum, int bithigh, int bitlow, u16 value) @@ -4016,6 +4044,7 @@ static int rtpcs_probe(struct platform_device *pdev) sds->first_start = true; sds->id = i; sds->ops = ctrl->cfg->sds_ops; + sds->regs = ctrl->cfg->sds_regs; } for_each_child_of_node(dev->of_node, child) {