Skip to contentSkip to conversation

lan78xx: Read configuration from Device Tree

PATCH Superseded Phil Elwell 4 participants 20 messages Apr 12, 2018 – Apr 17, 2018

Subsystems (6)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover lan78xx: Read configuration from Device Tree

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

This patch set adds support for reading the MAC address, EEE setting and LED modes from Device Tree.

Phil Elwell (4):
lan78xx: Read MAC address from DT if present
lan78xx: Read initial EEE setting from Device Tree
lan78xx: Read LED modes from Device Tree
dt-bindings: Document the DT bindings for lan78xx

 .../devicetree/bindings/net/microchip,lan78xx.txt  | 44 ++++++++++++
 MAINTAINERS                                        |  1 +
 drivers/net/usb/lan78xx.c                          | 81 ++++++++++++++++------
 3 files changed, 105 insertions(+), 21 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,lan78xx.txt
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 lan78xx: Read MAC address from DT if present

There is a standard mechanism for locating and using a MAC address from the Device Tree. Use this facility in the lan78xx driver to support applications without programmed EEPROM or OTP. At the same time, regularise the handling of the different address sources.

---
 drivers/net/usb/lan78xx.c | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)
drivers/net/usb/lan78xx.c +23 -21
index 55a78eb..d2727b5 100644
@@ -37,6 +37,7 @@
 #include <linux/irqchip/chained_irq.h>
 #include <linux/microchipphy.h>
 #include <linux/phy.h>
+#include <linux/of_net.h>
 #include "lan78xx.h"
 
 #define DRIVER_AUTHOR	"WOOJUNG HUH <[email protected]>"
@@ -1651,34 +1652,35 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)
 	addr[5] = (addr_hi >> 8) & 0xFF;
 
 	if (!is_valid_ether_addr(addr)) {
-		/* reading mac address from EEPROM or OTP */
-		if ((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
-					 addr) == 0) ||
-		    (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
-				      addr) == 0)) {
-			if (is_valid_ether_addr(addr)) {
-				/* eeprom values are valid so use them */
-				netif_dbg(dev, ifup, dev->net,
-					  "MAC address read from EEPROM");
-			} else {
-				/* generate random MAC */
-				random_ether_addr(addr);
-				netif_dbg(dev, ifup, dev->net,
-					  "MAC address set to random addr");
-			}
+		const u8 *mac_addr;
 
-			addr_lo = addr[0] | (addr[1] << 8) |
-				  (addr[2] << 16) | (addr[3] << 24);
-			addr_hi = addr[4] | (addr[5] << 8);
-
-			ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
-			ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
+		mac_addr = of_get_mac_address(dev->udev->dev.of_node);
+		if (mac_addr) {
+			/* valid address present in Device Tree */
+			ether_addr_copy(addr, mac_addr);
+			netif_dbg(dev, ifup, dev->net,
+				  "MAC address read from Device Tree");
+		} else if (((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET,
+						 ETH_ALEN, addr) == 0) ||
+			    (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET,
+					      ETH_ALEN, addr) == 0)) &&
+			   is_valid_ether_addr(addr)) {
+			/* eeprom values are valid so use them */
+			netif_dbg(dev, ifup, dev->net,
+				  "MAC address read from EEPROM");
 		} else {
 			/* generate random MAC */
 			random_ether_addr(addr);
 			netif_dbg(dev, ifup, dev->net,
 				  "MAC address set to random addr");
 		}
+
+		addr_lo = addr[0] | (addr[1] << 8) |
+			  (addr[2] << 16) | (addr[3] << 24);
+		addr_hi = addr[4] | (addr[5] << 8);
+
+		ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
+		ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
 	}
 
 	ret = lan78xx_write_reg(dev, MAF_LO(0), addr_lo);
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/4] lan78xx: Read MAC address from DT if present

Hi Phil

drivers/net/usb/lan78xx.c static void lan78xx_init_mac_address(struct lan78xx_net *dev) · line 1657

Quoted 3 lines
drivers/net/usb/lan78xx.c +1 -2
-			ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
-			ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
+		mac_addr = of_get_mac_address(dev->udev->dev.of_node);

