.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Ethernet driver for the WIZnet W5100/W5200/W5500 chip. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2016 Akinobu Mita <akinobu.mita@gmail.com> |
---|
5 | | - * |
---|
6 | | - * Licensed under the GPL-2 or later. |
---|
7 | 6 | * |
---|
8 | 7 | * Datasheet: |
---|
9 | 8 | * http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5100/Document/W5100_Datasheet_v1.2.6.pdf |
---|
.. | .. |
---|
16 | 15 | #include <linux/delay.h> |
---|
17 | 16 | #include <linux/netdevice.h> |
---|
18 | 17 | #include <linux/of_net.h> |
---|
| 18 | +#include <linux/of_device.h> |
---|
19 | 19 | #include <linux/spi/spi.h> |
---|
20 | 20 | |
---|
21 | 21 | #include "w5100.h" |
---|
.. | .. |
---|
410 | 410 | .init = w5500_spi_init, |
---|
411 | 411 | }; |
---|
412 | 412 | |
---|
| 413 | +static 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 | +}; |
---|
| 419 | +MODULE_DEVICE_TABLE(of, w5100_of_match); |
---|
| 420 | + |
---|
413 | 421 | static int w5100_spi_probe(struct spi_device *spi) |
---|
414 | 422 | { |
---|
415 | | - const struct spi_device_id *id = spi_get_device_id(spi); |
---|
| 423 | + const struct of_device_id *of_id; |
---|
416 | 424 | const struct w5100_ops *ops; |
---|
| 425 | + kernel_ulong_t driver_data; |
---|
417 | 426 | int priv_size; |
---|
418 | 427 | const void *mac = of_get_mac_address(spi->dev.of_node); |
---|
419 | 428 | |
---|
420 | | - 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) { |
---|
421 | 439 | case W5100: |
---|
422 | 440 | ops = &w5100_spi_ops; |
---|
423 | 441 | priv_size = 0; |
---|
.. | .. |
---|
454 | 472 | .driver = { |
---|
455 | 473 | .name = "w5100", |
---|
456 | 474 | .pm = &w5100_pm_ops, |
---|
| 475 | + .of_match_table = w5100_of_match, |
---|
457 | 476 | }, |
---|
458 | 477 | .probe = w5100_spi_probe, |
---|
459 | 478 | .remove = w5100_spi_remove, |
---|