0470-net-ethernet-enc28j60-add-device-tree-support.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. From 4f4509e88313b05862de58f529712bc20a164871 Mon Sep 17 00:00:00 2001
  2. From: Michael Heimpold <mhei@heimpold.de>
  3. Date: Thu, 28 Apr 2016 22:06:15 +0200
  4. Subject: [PATCH] net: ethernet: enc28j60: add device tree support
  5. (Upstream commit 2dd355a007e44960ec049c75920ddb6778fec9ee)
  6. The following patch adds the required match table for device tree support
  7. (and while at, fix the indent). It's also possible to specify the
  8. MAC address in the DT blob.
  9. Also add the corresponding binding documentation file.
  10. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
  11. Signed-off-by: David S. Miller <davem@davemloft.net>
  12. ---
  13. .../devicetree/bindings/net/microchip,enc28j60.txt | 59 ++++++++++++++++++++++
  14. drivers/net/ethernet/microchip/enc28j60.c | 21 +++++---
  15. 2 files changed, 73 insertions(+), 7 deletions(-)
  16. create mode 100644 Documentation/devicetree/bindings/net/microchip,enc28j60.txt
  17. --- /dev/null
  18. +++ b/Documentation/devicetree/bindings/net/microchip,enc28j60.txt
  19. @@ -0,0 +1,59 @@
  20. +* Microchip ENC28J60
  21. +
  22. +This is a standalone 10 MBit ethernet controller with SPI interface.
  23. +
  24. +For each device connected to a SPI bus, define a child node within
  25. +the SPI master node.
  26. +
  27. +Required properties:
  28. +- compatible: Should be "microchip,enc28j60"
  29. +- reg: Specify the SPI chip select the ENC28J60 is wired to
  30. +- interrupt-parent: Specify the phandle of the source interrupt, see interrupt
  31. + binding documentation for details. Usually this is the GPIO bank
  32. + the interrupt line is wired to.
  33. +- interrupts: Specify the interrupt index within the interrupt controller (referred
  34. + to above in interrupt-parent) and interrupt type. The ENC28J60 natively
  35. + generates falling edge interrupts, however, additional board logic
  36. + might invert the signal.
  37. +- pinctrl-names: List of assigned state names, see pinctrl binding documentation.
  38. +- pinctrl-0: List of phandles to configure the GPIO pin used as interrupt line,
  39. + see also generic and your platform specific pinctrl binding
  40. + documentation.
  41. +
  42. +Optional properties:
  43. +- spi-max-frequency: Maximum frequency of the SPI bus when accessing the ENC28J60.
  44. + According to the ENC28J80 datasheet, the chip allows a maximum of 20 MHz, however,
  45. + board designs may need to limit this value.
  46. +- local-mac-address: See ethernet.txt in the same directory.
  47. +
  48. +
  49. +Example (for NXP i.MX28 with pin control stuff for GPIO irq):
  50. +
  51. + ssp2: ssp@80014000 {
  52. + compatible = "fsl,imx28-spi";
  53. + pinctrl-names = "default";
  54. + pinctrl-0 = <&spi2_pins_b &spi2_sck_cfg>;
  55. + status = "okay";
  56. +
  57. + enc28j60: ethernet@0 {
  58. + compatible = "microchip,enc28j60";
  59. + pinctrl-names = "default";
  60. + pinctrl-0 = <&enc28j60_pins>;
  61. + reg = <0>;
  62. + interrupt-parent = <&gpio3>;
  63. + interrupts = <3 IRQ_TYPE_EDGE_FALLING>;
  64. + spi-max-frequency = <12000000>;
  65. + };
  66. + };
  67. +
  68. + pinctrl@80018000 {
  69. + enc28j60_pins: enc28j60_pins@0 {
  70. + reg = <0>;
  71. + fsl,pinmux-ids = <
  72. + MX28_PAD_AUART0_RTS__GPIO_3_3 /* Interrupt */
  73. + >;
  74. + fsl,drive-strength = <MXS_DRIVE_4mA>;
  75. + fsl,voltage = <MXS_VOLTAGE_HIGH>;
  76. + fsl,pull-up = <MXS_PULL_DISABLE>;
  77. + };
  78. + };
  79. --- a/drivers/net/ethernet/microchip/enc28j60.c
  80. +++ b/drivers/net/ethernet/microchip/enc28j60.c
  81. @@ -28,11 +28,12 @@
  82. #include <linux/skbuff.h>
  83. #include <linux/delay.h>
  84. #include <linux/spi/spi.h>
  85. +#include <linux/of_net.h>
  86. #include "enc28j60_hw.h"
  87. #define DRV_NAME "enc28j60"
  88. -#define DRV_VERSION "1.01"
  89. +#define DRV_VERSION "1.02"
  90. #define SPI_OPLEN 1
  91. @@ -1544,6 +1545,7 @@ static int enc28j60_probe(struct spi_dev
  92. {
  93. struct net_device *dev;
  94. struct enc28j60_net *priv;
  95. + const void *macaddr;
  96. int ret = 0;
  97. if (netif_msg_drv(&debug))
  98. @@ -1575,7 +1577,12 @@ static int enc28j60_probe(struct spi_dev
  99. ret = -EIO;
  100. goto error_irq;
  101. }
  102. - eth_hw_addr_random(dev);
  103. +
  104. + macaddr = of_get_mac_address(spi->dev.of_node);
  105. + if (macaddr)
  106. + ether_addr_copy(dev->dev_addr, macaddr);
  107. + else
  108. + eth_hw_addr_random(dev);
  109. enc28j60_set_hw_macaddr(dev);
  110. /* Board setup must set the relevant edge trigger type;
  111. @@ -1630,16 +1637,16 @@ static int enc28j60_remove(struct spi_de
  112. return 0;
  113. }
  114. -static const struct of_device_id enc28j60_of_match[] = {
  115. - { .compatible = "microchip,enc28j60", },
  116. +static const struct of_device_id enc28j60_dt_ids[] = {
  117. + { .compatible = "microchip,enc28j60" },
  118. { /* sentinel */ }
  119. };
  120. -MODULE_DEVICE_TABLE(of, enc28j60_of_match);
  121. +MODULE_DEVICE_TABLE(of, enc28j60_dt_ids);
  122. static struct spi_driver enc28j60_driver = {
  123. .driver = {
  124. - .name = DRV_NAME,
  125. - .of_match_table = enc28j60_of_match,
  126. + .name = DRV_NAME,
  127. + .of_match_table = enc28j60_dt_ids,
  128. },
  129. .probe = enc28j60_probe,
  130. .remove = enc28j60_remove,