1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2009-2015 Cavium, Inc.
8 #include <linux/module.h>
9 #include <linux/of_address.h>
10 #include <linux/of_mdio.h>
11 #include <linux/phy.h>
12 #include <linux/platform_device.h>
14 #include "mdio-cavium.h"
16 static int octeon_mdiobus_probe(struct platform_device
*pdev
)
18 struct cavium_mdiobus
*bus
;
19 struct mii_bus
*mii_bus
;
20 struct resource
*res_mem
;
21 resource_size_t mdio_phys
;
22 resource_size_t regsize
;
23 union cvmx_smix_en smi_en
;
26 mii_bus
= devm_mdiobus_alloc_size(&pdev
->dev
, sizeof(*bus
));
30 res_mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
31 if (res_mem
== NULL
) {
32 dev_err(&pdev
->dev
, "found no memory resource\n");
37 bus
->mii_bus
= mii_bus
;
38 mdio_phys
= res_mem
->start
;
39 regsize
= resource_size(res_mem
);
41 if (!devm_request_mem_region(&pdev
->dev
, mdio_phys
, regsize
,
43 dev_err(&pdev
->dev
, "request_mem_region failed\n");
47 bus
->register_base
= devm_ioremap(&pdev
->dev
, mdio_phys
, regsize
);
48 if (!bus
->register_base
) {
49 dev_err(&pdev
->dev
, "dev_ioremap failed\n");
55 oct_mdio_writeq(smi_en
.u64
, bus
->register_base
+ SMI_EN
);
57 bus
->mii_bus
->name
= KBUILD_MODNAME
;
58 snprintf(bus
->mii_bus
->id
, MII_BUS_ID_SIZE
, "%px", bus
->register_base
);
59 bus
->mii_bus
->parent
= &pdev
->dev
;
61 bus
->mii_bus
->read
= cavium_mdiobus_read_c22
;
62 bus
->mii_bus
->write
= cavium_mdiobus_write_c22
;
63 bus
->mii_bus
->read_c45
= cavium_mdiobus_read_c45
;
64 bus
->mii_bus
->write_c45
= cavium_mdiobus_write_c45
;
66 platform_set_drvdata(pdev
, bus
);
68 err
= of_mdiobus_register(bus
->mii_bus
, pdev
->dev
.of_node
);
72 dev_info(&pdev
->dev
, "Probed\n");
77 oct_mdio_writeq(smi_en
.u64
, bus
->register_base
+ SMI_EN
);
81 static void octeon_mdiobus_remove(struct platform_device
*pdev
)
83 struct cavium_mdiobus
*bus
;
84 union cvmx_smix_en smi_en
;
86 bus
= platform_get_drvdata(pdev
);
88 mdiobus_unregister(bus
->mii_bus
);
90 oct_mdio_writeq(smi_en
.u64
, bus
->register_base
+ SMI_EN
);
93 static const struct of_device_id octeon_mdiobus_match
[] = {
95 .compatible
= "cavium,octeon-3860-mdio",
99 MODULE_DEVICE_TABLE(of
, octeon_mdiobus_match
);
101 static struct platform_driver octeon_mdiobus_driver
= {
103 .name
= KBUILD_MODNAME
,
104 .of_match_table
= octeon_mdiobus_match
,
106 .probe
= octeon_mdiobus_probe
,
107 .remove
= octeon_mdiobus_remove
,
110 module_platform_driver(octeon_mdiobus_driver
);
112 MODULE_DESCRIPTION("Cavium OCTEON MDIO bus driver");
113 MODULE_AUTHOR("David Daney");
114 MODULE_LICENSE("GPL v2");