It might be better to use the higher level eth_platform_get_mac_address().

Andrew

#3 lore raw

Re: [PATCH 1/4] lan78xx: Read MAC address from DT if present

Hi Andrew,

Quoted 7 lines · Andrew Lunn

Hi Phil

drivers/net/usb/lan78xx.c static void lan78xx_init_mac_address(struct lan78xx_net *dev) · line 1657

Quoted 3 lines
drivers/net/usb/lan78xx.c +1 -2
-			ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
-			ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
+		mac_addr = of_get_mac_address(dev->udev->dev.of_node);

It might be better to use the higher level eth_platform_get_mac_address().

OK - I'll take your word for it.

Phil

#4 lore raw

PATCH 2/4 lan78xx: Read initial EEE setting from Device Tree

In reply to Phil Elwell

Add two new Device Tree properties:
* microchip,eee-enabled - a boolean to enable EEE
* microchip,tx-lpi-timer - time in microseconds to wait after TX goes idle before entering the low power state (default 600)

---
 drivers/net/usb/lan78xx.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/usb/lan78xx.c +17 -0
index d2727b5..d98397b 100644
@@ -2080,6 +2080,23 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 	mii_adv = (u32)mii_advertise_flowctrl(dev->fc_request_control);
 	phydev->advertising |= mii_adv_to_ethtool_adv_t(mii_adv);
 
+	if (of_property_read_bool(dev->udev->dev.of_node,
+				  "microchip,eee-enabled")) {
+		struct ethtool_eee edata;
+
+		memset(&edata, 0, sizeof(edata));
+		edata.cmd = ETHTOOL_SEEE;
+		edata.advertised = ADVERTISED_1000baseT_Full |
+				   ADVERTISED_100baseT_Full;
+		edata.eee_enabled = true;
+		edata.tx_lpi_enabled = true;
+		if (of_property_read_u32(dev->udev->dev.of_node,
+					 "microchip,tx-lpi-timer",
+					 &edata.tx_lpi_timer))
+			edata.tx_lpi_timer = 600; /* non-aggressive */
+		(void)lan78xx_set_eee(dev->net, &edata);
+	}
+
 	genphy_config_aneg(phydev);
 
 	dev->fc_autoneg = phydev->autoneg;
Signature · 1 line
2.7.4
#5 lore raw

Re: [PATCH 2/4] lan78xx: Read initial EEE setting from Device Tree

Quoted 5 lines · Phil Elwell

Add two new Device Tree properties:
* microchip,eee-enabled - a boolean to enable EEE
* microchip,tx-lpi-timer - time in microseconds to wait after TX goes idle before entering the low power state (default 600)

Hi Phil

This looks wrong.

What should happen is that the MAC driver calls phy_init_eee() to find out if the PHY supports EEE. There should be no need to look in device tree.

Andrew

#6 lore raw

Re: [PATCH 2/4] lan78xx: Read initial EEE setting from Device Tree

Andrew,

Quoted 7 lines · Andrew Lunn
Quoted 5 lines · Phil Elwell

Add two new Device Tree properties:
* microchip,eee-enabled - a boolean to enable EEE
* microchip,tx-lpi-timer - time in microseconds to wait after TX goes idle before entering the low power state (default 600)

Quoted 7 lines

Hi Phil

This looks wrong.

What should happen is that the MAC driver calls phy_init_eee() to find out if the PHY supports EEE. There should be no need to look in device tree.

If the driver should be calling phy_init_eee to initialise EEE operation then I'm fine with that (although I notice that the TI cpsw calls phy_ethtool_set_eee but I don't see it calling phy_init_eee). However, it sounds like I need to keep my DT toggle of the EEE enablement and parameters downstream.

Phil

#7 lore raw

PATCH 3/4 lan78xx: Read LED modes from Device Tree

In reply to Phil Elwell

Add support for DT property "microchip,led-modes", a vector of two cells (u32s) in the range 0-15, each of which sets the mode for one of the two LEDs. Some possible values are:

    0=link/activity          1=link1000/activity
    2=link100/activity       3=link10/activity
    4=link100/1000/activity  5=link10/1000/activity
    6=link10/100/activity    14=off    15=on

