aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/phy
diff options
context:
space:
mode:
authorDavid Daney <david.daney@cavium.com>2016-03-11 12:53:11 -0500
committerDavid S. Miller <davem@davemloft.net>2016-03-14 15:27:22 -0400
commit379d7ac7ca31722a1fb488ae3e98b274c9db568c (patch)
treeb46597bf328b8a005d607d85e8c3695ce00ea1ab /drivers/net/phy
parent1eefee901fca0208b8a56f20cdc134e2b8638ae7 (diff)
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>
Diffstat (limited to 'drivers/net/phy')
-rw-r--r--drivers/net/phy/Kconfig11
-rw-r--r--drivers/net/phy/Makefile1
-rw-r--r--drivers/net/phy/mdio-thunder.c154
3 files changed, 166 insertions, 0 deletions
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 40faec9f3b0b..075a4cc175b1 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -196,6 +196,17 @@ config MDIO_OCTEON
196 buses. It is required by the Octeon and ThunderX ethernet device 196 buses. It is required by the Octeon and ThunderX ethernet device
197 drivers on some systems. 197 drivers on some systems.
198 198
199config 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
199config MDIO_SUN4I 210config MDIO_SUN4I
200 tristate "Allwinner sun4i MDIO interface support" 211 tristate "Allwinner sun4i MDIO interface support"
201 depends on ARCH_SUNXI 212 depends on ARCH_SUNXI
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 041b3d977d31..fcdbb9299fab 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_DP83867_PHY) += dp83867.o
31obj-$(CONFIG_STE10XP) += ste10Xp.o 31obj-$(CONFIG_STE10XP) += ste10Xp.o
32obj-$(CONFIG_MICREL_PHY) += micrel.o 32obj-$(CONFIG_MICREL_PHY) += micrel.o
33obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o 33obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
34obj-$(CONFIG_MDIO_THUNDER) += mdio-thunder.o
34obj-$(CONFIG_MDIO_CAVIUM) += mdio-cavium.o 35obj-$(CONFIG_MDIO_CAVIUM) += mdio-cavium.o
35obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o 36obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o
36obj-$(CONFIG_AT803X_PHY) += at803x.o 37obj-$(CONFIG_AT803X_PHY) += at803x.o
diff --git a/drivers/net/phy/mdio-thunder.c b/drivers/net/phy/mdio-thunder.c
new file mode 100644
index 000000000000..564616968cad
--- /dev/null
+++ b/drivers/net/phy/mdio-thunder.c
@@ -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
20struct thunder_mdiobus_nexus {
21 void __iomem *bar0;
22 struct cavium_mdiobus *buses[4];
23};
24
25static 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
112err_release_regions:
113 pci_release_regions(pdev);
114
115err_disable_device:
116 pci_set_drvdata(pdev, NULL);
117 return err;
118}
119
120static 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
138static const struct pci_device_id thunder_mdiobus_id_table[] = {
139 { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa02b) },
140 { 0, } /* End of table. */
141};
142MODULE_DEVICE_TABLE(pci, thunder_mdiobus_id_table);
143
144static 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
151module_pci_driver(thunder_mdiobus_driver);
152
153MODULE_DESCRIPTION("Cavium ThunderX MDIO bus driver");
154MODULE_LICENSE("GPL");