> + /* get_phy_c45_ids() will stop the mdio bus scan if we return an error > + * here. So even though the SMI controller indicates an error for an > + * absent device don't proagate it here. > + */ > + //if (val & BIT(25)) { > + // err = -ENODEV; > + // return err; > + //} Please don't leave committed out code. It should either be needed, and uncommented, or deleted. > +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; > + } > + > + for (i = 0; i < MAX_SMI_BUSSES; i++) { > + if (priv->smi_bus_isc45[i]) { > + glb_ctrl_mask |= GLB_CTRL_INTF_SEL(i); > + glb_ctrl_val |= GLB_CTRL_INTF_SEL(i); > + } > + } Please could you add some comments because i don't understand this at all. > + > + err = regmap_bulk_write(priv->regmap, priv->reg_base + SMI_PORT0_5_ADDR_CTRL, > + port_addr, 5); > + if (err) > + return err; > + > + err = regmap_bulk_write(priv->regmap, priv->reg_base + SMI_PORT0_15_POLLING_SEL, > + poll_sel, 2); > + if (err) > + return err; > + > + err = regmap_update_bits(priv->regmap, priv->reg_base + SMI_GLB_CTRL, > + glb_ctrl_mask, glb_ctrl_val); > + if (err) > + return err; > + > + return 0; > +} > + > +static int realtek_mdiobus_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct realtek_mdio_priv *priv; > + struct fwnode_handle *child; > + struct mii_bus *bus; > + int err; > + > + bus = devm_mdiobus_alloc_size(dev, sizeof(*priv)); > + if (!bus) > + return -ENOMEM; > + > + bus->name = "Reaktek Switch MDIO Bus"; > + bus->read_c45 = realtek_mdio_read_c45; > + bus->write_c45 = realtek_mdio_write_c45; > + bus->parent = dev; > + priv = bus->priv; > + > + priv->regmap = syscon_node_to_regmap(dev->parent->of_node); > + if (IS_ERR(priv->regmap)) > + return PTR_ERR(priv->regmap); > + > + err = device_property_read_u32(dev, "reg", &priv->reg_base); > + if (err) > + return err; > + > + snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev)); > + > + device_for_each_child_node(dev, child) { > + u32 pn, smi_addr[2]; > + > + err = fwnode_property_read_u32(child, "reg", &pn); > + if (err) > + return err; > + > + if (pn > MAX_PORTS) > + return dev_err_probe(dev, -EINVAL, "illegal port number %d\n", pn); > + > + err = fwnode_property_read_u32_array(child, "realtek,smi-address", smi_addr, 2); > + if (err) { > + smi_addr[0] = 0; > + smi_addr[1] = pn; > + } Would returning -EINVAL be better here, since it indicates a bug in the device tree? > + > + if (fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45")) > + priv->smi_bus_isc45[smi_addr[0]] = true; If it is not C45 then what? I don't see any support for C22. Andrew