aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Saenz Julienne <nsaenzjulienne@suse.de>2019-06-12 08:25:25 -0400
committerDavid S. Miller <davem@davemloft.net>2019-06-12 12:52:04 -0400
commitb9dd694eb058b30575f73af8950b35ab93a7c65c (patch)
tree7c8e7225a948e5e9445cea6f6ec81d6ac6b388ea
parent7a096d579e8e2bd8b8ff34d5ef3093cd9bf3f13b (diff)
net: ethernet: wiznet: w5X00 add device tree support
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>
-rw-r--r--drivers/net/ethernet/wiznet/w5100-spi.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/drivers/net/ethernet/wiznet/w5100-spi.c b/drivers/net/ethernet/wiznet/w5100-spi.c
index 918b3e50850a..2b4126d2427d 100644
--- a/drivers/net/ethernet/wiznet/w5100-spi.c
+++ b/drivers/net/ethernet/wiznet/w5100-spi.c
@@ -15,6 +15,7 @@
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/netdevice.h> 16#include <linux/netdevice.h>
17#include <linux/of_net.h> 17#include <linux/of_net.h>
18#include <linux/of_device.h>
18#include <linux/spi/spi.h> 19#include <linux/spi/spi.h>
19 20
20#include "w5100.h" 21#include "w5100.h"
@@ -409,14 +410,32 @@ static const struct w5100_ops w5500_ops = {
409 .init = w5500_spi_init, 410 .init = w5500_spi_init,
410}; 411};
411 412
413static const struct of_device_id w5100_of_match[] = {
414 { .compatible = "wiznet,w5100", .data = (const void*)W5100, },
415 { .compatible = "wiznet,w5200", .data = (const void*)W5200, },
416 { .compatible = "wiznet,w5500", .data = (const void*)W5500, },
417 { },
418};
419MODULE_DEVICE_TABLE(of, w5100_of_match);
420
412static int w5100_spi_probe(struct spi_device *spi) 421static int w5100_spi_probe(struct spi_device *spi)
413{ 422{
414 const struct spi_device_id *id = spi_get_device_id(spi); 423 const struct of_device_id *of_id;
415 const struct w5100_ops *ops; 424 const struct w5100_ops *ops;
425 kernel_ulong_t driver_data;
416 int priv_size; 426 int priv_size;
417 const void *mac = of_get_mac_address(spi->dev.of_node); 427 const void *mac = of_get_mac_address(spi->dev.of_node);
418 428
419 switch (id->driver_data) { 429 if (spi->dev.of_node) {
430 of_id = of_match_device(w5100_of_match, &spi->dev);
431 if (!of_id)
432 return -ENODEV;
433 driver_data = (kernel_ulong_t)of_id->data;
434 } else {
435 driver_data = spi_get_device_id(spi)->driver_data;
436 }
437
438 switch (driver_data) {
420 case W5100: 439 case W5100:
421 ops = &w5100_spi_ops; 440 ops = &w5100_spi_ops;
422 priv_size = 0; 441 priv_size = 0;
@@ -453,6 +472,7 @@ static struct spi_driver w5100_spi_driver = {
453 .driver = { 472 .driver = {
454 .name = "w5100", 473 .name = "w5100",
455 .pm = &w5100_pm_ops, 474 .pm = &w5100_pm_ops,
475 .of_match_table = w5100_of_match,
456 }, 476 },
457 .probe = w5100_spi_probe, 477 .probe = w5100_spi_probe,
458 .remove = w5100_spi_remove, 478 .remove = w5100_spi_remove,