Skip to content

Commit

Permalink
net: ethernet: wiznet: w5X00 add device tree support
Browse files Browse the repository at this point in the history
The w5X00 chip provides an SPI to Ethernet inteface. This patch allows
platform devices to be defined through the device tree.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Nicolas Saenz Julienne authored and David S. Miller committed Jun 12, 2019
1 parent 7a096d5 commit b9dd694
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions drivers/net/ethernet/wiznet/w5100-spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/of_net.h>
#include <linux/of_device.h>
#include <linux/spi/spi.h>

#include "w5100.h"
Expand Down Expand Up @@ -409,14 +410,32 @@ static const struct w5100_ops w5500_ops = {
.init = w5500_spi_init,
};

static const struct of_device_id w5100_of_match[] = {
{ .compatible = "wiznet,w5100", .data = (const void*)W5100, },
{ .compatible = "wiznet,w5200", .data = (const void*)W5200, },
{ .compatible = "wiznet,w5500", .data = (const void*)W5500, },
{ },
};
MODULE_DEVICE_TABLE(of, w5100_of_match);

static int w5100_spi_probe(struct spi_device *spi)
{
const struct spi_device_id *id = spi_get_device_id(spi);
const struct of_device_id *of_id;
const struct w5100_ops *ops;
kernel_ulong_t driver_data;
int priv_size;
const void *mac = of_get_mac_address(spi->dev.of_node);

switch (id->driver_data) {
if (spi->dev.of_node) {
of_id = of_match_device(w5100_of_match, &spi->dev);
if (!of_id)
return -ENODEV;
driver_data = (kernel_ulong_t)of_id->data;
} else {
driver_data = spi_get_device_id(spi)->driver_data;
}

switch (driver_data) {
case W5100:
ops = &w5100_spi_ops;
priv_size = 0;
Expand Down Expand Up @@ -453,6 +472,7 @@ static struct spi_driver w5100_spi_driver = {
.driver = {
.name = "w5100",
.pm = &w5100_pm_ops,
.of_match_table = w5100_of_match,
},
.probe = w5100_spi_probe,
.remove = w5100_spi_remove,
Expand Down

0 comments on commit b9dd694

Please sign in to comment.