Skip to content

Commit 2776176

Browse files
lunndavem330
authored andcommitted
net: dsa: mv88e6060: Support probing as an mdio device
Probing DSA devices as platform devices has been superseded by using normal bus drivers. Add support for probing the mv88e6060 device as an mdio device. Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4925930 commit 2776176

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

drivers/net/dsa/mv88e6060.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,72 @@ static struct dsa_switch_driver mv88e6060_switch_drv = {
276276
.ops = &mv88e6060_switch_ops,
277277
};
278278

279+
static int mv88e6060_probe(struct mdio_device *mdiodev)
280+
{
281+
struct device *dev = &mdiodev->dev;
282+
struct mv88e6060_priv *priv;
283+
struct dsa_switch *ds;
284+
const char *name;
285+
286+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
287+
if (!priv)
288+
return -ENOMEM;
289+
290+
priv->bus = mdiodev->bus;
291+
priv->sw_addr = mdiodev->addr;
292+
293+
name = mv88e6060_get_name(priv->bus, priv->sw_addr);
294+
if (!name)
295+
return -ENODEV;
296+
297+
dev_info(dev, "switch %s detected\n", name);
298+
299+
ds = dsa_switch_alloc(dev, MV88E6060_PORTS);
300+
if (!ds)
301+
return -ENOMEM;
302+
303+
ds->priv = priv;
304+
ds->dev = dev;
305+
ds->ops = &mv88e6060_switch_ops;
306+
307+
dev_set_drvdata(dev, ds);
308+
309+
return dsa_register_switch(ds);
310+
}
311+
312+
static void mv88e6060_remove(struct mdio_device *mdiodev)
313+
{
314+
struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
315+
316+
dsa_unregister_switch(ds);
317+
}
318+
319+
static const struct of_device_id mv88e6060_of_match[] = {
320+
{
321+
.compatible = "marvell,mv88e6060",
322+
},
323+
{ /* sentinel */ },
324+
};
325+
326+
static struct mdio_driver mv88e6060_driver = {
327+
.probe = mv88e6060_probe,
328+
.remove = mv88e6060_remove,
329+
.mdiodrv.driver = {
330+
.name = "mv88e6060",
331+
.of_match_table = mv88e6060_of_match,
332+
},
333+
};
334+
279335
static int __init mv88e6060_init(void)
280336
{
281337
register_switch_driver(&mv88e6060_switch_drv);
282-
return 0;
338+
return mdio_driver_register(&mv88e6060_driver);
283339
}
284340
module_init(mv88e6060_init);
285341

286342
static void __exit mv88e6060_cleanup(void)
287343
{
344+
mdio_driver_unregister(&mv88e6060_driver);
288345
unregister_switch_driver(&mv88e6060_switch_drv);
289346
}
290347
module_exit(mv88e6060_cleanup);

0 commit comments

Comments
 (0)