Also use the presence of the DT property to indicate that the LEDs should be enabled - necessary in the event that no valid OTP or EEPROM is available.

---
 drivers/net/usb/lan78xx.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/usb/lan78xx.c +20 -0
index d98397b..ffb483d 100644
@@ -2008,6 +2008,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 {
 	int ret;
 	u32 mii_adv;
+	u32 led_modes[2];
 	struct phy_device *phydev;
 
 	phydev = phy_find_first(dev->mdiobus);
@@ -2097,6 +2098,25 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 		(void)lan78xx_set_eee(dev->net, &edata);
 	}
 
+	if (!of_property_read_u32_array(dev->udev->dev.of_node,
+					"microchip,led-modes",
+					led_modes, ARRAY_SIZE(led_modes))) {
+		u32 reg;
+		int i;
+
+		reg = phy_read(phydev, 0x1d);
+		for (i = 0; i < ARRAY_SIZE(led_modes); i++) {
+			reg &= ~(0xf << (i * 4));
+			reg |= (led_modes[i] & 0xf) << (i * 4);
+		}
+		(void)phy_write(phydev, 0x1d, reg);
+
+		/* Ensure the LEDs are enabled */
+		lan78xx_read_reg(dev, HW_CFG, &reg);
+		reg |= HW_CFG_LED0_EN_ | HW_CFG_LED1_EN_;
+		lan78xx_write_reg(dev, HW_CFG, reg);
+	}
+
 	genphy_config_aneg(phydev);
 
 	dev->fc_autoneg = phydev->autoneg;
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH 3/4] lan78xx: Read LED modes from Device Tree

Quoted 4 lines · Phil Elwell

Add support for DT property "microchip,led-modes", a vector of two cells (u32s) in the range 0-15, each of which sets the mode for one of the two LEDs. Some possible values are:

Quoted 8 lines
    0=link/activity          1=link1000/activity
    2=link100/activity       3=link10/activity
    4=link100/1000/activity  5=link10/1000/activity
    6=link10/100/activity    14=off    15=on

Also use the presence of the DT property to indicate that the LEDs should be enabled - necessary in the event that no valid OTP or EEPROM is available.

I'm not a fan of this, but at the moment, we don't have anything better.

Please follow what mscc does, add a header file for the LED settings.

Andrew

Quoted 23 lines
---
 drivers/net/usb/lan78xx.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/usb/lan78xx.c +2 -0
index d98397b..ffb483d 100644
@@ -2008,6 +2008,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 {
 	int ret;
 	u32 mii_adv;
+	u32 led_modes[2];
 	struct phy_device *phydev;
 
 	phydev = phy_find_first(dev->mdiobus);
@@ -2097,6 +2098,25 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 		(void)lan78xx_set_eee(dev->net, &edata);
 	}
 
