]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: pcs: add SerDes register struct and use it
authorJonas Jelonek <jelonek.jonas@gmail.com>
Fri, 13 Feb 2026 22:05:32 +0000 (22:05 +0000)
committerRobert Marko <robimarko@gmail.com>
Mon, 16 Feb 2026 14:43:20 +0000 (15:43 +0100)
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 <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/22013
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/realtek/files-6.12/drivers/net/pcs/pcs-rtl-otto.c

index b0c1674bb759e6b4c70a040c733fe38594646564..96dc3ab00f6cb777bc75964dfc81a4af00996d8b 100644 (file)
@@ -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) {