From 3cf04d2e0b95b853c09af7f709a81ee1a2ca6480 Mon Sep 17 00:00:00 2001 From: Jonas Jelonek Date: Wed, 8 Oct 2025 08:19:25 +0000 Subject: [PATCH] realtek: pcs: add more SerDes access helpers 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 Link: https://github.com/openwrt/openwrt/pull/20352 Signed-off-by: Robert Marko --- .../files-6.12/drivers/net/pcs/pcs-rtl-otto.c | 54 +++++++++++++++---- 1 file changed, 43 insertions(+), 11 deletions(-) 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 6a88b8c766..72b37ba8e2 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 @@ -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 "); MODULE_DESCRIPTION("Realtek Otto SerDes PCS driver"); -MODULE_LICENSE("GPL v2"); \ No newline at end of file +MODULE_LICENSE("GPL v2"); -- 2.30.2