Device properties of the RTL930x SOCs are hardcoded into the MDIO driver.
This must be relaxed to support additional devices like the RTL838x or
RTL839x. These do not have 4 SMI buses but 1 or 2 instead.
To support multiple devices establish an info structure that contains
individual variations of each series. As a first use case add the number
of buses into this structure and use it where needed.
Signed-off-by: Markus Stockhausen <redacted>
---
drivers/net/mdio/mdio-realtek-rtl9300.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c
index a3374d5241cb..140e6ac51e2b 100644
--- a/drivers/net/mdio/mdio-realtek-rtl9300.c
+++ b/drivers/net/mdio/mdio-realtek-rtl9300.c
@@ -48,7 +48,14 @@
#define MAX_SMI_BUSSES 4
#define MAX_SMI_ADDR 0x1f
+#define RTL9300_NUM_BUSES 4
+
+struct rtl_mdio_info {
+ u8 num_buses;
+};
+
struct rtl_mdio_priv {
+ const struct rtl_mdio_info *info;
struct regmap *regmap;
struct mutex lock; /* protect HW access */
DECLARE_BITMAP(valid_ports, MAX_PORTS);@@ -328,7 +335,7 @@ static int rtl9300_mdiobus_init(struct rtl_mdio_priv *priv)
/* Put the interfaces into C45 mode if required */
glb_ctrl_mask = GENMASK(19, 16);
- for (i = 0; i < MAX_SMI_BUSSES; i++)
+ for (i = 0; i < priv->info->num_buses; i++)
if (priv->smi_bus_is_c45[i])
glb_ctrl_val |= GLB_CTRL_INTF_SEL(i);
@@ -447,7 +454,7 @@ static int rtl_mdiobus_map_ports(struct device *dev)
if (err)
return err;
- if (bus >= MAX_SMI_BUSSES)
+ if (bus >= priv->info->num_buses)
return dev_err_probe(dev, -EINVAL, "illegal smi bus number %d\n", bus);
err = of_property_read_u32(phy_dn, "reg", &addr);
@@ -476,6 +483,7 @@ static int rtl_mdiobus_probe(struct platform_device *pdev)
if (err)
return err;
+ priv->info = device_get_match_data(dev);
priv->regmap = syscon_node_to_regmap(dev->parent->of_node);
if (IS_ERR(priv->regmap))
return PTR_ERR(priv->regmap);
@@ -499,8 +507,12 @@ static int rtl_mdiobus_probe(struct platform_device *pdev)
return 0;
}
+static const struct rtl_mdio_info rtl9300_mdio_info = {
+ .num_buses = RTL9300_NUM_BUSES,
+};
+
static const struct of_device_id rtl_mdio_ids[] = {
- { .compatible = "realtek,rtl9301-mdio" },
+ { .compatible = "realtek,rtl9301-mdio", .data = &rtl9300_mdio_info },
{}
};
MODULE_DEVICE_TABLE(of, rtl_mdio_ids);--
2.54.0