Skip to content

Commit 379d7ac

Browse files
daviddaneydavem330
authored andcommitted
phy: mdio-thunder: Add driver for Cavium Thunder SoC MDIO buses.
The Cavium Thunder SoCs have multiple MIDO buses that are part of a single PCI device. To model this in the device tree we call the PCI parent device a "cavium,thunder-8890-mdio-nexus", it has several children, one for each MDIO bus. The MDIO bus hardware is identical to that found in the OCTEON SoCs, so we use that code for things that are not part of the PCI driver probe/remove Signed-off-by: David Daney <david.daney@cavium.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1eefee9 commit 379d7ac

File tree

4 files changed

+225
-2
lines changed

4 files changed

+225
-2
lines changed

Documentation/devicetree/bindings/net/cavium-mdio.txt

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
* System Management Interface (SMI) / MDIO
22

33
Properties:
4-
- compatible: "cavium,octeon-3860-mdio"
4+
- compatible: One of:
55

6-
Compatibility with all cn3XXX, cn5XXX and cn6XXX SOCs.
6+
"cavium,octeon-3860-mdio": Compatibility with all cn3XXX, cn5XXX
7+
and cn6XXX SOCs.
8+
9+
"cavium,thunder-8890-mdio": Compatibility with all cn8XXX SOCs.
710

811
- reg: The base address of the MDIO bus controller register bank.
912

@@ -25,3 +28,57 @@ Example:
2528
reg = <0>;
2629
};
2730
};
31+
32+
33+
* System Management Interface (SMI) / MDIO Nexus
34+
35+
Several mdio buses may be gathered as children of a single PCI
36+
device, this PCI device is the nexus of the buses.
37+
38+
Properties:
39+
40+
- compatible: "cavium,thunder-8890-mdio-nexus";
41+
42+
- reg: The PCI device and function numbers of the nexus device.
43+
44+
- #address-cells: Must be <2>.
45+
46+
- #size-cells: Must be <2>.
47+
48+
- ranges: As needed for mapping of the MDIO bus device registers.
49+
50+
- assigned-addresses: As needed for mapping of the MDIO bus device registers.
51+
52+
Example:
53+
54+
mdio-nexus@1,3 {
55+
compatible = "cavium,thunder-8890-mdio-nexus";
56+
#address-cells = <2>;
57+
#size-cells = <2>;
58+
reg = <0x0b00 0 0 0 0>; /* DEVFN = 0x0b (1:3) */
59+
assigned-addresses = <0x03000000 0x87e0 0x05000000 0x0 0x800000>;
60+
ranges = <0x87e0 0x05000000 0x03000000 0x87e0 0x05000000 0x0 0x800000>;
61+
62+
mdio0@87e0,05003800 {
63+
compatible = "cavium,thunder-8890-mdio";
64+
#address-cells = <1>;
65+
#size-cells = <0>;
66+
reg = <0x87e0 0x05003800 0x0 0x30>;
67+
68+
ethernet-phy@0 {
69+
...
70+
reg = <0>;
71+
};
72+
};
73+
mdio0@87e0,05003880 {
74+
compatible = "cavium,thunder-8890-mdio";
75+
#address-cells = <1>;
76+
#size-cells = <0>;
77+
reg = <0x87e0 0x05003880 0x0 0x30>;
78+
79+
ethernet-phy@0 {
80+
...
81+
reg = <0>;
82+
};
83+
};
84+
};

drivers/net/phy/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ config MDIO_OCTEON
196196
buses. It is required by the Octeon and ThunderX ethernet device
197197
drivers on some systems.
198198

199+
config MDIO_THUNDER
200+
tristate "Support for MDIO buses on on ThunderX SOCs"
201+
depends on 64BIT
202+
depends on PCI
203+
select MDIO_CAVIUM
204+
help
205+
This driver supports the MDIO interfaces found on Cavium
206+
ThunderX SoCs when the MDIO bus device appears on as a PCI
207+
device.
208+
209+
199210
config MDIO_SUN4I
200211
tristate "Allwinner sun4i MDIO interface support"
201212
depends on ARCH_SUNXI

drivers/net/phy/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ obj-$(CONFIG_DP83867_PHY) += dp83867.o
3131
obj-$(CONFIG_STE10XP) += ste10Xp.o
3232
obj-$(CONFIG_MICREL_PHY) += micrel.o
3333
obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
34+
obj-$(CONFIG_MDIO_THUNDER) += mdio-thunder.o
3435
obj-$(CONFIG_MDIO_CAVIUM) += mdio-cavium.o
3536
obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o
3637
obj-$(CONFIG_AT803X_PHY) += at803x.o

