]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: mdio: realtek-rtl9300: Add register structure
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Thu, 21 May 2026 17:59:14 +0000 (19:59 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 26 May 2026 09:56:14 +0000 (11:56 +0200)
The MDIO controller of the Realtek Otto switches has either 4 or 7 command
registers. This depends on the number of supported ports. These registers
are "scattered" around the MMIO block and their addresses depend on the
specific model.

Nevertheless all command registers share a common pattern:

- A mask register with one bit per addressed port
  (remark: the driver internally works on ports instead of bus/address)
- A I/O data register that transfers the to be read/written data
- A C45 registers that takes devnum and regnum
- A C22 register that also includes run and status bits
  (remark: this also takes the Realtek proprietary C22 PHY page)

Provide an additional structure for these command registers so it can be
reused in two places.

1. For defining the register addresses in the regmap.
2. For defining the to be read/written register data

This will finally result in access patterns like

static int otto_emdio_run_cmd(u32 cmd,
                              struct rtl_mdio_cmd_regs *cmd_regs, ...)
{
  regmap_write(regmap, priv->info->reg->cmd_regs.c45_data,
                       cmd_regs->c45_data);
  ...
}

static int otto_emdio_9300_write_c45(...)
{
  struct otto_emdio_cmd_regs cmd_regs = {
    .c45_data  = ...
    .io_data   = ...,
    .port_mask = ...,
  };

  return otto_emdio_run_cmd(RTL9300_CMD_WRITE_C45, &cmd_regs, ...);
}

As a first step start with the C45 register. This one takes the
devnum/regnum data that is stored in the high/low 16 bits.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://patch.msgid.link/20260521175918.1494797-6-markus.stockhausen@gmx.de
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/mdio/mdio-realtek-rtl9300.c

index 94f59a56bc4667d777f3c5f7a71abef1b358df3d..c992f09835f97b61a4905e66e93ffc978bcf0631 100644 (file)
@@ -71,7 +71,7 @@
 #define SMI_ACCESS_PHY_CTRL_2          0xcb78
 #define   PHY_CTRL_INDATA              GENMASK(31, 16)
 #define   PHY_CTRL_DATA                        GENMASK(15, 0)
-#define SMI_ACCESS_PHY_CTRL_3          0xcb7c
+#define RTL9300_SMI_ACCESS_PHY_CTRL_3  0xcb7c
 #define   PHY_CTRL_MMD_DEVAD           GENMASK(20, 16)
 #define   PHY_CTRL_MMD_REG             GENMASK(15, 0)
 #define SMI_PORT0_5_ADDR_CTRL          0xcb80
 #define MAX_SMI_ADDR   0x1f
 #define RAW_PAGE(priv) ((priv)->info->num_pages - 1)
 
+
+struct otto_emdio_cmd_regs {
+       u32 c45_data;
+};
+
 struct otto_emdio_info {
+       struct otto_emdio_cmd_regs cmd_regs;
        u8 num_buses;
        u8 num_ports;
        u16 num_pages;
@@ -262,7 +268,7 @@ static int otto_emdio_9300_read_c45(struct mii_bus *bus, int phy_id, int dev_add
 
        val = FIELD_PREP(PHY_CTRL_MMD_DEVAD, dev_addr) |
              FIELD_PREP(PHY_CTRL_MMD_REG, regnum);
-       err = regmap_write(regmap, SMI_ACCESS_PHY_CTRL_3, val);
+       err = regmap_write(regmap, priv->info->cmd_regs.c45_data, val);
        if (err)
                goto out_err;
 
@@ -320,7 +326,7 @@ static int otto_emdio_9300_write_c45(struct mii_bus *bus, int phy_id, int dev_ad
 
        val = FIELD_PREP(PHY_CTRL_MMD_DEVAD, dev_addr) |
              FIELD_PREP(PHY_CTRL_MMD_REG, regnum);
-       err = regmap_write(regmap, SMI_ACCESS_PHY_CTRL_3, val);
+       err = regmap_write(regmap, priv->info->cmd_regs.c45_data, val);
        if (err)
                goto out_err;
 
@@ -541,6 +547,9 @@ static int otto_emdio_probe(struct platform_device *pdev)
 }
 
 static const struct otto_emdio_info otto_emdio_9300_info = {
+       .cmd_regs = {
+               .c45_data = RTL9300_SMI_ACCESS_PHY_CTRL_3,
+       },
        .num_buses = RTL9300_NUM_BUSES,
        .num_ports = RTL9300_NUM_PORTS,
        .num_pages = RTL9300_NUM_PAGES,