Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ethernet: enc28j60: add device tree support

The following patch adds the required match table for device tree support
(and while at, fix the indent). It's also possible to specify the
MAC address in the DT blob.

Also add the corresponding binding documentation file.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Michael Heimpold and committed by
David S. Miller
2dd355a0 2957a28a

+76 -3
+59
Documentation/devicetree/bindings/net/microchip,enc28j60.txt
··· 1 + * Microchip ENC28J60 2 + 3 + This is a standalone 10 MBit ethernet controller with SPI interface. 4 + 5 + For each device connected to a SPI bus, define a child node within 6 + the SPI master node. 7 + 8 + Required properties: 9 + - compatible: Should be "microchip,enc28j60" 10 + - reg: Specify the SPI chip select the ENC28J60 is wired to 11 + - interrupt-parent: Specify the phandle of the source interrupt, see interrupt 12 + binding documentation for details. Usually this is the GPIO bank 13 + the interrupt line is wired to. 14 + - interrupts: Specify the interrupt index within the interrupt controller (referred 15 + to above in interrupt-parent) and interrupt type. The ENC28J60 natively 16 + generates falling edge interrupts, however, additional board logic 17 + might invert the signal. 18 + - pinctrl-names: List of assigned state names, see pinctrl binding documentation. 19 + - pinctrl-0: List of phandles to configure the GPIO pin used as interrupt line, 20 + see also generic and your platform specific pinctrl binding 21 + documentation. 22 + 23 + Optional properties: 24 + - spi-max-frequency: Maximum frequency of the SPI bus when accessing the ENC28J60. 25 + According to the ENC28J80 datasheet, the chip allows a maximum of 20 MHz, however, 26 + board designs may need to limit this value. 27 + - local-mac-address: See ethernet.txt in the same directory. 28 + 29 + 30 + Example (for NXP i.MX28 with pin control stuff for GPIO irq): 31 + 32 + ssp2: ssp@80014000 { 33 + compatible = "fsl,imx28-spi"; 34 + pinctrl-names = "default"; 35 + pinctrl-0 = <&spi2_pins_b &spi2_sck_cfg>; 36 + status = "okay"; 37 + 38 + enc28j60: ethernet@0 { 39 + compatible = "microchip,enc28j60"; 40 + pinctrl-names = "default"; 41 + pinctrl-0 = <&enc28j60_pins>; 42 + reg = <0>; 43 + interrupt-parent = <&gpio3>; 44 + interrupts = <3 IRQ_TYPE_EDGE_FALLING>; 45 + spi-max-frequency = <12000000>; 46 + }; 47 + }; 48 + 49 + pinctrl@80018000 { 50 + enc28j60_pins: enc28j60_pins@0 { 51 + reg = <0>; 52 + fsl,pinmux-ids = < 53 + MX28_PAD_AUART0_RTS__GPIO_3_3 /* Interrupt */ 54 + >; 55 + fsl,drive-strength = <MXS_DRIVE_4mA>; 56 + fsl,voltage = <MXS_VOLTAGE_HIGH>; 57 + fsl,pull-up = <MXS_PULL_DISABLE>; 58 + }; 59 + };
+17 -3
drivers/net/ethernet/microchip/enc28j60.c
··· 28 28 #include <linux/skbuff.h> 29 29 #include <linux/delay.h> 30 30 #include <linux/spi/spi.h> 31 + #include <linux/of_net.h> 31 32 32 33 #include "enc28j60_hw.h" 33 34 34 35 #define DRV_NAME "enc28j60" 35 - #define DRV_VERSION "1.01" 36 + #define DRV_VERSION "1.02" 36 37 37 38 #define SPI_OPLEN 1 38 39 ··· 1549 1548 { 1550 1549 struct net_device *dev; 1551 1550 struct enc28j60_net *priv; 1551 + const void *macaddr; 1552 1552 int ret = 0; 1553 1553 1554 1554 if (netif_msg_drv(&debug)) ··· 1581 1579 ret = -EIO; 1582 1580 goto error_irq; 1583 1581 } 1584 - eth_hw_addr_random(dev); 1582 + 1583 + macaddr = of_get_mac_address(spi->dev.of_node); 1584 + if (macaddr) 1585 + ether_addr_copy(dev->dev_addr, macaddr); 1586 + else 1587 + eth_hw_addr_random(dev); 1585 1588 enc28j60_set_hw_macaddr(dev); 1586 1589 1587 1590 /* Board setup must set the relevant edge trigger type; ··· 1641 1634 return 0; 1642 1635 } 1643 1636 1637 + static const struct of_device_id enc28j60_dt_ids[] = { 1638 + { .compatible = "microchip,enc28j60" }, 1639 + { /* sentinel */ } 1640 + }; 1641 + MODULE_DEVICE_TABLE(of, enc28j60_dt_ids); 1642 + 1644 1643 static struct spi_driver enc28j60_driver = { 1645 1644 .driver = { 1646 - .name = DRV_NAME, 1645 + .name = DRV_NAME, 1646 + .of_match_table = enc28j60_dt_ids, 1647 1647 }, 1648 1648 .probe = enc28j60_probe, 1649 1649 .remove = enc28j60_remove,