drivers/net/phy/mdio-thunder.c

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* This file is subject to the terms and conditions of the GNU General Public
3+
* License. See the file "COPYING" in the main directory of this archive
4+
* for more details.
5+
*
6+
* Copyright (C) 2009-2016 Cavium, Inc.
7+
*/
8+
9+
#include <linux/of_address.h>
10+
#include <linux/of_mdio.h>
11+
#include <linux/module.h>
12+
#include <linux/gfp.h>
13+
#include <linux/phy.h>
14+
#include <linux/io.h>
15+
#include <linux/acpi.h>
16+
#include <linux/pci.h>
17+
18+
#include "mdio-cavium.h"
19+
20+
struct thunder_mdiobus_nexus {
21+
void __iomem *bar0;
22+
struct cavium_mdiobus *buses[4];
23+
};
24+
25+
static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,
26+
const struct pci_device_id *ent)
27+
{
28+
struct device_node *node;
29+
struct fwnode_handle *fwn;
30+
struct thunder_mdiobus_nexus *nexus;
31+
int err;
32+
int i;
33+
34+
nexus = devm_kzalloc(&pdev->dev, sizeof(*nexus), GFP_KERNEL);
35+
if (!nexus)
36+
return -ENOMEM;
37+
38+
pci_set_drvdata(pdev, nexus);
39+
40+
err = pcim_enable_device(pdev);
41+
if (err) {
42+
dev_err(&pdev->dev, "Failed to enable PCI device\n");
43+
pci_set_drvdata(pdev, NULL);
44+
return err;
45+
}
46+
47+
err = pci_request_regions(pdev, KBUILD_MODNAME);
48+
if (err) {
49+
dev_err(&pdev->dev, "pci_request_regions failed\n");
50+
goto err_disable_device;
51+
}
52+
53+
nexus->bar0 = pcim_iomap(pdev, 0, pci_resource_len(pdev, 0));
54+
if (!nexus->bar0) {
55+
err = -ENOMEM;
56+
goto err_release_regions;
57+
}
58+
59+
i = 0;
60+
device_for_each_child_node(&pdev->dev, fwn) {
61+
struct resource r;
62+
struct mii_bus *mii_bus;
63+
struct cavium_mdiobus *bus;
64+
union cvmx_smix_en smi_en;
65+
66+
/* If it is not an OF node we cannot handle it yet, so
67+
* exit the loop.
68+
*/
69+
node = to_of_node(fwn);
70+
if (!node)
71+
break;
72+
73+
err = of_address_to_resource(node, 0, &r);
74+
if (err) {
75+
dev_err(&pdev->dev,
76+
"Couldn't translate address for \"%s\"\n",
77+
node->name);
78+
break;
79+
}
80+
81+
mii_bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(*bus));
82+
if (!mii_bus)
83+
break;
84+
bus = mii_bus->priv;
85+
bus->mii_bus = mii_bus;
86+
87+
nexus->buses[i] = bus;
88+
i++;
89+
90+
bus->register_base = (u64)nexus->bar0 +
91+
r.start - pci_resource_start(pdev, 0);
92+
93+
smi_en.u64 = 0;
94+
smi_en.s.en = 1;
95+
oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
96+
bus->mii_bus->name = KBUILD_MODNAME;
97+
snprintf(bus->mii_bus->id, MII_BUS_ID_SIZE, "%llx", r.start);
98+
bus->mii_bus->parent = &pdev->dev;
99+
bus->mii_bus->read = cavium_mdiobus_read;
100+
bus->mii_bus->write = cavium_mdiobus_write;
101+
102+
err = of_mdiobus_register(bus->mii_bus, node);
103+
if (err)
104+
dev_err(&pdev->dev, "of_mdiobus_register failed\n");
105+
106+
dev_info(&pdev->dev, "Added bus at %llx\n", r.start);
107+
if (i >= ARRAY_SIZE(nexus->buses))
108+
break;
109+
}
110+
return 0;
111+
112+
err_release_regions:
113+
pci_release_regions(pdev);
114+
115+
err_disable_device:
116+
pci_set_drvdata(pdev, NULL);
117+
return err;
118+
}
119+
120+
static void thunder_mdiobus_pci_remove(struct pci_dev *pdev)
121+
{
122+
int i;
123+
struct thunder_mdiobus_nexus *nexus = pci_get_drvdata(pdev);
124+
125+
for (i = 0; i < ARRAY_SIZE(nexus->buses); i++) {
126+
struct cavium_mdiobus *bus = nexus->buses[i];
127+
128+
if (!bus)
129+
continue;
130+
131+
mdiobus_unregister(bus->mii_bus);
132+
mdiobus_free(bus->mii_bus);
133+
oct_mdio_writeq(0, bus->register_base + SMI_EN);
134+
}
135+
pci_set_drvdata(pdev, NULL);
136+
}
137+
138+
static const struct pci_device_id thunder_mdiobus_id_table[] = {
139+
{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa02b) },
140+
{ 0, } /* End of table. */
141+
};
142+
MODULE_DEVICE_TABLE(pci, thunder_mdiobus_id_table);
143+
144+
static struct pci_driver thunder_mdiobus_driver = {
145+
.name = KBUILD_MODNAME,
146+
.id_table = thunder_mdiobus_id_table,
147+
.probe = thunder_mdiobus_pci_probe,
148+
.remove = thunder_mdiobus_pci_remove,
149+
};
150+
151+
module_pci_driver(thunder_mdiobus_driver);
152+
153+
MODULE_DESCRIPTION("Cavium ThunderX MDIO bus driver");
154+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)