+	if (!of_property_read_u32_array(dev->udev->dev.of_node,

drivers/net/usb/lan78xx.c static int lan78xx_phy_init(struct lan78xx_net *dev) · line 2111

Quoted 10 lines
drivers/net/usb/lan78xx.c +10 -0
+					"microchip,led-modes",
+					led_modes, ARRAY_SIZE(led_modes))) {
+		u32 reg;
+		int i;
+
+		reg = phy_read(phydev, 0x1d);
+		for (i = 0; i < ARRAY_SIZE(led_modes); i++) {
+			reg &= ~(0xf << (i * 4));
+			reg |= (led_modes[i] & 0xf) << (i * 4);
+		}

Please add range checks for led_modes[i] and return -EINVAL if the check fails.

Andrew

#9 lore raw

Re: [PATCH 3/4] lan78xx: Read LED modes from Device Tree

Hi Andrew,

Quoted 10 lines · Andrew Lunn
Quoted 9 lines · Phil Elwell

Add support for DT property "microchip,led-modes", a vector of two cells (u32s) in the range 0-15, each of which sets the mode for one of the two LEDs. Some possible values are:

    0=link/activity          1=link1000/activity
    2=link100/activity       3=link10/activity
    4=link100/1000/activity  5=link10/1000/activity
    6=link10/100/activity    14=off    15=on
Quoted 8 lines
Quoted 3 lines

Also use the presence of the DT property to indicate that the LEDs should be enabled - necessary in the event that no valid OTP or EEPROM is available.

I'm not a fan of this, but at the moment, we don't have anything better.

Please follow what mscc does, add a header file for the LED settings.

Good idea.

Quoted 23 lines
Quoted 23 lines
---
 drivers/net/usb/lan78xx.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/usb/lan78xx.c +1 -0
index d98397b..ffb483d 100644
@@ -2008,6 +2008,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 {
 	int ret;
 	u32 mii_adv;
+	u32 led_modes[2];
 	struct phy_device *phydev;
 
 	phydev = phy_find_first(dev->mdiobus);
@@ -2097,6 +2098,25 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 		(void)lan78xx_set_eee(dev->net, &edata);
 	}
 
Quoted 14 lines

drivers/net/usb/lan78xx.c static int lan78xx_phy_init(struct lan78xx_net *dev) · line 2111

Quoted 11 lines
drivers/net/usb/lan78xx.c +11 -0
+	if (!of_property_read_u32_array(dev->udev->dev.of_node,
+					"microchip,led-modes",
+					led_modes, ARRAY_SIZE(led_modes))) {
+		u32 reg;
+		int i;
+
+		reg = phy_read(phydev, 0x1d);
+		for (i = 0; i < ARRAY_SIZE(led_modes); i++) {
+			reg &= ~(0xf << (i * 4));
+			reg |= (led_modes[i] & 0xf) << (i * 4);
+		}

Please add range checks for led_modes[i] and return -EINVAL if the check fails.

Will do.

Thanks,

Phil

#10 lore raw

Re: [PATCH 3/4] lan78xx: Read LED modes from Device Tree

In reply to Phil Elwell
Quoted 6 lines
drivers/net/usb/lan78xx.c +2 -0
@@ -2097,6 +2098,25 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 		(void)lan78xx_set_eee(dev->net, &edata);
 	}
 
+	if (!of_property_read_u32_array(dev->udev->dev.of_node,
+					"microchip,led-modes",

drivers/net/usb/lan78xx.c static int lan78xx_phy_init(struct lan78xx_net *dev) · line 2112

Quoted 10 lines
drivers/net/usb/lan78xx.c +10 -0
+					led_modes, ARRAY_SIZE(led_modes))) {
+		u32 reg;
+		int i;
+
+		reg = phy_read(phydev, 0x1d);
+		for (i = 0; i < ARRAY_SIZE(led_modes); i++) {
+			reg &= ~(0xf << (i * 4));
+			reg |= (led_modes[i] & 0xf) << (i * 4);
+		}
+		(void)phy_write(phydev, 0x1d, reg);

Poking PHY registers directly from the MAC driver is not always a good idea. This MAC driver does that in a few places :-(

What do we know about the PHY? It is built into the device or is it external? If it is external, how do you know the LED register is at 0x1d?

The safest place to do this is in the PHY driver, and place these OF properties into the PHY node.

Andrew

#11 lore raw

RE: [PATCH 3/4] lan78xx: Read LED modes from Device Tree

Quoted 4 lines
Quoted 4 lines
drivers/net/usb/lan78xx.c +0 -0
@@ -2097,6 +2098,25 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
 		(void)lan78xx_set_eee(dev->net, &edata);
 	}
 
Quoted 15 lines

drivers/net/usb/lan78xx.c static int lan78xx_phy_init(struct lan78xx_net *dev) · line 2112

Quoted 12 lines
drivers/net/usb/lan78xx.c +12 -0
+	if (!of_property_read_u32_array(dev->udev->dev.of_node,
+					"microchip,led-modes",
+					led_modes, ARRAY_SIZE(led_modes))) {
+		u32 reg;
+		int i;
+
+		reg = phy_read(phydev, 0x1d);
+		for (i = 0; i < ARRAY_SIZE(led_modes); i++) {
+			reg &= ~(0xf << (i * 4));
+			reg |= (led_modes[i] & 0xf) << (i * 4);
+		}
+		(void)phy_write(phydev, 0x1d, reg);

Poking PHY registers directly from the MAC driver is not always a good idea. This MAC driver does that in a few places :-(

Agree but, some are for workaround unfortunately.

Quoted 3 lines

What do we know about the PHY? It is built into the device or is it external? If it is external, how do you know the LED register is at 0x1d?

This register is not defined in include/linux/microchipphy.h. :( Also agree that there parts should be applied to internal PHY only.

#12 lore raw

PATCH 4/4 dt-bindings: Document the DT bindings for lan78xx

In reply to Phil Elwell

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

Document the supported properties in a bindings file, adding it to MAINTAINERS at the same time.

---
 .../devicetree/bindings/net/microchip,lan78xx.txt  | 44 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,lan78xx.txt
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +44 -0
new file mode 100644
index 0000000..e7d7850
@@ -0,0 +1,44 @@
+Microchip LAN78xx Gigabit Ethernet controller
+
+The LAN78XX devices are usually configured by programming their OTP or with
+an external EEPROM, but some platforms (e.g. Raspberry Pi 3 B+) have neither.
+
+Please refer to ethernet.txt for a description of common Ethernet bindings.
+
+Optional properties:
+- microchip,eee-enabled: if present, enable Energy Efficient Ethernet support;
+- microchip,led-modes: a two-element vector, with each element configuring
+  the operating mode of an LED. The values supported by the device are;
+  0: Link/Activity
+  1: Link1000/Activity
+  2: Link100/Activity
+  3: Link10/Activity
+  4: Link100/1000/Activity
+  5: Link10/1000/Activity
+  6: Link10/100/Activity
+  7: RESERVED
+  8: Duplex/Collision
+  9: Collision
+  10: Activity
+  11: RESERVED
+  12: Auto-negotiation Fault
+  13: RESERVED
+  14: Off
+  15: On
+- microchip,tx-lpi-timer: the delay (in microseconds) between the TX fifo
+  becoming empty and invoking Low Power Idles (default 600).
+
+Example:
+
+	/* Standard configuration for a Raspberry Pi 3 B+ */
+	ethernet: usbether@1 {
+		compatible = "usb424,7800";
+		reg = <1>;
+		microchip,eee-enabled;
+		microchip,tx-lpi-timer = <600>;
+		/*
+		 * led0 = 1:link1000/activity
+		 * led1 = 6:link10/100/activity
+		 */
+		microchip,led-modes = <1 6>;
+	};
MAINTAINERS +1 -0
index 2328eed..b637aad 100644
@@ -14482,6 +14482,7 @@ M:	Microchip Linux Driver Support <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	drivers/net/usb/lan78xx.*
+F:	Documentation/devicetree/bindings/net/microchip,lan78xx.txt
 
 USB MASS STORAGE DRIVER
 M:	Alan Stern <[email protected]>
Signature · 1 line
2.7.4
#13 lore raw

Re: [PATCH 4/4] dt-bindings: Document the DT bindings for lan78xx

Quoted 7 lines · Phil Elwell

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

Document the supported properties in a bindings file, adding it to MAINTAINERS at the same time.

Hi Phil

How you link an OF node to a USB device is not obvious. Could you please include either a pointer to some binding documentation, or make your example show it.

Thanks
Andrew

#14 lore raw

Re: [PATCH 4/4] dt-bindings: Document the DT bindings for lan78xx

Hi Andrew,

Quoted 6 lines · Andrew Lunn
Quoted 5 lines · Phil Elwell

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

Quoted 8 lines
Quoted 2 lines

Document the supported properties in a bindings file, adding it to MAINTAINERS at the same time.

Hi Phil

How you link an OF node to a USB device is not obvious. Could you please include either a pointer to some binding documentation, or make your example show it.

Thanks for the feedback. Would you consider this (lifted from the Pi 3B+ Device Tree) a sufficient example?

&usb {
	usb1@1 {
		compatible = "usb424,2514";
		reg = <1>;
		#address-cells = <1>;
		#size-cells = <0>;

		usb1_1@1 {
			compatible = "usb424,2514";
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			ethernet: usbether@1 {
				compatible = "usb424,7800";
				reg = <1>;
				microchip,eee-enabled;
				microchip,tx-lpi-timer = <600>; /* non-aggressive*/
				/*
				 * led0 = 1:link1000/activity
				 * led1 = 6:link10/100/activity
				 */
				microchip,led-modes = <1 6>;
			};
		};
	};
};

Phil

#15 lore raw

Re: [PATCH 4/4] dt-bindings: Document the DT bindings for lan78xx

Quoted 12 lines · Phil Elwell

Hi Andrew,

Quoted 9 lines · Andrew Lunn
Quoted 7 lines · Phil Elwell

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

Document the supported properties in a bindings file, adding it to MAINTAINERS at the same time.

Quoted 8 lines
Quoted 5 lines

Hi Phil

How you link an OF node to a USB device is not obvious. Could you please include either a pointer to some binding documentation, or make your example show it.

Thanks for the feedback. Would you consider this (lifted from the Pi 3B+ Device Tree) a sufficient example?

Yes, this is good.

Thanks
Andrew

#16 lore raw

Re: [PATCH 4/4] dt-bindings: Document the DT bindings for lan78xx

In reply to Phil Elwell
Quoted 4 lines · Phil Elwell

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

It would be good to document what happens when there is an EEPROM. Is OF used in preference to the EEPROM?

Andrew

#17 lore raw

Re: [PATCH 4/4] dt-bindings: Document the DT bindings for lan78xx

Hi Andrew,

Quoted 8 lines · Andrew Lunn
Quoted 4 lines · Phil Elwell

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

It would be good to document what happens when there is an EEPROM. Is OF used in preference to the EEPROM?

Yes it is. I'll mention it in V2.

Phil

maintainer
#18 lore raw

Re: [PATCH 4/4] dt-bindings: Document the DT bindings for lan78xx

In reply to Phil Elwell
Quoted 21 lines · Phil Elwell

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

Document the supported properties in a bindings file, adding it to MAINTAINERS at the same time.

---
 .../devicetree/bindings/net/microchip,lan78xx.txt  | 44 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,lan78xx.txt
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +0 -0
new file mode 100644
index 0000000..e7d7850

Documentation/devicetree/bindings/net/microchip,lan78xx.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +9 -0
@@ -0,0 +1,44 @@
+Microchip LAN78xx Gigabit Ethernet controller
+
+The LAN78XX devices are usually configured by programming their OTP or with
+an external EEPROM, but some platforms (e.g. Raspberry Pi 3 B+) have neither.
+
+Please refer to ethernet.txt for a description of common Ethernet bindings.
+
+Optional properties:
+- microchip,eee-enabled: if present, enable Energy Efficient Ethernet support;

I see we have some flags for broken EEE, but nothing already defined to enable EEE. Seems like this should either be a user option (therefore not in DT) or we should use the broken EEE properties if this is h/w dependent.

Quoted 10 lines
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +10 -0
+- microchip,led-modes: a two-element vector, with each element configuring
+  the operating mode of an LED. The values supported by the device are;
+  0: Link/Activity
+  1: Link1000/Activity
+  2: Link100/Activity
+  3: Link10/Activity
+  4: Link100/1000/Activity
+  5: Link10/1000/Activity
+  6: Link10/100/Activity
+  7: RESERVED

Documentation/devicetree/bindings/net/microchip,lan78xx.txt line 29

Quoted 10 lines
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +10 -0
+  8: Duplex/Collision
+  9: Collision
+  10: Activity
+  11: RESERVED
+  12: Auto-negotiation Fault
+  13: RESERVED
+  14: Off
+  15: On
+- microchip,tx-lpi-timer: the delay (in microseconds) between the TX fifo
+  becoming empty and invoking Low Power Idles (default 600).

Needs a unit suffix as defined in property-units.txt.

Quoted 30 lines
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +15 -0
+
+Example:
+
+	/* Standard configuration for a Raspberry Pi 3 B+ */
+	ethernet: usbether@1 {
+		compatible = "usb424,7800";
+		reg = <1>;
+		microchip,eee-enabled;
+		microchip,tx-lpi-timer = <600>;
+		/*
+		 * led0 = 1:link1000/activity
+		 * led1 = 6:link10/100/activity
+		 */
+		microchip,led-modes = <1 6>;
+	};
MAINTAINERS +1 -0
index 2328eed..b637aad 100644
@@ -14482,6 +14482,7 @@ M:	Microchip Linux Driver Support <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	drivers/net/usb/lan78xx.*
+F:	Documentation/devicetree/bindings/net/microchip,lan78xx.txt
 
 USB MASS STORAGE DRIVER
 M:	Alan Stern <[email protected]>
Signature · 1 line
2.7.4
#19 lore raw

Re: [PATCH 4/4] dt-bindings: Document the DT bindings for lan78xx

Quoted 28 lines · Rob Herring
Quoted 27 lines · Phil Elwell

The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP.

Document the supported properties in a bindings file, adding it to MAINTAINERS at the same time.

---
 .../devicetree/bindings/net/microchip,lan78xx.txt  | 44 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,lan78xx.txt
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +6 -0
new file mode 100644
index 0000000..e7d7850
@@ -0,0 +1,44 @@
+Microchip LAN78xx Gigabit Ethernet controller
+
+The LAN78XX devices are usually configured by programming their OTP or with
+an external EEPROM, but some platforms (e.g. Raspberry Pi 3 B+) have neither.
+
+Please refer to ethernet.txt for a description of common Ethernet bindings.
Quoted 8 lines

Documentation/devicetree/bindings/net/microchip,lan78xx.txt line 9

Quoted 3 lines
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +3 -0
+
+Optional properties:
+- microchip,eee-enabled: if present, enable Energy Efficient Ethernet support;

I see we have some flags for broken EEE, but nothing already defined to enable EEE. Seems like this should either be a user option (therefore not in DT) or we should use the broken EEE properties if this is h/w dependent.

In the downstream Raspberry Pi kernel we use DT as a way of passing user settings to drivers - it's more powerful than the command line. I understand that this is not the done thing here so I'm withdrawing this element of the patch series.

Apologies for the noise.

Quoted 53 lines
Quoted 10 lines
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +10 -0
+- microchip,led-modes: a two-element vector, with each element configuring
+  the operating mode of an LED. The values supported by the device are;
+  0: Link/Activity
+  1: Link1000/Activity
+  2: Link100/Activity
+  3: Link10/Activity
+  4: Link100/1000/Activity
+  5: Link10/1000/Activity
+  6: Link10/100/Activity
+  7: RESERVED

Documentation/devicetree/bindings/net/microchip,lan78xx.txt line 29

Quoted 10 lines
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +10 -0
+  8: Duplex/Collision
+  9: Collision
+  10: Activity
+  11: RESERVED
+  12: Auto-negotiation Fault
+  13: RESERVED
+  14: Off
+  15: On
+- microchip,tx-lpi-timer: the delay (in microseconds) between the TX fifo
+  becoming empty and invoking Low Power Idles (default 600).

Needs a unit suffix as defined in property-units.txt.

Quoted 30 lines
Documentation/devicetree/bindings/net/microchip,lan78xx.txt new file +15 -0
+
+Example:
+
+	/* Standard configuration for a Raspberry Pi 3 B+ */
+	ethernet: usbether@1 {
+		compatible = "usb424,7800";
+		reg = <1>;
+		microchip,eee-enabled;
+		microchip,tx-lpi-timer = <600>;
+		/*
+		 * led0 = 1:link1000/activity
+		 * led1 = 6:link10/100/activity
+		 */
+		microchip,led-modes = <1 6>;
+	};
MAINTAINERS +1 -0
index 2328eed..b637aad 100644
@@ -14482,6 +14482,7 @@ M:	Microchip Linux Driver Support <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	drivers/net/usb/lan78xx.*
+F:	Documentation/devicetree/bindings/net/microchip,lan78xx.txt
 
 USB MASS STORAGE DRIVER
 M:	Alan Stern <[email protected]>
Signature · 1 line
2.7.4