realtek: pcs: add more SerDes access helpers
authorJonas Jelonek <[email protected]>
Wed, 8 Oct 2025 08:19:25 +0000 (08:19 +0000)
committerRobert Marko <[email protected]>
Fri, 10 Oct 2025 09:00:15 +0000 (11:00 +0200)
Add more SerDes access helpers for the upcoming code import from PHY
driver. There, similar helpers are used to read and write full SerDes
registers or only parts of them (aka bitfields).

The helpers are expected to replace the following used in PHY SerDes
code:
  - rtl9300_sds_field_r
  - rtl9300_sds_field_w
  - rtsds_931x_read
  - rtsds_931x_read_field
  - rtsds_931x_write
  - rtsds_931x_write_field

Mark the helpers as unused for now to make the compiler happy. This will
be removed as soon as they are used.

Signed-off-by: Jonas Jelonek <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/20352
Signed-off-by: Robert Marko <[email protected]>
target/linux/realtek/files-6.12/drivers/net/pcs/pcs-rtl-otto.c

index 6a88b8c76625048734df71204e39bcbbd7e986d4..72b37ba8e2a9fee71cd703bd95bde7b4be91f420 100644 (file)
@@ -92,16 +92,48 @@ static int rtpcs_sds_read(struct rtpcs_ctrl *ctrl, int sds, int page, int regnum
        return mdiobus_c45_read(ctrl->bus, sds, MDIO_MMD_VEND1, mmd_regnum);
 }
 
-/*
- * For later use, when the SerDes registers need to be written ...
- *
- * static int rtpcs_sds_write(struct rtpcs_ctrl *ctrl, int sds, int page, int regnum, u16 value)
- * {
- *     int mmd_regnum = rtpcs_sds_to_mmd(page, regnum);
- *
- *     return mdiobus_c45_write(ctrl->bus, sds, MDIO_MMD_VEND1, mmd_regnum, value);
- * }
- */
+__attribute__((unused))
+static int rtpcs_sds_read_bits(struct rtpcs_ctrl *ctrl, int sds, int page,
+                              int regnum, int bithigh, int bitlow)
+{
+       int mask, val;
+
+       WARN_ON(bithigh < bitlow);
+
+       mask = GENMASK(bithigh, bitlow);
+       val = rtpcs_sds_read(ctrl, sds, page, regnum);
+       if (val < 0)
+               return val;
+
+       return (val & mask) >> bitlow;
+}
+
+__attribute__((unused))
+static int rtpcs_sds_write(struct rtpcs_ctrl *ctrl, int sds, int page, int regnum, u16 value)
+{
+       int mmd_regnum = rtpcs_sds_to_mmd(page, regnum);
+
+       return mdiobus_c45_write(ctrl->bus, sds, MDIO_MMD_VEND1, mmd_regnum, value);
+}
+
+__attribute__((unused))
+static int rtpcs_sds_write_bits(struct rtpcs_ctrl *ctrl, int sds, int page,
+                               int regnum, int bithigh, int bitlow, u16 value)
+{
+       int mask, reg;
+
+       WARN_ON(bithigh < bitlow);
+
+       mask = GENMASK(bithigh, bitlow);
+       reg = rtpcs_sds_read(ctrl, sds, page, regnum);
+       if (reg < 0)
+               return reg;
+
+       reg = (reg & ~mask);
+       reg |= (value << bitlow) & mask;
+
+       return rtpcs_sds_write(ctrl, sds, page, regnum, reg);
+}
 
 static int rtpcs_sds_modify(struct rtpcs_ctrl *ctrl, int sds, int page, int regnum,
                            u16 mask, u16 set)
@@ -476,4 +508,4 @@ module_platform_driver(rtpcs_driver);
 
 MODULE_AUTHOR("Markus Stockhausen <[email protected]>");
 MODULE_DESCRIPTION("Realtek Otto SerDes PCS driver");
-MODULE_LICENSE("GPL v2");
\ No newline at end of file
+MODULE_LICENSE("GPL v2");