Add a driver for the MDIO controller on the RTL9300 family of Ethernet
switches with integrated SoC. There are 4 physical SMI interfaces on the
RTL9300 but access is done using the switch ports so a single MDIO bus
is presented to the rest of the system.
Signed-off-by: Chris Packham <chris.packham@xxxxxxxxxxxxxxxxxxx>
+ err = regmap_write(priv->regmap, priv->reg_base + SMI_ACCESS_PHY_CTRL_1,
+ PHY_CTRL_RWOP | PHY_CTRL_TYPE | PHY_CTRL_CMD);
+ if (err)
+ return err;
+
+ err = regmap_read_poll_timeout(priv->regmap, priv->reg_base + SMI_ACCESS_PHY_CTRL_1,
+ val, !(val & PHY_CTRL_CMD), 10, 100);
+ if (err)
+ return err;
+
+ if (val & PHY_CTRL_FAIL) {
+ err = -ENXIO;
+ return err;
+ }
+
+ return err;
+}
+
+static int realtek_mdiobus_init(struct realtek_mdio_priv *priv)
+{
+ u32 port_addr[5] = { };
+ u32 poll_sel[2] = { 0, 0 };
+ u32 glb_ctrl_mask = 0, glb_ctrl_val = 0;
+ int i, err;
+
+ for (i = 0; i < MAX_PORTS; i++) {
+ int pos;
+
+ if (priv->smi_bus[i] > 3)
+ continue;
+
+ pos = (i % 6) * 5;
+ port_addr[i / 6] |= priv->smi_addr[i] << pos;
+
+ pos = (i % 16) * 2;
+ poll_sel[i / 16] |= priv->smi_bus[i] << pos;
+ }